From wuwei23 at gmail.com Mon Feb 1 00:16:43 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 21:16:43 -0800 (PST) Subject: A performance issue when using default value References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: keakon wrote: > def h2(x=[]): > ? y = x > ? y.append(1) > ? return y + [] > h2() is about 42 times slower than h2([]), but h() is a litter faster > than h([]). Are you aware that 'y = x' _doesn't_ make a copy of [], that it actually points to the same list as x? My guess is that the slowdown you're seeing is due to the increasing size of x _per timing iteration_. h2([]) will pass a new list each time, while h2() will append to the same list _every_ time. The difference between h & h2 is due to the concatenation of a new list to the built one: the longer the default list grows, the longer this will take, as extending a list takes O(k) time, with k being the number of elements. From keakon at gmail.com Mon Feb 1 00:20:28 2010 From: keakon at gmail.com (keakon) Date: Sun, 31 Jan 2010 21:20:28 -0800 (PST) Subject: A performance issue when using default value References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: <6eb8894f-ba52-4b47-8986-9fb7f3981da4@f17g2000prh.googlegroups.com> Even this style is 41 times faster than h2(): def i2(x=[]): y = x if not y: # add this line y = [] # add this line y.append(1) return y + [] print Timer('i2()','from __main__ import f2, g2, h2, i2').timeit (TIMES) Time: 0.00742356919664 From wuwei23 at gmail.com Mon Feb 1 00:20:53 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 21:20:53 -0800 (PST) Subject: A performance issue when using default value References: eabd60b1-269e-42e7-b8ee-0447cd34e6b5@v37g2000prh.googlegroups.com Message-ID: <9d2678d9-a232-4128-90f6-9ffae286ed23@s36g2000prf.googlegroups.com> alex23 wrote: > keakon wrote: > > def h2(x=[]): > > ? y = x > > ? y.append(1) > > ? return y + [] > > Are you aware that 'y = x' _doesn't_ make a copy of [], that it > actually points to the same list as x? Sorry, I meant to suggest trying the following instead: def h2(x=None): if x is None: x = [] x.append(1) return x + [] It's a common idiom to use None as a sentinel for this situation, esp. where you _don't_ want a default mutable object to be reused. From clp2 at rebertia.com Mon Feb 1 00:21:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Jan 2010 21:21:18 -0800 Subject: A performance issue when using default value In-Reply-To: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: <50697b2c1001312121y68cd9c5dk36e3c6c0d4f4d74e@mail.gmail.com> On Sun, Jan 31, 2010 at 8:58 PM, keakon wrote: > I've found strange performance issue when using default value, the > test code is list below: > > from timeit import Timer > > def f(x): > ?y = x > ?y.append(1) > ?return y > > def g(x=[]): > ?y = [] > ?y.append(1) > ?return y > > def h(x=[]): > ?y = x > ?y.append(1) > ?return y > > def f2(x): > ?y = x > ?y.append(1) > ?return y + [] > > def g2(x=[]): > ?y = [] > ?y.append(1) > ?return y + [] > > def h2(x=[]): > ?y = x > ?y.append(1) > ?return y + [] > > TIMES = 10000 > print Timer('f([])','from __main__ import f, g, h').timeit(TIMES) > print Timer('g()','from __main__ import f, g, h').timeit(TIMES) > print Timer('h([])','from __main__ import f, g, h').timeit(TIMES) > print Timer('h()','from __main__ import f, g, h').timeit(TIMES) > print Timer('f2([])','from __main__ import f2, g2, h2').timeit(TIMES) > print Timer('g2()','from __main__ import f2, g2, h2').timeit(TIMES) > print Timer('h2([])','from __main__ import f2, g2, h2').timeit(TIMES) > print Timer('h2()','from __main__ import f2, g2, h2').timeit(TIMES) > > > I tested it with Python 2.5.4, 2.6.4 and 3.1.1 on Windows XP, and get > almost the same result: > 0.00449247041174 > 0.00439608944712 > 0.00455867994396 > 0.00327471787615 > 0.00791581052899 > 0.00684919452053 > 0.00734311204357 > 0.30974942346 > > h2() is about 42 times slower than h2([]), but h() is a litter faster > than h([]). > > If change TIMES to 20000, other results are 2 times than before, but h2 > () is 4 times(about 1.2 sec) than before. > > Is there any tricks in it? Are you aware of the following pitfall?: >>> def foo(a=[]): ... a.append(7) ... return a >>> >>> print foo() [7] >>> print foo() [7, 7] >>> print foo() [7, 7, 7] i.e. the default argument is only evaluated once (when the function is defined) and is then reused every call when the caller doesn't provide a value. Cheers, Chris -- http://blog.rebertia.com From keakon at gmail.com Mon Feb 1 00:32:06 2010 From: keakon at gmail.com (keakon) Date: Sun, 31 Jan 2010 21:32:06 -0800 (PST) Subject: A performance issue when using default value References: eabd60b1-269e-42e7-b8ee-0447cd34e6b5@v37g2000prh.googlegroups.com <9d2678d9-a232-4128-90f6-9ffae286ed23@s36g2000prf.googlegroups.com> Message-ID: On 2?1?, ??1?20?, alex23 wrote: > alex23 wrote: > > keakon wrote: > > > def h2(x=[]): > > > y = x > > > y.append(1) > > > return y + [] > > > Are you aware that 'y = x' _doesn't_ make a copy of [], that it > > actually points to the same list as x? > > Sorry, I meant to suggest trying the following instead: > > def h2(x=None): > if x is None: x = [] > x.append(1) > return x + [] > > It's a common idiom to use None as a sentinel for this situation, esp. > where you _don't_ want a default mutable object to be reused. Thank you, I got it. The default value is mutable, and can be reused by all each call. So each call it will append 1 to the default value, that's very different than C++. From wuwei23 at gmail.com Mon Feb 1 00:58:06 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 21:58:06 -0800 (PST) Subject: A performance issue when using default value References: eabd60b1-269e-42e7-b8ee-0447cd34e6b5@v37g2000prh.googlegroups.com <9d2678d9-a232-4128-90f6-9ffae286ed23@s36g2000prf.googlegroups.com> Message-ID: <804a8f7e-0188-43f4-add9-52f841ceaf1a@w27g2000pre.googlegroups.com> keakon wrote: > The default value is mutable, and can be reused by all each call. > So each call it will append 1 to the default value, that's very > different than C++. Being different from C++ is one of the many reasons some of us choose Python ;) This tends to bite most newcomers, so it's mentioned in the FAQ: http://www.python.org/doc/faq/general/#id52 From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:05:17 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:05:17 GMT Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 31 Jan 2010 20:22:36 -0800, Paul Rubin wrote: > Terry Reedy writes: >> Three of you gave essentially identical answers, but I still do not see >> how given something like >> >> def f(): return 1 >> >> I differentiate between 'function object at address xxx' and 'int 1' >> objects. > > In the languages they are talking about, there is no such thing as a > function with no args. A function is closer to a mathematical function, > i.e. a mapping from one type to another, so every function has an arg. Suppose I have a function that queries a website http://guessmyname.com for a list of popular names and returns the most popular name on the list. Obviously this name will change from time to time, so I can't just get it once and treat the result as a constant. In a non-functional language, I'd write it something like this: def get_popular_name(): URL = 'http://guessmyname.com' data = fetch(URL) names = parse(data) name = choose(names, 1) return name name = get_popular_name() # call the function with no argument f = decorate(get_popular_name) # treat the function as a 1st class object How would Haskell coders write it? Something like this? def get_popular_name(url): data = fetch url names = parse data name = choose name 1 return name name = get_popular_name 'http://guessmyname.com' # call the function f = decorate get_popular_name # treat the function as a 1st class object But now you're needlessly having the caller, rather than the function, remember an implementation detail of the get_popular_name function. Since the argument couldn't be anything different, I'd immediately think of applying partial: get_popular_name = partial get_popular_name 'http://guessmyname.com' but now how do I call the new function? Is this where you say "Monads" and everyone's eyes glaze over? -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:15:35 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:15:35 GMT Subject: A performance issue when using default value References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: On Sun, 31 Jan 2010 20:58:50 -0800, keakon wrote: > I've found strange performance issue when using default value, the test > code is list below: > > from timeit import Timer > > def f(x): > y = x > y.append(1) > return y > > def g(x=[]): > y = [] > y.append(1) > return y > > def h(x=[]): > y = x > y.append(1) > return y > > def f2(x): > y = x > y.append(1) > return y + [] > > def g2(x=[]): > y = [] > y.append(1) > return y + [] > > def h2(x=[]): > y = x > y.append(1) > return y + [] > > TIMES = 10000 > print Timer('f([])','from __main__ import f, g, h').timeit(TIMES) print > Timer('g()','from __main__ import f, g, h').timeit(TIMES) print > Timer('h([])','from __main__ import f, g, h').timeit(TIMES) print > Timer('h()','from __main__ import f, g, h').timeit(TIMES) print > Timer('f2([])','from __main__ import f2, g2, h2').timeit(TIMES) print > Timer('g2()','from __main__ import f2, g2, h2').timeit(TIMES) print > Timer('h2([])','from __main__ import f2, g2, h2').timeit(TIMES) print > Timer('h2()','from __main__ import f2, g2, h2').timeit(TIMES) > > > I tested it with Python 2.5.4, 2.6.4 and 3.1.1 on Windows XP, and get > almost the same result: > 0.00449247041174 > 0.00439608944712 > 0.00455867994396 > 0.00327471787615 > 0.00791581052899 > 0.00684919452053 > 0.00734311204357 > 0.30974942346 You've only run those results once, haven't you? That is not trustworthy. In a multi-tasking operating system, including Windows, some other process might have run for some milliseconds, throwing the results off. More importantly, if you had run it multiple times, you'd see this: >>> for i in range(7): ... Timer('h2()','from __main__ import f2, g2, h2').timeit(TIMES) ... 0.0190200805664 0.315117120743 0.941411972046 1.56618499756 2.18553495407 2.79832291603 3.44865894318 h2 (and probably h, but I haven't tested it) get slower and slower and slower every time you run it. Why? I'm pretty sure this is in the FAQs, but default values are created once, not every time the function is called. So you create a function with the default value of []. Call the function, and that list gets 1 appended to it, so the default value is now [1]. Call the function again, and it becomes [1, 1]. And so on, and so on, and so on. The other functions create a new empty list each time the function is called, so you're comparing the time it takes to grow an ever-bigger list with the time it takes to create a tiny list. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:17:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:17:21 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <874om1ydxf.fsf@castleamber.com> Message-ID: On Sun, 31 Jan 2010 18:53:16 -0600, John Bokma wrote: > You don't have to buy my argument, I am not selling it. It's a figure of speech. You are making an argument others have made before, and I don't accept the validity of the argument. -- Steven From no.email at nospam.invalid Mon Feb 1 01:22:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 31 Jan 2010 22:22:14 -0800 Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: <7x4om18oh5.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > How would Haskell coders write it? Something like this? > > def get_popular_name(url): > data = fetch url > names = parse data > name = choose name 1 > return name The syntax and types would be different, but ok, something like that. > name = get_popular_name 'http://guessmyname.com' # call the function > f = decorate get_popular_name # treat the function as a 1st class object You wouldn't need "decorate". You'd just say f = get_popular_name "http://guessmyname.com" f is now an "I/O action" which when executed queries the guessmyname site. > but now how do I call the new function? > Is this where you say "Monads" and everyone's eyes glaze over? You'd say something like most_popular_name <- f to invoke the action. Yes, explaining the difference between "<-" and "=" involves monads. You might like the Haskell tutorial http://learnyouahaskell.com . From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:27:29 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:27:29 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: On Sun, 31 Jan 2010 21:30:15 -0600, John Bokma wrote: >>>>> While braces might be considered redundant they are not when for one >>>>> reason or another formatting is lost or done incorrectly. >>>> >>>> I've heard this argument before, and I don't buy it. Why should we >>>> expect the editor to correct malformed code? >>> >>> Or a prettyfier. It doesn't matter. The point is that with braces >>> there *is* redundancy that be used to fix the code. >> >> Prettyfiers are significant in languages that allow braces (or >> begin/end tokens) and indentation to go out of sync. Since that can't >> happen with Python, > > Yes it can. I *have* seen Python with broken indentation on web pages, > and good luck sorting it out. Blaming it on "broken tools" is just > another straw man. You're using that term wrong. It looks to me that you don't actually know what a straw man argument is. A straw man argument is when somebody responds to a deliberately weakened or invalid argument as if it had been made by their opponent. You raised the issue that the redundancy which prettyfiers exploit are a good reason for preferring braces, so it's not a straw man argument. It's not a straw man to say that you don't need a code prettyfier if indentation is significant when you raised the issue of prettyfiers in the first place. I certainly accept that braces + indentation do provide redundancy, and if the norm was noisy channels, that redundancy would be valuable. But that's not the norm. Most channels don't delete leading whitespace, and those noisy channels we do deal with (like web forms) tend to introduce far more noise than merely deleting leading whitespace, e.g. word- wrapping long lines. The argument that "web pages break indentation, therefore braces are better" is a real argument that some people make, but it is very weak. Suppose there was a web page that arbitrarily deleted braces out of some misplaced sense of security. Would anyone argue that this proves that indentation was better and braces were bad? No, of course not -- they would say "That website is broken". > It happens, and if you're learning Python and > interested in that code you have a problem. Yes you do. If you're trying to learn carpentry, and somebody gives you a blunt saw that causes the wood to break rather than cut cleanly, you have a problem. If you're learning to cook, and they give you a put with a hole in it and tell you to make soup in it, you have a problem. Broken tools lead to problems. > Snipped the rest, because you start to sound like a zealot. I should've > know better. Yeah, whatever. -- Steven From wuwei23 at gmail.com Mon Feb 1 01:43:56 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 22:43:56 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: Steven D'Aprano wrote: > You're using that term wrong. It looks to me that you don't actually know > what a straw man argument is. A straw man argument is when somebody > responds to a deliberately weakened or invalid argument as if it had been > made by their opponent. Jeez, Steve, you're beginning to sound like some kind of fallacy zealot... ;) From clp2 at rebertia.com Mon Feb 1 01:49:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Jan 2010 22:49:13 -0800 Subject: Python and Ruby In-Reply-To: References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c1001312249v237d4280xf297f4afac73f028@mail.gmail.com> On Sun, Jan 31, 2010 at 10:05 PM, Steven D'Aprano wrote: > On Sun, 31 Jan 2010 20:22:36 -0800, Paul Rubin wrote: >> Terry Reedy writes: >>> Three of you gave essentially identical answers, but I still do not see >>> how given something like >>> >>> def f(): return 1 >>> >>> I differentiate between 'function object at address xxx' and 'int 1' >>> objects. >> >> In the languages they are talking about, there is no such thing as a >> function with no args. ?A function is closer to a mathematical function, >> i.e. a mapping from one type to another, so every function has an arg. > > Suppose I have a function that queries a website http://guessmyname.com > for a list of popular names and returns the most popular name on the > list. Obviously this name will change from time to time, so I can't just > get it once and treat the result as a constant. > > In a non-functional language, I'd write it something like this: > > > def get_popular_name(): > ? ?URL = 'http://guessmyname.com' > ? ?data = fetch(URL) > ? ?names = parse(data) > ? ?name = choose(names, 1) > ? ?return name > > name = get_popular_name() ?# call the function with no argument > f = decorate(get_popular_name) ?# treat the function as a 1st class object > > > How would Haskell coders write it? > Is this where you say "Monads" and everyone's eyes glaze over? Yeah, basically. Your function has side-effects (i.e. it does I/O over the network), and thus some extra hoops need to be jumped through to reconcile that with the functional purity of the language. Assuming my understanding of monads is somewhat correct: get_popular_name would have the type: IO () -> IO String i.e. it takes no "real" parameters but does I/O, and returns a String. "IO" is a generic type, thus IO () is like IO, and IO String is IO (using Java/C#-like generics syntax). Wrapping things in IOs (the "IO monad") is how the type system models that I/O side effects are involved. So, get_popular_name would end up taking one argument, IO (). Now where does the caller get an IO () ? Well, the toplevel (i.e. the main function) is allowed to do IO (otherwise, we couldn't write very interesting programs), and thus is provided with an IO by the environment (through some sort of magic). Using this, it passes an IO () to get_popular_name (or it gets passed down the call stack and eventually winds up at get_popular_name) and we get back an IO String. And through some further monad trickery, we make sure that lazy evaluation is effectively bypassed for the I/O and we are able to rip the String out of its IO container and pass it to pure functions. And using the dark magic of "do-notation", we write the parts involving IO in pseudo-imperative style (the "<-" operator Paul mentioned is part of that). And there you have it (I think/hope). Supposedly, in practice, you don't need to know the monad guts of how the I/O system works in order to use it, you just need to be able to write do-notation. Cheers, Chris -- I really should read the monad chapters of my copy of "Real World Haskell". http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 02:12:51 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 07:12:51 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: On Sun, 31 Jan 2010 22:43:56 -0800, alex23 wrote: > Steven D'Aprano wrote: >> You're using that term wrong. It looks to me that you don't actually >> know what a straw man argument is. A straw man argument is when >> somebody responds to a deliberately weakened or invalid argument as if >> it had been made by their opponent. > > Jeez, Steve, you're beginning to sound like some kind of fallacy > zealot... ;) Death to all those who confuse agumentum ad populum with argumentum ad verecundiam!!! -- Steven From no.email at nospam.invalid Mon Feb 1 02:24:06 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 31 Jan 2010 23:24:06 -0800 Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: <7xk4uxju5l.fsf@ruckus.brouhaha.com> Chris Rebert writes: > get_popular_name would have the type: IO () -> IO String I don't know if it makes the explanation any clearer, but I think that isn't quite right. The Python version would have type String -> IO String. The parameterless Haskell version would just be an I/O action, with type IO String. IO () is not really involved. From lanyjie at yahoo.com Mon Feb 1 03:24:42 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 1 Feb 2010 00:24:42 -0800 (PST) Subject: expy 0.5.1 released Message-ID: <511580.45863.qm@web54208.mail.re2.yahoo.com> Hi there, EXPY 0.5.1 released, the exception raising feature is enhanced so that you can raise any builtin exceptions. Custom exceptions will be supported soon. For more information, see http://expy.sourceforge.net/ EXPY is an expressway to extend Python! Regards, Yingjie From stefan_ml at behnel.de Mon Feb 1 03:34:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Feb 2010 09:34:28 +0100 Subject: HTML Parser which allows low-keyed local changes? In-Reply-To: References: Message-ID: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Robert, 31.01.2010 20:57: > I tried lxml, but after walking and making changes in the element tree, > I'm forced to do a full serialization of the whole document > (etree.tostring(tree)) - which destroys the "human edited" format of the > original HTML code. makes it rather unreadable. What do you mean? Could you give an example? lxml certainly does not destroy anything it parsed, unless you tell it to do so. Stefan From ps.ohms at gmail.com Mon Feb 1 03:43:29 2010 From: ps.ohms at gmail.com (PS.OHM) Date: Mon, 1 Feb 2010 00:43:29 -0800 (PST) Subject: get error install MySQLdb on Mac OS X References: <30c0946e-fa6a-4a54-930c-1962d167fffe@x10g2000prk.googlegroups.com> Message-ID: <2be17362-8a54-4a04-9671-0a0ff7266e33@k2g2000pro.googlegroups.com> On Jan 29, 5:02?am, Sean DiZazzo wrote: > On Jan 28, 12:53?pm, "PS.OHM" wrote: > > > Hello Guys > > > I havegetsomeerrorwhen i install MySQLdb on Mac OS X > > > after i key command $python setup.py build > > > rusult is > > : > > : > >error: command 'gcc-4.0' failed with exit status 1 > > > How to config this poblem? > > Please show a little bit more of theerror iME-macbook-pro:MySQL-python-1.2.3c1 iME$ python setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb running build_ext building '_mysql' extension gcc-4.0 -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 - Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/Applications/ MAMP/Library/include/mysql -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 -fno-omit-frame-pointer -D_P1003_1B_VISIBLE - DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory _mysql.c:76: error: syntax error before ?MYSQL? _mysql.c:76: warning: no semicolon at end of struct or union _mysql.c:79: error: syntax error before ?}? token _mysql.c:79: warning: data definition has no type or storage class _mysql.c:90: error: syntax error before ?MYSQL_RES? _mysql.c:90: warning: no semicolon at end of struct or union _mysql.c:94: error: syntax error before ?}? token _mysql.c:94: warning: data definition has no type or storage class _mysql.c:106: error: syntax error before ?*? token _mysql.c: In function ?_mysql_Exception?: _mysql.c:120: error: ?c? undeclared (first use in this function) _mysql.c:120: error: (Each undeclared identifier is reported only once _mysql.c:120: error: for each function it appears in.) _mysql.c:123: error: ?CR_MAX_ERROR? undeclared (first use in this function) _mysql.c:131: error: ?CR_COMMANDS_OUT_OF_SYNC? undeclared (first use in this function) _mysql.c:132: error: ?ER_DB_CREATE_EXISTS? undeclared (first use in this function) _mysql.c:133: error: ?ER_SYNTAX_ERROR? undeclared (first use in this function) _mysql.c:134: error: ?ER_PARSE_ERROR? undeclared (first use in this function) _mysql.c:135: error: ?ER_NO_SUCH_TABLE? undeclared (first use in this function) _mysql.c:136: error: ?ER_WRONG_DB_NAME? undeclared (first use in this function) _mysql.c:137: error: ?ER_WRONG_TABLE_NAME? undeclared (first use in this function) _mysql.c:138: error: ?ER_FIELD_SPECIFIED_TWICE? undeclared (first use in this function) _mysql.c:139: error: ?ER_INVALID_GROUP_FUNC_USE? undeclared (first use in this function) _mysql.c:140: error: ?ER_UNSUPPORTED_EXTENSION? undeclared (first use in this function) _mysql.c:141: error: ?ER_TABLE_MUST_HAVE_COLUMNS? undeclared (first use in this function) _mysql.c:170: error: ?ER_DUP_ENTRY? undeclared (first use in this function) _mysql.c:213: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:358: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_Initialize?: _mysql.c:363: error: ?MYSQL_RES? undeclared (first use in this function) _mysql.c:363: error: ?result? undeclared (first use in this function) _mysql.c:364: error: ?conn? undeclared (first use in this function) _mysql.c:368: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:368: error: ?fields? undeclared (first use in this function) _mysql.c:370: error: ?args? undeclared (first use in this function) _mysql.c:370: error: ?kwargs? undeclared (first use in this function) _mysql.c:375: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:445: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_traverse?: _mysql.c:450: error: ?self? undeclared (first use in this function) _mysql.c:451: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:460: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_clear?: _mysql.c:462: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:471: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_Initialize?: _mysql.c:475: error: ?MYSQL? undeclared (first use in this function) _mysql.c:475: error: ?conn? undeclared (first use in this function) _mysql.c:500: error: ?self? undeclared (first use in this function) _mysql.c:503: error: ?args? undeclared (first use in this function) _mysql.c:503: error: ?kwargs? undeclared (first use in this function) _mysql.c:550: error: ?MYSQL_OPT_CONNECT_TIMEOUT? undeclared (first use in this function) _mysql.c:554: error: ?MYSQL_OPT_COMPRESS? undeclared (first use in this function) _mysql.c:555: error: ?CLIENT_COMPRESS? undeclared (first use in this function) _mysql.c:558: error: ?MYSQL_OPT_NAMED_PIPE? undeclared (first use in this function) _mysql.c:560: error: ?MYSQL_INIT_COMMAND? undeclared (first use in this function) _mysql.c:562: error: ?MYSQL_READ_DEFAULT_FILE? undeclared (first use in this function) _mysql.c:564: error: ?MYSQL_READ_DEFAULT_GROUP? undeclared (first use in this function) _mysql.c:567: error: ?MYSQL_OPT_LOCAL_INFILE? undeclared (first use in this function) _mysql.c: In function ?_mysql_connect?: _mysql.c:654: error: ?c? undeclared (first use in this function) _mysql.c:656: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:667: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_traverse?: _mysql.c:671: error: ?self? undeclared (first use in this function) _mysql.c:672: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:678: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_clear?: _mysql.c:680: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:690: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_close?: _mysql.c:693: error: ?args? undeclared (first use in this function) _mysql.c:696: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:718: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_affected_rows?: _mysql.c:721: error: ?args? undeclared (first use in this function) _mysql.c:722: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:752: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dump_debug_info?: _mysql.c:756: error: ?args? undeclared (first use in this function) _mysql.c:757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:771: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_autocommit?: _mysql.c:775: error: ?args? undeclared (first use in this function) _mysql.c:783: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:797: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_commit?: _mysql.c:801: error: ?args? undeclared (first use in this function) _mysql.c:806: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:819: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_rollback?: _mysql.c:823: error: ?args? undeclared (first use in this function) _mysql.c:828: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:851: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_next_result?: _mysql.c:855: error: ?args? undeclared (first use in this function) _mysql.c:863: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:936: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_errno?: _mysql.c:939: error: ?args? undeclared (first use in this function) _mysql.c:940: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:952: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_error?: _mysql.c:955: error: ?args? undeclared (first use in this function) _mysql.c:956: error: ?self? undeclared (first use in this function) _mysql.c:957: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:970: error: syntax error before ?*? token _mysql.c: In function ?_mysql_escape_string?: _mysql.c:976: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1005: error: syntax error before ?*? token _mysql.c: In function ?_mysql_string_literal?: _mysql.c:1011: error: ?args? undeclared (first use in this function) _mysql.c: In function ?_mysql_escape?: _mysql.c:1088: error: syntax error before ?)? token _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c: At top level: _mysql.c:38:19: _mysql.c:1164: error: syntax error before ?*? token error: mysql.h: No such file or directory _mysql.c: In function ?_mysql_ResultObject_describe?: _mysql.c:1168: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1168: error: ?fields? undeclared (first use in this function) _mysql.c:39:26: error: _mysql.c:1170: error: ?args? undeclared (first use in this function) mysqld_error.h: No such file or directory _mysql.c:1171: error: syntax error before ?)? token_mysql.c:40:20: error: _mysql.c:1171: error: syntax error before ?)? token errmsg.h: No such file or directory _mysql.c:1172: error: ?self? undeclared (first use in this function) _mysql.c:76: error: syntax error before ?MYSQL? _mysql.c:76: warning: no semicolon at end of struct or union _mysql.c:79: error: syntax error before ?}? token _mysql.c:79: warning: data definition has no type or storage class _mysql.c: At top level:_mysql.c:90: error: syntax error before ?MYSQL_RES? _mysql.c:90: warning: no semicolon at end of struct or union _mysql.c:94: error: syntax error before ?}? token _mysql.c:1200: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_field_flags?:_mysql.c:94: warning: data definition has no type or storage class _mysql.c:1204: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1204: error: ?fields? undeclared (first use in this function) _mysql.c:1206: error: ?args? undeclared (first use in this function) _mysql.c:106: error: syntax error before ?*? token _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1208: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_Exception?: _mysql.c:120: error: ?c? undeclared (first use in this function) _mysql.c:120: error: (Each undeclared identifier is reported only once _mysql.c:120: error: for each function it appears in.) _mysql.c:123: error: ?CR_MAX_ERROR? undeclared (first use in this function) _mysql.c:131: error: ?CR_COMMANDS_OUT_OF_SYNC? undeclared (first use in this function) _mysql.c:132: error: ?ER_DB_CREATE_EXISTS? undeclared (first use in this function) _mysql.c:133: error: ?ER_SYNTAX_ERROR? undeclared (first use in this function) _mysql.c:134: error: ?ER_PARSE_ERROR? undeclared (first use in this function) _mysql.c:135: error: ?ER_NO_SUCH_TABLE? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:136: error: ?ER_WRONG_DB_NAME? undeclared (first use in this function) _mysql.c:137: error: ?ER_WRONG_TABLE_NAME? undeclared (first use in this function) _mysql.c:138: error: ?ER_FIELD_SPECIFIED_TWICE? undeclared (first use in this function) _mysql.c:139: error: ?ER_INVALID_GROUP_FUNC_USE? undeclared (first use in this function) _mysql.c:140: error: ?ER_UNSUPPORTED_EXTENSION? undeclared (first use in this function) _mysql.c:141: error: ?ER_TABLE_MUST_HAVE_COLUMNS? undeclared (first use in this function) _mysql.c:170: error: ?ER_DUP_ENTRY? undeclared (first use in this function) _mysql.c:213: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c:1249: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_tuple?: _mysql.c:1256: error: ?self? undeclared (first use in this function) _mysql.c:1258: warning: assignment makes pointer from integer without a cast _mysql.c:1262: error: ?row? undeclared (first use in this function) _mysql.c: At top level:_mysql.c: At top level: _mysql.c:358: error: syntax error before ?*? token _mysql.c:1274: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_dict?: _mysql.c:1280: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1280: error: ?fields? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_Initialize?: _mysql.c:363: error: ?MYSQL_RES? undeclared (first use in this function) _mysql.c:363: error: ?result? undeclared (first use in this function) _mysql.c:364: error: ?conn? undeclared (first use in this function) _mysql.c:368: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:368: error: ?fields? undeclared (first use in this function) _mysql.c:370: error: ?args? undeclared (first use in this function) _mysql.c:370: error: ?kwargs? undeclared (first use in this function) _mysql.c:375: error: ?self? undeclared (first use in this function) _mysql.c:1282: error: ?self? undeclared (first use in this function) _mysql.c:1284: warning: assignment makes pointer from integer without a cast _mysql.c:1289: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:445: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_traverse?: _mysql.c:450: error: ?self? undeclared (first use in this function) _mysql.c:451: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c: At top level:_mysql.c:460: error: syntax error before ?*? token _mysql.c:1313: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_clear?: _mysql.c:462: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_row_to_dict_old?: _mysql.c:1319: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1319: error: ?fields? undeclared (first use in this function) _mysql.c:1321: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1323: warning: assignment makes pointer from integer without a cast _mysql.c:471: error: syntax error before ?*? token _mysql.c:1328: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1350: error: syntax error before ?*? token _mysql.c:1354: error: syntax error before ?*? token _mysql.c: In function ?_mysql__fetch_row?: _mysql.c:1361: error: ?MYSQL_ROW? undeclared (first use in this function) _mysql.c:1361: error: syntax error before ?row? _mysql.c:1363: error: ?skiprows? undeclared (first use in this function) _mysql.c:1363: error: ?maxrows? undeclared (first use in this function) _mysql.c:1365: error: ?self? undeclared (first use in this function) _mysql.c:1366: error: ?row? undeclared (first use in this function) _mysql.c:1372: error: syntax error before ?)? token _mysql.c:1373: error: syntax error before ?)? token _mysql.c: In function ?_mysql_ConnectionObject_Initialize?: _mysql.c:1377: error: ?r? undeclared (first use in this function) _mysql.c:475: error: ?MYSQL? undeclared (first use in this function) _mysql.c:475: error: ?conn? undeclared (first use in this function) _mysql.c:1380: warning: assignment makes pointer from integer without a cast _mysql.c:500: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1400: error: syntax error before ?*? token _mysql.c:503: error: ?args? undeclared (first use in this function) _mysql.c:503: error: ?kwargs? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_fetch_row?: _mysql.c:1404: error: syntax error before ?*? token _mysql.c:550: error: ?MYSQL_OPT_CONNECT_TIMEOUT? undeclared (first use in this function)_mysql.c:1416: error: ?args? undeclared (first use in this function) _mysql.c:1416: error: ?kwargs? undeclared (first use in this function) _mysql.c:554: error: ?MYSQL_OPT_COMPRESS? undeclared (first use in this function) _mysql.c:555: error: ?CLIENT_COMPRESS? undeclared (first use in this function) _mysql.c:558: error: ?MYSQL_OPT_NAMED_PIPE? undeclared (first use in this function) _mysql.c:560: error: ?MYSQL_INIT_COMMAND? undeclared (first use in this function) _mysql.c:562: error: ?MYSQL_READ_DEFAULT_FILE? undeclared (first use in this function)_mysql.c:1419: error: syntax error before ?)? token _mysql.c:1419: error: syntax error before ?)? token_mysql.c:564: error: ?MYSQL_READ_DEFAULT_GROUP? undeclared (first use in this function) _mysql.c:567: error: ?MYSQL_OPT_LOCAL_INFILE? undeclared (first use in this function) _mysql.c: In function ?_mysql_connect?: _mysql.c:654: error: ?c? undeclared (first use in this function) _mysql.c:656: error: syntax error before ?)? token _mysql.c:1427: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:667: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_traverse?: _mysql.c:671: error: ?self? undeclared (first use in this function) _mysql.c:672: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:678: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_clear?: _mysql.c:680: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1507: error: syntax error before ?*? token _mysql.c: At top level: _mysql.c:690: error: syntax error before ?*? token_mysql.c: In function ?_mysql_ConnectionObject_character_set_name?: _mysql.c:1511: error: ?args? undeclared (first use in this function) _mysql.c:1512: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ConnectionObject_close?: _mysql.c:693: error: ?args? undeclared (first use in this function) _mysql.c:696: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_get_client_info?: _mysql.c:1603: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:718: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_affected_rows?: _mysql.c:721: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1613: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_host_info?: _mysql.c:1616: error: ?args? undeclared (first use in this function) _mysql.c:1617: error: ?self? undeclared (first use in this function) _mysql.c:1618: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast_mysql.c:722: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1628: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_proto_info?: _mysql.c:1631: error: ?args? undeclared (first use in this function) _mysql.c:1632: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1643: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_server_info?: _mysql.c:1646: error: ?args? undeclared (first use in this function) _mysql.c:1647: error: ?self? undeclared (first use in this function) _mysql.c:1648: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1659: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_info?: _mysql.c:1663: error: ?args? undeclared (first use in this function) _mysql.c:1664: error: ?self? undeclared (first use in this function) _mysql.c:1665: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:752: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dump_debug_info?: _mysql.c:756: error: ?args? undeclared (first use in this function) _mysql.c:757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1694: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_insert_id?: _mysql.c:1697: error: ?my_ulonglong? undeclared (first use in this function) _mysql.c:1697: error: syntax error before ?r? _mysql.c:1698: error: ?args? undeclared (first use in this function) _mysql.c: At top level:_mysql.c:1699: error: ?self? undeclared (first use in this function) _mysql.c:771: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_autocommit?: _mysql.c:775: error: ?args? undeclared (first use in this function) _mysql.c:1701: error: ?r? undeclared (first use in this function) _mysql.c:783: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1712: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_kill?: _mysql.c:1717: error: ?args? undeclared (first use in this function) _mysql.c: At top level:_mysql.c:1718: error: ?self? undeclared (first use in this function) _mysql.c:797: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_commit?: _mysql.c:801: error: ?args? undeclared (first use in this function) _mysql.c:806: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1735: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_field_count?: _mysql.c: At top level: _mysql.c:819: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_rollback?: _mysql.c:823: error: ?args? undeclared (first use in this function) _mysql.c:828: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:851: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_next_result?: _mysql.c:855: error: ?args? undeclared (first use in this function) _mysql.c:863: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:936: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_errno?: _mysql.c:939: error: ?args? undeclared (first use in this function) _mysql.c:940: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:952: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_error?: _mysql.c:955: error: ?args? undeclared (first use in this function) _mysql.c:956: error: ?self? undeclared (first use in this function) _mysql.c:957: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:970: error: syntax error before ?*? token _mysql.c: In function ?_mysql_escape_string?: _mysql.c:976: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1005: error: syntax error before ?*? token _mysql.c: In function ?_mysql_string_literal?: _mysql.c:1011: error: ?args? undeclared (first use in this function) _mysql.c: In function ?_mysql_escape?: _mysql.c:1088: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:1164: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_describe?: _mysql.c:1168: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1168: error: ?fields? undeclared (first use in this function) _mysql.c:1170: error: ?args? undeclared (first use in this function) _mysql.c:1171: error: syntax error before ?)? token _mysql.c:1171: error: syntax error before ?)? token _mysql.c:1172: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1200: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_field_flags?: _mysql.c:1204: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1204: error: ?fields? undeclared (first use in this function) _mysql.c:1206: error: ?args? undeclared (first use in this function) _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1208: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1249: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_tuple?: _mysql.c:1256: error: ?self? undeclared (first use in this function) _mysql.c:1258: warning: assignment makes pointer from integer without a cast _mysql.c:1262: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1274: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_dict?: _mysql.c:1280: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1280: error: ?fields? undeclared (first use in this function) _mysql.c:1282: error: ?self? undeclared (first use in this function) _mysql.c:1284: warning: assignment makes pointer from integer without a cast _mysql.c:1289: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1313: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_dict_old?: _mysql.c:1319: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1319: error: ?fields? undeclared (first use in this function) _mysql.c:1321: error: ?self? undeclared (first use in this function) _mysql.c:1323: warning: assignment makes pointer from integer without a cast _mysql.c:1328: error: ?row? undeclared (first use in this function) _mysql.c:1738: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1350: error: syntax error before ?*? token _mysql.c:1354: error: syntax error before ?*? token _mysql.c:1739: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql__fetch_row?: _mysql.c:1361: error: ?MYSQL_ROW? undeclared (first use in this function) _mysql.c:1361: error: syntax error before ?row? _mysql.c:1363: error: ?skiprows? undeclared (first use in this function) _mysql.c:1363: error: ?maxrows? undeclared (first use in this function) _mysql.c:1365: error: ?self? undeclared (first use in this function) _mysql.c:1366: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1752: error: syntax error before ?*? token _mysql.c:1372: error: syntax error before ?)? token _mysql.c:1373: error: syntax error before ?)? token _mysql.c:1377: error: ?r? undeclared (first use in this function) _mysql.c:1380: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1400: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_fetch_row?: _mysql.c:1404: error: syntax error before ?*? token _mysql.c:1416: error: ?args? undeclared (first use in this function) _mysql.c:1416: error: ?kwargs? undeclared (first use in this function) _mysql.c:1419: error: syntax error before ?)? token _mysql.c:1419: error: syntax error before ?)? token _mysql.c:1427: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1507: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_character_set_name?: _mysql.c:1511: error: ?args? undeclared (first use in this function) _mysql.c:1512: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_get_client_info?: _mysql.c:1603: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1613: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_host_info?: _mysql.c:1616: error: ?args? undeclared (first use in this function) _mysql.c:1617: error: ?self? undeclared (first use in this function) _mysql.c:1618: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1628: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_proto_info?: _mysql.c:1631: error: ?args? undeclared (first use in this function) _mysql.c:1632: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_num_fields?: _mysql.c: At top level: _mysql.c:1643: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_server_info?: _mysql.c:1646: error: ?args? undeclared (first use in this function) _mysql.c:1647: error: ?self? undeclared (first use in this function) _mysql.c:1648: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1659: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_info?: _mysql.c:1663: error: ?args? undeclared (first use in this function) _mysql.c:1664: error: ?self? undeclared (first use in this function) _mysql.c:1665: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1694: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_insert_id?: _mysql.c:1697: error: ?my_ulonglong? undeclared (first use in this function) _mysql.c:1697:_mysql.c:1755: error: ?args? undeclared (first use in this function) _mysql.c:1756: error: syntax error before ?)? token _mysql.c:1756: error: syntax error before ?)? token _mysql.c:1757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1768: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_num_rows?: _mysql.c:1771: error: ?args? undeclared (first use in this function) _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1773: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1797: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_ping?: _mysql.c:1801: error: ?args? undeclared (first use in this function) _mysql.c:1802: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1820: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_query?: _mysql.c:1825: error: ?args? undeclared (first use in this function) _mysql.c:1826: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1850: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_select_db?: _mysql.c:1855: error: ?args? undeclared (first use in this function) _mysql.c:1856: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1872: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_shutdown?: _mysql.c:1876: error: ?args? undeclared (first use in this function) _mysql.c:1877: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1899: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_stat?: _mysql.c:1903: error: ?args? undeclared (first use in this function) _mysql.c:1904: error: ?self? undeclared (first use in this function) _mysql.c:1906: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1920: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_store_result?: _mysql.c:1924: error: ?r? undeclared (first use in this function) _mysql.c:1926: error: ?args? undeclared (first use in this function) _mysql.c:1927: error: ?self? undeclared (first use in this function) _mysql.c:1932: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:1961: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_thread_id?: _mysql.c:1965: error: ?args? undeclared (first use in this function) _mysql.c:1966: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1981: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_use_result?: _mysql.c:1985: error: ?r? undeclared (first use in this function) _mysql.c:1987: error: ?args? undeclared (first use in this function) _mysql.c:1988: error: ?self? undeclared (first use in this function) _mysql.c:1993: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:2011: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dealloc?: _mysql.c:2015: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2025: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_repr?: _mysql.c:2028: error: ?self? undeclared (first use in this function) error: syntax error before ?r? _mysql.c:1698: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2042: error: syntax error before ?*? token _mysql.c:1699: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_data_seek?: _mysql.c:2046: error: ?args? undeclared (first use in this function) _mysql.c:1701: error: ?r? undeclared (first use in this function) _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2048: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2057: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_seek?: _mysql.c:2061: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2061: error: syntax error before ?r? _mysql.c:2062: error: ?args? undeclared (first use in this function) _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2064: error: ?self? undeclared (first use in this function) _mysql.c:2069: error: ?r? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2079: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_tell?: _mysql.c:2082: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2082: error: syntax error before ?r? _mysql.c:2083: error: ?args? undeclared (first use in thi_mysql.c: At top level:s function) _mysql.c:1712: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_kill?: _mysql.c:1717: error: ?args? undeclared (first use in this function) _mysql.c:2084: error: syntax error before ?)? token _mysql.c:2084: error: syntax error before ?)? token _mysql.c:1718: error: ?self? undeclared (first use in this function) _mysql.c:2085: error: ?self? undeclared (first use in this function) _mysql.c:2090: error: ?r? undeclared (first use in this function) _mysql.c: At top level:_mysql.c: At top level: _mysql.c:1735: error: syntax error before ?*? token _mysql.c:2096: error: syntax error before ?*? token_mysql.c: In function ?_mysql_ConnectionObject_field_count?: _mysql.c:1738: error: ?args? undeclared (first use in this function) _mysql.c:1739: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_dealloc?: _mysql.c:2098: error: ?self? undeclared (first use in this function) _mysql.c: At top level:_mysql.c: At top level: _mysql.c:1752: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_num_fields?: _mysql.c:2106: error: syntax error before ?*? token _mysql.c:1755: error: ?args? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_repr?: _mysql.c:1756: error: syntax error before ?)? token _mysql.c:2110: error: ?self? undeclared (first use in this function) _mysql.c:1756: error: syntax error before ?)? token _mysql.c:1757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1768: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_num_rows?: _mysql.c:1771: error: ?args? undeclared (first use in this function) _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1773: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1797: error: syntax error before ?*? token_mysql.c: At top level: _mysql.c:2330: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2337: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2344: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2351: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2358: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2421: error: syntax error before ?_mysql_ResultObject? _mysql.c:2433: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_getattr?: _mysql.c:2438: error: ?self? undeclared (first use in this function) _mysql.c:2438: error: ?name? undeclared (first use in this function) _mysql.c:2438: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2438: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2442: warning: passing argument 1 of ?strcmp? from incompatible pointer type _mysql.c:2443: error: ?struct PyMemberDef? has no member named ?open? _mysql.c:2450: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2451: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2453: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2461: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_getattr?: _mysql.c:2466: error: ?self? undeclared (first use in this function) _mysql.c:2466: error: ?name? undeclared (first use in this function) _mysql.c:2466: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2466: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2476: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2477: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2479: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2487: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_setattr?: _mysql.c:2491: error: ?v? undeclared (first use in this function) _mysql.c:2502: error: ?name? undeclared (first use in this function) _mysql.c:2502: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2503: error: ?self? undeclared (first use in this function) _mysql.c:2503: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2503: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2505: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2512: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_setattr?: _mysql.c:2516: error: ?v? undeclared (first use in this function) _mysql.c:2527: error: ?name? undeclared (first use in this function) _mysql.c:2527: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2528: error: ?self? undeclared (first use in this function) _mysql.c:2528: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2528: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2530: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: In function ?_mysql_ConnectionObject_ping?: _mysql.c:1801: error: ?args? undeclared (first use in this function) _mysql.c:1802: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1820: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_query?: _mysql.c:1825: error: ?args? undeclared (first use in this function) _mysql.c:1826: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1850: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_select_db?: _mysql.c:1855: error: ?args? undeclared (first use in this function) _mysql.c:1856: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1872: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_shutdown?: _mysql.c:1876: error: ?args? undeclared (first use in this function) _mysql.c:1877: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1899: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_stat?: _mysql.c:1903: error: ?args? undeclared (first use in this function) _mysql.c:1904: error: ?self? undeclared (first use in this function) _mysql.c:1906: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1920: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_store_result?: _mysql.c:1924: error: ?r? undeclared (first use in this function) _mysql.c:1926: error: ?args? undeclared (first use in this function) _mysql.c:1927: error: ?self? undeclared (first use in this function) _mysql.c:1932: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:1961: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_thread_id?: _mysql.c:1965: error: ?args? undeclared (first use in this function) _mysql.c:1966: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1981: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_use_result?: _mysql.c:1985: error: ?r? undeclared (first use in this function) _mysql.c:1987: error: ?args? undeclared (first use in this function) _mysql.c:1988: error: ?self? undeclared (first use in this function) _mysql.c:1993: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:2011: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dealloc?: _mysql.c:2015: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2025: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_repr?: _mysql.c:2028: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2042: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_data_seek?: _mysql.c:2046: error: ?args? undeclared (first use in this function) _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2048: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2057: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_seek?: _mysql.c:2061: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2061: error: syntax error before ?r? _mysql.c:2062: error: ?args? undeclared (first use in this function) _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2064: error: ?self? undeclared (first use in this function) _mysql.c:2069: error: ?r? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2079: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_tell?: _mysql.c:2082: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2082: error: syntax error before ?r? _mysql.c:2083: error: ?args? undeclared (first use in this function) _mysql.c:2084: error: syntax error before ?)? token _mysql.c:2084: error: syntax error before ?)? token _mysql.c:2085: error: ?self? undeclared (first use in this function) _mysql.c:2090: error: ?r? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2096: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_dealloc?: _mysql.c:2098: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2106: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_repr?: _mysql.c:2110: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2330: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2337: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2344: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2351: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2358: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2421: error: syntax error before ?_mysql_ResultObject? _mysql.c:2433: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_getattr?: _mysql.c:2438: error: ?self? undeclared (first use in this function) _mysql.c:2438: error: ?name? undeclared (first use in this function) _mysql.c:2438: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2438: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2442: warning: passing argument 1 of ?strcmp? from incompatible pointer type _mysql.c:2443: error: ?struct PyMemberDef? has no member named ?open? _mysql.c:2450: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2451: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2453: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2461: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_getattr?: _mysql.c:2466: error: ?self? undeclared (first use in this function) _mysql.c:2466: error: ?name? undeclared (first use in this function) _mysql.c:2466: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2466: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2476: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2477: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2479: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2487: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_setattr?: _mysql.c:2491: error: ?v? undeclared (first use in this function) _mysql.c:2502: error: ?name? undeclared (first use in this function) _mysql.c:2502: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2503: error: ?self? undeclared (first use in this function) _mysql.c:2503: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2503: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2505: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2512: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_setattr?: _mysql.c:2516: error: ?v? undeclared (first use in this function) _mysql.c:2527: error: ?name? undeclared (first use in this function) _mysql.c:2527: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2528: error: ?self? undeclared (first use in this function) _mysql.c:2528: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2528: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2530: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type lipo: can't figure out the architecture type of: /var/folders/o5/ o5kYdZHuE3uFkIwBSAbeXE+++TI/-Tmp-//cctMmmFT.out error: command 'gcc-4.0' failed with exit status 1 From 54wutong at gmail.com Mon Feb 1 04:17:09 2010 From: 54wutong at gmail.com (Stephen.Wu) Date: Mon, 1 Feb 2010 01:17:09 -0800 (PST) Subject: how long a Str can be used in this python code segment? Message-ID: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> tmp=file.read() (very huge file) if targetStr in tmp: print "find it" else: print "not find" file.close() I checked if file.read() is huge to some extend, it doesn't work, but could any give me some certain information on this prolbem? From gherron at islandtraining.com Mon Feb 1 04:23:31 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 01 Feb 2010 01:23:31 -0800 Subject: gmtime In-Reply-To: <62938b5b-7eda-426c-b91d-3c7061840b2d@l26g2000yqd.googlegroups.com> References: <62938b5b-7eda-426c-b91d-3c7061840b2d@l26g2000yqd.googlegroups.com> Message-ID: <4B669D93.4070609@islandtraining.com> gazza wrote: > Hi, > > I am trying to discover how to obtain the correct time of say CST/ > America and EST/America in python? > > Any help on this would be appreciated. > > > Thanks, > Garyc > The datetime module should give you all you need. Gary Herron From clp2 at rebertia.com Mon Feb 1 04:26:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 01:26:55 -0800 Subject: how long a Str can be used in this python code segment? In-Reply-To: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: <50697b2c1002010126n7602495dlbf9cfc90755c8825@mail.gmail.com> On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wutong at gmail.com> wrote: > tmp=file.read() (very huge file) > if targetStr in tmp: > ? ?print "find it" > else: > ? ?print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? If the file's contents is larger than available memory, you'll get a MemoryError. To avoid this, you can read the file in by chunks (or if applicable, by lines) and see if each chunk/line matches. Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Mon Feb 1 04:29:20 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 01 Feb 2010 01:29:20 -0800 Subject: how long a Str can be used in this python code segment? In-Reply-To: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: <4B669EF0.800@islandtraining.com> Stephen.Wu wrote: > tmp=file.read() (very huge file) > if targetStr in tmp: > print "find it" > else: > print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? > > Python has no specific limit on string size other than memory size and perhaps 32 bit address space and so on. However, if your file size is even a fraction of that size, you should not attempt to read it all into memory at once. Is there not a way to process your file in batches of a reasonable size? Gary Herron From 54wutong at gmail.com Mon Feb 1 04:33:09 2010 From: 54wutong at gmail.com (Stephen.Wu) Date: Mon, 1 Feb 2010 01:33:09 -0800 (PST) Subject: how long a Str can be used in this python code segment? References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: On Feb 1, 5:26?pm, Chris Rebert wrote: > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wut... at gmail.com> wrote: > > tmp=file.read() (very huge file) > > if targetStr in tmp: > > ? ?print "find it" > > else: > > ? ?print "not find" > > file.close() > > > I checked if file.read() is huge to some extend, it doesn't work, but > > could any give me some certain information on this prolbem? > > If the file's contents is larger than available memory, you'll get a > MemoryError. To avoid this, you can read the file in by chunks (or if > applicable, by lines) and see if each chunk/line matches. > > Cheers, > Chris > --http://blog.rebertia.com actually, I just use file.read(length) way, i just want to know what exactly para of length I should set, I'm afraid length doesn't equal to the amount of physical memory after trials... From stefan_ml at behnel.de Mon Feb 1 04:45:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Feb 2010 10:45:28 +0100 Subject: how long a Str can be used in this python code segment? In-Reply-To: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: <4b66a2b8$0$6582$9b4e6d93@newsspool3.arcor-online.net> Stephen.Wu, 01.02.2010 10:17: > tmp=file.read() (very huge file) > if targetStr in tmp: > print "find it" > else: > print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? Others have already pointed out that reading the entire file into memory is not a good idea. Try reading chunks repeatedly instead. As it appears that you simply try to find out if a file contains a specific byte sequence, you might find acora interesting: http://pypi.python.org/pypi/acora Also note that there are usually platform optimised tools available to search content in files, e.g. grep. It's basically impossible to beat their raw speed even with hand-tuned Python code, so running the right tool using the subprocess module might be a solution. Stefan From fetchinson at googlemail.com Mon Feb 1 05:14:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Feb 2010 11:14:42 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> Message-ID: > PEP 3147 has just been posted, proposing that, beginning in release > 3.2 (and possibly 2.7) compiled .pyc and .pyo files be placed in a > directory with a .pyr extension. The reason is so that compiled > versions of a program can coexist, which isn't possible now. > > Frankly, I think this is a really good idea, although I've got a few > comments. > > 1. Apple's MAC OS X should be mentioned, since 10.5 (and presumably > 10.6) ship with both Python release 2.3 and 2.5 installed. > > 2. I think the proposed logic is too complex. If this is installed in > 3.2, then that release should simply store its .pyc file in the .pyr > directory, without the need for either a command line switch or an > environment variable (both are mentioned in the PEP.) > > 3. Tool support. There are tools that look for the .pyc files; these > need to be upgraded somehow. The ones that ship with Python should, of > course, be fixed with the PEP, but there are others. > > 4. I'm in favor of putting the source in the .pyr directory as well, > but that's got a couple more issues. One is tool support, which is > likely to be worse for source, and the other is some kind of algorithm > for identifying which source goes with which object. I also think the PEP is a great idea and proposes a solution to a real problem. But I also hear the 'directory clutter' argument and I'm really concerned too, having all these extra directories around (and quite a large number of them indeed!). How about this scheme: 1. install python source files to a shared (among python installations) location /this/is/shared 2. when python X.Y imports a source file from /this/is/shared it will create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ Time comparison would be between /this/is/shared/x.py and /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. Obviously pythonX.Y needs to know the path to /this/is/shared so it can import modules from there, but this can be controlled by an environment variable. There would be only .py files in /this/is/shared. Linux distro packagers would only offer a single python-myapp to install and it would only contain python source, and the version-specific pyc files would be created the first time the application is used by python. In /usr/lib/pythonX.Y/site-packages there would be only pyc files with magic number matching python X.Y. So, basically nothing would change only the location of py and pyc files would be different from current behavior, but the same algorithm would be run to determine which one to load, when to create a pyc file, when to ignore the old one, etc. What would be wrong with this setup? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From peloko45 at gmail.com Mon Feb 1 05:19:39 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 1 Feb 2010 02:19:39 -0800 (PST) Subject: User-defined exceptions from 2.6 Message-ID: <12ef62c2-b291-414d-ad58-c18c2811379d@c29g2000yqd.googlegroups.com> Which is the best way to create user-defined exceptions since that *BaseException.message* is deprecated in Python 2.6 ? From jeanmichel at sequans.com Mon Feb 1 05:25:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Feb 2010 11:25:15 +0100 Subject: SimpleXMLRPCServer daemon In-Reply-To: References: <1e689e5c-8e2a-4896-b867-717316fa783e@o26g2000vbd.googlegroups.com> Message-ID: <4B66AC0B.8050404@sequans.com> Gabriel Genellina wrote: > En Fri, 29 Jan 2010 12:54:23 -0300, Thomas Allen > escribi?: > >> I have a script that runs an instance of SimpleXMLRPCServer and in >> general it works as expected. In its __del__, it is supposed to clean >> up its PID file (written on boot). I have two problems with this >> server instance: The first is that tt doesn't always clean up its PID >> file; is there a more reliable way to do this than how I am currently? >> The second is that when it does crash, I don't know about it...what >> would be sufficient as a "keep-alive" script to restart it? I suppose >> I could use something like EventMachine (already installed on my >> server) to watch the PID file if it were deleted reliably. > > I agree with the recommendation of using some daemon library; doing it > right is better left to the experts :) > But if you can't or don't want to alter your code so much, I suggest: > > - use atexit.register, instead of __del__, to delete the PID file > - keep a lock on the pid file; if a second instance is able to write > to it, it means it's an orphan from a previous, aborted run. (Checking > whether a process with such pid exists is not enough - pids are > recycled rather fast) > see also http://code.activestate.com/recipes/278731/ JM From rohitraj007 at gmail.com Mon Feb 1 05:26:13 2010 From: rohitraj007 at gmail.com (Rohit Roger$) Date: Mon, 1 Feb 2010 15:56:13 +0530 Subject: Python-list Digest, Vol 77, Issue 7 * In-Reply-To: <4755336292109192622@unknownmsgid> References: <4755336292109192622@unknownmsgid> Message-ID: Hello Help for datetime module Source code is : *from *datetime *import *datetime d = datetime(datetime.now().year, datetime.now().month, datetime.now().day, 11, 59, 0 ) print d On Mon, Feb 1, 2010 at 3:44 PM, wrote: > Junk Score: 2 out of 10 (below your Auto Allow threshold) > | Approve sender | Block > sender | Block > domain > > 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: whassup? builtins? python3000? Naah can't be right? > (Andrej Mitrovic) > 2. gmtime (gazza) > 3. Re: A performance issue when using default value (keakon) > 4. Re: HTML Parser which allows low-keyed local changes? > (Stefan Behnel) > 5. how long a Str can be used in this python code segment? > (Stephen.Wu) > 6. Re: gmtime (Gary Herron) > 7. Re: how long a Str can be used in this python code segment? > (Chris Rebert) > 8. Re: how long a Str can be used in this python code segment? > (Gary Herron) > 9. Re: Keyboard input (Dennis Lee Bieber) > 10. Re: how long a Str can be used in this python code segment? > (Stephen.Wu) > 11. Re: how long a Str can be used in this python code segment? > (Stefan Behnel) > 12. Re: PEP 3147 - new .pyc format (Daniel Fetchinson) > > > ---------- Forwarded message ---------- > From: Andrej Mitrovic > To: > Date: Sun, 31 Jan 2010 20:01:57 -0800 (PST) > Subject: Re: whassup? builtins? python3000? Naah can't be right? > Hey, it's really simple! Just like the excerpt from the Learning > Python book says: > > "Really, the built-in scope is just a built-in module called builtins, > but > you have to import builtins to query built-ins because the name > builtins is not itself > built-in...." > > :) > > > > ---------- Forwarded message ---------- > From: gazza > To: > Date: Sun, 31 Jan 2010 13:27:46 -0800 (PST) > Subject: gmtime > Hi, > > I am trying to discover how to obtain the correct time of say CST/ > America and EST/America in python? > > Any help on this would be appreciated. > > > Thanks, > Garyc > > > > ---------- Forwarded message ---------- > From: keakon > To: > Date: Sun, 31 Jan 2010 21:20:28 -0800 (PST) > Subject: Re: A performance issue when using default value > Even this style is 41 times faster than h2(): > > def i2(x=[]): > y = x > if not y: # add this line > y = [] # add this line > y.append(1) > return y + [] > > print Timer('i2()','from __main__ import f2, g2, h2, i2').timeit > (TIMES) > > Time: 0.00742356919664 > > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: > Date: Mon, 01 Feb 2010 09:34:28 +0100 > Subject: Re: HTML Parser which allows low-keyed local changes? > Robert, 31.01.2010 20:57: > > I tried lxml, but after walking and making changes in the element tree, > > I'm forced to do a full serialization of the whole document > > (etree.tostring(tree)) - which destroys the "human edited" format of the > > original HTML code. makes it rather unreadable. > > What do you mean? Could you give an example? lxml certainly does not > destroy anything it parsed, unless you tell it to do so. > > Stefan > > > > ---------- Forwarded message ---------- > From: "Stephen.Wu" <54wutong at gmail.com> > To: python-list at python.org > Date: Mon, 1 Feb 2010 01:17:09 -0800 (PST) > Subject: how long a Str can be used in this python code segment? > tmp=file.read() (very huge file) > if targetStr in tmp: > print "find it" > else: > print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? > > > > > ---------- Forwarded message ---------- > From: Gary Herron > To: "python-list at python.org" > Date: Mon, 01 Feb 2010 01:23:31 -0800 > Subject: Re: gmtime > gazza wrote: > >> Hi, >> >> I am trying to discover how to obtain the correct time of say CST/ >> America and EST/America in python? >> >> Any help on this would be appreciated. >> >> >> Thanks, >> Garyc >> >> > The datetime module should give you all you need. > > Gary Herron > > > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: "Stephen.Wu" <54wutong at gmail.com> > Date: Mon, 1 Feb 2010 01:26:55 -0800 > Subject: Re: how long a Str can be used in this python code segment? > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wutong at gmail.com> wrote: > > tmp=file.read() (very huge file) > > if targetStr in tmp: > > print "find it" > > else: > > print "not find" > > file.close() > > > > I checked if file.read() is huge to some extend, it doesn't work, but > > could any give me some certain information on this prolbem? > > If the file's contents is larger than available memory, you'll get a > MemoryError. To avoid this, you can read the file in by chunks (or if > applicable, by lines) and see if each chunk/line matches. > > Cheers, > Chris > -- > http://blog.rebertia.com > > > > ---------- Forwarded message ---------- > From: Gary Herron > To: > Date: Mon, 01 Feb 2010 01:29:20 -0800 > Subject: Re: how long a Str can be used in this python code segment? > Stephen.Wu wrote: > >> tmp=file.read() (very huge file) >> if targetStr in tmp: >> print "find it" >> else: >> print "not find" >> file.close() >> >> I checked if file.read() is huge to some extend, it doesn't work, but >> could any give me some certain information on this prolbem? >> >> >> > > Python has no specific limit on string size other than memory size and > perhaps 32 bit address space and so on. However, if your file size is even > a fraction of that size, you should not attempt to read it all into memory > at once. Is there not a way to process your file in batches of a reasonable > size? > > Gary Herron > > > > > > ---------- Forwarded message ---------- > From: Dennis Lee Bieber > To: python-list at python.org > Date: Mon, 01 Feb 2010 01:31:25 -0800 > Subject: Re: Keyboard input > On 31 Jan 2010 22:40:55 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > > On Sun, 31 Jan 2010 14:10:34 -0800, Dennis Lee Bieber wrote: > > > > > On Sun, 31 Jan 2010 11:51:46 +0000, "Mr.SpOOn" > > > declaimed the following in gmane.comp.python.general: > > > > > >> 2010/1/29 Gabriel Genellina : > > >> > > > >> > That's strange. If you're using Linux, make sure you have the > > >> > readline package installed. > > >> > > >> I'm using Linux. Ubuntu. I checked on synaptic and I have > > >> readline-common. Do you mean something else? > > >> > > > But was your Python /built/ using readline? > > > > > > How do you ensure that it is? > > Well... I think the practice on the Linux variants is to set various > options when building Python locally. I'm on WinXP and rely upon the > packagers to build with everything available (and may need to check > the documentation of those builds as described by the packagers) > > It may mean ensuring not only that the runtime library is present, > but that the development library (C-language header files, etc.) are > installed. > -- > Wulfraed Dennis Lee Bieber KD6MOG > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > > > ---------- Forwarded message ---------- > From: "Stephen.Wu" <54wutong at gmail.com> > To: python-list at python.org > Date: Mon, 1 Feb 2010 01:33:09 -0800 (PST) > Subject: Re: how long a Str can be used in this python code segment? > On Feb 1, 5:26 pm, Chris Rebert wrote: > > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wut... at gmail.com> wrote: > > > tmp=file.read() (very huge file) > > > if targetStr in tmp: > > > print "find it" > > > else: > > > print "not find" > > > file.close() > > > > > I checked if file.read() is huge to some extend, it doesn't work, but > > > could any give me some certain information on this prolbem? > > > > If the file's contents is larger than available memory, you'll get a > > MemoryError. To avoid this, you can read the file in by chunks (or if > > applicable, by lines) and see if each chunk/line matches. > > > > Cheers, > > Chris > > --http://blog.rebertia.com > > actually, I just use file.read(length) way, i just want to know what > exactly para of length I should set, I'm afraid length doesn't equal > to the amount of physical memory after trials... > > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Mon, 01 Feb 2010 10:45:28 +0100 > Subject: Re: how long a Str can be used in this python code segment? > Stephen.Wu, 01.02.2010 10:17: > > tmp=file.read() (very huge file) > > if targetStr in tmp: > > print "find it" > > else: > > print "not find" > > file.close() > > > > I checked if file.read() is huge to some extend, it doesn't work, but > > could any give me some certain information on this prolbem? > > Others have already pointed out that reading the entire file into memory is > not a good idea. Try reading chunks repeatedly instead. > > As it appears that you simply try to find out if a file contains a specific > byte sequence, you might find acora interesting: > > http://pypi.python.org/pypi/acora > > Also note that there are usually platform optimised tools available to > search content in files, e.g. grep. It's basically impossible to beat their > raw speed even with hand-tuned Python code, so running the right tool using > the subprocess module might be a solution. > > Stefan > > > > ---------- Forwarded message ---------- > From: Daniel Fetchinson > To: Python > Date: Mon, 1 Feb 2010 11:14:42 +0100 > Subject: Re: PEP 3147 - new .pyc format > > PEP 3147 has just been posted, proposing that, beginning in release > > 3.2 (and possibly 2.7) compiled .pyc and .pyo files be placed in a > > directory with a .pyr extension. The reason is so that compiled > > versions of a program can coexist, which isn't possible now. > > > > Frankly, I think this is a really good idea, although I've got a few > > comments. > > > > 1. Apple's MAC OS X should be mentioned, since 10.5 (and presumably > > 10.6) ship with both Python release 2.3 and 2.5 installed. > > > > 2. I think the proposed logic is too complex. If this is installed in > > 3.2, then that release should simply store its .pyc file in the .pyr > > directory, without the need for either a command line switch or an > > environment variable (both are mentioned in the PEP.) > > > > 3. Tool support. There are tools that look for the .pyc files; these > > need to be upgraded somehow. The ones that ship with Python should, of > > course, be fixed with the PEP, but there are others. > > > > 4. I'm in favor of putting the source in the .pyr directory as well, > > but that's got a couple more issues. One is tool support, which is > > likely to be worse for source, and the other is some kind of algorithm > > for identifying which source goes with which object. > > I also think the PEP is a great idea and proposes a solution to a real > problem. But I also hear the 'directory clutter' argument and I'm > really concerned too, having all these extra directories around (and > quite a large number of them indeed!). How about this scheme: > > 1. install python source files to a shared (among python > installations) location /this/is/shared > 2. when python X.Y imports a source file from /this/is/shared it will > create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ > Time comparison would be between /this/is/shared/x.py and > /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. > > Obviously pythonX.Y needs to know the path to /this/is/shared so it > can import modules from there, but this can be controlled by an > environment variable. There would be only .py files in > /this/is/shared. > > Linux distro packagers would only offer a single python-myapp to > install and it would only contain python source, and the > version-specific pyc files would be created the first time the > application is used by python. In /usr/lib/pythonX.Y/site-packages > there would be only pyc files with magic number matching python X.Y. > > So, basically nothing would change only the location of py and pyc > files would be different from current behavior, but the same algorithm > would be run to determine which one to load, when to create a pyc > file, when to ignore the old one, etc. > > What would be wrong with this setup? > > Cheers, > Daniel > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gjango.py at gmail.com Mon Feb 1 05:35:06 2010 From: gjango.py at gmail.com (guptha) Date: Mon, 1 Feb 2010 02:35:06 -0800 (PST) Subject: Any Python Module to send ring tones from PC to mobile via GSM modem Message-ID: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> Hi group, Is there any python module available which sends ring tones from our PC to mobile phone using GSM Modem. I googled in vain to find a solution .I can find few modules like pygsm ,singshotsms by which only sms is send .I could appreciate if some one helps me to find a way to send ring tones . Thanks Ganesh From tino at wildenhain.de Mon Feb 1 06:07:36 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Mon, 01 Feb 2010 12:07:36 +0100 Subject: Any Python Module to send ring tones from PC to mobile via GSM modem In-Reply-To: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> References: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> Message-ID: <4B66B5F8.9020506@wildenhain.de> Hi Ganesh, Am 01.02.2010 11:35, schrieb guptha: > Hi group, > Is there any python module available which sends ring tones from our > PC to mobile phone using GSM Modem. > I googled in vain to find a solution .I can find few modules like > pygsm ,singshotsms by which only sms is send .I could appreciate if > some one helps me to find a way to send ring tones . If you really want to send via GSM (e.g. over the air to another Phone) it seems you need to generate an MMS instead of SMS. If thats not the case and you only want to upload tones to your phone via wire/bluetooth, obex should be the key to find more information on how to do that. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3254 bytes Desc: S/MIME Cryptographic Signature URL: From stef.mientki at gmail.com Mon Feb 1 06:14:13 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 01 Feb 2010 12:14:13 +0100 Subject: how to decode rtf characterset ? Message-ID: <4B66B785.1090406@gmail.com> hello, I want to translate rtf files to unicode strings. I succeeded in remove all the tags, but now I'm stucked to the special accent characters, like : "V??r" the character "?" is represented by the string r"\'f3", or in bytes: 92, 39,102, 51 so I think I need a way to translate that into the string r"\xf3" but I can't find a way to accomplish that. a Any suggestions are very welcome. thanks, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From bblais at bryant.edu Mon Feb 1 06:27:27 2010 From: bblais at bryant.edu (Brian Blais) Date: Mon, 01 Feb 2010 06:27:27 -0500 Subject: [Edu-sig] odd drawing problem with turtle.py In-Reply-To: References: Message-ID: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> > On Jan 31, 2010, at 23:05 , John Posner wrote: > >> Try commenting out this statement: >> >> self.turtle.tracer(False) >> >> That helps on Python 2.6.4. interesting. It seems as if the tracer property is a global one: In [1]:t1=Turtle() In [2]:t1.tracer() Out[2]:1 In [3]:t1.tracer(False) In [4]:t1.tracer() Out[4]:0 In [5]:t2=Turtle() In [6]:t2.tracer() Out[6]:0 In [7]:t2.tracer(True) In [8]:t1.tracer() Out[8]:1 looks like I need to set the tracer manually. however, even if the tracer is off, shouldn't it still draw the line? when I put in the T.tracer(True) it works, but I shouldn't need to I think. On Jan 31, 2010, at 21:11 , kirby urner wrote: > I don't see where you've defined a Turtle class to instantiate sir. Turtle is given in turtle.py. I should have subclassed it, but I was being lazy. :) thanks for the fast replies! bb > On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais > wrote: >> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - >> 24. 9. >> 2009. The following script draws 5 circles, which it is supposed >> to, but >> then doesn't draw the second turtle which is supposed to simply move >> forward. Any ideas? >> from turtle import * >> from numpy.random import randint >> resetscreen() >> class Circle(object): >> def __init__(self,x,y,r,color): >> self.x=x >> self.y=y >> self.r=r >> self.color=color >> >> self.turtle=Turtle(visible=False) >> self.turtle.tracer(False) >> self.draw() >> >> def draw(self): >> self.turtle.penup() >> self.turtle.setposition(self.x,self.y) >> self.turtle.setheading(0) >> self.turtle.backward(self.r) >> self.turtle.pendown() >> self.turtle.fill(True) >> self.turtle.pencolor("black") >> self.turtle.fillcolor(self.color) >> self.turtle.circle(self.r) >> self.turtle.fill(False) >> self.turtle.penup() >> >> for i in range(5): >> c=Circle(randint(-350,350),randint(-250,250),10,"red") >> >> >> T=Turtle() >> T.forward(100) >> T.forward(100) >> >> >> >> >> >> >> >> thanks, >> >> bb >> -- >> Brian Blais >> bblais at bryant.edu >> http://web.bryant.edu/~bblais >> http://bblais.blogspot.com/ >> >> >> >> _______________________________________________ >> Edu-sig mailing list >> Edu-sig at python.org >> http://mail.python.org/mailman/listinfo/edu-sig >> >> -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gobladoome at gmail.com Mon Feb 1 06:36:00 2010 From: gobladoome at gmail.com (Paul Atkin) Date: Tue, 2 Feb 2010 00:36:00 +1300 Subject: Embedded python 2.6 in C++ problems Message-ID: <5089497e1002010336k3e3882el451fc4e56946e7cd@mail.gmail.com> Hi, I'm extending some old Visual Studio 6 MFC code to add embedded python scripting. It works fine most of the time but some python function calls do not work as expected. The C++ code is a multithreaded MFC application. I was assuming that it was GIL issues but I have tried using the manual locking (PyEval_SaveThread & PyEval_RestoreThread) and what seems to be the current method (PyGILState_Ensure & PyGILState_Release) Here's the error I'm getting: Traceback (most recent call last): File "...scripts\receipt_parser.py", line 296, in get_giftcard_purchase_value details = extract_transaction_details_section(test) File "...scripts\receipt_parser.py", line 204, in extract_transaction_details_section for line in base_details: TypeError: expected string or Unicode object, NoneType found base_details is a string variable and the code runs fine when run from standard interpreter. Many other function calls work fine from the embedded app. I create and then Py_DECREF the function parameters and the return value after each function call. The module import is created at C++ object constructor and then Py_DECREF'd in the desctuctor Anyone else had issues of this kind? Thanks, Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gobladoome at gmail.com Mon Feb 1 06:51:48 2010 From: gobladoome at gmail.com (Paul Atkin) Date: Tue, 2 Feb 2010 00:51:48 +1300 Subject: Embedded python 2.6 in C++ problems Message-ID: <5089497e1002010351s773d5a87pb3df73e20f00f1f5@mail.gmail.com> Hi, I'm extending some old Visual Studio 6 MFC code to add embedded python scripting. It works fine most of the time but some python function calls do not work as expected. The C++ code is a multithreaded MFC application. I was assuming that it was GIL issues but I have tried using the manual locking (PyEval_SaveThread & PyEval_RestoreThread) and what seems to be the current method (PyGILState_Ensure & PyGILState_Release) Here's the error I'm getting: Traceback (most recent call last): File "...scripts\receipt_parser.py", line 296, in get_giftcard_purchase_value details = extract_transaction_details_section(test) File "...scripts\receipt_parser.py", line 204, in extract_transaction_details_section for line in base_details: TypeError: expected string or Unicode object, NoneType found base_details is a string variable and the code runs fine when run from standard interpreter. Many other function calls work fine from the embedded app. I create and then Py_DECREF the function parameters and the return value after each function call. The module import is created at C++ object constructor and then Py_DECREF'd in the desctuctor Anyone else had issues of this kind? Thanks, Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Mon Feb 1 07:06:25 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 1 Feb 2010 12:06:25 +0000 (UTC) Subject: recv_into(bytearray) complains about a "pinned buffer" References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> Message-ID: Le Mon, 01 Feb 2010 03:30:56 +0100, Martin v. Loewis a ?crit?: > >> Is this a bug in Python 2.6 or a deliberate choice regarding >> implementation concerns I don't know about? > > It's actually a bug also that you pass an array; doing so *should* give > the very same error. Well, if you can give neither an array nor a bytearray to recv_into(), what *could* you give it? recv_into() should simply be fixed to use the new buffer API, as it does in 3.x. From gjango.py at gmail.com Mon Feb 1 07:39:47 2010 From: gjango.py at gmail.com (guptha) Date: Mon, 1 Feb 2010 04:39:47 -0800 (PST) Subject: Any Python Module to send ring tones from PC to mobile via GSM modem References: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> Message-ID: <8406f031-202a-4245-8038-edf548dbad6c@v20g2000prb.googlegroups.com> Hi,Tino Thanks for your reply, My PC is connected with cell phone (through data card) as a modem,and my OS is Ubuntu I have to send ring tones from my PC to any other cell phone by using connected cell phone as a modem (Your first case satisfy my need ) I think with pygsm, it is not possible to send MMS,if so what could be the apt python module to work with .what about python-gammu? can any one point me a url which gives detail tutorial on this topic thanks ganesh From steve at REMOVE-THIS-cybersource.com.au Mon Feb 1 07:45:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 12:45:53 GMT Subject: User-defined exceptions from 2.6 References: <12ef62c2-b291-414d-ad58-c18c2811379d@c29g2000yqd.googlegroups.com> Message-ID: <0376b953$0$1309$c3e8da3@news.astraweb.com> On Mon, 01 Feb 2010 02:19:39 -0800, Joan Miller wrote: > Which is the best way to create user-defined exceptions since that > *BaseException.message* is deprecated in Python 2.6 ? Inherit from an existing exception. >>> class MyValueException(ValueError): ... pass ... >>> >>> raise MyValueException("value is impossible, try again") Traceback (most recent call last): File "", line 1, in __main__.MyValueException: value is impossible, try again >>> class GenericError(Exception): ... pass ... >>> raise GenericError("oops") Traceback (most recent call last): File "", line 1, in __main__.GenericError: oops Do you need anything more complicated? -- Steven From magawake at gmail.com Mon Feb 1 07:47:02 2010 From: magawake at gmail.com (Mag Gam) Date: Mon, 1 Feb 2010 07:47:02 -0500 Subject: libpcap and python Message-ID: <1cbd6f831002010447w4a2ab26dve66206919e99391@mail.gmail.com> Hello All, I used tcpdump to capture data on my network. I would like to analyze the data using python -- currently using ethereal and wireshark. I would like to get certain type of packets (I can get the hex code for them), what is the best way to do this? Lets say I want to capture all events of `ping localhost` TIA From steve at holdenweb.com Mon Feb 1 07:55:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Feb 2010 07:55:28 -0500 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: Steven D'Aprano wrote: > On Sun, 31 Jan 2010 22:43:56 -0800, alex23 wrote: > >> Steven D'Aprano wrote: >>> You're using that term wrong. It looks to me that you don't actually >>> know what a straw man argument is. A straw man argument is when >>> somebody responds to a deliberately weakened or invalid argument as if >>> it had been made by their opponent. >> Jeez, Steve, you're beginning to sound like some kind of fallacy >> zealot... ;) > > Death to all those who confuse agumentum ad populum with argumentum ad > verecundiam!!! > > Yeah, what did the zealots ever do for us? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 1 07:57:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Feb 2010 07:57:16 -0500 Subject: Python and Ruby In-Reply-To: References: <0375f245$0$1309$c3e8da3@news.astraweb.com> Message-ID: Terry Reedy wrote: > On 1/31/2010 7:25 PM, Steven D'Aprano wrote: >> On Sun, 31 Jan 2010 15:40:36 -0800, Chris Rebert wrote: >> >>> On Sun, Jan 31, 2010 at 2:36 PM, Steven D'Aprano >>> wrote: >>>> On Sun, 31 Jan 2010 04:28:41 -0800, Ed Keith wrote: >>>>> In most functional languages you just name a function to access it and >>>>> you do it ALL the time. >>>>> >>>>> for example, in if you have a function 'f' which takes two parameters >>>>> to call the function and get the result you use: >>>>> >>>>> f 2 3 >>>>> >>>>> If you want the function itself you use: >>>>> >>>>> f >>>> >>>> How do you call a function of no arguments? >>> >>> It's not really a function in that case, it's just a named constant. >>> (Recall that functions don't/can't have side-effects.) > > Three of you gave essentially identical answers, but I still do not see > how given something like > > def f(): return 1 > > I differentiate between 'function object at address xxx' and 'int 1' > objects. > But in a functional environment you don't need to. That's pretty much the whole point. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From peloko45 at gmail.com Mon Feb 1 07:59:03 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 1 Feb 2010 04:59:03 -0800 (PST) Subject: User-defined exceptions from 2.6 References: <12ef62c2-b291-414d-ad58-c18c2811379d@c29g2000yqd.googlegroups.com> <0376b953$0$1309$c3e8da3@news.astraweb.com> Message-ID: <4f599822-4037-4378-93bc-0ffd45ad3e5e@l26g2000yqd.googlegroups.com> On 1 feb, 12:45, Steven D'Aprano wrote: > On Mon, 01 Feb 2010 02:19:39 -0800, Joan Miller wrote: > > Which is the best way to create user-defined exceptions since that > > *BaseException.message* is deprecated in Python 2.6 ? > > Inherit from an existing exception. > > >>> class MyValueException(ValueError): > > ... ? ? pass > ... > > >>> raise MyValueException("value is impossible, try again") > > Traceback (most recent call last): > ? File "", line 1, in > __main__.MyValueException: value is impossible, try again > > >>> class GenericError(Exception): > > ... ? ? pass > ...>>> raise GenericError("oops") > > Traceback (most recent call last): > ? File "", line 1, in > __main__.GenericError: oops > > Do you need anything more complicated? > It's enought, thanks! From no-spam at non-existing.invalid Mon Feb 1 08:36:37 2010 From: no-spam at non-existing.invalid (Robert) Date: Mon, 01 Feb 2010 14:36:37 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Stefan Behnel wrote: > Robert, 31.01.2010 20:57: >> I tried lxml, but after walking and making changes in the element tree, >> I'm forced to do a full serialization of the whole document >> (etree.tostring(tree)) - which destroys the "human edited" format of the >> original HTML code. makes it rather unreadable. > > What do you mean? Could you give an example? lxml certainly does not > destroy anything it parsed, unless you tell it to do so. > of course it does not destroy during parsing.(?) I mean: I want to walk with a Python script through the parsed tree HTML and modify here and there things (auto alt tags from DB/similar, link corrections, text sections/translated sentences... due to HTML code and content checks.) Then I want to output the changed tree - but as close to the original format as far as possible. No changes to my white space identation, etc.. Only lokal changes, where really tags where changed. Thats similiar like that what a good HTML editor does: After you made little changes, it doesn't reformat/re-spit-out your whole code layout from tree/attribute logic only. you have lokal changes only. But a simple HTML editor like that in Mozilla-Seamonkey outputs a whole new HTML, produces the HTML from logical tree only (regarding his (ugly) style), destroys my whitspace layout and much more - forgetting anything about the original layout. Such a "good HTML editor" must somehow track the original positions of the tags in the file. And during each logical change in the tree it must tracks the file position changes/offsets. That thing seems to miss in lxml and BeautifulSoup which I tried so far. This is a frequent need I have. Nobody else's? Seems I need to write my own or patch BS to do that extra tracking? Robert From vceder at canterburyschool.org Mon Feb 1 08:48:08 2010 From: vceder at canterburyschool.org (Vern Ceder) Date: Mon, 01 Feb 2010 08:48:08 -0500 Subject: [Edu-sig] odd drawing problem with turtle.py In-Reply-To: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> References: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> Message-ID: <4B66DB98.9030800@canterburyschool.org> Brian Blais wrote: >> On Jan 31, 2010, at 23:05 , John Posner wrote: >> >>> Try commenting out this statement: >>> >>> self.turtle.tracer(False) >>> >>> That helps on Python 2.6.4. > > > interesting. It seems as if the tracer property is a global one: Actually, the tracer method that does the work is part of the TurtleScreen class, and individual Turtle instances just access the tracer method of the TurtleScreen they inhabit... if that makes sense. So since your turtles are on the same screen, yes, in effect, tracer is sort of global. Cheers, Vern > > In [1]:t1=Turtle() > > In [2]:t1.tracer() > Out[2]:1 > > In [3]:t1.tracer(False) > > In [4]:t1.tracer() > Out[4]:0 > > In [5]:t2=Turtle() > > In [6]:t2.tracer() > Out[6]:0 > > In [7]:t2.tracer(True) > > In [8]:t1.tracer() > Out[8]:1 > > looks like I need to set the tracer manually. > > however, even if the tracer is off, shouldn't it still draw the line? > when I put in the T.tracer(True) it works, but I shouldn't need to I think. > > > On Jan 31, 2010, at 21:11 , kirby urner wrote: > >> I don't see where you've defined a Turtle class to instantiate sir. > > Turtle is given in turtle.py. I should have subclassed it, but I was > being lazy. :) > > thanks for the fast replies! > > > bb > > >> On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais > > wrote: >>> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9. >>> 2009. The following script draws 5 circles, which it is supposed to, but >>> then doesn't draw the second turtle which is supposed to simply move >>> forward. Any ideas? >>> from turtle import * >>> from numpy.random import randint >>> resetscreen() >>> class Circle(object): >>> def __init__(self,x,y,r,color): >>> self.x=x >>> self.y=y >>> self.r=r >>> self.color=color >>> >>> self.turtle=Turtle(visible=False) >>> self.turtle.tracer(False) >>> self.draw() >>> >>> def draw(self): >>> self.turtle.penup() >>> self.turtle.setposition(self.x,self.y) >>> self.turtle.setheading(0) >>> self.turtle.backward(self.r) >>> self.turtle.pendown() >>> self.turtle.fill(True) >>> self.turtle.pencolor("black") >>> self.turtle.fillcolor(self.color) >>> self.turtle.circle(self.r) >>> self.turtle.fill(False) >>> self.turtle.penup() >>> >>> for i in range(5): >>> c=Circle(randint(-350,350),randint(-250,250),10,"red") >>> >>> >>> T=Turtle() >>> T.forward(100) >>> T.forward(100) >>> >>> >>> >>> >>> >>> >>> >>> thanks, >>> >>> bb >>> -- >>> Brian Blais >>> bblais at bryant.edu >>> http://web.bryant.edu/~bblais >>> http://bblais.blogspot.com/ >>> >>> >>> >>> _______________________________________________ >>> Edu-sig mailing list >>> Edu-sig at python.org >>> http://mail.python.org/mailman/listinfo/edu-sig >>> >>> > > -- > Brian Blais > bblais at bryant.edu > http://web.bryant.edu/~bblais > http://bblais.blogspot.com/ > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig -- This time for sure! -Bullwinkle J. Moose ----------------------------- Vern Ceder, Director of Technology Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804 vceder at canterburyschool.org; 260-436-0746; FAX: 260-436-5137 The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW From no-spam at non-existing.invalid Mon Feb 1 08:54:59 2010 From: no-spam at non-existing.invalid (Robert) Date: Mon, 01 Feb 2010 14:54:59 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Robert wrote: > Stefan Behnel wrote: >> Robert, 31.01.2010 20:57: >>> I tried lxml, but after walking and making changes in the element tree, >>> I'm forced to do a full serialization of the whole document >>> (etree.tostring(tree)) - which destroys the "human edited" format of the >>> original HTML code. makes it rather unreadable. >> >> What do you mean? Could you give an example? lxml certainly does not >> destroy anything it parsed, unless you tell it to do so. >> > > of course it does not destroy during parsing.(?) > > I mean: I want to walk with a Python script through the parsed tree HTML > and modify here and there things (auto alt tags from DB/similar, link > corrections, text sections/translated sentences... due to HTML code and > content checks.) > > Then I want to output the changed tree - but as close to the original > format as far as possible. No changes to my white space identation, > etc.. Only lokal changes, where really tags where changed. > > Thats similiar like that what a good HTML editor does: After you made > little changes, it doesn't reformat/re-spit-out your whole code layout > from tree/attribute logic only. you have lokal changes only. > But a simple HTML editor like that in Mozilla-Seamonkey outputs a whole > new HTML, produces the HTML from logical tree only (regarding his (ugly) > style), destroys my whitspace layout and much more - forgetting > anything about the original layout. > > Such a "good HTML editor" must somehow track the original positions of > the tags in the file. And during each logical change in the tree it must > tracks the file position changes/offsets. That thing seems to miss in > lxml and BeautifulSoup which I tried so far. > > This is a frequent need I have. Nobody else's? > > Seems I need to write my own or patch BS to do that extra tracking? > basic feature(s) of such parser perhaps: * can it tell for each tag object in the parsed tree, at what original file position start:end it resided? even a basic need: tell me the line number e.g. (for warning/analysis reports e.g.) (* do the tree objects auto track/know if they were changed. (for convenience; a tree copy may serve this otherwise .. ) the creation of a output with local changes whould be rather simple from that ... Robert From stefan_ml at behnel.de Mon Feb 1 09:05:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Feb 2010 15:05:39 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Robert, 01.02.2010 14:36: > Stefan Behnel wrote: >> Robert, 31.01.2010 20:57: >>> I tried lxml, but after walking and making changes in the element tree, >>> I'm forced to do a full serialization of the whole document >>> (etree.tostring(tree)) - which destroys the "human edited" format of the >>> original HTML code. makes it rather unreadable. >> >> What do you mean? Could you give an example? lxml certainly does not >> destroy anything it parsed, unless you tell it to do so. > > of course it does not destroy during parsing.(?) I meant "parsed" in the sense of "has parsed and is now working on". > I mean: I want to walk with a Python script through the parsed tree HTML > and modify here and there things (auto alt tags from DB/similar, link > corrections, text sections/translated sentences... due to HTML code and > content checks.) Sure, perfectly valid use case. > Then I want to output the changed tree - but as close to the original > format as far as possible. No changes to my white space identation, > etc.. Only lokal changes, where really tags where changed. That's up to you. If you only apply local changes that do not change any surrounding whitespace, you'll be fine. > Thats similiar like that what a good HTML editor does: After you made > little changes, it doesn't reformat/re-spit-out your whole code layout > from tree/attribute logic only. you have lokal changes only. HTML editors don't work that way. They always "re-spit-out" the whole code when you click on "save". They certainly don't track the original file position of tags. What they preserve is the content, including whitespace (or not, if they reformat the code, but that's usually an *option*). > Such a "good HTML editor" must somehow track the original positions of > the tags in the file. And during each logical change in the tree it must > tracks the file position changes/offsets. Sorry, but that's nonsense. The file position of a tag is determined by whitespace, i.e. line endings and indentation. lxml does not alter that, unless you tell it do do so. Since you keep claiming that it *does* alter it, please come up with a reproducible example that shows a) what you do in your code, b) what your input is and c) what unexpected output it creates. Do not forget to include the version number of lxml and libxml2 that you are using, as well as a comment on /how/ the output differs from what you expected. My stab in the dark is that you forgot to copy the tail text of elements that you replace by new content, and that you didn't properly indent new content that you added. But that's just that, a stab in the dark. You didn't provide enough information for even an educated guess. Stefan From invalid at invalid.invalid Mon Feb 1 10:09:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Feb 2010 15:09:29 +0000 (UTC) Subject: libpcap and python References: Message-ID: On 2010-02-01, Mag Gam wrote: > Hello All, > > I used tcpdump to capture data on my network. I would like to analyze > the data using python -- currently using ethereal and wireshark. > > I would like to get certain type of packets (I can get the hex code > for them), what is the best way to do this? Lets say I want to capture > all events of `ping localhost` http://www.google.com/search?q=python+pcap -- Grant Edwards grante Yow! My face is new, my at license is expired, and I'm visi.com under a doctor's care!!!! From steve at REMOVE-THIS-cybersource.com.au Mon Feb 1 10:27:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 15:27:31 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> Message-ID: <0376df33$0$1309$c3e8da3@news.astraweb.com> On Mon, 01 Feb 2010 11:14:42 +0100, Daniel Fetchinson wrote: > I also think the PEP is a great idea and proposes a solution to a real > problem. But I also hear the 'directory clutter' argument and I'm really > concerned too, having all these extra directories around (and quite a > large number of them indeed!). Keep in mind that if you don't explicitly ask for the proposed feature, you won't see any change at all. You need to run Python with the -R switch, or set an environment variable. The average developer won't see any clutter at all unless she is explicitly supporting multiple versions. > How about this scheme: > > 1. install python source files to a shared (among python installations) > location /this/is/shared > 2. when python X.Y imports a source file from /this/is/shared it will > create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ $ touch /usr/lib/python2.5/site-packages/STEVEN touch: cannot touch `/usr/lib/python2.5/site-packages/STEVEN': Permission denied There's your first problem: most users don't have write-access to the private area. When you install a package, you normally do so as root, and it all works. When you import a module and it gets compiled as a .pyc file, you're generally running as a regular user. > Time comparison would be between /this/is/shared/x.py and > /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. I don't quite understand what you mean by "time comparison". [...] > In /usr/lib/pythonX.Y/site-packages there would be only pyc files with > magic number matching python X.Y. Personally, I think it is a terribly idea to keep the source file and byte code file in such radically different places. They should be kept together. What you call "clutter" I call having the files that belong together kept together. > So, basically nothing would change only the location of py and pyc files > would be different from current behavior, but the same algorithm would > be run to determine which one to load, when to create a pyc file, when > to ignore the old one, etc. What happens when there is a .pyc file in the same location as the .py file? Because it *will* happen. Does it get ignored, or does it take precedence over the site specific file? Given: ./module.pyc /usr/lib/pythonX.Y/site-packages/module.pyc and you execute "import module", which gets used? Note that in this situation, there may or may not be a module.py file. > What would be wrong with this setup? Consider: ./module.py ./package/module.py Under your suggestion, both of these will compile to /usr/lib/pythonX.Y/site-packages/module.pyc -- Steven From robert.kern at gmail.com Mon Feb 1 10:30:50 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Feb 2010 09:30:50 -0600 Subject: Unable to install numpy In-Reply-To: References: <3a772f49-aee6-4450-b60e-8f05daec136a@21g2000yqj.googlegroups.com> Message-ID: On 2010-01-31 08:03 AM, vsoler wrote: > On Jan 18, 9:08 pm, Robert Kern wrote: >> On 2010-01-18 14:02 PM, vsoler wrote: >> >>> Hi all, >> >>> I just download Numpy, and tried to install it using "numpy-1.4.0- >>> win32-superpack-python2.6.exe" >> >>> I get an error: "Python version 2.6 required, which was not found in >>> the Registry" >> >>> However, I am using Python 2.6 every day. I'm running Windows 7. >> >>> What can I do? >> >> Please ask numpy installation questions on the numpy mailing list. >> >> http://www.scipy.org/Mailing_Lists > > Thank you Robert. > > I'm going to direct my questions towards scipy.org. However, since I > do not find my questions already answered, could you tell me where to > post it? > > I beg your pardon for still asking this question outside of scipy.org, > but I've been unable to move on. Subscribe to the numpy-discussion mailing list following the directions given on the above-linked page. Then send email to numpy-discussion at scipy.org with your question. -- 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 Mon Feb 1 10:46:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Feb 2010 15:46:52 +0000 Subject: how long a Str can be used in this python code segment? In-Reply-To: <50697b2c1002010126n7602495dlbf9cfc90755c8825@mail.gmail.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> <50697b2c1002010126n7602495dlbf9cfc90755c8825@mail.gmail.com> Message-ID: <4B66F76C.5040507@mrabarnett.plus.com> Chris Rebert wrote: > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wutong at gmail.com> wrote: >> tmp=file.read() (very huge file) >> if targetStr in tmp: >> print "find it" >> else: >> print "not find" >> file.close() >> >> I checked if file.read() is huge to some extend, it doesn't work, but >> could any give me some certain information on this prolbem? > > If the file's contents is larger than available memory, you'll get a > MemoryError. To avoid this, you can read the file in by chunks (or if > applicable, by lines) and see if each chunk/line matches. > If you're processing in chunks then you also need to consider the possibility that what you're looking for crosses a chunk boundary, of course. It's an easy case to miss! :-) From sdeibel at wingware.com Mon Feb 1 11:16:28 2010 From: sdeibel at wingware.com (Stephan Deibel) Date: Mon, 01 Feb 2010 11:16:28 -0500 Subject: ANN: Wing IDE 3.2.4 released Message-ID: <4B66FE5C.4010801@wingware.com> Hi, Wingware has released version 3.2.4 of Wing IDE, our integrated development environment for the Python programming language. Wing IDE can be used on Windows, Linux, and OS X to develop Python code for web, GUI, and embedded scripting applications. Wing IDE provides auto-completion, call tips, a powerful debugger, unit testing, version control, search, and many other features. This release includes the following minor features and improvements: * Corrected support for non-ascii I/O when debugging under Python 3.x * Support debugging of wide unicode builds of Python 3.x * Improve GUI responsiveness in very large projects (optimized external file change checking) * Auto-enter last failed or canceled version control commit message * Added context menu for copy/paste to commit message area in version control tools * Version control annotate commands like 'svn blame' show results in scratch buffer * Many other minor features and bug fixes; See the change log at http://wingware.com/pub/wingide/3.2.4/CHANGELOG.txt for details *Wing 3.2 Highlights* Version 3.2 of Wing IDE includes the following new features not present in Wing IDE 3.1: * Support for Python 3.0 and 3.1 * Rewritten version control integration with support for Subversion, CVS, Bazaar, git, Mercurial, and Perforce (*) * Added 64-bit Debian, RPM, and tar file installers for Linux * File management in Project view (**) * Auto-completion in the editor obtains completion data from live runtime when the debugger is active (**) * Perspectives: Create and save named GUI layouts and optionally automatically transition when debugging is started (*) * Improved support for Cython and Pyrex (*.pyx files) * Added key binding documentation to the manual * Added Restart Debugging item in Debug menu and tool bar (**) * Improved OS Commands and Bookmarks tools (*) (*)'d items are available in Wing IDE Professional only. (**)'d items are available in Wing IDE Personal and Professional only. The release also contains many other minor features and bug fixes; see the change log for details: http://wingware.com/pub/wingide/3.2.4/CHANGELOG.txt *Downloads* Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial license can be obtained directly from the product when launched. Wing IDE 101 can be used free of charge. Wing IDE Pro 3.2.4 http://wingware.com/downloads/wingide/3.2 Wing IDE Personal 3.2.4 http://wingware.com/downloads/wingide-personal/3.2 Wing IDE 101 3.2.4 http://wingware.com/downloads/wingide-101/3.2 *About Wing IDE* Wing IDE is an integrated development environment for the Python programming language. It provides powerful debugging, editing, code intelligence, testing, version control, and search capabilities that reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE 3.2 supports Python versions 2.0.x through 3.1.x. *Purchasing and Upgrading* Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Any 2.x license sold after May 2nd 2006 is free to upgrade; others cost 1/2 the normal price to upgrade. Upgrade a 2.x license: https://wingware.com/store/upgrade Purchase a 3.x license: https://wingware.com/store/purchase -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From andrej.mitrovich at gmail.com Mon Feb 1 11:31:34 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 08:31:34 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> Message-ID: On Feb 1, 4:03?am, Andrej Mitrovic wrote: > On Feb 1, 2:59?am, Andrej Mitrovic wrote: > > > > > Hi, > > > I've made a similar post on the Cython mailing list, however I think > > this is more python-specific. I'm having trouble setting up distutils > > to use MinGW instead of Visual Studio when building a module. Even tho > > I've just uninstalled VS, and cleared out any leftover VS environment > > variables, distutils keeps wanting to use it. > > > The steps I took: > > > Fresh installation of Python 3.1.1 > > Successfully installed MinGW, added to the path variable (gcc in > > command prompt works) > > Successfully installed Cython, imports from Cython in Python work. > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with: > > > [build] > > compiler=mingw32 > > > (also tried adding [build_ext] compiler=mingw32) > > > There's a demo setup.py module that came with Cython, I tried the > > following commands: > > > ---------------------------------------------------- > > > > python setup.py build_ext --inplace > > > error: Unable to find vcvarsall.bat > > > > python setup.py build > > > error: Unable to find vcvarsall.bat > > ---------------------------------------------------- > > > I'm having the exact same issue with trying to build the Polygon > > library via MinGW. In fact, the reason I had installed Visual Studio > > in the first place was to be able to build the Polygon library, since > > I was having these errors. > > > What do I need to do to make distutils/python use MinGW? > > Update: > > I installed and tried building with Python 2.6, it calls MinGW when I > have the distutils.cfg file configured properly (same configuration as > the Python 3.1.1 one) > > But why doesn't it work on a fresh Python 3.1.1 installation as well? > Is this a bug? Also tried calling (Python 3.1.1): ---------------------------------------------------- python setup.py build --compiler=mingw32 error: Unable to find vcvarsall.bat ---------------------------------------------------- I've tried using pexports and the dlltool to build new python31.def and libpython31.a files, and put them in the libs folder. That didn't work either. I've also tried adding some print statements in the \distutils\dist.py file, in the parse_config_files() function, just to see if Python properly parses the config file. And it does, both Python 2.6 and 3.1 parse the distutils.cfg file properly. Yet something is making python 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on any progres.. From casevh at gmail.com Mon Feb 1 11:44:46 2010 From: casevh at gmail.com (casevh) Date: Mon, 1 Feb 2010 08:44:46 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> Message-ID: <12c34cd1-7740-4257-9bb6-bdfb55b44b27@2g2000prl.googlegroups.com> On Feb 1, 8:31?am, Andrej Mitrovic wrote: > On Feb 1, 4:03?am, Andrej Mitrovic wrote: > > > > > > > On Feb 1, 2:59?am, Andrej Mitrovic wrote: > > > > Hi, > > > > I've made a similar post on the Cython mailing list, however I think > > > this is more python-specific. I'm having trouble setting up distutils > > > to use MinGW instead of Visual Studio when building a module. Even tho > > > I've just uninstalled VS, and cleared out any leftover VS environment > > > variables, distutils keeps wanting to use it. > > > > The steps I took: > > > > Fresh installation of Python 3.1.1 > > > Successfully installed MinGW, added to the path variable (gcc in > > > command prompt works) > > > Successfully installed Cython, imports from Cython in Python work. > > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with: > > > > [build] > > > compiler=mingw32 > > > > (also tried adding [build_ext] compiler=mingw32) > > > > There's a demo setup.py module that came with Cython, I tried the > > > following commands: > > > > ---------------------------------------------------- > > > > > python setup.py build_ext --inplace > > > > error: Unable to find vcvarsall.bat > > > > > python setup.py build > > > > error: Unable to find vcvarsall.bat > > > ---------------------------------------------------- > > > > I'm having the exact same issue with trying to build the Polygon > > > library via MinGW. In fact, the reason I had installed Visual Studio > > > in the first place was to be able to build the Polygon library, since > > > I was having these errors. > > > > What do I need to do to make distutils/python use MinGW? > > > Update: > > > I installed and tried building with Python 2.6, it calls MinGW when I > > have the distutils.cfg file configured properly (same configuration as > > the Python 3.1.1 one) > > > But why doesn't it work on a fresh Python 3.1.1 installation as well? > > Is this a bug? > > Also tried calling (Python 3.1.1): > > ---------------------------------------------------- > python setup.py build --compiler=mingw32 > > error: Unable to find vcvarsall.bat > ---------------------------------------------------- > > I've tried using pexports and the dlltool to build new python31.def > and libpython31.a files, and put them in the libs folder. That didn't > work either. > > I've also tried adding some print statements in the \distutils\dist.py > file, in the parse_config_files() function, just to see if Python > properly parses the config file. And it does, both Python 2.6 and 3.1 > parse the distutils.cfg file properly. Yet something is making python > 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on > any progres..- Hide quoted text - > > - Show quoted text - I think this is http://bugs.python.org/issue6377. I applied the patch to my local copy of Python 3.1 and it seems to work. casevh From gerald.britton at gmail.com Mon Feb 1 11:50:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Mon, 1 Feb 2010 11:50:36 -0500 Subject: Iterating over a function call Message-ID: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Hi -- I have many sections of code like this: for value in value_iterator: value_function(value) I noticed that this does two things I don't like: 1. looks up "value_function" and "value" for each iteration, but "value_function" doesn't change. 2. side effect of (maybe) leaking the iterator variable "value" into the code following the loop (if the iterator is not empty). I can take care of 2 by explicitly deleting the variable at the end: del value but I'd probably forget to do that sometimes. I then realized that, in the 2.x series, I can accomplish the same thing with: map(value_function, value_iterator) and avoid both problems BUT map() returns a list which is never used. Not a big deal for small iterables, I guess, but it seems messy. Upon conversion to 3.x I have to explicitly list-ify it: list(map(value_function, value_iterator)) which works but again the list returned is never used (extra work) and has to be gc'd I suppose (extra memory). It's easy to make a little function to take care of this (2.x): from itertools import imap def apply(function, iterable): for item in imap(function, iterable): pass then later: apply(value_function, value_iterator) or something similar thing in 3.x, but that just adds an additional function def that I have to include whenever I want to do something like this. So.....I'm wondering if there is any interest in an apply() built-in function that would work like map() does in 2.x (calls the function with each value returned by the iterator) but return nothing. Maybe "apply" isn't the best name; it's just the first one that occurred to me. Or is this just silly and should I forget about it? -- Gerald Britton From solipsis at pitrou.net Mon Feb 1 11:53:01 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 1 Feb 2010 16:53:01 +0000 (UTC) Subject: how long a Str can be used in this python code segment? References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: Le Mon, 01 Feb 2010 01:33:09 -0800, Stephen.Wu a ?crit?: > > actually, I just use file.read(length) way, i just want to know what > exactly para of length I should set, I'm afraid length doesn't equal to > the amount of physical memory after trials... There's no exact length you "should" set, just set something big enough that looping doesn't add any noticeable overhead, but small enough that it doesn't take too much memory. Something between 64kB and 1MB sounds reasonable. From andrej.mitrovich at gmail.com Mon Feb 1 11:53:41 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 08:53:41 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> Message-ID: <054ae97c-f8e9-4090-a7e0-cf6a55c2cf5d@a32g2000yqm.googlegroups.com> I've found the problem: For the windows Python 3.1.1 x86 installation, the file \Python31\Lib \Distutils\command\build_ext.py, has this: Line 313: self.compiler = new_compiler(compiler=None, But Python 2.6 has this line: Line 306: self.compiler = new_compiler(compiler=self.compiler, I've changed the Python 3.1.1 \Python31\Lib\Distutils\command \build_ext.py, Line 313 to this: self.compiler = new_compiler(compiler=self.compiler, And now MinGW gets properly called in Python 3.1.1. I think this must have been a typo. Is there anyone else that can confirm this? The installation that distributes the file with that line is from this Python ftp link: http://python.org/ftp/python/3.1.1/python-3.1.1.msi From affdfsdfdsfsd at b.com Mon Feb 1 12:00:19 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 01 Feb 2010 17:00:19 GMT Subject: create a string of variable lenght References: <4b65729b$0$1126$4fafbaef@reader3.news.tin.it> <4b660056$0$1131$4fafbaef@reader3.news.tin.it> Message-ID: <4b6708a3$0$1132$4fafbaef@reader1.news.tin.it> Il Sun, 31 Jan 2010 19:54:17 -0500, Benjamin Kaplan ha scritto: > First of all, if you haven't read this before, please do. It will make > this much clearer. > http://www.joelonsoftware.com/articles/Unicode.html i'm reading it right now, thanks :-) [cut] > Solution to your problem: in addition to keeping the #-*- coding ... > line, go with G?nther's advice and use Unicode strings. that is: always use the "u" operator (i.e. my_name = u"Nico"), right? Ciao, Nico From andrej.mitrovich at gmail.com Mon Feb 1 12:03:10 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 09:03:10 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> <12c34cd1-7740-4257-9bb6-bdfb55b44b27@2g2000prl.googlegroups.com> Message-ID: On Feb 1, 5:44?pm, casevh wrote: > On Feb 1, 8:31?am, Andrej Mitrovic wrote: > > > > > On Feb 1, 4:03?am, Andrej Mitrovic wrote: > > > > On Feb 1, 2:59?am, Andrej Mitrovic wrote: > > > > > Hi, > > > > > I've made a similar post on the Cython mailing list, however I think > > > > this is more python-specific. I'm having trouble setting up distutils > > > > to use MinGW instead of Visual Studio when building a module. Even tho > > > > I've just uninstalled VS, and cleared out any leftover VS environment > > > > variables, distutils keeps wanting to use it. > > > > > The steps I took: > > > > > Fresh installation of Python 3.1.1 > > > > Successfully installed MinGW, added to the path variable (gcc in > > > > command prompt works) > > > > Successfully installed Cython, imports from Cython in Python work. > > > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with: > > > > > [build] > > > > compiler=mingw32 > > > > > (also tried adding [build_ext] compiler=mingw32) > > > > > There's a demo setup.py module that came with Cython, I tried the > > > > following commands: > > > > > ---------------------------------------------------- > > > > > > python setup.py build_ext --inplace > > > > > error: Unable to find vcvarsall.bat > > > > > > python setup.py build > > > > > error: Unable to find vcvarsall.bat > > > > ---------------------------------------------------- > > > > > I'm having the exact same issue with trying to build the Polygon > > > > library via MinGW. In fact, the reason I had installed Visual Studio > > > > in the first place was to be able to build the Polygon library, since > > > > I was having these errors. > > > > > What do I need to do to make distutils/python use MinGW? > > > > Update: > > > > I installed and tried building with Python 2.6, it calls MinGW when I > > > have the distutils.cfg file configured properly (same configuration as > > > the Python 3.1.1 one) > > > > But why doesn't it work on a fresh Python 3.1.1 installation as well? > > > Is this a bug? > > > Also tried calling (Python 3.1.1): > > > ---------------------------------------------------- > > python setup.py build --compiler=mingw32 > > > error: Unable to find vcvarsall.bat > > ---------------------------------------------------- > > > I've tried using pexports and the dlltool to build new python31.def > > and libpython31.a files, and put them in the libs folder. That didn't > > work either. > > > I've also tried adding some print statements in the \distutils\dist.py > > file, in the parse_config_files() function, just to see if Python > > properly parses the config file. And it does, both Python 2.6 and 3.1 > > parse the distutils.cfg file properly. Yet something is making python > > 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on > > any progres..- Hide quoted text - > > > - Show quoted text - > > I think this ishttp://bugs.python.org/issue6377. > > I applied the patch to my local copy of Python 3.1 and it seems to > work. > > casevh Thanks for the link, it seems like it's got more to do than what I just posted. But in any case, it works for me now. I think I'll have to open myself a blog and post some guides for problems like these, so people can avoid spending whole nights around a problem like this. :) From andrej.mitrovich at gmail.com Mon Feb 1 12:03:20 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 09:03:20 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> <054ae97c-f8e9-4090-a7e0-cf6a55c2cf5d@a32g2000yqm.googlegroups.com> Message-ID: <0a26893d-45b2-42c6-ae5f-3a59410b790f@o28g2000yqh.googlegroups.com> Well, in any case this seems to be working ok for me now. From no-spam at non-existing.invalid Mon Feb 1 12:16:20 2010 From: no-spam at non-existing.invalid (Robert) Date: Mon, 01 Feb 2010 18:16:20 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Stefan Behnel wrote: > Robert, 01.02.2010 14:36: >> Stefan Behnel wrote: >>> Robert, 31.01.2010 20:57: >>>> I tried lxml, but after walking and making changes in the element tree, >>>> I'm forced to do a full serialization of the whole document >>>> (etree.tostring(tree)) - which destroys the "human edited" format of the >>>> original HTML code. makes it rather unreadable. >>> What do you mean? Could you give an example? lxml certainly does not >>> destroy anything it parsed, unless you tell it to do so. >> of course it does not destroy during parsing.(?) > > I meant "parsed" in the sense of "has parsed and is now working on". > > >> I mean: I want to walk with a Python script through the parsed tree HTML >> and modify here and there things (auto alt tags from DB/similar, link >> corrections, text sections/translated sentences... due to HTML code and >> content checks.) > > Sure, perfectly valid use case. > > >> Then I want to output the changed tree - but as close to the original >> format as far as possible. No changes to my white space identation, >> etc.. Only lokal changes, where really tags where changed. > > That's up to you. If you only apply local changes that do not change any > surrounding whitespace, you'll be fine. > > >> Thats similiar like that what a good HTML editor does: After you made >> little changes, it doesn't reformat/re-spit-out your whole code layout >> from tree/attribute logic only. you have lokal changes only. > > HTML editors don't work that way. They always "re-spit-out" the whole code > when you click on "save". They certainly don't track the original file > position of tags. What they preserve is the content, including whitespace > (or not, if they reformat the code, but that's usually an *option*). > > >> Such a "good HTML editor" must somehow track the original positions of >> the tags in the file. And during each logical change in the tree it must >> tracks the file position changes/offsets. > > Sorry, but that's nonsense. The file position of a tag is determined by > whitespace, i.e. line endings and indentation. lxml does not alter that, > unless you tell it do do so. > > Since you keep claiming that it *does* alter it, please come up with a > reproducible example that shows a) what you do in your code, b) what your > input is and c) what unexpected output it creates. Do not forget to include > the version number of lxml and libxml2 that you are using, as well as a > comment on /how/ the output differs from what you expected. > > My stab in the dark is that you forgot to copy the tail text of elements > that you replace by new content, and that you didn't properly indent new > content that you added. But that's just that, a stab in the dark. You > didn't provide enough information for even an educated guess. > I think you confused the logical level of what I meant with "file position": Of course its not about (necessarily) writing back to the same open file (OS-level), but regarding the whole serializiation string (wherever it is finally written to - I typically write the auto-converted HTML files to a 2nd test folder first, and want use "diff -u ..." to see human-readable what changed happened - which again is only reasonable if the original layout is preserved as good as possible ) lxml and BeautifulSoup e.g. : load&parse a HTML file to a tree, immediately serialize the tree without changes => you see big differences of original and serialized files with quite any file. The main issue: those libs seem to not track any info about the original string/file positions of the objects they parse. The just forget the past. Thus they cannot by principle do what I want it seems ... Or does anybody see attributes of the tree objects - which I overlooked? Or a lib which can do or at least enable better this source-back-connected editing? Robert From python at mrabarnett.plus.com Mon Feb 1 12:17:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Feb 2010 17:17:31 +0000 Subject: how to decode rtf characterset ? In-Reply-To: <4B66B785.1090406@gmail.com> References: <4B66B785.1090406@gmail.com> Message-ID: <4B670CAB.7090303@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > I want to translate rtf files to unicode strings. > I succeeded in remove all the tags, > but now I'm stucked to the special accent characters, > like : > > "V??r" > > the character "?" is represented by the string r"\'f3", > or in bytes: 92, 39,102, 51 > > so I think I need a way to translate that into the string r"\xf3" > but I can't find a way to accomplish that. > > a > Any suggestions are very welcome. > Change r"\'f3" to r"\xf3" and then decode to Unicode: >>> s = r"\'f3" >>> s = s.replace(r"\'", r"\x").decode("unicode_escape") >>> print s ? From kirby.urner at gmail.com Mon Feb 1 12:29:25 2010 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 1 Feb 2010 09:29:25 -0800 Subject: [Edu-sig] odd drawing problem with turtle.py In-Reply-To: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> References: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> Message-ID: On Mon, Feb 1, 2010 at 3:27 AM, Brian Blais wro > > I don't see where you've defined a Turtle class to instantiate sir. > > > Turtle is given in turtle.py. I should have subclassed it, but I was being > lazy. :) > > thanks for the fast replies! > > > > bb > > > No obvious need to subclass. You weren't being lazy, I was being sloppy. I'm glad Vern caught my error right away. Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.arnold at sas.com Mon Feb 1 12:42:07 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Mon, 1 Feb 2010 12:42:07 -0500 Subject: HTML Parser which allows low-keyed local changes (upon serialization) References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Message-ID: "Robert" wrote in message news:hk729b$naa$1 at news.albasani.net... > Stefan Behnel wrote: >> Robert, 01.02.2010 14:36: >>> Stefan Behnel wrote: >>>> Robert, 31.01.2010 20:57: >>>>> I tried lxml, but after walking and making changes in the element >>>>> tree, >>>>> I'm forced to do a full serialization of the whole document >>>>> (etree.tostring(tree)) - which destroys the "human edited" format of >>>>> the >>>>> original HTML code. makes it rather unreadable. >>>> What do you mean? Could you give an example? lxml certainly does not >>>> destroy anything it parsed, unless you tell it to do so. >>> of course it does not destroy during parsing.(?) >> I think I understand what you want, but I don't understand why yet. Do you want to view the differences in an IDE or something like that? If so, why not pretty-print both and compare that? --Tim From mal at egenix.com Mon Feb 1 13:06:37 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 01 Feb 2010 19:06:37 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4B67182D.3060500@egenix.com> Robert wrote: > I think you confused the logical level of what I meant with "file > position": > Of course its not about (necessarily) writing back to the same open file > (OS-level), but regarding the whole serializiation string (wherever it > is finally written to - I typically write the auto-converted HTML files > to a 2nd test folder first, and want use "diff -u ..." to see > human-readable what changed happened - which again is only reasonable if > the original layout is preserved as good as possible ) > > lxml and BeautifulSoup e.g. : load&parse a HTML file to a tree, > immediately serialize the tree without changes => you see big > differences of original and serialized files with quite any file. > > The main issue: those libs seem to not track any info about the original > string/file positions of the objects they parse. The just forget the > past. Thus they cannot by principle do what I want it seems ... > > Or does anybody see attributes of the tree objects - which I overlooked? > Or a lib which can do or at least enable better this > source-back-connected editing? You'd have to write your own parse (or extend the example HTML one we include), but mxTextTools allows you to work on original code quite easily: it tags parts of the input string with objects. You can then have those objects manipulate the underlying text as necessary and write back the text using the original formatting plus your local changes. http://www.egenix.com/products/python/mxBase/mxTextTools/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 01 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/ ________________________________________________________________________ ::: 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 mal at egenix.com Mon Feb 1 13:11:24 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 01 Feb 2010 19:11:24 +0100 Subject: how to decode rtf characterset ? In-Reply-To: <4B66B785.1090406@gmail.com> References: <4B66B785.1090406@gmail.com> Message-ID: <4B67194C.3030307@egenix.com> Stef Mientki wrote: > hello, > > I want to translate rtf files to unicode strings. > I succeeded in remove all the tags, > but now I'm stucked to the special accent characters, > like : > > "V??r" > > the character "?" is represented by the string r"\'f3", > or in bytes: 92, 39,102, 51 > so I think I need a way to translate that into the string r"\xf3" > but I can't find a way to accomplish that. > > a > Any suggestions are very welcome. You could try something along these lines: >>> s = r"\'f3" >>> s = s.replace("\\'", "\\x") >>> u = s.decode('unicode-escape') >>> u u'\xf3' However, this assumes Latin-1 codes being using by the RTF text. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 01 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/ ________________________________________________________________________ ::: 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 benjamin.kaplan at case.edu Mon Feb 1 13:56:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Feb 2010 13:56:16 -0500 Subject: create a string of variable lenght In-Reply-To: <4b6708a3$0$1132$4fafbaef@reader1.news.tin.it> References: <4b65729b$0$1126$4fafbaef@reader3.news.tin.it> <4b660056$0$1131$4fafbaef@reader3.news.tin.it> <4b6708a3$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: On Mon, Feb 1, 2010 at 12:00 PM, Tracubik wrote: > Il Sun, 31 Jan 2010 19:54:17 -0500, Benjamin Kaplan ha scritto: > >> First of all, if you haven't read this before, please do. It will make >> this much clearer. >> http://www.joelonsoftware.com/articles/Unicode.html > > i'm reading it right now, thanks :-) > > [cut] > >> Solution to your problem: in addition to keeping the #-*- coding ... >> line, go with G?nther's advice and use Unicode strings. > > that is: always use the "u" operator (i.e. my_name = u"Nico"), right? > > Ciao, > Nico > Short answer: yes. Slightly longer explanation for future reference: This is true for Python 2 but not Python 3. One of the big changes in Python 3 is that strings are Unicode by default because you're not the only one who runs into this problem. So in Python 3, just writing 'Nico' will make a Unicode string and you have to explicitly declare b'Nico' if you want to look at it as a series of bytes. From gagsl-py2 at yahoo.com.ar Mon Feb 1 14:00:38 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 16:00:38 -0300 Subject: Python-list Digest, Vol 77, Issue 7 * References: <4755336292109192622@unknownmsgid> Message-ID: En Mon, 01 Feb 2010 07:26:13 -0300, Rohit Roger$ escribi?: > Help for datetime module > > Source code is : > from datetime import datetime > d = datetime(datetime.now().year, datetime.now().month, > datetime.now().day, 11, 59, 0 ) > print d And your problem is...? This is what I get: py> print d 2010-02-01 11:59:00 -- Gabriel Genellina From deets at nospam.web.de Mon Feb 1 14:52:46 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 01 Feb 2010 20:52:46 +0100 Subject: Iterating over a function call In-Reply-To: References: Message-ID: <7sopofFg53U1@mid.uni-berlin.de> > So.....I'm wondering if there is any interest in an apply() built-in > function that would work like map() does in 2.x (calls the function > with each value returned by the iterator) but return nothing. Maybe > "apply" isn't the best name; it's just the first one that occurred to > me. > > Or is this just silly and should I forget about it? IMHO - yes. Looking up names is what python does all the time, trying to microoptimize that away is silly. It is only justfied if you have extremely timing-critical code. And then, all you need to do is to say def whatever(): _function = function for value in values: _function(value) which will reduce lookup-time, as _function is found in locals() rather than globals(). And any function that does something worthy will dwarf the second namespace-lookup I'd say. Diez From arnodel at googlemail.com Mon Feb 1 15:05:55 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 01 Feb 2010 20:05:55 +0000 Subject: Iterating over a function call References: Message-ID: Gerald Britton writes: > Hi -- I have many sections of code like this: > > for value in value_iterator: > value_function(value) > > I noticed that this does two things I don't like: > > 1. looks up "value_function" and "value" for each iteration, but > "value_function" doesn't change. > 2. side effect of (maybe) leaking the iterator variable "value" into > the code following the loop (if the iterator is not empty). > > I can take care of 2 by explicitly deleting the variable at the end: > > del value > > but I'd probably forget to do that sometimes. I then realized that, > in the 2.x series, I can accomplish the same thing with: > > map(value_function, value_iterator) > > and avoid both problems BUT map() returns a list which is never used. > Not a big deal for small iterables, I guess, but it seems messy. Upon > conversion to 3.x I have to explicitly list-ify it: > > list(map(value_function, value_iterator)) > > which works but again the list returned is never used (extra work) and > has to be gc'd I suppose (extra memory). > > It's easy to make a little function to take care of this (2.x): > > from itertools import imap > def apply(function, iterable): > for item in imap(function, iterable): > pass > > then later: > > apply(value_function, value_iterator) > > or something similar thing in 3.x, but that just adds an additional > function def that I have to include whenever I want to do something > like this. > You have itertools.consume which is close to what you want: consume(imap(func, iterable)) # 2.x consume(map(func, iterable)) # 3.x HTH -- Arnaud From rolf.oltmans at gmail.com Mon Feb 1 15:06:09 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 1 Feb 2010 12:06:09 -0800 (PST) Subject: Adding methods from one class to another, dynamically Message-ID: Hello Python gurus, I'm quite new when it comes to Python so I will appreciate any help. Here is what I'm trying to do. I've two classes like below import new import unittest class test(unittest.TestCase): def test_first(self): print 'first test' def test_second(self): print 'second test' def test_third(self): print 'third test' class tee(unittest.TestCase): pass and I want to attach all test methods of 'test'(i.e. test_first(), test_second() and test_third()) class to 'tee' class. So I'm trying to do something like if __name__=="__main__": for name,func in inspect.getmembers(test,inspect.ismethod): if name.find('test_')!= -1: tee.name = new.instancemethod(func,None,tee) after doing above when I run this statement print dirs(tee) I don't see test_first(), test_second() and test_third() attached to class 'tee'. Any ideas, on how can I attach methods of class 'test' to class 'tee' dynamically? Any help is highly appreciated. Many thanks and I look forward to any help. From fetchinson at googlemail.com Mon Feb 1 15:19:52 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Feb 2010 21:19:52 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: <0376df33$0$1309$c3e8da3@news.astraweb.com> References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >> I also think the PEP is a great idea and proposes a solution to a real >> problem. But I also hear the 'directory clutter' argument and I'm really >> concerned too, having all these extra directories around (and quite a >> large number of them indeed!). > > Keep in mind that if you don't explicitly ask for the proposed feature, > you won't see any change at all. You need to run Python with the -R > switch, or set an environment variable. The average developer won't see > any clutter at all unless she is explicitly supporting multiple versions. > > > >> How about this scheme: >> >> 1. install python source files to a shared (among python installations) >> location /this/is/shared >> 2. when python X.Y imports a source file from /this/is/shared it will >> create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ > > $ touch /usr/lib/python2.5/site-packages/STEVEN > touch: cannot touch `/usr/lib/python2.5/site-packages/STEVEN': Permission > denied > > There's your first problem: most users don't have write-access to the > private area. True, I haven't thought about that (I should have though). > When you install a package, you normally do so as root, and > it all works. When you import a module and it gets compiled as a .pyc > file, you're generally running as a regular user. > > >> Time comparison would be between /this/is/shared/x.py and >> /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. > > I don't quite understand what you mean by "time comparison". I meant the comparison of timestamps on .py and .pyc files in order to determine which is newer and if a recompilation should take place or not. > [...] >> In /usr/lib/pythonX.Y/site-packages there would be only pyc files with >> magic number matching python X.Y. > > Personally, I think it is a terribly idea to keep the source file and > byte code file in such radically different places. They should be kept > together. What you call "clutter" I call having the files that belong > together kept together. I see why you think so, it's reasonable, however there is compelling argument, I think, for the opposite view: namely to keep things separate. An average developer definitely wants easy access to .py files. However I see no good reason for having access to .pyc files. I for one have never inspected a .pyc file. Why would you want to have a .pyc file at hand? If we don't really want to have .pyc files in convenient locations because we (almost) never want to access them really, then I'd say it's a good idea to keep them totally separate and so make don't get in the way. >> So, basically nothing would change only the location of py and pyc files >> would be different from current behavior, but the same algorithm would >> be run to determine which one to load, when to create a pyc file, when >> to ignore the old one, etc. > > What happens when there is a .pyc file in the same location as the .py > file? Because it *will* happen. Does it get ignored, or does it take > precedence over the site specific file? > > Given: > > ./module.pyc > /usr/lib/pythonX.Y/site-packages/module.pyc > > and you execute "import module", which gets used? Note that in this > situation, there may or may not be a module.py file. > > >> What would be wrong with this setup? > > Consider: > > ./module.py > ./package/module.py > > Under your suggestion, both of these will compile to > > /usr/lib/pythonX.Y/site-packages/module.pyc I see the problems with my suggestion. However it would be great if in some other way the .pyc files could be kept out of the way. Granted, I don't have a good proposal for this. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From clp2 at rebertia.com Mon Feb 1 15:25:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 12:25:49 -0800 Subject: Adding methods from one class to another, dynamically In-Reply-To: References: Message-ID: <50697b2c1002011225l6155069alb2d90f6d771a70df@mail.gmail.com> On Mon, Feb 1, 2010 at 12:06 PM, Oltmans wrote: > Hello Python gurus, > > I'm quite new when it comes to Python so I will appreciate any help. > Here is what I'm trying to do. I've two classes like below > > import new > import unittest > > class test(unittest.TestCase): > ? ?def test_first(self): > ? ? ? ?print 'first test' > ? ?def test_second(self): > ? ? ? ?print 'second test' > ? ?def test_third(self): > ? ? ? ?print 'third test' > > class tee(unittest.TestCase): > ? ?pass > > and I want to attach all test methods of 'test'(i.e. test_first(), > test_second() and test_third()) class to 'tee' class. So I'm trying to > do something like > > if __name__=="__main__": > ? ?for name,func in inspect.getmembers(test,inspect.ismethod): > ? ? ? ?if name.find('test_')!= -1: > ? ? ? ? ? ?tee.name = new.instancemethod(func,None,tee) This ends up repeatedly assigning to the attribute "name" of tee; if you check dir(tee), you'll see the string "name" as an entry. It does *not* assign to the attribute named by the string in the variable `name`. You want setattr(): http://docs.python.org/library/functions.html#setattr Assuming the rest of your code chunk is correct: setattr(tee, name, new.instancemethod(func,None,tee)) Cheers, Chris -- http://blog.rebertia.com From gerald.britton at gmail.com Mon Feb 1 15:44:18 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Mon, 1 Feb 2010 15:44:18 -0500 Subject: Iterating over a function call In-Reply-To: References: Message-ID: <5d1a32001002011244n21b6f6a8g27051d2cbaa14ecf@mail.gmail.com> [snip[ > You have itertools.consume which is close to what you want: > > ? ?consume(imap(func, iterable)) # 2.x > > ? ?consume(map(func, iterable)) # 3.x > > HTH It does! Though in my case this is simpler: deque(imap(func, iterable), 0) since the recipe for consume just calls deque anyway when you want to eat up the rest of the iterable. It also solves the iterator-variable leakage problem and is only a wee bit slower than a conventional for-loop. > > -- > Arnaud > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From pavlovevidence at gmail.com Mon Feb 1 15:45:03 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Feb 2010 12:45:03 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: Message-ID: <95aceacf-4282-4ddb-b7a2-d9a71d3f8d00@o28g2000yqh.googlegroups.com> On Feb 1, 12:06?pm, Oltmans wrote: > Hello Python gurus, > > I'm quite new when it comes to Python so I will appreciate any help. > Here is what I'm trying to do. I've two classes like below > > import new > import unittest > > class test(unittest.TestCase): > ? ? def test_first(self): > ? ? ? ? print 'first test' > ? ? def test_second(self): > ? ? ? ? print 'second test' > ? ? def test_third(self): > ? ? ? ? print 'third test' > > class tee(unittest.TestCase): > ? ? pass > > and I want to attach all test methods of 'test'(i.e. test_first(), > test_second() and test_third()) class to 'tee' class. Simplest way: class tee(test): pass To do it dynamically the following might work: class tee(unittest.TestCase): pass tee.__bases__ = (test,) tee.__bases__ = (test2,) # dynamically reassign base > So I'm trying to > do something like > > if __name__=="__main__": > ? ? for name,func in inspect.getmembers(test,inspect.ismethod): > ? ? ? ? if name.find('test_')!= -1: > ? ? ? ? ? ? tee.name = new.instancemethod(func,None,tee) > > after doing above when I run this statement > print dirs(tee) > I don't see test_first(), test_second() and test_third() attached to > class 'tee'. Any ideas, on how can I attach methods of class 'test' to > class 'tee' dynamically? Any help is highly appreciated. If you want to do it this way--and I recommend regular inheritance if you can--this is how: for x in dir(test): # or inspect.getmembers if x.startswith('test_'): method = getattr(test,x) function = method.im_func setattr(tee,x,function) The business with method.im_func is because in Python 2.x the getattr on a class will actually returns an unbound method, so you have to get at the actual function object with im_func. In Python 3 this is not necessary. Carl Banks From gerald.britton at gmail.com Mon Feb 1 15:50:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Mon, 1 Feb 2010 15:50:36 -0500 Subject: Adding methods from one class to another, dynamically In-Reply-To: <50697b2c1002011225l6155069alb2d90f6d771a70df@mail.gmail.com> References: <50697b2c1002011225l6155069alb2d90f6d771a70df@mail.gmail.com> Message-ID: <5d1a32001002011250q705f881aid1c7f3246ebb217a@mail.gmail.com> Or you could just do a mixin: tee.__class__.__bases__ = (test,) + tee.__class__.__bases__ On Mon, Feb 1, 2010 at 3:25 PM, Chris Rebert wrote: > On Mon, Feb 1, 2010 at 12:06 PM, Oltmans wrote: >> Hello Python gurus, >> >> I'm quite new when it comes to Python so I will appreciate any help. >> Here is what I'm trying to do. I've two classes like below >> >> import new >> import unittest >> >> class test(unittest.TestCase): >> ? ?def test_first(self): >> ? ? ? ?print 'first test' >> ? ?def test_second(self): >> ? ? ? ?print 'second test' >> ? ?def test_third(self): >> ? ? ? ?print 'third test' >> >> class tee(unittest.TestCase): >> ? ?pass >> >> and I want to attach all test methods of 'test'(i.e. test_first(), >> test_second() and test_third()) class to 'tee' class. So I'm trying to >> do something like >> >> if __name__=="__main__": >> ? ?for name,func in inspect.getmembers(test,inspect.ismethod): >> ? ? ? ?if name.find('test_')!= -1: >> ? ? ? ? ? ?tee.name = new.instancemethod(func,None,tee) > > This ends up repeatedly assigning to the attribute "name" of tee; if > you check dir(tee), you'll see the string "name" as an entry. It does > *not* assign to the attribute named by the string in the variable > `name`. > You want setattr(): http://docs.python.org/library/functions.html#setattr > Assuming the rest of your code chunk is correct: > > setattr(tee, name, new.instancemethod(func,None,tee)) > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From nad at acm.org Mon Feb 1 15:55:17 2010 From: nad at acm.org (Ned Deily) Date: Mon, 01 Feb 2010 12:55:17 -0800 Subject: get error install MySQLdb on Mac OS X References: <30c0946e-fa6a-4a54-930c-1962d167fffe@x10g2000prk.googlegroups.com> <2be17362-8a54-4a04-9671-0a0ff7266e33@k2g2000pro.googlegroups.com> Message-ID: In article <2be17362-8a54-4a04-9671-0a0ff7266e33 at k2g2000pro.googlegroups.com>, "PS.OHM" wrote: > On Jan 29, 5:02?am, Sean DiZazzo wrote: > > On Jan 28, 12:53?pm, "PS.OHM" wrote: > > > I havegetsomeerrorwhen i install MySQLdb on Mac OS X > > > > > after i key command $python setup.py build The build of MySQLdb is not finding the MySQL client database libraries. You need to install them first and, for the python you are using, you need a version that includes 32-bit. The easiest options are to download them from mysql.com or, if you are comfortable with MacPorts, I would recommend installing them from there. sudo port install mysql5 In fact, with MacPorts you can install a complete Python 2.6.4, MySQLdb, and MySQL libraries with just one command. With the MacPorts base installed, this should do it: sudo port install py26-mysql You might need to tweak the variants of some of the packages if you want 32-bit only, etc, depending on what version of OS X you're running on. -- Ned Deily, nad at acm.org From rolf.oltmans at gmail.com Mon Feb 1 15:55:38 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 1 Feb 2010 12:55:38 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: Message-ID: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Thank you for your help, Chris. Looks like I can now attach methods to class 'tee'. However, after attaching methods to 'tee' when I try to run them using suite.run() I don't see any of the methods running, I'm sorry but I've no clue what's failing this. Any insights will be highly appreciated. Here is the sample code filename: check.py --- import inspect import unittest class result(unittest.TestResult): def addSuccess(self,test): print str(test) + ' succeeded' def addError(self,test,err): print 'An error occured while running the test ' + str(test) + ' and error is = ' + str(err) def addFailure(self,test,err): print str(test) + " failed with an error =" + str(err) class test(unittest.TestCase): def test_first(self): print 'first test' def test_second(self): print 'second test' def test_third(self): print 'third test' import new class tee(unittest.TestCase): pass if __name__=="__main__": r = result() for name,func in inspect.getmembers(test,inspect.ismethod): if name.find('test_')!= -1: setattr(tee, name, new.instancemethod(func,None,tee)) suite = unittest.defaultTestLoader.loadTestsFromName('check.tee') suite.run(r) --- Then line suite.run(r) should have run the methods that we just attached, but it's not. I must be missing something here. Please enlighten me. Thanks. On Feb 2, 1:25?am, Chris Rebert wrote: > On Mon, Feb 1, 2010 at 12:06 PM, Oltmans wrote: > > Hello Python gurus, > > > I'm quite new when it comes to Python so I will appreciate any help. > > Here is what I'm trying to do. I've two classes like below > > > import new > > import unittest > > > class test(unittest.TestCase): > > ? ?def test_first(self): > > ? ? ? ?print 'first test' > > ? ?def test_second(self): > > ? ? ? ?print 'second test' > > ? ?def test_third(self): > > ? ? ? ?print 'third test' > > > class tee(unittest.TestCase): > > ? ?pass > > > and I want to attach all test methods of 'test'(i.e. test_first(), > > test_second() and test_third()) class to 'tee' class. So I'm trying to > > do something like > > > if __name__=="__main__": > > ? ?for name,func in inspect.getmembers(test,inspect.ismethod): > > ? ? ? ?if name.find('test_')!= -1: > > ? ? ? ? ? ?tee.name = new.instancemethod(func,None,tee) > > This ends up repeatedly assigning to the attribute "name" of tee; if > you check dir(tee), you'll see the string "name" as an entry. It does > *not* assign to the attribute named by the string in the variable > `name`. > You want setattr():http://docs.python.org/library/functions.html#setattr > Assuming the rest of your code chunk is correct: > > setattr(tee, name, new.instancemethod(func,None,tee)) > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - From tjreedy at udel.edu Mon Feb 1 15:58:19 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 15:58:19 -0500 Subject: libpcap and python In-Reply-To: <1cbd6f831002010447w4a2ab26dve66206919e99391@mail.gmail.com> References: <1cbd6f831002010447w4a2ab26dve66206919e99391@mail.gmail.com> Message-ID: On 2/1/2010 7:47 AM, Mag Gam wrote: > Hello All, > > I used tcpdump to capture data on my network. I would like to analyze > the data using python -- currently using ethereal and wireshark. > > I would like to get certain type of packets (I can get the hex code > for them), what is the best way to do this? Lets say I want to capture > all events of `ping localhost` The following is pretty straightforward. def process(dump, wanted, func): for packet in dump: if packet_type(packet) == wanted: func(packet) Perhaps you can ask a more specific question. Terry Jan Reedy From steve at holdenweb.com Mon Feb 1 16:14:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Feb 2010 16:14:51 -0500 Subject: Adding methods from one class to another, dynamically In-Reply-To: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Message-ID: Oltmans wrote: > Thank you for your help, Chris. Looks like I can now attach methods to > class 'tee'. However, after attaching methods to 'tee' when I try to > run them using suite.run() I don't see any of the methods running, I'm > sorry but I've no clue what's failing this. Any insights will be > highly appreciated. Here is the sample code > filename: check.py > --- > import inspect > import unittest > > > class result(unittest.TestResult): > > def addSuccess(self,test): > print str(test) + ' succeeded' > def addError(self,test,err): > print 'An error occured while running the test ' + str(test) + > ' and error is = ' + str(err) > def addFailure(self,test,err): > print str(test) + " failed with an error =" + str(err) > > > > class test(unittest.TestCase): > def test_first(self): > print 'first test' > def test_second(self): > print 'second test' > def test_third(self): > print 'third test' > > import new > class tee(unittest.TestCase): > pass > > if __name__=="__main__": > r = result() > for name,func in inspect.getmembers(test,inspect.ismethod): > if name.find('test_')!= -1: > > setattr(tee, name, new.instancemethod(func,None,tee)) > > suite = unittest.defaultTestLoader.loadTestsFromName('check.tee') > suite.run(r) > --- > > Then line suite.run(r) should have run the methods that we just > attached, but it's not. I must be missing something here. Please > enlighten me. > Should not tee be subclassing test, not unittest.TestCase? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From info at feedmagnet.com Mon Feb 1 16:15:05 2010 From: info at feedmagnet.com (Jason) Date: Mon, 1 Feb 2010 13:15:05 -0800 (PST) Subject: CheddarGetter module for Python - easy recurring billing Message-ID: <972aa441-9a27-41ef-9c35-38ad5c141b33@n33g2000yqb.googlegroups.com> We just released pychedder, an open source module for integrating CheddarGetter with Python (and Django): http://www.feedmagnet.com/blog/cheddargetter-for-python-and-django/ Anyone who's built commercial web app knows that payment processing can be one of the toughest pieces to put in place - and it can distract you from working on the core functionality of your app. CheddarGetter is a web service that abstracts the entire process of managing credit cards, processing transactions on a recurring basis, and even more complex setups like free trials, setup fees, and overage charges. We're using CheddarGetter for FeedMagnet.com and we thought the Python community in general could benefit from the module we wrote to interact with it. More just just a Python wrapper for CheddarGetter, pycheddar gives you class objects that work a lot like Django models, making the whole experience of integrating with CheddarGetter just a little more awesome and Pythonic. We're a week or two away from putting pycheddar into production on FeedMagnet, but we felt like it was close enough that others could start using it. We also published it to PyPi so you can easy_install pycheddar and get the latest version (currently 0.9). Hope others can benefit from it! - Jason From aahz at pythoncraft.com Mon Feb 1 16:16:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Feb 2010 13:16:47 -0800 Subject: starting a thread in a nother thread References: <4b604df9$0$6723$9b4e6d93@newsspool2.arcor-online.net> <4b60a661$0$1598$742ec2ed@news.sonic.net> Message-ID: In article <4b60a661$0$1598$742ec2ed at news.sonic.net>, John Nagle wrote: > >If a C package called from Python crashes, the package is defective. >Nothing you can do from Python should be able to cause a segmentation >fault. ...unless you use ctypes. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From gobladoome at gmail.com Mon Feb 1 16:21:56 2010 From: gobladoome at gmail.com (Paul) Date: Tue, 2 Feb 2010 10:21:56 +1300 Subject: Problems embedding python 2.6 in C++ Message-ID: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> Hi, I'm extending some old Visual Studio 6 code to add embedded python scripting. It works fine most of the time but some python function calls do not work as expected. The C++ code is a multithreaded MFC application. I was assuming that it was GIL issues but I have tried using the manual locking (PyEval_SaveThread & PyEval_RestoreThread) and what seems to be the current method (PyGILState_Ensure & PyGILState_Release) Here's the error I'm getting: Traceback (most recent call last): File "...scripts\receipt_parser.py", line 296, in get_giftcard_purchase_value details = extract_transaction_details_section(test) File "...scripts\receipt_parser.py", line 204, in extract_transaction_details_section for line in base_details: TypeError: expected string or Unicode object, NoneType found base_details is a list of strings (I can just define it like 'base_details=["1","2","3"...]' on the line previous) and the code runs fine when run from standard interpreter. Many other function calls work fine from the embedded app. I create and then Py_DECREF the function parameters and the return value after each function call. The module import is created at C++ object constructor and then Py_DECREF'd in the desctuctor Anyone else had issues of this kind? My next try will be to use sub-interpreters per thread. Thanks, Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Feb 1 16:25:41 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 18:25:41 -0300 Subject: Function name unchanged in error message References: Message-ID: En Sat, 30 Jan 2010 06:28:19 -0300, Peter Otten <__peter__ at web.de> escribi?: > Gabriel Genellina wrote: >> En Fri, 29 Jan 2010 13:09:40 -0300, Michele Simionato >> escribi?: >>> On Jan 29, 2:30 pm, andrew cooke wrote: >>>> Is there any way to change the name of the function in an error >>>> message? In the example below I'd like the error to refer to bar(), >>>> for example (the motivation is related function decorators - I'd like >>>> the wrapper function to give the same name) >>> >>> Use the decorator module which does the right thing: >>> http://pypi.python.org/pypi/decorator >> >> The decorator module is a very fine addition to anyone's tool set -- but >> in this case it is enough to use the wraps() function from the functools >> standard module. > > I don't know about the decorator module, but functools.wraps() doesn't > affect the error message: It seems I misunderstood the original request and got it backwards - but then I have to question the usefulness of doing so. If an error happens in the "decorating" function (as opposed to inside the function being decorated) I'd like the error to be reported as such, in the "decorating" function (else tracebacks and line numbers would be lying). -- Gabriel Genellina From jakecjacobson at gmail.com Mon Feb 1 16:46:53 2010 From: jakecjacobson at gmail.com (jakecjacobson) Date: Mon, 1 Feb 2010 13:46:53 -0800 (PST) Subject: Processing XML File References: <6bac2d7b-509d-4f92-912f-5e8dc68c3f30@36g2000yqu.googlegroups.com> <4b6335f3$0$6573$9b4e6d93@newsspool3.arcor-online.net> <4b633a07$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Jan 29, 2:41?pm, Stefan Behnel wrote: > Sells, Fred, 29.01.2010 20:31: > > > Google is your friend. ?Elementtree is one of the better documented > > IMHO, but there are many modules to do this. > > Unless the OP provides some more information, "do this" is rather > underdefined. And sending someone off to Google who is just learning the > basics of Python and XML and trying to solve a very specific problem with > them is not exactly the spirit I'm used to in this newsgroup. > > Stefan Just want to thank everyone for their posts. I got it working after I discovered a name space issue with this code. xmlDoc = libxml2.parseDoc(guts) # Ignore namespace and just get the Resource resourceNodes = xmlDoc.xpathEval('//*[local-name()="Resource"]') for rNode in resourceNodes: print rNode From jgardner at jonathangardner.net Mon Feb 1 17:04:01 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:04:01 -0800 (PST) Subject: For loop searching takes too long! References: <6ea6ebda-43af-4a77-a17e-0930cdd13258@b9g2000pri.googlegroups.com> <03738ee7$0$1309$c3e8da3@news.astraweb.com> Message-ID: <96e06a43-2197-4e93-9837-3c4b461985e0@m27g2000prl.googlegroups.com> On Jan 29, 7:07?pm, Steven D'Aprano wrote: > On Fri, 29 Jan 2010 14:49:06 -0800, Jonathan Gardner wrote: > > On Jan 28, 3:52?pm, elsa wrote: > > >> I've got a problem with my program, in that the code just takes too > >> long to run. Here's what I'm doing. If anyone has any tips, they'd be > >> much appreciated! > > > First of all, don't play with large lists. Large lists have a tendency > > to grow larger over time, until they get absurdly large. > > > If you're dealing with a long list, work with it like you'd work with a > > file. If you need random access, stick it in some form of database, such > > as BDB or PostgreSQL. If you need an index, stick it in some form of DB. > > Eventually, large lists end up like that anyway. Don't fool yourself > > early on---prepare for the worst and solve the problems of tomorrow > > today. > > Talk about premature optimization. The OP probably has a few hundreds of > thousands of items, millions at most, which is trivial on a modern PC. > Your way of thinking is what has led to Firefox using a database to > manage a few thousand bookmarks and cookies, which in turn leads to > consistent data corruption problems. (I've been keeping note, and so far > my installation of Firefox 3 has had database corruption at startup one > time out of five.) > I think there's a difference between writing your code so that you have the option of using a database, or a flat file, or any other type of serial data source, and actually using a database (or whatever.) I prefer to write my code so that I don't have to re-write it 6 months later. Having worked with datasets that are truly enormous, whenever I see a list that is unbounded (as this appears to be), I freak out because unbounded can be a really, really big number. Might as well write software that works for the truly enormous case and the really large case and be done with it once and for all. From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:11:26 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:11:26 -0300 Subject: OT: Instant Messenger Clients References: <4dc0cfea1001311315u3494ad6bk792327d05447c96d@mail.gmail.com> Message-ID: En Sun, 31 Jan 2010 18:15:34 -0300, Victor Subervi escribi?: > I need to record my IM conversations. I'm using Gmal's IM client and I > can't > figure out how to do it, nor do I find any help googling it. Hard to believe... -- Gabriel Genellina From jgardner at jonathangardner.net Mon Feb 1 17:13:38 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:13:38 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: On Jan 30, 8:43?am, Nobody wrote: > On Wed, 27 Jan 2010 15:29:05 -0800, Jonathan Gardner wrote: > > Python is much, much cleaner. I don't know how anyone can honestly say > > Ruby is cleaner than Python. > > I'm not familiar with Ruby, but most languages are cleaner than Python > once you get beyond the "10-minute introduction" stage. > Probably too little, too late (haven't read all of the replies yet...) I judge a language's simplicity by how long it takes to explain the complete language. That is, what minimal set of documentation do you need to describe all of the language? With a handful of statements, and a very short list of operators, Python beats out every language in the Algol family that I know of. I can think of only one language (or rather, a class of languages) that can every hope to be shorter than Python. I doubt you've heard of it based on your comments, but I suggest you look into it. Unfortunately, to fully appreciate that language, you're going to have to study a textbook called "SICP". At the end of that textbook, you are blessed to not only see but understand the complete compiler for the language, in the language itself. From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:27:46 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:27:46 -0300 Subject: whassup? builtins? python3000? Naah can't be right? References: <799ea994-d00f-485c-9164-ed4b66e750a5@k41g2000yqm.googlegroups.com> Message-ID: En Sun, 31 Jan 2010 18:17:04 -0300, _wolf escribi?: > dear pythoneers, > > i would be very gladly accept any commentaries about what this > sentence, gleaned from > http://celabs.com/python-3.1/reference/executionmodel.html, > is meant to mean, or why gods have decided this is the way to go. i > anticipate this guy named Kay Schluehr will have a say on that, or > maybe even the BDFL will care to pronounce ``__builtins__`` the > correct way to his fallovers, followers, and fellownerds:: > > The built-in namespace associated with the execution of > a code block is actually found by looking up the name > __builtins__ in its global namespace; this should be a > dictionary or a module (in the latter case the module?s > dictionary is used). By default, when in the __main__ > module, __builtins__ is the built-in module builtins; > when in any other module, __builtins__ is an alias for > the dictionary of the builtins module itself. > __builtins__ can be set to a user-created dictionary to > create a weak form of restricted execution. Short answer: use `import builtins` (spelled __builtin__, no 's' and double underscores, in Python 2.x) to access the module containing the predefined (built-in) objects. Everything else is an implementation detail. -- Gabriel Genellina From jgardner at jonathangardner.net Mon Feb 1 17:28:28 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:28:28 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> Message-ID: <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> On Jan 31, 3:01?am, rantingrick wrote: > On Jan 30, 10:43?am, Nobody wrote: > > > That's also true for most functional languages, e.g. Haskell and ML, as > > well as e.g. Tcl and most shells. Why require "f(x)" or "(f x)" if "f x" > > will suffice? > > yuck! wrapping the arg list with parenthesis (python way) makes the > most sense. Its to easy to misread somthing like this > > onetwothree four five six > > onetwothree(four, five, six) #ahhh... plain english. In Lisp-ish languages, you have a list of stuff that represents a function call: (a b c d) means: Call "a" with values (b, c, d) While this certainly doesn't agree with what you learned in Algebra, it is a reasonable syntax that exposes the code-data duality of programs. There is, however, one fatal flaw. Why is the first element so different than the rest? This is inconsistent with what people who are unfamiliar with the language would expect. Indeed, in teaching Lisp, learners have to be reminded about how the evaluator looks at lists and processes them. I would expect a clear, simple language to have exactly one way to call a function. This calling notation would clearly distinguish between the function and its parameters. There are quite a few options, and it turns out that "function(arg, arg, arg)" is a really good compromise. One of the bad things with languages like perl and Ruby that call without parentheses is that getting a function ref is not obvious. You need even more syntax to do so. In perl: foo(); # Call 'foo' with no args. $bar = foo; # Call 'foo; with no args, assign to '$bar' $bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' # By the way, this '&' is not the bitwise-and '&'!!!! $bar->() # Call whatever '$bar' is pointing at with no args Compare with python: foo() # Call 'foo' with no args. bar = foo() # 'bar' is now pointing to whatever 'foo()' returned bar = foo # 'bar' is now pointing to the same thing 'foo' points to bar() # Call 'bar' with no args One is simple, consistent, and easy to explain. The other one requires the introduction of advanced syntax and an entirely new syntax to make function calls with references. Note that the Algebra notation of functions allows for an obvious, simple way to refer to functions without calling them, leading to syntax such as "f o g (x)" and more. From astan.chee at al.com.au Mon Feb 1 17:34:38 2010 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 2 Feb 2010 09:34:38 +1100 Subject: converting XML to hash/dict/CustomTreeCtrl Message-ID: <4B6756FE.9060206@al.com.au> Hi, I have xml files that I want to convert to a hash/dict and then further placed in a wx CustomTreeCtrl based on the structure. The problem I am having now is that the XML file is very unusual and there aren't any unique identifiers to be put in a dict and because there are no unique variables, finding the value of it from a CustromTreeCtrl is abit tricky. I would appreciate any help or links to projects similar to this. Thanks The XML file looks something like this: This is the note on calculation times 609.081574 2531.972081 65.119100 1772.011230 72.418861 28.285192 0.000 607.432373 4833280000 4833280000 4182777856 4182777856 1 1943498 0 1640100156 411307840 709596712 1406752 737720720 0 607.432373 5164184694 2054715622 From jgardner at jonathangardner.net Mon Feb 1 17:35:57 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:35:57 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> Message-ID: <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> On Jan 31, 12:43?pm, Nobody wrote: > > If it was common-place to use Curried functions and partial application in > Python, you'd probably prefer "f a b c" to "f(a)(b)(c)" as well. > That's just the point. It isn't common to play with curried functions or monads or anything like that in computer science today. Yes, Haskell exists, and is a great experiment in how such a language could actually work. But at the same time, you have to have a brain the size of the titanic to contain all the little details about the language before you could write any large-scale application. Meanwhile, Python's syntax and language is simple and clean, and provides tremendous expressiveness without getting in the way of the programmer. Comparing Python's syntax to Haskell's syntax, Python is simpler. Comparing what Python can do to what Haskell can do, Haskell is much faster at certain tasks and allows the expression of certain things that are difficult to express in Python. But at the end of the day, the difference really doesn't matter that much. Now, compare Python versus Language X along the same lines, and the end result is that (a) Python is extraordinarily more simple than Langauge X, and (b) Python is comparable in expressiveness to Language X. That's the #1 reason why I like Python, and why saying Ruby and Python are similar isn't correct. From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:36:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:36:36 -0300 Subject: ftp.storlines error References: <24ffaab0-f319-4019-97cf-56a7531e3eef@n7g2000yqb.googlegroups.com> Message-ID: En Sun, 31 Jan 2010 19:07:44 -0300, Mik0b0 escribi?: > Good day/night/etc. > I am rather a newb in Python (learning Python 3). I am trying to > create a small script for FTP file uploads on my home network. The > script looks like this: > > from ftplib import FTP > ftp=FTP('10.0.0.1') > ftp.login('mike','*****') > directory='/var/www/blabla/' > ftp.cwd(directory) > ftp.retrlines('LIST') > print('<- - - - - - - - - >') > file_to_change='test' > file=1 > file=open(file_to_change,'w') > text='test' > file.write(text) > ftp.storlines('STOR ' + file_to_change,file) > ftp.retrlines('LIST') > file.close() > > The output is like this: > Traceback (most recent call last): > File "ftp.py", line 13, in > ftp.storlines('STOR ' + file_to_change,i) > File "/usr/lib/python3.1/ftplib.py", line 474, in storlines > buf = fp.readline() > IOError: not readable For the ftp client to be able to read and upload the file, it must have been opened for reading. But you opened it with mode 'w' a few lines above. A quick and dirty way would be to close the file right after file.write(...) and re-open it with mode 'r': ... file.write(text) file.close() file = open(file_to_change,'r') ftp.storlines(...) But I'd separate file-creation from file-uploading. When it's time to upload the file, assume it already exists and has the desired contents (because it has already been created earlier by the same script, or perhaps by some other process), so you just have to open it with mode 'r'. -- Gabriel Genellina From vlastimil.brom at gmail.com Mon Feb 1 17:39:09 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 1 Feb 2010 22:39:09 +0000 Subject: Iterating over a function call In-Reply-To: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> References: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Message-ID: <9fdb569a1002011439q2db58f2ai42fb9c0c2bc19d23@mail.gmail.com> 2010/2/1 Gerald Britton : > Hi -- I have many sections of code like this: > > ? ?for value in value_iterator: > ? ? ? ? value_function(value) > > I noticed that this does two things I don't like: >... > -- > Gerald Britton > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, just to add to the collection of possible approaches (personally, I find the straightforward versions fine, given the task ... ) If you know, that the called function (used for side effect in any case) doesn't return any "true" value, you could use any(...) over a generator expression or imap (or, inversely, all(...) if there are "true" returns all the time). Not that it improves clarity, but something like a dummy reduce(lambda x, y: None, , None) might (kind of) work for arbitrary returns. Both variants only have a redundant boolean or None value. vbr From cjblaine at gmail.com Mon Feb 1 17:44:09 2010 From: cjblaine at gmail.com (cjblaine) Date: Mon, 1 Feb 2010 14:44:09 -0800 (PST) Subject: Modules failing to add runtime library path info at link time Message-ID: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> Hey everyone, this has been driving me crazy for long enough now that I'm motivated to post and find an answer. Before I pose my question, let me state that using LD_LIBRARY_PATH is not the answer :) We have things installed in odd places, such as very specific versions of libraries to link against, etc. When I build a module (let's say PyGreSQL for instance) via python setup.py build, the link part is including a proper -L argument (-L/ some/weird/lib because /some/weird/bin was in PATH), but is omitting the additional needed runtime linker arguments. For Solaris that's -R/some/weird/lib For Linux that's -Xlinker -rpath -Xlinker /some/weird/lib Where/how can I configure the appropriate portion of our Python install to do 100% the right thing instead of just 50% (-L)? A specific example -- note the -L and lack of -R (Solaris build): % python setup.py build ... gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so % From tjreedy at udel.edu Mon Feb 1 17:56:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 17:56:23 -0500 Subject: Iterating over a function call In-Reply-To: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> References: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Message-ID: On 2/1/2010 11:50 AM, Gerald Britton wrote: > Hi -- I have many sections of code like this: > > for value in value_iterator: > value_function(value) > > I noticed that this does two things I don't like: > > 1. looks up "value_function" and "value" for each iteration, but > "value_function" doesn't change. What you mean by 'looks up'? And why are you bothered by normal Python expression evaluation? Within a function, the 'look_up' is a fast LOAD_FAST instruction. > 2. side effect of (maybe) leaking the iterator variable "value" into > the code following the loop (if the iterator is not empty). So? it is sometime useful. > > I can take care of 2 by explicitly deleting the variable at the end: > > del value > > but I'd probably forget to do that sometimes. So? If having 'value' bound breaks your subsequent code, I consider it buggy. I then realized that, > in the 2.x series, I can accomplish the same thing with: > > map(value_function, value_iterator) > > and avoid both problems BUT map() returns a list which is never used. > Not a big deal for small iterables, I guess, but it seems messy. Upon > conversion to 3.x I have to explicitly list-ify it: > > list(map(value_function, value_iterator)) > > which works but again the list returned is never used (extra work) and > has to be gc'd I suppose (extra memory). > > It's easy to make a little function to take care of this (2.x): > > from itertools import imap > def apply(function, iterable): > for item in imap(function, iterable): > pass collections.deque(imap(function, iterable), maxlen=0) will do nearly the same and may be faster. > then later: > > apply(value_function, value_iterator) > > or something similar thing in 3.x, but that just adds an additional > function def that I have to include whenever I want to do something > like this. > > So.....I'm wondering if there is any interest in an apply() built-in > function that would work like map() does in 2.x (calls the function > with each value returned by the iterator) but return nothing. Maybe > "apply" isn't the best name; it's just the first one that occurred to > me. > > Or is this just silly and should I forget about it? In my opinion, forget about it. Terry Jan Reedy From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:59:32 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:59:32 -0300 Subject: Problems embedding python 2.6 in C++ References: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> Message-ID: En Mon, 01 Feb 2010 18:21:56 -0300, Paul escribi?: > I'm extending some old Visual Studio 6 code to add embedded python > scripting. It works fine most of the time but some python function calls > do > not work as expected. > > The C++ code is a multithreaded MFC application. I was assuming that it > was > GIL issues but I have tried using the manual locking (PyEval_SaveThread & > PyEval_RestoreThread) and what seems to be the current method > (PyGILState_Ensure & PyGILState_Release) > > Here's the error I'm getting: > > Traceback (most recent call last): > File "...scripts\receipt_parser.py", line 296, in > get_giftcard_purchase_value > details = extract_transaction_details_section(test) > File "...scripts\receipt_parser.py", line 204, in > extract_transaction_details_section > for line in base_details: > TypeError: expected string or Unicode object, NoneType found > > base_details is a list of strings (I can just define it like > 'base_details=["1","2","3"...]' on the line previous) and the code runs > fine > when run from standard interpreter. Many other function calls work fine > from > the embedded app. > I create and then Py_DECREF the function parameters and the return value > after each function call. The module import is created at C++ object > constructor and then Py_DECREF'd in the desctuctor Usually, errors in reference count handling prevent objects from being destroyed (a memory leak) or generate a GPF when accessing an now-inexistent object. In principle I'd look elsewhere. > Anyone else had issues of this kind? Hard to tell without more info. base_details is built in C++ code? Is it actually a list, or a subclass defined by you? A common error is to forget to check *every* API function call for errors, so errors get unnoticed for a while but are reported on the next check, which may happen in an entirely unrelated function. > My next try will be to use > sub-interpreters per thread. I would not do that - I'd try to *simplify* the code to test, not make it more complicated. Does it work in a single-threaded application? -- Gabriel Genellina From tjreedy at udel.edu Mon Feb 1 18:00:12 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 18:00:12 -0500 Subject: Iterating over a function call In-Reply-To: References: Message-ID: On 2/1/2010 3:05 PM, Arnaud Delobelle wrote: > You have itertools.consume which is close to what you want: > > consume(imap(func, iterable)) # 2.x > > consume(map(func, iterable)) # 3.x Consume is not in itertools. It is one of many recipes in the doc (9.7.2). For exhausting an iterator, collections.deque(iterator, maxlen=0). From Hermann.Lauer at iwr.uni-heidelberg.de Mon Feb 1 18:05:16 2010 From: Hermann.Lauer at iwr.uni-heidelberg.de (Hermann Lauer) Date: Tue, 2 Feb 2010 00:05:16 +0100 Subject: Optimized bytecode in exec statement Message-ID: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Dear All, while trying to optimize some unpack operations with self compiling code I wondered howto invoke the optimization in the exec statement. Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis code, which is appended below. My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on the stack (are there hash lookups behind those ?) and of course to optimize the integer arithmetics following below (removing +-0 etc). Thanks for any ideas, greetings Hermann >>> import dis >>> g=r.rra.LAST3.getter(ds=0,row=0) class fa(struct.Struct): def __init__(s): super(fa,s).__init__('d') def __call__(s,): return s.unpack_from(s.buf,5392+(((s.lastrow()-0)%2880)*3+0)*8)[0] >>> dis.dis(g.__call__) 7 0 LOAD_FAST 0 (s) 3 LOAD_ATTR 0 (unpack_from) 6 LOAD_FAST 0 (s) 9 LOAD_ATTR 1 (buf) 12 LOAD_CONST 1 (5392) 15 LOAD_FAST 0 (s) 18 LOAD_ATTR 2 (lastrow) 21 CALL_FUNCTION 0 24 LOAD_CONST 2 (0) 27 BINARY_SUBTRACT 28 LOAD_CONST 3 (2880) 31 BINARY_MODULO 32 LOAD_CONST 4 (3) 35 BINARY_MULTIPLY 36 LOAD_CONST 2 (0) 39 BINARY_ADD 40 LOAD_CONST 5 (8) 43 BINARY_MULTIPLY 44 BINARY_ADD 45 CALL_FUNCTION 2 48 LOAD_CONST 2 (0) 51 BINARY_SUBSCR 52 RETURN_VALUE -- Netzwerkadministration/Zentrale Dienste, Interdiziplinaeres Zentrum fuer wissenschaftliches Rechnen der Universitaet Heidelberg IWR; INF 368; 69120 Heidelberg; Tel: (06221)54-8236 Fax: -5224 Email: Hermann.Lauer at iwr.uni-heidelberg.de From clp2 at rebertia.com Mon Feb 1 18:07:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 15:07:03 -0800 Subject: Python and Ruby In-Reply-To: <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: <50697b2c1002011507m35902e99hca59d26101bc644@mail.gmail.com> On Mon, Feb 1, 2010 at 2:28 PM, Jonathan Gardner wrote: > On Jan 31, 3:01?am, rantingrick wrote: >> On Jan 30, 10:43?am, Nobody wrote: >> > That's also true for most functional languages, e.g. Haskell and ML, as >> > well as e.g. Tcl and most shells. Why require "f(x)" or "(f x)" if "f x" >> > will suffice? >> >> yuck! wrapping the arg list with parenthesis (python way) makes the >> most sense. Its to easy to misread somthing like this >> >> onetwothree four five six >> >> onetwothree(four, five, six) #ahhh... plain english. > > In Lisp-ish languages, you have a list of stuff that represents a > function call: > > ?(a b c d) > > means: Call "a" with values (b, c, d) > > While this certainly doesn't agree with what you learned in Algebra, > it is a reasonable syntax that exposes the code-data duality of > programs. There is, however, one fatal flaw. Why is the first element > so different than the rest? This is inconsistent with what people who > are unfamiliar with the language would expect. Indeed, in teaching > Lisp, learners have to be reminded about how the evaluator looks at > lists and processes them. > > I would expect a clear, simple language to have exactly one way to > call a function. This calling notation would clearly distinguish > between the function and its parameters. There are quite a few > options, and it turns out that "function(arg, arg, arg)" is a really > good compromise. > > One of the bad things with languages like perl and Ruby that call > without parentheses is that getting a function ref is not obvious. You > need even more syntax to do so. In perl: > > ?foo(); ? ? ? # Call 'foo' with no args. > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > ? ? ? ? ? ? ?# By the way, this '&' is not the bitwise-and '&'!!!! > ?$bar->() ? ? # Call whatever '$bar' is pointing at with no args > > Compare with python: > > ?foo() ? ? ? # Call 'foo' with no args. > ?bar = foo() # 'bar' is now pointing to whatever 'foo()' returned > ?bar = foo ? # 'bar' is now pointing to the same thing 'foo' points to > ?bar() ? ? ? # Call 'bar' with no args > > One is simple, consistent, and easy to explain. The other one requires > the introduction of advanced syntax and an entirely new syntax to make > function calls with references. Ruby isn't nearly as bad as Perl in this regard; at least it doesn't introduce extra syntax (though there are extra method calls): foo # Call 'foo' with no args. bar = foo # Call 'foo; with no args, assign to bar bar = method(:foo) # 'bar' is now referencing the 'foo' "function" bar.call # Call 'bar' (i.e. 'foo') with no args Cheers, Chris -- http://blog.rebertia.com From as at sci.fi Mon Feb 1 18:08:39 2010 From: as at sci.fi (Anssi Saari) Date: Tue, 02 Feb 2010 01:08:39 +0200 Subject: myths about python 3 References: <4b60a4c3$0$1655$742ec2ed@news.sonic.net> Message-ID: Blog writes: > Where did you come up with that information? Almost all of the major > distros ship with 2.6.x - CentOS, OpenSuSe, Ubuntu, Fedora. (Debian > does ship with 2.5, but the next major release "sid' is due out in Q2) I don't see Python 2.6 in my CentOS 5.4 installation. All I see is 2.4. Same as RHEL and I'd say that's a fairly major distribution too. From no.email at nospam.invalid Mon Feb 1 18:08:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Feb 2010 15:08:48 -0800 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <7xeil4tuyn.fsf@ruckus.brouhaha.com> Jonathan Gardner writes: > I judge a language's simplicity by how long it takes to explain the > complete language. That is, what minimal set of documentation do you > need to describe all of the language? With a handful of statements, > and a very short list of operators, Python beats out every language in > the Algol family that I know of. Python may have been like that in the 1.5 era. By now it's more complex, and not all that well documented. Consider the different subclassing rules for new and old style classes, the interaction of metaclasses and multiple inheritance, the vagaries of what operations are thread-safe without locks, the inter-thread signalling mechanism that can only be invoked through the C API, the mysteries of generator-based coroutines, etc. I've never used Ruby and I think its syntax is ugly, but everyone tells me it's more uniform. Simplicity is not necessarily such a good thing anyway. Consider FORTH. From martin at v.loewis.de Mon Feb 1 18:12:34 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 02 Feb 2010 00:12:34 +0100 Subject: recv_into(bytearray) complains about a "pinned buffer" In-Reply-To: References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> Message-ID: <4B675FE2.4090404@v.loewis.de> Antoine Pitrou wrote: > Le Mon, 01 Feb 2010 03:30:56 +0100, Martin v. Loewis a ?crit : >>> Is this a bug in Python 2.6 or a deliberate choice regarding >>> implementation concerns I don't know about? >> It's actually a bug also that you pass an array; doing so *should* give >> the very same error. > > Well, if you can give neither an array nor a bytearray to recv_into(), > what *could* you give it? My recommendation would be to not use recv_into in 2.x, but only in 3.x. > recv_into() should simply be fixed to use the new buffer API, as it does > in 3.x. I don't think that's the full solution. The array module should also implement the new buffer API, so that it would also fail with the old recv_into. Regards, Martin From aahz at pythoncraft.com Mon Feb 1 18:29:55 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Feb 2010 15:29:55 -0800 Subject: interaction of mode 'r+', file.write(), and file.tell(): a bug or undefined behavior? References: <4b617f4a$1@dnews.tpgi.com.au> Message-ID: In article <4b617f4a$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > >f = open('input.txt', 'r+') >for line in f: > s = line.replace('python', 'PYTHON') > # f.tell() > f.write(s) > >When f.tell() is commented, 'input.txt' does not change; but when >uncommented, the f.write() succeeded writing into the 'input.txt' >(surprisingly, but not entirely unexpected, at the end of the file). Another possible issue is that using a file iterator is generally not compatible with direct file operations. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From andrewdalke at gmail.com Mon Feb 1 19:02:24 2010 From: andrewdalke at gmail.com (Andrew Dalke) Date: Mon, 1 Feb 2010 16:02:24 -0800 (PST) Subject: recv_into(bytearray) complains about a "pinned buffer" References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> <4B675FE2.4090404@v.loewis.de> Message-ID: <942aa99d-1bc1-4aa8-867a-6366cb3668a1@36g2000yqu.googlegroups.com> On Feb 2, 12:12?am, Martin v. Loewis wrote: > My recommendation would be to not use recv_into in 2.x, but only in 3.x. > I don't think that's the full solution. The array module should also > implement the new buffer API, so that it would also fail with the old > recv_into. Okay. But recv_into was added in 2.5 and the test case in 2.6's test_socket.py clearly allows an array there: def testRecvInto(self): buf = array.array('c', ' '*1024) nbytes = self.cli_conn.recv_into(buf) self.assertEqual(nbytes, len(MSG)) msg = buf.tostring()[:len(MSG)] self.assertEqual(msg, MSG) Checking koders and Google Code search engines, I found one project which used recv_into, with the filename bmpreceiver.py . It uses a array.array("B", [0] * length) . Clearly it was added to work with an array, and it's being used with an array. Why shouldn't people use it with Python 2.x? Andrew dalke at dalkescientific.com From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 19:49:00 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 00:49:00 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Mon, 01 Feb 2010 21:19:52 +0100, Daniel Fetchinson wrote: >> Personally, I think it is a terribly idea to keep the source file and >> byte code file in such radically different places. They should be kept >> together. What you call "clutter" I call having the files that belong >> together kept together. > > I see why you think so, it's reasonable, however there is compelling > argument, I think, for the opposite view: namely to keep things > separate. An average developer definitely wants easy access to .py > files. However I see no good reason for having access to .pyc files. I > for one have never inspected a .pyc file. Why would you want to have a > .pyc file at hand? If you don't care about access to .pyc files, why do you care where they are? If they are in a subdirectory module.pyr, then shrug and ignore the subdirectory. If you (generic you) are one of those developers who don't care about .pyc files, then when you are browsing your source directory and see this: module.py module.pyc you just ignore the .pyc file. Or delete it, and Python will re-create it as needed. So if you see module.pyr/ just ignore that as well. > If we don't really want to have .pyc files in convenient locations > because we (almost) never want to access them really, then I'd say it's > a good idea to keep them totally separate and so make don't get in the > way. I like seeing them in the same place as the source file, because when I start developing a module, I often end up renaming it multiple times before it settles on a final name. When I rename or move it, I delete the .pyc file, and that ensures that if I miss changing an import, and try to import the old name, it will fail. By hiding the .pyc file elsewhere, it is easy to miss deleting one, and then the import won't fail, it will succeed, but use the old, obsolete byte code. -- Steven From lists at cheimes.de Mon Feb 1 20:00:50 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 02 Feb 2010 02:00:50 +0100 Subject: Modules failing to add runtime library path info at link time In-Reply-To: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> Message-ID: <4B677942.2090002@cheimes.de> cjblaine wrote: > Where/how can I configure the appropriate portion of our Python > install to do 100% the right thing instead of just 50% (-L)? Python's distutils doesn't alter the library search path unless you tell it explicitly. > A specific example -- note the -L and lack of -R (Solaris build): > > % python setup.py build > .... > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > % The Extension() class supports the rpath argument. Simply add rpath="/path/to/library/dir" and you are good. Christian From tjreedy at udel.edu Mon Feb 1 20:02:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 20:02:01 -0500 Subject: Optimized bytecode in exec statement In-Reply-To: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: On 2/1/2010 6:05 PM, Hermann Lauer wrote: > Dear All, > > while trying to optimize some unpack operations with self compiling > code I wondered howto invoke the optimization in the exec statement. > Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis code, which > is appended below. Currently, as far as I know, -0 just removes asserts. > > My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on the stack > (are there hash lookups behind those ?) Load_fast is a locals array lookup. load_fast 0 (s) means "put locals[0] on the top of the stack". The '(s)' is added for the human reader. > and of course to optimize the integer > arithmetics following below (removing +-0 etc). Something + 0 is no necessarily something. It depends on the type of something. So the interpreter will not optimize it away. What concretely happens with int+0 is a different matter. You can remove it though, if you want to get into byte-code hacking, but why write '+0' if you do not want it? > Thanks for any ideas, > greetings > Hermann > > >>>> import dis >>>> g=r.rra.LAST3.getter(ds=0,row=0) > > class fa(struct.Struct): > def __init__(s): > super(fa,s).__init__('d') > > def __call__(s,): > return s.unpack_from(s.buf,5392+(((s.lastrow()-0)%2880)*3+0)*8)[0] > >>>> dis.dis(g.__call__) > 7 0 LOAD_FAST 0 (s) > 3 LOAD_ATTR 0 (unpack_from) > 6 LOAD_FAST 0 (s) > 9 LOAD_ATTR 1 (buf) > 12 LOAD_CONST 1 (5392) > 15 LOAD_FAST 0 (s) > 18 LOAD_ATTR 2 (lastrow) > 21 CALL_FUNCTION 0 > 24 LOAD_CONST 2 (0) > 27 BINARY_SUBTRACT > 28 LOAD_CONST 3 (2880) > 31 BINARY_MODULO > 32 LOAD_CONST 4 (3) > 35 BINARY_MULTIPLY > 36 LOAD_CONST 2 (0) > 39 BINARY_ADD > 40 LOAD_CONST 5 (8) > 43 BINARY_MULTIPLY > 44 BINARY_ADD > 45 CALL_FUNCTION 2 > 48 LOAD_CONST 2 (0) > 51 BINARY_SUBSCR > 52 RETURN_VALUE Terry Jan Reedy From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 20:12:04 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 01:12:04 GMT Subject: For loop searching takes too long! References: <6ea6ebda-43af-4a77-a17e-0930cdd13258@b9g2000pri.googlegroups.com> <03738ee7$0$1309$c3e8da3@news.astraweb.com> <96e06a43-2197-4e93-9837-3c4b461985e0@m27g2000prl.googlegroups.com> Message-ID: On Mon, 01 Feb 2010 14:04:01 -0800, Jonathan Gardner wrote: > Having worked with datasets that are truly enormous, whenever I see a > list that is unbounded (as this appears to be), I freak out because > unbounded can be a really, really big number. Might as well write > software that works for the truly enormous case and the really large > case and be done with it once and for all. Then write it to work on iterators, if at all possible, and you won't care how large the data stream is. Even databases have limits! Of course you should write your code to deal with your expected data, but it is possible to commit overkill as well as underkill. There are trade- offs between development effort, runtime speed, memory usage, and size of data you can deal with, and maximizing the final one is not always the best strategy. Look at it this way... for most applications, you probably don't use arbitrary precision floats even though floating point numbers can have an unbounded number of decimal places. But in practice, you almost never need ten decimal places to pi, let alone an infinite number. If the creators of floating point libraries wrote software "that works for the truly enormous case", the overhead would be far too high for nearly all applications. Choose your algorithm according to your expected need. If you under- estimate your need, you will write slow code, and if you over-estimate it, you'll write slow code too. Getting that balance right is why they pay software architects the big bucks *wink* -- Steven From lists at cheimes.de Mon Feb 1 20:17:14 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 02 Feb 2010 02:17:14 +0100 Subject: Optimized bytecode in exec statement In-Reply-To: References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: <4B677D1A.9000403@cheimes.de> Terry Reedy wrote: > Currently, as far as I know, -0 just removes asserts. -O (not -0) also sets __debug__ to False. Christian From gagsl-py2 at yahoo.com.ar Mon Feb 1 20:19:43 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 22:19:43 -0300 Subject: Optimized bytecode in exec statement References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: En Mon, 01 Feb 2010 20:05:16 -0300, Hermann Lauer escribi?: > while trying to optimize some unpack operations with self compiling > code I wondered howto invoke the optimization in the exec statement. > Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis > code, which > is appended below. There is not much difference with -O or -OO; assert statements are removed, __debug__ is False, docstrings are not stored (in -OO). Code generation is basically the same. > My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on > the stack > (are there hash lookups behind those ?) No, no lookup is performed at run time. LOAD_FAST takes an integer argument, an index into the locals array. The compiler knows (by static analysis, at compile time) which names are local; those objects are stored in a C array. I've not done such microbenchmark, but using DUP_TOP instead might even be slower. > and of course to optimize the integer > arithmetics following below (removing +-0 etc). Can't you remove it from source beforehand? (or, from `r.rra.LAST3.getter(ds=0,row=0)` since it looks like a code generator) In general, x+0 may execute arbitrary code, depending on the type of x. Only if you could determine that x will always be an integer, you could optimize +0 away. Python (the current version of CPython) does not perform such analysis; you may investigate psyco, Unladen Swallow, ShedSkin for such things. -- Gabriel Genellina From nobody at nowhere.com Mon Feb 1 21:03:18 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 02:03:18 +0000 Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Sun, 31 Jan 2010 22:36:32 +0000, Steven D'Aprano wrote: >> for example, in if you have a function 'f' which takes two parameters to >> call the function and get the result you use: >> >> f 2 3 >> >> If you want the function itself you use: >> >> f > > How do you call a function of no arguments? There's no such thing. All functions take one argument and return a value. As functions don't have side-effects, there is seldom much point in having a function with no arguments or which doesn't return a value. In cases where it is useful (i.e. a value must have function type), you can use the unit type "()" (essentially a zero-element tuple), e.g.: f () = 1 or: f x = () From python at mrabarnett.plus.com Mon Feb 1 21:14:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Feb 2010 02:14:03 +0000 Subject: Python and Ruby In-Reply-To: References: <0375f245$0$1309$c3e8da3@news.astraweb.com> Message-ID: <4B678A6B.6060003@mrabarnett.plus.com> Nobody wrote: > On Sun, 31 Jan 2010 22:36:32 +0000, Steven D'Aprano wrote: > >>> for example, in if you have a function 'f' which takes two parameters to >>> call the function and get the result you use: >>> >>> f 2 3 >>> >>> If you want the function itself you use: >>> >>> f >> How do you call a function of no arguments? > > There's no such thing. All functions take one argument and return a value. > > As functions don't have side-effects, there is seldom much point in having > a function with no arguments or which doesn't return a value. In cases > where it is useful (i.e. a value must have function type), you can use the > unit type "()" (essentially a zero-element tuple), e.g.: > > f () = 1 > or: > f x = () > A function with no arguments could be used as a lazy constant, generated only on demand. From clp2 at rebertia.com Mon Feb 1 21:17:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 18:17:04 -0800 Subject: Python and Ruby In-Reply-To: <4B678A6B.6060003@mrabarnett.plus.com> References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <4B678A6B.6060003@mrabarnett.plus.com> Message-ID: <50697b2c1002011817t572edf0fo52954a7f4a192b03@mail.gmail.com> On Mon, Feb 1, 2010 at 6:14 PM, MRAB wrote: > Nobody wrote: >> On Sun, 31 Jan 2010 22:36:32 +0000, Steven D'Aprano wrote: >>>> for example, in if you have a function 'f' which takes two parameters to >>>> call the function and get the result you use: >>>> >>>> ?f 2 3 >>>> >>>> If you want the function itself you use: >>>> >>>> ? f >>> >>> How do you call a function of no arguments? >> >> There's no such thing. All functions take one argument and return a value. >> >> As functions don't have side-effects, there is seldom much point in having >> a function with no arguments or which doesn't return a value. In cases >> where it is useful (i.e. a value must have function type), you can use the >> unit type "()" (essentially a zero-element tuple), e.g.: >> >> ? ? ? ?f () = 1 >> or: >> ? ? ? ?f x = () >> > A function with no arguments could be used as a lazy constant, generated > only on demand. The usefulness of that depends on a language's evaluation strategy. Haskell, for instance, uses lazy evaluation by default, so your use case doesn't apply in that instance. Cheers, Chris -- http://blog.rebertia.com From nobody at nowhere.com Mon Feb 1 21:21:55 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 02:21:55 +0000 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> Message-ID: On Mon, 01 Feb 2010 14:35:57 -0800, Jonathan Gardner wrote: >> If it was common-place to use Curried functions and partial application in >> Python, you'd probably prefer "f a b c" to "f(a)(b)(c)" as well. > > That's just the point. It isn't common to play with curried functions > or monads or anything like that in computer science today. Yes, > Haskell exists, and is a great experiment in how such a language could > actually work. But at the same time, you have to have a brain the size > of the titanic to contain all the little details about the language > before you could write any large-scale application. No, not really. Haskell (and previously ML) are often used as introductory languages in Comp.Sci. courses (at least in the UK). You don't need to know the entire language before you can use any of it (if you did, Python would be deader than a certain parrot; Python's dark corners are *really* dark). The lack of mutable state (or at least, the isolation of it within monads) eliminates a lot of potential problems. How many Python novices get tripped up by "x = y = [] ; x.append(...); # now y has changed"? And in spite of the category theory behind monads, Haskell's I/O system really isn't any more complex than that of any other language, beyond the constraint that you can only use it in "procedures" (i.e. something returning an IO instance), not in functions. Which for the most part, is a net win, as it forces you to maintain a reasonable degree of structure. Now, if you actually want to use everything the language has to offer, you can run into some fairly hairy error messages. But then I've found that to be a common problem with generic programming in general. E.g. error messages relating to the C++ STL can be quite insanely complex (particularly when the actual error is "there are so many nested templates that the mangled function name is longer than the linker can handle" and it's trying to explain *where* the error is). From no.email at please.post Mon Feb 1 21:34:07 2010 From: no.email at please.post (kj) Date: Tue, 2 Feb 2010 02:34:07 +0000 (UTC) Subject: How to guard against bugs like this one? Message-ID: I just spent about 1-1/2 hours tracking down a bug. An innocuous little script, let's call it buggy.py, only 10 lines long, and whose output should have been, at most two lines, was quickly dumping tens of megabytes of non-printable characters to my screen (aka gobbledygook), and in the process was messing up my terminal *royally*. Here's buggy.py: import sys import psycopg2 connection_params = "dbname='%s' user='%s' password='%s'" % tuple(sys.argv[1:]) conn = psycopg2.connect(connection_params) cur = conn.cursor() cur.execute('SELECT * FROM version;') print '\n'.join(x[-1] for x in cur.fetchall()) (Of course, buggy.py is pretty useless; I reduced the original, more useful, script to this to help me debug it.) Through a *lot* of trial an error I finally discovered that the root cause of the problem was the fact that, in the same directory as buggy.py, there is *another* innocuous little script, totally unrelated, whose name happens to be numbers.py. (This second script is one I wrote as part of a little Python tutorial I put together months ago, and is not much more of a script than hello_world.py; it's baby-steps for the absolute beginner. But apparently, it has a killer name! I had completely forgotten about it.) Both scripts live in a directory filled with *hundreds* little one-off scripts like the two of them. I'll call this directory myscripts in what follows. It turns out that buggy.py imports psycopg2, as you can see, and apparently psycopg2 (or something imported by psycopg2) tries to import some standard Python module called numbers; instead it ends up importing the innocent myscript/numbers.py, resulting in *absolute mayhem*. (This is no mere Python "wart"; this is a suppurating chancre, and the fact that it remains unfixed is a neverending source of puzzlement for me.) How can the average Python programmer guard against this sort of time-devouring bug in the future (while remaining a Python programmer)? The only solution I can think of is to avoid like the plague the basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, and *pray* that whatever name one chooses for one's script does not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory of a future release. What else can one do? Let's see, one should put every script in its own directory, thereby containing the damage. Anything else? Any suggestion would be appreciated. TIA! ~k From john at castleamber.com Mon Feb 1 21:36:44 2010 From: john at castleamber.com (John Bokma) Date: Mon, 01 Feb 2010 20:36:44 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: <87sk9knz2b.fsf@castleamber.com> Jonathan Gardner writes: > One of the bad things with languages like perl FYI: the language is called Perl, the program that executes a Perl program is called perl. > without parentheses is that getting a function ref is not obvious. You > need even more syntax to do so. In perl: > > foo(); # Call 'foo' with no args. > $bar = foo; # Call 'foo; with no args, assign to '$bar' > $bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > # By the way, this '&' is not the bitwise-and '&'!!!! It should be $bar = \&foo Your example actually calls foo... [..] > One is simple, consistent, and easy to explain. The other one requires > the introduction of advanced syntax and an entirely new syntax to make > function calls with references. The syntax follows that of referencing and dereferencing: $bar = \@array; # bar contains now a reference to array $bar->[ 0 ]; # first element of array referenced by bar $bar = \%hash; # bar contains now a reference to a hash $bar->{ key }; # value associated with key of hash ref. by bar $bar = \&foo; # bar contains now a reference to a sub $bar->( 45 ); # call sub ref. by bar with 45 as an argument Consistent: yes. New syntax? No. Also, it helps to think of $ as a thing @ as thingies indexed by numbers % as thingies indexed by keys -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From apt.shansen at gmail.com Mon Feb 1 21:50:16 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 1 Feb 2010 18:50:16 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > First, I don't shadow built in modules. Its really not very hard to avoid. Secondly, I use packages structuring my libraries, and avoid junk directories of a hundred some odd 'scripts'. Third, I don't execute scripts in that directory structure directly, but instead do python -c 'from package.blah import main; main.main()' or some such. Usually via some short-cut, or a runner batch file. Note that the third avoids the above problem entirely, but that's not why I do it. Its just a side-effect. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Feb 1 21:50:55 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 02:50:55 +0000 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: On Mon, 01 Feb 2010 14:13:38 -0800, Jonathan Gardner wrote: > I judge a language's simplicity by how long it takes to explain the > complete language. That is, what minimal set of documentation do you > need to describe all of the language? That's not a particularly good metric, IMHO. A simple "core" language doesn't necessarily make a language simple to use. You can explain the entirety of pure lambda calculus or combinators in five minutes, but you wouldn't want to write real code in either (and you certainly wouldn't want to read such code which was written by someone else). For a start, languages with a particularly simple "core" tend to delegate too much to the library. One thing which puts a lot of people off of lisp is the lack of infix operators; after all, (* 2 (+ 3 4)) works fine and doesn't require any additional language syntax. For an alternative, Tcl provides the "expr" function which essentially provides a sub-language for arithmetic expressions. A better metric is whether using N features has O(N) complexity, or O(N^2) (where you have to understand how each feature relates to each other feature) or even O(2^N) (where you have to understand every possible combination of interactions). > With a handful of statements, > and a very short list of operators, Python beats out every language in > the Algol family that I know of. Not once you move beyond the 10-minute introduction, and have to start thinking in terms of x + y is x.__add__(y) or maybe y.__radd__(x) and also that x.__add__(y) is x.__getattribute__('__add__')(y) (but x + y *isn't* equivalent to the latter due to __slots__), and maybe .__coerce__() gets involved somewhere, and don't even get me started on __metaclass__ or __init__ versus __new__ or ... Yes, the original concept was very nice and clean, but everything since then has been wedged in there by sheer force with a bloody great hammer. From sccolbert at gmail.com Mon Feb 1 21:54:04 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 1 Feb 2010 21:54:04 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7f014ea61002011854h47a61da7j8740be722b8eb656@mail.gmail.com> This is kinda akin to creating your own libc.so in a folder where your compiling and executing c programs and then wondering why your program bugs out.... On Mon, Feb 1, 2010 at 9:34 PM, kj wrote: > > > I just spent about 1-1/2 hours tracking down a bug. > > An innocuous little script, let's call it buggy.py, only 10 lines > long, and whose output should have been, at most two lines, was > quickly dumping tens of megabytes of non-printable characters to > my screen (aka gobbledygook), and in the process was messing up my > terminal *royally*. Here's buggy.py: > > > > import sys > import psycopg2 > connection_params = "dbname='%s' user='%s' password='%s'" % > tuple(sys.argv[1:]) > conn = psycopg2.connect(connection_params) > cur = conn.cursor() > cur.execute('SELECT * FROM version;') > print '\n'.join(x[-1] for x in cur.fetchall()) > > > (Of course, buggy.py is pretty useless; I reduced the original, > more useful, script to this to help me debug it.) > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. (This second script > is one I wrote as part of a little Python tutorial I put together > months ago, and is not much more of a script than hello_world.py; > it's baby-steps for the absolute beginner. But apparently, it has > a killer name! I had completely forgotten about it.) > > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. I'll call this directory > myscripts in what follows. > > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > > What else can one do? Let's see, one should put every script in its > own directory, thereby containing the damage. > > Anything else? > > Any suggestion would be appreciated. > > TIA! > > ~k > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Feb 1 21:56:34 2010 From: john at castleamber.com (John Bokma) Date: Mon, 01 Feb 2010 20:56:34 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> Message-ID: <87bpg8ny59.fsf@castleamber.com> Nobody writes: > On Mon, 01 Feb 2010 14:35:57 -0800, Jonathan Gardner wrote: > >>> If it was common-place to use Curried functions and partial application in >>> Python, you'd probably prefer "f a b c" to "f(a)(b)(c)" as well. >> >> That's just the point. It isn't common to play with curried functions >> or monads or anything like that in computer science today. Yes, >> Haskell exists, and is a great experiment in how such a language could >> actually work. But at the same time, you have to have a brain the size >> of the titanic to contain all the little details about the language >> before you could write any large-scale application. > > No, not really. Haskell (and previously ML) are often used as introductory > languages in Comp.Sci. courses (at least in the UK). At least in the early 90's this was also the case in the Netherlands, at the University of Utrecht. We got Miranda/Gofer, and in a different, more advanced course Linda (Miranda for parallel machines). Also the inner workings of functional programming languages was a course. (Can't recall the name of the book that was used, but it was quite good IMO). I want to start (re)learning Haskell later this year, because I liked Miranda/Gofer a lot back then. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From clp2 at rebertia.com Mon Feb 1 21:57:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 18:57:27 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <50697b2c1002011857h6e60a28ajd3a6f0c4516fe286@mail.gmail.com> On Mon, Feb 1, 2010 at 6:34 PM, kj wrote: > I just spent about 1-1/2 hours tracking down a bug. > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. ?(This second script > is one I wrote as part of a little Python tutorial I put together > months ago, and is not much more of a script than hello_world.py; > it's baby-steps for the absolute beginner. ?But apparently, it has > a killer name! ?I had completely forgotten about it.) > > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. ?I'll call this directory > myscripts in what follows. > > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > > What else can one do? ?Let's see, one should put every script in its > own directory, thereby containing the damage. > > Anything else? > > Any suggestion would be appreciated. I think absolute imports avoid this problem: from __future__ import absolute_import For details, see PEP 328: http://www.python.org/dev/peps/pep-0328/ Cheers, Chris -- http://blog.rebertia.com From nobody at nowhere.com Mon Feb 1 22:09:48 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 03:09:48 +0000 Subject: HTML Parser which allows low-keyed local changes? References: Message-ID: On Sun, 31 Jan 2010 20:57:31 +0100, Robert wrote: > I tried lxml, but after walking and making changes in the element > tree, I'm forced to do a full serialization of the whole document > (etree.tostring(tree)) - which destroys the "human edited" format > of the original HTML code. > makes it rather unreadable. > > is there an existing HTML parser which supports tracking/writing > back particular changes in a cautious way by just making local > changes? or a least tracks the tag start/end positions in the file? HTMLParser, sgmllib.SGMLParser and htmllib.HTMLParser all allow you to retrieve the literal text of a start tag (but not an end tag). Unfortunately, they're only tokenisers, not parsers, so you'll need to handle minimisation yourself. From roy at panix.com Mon Feb 1 22:15:32 2010 From: roy at panix.com (Roy Smith) Date: Mon, 01 Feb 2010 22:15:32 -0500 Subject: How to guard against bugs like this one? References: Message-ID: In article , kj wrote: > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. > [...] > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. I feel your pain, but this is not a Python problem, per-se. The general pattern is: 1) You have something which refers to a resource by name. 2) There is a sequence of places which are searched for this name. 3) The search finds the wrong one because another resource by the same name appears earlier in the search path. I've gotten bitten like this by shells finding the wrong executable (in $PATH). By dynamic loaders finding the wrong library (in $LD_LIBRARY_PATH). By C compilers finding the wrong #include file. And so on. This is just Python's import finding the wrong module in your $PYTHON_PATH. The solution is the same in all cases. You either have to refer to resources by some absolute name, or you need to make sure you set up your search paths correctly and know what's in them. In your case, one possible solution be to make sure "." (or "") isn't in sys.path (although that might cause other issues). From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 22:28:55 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 03:28:55 GMT Subject: How to guard against bugs like this one? References: Message-ID: On Tue, 02 Feb 2010 02:34:07 +0000, kj wrote: > I just spent about 1-1/2 hours tracking down a bug. > > An innocuous little script, let's call it buggy.py, only 10 lines long, > and whose output should have been, at most two lines, was quickly > dumping tens of megabytes of non-printable characters to my screen (aka > gobbledygook), and in the process was messing up my terminal *royally*. > Here's buggy.py: [...] > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to import > some standard Python module called numbers; instead it ends up importing > the innocent myscript/numbers.py, resulting in *absolute mayhem*. There is no module numbers in the standard library, at least not in 2.5. >>> import numbers Traceback (most recent call last): File "", line 1, in ImportError: No module named numbers It must be specific to psycopg2. I would think this is a problem with psycopg2 -- it sounds like it should be written as a package, but instead is written as a bunch of loose modules. I could be wrong of course, but if it is just a collection of modules, I'd definitely call that a poor design decision, if not a bug. > (This is no mere Python "wart"; this is a suppurating chancre, and the > fact that it remains unfixed is a neverending source of puzzlement for > me.) No, it's a wart. There's no doubt it bites people occasionally, but I've been programming in Python for about ten years and I've never been bitten by this yet. I'm sure it will happen some day, but not yet. In this case, the severity of the bug (megabytes of binary crud to the screen) is not related to the cause of the bug (shadowing a module). As for fixing it, unfortunately it's not quite so simple to fix without breaking backwards-compatibility. The opportunity to do so for Python 3.0 was missed. Oh well, life goes on. > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, and > *pray* that whatever name one chooses for one's script does not suddenly > pop up in the appropriate /usr/lib/pythonX.XX directory of a future > release. Unfortunately, Python makes no guarantee that there won't be some clash between modules. You can minimize the risks by using packages, e.g. given a package spam containing modules a, b, c, and d, if you refer to spam.a etc. then you can't clash with modules a, b, c, d, but only spam. So you've cut your risk profile from five potential clashes to only one. Also, generally most module clashes are far more obvious. If you do this: import module x = module.y and module is shadowed by something else, you're *much* more likely to get an AttributeError than megabytes of crud to the screen. I'm sorry that you got bitten so hard by this, but in practice it's uncommon, and relatively mild when it happens. > What else can one do? Let's see, one should put every script in its own > directory, thereby containing the damage. That's probably a bit extreme, but your situation: "Both scripts live in a directory filled with *hundreds* little one-off scripts like the two of them." is far too chaotic for my liking. You don't need to go to the extreme of a separate directory for each file, but you can certainly tidy things up a bit. For example, anything that's obsolete should be moved out of the way where it can't be accidentally executed or imported. -- Steven From python.list at tim.thechases.com Mon Feb 1 22:33:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 01 Feb 2010 21:33:10 -0600 Subject: How to guard against bugs like this one? In-Reply-To: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> Message-ID: <4B679CF6.1060607@tim.thechases.com> Stephen Hansen wrote: > First, I don't shadow built in modules. Its really not very hard to avoid. Given the comprehensive nature of the batteries-included in Python, it's not as hard to accidentally shadow a built-in, unknown to you, but yet that is imported by a module you are using. The classic that's stung me enough times (and many others on c.l.p and other forums, as a quick google evidences) such that I *finally* remember: bash$ touch email.py bash$ python ... >>> import smtplib Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/smtplib.py", line 46, in import email.Utils ImportError: No module named Utils Using "email.py" is an innocuous name for a script/module you might want to do emailish things, and it's likely you'll use smtplib in the same code...and kablooie, things blow up even if your code doesn't reference or directly use the built-in email.py. Yes, as Chris mentions, PEP-328 absolute vs. relative imports should help ameliorate the problem, but it's not yet commonly used (unless you're using Py3, it's only at the request of a __future__ import in 2.5+). -tkc From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 22:35:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 03:35:47 GMT Subject: Optimized bytecode in exec statement References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: On Mon, 01 Feb 2010 22:19:43 -0300, Gabriel Genellina wrote: > En Mon, 01 Feb 2010 20:05:16 -0300, Hermann Lauer > escribi?: > >> while trying to optimize some unpack operations with self compiling >> code I wondered howto invoke the optimization in the exec statement. >> Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis >> code, which >> is appended below. > > There is not much difference with -O or -OO; assert statements are > removed, __debug__ is False, docstrings are not stored (in -OO). Code > generation is basically the same. Also code of the form: if __debug__: whatever is compiled away if __debug__ is false. > In general, x+0 may execute arbitrary code, depending on the type of x. > Only if you could determine that x will always be an integer, you could > optimize +0 away. Python (the current version of CPython) does not > perform such analysis; you may investigate psyco, Unladen Swallow, > ShedSkin for such things. Keep in mind that the peephole optimizer in CPython does constant folding: 1+1 compiles to 2. Older versions of Python, and other implementations, may not. But as a general rule, Python does very little optimization at compile time. To a first approximation, "remove asserts" is all that it does. -- Steven From apt.shansen at gmail.com Mon Feb 1 22:41:21 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 1 Feb 2010 19:41:21 -0800 Subject: How to guard against bugs like this one? In-Reply-To: <4B679CF6.1060607@tim.thechases.com> References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <4B679CF6.1060607@tim.thechases.com> Message-ID: <7a9c25c21002011941y6081fcabkd7f5d43b339f3781@mail.gmail.com> On Mon, Feb 1, 2010 at 7:33 PM, Tim Chase wrote: > Stephen Hansen wrote: > >> First, I don't shadow built in modules. Its really not very hard to avoid. >> > > Given the comprehensive nature of the batteries-included in Python, it's > not as hard to accidentally shadow a built-in, unknown to you, but yet that > is imported by a module you are using. I get that people run into this problem on occasion, but honestly-- its *really* not very hard to avoid. If you're creating a module which feels.. generic. As if you may use that same name for a certain kinda topic in a couple different programs-- chances are it /might/ be used as a generic provider of support for that kinda topic in the standard library. "email", "http", "url", anything with a generic .. smell. Assume it /is/ in the stdlib until you demonstrate otherwise, if you aren't deeply familiar with the stdlib. And two seconds later, you can know: 'import numbers' will work. Can't use that. Yeah, when a new version comes out, you may have to read What's New, and see a new module, then rename something. If you're going to use relative imports (and that's #2, I never do-- ever-- even before PEP328 existed), you just have to deal with the flatness of the top-level namespace and how Python broadly claims the right to put darn near anything in there. Although they do google around a bit to try to gauge how likely it is to clash, but still. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Mon Feb 1 23:01:11 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Feb 2010 20:01:11 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <012920a6-c9d7-4200-8b8a-160021dbf3bb@k2g2000pro.googlegroups.com> On Feb 1, 6:34?pm, kj wrote: > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. ?I'll call this directory > myscripts in what follows. [snip] > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? Don't put hundreds of little one-off scripts in single directory. Python can't save you from polluting your own namespace. Don't choose such generic names for modules. Keep in mind module names are potentially globally visible and any sane advice you ever heard about globals is to use descriptive names. I instinctively use adjectives, compound words, and abstract nouns for the names of all my modules so as to be more descriptive, and to avoid name conflicts with classes and variables. Also learn to debug better. Carl Banks From cjblaine at gmail.com Mon Feb 1 23:04:56 2010 From: cjblaine at gmail.com (cjblaine) Date: Mon, 1 Feb 2010 20:04:56 -0800 (PST) Subject: Modules failing to add runtime library path info at link time References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> Message-ID: <303e1371-bc77-4cc8-bbbf-bddfd610fad9@r19g2000yqb.googlegroups.com> On Feb 1, 8:00?pm, Christian Heimes wrote: > cjblaine wrote: > > Where/how can I configure the appropriate portion of our Python > > install to do 100% the right thing instead of just 50% (-L)? > > Python's distutils doesn't alter the library search path unless you tell > it explicitly. > > > A specific example -- note the -L and lack of -R (Solaris build): > > > % python setup.py build > > .... > > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > > % > > The Extension() class supports the rpath argument. Simply add > rpath="/path/to/library/dir" and you are good. > > Christian Thanks for the reply. So, python setup.py build rpath="/whatever/lib" ? From pavlovevidence at gmail.com Mon Feb 1 23:12:25 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Feb 2010 20:12:25 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> Message-ID: <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> On Feb 1, 7:33?pm, Tim Chase wrote: > Stephen Hansen wrote: > > First, I don't shadow built in modules. Its really not very hard to avoid. > > Given the comprehensive nature of the batteries-included in > Python, it's not as hard to accidentally shadow a built-in, > unknown to you, but yet that is imported by a module you are > using. ?The classic that's stung me enough times (and many others > on c.l.p and other forums, as a quick google evidences) such that > I *finally* remember: > > ? ?bash$ touch email.py > ? ?bash$ python > ? ?... > ? ?>>> import smtplib > ? ?Traceback (most recent call last): > ? ? ?File "", line 1, in > ? ? ?File "/usr/lib/python2.5/smtplib.py", line 46, in > ? ? ? ?import email.Utils > ? ?ImportError: No module named Utils > > Using "email.py" is an innocuous name for a script/module you > might want to do emailish things, and it's likely you'll use > smtplib in the same code...and kablooie, things blow up even if > your code doesn't reference or directly use the built-in email.py. email.py is not an innocuous name, it's a generic name in a global namespace, which is a Bad Thing. Plus what does a script or module called "email.py" actually do? Send email? Parse email? "email" is terrible name for a module and you deserve what you got for using it. Name your modules "send_email.py" or "sort_email.py" or if it's a library module of related functions, "email_handling.py". Modules and scripts do things (usually), they should be given action words as names. (**) Questionable though it be, if the Standard Library wants to use an "innocuous" name, It can. Carl Banks From cjblaine at gmail.com Mon Feb 1 23:35:37 2010 From: cjblaine at gmail.com (cjblaine) Date: Mon, 1 Feb 2010 20:35:37 -0800 (PST) Subject: Modules failing to add runtime library path info at link time References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> <303e1371-bc77-4cc8-bbbf-bddfd610fad9@r19g2000yqb.googlegroups.com> Message-ID: <8167cbe0-d099-4a0b-804e-6e91817197ec@b10g2000yqa.googlegroups.com> On Feb 1, 11:04?pm, cjblaine wrote: > On Feb 1, 8:00?pm, Christian Heimes wrote: > > > > > cjblaine wrote: > > > Where/how can I configure the appropriate portion of our Python > > > install to do 100% the right thing instead of just 50% (-L)? > > > Python's distutils doesn't alter the library search path unless you tell > > it explicitly. > > > > A specific example -- note the -L and lack of -R (Solaris build): > > > > % python setup.py build > > > .... > > > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > > > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > > > % > > > The Extension() class supports the rpath argument. Simply add > > rpath="/path/to/library/dir" and you are good. > > > Christian > > Thanks for the reply. > > So, python setup.py build rpath="/whatever/lib" ? Replying to myself: No. Actually, Christian, it looks like it's runtime_library_dirs? class Extension: ... runtime_library_dirs : [string] list of directories to search for C/C++ libraries at run time (for shared extensions, this is when the extension is loaded) So, how does one inject that into, I assume, setup.cfg ? Ideally it could be done via the build command-line, but I don't see a way to do that when browsing python setup.py build --help ( there is no setup.cfg provided in the PyGreSQL source tree, to ) ( continue that example case ) From gobladoome at gmail.com Tue Feb 2 00:26:57 2010 From: gobladoome at gmail.com (Paul) Date: Tue, 2 Feb 2010 18:26:57 +1300 Subject: Problems embedding python 2.6 in C++ In-Reply-To: References: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> Message-ID: <5089497e1002012126h55f0611ct476eabb0ccf1bea1@mail.gmail.com> Thanks Gabriel, I've managed to get it working and so far stable... What wasn't working reliably: mycppclass mycppclass::mycppclass() m_mypymodule = PyImport_Import(pModuleName) mycppclass::~ mycppclass() Py_XDECREF(m_mypymodule) mycppclass::callpy(funcname, args...) PyTuple_SetItem * args PyCallable_Check(func) PyObject_CallObject(func) Current working version: mycppclass mycppclass::mycppclass() {} mycppclass::~ mycppclass() {} mycppclass::callpy(funcname, args...) m_mypymodule = PyImport_Import(pModuleName) pyargs = PyTuple_SetItem * args PyCallable_Check(func) PyObject_CallObject(func,pyargs) Py_XDECREF(m_mypymodule) So now the module is being imported each function call (luckily I don't have to worry about performance) I assume this means that the internal representation of the imported module is being corrupted by something. I found another person with a similar issue here: http://mail.python.org/pipermail/python-dev/2004-March/043306.html - that is a long time ago but another multi-threaded app. I'm happy to use the working method but I'd like to understand what is going on a bit more. Can anyone shed any further light? Regards, Paul. On Tue, Feb 2, 2010 at 11:59 AM, Gabriel Genellina wrote: > En Mon, 01 Feb 2010 18:21:56 -0300, Paul escribi?: > > > I'm extending some old Visual Studio 6 code to add embedded python >> scripting. It works fine most of the time but some python function calls >> do >> not work as expected. >> >> The C++ code is a multithreaded MFC application. I was assuming that it >> was >> GIL issues but I have tried using the manual locking (PyEval_SaveThread & >> PyEval_RestoreThread) and what seems to be the current method >> (PyGILState_Ensure & PyGILState_Release) >> >> Here's the error I'm getting: >> >> Traceback (most recent call last): >> File "...scripts\receipt_parser.py", line 296, in >> get_giftcard_purchase_value >> details = extract_transaction_details_section(test) >> File "...scripts\receipt_parser.py", line 204, in >> extract_transaction_details_section >> for line in base_details: >> TypeError: expected string or Unicode object, NoneType found >> >> base_details is a list of strings (I can just define it like >> 'base_details=["1","2","3"...]' on the line previous) and the code runs >> fine >> when run from standard interpreter. Many other function calls work fine >> from >> the embedded app. >> I create and then Py_DECREF the function parameters and the return value >> after each function call. The module import is created at C++ object >> constructor and then Py_DECREF'd in the desctuctor >> > > Usually, errors in reference count handling prevent objects from being > destroyed (a memory leak) or generate a GPF when accessing an now-inexistent > object. In principle I'd look elsewhere. > > > Anyone else had issues of this kind? >> > > Hard to tell without more info. base_details is built in C++ code? Is it > actually a list, or a subclass defined by you? > A common error is to forget to check *every* API function call for errors, > so errors get unnoticed for a while but are reported on the next check, > which may happen in an entirely unrelated function. > > > My next try will be to use >> sub-interpreters per thread. >> > > I would not do that - I'd try to *simplify* the code to test, not make it > more complicated. > Does it work in a single-threaded application? > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michele.simionato at gmail.com Tue Feb 2 00:47:36 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 1 Feb 2010 21:47:36 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Message-ID: <38aead35-0662-4e05-877a-e924b76ad4e4@c4g2000yqa.googlegroups.com> Wanting the same methods to be attached to different classes often is a code smell (perhaps it is not your case and then use setattr as others said). Perhaps you can just leave such methods outside any class. I would suggest you to use a testing framework not based on inheritance (i.e. use nose or py.test). Perhaps your problem can be solved with generative tests. From rolf.oltmans at gmail.com Tue Feb 2 00:55:16 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 1 Feb 2010 21:55:16 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Message-ID: <9208c5ea-f36d-4a1c-969c-283ffb049491@e19g2000prn.googlegroups.com> On Feb 2, 2:14?am, Steve Holden wrote: > > Should not tee be subclassing test, not unittest.TestCase? > Thank you, Steve. This worked, but I've not clue why? Can you please enlighten me why sub-classing 'test' made it happen? Please. Thanks again. > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 ?http://us.pycon.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/- Hide quoted text - > > - Show quoted text - From gjango.py at gmail.com Tue Feb 2 01:05:38 2010 From: gjango.py at gmail.com (guptha) Date: Mon, 1 Feb 2010 22:05:38 -0800 (PST) Subject: How to use python-mms to send mms Message-ID: Hi group, After hours of googling i found out that we can use python-mms to send mms from our PC connected with GSM cell phone/Modem. I could appreciate if some one guide me with a example of sending an mms using python-mms. I am using Ubuntu9.10 .I am trying to send a ring tone via MMS. Thanks Ganesh Guptha From steve at holdenweb.com Tue Feb 2 01:06:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 01:06:32 -0500 Subject: Adding methods from one class to another, dynamically In-Reply-To: <9208c5ea-f36d-4a1c-969c-283ffb049491@e19g2000prn.googlegroups.com> References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> <9208c5ea-f36d-4a1c-969c-283ffb049491@e19g2000prn.googlegroups.com> Message-ID: Oltmans wrote: > On Feb 2, 2:14 am, Steve Holden wrote: >> Should not tee be subclassing test, not unittest.TestCase? >> > > Thank you, Steve. This worked, but I've not clue why? Can you please > enlighten me why sub-classing 'test' made it happen? Please. Thanks > again. unittest.TestCase doesn't have any test* methods (methods whose names begin with "test"). So neither do your subclasses. When you subclass test, however, test has everything that unittest.TestCase does (because it subclasses unittest.TestCase) and it also has three test* methods. So your subclass of test also has those three methods as well. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From purui.wang at gmail.com Tue Feb 2 01:26:52 2010 From: purui.wang at gmail.com (purui) Date: Mon, 1 Feb 2010 22:26:52 -0800 (PST) Subject: search engine for python source code Message-ID: <717f2d32-df15-4acc-bc39-e9532d23a4b2@u18g2000prn.googlegroups.com> I developed a source code search engine for python (http:// nullege.com). It helps you find samples from open source projects. Unlike other code search engines, it really understands python syntax and generates more relative results. I'm working on expend the source code collection now. Give it a try if google can't find a sample for you. - Purui From casevh at gmail.com Tue Feb 2 01:45:56 2010 From: casevh at gmail.com (casevh) Date: Mon, 1 Feb 2010 22:45:56 -0800 (PST) Subject: ANN: GMPY 1.11 released Message-ID: Everyone, I'm pleased to annouce the final release of GMPY 1.11. GMPY is a wrapper for the MPIR or GMP multiple-precision arithmetic library. GMPY 1.11 is available for download from: http://code.google.com/p/gmpy/ In addition to support for Python 3.x, there are several new features in this release: - Even faster conversion to/from Python longs. - Performance improvements by reducing function overhead. - Performance improvements by improved caching. - Support for cdivmod, fdivmod, and tdivmod. - Unicode strings are accepted on Python 2.x and 3.x. - Fixed regression in GMPY 1.10 where True/False were no longer recognized. Changes since 1.11rc1: - Recognizes GMP 5. - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). Comments on provided binaries The 32-bit Windows installers were compiled with MinGW32 using MPIR 1.3.1 and will automatically recognize the CPU type and use code optimized for the CPU at runtime. The 64-bit Windows installers were compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed instructions are included if you want to compile your own binary. Please report any issues! casevh From masklinn at masklinn.net Tue Feb 2 02:29:38 2010 From: masklinn at masklinn.net (Masklinn) Date: Tue, 2 Feb 2010 08:29:38 +0100 Subject: Logging oddity: handlers mandatory in every single logger? Message-ID: When trying to load the following config file, I get an error ``ConfigParser.NoOptionError: No option 'handlers' in section: 'logger_0'`` (in both Python 2.6.4 and Python 3.1.1 on OSX, obviously ConfigParser is spelled configparser in 3.1): [loggers] keys=root,0 [handlers] keys=console [formatters] keys=simple [logger_root] handlers=console [logger_0] level=DEBUG qualname=0 [handler_console] class=StreamHandler formatter=simple args=() [formatter_simple] format=%(asctime)s:%(levelname)-8s:%(name)s::%(message)s the goal is simply to have a logging level different on ``0`` than it is on ``root``, but to get it I have to include a handler on ``0`` and stop propagation (or messages are displayed on both root and 0). Do note that this behavior (of mandating handlers) does *not* happen when loggers are configured programmatically. Should this be considered a bug? Worthy of opening a request on the tracker? And while I'm at it, a few other oddities/annoyances I noticed in logging: * have to specify the `root` logger in loggers/keys, even though it's mandatory to configure the root logger, or I get the following error:: Traceback (most recent call last): File "test.py", line 6, in logging.config.fileConfig('logging.conf') File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 82, in fileConfig _install_loggers(cp, handlers, disable_existing_loggers) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 183, in _install_loggers llist.remove("root") ValueError: list.remove(x): x not in list * the ``args`` option is required when defining a handler, even in the example above where the handler doesn't take any argument (mandatory ones, anyway) * Logger.log() doesn't take level names, only numerical levels, even after having called ``addLevelName``. This makes logging with custom levels much less clear as one has to write something along the lines of ``logging.log(100, 'Houston, we have a problem')`` instead of the clearer ``logging.log('PANTS_ON_FIRE', 'Houston, we have a problem')``. Note that since the introduction of _checkLevel fixing that is trivial: diff -r dafc54104884 Lib/logging/__init__.py --- a/Lib/logging/__init__.py Sun Jan 31 14:17:25 2010 +0100 +++ b/Lib/logging/__init__.py Mon Feb 01 22:21:03 2010 +0100 @@ -1146,13 +1146,14 @@ logger.log(level, "We have a %s", "mysterious problem", exc_info=1) """ - if not isinstance(level, int): + try: + rv = _checkLevel(level) + except (TypeError, ValueError): if raiseExceptions: - raise TypeError("level must be an integer") - else: - return - if self.isEnabledFor(level): - self._log(level, msg, args, **kwargs) + raise + + if self.isEnabledFor(rv): + self._log(rv, msg, args, **kwargs) def findCaller(self): """ From stefan_ml at behnel.de Tue Feb 2 02:35:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 02 Feb 2010 08:35:13 +0100 Subject: converting XML to hash/dict/CustomTreeCtrl In-Reply-To: References: Message-ID: <4b67d5b1$0$6564$9b4e6d93@newsspool4.arcor-online.net> Astan Chee, 01.02.2010 23:34: > I have xml files that I want to convert to a hash/dict and then further > placed in a wx CustomTreeCtrl based on the structure. The problem I am > having now is that the XML file is very unusual and there aren't any > unique identifiers to be put in a dict and because there are no unique > variables, finding the value of it from a CustromTreeCtrl is abit tricky. > I would appreciate any help or links to projects similar to this. What part of the structure and what information are you interested in? That will determine the key that you should use. Maybe storing more than one field as key is an option. Stefan > The XML file looks something like this: > > > kind="position"> > > This is the note on > calculation times > > > > 609.081574 > 2531.972081 > 65.119100 > > > 1772.011230 > > kind="timers"> > > 72.418861 > > > > 28.285192 > > > 0.000 > > > > 607.432373 > > > > > > > 4833280000 > > 4833280000 > > > 4182777856 > 4182777856 > > 1 > > 1943498 > 0 > > > > 1640100156 > 411307840 > > > 709596712 > 1406752 > > > 737720720 > 0 > > > 607.432373 > > > > 5164184694 > 2054715622 > > > > > > > From ashish.vyas at motorola.com Tue Feb 2 02:48:10 2010 From: ashish.vyas at motorola.com (VYAS ASHISH M-NTB837) Date: Tue, 2 Feb 2010 15:48:10 +0800 Subject: Python packet capture utility In-Reply-To: <717f2d32-df15-4acc-bc39-e9532d23a4b2@u18g2000prn.googlegroups.com> Message-ID: <7C57DB58C81FB64CA979EC6C4DB73E7A03F04217@ZMY16EXM67.ds.mot.com> Dear All I want to capture tcp packets in python. I need to do this on both Windows and Linux on python3.1 I came across the following: http://sourceforge.net/projects/pycap/ http://sourceforge.net/projects/pylibpcap/ http://code.google.com/p/pypcap/ http://oss.coresecurity.com/projects/pcapy.html I am not able to evaluate on my own. Which one should I pick up? Priority is python3.1 support on both windows and Linux. I don't have to do many/complex operations. If it is not so programmer friendly I am OK. Also let me know if 2to3 would help here if there is not python3 support. Regards Ashish From no.email at nospam.invalid Tue Feb 2 03:18:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 02 Feb 2010 00:18:45 -0800 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <7xr5p4yrru.fsf@ruckus.brouhaha.com> Nobody writes: > A better metric is whether using N features has O(N) complexity, or O(N^2) > (where you have to understand how each feature relates to each other > feature) or even O(2^N) (where you have to understand every possible > combination of interactions). M. Felleisen wrote a paper trying to formalize some metric on the expressive power of programming languages. I skimmed through it for about a minute and wasn't convinced, but it apparently has gathered some respect. I want to read it more carefully sometime: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4656 From fetchinson at googlemail.com Tue Feb 2 03:38:07 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Feb 2010 09:38:07 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >>> Personally, I think it is a terribly idea to keep the source file and >>> byte code file in such radically different places. They should be kept >>> together. What you call "clutter" I call having the files that belong >>> together kept together. >> >> I see why you think so, it's reasonable, however there is compelling >> argument, I think, for the opposite view: namely to keep things >> separate. An average developer definitely wants easy access to .py >> files. However I see no good reason for having access to .pyc files. I >> for one have never inspected a .pyc file. Why would you want to have a >> .pyc file at hand? > > If you don't care about access to .pyc files, why do you care where they > are? If they are in a subdirectory module.pyr, then shrug and ignore the > subdirectory. > > If you (generic you) are one of those developers who don't care > about .pyc files, then when you are browsing your source directory and > see this: > > > module.py > module.pyc > > you just ignore the .pyc file. Or delete it, and Python will re-create it > as needed. So if you see > > module.pyr/ > > just ignore that as well. > > > >> If we don't really want to have .pyc files in convenient locations >> because we (almost) never want to access them really, then I'd say it's >> a good idea to keep them totally separate and so make don't get in the >> way. > > I like seeing them in the same place as the source file, because when I > start developing a module, I often end up renaming it multiple times > before it settles on a final name. When I rename or move it, I delete > the .pyc file, and that ensures that if I miss changing an import, and > try to import the old name, it will fail. > > By hiding the .pyc file elsewhere, it is easy to miss deleting one, and > then the import won't fail, it will succeed, but use the old, obsolete > byte code. Okay, I see your point but I think your argument about importing shows that python is doing something suboptimal because I have to worry about .pyc files. Ideally, I only would need to worry about python source files. There is now a chance to 'fix' (quotation marks because maybe there is nothing to fix, according to some) this issue and make all pyc files go away and having python magically doing the right thing. A central pyc repository would be something I was thinking about, but I admit it's a half baked or not even that, probably quarter baked idea. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From dickinsm at gmail.com Tue Feb 2 04:20:59 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 2 Feb 2010 01:20:59 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <05028e22-abed-41cc-a60a-cdc27f803a3a@a5g2000yqi.googlegroups.com> On Feb 2, 3:28?am, Steven D'Aprano wrote: > > There is no module numbers in the standard library, at least not in 2.5. It's new in 2.6 (and 3.0, I think; it's there in 3.1, anyway). It provides abstract base classes for numeric types; see the fractions module source for some of the ways it can be used. Here are the docs: http://docs.python.org/library/numbers.html and also PEP 3141, on which it's based: http://www.python.org/dev/peps/pep-3141/ -- Mark From waku at idi.ntnu.no Tue Feb 2 05:21:02 2010 From: waku at idi.ntnu.no (waku) Date: Tue, 2 Feb 2010 02:21:02 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> Message-ID: <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Steven D'Aprano wrote: > On Sat, 30 Jan 2010 16:58:34 +0000, tanix wrote: [...] > > The very idea of using a number of blanks to identify your block level > > is as insane as it gets. > > Not at all. People do it all the time. The very idea of expecting people > to count nested braces to identify block level is what is crazy, which is > why in languages with braces people still indent the blocks. for reading written code, it's surely helpful to have the code indented, though for *human* reading, the count of blanks seems rather inessential, as long as intended difference in indents is more pronounced than incidental difference between same-level lines. for writing new code, it's not necessarily that helpful to be *forced* to keep with strict indenting rules. in early development phases, code is often experimental, and parts of it may need to be blocked or unblocked as the codebase grows, and for experimentation, the need to carefully and consistently indent and de-indent large chunks of code can easily lead to a mess (blame it on the programmer, not the language, but still). yes, there are editors that help you indent chunks of code, but see below. there are languages where indentation can be either enforced and allow one to omit some syntactic nuissance like braces or begin-end clauses, or made optional, requiring other syntactic means for delimiting blocks etc. (consider f# with its #light declaration, for example.) [...] > In any case, if your IDE mixes tabs and spaces, your IDE is broken and > you should fix your tools rather than blame the language. as long as you are limited to your own code, sure. but if many work on the same bit, and use different editors and indentation policies, blanks-tabs indentation issues are not unlikely. you can have blanks converted to tabs and vice versa automatically, but that's clearly a nuisance. > > > > Braces is the most reliable way to identify blocks. > > Nonsense. For the compiler, both are equally reliable, and for the human > reader, indents beat braces easily. if blanks and tabs are mixed together as indentation, the setting of your ide can easily mess up the indentation, making the structure unclear. in some editors, you can have braces highlighted, so that it's even easier to see where a block ends or starts. and more advanced editors help one see the structure of the code, whereby both indentation and braces are made less important for the reader. but yes, indentation surely helps in reading the code. > > > > Sane compilers ignore blanks altogether. > > Really? So a "sane compiler" sees no difference between: > > for x in mylist: > > and > > forxinmylist: > > > I'm glad I don't have to program using a compiler you consider "sane". the point here was, i think, that blanks may have no syntactic meaning, though they can still be essential at the lexical level. your example targeted the lexical level, and that's rather irrelevant to the problem of syntactically meaningful indentation discussed here. vQ From jeanmichel at sequans.com Tue Feb 2 05:49:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 11:49:04 +0100 Subject: How to guard against bugs like this one? In-Reply-To: <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: <4B680320.1050803@sequans.com> Carl Banks wrote: > On Feb 1, 7:33 pm, Tim Chase wrote: > >> Stephen Hansen wrote: >> >>> First, I don't shadow built in modules. Its really not very hard to avoid. >>> >> Given the comprehensive nature of the batteries-included in >> Python, it's not as hard to accidentally shadow a built-in, >> unknown to you, but yet that is imported by a module you are >> using. The classic that's stung me enough times (and many others >> on c.l.p and other forums, as a quick google evidences) such that >> I *finally* remember: >> >> bash$ touch email.py >> bash$ python >> ... >> >>> import smtplib >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python2.5/smtplib.py", line 46, in >> import email.Utils >> ImportError: No module named Utils >> >> Using "email.py" is an innocuous name for a script/module you >> might want to do emailish things, and it's likely you'll use >> smtplib in the same code...and kablooie, things blow up even if >> your code doesn't reference or directly use the built-in email.py. >> > > > email.py is not an innocuous name, it's a generic name in a global > namespace, which is a Bad Thing. Plus what does a script or module > called "email.py" actually do? Send email? Parse email? "email" is > terrible name for a module and you deserve what you got for using it. > > Name your modules "send_email.py" or "sort_email.py" or if it's a > library module of related functions, "email_handling.py". Modules and > scripts do things (usually), they should be given action words as > names. > > > (**) Questionable though it be, if the Standard Library wants to use > an "innocuous" name, It can. > > > Carl Banks > That does not solve anything, if the smtplib follows your advice, then you'll be shadowing its send_email module. The only way to avoid collision would be to name your module __PDSFLSDF_send_email__13221sdfsdf__.py That way, the probabilty you'd shadow one package hidden module is below the probability that Misses Hilton ever says something relevant. However nobody wants to use such names. Stephen gave good advices in this thread that helps avoiding this issue. JM From mrkafk at gmail.com Tue Feb 2 06:20:34 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Feb 2010 12:20:34 +0100 Subject: unable to catch this exception Message-ID: Exception in thread Thread-9 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/local/lib/python2.6/threading.py", line 522, in __bootstrap_inner File "/var/www/html/cssh.py", line 875, in run File "/var/www/html/cssh.py", line 617, in ssh_connect : 'NoneType' object has no attribute 'BadAuthenticationType' This happens on interpreter shutdown, even though I do try to catch the AttributeError exception: try: fake = paramiko.BadAuthenticationType try: self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) loginsuccess = True except paramiko.BadAuthenticationType, e: # this is line 617 self.conerror = str(e) except paramiko.SSHException, e: self.conerror = str(e) except socket.timeout, e: self.conerror = str(e) except socket.error, e: self.conerror = str(e) except AttributeError: # this happens on interpreter shutdown self.conerror = 'shutdown' It's clear what happens: paramiko gets its attributes cleared or the module perhaps gets unloaded and as result "paramiko" label leads to None, which obviously has no attribute BadAuthenticationType. However, even though this is surrounded by try .. except AttributeError block, it evidently isn't catch. How to catch that exception? Or at least preven displaying this message? Regards, mk From louis.coilliot at gmail.com Tue Feb 2 06:30:44 2010 From: louis.coilliot at gmail.com (lofic) Date: Tue, 2 Feb 2010 03:30:44 -0800 (PST) Subject: threading+popen2 hang Message-ID: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> Hello, I've seen many messages and bug reports on popen2 about pipes, buffer size problems, sub-processes not properly closed, race conditions, popen2 not being thread safe... But I still can't figure what applies to my case. This piece of code: #!/usr/bin/python import threading import popen2 class MyThread ( threading.Thread ): def run ( self ): #popenChild = popen2.Popen3("cat /etc/passwd") #popenChild = popen2.Popen3("/usr/bin/iostat -V") popenChild = popen2.Popen3("/usr/bin/iostat -k -x 1 2") popenChild.wait() print 'Bye' MyThread().start() Works fine on RHEL5/python 2.4.3 Hangs on RHEL4/python 2.3.4 I presume it hangs on wait(). It does not hang with: popenChild = popen2.Popen3("/usr/bin/iostat -V") # short output popenChild = popen2.Popen3("cat /etc/passwd") # long output It does not hang outside of a thread: #!/usr/bin/python import popen2 popenChild = popen2.Popen3("/usr/bin/iostat -k -x 1 2") #print popenChild.fromchild.readlines() popenChild.wait() print 'Bye' Could someone explain this to me ? Thanks in advance. Louis Coilliot From jeanmichel at sequans.com Tue Feb 2 07:26:32 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 13:26:32 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: References: Message-ID: <4B6819F8.8080004@sequans.com> Masklinn wrote: > When trying to load the following config file, I get an error ``ConfigParser.NoOptionError: No option 'handlers' in section: 'logger_0'`` (in both Python 2.6.4 and Python 3.1.1 on OSX, obviously ConfigParser is spelled configparser in 3.1): > > [loggers] > keys=root,0 > [handlers] > keys=console > [formatters] > keys=simple > [logger_root] > handlers=console > [logger_0] > level=DEBUG > qualname=0 > [handler_console] > class=StreamHandler > formatter=simple > args=() > [formatter_simple] > format=%(asctime)s:%(levelname)-8s:%(name)s::%(message)s > > the goal is simply to have a logging level different on ``0`` than it is on ``root``, but to get it I have to include a handler on ``0`` and stop propagation (or messages are displayed on both root and 0). > > Do note that this behavior (of mandating handlers) does *not* happen when loggers are configured programmatically. > > Should this be considered a bug? Worthy of opening a request on the tracker? > > And while I'm at it, a few other oddities/annoyances I noticed in logging: > > * have to specify the `root` logger in loggers/keys, even though it's mandatory to configure the root logger, or I get the following error:: > > Traceback (most recent call last): > File "test.py", line 6, in > logging.config.fileConfig('logging.conf') > File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 82, in fileConfig > _install_loggers(cp, handlers, disable_existing_loggers) > File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 183, in _install_loggers > llist.remove("root") > ValueError: list.remove(x): x not in list > > * the ``args`` option is required when defining a handler, even in the example above where the handler doesn't take any argument (mandatory ones, anyway) > > * Logger.log() doesn't take level names, only numerical levels, even after having called ``addLevelName``. This makes logging with custom levels much less clear as one has to write something along the lines of ``logging.log(100, 'Houston, we have a problem')`` instead of the clearer ``logging.log('PANTS_ON_FIRE', 'Houston, we have a problem')``. Note that since the introduction of _checkLevel fixing that is trivial: > > To add a custom level, I would proceed that way: logging.ALERT = 45 logging.addLevelName(logging.ALERT, 'ALERT !!') logging.getLogger().log(logging.ALERT, 'test') Passing a string to the log method as you did is incorrect. Regarding your first point, I guess it's anti pattern. One way to do it: 1/ Configure the root logger with the lowest value 0, so the root logger does not filter any level. 2/ Configure each of your logger with the correct level That way you can configure your '0' logger as you (badly :o)) named it with one level, and configure a potential '1' logger with another level. Don't bother with propagation. That way you won't need to duplicate your handlers on every logger. JM From clp2 at rebertia.com Tue Feb 2 07:32:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Feb 2010 04:32:08 -0800 Subject: unable to catch this exception In-Reply-To: References: Message-ID: <50697b2c1002020432u718b018fj9abef3c1534a8f9@mail.gmail.com> On Tue, Feb 2, 2010 at 3:20 AM, mk wrote: > Exception in thread Thread-9 (most likely raised during interpreter > shutdown): > Traceback (most recent call last): > ?File "/usr/local/lib/python2.6/threading.py", line 522, in > __bootstrap_inner > ?File "/var/www/html/cssh.py", line 875, in run > ?File "/var/www/html/cssh.py", line 617, in ssh_connect > : 'NoneType' object has no attribute > 'BadAuthenticationType' > > > This happens on interpreter shutdown, even though I do try to catch the > AttributeError exception: > > try: > ? ?fake = paramiko.BadAuthenticationType > ? ?try: > ? ? ? ?self.conobj.connect(self.ip, username=self.username, > key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) > ? ? ? ?loginsuccess = True > ? ?except paramiko.BadAuthenticationType, e: # this is line 617 > ? ? ? ?self.conerror = str(e) > ? ?except paramiko.SSHException, e: > ? ? ? ?self.conerror = str(e) > ? ?except socket.timeout, e: > ? ? ? ?self.conerror = str(e) > ? ?except socket.error, e: > ? ? ? ?self.conerror = str(e) > except AttributeError: > ? ?# this happens on interpreter shutdown > ? ?self.conerror = 'shutdown' > > > It's clear what happens: paramiko gets its attributes cleared or the module > perhaps gets unloaded and as result "paramiko" label leads to None, which > obviously has no attribute BadAuthenticationType. > > However, even though this is surrounded by try .. except AttributeError > block, it evidently isn't catch. How to catch that exception? Or at least > preven displaying this message? Let's see if psychic debugging works...at 4 am... Pure conjecture: Do you have something like the following elsewhere in your code?: try: #code except SomeError, AttributeError: #code For why this causes problems, consider: except SomeError, e: vs. except SomeError, SomeOtherError: Example: try: raise IndexError except IndexError, IOError: pass print repr(IOError) #==> IndexError() Hence, in your case, `AttributeError` may no longer refer to AttributeError. You can check this by adding a `print repr(AttributeError)` at the right place in your code. I further conjecture that pyflakes/pychecker/etc. might issue a warning about the offending bit of code. "Third Option" solution: Since you take the same action no matter the exception's type, have you considered simplifying your code to: fake = paramiko.BadAuthenticationType try: self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) loginsuccess = True except Exception, e: self.conerror = str(e) Cheers, Chris -- http://tvtropes.org/pmwiki/pmwiki.php/Main/TakeAThirdOption http://blog.rebertia.com From mrkafk at gmail.com Tue Feb 2 08:24:46 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Feb 2010 14:24:46 +0100 Subject: passing string for editing in input() Message-ID: Hello, Is there an easy way to get an editing (readline) in Python that would contain string for editing and would not just be empty? I googled but found nothing. Regards, mk From clp2 at rebertia.com Tue Feb 2 08:29:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Feb 2010 05:29:10 -0800 Subject: passing string for editing in input() In-Reply-To: References: Message-ID: <50697b2c1002020529x2f97d03fxe4b1dc79539f2aaa@mail.gmail.com> On Tue, Feb 2, 2010 at 5:24 AM, mk wrote: > Hello, > > Is there an easy way to get an editing (readline) in Python that would > contain string for editing and would not just be empty? > > I googled but found nothing. Er...: http://docs.python.org/library/readline.html It's the third hit for "python readline". Actually reading the page, sounds like you want readline.insert_text() specifically. Cheers, Chris -- Satan, thy name is MMW http://blog.rebertia.com From solipsis at pitrou.net Tue Feb 2 09:05:02 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 2 Feb 2010 14:05:02 +0000 (UTC) Subject: recv_into(bytearray) complains about a "pinned buffer" References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> <4B675FE2.4090404@v.loewis.de> Message-ID: Le Tue, 02 Feb 2010 00:12:34 +0100, Martin v. Loewis a ?crit?: >> recv_into() should simply be fixed to use the new buffer API, as it >> does in 3.x. > > I don't think that's the full solution. The array module should also > implement the new buffer API, so that it would also fail with the old > recv_into. There was a patch for this in http://bugs.python.org/issue6071 , but the bug was closed when hashlib was "fixed". From __peter__ at web.de Tue Feb 2 09:12:59 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Feb 2010 15:12:59 +0100 Subject: passing string for editing in input() References: Message-ID: mk wrote: > Is there an easy way to get an editing (readline) in Python that would > contain string for editing and would not just be empty? http://mail.python.org/pipermail/python-list/2009-June/1209309.html Peter From no.email at please.post Tue Feb 2 09:13:19 2010 From: no.email at please.post (kj) Date: Tue, 2 Feb 2010 14:13:19 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: Let me preface everything by thanking you and all those who replied for their comments. I have only one follow-up question (or rather, set of related questions) that I'm very keen about, plus a bit of a vent at the end. In Steven D'Aprano writes: >As for fixing it, unfortunately it's not quite so simple to fix without >breaking backwards-compatibility. The opportunity to do so for Python 3.0 >was missed. This last point is to me the most befuddling of all. Does anyone know why this opportunity was missed for 3.0? Anyone out there with the inside scoop on this? Was the fixing of this problem discussed in some PEP or some mailing list thread? (I've tried Googling this but did not hit on the right keywords to bring up the deliberations I'm looking for.) ~k [NB: as I said before, what follows begins to slide into a vent, and is quite unimportant; I've left it, for whatever grain of truth it may contain, as an grossly overgrown PS; feel free to ignore it, I'm *by far* most interested in the question stated in the paragraph right above, because it will give me, I hope, a better sense of where the biggest obstacles to fixing this problem lie.] P.S. Yes, I see the backwards-compatibility problem, but that's what rolling out a whole new versions is good for; it's a bit of a fresh start. I remember hearing GvR's Google Talk on the coming Python 3, which was still in the works then, and being struck by the sheer *modesty* of the proposed changes (while the developers of the mythical Perl6 seemed to be on a quest for transcendence to a Higher Plane of Programming, as they still are). In particular the business with print -> print() seemed truly bizarre to me: this is a change that will break a *huge* volume of code, and yet, judging by the rationale given for it, the change solves what are, IMHO, a relatively minor annoyances. Python's old print statement is, I think, at most a tiny little zit invisible to all but those obsessed with absolute perfection. And I can't imagine that whatever would be required to fix Python's import system could break more code than redefining the rules for a workhorse like print. In contrast, the Python import problem is a ticking bomb potentially affecting all code that imports other modules. All that needs to happen is that, in a future release of Python, some new standard module emerges (like numbers.py emerged in 2.6), and this module is imported by some module your code imports. Boom! Note that it was only coincidental that the bug I reported in this thread occurred in a script I wrote recently. I could have written both scripts before 2.6 was released, and the new numbers.py along with it; barring the uncanny clairvoyance of some responders, there would have been, at the time, absolutely no plausible reason for not naming one of the two scripts numbers.py. To the argument that the import system can't be easily fixed because it breaks existing code, one can reply that the *current* import system already breaks existing code, as illustrated by the example I've given in this thread: this could have easily been old pre-2.6 code that got broken just because Python decided to add numbers.py to the distribution. (Yes, Python can't guarantee that the names of new standard modules won't clash with the names of existing local modules, but this is true for Perl as well, and due to Perl's module import scheme (and naming conventions), a scenario like the one I presented in this thread would have been astronomically improbable. The Perl example shows that the design of the module import scheme and naming conventions for standard modules can go a long way to minimize the consequences of this unavoidable potential for future name clashes.) From mrkafk at gmail.com Tue Feb 2 09:37:10 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Feb 2010 15:37:10 +0100 Subject: passing string for editing in input() In-Reply-To: References: Message-ID: Peter Otten wrote: > mk wrote: > >> Is there an easy way to get an editing (readline) in Python that would >> contain string for editing and would not just be empty? > > http://mail.python.org/pipermail/python-list/2009-June/1209309.html > > Peter Thanks a lot! Just what I needed. Regards, mk From gerald.britton at gmail.com Tue Feb 2 09:47:30 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 2 Feb 2010 09:47:30 -0500 Subject: Iterating over a function call In-Reply-To: References: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Message-ID: <5d1a32001002020647q29506c30s46ac98accc6098ca@mail.gmail.com> [snip] >> 2. side effect of (maybe) leaking the iterator variable "value" into >> the code following the loop (if the iterator is not empty). > > So? it is sometime useful. Except that you can't guarantee that it will be set since the for loop will not execute if the iterable is empty. >> >> I can take care of 2 by explicitly deleting the variable at the end: >> >> ? ?del value >> >> but I'd probably forget to do that sometimes. > > So? If having 'value' bound breaks your subsequent code, I consider it > buggy. Quite so. I just like to eliminate the possibility up front. If 'value' is never bound, the the bug will show up sooner. -- Gerald Britton From invalid at invalid.invalid Tue Feb 2 10:00:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Feb 2010 15:00:28 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: On 2010-02-02, Roy Smith wrote: > In article , kj > wrote: > >> Through a *lot* of trial an error I finally discovered that the >> root cause of the problem was the fact that, in the same directory >> as buggy.py, there is *another* innocuous little script, totally >> unrelated, whose name happens to be numbers.py. >> [...] >> It turns out that buggy.py imports psycopg2, as you can see, and >> apparently psycopg2 (or something imported by psycopg2) tries to >> import some standard Python module called numbers; instead it ends >> up importing the innocent myscript/numbers.py, resulting in *absolute >> mayhem*. > > I feel your pain, but this is not a Python problem, per-se. I think it is. There should be different syntax to import from "standard" places and from "current directory". Similar to the difference between "foo.h" and in cpp. > The general > pattern is: > > 1) You have something which refers to a resource by name. > > 2) There is a sequence of places which are searched for this > name. Searching the current directory by default is the problem. Nobody in their right mind has "." in the shell PATH and IMO it shouldn't be in Python's import path either. Even those wreckless souls who do put "." in their path put it at the end so they don't accidentally override system commands. -- Grant Edwards grante Yow! So this is what it at feels like to be potato visi.com salad From invalid at invalid.invalid Tue Feb 2 10:09:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Feb 2010 15:09:26 +0000 (UTC) Subject: Python packet capture utility References: Message-ID: On 2010-02-02, VYAS ASHISH M-NTB837 wrote: > > Dear All > > I want to capture tcp packets in python. I need to do this on both > Windows and Linux on python3.1 > > I came across the following: > http://sourceforge.net/projects/pycap/ > http://sourceforge.net/projects/pylibpcap/ > http://code.google.com/p/pypcap/ > http://oss.coresecurity.com/projects/pcapy.html > > > I am not able to evaluate on my own. And we're supposed to evaluate them for you? pycap: last release 5/2003. pylibpcap: last release 5/2008 pycap: last release 1/2007 pcapy: last release 3/2007 > Which one should I pick up? I'd start with the newest one. It's the one I use, and it works fine for me. > Priority is python3.1 support on both windows and Linux. I don't think any of them support 3.1. > I don't have to do many/complex operations. If it is not so > programmer friendly I am OK. > > Also let me know if 2to3 would help here if there is not > python3 support. I'f you're not expereienced porting libraries from 2.4 to 3.1, then you shouldn't be using 3.1. -- Grant Edwards grante Yow! Did you move a lot of at KOREAN STEAK KNIVES this visi.com trip, Dingy? From apt.shansen at gmail.com Tue Feb 2 10:12:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 2 Feb 2010 07:12:02 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7a9c25c21002020712h23fedd3g6e97368413633674@mail.gmail.com> On Tue, Feb 2, 2010 at 6:13 AM, kj wrote: > In Steven > D'Aprano writes: > > >As for fixing it, unfortunately it's not quite so simple to fix without > >breaking backwards-compatibility. The opportunity to do so for Python 3.0 > >was missed. > > This last point is to me the most befuddling of all. Does anyone > know why this opportunity was missed for 3.0? Anyone out there > with the inside scoop on this? Was the fixing of this problem > discussed in some PEP or some mailing list thread? (I've tried > Googling this but did not hit on the right keywords to bring up > the deliberations I'm looking for.) > The problem with "fixing" the import system is that touching it in any way potentially breaks *vast* volumes of code that works just right, right now in any version of Python. It's not even something you can easily test: there's a lot of edge-cases supporting various features that have been added over the years. A pure-python import mechanism with a set of test-cases to "prove" it reliably mimic'd the existing mechanism wasn't even complete by the time Python3 came out, without that, any changes to "fix" Python3+'s import system would just be a shot in the dark. And there'd be no telling just /what/ it would break if you start changing these very old import semantics. > P.S. Yes, I see the backwards-compatibility problem, but that's > what rolling out a whole new versions is good for; it's a bit of > a fresh start. I remember hearing GvR's Google Talk on the coming > Python 3, which was still in the works then, and being struck by > the sheer *modesty* of the proposed changes (while the developers > of the mythical Perl6 seemed to be on a quest for transcendence to > a Higher Plane of Programming, as they still are). Yes, it was a relatively modest upgrade, thankfully so. We actually have our fixed language, and Perl6 is coming on some point on the horizon. Python3 allowed backwards incompatible changes, but they still needed to have a justification to them: and more importantly, they usually needed to change from one well-defined state to a new, 'cleaner' well-defined state, so they could be automatically corrected or at least easily found. The Bytes/Unicode situation is one case where there wasn't a well-defined state you can convert from, and so with Python3, every single string you really need to look at and decide, "Should this have been bytes, or characters?". Having to ask that question for every string is a significant burden, to expect someone to have to ask the same sort of question for every single import is asking -way- too much for people porting to Python 3. Py3k's adoption is a slow, uphill process-- no one expected (from my reading at least)-- it to take less then years and multiple 3.x iterations before people would /really/ significantly start using it. There's too many third party modules people depend on and they have to slowly be converted. They're being converted, and IMHO there's steadily growing momentum on this (albeit not huge momentum), but had they messed with the import semantics-- this would be /way/ more difficult, and you might end up with a DOA project. > In particular > the business with print -> print() seemed truly bizarre to me: this > is a change that will break a *huge* volume of code, and yet, > judging by the rationale given for it, the change solves what are, > IMHO, a relatively minor annoyances. Python's old print statement > is, I think, at most a tiny little zit invisible to all but those > obsessed with absolute perfection. You have a very strange perception of huge. For one thing, every single use of print() can be converted -automatically-: the rules of this change are very clear. The print statement was a bizarre sort of wart (look at >>!) and fixing it is easy. Further, *huge* volume of code-- /really/?! In my experience, print isn't really all /that/ common after you get out of the tutorial and start doing real code. If you're doing lots of shell scripting maybe that's not the case: but for any sort of server-daemon-process sort of apps, print is utterly unacceptable. I use the logging module. For GUI apps, same. But for those times when you use print.. its /really easy/ to fix. And I can't imagine that whatever > would be required to fix Python's import system could break more > code than redefining the rules for a workhorse like print. > Your imagination is lacking here then: virtually every single bit of Python code uses import, and messing with it can have wide implications that you can't even /define/ ahead of time. As such you can't write a guide, a 2to3 fixer, or a HOWTO to tell people: hey, this is how you used to do things in Python2, this is how you do them in Python3. Having them mess with the import machinery would be throwing every Py3 developer under the bus, saying, "Well, just run it. Fix whatever errors happen." > In contrast, the Python import problem is a ticking bomb potentially > affecting all code that imports other modules. All that needs to > happen is that, in a future release of Python, some new standard > module emerges (like numbers.py emerged in 2.6), and this module > is imported by some module your code imports. Boom! Note that it > was only coincidental that the bug I reported in this thread occurred > in a script I wrote recently. I could have written both scripts > before 2.6 was released, and the new numbers.py along with it; > barring the uncanny clairvoyance of some responders, there would > have been, at the time, absolutely no plausible reason for not > naming one of the two scripts numbers.py. > This is drifting into hyperbole; yes, Python's flat import namespace isn't ideal, yes, it can mean that when a new version is released you may shadow something you didn't before, yes, that can cause code to break. Its really, really, really not anything like as bad as you're making it out to be. Your bomb can be averted via: - Don't use relative imports. - Don't structure your code and environment such that your libs and/or scripts end up living in the global namespace if you want to be future-proof. - If you didn't future-proof your code, then check What's New on new versions of Python. There, time bomb disarmed. To the argument that the import system can't be easily fixed because > it breaks existing code, one can reply that the *current* import > system already breaks existing code, as illustrated by the example > I've given in this thread: this could have easily been old pre-2.6 > code that got broken just because Python decided to add numbers.py > to the distribution. Yes, one can make that argument, but it would be specious. Messing with the import system -would- have broken code, and done so in a way which can not be easily or clearly identified by looking at code directly, as you wouldn't know "break" until you somehow took the /entire/ layout of the system into account, which is infeasible. The current import system -may- break code, if someone writes their code in such a way, structures their code in such a way, and Python happens to add a new item to its standard library which causes that code to now shadow a standard module. The former case, 'change the import system', requires someone look at every single import, evaluate that import in the full context of the environment, and determine if its working as intended or not. The latter case, 'leave the non-ideal import system in place', requires someone look at imports of top-level modules, and ensure that they don't shadow built-ins. You don't need to know where all the sys.path items are, you don't need to know if you're importing from a zip file, or anything like that. You just need to see if your top-level / relative import is shadowing a new standard library module or not. Yes, the latter case means that if you are supporting new Python versions that come out, you'll have to make that evaluation with each one if you decide not to code and structure your code in such a way that it is future-proof. > (Yes, Python can't guarantee that the names > of new standard modules won't clash with the names of existing > local modules, but this is true for Perl as well, and due to Perl's > module import scheme (and naming conventions), a scenario like the > one I presented in this thread would have been astronomically > improbable. The Perl example shows that the design of the module > import scheme and naming conventions for standard modules can go > a long way to minimize the consequences of this unavoidable potential > for future name clashes.) > Again: It is very, very avoidable. I know, cuz I've sorta been avoiding it easily and successfully for years now :P --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From bartc at freeuk.com Tue Feb 2 10:23:37 2010 From: bartc at freeuk.com (bartc) Date: Tue, 02 Feb 2010 15:23:37 GMT Subject: Python and Ruby In-Reply-To: <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: Jonathan Gardner wrote: > One of the bad things with languages like perl and Ruby that call > without parentheses is that getting a function ref is not obvious. You > need even more syntax to do so. In perl: > > foo(); # Call 'foo' with no args. > $bar = foo; # Call 'foo; with no args, assign to '$bar' > $bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > # By the way, this '&' is not the bitwise-and '&'!!!! > $bar->() # Call whatever '$bar' is pointing at with no args > > Compare with python: > > foo() # Call 'foo' with no args. > bar = foo() # 'bar' is now pointing to whatever 'foo()' returned > bar = foo # 'bar' is now pointing to the same thing 'foo' points to > bar() # Call 'bar' with no args > > One is simple, consistent, and easy to explain. The other one requires > the introduction of advanced syntax and an entirely new syntax to make > function calls with references. If you get rid of the syntax specific to Perl, then having to explicitly obtain a function reference, or to dereference the result, is not such a big deal: foo # Call 'foo' with no args. bar = foo # Call 'foo; with no args, assign to 'bar' bar = &foo # Don't call 'foo', but assign a pointer to it to 'bar' bar^ # Call whatever 'bar' is pointing at with no args (Here I use ^ instead of -> to dereference.) Compared with Python, it saves 3 lots of (), but needs & and ^ added. Still a net saving. > One of the bad things with languages like perl and Ruby that call > without parentheses is that getting a function ref is not obvious. I'd say that having this "&" symbol in front of "foo" makes it more obvious than just foo by itself. But I agree not quite as clean. Another thing is that you have to know whether "bar" is a function, or a function ref, and use the appropriate syntax. Sometimes this is helpful, sometimes not. -- Bartc From masklinn at masklinn.net Tue Feb 2 11:28:52 2010 From: masklinn at masklinn.net (Masklinn) Date: Tue, 2 Feb 2010 17:28:52 +0100 Subject: Logging oddity: handlers mandatory in every single logger? Message-ID: Jean-Michel Pichavant wrote: >To add a custom level, I would proceed that way: > >logging.ALERT = 45 >logging.addLevelName(logging.ALERT, 'ALERT !!') >logging.getLogger().log(logging.ALERT, 'test') > >Passing a string to the log method as you did is incorrect. I know it's currently incorrect. My point was more along the line that there was *no reason* for it to be incorrect. logging already contains all the tools for log('PANTS_ON_FIRE') to be allowed >Regarding your first point, I guess it's anti pattern. One way to do it: >1/ Configure the root logger with the lowest value 0, so the root logger >does not filter any level. >2/ Configure each of your logger with the correct level > >That way you can configure your '0' logger as you (badly :o)) named it >with one level, and configure a potential '1' logger with another level. >Don't bother with propagation. That way you won't need to duplicate your >handlers on every logger. re logger 0, no need for complex name for a test case (and it allowed me to create easy-to-remember 0.1 and 0.1.2 if needed) Re your answer, from what I understand you want the root logger to NOTSET and then each child logger with its correct level? But that's not a solution, each and every level will *still* require a handler explicitly configured on it. That's in fact very much my issue: logging refuses that a logger be handler-less in a config file, it's mandatory to configure a handler any time a logger is configured. From edreamleo at gmail.com Tue Feb 2 11:36:24 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Tue, 02 Feb 2010 10:36:24 -0600 Subject: ANN: Leo 4.7 b3 released Message-ID: Leo 4.7 beta 3 February 2, 2009 Leo 4.7 beta 3 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7 beta 3 fixes all known serious bugs in Leo. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - @auto-rst now works much more reliably reliably. - Leo no longer @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Edward K. Ream Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From peloko45 at gmail.com Tue Feb 2 11:42:12 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 2 Feb 2010 08:42:12 -0800 (PST) Subject: No return to the parent function Message-ID: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> I've a main function called i.e. *foo()* which has a block of code that is repetead several times (for the error catching code and error reporting), but that code has a return to exit of *foo()* ----------- foo(): ... if self.background: _log.exception(str(error)) return ReturnCode.ERROR, None else: raise NameError(error) ----------- So I would tu put that code block into a separated function (*throw() *), but the problem is that it returns to the parent function (foo()). How to solve it? From jeanmichel at sequans.com Tue Feb 2 11:52:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 17:52:48 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: References: Message-ID: <4B685860.4000903@sequans.com> Masklinn wrote: > Jean-Michel Pichavant wrote: > >> To add a custom level, I would proceed that way: >> >> logging.ALERT = 45 >> logging.addLevelName(logging.ALERT, 'ALERT !!') >> logging.getLogger().log(logging.ALERT, 'test') >> >> Passing a string to the log method as you did is incorrect. >> > > I know it's currently incorrect. My point was more along the line that there was *no reason* for it to be incorrect. logging already contains all the tools for log('PANTS_ON_FIRE') to be allowed > The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. > >> Regarding your first point, I guess it's anti pattern. One way to do it: >> 1/ Configure the root logger with the lowest value 0, so the root logger >> does not filter any level. >> 2/ Configure each of your logger with the correct level >> >> That way you can configure your '0' logger as you (badly :o)) named it >> with one level, and configure a potential '1' logger with another level. >> Don't bother with propagation. That way you won't need to duplicate your >> handlers on every logger. >> > > re logger 0, no need for complex name for a test case (and it allowed me to create easy-to-remember 0.1 and 0.1.2 if needed) > > Re your answer, from what I understand you want the root logger to NOTSET and then each child logger with its correct level? But that's not a solution, each and every level will *still* require a handler explicitly configured on it. That's in fact very much my issue: logging refuses that a logger be handler-less in a config file, it's mandatory to configure a handler any time a logger is configured. > the field handlers must be defined even if empty. [loggers] keys=root,0,1 [handlers] keys=console [formatters] keys=simple [logger_root] level=DEBUG handlers=console [logger_1] level=INFO qualname=1 handlers= [logger_0] level=DEBUG qualname=0 handlers= [handler_console] class=StreamHandler formatter=simple args=() [formatter_simple] format=%(asctime)s:%(levelname)-8s:%(name)s::%(message)s import logging; import logging.config logging.config.fileConfig("log.config") l1 = logging.getLogger("1") l0 = logging.getLogger("0") l1.debug('I am l1') ... l0.debug('I am l0') ... 2010-02-02 17:48:55,710:DEBUG :0::I am l0 JM From arnodel at googlemail.com Tue Feb 2 11:55:58 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 02 Feb 2010 16:55:58 +0000 Subject: No return to the parent function References: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> Message-ID: Joan Miller writes: > I've a main function called i.e. *foo()* which has a block of code > that is repetead several times (for the error catching code and error > reporting), but that code has a return to exit of *foo()* > > ----------- > foo(): > ... > if self.background: > _log.exception(str(error)) > return ReturnCode.ERROR, None > else: > raise NameError(error) > > ----------- > > So I would tu put that code block into a separated function (*throw() > *), but the problem is that it returns to the parent function (foo()). > How to solve it? If I understand correctly, you can simply do this: def throw(...): if ...: ... return ... else: raise ... def foo(): ... return throw(...) HTH I.e. if throw returns something, foo returns it as well. If throw raises an exception, it will go through foo. Is this what you want? -- Arnaud From peloko45 at gmail.com Tue Feb 2 12:00:45 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 2 Feb 2010 09:00:45 -0800 (PST) Subject: No return to the parent function References: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> Message-ID: <4aded884-b81e-45d6-be08-39e064fbe184@m16g2000yqc.googlegroups.com> On 2 feb, 16:55, Arnaud Delobelle wrote: > Joan Miller writes: > > I've a main function called i.e. *foo()* which has a block of code > > that is repetead several times (for the error catching code and error > > reporting), but that code has a return to exit of *foo()* > > > ----------- > > foo(): > > ? ... > > ? ? if self.background: > > ? ? ? ? _log.exception(str(error)) > > ? ? ? ? return ReturnCode.ERROR, None > > ? ? else: > > ? ? ? ? raise NameError(error) > > > ----------- > > > So I would tu put that code block into a separated function (*throw() > > *), but the problem is that it returns to the parent function (foo()). > > How to solve it? > > If I understand correctly, you can simply do this: > > def throw(...): > ? ? if ...: > ? ? ? ? ... > ? ? ? ? return ... > ? ? else: > ? ? ? ? raise ... > > def foo(): > ? ? ... > ? ? return throw(...) > > HTH > > I.e. if throw returns something, foo returns it as well. ?If throw > raises an exception, it will go through foo. ?Is this what you want? > > -- > Arnaud Yes, that is it. It was more simple that I had thinked, thanks! From nobody at nowhere.com Tue Feb 2 12:02:10 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 17:02:10 +0000 Subject: How to guard against bugs like this one? References: Message-ID: On Tue, 02 Feb 2010 15:00:28 +0000, Grant Edwards wrote: >>> It turns out that buggy.py imports psycopg2, as you can see, and >>> apparently psycopg2 (or something imported by psycopg2) tries to >>> import some standard Python module called numbers; instead it ends >>> up importing the innocent myscript/numbers.py, resulting in *absolute >>> mayhem*. >> >> I feel your pain, but this is not a Python problem, per-se. > > I think it is. I agree. > There should be different syntax to import from > "standard" places and from "current directory". Similar to the > difference between "foo.h" and in cpp. I don't know if that's necessary. Only supporting the "foo.h" case would work fine if Python behaved like gcc, i.e. if the "current directory" referred to the directory contain the file performing the import rather than in the process' CWD. As it stands, imports are dynamically scoped, when they should be lexically scoped. >> The general >> pattern is: >> >> 1) You have something which refers to a resource by name. >> >> 2) There is a sequence of places which are searched for this >> name. > > Searching the current directory by default is the problem. > Nobody in their right mind has "." in the shell PATH and IMO it > shouldn't be in Python's import path either. Even those > wreckless souls who do put "." in their path put it at the end > so they don't accidentally override system commands. Except, what should be happening here is that it should be searching the directory containing the file performing the import *first*. If foo.py contains "import bar", and there's a bar.py in the same directory as foo.py, that's the one it should be using. The existing behaviour is simply wrong, and there's no excuse for it ("but it's easier to implement" isn't a legitimate argument). The only situation where the process' CWD should be used is for an import statement in a non-file source (i.e. stdin or the argument to the -c switch). From python at mrabarnett.plus.com Tue Feb 2 12:08:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Feb 2010 17:08:54 +0000 Subject: No return to the parent function In-Reply-To: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> References: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> Message-ID: <4B685C26.3060601@mrabarnett.plus.com> Joan Miller wrote: > I've a main function called i.e. *foo()* which has a block of code > that is repetead several times (for the error catching code and error > reporting), but that code has a return to exit of *foo()* > > ----------- > foo(): > ... > if self.background: > _log.exception(str(error)) > return ReturnCode.ERROR, None > else: > raise NameError(error) > > ----------- > > So I would tu put that code block into a separated function (*throw() > *), but the problem is that it returns to the parent function (foo()). > How to solve it? Call it in a return statement. From alfps at start.no Tue Feb 2 12:20:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Feb 2010 18:20:41 +0100 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: * Nobody: > On Tue, 02 Feb 2010 15:00:28 +0000, Grant Edwards wrote: > >>>> It turns out that buggy.py imports psycopg2, as you can see, and >>>> apparently psycopg2 (or something imported by psycopg2) tries to >>>> import some standard Python module called numbers; instead it ends >>>> up importing the innocent myscript/numbers.py, resulting in *absolute >>>> mayhem*. >>> I feel your pain, but this is not a Python problem, per-se. >> I think it is. > > I agree. > >> There should be different syntax to import from >> "standard" places and from "current directory". Similar to the >> difference between "foo.h" and in cpp. > > I don't know if that's necessary. Only supporting the "foo.h" case would > work fine if Python behaved like gcc, i.e. if the "current directory" > referred to the directory contain the file performing the import rather > than in the process' CWD. > > As it stands, imports are dynamically scoped, when they should be > lexically scoped. > >>> The general >>> pattern is: >>> >>> 1) You have something which refers to a resource by name. >>> >>> 2) There is a sequence of places which are searched for this >>> name. >> Searching the current directory by default is the problem. >> Nobody in their right mind has "." in the shell PATH and IMO it >> shouldn't be in Python's import path either. Even those >> wreckless souls who do put "." in their path put it at the end >> so they don't accidentally override system commands. > > Except, what should be happening here is that it should be searching the > directory containing the file performing the import *first*. If foo.py > contains "import bar", and there's a bar.py in the same directory as > foo.py, that's the one it should be using. > > The existing behaviour is simply wrong, and there's no excuse for it > ("but it's easier to implement" isn't a legitimate argument). +1 > The only situation where the process' CWD should be used is for an import > statement in a non-file source (i.e. stdin or the argument to the -c > switch). Hm, not sure about that last. Cheers, - Alf From tjreedy at udel.edu Tue Feb 2 13:29:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Feb 2010 13:29:54 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: On 2/2/2010 9:13 AM, kj wrote: >> As for fixing it, unfortunately it's not quite so simple to fix without >> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >> was missed. > > This last point is to me the most befuddling of all. Does anyone > know why this opportunity was missed for 3.0? Anyone out there > with the inside scoop on this? Was the fixing of this problem > discussed in some PEP or some mailing list thread? (I've tried > Googling this but did not hit on the right keywords to bring up > the deliberations I'm looking for.) There was a proposal to put the whole stdlib into a gigantic package, so that import itertools would become, for instance import std.itertools. Guido rejected that. I believe he both did not like it and was concerned about making upgrade to 3.x even harder. The discussion was probably on the now closed py3k list. Terry Jan Reedy From tinnews at isbd.co.uk Tue Feb 2 13:32:46 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Tue, 2 Feb 2010 18:32:46 +0000 Subject: What's this vText() annotation mean? Message-ID: What does this vText() annotation mean in a returned list:- [['Apr 19', vText(u'PAYE'), ''], ['Mar 31', vText(u'VAT'), ''], ['May 19', vText(u'Year end PAYE'), '']] I *guess* it's some sort of indication of non-constant text, I need a way to make it constant (well, to get a constant copy of it) because a function I'm passing it to is complaining about a type mismatch:- TypeError: in method 'Fl_Input__value', argument 2 of type 'char const *' -- Chris Green From pavlovevidence at gmail.com Tue Feb 2 13:38:53 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 10:38:53 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: On Feb 2, 9:02?am, Nobody wrote: > I don't know if that's necessary. Only supporting the "foo.h" case would > work fine if Python behaved like gcc, i.e. if the "current directory" > referred to the directory contain the file performing the import rather > than in the process' CWD. > > As it stands, imports are dynamically scoped, when they should be > lexically scoped. Mostly incorrect. The CWD is in sys.path only for interactive sessions, and when started with -c switch. When running scripts, the directory where the script is located is used instead, not the process's working directory. So, no, it isn't anything like dynamic scoping. > The only situation where the process' CWD should be used is for an import > statement in a non-file source (i.e. stdin or the argument to the -c > switch). It already is that way, chief. I think you're misunderstanding what's wrong here; the CWD doesn't have anything to do with it. Even if CWD isn't in the path you still get the bad behavior kj noted. So now what? Python's importing can be improved but there's no foolproof way to get rid of the fundamental problem of name clashes. Carl Banks From pavlovevidence at gmail.com Tue Feb 2 13:45:07 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 10:45:07 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: On Feb 2, 2:49?am, Jean-Michel Pichavant wrote: > Carl Banks wrote: > > Name your modules "send_email.py" or "sort_email.py" or if it's a > > library module of related functions, "email_handling.py". ?Modules and > > scripts do things (usually), they should be given action words as > > names. > > > (**) Questionable though it be, if the Standard Library wants to use > > an "innocuous" name, It can. > > That does not solve anything, Of course it does, it solves the problem of having poorly-named modules. It also helps reduce possibility of name clashes. > if the smtplib follows your advice, then > you'll be shadowing its send_email module. > The only way to avoid collision would be to name your module > __PDSFLSDF_send_email__13221sdfsdf__.py I know, and as we all know accidental name clashes are the end of the world and Mother Python should protect us feeble victims from any remote possibility of ever having a name clash. Carl Banks From arnodel at googlemail.com Tue Feb 2 14:00:21 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 02 Feb 2010 19:00:21 +0000 Subject: What's this vText() annotation mean? References: Message-ID: tinnews at isbd.co.uk writes: > What does this vText() annotation mean in a returned list:- > > [['Apr 19', vText(u'PAYE'), ''], It means your list contains an instance of a class whose __repr__() method returns "vText(u'PAYE')". If it follows common practice, the class is probably named "vText". You are likely to be importing and using a module that defines a class called "vText". I don't know such a module, I don't think it's in the standard library so it would be useful if you gave more details about the context. A quick google for "vtext python" yields something about an iCalendar package for python. Is it what you are using? -- Arnaud From martin at v.loewis.de Tue Feb 2 14:01:21 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 02 Feb 2010 20:01:21 +0100 Subject: recv_into(bytearray) complains about a "pinned buffer" In-Reply-To: <942aa99d-1bc1-4aa8-867a-6366cb3668a1@36g2000yqu.googlegroups.com> References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> <4B675FE2.4090404@v.loewis.de> <942aa99d-1bc1-4aa8-867a-6366cb3668a1@36g2000yqu.googlegroups.com> Message-ID: > Clearly it was added to work with an array, and it's > being used with an array. Why shouldn't people use it > with Python 2.x? Because it's not thread-safe; it may crash the interpreter if used incorrectly. Of course, if you don't share the array across threads, it can be safe to use. Regards, Martin From jeanmichel at sequans.com Tue Feb 2 14:07:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 20:07:48 +0100 Subject: How to guard against bugs like this one? In-Reply-To: References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: <4B687804.6070005@sequans.com> Carl Banks wrote: > On Feb 2, 2:49 am, Jean-Michel Pichavant > wrote: > >> Carl Banks wrote: >> >>> Name your modules "send_email.py" or "sort_email.py" or if it's a >>> library module of related functions, "email_handling.py". Modules and >>> scripts do things (usually), they should be given action words as >>> names. >>> >>> (**) Questionable though it be, if the Standard Library wants to use >>> an "innocuous" name, It can. >>> >> That does not solve anything, >> > > Of course it does, it solves the problem of having poorly-named > modules. It also helps reduce possibility of name clashes. > Actually don't you think it will increase the possibility ? There are much less possibilties of properly naming an object than badly naming it. So if everybody tend to properly name their object with their obvious version like you proposed, the set of possible names will decrease, increasing the clash ratio. I'm just nitpicking by the way, but it may be better to ask for better namespacing instead of naming (which is good thing but unrelated to the OP issue). JM From no.email at please.post Tue Feb 2 14:43:40 2010 From: no.email at please.post (kj) Date: Tue, 2 Feb 2010 19:43:40 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: In Terry Reedy writes: >On 2/2/2010 9:13 AM, kj wrote: >>> As for fixing it, unfortunately it's not quite so simple to fix without >>> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >>> was missed. >> >> This last point is to me the most befuddling of all. Does anyone >> know why this opportunity was missed for 3.0? Anyone out there >> with the inside scoop on this? Was the fixing of this problem >> discussed in some PEP or some mailing list thread? (I've tried >> Googling this but did not hit on the right keywords to bring up >> the deliberations I'm looking for.) >There was a proposal to put the whole stdlib into a gigantic package, so >that >import itertools >would become, for instance >import std.itertools. >Guido rejected that. I believe he both did not like it and was concerned >about making upgrade to 3.x even harder. The discussion was probably on >the now closed py3k list. Thanks. I'll look for this thread. ~K From MLMDev at Comcast.net Tue Feb 2 15:14:27 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Tue, 2 Feb 2010 15:14:27 -0500 Subject: lists as an efficient implementation of large two-dimensional arrays(!) Message-ID: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> An instructive lesson in YAGNI ("you aren't going to need it"), premature optimization, and not making assumptions about Python data structure implementations. I need a 1000 x 1000 two-dimensional array of objects. (Since they are instances of application classes it appears that the array module is useless; likewise, since I am using Python 3.1, so among other things, I can't use numpy or its relatives.) The usage pattern is that the array is first completely filled with objects. Later, objects are sometimes accessed individually by row and column and often the entire array is iterated over. Worried (unnecessarily, as it turns out) by the prospect of 1,000,000 element list I started by constructing a dictionary with the keys 1 through 1000, each of which had as its value another dictionary with the keys 1 through 1000. Actual values were the values of the second level dictionary. Using numbers to fill the array to minimize the effect of creating my more complex objects, and running Python 3.1.1 on an 8-core Mac Pro with 8Gb memory, I tried the following #create and fill the array: t1 = time.time() d2 = {} for j in range(1000): d2[j] = dict() for k in range(1000): d2[j][k] = k print( round(time.time() - t1, 2)) 0.41 # access each element of the array: t1 = time.time() for j in range(1000): for k in range(1000): elt = d2[j][k] print( round(time.time() - t1, 2)) 0.55 My program was too slow, so I started investigating whether I could improve on the two-level dictionary, which got used a lot. To get another baseline I tried a pure 1,000,000-element list, expecting the times to be be horrendous, but look! # fill a list using append t1 = time.time() lst = [] for n in range(1000000): lst.append(n) print( round(time.time() - t1, 2)) 0.26 # access every element of a list t1 = time.time() for n in range(1000000): elt = lst[n] print( round(time.time() - t1, 2)) 0.25 What a shock! I could save half the execution time and all my clever work and awkward double-layer dictionary expressions by just using a list! Even better, look what happens using a comprehension to create the list instead of a loop with list.append: t1 = time.time() lst = [n for n in range(1000000)] print( round(time.time() - t1, 2)) 0.11 Half again to create the list. Iterating over the whole list is easier and faster than iterating over the double-level dictionary, in particular because it doesn't involve a two-level loop. But what about individual access given a row and a column? t1 = time.time() for j in range(1000): for k in range(1000): elt = lst[j * 1000 + k] print( round(time.time() - t1, 2)) 0.45 This is the same as for the dictionary. I tried a two-level list and a few other things but still haven't found anything that works better than a single long list -- just like 2-D arrays are coded in old-style languages, with indices computed as offsets from the beginning of the linear sequence of all the values. What's amazing is that creating and accessing 1,000,000-element list in Python is so efficient. The usual moral obtains: start simple, analyze problems (functional or performance) as they arise, decide whether they are worth the cost of change, then change in very limited ways. And of course abstract and modularize so that, in my case, for example, none of the program's code would be affected by the change from a two-level dictionary representation to using a single long list. I realize there are many directions an analysis like this can follow, and many factors affecting it, including patterns of use. I just wanted to demonstrate the basics for a situation that I just encountered. In particular, if the array was sparse, rather than completely full, the two-level dictionary implementation would be the natural representation. From pavlovevidence at gmail.com Tue Feb 2 15:26:16 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 12:26:16 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: On Feb 2, 11:07?am, Jean-Michel Pichavant wrote: > Carl Banks wrote: > > On Feb 2, 2:49 am, Jean-Michel Pichavant > > wrote: > > >> Carl Banks wrote: > > >>> Name your modules "send_email.py" or "sort_email.py" or if it's a > >>> library module of related functions, "email_handling.py". ?Modules and > >>> scripts do things (usually), they should be given action words as > >>> names. > > >>> (**) Questionable though it be, if the Standard Library wants to use > >>> an "innocuous" name, It can. > > >> That does not solve anything, > > > Of course it does, it solves the problem of having poorly-named > > modules. ?It also helps reduce possibility of name clashes. > > Actually don't you think it will increase the possibility ? There are > much less possibilties of properly naming an object than badly naming it. You've got to be kidding me, you're saying that a bad name like email.py is less likely to clash than a more descriptive name like send_email.py? > So if everybody tend to properly name their object with their obvious > version like you proposed, the set of possible names will decrease, > increasing the clash ratio. I did not propose obvious module names. I said obvious names like email.py are bad; more descriptive names like send_email.py are better. Carl Banks From gerald.britton at gmail.com Tue Feb 2 15:36:45 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 2 Feb 2010 15:36:45 -0500 Subject: lists as an efficient implementation of large two-dimensional arrays(!) In-Reply-To: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> References: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> Message-ID: <5d1a32001002021236s5f2e5eb2o5535258567921039@mail.gmail.com> Did you try it with an array object using the array module? On Tue, Feb 2, 2010 at 3:14 PM, Mitchell L Model wrote: > An instructive lesson in YAGNI ("you aren't going to need it"), premature > optimization, and not making assumptions about Python data structure > implementations. > > I need a 1000 x 1000 two-dimensional array of objects. (Since they are > instances of application classes it appears that the array module is > useless; likewise, since I am using Python 3.1, so among other things, I > can't use numpy or its relatives.) The usage pattern is that the array is > first completely filled with objects. Later, objects are sometimes accessed > individually by row and column and often the entire array is iterated over. > > Worried (unnecessarily, as it turns out) by the prospect of 1,000,000 > element list I started by constructing a dictionary with the keys 1 through > 1000, each of which had as its value another dictionary with the keys 1 > through 1000. Actual values were the values of the second level dictionary. > > Using numbers to fill the array to minimize the effect of creating my more > complex objects, and running Python 3.1.1 on an 8-core Mac Pro with 8Gb > memory, I tried the following > > #create and fill the array: > t1 = time.time() > d2 = {} > for j in range(1000): > ? ?d2[j] = dict() > ? ?for k in range(1000): > ? ? ? ?d2[j][k] = k > print( round(time.time() - t1, 2)) > > 0.41 > > # access each element of the array: > t1 = time.time() > for j in range(1000): > ? ?for k in range(1000): > ? ? ? ?elt = d2[j][k] > print( round(time.time() - t1, 2)) > > 0.55 > > ?My program was too slow, so I started investigating whether I could improve > on the two-level dictionary, which got used a lot. To get another baseline I > tried a pure 1,000,000-element list, expecting the times to be be > horrendous, but look! > > # fill a list using append > t1 = time.time() > lst = [] > for n in range(1000000): > ? ?lst.append(n) > print( round(time.time() - t1, 2)) > > 0.26 > > # access every element of a list > t1 = time.time() > for n in range(1000000): > ? ?elt = lst[n] > print( round(time.time() - t1, 2)) > > 0.25 > > What a shock! I could save half the execution time and all my clever work > and awkward double-layer dictionary expressions by just using a list! > > Even better, look what happens using a comprehension to create the list > instead of a loop with list.append: > > t1 = time.time() > lst = [n for n in range(1000000)] > print( round(time.time() - t1, 2)) > > 0.11 > > Half again to create the list. > > Iterating over the whole list is easier and faster than iterating over the > double-level dictionary, in particular because it doesn't involve a > two-level loop. But what about individual access given a row and a column? > > t1 = time.time() > for j in range(1000): > ? ?for k in range(1000): > ? ? ? ?elt = lst[j * 1000 + k] > print( round(time.time() - t1, 2)) > > 0.45 > > This is the same as for the dictionary. > > I tried a two-level list and a few other things but still haven't found > anything that works better than a single long list -- just like 2-D arrays > are coded in old-style languages, with indices computed as offsets from the > beginning of the linear sequence of all the values. What's amazing is that > creating and accessing 1,000,000-element list in Python is so efficient. The > usual moral obtains: start simple, analyze problems (functional or > performance) as they arise, decide whether they are worth the cost of > change, then change in very limited ways. And of course abstract and > modularize so that, in my case, for example, none of the program's code > would be affected by the change from a two-level dictionary representation > to using a single long list. > > I realize there are many directions an analysis like this can follow, and > many factors affecting it, including patterns of use. I just wanted to > demonstrate the basics for a situation that I just encountered. In > particular, if the array was sparse, rather than completely full, the > two-level dictionary implementation would be the natural representation. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From xahlee at gmail.com Tue Feb 2 15:40:13 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Feb 2010 12:40:13 -0800 (PST) Subject: python admin abuse complaint Message-ID: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> This is a short complaint on admin abuse on #python irc channel on freenode.net. Here's a log: 2010-02-02 (12:11:57 PM) The topic for #python is: NO LOL | http://pound-python.org/ | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: http://paste.pocoo.org/ | Tutorial: http://docs.python.org/tut/ | FAQ: http://effbot.org/pyfaq/ | New Programmer? Read http://tinyurl.com/thinkcspy | #python.web #wsgi #python-fr #python.de #python-es #python.tw #python.pl #python-br #python-jp #python-nl #python-ir #python- offtopic (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, actually. (12:12:01 PM) jarray52: Jarray (12:12:11 PM) _habnabit: jarray52, yes, you are. (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops etc) right is quite tricky (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just wondering whats up with the python verison :D (12:12:24 PM) mode (+o dash) by ChanServ (12:12:30 PM) You have been kicked by dash: (No.) --------------- I have not been using irc for the past about 2 year. (possibly perhaps 2 times in i think #web channel) In particular, i have not been in in freenode.net's #python channel. I don't know who is dash. Xah ? http://xahlee.org/ ? From alan at baselinedata.co.uk Tue Feb 2 15:50:28 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Tue, 02 Feb 2010 20:50:28 +0000 Subject: Threading issue with SQLite In-Reply-To: <09ca16b8-4e10-40f5-a69d-29fcdf6c2593@b9g2000pri.googlegroups.com> References: <09ca16b8-4e10-40f5-a69d-29fcdf6c2593@b9g2000pri.googlegroups.com> Message-ID: <4B689014.9090801@baselinedata.co.uk> Many thanks to all who replied to my questions re. SQLite connections, cursors and threading. Looks like I have got some reading to do regarding connection pooling and a decent SQLite ORM package. Does anyone know of any which are Python 3 compatible? Many thanks, Alanj From alfps at start.no Tue Feb 2 15:54:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Feb 2010 21:54:25 +0100 Subject: Your impression of for-novice writings on assertions Message-ID: I've started on ch 3 of my beginner's intro to programming, now delving into the details of the Python language. It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at which is at Google Docs. The first topic is about assertions and exceptions. I wonder whether this text is easy or difficult to understand for a beginner. Or any improvements that could be made. Cheers, - Alf From exarkun at twistedmatrix.com Tue Feb 2 15:57:11 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Tue, 02 Feb 2010 20:57:11 -0000 Subject: lists as an efficient implementation of large two-dimensional arrays(!) In-Reply-To: <5d1a32001002021236s5f2e5eb2o5535258567921039@mail.gmail.com> References: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> <5d1a32001002021236s5f2e5eb2o5535258567921039@mail.gmail.com> Message-ID: <20100202205711.26099.185894442.divmod.xquotient.82@localhost.localdomain> On 08:36 pm, gerald.britton at gmail.com wrote: >On Tue, Feb 2, 2010 at 3:14 PM, Mitchell L Model >wrote: >>I need a 1000 x 1000 two-dimensional array of objects. (Since they are >>instances of application classes it appears that the array module is >>useless; >Did you try it with an array object using the array module? Jean-Paul From astan.chee at al.com.au Tue Feb 2 16:07:50 2010 From: astan.chee at al.com.au (Astan Chee) Date: Wed, 3 Feb 2010 08:07:50 +1100 Subject: converting XML to hash/dict/CustomTreeCtrl In-Reply-To: <4B6756FE.9060206@al.com.au> References: <4B6756FE.9060206@al.com.au> Message-ID: <4B689426.1070400@al.com.au> Hi, Sorry for being vague but here my question about converting an xml into a dict. I found some examples online but none gives the dict/result I want. The xml looks like this: This is the note on calculation times 609.081574 2531.972081 65.119100 1772.011230 72.418861 28.285192 0.000 607.432373 4833280000 4833280000 4182777856 4182777856 1 1943498 0 1640100156 411307840 709596712 1406752 737720720 0 607.432373 5164184694 2054715622 using this script (taken from http://code.activestate.com/recipes/410469/): from xml.etree import cElementTree as ElementTree class XmlListConfig(list): def __init__(self, aList): for element in aList: if element: # treat like dict if len(element) == 1 or element[0].tag != element[1].tag: self.append(XmlDictConfig(element)) # treat like list elif element[0].tag == element[1].tag: self.append(XmlListConfig(element)) elif element.text: text = element.text.strip() if text: self.append(text) class XmlDictConfig(dict): ''' Example usage: >>> tree = ElementTree.parse('your_file.xml') >>> root = tree.getroot() >>> xmldict = XmlDictConfig(root) Or, if you want to use an XML string: >>> root = ElementTree.XML(xml_string) >>> xmldict = XmlDictConfig(root) And then use xmldict for what it is... a dict. ''' def __init__(self, parent_element): if parent_element.items(): self.update(dict(parent_element.items())) for element in parent_element: if element: # treat like dict - we assume that if the first two tags # in a series are different, then they are all different. if len(element) == 1 or element[0].tag != element[1].tag: aDict = XmlDictConfig(element) # treat like list - we assume that if the first two tags # in a series are the same, then the rest are the same. else: # here, we put the list in dictionary; the key is the # tag name the list elements all share in common, and # the value is the list itself aDict = {element[0].tag: XmlListConfig(element)} # if the tag has attributes, add those to the dict if element.items(): aDict.update(dict(element.items())) self.update({element.tag: aDict}) # this assumes that if you've got an attribute in a tag, # you won't be having any text. This may or may not be a # good idea -- time will tell. It works for the way we are # currently doing XML configuration files... elif element.items(): self.update({element.tag: dict(element.items())}) # finally, if there are no child tags and no attributes, extract # the text else: self.update({element.tag: element.text}) tree = ElementTree.parse('test.xml') root = tree.getroot() xmldict = XmlDictConfig(root) print xmldict Which I get this dict: {'stats': {'kind': 'position', 'stats': [{'kind': 'section', 'stats': {'kind': 'timers', 'name': 'timers', 'timer': [{'system': '65.119100', 'user': '2531.972081', 'elapsed': '609.081574', 'name': 'totaltime', 'description': 'Total time'}, {'elapsed': '1772.011230', 'name': 'partialTimer', 'description': 'Gravitational Displacement'}, [{'elapsed': '72.418861', 'name': 'subATimer', 'description': 'Phase time A'}, {'elapsed': '28.285192', 'name': 'subBTimer', 'description': 'Phase time B'}, {'elapsed': '0.000', 'name': 'spaceMem', 'description': 'Space memory'}], {'elapsed': '607.432373', 'name': 'endTime', 'description': 'End'}]}, 'name': 'time', 'string': {'name': 'timersNote', 'description': 'Note:'}, 'description': 'Timing summary'}, [[{'current': '4833280000', 'peak': '4833280000', 'name': 'heapSpace', 'description': 'Total Space'}, {'current': '4182777856', 'peak': '4182777856', 'name': 'spaceResidentSize', 'description': 'Space resident size'}, '1', '1943498', '0'], [{'current': '411307840', 'peak': '1640100156', 'name': 'geoSpace', 'description': 'Geo-Space'}, {'current': '1406752', 'peak': '709596712', 'name': 'gridSpace', 'description': 'Grid-Space'}, {'current': '0', 'peak': '737720720', 'name': 'spaceMem', 'description': 'Space memory'}, {'peak': '607.432373', 'name': 'endTime', 'description': 'End'}], {'current': '2054715622', 'peak': '5164184694', 'name': 'subsystemSpace', 'description': 'Subsystem space total'}]], 'name': 'position1', 'description': 'Calculation statistics'}} Which is kinda wrong. I expect the dict to have the "Space usage summary", but it doesn't (duplicate?). What am I doing wrong here? I am attempting to keep the attribute value of an XML as key (if it doesn't have a value, then just the tag name will do) and associate it with the text value of that tag/attribute value as well as reflecting the hierarchy structure of the XML in the dict. Does this make sense? Anyway, the python script above is just the first step or an example for me. Cheers and thanks again Astan From python at rcn.com Tue Feb 2 16:22:55 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 2 Feb 2010 13:22:55 -0800 (PST) Subject: Your impression of for-novice writings on assertions References: Message-ID: <1fe7535b-34dc-46ba-9807-bd1e8cf69a9c@x1g2000prb.googlegroups.com> On Feb 2, 12:54?pm, "Alf P. Steinbach" wrote: > The first topic is about assertions and exceptions. I wonder whether this text > is easy or difficult to understand for a beginner. Or any improvements that > could be made. To my eyes it reads nicely. You may want to try it out on a real beginner to get their feedback. I like your section on assertions. You could add examples of other ways assertions can be used (loop invariants, sanity checks, post- condition contract checks). For example, validate a loop invariant during a selection sort. In the hypot() example, use an assertion for sanity checking by verifying an expected mathematical relationship such as the triangle inequality: assert abs(c) <= abs(a) + abs(b). The pythagorean triple example can use assertions to check post conditions: assert all(isinstance(x, int) for x in (a,b,c)) and a*a +b*b==c*c. Raymond From andrewt.herd at gmail.com Tue Feb 2 16:25:07 2010 From: andrewt.herd at gmail.com (Andrew) Date: Tue, 2 Feb 2010 13:25:07 -0800 (PST) Subject: PyQt4 designer custom properties - combo box style Message-ID: I am creating custom widgets for the PyQt4 Designer. I can create custom properties, but I'm looking for how to create a custom property that has a combo box drop down. I've seen them in the example widgets and tried following them, but they are using pre-defined items to populate their property, so it's not a very clear example of how to get the combo box property to work. Is there any other examples or help for this kind of setup? Thanks, Andrew From aahz at pythoncraft.com Tue Feb 2 16:29:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2010 13:29:39 -0800 Subject: PyPI source dependencies? Message-ID: I'm trying to build PyObjC from source (because the binary doesn't work on OSX 10.5) and I can't figure out how to get all the dependencies downloaded automatically. Am I missing something? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From jgardner at jonathangardner.net Tue Feb 2 16:35:50 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:35:50 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: On Feb 2, 12:40?pm, Xah Lee wrote: > > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > I think you mean hash.clear() instead of hash.clean() The answer is that "hash = {}" will create a new dict and assign it to "hash", while "hash.clear()" simply guts the dict that "hash" is pointing to. In the end, both will result in "has" pointing to an empty dict. However, if you had something else pointing to what "hash" was pointing to, they will no longer be pointing to the same, empty hash after "hash = {}" is run. >>> a = b = {1:2} >>> a {1: 2} >>> b {1: 2} >>> a.clear() >>> a {} >>> b {} >>> a = b = {1:2} >>> a = {} >>> a {} >>> b {1: 2} From rschroev_nospam_ml at fastmail.fm Tue Feb 2 16:38:43 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 02 Feb 2010 22:38:43 +0100 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: Op 2010-02-02 18:02, Nobody schreef: > On Tue, 02 Feb 2010 15:00:28 +0000, Grant Edwards wrote: > >>>> It turns out that buggy.py imports psycopg2, as you can see, and >>>> apparently psycopg2 (or something imported by psycopg2) tries to >>>> import some standard Python module called numbers; instead it ends >>>> up importing the innocent myscript/numbers.py, resulting in *absolute >>>> mayhem*. >>> >>> I feel your pain, but this is not a Python problem, per-se. >> >> I think it is. > > I agree. > >> There should be different syntax to import from >> "standard" places and from "current directory". Similar to the >> difference between "foo.h" and in cpp. > > I don't know if that's necessary. Only supporting the "foo.h" case would > work fine if Python behaved like gcc, i.e. if the "current directory" > referred to the directory contain the file performing the import rather > than in the process' CWD. That is what I would have expected, it is the way I would have implemented it, and I don't understand why anyone would think differently. Yet not everyone seems to agree. Apparently, contrary to my expectations, Python looks in the directory containing the currently running script instead. That means that the behavior of "import foo" depends very much on circumstances not under control of the module in which that statement appears. Very fragile. Suggestions to use better names or just poor workarounds, IMO. Of the same nature are suggestions to limit the amount of scrips/modules in a directory... my /usr/bin contains no less than 2685 binaries, with 0 problems of name clashes; there is IMO no reason why Python should restrict itself to any less. Generally I like the design decisions used in Python, or at least I understand the reasons; in this case though, I don't see the advantages of the current approach. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From jgardner at jonathangardner.net Tue Feb 2 16:39:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:39:19 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <7a1ddcc5-0e2d-4c97-967d-6f6bbf0a7066@t17g2000prg.googlegroups.com> On Feb 1, 6:34?pm, kj wrote: > > An innocuous little script, let's call it buggy.py, only 10 lines > long, and whose output should have been, at most two lines, was > quickly dumping tens of megabytes of non-printable characters to > my screen (aka gobbledygook), and in the process was messing up my > terminal *royally*. > In linux terminals, try running the command "reset" to clear up any gobbledy-gook. It also works if you happen to hit CTRL-C while entering a password, in the rare case that it fails to set the text back to visible mode. From jgardner at jonathangardner.net Tue Feb 2 16:49:39 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:49:39 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: On Feb 2, 2:21?am, waku wrote: > > for writing new code, it's not necessarily that helpful to be *forced* > to keep with strict indenting rules. ?in early development phases, > code is often experimental, and parts of it may need to be blocked or > unblocked as the codebase grows, and for experimentation, the need to > carefully and consistently indent and de-indent large chunks of code > can easily lead to a mess (blame it on the programmer, not the > language, but still). ?yes, there are editors that help you indent > chunks of code, but see below. > > there are languages where indentation can be either enforced and allow > one to omit some syntactic nuissance like braces or begin-end clauses, > or made optional, requiring other syntactic means for delimiting > blocks etc. ?(consider f# with its #light declaration, for example.) > If you're writing "experimental code", you're doing it wrong. Every line of code you write may end up on the space shuttle one day (so to speak!) Why not write the code well-formatted in the first place, so that any bugs you introduce are as easily visible as possible? The only reason why you may want to write crap code without proper formatting is because your text editor is stupid. If that's the case, get rid of your text editor and find some tools that help you do the right thing the first time. > > as long as you are limited to your own code, sure. ?but if many work > on the same bit, and use different editors and indentation policies, > blanks-tabs indentation issues are not unlikely. ?you can have blanks > converted to tabs and vice versa automatically, but that's clearly a > nuisance. > If you're text editor has a problem with indenting, you have a terrible text editor. Period, end of sentence. You can't screw in bolts with a hammer, and you can't level with a saw. Don't try to write code in any language without a real text editor that can do proper indentation. Don't let your teammates use deficient text editors either. I wouldn't appreciate it if I delivered precision components that my teammates tried to install with sledgehammers. This is the 21st Century. Good text editors are not hard to find on any platform. From jgardner at jonathangardner.net Tue Feb 2 16:55:09 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:55:09 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> Message-ID: <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> On Feb 1, 6:21?pm, Nobody wrote: > > You don't need to know the entire language before you can use any of it > (if you did, Python would be deader than a certain parrot; Python's dark > corners are *really* dark). > I'm curious. What dark corners are you referring to? I can't think of any. Especially with the direction Python 3 is going, it seems like even the slightly dim corners are being rounded away. I can explain, in an hour, every single feature of the Python language to an experienced programmer, all the way up to metaclasses, __getattribute__, __new__ and __get__. These are the darkest corners I know of, and these are not at all dark. It takes a few paragraphs of documentation to explain all the details of each these features. I hold the entire Python language in my head, and I can still remember when my next meeting is. Compare that to something like Haskell, where you have to read entire books before you truly understand what monads are actually doing behind the scenes, and how Haskell actually interprets and runs your program, or to understand what the esoteric error messages that crop up are actually caused be. Yes, there are people that know how to do stuff in Haskell. These are really smart people, the cream of the crop, so to speak. But that doesn't make Haskell a simple language. From jgardner at jonathangardner.net Tue Feb 2 17:01:01 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 14:01:01 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> Message-ID: <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> On Feb 1, 6:36?pm, John Bokma wrote: > Jonathan Gardner writes: > > One of the bad things with languages like perl > > FYI: the language is called Perl, the program that executes a Perl > program is called perl. > > > without parentheses is that getting a function ref is not obvious. You > > need even more syntax to do so. In perl: > > > ?foo(); ? ? ? # Call 'foo' with no args. > > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > > ? ? ? ? ? ? ? # By the way, this '&' is not the bitwise-and '&'!!!! > > It should be $bar = \&foo > Your example actually calls foo... > I rest my case. I've been programming perl professionally since 2000, and I still make stupid, newbie mistakes like that. > > One is simple, consistent, and easy to explain. The other one requires > > the introduction of advanced syntax and an entirely new syntax to make > > function calls with references. > > The syntax follows that of referencing and dereferencing: > > $bar = \@array; ? ? ? # bar contains now a reference to array > $bar->[ 0 ]; ? ? ? ? ?# first element of array referenced by bar > $bar = \%hash; ? ? ? ?# bar contains now a reference to a hash > $bar->{ key }; ? ? ? ?# value associated with key of hash ref. by bar > $bar = \&foo; ? ? ? ? # bar contains now a reference to a sub > $bar->( 45 ); ? ? ? ? # call sub ref. by bar with 45 as an argument > > Consistent: yes. New syntax? No. > Except for the following symbols and combinations, which are entirely new and different from the $@% that you have to know just to use arrays and hashes. \@, ->[ ] \%, ->{ } \&, ->( ) By the way: * How do you do a hashslice on a hashref? * How do you invoke reference to a hash that contains a reference to an array that contains a reference to a function? Compare with Python's syntax. # The only way to assign a = b # The only way to call a function b(...) # The only way to access a hash or array or string or tuple b[...] > Also, it helps to think of > > $ as a thing > @ as thingies indexed by numbers > % as thingies indexed by keys > I'd rather think of the task at hand than what each of the funky symbols on my keyboard mean. From jgardner at jonathangardner.net Tue Feb 2 17:06:47 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 14:06:47 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: <2a5ee10d-4da3-4275-936d-3d792f3450e3@p13g2000pre.googlegroups.com> On Feb 2, 7:23?am, "bartc" wrote: > Jonathan Gardner wrote: > > One of the bad things with languages like perl and Ruby that call > > without parentheses is that getting a function ref is not obvious. You > > need even more syntax to do so. In perl: > > > ?foo(); ? ? ? # Call 'foo' with no args. > > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > > ? ? ? ? ? ? ? # By the way, this '&' is not the bitwise-and '&'!!!! > > ?$bar->() ? ? # Call whatever '$bar' is pointing at with no args > > > Compare with python: > > > ?foo() ? ? ? # Call 'foo' with no args. > > ?bar = foo() # 'bar' is now pointing to whatever 'foo()' returned > > ?bar = foo ? # 'bar' is now pointing to the same thing 'foo' points to > > ?bar() ? ? ? # Call 'bar' with no args > > > One is simple, consistent, and easy to explain. The other one requires > > the introduction of advanced syntax and an entirely new syntax to make > > function calls with references. > > If you get rid of the syntax specific to Perl, then having to explicitly > obtain a function reference, or to dereference the result, is not such a big > deal: > > ?foo ? ? ? ? ?# Call 'foo' with no args. > ?bar = foo ? ?# Call 'foo; with no args, assign to 'bar' > ?bar = &foo ? # Don't call 'foo', but assign a pointer to it to 'bar' > ?bar^ ? ? ? ? # Call whatever 'bar' is pointing at with no args > > (Here I use ^ instead of -> to dereference.) ?Compared with Python, it saves > 3 lots of (), but needs & and ^ added. Still a net saving. > On one shoulder, a demon taunts the programmer: "Ohmygosh, you can save three keystrokes if you introduce an entirely new syntax with odd squiggles that make no pronounceable sound in the English language! Perhaps one day, you can program APL in Python!" The angel that sits on the other shoulder says, "Alas, poor programmer, one day, you'll have to read that and understand it. And heaven help us when we hire a poor college graduate to maintain the code we wrote five years ago. Or worse, when that poor college graduate writes code and expects us to read it!" Thankfully, Guido has banished that demon from the realm of Python a long time ago. > > One of the bad things with languages like perl and Ruby that call > > without parentheses is that getting a function ref is not obvious. > > I'd say that having this "&" symbol in front of "foo" makes it more obvious > than just foo by itself. But I agree not quite as clean. > > Another thing is that you have to know whether "bar" is a function, or a > function ref, and use the appropriate syntax. Sometimes this is helpful, > sometimes not. > Thankfully, in Python, everything is a ref, so everything is consistent. From jgardner at jonathangardner.net Tue Feb 2 17:09:38 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 14:09:38 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <88cc29b2-cc2e-4e02-91dc-073be8216f61@m35g2000prh.googlegroups.com> On Feb 1, 6:50?pm, Nobody wrote: > On Mon, 01 Feb 2010 14:13:38 -0800, Jonathan Gardner wrote: > > I judge a language's simplicity by how long it takes to explain the > > complete language. That is, what minimal set of documentation do you > > need to describe all of the language? > > That's not a particularly good metric, IMHO. > > A simple "core" language doesn't necessarily make a language simple to > use. You can explain the entirety of pure lambda calculus or combinators > in five minutes, but you wouldn't want to write real code in either (and > you certainly wouldn't want to read such code which was written by someone > else). > > For a start, languages with a particularly simple "core" tend to delegate > too much to the library. One thing which puts a lot of people off of > lisp is the lack of infix operators; after all, (* 2 (+ 3 4)) works fine > and doesn't require any additional language syntax. For an alternative, > Tcl provides the "expr" function which essentially provides a sub-language > for arithmetic expressions. > > A better metric is whether using N features has O(N) complexity, or O(N^2) > (where you have to understand how each feature relates to each other > feature) or even O(2^N) (where you have to understand every possible > combination of interactions). > > > With a handful of statements, > > and a very short list of operators, Python beats out every language in > > the Algol family that I know of. > > Not once you move beyond the 10-minute introduction, and have to start > thinking in terms of x + y is x.__add__(y) or maybe y.__radd__(x) and also > that x.__add__(y) is x.__getattribute__('__add__')(y) (but x + y *isn't* > equivalent to the latter due to __slots__), and maybe .__coerce__() gets > involved somewhere, and don't even get me started on __metaclass__ or > __init__ versus __new__ or ... > > Yes, the original concept was very nice and clean, but everything since > then has been wedged in there by sheer force with a bloody great hammer. I strongly suggest you read the documentation on these bits of Python. If you're scared of __new__ versus __init__, then you haven't been programming very long in any language. There is a case when you need one over the other. The same goes for the other concepts. Programming languages that don't provide these features (like Javascript) are nice for toy programs, but lack the power to accommodate the needs of large apps. From ben+python at benfinney.id.au Tue Feb 2 17:21:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Feb 2010 09:21:13 +1100 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> Message-ID: <87mxzrp9d2.fsf@benfinney.id.au> Jonathan Gardner writes: > Compare with Python's syntax. > > # The only way to assign > a = b > > # The only way to call a function > b(...) > > # The only way to access a hash or array or string or tuple > b[...] For all of your examples, there are other ways supported. I do wish this focus on ?only way? would depart, it's a fallacy and not helpful. What is important (and supports the main point of your message) is that for each of the above, whether or not they are the only way, they are the one *obvious* way to do the operation. -- \ ?The cost of education is trivial compared to the cost of | `\ ignorance.? ?Thomas Jefferson | _o__) | Ben Finney From chairman at python.org Tue Feb 2 17:23:43 2010 From: chairman at python.org (Steve Holden, Chairman, PSF) Date: Tue, 02 Feb 2010 17:23:43 -0500 Subject: python admin abuse complaint In-Reply-To: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B68A5EF.7040100@python.org> Xah Lee wrote: > This is a short complaint on admin abuse on #python irc channel on > freenode.net. > > Here's a log: > > 2010-02-02 > > (12:11:57 PM) The topic for #python is: NO LOL | http://pound-python.org/ > | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: > http://paste.pocoo.org/ | Tutorial: http://docs.python.org/tut/ | FAQ: > http://effbot.org/pyfaq/ | New Programmer? Read http://tinyurl.com/thinkcspy > | #python.web #wsgi #python-fr #python.de #python-es #python.tw > #python.pl #python-br #python-jp #python-nl #python-ir #python- > offtopic > (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, > actually. > (12:12:01 PM) jarray52: Jarray > (12:12:11 PM) _habnabit: jarray52, yes, you are. > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops > etc) right is quite tricky > (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just > wondering whats up with the python verison :D > (12:12:24 PM) mode (+o dash) by ChanServ > (12:12:30 PM) You have been kicked by dash: (No.) > > --------------- > > I have not been using irc for the past about 2 year. (possibly perhaps > 2 times in i think #web channel) In particular, i have not been in in > freenode.net's #python channel. I don't know who is dash. > > Xah > ? http://xahlee.org/ > > ? Frankly, Xah Lee, I find it ironic that you see fit to complain about abuse of the IRC channel when you have apparently felt free to ignore the many complaints about your behavior on this and other newsgroups over many years. "As ye sew, so shall ye reap". I imagine that your reputation has preceded you, and that dash (whom I *do* know) is simply looking to keep a well-known nuisance from bothering the rest of the users on the channel. For the present my sympathies are all with him. The PSF will, however, investigate this issue and I will report back to you off-list in due course. regards Steve -- Steve Holden Chairman, Python Software Foundation The Python Community Conference http://python.org/psf/ PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/ Watch PyCon on video now! http://pycon.blip.tv/ From hnine at isis.vanderbilt.edu Tue Feb 2 17:38:00 2010 From: hnine at isis.vanderbilt.edu (Harmon Nine) Date: Tue, 2 Feb 2010 16:38:00 -0600 Subject: Calling a "raw" python function from C++ Message-ID: <7AB1C26C64423249964AB392C6EBF0E0049D4394@discovery.isis.vanderbilt.edu> Hello. I've been crawling the web for an answer to this one, but have come up empty. We can currently only use Boost 1.36 for our project, i.e. we are having problems using later versions of Boost. We are using Boost.Python to interface with Cheetah. Problem: In Boost 1.36, how do you call a "raw" method of a python class from C++? In particular, what C++ code is needed to call a "raw constructor", i.e. a constructor that can take an arbitrary number of positional and keyword arguments by using *args, **kwargs? For instance, this is defined in a ".py" file. class Gain: def __init__( self, *args, **kwargs ): ... In C++ we have (where "gainClass" is the Gain class above referenced from C++): ----- namespace bp = boost::python; bp::object gainObject = gainClass( /* what goes here to call the above Gain constructor? */ ); ----- Passing a tuple and a dict doesn't work. I wish we could use the most recent version of Boost, since in this you can just do this: ----- bp::object gainObject = gainClass( *bp::tuple(), **bp::dict() ); ----- But this is not available in Boost 1.36 TIA -- Harmon -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Feb 2 17:43:07 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 2 Feb 2010 14:43:07 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7a9c25c21002021443i50111efaia261872130364082@mail.gmail.com> On Tue, Feb 2, 2010 at 1:38 PM, Roel Schroeven < rschroev_nospam_ml at fastmail.fm> wrote: > Apparently, contrary to my expectations, Python looks in the directory > containing the currently running script instead. That means that the > behavior of "import foo" depends very much on circumstances not under > control of the module in which that statement appears. Very fragile. > Suggestions to use better names or just poor workarounds, IMO. Of the > same nature are suggestions to limit the amount of scrips/modules in a > directory... my /usr/bin contains no less than 2685 binaries, with 0 > problems of name clashes; there is IMO no reason why Python should > restrict itself to any less. > > Generally I like the design decisions used in Python, or at least I > understand the reasons; in this case though, I don't see the advantages > of the current approach. This really isn't anything new, novel, or even interesting. Its been known forever that Python searches the script's directory for other scripts, there's reasons for this. Its also been known forever that its not really an ideal situation, and so over the last seven or so years, Python's been working on fixing it. http://www.python.org/dev/peps/pep-0328/ In 2.5, you could activate your modules to use absolute imports by default, thus requiring you to use special syntax to access modules in your own path. In 2.6, relative imports of modules in the same dir (thus, possible shadowing modules) raises a deprecation warning. In Python 3+, you have to use the explicit syntax to get at modules in the current directory. This has taken years to address, yeah, because touching the import machinery is -dangerous-; you have to do it very carefully to be sure that vast amounts of code doesn't break that's relying on the existing, not-entirely-well-documented-or-defined mechanics. Why was Python designed like this? Ask Guido. I don't know, but I'm not surprised: python was always very /flat/ originally. Strict, flat scopes, didn't even have packages, etc. Its slowly gotten a little more nested / deeper over time-- from limited nested scoping (only for enclosing functions), to now absolute imports being default. Its a slow process seeking a delicate balance; "flat is better then nested" vs "namespaces are one honking great idea" are somewhat contradictory, after all :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Feb 2 17:47:19 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Feb 2010 17:47:19 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: On 2/2/2010 2:43 PM, kj wrote: > In Terry Reedy writes: > >> On 2/2/2010 9:13 AM, kj wrote: > >>>> As for fixing it, unfortunately it's not quite so simple to fix without >>>> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >>>> was missed. >>> >>> This last point is to me the most befuddling of all. Does anyone >>> know why this opportunity was missed for 3.0? Anyone out there >>> with the inside scoop on this? Was the fixing of this problem >>> discussed in some PEP or some mailing list thread? (I've tried >>> Googling this but did not hit on the right keywords to bring up >>> the deliberations I'm looking for.) > >> There was a proposal to put the whole stdlib into a gigantic package, so >> that > >> import itertools > >> would become, for instance > >> import std.itertools. > >> Guido rejected that. I believe he both did not like it and was concerned >> about making upgrade to 3.x even harder. The discussion was probably on >> the now closed py3k list. > > > Thanks. I'll look for this thread. Stephen Hansen's post explains a bit more than I did. To supplement his explanation: since print *was* a keyword, every use of 'print' in 2.x denotes a print statement with standard semantics. Therefore 2to3 *knows* what the statement means and can translate it. On the other hand, 'import string' usually means 'import the string module of the stdlib', but it could mean 'import my string module'. This depends on the execution environment. Moreover, I believe people have intentionally shadowed stdlib modules. So. like it or not, 2to3 cannot know what 'import string' means. Terry Jan Reedy From tjreedy at udel.edu Tue Feb 2 17:54:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Feb 2010 17:54:51 -0500 Subject: lists as an efficient implementation of large two-dimensional arrays(!) In-Reply-To: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> References: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> Message-ID: On 2/2/2010 3:14 PM, Mitchell L Model wrote: > I need a 1000 x 1000 two-dimensional array of objects. I would just use 1000 element list, with each element being a 1000 element list or array (if possible). Then l2d[i][j] works fine. From nagle at animats.com Tue Feb 2 18:02:49 2010 From: nagle at animats.com (John Nagle) Date: Tue, 02 Feb 2010 15:02:49 -0800 Subject: Overcoming python performance penalty for multicore CPU Message-ID: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> I know there's a performance penalty for running Python on a multicore CPU, but how bad is it? I've read the key paper ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate if the GIL just limited Python to running on one CPU at a time, but it's worse than that; there's excessive overhead due to a lame locking implementation. Running CPU-bound multithreaded code on a dual-core CPU runs HALF AS FAST as on a single-core CPU, according to Beasley. My main server application, which runs "sitetruth.com" has both multiple processes and multiple threads in each process. The system rates web sites, which involves reading and parsing up to 20 pages from each domain. Analysis of each domain is performed in a separate process, but each process uses multiple threads to read process several web pages simultaneously. Some of the threads go compute-bound for a second or two at a time as they parse web pages. Sometimes two threads (but never more than three) in the same process may be parsing web pages at the same time, so they're contending for CPU time. So this is nearly the worst case for the lame GIL lock logic. Has anyone tried using "affinity" ("http://pypi.python.org/pypi/affinity") to lock each Python process to a single CPU? Does that help? John Nagle From steve at holdenweb.com Tue Feb 2 18:05:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 18:05:30 -0500 Subject: Python and Ruby In-Reply-To: <87mxzrp9d2.fsf@benfinney.id.au> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> <87mxzrp9d2.fsf@benfinney.id.au> Message-ID: <4B68AFBA.2070008@holdenweb.com> Ben Finney wrote: > Jonathan Gardner writes: > >> Compare with Python's syntax. >> >> # The only way to assign >> a = b >> >> # The only way to call a function >> b(...) >> >> # The only way to access a hash or array or string or tuple >> b[...] > > For all of your examples, there are other ways supported. I do wish this > focus on ?only way? would depart, it's a fallacy and not helpful. > And besides which most people get the quote wrong. The "authoritative" version from the Zen is, as you clearly already know There should be one-- and preferably only one --obvious way to do it. > What is important (and supports the main point of your message) is that > for each of the above, whether or not they are the only way, they are > the one *obvious* way to do the operation. > Quite. People might be interested to know the history of the Zen, which I got directly from Tim Peters over lunch one day. It was composed, apparently, during the commercial breaks one evening while he was watching professional wrestling on the television! So it's wise not to take the Zen too seriously. It wasn't written to guide, but to amuse. The fact that it can do both is a testament to Tim's sagacity. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From aahz at pythoncraft.com Tue Feb 2 18:07:05 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2010 15:07:05 -0800 Subject: Need help with a program References: <96db4cd6-bda3-42db-a592-83d72e517e2d@28g2000vbf.googlegroups.com> <4B61CE0E.5000801@sequans.com> Message-ID: In article , D'Arcy J.M. Cain wrote: > >If you have a problem and you think that regular expressions are the >solution then now you have two problems. Regex is really overkill for >the OP's problem and it certainly doesn't improve readability. If you're going to use a quote, it works better if you use the exact quote and attribute it: 'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.' --Jamie Zawinski -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From sjdevnull at yahoo.com Tue Feb 2 18:07:47 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Tue, 2 Feb 2010 15:07:47 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> Message-ID: <1ee94353-24aa-48a9-a7e2-474149ae0f7c@u41g2000yqe.googlegroups.com> On Feb 2, 5:01?pm, Jonathan Gardner wrote: > On Feb 1, 6:36?pm, John Bokma wrote: > > > > > > > Jonathan Gardner writes: > > > One of the bad things with languages like perl > > > FYI: the language is called Perl, the program that executes a Perl > > program is called perl. > > > > without parentheses is that getting a function ref is not obvious. You > > > need even more syntax to do so. In perl: > > > > ?foo(); ? ? ? # Call 'foo' with no args. > > > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > > > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > > > ? ? ? ? ? ? ? # By the way, this '&' is not the bitwise-and '&'!!!! > > > It should be $bar = \&foo > > Your example actually calls foo... > > I rest my case. I've been programming perl professionally since 2000, > and I still make stupid, newbie mistakes like that. > > > > One is simple, consistent, and easy to explain. The other one requires > > > the introduction of advanced syntax and an entirely new syntax to make > > > function calls with references. > > > The syntax follows that of referencing and dereferencing: > > > $bar = \@array; ? ? ? # bar contains now a reference to array > > $bar->[ 0 ]; ? ? ? ? ?# first element of array referenced by bar > > $bar = \%hash; ? ? ? ?# bar contains now a reference to a hash > > $bar->{ key }; ? ? ? ?# value associated with key of hash ref. by bar > > $bar = \&foo; ? ? ? ? # bar contains now a reference to a sub > > $bar->( 45 ); ? ? ? ? # call sub ref. by bar with 45 as an argument > > > Consistent: yes. New syntax? No. > > Except for the following symbols and combinations, which are entirely > new and different from the $@% that you have to know just to use > arrays and hashes. > > \@, ->[ ] > \%, ->{ } > \&, ->( ) > > By the way: > * How do you do a hashslice on a hashref? > * How do you invoke reference to a hash that contains a reference to > an array that contains a reference to a function? > > Compare with Python's syntax. > > # The only way to assign > a = b >>> locals().__setitem__('a', 'b') >>> print a b > # The only way to call a function > b(...) >>> def b(a): ... print a*2 >>> apply(b, (3,)) 6 > # The only way to access a hash or array or string or tuple > b[...] >>> b={} >>> b[1] = 'a' >>> print b.__getitem__(1) a From exarkun at twistedmatrix.com Tue Feb 2 18:24:59 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Tue, 02 Feb 2010 23:24:59 -0000 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <20100202232459.26099.2057701829.divmod.xquotient.97@localhost.localdomain> On 11:02 pm, nagle at animats.com wrote: > I know there's a performance penalty for running Python on a >multicore CPU, but how bad is it? I've read the key paper >("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate >if the GIL just limited Python to running on one CPU at a time, >but it's worse than that; there's excessive overhead due to >a lame locking implementation. Running CPU-bound multithreaded >code on a dual-core CPU runs HALF AS FAST as on a single-core >CPU, according to Beasley. It's not clear that Beasley's performance numbers apply to any platform except OS X, which has a particularly poor implementation of the threading primitives CPython uses to implement the GIL. You should check to see if it actually applies to your deployment environment. The GIL has been re-implemented recently. Python 3.2, I think, will include the new implementation, which should bring OS X performance up to the level of other platforms. It may also improve certain other aspects of thread switching. Jean-Paul From gagsl-py2 at yahoo.com.ar Tue Feb 2 18:30:17 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Feb 2010 20:30:17 -0300 Subject: Problems embedding python 2.6 in C++ References: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> <5089497e1002012126h55f0611ct476eabb0ccf1bea1@mail.gmail.com> Message-ID: En Tue, 02 Feb 2010 02:26:57 -0300, Paul escribi?: > I've managed to get it working and so far stable... Glad to see you finally made it work! > Current working version: > [...] > mycppclass::callpy(funcname, args...) > m_mypymodule = PyImport_Import(pModuleName) > > pyargs = PyTuple_SetItem * args > PyCallable_Check(func) > PyObject_CallObject(func,pyargs) > > Py_XDECREF(m_mypymodule) > > So now the module is being imported each function call (luckily I don't > have > to worry about performance) Remember that after the module is successfully imported by the first time, a subsequent import returns early, as soon as it finds the module in sys.modules[] -- the performance penalty shouldn't be so big. > I assume this means that the internal representation of the imported > module > is being corrupted by something. I found another person with a similar > issue > here: > http://mail.python.org/pipermail/python-dev/2004-March/043306.html - > that is > a long time ago but another multi-threaded app. > I'm happy to use the working method but I'd like to understand what is > going > on a bit more. Can anyone shed any further light? Sorry, I cannot help on this. Seems to happen only with an embedded interpreter and a multithreaded application, and I've never used Python in that scenario. If you could trim your code to a minimal example that shows the faulty behavior, that would be great, so others can test it too and eventually determine what's going on. -- Gabriel Genellina From irmen-NOSPAM- at xs4all.nl Tue Feb 2 19:36:38 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Wed, 03 Feb 2010 01:36:38 +0100 Subject: Your impression of for-novice writings on assertions In-Reply-To: References: Message-ID: <4b68c4c0$0$22920$e4fe514c@news.xs4all.nl> On 2-2-2010 21:54, Alf P. Steinbach wrote: > I've started on ch 3 of my beginner's intro to programming, now delving > into the details of the Python language. > Alf, I think it's a good read so far. I just don't like the smilies that occur in the text. It's a book (or article) that I'm reading, not an instant messaging conversation. Irmen From bartc at freeuk.com Tue Feb 2 20:01:29 2010 From: bartc at freeuk.com (bartc) Date: Wed, 03 Feb 2010 01:01:29 GMT Subject: Python and Ruby In-Reply-To: <2a5ee10d-4da3-4275-936d-3d792f3450e3@p13g2000pre.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <2a5ee10d-4da3-4275-936d-3d792f3450e3@p13g2000pre.googlegroups.com> Message-ID: Jonathan Gardner wrote: > On Feb 2, 7:23 am, "bartc" wrote: >> Jonathan Gardner wrote: >>> One of the bad things with languages like perl and Ruby that call >>> without parentheses is that getting a function ref is not obvious. >>> You need even more syntax to do so. In perl: >> >>> foo(); # Call 'foo' with no args. ... >> If you get rid of the syntax specific to Perl, then having to >> explicitly obtain a function reference, or to dereference the >> result, is not such a big deal: >> >> foo # Call 'foo' with no args. >> bar = foo # Call 'foo; with no args, assign to 'bar' >> bar = &foo # Don't call 'foo', but assign a pointer to it to 'bar' >> bar^ # Call whatever 'bar' is pointing at with no args >> >> (Here I use ^ instead of -> to dereference.) Compared with Python, >> it saves 3 lots of (), but needs & and ^ added. Still a net saving. >> > > On one shoulder, a demon taunts the programmer: "Ohmygosh, you can > save three keystrokes if you introduce an entirely new syntax with odd > squiggles that make no pronounceable sound in the English language! > Perhaps one day, you can program APL in Python!" ... > Thankfully, Guido has banished that demon from the realm of Python a > long time ago. You mean & (bitwise AND in Python) and ^ (bitwise XOR in Python)? :-) -- Bartc From steve at holdenweb.com Tue Feb 2 20:06:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 20:06:49 -0500 Subject: Your impression of for-novice writings on assertions In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > I've started on ch 3 of my beginner's intro to programming, now delving > into the details of the Python language. > > It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at > which is at Google Docs. > > The first topic is about assertions and exceptions. I wonder whether > this text is easy or difficult to understand for a beginner. Or any > improvements that could be made. > I don't think it's helpful in Python to refer to "... variables, which are named locations in memory, ..." because Python specifically eschews this model, and trying to explain assignment (especially of mutable objects) in those terms will lead to conceptual difficulties. Also, why introduce exceptions by talking about "error handling" when the term "exception handling" is hanging in the air? This is also a conceptual thing, since you want to get the reader used to the idea that it's a legitimate programming technique to use exceptions as part of their programs' normal control flow. I'd also recommend taking docstrings a little more seriously, since their use makes code much more self-documenting - someone can import your module and learn its API using the help() function. You may have done that in an earlier chapter. Just a few points for you to think about, and reject if you choose. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From peter.milliken at gmail.com Tue Feb 2 20:21:14 2010 From: peter.milliken at gmail.com (Peter) Date: Tue, 2 Feb 2010 17:21:14 -0800 (PST) Subject: Your impression of for-novice writings on assertions References: Message-ID: On Feb 3, 7:54?am, "Alf P. Steinbach" wrote: > I've started on ch 3 of my beginner's intro to programming, now delving into the > details of the Python language. > > It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at which is at Google Docs. > > The first topic is about assertions and exceptions. I wonder whether this text > is easy or difficult to understand for a beginner. Or any improvements that > could be made. > > Cheers, > > - Alf The only issue I have with what is there is the example - most programmers are not interested in solving mathematical equations and the code is enough to make the reader go cross-eyed. IMO the example code tends to detract from the point you are trying to make about using and how to use assertions. I would suggest a much simpler (to read) example than the one given. Ideally I would like to see more than one example with the examples graded from simple to more complex. A simple example could be just using the assert statement to verify pre-condition (assumptions) made on parameters to a function i.e. def divide (x, y): return x / y The programmer obviously assumed that y will never be 0 - so with one simple example you teach two points: 1. how an assert can be used 2. when programming look for unconscious assumptions Peter P.S. You also raise an interesting issue in my mind when quoting Knuth and siting TeX as an example application with no known bugs - Knuth advocated and used literate programming when writing TeX to achieve "clarity". I believe he (still?) cites the fact that TeX is so bug free because he used Literate Programming to write it (well, at least one reason). So should we be trying to teach literate programming to beginners? You did open that can of worms by quoting and siting Knuth and TeX... :-) From xahlee at gmail.com Tue Feb 2 20:28:10 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Feb 2010 17:28:10 -0800 (PST) Subject: Python's Reference And Internal Model Of Computing Languages Message-ID: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> just wrote this essay. Comment & feedback very welcome. Python's Reference And Internal Model Of Computing Languages Xah Lee, 2010-02-02 In Python, there are 2 ways to clear a hash: ?myHash = {}? and ?myHash.clear()?. What is the difference? ? The difference is that ?myHash={}? simply creates a new empty hash and assigns to myHash, while ?myHash.clear()? actually clear the hash the myHash is pointing to. What does that mean?? Here's a code that illustrates: # python # 2 ways to clear hash and their difference aa = {'a':3, 'b':4} bb = aa aa = {} print bb # prints {'a': 3, 'b': 4} aa = {'a':3, 'b':4} bb = aa aa.clear() print bb # prints {} This is like this because of the ?reference? concept. The opposite alternative, is that everything is a copy, for example in most functional langs. (with respect to programer-visible behavior, not how it is implemented) >From the aspect of the relation of the language source code to the program behavior by the source code, this ?reference?-induced behavior is similar to dynamic scope vs lexicol scope. The former being un- intuitive and hard to understand the latter more intuitive and clear. The former requires the lang to have a internal model of the language, the latter more correspond to source code WYSIWYG. The former being easy to implement and is in early langs, the latter being more popular today. As with many languages that have concept of references, or pointers, this is a complexity that hampers programing progress. The concept of using some sort of ?reference? as part of the language is due to implementation efficiency. Starting with C and others in 1960s up to 1990s. But as time went on, this concept in computer languages are gradually disappearing, as they should. Other langs that have this ?reference? concept as ESSENTIAL part of the semantic of the language, includes: C, C++, Java, Perl, Common Lisp. (of course, each using different terminologies, and each lang faction will gouge the other faction's eyes out about what is the true meaning of terms like ?reference?, ?object?, ?list/sequence/vector/ array/hash?, and absolutely pretend other meanings do not exist. (partly due to, their ignorance of langs other than their own, partly, due to male power struggle nature.)) Languages that do not have any ?reference? or ?object?, or otherwise does not require the programer to have some internal model of source code, are: Mathematica, JavaScript, PHP. (others may include TCL, possibly assembly langs.) For some detail on this, see: Jargons And High Level Languages and Hardware Modeled Computer Languages. --------------------------- (perm url of this essay can be found on my website.) Xah ? http://xahlee.org/ ? From steven at REMOVE.THIS.cybersource.com.au Tue Feb 2 20:42:18 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 01:42:18 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Tue, 02 Feb 2010 09:38:07 +0100, Daniel Fetchinson wrote: >> I like seeing them in the same place as the source file, because when I >> start developing a module, I often end up renaming it multiple times >> before it settles on a final name. When I rename or move it, I delete >> the .pyc file, and that ensures that if I miss changing an import, and >> try to import the old name, it will fail. >> >> By hiding the .pyc file elsewhere, it is easy to miss deleting one, and >> then the import won't fail, it will succeed, but use the old, obsolete >> byte code. > > > Okay, I see your point but I think your argument about importing shows > that python is doing something suboptimal because I have to worry about > .pyc files. Ideally, I only would need to worry about python source > files. That's no different from any language that is compiled: you have to worry about keeping the compiled code (byte code or machine language) in sync with the source code. Python does most of that for you: it automatically recompiles the source whenever the source code's last modified date stamp is newer than that of the byte code. So to a first approximation you can forget all about the .pyc files and just care about the source. But that's only a first approximation. You might care about the .pyc files if: (1) you want to distribute your application in a non-human readable format; (2) if you care about clutter in your file system; (3) if you suspect a bug in the compiler; (4) if you are working with byte-code hacks; (5) if the clock on your PC is wonky; (6) if you leave random .pyc files floating around earlier in the PYTHONPATH than your source files; etc. > There is now a chance to 'fix' (quotation marks because maybe > there is nothing to fix, according to some) this issue and make all pyc > files go away and having python magically doing the right thing. Famous last words... The only ways I can see to have Python magically do the right thing in all cases would be: (1) Forget about byte-code compiling, and just treat Python as a purely interpreted language. If you think Python is slow now... (2) Compile as we do now, but only keep the byte code in memory. This would avoid all worries about scattered .pyc files, but would slow Python down significantly *and* reduce functionality (e.g. losing the ability to distribute non-source files). Neither of these are seriously an option. > A > central pyc repository would be something I was thinking about, but I > admit it's a half baked or not even that, probably quarter baked idea. A central .pyc repository doesn't eliminate the issues developers may have with byte code files, it just puts them somewhere else, out of sight, where they are more likely to bite. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 2 20:49:17 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 01:49:17 GMT Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: > I did not propose obvious module names. I said obvious names like > email.py are bad; more descriptive names like send_email.py are better. But surely send_email.py doesn't just send email, it parses email and receives email as well? -- Steven From gagsl-py2 at yahoo.com.ar Tue Feb 2 20:56:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Feb 2010 22:56:36 -0300 Subject: unable to catch this exception References: Message-ID: En Tue, 02 Feb 2010 08:20:34 -0300, mk escribi?: > Exception in thread Thread-9 (most likely raised during interpreter > shutdown): > Traceback (most recent call last): > File "/var/www/html/cssh.py", line 617, in ssh_connect > : 'NoneType' object has no attribute > 'BadAuthenticationType' So you started several threads, and one of them was in them middle of connecting to somewhere when the program exited, correct? > This happens on interpreter shutdown, even though I do try to catch the > AttributeError exception: > > try: > fake = paramiko.BadAuthenticationType > try: > self.conobj.connect(self.ip, username=self.username, > key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) > loginsuccess = True > except paramiko.BadAuthenticationType, e: # this is line 617 > self.conerror = str(e) > except paramiko.SSHException, e: > self.conerror = str(e) > except socket.timeout, e: > self.conerror = str(e) > except socket.error, e: > self.conerror = str(e) > except AttributeError: > # this happens on interpreter shutdown > self.conerror = 'shutdown' > > > It's clear what happens: paramiko gets its attributes cleared or the > module perhaps gets unloaded and as result "paramiko" label leads to > None, which obviously has no attribute BadAuthenticationType. As part of the interpreter shutdown procedure, module globals are set to None. Code that might be executed in those very precarious circumstances should NOT reference any globals. > However, even though this is surrounded by try .. except AttributeError > block, it evidently isn't catch. How to catch that exception? Or at > least preven displaying this message? You could keep a local reference to those global names; by example, by adding 'fake' default arguments: def ssh_connect(self, other, arguments, paramiko=paramiko, socket=socket): ... or perhaps: def ssh_connect(self, other, arguments): BadAuthenticationType = paramiko.BadAuthenticationType socket_timeout = socket.timeout try: ... except BadAuthenticationType, e: ... except socket_timeout, e: ... -- Gabriel Genellina From wuwei23 at gmail.com Tue Feb 2 21:02:09 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 2 Feb 2010 18:02:09 -0800 (PST) Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <1e88a2b7-089c-41d0-aadd-38f8586e2466@a16g2000pre.googlegroups.com> On Feb 3, 9:02?am, John Nagle wrote: > ? ? I know there's a performance penalty for running Python on a > multicore CPU, but how bad is it? ?I've read the key paper > ("www.dabeaz.com/python/GIL.pdf"), of course. It's a shame that Python 3.x is dead to you, otherwise you'd be able to enjoy the new GIL implementation in 3.2: http://www.dabeaz.com/python/NewGIL.pdf Actually, it looks like you probably still can: + patch for 2.5.4: http://thread.gmane.org/gmane.comp.python.devel/109929 + patch for 2.7? http://bugs.python.org/issue7753 (Can't comment on affinity, though, sorry) From no.email at please.post Tue Feb 2 21:35:55 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 02:35:55 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: (For reasons I don't understand Stephen Hansen's posts don't show in my news server. I became aware of his reply from a passing reference in one of Terry Reedy's post. Then I found Hansen's post online, and then an earlier one, and pasted the relevant portion below.) > First, I don't shadow built in modules. Its really not very hard to avoid. ...*if* you happen to be clairvoyant. I still don't see how the rest of us could have followed this fine principle in the case of numbers.py prior to Python 2.6. > Secondly, I use packages structuring my libraries, and avoid junk > directories of a hundred some odd 'scripts'. (I feel so icky now...) > Third, I don't execute scripts in that directory structure directly, but > instead do python -c 'from package.blah import main; main.main()' or some > such. Usually via some short-cut, or a runner batch file. Breathtaking... I wonder why the Python documentation, in particular the official Python tutorial, is not more forthcoming with these rules. ~K From no.email at please.post Tue Feb 2 21:36:49 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 02:36:49 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: In Terry Reedy writes: >On 2/2/2010 2:43 PM, kj wrote: >> In Terry Reedy writes: >> >>> On 2/2/2010 9:13 AM, kj wrote: >> >>>>> As for fixing it, unfortunately it's not quite so simple to fix without >>>>> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >>>>> was missed. >>>> >>>> This last point is to me the most befuddling of all. Does anyone >>>> know why this opportunity was missed for 3.0? Anyone out there >>>> with the inside scoop on this? Was the fixing of this problem >>>> discussed in some PEP or some mailing list thread? (I've tried >>>> Googling this but did not hit on the right keywords to bring up >>>> the deliberations I'm looking for.) >> >>> There was a proposal to put the whole stdlib into a gigantic package, so >>> that >> >>> import itertools >> >>> would become, for instance >> >>> import std.itertools. >> >>> Guido rejected that. I believe he both did not like it and was concerned >>> about making upgrade to 3.x even harder. The discussion was probably on >>> the now closed py3k list. >> >> >> Thanks. I'll look for this thread. >Stephen Hansen's post explains a bit more than I did. To supplement his >explanation: since print *was* a keyword, every use of 'print' in 2.x >denotes a print statement with standard semantics. Therefore 2to3 >*knows* what the statement means and can translate it. On the other >hand, 'import string' usually means 'import the string module of the >stdlib', but it could mean 'import my string module'. This depends on >the execution environment. Moreover, I believe people have intentionally >shadowed stdlib modules. So. like it or not, 2to3 cannot know what >'import string' means. Thanks, this dispels some of the mystery. ~K From harry.python at gmail.com Tue Feb 2 21:42:05 2010 From: harry.python at gmail.com (gashero) Date: Tue, 2 Feb 2010 18:42:05 -0800 (PST) Subject: libpcap and python References: Message-ID: <94d87bff-ec51-48c7-80c8-2ef7320f75da@a17g2000pre.googlegroups.com> On 2?1?, ??8?47?, Mag Gam wrote: > Hello All, > > I used tcpdump to capture data on my network. I would like to analyze > the data using python -- currently using ethereal and wireshark. > > I would like to get certain type of packets (I can get the hex code > for them), what is the best way to do this? Lets say I want to capture > all events of `ping localhost` > > TIA You need python module "pypcap" or "pcapy" to capture the packet, and the you can use Python to analyze it. To decode the internet packet you can use "dpkt". Good Luck! From ryan at rfk.id.au Tue Feb 2 21:46:59 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Wed, 03 Feb 2010 13:46:59 +1100 Subject: Python's Reference And Internal Model Of Computing Languages In-Reply-To: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: <1265165219.2711.13.camel@durian> > On Tue, 2010-02-02 at 17:28 -0800, Xah Lee wrote: I know, I know, do not feed the trolls. But this is just so *wrong* that I can't help myself. > In Python, there are 2 ways to clear a hash: No, no there's not. There's one way to clear a hash and there's one way to assign a new object to a variable. > ?myHash = {}? and > ?myHash.clear()?. What is the difference? > The difference is that ?myHash={}? simply creates a new empty hash and > assigns to myHash, while ?myHash.clear()? actually clear the hash the > myHash is pointing to. > > What does that mean?? Here's a code that illustrates: > > # python > # 2 ways to clear hash and their difference > aa = {'a':3, 'b':4} > bb = aa > aa = {} > print bb # prints {'a': 3, 'b': 4} > > aa = {'a':3, 'b':4} > bb = aa > aa.clear() > print bb # prints {} > > This is like this because of the ?reference? concept. ...snip inane babble... > Languages that do not have any ?reference? or ?object?, or otherwise > does not require the programer to have some internal model of source > code, are: Mathematica, JavaScript, PHP. (others may include TCL, > possibly assembly langs.) Just so we're all clear exactly how much thought has gone into this little rant, here's a transcript from a JavaScript session: var aa = {}; var bb = aa; aa.hello = "world"; alert(bb.hello) --> "world" delete bb.hello alert(aa.hello) --> "undefined" OMFG, references!! Come to think of it, the JavaScript and Python object models are really very similar. I'm genuinely curious now - what little sprinkle of magic fairy dust has earned JavaScript objects the Xah Lee seal of approval while Python objects miss out? 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From no.email at nospam.invalid Tue Feb 2 22:29:57 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 02 Feb 2010 19:29:57 -0800 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: <7xiqafro7e.fsf@ruckus.brouhaha.com> Ryan Kelly writes: > I know, I know, do not feed the trolls. But this is just so *wrong* > that I can't help myself. See: http://xkcd.com/386/ From xahlee at gmail.com Tue Feb 2 22:36:38 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Feb 2010 19:36:38 -0800 (PST) Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: ()On Feb 2, 6:46?pm, Ryan Kelly wrote: > > On Tue, 2010-02-02 at 17:28 -0800, Xah Lee wrote: > > I know, I know, do not feed the trolls. ?But this is just so *wrong* > that I can't help myself. > > > In Python, there are 2 ways to clear a hash: > > No, no there's not. ?There's one way to clear a hash and there's one way > to assign a new object to a variable. > > > > > > > ??myHash = {}? and > > ?myHash.clear()?. What is the difference? > > The difference is that ?myHash={}? simply creates a new empty hash and > > assigns to myHash, while ?myHash.clear()? actually clear the hash the > > myHash is pointing to. > > > What does that mean?? Here's a code that illustrates: > > > # python > > # 2 ways to clear hash and their difference > > aa = {'a':3, 'b':4} > > bb = aa > > aa = {} > > print bb # prints {'a': 3, 'b': 4} > > > aa = {'a':3, 'b':4} > > bb = aa > > aa.clear() > > print bb # prints {} > > > This is like this because of the ?reference? concept. > > ...snip inane babble... > > > Languages that do not have any ?reference? or ?object?, or otherwise > > does not require the programer to have some internal model of source > > code, are: Mathematica, JavaScript, PHP. (others may include TCL, > > possibly assembly langs.) > > Just so we're all clear exactly how much thought has gone into this > little rant, here's a transcript from a JavaScript session: > > ? var aa = {}; > ? var bb = aa; > ? aa.hello = "world"; > ? alert(bb.hello) ?--> ?"world" > ? delete bb.hello > ? alert(aa.hello) ?--> ?"undefined" > > OMFG, references!! > > Come to think of it, the JavaScript and Python object models are really > very similar. ?I'm genuinely curious now - what little sprinkle of magic > fairy dust has earned JavaScript objects the Xah Lee seal of approval > while Python objects miss out? Thanks. You are right. I think i put JavaScript there without much thinking. Xah From steve at holdenweb.com Tue Feb 2 22:53:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 22:53:44 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: kj wrote: > > (For reasons I don't understand Stephen Hansen's posts don't show > in my news server. I became aware of his reply from a passing > reference in one of Terry Reedy's post. Then I found Hansen's post > online, and then an earlier one, and pasted the relevant portion > below.) > > > >> First, I don't shadow built in modules. Its really not very hard to avoid. > > ...*if* you happen to be clairvoyant. I still don't see how the rest of us > could have followed this fine principle in the case of numbers.py > prior to Python 2.6. > Clearly the more you know about the standard library the less likely this is to be a problem. Had you been migrqating from an earlier version the breakage would have alerted you to look for some version-dependent difference. >> Secondly, I use packages structuring my libraries, and avoid junk >> directories of a hundred some odd 'scripts'. > > (I feel so icky now...) > Be as flippant as you like, but that is good advice. >> Third, I don't execute scripts in that directory structure directly, but >> instead do python -c 'from package.blah import main; main.main()' or some >> such. Usually via some short-cut, or a runner batch file. > > Breathtaking... I wonder why the Python documentation, in particular > the official Python tutorial, is not more forthcoming with these > rules. > Because despite the fact that this issue has clearly bitten you badly enough to sour you against the language, such issues are remarkably rare in practice and normally rather easier to debug. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From pavlovevidence at gmail.com Tue Feb 2 22:55:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 19:55:15 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: <8104faf3-c4ea-4b1f-8316-f8b17f53554b@q2g2000pre.googlegroups.com> On Feb 2, 5:49?pm, Steven D'Aprano wrote: > On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: > > I did not propose obvious module names. ?I said obvious names like > > email.py are bad; more descriptive names like send_email.py are better. > > But surely send_email.py doesn't just send email, it parses email and > receives email as well? No, it doesn't. Carl Banks From g.bogle at auckland.no.spam.ac.nz Tue Feb 2 23:03:08 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 03 Feb 2010 17:03:08 +1300 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> <7xiqafro7e.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Ryan Kelly writes: >> I know, I know, do not feed the trolls. But this is just so *wrong* >> that I can't help myself. > > See: http://xkcd.com/386/ :-) From steven at REMOVE.THIS.cybersource.com.au Tue Feb 2 23:52:42 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 04:52:42 GMT Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> <8104faf3-c4ea-4b1f-8316-f8b17f53554b@q2g2000pre.googlegroups.com> Message-ID: On Tue, 02 Feb 2010 19:55:15 -0800, Carl Banks wrote: > On Feb 2, 5:49?pm, Steven D'Aprano > wrote: >> On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: >> > I did not propose obvious module names. ?I said obvious names like >> > email.py are bad; more descriptive names like send_email.py are >> > better. >> >> But surely send_email.py doesn't just send email, it parses email and >> receives email as well? > > No, it doesn't. Nevertheless, as a general principle, modules will tend to be multi- purpose and/or generic. How would you rename the math or random modules to be less "obvious" and more "descriptive"? And of course, the less obvious the name, the harder it becomes for people to find and use it. Which extreme would you rather? import zip import compress_and_decompress_files_to_zip_archives I'm sympathetic to the position you're taking. It's not bad advice at all, but I think you're over-selling it as a complete solution to the problem of name clashes. I think it can only slightly alleviate the problem of name clashes, not eliminate it. -- Steven From john at castleamber.com Wed Feb 3 00:08:39 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Feb 2010 23:08:39 -0600 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <87bpg6sy7c.fsf@castleamber.com> Xah Lee writes: > (12:12:30 PM) You have been kicked by dash: (No.) Oh noes, someone is harrassing poor Xah the Usenet spammer. You have been and still are a major pain in the ass to a lot of Usenet users, and still surprised that you're not making friends. I mean, what did you want to do on IRC? Copy paste line by line one of your "fine" articles, followed by a link to your site. And what the hell were you doing, asking a Python question in #python? Shouldn't that be asked the Xah way in #perl or #lisp? -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Wed Feb 3 00:11:49 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Feb 2010 23:11:49 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> Message-ID: <877hqusy22.fsf@castleamber.com> Jonathan Gardner writes: > I can explain, in an hour, every single feature of the Python language > to an experienced programmer, all the way up to metaclasses, Either you're a hell of a talker, or I am far, far away from being an experienced programmer. It's advocacy like this, IMO, that keeps people away from a language, because you can't feel nothing but a failure after a statement like this. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Wed Feb 3 00:29:21 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Feb 2010 23:29:21 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> Message-ID: <873a1isx8u.fsf@castleamber.com> Jonathan Gardner writes: > On Feb 1, 6:36?pm, John Bokma wrote: [..] >> It should be $bar = \&foo >> Your example actually calls foo... > > I rest my case. I've been programming perl professionally since 2000, > and I still make stupid, newbie mistakes like that. Uhm, in another post you wrote that you could explain Python in an hour to an experienced programmer and you *still* make mistakes like that in Perl!? By the way, the language is called Perl. If you write "I've been programming perl" in a Perl related group some people might read it as that you've been working on the internals of the perl executable (in C) >> > One is simple, consistent, and easy to explain. The other one requires >> > the introduction of advanced syntax and an entirely new syntax to make >> > function calls with references. >> >> The syntax follows that of referencing and dereferencing: >> >> $bar = \@array; ? ? ? # bar contains now a reference to array >> $bar->[ 0 ]; ? ? ? ? ?# first element of array referenced by bar >> $bar = \%hash; ? ? ? ?# bar contains now a reference to a hash >> $bar->{ key }; ? ? ? ?# value associated with key of hash ref. by bar >> $bar = \&foo; ? ? ? ? # bar contains now a reference to a sub >> $bar->( 45 ); ? ? ? ? # call sub ref. by bar with 45 as an argument >> >> Consistent: yes. New syntax? No. >> > > Except for the following symbols and combinations, which are entirely > new and different from the $@% that you have to know just to use > arrays and hashes. > > \@, ->[ ] @array, one item: $array[ 1 ]; $arrayref, one item: $arrayref->[ 1 ]; > \%, ->{ } %hash, one item: $hash{ key }; hence: $hashref, one item: $hash->{ key } > \&, ->( ) should now be clear ;-) You *should* have no problem with that if you have been programming professionally Perl since 2000 IMNSHO. Otherwise print my post or copy it on a post-it note ;-). Remember that all this was added to Perl in version 5. So it had to be added in a way that wouldn't break Perl 4. Perl is, in my experience quite good in backwards compatibility. Quite some Perl modules on CPAN work from 5.00x-5.10 and most likely will work without trouble in 5.12. > By the way: > * How do you do a hashslice on a hashref? I will reply like it's a genuine question, and not like "Oh, look, how silly Perl works". I don't care about that much. I do like Perl and am starting to like Python. @$hashref{ 'key1', 'key2', 'key3' }; > * How do you invoke reference to a hash that contains a reference to > an array that contains a reference to a function? I guess you mean: $hashref->{ key }[ index ]( arguments ); The long version is: $hashref->{ key }->[ index ]->( arguments ); [ Python advocacy snipped] > I'd rather think of the task at hand than what each of the funky > symbols on my keyboard mean. Then just quit programming Perl ;-) Perl has always come naturally to me, no idea why. Recently I said to a close friend: Python is like my desk, which I prefer to keep clean and neat. Perl is like my livingroom, which I prefer to keep clean and neat to some extend, but some mess is allowed. For example, the cat can be there. Toys of my daughter are allowed to be all over the place. A pleasant mess, but not too much. I won't repeat what I said about PHP ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 00:59:03 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 05:59:03 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> Message-ID: On Tue, 02 Feb 2010 23:11:49 -0600, John Bokma wrote: > Jonathan Gardner writes: > >> I can explain, in an hour, every single feature of the Python language >> to an experienced programmer, all the way up to metaclasses, > > Either you're a hell of a talker, or I am far, far away from being an > experienced programmer. It's advocacy like this, IMO, that keeps people > away from a language, because you can't feel nothing but a failure after > a statement like this. Surely you're exaggerating? Without making any aspersions towards Jonathan either way, the Internet is full of both blowhards and geniuses. Anyone who lets the off-the-cup claims of either ruin their self-confidence is unlikely to be thinking about learning Python, they're probably sitting alone in a dark room staring as the walls close in. Either that or on MySpace. -- Steven From hirotaka.niitsuma at gmail.com Wed Feb 3 01:01:22 2010 From: hirotaka.niitsuma at gmail.com (Niitsuma Hirotaka) Date: Wed, 3 Feb 2010 15:01:22 +0900 Subject: calling python from lisp Message-ID: <6ce56e1a1002022201y9654271p9df4afc11dfc4d8b@mail.gmail.com> Autor: Martin Rubey Data: 2008-10-29 09:34 +900 Dla: python-list CC: sage-devel Temat: calling python from lisp http://archives.free.net.ph/message/20081029.003410.172560ac.pl.html >sys:1: RuntimeWarning: Python C API version mismatch for module pol: This Python has API version 1013, module pol has version 1011. I modified some of pythononlisp including this. http://www2s.biglobe.ne.jp/~niitsuma/pythononlispex.html plz try. From mensanator at aol.com Wed Feb 3 01:03:54 2010 From: mensanator at aol.com (Mensanator) Date: Tue, 2 Feb 2010 22:03:54 -0800 (PST) Subject: ANN: GMPY 1.11 released References: Message-ID: On Feb 2, 12:45?am, casevh wrote: > Everyone, > > I'm pleased to annouce the final release of GMPY 1.11. > GMPY is a wrapper for the MPIR or GMP multiple-precision > arithmetic library. GMPY 1.11 is available for download from: > > http://code.google.com/p/gmpy/ > > In addition to support for Python 3.x, there are several new > features in this release: > > - Even faster conversion to/from Python longs. > - Performance improvements by reducing function overhead. > - Performance improvements by improved caching. > - Support for cdivmod, fdivmod, and tdivmod. > - Unicode strings are accepted on Python 2.x and 3.x. > - Fixed regression in GMPY 1.10 where True/False were no > ? longer recognized. > > Changes since 1.11rc1: > - Recognizes GMP 5. > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > Comments on provided binaries > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > 1.3.1 and will automatically recognize the CPU type and use code > optimized for the CPU at runtime. The 64-bit Windows installers were > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > instructions are included if you want to compile your own binary. > > Please report any issues! My previous replies didn't show up. Something to do the .announce group? I'll trim that and try again. Sorry if they show up eventually. Two issues: 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply >>> gmpy.version() '1.11' Aren't these different versions? How are we supposed to tell them apart? 2] Is it true that the only changes since 1.11rc1 are not applicable to me since - I'm not using Windows - whether it recognizes GMP 5 is moot as GMP 5 cannot be compiled on a Mac (according to GMP site) Is it possible GMP's problems with getting GMP 5 to compile are the same ones I had with 3.1 on Snow Leopard? (They bemoan not having a set of every Mac system.) Think it would behoove me to try it? > > casevh From john at castleamber.com Wed Feb 3 01:20:18 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 00:20:18 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> Message-ID: <87pr4msuvx.fsf@castleamber.com> Steven D'Aprano writes: > On Tue, 02 Feb 2010 23:11:49 -0600, John Bokma wrote: > >> Jonathan Gardner writes: >> >>> I can explain, in an hour, every single feature of the Python language >>> to an experienced programmer, all the way up to metaclasses, >> >> Either you're a hell of a talker, or I am far, far away from being an >> experienced programmer. It's advocacy like this, IMO, that keeps people >> away from a language, because you can't feel nothing but a failure after >> a statement like this. > > Surely you're exaggerating? No, because if I was I would've put a smiley there somewhere. I am learning Python, for a time to be honest. I can manage in the language quite well. I consider myself quite an experienced Perl programmer, I have no problems with the constructs Jonathan elsewhere in this thread claims to have problems with after 10 years of professional Perl programming. They come natural to me. But I don't see myself being able to understand every Python feature in a talk of an hour *with* the current understanding of Python I have (read halfway through Programming In Python 3, read selected chapters on decorators, etc.). > Without making any aspersions towards Jonathan either way, the Internet > is full of both blowhards and geniuses. Anyone who lets the off-the-cup > claims of either ruin their self-confidence is unlikely to be thinking > about learning Python, they're probably sitting alone in a dark room > staring as the walls close in. I am quite serious about learning Python, I do write professionally in it [1], but I am convinced that I need at least several months more of studying to feel comfortable with most (not even all) of Python. To me a much more relastic view on learning a programming language is: http://norvig.com/21-days.html [1] very small programs, and my customer is fully aware of that I am learning a new language but trust me, which is great. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Wed Feb 3 01:27:37 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 00:27:37 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <87pr4msuvx.fsf@castleamber.com> Message-ID: <87ljfasujq.fsf@castleamber.com> John Bokma writes: > Steven D'Aprano writes: > >> On Tue, 02 Feb 2010 23:11:49 -0600, John Bokma wrote: >> >>> Jonathan Gardner writes: >>> >>>> I can explain, in an hour, every single feature of the Python language >>>> to an experienced programmer, all the way up to metaclasses, >>> >>> Either you're a hell of a talker, or I am far, far away from being an >>> experienced programmer. It's advocacy like this, IMO, that keeps people >>> away from a language, because you can't feel nothing but a failure after >>> a statement like this. >> >> Surely you're exaggerating? > > No, because if I was I would've put a smiley there somewhere. I am > learning Python, for a time to be honest. I can manage in the language > quite well. Clarification: for a beginner that is. > [1] very small programs, and my customer is fully aware of that I am > learning a new language but trust me, which is great. Should've been "but trusts me,". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 01:33:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 01:33:20 -0500 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <1e88a2b7-089c-41d0-aadd-38f8586e2466@a16g2000pre.googlegroups.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <1e88a2b7-089c-41d0-aadd-38f8586e2466@a16g2000pre.googlegroups.com> Message-ID: On 2/2/2010 9:02 PM, alex23 wrote: > On Feb 3, 9:02 am, John Nagle wrote: >> I know there's a performance penalty for running Python on a >> multicore CPU, but how bad is it? I've read the key paper >> ("www.dabeaz.com/python/GIL.pdf"), of course. > > It's a shame that Python 3.x is dead to you, otherwise you'd be able > to enjoy the new GIL implementation in 3.2: http://www.dabeaz.com/python/NewGIL.pdf > > Actually, it looks like you probably still can: > + patch for 2.5.4: http://thread.gmane.org/gmane.comp.python.devel/109929 > + patch for 2.7? http://bugs.python.org/issue7753 The patch was rejected for 2.7 (and earlier) because it could break code as explained in the discussion. One would have to apply and compile their own binary. From swrath at gmail.com Wed Feb 3 01:38:56 2010 From: swrath at gmail.com (sWrath swrath) Date: Tue, 2 Feb 2010 22:38:56 -0800 (PST) Subject: newbie qns : how do i use xmldiff? Message-ID: Hi , I am pretty new to python , and reading up on it. Basically I am trying to compare xml files . I know difflib have it but it does not work out as expected. I was looking at xmldiff , unfortunately I am not able to find documentation how to call it from python. Anyone knows a link or doc to it as I have been looking high and low for few days? lastly , is there a py (or algorithm) where it behaves exactly like diff ? Greatly appreciated. Thanks john From lanyjie at yahoo.com Wed Feb 3 01:43:51 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Feb 2010 22:43:51 -0800 (PST) Subject: expy 0.5.2 released Message-ID: <857729.7198.qm@web54208.mail.re2.yahoo.com> Hi, expy is an expressway to extend python. in release 0.5.2, expy now supports custom exceptions, besides all built-in ones, and exception handling is made easy. for more info, see http://expy.sourceforge.net/ cheers, Yingjie From simonzack at gmail.com Wed Feb 3 03:30:41 2010 From: simonzack at gmail.com (Simon zack) Date: Wed, 3 Feb 2010 16:30:41 +0800 Subject: exec within function Message-ID: hi, I'm not sure how I can use exec within a function correctly here is the code i'm using: def a(): exec('b=1') print(b) a() this will raise an error, but I would like to see it outputting 1 thanks smk -------------- next part -------------- An HTML attachment was scrubbed... URL: From news123 at free.fr Wed Feb 3 03:32:58 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 09:32:58 +0100 Subject: simple and fast platform independent IPC Message-ID: <4b6934ba$0$18396$426a34cc@news.free.fr> Hi, I wondered what IPC library might be best simplest for following task? I'm having a few python scripts all running on the same host (linux or win), which are started manually in random order. (no common parent process) Each process might be identified by an integer (1,2,3) or by a symbolic name ( 'dad' , 'mom' , 'dog' ) these scripts want to send short messages to each other ( mostly integers, max a few bytes, short string), which would be enqueued in message queues of the receiving process. example: 'dad' wants to tell 'mom': 'cook' 'dog' wants to tell 'dad' : 'feedme' 'mom' wants to tell 'dad' : 'cookyourself' the receiver dos not necesarily have to know who sent the message a message shall be dropped silently if the receiving process is not running a message shall be reliably delivered if the receiving process is up xmlrpc seems to be a little heavy for such tasks. signals don't allow to exchange data a shared memory message queue would probably a good solution, but python's Multiprocessing.Queue seems to require a common parent process thanks a lot for any ideas / suggestions N N From masklinn at masklinn.net Wed Feb 3 03:50:26 2010 From: masklinn at masklinn.net (Masklinn) Date: Wed, 3 Feb 2010 09:50:26 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <4B685860.4000903@sequans.com> References: <4B685860.4000903@sequans.com> Message-ID: <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> On 2 Feb 2010, at 17:52 , Jean-Michel Pichavant wrote: > > Masklinn wrote: >> Jean-Michel Pichavant wrote: >> >>> To add a custom level, I would proceed that way: >>> >>> logging.ALERT = 45 >>> logging.addLevelName(logging.ALERT, 'ALERT !!') >>> logging.getLogger().log(logging.ALERT, 'test') >>> >>> Passing a string to the log method as you did is incorrect. >>> >> >> I know it's currently incorrect. My point was more along the line that there was *no reason* for it to be incorrect. logging already contains all the tools for log('PANTS_ON_FIRE') to be allowed >> > The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. That's not a reason, that's just what currently happens. I know it doesn't work, and I know why, I went and checked the code. But there's no fundamental reason why you couldn't use a level *name* instead of a level code. And indeed, in most parts of logging you can (including but not limited to the configuration of handlers and loggers) >> >>> Regarding your first point, I guess it's anti pattern. One way to do it: >>> 1/ Configure the root logger with the lowest value 0, so the root logger does not filter any level. >>> 2/ Configure each of your logger with the correct level >>> >>> That way you can configure your '0' logger as you (badly :o)) named it with one level, and configure a potential '1' logger with another level. Don't bother with propagation. That way you won't need to duplicate your handlers on every logger. >>> >> >> re logger 0, no need for complex name for a test case (and it allowed me to create easy-to-remember 0.1 and 0.1.2 if needed) >> >> Re your answer, from what I understand you want the root logger to NOTSET and then each child logger with its correct level? But that's not a solution, each and every level will *still* require a handler explicitly configured on it. That's in fact very much my issue: logging refuses that a logger be handler-less in a config file, it's mandatory to configure a handler any time a logger is configured. >> > the field handlers must be defined even if empty. Ah, interesting, I didn't think it could be defined as empty. Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? From timothy.tsvetkov at gmail.com Wed Feb 3 04:21:44 2010 From: timothy.tsvetkov at gmail.com (Timothy N. Tsvetkov) Date: Wed, 3 Feb 2010 01:21:44 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <4da2372c-954c-46b8-a6e9-2768bce812f5@l19g2000yqb.googlegroups.com> On Jan 28, 2:29?am, Jonathan Gardner wrote: > On Jan 27, 5:47?am, Simon Brunning wrote: > > > > > I think Python is a little cleaner, but I'm sure you'd find Ruby fans > > who'd argue the complete opposite. > > Are you sure about that? > > There's a lot of line noise in Ruby. How are you supposed to pronounce > "@@"? What about "{|..| ... }"? > > There's a lot of "magic" in Ruby as well. For instance, function calls > are made without parentheses. Blocks can only appear as the first > argument. There's a lot more, if you put your mind to it. > > Indentation is also optional in Ruby. You can quickly fool a newbie by > not indenting your code properly, which is impossible in Python. > > Python is much, much cleaner. I don't know how anyone can honestly say > Ruby is cleaner than Python. I will. I developed on both (Python was first) and I think that ruby I very clean and maybe cleaner than Python. Also I don't know any situation where you need to pronounce your code symbol by symbol. You might need to pronounce some semantics. And you're wrong with blocks. About indent your right. It helps newbies indent code becouse they must to. But most of professional developers started with Pascal and then C and they all indent well :) it is about culture and it is what about teacher should say. From gagsl-py2 at yahoo.com.ar Wed Feb 3 04:29:38 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Feb 2010 06:29:38 -0300 Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: En Wed, 03 Feb 2010 05:32:58 -0300, News123 escribi?: > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent > process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) > > these scripts want to send short messages to each other ( mostly > integers, max a few bytes, short string), which would be enqueued in > message queues of the receiving process. > > example: > > 'dad' wants to tell 'mom': 'cook' > 'dog' wants to tell 'dad' : 'feedme' > 'mom' wants to tell 'dad' : 'cookyourself' Try using a named pipe between each pair of processes (os.mkfifo + open on Linux, open(r"\\.\pipe\desired_name", ...) on Windows) -- Gabriel Genellina From vinay_sajip at yahoo.co.uk Wed Feb 3 04:34:34 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 3 Feb 2010 01:34:34 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> On Feb 3, 8:32?am, News123 wrote: > Hi, > > I wondered what IPC library might be best simplest for following task? > > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) > > these scripts want to send short messages to each other ( mostly > integers, max a few bytes, short string), which would be enqueued in > message queues of the receiving process. > > example: > > 'dad' wants to tell 'mom': 'cook' > 'dog' wants to tell 'dad' : 'feedme' > 'mom' wants to tell 'dad' : 'cookyourself' > > the receiver dos not necesarily have to know who sent the message > > a message shall be dropped silently if the receiving process is not running > > a message shall be reliably delivered if the receiving process is up > > xmlrpc seems to be a little heavy for such tasks. > > signals don't allow to exchange data > > a shared memory message queue would probably a good solution, but > python's Multiprocessing.Queue ?seems to require a common parent process > > thanks a lot for any ideas / suggestions > > N > > N Gabriel's suggestion is very good; if you need something which is a little more like RPC but still quite lightweight, consider Pyro (http://pyro.sourceforge.net/) Regards, Vinay Sajip From tinnews at isbd.co.uk Wed Feb 3 04:45:16 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 3 Feb 2010 09:45:16 +0000 Subject: pyfltk ducumentation question Message-ID: I have just installed pyfltk version 1.1.4 on my xubuntu 9.10 system, it's working OK and a fairly trivial little program I have written is able to pop up a GUI window. However I'm now a bit stuck as the documentation seems a little sparse. For example I'm using FL_Multiline_Output and can't find enough detail to enable me to use its methods. I start from:- http://pyfltk.sourceforge.net/docs/CH3_Common.html This tells me that there is a FL_Multiline_Output widget and that it has a value() method, this is what I have used to display some text in my little application. When I click on the FL_Multiline_Output link in the above page it takes me to:- http://pyfltk.sourceforge.net/docs/fltk.html#Fl_Multiline_Output which lists all the methods and other bits and pieces belonging to Fl_Multiline_Output but as far as I can see that's it, there is no further information. The methods are links but they only link to themselves, when you click on them the browser moves the method to the top of the display window. Am I missing something obvious or do I need the FLTK documentation to give me the detail I need? -- Chris Green From no.email at please.post Wed Feb 3 05:01:55 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 10:01:55 +0000 (UTC) Subject: test -- please ignore Message-ID: (my replies in a different comp.lang.python thread are getting rejected by the server; i have no problem posting to alt.test; and i'm trying to toubleshoot the problem further.) From peloko45 at gmail.com Wed Feb 3 05:39:58 2010 From: peloko45 at gmail.com (Joan Miller) Date: Wed, 3 Feb 2010 02:39:58 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> Message-ID: <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> On 3 feb, 09:34, Vinay Sajip wrote: > On Feb 3, 8:32?am, News123 wrote: > > > > > Hi, > > > I wondered what IPC library might be best simplest for following task? > > > I'm having a few python scripts all running on the same host (linux or > > win), which are started manually in random order. (no common parent process) > > Each process might be identified by an integer (1,2,3) or by a symbolic > > name ( 'dad' , 'mom' , 'dog' ) > > > these scripts want to send short messages to each other ( mostly > > integers, max a few bytes, short string), which would be enqueued in > > message queues of the receiving process. > > > example: > > > 'dad' wants to tell 'mom': 'cook' > > 'dog' wants to tell 'dad' : 'feedme' > > 'mom' wants to tell 'dad' : 'cookyourself' > > > the receiver dos not necesarily have to know who sent the message > > > a message shall be dropped silently if the receiving process is not running > > > a message shall be reliably delivered if the receiving process is up > > > xmlrpc seems to be a little heavy for such tasks. > > > signals don't allow to exchange data > > > a shared memory message queue would probably a good solution, but > > python's Multiprocessing.Queue ?seems to require a common parent process > > > thanks a lot for any ideas / suggestions > > > N > > > N > > Gabriel's suggestion is very good; if you need something which is a > little more like RPC but still quite lightweight, consider Pyro > (http://pyro.sourceforge.net/) > > Regards, > > Vinay Sajip I've read that Pyro is not safe. Anyway, you have in mind that respect to speed: shared memory > named pipes > Unix domain socket > TCP socket I don't sure about if the message queues would be faster that Unix domain sockets Another thing. Using shared memory would be as to use a single thread but using message queues would be as multiple-threading. From news123 at free.fr Wed Feb 3 05:46:16 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 11:46:16 +0100 Subject: simple and fast platform independent IPC In-Reply-To: References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <4b6953f8$0$17133$426a74cc@news.free.fr> Hi Gabriel, I'll look at it. I wasn't aware about named pipes for windows. bye N Gabriel Genellina wrote: > En Wed, 03 Feb 2010 05:32:58 -0300, News123 escribi?: > >> I'm having a few python scripts all running on the same host (linux or >> win), which are started manually in random order. (no common parent >> process) >> Each process might be identified by an integer (1,2,3) or by a symbolic >> name ( 'dad' , 'mom' , 'dog' ) >> >> these scripts want to send short messages to each other ( mostly >> integers, max a few bytes, short string), which would be enqueued in >> message queues of the receiving process. >> >> example: >> >> 'dad' wants to tell 'mom': 'cook' >> 'dog' wants to tell 'dad' : 'feedme' >> 'mom' wants to tell 'dad' : 'cookyourself' > > Try using a named pipe between each pair of processes (os.mkfifo + open > on Linux, open(r"\\.\pipe\desired_name", ...) on Windows) > From jeanmichel at sequans.com Wed Feb 3 05:50:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 03 Feb 2010 11:50:19 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> Message-ID: <4B6954EB.6010004@sequans.com> >> The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. >> > That's not a reason, that's just what currently happens. I know it doesn't work, and I know why, I went and checked the code. But there's no fundamental reason why you couldn't use a level *name* instead of a level code. And indeed, in most parts of logging you can (including but not limited to the configuration of handlers and loggers) > > You don't neeed to check the code for that ! It is written in the documentation. The logging module designer choose to ask for a level, not a level name, possibly because 2 different levels can have the same name. >> >> the field handlers must be defined even if empty. >> > Ah, interesting, I didn't think it could be defined as empty. > > Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? > > 'completeley nonsensical' is overstating. It make sense to state that your handler list is empty, when it is empty. Having no field at all could possibly mean the same, but it's often better that have one consisten way to interface with a module. JM From mail at timgolden.me.uk Wed Feb 3 05:54:19 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 03 Feb 2010 10:54:19 +0000 Subject: simple and fast platform independent IPC In-Reply-To: <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> Message-ID: <4B6955DB.2060604@timgolden.me.uk> [News123] >>> I wondered what IPC library might be best simplest for following task? ... >>> xmlrpc seems to be a little heavy for such tasks. >> >>> signals don't allow to exchange data >> >>> a shared memory message queue would probably a good solution, but >>> python's Multiprocessing.Queue seems to require a common parent process [Vinay Sajip] >> Gabriel's suggestion is very good; if you need something which is a >> little more like RPC but still quite lightweight, consider Pyro >> (http://pyro.sourceforge.net/) [peloko45 at gmail.com] > I've read that Pyro is not safe. That's a fairly broad thing to say. I've read lots of things. What does "is not safe" mean, in any case? I assume you've got a valid concern in mind which is worth passing on to a would-be user, but what exactly is it? FWIW I've used Pyro on and off over the years without any problems. Certainly my computer's never blown up as a result of using it. Obviously Pyro is Python-only so interaction with non-Python code would be problematic. But the OP only mentions Python scripts so hopefully that wouldn't be an issue... >Anyway, you have in mind that respect to speed: > > shared memory> named pipes> Unix domain socket> TCP socket True, but the OP didn't mention speed; rather simplicity. Not saying it isn't a consideration but premature optimisation and all that... > Another thing. Using shared memory would be as to use a single thread > but using message queues would be as multiple-threading. And therefore...? I think you need to make your points more clearly. TJG From fetchinson at googlemail.com Wed Feb 3 05:55:57 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 3 Feb 2010 11:55:57 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >>> I like seeing them in the same place as the source file, because when I >>> start developing a module, I often end up renaming it multiple times >>> before it settles on a final name. When I rename or move it, I delete >>> the .pyc file, and that ensures that if I miss changing an import, and >>> try to import the old name, it will fail. >>> >>> By hiding the .pyc file elsewhere, it is easy to miss deleting one, and >>> then the import won't fail, it will succeed, but use the old, obsolete >>> byte code. >> >> >> Okay, I see your point but I think your argument about importing shows >> that python is doing something suboptimal because I have to worry about >> .pyc files. Ideally, I only would need to worry about python source >> files. > > That's no different from any language that is compiled: you have to worry > about keeping the compiled code (byte code or machine language) in sync > with the source code. True. > Python does most of that for you: it automatically recompiles the source > whenever the source code's last modified date stamp is newer than that of > the byte code. So to a first approximation you can forget all about > the .pyc files and just care about the source. True, but the .pyc file is lying around and I always have to do 'ls -al | grep -v pyc' in my python source directory. > But that's only a first approximation. You might care about the .pyc > files if: > > (1) you want to distribute your application in a non-human readable > format; Sure, I do care about pyc files, of course, I just would prefer to have them at a separate location. > (2) if you care about clutter in your file system; You mean having an extra directory structure for the pyc files? This I think would be better than having the pyc files in the source directory, but we are getting into 'gut feelings' territory :) > (3) if you suspect a bug in the compiler; If the pyc files are somewhere else you can still inspect them if you want. > (4) if you are working with byte-code hacks; Again, just because they are somewhere else doesn't mean you can't get to them. > (5) if the clock on your PC is wonky; Same as above. > (6) if you leave random .pyc files floating around earlier in the > PYTHONPATH than your source files; > > etc. > > > > >> There is now a chance to 'fix' (quotation marks because maybe >> there is nothing to fix, according to some) this issue and make all pyc >> files go away and having python magically doing the right thing. > > Famous last words... > > The only ways I can see to have Python magically do the right thing in > all cases would be: > > (1) Forget about byte-code compiling, and just treat Python as a purely > interpreted language. If you think Python is slow now... I'm not advocating this option, naturally. > (2) Compile as we do now, but only keep the byte code in memory. This > would avoid all worries about scattered .pyc files, but would slow Python > down significantly *and* reduce functionality (e.g. losing the ability to > distribute non-source files). I'm not advocating this option either. > Neither of these are seriously an option. Agreed. >> A >> central pyc repository would be something I was thinking about, but I >> admit it's a half baked or not even that, probably quarter baked idea. > > A central .pyc repository doesn't eliminate the issues developers may > have with byte code files, it just puts them somewhere else, out of > sight, where they are more likely to bite. Here is an example: shared object files. If your code needs them, you can use them easily, you can access them easily if you want to, but they are not in the directory where you keep your C files. They are somewhere in /usr/lib for example, where they are conveniently collected, you can inspect them, look at them, distribute them, do basically whatever you want, but they are out of the way, and 99% of the time while you develop your code, you don't need them. In the 1% of the case you can easily get at them in the centralized location, /usr/lib in our example. Of course the relationship between C source files and shared objects is not parallel to the relationship to python source files and the created pyc files, please don't nitpick on this point. The analogy is in the sense that your project inevitable needs for whatever reason some binary files which are rarely needed at hand, only the linker/compiler/interpreter/etc needs to know where they are. These files can be stored separately, but at a location where one can inspect them if needed (which rarely happens). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From eden at bicikl. Wed Feb 3 06:05:02 2010 From: eden at bicikl. (Eden Kirin) Date: Wed, 03 Feb 2010 12:05:02 +0100 Subject: simple and fast platform independent IPC In-Reply-To: <4b6934ba$0$18396$426a34cc@news.free.fr> References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: On 03.02.2010 09:32, News123 wrote: > Hi, > > I wondered what IPC library might be best simplest for following task? Consider using Thrift (http://incubator.apache.org/thrift/). It is multiplatform multilanguage RPC and IPC solution. I implemented it in couple of my projects and it works seamlessly. -- www.vikendi.net -/- www.supergrupa.com From ben+python at benfinney.id.au Wed Feb 3 06:05:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Feb 2010 22:05:08 +1100 Subject: test -- please ignore References: Message-ID: <87wryumvff.fsf@benfinney.id.au> kj writes: > (my replies in a different comp.lang.python thread are getting > rejected by the server; i have no problem posting to alt.test; and > i'm trying to toubleshoot the problem further.) Thank you for this explanation. It is important to know that you've tried the less obtrusive diagnostics first. Good hunting. -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From kmisoft at gmail.com Wed Feb 3 06:10:21 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 14:10:21 +0300 Subject: Dreaming of new generation IDE Message-ID: Hello, I am sitting here for quite some time, but usually keep silent ;-) I use Python since 2003 both "professionally" and for my hobby projects and love it a much. I notice however, that "maintaining" existing/older python code is may be not so enjoyable task. It may be even harder than supporting old code written in some type of "static" languages (like Java or C++). Surely "dynamic" nature of python comes with price. Finally I develop a feeling that strong instrumentation / tools can bring us the best of two worlds. That I am dreaming on is an absolute new type/class of IDE suitable for Python and potentially for other dynamic-type languages. Instead of current text-oriented IDEs, it should be a database-centric and resemble current CAD systems instead of being just "fancy text editor". Source text should be an output product of that CAD and not a "source material" itself. Well. I understand that it is a very ambitious and experimental stuff. Great efforts and motivation needed even to get something "runnable". So I am looking for someone to get in kind of "virtual partnership". If someone interesting it that soft of stuff, I would like to talk and discuss this system. Vladimir Ignatov From peloko45 at gmail.com Wed Feb 3 06:31:14 2010 From: peloko45 at gmail.com (Joan Miller) Date: Wed, 3 Feb 2010 03:31:14 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> Message-ID: <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> On 3 feb, 10:54, Tim Golden wrote: > [News123] > > >>> I wondered what IPC library might be best simplest for following task? > > ... > > >>> xmlrpc seems to be a little heavy for such tasks. > > >>> signals don't allow to exchange data > > >>> a shared memory message queue would probably a good solution, but > >>> python's Multiprocessing.Queue ?seems to require a common parent process > > [Vinay Sajip] > > >> Gabriel's suggestion is very good; if you need something which is a > >> little more like RPC but still quite lightweight, consider Pyro > >> (http://pyro.sourceforge.net/) > > [pelok... at gmail.com] > > > I've read that Pyro is not safe. > > That's a fairly broad thing to say. I've read lots > of things. What does "is not safe" mean, in any case? > I assume you've got a valid concern in mind which is > worth passing on to a would-be user, but what exactly > is it? FWIW I've used Pyro on and off over the years > without any problems. Certainly my computer's never > blown up as a result of using it. >From its own page: "Pyro has never been truly designed to provide a secure communication mechanism, nor has it had a security review or -test by a security expert." http://pyro.sourceforge.net/features.html > Obviously Pyro is Python-only so interaction with non-Python > code would be problematic. But the OP only mentions Python > scripts so hopefully that wouldn't be an issue... From masklinn at masklinn.net Wed Feb 3 06:36:53 2010 From: masklinn at masklinn.net (Masklinn) Date: Wed, 3 Feb 2010 12:36:53 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <4B6954EB.6010004@sequans.com> References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> <4B6954EB.6010004@sequans.com> Message-ID: <6B7EE46E-CECB-42CB-AA6B-5986E1A2210D@masklinn.net> On 3 Feb 2010, at 11:50 , Jean-Michel Pichavant wrote: > > >>> The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. >>> >> That's not a reason, that's just what currently happens. I know it doesn't work, and I know why, I went and checked the code. But there's no fundamental reason why you couldn't use a level *name* instead of a level code. And indeed, in most parts of logging you can (including but not limited to the configuration of handlers and loggers) >> > You don't neeed to check the code for that ! It is written in the documentation. The logging module designer choose to ask for a level, not a level name, possibly because 2 different levels can have the same name. > Nope, 2 different levels cannot have the same name: levels are currently stored in a dict of string:level and level:string, so you can't have 2 names for the same level, and you can't have 2 levels with the same name either. >>> >>> the field handlers must be defined even if empty. >>> >> Ah, interesting, I didn't think it could be defined as empty. >> >> Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? > 'completeley nonsensical' is overstating. It make sense to state that your handler list is empty, when it is empty. Programmatically, that's implied in the fact that you aren't specifying it. Why wouldn't it be in the config file? Why the asymetry here? From no.email at nospam.invalid Wed Feb 3 08:04:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 05:04:03 -0800 Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <7xtytyzd18.fsf@ruckus.brouhaha.com> News123 writes: > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) If they are running on the same host with no untrusted local users, you can use unix-domain sockets instead of TCP sockets and then the server should be unreachable from the internet. Then you're less exposed to possible security issues with libraries like Pyro. Personally I've just used SocketServer/SimpleHTTPServer on the listening side and simplejson for serialization, but that was for low-rent, low-performance applications. If you want something faster, zeromq (www.zeromq.org) looks interesting. From no.email at nospam.invalid Wed Feb 3 08:07:28 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 05:07:28 -0800 Subject: Dreaming of new generation IDE References: Message-ID: <7xpr4mzcvj.fsf@ruckus.brouhaha.com> Vladimir Ignatov writes: > I notice however, that "maintaining" existing/older python code is may > be not so enjoyable task. It may be even harder than supporting old > code written in some type of "static" languages (like Java or C++). > Surely "dynamic" nature of python comes with price. Yes, this is a well known drawback of dynamic typing. The usual remedy is lots and lots of test automation (a full suite of unit and integration tests that you run on every build, that check the properties of basically every function in your program). > Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems I've never used a current CAD system, so I can't make any sense of this. I don't see how databases would help. From stefan_ml at behnel.de Wed Feb 3 08:16:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Feb 2010 14:16:45 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <7xpr4mzcvj.fsf@ruckus.brouhaha.com> References: <7xpr4mzcvj.fsf@ruckus.brouhaha.com> Message-ID: <4b69773e$0$6577$9b4e6d93@newsspool3.arcor-online.net> Paul Rubin, 03.02.2010 14:07: >> Instead of current text-oriented IDEs, it >> should be a database-centric and resemble current CAD systems > > I've never used a current CAD system, so I can't make any sense of this. > I don't see how databases would help. Just like they help in current IDEs to index the source code. Stefan From awilliam at opengroupware.us Wed Feb 3 08:18:40 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Wed, 03 Feb 2010 08:18:40 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <1265203120.7916.5.camel@linux-m3mt> On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: > Hello, > I am sitting here for quite some time, but usually keep silent ;-) I > use Python since 2003 both "professionally" and for my hobby projects > and love it a much. > I notice however, that "maintaining" existing/older python code is may > be not so enjoyable task. It may be even harder than supporting old > code written in some type of "static" languages (like Java or C++). > Surely "dynamic" nature of python comes with price. Yes, it certainly does. Not that you'll get many Pythonistas to confess to that fact. Somehow those who brag about the readability and expressiveness of source code just cannot admit that: class.method(sting name, int count) - is *obviously* more expressive than - class.method(name, count) Oh, well. This is obvious even in the Python documentation itself where one frequently asks oneself "Uhh... so what is parameter X supposed to be... a string... a list... ?" Not knocking Python; Python is great. I maintain a rapidly growing Python code base. But the above is almost comically funny sometimes [sand.insert_head(pythonista)]. > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. Ugh, please NO! This has been attempted many many times in many environments - it always fails *terribly*. > Well. I understand that it is a very ambitious and experimental stuff. > Great efforts and motivation needed even to get something "runnable". > So I am looking for someone to get in kind of "virtual partnership". > If someone interesting it that soft of stuff, I would like to talk and > discuss this system. From jeanmichel at sequans.com Wed Feb 3 08:32:01 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 03 Feb 2010 14:32:01 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <6B7EE46E-CECB-42CB-AA6B-5986E1A2210D@masklinn.net> References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> <4B6954EB.6010004@sequans.com> <6B7EE46E-CECB-42CB-AA6B-5986E1A2210D@masklinn.net> Message-ID: <4B697AD1.8070602@sequans.com> Masklinn wrote: > On 3 Feb 2010, at 11:50 , Jean-Michel Pichavant wrote: > >> You don't neeed to check the code for that ! It is written in the documentation. The logging module designer choose to ask for a level, not a level name, possibly because 2 different levels can have the same name. >> >> > Nope, 2 different levels cannot have the same name: levels are currently stored in a dict of string:level and level:string, so you can't have 2 names for the same level, and you can't have 2 levels with the same name either. > > import logging logging.addLevelName(5, 'test') logging.addLevelName(6, 'test') logging._levelNames {0: 'NOTSET', 5: 'test', 6: 'test', 10: 'DEBUG', 20: 'INFO', 30: 'WARNING', 40: 'ERROR', 50: 'CRITICAL', 'CRITICAL': 50, 'DEBUG': 10, 'ERROR': 40, 'INFO': 20, 'NOTSET': 0, 'WARN': 30, 'WARNING': 30, 'test': 6} now quoting the doc: logging.addLevelName(/lvl/, /levelName/) Associates level /lvl/ with text /levelName/ in an internal dictionary, which is *used to map numeric levels to a textual representation*, for example when a Formatter formats a message. This function can also be used to define your own levels. The only constraints are that all levels used must be registered using this function, levels should be positive integers and they should increase in increasing order of severity. int -> string is the public association string- > int is an internal hack to map easilty map Level name to their int identifier. This is used for the config file, where you specify a string not an int (you vrite level=DEBUG, not level=10) Look at the builtin WARNING & WARN level, two different names for the same level. In any case, you have to trust the documentation and public interface signature. Introspecting the code can be misleading. Now I better understand your initial concern. >>>> the field handlers must be defined even if empty. >>>> >>>> >>> Ah, interesting, I didn't think it could be defined as empty. >>> >>> Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? >>> >> 'completeley nonsensical' is overstating. It make sense to state that your handler list is empty, when it is empty. >> > Programmatically, that's implied in the fact that you aren't specifying it. Why wouldn't it be in the config file? Why the asymetry here? > > Note how progammatically the list of handlers is set to an empty list. The attribute handlers is always set, so the config file field shall be :o) In [11]: logger = logging.getLogger('test') In [12]: logger.handlers Out[12]: [] JM From stefan_ml at behnel.de Wed Feb 3 08:35:41 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Feb 2010 14:35:41 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <4b697bae$0$6587$9b4e6d93@newsspool3.arcor-online.net> Adam Tauno Williams, 03.02.2010 14:18: > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" > > Not knocking Python; Python is great. I maintain a rapidly growing > Python code base. But the above is almost comically funny sometimes > [sand.insert_head(pythonista)]. So, what's "pythonista" in the above? A dummy? Stefan From jeanmichel at sequans.com Wed Feb 3 08:51:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 03 Feb 2010 14:51:46 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <4B697F72.30609@sequans.com> Adam Tauno Williams wrote: > Yes, it certainly does. Not that you'll get many Pythonistas to confess > to that fact. Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: > > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) > > class.method(string name, int count): """Return the cap'tain's age. name: a string giving the name of the cap'tain daughter count: an int giving the number of fingers left in the cap'tain right hand """ In python, attributes/parameters have no type (but you know that). By specifying them in the method signature, you're just duplicating the information hold in the docstring. JM From no.email at please.post Wed Feb 3 08:52:03 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 13:52:03 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: Steve, I apologize for the snarkiness of my previous reply to you. After all, I started the thread by asking the forum for advice on how to avoid a certain kind of bugs, you were among those who gave me advice. So nothing other than thanking you for it was in order. I just let myself get carried away by my annoyance with the Python import scheme. I'm sorry about it. Even though I don't think I can put to practice all of your advice, I can still learn a good deal from it. Cheers, ~kj Steve Holden writes: >kj wrote: >> >>> First, I don't shadow built in modules. Its really not very hard to avoid. >> >> ...*if* you happen to be clairvoyant. I still don't see how the rest of us >> could have followed this fine principle in the case of numbers.py >> prior to Python 2.6. >> >Clearly the more you know about the standard library the less likely >this is to be a problem. Had you been migrqating from an earlier version > the breakage would have alerted you to look for some version-dependent >difference. From kmisoft at gmail.com Wed Feb 3 08:54:26 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 16:54:26 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" Exactly. Often I don't need to know the exact type, but to figure out that "kind of type" it is. >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > Ugh, please NO! ?This has been attempted many many times in many > environments - it always fails *terribly*. Can you give some examples of such systems? (maybe just names for googling for) I don't see anything dirt in storing some additional meta-information about the code under development and using it later for all kind of benefits (easy refactoring for example). As with your example with "parameter x", some additional information can be "attached" to this paramer. Later it can be used during code-generation phase and placed as "comment" in source code or placed in popup tag in html-style presentation. Vladimir Ignatov From marco.salden at gmail.com Wed Feb 3 09:18:40 2010 From: marco.salden at gmail.com (Marco Salden) Date: Wed, 3 Feb 2010 06:18:40 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: On Feb 3, 12:10?pm, Vladimir Ignatov wrote: > Hello, > > I am sitting here for quite some time, but usually keep silent ;-) I > use Python since 2003 both "professionally" and for my hobby projects > and love it a much. > I notice however, that "maintaining" existing/older python code is may > be not so enjoyable task. It may be even harder than supporting old > code written in some type of "static" languages (like Java or C++). > Surely "dynamic" nature of python comes with price. > > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. > > Well. I understand that it is a very ambitious and experimental stuff. > Great efforts and motivation needed even to get something "runnable". > So I am looking for someone to get in kind of "virtual partnership". > If someone interesting it that soft of stuff, I would like to talk and > discuss this system. > > Vladimir Ignatov The maintenance thing may be true but for me that doesn't outweigh the clear benefits I get from using Python i.s.o. e.g. C++: the fact that I have much less code that is more compact and for me more directly readable is a clear advantage when doing maintance on code I didnt touch for a while. Documenting the essential parameters used with some examples and some logging helps (for me at least...). The type of IDE you are looking for is more something like Rational Rose (e.g. RRT?) type of tooling perhaps? There you "CAD" components and their statebehavior and the system generates C or C++ code. Regards, Marco From no.email at nospam.invalid Wed Feb 3 09:42:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 06:42:52 -0800 Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <7x4olys7mb.fsf@ruckus.brouhaha.com> Jean-Michel Pichavant writes: > class.method(string name, int count): > """Return the cap'tain's age. > > name: a string giving the name of the cap'tain daughter > count: an int giving the number of fingers left in the cap'tain > right hand > """ > > In python, attributes/parameters have no type (but you know that). By > specifying them in the method signature, you're just duplicating the > information hold in the docstring. It's not enough to just document (except as an aid to remembering) since the compiler and runtime don't enforce the documentation. You have to use static typing or write tests, to flag all the call sites if you change the signature. One nice trick with static types is if you change what the method does (even if its type signature doesn't change), you can rename the method: class.method2(string name, int count): # change 'method' to 'method2' and recompile your codebase. Every place in the code that called 'method' now gets a compile time "undefined method" error that you can examine to see if you need to update it. This is something you can't catch with unit tests because the call sites can be in distant modules. From kmisoft at gmail.com Wed Feb 3 09:58:25 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 17:58:25 +0300 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: > The maintenance thing may be true but for me that doesn't outweigh the > clear benefits I get from using Python i.s.o. e.g. C++: the fact that > I have much less code that is more compact and for me more directly > readable is a clear advantage when doing maintance on code I didnt > touch for a while. Documenting the essential parameters used with some > examples and some logging helps (for me at least...). Python is very easy to write. But with code grow and time passes, things get worse. Currently I tries to reanimate one of my old freeware project and faced it again. > The type of IDE you are looking for is more something like Rational > Rose (e.g. RRT?) type of tooling perhaps? There you "CAD" components > and their statebehavior and the system generates C or C++ code. Perhaps. I newer use Rational Rose but hear about it. But I use some other Rational* products and they scare me a lot. So maybe Rose can be used for "inspiration" but not much more. Actually I don't want to put programmer in GUI-fashioned env. with a lot of buttons and switches. I think about "classic" text-like view but that actually "understands" that are you doing (typing) on. So your types goes in "datastore" first and then renders back as a text representation. Something like this. Vladimir Ignatov From nobody at nowhere.com Wed Feb 3 10:03:22 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Feb 2010 15:03:22 +0000 Subject: Need help with a program References: <96db4cd6-bda3-42db-a592-83d72e517e2d@28g2000vbf.googlegroups.com> <4B61CE0E.5000801@sequans.com> Message-ID: On Tue, 02 Feb 2010 15:07:05 -0800, Aahz wrote: >>If you have a problem and you think that regular expressions are the >>solution then now you have two problems. Regex is really overkill for >>the OP's problem and it certainly doesn't improve readability. > > If you're going to use a quote, it works better if you use the exact > quote and attribute it: > > 'Some people, when confronted with a problem, think "I know, I'll use > regular expressions." Now they have two problems.' --Jamie Zawinski He may have mixed that one up with a different (and more generic) saying: "If you think that X is the solution to your problem, then you don't understand X and you don't understand your problem." For most values of X. From stef.mientki at gmail.com Wed Feb 3 10:23:00 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 3 Feb 2010 16:23:00 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> > Yes, it certainly does. Not that you'll get many Pythonistas to confess > to that fact. Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: > > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) > > Oh, well. > > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" > > But I thought that was the one of beauties of Python, you don't need to know if the input parameter is a list or a string. cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From cournape at gmail.com Wed Feb 3 10:24:00 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 4 Feb 2010 00:24:00 +0900 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <5b8d13221002030724m109e6d9fubd35c9f4a20b8a94@mail.gmail.com> On Wed, Feb 3, 2010 at 10:18 PM, Adam Tauno Williams wrote: > On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: >> Hello, >> I am sitting here for quite some time, but usually keep silent ;-) I >> use Python since 2003 both "professionally" and for my hobby projects >> and love it a much. >> I notice however, that "maintaining" existing/older python code is may >> be not so enjoyable task. It may be even harder than supporting old >> code written in some type of "static" languages (like Java or C++). >> Surely "dynamic" nature of python comes with price. > > Yes, it certainly does. ?Not that you'll get many Pythonistas to confess > to that fact. ?Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: Static typing sounds "obviously" better only if you assume everything else being equal. But the typing system also often goes in the way when developing large codebases, when you need to refactor things, etc... So if for a *given* codebase, you get type information, it is almost certainly very helpful. But when you need to change this codebase, maybe not so much. There was a nice paper from people at Adobe which mentioned this very aspect, focusing on how to maintain a significant codebase, from prototype-kind of development to maintenance-kind of development: http://www.ecmascript.org/es4/spec/evolutionary-programming-tutorial.pdf. It strikes me as a good way to look at this tradeoff between static and dynamic typing, where the dynamic typing for some "mostly frozen" code areas has diminishing returns, David From stef.mientki at gmail.com Wed Feb 3 10:28:19 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 3 Feb 2010 16:28:19 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric I don't see what the advantage of the use of a database is in a fairly linear hierarchical structure like python objects and modules. and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. > You mean something like LabView ? cheers, Stef (btw, my dreams ends up in the same needs) -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at opengroupware.us Wed Feb 3 10:39:53 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Wed, 03 Feb 2010 10:39:53 -0500 Subject: Dreaming of new generation IDE In-Reply-To: <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> References: <1265203120.7916.5.camel@linux-m3mt> <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> Message-ID: <1265211593.7916.12.camel@linux-m3mt> On Wed, 2010-02-03 at 16:23 +0100, Stef Mientki wrote: > Yes, it certainly does. Not that you'll get many Pythonistas > to confess > to that fact. Somehow those who brag about the readability > and > expressiveness of source code just cannot admit that: > class.method(sting name, int count) > - is *obviously* more expressive than - > class.method(name, count) > Oh, well. > This is obvious even in the Python documentation itself where > one > frequently asks oneself "Uhh... so what is parameter X > supposed to be... > a string... a list... ?" > But I thought that was the one of beauties of Python, you don't need > to know if the input parameter is a list or a string. You don't need to know; unless of course you want the expected result. From kmisoft at gmail.com Wed Feb 3 10:48:12 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 18:48:12 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: > I don't see what the advantage of the use of a database is in a fairly > linear hierarchical structure like python objects and modules. Imagine simple operation like "method renaming" in a simple "dumb" environment like text editor + grep. Now imagine how simple it can be if system "knows" all your identifiers and just regenerates relevant portions of text from internal database-alike representation. > You mean something like LabView ? No, I don't think so. I never use LabView but imagine it something very "graphical-oriented". No, I think about more "classic" text view. But back-ended with "smart" underlying system - not just obvious "text". Vladimir Ignatov From wanderer at dialup4less.com Wed Feb 3 10:49:44 2010 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 3 Feb 2010 07:49:44 -0800 (PST) Subject: Background Zones in Pylab Plot Message-ID: <1eaf6046-db41-44b5-8c9e-b7a15e4cf078@30g2000vbj.googlegroups.com> I would like to add background zones in pylab plots. Colored sections of the background that the curves pass through. Is this possible? My google searches don't turn up anything but maybe my search terms aren't the right ones. Thanks From banibrata.dutta at gmail.com Wed Feb 3 10:50:16 2010 From: banibrata.dutta at gmail.com (banibrata.dutta at gmail.com) Date: Wed, 03 Feb 2010 15:50:16 +0000 Subject: Dreaming of new generation IDE Message-ID: <4b699c58.11435e0a.1137.01ea@mx.google.com> -----Original Message----- From: Vladimir Ignatov Sent: 03/02/2010 7:24:26 pm Subject: Re: Dreaming of new generation IDE > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" Exactly. Often I don't need to know the exact type, but to figure out that "kind of type" it is. >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > Ugh, please NO! ?This has been attempted many many times in many > environments - it always fails *terribly*. Can you give some examples of such systems? (maybe just names for googling for) I don't see anything dirt in storing some additional meta-information about the code under development and using it later for all kind of benefits (easy refactoring for example). As with your example with "parameter x", some additional information can be "attached" to this paramer. Later it can be used during code-generation phase and placed as "comment" in source code or placed in popup tag in html-style presentation. BD> probably close to Java annotations perhaps? And as for the CAD approach, would a UML reverse engg tool help ? If yes, perhaps you could give BOUML a shot. Regards, Banibrata From nobody at nowhere.com Wed Feb 3 10:50:56 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Feb 2010 15:50:56 +0000 Subject: converting XML to hash/dict/CustomTreeCtrl References: <4B6756FE.9060206@al.com.au> Message-ID: On Wed, 03 Feb 2010 08:07:50 +1100, Astan Chee wrote: > Sorry for being vague but here my question about converting an xml into > a dict. I found some examples online but none gives the dict/result I > want. > Which is kinda wrong. I expect the dict to have the "Space usage > summary", but it doesn't (duplicate?). What am I doing wrong here? > I am attempting to keep the attribute value of an XML as key (if it > doesn't have a value, then just the tag name will do) and associate it > with the text value of that tag/attribute value as well as reflecting > the hierarchy structure of the XML in the dict. Does this make sense? > Anyway, the python script above is just the first step or an example for me. The code you're using expects the XML to follow a particular format, and yours doesn't. You might want to start with a fairly direct translation, e.g.: def xmldict(e): d = {} d['tag'] = e.tag d.update(e.attrib) children = map(xmldict, e) if children: d['children'] = children text = e.text.strip() if text: d['text'] = text return d tree = ElementTree.parse('test.xml') root = tree.getroot() d = xmldict(root) pprint.pprint(d) then refine this as needed. From stef.mientki at gmail.com Wed Feb 3 10:52:52 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Feb 2010 16:52:52 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: <4B699BD4.1010703@gmail.com> On 03-02-2010 16:48, Vladimir Ignatov wrote: >> I don't see what the advantage of the use of a database is in a fairly >> linear hierarchical structure like python objects and modules. >> > Imagine simple operation like "method renaming" in a simple "dumb" > environment like text editor + grep. Now imagine how simple it can be > if system "knows" all your identifiers and just regenerates relevant > portions of text from internal database-alike representation. > I think every IDE (not older than 20 years) does that already. cheers, Stef From no.email at please.post Wed Feb 3 11:17:52 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 16:17:52 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: In kj writes: >Steve, I apologize for the snarkiness of my previous reply to you. >After all, I started the thread by asking the forum for advice on >how to avoid a certain kind of bugs, you were among those who gave >me advice. So nothing other than thanking you for it was in order. >I just let myself get carried away by my annoyance with the Python >import scheme. I'm sorry about it. Even though I don't think I >can put to practice all of your advice, I can still learn a good >deal from it. Boy, that was dumb of me. The above apology was meant for Stephen Hansen, not Steve Holden. I guess this is now a meta-apology... (Sheesh.) ~kj From no.email at please.post Wed Feb 3 11:23:58 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 16:23:58 +0000 (UTC) Subject: test -- please ignore References: <87wryumvff.fsf@benfinney.id.au> Message-ID: In <87wryumvff.fsf at benfinney.id.au> Ben Finney writes: >kj writes: >> (my replies in a different comp.lang.python thread are getting >> rejected by the server; i have no problem posting to alt.test; and >> i'm trying to toubleshoot the problem further.) >Thank you for this explanation. It is important to know that you've >tried the less obtrusive diagnostics first. Good hunting. I figured out the immediate reason for the failure: when replying to *certain posts*, my newsreader omits the Newsgroups header from the response. Why it does this is still a mystery to me, but at least now I know what to look out for. Then again, I use the "venerable" (i.e. decrepit) nn as newsreader, so this discovery probably won't help many of those reading this... From mail at timgolden.me.uk Wed Feb 3 11:33:57 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 03 Feb 2010 16:33:57 +0000 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <4B69A575.2020604@timgolden.me.uk> On 03/02/2010 16:17, kj wrote: > Boy, that was dumb of me. The above apology was meant for Stephen > Hansen, not Steve Holden. I guess this is now a meta-apology... > (Sheesh.) You see? That's what I like about the Python community: people even apologise for apologising :) TJG From casevh at gmail.com Wed Feb 3 11:37:36 2010 From: casevh at gmail.com (casevh) Date: Wed, 3 Feb 2010 08:37:36 -0800 (PST) Subject: ANN: GMPY 1.11 released References: Message-ID: On Feb 2, 10:03?pm, Mensanator wrote: > On Feb 2, 12:45?am, casevh wrote: > > > > > Everyone, > > > I'm pleased to annouce the final release of GMPY 1.11. > > GMPY is a wrapper for the MPIR or GMP multiple-precision > > arithmetic library. GMPY 1.11 is available for download from: > > >http://code.google.com/p/gmpy/ > > > In addition to support for Python 3.x, there are several new > > features in this release: > > > - Even faster conversion to/from Python longs. > > - Performance improvements by reducing function overhead. > > - Performance improvements by improved caching. > > - Support for cdivmod, fdivmod, and tdivmod. > > - Unicode strings are accepted on Python 2.x and 3.x. > > - Fixed regression in GMPY 1.10 where True/False were no > > ? longer recognized. > > > Changes since 1.11rc1: > > - Recognizes GMP 5. > > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > > Comments on provided binaries > > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > > 1.3.1 and will automatically recognize the CPU type and use code > > optimized for the CPU at runtime. The 64-bit Windows installers were > > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > > instructions are included if you want to compile your own binary. > > > Please report any issues! > > My previous replies didn't show up. Something to do the .announce > group? I'll trim that and try again. Sorry if they show up eventually. > > Two issues: > > 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply > > >>> gmpy.version() > > '1.11' > > Aren't these different versions? How are we supposed to tell them > apart? Check the name of source tarball? gmpy._cvsid() will return the internal source code revision number. The changes made in each revision number are listed at http://code.google.com/p/gmpy/source/list. I know some applications check gmpy.version(). I don't know if they'll work if the format of the string changes. > > 2] Is it true that the only changes since 1.11rc1 are not > ? ?applicable to me since > > ? ?- I'm not using Windows > ? ?- whether it recognizes GMP 5 is moot as GMP 5 cannot be > ? ? ?compiled on a Mac (according to GMP site) Yes. The only change for GMP 5 was to recognize the new version number when running the tests. > > Is it possible GMP's problems with getting GMP 5 to compile > are the same ones I had with 3.1 on Snow Leopard? (They bemoan > not having a set of every Mac system.) Think it would behoove > me to try it? According to comments on GMP's mailing list, the latest snapshot should work. ftp://ftp.gmplib.org/pub/snapshot/ > > > > > casevh > > From aahz at pythoncraft.com Wed Feb 3 11:38:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2010 08:38:47 -0800 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: > > I shall blaspheme, and suggest that maybe the language you want to >use is REXX (ooREXX or Regina). > > By default, ANY statement that can not be confused for a REXX >language statement is sent to the currently defined command handler >(Which on most OSs is equivalent to Python's os.system() call; the late >Amiga, and IBM's mainframe OS had features that support defining other >applications as command handlers). How is that different from bash scripting? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Wed Feb 3 11:40:59 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2010 08:40:59 -0800 Subject: test -- please ignore References: <87wryumvff.fsf@benfinney.id.au> Message-ID: In article , kj wrote: > >I figured out the immediate reason for the failure: when replying >to *certain posts*, my newsreader omits the Newsgroups header from >the response. Why it does this is still a mystery to me, but at >least now I know what to look out for. Then again, I use the >"venerable" (i.e. decrepit) nn as newsreader, so this discovery >probably won't help many of those reading this... Perhaps it's similar to problems in the even-more-venerable trn3.6 that come from excessively long References: headers? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From nobody at nowhere.com Wed Feb 3 11:55:40 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Feb 2010 16:55:40 +0000 Subject: How to guard against bugs like this one? References: Message-ID: On Tue, 02 Feb 2010 10:38:53 -0800, Carl Banks wrote: >> I don't know if that's necessary. Only supporting the "foo.h" case would >> work fine if Python behaved like gcc, i.e. if the "current directory" >> referred to the directory contain the file performing the import rather >> than in the process' CWD. >> >> As it stands, imports are dynamically scoped, when they should be >> lexically scoped. > > Mostly incorrect. The CWD is in sys.path only for interactive > sessions, and when started with -c switch. When running scripts, the > directory where the script is located is used instead, not the > process's working directory. Okay, so s/CWD/directory containing __main__ script/, but the general argument still holds. > So, no, it isn't anything like dynamic scoping. That's what it looks like to me. The way that an import name is resolved depends upon the run-time context in which the import occurs. >> The only situation where the process' CWD should be used is for an import >> statement in a non-file source (i.e. stdin or the argument to the -c >> switch). > > It already is that way, chief. > > I think you're misunderstanding what's wrong here; the CWD doesn't > have anything to do with it. Even if CWD isn't in the path you still > get the bad behavior kj noted. So now what? Search for imports first in the directory containing the file performing the import. This is essentially the situation with gcc; the directory containing the current file takes precedence over directories specified by -I switches. If you want to override this, you have to use the -I- switch, which makes it very unlikely to happen by accident. From kmisoft at gmail.com Wed Feb 3 12:21:20 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 20:21:20 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <4B699BD4.1010703@gmail.com> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <4B699BD4.1010703@gmail.com> Message-ID: >> Imagine simple operation like "method renaming" in a simple "dumb" >> environment like text editor + grep. Now imagine how simple it can be >> if system "knows" all your identifiers and just regenerates relevant >> portions of text from internal database-alike representation. >> > > I think every IDE (not older than 20 years) does that already. And fix every reference to it in all files? For python? I don't think so. I even don't think this is possible at all. That if several different objects have a similar named method? How will IDE "classify" calls and renames only some of calls and not others? Vladimir Ignatov From tinnews at isbd.co.uk Wed Feb 3 12:33:21 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 3 Feb 2010 17:33:21 +0000 Subject: test -- please ignore References: <87wryumvff.fsf@benfinney.id.au> Message-ID: <1koo37-18b.ln1@chris.isbd.net> kj wrote: > In <87wryumvff.fsf at benfinney.id.au> Ben Finney writes: > > >kj writes: > > >> (my replies in a different comp.lang.python thread are getting > >> rejected by the server; i have no problem posting to alt.test; and > >> i'm trying to toubleshoot the problem further.) > > >Thank you for this explanation. It is important to know that you've > >tried the less obtrusive diagnostics first. Good hunting. > > I figured out the immediate reason for the failure: when replying > to *certain posts*, my newsreader omits the Newsgroups header from > the response. Why it does this is still a mystery to me, but at > least now I know what to look out for. Then again, I use the > "venerable" (i.e. decrepit) nn as newsreader, so this discovery > probably won't help many of those reading this... I used to use nn, now I use tin which is fairly similar and still being maintained. -- Chris Green From cp.astolfi at gmail.com Wed Feb 3 12:47:08 2010 From: cp.astolfi at gmail.com (Cpa) Date: Wed, 3 Feb 2010 09:47:08 -0800 (PST) Subject: Trouble with os.system Message-ID: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> Hi there, I'm having some trouble with os.system on Fedora 12. I have a bunch of .tex files in tmp/ and I want to compile them. In my shell, the following commands work perfectly : 'for file in tmp/ *.tex; do pdflatex "$file"; done'. But if I use the same command using os.system(), it will compile correctly every file except the last one, for which it raises an error (I get a prompt, as if I did a syntax error in tex document). I suspected some kind of escaping issue, but it won't even work with files such as : foo.txt, bar.txt. Any idea ? Thanks, Cpa From gerald.britton at gmail.com Wed Feb 3 12:54:20 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 3 Feb 2010 12:54:20 -0500 Subject: Trouble with os.system In-Reply-To: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> Message-ID: <5d1a32001002030954t7768a374l9cfcf5127c56f4d7@mail.gmail.com> Can you post your code? On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: > Hi there, > > I'm having some trouble with os.system on Fedora 12. > I have a bunch of .tex files in tmp/ and I want to compile them. > In my shell, the following commands work perfectly : 'for file in tmp/ > *.tex; do pdflatex "$file"; done'. > > But if I use the same command using os.system(), it will compile > correctly every file except the last one, for which it raises an error > (I get a prompt, as if I did a syntax error in tex document). > > I suspected some kind of escaping issue, but it won't even work with > files such as : foo.txt, bar.txt. > > Any idea ? > Thanks, > Cpa > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From cp.astolfi at gmail.com Wed Feb 3 12:58:43 2010 From: cp.astolfi at gmail.com (Cpa) Date: Wed, 3 Feb 2010 09:58:43 -0800 (PST) Subject: Trouble with os.system References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> Message-ID: <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Sure. import sys,re,os files2create = sys.argv[1:] os.system('mkdir tmp') # Some code to create the .tex # Compile tex files os.system('for file in tmp/*; do pdflatex "$file"; done') Pretty simple, alas. -- Cpa On 3 f?v, 18:54, Gerald Britton wrote: > Can you post your code? > > > > On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: > > Hi there, > > > I'm having some trouble with os.system on Fedora 12. > > I have a bunch of .tex files in tmp/ and I want to compile them. > > In my shell, the following commands work perfectly : 'for file in tmp/ > > *.tex; do pdflatex "$file"; done'. > > > But if I use the same command using os.system(), it will compile > > correctly every file except the last one, for which it raises an error > > (I get a prompt, as if I did a syntax error in tex document). > > > I suspected some kind of escaping issue, but it won't even work with > > files such as : foo.txt, bar.txt. > > > Any idea ? > > Thanks, > > Cpa > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > Gerald Britton From alan at baselinedata.co.uk Wed Feb 3 13:01:14 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Wed, 03 Feb 2010 18:01:14 +0000 Subject: Passing parameters in URL Message-ID: <4B69B9EA.1040503@baselinedata.co.uk> I have a web-page where each row in a grid has edit/delete buttons to enable the user to maintain a selected record on another page. The buttons are in the form of a link with href='/item_edit?id=123', but this string appears in the URL and gives clues as to how to bypass the correct sequence of events, and could be risky if they entered the URL directly (especially when it comes to deleting records). Is there another way of passing a record-id to a method a) without it appearing in the URL? b) without the user being able to fathom-out how to attach which id to which URL? As each link contains row-id, I guess there is nothing to stop someone from getting the id from the page source-code. Is it safe to use the above href method if I test for authorised credentials (user/password stored as session variables, perhaps?) before performing the edit/delete action? I am currently using CherryPy 3.2, but I guess the theory could apply to any HTTP framework or web app.. Any help would be appreciated. Alan Harris-Reid From phlip2005 at gmail.com Wed Feb 3 13:05:30 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 10:05:30 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> On Feb 3, 3:10?am, Vladimir Ignatov wrote: > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. That's fine so long as I can also treat the source as source, at need. You may have just reinvented Smalltalk's Squeak editor (reputedly the testbed for all of modern GUIs...). Current editors suck because they can't see into the code and browse it - unless it's so statically typed it's painful. That's why I wrote this: http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html From gerald.britton at gmail.com Wed Feb 3 13:08:53 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 3 Feb 2010 13:08:53 -0500 Subject: Trouble with os.system In-Reply-To: <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Message-ID: <5d1a32001002031008o332c5da9i580f023270a84ba7@mail.gmail.com> It kinda worked for me but I had to change it a little: os.system('for file in /tmp/*.tex; do pdflatex "$file"; done') Maybe you're picking up other files in /tmp that are not .tex files? On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: > Sure. > > import sys,re,os > files2create = sys.argv[1:] > os.system('mkdir tmp') > > # Some code to create the .tex > > # Compile tex files > os.system('for file in tmp/*; do pdflatex "$file"; done') > > Pretty simple, alas. > > -- > Cpa > > > On 3 f?v, 18:54, Gerald Britton wrote: >> Can you post your code? >> >> >> >> On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: >> > Hi there, >> >> > I'm having some trouble with os.system on Fedora 12. >> > I have a bunch of .tex files in tmp/ and I want to compile them. >> > In my shell, the following commands work perfectly : 'for file in tmp/ >> > *.tex; do pdflatex "$file"; done'. >> >> > But if I use the same command using os.system(), it will compile >> > correctly every file except the last one, for which it raises an error >> > (I get a prompt, as if I did a syntax error in tex document). >> >> > I suspected some kind of escaping issue, but it won't even work with >> > files such as : foo.txt, bar.txt. >> >> > Any idea ? >> > Thanks, >> > Cpa >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> -- >> Gerald Britton > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From john at castleamber.com Wed Feb 3 13:11:33 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 12:11:33 -0600 Subject: Passing parameters in URL References: Message-ID: <878wbafaui.fsf@castleamber.com> Alan Harris-Reid writes: > I have a web-page where each row in a grid has edit/delete buttons to > enable the user to maintain a selected record on another page. The > buttons are in the form of a link with href='/item_edit?id=123', but > this string appears in the URL and gives clues as to how to bypass the > correct sequence of events, and could be risky if they entered the URL > directly (especially when it comes to deleting records). You should *never* use a GET request to do actions like deleting records. You already are aware of it being risky, so don't do this. You should use GET for getting information, and POST for modifying information. > Is there another way of passing a record-id to a method > a) without it appearing in the URL? Use a POST request. Note that the user still has to select something, and that this information is send by the browser, and hence the user can see this information (and maybe others), and repeat the action with, for example, a Python program. > b) without the user being able to fathom-out how to attach which id to > which URL? I am not sure what you want to prevent here. If you're afraid that user A can delete things that belong user B, than "hiding" things or making them "hard to guess" are not going to help much. If you have several users, you must use some login procedure (and sessions). > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the > edit/delete action? Yes. But still make sure that session ids are not easy to guess, and expire. And make very sure that session ids can't leak to others. Moreover, each time you modify a database use POST. One could argue to also use POST for logging out, otherwise another site might be able to log your users out if they visit that site. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From no.email at nospam.invalid Wed Feb 3 13:12:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 10:12:48 -0800 Subject: Passing parameters in URL References: Message-ID: <7xwryudw7z.fsf@ruckus.brouhaha.com> Alan Harris-Reid writes: > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the > edit/delete action? Well, if it's really ok for them to delete records programmatically even if it's ok for them to delete through the web site. I'd probably encrypt the post parameters if this was a concern. From mensanator at aol.com Wed Feb 3 13:22:22 2010 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Feb 2010 10:22:22 -0800 (PST) Subject: ANN: GMPY 1.11 released References: Message-ID: <3cdf9936-035f-43db-abb0-a7daacac14ab@o28g2000yqh.googlegroups.com> On Feb 3, 10:37?am, casevh wrote: > On Feb 2, 10:03?pm, Mensanator wrote: > > > > > > > On Feb 2, 12:45?am, casevh wrote: > > > > Everyone, > > > > I'm pleased to annouce the final release of GMPY 1.11. > > > GMPY is a wrapper for the MPIR or GMP multiple-precision > > > arithmetic library. GMPY 1.11 is available for download from: > > > >http://code.google.com/p/gmpy/ > > > > In addition to support for Python 3.x, there are several new > > > features in this release: > > > > - Even faster conversion to/from Python longs. > > > - Performance improvements by reducing function overhead. > > > - Performance improvements by improved caching. > > > - Support for cdivmod, fdivmod, and tdivmod. > > > - Unicode strings are accepted on Python 2.x and 3.x. > > > - Fixed regression in GMPY 1.10 where True/False were no > > > ? longer recognized. > > > > Changes since 1.11rc1: > > > - Recognizes GMP 5. > > > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > > > Comments on provided binaries > > > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > > > 1.3.1 and will automatically recognize the CPU type and use code > > > optimized for the CPU at runtime. The 64-bit Windows installers were > > > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > > > instructions are included if you want to compile your own binary. > > > > Please report any issues! > > > My previous replies didn't show up. Something to do the .announce > > group? I'll trim that and try again. Sorry if they show up eventually. > > > Two issues: > > > 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply > > > >>> gmpy.version() > > > '1.11' > > > Aren't these different versions? How are we supposed to tell them > > apart? > > Check the name of source tarball? > > gmpy._cvsid() will return the internal source code revision number. > The changes made in each revision number are listed athttp://code.google.com/p/gmpy/source/list. So, '$Id: gmpy.c 237 2010-01-10 03:46:37Z casevh $' would be Revision 237 on that source list? > > I know some applications check gmpy.version(). I don't know if they'll > work if the format of the string changes. Then gmpy.version() isn't really intended to be a version per se, it's just a level of compatibility for those programs that care? > > > > > 2] Is it true that the only changes since 1.11rc1 are not > > ? ?applicable to me since > > > ? ?- I'm not using Windows > > ? ?- whether it recognizes GMP 5 is moot as GMP 5 cannot be > > ? ? ?compiled on a Mac (according to GMP site) > > Yes. The only change for GMP 5 was to recognize the new version number > when running the tests. Good. > > > > > Is it possible GMP's problems with getting GMP 5 to compile > > are the same ones I had with 3.1 on Snow Leopard? (They bemoan > > not having a set of every Mac system.) Think it would behoove > > me to try it? > > According to comments on GMP's mailing list, the latest snapshot > should work.ftp://ftp.gmplib.org/pub/snapshot/ > I'll have to see if I can get it to work this weekend. I sure hope I don't muck it up after after all the trouble I had getting the previous one to work. Thanks for the links. > > > > > > > casevh From python-url at phaseit.net Wed Feb 3 13:22:58 2010 From: python-url at phaseit.net (Gabriel Genellina) Date: Wed, 3 Feb 2010 18:22:58 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Feb 3) Message-ID: QOTW: "I think, in the spirit of the topic, they should hold it at both places at the same time." - Brian Blais, on whether the Python Concurrency Workshop, v2.0, should be in Chicago or Denver (in January!) The fastest way to consume an iterable until exhaustion: http://groups.google.com/group/comp.lang.python/t/c1ae3513a31eb63e/ When inheriting from a built-in class, it isn't obvious which of __new__ / __init__ should be overriden: http://groups.google.com/group/comp.lang.python/t/a453c65be4e0f355/ When importing a module, Python may pick the wrong one due to name clashes -- is this avoidable? http://groups.google.com/group/comp.lang.python/t/fe6430e7980e2a96/ Setting a default encoding for 'print' statements: http://groups.google.com/group/comp.lang.python/t/2fb77c8989f63f9d/ Despite its name, the iglob function (in module glob) isn't completely lazy: http://groups.google.com/group/comp.lang.python/t/d9a8617ec85e926d/ list.pop(0) has very poor performance; collections.deque works better in some cases; patch to allow lists to free elements from head (not just from tail): http://groups.google.com/group/comp.lang.python/t/9221d87f93748b3f/ How to parse ill-formed postal addresses: http://groups.google.com/group/comp.lang.python/t/76a4ab9fd7279a4e/ The future of Python 3: Adoption by Linux distros and package maintainers: http://groups.google.com/group/comp.lang.python/t/69463c4b9b1ecd8f/ Library support: http://groups.google.com/group/comp.lang.python/t/ae138cefffed0d6b/ Myths and fallacies: http://groups.google.com/group/comp.lang.python/t/8b8f4a9f999e33e8/ Why choose Python (and not Ruby) in an introductory course to programming: http://groups.google.com/group/comp.lang.python/t/dfe4f6c60032755e/ How an extension module (written in C) may perform cleaning tasks: http://groups.google.com/group/comp.lang.python/t/fbcb22b4401eaef1/ "Really, the built-in scope is just a built-in module called builtins, but you have to import builtins to query built-ins because the name builtins is not itself built-in..." (Lutz & Ascher, 'Programming Python') http://groups.google.com/group/comp.lang.python/t/dc719a4d922f2f87/ A new implementation of the GIL allows for much better performance in multicore architectures: http://groups.google.com/group/comp.lang.python/t/586ef2d3685fa7ea/ After a year of work with relative success, Unladen Swallow (a Google sponsored CPython improvement project) asks to be officially recognized: http://comments.gmane.org/gmane.comp.python.devel/109919 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From john at castleamber.com Wed Feb 3 13:24:43 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 12:24:43 -0600 Subject: Dreaming of new generation IDE References: Message-ID: <87zl3qdvo4.fsf@castleamber.com> Vladimir Ignatov writes: > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. Your idea is certainly not new. Moreover, I've been using such an IDE and implemented support for a (small) language in it: Programs are hierarchical compositions of formulae satisfying structural and extra-structural relationships. A program editor can use knowledge of such relationships to detect and provide immediate feedback about violations of them. The Synthesizer Generator is a tool for creating such editors from language descriptions. An editor designer specifies the desired relationships and the feedback to be given when they are violated, as well as a user interface; from the specification, the Synthesizer Generator creates a full-screen editor for manipulating programs in the language. http://portal.acm.org/citation.cfm?id=390010.808247 It might be a good start to read as much as possible on the Synthesizer Generator if you want to write such an IDE for Python. I am sure you could write such an IDE in the Synthesizer Generator, but I have no idea if it's still available. And back when I used it (at university) one had to pay for it, and most likely was closed source as well. See also: http://www.google.com/search?q=synthesizer%20generator -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From casevh at gmail.com Wed Feb 3 13:36:22 2010 From: casevh at gmail.com (casevh) Date: Wed, 3 Feb 2010 10:36:22 -0800 (PST) Subject: ANN: GMPY 1.11 released References: <3cdf9936-035f-43db-abb0-a7daacac14ab@o28g2000yqh.googlegroups.com> Message-ID: <167d472a-9981-4575-b463-a36413ed657e@x1g2000prb.googlegroups.com> On Feb 3, 10:22?am, Mensanator wrote: > On Feb 3, 10:37?am, casevh wrote: > > > > > On Feb 2, 10:03?pm, Mensanator wrote: > > > > On Feb 2, 12:45?am, casevh wrote: > > > > > Everyone, > > > > > I'm pleased to annouce the final release of GMPY 1.11. > > > > GMPY is a wrapper for the MPIR or GMP multiple-precision > > > > arithmetic library. GMPY 1.11 is available for download from: > > > > >http://code.google.com/p/gmpy/ > > > > > In addition to support for Python 3.x, there are several new > > > > features in this release: > > > > > - Even faster conversion to/from Python longs. > > > > - Performance improvements by reducing function overhead. > > > > - Performance improvements by improved caching. > > > > - Support for cdivmod, fdivmod, and tdivmod. > > > > - Unicode strings are accepted on Python 2.x and 3.x. > > > > - Fixed regression in GMPY 1.10 where True/False were no > > > > ? longer recognized. > > > > > Changes since 1.11rc1: > > > > - Recognizes GMP 5. > > > > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > > > > Comments on provided binaries > > > > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > > > > 1.3.1 and will automatically recognize the CPU type and use code > > > > optimized for the CPU at runtime. The 64-bit Windows installers were > > > > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > > > > instructions are included if you want to compile your own binary. > > > > > Please report any issues! > > > > My previous replies didn't show up. Something to do the .announce > > > group? I'll trim that and try again. Sorry if they show up eventually. > > > > Two issues: > > > > 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply > > > > >>> gmpy.version() > > > > '1.11' > > > > Aren't these different versions? How are we supposed to tell them > > > apart? > > > Check the name of source tarball? > > > gmpy._cvsid() will return the internal source code revision number. > > The changes made in each revision number are listed athttp://code.google.com/p/gmpy/source/list. > > So, '$Id: gmpy.c 237 2010-01-10 03:46:37Z casevh $' would be Revision > 237 > on that source list? > Correct. > > > > I know some applications check gmpy.version(). I don't know if they'll > > work if the format of the string changes. > > Then gmpy.version() isn't really intended to be a version per se, > it's just a level of compatibility for those programs that care? Historically, gmpy really didn't have alpha/beta/rc versions and gmpy.version() just had the version "number" and didn't indicate the status. If I change it, I'd rather go to "1.1.1rc1" or "1.2.0a0" but that might break some applications. > > > > > > 2] Is it true that the only changes since 1.11rc1 are not > > > ? ?applicable to me since > > > > ? ?- I'm not using Windows > > > ? ?- whether it recognizes GMP 5 is moot as GMP 5 cannot be > > > ? ? ?compiled on a Mac (according to GMP site) > > > Yes. The only change for GMP 5 was to recognize the new version number > > when running the tests. > > Good. > > > > > > Is it possible GMP's problems with getting GMP 5 to compile > > > are the same ones I had with 3.1 on Snow Leopard? (They bemoan > > > not having a set of every Mac system.) Think it would behoove > > > me to try it? > > > According to comments on GMP's mailing list, the latest snapshot > > should work.ftp://ftp.gmplib.org/pub/snapshot/ > > I'll have to see if I can get it to work this weekend. I sure hope I > don't muck it up after after all the trouble I had getting the > previous > one to work. > > Thanks for the links. > > > > > > > casevh > > From cp.astolfi at gmail.com Wed Feb 3 13:42:44 2010 From: cp.astolfi at gmail.com (Cpa) Date: Wed, 3 Feb 2010 10:42:44 -0800 (PST) Subject: Trouble with os.system References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Message-ID: <501794ef-bc0c-477f-a282-33b1d4a6c4af@z26g2000yqm.googlegroups.com> No, the tmp folder only contains files, and your modification still won't work for me. By the way I have the same error if I do: files2compile = os.listdir('./tmp/') for f in files2compile: os.system('pdflatex '+f) -- Cp On 3 f?v, 19:08, Gerald Britton wrote: > It kinda worked for me but I had to change it a little: > > os.system('for file in /tmp/*.tex; do pdflatex "$file"; done') > > Maybe you're picking up other files in /tmp that ?are not .tex files? > > > > On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: > > Sure. > > > import sys,re,os > > files2create = sys.argv[1:] > > os.system('mkdir tmp') > > > # Some code to create the .tex > > > # Compile tex files > > os.system('for file in tmp/*; do pdflatex "$file"; done') > > > Pretty simple, alas. > > > -- > > Cpa > > > On 3 f?v, 18:54, Gerald Britton wrote: > >> Can you post your code? > > >> On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: > >> > Hi there, > > >> > I'm having some trouble with os.system on Fedora 12. > >> > I have a bunch of .tex files in tmp/ and I want to compile them. > >> > In my shell, the following commands work perfectly : 'for file in tmp/ > >> > *.tex; do pdflatex "$file"; done'. > > >> > But if I use the same command using os.system(), it will compile > >> > correctly every file except the last one, for which it raises an error > >> > (I get a prompt, as if I did a syntax error in tex document). > > >> > I suspected some kind of escaping issue, but it won't even work with > >> > files such as : foo.txt, bar.txt. > > >> > Any idea ? > >> > Thanks, > >> > Cpa > >> > -- > >> >http://mail.python.org/mailman/listinfo/python-list > > >> -- > >> Gerald Britton > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > Gerald Britton From python at rcn.com Wed Feb 3 13:42:51 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Feb 2010 10:42:51 -0800 (PST) Subject: Selenium/SauceLabs OpenSpace at Pycon Message-ID: For those who are interested, the Sauce Labs team, http://saucelabs.com/about/team, is hosting two free tutorial open space sessions at Pycon in Atlanta. In the short session, people bringing their laptops should be able to record a web session in their browser, convert the recorded activity to a Python script, modify the script to accept a number of inputs , and replay the script locally on their laptops. Once you've learned how to fully automate your own browser, submit the same script to the Sauce Labs cloud to run the tests in parallel across multiple browsers and operating systems, and view the results with instant video playback. The tutorials should be of interest to web developers wanting fast, cross-browser testing and it should be of general interest to anyone wanting to use Python to automate browser sessions. The tutorials are being led by Jason Huggins, the creator of Selenium (an open source web app testing tool http://seleniumhq.org/ ). Several familiar names from the Python community will also be on-hand: http://saucelabs.com/about/news/feb-03-2010 Raymond From stef.mientki at gmail.com Wed Feb 3 13:54:14 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Feb 2010 19:54:14 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <4B699BD4.1010703@gmail.com> Message-ID: <4B69C656.3050402@gmail.com> On 03-02-2010 18:21, Vladimir Ignatov wrote: >>> Imagine simple operation like "method renaming" in a simple "dumb" >>> environment like text editor + grep. Now imagine how simple it can be >>> if system "knows" all your identifiers and just regenerates relevant >>> portions of text from internal database-alike representation. >>> >>> >> I think every IDE (not older than 20 years) does that already. >> > And fix every reference to it in all files? For python? I don't think > so. I even don't think this is possible at all. with tools like inspect it certainly should be possible > That if several > different objects have a similar named method? How will IDE "classify" > calls and renames only some of calls and not others? > yep, you're right, the IDE's I use have as the beste "search / select / rename". But how often do you must/want to rename something (mature) ? cheers, Stef > Vladimir Ignatov > From awilliam at opengroupware.us Wed Feb 3 13:57:51 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Wed, 03 Feb 2010 13:57:51 -0500 Subject: Dreaming of new generation IDE In-Reply-To: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: <1265223471.7916.25.camel@linux-m3mt> On Wed, 2010-02-03 at 10:05 -0800, Phlip wrote: > On Feb 3, 3:10 am, Vladimir Ignatov wrote: > > Finally I develop a feeling that strong instrumentation / tools can > > bring us the best of two worlds. That I am dreaming on is an absolute > > new type/class of IDE suitable for Python and potentially for other > > dynamic-type languages. Instead of current text-oriented IDEs, it > > should be a database-centric and resemble current CAD systems instead > > of being just "fancy text editor". Source text should be an output > > product of that CAD and not a "source material" itself. > That's fine so long as I can also treat the source as source, at need. > You may have just reinvented Smalltalk's Squeak editor (reputedly the > testbed for all of modern GUIs...). > Current editors suck because they can't see into the code and browse > it - unless it's so statically typed it's painful. ? I edit Python in MonoDevelop 2.2; and I can browse my file, classes, etc... So I don't know what you mean by "can't see into the code". It works pretty well. Of course it can't tell that I've set x = {an integer}, as that only happens at runtime. > That's why I wrote this: > http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html From astan.chee at al.com.au Wed Feb 3 14:12:22 2010 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 4 Feb 2010 06:12:22 +1100 Subject: converting XML to hash/dict/CustomTreeCtrl In-Reply-To: References: <4B6756FE.9060206@al.com.au> Message-ID: <4B69CA96.3090908@al.com.au> Nobody wrote: > The code you're using expects the XML to follow a particular format, and > yours doesn't. > > You might want to start with a fairly direct translation, e.g.: > > def xmldict(e): > d = {} > d['tag'] = e.tag > d.update(e.attrib) > children = map(xmldict, e) > if children: > d['children'] = children > text = e.text.strip() > if text: > d['text'] = text > return d > > tree = ElementTree.parse('test.xml') > root = tree.getroot() > d = xmldict(root) > pprint.pprint(d) > > then refine this as needed. > Thanks, that is simple enough for me to understand. I think I got it now. Thanks again From malaclypse2 at gmail.com Wed Feb 3 14:13:37 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 3 Feb 2010 14:13:37 -0500 Subject: Trouble with os.system In-Reply-To: <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Message-ID: <16651e81002031113k56fa1888kd600239627ab926e@mail.gmail.com> On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: > Sure. > > import sys,re,os > files2create = sys.argv[1:] > os.system('mkdir tmp') > > # Some code to create the .tex > > # Compile tex files > os.system('for file in tmp/*; do pdflatex "$file"; done') > > Pretty simple, alas. I think your bug is in the lines you chose not to share with us. I bet you've forgotten to close the last file you create, so that file has changes that haven't been flushed out to the disk yet. Make sure you call close() on each of the files when you're done writing them. -- Jerry From cp.astolfi at gmail.com Wed Feb 3 14:15:56 2010 From: cp.astolfi at gmail.com (Charles-Pierre Astolfi) Date: Wed, 3 Feb 2010 20:15:56 +0100 Subject: Trouble with os.system In-Reply-To: <16651e81002031113k56fa1888kd600239627ab926e@mail.gmail.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> <16651e81002031113k56fa1888kd600239627ab926e@mail.gmail.com> Message-ID: That was it ! What a stupid error... Thank you ! -- Cp On Wed, Feb 3, 2010 at 20:13, Jerry Hill wrote: > On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: >> Sure. >> >> import sys,re,os >> files2create = sys.argv[1:] >> os.system('mkdir tmp') >> >> # Some code to create the .tex >> >> # Compile tex files >> os.system('for file in tmp/*; do pdflatex "$file"; done') >> >> Pretty simple, alas. > > I think your bug is in the lines you chose not to share with us. ?I > bet you've forgotten to close the last file you create, so that file > has changes that haven't been flushed out to the disk yet. ?Make sure > you call close() on each of the files when you're done writing them. > > -- > Jerry > From steve at holdenweb.com Wed Feb 3 14:22:59 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 14:22:59 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: Don't give it another thought. I'd much rather you cared than you didn't ... regards Steve kj wrote: > > Steve, I apologize for the snarkiness of my previous reply to you. > After all, I started the thread by asking the forum for advice on > how to avoid a certain kind of bugs, you were among those who gave > me advice. So nothing other than thanking you for it was in order. > I just let myself get carried away by my annoyance with the Python > import scheme. I'm sorry about it. Even though I don't think I > can put to practice all of your advice, I can still learn a good > deal from it. > > Cheers, > > ~kj > > > Steve Holden writes: > >> kj wrote: >>>> First, I don't shadow built in modules. Its really not very hard to avoid. >>> ...*if* you happen to be clairvoyant. I still don't see how the rest of us >>> could have followed this fine principle in the case of numbers.py >>> prior to Python 2.6. >>> >> Clearly the more you know about the standard library the less likely >> this is to be a problem. Had you been migrqating from an earlier version >> the breakage would have alerted you to look for some version-dependent >> difference. > > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 3 14:23:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 14:23:53 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: kj wrote: > In kj writes: > > >> Steve, I apologize for the snarkiness of my previous reply to you. >> After all, I started the thread by asking the forum for advice on >> how to avoid a certain kind of bugs, you were among those who gave >> me advice. So nothing other than thanking you for it was in order. >> I just let myself get carried away by my annoyance with the Python >> import scheme. I'm sorry about it. Even though I don't think I >> can put to practice all of your advice, I can still learn a good >> deal from it. > > > Boy, that was dumb of me. The above apology was meant for Stephen > Hansen, not Steve Holden. I guess this is now a meta-apology... > (Sheesh.) > Oh, so you don't like *my* advice? ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mrkafk at gmail.com Wed Feb 3 14:30:04 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Feb 2010 20:30:04 +0100 Subject: The best library to create charting application Message-ID: The application will display (elaborate) financial charts. Pygame? Smth else? dotnet? Regards, mk From phlip2005 at gmail.com Wed Feb 3 14:38:57 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 11:38:57 -0800 (PST) Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: On Feb 3, 10:57?am, Adam Tauno Williams wrote: > > Current editors suck because they can't see into the code and browse > > it - unless it's so statically typed it's painful. > > ? ?I edit Python in MonoDevelop ?2.2; ?and I can browse my file, > classes, etc... ?So I don't know what you mean by "can't see into the > code". ?It works pretty well. > > Of course it can't tell that I've set x = {an integer}, as that only > happens at runtime. > > > That's why I wrote this: > > http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html You just said that your code browsing "works pretty well, except when it doesn't". Hence my blog entry. If your editor analyzed your code at runtime, instead of just static analysis, then it could see that x = an integer, or an object, no matter how dynamic your language. -- Phlip http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1 From phlip2005 at gmail.com Wed Feb 3 14:43:23 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 03 Feb 2010 11:43:23 -0800 Subject: The best library to create charting application In-Reply-To: References: Message-ID: mk wrote: > > The application will display (elaborate) financial charts. > > Pygame? Smth else? Back in the day it was Python BLT. Are you on the Web or the Desktop? -- Phlip http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html From mrkafk at gmail.com Wed Feb 3 14:50:43 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Feb 2010 20:50:43 +0100 Subject: The best library to create charting application In-Reply-To: References: Message-ID: Phlip wrote: > mk wrote: >> >> The application will display (elaborate) financial charts. >> >> Pygame? Smth else? > > Back in the day it was Python BLT. > > Are you on the Web or the Desktop? > Desktop, really (there should be some nominal web interface but the main application will be desktop) Regards, mk From tjreedy at udel.edu Wed Feb 3 14:59:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 14:59:17 -0500 Subject: exec within function In-Reply-To: References: Message-ID: On 2/3/2010 3:30 AM, Simon zack wrote: > hi, > I'm not sure how I can use exec within a function correctly > here is the code i'm using: > > def a(): > exec('b=1') > print(b) > > a() > > this will raise an error, but I would like to see it outputting 1 Always **copy and paste** **complete error tracebacks** when asking a question like this. (The only exception would be if it is v e r y long, as with hitting the recursion depth limit of 1000.) From john at castleamber.com Wed Feb 3 15:08:35 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 14:08:35 -0600 Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: <87vdeedqv0.fsf@castleamber.com> Phlip writes: > On Feb 3, 10:57?am, Adam Tauno Williams > wrote: > >> > Current editors suck because they can't see into the code and browse >> > it - unless it's so statically typed it's painful. >> >> ? ?I edit Python in MonoDevelop ?2.2; ?and I can browse my file, >> classes, etc... ?So I don't know what you mean by "can't see into the >> code". ?It works pretty well. >> >> Of course it can't tell that I've set x = {an integer}, as that only >> happens at runtime. >> >> > That's why I wrote this: >> > http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html > > You just said that your code browsing "works pretty well, except when > it doesn't". > > Hence my blog entry. If your editor analyzed your code at runtime, > instead of just static analysis, then it could see that x = an > integer, or an object, no matter how dynamic your language. In Perl: my $x = ( 5, "hello", sub {}, [], {} )[ int rand 5 ]; what's $x? The answer is: it depends. Moreover, even if your editor analyzes your code at runtime (which is certainly not always desirable) it might not be able to find out what the type is of x, simply because it would take too much time to find it out. (It sounds like you want an editor that solves the halting problem ;-) ) I agree with you that to /some extent/ and editor can do analyses, if it does compilation as well (and even runs the code, but the latter is not always desirable). I mentioned the Synthesizer Generator before, which can do compilation on the fly, if you implement it (or if it has been implemented for the language you edit with it). I've written a very simple assembler in it, ages ago, which did assembling on the fly. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 15:09:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 15:09:01 -0500 Subject: simple and fast platform independent IPC In-Reply-To: <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> Message-ID: On 2/3/2010 6:31 AM, Joan Miller wrote: >>> I've read that Pyro is not safe. >> >> That's a fairly broad thing to say. I've read lots >> of things. What does "is not safe" mean, in any case? >> I assume you've got a valid concern in mind which is >> worth passing on to a would-be user, but what exactly >> is it? FWIW I've used Pyro on and off over the years >> without any problems. Certainly my computer's never >> blown up as a result of using it. >> From its own page: > "Pyro has never been truly designed to provide a secure communication > mechanism, nor has it had a security review or -test by a security > expert." > http://pyro.sourceforge.net/features.html For communication between processes on one machine, that hardly seems to be a worry. If it were, I would expect that sending encrypted strings would substantially improve things. That aside, I would wonder whether you could use a master process with a gui to haphazardly launch subprocess, so as to avail oneself of multiprocessing.Queue. Terry Jan Reedy From john at castleamber.com Wed Feb 3 15:10:33 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 14:10:33 -0600 Subject: The best library to create charting application References: Message-ID: <87r5p2dqrq.fsf@castleamber.com> mk writes: > The application will display (elaborate) financial charts. > > Pygame? Smth else? You might want to check out the book "Beginning Python Visualisation". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 15:18:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 15:18:51 -0500 Subject: expy 0.5.2 released In-Reply-To: <857729.7198.qm@web54208.mail.re2.yahoo.com> References: <857729.7198.qm@web54208.mail.re2.yahoo.com> Message-ID: On 2/3/2010 1:43 AM, Yingjie Lan wrote: > Hi, > > expy is an expressway to extend python. > > in release 0.5.2, expy now supports custom exceptions, besides all built-in ones, and exception handling is made easy. > > for more info, see > > http://expy.sourceforge.net/ What Python versions does it work with? There is no indication either above or on the sf page. tjr From gerald.britton at gmail.com Wed Feb 3 15:29:15 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 3 Feb 2010 15:29:15 -0500 Subject: exec within function In-Reply-To: References: Message-ID: <5d1a32001002031229g64321cbeo538de15417127715@mail.gmail.com> I get no error: >>> def a(): ... exec('b=1') ... print(b) ... >>> a() 1 >>> On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy wrote: > On 2/3/2010 3:30 AM, Simon zack wrote: >> >> hi, >> I'm not sure how I can use exec within a function correctly >> here is the code i'm using: >> >> def a(): >> ? ? exec('b=1') >> ? ? print(b) >> >> a() >> >> this will raise an error, but I would like to see it outputting 1 > > Always **copy and paste** **complete error tracebacks** when asking a > question like this. (The only exception would be if it is v e r y long, as > with hitting the recursion depth limit of 1000.) > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From drsalists at gmail.com Wed Feb 3 15:33:25 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 03 Feb 2010 12:33:25 -0800 Subject: Wrap a function In-Reply-To: References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> <9a28cf01-20af-4ce2-9b78-d8529800e4b9@y7g2000prc.googlegroups.com> Message-ID: <4B69DD95.2050906@gmail.com> Joan Miller wrote: > On 28 ene, 21:40, Jonathan Gardner > wrote: > >> On Jan 28, 10:20 am, Joan Miller wrote: >> >> >> >> >>> I've to call to many functions with the format: >>> >>>>>> run("cmd") >>>>>> >>> were "cmd" is a command with its arguments to pass them to the shell >>> and run it, i.e. >>> >>>>>> run("pwd") >>>>>> >>> or >>> >>>>>> run("ls /home") >>>>>> >>> Does anybody knows any library to help me to avoid the use of the main >>> quotes, and brackets? >>> >>> I would to use anything as: >>> >>> $ ls /home => run("ls /home") >>> >>> or, at least >>> >>> run pwd => run("pwd") >>> >> How about this? >> >> def pwd(): return run("pwd") >> >> pwd() >> >> def ls(l=False, files=()): >> args = [] >> if l: args.insert(0, '-l') >> args.append(files) >> return run("ls", args) >> >> ls(l=True, "/foo") >> > > There would be to make a function for each system command to use so it > would be too inefficient, and follow the problem with the quotes. > > The best is make a parser into a compiled language > 'disagree. Best is to have a text file outside your program, in which you define commands and symbolic names for those commands. Then you have a python module which reads these commands and names, and creates functions that invoke them via the specified name. This way you get concise syntax, don't have to type as much boilerplate, and don't add line noise. Mixing two languages as though they were the same language greatly increases the complexity of the original language with little gain. Consider PowerShell - it's almost like two different languages smushed together, and you have to know how a command was implemented to know how to read it. Also, what if someday The Powers That Be (the python language core designers) decide they need to use $ for something? I hope they won't, but if they do, your preprocessor might make quite a mess of it. From tjreedy at udel.edu Wed Feb 3 15:34:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 15:34:52 -0500 Subject: newbie qns : how do i use xmldiff? In-Reply-To: References: Message-ID: On 2/3/2010 1:38 AM, sWrath swrath wrote: > Hi , > > I am pretty new to python , and reading up on it. > > Basically I am trying to compare xml files . I know difflib have it > but it does not work out as expected. I was looking at xmldiff , > unfortunately I am not able to find documentation how to call it from > python. Anyone knows a link or doc to it as I have been looking high > and low for few days? When asking such a question, it is good to explain what sort of thing, in this case, 'xmldiff' is and where it is is from. Let us assume you meant xmldiff from http://www.logilab.org/859 It says it is a python tool that can "be used be used as a library or as a command line tool." It includes a README file. Have you read that? That says "USAGE ... Read the HELP.txt file.". Have you read *that*? HELP.txt seems to focus on command line usage. I would start with that. To use it as a library (via import ...), you might have to look at the source code as I did not see importing covered in my quick look at that file. Terry Jan Reedy From mensanator at aol.com Wed Feb 3 15:38:19 2010 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Feb 2010 12:38:19 -0800 (PST) Subject: ANN: GMPY 1.11 released References: <3cdf9936-035f-43db-abb0-a7daacac14ab@o28g2000yqh.googlegroups.com> <167d472a-9981-4575-b463-a36413ed657e@x1g2000prb.googlegroups.com> Message-ID: <00b3d248-85a3-4cfc-a083-88a405a47e2c@3g2000yqn.googlegroups.com> On Feb 3, 12:36?pm, casevh wrote: > On Feb 3, 10:22?am, Mensanator wrote: > > > Historically, gmpy really didn't have alpha/beta/rc versions and > gmpy.version() just had the version "number" and didn't indicate the > status. If I change it, I'd rather go to "1.1.1rc1" or "1.2.0a0" but > that might break some applications. Ok. And historically, we never had Python 2.5, 2.6, 2.7 & 3.1 to support simultaneously with Windows Xp, Vista and 7 along with Mac OSX 10.4, 10.5,& 10.6 as well as whatever flavors Linnux comes it. Not to mention that there's now two flavors of GMP. How many different permutations do you suppose that is? Thinking about it makes my head hurt. I certainly fell sympathy towards you developers. From no-spam at non-existing.invalid Wed Feb 3 15:40:51 2010 From: no-spam at non-existing.invalid (Robert) Date: Wed, 03 Feb 2010 21:40:51 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: Vladimir Ignatov wrote: > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. can you sketch an example/use case more concretely? Robert From drsalists at gmail.com Wed Feb 3 15:41:43 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 03 Feb 2010 12:41:43 -0800 Subject: Wrap a function In-Reply-To: <87vdelwitb.fsf@benfinney.id.au> References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> <87vdelwitb.fsf@benfinney.id.au> Message-ID: <4B69DF87.4030207@gmail.com> Ben Finney wrote: > Dennis Lee Bieber writes: > > >> On Thu, 28 Jan 2010 11:24:28 -0800 (PST), Joan Miller: >> >>> On 28 ene, 19:16, Josh Holland wrote: >>> >>>> Check the docs on os.system(). >>>> >>> No. I've a function that uses subprocess to run commands on the same >>> shell and so substitute to bash scrips. But a script full of run >>> ("shell_command --with --arguments") is too verbose. >>> >> I shall blaspheme, and suggest that maybe the language you want >> to use is REXX (ooREXX or Regina). >> > > Heh. That isn't blasphemy, because no true Pythonista [0] would claim > Python to be the god of that domain. > > It's no sin to say that Python isn't a good choice for specific things; > and ?I want to write programs by indistinguishably mixing statements > with external system calls? is one of them, IMO >From http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html#terminology A quick note on terminology: open() is typically a system call. fopen is probably never a system call - instead, it is a function in the C library that wraps open(), making open() easier to use. Then there's the system() function - like fopen(), it isn't really a system call, despite its name. Rather, it is a C library function that typically will wrap the fork() and exec*() system calls. From phlip2005 at gmail.com Wed Feb 3 15:44:05 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 12:44:05 -0800 (PST) Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> <87vdeedqv0.fsf@castleamber.com> Message-ID: John Bokma wrote: > my $x = ( 5, "hello", sub {}, [], {} )[ int rand 5 ]; > > what's $x? The answer is: it depends. That's why my blog post advocated (as usual for me) developer tests. Then you either mock the rand, like all developers should, or you get what you pay for, and Principle of Least Surprise still applies... Over the past decade, teams discovered that developer tests more than made up for the lack of rigor in dynamic languages. A dynamic language with tests can be more productive than a static language, even with its runtime type checks AND with its tests. However, our editors must catch up to us. When I test, I am statically declaring a set of types, even if the language would prefer to dynamically fling them hither and yon. We should leverage that. -- Phlip From vinay_sajip at yahoo.co.uk Wed Feb 3 15:44:29 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 3 Feb 2010 12:44:29 -0800 (PST) Subject: Logging oddity: handlers mandatory in every single logger? References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> <4B6954EB.6010004@sequans.com> Message-ID: <0e582f33-718c-4c46-9c14-c07447474634@36g2000yqu.googlegroups.com> On Feb 3, 11:36?am, Masklinn wrote: Well, Xavier, I would be the first to agree that the existing logging configuration API is not ideal. There are a number of reasons for the current ConfigParser schema used (e.g. an old GUI for configuring logging, which was there before the logging package was added to Python, but which was not brought across). However, there is no point in nitpicking over the particular shortcomings you've focused on, unless of course you've run out of bikesheds to paint ;-) Particularly as I've just received the good news from Guido van Rossum that PEP 391 (Dictionary-Based Configuration For Logging) has been accepted, and my aim is to get it into Python 2.7 and Python 3.2. Now, PEP 391 was announced on python-list and python-dev in October 2009, so plenty of people have had an opportunity to comment on it. Going forwards, and over time, I would hope that this configuration scheme will supplant the ConfigParser-based approach, and so I don't think there's much need to tinker with that API. Onwards, upwards, ever forwards :-) Regards, Vinay Sajip From __peter__ at web.de Wed Feb 3 15:50:38 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Feb 2010 21:50:38 +0100 Subject: exec within function References: Message-ID: Gerald Britton wrote: > On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy wrote: >> On 2/3/2010 3:30 AM, Simon zack wrote: >>> >>> hi, >>> I'm not sure how I can use exec within a function correctly >>> here is the code i'm using: >>> >>> def a(): >>> exec('b=1') >>> print(b) >>> >>> a() >>> >>> this will raise an error, but I would like to see it outputting 1 >> >> Always **copy and paste** **complete error tracebacks** when asking a >> question like this. (The only exception would be if it is v e r y long, >> as with hitting the recursion depth limit of 1000.) > I get no error: > >>>> def a(): > ... exec('b=1') > ... print(b) > ... >>>> a() > 1 My crystal ball says you're using Python 2.x. Try it again, this time in 3.x: 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. >>> def f(): ... exec('a = 42') ... print(a) ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'a' is not defined OP: Python 2.x generates different bytecode for functions containing an exec statement. In 3.x this statement is gone and exec() has become a normal function. I suppose you now have to pass a namespace explicitly: >>> def f(): ... ns = {} ... exec("a=1", ns) ... print(ns["a"]) ... >>> f() 1 Peter From john at castleamber.com Wed Feb 3 16:02:33 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 15:02:33 -0600 Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> <87vdeedqv0.fsf@castleamber.com> Message-ID: <87iqaedod2.fsf@castleamber.com> Phlip writes: > John Bokma wrote: > >> my $x = ( 5, "hello", sub {}, [], {} )[ int rand 5 ]; >> >> what's $x? The answer is: it depends. > > That's why my blog post advocated (as usual for me) developer tests. > Then you either mock the rand, like all developers should, or you get > what you pay for, and Principle of Least Surprise still applies... Yup, I agree with you that (to some extent) an IDE should be able to determine types, especially if programmers don't reuse variables, like (again Perl): my $result = .... # int : : if ( ... ) { $result = .... # string } # $result can be still an int, or either a string, depending on the # test. > Over the past decade, teams discovered that developer tests more than > made up for the lack of rigor in dynamic languages. A dynamic language > with tests can be more productive than a static language, even with > its runtime type checks AND with its tests. Yup, this matches up with my experience. I can't recall that I ever bumped into an issue in Perl (the dynamic language I've been using the most for the past years). Not saying that it hasn't happened, but I just can't recall. Probably also the reason why a "new" language I am learning is also dynamic: Python ;-) > However, our editors must catch up to us. When I test, I am statically > declaring a set of types, even if the language would prefer to > dynamically fling them hither and yon. We should leverage that. I am all for testing, but it should IMO not get into the way. I am quite happy with Emacs as an editor (I "recently" switched), it satisfies most (if not all) of the items on the check list. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From drsalists at gmail.com Wed Feb 3 16:09:55 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 03 Feb 2010 13:09:55 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <4B69E623.4060704@gmail.com> kj wrote: > I just spent about 1-1/2 hours tracking down a bug. > > An innocuous little script, let's call it buggy.py, only 10 lines > long, and whose output should have been, at most two lines, was > quickly dumping tens of megabytes of non-printable characters to > my screen (aka gobbledygook), and in the process was messing up my > terminal *royally*. Here's buggy.py: > > > > import sys > import psycopg2 > connection_params = "dbname='%s' user='%s' password='%s'" % tuple(sys.argv[1:]) > conn = psycopg2.connect(connection_params) > cur = conn.cursor() > cur.execute('SELECT * FROM version;') > print '\n'.join(x[-1] for x in cur.fetchall()) > > > (Of course, buggy.py is pretty useless; I reduced the original, > more useful, script to this to help me debug it.) > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. (This second script > is one I wrote as part of a little Python tutorial I put together > months ago, and is not much more of a script than hello_world.py; > it's baby-steps for the absolute beginner. But apparently, it has > a killer name! I had completely forgotten about it.) > > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. I'll call this directory > myscripts in what follows. > > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > > What else can one do? Let's see, one should put every script in its > own directory, thereby containing the damage. > > Anything else? > > Any suggestion would be appreciated. > > TIA! > > ~k > Here's a pretty simple fix that should work in about any version of python available: Put modules in ~/lib. Put scripts in ~/bin. Your modules end with .py. Your scripts don't. Your scripts add ~/lib to sys.path as needed. Things that go in ~/lib are named carefully. Things in ~/bin also need to be named carefully, but for an entirely different reason - if you name something "ls", you may get into trouble. Then things in ~/lib plainly could cause issues. Things in ~/bin don't. Ending everything with .py seems to come from the perl tradition of ending everything with .pl. This perl tradition appears to have come from perl advocates wanting everyone to know (by looking at a URL) that they are using a perl CGI. IMO, it's language vanity, and best dispensed with - aside from this issue, it also keeps you from rewriting your program in another language with an identical interface. This does, however, appear to be a scary issue from a security standpoint. I certainly hope that scripts running as root don't search "." for modules. From john at castleamber.com Wed Feb 3 16:10:56 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 15:10:56 -0600 Subject: Dreaming of new generation IDE References: Message-ID: <87eil2dnz3.fsf@castleamber.com> Robert writes: > Vladimir Ignatov wrote: >> dynamic-type languages. Instead of current text-oriented IDEs, it >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > can you sketch an example/use case more concretely? I guess Vladimir means what's called a structure editor. The (by me) aforementioned Synthesizer Generator is an example of such an editor (environment). http://en.wikipedia.org/wiki/Structure_editor http://portal.acm.org/citation.cfm?doid=358746.358755 -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:17:42 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:17:42 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Wed, 03 Feb 2010 11:55:57 +0100, Daniel Fetchinson wrote: [...] >> Python does most of that for you: it automatically recompiles the >> source whenever the source code's last modified date stamp is newer >> than that of the byte code. So to a first approximation you can forget >> all about the .pyc files and just care about the source. > > True, but the .pyc file is lying around and I always have to do 'ls -al > | grep -v pyc' in my python source directory. So alias a one-word name to that :) [...] > Here is an example: shared object files. If your code needs them, you > can use them easily, you can access them easily if you want to, but they > are not in the directory where you keep your C files. They are somewhere > in /usr/lib for example, where they are conveniently collected, you can > inspect them, look at them, distribute them, do basically whatever you > want, but they are out of the way, and 99% of the time while you develop > your code, you don't need them. In the 1% of the case you can easily get > at them in the centralized location, /usr/lib in our example. > > Of course the relationship between C source files and shared objects is > not parallel to the relationship to python source files and the created > pyc files, please don't nitpick on this point. The analogy is in the > sense that your project inevitable needs for whatever reason some binary > files which are rarely needed at hand, only the > linker/compiler/interpreter/etc needs to know where they are. These > files can be stored separately, but at a location where one can inspect > them if needed (which rarely happens). I'll try not to nit-pick :) When an object file is in /usr/lib, you're dealing with it as a user. You, or likely someone else, have almost certainly compiled it in a different directory and then used make to drop it in place. It's now a library, you're a user of that library, and you don't care where the object file is so long as your app can find it (until you have a conflict, and then you do). While you are actively developing the library, on the other hand, the compiler typically puts the object file in the same directory as the source file. (There may be an option to gcc to do otherwise, but surely most people don't use it often.) While the library is still being actively developed, the last thing you want is for the object file to be placed somewhere other than in your working directory. A potentially unstable or broken library could end up in /usr/lib and stomp all over a working version. Even if it doesn't, it means you have to be flipping backwards and forwards between two locations to get anything done. Python development is much the same, the only(?) differences are that we have a lower threshold between "in production" and "in development", and that we typically install both the source and the binary instead of just the binary. When you are *using* a library/script/module, you don't care whether import uses the .py file or the .pyc, and you don't care where they are, so long as they are in your PYTHONPATH (and there are no conflicts). But I would argue that while you are *developing* the module, it would more nuisance than help to have the .pyc file anywhere other than immediately next to the .py file (either in the same directory, or in a clearly named sub-directory). -- Steven From kmisoft at gmail.com Wed Feb 3 16:24:30 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 00:24:30 +0300 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: > can you sketch an example/use case more concretely? Sorry, I don't have anything written down. I just have some rough idea of implementation and some concrete features I would like to see in such system. For example: 1) Instant refactoring. No more needs for manual search/inspect/rename. Since system knows exactly that is going on, the refactoring will be fully automatic. 2) Show "xref table" for each function. How often this function used? Where is it used? (code snippets of calls) What functionality is supported by this function? 3) Extended statistics. How many objects this object/function interacts with? Popular functions, dead/unused functions. 4) Code smell detector - too long functions, too much interaction with other objects, global objects, etc. ... Vladimir Ignatov From robert.kern at gmail.com Wed Feb 3 16:27:48 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 15:27:48 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-03 14:40 PM, Robert wrote: > Vladimir Ignatov wrote: >> dynamic-type languages. Instead of current text-oriented IDEs, it >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > can you sketch an example/use case more concretely? I believe that Smalltalk came pretty close to what Vladimir is asking for. You wrote the methods as linear plain text, but you used the GUI three pane class browser to define and navigate classes. You could export class definitions to a text file and read them back in, but in Vladimir's terms, the text files were not the "source material" themselves. http://www.cosc.canterbury.ac.nz/wolfgang.kreutzer/cosc205/smalltalk1.html -- 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 jgardner at jonathangardner.net Wed Feb 3 16:32:18 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Feb 2010 13:32:18 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> Message-ID: <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> On Feb 2, 9:11?pm, John Bokma wrote: > Jonathan Gardner writes: > > I can explain, in an hour, every single feature of the Python language > > to an experienced programmer, all the way up to metaclasses, > > Either you're a hell of a talker, or I am far, far away from being an > experienced programmer. It's advocacy like this, IMO, that keeps people > away from a language, because you can't feel nothing but a failure after > a statement like this. > I can explain all of Python in an hour; I doubt anyone will understand all of Python in an hour. Coming from perl to python, the big "aha!" moment was when I realized there wasn't anything more than what I saw before me. I kept expecting something big around the corner, kind of like when I first discovered refs in perl, or when I realized how hard it truly was to write OO code in perl that actually does what you think it should do. Perl has trained me to be fearful of the language, constantly on the lookout for jabberwockies. If you fall into one of those traps in perl, it's because you weren't smart enough and aren't worthy of the language, or so they say. It's never perl's fault. I mean, doesn't everyone know what the Schwartzian Transform is? Python is the complete opposite. Go through http://docs.python.org/reference/ . Once you've familiarized yourself with all the operators, statements, and the special methods, you're done with syntax and the core language. There is no more. The next step is to learn the basic objects and functions in builtins. That's in the first seven chapters of http://docs.python.org/library/index.html. You can always fall back to the "help" function to remind yourself if you forget. I do it all the time. After that, it's merely figuring out which standard libraries do what and how. The documentation there is complete and awesome, and there are more than enough people willing to point you in the right direction here. There are no dragons in this forest. Heck, this isn't even a forest--- it's a single-room apartment with everything you need right there where you can see it. The thermostat is set to room temperature, and no matter what happens outside, you're safe and protected from it all. From kmisoft at gmail.com Wed Feb 3 16:36:05 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 00:36:05 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <87eil2dnz3.fsf@castleamber.com> References: <87eil2dnz3.fsf@castleamber.com> Message-ID: > I guess Vladimir means what's called a structure editor. The (by me) > aforementioned Synthesizer Generator is an example of such an editor > (environment). Maybe. Yes, it kind of "generator". It has (entered somehow) internal representation of target program. Then it generates code out of this internal data. Yes, it is imaginable system, I don't have any working prototype yet. But about to start making it. For prototype I choose python 2.x as implementation language, sqlite as internal database and Django as UI. Vladimir Ignatov From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:37:55 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:37:55 GMT Subject: Dreaming of new generation IDE References: Message-ID: On Wed, 03 Feb 2010 08:18:40 -0500, Adam Tauno Williams wrote: > On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: >> Hello, >> I am sitting here for quite some time, but usually keep silent ;-) I >> use Python since 2003 both "professionally" and for my hobby projects >> and love it a much. >> I notice however, that "maintaining" existing/older python code is may >> be not so enjoyable task. It may be even harder than supporting old >> code written in some type of "static" languages (like Java or C++). >> Surely "dynamic" nature of python comes with price. > > Yes, it certainly does. Not that you'll get many Pythonistas to confess > to that fact. Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: > > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) Obviously? I don't know about that. Being told that "count" is an int doesn't really help me -- it's obvious just from the name. In a well- written API, what else could it be? And surely count should be positive or zero but not negative? Saying it's an int is misleading. Or perhaps count can be negative, in which case maybe negative counts have some special meaning that isn't obvious from the function signature. Can I pass None to get the default behaviour? Either way, I need to read the docs, so the supposed added expressiveness doesn't actually add much. And why is count limited to an actual int type, rather than anything which is integer-like? Why can't I pass 3.0 or Decimal(3)? If you have a good reason for that limitation, great, but if it's just there to satisfy the compiler, then boo hiss to you. I cheerfully admit that *sometimes* there are type restrictions which make sense, and of course we know that there are sometimes useful performance gains to be made with static typing. Any compiler which requires types to be declared is far too 1970s though -- a good modern static language should use type inference to reduce the number of declarations needed. As for Pythonistas refusing to accept this, how do you explain function annotations then? Quoting Guido: "Optional static typing has long been requested as a Python feature." http://www.artima.com/weblogs/viewpost.jsp?thread=85551 More on function annotations and type inference for Python: http://lambda-the-ultimate.org/node/1519 http://www.python.org/dev/peps/pep-3107/ http://www.python.org/workshops/2000-01/proceedings/papers/aycock/aycock.html > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" The answer is usually "both, and anything else that obeys some subset of the sequence or iterable protocols". -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:40:53 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:40:53 GMT Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 03 Feb 2010 06:42:52 -0800, Paul Rubin wrote: > One nice trick with static types is if you change > what the method does (even if its type signature doesn't change), you > can rename the method: > > class.method2(string name, int count): # change 'method' to > 'method2' > > and recompile your codebase. Every place in the code that called > 'method' now gets a compile time "undefined method" error that you can > examine to see if you need to update it. This is something you can't > catch with unit tests because the call sites can be in distant modules. I don't understand why that won't work with unit tests. If you change the name of a method, surely your unit tests will now start failing with AttributeError? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:42:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:42:26 GMT Subject: Dreaming of new generation IDE References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: On Wed, 03 Feb 2010 18:48:12 +0300, Vladimir Ignatov wrote: > Imagine simple operation like "method renaming" in a simple "dumb" > environment like text editor + grep. Now imagine how simple it can be if > system "knows" all your identifiers and just regenerates relevant > portions of text from internal database-alike representation. Something like Bicycle Repair Man then: http://bicyclerepair.sourceforge.net/ -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:43:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:43:26 GMT Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> Message-ID: On Wed, 03 Feb 2010 10:39:53 -0500, Adam Tauno Williams wrote: > On Wed, 2010-02-03 at 16:23 +0100, Stef Mientki wrote: >> Yes, it certainly does. Not that you'll get many Pythonistas >> to confess >> to that fact. Somehow those who brag about the readability and >> expressiveness of source code just cannot admit that: >> class.method(sting name, int count) >> - is *obviously* more expressive than - class.method(name, >> count) >> Oh, well. >> This is obvious even in the Python documentation itself where >> one >> frequently asks oneself "Uhh... so what is parameter X supposed >> to be... >> a string... a list... ?" > >> But I thought that was the one of beauties of Python, you don't need to >> know if the input parameter is a list or a string. > > You don't need to know; unless of course you want the expected result. Says who? If you're free to assume the function requires a certain type, we're free to assume the function is polymorphic and doesn't. -- Steven From news123 at free.fr Wed Feb 3 16:45:57 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 22:45:57 +0100 Subject: simple and fast platform independent IPC In-Reply-To: References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> Message-ID: <4b69ee95$0$10078$426a74cc@news.free.fr> Tim Golden wrote: > >> Anyway, you have in mind that respect to speed: >> >> shared memory> named pipes> Unix domain socket> TCP socket > > True, but the OP didn't mention speed; rather simplicity. Not > saying it isn't a consideration but premature optimisation and > all that... > Yes true. I'm looking for something simple, platform agnostic. Lateron I can always improve performance. Perhaps I'll stick initially with xmlrpc, as it is quite simple, though a little heavy. I just have to see how to deal with servers which are not up, no more up, being restarted. N From soltys at noabuse.net Wed Feb 3 16:46:11 2010 From: soltys at noabuse.net (soltys) Date: Wed, 03 Feb 2010 22:46:11 +0100 Subject: PyChecker under python's virtualenv Message-ID: Hi Everybody, I've been doing some test on pythons' virtualenv and recently I've decided to run PyChecker. But I'm having some difficulties with importing modules available only on virtualenv by pychecker. As if it was trying to use systemwide python. I've googled about it, and found nothing in this area. I installed pychecker using python setup.py install from virtualenv. I looked at pychecker script - it uses correct python. Any help appreciate, Soltys From ben+python at benfinney.id.au Wed Feb 3 16:50:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Feb 2010 08:50:44 +1100 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> <87vdelwitb.fsf@benfinney.id.au> Message-ID: <87ock6m1jf.fsf@benfinney.id.au> Dan Stromberg writes: > Ben Finney wrote: > > It's no sin to say that Python isn't a good choice for specific > > things; and ?I want to write programs by indistinguishably mixing > > statements with external system calls? is one of them, IMO > > From > http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html#terminology > > A quick note on terminology: open() is typically a system call. [?] That is a different use of ?system call?. I used it in the ?os.system? sense: meaning ?invoke an external OS command as a child of this process?. -- \ ?I was in a bar the other night, hopping from barstool to | `\ barstool, trying to get lucky, but there wasn't any gum under | _o__) any of them.? ?Emo Philips | Ben Finney From robert.kern at gmail.com Wed Feb 3 16:50:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 15:50:49 -0600 Subject: Python and Ruby In-Reply-To: <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: On 2010-02-03 15:32 PM, Jonathan Gardner wrote: > I can explain all of Python in an hour; I doubt anyone will understand > all of Python in an hour. With all respect, talking about a subject without a reasonable chance of your audience understanding the subject afterwards is not explaining. It's just exposition. -- 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 gb345 at invalid.com Wed Feb 3 16:51:44 2010 From: gb345 at invalid.com (gb345) Date: Wed, 3 Feb 2010 21:51:44 +0000 (UTC) Subject: Need help w 'Broken pipe' handling Message-ID: Hi! I'm having a hard time figuring out how to handle a Unix SIGPIPE exception cleanly. The following short script illustrates the problem: ------------------------------------------------------------------ #!/usr/bin/python # sigpipebug.py import sys import random from signal import signal, SIGPIPE, SIGINT def handle_sigpipe(signo, frame): print >> sys.stderr, "caught SIGPIPE (%d)" % signo sys.exit(0) def handle_sigint(signo, frame): print >> sys.stderr, "caught SIGINT (%d)" % signo sys.exit(1) def my_excepthook(exc_type, exc_obj, exc_tb): print >> sys.stderr, "excepthook called" sys.exit(0) signal(SIGPIPE, handle_sigpipe) signal(SIGINT, handle_sigint) # sys.excepthook = my_excepthook while True: try: print random.random() except IOError as (_, error): if error == 'Broken pipe': print >> sys.stderr, 'EXCEPTION: %s' % error sys.exit(0) raise ------------------------------------------------------------------ The problem shows up only occasionally; the following bash one-liner helps to see the problem (terminate with Ctrl-C): while [ 1 ]; do (./sigpipebug.py||break) | head -1; done (The pipe through head should cause the script to receive a PIPE signal.) The typical output from the above one-liner will start out as something like this: 0.666233280308 caught SIGPIPE (13) 0.554289690682 caught SIGPIPE (13) 0.438033929588 caught SIGPIPE (13) 0.969307976257 caught SIGPIPE (13) close failed in file object destructor: Error in sys.excepthook: Original exception was: 0.916260186232 caught SIGPIPE (13) 0.798590903019 caught SIGPIPE (13) 0.737496617527 ...though the length of the output preceding "close failed..." is highly variable. My problem is that I can't figure out how to get rid of this unwanted extra output: close failed in file object destructor: Error in sys.excepthook: Original exception was: I figure that the way the script is handling the SIGPIPE is somehow incorrect, but I don't see what is it that I'm doing wrong (BTW, I'm a Python noob). Is there some cleanup method I should invoke in the sigpipe handler before executing sys.exit(0)? (BTW, I'm using sys.exit in this script instead of plain exit to avoid a strange error of the form "NameError: global name 'exit' is not defined".) The same thing happens when I redefine sys.excepthook (by uncommenting the commented-out line). Also, is there a way to define the SIGPIPE handler to obviate the need to trap the IOError exception? (Without this try block, I get a traceback when the script receives the PIPE signal. This traceback is also unwanted output.) Any suggestions or comments would be appreciated! Gabe From no.email at nospam.invalid Wed Feb 3 17:00:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:00:42 -0800 Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: <7xmxzqq8s5.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> and recompile your codebase. Every place in the code that called >> 'method' now gets a compile time "undefined method" error that you can >> examine to see if you need to update it. This is something you can't >> catch with unit tests because the call sites can be in distant modules. > > I don't understand why that won't work with unit tests. If you change the > name of a method, surely your unit tests will now start failing with > AttributeError? Unit tests only test the code in the local module or package ("unit"). Obviously you also need other tests to exercise the interaction between local and remote modules, but it's harder to be as thorough with those, or write them as reflexively, in part because they're often written by a separate group of programmers. From no.email at nospam.invalid Wed Feb 3 17:01:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:01:52 -0800 Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> <4b69ee95$0$10078$426a74cc@news.free.fr> Message-ID: <7xiqaeq8q7.fsf@ruckus.brouhaha.com> News123 writes: > Perhaps I'll stick initially with xmlrpc, as it is quite simple, > though a little heavy. I just have to see how to deal with servers > which are not up, no more up, being restarted. Something wrong wtih nagios? From news123 at free.fr Wed Feb 3 17:02:32 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 23:02:32 +0100 Subject: simple and fast platform independent IPC In-Reply-To: References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> Message-ID: <4b69f278$0$25781$426a34cc@news.free.fr> Hi Terry, Terry Reedy wrote: > > That aside, I would wonder whether you could use a master process with a > gui to haphazardly launch subprocess, so as to avail oneself of > multiprocessing.Queue. > T This is also an option I'm looking. insted of the python scripts, thet users would normally click at I had to implement small sripts, that just communicate with the master process, which would then launch the application. From deets at nospam.web.de Wed Feb 3 17:04:31 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:04:31 +0100 Subject: Passing parameters in URL In-Reply-To: <878wbafaui.fsf@castleamber.com> References: <878wbafaui.fsf@castleamber.com> Message-ID: <7sua7fFn74U1@mid.uni-berlin.de> Am 03.02.10 19:11, schrieb John Bokma: > Alan Harris-Reid writes: > >> I have a web-page where each row in a grid has edit/delete buttons to >> enable the user to maintain a selected record on another page. The >> buttons are in the form of a link with href='/item_edit?id=123', but >> this string appears in the URL and gives clues as to how to bypass the >> correct sequence of events, and could be risky if they entered the URL >> directly (especially when it comes to deleting records). > > You should *never* use a GET request to do actions like deleting > records. You already are aware of it being risky, so don't do this. You > should use GET for getting information, and POST for modifying information. You should *never* say never, because there might be situations where exceptions from rules are valid. This is one such cases. Making this a post means that you need to resort to javascript to populate & submit a hidden HTML-form. Just for the sake of a POST. And there are people who say "you should *never* write web-apps that only work with enabled javascript"... catch 22. Also, your claim of it being more risky is simply nonsense. GET is a tiny bit more prone to tinkering by the average user. But calling this less risky is promoting security by obscurity, at most. Diez From no.email at nospam.invalid Wed Feb 3 17:09:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:09:07 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> Message-ID: <7xeil2q8e4.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Also, your claim of it being more risky is simply nonsense. GET is a > tiny bit more prone to tinkering by the average user. But calling this > less risky is promoting security by obscurity, at most. GET parameters also tend to get recorded in the http logs of web proxies and web servers while POST parameters usually aren't. This was an annoyance in a web chat package I fooled with for a while. Because the package sent user messages by GET, if I ran the software the way the developers set it up, the contents of all the user conversations stayed in my server logs. I was unable to convince the chat package maintainers that this was a bug. I ended up doing some fairly kludgy hack to prevent the logging. From deets at nospam.web.de Wed Feb 3 17:10:19 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:10:19 +0100 Subject: Passing parameters in URL In-Reply-To: References: Message-ID: <7suaicFp81U1@mid.uni-berlin.de> Am 03.02.10 19:01, schrieb Alan Harris-Reid: > I have a web-page where each row in a grid has edit/delete buttons to > enable the user to maintain a selected record on another page. The > buttons are in the form of a link with href='/item_edit?id=123', but > this string appears in the URL and gives clues as to how to bypass the > correct sequence of events, and could be risky if they entered the URL > directly (especially when it comes to deleting records). > > Is there another way of passing a record-id to a method > a) without it appearing in the URL? You can populate an invisible HTML-form with the values, and submit that - of course you need javascript for this. But this doesn't increase security a bit. Using an extension to FF such as HTTP live headers, it's easy enough to figure out what parameters are passed, and simply forge a request. > b) without the user being able to fathom-out how to attach which id to > which URL? Paul already mentioned that - you can create a server-side, session-stored action-item that is identified by a hash of some sort. Then use that hash as parameter. But I'd say you should instead make sure that your serve actions perform authorization checking before performing any operations. Then you don't need to worry - even guessing a hash argument won't work then. > > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the edit/delete > action? You should of course always do that. Every http-action except login should be guarded (unless you allow anonymous access of course). Diez From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 17:12:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 22:12:31 GMT Subject: [Off topic] Radian language Message-ID: For those interested in language design, the former head of RealBasic's development team, and current "compiler architect guy" for Microsoft's VisualBasic team, Mars Saxman, is developing an interesting programming language, Radian: "The goal of the Radian project is to provide the concurrency benefits of a pure functional language inside the syntax and conceptual style of a high-level imperative language. This suggests two questions: what is it about a pure functional language that makes it useful for developing concurrent software, and what is it about an imperative syntax that makes the marriage of these two divergent linguistic styles worth the effort?" Radian is heavily (but not uniquely) influenced by Python, although sometimes that influence is "what not to do". http://www.radian-lang.org/ -- Steven From deets at nospam.web.de Wed Feb 3 17:21:50 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:21:50 +0100 Subject: PyChecker under python's virtualenv In-Reply-To: References: Message-ID: <7sub7uFstoU1@mid.uni-berlin.de> Am 03.02.10 22:46, schrieb soltys: > Hi Everybody, > I've been doing some test on pythons' virtualenv and recently I've > decided to run PyChecker. But I'm having some difficulties with importing > modules available only on virtualenv by pychecker. As if it was > trying to use systemwide python. > I've googled about it, and found nothing in this area. > I installed pychecker using python setup.py install > from virtualenv. I looked at pychecker script - it uses correct python. I doubt that it uses the "correct python", because then you wouldn't have the problems you have. I don't use pychecker, but pylint. And there, the system-wide command uses the system's python - which of course doesn't know anything about virtualenv. There are two solutions to this problem: - install py(lint|checker) into your virtualenv. - write a wrapper-script that invokes py(lint|checker) with an adapted PYTHONPATH environtment variable, based on the venv's sys.path. I do that for my epylint-wrapper for emacs. Works flawlessly. Diez From john at castleamber.com Wed Feb 3 17:24:05 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 16:24:05 -0600 Subject: Dreaming of new generation IDE References: <87eil2dnz3.fsf@castleamber.com> Message-ID: <871vh2dkl6.fsf@castleamber.com> Vladimir Ignatov writes: >> I guess Vladimir means what's called a structure editor. The (by me) >> aforementioned Synthesizer Generator is an example of such an editor >> (environment). > > Maybe. Yes, it kind of "generator". It has (entered somehow) internal > representation of target program. Then it generates code out of this > internal data. Yes, it is imaginable system, I don't have any working > prototype yet. But about to start making it. For prototype I choose > python 2.x as implementation language, sqlite as internal database and > Django as UI. You might check out articles that mention the Synthesizer Generator, etc. http://citeseer.ist.psu.edu/cis?q=synthesizer+generator&cs=1 http://citeseer.ist.psu.edu/cis?q=structure+editor&cs=1 The idea is not new (at least 30 years old), and those articles might help you. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 17:24:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 17:24:50 -0500 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: On 2/3/2010 8:18 AM, Adam Tauno Williams wrote: > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) So write class.method(name:str, count:int)->return_type # 3.x if you really prefer. In spite of you disparagement of 'pythonistas', it seems that the head pythonista *did* admit that some people, at least, would prefer such annotations. 3.0 also added abstract base classes so one can better specify object classes without losing duck-typing. import numbers class.method(name:str, count:numbers.Integral)->return_type Now one is documenting that count should be an integral value that acts like an integer even if it is not an int per se. Of course, this is too broad as it allows (presumably invalid) negative values. Terry Jan Reedy From pavlovevidence at gmail.com Wed Feb 3 17:24:59 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Feb 2010 14:24:59 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <6025a408-182b-4ab7-8ad6-7a7305879b4e@a5g2000prg.googlegroups.com> On Feb 3, 8:55?am, Nobody wrote: > On Tue, 02 Feb 2010 10:38:53 -0800, Carl Banks wrote: > >> I don't know if that's necessary. Only supporting the "foo.h" case would > >> work fine if Python behaved like gcc, i.e. if the "current directory" > >> referred to the directory contain the file performing the import rather > >> than in the process' CWD. > > >> As it stands, imports are dynamically scoped, when they should be > >> lexically scoped. > > > Mostly incorrect. ?The CWD is in sys.path only for interactive > > sessions, and when started with -c switch. ?When running scripts, the > > directory where the script is located is used instead, not the > > process's working directory. > > Okay, so s/CWD/directory containing __main__ script/, but the general > argument still holds. > > > So, no, it isn't anything like dynamic scoping. > > That's what it looks like to me. The way that an import name is resolved > depends upon the run-time context in which the import occurs. Well it has one superficial similarity to dynamic binding, but that's pretty much it. When the directory containing __main__ script is in the path, it doesn't matter if you invoke it from a different directory or os.chdir () during the program, the same modules get imported. I.e., there's nothing dynamic at all about which modules are used. (Unless you fiddle with the path but that's another question.) All I'm saying is the analogy is bad. A better analogy would be if you have lexical binding, but you automatically look in various sister scope before your own scope. Carl Banks From robert.kern at gmail.com Wed Feb 3 17:27:43 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 16:27:43 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-03 15:40 PM, Steven D'Aprano wrote: > On Wed, 03 Feb 2010 06:42:52 -0800, Paul Rubin wrote: > >> One nice trick with static types is if you change >> what the method does (even if its type signature doesn't change), you >> can rename the method: >> >> class.method2(string name, int count): # change 'method' to >> 'method2' >> >> and recompile your codebase. Every place in the code that called >> 'method' now gets a compile time "undefined method" error that you can >> examine to see if you need to update it. This is something you can't >> catch with unit tests because the call sites can be in distant modules. > > I don't understand why that won't work with unit tests. If you change the > name of a method, surely your unit tests will now start failing with > AttributeError? Let's say we have class "A" with a method named "foo" that we change to "bar". We have another class "B" with a method that accepts and A() instance and calls the .foo() method on it. It is perfectly reasonable (and often necessary) for the unit test of class B to use a mock object instead of a real A() instance. The unit test for class B will fail to catch the renaming of A.foo() to A.bar() because it never tries to call .foo() on a real A instance. Of course, in a static language, it's much harder to make mock objects to do this kind of (very useful!) testing to begin with. -- 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 fetchinson at googlemail.com Wed Feb 3 17:28:14 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 3 Feb 2010 23:28:14 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >>> Python does most of that for you: it automatically recompiles the >>> source whenever the source code's last modified date stamp is newer >>> than that of the byte code. So to a first approximation you can forget >>> all about the .pyc files and just care about the source. >> >> True, but the .pyc file is lying around and I always have to do 'ls -al >> | grep -v pyc' in my python source directory. > > > So alias a one-word name to that :) > > > [...] >> Here is an example: shared object files. If your code needs them, you >> can use them easily, you can access them easily if you want to, but they >> are not in the directory where you keep your C files. They are somewhere >> in /usr/lib for example, where they are conveniently collected, you can >> inspect them, look at them, distribute them, do basically whatever you >> want, but they are out of the way, and 99% of the time while you develop >> your code, you don't need them. In the 1% of the case you can easily get >> at them in the centralized location, /usr/lib in our example. >> >> Of course the relationship between C source files and shared objects is >> not parallel to the relationship to python source files and the created >> pyc files, please don't nitpick on this point. The analogy is in the >> sense that your project inevitable needs for whatever reason some binary >> files which are rarely needed at hand, only the >> linker/compiler/interpreter/etc needs to know where they are. These >> files can be stored separately, but at a location where one can inspect >> them if needed (which rarely happens). > > I'll try not to nit-pick :) > > When an object file is in /usr/lib, you're dealing with it as a user. > You, or likely someone else, have almost certainly compiled it in a > different directory and then used make to drop it in place. It's now a > library, you're a user of that library, and you don't care where the > object file is so long as your app can find it (until you have a > conflict, and then you do). > > While you are actively developing the library, on the other hand, the > compiler typically puts the object file in the same directory as the > source file. (There may be an option to gcc to do otherwise, but surely > most people don't use it often.) While the library is still being > actively developed, the last thing you want is for the object file to be > placed somewhere other than in your working directory. A potentially > unstable or broken library could end up in /usr/lib and stomp all over a > working version. Even if it doesn't, it means you have to be flipping > backwards and forwards between two locations to get anything done. > > Python development is much the same, the only(?) differences are that we > have a lower threshold between "in production" and "in development", and > that we typically install both the source and the binary instead of just > the binary. > > When you are *using* a library/script/module, you don't care whether > import uses the .py file or the .pyc, and you don't care where they are, > so long as they are in your PYTHONPATH (and there are no conflicts). But > I would argue that while you are *developing* the module, it would more > nuisance than help to have the .pyc file anywhere other than immediately > next to the .py file (either in the same directory, or in a clearly named > sub-directory). Okay, I think we got to a point where it's more about rationalizing gut feelings than factual stuff. But that's okay, system/language/architecure design is often times more about gut feelings than facts so nothing to be too surprised about :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From deets at nospam.web.de Wed Feb 3 17:31:39 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:31:39 +0100 Subject: Passing parameters in URL In-Reply-To: <7xeil2q8e4.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> Message-ID: <7subqbFvvpU1@mid.uni-berlin.de> Am 03.02.10 23:09, schrieb Paul Rubin: > "Diez B. Roggisch" writes: >> Also, your claim of it being more risky is simply nonsense. GET is a >> tiny bit more prone to tinkering by the average user. But calling this >> less risky is promoting security by obscurity, at most. > > GET parameters also tend to get recorded in the http logs of web proxies > and web servers while POST parameters usually aren't. This was an > annoyance in a web chat package I fooled with for a while. Because the > package sent user messages by GET, if I ran the software the way the > developers set it up, the contents of all the user conversations stayed > in my server logs. I was unable to convince the chat package > maintainers that this was a bug. I ended up doing some fairly kludgy > hack to prevent the logging. If somebody happens to have access to a proxy & it's logs, he can as well log the request body. Don't get me wrong, I don't want to propagate the use of GET as one and only method for parameter passing. But whatever is transmitted clear text over the wire is subject to inspection of all hops in between. Use SSL if you bother. Diez From pavlovevidence at gmail.com Wed Feb 3 17:34:13 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Feb 2010 14:34:13 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> <8104faf3-c4ea-4b1f-8316-f8b17f53554b@q2g2000pre.googlegroups.com> Message-ID: <222d372b-5e43-48a5-835c-4086a992ba78@y7g2000prc.googlegroups.com> On Feb 2, 8:52?pm, Steven D'Aprano wrote: > On Tue, 02 Feb 2010 19:55:15 -0800, Carl Banks wrote: > > On Feb 2, 5:49?pm, Steven D'Aprano > > wrote: > >> On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: > >> > I did not propose obvious module names. ?I said obvious names like > >> > email.py are bad; more descriptive names like send_email.py are > >> > better. > > >> But surely send_email.py doesn't just send email, it parses email and > >> receives email as well? > > > No, it doesn't. > > Nevertheless, as a general principle, modules will tend to be multi- > purpose and/or generic. Uh, no? If your module is a library with a public API, then you might defensibly have a "generic and/or multi-purpose module", but if that's the case you should have already christened it something unique. Otherwise modules should stick to a single purpose that can be summarized in a short action word or phrase. Carl Banks From no.email at nospam.invalid Wed Feb 3 17:35:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:35:39 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> Message-ID: <7xmxzqx804.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > If somebody happens to have access to a proxy & it's logs, he can as > well log the request body. I'm not talking about a malicious server operator. In this situation, I was the server operator and I didn't want to be recording the conversations. I had to go out of my way to stop the recording. SSL doesn't help and in fact I was using it, but web server logging happens after the SSL layer. I suppose SSL would help against a malicious proxy. Many people back in those days (before AJAX became a buzzword du jour) wanted to do encryption on the client in java or javascript, but that was almost unworkably kludgy, and SSL was the only approach that made any sense. It might be easier now that the javascript API's are richer and the interpreters are faster. From robert.kern at gmail.com Wed Feb 3 17:38:21 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 16:38:21 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-03 15:37 PM, Steven D'Aprano wrote: > On Wed, 03 Feb 2010 08:18:40 -0500, Adam Tauno Williams wrote: > >> On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: >>> Hello, >>> I am sitting here for quite some time, but usually keep silent ;-) I >>> use Python since 2003 both "professionally" and for my hobby projects >>> and love it a much. >>> I notice however, that "maintaining" existing/older python code is may >>> be not so enjoyable task. It may be even harder than supporting old >>> code written in some type of "static" languages (like Java or C++). >>> Surely "dynamic" nature of python comes with price. >> >> Yes, it certainly does. Not that you'll get many Pythonistas to confess >> to that fact. Somehow those who brag about the readability and >> expressiveness of source code just cannot admit that: >> >> class.method(sting name, int count) >> >> - is *obviously* more expressive than - >> >> class.method(name, count) > > Obviously? I don't know about that. Being told that "count" is an int > doesn't really help me -- it's obvious just from the name. In a well- > written API, what else could it be? A bool. As in telling the method whether or not it should count something. That said, I agree with your later point that this kind of information is better provided by the docstring, not the call signature. Not least because the "type" may be something wishy-washy and ad-hoc like "sequence" or "string or list of strings". I do wish that people would document their parameters with this information a little more consistently, though. -- 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 phlip2005 at gmail.com Wed Feb 3 17:47:52 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 14:47:52 -0800 (PST) Subject: equivalent of Ruby's Pathname? Message-ID: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> Pythonistas: Yes, calling os.path.walk() and os.path.join() all the time on raw strings is fun, but I seem to recall from my Ruby days a class called Pathname, which presented an object that behaved like a string at need, and like a filesystem path at need. path + 'folder' would call .join() and insert the / correctly, for example. What's the best equivalent in Python-land? -- Phlip From pecora at anvil.nrl.navy.mil Wed Feb 3 17:54:57 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 03 Feb 2010 17:54:57 -0500 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: In article <1944d953-25ad-440b-9317-a7a4b4de6dac at f17g2000prh.googlegroups.com>, Jonathan Gardner wrote: > > I can explain all of Python in an hour; I doubt anyone will understand > all of Python in an hour. > > Coming from perl to python, the big "aha!" moment was when I realized > there wasn't anything more than what I saw before me. I kept expecting > something big around the corner, kind of like when I first discovered > refs in perl, or when I realized how hard it truly was to write OO > code in perl that actually does what you think it should do. > > Perl has trained me to be fearful of the language, constantly on the > lookout for jabberwockies. If you fall into one of those traps in > perl, it's because you weren't smart enough and aren't worthy of the > language, or so they say. It's never perl's fault. I mean, doesn't > everyone know what the Schwartzian Transform is? > > Python is the complete opposite. Go through http://docs.python.org/reference/ > . Once you've familiarized yourself with all the operators, > statements, and the special methods, you're done with syntax and the > core language. There is no more. > > The next step is to learn the basic objects and functions in builtins. > That's in the first seven chapters of > http://docs.python.org/library/index.html. > You can always fall back to the "help" function to remind yourself if > you forget. I do it all the time. > > After that, it's merely figuring out which standard libraries do what > and how. The documentation there is complete and awesome, and there > are more than enough people willing to point you in the right > direction here. > > There are no dragons in this forest. Heck, this isn't even a forest--- > it's a single-room apartment with everything you need right there > where you can see it. The thermostat is set to room temperature, and > no matter what happens outside, you're safe and protected from it all. That's a pretty accurate description of how I transitioned to Python from C and Fortran. I kept trying to think of how to output data and parameter variables of different types to files for later reading in. How to format them all consistently and then get them back in with the exact same accuracy. I was stuck in printf and scanf land. Then after much noodling around and reading it hit me that I could just put all that output of different types of variables into a list, hit it with a repr() function to get a string version, and write the string to a file -- no formatting necessary-- three lines of code. Later reading in the string version (no formatting necessary), and hitting it with an eval() function returned all the values I originally had in those variables. How simple, but beautiful. I was making it harder when Python was making it easier. Trained on the wrong language. -- -- Lou Pecora From bblais at bryant.edu Wed Feb 3 17:57:55 2010 From: bblais at bryant.edu (Brian Blais) Date: Wed, 03 Feb 2010 17:57:55 -0500 Subject: mouse input in turtle module Message-ID: <146C3C50-CA41-4A38-B9F4-4633219B1E99@bryant.edu> Hello, I would like to find a way to pause, and get mouse input in the turtle module. Since it is built on tk, I thought perhaps there would be an easy way, but I am stumped. Specifically, I'd like something like: x,y,button=mouse_input() # pause in here until the mouse is clicked in the turtle window I know about the screenclick, where I can define a callback but I couldn't rig it to pause until a mouse clicked, even using global flags. Is there an example of this somewhere? For a bonus, I'd love to be able to out of it, either raising an exception or return a button=-1 or something. thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Wed Feb 3 18:03:15 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 17:03:15 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <87wrytdirw.fsf@castleamber.com> Jonathan Gardner writes: > On Feb 2, 9:11?pm, John Bokma wrote: >> Jonathan Gardner writes: >> > I can explain, in an hour, every single feature of the Python language >> > to an experienced programmer, all the way up to metaclasses, >> >> Either you're a hell of a talker, or I am far, far away from being an >> experienced programmer. It's advocacy like this, IMO, that keeps people >> away from a language, because you can't feel nothing but a failure after >> a statement like this. >> > > I can explain all of Python in an hour; OK, in that case I would say give it a go. Put it on YouTube, or write a blog post about it (or post it here). I am sure you will help a lot of people that way. > Coming from perl to python, the big "aha!" moment was when I realized > there wasn't anything more than what I saw before me. I kept expecting > something big around the corner, kind of like when I first discovered > refs in perl, or when I realized how hard it truly was to write OO > code in perl that actually does what you think it should do. There are very nice frameworks to help you (e.g. Moose). OO is not that hard IMO, but I can imagine it's very hard if you don't understand references sufficiently. > Perl has trained me to be fearful of the language, constantly on the > lookout for jabberwockies. If you fall into one of those traps in > perl, it's because you weren't smart enough and aren't worthy of the > language, or so they say. Odd, you gave me the same feeling when you stated you could explain me all features of Python in an hour. > It's never perl's fault. I mean, doesn't everyone know what the > Schwartzian Transform is? Doesn't everyone know what the big O notation is? I mean, Schwartzian transform is not unique to Perl, and it strikes me as odd that you think it is. It's all about understanding that general sort on average is O(n log n), and hence does O(n log n) comparisons. Which means that if you do an expensive calculation in a custom compare function or do a lot of comparisons it might be cheaper to do precalculate the keys (O(n)). Randal Schwartz was the person who made this idea popular in the Perl community, hence the Perl community named it after him, but it was long known before that and used in other languages. [How to learn Python] I am fully aware of how to learn a language, I've done so several times (or many times even). I only disagree with your statement that you can explain all features of Python to me in an hour. But I love to be wrong on this, and to stand corrected. > There are no dragons in this forest. Heck, this isn't even a forest--- > it's a single-room apartment with everything you need right there > where you can see it. The thermostat is set to room temperature, and > no matter what happens outside, you're safe and protected from it all. Why does this sound like some religious speech? I always say: if there was a really easy to learn programming language, I would be programming in it. And no, I don't think Python is it. (Nor Perl for that matter). I do agree that Python /looks/ more simple (and certainly cleaner, unless you're using regexp a lot) than Perl, and certainly to some extend Python /is/ simpler. But in my (relatively long experience) programming boils mostly down to which libraries you know, and how well you can use them. Finally, note that simpeler doesn't always make your code more easy to grasp. There is a reason that human languages are rich and often have many ways to say something. Programming, after all, is also communication with other humans (if only with one self). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From no.email at nospam.invalid Wed Feb 3 18:09:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 15:09:37 -0800 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <7x8wb9j4r2.fsf@ruckus.brouhaha.com> Lou Pecora writes: > after much noodling around and reading it hit me that I could just put > all that output of different types of variables into a list, hit it > with a repr() function to get a string version, and write the string > to a file -- no formatting necessary-- three lines of code. Later > reading in the string version (no formatting necessary), and hitting > it with an eval() function returned all the values I originally had in > those variables. How simple, but beautiful. FYI: I do that too sometimes, but in general using repr/eval that way is poor style and not very reliable. It's better to use the pickle module, which is intended for that sort of thing, or the json module if your datatypes are suitable and you want to follow a semi-standard. From deets at nospam.web.de Wed Feb 3 18:26:17 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 00:26:17 +0100 Subject: Passing parameters in URL In-Reply-To: <7xmxzqx804.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> Message-ID: <7suf0pFhadU1@mid.uni-berlin.de> Am 03.02.10 23:35, schrieb Paul Rubin: > "Diez B. Roggisch" writes: >> If somebody happens to have access to a proxy& it's logs, he can as >> well log the request body. > > I'm not talking about a malicious server operator. In this situation, I > was the server operator and I didn't want to be recording the > conversations. I had to go out of my way to stop the recording. SSL > doesn't help and in fact I was using it, but web server logging happens > after the SSL layer. I suppose SSL would help against a malicious > proxy. Well, we actually implemented POST-parameter logging (inside the WSGI-app), because we *want* all parameters users pass. They end up in the application anyway, and aid debugging. Of course we blind sensitive parameters such as passwords & creditcard numbers. Of course only information not gathered is really safe information. But every operation that has side-effects is reproducable anyway, and if e.g. your chat-app has a history, you can as well log the parameters. Diez From tjreedy at udel.edu Wed Feb 3 18:31:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 18:31:09 -0500 Subject: Selenium/SauceLabs OpenSpace at Pycon In-Reply-To: References: Message-ID: On 2/3/2010 1:42 PM, Raymond Hettinger wrote: > For those who are interested, the Sauce Labs team, http://saucelabs.com/about/team, > is hosting two free tutorial open space sessions at Pycon in Atlanta. > > In the short session, people bringing their laptops should be able to > record a web session in their browser, convert the recorded activity > to a Python script, modify the script to accept a number of inputs , > and replay the script locally on their laptops. Once you've learned > how to fully automate your own browser, submit the same script to the > Sauce Labs cloud to run the tests in parallel across multiple browsers > and operating systems, and view the results with instant video > playback. A free tutorial is a good way to introduce Suace Lab and its product. I visited the site, but one variable I did not address is screen size and aspect ratio. When my wife redid her home page last fall, that was more of a problem than browser differences. tjr From steve at holdenweb.com Wed Feb 3 18:39:48 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 18:39:48 -0500 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: Robert Kern wrote: > On 2010-02-03 15:32 PM, Jonathan Gardner wrote: > >> I can explain all of Python in an hour; I doubt anyone will understand >> all of Python in an hour. > > With all respect, talking about a subject without a reasonable chance of > your audience understanding the subject afterwards is not explaining. > It's just exposition. > I agree. If the audience doesn't understand then you haven't explained it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at nospam.invalid Wed Feb 3 18:39:50 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 15:39:50 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> Message-ID: <7xr5p1dh2x.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Of course only information not gathered is really safe > information. But every operation that has side-effects is reproducable > anyway, and if e.g. your chat-app has a history, you can as well log > the parameters. No I can't. The chat-app history would be on the client, not the server, so I'd have no access to it. Put another way: as server operator, I'm like the owner of a coffee shop. I can't stop patrons from recording their own conversations with each other, and it's not even really my business whether they do that. But it would be outrageous for the shop owner to record the conversations of patrons. From lanyjie at yahoo.com Wed Feb 3 19:00:21 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 3 Feb 2010 16:00:21 -0800 (PST) Subject: expy 0.5.2 released In-Reply-To: Message-ID: <179000.53309.qm@web54207.mail.re2.yahoo.com> > > > > expy is an expressway to extend python. > > > > in release 0.5.2, expy now supports custom exceptions, > besides all built-in ones, and exception handling is made > easy. > > > > for more info, see > > > > http://expy.sourceforge.net/ > > What Python versions does it work with? > There is no indication either above or on the sf page. > Thanks for point that out, I will add this to the document. Currently, it works with Python 2.5, 2.6. I haven't tested with Python 2.7 or 3.x (for 3.x, need to use the code tool first, then I am not sure if the C API for 3.x has changed much). BTW, the current version is 0.5.5. Yingjie From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 19:01:06 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2010 00:01:06 GMT Subject: Dreaming of new generation IDE References: Message-ID: On Wed, 03 Feb 2010 16:38:21 -0600, Robert Kern wrote: >>> class.method(name, count) >> >> Obviously? I don't know about that. Being told that "count" is an int >> doesn't really help me -- it's obvious just from the name. In a well- >> written API, what else could it be? > > A bool. As in telling the method whether or not it should count > something. Ha ha, good point. I question that this is a well-written API: such flags to change the behaviour of a function/method are generally poor design. If method behaves differently depending on whether or not you want it to count something, then it is usually better design to have two methods, one that counts and one that doesn't. In any case, yes, the weakness of naming conventions is that there are always odd-corner cases of natural language. Perhaps `name` is also a flag telling the method whether or not to name something. But then, one can write crappy APIs in any language. -- Steven From deets at nospam.web.de Wed Feb 3 19:09:04 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 01:09:04 +0100 Subject: Passing parameters in URL In-Reply-To: <7xr5p1dh2x.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> Message-ID: <7suhh1Ft2dU1@mid.uni-berlin.de> Am 04.02.10 00:39, schrieb Paul Rubin: > "Diez B. Roggisch" writes: >> Of course only information not gathered is really safe >> information. But every operation that has side-effects is reproducable >> anyway, and if e.g. your chat-app has a history, you can as well log >> the parameters. > > No I can't. The chat-app history would be on the client, not the > server, so I'd have no access to it. Put another way: as server > operator, I'm like the owner of a coffee shop. I can't stop patrons > from recording their own conversations with each other, and it's not > even really my business whether they do that. But it would be > outrageous for the shop owner to record the conversations of patrons. Which is the exact thing that happens when you use an email-provider with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I wouldn't call outrageous. This discussion moves away from the original question: is there anything inherently less secure when using GET vs. POST. There isn't. Users can forge both kind of requests easy enough, whoever sits in the middle can access both, and it's at the discretion of the service provider to only save what it needs to. If you don't trust it, don't use it. Diez From news123 at free.fr Wed Feb 3 19:18:31 2010 From: news123 at free.fr (News123) Date: Thu, 04 Feb 2010 01:18:31 +0100 Subject: pychecker and "import my.special.module as mymod" Message-ID: <4b6a1257$0$12211$426a34cc@news.free.fr> Hi, I'm not really used to structuring modules withn directories, but I started playing ##################################### # the commands to reproduce my setup: ##################################### mkdir -p my/special touch my/__init__.py my/special/__init__.py echo 'print "myspecialmod"' > my/special/module.py echo "import my.special.module as mymod" > tst.py so I have now following files: -rw-r--r-- 1 0 2010-02-04 01:05 ./my/__init__.py -rw-r--r-- 1 131 2010-02-04 01:07 ./my/__init__.pyc -rw-r--r-- 1 0 2010-02-04 01:05 ./my/special/__init__.py -rw-r--r-- 1 139 2010-02-04 01:07 ./my/special/__init__.pyc -rw-r--r-- 1 21 2010-02-04 01:06 ./my/special/module.py -rw-r--r-- 1 159 2010-02-04 01:07 ./my/special/module.pyc -rw-r--r-- 1 34 2010-02-04 01:07 ./tst.py the program tst.py runs as expected: > $ python tst.py > myspecialmod However pychecker gives me two warnings: > $ pychecker tst.py > Processing module tst (tst.py)... > myspecialmod > > Warnings... > > tst.py:1: Imported module (my.special.module) not used > tst.py:1: No module attribute (special) found I understand the first one and this one will not appear in my real code. However I don't really understand the second one. So my questions are: - Is this a real warning or is this 'just' a pychecker problem? - Can I write my code such, that the warning will not appear? - Is there a pychecker switch, which would get rid of this warning? thanks a lot in advance for your answers / suggestions N From no.email at nospam.invalid Wed Feb 3 19:35:41 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 16:35:41 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> Message-ID: <7x3a1h7s82.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: >> But it would be outrageous for the shop owner to record the >> conversations of patrons. > > Which is the exact thing that happens when you use an email-provider > with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I > wouldn't call outrageous. Those are not comparable. IMAP is a storage service, and groups, facebook, and twitter are publishing systems (ok, I've never understood quite what Google Wave is). Yes, by definition, your voice mail provider (like IMAP) has to save recordings of messages people leave you, but that's a heck of a lot different than your phone carrier recording your real-time conversations. Recording live phone conversations by a third party is called a "wiretap" and doing it without suitable authorization can get you in a heck of a lot of trouble. > This discussion moves away from the original question: is there > anything inherently less secure when using GET vs. POST. There isn't. Well, the extra logging of GET parameters is not inherent to the protocol, but it's an accidental side effect that server ops may have to watch out for. > Users can forge both kind of requests easy enough, whoever sits in the > middle can access both, I'm not sure what you mean by that. Obviously if users want to record their own conversations, then I can't stop them, but that's much different than a non-participant in the conversation leaving a recorder running 24/7. Is that so hard to understand? Interception from the middle is addressed by SSL, though that relies on the PKI certificate infrastructure, which while somewhat dubious, is better than nothing. > and it's at the discretion of the service provider to only save what > it needs to. If you don't trust it, don't use it. I certainly didn't feel that saving or not saving client conversations on the server side was up to my discretion. When I found that the default server configuration caused conversations to be logged then I was appalled. Do you think the phone company has the right to record all your phone calls if they feel like it (absent something like a law enforcement investigation)? What about coffee shops that you visit with your friends? It is not up to their discretion. They have a positive obligation to not do it. If you think they are doing it on purpose without your authorization, you should notify the FBI or your equivalent, not just "don't use it". If they find they are doing it inadvertently, they have to take measures to make it stop. That is the situation I found myself in, because of the difference in how servers treat GET vs. POST. From monaghand.david at gmail.com Wed Feb 3 19:39:01 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Thu, 04 Feb 2010 00:39:01 +0000 Subject: Python 3 minor irritation Message-ID: I have a small program which reads files from the directory in which it resides. It's written in Python 3 and when run through IDLE or PythonWin works fine. If I double-click the file, it works fine in Python 2.6, but in 3 it fails because it looks for the files to load in the Python31 folder, not the one the script is in. It's not a big deal, but browsing around I haven't found why the behaviour has been changed or any comment about it (That might be my poor search technique, I suppose). The program fails at: try: tutdoc = minidom.parse(".//Myfile.xml") except IOError: DaveM From john at castleamber.com Wed Feb 3 19:42:39 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 18:42:39 -0600 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> Message-ID: <87iqadde68.fsf@castleamber.com> "Diez B. Roggisch" writes: > Am 03.02.10 19:11, schrieb John Bokma: >> Alan Harris-Reid writes: >> >>> I have a web-page where each row in a grid has edit/delete buttons to >>> enable the user to maintain a selected record on another page. The >>> buttons are in the form of a link with href='/item_edit?id=123', but >>> this string appears in the URL and gives clues as to how to bypass the >>> correct sequence of events, and could be risky if they entered the URL >>> directly (especially when it comes to deleting records). >> >> You should *never* use a GET request to do actions like deleting >> records. You already are aware of it being risky, so don't do this. You >> should use GET for getting information, and POST for modifying information. > > You should *never* say never, because there might be situations where > exceptions from rules are valid. This is one such cases. Making this a > post means that you need to resort to javascript to populate & submit > a hidden HTML-form. Just for the sake of a POST. Make each edit/delete button a submit button and optionally style it. > Also, your claim of it being more risky is simply nonsense. GET is a > tiny bit more prone to tinkering by the average user. But calling this > less risky is promoting security by obscurity, at most. Maybe you should think about what happens if someone posts: to a popular forum... -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From robert.kern at gmail.com Wed Feb 3 19:49:58 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 18:49:58 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-03 18:01 PM, Steven D'Aprano wrote: > On Wed, 03 Feb 2010 16:38:21 -0600, Robert Kern wrote: > >>>> class.method(name, count) >>> >>> Obviously? I don't know about that. Being told that "count" is an int >>> doesn't really help me -- it's obvious just from the name. In a well- >>> written API, what else could it be? >> >> A bool. As in telling the method whether or not it should count >> something. > > Ha ha, good point. I question that this is a well-written API: such flags > to change the behaviour of a function/method are generally poor design. > If method behaves differently depending on whether or not you want it to > count something, then it is usually better design to have two methods, > one that counts and one that doesn't. I prefer Guido's formulation (which, naturally, I can't find a direct quote for right now): if you expect that a boolean argument is only going to take *literal* True or False, then it should be split into two functions. There is a use case for a boolean argument like this when you can expect to pass around a variable between multiple functions. Of course, this also might be the private API that the public API (with two distinct methods for each case) uses internally in order to avoid code duplication. Private APIs need to be documented, too. > In any case, yes, the weakness of naming conventions is that there are > always odd-corner cases of natural language. Perhaps `name` is also a > flag telling the method whether or not to name something. > > But then, one can write crappy APIs in any language. Well, I'm not trying to make Paul's point that other languages are better in this regard. I think that type documentation is quite helpful, but requiring static type declaration to get that documentation is an undesirable tradeoff for most of the code that I want to write. I do think it is worthwhile to recognize that the tradeoff does cut the other way, too. It just so happens that Python has docstrings and argument annotations to document argument types without the burden of static typing. Not all good, clean APIs are always going to have argument names that clearly inform the kind of type it expects. And what an author thinks is obviously deducible while writing the API is often quite different from what a new user thinks is obvious. There isn't much reason to place that cognitive burden on the (many) readers of the code when the (single) author can put in a word or two into the docstring (once) to describe what the parameter is expected to be. Figuring out how to use an API to solve your real problem is hard enough without having your brainpower nickled-and-dimed at every turn. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at holdenweb.com Wed Feb 3 19:52:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 19:52:28 -0500 Subject: PyChecker under python's virtualenv In-Reply-To: <7sub7uFstoU1@mid.uni-berlin.de> References: <7sub7uFstoU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Am 03.02.10 22:46, schrieb soltys: >> Hi Everybody, >> I've been doing some test on pythons' virtualenv and recently I've >> decided to run PyChecker. But I'm having some difficulties with importing >> modules available only on virtualenv by pychecker. As if it was >> trying to use systemwide python. >> I've googled about it, and found nothing in this area. >> I installed pychecker using python setup.py install >> from virtualenv. I looked at pychecker script - it uses correct python. > > I doubt that it uses the "correct python", because then you wouldn't > have the problems you have. > > I don't use pychecker, but pylint. And there, the system-wide command > uses the system's python - which of course doesn't know anything about > virtualenv. > > There are two solutions to this problem: > > - install py(lint|checker) into your virtualenv. See the OP's original assertion: >> I installed pychecker using python setup.py install >> from virtualenv. I looked at pychecker script - it uses correct python. Isn't that "installing into his virtualenv"? regards Steve > - write a wrapper-script that invokes py(lint|checker) with an adapted > PYTHONPATH environtment variable, based on the venv's sys.path. I do > that for my epylint-wrapper for emacs. Works flawlessly. > > > Diez -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 3 19:55:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 19:55:45 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: Vladimir Ignatov wrote: >> can you sketch an example/use case more concretely? > > Sorry, I don't have anything written down. I just have some rough idea > of implementation and some concrete features I would like to see in > such system. For example: > > 1) Instant refactoring. No more needs for manual > search/inspect/rename. Since system knows exactly that is going on, > the refactoring will be fully automatic. You'll probably want to take a look at "Bicycle Repair Man", which offers Python refactoring functionality. > 2) Show "xref table" for each function. How often this function used? > Where is it used? (code snippets of calls) What functionality is > supported by this function? Bear in mind this information can only ever be partial, since functions are first-class objects and aren't always referred to by their original name. > 3) Extended statistics. How many objects this object/function > interacts with? Popular functions, dead/unused functions. > 4) Code smell detector - too long functions, too much interaction with > other objects, global objects, etc. > ... > Also take a look at pylint and pychecker, which are already built to perform that kind of check on Python code. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From john at castleamber.com Wed Feb 3 19:56:10 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 18:56:10 -0600 Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <87eil1ddjp.fsf_-_@castleamber.com> Lou Pecora writes: > That's a pretty accurate description of how I transitioned to Python > from C and Fortran. Not C, but C++ (but there are also C implementations): YAML, see: http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument I use YAML now and then with Perl for both reading/writing data and for debugging purposes (YAML is quite human readable, for programmers at least) Of course there is also YAML support for Python: http://pyyaml.org/. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From wuwei23 at gmail.com Wed Feb 3 20:03:47 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 3 Feb 2010 17:03:47 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <1dbae543-f4f4-4a79-bcda-58498a9c375d@f17g2000prh.googlegroups.com> Adam Tauno Williams wrote: > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" Could you provide an actual example to support this? The only places I tend to see 'x' as a parameter in the Python library docs are where it's clearly a number, or the text immediately beneath it explains exactly what it is. random.seed([x]) Initialize the basic random number generator. Optional argument x can be any hashable object. Everywhere else, the docs seem to declare what the parameters should be _and_ explains them in the text: itertools.combinations(iterable, r) Return r length subsequences of elements from the input iterable. If you're finding places in the docs where this isn't the case, I'd treat them as a documentation bug and report them. If it's not obvious to you what an iterable is, well, I'm sure you've got a disparaging term for those of us who do... From aahz at pythoncraft.com Wed Feb 3 20:32:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2010 17:32:31 -0800 Subject: Selenium/SauceLabs OpenSpace at Pycon References: Message-ID: In article , Raymond Hettinger wrote: > >For those who are interested, the Sauce Labs team, >http://saucelabs.com/about/team, is hosting two free tutorial open >space sessions at Pycon in Atlanta. Congrats on the new job! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From icanbob at gmail.com Wed Feb 3 20:40:00 2010 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 3 Feb 2010 17:40:00 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <4b497d3e-32c5-4e4f-b607-fb1b5a51f519@k22g2000vbp.googlegroups.com> On Feb 3, 3:32 am, News123 wrote: > Hi, > > I wondered what IPC library might be best simplest for following task? > > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) > > these scripts want to send short messages to each other ( mostly > integers, max a few bytes, short string), which would be enqueued in > message queues of the receiving process. > > example: > > 'dad' wants to tell 'mom': 'cook' > 'dog' wants to tell 'dad' : 'feedme' > 'mom' wants to tell 'dad' : 'cookyourself' > > the receiver dos not necesarily have to know who sent the message > > a message shall be dropped silently if the receiving process is not running > > a message shall be reliably delivered if the receiving process is up > > xmlrpc seems to be a little heavy for such tasks. > > signals don't allow to exchange data > > a shared memory message queue would probably a good solution, but > python's Multiprocessing.Queue seems to require a common parent process > > thanks a lot for any ideas / suggestions > > N > > N Have a look at the SIMPL toolkit (http://www.icanprogram.com/simpl or http://www.icanprogram.com/06py/main.html). It should do everything you describe at least on the Linux end of the spectrum. Under the hood SIMPL uses a shared memory scheme for local message exchange. SIMPL would be especially effective if you want to move your modules at some future point onto different nodes. SIMPL-Python can work seamlessly on heterogeneous networks provided at least one node is Linux. bob From ben+python at benfinney.id.au Wed Feb 3 20:46:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Feb 2010 12:46:27 +1100 Subject: Dreaming of new generation IDE References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: <87k4utn570.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 03 Feb 2010 18:48:12 +0300, Vladimir Ignatov wrote: > > [?] system "knows" all your identifiers and just regenerates > > relevant portions of text from internal database-alike > > representation. You will probably want to learn about ?refactoring? to see if that's related to what you mean . > Something like Bicycle Repair Man then: Bicycle Repair Man has not shown any development activity since 2004. Which is a shame, because it's an awesomely appropriate name for what it does :-) The niche is now occupied by the Rope library and tools . -- \ ?Holy knit one purl two, Batman!? ?Robin | `\ | _o__) | Ben Finney From no.email at nospam.invalid Wed Feb 3 20:51:36 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 17:51:36 -0800 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <7xbpg5dazb.fsf@ruckus.brouhaha.com> John Nagle writes: > Analysis of each domain is > performed in a separate process, but each process uses multiple > threads to read process several web pages simultaneously. > > Some of the threads go compute-bound for a second or two at a time as > they parse web pages. You're probably better off using separate processes for the different pages. If I remember, you were using BeautifulSoup, which while very cool, is pretty doggone slow for use on large volumes of pages. I don't know if there's much that can be done about that without going off on a fairly messy C or C++ coding adventure. Maybe someday someone will do that. From ben+python at benfinney.id.au Wed Feb 3 20:57:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Feb 2010 12:57:18 +1100 Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: <87fx5hn4ox.fsf@benfinney.id.au> Robert Kern writes: > It is perfectly reasonable (and often necessary) for the unit test of > class B to use a mock object instead of a real A() instance. The unit > test for class B will fail to catch the renaming of A.foo() to A.bar() > because it never tries to call .foo() on a real A instance. Right, which is one good reason why unit tests are *necessary* but not *sufficient*. You also need so-called ?integration? tests (make sure modules work together as expected) and ?system? tests (make sure the whole running system behaves as expected). This need for testing is true regardless of whether you're using a statically-typed or dynamically-typed language, of course. (I hope no-one here thinks that static typing obviates the need for integration and system tests in the test suite.) -- \ ?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 wuwei23 at gmail.com Wed Feb 3 21:08:52 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 3 Feb 2010 18:08:52 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> Message-ID: <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> On Feb 4, 8:47?am, Phlip wrote: > Yes, calling os.path.walk() and os.path.join() all the time on raw > strings is fun, but I seem to recall from my Ruby days a class called > Pathname, which presented an object that behaved like a string at > need, and like a filesystem path at need. path + 'folder' would > call .join() and insert the / correctly, for example. > > What's the best equivalent in Python-land? It's no longer supported, but the 3rd party 'path' module used to be the go-to module for this: >>> from path import path C:\Python26\lib\site-packages\path.py:32: DeprecationWarning: the md5 module is deprecated; use hashlib instead import sys, warnings, os, fnmatch, glob, shutil, codecs, md5 >>> c = path('C:\\') >>> c.listdir() [path(u'C:\\AUTOEXEC.BAT'), path(u'C:\\boot.ini'), ...] >>> (c + 'python26').listdir() [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ \python26\\DLLs'), ...] >>> (c / 'python26').listdir() [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ \python26\\DLLs'), ...] I've hand edited the results for brevity... The module could do with some TLC to bring it up to date, but warning aside it still seems to work fine under 2.6. (From memory, I think the original author gave up when it became clear it would never be integrated into the standard lib[1], which is a shame, I think there's scope for a pathtools addition to the lib that provides this level of convenience...) There was also a PEP with another possible implementation: http://www.python.org/dev/peps/pep-0355/ Hope this helps. From wuwei23 at gmail.com Wed Feb 3 21:17:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 3 Feb 2010 18:17:06 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <4da2372c-954c-46b8-a6e9-2768bce812f5@l19g2000yqb.googlegroups.com> Message-ID: "Timothy N. Tsvetkov" wrote: > Jonathan Gardner > > Python is much, much cleaner. I don't know how anyone can honestly say > > Ruby is cleaner than Python. > > I developed on both (Python was first) and I think that ruby I > very clean and maybe cleaner than Python. > > And you're wrong with blocks. You say 'static', and I say 'dynamic'. You say 'consistent', and I say 'erratic'. Static! Dynamic! Consistent! Erratic! Let's join the right news group. From mf2286 at gmail.com Wed Feb 3 21:33:33 2010 From: mf2286 at gmail.com (mf) Date: Wed, 3 Feb 2010 18:33:33 -0800 (PST) Subject: Repeat an exception Message-ID: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> I'm translating a db from english to spanish with the Google translator API. The problem is when a TranslationError occurs(usually because of connection problems). I can except the first one, but I don't know how to except again. I "solved" the problem by saving temp db's and then joining them, but it must be a pythonic way to do it. Here's a snippet from the code: english_field = oldDb[i].fieldData[0] #oldDb is a db filled with english words try: spanish_field = translate(english_field, lang_to='es', lang_from='en') except TranslationError: spanish_field = translate(english_field, lang_to='es', lang_from='en') #Then I save the fields into a new db From nobody at nowhere.com Wed Feb 3 21:52:14 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Feb 2010 02:52:14 +0000 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 03 Feb 2010 14:09:07 -0800, Paul Rubin wrote: >> Also, your claim of it being more risky is simply nonsense. GET is a >> tiny bit more prone to tinkering by the average user. But calling this >> less risky is promoting security by obscurity, at most. > > GET parameters also tend to get recorded in the http logs of web proxies > and web servers while POST parameters usually aren't. More significantly, they'll appear in the Referer: header for any link the user follows from the page, so they're visible to anyone who can get a link to their site onto the page (whether , or whatever). Even if this isn't possible at the moment, will you remember to fix it the first time you allow an off-site link? You should assume that anything which goes into a GET request is visible to the entire world. Don't put anything even remotely private in there. From alfps at start.no Wed Feb 3 21:56:53 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 03:56:53 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * David Monaghan: > I have a small program which reads files from the directory in which it > resides. It's written in Python 3 and when run through IDLE or PythonWin > works fine. If I double-click the file, it works fine in Python 2.6, but in > 3 it fails because it looks for the files to load in the Python31 folder, > not the one the script is in. > > It's not a big deal, but browsing around I haven't found why the behaviour > has been changed or any comment about it (That might be my poor search > technique, I suppose). > > The program fails at: > > try: > tutdoc = minidom.parse(".//Myfile.xml") > except IOError: > The "//" is wrong, but should not cause the behavior that you describe. Try to post a complete smallest possible program that exhibits the problem. Possibly, in creating that example you'll also find what's cause the problem. :-) Cheers & hth., - Alf From alfps at start.no Wed Feb 3 22:00:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 04:00:45 +0100 Subject: Repeat an exception In-Reply-To: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> Message-ID: * mf: > I'm translating a db from english to spanish with the Google > translator API. The problem is when a TranslationError occurs(usually > because of connection problems). I can > except the first one, but I don't know how to except again. I "solved" > the problem by saving temp db's and then joining them, but it must be > a pythonic way to do it. > > Here's a snippet from the code: > > english_field = oldDb[i].fieldData[0] #oldDb is a db filled > with english words Is this actual code? I may be mistaken, but at least in Python 3.x it seems there should be a comma between each 'with' expression. And there should certainly be a colon at the end. It's best to copy and paste real code. Made-up code can just be misleading for those who'd like to help. > try: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > except TranslationError: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > > #Then I save the fields into a new db Possibly I'm misunderstanding what you mean, but have you thought of using a loop? Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Wed Feb 3 22:09:02 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 00:09:02 -0300 Subject: Code snippet: dualmethod descriptor References: <0373b8b9$0$1309$c3e8da3@news.astraweb.com> Message-ID: En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano escribi?: > class dualmethod(object): > """Descriptor implementing dualmethods (combination > class/instance method). > > Returns a method which takes either an instance or a class as > the first argument. When called on an instance, the instance is > passed as the first argument. When called as a class, the class > itself is passed instead. Seems useful! Perhaps a better place to post it would be , at least it's easier to search. -- Gabriel Genellina From benjamin.kaplan at case.edu Wed Feb 3 22:14:59 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Feb 2010 22:14:59 -0500 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: > * David Monaghan: >> >> I have a small program which reads files from the directory in which it >> resides. It's written in Python 3 and when run through IDLE or PythonWin >> works fine. If I double-click the file, it works fine in Python 2.6, but >> in >> 3 it fails because it looks for the files to load in the Python31 folder, >> not the one the script is in. >> >> It's not a big deal, but browsing around I haven't found why the behaviour >> has been changed or any comment about it (That might be my poor search >> technique, I suppose). >> >> The program fails at: >> >> ? ?try: >> ? ? ? ?tutdoc = minidom.parse(".//Myfile.xml") >> ? ?except IOError: >> ? ? ? ? > > The "//" is wrong, but should not cause the behavior that you describe. > > Try to post a complete smallest possible program that exhibits the problem. > > Possibly, in creating that example you'll also find what's cause the > problem. :-) > > > Cheers & hth., > > - Alf That is the smallest example the exhibits the problem. It's not an issue with the Python code, it's an issue with how Windows is running it. I don't know enough about the way Windows Explorer runs files, but it seems to be doing the equivalent of cd C:\Python31 python31.exe C:\full\path\to\script\foo.py instead of cd C:\full\path\path\to\script C:\Python31\python.exe foo.py which is David expected. This throws off the relative filepath. The easiest way to solve this permanently, by the way, is to not use relative paths. All it takes is one script to call os.chdir and the script breaks. You can use __file__ and the os.path module to figure out exactly where you are in an OS-agnostic way. import os.path #get the absolute path to the current script abs_path = os.path.abspath(__file__) # get the full path to the directory of the script directory = os.path.dirname(abs_path) #get the full path to your file my_file = os.path.join(directory, "MyFile.xml") > -- > http://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Wed Feb 3 22:17:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Feb 2010 03:17:43 +0000 Subject: Repeat an exception In-Reply-To: References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> Message-ID: <4B6A3C57.2000606@mrabarnett.plus.com> Alf P. Steinbach wrote: > * mf: >> I'm translating a db from english to spanish with the Google >> translator API. The problem is when a TranslationError occurs(usually >> because of connection problems). I can >> except the first one, but I don't know how to except again. I "solved" >> the problem by saving temp db's and then joining them, but it must be >> a pythonic way to do it. >> >> Here's a snippet from the code: >> >> english_field = oldDb[i].fieldData[0] #oldDb is a db filled >> with english words > > Is this actual code? I may be mistaken, but at least in Python 3.x it > seems there should be a comma between each 'with' expression. And there > should certainly be a colon at the end. > > It's best to copy and paste real code. > > Made-up code can just be misleading for those who'd like to help. > It looks to me like the line wrapped during posting, ie the 'with' part belongs to the comment. > >> try: >> spanish_field = translate(english_field, lang_to='es', >> lang_from='en') >> except TranslationError: >> spanish_field = translate(english_field, lang_to='es', >> lang_from='en') >> >> #Then I save the fields into a new db > > Possibly I'm misunderstanding what you mean, but have you thought of > using a loop? > In other words: for attempt in range(2): try: spanish_field = translate(english_field, lang_to='es', lang_from='en') break except TranslationError: pass else: # Didn't break out of the loop, therefore not successful. print "Translation failed" From michael.gruenstaeudl at mail.utexas.edu Wed Feb 3 22:33:08 2010 From: michael.gruenstaeudl at mail.utexas.edu (Michael Gruenstaeudl) Date: Wed, 03 Feb 2010 21:33:08 -0600 Subject: Refreshing of urllib.urlopen() Message-ID: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> Hi, I am fairly new to Python and need advice on the urllib.urlopen() function. The website I am trying to open automatically refreshes after 5 seconds and remains stable thereafter. With urllib.urlopen().read() I can only read the initial but not the refreshed page. How can I access the refreshed page via urlopen().read()? I have already tried to intermediate with time.sleep() before invoking .read() (see below), but this does not work. page=urllib.urlopen(url) time.sleep(20) htmltext=page.readlines() Thanks, Michael G. From alfps at start.no Wed Feb 3 22:44:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 04:44:00 +0100 Subject: Repeat an exception In-Reply-To: References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> Message-ID: * MRAB: > Alf P. Steinbach wrote: >> * mf: >>> I'm translating a db from english to spanish with the Google >>> translator API. The problem is when a TranslationError occurs(usually >>> because of connection problems). I can >>> except the first one, but I don't know how to except again. I "solved" >>> the problem by saving temp db's and then joining them, but it must be >>> a pythonic way to do it. >>> >>> Here's a snippet from the code: >>> >>> english_field = oldDb[i].fieldData[0] #oldDb is a db filled >>> with english words >> >> Is this actual code? I may be mistaken, but at least in Python 3.x it >> seems there should be a comma between each 'with' expression. And >> there should certainly be a colon at the end. >> >> It's best to copy and paste real code. >> >> Made-up code can just be misleading for those who'd like to help. >> > It looks to me like the line wrapped during posting, ie the 'with' part > belongs to the comment. *banging me head* thx What one gets from conditioning oneself to ignore comments in code. >>> try: >>> spanish_field = translate(english_field, lang_to='es', >>> lang_from='en') >>> except TranslationError: >>> spanish_field = translate(english_field, lang_to='es', >>> lang_from='en') >>> >>> #Then I save the fields into a new db >> >> Possibly I'm misunderstanding what you mean, but have you thought of >> using a loop? >> > In other words: > > for attempt in range(2): > try: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > break > except TranslationError: > pass > else: > # Didn't break out of the loop, therefore not successful. > print "Translation failed" Cheers, - Alf From nagle at animats.com Wed Feb 3 22:46:43 2010 From: nagle at animats.com (John Nagle) Date: Wed, 03 Feb 2010 19:46:43 -0800 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <7xbpg5dazb.fsf@ruckus.brouhaha.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> Message-ID: <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Paul Rubin wrote: > John Nagle writes: >> Analysis of each domain is >> performed in a separate process, but each process uses multiple >> threads to read process several web pages simultaneously. >> >> Some of the threads go compute-bound for a second or two at a time as >> they parse web pages. > > You're probably better off using separate processes for the different > pages. If I remember, you were using BeautifulSoup, which while very > cool, is pretty doggone slow for use on large volumes of pages. I don't > know if there's much that can be done about that without going off on a > fairly messy C or C++ coding adventure. Maybe someday someone will do > that. I already use separate processes for different domains. I could live with Python's GIL as long as moving to a multicore server doesn't make performance worse. That's why I asked about CPU dedication for each process, to avoid thrashing at the GIL. There's enough intercommunication between the threads working on a single site that it's a pain to do them as subprocesses. And I definitely don't want to launch subprocesses for each page; the Python load time would be worse than the actual work. The subprocess module assumes you're willing to launch a subprocess for each transaction. The current program organization is that there's a scheduler process which gets requests, prioritizes them, and runs the requested domains through the site evaluation mill. The scheduler maintains a pool of worker processes which get work request via their input pipe, in Pickle format, and return results, again in Pickle format. When not in use, the worker processes sit there dormant, so there's no Python launch cost for each transaction. If a worker process crashes, the scheduler replaces it with a fresh one, and every few hundred uses, each worker process is replaced with a fresh copy, in case Python has a memory leak. It's a lot like the way FCGI works. Scheduling is managed using an in-memory table in MySQL, so the load can be spread over a cluster if desired, with a scheduler process on each machine. So I already have a scalable architecture. The only problem is excess overhead on multicore CPUs. John Nagle From cmpython at gmail.com Wed Feb 3 22:50:00 2010 From: cmpython at gmail.com (CM) Date: Wed, 3 Feb 2010 19:50:00 -0800 (PST) Subject: Background Zones in Pylab Plot References: <1eaf6046-db41-44b5-8c9e-b7a15e4cf078@30g2000vbj.googlegroups.com> Message-ID: <5a9e5eaf-2006-4dfe-8498-a544c09a8584@r6g2000yqn.googlegroups.com> On Feb 3, 10:49?am, Wanderer wrote: > I would like to add background zones in pylab plots. Colored sections > of the background that the curves pass through. Is this possible? My > google searches don't turn up anything but maybe my search terms > aren't the right ones. > > Thanks If you look at the matplotlib gallery, I think there may be some images that show something like what you want, and then you can look at the code. It's here: http://matplotlib.sourceforge.net/gallery.html HTH, Che From steve at holdenweb.com Wed Feb 3 22:50:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 22:50:19 -0500 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4b6a3f46$0$1597$742ec2ed@news.sonic.net> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Paul Rubin wrote: >> John Nagle writes: >>> Analysis of each domain is >>> performed in a separate process, but each process uses multiple >>> threads to read process several web pages simultaneously. >>> >>> Some of the threads go compute-bound for a second or two at a time as >>> they parse web pages. >> >> You're probably better off using separate processes for the different >> pages. If I remember, you were using BeautifulSoup, which while very >> cool, is pretty doggone slow for use on large volumes of pages. I don't >> know if there's much that can be done about that without going off on a >> fairly messy C or C++ coding adventure. Maybe someday someone will do >> that. > > I already use separate processes for different domains. I could > live with Python's GIL as long as moving to a multicore server > doesn't make performance worse. That's why I asked about CPU dedication > for each process, to avoid thrashing at the GIL. > I believe it's already been said that the GIL thrashing is mostly MacOS specific. You might also find something in the affinity module http://pypi.python.org/pypi/affinity/0.1.0 to ensure that each process in your pool runs on only one processor. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From hidura at gmail.com Wed Feb 3 23:00:56 2010 From: hidura at gmail.com (Hidura) Date: Thu, 4 Feb 2010 00:00:56 -0400 Subject: Problem with __init__.py in Python3.1 Message-ID: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> Good evening list, I have a really big trouble with the imports in the 3.1 version(Notes: In the older 2.64 theres no problems), I have two packages, the first package Utilities who contains Writer the second package, Writers contain the module tagmanip(What is imported in the best way inside the __init__.py of the Writer), when i make the import inside the writer everything is ok, but from the Utilities package the errors says: "ImportError: No module named tagsmanip". I don't understand why this is happening, if somebody could help me i will glad to hear any suggestion. Atte. -- Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 3 23:02:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 23:02:35 -0500 Subject: Refreshing of urllib.urlopen() In-Reply-To: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> References: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> Message-ID: Michael Gruenstaeudl wrote: > Hi, > I am fairly new to Python and need advice on the urllib.urlopen() > function. The website I am trying to open automatically refreshes after > 5 seconds and remains stable thereafter. With urllib.urlopen().read() I > can only read the initial but not the refreshed page. How can I access > the refreshed page via urlopen().read()? I have already tried to > intermediate with time.sleep() before invoking .read() (see below), but > this does not work. > > page=urllib.urlopen(url) > time.sleep(20) > htmltext=page.readlines() > When you say the page "refreshes" every 5 seconds, does it do so by redirecting the browser to the same address with new content? I suspect this is the case, because otherwise page.readlines() would not return because it wouldn't have seen the "end of file" on the incoming network stream. You can find this out by examining the page's headers. If page.headers['Refresh'] exists and has a value (like "5; url=http://") then browser refresh is being used. If that's so then the only way to access the content is to re-open the URL and read the updated content. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From kmisoft at gmail.com Wed Feb 3 23:13:18 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 07:13:18 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <87k4utn570.fsf@benfinney.id.au> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <87k4utn570.fsf@benfinney.id.au> Message-ID: >> > [?] system "knows" all your identifiers and just regenerates >> > relevant portions of text from internal database-alike >> > representation. > > You will probably want to learn about ?refactoring? to see if that's > related to what you mean . I mean if system actually "understands" your code (instead of try to figure it out from existing text files with source code), then much more complex refactoring is possible. My favorite refactoring is "Replace Method with Method Object". It is hard to imagine "external" tool that can provide such refactoring for python code. >> Something like Bicycle Repair Man then: > Bicycle Repair Man has not shown any development activity since 2004. > Which is a shame, because it's an awesomely appropriate name for what it > does :-) I believe it still live under the hood of PyDev plugin. I use it almost every day and need to say that it don't provide much more than simple renaming (which works right in 80% of cases in recent version). Vladimir Ignatov From alfps at start.no Wed Feb 3 23:18:38 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 05:18:38 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * Benjamin Kaplan: > On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: >> * David Monaghan: >>> I have a small program which reads files from the directory in which it >>> resides. It's written in Python 3 and when run through IDLE or PythonWin >>> works fine. If I double-click the file, it works fine in Python 2.6, but >>> in >>> 3 it fails because it looks for the files to load in the Python31 folder, >>> not the one the script is in. >>> >>> It's not a big deal, but browsing around I haven't found why the behaviour >>> has been changed or any comment about it (That might be my poor search >>> technique, I suppose). >>> >>> The program fails at: >>> >>> try: >>> tutdoc = minidom.parse(".//Myfile.xml") >>> except IOError: >>> >> The "//" is wrong, but should not cause the behavior that you describe. >> >> Try to post a complete smallest possible program that exhibits the problem. >> >> Possibly, in creating that example you'll also find what's cause the >> problem. :-) >> >> >> Cheers & hth., >> >> - Alf > > That is the smallest example the exhibits the problem. No, it doesn't seem to exhibit the problem at all. :-) > It's not an > issue with the Python code, it's an issue with how Windows is running > it. I don't know enough about the way Windows Explorer runs files, but > it seems to be doing the equivalent of > cd C:\Python31 > python31.exe C:\full\path\to\script\foo.py > > instead of > cd C:\full\path\path\to\script > C:\Python31\python.exe foo.py > which is David expected. This throws off the relative filepath. No, this is not what happens. What happens is that when you double-click the script, then __file__ is set to the absolute path instead of just the filename, at least on my machine (XP); whether the full path or just the filename is passed on the OS level depends, however, on the Windows version. The current directory is always (initially) correct, as the script's directory. > The easiest way to solve this permanently, by the way, is to not use > relative paths. All it takes is one script to call os.chdir and the > script breaks. You can use __file__ and the os.path module to figure > out exactly where you are in an OS-agnostic way. > > import os.path > #get the absolute path to the current script > abs_path = os.path.abspath(__file__) According to the docs: "On most platforms, this is equivalent to normpath(join(os.getcwd(), path))." Therefore, if getcwd() is not the script's directory, as you hypothesize above, then most likely the result of this code is Not The Path You're Looking For. However, since the current directory is in fact OK, the above is one way to get a sort of canonical (a where-you-know-the-format) representation of __file__. > # get the full path to the directory of the script > directory = os.path.dirname(abs_path) This is very much likely to yield the same result as calling os.getcwd(); see above. > #get the full path to your file > my_file = os.path.join(directory, "MyFile.xml") Cheers & hth., - Alf From benjamin.kaplan at case.edu Wed Feb 3 23:41:00 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Feb 2010 23:41:00 -0500 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: On Wed, Feb 3, 2010 at 11:18 PM, Alf P. Steinbach wrote: > * Benjamin Kaplan: >> >> On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: >>> >>> * David Monaghan: >>>> >>>> I have a small program which reads files from the directory in which it >>>> resides. It's written in Python 3 and when run through IDLE or PythonWin >>>> works fine. If I double-click the file, it works fine in Python 2.6, but >>>> in >>>> 3 it fails because it looks for the files to load in the Python31 >>>> folder, >>>> not the one the script is in. >>>> >>>> It's not a big deal, but browsing around I haven't found why the >>>> behaviour >>>> has been changed or any comment about it (That might be my poor search >>>> technique, I suppose). >>>> >>>> The program fails at: >>>> >>>> ? try: >>>> ? ? ? tutdoc = minidom.parse(".//Myfile.xml") >>>> ? except IOError: >>>> ? ? ? >>> >>> The "//" is wrong, but should not cause the behavior that you describe. >>> >>> Try to post a complete smallest possible program that exhibits the >>> problem. >>> >>> Possibly, in creating that example you'll also find what's cause the >>> problem. :-) >>> >>> >>> Cheers & hth., >>> >>> - Alf >> >> That is the smallest example the exhibits the problem. > > No, it doesn't seem to exhibit the problem at all. :-) > > >> It's not an >> issue with the Python code, it's an issue with how Windows is running >> it. I don't know enough about the way Windows Explorer runs files, but >> it seems to be doing the equivalent of >> cd C:\Python31 >> python31.exe C:\full\path\to\script\foo.py >> >> instead of >> cd C:\full\path\path\to\script >> C:\Python31\python.exe foo.py >> which is David expected. This throws off the relative filepath. > > No, this is not what happens. > > What happens is that when you double-click the script, then __file__ is set > to the absolute path instead of just the filename, at least on my machine > (XP); whether the full path or just the filename is passed on the OS level > depends, however, on the Windows version. > > The current directory is always (initially) correct, as the script's > directory. > Read my first paragraph again- it has absolutely nothing to do with Python. It has to do with how the Windows is running Python 3 on the OP's computer. The OP's description said that it was looking for the file .\\myfile.xml in C:\Python31 which means it translated '.', the current working directory, to be C:\Python31 and not the directory the script is in. > >> The easiest way to solve this permanently, by the way, is to not use >> relative paths. All it takes is one script to call os.chdir and the >> script breaks. You can use __file__ and the os.path module to figure >> out exactly where you are in an OS-agnostic way. >> >> import os.path >> #get the absolute path to the current script >> abs_path = os.path.abspath(__file__) > > According to the docs: "On most platforms, this is equivalent to > normpath(join(os.getcwd(), path))." > os.path.abspath will always work in this case (unless something changes the current working directory before that statement runs) because __file__ is given either as an absolute path or as relative to the current working directory. ----- /Users/bkaplan/test/test.py print(__file__) import os.path print(os.path.abspath(__file__)) ------------------ $ cd /users/bkaplan $ python3 test/test.py python3 test/test.py test/test.py /Users/bkaplan/test/test.py $cd /users/bkaplan/test $ python3 test.py test.py /Users/bkaplan/test/test.py If abspath is given an absolute path, it won't touch it Output from double clicking on the file: /Users/bkaplan/test/test.py /Users/bkaplan/test/test.py > Therefore, if getcwd() is not the script's directory, as you hypothesize > above, then most likely the result of this code is Not The Path You're > Looking For. > Except that if the cwd is not the directory the script is running in, __file__ should still point to it either through an absolute path (highly likely since it's run through Windows Explorer) or some (however convoluted) relative path. > However, since the current directory is in fact OK, the above is one way to > get a sort of canonical (a where-you-know-the-format) representation of > __file__. > > >> ?# get the full path to the directory of the script >> directory = os.path.dirname(abs_path) > > This is very much likely to yield the same result as calling os.getcwd(); > see above. > Not if there is more than one folder between __file__ and cwd. For instance, if the script is in a package several directories down from the main script. > >> #get the full path to your file >> my_file = os.path.join(directory, "MyFile.xml") > > > Cheers & hth., > > - Alf > -- > http://mail.python.org/mailman/listinfo/python-list > From alfps at start.no Thu Feb 4 00:20:47 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 06:20:47 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * Benjamin Kaplan: > On Wed, Feb 3, 2010 at 11:18 PM, Alf P. Steinbach wrote: >> * Benjamin Kaplan: >>> On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: >>>> * David Monaghan: >>>>> I have a small program which reads files from the directory in which it >>>>> resides. It's written in Python 3 and when run through IDLE or PythonWin >>>>> works fine. If I double-click the file, it works fine in Python 2.6, but >>>>> in >>>>> 3 it fails because it looks for the files to load in the Python31 >>>>> folder, >>>>> not the one the script is in. >>>>> >>>>> It's not a big deal, but browsing around I haven't found why the >>>>> behaviour >>>>> has been changed or any comment about it (That might be my poor search >>>>> technique, I suppose). >>>>> >>>>> The program fails at: >>>>> >>>>> try: >>>>> tutdoc = minidom.parse(".//Myfile.xml") >>>>> except IOError: >>>>> >>>> The "//" is wrong, but should not cause the behavior that you describe. >>>> >>>> Try to post a complete smallest possible program that exhibits the >>>> problem. >>>> >>>> Possibly, in creating that example you'll also find what's cause the >>>> problem. :-) >>>> >>>> >>>> Cheers & hth., >>>> >>>> - Alf >>> That is the smallest example the exhibits the problem. >> No, it doesn't seem to exhibit the problem at all. :-) >> >> >>> It's not an >>> issue with the Python code, it's an issue with how Windows is running >>> it. I don't know enough about the way Windows Explorer runs files, but >>> it seems to be doing the equivalent of >>> cd C:\Python31 >>> python31.exe C:\full\path\to\script\foo.py >>> >>> instead of >>> cd C:\full\path\path\to\script >>> C:\Python31\python.exe foo.py >>> which is David expected. This throws off the relative filepath. >> No, this is not what happens. >> >> What happens is that when you double-click the script, then __file__ is set >> to the absolute path instead of just the filename, at least on my machine >> (XP); whether the full path or just the filename is passed on the OS level >> depends, however, on the Windows version. >> >> The current directory is always (initially) correct, as the script's >> directory. >> > > Read my first paragraph again- it has absolutely nothing to do with > Python. It has to do with how the Windows is running Python 3 on the > OP's computer. I'm not sure what you're arguing here. But anyway, first, I haven't stated that "it" is (only) an issue with Python: on the contrary, I explained how the program is run by Windows Explorer, where in Windows XP the full path is passed by Windows Explorer, and how that results in (can result in) a full path in __file__ when a script is run by double-clicking. Second, as stated your hypothesis about current directory is Wrong(TM). So the explanation of an incorrect result involves not only Windows Explorer, the Windows version, and Python, but also the OP's code is involved. Hence the request for a minimal, complete example -- which is nearly always a good idea. > The OP's description said that it was looking for the > file .\\myfile.xml in C:\Python31 which means it translated '.', the > current working directory, to be C:\Python31 and not the directory the > script is in. I fail to reproduce that behavior. By the way, are you the OP (just with another name)? If not, have you reproduced the described behavior? Then kindly post the code. >>> The easiest way to solve this permanently, by the way, is to not use >>> relative paths. All it takes is one script to call os.chdir and the >>> script breaks. You can use __file__ and the os.path module to figure >>> out exactly where you are in an OS-agnostic way. >>> >>> import os.path >>> #get the absolute path to the current script >>> abs_path = os.path.abspath(__file__) >> According to the docs: "On most platforms, this is equivalent to >> normpath(join(os.getcwd(), path))." >> > > os.path.abspath will always work in this case (unless something > changes the current working directory before that statement runs) Which change is what you surmised as a cause of the original problem. Hello. > because __file__ is given either as an absolute path or as relative to > the current working directory. No, that's incorrect. import os print( "Current directory: [" + os.getcwd() + "]" ) print( "__file__ = " + __file__ ) os.chdir( "blah" ) print( "Current directory: [" + os.getcwd() + "]" ) print( "__file__ = " + __file__ ) C:\Documents and Settings\Alf\test> python curdir.py Current directory: [C:\Documents and Settings\Alf\test] __file__ = curdir.py Current directory: [C:\Documents and Settings\Alf\test\blah] __file__ = curdir.py <-- *Not* relative to cwd. C:\Documents and Settings\Alf\test> _ [snip] > Except that if the cwd is not the directory the script is running in, > __file__ should still point to it either through an absolute path > (highly likely since it's run through Windows Explorer) or some > (however convoluted) relative path. Don't know about "should", but if you're talking reality, no, that's incorrect; see above. [snip] Cheers & hth., - Alf From alfps at start.no Thu Feb 4 00:46:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 06:46:45 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * Alf P. Steinbach: > * Benjamin Kaplan: >> On Wed, Feb 3, 2010 at 11:18 PM, Alf P. Steinbach wrote: >>> * Benjamin Kaplan: >>>> The easiest way to solve this permanently, by the way, is to not use >>>> relative paths. All it takes is one script to call os.chdir and the >>>> script breaks. You can use __file__ and the os.path module to figure >>>> out exactly where you are in an OS-agnostic way. >>>> >>>> import os.path >>>> #get the absolute path to the current script >>>> abs_path = os.path.abspath(__file__) >>> According to the docs: "On most platforms, this is equivalent to >>> normpath(join(os.getcwd(), path))." >>> >> >> os.path.abspath will always work in this case (unless something >> changes the current working directory before that statement runs) > > Which change is what you surmised as a cause of the original problem. > > Hello. > > >> because __file__ is given either as an absolute path or as relative to >> the current working directory. > > No, that's incorrect. Oh sorry, now I see what you mean. I read it too literally. You mean that at script startup __file__ is a valid relative or absolute path to the script. But anyways, Windows Explorer doesn't change the current directory to that of the associated program, at least not in Windows XP. Where there *is* a difference with double-clicking the script is in the path that ends up as __file__. [snip my silly code counter-example + even more silly comment] Cheers, - Alf From gagsl-py2 at yahoo.com.ar Thu Feb 4 01:02:29 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 03:02:29 -0300 Subject: Refreshing of urllib.urlopen() References: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> Message-ID: En Thu, 04 Feb 2010 00:33:08 -0300, Michael Gruenstaeudl escribi?: > I am fairly new to Python and need advice on the urllib.urlopen() > function. The website I am trying to open automatically refreshes after > 5 seconds and remains stable thereafter. With urllib.urlopen().read() I > can only read the initial but not the refreshed page. How can I access > the refreshed page via urlopen().read()? I have already tried to > intermediate with time.sleep() before invoking .read() (see below), but > this does not work. > > page=urllib.urlopen(url) > time.sleep(20) > htmltext=page.readlines() How does the page refresh itself? If using a tag, look at the url. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 4 01:11:06 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 03:11:06 -0300 Subject: Problem with __init__.py in Python3.1 References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> Message-ID: En Thu, 04 Feb 2010 01:00:56 -0300, Hidura escribi?: > Good evening list, I have a really big trouble with the imports in the > 3.1 > version(Notes: In the older 2.64 theres no problems), I have two > packages, > the first package Utilities who contains Writer the second package, > Writers > contain the module tagmanip(What is imported in the best way inside the > __init__.py of the Writer), when i make the import inside the writer > everything is ok, but from the Utilities package the errors says: > "ImportError: No module named tagsmanip". > I don't understand why this is happening, if somebody could help me i > will > glad to hear any suggestion. In Python 3.x, "absolute" import is enabled by default (2.6 uses a mix of relative and absolute imports). To import sibling modules in a package, or modules in a subpackage, you have to use relative imports: from . import tagmanip from .Writers import tagmanip See PEP328 http://www.python.org/dev/peps/pep-0328/ -- Gabriel Genellina From nagle at animats.com Thu Feb 4 01:11:56 2010 From: nagle at animats.com (John Nagle) Date: Wed, 03 Feb 2010 22:11:56 -0800 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: <4b6a6150$0$1656$742ec2ed@news.sonic.net> Steve Holden wrote: > John Nagle wrote: >> Paul Rubin wrote: >>> John Nagle writes: >>>> Analysis of each domain is >>>> performed in a separate process, but each process uses multiple >>>> threads to read process several web pages simultaneously. >>>> >>>> Some of the threads go compute-bound for a second or two at a time as >>>> they parse web pages. >>> You're probably better off using separate processes for the different >>> pages. If I remember, you were using BeautifulSoup, which while very >>> cool, is pretty doggone slow for use on large volumes of pages. I don't >>> know if there's much that can be done about that without going off on a >>> fairly messy C or C++ coding adventure. Maybe someday someone will do >>> that. >> I already use separate processes for different domains. I could >> live with Python's GIL as long as moving to a multicore server >> doesn't make performance worse. That's why I asked about CPU dedication >> for each process, to avoid thrashing at the GIL. >> > I believe it's already been said that the GIL thrashing is mostly MacOS > specific. You might also find something in the affinity module No, the original analysis was MacOS oriented, but the same mechanism applies for fighting over the GIL on all platforms. There was some pontification that it might be a MacOS-only issue, but no facts were presented. It might be cheaper on C implementations with mutexes that don't make system calls for the non-blocking cases. John Nagle From gagsl-py2 at yahoo.com.ar Thu Feb 4 01:27:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 03:27:16 -0300 Subject: Python 3 minor irritation References: Message-ID: En Thu, 04 Feb 2010 02:46:45 -0300, Alf P. Steinbach escribi?: > Oh sorry, now I see what you mean. I read it too literally. You mean > that at script startup __file__ is a valid relative or absolute path to > the script. > > But anyways, Windows Explorer doesn't change the current directory to > that of the associated program, at least not in Windows XP. But the associated program might change the current directory - that's not the case with the default associations created by the Python installer, but one should verify this. To the OP: please create this small test script import os print("curdir=", os.getcwd()) print("__file__=", __file__) input() and post what you get when you double-click on it. Also, from the command line, execute: D:\temp>reg query HKCR\.py ! REG.EXE VERSION 3.0 HKEY_CLASSES_ROOT\.py REG_SZ Python.File Content Type REG_SZ text/plain HKEY_CLASSES_ROOT\.py\PersistentHandler D:\temp>reg query HKCR\Python.File\shell\open\command ! REG.EXE VERSION 3.0 HKEY_CLASSES_ROOT\Python.File\shell\open\command REG_SZ "D:\Apps\Python26\python.exe" "%1" %* The first command says that files ending with .py are of type "Python.File", the second one says which command is executed to open a "Python.File" file. -- Gabriel Genellina From cournape at gmail.com Thu Feb 4 01:33:10 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 4 Feb 2010 15:33:10 +0900 Subject: Dreaming of new generation IDE In-Reply-To: References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <87k4utn570.fsf@benfinney.id.au> Message-ID: <5b8d13221002032233m7d4cd716te38d8eafdc888002@mail.gmail.com> On Thu, Feb 4, 2010 at 1:13 PM, Vladimir Ignatov wrote: >>> > [?] system "knows" all your identifiers and just regenerates >>> > relevant portions of text from internal database-alike >>> > representation. >> >> You will probably want to learn about ?refactoring? to see if that's >> related to what you mean . > > I mean if system actually "understands" your code (instead of try to > figure it out from existing text files with source code), then much > more complex refactoring is possible. My favorite refactoring is > "Replace Method with Method Object". It is hard to imagine "external" > tool that can provide such refactoring for python code. You may be interested by this project, then: http://sourceforge.net/mailarchive/message.php?msg_name=9c768dc61001121642t5bd1a7ddmd1fe9e088e1d9ab0 at mail.gmail.com It seems limited to Jython implementation unfortunately, cheers, David From no.email at nospam.invalid Thu Feb 4 01:57:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 22:57:40 -0800 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: <7xsk9hxzbv.fsf@ruckus.brouhaha.com> John Nagle writes: > There's enough intercommunication between the threads working on > a single site that it's a pain to do them as subprocesses. And I > definitely don't want to launch subprocesses for each page; the > Python load time would be worse than the actual work. The > subprocess module assumes you're willing to launch a subprocess > for each transaction. Why not just use socketserver and have something like a fastcgi? From hirotaka.niitsuma at gmail.com Thu Feb 4 02:10:02 2010 From: hirotaka.niitsuma at gmail.com (Niitsuma Hirotaka) Date: Thu, 4 Feb 2010 16:10:02 +0900 Subject: python via netcat Message-ID: <6ce56e1a1002032310j7f20c4a6q818ccb61a6ea1502@mail.gmail.com> I write little script run python via netcat http://www2s.biglobe.ne.jp/~niitsuma/jsonrpcdirect.html Usage $ netcat localhost 31415 {"method": "numpy.linalg.norm", "params": [[2,2]], "id": 0} then get response {"result": 2.8284271247461903, "error": null, "id": 0} From stephen.thorne at gmail.com Thu Feb 4 02:15:31 2010 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Wed, 3 Feb 2010 23:15:31 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: On Feb 3, 6:40?am, Xah Lee wrote: > This is a short complaint on adminabuseon #pythonircchannel on > freenode.net. > > Here's a log: > > 2010-02-02 > > (12:11:57 PM) The topic for #pythonis: NO LOL |http://pound-python.org/ > | It's too early to usePython3.x | Pasting > 3 lines? Pastebin:http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ:http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy > | #python.web #wsgi #python-fr #python.de #python-es #python.tw > #python.pl #python-br #python-jp #python-nl #python-ir #python- > offtopic > (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, > actually. > (12:12:01 PM) jarray52: Jarray > (12:12:11 PM) _habnabit: jarray52, yes, you are. > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops > etc) right is quite tricky > (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just > wondering whats up with thepythonverison :D > (12:12:24 PM) mode (+o dash) by ChanServ > (12:12:30 PM) You have been kicked by dash: (No.) G'day, My name is Stephen Thorne, and my nick on #python is Jerub. dash and I are both ops on the #python IRC channel. According to my logs the most recent time I have banned you from #python was the 16th of June, 2006, when I established that you were the same troll that posts to this usenet group. I have no interest in letting you troll #python, and thoroughly approve of dash's responsible behaviour as a joint custodian of the #python irc channel. Maintaining a high signal to noise ratio is difficult, and we appreciate that in this particular case you have acknowledged that you were made unwelcome in our IRC community and will endeavour to avoid it in future. Regards, Stephen Thorne From deets at nospam.web.de Thu Feb 4 03:41:44 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 09:41:44 +0100 Subject: PyChecker under python's virtualenv In-Reply-To: References: <7sub7uFstoU1@mid.uni-berlin.de> Message-ID: <7svfiaFvilU1@mid.uni-berlin.de> Am 04.02.10 01:52, schrieb Steve Holden: > Diez B. Roggisch wrote: >> Am 03.02.10 22:46, schrieb soltys: >>> Hi Everybody, >>> I've been doing some test on pythons' virtualenv and recently I've >>> decided to run PyChecker. But I'm having some difficulties with importing >>> modules available only on virtualenv by pychecker. As if it was >>> trying to use systemwide python. >>> I've googled about it, and found nothing in this area. >>> I installed pychecker using python setup.py install >>> from virtualenv. I looked at pychecker script - it uses correct python. >> >> I doubt that it uses the "correct python", because then you wouldn't >> have the problems you have. >> >> I don't use pychecker, but pylint. And there, the system-wide command >> uses the system's python - which of course doesn't know anything about >> virtualenv. >> >> There are two solutions to this problem: >> >> - install py(lint|checker) into your virtualenv. > > See the OP's original assertion: > >>> I installed pychecker using python setup.py install >>> from virtualenv. I looked at pychecker script - it uses correct python. > > Isn't that "installing into his virtualenv"? You are right, it reads like that. I should have read it better. All I can say is that even a system-wide pylint with my recipe above gives me no troubles. Diez From purui.wang at gmail.com Thu Feb 4 03:52:55 2010 From: purui.wang at gmail.com (purui) Date: Thu, 4 Feb 2010 00:52:55 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <69fb5e89-2ad6-42c0-b4c8-c322bd812e05@m27g2000prl.googlegroups.com> > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" > That is partially why I created this search engine for python, to see what parameters other people feed in. http://nullege.com/ From deets at nospam.web.de Thu Feb 4 04:02:06 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 10:02:06 +0100 Subject: Passing parameters in URL In-Reply-To: <7x3a1h7s82.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> Message-ID: <7svgogF768U1@mid.uni-berlin.de> > I'm not sure what you mean by that. Obviously if users want to record > their own conversations, then I can't stop them, but that's much > different than a non-participant in the conversation leaving a recorder > running 24/7. Is that so hard to understand? Is it so hard to understand that this is not about laws and rights, but about technical properties of the HTTP-protocol? Your web-based chat uses HTTP, no P2P-protocol, and thus the service provider *can* log conversations. I don't say he should, I don't say I want that, I don't say there are now laws that prevent them from doing so, all I say is he *can*. > I certainly didn't feel that saving or not saving client conversations > on the server side was up to my discretion. When I found that the > default server configuration caused conversations to be logged then I > was appalled. Then stop logging. Or get a hosting-provider that allows you to configure it to strip QUERY_STRINGS from log-entries. And if they refuse to, maybe using POST solves the issue. But wait, there is http://www.cyberciti.biz/faq/apache-mod_dumpio-log-post-data/ So what if they run that? So, for the umpteenth time: data sent over the wire can be recorded. From the user's POV, your nitpicking of who's the actual culprit - the IT-guys, or the programmers - is fruitless. You have a nice anecdote where switching from GET to POST allowed you to trick whoever wasn't acting to your wishes. Good for you. But John B. and your posts indicate that using POST is inherently more secure. It *isn't*. > Do you think the phone company has the right to record all your phone > calls if they feel like it (absent something like a law enforcement > investigation)? What about coffee shops that you visit with your > friends? It is not up to their discretion. They have a positive > obligation to not do it. If you think they are doing it on purpose > without your authorization, you should notify the FBI or your > equivalent, not just "don't use it". If they find they are doing it > inadvertently, they have to take measures to make it stop. That is the > situation I found myself in, because of the difference in how servers > treat GET vs. POST. If they have a positive obligation not to do it, it doesn't matter if they run their service over GET or POST. Again, this is not about laws and what service providers should or must do. It's about POST vs. GET, and if either of them is more secure or not. It isn't. Diez From deets at nospam.web.de Thu Feb 4 04:07:49 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 10:07:49 +0100 Subject: Passing parameters in URL In-Reply-To: <87iqadde68.fsf@castleamber.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <87iqadde68.fsf@castleamber.com> Message-ID: <7svh39F8vvU1@mid.uni-berlin.de> Am 04.02.10 01:42, schrieb John Bokma: > "Diez B. Roggisch" writes: > >> Am 03.02.10 19:11, schrieb John Bokma: >>> Alan Harris-Reid writes: >>> >>>> I have a web-page where each row in a grid has edit/delete buttons to >>>> enable the user to maintain a selected record on another page. The >>>> buttons are in the form of a link with href='/item_edit?id=123', but >>>> this string appears in the URL and gives clues as to how to bypass the >>>> correct sequence of events, and could be risky if they entered the URL >>>> directly (especially when it comes to deleting records). >>> >>> You should *never* use a GET request to do actions like deleting >>> records. You already are aware of it being risky, so don't do this. You >>> should use GET for getting information, and POST for modifying information. >> >> You should *never* say never, because there might be situations where >> exceptions from rules are valid. This is one such cases. Making this a >> post means that you need to resort to javascript to populate& submit >> a hidden HTML-form. Just for the sake of a POST. > > Make each edit/delete button a submit button and optionally style it. *slap* Yep, you are right, no JS needed. I should have thought about that. > >> Also, your claim of it being more risky is simply nonsense. GET is a >> tiny bit more prone to tinkering by the average user. But calling this >> less risky is promoting security by obscurity, at most. > > Maybe you should think about what happens if someone posts: > to a popular forum... And the difference to posting from urrlib2 import open from urllib import encode open("http://example.com/item_delete", data=encode([("id", "123")])) to that same public "hacker" forum is exactly what? If your webapp happens to allow item_delete to be called without authentication & authorization, then *that's* your problem. Diez From deets at nospam.web.de Thu Feb 4 04:23:40 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 10:23:40 +0100 Subject: Passing parameters in URL In-Reply-To: References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> Message-ID: <7svi0uFecmU1@mid.uni-berlin.de> Am 04.02.10 03:52, schrieb Nobody: > On Wed, 03 Feb 2010 14:09:07 -0800, Paul Rubin wrote: > >>> Also, your claim of it being more risky is simply nonsense. GET is a >>> tiny bit more prone to tinkering by the average user. But calling this >>> less risky is promoting security by obscurity, at most. >> >> GET parameters also tend to get recorded in the http logs of web proxies >> and web servers while POST parameters usually aren't. > > More significantly, they'll appear in the Referer: header for any link the > user follows from the page, so they're visible to anyone who can get a > link to their site onto the page (whether, or > whatever). > > Even if this isn't possible at the moment, will you remember to fix it the > first time you allow an off-site link? > > You should assume that anything which goes into a GET request is visible > to the entire world. Don't put anything even remotely private in there. You mean like http://www.google.de/search?q=dirty+buttsex ? Which is the key example for when to use GET - non-modifying queries. I agree though that you have to be cautious about that, and using POST makes it easier to do so. Diez From kmisoft at gmail.com Thu Feb 4 04:41:03 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 12:41:03 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <69fb5e89-2ad6-42c0-b4c8-c322bd812e05@m27g2000prl.googlegroups.com> References: <69fb5e89-2ad6-42c0-b4c8-c322bd812e05@m27g2000prl.googlegroups.com> Message-ID: > That is partially why I created this search engine for python, to see > what parameters other people feed in. > http://nullege.com/ Thank you for excellent effort! I found it very useful and start using it on almost everyday basis. It's much simple to learn from real live examples. Vladimir Ignatov From no.email at nospam.invalid Thu Feb 4 05:27:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 02:27:49 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> <7svgogF768U1@mid.uni-berlin.de> Message-ID: <7xeil1qore.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Your web-based chat uses HTTP, no P2P-protocol, and thus the service > provider *can* log conversations. I don't say he should, I don't say I > want that, I don't say there are now laws that prevent them from doing > so, all I say is he *can*. Sure, my complaint is that the default setup caused this to actually happen so lots of people using that software were recording user conversations without realizing it and maybe without caring. This is a bad erosion as I see it. > Then stop logging. Or get a hosting-provider that allows you to > configure it to strip QUERY_STRINGS from log-entries. And if they > refuse to, maybe using POST solves the issue. I did stop logging. There wasn't an issue with the hosting provider since I was running the server myself. But I had to resort to some ugly software kludge to stop logging those particular strings. More frustratingly, I filed a bug report about the issue against the chat software but the conversation was sort of like the one you and I are having now. I just couldn't convince them that there was a problem and that they should change the default. > http://www.cyberciti.biz/faq/apache-mod_dumpio-log-post-data/ > So what if they run that? That sounds like something someone would have to go out of their way to install and use. It's not the default. Of course if someone is malicious they can do all sorts of nasty stuff. A coffeeshop that wanted to mess with me on purpose wouldn't have to do high tech crap like recording my conversations--they could just poison my coffee. I have to trust them to not do this on purpose, but then I see a situation where their coffee sweetener accidentaly has a harmful chemical, so of course I'd ask them to do something about it. > So, for the umpteenth time: data sent over the wire can be recorded. And for the umpteenth time, I'm less concerned about "can be" than "is". POST isn't logged unless you go to some lengths to have it logged. GET is logged unless you go to some lengths to prevent it. It's not enough in a software deployment to only consider what actions are possible. It's important to make sure that the default actions are the right ones. > If they have a positive obligation not to do it, it doesn't matter if > they run their service over GET or POST. GET makes it harder for them to fulfill their obligations. As a security nerd, I saw what was happening and took measures against it, but a more typical operator might never notice or care. There is also the matter of the referer header which an anon mentioned, though it didn't apply to this particular situation because of how the application worked. From no.email at nospam.invalid Thu Feb 4 05:32:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 02:32:01 -0800 Subject: Passing parameters in URL References: <4b6aa21d$0$11075$426a74cc@news.free.fr> Message-ID: <7xaavpqoke.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: >> The buttons are in the form of a link with href='/item_edit?id=123', > ...At least use "POST" requests for anything that Create/Update/Delete > resources. There's also the issue that a user can change "123" to "125" and possibly mess with someone else's resource, unless you use some server side authentication. Or just seeing how often the numbers change could reveal patterns about what other users are doing. I always think it's best to encrypt anything sensitive like that, to avoid leaking any info. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:32:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:32:02 +0100 Subject: Passing parameters in URL In-Reply-To: References: Message-ID: <4b6aa21d$0$11075$426a74cc@news.free.fr> Alan Harris-Reid a ?crit : > I have a web-page where each row in a grid has edit/delete buttons to > enable the user to maintain a selected record on another page. The > buttons are in the form of a link with href='/item_edit?id=123', but > this string appears in the URL and gives clues as to how to bypass the > correct sequence of events, and could be risky if they entered the URL > directly (especially when it comes to deleting records). Basic HTTP stuff - this is definitely not Python-related. Do yourself (and your users / customers / etc) a favor and read the HTTP rfc. "GET" requests should NOT modify the server state. At least use "POST" requests for anything that Create/Update/Delete resources. For the record, someone once had serious problems with GET requests deleting records - turned out to be a very bad idea when a robot started following these links... > Is there another way of passing a record-id to a method href="/item/23/edit" href="/item/edit/23" etc > a) without it appearing in the URL? > b) without the user being able to fathom-out how to attach which id to > which URL? Wrong solution. The correct solution is to 1/ make correct use of the request method (GET and POST at least). 2/ make sure the user performing the action has the permission to do it. 1/ won't protect your data from malicious users, but will at least avoid accidental mistakes. 2/ by checking the user's perms when handling the POST request of course - not by hidding "forbidden" urls. > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Nor even from trying any other id (brute-force attack). > Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the edit/delete > action? cf above. > I am currently using CherryPy 3.2, but I guess the theory could apply to > any HTTP framework or web app.. Indeed. From anand.shashwat at gmail.com Thu Feb 4 05:39:39 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 16:09:39 +0530 Subject: Common area of circles Message-ID: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. hope the picture makes it clear http://imagebin.us/images/p5qeo7hgc3547pnyrb6.gif -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:47:45 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:47:45 +0100 Subject: Passing parameters in URL In-Reply-To: <7sua7fFn74U1@mid.uni-berlin.de> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> Message-ID: <4b6aa5cf$0$30293$426a74cc@news.free.fr> Diez B. Roggisch a ?crit : > Am 03.02.10 19:11, schrieb John Bokma: >> Alan Harris-Reid writes: >> >>> I have a web-page where each row in a grid has edit/delete buttons to >>> enable the user to maintain a selected record on another page. The >>> buttons are in the form of a link with href='/item_edit?id=123', but >>> this string appears in the URL and gives clues as to how to bypass the >>> correct sequence of events, and could be risky if they entered the URL >>> directly (especially when it comes to deleting records). >> >> You should *never* use a GET request to do actions like deleting >> records. You already are aware of it being risky, so don't do this. You >> should use GET for getting information, and POST for modifying >> information. > > You should *never* say never, because there might be situations where > exceptions from rules are valid. This is one such cases. Oh yes ? > Making this a > post means that you need to resort to javascript to populate & submit a > hidden HTML-form. I beg your pardon ???? This is total nonsense. Hopefully you don't need any js to emit a post request from a browser ! The only thing you need to do is to use a form and submit input instead. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:52:12 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:52:12 +0100 Subject: Passing parameters in URL In-Reply-To: <7xaavpqoke.fsf@ruckus.brouhaha.com> References: <4b6aa21d$0$11075$426a74cc@news.free.fr> <7xaavpqoke.fsf@ruckus.brouhaha.com> Message-ID: <4b6aa6d6$0$30293$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> The buttons are in the form of a link with href='/item_edit?id=123', >> ...At least use "POST" requests for anything that Create/Update/Delete >> resources. > > There's also the issue that a user can change "123" to "125" and > possibly mess with someone else's resource, > unless you use some server > side authentication. What I said IIRC. > Or just seeing how often the numbers change could > reveal patterns about what other users are doing. I always think it's > best to encrypt anything sensitive like that, to avoid leaking any info. Depends on how "sensitive" it really is. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:53:21 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:53:21 +0100 Subject: Passing parameters in URL In-Reply-To: <4b6aa5cf$0$30293$426a74cc@news.free.fr> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <4b6aa5cf$0$30293$426a74cc@news.free.fr> Message-ID: <4b6aa71b$0$30293$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > Diez B. Roggisch a ?crit : (snip) >> Making this a post means that you need to resort to javascript to >> populate & submit a hidden HTML-form. > > I beg your pardon ???? This is total nonsense. Sorry, posted too fast, John alredy adressed this. From kmisoft at gmail.com Thu Feb 4 05:54:58 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 13:54:58 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <5b8d13221002032233m7d4cd716te38d8eafdc888002@mail.gmail.com> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <87k4utn570.fsf@benfinney.id.au> <5b8d13221002032233m7d4cd716te38d8eafdc888002@mail.gmail.com> Message-ID: > http://sourceforge.net/mailarchive/message.php?msg_name=9c768dc61001121642t5bd1a7ddmd1fe9e088e1d9ab0 at mail.gmail.com Thanks a lot! That is a great reference (a must read for everybody interested). Reading just this: "Internally at Google we have a language-neutral representation shared by all our language analyzers," make me jumping ;-) Googlers can't be wrong. Vladimir Ignatov From anh.hai.trinh at gmail.com Thu Feb 4 06:13:58 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Thu, 4 Feb 2010 03:13:58 -0800 (PST) Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: On Feb 4, 10:46?am, John Nagle wrote: > > ? ? There's enough intercommunication between the threads working on > a single site that it's a pain to do them as subprocesses. And I > definitely don't want to launch subprocesses for each page; the > Python load time would be worse than the actual work. ?The > subprocess module assumes you're willing to launch a subprocess > for each transaction. You could perhaps use a process pool inside each domain worker to work on the pages? There is multiprocessing.Pool and other implementations. For examples, in this library, you can s/ThreadPool/ProcessPool/g and this example would work: . If you want to DIY, with multiprocessing.Lock/Pipe/Queue, I don't understand why it would be more of a pain to write your threads as processes. // aht http://blog.onideas.ws From groups_ads12 at yahoo.com Thu Feb 4 06:16:50 2010 From: groups_ads12 at yahoo.com (groups_ads12) Date: Thu, 04 Feb 2010 11:16:50 -0000 Subject: learn Sql Server 2000 2005 2008 Message-ID: www.sqlserver.learn.net.in sql server sql server 2005 sql server 2008 sql server 2000 microsoft sql server sql server management studio microsoft sql server 2005 ms sql server microsoft sql server 2000 sql server 2005 download sql server hosting microsoft sql server 2008 sql server jobs sql server stored procedure sql server 2005 tutorial sql server query sql server reporting services sql server tutorial ms sql server 2005 download sql server microsoft sql server management studio express sql server 2003 sql server enterprise manager sql server integration services sql server backup sql server data types sql server dba sql server management sql server replication microsoft sql server 2005 express edition ms sql server 2000 mssql server sql server 2005 reporting services sql server client sql server cursor sql server database sql server performance sql server profiler sql server training ms sql server 2008 sql server 2008 developer edition sql server developer sql server manager sql server trigger sql server update sql server2005 microsoft sql server download sql server 7 sql server 7.0 sql server date format sql server datetime sql server identity sql server job sql server tools sql server tutorials sql server 2005 replication sql server 2005 tutorials sql server alter table sql server enterprise sql server insert sql server magazine sql server security sql server software sql server stored procedures sql server xml sql servers asp sql server sql server 2005 backup sql server 2005 training sql server bcp sql server insert into sql server jdbc learn sql server sql server 2005 client sql server administration sql server bulk insert sql server collation sql server consultant sql server error sql server free sql server select sql server standard sql server tool sql server transaction sql server tuning msdn sql server sql server 2005 books sql server 6.5 sql server books sql server consulting sql server data type sql server delete sql server queries sql server services sql server ssis sql server support sql server transaction log sql server 2005 tools sql server backup database sql server exec sql server joins sql server null sql server query analyzer tutorial sql server 2000 rename sql server sql server help sql server indexes sql server scripts sql server service buy sql server sql server 2000 backup sql server 2008 training sql server best practices sql server development sql server script sql server tempdb ms sql server hosting sql server databases sql server host sql server tips performance tuning sql server sql 2000 server download sql server course sql server courses sql server guide sql server maintenance sql server permissions learning sql server 2005 sql server 2005 tuning sql server command sql server data sql server execute sql server table sql server utilities msde sql server sql server db setting up sql server sql server programmer using sql server audit sql server performance tuning sql server 2005 sql server tables copy sql server sql server 2005 recovery syntax sql server sql server exams creating sql server tsql server sqlserver server differences sql server -------------- next part -------------- An HTML attachment was scrubbed... URL: From lallous at lgwm.org Thu Feb 4 06:34:04 2010 From: lallous at lgwm.org (lallous) Date: Thu, 4 Feb 2010 03:34:04 -0800 (PST) Subject: Building a multiline string Message-ID: Hello Maybe that's already documented, but it seems the parser accepts to build a long string w/o really using the first method: # Method1 x = "line1" + \ # cannot use comments! "line2"+ \ "line3" and instead using a list with one element like this: # Method2 x = [ "line1" # can use comments "line2" "line3" ][0] Or: # Method3 x = ( "line1" # can use comments "line2" "line3" ) (Not that I don't want new lines in the strings) Now should I be using method 2 or 3 in production code? -- Elias From clp2 at rebertia.com Thu Feb 4 06:41:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Feb 2010 03:41:18 -0800 Subject: Common area of circles In-Reply-To: References: Message-ID: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand wrote: > Given 'n' circles and the co-ordinates of their center, and the radius of > all being equal i.e. 'one', How can I take out the intersection of their > area. How is this at all specific to Python? This also sounds suspiciously like homework, which you should know this list is unlikely to give direct answers to, though you might be able to get a few pointers or some general suggestions. Cheers, Chris -- Back to toiling away on CSE 105 HW#3 http://blog.rebertia.com From anand.shashwat at gmail.com Thu Feb 4 06:47:43 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 17:17:43 +0530 Subject: Common area of circles In-Reply-To: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> Message-ID: I wanted some general suggestion/tips only On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert wrote: > On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand > wrote: > > Given 'n' circles and the co-ordinates of their center, and the radius of > > all being equal i.e. 'one', How can I take out the intersection of their > > area. > > How is this at all specific to Python? > > This also sounds suspiciously like homework, which you should know > this list is unlikely to give direct answers to, though you might be > able to get a few pointers or some general suggestions. > > Cheers, > Chris > -- > Back to toiling away on CSE 105 HW#3 > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Thu Feb 4 06:54:14 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 4 Feb 2010 21:54:14 +1000 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> Message-ID: <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> I'm not sure what you're after. Are you after how to calculate the area? Or are you trying to graph it? Or an analytical solution? What do you mean by "take out the intersection"? -Xav On Thu, Feb 4, 2010 at 9:47 PM, Shashwat Anand wrote: > I wanted some general suggestion/tips only > > > On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert wrote: > >> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand >> wrote: >> > Given 'n' circles and the co-ordinates of their center, and the radius >> of >> > all being equal i.e. 'one', How can I take out the intersection of their >> > area. >> >> How is this at all specific to Python? >> >> This also sounds suspiciously like homework, which you should know >> this list is unlikely to give direct answers to, though you might be >> able to get a few pointers or some general suggestions. >> >> Cheers, >> Chris >> -- >> Back to toiling away on CSE 105 HW#3 >> http://blog.rebertia.com >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Feb 4 07:04:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 07:04:35 -0500 Subject: How to guard against bugs like this one? In-Reply-To: <4B69A575.2020604@timgolden.me.uk> References: <4B69A575.2020604@timgolden.me.uk> Message-ID: Tim Golden wrote: > On 03/02/2010 16:17, kj wrote: >> Boy, that was dumb of me. The above apology was meant for Stephen >> Hansen, not Steve Holden. I guess this is now a meta-apology... >> (Sheesh.) > > You see? That's what I like about the Python community: > people even apologise for apologising :) > QOTW? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From anand.shashwat at gmail.com Thu Feb 4 07:05:46 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 17:35:46 +0530 Subject: Common area of circles In-Reply-To: <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. On Thu, Feb 4, 2010 at 5:24 PM, Xavier Ho wrote: > I'm not sure what you're after. Are you after how to calculate the area? Or > are you trying to graph it? Or an analytical solution? > > What do you mean by "take out the intersection"? > > -Xav > > On Thu, Feb 4, 2010 at 9:47 PM, Shashwat Anand wrote: > >> I wanted some general suggestion/tips only >> >> >> On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert wrote: >> >>> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand >>> wrote: >>> > Given 'n' circles and the co-ordinates of their center, and the radius >>> of >>> > all being equal i.e. 'one', How can I take out the intersection of >>> their >>> > area. >>> >>> How is this at all specific to Python? >>> >>> This also sounds suspiciously like homework, which you should know >>> this list is unlikely to give direct answers to, though you might be >>> able to get a few pointers or some general suggestions. >>> >>> Cheers, >>> Chris >>> -- >>> Back to toiling away on CSE 105 HW#3 >>> http://blog.rebertia.com >>> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eckhardt at satorlaser.com Thu Feb 4 07:09:46 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 04 Feb 2010 13:09:46 +0100 Subject: Building a multiline string References: Message-ID: Just for the record: Neither of the below methods actually produce a multiline string. They only spread a string containing one line over multiple lines of source code. lallous wrote: > Maybe that's already documented, but it seems the parser accepts to > build a long string w/o really using the first method: > > # Method1 > x = "line1" + \ # cannot use comments! > "line2"+ \ > "line3" Well, obviously you can't use comments like that there. The point of the backslash is that it continues the current logical line over the _immediately_ _following_ newline. If anything follows, that obviously doesn't work. > and instead using a list with one element like this: > > # Method2 > x = [ > "line1" # can use comments > "line2" > "line3" > ][0] This basically makes use of the fact that "this" "is" "one" "string" and not four strings. > # Method3 > x = ( > "line1" # can use comments > "line2" > "line3" > ) This uses the same, only that this time it uses brackets which cause an expression to extend to multiple lines. > (Not that I don't want new lines in the strings) You don't not want or you don't want newlines? Depending on that, you could also do this: # method 4 x = "line1"\ "line2"\ "line3" or maybe # method 5 x = """line1 line2 line3 """ > Now should I be using method 2 or 3 in production code? I'd go for 3 or 4. 2 is basically a hack (you could do the same with a dictionary, or a tuple, not only a list). 1 will actually create strings and then concatenate them (unless Python is smart enough to optimize that), but it allows adding expressions in the middle. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From steve at holdenweb.com Thu Feb 4 07:14:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 07:14:13 -0500 Subject: Passing parameters in URL In-Reply-To: <7x3a1h7s82.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> Message-ID: <4B6ABA15.7020307@holdenweb.com> Paul Rubin wrote: > "Diez B. Roggisch" writes: >>> But it would be outrageous for the shop owner to record the >>> conversations of patrons. >> Which is the exact thing that happens when you use an email-provider >> with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I >> wouldn't call outrageous. > > Those are not comparable. IMAP is a storage service, and groups, > facebook, and twitter are publishing systems (ok, I've never understood > quite what Google Wave is). Yes, by definition, your voice mail > provider (like IMAP) has to save recordings of messages people leave > you, but that's a heck of a lot different than your phone carrier > recording your real-time conversations. Recording live phone > conversations by a third party is called a "wiretap" and doing it > without suitable authorization can get you in a heck of a lot of > trouble. > Unless you happen to be following the illegal instructions of the President of the United States, in which case Congress will retro-actively alter the law to void your offenses and provide you with legal immunity for your wrong-doing. Assuming you are a large telephone company and not a private individual. >> This discussion moves away from the original question: is there >> anything inherently less secure when using GET vs. POST. There isn't. > > Well, the extra logging of GET parameters is not inherent to the > protocol, but it's an accidental side effect that server ops may have to > watch out for. > >> Users can forge both kind of requests easy enough, whoever sits in the >> middle can access both, > > I'm not sure what you mean by that. Obviously if users want to record > their own conversations, then I can't stop them, but that's much > different than a non-participant in the conversation leaving a recorder > running 24/7. Is that so hard to understand? > > Interception from the middle is addressed by SSL, though that relies on > the PKI certificate infrastructure, which while somewhat dubious, is > better than nothing. > >> and it's at the discretion of the service provider to only save what >> it needs to. If you don't trust it, don't use it. > > I certainly didn't feel that saving or not saving client conversations > on the server side was up to my discretion. When I found that the > default server configuration caused conversations to be logged then I > was appalled. > > Do you think the phone company has the right to record all your phone > calls if they feel like it (absent something like a law enforcement > investigation)? What about coffee shops that you visit with your > friends? It is not up to their discretion. They have a positive > obligation to not do it. If you think they are doing it on purpose > without your authorization, you should notify the FBI or your > equivalent, not just "don't use it". If they find they are doing it > inadvertently, they have to take measures to make it stop. That is the > situation I found myself in, because of the difference in how servers > treat GET vs. POST. A lot will depend on the terms of service of the network supply contract. Most vendors take pains to ensure that such "innocent" logging (i.e. the maintenance by their servers of logging information, which may under subpoena or similar legal coercion be given up to law enforcement authorities as "business records") is permitted. If you have signed the contract, then they have the right to log that data. Caveat emptor. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bearophileHUGS at lycos.com Thu Feb 4 07:19:35 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 4 Feb 2010 04:19:35 -0800 (PST) Subject: Common area of circles References: Message-ID: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> Shashwat Anand: > > Given 'n' circles and the co-ordinates of their center, and the radius of > > all being equal i.e. 'one', How can I take out the intersection of their > > area. I can see two possible solutions, both approximate. In both solutions you first look if there are a pair of circles that don't intersect, in this case the intersect area is zero. You also remove all circles fully contained in another circle. The first strategy is easy to do, but it probably leads to a lower precision. Then you can sample randomly many times the rectangular area that surely contains all circles. You count how many of those random points are inside all circles. This gives you an approximate area of their intersection. Increasing the points numbers slowly increases the result precision. The second strategy is more complex. You convert your circles into polygons with a fixed number of vertices (like 50 or 100 or 1000 or more. This number is constant even if the circles don't have all the same radius). So you can turn this circle into a simple mesh of triangles (all vertices are on the circumference). Then you "subtract" the second polygonalized circle, this can create a hole and split triangles in pieces, and so on with successive circles. At the end you can compute the total area of the triangles left. This is doable, but you need time to do implement this. The advantage is that the numerical precision of the result is probably higher. If you implement this second solution you can implement the first one too, and use it as a test to avoid bugs. Visualizing the triangles with Pygame or MatPlotLib can be useful to look for bugs. Bye, bearophile From anand.shashwat at gmail.com Thu Feb 4 07:27:14 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 17:57:14 +0530 Subject: Common area of circles In-Reply-To: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> References: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> Message-ID: I needed 6 decimal places of accuracy, so first way of solution will not work for my case. However, your second strategy seems promising. Working on it. Thanks :D ~l0nwlf On Thu, Feb 4, 2010 at 5:49 PM, Bearophile wrote: > Shashwat Anand: > > > Given 'n' circles and the co-ordinates of their center, and the radius > of > > > all being equal i.e. 'one', How can I take out the intersection of > their > > > area. > > I can see two possible solutions, both approximate. In both solutions > you first look if there are a pair of circles that don't intersect, in > this case the intersect area is zero. You also remove all circles > fully contained in another circle. > > The first strategy is easy to do, but it probably leads to a lower > precision. Then you can sample randomly many times the rectangular > area that surely contains all circles. You count how many of those > random points are inside all circles. This gives you an approximate > area of their intersection. Increasing the points numbers slowly > increases the result precision. > > The second strategy is more complex. You convert your circles into > polygons with a fixed number of vertices (like 50 or 100 or 1000 or > more. This number is constant even if the circles don't have all the > same radius). So you can turn this circle into a simple mesh of > triangles (all vertices are on the circumference). Then you "subtract" > the second polygonalized circle, this can create a hole and split > triangles in pieces, and so on with successive circles. At the end you > can compute the total area of the triangles left. This is doable, but > you need time to do implement this. The advantage is that the > numerical precision of the result is probably higher. If you implement > this second solution you can implement the first one too, and use it > as a test to avoid bugs. Visualizing the triangles with Pygame or > MatPlotLib can be useful to look for bugs. > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashokprabhuv at gmail.com Thu Feb 4 07:28:20 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Thu, 4 Feb 2010 04:28:20 -0800 (PST) Subject: read a process output with subprocess.Popen Message-ID: Hi, I m trying a read the output of a process which is running continuously with subprocess.Popen. However the readline() method hangs for the process to finish. Please let me know if the following code can be made to work with subprocess.Popen with threads or queues. I tried a lot of methods but to no avail. It would be great if someone can make it work. import subprocess p1 = subprocess.Popen('tail -f /var/log/ messages',stdout=subprocess.PIPE,shell=True) p2 = subprocess.Popen('grep something',stdin=p1.stdout,stdout=subprocess.PIPE,shell=True) while 1: line = p2.stdout.readline() print line Thanks, ~Ashok. From mgedmin at gmail.com Thu Feb 4 07:28:29 2010 From: mgedmin at gmail.com (Marius Gedminas) Date: Thu, 4 Feb 2010 04:28:29 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87wrytdirw.fsf@castleamber.com> Message-ID: <9e80909d-906c-466b-b9cb-77400a42ee7e@r24g2000yqd.googlegroups.com> On Feb 4, 1:03?am, John Bokma wrote: > Jonathan Gardner writes: > > I can explain all of Python in an hour; > > OK, in that case I would say give it a go. Put it on YouTube, or write a > blog post about it (or post it here). I am sure you will help a lot of > people that way. Someone already did: "Advanced Python or Understanding Python" http://video.google.com/videoplay?docid=7760178035196894549 (76 minutes). Worth watching. Regards, -- Marius Gedminas From steve at holdenweb.com Thu Feb 4 07:31:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 07:31:01 -0500 Subject: Building a multiline string In-Reply-To: References: Message-ID: lallous wrote: > Hello > > Maybe that's already documented, but it seems the parser accepts to > build a long string w/o really using the first method: > > # Method1 > x = "line1" + \ # cannot use comments! > "line2"+ \ > "line3" > > and instead using a list with one element like this: > > # Method2 > x = [ > "line1" # can use comments > "line2" > "line3" > ][0] > > Or: > # Method3 > x = ( > "line1" # can use comments > "line2" > "line3" > ) > > (Not that I don't want new lines in the strings) > > Now should I be using method 2 or 3 in production code? > I should have thought it was pretty obvious that method 2 creates a list and then performs an indexing operation on it. These are completely unnecessary operations, which are avoided in method 3 which is a simple parenthesised expression. So why anyone would want to adopt method 2, which is also mess clear as source code, is beyond me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Thu Feb 4 07:59:52 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Feb 2010 13:59:52 +0100 Subject: Repeat an exception In-Reply-To: <4B6A3C57.2000606@mrabarnett.plus.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> <4B6A3C57.2000606@mrabarnett.plus.com> Message-ID: <4B6AC4C8.5030902@sequans.com> MRAB wrote: > In other words: > > for attempt in range(2): > try: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > break > except TranslationError: > pass > else: > # Didn't break out of the loop, therefore not successful. > print "Translation failed" What the hell is this 'for else' loop !! :D First time I see this statement for years. I'd never thought I'd still learn something that basic. My first impression is that the mechansim is not that obvious. MRAB's need for a comment tends to confirm this. I'll try to remember that anyway. Nice addition. JM From marco at sferacarta.com Thu Feb 4 08:23:46 2010 From: marco at sferacarta.com (Marco Mariani) Date: Thu, 04 Feb 2010 14:23:46 +0100 Subject: Building a multiline string In-Reply-To: References: Message-ID: On 02/04/2010 12:34 PM, lallous wrote: > Now should I be using method 2 or 3 in production code? Another way... depending on what you are using the string for, of course. If it's an HTML/XML/SQL/whatever piece of code: >>>> from textwrap import dedent >>>> sql = dedent(""" > ... SELECT * > ... FROM table > ... WHERE foo=bar > ... """) >>>> >>>> print sql > > SELECT * > FROM table > WHERE foo=bar > And if you don't want the starting/ending newlines: >>>> sql = dedent("""\ > ... SELECT * > ... FROM table > ... WHERE foo=bar\ > ... """) >>>> >>>> print sql > SELECT * > FROM table > WHERE foo=bar >>>> I use this sometimes to keep both python and the embedded code readable while preserving indentation. From contact at xavierho.com Thu Feb 4 08:31:17 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 4 Feb 2010 23:31:17 +1000 Subject: Common area of circles In-Reply-To: References: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> Message-ID: <2d56febf1002040531g42d0ced3y220b0ff32e56a7f1@mail.gmail.com> It's an interesting problem. Never thought it was this difficult. I can't account for all geometrical enumerations, but assuming all 4 circles intersect, here's the solution for this particular senario. It's probably not going to be useful to you since you're working on geometrical approximations now, but it is precise to the exact value. I don't have it worked out here, but it goes like this. 1. Find the area covered by all 4 circles, unioned. Method here: http://stackoverflow.com/questions/1667310/combined-area-of-overlapping-circles 2: Follow this chart I made up: http://xavierho.com/media/images/Misc/IntersectionOfFourCircles.png And there you go. I'm sure there are way better, faster ways, and covers a lot more senarios, but this is the best I can come up with, without counting the rasterised pixels ratio =P. I like Bearophile's solution. Have fun! Cheers, Xav On Thu, Feb 4, 2010 at 10:27 PM, Shashwat Anand wrote: > I needed 6 decimal places of accuracy, so first way of solution will not > work for my case. However, your second strategy seems promising. Working on > it. Thanks :D > ~l0nwlf > > > On Thu, Feb 4, 2010 at 5:49 PM, Bearophile wrote: > >> Shashwat Anand: >> > > Given 'n' circles and the co-ordinates of their center, and the radius >> of >> > > all being equal i.e. 'one', How can I take out the intersection of >> their >> > > area. >> >> I can see two possible solutions, both approximate. In both solutions >> you first look if there are a pair of circles that don't intersect, in >> this case the intersect area is zero. You also remove all circles >> fully contained in another circle. >> >> The first strategy is easy to do, but it probably leads to a lower >> precision. Then you can sample randomly many times the rectangular >> area that surely contains all circles. You count how many of those >> random points are inside all circles. This gives you an approximate >> area of their intersection. Increasing the points numbers slowly >> increases the result precision. >> >> The second strategy is more complex. You convert your circles into >> polygons with a fixed number of vertices (like 50 or 100 or 1000 or >> more. This number is constant even if the circles don't have all the >> same radius). So you can turn this circle into a simple mesh of >> triangles (all vertices are on the circumference). Then you "subtract" >> the second polygonalized circle, this can create a hole and split >> triangles in pieces, and so on with successive circles. At the end you >> can compute the total area of the triangles left. This is doable, but >> you need time to do implement this. The advantage is that the >> numerical precision of the result is probably higher. If you implement >> this second solution you can implement the first one too, and use it >> as a test to avoid bugs. Visualizing the triangles with Pygame or >> MatPlotLib can be useful to look for bugs. >> >> Bye, >> bearophile >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Feb 4 09:01:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 09:01:01 -0500 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: On 2/4/2010 7:05 AM, Shashwat Anand wrote: > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is there > any other approach possible. There is a method for calculating the area of a polygon by traversing its boundary. I forget the formula, but you should be able to find it. So *if* you can find the arcs that bound the area, you can approximate each by a series of short lines and apply the polygon method. Terry Jan Reedy From anand.shashwat at gmail.com Thu Feb 4 09:19:06 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 19:49:06 +0530 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: thanks, all of you On Thu, Feb 4, 2010 at 7:31 PM, Terry Reedy wrote: > On 2/4/2010 7:05 AM, Shashwat Anand wrote: > >> I want to calculate areas. >> like for two circles (0, 0) and (0, 1) : the output is '1.228370' >> >> similarly my aim is to take 'n' co-ordinates, all of radius '1' and >> calculate the area common to all. >> The best I got was monte-carlo methods which is inefficient. Is there >> any other approach possible. >> > > There is a method for calculating the area of a polygon by traversing its > boundary. I forget the formula, but you should be able to find it. So *if* > you can find the arcs that bound the area, you can approximate each by a > series of short lines and apply the polygon method. > > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pecora at anvil.nrl.navy.mil Thu Feb 4 09:57:59 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 04 Feb 2010 09:57:59 -0500 Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> Message-ID: In article <87eil1ddjp.fsf_-_ at castleamber.com>, John Bokma wrote: > Lou Pecora writes: > > > That's a pretty accurate description of how I transitioned to Python > > from C and Fortran. > > Not C, but C++ (but there are also C implementations): YAML, see: > http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument > > I use YAML now and then with Perl for both reading/writing data and for > debugging purposes (YAML is quite human readable, for programmers at least) > > Of course there is also YAML support for Python: > http://pyyaml.org/. Well, that looks a bit more complicated than I would like, but maybe it's doing more stuff than I can grok. Here's what I needed and how I did it in Python: # Make some variables x=1.234e-8 y=2 astr="An output string...whatever" z=4.5+1j*1.3456 # a complex number # Output them to a file already opened as fp outlist=[x, y, astr, z] repvars= repr(outlist)+"\n" fp.write(repvars) # Reading same list in: instr=fp.readline() inlist=eval(instr) x1,y1,astr1,z1= inlist That's what I needed. 3 lines to write or read a inhomogeneous collection of variables. I can add more variables, shuffle the order, whatever without messing with formatting, etc. That's pretty easy for me and it's easy for anyone to see and understand what's being done. Not trying to start an argument, just showing how the former messasge I was replying to made a good point about Python's way of doing things and the effort to shake off old habits from other languages. -- -- Lou Pecora From pecora at anvil.nrl.navy.mil Thu Feb 4 09:59:29 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 04 Feb 2010 09:59:29 -0500 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <7x8wb9j4r2.fsf@ruckus.brouhaha.com> Message-ID: In article <7x8wb9j4r2.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lou Pecora writes: > > after much noodling around and reading it hit me that I could just put > > all that output of different types of variables into a list, hit it > > with a repr() function to get a string version, and write the string > > to a file -- no formatting necessary-- three lines of code. Later > > reading in the string version (no formatting necessary), and hitting > > it with an eval() function returned all the values I originally had in > > those variables. How simple, but beautiful. > > FYI: I do that too sometimes, but in general using repr/eval that way > is poor style and not very reliable. It's better to use the pickle > module, which is intended for that sort of thing, or the json module > if your datatypes are suitable and you want to follow a semi-standard. Yeah, I should look into pickle. Haven't messed with that. Most of what I do is numerical calculations for my consumption/research so quick and easy comes first. Thanks for the hint. -- -- Lou Pecora From hidura at gmail.com Thu Feb 4 10:40:41 2010 From: hidura at gmail.com (Hidura) Date: Thu, 4 Feb 2010 11:40:41 -0400 Subject: Problem with __init__.py in Python3.1 In-Reply-To: References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> Message-ID: <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> Thanks, I read it and try to put my code in the correct form, but now give me another error, inside the Writer Package says: "ValueError: Attempted relative import in non-package", if somebody knows a clue of how fix it i will glad to read opinions. [?] On Thu, Feb 4, 2010 at 2:11 AM, Gabriel Genellina wrote: > En Thu, 04 Feb 2010 01:00:56 -0300, Hidura escribi?: > > > Good evening list, I have a really big trouble with the imports in the 3.1 >> version(Notes: In the older 2.64 theres no problems), I have two packages, >> the first package Utilities who contains Writer the second package, >> Writers >> contain the module tagmanip(What is imported in the best way inside the >> __init__.py of the Writer), when i make the import inside the writer >> everything is ok, but from the Utilities package the errors says: >> "ImportError: No module named tagsmanip". >> I don't understand why this is happening, if somebody could help me i will >> glad to hear any suggestion. >> > > In Python 3.x, "absolute" import is enabled by default (2.6 uses a mix of > relative and absolute imports). > To import sibling modules in a package, or modules in a subpackage, you > have to use relative imports: > > from . import tagmanip > from .Writers import tagmanip > > See PEP328 http://www.python.org/dev/peps/pep-0328/ > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 330.png Type: image/png Size: 611 bytes Desc: not available URL: From grflanagan at gmail.com Thu Feb 4 11:29:25 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 04 Feb 2010 16:29:25 +0000 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: > On 2/4/2010 7:05 AM, Shashwat Anand wrote: > > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is > there > any other approach possible. > > A brute force approach - create a grid of small squares and calculate which squares are in all circles. I don't know whether it is any better than monte-carlo: for two circles, delta=0.001 takes about a minute and delta=0.0001 is still running after 30 minutes :-) 1.22 1.2281 1.22834799999 ------------------------------------------------------------------ import math class Circle: def __init__(self, x, y, r=1): self.x = float(x) self.y = float(y) self.r = float(r) def contains(self, a, b): return math.sqrt((self.x-a)**2 + (self.y-b)**2) <= self.r class Grid: def __init__(self, circles): self.X1 = min(c.x-c.r for c in circles) self.Y1 = max(c.y+c.r for c in circles) self.X2 = max(c.x+c.r for c in circles) self.Y2 = min(c.y-c.r for c in circles) self.circles = circles def iter_boxes(self, delta): X2 = self.X2 Y2 = self.Y2 a = self.X1 while a < X2: a += delta b = self.Y1 while b > Y2: b -= delta #print a, b yield a, b def intersection(self, delta=0.1): S = 0 s = delta**2 #box area circles = self.circles for a, b in self.iter_boxes(delta): if all(c.contains(a, b) for c in circles): S += s return S c = Circle(0, 1) assert c.contains(0, 1) assert c.contains(0, 1.5) assert c.contains(math.sqrt(2)/2, math.sqrt(2)/2) assert c.contains(0, 2) assert not c.contains(0, 2.01) assert not c.contains(0, 2.1) assert not c.contains(0, 3) circles = [ Circle(0, 0), Circle(0, 1), ] g = Grid(circles) print '-'*30 print g.intersection() print g.intersection(0.01) print g.intersection(0.001) print g.intersection(0.0001) ------------------------------------------------------------------ From python at mrabarnett.plus.com Thu Feb 4 11:36:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Feb 2010 16:36:09 +0000 Subject: Repeat an exception In-Reply-To: <4B6AC4C8.5030902@sequans.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> <4B6A3C57.2000606@mrabarnett.plus.com> <4B6AC4C8.5030902@sequans.com> Message-ID: <4B6AF779.8010609@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > MRAB wrote: >> In other words: >> >> for attempt in range(2): >> try: >> spanish_field = translate(english_field, lang_to='es', >> lang_from='en') >> break >> except TranslationError: >> pass >> else: >> # Didn't break out of the loop, therefore not successful. >> print "Translation failed" > > What the hell is this 'for else' loop !! :D First time I see this > statement for years. > I'd never thought I'd still learn something that basic. > > My first impression is that the mechansim is not that obvious. MRAB's > need for a comment tends to confirm this. > I'll try to remember that anyway. Nice addition. > The comment is there for the OP. _I_ don't need it! :-) From apt.shansen at gmail.com Thu Feb 4 11:38:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 4 Feb 2010 08:38:37 -0800 Subject: Repeat an exception In-Reply-To: <4B6AC4C8.5030902@sequans.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> <4B6A3C57.2000606@mrabarnett.plus.com> <4B6AC4C8.5030902@sequans.com> Message-ID: <7a9c25c21002040838g5fed0fb1leffbe227c42119b8@mail.gmail.com> On Thu, Feb 4, 2010 at 4:59 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > What the hell is this 'for else' loop !! :D First time I see this statement > for years. > I'd never thought I'd still learn something that basic. > Its one of the least used constructs in Python, I think, and leads to periodic statements like this on the list where people who think they know all about Python suddenly see it and go WTF :) But in Python, all loops have an "else" clause that is fired when the loop terminates-- but *only* if it terminates normally, where 'normally' is basically, 'if you don't use break to exit the loop prematurely'. It allows you to do certain things in a way which is (arguably, and I so don't want to start an argument about this) a bit cleaner, where the normal method would require a flag or some such. For example, if you need want to loop over a sequence to test to see if they all match some criteria, you can use a for..else, or some flag variable. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Thu Feb 4 11:46:27 2010 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 04 Feb 2010 08:46:27 -0800 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: <4B6AF9E3.6020403@islandtraining.com> Gerard Flanagan wrote: > >> On 2/4/2010 7:05 AM, Shashwat Anand wrote: >> >> I want to calculate areas. >> like for two circles (0, 0) and (0, 1) : the output is >> '1.228370' >> >> similarly my aim is to take 'n' co-ordinates, all of radius >> '1' and >> calculate the area common to all. >> The best I got was monte-carlo methods which is inefficient. Is >> there >> any other approach possible. >> >> > > A brute force approach - create a grid of small squares and calculate > which squares are in all circles. I don't know whether it is any > better than monte-carlo: That's just what the monte-carlo method is -- except the full family of monte-carlo methods can be quite sophisticated, including being more general (pseudo or quasi random points instead of a regular grid) and can provide a theoretical basis for calculating the rate of convergence, and so on. Gary Herron > for two circles, delta=0.001 takes about a minute and delta=0.0001 is > still running after 30 minutes :-) > > 1.22 > 1.2281 > 1.22834799999 > > > ------------------------------------------------------------------ > import math > > class Circle: > > def __init__(self, x, y, r=1): > self.x = float(x) > self.y = float(y) > self.r = float(r) > > def contains(self, a, b): > return math.sqrt((self.x-a)**2 + (self.y-b)**2) <= self.r > > class Grid: > > def __init__(self, circles): > self.X1 = min(c.x-c.r for c in circles) > self.Y1 = max(c.y+c.r for c in circles) > self.X2 = max(c.x+c.r for c in circles) > self.Y2 = min(c.y-c.r for c in circles) > self.circles = circles > > def iter_boxes(self, delta): > X2 = self.X2 > Y2 = self.Y2 > a = self.X1 > while a < X2: > a += delta > b = self.Y1 > while b > Y2: > b -= delta > #print a, b > yield a, b > > def intersection(self, delta=0.1): > S = 0 > s = delta**2 #box area > circles = self.circles > for a, b in self.iter_boxes(delta): > if all(c.contains(a, b) for c in circles): > S += s > return S > > > c = Circle(0, 1) > > assert c.contains(0, 1) > assert c.contains(0, 1.5) > assert c.contains(math.sqrt(2)/2, math.sqrt(2)/2) > assert c.contains(0, 2) > assert not c.contains(0, 2.01) > assert not c.contains(0, 2.1) > assert not c.contains(0, 3) > > circles = [ > Circle(0, 0), > Circle(0, 1), > ] > > g = Grid(circles) > > print '-'*30 > print g.intersection() > print g.intersection(0.01) > print g.intersection(0.001) > print g.intersection(0.0001) > > ------------------------------------------------------------------ > From nobody at nowhere.com Thu Feb 4 11:46:47 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Feb 2010 16:46:47 +0000 Subject: Refreshing of urllib.urlopen() References: Message-ID: On Wed, 03 Feb 2010 21:33:08 -0600, Michael Gruenstaeudl wrote: > I am fairly new to Python and need advice on the urllib.urlopen() > function. The website I am trying to open automatically refreshes > after 5 seconds and remains stable thereafter. With > urllib.urlopen().read() I can only read the initial but not the > refreshed page. How can I access the refreshed page via > urlopen().read()? I have already tried to intermediate with > time.sleep() before invoking .read() (see below), but this does not > work. In all probability, the server is instructing the browser to load a different URL via either a Refresh: header or a tag in the page. You will have to retrieve that information then issue a request for the new URL. It might even be redirecting via JavaScript, in which case, you lose (it's possible to handle this case, but it's difficult). From nobody at nowhere.com Thu Feb 4 12:02:23 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Feb 2010 17:02:23 +0000 Subject: read a process output with subprocess.Popen References: Message-ID: On Thu, 04 Feb 2010 04:28:20 -0800, Ashok Prabhu wrote: > I m trying a read the output of a process which is running > continuously with subprocess.Popen. However the readline() method > hangs for the process to finish. Please let me know if the following > code can be made to work with subprocess.Popen with threads or queues. > I tried a lot of methods but to no avail. It would be great if someone > can make it work. This is an issue with grep, not Python per se. By default, stdout (in the C library) is line-buffered if it refers to a TTY, and block-buffered otherwise (e.g. if it refers to a pipe). grep doesn't change the default buffering, so when it's stdout is a pipe, its output is written in 4K blocks. If you only need this to work with GNU grep, you can use the --line-buffered switch to force stdout to be flushed after each line. If it needs to be portable, you can implement the grep part in Python (i.e. read p1.stdout and ignore any lines which don't contain a given string or which don't match a given regex). From john at castleamber.com Thu Feb 4 12:22:27 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 11:22:27 -0600 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <87iqadde68.fsf@castleamber.com> <7svh39F8vvU1@mid.uni-berlin.de> Message-ID: <87636c531o.fsf@castleamber.com> "Diez B. Roggisch" writes: > Am 04.02.10 01:42, schrieb John Bokma: [..] >> Maybe you should think about what happens if someone posts: >> to a popular forum... > > And the difference to posting > > from urrlib2 import open > from urllib import encode > > open("http://example.com/item_delete", data=encode([("id", "123")])) > > to that same public "hacker" forum is exactly what? Imagine that a user of example.com, logged in at example.com (i.e. with a valid session ID in a cookie), visits the aforementioned (by me) forum, and that he has an item 123. It will be deleted. > If your webapp happens to allow item_delete to be called without > authentication & authorization, then *that's* your problem. You now understand that *with* a & a a GET request can be *still* harmful? -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From grflanagan at gmail.com Thu Feb 4 12:24:37 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 04 Feb 2010 17:24:37 +0000 Subject: Common area of circles In-Reply-To: <4B6AF9E3.6020403@islandtraining.com> References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> <4B6AF9E3.6020403@islandtraining.com> Message-ID: Gary Herron wrote: > Gerard Flanagan wrote: >> >> A brute force approach - create a grid of small squares and calculate >> which squares are in all circles. I don't know whether it is any >> better than monte-carlo: > > That's just what the monte-carlo method is -- except the full family of > monte-carlo methods can be quite sophisticated, including being more > general (pseudo or quasi random points instead of a regular grid) and > can provide a theoretical basis for calculating the rate of convergence, > and so on. > I would have said a Monte Carlo method necessarily involves random sampling in some shape or form, no? (Casinos, Chance etc..) And as I've previously understood Monte Carlo Integration, the technique involves rather the ratio "hits/total sample" rather than the sum of small areas. That's how I remember it, at least - it's been a while though. Regards G.F From john at castleamber.com Thu Feb 4 12:26:26 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 11:26:26 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87wrytdirw.fsf@castleamber.com> <9e80909d-906c-466b-b9cb-77400a42ee7e@r24g2000yqd.googlegroups.com> Message-ID: <87y6j83oal.fsf@castleamber.com> Marius Gedminas writes: > On Feb 4, 1:03?am, John Bokma wrote: >> Jonathan Gardner writes: >> > I can explain all of Python in an hour; >> >> OK, in that case I would say give it a go. Put it on YouTube, or write a >> blog post about it (or post it here). I am sure you will help a lot of >> people that way. > > Someone already did: "Advanced Python or Understanding Python" > http://video.google.com/videoplay?docid=7760178035196894549 > (76 minutes). > > Worth watching. Thanks, I will. And let you know if it succeeds at "explain all of Python in 76 minutes". It's not a fair test, since I am not new to Python, but let me see first ;-) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From davea at ieee.org Thu Feb 4 12:27:16 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 04 Feb 2010 12:27:16 -0500 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: <4B6B0374.8060400@ieee.org> Shashwat Anand wrote: > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is there any > other approach possible. > > > You start with a list of circles, each having center (a,b), and radius (r). As you stated the problem, r is always 1, but I'll keep the algorithm general. This is untested, and probably contains typos, at least. I would do it with successively smaller squares. A square can be described using center coordinates (x,y) , and length (s) of a side. Each square can have three states: not included, partially included, and fully included. You build a list of squares, starting with one, the bounding square for the first circle. For each square in the list, you go through all the circles (each with center a,b, and radius r), and for each circle decide if the square is entirely within the circle, or partially. If it's fully included in all of them, you add its area to the the accumulator, and drop it from your list. if it's not included at all in one of them, you just drop it from the list. (Note, be careful about modifying a list you're iterating through -- make a copy) After a pass through the list, the accumulator is a lower-bound for the area, and the accumulator plus the areas of all the squares is an upper bound. If these are close enough together, you terminate. Otherwise you take the remaining squares in the list, split each into four pieces, and end up with a list 4 times as long. And repeat the loop, checking each square against each circle. The only remaining question is how you decide for a given circle and a given square which of the three states it's in. And it turns out you can be pretty approximate in this, and it'll still converge. So you can take a distance between (a,b) and (x,y), and compare it to r-s/2 and to r+(s*0.707106781187). If it's greater than r+s*0.707106781187, no intersection. If it's less than r-s/2, then the square's entirely inside. Note that I used 0.707106781187 above, but you'd actually use sqr(0.5) to whatever precision you needed. And if it's convenient to round it, round it upwards; again it won't affect the result. I doubt if it would matter in Python code, but you could even do the whole thing in integers (avoiding the sqrt for distance calc), if you were careful about the bounding formulas. That's premature optimization, however. HTH, DaveA From john at castleamber.com Thu Feb 4 12:49:21 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 11:49:21 -0600 Subject: YAML References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> Message-ID: <87tytw3n8e.fsf@castleamber.com> Lou Pecora writes: > In article <87eil1ddjp.fsf_-_ at castleamber.com>, > John Bokma wrote: > >> Lou Pecora writes: >> >> > That's a pretty accurate description of how I transitioned to Python >> > from C and Fortran. >> >> Not C, but C++ (but there are also C implementations): YAML, see: >> http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument >> >> I use YAML now and then with Perl for both reading/writing data and for >> debugging purposes (YAML is quite human readable, for programmers at least) >> >> Of course there is also YAML support for Python: >> http://pyyaml.org/. > > Well, that looks a bit more complicated than I would like, but maybe > it's doing more stuff than I can grok. Here's what I needed and how I > did it in Python: > > # Make some variables > x=1.234e-8 > y=2 > astr="An output string...whatever" > z=4.5+1j*1.3456 # a complex number > > # Output them to a file already opened as fp > outlist=[x, y, astr, z] > repvars= repr(outlist)+"\n" > fp.write(repvars) > > # Reading same list in: > instr=fp.readline() > inlist=eval(instr) > x1,y1,astr1,z1= inlist > > > That's what I needed. 3 lines to write or read a inhomogeneous > collection of variables. I can add more variables, shuffle the order, > whatever without messing with formatting, etc. That's pretty easy for me > and it's easy for anyone to see and understand what's being done. Not > trying to start an argument, just showing how the former messasge I was > replying to made a good point about Python's way of doing things and the > effort to shake off old habits from other languages. My C++ is rusty to say the least, so I can't give you an example in C++, and the C++ version will be longer than the Python version for sure. I use YAML, YAML::Syck to be precise, now and then in Perl. In Perl, if $data is a reference to an arbitrary (complex) datastructure: DumpFile( 'filename', $data ); writes it out and $data = LoadFile( 'filename' ); reads it back in. Since YAML is to some extent human readable, I now and then use it for debugging purposes over Data::Dumper, also because the output is more compact, e.g. die Dump $data; Personally I think it's good to be aware of YAML, since it's supported by several languages and it should in general be possible to exchange the generated YAML between them. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From deets at nospam.web.de Thu Feb 4 13:07:39 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 19:07:39 +0100 Subject: Passing parameters in URL In-Reply-To: <87636c531o.fsf@castleamber.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <87iqadde68.fsf@castleamber.com> <7svh39F8vvU1@mid.uni-berlin.de> <87636c531o.fsf@castleamber.com> Message-ID: <7t0gndFu21U1@mid.uni-berlin.de> Am 04.02.10 18:22, schrieb John Bokma: > "Diez B. Roggisch" writes: > >> Am 04.02.10 01:42, schrieb John Bokma: > > [..] > >>> Maybe you should think about what happens if someone posts: >>> to a popular forum... >> >> And the difference to posting >> >> from urrlib2 import open >> from urllib import encode >> >> open("http://example.com/item_delete", data=encode([("id", "123")])) >> >> to that same public "hacker" forum is exactly what? > > Imagine that a user of example.com, logged in at example.com (i.e. with > a valid session ID in a cookie), visits the aforementioned (by me) > forum, and that he has an item 123. It will be deleted. The webapp must be actually preventing the processing of GET-requests for the aciton in question. This isn't the case by default for many of them, in fact at least e.g. TurboGears, as well as PHP offer you ways to treat GET and POSTvars the exact same way. So unless the programmer is aware of this potential problem, it won't help. And in the same way one can embed a form with a post-action that leads to the full http://example.com-url into an external page. So it is equally as dangerous. Yes, links are easier, no doubt about that. But POST doesn't magically make you safe from those kinds of attacks. The only way to prevent this are short-lived sessions, or action-tokens of some kind, as Paul mentioned before. Diez From python at rcn.com Thu Feb 4 13:18:23 2010 From: python at rcn.com (Raymond Hettinger) Date: Thu, 4 Feb 2010 10:18:23 -0800 (PST) Subject: Selenium/SauceLabs OpenSpace at Pycon References: Message-ID: <63678d2b-2571-42fb-aa9b-90737cea561e@w27g2000pre.googlegroups.com> > >For those who are interested, the Sauce Labs team, > >http://saucelabs.com/about/team, is hosting two free tutorial open > >space sessions at Pycon in Atlanta. [Aahz] > Congrats on the new job! Thanks. I'm really enjoying working with Jim Baker and Frank Wierzbicki. Raymond From duncan.booth at invalid.invalid Thu Feb 4 13:23:35 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Feb 2010 18:23:35 GMT Subject: Building a multiline string References: Message-ID: lallous wrote: > Now should I be using method 2 or 3 in production code? Also Method1a: # Method1a x = ("line1" + # can use comments! "line2"+ "line3") Use Method1a or Method3 as you prefer: either of these generates a single string constant. Method2 is dumb. From dickinsm at gmail.com Thu Feb 4 13:55:14 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 4 Feb 2010 10:55:14 -0800 (PST) Subject: Common area of circles References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: On 2/4/2010 7:05 AM, Shashwat Anand wrote: > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is there > any other approach possible. How much accuracy do you need? How fast does the algorithm need to be? How many circles are typically involved? Is the intersection necessarily non-empty for the configurations of circles that you use? How much code are you prepared to write? How much mathematics do you want to use? Besides the Monte-Carlo and grid-based approaches already mentioned, I see a couple of other possibilities: (1) It should be entirely possible to do this analytically. The hard part would be identifying the intersection points that form the vertices of the intersection (and especially, doing this robustly in the face of numerical errors and triple intersections or near-triple intersections). Once you've got the vertices, it should be straightforward to compute the area: compute the area of the polygon given by the convex hull of the vertices, then add on the extra areas for the segments bounded by the (straight) sides of the polygon and the corresponding outer arcs. (2) For a numerical approach that might be slightly better than the 2d brute-force approaches described by others: make use of the fact that the intersection is convex. Pick a point P in the intersection (if it exists: finding such a point is an issue in itself). For each angle t, 0 <= t <= 2*pi, define f(t) to be the distance from P to the boundary of the region, in the direction of the angle t. We always have 0 <= f(t) <= 1, so f(t) can be quickly and accurately computed with a bisection search. Now find the definite integral of 0.5 * (f(t))**2, as t goes from 0 to 2*pi, using your favourite quadrature method (but avoid methods that would be very sensitive to continuity of derivatives: f(t) will be continuous, but f'(t) will not). Simpson's rule is probably good enough. Good luck! -- Mark From tompelka at gmail.com Thu Feb 4 14:05:51 2010 From: tompelka at gmail.com (Tomas Pelka) Date: Thu, 04 Feb 2010 20:05:51 +0100 Subject: how to run part of my python code as root Message-ID: <4B6B1A8F.1000504@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey, is there possibility how to run part of my code (function for example) as superuser. Or only way how to do this is create a wrapper and run is with Popen through sudo (but I have to configure sudo to run "whole" python as root). Thanks for advice. - -- Tom Key fingerprint = 06C0 23C6 9EB7 0761 9807 65F4 7F6F 7EAB 496B 28AA -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAktrGoYACgkQf29+q0lrKKqaNACdEvfg+g0n3DzFr/7R33y2Nesy hK8An3ZlpUEEibf0Q1wVET/KpXnsv/PO =JKro -----END PGP SIGNATURE----- From anand.shashwat at gmail.com Thu Feb 4 14:19:59 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Feb 2010 00:49:59 +0530 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: maximum number of circles = 10**6 runtime <= 5 sec center of circles , -1000<=xi,yi<=1000 (float) [for int it was easier] intersection is there and the area will be non-zero (it can always be checked if intersection is taking place and if no, then area = 0.000000) This was a programming contest problem, so code will be short Maths, I'm eager to use. I attempted this problem because I saw scope of maths in it. (I learnt python while doing ProjectEuler because C/C++ was cumbersome for PE IMHO). I tried monte-carlo, but the time-limit exceeds if i go for required accuracy. The same happens with grid approach. On Fri, Feb 5, 2010 at 12:25 AM, Mark Dickinson wrote: > On 2/4/2010 7:05 AM, Shashwat Anand wrote: > > I want to calculate areas. > > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > > calculate the area common to all. > > The best I got was monte-carlo methods which is inefficient. Is there > > any other approach possible. > > How much accuracy do you need? How fast does the algorithm need to > be? How many circles are typically involved? Is the intersection > necessarily non-empty for the configurations of circles that you use? > How much code are you prepared to write? How much mathematics do you > want to use? > > Besides the Monte-Carlo and grid-based approaches already mentioned, I > see a couple of other possibilities: > > (1) It should be entirely possible to do this analytically. The hard > part would be identifying the intersection points that form the > vertices of the intersection (and especially, doing this robustly in > the face of numerical errors and triple intersections or near-triple > intersections). Once you've got the vertices, it should be > straightforward to compute the area: compute the area of the polygon > given by the convex hull of the vertices, then add on the extra areas > for the segments bounded by the (straight) sides of the polygon and > the corresponding outer arcs. > > (2) For a numerical approach that might be slightly better than the 2d > brute-force approaches described by others: make use of the fact that > the intersection is convex. Pick a point P in the intersection (if it > exists: finding such a point is an issue in itself). For each angle > t, 0 <= t <= 2*pi, define f(t) to be the distance from P to the > boundary of the region, in the direction of the angle t. We always > have 0 <= f(t) <= 1, so f(t) can be quickly and accurately computed > with a bisection search. Now find the definite integral of 0.5 * > (f(t))**2, as t goes from 0 to 2*pi, using your favourite quadrature > method (but avoid methods that would be very sensitive to continuity > of derivatives: f(t) will be continuous, but f'(t) will not). > Simpson's rule is probably good enough. > > Good luck! > > -- > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Thu Feb 4 14:21:30 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 16:21:30 -0300 Subject: Problem with __init__.py in Python3.1 References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> Message-ID: En Thu, 04 Feb 2010 12:40:41 -0300, Hidura escribi?: > Thanks, I read it and try to put my code in the correct form, but now > give > me another error, inside the Writer Package says: > "ValueError: Attempted relative import in non-package", if somebody > knows a > clue of how fix it i will glad to read opinions. [?] You say that Writer is a package, but apparently Python disagrees. A package is not just "a directory containing an __init__.py file", this is half the truth. Python must be *aware* of such file, and this happens when you import the package. If you directly run a script from inside a package, Python does not know that it belongs to a package, and treats it as a simple, lonely script. In that case, relative imports won't work. Put the "main" script (the one that you directly execute) outside the package. It can be as small as this, if you want: from some.package import main main() -- Gabriel Genellina From no.email at nospam.invalid Thu Feb 4 14:48:35 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 11:48:35 -0800 Subject: Selenium/SauceLabs OpenSpace at Pycon References: Message-ID: <7xwryssrxo.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > Raymond Hettinger wrote: >>For those who are interested, the Sauce Labs team, >>http://saucelabs.com/about/team, is hosting two free tutorial open >>space sessions at Pycon in Atlanta. > > Congrats on the new job! Yes, cool! I don't recognize several of these logos, but maybe Sauce can help: http://aasi.ebm.fi/5742/browsers.jpg ;-) From sjdevnull at yahoo.com Thu Feb 4 14:56:57 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 4 Feb 2010 11:56:57 -0800 (PST) Subject: how to run part of my python code as root References: Message-ID: On Feb 4, 2:05?pm, Tomas Pelka wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hey, > > is there possibility how to run part of my code (function for example) > as superuser. > > Or only way how to do this is create a wrapper and run is with Popen > through sudo (but I have to configure sudo to run "whole" python as root). In decreasing order of desirability: 1. Find a way to not need root access (e.g. grant another user or group access to whatever resource you're trying to access). 2. Isolate the stuff that needs root access into a small helper program that does strict validation of all input (including arguments, environment, etc); when needed, run that process under sudo or similar. 2a. Have some sort of well-verified helper daemon that has access to the resource you need and mediates use of that resource. 3. Run the process as root, using seteuid() to switch between user and root privs. The entire program must be heavily verified and do strict validation of all inputs. Any attacker who gets control over the process can easily switch to root privs and do damage. This is generally a bad idea. From john at castleamber.com Thu Feb 4 15:15:05 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 14:15:05 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87wrytdirw.fsf@castleamber.com> <9e80909d-906c-466b-b9cb-77400a42ee7e@r24g2000yqd.googlegroups.com> Message-ID: <87bpg4ahbq.fsf@castleamber.com> Marius Gedminas writes: > On Feb 4, 1:03?am, John Bokma wrote: >> Jonathan Gardner writes: >> > I can explain all of Python in an hour; >> >> OK, in that case I would say give it a go. Put it on YouTube, or write a >> blog post about it (or post it here). I am sure you will help a lot of >> people that way. > > Someone already did: "Advanced Python or Understanding Python" > http://video.google.com/videoplay?docid=7760178035196894549 > (76 minutes). > > Worth watching. Certainly worth watching (I learned some stuff), but in my opinion you /need to have some Python experience/ to be able to follow so no (IMO), someone didn't do it already. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From g.bogle at auckland.no.spam.ac.nz Thu Feb 4 15:50:29 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Fri, 05 Feb 2010 09:50:29 +1300 Subject: Python 3 minor irritation References: Message-ID: Gabriel Genellina wrote: > But the associated program might change the current directory - that's > not the case with the default associations created by the Python > installer, but one should verify this. > To the OP: please create this small test script > > import os > print("curdir=", os.getcwd()) > print("__file__=", __file__) > input() > > and post what you get when you double-click on it. > > Also, from the command line, execute: > > D:\temp>reg query HKCR\.py > > ! REG.EXE VERSION 3.0 > > HKEY_CLASSES_ROOT\.py > REG_SZ Python.File > Content Type REG_SZ text/plain > > HKEY_CLASSES_ROOT\.py\PersistentHandler I'm interested in this, because I'm using Windows XP, and when I execute this command I see the first part but not the second (with PersistentHandler). Is this related to the fact that when I double-click on a .py file the command window disappears after the execution is completed? From ALANBIDDLE70 at YAHOO.COM Thu Feb 4 15:55:21 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Thu, 04 Feb 2010 14:55:21 -0600 Subject: Passing command line argument to program from within IDLE? Message-ID: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Just finishing my first Python (2.6 on Win XP) program, which is working fine. My "Duh?" question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. -- Alan From jgardner at jonathangardner.net Thu Feb 4 15:55:44 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 4 Feb 2010 12:55:44 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: On Feb 3, 3:39?pm, Steve Holden wrote: > Robert Kern wrote: > > On 2010-02-03 15:32 PM, Jonathan Gardner wrote: > > >> I can explain all of Python in an hour; I doubt anyone will understand > >> all of Python in an hour. > > > With all respect, talking about a subject without a reasonable chance of > > your audience understanding the subject afterwards is not explaining. > > It's just exposition. > > I agree. If the audience doesn't understand then you haven't explained it. > On the contrary, that explanation would have everything you need. It would take an hour to read or listen to the explanation, but much more than that time to truly understand everything that was said. From steve at REMOVE-THIS-cybersource.com.au Thu Feb 4 16:03:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2010 21:03:06 GMT Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> Message-ID: <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 09:57:59 -0500, Lou Pecora wrote: > Well, that looks a bit more complicated than I would like, but maybe > it's doing more stuff than I can grok. Here's what I needed and how I > did it in Python: [...] > # Reading same list in: > instr=fp.readline() > inlist=eval(instr) > x1,y1,astr1,z1= inlist > > > That's what I needed. 3 lines to write or read a inhomogeneous > collection of variables. Easy, but also quick and dirty -- good enough for small scripts, but not really good enough for production applications. > I can add more variables, shuffle the order, > whatever without messing with formatting, etc. This is nice and easy. But there are at least four catches: * you can't safely treat the data file as human-editable (although a sufficiently careful and Python-aware user could edit it) * you can't use any data that isn't a built-in, or that contains something that is not a built-in * there may be reliability issues with floats - you're at the mercy of changes to the underlying repr of float objects, and it almost certainly will blow up in your face if you get an inf or nan (at least prior to Python 2.6) * you're using eval, which is a security risk if you can't trust the source of the data file. However, be aware that neither marshal nor pickle guarantees to be safe against malicious data either. The docs for both warn against using them on untrusted data. YAML or JSON *might* be safer, I haven't looked. > That's pretty easy for me > and it's easy for anyone to see and understand what's being done. Not > trying to start an argument, just showing how the former messasge I was > replying to made a good point about Python's way of doing things and the > effort to shake off old habits from other languages. These are all good points. -- Steven From tjreedy at udel.edu Thu Feb 4 16:14:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 16:14:33 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: On 2/4/2010 3:55 PM, Alan Biddle wrote: > Just finishing my first Python (2.6 on Win XP) program, which is > working fine. My "Duh?" question is about how to run it from within > IDLE and pass it command line arguments. No problem using sys.argv > from a Windows command line, but I have missed how you can do that > from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>> import sys >>> sys.argv [''] >>> sys.argv = ['abc','dev'] >>> sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. Terry Jan Reedy From john at castleamber.com Thu Feb 4 16:18:53 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 15:18:53 -0600 Subject: YAML References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> Message-ID: <877hqsaede.fsf@castleamber.com> Steven D'Aprano writes: > However, be aware that neither marshal nor pickle guarantees to be safe > against malicious data either. The docs for both warn against using them > on untrusted data. YAML or JSON *might* be safer, I haven't looked. Regarding malicious data, from the Loading YAML section of PyYAML: Warning: It is not safe to call yaml.load with any data received from an untrusted source! yaml.load is as powerful as pickle.load and so may call any Python function. Check the yaml.safe_load function though. http://pyyaml.org/wiki/PyYAMLDocumentation#LoadingYAML yaml.safe_load however, limits to simple Python objects and Python objects you mark as safe. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steve at holdenweb.com Thu Feb 4 16:28:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 16:28:17 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: Terry Reedy wrote: > On 2/4/2010 3:55 PM, Alan Biddle wrote: >> Just finishing my first Python (2.6 on Win XP) program, which is >> working fine. My "Duh?" question is about how to run it from within >> IDLE and pass it command line arguments. No problem using sys.argv >> from a Windows command line, but I have missed how you can do that >> from within IDLE, which complicates development and debugging. > > I presume you mean edit, F5-run, see result in shell window. > Set sys.argv in test function or __name__=='__main__' > In 3.1 idle shell: > >>>> import sys >>>> sys.argv > [''] >>>> sys.argv = ['abc','dev'] >>>> sys.argv > ['abc', 'dev'] > > I did not know it was writable, either, until I tried it. > As a solution, however, that sucks, wouldn't you agree? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ALANBIDDLE70 at YAHOO.COM Thu Feb 4 16:37:10 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Thu, 04 Feb 2010 15:37:10 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: Yes, that is what I was trying to do. I need to puzzle a bit on the solution, being a newbie. Thanks! -- Alan From ALANBIDDLE70 at YAHOO.COM Thu Feb 4 16:47:09 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Thu, 04 Feb 2010 15:47:09 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: <7rfmm5h99dsfico46fnbrkjbouujli49a7@4ax.com> Terry, CLICK, the light just came on. Knowing that it is writable, I can look at the length to determine whether there are any arguments. If not, I can switch to interactive input within the program, and input the values that way. A few easy extra lines. Whatever works. Thanks!! -- Alan From xahlee at gmail.com Thu Feb 4 17:26:02 2010 From: xahlee at gmail.com (Xah Lee) Date: Thu, 4 Feb 2010 14:26:02 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: 2010-02-04 Hi Steve, thank you for the reply. I appreciate that you taking this more seriously than normal newsgroups postings. In fact, for this complaint, the response you made is all i asked for. I have a lot things to say about the various political struggle that one sees everyday in just about every communication channels that are predominantly young male groups, of relatively few people, in online posting forums, ircs, online massive multiplayer games... as you may know, the quarrels, accusations, bans, happen every hour. But to be concrete and constructive, i would suggest that in freenode's python irc channel: ? when a admin bans someone, the admin needs to tell the person the reason, and not in some rude way. (a single sentence will do.) ? The list of ban'd person's names, the reason for banning, and the name of admin who ban'd them, should be public. (irc already provides means for this that allows admins to annotate in the ban list.) In particular, if you are going to ban someone by ip address, make sure the person's handle (or preferably real life name), be listed together with it. (again, this needs not elaborate. A single sentence will do, e.g. ?repeatedly asking same question?, ?continously raising controversial issues?, ?refused to use paste bin when requested? will do. Again, be as precise in description as possible. For example, ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) ? additionally, i would suggest that bans be temporary. The following period seems a good start: 5 min ban, 1 hour ban, 1 day ban, 1 week ban, 1 month ban. Each can be executed according to severity per the admin's judgement. There should be no permanent ban, unless it's machine generated commercial spam. Thank you. For anyone reading this thread and interested in my opinions, i have written many essays related to this and netiquette. Many of which detail other similar incidences that i personally experienced, such as freenode's irc ban in #emacs channel. If you are interested, they can be found on my website, search for ?ban xah lee?. Xah ? http://xahlee.org/ ? On Feb 2, 2:23?pm, "Steve Holden, Chairman, PSF" wrote: > Xah Lee wrote: > > This is a short complaint on admin abuse on #python irc channel on > > freenode.net. > > > Here's a log: > > > 2010-02-02 > > > (12:11:57 PM) The topic for #python is: NO LOL |http://pound-python.org/ > > | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: > >http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ: > >http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy > > | #python.web #wsgi #python-fr #python.de #python-es #python.tw > > #python.pl #python-br #python-jp #python-nl #python-ir #python- > > offtopic > > (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, > > actually. > > (12:12:01 PM) jarray52: Jarray > > (12:12:11 PM) _habnabit: jarray52, yes, you are. > > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > > (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops > > etc) right is quite tricky > > (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just > > wondering whats up with the python verison :D > > (12:12:24 PM) mode (+o dash) by ChanServ > > (12:12:30 PM) You have been kicked by dash: (No.) > > > --------------- > > > I have not been using irc for the past about 2 year. (possibly perhaps > > 2 times in i think #web channel) In particular, i have not been in in > > freenode.net's #python channel. I don't know who is dash. > > > ? Xah > > ?http://xahlee.org/ > > > ? > > Frankly, Xah Lee, I find it ironic that you see fit to complain about > abuse of the IRC channel when you have apparently felt free to ignore > the many complaints about your behavior on this and other newsgroups > over many years. > > "As ye sew, so shall ye reap". I imagine that your reputation has > preceded you, and that dash (whom I *do* know) is simply looking to keep > a well-known nuisance from bothering the rest of the users on the channel. > > For the present my sympathies are all with him. The PSF will, however, > investigate this issue and I will report back to you off-list in due course. > > regards > ?Steve > -- > Steve Holden ? ? ? ?Chairman, Python Software Foundation > The Python Community Conference ?http://python.org/psf/ > PyCon 2010 Atlanta Feb 19-21 ? ? ? ?http://us.pycon.org/ > Watch PyCon on video now! ? ? ? ? ?http://pycon.blip.tv/ From news123 at free.fr Thu Feb 4 17:34:20 2010 From: news123 at free.fr (News123) Date: Thu, 04 Feb 2010 23:34:20 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used Message-ID: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Hi, I wrote a small xmlrpc client on Windows 7 with python 2.6 srv = xmlrpclib.Server('http://localhost:80') I was able to perform about 1 rpc call per second After changing to srv = xmlrpclib.Server('http://127.0.0.1:80') I was able to perform about 10 to 16 rpc calls per second. So it seems, that under windows 7 the host name lookup occurs for every RPC call (which is of course necessary for long running processes, as the target host might change it's ip during the scripts execution) For my use cases however I could live with one IP-address lookup at the beginning of the script. I wonder now about how I could deal with virtual web servers. ( a web server running with one ip-adress and one port, which behaves differntly depending on the host name of the url request) I'm just curious, as currently I don't have to access virtual servers via xmlrpc, Is there any way to 'pre-lookup the IP address', and to keep the host name in the http POST request? thanks for any ideas N From ben+python at benfinney.id.au Thu Feb 4 17:47:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Feb 2010 09:47:21 +1100 Subject: Problem with __init__.py in Python3.1 References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> Message-ID: <871vh0mxdy.fsf@benfinney.id.au> "Gabriel Genellina" writes: > If you directly run a script from inside a package, Python does not > know that it belongs to a package, and treats it as a simple, lonely > script. In that case, relative imports won't work. Which I consider to be a bug. Fortunately, it's already addressed in PEP 366 . Unfortunately, it involves more hackish boilerplate at the top of the program, and is only available in Python 2.6+. -- \ ?Ignorance more frequently begets confidence than does | `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | _o__) | Ben Finney From wanderer at dialup4less.com Thu Feb 4 17:52:03 2010 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 4 Feb 2010 14:52:03 -0800 (PST) Subject: Background Zones in Pylab Plot References: <1eaf6046-db41-44b5-8c9e-b7a15e4cf078@30g2000vbj.googlegroups.com> <5a9e5eaf-2006-4dfe-8498-a544c09a8584@r6g2000yqn.googlegroups.com> Message-ID: On Feb 3, 10:50?pm, CM wrote: > On Feb 3, 10:49?am, Wanderer wrote: > > > I would like to add background zones in pylab plots. Colored sections > > of the background that the curves pass through. Is this possible? My > > google searches don't turn up anything but maybe my search terms > > aren't the right ones. > > > Thanks > > If you look at the matplotlib gallery, I think there may be some > images > that show something like what you want, and then you can look at the > code. ?It's here: > > http://matplotlib.sourceforge.net/gallery.html > > HTH, > Che That helped. There should be something in there I can use. Thank you From robert.kern at gmail.com Thu Feb 4 17:56:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Feb 2010 16:56:44 -0600 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: On 2010-02-04 14:55 PM, Jonathan Gardner wrote: > On Feb 3, 3:39 pm, Steve Holden wrote: >> Robert Kern wrote: >>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >> >>>> I can explain all of Python in an hour; I doubt anyone will understand >>>> all of Python in an hour. >> >>> With all respect, talking about a subject without a reasonable chance of >>> your audience understanding the subject afterwards is not explaining. >>> It's just exposition. >> >> I agree. If the audience doesn't understand then you haven't explained it. > > On the contrary, that explanation would have everything you need. It > would take an hour to read or listen to the explanation, but much more > than that time to truly understand everything that was said. Like I said, that's exposition, not explanation. There is an important distinction between the two words. Simply providing information is not explanation. If it takes four hours for your audience to understand it, then you explained it in four hours no matter when you stopped talking. -- 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 senhor.abrantes at gmail.com Thu Feb 4 17:57:53 2010 From: senhor.abrantes at gmail.com (joao abrantes) Date: Thu, 4 Feb 2010 22:57:53 +0000 Subject: Pixel control Message-ID: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> Hello everyone. For example i am using a screen resolution of 800x600 is it possible to make python control the color of the pixels? For example paint the pixel (100,200) in red! And it would stay red when i am seeing a webpage, a movie, playing a game... etc.. Regards, Jo?o Abrantes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at boddie.org.uk Thu Feb 4 17:59:44 2010 From: david at boddie.org.uk (David Boddie) Date: Thu, 04 Feb 2010 23:59:44 +0100 Subject: PyQt4 designer custom properties - combo box style References: Message-ID: On Tuesday 02 February 2010 22:25, Andrew wrote: > I am creating custom widgets for the PyQt4 Designer. I can create > custom properties, but I'm looking for how to create a custom property > that has a combo box drop down. I've seen them in the example widgets > and tried following them, but they are using pre-defined items to > populate their property, so it's not a very clear example of how to > get the combo box property to work. Can you explain a bit more about what you have seen and what you are trying to do. Are you trying to create a property that is treated specially by Designer or do you want to get the data for the combo box from somewhere else? > Is there any other examples or help for this kind of setup? Have you seen this article? http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html David From steve at REMOVE-THIS-cybersource.com.au Thu Feb 4 18:01:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2010 23:01:02 GMT Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: <00f4d6df$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: > Terry Reedy wrote: >> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>> Just finishing my first Python (2.6 on Win XP) program, which is >>> working fine. My "Duh?" question is about how to run it from within >>> IDLE and pass it command line arguments. No problem using sys.argv >>> from a Windows command line, but I have missed how you can do that >>> from within IDLE, which complicates development and debugging. >> >> I presume you mean edit, F5-run, see result in shell window. Set >> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >> >>>>> import sys >>>>> sys.argv >> [''] >>>>> sys.argv = ['abc','dev'] >>>>> sys.argv >> ['abc', 'dev'] >> >> I did not know it was writable, either, until I tried it. >> > As a solution, however, that sucks, wouldn't you agree? [scratches head] Do you mean setting sys.argv as a solution sucks? No, I don't, I think it is grand. If sys.argv was unmodifiable, *that* would suck. Or do you mean that trying it as a solution to the problem of answering the OP's question sucks? Well, no, experimentation is good for answering these sorts of questions, and I can't assume that the documentation will cover every imaginable use-case, or that users will find it. In the absence of any documentation stating otherwise, I would have assumed that sys.argv was an ordinary list which you can modify at will, but having been caught out on faulty assumptions before, I would try it and see before commenting publicly. -- Steven From steve at holdenweb.com Thu Feb 4 18:02:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 18:02:53 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B6B521D.6050408@holdenweb.com> Xah Lee wrote: > 2010-02-04 > > Hi Steve, > > thank you for the reply. > > I appreciate that you taking this more seriously than normal > newsgroups postings. In fact, for this complaint, the response you > made is all i asked for. > OK, in that case I won't trouble anyone else about it. > I have a lot things to say about the various political struggle that > one sees everyday in just about every communication channels that are > predominantly young male groups, of relatively few people, in online > posting forums, ircs, online massive multiplayer games... as you may > know, the quarrels, accusations, bans, happen every hour. > I understand that the diversity of the various channels available to Python users (and indeed of the Python community overall) is not as high as it could be. This does from time to time lead to inappropriate behaviors. I suspect dash kicked you off #python simply because of the reputation you have established on comp.lang.python, but of course I cannot speak for him. > But to be concrete and constructive, i would suggest that in > freenode's python irc channel: > > ? when a admin bans someone, the admin needs to tell the person the > reason, and not in some rude way. (a single sentence will do.) > That would, I agree, be appropriate. > ? The list of ban'd person's names, the reason for banning, and the > name of admin who ban'd them, should be public. (irc already provides > means for this that allows admins to annotate in the ban list.) In > particular, if you are going to ban someone by ip address, make sure > the person's handle (or preferably real life name), be listed together > with it. (again, this needs not elaborate. A single sentence will do, > e.g. ?repeatedly asking same question?, ?continously raising > controversial issues?, ?refused to use paste bin when requested? will > do. Again, be as precise in description as possible. For example, > ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) > This is perhaps a little formal for something that (as far as I know) happens less than once a month. I am reluctant to start up any kind of bureaucracy around bannings unless they become too frequent (in which case your suggestions above seem reasonable). > ? additionally, i would suggest that bans be temporary. The following > period seems a good start: 5 min ban, 1 hour ban, 1 day ban, 1 week > ban, 1 month ban. Each can be executed according to severity per the > admin's judgement. There should be no permanent ban, unless it's > machine generated commercial spam. > Again, this is probably over-formal for the current levels of banning, but a reasonable idea in principle. > Thank you. > > For anyone reading this thread and interested in my opinions, i have > written many essays related to this and netiquette. Many of which > detail other similar incidences that i personally experienced, such as > freenode's irc ban in #emacs channel. If you are interested, they can > be found on my website, search for ?ban xah lee?. > Xah, your opinions are I think pretty well-known around here. I understand that you consider yourself an authority on netiquette, but as I mentioned in my last response I have personally observed you on many occasions indulging in inappropriate behavior such as cross-posting irrelevant material to many newsgroups at the same time. It is actions like that, combined with your use of intemperate and abusive language, that caused you to get banned before you had chance to say much. It's a bit like the boy who cried 'wolf'. People see you doing these things, and so when you appear on an IRC channel where this is known about you get banned as a pre-emptive measure. I have discussed this matter with dash, and he has agreed not to kick you off without reason the next time you join #python. This will only last as long as your behavior remains acceptable, so please don't abuse the privilege I have won back for you. If you do, that will make me feel (and look) like a real dick, and get you banned again straight away. regards Steve > Xah > ? http://xahlee.org/ > > ? > > > On Feb 2, 2:23 pm, "Steve Holden, Chairman, PSF" > wrote: >> Xah Lee wrote: >>> This is a short complaint on admin abuse on #python irc channel on >>> freenode.net. >>> Here's a log: >>> 2010-02-02 >>> (12:11:57 PM) The topic for #python is: NO LOL |http://pound-python.org/ >>> | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: >>> http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ: >>> http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy >>> | #python.web #wsgi #python-fr #python.de #python-es #python.tw >>> #python.pl #python-br #python-jp #python-nl #python-ir #python- >>> offtopic >>> (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, >>> actually. >>> (12:12:01 PM) jarray52: Jarray >>> (12:12:11 PM) _habnabit: jarray52, yes, you are. >>> (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? >>> (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops >>> etc) right is quite tricky >>> (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just >>> wondering whats up with the python verison :D >>> (12:12:24 PM) mode (+o dash) by ChanServ >>> (12:12:30 PM) You have been kicked by dash: (No.) >>> --------------- >>> I have not been using irc for the past about 2 year. (possibly perhaps >>> 2 times in i think #web channel) In particular, i have not been in in >>> freenode.net's #python channel. I don't know who is dash. >>> Xah >>> ?http://xahlee.org/ >>> ? >> Frankly, Xah Lee, I find it ironic that you see fit to complain about >> abuse of the IRC channel when you have apparently felt free to ignore >> the many complaints about your behavior on this and other newsgroups >> over many years. >> >> "As ye sew, so shall ye reap". I imagine that your reputation has >> preceded you, and that dash (whom I *do* know) is simply looking to keep >> a well-known nuisance from bothering the rest of the users on the channel. >> >> For the present my sympathies are all with him. The PSF will, however, >> investigate this issue and I will report back to you off-list in due course. >> >> regards >> Steve >> -- >> Steve Holden Chairman, Python Software Foundation >> The Python Community Conference http://python.org/psf/ >> PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/ >> Watch PyCon on video now! http://pycon.blip.tv/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mailings at julianmoritz.de Thu Feb 4 18:03:08 2010 From: mailings at julianmoritz.de (Julian) Date: Thu, 4 Feb 2010 15:03:08 -0800 (PST) Subject: Your beloved python features Message-ID: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Hello, I've asked this question at stackoverflow a few weeks ago, and to make it clear: this should NOT be a copy of the stackoverflow-thread "hidden features of Python". I want to design a poster for an open source conference, the local usergroup will have a table there, and in the past years there were some people that came to the python-table just to ask "why should I use python?". For those guys would be a poster quite cool which describes the most popular and beloved python features. So, may you help me please? If there's a similar thread/blogpost/ whatever, please give it to me, google couldn't. Regards Julian From rfritz333 at gmail.com Thu Feb 4 18:10:55 2010 From: rfritz333 at gmail.com (R Fritz) Date: Thu, 4 Feb 2010 15:10:55 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: My favorite feature is its readability. It's as near to pseudo-code as any language we have, and that's valuable in open source projects or when I return to code to modify it. From alfps at start.no Thu Feb 4 18:13:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Feb 2010 00:13:50 +0100 Subject: Stephen -- Bruce? Message-ID: What's this about all the Stephen'ses here? Shouldn't it be Bruce? - Alf (wondering) From no.email at nospam.invalid Thu Feb 4 18:20:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 15:20:01 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <7xk4usa8ri.fsf@ruckus.brouhaha.com> Julian writes: > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". It's terrible, but all the alternatives are even worse. ;-) From steve at holdenweb.com Thu Feb 4 18:29:14 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 18:29:14 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: <00f4d6df$0$15566$c3e8da3@news.astraweb.com> References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: > >> Terry Reedy wrote: >>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>> working fine. My "Duh?" question is about how to run it from within >>>> IDLE and pass it command line arguments. No problem using sys.argv >>>> from a Windows command line, but I have missed how you can do that >>>> from within IDLE, which complicates development and debugging. >>> I presume you mean edit, F5-run, see result in shell window. Set >>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>> >>>>>> import sys >>>>>> sys.argv >>> [''] >>>>>> sys.argv = ['abc','dev'] >>>>>> sys.argv >>> ['abc', 'dev'] >>> >>> I did not know it was writable, either, until I tried it. >>> >> As a solution, however, that sucks, wouldn't you agree? > > [scratches head] > > Do you mean setting sys.argv as a solution sucks? No, I don't, I think it > is grand. If sys.argv was unmodifiable, *that* would suck. > > Or do you mean that trying it as a solution to the problem of answering > the OP's question sucks? Well, no, experimentation is good for answering > these sorts of questions, and I can't assume that the documentation will > cover every imaginable use-case, or that users will find it. In the > absence of any documentation stating otherwise, I would have assumed that > sys.argv was an ordinary list which you can modify at will, but having > been caught out on faulty assumptions before, I would try it and see > before commenting publicly. > > What I meant was it sucks that IDLE has no way to fill in sys.argv as a part of its "Run Module" functionality - something that is present in both PythonWin and Wing IDE, for example. But then I have come to the conclusion that IDLE doesn't fit my brain, or my brain doesn't fit it. That sys.argv is mutable simply reflects the fact that it's a list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mensanator at aol.com Thu Feb 4 18:36:04 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Feb 2010 15:36:04 -0800 (PST) Subject: Stephen -- Bruce? References: Message-ID: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> On Feb 4, 5:13?pm, "Alf P. Steinbach" wrote: > What's this about all the Stephen'ses here? > > Shouldn't it be Bruce? Of course. We just call everyone Stephen to avoid confusion. > > - Alf (wondering) From john at castleamber.com Thu Feb 4 18:40:41 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 17:40:41 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> Message-ID: <87r5p07eo6.fsf@castleamber.com> Steven D'Aprano writes: > On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: > >> Terry Reedy wrote: >>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>> working fine. My "Duh?" question is about how to run it from within >>>> IDLE and pass it command line arguments. No problem using sys.argv >>>> from a Windows command line, but I have missed how you can do that >>>> from within IDLE, which complicates development and debugging. >>> >>> I presume you mean edit, F5-run, see result in shell window. Set >>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>> >>>>>> import sys >>>>>> sys.argv >>> [''] >>>>>> sys.argv = ['abc','dev'] >>>>>> sys.argv >>> ['abc', 'dev'] >>> >>> I did not know it was writable, either, until I tried it. >>> >> As a solution, however, that sucks, wouldn't you agree? > > [scratches head] > > Do you mean setting sys.argv as a solution sucks? No, I don't, I think it > is grand. If sys.argv was unmodifiable, *that* would suck. > > Or do you mean that trying it as a solution to the problem of answering > the OP's question sucks? Well, no, experimentation is good for answering > these sorts of questions, and I can't assume that the documentation will > cover every imaginable use-case, or that users will find it. In the > absence of any documentation stating otherwise, I would have assumed that > sys.argv was an ordinary list which you can modify at will, but having > been caught out on faulty assumptions before, I would try it and see > before commenting publicly. I guess that Terry means that a solution that makes it possible to specify in IDLE *outside* of the Python code the arguments would be better. Hardcoding the command line arguments isn't something I would do for testing. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Thu Feb 4 18:46:52 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 17:46:52 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> Message-ID: <87mxzo7edv.fsf@castleamber.com> John Bokma writes: > Steven D'Aprano writes: > >> On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: >> >>> Terry Reedy wrote: >>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>> working fine. My "Duh?" question is about how to run it from within >>>>> IDLE and pass it command line arguments. No problem using sys.argv >>>>> from a Windows command line, but I have missed how you can do that >>>>> from within IDLE, which complicates development and debugging. >>>> >>>> I presume you mean edit, F5-run, see result in shell window. Set >>>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>>> >>>>>>> import sys >>>>>>> sys.argv >>>> [''] >>>>>>> sys.argv = ['abc','dev'] >>>>>>> sys.argv >>>> ['abc', 'dev'] >>>> >>>> I did not know it was writable, either, until I tried it. >>>> >>> As a solution, however, that sucks, wouldn't you agree? >> >> [scratches head] >> >> Do you mean setting sys.argv as a solution sucks? No, I don't, I think it >> is grand. If sys.argv was unmodifiable, *that* would suck. >> >> Or do you mean that trying it as a solution to the problem of answering >> the OP's question sucks? Well, no, experimentation is good for answering >> these sorts of questions, and I can't assume that the documentation will >> cover every imaginable use-case, or that users will find it. In the >> absence of any documentation stating otherwise, I would have assumed that >> sys.argv was an ordinary list which you can modify at will, but having >> been caught out on faulty assumptions before, I would try it and see >> before commenting publicly. > > I guess that Terry means that a solution that makes it possible to > specify in IDLE *outside* of the Python code the arguments would be > better. Hardcoding the command line arguments isn't something I would do > for testing. Oops, that should've been Steve, my apologies. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From ethan at stoneleaf.us Thu Feb 4 18:46:58 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Feb 2010 15:46:58 -0800 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <4B6B5C72.8080100@stoneleaf.us> Robert Kern wrote: > On 2010-02-04 14:55 PM, Jonathan Gardner wrote: >> On Feb 3, 3:39 pm, Steve Holden wrote: >>> Robert Kern wrote: >>>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >>> >>>>> I can explain all of Python in an hour; I doubt anyone will understand >>>>> all of Python in an hour. >>> >>>> With all respect, talking about a subject without a reasonable >>>> chance of >>>> your audience understanding the subject afterwards is not explaining. >>>> It's just exposition. >>> >>> I agree. If the audience doesn't understand then you haven't >>> explained it. >> >> On the contrary, that explanation would have everything you need. It >> would take an hour to read or listen to the explanation, but much more >> than that time to truly understand everything that was said. > > Like I said, that's exposition, not explanation. There is an important > distinction between the two words. Simply providing information is not > explanation. If it takes four hours for your audience to understand it, > then you explained it in four hours no matter when you stopped talking. > And if it takes six months? Would you seriously say it took you six months to explain something because it took that long for your audience to understand it? At some point you have to make the transition from person A explaining and person(s) B understanding -- they don't necessarily happen synchronously. As a real-life example, I've read several Python books, tutorials, and this list for quite some time, some of which has very good explanatory material, and yet some of the points I didn't fully comprehend until much, much later. Every time, though, it's still the same reaction: I *love* Python! :D ~Ethan~ From ethan at stoneleaf.us Thu Feb 4 18:55:30 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Feb 2010 15:55:30 -0800 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4B6B5E72.20702@stoneleaf.us> Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. > > Regards > Julian http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf From gagsl-py2 at yahoo.com.ar Thu Feb 4 19:03:20 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 21:03:20 -0300 Subject: Python 3 minor irritation References: Message-ID: En Thu, 04 Feb 2010 17:50:29 -0300, Gib Bogle escribi?: > Gabriel Genellina wrote: >> Also, from the command line, execute: >> D:\temp>reg query HKCR\.py >> ! REG.EXE VERSION 3.0 >> HKEY_CLASSES_ROOT\.py >> REG_SZ Python.File >> Content Type REG_SZ text/plain >> HKEY_CLASSES_ROOT\.py\PersistentHandler > > I'm interested in this, because I'm using Windows XP, and when I execute > this command I see the first part but not the second (with > PersistentHandler). Sorry, I should have removed that line. This is just my setup; a normal Python install doesn't create that registry entry. It allows Desktop Search (or Windows Search, or whatever it is called nowadays; the F3 key) to search inside .py files (default behavior is to just ignore their contents). See http://support.microsoft.com/kb/309173 > Is this related to the fact that when I double-click on a .py file the > command window disappears after the execution is completed? (I bet the "Persistent" word confused you.) No, as you can see, it's completely unrelated. AFAIK, there is no way (on XP and later at least) to keep a console window open after the program exited. Three choices: - Open a cmd window and execute the script there. You may drag&drop the file over the window to avoid typing the full path (I think this last part does not work on Vista nor Win7) - Add a raw_input() [2.x] or input() [3.x] line at the end of the script - Rename it with a '.cmd' extension and add this line at the very top: @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF (see this post by Duncan Booth last month: http://comments.gmane.org/gmane.comp.python.general/650913 ) -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Thu Feb 4 19:09:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 00:09:24 GMT Subject: Code snippet: dualmethod descriptor References: <0373b8b9$0$1309$c3e8da3@news.astraweb.com> Message-ID: <00f4e6e5$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 00:09:02 -0300, Gabriel Genellina wrote: > En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano > escribi?: > >> class dualmethod(object): [...] > Seems useful! > Perhaps a better place to post it would be > , at least it's > easier to search. Thank you for the encouragement. The recipe is now posted: http://code.activestate.com/recipes/577030/ -- Steven From gagsl-py2 at yahoo.com.ar Thu Feb 4 19:09:28 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 21:09:28 -0300 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma escribi?: > John Bokma writes: >>>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>>> working fine. My "Duh?" question is about how to run it from within >>>>>> IDLE and pass it command line arguments. >> I guess that Terry means that a solution that makes it possible to >> specify in IDLE *outside* of the Python code the arguments would be >> better. Hardcoding the command line arguments isn't something I would do >> for testing. > > Oops, that should've been Steve, my apologies. See http://bugs.python.org/issue5680 -- Gabriel Genellina From tjreedy at udel.edu Thu Feb 4 19:10:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 19:10:52 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> Message-ID: On 2/4/2010 6:29 PM, Steve Holden wrote: > Steven D'Aprano wrote: >> On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: >> >>> Terry Reedy wrote: >>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>> working fine. My "Duh?" question is about how to run it from within >>>>> IDLE and pass it command line arguments. No problem using sys.argv >>>>> from a Windows command line, but I have missed how you can do that >>>>> from within IDLE, which complicates development and debugging. >>>> I presume you mean edit, F5-run, see result in shell window. Set >>>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>>> >>>>>>> import sys >>>>>>> sys.argv >>>> [''] >>>>>>> sys.argv = ['abc','dev'] >>>>>>> sys.argv >>>> ['abc', 'dev'] >>>> >>>> I did not know it was writable, either, until I tried it. >>>> >>> As a solution, however, that sucks, wouldn't you agree? No, see below. >> [scratches head] >> >> Do you mean setting sys.argv as a solution sucks? No, I don't, I think it >> is grand. If sys.argv was unmodifiable, *that* would suck. >> >> Or do you mean that trying it as a solution to the problem of answering >> the OP's question sucks? Well, no, experimentation is good for answering >> these sorts of questions, and I can't assume that the documentation will >> cover every imaginable use-case, or that users will find it. In the >> absence of any documentation stating otherwise, I would have assumed that >> sys.argv was an ordinary list which you can modify at will, but having >> been caught out on faulty assumptions before, I would try it and see >> before commenting publicly. >> >> > What I meant was it sucks that IDLE has no way to fill in sys.argv as a > part of its "Run Module" functionality - something that is present in > both PythonWin and Wing IDE, for example. The first thing I did was to check for such an option on the run tab. The second thing I thought of was to suggest to OP that he file a feature request (which would likely take years, if ever). But then the test line would not be fetched from the file (unless some ##cmdline convention were invented), but would have to be hand-entered each time the editor were run. Also, a given run of a program can have only one command line, and changing the run line for each test case would suck. Then I tried sys.argv. Why that does not suck: A Python program, as far as I know, cannot process a command lines directly, but only processed command line args in the form of a list of strings -- sys.argv. Therefore, the need for testing is not to simulate a command line but to set sys.argv. I assume the programmer knows the mapping from command line to argv since he otherwise cannot sensibly proceed. I believe it is sensible, if not recommended, to put an arg processing in a defined function that returns, for instance, a dict, rather than to do it at top-level in the main script. So in use, process_args() will be called in a context with sys.argv set. So let it be tested. For instance, something like: def _test_arg_processing: arg_dict_pairs - ( (['arg1', 'arg2'], {'speed':int('arg1'), 'range':float('arg2'}), (['-v'], {'verbose': True}, ) for args,dic in arg_dict_pairs: sys.argv = args assert process_args() == dic Repeatable automatic testing of multiple test cases. I just starting doing this a year ago and love it. Terry Jan Reedy From tjreedy at udel.edu Thu Feb 4 19:12:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 19:12:27 -0500 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: Iterators, and in particular, generators. A killer feature. Terry Jan Reedy From aahz at pythoncraft.com Thu Feb 4 19:18:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Feb 2010 16:18:04 -0800 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On 3 Feb 2010 08:38:47 -0800, aahz at pythoncraft.com (Aahz) declaimed the >following in gmane.comp.python.general: >> In article , >> Dennis Lee Bieber wrote: >>> >>> I shall blaspheme, and suggest that maybe the language you want to >>>use is REXX (ooREXX or Regina). >>> >>> By default, ANY statement that can not be confused for a REXX >>>language statement is sent to the currently defined command handler >>>(Which on most OSs is equivalent to Python's os.system() call; the late >>>Amiga, and IBM's mainframe OS had features that support defining other >>>applications as command handlers). >> >> How is that different from bash scripting? > > Uhm... Does a bash script support inlining statements from some >other language? > > Python's shutil library essentially disappears in REXX as one can >plug in the native command line statement for those functions. But in bash scripting, you'd just use rsync or cp or rm -- maybe an example would make clearer how REXX differs from bash. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at holdenweb.com Thu Feb 4 19:20:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 19:20:38 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: Gabriel Genellina wrote: > En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma > escribi?: >> John Bokma writes: > >>>>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>>>> working fine. My "Duh?" question is about how to run it from within >>>>>>> IDLE and pass it command line arguments. > >>> I guess that Terry means that a solution that makes it possible to >>> specify in IDLE *outside* of the Python code the arguments would be >>> better. Hardcoding the command line arguments isn't something I would do >>> for testing. >> >> Oops, that should've been Steve, my apologies. > > See http://bugs.python.org/issue5680 > So we've had a patch since April and it still didn't make it into 3.1? That's disappointing. I wonder if there's any chance it'll get into 2.7. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From g.bogle at auckland.no.spam.ac.nz Thu Feb 4 19:21:07 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Fri, 05 Feb 2010 13:21:07 +1300 Subject: Python 3 minor irritation References: Message-ID: Gabriel Genellina wrote: > Sorry, I should have removed that line. This is just my setup; a normal > Python install doesn't create that registry entry. It allows Desktop > Search (or Windows Search, or whatever it is called nowadays; the F3 > key) to search inside .py files (default behavior is to just ignore > their contents). > See http://support.microsoft.com/kb/309173 > >> Is this related to the fact that when I double-click on a .py file the >> command window disappears after the execution is completed? > > (I bet the "Persistent" word confused you.) No, as you can see, it's > completely unrelated. AFAIK, there is no way (on XP and later at least) > to keep a console window open after the program exited. Three choices: > > - Open a cmd window and execute the script there. You may drag&drop the > file over the window to avoid typing the full path (I think this last > part does not work on Vista nor Win7) > > - Add a raw_input() [2.x] or input() [3.x] line at the end of the script > > - Rename it with a '.cmd' extension and add this line at the very top: > > @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF > > (see this post by Duncan Booth last month: > http://comments.gmane.org/gmane.comp.python.general/650913 ) > Thanks Gabriel. I didn't know about the drag&drop capability (learn something every day, forget two things). BTW input() works for me in 2.5. Cheers Gib From gagsl-py2 at yahoo.com.ar Thu Feb 4 20:13:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 22:13:36 -0300 Subject: xmlrpc slow in windows 7 if hostnames are used References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Message-ID: En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: > I wrote a small xmlrpc client on Windows 7 with python 2.6 > > srv = xmlrpclib.Server('http://localhost:80') > > I was able to perform about 1 rpc call per second > > > After changing to > srv = xmlrpclib.Server('http://127.0.0.1:80') > > I was able to perform about 10 to 16 rpc calls per second. > > So it seems, that under windows 7 the host name lookup occurs for every > RPC call Not necesarily. There is another difference: 127.0.0.1 is an IPv4 address, localhost maps to both IPv4 and IPv6 addresses (::1) I vaguely remember a problem with that - IPv6 is tried first, doesn't work, only then IPv4, and that slows down the whole process. Try disabling completely the IPv6 stack, if you don't need it. -- Gabriel Genellina From stephen.thorne at gmail.com Thu Feb 4 20:13:40 2010 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Thu, 4 Feb 2010 17:13:40 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <7030037b-cd1e-4621-ab74-4f819ef5f4eb@k6g2000prg.googlegroups.com> On Feb 5, 8:26?am, Xah Lee wrote: > I appreciate that you taking this more seriously than normal > newsgroups postings. In fact, for this complaint, the response you > made is all i asked for. > > I am taking this as seriously as all the articles you have posted to usenet. Stephen. From python.list at tim.thechases.com Thu Feb 4 20:36:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Feb 2010 19:36:19 -0600 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: <4B6B7613.3000903@tim.thechases.com> Gabriel Genellina wrote: > En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma >> Oops, that should've been Steve, my apologies. > > See http://bugs.python.org/issue5680 Am I the only one that expected that issue to be about too many Steves (and perhaps too many Tims) on c.l.p? :-) -tkc From bcb at undisclosedlocation.net Thu Feb 4 20:45:48 2010 From: bcb at undisclosedlocation.net (Bruce C. Baker) Date: Thu, 4 Feb 2010 19:45:48 -0600 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: "Terry Reedy" wrote in message news:mailman.1929.1265328905.28905.python-list at python.org... > Iterators, and in particular, generators. > A killer feature. > > Terry Jan Reedy > Neither unique to Python. And then're the other killer "features" superfluous ":"s and rigid formatting! From jonny.lowe.12345 at gmail.com Thu Feb 4 20:56:50 2010 From: jonny.lowe.12345 at gmail.com (jonny lowe) Date: Thu, 4 Feb 2010 17:56:50 -0800 (PST) Subject: merge stdin, stdout? Message-ID: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> Hi everyone, Is there an easy way to merge stdin and stdout? For instance suppose I have script that prompts for a number and prints the number. If you execute this with redirection from a file say input.txt with 42 in the file, then executing ./myscript < input.txt > output.txt the output.txt might look like this: Enter a number: You entered 42. What I want is to have an easy way to merge input.txt and the stdout so that output.txt look like: Enter a number: 42 You entered 42. Here, the first 42 is of course from input.txt. Thanks. -jon From stephen.thorne at gmail.com Thu Feb 4 20:58:36 2010 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Thu, 4 Feb 2010 17:58:36 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: On Feb 5, 9:02?am, Steve Holden wrote: > > ? The list of ban'd person's names, the reason for banning, and the > > name of admin who ban'd them, should be public. (irc already provides > > means for this that allows admins to annotate in the ban list.) In > > particular, if you are going to ban someone by ip address, make sure > > the person's handle (or preferably real life name), be listed together > > with it. (again, this needs not elaborate. A single sentence will do, > > e.g. ?repeatedly asking same question?, ?continously raising > > controversial issues?, ?refused to use paste bin when requested? will > > do. Again, be as precise in description as possible. For example, > > ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) > > This is perhaps a little formal for something that (as far as I know) > happens less than once a month. I am reluctant to start up any kind of > bureaucracy around bannings unless they become too frequent (in which > case your suggestions above seem reasonable). The current banlist lists 258 names. According to my logs there have been 95 masks added to this list and 44 removals since October. This is approximately 23 a month, or 3 every 4 days. 11 ops were active in this action during this period. For reference, this is the 4th largest IRC channel on freenode according to http://searchirc.com/search.php?SCHANS=1&SSORT=SIZE&N=freenode and the other large channels weigh in with 298 (gentoo), 9 (archlinux), 14 (##C++), 280 (#ubuntu), 109 (#debian). We are hardly exceptional in the size of our list of people we have excluded from the IRC community. On discussion with #archlinux it seems that the reason archlinux has so few on their list is because they use chanserv's AKICK feature, which means the name isn't kept in the IRC client accessable banlist, and is only put there temporarily when the excluded user returns by chanserv. Stephen. From wolftracks at invalid.com Thu Feb 4 21:01:08 2010 From: wolftracks at invalid.com (W. eWatson) Date: Thu, 04 Feb 2010 18:01:08 -0800 Subject: Exiting a Program Running in Idle, Various Choices Message-ID: I I have a very simple program running in Python, with say the last line print "bye". it finishes leaving the script showing >>> in the shell window. The program proceeds linearly to the bottom line. Suppose now I have instead a few lines of MatPlotLib code (MPL) like this at the end: ... Show() Show displays some graph and again the code proceeds linearly from line 1. However, if one closes the graphic by clicking the x in the upper right corner of that window, then no >>> appears in the shell, and one must kill the shell using the x in the shell's upper right corner. A little dialog with the choices of OK (kill) or cancel appears. Use OK and the shell window disappears. A ctrl-c does nothing in the shell. I know about sys.exit(),and a "finish" def when using Tkinter. I'm not using Tkinter as far as I know via MPL. So how does one exit smoothly in this case of Show(), so that the shell window remains ready to entry commands? From steve at holdenweb.com Thu Feb 4 21:09:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 21:09:47 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B6B7DEB.5020101@holdenweb.com> Stephen Thorne wrote: > On Feb 5, 9:02 am, Steve Holden wrote: >>> ? The list of ban'd person's names, the reason for banning, and the >>> name of admin who ban'd them, should be public. (irc already provides >>> means for this that allows admins to annotate in the ban list.) In >>> particular, if you are going to ban someone by ip address, make sure >>> the person's handle (or preferably real life name), be listed together >>> with it. (again, this needs not elaborate. A single sentence will do, >>> e.g. ?repeatedly asking same question?, ?continously raising >>> controversial issues?, ?refused to use paste bin when requested? will >>> do. Again, be as precise in description as possible. For example, >>> ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) >> This is perhaps a little formal for something that (as far as I know) >> happens less than once a month. I am reluctant to start up any kind of >> bureaucracy around bannings unless they become too frequent (in which >> case your suggestions above seem reasonable). > > The current banlist lists 258 names. According to my logs there have > been 95 masks added to this list and 44 removals since October. This > is approximately 23 a month, or 3 every 4 days. 11 ops were active in > this action during this period. > > For reference, this is the 4th largest IRC channel on freenode > according to http://searchirc.com/search.php?SCHANS=1&SSORT=SIZE&N=freenode > and the other large channels weigh in with 298 (gentoo), 9 > (archlinux), 14 (##C++), 280 (#ubuntu), 109 (#debian). > > We are hardly exceptional in the size of our list of people we have > excluded from the IRC community. > > On discussion with #archlinux it seems that the reason archlinux has > so few on their list is because they use chanserv's AKICK feature, > which means the name isn't kept in the IRC client accessable banlist, > and is only put there temporarily when the excluded user returns by > chanserv. > Thanks, Stephen. It's fairly obvious I am not an active IRC user, isn't it? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From hidura at gmail.com Thu Feb 4 21:10:45 2010 From: hidura at gmail.com (Hidura) Date: Thu, 4 Feb 2010 22:10:45 -0400 Subject: Problem with __init__.py in Python3.1 In-Reply-To: <871vh0mxdy.fsf@benfinney.id.au> References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> <871vh0mxdy.fsf@benfinney.id.au> Message-ID: <4bbf7fb21002041810xc9bf899v1827ff83abb67c44@mail.gmail.com> Thanks i middle resolve the problem, and i going to read the PEP-366 i've been read the 328, i will kept informed of the progresses. Thanks again for the help [?] On Thu, Feb 4, 2010 at 6:47 PM, Ben Finney > wrote: > "Gabriel Genellina" writes: > > > If you directly run a script from inside a package, Python does not > > know that it belongs to a package, and treats it as a simple, lonely > > script. In that case, relative imports won't work. > > Which I consider to be a bug. Fortunately, it's already addressed in PEP > 366 . Unfortunately, it > involves more hackish boilerplate at the top of the program, and is only > available in Python 2.6+. > > -- > \ ?Ignorance more frequently begets confidence than does | > `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 330.png Type: image/png Size: 611 bytes Desc: not available URL: From exarkun at twistedmatrix.com Thu Feb 4 21:20:22 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 05 Feb 2010 02:20:22 -0000 Subject: merge stdin, stdout? In-Reply-To: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> Message-ID: <20100205022022.26099.2092860927.divmod.xquotient.476@localhost.localdomain> On 01:56 am, jonny.lowe.12345 at gmail.com wrote: >Hi everyone, > >Is there an easy way to merge stdin and stdout? For instance suppose I >have script that prompts for a number and prints the number. If you >execute this with redirection from a file say input.txt with 42 in the >file, then executing > >./myscript < input.txt > output.txt > >the output.txt might look like this: > >Enter a number: >You entered 42. > >What I want is to have an easy way to merge input.txt and the stdout >so that output.txt look like: > >Enter a number: 42 >You entered 42. > >Here, the first 42 is of course from input.txt. It sounds like you might be looking for script(1)? Jean-Paul From half.italian at gmail.com Thu Feb 4 21:26:06 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Thu, 4 Feb 2010 18:26:06 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <1445b521-d9d9-4200-9a01-f146e1543d40@t17g2000prg.googlegroups.com> On Feb 4, 3:03?pm, Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. > > Regards > Julian I love list comprehensions, but am currently falling for 'with'. ~Sean From half.italian at gmail.com Thu Feb 4 22:10:31 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Thu, 4 Feb 2010 19:10:31 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: On Feb 3, 6:08?pm, alex23 wrote: > On Feb 4, 8:47?am, Phlip wrote: > > > Yes, calling os.path.walk() and os.path.join() all the time on raw > > strings is fun, but I seem to recall from my Ruby days a class called > > Pathname, which presented an object that behaved like a string at > > need, and like a filesystem path at need. path + 'folder' would > > call .join() and insert the / correctly, for example. > > > What's the best equivalent in Python-land? > > It's no longer supported, but the 3rd party 'path' module used to be > the go-to module for this: > > >>> from path import path > > C:\Python26\lib\site-packages\path.py:32: DeprecationWarning: the md5 > module is deprecated; use hashlib instead > ? import sys, warnings, os, fnmatch, glob, shutil, codecs, md5>>> c = path('C:\\') > >>> c.listdir() > > [path(u'C:\\AUTOEXEC.BAT'), path(u'C:\\boot.ini'), ...]>>> (c + 'python26').listdir() > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > \python26\\DLLs'), ...]>>> (c / 'python26').listdir() > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > \python26\\DLLs'), ...] > > I've hand edited the results for brevity... > > The module could do with some TLC to bring it up to date, but warning > aside it still seems to work fine under 2.6. > > (From memory, I think the original author gave up when it became clear > it would never be integrated into the standard lib[1], which is a > shame, I think there's scope for a pathtools addition to the lib that > provides this level of convenience...) > > There was also a PEP with another possible implementation:http://www.python.org/dev/peps/pep-0355/ > > Hope this helps. It's too bad that something like this can't be agreed to. I used a homegrown module like this for a couple of years in my early days with python. It was great, but I didn't know enough at the time to make it really useful. Why did Path() get rejected? Is it the idea itself, or just the approach that was used? What are the complaints? ~Sean From aharrisreid at googlemail.com Thu Feb 4 22:29:40 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Fri, 05 Feb 2010 03:29:40 +0000 Subject: Passing parameters in URL In-Reply-To: <7svgogF768U1@mid.uni-berlin.de> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> <7svgogF768U1@mid.uni-berlin.de> Message-ID: <4B6B90A4.6060708@googlemail.com> Many thanks to all those who replied to my question and clearing-up the differences between GET and POST. I think I know what to do now - if not, I'll be back :-) Regards, Alan From sridharr at activestate.com Fri Feb 5 00:01:27 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 4 Feb 2010 21:01:27 -0800 Subject: ANN: ActivePython 2.6.4.10 is now available Message-ID: I'm happy to announce that ActivePython 2.6.4.10 is now available for download from: http://www.activestate.com/activepython/ This is a minor release with several updates and fixes. Changes in 2.6.4.10 ------------------- - PyPM is now included in 64-bit Windows and Linux builds - Include Distribute instead of setuptools - Include pip - Upgrade to Tcl/Tk 8.5.8 - [Windows] Upgrade to Pywin32 CVS (2009-11-10) - [Windows] Support for OpenSSL in 64-bit - [Windows] Include Tcl/Tk header files - [Windows] Fix broken IDLE on the 64-bit build 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. Builds for Solaris, HP-UX and AIX, and access to older versions are available with ActivePython Business Edition: http://www.activestate.com/business_edition/ 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. Beginning with the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: pypm install pylons 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/query.cgi?set_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 Edition only) - Solaris/x86 (Business Edition only) - HP-UX/PA-RISC (Business Edition only) - AIX/PowerPC (Business Edition only) - AIX/PowerPC 64-bit (Business Edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/activepython/enterprise/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 00:20:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 05:20:58 GMT Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: <00f52feb$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 19:36:19 -0600, Tim Chase wrote: > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma >>> Oops, that should've been Steve, my apologies. >> >> See http://bugs.python.org/issue5680 > > > Am I the only one that expected that issue to be about too many Steves > (and perhaps too many Tims) on c.l.p? :-) That was exactly my thought too. One of the multiple Steves'ly yrs, -- Steve From john at castleamber.com Fri Feb 5 00:50:20 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 23:50:20 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: <871vh0z0wz.fsf@castleamber.com> Tim Chase writes: > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma >> >>> Oops, that should've been Steve, my apologies. >> >> See http://bugs.python.org/issue5680 > > Am I the only one that expected that issue to be about too many Steves > (and perhaps too many Tims) on c.l.p? :-) Ha ha ha, yeah something like that, wasn't expecting what was actually on that page. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From nagle at animats.com Fri Feb 5 01:18:37 2010 From: nagle at animats.com (John Nagle) Date: Thu, 04 Feb 2010 22:18:37 -0800 Subject: Common area of circles In-Reply-To: References: Message-ID: <4b6bb461$0$1654$742ec2ed@news.sonic.net> Chris Rebert wrote: > On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand wrote: >> Given 'n' circles and the co-ordinates of their center, and the radius of >> all being equal i.e. 'one', How can I take out the intersection of their >> area. > > How is this at all specific to Python? > > This also sounds suspiciously like homework, which you should know > this list is unlikely to give direct answers to, though you might be > able to get a few pointers or some general suggestions. Good point. This is actually a problem in what's called "constructive geometry". Usually, this is a 3D problem, for which the term "constructive solid geometry", or CSG, is used. That's where to look for algorithms. Yes, there are efficient algorithms and near-exact solutions. The basic idea is that you find all the points at which circles intersect, sort those by one coordinate, and advance across that coordinate, from one value of interest to the next. Between any two values of interest you're dealing with areas bounded by arcs and lines, so the areas can be calculated analytically. It's a lot like a rasterized polygon fill algorithm. (I used to do stuff like this back when I did physics engines with efficient 3D collision detection.) John Nagle From arnodel at googlemail.com Fri Feb 5 02:12:05 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 4 Feb 2010 23:12:05 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On 4 Feb, 23:03, Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. > > Regards > Julian * simplicity * documentation - some criticise it, I love it. * duck typing * batteries included And lots more! -- Arnaud From no.email at nospam.invalid Fri Feb 5 02:19:46 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 23:19:46 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <7xr5p0kv3h.fsf@ruckus.brouhaha.com> Julian writes: > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". - Very easy to learn, at least for the not-too-hairy fragment - some features like generators are advanced compared with some other languages, yet still easy to use - pleasant-to-use syntax (yes, the indentation stuff that everyone is freaked out by at first) and well-evolved library makes coding very productive and enjoyable - reasonably good documentation - large and friendly user/developer community From george.sakkis at gmail.com Fri Feb 5 02:25:59 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Thu, 4 Feb 2010 23:25:59 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On Feb 5, 2:45?am, "Bruce C. Baker" wrote: > "Terry Reedy" wrote in message > > news:mailman.1929.1265328905.28905.python-list at python.org... > > > Iterators, and in particular, generators. > > A killer feature. > > > Terry Jan Reedy +1, iterators/generators is among Python's best features for me too. > Neither unique to Python. Can you name a single feature that is unique to a language, Python or other ? Every idea that's any good has been copied over, usually more than once. > And then're the other killer "features" superfluous ":"s and rigid > formatting! I'll give the benefit of doubt and assume you're joking rather than trolling. George From contact at xavierho.com Fri Feb 5 02:29:39 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 5 Feb 2010 17:29:39 +1000 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <2d56febf1002042329p63900958v56e1e9074267d1c8@mail.gmail.com> Personally, I love the fact that I can type in 2**25 in the intepreter without crashing my machine. ;) Cheers, -Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From monaghand.david at gmail.com Fri Feb 5 02:43:55 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Fri, 05 Feb 2010 07:43:55 +0000 Subject: Python 3 minor irritation References: Message-ID: On Thu, 04 Feb 2010 00:39:01 +0000, David Monaghan wrote: >I have a small program which reads files from the directory in which it >resides. It's written in Python 3 and when run through IDLE or PythonWin >works fine. If I double-click the file, it works fine in Python 2.6, but in >3 it fails because it looks for the files to load in the Python31 folder, >not the one the script is in. > >It's not a big deal, but browsing around I haven't found why the behaviour >has been changed or any comment about it (That might be my poor search >technique, I suppose). > >The program fails at: > > try: > tutdoc = minidom.parse(".//Myfile.xml") > except IOError: > I very much appreciate all the help offered on this, but feel a bit of an idiot now as I can't reproduce the behaviour (it had happened on two separate machines). What I am still getting is a similar problem on my work computer with the program on a network hard drive. Not always - it'll run on repeated attempts, then fail for a few, then work again. When it failed I ran the script as suggested: import os print("curdir=", os.getcwd()) print("__file__=", __file__) input() and got the response: curdir= H:\ __file__= H:\FRCR\FRCR2010\Course documents\FRCR2009\Script1.py so it's 'sticking' at H: For interest, I ran the script from IDLE, too, and PythonWin, on three separate computers (2 Python3, 1 Python2.6) With that I get a NameError for __file__ curdir= H:\FRCR\FRCR2010\Course documents\FRCR2009 Traceback (most recent call last): File "H:\FRCR\FRCR2010\Course documents\FRCR2009\Script1.py", line 3, in print("__file__=", __file__) NameError: name '__file__' is not defined What have I done wrong? DaveM From donn.ingle at gmail.com Fri Feb 5 03:01:54 2010 From: donn.ingle at gmail.com (donn) Date: Fri, 05 Feb 2010 10:01:54 +0200 Subject: pyclutter anyone? Message-ID: <4B6BD072.4080006@gmail.com> Hi, this is a little bit of a cross-post. I posted to the clutter list, but there's little activity there. I am trying to make sense of pyClutter 1.0. Could anyone point me to an example (or post one) that shows clipping from a path applied to child objects? For example: A star shape that contains a bunch of moving rectangles which will travel/size/rotate with the star, but are clipped to the shape of the star. I suspect this will involve a custom clutter.Group class of some kind, with cogl paths and an on_paint() method, but I can find no headway on the web so far. Hope someone can help! \d -- Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software From anthra.norell at bluewin.ch Fri Feb 5 03:36:33 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 05 Feb 2010 09:36:33 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start Message-ID: <4B6BD891.3060505@bluewin.ch> Hi, I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle window. This is the command I have been using: C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c execfile('C:\\Python24\\i') And this is the command that doesn't start anything: C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c execfile('C:\\Python25\\i') The command is exactly the same with the digit 5 in the place of 4. All paths and names are correct. C:\\Python25\\i sets up sys.path but seems irrelevant, as taking the execfile () part out doesn't change anything. The OS is Windows ME. The download of 2.5 finished with a warning saying that 2.5 was the highest version for Windows 9* Any tips? Thanks Frederic From anand.shashwat at gmail.com Fri Feb 5 03:49:02 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Feb 2010 14:19:02 +0530 Subject: Common area of circles In-Reply-To: <4b6bb461$0$1654$742ec2ed@news.sonic.net> References: <4b6bb461$0$1654$742ec2ed@news.sonic.net> Message-ID: Here is my approach: # input circles, remove duplicates, store them # check whether all circle intersect: if no: print '0.0' if yes: # calculate intersection points of two circles. # check if that point lies in rest all circles if yes: store it as polygon-coordinates (hull) calculate area of curve from the given two points # calculate final area : net area of curve + area of polygon Here is my final code : It's still Buggy (the logic I believe is correct, The implementation is Buggy I guess import math def catch_point(x, y): # checks for points which lie inside all the circles # stores all such point in hull kount = True for i in range(n): if (x - circle[i][0])**2 + (y - circle[i][1])**2 - 1.0 > 0: kount = False if kount == True: hull.append((x, y)) def curve_area(x0, y0, x1, y1, x2, y2): k = math.sqrt((x1 - x2)**2 + (y1 - y2)**2) area_c = math.pi * (math.degrees(math.acos(1.0 - k*k/2.0))/360) #TODO Verify area_t = 0.5 * ( x0*(y1 - y2) - x1*(y0 - y2) + x2*(y0 - y1) ) if area_t < 0: area_t = -area_t area = area_c - area_t #print area return area def polygon_area(p): # calculate area of the polygon given the co-ordinates return 0.5 * abs(sum(x0*y1 - x1*y0 for ((x0, y0), (x1, y1)) in segments(p))) def segments(p): return zip(p, p[1:] + [p[0]]) def intersect_circles(l): # check whether all circle intersects or not for i in l: for j in l: if (i[0] - j[0])**2 + (i[1] - j[1])**2 >= 4.0: sol = 0.0 return sol break return 1.0 def intersect_coordinates(l): sol = 0.0 # initialisation of final result for i in range(n): for j in range(n): # find all intersecting co-ordinates for each circle xa, xb = circle[i][0], circle[j][0] ya, yb = circle[i][1], circle[j][1] d = math.sqrt((xa - xb)**2 + (ya - yb)**2) if d == 0: continue x1 = 0.5*(xa + xb) + 0.5*(yb - ya)*math.sqrt(4 - d*d) / d y1 = 0.5*(yb + ya) - 0.5*(xb - xa)*math.sqrt(4 - d*d) / d catch_point(x1, y1) # first intersection point x2 = 0.5*(xa + xb) - 0.5*(yb - ya)*math.sqrt(4 - d*d) / d y2 = 0.5*(yb + ya) + 0.5*(xb - xa)*math.sqrt(4 - d*d) / d catch_point(x2, y2) # second intersection point sol += curve_area(circle[i][0], circle[i][1], hull[-1][0], hull[-1][1], hull[-2][0], hull[-2][1]) # add up the value of curves return sol t = int(raw_input()) # total no. of test cases for test in range(t): n = int(raw_input()) # total no. of circles circle = [] # a blank list which will contain center of circles hull = [] # a blank list which will consist of points on convex polygon for i in range(n): x,y = [float(i) for i in raw_input().split()] circle.append((x,y)) # storing the value circle = list(set(circle)) # removing duplicates n = len(circle) # calculating no. of non-duplicate circle sol = intersect_circles(circle) #intersect_circles() check whether all circle intersect if sol == 0.0: # if sol == 0.0 means all circle do not intersect print "0.000000" # solution = 0.000000 in this case elif n == 1: # if only 1 circle present, the solution is PI print "%.6f" %(math.pi) else: sol = intersect_coordinates(circle) # for rest cases we need to calculate intersection co-ordinates of circle print "%.6f" %(sol + polygon_area(hull)) # final solution sample output : 4 2 0 0 1 0 1.228370 3 0 0 0 0 0 0 3.141593 3 0 0 0 1 10 12 0.000000 3 0 0 1 0 0 1 0.192972 Either there is a redundency or there is some issue with this line : sol += curve_area(circle[i][0], circle[i][1], hull[-1][0], hull[-1][1], hull[-2][0], hull[-2][1]) Still trying to fix it. ~l0nwlf On Fri, Feb 5, 2010 at 11:48 AM, John Nagle wrote: > Chris Rebert wrote: > >> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand >> wrote: >> >>> Given 'n' circles and the co-ordinates of their center, and the radius of >>> all being equal i.e. 'one', How can I take out the intersection of their >>> area. >>> >> >> How is this at all specific to Python? >> >> This also sounds suspiciously like homework, which you should know >> this list is unlikely to give direct answers to, though you might be >> able to get a few pointers or some general suggestions. >> > > Good point. > > This is actually a problem in what's called "constructive geometry". > Usually, this is a 3D problem, for which the term "constructive solid > geometry", or CSG, is used. That's where to look for algorithms. > > Yes, there are efficient algorithms and near-exact solutions. > The basic idea is that you find all the points at which circles > intersect, sort those by one coordinate, and advance across that > coordinate, from one value of interest to the next. Between any > two values of interest you're dealing with areas bounded by arcs > and lines, so the areas can be calculated analytically. It's a > lot like a rasterized polygon fill algorithm. > > (I used to do stuff like this back when I did physics engines > with efficient 3D collision detection.) > > John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Fri Feb 5 04:01:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Feb 2010 10:01:49 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: Message-ID: * Anthra Norell: > Hi, > > I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle window. > > This is the command I have been using: > C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python24\\i') > > And this is the command that doesn't start anything: > C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python25\\i') > > The command is exactly the same with the digit 5 in the place of 4. All > paths and names are correct. C:\\Python25\\i sets up sys.path but seems > irrelevant, as taking the execfile () part out doesn't change anything. > The OS is Windows ME. The download of 2.5 finished with a warning saying > that 2.5 was the highest version for Windows 9* Any tips? Don't know, but the '-n' option, is that passed to IDLE? Perhaps try removing that. Cheers & hth., - Alf From news123 at free.fr Fri Feb 5 04:10:39 2010 From: news123 at free.fr (News123) Date: Fri, 05 Feb 2010 10:10:39 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Message-ID: <4b6be08f$0$10133$426a74cc@news.free.fr> Yhanks a lot I'll check whether this is the root cause. Currently my machine could live without IPV6 bye N Gabriel Genellina wrote: > En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: > >> I wrote a small xmlrpc client on Windows 7 with python 2.6 >> >> srv = xmlrpclib.Server('http://localhost:80') >> >> I was able to perform about 1 rpc call per second >> >> >> After changing to >> srv = xmlrpclib.Server('http://127.0.0.1:80') >> >> I was able to perform about 10 to 16 rpc calls per second. >> >> So it seems, that under windows 7 the host name lookup occurs for every >> RPC call > > Not necesarily. There is another difference: 127.0.0.1 is an IPv4 > address, localhost maps to both IPv4 and IPv6 addresses (::1) > > I vaguely remember a problem with that - IPv6 is tried first, doesn't > work, only then IPv4, and that slows down the whole process. > Try disabling completely the IPv6 stack, if you don't need it. > From jeanmichel at sequans.com Fri Feb 5 05:58:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 11:58:18 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6be08f$0$10133$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> Message-ID: <4B6BF9CA.4030702@sequans.com> News123 wrote: > Yhanks a lot I'll check whether this is the root cause. > > Currently my machine could live without IPV6 > > > bye > > N > > > Gabriel Genellina wrote: > >> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >> >> >>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>> >>> srv = xmlrpclib.Server('http://localhost:80') >>> >>> I was able to perform about 1 rpc call per second >>> >>> >>> After changing to >>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>> >>> I was able to perform about 10 to 16 rpc calls per second. >>> >>> So it seems, that under windows 7 the host name lookup occurs for every >>> RPC call >>> >> Not necesarily. There is another difference: 127.0.0.1 is an IPv4 >> address, localhost maps to both IPv4 and IPv6 addresses (::1) >> >> I vaguely remember a problem with that - IPv6 is tried first, doesn't >> work, only then IPv4, and that slows down the whole process. >> Try disabling completely the IPv6 stack, if you don't need it. >> >> Or you can simply use an explicit external address. Most of the time xmlRPC server/clients are used between distant machines. If your are using localhost for test purpose, then binding your server on its external IP instead of the local one could solve your problem (wihtout removing the IPV6 stack). import socket # server server = SimpleXMLRPCServer((socket.gethostname(), 5000), logRequests=False, allow_none=True) # client xmlrpclib.ServerProxy("http://%s.yourdomain.com:%s" % (socket.gethostname(), 5000)) JM PS : please don't top post :o) PS : just wondering if using the port 80 is legal From martin.hellwig at dcuktec.org Fri Feb 5 06:09:16 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Feb 2010 11:09:16 +0000 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On 02/04/10 23:03, Julian wrote: > For those guys would be a poster quite cool which describes the most > popular and beloved python features. That it is ego-orientated programming ;-) http://mail.python.org/pipermail/python-announce-list/2009-April/007419.html -- mph From jeanmichel at sequans.com Fri Feb 5 06:10:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 12:10:57 +0100 Subject: Your beloved python features In-Reply-To: <4B6B5E72.20702@stoneleaf.us> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: <4B6BFCC1.9070104@sequans.com> Ethan Furman wrote: > Julian wrote: >> Hello, >> >> I've asked this question at stackoverflow a few weeks ago, and to make >> it clear: this should NOT be a copy of the stackoverflow-thread >> "hidden features of Python". >> >> I want to design a poster for an open source conference, the local >> usergroup will have a table there, and in the past years there were >> some people that came to the python-table just to ask "why should I >> use python?". >> >> For those guys would be a poster quite cool which describes the most >> popular and beloved python features. >> >> So, may you help me please? If there's a similar thread/blogpost/ >> whatever, please give it to me, google couldn't. >> >> Regards >> Julian > > http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf > "Choose metaclasses if you don?t value your sanity." That remembers me the time when it took me 4 hours to write a ten lines metaclass :o) JM From lallous at lgwm.org Fri Feb 5 06:11:01 2010 From: lallous at lgwm.org (lallous) Date: Fri, 5 Feb 2010 03:11:01 -0800 (PST) Subject: Building a multiline string References: Message-ID: @Ulrich: On Feb 4, 1:09?pm, Ulrich Eckhardt wrote: > Just for the record: Neither of the below methods actually produce a > multiline string. They only spread a string containing one line over > multiple lines of source code. > I meant: "Note" -> "Note: I don't want to use new lines" I did not want a multi line string Thanks guys, method 3 seems to be good enough. From duncan.booth at invalid.invalid Fri Feb 5 06:38:15 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2010 11:38:15 GMT Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: Message-ID: Anthra Norell wrote: > Hi, > > I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle > window. > > This is the command I have been using: > C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python24\\i') > > And this is the command that doesn't start anything: > C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python25\\i') > > The command is exactly the same with the digit 5 in the place of 4. > All paths and names are correct. C:\\Python25\\i sets up sys.path but > seems irrelevant, as taking the execfile () part out doesn't change > anything. The OS is Windows ME. The download of 2.5 finished with a > warning saying that 2.5 was the highest version for Windows 9* Any > tips? > > Thanks > Does 'unable to start a 2.5 idle window' mean you get some sort of error or simply that nothing happens? What happens if you simply run C:\Python25\Lib\IDLELIB\idle.bat Does that work or not? What about running this from a command prompt: C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.py Does that run idle or do you get any error messages? What about this? C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.pyw Using pythonw.exe will start the program with all error output dumped in the bit bucket. Running from a command prompt with python.exe will at least let you see if there are any errors. -- Duncan Booth http://kupuguy.blogspot.com From fetchinson at googlemail.com Fri Feb 5 06:42:47 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 5 Feb 2010 12:42:47 +0100 Subject: Your beloved python features In-Reply-To: <4B6B5E72.20702@stoneleaf.us> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: >> I've asked this question at stackoverflow a few weeks ago, and to make >> it clear: this should NOT be a copy of the stackoverflow-thread >> "hidden features of Python". >> >> I want to design a poster for an open source conference, the local >> usergroup will have a table there, and in the past years there were >> some people that came to the python-table just to ask "why should I >> use python?". >> >> For those guys would be a poster quite cool which describes the most >> popular and beloved python features. >> >> So, may you help me please? If there's a similar thread/blogpost/ >> whatever, please give it to me, google couldn't. >> >> Regards >> Julian > > http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf This is effin hilarious! Should be either linked or stored on python.org Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ashokprabhuv at gmail.com Fri Feb 5 06:57:17 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 03:57:17 -0800 (PST) Subject: Repost: Read a running process output Message-ID: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> Hi, I very badly need this to work. I have been googling out for a week with no significant solution. I open a process p1 which does keeps running for 4+ hours. It gives some output in stdout now and then. I open this process with subprocess.Popen and redirect the stdout to PIPE. However when I read the output with readline it blocks waiting forever. I need to read from p1.stdout till what it has in the PIPE. Can someone help me out with the exact code change that can accomplish the task. from subprocess import * p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) while 1: line=p1.stdout.readline() print line Thanks in advance, ~Ashok. From alain at dpt-info.u-strasbg.fr Fri Feb 5 07:12:55 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Feb 2010 13:12:55 +0100 Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> Message-ID: <87aavnnans.fsf@dpt-info.u-strasbg.fr> Ashok Prabhu writes: > from subprocess import * > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. -- Alain. From mrkafk at gmail.com Fri Feb 5 07:13:16 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 13:13:16 +0100 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: Steve Holden wrote: >>> Jeez, Steve, you're beginning to sound like some kind of fallacy >>> zealot... ;) >> Death to all those who confuse agumentum ad populum with argumentum ad >> verecundiam!!! >> >> > Yeah, what did the zealots ever do for us? They produced Python? . . . Oh Python! Shut up! From alpeachey at gmail.com Fri Feb 5 07:16:16 2010 From: alpeachey at gmail.com (apeach) Date: Fri, 5 Feb 2010 04:16:16 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: I love intuitive type recognition. no need to 'DIM everything AS Integer' etc.! From bartc at freeuk.com Fri Feb 5 07:18:46 2010 From: bartc at freeuk.com (bartc) Date: Fri, 05 Feb 2010 12:18:46 GMT Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: "R Fritz" wrote in message news:e97ff208-d08e-4934-8e38-a40d668cd116 at l24g2000prh.googlegroups.com... > My favorite feature is its readability. It's as near to pseudo-code > as any language we have, and that's valuable in open source projects > or when I return to code to modify it. That might be true when used to code actual algorithms using basic features. But a lot of Pythonisms would appear mysterious to someone who doesn't know the language (for example, what does :: mean in an array index). Or perhaps pseudo-code is much more advanced these days... -- bartc From frank at chagford.com Fri Feb 5 07:45:30 2010 From: frank at chagford.com (Frank Millman) Date: Fri, 5 Feb 2010 14:45:30 +0200 Subject: Simple question about Queue.Queue and threads Message-ID: Hi all Assume you have a server process running, a pool of worker threads to perform tasks, and a Queue.Queue() to pass the tasks to the workers. In order to shut down the server cleanly, you want to ensure that the workers have all finished their tasks. I like the technique of putting a None onto the queue, and have each worker check for None, put None back onto the queue, and terminate itself. The main program would look something like this - q.put(None) for worker in worker_threads: worker.join() At this point you can be sure that each thread has completed its tasks and terminated itself. However, the queue is not empty - it still has the final None in it. Is it advisable to finalise the cleanup like this? - while not q.empty(): q.get() q.task_done() q.join() Or is this completely redundant? Thanks Frank Millman From ashokprabhuv at gmail.com Fri Feb 5 07:53:05 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 04:53:05 -0800 (PST) Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> Message-ID: <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> On Feb 5, 5:12?pm, Alain Ketterlin wrote: > Ashok Prabhu writes: > > from subprocess import * > > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. > > -- Alain. Hi Alain, Thanks for the response. However it throws an error. Please find below. >>> from subprocess import * >>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/subprocess.py", line 543, in __init__ errread, errwrite) File "/usr/lib/python2.4/subprocess.py", line 975, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory Thanks, ~Ashok. From alain at dpt-info.u-strasbg.fr Fri Feb 5 07:58:27 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Feb 2010 13:58:27 +0100 Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> Message-ID: <87636bn8jw.fsf@dpt-info.u-strasbg.fr> Ashok Prabhu writes: >> > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) >> >> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. >> >> -- Alain. > Thanks for the response. However it throws an error. Please find > below. > >>>> from subprocess import * >>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) You forgot to change the monolithic command into a list of words. Since you don't use the shell anymore you have to give Popen a pre-parsed command line. -- Alain. From anthra.norell at bluewin.ch Fri Feb 5 08:23:57 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 05 Feb 2010 14:23:57 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: Message-ID: <4B6C1BED.6090807@bluewin.ch> Thank you both (Alf and Duncan) for your comments. I answer Duncan's questions interleaved: Duncan Booth wrote: > Anthra Norell wrote: > > >> Hi, >> >> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >> window. >> >> This is the command I have been using: >> C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c >> execfile('C:\\Python24\\i') >> >> And this is the command that doesn't start anything: >> C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c >> execfile('C:\\Python25\\i') >> >> The command is exactly the same with the digit 5 in the place of 4. >> All paths and names are correct. C:\\Python25\\i sets up sys.path but >> seems irrelevant, as taking the execfile () part out doesn't change >> anything. The OS is Windows ME. The download of 2.5 finished with a >> warning saying that 2.5 was the highest version for Windows 9* Any >> tips? >> >> Thanks >> >> > Does 'unable to start a 2.5 idle window' mean you get some sort of error > or simply that nothing happens? > Nothing happens and no error message shows. The disk head stepper makes a brief attempt at something then goes silent and that's it. > What happens if you simply run C:\Python25\Lib\IDLELIB\idle.bat > Does that work or not? > Same thing: Nothing happens > What about running this from a command prompt: > > C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.py > Same thing: Nothing! > Does that run idle or do you get any error messages? > What about this? > > C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.pyw > > Nothing! > Using pythonw.exe will start the program with all error output dumped in > the bit bucket. Running from a command prompt with python.exe will at > least let you see if there are any errors. > python.exe from the command line works all right in a DOS window. The problem must be with idle.pyw. I tried the old idle.pyw (2.4) with the new python.exe. (2.5) and that didn't work either. What is the bit bucket? If I had a clue, I could go from there. What puzzles me is that version 2.4 has been working fine and one wouldn't think that the changes from 2.4 to 2.5 would be so extensive as to cause a major malfunction. For the time being 2.4 works fine. I'd much prefer 2.5, though, because it includes the image library (PIL), whereas 2.4 cannot even use it. Frederic From ashokprabhuv at gmail.com Fri Feb 5 08:33:00 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 05:33:00 -0800 (PST) Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> <87636bn8jw.fsf@dpt-info.u-strasbg.fr> Message-ID: <4ae7195a-d3ec-4886-9123-de88641aa797@g8g2000pri.googlegroups.com> On Feb 5, 5:58?pm, Alain Ketterlin wrote: > Ashok Prabhu writes: > >> > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > >> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. > > >> -- Alain. > > Thanks for the response. However it throws an error. Please find > > below. > > >>>> from subprocess import * > >>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) > > You forgot to change the monolithic command into a list of words. Since > you don't use the shell anymore you have to give Popen a pre-parsed > command line. > > -- Alain. Here is the error again >>> p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/subprocess.py", line 494, in __init__ raise TypeError("bufsize must be an integer") TypeError: bufsize must be an integer ~Ashok. From ashokprabhuv at gmail.com Fri Feb 5 08:39:49 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 05:39:49 -0800 (PST) Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> <87636bn8jw.fsf@dpt-info.u-strasbg.fr> <4ae7195a-d3ec-4886-9123-de88641aa797@g8g2000pri.googlegroups.com> Message-ID: On Feb 5, 6:33?pm, Ashok Prabhu wrote: > On Feb 5, 5:58?pm, Alain Ketterlin > wrote: > > > > > Ashok Prabhu writes: > > >> > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > > >> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. > > > >> -- Alain. > > > Thanks for the response. However it throws an error. Please find > > > below. > > > >>>> from subprocess import * > > >>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) > > > You forgot to change the monolithic command into a list of words. Since > > you don't use the shell anymore you have to give Popen a pre-parsed > > command line. > > > -- Alain. > > Here is the error again > > >>> p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE) > > Traceback (most recent call last): > ? File "", line 1, in ? > ? File "/usr/lib/python2.4/subprocess.py", line 494, in __init__ > ? ? raise TypeError("bufsize must be an integer") > TypeError: bufsize must be an integer > > ~Ashok. Oops i missed the braces. But still no output. >>> p1=Popen(['/usr/sunvts/bin/64/vtsk','-d'],stdout=PIPE) >>> while 1: ... a=p1.stdout.readline() ... print a ... From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 08:43:50 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 14:43:50 +0100 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4b6c2095$0$22370$426a74cc@news.free.fr> apeach a ?crit : > I love intuitive type recognition. > > no need to 'DIM everything AS Integer' etc.! > not to mention the ever hilarious (that is, when you don't have to maintain it) typical Java idiom: EveryThing theEveryThing = new EveryThing(); From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 08:45:17 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 14:45:17 +0100 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4b6c20eb$0$22370$426a74cc@news.free.fr> Julian a ?crit : > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. My all-time favorite Python feature : it fits my brain. From rdv at roalddevries.nl Fri Feb 5 08:49:53 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 5 Feb 2010 14:49:53 +0100 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <99F0D2AF-0DAD-457C-B651-0A93A31A37CE@roalddevries.nl> On Feb 5, 2010, at 12:03 AM, Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. My reasoning: I needed a language more powerful than bash, but more portable and faster to develop (at least small scripts) than C/C++. So I needed a scripting language. Python, Ruby, Perl, Tcl, ...? Python seems to be the language with the most libraries available, programs written in it, OS-support (even runs on my smartphone), has a good data-model, has a good interactive shell (iPython). From duncan.booth at invalid.invalid Fri Feb 5 08:49:53 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2010 13:49:53 GMT Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: Message-ID: Anthra Norell wrote: >> Using pythonw.exe will start the program with all error output dumped in >> the bit bucket. Running from a command prompt with python.exe will at >> least let you see if there are any errors. >> > python.exe from the command line works all right in a DOS window. The > problem must be with idle.pyw. I tried the old idle.pyw (2.4) with the > new python.exe. (2.5) and that didn't work either. > What is the bit bucket? If I had a clue, I could go from there. What > puzzles me is that version 2.4 has been working fine and one wouldn't > think that the changes from 2.4 to 2.5 would be so extensive as to cause > a major malfunction. For the time being 2.4 works fine. I'd much prefer > 2.5, though, because it includes the image library (PIL), whereas 2.4 > cannot even use it. Bit bucket: http://en.wikipedia.org/wiki/Bit_bucket If you are seeing nothing at all when running it with python.exe instead of pythonw.exe then something bizarre must be happening. My guess would have been that you had a problem importing something: e.g. if Tkinter isn't installed properly then running Idle under pythonw.exe would exit with an error message but you wouldn't see the error message. However since you don't see an error message when running it with python.exe it isn't that. Sorry, I'm out of ideas for now. -- Duncan Booth http://kupuguy.blogspot.com From mrkafk at gmail.com Fri Feb 5 09:21:05 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 15:21:05 +0100 Subject: which Message-ID: if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) else: self.cmd = cmd or self.cmd = cmd if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) From pecora at anvil.nrl.navy.mil Fri Feb 5 09:22:03 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Fri, 05 Feb 2010 09:22:03 -0500 Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> Message-ID: In article <00f4bb3a$0$15566$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 04 Feb 2010 09:57:59 -0500, Lou Pecora wrote: > > > Well, that looks a bit more complicated than I would like, but maybe > > it's doing more stuff than I can grok. Here's what I needed and how I > > did it in Python: > [...] > > # Reading same list in: > > instr=fp.readline() > > inlist=eval(instr) > > x1,y1,astr1,z1= inlist > > > > > > That's what I needed. 3 lines to write or read a inhomogeneous > > collection of variables. > > Easy, but also quick and dirty -- good enough for small scripts, but not > really good enough for production applications. > > > > I can add more variables, shuffle the order, > > whatever without messing with formatting, etc. > > This is nice and easy. But there are at least four catches: > > > * you can't safely treat the data file as human-editable > (although a sufficiently careful and Python-aware user could edit it) > > * you can't use any data that isn't a built-in, or that contains > something that is not a built-in > > * there may be reliability issues with floats - you're at the mercy of > changes to the underlying repr of float objects, and it almost certainly > will blow up in your face if you get an inf or nan (at least prior to > Python 2.6) > > * you're using eval, which is a security risk if you can't trust the > source of the data file. > > However, be aware that neither marshal nor pickle guarantees to be safe > against malicious data either. The docs for both warn against using them > on untrusted data. YAML or JSON *might* be safer, I haven't looked. I understand where you are coming from: Production Code. I was just making a point about Python and my code is only used by me. I can edit the file for the simple I/O I do. I am not recommending this way for everyone. Just an example. -- -- Lou Pecora From gdementen at gmail.com Fri Feb 5 09:25:02 2010 From: gdementen at gmail.com (Gaetan de Menten) Date: Fri, 5 Feb 2010 15:25:02 +0100 Subject: Pickling an extension type subclasses problems Message-ID: Hi all, I am trying to write an (optional!) C extension for SQLAlchemy, and I am struggling to make an extension type picklable *and* using the same format as the pure Python version (so that computers with the C extension can unpickle pickles from computers without it and vice-versa). Also the extension type (MyBase in the example code below) only serves as a base class for the type that get pickled (MyPythonType). MyPythonType also has further subclasses and those should be picklable too. My setup is as follow: On the Python side: ================ try: from cextension import MyBase except ImportError: class MyBase(object): __slots__ = ('a', 'b', 'c') def __init__(self, a, b, c): self.a, self.b, self.c = a, b, c def __getstate__(self): ... def __setstate__(self, state): ... ... class MyPythonType(MyBase): ... On the .c side: =========== I implemented a reduce method, which returns Py_BuildValue("(O(s)N)", Py_TYPE(self), "__state__", state); and in my BaseRowProxy_init method, I check the number of arguments, whether the "__state__" marker is present and unpack the state if it is. This makes the type nicely pickleable, but this is obviously not the same "pickle format" as the Python version. What would you recommend in this kind of situation? I'm a bit tired of trial and error... My last hope is to define __reduce__ on the Python side too, and make it use a module-level "reconstructor" function as follow: def mypythontype_reconstructor(cls, state): obj = object.__new__(cls, state): .... return obj Will this work? Any other idea? Thanks in advance, -- Ga?tan de Menten From killy.draw at gmail.com Fri Feb 5 09:25:05 2010 From: killy.draw at gmail.com (KDr2) Date: Fri, 5 Feb 2010 22:25:05 +0800 Subject: which In-Reply-To: References: Message-ID: <2eebcba81002050625s28b4a51dj5e67bf182601c2c4@mail.gmail.com> cmd= isinstance(cmd,str) and c.replace('${ADDR}',ip) or cmd Best Regards, -- KDr2 http://kdr2.net On Fri, Feb 5, 2010 at 10:21 PM, mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Feb 5 09:30:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 09:30:11 -0500 Subject: which In-Reply-To: References: Message-ID: mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > My own preference is for the latter, but I am sure you will find that opinions are mixed on this. In recent versions of Python you might want to take the possibility that cmd is Unicode into account by using id isinstance(cmd, basestring): regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tgrav at me.com Fri Feb 5 09:31:02 2010 From: tgrav at me.com (Tommy Grav) Date: Fri, 05 Feb 2010 09:31:02 -0500 Subject: ANN: ActivePython 2.6.4.10 is now available In-Reply-To: References: Message-ID: On Feb 5, 2010, at 12:01 AM, Sridhar Ratnakumar wrote: > I'm happy to announce that ActivePython 2.6.4.10 is now available for download from: > On what platforms does ActivePython run? > ---------------------------------------- > > ActivePython includes installers for the following platforms: > > - Windows/x86 > - Windows/x64 (aka "AMD64") > - Mac OS X Is the Mac OS X version still only 32 bit? If so does ActiveState plan to make binaries for 64bit builds for Snow Leopard? Cheers Tommy -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 5 09:41:34 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 15:41:34 +0100 Subject: which In-Reply-To: References: Message-ID: <4B6C2E1E.7000201@sequans.com> mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > I would vote for the first one. But I could use the second as well, I would'nt fight for it. What is worrying me the most in your code sample is that self.cmd can hold diferrent types (str, and something else). That is usually a bad thing to do (putting None aside). However, my remark could be totally irrelevant of course, that depends on the context. JM From jeanmichel at sequans.com Fri Feb 5 09:42:44 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 15:42:44 +0100 Subject: Your beloved python features In-Reply-To: <4b6c20eb$0$22370$426a74cc@news.free.fr> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c20eb$0$22370$426a74cc@news.free.fr> Message-ID: <4B6C2E64.2080205@sequans.com> Bruno Desthuilliers wrote: > Julian a ?crit : >> Hello, >> >> I've asked this question at stackoverflow a few weeks ago, and to make >> it clear: this should NOT be a copy of the stackoverflow-thread >> "hidden features of Python". >> >> I want to design a poster for an open source conference, the local >> usergroup will have a table there, and in the past years there were >> some people that came to the python-table just to ask "why should I >> use python?". >> >> For those guys would be a poster quite cool which describes the most >> popular and beloved python features. > > My all-time favorite Python feature : it fits my brain. Python is simple ... no offense Bruno :D JM (sorry couldn't help) From bradallen137 at gmail.com Fri Feb 5 09:57:18 2010 From: bradallen137 at gmail.com (bradallen) Date: Fri, 5 Feb 2010 06:57:18 -0800 (PST) Subject: method to intercept string formatting % operations Message-ID: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Hello, For container class derived from namedtuple, but which also behaves like a dictionary by implementing __getitem__ for non-integer index values, is there a special reserved method which allows intercepting % string formatting operations? I would like for my container type to behave appropriately depending on whether the string formatting operation has a string like this : "whatever %s yadayada" % mycontainer # needs to act like a tuple "whatever %(key)s yadayada" % mycontainer # needs to act like a dictionary I looked through the Python data model docs at but only found this: "If the left operand of a % operator is a string or Unicode object, no coercion takes place and the string formatting operation is invoked instead." Thanks! From mrkafk at gmail.com Fri Feb 5 10:15:59 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:15:59 +0100 Subject: which In-Reply-To: <4B6C2E1E.7000201@sequans.com> References: <4B6C2E1E.7000201@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > > What is worrying me the most in your code sample is that self.cmd can > hold diferrent types (str, and something else). That is usually a bad > thing to do (putting None aside). > However, my remark could be totally irrelevant of course, that depends > on the context. That's a valid criticism - but I do not know how to handle this otherwise really, because the program can be called with "cmd" to run, or a script to run (or a directory to copy) and in those cases cmd is None. I guess I could use if cmd: self.cmd = ... But. Suppose that under some circumstances cmd is not string. What then? I know that isinstance is typically not recommended, but I don't see better solution here. Regards, mk From mrkafk at gmail.com Fri Feb 5 10:21:30 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:21:30 +0100 Subject: which In-Reply-To: <2eebcba81002050625s28b4a51dj5e67bf182601c2c4@mail.gmail.com> References: <2eebcba81002050625s28b4a51dj5e67bf182601c2c4@mail.gmail.com> Message-ID: KDr2 wrote: > cmd= isinstance(cmd,str) and c.replace('${ADDR}',ip) or cmd Perlish, but I like that. :-) Regards, mk From invalid at invalid.invalid Fri Feb 5 10:24:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Feb 2010 15:24:04 +0000 (UTC) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On 2010-02-04, Julian wrote: > I've asked this question at stackoverflow a few weeks ago, and > to make it clear: this should NOT be a copy of the > stackoverflow-thread "hidden features of Python". > > I want to design a poster for an open source conference, the > local usergroup will have a table there, and in the past years > there were some people that came to the python-table just to > ask "why should I use python?". > > For those guys would be a poster quite cool which describes > the most popular and beloved python features. In the fine old tradition: Python: It sucks less. A lot less. -- Grant Edwards grante Yow! You should all JUMP at UP AND DOWN for TWO HOURS visi.com while I decide on a NEW CAREER!! From mrkafk at gmail.com Fri Feb 5 10:25:42 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:25:42 +0100 Subject: Terminating threaded programs Message-ID: Hello everyone, I have a problem with a threaded program: it frequently hangs on sys.exit. The problem is that my program uses threads which in turn use paramiko library, which itself is threaded. I try to gracefully close the threads (below), but it doesn't always work, if paramiko calls happen to be at stage of negotiating ssh connection or smth similar. The only workable solution I have is a program sending itself SIGKILL, which makes it terminated by OS (I think so). Is there any way to brutally close the threads? I know that normally that should not be done, but shutdown when you don't care about writing out to disk is the only situation where it doesn't apply. def ctrlchandler(signal, frame): print print ENDC + "Terminating on Ctrl-C, closing threads for:", while queue: for ip, th in queue: print ip, try: lock.acquire() th.abort = True lock.release() except RuntimeError: pass queue.remove((ip,th)) print pid = os.getpid() print "Finished closing threads." # suicide - it's the only way of preventing frequent hangup on sys.exit os.kill(pid, SIGTERM) os.kill(pid, SIGKILL) sys.exit(0) From jeanmichel at sequans.com Fri Feb 5 10:28:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 16:28:25 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> Message-ID: <4B6C3919.3050300@sequans.com> mk wrote: > Jean-Michel Pichavant wrote: >> >> What is worrying me the most in your code sample is that self.cmd can >> hold diferrent types (str, and something else). That is usually a bad >> thing to do (putting None aside). >> However, my remark could be totally irrelevant of course, that >> depends on the context. > > That's a valid criticism - but I do not know how to handle this > otherwise really, because the program can be called with "cmd" to run, > or a script to run (or a directory to copy) and in those cases cmd is > None. > > I guess I could use > > if cmd: > self.cmd = ... > > > But. Suppose that under some circumstances cmd is not string. What then? > > I know that isinstance is typically not recommended, but I don't see > better solution here. > > > Regards, > mk > > If you can change your program interface, then do it, if not then you're right you don't have much choice as you are suffering from the program poor interface. You can fix this problem by explicitly asking for the thing you want to do, instead of guessing by inspecting the argument nature. myProg --help usage : myProg command [args] command list: - cmd: execute the given command line - exec: execute the given script file named - copy: copy to example: >myProg cmd "echo that's cool" >myProg exec /etc/init.d/myDaemon >myProg copy /tmp /tmp2 JM From wolftracks at invalid.com Fri Feb 5 10:39:48 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 07:39:48 -0800 Subject: Drawing a zig-zag Trail in Python? Message-ID: I'd like to draw something like an animal track. Between each point is a line. Perhaps the line would have an arrow showing the direction of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? From jjposner at optimum.net Fri Feb 5 10:42:13 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 10:42:13 -0500 Subject: which In-Reply-To: References: Message-ID: <4B6C3C55.5040907@optimum.net> On 2/5/2010 9:21 AM, mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > (lunatic fringe?) Last August [1], I offered this alternative: self.cmd = (cmd.replace(r'${ADDR}',ip) if isinstance(cmd, str) else cmd) But it didn't get much love in this forum! [1] http://groups.google.com/group/comp.lang.python/browse_thread/thread/6876917a4d579d59/1f700586f4c4614d?lnk=gst&q=Posner#1f700586f4c4614d From jeanmichel at sequans.com Fri Feb 5 10:49:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 16:49:00 +0100 Subject: method to intercept string formatting % operations In-Reply-To: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Message-ID: <4B6C3DEC.9030109@sequans.com> bradallen wrote: > Hello, > > For container class derived from namedtuple, but which also behaves > like a dictionary by implementing __getitem__ for non-integer index > values, is there a special reserved method which allows intercepting % > string formatting operations? I would like for my container type to > behave appropriately depending on whether the string formatting > operation has a string like this : > > "whatever %s yadayada" % mycontainer # needs to act like a tuple > > "whatever %(key)s yadayada" % mycontainer # needs to act like a > dictionary > > I looked through the Python data model docs at reference/datamodel.html#emulating-container-types> but only found > this: > > "If the left operand of a % operator is a string or Unicode object, no > coercion takes place and the string formatting operation is invoked > instead." > > Thanks! > > class toto: def __getitem__(self, key): return 'paf' def __str__(self): return 'pif' def toTuple(self): return (1,2,3) 1/ print '%s %s %s' % toto().toTuple() '1 2 3' 2/ print '%(key)s ' % toto() 'paf' 3/ print '%s' % toto() 'pif' 1/ I don't know how to spare the explicit toTuple conversion, supporting tuple() would be tedious 2/ thanks to __getitem__ (duck typing) 3/ thanks to __str__ Anyway why would you want to use the tuple form ? it's beaten in every aspect by the dictionary form. JM "If you need something call me, I'll tell you how to live without it" (Coluche, about politicians) From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 10:49:08 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 16:49:08 +0100 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c20eb$0$22370$426a74cc@news.free.fr> Message-ID: <4b6c3df3$0$23914$426a74cc@news.free.fr> Jean-Michel Pichavant a ?crit : > Bruno Desthuilliers wrote: >> >> My all-time favorite Python feature : it fits my brain. > Python is simple ... no offense Bruno :D !-) But FWIW, that's exactly the point : even a stoopid like me can manage to learn and use Python, and proceed to write working apps without spending more time reading the doc than actually solving the problem. From __peter__ at web.de Fri Feb 5 10:49:22 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Feb 2010 16:49:22 +0100 Subject: which References: Message-ID: mk wrote: > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) Neither. self.cmd = cmd self.ip = ip ... subprocess.call(self.cmd, shell=True, env=dict(ADDR=self.ip)) Please spend a bit more energy on a descriptive subject and an unambiguous exposition of your problem (in English rather than code) next time. Peter From mrkafk at gmail.com Fri Feb 5 10:52:19 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:52:19 +0100 Subject: which In-Reply-To: <4B6C3919.3050300@sequans.com> References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > If you can change your program interface, then do it, if not then you're > right you don't have much choice as you are suffering from the program > poor interface. > You can fix this problem by explicitly asking for the thing you want to > do, instead of guessing by inspecting the argument nature. > > myProg --help > > usage : myProg command [args] > command list: > - cmd: execute the given command line > - exec: execute the given script file named > - copy: copy to > > example: > >myProg cmd "echo that's cool" > >myProg exec /etc/init.d/myDaemon > >myProg copy /tmp /tmp2 > I sure can change the interface since I'm the author of the entire program. But I don't see how I can arrange program in a different way: the program is supposed to be called with -c parameter (command to run), -s script to run, or -y file_or_dir_to_copy. Then, I start instances of SSHThread class to do precisely that, separately for each ip/hostname: class SSHThread(threading.Thread): def __init__(self, lock, cmd, ip, username, sshprivkey=None, passw=None, port=22, script=None, remotedir=None): threading.Thread.__init__(self) self.lock = lock if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) else: self.cmd = cmd self.ip = ip self.username = username self.sshprivkey = sshprivkey self.passw = passw self.port = port self.conobj = None self.conerror = '' self.msgstr = '' self.confailed = True if script: self.setpathinfo(script, remotedir=remotedir) self.sentbytes = 0 self.finished = False self.abort = False It gets called like this: th = SSHThread(lock, opts.cmd, ip, username=username, sshprivkey=opts.key, passw=passw, port=port, script=opts.script, remotedir=opts.remotedir) ..where all the options are parsed by ConfigParser.OptionParser(). So they are either strings, or Nones. So in this context this is fine. But I wanted to make the class more robust. Perhaps I should do smth like this before setting self.cmd? assert isinstance(cmd, basestring) or cmd is None, "cmd should be string or None" and then: if cmd: self.cmd = cmd.replace.. ? Entire source code is here: http://python.domeny.com/cssh.py regards, mk From dthole at gmail.com Fri Feb 5 10:53:33 2010 From: dthole at gmail.com (David Thole) Date: Fri, 05 Feb 2010 09:53:33 -0600 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: I read this....and am a tiny bit confused about the actual problem. It's not exactly complex to realize that something like: a = b = array that a and b both point to the array. Logically speaking, I'm not sure how one could assume that the same assignment would yield a and b point to the same duplicate array. If that was the case, why not do: a = array.. b = array.. I know with what you were complaining about a few days ago, .clear makes perfect sense. If a and b point to the same array, clear should clear both arrays. Again, if you didn't want that to happen, create a duplicate array. Personally I feel that this complexity doesn't hamper programming process, and yes while its good for efficiency it also just makes sense. Also, I wouldn't look at PHP on the right way to do something programming wise. I have ~5 years experience in this language, and I dislike it a whole lot. There's a lot of things it should do right that it doesn't out of convenience. -David www.thedarktrumpet.com From jeanmichel at sequans.com Fri Feb 5 10:54:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 16:54:18 +0100 Subject: which In-Reply-To: <4B6C3C55.5040907@optimum.net> References: <4B6C3C55.5040907@optimum.net> Message-ID: <4B6C3F2A.1070108@sequans.com> John Posner wrote: > On 2/5/2010 9:21 AM, mk wrote: >> >> if isinstance(cmd, str): >> self.cmd = cmd.replace(r'${ADDR}',ip) >> else: >> self.cmd = cmd >> >> or >> >> self.cmd = cmd >> if isinstance(cmd, str): >> self.cmd = cmd.replace(r'${ADDR}',ip) >> >> > > (lunatic fringe?) > > Last August [1], I offered this alternative: > > self.cmd = (cmd.replace(r'${ADDR}',ip) > if isinstance(cmd, str) else > cmd) > > But it didn't get much love in this forum! > > > [1] > http://groups.google.com/group/comp.lang.python/browse_thread/thread/6876917a4d579d59/1f700586f4c4614d?lnk=gst&q=Posner#1f700586f4c4614d > Heresy ! JM From aahz at pythoncraft.com Fri Feb 5 10:55:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2010 07:55:17 -0800 Subject: list.extend([]) Question References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> Message-ID: In article <088e7a24-b0d0-4d43-bee7-193e5eaefe57 at b7g2000pro.googlegroups.com>, Dan Brown wrote: > >Why does extending a list with the empty list result in None? It >seems very counterintuitive to me, at least --- I expected ['a'].extend >([]) to result in ['a'], not None. http://www.python.org/doc/faq/general/#why-doesn-t-list-sort-return-the-sorted-list -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 11:02:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 17:02:37 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: <4b6c411b$0$20638$426a74cc@news.free.fr> mk a ?crit : (snip) > So in this context this is fine. But I wanted to make the class more > robust. Perhaps I should do smth like this before setting self.cmd? > > assert isinstance(cmd, basestring) or cmd is None, "cmd should be string > or None" > > and then: > > if cmd: > self.cmd = cmd.replace.. And what if cmd happens to be the empty string ?-) ok, me --->[] From jeanmichel at sequans.com Fri Feb 5 11:03:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 17:03:28 +0100 Subject: xmlrcp - how to marshall objects Message-ID: <4B6C4150.8050705@sequans.com> Deos anyone knows where to find an code sample describing how to implement the interface to marshall one object into XMLRPC compliant structures ? I googled without any success, and what google does not find does not exist. Let say I have this very simple class: class Point: def __init__(self, x, y): self.x = x self.y = y I've looked into xmlrpc code, I see 2 options: 1/ override the Marshaller class of client and server 2/ looks like the lib is supporting a WRAPPER list system, it uses to Marshall Datetime & Binary object. Can it be possible to add its own class (could require to emplement the 'encode' method) I sense I will spend much more time than required unless someone is pointing me in the right direction. JM From gerald.britton at gmail.com Fri Feb 5 11:06:52 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 11:06:52 -0500 Subject: which In-Reply-To: <4B6C3C55.5040907@optimum.net> References: <4B6C3C55.5040907@optimum.net> Message-ID: <5d1a32001002050806n207d7784p144819c8af4c57cb@mail.gmail.com> [snip] > Last August [1], I offered this alternative: > > ?self.cmd = (cmd.replace(r'${ADDR}',ip) > ? ? ? ? ? ? ?if isinstance(cmd, str) else > ? ? ? ? ? ? ?cmd) > > But it didn't get much love in this forum! I'd probably go for that one as well though I might consider removing the outer parentheses. -- Gerald Britton From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 11:07:52 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 17:07:52 +0100 Subject: which In-Reply-To: References: Message-ID: <4b6c4256$0$21794$426a74cc@news.free.fr> mk a ?crit : > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd What could "cmd" be except a string ? From other posts here, I guess it's either a string or None ? If yes, then I'd go for this: if cmd: cmd = cmd.replace(r'${ADDR}',ip) self.cmd = cmd From wolftracks at invalid.com Fri Feb 5 11:17:15 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 08:17:15 -0800 Subject: How Uninstall MatPlotLib? Message-ID: See Subject. From andrew.degtiariov at gmail.com Fri Feb 5 11:21:47 2010 From: andrew.degtiariov at gmail.com (Andrew Degtiariov) Date: Fri, 5 Feb 2010 18:21:47 +0200 Subject: Import question Message-ID: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> Code of our project has split into several packages and we deploy the project using buildout. All worked fine until I need to dynamically inspect python modules. Here is structure of our src directory ????project.api.config ? ????project ? ? ????api ? ? ????config ? ? ????settings ? ????project.api.config.egg-info ????project.api.contacts ? ????project ? ? ????api ? ? ????contacts ? ? ????importer ? ? ????views ? ????project.api.contacts.egg-info ????project.api.core ? ????project ? ? ????api ? ? ????core ? ? ????js ? ? ????lib ? ? ????management ? ? ? ????commands ? ? ????middleware ? ? ????sessions ? ? ????users ? ????project.api.core.egg-info Buildout by itself generates bin/python which look like: import sys sys.path[0:0] = [ 'c:\\users\\ad\\project\\src\\project.api.core', 'c:\\users\\ad\\project\\src\\project.api.config', 'c:\\users\\ad\\project\\src\\project.api.contacts', 'c:\\users\\ad\\project\\eggs\\lockfile-0.8-py2.6.egg', 'c:\\users\\ad\\project\\parts\\django', 'c:\\users\\ad\\project\\eggs\\web.py-0.33-py2.6.egg', .... Regular code like "import project.api.config" worked fine, but now I'm tryed __import__('project.api.config'): $ bin/python >>> import project.api.config >>> __import__('project.api.config') >>> What's wrong? Ok, I'm trying imp: >>> import imp >>> imp.find_module('project.api.config') Traceback (most recent call last): File "", line 1, in ImportError: No module named project.api.config >>> import sys >>> sys.path[1] 'c:\\users\\ad\\project\\src\\project.api.config' >>> imp.find_module('project.api.config', sys.path[1]) Traceback (most recent call last): File "", line 1, in ImportError: No frozen submodule named c:\users\ad\project\src\project.api.config.project.api.config >>> There is setup.py for project.api.config: import os from setuptools import setup, find_packages name = "project.api.config" install_requires = [ 'zc.buildout', 'setuptools', 'web.py>=0.33', 'project.api.core', 'Django>=1.1.0', 'lockfile' ] if sys.platform != 'win32': install_requires.append('python-daemon') setup( name = name, version = "1.0", author = "Andrew Degtiariov", author_email = "andrew.degtiariov at gmail.com", description = "...", license = "Commercial", packages=find_packages(os.path.dirname(__file__), exclude=['ez_setup']), namespace_packages=['project, 'project.api'], include_package_data=True, zip_safe=False, install_requires = install_requires ) What's wrong? We really need to split the code for several eggs and want that all of our package's names starts from 'project.api' -- Andrew Degtiariov DA-RIPE -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Fri Feb 5 11:22:56 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 11:22:56 -0500 Subject: which In-Reply-To: References: <4B6C3C55.5040907@optimum.net> Message-ID: <4B6C45E0.1000309@optimum.net> On 2/5/2010 11:06 AM, Gerald Britton wrote: > [snip] > >> Last August [1], I offered this alternative: >> >> self.cmd = (cmd.replace(r'${ADDR}',ip) >> if isinstance(cmd, str) else >> cmd) >> >> But it didn't get much love in this forum! > > I'd probably go for that one as well though I might consider removing > the outer parentheses. Agreed ... except that you *need* the outer parentheses if the statement occupies multiple source lines. -John From aahz at pythoncraft.com Fri Feb 5 11:23:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2010 08:23:57 -0800 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On 4 Feb 2010 16:18:04 -0800, aahz at pythoncraft.com (Aahz) declaimed the >following in gmane.comp.python.general: >> >> But in bash scripting, you'd just use rsync or cp or rm -- maybe an >> example would make clearer how REXX differs from bash. > > I suspect the only really good examples would have to written under >OS/VMS (where it originated, written to be a more powerful & friendlier >replacement for the EXEC scripting language) or AmigaOS -- to >demonstrate the switching interaction of command handlers. REXX >implementations for Windows and Linux pretty much only support the >"shell" as a command handler, whereas the two named OS could address >editors (and on the Amiga, word processors, desktop publishing programs, >terminal emulators/comm programs, system editor). > > My Amiga's been in storage since Win95 days, so this is a fictitious >example based on the reference manuals. > >address command /* use normal command shell to process commands */ >file = 'some.file' >'run ed' file /* start ED editor in background, editing 'file'*/ >address ED /* send commands to the ED instance */ >'b' /* go to bottom of file */ >'i /text to be inserted before bottom line/' >'t' /* to to top */ >'a /text inserted after first line/' >find = 'needle' >replace = 'thorn' >'rpe /' || find || '/' || replace '/' >'x' /* save & exit */ >address command >'type' file /* type file to screen */ >'filenote' file "edited via AREXX script" IOW, kinda like AppleScript? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From mrkafk at gmail.com Fri Feb 5 11:27:35 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 17:27:35 +0100 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: References: Message-ID: W. eWatson wrote: > I'd like to draw something like an animal track. Between each point is a > line. Perhaps the line would have an arrow showing the direction of > motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? Pycairo? From jarausch at skynet.be Fri Feb 5 11:31:08 2010 From: jarausch at skynet.be (Helmut Jarausch) Date: Fri, 05 Feb 2010 17:31:08 +0100 Subject: Repost: Read a running process output In-Reply-To: References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> <87636bn8jw.fsf@dpt-info.u-strasbg.fr> <4ae7195a-d3ec-4886-9123-de88641aa797@g8g2000pri.googlegroups.com> Message-ID: <4b6c47cb$0$2865$ba620e4c@news.skynet.be> On 02/05/10 14:39, Ashok Prabhu wrote: > On Feb 5, 6:33 pm, Ashok Prabhu wrote: >> On Feb 5, 5:58 pm, Alain Ketterlin >> wrote: >> >> >> >>> Ashok Prabhu writes: >>>>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) >> >>>>> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. >> >>>>> -- Alain. >>>> Thanks for the response. However it throws an error. Please find >>>> below. >> >>>>>>> from subprocess import * >>>>>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) >> >>> You forgot to change the monolithic command into a list of words. Since >>> you don't use the shell anymore you have to give Popen a pre-parsed >>> command line. >> >>> -- Alain. >> >> Here is the error again >> >>>>> p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE) >> >> Traceback (most recent call last): >> File "", line 1, in ? >> File "/usr/lib/python2.4/subprocess.py", line 494, in __init__ >> raise TypeError("bufsize must be an integer") >> TypeError: bufsize must be an integer >> >> ~Ashok. > > Oops i missed the braces. But still no output. > > >>>> p1=Popen(['/usr/sunvts/bin/64/vtsk','-d'],stdout=PIPE) >>>> while 1: > ... a=p1.stdout.readline() > ... print a > ... I've tried #!/usr/bin/python import subprocess p1= subprocess.Popen(['/bin/ls','/LOCAL/'],stdout=subprocess.PIPE) for line in p1.stdout : print ">>>",line which works just fine. Are you sure, your /usr/sunvts/bin/64/vtsk writes a newline character (readline is waiting for that)? Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From gerald.britton at gmail.com Fri Feb 5 11:31:52 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 11:31:52 -0500 Subject: list.extend([]) Question In-Reply-To: References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> Message-ID: <5d1a32001002050831r6233b751mcbc5f55fb9a2c1b4@mail.gmail.com> I think it's because when you do ['a'].extend([]) or whatever, the result is whatever the method "extend" returns. But "extend" has no return value, hence you will see None if you do this interactively. On Fri, Feb 5, 2010 at 10:55 AM, Aahz wrote: > In article <088e7a24-b0d0-4d43-bee7-193e5eaefe57 at b7g2000pro.googlegroups.com>, > Dan Brown ? wrote: >> >>Why does extending a list with the empty list result in None? ?It >>seems very counterintuitive to me, at least --- I expected ['a'].extend >>([]) to result in ['a'], not None. > > http://www.python.org/doc/faq/general/#why-doesn-t-list-sort-return-the-sorted-list > -- > Aahz (aahz at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ? http://www.pythoncraft.com/ > > import antigravity > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From mrkafk at gmail.com Fri Feb 5 11:34:13 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 17:34:13 +0100 Subject: which In-Reply-To: <4b6c411b$0$20638$426a74cc@news.free.fr> References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> <4b6c411b$0$20638$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> if cmd: >> self.cmd = cmd.replace.. > > And what if cmd happens to be the empty string ?-) > > ok, me --->[] Right, I didn't think much when I wrote that. Anyway, that's back to square one. I will probably go for this anyway: assert isinstance(cmd, basestring) or cmd is None, 'cmd has to be string or None' if cmd: cmd = cmd.replace(r'${ADDR}',ip) self.cmd = cmd From jeanmichel at sequans.com Fri Feb 5 11:40:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 17:40:38 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: <4B6C4A06.6010700@sequans.com> mk wrote: > Jean-Michel Pichavant wrote: >> If you can change your program interface, then do it, if not then >> you're right you don't have much choice as you are suffering from the >> program poor interface. >> You can fix this problem by explicitly asking for the thing you want >> to do, instead of guessing by inspecting the argument nature. >> >> myProg --help >> >> usage : myProg command [args] >> command list: >> - cmd: execute the given command line >> - exec: execute the given script file named >> - copy: copy to >> >> example: >> >myProg cmd "echo that's cool" >> >myProg exec /etc/init.d/myDaemon >> >myProg copy /tmp /tmp2 >> > > I sure can change the interface since I'm the author of the entire > program. But I don't see how I can arrange program in a different way: > the program is supposed to be called with -c parameter (command to > run), -s script to run, or -y file_or_dir_to_copy. > > Then, I start instances of SSHThread class to do precisely that, > separately for each ip/hostname: > > > class SSHThread(threading.Thread): > def __init__(self, lock, cmd, ip, username, sshprivkey=None, > passw=None, port=22, script=None, remotedir=None): > > threading.Thread.__init__(self) > > self.lock = lock > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > self.ip = ip > self.username = username > self.sshprivkey = sshprivkey > self.passw = passw > self.port = port > self.conobj = None > self.conerror = '' > self.msgstr = '' > self.confailed = True > if script: > self.setpathinfo(script, remotedir=remotedir) > self.sentbytes = 0 > self.finished = False > self.abort = False > > It gets called like this: > > th = SSHThread(lock, opts.cmd, ip, username=username, > sshprivkey=opts.key, passw=passw, port=port, script=opts.script, > remotedir=opts.remotedir) > > > ..where all the options are parsed by ConfigParser.OptionParser(). So > they are either strings, or Nones. > > So in this context this is fine. But I wanted to make the class more > robust. Perhaps I should do smth like this before setting self.cmd? > > assert isinstance(cmd, basestring) or cmd is None, "cmd should be > string or None" > > and then: > > if cmd: > self.cmd = cmd.replace.. > > > ? > > Entire source code is here: > > http://python.domeny.com/cssh.py > > regards, > mk > To be honest I have not enough courrage to dive into yout 1000 lines of script :-) What I can say however: 1/ your interface is somehow broken. You ask actions through options (-c -y -s), meaning one can possibly use all these 3 options together. Your code won't handle it (you are using elif statements). What happens if I use no option at all ? As the the optparse doc states : if an option is not optional, then it is not an option (it's a positional argument). 2/ executing a script, or copying a directory are both commands as well. myProg -s /tmp/myscript.sh is nothing more than myProg -c '/bin/sh myscript.sh' myProg -y file1 is nothing more than myProg -c 'cp file1 towhatever' 3/ check your user parameters before creating your SSHThread, and create your SSHThread with already validated parameters. You don't want to pollute you SSHThread code with irrelevant user error check. my humble conclusion: 1/ rewrite your interface with prog command args [options] 2/ Simplify your SSHThread by handling only shell commands 3/ at the CLI level (right after parameter validation), mute you copy & script command to a shell command and pass it to SSHThread. Cheers, JM From jeanmichel at sequans.com Fri Feb 5 11:42:43 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 17:42:43 +0100 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: References: Message-ID: <4B6C4A83.7080802@sequans.com> mk wrote: > W. eWatson wrote: >> I'd like to draw something like an animal track. Between each point >> is a line. Perhaps the line would have an arrow showing the direction >> of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? > > Pycairo? > turtle http://docs.python.org/library/turtle.html From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 11:44:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 17:44:02 +0100 Subject: list.extend([]) Question In-Reply-To: References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> Message-ID: <4b6c4ad0$0$23943$426a74cc@news.free.fr> Gerald Britton a ?crit : > I think it's because when you do ['a'].extend([]) or whatever, the > result is whatever the method "extend" returns. But "extend" has no > return value It does : it returns None. From jurgenex at hotmail.com Fri Feb 5 11:48:29 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Fri, 05 Feb 2010 08:48:29 -0800 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: David Thole wrote in comp.lang.perl.misc: >I read this....and am a tiny bit confused about the actual problem. > >It's not exactly complex to realize that something like: >a = b = array >that a and b both point to the array. ??? What are you talking about? First of all you should post actual code, not pseudo-code because pseudo-code leads to misunderstandings. Did you mean @a = @b = @array Second what do you mean by "pointing"? That is a very ambiguous term. if you do the assignment as written above then @a and @b will be _copies_ of @array. If you want two additional references to the same array insted then you have to create that reference first and assign that reference to $a and $b instead of copying the array, see "perldoc perlref" for details. And remember, references are scalars, no matter if they reference other scalars or arrays. >Logically speaking, I'm not sure how one could assume that the same >assignment would yield a and b point to the same duplicate array. If Now what? The same array or a duplicate array? Two very different and mutually exclusive things. >that was the case, why not do: >a = array.. >b = array.. Which, after correcting the obvious syntax errors is the same as the code above. >I know with what you were complaining about a few days ago, .clear makes >perfect sense. If a and b point to the same array, clear should clear They don't point, they are copies. And what do you mean by "clear"? >both arrays. Again, if you didn't want that to happen, create a >duplicate array. But that is what that code above does. If you want references then create references. jue From sridharr at activestate.com Fri Feb 5 11:50:10 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 5 Feb 2010 08:50:10 -0800 Subject: ANN: ActivePython 2.6.4.10 is now available In-Reply-To: References: Message-ID: <7E38E471-25C3-49C9-B27F-2D4F0B355290@activestate.com> On 2010-02-05, at 6:31 AM, Tommy Grav wrote: > > On Feb 5, 2010, at 12:01 AM, Sridhar Ratnakumar wrote: > >> I'm happy to announce that ActivePython 2.6.4.10 is now available for download from: > >> On what platforms does ActivePython run? >> ---------------------------------------- >> >> ActivePython includes installers for the following platforms: >> >> - Windows/x86 >> - Windows/x64 (aka "AMD64") >> - Mac OS X > > Is the Mac OS X version still only 32 bit? Yes. > If so does ActiveState plan to make binaries for 64bit builds > for Snow Leopard? No concrete plans yet, but we do intend to make 64 bit for Mac available eventually. -srid -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Fri Feb 5 11:51:31 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 11:51:31 -0500 Subject: which In-Reply-To: <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> References: <4B6C3C55.5040907@optimum.net> <4B6C45E0.1000309@optimum.net> <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> Message-ID: <4B6C4C93.3050602@optimum.net> On 2/5/2010 11:26 AM, Gerald Britton wrote: > sure, but it will fit nicely on one line if you like > > On Fri, Feb 5, 2010 at 11:22 AM, John Posner wrote: > >> On 2/5/2010 11:06 AM, Gerald Britton wrote: >> >>> [snip] >>> >>> >>>> Last August [1], I offered this alternative: >>>> >>>> self.cmd = (cmd.replace(r'${ADDR}',ip) >>>> if isinstance(cmd, str) else >>>> cmd) >>>> >>>> But it didn't get much love in this forum! >>>> >>> I'd probably go for that one as well though I might consider removing >>> the outer parentheses. >>> >> Agreed ... except that you *need* the outer parentheses if the statement >> occupies multiple source lines. >> >> -John >> >> >> >> > > > Did you mean to take this off-list? Also, I'm contractually obligated to admonish you not to "top post". At any rate, I proposed the 3-line format specifically because it separates the data values from the if-then-else machinery, making it easier (for me) to read. But there was considerable resistance to spending so much vertical space in the source code. -John From awilliam at opengroupware.us Fri Feb 5 11:52:57 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Fri, 05 Feb 2010 11:52:57 -0500 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C4150.8050705@sequans.com> References: <4B6C4150.8050705@sequans.com> Message-ID: <1265388777.3112.7.camel@linux-m3mt> On Fri, 2010-02-05 at 17:03 +0100, Jean-Michel Pichavant wrote: > Deos anyone knows where to find an code sample describing how to > implement the interface to marshall one object into XMLRPC compliant > structures ? > I googled without any success, and what google does not find does not exist. > Let say I have this very simple class: > class Point: > def __init__(self, x, y): > self.x = x > self.y = y You have to be more specific about what you want to do; "marshall" is a fairly generic term. XML-RPC isn't CORBA; typically you don't remote persistent objects you just make individual calls. > I've looked into xmlrpc code, I see 2 options: > 1/ override the Marshaller class of client and server > 2/ looks like the lib is supporting a WRAPPER list system, it uses to > Marshall Datetime & Binary object. Can it be possible to add its own > class (could require to emplement the 'encode' method) > I sense I will spend much more time than required unless someone is > pointing me in the right direction. You can use the loads and dumps methods to process the XML-RPC call anyway you like. -- OpenGroupware developer: awilliam at whitemice.org OpenGroupare & Cyrus IMAPd documenation @ From gerald.britton at gmail.com Fri Feb 5 11:53:33 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 11:53:33 -0500 Subject: which In-Reply-To: <4B6C4C93.3050602@optimum.net> References: <4B6C3C55.5040907@optimum.net> <4B6C45E0.1000309@optimum.net> <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> <4B6C4C93.3050602@optimum.net> Message-ID: <5d1a32001002050853s4621ca0dy9976609813cc4e3@mail.gmail.com> > > Did you mean to take this off-list? Nope -- just hit the wrong key ?Also, I'm contractually obligated to > admonish you not to "top post". Contract? > > At any rate, I proposed the 3-line format specifically because it separates > the data values from the if-then-else machinery, making it easier (for me) > to read. But there was considerable resistance to spending so much vertical > space in the source code. Weird! It's three lines and the original was four lines was it not>? -- Gerald Britton From mrkafk at gmail.com Fri Feb 5 11:56:44 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 17:56:44 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C4150.8050705@sequans.com> References: <4B6C4150.8050705@sequans.com> Message-ID: Jean-Michel Pichavant wrote: Why not dump the whole thing and use Pyro, which works beautifully and handles all the serialization business by itself, you get a Python object on the other side? Unless xmlrpc has to be at the other end, that is. From giles.thomas at resolversystems.com Fri Feb 5 12:04:10 2010 From: giles.thomas at resolversystems.com (Giles Thomas) Date: Fri, 5 Feb 2010 09:04:10 -0800 (PST) Subject: ANN: Resolver One 1.8 released Message-ID: We're proud to announce that we've just released version 1.8 of Resolver One. This version switches to IronPython 2.6, which gives us support for Python 2.6 syntax along with some serious performance improvements. Resolver One is a Windows-based spreadsheet that integrates Python deeply into its recalculation loop, making the models you build more reliable and more maintainable. In version 1.8, we've worked hard on improving performance above and beyond the gains we got from IronPython 2.6, and we've also added a number of new statistical functions, along with various minor bugfixes and smaller enhancements. You can read more about Resolver One here: We have a 31-day free trial version, so if you would like to take a look, you can download it from our website: If you want to use Resolver One in an Open Source project, we offer free licenses for that: Best regards, Giles -- Giles Thomas giles.thomas at resolversystems.com +44 (0) 20 7253 6372 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From mrkafk at gmail.com Fri Feb 5 12:07:11 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:07:11 +0100 Subject: which In-Reply-To: <4B6C4A06.6010700@sequans.com> References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> <4B6C4A06.6010700@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > To be honest I have not enough courrage to dive into yout 1000 lines of > script :-) Understandable. > What I can say however: > > 1/ your interface is somehow broken. You ask actions through options (-c > -y -s), meaning one can possibly use all these 3 options together. Your > code won't handle it (you are using elif statements). What happens if I > use no option at all ? You get this: Linux RH [17:35] root ~ # cssh.py -c "ps|wc" -s /tmp/s.sh Following options that you specified are mutually exclusive: -s / --script (value: /tmp/s.sh) -c / --cmd (value: ps|wc) You have to specify exactly one of options -c / --cmd, or -s / --script, or -y / --copy. I wrote additional logic to handle such situations, I don't rely entirely on optparse. > 2/ executing a script, or copying a directory are both commands as well. > myProg -s /tmp/myscript.sh > is nothing more than > myProg -c '/bin/sh myscript.sh' True. But you have to copy the script to remote machine in the first place. It's more convenient to do this using one option (copy to remote machine & execute there). > myProg -y file1 > is nothing more than > myProg -c 'cp file1 towhatever' Err but this is command to copy a local file/dir to *remote* machine. Like scp (in fact it uses scp protocol internally). > > 3/ check your user parameters before creating your SSHThread, and create > your SSHThread with already validated parameters. You don't want to > pollute you SSHThread code with irrelevant user error check. > > > my humble conclusion: > > 1/ rewrite your interface with > prog command args [options] > > 2/ Simplify your SSHThread by handling only shell commands > > 3/ at the CLI level (right after parameter validation), mute you copy & > script > command to a shell command and pass it to SSHThread. > > Cheers, > > JM > > From mrkafk at gmail.com Fri Feb 5 12:08:40 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:08:40 +0100 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: <4B6C4A83.7080802@sequans.com> References: <4B6C4A83.7080802@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > mk wrote: >> W. eWatson wrote: >>> I'd like to draw something like an animal track. Between each point >>> is a line. Perhaps the line would have an arrow showing the direction >>> of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? >> >> Pycairo? >> > turtle > > http://docs.python.org/library/turtle.html It's in standard library, and therefore Not Cool. From donn.ingle at gmail.com Fri Feb 5 12:19:06 2010 From: donn.ingle at gmail.com (donn) Date: Fri, 05 Feb 2010 19:19:06 +0200 Subject: pyclutter anyone? In-Reply-To: <4B6BD072.4080006@gmail.com> References: <4B6BD072.4080006@gmail.com> Message-ID: <4B6C530A.70303@gmail.com> No one uses pyClutter? I have some code, it does not work, but maybe this will start to help solve the problem: import clutter from clutter import cogl x,y=0,0 def boo(tl,frame,obj):#,evt): global x,y obj.set_position(x, y) def xy(obj,evt): global x,y x,y = evt.x,evt.y class G(clutter.Group): """ Attempt to make a Group that can clip its children to a path. """ def __init__(self,*args): clutter.Group.__init__(self,*args) #self.set_clip(0,0,10,10) self.connect("paint",self.do_paint) self._color = clutter.Color(255,200,100) def do_paint(self, args): width,height=200,200 cogl.path_move_to(width / 2, 0) cogl.path_line_to(width, height) cogl.path_line_to(0, height) cogl.path_line_to(width / 2, 0) cogl.path_close() #cogl.set_source_color(self._color) #cogl.path_fill() ## Colour me lost from here... cogl.clip_push_from_path() clutter.Group.do_paint(self) cogl.clip_pop() def main(): global group1 stage = clutter.Stage() stage.set_size(500, 500) stage.set_color(clutter.color_from_string("#FFF")) rect1, rect2, rect3 = clutter.Rectangle(), clutter.Rectangle(), clutter.Rectangle() group1, group2, group3 = G(), clutter.Group(), clutter.Group() group1.add(rect1, group2) group2.add(rect2, group3) group3.add(rect3) group1.set_position(100, 100) group2.set_position(100, 100) group3.set_position(100, 100) rect1.set_position(0, 0) rect2.set_position(0, 0) rect3.set_position(0, 0) rect1.set_size(150, 150) rect2.set_size(150, 150) rect3.set_size(150, 150) rect1.set_color(clutter.color_from_string("#FF000090")) rect2.set_color(clutter.color_from_string("#00FF0090")) rect3.set_color(clutter.color_from_string("#0000FF90")) stage.add(group1) stage.show_all() group1.show_all() group2.show_all() group3.show_all() stage.connect("key-press-event", clutter.main_quit) stage.connect('destroy', clutter.main_quit) stage.connect('motion-event', xy) path = clutter.Path('M 0 0 L 300 0 L 300 300 L 0 300z') timeline = clutter.Timeline(4000) timeline.set_loop(True) alpha = clutter.Alpha(timeline,clutter.EASE_OUT_SINE) p_behaviour = clutter.BehaviourPath(alpha, path) path.add_move_to(0, 0) p_behaviour.apply(group3) timeline.add_marker_at_time("foo",2000) timeline.start() t=clutter.Timeline(1000) t.set_loop(True) t.connect('new-frame', boo, group1) t.start() clutter.main() if __name__ == '__main__': main() \d -- Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software From mrkafk at gmail.com Fri Feb 5 12:23:09 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:23:09 +0100 Subject: timer for a function Message-ID: I have the following situation: 1. self.conobj = paramiko.SSHClient() self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) 2. very slow SSH host that is hanging for 30+ seconds on key exchange. The timeout in the options regards only a socket timeout, not further stages of connection negotiation, so it doesn't work there. On paramiko mailing list I got the suggestion to build a timer and then quit this by myself: > The timeout option in connect() is for the socket, not for the entire > operation. You are connected, so that timeout is no longer relevant. > You would probably have to wrap the transport.connect() method in a > timer to break out of this early. Question: how can I do that? Use another threaded class? Is there some other way? Additional snag is SSHClient() is a class that internally uses threads. How do I kill brutally its threads? Is there any way to do it? Regards, mk From arnodel at googlemail.com Fri Feb 5 12:23:51 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Feb 2010 17:23:51 +0000 Subject: Dreaming of new generation IDE References: Message-ID: Robert Kern writes: > I prefer Guido's formulation (which, naturally, I can't find a direct > quote for right now): if you expect that a boolean argument is only > going to take *literal* True or False, then it should be split into > two functions. So rather than three boolean arguments, would you have eight functions? -- Arnaud From jeanmichel at sequans.com Fri Feb 5 12:24:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 18:24:20 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C4150.8050705@sequans.com> References: <4B6C4150.8050705@sequans.com> Message-ID: <4B6C5444.4090205@sequans.com> Jean-Michel Pichavant wrote: > Deos anyone knows where to find an code sample describing how to > implement the interface to marshall one object into XMLRPC compliant > structures ? > > I googled without any success, and what google does not find does not > exist. > > Let say I have this very simple class: > > class Point: > def __init__(self, x, y): > self.x = x > self.y = y > > > I've looked into xmlrpc code, I see 2 options: > 1/ override the Marshaller class of client and server > 2/ looks like the lib is supporting a WRAPPER list system, it uses to > Marshall Datetime & Binary object. Can it be possible to add its own > class (could require to emplement the 'encode' method) > > I sense I will spend much more time than required unless someone is > pointing me in the right direction. > > JM > I realized I gave a poor example, actually the Point object is marshable (marshallable ? like to invent new words), xmlrpc will try to marshall using __dict__ if possible. import os class Point: def __init__(self, x, y): self.x = x self.y = y self.notMarshallable = os JM From tadmc at seesig.invalid Fri Feb 5 12:25:34 2010 From: tadmc at seesig.invalid (Tad McClellan) Date: Fri, 05 Feb 2010 11:25:34 -0600 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: ["Followup-To:" header set to comp.lang.perl.misc.] J?rgen Exner wrote: > David Thole wrote in comp.lang.perl.misc: >>I read this....and am a tiny bit confused about the actual problem. >> >>It's not exactly complex to realize that something like: >>a = b = array >>that a and b both point to the array. > > ??? > What are you talking about? First of all you should post actual code, First of all, we should not be feeding the troll! actual code in one of Perl, Python or Lisp? -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" From mrkafk at gmail.com Fri Feb 5 12:29:07 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:29:07 +0100 Subject: Your beloved python features In-Reply-To: <4B6B5E72.20702@stoneleaf.us> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: Ethan Furman wrote: > http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf > Choose to get your difficult questions about threads in Python ignored. Oh well.. From jeanmichel at sequans.com Fri Feb 5 12:30:17 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 18:30:17 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: References: <4B6C4150.8050705@sequans.com> Message-ID: <4B6C55A9.9000902@sequans.com> mk wrote: > Jean-Michel Pichavant wrote: > > Why not dump the whole thing and use Pyro, which works beautifully and > handles all the serialization business by itself, you get a Python > object on the other side? Unless xmlrpc has to be at the other end, > that is. > > Company stuff. We are all using the xmlrpc standard for our network code. JM From invalid at invalid.invalid Fri Feb 5 12:30:46 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Feb 2010 17:30:46 +0000 (UTC) Subject: Drawing a zig-zag Trail in Python? References: Message-ID: On 2010-02-05, W. eWatson wrote: > I'd like to draw something like an animal track. Between each > point is a line. Perhaps the line would have an arrow showing > the direction of motion. There should be x-y coordinates > axises. PIL? MatPlotLib, ?? I'd probably use gnuplot-py, but I'm probably biased since I've been using gnuplot since way before I learned Python. -- Grant Edwards grante Yow! Hello, GORRY-O!! at I'm a GENIUS from HARVARD!! visi.com From mrkafk at gmail.com Fri Feb 5 12:30:50 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:30:50 +0100 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: Julian wrote: > For those guys would be a poster quite cool which describes the most > popular and beloved python features. Dictionaries. A workhorse of Python, by far the most useful data structure. From mrkafk at gmail.com Fri Feb 5 12:35:39 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:35:39 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> <4B6C4A06.6010700@sequans.com> Message-ID: mk wrote: > > > What I can say however: > > > > 1/ your interface is somehow broken. You ask actions through options (-c > > -y -s), meaning one can possibly use all these 3 options together. Your > > code won't handle it (you are using elif statements). What happens if I > > use no option at all ? Arrgh this is my bad day. You get this: Linux RH [17:35] root ~ # cssh.py -i linux You have to specify exactly one of the following: - command to run remotely, using -c command / --cmd command, or - script to run remotely, using -s scriptfile / --script scriptfile, or - file/directory to copy, using -y file_or_dir / --copy file_or_dir From bradallen137 at gmail.com Fri Feb 5 12:48:24 2010 From: bradallen137 at gmail.com (Brad Allen) Date: Fri, 5 Feb 2010 11:48:24 -0600 Subject: method to intercept string formatting % operations In-Reply-To: <4B6C3DEC.9030109@sequans.com> References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> <4B6C3DEC.9030109@sequans.com> Message-ID: <4957f1ef1002050948i49816576nfe2f614a36d17cb1@mail.gmail.com> On Fri, Feb 5, 2010 at 9:49 AM, Jean-Michel Pichavant wrote: > Anyway why would you want to use the tuple form ? it's beaten in every > aspect by the dictionary form. I'm subclassing a namedtuple, and adding some additional functionality such as __getitem__, __setitem__, so that the namedtuple also behaves like a dict. From charles at declareSub.com Fri Feb 5 12:55:58 2010 From: charles at declareSub.com (Charles Yeomans) Date: Fri, 5 Feb 2010 12:55:58 -0500 Subject: Exception class documentation Message-ID: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> I am so far unable to find the information I want about the Exception class. Information like the signature of __init__ seems to be unavailable. Any suggestions where I might find such information? Charles Yeomans From cjblaine at gmail.com Fri Feb 5 12:58:52 2010 From: cjblaine at gmail.com (cjblaine) Date: Fri, 5 Feb 2010 09:58:52 -0800 (PST) Subject: Modules failing to add runtime library path info at link time References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> <303e1371-bc77-4cc8-bbbf-bddfd610fad9@r19g2000yqb.googlegroups.com> <8167cbe0-d099-4a0b-804e-6e91817197ec@b10g2000yqa.googlegroups.com> Message-ID: <382f9f94-e863-4511-a824-b03225135faa@r24g2000yqd.googlegroups.com> On Feb 1, 11:35?pm, cjblaine wrote: > On Feb 1, 11:04?pm, cjblaine wrote: > > > > > On Feb 1, 8:00?pm, Christian Heimes wrote: > > > > cjblaine wrote: > > > > Where/how can I configure the appropriate portion of our Python > > > > install to do 100% the right thing instead of just 50% (-L)? > > > > Python's distutils doesn't alter the library search path unless you tell > > > it explicitly. > > > > > A specific example -- note the -L and lack of -R (Solaris build): > > > > > % python setup.py build > > > > .... > > > > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > > > > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > > > > % > > > > The Extension() class supports the rpath argument. Simply add > > > rpath="/path/to/library/dir" and you are good. > > > > Christian > > > Thanks for the reply. > > > So, python setup.py build rpath="/whatever/lib" ? > > Replying to myself: > > No. ?Actually, Christian, it looks like it's runtime_library_dirs? > > class Extension: > ... > ? ? ? runtime_library_dirs : [string] > ? ? ? ? list of directories to search for C/C++ libraries at run time > ? ? ? ? (for shared extensions, this is when the extension is loaded) > > So, how does one inject that into, I assume, setup.cfg ? ?Ideally it > could be done via the build command-line, but I don't see a way to do > that when browsing python setup.py build --help > > ( there is no setup.cfg provided in the PyGreSQL source tree, to ) > ( continue that example case ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ) Anyone? From gandalf at shopzeus.com Fri Feb 5 13:11:17 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 05 Feb 2010 19:11:17 +0100 Subject: Editor for Python Message-ID: <4B6C5F45.8010200@shopzeus.com> Hi All, I know that this question was put up on this list a thousand times. I know that most of the editors are listed here: http://wiki.python.org/moin/PythonEditors I already tried most of them. But still, I need something that is not listed there. Requirements: * starts and works fast * has code folding, displays identation guides * auto completion * class browser * source code browser (e.g. a list of definitions, when you click it jumps to the definition * integration with pychecker or pylint * UTF-8 files * free, or not-so-expensive * works on linux and windows The one I'm using now is Geany. It does everything, except class browser and pychecker/pylint. Now maybe, I can install (or write??) a geany extension that would allow me to use pychecker. But I could not find information on that. There where others I tried (PyPE, DrPython, KomodoEdit, Editra etc.) but all of them failed for some reason. Can you please suggest another editor that I could try? Or send me a link that tells how to write or install pychecked plugin for Geany. Thanks, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 5 13:20:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Feb 2010 18:20:40 +0000 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C5444.4090205@sequans.com> References: <4B6C4150.8050705@sequans.com> <4B6C5444.4090205@sequans.com> Message-ID: <4B6C6178.2010002@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > Jean-Michel Pichavant wrote: >> Deos anyone knows where to find an code sample describing how to >> implement the interface to marshall one object into XMLRPC compliant >> structures ? >> >> I googled without any success, and what google does not find does not >> exist. >> >> Let say I have this very simple class: >> >> class Point: >> def __init__(self, x, y): >> self.x = x >> self.y = y >> >> >> I've looked into xmlrpc code, I see 2 options: >> 1/ override the Marshaller class of client and server >> 2/ looks like the lib is supporting a WRAPPER list system, it uses to >> Marshall Datetime & Binary object. Can it be possible to add its own >> class (could require to emplement the 'encode' method) >> >> I sense I will spend much more time than required unless someone is >> pointing me in the right direction. >> >> JM >> > I realized I gave a poor example, actually the Point object is marshable > (marshallable ? like to invent new words), xmlrpc will try to marshall > using __dict__ if possible. > "marshallable". Just pick a verb and add -able. There was an advertisement by British Gas in which someone said that his gas central heating was very turn-off-and-on-able! :-) > import os > > class Point: > def __init__(self, x, y): > self.x = x > self.y = y > self.notMarshallable = os > From jjposner at optimum.net Fri Feb 5 13:26:23 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 13:26:23 -0500 Subject: which In-Reply-To: References: <4B6C3C55.5040907@optimum.net> <4B6C45E0.1000309@optimum.net> <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> <4B6C4C93.3050602@optimum.net> Message-ID: <4B6C62CF.9090902@optimum.net> On 2/5/2010 11:53 AM, Gerald Britton wrote: > Also, I'm contractually obligated to >> admonish you not to "top post". > > Contract? Joke. (I know it's hard to tell.) > >> >> At any rate, I proposed the 3-line format specifically because it separates >> the data values from the if-then-else machinery, making it easier (for me) >> to read. But there was considerable resistance to spending so much vertical >> space in the source code. > > Weird! It's three lines and the original was four lines was it not>? Yes, but most people (including you, right?) seemed to think that conditional expressions are best confined to a single line. I proposed my 3-line alternative for expressions that *cannot* reasonably be confined to a single line. -John From gerald.britton at gmail.com Fri Feb 5 13:41:52 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 13:41:52 -0500 Subject: Editor for Python In-Reply-To: <4B6C5F45.8010200@shopzeus.com> References: <4B6C5F45.8010200@shopzeus.com> Message-ID: <5d1a32001002051041od360fd1qe46a1ba8593df7ff@mail.gmail.com> 2010/2/5 Laszlo Nagy : > > ? Hi All, > > I know that this question was put up on this list a thousand times. I know > that most of the editors are listed here: > http://wiki.python.org/moin/PythonEditors > > I already tried most of them. But still, I need something that is not listed > there. Requirements: > > starts and works fast > has code folding, displays identation guides > auto completion > class browser > source code browser (e.g. a list of definitions, when you click it jumps to > the definition > integration with pychecker or pylint > UTF-8 files > free, or not-so-expensive > works on linux and windows > > The one I'm using now is Geany. It does everything, except class browser and > pychecker/pylint. Now maybe, I can install (or write??) a geany extension > that would allow me to use pychecker. But I could not find information on > that. There where others I tried (PyPE, DrPython, KomodoEdit, Editra etc.) > but all of them failed for some reason. Can you please suggest another > editor that I could try? Or send me a link that tells how to write or > install pychecked plugin for Geany. > > Thanks, > > ?? Laszlo > > > -- > http://mail.python.org/mailman/listinfo/python-list > > I use Geany too. It lets me see the classes in my module, though not within a package (Is that what you mean)? You'd probably have to write a plugin to support pychecker or pylint though I believe that its not too difficult. Who knows? Perhaps someone already has such a plugin that you can use. -- Gerald Britton From gnarlodious at gmail.com Fri Feb 5 13:44:03 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Fri, 5 Feb 2010 10:44:03 -0800 (PST) Subject: SQLite3: preventing new file creation Message-ID: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> Every time I say something like: connection=sqlite3.connect(file) sqlite creates a new database file. Can this behavior be suppressed through SQLite? Or am I forced to check for the file existing first? -- Gnarlie From wolftracks at invalid.com Fri Feb 5 14:04:34 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 11:04:34 -0800 Subject: How Uninstall MatPlotLib? In-Reply-To: References: Message-ID: On 2/5/2010 8:17 AM, W. eWatson wrote: > See Subject. I'm working in IDLE in Win7. It seems to me it gets stuck in site-packages under C:\Python25. Maybe this is as simple as deleting the entry? Well, yes there's a MPL folder under site-packages and an info MPL file of 540 bytes. There are also pylab.py, pyc,and py0 files under site. From gerald.britton at gmail.com Fri Feb 5 14:13:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 14:13:36 -0500 Subject: Exception class documentation In-Reply-To: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> Message-ID: <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> On Fri, Feb 5, 2010 at 12:55 PM, Charles Yeomans wrote: > I am so far unable to find the information I want about the Exception class. > ?Information like the signature of __init__ seems to be unavailable. ?Any > suggestions where I might find such information? > > > Charles Yeomans > -- > http://mail.python.org/mailman/listinfo/python-list > Though not documented, some silly tests indicate that it will accept pretty much anything: >>> Exception(1,2,4,54) Exception(1, 2, 4, 54) >>> Exception(*range(10)) Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>> Exception(*range(50)) Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49) >>> Exception('a','b','c','d','e') Exception('a', 'b', 'c', 'd', 'e') >>> Exception(Exception(1)) Exception(Exception(1,),) -- Gerald Britton From wanderer at dialup4less.com Fri Feb 5 14:53:08 2010 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 5 Feb 2010 11:53:08 -0800 (PST) Subject: method names nounVerb or verbNoun Message-ID: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Which is the more accepted way to compose method names nounVerb or verbNoun? For example voltageGet or getVoltage? getVoltage sounds more normal, but voltageGet is more like voltage.Get. I seem to mix them and I should probably pick one way and stick with it. Thanks From steve at holdenweb.com Fri Feb 5 14:55:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 14:55:25 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: > Robert Kern writes: > >> I prefer Guido's formulation (which, naturally, I can't find a direct >> quote for right now): if you expect that a boolean argument is only >> going to take *literal* True or False, then it should be split into >> two functions. > > So rather than three boolean arguments, would you have eight functions? > If there's genuinely a need for that functionality, yes. I statement that calls one of two functions depending on the value of a Boolean is normally considered to be better coupling than calling a single function with the Boolean as an argument. As with everything else you have to apply a certain amount of common sense. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From gerald.britton at gmail.com Fri Feb 5 15:00:45 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 15:00:45 -0500 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <5d1a32001002051200n11f02e65re43ad5291bbbf951@mail.gmail.com> On Fri, Feb 5, 2010 at 2:53 PM, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > I'd say noun_verb (note the underscore in accordance with the style guide in PEP 8): http://www.python.org/dev/peps/pep-0008/ Function Names Function names should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility. -- Gerald Britton From mukeshtiwari.iiitm at gmail.com Fri Feb 5 15:14:51 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Fri, 5 Feb 2010 12:14:51 -0800 (PST) Subject: Last M digits of expression A^N Message-ID: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Hello everyone. I am kind of new to python so pardon me if i sound stupid. I have to find out the last M digits of expression.One thing i can do is (A**N)%M but my A and N are too large (10^100) and M is less than 10^5. The other approach was repeated squaring and taking mod of expression. Is there any other way to do this in python more faster than log N. def power(A,N,M): ret=1 while(N): if(N%2!=0):ret=(ret*A)%M A=(A*A)%M N=N//2 return ret From awilliam at opengroupware.us Fri Feb 5 15:15:42 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Fri, 05 Feb 2010 15:15:42 -0500 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C5444.4090205@sequans.com> References: <4B6C4150.8050705@sequans.com> <4B6C5444.4090205@sequans.com> Message-ID: <1265400942.3301.14.camel@linux-m3mt> On Fri, 2010-02-05 at 18:24 +0100, Jean-Michel Pichavant wrote: > Jean-Michel Pichavant wrote: > > Deos anyone knows where to find an code sample describing how to > > implement the interface to marshall one object into XMLRPC compliant > > structures ? > > I googled without any success, and what google does not find does not > > exist. > > Let say I have this very simple class: > > class Point: > > def __init__(self, x, y): > > self.x = x > > self.y = y > > I've looked into xmlrpc code, I see 2 options: > > 1/ override the Marshaller class of client and server > > 2/ looks like the lib is supporting a WRAPPER list system, it uses to > > Marshall Datetime & Binary object. Can it be possible to add its own > > class (could require to emplement the 'encode' method) > > I sense I will spend much more time than required unless someone is > > pointing me in the right direction. > I realized I gave a poor example, actually the Point object is marshable > (marshallable ? like to invent new words), xmlrpc will try to marshall > using __dict__ if possible. > import os > class Point: > def __init__(self, x, y): > self.x = x > self.y = y > self.notMarshallable = os This example doesn't make any sense. Why would you set a variable equal to an important module in a class named Point? What is it you are actually trying to accomplish? If you are trying to create an object publishing environment then maybe something like - rpc = xmlrpclib.loads(payload, use_datetime=True) method = rpc[1].split('.') classname = method[0] methodname = method[1] parameters = rpc[0] classclass = eval(classname) handler = classclass() call = getattr(handler, method_name) result = apply(call, parameters) result = xmlrpclib.dumps(tuple([result]), methodresponse=True) Obviously add copious amounts of exception handling and a security model. -- OpenGroupware developer: awilliam at whitemice.org OpenGroupare & Cyrus IMAPd documenation @ From nagle at animats.com Fri Feb 5 15:16:46 2010 From: nagle at animats.com (John Nagle) Date: Fri, 05 Feb 2010 12:16:46 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> kj wrote: ... > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. The right answer to this is to make module search return an error if two modules satisfy the search criteria. "First find" isn't a good solution. John Nagle From dickinsm at gmail.com Fri Feb 5 15:18:42 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 5 Feb 2010 12:18:42 -0800 (PST) Subject: Last M digits of expression A^N References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <5630ef4a-28c0-4efd-9d4f-a7b8aab28cb3@r24g2000yqd.googlegroups.com> On Feb 5, 8:14?pm, mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > 10^5. The other approach ? was ?repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. > > def power(A,N,M): > ? ? ret=1 > ? ? while(N): > ? ? ? ? if(N%2!=0):ret=(ret*A)%M > ? ? ? ? A=(A*A)%M > ? ? ? ? N=N//2 > ? ? return ret The built-in pow function does exactly this, if you give it three arguments: >>> pow(12345, 67891, 17) 10 >>> 12345 ** 67891 % 17 10L (Though this won't work for negative N.) Mark From apt.shansen at gmail.com Fri Feb 5 15:19:26 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 5 Feb 2010 12:19:26 -0800 Subject: How to guard against bugs like this one? In-Reply-To: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> References: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> Message-ID: <7a9c25c21002051219v65760f7co276617dd6422952b@mail.gmail.com> On Fri, Feb 5, 2010 at 12:16 PM, John Nagle wrote: > kj wrote: > >> Through a *lot* of trial an error I finally discovered that the >> root cause of the problem was the fact that, in the same directory >> as buggy.py, there is *another* innocuous little script, totally >> unrelated, whose name happens to be numbers.py. >> > > The right answer to this is to make module search return an > error if two modules satisfy the search criteria. "First find" > isn't a good solution. > And thereby slowdown every single import and application startup time as the common case of finding a module in one of the first couple entries in sys.path now has to search it in every single item on that path. Its not uncommon to have a LOT of things on sys.path. No thanks. "First Find" is good enough, especially with PEP328 and absolute_import being on in Python 3 (and presumably 2.7). It doesn't really help older Python versions unfortunately, but changing how import works wouldn't help them anyways. Yeah, there might be two paths on sys.path which both have a 'numbers.py' at the top level and First Find might return the wrong one, but... people making poor decisions on code organization and not using packages isn't something the language really needs to fix. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerald.britton at gmail.com Fri Feb 5 15:21:13 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 15:21:13 -0500 Subject: Last M digits of expression A^N In-Reply-To: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <5d1a32001002051221r2b4ffadak442492bac6debb40@mail.gmail.com> On Fri, Feb 5, 2010 at 3:14 PM, mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > 10^5. The other approach ? was ?repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. > > def power(A,N,M): > ? ?ret=1 > ? ?while(N): > ? ? ? ?if(N%2!=0):ret=(ret*A)%M > ? ? ? ?A=(A*A)%M > ? ? ? ?N=N//2 > ? ?return ret > -- > http://mail.python.org/mailman/listinfo/python-list > http://docs.python.org/3.1/library/decimal.html#decimal.Context.power -- Gerald Britton From clp2 at rebertia.com Fri Feb 5 15:26:38 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Feb 2010 12:26:38 -0800 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <50697b2c1002051226o50d4ff02u101d8c362ae0d1ea@mail.gmail.com> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. Use properties[1] and just call it `voltage`. Python is not Java [2]; explicit getters/setters are unpythonic. [1] http://docs.python.org/library/functions.html#property [2] http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Fri Feb 5 15:26:44 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Feb 2010 20:26:44 +0000 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <4B6C7F04.1090002@mrabarnett.plus.com> Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > I would use the 'normal' order, which in this case is 'get_voltage'. From mensanator at aol.com Fri Feb 5 15:28:37 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Feb 2010 12:28:37 -0800 (PST) Subject: Last M digits of expression A^N References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> <5630ef4a-28c0-4efd-9d4f-a7b8aab28cb3@r24g2000yqd.googlegroups.com> Message-ID: On Feb 5, 2:18?pm, Mark Dickinson wrote: > On Feb 5, 8:14?pm, mukesh tiwari wrote: > > > Hello everyone. I am kind of new to python so pardon me if i sound > > stupid. > > I have to find out the last M digits of expression.One thing i can do > > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > > 10^5. The other approach ? was ?repeated squaring and taking mod of > > expression. Is there any other way to do this in python more faster > > than log N. > > > def power(A,N,M): > > ? ? ret=1 > > ? ? while(N): > > ? ? ? ? if(N%2!=0):ret=(ret*A)%M > > ? ? ? ? A=(A*A)%M > > ? ? ? ? N=N//2 > > ? ? return ret > > The built-in pow function does exactly this, It doesn't do 'exactly' that. M is the number of digits. If you want 17 digits, the third number should 10**17. Using 17 directly will give you a 2-digit answer as shown. Try this instead: >>> pow(12345,67891,10**17) 50553131103515625 > if you give it three > arguments: > > >>> pow(12345, 67891, 17) > 10 > >>> 12345 ** 67891 % 17 > > 10L > > (Though this won't work for negative N.) > > Mark From jonny.lowe.12345 at gmail.com Fri Feb 5 15:39:07 2010 From: jonny.lowe.12345 at gmail.com (jonny lowe) Date: Fri, 5 Feb 2010 12:39:07 -0800 (PST) Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> Message-ID: <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> On Feb 4, 8:20?pm, exar... at twistedmatrix.com wrote: > On 01:56 am, jonny.lowe.12... at gmail.com wrote: > > > > >Hi everyone, > > >Is there an easy way to mergestdinandstdout? For instance suppose I > >havescriptthat prompts for a number and prints the number. If you > >execute this with redirection from a file say input.txt with 42 in the > >file, then executing > > >./myscript < input.txt > output.txt > > >the output.txt might look like this: > > >Enter a number: > >You entered 42. > > >What I want is to have an easy way to merge input.txt and thestdout > >so that output.txt look like: > > >Enter a number: 42 > >You entered 42. > > >Here, the first 42 is of course from input.txt. > > It sounds like you might be looking forscript(1)? > > Jean-Paul Hi Jean-Paul, I tried it. But stdin is not merged in with stdout. Maybe I'm using script wrongly? This is what I've done. I have a python script y. Here's what it looks like when I run it and I entered "sss": $ ./y gimme x:sss you entered sss Now I'm going to use the script command. I'm using an input file input.txt that contains just the string "hello". $ script -c "./y < input.txt" output.txt Script started, file is output.txt gimme x:you entered hello Script done, file is output.txt And when I view output.txt this is what I see: $ less output.txt Script started on Thu Feb 4 22:28:12 2010 gimme x:you entered hello Script done on Thu Feb 4 22:28:13 2010 As you can see the stdin is not printed. What I'd really wanted was something like this in output.txt: gimme x:hello you entered hello -jon From python at mrabarnett.plus.com Fri Feb 5 15:44:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Feb 2010 20:44:58 +0000 Subject: How to guard against bugs like this one? In-Reply-To: <7a9c25c21002051219v65760f7co276617dd6422952b@mail.gmail.com> References: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> <7a9c25c21002051219v65760f7co276617dd6422952b@mail.gmail.com> Message-ID: <4B6C834A.7020801@mrabarnett.plus.com> Stephen Hansen wrote: > On Fri, Feb 5, 2010 at 12:16 PM, John Nagle > wrote: > > kj wrote: > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. > > > The right answer to this is to make module search return an > error if two modules satisfy the search criteria. "First find" > isn't a good solution. > > > And thereby slowdown every single import and application startup time as > the common case of finding a module in one of the first couple entries > in sys.path now has to search it in every single item on that path. Its > not uncommon to have a LOT of things on sys.path. > > No thanks. "First Find" is good enough, especially with PEP328 and > absolute_import being on in Python 3 (and presumably 2.7). It doesn't > really help older Python versions unfortunately, but changing how import > works wouldn't help them anyways. Yeah, there might be two paths on > sys.path which both have a 'numbers.py' at the top level and First Find > might return the wrong one, but... people making poor decisions on code > organization and not using packages isn't something the language really > needs to fix. > You might want to write a script that looks through the search paths for duplicated names, especially ones which hide modules in the standard library. Has anyone done this already? From python at rcn.com Fri Feb 5 15:53:51 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Feb 2010 12:53:51 -0800 (PST) Subject: method to intercept string formatting % operations References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Message-ID: <649b3c62-f228-4fc1-9913-2dbe4d253788@k36g2000prb.googlegroups.com> On Feb 5, 6:57?am, bradallen wrote: > Hello, > > For container class derived from namedtuple, but which also behaves > like a dictionary by implementing __getitem__ for non-integer index > values, is there a special reserved method which allows intercepting % > string formatting operations? I would like for my container type to > behave appropriately depending on whether the string formatting > operation has a string like this : > > "whatever %s yadayada" % mycontainer ?# needs to act like a tuple > > "whatever %(key)s yadayada" % mycontainer ?# needs to act like a > dictionary The implementation for str.__mod__ refuses to treat tuples and tuple subclasses as a dictionary. Since namedtuples are a subclass of tuple, you're not going to have any luck with this one. To see actual C code, look at PyString_Format() in http://svn.python.org/view/python/trunk/Objects/stringobject.c?view=markup PyObject *dict = NULL; . . . if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) && !PyObject_TypeCheck(args, &PyBaseString_Type)) dict = args; Since automatic conversion is out, you can instead use the namedtuple._asdict() method for an explicit conversion: >>> from collections import namedtuple >>> Point = namedtuple('Point', 'x y') >>> p = Point(5, 12) >>> 'x: %(x)s' % p._asdict() 'x: 5' Raymond From robert.kern at gmail.com Fri Feb 5 16:03:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Feb 2010 15:03:15 -0600 Subject: Python and Ruby In-Reply-To: <4B6B5C72.8080100@stoneleaf.us> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <4B6B5C72.8080100@stoneleaf.us> Message-ID: On 2010-02-04 17:46 PM, Ethan Furman wrote: > Robert Kern wrote: >> On 2010-02-04 14:55 PM, Jonathan Gardner wrote: >>> On Feb 3, 3:39 pm, Steve Holden wrote: >>>> Robert Kern wrote: >>>>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >>>> >>>>>> I can explain all of Python in an hour; I doubt anyone will >>>>>> understand >>>>>> all of Python in an hour. >>>> >>>>> With all respect, talking about a subject without a reasonable >>>>> chance of >>>>> your audience understanding the subject afterwards is not explaining. >>>>> It's just exposition. >>>> >>>> I agree. If the audience doesn't understand then you haven't >>>> explained it. >>> >>> On the contrary, that explanation would have everything you need. It >>> would take an hour to read or listen to the explanation, but much more >>> than that time to truly understand everything that was said. >> >> Like I said, that's exposition, not explanation. There is an important >> distinction between the two words. Simply providing information is not >> explanation. If it takes four hours for your audience to understand >> it, then you explained it in four hours no matter when you stopped >> talking. > > And if it takes six months? Would you seriously say it took you six > months to explain something because it took that long for your audience > to understand it? > > At some point you have to make the transition from person A explaining > and person(s) B understanding -- they don't necessarily happen > synchronously. Then it's exposition and understanding, not explanation and understanding. -- 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 anthra.norell at bluewin.ch Fri Feb 5 16:09:55 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 05 Feb 2010 22:09:55 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: Message-ID: <4B6C8923.3090501@bluewin.ch> Duncan Booth wrote: > Anthra Norell wrote: > > >>> Using pythonw.exe will start the program with all error output dumped in >>> the bit bucket. Running from a command prompt with python.exe will at >>> least let you see if there are any errors. >>> >>> >> python.exe from the command line works all right in a DOS window. The >> problem must be with idle.pyw. I tried the old idle.pyw (2.4) with the >> new python.exe. (2.5) and that didn't work either. >> What is the bit bucket? If I had a clue, I could go from there. What >> puzzles me is that version 2.4 has been working fine and one wouldn't >> think that the changes from 2.4 to 2.5 would be so extensive as to cause >> a major malfunction. For the time being 2.4 works fine. I'd much prefer >> 2.5, though, because it includes the image library (PIL), whereas 2.4 >> cannot even use it. >> > > Bit bucket: http://en.wikipedia.org/wiki/Bit_bucket > > If you are seeing nothing at all when running it with python.exe instead of > pythonw.exe then something bizarre must be happening. > > My guess would have been that you had a problem importing something: e.g. > if Tkinter isn't installed properly then running Idle under pythonw.exe > would exit with an error message but you wouldn't see the error message. > However since you don't see an error message when running it with > python.exe it isn't that. > > Sorry, I'm out of ideas for now. > > No matter. I'll just keep working with 2.4. The machine is on its way out anyway. I have a brand new Dell Latitude E6500 without an operating system waiting to be set up with Linux. That'll take some time. Thank you for your suggestions. Frederic From bcb at undisclosedlocation.net Fri Feb 5 16:22:25 2010 From: bcb at undisclosedlocation.net (Bruce C. Baker) Date: Fri, 5 Feb 2010 15:22:25 -0600 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: "George Sakkis" wrote in message news:de06116c-e77c-47c4-982d-62b48bca5064 at j31g2000yqa.googlegroups.com... I'll give the benefit of doubt and assume you're joking rather than trolling. George ************************************************************* Not trolling, my friend! GvR got it right when he discarded the superfluous semicolons from the ends of statements--and then he ADDS superfluous colons to the ends of control statements? It will probably be as much of a shock to you as it was to me when I learned after studying parsing that colons, semicolons, "then"'s and "do"'s, etc., are simply noise tokens that serve no purpose except to clutter up the source. As for enforced indentation, back in the late 60's when I was a programming newbie I remember thinking how cool it would be to just indent the statements controlled by for loops (we didn't have none of them fancy while loops in FORTRAN back then! :-) ) Not too long after that I saw the havoc that a buggy editor could wreak on nicely-formatted source. :-( Formatting held hostage to a significant, invisible whitespace char? An inevitable accident waiting to happen! Not good, Guido; not good at all. That'll do for starters. :-) From aharrisreid at googlemail.com Fri Feb 5 16:26:20 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Fri, 05 Feb 2010 21:26:20 +0000 Subject: Editor for Python In-Reply-To: <4B6C5F45.8010200@shopzeus.com> References: <4B6C5F45.8010200@shopzeus.com> Message-ID: <4B6C8CFC.8020507@googlemail.com> Hi Laszlo, I use Wing IDE (not free, $35 for personal edition) and PyScripter (free). I find both good, for different reasons. Regards, Alan ------------------------------------------------------------------------ Laszlo Nagy wrote: > > Hi All, > > I know that this question was put up on this list a thousand times. I > know that most of the editors are listed here: > http://wiki.python.org/moin/PythonEditors > > I already tried most of them. But still, I need something that is not > listed there. Requirements: > > * starts and works fast > * has code folding, displays identation guides > * auto completion > * class browser > * source code browser (e.g. a list of definitions, when you click > it jumps to the definition > * integration with pychecker or pylint > * UTF-8 files > * free, or not-so-expensive > * works on linux and windows > > The one I'm using now is Geany. It does everything, except class > browser and pychecker/pylint. Now maybe, I can install (or write??) a > geany extension that would allow me to use pychecker. But I could not > find information on that. There where others I tried (PyPE, DrPython, > KomodoEdit, Editra etc.) but all of them failed for some reason. Can > you please suggest another editor that I could try? Or send me a link > that tells how to write or install pychecked plugin for Geany. > > Thanks, > > Laszlo > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Feb 5 16:39:46 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Feb 2010 13:39:46 -0800 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <4B6B5C72.8080100@stoneleaf.us> Message-ID: <4B6C9022.5050604@stoneleaf.us> Robert Kern wrote: > On 2010-02-04 17:46 PM, Ethan Furman wrote: >> Robert Kern wrote: >>> On 2010-02-04 14:55 PM, Jonathan Gardner wrote: >>>> On Feb 3, 3:39 pm, Steve Holden wrote: >>>>> Robert Kern wrote: >>>>>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >>>>> >>>>>>> I can explain all of Python in an hour; I doubt anyone will >>>>>>> understand >>>>>>> all of Python in an hour. >>>>> >>>>>> With all respect, talking about a subject without a reasonable >>>>>> chance of >>>>>> your audience understanding the subject afterwards is not explaining. >>>>>> It's just exposition. >>>>> >>>>> I agree. If the audience doesn't understand then you haven't >>>>> explained it. >>>> >>>> On the contrary, that explanation would have everything you need. It >>>> would take an hour to read or listen to the explanation, but much more >>>> than that time to truly understand everything that was said. >>> >>> Like I said, that's exposition, not explanation. There is an important >>> distinction between the two words. Simply providing information is not >>> explanation. If it takes four hours for your audience to understand >>> it, then you explained it in four hours no matter when you stopped >>> talking. >> >> And if it takes six months? Would you seriously say it took you six >> months to explain something because it took that long for your audience >> to understand it? >> >> At some point you have to make the transition from person A explaining >> and person(s) B understanding -- they don't necessarily happen >> synchronously. > > Then it's exposition and understanding, not explanation and understanding. > Hmm. Well, I can see your point -- after all, if are "explaining" but your audience is not understanding, are you really explaining? Okay, looking in the dictionary... ex?plain ?verb (used with object) 1. to make plain or clear; render understandable or intelligible: to explain an obscure point. 2. to make known in detail: to explain how to do something. un?der?stand ?verb (used with object) 1. to perceive the meaning of; grasp the idea of; comprehend: to understand Spanish; I didn't understand your question. 2. to be thoroughly familiar with; apprehend clearly the character, nature, or subtleties of: to understand a trade. 3. to assign a meaning to; interpret: He understood her suggestion as a complaint. 4. to grasp the significance, implications, or importance of: He does not understand responsibility. For me, at least, it boils down to this feeling that understanding is not a True/False item, but more of a scale (like all the the numbers between 0.0 and 1.0 [not including 1.0 of course -- this *is* Python! ;)]). As a personal example, decorators are not that difficult to grasp -- you take your function and wrap it in another function; but what you can do with them! They are truly impressive once your understanding deepens. And at the end of the day (or this thread, whichever comes first ;) Python is awesome, and that's what counts. ~Ethan~ From ethan at stoneleaf.us Fri Feb 5 16:48:22 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Feb 2010 13:48:22 -0800 Subject: How to guard against bugs like this one? In-Reply-To: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> References: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> Message-ID: <4B6C9226.2020606@stoneleaf.us> John Nagle wrote: > kj wrote: > ... >> >> Through a *lot* of trial an error I finally discovered that the >> root cause of the problem was the fact that, in the same directory >> as buggy.py, there is *another* innocuous little script, totally >> unrelated, whose name happens to be numbers.py. > > The right answer to this is to make module search return an > error if two modules satisfy the search criteria. "First find" > isn't a good solution. > > John Nagle Then what happens when you *want* to shadow a module? As MRAB suggests, if you are really concerned about it use a script that checks for duplicate modules (not a bad idea for debugging), but don't start throwing errors... next thing you know we won't be able to shadow classes, functions, or built-ins! !-) ~Ethan~ From wanderer at dialup4less.com Fri Feb 5 16:49:33 2010 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 5 Feb 2010 13:49:33 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: On Feb 5, 3:26?pm, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > > Which is the more accepted way to compose method names nounVerb or > > verbNoun? > > > For example voltageGet or getVoltage? getVoltage sounds more normal, > > but voltageGet is more like voltage.Get. I seem to mix them and I > > should probably pick one way and stick with it. > > Use properties[1] and just call it `voltage`. Python is not Java [2]; > explicit getters/setters are unpythonic. > > [1]http://docs.python.org/library/functions.html#property > [2]http://dirtsimple.org/2004/12/python-is-not-java.html > > Cheers, > Chris > --http://blog.rebertia.com Maybe I'm not using Get right either. I'm wrapping functions. def AbbeGet(self, Lens): """ Get the Abbe Number V for the material where V = (Nd - 1)/(Nf - Nc) where the Index of Refractions are Nd at the Fraunhofer D line 0.5892um Nf at the Fraunhofer F line 0.4861um Nc at the Fraunhofer C line 0.6563um """ Nd = Lens.Mat.NtGet(0.5892) Nf = Lens.Mat.NtGet(0.4861) Nc = Lens.Mat.NtGet(0.6563) if (Nf - Nc) != 0: V = (Nd - 1)/(Nf - Nc) else: V = 1e6 return V # end AbbeGet From alfps at start.no Fri Feb 5 16:53:16 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Feb 2010 22:53:16 +0100 Subject: method names nounVerb or verbNoun In-Reply-To: References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: * Wanderer: > On Feb 5, 3:26 pm, Chris Rebert wrote: >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: >>> Which is the more accepted way to compose method names nounVerb or >>> verbNoun? >>> For example voltageGet or getVoltage? getVoltage sounds more normal, >>> but voltageGet is more like voltage.Get. I seem to mix them and I >>> should probably pick one way and stick with it. >> Use properties[1] and just call it `voltage`. Python is not Java [2]; >> explicit getters/setters are unpythonic. >> >> [1]http://docs.python.org/library/functions.html#property >> [2]http://dirtsimple.org/2004/12/python-is-not-java.html >> >> Cheers, >> Chris >> --http://blog.rebertia.com > > Maybe I'm not using Get right either. I'm wrapping functions. > > def AbbeGet(self, Lens): > """ > Get the Abbe Number V for the material > where > V = (Nd - 1)/(Nf - Nc) > where the Index of Refractions are > Nd at the Fraunhofer D line 0.5892um > Nf at the Fraunhofer F line 0.4861um > Nc at the Fraunhofer C line 0.6563um > """ > > Nd = Lens.Mat.NtGet(0.5892) > Nf = Lens.Mat.NtGet(0.4861) > Nc = Lens.Mat.NtGet(0.6563) > > if (Nf - Nc) != 0: > V = (Nd - 1)/(Nf - Nc) > else: > V = 1e6 > > return V > > # end AbbeGet Consider this piece of code: x = 2*sin( angle ) versus this: x = 2*get_sin( angle ) or this: x = 2*sin_get( angle ) Cheers & hth., - Alf From clp2 at rebertia.com Fri Feb 5 16:53:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Feb 2010 13:53:57 -0800 Subject: method names nounVerb or verbNoun In-Reply-To: References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <50697b2c1002051353o5031b76el6f6f0fcd540bbf64@mail.gmail.com> On Fri, Feb 5, 2010 at 1:49 PM, Wanderer wrote: > On Feb 5, 3:26?pm, Chris Rebert wrote: >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: >> > Which is the more accepted way to compose method names nounVerb or >> > verbNoun? >> >> > For example voltageGet or getVoltage? getVoltage sounds more normal, >> > but voltageGet is more like voltage.Get. I seem to mix them and I >> > should probably pick one way and stick with it. >> >> Use properties[1] and just call it `voltage`. Python is not Java [2]; >> explicit getters/setters are unpythonic. >> >> [1]http://docs.python.org/library/functions.html#property > > Maybe I'm not using Get right either. I'm wrapping functions. > > ? ?def AbbeGet(self, Lens): > ? ? ? ?""" > ? ? ? ?Get the Abbe Number V for the material > ? ? ? ?where > ? ? ? ?V = (Nd - 1)/(Nf - Nc) > ? ? ? ?where the Index of Refractions are > ? ? ? ?Nd at the Fraunhofer D line 0.5892um > ? ? ? ?Nf at the Fraunhofer F line 0.4861um > ? ? ? ?Nc at the Fraunhofer C line 0.6563um > ? ? ? ?""" > > ? ? ? ?Nd = Lens.Mat.NtGet(0.5892) > ? ? ? ?Nf = Lens.Mat.NtGet(0.4861) > ? ? ? ?Nc = Lens.Mat.NtGet(0.6563) > > ? ? ? ?if (Nf - Nc) != 0: > ? ? ? ? ? ?V = (Nd - 1)/(Nf - Nc) > ? ? ? ?else: > ? ? ? ? ? ?V = 1e6 > > ? ? ? ?return V This isn't even really a method; you don't refer to "self" in the body at all. Why isn't it just a function? Cheers, Chris -- http://blog.rebertia.com From cmpython at gmail.com Fri Feb 5 16:56:29 2010 From: cmpython at gmail.com (CM) Date: Fri, 5 Feb 2010 13:56:29 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <65c717dd-826d-4e8e-8dd3-8a0a90df7b86@o26g2000vbd.googlegroups.com> > GvR got it right when he discarded the superfluous semicolons from the ends > of statements--and then he ADDS superfluous colons to the ends of control > statements? It will probably be as much of a shock to you as it was to me > when I learned after studying parsing that colons, semicolons, "then"'s and > "do"'s, etc., ?are simply noise tokens that serve no purpose except to > clutter up the source. Some argue that the colon is a useful visual cue that aids in readability and that "explicit is better than implicit". I think one can feel either way about it. For my part, I prefer to have colons at that point, because it serves as a mental primer that a certain type of block follows. Semi-colons at the end of statements don't seem to provide any mental priming for me that can't better be served by a line break. > As for enforced indentation, back in the late 60's when I was a programming > newbie I remember thinking how cool it would be to just indent the > statements controlled by for loops (we didn't have none of them fancy while > loops in FORTRAN back then! :-) ) ?Not too long after that I saw the havoc > that a buggy editor could wreak on nicely-formatted source. :-( Formatting > held hostage to a significant, invisible whitespace char? An inevitable > accident waiting to happen! Not good, Guido; not good at all. First, why would you tolerate a buggy editor? I've had my share of challenges in learning Python, but indentation problems would be about 403rd down on the list. A simple indentation error is shown in my editor that immediately gets fixed. No havoc at all. And I also know that every piece of Python code I ever get from others *has* to be readable (at least in terms of the very visually helpful indented blocks). Che Che > > That'll do for starters. :-) From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:02:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:02:42 GMT Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> Message-ID: <037c81ba$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 09:22:03 -0500, Lou Pecora wrote: [...] >> > That's what I needed. 3 lines to write or read a inhomogeneous >> > collection of variables. >> >> Easy, but also quick and dirty -- good enough for small scripts, but >> not really good enough for production applications. [...] > I understand where you are coming from: Production Code. I was just > making a point about Python and my code is only used by me. I can edit > the file for the simple I/O I do. I am not recommending this way for > everyone. Just an example. We're in violent agreement then :) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:19:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:19:11 GMT Subject: which References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: <037c8597$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 16:52:19 +0100, mk wrote: > assert isinstance(cmd, basestring) or cmd is None, "cmd should be string > or None" Do not use assertions for input validation. That's not what they're for. assert is compiled away when you run your code with the -O switch, which means that the test may never be made at all. You should limit assertions for testing "this can never happen" situations, verifying pre- and post- conditions, checking the internal logic of your code, and similar. See also: http://nedbatchelder.com/text/assert.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:19:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:19:31 GMT Subject: method to intercept string formatting % operations References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Message-ID: <037c85ab$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 16:49:00 +0100, Jean-Michel Pichavant wrote: > Anyway why would you want to use the tuple form ? it's beaten in every > aspect by the dictionary form. Except convenience, efficiency and readability. "%s %s" % (1, 2) versus "%(a)s %(b)s" % {'a': 1, 'b': 2} I'm all in favour of the second form when you need it. But you certainly don't need it all time. -- Steven From phlip2005 at gmail.com Fri Feb 5 17:19:36 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 5 Feb 2010 14:19:36 -0800 (PST) Subject: reconstruct the source of a lambda from its func_code, func_name, etc Message-ID: <03a5232b-fdcb-48f9-926e-bdd6e2e4b638@l24g2000prh.googlegroups.com> Thy Pon: Has anyone figured out how to reflect a passed function, such as a lambda, all the way back to its source? I am aware than func_code knows the file name and line number; I would rather not use them to read the file because the lambda might not start in the first column. I will go with this option until someone suggests a better fix! -- Phlip http://penbird.tumblr.com/ From news123 at free.fr Fri Feb 5 17:20:58 2010 From: news123 at free.fr (News123) Date: Fri, 05 Feb 2010 23:20:58 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Message-ID: <4b6c99ca$0$5907$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: > >> I wrote a small xmlrpc client on Windows 7 with python 2.6 >> >> srv = xmlrpclib.Server('http://localhost:80') >> >> I was able to perform about 1 rpc call per second >> >> After changing to >> srv = xmlrpclib.Server('http://127.0.0.1:80') >> >> I was able to perform about 10 to 16 rpc calls per second. > > Not necesarily. There is another difference: 127.0.0.1 is an IPv4 > address, localhost maps to both IPv4 and IPv6 addresses (::1) > > I vaguely remember a problem with that - IPv6 is tried first, doesn't > work, only then IPv4, and that slows down the whole process. > Try disabling completely the IPv6 stack, if you don't need it. How can I completely disable IP6. I went to my network device and disabled IPV6 under properties. The XMRPC calls were stull slow. bye N From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:21:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:21:05 GMT Subject: which References: Message-ID: <037c8609$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 15:21:05 +0100, mk wrote: > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) Whichever one you like. The differences are insignificance, and essentially boil down to personal preference. -- Steven From wanderer at dialup4less.com Fri Feb 5 17:21:55 2010 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 5 Feb 2010 14:21:55 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <36952f27-c825-4ab8-bd2e-7dff097075fd@d30g2000vbl.googlegroups.com> On Feb 5, 4:53?pm, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 1:49 PM, Wanderer wrote: > > On Feb 5, 3:26?pm, Chris Rebert wrote: > >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > >> > Which is the more accepted way to compose method names nounVerb or > >> > verbNoun? > > >> > For example voltageGet or getVoltage? getVoltage sounds more normal, > >> > but voltageGet is more like voltage.Get. I seem to mix them and I > >> > should probably pick one way and stick with it. > > >> Use properties[1] and just call it `voltage`. Python is not Java [2]; > >> explicit getters/setters are unpythonic. > > >> [1]http://docs.python.org/library/functions.html#property > > > Maybe I'm not using Get right either. I'm wrapping functions. > > > ? ?def AbbeGet(self, Lens): > > ? ? ? ?""" > > ? ? ? ?Get the Abbe Number V for the material > > ? ? ? ?where > > ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > ? ? ? ?where the Index of Refractions are > > ? ? ? ?Nd at the Fraunhofer D line 0.5892um > > ? ? ? ?Nf at the Fraunhofer F line 0.4861um > > ? ? ? ?Nc at the Fraunhofer C line 0.6563um > > ? ? ? ?""" > > > ? ? ? ?Nd = Lens.Mat.NtGet(0.5892) > > ? ? ? ?Nf = Lens.Mat.NtGet(0.4861) > > ? ? ? ?Nc = Lens.Mat.NtGet(0.6563) > > > ? ? ? ?if (Nf - Nc) != 0: > > ? ? ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > ? ? ? ?else: > > ? ? ? ? ? ?V = 1e6 > > > ? ? ? ?return V > > This isn't even really a method; you don't refer to "self" in the body > at all. Why isn't it just a function? > > Cheers, > Chris > --http://blog.rebertia.com Okay, I guess it should be a function called abbe() instead of a method called AbbeGet(). That should solve the problem of trying to remember whether I called it GetAbbe or AbbeGet. Thanks From bartc at freeuk.com Fri Feb 5 17:22:39 2010 From: bartc at freeuk.com (bartc) Date: Fri, 05 Feb 2010 22:22:39 GMT Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: "Steve Holden" wrote in message news:mailman.1998.1265399766.28905.python-list at python.org... > Arnaud Delobelle wrote: >> Robert Kern writes: >> >>> I prefer Guido's formulation (which, naturally, I can't find a direct >>> quote for right now): if you expect that a boolean argument is only >>> going to take *literal* True or False, then it should be split into >>> two functions. >> >> So rather than three boolean arguments, would you have eight functions? >> > If there's genuinely a need for that functionality, yes. So you want a function such as drawtext(s, bold=true, italic=false, underline=true) to be split into: drawtext(s) drawtextb(s) drawtexti(s) drawtextu(s) drawtextbi(s) drawtextbu(s) drawtextiu(s) drawtextbiu(s) Which of course is going to be fun if the bold/italic/underline values are not constants; instead of writing: drawtext(s,b,i,u) you have to say: if b==0 and i==0 and u==0: drawtext(s) elif b==1 and i==0 and u==0: drawtextb(s) and so on. With half-a-dozen or more booleans, this becomes completely impractical. -- Bartc From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:26:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:26:03 GMT Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: <037c8733$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 09:53:33 -0600, David Thole wrote: > I read this....and am a tiny bit confused about the actual problem. > > It's not exactly complex to realize that something like: a = b = array > that a and b both point to the array. > > Logically speaking, I'm not sure how one could assume that the same > assignment would yield a and b point to the same duplicate array. It's an easy mistake to make, if you don't understand Python's object model: >>> a = b = 2 >>> a += 1 >>> a, b (3, 2) >>> a = b = [2] >>> a[0] += 1 >>> a, b ([3], [3]) For the non-Python coders reading, the difference is that ints are immutable, and hence a += 1 assigns a to a new int, leaving b untouched, but lists are mutable, hence a[0] += 1 mutates the list which both a and b refer to. This is a Good Thing, but it is one of the things which give newcomers some trouble. -- Steven From news123 at free.fr Fri Feb 5 17:26:48 2010 From: news123 at free.fr (News123) Date: Fri, 05 Feb 2010 23:26:48 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> Message-ID: <4b6c9b28$0$10494$426a74cc@news.free.fr> Hi JM, Jean-Michel Pichavant wrote: >> Gabriel Genellina wrote: >> >>> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >>> >>> >>>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>>> >>>> srv = xmlrpclib.Server('http://localhost:80') >>>> >>>> I was able to perform about 1 rpc call per second >>>> >>>> >>>> After changing to >>>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>>> >>>> I was able to perform about 10 to 16 rpc calls per second. >>>> > > Or you can simply use an explicit external address. Most of the time > xmlRPC server/clients are used between distant machines. > If your are using localhost for test purpose, then binding your server > on its external IP instead of the local one could solve your problem > (wihtout removing the IPV6 stack). > > import socket > > # server > server = SimpleXMLRPCServer((socket.gethostname(), 5000), > logRequests=False, allow_none=True) > > > # client > xmlrpclib.ServerProxy("http://%s.yourdomain.com:%s" % > (socket.gethostname(), 5000)) Well This was exactly my question. for virtual web servers I cannot just use the IP-address. some XMLRPC servers do need the histname within the HTTP-POST request. if I just replaced the hostname with the IP addres, then certain servers would not be accessable. I had to use the IP-address for connecteing, but to pass the hostname in the HTTP-POST request. I wondered how to convince puthon's SimpleXMLRPCServer (or any other standard python xmlrpc server), such, that I can obtain above mentioned goal. bye N > PS : just wondering if using the port 80 is legal If nothing else on the host runs on port 80 the answer is yes. From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:31:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:31:32 GMT Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <037c887c$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 11:53:08 -0800, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, +0.5 for getVoltage +1 get_voltage -1 for voltageGet or voltage_get > but > voltageGet is more like voltage.Get. According to PEP 8, the style guide for the standard library, method names should use lowercase initial letter, so you should have voltage.get. Following PEP 8 isn't compulsory, but it is recommended unless you want a bunch of busy-body coders telling you you need to follow PEP 8 :) > I seem to mix them and I should > probably pick one way and stick with it. Yes. -- Steven From nobody at nowhere.com Fri Feb 5 17:41:22 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Feb 2010 22:41:22 +0000 Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> Message-ID: On Fri, 05 Feb 2010 03:57:17 -0800, Ashok Prabhu wrote: > I very badly need this to work. I have been googling out for a week > with no significant solution. I open a process p1 which does keeps > running for 4+ hours. It gives some output in stdout now and then. I > open this process with subprocess.Popen and redirect the stdout to > PIPE. However when I read the output with readline it blocks waiting > forever. I need to read from p1.stdout till what it has in the PIPE. > Can someone help me out with the exact code change that can accomplish > the task. > > from subprocess import * > > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > while 1: > line=p1.stdout.readline() > print line The answer is essentially the same one I gave in response to your post entitled "read a process output with subprocess.Popen" yesterday. You need to persuade the command to line-buffer its output rather than block-buffering it. If the command insists on block-buffering, you're out of luck; there's no way that Python can force it to do otherwise. You might be able to persuade the command to use line-buffering by using a pty rather than a pipe for its stdout, although that depends upon os.openpty() being available on your platform (the documentation only says "Availability: some flavors of Unix"). From g.statkute at gmail.com Fri Feb 5 17:42:23 2010 From: g.statkute at gmail.com (gintare statkute) Date: Sat, 6 Feb 2010 00:42:23 +0200 Subject: execute sqlite3 dot commands in python Message-ID: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Does anybody know if it possible to execute sqlite3 dot commands in python? dovanotas:/pages/links# python Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> sqlite3 .help Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'help' >>> the same with other commands: .databases .tables http://www.sqlite.org/sqlite.html regards, gintare From robert.kern at gmail.com Fri Feb 5 17:45:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Feb 2010 16:45:38 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-05 16:22 PM, bartc wrote: > > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) > > Which of course is going to be fun if the bold/italic/underline values > are not constants; instead of writing: > > drawtext(s,b,i,u) > > you have to say: > > if b==0 and i==0 and u==0: > drawtext(s) > elif b==1 and i==0 and u==0: > drawtextb(s) > > and so on. With half-a-dozen or more booleans, this becomes completely > impractical. Then you refactor to drawtext(s, font) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:45:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:45:51 GMT Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <037c8bd7$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 12:26:38 -0800, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 11:53 AM, Wanderer > wrote: >> Which is the more accepted way to compose method names nounVerb or >> verbNoun? >> >> For example voltageGet or getVoltage? getVoltage sounds more normal, >> but voltageGet is more like voltage.Get. I seem to mix them and I >> should probably pick one way and stick with it. > > Use properties[1] and just call it `voltage`. Python is not Java [2]; > explicit getters/setters are unpythonic. But sometimes you still need methods or functions of the form verb_noun. For instance, if getting or setting the voltage is an expensive operation, you don't want to fool the user into thinking it is a cheap attribute access. Or get_voltage might be a stand-alone function rather than a method. Or the getter might allow additional arguments. The admonition to avoid getters and setters isn't meant to prohibit *any* method which has a get/set in the name (whether implicit or explicit). It's meant as an antidote to the Java idiom of making *every* attribute private and accessing them via getters/setters, even when all they do is merely get/set the contents of the attribute. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:48:37 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:48:37 GMT Subject: reconstruct the source of a lambda from its func_code, func_name, etc References: <03a5232b-fdcb-48f9-926e-bdd6e2e4b638@l24g2000prh.googlegroups.com> Message-ID: <037c8c7d$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 14:19:36 -0800, Phlip wrote: > Thy Pon: > > Has anyone figured out how to reflect a passed function, such as a > lambda, all the way back to its source? Use the dis module to disassemble the byte code to human readable form, then write some sort of decompiler to translate it back to Python. The second half is the difficult part... -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:52:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:52:24 GMT Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: <037c8d60$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: > Ethan Furman wrote: > >> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ choose_python.pdf >> >> > Choose to get your difficult questions about threads in Python ignored. > Oh well.. With an attitude like that, you're damn lucky if you don't get kill- filed. It was SIX MINUTES since you posted your question about timers, what did you expect? Threads are hard, and many people don't use them at all. You might never get an answer, even without alienating people. Complaining after six DAYS might be acceptable, if you do it with a sense of humour, but after six minutes? Advice on public forums is free, but it doesn't come with an guaranteed response time. If you want a Service Level Agreement, you will need to pay somebody for it. -- Steven From steve at holdenweb.com Fri Feb 5 17:54:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 17:54:52 -0500 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6c99ca$0$5907$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6c99ca$0$5907$426a74cc@news.free.fr> Message-ID: <4B6CA1BC.3060401@holdenweb.com> News123 wrote: > Hi Gabriel, > > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >> >>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>> >>> srv = xmlrpclib.Server('http://localhost:80') >>> >>> I was able to perform about 1 rpc call per second >>> >>> After changing to >>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>> >>> I was able to perform about 10 to 16 rpc calls per second. >> Not necesarily. There is another difference: 127.0.0.1 is an IPv4 >> address, localhost maps to both IPv4 and IPv6 addresses (::1) >> >> I vaguely remember a problem with that - IPv6 is tried first, doesn't >> work, only then IPv4, and that slows down the whole process. >> Try disabling completely the IPv6 stack, if you don't need it. > > > > How can I completely disable IP6. > > I went to my network device and disabled IPV6 under properties. The > XMRPC calls were stull slow. > There's not a lot of point taking actions like disabling IPv6 until you actually know what the cause of the problem is (though I suppose a few likely-sounding actions are worth taking if they don't require much effort). Sounds to me like you need to get WireShark or some similar protocol analyzer on the network and determine what traffic is passing across the network. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 5 17:54:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 17:54:52 -0500 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6c99ca$0$5907$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6c99ca$0$5907$426a74cc@news.free.fr> Message-ID: <4B6CA1BC.3060401@holdenweb.com> News123 wrote: > Hi Gabriel, > > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >> >>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>> >>> srv = xmlrpclib.Server('http://localhost:80') >>> >>> I was able to perform about 1 rpc call per second >>> >>> After changing to >>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>> >>> I was able to perform about 10 to 16 rpc calls per second. >> Not necesarily. There is another difference: 127.0.0.1 is an IPv4 >> address, localhost maps to both IPv4 and IPv6 addresses (::1) >> >> I vaguely remember a problem with that - IPv6 is tried first, doesn't >> work, only then IPv4, and that slows down the whole process. >> Try disabling completely the IPv6 stack, if you don't need it. > > > > How can I completely disable IP6. > > I went to my network device and disabled IPV6 under properties. The > XMRPC calls were stull slow. > There's not a lot of point taking actions like disabling IPv6 until you actually know what the cause of the problem is (though I suppose a few likely-sounding actions are worth taking if they don't require much effort). Sounds to me like you need to get WireShark or some similar protocol analyzer on the network and determine what traffic is passing across the network. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 18:01:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 23:01:46 GMT Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <037c8f92$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 15:22:25 -0600, Bruce C. Baker wrote: > GvR got it right when he discarded the superfluous semicolons from the > ends of statements--and then he ADDS superfluous colons to the ends of > control statements? They're not superfluous, they have a real, practical use. > It will probably be as much of a shock to you as it > was to me when I learned after studying parsing that colons, semicolons, > "then"'s and "do"'s, etc., are simply noise tokens that serve no > purpose except to clutter up the source. Incorrect, they do have a use. Hint: source code isn't just read by parsers. > As for enforced indentation, back in the late 60's when I was a > programming newbie I remember thinking how cool it would be to just > indent the statements controlled by for loops (we didn't have none of > them fancy while loops in FORTRAN back then! :-) ) Not too long after > that I saw the havoc that a buggy editor could wreak on nicely-formatted > source. :-( As opposed to how resistant source code is to buggy editors that make other changes to source code. If your editor flips the order of characters, or turns the digit "4" into "7", or deletes braces, or inserts "#" characters at the start of lines, you would dump the editor in a second. But if the editor inserts or removes whitespace, we're supposed to continue using the editor and change the language? > Formatting held hostage to a significant, invisible > whitespace char? It's not invisible. You can see it by noticing the space between the left margin and the start of non-whitespace text. Can you see the difference between these? hello world hello world Of course you can, unless your News reader or mail client is buggy. If it is deleting whitespace at the start of lines, how can you trust it not to delete anything else? Trailing spaces and tabs, on the other hand, *are* invisible. But they're also insignificant, and so don't matter. (Except for one little tiny corner case, which I shall leave as an exercise for the advanced reader.) -- Steven From news123 at free.fr Fri Feb 5 18:03:51 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 00:03:51 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows Message-ID: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Hi, I'm using an XMLRPC server under Windows. What I wonder is how I could create a server, that can be killed with CTRL-C The server aborts easily with CTRL-BREAK but not with CTRL-C (under Windows) If I press CTRL-C it will only abort when the next RPC call occurs. It seems it is blocking in the select() call in the handle_request() function. Is there any trick, which I overlook? thanks in advance for ideas and bye N From aahz at pythoncraft.com Fri Feb 5 18:08:08 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2010 15:08:08 -0800 Subject: SQLite3: preventing new file creation References: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> Message-ID: In article <6cf467a9-99d7-4fda-99da-075b4b38e3e0 at k6g2000prg.googlegroups.com>, Gnarlodious wrote: > >Every time I say something like: > >connection=sqlite3.connect(file) > >sqlite creates a new database file. Can this behavior be suppressed >through SQLite? Or am I forced to check for the file existing first? Check first -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at holdenweb.com Fri Feb 5 18:11:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 18:11:04 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: bartc wrote: > > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) > The case I was discussing was where the function was required to implement significantly different logic flow for the two different values of the Boolean. > Which of course is going to be fun if the bold/italic/underline values > are not constants; instead of writing: > > drawtext(s,b,i,u) > > you have to say: > > if b==0 and i==0 and u==0: > drawtext(s) > elif b==1 and i==0 and u==0: > drawtextb(s) > > and so on. With half-a-dozen or more booleans, this becomes completely > impractical. > It's completely impractical the way you've written it anyway, since the drawtext function shouldn't be required to know whether it's printing bold, italic, etc. - those properties should be attributes of the font. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 5 18:19:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 18:19:09 -0500 Subject: execute sqlite3 dot commands in python In-Reply-To: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: gintare statkute wrote: > Does anybody know if it possible to execute sqlite3 dot commands in python? > > dovanotas:/pages/links# python > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sqlite3 >>>> sqlite3 .help > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'help' > > the same with other commands: > .databases > .tables > http://www.sqlite.org/sqlite.html > No. That's not how you pass commands to sqlite3 - you connect to a database, create a cursor on the connection, and then execute SQL statements (not sqlite commands) on the cursor. Like this: >>> import sqlite3 >>> c = sqlite3.connect("deleteme") >>> cu = c.cursor() >>> cu.execute(".help") Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: near ".": syntax error >>> cu.execute("""\ ... CREATE TABLE test( ... a int primary key, ... b varchar)""") >>> As you can see, the cursor's execute() method expects SQL statements. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 18:29:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 23:29:10 GMT Subject: Dreaming of new generation IDE References: Message-ID: <037c95fe$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 22:22:39 +0000, bartc wrote: > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight >>> functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) No, of course not. But one might prefer a function with an alternate API, such as: style = TextStyle(bold=True, underline=True, size=12, font='helvetica') drawtext(s, style) style.italic = True drawtext(s, style) Other alternatives might be to pass the style information as a string "BU" (bold underline) or a numeric flag (BOLD & UNDERLINE). In general, if your implementation looks like this: def function(args, flag): if flag: do_this() else: do_that() then this is a good candidate for splitting into multiple functions. Likewise: def function(args, flag): result = do_this() if flag: result = modify(result) return result or similar. The point is that such a function uses the flag to select between two different semantics. From a API perspective, it is generally better to make each behaviour an independent function (perhaps calling a third, private, function implementing any common behaviour). For example, instead of: def extreme(sequence, biggest=True): """Return the extreme value from sequence. If biggest is a true value, return the maximum value, otherwise return the smallest. """ pass # implementation left as an exercise have two functions, max and min. -- Steven From clp2 at rebertia.com Fri Feb 5 18:36:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Feb 2010 15:36:19 -0800 Subject: method names nounVerb or verbNoun In-Reply-To: <037c8bd7$0$1292$c3e8da3@news.astraweb.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> <037c8bd7$0$1292$c3e8da3@news.astraweb.com> Message-ID: <50697b2c1002051536u4f29be9laac873fcd212a7b9@mail.gmail.com> On Fri, Feb 5, 2010 at 2:45 PM, Steven D'Aprano wrote: > On Fri, 05 Feb 2010 12:26:38 -0800, Chris Rebert wrote: >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer >> wrote: >>> Which is the more accepted way to compose method names nounVerb or >>> verbNoun? >>> >>> For example voltageGet or getVoltage? getVoltage sounds more normal, >>> but voltageGet is more like voltage.Get. I seem to mix them and I >>> should probably pick one way and stick with it. >> >> Use properties[1] and just call it `voltage`. Python is not Java [2]; >> explicit getters/setters are unpythonic. > > But sometimes you still need methods or functions of the form verb_noun. True, but when the verb is "get" and you're using Python, your design probably merits another going-over. If the OP hadn't used "get" as their example, I would have answered significantly differently. > For instance, if getting or setting the voltage is an expensive > operation, you don't want to fool the user into thinking it is a cheap > attribute access. I strongly disagree with this rationale as it violates the Uniform Access Principle (http://en.wikipedia.org/wiki/Uniform_access_principle). Though I concede Python's builtins don't adhere to the UAP. > Or get_voltage might be a stand-alone function rather > than a method. The OP originally said quite explicitly it was a method in their original post. (Though they since wisely changed their code structure so it's not.) > Or the getter might allow additional arguments. True; but before the OP posted the actual function body, there was no way to know whether it did. Lacking such info, I assumed the simplest and most frequent case, namely that it didn't take any args. > The admonition to avoid getters and setters isn't meant to prohibit *any* > method which has a get/set in the name (whether implicit or explicit). > It's meant as an antidote to the Java idiom of making *every* attribute > private and accessing them via getters/setters, even when all they do is > merely get/set the contents of the attribute. True. Again, before the OP posted the method body, there was no way to know it wasn't a trivial Java-esque getter. Cheers, Chris -- http://blog.rebertia.com From jackdied at gmail.com Fri Feb 5 18:43:13 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 5 Feb 2010 18:43:13 -0500 Subject: list.extend([]) Question In-Reply-To: <5d1a32001002050831r6233b751mcbc5f55fb9a2c1b4@mail.gmail.com> References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> <5d1a32001002050831r6233b751mcbc5f55fb9a2c1b4@mail.gmail.com> Message-ID: On Fri, Feb 5, 2010 at 11:31 AM, Gerald Britton wrote: > I think it's because when you do ['a'].extend([]) or whatever, the > result is whatever the method "extend" returns. ?But "extend" has no > return value, hence you will see None if you do this interactively. > That sums it up. In Python the convention is to raise an exception on error, return a new value in the case where a new value is created, and - as in this case - to return None for modification of an existing value. Returning "None" is vexing if you are used to another language that has a different convention but is expected for well behaved python libraries. So yeah, Python does it that way because the intent is to loudly and regularly announce that something was modified or to loudly and regularly announce that something new was /not/ created. It's a boring story with no whiz-bang feature behind it, but I like that the language behaves that way for exactly that reason. -Jack From python.list at tim.thechases.com Fri Feb 5 19:00:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Feb 2010 18:00:44 -0600 Subject: Your beloved python features In-Reply-To: <037c8f92$0$1292$c3e8da3@news.astraweb.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <037c8f92$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B6CB12C.4020705@tim.thechases.com> Steven D'Aprano wrote: > Trailing spaces and tabs, on the other hand, *are* invisible. But they're > also insignificant, and so don't matter. > > (Except for one little tiny corner case, which I shall leave as an > exercise for the advanced reader.) Drat, now I'm gonna be up at odd hours tonight dredging my brain for such corner cases. My catalog so far: - triple-quoted multi-line strings - "\" line-continuations don't work with trailing whitespace (though Vim's syntax highlighting flags them, changing their color if there's whitespace afterwards) - files that read themselves (or perhaps depend on introspection/debugging modules to read themselves) Any others that I missed? -tkc From mentifex at myuw.net Fri Feb 5 19:02:53 2010 From: mentifex at myuw.net (Forthminder) Date: Fri, 5 Feb 2010 16:02:53 -0800 (PST) Subject: Google AI Challenge at U of Waterloo Message-ID: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Contest runs from 4 February to 26 February 2010. You may choose a programming language, such as Java, C++, Python, Ruby or Haskell. See details at http://csclub.uwaterloo.ca/contest/problem_description.php Bonne Chance! Mentifex -- http://www.scn.org/~mentifex/mindforth.txt From wgaggioli at gmail.com Fri Feb 5 19:08:06 2010 From: wgaggioli at gmail.com (William Gaggioli) Date: Fri, 5 Feb 2010 19:08:06 -0500 Subject: Calendar GUI Message-ID: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> Hello Everyone, I'm working on setting up some software for a Peruvian non-profit to help them organize their incoming volunteers. One of the features I'd like to add is a calendar-like view of the different volunteers arrival dates and staying time, with potentially some other info through some double-click action. Rather than writing a calendar gui myself, is there some open-source calendar program you guys could recommend that I could plug into? It has to be run locally, as the internet isn't so reliable down here, but other than that something simple and clean is ideal. Thanks, Will -------------- next part -------------- An HTML attachment was scrubbed... URL: From gabriel at opensuse.org Fri Feb 5 19:14:33 2010 From: gabriel at opensuse.org (Gabriel) Date: Fri, 5 Feb 2010 21:14:33 -0300 Subject: Calendar GUI In-Reply-To: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> Message-ID: <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: > Hello Everyone, > > I'm working on setting up some software for a Peruvian non-profit to help > them organize their incoming volunteers. One of the features I'd like to add > is a calendar-like view of the different volunteers arrival dates and > staying time, with potentially some other info through some double-click > action. Rather than writing a calendar gui myself, is there some open-source > calendar program you guys could recommend that I could plug into? It has to > be run locally, as the internet isn't so reliable down here, but other than > that something simple and clean is ideal. > I wrote a gtk gui for google calendar. Maybe you can adapt it to your needs. http://code.google.com/p/googlecalendar-gtk/ -- Kind Regards From imuaplease at gmail.com Fri Feb 5 19:24:56 2010 From: imuaplease at gmail.com (**Group User**) Date: Fri, 5 Feb 2010 16:24:56 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <1eed1fcc-f1d1-4f71-bc05-68dddb3f17b4@s33g2000prm.googlegroups.com> On Feb 6, 7:02?am, Forthminder wrote: > Contest runs from 4 February to 26 February 2010. > > You may choose a programming language, such as > Java, C++, Python, Ruby or Haskell. > > See details at > > http://csclub.uwaterloo.ca/contest/problem_description.php > > Bonne Chance! > > Mentifex > --http://www.scn.org/~mentifex/mindforth.txt I find out that I was a donkie I was hooked up Torn Screwed up And Haskel was there at that time He got anrgy, pity For my stupidity All for best Simulation for good alone KKKKKKIIIIIIIIIIEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEENNNNNNNNNNNNNNNNNNNNNNIIEEEE From charles at declaresub.com Fri Feb 5 19:27:55 2010 From: charles at declaresub.com (Charles Yeomans) Date: Fri, 5 Feb 2010 19:27:55 -0500 Subject: Exception class documentation In-Reply-To: <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> Message-ID: <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> On Feb 5, 2010, at 2:13 PM, Gerald Britton wrote: > On Fri, Feb 5, 2010 at 12:55 PM, Charles Yeomans > wrote: >> I am so far unable to find the information I want about the >> Exception class. >> Information like the signature of __init__ seems to be >> unavailable. Any >> suggestions where I might find such information? >> > > Though not documented, some silly tests indicate that it will accept > pretty much anything: > >>>> Exception(1,2,4,54) > Exception(1, 2, 4, 54) >>>> Exception(*range(10)) > Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>>> Exception(*range(50)) > Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, > 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, > 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49) >>>> Exception('a','b','c','d','e') > Exception('a', 'b', 'c', 'd', 'e') >>>> Exception(Exception(1)) > Exception(Exception(1,),) I had also tried such tests. If you pass a single argument msg, it is assigned to the message property, and the args property is set to (msg,). If you pass more than one argument, the tuple of arguments is assigned to the args property, and nothing is assigned to the message property. I was hoping to at least find source code that provides a definitive answer. Charles Yeomans From news123 at free.fr Fri Feb 5 19:31:16 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 01:31:16 +0100 Subject: can pydoc display doc for local funcs? or other doc tools for own code Message-ID: <4b6cb854$0$28668$426a34cc@news.free.fr> Hi, often I start "pydoc -g" in a projects working directory in order to view the docstrings of my own project and in order to get a quick overview of the code structure In some cases I would like to see also to see private methods (especially when trying to understand the internals of a collegues code or even to browse throught the internals of my own code) Therefore I wonder whether pydoc could be configured such, that it would also display private methods (the ones with leading underscores) If not: What tools / methodologies would you recommend to quickly browse own / collegues source code. In many cases the function prototypes and the doc strings of public and private methods would be sufficient for me. thanks for any ideas N From gagsl-py2 at yahoo.com.ar Fri Feb 5 19:56:21 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Feb 2010 21:56:21 -0300 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: > I'm using an XMLRPC server under Windows. > > What I wonder is how I could create a server, that can be killed with > CTRL-C > > The server aborts easily with CTRL-BREAK but not with CTRL-C (under > Windows) > > If I press CTRL-C it will only abort when the next RPC call occurs. > It seems it is blocking in the select() call in the handle_request() > function. Python 2.6 and up behaves exactly as you want. On previous versions you may use this: class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): ... your methods ... if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): # pre 2.6 quit = False def serve_forever(self): while not self.quit: self.handle_request() def shutdown(self): self.quit = True def server_bind(self): self.socket.settimeout(1.0) SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) -- Gabriel Genellina From wolftracks at invalid.com Fri Feb 5 21:49:08 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 18:49:08 -0800 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: References: Message-ID: On 2/5/2010 9:30 AM, Grant Edwards wrote: > On 2010-02-05, W. eWatson wrote: > >> I'd like to draw something like an animal track. Between each >> point is a line. Perhaps the line would have an arrow showing >> the direction of motion. There should be x-y coordinates >> axises. PIL? MatPlotLib, ?? > > I'd probably use gnuplot-py, but I'm probably biased since I've > been using gnuplot since way before I learned Python. > It appears this is easier than I thought. MLB's plot will do it. I can put arrows at the end of a line, and even use sleep to watch the path slowly evolving. From andrej.mitrovich at gmail.com Fri Feb 5 22:17:17 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Fri, 5 Feb 2010 19:17:17 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> <1eed1fcc-f1d1-4f71-bc05-68dddb3f17b4@s33g2000prm.googlegroups.com> Message-ID: <814cf6b9-546c-4e1c-a02b-80d84a757da5@f15g2000yqe.googlegroups.com> Sweet, something to keep my brain busy for the next couple of weeks. From nagle at animats.com Fri Feb 5 22:38:15 2010 From: nagle at animats.com (John Nagle) Date: Fri, 05 Feb 2010 19:38:15 -0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <4b6ce04c$0$1622$742ec2ed@news.sonic.net> Forthminder wrote: ... Ignore. Well-known nut. See "http://www.nothingisreal.com/mentifex_faq.html" John Nagle From fuzzy.666.chaos at gmail.com Fri Feb 5 22:54:48 2010 From: fuzzy.666.chaos at gmail.com (Jordan Uchima) Date: Fri, 5 Feb 2010 21:54:48 -0600 Subject: "Nim" game being created, no GUI used... Need tips... Message-ID: <1b07ab151002051954hf3c946bqf4f306184228da40@mail.gmail.com> I am creating a game called Nim, but cannot get a loop going no matter what I do. What i am trying to do is get it to only accept input from 1 to 4, and keep asking for input from the same player if he/she enters in an invalid number. I also want it to stop when there is 1 or no piece(s) left, and declare the player who DID NOT take the last piece the winner. Also, how do I word the coding so that way it will make the players take turns? there are 2 players. there are 13 pieces to start with. i am using python 2.6.4 . here is my code: ----------------------------------------------------------------------------------------------------------------------------------------------- # taking pieces away player1Choice = raw_input("Well, " + namePlayer1 + " how many"\ " pieces would you like to take?\n" + range(1, 4)) player2Choice = raw_input("Well, " + namePlayer2 + " how many"\ " pieces would you like to take?\n" + range(1, 4)) # setting a variable for the number of pieces x = 13 - int(player1Choice or player2Choice) and not < 0 # to alternate turns turn = \ while player1Choice is False: print player1Choice and "There is ", x, " pieces remaining." while player1Choice is True: print player2Choice and "There is ", x, " pieces remaining." while player2Choice is False: print player2Choice and "There is ", x, " pieces remaining." while player1Choice and player2Choice is True: print player1Choice and "There is ", x, " pieces remaining." while x != range(0, 1): continue turn # to determine winner/loser loss = while x = range(0, 4) is True: print loser " loses!" + loser = \ if player1Choice = loss: print namePlayer1 + loss elif player2Choice = loss: print namePlayer2 + loss else player1Choice and player2Choice = loss: print "It's a draw!" elif player1Choice != loss: print "" elif player2Choice != loss: print "" else player1Choice and player2Choice != loss: print "Keep going! Only ", x, " pieces left!" winner = \ if player1Choice != loss: print namePlayer1 " wins!" elif player2Choice != loss: print namePlayer2 " wins!" elif player1Choice and player2Choice != loss: print "Keep going! Only ", x, " pieces left!" elif player1Choice = loss: print namePlayer1 + loss elif player2Choice = loss: print namePlayer2 + loss else player1Choice and player2Choice = loss: print "It's a draw!" # getting player's names namePlayer1 = raw_input("Hello Player 1, what is your name?\n") namePlayer2 = raw_input("Hello Player 2, what is your name?\n") # greeting players print "Hello", namePlayer1, "and", namePlayer2, "!" # instructions print "Welcome to the game of Nim, where you actually have to think!\n\n"\ "The instructions are simple: you can take 1 to 4 pieces at a time,"\ " but, if you take the last piece, YOU LOSE!\n\n"\ "To take pieces, simply type in the number of pieces you want"\ " to take, and press the ENTER (or in some cases, RETURN) key.\n\n"\ "However, you can NOT take 0 pieces, or more than 4 pieces!\n\n"\ "Well then, let's get started! :-)" # starting the game print turn --------------------------------------------------------------------------------------------------------------------------------------------- All help and insertions would be appreciated. You can reach me at fuzzy.666.chaos at gmail.com . Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From toylet.toylet at gmail.com Fri Feb 5 23:18:40 2010 From: toylet.toylet at gmail.com (Man-wai Chang to The Door (24000bps)) Date: Sat, 06 Feb 2010 12:18:40 +0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: On 06-Feb-10 08:02, Forthminder wrote: > Contest runs from 4 February to 26 February 2010. > http://csclub.uwaterloo.ca/contest/problem_description.php > Bonne Chance! It's definitely *not* exactly a programming challenge, but algorithm challenge. A programming (only) challenge should only require the players to write codes to implement an algorithm. This one requires both algorithm design & programming. -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.7 ^ ^ 12:16:01 up 6 days 20:22 2 users load average: 0.45 0.26 0.09 ???! ???! ???! ???! ???! ???! ????? (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa From gherron at islandtraining.com Fri Feb 5 23:55:54 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Feb 2010 20:55:54 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> Message-ID: <4B6CF65A.6030703@islandtraining.com> Craig Berry wrote: > Is there any way to get mouse wheel events from glut in PyOpenGL? > > Use Linux. (On Linux, Glut returns mouse wheel events as buttons 4 and 5), or use FreeGlut. On both Windows and Linux freeglut returns mouse wheel events as buttons 4 and 5. Gary Herron From darnzen at gmail.com Sat Feb 6 00:05:53 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 5 Feb 2010 21:05:53 -0800 (PST) Subject: WCK and PIL Message-ID: <1fbe5e4b-2179-410b-9f76-9d65a7a08dce@k19g2000yqc.googlegroups.com> I've written an app using the wck library (widget construction kit, see http://www.effbot.org), in addition to the wckGraph module. What I'd like to do, is take the output of one of my windows (happens to be a graph), and save it as a *.png or *.gif. I was planning on using the PIL for this. I'd like to use the code I have as is, without re- writing all the graphic calls to use PIL methods. WCK uses its own "pixmap" class for storing images in memory. I can't find any documentation or class reference for pixmap and what I find in the source is confusing. Does anyone have any direct experience with these libraries that can tell me that there's some super easy thing I'm missing? I'd love it if the wck pixmap is compatible with PIL. I don't have the time to mess with it unless I know its going to work. From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:10:08 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:10:08 -0300 Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> Message-ID: En Fri, 05 Feb 2010 17:39:07 -0300, jonny lowe escribi?: > On Feb 4, 8:20 pm, exar... at twistedmatrix.com wrote: >> On 01:56 am, jonny.lowe.12... at gmail.com wrote: >> >What I want is to have an easy way to merge input.txt and thestdout >> >so that output.txt look like: >> >> >Enter a number: 42 >> >You entered 42. >> >> >Here, the first 42 is of course from input.txt. >> >> It sounds like you might be looking forscript(1)? > > $ script -c "./y < input.txt" output.txt > Script started, file is output.txt > gimme x:you entered hello > Script done, file is output.txt Try moving the redirection out of the command: $ script -c ./y output.txt < input.txt -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:19:22 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:19:22 -0300 Subject: Dreaming of new generation IDE References: Message-ID: En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into ^^^^^^^^^^^^^^^^^^^^^^^ >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) Note the *literal* part. If you (the programmer) is likely to know the parameter value when writing the code, then the function is actually two separate functions. By example, foo.get_path(absolute=True) should be written as foo.get_absolute_path() and foo.get_relative_path() It gets worse when one parameter alters the type of the returned value, or even the number of returned values. This is an actual example: def build_image(self, zone=-1, return_sizes=False): ... if return_size: return img, sizes else: return img image = foo.build_image(3) but: image, sizes = foo.build_image(3, True) It should be split onto two separate functions; in this particular case, computing 'sizes' required actually drawing the image, so the solution was to make those 'sizes' attributes of the returned image. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:19:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:19:54 -0300 Subject: Import question References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> Message-ID: En Fri, 05 Feb 2010 13:21:47 -0300, Andrew Degtiariov escribi?: > Code of our project has split into several packages and we deploy the > project using buildout. > All worked fine until I need to dynamically inspect python modules. Entirely by luck, I'd say :) > ????project.api.config > ? ????project > ? ? ????api > ? ? ????config > ? ? ????settings > ? ????project.api.config.egg-info > ????project.api.contacts > ? ????project > ? ? ????api > ? ? ????contacts > ? ? ????importer > ? ? ????views > ? ????project.api.contacts.egg-info > Regular code like "import project.api.config" worked fine, but now I'm > tryed > __import__('project.api.config'): > > $ bin/python > >>>> import project.api.config >>>> __import__('project.api.config') > 'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'> You can't use dots neither in module names nor package names as they're identifiers [1]. It's like trying to use an attribute named 'foo.bar': you can handle it with getattr/setattr, but normal attribute access won't work: py> x.foo.bar = 1 Traceback (most recent call last): File "", line 1, in AttributeError: X instance has no attribute 'foo' py> setattr(x, 'foo.bar', 1) py> x.foo.bar Traceback (most recent call last): File "", line 1, in AttributeError: X instance has no attribute 'foo' py> getattr(x, 'foo.bar') 1 [1] http://docs.python.org/reference/simple_stmts.html#the-import-statement > What's wrong? We really need to split the code for several eggs and want > that all of our package's names starts from 'project.api' The only sane solution is to avoid using dots in package names. Sorry, but having project.api.config, project.api.contacts as directory names is simply crazy. Looks like you actually wanted to use this layout: project/ api/ config/ ... contacts/ ... core/ ... but made a wrong turn in the road... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:20:13 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:20:13 -0300 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: <4B6C1BED.6090807@bluewin.ch> Message-ID: En Fri, 05 Feb 2010 10:23:57 -0300, Anthra Norell escribi?: >>> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >>> window. The OS is Windows ME. The download of 2.5 finished with a >>> warning saying that 2.5 was the highest version for Windows 9* Any >>> tips? I'd suggest a couple more tests. Open the Python interpreter and execute: py> from idlelib import idle This *should* launch IDLE, or raise an error... If nothing happens, exit the process and open another one, and execute: py> import Tkinter py> root = Tkinter.Tk() py> root.mainloop() An empty window should appear. If not, I'd say something is wrong with the Tcl/Tk libraries. > For the time being 2.4 works fine. I'd much prefer 2.5, though, because > it includes the image library (PIL), whereas 2.4 cannot even use it. PIL has an impressive compatibility record - it works with *any* Python version from 1.5.2 up. You should be able to use PIL with 2.4 without problems. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:59:35 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:59:35 -0300 Subject: Simple question about Queue.Queue and threads References: Message-ID: En Fri, 05 Feb 2010 09:45:30 -0300, Frank Millman escribi?: > Assume you have a server process running, a pool of worker threads to > perform tasks, and a Queue.Queue() to pass the tasks to the workers. > > In order to shut down the server cleanly, you want to ensure that the > workers have all finished their tasks. I like the technique of putting a > None onto the queue, and have each worker check for None, put None back > onto the queue, and terminate itself. > > The main program would look something like this - > > q.put(None) > for worker in worker_threads: > worker.join() > > At this point you can be sure that each thread has completed its tasks > and terminated itself. > > However, the queue is not empty - it still has the final None in it. Yes - but who cares? :) > Is it advisable to finalise the cleanup like this? - > > while not q.empty(): > q.get() > q.task_done() > q.join() > > Or is this completely redundant? I don't see what you gain by doing that. On the other hand, you might check whether the queue contains exactly one item and it is None, just to be sure that all queued work has been done. (BTW, I'd use a different sentinel instead of None; perhaps this could not happen in your current code, but it's easy to inadvertedly put a None in the queue, stopping all workers prematurely.) -- Gabriel Genellina From torriem at gmail.com Sat Feb 6 00:59:54 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 05 Feb 2010 22:59:54 -0700 Subject: Calendar GUI In-Reply-To: <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> Message-ID: <4B6D055A.30901@gmail.com> Gabriel wrote: > On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: >> I'm working on setting up some software for a Peruvian non-profit to help >> them organize their incoming volunteers. One of the features I'd like to add >> is a calendar-like view of the different volunteers arrival dates and >> staying time, with potentially some other info through some double-click >> action. Rather than writing a calendar gui myself, is there some open-source >> calendar program you guys could recommend that I could plug into? It has to >> be run locally, as the internet isn't so reliable down here, but other than >> that something simple and clean is ideal. > > I wrote a gtk gui for google calendar. > > Maybe you can adapt it to your needs. > > http://code.google.com/p/googlecalendar-gtk/ Would this work without an internet connection? The original poster stated that internet isn't so reliable, hence the need for a local solution. From frank at chagford.com Sat Feb 6 01:30:55 2010 From: frank at chagford.com (Frank Millman) Date: Sat, 6 Feb 2010 08:30:55 +0200 Subject: Simple question about Queue.Queue and threads References: Message-ID: On Feb 6, 7:59 am, "Gabriel Genellina" wrote: > En Fri, 05 Feb 2010 09:45:30 -0300, Frank Millman > escribi?: > [...] > > However, the queue is not empty - it still has the final None in it. > > Yes - but who cares? :) > That was my point. I didn't think I needed to care, but I wanted to be sure I was not missing something. I will just discard all the final cleanup code. > > (BTW, I'd use a different sentinel instead of None; perhaps this could not > happen in your current code, but it's easy to inadvertedly put a None in > the queue, stopping all workers prematurely.) > Good advice. Thanks, Gabriel Frank From greg.ewing at canterbury.ac.nz Sat Feb 6 03:08:09 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 06 Feb 2010 21:08:09 +1300 Subject: ANN: PyGUI 2.2 Message-ID: PyGUI 2.2 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Highlights of this version: - TextEditor component with tabs, scrolling and word wrap - Classes for laying out components in rows, colums and grids - Printing support What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From pavlovevidence at gmail.com Sat Feb 6 04:29:10 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Feb 2010 01:29:10 -0800 (PST) Subject: execute sqlite3 dot commands in python References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: On Feb 5, 3:19?pm, Steve Holden wrote: > gintare statkute wrote: > > Does anybody know if it possible to execute sqlite3 dot commands in python? > > > dovanotas:/pages/links# python > > Python 2.5.2 (r252:60911, Jan ?4 2009, 17:40:26) > > [GCC 4.3.2] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import sqlite3 > >>>> sqlite3 ?.help > > Traceback (most recent call last): > > ? File "", line 1, in > > AttributeError: 'module' object has no attribute 'help' > > > the same with other commands: > > .databases > > .tables > >http://www.sqlite.org/sqlite.html > > No. Well actually you can, sort of. For instance: os.system('sqlite3 :memory: .help') Carl Banks From andrewt.herd at gmail.com Sat Feb 6 04:32:58 2010 From: andrewt.herd at gmail.com (Andrew) Date: Sat, 6 Feb 2010 01:32:58 -0800 (PST) Subject: PyQt4 designer custom properties - combo box style References: Message-ID: On Feb 4, 2:59?pm, David Boddie wrote: > On Tuesday 02 February 2010 22:25, Andrew wrote: > > > I am creating custom widgets for the PyQt4 Designer. I can create > > custom properties, but I'm looking for how to create a custom property > > that has a combo box drop down. I've seen them in the example widgets > > and tried following them, but they are using pre-defined items to > > populate their property, so it's not a very clear example of how to > > get the combo box property to work. > > Can you explain a bit more about what you have seen and what you are > trying to do. Are you trying to create a property that is treated > specially by Designer or do you want to get the data for the combo > box from somewhere else? I'm attempting to create a drop down property for a custom widget I'm creating. So when in designer and you scroll down to the custom properties, under the regular widget properties, one of them would be a drop down menu. The data to populate it will be coming from our API and currently is a list of string-items. Yes, it would be treated specially by Designer, since it's the only place it would be seen. In the PyQt4\examples\designer folder, it carries a number of custom widgets that will load into designer. The datetimeedit widget creates a custom drop down menu property. The plugin pulls its information from the QtCore libraries and from the QCalander Widget. Though I am unable to find a better example or even explanation of how it's actually creating that drop down menu. > > > Is there any other examples or help for this kind of setup? > > Have you seen this article? > > ?http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html No, I haven't, thanks. That might step in the right direction. I can't run it right now, so I'm not sure if it is putting a spinbox as it's property or just the value from the spin box. > > David Andrew From keakon at gmail.com Sat Feb 6 04:33:24 2010 From: keakon at gmail.com (keakon) Date: Sat, 6 Feb 2010 01:33:24 -0800 (PST) Subject: which References: Message-ID: self.cmd = cmd.replace(r'${ADDR}',ip) if isinstance(cmd, str) else cmd From cameron.jp at gmail.com Sat Feb 6 04:40:26 2010 From: cameron.jp at gmail.com (Jeff Cameron) Date: Sat, 6 Feb 2010 01:40:26 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: On Feb 5, 11:18?pm, "Man-wai Chang to The Door (24000bps)" wrote: > On 06-Feb-10 08:02, Forthminder wrote: > > > Contest runs from 4 February to 26 February 2010. > >http://csclub.uwaterloo.ca/contest/problem_description.php > > Bonne Chance! > > It's definitely *not* exactly a programming challenge, but algorithm > challenge. > > A programming (only) challenge should only require the players to write > codes to implement an algorithm. > > This one requires both algorithm design & programming. > > -- > ? ?@~@ ? Might, Courage, Vision, SINCERITY. > ? / v \ ?Simplicity is Beauty! May the Force and Farce be with you! > /( _ )\ (x86_64 Ubuntu 9.10) ?Linux 2.6.32.7 > ? ?^ ^ ? 12:16:01 up 6 days 20:22 2 users load average: 0.45 0.26 0.09 > ???! ???! ???! ???! ???! ???! ????? (CSSA):http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa Hello, this is Jeff Cameron, the organizer of the Google AI Challenge. I'm glad to see all this interest in our humble little contest. I wish you all the best of luck, and encourage everyone to try their hand at writing an AI for Tron! www.ai-contest.com From no.email at nospam.invalid Sat Feb 6 04:45:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Feb 2010 01:45:03 -0800 Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <7xpr4ihf4w.fsf@ruckus.brouhaha.com> "Man-wai Chang to The Door (24000bps)" writes: > It's definitely *not* exactly a programming challenge, but algorithm > challenge. > A programming (only) challenge should only require the players to > write codes to implement an algorithm. Eh? Just about every interesting programming challenge is mostly about algorithm selection. Try some Project Euler for example. From pavlovevidence at gmail.com Sat Feb 6 04:56:41 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Feb 2010 01:56:41 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> <037c8bd7$0$1292$c3e8da3@news.astraweb.com> Message-ID: <6ee9e549-081b-4f22-9f08-62440df85d5d@t17g2000prg.googlegroups.com> On Feb 5, 3:36?pm, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 2:45 PM, Steven D'Aprano > > wrote: > > For instance, if getting or setting the voltage is an expensive > > operation, you don't want to fool the user into thinking it is a cheap > > attribute access. > > I strongly disagree with this rationale as it violates the Uniform > Access Principle > (http://en.wikipedia.org/wiki/Uniform_access_principle). Though I > concede Python's builtins don't adhere to the UAP. And I strongly disagree with the Uniform Access Principle. I want my accesses to an object to be explicitly "data-like" or "method-like", even if Based on the Wikipedia page, Meyer's main reason behind UAP seems to be to minimize the need to break interfaces: the UAP is a means to an end. Python achieves that end without the conforming to UAP, therefore it doesn't need it, and there's no reason to adhere to it. Carl Banks From anthra.norell at bluewin.ch Sat Feb 6 06:21:46 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Sat, 06 Feb 2010 12:21:46 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: <4B6C1BED.6090807@bluewin.ch> Message-ID: <4B6D50CA.5070006@bluewin.ch> Gabriel, Thanks for your hints. I take them up one by one: Gabriel Genellina wrote: > En Fri, 05 Feb 2010 10:23:57 -0300, Anthra Norell > escribi?: > >>>> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >>>> window. The OS is Windows ME. The download of 2.5 finished with a >>>> warning saying that 2.5 was the highest version for Windows 9* Any >>>> tips? > > I'd suggest a couple more tests. > Open the Python interpreter and execute: > > py> from idlelib import idle > > This *should* launch IDLE, or raise an error... >>> import idle Traceback (most recent call last): File "", line 1, in File "C:/PYTHON25/Lib/IDLELIB\idle.pyw", line 6, in import PyShell File "C:\Python25\Lib\idlelib\PyShell.py", line 3, in ImportError: No module named os >>> import os Traceback (most recent call last): File "", line 1, in ImportError: No module named os > If nothing happens, exit > the process and open another one, and execute: > > py> import Tkinter >>> import Tkinter Traceback (most recent call last): File "", line 1, in File "C:\PYTHON25\lib\lib-tk\Tkinter.py", line 37, in import FixTk # Attempt to configure Tcl/Tk without requiring PATH File "C:\PYTHON25\lib\lib-tk\FixTk.py", line 1, in import sys, os ImportError: No module named os > > py> root = Tkinter.Tk() > py> root.mainloop() > > An empty window should appear. If not, I'd say something is wrong with > the > Tcl/Tk libraries. > >> For the time being 2.4 works fine. I'd much prefer 2.5, though, >> because it includes the image library (PIL), whereas 2.4 cannot even >> use it. > > PIL has an impressive compatibility record - it works with *any* Python > version from 1.5.2 up. You should be able to use PIL with 2.4 without > problems. > Another good hint to a side issue: I should download PIL for P2.4. I guess it wasn't available back then and so I continued doing images with P2.2. The real issue seems to be a missing module "os". C:\PYTHON25\LIB>dir os.* Volume in drive C is PKBACK# 001 Volume Serial Number is 07D1-0103 Directory of C:\PYTHON25\Lib OS PY 25,211 08-03-06 9:27a OS.PY OS PYC 24,430 06-05-08 6:45p OS.PYC 2 file(s) 49,641 bytes 0 dir(s) 2,635.30 MB free Here we are! Somehow the name got upper-cased! There's a whole bunch (131) of upper-cased names in the Lib I shall install the whole thing from scratch. That should take care if it. Thank you very much. Frederic (Looking forward to Linux!) From tompelka at gmail.com Sat Feb 6 06:38:39 2010 From: tompelka at gmail.com (Tomas Pelka) Date: Sat, 06 Feb 2010 12:38:39 +0100 Subject: how to run part of my python code as root In-Reply-To: References: Message-ID: <4B6D54BF.90903@gmail.com> sjdevnull at yahoo.com wrote: > On Feb 4, 2:05 pm, Tomas Pelka wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Hey, >> >> is there possibility how to run part of my code (function for example) >> as superuser. >> >> Or only way how to do this is create a wrapper and run is with Popen >> through sudo (but I have to configure sudo to run "whole" python as root). > thank you for excellent explanation. > In decreasing order of desirability: > 1. Find a way to not need root access (e.g. grant another user or > group access to whatever resource you're trying to access). > 2. Isolate the stuff that needs root access into a small helper > program that does strict validation of all input (including arguments, > environment, etc); when needed, run that process under sudo or > similar. I thing this approach is the best for me. But how to connect two separated processes, one running with root privileges and second without superuser privileges? Is was thinking about Queues from multiprocessing, didn't you know if it is a good choice? > 2a. Have some sort of well-verified helper daemon that has access to > the resource you need and mediates use of that resource. > 3. Run the process as root, using seteuid() to switch between user and > root privs. The entire program must be heavily verified and do strict > validation of all inputs. Any attacker who gets control over the > process can easily switch to root privs and do damage. This is > generally a bad idea. -- Tom Key fingerprint = 06C0 23C6 9EB7 0761 9807 65F4 7F6F 7EAB 496B 28AA From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 06:48:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 11:48:56 GMT Subject: Doctests and decorated methods don't get along Message-ID: <037d435d$0$1292$c3e8da3@news.astraweb.com> It seems that doctest doesn't discover or execute doctests in methods which have been decorated. Here is my test file: # ====== class MyStaticMethod(object): """Emulate built-in staticmethod descriptor.""" def __init__(self, f): self.f = f def __get__(self, obj, objtype=None): return self.f class Test(object): def method1(self): """Doc string >>> print 'x' x """ @staticmethod def method2(): """Doc string >>> print 'y' y """ @MyStaticMethod def method3(): """Doc string >>> print '***' # This test should fail. z """ if __name__ == '__main__': import doctest doctest.testmod(verbose=True) # ====== and here is the output using Python 2.6.4: [steve at sylar python]$ python2.6 test_doctests.py Trying: print 'x' Expecting: x ok Trying: print 'y' Expecting: y ok 5 items had no tests: __main__ __main__.MyStaticMethod __main__.MyStaticMethod.__get__ __main__.MyStaticMethod.__init__ __main__.Test 2 items passed all tests: 1 tests in __main__.Test.method1 1 tests in __main__.Test.method2 2 tests in 7 items. 2 passed and 0 failed. Test passed. It doesn't even see method3, let alone run the tests. This looks like bug to me. Have I missed anything? Any work arounds? -- Steven From news123 at free.fr Sat Feb 6 07:09:06 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 13:09:06 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows In-Reply-To: References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: <4b6d5be2$0$21960$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: > >> I'm using an XMLRPC server under Windows. >> >> What I wonder is how I could create a server, that can be killed with >> CTRL-C >> >> The server aborts easily with CTRL-BREAK but not with CTRL-C (under >> Windows) >> >> If I press CTRL-C it will only abort when the next RPC call occurs. >> It seems it is blocking in the select() call in the handle_request() >> function. > > Python 2.6 and up behaves exactly as you want. > On previous versions you may use this:] I', using python 2.6.4 nd neither on Win-XP nor on Win-7 I'm capable to abort with CTR-C ? On Linux however I can use CTRL-C . > > class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): > > ... your methods ... > > if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): > > # pre 2.6 > quit = False > > def serve_forever(self): > while not self.quit: > self.handle_request() > > def shutdown(self): > self.quit = True > > def server_bind(self): > self.socket.settimeout(1.0) > SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) > I tried something similiar, but without setting the socket timeout. I'll try it now with. N From kevin.p.dwyer at gmail.com Sat Feb 6 07:10:48 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 6 Feb 2010 12:10:48 +0000 (UTC) Subject: "Nim" game being created, no GUI used... Need tips... References: <1b07ab151002051954hf3c946bqf4f306184228da40@mail.gmail.com> Message-ID: On Fri, 05 Feb 2010 21:54:48 -0600, Jordan Uchima wrote: Hello Jordan, You could try something like this (not tested, and maybe I don't quite "get" the rules): """ Nim game. In response to question on c.l.p. """ # Start with pot of thirteen pieces and two players. # Each player takes 1 - 4 pieces each turn. # Player who takes the last piece loses. # Declare constants. NUMBER_OF_PLAYERS = 2 TOTAL_PIECES_AT_START = 13 # Declare functions. def rules(): """Print the rules of the game.""" print 'Some rules' def get_players(): """Get the names of the players.""" # Let's put the player's names in a list. players = [] # Looping like this saves us repeating lines of code for each player. for player in range(NUMBER_OF_PLAYERS): name = raw_input("Hello Player %d, what is your name?\n" % player) players.append(player) return players def take_turn(player): """Handle a player's turn.""" # Turn logic goes here. # Left as an exercise :) the_remaining_number_of_pieces_after_this_turn = 1 return the_remaining_number_of_pieces_after_this_turn def main(): """Run the game.""" # Display the rules by calling rules function. rules() # Get the players by calling the get_players function. players = get_players() # Set up the game. remaining_pieces = TOTAL_PIECES_AT_START playing = True # Main loop - let's play! while playing: # Take turns. for player in players: remaining_pieces = take_turn(player) # Check if this player has lost. if remaining_pieces == 0: # Player has taken last piece. print 'Sorry %s, you have lost.' % player # Break out of the loop playing = False break # Automatically run main function if we're run as a script. if __name__ == '__main__': main() # End. The "while" loop in the main function runs the game until a winner (or loser in this case) is declared. The "for" loop within the while loop handles the alternation of turns. Have a look at the python tutorial at http://docs.python.org/tutorial/index.html for more on "while" and "for" statements. Use functions to break up the code into related sections. Check out the tutorial material for functions too. This skeleton should give you a starting structure for your program. Have fun :) Kev From gerald.britton at gmail.com Sat Feb 6 08:09:10 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Sat, 6 Feb 2010 08:09:10 -0500 Subject: Exception class documentation In-Reply-To: <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> Message-ID: <5d1a32001002060509w56f9fce1wf72dc56d7a70d3cb@mail.gmail.com> If you browse the Python source tree, you should be able to find it. http://svn.python.org/view/python/trunk/Objects/exceptions.c?revision=77045&view=markup On Fri, Feb 5, 2010 at 7:27 PM, Charles Yeomans wrote: > > On Feb 5, 2010, at 2:13 PM, Gerald Britton wrote: > >> On Fri, Feb 5, 2010 at 12:55 PM, Charles Yeomans >> wrote: >>> >>> I am so far unable to find the information I want about the Exception >>> class. >>> ?Information like the signature of __init__ seems to be unavailable. ?Any >>> suggestions where I might find such information? >>> >> >> Though not documented, some silly tests indicate that it will accept >> pretty much anything: >> >>>>> Exception(1,2,4,54) >> >> Exception(1, 2, 4, 54) >>>>> >>>>> Exception(*range(10)) >> >> Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>>>> >>>>> Exception(*range(50)) >> >> Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, >> 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, >> 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49) >>>>> >>>>> Exception('a','b','c','d','e') >> >> Exception('a', 'b', 'c', 'd', 'e') >>>>> >>>>> Exception(Exception(1)) >> >> Exception(Exception(1,),) > > I had also tried such tests. ?If you pass a single argument msg, it is > assigned to the message property, and the args property is set to (msg,). If > you pass more than one argument, the tuple of arguments is assigned to the > args property, and nothing is assigned to the message property. ?I was > hoping to at least find source code that provides a definitive answer. > > > Charles Yeomans > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From anthra.norell at bluewin.ch Sat Feb 6 08:33:57 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Sat, 06 Feb 2010 14:33:57 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: <4B6D50CA.5070006@bluewin.ch> References: <4B6C1BED.6090807@bluewin.ch> <4B6D50CA.5070006@bluewin.ch> Message-ID: <4B6D6FC5.3000705@bluewin.ch> Gabriel, After reinstalling the whole package things are shaping up. It still doesn't work but it fails more to the point of your suggestions. I update the responses to your questions: Anthra Norell wrote: > Gabriel, > Thanks for your hints. I take them up one by one: > > Gabriel Genellina wrote: >> En Fri, 05 Feb 2010 10:23:57 -0300, Anthra Norell >> escribi?: >> >>>>> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >>>>> window. The OS is Windows ME. The download of 2.5 finished with a >>>>> warning saying that 2.5 was the highest version for Windows 9* Any >>>>> tips? >> >> I'd suggest a couple more tests. >> Open the Python interpreter and execute: >> >> py> from idlelib import idle >> >> This *should* launch IDLE, or raise an error... > >>> import idle Traceback (most recent call last): File "", line 1, in File "C:/PYTHON25/lib/IDLELIB\idle.py", line 19, in PyShell.main() File "C:\Python25\Lib\idlelib\PyShell.py", line 1390, in main root = Tk(className="Idle") File "C:\PYTHON25\lib\lib-tk\Tkinter.py", line 1647, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, want objects, useTk, sync, use) _tkinter.TclError: Can't find a usable init.tcl in the following directories: C:/PYTHON25/lib/tcl8.4 C:/lib/tcl8.4 C:/library Checking for the whereabouts of the tcl8.4 directory I find it in C:/PYTHON25/TCL together with a few more plus some files. C:\PYTHON25\TCL>dir Volume in drive C is PKBACK# 001 Volume Serial Number is 07D1-0103 Directory of C:\PYTHON25\TCL . 11-25-08 4:09p . .. 11-25-08 4:09p .. TCL84 LIB 191,802 03-27-06 4:23p tcl84.lib TCLSTU~1 LIB 2,264 03-27-06 4:23p tclstub84.lib DDE1 2 11-25-08 4:09p DDE1.2 REG1 1 11-25-08 4:09p REG1.1 TCL8 4 11-25-08 4:09p TCL8.4 TK8 4 11-25-08 4:09p TK8.4 TK84 LIB 167,288 03-27-06 4:44p tk84.lib TKSTUB84 LIB 2,988 03-27-06 4:43p tkstub84.lib TIX8 4 02-06-10 1:09p tix8.4 4 file(s) 364,342 bytes 7 dir(s) 2,569.25 MB free This is the way the installer fixed it. The thing to do seems to be to move the tcl8.4 dirctory to the lib directory. Before I start upsetting things, perhaps you would know whether the whole TCL subtree should move. Frederic From toylet.toylet at gmail.com Sat Feb 6 08:41:52 2010 From: toylet.toylet at gmail.com (Man-wai Chang to The Door (24000bps)) Date: Sat, 06 Feb 2010 21:41:52 +0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: <7xpr4ihf4w.fsf@ruckus.brouhaha.com> References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> <7xpr4ihf4w.fsf@ruckus.brouhaha.com> Message-ID: > Eh? Just about every interesting programming challenge is mostly about > algorithm selection. Try some Project Euler for example. Everyone back then has abused the "programming" word to meant doing everything (algorithms (system analysis & design), data structures, coding, testing, documentation, auditing, ....) at cheap salaries+benefits and tight schedules! -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.7 ^ ^ 21:40:01 up 7 days 5:46 2 users load average: 0.00 0.04 0.01 ???! ???! ???! ???! ???! ???! ????? (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa From toylet.toylet at gmail.com Sat Feb 6 08:43:28 2010 From: toylet.toylet at gmail.com (Man-wai Chang to The Door (24000bps)) Date: Sat, 06 Feb 2010 21:43:28 +0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: > Hello, this is Jeff Cameron, the organizer of the Google AI Challenge. > I'm glad to see all this interest in our humble little contest. I wish > you all the best of luck, and encourage everyone to try their hand at > writing an AI for Tron! www.ai-contest.com Someone please dumb the Tron ROM from the MAME32 project and use it as baseline answer. :) -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.7 ^ ^ 21:42:01 up 7 days 5:48 2 users load average: 0.00 0.02 0.00 ???! ???! ???! ???! ???! ???! ????? (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa From wgaggioli at gmail.com Sat Feb 6 09:51:53 2010 From: wgaggioli at gmail.com (Sir Wilhelm the Sturdy) Date: Sat, 6 Feb 2010 06:51:53 -0800 (PST) Subject: Calendar GUI References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> Message-ID: <4bb356ba-b043-444e-a318-6ec010028bb4@d37g2000yqa.googlegroups.com> On Feb 6, 12:59?am, Michael Torrie wrote: > Gabriel wrote: > > On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: > >> I'm working on setting up some software for a Peruvian non-profit to help > >> them organize their incoming volunteers. One of the features I'd like to add > >> is acalendar-like view of the different volunteers arrival dates and > >> staying time, with potentially some other info through some double-click > >> action. Rather than writing acalendarguimyself, is there some open-source > >>calendarprogram you guys could recommend that I could plug into? It has to > >> be run locally, as the internet isn't so reliable down here, but other than > >> that something simple and clean is ideal. > > > I wrote a gtkguifor googlecalendar. > > > Maybe you can adapt it to your needs. > > >http://code.google.com/p/googlecalendar-gtk/ > > Would this work without an internet connection? ?The original poster > stated that internet isn't so reliable, hence the need for a local solution. The functionality of Google calendar would be perfect, but it needs to be run locally. From ALANBIDDLE70 at YAHOO.COM Sat Feb 6 10:45:39 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Sat, 06 Feb 2010 09:45:39 -0600 Subject: Need installer recommendation Message-ID: <6q2rm5htqdj2puinbg9pmkco8o6nhd72h5@4ax.com> Hi, I could use a recommendation on a free installer for use by an unsophisticated programmer, that would be me, for some simple programs which are a bit more than "Hello World," but only a little. Basically reading text files and processing the results. Nothing fancy. I am using PY2EXE to create the distribution. In doing the Google, and from past posting here, I see that most recommendations are for inno and nsis. I expect that either would do what I want. Is one a better choice for someone to learn enough to do basic stuff without getting bogged down in details which are not immediately important? -- Alan From charles at declaresub.com Sat Feb 6 11:05:42 2010 From: charles at declaresub.com (Charles Yeomans) Date: Sat, 6 Feb 2010 11:05:42 -0500 Subject: Exception class documentation In-Reply-To: <5d1a32001002060509w56f9fce1wf72dc56d7a70d3cb@mail.gmail.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> <5d1a32001002060509w56f9fce1wf72dc56d7a70d3cb@mail.gmail.com> Message-ID: <35733041-2A61-4E19-9730-D5065CA6E826@declaresub.com> On Feb 6, 2010, at 8:09 AM, Gerald Britton wrote: > If you browse the Python source tree, you should be able to find it. > > http://svn.python.org/view/python/trunk/Objects/exceptions.c?revision=77045&view=markup > Perfect (even if I have to read C). Thanks. Charles Yeomans From mark.wendell at gmail.com Sat Feb 6 12:19:46 2010 From: mark.wendell at gmail.com (mark.wendell) Date: Sat, 6 Feb 2010 09:19:46 -0800 (PST) Subject: optparse print_help question Message-ID: Is there a way to use the optparser parser.print_help() so that it ONLY prints out the options, and NOT the usage? thanks From benjamin at python.org Sat Feb 6 12:56:40 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Feb 2010 11:56:40 -0600 Subject: [RELEASED] Python 2.7 alpha 3 Message-ID: <1afaf6161002060956o4b303053pfd8b37922bea904f@mail.gmail.com> On behalf of the Python development team, I'm cheerful to announce the third alpha release of Python 2.7. Python 2.7 is scheduled (by Guido and Python-dev) to be the last major version in the 2.x series. Though more major releases have not been absolutely ruled out, it's likely that the 2.7 release will an extended period of maintenance for the 2.x series. 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, 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/ Please note that this is a development release, intended as a preview of new features for the community, and is thus not suitable for production use. The 2.7 documentation can be found at: http://docs.python.org/2.7 Please consider trying Python 2.7 with your code and reporting any bugs you may notice to: http://bugs.python.org Enjoy! -- Benjamin Peterson 2.7 Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7's contributors) From sccolbert at gmail.com Sat Feb 6 13:24:21 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sat, 6 Feb 2010 13:24:21 -0500 Subject: determining which value is the first to appear five times in a list? Message-ID: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> I'm working on a naive K-nearest-neighbors selection criteria for an optical character recognition problem. After I build my training set, I test each new image against against the trained feature vectors and record the scores as follows: match_vals = [(match_val_1, identifier_a), (match_val_2, identifier_b) .... ] and so on.. then I sort the list so the smallest match_val's appear first (indictating a strong match, so I may end up with something like this: [(match_val_291, identifier_b), (match_val_23, identifier_b), (match_val_22, identifer_k) .... ] Now, what I would like to do is step through this list and find the identifier which appears first a K number of times. Naively, I could make a dict and iterate through the list AND the dict at the same time and keep a tally, breaking when the criteria is met. such as: def getnn(match_vals): tallies = defaultdict(lambda: 0) for match_val, ident in match_vals: tallies[ident] += 1 for ident, tally in tallies.iteritems(): if tally == 5: return ident I would think there is a better way to do this. Any ideas? Cheers! Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 6 13:54:09 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 00:24:09 +0530 Subject: how to fix bugs (python) Message-ID: I am interested in fixing bugs in python. Are there entry-level bugs in python which makes me familiarize with the process just like gnome have gnome-love ? Just a small start-up guidance will be a big favour as I have never fixed any. Thanks, ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Feb 6 13:56:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 13:56:25 -0500 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> Message-ID: On 2/6/2010 1:24 PM, Chris Colbert wrote: > I'm working on a naive K-nearest-neighbors selection criteria for an > optical character recognition problem. > > After I build my training set, I test each new image against against the > trained feature vectors and record the scores as follows: > > match_vals = [(match_val_1, identifier_a), (match_val_2, identifier_b) > .... ] and so on.. > > then I sort the list so the smallest match_val's appear first > (indictating a strong match, so I may end up with something like this: > > [(match_val_291, identifier_b), (match_val_23, identifier_b), > (match_val_22, identifer_k) .... ] > > Now, what I would like to do is step through this list and find the > identifier which appears first a K number of times. > > Naively, I could make a dict and iterate through the list AND the dict > at the same time and keep a tally, breaking when the criteria is met. > > such as: > > def getnn(match_vals): > tallies = defaultdict(lambda: 0) > for match_val, ident in match_vals: > tallies[ident] += 1 > for ident, tally in tallies.iteritems(): > if tally == 5: > return ident > > I would think there is a better way to do this. Any ideas? You only need to check that the incremented tally is 5, which is to say, that the about-to-be-incremented tally is 4. t = tallies[ident] if t < 4: tallies[ident] = t+1 else: return ident From jjposner at optimum.net Sat Feb 6 14:00:28 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 06 Feb 2010 14:00:28 -0500 Subject: Doctests and decorated methods don't get along In-Reply-To: <037d435d$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B6DBC4C.4080100@optimum.net> On 2/6/2010 6:48 AM, Steven D'Aprano wrote: > class MyStaticMethod(object): > """Emulate built-in staticmethod descriptor.""" > def __init__(self, f): > self.f = f > def __get__(self, obj, objtype=None): > return self.f How about using a function, instead of a class, to implement the decorator: import functools def MyStaticMethod(f): @functools.wraps(f) def _wrapper(*args, **kwargs): return f(*args, **kwargs) return _wrapper For me, this produces the hoped-for doctest failure in __main__.Test.method3. I tried making the class-based implementation work by using functools.wraps(), but I couldn't manage it. Also, doesn't the decorator protocol want the class to implement a __call__() method, not a __get__() method? Or am I getting hung up (not the first time) at the nexus of the descriptor and decorator protocols? -John From rrr at ronadam.com Sat Feb 6 14:03:47 2010 From: rrr at ronadam.com (Ron Adam) Date: Sat, 06 Feb 2010 13:03:47 -0600 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: Xah Lee wrote: > For anyone reading this thread and interested in my opinions, i have > written many essays related to this and netiquette. Many of which > detail other similar incidences that i personally experienced, such as > freenode's irc ban in #emacs channel. If you are interested, they can > be found on my website, search for ?ban xah lee?. Xah, Often (in the past) most of your posts have come across as complaints or ones pointing out problems or comparisons of the negative sort. Your overall negative tone is just one of the reasons you get labeled a troll. I suggest you try to be less confrontational and more positive. Use your expertise and intelligence to help others but don't be offended if they don't agree with you. There's more than one way to do almost everything and sometimes the best way for "a person" to do it is the way that person is able to grasp it. Regards, Ron From wentland at cl.uni-heidelberg.de Sat Feb 6 14:09:01 2010 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Sat, 6 Feb 2010 20:09:01 +0100 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> Message-ID: <20100206190901.GB2508@kinakuta.local> On Sat, Feb 06, 2010 at 13:24 -0500, Chris Colbert wrote: > [(match_val_291, identifier_b), (match_val_23, identifier_b), (match_val_22, > identifer_k) .... ] > > Now, what I would like to do is step through this list and find the identifier > which appears first a K number of times. I think you can use the itertools.groupby(L, lambda el: el[1]) to group elements in your *sorted* list L by the value el[1] (i.e. the identifier) and then iterate through these groups until you find the desired number of instances grouped by the same identifier. Let me exemplify this: >>> from itertools import groupby >>> instances = [(1, 'b'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'c'), (6, 'c'), (7, 'd')] >>> k = 3 >>> grouped_by_identifier = groupby(instances, lambda el: el[1]) >>> grouped_by_identifier = ((identifier, list(group)) for identifier, group in grouped_by_identifier) >>> k_instances = (group for identifier, group in grouped_by_identifier if len(group) == k) >>> next(k_instances) [(4, 'c'), (5, 'c'), (6, 'c')] >>> next(k_instances) Traceback (most recent call last): File "", line 1, in StopIteration There are certainly millions of ways to do this and most of them will be better than my proposal here, but you might like this approach. Another approach would use itertools.takewhile() or itertools.ifilter() ... Just have a look :-) yours sincerely -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From jim.hefferon at gmail.com Sat Feb 6 14:09:31 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 6 Feb 2010 11:09:31 -0800 (PST) Subject: intolerant HTML parser Message-ID: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> I generate some HTML and I want to include in my unit tests a check for syntax. So I am looking for a program that will complain at any syntax irregularities. I am familiar with Beautiful Soup (use it all the time) but it is intended to cope with bad syntax. I just tried feeding HTMLParser.HTMLParser some HTML containing '

ab

' and it didn't complain. That is, this: h=HTMLParser.HTMLParser() try: h.feed('

ab

') h.close() print "I expect not to see this line" except Exception, err: print "exception:",str(err) gives me "I expect not to see this line". Am I using that routine incorrectly? Is there a natural Python choice for this job? Thanks, Jim From jim.hefferon at gmail.com Sat Feb 6 14:35:34 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 6 Feb 2010 11:35:34 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6dc27c$0$1608$742ec2ed@news.sonic.net> Message-ID: Thank you, John. I did not find that by looking around; I must not have used the right words. The speed of the unit tests are not critical so this seems like the solution for me. Jim From hzhuo1 at gmail.com Sat Feb 6 14:36:46 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sat, 6 Feb 2010 11:36:46 -0800 (PST) Subject: How to print all expressions that match a regular expression Message-ID: Hi, I am a fresh man with python. I know there is regular expressions in Python. What I need is that given a particular regular expression, output all the matches. For example, given ?[1|2|3]{2}? as the regular expression, the program should output all 9 matches, i.e., "11 12 13 21 22 23 31 32 33". Is there any well-written routine in Python or third-party program to do this? If there isn't, could somebody make some suggestions on how to write it myself? Thanks. Zhuo From tjreedy at udel.edu Sat Feb 6 14:39:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 14:39:00 -0500 Subject: Doctests and decorated methods don't get along In-Reply-To: <037d435d$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: On 2/6/2010 6:48 AM, Steven D'Aprano wrote: > It seems that doctest doesn't discover or execute doctests in methods > which have been decorated. > > > Here is my test file: > > # ====== > class MyStaticMethod(object): > """Emulate built-in staticmethod descriptor.""" > def __init__(self, f): > self.f = f > def __get__(self, obj, objtype=None): > return self.f > > class Test(object): > def method1(self): > """Doc string > > >>> print 'x' > x > """ > > @staticmethod > def method2(): > """Doc string > > >>> print 'y' > y > """ > > @MyStaticMethod > def method3(): > """Doc string > > >>> print '***' # This test should fail. > z > """ > > if __name__ == '__main__': > import doctest > doctest.testmod(verbose=True) > # ====== > > > and here is the output using Python 2.6.4: > > [steve at sylar python]$ python2.6 test_doctests.py > Trying: > print 'x' > Expecting: > x > ok > Trying: > print 'y' > Expecting: > y > ok > 5 items had no tests: > __main__ > __main__.MyStaticMethod > __main__.MyStaticMethod.__get__ > __main__.MyStaticMethod.__init__ > __main__.Test > 2 items passed all tests: > 1 tests in __main__.Test.method1 > 1 tests in __main__.Test.method2 > 2 tests in 7 items. > 2 passed and 0 failed. > Test passed. > > > It doesn't even see method3, let alone run the tests. Method3 is wrapped as an instance of MyStaticMethod and doctest does not see that as function. Even if it did, you would might have to copy the docstring (self.__doc__ = f.__doc__) to have the test run. Note the following: (3.1) >>> Test.method3 >>> Test.__dict__['method3'] <__main__.MyStaticMethod object at 0x00F5CDF0> >>> Test.__dict__['method2'] Doctest has to scan the dict, so it does not see the attribute-lookup result. > This looks like bug to me. Have I missed anything? I would call it a limitation as I do not see the doc as promising otherwise. I believe doctest predates the descripter protocol, at least in its current form, so it may not be completely descriptor-aware. You certainly could file a feature request for improved recognition and subsequent calling of __get__. An initial patch would improve chances of action. > Any workarounds? Perhaps look at the doctest source to see why staticmethod instances are recognized as functions. If doctest directly special-cases their recognition, then use the standard nested function approach for decorators, making sure to copy the doc string. Look at functools.wraps. If doctest recognizes them by some characteristic that you have not emulated, try to improve that. Terry Jan Reedy Terry Jan Reedy From tjreedy at udel.edu Sat Feb 6 14:42:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 14:42:52 -0500 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <20100206190901.GB2508@kinakuta.local> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> <20100206190901.GB2508@kinakuta.local> Message-ID: On 2/6/2010 2:09 PM, Wolodja Wentland wrote: > On Sat, Feb 06, 2010 at 13:24 -0500, Chris Colbert wrote: >> [(match_val_291, identifier_b), (match_val_23, identifier_b), (match_val_22, >> identifer_k) .... ] >> >> Now, what I would like to do is step through this list and find the identifier >> which appears first a K number of times. > > I think you can use the itertools.groupby(L, lambda el: el[1]) to group > elements in your *sorted* list L by the value el[1] (i.e. the > identifier) and then iterate through these groups until you find the > desired number of instances grouped by the same identifier. This will generally not return the same result. It depends on whether OP wants *any* item appearing at least 5 times or whether the order is significant and the OP literally wants the first. Sorting the entire list may also take a *lot* longer. Terry Jan Reedy From nagle at animats.com Sat Feb 6 14:43:19 2010 From: nagle at animats.com (John Nagle) Date: Sat, 06 Feb 2010 11:43:19 -0800 Subject: intolerant HTML parser In-Reply-To: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> Message-ID: <4b6dc27c$0$1608$742ec2ed@news.sonic.net> Jim wrote: > I generate some HTML and I want to include in my unit tests a check > for syntax. So I am looking for a program that will complain at any > syntax irregularities. > > I am familiar with Beautiful Soup (use it all the time) but it is > intended to cope with bad syntax. I just tried feeding > HTMLParser.HTMLParser some HTML containing '

ab

' and it > didn't complain. Try HTML5lib. http://code.google.com/p/html5lib/downloads/list The syntax for HTML5 has well-defined notions of "correct", "fixable", and "unparseable". For example, the common but incorrect form of HTML comments, <- comment -> is understood. HTML5lib is slow, though. Sometimes very slow. It's really a reference implementation of the spec. There's code like this: #Should speed up this check somehow (e.g. move the set to a constant) if ((0x0001 <= charAsInt <= 0x0008) or (0x000E <= charAsInt <= 0x001F) or (0x007F <= charAsInt <= 0x009F) or (0xFDD0 <= charAsInt <= 0xFDEF) or charAsInt in frozenset([0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, 0x10FFFF])): self.tokenQueue.append({"type": tokenTypes["ParseError"], "data": "illegal-codepoint-for-numeric-entity", "datavars": {"charAsInt": charAsInt}}) Every time through the loop (once per character), they build that frozen set again. John Nagle From tjreedy at udel.edu Sat Feb 6 14:49:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 14:49:29 -0500 Subject: how to fix bugs (python) In-Reply-To: References: Message-ID: On 2/6/2010 1:54 PM, Shashwat Anand wrote: > I am interested in fixing bugs in python. Are there entry-level bugs in > python which makes me familiarize with the process just like gnome have > gnome-love ? Just a small start-up guidance will be a big favour as I > have never fixed any. Go to python.org/dev/ and look at various pages there. The item tracker is at bugs.python.org Some items are marked easy. Many items have patches that need review. Help is needed both with Python code (modules) and C code (core and modules) depending on your abilities and interest. I would start with looking at current items on the tracker. Terry Jan Reedy From anand.shashwat at gmail.com Sat Feb 6 14:58:47 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 01:28:47 +0530 Subject: how to fix bugs (python) In-Reply-To: References: Message-ID: Thanks Terry. I am looking on it. :) On Sun, Feb 7, 2010 at 1:19 AM, Terry Reedy wrote: > On 2/6/2010 1:54 PM, Shashwat Anand wrote: > >> I am interested in fixing bugs in python. Are there entry-level bugs in >> python which makes me familiarize with the process just like gnome have >> gnome-love ? Just a small start-up guidance will be a big favour as I >> have never fixed any. >> > > Go to > python.org/dev/ > and look at various pages there. The item tracker is at > bugs.python.org > Some items are marked easy. Many items have patches that need review. Help > is needed both with Python code (modules) and C code (core and modules) > depending on your abilities and interest. I would start with looking at > current items on the tracker. > > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wgaggioli at gmail.com Sat Feb 6 15:06:04 2010 From: wgaggioli at gmail.com (Sir Wilhelm the Sturdy) Date: Sat, 6 Feb 2010 12:06:04 -0800 (PST) Subject: Subclassing datetime.date Message-ID: Hi all, I recently attempted to subclass the datetime.date object resulting in horror and confusion, before submitting to a has-a relationship. That's all fine and dandy, but out of curiosity I'd like to know what I'm missing. I was attempting to allow more flexible instancing of an object, like so: import datetime class MyDate(datetime.date): def __init__(self,*args,**kw): if len(kw) + len(args) > 1: self.construct(*args,**kw) def construct(self,d,m=None,y=None,**kw): today = datetime.date.today() if m is None: m = today.month if y is None: y = today.year datetime.date.__init__(self,y,m,d,**kw) However, it wasn't having the desired effect. Indeed, I could still only instance it with 3 variables lest I get errors, and when I did call it with 3 variables it didn't reflect the order change I had implemented. Indeed, the properties were already set before it even got to the construct method. Is there some kind of built in I'm missing here? Thanks all, Will From wentland at cl.uni-heidelberg.de Sat Feb 6 15:25:40 2010 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Sat, 6 Feb 2010 21:25:40 +0100 Subject: determining which value is the first to appear five times in a list? In-Reply-To: References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> <20100206190901.GB2508@kinakuta.local> Message-ID: <20100206202540.GC2508@kinakuta.local> On Sat, Feb 06, 2010 at 14:42 -0500, Terry Reedy wrote: > On 2/6/2010 2:09 PM, Wolodja Wentland wrote: > >I think you can use the itertools.groupby(L, lambda el: el[1]) to group > >elements in your *sorted* list L by the value el[1] (i.e. the > >identifier) and then iterate through these groups until you find the > >desired number of instances grouped by the same identifier. > This will generally not return the same result. It depends on > whether OP wants *any* item appearing at least 5 times or whether > the order is significant and the OP literally wants the first. Order is preserved by itertools.groupby - Have a look: >>> instances = [(1, 'b'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'c'), (6, 'c'), (7, 'b'), (8, 'b')] >>> grouped_by_identifier = groupby(instances, lambda el: el[1]) >>> grouped_by_identifier = ((identifier, list(group)) for identifier, group in grouped_by_identifier) >>> k_instances = (group for identifier, group in grouped_by_identifier if len(group) == 2) >>> for group in k_instances: ... print group ... [(1, 'b'), (2, 'b')] [(7, 'b'), (8, 'b')] So the first element yielded by the k_instances generator will be the first group of elements from the original list whose identifier appears exactly k times in a row. > Sorting the entire list may also take a *lot* longer. Than what? Am I missing something? Is the "*sorted*" the culprit? If yes -> Just forget it as it is not relevant. -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From alfps at start.no Sat Feb 6 15:31:52 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Feb 2010 21:31:52 +0100 Subject: TABS in the CPython C source code Message-ID: Just trying to delve into the CPython source code. Pleasant surprise: while e.g. the gcc compiler is written in K&R C (1975 style C), CPython seems to be written in almost modern C (1989 and on). But, hey, TABS used for indenting, combined haphazardly and randomly with SPACES used for indenting, in the same source files... The size-8 tabs look really bad in an editor configured with tab size 4, as is common in Windows. I'm concluding that the CPython programmers configure their Visual Studio's to *nix convention. Or perhaps modern Visual Studio has default tab size 8, it wouldn't surprise me (the best version was the MSVC 6.0 Developer Studio, since then that IDE has only gone downhill being re-based on the Office Assistant inspired "for dummies" IDE that Microsoft had for web designers). Anyways, I would suggest converting all those tabs to spaces, as e.g. the Boost library project does -- no tabs allowed. That's much more platform-independent. :-) Cheers, - Alf From david at boddie.org.uk Sat Feb 6 15:52:20 2010 From: david at boddie.org.uk (David Boddie) Date: Sat, 06 Feb 2010 21:52:20 +0100 Subject: PyQt4 designer custom properties - combo box style References: Message-ID: On Saturday 06 February 2010 10:32, Andrew wrote: > I'm attempting to create a drop down property for a custom widget I'm > creating. So when in designer and you scroll down to the custom > properties, under the regular widget properties, one of them would be > a drop down menu. The data to populate it will be coming from our API > and currently is a list of string-items. Yes, it would be treated > specially by Designer, since it's the only place it would be seen. Right. The drop down menus in the property editor usually contain values defined for C++ enums which have been declared to Qt's meta-object system when a C++ library or plugin is compiled. I'm not sure that PyQt can expose lists of Python values in the same way. An example of this is the alignment property in QLineEdit. > In the PyQt4\examples\designer folder, it carries a number of custom > widgets that will load into designer. The datetimeedit widget creates > a custom drop down menu property. The plugin pulls its information > from the QtCore libraries and from the QCalander Widget. Though I am > unable to find a better example or even explanation of how it's > actually creating that drop down menu. Each of the individual properties are just single values, aren't they, not collections of values? >> Have you seen this article? >> >> http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html > > No, I haven't, thanks. That might step in the right direction. I can't > run it right now, so I'm not sure if it is putting a spinbox as it's > property or just the value from the spin box. The value from each spin box is turned into a property, so there are latitude and longitude properties, though each of these only holds a double precision floating point number. It sounds like you want to be able to select from a list of values, or possibly change the values themselves. If it turns out you can't add a property to Qt Designer in the way you want, you can still add a custom editor to the widget so that users can open a context menu and select an item to configure it. This is similar to the way you can open a dialog to edit the text inside QTextEdit widgets. The article I referred to also covers this: http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html#makingamenu David From user at example.net Sat Feb 6 16:02:07 2010 From: user at example.net (monkeys paw) Date: Sat, 06 Feb 2010 16:02:07 -0500 Subject: Last M digits of expression A^N In-Reply-To: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my A and N are too large (10^100) and M is less than > 10^5. The other approach was repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. How do you arrive at log N as the performance number? > > def power(A,N,M): > ret=1 > while(N): > if(N%2!=0):ret=(ret*A)%M > A=(A*A)%M > N=N//2 > return ret From andrej.mitrovich at gmail.com Sat Feb 6 16:05:27 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sat, 6 Feb 2010 13:05:27 -0800 (PST) Subject: TABS in the CPython C source code References: Message-ID: On Feb 6, 9:31?pm, "Alf P. Steinbach" wrote: > Just trying to delve into the CPython source code. > > Pleasant surprise: while e.g. the gcc compiler is written in K&R C (1975 style > C), CPython seems to be written in almost modern C (1989 and on). > > But, hey, TABS used for indenting, combined haphazardly and randomly with SPACES > used for indenting, in the same source files... > > The size-8 tabs look really bad in an editor configured with tab size 4, as is > common in Windows. I'm concluding that the CPython programmers configure their > Visual Studio's to *nix convention. Or perhaps modern Visual Studio has default > tab size 8, it wouldn't surprise me (the best version was the MSVC 6.0 Developer > Studio, since then that IDE has only gone downhill being re-based on the Office > Assistant inspired "for dummies" IDE that Microsoft had for web designers). > > Anyways, I would suggest converting all those tabs to spaces, as e.g. the Boost > library project does ?-- ?no tabs allowed. > > That's much more platform-independent. :-) > > Cheers, > > - Alf So what's stopping you from doing this yourself? From alfps at start.no Sat Feb 6 16:12:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Feb 2010 22:12:05 +0100 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: * Andrej Mitrovic: > On Feb 6, 9:31 pm, "Alf P. Steinbach" wrote: >> Just trying to delve into the CPython source code. >> >> Pleasant surprise: while e.g. the gcc compiler is written in K&R C (1975 style >> C), CPython seems to be written in almost modern C (1989 and on). >> >> But, hey, TABS used for indenting, combined haphazardly and randomly with SPACES >> used for indenting, in the same source files... >> >> The size-8 tabs look really bad in an editor configured with tab size 4, as is >> common in Windows. I'm concluding that the CPython programmers configure their >> Visual Studio's to *nix convention. Or perhaps modern Visual Studio has default >> tab size 8, it wouldn't surprise me (the best version was the MSVC 6.0 Developer >> Studio, since then that IDE has only gone downhill being re-based on the Office >> Assistant inspired "for dummies" IDE that Microsoft had for web designers). >> >> Anyways, I would suggest converting all those tabs to spaces, as e.g. the Boost >> library project does -- no tabs allowed. >> >> That's much more platform-independent. :-) >> >> Cheers, >> >> - Alf > > So what's stopping you from doing this yourself? Depends what "this" you're referring to. If by "this" you mean, automatically converting tabs to spaces on checking out a newer version of a CPython source file, nothing in particular stops anyone from doing that. But it's needless work, and it results in "false positive" changes when checking in something. That's why e.g. Boost standardizes on spaces. If by "this" you mean, changing the coding guidelines (if such exist) for the CPython project, well I'm not involved, so the best I can do is to float the idea and point to existing practice in other projects, which I've now done. :-) Cheers & hth., - Alf From nyamatongwe+thunder at gmail.com Sat Feb 6 16:19:18 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sat, 06 Feb 2010 21:19:18 GMT Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: Alf P. Steinbach: > The size-8 tabs look really bad in an editor configured with tab size 4, > as is common in Windows. I'm concluding that the CPython programmers > configure their Visual Studio's to *nix convention. Most of the core developers use Unix. > Anyways, I would suggest converting all those tabs to spaces, as e.g. > the Boost library project does -- no tabs allowed. This would damage the usefulness of source control histories (svn annotate) as all of the converted lines would show this recent cosmetic change rather than the previous change which is likely to be a substantive modification. Neil From john at castleamber.com Sat Feb 6 16:42:29 2010 From: john at castleamber.com (John Bokma) Date: Sat, 06 Feb 2010 15:42:29 -0600 Subject: Subclassing datetime.date References: Message-ID: <87vdea9h2y.fsf@castleamber.com> Sir Wilhelm the Sturdy writes: F> Hi all, > > I recently attempted to subclass the datetime.date object resulting in > horror and confusion, before submitting to a has-a relationship. > That's all fine and dandy, but out of curiosity I'd like to know what > I'm missing. > > I was attempting to allow more flexible instancing of an object, like > so: > > import datetime > > class MyDate(datetime.date): > > def __init__(self,*args,**kw): > > if len(kw) + len(args) > 1: > self.construct(*args,**kw) > > def construct(self,d,m=None,y=None,**kw): > > today = datetime.date.today() > if m is None: > m = today.month > if y is None: > y = today.year > > datetime.date.__init__(self,y,m,d,**kw) > > > However, it wasn't having the desired effect. Indeed, I could still > only instance it with 3 variables lest I get errors, and when I did > call it with 3 variables it didn't reflect the order change I had > implemented. Indeed, the properties were already set before it even > got to the construct method. __init__ is *not* the construction method, __new__ is (at least with new style classes) > Is there some kind of built in I'm missing here? I guess __new__ but I am quite the newbie. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Sat Feb 6 16:44:56 2010 From: john at castleamber.com (John Bokma) Date: Sat, 06 Feb 2010 15:44:56 -0600 Subject: TABS in the CPython C source code References: Message-ID: <87r5oy9gyv.fsf@castleamber.com> "Alf P. Steinbach" writes: > Just trying to delve into the CPython source code. > > Pleasant surprise: while e.g. the gcc compiler is written in K&R C > (1975 style C), CPython seems to be written in almost modern C (1989 > and on). > > But, hey, TABS used for indenting, combined haphazardly and randomly > with SPACES used for indenting, in the same source files... > > The size-8 tabs look really bad in an editor configured with tab size > 4, as is common in Windows. Then you are either used a broken editor or a misconfigured editor. I've used TextPad for ages, and it can be configured to hard tab 8 (might even be the default [1]). [1] With Perl coding I configured it to indent 4 spaces, hard tab 4 spaces and convert hard tabs to 4 spaces while saving, so no surprises. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From news123 at free.fr Sat Feb 6 16:45:01 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 22:45:01 +0100 Subject: how to add pydoc strings to 'Data and other attributes' Message-ID: <4b6de2de$0$4830$426a74cc@news.free.fr> I'm having some problems with pydoc and I was not very sucessful in googling. (probably missng one key word) Is there soemthing like a documentation of pydoc (execpt pydocs output of pydoc, which doesn't seem to answer my question ) I can add docstrings to - the file head - to a class - to a class function - to a property but I don't know how document a class attribute (like 'name' ) in my example below Does anybody know how to doc it? # file starts here # ############################################################################# # This appears in the python documentation # ############################################################################# __author__ = 'News123' # this will also be part of pydoc """ general blabla will not be part of pydoc""" class MyClass(object): """ This class can be doc-ed """ name = 3 ### I don't know how to document this def get_f(self): """ the function get_f is here """ return 3 f = property(get_f,doc="this property is also documented") ######### file ends here thanks for any help N From arnodel at googlemail.com Sat Feb 6 17:08:55 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 06 Feb 2010 22:08:55 +0000 Subject: Code snippet: dualmethod descriptor References: <0373b8b9$0$1309$c3e8da3@news.astraweb.com> <00f4e6e5$0$15566$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Thu, 04 Feb 2010 00:09:02 -0300, Gabriel Genellina wrote: > >> En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano >> escribi?: >> >>> class dualmethod(object): > [...] > >> Seems useful! >> Perhaps a better place to post it would be >> , at least it's >> easier to search. > > > > Thank you for the encouragement. The recipe is now posted: > > http://code.activestate.com/recipes/577030/ Oddly, in Python 3 you can achieve something a bit similar very simply: >>> class A: ... def foo(self=None): ... return "Instance" if self else "Class" ... >>> A.foo() 'Class' >>> a = A() >>> a.foo() 'Instance' It works in python 3 because unbound methods are plain functions. -- Arnaud From arnodel at googlemail.com Sat Feb 6 17:22:47 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 06 Feb 2010 22:22:47 +0000 Subject: Dreaming of new generation IDE References: Message-ID: "Gabriel Genellina" writes: > En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: >> "Steve Holden" wrote in message >> news:mailman.1998.1265399766.28905.python-list at python.org... >>> Arnaud Delobelle wrote: >>>> Robert Kern writes: >>>> >>>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>>> quote for right now): if you expect that a boolean argument is only >>>>> going to take *literal* True or False, then it should be split into > ^^^^^^^^^^^^^^^^^^^^^^^ >>>>> two functions. >>>> >>>> So rather than three boolean arguments, would you have eight functions? >>>> >>> If there's genuinely a need for that functionality, yes. >> >> So you want a function such as drawtext(s, bold=true, italic=false, >> underline=true) to be split into: >> >> drawtext(s) >> drawtextb(s) >> drawtexti(s) >> drawtextu(s) >> drawtextbi(s) >> drawtextbu(s) >> drawtextiu(s) >> drawtextbiu(s) > > Note the *literal* part. If you (the programmer) is likely to know the > parameter value when writing the code, then the function is actually two > separate functions. Thanks, I understand what Steve Holden meant now. -- Arnaud From roy at panix.com Sat Feb 6 17:23:01 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Feb 2010 17:23:01 -0500 Subject: How to print all expressions that match a regular expression References: Message-ID: In article , "hzhuo1 at gmail.com" wrote: > Hi, > > I am a fresh man with python. I know there is regular expressions in > Python. What I need is that given a particular regular expression, > output all the matches. For example, given ?[1|2|3]{2}? as the regular > expression, the program should output all 9 matches, i.e., "11 12 13 > 21 22 23 31 32 33". > > Is there any well-written routine in Python or third-party program to > do this? If there isn't, could somebody make some suggestions on how > to write it myself? > > Thanks. > > Zhuo Please enumerate all the strings which match ".*". Use additional sheets of paper if needed. From benjamin at python.org Sat Feb 6 17:26:55 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Feb 2010 22:26:55 +0000 (UTC) Subject: TABS in the CPython C source code References: Message-ID: Neil Hodgson gmail.com> writes: > This would damage the usefulness of source control histories (svn > annotate) as all of the converted lines would show this recent cosmetic > change rather than the previous change which is likely to be a > substantive modification. That's not completely true given svn diff -x -w. From benjamin at python.org Sat Feb 6 17:28:17 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Feb 2010 22:28:17 +0000 (UTC) Subject: TABS in the CPython C source code References: Message-ID: Alf P. Steinbach start.no> writes: > Anyways, I would suggest converting all those tabs to spaces This has been discussed to death of Python-dev. We use spaces for all new files and tabs for historical reasons in old files. Mixed ones should be converted one way or the other. > > That's much more platform-independent. From anand.shashwat at gmail.com Sat Feb 6 17:28:44 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 03:58:44 +0530 Subject: Last M digits of expression A^N In-Reply-To: References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: Yes, it can be done. Have a look at : http://en.wikipedia.org/wiki/Modular_exponentiation The algorithm is also mentioned in CLRS.I tried writing my own modular-exponentiation code following CLRS but observed that python pow() function is much more efficient. Have a look at this problem : https://www.spoj.pl/problems/LASTDIG/ as you can see ( https://www.spoj.pl/status/LASTDIG,l0nwlf/ )my first solution used algorithm hard-coded from CLRS which took 0.04 sec however using pow() function directly improved the efficiency to 0.0 So I would suggest to go for pow() unless you intend to learn modular exponentiation algorithm for which hand-coding is a must. here are my solutions : first one (hand-coded): 1. def pow(a, b): 2. if( not b): 3. return 1 4. if( b & 1 ): 5. return ( pow( a, b - 1 ) * a ) % 10 6. 7. tmp = pow( a, b / 2 ) 8. return ( tmp * tmp ) % 10; 9. 10. for i in xrange(input()): 11. a,b = [ int(x) for x in raw_input().split(' ')] 12. print( pow( a % 10, b ) ) second one (pow()): 1. for i in range(int(raw_input())): 2. a,b = [int(x) for x in raw_input().split()] 3. print pow (a,b,10) 4. HTH ~l0nwlf On Sun, Feb 7, 2010 at 2:32 AM, monkeys paw wrote: > mukesh tiwari wrote: > >> Hello everyone. I am kind of new to python so pardon me if i sound >> stupid. >> I have to find out the last M digits of expression.One thing i can do >> is (A**N)%M but my A and N are too large (10^100) and M is less than >> 10^5. The other approach was repeated squaring and taking mod of >> expression. Is there any other way to do this in python more faster >> than log N. >> > > How do you arrive at log N as the performance number? > > > >> def power(A,N,M): >> ret=1 >> while(N): >> if(N%2!=0):ret=(ret*A)%M >> A=(A*A)%M >> N=N//2 >> return ret >> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 6 17:31:28 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 04:01:28 +0530 Subject: Last M digits of expression A^N In-Reply-To: References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: a nice exercise to do can be this problem : http://www.codechef.com/MARCH09/problems/A4/ , it deals with both cases, first and last k digits and can be performed within O(log n) On Sun, Feb 7, 2010 at 3:58 AM, Shashwat Anand wrote: > Yes, it can be done. Have a look at : > http://en.wikipedia.org/wiki/Modular_exponentiation > The algorithm is also mentioned in CLRS.I tried writing my own > modular-exponentiation code following CLRS but observed that python pow() > function is much more efficient. > Have a look at this problem : https://www.spoj.pl/problems/LASTDIG/ > as you can see ( https://www.spoj.pl/status/LASTDIG,l0nwlf/ )my first > solution used algorithm hard-coded from CLRS which took 0.04 sec however > using pow() function directly improved the efficiency to 0.0 So I would > suggest to go for pow() unless you intend to learn modular exponentiation > algorithm for which hand-coding is a must. > > here are my solutions : > first one (hand-coded): > > > 1. def pow(a, b): > 2. if( not b): > 3. return 1 > 4. if( b & 1 ): > 5. return ( pow( a, b - 1 ) * a ) % 10 > > 6. > 7. tmp = pow( a, b / 2 ) > 8. return ( tmp * tmp ) % 10; > 9. > 10. for i in xrange(input()): > 11. a,b = [ int(x) for x in raw_input().split(' ')] > > 12. print( pow( a % 10, b ) ) > > > second one (pow()): > > > 1. for i in range(int(raw_input())): > > 2. a,b = [int(x) for x in raw_input().split()] > > 3. print pow (a,b,10) > 4. > > > HTH > ~l0nwlf > > > On Sun, Feb 7, 2010 at 2:32 AM, monkeys paw wrote: > >> mukesh tiwari wrote: >> >>> Hello everyone. I am kind of new to python so pardon me if i sound >>> stupid. >>> I have to find out the last M digits of expression.One thing i can do >>> is (A**N)%M but my A and N are too large (10^100) and M is less than >>> 10^5. The other approach was repeated squaring and taking mod of >>> expression. Is there any other way to do this in python more faster >>> than log N. >>> >> >> How do you arrive at log N as the performance number? >> >> >> >>> def power(A,N,M): >>> ret=1 >>> while(N): >>> if(N%2!=0):ret=(ret*A)%M >>> A=(A*A)%M >>> N=N//2 >>> return ret >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Feb 6 17:40:53 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 17:40:53 -0500 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <20100206202540.GC2508@kinakuta.local> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> <20100206190901.GB2508@kinakuta.local> <20100206202540.GC2508@kinakuta.local> Message-ID: On 2/6/2010 3:25 PM, Wolodja Wentland wrote: > On Sat, Feb 06, 2010 at 14:42 -0500, Terry Reedy wrote: >> On 2/6/2010 2:09 PM, Wolodja Wentland wrote: > >>> I think you can use the itertools.groupby(L, lambda el: el[1]) to group >>> elements in your *sorted* list L by the value el[1] (i.e. the >>> identifier) and then iterate through these groups until you find the >>> desired number of instances grouped by the same identifier. > >> This will generally not return the same result. It depends on >> whether OP wants *any* item appearing at least 5 times or whether >> the order is significant and the OP literally wants the first. > > Order is preserved by itertools.groupby - Have a look: Sorting does not. > >>>> instances = [(1, 'b'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'c'), (6, 'c'), (7, 'b'), (8, 'b')] >>>> grouped_by_identifier = groupby(instances, lambda el: el[1]) >>>> grouped_by_identifier = ((identifier, list(group)) for identifier, group in grouped_by_identifier) >>>> k_instances = (group for identifier, group in grouped_by_identifier if len(group) == 2) >>>> for group in k_instances: > ... print group > ... > [(1, 'b'), (2, 'b')] > [(7, 'b'), (8, 'b')] > > So the first element yielded by the k_instances generator will be the > first group of elements from the original list whose identifier appears > exactly k times in a row. > >> Sorting the entire list may also take a *lot* longer. > Than what? Than linearly scanning for the first 5x item, as in my corrected version of the original code. Terry Jan Reedy From ben+python at benfinney.id.au Sat Feb 6 17:43:23 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 07 Feb 2010 09:43:23 +1100 Subject: How to print all expressions that match a regular expression References: Message-ID: <87eikykmt0.fsf@benfinney.id.au> Roy Smith writes: > "hzhuo1 at gmail.com" wrote: > > What I need is that given a particular regular expression, output > > all the matches. [?] > Please enumerate all the strings which match ".*". Use additional > sheets of paper if needed. +1 QOTW -- \ ?Are you pondering what I'm pondering?? ?I think so, ... Brain, | `\ but how can we get seven dwarves to shave their legs?? ?_Pinky | _o__) and The Brain_ | Ben Finney From Martin.Drautzburg at web.de Sat Feb 6 17:53:53 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sat, 06 Feb 2010 23:53:53 +0100 Subject: new.instancemethod __iter__ Message-ID: <2036837.yhpURs0z1y@beaureve.gmx.net> Hello all When I create an Object and set its __iter__ method from outside s = Sequence #one of my own classes s.__iter__ = new.instancemethod(f,s,Sequence) I get different results, depending on whether I call for x in y.__iter__(): print x or for x in y: print x The first case does what I expected, i.e. it iterates over whatever f() yields. In the second case nothing is printed. I have the impression that it still calls the original __iter__() method (the one defined at the class level). Why is that so? How can I replace the __iter__() method so it does what I want. The reason I want to do such things is I need to implement operations similar to what itertools do. However I want my own classes and the operations are only similar to itertools, but differ in significant details. From davea at ieee.org Sat Feb 6 17:59:44 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Feb 2010 17:59:44 -0500 Subject: Last M digits of expression A^N In-Reply-To: References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <4B6DF460.8020403@ieee.org> monkeys paw wrote: >
mukesh > tiwari wrote: >> Hello everyone. I am kind of new to python so pardon me if i sound >> stupid. >> I have to find out the last M digits of expression.One thing i can do >> is (A**N)%M but my A and N are too large (10^100) and M is less than >> 10^5. The other approach was repeated squaring and taking mod of >> expression. Is there any other way to do this in python more faster >> than log N. > > How do you arrive at log N as the performance number? > >> >> def power(A,N,M): >> ret=1 >> while(N): >> if(N%2!=0):ret=(ret*A)%M >> A=(A*A)%M >> N=N//2 >> return ret > Because the N= N/2 operation in the loop means that the number of loops is equal to the number of bits in N, or the log-base-2 of N. DaveA From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 18:03:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 23:03:25 GMT Subject: Doctests and decorated methods don't get along References: <037d435d$0$1292$c3e8da3@news.astraweb.com> <4B6DBC4C.4080100@optimum.net> Message-ID: <037de16f$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 14:00:28 -0500, John Posner wrote: > On 2/6/2010 6:48 AM, Steven D'Aprano wrote: >> class MyStaticMethod(object): >> """Emulate built-in staticmethod descriptor.""" >> def __init__(self, f): >> self.f = f >> def __get__(self, obj, objtype=None): >> return self.f > > How about using a function, instead of a class, to implement the > decorator: I've had problems with function decorators and doctest in the past. If I remember the problem correctly, functools.wraps changing the __module__ of the wrapped function, making it look like it came from the functool module, and so doctest would not run the tests. But it seems that has been fixed in 2.6: I can confirm your version works as expected. Nevertheless, I think it is a limitation of doctest that it doesn't see methods using the descriptor protocol. Even if I could work around my immediate issue by using a function decorator (and I don't think I can) I'd still want to fix this problem. > I tried making the class-based implementation work by using > functools.wraps(), but I couldn't manage it. Me neither. I think the problem is that the doctest.DocTestFinder class doesn't find descriptor-based methods. It special cases staticmethod, classmethod and property. > Also, doesn't the decorator > protocol want the class to implement a __call__() method, not a > __get__() method? Or am I getting hung up (not the first time) at the > nexus of the descriptor and decorator protocols? In this case, I'm actually using a descriptor as the decorator. The descriptor is called at attribute lookup, before the method is called. __get__ returns a function, which has a __call__ method, and it should all just work. -- Steven From solipsis at pitrou.net Sat Feb 6 18:30:30 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 6 Feb 2010 23:30:30 +0000 (UTC) Subject: TABS in the CPython C source code References: Message-ID: Le Sat, 06 Feb 2010 22:26:55 +0000, Benjamin Peterson a ?crit?: > Neil Hodgson gmail.com> writes: >> This would damage the usefulness of source control histories (svn >> annotate) as all of the converted lines would show this recent cosmetic >> change rather than the previous change which is likely to be a >> substantive modification. > > That's not completely true given svn diff -x -w. That's even less true given we aren't ashamed to make other kinds of cosmetic changes when desired, even though it also "damages the usefulness of source control histories" ;-) From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 18:35:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 23:35:11 GMT Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> Message-ID: <037de8e1$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 23:53:53 +0100, Martin Drautzburg wrote: > Hello all > > When I create an Object and set its __iter__ method from outside > > s = Sequence #one of my own classes > s.__iter__ = new.instancemethod(f,s,Sequence) I'm confused as to why you are aliasing your class before changing it. The above just makes s an alternative name for Sequence. Did you mean this? s = Sequence() # make an instance of the class > I get different results, depending on whether I call > > > for x in y.__iter__(): > print x What's y? Where does it come from? Is y supposed to be an instance of Sequence? > or > > for x in y: > print x > > The first case does what I expected, i.e. it iterates over whatever f() > yields. In the second case nothing is printed. I have the impression > that it still calls the original __iter__() method (the one defined at > the class level). Yes, that's almost certainly what is happening. As an optimization, Python bypasses the instance for special methods __NAME__. > Why is that so? > How can I replace the __iter__() method so it does what I want. The best solution is, find another way to do what you want. The clunky solution is to use delegation to wrap your class, and have the outer class re-direct calls to special methods to the instance first. > The reason I want to do such things is I need to implement operations > similar to what itertools do. However I want my own classes and the > operations are only similar to itertools, but differ in significant > details. I don't understand this. If you want iterator operations "similar to itertools", why does this mean you need to replace anything? Just create your own iterators. Or use pre-processing and post-processing to get what you want. Can you show an example of what you would like to happen? -- Steven From jonny.lowe.12345 at gmail.com Sat Feb 6 18:41:09 2010 From: jonny.lowe.12345 at gmail.com (jonny lowe) Date: Sat, 6 Feb 2010 15:41:09 -0800 (PST) Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> Message-ID: On Feb 5, 11:10?pm, "Gabriel Genellina" wrote: > En Fri, 05 Feb 2010 17:39:07 -0300, jonny lowe > escribi?: > > > > > > > On Feb 4, 8:20 pm, exar... at twistedmatrix.com wrote: > >> On 01:56 am, jonny.lowe.12... at gmail.com wrote: > >> >What I want is to have an easy way tomergeinput.txt and thestdout > >> >so that output.txt look like: > > >> >Enter a number: 42 > >> >You entered 42. > > >> >Here, the first 42 is of course from input.txt. > > >> It sounds like you might be looking forscript(1)? > > > $ script -c "./y < input.txt" output.txt > > Script started, file is output.txt > > gimme x:you entered hello > > Script done, file is output.txt > > Try moving the redirection out of the command: > > $ script -c ./y output.txt < input.txt > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - The result is the same as before. I've tested in fedora11. -jon From dickinsm at gmail.com Sat Feb 6 18:43:35 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 6 Feb 2010 15:43:35 -0800 (PST) Subject: Last M digits of expression A^N References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <0c50037a-8cb0-4948-9978-46f4a56fb3da@l19g2000yqb.googlegroups.com> On Feb 5, 8:14?pm, mukesh tiwari wrote: > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > 10^5. The other approach ? was ?repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. By the way, given that your M is fairly tiny compared with A and N, a little bit of elementary number theory (e.g., Euler's theorem) could save you a lot of time here. For example, pow(a, n, 10**5) is equivalent to pow(a, 5 + (n - 5) % 40000, 10**5) for any n >= 5. Not sure if this is the kind of thing you're looking for. -- Mark From lists at cheimes.de Sat Feb 6 18:54:44 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 07 Feb 2010 00:54:44 +0100 Subject: new.instancemethod __iter__ In-Reply-To: <2036837.yhpURs0z1y@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> Message-ID: <4B6E0144.8090603@cheimes.de> Martin Drautzburg wrote: > The first case does what I expected, i.e. it iterates over whatever f() > yields. In the second case nothing is printed. I have the impression > that it still calls the original __iter__() method (the one defined at > the class level). > > Why is that so? > How can I replace the __iter__() method so it does what I want. Virtually all __magic__ methods are looked up on the type, not the instance. So obj.__iter__() translates into type(obj).__iter__(obj). If you *really* need to overwrite __iter__ on your instance rather than defining it on your class, you need to proxy the method call: class MyObject(object): def __iter__(self): return self.myiter() obj = MyObject() obj.myiter = myiter That should do the trick. Christian From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 18:58:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 23:58:07 GMT Subject: Doctests and decorated methods don't get along References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <037dee41$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 14:39:00 -0500, Terry Reedy wrote: > On 2/6/2010 6:48 AM, Steven D'Aprano wrote: >> It seems that doctest doesn't discover or execute doctests in methods >> which have been decorated. [...] > Doctest has to scan the dict, so it does not see the attribute-lookup > result. Ahaha, now we're getting somewhere. If I do this: >>> import inspect >>> import test_doctests >>> method3 = test_doctests.Test.__dict__['method3'] >>> inspect.isfunction(method3) False >>> inspect.ismethod(method3) False But: >>> inspect.ismethoddescriptor(method3) True which is what I want to see. Presumably doctest.DocTestFinder needs a patch to call methoddescriptor's __get__ method. (BTW, classmethod, staticmethod and property are all special-cased by DocTestFinder.) -- Steven From hzhuo1 at gmail.com Sat Feb 6 19:05:15 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sat, 6 Feb 2010 16:05:15 -0800 (PST) Subject: How to print all expressions that match a regular expression References: Message-ID: Thanks for your reply. So there isn't such a routine just because some of the regular expressions cannot be enumerated. However, some of them can be enumerated. I guess I have to write a function myself. Zhuo On Feb 6, 5:23?pm, Roy Smith wrote: > In article > , > > > > > > ?"hzh... at gmail.com" wrote: > > Hi, > > > I am a fresh man with python. I know there is regular expressions in > > Python. What I need is that given a particular regular expression, > > output all the matches. For example, given ?[1|2|3]{2}? as the regular > > expression, the program should output all 9 matches, i.e., "11 12 13 > > 21 22 23 31 32 33". > > > Is there any well-written routine in Python or third-party program to > > do this? If there isn't, could somebody make some suggestions on how > > to write it myself? > > > Thanks. > > > Zhuo > > Please enumerate all the strings which match ".*". ?Use additional sheets > of paper if needed. From news123 at free.fr Sat Feb 6 19:07:49 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 01:07:49 +0100 Subject: sshd in python for windows 7 Message-ID: <4b6e0455$0$20650$426a34cc@news.free.fr> Hi, I wondered which modules would be best to perform following task: A user uses a standard ssh (e.g. putty or openssh) client and performs an ssh to a windows host The windows host would run a python script acting as ssh server. Instead of controlling a shell the user would directly have access to stdin/stdout/stderr of another python script. Another option would of course be to install a non python sshd for windows. The only ssh server for windows, that I know is however a little heavy as it is openssh under cygwin (and I only used it on XP hosts.) I'm still not sure, whether python as sshd is a good choice or whether any other sshd would be better. bye N From news123 at free.fr Sat Feb 6 19:24:33 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 01:24:33 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows In-Reply-To: References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: <4b6e0841$0$22047$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: > >> I'm using an XMLRPC server under Windows. >> >> What I wonder is how I could create a server, that can be killed with >> CTRL-C >> >> The server aborts easily with CTRL-BREAK but not with CTRL-C (under >> Windows) >> >> If I press CTRL-C it will only abort when the next RPC call occurs. >> It seems it is blocking in the select() call in the handle_request() >> function. > > Python 2.6 and up behaves exactly as you want. > On previous versions you may use this: > > class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): > > ... your methods ... > > if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): > > # pre 2.6 > quit = False > > def serve_forever(self): > while not self.quit: > self.handle_request() > > def shutdown(self): > self.quit = True > > def server_bind(self): > self.socket.settimeout(1.0) > SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) > Overloading server_bind() with your version solved my problem. thanks again N From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 19:26:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 00:26:36 GMT Subject: How to print all expressions that match a regular expression References: Message-ID: <037df4ef$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1 at gmail.com wrote: > Thanks for your reply. > So there isn't such a routine just because some of the regular > expressions cannot be enumerated. However, some of them can be > enumerated. I guess I have to write a function myself. How do you expect to tell the ones that can be enumerated apart from those that can't be? Regular expressions are programs in a "regex" programming language. What you are asking for is the same as saying: "Is there a program that can enumerate every possible set of data that is usable as valid input for a given program?" This, in turn, is equivalent to the Halting Problem -- if you can solve one, you can solve the other. You might like to google on the Halting Problem before you spend too much time on this. (Note, however, it isn't necessary to solve the Halting Problem for *all* cases in order to have a useful Endless Loop Detector program.) Why do you think you need this? Seems to me you're starting on an extraordinarily difficult job. I hope the benefit is equally extraordinary. [Aside: Python regexes aren't Turing Complete. I'm not sure about Perl regexes. Either way, this might actually be less difficult than the Halting Problem, as in "amazingly difficult" rather than "impossible".] -- Steven From jeanmichel at sequans.com Sat Feb 6 19:48:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sun, 07 Feb 2010 01:48:22 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: <1265400942.3301.14.camel@linux-m3mt> References: <4B6C4150.8050705@sequans.com> <4B6C5444.4090205@sequans.com> <1265400942.3301.14.camel@linux-m3mt> Message-ID: <4B6E0DD6.1000908@sequans.com> Adam Tauno Williams wrote: > On Fri, 2010-02-05 at 18:24 +0100, Jean-Michel Pichavant wrote: > >> Jean-Michel Pichavant wrote: >> >>> Deos anyone knows where to find an code sample describing how to >>> implement the interface to marshall one object into XMLRPC compliant >>> structures ? >>> I googled without any success, and what google does not find does not >>> exist. >>> Let say I have this very simple class: >>> class Point: >>> def __init__(self, x, y): >>> self.x = x >>> self.y = y >>> I've looked into xmlrpc code, I see 2 options: >>> 1/ override the Marshaller class of client and server >>> 2/ looks like the lib is supporting a WRAPPER list system, it uses to >>> Marshall Datetime & Binary object. Can it be possible to add its own >>> class (could require to emplement the 'encode' method) >>> I sense I will spend much more time than required unless someone is >>> pointing me in the right direction. >>> >> I realized I gave a poor example, actually the Point object is marshable >> (marshallable ? like to invent new words), xmlrpc will try to marshall >> using __dict__ if possible. >> import os >> class Point: >> def __init__(self, x, y): >> self.x = x >> self.y = y >> self.notMarshallable = os >> > > This example doesn't make any sense. Why would you set a variable equal > to an important module in a class named Point? > > What is it you are actually trying to accomplish? If you are trying to > create an object publishing environment then maybe something like - > > rpc = xmlrpclib.loads(payload, use_datetime=True) > method = rpc[1].split('.') > classname = method[0] > methodname = method[1] > parameters = rpc[0] > classclass = eval(classname) > handler = classclass() > call = getattr(handler, method_name) > result = apply(call, parameters) > result = xmlrpclib.dumps(tuple([result]), methodresponse=True) > > Obviously add copious amounts of exception handling and a security > model. > I just took the first non marshallable object that came to my mind. So yes that makes no sense but it was an example. I'll try to sitck to what I'm really trying to do. I have 2 classes, defined on server side class Pool: def foo(): return 42 class Stream: def __init__(self, pool): """@param pool: the pool the stream belongs so.""" self._pool = pool I won't need any more detail I think for my example. Now If I want to return a stream, sending it to the client, I can't because xmlrpclib won't be able to marshall _pool. What I need is the sever being able to marshall a Stream. I would like to overide the marshall method of that stream, so that instead of raising an error because self._pool is not marshallable, it sends an int instead identifying the pool on the server side. class Pool: instances = {} when marshalling a stream: id = some_unique_generated_int() Pool.instances[id] = self._pool self._pool = id # an int will be gracefully marshalled by the defaut marshaller # call here the default marshaller Then, when unmarshalling, the server can reassign the _pool reference using the id provided by the client. I hope I am being clear. JM From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 19:51:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 00:51:19 GMT Subject: Doctests and decorated methods don't get along References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <037dfaba$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 14:39:00 -0500, Terry Reedy wrote: > On 2/6/2010 6:48 AM, Steven D'Aprano wrote: >> It seems that doctest doesn't discover or execute doctests in methods >> which have been decorated [by method descriptors]. [...] >> This looks like bug to me. Have I missed anything? > > I would call it a limitation as I do not see the doc as promising > otherwise. I believe doctest predates the descripter protocol, at least > in its current form, so it may not be completely descriptor-aware. You > certainly could file a feature request for improved recognition and > subsequent calling of __get__. An initial patch would improve chances of > action. I have found an existing report for this issue: http://bugs.python.org/issue4037 The original poster's suggested fix was on the right track, but not complete. I've added a patch which works according to my tests. Since this report is currently unassigned, is there a protocol for raising its profile and having somebody check my patch for inclusion? Should I just send an email to python-dev? -- Steven From alfps at start.no Sat Feb 6 19:51:19 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 01:51:19 +0100 Subject: How to print all expressions that match a regular expression In-Reply-To: <037df4ef$0$1292$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1 at gmail.com wrote: > >> Thanks for your reply. >> So there isn't such a routine just because some of the regular >> expressions cannot be enumerated. However, some of them can be >> enumerated. I guess I have to write a function myself. > > How do you expect to tell the ones that can be enumerated apart from > those that can't be? > > Regular expressions are programs in a "regex" programming language. What > you are asking for is the same as saying: > > "Is there a program that can enumerate every possible set of data that is > usable as valid input for a given program?" > > This, in turn, is equivalent to the Halting Problem -- if you can solve > one, you can solve the other. You might like to google on the Halting > Problem before you spend too much time on this. Hm, well, text editors /regularly/ do repeated regular expression searches, producing match after match after match, on request. To use that /expression/, it seems that Theory is yet again up against Hard Reality. In such a contest where something doesn't quite /match/, is the Map, the Terrain, or perhaps the Interpretation of how the Map applies to Terrain, at fault? > (Note, however, it isn't necessary to solve the Halting Problem for *all* > cases in order to have a useful Endless Loop Detector program.) > > Why do you think you need this? Seems to me you're starting on an > extraordinarily difficult job. I hope the benefit is equally > extraordinary. Depending on the application there may be more efficient ways than applying a general purpose regexp matcher. Don't know about modern *nix but in the old days there were different greps for different purposes, egrep, fgrep, whatever. Aside: the only article by Niklaus Wirth that I can remember reading was about how to transform algorithms to more efficient ones by exploiting the invariants, and one of his examples was simple text searching, where you can advance the pattern a number of characters depending on the current non-matching character. > [Aside: Python regexes aren't Turing Complete. I'm not sure about Perl > regexes. Either way, this might actually be less difficult than the > Halting Problem, as in "amazingly difficult" rather than "impossible".] Cheers, - Alf From buzzard at urubu.freeserve.co.uk Sat Feb 6 19:52:48 2010 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sun, 07 Feb 2010 00:52:48 +0000 Subject: max / min / smallest float value on Python 2.5 Message-ID: Hello, I'm trying to find a clean and reliable way of uncovering information about 'extremal' values for floats on versions of Python earlier than 2.6 (just 2.5 actually). I don't want to add a dependence on 3rd party modules just for this purpose. e.g. For the smallest positive float I'm using, import platform if platform.architecture()[0].startswith('64'): TINY = 2.2250738585072014e-308 else: TINY = 1.1754943508222875e-38 where I've extracted the values for TINY from numpy in IDLE, >>> float(numpy.finfo(numpy.float32).tiny) 1.1754943508222875e-38 >>> float(numpy.finfo(numpy.float64).tiny) 2.2250738585072014e-308 >>> I'm not 100% sure how reliable this will be across platforms. Any ideas about the cleanest, reliable way of uncovering this type of information? (I can always invoke numpy, or use Python 2.6, on my home machine and hardcode the retrieved values, but I need the code to run on 2.5 without 3rd part dependencies.) Cheers. Duncan From steve at holdenweb.com Sat Feb 6 19:54:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Feb 2010 19:54:54 -0500 Subject: Your beloved python features In-Reply-To: <4b6c2095$0$22370$426a74cc@news.free.fr> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c2095$0$22370$426a74cc@news.free.fr> Message-ID: <4B6E0F5E.10503@holdenweb.com> Bruno Desthuilliers wrote: > apeach a ?crit : >> I love intuitive type recognition. >> >> no need to 'DIM everything AS Integer' etc.! >> > > not to mention the ever hilarious (that is, when you don't have to > maintain it) typical Java idiom: > > EveryThing theEveryThing = new EveryThing(); > http://www.artima.com/weblogs/viewpost.jsp?thread=42242 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Sat Feb 6 20:15:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sun, 07 Feb 2010 02:15:48 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6c9b28$0$10494$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> Message-ID: <4B6E1444.9060001@sequans.com> News123 wrote: > Hi JM, > > Jean-Michel Pichavant wrote: > >> import socket >> >> # server >> server = SimpleXMLRPCServer((socket.gethostname(), 5000), >> logRequests=False, allow_none=True) >> >> >> # client >> xmlrpclib.ServerProxy("http://%s.yourdomain.com:%s" % >> (socket.gethostname(), 5000)) >> > > > Well This was exactly my question. > for virtual web servers I cannot just use the IP-address. > some XMLRPC servers do need the histname within the HTTP-POST request. > > a valid IP address would make it > if I just replaced the hostname with the IP addres, then certain servers > would not be accessable. > > I had to use the IP-address for connecteing why not using the host names? > , but to pass the hostname in > the HTTP-POST request. > > I wondered how to convince puthon's SimpleXMLRPCServer (or any other > standard python xmlrpc server), such, that I can obtain above mentioned > goal. > > > bye > > N > I'm puzzled. Unless my english is failing me, everything would be solved using hostnames if I follow you. Why don't you do that ? I am no network/IP guru, but it sounds very weird to have requests rejected when using IP addresses. Are you sure your host names are resolved with the same IPM address you are using ? JM From anand.shashwat at gmail.com Sat Feb 6 20:17:34 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 06:47:34 +0530 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: On Sun, Feb 7, 2010 at 6:22 AM, duncan smith wrote: > Hello, > I'm trying to find a clean and reliable way of uncovering information > about 'extremal' values for floats on versions of Python earlier than 2.6 > (just 2.5 actually). I don't want to add a dependence on 3rd party modules > just for this purpose. e.g. For the smallest positive float I'm using, > > > import platform > if platform.architecture()[0].startswith('64'): > TINY = 2.2250738585072014e-308 > else: > TINY = 1.1754943508222875e-38 > The above code is executed on OSX (snow leopard - 64 bit) without any issue. Your implementation seems fine to me. > > > where I've extracted the values for TINY from numpy in IDLE, > > > >>> float(numpy.finfo(numpy.float32).tiny) > 1.1754943508222875e-38 > >>> float(numpy.finfo(numpy.float64).tiny) > 2.2250738585072014e-308 > >>> > > > I'm not 100% sure how reliable this will be across platforms. Any ideas > about the cleanest, reliable way of uncovering this type of information? (I > can always invoke numpy, or use Python 2.6, on my home machine and hardcode > the retrieved values, but I need the code to run on 2.5 without 3rd part > dependencies.) Cheers. > > Duncan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sat Feb 6 20:21:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Feb 2010 17:21:15 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c2095$0$22370$426a74cc@news.free.fr> Message-ID: <7xaavlet84.fsf@ruckus.brouhaha.com> Steve Holden writes: >> EveryThing theEveryThing = new EveryThing(); > http://www.artima.com/weblogs/viewpost.jsp?thread=42242 Pretty cool! I see your blog post criticizing Java's lack of type inference, and then immediately adjacent to the post there's a banner ad for a book called "Programming in Scala". I think I am getting a mixed message ;-) From benjamin.kaplan at case.edu Sat Feb 6 20:23:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 6 Feb 2010 20:23:16 -0500 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: On Sat, Feb 6, 2010 at 7:52 PM, duncan smith wrote: > Hello, > ? ? ?I'm trying to find a clean and reliable way of uncovering information > about 'extremal' values for floats on versions of Python earlier than 2.6 > (just 2.5 actually). ?I don't want to add a dependence on 3rd party modules > just for this purpose. ?e.g. For the smallest positive float I'm using, > > > import platform > if platform.architecture()[0].startswith('64'): > ? ?TINY = 2.2250738585072014e-308 > else: > ? ?TINY = 1.1754943508222875e-38 > > > where I've extracted the values for TINY from numpy in IDLE, > > >>>> float(numpy.finfo(numpy.float32).tiny) > 1.1754943508222875e-38 >>>> float(numpy.finfo(numpy.float64).tiny) > 2.2250738585072014e-308 >>>> > > > I'm not 100% sure how reliable this will be across platforms. ?Any ideas > about the cleanest, reliable way of uncovering this type of information? ?(I > can always invoke numpy, or use Python 2.6, on my home machine and hardcode > the retrieved values, but I need the code to run on 2.5 without 3rd part > dependencies.) ?Cheers. > > Duncan >>> import platform >>> platform.architecture() ('32bit', '') >>> tiny = 2.22e-308 >>> tiny 2.2200000000000001e-308 float32 vs. float64 has nothing to do with a 32-bit vs. a 64-bit platform. It's single precision floating-point (C float) vs. double-precision floating point (C double). It's used in numpy because numpy optimizes everything like crazy. Python always uses doubles. >>> import numpy >>> numpy.double > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 20:28:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 01:28:47 GMT Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: <037e0381$0$1292$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 01:51:19 +0100, Alf P. Steinbach wrote: >> Regular expressions are programs in a "regex" programming language. >> What you are asking for is the same as saying: >> >> "Is there a program that can enumerate every possible set of data that >> is usable as valid input for a given program?" >> >> This, in turn, is equivalent to the Halting Problem -- if you can solve >> one, you can solve the other. You might like to google on the Halting >> Problem before you spend too much time on this. > > Hm, well, text editors /regularly/ do repeated regular expression > searches, producing match after match after match, on request. I think you have completely misunderstood what I'm saying. I'm not saying that you can't *run* a regular expression against text and generate output. That truly would be a stupid thing to say, because I clearly can do this: >>> import re >>> mo = re.search("p.rr.t", ... "Some text containing parrots as well as other things") >>> mo.group() 'parrot' As you point out, it's not hard to embed a regex interpreter inside a text editor or other application, or to call an external library. What is difficult, and potentially impossible, is to take an arbitrary regular expression such as "p.rr.t" (the program in the regex language) and generate every possible data ("parrot", "pbrrat", ...) that would give a match when applied to that regular expression. Now, in this case, my example is very simple, and it would be easy to enumerate every possible data: there's only 65025 of them, limiting to the extended ASCII range excluding NUL (1-255). But for an arbitrary regex, it won't be that easy. Often it will be unbounded: the example of enumerating every string that matches .* has already been given. The second problem is, generating the data which gives the output you want is potentially very, very, difficult, potentially as difficult as finding collisions in cryptographic hash functions: "Given the function hashlib.sha256, enumerate all the possible inputs that give the hexadecimal result 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." This too is unbounded, but you'll have your work cut out just to find *one* match, let alone an infinite number of them. (In this specific example, your best bet is to try a crib: knowing what newsgroup this is, and knowing what I've written in the past, the message is predictable for being totally unexpected. And yes, that's a hint. A shiny penny for the first person to guess what it is.) I'm suggesting that, in general, there's no way to tell in advance which regexes will be easy and which will be hard, and even when they are easy, the enumeration will often be infinite. -- Steven From bartc at freeuk.com Sat Feb 6 20:34:14 2010 From: bartc at freeuk.com (bartc) Date: Sun, 07 Feb 2010 01:34:14 GMT Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: "Arnaud Delobelle" wrote in message news:m28wb6ypfs.fsf at googlemail.com... > "Gabriel Genellina" writes: > >> En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: >>> "Steve Holden" wrote in message >>> news:mailman.1998.1265399766.28905.python-list at python.org... >>>> Arnaud Delobelle wrote: >>>>> Robert Kern writes: >>>>> >>>>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>>>> quote for right now): if you expect that a boolean argument is only >>>>>> going to take *literal* True or False, then it should be split into >> ^^^^^^^^^^^^^^^^^^^^^^^ >>>>>> two functions. >>>>> >>>>> So rather than three boolean arguments, would you have eight >>>>> functions? >>>>> >>>> If there's genuinely a need for that functionality, yes. >>> >>> So you want a function such as drawtext(s, bold=true, italic=false, >>> underline=true) to be split into: >>> >>> drawtext(s) >>> drawtextb(s) >>> drawtexti(s) >>> drawtextu(s) >>> drawtextbi(s) >>> drawtextbu(s) >>> drawtextiu(s) >>> drawtextbiu(s) >> >> Note the *literal* part. If you (the programmer) is likely to know the >> parameter value when writing the code, then the function is actually two >> separate functions. > > Thanks, I understand what Steve Holden meant now. I've just noticed that 'literal' part. But I think I still disagree. For a real-world example, it means instead of having a room with a light-switch in it, if I *know* I want the light on or off, I should have two rooms: one with the light permanently on, and one with it permanently off, and just walk into the right one. -- Bartc From jeanmichel at sequans.com Sat Feb 6 20:36:34 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sun, 07 Feb 2010 02:36:34 +0100 Subject: Calendar GUI In-Reply-To: <4B6D055A.30901@gmail.com> References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> <4B6D055A.30901@gmail.com> Message-ID: <4B6E1922.4030404@sequans.com> Michael Torrie wrote: > Gabriel wrote: > >> On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: >> >>> I'm working on setting up some software for a Peruvian non-profit to help >>> them organize their incoming volunteers. One of the features I'd like to add >>> is a calendar-like view of the different volunteers arrival dates and >>> staying time, with potentially some other info through some double-click >>> action. Rather than writing a calendar gui myself, is there some open-source >>> calendar program you guys could recommend that I could plug into? It has to >>> be run locally, as the internet isn't so reliable down here, but other than >>> that something simple and clean is ideal. >>> >> I wrote a gtk gui for google calendar. >> >> Maybe you can adapt it to your needs. >> >> http://code.google.com/p/googlecalendar-gtk/ >> > > Would this work without an internet connection? The original poster > stated that internet isn't so reliable, hence the need for a local solution. > > How about zimbra ? http://www.zimbra.com/products/calendar-collaboration.html Ok, that's heavy stuff, but it's free, open source and widely used. JM From python at mrabarnett.plus.com Sat Feb 6 20:48:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Feb 2010 01:48:12 +0000 Subject: How to print all expressions that match a regular expression In-Reply-To: References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B6E1BDC.5090002@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1 at gmail.com wrote: >> >>> Thanks for your reply. >>> So there isn't such a routine just because some of the regular >>> expressions cannot be enumerated. However, some of them can be >>> enumerated. I guess I have to write a function myself. >> >> How do you expect to tell the ones that can be enumerated apart from >> those that can't be? >> >> Regular expressions are programs in a "regex" programming language. >> What you are asking for is the same as saying: >> >> "Is there a program that can enumerate every possible set of data that >> is usable as valid input for a given program?" >> >> This, in turn, is equivalent to the Halting Problem -- if you can >> solve one, you can solve the other. You might like to google on the >> Halting Problem before you spend too much time on this. > > Hm, well, text editors /regularly/ do repeated regular expression > searches, producing match after match after match, on request. > [snip] I'm not sure you understood what the OP was requesting: a way of generating the strings which would match a given regex. From lists at cheimes.de Sat Feb 6 20:55:48 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 07 Feb 2010 02:55:48 +0100 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: <4B6E1DA4.2060908@cheimes.de> duncan smith wrote: > Hello, > I'm trying to find a clean and reliable way of uncovering > information about 'extremal' values for floats on versions of Python > earlier than 2.6 (just 2.5 actually). I don't want to add a dependence > on 3rd party modules just for this purpose. e.g. For the smallest > positive float I'm using, > > > import platform > if platform.architecture()[0].startswith('64'): > TINY = 2.2250738585072014e-308 > else: > TINY = 1.1754943508222875e-38 > > > where I've extracted the values for TINY from numpy in IDLE, > > > >>> float(numpy.finfo(numpy.float32).tiny) > 1.1754943508222875e-38 > >>> float(numpy.finfo(numpy.float64).tiny) > 2.2250738585072014e-308 You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's float type is build upon C's double precision float type on both 32 and 64 bit builds. The simple precision 32bit float type isn't used. The DBL_MIN and DBL_MAX values are equal on all platforms that have full IEEE 754 float point support. The radix may be different, though. Christian From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 20:57:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 01:57:24 GMT Subject: Dreaming of new generation IDE References: Message-ID: <037e0a36$0$1292$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 01:34:14 +0000, bartc wrote: > For a real-world example, it means instead of having a room with a > light-switch in it, if I *know* I want the light on or off, I should > have two rooms: one with the light permanently on, and one with it > permanently off, and just walk into the right one. I don't think you can apply real-world analogies to software in that way. They're too different. Think of the objections to having two rooms, one permanently lit up, the other permanently not: (1) Having two rooms is expensive and wasteful of physical space, which is in short supply. (2) You typically use rooms for storing things (furniture and smaller objects), having two rooms mean you would need to clone every object inside it and somehow keep them in perfect synchronisation. (3) the light that is always on will use electricity 24 hours a day, regardless of whether you are inside it or not. But none of those objections apply to functions: (1) Functions are cheap and live in memory, which is not in short supply unless you're programming for an embedded device. (1a) Even if you are programming in a device that is short of memory, the overhead of a second function is minimal. There's little difference between: def func(flag): if flag: blockA else: blockB and def funcA(): blockA def funcB(): blockB for any non-trivial code blocks, particularly if any common code is factored out into another function which you call. (2) Functions aren't typically used for storage, and when they need external data, it is easy to have them access a common data store. (3) Functions don't use CPU cycles just by existing. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 21:09:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 02:09:53 GMT Subject: max / min / smallest float value on Python 2.5 References: Message-ID: <037e0d22$0$1292$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 00:52:48 +0000, duncan smith wrote: > Hello, > I'm trying to find a clean and reliable way of uncovering > information about 'extremal' values for floats on versions of Python > earlier than 2.6 (just 2.5 actually). I don't want to add a dependence > on 3rd party modules just for this purpose. e.g. For the smallest > positive float I'm using, Assuming that your architecture is based on binary floats: >>> x = 1.0/2 >>> while 0.0 + x != 0.0: ... smallest = x ... x /= 2.0 ... >>> smallest 4.9406564584124654e-324 which is the smallest number that can be distinguished from zero on my system. If you're running on some weird platform with non-binary floats (perhaps a Russian ternary mainframe, or an old supercomputer with decimal floats) then you're on your own. I calculated this using Python 2.5. In 2.6, I see this: >>> sys.float_info sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.2204460492503131e-16, radix=2, rounds=1) So there's obviously a difference between how I calculate the smallest number and what Python thinks. The reason for this is left as an exercise. -- Steven From invalid at invalid.invalid Sat Feb 6 21:44:27 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Feb 2010 02:44:27 +0000 (UTC) Subject: How to print all expressions that match a regular expression References: Message-ID: On 2010-02-06, Roy Smith wrote: >> I am a fresh man with python. I know there is regular expressions in >> Python. What I need is that given a particular regular expression, >> output all the matches. [..] > Please enumerate all the strings which match ".*". Use additional sheets > of paper if needed. And be sure to show your work. -- Grant From alfps at start.no Sat Feb 6 21:53:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 03:53:49 +0100 Subject: How to print all expressions that match a regular expression In-Reply-To: <037e0381$0$1292$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sun, 07 Feb 2010 01:51:19 +0100, Alf P. Steinbach wrote: > >>> Regular expressions are programs in a "regex" programming language. >>> What you are asking for is the same as saying: >>> >>> "Is there a program that can enumerate every possible set of data that >>> is usable as valid input for a given program?" >>> >>> This, in turn, is equivalent to the Halting Problem -- if you can solve >>> one, you can solve the other. You might like to google on the Halting >>> Problem before you spend too much time on this. >> Hm, well, text editors /regularly/ do repeated regular expression >> searches, producing match after match after match, on request. > > I think you have completely misunderstood what I'm saying. Yes. > I'm not saying that you can't *run* a regular expression against text and > generate output. That truly would be a stupid thing to say, because I > clearly can do this: > >>>> import re >>>> mo = re.search("p.rr.t", > ... "Some text containing parrots as well as other things") >>>> mo.group() > 'parrot' > > As you point out, it's not hard to embed a regex interpreter inside a > text editor or other application, or to call an external library. > > What is difficult, and potentially impossible, is to take an arbitrary > regular expression such as "p.rr.t" (the program in the regex language) > and generate every possible data ("parrot", "pbrrat", ...) that would > give a match when applied to that regular expression. Hm, that's not difficult to do, it's just like counting, but it's rather meaningless since either the output is trivial or it's in general exponential or infinite. So it seems we both misunderstood the problem. I didn't read the top level article until now, and reading it, I can't make sense of it. It sounds like some kind of homework problem, but without the constraints that surely would be there in a homework problem. > Now, in this case, my example is very simple, and it would be easy to > enumerate every possible data: there's only 65025 of them, limiting to > the extended ASCII range excluding NUL (1-255). But for an arbitrary > regex, it won't be that easy. Often it will be unbounded: the example of > enumerating every string that matches .* has already been given. > > The second problem is, generating the data which gives the output you > want is potentially very, very, difficult, potentially as difficult as > finding collisions in cryptographic hash functions: > > "Given the function hashlib.sha256, enumerate all the possible inputs > that give the hexadecimal result > 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." I tried some "parrot" variants but no dice. :-( [snip] > I'm suggesting that, in general, there's no way to tell in advance which > regexes will be easy and which will be hard, and even when they are easy, > the enumeration will often be infinite. I agree about the (implied) meaningless, exponential/infinite output, which means that possibly that's not what the OP meant, but disagree about the reasoning about "no way": really, regular expressions are /very/ limited so it's not hard to compute up front the number of strings it can generate from some given character set, in time linear in the length of the regexp. Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation that denotes "digit sequence") yields an infinite number of strings. And otherwise the regexp is of the form ABCDE..., where A, B, C etc are parts that each can generate a certain finite number of strings; multiplying these numbers gives the total number of strings that the regexp can generate. Cheers, - Alf From buzzard at urubu.freeserve.co.uk Sat Feb 6 22:02:05 2010 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sun, 07 Feb 2010 03:02:05 +0000 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: Christian Heimes wrote: > duncan smith wrote: >> Hello, >> I'm trying to find a clean and reliable way of uncovering >> information about 'extremal' values for floats on versions of Python >> earlier than 2.6 (just 2.5 actually). I don't want to add a dependence >> on 3rd party modules just for this purpose. e.g. For the smallest >> positive float I'm using, >> >> >> import platform >> if platform.architecture()[0].startswith('64'): >> TINY = 2.2250738585072014e-308 >> else: >> TINY = 1.1754943508222875e-38 >> >> >> where I've extracted the values for TINY from numpy in IDLE, >> >> >> >>> float(numpy.finfo(numpy.float32).tiny) >> 1.1754943508222875e-38 >> >>> float(numpy.finfo(numpy.float64).tiny) >> 2.2250738585072014e-308 > > You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's > float type is build upon C's double precision float type on both 32 and > 64 bit builds. The simple precision 32bit float type isn't used. The > DBL_MIN and DBL_MAX values are equal on all platforms that have full > IEEE 754 float point support. The radix may be different, though. > > Christian OK, this is the sort of confusion I suspected. I wasn't thinking straight. The precise issue is that I'm supplying a default value of 2.2250738585072014e-308 for a parameter (finishing temperature for a simulated annealing algorithm) in an application. I develop on Ubuntu64, but (I am told) it's too small a value when run on a Win32 server. I assume it's being interpreted as zero and raising an exception. Thanks. Duncan From alfps at start.no Sat Feb 6 22:04:03 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 04:04:03 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <037e0a36$0$1292$c3e8da3@news.astraweb.com> References: <037e0a36$0$1292$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sun, 07 Feb 2010 01:34:14 +0000, bartc wrote: > >> For a real-world example, it means instead of having a room with a >> light-switch in it, if I *know* I want the light on or off, I should >> have two rooms: one with the light permanently on, and one with it >> permanently off, and just walk into the right one. > > I don't think you can apply real-world analogies to software in that way. > They're too different. > > Think of the objections to having two rooms, one permanently lit up, the > other permanently not: > > (1) Having two rooms is expensive and wasteful of physical space, which > is in short supply. > > (2) You typically use rooms for storing things (furniture and smaller > objects), having two rooms mean you would need to clone every object > inside it and somehow keep them in perfect synchronisation. > > (3) the light that is always on will use electricity 24 hours a day, > regardless of whether you are inside it or not. > > But none of those objections apply to functions: > > (1) Functions are cheap and live in memory, which is not in short supply > unless you're programming for an embedded device. > > (1a) Even if you are programming in a device that is short of memory, the > overhead of a second function is minimal. There's little difference > between: > > def func(flag): > if flag: > blockA > else: > blockB > > > and > > > def funcA(): > blockA > > def funcB(): > blockB > > > for any non-trivial code blocks, particularly if any common code is > factored out into another function which you call. > > (2) Functions aren't typically used for storage, and when they need > external data, it is easy to have them access a common data store. > > (3) Functions don't use CPU cycles just by existing. I agree with your reasoning :-), but it's not either/or. Consider, sometimes one wants to do switch.off() and sometimes one wants to do original_switch_state = switch.state() switch.off() # ... Do things that are best done in utter darkness. switch.set_state( original_switch_state ) E.g. the "switch" might be the enabled/disabled state of some GUI widget. So IMHO it depends. Sometimes one wants both kinds of "protocols". Cheers, - Alf From malaclypse2 at gmail.com Sat Feb 6 22:15:51 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Sat, 6 Feb 2010 22:15:51 -0500 Subject: sshd in python for windows 7 In-Reply-To: <4b6e0455$0$20650$426a34cc@news.free.fr> References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <16651e81002061915v72cbc134he6c3c46f6add226c@mail.gmail.com> On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: > Hi, > > I wondered which modules would be best to perform following task: > > A user uses a standard ssh (e.g. putty or openssh) client and performs > an ssh to a windows host > > The windows host would run a python script acting as ssh server. The Twisted library has an sshd implementation, called conch. Here an article with a simple python sshd built with twisted: http://www.ibm.com/developerworks/linux/library/l-twist4.html -- Jerry From hzhuo1 at gmail.com Sat Feb 6 23:16:09 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sat, 6 Feb 2010 20:16:09 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> Message-ID: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> > > So it seems we both misunderstood the problem. > > I didn't read the top level article until now, and reading it, I can't make > sense of it. > Seems that you should read the whole thing before making a post, or else you cannot know what we are talking about. Steven doesn't misunderstand me. We are talking about what I need, and he tries to help. > > > "Given the function hashlib.sha256, enumerate all the possible inputs > > that give the hexadecimal result > > 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." > > I tried some "parrot" variants but no dice. :-( > > [snip] > This is a hash collision problem. Nobody has proved that SHA-256 is collision free, even not in the random oracle model, because people always suppose that a random oracle exists, and make hash function its substitution. That means it may be broken someday. And any provable security based on random oracle model is not secure. > > I'm suggesting that, in general, there's no way to tell in advance which > > regexes will be easy and which will be hard, and even when they are easy, > > the enumeration will often be infinite. It is hard to tell in advance. However, we can add some timing limit or counting limit, to make it an algorithm, which can halt. For example, whenever the program outputs more than 1000000 expressions that match the input regex, we can halt because that exceeds our limit. But surely this is not efficient because of the post-decision. > > Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation > that denotes "digit sequence") yields an infinite number of strings. Infinity is really relative, not absolute. It is relative to the computing speed. For example, the regex '^[0|1]{2048}$' is rather simple and doesn't contain '+' or '$', but trying to output all expressions that match it has a complexity of 2^2048. If we can do that, then we can break RSA-2048. We must face the reality . Zhuo From nobody at nowhere.com Sat Feb 6 23:19:20 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 04:19:20 +0000 Subject: WCK and PIL References: <1fbe5e4b-2179-410b-9f76-9d65a7a08dce@k19g2000yqc.googlegroups.com> Message-ID: On Fri, 05 Feb 2010 21:05:53 -0800, darnzen wrote: > I've written an app using the wck library (widget construction kit, > see http://www.effbot.org), in addition to the wckGraph module. What > I'd like to do, is take the output of one of my windows (happens to be > a graph), and save it as a *.png or *.gif. I was planning on using the > PIL for this. I'd like to use the code I have as is, without re- > writing all the graphic calls to use PIL methods. > > WCK uses its own "pixmap" class for storing images in memory. I can't > find any documentation or class reference for pixmap and what I find > in the source is confusing. A WCK pixmap is a "draw object" whose underlying drawable is a pixmap (i.e. a Tk pixmap, which is the platform's native "chunk of video memory" pixmap type) rather than a window. >From the source code, WCK doesn't appear to offer any way to retrieve the pixel data (i.e. there's no way to do the opposite of draw.paste()). From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 23:31:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 04:31:36 GMT Subject: max / min / smallest float value on Python 2.5 References: Message-ID: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 03:02:05 +0000, duncan smith wrote: > The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. Thanks. I'm trying to think of what sort of experiment would be able to measure temperatures accurate to less than 3e-308 Kelvin, and my brain boiled. Surely 1e-100 would be close enough to zero as to make no practical difference? Or even 1e-30? Whatever you're simulating surely isn't going to require 300+ decimal points of accuracy. I must admit I'm not really familiar with simulated annealing, so I could be completely out of line, but my copy of "Numerical Recipes ..." by Press et al has an example, and they take the temperature down to about 1e-6 before halting. Even a trillion times lower that that is 1e-15. -- Steven From nobody at nowhere.com Sat Feb 6 23:33:12 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 04:33:12 +0000 Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> Message-ID: On Sat, 06 Feb 2010 11:09:31 -0800, Jim wrote: > I generate some HTML and I want to include in my unit tests a check > for syntax. So I am looking for a program that will complain at any > syntax irregularities. > > I am familiar with Beautiful Soup (use it all the time) but it is > intended to cope with bad syntax. I just tried feeding > HTMLParser.HTMLParser some HTML containing '

ab

' and it > didn't complain. HTMLParser is a tokeniser, not a parser. It treats the data as a stream of tokens (tags, entities, PCDATA, etc); it doesn't know anything about the HTML DTD. For all it knows, the above example could be perfectly valid (the "b" element might allow both its start and end tags to be omitted). Does the validation need to be done in Python? If not, you can use "nsgmls" to validate any SGML document for which you have a DTD. OpenSP includes nsgmls along with the various HTML DTDs. From alfps at start.no Sat Feb 6 23:38:38 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 05:38:38 +0100 Subject: How to print all expressions that match a regular expression In-Reply-To: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: * hzhuo1 at gmail.com: >> So it seems we both misunderstood the problem. >> >> I didn't read the top level article until now, and reading it, I can't make >> sense of it. >> > > [1] Seems that you should read the whole thing before making a post, or > else you cannot know what we are talking about. > Steven doesn't misunderstand me. We are talking about what I need, and > he tries to help. If you were not misunderstood then you've posted a question for which there's no practical solution. >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( >> >> [snip] >> > > This is a hash collision problem. Nobody has proved that SHA-256 is > collision free, even not in the random oracle model, because people > always suppose that a random oracle exists, and make hash function its > substitution. That means it may be broken someday. And any provable > security based on random oracle model is not secure. Stephen's little challenge wasn't about breaking SHA-256 but about guessing his secret phrase, given his clues. >>> I'm suggesting that, in general, there's no way to tell in advance which >>> regexes will be easy and which will be hard, and even when they are easy, >>> the enumeration will often be infinite. > > It is hard to tell in advance. No, it's trivial. > [2] However, we can add some timing limit > or counting limit, to make it an algorithm, which can halt. For > example, whenever the program outputs more than 1000000 expressions > that match the input regex, we can halt because that exceeds our > limit. But surely this is not efficient because of the post-decision. You don't need to wait for that output to complete. You can calculate the number of strings up front. Like it appears that you do below: >> Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation >> that denotes "digit sequence") yields an infinite number of strings. > > Infinity is really relative, not absolute. It is relative to the > computing speed. For example, the regex '^[0|1]{2048}$' is rather > simple and doesn't contain '+' or '$', but trying to output all > expressions that match it has a complexity of 2^2048. If we can do > that, then we can break RSA-2048. > We must face the reality . Here it seems that you have no problem calculating number of combinations, yet above, at the paragraph marked [2], you talk about waiting for a million strings to be output before seeing that it's too much, and earlier, at the paragraph marked [1], you maintain that your original question about generating all such strings (completely impractical) was what you wanted help with? I'm sorry but I can't make sense of this; it appears to be meaningless. Perhaps if you tried to clarify the requirements a bit. Cheers & hth., - Alf From schifschaf at gmail.com Sat Feb 6 23:49:06 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sat, 6 Feb 2010 20:49:06 -0800 (PST) Subject: Help with regex search-and-replace (Perl to Python) Message-ID: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Hi, I've got some text that looks like this: Lorem [ipsum] dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna aliqua. and I want to make it look like this: Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua. (brackets replaced by braces). I can do that with Perl pretty easily: ~~~~ for (<>) { s/\[(.+?)\]/\{$1\}/g; print; } ~~~~ but am not able to figure out how to do it with Python. I start out trying something like: ~~~~ import re, sys withbracks = re.compile(r'\[(.+?)\]') for line in sys.stdin: mat = withbracks.search(line) if mat: # Well, this line has at least one. # Should be able to use withbracks.sub() # and mat.group() maybe ... ? line = withbracks.sub('{' + mat.group(0) + '}', line) # No, that's not working right. sys.stdout.write(line) ~~~~ but then am not sure where to go with that. How would you do it? Thanks. From schifschaf at gmail.com Sun Feb 7 00:04:44 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sat, 6 Feb 2010 21:04:44 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <1500989d-b1d9-4734-ac03-5d7b9d531aeb@c4g2000yqa.googlegroups.com> On Feb 5, 8:49?am, Roald de Vries wrote: > My reasoning: I needed a language more powerful than bash, but more ? > portable and faster to develop (at least small scripts) than C/C++. So ? > I needed a scripting language. Python, Ruby, Perl, Tcl, ...? > > Python seems to be the language with the most libraries available, I like Python a lot. That said, it looks like Perl's CPAN currently has approximately double the number of packages in the Cheeseshop. I'm guessing the CPAN is still growing, but I don't know how fast it is growing compared to the Cheeseshop. I won't venture a guess as to which has a higher percentage of older unmaintained packages. From nobody at nowhere.com Sun Feb 7 00:09:40 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 05:09:40 +0000 Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: On Sun, 07 Feb 2010 00:26:36 +0000, Steven D'Aprano wrote: >> So there isn't such a routine just because some of the regular >> expressions cannot be enumerated. No. There isn't a routine because no-one has yet felt any need to write one. >> However, some of them can be >> enumerated. I guess I have to write a function myself. > > How do you expect to tell the ones that can be enumerated apart from > those that can't be? The ones which use the '+', '*' and '{m,}' operators match an infinite number of strings; the rest can only match a finite number (assuming POSIX REs; Python also has +? and *?). ["Enumerate" isn't the correct word here. You can *enumerate* an infinite set, in the sense that you could write a Python generator for which any member will eventually be generated.] The obvious implementation is to construct the NFA then "run" it. If you know that the RE can only match finite strings (i.e. the graph is acyclic), then you can enumerate them using depth-first traversal. If it can match infinite strings (i.e. if there are any cycles in the graph), then you would need to use either breadth-first traversal or incrementally-bounded depth-first traversal. > [Aside: Python regexes aren't Turing Complete. I'm not sure about Perl > regexes. Either way, this might actually be less difficult than the > Halting Problem, as in "amazingly difficult" rather than "impossible".] "Regular expressions" aren't Turing complete; this is implicit in the definition of "regular". The Chomsky hierarchy has four levels, with higher levels require a more capable system to decide whether a string is a member of the language defined by the grammar: grammar decidable by regular finite automaton context-free pushdown automaton[1] context-sensitive linear-bounded automaton[2] recursively-enumerable Turing machine However, any "regular expression" syntax which allows backreferences (including the POSIX specification) isn't actually "regular" in the formal sense (as it requires an infinite number of states), but context-free. [1] pushdown automaton = finite automaton with a stack [2] linear-bounded automaton = Turing machine, except that it's "tape" is finite and proportional to the size of the input. http://en.wikipedia.org/wiki/Chomsky_hierarchy From alfps at start.no Sun Feb 7 00:19:13 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 06:19:13 +0100 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: * Schif Schaf: > Hi, > > I've got some text that looks like this: > > > Lorem [ipsum] dolor sit amet, consectetur > adipisicing elit, sed do eiusmod tempor > incididunt ut [labore] et [dolore] magna aliqua. > > and I want to make it look like this: > > > Lorem {ipsum} dolor sit amet, consectetur > adipisicing elit, sed do eiusmod tempor > incididunt ut {labore} et {dolore} magna aliqua. > > (brackets replaced by braces). I can do that with Perl pretty easily: > > ~~~~ > for (<>) { > s/\[(.+?)\]/\{$1\}/g; > print; > } > ~~~~ > > but am not able to figure out how to do it with Python. I start out > trying something like: > > ~~~~ > import re, sys > withbracks = re.compile(r'\[(.+?)\]') > for line in sys.stdin: > mat = withbracks.search(line) > if mat: > # Well, this line has at least one. > # Should be able to use withbracks.sub() > # and mat.group() maybe ... ? > line = withbracks.sub('{' + mat.group(0) + '}', line) > # No, that's not working right. > > sys.stdout.write(line) > ~~~~ > > but then am not sure where to go with that. > > How would you do it? I haven't used regexps in Python before, but what I did was (1) look in the documentation, (2) check that it worked. import re text = ( "Lorem [ipsum] dolor sit amet, consectetur", "adipisicing elit, sed do eiusmod tempor", "incididunt ut [labore] et [dolore] magna aliqua." ) withbracks = re.compile( r'\[(.+?)\]' ) for line in text: print( re.sub( withbracks, r'{\1}', line) ) Python's equivalent of the Perl snippet seems to be the same number of lines, and more clear. :-) Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Sun Feb 7 00:43:26 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 02:43:26 -0300 Subject: Subclassing datetime.date References: <87vdea9h2y.fsf@castleamber.com> Message-ID: En Sat, 06 Feb 2010 18:42:29 -0300, John Bokma escribi?: > Sir Wilhelm the Sturdy writes: >> >> I recently attempted to subclass the datetime.date object resulting in >> horror and confusion, before submitting to a has-a relationship. >> That's all fine and dandy, but out of curiosity I'd like to know what >> I'm missing. >> >> class MyDate(datetime.date): >> >> def __init__(self,*args,**kw): >> ... > __init__ is *not* the construction method, __new__ is (at least with new > style classes) You're right. But in this case, instead of overriding __new__, I would add a separate constructor to avoid confusion with the existing one (a classmethod, actually, like fromordinal and fromtimestamp): py> from datetime import date py> class date(date): ... @classmethod ... def fromDMY(cls, d, m=None, y=None): ... today = date.today() ... if m is None: m = today.month ... if y is None: y = today.year ... return cls(y, m, d) ... py> date.fromDMY(20, 3, 2010) date(2010, 3, 20) py> date.fromDMY(11) date(2010, 2, 11) -- Gabriel Genellina From schifschaf at gmail.com Sun Feb 7 00:45:39 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sat, 6 Feb 2010 21:45:39 -0800 (PST) Subject: Help with regex search-and-replace (Perl to Python) References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: On Feb 7, 12:19?am, "Alf P. Steinbach" wrote: > > I haven't used regexps in Python before, but what I did was (1) look in the > documentation, Hm. I checked in the repl, running `import re; help(re)` and the docs on the `sub()` method didn't say anything about using back-refs in the replacement string. Neat feature though. > (2) check that it worked. > > > import re > > text = ( > ? ? ?"Lorem [ipsum] dolor sit amet, consectetur", > ? ? ?"adipisicing elit, sed do eiusmod tempor", > ? ? ?"incididunt ut [labore] et [dolore] magna aliqua." > ? ? ?) > > withbracks = re.compile( r'\[(.+?)\]' ) > for line in text: > ? ? ?print( re.sub( withbracks, r'{\1}', line) ) > > Seems like there's magic happening here. There's the `withbracks` regex that applies itself to `line`. But then when `re.sub()` does the replacement operation, it appears to consult the `withbracks` regex on the most recent match it just had. Thanks. From nobody at nowhere.com Sun Feb 7 00:49:28 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 05:49:28 +0000 Subject: TABS in the CPython C source code References: Message-ID: On Sat, 06 Feb 2010 21:31:52 +0100, Alf P. Steinbach wrote: > The size-8 tabs look really bad in an editor configured with tab size 4, > as is common in Windows. I'm concluding that the CPython programmers > configure their Visual Studio's to *nix convention. 8-column tabs aren't a "*nix convention"; that's been the norm since the mechanical typewriter. Historically, software and hardware which knows what a "tab" could be split into two categories: 1. Tab stops are fixed at 8-column intervals. 2. Tab stops default to 8-column intervals but can be changed. Recently, a third category has appeared (tab stops default to something other than 8 columns). The most common example is Visual Studio. No surprise there: Microsoft has a track record of introducing slight incompatibilities into established standards. Just enough to inconvenience anyone using competing products, but not so much that anyone operating in a context where Microsoft isn't dominant has to abandon Microsoft's product. Given that: 1. 8-column tabs have been the standard for longer than most of us have been alive, let alone programming, and 2. even if a particular text editor supports some other value, there is no way to communicate this fact to anything else which might read the code, the logical conclusion is that using anything other than 8 columns lies somewhere between "silly" and "assuming the world revolves around you". From gagsl-py2 at yahoo.com.ar Sun Feb 7 00:59:00 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 02:59:00 -0300 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: <4B6C1BED.6090807@bluewin.ch> <4B6D50CA.5070006@bluewin.ch> Message-ID: En Sat, 06 Feb 2010 08:21:46 -0300, Anthra Norell escribi?: > Gabriel, > Thanks for your hints. I take them up one by one: > > >>> import os > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named os > > C:\PYTHON25\LIB>dir os.* > > OS PY 25,211 08-03-06 9:27a OS.PY > OS PYC 24,430 06-05-08 6:45p OS.PYC > > Here we are! Somehow the name got upper-cased! There's a whole bunch > (131) of upper-cased names in the Lib I shall install the whole thing > from scratch. That should take care if it. Thank you very much. If you still have problems, try setting the PYTHONCASEOK environment variable. C:\temp>python25 -? ... Other environment variables: ... PYTHONCASEOK : ignore case in 'import' statements (Windows). > Frederic (Looking forward to Linux!) Or at least a more decent Windows version. ME was a complete failure - Win98 Second Edition, being older, was better. -- Gabriel Genellina From tjreedy at udel.edu Sun Feb 7 01:00:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 07 Feb 2010 01:00:30 -0500 Subject: Doctests and decorated methods don't get along In-Reply-To: <037dfaba$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> <037dfaba$0$1292$c3e8da3@news.astraweb.com> Message-ID: On 2/6/2010 7:51 PM, Steven D'Aprano wrote: > I have found an existing report for this issue: > > http://bugs.python.org/issue4037 > > The original poster's suggested fix was on the right track, but not > complete. I've added a patch which works according to my tests. > > Since this report is currently unassigned, is there a protocol for > raising its profile and having somebody check my patch for inclusion? > Should I just send an email to python-dev? At one time, I believe this would have been assigned to Tim Peters, but he seems not to be very active in Python development currently. Given that the patch is fairly trivial and the module possible orphaned, and that you do not regularly bug python-dev, I suspect it would be ok to enquire, once you have a complete patch (with testcase). The latter would let a committer/reviewer quickly check that it does what you claim. You might be asked to review some other issues in exchange. (Or the OP of this thread or the tracker item might help ;-). Terry Jan Reedy From alfps at start.no Sun Feb 7 01:26:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 07:26:00 +0100 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: * Nobody: > On Sat, 06 Feb 2010 21:31:52 +0100, Alf P. Steinbach wrote: > >> The size-8 tabs look really bad in an editor configured with tab size 4, >> as is common in Windows. I'm concluding that the CPython programmers >> configure their Visual Studio's to *nix convention. > > 8-column tabs aren't a "*nix convention"; that's been the norm since > the mechanical typewriter. > > Historically, software and hardware which knows what a "tab" could be > split into two categories: > > 1. Tab stops are fixed at 8-column intervals. > 2. Tab stops default to 8-column intervals but can be changed. > > Recently, a third category has appeared (tab stops default to something > other than 8 columns). I'm sorry, but you have your history wrong. Tab stops originated with mechanical typewriters, and then printers. They could be just about anything. Tab stops have never been universally 8 columns -- so unless by "recent" introduction of other sizes you mean 1958 or thereabouts, you're completely off track. > The most common example is Visual Studio. No > surprise there: Microsoft has a track record of introducing slight > incompatibilities into established standards. Just enough to inconvenience > anyone using competing products, but not so much that anyone operating > in a context where Microsoft isn't dominant has to abandon Microsoft's > product. > > Given that: > > 1. 8-column tabs have been the standard for longer than most of us > have been alive, let alone programming, and I'm sorry, that's incorrect, it's never been standard. > 2. even if a particular text editor supports some other value, there is no > way to communicate this fact to anything else which might read the code, If you add the word "portable" and remove the word "other" and replace "supports" with "is configured to use" then that's sort of technically correct. But I agree with the general sense. And I think most everyone does. A common convention would have been nice. But we don't have that. > the logical conclusion is that using anything other than 8 columns lies > somewhere between "silly" and "assuming the world revolves around you". ?the logical conclusion is that assuming 8 column tab stops lies somewhere between "silly" and "assuming the world revolves around you"? :-) In particular, consider Windows programming. Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Sun Feb 7 01:29:20 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 03:29:20 -0300 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> <4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: En Sat, 06 Feb 2010 21:24:33 -0300, News123 escribi?: > Gabriel Genellina wrote: >> En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: >> >>> I'm using an XMLRPC server under Windows. >>> What I wonder is how I could create a server, that can be killed with >>> CTRL-C >> >> Python 2.6 and up behaves exactly as you want. >> On previous versions you may use this: >> >> def server_bind(self): >> self.socket.settimeout(1.0) >> SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) >> > > Overloading server_bind() with your version solved my problem. Strange. With Python 2.6.4 I don't need to do that; I'd say the difference is in the OS or antivirus (some AV are known to break the TCP stack). -- Gabriel Genellina From aahz at pythoncraft.com Sun Feb 7 01:38:06 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Feb 2010 22:38:06 -0800 Subject: TABS in the CPython C source code References: Message-ID: In article , Neil Hodgson wrote: >Alf P. Steinbach: >> >> Anyways, I would suggest converting all those tabs to spaces, as e.g. >> the Boost library project does -- no tabs allowed. > > This would damage the usefulness of source control histories (svn >annotate) as all of the converted lines would show this recent cosmetic >change rather than the previous change which is likely to be a >substantive modification. BTW, in case anyone is confused, it's "svn blame" vs "cvs annotate". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Sun Feb 7 01:42:22 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Feb 2010 22:42:22 -0800 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: In article <0c535d15-967d-4909-a9bb-b5970818199f at l24g2000prh.googlegroups.com>, Xah Lee wrote: > >This is a short complaint on admin abuse on #python irc channel on >freenode.net. Let's see, you are complaining about getting banned from #python by CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's grounds for extending the IRC ban permanently. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From gagsl-py2 at yahoo.com.ar Sun Feb 7 02:14:11 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 04:14:11 -0300 Subject: xmlrpc slow in windows 7 if hostnames are used References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> <4B6E1444.9060001@sequans.com> Message-ID: En Sat, 06 Feb 2010 22:15:48 -0300, Jean-Michel Pichavant escribi?: > I'm puzzled. > Unless my english is failing me, everything would be solved using > hostnames if I follow you. Why don't you do that ? > I am no network/IP guru, but it sounds very weird to have requests > rejected when using IP addresses. Are you sure your host names are > resolved with the same IPM address you are using ? HTTP 1.1 requires a Host: header field; this way, multiple web servers may share the same IP address. So you can't identify a host by its IP alone; the host name is required. This was devised in order to save IPv4 addresses; LACNIC (the Latin America addresses register) does not assign addresses to ISP's based solely on web hosting anymore - they MUST share existing IPs. And I think a similar policy is used on other regions. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Feb 7 02:52:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 04:52:18 -0300 Subject: Dreaming of new generation IDE References: Message-ID: En Sat, 06 Feb 2010 22:34:14 -0300, bartc escribi?: > "Arnaud Delobelle" wrote in message > news:m28wb6ypfs.fsf at googlemail.com... >> "Gabriel Genellina" writes: >>> Note the *literal* part. If you (the programmer) is likely to know the >>> parameter value when writing the code, then the function is actually >>> two >>> separate functions. >> >> Thanks, I understand what Steve Holden meant now. > > I've just noticed that 'literal' part. But I think I still disagree. > > For a real-world example, it means instead of having a room with a > light-switch in it, if I *know* I want the light on or off, I should > have two rooms: one with the light permanently on, and one with it > permanently off, and just walk into the right one. I think this would be a better analogy: A multiple screwdriver like this one http://img.alibaba.com/photo/204461747/Multi_function_screwdriver_screwdriver.jpg You use it when you need flexibility, or you don't know in advance what kind of screws you're going to encounter; they're mostly for hobbysts. On the other hand, you have separate tools like this: http://i277.photobucket.com/albums/kk43/hightecelectronica/021-482.jpg You choose one of them when you know exactly what you want. If the stuff you're working on uses exclusively certain kind of screws, you don't need flexibility, and you can choose in advance. They're also professional's choice. -- Gabriel Genellina From anand.shashwat at gmail.com Sun Feb 7 04:03:07 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 14:33:07 +0530 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: Here is one simple solution : >>> intext = """Lorem [ipsum] dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna aliqua.""" >>> intext.replace('[', '{').replace(']', '}') 'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua.' *Some people, when confronted with a problem, think "I know, I?ll use regular expressions." Now they have two problems.* ? Jamie Zawinskiin comp.lang.emacs. On Sun, Feb 7, 2010 at 11:15 AM, Schif Schaf wrote: > On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: > > > > > I haven't used regexps in Python before, but what I did was (1) look in > the > > documentation, > > Hm. I checked in the repl, running `import re; help(re)` and the docs > on the `sub()` method didn't say anything about using back-refs in the > replacement string. Neat feature though. > > > (2) check that it worked. > > > > > > import re > > > > text = ( > > "Lorem [ipsum] dolor sit amet, consectetur", > > "adipisicing elit, sed do eiusmod tempor", > > "incididunt ut [labore] et [dolore] magna aliqua." > > ) > > > > withbracks = re.compile( r'\[(.+?)\]' ) > > for line in text: > > print( re.sub( withbracks, r'{\1}', line) ) > > > > > > Seems like there's magic happening here. There's the `withbracks` > regex that applies itself to `line`. But then when `re.sub()` does the > replacement operation, it appears to consult the `withbracks` regex on > the most recent match it just had. > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From macosx at rocteur.cc Sun Feb 7 04:52:10 2010 From: macosx at rocteur.cc (@ Rocteur CC) Date: Sun, 7 Feb 2010 10:52:10 +0100 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: <6C6462AB-4665-40C9-B652-076FA574B872@rocteur.cc> On 07 Feb 2010, at 10:03, Shashwat Anand wrote: > Here is one simple solution : > >>> intext = """Lorem [ipsum] dolor sit amet, consectetur > adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et > [dolore] magna aliqua.""" > > >>> intext.replace('[', '{').replace(']', '}') > 'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do > eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua.' > > Some people, when confronted with a problem, think "I know, I?ll use > regular expressions." Now they have two problems. ? Jamie Zawinski > in comp.lang.emacs. That is because regular expressions are what we learned in programming the shell from sed to awk and ksh and zsh and of course Perl and we've read the two books by Jeffrey and much much more!!! How do we rethink and relearn how we do things and should we ? What is the solution ? Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From Martin.Drautzburg at web.de Sun Feb 7 04:54:16 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sun, 07 Feb 2010 10:54:16 +0100 Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> Message-ID: <3360023.OTX69idHFh@beaureve.gmx.net> Christian Heimes wrote: > If you *really* need to overwrite __iter__ on your instance rather > than defining it on your class, you need to proxy the method call: > > class MyObject(object): > def __iter__(self): > return self.myiter() > > obj = MyObject() > obj.myiter = myiter > > That should do the trick. Thanks a lot, that works. From dickinsm at gmail.com Sun Feb 7 04:55:53 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 7 Feb 2010 01:55:53 -0800 (PST) Subject: max / min / smallest float value on Python 2.5 References: Message-ID: <6361d161-2367-44e0-a1aa-1938cb5e0bfc@21g2000yqj.googlegroups.com> On Feb 7, 12:52?am, duncan smith wrote: > import platform > if platform.architecture()[0].startswith('64'): > ? ? ?TINY = 2.2250738585072014e-308 > else: > ? ? ?TINY = 1.1754943508222875e-38 As Christian said, whether you're using 32-bit or 64-bit shouldn't make a difference here. Just use the first TINY value you give. > I'm not 100% sure how reliable this will be across platforms. ?Any ideas > about the cleanest, reliable way of uncovering this type of information? In practice, it's safe to assume that your 2.225....e-308 value is reliable across platforms. That value is the one that's appropriate for the IEEE 754 binary64 format, and it's difficult these days to find CPython running on a machine that uses any other format for C doubles (and hence for Python floats). The smallest positive *normal* number representable in IEEE 754 binary64 is exactly 2**-1022 (or approximately 2.2250738585072014e-308). The smallest positive *subnormal* number representable is exactly 2**-1074, or approximately '4.9406564584124654e-324'. (Subnormals have fewer bits of precision than normal numbers; it's the presence of subnormals that allows for 'gradual underflow'.) Some machines can/will treat subnormal numbers specially for speed reasons, either flushing a subnormal result of a floating-point operation to 0, or replacing subnormal inputs to an floating-point operation with 0, or both. So for maximal portability, and to avoid numerical problems, it's best to avoid the subnormal region. > The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. This is a bit surprising. What's the precise form of the error you get? Do you still get the same error if you replace your TINY value by something fractionally larger? (E.g., 2.23e-308.) -- Mark From rychphd at gmail.com Sun Feb 7 05:06:52 2010 From: rychphd at gmail.com (rych) Date: Sun, 7 Feb 2010 02:06:52 -0800 (PST) Subject: ctypes Structure serialization Message-ID: <615b1271-a9b0-4558-8e45-e4370698d96a@a16g2000pre.googlegroups.com> I'm not quite familiar with python serialization but the picle module, at least, doesn't seem to be able to serialize a ctypes Structure with array-fields. Even if it was, the ASCII file produced is not in a human-friendly format. Could someone please suggest a method of saving and loading the fields in ctypes' Structure derived class to a json or better yet, to something like INFO http://www.boost.org/doc/libs/1_41_0/doc/html/boost_propertytree/parsers.html#boost_propertytree.parsers.info_parser For example, I have an object of >>> class MyStruct(Structure): ... _fields_ = [("a", c_int), ... ("b", c_float), ... ("point_array", c_float * 4)] I'd like the corresponding file to look like a 1 b 1.0 point array 1.1 1.2 1.3 1.4 Thanks From Martin.Drautzburg at web.de Sun Feb 7 05:13:41 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sun, 07 Feb 2010 11:13:41 +0100 Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> Message-ID: <63288869.8iZ5tTOMcE@beaureve.gmx.net> Steven D'Aprano wrote: > If you want iterator operations "similar to itertools", why does this > mean you need to replace anything? Just create your own iterators. > > Or use pre-processing and post-processing to get what you want. > > Can you show an example of what you would like to happen? Steven, my classes repesent musical objects. The fundamental paradigm I want to apply is that of a Sequence, i.e. the most abstract aspect of music is that "things" occur in a certain order. Then I have a TimedSequence class, which is a Sequences whose elements have a "time" attribute. I now want to be able to append such Sequences by writing s1 = TimedSequence (time=1,'a') # one-element Sequence s2 = TimedSequence (time=2,'b') y = s1*2 + s2 Naively appending those sequences would give me Time=1,'a' Time=1,'a' Time=2,'b' but this is not what I want. Time needs to progress if I append a sequence to another. So what I really want is something like Time=1,'a' Time=2,'a' Time=3,'b' This implies that time is shifted to the next integer, but this is not always the case. I need to know about some kind of "alignment". In music this translates to "let a sequence start at the beginning of a bar", or half bar or quarter note or whatever. So I want to write y = s1*2 + s2(align=10) which should iterate as Time=1,'a' Time=2,'a' Time=10,'b' I have no difficulty passing "align" to the object (using __call__) and use it while I furnish my own __iter__() method. However I don't quite see how I can do this with bare itertools, though I may be wrong here. Bare in mind that it is not only about somehow getting the job done. The beauty of the resulting syntax is also important. From news123 at free.fr Sun Feb 7 05:33:55 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:33:55 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> Message-ID: <4b6e9714$0$29806$426a74cc@news.free.fr> Hi JM, Jean-Michel Pichavant wrote: > News123 wrote: >> Jean-Michel Pichavant wrote: >> >> >> Well This was exactly my question. >> for virtual web servers I cannot just use the IP-address. >> some XMLRPC servers do need the histname within the HTTP-POST request. >> >> > a valid IP address would make it What I meant is: Window 7 seems to be waaaayyyy slower if an xmlrpc client uses a host name ('localhost') than an IP-address ('127.0.0.1). the speed difference is between 1 request per second or 10-20 requests per second. >> if I just replaced the hostname with the IP address, then certain servers >> would not be accessable. many computers host multiple web servers under the same IP-address. ( see for example http://httpd.apache.org/docs/1.3/vhosts/name-based.html ) So I cannot just replace a host name with an IP-address and expect to receive the correct data / correct xmlrpc server. >> I had to use the IP-address for connecteing > why not using the host names? I did not want to use the hostname due to the slowdown of "locahost vs. 127.0.0.1" issue on my host. You are right, that I did not verify whether this issue exists also with external servers and I should verify this first. >> , but to pass the hostname in >> the HTTP-POST request. >> >> I wondered how to convince puthon's SimpleXMLRPCServer (or any other >> standard python xmlrpc server), such, that I can obtain above mentioned >> goal. >> >> > I'm puzzled. > Unless my english is failing me, everything would be solved using > hostnames if I follow you. Why don't you do that ? > I am no network/IP guru, but it sounds very weird to have requests > rejected when using IP addresses. Are you sure your host names are > resolved with the same IPM address you are using ? The request would not be rejected, but apache can (if being configured for name based virtual hosts) look at the hostname within the TCP/IP payload (the entire url (including the host name) is normally also in the GET / POST request ) and decide to deliver different data (or to return HTTP errors) depending on the hostname in the payload. I hope this clarifies. Your answer gave me some thoughts though: I still have to check whether the issue really exists with external requests other than localhost. Also I should probably try to attack the root cause ( probably with help of ethereal or a similiar tool) instead of trying to work around it. I could just change the windows /etc/hosts equivalent and tell localhost to have only an IPV4 address (perhaps this increases the performance) On the other hand: Some people use name based virtual servers to provide special web services by providing a 'fake-host name' in the http request. it might be, that the fake host name doesn't even have a DNS entry. ( Though security by obscurity is a questionable practice ) so for some weird use cases it could be worth knowing how to connect to one IP addres and to pass a different host name in the HTTP payload when using an xmlrpcclient bye N From news123 at free.fr Sun Feb 7 05:38:39 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:38:39 +0100 Subject: sshd in python for windows 7 In-Reply-To: References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <4B6E982F.4020404@free.fr> Hi Jerry, Jerry Hill wrote: > On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: >> Hi, >> >> I wondered which modules would be best to perform following task: >> >> A user uses a standard ssh (e.g. putty or openssh) client and performs >> an ssh to a windows host >> >> The windows host would run a python script acting as ssh server. > > The Twisted library has an sshd implementation, called conch. Here an > article with a simple python sshd built with twisted: > http://www.ibm.com/developerworks/linux/library/l-twist4.html Thanks. I'll check whether twisted conch runs also under windows. Yesterday I made the probably too fast conclusion, that twisted conch exists only for liux as I could only find a twisted-conch tarball and not a windows installer. But probably twisted-conch is already part of the twisted installer for windows. I'll check it. From news123 at free.fr Sun Feb 7 05:39:06 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:39:06 +0100 Subject: sshd in python for windows 7 In-Reply-To: References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <4b6e984a$0$29806$426a74cc@news.free.fr> Hi Jerry, Jerry Hill wrote: > On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: >> Hi, >> >> I wondered which modules would be best to perform following task: >> >> A user uses a standard ssh (e.g. putty or openssh) client and performs >> an ssh to a windows host >> >> The windows host would run a python script acting as ssh server. > > The Twisted library has an sshd implementation, called conch. Here an > article with a simple python sshd built with twisted: > http://www.ibm.com/developerworks/linux/library/l-twist4.html Thanks. I'll check whether twisted conch runs also under windows. Yesterday I made the probably too fast conclusion, that twisted conch exists only for liux as I could only find a twisted-conch tarball and not a windows installer. But probably twisted-conch is already part of the twisted installer for windows. I'll check it. From news123 at free.fr Sun Feb 7 05:42:12 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:42:12 +0100 Subject: sshd in python for windows 7 In-Reply-To: References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <4b6e9904$0$29806$426a74cc@news.free.fr> Hi Jerry, Jerry Hill wrote: > On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: >> Hi, >> >> I wondered which modules would be best to perform following task: >> >> A user uses a standard ssh (e.g. putty or openssh) client and performs >> an ssh to a windows host >> >> The windows host would run a python script acting as ssh server. > > The Twisted library has an sshd implementation, called conch. Here an > article with a simple python sshd built with twisted: > http://www.ibm.com/developerworks/linux/library/l-twist4.html THanks a look at it in moe detail. Yesterday I made the probably wrong assumption, that twisted-conch exists only for linux as I just found a twisted-conch tarball. Probably however twisted-conch is already part of the twisted windows installer package I'll check this. N From peloko45 at gmail.com Sun Feb 7 06:22:59 2010 From: peloko45 at gmail.com (Joan Miller) Date: Sun, 7 Feb 2010 03:22:59 -0800 (PST) Subject: Simulating logging.exception with another traceback Message-ID: <0c13d3f7-addf-4972-91c3-6f41fadfb2b5@u26g2000yqm.googlegroups.com> I would want to get the output from `logging.exception` but with traceback from the caller function (I've already all that information). This would be the error with logging.exception: -------------------- ERROR: PipeError('/bin/ls -l | ', 'no command after of pipe') Traceback (most recent call last): File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line 160, in __call__ raise PipeError(command, 'no command after of pipe') PipeError: ('/bin/ls -l | ', 'no command after of pipe') -------------------- And I've trying it with: -------------------- message = "File \"{0}\", line {1}, in {2}\n\n {3}".format( file, line, function, caller) logging.error(message) ERROR: File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line 163, in __call__ return self.throw(PipeError, command, 'no command after of pipe') -------------------- Could be used `logging.LogRecord` [1] to get it? How? [1] http://docs.python.org/library/logging.html#logging.LogRecord From chyavana at gmail.com Sun Feb 7 06:32:14 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Sun, 07 Feb 2010 19:32:14 +0800 Subject: Dynamic variable names Message-ID: Dear Folks, I have read that one should use a dictionary in python to accommodate dynamic variable names. Yet, I am puzzled how to achieve that in my case. Here is what I want to do: 1. The user inputs a number of six-digit hex numbers as a comma-separated list. These numbers represent colours, but the number of colours is not known beforehand. 2. Using these colours in pairs, I am generating image files whose names must be unique. I could use the respective hex numbers for this, but would like to explore generating filenames like colour_1-colour_2.jpg Because I do not know how many colours there would be in advance, I need to generate the colour_n names on the fly. So, my two questions are: 1. How do I do this properly in python? 2. If there is a better scheme than what I have outlined, can someone please point me to a Web link? Thank you. Chandra From steve at holdenweb.com Sun Feb 7 07:28:27 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:28:27 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: Aahz wrote: > In article <0c535d15-967d-4909-a9bb-b5970818199f at l24g2000prh.googlegroups.com>, > Xah Lee wrote: >> This is a short complaint on admin abuse on #python irc channel on >> freenode.net. > > Let's see, you are complaining about getting banned from #python by > CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's > grounds for extending the IRC ban permanently. It certainly doesn't inspire any confidence that Xah's next trip to #python is likely to last much longer than the last. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:32:14 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:32:14 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: bartc wrote: > "Arnaud Delobelle" wrote in message > news:m28wb6ypfs.fsf at googlemail.com... >> "Gabriel Genellina" writes: >> >>> En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: >>>> "Steve Holden" wrote in message >>>> news:mailman.1998.1265399766.28905.python-list at python.org... >>>>> Arnaud Delobelle wrote: >>>>>> Robert Kern writes: >>>>>> >>>>>>> I prefer Guido's formulation (which, naturally, I can't find a >>>>>>> direct >>>>>>> quote for right now): if you expect that a boolean argument is only >>>>>>> going to take *literal* True or False, then it should be split into >>> ^^^^^^^^^^^^^^^^^^^^^^^ >>>>>>> two functions. >>>>>> >>>>>> So rather than three boolean arguments, would you have eight >>>>>> functions? >>>>>> >>>>> If there's genuinely a need for that functionality, yes. >>>> >>>> So you want a function such as drawtext(s, bold=true, italic=false, >>>> underline=true) to be split into: >>>> >>>> drawtext(s) >>>> drawtextb(s) >>>> drawtexti(s) >>>> drawtextu(s) >>>> drawtextbi(s) >>>> drawtextbu(s) >>>> drawtextiu(s) >>>> drawtextbiu(s) >>> >>> Note the *literal* part. If you (the programmer) is likely to know the >>> parameter value when writing the code, then the function is actually two >>> separate functions. >> >> Thanks, I understand what Steve Holden meant now. > > I've just noticed that 'literal' part. But I think I still disagree. > > For a real-world example, it means instead of having a room with a > light-switch in it, if I *know* I want the light on or off, I should > have two rooms: one with the light permanently on, and one with it > permanently off, and just walk into the right one. > Congratulations. That has to be the most bogus analogy I've seen on c.l.py this year. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:39:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:39:24 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: Nobody wrote: > On Sat, 06 Feb 2010 21:31:52 +0100, Alf P. Steinbach wrote: > >> The size-8 tabs look really bad in an editor configured with tab size 4, >> as is common in Windows. I'm concluding that the CPython programmers >> configure their Visual Studio's to *nix convention. > > 8-column tabs aren't a "*nix convention"; that's been the norm since > the mechanical typewriter. > Clearly written by someone who has never *used* a mechanical typewriter. The original mechanisms had "tab set" and "tab clear" keys, so you had variable tabbing according to the needs of the particular document you were working on. Look under "T" in http://www.mytypewriter.com/explorelearn/glossary.html if you aren't old enough to have used one. > Historically, software and hardware which knows what a "tab" could be > split into two categories: > > 1. Tab stops are fixed at 8-column intervals. > 2. Tab stops default to 8-column intervals but can be changed. > > Recently, a third category has appeared (tab stops default to something > other than 8 columns). The most common example is Visual Studio. No > surprise there: Microsoft has a track record of introducing slight > incompatibilities into established standards. Just enough to inconvenience > anyone using competing products, but not so much that anyone operating > in a context where Microsoft isn't dominant has to abandon Microsoft's > product. > Consider instead that perhaps this one time Microsoft did it for the convenience of the user (there has to be some reason why it's such a wealthy company). > Given that: > > 1. 8-column tabs have been the standard for longer than most of us > have been alive, let alone programming, and > 2. even if a particular text editor supports some other value, there is no > way to communicate this fact to anything else which might read the code, > > the logical conclusion is that using anything other than 8 columns lies > somewhere between "silly" and "assuming the world revolves around you". > Which is what you appear to be doing with your fantasy about mechanical typewriters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:46:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:46:52 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: <4B6EB63C.1060208@holdenweb.com> Dennis Lee Bieber wrote: > On Sun, 07 Feb 2010 05:49:28 +0000, Nobody > declaimed the following in gmane.comp.python.general: > > >> 8-column tabs aren't a "*nix convention"; that's been the norm since >> the mechanical typewriter. >> > Really? None of the various Royal, Remington, and Olivetti (sp?) > typewriters I learned on had any knowledge of default tab stops. All had > a row of sliding "pins" on the carriage, which were slid back and forth > by the and button (which required one to first > position the carriage at the position at which the stop was to be > placed). The key itself functioned by first pushing a lever into > the area covered by the stop-row (after the current position stop, if > one existed), then releasing the carriage to slide until the next stop > -- uhm -- stopped the motion by impacting the lever; releasing the > key would then re-engage the normal carriage motion control, and > withdraw the lever. > > 8-space tab stops were, I believe, the default for various computer > terminals, DECwriter printers, and maybe teletype units (in which there > was no moving carriage on which a physical stop could be placed). Not > sure how an 029 keypunch machine would behave -- either punching the > code the a tab character, or skipping to the next field defined on a > drum-card. > When I started my computing career the main input medium at the installation I worked was paper tape, and the Flexowriter (pretty much a mechanical typewriter mechanism with a tape reader and punch attached) was the data preparation device (though teletypes were used at other installations). So it had adjustable tab settings. The 029 punch (and the 026 before it) used a punch card mounte on a drum to set the tab stops, which were therefore completely variable - one would use a different tab card for Fortran and PL/1, for example. So a tab was purely a spacing operation, no chads were punched from the card, and indeed I was never aware of an EBCDIC "tab" character code (which is by no means to say that there isn't one - Wikipedia says "The EBCDIC code for HT is 5"). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:46:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:46:52 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: <4B6EB63C.1060208@holdenweb.com> Dennis Lee Bieber wrote: > On Sun, 07 Feb 2010 05:49:28 +0000, Nobody > declaimed the following in gmane.comp.python.general: > > >> 8-column tabs aren't a "*nix convention"; that's been the norm since >> the mechanical typewriter. >> > Really? None of the various Royal, Remington, and Olivetti (sp?) > typewriters I learned on had any knowledge of default tab stops. All had > a row of sliding "pins" on the carriage, which were slid back and forth > by the and button (which required one to first > position the carriage at the position at which the stop was to be > placed). The key itself functioned by first pushing a lever into > the area covered by the stop-row (after the current position stop, if > one existed), then releasing the carriage to slide until the next stop > -- uhm -- stopped the motion by impacting the lever; releasing the > key would then re-engage the normal carriage motion control, and > withdraw the lever. > > 8-space tab stops were, I believe, the default for various computer > terminals, DECwriter printers, and maybe teletype units (in which there > was no moving carriage on which a physical stop could be placed). Not > sure how an 029 keypunch machine would behave -- either punching the > code the a tab character, or skipping to the next field defined on a > drum-card. > When I started my computing career the main input medium at the installation I worked was paper tape, and the Flexowriter (pretty much a mechanical typewriter mechanism with a tape reader and punch attached) was the data preparation device (though teletypes were used at other installations). So it had adjustable tab settings. The 029 punch (and the 026 before it) used a punch card mounte on a drum to set the tab stops, which were therefore completely variable - one would use a different tab card for Fortran and PL/1, for example. So a tab was purely a spacing operation, no chads were punched from the card, and indeed I was never aware of an EBCDIC "tab" character code (which is by no means to say that there isn't one - Wikipedia says "The EBCDIC code for HT is 5"). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:49:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:49:13 -0500 Subject: new.instancemethod __iter__ In-Reply-To: <63288869.8iZ5tTOMcE@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> Message-ID: Martin Drautzburg wrote: > Steven D'Aprano wrote: > >> If you want iterator operations "similar to itertools", why does this >> mean you need to replace anything? Just create your own iterators. >> >> Or use pre-processing and post-processing to get what you want. >> >> Can you show an example of what you would like to happen? > > Steven, > > my classes repesent musical objects. The fundamental paradigm I want to > apply is that of a Sequence, i.e. the most abstract aspect of music is > that "things" occur in a certain order. > > Then I have a TimedSequence class, which is a Sequences whose elements > have a "time" attribute. I now want to be able to append such Sequences > by writing > > s1 = TimedSequence (time=1,'a') # one-element Sequence > s2 = TimedSequence (time=2,'b') > > y = s1*2 + s2 > > Naively appending those sequences would give me > Time=1,'a' > Time=1,'a' > Time=2,'b' > > but this is not what I want. Time needs to progress if I append a > sequence to another. So what I really want is something like > > Time=1,'a' > Time=2,'a' > Time=3,'b' > > This implies that time is shifted to the next integer, but this is not > always the case. I need to know about some kind of "alignment". In > music this translates to "let a sequence start at the beginning of a > bar", or half bar or quarter note or whatever. > > So I want to write > > y = s1*2 + s2(align=10) > > which should iterate as > > Time=1,'a' > Time=2,'a' > Time=10,'b' > > I have no difficulty passing "align" to the object (using __call__) and > use it while I furnish my own __iter__() method. However I don't quite > see how I can do this with bare itertools, though I may be wrong here. > > Bare in mind that it is not only about somehow getting the job done. The > beauty of the resulting syntax is also important. > In that case why not just assume that the timing of a sequence is relative to the current time unless the "align" argument is given? You might also need an event of zero duration to set the start time for a sequence. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From fetchinson at googlemail.com Sun Feb 7 07:57:13 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 13:57:13 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: >>> This is a short complaint on admin abuse on #python irc channel on >>> freenode.net. >> >> Let's see, you are complaining about getting banned from #python by >> CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's >> grounds for extending the IRC ban permanently. > > It certainly doesn't inspire any confidence that Xah's next trip to > #python is likely to last much longer than the last. Some humanity, please! If you look at the web page of the guy it really strikes me as a poor bastard who deserves more pity than bashing. IRC, newsgroups, email, web page, etc, these are the only things that this guy is doing, if you take these things away from him I don't know what will be left for him. Yes, he is annoying, yes, he is trolling, but if this prevents him from jumping under the bus, then I'd say let him do it. How many serial trolls are there on c.l.p? Not many. The average troll should of course be kicked out from everywhere, but guys like Xah are really rare and on humanitarian grounds I think should be allowed to do their things. If you really think about it the damage is not that great. In medieval times 99% of crazy people (using a loose definition of crazy) were either executed or tortured and executed, however, the one lonely village clown or court clown was allowed to be crazy, he even had a decent income from the king. I'm not suggesting a stipend for Xah from the PSF :) but having a single c.l.p clown is tolerable if it makes him happy. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at holdenweb.com Sun Feb 7 08:07:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:07:30 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: hzhuo1 at gmail.com wrote: >> So it seems we both misunderstood the problem. >> >> I didn't read the top level article until now, and reading it, I can't make >> sense of it. >> > > Seems that you should read the whole thing before making a post, or > else you cannot know what we are talking about. > Steven doesn't misunderstand me. We are talking about what I need, and > he tries to help. > > > >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( >> >> [snip] >> > > This is a hash collision problem. Nobody has proved that SHA-256 is > collision free, even not in the random oracle model, because people > always suppose that a random oracle exists, and make hash function its > substitution. That means it may be broken someday. And any provable > security based on random oracle model is not secure. > It's very easy to prove that no hash function is collision-free, since the domain (all possible inputs) is much larger than the range (all possible outputs). Hence there must be many inputs that map to the same output. A *good* hash function is unpredictable enough to make finding two colliding strings impractical - and even the best hash functions that cryptographers could devise at the time have been broken. We should remember that "broken" to a cryptographer means something rather different than it does in common usage, so a broken scheme need not necessarily be dropped immediately - one would just stop using it in new systems. > >>> I'm suggesting that, in general, there's no way to tell in advance which >>> regexes will be easy and which will be hard, and even when they are easy, >>> the enumeration will often be infinite. > > It is hard to tell in advance. However, we can add some timing limit > or counting limit, to make it an algorithm, which can halt. For > example, whenever the program outputs more than 1000000 expressions > that match the input regex, we can halt because that exceeds our > limit. But surely this is not efficient because of the post-decision. > >> Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation >> that denotes "digit sequence") yields an infinite number of strings. > > Infinity is really relative, not absolute. It is relative to the > computing speed. For example, the regex '^[0|1]{2048}$' is rather > simple and doesn't contain '+' or '$', but trying to output all > expressions that match it has a complexity of 2^2048. If we can do > that, then we can break RSA-2048. > We must face the reality . > I have always understood that there's a pretty real distinction between "finite" and "infinite". Are you telling me I am wrong, or are you merely saying that some finite cases might just as well be infinite for practical purposes? And I really don't see how simple enumeration of range(2^2048) breaks RSA-2048, since that problem requires you to find two factors which, when multiplied together, give that specific value. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python.list at tim.thechases.com Sun Feb 7 08:11:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 07:11:10 -0600 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: <4B6EBBEE.2070402@tim.thechases.com> Schif Schaf wrote: > On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: >> I haven't used regexps in Python before, but what I did was (1) look in the >> documentation, [snip] >> >> import re >> >> text = ( >> "Lorem [ipsum] dolor sit amet, consectetur", >> "adipisicing elit, sed do eiusmod tempor", >> "incididunt ut [labore] et [dolore] magna aliqua." >> ) >> >> withbracks = re.compile( r'\[(.+?)\]' ) >> for line in text: >> print( re.sub( withbracks, r'{\1}', line) ) >> > > Seems like there's magic happening here. There's the `withbracks` > regex that applies itself to `line`. But then when `re.sub()` does the > replacement operation, it appears to consult the `withbracks` regex on > the most recent match it just had. I suspect Alf's rustiness with regexps caused him to miss the simpler rendition of print withbacks.sub(r'{\1}', line) And to answer those who are reaching for other non-regex (whether string translations or .replace(), or pyparsing) solutions, it depends on what you want to happen in pathological cases like s = """Dangling closing] with properly [[nested]] and complex [properly [nested] text] and [improperly [nested] text and with some text [straddling lines] and with dangling opening [brackets """ where you'll begin to see the differences. -tkc From anand.shashwat at gmail.com Sun Feb 7 08:15:11 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 18:45:11 +0530 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: LOL pow(funny, sys.maxint) On Sun, Feb 7, 2010 at 6:27 PM, Daniel Fetchinson wrote: > >>> This is a short complaint on admin abuse on #python irc channel on > >>> freenode.net. > >> > >> Let's see, you are complaining about getting banned from #python by > >> CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's > >> grounds for extending the IRC ban permanently. > > > > It certainly doesn't inspire any confidence that Xah's next trip to > > #python is likely to last much longer than the last. > > Some humanity, please! If you look at the web page of the guy it > really strikes me as a poor bastard who deserves more pity than > bashing. IRC, newsgroups, email, web page, etc, these are the only > things that this guy is doing, if you take these things away from him > I don't know what will be left for him. Yes, he is annoying, yes, he > is trolling, but if this prevents him from jumping under the bus, then > I'd say let him do it. How many serial trolls are there on c.l.p? Not > many. The average troll should of course be kicked out from > everywhere, but guys like Xah are really rare and on humanitarian > grounds I think should be allowed to do their things. If you really > think about it the damage is not that great. > > In medieval times 99% of crazy people (using a loose definition of > crazy) were either executed or tortured and executed, however, the one > lonely village clown or court clown was allowed to be crazy, he even > had a decent income from the king. I'm not suggesting a stipend for > Xah from the PSF :) but having a single c.l.p clown is tolerable if it > makes him happy. > > Cheers, > Daniel > > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Feb 7 08:19:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:19:51 -0500 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: <4B6EBDF7.1010907@holdenweb.com> duncan smith wrote: > Christian Heimes wrote: >> duncan smith wrote: >>> Hello, >>> I'm trying to find a clean and reliable way of uncovering >>> information about 'extremal' values for floats on versions of Python >>> earlier than 2.6 (just 2.5 actually). I don't want to add a >>> dependence on 3rd party modules just for this purpose. e.g. For the >>> smallest positive float I'm using, >>> >>> >>> import platform >>> if platform.architecture()[0].startswith('64'): >>> TINY = 2.2250738585072014e-308 >>> else: >>> TINY = 1.1754943508222875e-38 >>> >>> >>> where I've extracted the values for TINY from numpy in IDLE, >>> >>> >>> >>> float(numpy.finfo(numpy.float32).tiny) >>> 1.1754943508222875e-38 >>> >>> float(numpy.finfo(numpy.float64).tiny) >>> 2.2250738585072014e-308 >> >> You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's >> float type is build upon C's double precision float type on both 32 and >> 64 bit builds. The simple precision 32bit float type isn't used. The >> DBL_MIN and DBL_MAX values are equal on all platforms that have full >> IEEE 754 float point support. The radix may be different, though. >> >> Christian > > OK, this is the sort of confusion I suspected. I wasn't thinking > straight. The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. Thanks. > Whether this is relevant or not I can't say, but you must be careful to note that the smallest representable floating-point value (i.e. the smallest number distinguishable from zero) is not the same as the smallest difference between two numbers of a given magnitude. Consider a decimal floating-point system with a two-digit exponent and a four-digit mantissa, and for convenience ignore negative mantissas. The range of representable non-zero values runs from 1E-99 to 9999E99. But adding 1E-99 to (say) 1 will just give you 1 because the system has insufficient precision to represent the true result. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:19:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:19:51 -0500 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: <4B6EBDF7.1010907@holdenweb.com> duncan smith wrote: > Christian Heimes wrote: >> duncan smith wrote: >>> Hello, >>> I'm trying to find a clean and reliable way of uncovering >>> information about 'extremal' values for floats on versions of Python >>> earlier than 2.6 (just 2.5 actually). I don't want to add a >>> dependence on 3rd party modules just for this purpose. e.g. For the >>> smallest positive float I'm using, >>> >>> >>> import platform >>> if platform.architecture()[0].startswith('64'): >>> TINY = 2.2250738585072014e-308 >>> else: >>> TINY = 1.1754943508222875e-38 >>> >>> >>> where I've extracted the values for TINY from numpy in IDLE, >>> >>> >>> >>> float(numpy.finfo(numpy.float32).tiny) >>> 1.1754943508222875e-38 >>> >>> float(numpy.finfo(numpy.float64).tiny) >>> 2.2250738585072014e-308 >> >> You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's >> float type is build upon C's double precision float type on both 32 and >> 64 bit builds. The simple precision 32bit float type isn't used. The >> DBL_MIN and DBL_MAX values are equal on all platforms that have full >> IEEE 754 float point support. The radix may be different, though. >> >> Christian > > OK, this is the sort of confusion I suspected. I wasn't thinking > straight. The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. Thanks. > Whether this is relevant or not I can't say, but you must be careful to note that the smallest representable floating-point value (i.e. the smallest number distinguishable from zero) is not the same as the smallest difference between two numbers of a given magnitude. Consider a decimal floating-point system with a two-digit exponent and a four-digit mantissa, and for convenience ignore negative mantissas. The range of representable non-zero values runs from 1E-99 to 9999E99. But adding 1E-99 to (say) 1 will just give you 1 because the system has insufficient precision to represent the true result. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:25:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:25:28 -0500 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <6C6462AB-4665-40C9-B652-076FA574B872@rocteur.cc> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <6C6462AB-4665-40C9-B652-076FA574B872@rocteur.cc> Message-ID: @ Rocteur CC wrote: > > On 07 Feb 2010, at 10:03, Shashwat Anand wrote: > >> Here is one simple solution : >> >>> intext = """Lorem [ipsum] dolor sit amet, consectetur adipisicing >> elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna >> aliqua.""" >> >> >>> intext.replace('[', '{').replace(']', >> '}') >> 'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do >> eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua.' >> >> /Some people, when confronted with a problem, think "I know, I?ll use >> regular expressions." Now they have two problems./ ? Jamie Zawinski >> in comp.lang.emacs. > > That is because regular expressions are what we learned in programming > the shell from sed to awk and ksh and zsh and of course Perl and we've > read the two books by Jeffrey and much much more!!! > > How do we rethink and relearn how we do things and should we ? > > What is the solution ? > A rigorous focus on programming simplicity. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From fetchinson at googlemail.com Sun Feb 7 08:31:08 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 14:31:08 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: > LOL assert funny > 1 > pow(funny, sys.maxint) >> >>> This is a short complaint on admin abuse on #python irc channel on >> >>> freenode.net. >> >> >> >> Let's see, you are complaining about getting banned from #python by >> >> CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's >> >> grounds for extending the IRC ban permanently. >> > >> > It certainly doesn't inspire any confidence that Xah's next trip to >> > #python is likely to last much longer than the last. >> >> Some humanity, please! If you look at the web page of the guy it >> really strikes me as a poor bastard who deserves more pity than >> bashing. IRC, newsgroups, email, web page, etc, these are the only >> things that this guy is doing, if you take these things away from him >> I don't know what will be left for him. Yes, he is annoying, yes, he >> is trolling, but if this prevents him from jumping under the bus, then >> I'd say let him do it. How many serial trolls are there on c.l.p? Not >> many. The average troll should of course be kicked out from >> everywhere, but guys like Xah are really rare and on humanitarian >> grounds I think should be allowed to do their things. If you really >> think about it the damage is not that great. >> >> In medieval times 99% of crazy people (using a loose definition of >> crazy) were either executed or tortured and executed, however, the one >> lonely village clown or court clown was allowed to be crazy, he even >> had a decent income from the king. I'm not suggesting a stipend for >> Xah from the PSF :) but having a single c.l.p clown is tolerable if it >> makes him happy. >> >> Cheers, >> Daniel >> >> >> >> -- >> Psss, psss, put it down! - http://www.cafepress.com/putitdown >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at holdenweb.com Sun Feb 7 08:31:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:31:24 -0500 Subject: Dynamic variable names In-Reply-To: References: Message-ID: R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I have read that one should use a dictionary in python to accommodate > dynamic variable names. Yet, I am puzzled how to achieve that in my > case. Here is what I want to do: > > 1. The user inputs a number of six-digit hex numbers as a > comma-separated list. These numbers represent colours, but the number of > colours is not known beforehand. > > 2. Using these colours in pairs, I am generating image files whose names > must be unique. I could use the respective hex numbers for this, but > would like to explore generating filenames like > > colour_1-colour_2.jpg > > Because I do not know how many colours there would be in advance, I need > to generate the colour_n names on the fly. > > So, my two questions are: > > 1. How do I do this properly in python? > > 2. If there is a better scheme than what I have outlined, can someone > please point me to a Web link? > Here's one way, though not necessarily the best: >>> import itertools >>> ctr = itertools.count(1) >>> for i in range(5): ... print "colour_%03d-colour%03d.jpg" % (ctr.next(), ctr.next()) ... colour_001-colour002.jpg colour_003-colour004.jpg colour_005-colour006.jpg colour_007-colour008.jpg colour_009-colour010.jpg >>> I zero-filled the names so they sort in numerical order. If this isn't a requirement then simply change the format string to "colour_%d-colour%d.jpg" regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From as at sci.fi Sun Feb 7 08:33:43 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 07 Feb 2010 15:33:43 +0200 Subject: Help with regex search-and-replace (Perl to Python) References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: Schif Schaf writes: > (brackets replaced by braces). I can do that with Perl pretty easily: > > ~~~~ > for (<>) { > s/\[(.+?)\]/\{$1\}/g; > print; > } > ~~~~ Just curious, but since this is just transpose, then why not simply tr/[]/{}/? I.e. why use a regular expression at all for this? In python you would do this with for line in text: print line.replace('[', '{').replace(']', '}') From steve at holdenweb.com Sun Feb 7 08:35:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:35:22 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: Shashwat Anand wrote: > LOL > pow(funny, sys.maxint) > Yes, funny, but it overlooks the point that Xah is a nuisance to multiple communities, not just to ours, and quite often concurrently. I'm all in favor of tolerance, but I'd like to see some evidence that rehabilitation is practical before the community has to tolerate too much of that kind of nonsense. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:37:07 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:37:07 -0500 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <4B6EBBEE.2070402@tim.thechases.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> Message-ID: <4B6EC203.4040807@holdenweb.com> Tim Chase wrote: > Schif Schaf wrote: >> On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: >>> I haven't used regexps in Python before, but what I did was (1) look >>> in the >>> documentation, > [snip] >>> >>> import re >>> >>> text = ( >>> "Lorem [ipsum] dolor sit amet, consectetur", >>> "adipisicing elit, sed do eiusmod tempor", >>> "incididunt ut [labore] et [dolore] magna aliqua." >>> ) >>> >>> withbracks = re.compile( r'\[(.+?)\]' ) >>> for line in text: >>> print( re.sub( withbracks, r'{\1}', line) ) >>> >> >> Seems like there's magic happening here. There's the `withbracks` >> regex that applies itself to `line`. But then when `re.sub()` does the >> replacement operation, it appears to consult the `withbracks` regex on >> the most recent match it just had. > > I suspect Alf's rustiness with regexps caused him to miss the simpler > rendition of > > print withbacks.sub(r'{\1}', line) > > And to answer those who are reaching for other non-regex (whether string > translations or .replace(), or pyparsing) solutions, it depends on what > you want to happen in pathological cases like > > s = """Dangling closing] > with properly [[nested]] and > complex [properly [nested] text] > and [improperly [nested] text > and with some text [straddling > lines] and with > dangling opening [brackets > """ > where you'll begin to see the differences. > Really? Under what circumstances does a simple one-for-one character replacement operation fail? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:37:07 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:37:07 -0500 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <4B6EBBEE.2070402@tim.thechases.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> Message-ID: <4B6EC203.4040807@holdenweb.com> Tim Chase wrote: > Schif Schaf wrote: >> On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: >>> I haven't used regexps in Python before, but what I did was (1) look >>> in the >>> documentation, > [snip] >>> >>> import re >>> >>> text = ( >>> "Lorem [ipsum] dolor sit amet, consectetur", >>> "adipisicing elit, sed do eiusmod tempor", >>> "incididunt ut [labore] et [dolore] magna aliqua." >>> ) >>> >>> withbracks = re.compile( r'\[(.+?)\]' ) >>> for line in text: >>> print( re.sub( withbracks, r'{\1}', line) ) >>> >> >> Seems like there's magic happening here. There's the `withbracks` >> regex that applies itself to `line`. But then when `re.sub()` does the >> replacement operation, it appears to consult the `withbracks` regex on >> the most recent match it just had. > > I suspect Alf's rustiness with regexps caused him to miss the simpler > rendition of > > print withbacks.sub(r'{\1}', line) > > And to answer those who are reaching for other non-regex (whether string > translations or .replace(), or pyparsing) solutions, it depends on what > you want to happen in pathological cases like > > s = """Dangling closing] > with properly [[nested]] and > complex [properly [nested] text] > and [improperly [nested] text > and with some text [straddling > lines] and with > dangling opening [brackets > """ > where you'll begin to see the differences. > Really? Under what circumstances does a simple one-for-one character replacement operation fail? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python.list at tim.thechases.com Sun Feb 7 08:47:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 07:47:17 -0600 Subject: How to print all expressions that match a regular expression In-Reply-To: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: <4B6EC465.3000405@tim.thechases.com> hzhuo1 at gmail.com wrote: >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." > > This is a hash collision problem. Nobody has proved that SHA-256 is > collision free It's actually pretty easy to prove that it is *not* collision free. The SHA-256 encodes 512 bits of data. So the the process of encoding (2**512)+1 distinct inputs incurs a collision in SHA-256 space as soon as you've hit (2**512)+1 if not earlier. to start you off: sha_backmap = {} for i in xrange((2**512)+2): hash = sha(str(i)) if hash in sha_backmap: print "Collision found: %i and %i" % ( i, sha_backmap[hash]) break sha_backmap[hash] = i Though it might take a computer the size of the universe, so I'm guessing that the first collision encountered is with "42". I leave the actual calculation and hashing of all possible combinations of 513 bits of data as an exercise to the reader with a lot of time on their hands or a quantum computer under their desk ;-) > It is hard to tell in advance. However, we can add some timing limit > or counting limit, to make it an algorithm, which can halt. For > example, whenever the program outputs more than 1000000 expressions > that match the input regex, we can halt because that exceeds our > limit. But surely this is not efficient because of the post-decision. As mentioned, it sounds like you either want a depth-first of the solution space that raises exceptions on an infinite/unbounded operator ("*", "+", and "{N,}" as mentioned in another email), or if you want to handle those operators, do a breadth-first search of the solution-space and track your depth (or time taken, or previous number of multi-factor atoms if you desire) to ensure you don't exceed a certain depth. But you're still talking a combinatorial number of solutions for even simple regexps. -tkc From python.list at tim.thechases.com Sun Feb 7 08:57:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 07:57:31 -0600 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <4B6EC203.4040807@holdenweb.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> <4B6EC203.4040807@holdenweb.com> Message-ID: <4B6EC6CB.8090800@tim.thechases.com> Steve Holden wrote: > Tim Chase wrote: >> And to answer those who are reaching for other non-regex (whether string >> translations or .replace(), or pyparsing) solutions, it depends on what >> you want to happen in pathological cases like >> >> s = """Dangling closing] >> with properly [[nested]] and >> complex [properly [nested] text] >> and [improperly [nested] text >> and with some text [straddling >> lines] and with >> dangling opening [brackets >> """ >> where you'll begin to see the differences. >> > Really? Under what circumstances does a simple one-for-one character > replacement operation fail? Failure is only defined in the clarified context of what the OP wants :) Replacement operations only fail if the OP's desired output from the above mess doesn't change *all* of the ]/[ characters, but only those with some form of parity (nested or otherwise). But if the OP *does* want all of the ]/[ characters replaced regardless of contextual nature, then yes, replace is a much better solution than regexps. -tkc From fetchinson at googlemail.com Sun Feb 7 09:11:41 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 15:11:41 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: >> LOL >> pow(funny, sys.maxint) >> > Yes, funny, but it overlooks the point that Xah is a nuisance to > multiple communities, not just to ours, and quite often concurrently. I don't think we need to worry about other communities or every internet related problem. The only thing we need to make sure is that c.l.p or the python community in general is friendly, tolerant, healthy and perhaps shows a good example to other communities on how to run a community, including how to handle problematic behavior. > I'm all in favor of tolerance, but I'd like to see some evidence that > rehabilitation is practical before the community has to tolerate too > much of that kind of nonsense. I don't think you get my point. Rehabilitation or cure is not the goal here. A village clown or court clown never changed, never got cured, never got reintroduced into the community as a 'normal' person. A village clown is tolerated in the purest form of the word 'tolerance' by nor wishing him to change. Let him be the clown, let everybody accept him as such, including all the annoyance and weird behavior. Hoping for someone to change is the same as assigning him to a correctional facility. I'd say let's designate a post Python Community Jester, or PCJ for short, let's name Xah Lee the PCJ and make it clear that he can engage in his activities on c.l.p and #python as he wishes without retribution and fear, and nobody should really bother him. The only people should do who don't like him is ignoring him. What is very important is that there can be only one PCJ and everybody else with objectionable behavior will be banned, blacklisted, etc. with the full force of available methods. This would I think send a very clear message to all other online communities that the Python Community is able to think outside the box, and is not afraid of taking unusual steps to maintain a healthy community and is even able to incorporate revolutionary new tactics to keep the community friendly and tolerant. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Sun Feb 7 09:14:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 15:14:42 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: >>> LOL >>> pow(funny, sys.maxint) >>> >> Yes, funny, but it overlooks the point that Xah is a nuisance to >> multiple communities, not just to ours, and quite often concurrently. > > I don't think we need to worry about other communities or every > internet related problem. The only thing we need to make sure is that > c.l.p or the python community in general is friendly, tolerant, > healthy and perhaps shows a good example to other communities on how > to run a community, including how to handle problematic behavior. > >> I'm all in favor of tolerance, but I'd like to see some evidence that >> rehabilitation is practical before the community has to tolerate too >> much of that kind of nonsense. > > I don't think you get my point. Rehabilitation or cure is not the goal > here. A village clown or court clown never changed, never got cured, > never got reintroduced into the community as a 'normal' person. A > village clown is tolerated in the purest form of the word 'tolerance' > by nor wishing him to change. Let him be the clown, let everybody > accept him as such, including all the annoyance and weird behavior. > Hoping for someone to change is the same as assigning him to a > correctional facility. > > I'd say let's designate a post Python Community Jester, or PCJ for > short, let's name Xah Lee the PCJ and make it clear that he can engage > in his activities on c.l.p and #python as he wishes without > retribution and fear, and nobody should really bother him. The only > people should do who don't like him is ignoring him. What is very > important is that there can be only one PCJ and everybody else with > objectionable behavior will be banned, blacklisted, etc. with the full > force of available methods. > > This would I think send a very clear message to all other online > communities that the Python Community is able to think outside the > box, and is not afraid of taking unusual steps to maintain a healthy > community and is even able to incorporate revolutionary new tactics to > keep the community friendly and tolerant. One more thing: if every online community (or only programming related newsgroup) would designate an XY Community Jester I believe the relatively few number of serial trolls would all find their places somewhere eventually. This approach would actually work and solve a serious problem, as opposed to building more jails and more correctional facilities. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From as at sci.fi Sun Feb 7 09:30:52 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 07 Feb 2010 16:30:52 +0200 Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> Message-ID: jonny lowe writes: > The result is the same as before. I've tested in fedora11. I don't think script is the answer here, since it only stores what's displayed on a terminal and your program's input comes from a file and is not displayed on the terminal. Simplest solution is probably that you have your program echo every line of input. Maybe some hairy terminal trickery could be done? Really more of a Linux question than python. From darcy at druid.net Sun Feb 7 09:48:45 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 7 Feb 2010 09:48:45 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <20100207094845.4c448cf1.darcy@druid.net> On Sun, 7 Feb 2010 15:11:41 +0100 Daniel Fetchinson wrote: > I'd say let's designate a post Python Community Jester, or PCJ for > short, let's name Xah Lee the PCJ and make it clear that he can engage > in his activities on c.l.p and #python as he wishes without > retribution and fear, and nobody should really bother him. The only Are you sure you aren't lobbying for the position for yourself? I think you have a shot based on this proposal. -- 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 Martin.Drautzburg at web.de Sun Feb 7 09:50:53 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sun, 07 Feb 2010 15:50:53 +0100 Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> Message-ID: <1458390.bWaDTVVBS2@beaureve.gmx.net> Steve Holden wrote: >> y = s1*2 + s2(align=10) >> >> which should iterate as >> >> Time=1,'a' >> Time=2,'a' >> Time=10,'b' >> >> I have no difficulty passing "align" to the object (using __call__) >> and use it while I furnish my own __iter__() method. However I don't >> quite see how I can do this with bare itertools, though I may be >> wrong here. >> >> Bare in mind that it is not only about somehow getting the job done. >> The beauty of the resulting syntax is also important. >> > In that case why not just assume that the timing of a sequence is > relative to the current time unless the "align" argument is given? Well that's pretty much what I'm doing. I just fail to see how I can do this with bare itertools. Currently I am doing it in the following way: When I call a Sequence as in s2(align=2) I create a new Sequence where the "align" value is simply stored in an instance variable. When creating the sum of two sequences, I create a Sequence with a new iter() method which first iterates over self and then over the second Sequence. But each time it has to look up the "align" value of the respective sequence and adjust "time" accordingly. Appending the two Sequences is the easy part, but adjusting time is the difficult part. My impression was, that itertools can only help to solve the first part. I may be missing something obvious. If that's the case, please let me know. From hzhuo1 at gmail.com Sun Feb 7 10:08:51 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sun, 7 Feb 2010 07:08:51 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> > > And I really don't see how simple enumeration of range(2^2048) breaks > RSA-2048, since that problem requires you to find two factors which, > when multiplied together, give that specific value. > I can tell you why is that. RSA-2048 has a composite of length less than 2^2048, which is a product of two large primes. So one of its factors cannot exceed 2^2047, and we can treat the multiplication as a computation with constant complexity. So the time complexity of enumerating 2^2048 strings is the same with factoring a composite with length 2^2048 which is the product of two primes. And obviously, whenever we successfully factor the composite, we can calculate the Euler function of it. So that given any public key (n,e), calculating the private key (n,d) is easy. From steve at holdenweb.com Sun Feb 7 10:10:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:10:15 -0500 Subject: new.instancemethod __iter__ In-Reply-To: <1458390.bWaDTVVBS2@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> <1458390.bWaDTVVBS2@beaureve.gmx.net> Message-ID: <4B6ED7D7.6050106@holdenweb.com> Martin Drautzburg wrote: > Steve Holden wrote: > > >>> y = s1*2 + s2(align=10) >>> >>> which should iterate as >>> >>> Time=1,'a' >>> Time=2,'a' >>> Time=10,'b' >>> >>> I have no difficulty passing "align" to the object (using __call__) >>> and use it while I furnish my own __iter__() method. However I don't >>> quite see how I can do this with bare itertools, though I may be >>> wrong here. >>> >>> Bare in mind that it is not only about somehow getting the job done. >>> The beauty of the resulting syntax is also important. >>> >> In that case why not just assume that the timing of a sequence is >> relative to the current time unless the "align" argument is given? > > Well that's pretty much what I'm doing. I just fail to see how I can do > this with bare itertools. Currently I am doing it in the following way: > > When I call a Sequence as in s2(align=2) I create a new Sequence where > the "align" value is simply stored in an instance variable. > > When creating the sum of two sequences, I create a Sequence with a new > iter() method which first iterates over self and then over the second > Sequence. But each time it has to look up the "align" value of the > respective sequence and adjust "time" accordingly. > > Appending the two Sequences is the easy part, but adjusting time is the > difficult part. My impression was, that itertools can only help to > solve the first part. > > I may be missing something obvious. If that's the case, please let me > know. > Perhaps I am assuming too much of your simulation environment/player. I presumed that there would be a global "current time" value that would be passed into or available to the play method of the sequences. However I can see that you might need something more complex if (e.g.) you want to be able to start playing at an arbitrary point in time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:10:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:10:15 -0500 Subject: new.instancemethod __iter__ In-Reply-To: <1458390.bWaDTVVBS2@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> <1458390.bWaDTVVBS2@beaureve.gmx.net> Message-ID: <4B6ED7D7.6050106@holdenweb.com> Martin Drautzburg wrote: > Steve Holden wrote: > > >>> y = s1*2 + s2(align=10) >>> >>> which should iterate as >>> >>> Time=1,'a' >>> Time=2,'a' >>> Time=10,'b' >>> >>> I have no difficulty passing "align" to the object (using __call__) >>> and use it while I furnish my own __iter__() method. However I don't >>> quite see how I can do this with bare itertools, though I may be >>> wrong here. >>> >>> Bare in mind that it is not only about somehow getting the job done. >>> The beauty of the resulting syntax is also important. >>> >> In that case why not just assume that the timing of a sequence is >> relative to the current time unless the "align" argument is given? > > Well that's pretty much what I'm doing. I just fail to see how I can do > this with bare itertools. Currently I am doing it in the following way: > > When I call a Sequence as in s2(align=2) I create a new Sequence where > the "align" value is simply stored in an instance variable. > > When creating the sum of two sequences, I create a Sequence with a new > iter() method which first iterates over self and then over the second > Sequence. But each time it has to look up the "align" value of the > respective sequence and adjust "time" accordingly. > > Appending the two Sequences is the easy part, but adjusting time is the > difficult part. My impression was, that itertools can only help to > solve the first part. > > I may be missing something obvious. If that's the case, please let me > know. > Perhaps I am assuming too much of your simulation environment/player. I presumed that there would be a global "current time" value that would be passed into or available to the play method of the sequences. However I can see that you might need something more complex if (e.g.) you want to be able to start playing at an arbitrary point in time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From fuzzy.666.chaos at gmail.com Sun Feb 7 10:22:55 2010 From: fuzzy.666.chaos at gmail.com (Jordan Uchima) Date: Sun, 7 Feb 2010 09:22:55 -0600 Subject: still having problems with "Nim". using python 2.6.4 Message-ID: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> I have attached the file that the game is on. feel free to modify it to make it better. all suggestions are welcome. if you don't want to download the file then here's the code: ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Start with thirteen pieces and two players. # Each player takes 1 - 4 pieces each turn. # Player who takes the last piece loses. # Declare constants. NUMBER_OF_PLAYERS = 2 TOTAL_PIECES_AT_START = 13 namePlayer1 = raw_input("Hello Player 1, what is your name?\n") namePlayer2 = raw_input("Hello Player 2, what is your name?\n") # Declare functions. def rules(): """Print the rules of the game.""" print 'The player that takes the last piece loses!'\ 'You can only take 1 - 4 pieces!\n\n' def get_players(): """Get the names of the players.""" # Let's put the player's names in a list. players = [] # Looping like this saves us repeating lines of code for each player. for player in range(NUMBER_OF_PLAYERS): players.append(player) break return players def take_turn(player): """Handle a player's turn.""" # Turn logic goes here. player1Choice = int(raw_input(namePlayer1 + " how many pieces would you like to take?\n")), player2Choice = int(raw_input(namePlayer2 + " how many pieces would you like to take?\n")) playerChoice = player1Choice and player2Choice x = 13 - playerChoice loss = x <=2 and x >= 0, while player1Choice == loss is True: print namePlayer1 + " loses!" while player2Choice == loss is True: print namePlayer2, loss while player1Choice and player2Choice == loss is True: print "It's a draw!" while player1Choice != loss is True: print x while player2Choice != loss is True: print x while player1Choice and player2Choice != loss is True: print ("Keep going! Only ", x, " pieces left!") validChoice = \ player1Choice == range(1, 4) is True, print x player1Choice == range(1, 4) is False, print validChoice player2Choice == range(1, 4) is True, print x player2Choice == range(1, 4) is False, print validChoice def main(): """Run the game.""" # Display the rules by calling rules function. rules() # Get the players by calling the get_players function. players = get_players() # Set up the game. remaining_pieces = TOTAL_PIECES_AT_START playing = True # Main loop - let's play! while playing: # Take turns. for player in players: remaining_pieces = take_turn(player) # Check if this player has lost. if remaining_pieces <= 1: # Player has taken last piece. print 'Sorry ', loser, ' you have lost.' # Break out of the loop playing = False break # Automatically run main function if we're run as a script. if __name__ == '__main__': main() # End. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- my problem is that i can't get it to make the players have more than 1 turn each, it accepts any value for playerChoice, (it is only supposed to accept values from 1 to 4), and "x" resets after each turn. i can get it to subtract playerChoice from "x", and display the result, which should be "x", but, then, "x" resets... by the way, i need this program finished by wednesday, Feb. 10, 2010. Please help me!!! -- Jordan (fuzzy.666.chaos at gmail.com) -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Nim.py Type: application/octet-stream Size: 2785 bytes Desc: not available URL: From steve at holdenweb.com Sun Feb 7 10:38:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:38:38 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> Message-ID: <4B6EDE7E.7020304@holdenweb.com> hzhuo1 at gmail.com wrote: >> And I really don't see how simple enumeration of range(2^2048) breaks >> RSA-2048, since that problem requires you to find two factors which, >> when multiplied together, give that specific value. >> > > I can tell you why is that. RSA-2048 has a composite of length less > than 2^2048, which is a product of two large primes. So one of its > factors cannot exceed 2^2047, and we can treat the multiplication as a > computation with constant complexity. So the time complexity of > enumerating 2^2048 strings is the same with factoring a composite with > length 2^2048 which is the product of two primes. > > And obviously, whenever we successfully factor the composite, we can > calculate the Euler function of it. So that given any public key > (n,e), calculating the private key (n,d) is easy. > So all I have to do to break RSA is to count to 2^2048? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:38:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:38:38 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> Message-ID: <4B6EDE7E.7020304@holdenweb.com> hzhuo1 at gmail.com wrote: >> And I really don't see how simple enumeration of range(2^2048) breaks >> RSA-2048, since that problem requires you to find two factors which, >> when multiplied together, give that specific value. >> > > I can tell you why is that. RSA-2048 has a composite of length less > than 2^2048, which is a product of two large primes. So one of its > factors cannot exceed 2^2047, and we can treat the multiplication as a > computation with constant complexity. So the time complexity of > enumerating 2^2048 strings is the same with factoring a composite with > length 2^2048 which is the product of two primes. > > And obviously, whenever we successfully factor the composite, we can > calculate the Euler function of it. So that given any public key > (n,e), calculating the private key (n,d) is easy. > So all I have to do to break RSA is to count to 2^2048? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:46:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:46:34 -0500 Subject: still having problems with "Nim". using python 2.6.4 In-Reply-To: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> References: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> Message-ID: <4B6EE05A.8080100@holdenweb.com> Jordan Uchima wrote: > I have attached the file that the game is on. feel free to modify it to > make it better. all suggestions are welcome. if you don't want to > download the file then here's the code: > [...] > > my problem is that i can't get it to make the players have more than 1 > turn each, it accepts any value for playerChoice, (it is only supposed > to accept values from 1 to 4), and "x" resets after each turn. i can get > it to subtract playerChoice from "x", and display the result, which > should be "x", but, then, "x" resets... by the way, i need this program > finished by wednesday, Feb. 10, 2010. Please help me!!! > The deadline implies an even higher probability that this is homework. I don't know whether you declared this in your earlier post, but it's always as well to do so. You've made a substantial effort to solve the problem though, so I don't mind trying to help. I hope you regard the following as helpful. You need a program structure that keeps going until the required termination condition is reached. One such structure would be: while sticks_remaining > 1: taketurn(next_player()) So now you only need a next_player() function that returns alternate values on successive calls and a taketurn() function that reduces the number of sticks according to the instructions form the given player. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:46:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:46:34 -0500 Subject: still having problems with "Nim". using python 2.6.4 In-Reply-To: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> References: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> Message-ID: <4B6EE05A.8080100@holdenweb.com> Jordan Uchima wrote: > I have attached the file that the game is on. feel free to modify it to > make it better. all suggestions are welcome. if you don't want to > download the file then here's the code: > [...] > > my problem is that i can't get it to make the players have more than 1 > turn each, it accepts any value for playerChoice, (it is only supposed > to accept values from 1 to 4), and "x" resets after each turn. i can get > it to subtract playerChoice from "x", and display the result, which > should be "x", but, then, "x" resets... by the way, i need this program > finished by wednesday, Feb. 10, 2010. Please help me!!! > The deadline implies an even higher probability that this is homework. I don't know whether you declared this in your earlier post, but it's always as well to do so. You've made a substantial effort to solve the problem though, so I don't mind trying to help. I hope you regard the following as helpful. You need a program structure that keeps going until the required termination condition is reached. One such structure would be: while sticks_remaining > 1: taketurn(next_player()) So now you only need a next_player() function that returns alternate values on successive calls and a taketurn() function that reduces the number of sticks according to the instructions form the given player. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From aahz at pythoncraft.com Sun Feb 7 11:00:27 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Feb 2010 08:00:27 -0800 Subject: threading+popen2 hang References: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> Message-ID: In article <188bfb67-3334-4325-adfc-3fa4d28f0cbf at d27g2000yqn.googlegroups.com>, lofic wrote: > >Works fine on RHEL5/python 2.4.3 >Hangs on RHEL4/python 2.3.4 Then use Python 2.4 -- surely you don't expect anyone to provide bugfixes for a release that's several years old? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Sun Feb 7 11:24:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Feb 2010 08:24:04 -0800 Subject: passing string for editing in input() References: Message-ID: In article , Chris Rebert wrote: >On Tue, Feb 2, 2010 at 5:24 AM, mk wrote: >> >> Is there an easy way to get an editing (readline) in Python that would >> contain string for editing and would not just be empty? >> >> I googled but found nothing. > >Er...: http://docs.python.org/library/readline.html >It's the third hit for "python readline". > >Actually reading the page, sounds like you want readline.insert_text() >specifically. That seems a tad harsh, especially after reading the docs and following Peter Otten's link. It's not at all obvious how to actually use insert_text(), and although I probably could have figured it out on my own, I might well have posted here myself. Did you try using insert_text() before posting? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at REMOVE-THIS-cybersource.com.au Sun Feb 7 11:31:12 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 16:31:12 GMT Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <00f87008$0$15628$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 13:57:13 +0100, Daniel Fetchinson wrote: > having a single c.l.p clown is tolerable if it makes him happy. Why should we care about his happiness if it comes at the expense of the happiness of hundreds of other people? I mean, if he decided that his happiness was best satisfied by following you home one day and smashing all your windows and pouring tar all over your furniture and smearing excrement over your clothes, should we tolerate that because it makes him happy? And later, in another post: > A village clown is tolerated in the purest form of the word 'tolerance' > by nor wishing him to change. Let him be the clown, let everybody > accept him as such, including all the annoyance and weird behavior. Why should we? What's in it for us? > Hoping for someone to change is the same as assigning him to a > correctional facility. That's a ridiculous comparison, which could only have been spoken to somebody who has never been in prison. You trivialise the problem of the punishment society by equating it to expecting a modicum of polite behaviour in public. > I'd say let's designate a post Python Community Jester, or PCJ for > short, let's name Xah Lee the PCJ and make it clear that he can engage > in his activities on c.l.p and #python as he wishes without > retribution and fear, and nobody should really bother him. The only > people should do who don't like him is ignoring him. What is very > important is that there can be only one PCJ and everybody else with > objectionable behavior will be banned, blacklisted, etc. with the full > force of available methods. Why should Xah Lee get special treatment? If other anti-social nuisances and trolls are banned, why should he get the privilege of being tolerated no matter what he does? What is so special about Xah Lee that he gets carte blanche permission to be as obnoxious as he wants, while everyone else has to follow the rules of polite society? -- Steven From ldl08 at gmx.net Sun Feb 7 12:07:33 2010 From: ldl08 at gmx.net (David) Date: Mon, 08 Feb 2010 01:07:33 +0800 Subject: Your impression of for-novice writings on assertions In-Reply-To: References: Message-ID: <4B6EF355.1040405@gmx.net> Hi Alf, I think you talk too much... :-) Basically I am all for a verbose approach in a text for beginners, but on the other hand it is necessary to stick to the point you are making. When, for example, you introduce your reader to the thoughts of Francis Glassborrow on page 5 of chapter three, then the only relevant point you are making is the following: "Many programmers hide the structure of their code behind their comments [which is to be avoided]". If you insist on a proper citation here, then use a footnote, but even there I would suggest you merely offer the link. As it stands you are not to the point, and frankly, as a beginner I have enough stuff troubling my head so that I do not need superfluous information as to the evolution of the things you are talking about. Just the facts, please. My 2 cents, David On 03/02/10 04:54, Alf P. Steinbach wrote: > I've started on ch 3 of my beginner's intro to programming, now delving > into the details of the Python language. > > It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at > which is at Google Docs. > > The first topic is about assertions and exceptions. I wonder whether > this text is easy or difficult to understand for a beginner. Or any > improvements that could be made. > > > Cheers, > > - Alf From john at castleamber.com Sun Feb 7 12:38:51 2010 From: john at castleamber.com (John Bokma) Date: Sun, 07 Feb 2010 11:38:51 -0600 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <87eikx54k4.fsf@castleamber.com> Daniel Fetchinson writes: > One more thing: Yeah, one more thing: since you are all for a better community why not reply without quoting the entire message? Just quote enough to provide some decent context. Xah is just a spammer. It amazes me how often people want to step in the role of Xah's sockpuppet. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Sun Feb 7 13:20:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 07 Feb 2010 13:20:25 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: On 2/7/2010 7:39 AM, Steve Holden wrote: > Clearly written by someone who has never *used* a mechanical typewriter. > The original mechanisms had "tab set" and "tab clear" keys, so you had > variable tabbing according to the needs of the particular document you > were working on. Look under "T" in > > http://www.mytypewriter.com/explorelearn/glossary.html > > if you aren't old enough to have used one. I did start with real typewriters. The 'standard', if anything, was 1/2" for paragraph indents. That was 5 chars with normal 10 cpi type, 6 with 12 cpi 'elite' type. I used both. I always thought the 8 char unix indent to be excessive. If a power of 2 was needed, rounding 5 down to 4 would have been more sensible. Wordperfect, which I wrote a couple of books with, followed the typewriter model in defaulting tab stops to every 1/2 inch, regardless of font. Sensible software tab defaults were not pioneered by Microsoft. Terry Jan Reedy From darnzen at gmail.com Sun Feb 7 13:24:40 2010 From: darnzen at gmail.com (darnzen) Date: Sun, 7 Feb 2010 10:24:40 -0800 (PST) Subject: WCK and PIL References: <1fbe5e4b-2179-410b-9f76-9d65a7a08dce@k19g2000yqc.googlegroups.com> Message-ID: <28dee2e8-25a1-4f1d-901e-d8f7d0417e0a@z26g2000yqm.googlegroups.com> On Feb 6, 10:19?pm, Nobody wrote: > On Fri, 05 Feb 2010 21:05:53 -0800, darnzen wrote: > > I've written an app using thewcklibrary (widget construction kit, > > seehttp://www.effbot.org), in addition to the wckGraph module. What > > I'd like to do, is take the output of one of my windows (happens to be > > a graph), and save it as a *.png or *.gif. I was planning on using the > >PILfor this. I'd like to use the code I have as is, without re- > > writing all the graphic calls to usePILmethods. > > >WCKuses its own "pixmap" class for storing images in memory. I can't > > find any documentation or class reference for pixmap and what I find > > in the source is confusing. > > AWCKpixmap is a "draw object" whose underlying drawable is a pixmap > (i.e. a Tk pixmap, which is the platform's native "chunk of video memory" > pixmap type) rather than a window. > > From the source code,WCKdoesn't appear to offer any way to retrieve the > pixel data (i.e. there's no way to do the opposite of draw.paste()). I found a description of how to use a WCK drawing interface to draw into a PIL image. (http://effbot.org/zone/pil-draw-wck.htm) but I'm not sure how to use that class (SimpleDraw) to allow me to use existing WCK code. Should I use it as a "mix in" to overwrite base methods via inheritance? class MyClass(SimpleDraw, Widget): pass From rikutheronin at gmail.com Sun Feb 7 13:36:10 2010 From: rikutheronin at gmail.com (Pablo Recio Quijano) Date: Sun, 7 Feb 2010 19:36:10 +0100 Subject: Checking the coding style Message-ID: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Hi! I'm finishing a project writen in Python, and I realize about the document PEP8 - Style Guide for Python Code [1]. Is there any app or script that checks if my project pass that style guide? I also worked with Drupal, and I know there is some modules and scripts that checks its coding standars [2] and it's very usefull to clean the code. Thanks in advance! [1] http://www.python.org/dev/peps/pep-0008/ [2] http://drupal.org/coding-standards -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From misceverything at gmail.com Sun Feb 7 14:02:30 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 11:02:30 -0800 (PST) Subject: Executing Commands From Windows Service Message-ID: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> I have a script, which runs as a Windows service under the LocalSystem account, that I wish to have execute some commands. Specifically, the program will call plink.exe to create a reverse SSH tunnel. Right now I'm using subprocess.Popen to do so. When I run it interactively via an admin account, all is well. However, when I'm running it via service, no luck. I'm assuming this is to do with the fact that it's trying to run under the LocalSystem account, which is failing. What would be the best way around this? Thanks! From gerald.britton at gmail.com Sun Feb 7 14:17:19 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Sun, 7 Feb 2010 14:17:19 -0500 Subject: Checking the coding style In-Reply-To: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Message-ID: <5d1a32001002071117n18ba7b47j515d75946b79af0f@mail.gmail.com> pylint and pychecker are good options On Sun, Feb 7, 2010 at 1:36 PM, Pablo Recio Quijano wrote: > Hi! > I'm finishing a project writen in Python, and I realize about the document > PEP8 - Style Guide for Python Code [1]. > Is there any app or script that checks if my project pass that style guide? > I also worked with Drupal, and I know there is some modules and scripts that > checks its coding standars [2] and it's very usefull to clean the code. > Thanks in advance! > [1]?http://www.python.org/dev/peps/pep-0008/ > [2]?http://drupal.org/coding-standards > > -- > Pablo Recio Quijano > > Estudiante de Ingenier?a Inform?tica (UCA) > Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos > Participante del IV Concurso Universitario de Software Libre > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Gerald Britton From apt.shansen at gmail.com Sun Feb 7 14:17:40 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 7 Feb 2010 11:17:40 -0800 Subject: Executing Commands From Windows Service In-Reply-To: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <7a9c25c21002071117p139f00bx19362eaf72a8d037@mail.gmail.com> On Sun, Feb 7, 2010 at 11:02 AM, T wrote: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. Specifically, the > program will call plink.exe to create a reverse SSH tunnel. Right now > I'm using subprocess.Popen to do so. When I run it interactively via > an admin account, all is well. However, when I'm running it via > service, no luck. I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. What > would be the best way around this? Thanks! > I don't know what your specific issue is, but here's some tips for running Python as a service on windows which are not always immediately obvious and can cause failures: - The search path is screwy: if you are importing a module that happens to be the same name as a dll in system32 (even if this isn't at all a python dll), it can get confused. - There is *no* sys.stdout! This is a big one. If any piece of code you're using ever does 'print', the whole thing can crash hard. I replace sys.stdout and sys.stderr with a fake file-like object that catches errors in attempting to .write to the real one and ignores them. If neither of those two are a problem for you, you need to define "no luck" before anyone will be able to help you. Are there errors in the event viewer? Are you getting an exception that's killing out your service (capture and write to a file with the logging module)? Or is the Popen call being run and returning but just not doing anything (in which case, try capturing output from the command and see if it indicates an error message from plink.exe). Etc. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Sun Feb 7 14:22:26 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 7 Feb 2010 19:22:26 +0000 (UTC) Subject: Checking the coding style References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Message-ID: On Sun, 07 Feb 2010 19:36:10 +0100, Pablo Recio Quijano wrote: > Hi! > > I'm finishing a project writen in Python, and I realize about the > document PEP8 - Style Guide for Python Code [1]. > > Is there any app or script that checks if my project pass that style > guide? I also worked with Drupal, and I know there is some modules and > scripts that checks its coding standars [2] and it's very usefull to > clean the code. > > Thanks in advance! > > [1] http://www.python.org/dev/peps/pep-0008/ [2] > http://drupal.org/coding-standards Hello Pablo, The pep8 package (http://pypi.python.org/pypi/pep8) can do this, though I have never used it myself. PyLint is a customisable static analysis program that checks style among other things. Cheers, Kev From rikutheronin at gmail.com Sun Feb 7 14:27:45 2010 From: rikutheronin at gmail.com (Pablo Recio Quijano) Date: Sun, 7 Feb 2010 20:27:45 +0100 Subject: Checking the coding style In-Reply-To: <5d1a32001002071117n18ba7b47j515d75946b79af0f@mail.gmail.com> References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> <5d1a32001002071117n18ba7b47j515d75946b79af0f@mail.gmail.com> Message-ID: <1fb1c371002071127u8cf0bf2w3eeef60c03bf6868@mail.gmail.com> Thanks! Pylint was what i was loking for 2010/2/7 Gerald Britton > pylint and pychecker are good options > > On Sun, Feb 7, 2010 at 1:36 PM, Pablo Recio Quijano > wrote: > > Hi! > > I'm finishing a project writen in Python, and I realize about the > document > > PEP8 - Style Guide for Python Code [1]. > > Is there any app or script that checks if my project pass that style > guide? > > I also worked with Drupal, and I know there is some modules and scripts > that > > checks its coding standars [2] and it's very usefull to clean the code. > > Thanks in advance! > > [1] http://www.python.org/dev/peps/pep-0008/ > > [2] http://drupal.org/coding-standards > > > > -- > > Pablo Recio Quijano > > > > Estudiante de Ingenier?a Inform?tica (UCA) > > Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos > > Participante del IV Concurso Universitario de Software Libre > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > Gerald Britton > -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Sun Feb 7 14:59:40 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sun, 7 Feb 2010 11:59:40 -0800 (PST) Subject: Checking the coding style References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Message-ID: <4f2ae5b7-1b4e-46cc-94ae-e70b3099ea7a@d37g2000yqa.googlegroups.com> On Feb 7, 8:22?pm, Kev Dwyer wrote: > On Sun, 07 Feb 2010 19:36:10 +0100, Pablo Recio Quijano wrote: > > Hi! > > > I'm finishing a project writen in Python, and I realize about the > > document PEP8 - Style Guide for Python Code [1]. > > > Is there any app or script that checks if my project pass that style > > guide? I also worked with Drupal, and I know there is some modules and > > scripts that checks its coding standars [2] and it's very usefull to > > clean the code. > > > Thanks in advance! > > > [1]http://www.python.org/dev/peps/pep-0008/[2] > >http://drupal.org/coding-standards > > Hello Pablo, > > The pep8 package (http://pypi.python.org/pypi/pep8) can do this, though > I have never used it myself. ?PyLint is a customisable static analysis > program that checks style among other things. > > Cheers, > > Kev I've used pep8.py myself for some Python 3.x projects, and it's pretty good. You don't need to install it either, a simple call via python pep8.py 'yourpythonfile.py' should do. I think PyLint can be used for Python 2.x, but I'm not sure about 3.x. From buzzard at urubu.freeserve.co.uk Sun Feb 7 15:45:59 2010 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sun, 07 Feb 2010 20:45:59 +0000 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> References: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 07 Feb 2010 03:02:05 +0000, duncan smith wrote: > >> The precise issue is that I'm supplying a default value of >> 2.2250738585072014e-308 for a parameter (finishing temperature for a >> simulated annealing algorithm) in an application. I develop on >> Ubuntu64, but (I am told) it's too small a value when run on a Win32 >> server. I assume it's being interpreted as zero and raising an >> exception. Thanks. > > I'm trying to think of what sort of experiment would be able to measure > temperatures accurate to less than 3e-308 Kelvin, and my brain boiled. > > Surely 1e-100 would be close enough to zero as to make no practical > difference? Or even 1e-30? Whatever you're simulating surely isn't going > to require 300+ decimal points of accuracy. > > I must admit I'm not really familiar with simulated annealing, so I could > be completely out of line, but my copy of "Numerical Recipes ..." by > Press et al has an example, and they take the temperature down to about > 1e-6 before halting. Even a trillion times lower that that is 1e-15. > > It depends on the optimisation problem, but I suppose the fitness functions could be tweaked. I could paste the actual code if anyone's interested, but the following pseudo-python gives the idea. For an exponential cooling schedule the temperatures are generated as below. The lower the final temperature the greater the number of iterations, and the longer the algorithm spends searching locally for an optimal solution (having already searched more widely for areas of high fitness at higher temperatures). The probability of moving to a less fit solution is given by exp(dF/temp) where dF is a (negative) change in fitness and temp is the current temperature. So I could scale the fitness function to cope with higher finishing temperatures. I'm going to have to think about the point raised by Steve (Holden). I also think I can probably improve on raising StopIteration if exp(dF/temp) overflows by yielding False instead (although if it does overflow it probably indicates a poor choice of cooling schedule for the given problem). Stuff to think about. Cheers. Duncan import random import math def temps(start, final, mult): t = start while t > final: yield t t *= mult def sim_anneal(permuter, start, final, mult): rand = random.random exp = math.exp for temp in temps(start, final, mult): dF = permuter.next() if dF >= 0: yield True else: try: yield rand() < exp(dF / temp) except OverflowError: raise StopIteration class Permuter(object): def __init__(self, obj): self.obj = obj self.proposed = None def run(self, start, final, mult): for decision in sim_anneal(self, start, final, mult): if decision: # commit proposed change to self.obj def next(): # propose a change to self.obj # calculate and return the change in fitness self.proposed = proposed return dF From dickinsm at gmail.com Sun Feb 7 16:06:59 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 7 Feb 2010 13:06:59 -0800 (PST) Subject: max / min / smallest float value on Python 2.5 References: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> Message-ID: <11668ca0-0f7f-41d0-9f6b-2e9f6b6a02ea@l26g2000yqd.googlegroups.com> On Feb 7, 8:45?pm, duncan smith wrote: [...] > interested, but the following pseudo-python gives the idea. ?For an [...] > ? ? ? ? ? ? ?try: > ? ? ? ? ? ? ? ? ?yield rand() < exp(dF / temp) Practically speaking, the condition rand() < exp(dF / temp) is never going to be satisfied if dF / temp < -40 (in fact, the output of rand() is always an exact multiple of 2**-53, so the condition rand() < exp(-40) is identical to the condition rand() == 0.0, which should occur for one random sample out of every 9 thousand million million or so). So assuming that your fitness delta dF can't get smaller than 1e-16 or so in absolute value (which seems reasonable, given that dF is presumably the result of subtracting two numbers of 'normal' magnitude), there would be little point having temp go much smaller than, say, 1e-20. IOW, I agree with Steven: 2.2e-308 seems extreme. -- Mark From nyamatongwe+thunder at gmail.com Sun Feb 7 16:08:45 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 07 Feb 2010 21:08:45 GMT Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: Aahz: > BTW, in case anyone is confused, it's "svn blame" vs "cvs annotate". Possibly earlier versions of SVN only supported "blame" but the variants "annotate", "ann", and "praise" all work with the version of SVN (1.6.5) I have installed. Neil From james.harris.1 at googlemail.com Sun Feb 7 16:25:21 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sun, 7 Feb 2010 13:25:21 -0800 (PST) Subject: Available for use: Tabs management software Message-ID: In case someone else finds it useful here is a program I wrote a year or so ago to help manage tab characters. It will convert tabs to runs of spaces, convert runs of spaces to tabs, or count or check for tab characters as required. It supports tab stops at regular and irregular positions. http://codewiki.wikispaces.com/tabs.py It is written in Python and you can either use it from the command line or call the functions from another Python script. Documentation is included on the web page. James From half.italian at gmail.com Sun Feb 7 16:43:02 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sun, 7 Feb 2010 13:43:02 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> On Feb 7, 11:02?am, T wrote: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. ?Specifically, the > program will call plink.exe to create a reverse SSH tunnel. ?Right now > I'm using subprocess.Popen to do so. ?When I run it interactively via > an admin account, all is well. ?However, when I'm running it via > service, no luck. ?I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. ?What > would be the best way around this? ?Thanks! Try running/debugging your service from the commandline as " debug" That should lead you to the error. Otherwise, we need to see a traceback and some code to be better able to help. ~Sean From misceverything at gmail.com Sun Feb 7 16:51:19 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 13:51:19 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> Message-ID: <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> On Feb 7, 4:43?pm, Sean DiZazzo wrote: > On Feb 7, 11:02?am, T wrote: > > > I have a script, which runs as a Windows service under the LocalSystem > > account, that I wish to have execute some commands. ?Specifically, the > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > an admin account, all is well. ?However, when I'm running it via > > service, no luck. ?I'm assuming this is to do with the fact that it's > > trying to run under the LocalSystem account, which is failing. ?What > > would be the best way around this? ?Thanks! > > Try running/debugging your service from the commandline as > " debug" ?That should lead you to the error. > > Otherwise, we need to see a traceback and some code to be better able > to help. > > ~Sean It's working fine when I run it via " debug" - that's how I was testing before. It's when I start the service that it fails - and you can see that, when you run it with debug, plink.exe runs under my username. When I run it as a service, it runs under System... From ahleniusm at gmail.com Sun Feb 7 16:51:36 2010 From: ahleniusm at gmail.com (m_ahlenius) Date: Sun, 7 Feb 2010 13:51:36 -0800 (PST) Subject: question on using tarfile to read a *.tar.gzip file Message-ID: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> Hi, I have a number of relatively large number *tar.gzip files to process. With the py module tarfile, I see that I can access and extract them, one at a time to a temporary dir, but that of course takes time. All that I need to do is to read the first and last lines of each file and then move on to the next one. I am not changing anything in these files - just reading. The file lines are not fixed lengths either, which makes it a bit more fun. Is there a way to do this, without decompressing each file to a temp dir? Like is there a method using some tarfile interface adapter to read a compressed file? Otherwise I'll just access each file, extract it, grab the 1st and last lines and then delete the temp file. thx 'mark From hzhuo1 at gmail.com Sun Feb 7 16:57:14 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sun, 7 Feb 2010 13:57:14 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> Message-ID: That is a method called brute force. According to my computation, 2^2048= 32317006071311007300714876688669951960444102669715484032130345427524655138867890 89319720141152291346368871796092189801949411955915049092109508815238644828312063 08773673009960917501977503896521067960576383840675682767922186426197561618380943 38476170470581645852036305042887575891541065808607552399123930385521914333389668 34242068497478656456949485617603532632205807780565933102619270846031415025859286 41771167259436037184618573575983511523016459044036976132332872312271256847108202 09725157101726931323469678542580656697935045997268352998638215525166389437335543 602135433229604645318478604952148193555853611059596230656L which is a very large number. There are some other algorithms for factoring integers, including Generalized number field sieve. And in quantum computing, there is an algorithm called Shor, which is claimed to be a polynomial algorithm if run under quantum computers. But seems that kind of computers haven't been successfully built, or else RSA and many other security mechanisms based on computation complexity cannot be used any longer. What I need in my application is just to list all expressions that match a particular regex, which I believe will be more efficient to deal with if there is a general function for this purpose. Unfortunately there is not such a function, so I will write my own function to deal with my particular regex, which can be enumerated. Sincerely, Zhuo On Feb 7, 10:38?am, Steve Holden wrote: > hzh... at gmail.com wrote: > >> And I really don't see how simple enumeration of range(2^2048) breaks > >> RSA-2048, since that problem requires you to find two factors which, > >> when multiplied together, give that specific value. > > > I can tell you why is that. RSA-2048 has a composite of length less > > than 2^2048, which is a product of two large primes. So one of its > > factors cannot exceed 2^2047, and we can treat the multiplication as a > > computation with constant complexity. So the time complexity of > > enumerating 2^2048 strings is the same with factoring a composite with > > length 2^2048 which is the product of two primes. > > > And obviously, whenever we successfully factor the composite, we can > > calculate the Euler function of it. So that given any public key > > (n,e), calculating the private key (n,d) is easy. > > So all I have to do to break RSA is to count to 2^2048? > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 ?http://us.pycon.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ From half.italian at gmail.com Sun Feb 7 17:02:37 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sun, 7 Feb 2010 14:02:37 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> Message-ID: > > It's working fine when I run it via " debug" - that's how > I was testing before. ?It's when I start the service that it fails - > and you can see that, when you run it with debug, plink.exe runs under > my username. ?When I run it as a service, it runs under System... You can have the service run as any user under the service properties. Perhaps set the service to run under your username? There may be some environment variables set in your session that aren't in the one its running as. So maybe check there as well. Off to drink beer. Good luck. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 7 17:07:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 22:07:15 GMT Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> Message-ID: <00f8becc$0$15628$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: >> "Given the function hashlib.sha256, enumerate all the possible inputs >> that give the hexadecimal result >> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." > > I tried some "parrot" variants but no dice. :-( Oh, everybody expects parrots! That's not unexpected -- as a clue, I wrote that "the message is predictable for being totally unexpected". The input was "Nobody expects the Spanish Inquisition!", which is another Monty Python catchphrase. -- Steven From alfps at start.no Sun Feb 7 17:14:39 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 23:14:39 +0100 Subject: Executing Commands From Windows Service In-Reply-To: <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> Message-ID: * T: > On Feb 7, 4:43 pm, Sean DiZazzo wrote: >> On Feb 7, 11:02 am, T wrote: >> >>> I have a script, which runs as a Windows service under the LocalSystem >>> account, that I wish to have execute some commands. Specifically, the >>> program will call plink.exe to create a reverse SSH tunnel. Right now >>> I'm using subprocess.Popen to do so. When I run it interactively via >>> an admin account, all is well. However, when I'm running it via >>> service, no luck. I'm assuming this is to do with the fact that it's >>> trying to run under the LocalSystem account, which is failing. What >>> would be the best way around this? Thanks! >> Try running/debugging your service from the commandline as >> " debug" That should lead you to the error. >> >> Otherwise, we need to see a traceback and some code to be better able >> to help. >> >> ~Sean > > It's working fine when I run it via " debug" - that's how > I was testing before. It's when I start the service that it fails - > and you can see that, when you run it with debug, plink.exe runs under > my username. When I run it as a service, it runs under System... This sounds like a Windows programming problem, not anything related to Python per se. Windows services are generally limited in what they can do, such as interaction with the user, and I guess that spills over to network access. Also, services need to interact with the service control manager, the "scum" as it's known. Well, all right, that's just what my coworkers and I called it once. But essentially, it's an even-driven execution model, which means that it might not work to use just any program, such as [python.exe], directly as a service. The Windows Resource Kit used to have a facility for running ordinary programs as services. I'm not sure what it did at the technical level, but it worked. Or it appeared to work. You might also find it useful to look up the documentation on services that interact with the user. In the old times that was mostly a matter of configuring which account the service ran under. But I think it all got more complicated with Microsoft's introduction of Terminal services (generally, most of the complication in modern Windows is due to the shift in focus about 1995, ditching the personal computer user market in favor of the enterprise and MIS market). Cross-posted to [comp.os.ms-windows.programmer.win32], follow-ups set to that group -- that means, unless overridden you won't see follow-ups in [c.l.p]. I think that group may give more informative and helpful responses. Cheers & hth., - Alf From clp2 at rebertia.com Sun Feb 7 17:52:38 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Feb 2010 14:52:38 -0800 Subject: passing string for editing in input() In-Reply-To: References: Message-ID: <50697b2c1002071452o685d5054sc94b747676033cee@mail.gmail.com> On Sun, Feb 7, 2010 at 8:24 AM, Aahz wrote: > In article , > Chris Rebert ? wrote: >>On Tue, Feb 2, 2010 at 5:24 AM, mk wrote: >>> >>> Is there an easy way to get an editing (readline) in Python that would >>> contain string for editing and would not just be empty? >>> >>> I googled but found nothing. >> >>Er...: http://docs.python.org/library/readline.html >>It's the third hit for "python readline". >> >>Actually reading the page, sounds like you want readline.insert_text() >>specifically. > > That seems a tad harsh, especially after reading the docs and following > Peter Otten's link. ?It's not at all obvious how to actually use > insert_text(), and although I probably could have figured it out on my > own, I might well have posted here myself. ?Did you try using > insert_text() before posting? No; I've never used the readline module for that matter. I was just giving a (hopefully helpful) suggestion based on a quick scan of the docs (hence the tentative "sounds like"). The OP's comment about finding /nothing/ on Google made it sound as though they hadn't located/checked the readline module docs. In retrospect, I might have misinterpreted in that regard; but in my defense, if they did check the docs, it might have been good to say so, and if they had found insert_text(), they ought to have made their question more specific. Cheers, Chris From python.list at tim.thechases.com Sun Feb 7 18:01:24 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 17:01:24 -0600 Subject: question on using tarfile to read a *.tar.gzip file In-Reply-To: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> References: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> Message-ID: <4B6F4644.60201@tim.thechases.com> > Is there a way to do this, without decompressing each file to a temp > dir? Like is there a method using some tarfile interface adapter to > read a compressed file? Otherwise I'll just access each file, extract > it, grab the 1st and last lines and then delete the temp file. I think you're looking for the extractfile() method of the TarFile object: from glob import glob from tarfile import TarFile for fname in glob('*.tgz'): print fname tf = TarFile.gzopen(fname) for ti in tf: print ' %s' % ti.name f = tf.extractfile(ti) if not f: continue fi = iter(f) # f doesn't natively support next() first_line = fi.next() for line in fi: pass f.close() print " First line: %r" % first_line print " Last line: %r" % line tf.close() If you just want the first & last lines, it's a little more complex if you don't want to scan the entire file (like I do with the for-loop), but the file-like object returned by extractfile() is documented as supporting seek() so you can skip to the end and then read backwards until you have sufficient lines. I wrote a "get the last line of a large file using seeks from the EOF" function which you can find at [1] which should handle the odd edge cases of $BUFFER_SIZE containing more or less than a full line and then reading backwards in chunks (if needed) until you have one full line, handling a one-line file, and other odd/annoying edge-cases. Hope it helps. -tkc [1] http://mail.python.org/pipermail/python-list/2009-January/1186176.html From james.harris.1 at googlemail.com Sun Feb 7 18:09:15 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sun, 7 Feb 2010 15:09:15 -0800 (PST) Subject: Available for use: Tabs management software References: Message-ID: <5e9b7d2a-a1dc-4a73-a3f6-4acc4dcb6fc5@b10g2000yqa.googlegroups.com> On 7 Feb, 21:25, James Harris wrote: > In case someone else finds it useful here is a program I wrote a year > or so ago to help manage tab characters. It will convert tabs to runs > of spaces, convert runs of spaces to tabs, or count or check for tab > characters as required. It supports tab stops at regular and irregular > positions. > > ?http://codewiki.wikispaces.com/tabs.py > > It is written in Python and you can either use it from the command > line or call the functions from another Python script. Documentation > is included on the web page. After posting this I realised the code had a dependence on a separate debugging module. I've commented-out all such references and tested it in isolation from other code. Everything behaved as it should so if you download it you should find it just works. The only dependence is on Python (i.e. Python 2.x; I gather 3.x needs print statements and maybe other stuff to be changed). Any issues, feel free to post them here. James From nobody at nowhere.com Sun Feb 7 18:55:52 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 23:55:52 +0000 Subject: TABS in the CPython C source code References: Message-ID: On Sun, 07 Feb 2010 05:49:28 +0000, Nobody wrote: >> The size-8 tabs look really bad in an editor configured with tab size 4, >> as is common in Windows. I'm concluding that the CPython programmers >> configure their Visual Studio's to *nix convention. > > 8-column tabs aren't a "*nix convention"; that's been the norm since > the mechanical typewriter. Okay, as everyone has pointed out, it's not quite that old. I've seen typewriters with fixed tabs, but I'm not certain that they were at 8 columns, and even if they were, it wasn't common enough to be a standard. From as at sci.fi Sun Feb 7 19:21:17 2010 From: as at sci.fi (Anssi Saari) Date: Mon, 08 Feb 2010 02:21:17 +0200 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: Julian writes: > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". Thanks for the hint, interesting stuff in there. > For those guys would be a poster quite cool which describes the most > popular and beloved python features. For me as an electronics HW guy, I really like that I can easily handle binary data without doing tedious and error prone shifting and anding and oring. From ahleniusm at gmail.com Sun Feb 7 19:25:50 2010 From: ahleniusm at gmail.com (m_ahlenius) Date: Sun, 7 Feb 2010 16:25:50 -0800 (PST) Subject: question on using tarfile to read a *.tar.gzip file References: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> Message-ID: <56cb4ae5-7a8d-4571-a9f2-57f3c7500664@v25g2000yqk.googlegroups.com> On Feb 7, 5:01?pm, Tim Chase wrote: > > Is there a way to do this, without decompressing each file to a temp > > dir? ?Like is there a method using some tarfile interface adapter to > > read a compressed file? ?Otherwise I'll just access each file, extract > > it, ?grab the 1st and last lines and then delete the temp file. > > I think you're looking for the extractfile() method of the > TarFile object: > > ? ?from glob import glob > ? ?from tarfile import TarFile > ? ?for fname in glob('*.tgz'): > ? ? ?print fname > ? ? ?tf = TarFile.gzopen(fname) > ? ? ?for ti in tf: > ? ? ? ?print ' %s' % ti.name > ? ? ? ?f = tf.extractfile(ti) > ? ? ? ?if not f: continue > ? ? ? ?fi = iter(f) # f doesn't natively support next() > ? ? ? ?first_line = fi.next() > ? ? ? ?for line in fi: pass > ? ? ? ?f.close() > ? ? ? ?print " ?First line: %r" % first_line > ? ? ? ?print " ?Last line: %r" % line > ? ? ?tf.close() > > If you just want the first & last lines, it's a little more > complex if you don't want to scan the entire file (like I do with > the for-loop), but the file-like object returned by extractfile() > is documented as supporting seek() so you can skip to the end and > then read backwards until you have sufficient lines. ?I wrote a > "get the last line of a large file using seeks from the EOF" > function which you can find at [1] which should handle the odd > edge cases of $BUFFER_SIZE containing more or less than a full > line and then reading backwards in chunks (if needed) until you > have one full line, handling a one-line file, and other > odd/annoying edge-cases. ?Hope it helps. > > -tkc > > [1]http://mail.python.org/pipermail/python-list/2009-January/1186176.html Thanks Tim - this was very helpful. Just learning about tarfile. 'mark From escalation746 at yahoo.com Sun Feb 7 19:26:25 2010 From: escalation746 at yahoo.com (escalation746) Date: Sun, 7 Feb 2010 16:26:25 -0800 (PST) Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 Message-ID: I am having a heck of a time doing the simplest thing: installing Python and the pywin extensions, including the PythonWin editor I have always relied on, into my new Windows 7 Professional 64-bit OS. I tried the Python package from python.org and pywin32 from sourceforge. But the latter would not install, saying that it could not find Python 2.6 in the registry. And apparently it will not let me specify the location of same, although a dialogue window tantalises me with blank text boxes I cannot type into. I then tried the 64-bit version of ActiveState's Python, but this installed sans the PythonWin editor, apparently. At least I cannot find it either in the Start menu or in the Python folder. What am I missing? What have I not been told? -- robin From apt.shansen at gmail.com Sun Feb 7 19:55:05 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 7 Feb 2010 16:55:05 -0800 Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 In-Reply-To: References: Message-ID: <7a9c25c21002071655h4a4076e7tb9f94e92a78a3273@mail.gmail.com> On Sun, Feb 7, 2010 at 4:26 PM, escalation746 wrote: > I am having a heck of a time doing the simplest thing: installing > Python and the pywin extensions, including the PythonWin editor I have > always relied on, into my new Windows 7 Professional 64-bit OS. I > tried the Python package from python.org and pywin32 from sourceforge. > But the latter would not install, saying that it could not find Python > 2.6 in the registry. And apparently it will not let me specify the > location of same, although a dialogue window tantalises me with blank > text boxes I cannot type into. > Saying, "the Python package from python.org" is insufficiently specific; are you sure you got the 64-bit version of BOTH packages? If you install 64-bit Python, any extensions must also be 64-bit. If you look at http://sourceforge.net/projects/pywin32/files/ you'll notice separate builds for 64-bit, marked amd64. Are you sure you got the pywin32-214.win-amd64-py2.6.exe and not the normal one? Alternatively, you can just get the 32-bit version of both and install them. But you can't mix and match, 32-bit one, 64-bit the other, in that case they won't find each-other. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Sun Feb 7 19:57:01 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sun, 7 Feb 2010 16:57:01 -0800 (PST) Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 References: Message-ID: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> On Feb 8, 1:26?am, escalation746 wrote: > I am having a heck of a time doing the simplest thing: installing > Python and the pywin extensions, including the PythonWin editor I have > always relied on, into my new Windows 7 Professional 64-bit OS. I > tried the Python package from python.org and pywin32 from sourceforge. > But the latter would not install, saying that it could not find Python > 2.6 in the registry. And apparently it will not let me specify the > location of same, although a dialogue window tantalises me with blank > text boxes I cannot type into. > > I then tried the 64-bit version of ActiveState's Python, but this > installed sans the PythonWin editor, apparently. At least I cannot > find it either in the Start menu or in the Python folder. > > What am I missing? What have I not been told? > > -- robin Perhaps you've accidentally downloaded the wrong version of PythonWin? I think this should be the one: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win-amd64-py2.6.exe/download From misceverything at gmail.com Sun Feb 7 19:57:36 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 16:57:36 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> Message-ID: <811dd4e9-6eea-4c1f-a24b-ba0179e57f84@a13g2000vbf.googlegroups.com> Thanks for the suggestions - I think my next step is to try running it under an admin user account, as you guys both mentioned. Alf - you're absolutely right, Microsoft has srvany.exe, which allows you to run any EXE as a Windows service. I've done this in the past, but it's more of a "hack"..so this go around (since I will be distributing this program), I wanted to go the more professional route..which, unfortunately, involves learning the "scum". :) I posted this to comp.os.ms-windows.programmer.win32, so we'll see if what the Win32 programmers have to say as well. Thanks again! From escalation746 at yahoo.com Sun Feb 7 20:02:33 2010 From: escalation746 at yahoo.com (escalation746) Date: Sun, 7 Feb 2010 17:02:33 -0800 (PST) Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 References: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> Message-ID: <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> Andrej Mitrovic wrote: > Perhaps you've accidentally downloaded the wrong version of PythonWin? Erk, yes, my bad. Thanks for the quick help! Though I still wonder why the ActiveState build does not include this. -- robin From misceverything at gmail.com Sun Feb 7 20:05:39 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 17:05:39 -0800 (PST) Subject: Modifying Class Object Message-ID: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Ok, just looking for a sanity check here, or maybe something I'm missing. I have a class Test, for example: class Test: def __init__(self, param1, param2, param3): self.param1 = param1 self.param2 = param2 self.param3 = param3 Next, I have a dictionary mytest that contains instances of Test. If I want to modify one of the Test instances within my dictionary, I have to rewrite the entire entry, correct (since Python passes by value, not reference)? I.e. if I wish to change just param3 of an instance, I would have to do: def changevalue(): for key in mytest.keys(): currentparam = mytest[key] param1 = currentparam.param1 param2 = currentparam.param2 param3 = currentparam.param3 param3 = "newvalue" mytest[key] = Test(param1, param2, param3) If there's an easier way to accomplish this that I'm missing, that'd be great! From clp2 at rebertia.com Sun Feb 7 20:16:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Feb 2010 17:16:19 -0800 Subject: Modifying Class Object In-Reply-To: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <50697b2c1002071716k26062ba9h640835149f34c6e9@mail.gmail.com> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: > Ok, just looking for a sanity check here, or maybe something I'm > missing. ?I have a class Test, for example: > > class Test: > ? ?def __init__(self, param1, param2, param3): > ? ? ? ?self.param1 = param1 > ? ? ? ?self.param2 = param2 > ? ? ? ?self.param3 = param3 > > Next, I have a dictionary mytest that contains instances of Test. ?If > I want to modify one of the Test instances within my dictionary, I > have to rewrite the entire entry, correct (since Python passes by > value, not reference)? Incorrect; Python uses neither. See http://effbot.org/zone/call-by-object.htm for a excellent explanation of what Python does use. > I.e. if I wish to change just param3 of an > instance, I would have to do: > > def changevalue(): > ? ?for key in mytest.keys(): > ? ? ? ?currentparam = mytest[key] > ? ? ? ?param1 = currentparam.param1 > ? ? ? ?param2 = currentparam.param2 > ? ? ? ?param3 = currentparam.param3 > ? ? ? ?param3 = "newvalue" > ? ? ? ?mytest[key] = Test(param1, param2, param3) > > If there's an easier way to accomplish this that I'm missing, that'd > be great! def changevalue(): for test in mytest.values(): test.param3 = "newvalue" Cheers, Chris -- http://blog.rebertia.com From steve at holdenweb.com Sun Feb 7 20:19:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 20:19:53 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <00f8becc$0$15628$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <00f8becc$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B6F66B9.2060801@holdenweb.com> Steven D'Aprano wrote: > On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: > >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( > > Oh, everybody expects parrots! That's not unexpected -- as a clue, I > wrote that "the message is predictable for being totally unexpected". > > The input was "Nobody expects the Spanish Inquisition!", which is another > Monty Python catchphrase. > > Bugger - Got everything except the trailing exclamation mark ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 20:19:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 20:19:53 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <00f8becc$0$15628$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <00f8becc$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B6F66B9.2060801@holdenweb.com> Steven D'Aprano wrote: > On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: > >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( > > Oh, everybody expects parrots! That's not unexpected -- as a clue, I > wrote that "the message is predictable for being totally unexpected". > > The input was "Nobody expects the Spanish Inquisition!", which is another > Monty Python catchphrase. > > Bugger - Got everything except the trailing exclamation mark ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From misceverything at gmail.com Sun Feb 7 20:24:13 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 17:24:13 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Feb 7, 8:16?pm, Chris Rebert wrote: > On Sun, Feb 7, 2010 at 5:05 PM, T wrote: > > Ok, just looking for a sanity check here, or maybe something I'm > > missing. ?I have a class Test, for example: > > > class Test: > > ? ?def __init__(self, param1, param2, param3): > > ? ? ? ?self.param1 = param1 > > ? ? ? ?self.param2 = param2 > > ? ? ? ?self.param3 = param3 > > > Next, I have a dictionary mytest that contains instances of Test. ?If > > I want to modify one of the Test instances within my dictionary, I > > have to rewrite the entire entry, correct (since Python passes by > > value, not reference)? > > Incorrect; Python uses neither. Seehttp://effbot.org/zone/call-by-object.htmfor a excellent explanation > of what Python does use. > > > I.e. if I wish to change just param3 of an > > instance, I would have to do: > > > def changevalue(): > > ? ?for key in mytest.keys(): > > ? ? ? ?currentparam = mytest[key] > > ? ? ? ?param1 = currentparam.param1 > > ? ? ? ?param2 = currentparam.param2 > > ? ? ? ?param3 = currentparam.param3 > > ? ? ? ?param3 = "newvalue" > > ? ? ? ?mytest[key] = Test(param1, param2, param3) > > > If there's an easier way to accomplish this that I'm missing, that'd > > be great! > > def changevalue(): > ? ? for test in mytest.values(): > ? ? ? ? test.param3 = "newvalue" > > Cheers, > Chris > --http://blog.rebertia.com Thanks so much - this makes life a lot easier! And a great reference as well. Cheers, Doug From steve at holdenweb.com Sun Feb 7 20:31:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 20:31:31 -0500 Subject: Modifying Class Object In-Reply-To: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: T wrote: > Ok, just looking for a sanity check here, or maybe something I'm > missing. I have a class Test, for example: > > class Test: > def __init__(self, param1, param2, param3): > self.param1 = param1 > self.param2 = param2 > self.param3 = param3 > > Next, I have a dictionary mytest that contains instances of Test. If > I want to modify one of the Test instances within my dictionary, I > have to rewrite the entire entry, correct (since Python passes by > value, not reference)? I.e. if I wish to change just param3 of an > instance, I would have to do: > > def changevalue(): > for key in mytest.keys(): > currentparam = mytest[key] > param1 = currentparam.param1 > param2 = currentparam.param2 > param3 = currentparam.param3 > param3 = "newvalue" > mytest[key] = Test(param1, param2, param3) > > If there's an easier way to accomplish this that I'm missing, that'd > be great! def changevalue(): for key in mytest.keys(): mytest[key].param3 = "newvalue" regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Sun Feb 7 20:32:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Feb 2010 02:32:31 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B6F69AF.8050200@sequans.com> Steve Holden wrote: > Shashwat Anand wrote: > >> LOL >> pow(funny, sys.maxint) >> >> > Yes, funny, but it overlooks the point that Xah is a nuisance to > multiple communities, not just to ours, and quite often concurrently. > > I'm all in favor of tolerance, but I'd like to see some evidence that > rehabilitation is practical before the community has to tolerate too > much of that kind of nonsense. > > regards > Steve > Actually for one Xah post I get, I then get 20 mails complaining about him. The fact is, for someone like me who subscribed only to the python list (what's the purpose of subscribing the perl list when you know about python existence btw :o) ), the real annoying spam comes from the complains, not Xah. Speaking for myself, I may get 3 or 4 posts from Xah a month at most. Something I can live with. So guys, just ignore him if you don't like him. Mailers & news readers have plenty of feature to make it happen. Adding my contribution to complains... JM From python at mrabarnett.plus.com Sun Feb 7 20:48:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 01:48:21 +0000 Subject: python admin abuse complaint In-Reply-To: <4B6F69AF.8050200@sequans.com> References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> <4B6F69AF.8050200@sequans.com> Message-ID: <4B6F6D65.7030408@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > Steve Holden wrote: >> Shashwat Anand wrote: >> >>> LOL >>> pow(funny, sys.maxint) >>> >>> >> Yes, funny, but it overlooks the point that Xah is a nuisance to >> multiple communities, not just to ours, and quite often concurrently. >> >> I'm all in favor of tolerance, but I'd like to see some evidence that >> rehabilitation is practical before the community has to tolerate too >> much of that kind of nonsense. >> >> regards >> Steve >> > Actually for one Xah post I get, I then get 20 mails complaining about > him. The fact is, for someone like me who subscribed only to the python > list (what's the purpose of subscribing the perl list when you know > about python existence btw :o) ), the real annoying spam comes from the > complains, not Xah. Speaking for myself, I may get 3 or 4 posts from Xah > a month at most. Something I can live with. > > So guys, just ignore him if you don't like him. Mailers & news readers > have plenty of feature to make it happen. > > Adding my contribution to complains... > Alternatively, add [XAH] to the subject in the replies so that they can be filtered out easily. :-) From alfps at start.no Sun Feb 7 20:51:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 02:51:05 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Chris Rebert: > On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >> Ok, just looking for a sanity check here, or maybe something I'm >> missing. I have a class Test, for example: >> >> class Test: >> def __init__(self, param1, param2, param3): >> self.param1 = param1 >> self.param2 = param2 >> self.param3 = param3 >> >> Next, I have a dictionary mytest that contains instances of Test. If >> I want to modify one of the Test instances within my dictionary, I >> have to rewrite the entire entry, correct (since Python passes by >> value, not reference)? > > Incorrect; Python uses neither. See > http://effbot.org/zone/call-by-object.htm for a excellent explanation > of what Python does use. Hm. While most everything I've seen at effbot.org has been clear and to the point, that particular article reads like a ton of obfuscation. Python passes pointers by value, just as e.g. Java does. There, it needed just 10 words or so. :-) Or perhaps some more words to point out that in the Java language spec those reference values are called pointers, but that this terminology isn't (apparently) used for Python, and isn't even well known among Java programmers. But that's just one extra little para. One just has to be clear about exactly what it is that's passed by value. Not Python objects, but references (pointers) to them, the id(o) values. >> I.e. if I wish to change just param3 of an >> instance, I would have to do: >> >> def changevalue(): >> for key in mytest.keys(): >> currentparam = mytest[key] >> param1 = currentparam.param1 >> param2 = currentparam.param2 >> param3 = currentparam.param3 >> param3 = "newvalue" >> mytest[key] = Test(param1, param2, param3) >> >> If there's an easier way to accomplish this that I'm missing, that'd >> be great! > > def changevalue(): > for test in mytest.values(): > test.param3 = "newvalue" Cheers, - Alf From python at mrabarnett.plus.com Sun Feb 7 21:07:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 02:07:55 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <4B6F71FB.6060709@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Chris Rebert: >> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>> Ok, just looking for a sanity check here, or maybe something I'm >>> missing. I have a class Test, for example: >>> >>> class Test: >>> def __init__(self, param1, param2, param3): >>> self.param1 = param1 >>> self.param2 = param2 >>> self.param3 = param3 >>> >>> Next, I have a dictionary mytest that contains instances of Test. If >>> I want to modify one of the Test instances within my dictionary, I >>> have to rewrite the entire entry, correct (since Python passes by >>> value, not reference)? >> >> Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> of what Python does use. > > Hm. While most everything I've seen at effbot.org has been clear and to > the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) Or perhaps some more words to > point out that in the Java language spec those reference values are > called pointers, but that this terminology isn't (apparently) used for > Python, and isn't even well known among Java programmers. But that's > just one extra little para. > > One just has to be clear about exactly what it is that's passed by value. > > Not Python objects, but references (pointers) to them, the id(o) values. > A reference is not the same as a pointer. A pointer tells you where something is; a reference doesn't. From alfps at start.no Sun Feb 7 21:21:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 03:21:11 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * MRAB: > Alf P. Steinbach wrote: >> * Chris Rebert: >>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>> Ok, just looking for a sanity check here, or maybe something I'm >>>> missing. I have a class Test, for example: >>>> >>>> class Test: >>>> def __init__(self, param1, param2, param3): >>>> self.param1 = param1 >>>> self.param2 = param2 >>>> self.param3 = param3 >>>> >>>> Next, I have a dictionary mytest that contains instances of Test. If >>>> I want to modify one of the Test instances within my dictionary, I >>>> have to rewrite the entire entry, correct (since Python passes by >>>> value, not reference)? >>> >>> Incorrect; Python uses neither. See >>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>> of what Python does use. >> >> Hm. While most everything I've seen at effbot.org has been clear and >> to the point, that particular article reads like a ton of obfuscation. >> >> Python passes pointers by value, just as e.g. Java does. >> >> There, it needed just 10 words or so. :-) Or perhaps some more words >> to point out that in the Java language spec those reference values are >> called pointers, but that this terminology isn't (apparently) used for >> Python, and isn't even well known among Java programmers. But that's >> just one extra little para. >> >> One just has to be clear about exactly what it is that's passed by value. >> >> Not Python objects, but references (pointers) to them, the id(o) values. >> > A reference is not the same as a pointer. Depends on your choice terminology. I referred to the Java (language spec) terminology to make it clear. > A pointer tells you where something is; a reference doesn't. Sorry, I don't know of any relevant terminology where that is the case. Cheers & hth., - Alf From steven at REMOVE.THIS.cybersource.com.au Sun Feb 7 21:33:12 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 02:33:12 GMT Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <00f8becc$0$15628$c3e8da3@news.astraweb.com> Message-ID: On Sun, 07 Feb 2010 20:19:53 -0500, Steve Holden wrote: > Steven D'Aprano wrote: >> On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: >> >>>> "Given the function hashlib.sha256, enumerate all the possible inputs >>>> that give the hexadecimal result >>>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >>> I tried some "parrot" variants but no dice. :-( >> >> Oh, everybody expects parrots! That's not unexpected -- as a clue, I >> wrote that "the message is predictable for being totally unexpected". >> >> The input was "Nobody expects the Spanish Inquisition!", which is >> another Monty Python catchphrase. >> >> > Bugger - Got everything except the trailing exclamation mark ... NOBODY EXPECTS THE TRAILING EXCLAMATION MARK!!! -- Steven From schifschaf at gmail.com Sun Feb 7 22:00:40 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sun, 7 Feb 2010 19:00:40 -0800 (PST) Subject: Help with regex search-and-replace (Perl to Python) References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> <4B6EC203.4040807@holdenweb.com> Message-ID: <06a91472-3974-45d3-b86a-c3c9055a5831@z26g2000yqm.googlegroups.com> On Feb 7, 8:57?am, Tim Chase wrote: > Steve Holden wrote: > > > Really? Under what circumstances does a simple one-for-one character > > replacement operation fail? > > Failure is only defined in the clarified context of what the OP > wants :) ?Replacement operations only fail if the OP's desired > output from the above mess doesn't change *all* of the ]/[ > characters, but only those with some form of parity (nested or > otherwise). ?But if the OP *does* want all of the ]/[ characters > replaced regardless of contextual nature, then yes, replace is a > much better solution than regexps. > I need to do the usual "pipe text through and do various search/ replace" thing fairly often. The above case of having to replace brackets with braces is only one example. Simple string methods run out of steam pretty quickly and much of my work relies on using regular expressions. Yes, I try to keep focused on simplicity, and often regexes are the simplest solution for my day-to-day needs. From steve at holdenweb.com Sun Feb 7 22:03:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 22:03:06 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * MRAB: >> Alf P. Steinbach wrote: >>> * Chris Rebert: >>>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>>> Ok, just looking for a sanity check here, or maybe something I'm >>>>> missing. I have a class Test, for example: >>>>> >>>>> class Test: >>>>> def __init__(self, param1, param2, param3): >>>>> self.param1 = param1 >>>>> self.param2 = param2 >>>>> self.param3 = param3 >>>>> >>>>> Next, I have a dictionary mytest that contains instances of Test. If >>>>> I want to modify one of the Test instances within my dictionary, I >>>>> have to rewrite the entire entry, correct (since Python passes by >>>>> value, not reference)? >>>> >>>> Incorrect; Python uses neither. See >>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>>> of what Python does use. >>> >>> Hm. While most everything I've seen at effbot.org has been clear and >>> to the point, that particular article reads like a ton of obfuscation. >>> >>> Python passes pointers by value, just as e.g. Java does. >>> >>> There, it needed just 10 words or so. :-) Or perhaps some more words >>> to point out that in the Java language spec those reference values >>> are called pointers, but that this terminology isn't (apparently) >>> used for Python, and isn't even well known among Java programmers. >>> But that's just one extra little para. >>> >>> One just has to be clear about exactly what it is that's passed by >>> value. >>> >>> Not Python objects, but references (pointers) to them, the id(o) values. >>> >> A reference is not the same as a pointer. > > Depends on your choice terminology. I referred to the Java (language > spec) terminology to make it clear. > > >> A pointer tells you where something is; a reference doesn't. > > Sorry, I don't know of any relevant terminology where that is the case. > Alf: This topic was discussed at great, nay interminable, length about a year ago. I'd appreciate it if you would search the archives and read what was said then rather than hashing the whole topic over again to nobody's real advantage. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Sun Feb 7 22:10:06 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 7 Feb 2010 19:10:06 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <7a9c25c21002071910p462a2ddckc5d54de48cbeb97f@mail.gmail.com> On Sun, Feb 7, 2010 at 5:51 PM, Alf P. Steinbach wrote: > Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> >> of what Python does use. >> > > Hm. While most everything I've seen at effbot.org has been clear and to > the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) Or perhaps some more words to > point out that in the Java language spec those reference values are called > pointers, but that this terminology isn't (apparently) used for Python, and > isn't even well known among Java programmers. But that's just one extra > little para. > One just has to be clear about exactly what it is that's passed by value. > > Not Python objects, but references (pointers) to them, the id(o) values. > Sigh. Why does this always come up? And then someone makes a statement like this, and now a /very/ long thread in which everyone argues semantics will begin and sooner or later, the presence of the GIL will cause a Python civil war, even though the GIL has nothing to do with anything related to this conversation. Mark my words! Python only passes by value if you use a non-standard definition of "value": and the moment you do that, a whole bunch of people will start making weird assumptions of Python's object and scoping semantics and all kinds of confusion will occur. Or holy wars on words shall come to pass. Python does not have pointers, it is not passing a pointer, it is passing an object. The moment you start talking about passing pointers, people start expecting things to work as if they -were- pointers. Python objects don't. Python has names, and objects. It passes objects. Those objects get a new name as a result. If the object is mutable, changes will be seen by the caller. If the object is not, changes won't (because you're re-binding a name, not changing an object). Any attempt to apply any other sort of words or labels besides "names" and "objects" to the situation is just going to confuse people and make them think Python-is-LanguageXor Python-works-like-LanguageY. Let the argument begin! Again. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptmcg at austin.rr.com Sun Feb 7 22:11:10 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sun, 7 Feb 2010 19:11:10 -0800 (PST) Subject: How to print all expressions that match a regular expression References: Message-ID: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> On Feb 6, 1:36?pm, "hzh... at gmail.com" wrote: > Hi, > > I am a fresh man with python. I know there is regular expressions in > Python. What I need is that given a particular regular expression, > output all the matches. For example, given ?[1|2|3]{2}? as the regular > expression, the program should output all 9 matches, i.e., "11 12 13 > 21 22 23 31 32 33". > > Is there any well-written routine in Python or third-party program to > do this? If there isn't, could somebody make some suggestions on how > to write it myself? > > Thanks. > > Zhuo Please check out this example on the pyparsing wiki, invRegex.py: http://pyparsing.wikispaces.com/file/view/invRegex.py. This code implements a generator that returns successive matching strings for the given regex. Running it, I see that you actually have a typo in your example. >>> print list(invert("[1|2|3]{2}")) ['11', '1|', '12', '13', '|1', '||', '|2', '|3', '21', '2|', '22', '23', '31', '3|', '32', '33'] I think you meant either "[123]{2}" or "(1|2|3){2}". >>> print list(invert("[123]{2}")) ['11', '12', '13', '21', '22', '23', '31', '32', '33'] >>> print list(invert("(1|2|3){2}")) ['11', '12', '13', '21', '22', '23', '31', '32', '33'] Of course, as other posters have pointed out, this inverter does not accept regexen with unbounded multiple characters '+' or '*', but '?' and "{min,max}" notation will work. Even '.' is supported, although this can generate a large number of return values. Of course, you'll also have to install pyparsing to get this to work. -- Paul From steven at REMOVE.THIS.cybersource.com.au Sun Feb 7 22:14:22 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 03:14:22 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Sun, 07 Feb 2010 22:03:06 -0500, Steve Holden wrote: > Alf: > > This topic was discussed at great, nay interminable, length about a year > ago. I'd appreciate it if you would search the archives and read what > was said then rather than hashing the whole topic over again to nobody's > real advantage. Curse you Steve, I had just come up with a brilliant rebuttal of Alf's position. It was sheer genius, the sort of thing that would have James Gosling weeping with envy. Oh well, into the bitbucket it goes... -- Steven From wuwei23 at gmail.com Sun Feb 7 22:18:33 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 7 Feb 2010 19:18:33 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: "Alf P. Steinbach" wrote: > Hm. While most everything I've seen at effbot.org has been clear and to the > point, that particular article reads like a ton of obfuscation. Must. Resist. Ad hominem. > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) 10 words _plus_ an understanding of Java. Do you really think its appropriate to discuss Python's behaviour purely in terms of other languages? Further, you've managed to define Python's behaviour as being somehow _both_ of the major evaluation strategies - calling a reference by value - so you're asking people to understand two totally irrelevant models just to avoid describing one in its own terms. Rather than arguing about whether you have a 'value' or a 'reference', it's a lot easier to explain that you're passing mutable & immutable objects around. The behaviour is thus defined in terms of the object and _not_ in the calling model, and is far more consistent with object references throughout the language. It also doesn't require reference to other languages simply to define Python's model in terms of what it isn't. From alfps at start.no Sun Feb 7 22:27:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 04:27:07 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * MRAB: >>> Alf P. Steinbach wrote: >>>> * Chris Rebert: >>>>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>>>> Ok, just looking for a sanity check here, or maybe something I'm >>>>>> missing. I have a class Test, for example: >>>>>> >>>>>> class Test: >>>>>> def __init__(self, param1, param2, param3): >>>>>> self.param1 = param1 >>>>>> self.param2 = param2 >>>>>> self.param3 = param3 >>>>>> >>>>>> Next, I have a dictionary mytest that contains instances of Test. If >>>>>> I want to modify one of the Test instances within my dictionary, I >>>>>> have to rewrite the entire entry, correct (since Python passes by >>>>>> value, not reference)? >>>>> Incorrect; Python uses neither. See >>>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>>>> of what Python does use. >>>> Hm. While most everything I've seen at effbot.org has been clear and >>>> to the point, that particular article reads like a ton of obfuscation. >>>> >>>> Python passes pointers by value, just as e.g. Java does. >>>> >>>> There, it needed just 10 words or so. :-) Or perhaps some more words >>>> to point out that in the Java language spec those reference values >>>> are called pointers, but that this terminology isn't (apparently) >>>> used for Python, and isn't even well known among Java programmers. >>>> But that's just one extra little para. >>>> >>>> One just has to be clear about exactly what it is that's passed by >>>> value. >>>> >>>> Not Python objects, but references (pointers) to them, the id(o) values. >>>> >>> A reference is not the same as a pointer. >> Depends on your choice terminology. I referred to the Java (language >> spec) terminology to make it clear. >> >> >>> A pointer tells you where something is; a reference doesn't. >> Sorry, I don't know of any relevant terminology where that is the case. >> > Alf: > > This topic was discussed at great, nay interminable, length about a year > ago. I'd appreciate it if you would search the archives and read what > was said then rather than hashing the whole topic over again to nobody's > real advantage. Well that's my point, and thanks for backing me up on that :-): it's very simple, and as demonstrated can be expressed in 10 words or less (plus perhaps a terminology reference, as I did above), so all that discussion and in particular the lengthy article at effbot serves as obfuscation and nothing else. By the way, most every programming language has some corner like that, something that is utterly simple but somehow has some kind of obfuscation-meme attached. In C++ it's "call" and "constructor". It doesn't help that the language's standard lays down the law on it, it doesn't help that the language's creator has laid down the law, it doesn't help that it's utterly and completely simple. Somehow newbies and even some experienced people manage to create their own terminological nightmare and drawing conclusions about reality from that misguided obfuscated view, and then discussing it up and down and sideways. Cheers & hth., - Alf From austin.brkich at gmail.com Sun Feb 7 22:56:39 2010 From: austin.brkich at gmail.com (7H3LaughingMan) Date: Sun, 7 Feb 2010 19:56:39 -0800 (PST) Subject: C/C++ Import Message-ID: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> To make the background information short, I am trying to take a program that uses Python for scripting and recompile it for Linux since it originally was built to run on Win32. The program itself was designed to be able to be compiled on Linux and someone made there on release with source that added python scripting. After some issues I got it to compile but now it is unable to import the files that it needs. The program is running the following code... PyImport_Import( PyString_FromString("python.PlayerManager") ); This is meant to import the file PlayerManager.py inside of the python folder. However it throws the following Python Error (Gotten through PyErr_Print()) ImportError: No module named python.PlayerManager I am using 2.6.4 so I can't call it by the filename, does anyone know how to do a proper import? From steven at REMOVE.THIS.cybersource.com.au Sun Feb 7 23:01:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 04:01:05 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Mon, 08 Feb 2010 02:51:05 +0100, Alf P. Steinbach wrote: > Python passes pointers by value, just as e.g. Java does. How do I get a pointer in pure Python code (no ctypes)? I tried both Pascal and C syntax (^x and *x), but both give syntax errors. For that matter, how do I get a pointer in Java code? If Python doesn't have pointers, then why are you talking about Python passing pointers? It's a vacuous truth, like saying that Python passes dinosaurs by name. -- Steven From misceverything at gmail.com Sun Feb 7 23:15:52 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 20:15:52 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> Oops, this one was my fault - the object I was having the issues with was actually a shelve file, not a dictionary..so just re-assigning the variable isn't working, but re-writing the object to the shelve file does. So in this case, is there any way to just change a single value, or am I stuck rewriting the entry? From cjstevens at gmail.com Mon Feb 8 00:08:33 2010 From: cjstevens at gmail.com (Chris Stevens) Date: Mon, 8 Feb 2010 16:08:33 +1100 Subject: Python 2.4 and list of dictionary issues Message-ID: Hi all, I'm a python newbie so please excuse me if I am missing something simple here. I am writing a script which requires a list of dictionaries (originally a dictionary of dictionaries, but I changed it to a list to try and overcome the below problem). Now my understanding is that you create the empty list, then append or add entries to it. Correct? Here is some code: userInfo = [] ... userInfo.append( { 'username' : uidString[0], ... 'failedattempts' : int(0) }) I'm not to sure on the bracketing here, but I have tried many combinations. The issue here is that I get a "IndexError: list index out of range" message on the line "userInfo.append( {" I wrote this script on a box with Python 2.6 and it worked fine. Moving it to a box with 2.4, and I get this error. I can't understand why i'm getting a list index out of range error when trying to append (not reference) a list?? I have also tried "+=", and userInfo(len(userInfo))= .... just get the same error. Could anyone shed some light on this? Thanks, Chris From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 00:12:14 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 05:12:14 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Mon, 08 Feb 2010 03:21:11 +0100, Alf P. Steinbach wrote: >> A pointer tells you where something is; a reference doesn't. > > Sorry, I don't know of any relevant terminology where that is the case. Taken from Wikipedia: "A pointer is a simple, less abstracted implementation of the more abstracted reference data type (although it is not as directly usable as a C++ reference)." http://en.wikipedia.org/wiki/Pointer_(computing) In other words, a pointer is a specific type of reference. A reference in turn is an opaque but low-level data type which "refers to" in some way to the data you actually care about. (C++ has a concrete reference type, which is not to be confused with abstract references.) http://en.wikipedia.org/wiki/Reference_(computer_science) Unless otherwise stated, references are opaque and coders need not care how the reference mechanism is implemented, see e.g.: http://www.cocoabuilder.com/archive/cocoa/20777-opaque-reference.html In Python you don't use references directly, there is no reference type or object. You can simulate the semantics of references (but not pointers) by putting your object in a list and passing the list around. -- Steven From alfps at start.no Mon Feb 8 00:12:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 06:12:50 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steven D'Aprano: > On Mon, 08 Feb 2010 02:51:05 +0100, Alf P. Steinbach wrote: > >> Python passes pointers by value, just as e.g. Java does. > > How do I get a pointer in pure Python code (no ctypes)? I tried both > Pascal and C syntax (^x and *x), but both give syntax errors. Well, I don't believe that you tried that. :-) From one point of view it's extremely easy: just create some object, even just type 42 as an integer literal, and you can apply all of Python's pointer operations to the result -- which isn't much, basically just checking for pointer equality via 'is' or applying 'id' to get a value that represents the pointer uniquely, or copying the pointer via assignment or parameter passing. Whether you can obtain the bits of the internal pointer value, represented as e.g. an int, formally depends on the Python implementation. In CPython the 'id' function provides the internal pointer value as an int. I.e., with CPython you can do def foo( o ): print( id( o ) ) # Shows the pointer value in decimal. whatever = 42 print( id( whatever ) ) # Shows the pointer value in decimal. foo( whatever ) # Shows the exact *same* pointer value. which at a slightly higher level of abstraction works just as well with any conceivable Python implementation, although you have no formal guarantee that the conceptual "pointer" values are actually the internally memory addresses. But, in CPython they are, and you run into them all the time, for example (where the "at" tells you that it's a memory location specification, a pointer), >>> import turtle >>> turtle.forward >>> >>> id( turtle.forward ) 14384416 >>> hex( id( turtle.forward ) ) '0xdb7d20' >>> _ > For that matter, how do I get a pointer in Java code? As with Python, from one point of view it's extremely easy, just 'new' some object, and then you can apply all of Java's pure pointer operations to the result -- which isn't much, basically just checking for pointer equality and copying a pointer via assignment or parameter passing. In Java it's a pointer by definition, namely the language spec's definition. From another point of view, getting at the internal representation of the pointer is a bit harder in Java than in Python, at least as far as I know. It may not be practically possible. Disclaimer: I'm not a Java expert, and haven't used Java for years, and it just might be possible by using JNI (Java Native Interface), but that requires you to write a dynamic library in e.g. C or C++, and as I recall Java just creates a kind of fixed reference for the duration of a JNI call so the JNI side of things may not tell you anything about the Java side of things before or after the call. But if it helps, just to learn about pointers in various languages you -- or rather, some other reader, because I suspect that you know this already! :-) -- might look at . It contains a simple pointers example expressed in four different languages, namely C, C++, Pascal and Java, in particular comparing C and Java. > If Python doesn't have pointers, then why are you talking about Python > passing pointers? It's a vacuous truth, like saying that Python passes > dinosaurs by name. See above. Cheers & hth., - Alf From hzhuo1 at gmail.com Mon Feb 8 00:17:59 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sun, 7 Feb 2010 21:17:59 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> Message-ID: <76609ff4-6579-4b2b-80b7-fb88bd5f1fa7@a32g2000yqm.googlegroups.com> > > Please check out this example on the pyparsing wiki, invRegex.py:http://pyparsing.wikispaces.com/file/view/invRegex.py. ?This code > implements a generator that returns successive matching strings for > the given regex. ?Running it, I see that you actually have a typo in > your example. > > >>> print list(invert("[1|2|3]{2}")) > > ['11', '1|', '12', '13', '|1', '||', '|2', '|3', '21', '2|', '22', > '23', '31', '3|', '32', '33'] > > I think you meant either "[123]{2}" or "(1|2|3){2}". > > >>> print list(invert("[123]{2}")) > > ['11', '12', '13', '21', '22', '23', '31', '32', '33'] > > >>> print list(invert("(1|2|3){2}")) > > ['11', '12', '13', '21', '22', '23', '31', '32', '33'] > > Of course, as other posters have pointed out, this inverter does not > accept regexen with unbounded multiple characters '+' or '*', but '?' > and "{min,max}" notation will work. ?Even '.' is supported, although > this can generate a large number of return values. > > Of course, you'll also have to install pyparsing to get this to work. > > -- Paul Hi Paul, Thanks very much. This is exactly what I need now. I will check this function. Zhuo From alfps at start.no Mon Feb 8 00:18:14 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 06:18:14 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steven D'Aprano: > On Mon, 08 Feb 2010 03:21:11 +0100, Alf P. Steinbach wrote: > >>> A pointer tells you where something is; a reference doesn't. >> Sorry, I don't know of any relevant terminology where that is the case. > > Taken from Wikipedia: > > "A pointer is a simple, less abstracted implementation of the more > abstracted reference data type (although it is not as directly usable as > a C++ reference)." > > http://en.wikipedia.org/wiki/Pointer_(computing) > > In other words, a pointer is a specific type of reference. A reference in > turn is an opaque but low-level data type which "refers to" in some way > to the data you actually care about. (C++ has a concrete reference type, > which is not to be confused with abstract references.) > > http://en.wikipedia.org/wiki/Reference_(computer_science) > > Unless otherwise stated, references are opaque and coders need not care > how the reference mechanism is implemented, see e.g.: > > http://www.cocoabuilder.com/archive/cocoa/20777-opaque-reference.html > > In Python you don't use references directly, there is no reference type > or object. You can simulate the semantics of references (but not > pointers) by putting your object in a list and passing the list around. Yes, sort of. The last paragraph however confuses two different meanings of "reference". So when using terms such as "reference" it helps to refer :-) to some specific terminology, unless that's clearly understood from context. Cheers, - Alf From aahz at pythoncraft.com Mon Feb 8 00:23:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Feb 2010 21:23:51 -0800 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: In article , Jean-Michel Pichavant wrote: > >So guys, just ignore him if you don't like him. Mailers & news readers >have plenty of feature to make it happen. Unfortunately, unless you have a stable group of people with self-control, that doesn't work. Idiots like Xah will always get responses. (This opinion brought to you by two decades of experience with BBS, mailing lists, and Usenet.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From clp2 at rebertia.com Mon Feb 8 00:35:40 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Feb 2010 21:35:40 -0800 Subject: Python 2.4 and list of dictionary issues In-Reply-To: References: Message-ID: <50697b2c1002072135s68fbac3eqab417ff6fa5ac4cc@mail.gmail.com> On Sun, Feb 7, 2010 at 9:08 PM, Chris Stevens wrote: > Hi all, > > I'm a python newbie so please excuse me if I am missing something > simple here. I am writing a script which requires a list of > dictionaries (originally a dictionary of dictionaries, but I changed > it to a list to try and overcome the below problem). > > Now my understanding is that you create the empty list, then append or > add entries to it. Correct? > > Here is some code: > > userInfo = [] > ... > userInfo.append( { > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'username' : uidString[0], > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?... > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'failedattempts' : int(0) > }) > > I'm not to sure on the bracketing here, but I have tried many > combinations. The issue here is that I get a "IndexError: list index > out of range" message on the line "userInfo.append( {" Please include the full and exact error Traceback, and remember to do so in the future. > I wrote this script on a box with Python 2.6 and it worked fine. > Moving it to a box with 2.4, and I get this error. I can't understand > why i'm getting a list index out of range error when trying to append > (not reference) a list?? I have also tried "+=", and > userInfo(len(userInfo))= .... just get the same error. > > Could anyone shed some light on this? I would guess that `uidString` is probably an empty string or list, thus when you try to access the first character or item of it via uidString[0], you get an error. However, as you didn't include a Traceback, I can't be sure. I have no idea why the error only shows itself for certain Python versions; the problem is probably in some part of the code you're not showing us. Cheers, Chris -- http://blog.rebertia.com From danielwong at berkeley.edu Mon Feb 8 01:06:14 2010 From: danielwong at berkeley.edu (danielx) Date: Sun, 7 Feb 2010 22:06:14 -0800 (PST) Subject: convention for documenting function parameters in doc strings Message-ID: Is there a convention for how to document function (or method) parameters in doc strings? Recently, I've been doing alot of PHP programming, and in PHPdoc, you'd do it like this: /* * @param type $foo Description. * * @return type Description. */ function bar($foo) { ... } Is there an equivalent convention I (c|sh)ould be using in my Python docstrings? I saw that Python 3 has function annotations, which could be used for this purpose, but function annotations have no particular purpose within the language itself (which seems like a mistake to me), and they don't exist in the Python 2.x series (at least not the older versions). From gherron at islandtraining.com Mon Feb 8 01:26:14 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 07 Feb 2010 22:26:14 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> Message-ID: <4B6FAE86.2060603@islandtraining.com> Craig Berry wrote: > Can someone please tell me if there's a way to do this, or answer > definitively that there is no way? I have a design in progress that > could really use mousewheel control, and I don't want to settle for > Plan B until I know Plan A is impossible. :) > > On Fri, Feb 5, 2010 at 19:48, Craig Berry wrote: > >> Is there any way to get mouse wheel events from glut in PyOpenGL? >> >> -- >> Craig Berry - http://www.cine.net/~cberry/ >> "Lots of things in the universe don?t solve any problems, and >> nevertheless exist." -- Sean Carroll >> >> > > > > Didn't I answer this already? GLUT on windows usually does not catch mousewheel events for me. (Although it seems to me that is has worked sporadically over past years and versions.) GLUT on Linux does catch wheel events nicely -- but read on anyway... Freeglut (which is open source) is an (almost) direct binary replacement for GLUT, and it *does* catch mousewheel events. (On both Windows and Linux.) Is there a reason this answer is not satisfactory? If you're not *forced* to use GLUT, use FREEGLUT and your problem is solved with no additional work. If you *are* forced to use GLUT, rebel. GLUT has not been maintained for more than 10 years, is showing its age, and is licensed in such a way that you can't modify it. Use FREEGLUT instead: see http://freeglut.sourceforge.net/ From half.italian at gmail.com Mon Feb 8 01:28:19 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sun, 7 Feb 2010 22:28:19 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> <811dd4e9-6eea-4c1f-a24b-ba0179e57f84@a13g2000vbf.googlegroups.com> Message-ID: On Feb 7, 4:57?pm, T wrote: > Thanks for the suggestions - ?I think my next step is to try running > it under an admin user account, as you guys both mentioned. ?Alf - > you're absolutely right, Microsoft has srvany.exe, which allows you to > run any EXE as a Windows service. ?I've done this in the past, but > it's more of a "hack"..so this go around (since I will be distributing > this program), I wanted to go the more professional route..which, > unfortunately, involves learning the "scum". :) ?I ?posted this to > comp.os.ms-windows.programmer.win32, so we'll see if what the Win32 > programmers have to say as well. ?Thanks again! I use windows services and they are very reliable. I would say though that relying on plink.exe is much less reliable than either python or the service that it is running under. Why not take a look at paramiko as the ssh client library? I think it runs under windows. Also perhaps Twisted has something. Either way would be light years ahead of using subprocess with plink. Just my thoughts. ~Sean From austin.bingham at gmail.com Mon Feb 8 01:42:24 2010 From: austin.bingham at gmail.com (Austin Bingham) Date: Mon, 8 Feb 2010 07:42:24 +0100 Subject: C/C++ Import In-Reply-To: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: Does the 'python' directory contain a file named '__init__.py'? This is required to let that directory act as a package (see: http://docs.python.org/tutorial/modules.html#packages); without it, you'll see the symptoms you're seeing. Austin On Mon, Feb 8, 2010 at 4:56 AM, 7H3LaughingMan wrote: > To make the background information short, I am trying to take a > program that uses Python for scripting and recompile it for Linux > since it originally was built to run on Win32. The program itself was > designed to be able to be compiled on Linux and someone made there on > release with source that added python scripting. After some issues I > got it to compile but now it is unable to import the files that it > needs. > > The program is running the following code... > PyImport_Import( PyString_FromString("python.PlayerManager") ); > > This is meant to import the file PlayerManager.py inside of the python > folder. However it throws the following Python Error (Gotten through > PyErr_Print()) > ImportError: No module named python.PlayerManager > > I am using 2.6.4 so I can't call it by the filename, does anyone know > how to do a proper import? > -- > http://mail.python.org/mailman/listinfo/python-list > From cdberry at gmail.com Mon Feb 8 01:45:44 2010 From: cdberry at gmail.com (Craig Berry) Date: Sun, 7 Feb 2010 22:45:44 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <4B6FAE86.2060603@islandtraining.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> Message-ID: <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> On Sun, Feb 7, 2010 at 22:26, Gary Herron wrote: > Didn't I answer this already? If you did, for whatever reason I didn't see it; I just rechecked my inbox to be sure. Thanks for doing so again! I assume, given the list we're on, that Freeglut can be used with Python. I'll look into it. Thanks for the pointer! -- Craig Berry - http://www.cine.net/~cberry/ "Lots of things in the universe don?t solve any problems, and nevertheless exist." -- Sean Carroll From arnodel at googlemail.com Mon Feb 8 02:19:59 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 08 Feb 2010 07:19:59 +0000 Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: "Alf P. Steinbach" writes: > * Chris Rebert: >> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>> Ok, just looking for a sanity check here, or maybe something I'm >>> missing. I have a class Test, for example: >>> >>> class Test: >>> def __init__(self, param1, param2, param3): >>> self.param1 = param1 >>> self.param2 = param2 >>> self.param3 = param3 >>> >>> Next, I have a dictionary mytest that contains instances of Test. If >>> I want to modify one of the Test instances within my dictionary, I >>> have to rewrite the entire entry, correct (since Python passes by >>> value, not reference)? >> >> Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> of what Python does use. > > Hm. While most everything I've seen at effbot.org has been clear and > to the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. Please! Not this again! This has been discussed to death and beyond more than enough times. Go search the c.l.p archives, read it all, and I'm sure you won't want to add anything anymore. -- Arnaud From grflanagan at gmail.com Mon Feb 8 03:02:43 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 08 Feb 2010 08:02:43 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Arnaud Delobelle wrote: > "Alf P. Steinbach" writes: > >> * Chris Rebert: >>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>> Ok, just looking for a sanity check here, or maybe something I'm >>>> missing. I have a class Test, for example: >>>> >>>> class Test: >>>> def __init__(self, param1, param2, param3): >>>> self.param1 = param1 >>>> self.param2 = param2 >>>> self.param3 = param3 >>>> >>>> Next, I have a dictionary mytest that contains instances of Test. If >>>> I want to modify one of the Test instances within my dictionary, I >>>> have to rewrite the entire entry, correct (since Python passes by >>>> value, not reference)? >>> Incorrect; Python uses neither. See >>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>> of what Python does use. >> Hm. While most everything I've seen at effbot.org has been clear and >> to the point, that particular article reads like a ton of obfuscation. >> >> Python passes pointers by value, just as e.g. Java does. > > > Please! Not this again! This has been discussed to death and beyond more > than enough times. Go search the c.l.p archives, read it all, and I'm > sure you won't want to add anything anymore. > +1 !! From rogerb at rogerbinns.com Mon Feb 8 03:11:22 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 08 Feb 2010 00:11:22 -0800 Subject: SQLite3: preventing new file creation In-Reply-To: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> References: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gnarlodious wrote: > Every time I say something like: > > connection=sqlite3.connect(file) > > sqlite creates a new database file. Can this behavior be suppressed > through SQLite? Or am I forced to check for the file existing first? This is due to the API that pysqlite uses to talk to SQLite. (There is a more recent API but pysqlite remains backwards compatible with older SQLite versions). Note that although SQLite will create the file, it will be zero length (*) until you do a command that causes a database change. Also as a guideline be careful with SQLite files. In particular not only is there a database file, but there may also be a journal file. If the journal is removed then the main database file can be corrupted. (The journal contains data in order to rollback back incomplete transactions from the database.) (*) On Mac due to an operating system bug the file will actually be created as one byte in length containing the upper case letter 'S'. There is a dedicated mailing list for Python and SQLite: http://groups.google.com/group/python-sqlite You can use the newer SQLite database open API as well as many other SQLite APIs not supported by pysqlite by using APSW. (Disclaimer: I am the author of APSW.) Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAktvxyoACgkQmOOfHg372QQjqwCglx0u6OgGgOsQm0Bwd7s6BmCS 7EgAoKDdMZyDaw3Ov+Uqzs3RFX/NSHEK =/E0N -----END PGP SIGNATURE----- From rogerb at rogerbinns.com Mon Feb 8 03:16:35 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 08 Feb 2010 00:16:35 -0800 Subject: execute sqlite3 dot commands in python In-Reply-To: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 gintare statkute wrote: > Does anybody know if it possible to execute sqlite3 dot commands in python? The dot commands are parsed and executed by different code not part of the standard SQLite library. However if you want interactive shell functionality from Python then you can use APSW. It includes a shell you can just go ahead and use based on a shell class you can extend with your own methods, direct input and output as needed, completion etc. http://apsw.googlecode.com/svn/publish/shell.html (Disclaimer: I am the APSW author) Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAktvyGMACgkQmOOfHg372QT5mgCgrMCtb3bHd3rF0L+lL/nZV6BX zrMAn1fcxS4CyKYF4KXVBcVcEXWhxoig =hpkY -----END PGP SIGNATURE----- From petef4+usenet at gmail.com Mon Feb 8 03:27:52 2010 From: petef4+usenet at gmail.com (Pete Forman) Date: Mon, 08 Feb 2010 08:27:52 +0000 Subject: xmlrpc slow in windows 7 if hostnames are used References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> <4B6E1444.9060001@sequans.com> Message-ID: "Gabriel Genellina" writes: > En Sat, 06 Feb 2010 22:15:48 -0300, Jean-Michel Pichavant > escribi?: > >> I'm puzzled. >> Unless my english is failing me, everything would be solved using >> hostnames if I follow you. Why don't you do that ? >> I am no network/IP guru, but it sounds very weird to have requests >> rejected when using IP addresses. Are you sure your host names are >> resolved with the same IPM address you are using ? > > HTTP 1.1 requires a Host: header field; this way, multiple web > servers may share the same IP address. So you can't identify a host > by its IP alone; the host name is required. This was devised in > order to save IPv4 addresses; LACNIC (the Latin America addresses > register) does not assign addresses to ISP's based solely on web > hosting anymore - they MUST share existing IPs. And I think a > similar policy is used on other regions. If you really want to go for speed you should be able to set the Host: header to the name but use the IP address to make the connection. Something else that might be slowing you down is anti-spyware or anti-virus. Several products put a long list of blacklist sites in the hosts file. Windows can be rather slow to process that file. -- Pete Forman -./\.- West Sussex, UK -./\.- http://petef.22web.net -./\.- petef4+usenet at gmail.com -./\.- From anthra.norell at bluewin.ch Mon Feb 8 03:30:51 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 08 Feb 2010 09:30:51 +0100 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <06a91472-3974-45d3-b86a-c3c9055a5831@z26g2000yqm.googlegroups.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> <4B6EC203.4040807@holdenweb.com> <06a91472-3974-45d3-b86a-c3c9055a5831@z26g2000yqm.googlegroups.com> Message-ID: <4B6FCBBB.3090707@bluewin.ch> Schif Schaf wrote: > On Feb 7, 8:57 am, Tim Chase wrote: > >> Steve Holden wrote: >> >> >>> Really? Under what circumstances does a simple one-for-one character >>> replacement operation fail? >>> >> Failure is only defined in the clarified context of what the OP >> wants :) Replacement operations only fail if the OP's desired >> output from the above mess doesn't change *all* of the ]/[ >> characters, but only those with some form of parity (nested or >> otherwise). But if the OP *does* want all of the ]/[ characters >> replaced regardless of contextual nature, then yes, replace is a >> much better solution than regexps. >> >> > > I need to do the usual "pipe text through and do various search/ > replace" thing fairly often. The above case of having to replace > brackets with braces is only one example. Simple string methods run > out of steam pretty quickly and much of my work relies on using > regular expressions. Yes, I try to keep focused on simplicity, and > often regexes are the simplest solution for my day-to-day needs. > Could you post a complex case? It's a kindness to your helpers to simplify your case, but if the simplification doesn't cover the full scope of your problem you can't expect the suggestions to cover it. Frederic From rychphd at gmail.com Mon Feb 8 03:38:12 2010 From: rychphd at gmail.com (rych) Date: Mon, 8 Feb 2010 00:38:12 -0800 (PST) Subject: ctypes Structure serialization References: <615b1271-a9b0-4558-8e45-e4370698d96a@a16g2000pre.googlegroups.com> Message-ID: OK, an easier question, hopefully. How to unpack all fields from ctypes Structure line by line and save into the name-value pairs? From ldo at geek-central.gen.new_zealand Mon Feb 8 03:53:24 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Feb 2010 21:53:24 +1300 Subject: The Case For Do-Once Message-ID: I wrote my first Python extension library over the last couple of weeks. I took note of all the recommendations to keep track of reference counts, to ensure that objects were not disposed when they shouldn?t be, and were when they should. However, the example code seems to use gotos. And the trouble with these is that they don?t nest and un-nest easily; try to do too much refactoring with them, and you run into the age-old ?spaghetti code? problem. Which is where the do-once block comes in. The basic control flow is this: * Unconditionally initialize all dynamic storage to nil * Do the main body of the code, aborting in any error * Regardless of success or failure of the above, dispose of all allocated dynamic storage, using disposal calls which turn into noops if passed pointers that are already nil. For example, here?s a utility routine from my extension that, passed a Python array object, returns the address and length of the storage: static void GetBufferInfo ( PyObject * FromArray, unsigned long * addr, unsigned long * len ) /* returns the address and length of the data in a Python array object. */ { PyObject * TheBufferInfo = 0; PyObject * AddrObj = 0; PyObject * LenObj = 0; do /*once*/ { TheBufferInfo = PyObject_CallMethod(FromArray, "buffer_info", ""); if (TheBufferInfo == 0) break; AddrObj = PyTuple_GetItem(TheBufferInfo, 0); LenObj = PyTuple_GetItem(TheBufferInfo, 1); if (PyErr_Occurred()) break; Py_INCREF(AddrObj); Py_INCREF(LenObj); *addr = PyInt_AsUnsignedLongMask(AddrObj); *len = PyInt_AsUnsignedLongMask(LenObj); if (PyErr_Occurred()) break; } while (false); Py_XDECREF(AddrObj); Py_XDECREF(LenObj); Py_XDECREF(TheBufferInfo); } /*GetBufferInfo*/ You can pretty much determine by inspection that all the reference counts are properly maintained, no need to trace through convoluted flows of control. From stefan_ml at behnel.de Mon Feb 8 03:59:42 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 09:59:42 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <7xbpg5dazb.fsf@ruckus.brouhaha.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> Message-ID: <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> Paul Rubin, 04.02.2010 02:51: > John Nagle writes: >> Analysis of each domain is >> performed in a separate process, but each process uses multiple >> threads to read process several web pages simultaneously. >> >> Some of the threads go compute-bound for a second or two at a time as >> they parse web pages. > > You're probably better off using separate processes for the different > pages. If I remember, you were using BeautifulSoup, which while very > cool, is pretty doggone slow for use on large volumes of pages. I don't > know if there's much that can be done about that without going off on a > fairly messy C or C++ coding adventure. Maybe someday someone will do > that. Well, if multi-core performance is so important here, then there's a pretty simple thing the OP can do: switch to lxml. http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Stefan From duncan.booth at invalid.invalid Mon Feb 8 04:00:37 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Feb 2010 09:00:37 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> Message-ID: T wrote: > Oops, this one was my fault - the object I was having the issues with > was actually a shelve file, not a dictionary..so just re-assigning the > variable isn't working, but re-writing the object to the shelve file > does. So in this case, is there any way to just change a single > value, or am I stuck rewriting the entry? Either open the shelve with writeback=True or rewrite the entry. Rewriting the entry isn't hard: you can just re-use the same value: def changevalue(): for key in mytest.keys(): temp = mytest[key] temp.param3 = "newvalue" mytest[key] = temp If you really are changing every item in the shelve using writeback=True will be much simpler, but if you are only changing a few then just tell the shelve that you've updated them as above. -- Duncan Booth http://kupuguy.blogspot.com From stefan_ml at behnel.de Mon Feb 8 04:02:00 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 10:02:00 +0100 Subject: Stephen -- Bruce? In-Reply-To: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> References: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> Message-ID: <4b6fd308$0$6722$9b4e6d93@newsspool2.arcor-online.net> Mensanator, 05.02.2010 00:36: > On Feb 4, 5:13 pm, "Alf P. Steinbach" wrote: >> What's this about all the Stephen'ses here? >> >> Shouldn't it be Bruce? > > Of course. We just call everyone Stephen to avoid confusion. Some people even manage to adapt the spellings accordingly. Stefan From louis.coilliot at gmail.com Mon Feb 8 04:02:50 2010 From: louis.coilliot at gmail.com (lofic) Date: Mon, 8 Feb 2010 01:02:50 -0800 (PST) Subject: threading+popen2 hang References: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> Message-ID: <2542cf60-a193-4087-a1fe-1d60ee13c630@v25g2000yqk.googlegroups.com> On 7 f?v, 17:00, a... at pythoncraft.com (Aahz) wrote: > In article <188bfb67-3334-4325-adfc-3fa4d28f0... at d27g2000yqn.googlegroups.com>, > > lofic ? wrote: > > >Works fine on RHEL5/python 2.4.3 > >Hangs on RHEL4/python 2.3.4 > > Then use Python 2.4 -- surely you don't expect anyone to provide bugfixes > for a release that's several years old? > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > import antigravity 2.3 is the version provided with RHEL 4, which is still widely used in production environments. Sometimes it is not so easy to shift to another version in production systems. Some people don't work with the last bleeding edge Fedora release and must deal with (sometimes pretty old) existing system pools. I could deploy python 2.4 in addition to python 2.3, but it is much shake up for a little bug and a little program. I was not expected a bugfix, but maybe a workaround. Louis From no.email at nospam.invalid Mon Feb 8 04:10:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 08 Feb 2010 01:10:07 -0800 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <7xeikw2ivk.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > Well, if multi-core performance is so important here, then there's a pretty > simple thing the OP can do: switch to lxml. > > http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Well, lxml is uses libxml2, a fast XML parser written in C, but AFAIK it only works on well-formed XML. The point of Beautiful Soup is that it works on all kinds of garbage hand-written legacy HTML with mismatched tags and other sorts of errors. Beautiful Soup is slower because it's full of special cases and hacks for that reason, and it is written in Python. Writing something that complex in C to handle so much potentially malicious input would be quite a lot of work to write at all, and very difficult to ensure was really safe. Look at the many browser vulnerabilities we've seen over the years due to that sort of problem, for example. But, for web crawling, you really do need to handle the messy and wrong HTML properly. From stefan_ml at behnel.de Mon Feb 8 04:16:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 10:16:34 +0100 Subject: intolerant HTML parser In-Reply-To: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> Message-ID: <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> Jim, 06.02.2010 20:09: > I generate some HTML and I want to include in my unit tests a check > for syntax. So I am looking for a program that will complain at any > syntax irregularities. First thing to note here is that you should consider switching to an HTML generation tool that does this automatically. Generating markup manually is usually not a good idea. > I am familiar with Beautiful Soup (use it all the time) but it is > intended to cope with bad syntax. I just tried feeding > HTMLParser.HTMLParser some HTML containing '

ab

' and it > didn't complain. > > That is, this: > h=HTMLParser.HTMLParser() > try: > h.feed('

ab

') > h.close() > print "I expect not to see this line" > except Exception, err: > print "exception:",str(err) > gives me "I expect not to see this line". > > Am I using that routine incorrectly? Is there a natural Python choice > for this job? You can use lxml and let it validate the HTML output against the HTML DTD. Just load the DTD from a catalog using the DOCTYPE in the document (see the 'docinfo' property on the parse tree). http://codespeak.net/lxml/validation.html#id1 Note that when parsing the HTML file, you should disable the parser failure recovery to make sure it barks on syntax errors instead of fixing them up. http://codespeak.net/lxml/parsing.html#parser-options http://codespeak.net/lxml/parsing.html#parsing-html Stefan From stefan_ml at behnel.de Mon Feb 8 04:19:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 10:19:54 +0100 Subject: The Case For Do-Once In-Reply-To: References: Message-ID: <4b6fd73a$0$6734$9b4e6d93@newsspool2.arcor-online.net> Lawrence D'Oliveiro, 08.02.2010 09:53: > I wrote my first Python extension library over the last couple of weeks. I > took note of all the recommendations to keep track of reference counts, to > ensure that objects were not disposed when they shouldn?t be, and were when > they should. This sounds more like a case for Cython to me, should have saved you a lot of time. Stefan From andrew.degtiariov at gmail.com Mon Feb 8 04:37:53 2010 From: andrew.degtiariov at gmail.com (Andrew Degtiariov) Date: Mon, 8 Feb 2010 11:37:53 +0200 Subject: Import question In-Reply-To: References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> Message-ID: <5d1b76f61002080137o6e3f9a1fjdab8bcf8d3959faf@mail.gmail.com> 2010/2/6 Gabriel Genellina > En Fri, 05 Feb 2010 13:21:47 -0300, Andrew Degtiariov > escribi?: > > > Code of our project has split into several packages and we deploy the >> project using buildout. >> All worked fine until I need to dynamically inspect python modules. >> > > Entirely by luck, I'd say :) > > > ????project.api.config >> ? ????project >> ? ? ????api >> ? ? ????config >> ? ? ????settings >> ? ????project.api.config.egg-info >> ????project.api.contacts >> ? ????project >> ? ? ????api >> ? ? ????contacts >> ? ? ????importer >> ? ? ????views >> ? ????project.api.contacts.egg-info >> > > Regular code like "import project.api.config" worked fine, but now I'm >> tryed >> __import__('project.api.config'): >> >> $ bin/python >> >> import project.api.config >>>>> __import__('project.api.config') >>>>> >>>> > 'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'> >> > > > If someone is interesting - __import__ works but imp doesn't. In my example: >>> m = __import__('project.api.config') >>> m >>> m.api >>> m.api.config Please note that the m and m.api pointed to first installing package with namespace project.api but m.api.config have pointed to the proper file. And releasing code with several distributions it is one of goals of Distribute. And you might look to pypi for... zope. There is lot of package which names starts from "zope." It's really convenient -- Andrew Degtiariov DA-RIPE -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Feb 8 05:19:34 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 08 Feb 2010 07:19:34 -0300 Subject: How to print all expressions that match a regular expression References: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> <76609ff4-6579-4b2b-80b7-fb88bd5f1fa7@a32g2000yqm.googlegroups.com> Message-ID: En Mon, 08 Feb 2010 02:17:59 -0300, hzhuo1 at gmail.com escribi?: >> Please check out this example on the pyparsing wiki, >> invRegex.py:http://pyparsing.wikispaces.com/file/view/invRegex.py. >> This code >> implements a generator that returns successive matching strings for >> the given regex. [...] >> Of course, as other posters have pointed out, this inverter does not >> accept regexen with unbounded multiple characters '+' or '*', but '?' >> and "{min,max}" notation will work. Even '.' is supported, although >> this can generate a large number of return values. > > Thanks very much. This is exactly what I need now. I will check this > function. > Here you have another approach based on [1]. This is a generator-based approach, yielding all strings in increasing length order. In principle it can handle unbounded repetitions, except as written the maximum recursion limit is shortly reached (the original code is in Haskell, I almost blindly translated it into Python; certainly it can be rewritten more efficiently) You have to parse the R.E. and generate the corresponding function calls to the merge/prod/closure functions -- pyparsing certainly can help with that. "ab" becomes prod(a,b), "a|b" becomes merge(a,b), and "a*" becomes closure(a) By example, to find the language defined by this expression "(a|bc)*d", one has to evaluate: prod( closure( merge(['a'], prod(['b'],['c']))), ['d'] ) wich yields these strings: d ad aad bcd aaad abcd bcad ... bcbcbcbcaad bcbcbcbcbcd aaaaaaaaaaad and after 234 results aborts with a recursion error :( [1] http://www.cs.utexas.edu/users/misra/Notes.dir/RegExp.pdf -- Gabriel Genellina -------------- next part -------------- A non-text attachment was scrubbed... Name: enumerate_regular_language.py Type: application/octet-stream Size: 2732 bytes Desc: not available URL: From gagsl-py2 at yahoo.com.ar Mon Feb 8 05:19:34 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 08 Feb 2010 07:19:34 -0300 Subject: How to print all expressions that match a regular expression References: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> <76609ff4-6579-4b2b-80b7-fb88bd5f1fa7@a32g2000yqm.googlegroups.com> Message-ID: En Mon, 08 Feb 2010 02:17:59 -0300, hzhuo1 at gmail.com escribi?: >> Please check out this example on the pyparsing wiki, >> invRegex.py:http://pyparsing.wikispaces.com/file/view/invRegex.py. >> This code >> implements a generator that returns successive matching strings for >> the given regex. [...] >> Of course, as other posters have pointed out, this inverter does not >> accept regexen with unbounded multiple characters '+' or '*', but '?' >> and "{min,max}" notation will work. Even '.' is supported, although >> this can generate a large number of return values. > > Thanks very much. This is exactly what I need now. I will check this > function. > Here you have another approach based on [1]. This is a generator-based approach, yielding all strings in increasing length order. In principle it can handle unbounded repetitions, except as written the maximum recursion limit is shortly reached (the original code is in Haskell, I almost blindly translated it into Python; certainly it can be rewritten more efficiently) You have to parse the R.E. and generate the corresponding function calls to the merge/prod/closure functions -- pyparsing certainly can help with that. "ab" becomes prod(a,b), "a|b" becomes merge(a,b), and "a*" becomes closure(a) By example, to find the language defined by this expression "(a|bc)*d", one has to evaluate: prod( closure( merge(['a'], prod(['b'],['c']))), ['d'] ) wich yields these strings: d ad aad bcd aaad abcd bcad ... bcbcbcbcaad bcbcbcbcbcd aaaaaaaaaaad and after 234 results aborts with a recursion error :( [1] http://www.cs.utexas.edu/users/misra/Notes.dir/RegExp.pdf -- Gabriel Genellina -------------- next part -------------- A non-text attachment was scrubbed... Name: enumerate_regular_language.py Type: application/octet-stream Size: 2732 bytes Desc: not available URL: From ldo at geek-central.gen.new_zealand Mon Feb 8 05:19:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Feb 2010 23:19:45 +1300 Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> Message-ID: In message <4b6fd672$0$6734$9b4e6d93 at newsspool2.arcor-online.net>, Stefan Behnel wrote: > Jim, 06.02.2010 20:09: > >> I generate some HTML and I want to include in my unit tests a check >> for syntax. So I am looking for a program that will complain at any >> syntax irregularities. > > First thing to note here is that you should consider switching to an HTML > generation tool that does this automatically. I think that?s what he?s writing. From stefan_ml at behnel.de Mon Feb 8 05:36:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 11:36:45 +0100 Subject: intolerant HTML parser In-Reply-To: References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Lawrence D'Oliveiro, 08.02.2010 11:19: > In message <4b6fd672$0$6734$9b4e6d93 at newsspool2.arcor-online.net>, Stefan > Behnel wrote: > >> Jim, 06.02.2010 20:09: >> >>> I generate some HTML and I want to include in my unit tests a check >>> for syntax. So I am looking for a program that will complain at any >>> syntax irregularities. >> First thing to note here is that you should consider switching to an HTML >> generation tool that does this automatically. > > I think that?s what he?s writing. I don't read it that way. There's a huge difference between - generating HTML manually and validating (some of) it in a unit test and - generating HTML using a tool that guarantees correct HTML output the advantage of the second approach being that others have already done all the debugging for you. Stefan From jeanmichel at sequans.com Mon Feb 8 05:49:52 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Feb 2010 11:49:52 +0100 Subject: convention for documenting function parameters in doc strings In-Reply-To: References: Message-ID: <4B6FEC50.90708@sequans.com> danielx wrote: > Is there a convention for how to document function (or method) > parameters in doc strings? Recently, I've been doing alot of PHP > programming, and in PHPdoc, you'd do it like this: > > /* > * @param type $foo Description. > * > * @return type Description. > */ > function bar($foo) { > ... > } > > Is there an equivalent convention I (c|sh)ould be using in my Python > docstrings? I saw that Python 3 has function annotations, which could > be used for this purpose, but function annotations have no particular > purpose within the language itself (which seems like a mistake to me), > and they don't exist in the Python 2.x series (at least not the older > versions). > Different strategies here: 1/ most doc builders propose their own format. You can stick to it if you don't want to use another builder (e.g. epydoc has a specific syntax to document signatures) 2/ Use a 'standard' format, usually these formats are a bit more formal but they gain in portability, most builders support these formats. reStructuredText is one of them and supported by all python doc builders. http://epydoc.sourceforge.net/manual-othermarkup.html JM From klausneuner72 at googlemail.com Mon Feb 8 05:57:33 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Mon, 8 Feb 2010 02:57:33 -0800 (PST) Subject: use strings to call functions Message-ID: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Hello, I am writing a program that analyzes files of different formats. I would like to use a function for each format. Obviously, functions can be mapped to file formats. E.g. like this: if file.endswith('xyz'): xyz(file) elif file.endswith('abc'): abc(file) ... Yet, I would prefer to do something of the following kind: func = file[-3:] apply_func(func, file) Can something of this kind be done in Python? Klaus From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 8 06:11:14 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 08 Feb 2010 12:11:14 +0100 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4b6ff153$0$28652$426a74cc@news.free.fr> Klaus Neuner a ?crit : > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] A file extension is not necessarily 3 chars long. > apply_func(func, file) > > Can something of this kind be done in Python? The simplest (and canonical) solution is to use a dict: def handle_txt(path): # code here def handle_py(path): # code here etc... def handle_default(path): # for anything else handlers = { ".txt" : handle_txt, ".py" : handle_py, # etc } import os def handle_file(path): dummy, ext = os.path.splitext(path) handler = handlers.get(ext, handle_default) return handler(path) HTH From boblatest at googlemail.com Mon Feb 8 06:14:40 2010 From: boblatest at googlemail.com (boblatest) Date: Mon, 8 Feb 2010 03:14:40 -0800 (PST) Subject: Create a backslash-escaped version of a string? Message-ID: Hello, I'd like to have control characters in a string to be converted to their backslash-escaped counterparts. I looked in the encoders section of the string module but couldn't find anything appropriate. I could write it myself but I'm sure something of the sort exists. The hypothetical method "c_escaped()" would work like this: >>> a="abc\rdef" >>> print a.c_escaped() abc\rdef >>> Thanks, robert From sivaits4u at gmail.com Mon Feb 8 06:20:50 2010 From: sivaits4u at gmail.com (Bujji) Date: Mon, 8 Feb 2010 16:50:50 +0530 Subject: speed of server Message-ID: <581ce2791002080320p4e257539s6d089d5f75a62853@mail.gmail.com> hi all, how to find the speed of a particular server ( suppose it is hosting a site yahoo.com) how can i find it using python script whether it is slow or faster on that time help me thanks Bujji -------------- next part -------------- An HTML attachment was scrubbed... URL: From klausneuner72 at googlemail.com Mon Feb 8 06:26:39 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Mon, 8 Feb 2010 03:26:39 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> Message-ID: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> > > A file extension is not necessarily 3 chars long. No, of course not. But it is, if I choose to use only (self-made) file endings that are 3 chars long. Anyway, it was just an example. > handlers = { > ? ? ".txt" : handle_txt, > ? ? ".py" : handle_py, > ? ? # etc > ? ? } > That is exactly what I would like to avoid: Having to map the function 'handle_txt' to '.txt'. Firstly, because I don't want to repeat anything and secondly, because I will one day add a new function and forget to add its name to the dictionary. (This is not severe if there is only one dictionary for mapping functions, but it will make life a lot harder, if a lot of mappings of this kind are used.) What I want is calling the string directly. In Prolog, I would use something like: get_file_ending(File, Ending), Predicate =.. [Ending, File], call(Predicate). From clp2 at rebertia.com Mon Feb 8 06:28:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Feb 2010 03:28:39 -0800 Subject: Create a backslash-escaped version of a string? In-Reply-To: References: Message-ID: <50697b2c1002080328s55ec1369u98466118a620fb98@mail.gmail.com> On Mon, Feb 8, 2010 at 3:14 AM, boblatest wrote: > Hello, > > I'd like to have control characters in a string to be converted to > their backslash-escaped counterparts. I looked in the encoders section > of the string module but couldn't find anything appropriate. I could > write it myself but I'm sure something of the sort exists. The > hypothetical method "c_escaped()" would work like this: > >>>> a="abc\rdef" >>>> print a.c_escaped() > abc\rdef print a.encode("string-escape") Note that there are some wrinkles if the string contains quote marks (and possibly also if it contains Unicode; I didn't test). Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Mon Feb 8 06:30:34 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Feb 2010 06:30:34 -0500 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4B6FF5DA.2040804@ieee.org> Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? > > Klaus > > > You perhaps were intending to use the file extension , rather than the last three characters of the name. If so, consider os.path.splitext(). And you shouldn't shadow the builtin *file* type with a variable of the same name. More directly to your question, best suggestion is to build a (const) dictionary: apply_func = { "xyz":xyz, "abc":abc } which maps the strings to functions. This line can be at outer scope, as long as it follows all the appropriate function definitions. Notice that the individual functions need not be in the same module, if you use a fully qualified name in the dictionary. And of course, there's no necessity of naming the function exactly the same as the extension. So you could implement the functions in another module 'implem", and use the following: import implem apply_func = { "xyz":implem.process_xyz_files, "abc":implem.process_abc_files } Now, you use it by something like: dummy, func_ext = os.path.splitext(my_filename) apply_func(func_ext, my_filename) (all code untested) DaveA From wojciech_mula at poczta.null.onet.pl.invalid Mon Feb 8 06:37:49 2010 From: wojciech_mula at poczta.null.onet.pl.invalid (Wojciech =?ISO-8859-2?Q?Mu=B3a?=) Date: Mon, 8 Feb 2010 12:37:49 +0100 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <20100208123749.d0c0d6c1.wojciech_mula@poczta.null.onet.pl.invalid> Klaus Neuner wrote: > > handlers = { > > ? ? ".txt" : handle_txt, > > ? ? ".py" : handle_py, > > ? ? # etc > > ? ? } > > > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. Use dictionary mantained by runtime: def handle(extensions): funname = "handle_" + extension return globals()[funname] handle('txt') # => function handle_txt w. From mail at timgolden.me.uk Mon Feb 8 06:50:02 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Feb 2010 11:50:02 +0000 Subject: use strings to call functions In-Reply-To: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <4B6FFA6A.9080604@timgolden.me.uk> On 08/02/2010 11:26, Klaus Neuner wrote: >> >> A file extension is not necessarily 3 chars long. > > No, of course not. But it is, if I choose to use only (self-made) file > endings that are 3 chars long. Anyway, it was just an example. > >> handlers = { >> ".txt" : handle_txt, >> ".py" : handle_py, >> # etc >> } >> > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. (This is not severe if there > is only one dictionary for mapping functions, but it will make life a > lot harder, if a lot of mappings of this kind are used.) > > What I want is calling the string directly. In Prolog, I would use > something like: > > get_file_ending(File, Ending), > Predicate =.. [Ending, File], > call(Predicate). You basically need a getattr lookup. If you're prepared to instantiate a class or to import a handlers module then you can just look up against that: def handle_py (stuff): "print handling py" def handle_default (stuff): "print handling default"
import handlers ext = "py" handler = getattr (handlers, "handle_" + ext, handlers.handle_default) handler ("stuff")
You can do the equivalent by having a Handlers class with the appropriate methods (handle_py, etc.) and which you then instantiate. If you want to keep everything in one module, you should be able to achieve the same effect by looking the module up in sys.modules and then proceeding as above: import sys def handle_py (stuff): print "handling py" def handle_default (stuff): print "handling default" ext = "py" me = sys.modules[__name__] handler = getattr (me, "handle_" + ext, me.handle_default) handler ("blah") (All untested...) TJG From steve at holdenweb.com Mon Feb 8 06:51:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 06:51:38 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Sun, 07 Feb 2010 22:03:06 -0500, Steve Holden wrote: > >> Alf: >> >> This topic was discussed at great, nay interminable, length about a year >> ago. I'd appreciate it if you would search the archives and read what >> was said then rather than hashing the whole topic over again to nobody's >> real advantage. > > Curse you Steve, I had just come up with a brilliant rebuttal of Alf's > position. It was sheer genius, the sort of thing that would have James > Gosling weeping with envy. > > Oh well, into the bitbucket it goes... > > You're a better man for it, Steven! Admirable self-restraint ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 8 06:59:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 06:59:02 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: [...] >> Alf: >> >> This topic was discussed at great, nay interminable, length about a year >> ago. I'd appreciate it if you would search the archives and read what >> was said then rather than hashing the whole topic over again to nobody's >> real advantage. > > Well that's my point, and thanks for backing me up on that :-): it's > very simple, and as demonstrated can be expressed in 10 words or less > (plus perhaps a terminology reference, as I did above), so all that > discussion and in particular the lengthy article at effbot serves as > obfuscation and nothing else. > Please don't assume I was trying to support you. Your remarks showed considerable ignorance of issue that were extremely nuanced. Whatever point you were trying to make was lost in your self-aggrandizing disrespect of Fredrik Lundh, a software engineer of some repute with a long history of contribution to Python. The fact that your post was basically a restatement of one of the several competing positions in that thread makes it no more right than any of the others. > By the way, most every programming language has some corner like that, > something that is utterly simple but somehow has some kind of > obfuscation-meme attached. > Why thank you for the education. Somehow in my 40-odd years of programming I had quite overlooked that fact. Which helps how? > In C++ it's "call" and "constructor". It doesn't help that the > language's standard lays down the law on it, it doesn't help that the > language's creator has laid down the law, it doesn't help that it's > utterly and completely simple. Somehow newbies and even some experienced > people manage to create their own terminological nightmare and drawing > conclusions about reality from that misguided obfuscated view, and then > discussing it up and down and sideways. > Which IMHO you have done little to assist. Just how exactly *do* we succeed in asking you not to discuss something? yours intemperate-ly - steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Mon Feb 8 06:59:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Feb 2010 12:59:39 +0100 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4B6FFCAB.2040802@sequans.com> Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? > > Klaus > > You won't need anything else than defining the proper function to support the extension with the following code: import os class Handlers: class NoHandler(Exception): pass @staticmethod def txt(fileName): print 'I am processing a txt file' @staticmethod def tar(fileName): print 'I am processing a tar file' @classmethod def default(cls, fileName): raise cls.NoHandler("I don't know how to handle %s " % fileName) for fileName in ['/tmp/test.txt', '/tmp/sdfsd.sfds']: _, extension = os.path.splitext(fileName) func = getattr(Handlers, extension.replace('.', ''), Handlers.default) try: func(fileName) except Handlers.NoHandler, exc: print exc JM From steve at holdenweb.com Mon Feb 8 07:01:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 07:01:42 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Gerard Flanagan wrote: > Arnaud Delobelle wrote: >> "Alf P. Steinbach" writes: >> >>> * Chris Rebert: >>>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>>> Ok, just looking for a sanity check here, or maybe something I'm >>>>> missing. I have a class Test, for example: >>>>> >>>>> class Test: >>>>> def __init__(self, param1, param2, param3): >>>>> self.param1 = param1 >>>>> self.param2 = param2 >>>>> self.param3 = param3 >>>>> >>>>> Next, I have a dictionary mytest that contains instances of Test. If >>>>> I want to modify one of the Test instances within my dictionary, I >>>>> have to rewrite the entire entry, correct (since Python passes by >>>>> value, not reference)? >>>> Incorrect; Python uses neither. See >>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>>> of what Python does use. >>> Hm. While most everything I've seen at effbot.org has been clear and >>> to the point, that particular article reads like a ton of obfuscation. >>> >>> Python passes pointers by value, just as e.g. Java does. >> >> >> Please! Not this again! This has been discussed to death and beyond more >> than enough times. Go search the c.l.p archives, read it all, and I'm >> sure you won't want to add anything anymore. >> > > +1 !! > +1000 -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From stefan_ml at behnel.de Mon Feb 8 07:03:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 13:03:10 +0100 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4b6ffd7e$0$6735$9b4e6d93@newsspool2.arcor-online.net> Klaus Neuner, 08.02.2010 11:57: > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? Others have already pointed you to the approach of using a dict, or a module/class namespace with functions/methods to do this. Either of the latter two would be my favourite, depending on the complexity of the handlers. A class is more suitable as a container for short, highly correlated handlers, whereas a module makes more sense for handlers that do rather different things, or that are longer than a single function. A mixture of the two, e.g. a module of classes, where an entire class is used to implement a complete handler over several methods (potentially including some inheritance hierarchy between handlers that share functionality) might also be a solution. Note that objects can be callable in Python (special method __call__), you can exploit that here. What you are implementing here is commonly called a dispatch mechanism, BTW. There are several ways to do that, also within in Python. A web search should reveal some more. Stefan From steve at holdenweb.com Mon Feb 8 07:08:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 07:08:15 -0500 Subject: use strings to call functions In-Reply-To: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <4B6FFEAF.5070305@holdenweb.com> Klaus Neuner wrote: >> A file extension is not necessarily 3 chars long. > > No, of course not. But it is, if I choose to use only (self-made) file > endings that are 3 chars long. Anyway, it was just an example. > >> handlers = { >> ".txt" : handle_txt, >> ".py" : handle_py, >> # etc >> } >> > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. (This is not severe if there > is only one dictionary for mapping functions, but it will make life a > lot harder, if a lot of mappings of this kind are used.) > > What I want is calling the string directly. In Prolog, I would use > something like: > > get_file_ending(File, Ending), > Predicate =.. [Ending, File], > call(Predicate). > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 8 07:08:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 07:08:15 -0500 Subject: use strings to call functions In-Reply-To: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <4B6FFEAF.5070305@holdenweb.com> Klaus Neuner wrote: >> A file extension is not necessarily 3 chars long. > > No, of course not. But it is, if I choose to use only (self-made) file > endings that are 3 chars long. Anyway, it was just an example. > >> handlers = { >> ".txt" : handle_txt, >> ".py" : handle_py, >> # etc >> } >> > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. (This is not severe if there > is only one dictionary for mapping functions, but it will make life a > lot harder, if a lot of mappings of this kind are used.) > > What I want is calling the string directly. In Prolog, I would use > something like: > > get_file_ending(File, Ending), > Predicate =.. [Ending, File], > call(Predicate). > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tim_grove at sil.org Mon Feb 8 09:22:56 2010 From: tim_grove at sil.org (Timothy W. Grove) Date: Mon, 08 Feb 2010 14:22:56 +0000 Subject: Python User Group near Cheltenham, UK ? Message-ID: <4B701E40.2030307@sil.org> Anyone know of an 'active' Python User Group near Cheltenham, UK? I spotted one in Birmingham (http://www.pywm.eu), but would like one a little closer ... :-) Tim From jfabiani at yolo.com Mon Feb 8 09:27:21 2010 From: jfabiani at yolo.com (jfabiani at yolo.com) Date: Mon, 08 Feb 2010 06:27:21 -0800 Subject: Calendar GUI References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> <4B6D055A.30901@gmail.com> Message-ID: Jean-Michel Pichavant wrote: > Michael Torrie wrote: >> Gabriel wrote: >> >>> On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli >>> wrote: >>> >>>> I'm working on setting up some software for a Peruvian non-profit to >>>> help them organize their incoming volunteers. One of the features I'd >>>> like to add is a calendar-like view of the different volunteers arrival >>>> dates and staying time, with potentially some other info through some >>>> double-click action. Rather than writing a calendar gui myself, is >>>> there some open-source calendar program you guys could recommend that I >>>> could plug into? It has to be run locally, as the internet isn't so >>>> reliable down here, but other than that something simple and clean is >>>> ideal. >>>> Take a look at wxscheduler, and chandler. Johnf From solipsis at pitrou.net Mon Feb 8 09:28:41 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 8 Feb 2010 14:28:41 +0000 (UTC) Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: Le Tue, 02 Feb 2010 15:02:49 -0800, John Nagle a ?crit?: > I know there's a performance penalty for running Python on a multicore > CPU, but how bad is it? I've read the key paper > ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate if > the GIL just limited Python to running on one CPU at a time, but it's > worse than that; there's excessive overhead due to a lame locking > implementation. Running CPU-bound multithreaded code on a dual-core CPU > runs HALF AS FAST as on a single-core CPU, according to Beasley. That's on certain types of workloads, and perhaps on certain OSes, so you should try benching your own workload to see whether it applies. Two closing remarks: - this should (hopefully) be fixed in 3.2, as exarkun noticed - instead of spawning one thread per Web page, you could use Twisted or another event loop mechanism in order to process pages serially, in the order of arrival Regards Antoine. From mail at timgolden.me.uk Mon Feb 8 09:46:09 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Feb 2010 14:46:09 +0000 Subject: Python User Group near Cheltenham, UK ? In-Reply-To: <4B701E40.2030307@sil.org> References: <4B701E40.2030307@sil.org> Message-ID: <4B7023B1.2050802@timgolden.me.uk> On 08/02/2010 14:22, Timothy W. Grove wrote: > Anyone know of an 'active' Python User Group near Cheltenham, UK? I > spotted one in Birmingham (http://www.pywm.eu), but would like one a > little closer ... :-) Don't think there's anything further west than Northants / W. Midlands. There are Open Source things in Oxford but nothing Python-specific, I believe. TJG From austin.brkich at gmail.com Mon Feb 8 09:50:20 2010 From: austin.brkich at gmail.com (7H3LaughingMan) Date: Mon, 8 Feb 2010 06:50:20 -0800 (PST) Subject: C/C++ Import References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: <4d7eb353-fb6b-4379-beee-8971ddc2472d@o28g2000yqh.googlegroups.com> The folder does contain a file named '__init__.py'. However it contains nothing inside of the file. On Feb 8, 12:42?am, Austin Bingham wrote: > Does the 'python' directory contain a file named '__init__.py'? This > is required to let that directory act as a package (see:http://docs.python.org/tutorial/modules.html#packages);without it, > you'll see the symptoms you're seeing. > > Austin > > On Mon, Feb 8, 2010 at 4:56 AM, 7H3LaughingMan wrote: > > To make the background information short, I am trying to take a > > program that uses Python for scripting and recompile it for Linux > > since it originally was built to run on Win32. The program itself was > > designed to be able to be compiled on Linux and someone made there on > > release with source that added python scripting. After some issues I > > got it to compile but now it is unable to import the files that it > > needs. > > > The program is running the following code... > > PyImport_Import( PyString_FromString("python.PlayerManager") ); > > > This is meant to import the file PlayerManager.py inside of the python > > folder. However it throws the following Python Error (Gotten through > > PyErr_Print()) > > ImportError: No module named python.PlayerManager > > > I am using 2.6.4 so I can't call it by the filename, does anyone know > > how to do a proper import? > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From Steven.Rumbalski at fiserv.com Mon Feb 8 09:51:02 2010 From: Steven.Rumbalski at fiserv.com (Steven) Date: Mon, 8 Feb 2010 06:51:02 -0800 (PST) Subject: Simple question about Queue.Queue and threads References: Message-ID: <770583c3-a7c7-4a3d-b90f-9546801040e3@u26g2000yqm.googlegroups.com> On Feb 5, 7:45?am, "Frank Millman" wrote: > Hi all > > Assume you have a server process running, a pool of worker threads to > perform tasks, and aQueue.Queue() to pass the tasks to the workers. > > In order to shut down the server cleanly, you want to ensure that the > workers have all finished their tasks. I like the technique of putting a > None onto thequeue, and have each worker check for None, put None back onto > thequeue, and terminate itself. > > The main program would look something like this - > > ? ? q.put(None) > ? ? for worker in worker_threads: > ? ? ? ? worker.join() > > At this point you can be sure that each thread has completed its tasks and > terminated itself. > > However, thequeueis not empty - it still has the final None in it. > > Is it advisable to finalise the cleanup like this? - > > ? ? while not q.empty(): > ? ? ? ? q.get() > ? ? ? ? q.task_done() > ? ? q.join() > > Or is this completely redundant? > > Thanks > > Frank Millman Queue objects have support for this signaling baked in with q.task_done and q.join. After the server process has put all tasks into the queue, it can join the queue itself, not the worker threads. q.join() This will block until all tasks have been gotten AND completed. The worker threads would simply do this: task_data = q.get() do_task(task_data) q.task_done() Using pairs of get and task_done you no longer need to send a signal. Just exit the server process and the worker threads will die (assuming of course, you set .setDaemon(True) before starting each worker thread). Steven Rumbalski From grflanagan at gmail.com Mon Feb 8 10:00:27 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 08 Feb 2010 15:00:27 +0000 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > As mentioned, a dictionary dispatch will do what you want, but you can also use the self-registering technique outlined here: http://effbot.org/zone/metaclass-plugins.htm [Fredrik Lundh] (For Plugin, read Handler in this case.) One idea might be to have Handler classes such as: class TextHandler(HandlerType): extensions = ['', 'txt', 'rst'] def run(self, *args, **kw): .... do stuff then the __init__ of HandlerType's metaclass: def __init__(cls, name, bases, attrs): for ext in attrs.get('extensions', []): registry[ext] = cls then use like: registry['txt']().run() If you don't need state, you could perhaps make 'run' a staticmethod and store it rather than the class, eg. registry[ext] = cls.run and then just: registry['txt']() hth G.F ------------------------------------------------------------------------ registry = {} class HandlerType(object): class __metaclass__(type): def __init__(cls, name, bases, attrs): for ext in attrs.get('extensions', []): registry[ext] = cls class TextHandler(HandlerType): extensions = ['', 'txt'] print registry From alfps at start.no Mon Feb 8 10:22:03 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 16:22:03 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: > [...] >>> Alf: >>> >>> This topic was discussed at great, nay interminable, length about a year >>> ago. I'd appreciate it if you would search the archives and read what >>> was said then rather than hashing the whole topic over again to nobody's >>> real advantage. >> Well that's my point, and thanks for backing me up on that :-): it's >> very simple, and as demonstrated can be expressed in 10 words or less >> (plus perhaps a terminology reference, as I did above), so all that >> discussion and in particular the lengthy article at effbot serves as >> obfuscation and nothing else. >> > Please don't assume I was trying to support you. Your remarks showed > considerable ignorance of issue that were extremely nuanced. Whatever > point you were trying to make was lost in your self-aggrandizing > disrespect of Fredrik Lundh, a software engineer of some repute with a > long history of contribution to Python. The fact that your post was > basically a restatement of one of the several competing positions in > that thread makes it no more right than any of the others. What on Earth are you babbling about? Perhaps next you'll drag in the Pope, saying I've shown him some disrespect. News for you: the Pope ain't participating. >> By the way, most every programming language has some corner like that, >> something that is utterly simple but somehow has some kind of >> obfuscation-meme attached. >> > Why thank you for the education. Somehow in my 40-odd years of > programming I had quite overlooked that fact. Which helps how? > >> In C++ it's "call" and "constructor". It doesn't help that the >> language's standard lays down the law on it, it doesn't help that the >> language's creator has laid down the law, it doesn't help that it's >> utterly and completely simple. Somehow newbies and even some experienced >> people manage to create their own terminological nightmare and drawing >> conclusions about reality from that misguided obfuscated view, and then >> discussing it up and down and sideways. >> > Which IMHO you have done little to assist. Just how exactly *do* we > succeed in asking you not to discuss something? That's just a silly as the above. Hello? *Not* discuss an on-topic topic? Anyways, we haven't reached discussion yet, if it will ever come to that. All I see is a lot of silly noise about a simple trivially true technical statement, with incoherent allegations of disrespect to the Pope, the current king of France, and whomever, unfortunately as usual in this group. :-( Cheers & hth., - Alf From wanderer at dialup4less.com Mon Feb 8 10:24:32 2010 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 8 Feb 2010 07:24:32 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> <36952f27-c825-4ab8-bd2e-7dff097075fd@d30g2000vbl.googlegroups.com> Message-ID: <0434e8b6-fe13-4eed-97c7-090c1c2b0a3a@y7g2000vbb.googlegroups.com> On Feb 5, 5:21?pm, Wanderer wrote: > On Feb 5, 4:53?pm, Chris Rebert wrote: > > > > > On Fri, Feb 5, 2010 at 1:49 PM, Wanderer wrote: > > > On Feb 5, 3:26?pm, Chris Rebert wrote: > > >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > > >> > Which is the more accepted way to compose method names nounVerb or > > >> > verbNoun? > > > >> > For example voltageGet or getVoltage? getVoltage sounds more normal, > > >> > but voltageGet is more like voltage.Get. I seem to mix them and I > > >> > should probably pick one way and stick with it. > > > >> Use properties[1] and just call it `voltage`. Python is not Java [2]; > > >> explicit getters/setters are unpythonic. > > > >> [1]http://docs.python.org/library/functions.html#property > > > > Maybe I'm not using Get right either. I'm wrapping functions. > > > > ? ?def AbbeGet(self, Lens): > > > ? ? ? ?""" > > > ? ? ? ?Get the Abbe Number V for the material > > > ? ? ? ?where > > > ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > > ? ? ? ?where the Index of Refractions are > > > ? ? ? ?Nd at the Fraunhofer D line 0.5892um > > > ? ? ? ?Nf at the Fraunhofer F line 0.4861um > > > ? ? ? ?Nc at the Fraunhofer C line 0.6563um > > > ? ? ? ?""" > > > > ? ? ? ?Nd = Lens.Mat.NtGet(0.5892) > > > ? ? ? ?Nf = Lens.Mat.NtGet(0.4861) > > > ? ? ? ?Nc = Lens.Mat.NtGet(0.6563) > > > > ? ? ? ?if (Nf - Nc) != 0: > > > ? ? ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > > ? ? ? ?else: > > > ? ? ? ? ? ?V = 1e6 > > > > ? ? ? ?return V > > > This isn't even really a method; you don't refer to "self" in the body > > at all. Why isn't it just a function? > > > Cheers, > > Chris > > --http://blog.rebertia.com > > Okay, I guess it should be a function called abbe() instead of a > method called AbbeGet(). That should solve the problem of trying to > remember whether I called it GetAbbe or AbbeGet. > > Thanks Actually I decided it still should be a method, just not of doublet but of Lens. so the calls change from V1 = self.AbbeGet(Lens1) V2 = self.AbbeGet(Lens2) V1 = self.Lens1.abbe() V2 = self.Lens2.abbe() From boblatest at googlemail.com Mon Feb 8 10:50:55 2010 From: boblatest at googlemail.com (boblatest) Date: Mon, 8 Feb 2010 07:50:55 -0800 (PST) Subject: Create a backslash-escaped version of a string? References: Message-ID: <21d5019a-95ed-4c28-8c8e-8f2a6b9fc050@j31g2000yqa.googlegroups.com> On Feb 8, 12:28?pm, Chris Rebert wrote: > print a.encode("string-escape") How could I miss that? I was on that doc page already. Should have typed "/escape" in the browser ;-) Thanks, robert From gherron at islandtraining.com Mon Feb 8 11:02:54 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Feb 2010 08:02:54 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> Message-ID: <4B7035AE.2020500@islandtraining.com> Craig Berry wrote: > On Sun, Feb 7, 2010 at 22:26, Gary Herron wrote: > > >> Didn't I answer this already? >> > > If you did, for whatever reason I didn't see it; I just rechecked my > inbox to be sure. Thanks for doing so again! > > I assume, given the list we're on, that Freeglut can be used with > Python. I'll look into it. Thanks for the pointer! > > Yes, easily. PyOpenGL has bindings for all the procedures in GLUT/FREEGLUT. Just tell PyOpenGL to use the freeglut library instead, or even just copy freeglut (.dll or .so or whatever) over your existing glut library (glut32.dll or whatever). It really can serve as a binary drop in replacement. Gary Herron From james at agentultra.com Mon Feb 8 11:21:07 2010 From: james at agentultra.com (J Kenneth King) Date: Mon, 08 Feb 2010 11:21:07 -0500 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> <7xeikw2ivk.fsf@ruckus.brouhaha.com> Message-ID: <85zl3ju2a4.fsf@agentultra.com> Paul Rubin writes: > Stefan Behnel writes: >> Well, if multi-core performance is so important here, then there's a pretty >> simple thing the OP can do: switch to lxml. >> >> http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ > > Well, lxml is uses libxml2, a fast XML parser written in C, but AFAIK it > only works on well-formed XML. The point of Beautiful Soup is that it > works on all kinds of garbage hand-written legacy HTML with mismatched > tags and other sorts of errors. Beautiful Soup is slower because it's > full of special cases and hacks for that reason, and it is written in > Python. Writing something that complex in C to handle so much > potentially malicious input would be quite a lot of work to write at > all, and very difficult to ensure was really safe. Look at the many > browser vulnerabilities we've seen over the years due to that sort of > problem, for example. But, for web crawling, you really do need to > handle the messy and wrong HTML properly. If the difference is great enough, you might get a benefit from analyzing all pages with lxml and throwing invalid pages into a bucket for later processing with BeautifulSoup. From aahz at pythoncraft.com Mon Feb 8 11:22:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 08:22:40 -0800 Subject: threading+popen2 hang References: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> <2542cf60-a193-4087-a1fe-1d60ee13c630@v25g2000yqk.googlegroups.com> Message-ID: In article <2542cf60-a193-4087-a1fe-1d60ee13c630 at v25g2000yqk.googlegroups.com>, lofic wrote: >On 7 f=E9v, 17:00, a... at pythoncraft.com (Aahz) wrote: >> In article <188bfb67-3334-4325-adfc-3fa4d28f0... at d27g2000yqn.googlegroups= >.com>, >> lofic =A0 wrote: >>> >>>Works fine on RHEL5/python 2.4.3 >>>Hangs on RHEL4/python 2.3.4 >> >> Then use Python 2.4 -- surely you don't expect anyone to provide bugfixes >> for a release that's several years old? > >2.3 is the version provided with RHEL 4, which is still widely used in >production environments. Sometimes it is not so easy to shift to >another version in production systems. Believe me, I'm well aware of that (my last job was also stuck on 2.3). Nevertheless, the pool of people familiar with the minutiae of bugs for both Python 2.3 and 2.4 is dwindling daily, and your best recourse is intensive Googling. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From misceverything at gmail.com Mon Feb 8 11:37:38 2010 From: misceverything at gmail.com (T) Date: Mon, 8 Feb 2010 08:37:38 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> <811dd4e9-6eea-4c1f-a24b-ba0179e57f84@a13g2000vbf.googlegroups.com> Message-ID: On Feb 8, 1:28?am, Sean DiZazzo wrote: > On Feb 7, 4:57?pm, T wrote: > > > Thanks for the suggestions - ?I think my next step is to try running > > it under an admin user account, as you guys both mentioned. ?Alf - > > you're absolutely right, Microsoft has srvany.exe, which allows you to > > run any EXE as a Windows service. ?I've done this in the past, but > > it's more of a "hack"..so this go around (since I will be distributing > > this program), I wanted to go the more professional route..which, > > unfortunately, involves learning the "scum". :) ?I ?posted this to > > comp.os.ms-windows.programmer.win32, so we'll see if what the Win32 > > programmers have to say as well. ?Thanks again! > > I use windows services and they are very reliable. ?I would say though > that relying on plink.exe is much less reliable than either python or > the service that it is running under. > > Why not take a look at paramiko as the ssh client library? ?I think it > runs under windows. ?Also perhaps Twisted has something. ?Either way > would be light years ahead of using subprocess with plink. > > Just my thoughts. > > ~Sean I totally agree that it would be much more reliable to use a Python library for SSH - however, the program will need to execute other external binaries as well. So my goal at this point is to track down _why_ it's failing when running as a service. The actual command is as follows: C:\plink.exe -R 9999:127.0.0.1:2020 -batch -i C:\keyfile.ppk user at 10.10.10.1 I tried having subprocess.Popen run plink.exe by itself and piping output to file, and this worked - so I know it's at least executing plink.exe. Sorry, I realize this isn't truly just a Python-related question, but any help would be greatly appreciated! So far no help at comp.os.ms-windows.programmer.win32.. From jkrukoff at ltgc.com Mon Feb 8 11:43:10 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Mon, 08 Feb 2010 09:43:10 -0700 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <7xeikw2ivk.fsf@ruckus.brouhaha.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> <7xeikw2ivk.fsf@ruckus.brouhaha.com> Message-ID: <1265647390.10548.1804.camel@localhost.localdomain> On Mon, 2010-02-08 at 01:10 -0800, Paul Rubin wrote: > Stefan Behnel writes: > > Well, if multi-core performance is so important here, then there's a pretty > > simple thing the OP can do: switch to lxml. > > > > http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ > > Well, lxml is uses libxml2, a fast XML parser written in C, but AFAIK it > only works on well-formed XML. The point of Beautiful Soup is that it > works on all kinds of garbage hand-written legacy HTML with mismatched > tags and other sorts of errors. Beautiful Soup is slower because it's > full of special cases and hacks for that reason, and it is written in > Python. Writing something that complex in C to handle so much > potentially malicious input would be quite a lot of work to write at > all, and very difficult to ensure was really safe. Look at the many > browser vulnerabilities we've seen over the years due to that sort of > problem, for example. But, for web crawling, you really do need to > handle the messy and wrong HTML properly. > Actually, lxml has an HTML parser which does pretty well with the standard level of broken one finds most often on the web. And, when it falls down, it's easy to integrate BeautifulSoup as a slow backup for when things go really wrong (as J Kenneth King mentioned earlier): http://codespeak.net/lxml/lxmlhtml.html#parsing-html At least in my experience, I haven't actually had to parse anything that lxml couldn't handle yet, however. -- John Krukoff Land Title Guarantee Company From tjreedy at udel.edu Mon Feb 8 11:52:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Feb 2010 11:52:17 -0500 Subject: C/C++ Import In-Reply-To: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: On 2/7/2010 10:56 PM, 7H3LaughingMan wrote: > To make the background information short, I am trying to take a > program that uses Python for scripting and recompile it for Linux > since it originally was built to run on Win32. The program itself was > designed to be able to be compiled on Linux and someone made there on > release with source that added python scripting. After some issues I > got it to compile but now it is unable to import the files that it > needs. > > The program is running the following code... > PyImport_Import( PyString_FromString("python.PlayerManager") ); > > This is meant to import the file PlayerManager.py inside of the python > folder. However it throws the following Python Error (Gotten through > PyErr_Print()) > ImportError: No module named python.PlayerManager > > I am using 2.6.4 so I can't call it by the filename, does anyone know > how to do a proper import? Your 'python' package directory must be in a directory listed in sys.path. I would print that check. From misceverything at gmail.com Mon Feb 8 12:05:05 2010 From: misceverything at gmail.com (T) Date: Mon, 8 Feb 2010 09:05:05 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> Message-ID: <7c8003e9-5813-4891-bcc8-6e00e69740b2@c10g2000vbr.googlegroups.com> On Feb 8, 4:00?am, Duncan Booth wrote: > T wrote: > > Oops, this one was my fault - the object I was having the issues with > > was actually a shelve file, not a dictionary..so just re-assigning the > > variable isn't working, but re-writing the object to the shelve file > > does. ?So in this case, is there any way to just change a single > > value, or am I stuck rewriting the entry? > > Either open the shelve with writeback=True or rewrite the entry. > Rewriting the entry isn't hard: you can just re-use the same value: > > def changevalue(): > ? ? for key in mytest.keys(): > ? ? ? ? temp = mytest[key] > ? ? ? ? temp.param3 = "newvalue" > ? ? ? ? mytest[key] = temp > > If you really are changing every item in the shelve using writeback=True > will be much simpler, but if you are only changing a few then just tell the > shelve that you've updated them as above. > > -- > Duncan Boothhttp://kupuguy.blogspot.com Duncan - Thanks for your help. So each of the shelve entries I'm modifying look something like this: myshelve[key] = TestClassObject(param1, param2, param3, param4, param5, etc.). In this case, with quite a few parameters, would you suggest setting writeback=True and just modifying the needed value, or rewriting the entire entry? I have to admit the writeback option looks good, and if the TestClassObject format ever changes (i.e. if I ever change the order of the params), this particular function will be unchanged. However, I don't know what the performance hit would be in using it. From mrkafk at gmail.com Mon Feb 8 12:07:56 2010 From: mrkafk at gmail.com (mk) Date: Mon, 08 Feb 2010 18:07:56 +0100 Subject: Your beloved python features In-Reply-To: <037c8d60$0$1292$c3e8da3@news.astraweb.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: > >> Ethan Furman wrote: >> >>> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ > choose_python.pdf >>> >> Choose to get your difficult questions about threads in Python ignored. >> Oh well.. > > With an attitude like that, you're damn lucky if you don't get kill- > filed. It was SIX MINUTES since you posted your question about timers, > what did you expect? I didn't expect immediate answer to this particular question. I have repeatedly asked many questions about threads in the past, and IIRC every one of them was ignored. > > Threads are hard, and many people don't use them at all. You might never > get an answer, even without alienating people. Complaining after six DAYS > might be acceptable, if you do it with a sense of humour, but after six > minutes? Well, it's 4 days now. I would be happy to get 50% response rate. Apparently nobody is really using threads. regards, mk From phlip2005 at gmail.com Mon Feb 8 12:12:46 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 09:12:46 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Stefan Behnel wrote: > I don't read it that way. There's a huge difference between > > - generating HTML manually and validating (some of) it in a unit test > > and > > - generating HTML using a tool that guarantees correct HTML output > > the advantage of the second approach being that others have already done > all the debugging for you. Anyone TDDing around HTML or XML should use or fork my assert_xml() (from django-test-extensions). The current version trivially detects a leading tag and uses etree.HTML(xml); else it goes with the stricter etree.XML(xml). The former will not complain about the provided sample HTML. Sadly, the industry has such a legacy of HTML written in Notepad that well-formed (X)HTML will never be well-formed XML. My own action item here is to apply Stefan's parser_options suggestion to make the etree.HTML() stricter. However, a generator is free to produce arbitrarily restricted XML that avoids the problems with XHTML. It could, for example, push any Javascript that even dreams of using & instead of & out into .js files. So an assert_xml() hot-wired to process only XML - with the true HTML doctype - is still useful to TDD generated code, because its XPath reference will detect that you get the nodes you expect. -- Phlip http://c2.com/cgi/wiki?ZeekLand From python at mrabarnett.plus.com Mon Feb 8 12:31:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 17:31:13 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <4B704A61.7070405@mrabarnett.plus.com> Steven D'Aprano wrote: > On Mon, 08 Feb 2010 02:51:05 +0100, Alf P. Steinbach wrote: > >> Python passes pointers by value, just as e.g. Java does. > > How do I get a pointer in pure Python code (no ctypes)? I tried both > Pascal and C syntax (^x and *x), but both give syntax errors. > In Pascal it's x^. > For that matter, how do I get a pointer in Java code? > > If Python doesn't have pointers, then why are you talking about Python > passing pointers? It's a vacuous truth, like saying that Python passes > dinosaurs by name. > From python at mrabarnett.plus.com Mon Feb 8 12:33:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 17:33:45 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <4B704AF9.2030804@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Steve Holden: >> [...] >>>> Alf: >>>> >>>> This topic was discussed at great, nay interminable, length about a >>>> year >>>> ago. I'd appreciate it if you would search the archives and read what >>>> was said then rather than hashing the whole topic over again to >>>> nobody's >>>> real advantage. >>> Well that's my point, and thanks for backing me up on that :-): it's >>> very simple, and as demonstrated can be expressed in 10 words or less >>> (plus perhaps a terminology reference, as I did above), so all that >>> discussion and in particular the lengthy article at effbot serves as >>> obfuscation and nothing else. >>> >> Please don't assume I was trying to support you. Your remarks showed >> considerable ignorance of issue that were extremely nuanced. Whatever >> point you were trying to make was lost in your self-aggrandizing >> disrespect of Fredrik Lundh, a software engineer of some repute with a >> long history of contribution to Python. The fact that your post was >> basically a restatement of one of the several competing positions in >> that thread makes it no more right than any of the others. > > What on Earth are you babbling about? > > Perhaps next you'll drag in the Pope, saying I've shown him some > disrespect. > > News for you: the Pope ain't participating. > [snip] The Pope isn't (as far as we know) a Pythonista. From duncan.booth at invalid.invalid Mon Feb 8 12:57:45 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Feb 2010 17:57:45 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> <7c8003e9-5813-4891-bcc8-6e00e69740b2@c10g2000vbr.googlegroups.com> Message-ID: T wrote: > Duncan - Thanks for your help. So each of the shelve entries I'm > modifying look something like this: myshelve[key] > TestClassObject(param1, param2, param3, param4, param5, etc.). In > this case, with quite a few parameters, would you suggest setting > writeback=True and just modifying the needed value, or rewriting the > entire entry? I have to admit the writeback option looks good, and if > the TestClassObject format ever changes (i.e. if I ever change the > order of the params), this particular function will be unchanged. > However, I don't know what the performance hit would be in using it. Only you know your data and pattern of use. Try a few tests to get a feel of the trade-offs between explicitly flagging items as changed or using writeback=True. From phlip2005 at gmail.com Mon Feb 8 13:16:22 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 10:16:22 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <5e67584b-2421-4254-addf-b4a355836a20@b9g2000pri.googlegroups.com> and the tweak is: parser = etree.HTMLParser(recover=False) return etree.HTML(xml, parser) That reduces tolerance. The entire assert_xml() is (apologies for wrapping lines!): def _xml_to_tree(self, xml): from lxml import etree self._xml = xml try: if ' 0, xpath + ' not found in ' + self._xml) node = nodes[0] if kw.get('verbose', False): self.reveal_xml(node) # "here have ye been? What have ye seen?"--Morgoth return node def reveal_xml(self, node): 'Spews an XML node as source, for diagnosis' from lxml import etree print etree.tostring(node, pretty_print=True) # CONSIDER does pretty_print work? why not? def deny_xml(self, xml, xpath): 'Check that a given extent of XML or HTML does not contain a given XPath' tree = self._xml_to_tree(xml) nodes = tree.xpath(xpath) self.assertEqual(0, len(nodes), xpath + ' should not appear in ' + self._xml) From deets at nospam.web.de Mon Feb 8 14:04:19 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 08 Feb 2010 20:04:19 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <7tb5hlF3nmU1@mid.uni-berlin.de> Am 08.02.10 02:51, schrieb Alf P. Steinbach: > * Chris Rebert: >> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>> Ok, just looking for a sanity check here, or maybe something I'm >>> missing. I have a class Test, for example: >>> >>> class Test: >>> def __init__(self, param1, param2, param3): >>> self.param1 = param1 >>> self.param2 = param2 >>> self.param3 = param3 >>> >>> Next, I have a dictionary mytest that contains instances of Test. If >>> I want to modify one of the Test instances within my dictionary, I >>> have to rewrite the entire entry, correct (since Python passes by >>> value, not reference)? >> >> Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> of what Python does use. > > Hm. While most everything I've seen at effbot.org has been clear and to > the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) Or perhaps some more words to > point out that in the Java language spec those reference values are > called pointers, but that this terminology isn't (apparently) used for > Python, and isn't even well known among Java programmers. But that's > just one extra little para. > > One just has to be clear about exactly what it is that's passed by value. > > Not Python objects, but references (pointers) to them, the id(o) values. Whao. You just needed 10 words, plus a paragraph to explain something in terms of a spec that's just about 600 pages strong. Amazing display of conciseness, and certainly the most valuable thing for some programming newbie to work with. Thanks! Diez From alfps at start.no Mon Feb 8 14:10:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 20:10:00 +0100 Subject: Modifying Class Object In-Reply-To: <7tb5hlF3nmU1@mid.uni-berlin.de> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: > Am 08.02.10 02:51, schrieb Alf P. Steinbach: >> * Chris Rebert: >>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>> Ok, just looking for a sanity check here, or maybe something I'm >>>> missing. I have a class Test, for example: >>>> >>>> class Test: >>>> def __init__(self, param1, param2, param3): >>>> self.param1 = param1 >>>> self.param2 = param2 >>>> self.param3 = param3 >>>> >>>> Next, I have a dictionary mytest that contains instances of Test. If >>>> I want to modify one of the Test instances within my dictionary, I >>>> have to rewrite the entire entry, correct (since Python passes by >>>> value, not reference)? >>> >>> Incorrect; Python uses neither. See >>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>> of what Python does use. >> >> Hm. While most everything I've seen at effbot.org has been clear and to >> the point, that particular article reads like a ton of obfuscation. >> >> Python passes pointers by value, just as e.g. Java does. >> >> There, it needed just 10 words or so. :-) Or perhaps some more words to >> point out that in the Java language spec those reference values are >> called pointers, but that this terminology isn't (apparently) used for >> Python, and isn't even well known among Java programmers. But that's >> just one extra little para. >> >> One just has to be clear about exactly what it is that's passed by value. >> >> Not Python objects, but references (pointers) to them, the id(o) values. > > Whao. You just needed 10 words, plus a paragraph to explain something in > terms of a spec that's just about 600 pages strong. Amazing display of > conciseness, and certainly the most valuable thing for some programming > newbie to work with. Thanks! I apologize for assuming that "pointer" is a known word to [c.l.p.] denizens. But, if it can help, although for clarity I had to provide a concrete reference, you don't need to read the complete Java language spec to understand that word. Just Google it. Cheers & hth., - ALf From gagsl-py2 at yahoo.com.ar Mon Feb 8 14:21:15 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 08 Feb 2010 16:21:15 -0300 Subject: Import question References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> <5d1b76f61002080137o6e3f9a1fjdab8bcf8d3959faf@mail.gmail.com> Message-ID: En Mon, 08 Feb 2010 06:37:53 -0300, Andrew Degtiariov escribi?: > 2010/2/6 Gabriel Genellina >> En Fri, 05 Feb 2010 13:21:47 -0300, Andrew Degtiariov >> escribi?: >> >> >>> Code of our project has split into several packages and we deploy the >>> project using buildout. >>> All worked fine until I need to dynamically inspect python modules. >> Entirely by luck, I'd say :) >> >> >> ????project.api.config >>> ? ????project >>> ? ? ????api >>> ? ? ????config >>> ? ? ????settings >>> ? ????project.api.config.egg-info >>> ????project.api.contacts >>> ? ????project >>> ? ? ????api >>> ? ? ????contacts >>> ? ? ????importer >>> ? ? ????views >>> ? ????project.api.contacts.egg-info >>> > If someone is interesting - __import__ works but imp doesn't. > In my example: >>>> m = __import__('project.api.config') >>>> m > 'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'> >>>> m.api > 'c:\users\ad\project\src\project.api.contacts\project\api\__init__.pyc'> >>>> m.api.config > from'c:\users\ad\project\src\project.api.config\project\api\config\__init__.pyc'> > > Please note that the m and m.api pointed to first installing package with > namespace project.api but m.api.config have pointed to the proper file. > > And releasing code with several distributions it is one of goals of > Distribute. And you might look to pypi for... zope. There is lot of > package > which names starts from "zope." > It's really convenient Those are called namespace packages. Zope and Plone (ab)use them extensively. The intended usage is to break up a big, monolithic package [0] in parts that can be distributed independently. To implement a namespace package, you need an empty __init__.py file with only these lines [1]: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) But think carefully if you really need namespace packages; they solve a specific problem, aren't a general purpose technique. See [2] for a discussion. [0] Think of a huge behemoth with a "Z O P E" sign on both sides :) [1] http://docs.python.org/library/pkgutil.html [2] http://weblion.psu.edu/news/are-we-overusing-namespace-packages -- Gabriel Genellina From db3l.net at gmail.com Mon Feb 8 14:25:09 2010 From: db3l.net at gmail.com (David Bolen) Date: Mon, 08 Feb 2010 14:25:09 -0500 Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: T writes: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. Specifically, the > program will call plink.exe to create a reverse SSH tunnel. Right now > I'm using subprocess.Popen to do so. When I run it interactively via > an admin account, all is well. However, when I'm running it via > service, no luck. I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. What > would be the best way around this? Thanks! The LocalSystem account is not, if I recall correctly, permitted to access the network. You'll have to install the service to run under some other account that has appropriate access to the network. -- David From olivier.darge at gmail.com Mon Feb 8 14:28:53 2010 From: olivier.darge at gmail.com (OdarR) Date: Mon, 8 Feb 2010 11:28:53 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> On 8 f?v, 11:57, Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > ? ? xyz(file) > elif file.endswith('abc'): > ? ? abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? and with eval(), did you try ? import sys def functext(): print "texte" def funcdoc(): print "doc" def funcabc(): print "abc" if __name__ == "__main__": #replace filename with suitable value filename = sys.argv[1].split('.')[1] try: eval('func' + filename + '()') except: print 'error' From gherron at islandtraining.com Mon Feb 8 14:47:40 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Feb 2010 11:47:40 -0800 Subject: use strings to call functions In-Reply-To: <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <4B706A5C.2080506@islandtraining.com> OdarR wrote: > On 8 f?v, 11:57, Klaus Neuner wrote: > >> Hello, >> >> I am writing a program that analyzes files of different formats. I >> would like to use a function for each format. Obviously, functions can >> be mapped to file formats. E.g. like this: >> >> if file.endswith('xyz'): >> xyz(file) >> elif file.endswith('abc'): >> abc(file) >> >> ... >> >> Yet, I would prefer to do something of the following kind: >> >> func = file[-3:] >> apply_func(func, file) >> >> Can something of this kind be done in Python? >> I may have missed a bit of this thread -- so I have to ask: Has anyone mentioned using getattr yet? It's a way of looking up *any* attribute using a string to specify the name. Like this for your particular example: class Functions: # This could be a module instead of a class def xyz(...): ... def abc(...): ... ... and so on ... ext = os.path.splitext(file) # Parses out the extension fn = getattr(Functions, ext) # Lookup the correct function fn(...) # and call it Gary Herron From gnewsg at gmail.com Mon Feb 8 15:04:12 2010 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 8 Feb 2010 12:04:12 -0800 (PST) Subject: setuptools/distutil and pywin32 Message-ID: <04946f8f-46c0-4e90-b0cb-26a44e6c0323@r24g2000yqd.googlegroups.com> Hi, I have a program which requires pywin32 as a dependancy and I'd like to make setuptools automatically retrieve it from internet and install it. My setup.py script looks like this: from setuptools import setup setup( ... ... install_requires = ['pywin32'] ... ) When I run setup.py install I get this error: Processing dependencies for psutil==0.1.3 Searching for pywin32 Reading http://pypi.python.org/simple/pywin32/ Reading http://sf.net/projects/pywin32 Reading http://sourceforge.net/project/showfiles.php?group_id=78018 Best match: pywin32 214 Downloading http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win32-py2.6.exe download Processing download error: Not a recognized archive type: c:\users\giampa~1\appdata\local \temp\easy_ install-xefzrd\download I've googled a lot about this but it seems that as of right now it's just not possible to install pywin32 via setuptools but it seems pretty strange to me as it is a very important third party module. Can someone confirm to me that there's no way to solve this problem? Thanks in advance, ---- Giampaolo http://code.google.com/p/psutil http://code.google.com/p/pyftpdlib From debatem1 at gmail.com Mon Feb 8 15:06:26 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Feb 2010 15:06:26 -0500 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: On Mon, Feb 8, 2010 at 12:07 PM, mk wrote: > Steven D'Aprano wrote: >> >> On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: >> >>> Ethan Furman wrote: >>> >>>> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ >> >> choose_python.pdf >>>> >>> Choose to get your difficult questions about threads in Python ignored. >>> Oh well.. >> >> With an attitude like that, you're damn lucky if you don't get kill- >> filed. It was SIX MINUTES since you posted your question about timers, >> what did you expect? > > I didn't expect immediate answer to this particular question. I have > repeatedly asked many questions about threads in the past, and IIRC every > one of them was ignored. > >> >> Threads are hard, and many people don't use them at all. You might never >> get an answer, even without alienating people. Complaining after six DAYS >> might be acceptable, if you do it with a sense of humour, but after six >> minutes? > > Well, it's 4 days now. I would be happy to get 50% response rate. Apparently > nobody is really using threads. > > regards, > mk I use threads. Geremy Condra From pwashington85 at gmail.com Mon Feb 8 15:16:24 2010 From: pwashington85 at gmail.com (spike) Date: Mon, 8 Feb 2010 12:16:24 -0800 (PST) Subject: Does anyone have a Python Logic Map/Flow Chart? (Example Provided) Message-ID: <05a9edbc-63e9-4155-833c-15cf5dacd7ea@p13g2000pre.googlegroups.com> Has anyone been able to come across a Python logic map or flow chart? An example can be seen here on the right: http://en.wikipedia.org/wiki/Usenet This would be very helpful for users. From pwashington85 at gmail.com Mon Feb 8 15:20:15 2010 From: pwashington85 at gmail.com (spike) Date: Mon, 8 Feb 2010 12:20:15 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) Message-ID: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Has anyone been able to come across a Python logic map or Python logic flow chart? An example can be seen on the right under History: http://en.wikipedia.org/wiki/Usenet#History This would be very helpful for all users. From invalid at gmail.com Mon Feb 8 15:36:43 2010 From: invalid at gmail.com (Dave Peterson) Date: Mon, 8 Feb 2010 12:36:43 -0800 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples Message-ID: Page 7: Very first example doesn't compile: syntax error Pate 11: 2nd example: syntax error Page 12, printing digits: syntax error Page 13, printing a number: syntax error page 14, statements: syntax error From benjamin.kaplan at case.edu Mon Feb 8 15:45:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 8 Feb 2010 15:45:05 -0500 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples In-Reply-To: References: Message-ID: On Mon, Feb 8, 2010 at 3:36 PM, Dave Peterson wrote: > Page 7: Very first example doesn't compile: syntax error > Pate 11: 2nd example: syntax error > Page 12, printing digits: syntax error > Page 13, printing a number: syntax error > page 14, statements: syntax error > Let me guess, you're using Python 3.1. That book was written for Python 2.x and there were several backwards-incompatible changes. For instance, print was changed from a statement to a function. Which is why the "Hello, World" doesn't work any more. If you want to use the older books, use Python 2.6 instead. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From robert.kern at gmail.com Mon Feb 8 15:52:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Feb 2010 14:52:20 -0600 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples In-Reply-To: References: Message-ID: On 2010-02-08 14:36 PM, Dave Peterson wrote: > Page 7: Very first example doesn't compile: syntax error > Pate 11: 2nd example: syntax error > Page 12, printing digits: syntax error > Page 13, printing a number: syntax error > page 14, statements: syntax error This book was written for the 2.x versions of Python. Are you using Python 3.1? Python changed some of its syntax for version 3.0, notably print "Hello, world!" becomes print("Hello, world!") This accounts for all of the SyntaxErrors that you are seeing. The examples aren't broken for the version of Python it is teaching. You may want to try _Dive Into Python 3_ to learn about Python 3 in particular: http://diveintopython3.org/ -- 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 andrej.mitrovich at gmail.com Mon Feb 8 15:53:00 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 8 Feb 2010 12:53:00 -0800 (PST) Subject: Awful book warning: How to think like a (Python) programmer - non-working examples References: Message-ID: The book covers Python 2.x syntax. You might have downloaded Python 3.1, which has different syntax then Python 2.x. From what I can tell, the first example on page 7 is ">>> print 1 + 1". Try issuing this command: print(1 + 1) If everything goes well, and you get '2' as the answer, then you're probably using Python 3.x. You will have to download the Python 2.x binaries from the Python website, install Python 2.x, and try the example from the book again. From vim at aryehleib.com Mon Feb 8 15:54:15 2010 From: vim at aryehleib.com (Aryeh Leib Taurog) Date: Mon, 8 Feb 2010 12:54:15 -0800 (PST) Subject: glibc detected double free or corruption Message-ID: <2e4cd5eb-decf-43a9-8d2e-8d3b99134d50@19g2000yql.googlegroups.com> I'm encountering the following error on my fastcgi web server and would greatly appreciate ANY pointers for debugging/fixing this problem. *** glibc detected *** /usr/bin/python2.5: double free or corruption (fasttop): 0x08b47d60 *** If I don't set MALLOC_CHECK_ then the server just hangs and the above message appears in the fastcgi error log. With MALLOC_CHECK_=0 I get an error message in the browser instead. I'm using the following components (on a shared hosting account): Debian lenny 64 bit Python 2.5.2 lighttpd 1.4.19 Django 1.1.1 latest flup (today's hg tip, flup-server-ae5fe54fba18) postgresql 8.3.9 psycopg2 2.0.13 What's interesting about the problem is it seems to happen only when new fcgi processes are spawned and only when a db query is made. That is, the frequency of the problem corresponds exactly with the maxrequests setting on my fcgi process. If I set maxrequests to 1 then I get this error for each request that hits the database. If I set it to 3 then I get the error with every third request, if that request hits the database. If I put Django into DEBUG and set MALLOC_CHECK_=0 then I get the following error with traceback: Exception Type: OperationalError Exception Value: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. Exception Location: /home/altaurog/django/db/backends/util.py in execute, line 19 Regardless of which url/view I request, the exception always is raised on a sql execute statement. --- Aryeh Leib Taurog From Martin.Drautzburg at web.de Mon Feb 8 15:59:18 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Mon, 08 Feb 2010 21:59:18 +0100 Subject: Ternary plus Message-ID: <1475043.2616QT5JLn@beaureve.gmx.net> Just for the hell of it ... I can easily define __plus__() with three parameters. If the last one is optional the + operation works as expected. Is there a way to pass the third argument to "+" From vinay_sajip at yahoo.co.uk Mon Feb 8 16:13:33 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 8 Feb 2010 13:13:33 -0800 (PST) Subject: Simulating logging.exception with another traceback References: <0c13d3f7-addf-4972-91c3-6f41fadfb2b5@u26g2000yqm.googlegroups.com> Message-ID: <3512c1a4-01e3-449d-8e48-e673e668bb17@u26g2000yqm.googlegroups.com> On Feb 7, 11:22?am, Joan Miller wrote: > I would want to get the output from `logging.exception` but with > traceback from the caller function (I've already all that > information). > > This would be the error withlogging.exception: > -------------------- > ERROR: > ? PipeError('/bin/ls -l | ?', 'no command after of pipe') > Traceback (most recent call last): > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > 160, in __call__ > ? ? raise PipeError(command, 'no command after of pipe') > PipeError: ('/bin/ls -l | ?', 'no command after of pipe') > -------------------- > > And I've trying it with: > -------------------- > message = "File \"{0}\", line {1}, in {2}\n\n ?{3}".format( > ? ? ? ? ? ? ? ? file, line, function, caller)logging.error(message) > > ERROR: > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > ? 163, in __call__ ? ?return self.throw(PipeError, command, 'no > ? command after of pipe') > -------------------- > > Could be used `logging.LogRecord` [1] to get it? How? > > [1]http://docs.python.org/library/logging.html#logging.LogRecord Sorry, Joan, I don't understand your question. Can you create a short script which throws an exception, and show exactly how you want it formatted? The logger.exception method does the same as logger.error, except that it prints exception trace information and is intended to be called from exception handling clauses. You can format exceptions how you like by subclassing Formatter and overriding formatException. Regards, Vinay Sajip From dmalcolm at redhat.com Mon Feb 8 16:14:08 2010 From: dmalcolm at redhat.com (David Malcolm) Date: Mon, 08 Feb 2010 16:14:08 -0500 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples In-Reply-To: References: Message-ID: <1265663648.25625.233.camel@brick> On Mon, 2010-02-08 at 12:53 -0800, Andrej Mitrovic wrote: > The book covers Python 2.x syntax. > > You might have downloaded Python 3.1, which has different syntax then > Python 2.x. From what I can tell, the first example on page 7 is ">>> > print 1 + 1". > > Try issuing this command: > print(1 + 1) > > If everything goes well, and you get '2' as the answer, then you're > probably using Python 3.x. You will have to download the Python 2.x > binaries from the Python website, install Python 2.x, and try the > example from the book again. Sorry to nitpick; the main thrust of the above sounds correct, in that: print 1 + 1 works in Python 2 but fails in Python 3, but, a minor correction, note that: print(1+1) does work in Python 2 as well as in Python 3; the parentheses are treated (in the former) as denoting grouping of a subexpression, rather than function invocation (in the latter): Python 2.6.2 (r262:71600, Jan 25 2010, 13:22:47) [GCC 4.4.2 20100121 (Red Hat 4.4.2-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print(1+1) 2 This can be useful if you're trying to write short fragments of code that work with both. Look at the startup message, or run this command, which should work on both python2 and python3: import sys; print(sys.version) Hope this is helpful Dave From andrej.mitrovich at gmail.com Mon Feb 8 16:27:00 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 8 Feb 2010 13:27:00 -0800 (PST) Subject: Awful book warning: How to think like a (Python) programmer - non-working examples References: Message-ID: On Feb 8, 10:14?pm, David Malcolm wrote: > On Mon, 2010-02-08 at 12:53 -0800, Andrej Mitrovic wrote: > > The book covers Python 2.x syntax. > > > You might have downloaded Python 3.1, which has different syntax then > > Python 2.x. From what I can tell, the first example on page 7 is ">>> > > print 1 + 1". > > > Try issuing this command: > > print(1 + 1) > > > If everything goes well, and you get '2' as the answer, then you're > > probably using Python 3.x. You will have to download the Python 2.x > > binaries from the Python website, install Python 2.x, and try the > > example from the book again. > > Sorry to nitpick; the main thrust of the above sounds correct, in that: > ? ? print 1 + 1 > works in Python 2 but fails in Python 3, but, a minor correction, note > that: > ? ? print(1+1) > does work in Python 2 as well as in Python 3; the parentheses are > treated (in the former) as denoting grouping of a subexpression, rather > than function invocation (in the latter): > > Python 2.6.2 (r262:71600, Jan 25 2010, 13:22:47) > [GCC 4.4.2 20100121 (Red Hat 4.4.2-28)] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> print(1+1) > > 2 > > This can be useful if you're trying to write short fragments of code > that work with both. > > Look at the startup message, or run this command, which should work on > both python2 and python3: > ? import sys; print(sys.version) > > Hope this is helpful > Dave Oops, you're right. I'm used to Python 3 syntax so I'm only aware of some basic differences. :) From aahz at pythoncraft.com Mon Feb 8 16:28:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 13:28:03 -0800 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: In article <0efe23a6-b16d-4f92-8bc0-12d056bf599d at z26g2000yqm.googlegroups.com>, OdarR wrote: > >and with eval(), did you try ? WARNING: eval() is almost always the wrong answer to any question -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From robert.kern at gmail.com Mon Feb 8 16:28:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Feb 2010 15:28:54 -0600 Subject: Ternary plus In-Reply-To: <1475043.2616QT5JLn@beaureve.gmx.net> References: <1475043.2616QT5JLn@beaureve.gmx.net> Message-ID: On 2010-02-08 14:59 PM, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" No. -- 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 gherron at islandtraining.com Mon Feb 8 16:35:10 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Feb 2010 13:35:10 -0800 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <4B70838E.4070700@islandtraining.com> spike wrote: > Has anyone been able to come across a Python logic map or Python logic > flow chart? > > An example can be seen on the right under History: > http://en.wikipedia.org/wiki/Usenet#History > > This would be very helpful for all users. > Huh??? What aspect of Python were you thinking of mapping out? Your example us a bad ascii art graph of -- I've no clue what? Gary Herron From olivier.darge at gmail.com Mon Feb 8 16:39:33 2010 From: olivier.darge at gmail.com (OdarR) Date: Mon, 8 Feb 2010 13:39:33 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> On 8 f?v, 22:28, a... at pythoncraft.com (Aahz) wrote: > In article <0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, > > OdarR ? wrote: > > >and with eval(), did you try ? > > WARNING: eval() is almost always the wrong answer to any question warning : it works ! another question ? > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > import antigravity From andrew.degtiariov at gmail.com Mon Feb 8 16:39:42 2010 From: andrew.degtiariov at gmail.com (Andrew Degtiariov) Date: Mon, 8 Feb 2010 23:39:42 +0200 Subject: Import question In-Reply-To: References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> <5d1b76f61002080137o6e3f9a1fjdab8bcf8d3959faf@mail.gmail.com> Message-ID: <5d1b76f61002081339u5648906bp282e5e7bddde1760@mail.gmail.com> Those are called namespace packages. Zope and Plone (ab)use them > extensively. The intended usage is to break up a big, monolithic package > [0] in parts that can be distributed independently. To implement a > namespace package, you need an empty __init__.py file with only these > lines [1]: > > from pkgutil import extend_path > __path__ = extend_path(__path__, __name__) > > But think carefully if you really need namespace packages; they solve a > specific problem, aren't a general purpose technique. See [2] for a > discussion. > > [0] Think of a huge behemoth with a "Z O P E" sign on both sides :) > [1] http://docs.python.org/library/pkgutil.html > [2] http://weblion.psu.edu/news/are-we-overusing-namespace-packages > > Hm.. We are using pkg_resources.declare_namespace(__name__) but I think pkgutil is much better. And we are using buildout so the omelette might help me. Link [2] very interesting. Thank you, Gabrial. -- Andrew Degtiariov DA-RIPE -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Mon Feb 8 16:40:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Feb 2010 10:40:33 +1300 Subject: The Case For Do-Once References: Message-ID: In message , Lawrence D'Oliveiro wrote: > The basic control flow is this: > * Unconditionally initialize all dynamic storage to nil > * Do the main body of the code, aborting in any error > * Regardless of success or failure of the above, dispose of all > allocated dynamic storage, using disposal calls which turn into > noops if passed pointers that are already nil. For more examples, see the spuhelper.c module here . From davodavo2 at gmail.com Mon Feb 8 16:47:52 2010 From: davodavo2 at gmail.com (Davo) Date: Mon, 8 Feb 2010 13:47:52 -0800 (PST) Subject: Read PGM's with more than 256 range in PIL1.1.7 Message-ID: <24a311e0-963e-43a5-9d8f-3a573dbf5fe2@m35g2000prh.googlegroups.com> I have a PGM format image file with 4096 range. When I reads it with PIL, I get an image with 8-bit values and alternate columns are zero. Does PIL support reading and writing PGM's with more than 8-bits? Davo From mensanator at aol.com Mon Feb 8 17:31:48 2010 From: mensanator at aol.com (Mensanator) Date: Mon, 8 Feb 2010 14:31:48 -0800 (PST) Subject: Stephen -- Bruce? References: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> <4b6fd308$0$6722$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <54742c54-bf2d-4228-ad7c-d1dca1858775@m16g2000yqc.googlegroups.com> On Feb 8, 3:02?am, Stefan Behnel wrote: > Mensanator, 05.02.2010 00:36: > > > On Feb 4, 5:13 pm, "Alf P. Steinbach" wrote: > >> What's this about all the Stephen'ses here? > > >> Shouldn't it be Bruce? > > > Of course. We just call everyone Stephen to avoid confusion. > > Some people even manage to adapt the spellings accordingly. > > Stefan You appear to be confused. From aahz at pythoncraft.com Mon Feb 8 17:36:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 14:36:47 -0800 Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: In article , Sean DiZazzo wrote: >On Feb 3, 6:08=A0pm, alex23 wrote: >> >> There was also a PEP with another possible implementation: >> http://www.python.org/dev/peps/pep-0355/ > >Why did Path() get rejected? Is it the idea itself, or just the >approach that was used? What are the complaints? You should search for the discussiona around it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Mon Feb 8 17:43:46 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 14:43:46 -0800 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: In article <5790c33c-13d0-4596-91b0-b3c9aeebf637 at f8g2000yqn.googlegroups.com>, OdarR wrote: >On 8 f=E9v, 22:28, a... at pythoncraft.com (Aahz) wrote: >> In article <0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups= >.com>, >> OdarR =A0 wrote: >>> >>>and with eval(), did you try ? >> >> WARNING: eval() is almost always the wrong answer to any question > >warning : it works ! Works for what? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From phlip2005 at gmail.com Mon Feb 8 17:46:36 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 14:46:36 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: <9a2b87ca-abd4-4d5d-9fca-9ebee8a44730@m35g2000prh.googlegroups.com> On Feb 8, 2:36?pm, a... at pythoncraft.com (Aahz) wrote: > >> There was also a PEP with another possible implementation: > >>http://www.python.org/dev/peps/pep-0355/ > > >Why did Path() get rejected? ?Is it the idea itself, or just the > >approach that was used? ?What are the complaints? > > You should search for the discussiona around it. I, OTOH, am burning rubber with Python 2.6.1, so leading edge concerns are not mine - yet! I went with this version, generously ripped out & plopped into our project: # URL: http://www.jorendorff.com/articles/python/path # Author: Jason Orendorff (and others - see the url!) # Date: 7 Mar 2004 class path(_base): """ Represents a filesystem path. """ Gods bless http://www.google.com/codesearch, huh?! -- Phlip http://c2.com/cgi/wiki?ZeekLand From python at mrabarnett.plus.com Mon Feb 8 17:50:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 22:50:02 +0000 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B70951A.90805@mrabarnett.plus.com> geremy condra wrote: > On Mon, Feb 8, 2010 at 12:07 PM, mk wrote: >> Steven D'Aprano wrote: >>> On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: >>> >>>> Ethan Furman wrote: >>>> >>>>> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ >>> choose_python.pdf >>>> Choose to get your difficult questions about threads in Python ignored. >>>> Oh well.. >>> With an attitude like that, you're damn lucky if you don't get kill- >>> filed. It was SIX MINUTES since you posted your question about timers, >>> what did you expect? >> I didn't expect immediate answer to this particular question. I have >> repeatedly asked many questions about threads in the past, and IIRC every >> one of them was ignored. >> >>> Threads are hard, and many people don't use them at all. You might never >>> get an answer, even without alienating people. Complaining after six DAYS >>> might be acceptable, if you do it with a sense of humour, but after six >>> minutes? >> Well, it's 4 days now. I would be happy to get 50% response rate. Apparently >> nobody is really using threads. >> >> regards, >> mk > > I use threads. > So do I, where appropriate. From aahz at pythoncraft.com Mon Feb 8 17:50:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 14:50:21 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: In article <28c6967f-7637-4823-aee9-15487e1ce98b at o28g2000yqh.googlegroups.com>, Julian wrote: > >I want to design a poster for an open source conference, the local >usergroup will have a table there, and in the past years there were >some people that came to the python-table just to ask "why should I >use python?". Readability -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Mon Feb 8 18:24:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 15:24:01 -0800 Subject: Building a multiline string References: Message-ID: In article , lallous wrote: > >x = ( >"line1" # can use comments >"line2" >"line3" >) You should indent the second and following lines (I changed the name to "xyz" to make clear that the following lines use a regular Python indent rather than lining up under the open paren): xyz = ( "line1" # can use comments "line2" "line3" ) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at REMOVE-THIS-cybersource.com.au Mon Feb 8 18:46:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 23:46:47 GMT Subject: ANN: obfuscate Message-ID: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> I am pleased to announce the first public release of obfuscate 0.2.2a. http://pypi.python.org/pypi/obfuscate/0.2.2a obfuscate is a pure-Python module providing classical encryption algorithms suitable for obfuscating and unobfuscating text. obfuscate includes the following ciphers: - Caesar, rot13, rot5, rot18, rot47 - atbash - Playfair, Playfair6 and Playfair16 - Railfence (encryption only) - Keyword - Affine - Vigenere - frob (xor) and others. DISCLAIMER: obfuscate is not cryptographically strong, and should not be used where high security is required. (The ciphers provided in obfuscate may have been state of the art centuries ago, but should not be used where strong encryption is required. obfuscate is released under the MIT licence. Requires Python 2.5 or 2.6. -- Steven D'Aprano From pavlovevidence at gmail.com Mon Feb 8 19:26:18 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 16:26:18 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> On Feb 4, 7:10?pm, Sean DiZazzo wrote: > On Feb 3, 6:08?pm, alex23 wrote: > > > > > On Feb 4, 8:47?am, Phlip wrote: > > > > Yes, calling os.path.walk() and os.path.join() all the time on raw > > > strings is fun, but I seem to recall from my Ruby days a class called > > > Pathname, which presented an object that behaved like a string at > > > need, and like a filesystem path at need. path + 'folder' would > > > call .join() and insert the / correctly, for example. > > > > What's the best equivalent in Python-land? > > > It's no longer supported, but the 3rd party 'path' module used to be > > the go-to module for this: > > > >>> from path import path > > > C:\Python26\lib\site-packages\path.py:32: DeprecationWarning: the md5 > > module is deprecated; use hashlib instead > > ? import sys, warnings, os, fnmatch, glob, shutil, codecs, md5>>> c = path('C:\\') > > >>> c.listdir() > > > [path(u'C:\\AUTOEXEC.BAT'), path(u'C:\\boot.ini'), ...]>>> (c + 'python26').listdir() > > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > > \python26\\DLLs'), ...]>>> (c / 'python26').listdir() > > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > > \python26\\DLLs'), ...] > > > I've hand edited the results for brevity... > > > The module could do with some TLC to bring it up to date, but warning > > aside it still seems to work fine under 2.6. > > > (From memory, I think the original author gave up when it became clear > > it would never be integrated into the standard lib[1], which is a > > shame, I think there's scope for a pathtools addition to the lib that > > provides this level of convenience...) > > > There was also a PEP with another possible implementation:http://www.python.org/dev/peps/pep-0355/ > > > Hope this helps. > > It's too bad that something like this can't be agreed to. ?I used a > homegrown module like this for a couple of years in my early days with > python. ?It was great, but I didn't know enough at the time to make it > really useful. > > Why did Path() get rejected? ?Is it the idea itself, or just the > approach that was used? ?What are the complaints? I don't know if it was the reason it was rejected, but a seriously divisive question is whether the path should be a subset of string. Under ordinary circumstances it would be a poor choice for inheritance (only a few string methods would be useful fot a pathname), but some people were fiercely adamant that paths should be passable to open() as-in (without having to explicity convert to string). IIRC, the guy who maintained path wavered between subclassing and not subclassing str. I don't remember if the idea of modifying open to accept path objects came up. Carl Banks From lists at cheimes.de Mon Feb 8 19:29:01 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 09 Feb 2010 01:29:01 +0100 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B70AC4D.6040008@cheimes.de> Steven D'Aprano schrieb: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) Nice work! Your work should be interesting for everybody who has read Simon Sing's "The Code Book: The Science of Secrecy from Ancient Egypt to Quantum". Christian From debatem1 at gmail.com Mon Feb 8 19:37:52 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Feb 2010 19:37:52 -0500 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: On Mon, Feb 8, 2010 at 6:46 PM, Steven D'Aprano wrote: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > ?- Caesar, rot13, rot5, rot18, rot47 > ?- atbash > ?- Playfair, Playfair6 and Playfair16 > ?- Railfence (encryption only) > ?- Keyword > ?- Affine > ?- Vigenere > ?- frob (xor) > > and others. > > DISCLAIMER: obfuscate is not cryptographically strong, and should not be > used where high security is required. (The ciphers provided in obfuscate > may have been state of the art centuries ago, but should not be used > where strong encryption is required. > > obfuscate is released under the MIT licence. > > Requires Python 2.5 or 2.6. > > > -- > Steven D'Aprano > -- > http://mail.python.org/mailman/listinfo/python-list > Nice! Maybe someday you can extend it with a pen-and-paper signature scheme ;) Geremy Condra From alfps at start.no Mon Feb 8 19:44:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 01:44:35 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * alex23: > "Alf P. Steinbach" wrote: >> Hm. While most everything I've seen at effbot.org has been clear and to the >> point, that particular article reads like a ton of obfuscation. > > Must. Resist. Ad hominem. > >> Python passes pointers by value, just as e.g. Java does. >> >> There, it needed just 10 words or so. :-) > > 10 words _plus_ an understanding of Java. No, one only needs an understanding of "pointer". "Pointer" is a mostly language independent concept. The reference to the Java language spec, where that term is used for this, was just an unsuccessful attempt to keep out word-play arguments based on the incompatibility of some incompatible meaning of "pointer"... Cheers & hth., - Alf From sccolbert at gmail.com Mon Feb 8 20:08:00 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 8 Feb 2010 20:08:00 -0500 Subject: Read PGM's with more than 256 range in PIL1.1.7 In-Reply-To: <24a311e0-963e-43a5-9d8f-3a573dbf5fe2@m35g2000prh.googlegroups.com> References: <24a311e0-963e-43a5-9d8f-3a573dbf5fe2@m35g2000prh.googlegroups.com> Message-ID: <7f014ea61002081708w362fc0ccr26019221660ac5e3@mail.gmail.com> According the pil manual it handles PGM files with "'1', 'L', or 'RGB' data" which leads me to believe 16bit data is not supported. You CAN write your own decoder for that though: http://www.pythonware.com/library/pil/handbook/decoder.htm It would be trivial to write a decoder for the pgm format. On Mon, Feb 8, 2010 at 4:47 PM, Davo wrote: > I have a PGM format image file with 4096 range. When I reads it with > PIL, I get an image with 8-bit values and alternate columns are zero. > Does PIL support reading and writing PGM's with more than 8-bits? > > Davo > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:31:35 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:31:35 GMT Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: On Mon, 08 Feb 2010 18:07:56 +0100, mk wrote: >> Threads are hard, and many people don't use them at all. You might >> never get an answer, even without alienating people. Complaining after >> six DAYS might be acceptable, if you do it with a sense of humour, but >> after six minutes? > > Well, it's 4 days now. I would be happy to get 50% response rate. > Apparently nobody is really using threads. Please see my response to your post "timer for a function". -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:36:48 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:36:48 GMT Subject: timer for a function References: Message-ID: On Fri, 05 Feb 2010 18:23:09 +0100, mk wrote: [...] > On paramiko mailing list I got the suggestion to build a timer and then > quit this by myself: > >> The timeout option in connect() is for the socket, not for the entire >> operation. You are connected, so that timeout is no longer relevant. >> You would probably have to wrap the transport.connect() method in a >> timer to break out of this early. > > Question: how can I do that? Use another threaded class? Is there some > other way? I don't use threads enough (or at all) to answer that question directly, but I can point you at these. Hopefully they will help, or at least give you some ideas: http://code.activestate.com/recipes/534115/ http://code.activestate.com/recipes/473878/ Found by googling for "python timeout any function". > Additional snag is SSHClient() is a class that internally uses threads. > How do I kill brutally its threads? Is there any way to do it? You can't kill threads in Python. You have to ask them nicely to die. Google on "python kill thread" for more. -- Steven From aonlazio at gmail.com Mon Feb 8 20:39:58 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Mon, 8 Feb 2010 20:39:58 -0500 Subject: Programing family Message-ID: I have thought funny things If we think all languages are like a family I could draft them like this (Python base) C is Python's Mom C++ : Dad Pascal/Assembly : Grandparents C# : Uncle Java : Ant Ruby: Cousin Perl : Girlfriend What u guys think? XD -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:49:39 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:49:39 GMT Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> Message-ID: On Mon, 08 Feb 2010 21:59:18 +0100, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" How do you give three operands to a binary operator? Binary operators only have two sides, a left and a right, so you can only fit two operands around them. Mathematicians solve this problem by using functions: add(a, b, c, d) In Python, you can do this: >>> class F: ... def __add__(self, other, foo=None): ... print self, other, foo ... return 1 ... >>> >>> F() + 3 <__main__.F instance at 0xb7f06f4c> 3 None 1 >>> F().__add__(3, 4) <__main__.F instance at 0xb7f06d8c> 3 4 1 but if you do, people will laugh and point at you in the street. *wink* -- Steven From jeanmichel at sequans.com Mon Feb 8 20:50:13 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 02:50:13 +0100 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <4B70BF55.90704@sequans.com> Aahz wrote: > In article <0efe23a6-b16d-4f92-8bc0-12d056bf599d at z26g2000yqm.googlegroups.com>, > OdarR wrote: > >> and with eval(), did you try ? >> > > WARNING: eval() is almost always the wrong answer to any question > Some say that eval is evil ! JM From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:51:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:51:01 GMT Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: On Mon, 08 Feb 2010 14:43:46 -0800, Aahz wrote: >>> WARNING: eval() is almost always the wrong answer to any question >> >>warning : it works ! > > Works for what? Code injection security bugs, of course. http://en.wikipedia.org/wiki/Code_injection It is surprisingly difficult to sanitize strings in Python to make them safe to pass to eval. Unless you are prepared to trust the input data explicitly, it's best to just avoid eval. -- Steven From apt.shansen at gmail.com Mon Feb 8 20:55:44 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 17:55:44 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> On Mon, Feb 8, 2010 at 4:44 PM, Alf P. Steinbach wrote: > No, one only needs an understanding of "pointer". > > "Pointer" is a mostly language independent concept. > > The reference to the Java language spec, where that term is used for this, > was just an unsuccessful attempt to keep out word-play arguments based on > the incompatibility of some incompatible meaning of "pointer"... > The fact is, "pointer" is not really a language independent concept. Just because a concept is used in multiple languages doesn't make it a general purpose term that has a clear meaning that's defined in a well-understood way. The last time I paid attention to one of your semantic arguments was when you were talking about "routine", where that -was- a language independent concept, but as wholly inappropriate to use in context of Python as pass-by-value (especially due to ambiguity). You seem to have an idea of a word in your head and a meaning and context, and are ignoring the fact that there's a huge body of knowledge that places another context or meaning on that word or phrase. Thus, the usage of that phrase actually -confuses- and does not -clarify-. The terms "call by reference" and "call by value" have *meaning* beyond the purely abstract: they have meaning to semantics that people expect when you use them, meaning to how the language works, and those meanings do *not* apply to Python. Python doesn't have pointers. That you can do id() and see something like a memory address is a CPython implementation detail which is not guaranteed and the fact that Python is implemented -in- a language which -does- have pointers, and that implementation uses pointers beneath the Python level. But the Python language (and CPython implementation) does -not- provide pointers to us. We do not use pointers in any Python code we do. To say, "pass by value" implies things to people. It describes a sort of world where I'm a function about to do some work, and on my desk I have a series of boxes with names on it. It describes an environment where someone comes over and drops something into each of my boxes. The contents of these boxes are mine alone! To say, "pass by reference" implies other things to people. It describes a sort of world where my desk doesn't have any boxes, really. It's got some places for boxes, but when someone gives me something? They give me their boxes too. The actual -stuff- in them I can swap between the two boxes if I want, and when I give those boxes back to the one who called me? They'll be swapped. That's a sort of defining characteristic of pass-by-reference environments. _Neither_ of these are accurate descriptions of Python's universe. You can say, "its pass by value, just be specific that the value is..." but at that point the statement is meaningless. You've taken a relatively well-understood statement with certain meaning and a semantic weight behind what it means, and just totally made it into something else entirely. By changing the entire meaning of "value", from the value of the variable which is copied, to the value of the memory address, you've changed -everything- that 'pass by value' means. So you should use a different word. Like, "objects" (or "sharing" is also used.) Python has names, and objects. The guy over there has things on his desk, with a label attached to it that has a name. He tosses it over to me, and I get the same object he did-- no boxes. I put my own label on it, even though he keeps hold of his label. I fiddle with it, and might toss it back. Or might not, maybe I'll toss something else back. Either way, he still has it. In Python, we get objects. Real objects. The original one. Its not a pointer, its an object, that happens to have a label attached to it. It doesn't have any idea what that label is, and it can't even find out. Its not in any boxes owned by any functions, its just floating out there with everything else, with lots of labels tied to it. Its just that when the last one is cut, nothing else is holding it up, and it falls to the ground and gets swept away. That python is pass-by-objects is -really- important for people to understand to really "get" python, and using other terms is /bad/ because it makes them think of the semantics those terms imply. Because if you don't -remember- and just instinctively -know- that Python is "pass-by-objects", you'll forget the difference between passing an immutable and a mutable object into a function, and be surprised by the result. >>> import copy >>> def doit(a): ... a += a ... return a ... >>> test1 = 1 >>> test2 = doit(test1) >>> test1 1 >>> test2 2 >>> test3 = [1] >>> test4 = doit(test3) >>> test3 [1, 1] >>> test4 [1, 1] I know you already know this, but the point is: you're -hurting- other peoples understanding by using terms like this that don't apply to Python's specific nature. In Python, every function gets the original objects that you pass into it. Some are immutable, some are mutable. With immutable ones, it might very well seem like its pass-by-value and behaves like pass-by-value semantics, but when you get mutable objects, that changes /quickly/. Changing "value" to mean, "the memory address where the object is stored" just obfuscates the entire point and doesn't actually explain what people need to understand in this question. --S P.S. I couldn't resist. :( -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Feb 8 21:03:32 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:03:32 -0800 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: <7a9c25c21002081803n858a715wc9baace9f6210c04@mail.gmail.com> On Mon, Feb 8, 2010 at 5:51 PM, Steven D'Aprano < steven at remove.this.cybersource.com.au> wrote: > On Mon, 08 Feb 2010 14:43:46 -0800, Aahz wrote: > > >>> WARNING: eval() is almost always the wrong answer to any question > >> > >>warning : it works ! > > > > Works for what? > > Code injection security bugs, of course. > > http://en.wikipedia.org/wiki/Code_injection > > It is surprisingly difficult to sanitize strings in Python to make them > safe to pass to eval. Unless you are prepared to trust the input data > explicitly, it's best to just avoid eval. > I'd make it a bit stronger: unless you are prepared to trust the input data explicitly, and forever-- and extending that trust to whomever might in the future be hired to work along, beside, under, or instead of you-- including the fact that they may use your system or code in a different or new way to get the data-- or how you may in the future decide to grow your system in ways you're not today prepared for and are committed to do a complete review of your entire codebase on every such change to ensure you don't leak some potentially bad data down into such a place-- then you can use eval. Otherwise, other solutions are better. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Feb 8 21:16:04 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:16:04 -0800 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: <7a9c25c21002081816r3b7a7c4fq5b079424dbd1f46e@mail.gmail.com> On Fri, Feb 5, 2010 at 7:25 AM, mk wrote: > Hello everyone, > > I have a problem with a threaded program: it frequently hangs on sys.exit. > I use threads all the time (well, for certain types of workloads) and have never seen this. Are your threads daemon threads? The only time I've seen sys.exit() not close out my program is when I'm launching non-daemon threads on accident. Now, I do get some slightly random errors on close due to threads doing stuff or returning from doing stuff while the shutdown procedure is going on, but I don't really care, cuz, well, I'm shutting everything down and nothing worth knowing is going on in the rest of the program. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Feb 8 21:19:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Feb 2010 20:19:57 -0600 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B70C64D.3020908@tim.thechases.com> Steven D'Aprano wrote: > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) I prefer the strength of Triple ROT-13 for my obfuscation needs, but I don't see it listed here. I guess I'll have to roll my own despite the dire warnings against amateur cryptographers authoring their own unvetted implementations. ;-) -tkc From sccolbert at gmail.com Mon Feb 8 21:29:50 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 8 Feb 2010 21:29:50 -0500 Subject: ANN: obfuscate In-Reply-To: <4B70C64D.3020908@tim.thechases.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <4B70C64D.3020908@tim.thechases.com> Message-ID: <7f014ea61002081829i2333f8b3y791485074e35b4ca@mail.gmail.com> I always though a double rot13 followed by a rot26 was the best? On Mon, Feb 8, 2010 at 9:19 PM, Tim Chase wrote: > Steven D'Aprano wrote: > >> obfuscate is a pure-Python module providing classical encryption >> algorithms suitable for obfuscating and unobfuscating text. >> >> obfuscate includes the following ciphers: >> - Caesar, rot13, rot5, rot18, rot47 >> - atbash >> - Playfair, Playfair6 and Playfair16 >> - Railfence (encryption only) >> - Keyword >> - Affine >> - Vigenere >> - frob (xor) >> > > I prefer the strength of Triple ROT-13 for my obfuscation needs, but I > don't see it listed here. I guess I'll have to roll my own despite the dire > warnings against amateur cryptographers authoring their own unvetted > implementations. ;-) > > -tkc > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Feb 8 21:42:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 21:42:53 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: Stephen Hansen wrote: [...] > P.S. I couldn't resist. :( > And here I was, sitting on my hands ... but someone was wrong on the Internet, so D'Aprano had to put them right. Your fatal weakness. Of course this won't make the slightest difference. "'When I use a word,' said Humpty ..." regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Mon Feb 8 21:44:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:44:17 -0800 Subject: timer for a function In-Reply-To: References: Message-ID: <7a9c25c21002081844h5a280e94k794ddc5d0df77610@mail.gmail.com> On Fri, Feb 5, 2010 at 9:23 AM, mk wrote: > On paramiko mailing list I got the suggestion to build a timer and then > quit this by myself: > > The timeout option in connect() is for the socket, not for the entire >> operation. You are connected, so that timeout is no longer relevant. >> You would probably have to wrap the transport.connect() method in a >> timer to break out of this early. >> > > Question: how can I do that? Use another threaded class? Is there some > other way? > What OS? Does this have to be OS-independant? Are you using more then one transport/SSLClient in your process and you want to just kill one (and any of its child threads), or are you doing one per process? If you want to terminate -all- threads your process is running in a given timeframe, using a SIGALRM in the signal module will do it, I believe-- provided you don't need to support windows. I had a contextlib manager do that for awhile. If you only want to terminate one (and its child-threads)... you're out of luck, I think. The only way to terminate a thread in Python is with conditions/events/whatever and the thread cooperating and exiting on its own. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Mon Feb 8 21:46:05 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 18:46:05 -0800 (PST) Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> Message-ID: <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> On Feb 8, 12:59?pm, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" If, for some reason, you wanted to define a type for which it makes sense to "add" three objects, but not two, you can get the effect you want, kind of. (a + b + c) is useful (a + b) is meaningless You can have __add__ return a closure for the first addition, then perform the operation on the second one. Example (untested): class Closure(object): def __init__(self,t1,t2): self.t1 = t1 self.t2 = t2 def __add__(self,t3): # whole operation peformed here return self.t1 + self.t2 + t3 class MySpecialInt(int): def __add__(self,other): return Closure(self,other) I wouldn't recommend it. Just use a function call with three arguments. Carl Banks From apt.shansen at gmail.com Mon Feb 8 21:48:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:48:02 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden wrote: > Stephen Hansen wrote: > [...] > > P.S. I couldn't resist. :( > > > > And here I was, sitting on my hands ... but someone was wrong on the > Internet, so D'Aprano had to put them right. Your fatal weakness. > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." > This is getting out of hand. First, someone thought I was you. Now you think I'm D'Aprano. I'm just gonna go by Bob for now on. :) --B -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Mon Feb 8 21:55:17 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 18:55:17 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> On Feb 8, 12:20?pm, spike wrote: > Has anyone been able to come across a Python logic map or Python logic > flow chart? > > An example can be seen on the right under History:http://en.wikipedia.org/wiki/Usenet#History > > This would be very helpful for all users. Begin | | V Start Editor | | V Write Code <----+ | | | | V | Run Python | | | | | No. V | Did it do what you want? | | Yes. | V Stop. HTH. Carl Banks From pavlovevidence at gmail.com Mon Feb 8 21:57:19 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 18:57:19 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <0dc66912-76de-4979-b98d-8358436b8ee8@d37g2000yqa.googlegroups.com> On Feb 8, 1:35?pm, Gary Herron wrote: > spike wrote: > > Has anyone been able to come across a Python logic map or Python logic > > flow chart? > > > An example can be seen on the right under History: > >http://en.wikipedia.org/wiki/Usenet#History > > > This would be very helpful for all users. > > Huh??? ?What aspect of Python were you thinking of mapping out? > > Your example us a bad ascii art graph of -- I've no clue what? Usenet servers. Back in the day people had these in their .sigfiles Carl Banks From python at mrabarnett.plus.com Mon Feb 8 22:07:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 09 Feb 2010 03:07:55 +0000 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> Message-ID: <4B70D18B.5040008@mrabarnett.plus.com> Stephen Hansen wrote: > On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden > wrote: > > Stephen Hansen wrote: > [...] > > P.S. I couldn't resist. :( > > > > And here I was, sitting on my hands ... but someone was wrong on the > Internet, so D'Aprano had to put them right. Your fatal weakness. > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." > > > This is getting out of hand. > > First, someone thought I was you. > > Now you think I'm D'Aprano. > > I'm just gonna go by Bob for now on. > > :) > > --B > Bruce would be less confusing. :-) From apt.shansen at gmail.com Mon Feb 8 22:17:48 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 19:17:48 -0800 Subject: Modifying Class Object In-Reply-To: <4B70D18B.5040008@mrabarnett.plus.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> <4B70D18B.5040008@mrabarnett.plus.com> Message-ID: <7a9c25c21002081917m3e8f7afbw3f5b0d58edf6a509@mail.gmail.com> On Mon, Feb 8, 2010 at 7:07 PM, MRAB wrote: > This is getting out of hand. >> >> First, someone thought I was you. >> >> Now you think I'm D'Aprano. >> >> I'm just gonna go by Bob for now on. >> :) >> >> --B >> >> Bruce would be less confusing. :-) I've heard that, and can't fathom the claim. I've only ever met a single Bruce in my entire life, though I've seen a couple on the 'net. Maybe its geographical, and Bruce's just don't like California? I dunno. Stephen's though I'm used to being one of many; I was 'number 5' at the office for quite awhile, since I worked directly for (and next to) a Stephen, with another Stephen, and frequently at to ask two other Stephen's for advice. So we all went by numbers. Time to take up the habit on the internet! Anyways. Ahem. --Bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Mon Feb 8 22:24:40 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:24:40 -0800 Subject: Socket Error: Permission Denied Message-ID: I'm using IDLE with winxp. It seems every day I get into the Subject above. Usually, after 5-8 minutes I get past it. A msg appearing at the same time say, "IDLE's subprocess didn't make connect. ... possible firewall problem." A resource for this is . There a number of choices. Perhaps the most appealing is: adgprogramming: first, bring up your task manager and make sure there are no python processes running. 2.6.x subprocesses can get stuck. Then make sure that your firewall isn't blocking socket access to localhost. Then restart IDLE. IDLE 3.1.1 may work for you since it has the recent enhancement that allows multiple copies of IDLE to run simultaneously, but it still needs interprocess access via sockets. How would I know the which Python processes or subprocesses are running? I can kill the main one, but that seems to do no good. pythonw.exe. Comments? From wolftracks at invalid.com Mon Feb 8 22:38:48 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:38:48 -0800 Subject: Socket Error: Permission Denied In-Reply-To: References: Message-ID: On 2/8/2010 7:24 PM, W. eWatson wrote: > I'm using IDLE with winxp. It seems every day I get into the Subject > above. Usually, after 5-8 minutes I get past it. A msg appearing at the > same time say, "IDLE's subprocess didn't make connect. ... possible > firewall problem." > > A resource for this is . There a > number of choices. Perhaps the most appealing is: > > adgprogramming: first, bring up your task manager and make sure there > are no python processes running. 2.6.x subprocesses can get stuck. > Then make sure that your firewall isn't blocking socket access to > localhost. Then restart IDLE. IDLE 3.1.1 may work for you since it > has the recent enhancement that allows multiple copies of IDLE to run > simultaneously, but it still needs interprocess access via sockets. > > How would I know the which Python processes or subprocesses are running? > I can kill the main one, but that seems to do no good. > pythonw.exe. > > Comments? I'm using McAffee. I see it was pythonw.exe blocked in red. There are several choices: Allow Access, Allow Outboubnd only Block (current), Remove Prgrm permission, Learn More. Outbound only seem reasonable, but why does the blocking keep returning every many hours, or maybe when I reboot, which I've done several times today? From wolftracks at invalid.com Mon Feb 8 22:45:50 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:45:50 -0800 Subject: Socket Error: Permission Denied In-Reply-To: References: Message-ID: I decided to go with outbound. Now when I run the program, I get a long of messabge about deprecations and NumpyTest will be removed in the next release. please update code to nose or unittest. From wolftracks at invalid.com Mon Feb 8 22:53:29 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:53:29 -0800 Subject: Tangling with mathplotlib(MPL) on XP and Win7 -- show() stopper Message-ID: I'm doing most of this on a win7 machine. When I installed MPL, I had two small dialogs appear that said something was missing, but I pressed on. MPL seemed to generally work except for the show() problem. When it was to be executed to show the output of plot(x,y), it did just that; however, the shell window hung, and I had to upper right corner x my way out of it--2 to 3 steps. The plot window and program easily went the same way. IDLE is the tool of choice on both machines. I'm in the process of bringing programs from my XP to the win7 machine, and on the XP machine I decided to start using MPL with a 900 line Py program that I'm revising. I had gotten stuck with the very same problem there. However, last night I realized someone had added a MPL plot to it years ago, and it does not fail on show(). I've put print stmts after show() in the big program, but nothing is printed in either case when I close the plot window. Tried in IDLE and executing from clicking on the py file in its folder. I brought some of this up on the MPL mailing list, and one respondent said he had tried some of the examples with show(), and they had worked. I noticed the dialog msgs mentioned above, and thought I made a mistake in not installing numpy first, so tried to figure out a way to do it. Three posts on different forums did not provide an answer. I accidentally found the author of MPL's hidden away in one of MPL files. He said it didn't make a difference and asked me not to use his address. I though the warning msgs might be of interest to him, so wrote to him. He had blocked me. Perhaps I need to file a bug report to get his attention on that. Anyway, I'm now stalled on the development of the big program. It's possible this is an IDLE problem, but I ran the big program with a click on the file, and the black window showed the same problem. This is all on XP Pro. I'm going to copy the two code segments here. Maybe someone can see a difference. =================OLD working code============ def light_curve( self ): result = [] test = 1 for tup in self.subimages: left,top,subimage = tup total = 0 avg_total = 0 if (test == 1): box = (left, top, left+128, top+128) region = self.reference_image.crop(box) self.reference_image.paste(subimage, box) test = 2 else: for x in range(left+43,left+82): for y in range(top+43, top+82): avg_total = avg_total + self.reference_image.getpixel((x, y)) for x in range(43,82): #take the center 40 X 40 pixel block for y in range(43,82): v = subimage.getpixel((x, y)) total = total + v #for x in range(left, left+127): # for y in range(top, top+127): # avg_total = avg_total + self.reference_image.getpixel((x, y)) #for x in range(0, 127): # for y in range(0, 127): # total = total + subimage.getpixel((x, y)) result.append(total - avg_total) #(average - background average) gives pixel intensity above the background) plotting_x = range(2, len(result)+2) plot(plotting_x, result) xlabel('Frame #') ylabel('Pixel count above background count') title('Light curve for selected subplot') show() ===========New Code with show problem def get_point_trail_stats(self): # Simple track statistics xy = array(self.xya)[:,0:2] # creates a two column array for x,y pt2pt_dist = [] pt_dist = [] for k in arange(0,len(xy)-1): distance = sqrt((xy[k+1,0]-xy[k,0])**2 + (xy[k+1,1]-xy[k,1])**2) pt_dist.append(distance) # wtw print "k ",k, (xy[k,0], xy[k,1]), " distance: ", distance # wtwfor k in arange(0, len(xy)-50): # wtw print "k: %3i dist: %6.2f (x,y) (%4.1f,%4.1f)" % (k, pt_dist[k], xy[k,0], xy[k,1]) per_tile25 = stats.scoreatpercentile(pt_dist,25.0) per_tile50 = stats.scoreatpercentile(pt_dist,50.0) per_tile75 = stats.scoreatpercentile(pt_dist,75.0) mean = stats.mean(pt_dist) std = stats.std(pt_dist) #sys.exit() amin = min(pt_dist) amax = max(pt_dist) print " mean: %7.2f std: %7.2f min: %7.2f max: %7.2f" % (mean, std, amin, amax) print " quartiles (25-per: %7.2f, 50-per: %7.2f, 75-per: %7.2f): " % (per_tile25, per_tile50, per_tile75) #print " Extended stats" #print " min: %7.2f max: %7.2f mean: %7.2f std: %7.2f" % \ # (min, max, mean, std) #print " p25: %7.2f p50: %7.2f p75: %7.2f" % (per_tile25, per_tile50, per_tile75) trk_stats = (amin, amax, mean, std, per_tile25, per_tile50, per_tile75) fig = figure() ax1 = fig.add_subplot(111) v = (0, 640, 0, 480) print "shapes: ", xy[:,0].shape, xy[:,1].shape fig.close() ax1.plot(xy[:,0], xy[:,1]) #,100*s, c , picker=True) ax1.axis(v) #x = (0,1,3,20,20);y=(5,7, 9, 22,90) #col = ax1.plot(x,y) show() print "something for wtw plot" print return trk_stats From alfps at start.no Mon Feb 8 23:01:16 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 05:01:16 +0100 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: * Stephen Hansen -> Alf P. Steinbach: > > [snip] > To say, "pass by value" implies things to people. It describes a sort of > world where I'm a function about to do some work, and on my desk I have > a series of boxes with names on it. It describes an environment where > someone comes over and drops something into each of my boxes. The > contents of these boxes are mine alone! Then, when the imprecision makes people misunderstand, one should not say that. One should then be more precise. One should say /what/ is passed by value. [snip] > >>> import copy > >>> def doit(a): > ... a += a > ... return a > ... > >>> test1 = 1 > >>> test2 = doit(test1) > >>> test1 > 1 > >>> test2 > 2 > >>> test3 = [1] > >>> test4 = doit(test3) > >>> test3 > [1, 1] > >>> test4 > [1, 1] > > I know you already know this, but the point is: you're -hurting- other > peoples understanding by using terms like this that don't apply to > Python's specific nature. The terms apply very well to Java. And Java has the identical parameter passing mechanism for class type objects. Hence, the argument is bogus. Cheers & hth., - Alf PS: I cannot see any of your postings on Usenet. So I just sort of grabbed this from GMane and posted to Usenet. Hopefully you'll see it back at the list. :-) From gnarlodious at gmail.com Mon Feb 8 23:02:30 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 8 Feb 2010 20:02:30 -0800 (PST) Subject: Python 3: Plist as OrderedDict Message-ID: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> I am trying to read a *.plist into Python 3's OrderedDict but can't figure it out. Saying something like this: from plistlib import readPlist dict=readPlist('/path/file.plist') --> arbitrarily ordered dictionary compared to the XML file from collections import OrderedDict OrderedDict(readPlist('/path/file.plist')) --> essentially does the same thing as the previous readPlist seems to do the scrambling, is this a non-implementation in Python 3.1? I "upgraded" to Py3 to have OrderedDict, so please don't say it is impossible... -- Gnarlie From ben+python at benfinney.id.au Mon Feb 8 23:17:23 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Feb 2010 15:17:23 +1100 Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: <871vgvjb58.fsf@benfinney.id.au> Gnarlodious writes: > from plistlib import readPlist > dict=readPlist('/path/file.plist') > --> arbitrarily ordered dictionary compared to the XML file Right. The items in a dict are unordered, and when serialised to a list they will appear in an arbitrary, unpredictable order. >>> foo = dict( ... [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]) >>> foo {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} > from collections import OrderedDict > OrderedDict(readPlist('/path/file.plist')) > --> essentially does the same thing as the previous Yes, because you are initialising an OrderedDict instance from a dict. That accesses the dict items as an iterable, which of course is going to retrieve the items in an arbitrary, unpredictable order. >>> foo.items() dict_items([('a', 1), ('c', 3), ('b', 2), ('e', 5), ('d', 4)]) The OrderedDict then faithfully remembers the arbitrary ordering of the items. >>> from collections import OrderedDict >>> OrderedDict(foo.items()) OrderedDict([('a', 1), ('c', 3), ('b', 2), ('e', 5), ('d', 4)]) > readPlist seems to do the scrambling Nothing ?does? the scrambling; the order is forgotten by the dict as soon as the items go in. > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... What you'll need to do is insert the items into the OrderedDict instance in the desired order. You will, of course, need to define what that desired order is. >>> sorted(foo.items(), key=(lambda item: item[0])) [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)] >>> OrderedDict(sorted(foo.items(), key=(lambda item: item[0]))) OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]) -- \ ?When we talk to God, we're praying. When God talks to us, | `\ we're schizophrenic.? ?Jane Wagner, via Lily Tomlin, 1985 | _o__) | Ben Finney From benjamin.kaplan at case.edu Mon Feb 8 23:21:13 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 8 Feb 2010 23:21:13 -0500 Subject: Python 3: Plist as OrderedDict In-Reply-To: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: On Mon, Feb 8, 2010 at 11:02 PM, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: > > from plistlib import readPlist > dict=readPlist('/path/file.plist') > --> arbitrarily ordered dictionary compared to the XML file > > from collections import OrderedDict > OrderedDict(readPlist('/path/file.plist')) > --> essentially does the same thing as the previous > readPlist seems to do the scrambling, is this a non-implementation in > Python 3.1? > > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... > > -- Gnarlie readPlist returns a dict. That dict is unordered. Wrapping the call in OrderedDict() doesn't suddenly make readPlist use an ordered dict instead, it just takes the (unordered) dict and sticks it in a new OrderedDict. I suppose you could dig into the plistlib source code and change that to use the OrderedDict if you really need it. > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Mon Feb 8 23:25:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Feb 2010 23:25:25 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: On 2/8/2010 2:10 PM, Alf P. Steinbach wrote: > I apologize for assuming that "pointer" is a known word to [c.l.p.] > denizens. It is irrelevant. Python calls Python functions by associating argument objects (or objects derived therefrom) with paramenter names, very much like assigment statements. If one understands Python objects, names, and assignment statements, which one must to understand Python, this completely explains the function calls, function execution, and its effect on passed objects. All Python expressions evaluate to an object. Call expressions evaluate to the object returned by the function. Different interpreters implement call and return differently. Certainly, most humans do not use C pointers when they mentally execute Python code. Terry Jan Reedy From apt.shansen at gmail.com Mon Feb 8 23:29:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 20:29:02 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> On Mon, Feb 8, 2010 at 8:01 PM, Alf P. Steinbach wrote: > * Stephen Hansen -> Alf P. Steinbach: > >> >> [snip] >> >> To say, "pass by value" implies things to people. It describes a sort of >> world where I'm a function about to do some work, and on my desk I have a >> series of boxes with names on it. It describes an environment where someone >> comes over and drops something into each of my boxes. The contents of these >> boxes are mine alone! >> > > Then, when the imprecision makes people misunderstand, one should not say > that. > > One should then be more precise. > > One should say /what/ is passed by value. > No. One should not use the phrase that is fundamentally imprecise. The phrase "pass by value" means something different then the phrase "pass by object" aka "pass by sharing". They are in many cases very similar. They are not the same. Using it is simply wrong. There is really no legitimate argument you can make otherwise: even in languages where call-by-value IS the norm, the phrase is imprecise enough to confuse people, as the semantics of what call-by-value mean to a language vary. But those semantics do NOT apply to Python. [snip] > >> >> I know you already know this, but the point is: you're -hurting- other >> peoples understanding by using terms like this that don't apply to Python's >> specific nature. >> > > The terms apply very well to Java. And Java has the identical parameter > passing mechanism for class type objects. Hence, the argument is bogus. > Java uses silly terminology; and that it chooses to use silly terminology in no way impacts the validity of the argument. Java isn't an authority. Python's been around longer! And the specific behavior here, "call by value where the value is an object reference" was named "call by sharing" back in the 1970's by Liskov. Java isn't call-by-value (for objects) either, even if that phrase is common in the Java community. C is call-by-value. VB is, I believe, call-by-value -- though I may be wrong here, as I only sort of blinked at VB a long, long time ago. Its distinct. Its different. Its neither call-by-value, nor call-by-reference. The /value/ of a thing is NOT its identity. Its the /state/ of that thing. By your argument, call-by-reference is call-by-value too! Because you're passing "a value" -- but you're -always- going to pass some piece of data, otherwise you're not actually passing anything. The /by value/ vs /by reference/ vs /by sharing/ is not about "is a value being passed", in all cases, "a value" is. By Value means a copy of the thing is made. By Reference means you're accessing the callers variable directly. By Sharing means you're both sharing the same object. PS: I cannot see any of your postings on Usenet. So I just sort of grabbed > this from GMane and posted to Usenet. Hopefully you'll see it back at the > list. :-) I've heard that before, and have no idea why, nor any real interest in solving it: I don't want to read cpl via Usenet, and prefer to read it as a mailing list. Somewhere between Gmail->python.org->python.org's usenet server->the world, some people don't seem to get my posts. Yet it shows up on some news servers, not others. No idea. Nothing I know of can solve it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From bchang2002 at gmail.com Mon Feb 8 23:40:54 2010 From: bchang2002 at gmail.com (dontcare) Date: Mon, 8 Feb 2010 20:40:54 -0800 (PST) Subject: xml.sax parsing elements with the same name References: <51ad9cee-6b7b-42c8-8f9e-44c0f8b96bc7@j19g2000yqk.googlegroups.com> <4b4c2f2e$0$6731$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <961b9e15-5d20-472b-92bc-917796dc6e5e@y7g2000prc.googlegroups.com> If you are using jython, then you might also want to consider VTD-XML, which is a lot easier to use and faster than SAX, native XPath support may be useful too http;//vtd-xml.sf.net On Jan 12, 12:13?am, Stefan Behnel wrote: > amadain, 11.01.2010 20:13: > > > > > > > I have an event log with 100s of thousands of entries with logs of the > > form: > > > > uniqueId="1261124569.35725_PFS_1_1340035961"> > > ? ? > > ? ? ? > > ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? > > ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? > > ? ? ? > > > > > I am usingxml.saxto parse the event log. > > You should give ElementTree's iterparse() a try (xml.etree package). > Instead of a stream of simple events, it will give you a stream of > subtrees, which are a lot easier to work with. You can intercept the event > stream on each 'event' tag, handle it completely in one obvious code step, > and then delete any content you are done with to safe memory. > > It's also very fast, you will like not loose muchperformancecompared toxml.sax. > > Stefan- Hide quoted text - > > - Show quoted text - From tjreedy at udel.edu Mon Feb 8 23:47:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Feb 2010 23:47:20 -0500 Subject: Python 3: Plist as OrderedDict In-Reply-To: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: On 2/8/2010 11:02 PM, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: > > from plistlib import readPlist As a general note, include a link or something when discussing a relatively obscure module that seems not to even be listed in pypi. > dict=readPlist('/path/file.plist') Redefining a basic builtin name like 'dict' is usually a bad idea. > --> arbitrarily ordered dictionary compared to the XML file > > from collections import OrderedDict > OrderedDict(readPlist('/path/file.plist')) > --> essentially does the same thing as the previous > readPlist seems to do the scrambling, is this a non-implementation in > Python 3.1? > > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... I agree with Benjamin -- check the source. Is plistlib 3.x ready? Terry Jan Reedy From alfps at start.no Tue Feb 9 00:12:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 06:12:07 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: * Terry Reedy: > On 2/8/2010 2:10 PM, Alf P. Steinbach wrote: > >> I apologize for assuming that "pointer" is a known word to [c.l.p.] >> denizens. > > It is irrelevant. > > Python calls Python functions by associating argument objects (or > objects derived therefrom) with paramenter names, very much like > assigment statements. Well, part of the above is word-play. When a name refers to an object elsewhere and that reference can be copied around, then it is a pointer to the object in e.g. the Java sense, which I very purposefully referenced to be clear about it. So you're saying that X is irrelevant in Python because Python uses Y, where Y is a description of X... But part of what you write puzzles me. As far as the language spec is concerned the argument passing mechanism seems to me to be identical to assignments, not just "very much like". Your phrase "or objects derived therefrom" seems to imply that immutable objects can be copied (an optimization that once was rejected), but as far as I can see the language spec only talks about binding with no provision for binding to do anything else than making a name refer directly to a specified object, presumably with *the same id*. Not talking about things built on top of argument passing like *, and not talking about scopes or other (in this context) extraneous details: is there something I've overlooked in the basic mechanism? > If one understands Python objects, names, and assignment statements, > which one must to understand Python, this completely explains the > function calls, function execution, and its effect on passed objects. Yes. There are many ways to understand it though. The simplest description, reality, that names refer to objects, where those references can be copied, i.e. that they in e.g. the Java sense are pointers to objects, seems to be simplest -- and is certainly shortest. :-) > All Python expressions evaluate to an object. Call expressions evaluate > to the object returned by the function. > > Different interpreters implement call and return differently. Certainly, > most humans do not use C pointers when they mentally execute Python code. The Java language spec reference for "pointer" was to avoid arguments about irrelevant specialized meanings of the term, such as C pointers. Cheers & hth., - Alf From phlip2005 at gmail.com Tue Feb 9 00:21:55 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 21:21:55 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> Message-ID: <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> Carl Banks wrote: > I don't know if it was the reason it was rejected, but a seriously > divisive question is whether the path should be a subset of string. OMG that's nothing but the OO "circle vs ellipse" non-question. Glad to see the Committee derailed a perfectly good library over such sophistry. > Under ordinary circumstances it would be a poor choice for inheritance > (only a few string methods would be useful fot a pathname), but some > people were fiercely adamant that paths should be passable to open() > as-in (without having to explicity convert to string). That's just silly. To be object-based, you should say path.open('r'). fopen() and its ilk are too 1960s... My 5th Grade science teacher, one Eunice Feight, once expressed chagrin for submitting a proposal to Readers' Digest, and getting it accepted. She sold them the following sloka: Don't be clever don't be witty Or you'll wind up BEING the Committee! -- Phlip http://penbird.tumblr.com/ From ijcsorgeditor at gmail.com Tue Feb 9 00:35:55 2010 From: ijcsorgeditor at gmail.com (editor ijcs) Date: Mon, 8 Feb 2010 21:35:55 -0800 (PST) Subject: Call for Paper The International Journal of Computer Science (IJCS) Message-ID: Call for Paper The International Journal of Computer Science (IJCS) publishes original papers on all subjects relevant to computer science, communication network, and information systems. The highest priority will be given to those contributions concerned with a discussion of the background of a practical problem, the establishment of an appropriate model, the determination of a solution, approximate or exact, analytical or numerical, and a discussion of the relevance of the results when applied to the real-life problem. Paper submissions are invited in the area of computer science, in particular the technological advances and research results in the fields of theoretical, experimental, applied electronics, computer science, communication network and Information technology. Topics of interest include but are not limited to the following: Computer Science * Parallel Processing and Distributed Computing * Foundations of High-performance Computing * Graph Theory and Analysis of Algorithms * Artificial Intelligences and Pattern/Image Recognitions * Neural Networks and Biomedical Simulations * Virtual Visions and Virtual Simulations * Data Mining, Web Image Mining and Applications * Data Base Management & Information Retrievals Adaptive Systems * Bifurcation, Biocybernetics & Bioinformatics * Blind Systems, Neural Networks &Control Systems * Cryptosystems &Data Compression * Evolutional Computation &Fuzzy Systems * Image Processing and Image Recognition, Modeling & Optimization * Speech Processing, Speech Synthesis & Speech Recognition * Video Signal Processing, Watermarking & Wavelet Transform * All topics related Computer Science Communication Network * Quantum Computing & Coding * Error Controls Agent Computing & Multi-Agents Systems * Defining Spectrum Rights and Open Spectrum Solutions * Quality of Services and Communication Protocols * Satellite and Optical Communication Systems * 3G/4G Network Evolutions & CDMA/GSM Communication Protocols * Mobile Computing, Transmission/Switching/Distribution technologies * Communication Theory & Signal Processing for Communications * Wireless Communications, Wireless & Mobile Networking * Optical Networks and Systems &Next-Generation Networking and Internet * Communication QoS &Reliability and Modeling * Ad-hoc, Sensor & Mesh Networking * Multimedia Services, Communication Software & Services * Communication and Information System Security * System control and network/service management * Network and Internet protocols and standards * Client-server, distributed & Web-based communication systems * Broadband and multimedia systems & applications * Trials of advanced systems and services * Any topics related Communication Network Information and Systems * Cryptography and Foundation of Computer Security * Authentication/Authorization Issues * IDS/Firewall, Anti-Spam mail & Anti-virus issues * Biometric authentication & algorithms * Fingerprint /Hand/Biometrics Recognitions and Technologies * IC-card Security, OTP & Key Management Issues * E-commerce, Ubiquitous & RFID Applications * Metadata, Meta Modeling, XML & Data Management * Knowledge Management, Web Security & Privacy * Cyber Threats, Web Services & Web Engineering * Web Intelligence, Protocols & Standards * Proxies and Servers * Multimedia Applications * Ontology and the Semantic Web * B2B, B2C and C2C * E-Business System Design and Development, E-Payment * Portal Strategies, Social Networks and Information Systems * Social and Legal Issues and Digital Ecology * E-Governance, E-Learning and Virtual Classrooms * E-Entertainment, E-Journalism * Any topics related Information systems Electronics * Circuits & Devices * Communication Networks & Systems * Communications & Information Processing * Digital Signal Processing & Electrical Engineering Communications * Electromagnetics & Microwaves * Instrumentation * Measurement & Testing * Nanoscience & Nanotechnology * Optics & Optoelectronic Effects * Devices, Systems &Semiconductors * Systems & Control Engineering * Telecommunications * Any topics related Electronics International Journal of Computer Science (IJCS) ISSN: 1884-9083 Website: https://sites.google.com/site/ijcsorg/ Manuscript submission to: ijcsorgeditor at gmail.com All submitted papers will be judged based on their quality by the technical committee and reviewers. Papers that describe research and experimentation are encouraged. All paper submissions will be handled electronically and detailed instructions on submission procedure are available on IJCS web pages. Researchers and authors are invited to participate in the peer-review process of IJCS papers if your research interest matches with the themes of Call for Papers. For other information, please contact IJCS Managing Editor. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 00:38:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 05:38:26 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: On Tue, 09 Feb 2010 05:01:16 +0100, Alf P. Steinbach wrote: > * Stephen Hansen -> Alf P. Steinbach: >> >> [snip] >> To say, "pass by value" implies things to people. It describes a sort >> of world where I'm a function about to do some work, and on my desk I >> have a series of boxes with names on it. It describes an environment >> where someone comes over and drops something into each of my boxes. The >> contents of these boxes are mine alone! > > Then, when the imprecision makes people misunderstand, one should not > say that. > > One should then be more precise. > > One should say /what/ is passed by value. I don't see how that matters. Python's behaviour is EXACTLY the same, no matter what you pass to the function. You don't pass pointers in Python, because you, the Python author, have no way of specifying a pointer in Python code. It is *always* an object that you pass, by giving a literal, the name an object is bound to, or some other expression that returns an object: function( my_object ) function( 12345 ) function( ham(3) + spam(5) ) If you're talking to the person who writes Python code, then you should discuss the sorts of things that exist in Python: objects and names and expressions, but no pointers. If you're talking about the Python virtual machine, instead of the high- level Python code, then you should say so -- but there are still no pointers in the VM. Look at the output of dis.dis and you will see objects pushed onto a stack, but no pointers. It's not until you get past the level of Python code, past the virtual machine, and into the implementation of the virtual machine, that you will finally find pointers. But why stop there? If somebody asks you a question about Python, and you choose to ignore them and answer a different question about one particular implementation's internals instead, I don't see why you stop there. Why not go down another layer and talk about copying bytes, or two layers and answer that Python does call-by-bit-flipping, or a layer below that and say it's all done by varying potential differences? You shouldn't expect your listener to understand machine code to understand Python's high-level behaviour, nor should you expect them to be C coders. You don't need to understand pointers to understand a language that doesn't support them. [...] > The terms apply very well to Java. And Java has the identical parameter > passing mechanism for class type objects. Hence, the argument is bogus. Everything I've said applies to Java as well, and the argument about call- by-whatever is just as prevalent in Java circles as in Python. Example #1: Q: If Java uses the pass-by reference, why won't a swap function work? A: Your question demonstrates a common error made by Java language newcomers. Indeed, even seasoned veterans find it difficult to keep the terms straight. Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value. http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html Example #2: Myth: "Objects are passed by reference, primitives are passed by value" Some proponents of this then say, "Ah, except for immutable objects which are passed by value [etc]" which introduces loads of rules without really tackling how Java works. http://www.yoda.arachsys.com/java/passing.html Example #3: Java is Pass-by-Value, Dammit! http://javadude.com/articles/passbyvalue.htm Java programmers suffer for a bad mental model just as much as Python programmers. All this is because of two conceptual mistakes: (1) the Java community has conflated the internals of what happens in the implementation of the Java VM with high-level Java code; and (2) a refusal to accept that there are calling strategies other than pass-by-value and pass-by-reference. -- Steven From ldo at geek-central.gen.new_zealand Tue Feb 9 00:43:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Feb 2010 18:43:48 +1300 Subject: ctypes Structure serialization References: <615b1271-a9b0-4558-8e45-e4370698d96a@a16g2000pre.googlegroups.com> Message-ID: In message <615b1271-a9b0-4558-8e45- e4370698d96a at a16g2000pre.googlegroups.com>, rych wrote: > I'm not quite familiar with python serialization but the picle module, > at least, doesn't seem to be able to serialize a ctypes Structure with > array-fields. Remember that a ctypes structure is supposed to represent a lower-language- level structure, which is just a block of bytes. Those bytes are the serialization. From olivier.darge at gmail.com Tue Feb 9 01:00:15 2010 From: olivier.darge at gmail.com (OdarR) Date: Mon, 8 Feb 2010 22:00:15 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: On 9 f?v, 02:50, Jean-Michel Pichavant wrote: > Aahz wrote: > > In article <0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, > > OdarR ? wrote: > > >> and with eval(), did you try ? > > > WARNING: eval() is almost always the wrong answer to any question > > Some say that eval is evil ! > > JM go to hell ;-), it is part of the language, it seems to match the aforementioned question. I don't see it as a problem. Let's wait Klaus opinion. Olivier From apt.shansen at gmail.com Tue Feb 9 01:26:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 22:26:11 -0800 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <7a9c25c21002082226t7f042f00lf001c827fe7b88eb@mail.gmail.com> On Mon, Feb 8, 2010 at 10:00 PM, OdarR wrote: > On 9 f?v, 02:50, Jean-Michel Pichavant wrote: > > Aahz wrote: > > > In article < > 0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, > > > OdarR wrote: > > > > >> and with eval(), did you try ? > > > > > WARNING: eval() is almost always the wrong answer to any question > > > > Some say that eval is evil ! > > > > JM > > go to hell ;-), it is part of the language, it seems to match the > aforementioned question. > > I don't see it as a problem. > Yes, it is a part of the language, because as a dynamic language has to have such a capability. Because there are legitimate use-cases for it. But they are extremely rare. Extremely rare. But it is there: if there is a real, legitimate use-case for a feature that can't be solved by other means, then certainly include a feature to accomplish that goal. But that doesn't mean you use that feature all over just because its there. You use it when its appropriate. The ability to do a thing doesn't mean you should do a thing. In most cases, eval is not appropriate. It might do what you think you want, but often there are huge consequences and not at all obvious considerations you have to take into account. Usually when you think you want to eval, there's a better way to approach the problem. It might not seem right away to be as "easy" or "seamless" as you think you want, but there are almost always compelling reasons why its better, easier, more efficient and simpler. People are trying to help the OP not only by providing the easiest approach to solve a problem, but trying to show him the best way to make /good code/. Good Code isn't a purely subjective thing left up to idle taste. ... Also? "go to hell" even with a smiley is being an asshat. Don't be an asshat. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Tue Feb 9 01:35:57 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 07:35:57 +0100 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: * Stephen Hansen: > On Mon, Feb 8, 2010 at 8:01 PM, Alf P. Steinbach > wrote: > > * Stephen Hansen -> Alf P. Steinbach: > > > [snip] > > To say, "pass by value" implies things to people. It describes a > sort of world where I'm a function about to do some work, and on > my desk I have a series of boxes with names on it. It describes > an environment where someone comes over and drops something into > each of my boxes. The contents of these boxes are mine alone! > > > Then, when the imprecision makes people misunderstand, one should > not say that. > > One should then be more precise. > > One should say /what/ is passed by value. > > > No. > > One should not use the phrase that is fundamentally imprecise. > > The phrase "pass by value" means something different then the phrase > "pass by object" aka "pass by sharing". They are in many cases very > similar. They are not the same. Right. "pass by value" is a lower level notion. And as you show below, in the paragraph marked [1], it can be used to describe call by sharing very succinctly and precisely, just as I did... ;-) > Using it is simply wrong. There is > really no legitimate argument you can make otherwise: even in languages > where call-by-value IS the norm, the phrase is imprecise enough to > confuse people, as the semantics of what call-by-value mean to a > language vary. But those semantics do NOT apply to Python. In a way that's right, but only at the level of abstraction of pass by sharing. At that level it's wrong to say that pass by sharing is pass by value (as they reportedly do over in Java-land), just as, at that level, it's wrong to say that pass by reference is pass by value notwithstanding that some kind of value must be copied in the internal implementation. Describing pass by sharing in terms of pass by value is however very simple and legitimate, involving a higher level described in terms of a lower level -- as you illustrate right below: > [snip] > I know you already know this, but the point is: you're -hurting- > other peoples understanding by using terms like this that don't > apply to Python's specific nature. > The terms apply very well to Java. And Java has the identical > parameter passing mechanism for class type objects. Hence, the > argument is bogus. > > > [1] Java uses silly terminology; and that it chooses to use silly > terminology in no way impacts the validity of the argument. Java isn't > an authority. Python's been around longer! And the specific behavior > here, "call by value where the value is an object reference" was named > "call by sharing" back in the 1970's by Liskov. Yep. As you write, "call by sharing" can be described as "call by value where the value is an object reference". Althuogh I'd rather use "where the value is an object pointer", because the word "pointer" already denotes a copyable value so doesn't make the head spin... > Java isn't call-by-value (for objects) either, even if that phrase is > common in the Java community. Right, and here the parenthesis (for objects) establishes which abstraction level. > C is call-by-value. VB is, I believe, > call-by-value -- though I may be wrong here, as I only sort of blinked > at VB a long, long time ago. Full VB supports both call by sharing and call by reference. > Its distinct. Its different. Its neither call-by-value, nor > call-by-reference. The /value/ of a thing is NOT its identity. Its the > /state/ of that thing. Talking about a reference value (a.k.a. pointer), as you do earlier above in [1], does not mean that one is talking about a Python object value. So essentially the paragraph immediately above seems to be a confusion based on multiple meanings of "value", unless it's just a description of Python objects? > By your argument, call-by-reference is call-by-value too! Because you're > passing "a value" -- but you're -always- going to pass some piece of > data, otherwise you're not actually passing anything. No, whatever you think my argument is (no quote, so I'm left in the dark about that assumption) here you're back to confusing levels of abstraction again. Call by reference is necessarily, at some level, implemented in terms of call by value. That doesn't make call by reference the same as call by value, not more than the human body is one giant molecule just because it consists of molecules. > The /by value/ vs /by reference/ vs /by sharing/ is not about "is a > value being passed", in all cases, "a value" is. By Value means a copy > of the thing is made. By Reference means you're accessing the callers > variable directly. By Sharing means you're both sharing the same object. Yes, violent agreement. > PS: I cannot see any of your postings on Usenet. So I just sort of > grabbed this from GMane and posted to Usenet. Hopefully you'll see > it back at the list. :-) > > > I've heard that before, and have no idea why, nor any real interest in > solving it: I don't want to read cpl via Usenet, and prefer to read it > as a mailing list. Somewhere between Gmail->python.org->python.org > 's usenet server->the world, some people don't seem > to get my posts. Yet it shows up on some news servers, not others. > > No idea. Nothing I know of can solve it. Not sure, but perhaps it's possible to mail directly to gmane? Cheers & hth., - Alf From frank at chagford.com Tue Feb 9 01:45:03 2010 From: frank at chagford.com (Frank Millman) Date: Tue, 9 Feb 2010 08:45:03 +0200 Subject: Simple question about Queue.Queue and threads References: <770583c3-a7c7-4a3d-b90f-9546801040e3@u26g2000yqm.googlegroups.com> Message-ID: On Feb 8, 4:51 pm, Steven wrote: > > Queue objects have support for this signaling baked in with > q.task_done and q.join. > > After the server process has put all tasks into the queue, it can join > the queue itself, not the worker threads. > > q.join() > > This will block until all tasks have been gotten AND completed. The > worker threads would simply do this: > task_data = q.get() > do_task(task_data) > q.task_done() > > Using pairs of get and task_done you no longer need to send a signal. > Just exit the server process and the worker threads will die (assuming > of course, you set .setDaemon(True) before starting each worker > thread). > Thanks, Steven. This works perfectly in my scenario, and tidies up the code a bit. Minor point - according to the 2.6 docs, .setDaemon(True) is the old API - the current way of specifying this is .daemon = True. Thanks for the tip. Frank From nad at acm.org Tue Feb 9 01:47:25 2010 From: nad at acm.org (Ned Deily) Date: Mon, 08 Feb 2010 22:47:25 -0800 Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: In article , Terry Reedy wrote: > On 2/8/2010 11:02 PM, Gnarlodious wrote: > > I am trying to read a *.plist into Python 3's OrderedDict but can't > > figure it out. Saying something like this: > > from plistlib import readPlist > As a general note, include a link or something when discussing a > relatively obscure module that seems not to even be listed in pypi. http://docs.python.org/library/plistlib.html -- Ned Deily, nad at acm.org From pwashington85 at gmail.com Tue Feb 9 01:47:42 2010 From: pwashington85 at gmail.com (spike) Date: Mon, 8 Feb 2010 22:47:42 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> On Feb 8, 1:35?pm, Gary Herron wrote: > spike wrote: > > Has anyone been able to come across a Python logic map or Python logic > > flow chart? > > > An example can be seen on the right under History: > >http://en.wikipedia.org/wiki/Usenet#History > > > This would be very helpful for all users. > > Huh??? ?What aspect of Python were you thinking of mapping out? > > Your example us a bad ascii art graph of -- I've no clue what? > > Gary Herron Do you know what "Logic" means? Guess not. Before you comedians quit your day job some people are looking for information. If you have nothing positive to say, go pester somewhere else. Grow up. From greg.ewing at canterbury.ac.nz Tue Feb 9 01:55:16 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Feb 2010 19:55:16 +1300 Subject: equivalent of Ruby's Pathname? In-Reply-To: <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> Message-ID: <7tceiuF94hU1@mid.individual.net> Carl Banks wrote: > I don't remember if the idea of modifying open to accept path > objects came up. It wouldn't just be open() that people would want modified -- it would be every other function that takes a pathname as well. I seem to recall another point of contention was whether path objects should have methods for accessing the file system (opening files, renaming them, etc.) or whether it should confine itself to representing and manipulating pathnames. In any case, introducing any kind of path object at this late stage of the language's development would result in More Than One Way to represent pathnames, with neither of them being the obvious choice. -- Greg From greg.ewing at canterbury.ac.nz Tue Feb 9 01:58:29 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Feb 2010 19:58:29 +1300 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <7tceorF94hU2@mid.individual.net> Tim Chase wrote: > I prefer the strength of Triple ROT-13 for my obfuscation needs, but I > don't see it listed here. That's old hat -- with the advent of 3GHz cpus and GPGPU, all the experts are recommending quadruple ROT-128 nowadays. -- Greg From python at rcn.com Tue Feb 9 02:15:57 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Feb 2010 23:15:57 -0800 (PST) Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> On Feb 8, 8:02?pm, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: ... > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... You may be able to monkey patch an OrderedDict into the PlistParser. Here's an untested stab at it: from collections import OrderedDict import plistlib plistlib._InteralDict = OrderedDict Raymond From alfps at start.no Tue Feb 9 02:19:56 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 08:19:56 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: * Steven D'Aprano: > On Tue, 09 Feb 2010 05:01:16 +0100, Alf P. Steinbach wrote: > >> * Stephen Hansen -> Alf P. Steinbach: >>> [snip] >>> To say, "pass by value" implies things to people. It describes a sort >>> of world where I'm a function about to do some work, and on my desk I >>> have a series of boxes with names on it. It describes an environment >>> where someone comes over and drops something into each of my boxes. The >>> contents of these boxes are mine alone! >> Then, when the imprecision makes people misunderstand, one should not >> say that. >> >> One should then be more precise. >> >> One should say /what/ is passed by value. > > I don't see how that matters. Python's behaviour is EXACTLY the same, no > matter what you pass to the function. > > You don't pass pointers in Python, because you, the Python author, have > no way of specifying a pointer in Python code. It is *always* an object > that you pass, by giving a literal, the name an object is bound to, or > some other expression that returns an object: > > function( my_object ) > function( 12345 ) > function( ham(3) + spam(5) ) Every name and literal above (and in Python generally) stands for a copyable reference to an object, not for the object itself. You can copy the reference: a = [123] b = a assert( a is b ) # Doesn't matter if mutable or immutable or what. A copyable reference is a pointer. That is, a "pointer", in e.g. the Java sense, and in the general language independent sense, means a copyable reference -- as illustrated e.g. in the Stanford computer science 101 course page I referred you to earlier, with C versus Java pointers illustrated in the concrete. Hence, since every name and literal above stands for a copyable reference, and since a copyable reference is a pointer, every name and literal above stands for a pointer -- that's /all/ that you handle directly in Python, namely pointers. But if that terminology sounds bad or has too strong C-vibes or Java-vibes or whatever, then we just need some other term for a Python "copyable reference". > If you're talking to the person who writes Python code, then you should > discuss the sorts of things that exist in Python: objects and names and > expressions, but no pointers. Well, given this terminology debate we may need some other term. But IMHO the horse drawing the wagon needs to be mentioned to the potential wagon driver, whatever that horse is called -- fourfooter, drawing-animal... Anything else seems just senseless, meaningless abstraction, replacing one simple single concept with a load of connections and special case rules. > If you're talking about the Python virtual machine, instead of the high- > level Python code, then you should say so -- but there are still no > pointers in the VM. Look at the output of dis.dis and you will see > objects pushed onto a stack, but no pointers. I don't think you will see any Python objects pushed on the stack. But you will see copyable object references pushed on the stack. That is, you will see pointers pushed on the stack. > It's not until you get past the level of Python code, past the virtual > machine, and into the implementation of the virtual machine, that you > will finally find pointers. There too. > But why stop there? If somebody asks you a question about Python, and you > choose to ignore them and answer a different question about one > particular implementation's internals instead, I don't see why you stop > there. Why not go down another layer and talk about copying bytes, or two > layers and answer that Python does call-by-bit-flipping, or a layer below > that and say it's all done by varying potential differences? I think a good professional programmer knows about all these levels. Unfortunately, at least about 10 years ago students fresh out of college in Norway did not know about "internal" things such as call stacks, which led them to adopt many Unholy Programming Practices and to be Extremely Baffled by things such as stack traces. > You shouldn't expect your listener to understand machine code to > understand Python's high-level behaviour, nor should you expect them to > be C coders. You don't need to understand pointers to understand a > language that doesn't support them. From the above comments it seems you're thinking about C pointers. To prevent that misconception I've defined the term "pointer" in every or most every posting I've made in this thread, including this posting. I've also posted a link to a Stanford University page with a simple-words explanation (they even have an animated Bunny video, although I've not looked at it); it's CS 101. You don't have anything /but/ pointers in Python. So pointers are key -- by whatever name. [snip] > Java programmers suffer for a bad mental model just as much as Python > programmers. Yes. :-) > All this is because of two conceptual mistakes: (1) the Java community > has conflated the internals of what happens in the implementation of the > Java VM with high-level Java code; and (2) a refusal to accept that there > are calling strategies other than pass-by-value and pass-by-reference. I'm not entirely sure about causes, but there is a tendency in general for humans to go from one extreme to another that they regard as "opposite". Using the term "call by value" for the Java (and Python) parameter passing is just Wrong(TM), at least without a clear understanding of what can be passed. Using "call by value" in a description of that model, mentioning very clearly what's passed, is on the other hand very practical: it's short, succinct & correct. Cheers & hth., - Alf From sivaits4u at gmail.com Tue Feb 9 02:20:22 2010 From: sivaits4u at gmail.com (Bujji) Date: Tue, 9 Feb 2010 12:50:22 +0530 Subject: event handling in pyuthon Message-ID: <581ce2791002082320t2af425ffif36e6683e08cd038@mail.gmail.com> hi all, any event handling mechanisms in python ? i want event handler examples in python Thanks Bujji -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.nospam at rudin.co.uk Tue Feb 9 02:29:33 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 09 Feb 2010 07:29:33 +0000 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: <873a1a3m02.fsf@rudin.co.uk> Steven D'Aprano writes: > On Mon, 08 Feb 2010 14:43:46 -0800, Aahz wrote: > >>>> WARNING: eval() is almost always the wrong answer to any question >>> >>>warning : it works ! >> >> Works for what? > > Code injection security bugs, of course. > > http://en.wikipedia.org/wiki/Code_injection > > It is surprisingly difficult to sanitize strings in Python to make them > safe to pass to eval. Unless you are prepared to trust the input data > explicitly, it's best to just avoid eval. Despite the fact that it's used in the standard library... From gherron at digipen.edu Tue Feb 9 02:35:51 2010 From: gherron at digipen.edu (Gary Herron) Date: Mon, 08 Feb 2010 23:35:51 -0800 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> Message-ID: <4B711057.9030003@digipen.edu> spike wrote: > On Feb 8, 1:35 pm, Gary Herron wrote: > >> spike wrote: >> >>> Has anyone been able to come across a Python logic map or Python logic >>> flow chart? >>> >>> An example can be seen on the right under History: >>> http://en.wikipedia.org/wiki/Usenet#History >>> >>> This would be very helpful for all users. >>> >> Huh??? What aspect of Python were you thinking of mapping out? >> >> Your example us a bad ascii art graph of -- I've no clue what? >> >> Gary Herron >> > > Do you know what "Logic" means? Guess not. Before you comedians quit > your day job some people are looking for information. If you have > nothing positive to say, go pester somewhere else. > > Grow up. > Why the attitude? I wouldn't have asked for a clarification if I didn't want to help. However, I seriously have *no* idea what the OP has asked for when he says "Python logic map". Do you? If so, then answer the poor guy's question instead of whining at me. (And I'll respectfully read your answer, just to see how you interpret "Python logic map".) And I still claim that the example he aimed us at does not help in figuring out what he's asking. It's a (nearly) 30 year old ascii-art drawing of the connectivity between (mostly university and government research lab ) computers that comprised the UUCP/USENET and ARPANET -- the precursor to today's internet. BUT, that begs the question: What does an old network connectivity chart have to do with a "Python logic map"? If the OP is asking for a way to draw flow charts of Python programs, then why is his example of something that is *not* a flow chart, and drawn with 30 year old technology to boot. If he is asking for a way to draw some kind of a connectivity graph, then I have to ask: Connectivity of what? -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From austin.bingham at gmail.com Tue Feb 9 02:39:49 2010 From: austin.bingham at gmail.com (Austin Bingham) Date: Tue, 9 Feb 2010 08:39:49 +0100 Subject: C/C++ Import In-Reply-To: References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: Just to elaborate on Terry's point a bit, sys.path is influenced (in part) by the PYTHONPATH environment variable. If you find that the directory containing 'python' is not in sys.path (which you can check with 'import sys; print sys.path'), add that directory to PYTHONPATH and try again. This may not be the solution you ultimately end up using, but it'll get you pointed in the right direction. Austin On Mon, Feb 8, 2010 at 5:52 PM, Terry Reedy wrote: > On 2/7/2010 10:56 PM, 7H3LaughingMan wrote: >> >> To make the background information short, I am trying to take a >> program that uses Python for scripting and recompile it for Linux >> since it originally was built to run on Win32. The program itself was >> designed to be able to be compiled on Linux and someone made there on >> release with source that added python scripting. After some issues I >> got it to compile but now it is unable to import the files that it >> needs. >> >> The program is running the following code... >> PyImport_Import( PyString_FromString("python.PlayerManager") ); >> >> This is meant to import the file PlayerManager.py inside of the python >> folder. However it throws the following Python Error (Gotten through >> PyErr_Print()) >> ImportError: No module named python.PlayerManager >> >> I am using 2.6.4 so I can't call it by the filename, does anyone know >> how to do a proper import? > > Your 'python' package directory must be in a directory listed in sys.path. I > would print that check. > > -- > http://mail.python.org/mailman/listinfo/python-list > From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 03:11:02 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 08:11:02 GMT Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> <873a1a3m02.fsf@rudin.co.uk> Message-ID: On Tue, 09 Feb 2010 07:29:33 +0000, Paul Rudin wrote: >> It is surprisingly difficult to sanitize strings in Python to make them >> safe to pass to eval. Unless you are prepared to trust the input data >> explicitly, it's best to just avoid eval. > > Despite the fact that it's used in the standard library... Wisely or not, the standard library implicitly trusts it's input. That's one of the many reasons why it's so hard to have a restricted subset of Python. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 03:21:48 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 08:21:48 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: On Tue, 09 Feb 2010 08:19:56 +0100, Alf P. Steinbach wrote: > You don't have anything /but/ pointers in Python. x = 5 y = "hello" You want us to accept that the values of x and y are some mysterious pointer entities rather than the integer object 5 and the string object "hello". At the point that your explanation depends on the reader understanding that the value of a variable x is not actually the thing that they assign to x, but some mysterious, invisible entity that exists entirely inside the implementation where the user can never reach, you probably should rethink your attachment to that explanation. No wonder so many Java programmers are still confused by it. It might help your case if we had a word for the thing that is actually assigned to the variable. In plain English that is "value", but you want to use that for the pointer to the thing-that-we-otherwise-would-call- value, which leaves us no simple way to talk about the int 5 and string "hello". -- Steven From deets at nospam.web.de Tue Feb 9 03:40:16 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Feb 2010 09:40:16 +0100 Subject: Doctests and decorated methods don't get along In-Reply-To: <037d435d$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <7tclbhF8ttU1@mid.uni-berlin.de> Am 06.02.10 12:48, schrieb Steven D'Aprano: > It seems that doctest doesn't discover or execute doctests in methods > which have been decorated. > > > Here is my test file: > > # ====== > class MyStaticMethod(object): > """Emulate built-in staticmethod descriptor.""" > def __init__(self, f): > self.f = f > def __get__(self, obj, objtype=None): > return self.f > > class Test(object): > def method1(self): > """Doc string > > >>> print 'x' > x > """ > > @staticmethod > def method2(): > """Doc string > > >>> print 'y' > y > """ > > @MyStaticMethod > def method3(): > """Doc string > > >>> print '***' # This test should fail. > z > """ > > if __name__ == '__main__': > import doctest > doctest.testmod(verbose=True) > # ====== > > > and here is the output using Python 2.6.4: > > [steve at sylar python]$ python2.6 test_doctests.py > Trying: > print 'x' > Expecting: > x > ok > Trying: > print 'y' > Expecting: > y > ok > 5 items had no tests: > __main__ > __main__.MyStaticMethod > __main__.MyStaticMethod.__get__ > __main__.MyStaticMethod.__init__ > __main__.Test > 2 items passed all tests: > 1 tests in __main__.Test.method1 > 1 tests in __main__.Test.method2 > 2 tests in 7 items. > 2 passed and 0 failed. > Test passed. > > > It doesn't even see method3, let alone run the tests. > > > This looks like bug to me. Have I missed anything? > > Any work arounds? Use functools.wraps to preserve some essential parts of the function declaration. def my_static(f): @wraps(f) def _d(*args, **kwargs): return f(*args, **kwargs) return _d Diez From deets at nospam.web.de Tue Feb 9 03:47:42 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Feb 2010 09:47:42 +0100 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <7tclpfFccvU1@mid.uni-berlin.de> Am 09.02.10 07:00, schrieb OdarR: > On 9 f?v, 02:50, Jean-Michel Pichavant wrote: >> Aahz wrote: >>> In article<0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, >>> OdarR wrote: >> >>>> and with eval(), did you try ? >> >>> WARNING: eval() is almost always the wrong answer to any question >> >> Some say that eval is evil ! >> >> JM > > go to hell ;-), it is part of the language, it seems to match the > aforementioned question. And if the extension happens to be valid python-code, you might inject code malus code through the filename. Great idea! globals()["function_" + ext]() is all you need, and doesn't suffer from that attack vector. Diez From george.sakkis at gmail.com Tue Feb 9 03:54:08 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Tue, 9 Feb 2010 00:54:08 -0800 (PST) Subject: To (monkey)patch or not to (monkey)patch, that is the question Message-ID: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> I was talking to a colleague about one rather unexpected/undesired (though not buggy) behavior of some package we use. Although there is an easy fix (or at least workaround) on our end without any apparent side effect, he strongly suggested extending the relevant code by hard patching it and posting the patch upstream, hopefully to be accepted at some point in the future. In fact we maintain patches against specific versions of several packages that are applied automatically on each new build. The main argument is that this is the right thing to do, as opposed to an "ugly" workaround or a fragile monkey patch. On the other hand, I favor practicality over purity and my general rule of thumb is that "no patch" > "monkey patch" > "hard patch", at least for anything less than a (critical) bug fix. So I'm wondering if there is a consensus on when it's better to (hard) patch, monkey patch or just try to work around a third party package that doesn't do exactly what one would like. Does it have mainly to do with the reason for the patch (e.g. fixing a bug, modifying behavior, adding missing feature), the given package (size, complexity, maturity, developer responsiveness), something else or there are no general rules and one should decide on a case-by-case basis ? George From klausneuner72 at googlemail.com Tue Feb 9 04:04:20 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Tue, 9 Feb 2010 01:04:20 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> > go to hell ;-), it is part of the language, it seems to match the > aforementioned question. Thats right. In fact, your code is the precise analogy of my Prolog example in Python. Obviously, eval() and call() are both inherently dangerous. They should never be used in programs that are used in programs that get input from people other than the author. Yet, my program is supposed to parse files that I have created myself and that are on my laptop. It is not supposed to interact with anybody else than me. On the other hand, I think, it is worthwhile getting acquainted with the getattr-stuff, because this method can be useful in many contexts. Anyway, thanks to all who participated in this thread. It taught me a lot. From alfps at start.no Tue Feb 9 04:08:15 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 10:08:15 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: * Steven D'Aprano: > On Tue, 09 Feb 2010 08:19:56 +0100, Alf P. Steinbach wrote: > >> You don't have anything /but/ pointers in Python. > > x = 5 The above assigns to x a pointer to an object whose value is 5: x ------> 5 > y = "hello" Ditto result: y ------> "hello" And if now do x = y then the code is assigning (copying) to x the pointer in y: x ----------- \ y ---------- > "hello" which you can check by assert( x is y ) or assert( id( x ) == id( y ) ) and which becomes essential to understand when that object is mutable... Like: x = [1, 2, 3, 4] y = "hello" y = x y.append( 5 ) print( x ) > You want us to accept that the values of x and y are some mysterious > pointer entities rather than the integer object 5 and the string object > "hello". The basics of pointers are simple. You can copy pointers (assignment, argument), and you can check for equality (is), and you can refer to the object that's pointed to (attribute access, indexing, operators). And in CPython you can even obtain the pointer value as an integer via id(). So there's nothing mysterious. In particular x = [1, 2, 3, 4] y = x does not copy the object value, it only copies the pointer. That also matters for e.g. x = 10000000*"A" y = x And aliasing, like in the last three examples above, is pretty difficult to understand without a pointer view of things. And if aliasing is not understood, then forever stranded at beginner's level. > At the point that your explanation depends on the reader understanding > that the value of a variable x is not actually the thing that they assign > to x, but some mysterious, invisible entity that exists entirely inside > the implementation where the user can never reach, you probably should > rethink your attachment to that explanation. No wonder so many Java > programmers are still confused by it. Thanks for thinking about my writings. As it happens I've already written about pointers in chapter 2, although not mentioning the word "pointer". :-) I made do with the term "reference", because in Python there's not anything else (in particular there's no pass by reference) that could cause confusion. However, that cop-out (is that the right term?) wouldn't work for text based on a language like C++, which has another kind of reference, or for that matter C# which is like Python and Java except that C# also has pass by reference... Some mixed feedbacks on that writing, but it's section 2.6.7 "References & automatic garbage collection" in ch 2 "Basic concepts" at (I hope I typed the URL correctly). > It might help your case if we had a word for the thing that is actually > assigned to the variable. In plain English that is "value", but you want > to use that for the pointer to the thing-that-we-otherwise-would-call- > value, which leaves us no simple way to talk about the int 5 and string > "hello". There are two values: the pointer value, and the object value. In CPython: >>> a = "blah" >>> str.format( "Pointer = {0}, object = {1}".format( id( a ), a ) ) 'Pointer = 12090272, object = blah' >>> _ More simply, there's the pointer and there's the object pointed to. Or, in the not-very-general-but-I-think-works-in-Python terminology that I used in 2.6.7, there's the reference and there's the object. So the thing that's actually assigned to a variable is in language-independent terminology a "pointer" (or pointer value), although that doesn't mean C or Pascal or whatever specific language pointer but just a copyable object reference, and perhaps in Python-specific terminology it's just a "reference". I don't know better terms... Cheers, - Alf From stefan_ml at behnel.de Tue Feb 9 04:21:29 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Feb 2010 10:21:29 +0100 Subject: intolerant HTML parser In-Reply-To: References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4b712919$0$6584$9b4e6d93@newsspool3.arcor-online.net> Lawrence D'Oliveiro, 08.02.2010 22:39: > In message <4b6fe93d$0$6724$9b4e6d93 at newsspool2.arcor-online.net>, Stefan > Behnel wrote: > >> - generating HTML using a tool that guarantees correct HTML output > > Where do you think these tools come from? Usually PyPI. Stefan From waku at idi.ntnu.no Tue Feb 9 04:51:57 2010 From: waku at idi.ntnu.no (waku) Date: Tue, 9 Feb 2010 01:51:57 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: On Feb 2, 10:49?pm, Jonathan Gardner wrote: > On Feb 2, 2:21?am,waku wrote: [...] > > there are languages where indentation can be either enforced and allow > > one to omit some syntactic nuissance like braces or begin-end clauses, > > or made optional, requiring other syntactic means for delimiting > > blocks etc. ?(consider f# with its #light declaration, for example.) > > If you're writing "experimental code", you're doing it wrong. Every > line of code you write may end up on the space shuttle one day (so to > speak!) Why not write the code well-formatted in the first place, so > that any bugs you introduce are as easily visible as possible? you're missing the large part of the language's customers that use it specifically for experimenting. they're not developing space shuttles, but rather explore available data, experiment with algorithms, etc. (and for space shuttles, i doubt python is the first choice anyway.) yes, i am writing lots of experimental code, and i know many who do, too, and there is *nothing* wrong about it. and then, i sometimes use ipython to interactively experiment, saving the input to a log file, and editing it afterwards as needed. and just the mere fact that i *have* to adapt my editor to ipython's indentation policy (or vice versa) whenever working with others' code because otherwise the code fails, is fairly annoying. there is nothing wrong or stupid about the editor in this respect. > The only reason why you may want to write crap code without proper > formatting is because your text editor is stupid. 'proper' formatting is, in some languages, something achieved by simply running a pretty formatter. in some, it's the job of the programmer. it has nothing to do with the claimed stupidity of the editor. > If that's the case, > get rid of your text editor and find some tools that help you do the > right thing the first time. [...] > If you're text editor has a problem with indenting, you have a > terrible text editor. Period, end of sentence. > you're just wrong. > You can't screw in bolts with a hammer, and you can't level with a > saw. ... and you can't freely format you code with python. > Don't try to write code in any language without a real text 'real'? meaning one able to guess how to combine code from multiple developers with different indentation policies, for example, one using tabs, another four spaces, and yet another eight? (which is not at all uncommon, and not quite wrong or stupid.) > editor that can do proper indentation. Don't let your teammates use > deficient text editors either. I wouldn't appreciate it if I delivered > precision components that my teammates tried to install with > sledgehammers. > > This is the 21st Century. Good text editors are not hard to find on > any platform. 'stupid', 'wrong', 'deficient', 'terrible', ... you're using strong words instead of concrete arguments, it might intimidate your opponents, but is hardly helpful in a fair discussion. vQ From stefan_ml at behnel.de Tue Feb 9 05:01:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Feb 2010 11:01:04 +0100 Subject: use strings to call functions In-Reply-To: <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> Message-ID: <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> Klaus Neuner, 09.02.2010 10:04: > my program is supposed to parse files that I have created myself and that > are on my laptop. It is not supposed to interact with anybody else > than me. Famous last words. Stefan From peloko45 at gmail.com Tue Feb 9 05:06:52 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 9 Feb 2010 02:06:52 -0800 (PST) Subject: Simulating logging.exception with another traceback References: <0c13d3f7-addf-4972-91c3-6f41fadfb2b5@u26g2000yqm.googlegroups.com> <3512c1a4-01e3-449d-8e48-e673e668bb17@u26g2000yqm.googlegroups.com> Message-ID: <1ec8b017-36cc-4ed2-b6d1-52ddc5015d13@b7g2000yqd.googlegroups.com> On 8 feb, 21:13, Vinay Sajip wrote: > On Feb 7, 11:22?am, Joan Miller wrote: > > > > > I would want to get the output from `logging.exception` but with > > traceback from the caller function (I've already all that > > information). > > > This would be the error withlogging.exception: > > -------------------- > > ERROR: > > ? PipeError('/bin/ls -l | ?', 'no command after of pipe') > > Traceback (most recent call last): > > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > > 160, in __call__ > > ? ? raise PipeError(command, 'no command after of pipe') > > PipeError: ('/bin/ls -l | ?', 'no command after of pipe') > > -------------------- > > > And I've trying it with: > > -------------------- > > message = "File \"{0}\", line {1}, in {2}\n\n ?{3}".format( > > ? ? ? ? ? ? ? ? file, line, function, caller)logging.error(message) > > > ERROR: > > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > > ? 163, in __call__ ? ?return self.throw(PipeError, command, 'no > > ? command after of pipe') > > -------------------- > > > Could be used `logging.LogRecord` [1] to get it? How? > > > [1]http://docs.python.org/library/logging.html#logging.LogRecord > > Sorry, Joan, > > I don't understand your question. Can you create a short script which > throws an exception, and show exactly how you want it formatted? > > The logger.exception method does the same as logger.error, except that > it prints exception trace information and is intended to be called > from exception handling clauses. You can format exceptions how you > like by subclassing Formatter and overriding formatException. > > Regards, > > Vinay Sajip Hi! I want to throw `logging.exception()` [1] but using the traceback of caller's function, so: --------- up=1 frame = traceback.extract_stack(limit=up+2) --------- Reading the code, `traceback.print_exception` prints the message from a record got with `LogRecord.getMessage()` [2] So I'm supposed that I'd have to use it to get a new record that can be used by `traceback.print_exception`. [1] http://code.python.org/hg/branches/release2.6-maint-full/file/f5a05355fe48/Lib/logging/__init__.py#l408 [2] http://code.python.org/hg/branches/release2.6-maint-full/file/f5a05355fe48/Lib/logging/__init__.py#l423 From gagsl-py2 at yahoo.com.ar Tue Feb 9 05:11:05 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 07:11:05 -0300 Subject: Need installer recommendation References: <6q2rm5htqdj2puinbg9pmkco8o6nhd72h5@4ax.com> Message-ID: En Sat, 06 Feb 2010 12:45:39 -0300, Alan Biddle escribi?: > I could use a recommendation on a free installer for use by an > unsophisticated programmer, that would be me, for some simple programs > which are a bit more than "Hello World," but only a little. Basically > reading text files and processing the results. Nothing fancy. I am > using PY2EXE to create the distribution. > > In doing the Google, and from past posting here, I see that most > recommendations are for inno and nsis. I expect that either would do > what I want. Is one a better choice for someone to learn enough to do > basic stuff without getting bogged down in details which are not > immediately important? I, for myself, prefer InnoSetup. For a simple and standard installer, just use the wizard to create it, and you're done. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Feb 9 05:11:09 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 07:11:09 -0300 Subject: Pickling an extension type subclasses problems References: Message-ID: En Fri, 05 Feb 2010 11:25:02 -0300, Gaetan de Menten escribi?: > I am trying to write an (optional!) C extension for SQLAlchemy, and I > am struggling to make an extension type picklable *and* using the same > format as the pure Python version (so that computers with the C > extension can unpickle pickles from computers without it and > vice-versa). [...] > My last hope is to define __reduce__ on the Python > side too, That seems reasonable. > and make it use a module-level "reconstructor" function as > follow: > > def mypythontype_reconstructor(cls, state): > obj = object.__new__(cls, state): > .... > return obj > > Will this work? Any other idea? If you're going to call object.__new__(cls, state) anyway, then just return the object's type as the first item in __reduce__; no need to create such global function -- Gabriel Genellina From jeanmichel at sequans.com Tue Feb 9 05:25:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 11:25:42 +0100 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> Message-ID: <4B713826.6010009@sequans.com> Carl Banks wrote: > On Feb 8, 12:20 pm, spike wrote: > >> Has anyone been able to come across a Python logic map or Python logic >> flow chart? >> >> An example can be seen on the right under History:http://en.wikipedia.org/wiki/Usenet#History >> >> This would be very helpful for all users. >> > > > Begin > | > | > V > Start Editor > | > | > V > Write Code <----+ > | | > | | > V | > Run Python | > | | > | | No. > V | > Did it do what you want? > | > | Yes. > | > V > Stop. > > > HTH. > > > Carl Banks > I use this one: Begin | | V Start Mail client | | V Ask python-list <-----+ | | | | V what a bunch of dumbass wait 2 min | | | | | No. V | Did you get any answer ? | | Yes. | V Stop. JM From jeanmichel at sequans.com Tue Feb 9 05:39:58 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 11:39:58 +0100 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <4B713826.6010009@sequans.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> <4B713826.6010009@sequans.com> Message-ID: <4B713B7E.3080302@sequans.com> >> > > I use this one: > > Begin > | > | > V > Start Mail client > | > | > V > Ask python-list <-----+ > | | > | | > V what a bunch of dumbass wait 2 min | > | | > | | No. > V | > Did you get any answer ? > | > | Yes. > | > V > Stop. > > > > JM How to miss a joke thanks to some crappy line word wraping whatsoever feature. I'll burn thunderbird. Don't use it ! JM From duncan.booth at invalid.invalid Tue Feb 9 05:44:57 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 9 Feb 2010 10:44:57 GMT Subject: Modifying Class Object References: Message-ID: "Alf P. Steinbach" wrote: > A copyable reference is a pointer. That is, a "pointer", in e.g. the > Java sense, > and in the general language independent sense, means a copyable > reference -- as illustrated e.g. in the Stanford computer science > 101 course page I > referred you to earlier, with C versus Java pointers illustrated in > the concrete. The fact that C style pointers are used internally is an detail of the CPython implementation. In CPython objects once created remain in the same memory location (and their id is their address). Compare that to IronPython where the objects themselves can move around in memory so they have no fixed address. Try comparing the IronPython implementation to C pointers and you'll cause a lot of confusion. e.g. someone might think the id() value is in some way related to an address. Ruby implements integers without using any pointers at all: there's nothing in the Python specification which prevents a Python implementation doing the same for small integers, in fact I believe it has been tried but wasn't found to improve performance. The terminology of 'objects', 'names', 'references' describes an abstract machine. The Python runtime can implement it in any way it chooses so long as those semantics are preserved. One implementation involves 'pointers', but that word implies other baggage which is not a required part of the model. -- Duncan Booth http://kupuguy.blogspot.com From wolftracks at invalid.com Tue Feb 9 05:50:05 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 09 Feb 2010 02:50:05 -0800 Subject: Socket Error: Permission Denied (Firewall) In-Reply-To: References: Message-ID: (corrected typos) I decided to go with outbound in McAfee. Now when I run the program, I get a long list of messages about deprecations and NumpyTest will be removed in the next release. please update code to nose or unittest. From steve at holdenweb.com Tue Feb 9 07:31:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:31:17 -0500 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> Message-ID: spike wrote: > On Feb 8, 1:35 pm, Gary Herron wrote: >> spike wrote: >>> Has anyone been able to come across a Python logic map or Python logic >>> flow chart? >>> An example can be seen on the right under History: >>> http://en.wikipedia.org/wiki/Usenet#History >>> This would be very helpful for all users. >> Huh??? What aspect of Python were you thinking of mapping out? >> >> Your example us a bad ascii art graph of -- I've no clue what? >> >> Gary Herron > > Do you know what "Logic" means? Guess not. Before you comedians quit > your day job some people are looking for information. If you have > nothing positive to say, go pester somewhere else. > > Grow up. Oh right, we forgot, it's our duty to answer every question that comes in, seriously and to the point, no matter how badly it is phrased and how obnoxious the questioner becomes when the answer is not immediately forthcoming. This is the Intarwebs. I suggest it's *you* who needs to grow up. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 07:38:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:38:42 -0500 Subject: equivalent of Ruby's Pathname? In-Reply-To: <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> Message-ID: Phlip wrote: > Carl Banks wrote: > >> I don't know if it was the reason it was rejected, but a seriously >> divisive question is whether the path should be a subset of string. > > OMG that's nothing but the OO "circle vs ellipse" non-question. Glad > to see the Committee derailed a perfectly good library over such > sophistry. > That's nothing but the most arrant nonsense, as you would discover if you took the trouble to read the discussion on python-dev instead of jumping to conclusions. >> Under ordinary circumstances it would be a poor choice for inheritance >> (only a few string methods would be useful fot a pathname), but some >> people were fiercely adamant that paths should be passable to open() >> as-in (without having to explicity convert to string). > > That's just silly. To be object-based, you should say path.open('r'). > fopen() and its ilk are too 1960s... > What? Are you arguing for "myfile.txt".open('r') to be a valid Python construct? If not then surely you can see that paths would require different treatment from strings, which was the main thrust of the discussion on the dev list. I find it really irritating when the clueless come along and criticize decisions made by the developers after thorough discussion. Not only do decisions have to be made about how code is going to work (and work for the next twenty years or so), but someone has to commit to maintaining the code before it goes in (otherwise Python will be full of bit-rot). To call your criticism ill-informed would be flattering it. > My 5th Grade science teacher, one Eunice Feight, once expressed > chagrin for submitting a proposal to Readers' Digest, and getting it > accepted. She sold them the following sloka: > > Don't be clever don't be witty > Or you'll wind up BEING the Committee! > Criticism isn't pretty Specially when your logic's shitty. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 07:40:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:40:55 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden > wrote: > > Stephen Hansen wrote: > [...] > > P.S. I couldn't resist. :( > > > > And here I was, sitting on my hands ... but someone was wrong on the > Internet, so D'Aprano had to put them right. Your fatal weakness. > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." > > > This is getting out of hand. > > First, someone thought I was you. > > Now you think I'm D'Aprano. > > I'm just gonna go by Bob for now on. > > :) > Sorry about that, Bob. But you have to admit your pedantry was rather D'Aprano-like (I have these feeling I just insulted you both with one sentence). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 07:44:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:44:38 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: Alf P. Steinbach wrote: > * Stephen Hansen: [...] >> I've heard that before, and have no idea why, nor any real interest in >> solving it: I don't want to read cpl via Usenet, and prefer to read it >> as a mailing list. Somewhere between Gmail->python.org->python.org >> 's usenet server->the world, some people don't seem >> to get my posts. Yet it shows up on some news servers, not others. >> >> No idea. Nothing I know of can solve it. > > Not sure, but perhaps it's possible to mail directly to gmane? > Is there *any* problem you don't have a fatuous answer for? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From clp2 at rebertia.com Tue Feb 9 07:52:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Feb 2010 04:52:02 -0800 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> Message-ID: <50697b2c1002090452g502c30c7jaea48a4e4f821a37@mail.gmail.com> On Tue, Feb 9, 2010 at 4:38 AM, Steve Holden wrote: > Phlip wrote: >> Carl Banks wrote: >> >>> I don't know if it was the reason it was rejected, but a seriously >>> divisive question is whether the path should be a subset of string. >> >> OMG that's nothing but the OO "circle vs ellipse" non-question. Glad >> to see the Committee derailed a perfectly good library over such >> sophistry. >> > That's nothing but the most arrant nonsense, as you would discover if > you took the trouble to read the discussion on python-dev instead of > jumping to conclusions. > >>> Under ordinary circumstances it would be a poor choice for inheritance >>> (only a few string methods would be useful fot a pathname), but some >>> people were fiercely adamant that paths should be passable to open() >>> as-in (without having to explicity convert to string). >> >> That's just silly. To be object-based, you should say path.open('r'). >> fopen() and its ilk are too 1960s... >> > What? Are you arguing for "myfile.txt".open('r') to be a valid Python > construct? If not then surely you can see that paths would require > different treatment from strings, which was the main thrust of the > discussion on the dev list. Based on the context, I'm /pretty/ sure he was (implicitly) talking about e.g. Path("myfile.txt").open('r'). Cheers, Chris -- http://blog.rebertia.com From roy at panix.com Tue Feb 9 08:21:35 2010 From: roy at panix.com (Roy Smith) Date: Tue, 09 Feb 2010 08:21:35 -0500 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: In article <00fa27a3$0$15628$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) No pig latin? From phlip2005 at gmail.com Tue Feb 9 09:00:23 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 9 Feb 2010 06:00:23 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > It wouldn't just be open() that people would want modified -- > it would be every other function that takes a pathname as > well. Then refer to the same argument against implicit type conversions in C+ +. A ::std::string must call .c_str() to turn into a lowly char*, before passing into a C function. Advocating for 8 characters of convenience opens the risk of silent bugs at refactor time. > I seem to recall another point of contention was whether > path objects should have methods for accessing the file > system (opening files, renaming them, etc.) or whether it > should confine itself to representing and manipulating > pathnames. In that case, the package I picked seems to have "erred" on the side of programmer convenience. Because the basic file operations (exist, stat, move/rename, copy, open, chmod, unlink) come as a complete and whole kit, a class should simply present that kit, insulating against filesystem differences. > In any case, introducing any kind of path object at this > late stage of the language's development would result in > More Than One Way to represent pathnames, with neither of > them being the obvious choice. Ah, now we get down to the root of the problem. Because Python is so stuck on the "one best way to do it" mentality, language bigotry prevented the Committee from picking from among several equally valid but non-best options. And after 20 years of growth, Python still has no Pathname class. What a mature community! C-: -- Phlip http://c2.com/cgi/wiki?MoreliaViridis From tiagokatcipis at gmail.com Tue Feb 9 09:01:31 2010 From: tiagokatcipis at gmail.com (Tiago Katcipis) Date: Tue, 9 Feb 2010 12:01:31 -0200 Subject: event handling in pyuthon In-Reply-To: <581ce2791002082320t2af425ffif36e6683e08cd038@mail.gmail.com> References: <581ce2791002082320t2af425ffif36e6683e08cd038@mail.gmail.com> Message-ID: <60a9403b1002090601v783534e2q496b499070dbed61@mail.gmail.com> On Tue, Feb 9, 2010 at 5:20 AM, Bujji wrote: > hi all, > any event handling mechanisms in python ? > i want event handler examples in python > dont know if it is this that you are looking for: http://home.gna.org/py-notify/ > > > Thanks > Bujji > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Carolyn.Nevills at fortbend.k12.tx.us Tue Feb 9 09:04:53 2010 From: Carolyn.Nevills at fortbend.k12.tx.us (Nevills, Carolyn) Date: Tue, 9 Feb 2010 08:04:53 -0600 Subject: Plese take me off the mailing list Message-ID: Good morning, Please take my name off your mailing list . Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From twistedphrame at gmail.com Tue Feb 9 09:11:24 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 06:11:24 -0800 (PST) Subject: errno 107 socket.recv issue Message-ID: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> I have a simple tcp server and client where the server sits and waits for a message and then processes it, my client sends its first message to the server. On the server I receive: socket.error: [Errno 107] Transport endpoint is not connected when calling msg = self.socket.recv(self.buffer) My client receives the error: socket.error: [Errno 104] Connection reset by peer when calling msg = self.socket.recv(self.buffer) I was working on the server and client over the weekend and sending and receiving worked fine, I wanted to debug a few things and I get this when I try to run it (no changes made from what I had on the weekend) From ALANBIDDLE70 at YAHOO.COM Tue Feb 9 09:17:40 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Tue, 09 Feb 2010 08:17:40 -0600 Subject: Need installer recommendation References: <6q2rm5htqdj2puinbg9pmkco8o6nhd72h5@4ax.com> Message-ID: Thanks you very much for the suggestion. I will give it a try. Since I posted the original question, I have tried PyInstaller. I am using Python 2.6.4, which is technically not supported, but it worked fine for the simple programs I tried, and simple enough even for me. ;) -- Alan From steve at holdenweb.com Tue Feb 9 09:30:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 09:30:55 -0500 Subject: errno 107 socket.recv issue In-Reply-To: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> Message-ID: Jordan Apgar wrote: > I have a simple tcp server and client where the server sits and waits > for a message and then processes it, my client sends its first message > to the server. On the server I receive: > > socket.error: [Errno 107] Transport endpoint is not connected > when calling > msg = self.socket.recv(self.buffer) > > My client receives the error: > socket.error: [Errno 104] Connection reset by peer > when calling > msg = self.socket.recv(self.buffer) > > I was working on the server and client over the weekend and sending > and receiving worked fine, I wanted to debug a few things and I get > this when I try to run it (no changes made from what I had on the > weekend) My car has this problem. It makes a noise when it rolls along the road. I've brought the wheel for you to take a look at, can you fix it, please? ;-) A little more context might be helpful - at least the error traceback and the code that makes the socket calls. I presume you are using TCP judging by the client error message. This implies the server isn't listening. Have you correctly bound the socket to an IP address and port before issuing an accept() call? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From misceverything at gmail.com Tue Feb 9 09:52:26 2010 From: misceverything at gmail.com (T) Date: Tue, 9 Feb 2010 06:52:26 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> On Feb 8, 2:25?pm, David Bolen wrote: > T writes: > > I have a script, which runs as a Windows service under the LocalSystem > > account, that I wish to have execute some commands. ?Specifically, the > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > an admin account, all is well. ?However, when I'm running it via > > service, no luck. ?I'm assuming this is to do with the fact that it's > > trying to run under the LocalSystem account, which is failing. ?What > > would be the best way around this? ?Thanks! > > The LocalSystem account is not, if I recall correctly, permitted to > access the network. > > You'll have to install the service to run under some other account that > has appropriate access to the network. > > -- David The more testing I do, I think you may be right..I was able to get it to work under a local admin account, and it worked under debug mode (which would also have been running as this user). I'm a bit surprised though - I was under the assumption that LocalSystem had rights to access the network? From jeanmichel at sequans.com Tue Feb 9 09:56:41 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 15:56:41 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> Message-ID: <4B7177A9.30809@sequans.com> Jordan Apgar wrote: > I have a simple tcp server and client where the server sits and waits > for a message and then processes it, my client sends its first message > to the server. On the server I receive: > > socket.error: [Errno 107] Transport endpoint is not connected > when calling > msg = self.socket.recv(self.buffer) > > My client receives the error: > socket.error: [Errno 104] Connection reset by peer > when calling > msg = self.socket.recv(self.buffer) > > I was working on the server and client over the weekend and sending > and receiving worked fine, I wanted to debug a few things and I get > this when I try to run it (no changes made from what I had on the > weekend) > Unless you want to know more about net coding, I would suggest to use libraries for that. Pyro or xmlrpclib are among the most used. Then if you have any connection problem, that's because there is a connection problem. Not because you mess up with your net code. JM From python-url at phaseit.net Tue Feb 9 10:03:02 2010 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 9 Feb 2010 15:03:02 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Feb 9) Message-ID: QOTW: "You see? That's what I like about the Python community: people even apologise for apologising :)" - Tim Golden http://groups.google.com/group/comp.lang.python/msg/858d1c31d0c2adff The third alpha version of Python 2.7 is ready for testing: http://groups.google.com/group/comp.lang.python/t/6f49dacfe8759508/ How to enumerate all possible strings matching a given regular expression: http://groups.google.com/group/comp.lang.python/t/1b78346c6661ac4f/ Which language features do you like most? http://groups.google.com/group/comp.lang.python/t/599b3c9772421ece/ Implementing a two-dimensional array in a simple way seems to actually be more efficient than other, more sophisticated alternatives: http://groups.google.com/group/comp.lang.python/t/55e595d6dc4ca3f4/ The new GIL (to be implemented in Python 3.2) will provide less overhead, especially in multicore CPUs: http://groups.google.com/group/comp.lang.python/t/586ef2d3685fa7ea/ In Python 3, 'exec' inside a function does not have the same effect as before: http://groups.google.com/group/comp.lang.python/t/7a046e4ede9c310a/ Using Queue objects to feed and synchronize several worker threads: http://groups.google.com/group/comp.lang.python/t/32256dd608c9c02/ New generation IDEs should provide much better and integrated refactoring tools: http://groups.google.com/group/comp.lang.python/t/e019614ea149e7bd/ There is no module in the standard library to handle filesystem paths in an OO way - but why? http://groups.google.com/group/comp.lang.pythonf580fb3763208425ece/ A "History Channel" special: how the way a TAB key was interpreted changed over time http://groups.google.com/group/comp.lang.python82d9181fcd31ffea3f4/ After a false start, finally we get our first "Is it Call-By-Value or Call-By-Reference?" thread of the year! http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From twistedphrame at gmail.com Tue Feb 9 10:20:33 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 07:20:33 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> Message-ID: <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> I found my car ;) here's the server: class commServer: """Class to hold a tcp server and interact with with it allows for a wrapper around socket class to keep code clean""" def __init__ (self, host, hostid, port, buff =1024): self.host = host self.hostid = hostid #id of the server self.port = port self.buffer = buff self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.conn = None self.addr = None def bindServ(self): """Connect to the server specified by self.host, self.port""" self.socket.bind((self.host, self.port)) def closeConn(self): """Disconnect from the server connected to""" self.conn.close() def listen(self): self.socket.listen(1) def accept(self): self.conn, self.addr = self.socket.accept() #lets you send a string msg to the server def sendMSG(self, msg): self.conn.send(msg) #lets you receive data from the server def recvMSG(self): msg = self.socket.recv(self.buffer) if msg == "": #if the client disconnected let's not throw return False else: return msg class Negotiator: """Negotiator for the server handles all communication with the client to verify the server and prepare the file the client wants for download""" def __init__(self, host, hostid, port, rsa_key): self.server = commServer(host,hostid,port) def Negotiate(self): self.server.bindServ() self.server.listen() self.server.accept() #Plan on being asked for server confirmation clmsg = self.server.recvMSG() # it fails right here on the server calling the Server Negotiator as: host = "127.0.0.1" port = 8005 HOSTID = a string key = an RSA key servernegotiator = Negotiator(host,HostID, port, key) if servernegotiator.Negotiate() == False: print "something went wrong" print "Done" for the client it is: class commClient: """Class to hold a tcp client and interact with with it allows for a wrapper around socket class to keep code clean""" def __init__ (self, host, hostid, port, buff =1024): self.host = host self.hostid = hostid #id of the server self.port = port self.buffer = buff self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def connectServ(self): """Connect to the server specified by self.host, self.port""" self.socket.connect((self.host, self.port)) def disconnServ(self): """Disconnect from the server connected to""" self.socket.close() #lets you send a string msg to the server def sendMSG(self, msg): self.socket.send(msg) #lets you receive data from the server def recvMSG(self): msg = self.socket.recv(self.buffer) if msg == "": #if the server disconnected let's not throw something later return False else: return msg class Negotiator: """The Negotiator handles all communications and message handling necessary for verifying the server, and that the file is available to download""" def __init__(self, host, hostid, port, rsa_key): """client should be a commClient object that has not been connected to the server.""" self.client = commClient(host, hostid, port) self.clientKey = rsa_key self.serverKey = None self.CScipher = None #AES cipher for client -> server self.SCcipher = None #AES cipher for server -> client self.CShalves = None #tuple for random halves by client self.SChalves = None #tuple for random halves by server self.file = None def Negotiate(self, fname): """Contact the server, verify the server, negotiates for a file to be downloaded by the client. It returns the file name to be downloaded, and the cipher to decrypt it.""" self.client.connectServ() print "connected" #tell the server you want to connect clmsg = message(CONN, (self.client.getHost(), self.client.getHostID())) #message acts as a wrapper around a message type and the data for the type self.client.sendMSG(clmsg.getSendable()) # here is were it fails the Negotiator is called as: host = "127.0.0.1" port = 8005 HOSTID is the same string as before key is an RSA key clientnegotiator = Negotiator(host, HostID, port, key) filename = clientnegotiator.Negotiate("hostid") the stack traces are: Server side: Traceback (most recent call last): File "Server.py", line 17, in if servernegotiator.Negotiate() == False: File "/home/twistedphrame/Desktop/communication/ ServerNegotiator.py", line 184, in Negotiate clmsg = self.server.recvMSG() File "/home/twistedphrame/Desktop/communication/ ServerNegotiator.py", line 67, in recvMSG msg = self.socket.recv(self.buffer) socket.error: [Errno 107] Transport endpoint is not connected Client Side: File "Client.py", line 17, in filename = clientnegotiator.Negotiate("hostid") File "/home/twistedphrame/Desktop/communication/ ClientNegotiator.py", line 209, in Negotiate srvmsg = self.client.recvMSG() File "/home/twistedphrame/Desktop/communication/ ClientNegotiator.py", line 55, in recvMSG msg = self.socket.recv(self.buffer) socket.error: [Errno 104] Connection reset by peer From gnarlodious at gmail.com Tue Feb 9 10:21:28 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 07:21:28 -0800 (PST) Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> Message-ID: On Feb 9, 12:15?am, Raymond Hettinger wrote: > You may be able to monkey patch an OrderedDict into the PlistParser. > Here's an untested stab at it: > > ? ? from collections import OrderedDict > ? ? import plistlib > ? ? plistlib._InteralDict = OrderedDict Genius! After fixing the misspelled InteralDict I got this: from collections import OrderedDict import plistlib plistlib._InternalDict = OrderedDict plistlib.readPlist('/path/to/some.plist') --> OrderedDict([('List', 'of'), ('tuples', 'in'), ('plist', 'order')]) So thank you for that [somewhat contorted] solution. (PyN00b): Now how do I extract the list from the function? -- Gnarlie From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 9 10:23:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Feb 2010 16:23:59 +0100 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <4b717e07$0$14666$426a34cc@news.free.fr> Phlip a ?crit : > Gregory Ewing wrote: > >> In any case, introducing any kind of path object at this >> late stage of the language's development would result in >> More Than One Way to represent pathnames, with neither of >> them being the obvious choice. > > Ah, now we get down to the root of the problem. Because Python is so > stuck on the "one best way to do it" > mentality, language bigotry > prevented the Committee from picking from among several equally valid > but non-best options. You failed to actually _read_ what you're answering to. Try again. Using your brain, this time. From apt.shansen at gmail.com Tue Feb 9 10:27:06 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:27:06 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> On Mon, Feb 8, 2010 at 10:35 PM, Alf P. Steinbach wrote: > Right. > > "pass by value" is a lower level notion. > > And as you show below, in the paragraph marked [1], it can be used to > describe call by sharing very succinctly and precisely, just as I did... ;-) No. There's nothing at all succinct or precise about either "value" or "reference" when speaking of programming languages, and using both together just compounds that. They are loaded words. The phrase "call my value where value is an object reference" is not clear, not obvious, not helpful. It requires far too much explanation of every single word there, depending on the background of who you are speaking to, to explain how it does not exactly use any of the words in a way which the person may be expecting, and making sure they understand that it does not imply anything that those words usually imply. I'm not even going to bother further-- I shouldn't have to begin with-- your entire post is full of arguments with no more weight then, "I say this means that, and its clearer" with absolutely no regard for the fact that all of these words have weight and meaning to the world outside of your head. Python has objects, and objects have names. Objects are never copied implicitly, and objects can be referred to by many names in many places, thus you may share those objects as you see fit. Some objects you may change, some objects you may not. An object exists so long as someone has a name for it. Period, end of line. That's the mental model and passing model that is valid in Python. There are no "copyable references", because a reference is a 'thing' and copying it is an action. In Python there are simply objects. That's where the abstraction begins and ends. What is so obvious, precise, succinct and clear to YOU is mixing loaded terms with a implications and semantic expectations from countless other languages and sources in computer science. If you want to think of things that way in your head, then by all means, do so. But it doesn't make it right, and further arguing is clearly just not going to do any good. You're insisting on using imprecise terminology common to other languages in complicated ways together to describe very simple things. Python has objects, objects are given various names. It helps no one to try to artificially create an abstraction above that which the language provides as you are doing. I've heard that before, and have no idea why, nor any real interest in >> solving it: I don't want to read cpl via Usenet, and prefer to read it as a >> mailing list. Somewhere between Gmail->python.org->python.org < >> http://python.org>'s usenet server->the world, some people don't seem to >> get my posts. Yet it shows up on some news servers, not others. >> >> >> No idea. Nothing I know of can solve it. >> > > Not sure, but perhaps it's possible to mail directly to gmane? > I participate with the community via python-list; I take no responsibility for the deficiency of any particular usenet server which may or may not mirror python-list accurately. Usenet's a fuzzy thing like that, with all the servers cross-sharing and messages bouncing around. I have no need for its complexity and unbounded freedom. I'm subscribed to a mailing list, albeit a high-volume one. That its cross-mirrored with a usenet group is something I have no control over, and usenet is inherently beyond control. Its great that Gmane provides a means of making usenet discussion groups accessible as mailing lists, but I don't see any reason to bother. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericthecyclist at gmail.com Tue Feb 9 10:27:39 2010 From: ericthecyclist at gmail.com (CyclingGuy) Date: Tue, 9 Feb 2010 07:27:39 -0800 (PST) Subject: PostgreSQL driver for Python applications that supports bytea correctly? Message-ID: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Can anyone recommend a PostgreSQL driver for Python that supports selecting and inserting bytea types? I'm not looking to write server functions in Python, just client applications. Thank you Eric. From mgedmin at gmail.com Tue Feb 9 10:32:54 2010 From: mgedmin at gmail.com (Marius Gedminas) Date: Tue, 9 Feb 2010 07:32:54 -0800 (PST) Subject: Python-URL! - weekly Python news and links (Feb 9) References: Message-ID: The last three URLs are malformed: On Feb 9, 5:03?pm, "Gabriel Genellina" wrote: > ? ? There is no module in the standard library to handle filesystem paths > ? ? in an OO way - but why? > ? ? ? ?http://groups.google.com/group/comp.lang.pythonf580fb3763208425ece/ > > ? ? A "History Channel" special: how the way a TAB key was interpreted > ? ? changed over time > ? ? ? ?http://groups.google.com/group/comp.lang.python82d9181fcd31ffea3f4/ > > ? ? After a false start, finally we get our first "Is it Call-By-Value or > ? ? Call-By-Reference?" thread of the year! > ? ? ? ?http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ Any chance of getting them fixed? Regards, -- Marius Gedminas From apt.shansen at gmail.com Tue Feb 9 10:34:57 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:34:57 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> Message-ID: <7a9c25c21002090734v324f8b5bic6d2bc675bce8cbe@mail.gmail.com> On Tue, Feb 9, 2010 at 4:40 AM, Steve Holden wrote: > Stephen Hansen wrote: > > This is getting out of hand. > > > > First, someone thought I was you. > > > > Now you think I'm D'Aprano. > > > > I'm just gonna go by Bob for now on. > > > > :) > > > Sorry about that, Bob. But you have to admit your pedantry was rather > D'Aprano-like (I have these feeling I just insulted you both with one > sentence). > I'm not sure how I feel about the word /pedantry/ to describe what I have to say (in fact, I sort of thought it might be better applied to the other side of the discussion), but I don't see anything terribly insulting with being confused with the other Ste[ph|v]en's floating around python-list, even allowing for blowhard tendencies we may or may not have. :) Even if I'm the only one who can spell his name right. :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Feb 9 10:37:42 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:37:42 -0800 Subject: Python-URL! - weekly Python news and links (Feb 9) In-Reply-To: References: Message-ID: <7a9c25c21002090737o13b1fd48p8b688d5640eefead@mail.gmail.com> On Tue, Feb 9, 2010 at 7:03 AM, Gabriel Genellina wrote: > After a false start, finally we get our first "Is it Call-By-Value or > Call-By-Reference?" thread of the year! > http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ LOL. Can we set up some sort of "argh" filter on python-list, analogous to a spam filter, which detects these threads and shunts them to python-list-ohnoyoudidnt at python.org? Because avoiding them is -hard-. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Feb 9 10:37:50 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 9 Feb 2010 16:37:50 +0100 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) > > and others. > > DISCLAIMER: obfuscate is not cryptographically strong, and should not be > used where high security is required. (The ciphers provided in obfuscate > may have been state of the art centuries ago, but should not be used > where strong encryption is required. > > obfuscate is released under the MIT licence. > > Requires Python 2.5 or 2.6. Great, these packages are badly needed! If the code base stabilizes in a production version after losing the alphas and betas they would be a great addition to the stdlib, I think. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From apt.shansen at gmail.com Tue Feb 9 10:47:35 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:47:35 -0800 Subject: To (monkey)patch or not to (monkey)patch, that is the question In-Reply-To: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: <7a9c25c21002090747w39f4ec30i910557c79a8dcb29@mail.gmail.com> On Tue, Feb 9, 2010 at 12:54 AM, George Sakkis wrote: > So I'm wondering if there is a consensus on when it's better to (hard) > patch, monkey patch or just try to work around a third party package > that doesn't do exactly what one would like. Does it have mainly to do > with the reason for the patch (e.g. fixing a bug, modifying behavior, > adding missing feature), the given package (size, complexity, > maturity, developer responsiveness), something else or there are no > general rules and one should decide on a case-by-case basis ? > IMHO, monkey-patching is one of those things that you shouldn't really mention in the public without looking both ways, leaning in, and lowering your voice. Its not that its -bad- exactly, and its really not terribly kinky or obscene, but its something that you still shouldn't exactly do in polite company, y'know? There's no guarantees it'll work forever, so its not the safest practice, but if you're willing to accept the burden (and ideally have a unit test proving that it still functions after an update to such a package), then... consenting adults! Go ahead. If you can get the upstream package to make such a thing not necessary, that's ideal-er, of course. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Feb 9 10:48:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 16:48:39 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> Message-ID: <4B7183D7.2010805@sequans.com> Jordan Apgar wrote: > I found my car ;) > > here's the server: > > class commServer: > """Class to hold a tcp server and interact with with it > allows for a wrapper around socket class to keep code clean""" > > def __init__ (self, host, hostid, port, buff =1024): > self.host = host > self.hostid = hostid #id of the server > self.port = port > self.buffer = buff > self.socket = socket.socket(socket.AF_INET, > socket.SOCK_STREAM) > self.conn = None > self.addr = None > > def bindServ(self): > """Connect to the server specified by self.host, self.port""" > self.socket.bind((self.host, self.port)) > def closeConn(self): > """Disconnect from the server connected to""" > self.conn.close() > def listen(self): > self.socket.listen(1) > def accept(self): > self.conn, self.addr = self.socket.accept() > > #lets you send a string msg to the server > def sendMSG(self, msg): > self.conn.send(msg) > #lets you receive data from the server > def recvMSG(self): > msg = self.socket.recv(self.buffer) > if msg == "": #if the client disconnected let's not throw > return False > else: > return msg > > > class Negotiator: > """Negotiator for the server handles all communication with the > client to > verify the server and prepare the file the client wants for > download""" > def __init__(self, host, hostid, port, rsa_key): > self.server = commServer(host,hostid,port) > > def Negotiate(self): > self.server.bindServ() > self.server.listen() > self.server.accept() > > #Plan on being asked for server confirmation > clmsg = self.server.recvMSG() # it fails right here on the > server > > > calling the Server Negotiator as: > host = "127.0.0.1" > port = 8005 > HOSTID = a string > key = an RSA key > servernegotiator = Negotiator(host,HostID, port, key) > if servernegotiator.Negotiate() == False: > print "something went wrong" > print "Done" > > > > for the client it is: > class commClient: > """Class to hold a tcp client and interact with with it > allows for a wrapper around socket class to keep code clean""" > > def __init__ (self, host, hostid, port, buff =1024): > self.host = host > self.hostid = hostid #id of the server > self.port = port > self.buffer = buff > self.socket = socket.socket(socket.AF_INET, > socket.SOCK_STREAM) > > def connectServ(self): > """Connect to the server specified by self.host, self.port""" > self.socket.connect((self.host, self.port)) > def disconnServ(self): > """Disconnect from the server connected to""" > self.socket.close() > > #lets you send a string msg to the server > def sendMSG(self, msg): > self.socket.send(msg) > #lets you receive data from the server > def recvMSG(self): > msg = self.socket.recv(self.buffer) > if msg == "": #if the server disconnected let's not throw > something later > return False > else: > return msg > > > > class Negotiator: > """The Negotiator handles all communications and message handling > necessary for verifying the server, and that the file is available > to > download""" > def __init__(self, host, hostid, port, rsa_key): > """client should be a commClient object that has not been > connected > to the server.""" > self.client = commClient(host, hostid, port) > self.clientKey = rsa_key > self.serverKey = None > self.CScipher = None #AES cipher for client -> server > self.SCcipher = None #AES cipher for server -> client > self.CShalves = None #tuple for random halves by client > self.SChalves = None #tuple for random halves by server > self.file = None > > > def Negotiate(self, fname): > """Contact the server, verify the server, > negotiates for a file to be downloaded by the client. It > returns > the file name to be downloaded, and the cipher to decrypt > it.""" > > self.client.connectServ() > print "connected" > > #tell the server you want to connect > clmsg = message(CONN, (self.client.getHost(), > self.client.getHostID())) #message acts > as a wrapper around a message type and the data for the type > self.client.sendMSG(clmsg.getSendable()) # here is were it > fails > > the Negotiator is called as: > host = "127.0.0.1" > port = 8005 > HOSTID is the same string as before > key is an RSA key > clientnegotiator = Negotiator(host, HostID, port, key) > filename = clientnegotiator.Negotiate("hostid") > > the stack traces are: > Server side: > Traceback (most recent call last): > File "Server.py", line 17, in > if servernegotiator.Negotiate() == False: > File "/home/twistedphrame/Desktop/communication/ > ServerNegotiator.py", line 184, in Negotiate > clmsg = self.server.recvMSG() > File "/home/twistedphrame/Desktop/communication/ > ServerNegotiator.py", line 67, in recvMSG > msg = self.socket.recv(self.buffer) > socket.error: [Errno 107] Transport endpoint is not connected > > Client Side: > File "Client.py", line 17, in > filename = clientnegotiator.Negotiate("hostid") > File "/home/twistedphrame/Desktop/communication/ > ClientNegotiator.py", line 209, in Negotiate > srvmsg = self.client.recvMSG() > File "/home/twistedphrame/Desktop/communication/ > ClientNegotiator.py", line 55, in recvMSG > msg = self.socket.recv(self.buffer) > socket.error: [Errno 104] Connection reset by peer > > > http://docs.python.org/library/socketserver.html JM From jeanmichel at sequans.com Tue Feb 9 10:53:35 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 16:53:35 +0100 Subject: PostgreSQL driver for Python applications that supports bytea correctly? In-Reply-To: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> References: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Message-ID: <4B7184FF.7090405@sequans.com> CyclingGuy wrote: > Can anyone recommend a PostgreSQL driver for Python that supports > selecting and inserting bytea types? > I'm not looking to write server functions in Python, just client > applications. > > Thank you > Eric. > Did you try any ? I know about pgdb, and since it has a function called escape_bytea it may support this type... JM From steve at holdenweb.com Tue Feb 9 10:53:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 10:53:52 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Mon, Feb 8, 2010 at 10:35 PM, Alf P. Steinbach > wrote: > > Right. > > "pass by value" is a lower level notion. > > And as you show below, in the paragraph marked [1], it can be used > to describe call by sharing very succinctly and precisely, just as I > did... ;-) > > > No. There's nothing at all succinct or precise about either "value" or > "reference" when speaking of programming languages, and using both > together just compounds that. They are loaded words. The phrase "call my > value where value is an object reference" is not clear, not obvious, not > helpful. It requires far too much explanation of every single word > there, depending on the background of who you are speaking to, to > explain how it does not exactly use any of the words in a way which the > person may be expecting, and making sure they understand that it does > not imply anything that those words usually imply. > > I'm not even going to bother further-- I shouldn't have to begin with-- > your entire post is full of arguments with no more weight then, "I say > this means that, and its clearer" with absolutely no regard for the fact > that all of these words have weight and meaning to the world outside of > your head. > [several paragraphs-worth of bothering further] So you didn't believe me when I said > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Tue Feb 9 10:54:13 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:54:13 -0800 Subject: Programing family In-Reply-To: References: Message-ID: <7a9c25c21002090754r37a63ef2y2e02e47b4179bbeb@mail.gmail.com> On Mon, Feb 8, 2010 at 5:39 PM, AON LAZIO wrote: > I have thought funny things > If we think all languages are like a family > I could draft them like this (Python base) > > C is Python's Mom > I can see this. > C++ : Dad > Ick, no. C++ is the dirty Uncle who gets touchy with us in inappropriate ways. > Pascal/Assembly : Grandparents > o.O > C# : Uncle Java : Aunt If C# and Java are our parents siblings and we're older by quite a bit then them, then... that implies some sort of shady things in our family tree! Maybe Grandpappy married a bombshell just out of high school and managed to knock her up. Then again, we did take some stuff from both. So maybe C# and Java are our neighbors, and our sister had an affair with one of them and got knocked up, and so we got the "logging" package and decorators and. Er. I fail at this analogy. Ruby: Cousin > I can see this. > Perl : Girlfriend > You seriously need to duck and run for cover at this one. Someone on one of our sides is going to throw a rock at you now. :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Tue Feb 9 10:55:47 2010 From: mrkafk at gmail.com (mk) Date: Tue, 09 Feb 2010 16:55:47 +0100 Subject: timer for a function In-Reply-To: <7a9c25c21002081844h5a280e94k794ddc5d0df77610@mail.gmail.com> References: <7a9c25c21002081844h5a280e94k794ddc5d0df77610@mail.gmail.com> Message-ID: Stephen Hansen wrote: > Question: how can I do that? Use another threaded class? Is there > some other way? First of all, thanks for answer! > What OS? Does this have to be OS-independant? Err, sorry -- this is Linux/UNIX only. > Are you using more then > one transport/SSLClient in your process and you want to just kill one > (and any of its child threads), or are you doing one per process? I'm using multiple threads myself, one per IP basically, which in turn call paramiko calls, which itself is threaded. > If you want to terminate -all- threads your process is running in a > given timeframe, using a SIGALRM in the signal module will do it, I > believe-- provided you don't need to support windows. Thanks, that's still useful! Although... 1. if I don't install signal handler for SIGALRM I get this printed on the console at the end of execution: Alarm clock Although it does seem to close cleanly. Is there any way to suppress this message? 2. If I do install signal handler for SIGALRM, I'm back at square one: Exception in thread Thread-25 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap File "./cssh.py", line 1003, in run File "./cssh.py", line 739, in ssh_connect_for_scp File "build/bdist.linux-i686/egg/paramiko/transport.py", line 1006, in connect File "build/bdist.linux-i686/egg/paramiko/transport.py", line 1382, in _log exceptions.TypeError: 'NoneType' object is not callable Unhandled exception in thread started by This happens even though I surround "connect" (line 1006) with catching all Exceptions: try: self.trans.connect(hostkey=None, username=self.username, pkey = pkey) except Exception, e: self.conerror = str(e) >I had a contextlib > manager do that for awhile. If you only want to terminate one (and its > child-threads)... you're out of luck, I think. The only way to terminate > a thread in Python is with conditions/events/whatever and the thread > cooperating and exiting on its own. I will probably have to get the library author look at this. Regards, mk From apt.shansen at gmail.com Tue Feb 9 10:59:13 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:59:13 -0800 Subject: Socket Error: Permission Denied In-Reply-To: References: Message-ID: <7a9c25c21002090759s3c94f2a8wd3ccb18b8faa9012@mail.gmail.com> On Mon, Feb 8, 2010 at 7:38 PM, W. eWatson wrote: > I'm using McAffee. I see it was pythonw.exe blocked in red. There are > several choices: Allow Access, Allow Outboubnd only > Block (current), Remove Prgrm permission, Learn More. > > Outbound only seem reasonable, but why does the blocking keep returning > every many hours, or maybe when I reboot, which I've done several times > today? I can't help you with McAfee, contact their support forums. As for outbound vs anything else... pythonw.exe needs to accept connections at least on the local machine. No idea how to get McAfee to allow that. Outbound may not be sufficient, you may need just Allow. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnarlodious at gmail.com Tue Feb 9 11:07:42 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 08:07:42 -0800 (PST) Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> Message-ID: <663dd630-f029-4b6f-909e-52ce79adbbd1@x1g2000prb.googlegroups.com> On Feb 9, 12:15?am, Raymond Hettinger wrote: > You may be able to monkey patch an OrderedDict into the PlistParser. > Here's an untested stab at it: > ? ? from collections import OrderedDict > ? ? import plistlib > ? ? plistlib._InteralDict = OrderedDict Genius! After fixing the misspelled InteralDict I got this: from collections import OrderedDict import plistlib plistlib._InternalDict = OrderedDict plistlib.readPlist('/path/to/some.plist') --> OrderedDict([('List', 'of'), ('tuples', 'in'), ('plist', 'order')]) So thank you for that [somewhat contorted] solution. To extract the list I am saying this: ordered=plistlib.readPlist(path) print(list(ordered)) # only a list of keys print(ordered[list(ordered)[0]]) However this seems too laborious. is there an easier way? -- Gnarlie From invalid at invalid.invalid Tue Feb 9 11:10:56 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 16:10:56 +0000 (UTC) Subject: How to measure elapsed time under Windows? Message-ID: What's the correct way to measure small periods of elapsed time. I've always used time.clock() in the past: start = time.clock() [stuff being timed] stop = time.clock() delta = stop-start However on multi-processor machines that doesn't work. Sometimes I get negative values for delta. According to google, this is due to a bug in Windows that causes the value of time.clock() to be different depending on which core in a multi-core CPU you happen to be on. [insert appropriate MS-bashing here] Is there another way to measure small periods of elapsed time (say in the 1-10ms range)? Is there a way to lock the python process to a single core so that time.clock() works right? -- Grant Edwards grante Yow! If I felt any more at SOPHISTICATED I would DIE visi.com of EMBARRASSMENT! From rodrick.brown at gmail.com Tue Feb 9 11:13:35 2010 From: rodrick.brown at gmail.com (rodrick brown) Date: Tue, 9 Feb 2010 11:13:35 -0500 Subject: Programing family In-Reply-To: References: Message-ID: <53AA95DE-1589-466E-BEE3-7B95728C766E@gmail.com> Don't forget his little brother Go! Sent from my iPhone 3GS. On Feb 8, 2010, at 8:39 PM, AON LAZIO wrote: > I have thought funny things > If we think all languages are like a family > I could draft them like this (Python base) > > C is Python's Mom > C++ : Dad > Pascal/Assembly : Grandparents > C# : Uncle > Java : Ant > Ruby: Cousin > Perl : Girlfriend > > > What u guys think? XD > -- > Passion is my style > -- > http://mail.python.org/mailman/listinfo/python-list From mail at timgolden.me.uk Tue Feb 9 11:21:17 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Feb 2010 16:21:17 +0000 Subject: Python-URL! - weekly Python news and links (Feb 9) In-Reply-To: <7a9c25c21002090737o13b1fd48p8b688d5640eefead@mail.gmail.com> References: <7a9c25c21002090737o13b1fd48p8b688d5640eefead@mail.gmail.com> Message-ID: <4B718B7D.8050603@timgolden.me.uk> On 09/02/2010 15:37, Stephen Hansen wrote: > On Tue, Feb 9, 2010 at 7:03 AM, Gabriel Genellinawrote: > >> After a false start, finally we get our first "Is it Call-By-Value or >> Call-By-Reference?" thread of the year! >> http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ > > > LOL. > > Can we set up some sort of "argh" filter on python-list, analogous to a spam > filter, which detects these threads and shunts them to > python-list-ohnoyoudidnt at python.org? > > Because avoiding them is -hard-. Oh no it isn't! (Sorry; couldn't resist) TJG From robert.kern at gmail.com Tue Feb 9 11:29:42 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Feb 2010 10:29:42 -0600 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >> I am pleased to announce the first public release of obfuscate 0.2.2a. >> >> http://pypi.python.org/pypi/obfuscate/0.2.2a >> >> obfuscate is a pure-Python module providing classical encryption >> algorithms suitable for obfuscating and unobfuscating text. >> >> obfuscate includes the following ciphers: >> - Caesar, rot13, rot5, rot18, rot47 >> - atbash >> - Playfair, Playfair6 and Playfair16 >> - Railfence (encryption only) >> - Keyword >> - Affine >> - Vigenere >> - frob (xor) >> >> and others. >> >> DISCLAIMER: obfuscate is not cryptographically strong, and should not be >> used where high security is required. (The ciphers provided in obfuscate >> may have been state of the art centuries ago, but should not be used >> where strong encryption is required. >> >> obfuscate is released under the MIT licence. >> >> Requires Python 2.5 or 2.6. > > Great, these packages are badly needed! > > If the code base stabilizes in a production version after losing the > alphas and betas they would be a great addition to the stdlib, I > think. Why? -- 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 jpahonthe at gmail.com Tue Feb 9 11:33:32 2010 From: jpahonthe at gmail.com (r. clayton) Date: Tue, 9 Feb 2010 08:33:32 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> Message-ID: > http://docs.python.org/library/socketserver.html > > JM each time a handler is spawned is it client specific? in other words when two clients send something to the server do handlers spawn for each of them or does everything just go into a single handler? From twistedphrame at gmail.com Tue Feb 9 11:36:25 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 08:36:25 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> Message-ID: <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> > http://docs.python.org/library/socketserver.html > > JM each time a handler is spawned is it client specific? in other words when two clients send something to the server do handlers spawn for each of them or does everything just go into a single handler? From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 9 11:49:21 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Feb 2010 17:49:21 +0100 Subject: Programing family In-Reply-To: References: Message-ID: <4b719209$0$10071$426a34cc@news.free.fr> On Feb 8, 2010, at 8:39 PM, AON LAZIO wrote: > >> I have thought funny things >> If we think all languages are like a family Then it would be a very incestuous family fore sure. >> I could draft them like this (Python base) >> >> C is Python's Mom >> C++ : Dad Not that much C++ in Python, IMHO. If that's for the OO part, then the closer to Python's object model I can think of is javascript. Historically, Python comes from ABC, which itself comes from SETL. >> Pascal/Assembly : Grandparents Assembly ? What about binary machine code then ?-) >> C# : Uncle >> Java : Ant Interesting typo here !-) Hmmm... Python predates both C# and Java. Ok, technically speaking nothing prevents an uncle or aunt from being younger than their nephews, and I even saw the case a couple time - but that's far from being the common case. >> Ruby: Cousin >> Perl : Girlfriend Then it's kind of a very passionate love-hate relationship - bordering on pathological FWIW !-) Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of course Simula and Smalltalk. From darcy at druid.net Tue Feb 9 11:51:15 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 9 Feb 2010 11:51:15 -0500 Subject: PostgreSQL driver for Python applications that supports bytea correctly? In-Reply-To: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> References: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Message-ID: <20100209115115.fd6bd546.darcy@druid.net> On Tue, 9 Feb 2010 07:27:39 -0800 (PST) CyclingGuy wrote: > Can anyone recommend a PostgreSQL driver for Python that supports > selecting and inserting bytea types? > I'm not looking to write server functions in Python, just client > applications. http://www.PyGreSQL.org/ -- 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 no.email at nospam.invalid Tue Feb 9 11:56:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 09 Feb 2010 08:56:14 -0800 Subject: Programing family References: <4b719209$0$10071$426a34cc@news.free.fr> Message-ID: <7xaavi5owh.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of > course Simula and Smalltalk. http://i.imgur.com/1gF1j.jpg From apt.shansen at gmail.com Tue Feb 9 11:57:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 08:57:17 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> Message-ID: <7a9c25c21002090857r2ff4ee51k899c5451e552cf25@mail.gmail.com> On Tue, Feb 9, 2010 at 7:53 AM, Steve Holden wrote: > > [several paragraphs-worth of bothering further] > > So you didn't believe me when I said > > > Of course this won't make the slightest difference. "'When I use a > > word,' said Humpty ..." > It was early, I was barely awake. That paragraph was originally the last one. Apparently some extra bother had to work itself out. I'm pretty sure I got the last of it squeezed out. I swear I /wanted/ to believe you. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Feb 9 12:06:42 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 09:06:42 -0800 Subject: Python 3: Plist as OrderedDict In-Reply-To: <663dd630-f029-4b6f-909e-52ce79adbbd1@x1g2000prb.googlegroups.com> References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> <663dd630-f029-4b6f-909e-52ce79adbbd1@x1g2000prb.googlegroups.com> Message-ID: <7a9c25c21002090906ya5c10c3rb57c4eb19203f00@mail.gmail.com> On Tue, Feb 9, 2010 at 8:07 AM, Gnarlodious wrote: > To extract the list I am saying this: > > ordered=plistlib.readPlist(path) > print(list(ordered)) # only a list of keys > print(ordered[list(ordered)[0]]) > > However this seems too laborious. is there an easier way? > I'm not familiar with plistlib or what you're trying to do-- it'd help if you provided the output from those print's, as I don't have a plist on hand which I can use to test it out and see what you're seeing. But, is "ordered.keys()" or "ordered.items()" what you're trying to get? Or, ordered[ordered.keys()[0]] to get the first one? Or "for key in ordered: print(ordered[key])" which will get the keys in order and print the values according to that order? Basically, I'm not sure what you're actually trying to do. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From half.italian at gmail.com Tue Feb 9 12:09:50 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Tue, 9 Feb 2010 09:09:50 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: On Feb 9, 6:52?am, T wrote: > On Feb 8, 2:25?pm, David Bolen wrote: > > > > > T writes: > > > I have a script, which runs as a Windows service under the LocalSystem > > > account, that I wish to have execute some commands. ?Specifically, the > > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > > an admin account, all is well. ?However, when I'm running it via > > > service, no luck. ?I'm assuming this is to do with the fact that it's > > > trying to run under the LocalSystem account, which is failing. ?What > > > would be the best way around this? ?Thanks! > > > The LocalSystem account is not, if I recall correctly, permitted to > > access the network. > > > You'll have to install the service to run under some other account that > > has appropriate access to the network. > > > -- David > > The more testing I do, I think you may be right..I was able to get it > to work under a local admin account, and it worked under debug mode > (which would also have been running as this user). ?I'm a bit > surprised though - I was under the assumption that LocalSystem had > rights to access the network? You really need a way to see the error you are getting. If you can't get it to show you the error in the shell, set up some logging to a file, and find the error that way. I think the user can access the network just fine, but that maybe plink.exe is not in his path or some such thing. Find the error! From apt.shansen at gmail.com Tue Feb 9 12:14:26 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 09:14:26 -0800 Subject: How to measure elapsed time under Windows? In-Reply-To: References: Message-ID: <7a9c25c21002090914r68310597se5541213279252fd@mail.gmail.com> On Tue, Feb 9, 2010 at 8:10 AM, Grant Edwards wrote: > However on multi-processor machines that doesn't work. > Sometimes I get negative values for delta. According to > google, this is due to a bug in Windows that causes the value > of time.clock() to be different depending on which core in a > multi-core CPU you happen to be on. [insert appropriate > MS-bashing here] > > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > > Is there a way to lock the python process to a single core so > that time.clock() works right? The only time I ever had to do that, I just grabbed: http://svn.python.org/projects/python/trunk/Tools/pybench/systimes.py HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Feb 9 12:25:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Feb 2010 12:25:48 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: On 2/9/2010 12:12 AM, Alf P. Steinbach wrote: > As far as the language spec is concerned the argument passing mechanism > seems to me to be identical to assignments, not just "very much like". Except for the cross-namespace nature of the assignment, yes. Glad you agree. > Your phrase "or objects derived therefrom" seems to imply that immutable > objects can be copied No. Given def f(*args, **kwds): print(args, kwds) the objects bound to args and kwds are a tuple and dict *derived* from (that collect together) the objects passed. Terry Jan Reedy From thomasharrisonnelson at gmail.com Tue Feb 9 12:39:27 2010 From: thomasharrisonnelson at gmail.com (Thomas Nelson) Date: Tue, 9 Feb 2010 09:39:27 -0800 (PST) Subject: mac install Message-ID: I downloaded the 3.1.1 dmg from http://www.python.org/download/releases/3.1.1/ but when I run it I get the error "The folowing install step failed: run postflight script for python documentation." The bugs list has this bug at http://bugs.python.org/issue6934 but it's described as fixed. Is it only fixed for the source version? Where should I go to install? Thanks, Tom From aahz at pythoncraft.com Tue Feb 9 12:40:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Feb 2010 09:40:03 -0800 Subject: pyclutter anyone? References: <4B6BD072.4080006@gmail.com> Message-ID: In article , donn wrote: > >No one uses pyClutter? Never heard of it before. >I have some code, it does not work, but maybe this will start to help >solve the problem: You need to provide some more detail than "does not work". Perhaps this will help: http://www.catb.org/~esr/faqs/smart-questions.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Tue Feb 9 12:47:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Feb 2010 09:47:39 -0800 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: In article , Robert Kern wrote: >On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>> >>> obfuscate is a pure-Python module providing classical encryption >>> algorithms suitable for obfuscating and unobfuscating text. >>> >>> DISCLAIMER: obfuscate is not cryptographically strong, and should not be >>> used where high security is required. (The ciphers provided in obfuscate >>> may have been state of the art centuries ago, but should not be used >>> where strong encryption is required. >> >> Great, these packages are badly needed! >> >> If the code base stabilizes in a production version after losing the >> alphas and betas they would be a great addition to the stdlib, I >> think. > >Why? You missed the white-on-white smiley, I think. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From jeanmichel at sequans.com Tue Feb 9 12:49:51 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 18:49:51 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> Message-ID: <4B71A03F.8070803@sequans.com> Jordan Apgar wrote: >> http://docs.python.org/library/socketserver.html >> >> JM >> > > each time a handler is spawned is it client specific? in other words > when two clients send something to the server do handlers spawn for > each of them or does everything just go into a single handler? > docstring of the example: """ The RequestHandler class for our server. It is instantiated once per connection to the server, and must override the handle() method to implement communication to the client. """ If you want data persistant over connections, store them in your handler class. class MyTCPHandler(SocketServer.BaseRequestHandler): cnxNumber = 0 def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() # just send back the same data, but upper-cased self.request.send(self.data.upper()) cnxNumber +=1 print "handling connection N?%s" % cnxNumber JM From ricaraoz at gmail.com Tue Feb 9 13:00:36 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Tue, 09 Feb 2010 15:00:36 -0300 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4B71A2C4.1060507@gmail.com> Bruce C. Baker wrote: > "Terry Reedy" wrote in message > news:mailman.1929.1265328905.28905.python-list at python.org... > >> Iterators, and in particular, generators. >> A killer feature. >> >> Terry Jan Reedy >> >> > > Neither unique to Python. > > And then're the other killer "features" superfluous ":"s and rigid > formatting! > Hmmmm.... Let's see..... nope, I could not find the "unique" word neither in the subject or in the cited text. I've had a strange feeling last weeks. Two possible explanations come to mind : a) The list is under a concerted troll attack. b) Idiocy is contagious. I wonder which... P.S. : will the indentation of the choices be noticed? Shouldn't I put them within braces? -------------- next part -------------- An HTML attachment was scrubbed... URL: From salman.haq at gmail.com Tue Feb 9 13:02:45 2010 From: salman.haq at gmail.com (slmnhq) Date: Tue, 9 Feb 2010 10:02:45 -0800 (PST) Subject: Incorrect 'Host' header when using urllib2 to access a server by its IPv6 link-local address Message-ID: <6f17b819-0420-41d2-8875-f087d8c392d8@c28g2000vbc.googlegroups.com> I have a snippet of Python code that makes an HTTP GET request to an Apache web server (v 2.2.3) using urllib2. The server responds with an HTTP 400 error presumably because of a malformed 'Host' header. The snippet is quite simple: it creates a url based on IPv6 string literal syntax, then creates a Request object and calls urlopen. def via_urllib2 (addr="fe80::207:b8ff:fedc:636b", scope_id="eth4"): host = "[%s%%%s]:80" % (addr, scope_id) # "[fe80::207:b8ff:fedc: 636b%eth4]" url = "http://"+host+"/system/status/" req = urllib2.Request(url) f = urllib2.urlopen(req) print f.read() The urlopen() throws: HTTPError: HTTP Error 400: Bad Request The Apache error_log reports "Client sent malformed Host header". Googling for "apache Client sent malformed Host header ipv6" I came across the following bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=35122 The problem is that Apache does not handle the scope id in the host header field very well and reports a 400 error. So I tried to override that field by creating my own header in the above snippet: ... req.add_header('Host', "["+urllib.quote(addr)+"]") ... Now the header is simply 'Host: [fe80::207:b8ff:fedc:636b]" (notice the lack of "%eth4"). However, this still results in the same error. I know this is not a problem with urllib2 per say, but I'm posting here in the hope that some Python coder may be knowledgeable enough about HTTP and IPv6 that they might be able to provide an answer. Thank you, Salman From python at rcn.com Tue Feb 9 13:03:25 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 9 Feb 2010 10:03:25 -0800 (PST) Subject: To (monkey)patch or not to (monkey)patch, that is the question References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: <6f5a299b-66a9-43ae-acf7-6d6450f7f240@b1g2000prc.googlegroups.com> On Feb 9, 12:54?am, George Sakkis wrote: > So I'm wondering if there is a consensus on when it's better to (hard) > patch, monkey patch or just try to work around a third party package > that doesn't do exactly what one would like. Does it have mainly to do > with the reason for the patch (e.g. fixing a bug, modifying behavior, > adding missing feature), the given package (size, complexity, > maturity, developer responsiveness), something else or there are no > general rules and one should decide on a case-by-case basis ? I agree that practically beats purity here. Python is a consenting adults language that makes monkey patching possible. It provides a direct way to compensate for someone failing to put hooks in their API. The risk of monkey patching is that if other modules use the patched module, they have no way of knowing that the behavior is changed. IOW, monkey patching is a fragile technique for a large project. Raymond From twistedphrame at gmail.com Tue Feb 9 13:03:45 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 10:03:45 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> Message-ID: <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> thanks JM, at this point i switched over to this scheme and now I'm getting an error durring instantiation of the server: Server.py: from Crypto.PublicKey import RSA from ServerNegotiator import ServerNegotiator from sharedComs import * f = open("hostid") tup = stringToTuple(f.readline()[0:-1]) HostID = f.readline()[0:-1] f.close() key = RSA.construct((long(tup[0]),long(tup[1]), long(tup[2]), long(tup[3]), long(tup[4]),long(tup[5]))) host = "localhost" port = 8005 servernegotiator = ServerNegotiator(host,HostID, port, key) servernegotiator.start() ServerNegotiatior.py lines 185 - end class ServerNegotiator: def __init__(self, host, port, hostid, rsa_key, buf = 512): negotiator = Negotiator(host, hostid, rsa_key,buf) self.server = SocketServer.TCPServer((host, port), negotiator) def start(self): self.server.serve_forever() Traceback (most recent call last): File "Server.py", line 16, in servernegotiator = ServerNegotiator(host,HostID, port, key) File "/home/twistedphrame/Desktop/communication/ ServerNegotiator.py", line 188, in __init__ self.server = SocketServer.TCPServer((host, port), negotiator) File "/usr/lib/python2.6/SocketServer.py", line 400, in __init__ self.server_bind() File "/usr/lib/python2.6/SocketServer.py", line 411, in server_bind self.socket.bind(self.server_address) File "", line 1, in bind TypeError: an integer is required From twistedphrame at gmail.com Tue Feb 9 13:09:53 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 10:09:53 -0800 (PST) Subject: Pycrypto RSA Issue Message-ID: <36189d1d-b33f-49bc-9857-74611e665aed@j6g2000vbd.googlegroups.com> I am trying to encrypt public data along with another tuple and then decrypt it after sending. RSA is needed for negotiation of keys for AES. But I just get garbage after I decrypt it. This is what I'm attempting to do: from Crypto.PublicKey import RSA from Crypto import Random gkey = RSA.generate(384, Random.new().read) string = str((gkey.publickey().__getstate__(), (333,444))) print string print data = gkey.encrypt(string,"") print "data:",data print print "decrypt" print "decrypt,", gkey.decrypt(data) print "done" All I get are junk values when printing the decrypted value. From olivier.darge at gmail.com Tue Feb 9 13:11:17 2010 From: olivier.darge at gmail.com (OdarR) Date: Tue, 9 Feb 2010 10:11:17 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <72bd2afa-2a58-489d-819a-966a92096d1d@y33g2000yqb.googlegroups.com> On 9 f?v, 11:01, Stefan Behnel wrote: > Klaus Neuner, 09.02.2010 10:04: > > > my program is supposed to parse files that I have created myself and that > > are on my laptop. It is not supposed to interact with anybody else > > than me. > > Famous last words. > > Stefan I knew it. Olivier From jeanmichel at sequans.com Tue Feb 9 13:23:21 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 19:23:21 +0100 Subject: How to measure elapsed time under Windows? In-Reply-To: References: Message-ID: <4B71A819.8050509@sequans.com> Grant Edwards wrote: > What's the correct way to measure small periods of elapsed > time. I've always used time.clock() in the past: > > start = time.clock() > [stuff being timed] > stop = time.clock() > > delta = stop-start > > > However on multi-processor machines that doesn't work. > Sometimes I get negative values for delta. According to > google, this is due to a bug in Windows that causes the value > of time.clock() to be different depending on which core in a > multi-core CPU you happen to be on. [insert appropriate > MS-bashing here] > > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > > Is there a way to lock the python process to a single core so > that time.clock() works right? > > Did you try with the datetime module ? import datetime t0 = datetime.datetime.now() t1 = t0 - datetime.datetime.now() t1.microseconds Out[4]: 644114 JM From pheensoowt at farifluset.mailexpire.com Tue Feb 9 13:27:36 2010 From: pheensoowt at farifluset.mailexpire.com (Legrandin) Date: 09 Feb 2010 18:27:36 GMT Subject: Pycrypto RSA Issue References: <36189d1d-b33f-49bc-9857-74611e665aed@j6g2000vbd.googlegroups.com> Message-ID: <4b71a918$0$14115$703f8584@textnews.kpn.nl> > gkey = RSA.generate(384, Random.new().read) > string = str((gkey.publickey().__getstate__(),(333,444))) You are encrypting with RSA a piece of data which is way larger than the key size (48 bytes). From george.trojan at noaa.gov Tue Feb 9 13:41:45 2010 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 09 Feb 2010 18:41:45 +0000 Subject: errno 107 socket.recv issue In-Reply-To: <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: Argument mismatch? Jordan Apgar wrote: > > servernegotiator = ServerNegotiator(host,HostID, port, key) > > class ServerNegotiator: > def __init__(self, host, port, hostid, rsa_key, buf = 512): > From Martin.Drautzburg at web.de Tue Feb 9 13:47:43 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Tue, 09 Feb 2010 19:47:43 +0100 Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> Message-ID: <8281270.AG5xCW3FSB@beaureve.gmx.net> Carl Banks wrote: > You can have __add__ return a closure for the first addition, then > perform the operation on the second one. Example (untested): > > class Closure(object): > def __init__(self,t1,t2): > self.t1 = t1 > self.t2 = t2 > def __add__(self,t3): > # whole operation peformed here > return self.t1 + self.t2 + t3 > > class MySpecialInt(int): > def __add__(self,other): > return Closure(self,other) > > > I wouldn't recommend it. Just use a function call with three > arguments. That's way cool. Of course! - CURRYING!! If you can return closures you can do everything with just single-parameter functions. BTW I am not really trying to add three objects, I wanted a third object which controls the way the addition is done. Sort of like "/" and "//" which are two different ways of doing division. Anyways: thanks a lot. From gnarlodious at gmail.com Tue Feb 9 13:51:09 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 10:51:09 -0800 (PST) Subject: mac install References: Message-ID: <618b5d95-252c-425c-bd18-b38e3bf5e7fb@s36g2000prh.googlegroups.com> Hello. The answer is, I don't know. But I originally replaced my existing Python with 3.1.1. I then had to backtrack because some stuff broke. Nothing in the OS, but adapting every Python script on my HD was not what I wanted to do. So my Py3 executable is at: /Library/Frameworks/Python.framework/Versions/3.1/bin/python3.1 then symlink to that in folder: /usr/local/bin using command: sudo ln -s /Library/Frameworks/Python.framework/Versions/3.1/bin/ python3.1 /usr/local/bin/python3.1 so that saying: ls /usr/local/bin shows the link to the Py3 folder as: python3.1 -> /Library/Frameworks/Python.framework/Versions/3.1/bin/ python3.1 Now your existing scripts still work on Py 2.6. New scripts invoke Py3 like this: #!/usr/local/bin/python3.1 For Terminal sessions, an alias in your bash_profile puts you in Py3 by default without nasty surprises: alias python=/usr/local/bin/python3.1 You can also create a file at: /Library/Python/3.1/site-packages/sitecustomize.py with a configuration that runs at loadtime, although some things seem to fail. But all in all this system has worked well for me (including CGI) and should be easy to go mainstream once Apple goes to Py3. -- Gnarlie From jeanmichel at sequans.com Tue Feb 9 13:51:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 19:51:31 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: <4B71AEB3.3030908@sequans.com> Jordan Apgar wrote: > thanks JM, > > at this point i switched over to this scheme and now I'm getting an > error durring instantiation of the server: > Server.py: > from Crypto.PublicKey import RSA > from ServerNegotiator import ServerNegotiator > from sharedComs import * > > f = open("hostid") > tup = stringToTuple(f.readline()[0:-1]) > HostID = f.readline()[0:-1] > f.close() > > key = RSA.construct((long(tup[0]),long(tup[1]), long(tup[2]), > long(tup[3]), > long(tup[4]),long(tup[5]))) > host = "localhost" > port = 8005 > > servernegotiator = ServerNegotiator(host,HostID, port, key) > servernegotiator.start() > > > ServerNegotiatior.py lines 185 - end > class ServerNegotiator: > def __init__(self, host, port, hostid, rsa_key, buf = 512): > negotiator = Negotiator(host, hostid, rsa_key,buf) > self.server = SocketServer.TCPServer((host, port), negotiator) > > def start(self): > self.server.serve_forever() > > > > > > Traceback (most recent call last): > File "Server.py", line 16, in > servernegotiator = ServerNegotiator(host,HostID, port, key) > File "/home/twistedphrame/Desktop/communication/ > ServerNegotiator.py", line 188, in __init__ > self.server = SocketServer.TCPServer((host, port), negotiator) > File "/usr/lib/python2.6/SocketServer.py", line 400, in __init__ > self.server_bind() > File "/usr/lib/python2.6/SocketServer.py", line 411, in server_bind > self.socket.bind(self.server_address) > File "", line 1, in bind > TypeError: an integer is required > > servernegotiator = ServerNegotiator(host,HostID, port, key) class ServerNegotiator: def __init__(self, host, port, hostid, rsa_key, buf = 512): you swapped port & hostID in your call JM From gnarlodious at gmail.com Tue Feb 9 13:58:19 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 10:58:19 -0800 (PST) Subject: Programing family References: <4b719209$0$10071$426a34cc@news.free.fr> <7xaavi5owh.fsf@ruckus.brouhaha.com> Message-ID: On Feb 9, 9:56?am, Paul Rubin wrote: > http://i.imgur.com/1gF1j.jpg Very funny, except where is Python and Forth? -- Gnarlie From invalid at invalid.invalid Tue Feb 9 14:04:01 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 19:04:01 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Jean-Michel Pichavant wrote: > Grant Edwards wrote: >> What's the correct way to measure small periods of elapsed >> time. I've always used time.clock() in the past: >> >> start = time.clock() >> [stuff being timed] >> stop = time.clock() >> >> delta = stop-start >> >> However on multi-processor machines that doesn't work. >> Sometimes I get negative values for delta. According to >> google, this is due to a bug in Windows that causes the value >> of time.clock() to be different depending on which core in a >> multi-core CPU you happen to be on. [insert appropriate >> MS-bashing here] >> >> Is there another way to measure small periods of elapsed time >> (say in the 1-10ms range)? >> >> Is there a way to lock the python process to a single core so >> that time.clock() works right? >> >> > > Did you try with the datetime module ? No. What mechanism does it use to get the current date/time? > import datetime > t0 = datetime.datetime.now() > t1 = t0 - datetime.datetime.now() > t1.microseconds > Out[4]: 644114 That looks very broken to me. I need to measure stuff in the 1-20ms range, and the smallest value you can measure using the method above appears to be 640ms. Thats almost 2/3 of a second. -- Grant Edwards grante Yow! If our behavior is at strict, we do not need fun! visi.com From twistedphrame at gmail.com Tue Feb 9 14:13:46 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 11:13:46 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: On Feb 9, 1:51?pm, Jean-Michel Pichavant wrote: > Jordan Apgar wrote: > > thanks JM, > > > at this point i switched over to this scheme and now I'm getting an > > error durring instantiation of the server: > > Server.py: > > from Crypto.PublicKey import RSA > > from ServerNegotiator import ServerNegotiator > > from sharedComs import * > > > f = open("hostid") > > tup = stringToTuple(f.readline()[0:-1]) > > HostID = f.readline()[0:-1] > > f.close() > > > key = RSA.construct((long(tup[0]),long(tup[1]), long(tup[2]), > > long(tup[3]), > > ? ? ? ? ? ? ? ? ? ? ?long(tup[4]),long(tup[5]))) > > host = "localhost" > > port = 8005 > > > servernegotiator = ServerNegotiator(host,HostID, port, key) > > servernegotiator.start() > > > ServerNegotiatior.py lines 185 - end > > class ServerNegotiator: > > ? ? def __init__(self, host, port, hostid, rsa_key, buf = 512): > > ? ? ? ? negotiator = Negotiator(host, hostid, rsa_key,buf) > > ? ? ? ? self.server = SocketServer.TCPServer((host, port), negotiator) > > > ? ? def start(self): > > ? ? ? ? self.server.serve_forever() > > > Traceback (most recent call last): > > ? File "Server.py", line 16, in > > ? ? servernegotiator = ServerNegotiator(host,HostID, port, key) > > ? File "/home/twistedphrame/Desktop/communication/ > > ServerNegotiator.py", line 188, in __init__ > > ? ? self.server = SocketServer.TCPServer((host, port), negotiator) > > ? File "/usr/lib/python2.6/SocketServer.py", line 400, in __init__ > > ? ? self.server_bind() > > ? File "/usr/lib/python2.6/SocketServer.py", line 411, in server_bind > > ? ? self.socket.bind(self.server_address) > > ? File "", line 1, in bind > > TypeError: an integer is required > > servernegotiator = ServerNegotiator(host,HostID, port, key) > class ServerNegotiator: > ? ? def __init__(self, host, port, hostid, rsa_key, buf = 512): > > you swapped port & hostID in your call > > JM tThanks guys it's working now... feel a little stupid though. From twistedphrame at gmail.com Tue Feb 9 14:14:27 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 11:14:27 -0800 (PST) Subject: Pycrypto RSA Issue References: <36189d1d-b33f-49bc-9857-74611e665aed@j6g2000vbd.googlegroups.com> <4b71a918$0$14115$703f8584@textnews.kpn.nl> Message-ID: <6a1bbf69-3cfc-4d2b-b329-939ca6d2d553@x9g2000vbo.googlegroups.com> On Feb 9, 1:27?pm, Legrandin wrote: > > gkey = RSA.generate(384, Random.new().read) > > string = str((gkey.publickey().__getstate__(),(333,444))) > > You are encrypting with RSA a piece of data which is way > larger than the key size (48 bytes). ah thanks Legrandin From db3l.net at gmail.com Tue Feb 9 14:18:50 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 09 Feb 2010 14:18:50 -0500 Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: T writes: > The more testing I do, I think you may be right..I was able to get it > to work under a local admin account, and it worked under debug mode > (which would also have been running as this user). I'm a bit > surprised though - I was under the assumption that LocalSystem had > rights to access the network? Not from my past experience - the system account (LocalSystem for services) can be surprising, in that it's pretty much unlimited access to all local resources, but severely limited in a handful of cases, one of which is any attempt to access the network. I can't recall for sure if it's an absolute block, or if in some cases you can configure around it (e.g., it might use a null session for remote shares which can be enabled through the registry on the target machine). I've basically stuck "LocalSystem = no network" in my head from past experience. So you can either install your service to run under your existing account, or create an account specifically for running your service, granting that account just the rights it needs. -- David From sjdevnull at yahoo.com Tue Feb 9 14:59:18 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Tue, 9 Feb 2010 11:59:18 -0800 (PST) Subject: To (monkey)patch or not to (monkey)patch, that is the question References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: On Feb 9, 3:54?am, George Sakkis wrote: > I was talking to a colleague about one rather unexpected/undesired > (though not buggy) behavior of some package we use. Although there is > an easy fix (or at least workaround) on our end without any apparent > side effect, he strongly suggested extending the relevant code by hard > patching it and posting the patch upstream, hopefully to be accepted > at some point in the future. In fact we maintain patches against > specific versions of several packages that are applied automatically > on each new build. The main argument is that this is the right thing > to do, as opposed to an "ugly" workaround or a fragile monkey patch. > On the other hand, I favor practicality over purity and my general > rule of thumb is that "no patch" > "monkey patch" > "hard patch", at > least for anything less than a (critical) bug fix. I'd monkey patch for the meantime, but send a hard patch in the hopes of shifting the maintenance burden to someone else. (Plus maybe help out the upstream project and other people, I guess) From alfps at start.no Tue Feb 9 15:02:12 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 21:02:12 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Duncan Booth: > "Alf P. Steinbach" wrote: > >> A copyable reference is a pointer. That is, a "pointer", in e.g. the >> Java sense, >> and in the general language independent sense, means a copyable >> reference -- as illustrated e.g. in the Stanford computer science >> 101 course page I >> referred you to earlier, with C versus Java pointers illustrated in >> the concrete. > > The fact that C style pointers are used internally is an detail of the > CPython implementation. Your statement seems pretty irrelevant to anything. It's almost hilarious, quoting a single paragraph about how irrelevant the C pointer is, and responding with something like that. Do you understand that you're restating (in the form of exemplifying) what you're quoting? > In CPython objects once created remain in the same memory location (and > their id is their address). Compare that to IronPython where the objects > themselves can move around in memory so they have no fixed address. Try > comparing the IronPython implementation to C pointers and you'll cause a > lot of confusion. e.g. someone might think the id() value is in some way > related to an address. Did you /read/ what you quoted? > Ruby implements integers without using any pointers at all: there's nothing > in the Python specification which prevents a Python implementation doing > the same for small integers, in fact I believe it has been tried but wasn't > found to improve performance. All theree of your points about Python are wrong; I don't know about the Ruby point. First, the current Python language specification formally prevents the optimization you mention, because there's no support for binding to do anything but direct binding leaving object identities unchanged. But in practice that's no big deal though: I can't imagine any code relying on identities of completely immutable objects. Second, even the variant that was tried improved performance. But it would reportedly have wreaked havoc with imperfect C code. Third, the optimization doesn't do away with pointers. If it did then it would transform the language completely. The user's view is still one where names denote pointers. > The terminology of 'objects', 'names', 'references' describes an abstract > machine. The Python runtime can implement it in any way it chooses so long > as those semantics are preserved. One implementation involves 'pointers', It seems that you're thinking of C pointers. That's pretty dumb since (1) it doesn't make sense, and (2) it has been mentioned in almost every article in this thread, including my first, and including the single paragraph that *you quoted above*, which was only about that, that we're not talking about C pointers here. Python names denote pointers by definition (of pointer). > but that word implies other baggage which is not a required part of the > model. The word itself doesn't imply other baggage, no. It might help to *read* what you're quoting, try to follow references, so on. Cheers & hth., - Alf From wolftracks at invalid.com Tue Feb 9 15:02:50 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 09 Feb 2010 12:02:50 -0800 Subject: Tangling with mathplotlib(MPL) on XP and Win7 -- show() stopper In-Reply-To: References: Message-ID: Solved. I need to get into the interactive mode. Never heard of it until this morning. From alfps at start.no Tue Feb 9 15:04:08 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 21:04:08 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Stephen Hansen: > [...] >>> I've heard that before, and have no idea why, nor any real interest in >>> solving it: I don't want to read cpl via Usenet, and prefer to read it >>> as a mailing list. Somewhere between Gmail->python.org->python.org >>> 's usenet server->the world, some people don't seem >>> to get my posts. Yet it shows up on some news servers, not others. >>> >>> No idea. Nothing I know of can solve it. >> Not sure, but perhaps it's possible to mail directly to gmane? >> > Is there *any* problem you don't have a fatuous answer for? I thought the answer could help. You thought you cold do a bit of ad hominem attack. That's the difference between us. Cheers, - Alf From steve at holdenweb.com Tue Feb 9 15:39:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 15:39:05 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Stephen Hansen: >> [...] >>>> I've heard that before, and have no idea why, nor any real interest in >>>> solving it: I don't want to read cpl via Usenet, and prefer to read it >>>> as a mailing list. Somewhere between Gmail->python.org->python.org >>>> 's usenet server->the world, some people don't seem >>>> to get my posts. Yet it shows up on some news servers, not others. >>>> >>>> No idea. Nothing I know of can solve it. >>> Not sure, but perhaps it's possible to mail directly to gmane? >>> >> Is there *any* problem you don't have a fatuous answer for? > > I thought the answer could help. > > You thought you cold do a bit of ad hominem attack. > > That's the difference between us. > Well, the way I see it, you assumed you knew better than Stephen, and insisted on proposing a solution to a problem that he clearly stated he had no interest in. I'm not quite sure, given that, what the point of the advice was. However, my question was genuine, based on your observed behavior. I agree I might have phrased it more politely, but I do find your self-assurance somewhat irritating. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 15:39:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 15:39:44 -0500 Subject: errno 107 socket.recv issue In-Reply-To: References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: Jordan Apgar wrote: > On Feb 9, 1:51 pm, Jean-Michel Pichavant [...] >> you swapped port & hostID in your call >> >> JM > > tThanks guys it's working now... feel a little stupid though. Cool! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From quindennis at grandecom.net Tue Feb 9 16:00:47 2010 From: quindennis at grandecom.net (Quin) Date: Tue, 9 Feb 2010 15:00:47 -0600 Subject: New to Python Message-ID: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' this generates output: not found processing so, it doesn't find the substring, but goes into processing code anyway. This is using IronPython From alfps at start.no Tue Feb 9 16:08:27 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 22:08:27 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >>>> * Stephen Hansen: >>> [...] >>>>> I've heard that before, and have no idea why, nor any real interest in >>>>> solving it: I don't want to read cpl via Usenet, and prefer to read it >>>>> as a mailing list. Somewhere between Gmail->python.org->python.org >>>>> 's usenet server->the world, some people don't seem >>>>> to get my posts. Yet it shows up on some news servers, not others. >>>>> >>>>> No idea. Nothing I know of can solve it. >>>> Not sure, but perhaps it's possible to mail directly to gmane? >>>> >>> Is there *any* problem you don't have a fatuous answer for? >> I thought the answer could help. >> >> You thought you cold do a bit of ad hominem attack. >> >> That's the difference between us. >> > Well, the way I see it, you assumed you knew better than Stephen, and > insisted on proposing a solution to a problem that he clearly stated he > had no interest in. You're going into motivations, that it seems to me that you're projecting, saying that any helpful suggestion mean that one thinks one knows better and implies a desire to demonstrate imagined superiority. You're trying to portray a helping hand as a negative personal characteristic of the helper. "the only reason that guy tries to help you is because he wishes to show how superior he (thinks he) is". That's your style in a fair number of postings, and now here: * ad hominem attack, * projection (at least the way I read it), and * inject - noise - about - something - completely - irrelevant Note that readers can easily guess about motivations for the last. > I'm not quite sure, given that, what the point of the advice was. There are many people who read just the Usenet group, e.g. via Google groups. When you say you don't understand the point of the advice, you're saying that * those people don't matter, and that * it doesn't matter whether they can read Stephen Hansen's articles. That's * slighting Stephen Hansen, and * showing off an extreme ego-centric view of the world, sorry. > However, my question was genuine, based on your observed behavior. I > agree I might have phrased it more politely, but I do find your > self-assurance somewhat irritating. Thanks. :-) Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Tue Feb 9 16:18:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 18:18:44 -0300 Subject: Python-URL! - weekly Python news and links (Feb 9) References: Message-ID: En Tue, 09 Feb 2010 12:32:54 -0300, Marius Gedminas escribi?: > The last three URLs are malformed: Sorry... It happens even in the best of families :) These are the right ones: There is no module in the standard library to handle filesystem paths in an OO way - but why? http://groups.google.com/group/comp.lang.python/t/f580fb3763208425/ A "History Channel" special: how the way a TAB key was interpreted changed over time http://groups.google.com/group/comp.lang.python/t/82d9181fcd31ffe4/ After a false start, finally we get our first "Is it Call-By-Value or Call-By-Reference?" thread of the year! http://groups.google.com/group/comp.lang.python/t/fd36962c4970ac48/ -- Gabriel Genellina From invalid at invalid.invalid Tue Feb 9 16:19:05 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 21:19:05 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Grant Edwards wrote: > On 2010-02-09, Jean-Michel Pichavant wrote: >> Did you try with the datetime module ? > > No. What mechanism does it use to get the current date/time? > >> import datetime >> t0 = datetime.datetime.now() >> t1 = t0 - datetime.datetime.now() >> t1.microseconds >> Out[4]: 644114 > > That looks very broken to me. I need to measure stuff in the > 1-20ms range, and the smallest value you can measure using the > method above appears to be 640ms. Thats almost 2/3 of a second. Duh. It just occurred to me that was done interactively. I'll give the datetime module a try once I reboot my test machine back into Windows. -- Grant Edwards grante Yow! Is this sexual at intercourse yet?? Is it, visi.com huh, is it?? From db3l.net at gmail.com Tue Feb 9 16:25:24 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 09 Feb 2010 16:25:24 -0500 Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: David Bolen writes: > Not from my past experience - the system account (LocalSystem for > services) can be surprising, in that it's pretty much unlimited access > to all local resources, but severely limited in a handful of cases, > one of which is any attempt to access the network. I can't recall for > sure if it's an absolute block, or if in some cases you can configure > around it (e.g., it might use a null session for remote shares which > can be enabled through the registry on the target machine). I've > basically stuck "LocalSystem = no network" in my head from past > experience. Given it's been a few years, I decided to try some tests, and the above is too simplistic. The LocalSystem account runs without any local Windows credentials (e.g., not like a logged in user), which has several consequences. One is that you can't access any network resources that require such credentials (like shares). However, there's no sort of firewall filtering or anything, so plain old TCP/IP connections are fine. Unless, of course, the client being used also has other needs for local Windows credentials, independent or as a pre-requisite to the network operations. So backing up a bit, the TCP/IP connection that plink is making is not inherently disabled by running under LocalSystem, but it's certainly possible that plink is trying to identify the user under which it is operating to perhaps identify ssh keys or other local resources it needs to operate. You might be able to cover this with command line options (e.g., plink supports "-i" to specify a key file to use), but you'll also need to ensure that the file you are referencing is readable by the LocalSystem account. One of the other responders had a very good point about locating plink in the first place too. Services run beneath an environment that is inherited from the service control manager process, and won't include various settings that are applied to your user when logged in, especially things like local path changes, and working directories. Should you change the system path (via the environment settings), you'll need to reboot for the service control manager to notice - I don't think you can restart it without a reboot. So it's generally safer to be very clear, and absolute when possible, in a service for paths to external resources. The prior advice of running the service as an identified user (e.g., with local credentials) is still good as it does remove most of these issues since if you can run the script manually under that user you know it'll work under service. But it's not a hard requirement. If your script is dying such that a top level exception is being raised you should be able to find it in the application event log. So that might give further information on what about the different environment is problematic. You can also use the win32traceutil module to help with grabbing debug output on the fly. Import the module in your service, which will implicitly redirect stdout/stderr to a trace buffer. Run the same win32traceutil module from the command line in another window. Then start the service. Any stdout/stderr will be reflected in the other window. Can't catch everything (suppressed exceptions, or I/O that doesn't flow through the script's stdout/stderr), but again might help point in the right direction. -- David From jgardner at jonathangardner.net Tue Feb 9 16:41:34 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 9 Feb 2010 13:41:34 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: On Feb 9, 1:51?am, waku wrote: > 'stupid', 'wrong', 'deficient', 'terrible', ... ?you're using strong > words instead of concrete arguments, it might intimidate your > opponents, but is hardly helpful in a fair discussion. > In today's day and age, I don't know how a text editor which cannot do simple indentation can be considered anything but "stupid", "wrong", "deficient", and "terrible". There is simply no excuse for this kind of behavior on the part of the text editor. I mean, how long has vi had the auto indent feature? How many decades has emacs supported the same? This isn't new technology, or difficult technology to implement. It's not even non-standard anymore. Heck, far more advanced features, such as syntax highlighting, are standard in all text editors. Your problem is you're using something like Windows Notepad to edit your code. Windows Notepad is a terrible tool for writing anything, let alone writing code. Why in the world would any programming language adapt itself to the mental deficiencies of Windows Notepad? I mean, if you were an artist, would you use MS Paint to do anything serious? If you did, would you complain that the art world has a problem because they don't accept your paintings? I strongly suggest you download one of the *hundreds* of free text editors available for the Windows platform that give you the indentation features you so sorely lack. I suggest ViM, though it has a steep learning curve. From hklasky at gmail.com Tue Feb 9 16:42:39 2010 From: hklasky at gmail.com (seth) Date: Tue, 9 Feb 2010 13:42:39 -0800 (PST) Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 Message-ID: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> There is something you could possibly help me with. We have a code that creates a simple Python shelve database. We are able to serialize objects and store them in the dbm file. This seem to work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6, but on Os X 10.5 with Python 2.5 the database filename is changed by the operating system by attaching the .db extension to it. Does an one know why is that? What is worse, at the time of reading it we get the error below the extracted code, on Os X 10.5: if os.path.exists( tarname )and tarfile.is_tarfile( tarname ): try: datastore_tarfile=tarfile.open( tarname, 'r:gz' ) print "Successfully opened the tarball: %s"%tarname members=datastore_tarfile.getnames() for dbmFile in members: datastore_tarfile.extract( dbmFile ) print "Extracting Realizations File: %s"%dbmFile realizations=shelve.open( dbmFile, 'c', 2, writeback = False ) Successfully opened the tarball: datastore.tar.gz Extracting Realizations File: realizations.dbm.db (22, 'Invalid argument') This does not happen on Windows XP with Python 2.5. Does anyone know what is happening on Os X? Any comments and suggestions will be greatly appreciated. Thank you very much in advance. From jgardner at jonathangardner.net Tue Feb 9 16:43:37 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 9 Feb 2010 13:43:37 -0800 (PST) Subject: PostgreSQL driver for Python applications that supports bytea correctly? References: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Message-ID: <690d8388-0f24-4461-89a1-cb34e3a082a9@k5g2000pra.googlegroups.com> On Feb 9, 7:27?am, CyclingGuy wrote: > Can anyone recommend a PostgreSQL driver for Python that supports > selecting and inserting bytea types? > Can you name some that don't? From invalid at invalid.invalid Tue Feb 9 16:45:38 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 21:45:38 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Jean-Michel Pichavant wrote: > Grant Edwards wrote: >> What's the correct way to measure small periods of elapsed >> time. I've always used time.clock() in the past: >> >> start = time.clock() >> [stuff being timed] >> stop = time.clock() >> >> delta = stop-start >> >> >> However on multi-processor machines that doesn't work. >> Sometimes I get negative values for delta. According to >> google, this is due to a bug in Windows that causes the value >> of time.clock() to be different depending on which core in a >> multi-core CPU you happen to be on. [insert appropriate >> MS-bashing here] >> >> Is there another way to measure small periods of elapsed time >> (say in the 1-10ms range)? >> >> Is there a way to lock the python process to a single core so >> that time.clock() works right? > Did you try with the datetime module ? > > import datetime > t0 = datetime.datetime.now() > t1 = t0 - datetime.datetime.now() > t1.microseconds > Out[4]: 644114 Doesn't work. datetime.datetime.now has granularity of 15-16ms. Intervals much less that that often come back with a delta of 0. A delay of 20ms produces a delta of either 15-16ms or 31-32ms -- Grant Edwards grante Yow! I'm receiving a coded at message from EUBIE BLAKE!! visi.com From gagsl-py2 at yahoo.com.ar Tue Feb 9 16:50:53 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 18:50:53 -0300 Subject: Programing family References: Message-ID: En Mon, 08 Feb 2010 22:39:58 -0300, AON LAZIO escribi?: > I have thought funny things > If we think all languages are like a family > I could draft them like this (Python base) Have a look at: http://oreilly.com/news/languageposter_0504.html -- Gabriel Genellina From invalid at invalid.invalid Tue Feb 9 17:00:50 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 22:00:50 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Grant Edwards wrote: > On 2010-02-09, Jean-Michel Pichavant wrote: >> Grant Edwards wrote: >>> What's the correct way to measure small periods of elapsed >>> time. I've always used time.clock() in the past: >>> >>> start = time.clock() >>> [stuff being timed] >>> stop = time.clock() >>> >>> delta = stop-start >>> >>> >>> However on multi-processor machines that doesn't work. >>> Sometimes I get negative values for delta. According to >>> google, this is due to a bug in Windows that causes the value >>> of time.clock() to be different depending on which core in a >>> multi-core CPU you happen to be on. [insert appropriate >>> MS-bashing here] >>> >>> Is there another way to measure small periods of elapsed time >>> (say in the 1-10ms range)? >>> >>> Is there a way to lock the python process to a single core so >>> that time.clock() works right? > >> Did you try with the datetime module ? >> >> import datetime >> t0 = datetime.datetime.now() >> t1 = t0 - datetime.datetime.now() >> t1.microseconds >> Out[4]: 644114 > > Doesn't work. datetime.datetime.now has granularity of > 15-16ms. time.time() exhibits the same behavior, so I assume that datetime.datetime.new() ends up making the same libc/system call as time.time(). From what I can grok of the datetime module source code, it looks like it's calling gettimeofday(). I can't find any real documentation on the granularity of Win32 gettimeofday() other than a blog post that claims it is 10ms (which doesn't agree with what my tests show). -- Grant Edwards grante Yow! I feel better about at world problems now! visi.com From mukeshtiwari.iiitm at gmail.com Tue Feb 9 17:06:56 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Tue, 9 Feb 2010 14:06:56 -0800 (PST) Subject: Problem Regarding Queue Message-ID: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> Could some one please tell what is wrong with this code. I am trying to use Queue in this program but i am getting error Traceback (most recent call last): File "/home/user/NetBeansProjects/NewPythonProject2/src/ Pollard_rho.py", line 80, in factor(n) File "/home/user/NetBeansProjects/NewPythonProject2/src/ Pollard_rho.py", line 59, in factor Q_1=Queue() NameError: global name 'Queue' is not defined. As i am new to python so kindly pardon me if i sound stupid. Here is the code # To change this template, choose Tools | Templates # and open the template in the editor. __author__="Mukesh Tiwari" __date__ ="$Feb 10, 2010 1:35:26 AM$" import random import sys def gcd(a,b): while b: a,b=b,a%b return a def rabin_miller(p): if(p<2): return False if(p!=2 and p%2==0): return False s=p-1 while(s%2==0): s>>=1 for i in xrange(10): a=random.randrange(p-1)+1 temp=s mod=pow(a,temp,p) while(temp!=p-1 and mod!=1 and mod!=p-1): mod=(mod*mod)%p temp=temp*2 if(mod!=p-1 and temp%2==0): return False return True def pollard(n): if(n%2==0): return 2; x=random.randrange(2,1000000) c=random.randrange(2,1000000) y=x d=1 while(d==1): x=(x*x+c)%n y=(y*y+c)%n y=(y*y+c)%n d=gcd(x-y,n) if(d==n): break; return d; def factor(n): #if(rabin_miller(n)): # print n # return #d=pollard(n) #if(d!=n): # factor(d) # factor(n/d) #else: # factor(n) Q_1=Queue() Q_2=Queue() Q_1.put(n) while(not Q_1.empty()): l=Q_1.get() if(rabin_miller(l)): Q_2.put(l) continue d=pollard(l) if(d==l):Q_1.put(l) else: Q_1.put(d) Q_1.put(l/d) while(not Q_2.empty()): print Q_2.get() if __name__ == "__main__": while(True): n=input(); factor(n) From simon at brunningonline.net Tue Feb 9 17:10:46 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 9 Feb 2010 22:10:46 +0000 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> On 9 February 2010 16:29, Robert Kern wrote: > On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >> If the code base stabilizes in a production version after losing the >> alphas and betas they would be a great addition to the stdlib, I >> think. > > Why? I agree. Why wait? Put them in the stdlib now! -- Cheers, Simon B. From gordon at panix.com Tue Feb 9 17:11:45 2010 From: gordon at panix.com (John Gordon) Date: Tue, 9 Feb 2010 22:11:45 +0000 (UTC) Subject: New to Python References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: In <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d at posted.grandecom> "Quin" writes: > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > this generates output: > not found > processing > so, it doesn't find the substring, but goes into processing code anyway. I got this output when f contained 'mystring': foundit processing And this output when f did not contain 'mystring': notfound I have no idea why it would have worked otherwise for you. When you posted your question, did you type the code by hand? Perhaps you made a mistake. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From apt.shansen at gmail.com Tue Feb 9 17:25:31 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 14:25:31 -0800 Subject: Problem Regarding Queue In-Reply-To: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> References: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> Message-ID: <7a9c25c21002091425p5ed2181bybe1e5d89e99a89c2@mail.gmail.com> On Tue, Feb 9, 2010 at 2:06 PM, mukesh tiwari wrote: > Could some one please tell what is wrong with this code. I am trying > to use Queue in this program but i am getting error > Traceback (most recent call last): > File "/home/user/NetBeansProjects/NewPythonProject2/src/ > Pollard_rho.py", line 80, in > factor(n) > File "/home/user/NetBeansProjects/NewPythonProject2/src/ > Pollard_rho.py", line 59, in factor > Q_1=Queue() > NameError: global name 'Queue' is not defined. > That's because you haven't imported the Queue module. You need to do: import Queue Then call: Q_1 = Queue.Queue() Alternately, you can do: from Queue import Queue And instantiate the class the same way you previously were. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Feb 9 17:28:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Feb 2010 14:28:12 -0800 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <50697b2c1002091428n167d2f5ew4393f7bab9a4a8d8@mail.gmail.com> On Tue, Feb 9, 2010 at 6:00 AM, Phlip wrote: > Ah, now we get down to the root of the problem. Because Python is so > stuck on the "one best way to do it" mentality, language bigotry > prevented the Committee from picking from among several equally valid > but non-best options. And after 20 years of growth, Python still has > no Pathname class. What a mature community! C-: Committee? I think you have us confused with C++... *wink*, Chris From drobinow at gmail.com Tue Feb 9 17:42:57 2010 From: drobinow at gmail.com (David Robinow) Date: Tue, 9 Feb 2010 17:42:57 -0500 Subject: ANN: obfuscate In-Reply-To: <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> Message-ID: <4eb0089f1002091442pa4ce024ueb5fa8326cf4b7e@mail.gmail.com> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning wrote: > On 9 February 2010 16:29, Robert Kern wrote: >> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>> If the code base stabilizes in a production version after losing the >>> alphas and betas they would be a great addition to the stdlib, I >>> think. >> >> Why? > > I agree. Why wait? Put them in the stdlib now! > > -- > Cheers, > Simon B. Can we please stop this? From sridharr at activestate.com Tue Feb 9 17:49:07 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Tue, 9 Feb 2010 14:49:07 -0800 Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 In-Reply-To: <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> References: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> Message-ID: On 2010-02-07, at 5:02 PM, escalation746 wrote: > Andrej Mitrovic wrote: > >> Perhaps you've accidentally downloaded the wrong version of PythonWin? > > Erk, yes, my bad. > > Thanks for the quick help! Though I still wonder why the ActiveState > build does not include this. I just added support for PyWin32 in ActivePython 2.6 64-bit. http://twitter.com/sridhr/status/8874549314 I should be part of next release (2.6.4.11). -srid From arnodel at googlemail.com Tue Feb 9 17:52:35 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 09 Feb 2010 22:52:35 +0000 Subject: EAFP gone wrong Message-ID: Hi all, Hi have a set of classes that represent mathematical objects which can be represented as a string using a 'latex' method (after Knuth's famous typesetting system). As I want to be able to typeset some builtin types as well, I have a generic function, latex(), as follows: def latex(val): try: return val.latex() except AttributeError: if isinstance(val, (tuple, list)): return ", ".join(map(latex, val)) elif isinstance(val, dict): return ", ".join( "%s=%s" % (latex(k), latex(v)) for k, v in sorted(val.iteritems()) ) else: return str(val) It's EAFP and I have used this for a while with no problem. Recently I added a new class for 'n choose r' objects, as follows: class Choose(Expression): def __init__(self, n, r): self.subexprs = n, r self.n = n self.r = r def calc(self, ns=None, calc=calc): return choose(calc(self.n, ns), calc(self.r, ns)) def latex(self): return "{%s \\choose %s}" % (latex(self.n), latex(self.k)) When I create a Choose object and try to get its latex representation, this happens: >>> c = Choose(5, 3) >>> latex(c) '' This puzzled me for a bit: why is it not trying to use the latex() method of the Choose object? I read and reread the definition of the latex() method for a while until I found that there was a typo. Where it says: latex(self.k) it should say: latex(self.r) Thus it triggers an AttributeError, which is exactly the kind of exception that I am catching in the latex() function after trying val.latex(). (Of course I could have caught this by calling c.latex() directly but it's such a short method definition that I couldn't imagine missing the typo!). This means that EAFP made me hide a typo which would have been obviously detected had I LBYLed, i.e. instead of try: return val.latex() except AttributeError: ... do if hasattr(val, 'latex'): return val.latex() else: ... So was it wrong to say it's EAFP in this case? Should I have known to LBYL from the start? How do you decide which one to use? Up to now, I thought it was more or less a matter of taste but now this makes me think that at least LBYL is better than catching AttributeError. Thanks for any guidance. -- Arnaud From mark0978 at gmail.com Tue Feb 9 17:55:30 2010 From: mark0978 at gmail.com (Mark Jones) Date: Tue, 9 Feb 2010 14:55:30 -0800 (PST) Subject: I've built Python, but can't figure out how to package it for windows Message-ID: Python 2.6.4 is built, and I found a bdist_wininst project and wininst-8 project. How do I manage to build the msi for this thing? From alfps at start.no Tue Feb 9 18:09:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 00:09:23 +0100 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> Message-ID: * David Robinow: > On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning wrote: >> On 9 February 2010 16:29, Robert Kern wrote: >>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>>> If the code base stabilizes in a production version after losing the >>>> alphas and betas they would be a great addition to the stdlib, I >>>> think. >>> Why? >> I agree. Why wait? Put them in the stdlib now! >> > Can we please stop this? I agree. I haven't looked at the code but the functionality that's listed is useful, e.g. in a Usenet client, and it's fun to play around with for a beginner. Also, for example, Christian Heimes wrote else-thread: ?Your work should be interesting for everybody who has read Simon Sing's "The Code Book: The Science of Secrecy from Ancient Egypt to Quantum"? (and I for one have that book). Cheers, - Alf From ben+python at benfinney.id.au Tue Feb 9 18:11:41 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 10:11:41 +1100 Subject: EAFP gone wrong References: Message-ID: <87k4umhumq.fsf@benfinney.id.au> Arnaud Delobelle writes: > As I want to be able to typeset some builtin types as well, I have a > generic function, latex(), as follows: > > def latex(val): > try: > return val.latex() > except AttributeError: [?] > It's EAFP and I have used this for a while with no problem. [?] > I found that there was a typo. Where it says: > > latex(self.k) > > it should say: > > latex(self.r) > > Thus it triggers an AttributeError, which is exactly the kind of > exception that I am catching in the latex() function after trying > val.latex(). (Of course I could have caught this by calling c.latex() > directly but it's such a short method definition that I couldn't > imagine missing the typo!). > > This means that EAFP made me hide a typo which would have been obviously > detected had I LBYLed The correct approach here is to reduce the operations being done in the ?try? suite to a minimum. The fact that you're calling a function in the ?try? block obviously opens you to the potential for an AttributeError from that function. Since that's not what you intend to catch, you need to separate those concerns. def latex(val): def make_result_in_the_absence_of_a_latex_method(): result = transmogrify(val) return result try: typeset_func = val.latex except AttributeError: typeset_func = make_result_in_the_absence_of_a_latex_method result = typeset_func() return result -- \ ?Two hands working can do more than a thousand clasped in | `\ prayer.? ?Anonymous | _o__) | Ben Finney From helmert at informatik.uni-freiburg.de Tue Feb 9 18:22:50 2010 From: helmert at informatik.uni-freiburg.de (Malte Helmert) Date: Wed, 10 Feb 2010 00:22:50 +0100 Subject: EAFP gone wrong In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: > This means that EAFP made me hide a typo which would have been obviously > detected had I LBYLed, i.e. instead of > > try: > return val.latex() > except AttributeError: > ... > > do > > if hasattr(val, 'latex'): > return val.latex() > else: > ... > > > So was it wrong to say it's EAFP in this case? I would say that it's not really the EAFP concept that is problematic here, but rather that the try block encompasses more code than it should. Generally try blocks should be as narrow as possible, i.e., they should contain only the part where you really want to catch a potential failure. "return val.latex()" does two separate things that might fail: the lookup of val.latex, and the actual method call. If I understood you correctly, you only want to catch the AttributeError in the "val.latex" lookup here, and hence I'd say the "correct" application of EAFP here would be something like: try: foo = val.latex except AttributeError: ... else: return foo() Whether that's any better than LBYL in this particular case is of course debatable -- one nice thing compared to your LBYL version is that it doesn't look up val.latex twice upon success. But you could also get that via the LBYLish: latex_method = getattr(val, "latex") if latex_method: return latex_method() ... Malte From helmert at informatik.uni-freiburg.de Tue Feb 9 18:27:10 2010 From: helmert at informatik.uni-freiburg.de (Malte Helmert) Date: Wed, 10 Feb 2010 00:27:10 +0100 Subject: EAFP gone wrong In-Reply-To: <87k4umhumq.fsf@benfinney.id.au> References: <87k4umhumq.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > def latex(val): > def make_result_in_the_absence_of_a_latex_method(): > result = transmogrify(val) > return result > > try: > typeset_func = val.latex > except AttributeError: > typeset_func = make_result_in_the_absence_of_a_latex_method > > result = typeset_func() > return result In this particular case, where in the case of an AttributeError you want to use a fallback callable with the same signature as the bound method you get in case of success, I'd say getattr with a default is the nicest approach: def latex(val): def make_result_in_the_absence_of_a_latex_method(): result = transmogrify(val) return result return getattr(val, "latex", make_result_in_the_absence_of_a_latex_method)() Doesn't work as nicely if you don't have make_result_in_the_absence_of_a_latex_method's functionality bundled into a suitable function already, though. Malte From stef.mientki at gmail.com Tue Feb 9 18:27:13 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 10 Feb 2010 00:27:13 +0100 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> Message-ID: <4B71EF50.7050801@gmail.com> On 10-02-2010 00:09, Alf P. Steinbach wrote: > * David Robinow: >> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning >> wrote: >>> On 9 February 2010 16:29, Robert Kern wrote: >>>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>>>> If the code base stabilizes in a production version after losing the >>>>> alphas and betas they would be a great addition to the stdlib, I >>>>> think. >>>> Why? >>> I agree. Why wait? Put them in the stdlib now! >>> >> Can we please stop this? > > I agree. > sorry I don't, unless Python is only meant for the very well educated people in encryption. > I haven't looked at the code but the functionality that's listed is > useful, e.g. in a Usenet client, and it's fun to play around with for > a beginner. I neither did look at the code, but as a beginner with just 3 years of experience in Python, I've tried several scrambling libs, for a quick and dirty use. All were much too difficult, so I made my own xor-something. Coming from Delphi, a scrambling lib is working is less than 10 minutes, without the need of any knowledge of encryption. I prefer Python over Delphi, but some things are made very complex in Python. cheers, Stef > > Also, for example, Christian Heimes wrote else-thread: ?Your work > should be interesting for everybody who has read Simon Sing's "The > Code Book: The Science of Secrecy from Ancient Egypt to Quantum"? (and > I for one have that book). > > > Cheers, > > - Alf From steve at REMOVE-THIS-cybersource.com.au Tue Feb 9 18:31:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 23:31:32 GMT Subject: Programing family References: <4b719209$0$10071$426a34cc@news.free.fr> Message-ID: <00fb7592$0$15628$c3e8da3@news.astraweb.com> On Tue, 09 Feb 2010 17:49:21 +0100, Bruno Desthuilliers wrote: > On Feb 8, 2010, at 8:39 PM, AON LAZIO wrote: >> >>> I have thought funny things >>> If we think all languages are like a family > > Then it would be a very incestuous family fore sure. > >>> I could draft them like this (Python base) >>> >>> C is Python's Mom >>> C++ : Dad > > Not that much C++ in Python, IMHO. If that's for the OO part, then the > closer to Python's object model I can think of is javascript. I thought that Javascript didn't even have inheritance until recently? Like in the last year? > Historically, Python comes from ABC, which itself comes from SETL. > >>> Pascal/Assembly : Grandparents > > Assembly ? What about binary machine code then ?-) I'd say assembly is more like the distant answer, back when we still had tails and lived in trees and worried about being eaten by eagles. >>> C# : Uncle >>> Java : Ant > > Interesting typo here !-) > > Hmmm... Python predates both C# and Java. Ok, technically speaking > nothing prevents an uncle or aunt from being younger than their nephews, > and I even saw the case a couple time - but that's far from being the > common case. > >>> Ruby: Cousin >>> Perl : Girlfriend > > Then it's kind of a very passionate love-hate relationship - bordering > on pathological FWIW !-) I'd say that the girlfriend is more likely Lisp or Haskell -- some of the more functional aspects of Python have been inspired by these languages. > Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of > course Simula and Smalltalk. -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Feb 9 18:37:45 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 23:37:45 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: <00fb7707$0$15628$c3e8da3@news.astraweb.com> On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote: > You thought you cold do a bit of ad hominem attack. That phrase you keep using, "ad hominem"... it doesn't mean what you seem to think it means. An ad hominem attack is not when somebody makes a criticism of you personally. It is when somebody says something along the lines of "Don't pay any attention to Alf, he doesn't know what he's talking about, he's a ". You might not like the personal criticism, but that doesn't make it either an attack or a fallacy. -- Steven From alfps at start.no Tue Feb 9 18:40:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 00:40:50 +0100 Subject: Easter Eggs Message-ID: I know 3 Python Easter Eggs, from __future__ import braces import this help( "antigravity" ) Are there more? Cheers, - Alf From gagsl-py2 at yahoo.com.ar Tue Feb 9 18:43:51 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 20:43:51 -0300 Subject: How to measure elapsed time under Windows? References: Message-ID: En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards escribi?: > What's the correct way to measure small periods of elapsed > time. I've always used time.clock() in the past: > > However on multi-processor machines that doesn't work. > Sometimes I get negative values for delta. According to > google, this is due to a bug in Windows that causes the value > of time.clock() to be different depending on which core in a > multi-core CPU you happen to be on. [insert appropriate > MS-bashing here] I'm not sure you can blame MS of this issue; anyway, this patch should fix the problem: http://support.microsoft.com/?id=896256 > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? No that I know of. QueryPerformanceCounter (the function used by time.clock) seems to be the best timer available. > Is there a way to lock the python process to a single core so > that time.clock() works right? Interactively, from the Task Manager: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_assign_process.mspx In code, using SetProcessAffinityMask and related functions: http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx -- Gabriel Genellina From mrabarnett at mrabarnett.plus.com Tue Feb 9 18:49:25 2010 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Tue, 09 Feb 2010 23:49:25 +0000 Subject: EAFP gone wrong In-Reply-To: References: Message-ID: <4B71F485.4050703@mrabarnett.plus.com> Arnaud Delobelle wrote: > Hi all, > > Hi have a set of classes that represent mathematical objects which can > be represented as a string using a 'latex' method (after Knuth's famous > typesetting system). As I want to be able to typeset some builtin types as > well, I have a generic function, latex(), as follows: > > def latex(val): > try: > return val.latex() > except AttributeError: > if isinstance(val, (tuple, list)): > return ", ".join(map(latex, val)) > elif isinstance(val, dict): > return ", ".join( > "%s=%s" % (latex(k), latex(v)) > for k, v in sorted(val.iteritems()) > ) > else: > return str(val) > > It's EAFP and I have used this for a while with no problem. Recently I > added a new class for 'n choose r' objects, as follows: > > class Choose(Expression): > def __init__(self, n, r): > self.subexprs = n, r > self.n = n > self.r = r > def calc(self, ns=None, calc=calc): > return choose(calc(self.n, ns), calc(self.r, ns)) > def latex(self): > return "{%s \\choose %s}" % (latex(self.n), latex(self.k)) > > When I create a Choose object and try to get its latex representation, > this happens: > >>>> c = Choose(5, 3) >>>> latex(c) > '' > > This puzzled me for a bit: why is it not trying to use the latex() > method of the Choose object? I read and reread the definition of the > latex() method for a while until I found that there was a typo. Where > it says: > > latex(self.k) > > it should say: > > latex(self.r) > > Thus it triggers an AttributeError, which is exactly the kind of > exception that I am catching in the latex() function after trying > val.latex(). (Of course I could have caught this by calling c.latex() > directly but it's such a short method definition that I couldn't imagine > missing the typo!). > > This means that EAFP made me hide a typo which would have been obviously > detected had I LBYLed, i.e. instead of > > try: > return val.latex() > except AttributeError: > ... > > do > > if hasattr(val, 'latex'): > return val.latex() > else: > ... > > > So was it wrong to say it's EAFP in this case? Should I have known to > LBYL from the start? How do you decide which one to use? Up to now, I > thought it was more or less a matter of taste but now this makes me > think that at least LBYL is better than catching AttributeError. > > Thanks for any guidance. > In addition to the other replies, you should've tested the Choose class. :-) From rantingrick at gmail.com Tue Feb 9 18:55:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 9 Feb 2010 15:55:36 -0800 (PST) Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: On Feb 9, 7:21?am, Roy Smith wrote: > In article <00fa27a3$0$15628$c3e8... at news.astraweb.com>, > ?Steven D'Aprano wrote: [..] > No pig latin? Wait a minute guys, Stevens a well known prankster and comic relief clown around here, I think he's just shining us all on! ;o) From jeanmichel at sequans.com Tue Feb 9 18:59:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 00:59:15 +0100 Subject: New to Python In-Reply-To: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <4B71F6D3.9020803@sequans.com> Quin wrote: > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > this generates output: > not found > processing > > so, it doesn't find the substring, but goes into processing code anyway. > > This is using IronPython The code you povided works as expected. Copy paste the exact code JM From gagsl-py2 at yahoo.com.ar Tue Feb 9 18:59:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 20:59:16 -0300 Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> <8281270.AG5xCW3FSB@beaureve.gmx.net> Message-ID: En Tue, 09 Feb 2010 15:47:43 -0300, Martin Drautzburg escribi?: > Carl Banks wrote: > >> You can have __add__ return a closure for the first addition, then >> perform the operation on the second one. Example (untested): >> > > That's way cool. > > Of course! - CURRYING!! If you can return closures > you can do everything with just single-parameter functions. insight> > > BTW I am not really trying to add three objects, I wanted a third object > which controls the way the addition is done. Sort of like "/" and "//" > which are two different ways of doing division. See http://code.activestate.com/recipes/384122/ for another cool hack that may help with that. -- Gabriel Genellina From rantingrick at gmail.com Tue Feb 9 19:01:44 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 9 Feb 2010 16:01:44 -0800 (PST) Subject: Easter Eggs References: Message-ID: <7e0eb494-71d6-47c6-96ad-fecf0866fb25@d27g2000yqn.googlegroups.com> On Feb 9, 5:40?pm, "Alf P. Steinbach" wrote: > I know 3 Python Easter Eggs, > > ? ?from __future__ import braces > ? ?import this > ? ?help( "antigravity" ) > > Are there more? > > Cheers, > > - Alf Oh this is just great ALF! Now what secrets will the Py-Illuminati have to giggle about whist watching Monty Python's flying circus and enjoying those delightfully delicious little crumpets? I very disappointed in you sir! :'-( PS WTF From alfps at start.no Tue Feb 9 19:06:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 01:06:02 +0100 Subject: Modifying Class Object In-Reply-To: <00fb7707$0$15628$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote: > >> You thought you cold do a bit of ad hominem attack. > > That phrase you keep using, "ad hominem"... it doesn't mean what you seem > to think it means. > > An ad hominem attack is not when somebody makes a criticism of you > personally. It is when somebody says something along the lines of "Don't > pay any attention to Alf, he doesn't know what he's talking about, he's a > ". ad hominem Latin [?d ?h?m??n?m] adj & adv 1. directed against a person rather than against his arguments 2. based on or appealing to emotion rather than reason Compare ad rem See also argumentum ad hominem > You might not like the personal criticism, but that doesn't make it > either an attack or a fallacy. Steve Holden attacked only at the personal level, via characterization. In response to ... > >> No idea. Nothing I know of can solve it [failure of article propagation]. > > Not sure, but perhaps it's possible to mail directly to gmane? ... Steve Holden wrote: Is there *any* problem you don't have a fatuous answer for? Which doesn't have anything to do with any subject matter discussed, not even the PS that he was replying to (which absolutely didn't warrant that description or any negative response), but which does convey an impression of a person. Then he wrote you assumed you knew better than Stephen [Hansen] which again is only about a person, and here about the person's motivations for trying to help. And there was a bit more with some collateral damage in the implications. It's pretty dirty and yes, personal attacks are ad hominem; see above. The ad hominem attacks that he appears to routinely engage in reflect back on Steve Holden but the sub-threads that they invariably spawn also constitute a high level of noise deflecting from whatever issue was discussed. Cheers & hth. (especially the dictionary reference), - Alf PS: in order to recognize various forms of fallacies the following is a quite useful resource: . I just typed "fallacies" in the Firefox address bar. - DS From gagsl-py2 at yahoo.com.ar Tue Feb 9 19:14:57 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 21:14:57 -0300 Subject: I've built Python, but can't figure out how to package it for windows References: Message-ID: En Tue, 09 Feb 2010 19:55:30 -0300, Mark Jones escribi?: > Python 2.6.4 is built, and I found a bdist_wininst project and > wininst-8 project. > > How do I manage to build the msi for this thing? See the Tools\msi directory; and look for some posts last year from Tim Golden regarding some issues with the directory layout and other details. -- Gabriel Genellina From rtw at freenet.co.uk Tue Feb 9 19:16:24 2010 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 09 Feb 2010 18:16:24 -0600 Subject: Problem Regarding Queue References: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> Message-ID: mukesh tiwari wrote in news:80fed7d5-76eb-40c8-ace1-0c35736de399 @t17g2000prg.googlegroups.com in comp.lang.python: > Could some one please tell what is wrong with this code. I am trying > to use Queue in this program but i am getting error The type you appear to be trying to use is Queue.Queue which you import with: from Queue import Queue http://docs.python.org/library/queue.html?highlight=queue#Queue.Queue > Q_1=Queue() > Q_2=Queue() > Q_1.put(n) > while(not Q_1.empty()): > l=Q_1.get() > if(rabin_miller(l)): > Q_2.put(l) > continue > d=pollard(l) > if(d==l):Q_1.put(l) > else: As the help page above points out also check out the deque Class: http://docs.python.org/library/collections.html#collections.deque Rob. From ben+python at benfinney.id.au Tue Feb 9 19:23:34 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 11:23:34 +1100 Subject: Personal criticisms and logical fallacies (was: Modifying Class Object) References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> Message-ID: <87eikuhrax.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > An ad hominem attack is not when somebody makes a criticism of you > personally. It is when somebody says something along the lines of > "Don't pay any attention to Alf, he doesn't know what he's talking > about, he's a ". In other words, a criticism of the person is only a fallacy if it is both irrelevant to the argument *and* used to dismiss the argument. Many criticisms are introduced not because they directly connect to the argument, but simply because they are relevant to the demonstrated behaviour at the time. > You might not like the personal criticism, but that doesn't make it > either an attack or a fallacy. Exactly. A personal criticism can be expressed *as a criticism*, and be valid or not without needing to be relevant to your chosen argument. Look to the criticism on its own merits, and decide what to do about it. -- \ ?If there were not God, there would be no atheists.? ?G. K. | `\ Chesterton | _o__) | Ben Finney From van.lindberg at gmail.com Tue Feb 9 19:24:15 2010 From: van.lindberg at gmail.com (VanL) Date: Tue, 09 Feb 2010 18:24:15 -0600 Subject: PyCon is coming! Tomorrow, Feb. 10 is the last day for pre-conference rates Message-ID: PyCon is coming! Tomorrow (February 10th) is the last day for pre-conference rates. You can register for PyCon online at: Register while it is still Feb. 10th somewhere in the world and rest easy in the knowledge that within 10 days you will enjoying the company of some of the finest Python hackers in the world. As an additional bonus, PyCon this year will be in Atlanta, making it an ideal location for those looking for a way to escape the late winter blizzards in the northeastern United States, or the dreary fog of the Bay area. See you at PyCon 2010! From mark0978 at gmail.com Tue Feb 9 19:24:58 2010 From: mark0978 at gmail.com (Mark Jones) Date: Tue, 9 Feb 2010 16:24:58 -0800 (PST) Subject: I've built Python, but can't figure out how to package it for windows References: Message-ID: That was so simple, thanks. I scanned all the folders for inst, install, setup, but since msi was the expected output extension, I didn't see that! On Feb 9, 6:14?pm, "Gabriel Genellina" wrote: > En Tue, 09 Feb 2010 19:55:30 -0300, Mark Jones ? > escribi?: > > > Python 2.6.4 is built, and I found a bdist_wininst project and > > wininst-8 project. > > > How do I manage to build the msi for this thing? > > See the Tools\msi directory; and look for some posts last year from Tim ? > Golden regarding some issues with the directory layout and other details. > > -- > Gabriel Genellina From half.italian at gmail.com Tue Feb 9 19:27:41 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Tue, 9 Feb 2010 16:27:41 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: <8fc356e0-f3ed-4a67-9b37-f21561cef4a5@p13g2000pre.googlegroups.com> On Feb 8, 2:36?pm, a... at pythoncraft.com (Aahz) wrote: > In article , > Sean DiZazzo ? wrote: > > >On Feb 3, 6:08=A0pm, alex23 wrote: > > >> There was also a PEP with another possible implementation: > >>http://www.python.org/dev/peps/pep-0355/ > > >Why did Path() get rejected? ?Is it the idea itself, or just the > >approach that was used? ?What are the complaints? > > You should search for the discussiona around it. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > import antigravity I read the discussion, and there was definitely some going back and forth on whether it should be sub-classed from string, but the conversation just seemed to stop abruptly with no decision one way of the other. Maybe I missed a thread. I guess being dropped without a final go-ahead is just as good as a formal no anyway. From gagsl-py2 at yahoo.com.ar Tue Feb 9 19:29:31 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 21:29:31 -0300 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: En Tue, 09 Feb 2010 20:27:13 -0300, Stef Mientki escribi?: > On 10-02-2010 00:09, Alf P. Steinbach wrote: >> * David Robinow: >>> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning >>> wrote: >>>> On 9 February 2010 16:29, Robert Kern wrote: >>>>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>>>>> If the code base stabilizes in a production version after losing the >>>>>> alphas and betas they would be a great addition to the stdlib, I >>>>>> think. >>>>> Why? >>>> I agree. Why wait? Put them in the stdlib now! >>> Can we please stop this? >> I agree. >> > sorry I don't, > unless Python is only meant for the very well educated people in > encryption. > >> I haven't looked at the code but the functionality that's listed is >> useful, e.g. in a Usenet client, and it's fun to play around with for a >> beginner. > I neither did look at the code, > but as a beginner with just 3 years of experience in Python, > I've tried several scrambling libs, for a quick and dirty use. > All were much too difficult, so I made my own xor-something. > Coming from Delphi, a scrambling lib is working is less than 10 minutes, > without the need of any knowledge of encryption. > I prefer Python over Delphi, but some things are made very complex in > Python. Are you sure? >>> def xor(s, key): ... return ''.join(chr(ord(c)^key) for c in s) ... >>> txt = "Hello world!" >>> xor(txt, 123) '3\x1e\x17\x17\x14[\x0c\x14\t\x17\x1fZ' >>> xor(_, 123) 'Hello world!' The Delphi code would be certainly longer than that, some variation of: function encrypt_xor(const s: string; key: integer); var i: integer; begin SetLength(Result, length(s)); for i:=1 to length(s) do begin Result[i] := chr(ord(s[i]) xor key); end; end; (untested) -- Gabriel Genellina From alfps at start.no Tue Feb 9 19:38:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 01:38:50 +0100 Subject: Personal criticisms and logical fallacies In-Reply-To: <87eikuhrax.fsf_-_@benfinney.id.au> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> Message-ID: * Ben Finney: > Steven D'Aprano writes: > >> An ad hominem attack is not when somebody makes a criticism of you >> personally. It is when somebody says something along the lines of >> "Don't pay any attention to Alf, he doesn't know what he's talking >> about, he's a ". > > In other words, a criticism of the person is only a fallacy if it is > both irrelevant to the argument *and* used to dismiss the argument. Or to weaken an argument, or to draw attention away from an argument, or to weaken future arguments... However, although in this particular case the Ad Hominems constituted logical fallacies, not all Ad Hominems are logical fallacies. For example, if a person is a chronic liar, has a known history of lying, then that can have a strong bearing on whether the person's claims -- technical or about other persons -- should be seriously considered[1]. Cheers & hth., - Alf Notes: [1] As explained at From gagsl-py2 at yahoo.com.ar Tue Feb 9 19:39:31 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 21:39:31 -0300 Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> Message-ID: En Tue, 09 Feb 2010 21:06:02 -0300, Alf P. Steinbach escribi?: > * Steven D'Aprano: >> On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote: >> >>> You thought you cold do a bit of ad hominem attack. >> That phrase you keep using, "ad hominem"... it doesn't mean what you >> seem to think it means. >> An ad hominem attack is not when somebody makes a criticism of you >> personally. It is when somebody says something along the lines of >> "Don't pay any attention to Alf, he doesn't know what he's talking >> about, he's a ". > > > ad hominem Latin [?d ?h?m??n?m] > adj & adv > 1. directed against a person rather than against his arguments ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 2. based on or appealing to emotion rather than reason Compare ad rem > See also argumentum ad hominem > > In response to ... > > > >> No idea. Nothing I know of can solve it [failure of article > propagation]. > > > > Not sure, but perhaps it's possible to mail directly to gmane? > > ... Steve Holden wrote: > > > Is there *any* problem you don't have a fatuous answer for? > > > Which doesn't have anything to do with any subject matter discussed, not > even the PS that he was replying to (which absolutely didn't warrant > that description or any negative response), but which does convey an > impression of a person. This doesn't make it an ad hominem fallacie. This is just criticism directed to your person, that you may like or not. It would be a fallacie if it were intended to dismiss your argument. > PS: in order to recognize various forms of fallacies the following is a > quite useful resource: . > I just typed "fallacies" in the Firefox address bar. - DS From the above site: "this fallacy involves two steps. First, an attack against the character of person making the claim [...] Second, this attack is taken to be evidence against the claim or argument the person in question is making (or presenting)." That second part is missing in S. H. posts. -- Gabriel Genellina From lists at cheimes.de Tue Feb 9 20:03:47 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 10 Feb 2010 02:03:47 +0100 Subject: ANN: obfuscate In-Reply-To: <4B71EF50.7050801@gmail.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: <4B7205F3.6040603@cheimes.de> Stef Mientki wrote: > sorry I don't, > unless Python is only meant for the very well educated people in encryption. All algorithms in obfuscate are obsolete, insecure and only interesting for people *that* want to get well educated in the history of encryption. > I neither did look at the code, > but as a beginner with just 3 years of experience in Python, > I've tried several scrambling libs, for a quick and dirty use. > All were much too difficult, so I made my own xor-something. > Coming from Delphi, a scrambling lib is working is less than 10 minutes, > without the need of any knowledge of encryption. > I prefer Python over Delphi, but some things are made very complex in > Python. It's tricky to implement modern cryptographic algorithms with Python. Most example codes are written in C and the implementations are using overflow (e.g. 255 + 1 == 0) a lot. It took me twice as long to get the TEA family (TEA, XTEA, XXTEA) crypt functions right in Python than I required to wrap existing code in an handwritten C interface. One of the strongest encryption algorithm in the list -- Vigen?re -- was crack over 150 years (!) ago. A much, much stronger version of the principles behind Vigen?re was used in the German Enigma machine. Because the algorithm was still not good enought some clever guy called Turing and his team was able to crack the enigma. It's one of the main reasons the Germans were defeated and the world doesn't look like in Robert Harris "Fatherland" today. Oh, and we go computers, too. ;) Grab pycrypto, m2crypto or one of the other packages if you need a minimum amount of security. Christian From ben+python at benfinney.id.au Tue Feb 9 20:24:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 12:24:44 +1100 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: <871vgtj31f.fsf@benfinney.id.au> Christian Heimes writes: > All algorithms in obfuscate are obsolete, insecure and only > interesting for people *that* want to get well educated in the history > of encryption. Not true. Another use case is suggested by the chosen name for the library: to obfuscate text against casual human reading, while not making it at all difficult to decrypt by people who are motivated to do so. The classic example is rot-13 encryption of text in internet messages; it would be a failure of imagination to suggest there are not other, similar use cases. > Grab pycrypto, m2crypto or one of the other packages if you need a > minimum amount of security. Agreed. However, for cases that *don't* need security from determined attackers, I don't think those obviate the usefulness of this library. -- \ ?Reality must take precedence over public relations, for nature | `\ cannot be fooled.? ?Richard P. Feynman | _o__) | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 20:35:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 01:35:21 GMT Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: On Wed, 10 Feb 2010 02:03:47 +0100, Christian Heimes wrote: > Stef Mientki wrote: >> sorry I don't, >> unless Python is only meant for the very well educated people in >> encryption. > > All algorithms in obfuscate are obsolete, insecure and only interesting > for people *that* want to get well educated in the history of > encryption. [...] > Grab pycrypto, m2crypto or one of the other packages if you need a > minimum amount of security. As the author of obfuscate, I would like to second Christian's statement. obfuscate is NOT meant for serious security, as I state in both the source code and the documentation to the module. That's not to say that it can't be useful for some people -- I wouldn't have spent the time writing it if I didn't think it was useful. But it is useful for obfuscation, education and puzzles, not for secure encryption. I'm not sure how serious the calls for this to be added to the standard library are. If they're serious, I'm grateful for the votes of confidence from people, but I can't imagine Guido saying yes. In any case, it's premature to talk about adding it to the std library while it is still in alpha. Thank you for all the comments, even the tongue-in-cheek ones. This has exceeded my wildest expectations! I'm always interested in feedback, good and bad, either publicly or privately. -- Steven From tjreedy at udel.edu Tue Feb 9 21:04:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Feb 2010 21:04:43 -0500 Subject: Programing family In-Reply-To: <4b719209$0$10071$426a34cc@news.free.fr> References: <4b719209$0$10071$426a34cc@news.free.fr> Message-ID: >>> C is Python's Mom >>> C++ : Dad Obviously no. The other parent might be arguably be Barbara Liskov's CLU, itself based on Algol. http://en.wikipedia.org/wiki/CLU_%28programming_language%29 CLU contributions: The basic object model, including mutable/immutable The function call-by-object model Iterators/generators/yield Multiple assignment and function returns Terry Jan Reedy From danielwong at berkeley.edu Tue Feb 9 21:40:26 2010 From: danielwong at berkeley.edu (danielx) Date: Tue, 9 Feb 2010 18:40:26 -0800 (PST) Subject: convention for documenting function parameters in doc strings References: Message-ID: On Feb 8, 2:49?am, Jean-Michel Pichavant wrote: > danielx wrote: > > Is there aconventionfor how to document function (or method) > > parameters in doc strings? Recently, I've been doing alot of PHP > > programming, and in PHPdoc, you'd do it like this: > > > /* > > ?* @param type $foo Description. > > ?* > > ?* @return type Description. > > ?*/ > > function bar($foo) { > > ? ... > > } > > > Is there an equivalentconventionI (c|sh)ould be using in my Python > > docstrings? I saw that Python 3 has function annotations, which could > > be used for this purpose, but function annotations have no particular > > purpose within the language itself (which seems like a mistake to me), > > and they don't exist in the Python 2.x series (at least not the older > > versions). > > Different strategies here: > > 1/ most doc builders propose their own format. You can stick to it if > you don't want to use another builder (e.g. epydoc has a specific syntax > to document signatures) > 2/ Use a 'standard' format, usually these formats are a bit more formal > but they gain in portability, most builders support these formats. > reStructuredText is one of them and supported by all python doc builders. > > http://epydoc.sourceforge.net/manual-othermarkup.html > > JM Thanks for the link, Jean-Michel. I was hoping to find out more about how this is don in reStructuredText, since that seems to be what's used to document Python at docs.python.org. There is a section in the page that you linked to which describes how documenting function parameters in reST works, which seems to be what I was looking for. From orgnut at yahoo.com Tue Feb 9 22:09:45 2010 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 09 Feb 2010 19:09:45 -0800 Subject: New to Python In-Reply-To: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: Quin wrote: > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > this generates output: > not found > processing > > so, it doesn't find the substring, but goes into processing code anyway. > > This is using IronPython As others have already said, this _does_ work properly. But a minor rearrangement is simpler, and IMHO clearer: if 'mystring' not in s: print 'not found' else: print 'foundit' print 'processing' -=- Larry -=- From quindennis at grandecom.net Tue Feb 9 22:30:52 2010 From: quindennis at grandecom.net (Quin) Date: Tue, 9 Feb 2010 21:30:52 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Thanks guys, I'm thinking it's a problem with IronPython. I'm switching to PyScripter and will test tomorrow. "Larry Hudson" wrote in message news:ybmdnRFZZ_3nvu_WnZ2dnUVZ_hGdnZ2d at giganews.com... > Quin wrote: >> s = f.readline() >> if 'mystring' in s: print 'foundit' >> if 'mystring' not in s: print 'not found' >> if 'mystring' in s: >> print 'processing' >> >> this generates output: >> not found >> processing >> >> so, it doesn't find the substring, but goes into processing code anyway. >> >> This is using IronPython > > As others have already said, this _does_ work properly. > > But a minor rearrangement is simpler, and IMHO clearer: > > if 'mystring' not in s: > print 'not found' > else: > print 'foundit' > print 'processing' > > -=- Larry -=- From python.list at tim.thechases.com Tue Feb 9 22:36:50 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Feb 2010 21:36:50 -0600 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <4B7229D2.8060704@tim.thechases.com> Larry Hudson wrote: > But a minor rearrangement is simpler, and IMHO clearer: > > if 'mystring' not in s: > print 'not found' > else: > print 'foundit' > print 'processing' I've always vacillated on whether that would better be written as Larry does, or as if 'mystring' in s print 'foundit' print 'processing' else: print 'not found' removing the "not" from the condition. I admit I choose one over the other based on some gut-feeling aesthetic that I can't really nail down. I think one of my major influencing factors revolves around the negative "not" portion having one or two lines and the positive portion having a large block of code. If the code-blocks are more equal in size, I tend to use "if {positive}", but if the negative "not" section is only 1-2 lines, I tend to do as Larry writes and make it harder to miss by using "if {negative}". Otherwise the "if {positive}...else" can end up sufficiently distant from the "if" that it's easy to miss. Any thoughts on how others make the choice? -tkc From cs at zip.com.au Tue Feb 9 22:54:17 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 10 Feb 2010 14:54:17 +1100 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <4B7229D2.8060704@tim.thechases.com> Message-ID: <20100210035417.GA5737@cskk.homeip.net> On 09Feb2010 21:36, Tim Chase wrote: | Larry Hudson wrote: | >But a minor rearrangement is simpler, and IMHO clearer: | > | >if 'mystring' not in s: | > print 'not found' | >else: | > print 'foundit' | > print 'processing' | | I've always vacillated on whether that would better be written as | Larry does, or as | | if 'mystring' in s | print 'foundit' | print 'processing' | else: | print 'not found' | | removing the "not" from the condition. I admit I choose one over | the other based on some gut-feeling aesthetic that I can't really | nail down. I think one of my major influencing factors revolves | around the negative "not" portion having one or two lines and the | positive portion having a large block of code. If the code-blocks | are more equal in size, I tend to use "if {positive}", but if the | negative "not" section is only 1-2 lines, I tend to do as Larry | writes and make it harder to miss by using "if {negative}". | Otherwise the "if {positive}...else" can end up sufficiently distant | from the "if" that it's easy to miss. I do it like you, usually: if one branch is small, it comes first, the other branch is easily in sight under the "else". Otherwise, I tend to go with "if {positive}", or at any rate "if {the easiest-to-read-form-of-the-test}" if it all still reads well. If the program flow gets ugly one way, that breaks "still reads well" and can be cause to flip the condition. In loops my tendency is a bit less flexible; I often have code like this: while ...: if winnowing-test: whinge set flag continue or break, depending main body of loop here... Not a lot of choice about positive/negative in that scenario, though it fits well with the first criterion. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A Master is someone who started before you did. - Gary Zukav From daniel at stutzbachenterprises.com Tue Feb 9 22:58:02 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Tue, 9 Feb 2010 21:58:02 -0600 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: On Tue, Feb 9, 2010 at 9:36 PM, Tim Chase wrote: > removing the "not" from the condition. I admit I choose one over the other > based on some gut-feeling aesthetic that I can't really nail down. I think > one of my major influencing factors revolves around the negative "not" > portion having one or two lines and the positive portion having a large > block of code. If one block is much shorter, I tend to put the shorter block first. That way, the "else" and the "if" are almost always on the screen together at the same time. If they're both long, I factor out one or both of the blocks into functions. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Feb 9 23:01:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 23:01:31 -0500 Subject: New to Python In-Reply-To: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Quin wrote: > Thanks guys, I'm thinking it's a problem with IronPython. I'm switching > to PyScripter and will test tomorrow. > I'd be very surprised to find that something as basic as this was wrong with IronPython. Complex commercial software has been built on it, so there's little question that the platform is sound. Are you *sure* you copied and pasted the session you listed? regards Steve > "Larry Hudson" wrote in message > news:ybmdnRFZZ_3nvu_WnZ2dnUVZ_hGdnZ2d at giganews.com... >> Quin wrote: >>> s = f.readline() >>> if 'mystring' in s: print 'foundit' >>> if 'mystring' not in s: print 'not found' >>> if 'mystring' in s: >>> print 'processing' >>> >>> this generates output: >>> not found >>> processing >>> >>> so, it doesn't find the substring, but goes into processing code anyway. >>> >>> This is using IronPython >> >> As others have already said, this _does_ work properly. >> >> But a minor rearrangement is simpler, and IMHO clearer: >> >> if 'mystring' not in s: >> print 'not found' >> else: >> print 'foundit' >> print 'processing' >> >> -=- Larry -=- > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Tue Feb 9 23:05:09 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 20:05:09 -0800 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: <7a9c25c21002092005k7b8f6a2csec1ea5a8c28ec530@mail.gmail.com> On Tue, Feb 9, 2010 at 7:58 PM, Daniel Stutzbach < daniel at stutzbachenterprises.com> wrote: > On Tue, Feb 9, 2010 at 9:36 PM, Tim Chase wrote: > >> removing the "not" from the condition. I admit I choose one over the >> other based on some gut-feeling aesthetic that I can't really nail down. I >> think one of my major influencing factors revolves around the negative "not" >> portion having one or two lines and the positive portion having a large >> block of code. > > > If one block is much shorter, I tend to put the shorter block first. That > way, the "else" and the "if" are almost always on the screen together at the > same time. If they're both long, I factor out one or both of the blocks > into functions. > Agree 100%. I like whatever the little branch is to be first, with the big branch falling into the "else:". It reads better then to have an "else:" at the end with only a line or two: in such a situation what 'else' is doesn't really have direct meaning, you have to look too far up to connect it to the "if" logic. Comments shouldn't be needed-- if an "else:" falls too far away from the "if" then scrolling around and looking for the code, it won't be immediately obvious in meaning. And if both branches are fairly long, it tends to imply that I just might benefit from some more functions to re-organize logic into manageable chunks. Then again, general rule of thumb? If a function is not entirely visible on my screen, it might imply I might benefit from some more functions. Though this is not anything like a hard rule. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Tue Feb 9 23:09:37 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 05:09:37 +0100 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: * Tim Chase: > Larry Hudson wrote: >> But a minor rearrangement is simpler, and IMHO clearer: >> >> if 'mystring' not in s: >> print 'not found' >> else: >> print 'foundit' >> print 'processing' > > I've always vacillated on whether that would better be written as Larry > does, or as > > if 'mystring' in s > print 'foundit' > print 'processing' > else: > print 'not found' > > removing the "not" from the condition. I admit I choose one over the > other based on some gut-feeling aesthetic that I can't really nail > down. I think one of my major influencing factors revolves around the > negative "not" portion having one or two lines and the positive portion > having a large block of code. If the code-blocks are more equal in > size, I tend to use "if {positive}", but if the negative "not" section > is only 1-2 lines, I tend to do as Larry writes and make it harder to > miss by using "if {negative}". Otherwise the "if {positive}...else" can > end up sufficiently distant from the "if" that it's easy to miss. > > Any thoughts on how others make the choice? I think it spills over from the practice of checking preconditions first, e.g. returning or raising exceptions or whatever. This avoids silly n-level nesting of the main "normal case" part. Cheers, - Alf From python at bdurham.com Tue Feb 9 23:45:28 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 09 Feb 2010 23:45:28 -0500 Subject: Creating formatted output using picture strings Message-ID: <1265777128.24758.1359202989@webmail.messagingengine.com> Does Python provide a way to format a string according to a 'picture' format? For example, if I have a string '123456789' and want it formatted like '(123)-45-(678)[9]', is there a module or function that will allow me to do this or do I need to code this type of transformation myself? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Wed Feb 10 00:24:20 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 21:24:20 -0800 Subject: Creating formatted output using picture strings In-Reply-To: <1265777128.24758.1359202989@webmail.messagingengine.com> References: <1265777128.24758.1359202989@webmail.messagingengine.com> Message-ID: <7a9c25c21002092124v51815151m96042ed8483afe23@mail.gmail.com> On Tue, Feb 9, 2010 at 8:45 PM, wrote: > Does Python provide a way to format a string according to a 'picture' > format? > > For example, if I have a string '123456789' and want it formatted like > '(123)-45-(678)[9]', is there a module or function that will allow me to do > this or do I need to code this type of transformation myself? > Although I usually don't jump to suggesting regular expressions, its the easiest way I can figure out to do this. >>> import re >>> >>> print re.sub(r"(\d{3})(\d{2})(\d{3})(\d)", r"(\1)-\2-(\3)[\4]", "123456789") (123)-45-(678)[9] --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptmcg at austin.rr.com Wed Feb 10 01:41:46 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 9 Feb 2010 22:41:46 -0800 (PST) Subject: How to measure elapsed time under Windows? References: Message-ID: <7c76a725-bd88-41a0-9867-820b82b872e7@l19g2000yqb.googlegroups.com> On Feb 9, 10:10?am, Grant Edwards wrote: > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > On Feb 9, 10:10 am, Grant Edwards wrote: > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > I made repeated calls to time.clock() in a generator expression, which is as fast a loop I can think of in Python. Then I computed the successive time deltas to see if any granularities jumped out. Here are the results: >>> import time >>> from itertools import groupby >>> >>> # get about 1000 different values of time.clock() >>> ts = set(time.clock() for i in range(1000)) >>> >>> # sort in ascending order >>> ts = sorted(ts) >>> >>> # compute diffs between adjacent time values >>> diffs = [j-i for i,j in zip(ts[:-1],ts[1:])] >>> >>> # sort and group >>> diffs.sort() >>> diffgroups = groupby(diffs) >>> >>> # print the distribution of time differences in microseconds >>> for i in diffgroups: print "%3d %12.6f" % (len(list(i[1])), i[0]*1e6) ... 25 2.234921 28 2.234921 242 2.514286 506 2.514286 45 2.793651 116 2.793651 1 3.073016 8 3.073016 6 3.352381 4 3.631746 3 3.911112 1 3.911112 5 4.190477 2 4.469842 1 6.146033 1 8.660319 1 9.777779 1 10.895239 1 11.174605 1 24.304765 1 41.904767 There seems to be a step size of about .28 microseconds. So I would guess time.clock() has enough resolution. But also beware of the overhead of the calls to clock() - using timeit, I find that each call takes about 2 microseconds (consistent with the smallest time difference in the above data set). -- Paul From apt.shansen at gmail.com Wed Feb 10 01:47:40 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 22:47:40 -0800 Subject: New to Python In-Reply-To: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <7a9c25c21002092247g2a3a2c4bt6e93921a73c005c3@mail.gmail.com> On Tue, Feb 9, 2010 at 7:30 PM, Quin wrote: > Thanks guys, I'm thinking it's a problem with IronPython. I'm switching to > PyScripter and will test tomorrow. > The chance of this being the case is vanishingly small. Provide real code, copy-pasted directly from a real file, and showing real results that demonstrate this behavior. There is no way that IronProfile is so utterly and fundamentally broken that such a simple and basic function doesn't work like this. There's no way that what you've shown us as describing the behavior is -really- what's happening. You seem to be paraphrasing code to illustrate a problem: but that's leaving out what's -really- causing the problem that you think isn't related, but really is. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Wed Feb 10 01:51:32 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 10 Feb 2010 01:51:32 -0500 Subject: Personal criticisms and logical fallacies In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> Message-ID: <20100210015132.3808f0d5.darcy@druid.net> On Wed, 10 Feb 2010 01:38:50 +0100 "Alf P. Steinbach" wrote: > However, although in this particular case the Ad Hominems constituted logical > fallacies, not all Ad Hominems are logical fallacies. Yes they are. Using the reputation of someone to prove or disprove their claims is a logical fallacy. > For example, if a person is a chronic liar, has a known history of lying, then > that can have a strong bearing on whether the person's claims -- technical or > about other persons -- should be seriously considered[1]. Yes but it's still a fallacy. Taking the author's history into account may be valid for deciding that further investigation is warranted but by itself it does not prove anything about the claims. Suggesting that it does is fallacious. "Bill is a liar therefore his statement is false" is a fallacy. "Bill is a liar so take his claims with a grain of salt" is not. There is another case. "Bill never tells the truth therefore his claim is wrong" is not an ad hominem fallacy. It's a sylogism. It may or may not be correct but if the first statement is true (Bill always lies) then the the conclusion is true. -- 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 howe.steven at gmail.com Wed Feb 10 02:06:24 2010 From: howe.steven at gmail.com (Steven Howe) Date: Tue, 09 Feb 2010 23:06:24 -0800 Subject: Personal criticisms and logical fallacies In-Reply-To: <20100210015132.3808f0d5.darcy@druid.net> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> <20100210015132.3808f0d5.darcy@druid.net> Message-ID: <4B725AF0.9030803@gmail.com> Really, is this a relevant topic on a program mail list? You guys need to get a room and start discussing angel counts on pinheads under the blankets. sph On 02/09/2010 10:51 PM, D'Arcy J.M. Cain wrote: > On Wed, 10 Feb 2010 01:38:50 +0100 > "Alf P. Steinbach" wrote: > >> However, although in this particular case the Ad Hominems constituted logical >> fallacies, not all Ad Hominems are logical fallacies. >> > Yes they are. Using the reputation of someone to prove or disprove > their claims is a logical fallacy. > > >> For example, if a person is a chronic liar, has a known history of lying, then >> that can have a strong bearing on whether the person's claims -- technical or >> about other persons -- should be seriously considered[1]. >> > Yes but it's still a fallacy. Taking the author's history into account > may be valid for deciding that further investigation is warranted but by > itself it does not prove anything about the claims. Suggesting that it > does is fallacious. > > "Bill is a liar therefore his statement is false" is a fallacy. "Bill > is a liar so take his claims with a grain of salt" is not. > > There is another case. "Bill never tells the truth therefore his > claim is wrong" is not an ad hominem fallacy. It's a sylogism. It may > or may not be correct but if the first statement is true (Bill always > lies) then the the conclusion is true. > > From ben+python at benfinney.id.au Wed Feb 10 02:41:53 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 18:41:53 +1100 Subject: Personal criticisms and logical fallacies References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> Message-ID: <87wrylh70e.fsf@benfinney.id.au> "D'Arcy J.M. Cain" writes: > On Wed, 10 Feb 2010 01:38:50 +0100 > "Alf P. Steinbach" wrote: > > However, although in this particular case the Ad Hominems > > constituted logical fallacies, not all Ad Hominems are logical > > fallacies. > > Yes they are. Using the reputation of someone to prove or disprove > their claims is a logical fallacy. The trouble is, the bulk of statements Alf is calling ?ad hominem attack? are, if one actually reads them, a criticism of his person. Not intended as a connecting claim in an argument, but a claim *distinct from* the argument Alf is engaged in. So they're *not intended* to prove or disprove the specific claims that immediately precede them. They're intended, at least partly, to provoke self-reflection on the part of the person criticised and, ideally, an improvement in behaviour. Failure to recognise a criticism as such, and instead repeatedly flinging the term ?ad hominem? around as though it has any bearing, is an example of behaviour that could easily be improved, if only the person engaging in it would stop. -- \ ?You've got to think about big things while you're doing small | `\ things, so that all the small things go in the right | _o__) direction.? ?Alvin Toffler | Ben Finney From apt.shansen at gmail.com Wed Feb 10 02:43:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 23:43:17 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> On Tue, Feb 9, 2010 at 1:08 PM, Alf P. Steinbach wrote: [abundant snips which do not accurately represent who said what where due to my own laziness] > Not sure, but perhaps it's possible to mail directly to gmane? >>>>> >>>>> Is there *any* problem you don't have a fatuous answer for? >>>> >>> I thought the answer could help. >>> >>> You thought you cold do a bit of ad hominem attack. >>> >>> That's the difference between us. >>> >>> Well, the way I see it, you assumed you knew better than Stephen, and >> insisted on proposing a solution to a problem that he clearly stated he >> had no interest in. >> > > You're going into motivations, that it seems to me that you're projecting, > saying that any helpful suggestion mean that one thinks one knows better and > implies a desire to demonstrate imagined superiority. > > You're trying to portray a helping hand as a negative personal > characteristic of the helper. > > "the only reason that guy tries to help you is because he wishes to show > how superior he (thinks he) is". > > That's your style in a fair number of postings, and now here: > > * ad hominem attack, > I am, frankly, tired of this. Please stop this overly obsessive sensitivity towards what you think are "ad hominem" attacks. Just drop it. Its worthless. It degrades you. Your arguments are frequently nothing more then, "I define the world this way and you do not disagree so I declare your argument invalid". You've dismissed at least one of my arguments with a simple hand-waving of, "That's invalid, cuz." The thing is, there was no basis for 'cuz' beyond "In my own head this is what I think, this is how I'm defining words" The response of others to such arguments has been, "Do you /really/ need to be so absolutely right in everything?!" which is said in frustration, irritation and with deep sighing. And then begins the loud declarations of ad hominem attacks. Its not productive. It doesn't help your case or arguments. Its tired. It doesn't make your case. It doesn't make anyone but you look bad. Every time you go on about, "YOU ARE AD HOMINEM'N ME!", you just make yourself look worse. Yeah. People can be snarky in a community. Maybe... MAYBE... Steve Holden is periodically a little snarky at you. It is not without reason. And your declarations of his ad hominem attacks against you comes off as nothing but base /whining/. Just drop it. Its boring. Also... I'm not quite sure, given that, what the point of the advice was. >> > > There are many people who read just the Usenet group, e.g. via Google > groups. > > When you say you don't understand the point of the advice, you're saying > that > > * those people don't matter, and that > > * it doesn't matter whether they can read Stephen Hansen's articles. > > That's > > * slighting Stephen Hansen, and > > * showing off an extreme ego-centric view of the world, > Please do NOT presume to take up my defense on ANY level. I can handle myself, thank you. I have said as much on two occasions that I don't know why some people seem unable to see my postings on usenet, and that despite this, I don't really care. It is not worth it to me to make my voice known to every possible listener in the world. I don't have sufficient vanity to assume that I need to be heard. I speak when it interests me to speak; and if heard, perhaps I'm listened to. Perhaps they will be helped. Perhaps they will not. Perhaps someone will argue with me. Perhaps we will both benefit from this debate and the exchange of ideas. That's the ideal situation, of course. Discourse and debate leading to new understanding. But I don't need anyone to defend my place in such discourse. I do not want, and utterly reject, anyone else standing up and taking any sort of stand on my behalf related to if someone else has slighted me. If and when I feel that I have been slighted, I will react accordingly. If Steve Holden slighted me in any way (he has not), I am more then capable of saying so on my own. I'd tell the BDFL he was an ass if he were an ass (he is not!) if I thought it was warranted. Thank you, but the value of my contribution to the community is a determination that I will make based on my own interest to share; and a determination those who do read me will make based on their interest to respond. If I needed everyone to hear me, I'd start up a blog and post rants all the time. If I felt that my contribution were not being heard fairly according to its worth, I'd try to take steps to make sure I was. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Wed Feb 10 02:53:53 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 08:53:53 +0100 Subject: Personal criticisms and logical fallacies In-Reply-To: <87wrylh70e.fsf@benfinney.id.au> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> <87wrylh70e.fsf@benfinney.id.au> Message-ID: * Ben Finney: > "D'Arcy J.M. Cain" writes: > >> On Wed, 10 Feb 2010 01:38:50 +0100 >> "Alf P. Steinbach" wrote: >>> However, although in this particular case the Ad Hominems >>> constituted logical fallacies, not all Ad Hominems are logical >>> fallacies. >> Yes they are. Using the reputation of someone to prove or disprove >> their claims is a logical fallacy. > > The trouble is, the bulk of statements Alf is calling ?ad hominem > attack? are, if one actually reads them, a criticism of his person. Not > intended as a connecting claim in an argument, but a claim *distinct > from* the argument Alf is engaged in. That's false. Happily anyone can check back, e.g. up-thread here. Judging by the last few months the number of persons engaging in ad hominem attacks in this group is small, counted on one hand with possibly one finger from the other hand to help. They're very active. But happily, few. However, in the other non-moderated groups I participate in the number of such persons is essentially *zero*, not counting sporadic visits from trolls. > So they're *not intended* to prove or disprove the specific claims that > immediately precede them. They're intended, at least partly, to provoke > self-reflection on the part of the person criticised and, ideally, an > improvement in behaviour. And that's ad hominem, implying unacceptable behavior on my part, which if you could back up you'd cited. > Failure to recognise a criticism as such, and instead repeatedly > flinging the term ?ad hominem? around as though it has any bearing, is > an example of behaviour that could easily be improved, if only the > person engaging in it would stop. Cheers & hth., - Alf From arnodel at googlemail.com Wed Feb 10 02:55:10 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 07:55:10 +0000 Subject: EAFP gone wrong References: Message-ID: Malte Helmert writes: > Arnaud Delobelle wrote: > >> This means that EAFP made me hide a typo which would have been obviously >> detected had I LBYLed, i.e. instead of >> >> try: >> return val.latex() >> except AttributeError: >> ... >> >> do >> >> if hasattr(val, 'latex'): >> return val.latex() >> else: >> ... >> >> >> So was it wrong to say it's EAFP in this case? > > I would say that it's not really the EAFP concept that is problematic > here, but rather that the try block encompasses more code than it > should. Generally try blocks should be as narrow as possible, i.e., they > should contain only the part where you really want to catch a potential > failure. > > "return val.latex()" does two separate things that might fail: the > lookup of val.latex, and the actual method call. If I understood you > correctly, you only want to catch the AttributeError in the "val.latex" > lookup here, and hence I'd say the "correct" application of EAFP here > would be something like: > > try: > foo = val.latex > except AttributeError: > ... > else: > return foo() > > Whether that's any better than LBYL in this particular case is of course > debatable -- one nice thing compared to your LBYL version is that it > doesn't look up val.latex twice upon success. But you could also get > that via the LBYLish: > > latex_method = getattr(val, "latex") > if latex_method: > return latex_method() > Ben, Malte, Thanks for your informative replies. I can now see where my blind spot was and that I never really used EAFP properly before. I think I will go with one of the two solutions above (probably the second) as I feel it's a bit heavy handed to create a closure and perhaps call it every time the latex() function is called. Matthew, You are right. Believe me I am fully aware of this. To my shame I have many thousands lines of Python without any tests in this project and I don't even know where to start... Thanks again, -- Arnaud From alfps at start.no Wed Feb 10 03:13:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 09:13:22 +0100 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> Message-ID: * Stephen Hansen: > > On Tue, Feb 9, 2010 at 1:08 PM, Alf P. Steinbach > wrote: > [abundant snips which do not accurately represent who said what where > due to my own laziness] > > Not sure, but perhaps it's possible to mail directly > to gmane? > > Is there *any* problem you don't have a fatuous answer for? > > I thought the answer could help. > > You thought you cold do a bit of ad hominem attack. > > That's the difference between us. > > Well, the way I see it, you assumed you knew better than > Stephen, and > insisted on proposing a solution to a problem that he clearly > stated he > had no interest in. > > > You're going into motivations, that it seems to me that you're > projecting, saying that any helpful suggestion mean that one thinks > one knows better and implies a desire to demonstrate imagined > superiority. > > You're trying to portray a helping hand as a negative personal > characteristic of the helper. > > "the only reason that guy tries to help you is because he wishes to > show how superior he (thinks he) is". > > That's your style in a fair number of postings, and now here: > > * ad hominem attack, > > > I am, frankly, tired of this. > > Please stop this overly obsessive sensitivity towards what you think are > "ad hominem" attacks. Just drop it. Its worthless. It degrades you. Your > arguments are frequently nothing more then, "I define the world this way > and you do not disagree so I declare your argument invalid". I'm happy that even though that may (with some low probability) be your actual opinion, it's incorrect. > You've > dismissed at least one of my arguments with a simple hand-waving of, > "That's invalid, cuz." That is not a quote of me. It is a lie. > The thing is, there was no basis for 'cuz' beyond > "In my own head this is what I think, this is how I'm defining words" That's also a lie, and it's not a quote of me. And just to be clear, as anyone can see by looking up-thread, generally, contrary to your claims, I give references for whatever that I suspect might be genuinely misunderstood. And so I've done in (nearly) every article in the original thread, especially for the terms, and still people have posted articles apparently mis-interpreting those terms in very non-sensible ways -- one gets tired of that, yes. > The response of others to such arguments has been, "Do you /really/ need > to be so absolutely right in everything?!" which is said in frustration, > irritation and with deep sighing. It's true that that kind of insinuative arguments have been used in this group, yes. It goes to alleged motives and alleged history instead of the technical, that is, it is a purely personal attack. So, ironically, you're here citing one kind of hominem attack -- not exactly clever when you're arguing that such does not occur. > And then begins the loud declarations of ad hominem attacks. > > Its not productive. It doesn't help your case or arguments. > > Its tired. > > It doesn't make your case. It doesn't make anyone but you look bad. > Every time you go on about, "YOU ARE AD HOMINEM'N ME!", you just make > yourself look worse. > > Yeah. People can be snarky in a community. Maybe... MAYBE... Steve > Holden is periodically a little snarky at you. It is not without reason. > And your declarations of his ad hominem attacks against you comes off as > nothing but base /whining/. > > Just drop it. > > Its boring. > > Also... > > I'm not quite sure, given that, what the point of the advice was. > > > There are many people who read just the Usenet group, e.g. via > Google groups. > > When you say you don't understand the point of the advice, you're > saying that > > * those people don't matter, and that > > * it doesn't matter whether they can read Stephen Hansen's articles. > > That's > > * slighting Stephen Hansen, and > > * showing off an extreme ego-centric view of the world, > > > Please do NOT presume to take up my defense on ANY level. > > I can handle myself, thank you. I do offer unsolicited help now and then, as I gave you and for which Steve Holden decided that a bit of personal attack would be suitable. But my help was just as much in order to help others (who can't read your non-propagated articles) as in order to help you personally. That's the spirit of Usenet in many other groups. One just helps out, and often the reaction is a "thank you" instead of an ad hominem attack (as with Steve Holden) or, as in your case, faked quotes and general lies, which is border-line ad hominem. Anyway, please stop post faked quotes and general lies, as you do above. Cheers & hth., - Alf From apt.shansen at gmail.com Wed Feb 10 03:27:24 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 00:27:24 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> Message-ID: <7a9c25c21002100027q377d902cp9578312c7dffe9cc@mail.gmail.com> On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach wrote: > You've dismissed at least one of my arguments with a simple hand-waving of, >> "That's invalid, cuz." >> > > That is not a quote of me. It is a lie. > > > > The thing is, there was no basis for 'cuz' beyond "In my own head this is >> what I think, this is how I'm defining words" >> > > That's also a lie, and it's not a quote of me. > On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach wrote: > > Anyway, please stop post faked quotes and general lies, as you do above. Wow. If that's your argument, I question your sanity. None of the "quotes" were faked. None of the "quotes" were lies. If a message were intended as an actual quotation of another's words, I'd include actual citation. That a message is included in quotation-characters does not make it an actual citation. They are, quite obviously IMHO, paraphrased references to how I evaluate your arguments. The word "cuz" alone seems to make that very, very, very, very, very, very obvious. Get over yourself. Seriously. Quote marks don't make a quotation. If and when I choose to quote you, I will quote you. You will see a line saying, as you see above, "On , Alf wrote:" > >> I can handle myself, thank you. >> > > I do offer unsolicited help now and then, as I gave you and for which Steve > Holden decided that a bit of personal attack would be suitable. > > But my help was just as much in order to help others (who can't read your > non-propagated articles) as in order to help you personally. That's the > spirit of Usenet in many other groups. One just helps out, and often the > reaction is a "thank you" instead of an ad hominem attack (as with Steve > Holden) or, as in your case, faked quotes and general lies, which is > border-line ad hominem. > I reject the assistance of you-- or anyone else-- to make my voice heard. You do not speak for me. You will not speak for me. I speak for myself, thank you. Do not presume to subjugate my voice by defending it for your purposes. Anyway, please stop post faked quotes and general lies, as you do above. I didn't. You're nuts if you think I did. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Wed Feb 10 03:31:43 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Feb 2010 00:31:43 -0800 (PST) Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> <8281270.AG5xCW3FSB@beaureve.gmx.net> Message-ID: On Feb 9, 6:47?pm, Martin Drautzburg wrote: > BTW I am not really trying to add three objects, I wanted a third object > which controls the way the addition is done. Sort of like "/" and "//" > which are two different ways of doing division. That seems like a reasonable use case for a third parameter to __add__, though as others have pointed out the only way to pass the third argument is to call __add__ explicitly. Here's an extract from the decimal module: class Decimal(object): ... def __add__(self, other, context=None): other = _convert_other(other) if other is NotImplemented: return other if context is None: context = getcontext() ... And here's how it's used in the decimal.Context module: class Context(object): ... def add(self, a, b): """Return the sum of the two operands. >>> ExtendedContext.add(Decimal('12'), Decimal('7.00')) Decimal('19.00') >>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4')) Decimal('1.02E+4') """ return a.__add__(b, context=self) -- Mark From martin.hellwig at dcuktec.org Wed Feb 10 03:40:44 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Feb 2010 08:40:44 +0000 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: On 02/10/10 03:36, Tim Chase wrote: > Larry Hudson wrote: >> But a minor rearrangement is simpler, and IMHO clearer: >> >> if 'mystring' not in s: >> print 'not found' >> else: >> print 'foundit' >> print 'processing' > > I've always vacillated on whether that would better be written as Larry > does, or as > > if 'mystring' in s > print 'foundit' > print 'processing' > else: > print 'not found' > > Any thoughts on how others make the choice? > I cases like this when aesthetics are not that much of a deal breaker, I usually put the condition which I think will be the true the majority of the time first. This is not for performance reasons (never tested whether this has any effect) but more documentation like purpose to go from a most expected case to the least expected one. YMMV -- mph From apt.shansen at gmail.com Wed Feb 10 03:41:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 00:41:02 -0800 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002100027q377d902cp9578312c7dffe9cc@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <7a9c25c21002100027q377d902cp9578312c7dffe9cc@mail.gmail.com> Message-ID: <7a9c25c21002100041n17dbdce4ycce5f9eb974b9940@mail.gmail.com> > > On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach wrote: > >> I do offer unsolicited help now and then, as I gave you and for which >>> Steve Holden decided that a bit of personal attack would be suitable. >> >> Really, I do have to say. It's one thing to say, "Aren't you being rude?" (please note, this is not an actual quotation of any actual person, and I feel it is required I make this disclaimer since you have shown you are unable to differentiate a statement paraphrased in quotation marks from an actual quotation and citation of another's words) It's another thing entirely to decide on your own to be my champion and choose to speak for me in my defense. The former is someone offering unsolicited help; the latter I find more then a little insulting. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Wed Feb 10 03:42:05 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Feb 2010 00:42:05 -0800 (PST) Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> <8281270.AG5xCW3FSB@beaureve.gmx.net> Message-ID: <67d10050-7553-4c88-8dbb-f51c19cb2b5e@j31g2000yqa.googlegroups.com> On Feb 10, 8:31?am, Mark Dickinson wrote: > And here's how it's used in the decimal.Context module: Aargh! decimal.Context *class*, not module. And it occurs to me that it would have been cleaner to have Decimal.__add__ call Context.add rather than the other way around. Then Decimal.__add__ could have stayed a two-argument function, as intended. Oh well. -- Mark From klausneuner72 at googlemail.com Wed Feb 10 03:58:37 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Wed, 10 Feb 2010 00:58:37 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> On Feb 9, 11:01?am, Stefan Behnel wrote: > KlausNeuner, 09.02.2010 10:04: > > > my program is supposed to parse files that I have created myself and that > > are on my laptop. It is not supposed to interact with anybody else > > than me. > > Famous last words. > > Stefan All right, I admit that eval() is evil and should never be used. Under no circumstances. (Which is, of course, the reason, why Python has eval().) The same applies to knives. You shouldn't use them. You shouldn't even use them in your own kitchen. A man might enter your kitchen, take your knife away and use it against you. From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 04:28:20 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 10:28:20 +0100 Subject: Programing family In-Reply-To: <00fb7592$0$15628$c3e8da3@news.astraweb.com> References: <4b719209$0$10071$426a34cc@news.free.fr> <00fb7592$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4b727c27$0$10168$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Tue, 09 Feb 2010 17:49:21 +0100, Bruno Desthuilliers wrote: > >> Not that much C++ in Python, IMHO. If that's for the OO part, then the >> closer to Python's object model I can think of is javascript. > > I thought that Javascript didn't even have inheritance until recently? If you mean "class inheritance", it's obviously not something you'd expect to find in a prototype based language. But inheritance works with prototypes too. From __peter__ at web.de Wed Feb 10 04:45:37 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Feb 2010 10:45:37 +0100 Subject: Creating formatted output using picture strings Message-ID: python at bdurham.com wrote: > Does Python provide a way to format a string according to a > 'picture' format? > > For example, if I have a string '123456789' and want it formatted > like '(123)-45-(678)[9]', is there a module or function that will > allow me to do this or do I need to code this type of > transformation myself? A basic implementation without regular expressions: >>> def picture(s, pic, placeholder="@"): ... parts = pic.split(placeholder) ... result = [None]*(len(parts)+len(s)) ... result[::2] = parts ... result[1::2] = s ... return "".join(result) ... >>> >>> picture("123456789", "(@@@)-@@-(@@@)[@]") '(123)-45-(678)[9]' Peter From nad at acm.org Wed Feb 10 05:11:59 2010 From: nad at acm.org (Ned Deily) Date: Wed, 10 Feb 2010 02:11:59 -0800 Subject: mac install References: Message-ID: In article , Thomas Nelson wrote: > I downloaded the 3.1.1 dmg from http://www.python.org/download/releases/3.1.1/ > but when I run it I get the error "The folowing install step failed: > run postflight script for python documentation." The bugs list has > this bug at http://bugs.python.org/issue6934 but it's described as > fixed. Is it only fixed for the source version? Where should I go to > install? Unfortunately, there hasn't been a release of Python 3.1 since 3.1.1. On the other hand, the problem isn't critical: it only prevents the installation from creating the .pyc compiled byte-code files for the python files in the standard library. Python 3.1.1 should run just fine, albeit sometimes a bit slower, without them. -- Ned Deily, nad at acm.org From quindennis at grandecom.net Wed Feb 10 05:21:44 2010 From: quindennis at grandecom.net (Quin) Date: Wed, 10 Feb 2010 04:21:44 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Well, PyScripter works find with that code. Furthermore, the un-intellisense in IronPython was problematic, inserting the wrong things, which I had to erase. Also, there were some code constructs IronPython let pass that PyScripter didn't, namely, print(), PyScripter requires the () Something simple, like: n = -1 if n <> -1: print('fell through') falls through to the print. So, I don't know what the problem is with IronPython, perhaps it isn't compatible with Python v3, but on my machine, at least, it doesn't perform. "Steve Holden" wrote in message news:mailman.2272.1265774639.28905.python-list at python.org... > Quin wrote: >> Thanks guys, I'm thinking it's a problem with IronPython. I'm switching >> to PyScripter and will test tomorrow. >> > I'd be very surprised to find that something as basic as this was wrong > with IronPython. Complex commercial software has been built on it, so > there's little question that the platform is sound. > > Are you *sure* you copied and pasted the session you listed? > > regards > Steve > >> "Larry Hudson" wrote in message >> news:ybmdnRFZZ_3nvu_WnZ2dnUVZ_hGdnZ2d at giganews.com... >>> Quin wrote: >>>> s = f.readline() >>>> if 'mystring' in s: print 'foundit' >>>> if 'mystring' not in s: print 'not found' >>>> if 'mystring' in s: >>>> print 'processing' >>>> >>>> this generates output: >>>> not found >>>> processing >>>> >>>> so, it doesn't find the substring, but goes into processing code >>>> anyway. >>>> >>>> This is using IronPython >>> >>> As others have already said, this _does_ work properly. >>> >>> But a minor rearrangement is simpler, and IMHO clearer: >>> >>> if 'mystring' not in s: >>> print 'not found' >>> else: >>> print 'foundit' >>> print 'processing' >>> >>> -=- Larry -=- >> > > > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > From jeanmichel at sequans.com Wed Feb 10 05:22:12 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 11:22:12 +0100 Subject: New to Python In-Reply-To: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <4B7288D4.8010704@sequans.com> Quin wrote: > Thanks guys, I'm thinking it's a problem with IronPython. I'm > switching to PyScripter and will test tomorrow. > > I'm willing to bet money that it is not. If ironPython had a broken if statement, don't you think we would have known, already ? There's a rule when test writing/testing code: "if you think the compiler is wrong, then you are wrong twice." JM From quindennis at grandecom.net Wed Feb 10 05:23:43 2010 From: quindennis at grandecom.net (Quin) Date: Wed, 10 Feb 2010 04:23:43 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Well, now you know! "Jean-Michel Pichavant" wrote in message news:mailman.2286.1265797348.28905.python-list at python.org... > Quin wrote: >> Thanks guys, I'm thinking it's a problem with IronPython. I'm switching >> to PyScripter and will test tomorrow. >> >> > I'm willing to bet money that it is not. If ironPython had a broken if > statement, don't you think we would have known, already ? > > There's a rule when test writing/testing code: > "if you think the compiler is wrong, then you are wrong twice." > > JM From olof.bjarnason at gmail.com Wed Feb 10 05:50:45 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 10 Feb 2010 11:50:45 +0100 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: 2010/2/10 Peter Otten <__peter__ at web.de>: > python at bdurham.com wrote: > >> Does Python provide a way to format a string according to a >> 'picture' format? >> >> For example, if I have a string '123456789' and want it formatted >> like '(123)-45-(678)[9]', is there a module or function that will >> allow me to do this or do I need to code this type of >> transformation myself? > > A basic implementation without regular expressions: > >>>> def picture(s, pic, placeholder="@"): > ... ? ? parts = pic.split(placeholder) > ... ? ? result = [None]*(len(parts)+len(s)) > ... ? ? result[::2] = parts > ... ? ? result[1::2] = s > ... ? ? return "".join(result) > ... >>>> >>>> picture("123456789", "(@@@)-@@-(@@@)[@]") > '(123)-45-(678)[9]' > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > Inspired by your answer here's another version: >>> def picture(s, pic): ... if len(s)==0: return pic ... if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) ... return pic[0]+picture(s, pic[1:]) ... >>> picture("123456789", "(###)-##-(###)[#]") '(123)-45-(678)[9]' >>> -- http://olofb.wordpress.com From jeanmichel at sequans.com Wed Feb 10 05:53:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 11:53:46 +0100 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <4B72903A.1030404@sequans.com> Quin wrote: > Well, now you know! > > "Jean-Michel Pichavant" wrote in message > news:mailman.2286.1265797348.28905.python-list at python.org... >> Quin wrote: >>> Thanks guys, I'm thinking it's a problem with IronPython. I'm >>> switching to PyScripter and will test tomorrow. >>> >>> >> I'm willing to bet money that it is not. If ironPython had a broken >> if statement, don't you think we would have known, already ? >> >> There's a rule when test writing/testing code: >> "if you think the compiler is wrong, then you are wrong twice." >> >> JM > All I know is that you are using a python implementation that does not support python 3. No wonder why your py3 code fails. Please do not top post. JM IronPython * Stable Version is 2.0.3 (targeting Python 2.5) * Developers Version is 2.6 Beta 3 (targeting Python 2.6) From fetchinson at googlemail.com Wed Feb 10 06:06:37 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 10 Feb 2010 12:06:37 +0100 Subject: ANN: obfuscate In-Reply-To: <871vgtj31f.fsf@benfinney.id.au> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> Message-ID: >> All algorithms in obfuscate are obsolete, insecure and only >> interesting for people *that* want to get well educated in the history >> of encryption. > > Not true. Another use case is suggested by the chosen name for the > library: to obfuscate text against casual human reading, while not > making it at all difficult to decrypt by people who are motivated to do > so. > > The classic example is rot-13 encryption of text in internet messages; > it would be a failure of imagination to suggest there are not other, > similar use cases. I fully agree. Judging by the posts on c.l.p the need for simple obfuscation regularly comes up. I also posted something not so long ago and got all sorts of useful advice, a package here, a module there, etc. It also turned out that everybody mostly writes his/her own obfuscation routine. That is why I suggested that perhaps if the code base stabilizes an inclusion into the stdlib could be discussed. I'm not sure it really needs to go there but if it turns out that as many people need this kind of stuff as I imagine it, well, then we have enough use cases for sure. >> Grab pycrypto, m2crypto or one of the other packages if you need a >> minimum amount of security. > > Agreed. However, for cases that *don't* need security from determined > attackers, I don't think those obviate the usefulness of this library. Exactly. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From simon at brunningonline.net Wed Feb 10 06:12:26 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Feb 2010 11:12:26 +0000 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: <8c7f10c61002100312j39c775ddi736af6693e1e2549@mail.gmail.com> On 10 February 2010 03:36, Tim Chase wrote: > Any thoughts on how others make the choice? There are two criteria that I use here. I'll often tend towards the positive test; it's just that little bit easier to comprehend, I think. On the other hand, if one case is overwhelmingly more common, I'll usually put that first even if it does mean using a negative test. I'm not buying the short-case-first argument. If the code in a case block is long enough for that to matter, it really belongs in a function of its own anyway. -- Cheers, Simon B. From simon at brunningonline.net Wed Feb 10 06:23:01 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Feb 2010 11:23:01 +0000 Subject: ANN: obfuscate In-Reply-To: <871vgtj31f.fsf@benfinney.id.au> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> Message-ID: <8c7f10c61002100323v1650769dob3d0411a0c5b08c8@mail.gmail.com> On 10 February 2010 01:24, Ben Finney wrote: > The classic example is rot-13 encryption of text in internet messages; > it would be a failure of imagination to suggest there are not other, > similar use cases. That's built-in: >>> "Hello World!".encode('rot-13') 'Uryyb Jbeyq!' -- Cheers, Simon B. From mail at timgolden.me.uk Wed Feb 10 06:27:48 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Feb 2010 11:27:48 +0000 Subject: ANN: obfuscate In-Reply-To: <8c7f10c61002100323v1650769dob3d0411a0c5b08c8@mail.gmail.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> <8c7f10c61002100323v1650769dob3d0411a0c5b08c8@mail.gmail.com> Message-ID: <4B729834.7050606@timgolden.me.uk> On 10/02/2010 11:23, Simon Brunning wrote: > "Hello World!".encode('rot-13') Not any more! Python 3.1.1 (r311:74483, Aug 17 2009, win32 Type "help", "copyright", "credits" or >>> "Hello World!".encode('rot-13') Traceback (most recent call last): File "", line 1, in LookupError: unknown encoding: rot-13 >>> TJG From alfps at start.no Wed Feb 10 06:45:47 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 12:45:47 +0100 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: * Olof Bjarnason: > 2010/2/10 Peter Otten <__peter__ at web.de>: >> python at bdurham.com wrote: >> >>> Does Python provide a way to format a string according to a >>> 'picture' format? >>> >>> For example, if I have a string '123456789' and want it formatted >>> like '(123)-45-(678)[9]', is there a module or function that will >>> allow me to do this or do I need to code this type of >>> transformation myself? >> A basic implementation without regular expressions: >> >>>>> def picture(s, pic, placeholder="@"): >> ... parts = pic.split(placeholder) >> ... result = [None]*(len(parts)+len(s)) >> ... result[::2] = parts >> ... result[1::2] = s >> ... return "".join(result) >> ... >>>>> picture("123456789", "(@@@)-@@-(@@@)[@]") >> '(123)-45-(678)[9]' >> >> Peter >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Inspired by your answer here's another version: > >>>> def picture(s, pic): > ... if len(s)==0: return pic > ... if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) > ... return pic[0]+picture(s, pic[1:]) > ... >>>> picture("123456789", "(###)-##-(###)[#]") > '(123)-45-(678)[9]' I learned a bit by Peter Otten's example; I would have gotten to that notation sooner or later, but that example made it 'sooner' :-). I think your version is cute. I'd probably write it in a non-recursive way, though, like def picture( s, pic, placeholder = "@" ): result = "" char_iter = iter( s ) for c in pic: result += c if c != placeholder else next( char_iter ) return result Of course this is mostly personal preference, but there is also a functional difference. With your version an IndexError will be raised if there are too /many/ characters in s, while too few characters in s will yield "#" in the result. With my version a StopIteration will be raised if there are to /few/ characters in s, while too many characters will just have the extraneous chars ignored. Cheers, - Alf From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 06:55:44 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 12:55:44 +0100 Subject: use strings to call functions In-Reply-To: <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> Message-ID: <4b729eb2$0$18397$426a74cc@news.free.fr> Klaus Neuner a ?crit : > > All right, I admit that eval() is evil and should never be used. Can you tell the difference between your above statement and the following: """ eval() is potentially dangerous and can make code harder to debug. 99% of the proposed use case for eval() are covered by simpler, less dangerous and easier to understand solutions, so the GoodPractice(tm) is to favor these solutions and only use eval() - with appropriate care - for the remaining 1% _real_ use case. """ If you can't tell the difference, then you're about as (im)mature as my 13 year old son and it might eventually be time to grow up. > The same applies to knives. You shouldn't use them. You > shouldn't even use them in your own kitchen. A man might enter your > kitchen, take your knife away and use it against you. Knives - specially the kind I use in my kitchen - are indeed potentially dangerous, and I indeed had to educate my son so he wouldn't do anything stupid with them - like pointing a knife at someone, running across the house with a knife in his hand, or using them instead of a more appropriate tool. The probability that someone will enter your kitchen and use one of your knives against you, while not null, are low enough to be ignored IMHO. I whish I could say the same about script kiddies or more educated (and dangerous) bad guys trying to attack our servers. But you obviously never had to neither fix a compromised server nor raise a kid - else you'd now better. Hopefully you didn't raise my kid - now I just pray none of your code will ever run on our servers. From martin.hellwig at dcuktec.org Wed Feb 10 06:59:40 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Feb 2010 11:59:40 +0000 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: On 02/10/10 10:53, Jean-Michel Pichavant wrote: > Quin wrote: >> Well, now you know! >> > > All I know is that you are using a python implementation that does not > support python 3. No wonder why your py3 code fails. > You knew you known, you know :-) -- mph From snarks at gmail.com Wed Feb 10 07:24:36 2010 From: snarks at gmail.com (Phil Hibbs) Date: Wed, 10 Feb 2010 04:24:36 -0800 (PST) Subject: Generic spreadsheet interface Message-ID: <3acdf3a7-e2eb-4a9a-bc89-7e285073a9c9@o28g2000yqh.googlegroups.com> I've currently got an Excel spreadsheet with loads of VBA, and I've been thinking of porting it to OpenOffice.org. "This is a Python list!" I hear you cry, but bear with me - rather than just re-writing all the VBA code in OOo script, I thought, "why not make it generic - so it can work with Excel or OOo?" - then I thought of Python. Python can interface with both, but the specifics of how to interface with each are very different. What would be nice is a generic wrapper class that can work with either. Has anyone come across anything like that? Phil Hibbs. From fuzzyman at gmail.com Wed Feb 10 07:28:02 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Feb 2010 04:28:02 -0800 (PST) Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: On Feb 3, 7:38?pm, Phlip wrote: > On Feb 3, 10:57?am, Adam Tauno Williams > wrote: > > > > Current editors suck because they can't see into the code and browse > > > it - unless it's so statically typed it's painful. > > > ? ?I edit Python in MonoDevelop ?2.2; ?and I can browse my file, > > classes, etc... ?So I don't know what you mean by "can't see into the > > code". ?It works pretty well. > > > Of course it can't tell that I've set x = {an integer}, as that only > > happens at runtime. > > > > That's why I wrote this: > > >http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_ed... > > You just said that your code browsing "works pretty well, except when > it doesn't". > > Hence my blog entry. If your editor analyzed your code at runtime, > instead of just static analysis, then it could see that x = an > integer, or an object, no matter how dynamic your language. > The Wingware Wing IDE has an integrated debugger. The IDE does type inferencing through static analysis to provide autocomplete and code navigation features. If you run the code under the debugger it will also use 'actual' type information to augment the static analysis. Michael Foord -- http://www.voidspace.org.uk/ From mailings at julianmoritz.de Wed Feb 10 07:40:39 2010 From: mailings at julianmoritz.de (Julian) Date: Wed, 10 Feb 2010 04:40:39 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: hello there, thanks everyone for that many answers! I'm lying in bed with a bad cold, so I'll get through all the posts on the weekend. regards Julian From olof.bjarnason at gmail.com Wed Feb 10 07:46:31 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 10 Feb 2010 13:46:31 +0100 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: 2010/2/10 Alf P. Steinbach : > * Olof Bjarnason: >> >> 2010/2/10 Peter Otten <__peter__ at web.de>: >>> >>> python at bdurham.com wrote: >>> >>>> Does Python provide a way to format a string according to a >>>> 'picture' format? >>>> >>>> For example, if I have a string '123456789' and want it formatted >>>> like '(123)-45-(678)[9]', is there a module or function that will >>>> allow me to do this or do I need to code this type of >>>> transformation myself? >>> >>> A basic implementation without regular expressions: >>> >>>>>> def picture(s, pic, placeholder="@"): >>> >>> ... ? ? parts = pic.split(placeholder) >>> ... ? ? result = [None]*(len(parts)+len(s)) >>> ... ? ? result[::2] = parts >>> ... ? ? result[1::2] = s >>> ... ? ? return "".join(result) >>> ... >>>>>> >>>>>> picture("123456789", "(@@@)-@@-(@@@)[@]") >>> >>> '(123)-45-(678)[9]' >>> >>> Peter >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> Inspired by your answer here's another version: >> >>>>> def picture(s, pic): >> >> ... ? if len(s)==0: return pic >> ... ? if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) >> ... ? return pic[0]+picture(s, pic[1:]) >> ... >>>>> >>>>> picture("123456789", "(###)-##-(###)[#]") >> >> '(123)-45-(678)[9]' > > I learned a bit by Peter Otten's example; I would have gotten to that > notation sooner or later, but that example made it 'sooner' :-). > > I think your version is cute. Thanks! Here's another version (maybe a little more readable?): def first(s): return s[0] def rest(s): return s[1:] def picture(s, pic): if not s: return pic if first(pic)=='#': return first(s)+picture(rest(s), rest(pic)) return first(pic)+picture(s, rest(pic)) > > I'd probably write it in a non-recursive way, though, like > > ? ?def picture( s, pic, placeholder = "@" ): > ? ? ? ?result = "" > ? ? ? ?char_iter = iter( s ) > ? ? ? ?for c in pic: > ? ? ? ? ? ?result += c if c != placeholder else next( char_iter ) > ? ? ? ?return result > > Of course this is mostly personal preference, but there is also a functional > difference. > > With your version an IndexError will be raised if there are too /many/ > characters in s, while too few characters in s will yield "#" in the result. > > With my version a StopIteration will be raised if there are to /few/ > characters in s, while too many characters will just have the extraneous > chars ignored. > > > Cheers, > > - Alf > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://olofb.wordpress.com From klausneuner72 at googlemail.com Wed Feb 10 08:24:33 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Wed, 10 Feb 2010 05:24:33 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> <4b729eb2$0$18397$426a74cc@news.free.fr> Message-ID: On Feb 10, 12:55?pm, Bruno Desthuilliers wrote: > KlausNeunera ?crit : > > > > > All right, I admit that eval() is evil and should never be used. > > Can you tell the difference between your above statement and the following: As already pointed out in my second post (though perhaps not explicitly enough), I like the getattr-stuff better than eval(). That is why I will not use eval(). I don't have a reason to use eval(). All I wanted to say is this: If there are no circumstances at all under which eval() can reasonably be used, then it should not be part of Python. As it is part of Python (and as Python is a carefully designed language), there will most probably some situations in which one might want to use it. From almar.klein at gmail.com Wed Feb 10 08:29:42 2010 From: almar.klein at gmail.com (Almar Klein) Date: Wed, 10 Feb 2010 14:29:42 +0100 Subject: ANN: visvis v1.1 Message-ID: Hi all, I am pleased to announce version 1.1 of visvis, a Python visualization library for of 1D to 4D data. Website: http://code.google.com/p/visvis/ Discussion group: http://groups.google.com/group/visvis/ Documentation: http://code.google.com/p/visvis/wiki/Visvis_basics === Description === Visvis is a pure Python visualization library that uses OpenGl to display 1D to 4D data; it can be used from simple plotting tasks to rendering 3D volumetric data that moves in time. Visvis can be used in Python scripts, interactive Python sessions (as with IPython) and can be embedded in applications. Visvis employs an object oriented structure; each object being visualized (e.g. a line or a texture) has various properties that can be modified to change its behavior or appearance. A Matlab-like interface in the form of a set of functions allows easy creation of these objects (e.g. plot(), imshow(), volshow()). === Changes === A complete list can be found at http://code.google.com/p/visvis/wiki/releaseNotes. - Colormaps are now supported for texture objects. A colorbar and colormapEditor wibject are also available. - The performance of rendering 3D volumes has significantly improved. A new shader (raycast) is also available). - Fonts are rendered more smoothly and faster. - Data for textures is automatically padded to a factor two if necessary, and down-sampled if too large to fit in OpenGl memory. - Visvis now works for any OpenGl version from OpenGl 1.1 (some features might not be supported for lower versions though). Regards, Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptmcg at austin.rr.com Wed Feb 10 08:37:22 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 10 Feb 2010 05:37:22 -0800 (PST) Subject: How to measure elapsed time under Windows? References: Message-ID: <87404349-5d3a-4396-aeff-60edc14a506a@f8g2000yqn.googlegroups.com> On Feb 10, 2:24?am, Dennis Lee Bieber wrote: > On Tue, 9 Feb 2010 21:45:38 +0000 (UTC), Grant Edwards > declaimed the following in > gmane.comp.python.general: > > > Doesn't work. ?datetime.datetime.now has granularity of > > 15-16ms. > > > Intervals much less that that often come back with a delta of > > 0. ?A delay of 20ms produces a delta of either 15-16ms or > > 31-32ms > > ? ? ? ? WinXP uses an ~15ms time quantum for task switching. Which defines > the step rate of the wall clock output... > > http://www.eggheadcafe.com/software/aspnet/35546579/the-quantum-was-n...http://www.eggheadcafe.com/software/aspnet/32823760/how-do-you-set-ti... > > http://www.lochan.org/2005/keith-cl/useful/win32time.html > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ Gabriel Genellina reports that time.clock() uses Windows' QueryPerformanceCounter() API, which has much higher resolution than the task switcher's 15ms. QueryPerformanceCounter's resolution is hardware-dependent; using the Win API, and a little test program, I get this value on my machine: Frequency is 3579545 ticks/sec Resolution is 0.279365114840015 microsecond/tick -- Paul From roy at panix.com Wed Feb 10 08:38:18 2010 From: roy at panix.com (Roy Smith) Date: Wed, 10 Feb 2010 08:38:18 -0500 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: In article , Tim Chase wrote: > Larry Hudson wrote: > > But a minor rearrangement is simpler, and IMHO clearer: > > > > if 'mystring' not in s: > > print 'not found' > > else: > > print 'foundit' > > print 'processing' > > I've always vacillated on whether that would better be written as > Larry does, or as > > if 'mystring' in s > print 'foundit' > print 'processing' > else: > print 'not found' > > removing the "not" from the condition. I admit I choose one over > the other based on some gut-feeling aesthetic that I can't really > nail down. I think one of my major influencing factors revolves > around the negative "not" portion having one or two lines and the > positive portion having a large block of code. If the > code-blocks are more equal in size, I tend to use "if > {positive}", but if the negative "not" section is only 1-2 lines, > I tend to do as Larry writes and make it harder to miss by using > "if {negative}". Otherwise the "if {positive}...else" can end up > sufficiently distant from the "if" that it's easy to miss. > > Any thoughts on how others make the choice? > > -tkc In general, I try to avoid negation, because it makes things harder to understand. When you write: if not foo: blah else: blah-blah the else clause is executed if "not foo is not true". That quickly gets confusing. As for the code blocks being so large that the else becomes distant from the condition, that smells like the two codeblocks want to be refactored into distinct functions: if foo: do_one_thing() else: do_something_else() It's not always practical, but my first reaction would be to try that and see if it works. From catonano at gmail.com Wed Feb 10 08:45:49 2010 From: catonano at gmail.com (catonano) Date: Wed, 10 Feb 2010 05:45:49 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: Vladimir, On Feb 3, 12:10?pm, Vladimir Ignatov wrote: > Hello, > > I am sitting here for quite some time, but usually keep silent ;-) I > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. I don't know CAD systems, but I want to share my comments about this. I self learned to program with Squeak Smalltalk at 17. Later, I worked with VisualAge for Java, that was a Smalltalk IDE applied to Java. Now, I can tell you that in Smalltalk IDEs the code is not written in files. It's stored in a thing called "image". You have these frames, in the first frame you have the classes, in the second frame you have the child classes and in the third frame you have the methods of the child class you selected. A bigger frame showed the code of the single method you had selected. You modified the method, hit ctrl-s and it was COMPILED and saved in the image. You had a frame in which you could interactively call your objects, some of them represented things that were "showable" on the monitor and you could see these things pop up as you instantiated them. Then, you had some specialized browsers in which you could search, for example, all the places a method was called in (a thing I have difficulties with, in python, today) VisualAge had its own management version system such that EVERY TIME I saved a method, it became a VERSION and there was a specialized browser for browsing the versions (the image tended to grow, that's it) while the regular browser defaulted on the last version and there was a tool for freezing a version as a milestone. Today, I tried to understand the twisted.web.client code and I found 3 methods I couldn't find by who were called. I asked on the mailing list and they suggested me where they were called and that the tool for such thing is "grep". So, you grep, you get a list of files, you open each one of them and keep scrolling and switching from one file to another... endlessly. Maybe I'm getting old, but I tend to get lost in the process. I can't believe the code editing situation today is in a such sorry state. Is this what you meant ? If it's this, then it's not experimental at all, it's been done already and been put apart. Crap won :-( You write: > Instead of current text-oriented IDEs, it > should be a database-centric well, it seems you agree with Alan Kay, (the Smalltalk inventor) when he wrote that programming is NOT glorified text editing. He called it "direct manipulation" every method was a live thing you could send messages to and the source code that implemented it was just an attribute of the method. So you could have had a World Of Warcraft like interface, to manipulate your methods. You know what I'm doing now ? I'm drawing the map of twisted.web.client on a paper with a pencil :-( Bye Catonano From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 08:51:19 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 14:51:19 +0100 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> <4b729eb2$0$18397$426a74cc@news.free.fr> Message-ID: <4b72b9c8$0$8274$426a74cc@news.free.fr> Klaus Neuner a ?crit : > On Feb 10, 12:55 pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> KlausNeunera ?crit : >> >> >> >>> All right, I admit that eval() is evil and should never be used. >> Can you tell the difference between your above statement and the following: > > As already pointed out in my second post (though perhaps not > explicitly enough), Or perhaps is it me that failed to re-read a bit more of the thread before answering - I obviously missed the irony (and made an a... of myself), sorry :-/ > All > I wanted to say is this: If there are no circumstances at all under > which eval() can reasonably be used, then it should not be part of > Python. As it is part of Python (and as Python is a carefully designed > language), there will most probably some situations in which one might > want to use it. Indeed. From duncan.booth at invalid.invalid Wed Feb 10 08:56:03 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Feb 2010 13:56:03 GMT Subject: Modifying Class Object References: Message-ID: "Alf P. Steinbach" wrote: >> In CPython objects once created remain in the same memory location >> (and their id is their address). Compare that to IronPython where the >> objects themselves can move around in memory so they have no fixed >> address. Try comparing the IronPython implementation to C pointers >> and you'll cause a lot of confusion. e.g. someone might think the >> id() value is in some way related to an address. > > Did you /read/ what you quoted? > > >> Ruby implements integers without using any pointers at all: there's >> nothing in the Python specification which prevents a Python >> implementation doing the same for small integers, in fact I believe >> it has been tried but wasn't found to improve performance. > > All theree of your points about Python are wrong; I don't know about > the Ruby point. Would you care to expand upon your claim that my three points about Python are wrong? Are you saying that CPyhton objects move around, or that IronPython objects are fixed to a single memory location or that their id is related to their address? Clue here: IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> id(x) 43 >>> y = 43 >>> id(y) 44 >>> z = "whatever" >>> id(z) 45 -- Duncan Booth http://kupuguy.blogspot.com From quindennis at grandecom.net Wed Feb 10 08:59:19 2010 From: quindennis at grandecom.net (Quin) Date: Wed, 10 Feb 2010 07:59:19 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: You know, Jack, that was the point of my original post: to determine why things weren't working. Do you still want to bet money that it is? I can screenshot you TD. "Jean-Michel Pichavant" wrote in message news:mailman.2288.1265799238.28905.python-list at python.org... > Quin wrote: >> Well, now you know! >> >> "Jean-Michel Pichavant" wrote in message >> news:mailman.2286.1265797348.28905.python-list at python.org... >>> Quin wrote: >>>> Thanks guys, I'm thinking it's a problem with IronPython. I'm >>>> switching to PyScripter and will test tomorrow. >>>> >>>> >>> I'm willing to bet money that it is not. If ironPython had a broken if >>> statement, don't you think we would have known, already ? >>> >>> There's a rule when test writing/testing code: >>> "if you think the compiler is wrong, then you are wrong twice." >>> >>> JM >> > > All I know is that you are using a python implementation that does not > support python 3. No wonder why your py3 code fails. > > Please do not top post. > > JM > > > IronPython > > * Stable Version is 2.0.3 (targeting Python 2.5) > * Developers Version is 2.6 Beta 3 (targeting Python 2.6) > From malkarouri at gmail.com Wed Feb 10 08:59:41 2010 From: malkarouri at gmail.com (Muhammad Alkarouri) Date: Wed, 10 Feb 2010 05:59:41 -0800 (PST) Subject: Function attributes Message-ID: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Hi everyone, What is the simplest way to access the attributes of a function from inside it, other than using its explicit name? In a function like f below: def f(*args): f.args = args print args is there any other way? I am guessing the next question will be: should I really care? It just feels like there should be a way, but I am not able to verbalise a valid one at the moment, sorry. Regards, Muhammad Alkarouri From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 09:16:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 14:16:46 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> Message-ID: <0382abea$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 09:13:22 +0100, Alf P. Steinbach wrote: >> You've >> dismissed at least one of my arguments with a simple hand-waving of, >> "That's invalid, cuz." > > That is not a quote of me. It is a lie. Alf, although your English in this forum has been excellent so far, I understand you are Norwegian, so it is possible that you aren't a native English speaker and possibly unaware that quotation marks are sometimes ambiguous in English. While it is true that quoted text is officially meant to indicate a direct quote, it is also commonly used in informal text to indicate a paraphrase. (There are other uses as well, but they don't concern us now.) Unfortunately, this means that in informal discussions like this it is sometimes difficult to distinguish a direct quote from a paraphrase, except by context. In context, as a native speaker, I can assure you that Stephen Hansen's use of quotation marks is a paraphrase and not meant to be read as a direct quote. As a paraphrase, it's not a *lie* -- it should be read as Stephen's *opinion* of your actions, not a direct quote. Stephen might, or might not, be *mistaken*, but it's unlikely he's actively lying. Arguing pedantically that you didn't write those exact words won't win you any friends or supporters. You can choose to defend yourself against a gross misrepresentation of what you actually said; or you can accept that it captures the spirit (but not the letter) of your words; or you can choose a middle position, and accept that even if it is not a 100% accurate representation of your statements, perhaps it is 90% accurate, or 10%, or 50%. The exact amount doesn't really matter, and will be subjective, and frankly I don't care. But whatever degree you choose to accept, it is obvious that a number of people are not just being annoyed by your behaviour, but they are annoyed enough to publicly chastise you for it. That includes Steve Holden, who is usually far more even-tempered than (e.g.) me. Without necessarily suggesting that you are 100% to blame for the antagonism, its unlikely that so many disparate individuals are all 100% mistaken. As you say, the public record is there for anyone who wishes to read the history. Believe me Alf, the fact that people are taking the time to try to argue with you instead of just kill-filing you is a compliment. -- Steven From waku at idi.ntnu.no Wed Feb 10 09:33:50 2010 From: waku at idi.ntnu.no (waku) Date: Wed, 10 Feb 2010 06:33:50 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> On Feb 9, 10:41?pm, Jonathan Gardner wrote: > On Feb 9, 1:51?am, waku wrote: > > > 'stupid', 'wrong', 'deficient', 'terrible', ... ?you're using strong > > words instead of concrete arguments, it might intimidate your > > opponents, but is hardly helpful in a fair discussion. > > In today's day and age, I don't know how a text editor which cannot do > simple indentation can be considered anything but "stupid", "wrong", > "deficient", and "terrible". There is simply no excuse for this kind > of behavior on the part of the text editor. i thought we were not discussing text editors, why should you insist so much on diverting attention from the issue of a programmer being *forced* to keep perfect indentation to the issue of an editor doing autoindent or the like. > > I mean, how long has vi had the auto indent feature? How many decades > has emacs supported the same? This isn't new technology, or difficult > technology to implement. It's not even non-standard anymore. Heck, far > more advanced features, such as syntax highlighting, are standard in > all text editors. wow! and then, back to the issue of enforced indentation in python? > Your problem is you're using something like Windows Notepad to edit > your code. thin ice! you haven't got the faintest idea of what i use to edit my code, do you. Windows Notepad is a terrible tool for writing anything, > let alone writing code. Why in the world would any programming > language adapt itself to the mental deficiencies of Windows Notepad? I > mean, if you were an artist, would you use MS Paint to do anything > serious? If you did, would you complain that the art world has a > problem because they don't accept your paintings? > > I strongly suggest you download one of the *hundreds* of free text > editors available for the Windows platform that give you the > indentation features you so sorely lack. I suggest ViM, though it has > a steep learning curve. listen to what people say before responding, and stop showing off. again, you haven't used a single reasonable argument here. vQ From __peter__ at web.de Wed Feb 10 09:35:57 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Feb 2010 15:35:57 +0100 Subject: New to Python References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Quin wrote: > You know, Jack, that was the point of my original post: to determine why > things weren't working. Do you still want to bet money that it is? I can > screenshot you TD. You haven't posted the complete script, and you haven't given a thorough description how you invoke that script. To help us find an explanation for your problem and a possible fix please make the script as small as you can while preserving its very strange behaviour, open a DOS window and invoke the Ironpython interpreter manually on the command line. Finally copy and paste the output and the complete script and post it here again. Peter From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 09:36:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 14:36:32 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: <0382b08c$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? In a function like f > below: > > def f(*args): > f.args = args > print args > > is there any other way? Not built-in. > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a valid > one at the moment, sorry. I completely agree with you. It is a wart that functions are only able to refer to themselves by name, because if the name changes, things break. Consider: old_f = f # save the old version of the function def f(x): return old_f(x+1) # make a new function and call it f This won't work correctly, because old_f still tries to refer to itself under the name "f", and things break very quickly. -- Steven From krister.svanlund at gmail.com Wed Feb 10 09:46:00 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Wed, 10 Feb 2010 15:46:00 +0100 Subject: Function attributes In-Reply-To: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: <2cf430a61002100646k557abc9dm73212357d2d3dad3@mail.gmail.com> On Wed, Feb 10, 2010 at 2:59 PM, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): > ? ?f.args = args > ? ?print args > > is there any other way? > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a > valid one at the moment, sorry. > > Regards, > > Muhammad Alkarouri > -- > http://mail.python.org/mailman/listinfo/python-list > This sounds like something you shouldn't be doing. You should probably use a class instead. (Sending again to get it on the list >_<) From klausneuner72 at googlemail.com Wed Feb 10 09:49:37 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Wed, 10 Feb 2010 06:49:37 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> <4b729eb2$0$18397$426a74cc@news.free.fr> <4b72b9c8$0$8274$426a74cc@news.free.fr> Message-ID: > Or perhaps is it me that failed to re-read a bit more of the thread > before answering - I obviously missed the irony (and made an a... of > myself), sorry :-/ There is nothing to be sorry about. I am grateful to all participants of this thread. I know a lot more about Python than before. From steve at holdenweb.com Wed Feb 10 09:51:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 09:51:11 -0500 Subject: Python and Ruby In-Reply-To: <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> Message-ID: waku wrote: > On Feb 9, 10:41 pm, Jonathan Gardner > wrote: >> On Feb 9, 1:51 am, waku wrote: >> >>> 'stupid', 'wrong', 'deficient', 'terrible', ... you're using strong >>> words instead of concrete arguments, it might intimidate your >>> opponents, but is hardly helpful in a fair discussion. >> In today's day and age, I don't know how a text editor which cannot do >> simple indentation can be considered anything but "stupid", "wrong", >> "deficient", and "terrible". There is simply no excuse for this kind >> of behavior on the part of the text editor. > > i thought we were not discussing text editors, why should you insist > so much on diverting attention from the issue of a programmer being > *forced* to keep perfect indentation to the issue of an editor doing > autoindent or the like. > It's as sensible to complain about people being "*forced* to keep perfect indentation" as it is to complain about people being *forced* to use braces to delimit code blocks. This is called "syntax", and it's a part of the language, so get over it - this aspect of Python has been present in the language since its inception, and it isn't going to change. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Wed Feb 10 09:54:37 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 15:54:37 +0100 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <4B72C8AD.2060203@sequans.com> Quin wrote: > You know, Jack, that was the point of my original post: to determine > why things weren't working. Do you still want to bet money that it > is? I can screenshot you TD. > Another flaming war starting... IronPython implements python 2.5 and you're still complaining about your py3 code not working. Try your code in a ruby shell, and tell the ruby community that their intepreter cannot even handle an if statement. Feel free to put my mail address in cc. So to be clear, IronPython can properly handle if statements. I'll bet all your money on that. Jack From visiblelight at gmail.com Wed Feb 10 09:59:54 2010 From: visiblelight at gmail.com (Vision) Date: Wed, 10 Feb 2010 06:59:54 -0800 (PST) Subject: looking for some libraries Message-ID: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> hi all, I am doing some stuffs with some software, which has similar layout like this: Editbox________1 Editbox________2 Editbox________3 _OK_ _______________ | output | | output | | output | | output | | output | -------------------------- What I need to do is to fill the edit boxes, then press the OK button, then I will get some output text below. This is tedious since I have lots of entries to deal with. So I am trying to write some scripts to handle this. And I wonder if there is any library available for me to simplify the process? Thanks! From jjposner at optimum.net Wed Feb 10 10:08:47 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 10:08:47 -0500 Subject: Function attributes In-Reply-To: <0382b08c$0$1277$c3e8da3@news.astraweb.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B72CBFF.9020500@optimum.net> On 2/10/2010 9:36 AM, Steven D'Aprano wrote: > On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > >> Hi everyone, >> >> What is the simplest way to access the attributes of a function from >> inside it, other than using its explicit name? In a function like f >> below: >> >> def f(*args): >> f.args = args >> print args >> >> is there any other way? > > Not built-in. > > >> I am guessing the next question will be: should I really care? It just >> feels like there should be a way, but I am not able to verbalise a valid >> one at the moment, sorry. > > I completely agree with you. It is a wart that functions are only able to > refer to themselves by name, because if the name changes, things break. > Consider: > > old_f = f # save the old version of the function > > def f(x): > return old_f(x+1) # make a new function and call it f > > This won't work correctly, because old_f still tries to refer to itself > under the name "f", and things break very quickly. They didn't break immediately for me -- what am I missing?: #------------------- def f(): return "old func" g = f print "name attr of f:", f.__name__ print "name attr of g:", g.__name__ def f(): return "new func" print "name attr of f:", f.__name__ print "name attr of g:", g.__name__ print "*** calling function currently named f:" print f() print "*** calling function currently named g:" print g() #------------------- program output (Python 2.6.4): name attr of f: f name attr of g: f name attr of f: f name attr of g: f *** calling function currently named f: new func *** calling function currently named g: old func -John From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 10:24:56 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 16:24:56 +0100 Subject: Function attributes In-Reply-To: <4B72CBFF.9020500@optimum.net> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> Message-ID: <4b72cfb9$0$30354$426a74cc@news.free.fr> John Posner a ?crit : > On 2/10/2010 9:36 AM, Steven D'Aprano wrote: >> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: >> (snip) >>> def f(*args): >>> f.args = args >>> print args >>> (snip) >> I completely agree with you. It is a wart that functions are only able to >> refer to themselves by name, because if the name changes, things break. >> Consider: >> >> old_f = f # save the old version of the function >> >> def f(x): >> return old_f(x+1) # make a new function and call it f >> >> This won't work correctly, because old_f still tries to refer to itself >> under the name "f", and things break very quickly. > > They didn't break immediately for me -- what am I missing?: The fact that in the OP's snippet, code inside f's body refers to f by its name. From skylarking11 at gmail.com Wed Feb 10 10:29:40 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 10 Feb 2010 07:29:40 -0800 (PST) Subject: Python v. Processing Message-ID: I am a light user of Python in a role as a systems administrator...I am new to the list, but have grown to really enjoy using Python to help in my job...Another interest I have ( but haven't fully explored ) is the idea of using programming as a creative outlet .. I have heard Processing: http://processing.org/ is a good language for these sort of endeavors --- I am interested in Processing, but would rather do similar creative work in Python (i know that is vague, but the projects on Processing.org are good examples of what I am intending to do ). I've tried learning different languages concurrently, and it is usually too much for me too handle.... Are there creative types using Python in the way Processing is being implemented? Just curious of their similarities and differences, and what Python's limitations maybe be in this arena ( if any ) . Thanks! From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 10:33:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 15:33:34 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> Message-ID: <0382bdeb$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote: >> This won't work correctly, because old_f still tries to refer to itself >> under the name "f", and things break very quickly. > > They didn't break immediately for me -- what am I missing?: The original function f doesn't try to refer to itself in any way. With no recursive call or access, it doesn't matter what f is named. See this example instead: >>> def f(x): ... if x < 0: ... print "original" ... return f(-x) ... else: ... return x+1 ... >>> f(2) 3 >>> f(-2) original 3 >>> >>> old_f = f >>> def f(x): ... if x > 0: ... return old_f(-x) ... else: ... return x ... >>> f(-1) -1 >>> f(1) original original original original original original [...] File "", line 3, in f File "", line 4, in f File "", line 3, in f RuntimeError: maximum recursion depth exceeded -- Steven From yakovenko87 at gmail.com Wed Feb 10 10:34:13 2010 From: yakovenko87 at gmail.com (=?UTF-8?B?0JrQuNGA0LjQu9C7?=) Date: Wed, 10 Feb 2010 07:34:13 -0800 (PST) Subject: not correct socket closing Message-ID: <13f582d6-dc41-48a3-9900-5ed95a42dcf0@a32g2000yqm.googlegroups.com> Hi all, I have got a small script for upload file on http server, and I need interrupt uploading if I get tired wait. I create socket: self.conn = httplib.HTTPConnection("192.168.0.195") #self.conn.debuglevel = 1 self.conn.request("POST", "/upload/", body, head) if self.conn.sock: self.conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)) and close it in other thread: if self.conn.sock: self.conn.close() Python notify me what socket have closed, but he continues to send data. As can I close it and stop sending of the data? Best Regards, Kirill. From apt.shansen at gmail.com Wed Feb 10 10:42:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 07:42:37 -0800 Subject: Modifying Class Object In-Reply-To: <0382abea$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002100742x2f8fbeefi5f33fbdd475fdc77@mail.gmail.com> On Wed, Feb 10, 2010 at 6:16 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > While it is true that quoted text is officially meant to indicate a > direct quote, it is also commonly used in informal text to indicate a > paraphrase. (There are other uses as well, but they don't concern us now.) > Hm. I hadn't considered that others may interpret my words in the context of other cultural punctuation rules; it seemed obvious to me that the phrases Alf declared a "lie" were an opinion, and indeed as Steven points out, my interpretation and paraphrasing of the original arguments. Apologies if you considered it a direct quote and thought I was attempting to assert you actually said what was in quote marks. The comments were simply my interpretation (accurate or inaccurate as that may be, it is my interpretation) of your remarks, and not a quotation of your remarks to be attributed to you. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 10 10:51:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 10:51:31 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: catonano wrote: [... much wishing for the "good old day" of SmallTalk ...] > Today, I tried to understand the twisted.web.client code and I found 3 > methods I couldn't find by who were called. > > I asked on the mailing list and they suggested me where they were > called and that the tool for such thing is "grep". > > So, you grep, you get a list of files, you open each one of them and > keep scrolling and switching from one file to another... endlessly. > Maybe I'm getting old, but I tend to get lost in the process. > Maybe you are getting old. Or maybe you didn't realise that the advice was given you so that it would be useful whether or not you were using an IDE. > I can't believe the code editing situation today is in a such sorry > state. > It isn't. There are many IDEs that will allow you to easily locate the calls of specific methods. > Is this what you meant ? > > If it's this, then it's not experimental at all, it's been done > already and been put apart. > > Crap won :-( > It seems you yearn for the days of the SmallTalk image. Unfortunately this didn't allow for conveniences like using external data stored in files whose contents persisted and which could be transferred between different machines. I would never call SmallTalk "crap": it was a ground-breaking system almost 40 yers ago. But the environment suffered from many limitations of which you appear to be entirely unaware. > You write: > >> Instead of current text-oriented IDEs, it >> should be a database-centric > > well, it seems you agree with Alan Kay, (the Smalltalk inventor) when > he wrote that programming is NOT glorified text editing. > > He called it "direct manipulation" every method was a live thing you > could send messages to and the source code that implemented it was > just an attribute of the method. > This aspect of SmallTalk was one of the things that made software engineering rather difficult. Everything could be changed on the fly. > So you could have had a World Of Warcraft like interface, to > manipulate your methods. > > You know what I'm doing now ? I'm drawing the map of > twisted.web.client on a paper with a pencil :-( > Well why don't you get yourself a sensible tool like Wing IDE or Komodo? They at least will let you solve the problem you currently face without having to poke around in the innards of a running virtual machine the way we used to in SmallTalk. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From franke.rob at googlemail.com Wed Feb 10 10:54:50 2010 From: franke.rob at googlemail.com (Robert Franke) Date: Wed, 10 Feb 2010 16:54:50 +0100 Subject: Python v. Processing In-Reply-To: References: Message-ID: Hi Sky, there is a project called pyprocessing (http://code.google.com/p/pyprocessing/) that aims to create a similar environment like processing in python. I am not sure though how advanced this is. Cheers, Robert On Wed, Feb 10, 2010 at 4:29 PM, Sky Larking wrote: > I am a light user of Python in a role as a systems administrator...I > am new to the list, but have grown to really enjoy using Python to > help in my job...Another interest I have ( but haven't fully > explored ) ?is the idea of using programming as a creative outlet .. I > have heard Processing: http://processing.org/ is a good language for > these sort of endeavors --- I am interested in Processing, but would > rather do similar creative work in ?Python (i know that is vague, but > the projects on Processing.org are good examples of what I am > intending to do ). I've tried learning different languages > concurrently, and it is usually too much for me too handle.... Are > there creative types using Python in the way Processing is being > implemented? Just curious of their similarities and differences, and > what Python's limitations maybe be in this arena ( if any ) . > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > From apt.shansen at gmail.com Wed Feb 10 10:56:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 07:56:37 -0800 Subject: Function attributes In-Reply-To: <0382b08c$0$1277$c3e8da3@news.astraweb.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > > What is the simplest way to access the attributes of a function from > > inside it, other than using its explicit name? In a function like f > > Not built-in. > > > I am guessing the next question will be: should I really care? It just > > feels like there should be a way, but I am not able to verbalise a valid > > one at the moment, sorry. > > I completely agree with you. It is a wart that functions are only able to > refer to themselves by name, because if the name changes, things break. > I agree its slightly... in-elegant, or sub-optimal, but I'm not sure I want to call it a *wart*. If one calls it a wart, there might be inspiration to fix it. And this sounds like a precursor to making "self" non-explicit, and I *really* like my explicit self. :) Then again, I have been slightly bruised by this sub-optimal situation before. I tried to do a function using a frame hack to get the information easily, but failed. My long years of avoiding frame hacks like the plague have left me deficient. :( --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Feb 10 11:02:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 16:02:54 +0000 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: <4B72D8AE.3000503@mrabarnett.plus.com> Olof Bjarnason wrote: > 2010/2/10 Peter Otten <__peter__ at web.de>: >> python at bdurham.com wrote: >> >>> Does Python provide a way to format a string according to a >>> 'picture' format? >>> >>> For example, if I have a string '123456789' and want it formatted >>> like '(123)-45-(678)[9]', is there a module or function that will >>> allow me to do this or do I need to code this type of >>> transformation myself? >> A basic implementation without regular expressions: >> >>>>> def picture(s, pic, placeholder="@"): >> ... parts = pic.split(placeholder) >> ... result = [None]*(len(parts)+len(s)) >> ... result[::2] = parts >> ... result[1::2] = s >> ... return "".join(result) >> ... >>>>> picture("123456789", "(@@@)-@@-(@@@)[@]") >> '(123)-45-(678)[9]' >> >> Peter >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Inspired by your answer here's another version: > >>>> def picture(s, pic): > ... if len(s)==0: return pic > ... if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) > ... return pic[0]+picture(s, pic[1:]) > ... >>>> picture("123456789", "(###)-##-(###)[#]") > '(123)-45-(678)[9]' > Here's a version without recursion: >>> def picture(s, pic): ... pic = pic.replace("%", "%%").replace("#", "%s") ... return pic % tuple(s) ... >>> picture("123456789", "(###)-##-(###)[#]") '(123)-45-(678)[9]' From apt.shansen at gmail.com Wed Feb 10 11:06:25 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 08:06:25 -0800 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: <7a9c25c21002100806m66bc38f6mc2242c381be5c7ee@mail.gmail.com> On Wed, Feb 10, 2010 at 1:45 AM, Peter Otten <__peter__ at web.de> wrote: > A basic implementation without regular expressions: > > >>> def picture(s, pic, placeholder="@"): > ... parts = pic.split(placeholder) > ... result = [None]*(len(parts)+len(s)) > ... result[::2] = parts > ... result[1::2] = s > ... return "".join(result) > ... > >>> > >>> picture("123456789", "(@@@)-@@-(@@@)[@]") > '(123)-45-(678)[9]' > Huh. This is the best version of those posted, I think (especially including mine! My jumping to regex is worthy of shame, sh ame). It took a little bit to figure out what was really going on here, but its a single-pass through to do it without recursion or building a bunch of intermediate strings that are concatenated and dropped away. Its clever, and I don't mean that in the bad way, because -all- the solutions are pretty clever in the sneaky-tricky-neat way. But this is clever-cool. Just slightly dark-voodoo-incantation-esque. Slightly! --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Feb 10 11:10:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Feb 2010 10:10:23 -0600 Subject: Personal criticisms and logical fallacies In-Reply-To: <4B725AF0.9030803@gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> <20100210015132.3808f0d5.darcy@druid.net> <4B725AF0.9030803@gmail.com> Message-ID: On 2010-02-10 01:06 AM, Steven Howe wrote: > Really, is this a relevant topic on a program mail list? Yes. Meta-discussions about how we discuss programming productively are also on-topic. -- 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 invalid at invalid.invalid Wed Feb 10 11:15:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 16:15:22 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Gabriel Genellina wrote: > En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards > escribi?: > >> What's the correct way to measure small periods of elapsed >> time. I've always used time.clock() in the past: >> >> However on multi-processor machines that doesn't work. >> Sometimes I get negative values for delta. According to >> google, this is due to a bug in Windows that causes the value >> of time.clock() to be different depending on which core in a >> multi-core CPU you happen to be on. [insert appropriate >> MS-bashing here] > > I'm not sure you can blame MS of this issue; anyway, this > patch should fix the problem: > http://support.microsoft.com/?id=896256 I'm curious why it wouldn't be Microsoft's fault, because A) Everything is Microsoft's fault. ;) B) If a patch to MS Windows fixes the problem, how is it not a problem in MS Windows? >> Is there a way to lock the python process to a single core so >> that time.clock() works right? > > Interactively, from the Task Manager: > http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_assign_process.mspx Thanks. That looks a bit easier than disabling the second core (which is what I ended up doing). > In code, using SetProcessAffinityMask and related functions: > http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx With help from google and some old mailing list posting I might even try that. -- Grant Edwards grante Yow! It's a lot of fun at being alive ... I wonder if visi.com my bed is made?!? From rantingrick at gmail.com Wed Feb 10 12:15:07 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Feb 2010 09:15:07 -0800 (PST) Subject: looking for some libraries References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> Message-ID: <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> On Feb 10, 8:59?am, Vision wrote: > hi all, > I am doing some stuffs with some software, which has similar layout > like this: > Editbox________1 > Editbox________2 > Editbox________3 > ? ? ? ?_OK_ > _______________ > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > -------------------------- > What I need to do is to fill the edit boxes, then press the OK button, > then I will get some output text below. > This is tedious since I have lots of entries to deal with. > So I am trying to write some scripts to handle this. And I wonder if > there is any library available for me to simplify the process? > Thanks! Well a GUI kit comes to mind. And since you did not mention a preference (or much really) i would suggest Tkinter in the stdlib as a starting point. Here is a big hint! #-- start code --# import Tkinter as tk def fooit(): lister.insert(END, entry1.get()) app = tk.Tk() label1 = tk.Label(app, text='label-1').grid(row=0, column=0) entry1 = tk.Entry(app).grid(row=0, column=1) tk.Button(app, text='OK', command=fooit).grid(row=1, column=0, columnspan=2) lister = tk.Listbox(app, width=20, height=10) lister.grid(row=2, column=0, columnspan=2) app.mainloop() #-- end code --# i would wrap the label and entry up into a class myself but milage may vary. From rantingrick at gmail.com Wed Feb 10 12:20:34 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Feb 2010 09:20:34 -0800 (PST) Subject: looking for some libraries References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> Message-ID: <72f1941d-92bd-4063-aa14-d5bb3e0b5107@j31g2000yqa.googlegroups.com> @Vision Its nice to start with examples that don't crash, so try this instead ;D import Tkinter as tk def fooit(): lister.insert('end', entry1.get()) app = tk.Tk() label1 = tk.Label(app, text='label-1').grid(row=0, column=0) entry1 = tk.Entry(app) entry1.grid(row=0, column=1) tk.Button(app, text='OK', command=fooit).grid(row=1, column=0, columnspan=2) -- there are no redo's in Usenet!! lister = tk.Listbox(app, width=20, height=10) lister.grid(row=2, column=0, columnspan=2) app.mainloop() From python at mrabarnett.plus.com Wed Feb 10 12:23:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 17:23:36 +0000 Subject: Function attributes In-Reply-To: <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> Message-ID: <4B72EB98.1000204@mrabarnett.plus.com> Stephen Hansen wrote: > On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano > > wrote: > > On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > > What is the simplest way to access the attributes of a function from > > inside it, other than using its explicit name? In a function like f > > Not built-in. > > > I am guessing the next question will be: should I really care? It > just > > feels like there should be a way, but I am not able to verbalise > a valid > > one at the moment, sorry. > > I completely agree with you. It is a wart that functions are only > able to > refer to themselves by name, because if the name changes, things break. > > > I agree its slightly... in-elegant, or sub-optimal, but I'm not sure I > want to call it a *wart*. If one calls it a wart, there might be > inspiration to fix it. > > And this sounds like a precursor to making "self" non-explicit, and I > *really* like my explicit self. :) > > Then again, I have been slightly bruised by this sub-optimal situation > before. > > I tried to do a function using a frame hack to get the information > easily, but failed. My long years of avoiding frame hacks like the > plague have left me deficient. :( > Does this mean that Python needs, say, __function__ (and perhaps also __module__)? From python at bdurham.com Wed Feb 10 12:23:38 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 10 Feb 2010 12:23:38 -0500 Subject: Creating formatted output using picture strings In-Reply-To: <1265822561.1942.1359302945@webmail.messagingengine.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <1265822618.2095.1359305405@webmail.messagingengine.com> Original poster here. Thank you all for your ideas. I certainly learned some great techniques by studying everyone's solutions!! I was thinking that there was a built-in function for this common(?) use case which is why I shied away from writing my own in the first place ... hoping to not-reinvent the wheel, etc. Here's the solution I came up with myself. Its not as sexy as some of the posted solutions, but it does have the advantage of not failing when the number of input chars <> the number of placeholders in the pic string. I think it handles the edge cases pretty elegantly unless I'm too close to the details to miss the obvious. Any feedback on what follows would be appreciated. # format s using a picture string # stops processing when runs out of chars in s or pic string # example: picture("123456789", "(@@@)-@@-(@@@)[@]") def picture( s, pic, placeholder="@" ): s = list( s ) output = [] for sym in pic: if sym <> placeholder: output.append( sym ) elif len( s ): output.append( s.pop( 0 ) ) else: break return ''.join( output ) # test cases print picture("123456789", "(@@@)-@@-(@@@)[@]") print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") print picture("1234", "(@@@)-@@-(@@@)[@]") print picture("123456789", "(@@@)-@@-(@@@)") print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") Regards, Malcolm From cdberry at gmail.com Wed Feb 10 12:38:33 2010 From: cdberry at gmail.com (Craig Berry) Date: Wed, 10 Feb 2010 09:38:33 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> Message-ID: <8dee73061002100938l39f4b609k94088afefccecdd0@mail.gmail.com> I'm happy to report that FreeGLUT solved my problem. I obtained the Windows prepackaged binary distribution, pulled out freeglut.dll, renamed it to glut32.dll, and replaced the existing glut32.dll in the PyOpenGL installation directory tree with the new version. Mousewheel events are now reported, and everything else seems to be working as expected. Thanks for your help! -- Craig Berry - http://www.cine.net/~cberry/ "Lots of things in the universe don?t solve any problems, and nevertheless exist." -- Sean Carroll From jeanmichel at sequans.com Wed Feb 10 12:55:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 18:55:00 +0100 Subject: looking for some libraries In-Reply-To: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> Message-ID: <4B72F2F4.4020607@sequans.com> Vision wrote: > hi all, > I am doing some stuffs with some software, which has similar layout > like this: > Editbox________1 > Editbox________2 > Editbox________3 > _OK_ > _______________ > | output | > | output | > | output | > | output | > | output | > -------------------------- > What I need to do is to fill the edit boxes, then press the OK button, > then I will get some output text below. > This is tedious since I have lots of entries to deal with. > So I am trying to write some scripts to handle this. And I wonder if > there is any library available for me to simplify the process? > Thanks! > Someone posted this link few weeks ago: http://www.sikuli.org/ It supports only mac & windows though. You can also have a look at http://pywinauto.openqa.org/ JM From python.list at tim.thechases.com Wed Feb 10 13:04:14 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 12:04:14 -0600 Subject: Creating formatted output using picture strings In-Reply-To: <1265822618.2095.1359305405@webmail.messagingengine.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265822618.2095.1359305405@webmail.messagingengine.com> Message-ID: <4B72F51E.1080609@tim.thechases.com> python at bdurham.com wrote: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! Thanks for the positive feedback -- it's something most folks like to hear when they try to assist and such thanks appears too rarely on the list. > Here's the solution I came up with myself. Its not as sexy as some of > the posted solutions, but it does have the advantage of not failing when > the number of input chars <> the number of placeholders in the pic > string. > > Any feedback on what follows would be appreciated. [snip] > # test cases > print picture("123456789", "(@@@)-@@-(@@@)[@]") > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") > print picture("1234", "(@@@)-@@-(@@@)[@]") > print picture("123456789", "(@@@)-@@-(@@@)") > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") > You don't give the expected output for these test cases, so it's hard to tell whether you want to pad-left or pad-right. Riffing on MRAB's lovely solution, you can do something like def picture( s, pic, placeholder='@', padding=' ', pad_left=True ): assert placeholder != '%' s = str(s) expected = pic.count(placeholder) if len(s) > expected: s = s[:expected] if len(s) < expected: if pad_left: s = s.rjust(expected, padding) else: s = s.ljust(expected, padding) return pic.replace( '%', '%%').replace( placeholder, '%s') % tuple(s) print picture("123456789", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789ABC", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("1234", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]", pad_left=False) That way you can specify your placeholder, your padding character, and whether you want it to pad to the left or right. -tkc From jjposner at optimum.net Wed Feb 10 13:15:27 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 13:15:27 -0500 Subject: Function attributes In-Reply-To: <4b72cfb9$0$30354$426a74cc@news.free.fr> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <4b72cfb9$0$30354$426a74cc@news.free.fr> Message-ID: <4b72f7a5$0$5017$607ed4bc@cv.net> On 2/10/2010 10:24 AM, Bruno Desthuilliers wrote: >> >> They didn't break immediately for me -- what am I missing?: > > The fact that in the OP's snippet, code inside f's body refers to f by > its name. Of course! Tx. -John From arnodel at googlemail.com Wed Feb 10 13:21:35 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 18:21:35 +0000 Subject: Creating formatted output using picture strings References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: python at bdurham.com writes: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! > > I was thinking that there was a built-in function for this common(?) use > case which is why I shied away from writing my own in the first place > ... hoping to not-reinvent the wheel, etc. > > Here's the solution I came up with myself. Its not as sexy as some of > the posted solutions, but it does have the advantage of not failing when > the number of input chars <> the number of placeholders in the pic > string. I think it handles the edge cases pretty elegantly unless I'm > too close to the details to miss the obvious. > > Any feedback on what follows would be appreciated. > > # format s using a picture string > # stops processing when runs out of chars in s or pic string > # example: picture("123456789", "(@@@)-@@-(@@@)[@]") > def picture( s, pic, placeholder="@" ): > s = list( s ) > output = [] > for sym in pic: > if sym <> placeholder: > output.append( sym ) > elif len( s ): > output.append( s.pop( 0 ) ) > else: > break > return ''.join( output ) > > # test cases > print picture("123456789", "(@@@)-@@-(@@@)[@]") > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") > print picture("1234", "(@@@)-@@-(@@@)[@]") > print picture("123456789", "(@@@)-@@-(@@@)") > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") > > Regards, > Malcolm def picture(s, pic, placeholder='@'): nextchar=iter(s).next return ''.join(nextchar() if i == placeholder else i for i in pic) passes all your test cases I think (I can't be sure because you didn't post the expected output). The trick is that when nextchar reaches the end of the string 's', it raises a StopIteration which is caught by the generator expression. -- Arnaud From python at bdurham.com Wed Feb 10 13:30:21 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 10 Feb 2010 13:30:21 -0500 Subject: Creating formatted output using picture strings In-Reply-To: <4B72F51E.1080609@tim.thechases.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265822618.2095.1359305405@webmail.messagingengine.com> <4B72F51E.1080609@tim.thechases.com> Message-ID: <1265826621.13859.1359315979@webmail.messagingengine.com> Hi Tim, Thank you very much for your update to MRAB's creative solution. > You don't give the expected output for these test cases, so > it's hard to tell whether you want to pad-left or pad-right. To be honest, I wasn't sure myself :) My original post was the result of doing some simple formatting where my input strings were 'guaranteed' to be a consistent length. I hadn't started to think about the specs for a more universal picture function until I started to study and test the solutions proposed by others. It bears repeating again - what a clever mix of techniques - I really learned a lot more than I was expecting! I appreciate you taking the extra time to analyze the problem and refine it further. Cheers, Malcolm Riffing on MRAB's lovely solution, you can do something like def picture( s, pic, placeholder='@', padding=' ', pad_left=True ): assert placeholder != '%' s = str(s) expected = pic.count(placeholder) if len(s) > expected: s = s[:expected] if len(s) < expected: if pad_left: s = s.rjust(expected, padding) else: s = s.ljust(expected, padding) return pic.replace( '%', '%%').replace( placeholder, '%s') % tuple(s) print picture("123456789", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789ABC", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("1234", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]", pad_left=False) That way you can specify your placeholder, your padding character, and whether you want it to pad to the left or right. From usenot at geekmail.INVALID Wed Feb 10 13:30:22 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 10 Feb 2010 19:30:22 +0100 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> Message-ID: <20100210193022.5067e3e3@geekmail.INVALID> On Wed, 10 Feb 2010 09:51:11 -0500 Steve Holden wrote: > [snip] > It's as sensible to complain about people being "*forced* to keep > perfect indentation" as it is to complain about people being *forced* > to use braces to delimit code blocks. > > This is called "syntax", and it's a part of the language, so get over > it - this aspect of Python has been present in the language since its > inception, and it isn't going to change. > Amen. Now everybody do a quick from __future__ import braces and get back to work. /W -- INVALID? DE! From arnodel at googlemail.com Wed Feb 10 13:31:23 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 18:31:23 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <0382bdeb$0$1277$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote: > >>> This won't work correctly, because old_f still tries to refer to itself >>> under the name "f", and things break very quickly. >> >> They didn't break immediately for me -- what am I missing?: > > The original function f doesn't try to refer to itself in any way. With > no recursive call or access, it doesn't matter what f is named. > > See this example instead: > > >>>> def f(x): > ... if x < 0: > ... print "original" > ... return f(-x) > ... else: > ... return x+1 > ... >>>> f(2) > 3 >>>> f(-2) > original > 3 >>>> >>>> old_f = f >>>> def f(x): > ... if x > 0: > ... return old_f(-x) > ... else: > ... return x > ... >>>> f(-1) > -1 >>>> f(1) > original > original > original > original > original > original > [...] > File "", line 3, in f > File "", line 4, in f > File "", line 3, in f > RuntimeError: maximum recursion depth exceeded It's not ideal, but you can use a decorator like this to solve this problem: def bindfunction(f): def bound_f(*args, **kwargs): return f(bound_f, *args, **kwargs) bound_f.__name__ = f.__name__ return bound_f >>> @bindfunction ... def factorial(this_function, n): ... if n > 0: ... return n * this_function(n - 1) ... else: ... return 1 ... >>> factorial(15) 1307674368000L >>> fac = factorial >>> fac(15) 1307674368000L >>> factorial = 'foobar' >>> fac(15) 1307674368000L -- Arnaud From gherron at islandtraining.com Wed Feb 10 13:33:24 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 10 Feb 2010 10:33:24 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002100938l39f4b609k94088afefccecdd0@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> <8dee73061002100938l39f4b609k94088afefccecdd0@mail.gmail.com> Message-ID: <4B72FBF4.7060501@islandtraining.com> Craig Berry wrote: > I'm happy to report that FreeGLUT solved my problem. I obtained the > Windows prepackaged binary distribution, pulled out freeglut.dll, > renamed it to glut32.dll, and replaced the existing glut32.dll in the > PyOpenGL installation directory tree with the new version. Mousewheel > events are now reported, and everything else seems to be working as > expected. Thanks for your help! > > :-) Gary Herron From python at bdurham.com Wed Feb 10 13:36:34 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 10 Feb 2010 13:36:34 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <1265826994.14794.1359317783@webmail.messagingengine.com> Arnaud, Very cool!! Just when I thought the problem couldn't be made simpler ... WOW!!! Again, a big thank you to everyone who posted solutions!!! I'm humbled at how clever and different everyone's techniques have been. I have to say, I learned much more than I thought I needed to learn :) Thanks again! Malcolm ----- Original message ----- From: "Arnaud Delobelle" To: python-list at python.org Date: Wed, 10 Feb 2010 18:21:35 +0000 Subject: Re: Creating formatted output using picture strings python at bdurham.com writes: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! > > I was thinking that there was a built-in function for this common(?) use > case which is why I shied away from writing my own in the first place > ... hoping to not-reinvent the wheel, etc. > > Here's the solution I came up with myself. Its not as sexy as some of > the posted solutions, but it does have the advantage of not failing when > the number of input chars <> the number of placeholders in the pic > string. I think it handles the edge cases pretty elegantly unless I'm > too close to the details to miss the obvious. > > Any feedback on what follows would be appreciated. > > # format s using a picture string > # stops processing when runs out of chars in s or pic string > # example: picture("123456789", "(@@@)-@@-(@@@)[@]") > def picture( s, pic, placeholder="@" ): > s = list( s ) > output = [] > for sym in pic: > if sym <> placeholder: > output.append( sym ) > elif len( s ): > output.append( s.pop( 0 ) ) > else: > break > return ''.join( output ) > > # test cases > print picture("123456789", "(@@@)-@@-(@@@)[@]") > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") > print picture("1234", "(@@@)-@@-(@@@)[@]") > print picture("123456789", "(@@@)-@@-(@@@)") > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") > > Regards, > Malcolm def picture(s, pic, placeholder='@'): nextchar=iter(s).next return ''.join(nextchar() if i == placeholder else i for i in pic) passes all your test cases I think (I can't be sure because you didn't post the expected output). The trick is that when nextchar reaches the end of the string 's', it raises a StopIteration which is caught by the generator expression. -- Arnaud From ethan at stoneleaf.us Wed Feb 10 13:38:58 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 10 Feb 2010 10:38:58 -0800 Subject: Modifying Class Object In-Reply-To: <0382abea$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B72FD42.8010203@stoneleaf.us> Steven D'Aprano wrote: > > Believe me Alf, the fact that people are taking the time to try to argue > with you instead of just kill-filing you is a compliment. It's a compliment I am not paying, although I am grateful to those who are attempting to teach him. At the rate it's going, though, I don't see myself buying any book he produces. Besides the arrogant attitude, he is wrong on so many things about Python it is truly stunning. He seems to have confidence born of ignorance... a scary sight to see. In the spirit of being helpful and not just being a jerk myself: Alf, Using smileys after declaring somebody is mistaken/wrong/etc makes you look bad. Not attempting to learn the language makes you look like an arrogant idiot (case in point: passing-by-object). Accusing anyone and everyone that criticizes you of making ad hominem (sp?) attacks makes you look like a whiner. After all is said and done - if you had a truly good grasp of Python, I might buy your book even if you still had -- ummm -- a less than winning presence on the mailing list; but right now your understanding is not worth paying for. Hoping-this-helps-but-not-really-expecting-it-to-ly yours, ~Ethan~ From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 13:58:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 18:58:02 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> Message-ID: <0382edd6$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 17:23:36 +0000, MRAB wrote: > Stephen Hansen wrote: >> On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano >> > > wrote: >> >> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: >> > What is the simplest way to access the attributes of a function >> > from inside it, other than using its explicit name? In a >> > function like f >> >> Not built-in. [...] > Does this mean that Python needs, say, __function__ (and perhaps also > __module__)? Python already has __module__, except that it is spelled: import __main__ As for __function__, perhaps, but a solution I would be satisfied with would be to make it optional. Most functions are not recursive, and do not attach attributes to themselves. For the few that do need to refer to themselves, it would be sufficient to call a decorator to get the behaviour needed. I thought I had come up with such a thing, once before, but I can't find it now :( -- Steven From donn.ingle at gmail.com Wed Feb 10 14:00:57 2010 From: donn.ingle at gmail.com (donn) Date: Wed, 10 Feb 2010 21:00:57 +0200 Subject: Creating formatted output using picture strings In-Reply-To: <1265826994.14794.1359317783@webmail.messagingengine.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265826994.14794.1359317783@webmail.messagingengine.com> Message-ID: <4B730269.70809@gmail.com> On 10/02/2010 20:36, python at bdurham.com wrote: > def picture(s, pic, placeholder='@'): > nextchar=iter(s).next > return ''.join(nextchar() if i == placeholder else i for i in pic) Hell's teeth - even I understood that! Amazing solution. \d -- Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 14:04:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 19:04:58 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <0382bdeb$0$1277$c3e8da3@news.astraweb.com> Message-ID: <0382ef76$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 18:31:23 +0000, Arnaud Delobelle wrote: > It's not ideal, but you can use a decorator like this to solve this > problem: > > def bindfunction(f): > def bound_f(*args, **kwargs): > return f(bound_f, *args, **kwargs) > bound_f.__name__ = f.__name__ > return bound_f Ah, very nice. Perhaps it's better to use functools.wraps? import functools def bindfunction(f): @functools.wraps(f) def bound_f(*args, **kwargs): return f(bound_f, *args, **kwargs) return bound_f -- Steven From no.email at please.post Wed Feb 10 14:09:46 2010 From: no.email at please.post (kj) Date: Wed, 10 Feb 2010 19:09:46 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia Message-ID: Some people have mathphobia. I'm developing a wicked case of Unicodephobia. I have read a *ton* of stuff on Unicode. It doesn't even seem all that hard. Or so I think. Then I start writing code, and WHAM: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) (There, see? My Unicodephobia just went up a notch.) Here's the thing: I don't even know how to *begin* debugging errors like this. This is where I could use some help. In the past I've gone for method of choice of the clueless: "programming by trial-and-error", try random crap until something "works." And if that "strategy" fails, I come begging for help to c.l.p. And thanks for the very effective pointers for getting rid of the errors. But afterwards I remain as clueless as ever... It's the old "give a man a fish" vs. "teach a man to fish" story. I need a systematic approach to troubleshooting and debugging these Unicode errors. I don't know what. Some tools maybe. Some useful modules or builtin commands. A diagnostic flowchart? I don't think that any more RTFM on Unicode is going to help (I've done it in spades), but if there's a particularly good write-up on Unicode debugging, please let me know. Any suggestions would be much appreciated. FWIW, I'm using Python 2.6. The example above happens to come from a script that extracts data from HTML files, which are all in English, but they are a daily occurrence when I write code to process non-English text. The script uses Beautiful Soup. I won't post a lot of code because, as I said, what I'm after is not so much a way around this specific error as much as the tools and techniques to troubleshoot it and fix it on my own. But to ground the problem a bit I'll say that the exception above happens during the execution of a statement of the form: x = '%s %s' % (y, z) Also, I found that, with the exact same values y and z as above, all of the following statements work perfectly fine: x = '%s' % y x = '%s' % z print y print z print y, z TIA! ~K From jgardner at jonathangardner.net Wed Feb 10 14:22:44 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 10 Feb 2010 11:22:44 -0800 (PST) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> On Feb 10, 11:09?am, kj wrote: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) > You'll have to understand some terminology first. "codec" is a description of how to encode and decode unicode data to a stream of bytes. "decode" means you are taking a series of bytes and converting it to unicode. "encode" is the opposite---take a unicode string and convert it to a stream of bytes. "ascii" is a codec that can only describe 0-127 with bytes 0-127. "utf-8", "utf-16", etc... are other codecs. There's a lot of them. Only some of them (ie, utf-8, utf-16) can encode all unicode. Most (ie, ascii) can only do a subset of unicode. In this case, you've fed a stream of bytes with 128 as one of the bytes to the decoder. Since the decoder thinks it's working with ascii, it doesn't know what to do with 128. There's a number of ways to fix this: (1) Feed it unicode instead, so it doesn't try to decode it. (2) Tell it what encoding you are using, because it's obviously not ascii. > > FWIW, I'm using Python 2.6. ?The example above happens to come from > a script that extracts data from HTML files, which are all in > English, but they are a daily occurrence when I write code to > process non-English text. ?The script uses Beautiful Soup. ?I won't > post a lot of code because, as I said, what I'm after is not so > much a way around this specific error as much as the tools and > techniques to troubleshoot it and fix it on my own. ?But to ground > the problem a bit I'll say that the exception above happens during > the execution of a statement of the form: > > ? x = '%s %s' % (y, z) > > Also, I found that, with the exact same values y and z as above, > all of the following statements work perfectly fine: > > ? x = '%s' % y > ? x = '%s' % z > ? print y > ? print z > ? print y, z > What are y and z? Are they unicode or strings? What are their values? It sounds like someone, probably beautiful soup, is trying to turn your strings into unicode. A full stacktrace would be useful to see who did what where. From duncan.booth at invalid.invalid Wed Feb 10 14:56:20 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Feb 2010 19:56:20 GMT Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: kj wrote: > But to ground > the problem a bit I'll say that the exception above happens during > the execution of a statement of the form: > > x = '%s %s' % (y, z) > > Also, I found that, with the exact same values y and z as above, > all of the following statements work perfectly fine: > > x = '%s' % y > x = '%s' % z > print y > print z > print y, z > One of y or z is unicode, the other is str. The statement that goes wrong is combining the unicode string with the other one so the result has to be unicode. That means whichever of y or z is str is being decoded to unicode is being decoded with the default of 'ascii'. When you format them separately one assignment to x gives a unicode result, the other gives str. When you print them you are encoding the unicode value to ascii and that isn't giving a problem. 1. Print the repr of each value so you can see which is which. 2. Explicitly decode the str to unicode using whatever encoding is correct (possibly utf-8) when formatting. 3. Explicitly encode back to str when printing using the encoding of your output device. 4. Know what types you are using: never mix str and unicode without being explicit. 5. When you post to this newsgroup include the full traceback, not just the error message. From python at mrabarnett.plus.com Wed Feb 10 14:56:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 19:56:25 +0000 Subject: Creating formatted output using picture strings In-Reply-To: <4B72F51E.1080609@tim.thechases.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265822618.2095.1359305405@webmail.messagingengine.com> <4B72F51E.1080609@tim.thechases.com> Message-ID: <4B730F69.8090205@mrabarnett.plus.com> Tim Chase wrote: > python at bdurham.com wrote: >> Original poster here. >> >> Thank you all for your ideas. I certainly learned some great techniques >> by studying everyone's solutions!! > > Thanks for the positive feedback -- it's something most folks like to > hear when they try to assist and such thanks appears too rarely on the > list. > >> Here's the solution I came up with myself. Its not as sexy as some of >> the posted solutions, but it does have the advantage of not failing when >> the number of input chars <> the number of placeholders in the pic >> string. > > >> Any feedback on what follows would be appreciated. > [snip] >> # test cases >> print picture("123456789", "(@@@)-@@-(@@@)[@]") >> print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") >> print picture("1234", "(@@@)-@@-(@@@)[@]") >> print picture("123456789", "(@@@)-@@-(@@@)") >> print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") >> > > You don't give the expected output for these test cases, so it's hard to > tell whether you want to pad-left or pad-right. > > Riffing on MRAB's lovely solution, you can do something like > > def picture( > s, pic, > placeholder='@', > padding=' ', > pad_left=True > ): > assert placeholder != '%' > s = str(s) > expected = pic.count(placeholder) > if len(s) > expected: > s = s[:expected] > if len(s) < expected: > if pad_left: > s = s.rjust(expected, padding) > else: > s = s.ljust(expected, padding) > return pic.replace( > '%', '%%').replace( > placeholder, '%s') % tuple(s) > > print picture("123456789", "(@@@)-@@-(@@@)[@]", pad_left=False) > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]", pad_left=False) > print picture("1234", "(@@@)-@@-(@@@)[@]", pad_left=False) > print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False) > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]", pad_left=False) > > That way you can specify your placeholder, your padding character, and > whether you want it to pad to the left or right. > The code changes any existing '%' to '%%' because each placeholder will be changed to '%s'. However, if the placeholder itself is '%' then the initial 'fix' isn't necessary. Therefore: def picture(s, pic, placeholder='@', padding=' ', pad_left=True): s = str(s) expected = pic.count(placeholder) if len(s) > expected: s = s[:expected] elif len(s) < expected: if pad_left: s = s.rjust(expected, padding) else: s = s.ljust(expected, padding) if placeholder != '%': pic = pic.replace('%', '%%') return pic.replace(placeholder, '%s') % tuple(s) From invalid at invalid.invalid Wed Feb 10 14:57:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 19:57:04 +0000 (UTC) Subject: Creating formatted output using picture strings References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: On 2010-02-10, python at bdurham.com wrote: [regardning "picture" output format specifiers] > I was thinking that there was a built-in function for this > common(?) use case I haven't seen that paradigm since my one-and-only exposure to COBOL in a class I took back in 1979. Is the "picture" thing commonly used in other places than COBOL? -- Grant Edwards grante Yow! Did I say I was at a sardine? Or a bus??? visi.com From alfps at start.no Wed Feb 10 15:02:14 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 21:02:14 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Duncan Booth: > "Alf P. Steinbach" wrote: > >>> In CPython objects once created remain in the same memory location >>> (and their id is their address). Compare that to IronPython where the >>> objects themselves can move around in memory so they have no fixed >>> address. Try comparing the IronPython implementation to C pointers >>> and you'll cause a lot of confusion. e.g. someone might think the >>> id() value is in some way related to an address. >> Did you /read/ what you quoted? >> >> >>> Ruby implements integers without using any pointers at all: there's >>> nothing in the Python specification which prevents a Python >>> implementation doing the same for small integers, in fact I believe >>> it has been tried but wasn't found to improve performance. >> All theree of your points about Python are wrong; I don't know about >> the Ruby point. > > Would you care to expand upon your claim that my three points about Python > are wrong? Sure. I already did in the article you're replying to, immediately following what you quote above. You snipped that which you're asking for, so I requote: First, the current Python language specification formally prevents the optimization you mention, because there's no support for binding to do anything but direct binding leaving object identities unchanged. But in practice that's no big deal though: I can't imagine any code relying on identities of completely immutable objects. Second, even the variant that was tried improved performance. But it would reportedly have wreaked havoc with imperfect C code. Third, the optimization doesn't do away with pointers. If it did then it would transform the language completely. The user's view is still one where names denote pointers. Since in the quoting above no reference to definition of "pointer" remains: "pointer" refers to a copyable reference value as seen from the Python level, in the same way as "pointer" is used by e.g. the Java language spec. > Are you saying that CPyhton objects move around, or that > IronPython objects are fixed to a single memory location or that their id > is related to their address? No, I can't see how you can deduce any such connection from I wrote. Whether objects "move around" depends on what exactly you mean by "move around", and given that, it may then depend on the Python implementation. However, from the Python point of view every object has a fixed unique id, available via id(). > Clue here: > > IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082 > Type "help", "copyright", "credits" or "license" for more information. >>>> x = 42 >>>> id(x) > 43 >>>> y = 43 >>>> id(y) > 44 >>>> z = "whatever" >>>> id(z) > 45 > I'm guessing wildly that you're trying to illustrate id's that don't correspond to memory addresses? If so, then that's correct: a Python (or Java, or whatever language) pointer is not necessarily directly a memory address, and furthermore id is not guaranteed to reproduce the bits of a pointer value -- which might not even make sense. All that id does is to produce a value that uniquely identifies the object pointed to, i.e. it corresponds to the pointer value, and although in CPython that's simply the bits of a C pointer typed as integer, in IronPython it's not. Cheers & hth., - Alf From python at mrabarnett.plus.com Wed Feb 10 15:05:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 20:05:55 +0000 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: <4B7311A3.3010504@mrabarnett.plus.com> kj wrote: > > Some people have mathphobia. I'm developing a wicked case of > Unicodephobia. > > I have read a *ton* of stuff on Unicode. It doesn't even seem all > that hard. Or so I think. Then I start writing code, and WHAM: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) > > (There, see? My Unicodephobia just went up a notch.) > > Here's the thing: I don't even know how to *begin* debugging errors > like this. This is where I could use some help. > > In the past I've gone for method of choice of the clueless: > "programming by trial-and-error", try random crap until something > "works." And if that "strategy" fails, I come begging for help to > c.l.p. And thanks for the very effective pointers for getting rid > of the errors. > > But afterwards I remain as clueless as ever... It's the old "give > a man a fish" vs. "teach a man to fish" story. > > I need a systematic approach to troubleshooting and debugging these > Unicode errors. I don't know what. Some tools maybe. Some useful > modules or builtin commands. A diagnostic flowchart? I don't > think that any more RTFM on Unicode is going to help (I've done it > in spades), but if there's a particularly good write-up on Unicode > debugging, please let me know. > > Any suggestions would be much appreciated. > > FWIW, I'm using Python 2.6. The example above happens to come from > a script that extracts data from HTML files, which are all in > English, but they are a daily occurrence when I write code to > process non-English text. The script uses Beautiful Soup. I won't > post a lot of code because, as I said, what I'm after is not so > much a way around this specific error as much as the tools and > techniques to troubleshoot it and fix it on my own. But to ground > the problem a bit I'll say that the exception above happens during > the execution of a statement of the form: > > x = '%s %s' % (y, z) > > Also, I found that, with the exact same values y and z as above, > all of the following statements work perfectly fine: > > x = '%s' % y > x = '%s' % z > print y > print z > print y, z > Decode all text input; encode all text output; do all text processing in Unicode, which also means making all text literals Unicode (prefixed with 'u'). Note: I'm talking about when you're working with _text_, as distinct from when you're working with _binary data_, ie bytes. From twistedphrame at gmail.com Wed Feb 10 15:13:58 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Wed, 10 Feb 2010 12:13:58 -0800 (PST) Subject: SocketServer error: AttributeError: instance has no __call__ method Message-ID: Hey guys, I'm having some issues connecting to my Socket Server, I get this traceback on the sever side: ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 56404) Traceback (most recent call last): File "/usr/lib/python2.6/SocketServer.py", line 281, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python2.6/SocketServer.py", line 307, in process_request self.finish_request(request, client_address) File "/usr/lib/python2.6/SocketServer.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) AttributeError: Negotiator instance has no __call__ method ---------------------------------------- here's the handler and my server: #server side negotiator from message import message from sharedComs import * from Crypto.Hash import SHA256 from Crypto.Cipher import AES from Crypto import Random from Crypto.PublicKey import RSA import xmlrpclib as xmlrpc import os import SocketServer class Negotiator(SocketServer.BaseRequestHandler): CLIENT_KEY = 0 CSCIPHER = 1 SCCIPHER = 2 CSHALVES = 3 SCHALVES = 4 FILENAME = 5 def __init__(self, host, hostid, rsa_key, buf = 512): self.host = host self.hostid = hostid self.serverKey = rsa_key self.buffer = buf self.clientKey = None self.SCcipher = None self.CScipher = None self.CSHalves = None self.SCHalves = None self.file = None usr_dict = {} def setSChalves(self): usr_dict[str(self.client_address)][SCHALVES] = (Random.new().read(32), Random.new().read(32)) def createCiphers(self): """Create the two ciphers we will be using for communication between negotiators""" name = str(self.client_address) usr_dict[name][1] = AES.new(SHA256.new(str("KCS", usr_dict[name] [SCHALVES][0], self.serverKey.publickey(), usr_dict[name] [CSHALVES][0], usr_dict[name] [CLIENT_KEY].publickey())).digest()) usr_dict[name][2] = AES.new(SHA256.new(str("KSC", usr_dict[name] [SCHALVES][1], self.serverKey.publickey(), usr_dict[name] [CSHALVES][1], usr_dict[name] [CLIENT_KEY].publickey())).digest()) def handleConn(self, clmsg): data = clmsg[1] if data[0] == self.host and data[1] == self.hostid: return True else: return False def getClientHalves(self, clmsg): """Get the halves from the clien as well as the client key.""" print clmsg print "clmsg[1]", clmsg[1] data = stringToTuple(clmsg[1]) print "tuple", data print "tuple[0]", data[0] print "tuple[1]", data[1] data = self.serverKey.decrypt(str(data[0])) print print "data:",data print data = stringToTuple(data) usr_dict[str(self.client_address)][CLIENT_KEY] = RSA.construct((data[0],data[1])) usr_dict[str(self.client_address)][CSHALVES] = (data[2], data[3]) def handleFileReq(self, clmsg): """Determine if the file requested exists: TODO: if the client is allowed to acces""" data = DecodeAES(self.CScipher, clmsg[1]) usr_dict[str(self.client_address)][FILENAME] = data return os.path.exists(usr_dict[str(self.client_address)][5]) def packageFile(self): f = open(usr_dict[str(self.client_address)][5],"rb") data = f.read() f.close() crypt = EncodeAES(self.SCcipher, data) f = open(usr_dict[str(self.client_address)] [5]+str(self.client_address), "wb") f.write(crypt) f.close return (True,self.file+self.client.getAddr()) def handleUserDisc(self, clmsg): os.remove(usr_dict[str(self.client_address)][FILENAME] +str(self.client_address)) def handle(self): #Plan on being asked for server comfirmation msg = self.request.recv(self.buffer) name = str(self.client_address) clmsg = None if not msg == "": clmsg = xmlrpc.loads() if not name in usr_dict: user_dict[name] = ["","","","","",""] print "handle Server ver" clmsg = clmsg[0] if clmsg[0] == CONN: if not self.handleConn(clmsg): print "Not right HostID" del usr_dict[name] else: #We got the right message send a reply with our key srvmsg = message(SERVER_INFO, str(self.serverKey.publickey())) self.request.send(xmlrpc.dumps(srvmsg.getSendable())) elif clmsg[0] == CS_KEY: #all this is public key encryption #plan on getting key halves from the client # as well as the clients public key print "get key/halves from client" self.getClientHalves(clmsg) #send over our halves now print "send halves" self.setSCHalves() srvmsg = message(SC_KEYDAT, str(usr_dict[name] [0].encrypt(usr_dict[name][4],""))) #everyones halves were sent so generate the ciphers self.createCiphers() #all this is AES encryption #### USER AUTH HERE JUST SENDING ACK FOR NOW #no user auth yet so just acknowledge the user exists print "send usr ack" srvmsg = message(USER_ACK, str(EncodeAES(usr_dict[name] [2],True))) self.server.send(xmlrpc.dumps(servmsg.getSendable())) #the client should be sending a file request elif clmsg[0] == FILE_REQ: print "expecting file req" available = self.handleFileReq(clmsg) if available: #file is available srvmsg = message(FILE_ACK, str(EncodeAES(usr_dict[name] [2],available))) else: #file isn't available srvmsg = message(FILE_ACK, str(EncodeAES(usr_dict[name] [2],available))) print "File %s not Available" %self.file del usr_dict[name] #package the file and tell the client package = self.packageFile() srvmsg = message(DL_READY, EncodeAES(usr_dict[name][2], package)) self.server.send(xmlrpc(srvmsg.getSendable())) if not package[0]: # the file wasn't pakaged so close the connection #the client tells us they got the file so just remove the file that #was made print "expecting USER_DISC" else: if not usr_dict[name][5] == "": handleUserDisc(clmsg) del usr_dict[name] class ServerNegotiator: def __init__(self, host, port, hostid, rsa_key, buf = 512): negotiator = Negotiator(host, hostid, rsa_key,buf) self.server = SocketServer.TCPServer((host, port), negotiator) def start(self): self.server.serve_forever() Do I need to write the __call__() method as well? From alfps at start.no Wed Feb 10 15:14:54 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 21:14:54 +0100 Subject: Modifying Class Object In-Reply-To: <0382abea$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 09:13:22 +0100, Alf P. Steinbach wrote: > >>> You've >>> dismissed at least one of my arguments with a simple hand-waving of, >>> "That's invalid, cuz." >> That is not a quote of me. It is a lie. > > Alf, although your English in this forum has been excellent so far, I > understand you are Norwegian, so it is possible that you aren't a native > English speaker and possibly unaware that quotation marks are sometimes > ambiguous in English. > > While it is true that quoted text is officially meant to indicate a > direct quote, it is also commonly used in informal text to indicate a > paraphrase. (There are other uses as well, but they don't concern us now.) > > Unfortunately, this means that in informal discussions like this it is > sometimes difficult to distinguish a direct quote from a paraphrase, > except by context. In context, as a native speaker, I can assure you that > Stephen Hansen's use of quotation marks is a paraphrase and not meant to > be read as a direct quote. I'm aware that Stephen Hansen maintains that, but I'm not replying to his ramblings about insanity and so on (perhaps he is a child, but I'm not replying to that kind of stuff). Anyway, in the original article he refererred to part of the quoted text, quoting that in turn as an example of how allegedly patronising (or whatever) I'd been to him. Re-quoting a part *does not make sense* for paraphrasing. And anyway, he wrote a piece where quotes seemed to signify quoting, drawing conclusions from the quoted text. It's just plain lying. Cheers & hth., - Alf From anthony.tolle at gmail.com Wed Feb 10 15:17:51 2010 From: anthony.tolle at gmail.com (Anthony Tolle) Date: Wed, 10 Feb 2010 12:17:51 -0800 (PST) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> On Feb 10, 2:09?pm, kj wrote: > Some people have mathphobia. ?I'm developing a wicked case of > Unicodephobia. > [snip] Some general advice (Looks like I am reiterating what MRAB said -- I type slower :): 1. If possible, use unicode strings for everything. That is, don't use both str and unicode within the same project. 2. If that isn't possible, convert strings to unicode as early as possible, work with them that way, then convert them back as late as possible. 3. Know what type of string you are working with! If a function returns or accepts a string value, verify whether the expected type is unicode or str. 4. Consider switching to Python 3.x, since there is only one string type (unicode). -- From ssteinerx at gmail.com Wed Feb 10 15:19:52 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Wed, 10 Feb 2010 15:19:52 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <72157116-44AD-4F52-BB6E-35BBD629A7A6@gmail.com> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: > On 2010-02-10, python at bdurham.com wrote: > > [regardning "picture" output format specifiers] > >> I was thinking that there was a built-in function for this >> common(?) use case > > I haven't seen that paradigm since my one-and-only exposure to > COBOL in a class I took back in 1979. Is the "picture" thing > commonly used in other places than COBOL? Seriously? I've seen it in dozens places other than COBOL over the years in everything from templating languages to report generators, to built-in support in a variety of languages (dBASE II anyone?). Haven't you ever had to get a e.g. a phone number or social security number from user input? S From tjreedy at udel.edu Wed Feb 10 15:24:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Feb 2010 15:24:39 -0500 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: On 2/10/2010 5:21 AM, Quin wrote: > Well, PyScripter works find with that code. Furthermore, the > un-intellisense in IronPython was problematic, inserting the wrong > things, which I had to erase. > > Also, there were some code constructs IronPython let pass that > PyScripter didn't, namely, print(), PyScripter requires the () > > Something simple, like: > n = -1 > if n <> -1: > print('fell through') > > falls through to the print. > > So, I don't know what the problem is with IronPython, perhaps it isn't > compatible with Python v3, but on my machine, at least, it doesn't perform. '<>' is not legal in Python3, so above is not Python3 code. From python.list at tim.thechases.com Wed Feb 10 15:39:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 14:39:44 -0600 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <4B731990.4020400@tim.thechases.com> Grant Edwards wrote: > [regardning "picture" output format specifiers] >> I was thinking that there was a built-in function for this >> common(?) use case > > I haven't seen that paradigm since my one-and-only exposure to > COBOL in a class I took back in 1979. Is the "picture" thing > commonly used in other places than COBOL? I've spotted in the wild as recently as Visual Basic 6. I don't know if remnants made it into Visual Fred (VB.net). I think they're referred to as "format strings", but they're a mystical (and poorly documented) suite of characters that seem to have accrued features like my bathtub gets mildew. Most folks just copy and paste the format strings from the web. -tkc From invalid at invalid.invalid Wed Feb 10 15:40:41 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 20:40:41 +0000 (UTC) Subject: Creating formatted output using picture strings References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: On 2010-02-10, ssteinerX at gmail.com wrote: > On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: > >> On 2010-02-10, python at bdurham.com wrote: >> >> [regardning "picture" output format specifiers] >> >>> I was thinking that there was a built-in function for this >>> common(?) use case >> >> I haven't seen that paradigm since my one-and-only exposure to >> COBOL in a class I took back in 1979. Is the "picture" thing >> commonly used in other places than COBOL? > > Seriously? Seriously. > I've seen it in dozens places other than COBOL over the years > in everything from templating languages to report generators, > to built-in support in a variety of languages (dBASE II > anyone?). > > Haven't you ever had to get a e.g. a phone number or social > security number from user input? Nope. I guess it's specific to certain application areas. I've never done any database type stuff. I do mostly embedded, device drivers, networking/protocols, industrial automation, Unix system admin/automation, and scientific visualization. -- Grant Edwards grante Yow! I once decorated my at apartment entirely in ten visi.com foot salad forks!! From subhakolkata1234 at gmail.com Wed Feb 10 15:42:17 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Wed, 10 Feb 2010 12:42:17 -0800 (PST) Subject: A silly question on file opening Message-ID: Dear Group, I was using Python with IDLE as GUI for quite some time. My Operating System was Windows XP with Service Pack2. Recently I changed the Operating System to Windows XP with Service Pack3. I had to reinstall Python for which I downloaded "python-2.6.4.msi"and loaded it in my D drive. Here, as I am trying to open the file if I am giving a statement like, file_open=open("python26/file","r") It is showing an error, On checking how the files are stored it is showing that it is storing in D drive directly but not in Python folder in D drive there is no Python folder at all. I tried to change the location to D:\file and as I saw in Python Docs the file reading option is now "r+" so I changed the statement to file_open=open("D:\file","r+") but it is still giving error. Did I install it wrongly? If you can please help it out. Best Regards, Subhabrata. From ssteinerx at gmail.com Wed Feb 10 15:52:42 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Wed, 10 Feb 2010 15:52:42 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: On Feb 10, 2010, at 3:40 PM, Grant Edwards wrote: > On 2010-02-10, ssteinerX at gmail.com wrote: >> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: >> >>> On 2010-02-10, python at bdurham.com wrote: >>> >>> [regardning "picture" output format specifiers] >>> >>>> I was thinking that there was a built-in function for this >>>> common(?) use case >>> >>> I haven't seen that paradigm since my one-and-only exposure to >>> COBOL in a class I took back in 1979. Is the "picture" thing >>> commonly used in other places than COBOL? >> >> Seriously? > > Seriously. > >> I've seen it in dozens places other than COBOL over the years >> in everything from templating languages to report generators, >> to built-in support in a variety of languages (dBASE II >> anyone?). >> >> Haven't you ever had to get a e.g. a phone number or social >> security number from user input? > > Nope. I guess it's specific to certain application areas. I've > never done any database type stuff. I do mostly embedded, > device drivers, networking/protocols, industrial automation, > Unix system admin/automation, and scientific visualization. Yah, I've hardly ever had to get SSN input from users in a device driver ;-). That's what makes groups like this go 'round; we have all done different types of things which gives us all different perspectives. S From ethan at stoneleaf.us Wed Feb 10 15:56:02 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 10 Feb 2010 12:56:02 -0800 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: <4B731D62.1010004@stoneleaf.us> Tim Chase wrote: > Any thoughts on how others make the choice? > > -tkc If one branch is only a few lines, it comes first. As often as not, that tiny branch is checking for errors, and the "else" branch doesn't need to be indented. def func(arg1): if arg1 is 'stupid': raise ValueError("that's a stupid argument!") do_something do_something_else etc, etc ~Ethan~ From anthony.tolle at gmail.com Wed Feb 10 15:57:52 2010 From: anthony.tolle at gmail.com (Anthony Tolle) Date: Wed, 10 Feb 2010 12:57:52 -0800 (PST) Subject: A silly question on file opening References: Message-ID: On Feb 10, 3:42?pm, joy99 wrote: > Dear Group, > [snip] > I tried to change the location to D:\file and as I saw in Python Docs > the file reading option is now "r+" so I changed the statement to > ? ?file_open=open("D:\file","r+") > but it is still giving error. Only use "r+" if you need to also write to the file. "r" is still good for opening for reading. Without seeing a traceback, I can only assume the error is caused by using a backslash in the path without escaping it. Try either the following: file_open=open("D:\\file","r+") file_open=open(r"D:\file","r+") For an explanation, see the Python documentation: http://docs.python.org/reference/lexical_analysis.html#string-literals From no.email at please.post Wed Feb 10 16:03:01 2010 From: no.email at please.post (kj) Date: Wed, 10 Feb 2010 21:03:01 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: In <402ac982-0750-4977-adb2-602b19149d81 at m24g2000prn.googlegroups.com> Jonathan Gardner writes: >On Feb 10, 11:09=A0am, kj wrote: >> FWIW, I'm using Python 2.6. =A0The example above happens to come from >> a script that extracts data from HTML files, which are all in >> English, but they are a daily occurrence when I write code to >> process non-English text. =A0The script uses Beautiful Soup. =A0I won't >> post a lot of code because, as I said, what I'm after is not so >> much a way around this specific error as much as the tools and >> techniques to troubleshoot it and fix it on my own. =A0But to ground >> the problem a bit I'll say that the exception above happens during >> the execution of a statement of the form: >> >> =A0 x =3D '%s %s' % (y, z) >> >> Also, I found that, with the exact same values y and z as above, >> all of the following statements work perfectly fine: >> >> =A0 x =3D '%s' % y >> =A0 x =3D '%s' % z >> =A0 print y >> =A0 print z >> =A0 print y, z >> >What are y and z? x = "%s %s" % (table['id'], table.tr.renderContents()) where the variable table represents a BeautifulSoup.Tag instance. >Are they unicode or strings? The first item (table['id']) is unicode, and the second is str. >What are their values? The only easy way I know to examine the values of these strings is to print them, which, I know, is very crude. (IOW, to answer this question usefully, in the context of this problem, more Unicode knowhow is needed than I have.) If I print them, the output for the first one on my screen is "mainTable", and for the second it is Tags Id >It sounds like someone, probably beautiful soup, is trying to turn >your strings into unicode. A full stacktrace would be useful to see >who did what where. Unfortunately, there's not much in the stacktrace: Traceback (most recent call last): File "./download_tt.py", line 427, in x = "%s %s" % (table['id'], table.tr.renderContents()) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 41: ordinal not in range(128) (NB: the difference between this error message and the one I originally posted, namely the position of the unrecognized byte, is because I simplified the code for the purpose of posting it here, eliminating one additional processing of the second entry of the tuple above.) ~K From steve at holdenweb.com Wed Feb 10 16:14:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 16:14:51 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > * Duncan Booth: >> "Alf P. Steinbach" wrote: >> >>>> In CPython objects once created remain in the same memory location >>>> (and their id is their address). Compare that to IronPython where the >>>> objects themselves can move around in memory so they have no fixed >>>> address. Try comparing the IronPython implementation to C pointers >>>> and you'll cause a lot of confusion. e.g. someone might think the >>>> id() value is in some way related to an address. >>> Did you /read/ what you quoted? >>> >>> >>>> Ruby implements integers without using any pointers at all: there's >>>> nothing in the Python specification which prevents a Python >>>> implementation doing the same for small integers, in fact I believe >>>> it has been tried but wasn't found to improve performance. >>> All theree of your points about Python are wrong; I don't know about >>> the Ruby point. >> >> Would you care to expand upon your claim that my three points about >> Python are wrong? > > Sure. I already did in the article you're replying to, immediately > following what you quote above. You snipped that which you're asking > for, so I requote: > > > > First, the current Python language specification formally prevents the > optimization you mention, because there's no support for binding to do > anything but direct binding leaving object identities unchanged. > > But in practice that's no big deal though: I can't imagine any code > relying on identities of completely immutable objects. > > Second, even the variant that was tried improved performance. > > But it would reportedly have wreaked havoc with imperfect C code. > > Third, the optimization doesn't do away with pointers. If it did then it > would transform the language completely. The user's view is still one > where names denote pointers. > > > > Since in the quoting above no reference to definition of "pointer" > remains: "pointer" refers to a copyable reference value as seen from the > Python level, in the same way as "pointer" is used by e.g. the Java > language spec. > > >> Are you saying that CPyhton objects move around, or that IronPython >> objects are fixed to a single memory location or that their id is >> related to their address? > > No, I can't see how you can deduce any such connection from I wrote. > > Whether objects "move around" depends on what exactly you mean by "move > around", and given that, it may then depend on the Python implementation. > > However, from the Python point of view every object has a fixed unique > id, available via id(). > > >> Clue here: >> >> IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> x = 42 >>>>> id(x) >> 43 >>>>> y = 43 >>>>> id(y) >> 44 >>>>> z = "whatever" >>>>> id(z) >> 45 >> > > I'm guessing wildly that you're trying to illustrate id's that don't > correspond to memory addresses? > > If so, then that's correct: a Python (or Java, or whatever language) > pointer is not necessarily directly a memory address, and furthermore id > is not guaranteed to reproduce the bits of a pointer value -- which > might not even make sense. > > All that id does is to produce a value that uniquely identifies the > object pointed to, i.e. it corresponds to the pointer value, and > although in CPython that's simply the bits of a C pointer typed as > integer, in IronPython it's not. > You go too far here. What you are referring to in your bizarrely constructed definition above as a pointer does not allow you to access the value that is "pointed to". So I fail to see why you feel its its introduction is necessary. Whether in CPython, Jython or IronPython the value returned by calling id(x) (whether x is a literal, a simple name or a more complex expression) is absolutely no use as an accessor: it does not give you access to the referenced value. If you disagree, please write (in any implementation you like: it need not even be portable, though I can't imagine why ti wouldn't be) a Python function which takes an id() value as its argument and returns the value for which the id() value was provided. So in your world it's unnecessary for pointers to point to anything (or references to refer to something)? For someone who cheerfully admits to being wrong from time to time (an admirable characteristic) you are certainly difficult to convince on this point. One wonders what further hand-waving will follow. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Wed Feb 10 16:18:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 13:18:17 -0800 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <7a9c25c21002101318w2b72f255ga4ee2b643a8ac66d@mail.gmail.com> On Wed, Feb 10, 2010 at 2:21 AM, Quin wrote: > Well, PyScripter works find with that code. Furthermore, the > un-intellisense in IronPython was problematic, inserting the wrong things, > which I had to erase. > I think you're confused and are comparing apples to oranges. To define a couple terms-- I'm starting at the basics, forgive me: Python is a language; CPython is an implementation of that language, in C. Often, Python and CPython are used interchangeably, but not always. There are sort of two concurrent versions of Python available today, both current; 2.6 and 3.1. IronPython is an alternate implementation of the Python 2.6 language, built upon the .NET platform. It's a language, not a tool. (Well, insofar as every language is ultimately a tool). IronPython (like Jython, PyPy, and the other Python alternate implementations) does not yet support Python 3.x. PyScripter is an IDE for Python. IDE's have intellisense and such, languages do not. I'm not sure what you were using as your IDE when you used IronPython-- perhaps IronPython Studio? That's a distinct thing from IronPython itself. PyScripter can support both Python 2.x and 3.x, but I don't know if it requires any settings to change between modes or if you have to select which interpreter you want to use. We can only guess what actual version of Python you're using from your comments, but it looks sort of like 2.x Also, there were some code constructs IronPython let pass that PyScripter > didn't, namely, print(), PyScripter requires the () > > Something simple, like: > n = -1 > if n <> -1: > print('fell through') > > falls through to the print. > PyScripter is not a language, but a tool; in Python 3.x, print requires the () as it is a function. Additionally, in Python 3.x, you have to say "not equal" as !=, you can't use <> anymore. In Python 2.x, print is a statement. You /may/ put () around an expression but that isn't the same thing. For simple operations it frequently looks the same and produces the same output, though. In Python 2.x, you can say "not equal" as either != or <>. The original code: s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' ... will only work on Python 2.x, as print is being used as a statement. If you change print to a function, that code will work in either Python 2.x or Python 3.x. However, in both CPython and IronPython, the above is provably correct code. It works fine: with those five lines alone, you are guaranteed to get 'foundit' followed by 'processing' if mystring is in s. With those five lines alone, you must get that result. If you aren't, then there's something else going on before or after-- and its not about IronPython vs CPython. To help diagnose what's wrong, copy and paste -real- results from a command prompt or interpreter when you run it, providing complete code. Something else is going wrong, you're looking in the wrong place to find the solution. If you're using an IDE, perhaps that IDE is doing something strange (though I can't fathom what), or perhaps its pointing at a different version of Python then you're expecting. We can't really tell from what you've said. So, I don't know what the problem is with IronPython, perhaps it isn't > compatible with Python v3, but on my machine, at least, it doesn't perform. > The current version of IronPython (http://ironpython.net/) is 2.6, yes. They have not yet made a Python 3.x port. Then again, much of the code you've shown us seems to imply you're using Python 2.x, not 3.x. So I can't quite make sense of your environment yet to offer more help-- specifically, you seem to be saying IronPython, but not actually -mean- IronPython, but instead some IDE? --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Feb 10 16:19:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Feb 2010 13:19:14 -0800 Subject: Creating formatted output using picture strings In-Reply-To: <72157116-44AD-4F52-BB6E-35BBD629A7A6@gmail.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <72157116-44AD-4F52-BB6E-35BBD629A7A6@gmail.com> Message-ID: <50697b2c1002101319p407af3d7o5333c416b4db9522@mail.gmail.com> On Wed, Feb 10, 2010 at 12:19 PM, ssteinerX at gmail.com wrote: > On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: >> On 2010-02-10, python at bdurham.com wrote: >> >> [regardning "picture" output format specifiers] >> >>> I was thinking that there was a built-in function for this >>> common(?) use case >> >> I haven't seen that paradigm since my one-and-only exposure to >> COBOL in a class I took back in 1979. Is the "picture" thing >> commonly used in other places than COBOL? > Haven't you ever had to get a e.g. a phone number or social security number from user input? If I have a GUI, I can just put 3 separate length-limited text fields and then I only have to check that the input is numerical and each field is of the right length; no fiddling with punctuation or manual separation into fields; or more likely, there's already a phone number widget! In other words, I won't care about the punctuation characters anyway. If I don't have a GUI: (1) my program is probably not for end-users, so I can be less user-friendly and more dictatorial about the required format (2) or it's munging mediocre data from a DB and I need to be more error-tolerant that picture formatting would allow (3) in any case, it's not *that* hard to do without picture formatting (although it might get tedious after a while, probably hence why some languages in just the right niche indeed offer picture formatting): phone_parts = input("Phone number?: ").replace('(', '').replace(')', '').split('-') if not all(part.isdigit() for part in phone_parts) or [3,3,4] != map(len, phone_parts): #error message to user Stricter validation would either be user-unfriendly or is left as an exercise to the reader. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 16:23:08 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 21:23:08 GMT Subject: A silly question on file opening References: Message-ID: On Wed, 10 Feb 2010 12:42:17 -0800, joy99 wrote: > I tried to change the location to D:\file and as I saw in Python Docs > the file reading option is now "r+" so I changed the statement to > file_open=open("D:\file","r+") > but it is still giving error. You should copy and paste (do not re-type!) the *exact* line that leads to an error, and the full traceback that Python prints. But in this case I can guess what the problem is. Like most C-inspired languages, Python uses backslashes to put in special characters: e.g. \n for newline, \t for tab, and \f for formfeed. So when you try to open "D:\file" you are actually looking for a file on D drive called (chr(12) + "ile"), not "file". The solution to this is to remember that Windows accepts forward slashes as well as backslashes, and always use the forward slash. So try: open("D:/file") and see if that works. >>> print "D:\file" D: ile >>> print "D:/file" D:/file -- Steven From gerald.britton at gmail.com Wed Feb 10 16:27:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 10 Feb 2010 16:27:36 -0500 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: <4B731D62.1010004@stoneleaf.us> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> <4B731D62.1010004@stoneleaf.us> Message-ID: <5d1a32001002101327j1e2ceff3vd899d493f68443f7@mail.gmail.com> On Wed, Feb 10, 2010 at 3:56 PM, Ethan Furman wrote: > Tim Chase wrote: >> >> Any thoughts on how others make the choice? >> >> -tkc > > If one branch is only a few lines, it comes first. ?As often as not, that > tiny branch is checking for errors, and the "else" branch doesn't need to be > indented. > > def func(arg1): > ? ?if arg1 is 'stupid': > ? ? ? ?raise ValueError("that's a stupid argument!") > ? ?do_something > ? ?do_something_else > ? ?etc, etc > > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > Something similar in a for-loop: for x in y: if not should_process(x): continue # process x -- Gerald Britton From apt.shansen at gmail.com Wed Feb 10 16:33:41 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 13:33:41 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: <7a9c25c21002101333q64006b8bm29ad9b7f82a60973@mail.gmail.com> On Wed, Feb 10, 2010 at 1:03 PM, kj wrote: > >What are y and z? > > x = "%s %s" % (table['id'], table.tr.renderContents()) > > where the variable table represents a BeautifulSoup.Tag instance. > > >Are they unicode or strings? > > The first item (table['id']) is unicode, and the second is str. > The problem is you are mixing unicode and strings; if you want to support unicode at all, you should use it -everywhere- within your program. At the entry-points, you should convert from strings to unicode, then use unicode -exclusively-. Here, you are trying to combine a unicode variable with a string variable, and Python is -trying- to convert it for you, but it can't. I suspect you aren't actually realizing this implicit conversion is going on: Python's trying to produce an output string according to what you've requested. To do that, it is upgrading x from string to unicode, and then writing to that string first table['id'] then table.tr.renderContents(). Its the table.tr.renderContents that, I believe, is your problem: it is a byte string, but it contains encoded data. You have to 'upgrade' it to unicode before you can pump it over into x, because Python doesn't know what encoding that is. It just knows there's a character somewhere in there that doesn't fit into ASCII. I can't quite tell you what the encoding is, though it may be UTF8. Try: table.tr.renderContents().decode("utf8") Its an easy mistake to make. To further illustrate, do this: >>> "%s %s" % (u'hi', u'bye') u'hi bye' Even though you're assigning a regular string to "x", you're using a format str to merge in a unicode string to it. So Python implicitly upgrades your format string, as if you had typed: >>> u"%s %s" % (u'hi', 'bye') Upgrading a string to unicode is easy, provided a string contains nothing but plain ASCII. The moment it contains encoded data, the default translation fails. So you have to explicitly tell Python how to convert the byte string back into unicode-- meaning, you have to decode it. Take this example: >>> s = u"He\u2014llo".encode("utf8") >>> s 'He\xe2\x80\x94llo' >>> "%s %s" % (u'hi', s) Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 2: ordinal not in range(128) >>> "%s %s" % (u'hi', s.decode("utf8")) u'hi He\u2014llo' I started out with a string, "s", containing Hello with an em-dash stuck in the middle. I encoded it as UTF8: its now a byte string similar to what may exist on any webpage you get. Remember, pure "unicode" exists only in memory. Everything on the internet or a file is /encoded/. You work with unicode in memory, then encode it to some form when writing it out-- anywhere. When I first try to combine the two, I get an error like you got. But if I explicitly decode my 's', it all works fine. The encoded form is translated back into unicode. As for how to debug and deal with issues like this... never mix unicode and regular strings, use unicode strings exclusively in your logic, and decode as early as possible. Then the only problem you're likely to run into is situations where a claimed encoding/charset is a lie. (Web servers sometimes claim charset/encoding A, or a file may claim charset/encoding B, even though the file was written out by someone with charset/encoding C... and there's no easy way to go around fixing such situations) HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Wed Feb 10 16:39:33 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 21:39:33 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <0382bdeb$0$1277$c3e8da3@news.astraweb.com> <0382ef76$0$1277$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 10 Feb 2010 18:31:23 +0000, Arnaud Delobelle wrote: > >> It's not ideal, but you can use a decorator like this to solve this >> problem: >> >> def bindfunction(f): >> def bound_f(*args, **kwargs): >> return f(bound_f, *args, **kwargs) >> bound_f.__name__ = f.__name__ >> return bound_f > > Ah, very nice. Perhaps it's better to use functools.wraps? > > import functools > > def bindfunction(f): > @functools.wraps(f) > def bound_f(*args, **kwargs): > return f(bound_f, *args, **kwargs) > return bound_f I think I wrote this before functools :). Anyway it still doesn't work with mutually recursive functions. I also tried another approach (can't find the file anymore, so I've redone it, sorry no time to make it very readable) as below. It doesn't require an extra first argument for the function and it takes care of mutually recursive functions if used as in the example. def bindglobals(*args): """ Binds all the globals in all the arguments which must be functions. return the new bound functions. When called with a single argument, return the bound function so it can be used as a decorator. It is assumed that all argument are functions and have the same global namespace """ function_names = [f.__name__ for f in args] def get_global(f, n): d = f.func_globals if n not in d: d = d['__builtins__'].__dict__ return d[n] bound_globals = dict( (n, get_global(f, n)) for f in args for n in f.func_code.co_names if n not in function_names ) bound_functions = [ type(f)(f.func_code, bound_globals, f.func_name, f.func_defaults, f.func_closure) for f in args ] bound_globals.update(zip(function_names, bound_functions)) if len(args) == 1: return bound_functions[0] else: return bound_functions # Example @bindglobals def fac(n): return 1 if n <= 1 else n*fac(n - 1) # Decorator syntax cannot be used with mutually recursive functions: def even(n): return True if not n else odd(n - 1) def odd(n): return False if not n else even(n - 1) even, odd = bindglobals(even, odd) # Example in action: >>> fac(10) 3628800 >>> f = fac >>> fac = 'foo' >>> f(10) 3628800 >>> even(5), odd(5) (False, True) >>> e, o = even, odd >>> even, odd = 'spam', 'eggs' >>> e(5), o(5) (False, True) This is proof of concept stuff - probably very fragile! -- Arnaud From clp2 at rebertia.com Wed Feb 10 16:43:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Feb 2010 13:43:14 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: <50697b2c1002101343h5a853325g74c8b470735b95e@mail.gmail.com> On Wed, Feb 10, 2010 at 1:03 PM, kj wrote: > In <402ac982-0750-4977-adb2-602b19149d81 at m24g2000prn.googlegroups.com> Jonathan Gardner writes: >>It sounds like someone, probably beautiful soup, is trying to turn >>your strings into unicode. A full stacktrace would be useful to see >>who did what where. > > Unfortunately, there's not much in the stacktrace: > > Traceback (most recent call last): > File "./download_tt.py", line 427, in > x = "%s %s" % (table['id'], table.tr.renderContents()) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 41: ordinal not in range(128) Think I've found the problem. According to the BeautifulSoup docs, renderContents() returns a (by default, UTF-8-encoded) str [i.e. byte sequence] as opposed to unicode[i.e. abstract code point sequence] . Thus, as was said previously, you're combining the unicode from table['id']and the str from renderContents(), so Python tries to automatically+implicitly convert the str to unicode by decoding it as ASCII. However, it's not ASCII but UTF-8, hence you get the error about it having non-ASCII bytes. Solution: Convert the output of renderContents() back to unicode. x = u"%s %s" % (table['id'], table.tr.renderContents().decode('utf8')) Now only unicode objects are being combined. Your problem is particularly ironic considering how well BeautifulSoup handles Unicode overall; I was unable to locate a renderContents() equivalent that returned unicode. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 16:46:19 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 21:46:19 GMT Subject: Modifying Class Object References: Message-ID: On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: > "pointer" refers to a copyable reference value as seen from the Python > level, in the same way as "pointer" is used by e.g. the Java language > spec. Python doesn't have "copyable reference values" in the Python level. It has objects. It seems to me that your argument is based on the premises: (1) that the "value" of a variable is not what 99.99% of people would describe as the value, but is some hidden, implementation dependent "pointer" instead; (2) that "pointer" doesn't necessarily mean what 99% of people who learned C or Pascal understand by pointer; (3) that mangling both common English and programmers' expectations in that fashion is somehow more accurate and more useful than using the 35 year old term "call by object" (or "call by object reference"); (4) and, presumably because of some deeply-held belief that the only parameter passing strategies that we're allowed to talk about are "call by value" and "call by reference", no matter how much violence we do to the concept of both value and pointer, Python and Java must be call-by- value since they clearly aren't call-by-reference. Of these, the only one that I consider value is that Python and Java are not call-y-reference. Otherwise, I reject all these premises, and consequently none of your arguments make the slightest sense to me. You keep talking about Python operating on pointers. I've never used a single pointer in 10+ years of Python coding, no matter how many times you tell me I have. What the implementation of the Python virtual machine does is not what I do high-level Python code, and the implementation is not the language. -- Steven From arnodel at googlemail.com Wed Feb 10 16:47:19 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 21:47:19 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> Message-ID: MRAB writes: > Does this mean that Python needs, say, __function__ (and perhaps also > __module__)? See PEP 3130 "Access to Current Module/Class/Function" (rejected) (http://www.python.org/dev/peps/pep-3130/) -- Arnaud From pavlovevidence at gmail.com Wed Feb 10 16:47:44 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 10 Feb 2010 13:47:44 -0800 (PST) Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <41a79d8c-65d2-41e3-bb61-5a987b40be1b@w27g2000pre.googlegroups.com> On Feb 9, 7:36?pm, Tim Chase wrote: > Larry Hudson wrote: > > But a minor rearrangement is simpler, and IMHO clearer: > > > if 'mystring' not in s: > > ? ? ?print 'not found' > > else: > > ? ? ?print 'foundit' > > ? ? ?print 'processing' > > I've always vacillated on whether that would better be written as > Larry does, or as > > ? ?if 'mystring' in s > ? ? ?print 'foundit' > ? ? ?print 'processing' > ? ?else: > ? ? ?print 'not found' [pass] > Any thoughts on how others make the choice? I almost always arrange it as follows, regardless of the size of the blocks or whether the condition is negated or not: if (typical-condition): typical-case else: exceptional-case In particular I almost always test if something is not None, because being None is almost always the exceptional case: if x is not None: ... else: ... However, whenever the exceptional case action is to break, return, continue, or raise an exception, I'll test for it and leave the typical case unnested: if (exceptional-condition): exceptional-case typical-case No, it deosn't bother me in the least that I sometimes test for the exceptional case and sometimes for the typical. Whenever there is no typical case or exceptional case I'll go for the simpler condition. Carl Banks From gagsl-py2 at yahoo.com.ar Wed Feb 10 16:49:40 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Feb 2010 18:49:40 -0300 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: En Wed, 10 Feb 2010 10:59:41 -0300, Muhammad Alkarouri escribi?: > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): > f.args = args > print args > > is there any other way? See this: >>> def foo(): pass ... >>> import sys >>> sys.getrefcount(foo) 2 The 2 means that there is a *single* reference to the function - the foo name in the global namespace. No other reference exists, there is no hidden attribute somewhere that you may use. If you want another way to reach the function, you'll have to add it yourself. I've written a decorator for "injecting" a __function__ name into the function namespace, but I can't find it anywhere. I think I implemented it by adding a fake additional argument and replacing LOAD_GLOBAL with LOAD_NAME in the bytecode. > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a > valid one at the moment, sorry. One reason would be to write truly recursive functions (currently, a recursive call involves a name lookup, which could potentially return a different function). Another one, to implement some kind of tail call optimization. -- Gabriel Genellina From jjposner at optimum.net Wed Feb 10 16:55:07 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 16:55:07 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <4b732b20$0$5011$607ed4bc@cv.net> On 2/10/2010 2:57 PM, Grant Edwards wrote: > On 2010-02-10, python at bdurham.com wrote: > > [regardning "picture" output format specifiers] > >> I was thinking that there was a built-in function for this >> common(?) use case > > I haven't seen that paradigm since my one-and-only exposure to > COBOL in a class I took back in 1979. Is the "picture" thing > commonly used in other places than COBOL? > FWIW, Microsoft Excel supports "Custom" numeric cell formats that use a PICTURE-like syntax. -John From jcd at sdf.lonestar.org Wed Feb 10 16:57:09 2010 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 10 Feb 2010 16:57:09 -0500 Subject: New to Python In-Reply-To: <7a9c25c21002101318w2b72f255ga4ee2b643a8ac66d@mail.gmail.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> <7a9c25c21002101318w2b72f255ga4ee2b643a8ac66d@mail.gmail.com> Message-ID: <1265839029.5997.11.camel@aalcdl07> On Wed, 2010-02-10 at 13:18 -0800, Stephen Hansen wrote: > > The original code: > > > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > > ... will only work on Python 2.x, as print is being used as a > statement. If you change print to a function, that code will work in > either Python 2.x or Python 3.x. > > > However, in both CPython and IronPython, the above is provably correct > code. It works fine: with those five lines alone, you are guaranteed > to get 'foundit' followed by 'processing' if mystring is in s. With > those five lines alone, you must get that result. If you aren't, then > there's something else going on before or after-- and its not about > IronPython vs CPython. To help diagnose what's wrong, copy and paste > -real- results from a command prompt or interpreter when you run it, > providing complete code. Something else is going wrong, you're looking > in the wrong place to find the solution. One other assumption that you are making is that f is a file-like object that supports a reasonalbe readline function. Quin: can you Ctrl-C, Ctrl-V the following code into a python file, by itself, and run it to reproduce your problem? from StringIO import StringIO f = StringIO('This string contains mystring') s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' # Should print: # foundit # processing f = StringIO('This string does not contain MyStRiNg') s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' # Should print: # not found And please, humor me and copy and paste the exact results as returned by your IronPython interpreter. From alfps at start.no Wed Feb 10 17:02:27 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 23:02:27 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steve Holden: > Alf P. Steinbach wrote: [snip] >> >> Since in the quoting above no reference to definition of "pointer" >> remains: "pointer" refers to a copyable reference value as seen from the >> Python level, in the same way as "pointer" is used by e.g. the Java >> language spec. >> [snip] >> >> If so, then that's correct: a Python (or Java, or whatever language) >> pointer is not necessarily directly a memory address, and furthermore id >> is not guaranteed to reproduce the bits of a pointer value -- which >> might not even make sense. >> >> All that id does is to produce a value that uniquely identifies the >> object pointed to, i.e. it corresponds to the pointer value, and >> although in CPython that's simply the bits of a C pointer typed as >> integer, in IronPython it's not. >> > You go too far here. What you are referring to in your bizarrely > constructed definition above No, it's not bizarre, it's the standard general language independent definition. And since I'm referring to an external definition (Java) it's not mine, either. :-) > as a pointer does not allow you to access > the value that is "pointed to". So I fail to see why you feel its its > introduction is necessary. Python provides a number of ways to access the object pointed to. Attribute access, indexing, and operators access the objects pointed to. For example, x = s[0] accesses the object that s points (refers) to. While 'is', 'id' and assignment operate on the pointers (references) themselves. So there's one set of language features that operate on pointers, and one set of language features that operate on the pointed to objects. This is so also in Java and C#. For example. > Whether in CPython, Jython or IronPython the value returned by calling > id(x) (whether x is a literal, a simple name or a more complex > expression) is absolutely no use as an accessor: it does not give you > access to the referenced value. Yes, the id does not give you access to the referenced object. > If you disagree, please write (in any implementation you like: it need > not even be portable, though I can't imagine why ti wouldn't be) a > Python function which takes an id() value as its argument and returns > the value for which the id() value was provided. No, I don't disagree with that. It would be excessively inefficient to do, involving enumeration of all objects. > So in your world it's unnecessary for pointers to point to anything (or > references to refer to something)? For someone who cheerfully admits to > being wrong from time to time (an admirable characteristic) you are > certainly difficult to convince on this point. One wonders what further > hand-waving will follow. He he, "further" handwaiving: you're good at unsubstantiated allegations. I generally strive to provide concrete examples, and you know it. Anywyay, treating the first sentence as a genuine question: in the most likely interpretation it seems that you're conflating id's with pointers. An id() value uniquely represents a pointer (i.e., the identity of the object pointed to). It is not itself a pointer since it lack any pointer semantics. For a less likely more technical interpretation, as far as I know in Python there's just one case of a pointer that does not point to anything, namely as exemplified by def foo(): print( x ) x = "whatever" The Java equivalent would say "NullPointerException", in Python it says something like "unbound". Which means the same. Cheers & hth., - Alf From alfps at start.no Wed Feb 10 17:09:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 23:09:25 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Ethan Furman: > Steven D'Aprano wrote: >> >> Believe me Alf, the fact that people are taking the time to try to >> argue with you instead of just kill-filing you is a compliment. > > It's a compliment I am not paying, although I am grateful to those who > are attempting to teach him. At the rate it's going, though, I don't > see myself buying any book he produces. > > Besides the arrogant attitude, he is wrong on so many things about > Python it is truly stunning. That's bullshit. I am probably wrong about many Python things, for this is so no matter the language and the practictioner, but not any that you know about. > He seems to have confidence born of > ignorance... a scary sight to see. > > In the spirit of being helpful and not just being a jerk myself: > > Alf, > > Using smileys after declaring somebody is mistaken/wrong/etc makes you > look bad. > > Not attempting to learn the language makes you look like an arrogant > idiot (case in point: passing-by-object). > > Accusing anyone and everyone that criticizes you of making ad hominem > (sp?) attacks makes you look like a whiner. > > After all is said and done - if you had a truly good grasp of Python, I > might buy your book even if you still had -- ummm -- a less than winning > presence on the mailing list; but right now your understanding is not > worth paying for. > > Hoping-this-helps-but-not-really-expecting-it-to-ly yours, It's yet another ad hominem attack, which means that you're painfully aware of supporting an untenable technical position, or supporting a clique of people. It also reflects rather badly on you. Cheers & hth., - Alf From jjposner at optimum.net Wed Feb 10 17:13:06 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 17:13:06 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B732F72.1030208@optimum.net> On 2/10/2010 1:38 PM, Ethan Furman wrote: > > After all is said and done - if you had a truly good grasp of Python, I > might buy your book even if you still had -- ummm -- a less than winning > presence on the mailing list; but right now your understanding is not > worth paying for. > Alf, here's my suggestion on how to respond to people's criticisms of your technical prowess: come up with the "best ever" description of Python's variable-assignment and argument-passing schemes, and place the description in your manuscript [1]. Section 2.4, "Naming things", currently does not address the issues discussed in this thread ("pass by XXX", etc.). HTH, John [1] http://mail.python.org/pipermail/python-list/2009-December/1229932.html From twistedphrame at gmail.com Wed Feb 10 17:19:50 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Wed, 10 Feb 2010 14:19:50 -0800 (PST) Subject: SimpleXMLRPCServer and client address Message-ID: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> I'm trying to right a server that needs specific information for each client accessing it. The easiest way I could think of doing this is keeping this information based on ip address (the information is only valid for a short time). I know there is no was to get the client's address directly and have seen a few examples of subclassing the SimpleXMLRPCServer like this: class RPCServer(SimpleXMLRPCServer): def _dispatch(self, method, params): """Extend dispatch, adding client info to some parameters.""" if method in ({my list of methods I needed client address}): return SimpleXMLRPCServer._dispatch(self, method, params+(self.client_address,)) return SimpleXMLRPCServer._dispatch(self, method, params); but to be honest I don't understand what's going on there or how to use it. Would anyone be able to explain this to me? From arnodel at googlemail.com Wed Feb 10 17:19:50 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 22:19:50 +0000 Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: "Alf P. Steinbach" writes: [...] > That's bullshit. [...] > not any that you know about. [...] > yet another ad hominem attack [...] > It also reflects rather badly on you. [...] > - Alf Alf, The above was extracted from the last post from you but I could have picked almost any of your recent endeavours. I've come to the conclusion that you're not a cute furry alien with a long nose. You're a big bad troll! -- Arnaud From icanbob at gmail.com Wed Feb 10 17:19:55 2010 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 10 Feb 2010 14:19:55 -0800 (PST) Subject: strange issue with C extension using Py_BuildValue Message-ID: I'm am having "strange" problems with the code snip below. When this code is built on a 64bit Linux, it would appear to work flawlessly. When the source is rebuilt on a 32bit Linux it begins to crack in strange ways. The issue seems to be associated with the sender field in the Py_BuildValue call. The fact that sender is a pointer should mean that its value is an unsigned integer. However, on the 32 bit build the failure is that the msgPtr->data value is "messed up". If the format associated with the sender (a pointer) from "L" to "i" things work on the 32 bit side but break on the 64 bit side. I fully understand that an address will be stored differently on the 64bit vs. the 32bit systems. The problem is that the code is recompiled from source in both cases so shouldn't the "L" format work as expected in both architectures? Furthermore, how can an incorrect format result in messing up the field which follows? Thanks in advance for any help. bob PS. The Python side using this extension isn't expecting to do anything with the sender parameter other than store it for later use as a parameter in a Reply() function call. ie. an address goes from extension ->Python -> extension. ========= begin code snip =================== static PyObject *simpl_receive(PyObject *self, PyObject *args) { int ret; char *sender; FCMSG_REC *msgPtr; // call the actual simpl C library function ret = Receive(&sender, NULL, 0); // what sort of message are we dealing with? if (ret > 0) // message { msgPtr = (FCMSG_REC *)sender; return( Py_BuildValue("iLz#", ret, sender, &msgPtr->data, ret) ); } ========== end code snip ============ From ldo at geek-central.gen.new_zealand Wed Feb 10 17:30:24 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Feb 2010 11:30:24 +1300 Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> <4b712919$0$6584$9b4e6d93@newsspool3.arcor-online.net> Message-ID: In message <4b712919$0$6584$9b4e6d93 at newsspool3.arcor-online.net>, Stefan Behnel wrote: > Usually PyPI. Where do you think these tools come from? They don?t write themselves, you know. From gagsl-py2 at yahoo.com.ar Wed Feb 10 17:37:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Feb 2010 19:37:36 -0300 Subject: How to measure elapsed time under Windows? References: Message-ID: En Wed, 10 Feb 2010 13:15:22 -0300, Grant Edwards escribi?: > On 2010-02-09, Gabriel Genellina wrote: >> En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards >> escribi?: >> >>> What's the correct way to measure small periods of elapsed >>> time. I've always used time.clock() in the past: >>> However on multi-processor machines that doesn't work. >>> Sometimes I get negative values for delta. According to >>> google, this is due to a bug in Windows that causes the value >>> of time.clock() to be different depending on which core in a >>> multi-core CPU you happen to be on. [insert appropriate >>> MS-bashing here] >> >> I'm not sure you can blame MS of this issue; anyway, this >> patch should fix the problem: >> http://support.microsoft.com/?id=896256 > > I'm curious why it wouldn't be Microsoft's fault, because > > A) Everything is Microsoft's fault. ;) > > B) If a patch to MS Windows fixes the problem, how is it not a > problem in MS Windows? I won't argue against A) because its truthness (?) is self-evident :) 99% of my code does not run in Python 3.x; I may fix it and it will eventually run fine, but that doesn't mean it's *my* fault. The original problem was with the RDTSC instruction on multicore CPUs; different cores may yield different results because they're not synchronized at all times. Windows XP was launched in 2001, and the first dual core processors able to execute Windows were AMD Opteron and IBM Pentium D, both launched around April 2005 (and targeting the server market, not the home/desktop market of Windows XP). How could MS know in 2001 of a hardware issue that would happen four years in the future? Guido seems very jealous of his time machine and does not lend it to anyone. -- Gabriel Genellina From invalid at invalid.invalid Wed Feb 10 17:40:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 22:40:34 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Gabriel Genellina wrote: > In code, using SetProcessAffinityMask and related functions: > http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx That solves the problem. If I don't set the process affinity mask, I regularly get measurements that are off by 6ms. I presume 6ms is the skew between the two cores' performance counter values. I don't know if that difference is stable or how it varies, but now it doesn't matter. :) -- Grant Edwards grante Yow! If our behavior is at strict, we do not need fun! visi.com From misceverything at gmail.com Wed Feb 10 17:55:22 2010 From: misceverything at gmail.com (T) Date: Wed, 10 Feb 2010 14:55:22 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> On Feb 9, 4:25?pm, David Bolen wrote: > David Bolen writes: > > Not from my past experience - the system account (LocalSystem for > > services) can be surprising, in that it's pretty much unlimited access > > to all local resources, but severely limited in a handful of cases, > > one of which is any attempt to access the network. ?I can't recall for > > sure if it's an absolute block, or if in some cases you can configure > > around it (e.g., it might use a null session for remote shares which > > can be enabled through the registry on the target machine). ?I've > > basically stuck "LocalSystem = no network" in my head from past > > experience. > > Given it's been a few years, I decided to try some tests, and the > above is too simplistic. > > The LocalSystem account runs without any local Windows credentials > (e.g., not like a logged in user), which has several consequences. > One is that you can't access any network resources that require such > credentials (like shares). ?However, there's no sort of firewall > filtering or anything, so plain old TCP/IP connections are fine. > Unless, of course, the client being used also has other needs for > local Windows credentials, independent or as a pre-requisite to the > network operations. > > So backing up a bit, the TCP/IP connection that plink is making is not > inherently disabled by running under LocalSystem, but it's certainly > possible that plink is trying to identify the user under which it is > operating to perhaps identify ssh keys or other local resources it > needs to operate. ?You might be able to cover this with command line > options (e.g., plink supports "-i" to specify a key file to use), but > you'll also need to ensure that the file you are referencing is > readable by the LocalSystem account. > > One of the other responders had a very good point about locating plink > in the first place too. ?Services run beneath an environment that is > inherited from the service control manager process, and won't include > various settings that are applied to your user when logged in, > especially things like local path changes, and working directories. > Should you change the system path (via the environment settings), > you'll need to reboot for the service control manager to notice - I > don't think you can restart it without a reboot. > > So it's generally safer to be very clear, and absolute when possible, > in a service for paths to external resources. > > The prior advice of running the service as an identified user (e.g., > with local credentials) is still good as it does remove most of these > issues since if you can run the script manually under that user you > know it'll work under service. ?But it's not a hard requirement. > > If your script is dying such that a top level exception is being > raised you should be able to find it in the application event log. ?So > that might give further information on what about the different > environment is problematic. > > You can also use the win32traceutil module to help with grabbing debug > output on the fly. ?Import the module in your service, which will > implicitly redirect stdout/stderr to a trace buffer. ?Run the same > win32traceutil module from the command line in another window. ?Then > start the service. ?Any stdout/stderr will be reflected in the other > window. ?Can't catch everything (suppressed exceptions, or I/O that > doesn't flow through the script's stdout/stderr), but again might help > point in the right direction. > > -- David Great suggestions once again - I did verify that it was at least running the plink.exe binary when under LocalSystem by having the service run "plink.exe > C:\plinkoutput.txt" - this worked fine. And, as I mentioned, it's now working just fine when running under a regular admin account. So, I think that's going to be my solution to avoid any further issues. My best guess at this point (as you mentioned), is that plink.exe is doing _something_ network-related that LocalSystem doesn't have the privileges to do - what exactly it is, I have no idea. I may play around with it some more later, but running the service under an admin account should be a perfectly acceptable solution. Also, I will be writing other Python apps that the service will be executing - so it goes without saying that I'll be including a log to file option :) Thanks again for all your guys' help! From alfps at start.no Wed Feb 10 17:56:36 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 23:56:36 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: > >> "pointer" refers to a copyable reference value as seen from the Python >> level, in the same way as "pointer" is used by e.g. the Java language >> spec. > > Python doesn't have "copyable reference values" in the Python level. It > has objects. Given s = [1] t = s # Copies reference. t[0] = 2 # Changes referenced object via copied reference. print( s ) # Checks the object via the original reference. your argument that the copied reference does not exist, is just silly. And you know it. > It seems to me that your argument is based on the premises: > > (1) that the "value" of a variable is not what 99.99% of people would > describe as the value, but is some hidden, implementation dependent > "pointer" instead; No. The Python language spec defines what value of an object means. And people use "value" with many different meanings, using Common Sense to arbitrate. It would be senseless to try to pin down a single meaning of the word "value". You're arguing against a position unrelated to mine. > (2) that "pointer" doesn't necessarily mean what 99% of people who > learned C or Pascal understand by pointer; No. But although this is "just" a terminological issue, it's worth discussing. I refuse to believe that 99% of C and Pascal programmers believe that "pointer" only refers to the pointer implementation in their language of choice. In my first article in this thread I specifically referred to the Java language specification, which says, first sentence in ?4.3.1 in the 3.0 spec, that "The reference values (often just references) are pointers to these objects, and a special null reference, which refers to no object." which is relevant to Python because Java has the same semantics, although Java "NullPointerException" is called "unbound" in Python (but this is again just terminology, not semantics). I.e., the general pointer term /can/ be used, and is used, for reference values. Only a willingness to misinterpret can cause confusion, at least when the terminology is defined, as I've done all the time. Secondly I referred (actually that was in response to you) to a Stanford University introduction to pointers, comparing four languages including Java. I didn't refer you to Wikipedia because that article seems to lack mention of reference based languages and does include a reference to an article that I wrote about pointers in C++ (now off-net), and given the noise level here it would therefore probably not help. > (3) that mangling both common English and programmers' expectations in > that fashion is somehow more accurate and more useful than using the 35 > year old term "call by object" (or "call by object reference"); No, I haven't stated any opposition to using that term; the archives show the opposite. So for the second time here you're arguing against a silly position that I do not hold. > (4) and, presumably because of some deeply-held belief that the only > parameter passing strategies that we're allowed to talk about are "call > by value" and "call by reference", no matter how much violence we do to > the concept of both value and pointer, Python and Java must be call-by- > value since they clearly aren't call-by-reference. Well that's the third time here that you're arguing against a silly position that I do not hold. > Of these, the only one that I consider value is that Python and Java are > not call-y-reference. Otherwise, I reject all these premises, Good rejection as far as 1, 3 and 4 are concerned. Regarding the term "pointer", your point 2, I strongly encourage you to seek out the sources I've referenced and quoted. For without a common language it's difficult to communicate, and if Python programmers should continue to not understand common terms then that would just further flame wars such as this thread has escalated to. Please seek out sources. Don't just take my word, instead, read e.g. what I've quoted, try out the example I've given, and so on: be critical (to your own assumptions also!). > and > consequently none of your arguments make the slightest sense to me. Well, you'd first have to examine at least one of my arguments. In this article you haven't, instead attacking a number of positions that I haven't advocated and do not hold, except for your silly denial of existence of references at the top. But that's just silly -- consider the concrete example given. > You > keep talking about Python operating on pointers. I've never used a single > pointer in 10+ years of Python coding, no matter how many times you tell > me I have. What the implementation of the Python virtual machine does is > not what I do high-level Python code, and the implementation is not the > language. Here again you're conflating things and engage in a kind of denial coupled with a correct argument. It's hard to argue against such confusion. Instead I've tried above to address your only relevant point, by a concrete example. Summing up, denying the existence of references, as you do at the top, is just silly; do consider the code example. Your points 1, 3 and 4 attack positions that I do not hold and have not advocated. Your point 2, about terminology, is important on its own. And I suggest you check out the references I've given. And read what I quoted from the language specification of a language with the same semantics as Python. Cheers & hth., - Alf From dmalcolm at redhat.com Wed Feb 10 18:03:32 2010 From: dmalcolm at redhat.com (David Malcolm) Date: Wed, 10 Feb 2010 18:03:32 -0500 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> References: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> Message-ID: <1265843012.8386.17.camel@brick> On Wed, 2010-02-10 at 12:17 -0800, Anthony Tolle wrote: > On Feb 10, 2:09 pm, kj wrote: > > Some people have mathphobia. I'm developing a wicked case of > > Unicodephobia. > > [snip] > > Some general advice (Looks like I am reiterating what MRAB said -- I > type slower :): > > 1. If possible, use unicode strings for everything. That is, don't > use both str and unicode within the same project. > > 2. If that isn't possible, convert strings to unicode as early as > possible, work with them that way, then convert them back as late as > possible. > > 3. Know what type of string you are working with! If a function > returns or accepts a string value, verify whether the expected type is > unicode or str. > > 4. Consider switching to Python 3.x, since there is only one string > type (unicode). Some further nasty gotchas: 5. Be wary of the encoding of sys.stdout (and stderr/stdin), e.g. when issuing a "print" statement: they can change on Unix depending on whether the python process is directly connected to a tty or not. (a) If they're directly connected to a tty, their encoding is taken from the locale, UTF-8 on my machine: [david at brick ~]$ python -c 'print u"\u03b1\u03b2\u03b3"' ??? (prints alpha, beta, gamma to terminal, though these characters might not survive being sent in this email) (b) If they're not (e.g. cronjob, daemon, within a shell pipeline, etc) their encoding is the default encoding, which is typically ascii; rerunning the same command, but piping into "cat": [david at brick ~]$ python -c 'print u"\u03b1\u03b2\u03b3"'| cat Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) (c) These problems can lurk in sources and only manifest themselves during _deployment_ of code. You can set PYTHONIOENCODING=ascii in the environment to force (a) to behave like (b), so that your code will fail whilst you're _developing_ it, rather than on your servers at midnight: [david at brick ~]$ PYTHONIOENCODING=ascii python -c 'print u"\u03b1\u03b2 \u03b3"' Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) (Given the above, it could be argued perhaps that one should never "print" unicode instances, and instead should write the data to file-like objects, specifying an encoding. Not sure). 6. If you're using pygtk (specifically the "pango" module, typically implicitly imported), be warned that it abuses the C API to set the default encoding inside python, which probably breaks any unicode instances in memory at the time, and is likely to cause weird side effects: [david at brick ~]$ python Python 2.6.2 (r262:71600, Jan 25 2010, 13:22:47) [GCC 4.4.2 20100121 (Red Hat 4.4.2-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getdefaultencoding() 'ascii' >>> import pango >>> sys.getdefaultencoding() 'utf-8' (the above is on Fedora 12, though I'd expect to see the same weirdness on any linux distro running gnome 2) Python 3 will probably make this all much easier; you'll still have to care about encodings when dealing with files/sockets/etc, but it should be much more clear what's going on. I hope. Hope this is helpful Dave From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 18:11:10 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 23:11:10 GMT Subject: Modifying Class Object References: Message-ID: On Wed, 10 Feb 2010 23:02:27 +0100, Alf P. Steinbach wrote: > For a less likely more technical interpretation, as far as I know in > Python there's just one case of a pointer that does not point to > anything, namely as exemplified by > > def foo(): > print( x ) > x = "whatever" > > The Java equivalent would say "NullPointerException", in Python it says > something like "unbound". Which means the same. Not in plain language. NullPointerException means that x is assigned to a null pointer, and you have tried to follow that pointer. Unbound means that x has nothing assigned to it. Semantically, the difference is somewhat analogous to the situations: "the president is dead, and a new president hasn't yet been appointed" (the office of the president is currently assigned to a dead guy) versus "the king has dissolved parliament and with it the office of president" (there is no president at all) Now, of course we understand that in the implementation of CPython, local variables are stored efficiently in slots in an array, and you can't have empty slots: every address always has some bit pattern. It is very likely that the CPython implementation uses a nil pointer to indicate an empty slot just like Java does. The difference is that Java exposes that implementation decision as part of the language specification, while Python deliberately does not. It isn't an accident that the Python exception describes the *semantics* of the error (x is not bound to any value) rather than the implementation detail (the slot known as x has a nil pointer in it). Semantically, the Python language treats the slot as empty and leaves the details of how the implementation recognises empty slots as an implementation decision. I'm just as interested by the implementation decisions made in CPython as the next guy, but they don't effect the semantics of the high level Python language. Here is a thought experiment for you: One can imagine an implementation of Python that eschews all pointers for some scheme by which objects are cleverly copied and synchronized as needed. Such an implementation would still be Python, but it would be entirely pointer-free. -- Steven From pengyu.ut at gmail.com Wed Feb 10 18:23:42 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 10 Feb 2010 15:23:42 -0800 (PST) Subject: Is a merge interval function available? Message-ID: I'm wondering there is already a function in python library that can merge intervals. For example, if I have the following intervals ('[' and ']' means closed interval as in http://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_endpoints) [1, 3] [2, 9] [10,13] [11,12] I want to get the following merged intervals. [1,9] [10,13] Could somebody let me know if there is a function in the python library? From alfps at start.no Wed Feb 10 18:34:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 00:34:05 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 23:02:27 +0100, Alf P. Steinbach wrote: > >> For a less likely more technical interpretation, as far as I know in >> Python there's just one case of a pointer that does not point to >> anything, namely as exemplified by >> >> def foo(): >> print( x ) >> x = "whatever" >> >> The Java equivalent would say "NullPointerException", in Python it says >> something like "unbound". Which means the same. > > Not in plain language. NullPointerException means that x is assigned to a > null pointer, and you have tried to follow that pointer. Unbound means > that x has nothing assigned to it. No, it's the same. String x; somethingIDontRememberProbablyIo.println( x ) // Java equivalent It's just different terminology, "NullPointerException" versus "unbound". It's the same semantics. Nothing substantial is changed by changing the Java message or changing the Python message. The word is just a word. > Semantically, the difference is > somewhat analogous to the situations: > > "the president is dead, and a new president hasn't yet been appointed" > (the office of the president is currently assigned to a dead guy) > > versus > > "the king has dissolved parliament and with it the office of president" > (there is no president at all) > > Now, of course we understand that in the implementation of CPython, local > variables are stored efficiently in slots in an array, and you can't have > empty slots: every address always has some bit pattern. It is very likely > that the CPython implementation uses a nil pointer to indicate an empty > slot just like Java does. The difference is that Java exposes that > implementation decision as part of the language specification, while > Python deliberately does not. How a Python implementation implements local variables is irrelevant, except that since references to local variables can be copied and *live on*, be used, after a call, it has to work as if it uses implementation level pointers. The notion of pointers (references) at the language level is not the same as the notion of pointers at the implementation level. This is the same as the notion of integers at the Python 3.x level (unbounded values) is not the same as the notion of integers at the C or C# or Java level (depending on the Python implementation, bounded values with wrap-around or undefined behavior). I.e. you're conflating two levels here. You can perhaps more easily see that by considering an implementation of Python in Python, using some computed counter as object id's. It doesn't change the user view of copyable references. But it hides all that C pointer stuff two or three abstraction levels down so that it becomes meaningless to talk about it. > It isn't an accident that the Python exception describes the *semantics* > of the error (x is not bound to any value) rather than the implementation > detail (the slot known as x has a nil pointer in it). Semantically, the > Python language treats the slot as empty and leaves the details of how > the implementation recognises empty slots as an implementation decision. > > I'm just as interested by the implementation decisions made in CPython as > the next guy, but they don't effect the semantics of the high level > Python language. Right. > Here is a thought experiment for you: > > One can imagine an implementation of Python that eschews all pointers for > some scheme by which objects are cleverly copied and synchronized as > needed. Such an implementation would still be Python, but it would be > entirely pointer-free. Uhm, bad example (it wouldn't work exactly as described), but concerning what I think you're trying to /communicate/, that X at the Python level is not the same as X at the implementation level, like, 'int' at the Python 3.x level is not 'int' in C, and like, "pointer" at the Python level is not "pointer" in C: yes. Cheers & hth., - Alf From rhodri at wildebst.demon.co.uk Wed Feb 10 18:35:19 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 10 Feb 2010 23:35:19 -0000 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> Message-ID: On Tue, 09 Feb 2010 07:35:51 -0000, Gary Herron wrote: > spike wrote: >> On Feb 8, 1:35 pm, Gary Herron wrote: >> >>> spike wrote: >>> >>>> Has anyone been able to come across a Python logic map or Python logic >>>> flow chart? >>>> An example can be seen on the right under History: >>>> http://en.wikipedia.org/wiki/Usenet#History >>>> This would be very helpful for all users. >>>> >>> Huh??? What aspect of Python were you thinking of mapping out? >>> >>> Your example us a bad ascii art graph of -- I've no clue what? >>> >>> Gary Herron >>> >> >> Do you know what "Logic" means? Guess not. Before you comedians quit >> your day job some people are looking for information. If you have >> nothing positive to say, go pester somewhere else. >> >> Grow up. >> > > Why the attitude? I wouldn't have asked for a clarification if I didn't > want to help. However, I seriously have *no* idea what the OP has asked > for when he says "Python logic map". Do you? If so, then answer the > poor guy's question instead of whining at me. (And I'll respectfully > read your answer, just to see how you interpret "Python logic map".) Er, Gary, that *is* the OP. He's just much better at being peeved than at clearly explaining what he wants. And sorry, but I have no idea what Python logic maps or Python logic flow charts either, or even what a inter-network connectivity diagram might have to do with them. An expansion of the original question is definitely in order. -- Rhodri James *-* Wildebeeste Herder to the Masses From wayne.dads.bell at gmail.com Wed Feb 10 19:16:23 2010 From: wayne.dads.bell at gmail.com (dads) Date: Wed, 10 Feb 2010 16:16:23 -0800 (PST) Subject: sqlite3 bug? Message-ID: When the method below is run it raises 'sqlite3.OperationalError: no such table: dave'. the arguments are ds = a datestamp and w = a string of digits. The path of the db is C:\sv_zip_test\2006\2006.db and the table is definitely named dave. I've run the sql in sql manager and it works. Is this a bug? def findArchive(self, ds, w): year = ds.GetYear() if year < 2005: wx.MessageBox('Year out of Archive, check the date!') return year = str(year) archive = 'C:/sv_zip_test' dbfp = os.path.abspath(os.path.join(archive, year, year + '.db')) if os.path.exists(dbfp): con = sqlite3.connect('dbfp') cur = con.cursor() #cur.execute("SELECT * FROM dave WHERE webno = ?", [w]) cur.execute("SELECT * FROM dave") for r in cur: self.fil.AppendText(r[2] + '\n') else: wx.MessageBox('no db, %s' % dbfp) From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 19:26:40 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Feb 2010 00:26:40 GMT Subject: Is a merge interval function available? References: Message-ID: On Wed, 10 Feb 2010 15:23:42 -0800, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. For example, if I have the following intervals ('[' and > ']' means closed interval as in > http://en.wikipedia.org/wiki/Interval_(mathematics) #Excluding_the_endpoints) Not in the standard library. There may be third-party libraries that do it. Did you google "python interval"? -- Steven From python.list at tim.thechases.com Wed Feb 10 19:38:13 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 18:38:13 -0600 Subject: sqlite3 bug? In-Reply-To: References: Message-ID: <4B735175.9020704@tim.thechases.com> dads wrote: > When the method below is run it raises 'sqlite3.OperationalError: no > such table: dave'. > the arguments are ds = a datestamp and w = a string of digits. The > path of the db is > C:\sv_zip_test\2006\2006.db and the table is definitely named dave. > I've run the sql > in sql manager and it works. Is this a bug? > > dbfp = os.path.abspath(os.path.join(archive, year, year + '.db')) > if os.path.exists(dbfp): > con = sqlite3.connect('dbfp') did you mean connect(dbfp) instead of connect('dbfp') ? -tkc From list-sink at trainedmonkeystudios.org Wed Feb 10 19:44:13 2010 From: list-sink at trainedmonkeystudios.org (Terrence Cole) Date: Wed, 10 Feb 2010 16:44:13 -0800 Subject: Bizarre arithmetic results Message-ID: <1265849053.24800.38.camel@localhost> Can someone explain to me what python is doing here? Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -0.1 ** 0.1 -0.7943282347242815 >>> a = -0.1; b = 0.1 >>> a ** b (0.7554510437117542+0.2454609236416552j) >>> -abs(a ** b) -0.7943282347242815 Why does the literal version return the signed magnitude and the variable version return a complex? Cheers, Terrence From davidism at gmail.com Wed Feb 10 19:48:39 2010 From: davidism at gmail.com (David) Date: Wed, 10 Feb 2010 16:48:39 -0800 (PST) Subject: Get __doc__ from main module in imported module. Message-ID: I have a module toolkit.py with some functions I use often. One of these functions displays a usage message (__doc__). def usage(messages=[], exit=-1): """Print the doc string as wells as any useful messages.""" print(__doc__) for message in messages: print("\033[91m{}\033[0m".format(message)) if exit >= 0: sys.exit(exit) I import this module into another module, with the doc string I want to display. However, calling usage prints toolkit's doc string (None), not the current module's doc string. How can I access the top level module's doc string from toolkit? From no.email at please.post Wed Feb 10 19:50:50 2010 From: no.email at please.post (kj) Date: Thu, 11 Feb 2010 00:50:50 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: In Duncan Booth writes: >kj wrote: >> But to ground >> the problem a bit I'll say that the exception above happens during >> the execution of a statement of the form: >> >> x = '%s %s' % (y, z) >> >> Also, I found that, with the exact same values y and z as above, >> all of the following statements work perfectly fine: >> >> x = '%s' % y >> x = '%s' % z >> print y >> print z >> print y, z >> >One of y or z is unicode, the other is str. Yes, that was the root of the problem. >1. Print the repr of each value so you can see which is which. Thanks for pointing out repr; it's really useful when dealing with Unicode headaches. Thanks for all the replies! ~K From ahleniusm at gmail.com Wed Feb 10 20:17:17 2010 From: ahleniusm at gmail.com (m_ahlenius) Date: Wed, 10 Feb 2010 17:17:17 -0800 (PST) Subject: question on storing dates in a tuple Message-ID: Hi, I have a weird question about tuples. I am getting some dates from a mysql db, using the mysqldb interface. I am doing a standard query with several of the fields are "datetime" format in mysql. When I retrieve and print them in python, they look fine. eg. storeddate = 2010-02-07 12:03:41 But when I append these dates into a string to write to an ascii log file, they come out as: datetime.datetime(2010, 2, 7, 12, 03, 41) (or something along those lines). It appears that I am dealing with some sort of date object here. So I am just trying to understand what's going on, and whats the best work with such objects. thanks 'mark From skippy.hammond at gmail.com Wed Feb 10 20:24:30 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 11 Feb 2010 12:24:30 +1100 Subject: strange issue with C extension using Py_BuildValue In-Reply-To: References: Message-ID: <4B735C4E.3040408@gmail.com> On 11/02/2010 9:19 AM, bobicanprogram wrote: > I'm am having "strange" problems with the code snip below. > > When this code is built on a 64bit Linux, it would appear to work > flawlessly. When the source is rebuilt on a 32bit Linux it begins > to crack in strange ways. The issue seems to be associated with the > sender field in the Py_BuildValue call. The fact that sender is a > pointer should mean that its value is an unsigned integer. However, > on the 32 bit build the failure is that the msgPtr->data value is > "messed up". If the format associated with the sender (a pointer) > from "L" to "i" things work on the 32 bit side but break on the 64 bit > side. I expect that in a 32bit build of linux, a "long long" (the 'L' format) is still 64 bits. You probably want something like: Py_BuildValue("iNz#", ret, PyLong_FromVoidPtr(sender), &msgPtr->data, ret); and PyLong_AsVoidPtr() for the other direction. HTH, Mark From mludvig at logix.net.nz Wed Feb 10 20:25:10 2010 From: mludvig at logix.net.nz (Michal Ludvig) Date: Thu, 11 Feb 2010 14:25:10 +1300 Subject: ignoring some placeholders in string formatting Message-ID: <4B735C76.9040505@logix.net.nz> Hi all, when I've got a string, say: URL="http://xyz/blah?session=%(session)s&message=%(message)s" is it possible to fill in only 'session' and leave "%(message)s" as is when it isn't present in the values dict? For example: URL % { 'session' : 123 } raises KeyError because of missing 'message' in the dict. I could indeed replace '%(session)s' with a string replace or regexp but that's not very elegant ;-) Is there any way to tell the formatter to use only what's available and ignore the rest? Thanks Michal From clp2 at rebertia.com Wed Feb 10 20:30:52 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Feb 2010 17:30:52 -0800 Subject: question on storing dates in a tuple In-Reply-To: References: Message-ID: <50697b2c1002101730t60532036i3ef4a853d10c2d9f@mail.gmail.com> On Wed, Feb 10, 2010 at 5:17 PM, m_ahlenius wrote: > Hi, > > I have a weird question about tuples. ?I am getting some dates from a > mysql db, using the mysqldb interface. ?I am doing a standard query > with several of the fields are "datetime" format in mysql. > When I retrieve and print them in python, they look fine. > > eg. > storeddate = 2010-02-07 12:03:41 > > But when I append these dates ?into a string to write to an ascii ?log > file, they come out as: > > datetime.datetime(2010, 2, 7, 12, 03, 41) ? ?(or something along those > lines). > > It appears that I am dealing with some sort of date object here. ? So > I am just trying to understand what's going on, and whats the best > work with such objects. http://docs.python.org/library/datetime.html#datetime.datetime >>> from datetime import datetime >>> now = datetime.now() >>> print str(now) 2010-02-10 17:22:12.459277 >>> print repr(now) datetime.datetime(2010, 2, 10, 17, 22, 12, 459277) >>> print (now,) (datetime.datetime(2010, 2, 10, 17, 22, 12, 459277),) tuples use repr() on their elements when they're converted to strings, and repr() on datetime-s uses the constructor notation as opposed to the more normal notation used by str(). Same sort of thing happens with strings; note the presence/lack of quotes: >>> string = "aa" >>> print str(string) aa >>> print repr(string) 'aa' >>> print (string,) ('aa',) Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Wed Feb 10 20:31:37 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 02:31:37 +0100 Subject: Get __doc__ from main module in imported module. In-Reply-To: References: Message-ID: * David: > I have a module toolkit.py with some functions I use often. One of > these functions displays a usage message (__doc__). > > def usage(messages=[], exit=-1): > """Print the doc string as wells as any useful messages.""" > print(__doc__) > for message in messages: > print("\033[91m{}\033[0m".format(message)) Consider using a terminal control library such as 'curses' instead of embedding escape sequences directly in the text, since escape sequences vary from terminal to terminal. > if exit >= 0: > sys.exit(exit) > > I import this module into another module, with the doc string I want > to display. However, calling usage prints toolkit's doc string > (None), not the current module's doc string. The function doesn't know where it's called from. You have to tell it, or dynamically create a module-specific function. One way to tell it is to pass the current module as an argument. > How can I access the top level module's doc string from toolkit? Like import __main__ print_usage( __main__ ) with suitable definition of 'usage'. Cheers & hth., - Alf From rhodri at wildebst.demon.co.uk Wed Feb 10 20:36:11 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Feb 2010 01:36:11 -0000 Subject: question on storing dates in a tuple References: Message-ID: On Thu, 11 Feb 2010 01:17:17 -0000, m_ahlenius wrote: > Hi, > > I have a weird question about tuples. I am getting some dates from a > mysql db, using the mysqldb interface. I am doing a standard query > with several of the fields are "datetime" format in mysql. > When I retrieve and print them in python, they look fine. > > eg. > storeddate = 2010-02-07 12:03:41 > > But when I append these dates into a string to write to an ascii log > file, they come out as: > > datetime.datetime(2010, 2, 7, 12, 03, 41) (or something along those > lines). > > It appears that I am dealing with some sort of date object here. So > I am just trying to understand what's going on, and whats the best > work with such objects. You're getting Python datetime objects: rhodri at gnudebst:~$ 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. >>> import datetime >>> now = datetime.datetime.today() >>> print str(now) 2010-02-11 01:30:03.749223 >>> print repr(now) datetime.datetime(2010, 2, 11, 1, 30, 3, 749223) See http://docs.python.org/library/datetime.html#datetime-objects for details of what you can do with them. In your case, you probably just want to use "str()" to explicitly convert the object into a string. -- Rhodri James *-* Wildebeeste Herder to the Masses From jeanmichel at sequans.com Wed Feb 10 20:36:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Feb 2010 02:36:15 +0100 Subject: SimpleXMLRPCServer and client address In-Reply-To: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> Message-ID: <4B735F0F.6080503@sequans.com> Jordan Apgar wrote: > I'm trying to right a server that needs specific information for each > client accessing it. The easiest way I could think of doing this is > keeping this information based on ip address (the information is only > valid for a short time). I know there is no was to get the client's > address directly and have seen a few examples of subclassing the > SimpleXMLRPCServer like this: > > class RPCServer(SimpleXMLRPCServer): > > def _dispatch(self, method, params): > """Extend dispatch, adding client info to some parameters.""" > if method in ({my list of methods I needed client address}): > return SimpleXMLRPCServer._dispatch(self, method, > params+(self.client_address,)) > return SimpleXMLRPCServer._dispatch(self, method, params); > > > but to be honest I don't understand what's going on there or how to > use it. Would anyone be able to explain this to me? > I don't know exactly what you are trying to do, but if your server requires informations from the client, it would be better to ask explicitly the client for those informations. For instance, if a method requires te client IP address, then the IP address is definitely a parameter of the method. JM From python.list at tim.thechases.com Wed Feb 10 20:53:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 19:53:44 -0600 Subject: ignoring some placeholders in string formatting In-Reply-To: <4B735C76.9040505@logix.net.nz> References: <4B735C76.9040505@logix.net.nz> Message-ID: <4B736328.806@tim.thechases.com> Michal Ludvig wrote: > URL="http://xyz/blah?session=%(session)s&message=%(message)s" > > is it possible to fill in only 'session' and leave "%(message)s" as is > when it isn't present in the values dict? > > For example: > URL % { 'session' : 123 } > raises KeyError because of missing 'message' in the dict. > > I could indeed replace '%(session)s' with a string replace or regexp but > that's not very elegant ;-) You can use a defaultdict instead of a regular dict: from collections import defaultdict d = defaultdict(str) d['session'] = 123 URL="http://xyz/blah?session=%(session)s&message=%(message)s" print URL % d -tkc From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 21:11:38 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Feb 2010 02:11:38 GMT Subject: ignoring some placeholders in string formatting References: Message-ID: On Thu, 11 Feb 2010 14:25:10 +1300, Michal Ludvig wrote: > Hi all, > > when I've got a string, say: > > URL="http://xyz/blah?session=%(session)s&message=%(message)s" > > is it possible to fill in only 'session' and leave "%(message)s" as is > when it isn't present in the values dict? No, but instead see string templates: http://docs.python.org/library/string.html#template-strings -- Steven From davidism at gmail.com Wed Feb 10 21:32:28 2010 From: davidism at gmail.com (David) Date: Wed, 10 Feb 2010 18:32:28 -0800 (PST) Subject: Get __doc__ from main module in imported module. References: Message-ID: <7775b9dd-7692-4f43-92b3-9c155e9c21ff@a17g2000pre.googlegroups.com> > > How can I access the top level module's doc string from toolkit? > > Like > > ? ? ?import __main__ > ? ? ?print_usage( __main__ ) > > with suitable definition of 'usage'. > > Cheers & hth., > > - Alf Problem solved! Thanks for the other tips too. From python at mrabarnett.plus.com Wed Feb 10 21:51:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 02:51:06 +0000 Subject: ignoring some placeholders in string formatting In-Reply-To: <4B735C76.9040505@logix.net.nz> References: <4B735C76.9040505@logix.net.nz> Message-ID: <4B73709A.8070201@mrabarnett.plus.com> Michal Ludvig wrote: > Hi all, > > when I've got a string, say: > > URL="http://xyz/blah?session=%(session)s&message=%(message)s" > > is it possible to fill in only 'session' and leave "%(message)s" as is > when it isn't present in the values dict? > > For example: > URL % { 'session' : 123 } > raises KeyError because of missing 'message' in the dict. > > I could indeed replace '%(session)s' with a string replace or regexp but > that's not very elegant ;-) > > Is there any way to tell the formatter to use only what's available and > ignore the rest? > You could write a class inheriting from dict which, for example, returns "%(key)s" if the key "key" is absent: >>> class IgnoreDict(dict): def __getitem__(self, key): try: return dict.__getitem__(self, key) except KeyError: return "%%(%s)s" % key >>> d = {'session': 123} >>> URL = "http://xyz/blah?session=%(session)s&message=%(message)s" >>> URL % d Traceback (most recent call last): File "", line 1, in URL % d KeyError: 'message' >>> URL % IgnoreDict(d) 'http://xyz/blah?session=123&message=%(message)s' From steve at holdenweb.com Wed Feb 10 21:51:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 21:51:42 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Ethan Furman: >> Steven D'Aprano wrote: >>> >>> Believe me Alf, the fact that people are taking the time to try to >>> argue with you instead of just kill-filing you is a compliment. >> >> It's a compliment I am not paying, although I am grateful to those who >> are attempting to teach him. At the rate it's going, though, I don't >> see myself buying any book he produces. >> >> Besides the arrogant attitude, he is wrong on so many things about >> Python it is truly stunning. > > That's bullshit. I am probably wrong about many Python things, for this > is so no matter the language and the practictioner, but not any that you > know about. > So your accomplishments include mind-reading now, and you understand everything that Stephen knows and does not know about? That's a startling and, I suggest, untenable claim. > >> He seems to have confidence born of ignorance... a scary sight to see. >> >> In the spirit of being helpful and not just being a jerk myself: >> >> Alf, >> >> Using smileys after declaring somebody is mistaken/wrong/etc makes you >> look bad. >> >> Not attempting to learn the language makes you look like an arrogant >> idiot (case in point: passing-by-object). >> >> Accusing anyone and everyone that criticizes you of making ad hominem >> (sp?) attacks makes you look like a whiner. >> >> After all is said and done - if you had a truly good grasp of Python, >> I might buy your book even if you still had -- ummm -- a less than >> winning presence on the mailing list; but right now your understanding >> is not worth paying for. >> >> Hoping-this-helps-but-not-really-expecting-it-to-ly yours, > > It's yet another ad hominem attack, which means that you're painfully > aware of supporting an untenable technical position, or supporting a > clique of people. > So now the whole thing boils down to "Alf against the world"? The reminds me of the story about the woman who went to see her son qualify from his basic army training. When asked what she thought of the parade she said it was very nice, but that "everyone but our Alf was out of step". I am unsure at this stage what it would take to convince you that you are not only wrong about several important aspects of Python but also wrong-headed. Whenever anyone points out any aspect of your behavior which is unacceptable or ignorant you trot out this accusation that people are making "ad hominem attacks" as though commenting on aspects of your personality is an attempt to undermine your arguments. It isn't. The two are orthogonal. Your arguments are wrong *and* you are behaving like a pratt. A change in either one of these aspects would improve matters, but each seems as unlikely as the other. > It also reflects rather badly on you. Sigh. We're all out of step again, obviously. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From kirby.urner at gmail.com Wed Feb 10 22:10:42 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 10 Feb 2010 19:10:42 -0800 (PST) Subject: FWD: Lore about Division Message-ID: <47257550-587f-4ae6-b909-655a3dff1024@k18g2000prf.googlegroups.com> Alan: 2^(1/2) Kirby: Also pow(2, 0.5) in Python. Alan: Gee, I wonder if pow(2, (1/2)) also works in Python? Kirby: It does if you remember integer division in earlier versions, such that one needed: from __future__ import division or, simply made it 1./2 or 1/2. or something, to force a floating point answer. In 3.x, division is natively floating, with // to force an integer output. [ EDITOR'S NOTE: not quite right, may be floating type output with integer value ] This is Python 3.1, right out of the box: >>> pow(2, 1/2) 1.4142135623730951 Alan: That reminds me of FORTRAN http://en.wikipedia.org/wiki/Fortran_language_features#Implicit_and_explicit_typing "Unless specified otherwise, all variables starting with letters I, J, K, L, M and N are default INTEGER, and all others are default REAL; other data types must be explicitly declared. This is known as implicit typing and is a heritage of early FORTRAN days." Kirby: I think the original intent was something like "closure" i.e. int / int should give int, whereas float / float or float / int or int / float should coerce float answer, and that is how it was done. However it was later realized, by Guido and others, that in source code, when you see a / b, you really have no way of knowing what's going through there, i.e. a and b might name anything, so it gets hard to debug if the behavior is so dependent on 1 versus 3 use cases. Better to just have a consistent float output, no matter what. Then use // if you want to force an integer value output, even if you input floats to get floats back: >>> 1.//2. 0.0 >>> 1/2 0.5 >>> 3.//2. 1.0 It's quite basic to a language, how it deals with division, so Guido had to devise a scheme that would let the snake "shed its skin". Already, the brand name (Python) was in his favor, as that's what Pythons do (shed skin). A lot of basic changes piled up, including a more complete move to a Unicode basis for source files. If you're going to break backward compatibility, might as well do a lot of breaking all at once. As of this writing, we're on the other end of it, having made the leap from 2.x to 3.x. The backward incompatibility gap has been crossed. However, a number of important libraries and other assets still need to bring up the rear, so a new PEP (Python Enhancement Proposal) has been accepted, to freeze Python for awhile, in terms of its core syntax and semantics. Give the library people some breathing room. This seems a good plan. [ original context: http://groups.yahoo.com/group/synergeo/ ] From wuwei23 at gmail.com Wed Feb 10 22:22:27 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Feb 2010 19:22:27 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <6da47c86-b533-4d54-8b8a-d68feb2c4101@v20g2000prb.googlegroups.com> catonano wrote: > You know what I'm doing now ? I'm drawing the map of > twisted.web.client on a paper with a pencil :-( You're a programmer. Why are you complaining about the problem instead of endeavouring to solve it? From tjreedy at udel.edu Wed Feb 10 22:25:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Feb 2010 22:25:00 -0500 Subject: Function attributes In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: On 2/10/2010 4:49 PM, Gabriel Genellina wrote: > I've written a decorator for "injecting" a __function__ name into the > function namespace, but I can't find it anywhere. I think I implemented > it by adding a fake additional argument and replacing LOAD_GLOBAL with > LOAD_NAME in the bytecode. The decorator only needs to replace the defaults args tuple. It does not even need to know the parameter name, just that it is the only (or last) with a default . def f(n, me=None): if n > 0: return n*me(n-1) elif n==0: return 1 f.__defaults__ = (f,) # 3.1 print(f(5)) # 120 To generalize: def g(a,b=1,me=None): if a: return me(0) else: return 41+b g.__defaults__ = g.__defaults__[:len(g.__defaults__)-1] + (g,) print(g(3)) #42 Of course, user could still screw up recursion by providing another value for 'me'. This strikes me as about a likely (low) as a user screwing up recursion in a library module function by rebinding the name in the imported module. Terry Jan Reedy From alfps at start.no Wed Feb 10 22:36:51 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 04:36:51 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steve Holden: > > So now the whole thing boils down to "Alf against the world"? The > reminds me of the story about the woman who went to see her son qualify > from his basic army training. When asked what she thought of the parade > she said it was very nice, but that "everyone but our Alf was out of step". Considering your frequent ad hominem attacks (and this is yet one more), you seem to think that social coercion works well for establishing engineering solutions or scientific truth. That's a misconception. Social matters and matters of engineering or science are different things. > I am unsure at this stage what it would take to convince you that you > are not only wrong about several important aspects of Python but also > wrong-headed. You might start by starting a thread about one such thing; I'll correct you if you're wrong about something I know, or if you demonstrate that I'm wrong about something, then I'll be happy to learn something, as always. It would be a nice change from your extreme focus on my person, if you could manage to discuss something technical. > Whenever anyone points out any aspect of your behavior > which is unacceptable or ignorant you trot out this accusation that > people are making "ad hominem attacks" as though commenting on aspects > of your personality is an attempt to undermine your arguments. That's an ad hominem attack, albeit a pretty silly one. Your behavior, with ad hominem, coercion, insinuations, misrepresentations and so forth the basic ingredients, is completely unacceptable to me, by the way. It's like a bully in the schoolyard. > It isn't. The two are orthogonal. Your arguments are wrong *and* you are > behaving like a pratt. A change in either one of these aspects would > improve matters, but each seems as unlikely as the other. > >> It also reflects rather badly on you. > > Sigh. We're all out of step again, obviously. If you had any argument that held regarding the technical, then I think you (and I mean the singular you) would have tried it by now. But instead, you engage in this bullying behavior. Cheers, - Alf From nobody at nowhere.com Wed Feb 10 22:37:06 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 11 Feb 2010 03:37:06 +0000 Subject: A silly question on file opening References: Message-ID: On Wed, 10 Feb 2010 21:23:08 +0000, Steven D'Aprano wrote: > The solution to this is to remember that Windows accepts forward slashes > as well as backslashes, and always use the forward slash. So try: > > open("D:/file") > > and see if that works. The solution is not to hard-code pathnames in your source file. Read the base directory from an environment variable, registry key, or configuration file, and use os.path.join() to construct paths relative to that directory. On Unix, there are situations which require hard-coding pathnames, e.g. the path to the package's system-wide configuration file. But on Windows, there isn't a single directory whose name is fixed. "Windows" isn't guaranteed to be on "C:", and the other standard directories typically have names which vary by language. Hard-coding "Program Files" is a quick way to guarantee that your software won't work on systems using a language other than English. From lanyjie at yahoo.com Wed Feb 10 22:40:54 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Feb 2010 19:40:54 -0800 (PST) Subject: expy 0.6 released Message-ID: <155225.21818.qm@web54203.mail.re2.yahoo.com> Hi: EXPY (http://expy.sourceforge.net/) is an express way to extend Python. Why consider expy? Here are some good reasons: (I). WYSIWYG. The expy project enables you to write your module in Python the way your extension would be (WYSIWYG), and meanwhile write your implementation in pure C. You specify your modules, functions, methods, classes, and even their documentations the usual way of writing your Python correspondences. Then provide your implementation to the functions/methods by returning a multi-line string. By such an arrangement, everything falls in its right place, and your extension code becomes easy to read and maintain. Also, the generated code is very human-friendly. (II). You only provide minimal information to indicate your intension of how your module/class would function in Python. So your extension is largely independent from the Python extension API. As your interaction with the Python extension API is reduced to minimal (you only care about the functionality and logic), it is then possible that your module written in expy can be independent of changes in the extension API. (III). The building and setup of your project can be automatically done with the distutil tool. In the tutorial, there are ample examples on how easily this is achieved. (IV). Very light weight. The expy tool is surprisingly light weight dispite of its powerful ability, as it is written in pure Python. There is no parser or compiler for code generation, but rather the powerful reflexion mechanism of Python is exploited in a clever way to generate human-friendly codes. Currently, generating code in C is supported, however, the implementation is well modularized and code generation in other languages such as Java and C++ should be easy. Currently, EXPY/CXPY works with Python 2.5, 2.6. I haven?t tested with Python 2.7 or 3.x (for 3.x, need to use the code tool first, and I am not sure if the C API for 3.x has changed much, if you happen to try it out, let me know what happened). While there are already a couple of other projects trying to simply this task with different strategies, such as Cython, Pyrex and modulator, this project is unique and charming in its own way. All you need is the WYSIWYG Python file for your module extension, then expy takes care of everything else. What follows in this documentation is on how to extend Python in C using expy-cxpy: the module expy helps define your module, while module cxpy helps generate C codes for your defined module. Yingjie From nobody at nowhere.com Wed Feb 10 22:48:05 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 11 Feb 2010 03:48:05 +0000 Subject: Is a merge interval function available? References: Message-ID: On Wed, 10 Feb 2010 15:23:42 -0800, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. For example, if I have the following intervals ('[' > and ']' means closed interval as in > http://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_endpoints) > > [1, 3] > [2, 9] > [10,13] > [11,12] > > I want to get the following merged intervals. > > [1,9] > [10,13] > > Could somebody let me know if there is a function in the python > library? No, but try this: def merge(intervals): if not intervals: return [] intervals = sorted(intervals, key = lambda x: x[0]) result = [] (a, b) = intervals[0] for (x, y) in intervals[1:]: if x <= b: b = max(b, y) else: result.append((a, b)) (a, b) = (x, y) result.append((a, b)) return result From steve at holdenweb.com Wed Feb 10 22:49:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 22:49:15 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: > [snip] >>> >>> Since in the quoting above no reference to definition of "pointer" >>> remains: "pointer" refers to a copyable reference value as seen from the >>> Python level, in the same way as "pointer" is used by e.g. the Java >>> language spec. >>> > [snip] >>> >>> If so, then that's correct: a Python (or Java, or whatever language) >>> pointer is not necessarily directly a memory address, and furthermore id >>> is not guaranteed to reproduce the bits of a pointer value -- which >>> might not even make sense. >>> >>> All that id does is to produce a value that uniquely identifies the >>> object pointed to, i.e. it corresponds to the pointer value, and >>> although in CPython that's simply the bits of a C pointer typed as >>> integer, in IronPython it's not. >>> >> You go too far here. What you are referring to in your bizarrely >> constructed definition above > > No, it's not bizarre, it's the standard general language independent > definition. > *The* standard general language independent definition? As defined where? The id() value doesn't "correspond to the pointer value", it corresponds to the object. Why you see the need for this indirection remains a mystery. > And since I'm referring to an external definition (Java) it's not mine, > either. :-) > > >> as a pointer does not allow you to access >> the value that is "pointed to". So I fail to see why you feel its its >> introduction is necessary. > > Python provides a number of ways to access the object pointed to. > > Attribute access, indexing, and operators access the objects pointed to. No, they access the objects. In the IronPython implementation, for example, it has already been shown quite clearly that the id value is simply an attribute of the object, whose values are incremented by one for each new object. > > For example, > > x = s[0] > > accesses the object that s points (refers) to. It accesses (the first element of) the object bound to the name "s". > > While 'is', 'id' and assignment operate on the pointers (references) > themselves. > The 'is' operator is a simple test for equality of ids of the objects resulting from the evaluation of two expressions. The expressions can be literals, simple names, or any other valid Python expression. They are *not* pointers, or references. id() simply returns a unique value identifying a particular object. In CPython, where objects do not migrate in memory once created, the memory address of the object is used. In IronPython each object is assigned an id when it is created, and that value is stored as an attribute. > So there's one set of language features that operate on pointers, and > one set of language features that operate on the pointed to objects. > This is so also in Java and C#. For example. > > >> Whether in CPython, Jython or IronPython the value returned by calling >> id(x) (whether x is a literal, a simple name or a more complex >> expression) is absolutely no use as an accessor: it does not give you >> access to the referenced value. > > Yes, the id does not give you access to the referenced object. > Well at least we have found one aspect of Python we agree on. > >> If you disagree, please write (in any implementation you like: it need >> not even be portable, though I can't imagine why ti wouldn't be) a >> Python function which takes an id() value as its argument and returns >> the value for which the id() value was provided. > > No, I don't disagree with that. > Good. > It would be excessively inefficient to do, involving enumeration of all > objects. > > >> So in your world it's unnecessary for pointers to point to anything (or >> references to refer to something)? For someone who cheerfully admits to >> being wrong from time to time (an admirable characteristic) you are >> certainly difficult to convince on this point. One wonders what further >> hand-waving will follow. > > He he, "further" handwaiving: you're good at unsubstantiated allegations. > I am simply pointing out that to make your point you are relying on abstractions which increasingly diverge from the reality of the Python language. I don't think it's unreasonable to describe that as "hand-waving". You apparently do. > I generally strive to provide concrete examples, and you know it. > Again with the mind-reading: you appear to have convinced yourself that you are an authority on what I know. > Anywyay, treating the first sentence as a genuine question: in the most > likely interpretation it seems that you're conflating id's with > pointers. An id() value uniquely represents a pointer (i.e., the > identity of the object pointed to). It is not itself a pointer since it > lack any pointer semantics. > No, it doesn't uniquely represent a pointer, it uniquely represents an *object*. > For a less likely more technical interpretation, as far as I know in > Python there's just one case of a pointer that does not point to > anything, namely as exemplified by > > def foo(): > print( x ) > x = "whatever" > > The Java equivalent would say "NullPointerException", in Python it says > something like "unbound". Which means the same. > Be careful when comparing static and dynamic languages. Java, being a static language, has no equivalent to Python's NameError and AttributeError, which both represent situations in which no object has been bound to a name. In those cases it isn't that the name exists and is bound to a "null pointer", it's simply that the name doesn't exist. So there is no "copyable reference value". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Wed Feb 10 22:56:49 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 19:56:49 -0800 Subject: SimpleXMLRPCServer and client address In-Reply-To: <4B735F0F.6080503@sequans.com> References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> <4B735F0F.6080503@sequans.com> Message-ID: <7a9c25c21002101956x1298f01euc40285c2227a0598@mail.gmail.com> On Wed, Feb 10, 2010 at 5:36 PM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > I don't know exactly what you are trying to do, but if your server requires > informations from the client, it would be better to ask explicitly the > client for those informations. > For instance, if a method requires te client IP address, then the IP > address is definitely a parameter of the method. > I can't answer the OP, as I don't know the answer to his specific question-- but er, asking a client to provide one's IP address is not really a very workable solution. There's no way to really determine your own IP address in a reliable way. All the usual methods (e.g., socket.gethostbyname(socket.gethostname())) can fail and/or be wrong in some not terribly uncommon situations. The only reliable way to get such a piece of information is to connect to a server, and ask that server what address you were connecting to them as. Even then, that IP may not be the same as an IP you use to connect to say, a different server (on a different network) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 10 23:03:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 23:03:29 -0500 Subject: Is a merge interval function available? In-Reply-To: References: Message-ID: Nobody wrote: > On Wed, 10 Feb 2010 15:23:42 -0800, Peng Yu wrote: > >> I'm wondering there is already a function in python library that can >> merge intervals. For example, if I have the following intervals ('[' >> and ']' means closed interval as in >> http://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_endpoints) >> >> [1, 3] >> [2, 9] >> [10,13] >> [11,12] >> >> I want to get the following merged intervals. >> >> [1,9] >> [10,13] >> >> Could somebody let me know if there is a function in the python >> library? > > No, but try this: > > def merge(intervals): > if not intervals: > return [] > intervals = sorted(intervals, key = lambda x: x[0]) Since Python uses lexical sorting and the intervals are lists isn't the key specification redundant here? > result = [] > (a, b) = intervals[0] > for (x, y) in intervals[1:]: > if x <= b: > b = max(b, y) > else: > result.append((a, b)) > (a, b) = (x, y) > result.append((a, b)) > return result > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Wed Feb 10 23:13:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 20:13:17 -0800 Subject: Modifying Class Object In-Reply-To: References: Message-ID: <7a9c25c21002102013l4a5eb26ay2f684b8e1ba35256@mail.gmail.com> On Wed, Feb 10, 2010 at 7:49 PM, Steve Holden wrote: > *The* standard general language independent definition? As defined where? > Wait, what happened here? This thread started a couple days ago; you pointed out its futility, and even knowing better, I jumped in the deep end. When I realized the futility, you rightly I-told-you-so'd me. You didn't have to pick up my slack ;) On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden wrote: > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 10 23:19:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 23:19:52 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> >> So now the whole thing boils down to "Alf against the world"? The >> reminds me of the story about the woman who went to see her son qualify >> from his basic army training. When asked what she thought of the parade >> she said it was very nice, but that "everyone but our Alf was out of >> step". > > Considering your frequent ad hominem attacks (and this is yet one more), > you seem to think that social coercion works well for establishing > engineering solutions or scientific truth. > > That's a misconception. > So now I understand neither engineering nor science? I find that assertion offensive, though unsurprising. > Social matters and matters of engineering or science are different things. > I am hardly ignorant of that, as you should know from my many past writings on both aspects of Python usage. You are attempting to teach your grandmother to suck eggs. > >> I am unsure at this stage what it would take to convince you that you >> are not only wrong about several important aspects of Python but also >> wrong-headed. > > You might start by starting a thread about one such thing; I'll correct > you if you're wrong about something I know, or if you demonstrate that > I'm wrong about something, then I'll be happy to learn something, as > always. > > It would be a nice change from your extreme focus on my person, if you > could manage to discuss something technical. > See below. > >> Whenever anyone points out any aspect of your behavior >> which is unacceptable or ignorant you trot out this accusation that >> people are making "ad hominem attacks" as though commenting on aspects >> of your personality is an attempt to undermine your arguments. > > That's an ad hominem attack, albeit a pretty silly one. > [facepalm] > Your behavior, with ad hominem, coercion, insinuations, > misrepresentations and so forth the basic ingredients, is completely > unacceptable to me, by the way. > > It's like a bully in the schoolyard. > I am attempting to persuade, not to coerce. > >> It isn't. The two are orthogonal. Your arguments are wrong *and* you are >> behaving like a pratt. A change in either one of these aspects would >> improve matters, but each seems as unlikely as the other. >> >>> It also reflects rather badly on you. >> >> Sigh. We're all out of step again, obviously. > > If you had any argument that held regarding the technical, then I think > you (and I mean the singular you) would have tried it by now. > > But instead, you engage in this bullying behavior. > My (technical) views on your insistence that Python's semantics require the use of pointers to explain them is ongoing elsewhere, and remains open for you to refute. In this particular part of the thread I am attempting, unsuccessfully, to convince you that a change in *your* behavior would lead to less hostility directed towards the way you present your ideas. You apparently feel it is quite acceptable to tell people to "learn to read", and calling their assertions "bullshit", but when we try to point out aspects of your behavior that are either undesirable or unacceptable we are indulging in "ad hominem attacks". In your terms, your accusing me of bullying behavior is an ad hominem attack on me, so I won't bother to respond further. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 10 23:21:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 23:21:08 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002102013l4a5eb26ay2f684b8e1ba35256@mail.gmail.com> References: <7a9c25c21002102013l4a5eb26ay2f684b8e1ba35256@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Wed, Feb 10, 2010 at 7:49 PM, Steve Holden > wrote: > > *The* standard general language independent definition? As > defined where? > > > Wait, what happened here? > > This thread started a couple days ago; you pointed out its futility, and > even knowing better, I jumped in the deep end. When I realized the > futility, you rightly I-told-you-so'd me. > > You didn't have to pick up my slack ;) > > On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden > wrote: > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." Yes, but someone on the Internet is wrong, dammit, I can't go to bed yet. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From daniel at stutzbachenterprises.com Wed Feb 10 23:27:30 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 10 Feb 2010 22:27:30 -0600 Subject: Is a merge interval function available? In-Reply-To: References: Message-ID: On Wed, Feb 10, 2010 at 5:23 PM, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. > Not in the standard library, but this package may help: http://pypi.python.org/pypi/interval -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken at seehart.com Wed Feb 10 23:42:25 2010 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Feb 2010 20:42:25 -0800 Subject: regex to match python string literal syntax Message-ID: <4B738AB1.2030702@seehart.com> I found this: http://code.activestate.com/recipes/475109/ But it is incorrect in some cases, such as: * "foo \" bar"* / (incorrectly matches "foo \")/ * '''* /(incorrectly matches the second two single quotes)/ *" foo bar "* / (incorrectly matches quote containing newline/) Anyone know a regular expression that correctly matches python string literals? Thanks in advance, Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Wed Feb 10 23:49:01 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 05:49:01 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >> [snip] >>>> Since in the quoting above no reference to definition of "pointer" >>>> remains: "pointer" refers to a copyable reference value as seen from the >>>> Python level, in the same way as "pointer" is used by e.g. the Java >>>> language spec. >>>> >> [snip] >>>> If so, then that's correct: a Python (or Java, or whatever language) >>>> pointer is not necessarily directly a memory address, and furthermore id >>>> is not guaranteed to reproduce the bits of a pointer value -- which >>>> might not even make sense. >>>> >>>> All that id does is to produce a value that uniquely identifies the >>>> object pointed to, i.e. it corresponds to the pointer value, and >>>> although in CPython that's simply the bits of a C pointer typed as >>>> integer, in IronPython it's not. >>>> >>> You go too far here. What you are referring to in your bizarrely >>> constructed definition above >> No, it's not bizarre, it's the standard general language independent >> definition. >> > *The* standard general language independent definition? Yes. > As defined where? For example, as I used as reference in my first posting, the Java language spec. But it has nothing specifically to do with Java. It is a basic concept in computer science, that (most) CS students learn in their *first year*. E.g. A pointer stores a reference to something. Unfortunately there is no fixed term for the thing that the pointer points to, and across different computer languages there is a wide variety of things that pointers point to. We use the term pointee for the thing that the pointer points to, and we stick to the basic properties of the pointer/pointee relationship which are true in all languages. The term "reference" means pretty much the same thing as "pointer" -- "reference" implies a more high-level discussion, while "pointer" implies the traditional compiled language implementation of pointers as addresses. For the basic pointer/pointee rules covered here, the terms are effectively equivalent. Note that that discussion at Stanford University has several Java examples + a FAQ about the application of the term "pointer" to Java (plus of course that that's specified by the language spec), so "implies ... pointers as addresses" is not smart to get too focused on. Some common sense is required. As mentioned, it is for first-year students. But anyway, this is just terminology; if you don't like the term, then invent or suggest one that you're able to grok or think others will more likely grok. > The id() value doesn't "correspond to the pointer value", it > corresponds to the object. Why you see the need for this indirection > remains a mystery. The language specifies pointer semantics, that's all. You can copy and replace references. So, they quack like pointers, waddle like pointers and look like pointers: = pointers. >> And since I'm referring to an external definition (Java) it's not mine, >> either. :-) >> >> >>> as a pointer does not allow you to access >>> the value that is "pointed to". So I fail to see why you feel its its >>> introduction is necessary. >> Python provides a number of ways to access the object pointed to. >> >> Attribute access, indexing, and operators access the objects pointed to. > > No, they access the objects. What's the difference between "access the objects" and "access the objects"? I'm not genuinely interested in how you came up with this amazing rebuttal, it was a rhetorical question only. But I note that the only difference seems to be that you don't want the objects to be referenced (pointed to) by anything, removing that bit of text, which would make it a bit problematic to apply /any/ operation... > In the IronPython implementation, for > example, it has already been shown quite clearly that the id value is > simply an attribute of the object, whose values are incremented by one > for each new object. Please demonstrate how that is relevant to whatever you're arguing. >> For example, >> >> x = s[0] >> >> accesses the object that s points (refers) to. > > It accesses (the first element of) the object bound to the name "s". Yes. >> While 'is', 'id' and assignment operate on the pointers (references) >> themselves. >> > The 'is' operator is a simple test for equality of ids of the objects > resulting from the evaluation of two expressions. The expressions can be > literals, simple names, or any other valid Python expression. Yes. > They are *not* pointers, or references. Simple demonstration that they're references (have reference semantics): s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. It's pretty hard to argue seriously against this without committing a number of fallacies. Denial is of course easy, and you've done that, but it's at best just childish. > id() simply returns a unique value identifying a particular object. In > CPython, where objects do not migrate in memory once created, the memory > address of the object is used. In IronPython each object is assigned an > id when it is created, and that value is stored as an attribute. Yes. >> So there's one set of language features that operate on pointers, and >> one set of language features that operate on the pointed to objects. >> This is so also in Java and C#. For example. >> >>> Whether in CPython, Jython or IronPython the value returned by calling >>> id(x) (whether x is a literal, a simple name or a more complex >>> expression) is absolutely no use as an accessor: it does not give you >>> access to the referenced value. >> Yes, the id does not give you access to the referenced object. >> > Well at least we have found one aspect of Python we agree on. Oh, good. :-) >>> If you disagree, please write (in any implementation you like: it need >>> not even be portable, though I can't imagine why ti wouldn't be) a >>> Python function which takes an id() value as its argument and returns >>> the value for which the id() value was provided. >> No, I don't disagree with that. >> > Good. > >> It would be excessively inefficient to do, involving enumeration of all >> objects. >> >> >>> So in your world it's unnecessary for pointers to point to anything (or >>> references to refer to something)? For someone who cheerfully admits to >>> being wrong from time to time (an admirable characteristic) you are >>> certainly difficult to convince on this point. One wonders what further >>> hand-waving will follow. >> He he, "further" handwaiving: you're good at unsubstantiated allegations. >> > I am simply pointing out that to make your point you are relying on > abstractions which increasingly diverge from the reality of the Python > language. On the contrary, the closest abstraction to reference semantics is reference semantics. No special cases needed. No extraneous conceptual ballast. > I don't think it's unreasonable to describe that as > "hand-waving". You apparently do. Yes and no. Regarding what you write now, that is regarding what people (who don't have set positions) find easier to grasp: discussing that is necessarily handwaiving, but to the same degree no matter which side you argue. Unless one applies statistics. So by your own argument you're handwaiving. On the other hand, regarding what you wrote earlier you implied a history of handwaiving from me. You would be unable to give examples of that. But above you present an argument about IronPython which suggest some unspecified contradiction with something unspecified (to get to the implied contradiction a reader would have to form a picture that would be misrepresenting me), and *that* is an example of handwaiving, diversion and misrepresentation -- which I didn't have to look far to find... >> I generally strive to provide concrete examples, and you know it. >> > Again with the mind-reading: you appear to have convinced yourself that > you are an authority on what I know. What on Earth are you babbling about now? I say what I do. You therefore think I'm reading your mind? Hello. Get a grip. >> Anywyay, treating the first sentence as a genuine question: in the most >> likely interpretation it seems that you're conflating id's with >> pointers. An id() value uniquely represents a pointer (i.e., the >> identity of the object pointed to). It is not itself a pointer since it >> lack any pointer semantics. >> > No, it doesn't uniquely represent a pointer, Denial is just stupid, sorry. > it uniquely represents an *object*. Yes, and that implies that it also uniquely represents a pointer to the object. If nothing else you could take the address of the object and have a direct correspondence (one-to-one mapping) with the id value, contradicting your statement. But that's just one concrete example, it doesn't capture the general idea of an abstract pointer: it only shows that your statement is a self-contradiction, i.e., fallacious. >> For a less likely more technical interpretation, as far as I know in >> Python there's just one case of a pointer that does not point to >> anything, namely as exemplified by >> >> def foo(): >> print( x ) >> x = "whatever" >> >> The Java equivalent would say "NullPointerException", in Python it says >> something like "unbound". Which means the same. >> > Be careful when comparing static and dynamic languages. Java, being a > static language, has no equivalent to Python's NameError and > AttributeError, which both represent situations in which no object has > been bound to a name. In those cases it isn't that the name exists and > is bound to a "null pointer", it's simply that the name doesn't exist. > So there is no "copyable reference value". Yes, you have point there (the first so far, I must add, since this is at the end of the article!). And it is a good but subtle point that I was a bit hesitant to mention. But since you've let that cat out of ze bag, Java and Python differ in what dangerous name/pointer features they offer: IIRC Java allows a name to become "unbound" by assigning nullpointer, i.e. an extra path to that dangerous nullpointer/unbound state, while Python allows a name to become non-existent via del, i.e. an extra path to that dangerous non-existence. Still, the unbound/nullpointer state is the same, with the same effect. And that's quite suggestive. Cheers & hth., - Alf From dinov at microsoft.com Wed Feb 10 23:58:33 2010 From: dinov at microsoft.com (Dino Viehland) Date: Thu, 11 Feb 2010 04:58:33 +0000 Subject: Modifying Class Object In-Reply-To: References: Message-ID: <1A472770E042064698CB5ADC83A12ACD392D9ED8@TK5EX14MBXC116.redmond.corp.microsoft.com> Steve wrote: > id() simply returns a unique value identifying a particular object. In > CPython, where objects do not migrate in memory once created, the > memory > address of the object is used. In IronPython each object is assigned an > id when it is created, and that value is stored as an attribute. Just a point of clarification: In IronPython ids are lazily assigned upon a call to the id(). They're actually fairly expensive to create because the ids need to be maintained by a dictionary which uses weak references. > >> If you disagree, please write (in any implementation you like: it need > >> not even be portable, though I can't imagine why ti wouldn't be) a > >> Python function which takes an id() value as its argument and > >> returns the value for which the id() value was provided. Just for fun this works in IronPython 2.6: >>> import clr >>> clr.AddReference('Microsoft.Dynamic') >>> from Microsoft.Scripting.Runtime import IdDispenser >>> x = object() >>> id(x) 43 >>> IdDispenser.GetObject(43) >>> IdDispenser.GetObject(43) is x True Please, please, no one ever use this code! I do generally agree with the sentiment that id is object identity and in way related to pointers though. From alfps at start.no Thu Feb 11 00:01:54 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 06:01:54 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> So now the whole thing boils down to "Alf against the world"? The >>> reminds me of the story about the woman who went to see her son qualify >>> from his basic army training. When asked what she thought of the parade >>> she said it was very nice, but that "everyone but our Alf was out of >>> step". >> Considering your frequent ad hominem attacks (and this is yet one more), >> you seem to think that social coercion works well for establishing >> engineering solutions or scientific truth. >> >> That's a misconception. >> > So now I understand neither engineering nor science? I find that > assertion offensive, though unsurprising. > >> Social matters and matters of engineering or science are different things. >> > I am hardly ignorant of that, as you should know from my many past > writings on both aspects of Python usage. You are attempting to teach > your grandmother to suck eggs. >>> I am unsure at this stage what it would take to convince you that you >>> are not only wrong about several important aspects of Python but also >>> wrong-headed. >> You might start by starting a thread about one such thing; I'll correct >> you if you're wrong about something I know, or if you demonstrate that >> I'm wrong about something, then I'll be happy to learn something, as >> always. >> >> It would be a nice change from your extreme focus on my person, if you >> could manage to discuss something technical. >> > See below. >>> Whenever anyone points out any aspect of your behavior >>> which is unacceptable or ignorant you trot out this accusation that >>> people are making "ad hominem attacks" as though commenting on aspects >>> of your personality is an attempt to undermine your arguments. >> That's an ad hominem attack, albeit a pretty silly one. >> > [facepalm] > >> Your behavior, with ad hominem, coercion, insinuations, >> misrepresentations and so forth the basic ingredients, is completely >> unacceptable to me, by the way. >> >> It's like a bully in the schoolyard. >> > I am attempting to persuade, not to coerce. >>> It isn't. The two are orthogonal. Your arguments are wrong *and* you are >>> behaving like a pratt. A change in either one of these aspects would >>> improve matters, but each seems as unlikely as the other. >>> >>>> It also reflects rather badly on you. >>> Sigh. We're all out of step again, obviously. >> If you had any argument that held regarding the technical, then I think >> you (and I mean the singular you) would have tried it by now. >> >> But instead, you engage in this bullying behavior. >> > My (technical) views on your insistence that Python's semantics require > the use of pointers to explain them is ongoing elsewhere, and remains > open for you to refute. > > In this particular part of the thread I am attempting, unsuccessfully, > to convince you that a change in *your* behavior would lead to less > hostility directed towards the way you present your ideas. > > You apparently feel it is quite acceptable to tell people to "learn to > read", I have not used that expression. However I have suggest and emphasized that it might help to *read* whatever one quotes, when the quoted material (such as one paragraph) has not been read. Telling someone to "learn to read" is a Steve Holden'sk way to imply that the person is an ignoramus who hasn't bothered to learn to read. Telling a person to read something that's obviously not been read is quite another matter. So, you are misrepresenting -- again -- and in a quite revealing way, sorry. > and calling their assertions "bullshit", Yes, in this group, but only for personal attacks. Such as yours. I think I've shown extreme restraint in the face of bullying from you and some followers, and calling the insinuations bullshit is quite mild. > but when we try to point > out aspects of your behavior that are either undesirable or unacceptable > we are indulging in "ad hominem attacks". That is an untrue and extremely misleading description of what you've been doing. > In your terms, your accusing me of bullying behavior is an ad hominem > attack on me, so I won't bother to respond further. You're complaining about the person you're hitting saying clearly what you did. If some truthful words about bullying can get you straight I'm for it. Even if it means getting down to your level (and yes, I did). Cheers, - Alf From mark0978 at gmail.com Thu Feb 11 00:24:34 2010 From: mark0978 at gmail.com (Mark Jones) Date: Wed, 10 Feb 2010 21:24:34 -0800 (PST) Subject: I've built Python, but can't figure out how to package it for windows References: Message-ID: Turns out there is an tools/msi directory and in there is python code to help build the MSI from the tree you built. Only problem is you can't use it without having python and PythonWin installed. So I grabbed 2.6.4 python and pythonwin and installed them. It uses COM objects and the CabSDK from MS to build the MSI file. And then it has a couple of "Issues" that I had to resolve. First you need a VS2008 shell so you can nmake -f msisupport.mak then you need to grab a copy of TIX (I didn't have to build it, just have it in place fore the license.terms file (probably could have just removed that list member for the same effect, but I was worried about something else being needed down below) ("Tcl", "tcl8*", "license.terms"), ("Tk", "tk8*", "license.terms"), ("Tix", "Tix-*", "license.terms")): had to be changed to: ("Tcl", "tcl-8*", "license.terms"), ("Tk", "tk-8*", "license.terms"), ("Tix", "Tix*", "license.terms")): because the package names have evidently changed in the not to distant past? After that, I ran c:\python26\python msi.py and then it griped about the python264.chm being missing, so instead of trying to build it, I grabbed the one from the copy of python I had to install in order to build python and dumped it in the expected location. Oh yea, I also had to go to the PC directory and nmake -f icons.mak This gave me a runnable msi file to install python (which was already installed, so that I could build the msi file to install my own version). Oh well, at least it is built now. Whew! From gagsl-py2 at yahoo.com.ar Thu Feb 11 00:35:08 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Feb 2010 02:35:08 -0300 Subject: SocketServer error: AttributeError: instance has no __call__ method References: Message-ID: En Wed, 10 Feb 2010 17:13:58 -0300, Jordan Apgar escribi?: > I'm having some issues connecting to my Socket Server, I get this > traceback on the sever side: > ---------------------------------------- > Exception happened during processing of request from ('127.0.0.1', > 56404) > Traceback (most recent call last): > File "/usr/lib/python2.6/SocketServer.py", line 320, in > finish_request > self.RequestHandlerClass(request, client_address, self) > AttributeError: Negotiator instance has no __call__ method > ---------------------------------------- > class ServerNegotiator: > def __init__(self, host, port, hostid, rsa_key, buf = 512): > negotiator = Negotiator(host, hostid, rsa_key,buf) > self.server = SocketServer.TCPServer((host, port), negotiator) You have to pass the *class* of the RequestHandler you want, not an instance. TCPServer will create an instance of such class for every request handled. So you can't (or shouldn't) save permanent info in the handler, like rsa_key. Store all those parameters in the server. From the handler, you may access the server using its .server attribute. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 11 00:37:17 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Feb 2010 02:37:17 -0300 Subject: SimpleXMLRPCServer and client address References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> Message-ID: En Wed, 10 Feb 2010 19:19:50 -0300, Jordan Apgar escribi?: > I'm trying to right a server that needs specific information for each > client accessing it. The easiest way I could think of doing this is > keeping this information based on ip address (the information is only > valid for a short time). I know there is no was to get the client's > address directly and have seen a few examples of subclassing the > SimpleXMLRPCServer like this: > > class RPCServer(SimpleXMLRPCServer): > > def _dispatch(self, method, params): > """Extend dispatch, adding client info to some parameters.""" > if method in ({my list of methods I needed client address}): > return SimpleXMLRPCServer._dispatch(self, method, > params+(self.client_address,)) > return SimpleXMLRPCServer._dispatch(self, method, params); > > > but to be honest I don't understand what's going on there or how to > use it. Would anyone be able to explain this to me? Do you want an explanation of what the above code does? -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Thu Feb 11 00:46:27 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Feb 2010 05:46:27 GMT Subject: Modifying Class Object References: Message-ID: On Wed, 10 Feb 2010 23:56:36 +0100, Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: >> >>> "pointer" refers to a copyable reference value as seen from the Python >>> level, in the same way as "pointer" is used by e.g. the Java language >>> spec. >> >> Python doesn't have "copyable reference values" in the Python level. It >> has objects. > > Given > > s = [1] > t = s # Copies reference. > t[0] = 2 # Changes referenced object via copied reference. > print( s ) # Checks the object via the original reference. > > your argument that the copied reference does not exist, is just silly. > > And you know it. You keep making a habit of pretending that you know what other people are thinking, accusing them of lying for having an opinion that differs from yours, and of deliberately making silly arguments that the poster (in this case, me) knows is untrue. It is an obnoxious, trolling habit. Please stop it. I don't "know" it is a silly argument, because I don't accept your givens. Specifically: s = [1] t = s # Binds the name t to the object bound to the name s. t[0] = 2 # Changes the object bound to the name t print(s) # Checks the object via the original name. Notice that your version describes what happens according to some implementation, below the level of the Python virtual machine. My version describes what happens at the level of high-level Python code, which is the defined semantics of the language. It makes no assumptions about the implementation, completely unlike yours which is entirely implementation- specific. My description is equally valid whether Python is being executed by the CPython virtual machine on an Intel-compatible processor, or hand-simulated with pencil and paper, or something completely different. Yours is not. I describe the high-level language, you describe one implementation. Neither view is *wrong*, per se, but one describes the semantics of the language while the other describes the implementation. The first paragraph of the Python docs about the execution model says: "NAMES REFER TO OBJECTS [emphasis added]. Names are introduced by name binding operations. Each occurrence of a name in the program text refers to the binding of that name established in the innermost function block containing the use." http://docs.python.org/reference/executionmodel.html Apart from the use of the generic English term "refers to" (and similar), you will find *nothing* about pointers in this. That's because pointers are not a part of the high-level behaviour of Python. See also: http://docs.python.org/reference/simple_stmts.html#assignment-statements where you will also not find the word "pointer" used to describe any high- level Python feature, or used in relation to assignment. -- Steven From wuwei23 at gmail.com Thu Feb 11 01:10:53 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Feb 2010 22:10:53 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <81e93706-0e5f-429c-8514-f079c3910289@x1g2000prb.googlegroups.com> "Alf P. Steinbach" wrote: > Telling someone to "learn to read" is a Steve Holden'sk way to imply that the > person is an ignoramus who hasn't bothered to learn to read. Ad hominem. > So, you > are misrepresenting ?-- ?again ?-- ?and in a quite revealing way, sorry. Ad hominem. > Yes, in this group, but only for personal attacks. Such as yours. Ad hominem. > I think I've shown extreme restraint in the face of bullying from you and some > followers, and calling the insinuations bullshit is quite mild. Ad hominem. > That is an untrue and extremely misleading description of what you've been doing. Ad hominem. > Even if it means getting down to your level (and yes, I did). Ad hominem. So the real lesson you're trying to impart is to do as you say and not as you do? From ken at seehart.com Thu Feb 11 01:28:43 2010 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Feb 2010 22:28:43 -0800 Subject: regex to match python string literal syntax In-Reply-To: <4B738AB1.2030702@seehart.com> References: <4B738AB1.2030702@seehart.com> Message-ID: <4B73A39B.5090503@seehart.com> Found this in pypy! # Match any flavor of string; /*the terminating quote is optional*/ # so that we're robust in the face of incomplete program text. _match_stringre = re.compile(r""" \""" [^"\\]* (?: (?: \\. | "(?!"") ) [^"\\]* )* (?: \""" )? | " [^"\\\n]* (?: \\. [^"\\\n]* )* "? | ''' [^'\\]* (?: (?: \\. | '(?!'') ) [^'\\]* )* (?: ''' )? | ' [^'\\\n]* (?: \\. [^'\\\n]* )* '? """, re.VERBOSE | re.DOTALL).match Problem solved. Ken Ken Seehart wrote: > > I found this: > http://code.activestate.com/recipes/475109/ > > But it is incorrect in some cases, such as: > * > "foo \" bar"* / (incorrectly matches "foo \")/ > * > '''* /(incorrectly matches the second two single quotes)/ > > *" foo > bar "* / (incorrectly matches quote containing newline/) > > Anyone know a regular expression that correctly matches python string > literals? > > Thanks in advance, > Ken > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 11 01:37:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 07:37:35 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 23:56:36 +0100, Alf P. Steinbach wrote: > >> * Steven D'Aprano: >>> On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: >>> >>>> "pointer" refers to a copyable reference value as seen from the Python >>>> level, in the same way as "pointer" is used by e.g. the Java language >>>> spec. >>> Python doesn't have "copyable reference values" in the Python level. It >>> has objects. >> Given >> >> s = [1] >> t = s # Copies reference. >> t[0] = 2 # Changes referenced object via copied reference. >> print( s ) # Checks the object via the original reference. >> >> your argument that the copied reference does not exist, is just silly. >> >> And you know it. > > You keep making a habit of pretending that you know what other people are > thinking, No, that is untrue, I do neither know nor pretend to know what other people are thinking. But I do know that you know some elementary things, such as understanding what the code above does. I do not by that mean that you don't also understand far more advanced things :-), just that I'm fairly ~100% sure that you do understand the code above. > accusing them of lying for having an opinion that differs from > yours, That is untrue. [snip] > I don't "know" it is a silly argument, because I don't accept your > givens. Specifically: > > s = [1] > t = s # Binds the name t to the object bound to the name s. > t[0] = 2 # Changes the object bound to the name t > print(s) # Checks the object via the original name. > > Notice that your version describes what happens according to some > implementation, below the level of the Python virtual machine. Consider just the assert( t is not s ) t = s Does this change anything at all in the computer's memory? If it doesn't, then it has no effect whatsoever. But since it does have an effect, a memory change has been effected. You describe that memory change as that t has been "bound" to the same object as s. By which you mean that henceforth, until the next assignment to t, t *refers* to the same object as s. That explanation in terms of "refers" is necessary. No beginner knows what it means that a name is "bound" to something means, until it's been explained. The explanation is necessarily in terms of "refers to". When something A refers to something B, then by definition A is a *reference* to B. Anyway, you have changed which object t refers to, by changing memory contents so that t now refers to the same object as s. Effectively, by making t refer to the same object as s, by all measures of reference equality (which is just, do they refer to same object?) you have *copied* the s reference to t. For if you haven't, then t necessarily refers to something else. So the memory change, whatever it was, involved an effective copying of a reference, in memory. And that copying of a reference, in memory, implies a copyable reference. Going the other way, copying of references very directly implies binding. No need for the long logic chain above. So copying of references is in my view much more powerful as a model of what goes on, yielding immediate conclusions, avoiding special case rules, and being very suitable for visualization. Not the least, it's more powerful because in order to explain "bind" you need "refer" and "reference", so the "bind" view involves more, violating Occam's. But given the explanation in terms of "refer" and "reference" you do not need "bind", so it's less, it's simpler -- and it's easier to visualize. --- Anyway, there is more practical way to look at it. Say that you're going to implement a linked list. The functionality required for that is exactly that of general pointers. But a linked list can be implemented in Python, using names (attributes) as pointers. And since that works, without having to do anything extra in order to "implement" pointers in terms of names, but just using those names directly, those names necessarily have the functionality of general pointers. > My version > describes what happens at the level of high-level Python code, which is > the defined semantics of the language. It makes no assumptions about the > implementation, completely unlike yours which is entirely implementation- > specific. My description is equally valid whether Python is being > executed by the CPython virtual machine on an Intel-compatible processor, > or hand-simulated with pencil and paper, or something completely > different. Yours is not. > > I describe the high-level language, you describe one implementation. > Neither view is *wrong*, per se, but one describes the semantics of the > language while the other describes the implementation. > > The first paragraph of the Python docs about the execution model says: > > "NAMES REFER TO OBJECTS [emphasis added]. Names are introduced by name > binding operations. Each occurrence of a name in the program text refers > to the binding of that name established in the innermost function block > containing the use." > > http://docs.python.org/reference/executionmodel.html > > Apart from the use of the generic English term "refers to" (and similar), > you will find *nothing* about pointers in this. That's because pointers > are not a part of the high-level behaviour of Python. Well, apart from... As you say. > See also: > > http://docs.python.org/reference/simple_stmts.html#assignment-statements > > where you will also not find the word "pointer" used to describe any high- > level Python feature, or used in relation to assignment. Yes, that's right. It does not mean that such a description is invalid. It only means that common sense needs to be applied, and that the urge to misinterpret needs to be suppressed. I don't think those are problems for novices. But still a better term than "pointer" would be nice, and I guess "reference" is it, as suggested by the course material I linked to. Cheers & hth., - Alf From alfps at start.no Thu Feb 11 01:46:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 07:46:46 +0100 Subject: Modifying Class Object In-Reply-To: <81e93706-0e5f-429c-8514-f079c3910289@x1g2000prb.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <81e93706-0e5f-429c-8514-f079c3910289@x1g2000prb.googlegroups.com> Message-ID: * alex23: > "Alf P. Steinbach" wrote: >> Telling someone to "learn to read" is a Steve Holden'sk way to imply that the >> person is an ignoramus who hasn't bothered to learn to read. > > Ad hominem. > >> So, you >> are misrepresenting -- again -- and in a quite revealing way, sorry. > > Ad hominem. > >> Yes, in this group, but only for personal attacks. Such as yours. > > Ad hominem. > >> I think I've shown extreme restraint in the face of bullying from you and some >> followers, and calling the insinuations bullshit is quite mild. > > Ad hominem. > >> That is an untrue and extremely misleading description of what you've been doing. > > Ad hominem. > >> Even if it means getting down to your level (and yes, I did). > > Ad hominem. > > So the real lesson you're trying to impart is to do as you say and not > as you do? Well, I don't think any of you guys would hold out as long as I did. I think it's Not Nice to get personal. But there's a limit, one can't just ignore punches every day, and you're right, the above from me was ad hominem all the way (well, except that it doesn't concern any technical discussion, and that I'm not injecting noise but responding to such and trying to reduce it in the future, but still). Cheers, - Alf From ivlenin at gmail.com Thu Feb 11 02:38:32 2010 From: ivlenin at gmail.com (I V) Date: 11 Feb 2010 08:38:32 +0100 Subject: Modifying Class Object References: Message-ID: <4b73b3f8$1@news.x-privat.org> On Thu, 11 Feb 2010 07:37:35 +0100, Alf P. Steinbach wrote: > * Steven D'Aprano: >> s = [1] >> t = s # Binds the name t to the object bound to the name s. >> t[0] = 2 # Changes the object bound to the name t print(s) # >> Checks the object via the original name. >> >> Notice that your version describes what happens according to some >> implementation, below the level of the Python virtual machine. > > Consider just the > > assert( t is not s ) > > t = s > > Does this change anything at all in the computer's memory? > > If it doesn't, then it has no effect whatsoever. > > But since it does have an effect, a memory change has been effected. I don't think your disagreeing with Steven here - by talking about "the computers memory," it's clear that you are talking about the details of an implementation of python, not the semantics of python itself. Unless, of course, you are under the misapprehension that "the computer's memory" is relevant to the python language, rather than the particular implementation. Python itself has nothing to do with "computers" or "memory"; these are mere implementation details. From wayne.dads.bell at gmail.com Thu Feb 11 02:39:36 2010 From: wayne.dads.bell at gmail.com (wayne.dads.bell at gmail.com) Date: Thu, 11 Feb 2010 07:39:36 +0000 Subject: sqlite3 bug? In-Reply-To: <4B735175.9020704@tim.thechases.com> Message-ID: <001636498db3b55769047f4e4011@google.com> Thank you It just highlights that when your tired things can easily be missed and maybe you should leave things until the morning to view things with fresh eyes =) -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Thu Feb 11 02:59:38 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 11 Feb 2010 20:59:38 +1300 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: <7thr3kFeqlU1@mid.individual.net> Christian Heimes wrote: > A much, much stronger version of the > principles behind Vigen?re was used in the German Enigma machine. > Because the algorithm was still not good enought some clever guy called > Turing and his team was able to crack the enigma. Actually I gather it had a lot to do with the fact that the Germans made some blunders in the way they used the Enigma that seriously compromised its security. There was reportedly a branch of the German forces that used their Enigmas differently, avoiding those mistakes, and the British never managed to crack any of their messages. -- Greg From greg.ewing at canterbury.ac.nz Thu Feb 11 03:01:35 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 11 Feb 2010 21:01:35 +1300 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> Message-ID: <7thr76FeqlU2@mid.individual.net> Daniel Fetchinson wrote: > It also turned out that everybody mostly writes his/her > own obfuscation routine. Hey, it gives you the additional advantage of obfuscation by obscurity! -- Greg From alfps at start.no Thu Feb 11 03:09:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 09:09:04 +0100 Subject: Modifying Class Object In-Reply-To: <4b73b3f8$1@news.x-privat.org> References: <4b73b3f8$1@news.x-privat.org> Message-ID: * I V: > On Thu, 11 Feb 2010 07:37:35 +0100, Alf P. Steinbach wrote: >> * Steven D'Aprano: >>> s = [1] >>> t = s # Binds the name t to the object bound to the name s. >>> t[0] = 2 # Changes the object bound to the name t print(s) # >>> Checks the object via the original name. >>> >>> Notice that your version describes what happens according to some >>> implementation, below the level of the Python virtual machine. >> Consider just the >> >> assert( t is not s ) >> >> t = s >> >> Does this change anything at all in the computer's memory? >> >> If it doesn't, then it has no effect whatsoever. >> >> But since it does have an effect, a memory change has been effected. > > I don't think your disagreeing with Steven here - by talking about "the > computers memory," it's clear that you are talking about the details of > an implementation of python, not the semantics of python itself. Unless, > of course, you are under the misapprehension that "the computer's memory" > is relevant to the python language, rather than the particular > implementation. Python itself has nothing to do with "computers" or > "memory"; these are mere implementation details. You know, the programming language that doesn't need computers: Python. :-) Cheers, - Alf (not sure how to read your posting, but it's funny anyhow) From mail at timgolden.me.uk Thu Feb 11 03:56:32 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Feb 2010 08:56:32 +0000 Subject: I've built Python, but can't figure out how to package it for windows In-Reply-To: References: Message-ID: <4B73C640.1000500@timgolden.me.uk> On 11/02/2010 05:24, Mark Jones wrote: [... problems building from tools/msi ...] I sympathise. I went through similar hoops last year, merely to be able to do it. I think I'm right in saying that very few people are bothered enough to package their own MSI on windows because the (probably very few) developers who have a need to run bleeding-edge Python, eg to test out patches or whatever, can simply run from \pcbuild\python_d.exe or whatever. And everyone else simply runs the MSI provided on python.org. I'm fairly sure I'm right in saying that it's Martin von L who builds the MSIs for python.org and if I haven't done it before I'd like to offer him a vote of thanks for having done and for continuing to do this. The tools/msi is used by him to do those builds and does make certain assumptions. One, in particular, is that you have an *existing* copy of some recent Python running somewhere. (I use python25, I think). Altho' it might be nice to be able to bootstrap, in practice it isn't a problem. For interest's sake I offer my make-snapshots area which I use to build trunk or branches for Python 2.x / 3.x when I have the change: http://svn.tjg.org.uk/make-snapshots Feel free to look at least to see what I'm doing. I think I didn't bother with Tix (I don't use Tkinter) so thanks for providing some input on that; I may well go back and retrofit. TJG From mail at timgolden.me.uk Thu Feb 11 04:10:49 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Feb 2010 09:10:49 +0000 Subject: Executing Commands From Windows Service In-Reply-To: <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> Message-ID: <4B73C999.90206@timgolden.me.uk> On 10/02/2010 22:55, T wrote: > Great suggestions once again - I did verify that it was at least > running the plink.exe binary when under LocalSystem by having the > service run "plink.exe> C:\plinkoutput.txt" - this worked fine. And, > as I mentioned, it's now working just fine when running under a > regular admin account. So, I think that's going to be my solution to > avoid any further issues. My best guess at this point (as you > mentioned), is that plink.exe is doing _something_ network-related > that LocalSystem doesn't have the privileges to do - what exactly it > is, I have no idea. I may play around with it some more later, but > running the service under an admin account should be a perfectly > acceptable solution. > > Also, I will be writing other Python apps that the service will be > executing - so it goes without saying that I'll be including a log to > file option :) Thanks again for all your guys' help! I'm not sure if this has been said already, but a reasonably common approach to services is to create a user specifically for the service and grant it exactly the privs / perms it needs (once you work out what they are). You then assign it a generated password, eg a GUID which you don't even try to remember: simply cut-and-paste it in. Then create the service to run under that user. That way you don't have the service running under some local Administrator account with the associated risk of its being subverted and gaining more control than you want. Nor do you have it running as a real user whose password might change for any reason, leaving you with a service which won't start up. I don't remember at this moment whether such a user's profile is automatically loaded in the process when the service starts or whether you have to do the LoadUserProfile thing. TJG From lists at cheimes.de Thu Feb 11 04:46:16 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Feb 2010 10:46:16 +0100 Subject: ANN: obfuscate In-Reply-To: <7thr3kFeqlU1@mid.individual.net> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> Message-ID: <4B73D1E8.9040603@cheimes.de> Gregory Ewing wrote: > Actually I gather it had a lot to do with the fact that > the Germans made some blunders in the way they used the > Enigma that seriously compromised its security. There > was reportedly a branch of the German forces that used > their Enigmas differently, avoiding those mistakes, and > the British never managed to crack any of their messages. IIRC some versions of the Enigma weren't cracked because they used a different setup and different daily keys. The predecessor of the Enigma was cracked by Polish scientists years before WW2 started. Some flaws in the instructions and a known plain text attack made the crack of the Enigma practical. It took the British scientists merely hours rather than days or weeks to decipher the daily key with some smart tricks. For example they started fake attacks on ships or cities just to have the names in some encrypted reports. From aabelyakov at gmail.com Thu Feb 11 04:57:00 2010 From: aabelyakov at gmail.com (aabelyakov) Date: Thu, 11 Feb 2010 01:57:00 -0800 (PST) Subject: Unicode strings Message-ID: <9c47f29c-4f98-442c-ba60-ec1d68f401f8@b7g2000yqd.googlegroups.com> Excellent! But what about the unicode From aabelyakov at gmail.com Thu Feb 11 05:00:05 2010 From: aabelyakov at gmail.com (aabelyakov) Date: Thu, 11 Feb 2010 02:00:05 -0800 (PST) Subject: Unicode strings Message-ID: Excellent! But what about the unicode? From no.email at nospam.invalid Thu Feb 11 06:32:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Feb 2010 03:32:18 -0800 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> Message-ID: <7x6364gg8t.fsf@ruckus.brouhaha.com> Gregory Ewing writes: > Actually I gather it had a lot to do with the fact that the Germans > made some blunders in the way they used the Enigma that seriously > compromised its security. There was reportedly a branch of the German > forces that used their Enigmas differently, avoiding those mistakes, > and the British never managed to crack any of their messages. I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they were more careful with procedures, but the machine was also harder to crack because it had four rotors instead of three. IIRC, the Brits were eventually (1942?) able to capture one by shooting up a German submarine and boarding it to get the machine while the sub was sinking; a British sailor wasn't able to get out in time and drowned during that operation. Getting the rotor settings off the captured unit (they may have had to do it more than once) was enough to get a foothold into the code. My memory is hazy on this by now so I may have some parts wrong, but David Kahn's book "Seizing the Enigma" tells the story (I read it many years ago). A fictionalized version appears in Neil Stephenson's novel "Cryptonomicon". From zasaconsulting at gmail.com Thu Feb 11 06:44:55 2010 From: zasaconsulting at gmail.com (Alexzive) Date: Thu, 11 Feb 2010 03:44:55 -0800 (PST) Subject: how to improve this cycle (extracting data from structured array)? Message-ID: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> Hello guys, I am just wondering if there is a quick way to improve this algorithm [N is a structured array which hold info about the nodes n of a finite element mesh, and n is about 300.000). I need to extract info from N and put it in to a 3*n matrix NN which I reshape then with numpy. I think to "append" is quite unefficient: *********************************************************** N = odb.rootAssembly.instances['PART-1-1'].nodes NN=[] B=[0,0,0] #auxsiliar vector for i in range(len(N)): B[0] = N[i].label B[1] = N[i].coordinates[0] B[2] = N[i].coordinates[1] NN = append(NN,B) NN=NN.reshape(-1,3) **************************************************** Many Thanks in advance! Alex From python.list at tim.thechases.com Thu Feb 11 07:08:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Feb 2010 06:08:31 -0600 Subject: how to improve this cycle (extracting data from structured array)? In-Reply-To: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> References: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> Message-ID: <4B73F33F.9060205@tim.thechases.com> Alexzive wrote: > I am just wondering if there is a quick way to improve this algorithm > [N is a structured array which hold info about the nodes n of a finite > element mesh, and n is about 300.000). I need to extract info from N > and put it in to a 3*n matrix NN which I reshape then with numpy. I > think to "append" is quite unefficient: > > *********************************************************** > N = odb.rootAssembly.instances['PART-1-1'].nodes > > NN=[] > > B=[0,0,0] > #auxsiliar vector > for i in range(len(N)): > B[0] = N[i].label > B[1] = N[i].coordinates[0] > B[2] = N[i].coordinates[1] > NN = append(NN,B) Usually this would be written with a list-comprehension, something like nn = [(x.label, x.coordinates[0], x.coordinates[1]) for x in N] or if you really need lists-of-lists instead of lists-of-tuples: nn = [[x.label, x.coordinates[0], x.coordinates[1]] for x in N] -tkc From __peter__ at web.de Thu Feb 11 07:25:47 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Feb 2010 13:25:47 +0100 Subject: Bizarre arithmetic results References: Message-ID: Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? Operator precedence. >>> -0.1**0.1 -0.7943282347242815 >>> (-0.1)**0.1 (0.7554510437117542+0.2454609236416552j) Quoting http://docs.python.org/3.1/reference/expressions.html: """ The power operator binds more tightly than unary operators on its left; it binds less tightly than unary operators on its right. """ Peter From andreengels at gmail.com Thu Feb 11 07:26:56 2010 From: andreengels at gmail.com (Andre Engels) Date: Thu, 11 Feb 2010 13:26:56 +0100 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: <6faf39c91002110426j2f41d7ebjb1775e6ee6968386@mail.gmail.com> On Thu, Feb 11, 2010 at 1:44 AM, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb ?3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? It's an issue of precedence of operators: -0.1 ** 0.1 is interpreted as -(0.1 ** 0.1) and not as (-0.1) ** 0.1 -- Andr? Engels, andreengels at gmail.com From dickinsm at gmail.com Thu Feb 11 07:27:14 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Feb 2010 04:27:14 -0800 (PST) Subject: Bizarre arithmetic results References: Message-ID: On Feb 11, 12:44?am, Terrence Cole wrote: > Can someone explain to me what python is doing here? > >>> -0.1 ** 0.1 > -0.7943282347242815 Here you're computing -(0.1 ** 0.1). The exponentiation operator binds more strongly than the negation operator. > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.7554510437117542+0.2454609236416552j) Here you're computing (-0.1) ** 0.1. -- Mark From anand.shashwat at gmail.com Thu Feb 11 07:31:54 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 11 Feb 2010 18:01:54 +0530 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: Do you really believe that -0.1 ** 0.1 is a valid computational problem ? Can you raise a negative number to a fractional power ? Output on my console (python 2.6) >>> -.1 ** .1 -0.79432823472428149 >>> a,b = -.1,.1 >>> a**b Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power >>> -abs(a**b) Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power There is a little issue here that '>>> -.1 ** .1' should give you error message. That is it. On Thu, Feb 11, 2010 at 6:14 AM, Terrence Cole < list-sink at trainedmonkeystudios.org> wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> -0.1 ** 0.1 > -0.7943282347242815 > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.7554510437117542+0.2454609236416552j) > >>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? > > Cheers, > Terrence > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Thu Feb 11 07:33:37 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Feb 2010 13:33:37 +0100 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: Terrence Cole wrote: >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? The binary power operator has a higher precedence than the unary negative operator. -0.1 ** 0.1 is equal to -(0.1**0.1) Christian From anand.shashwat at gmail.com Thu Feb 11 07:35:26 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 11 Feb 2010 18:05:26 +0530 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: Just realized my flaw >>> .1**.1 0.79432823472428149 >>> (-.1)**(.1) Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power - a ** b = - (a ** b) and not (-a) ** b, Thats why -.1**.1 giving you -0.79432823472428149 since .1 ** .1 = 0.79432823472428149 and minus sign is appended prior to it. On Thu, Feb 11, 2010 at 6:01 PM, Shashwat Anand wrote: > Do you really believe that -0.1 ** 0.1 is a valid computational problem ? > Can you raise a negative number to a fractional power ? > Output on my console (python 2.6) > > >>> -.1 ** .1 > -0.79432823472428149 > >>> a,b = -.1,.1 > >>> a**b > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > >>> -abs(a**b) > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > > There is a little issue here that '>>> -.1 ** .1' should give you error > message. That is it. > > > > On Thu, Feb 11, 2010 at 6:14 AM, Terrence Cole < > list-sink at trainedmonkeystudios.org> wrote: > >> Can someone explain to me what python is doing here? >> >> Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) >> [GCC 4.3.4] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> -0.1 ** 0.1 >> -0.7943282347242815 >> >>> a = -0.1; b = 0.1 >> >>> a ** b >> (0.7554510437117542+0.2454609236416552j) >> >>> -abs(a ** b) >> -0.7943282347242815 >> >> Why does the literal version return the signed magnitude and the >> variable version return a complex? >> >> Cheers, >> Terrence >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Thu Feb 11 07:37:45 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 Feb 2010 14:37:45 +0200 Subject: Bizarre arithmetic results References: Message-ID: Terrence Cole writes: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> -0.1 ** 0.1 > -0.7943282347242815 > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.7554510437117542+0.2454609236416552j) > >>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? The minus sign is not part of the literal syntax. Python takes the expression as -(0.1 ** 0.1), the binary operator binding tighter than the unary. Try (-0.1) ** 0.1, and try a = 0.1, then -a ** 0.1. From mail at timgolden.me.uk Thu Feb 11 07:43:35 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Feb 2010 12:43:35 +0000 Subject: ANN: obfuscate In-Reply-To: <7x6364gg8t.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <7x6364gg8t.fsf@ruckus.brouhaha.com> Message-ID: <4B73FB77.1090005@timgolden.me.uk> On 11/02/2010 11:32, Paul Rubin wrote: > Gregory Ewing writes: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the German >> forces that used their Enigmas differently, avoiding those mistakes, >> and the British never managed to crack any of their messages. > > I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they > were more careful with procedures, but the machine was also harder to > crack because it had four rotors instead of three. IIRC, the Brits were > eventually (1942?) able to capture one by shooting up a German submarine > and boarding it to get the machine while the sub was sinking; a British > sailor wasn't able to get out in time and drowned during that operation. > Getting the rotor settings off the captured unit (they may have had to > do it more than once) was enough to get a foothold into the code. My > memory is hazy on this by now so I may have some parts wrong, but David > Kahn's book "Seizing the Enigma" tells the story (I read it many years > ago). A fictionalized version appears in Neil Stephenson's novel > "Cryptonomicon". And for those who haven't been to Bletchley Park [*] I recommend it. Not only is it full of interesting stuff, but it has an engagingly amateurish air about it which I personally prefer to the sleek-and-shiny nature of many museum-y places today. When I was there last summer I was disappointed to see that they'd closed the Pigeon Museum. But the Model Railway club was still there (altho' we were too late in the day to get in) and the new Computing Museum is full of delightful nostalgic clutter being worked on by enthusiastic people. My kind of place.. TJG [*] http://www.bletchleypark.org.uk/ From python.list at tim.thechases.com Thu Feb 11 07:47:56 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Feb 2010 06:47:56 -0600 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: <4B73FC7C.5040006@tim.thechases.com> Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? I think this recently showed up on the list and the answer involved the order of operations and precedence of "-" vs. "**". To check, try >>> (-0.1) ** 0.1 >>> -(0.1 ** 0.1) The first one is what the assignment-to-variables gains you, but I think "**" has a higher precedence than the unary-"-" so it gets performed first. I don't have Py3 on my machine here, and 2.5 rejects the first form: Python 2.5.4 (r254:67916, Nov 19 2009, 19:46:21) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -(0.1**0.1) -0.79432823472428149 >>> (-0.1)**0.1 Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power But perhaps Py3 changes evaluation, returning an complex number. -tkc From fetchinson at googlemail.com Thu Feb 11 07:49:37 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 11 Feb 2010 13:49:37 +0100 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: On 2/11/10, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? Try this and think about operator precedence: Python 3.1.1 (r311:74480, Dec 13 2009, 16:50:25) [GCC 4.4.2 20091027 (Red Hat 4.4.2-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> (-0.1)**0.1 (0.7554510437117542+0.2454609236416552j) >>> I.e. -0.1**0.1 is not the same as (-0.1)**0.1, because it's first 0.1**0.1 and then a minus sign. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From wayne.dads.bell at gmail.com Thu Feb 11 08:20:24 2010 From: wayne.dads.bell at gmail.com (dads) Date: Thu, 11 Feb 2010 05:20:24 -0800 (PST) Subject: sqlite3 bug? References: Message-ID: Thank you It just highlights that when your tired things can easily be missed and maybe you should leave things until the morning to view things with fresh eyes =) From martin.hellwig at dcuktec.org Thu Feb 11 08:21:56 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Feb 2010 13:21:56 +0000 Subject: Executing Commands From Windows Service In-Reply-To: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: On 02/07/10 19:02, T wrote: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. Specifically, the > program will call plink.exe to create a reverse SSH tunnel. Right now > I'm using subprocess.Popen to do so. When I run it interactively via > an admin account, all is well. However, when I'm running it via > service, no luck. I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. What > would be the best way around this? Thanks! All being said about LS account not having the appropriate rights to access the necessary devices/files. Could it be so simple that the network is plain simply not available at all? For wireless connections I believe the connection/authentication by default is made in user space. I would save the output of an ipconfig run as the LS account to a file and see what is happening. Perhaps followed by a ping. -- mph From vishal_shetye at persistent.co.in Thu Feb 11 08:27:51 2010 From: vishal_shetye at persistent.co.in (Vishal Shetye) Date: Thu, 11 Feb 2010 18:57:51 +0530 Subject: base32hex support in python? Message-ID: <14B8F27D7CE40C4C9E481B2B845C2E0D026A34BDCF@EXCHANGE.persistent.co.in> Hi, One of the modules that I am currently working on requires base32hex encoding as defined by RFC 4648, section 7. I checked base64 module which has base32encode/decode functionality but not with extended hex alphabet. Is there a module, currently available, that provides this? As far as I see, it looks fairly simple to add support for base32hex. It differs from the base32 encoding only in the alphabet used. I am willing to provide a patch. Just to note, map01 argument won't be applicable to base32hexdecode as this encoding uses both 0 (zero) and O (oh) in its alphabet. Looking at the section 13 of RFC 4648, I think, adding base32hex support would make it conform to RFC 4648. - Vishal DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marklocklear at gmail.com Thu Feb 11 08:33:41 2010 From: marklocklear at gmail.com (Lumbee) Date: Thu, 11 Feb 2010 05:33:41 -0800 (PST) Subject: exception in Tkinter on Ubtunu... Message-ID: <561ee0cf-f1fd-49ee-89e9-527124f9ff62@q16g2000yqq.googlegroups.com> ...hey guys, I posted this over on the Ubuntu forums with no luck. I'm running Ubuntu 9.10 and python 2.5. In Idle when I type in a function I get this error... >>> Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1417, in __call__ return self.func(*args) File "/usr/lib/python2.5/idlelib/MultiCall.py", line 151, in handler r = l[i](event) File "/usr/lib/python2.5/idlelib/CallTips.py", line 55, in try_open_calltip_event self.open_calltip(False) File "/usr/lib/python2.5/idlelib/CallTips.py", line 79, in open_calltip self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1]) File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 66, in showtip self.position_window() File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 35, in position_window self.parencol)) File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 2860, in bbox self.tk.call((self._w, 'bbox') + args)) or None File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1033, in _getints return tuple(map(getint, self.tk.splitlist(string))) ValueError: invalid literal for int() with base 10: '(167,' testNestEggFixed( ...I've tried reinstalling, and am not sure where to go from here. I also get a 2nd small windows about 2X2" with 'idle' in the title, and nothing in the box, and I cannot use the mouse if I open a Python program from Idle. Any ideas? From jeanmichel at sequans.com Thu Feb 11 08:34:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Feb 2010 14:34:16 +0100 Subject: SimpleXMLRPCServer and client address In-Reply-To: <7a9c25c21002101956x1298f01euc40285c2227a0598@mail.gmail.com> References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> <4B735F0F.6080503@sequans.com> <7a9c25c21002101956x1298f01euc40285c2227a0598@mail.gmail.com> Message-ID: <4B740758.8020208@sequans.com> Stephen Hansen wrote: > On Wed, Feb 10, 2010 at 5:36 PM, Jean-Michel Pichavant > > wrote: > > I don't know exactly what you are trying to do, but if your server > requires informations from the client, it would be better to ask > explicitly the client for those informations. > For instance, if a method requires te client IP address, then the > IP address is definitely a parameter of the method. > > > I can't answer the OP, as I don't know the answer to his specific > question-- but er, asking a client to provide one's IP address is not > really a very workable solution. There's no way to really determine > your own IP address in a reliable way. > > All the usual methods (e.g., > socket.gethostbyname(socket.gethostname())) can fail and/or be wrong > in some not terribly uncommon situations. The only reliable way to get > such a piece of information is to connect to a server, and ask that > server what address you were connecting to them as. Even then, that IP > may not be the same as an IP you use to connect to say, a different > server (on a different network) > > --S You're probably right. But my point covered only the fact that if a method needs something it should ask it explicitly throught parameters, not taking the opportunity to guess it since it happens that it's a xmlrpc server and that the information could be deduced from the client IP address. My feeling is that the OP needed something else than the client IP address, and was trying at the server side to map client IPs with the data he effectively needs. I could be wrong though. JM From Juergen.Hermann at 1und1.de Thu Feb 11 08:34:26 2010 From: Juergen.Hermann at 1und1.de (jhermann) Date: Thu, 11 Feb 2010 05:34:26 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <8504b5fe-8776-4c60-a001-a27bc0225f6d@q16g2000yqq.googlegroups.com> $ python -c "import this" From duncan.booth at invalid.invalid Thu Feb 11 08:38:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Feb 2010 13:38:46 GMT Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Tim Chase wrote: > But perhaps Py3 changes evaluation, returning an complex number. Yes, the change is documented at http://docs.python.org/3.1/reference/expressions.html#the-power-operator If it is in any of the "What's new in Python x.xx" documents or in a PEP somewhere I haven't spotted it. -- Duncan Booth http://kupuguy.blogspot.com From zasaconsulting at gmail.com Thu Feb 11 09:16:12 2010 From: zasaconsulting at gmail.com (Alexzive) Date: Thu, 11 Feb 2010 06:16:12 -0800 (PST) Subject: how to improve this cycle (extracting data from structured array)? References: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> Message-ID: <992f5035-904f-49b6-9d6a-6bf16cd03e32@x22g2000yqx.googlegroups.com> On Feb 11, 1:08?pm, Tim Chase wrote: > Alexzive wrote: > > I am just wondering if there is a quick way to improve this algorithm > > [N is a structured array which hold info about the nodes n of a finite > > element mesh, and n is about 300.000). I need to extract info from N > > and put it in to a 3*n matrix NN which I reshape then with numpy. I > > think to "append" is quite unefficient: > > > *********************************************************** > > N = odb.rootAssembly.instances['PART-1-1'].nodes > > > NN=[] > > > B=[0,0,0] > > ?#auxsiliar vector > > for i in range(len(N)): > > ? ? B[0] = N[i].label > > ? ? B[1] = N[i].coordinates[0] > > ? ? B[2] = N[i].coordinates[1] > > ? ? NN = append(NN,B) > > Usually this would be written with a list-comprehension, > something like > > ? ?nn = [(x.label, x.coordinates[0], x.coordinates[1]) > ? ? ? ? ?for x in N] > > or if you really need lists-of-lists instead of lists-of-tuples: > > ? ?nn = [[x.label, x.coordinates[0], x.coordinates[1]] > ? ? ? ? ?for x in N] > > -tkc yeah, much better thanks! Alex From dickinsm at gmail.com Thu Feb 11 09:21:57 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Feb 2010 06:21:57 -0800 (PST) Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: <9ea745cf-e10e-4b61-a2bc-8390f54c79ff@d37g2000yqa.googlegroups.com> On Feb 11, 1:38?pm, Duncan Booth wrote: > Tim Chase wrote: > > But perhaps Py3 changes evaluation, returning an complex number. > > Yes, the change is documented athttp://docs.python.org/3.1/reference/expressions.html#the-power-operator > > If it is in any of the "What's new in Python x.xx" documents or in a PEP > somewhere I haven't spotted it. Not in the 'what's new' documents, as far as I can tell, but this change was introduced as part of implementing PEP 3141. http://www.python.org/dev/peps/pep-3141/ Here's an extract from the PEP, describing the 'Complex' abstract base class: class Complex(Number): """Complex defines the operations that work on the builtin complex type. In short, those are: conversion to complex, bool(), .real, .imag, +, -, *, /, **, abs(), .conjugate(), ==, and !=. If it is given heterogenous arguments, and doesn't have special knowledge about them, it should fall back to the builtin complex type as described below. """ @abstractmethod def __pow__(self, exponent): """a**b; should promote to float or complex when necessary.""" raise NotImplementedError -- Mark From hjebbers at gmail.com Thu Feb 11 09:32:33 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 06:32:33 -0800 (PST) Subject: python crash on windows but not on linux Message-ID: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> To all, I am running an EDI translator, and doing stress tests. When processing a test with a (relatively) big EDI file(s) on windowsXP I get a crash: 'sorry for the inconvenience' etc (so no clues about what is causing the problem) This happens with python 2.4, 2.5, 2.6 It does not happen in the same setup&tests on linux. (while the linux machine has only half of the RAM of the windows machine). I am quite sure it is not some external module; there's no GUI (apart from 'print'), no network connections. Actually, the crash is not predictable....the crash occurs most of the time...but at different points. So basically I am wondering how to proceed. Is it related to a memory problem? (which does not occur on Linux) any pointer is very welcome, henk-jan From cjw at ncf.ca Thu Feb 11 10:24:00 2010 From: cjw at ncf.ca (cjw) Date: Thu, 11 Feb 2010 10:24:00 -0500 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: On 05-Feb-10 14:53 PM, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > > Thanks I prefer verbNoun. Let's remember that PEP 8 is a guide, not a set of rules. Colin W. From gilsapir86 at gmail.com Thu Feb 11 10:31:47 2010 From: gilsapir86 at gmail.com (apple man) Date: Thu, 11 Feb 2010 07:31:47 -0800 (PST) Subject: can you help me about this deal? Message-ID: <608d3dbd-4705-42e8-a77b-ee425a6dc8ef@d27g2000yqn.googlegroups.com> hi i saw this very cheap macbook pro 500$ here: (the 3rd from the left) http://sites.google.com/site/applestorebyamazone1/ i want to buy it, is it a good price? can i get a lower price? thanks From robert.kern at gmail.com Thu Feb 11 10:55:30 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Feb 2010 09:55:30 -0600 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: On 2010-02-11 06:31 AM, Shashwat Anand wrote: > Do you really believe that -0.1 ** 0.1 is a valid computational problem > ? Can you raise a negative number to a fractional power ? > Output on my console (python 2.6) > > >>> -.1 ** .1 > -0.79432823472428149 > >>> a,b = -.1,.1 > >>> a**b > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > >>> -abs(a**b) > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > > There is a little issue here that '>>> -.1 ** .1' should give you error > message. That is it. No, fractional powers of negative numbers are perfectly valid mathematically. The result is a complex number. In Python 3 (what the OP is using), this has been implemented, but not in Python 2.6. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at holdenweb.com Thu Feb 11 10:59:41 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 10:59:41 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: [...] >> In this particular part of the thread I am attempting, unsuccessfully, >> to convince you that a change in *your* behavior would lead to less >> hostility directed towards the way you present your ideas. >> >> You apparently feel it is quite acceptable to tell people to "learn to >> read", > > I have not used that expression. > > However I have suggest and emphasized that it might help to *read* > whatever one quotes, when the quoted material (such as one paragraph) > has not been read. > > Telling someone to "learn to read" is a Steve Holden'sk way to imply > that the person is an ignoramus who hasn't bothered to learn to read. > Telling a person to read something that's obviously not been read is > quite another matter. So, you are misrepresenting -- again -- and in > a quite revealing way, sorry. > Pardon me? You used it on December 16 in a response to Mensanator in message M :> How about devoting a section on downloading the source files M :> and compiling it on a Mac? AS:> Learn to read. AS:> At the top of every second page it tells you that this is an AS:> introduction based on Windows. I am sure you will have some glib response as to why this wasn't rude at all. Allow me to correct you - it was, and rudeness is not welcomed on comp.lang.python. That doesn't mean it doesn't happen (why, I have even been known to be rude myself - we are none of us perfect, after all). I have already given ample evidence that when I am wrong I will admit it. You, contrariwise, maintain that you will admit when you are wrong (I believe 40% of the time was the figure you used) but I fail to remember any single incident when you made such an admission. >> and calling their assertions "bullshit", > > Yes, in this group, but only for personal attacks. > > Such as yours. > > I think I've shown extreme restraint in the face of bullying from you > and some followers, and calling the insinuations bullshit is quite mild. I don't have "followers". Assertions I make are my own, and stand alone without the need of support. Calling them "bullshit" is indeed quite mild, but doesn't invalidate them. You can only do that by engaging, but instead you hysterically shout "ad hominem" whenever anyone makes a personal remark. > >> but when we try to point >> out aspects of your behavior that are either undesirable or unacceptable >> we are indulging in "ad hominem attacks". > > That is an untrue and extremely misleading description of what you've > been doing. > I'll let that be judged on the record. You have consistently refused to accept, despite assertions from several individuals (presumably those you choose to characterize as my "followers", thereby allowing you to write them off without seriously considering what they say - at least that is how it looks from the outside) that criticism of your behavior is not, in fact, an ad hominem attack but an attempt to engage you in debate and have you modify that behavior. So, for the final time: remarks about personal characteristics only constitute ad hominem attacks ONLY when they are made for the purpose of invalidating other (typically, in this group, technical) arguments. If we met in person at a conference (God help us both) and you sat in an open space session picking your nose, would you deem it an "ad hominem attack" if I told you to stop? It sounds like it, even though I would tell you to stop not so that others would respect your technical arguments any less, but because by departing from the accepted standards of behavior you would offend others. > >> In your terms, your accusing me of bullying behavior is an ad hominem >> attack on me, so I won't bother to respond further. > > You're complaining about the person you're hitting saying clearly what > you did. > > If some truthful words about bullying can get you straight I'm for it. > > Even if it means getting down to your level (and yes, I did). > Nope, I'm not complaining at all. That's your tactic: "look, Steve is hitting me". You are entitled to write what you like on this newsgroup, but you have to accept that it will have consequences. I am simply pointing out that what's sauce for the goose is sauce for the gander. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Feb 11 10:59:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 10:59:49 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > * Steven D'Aprano: [...] >> accusing them of lying for having an opinion that differs from yours, > > That is untrue. > Well, that says it all really. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mrkafk at gmail.com Thu Feb 11 11:17:44 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 17:17:44 +0100 Subject: Any way to turn off exception handling? (debugging) Message-ID: Hello everyone, I'm getting an exception (on socket) handled in a program I'm trying to debug. I have trouble locating where exactly that happens. In such situation turning exception handling off could be useful, bc unhandled exception stack trace is precisely what I'm trying to obtain. Anybody knows of such possibility? Regards, mk From martin.hellwig at dcuktec.org Thu Feb 11 11:23:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Feb 2010 16:23:34 +0000 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: On 02/05/10 19:53, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > > Thanks For me personally I do the following: spam_get/spam_set; might be preferred if you have more spam_* functions (i.e. spam_del, spam_eat, etc.) set_spam/get_spam; is I think reasonable if you have also a *_ham function (i.e. set_ham, get_ham). Funny thing for me is that when I have both spam_* & *_ham naming, I usually rethink my approach and split it out to separate classes/modules. Please note that this is at the moment a personal, uneducated, never really thought about it, preference. Meaning it is very likely that with some more insight there is a good chance that I find my approach in retrospect flawed. -- mph From jpiitula at ling.helsinki.fi Thu Feb 11 11:23:38 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 Feb 2010 18:23:38 +0200 Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Robert Kern writes: > On 2010-02-11 06:31 AM, Shashwat Anand wrote: > > There is a little issue here that '>>> -.1 ** .1' should give you > > error message. That is it. > > No, fractional powers of negative numbers are perfectly valid > mathematically. The result is a complex number. In Python 3 (what > the OP is using), this has been implemented, but not in Python 2.6. Perhaps it should raise a MisleadingSpacingError at compile time. The error message could recommend - .1**.1, or better -(.1 ** .1). From steve at holdenweb.com Thu Feb 11 11:27:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 11:27:17 -0500 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: Message-ID: mk wrote: > Hello everyone, > > I'm getting an exception (on socket) handled in a program I'm trying to > debug. I have trouble locating where exactly that happens. > > In such situation turning exception handling off could be useful, bc > unhandled exception stack trace is precisely what I'm trying to obtain. > > Anybody knows of such possibility? > > Regards, > mk > If the exception is currently being trapped by a handler in your code you could just insert a "raise" statement at the start of that handler. This will re-raise the same exception, which will presumably not be caught a second time? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 11 11:41:58 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 11 Feb 2010 17:41:58 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <4b743340$0$20738$426a74cc@news.free.fr> catonano a ?crit : (snip) > Today, I tried to understand the twisted.web.client code and I found 3 > methods I couldn't find by who were called. > > I asked on the mailing list and they suggested me where they were > called and that the tool for such thing is "grep". > > So, you grep, you get a list of files, you open each one of them and > keep scrolling May I suggest reading grep's FineManual ? with proper options, you'll get not only the file, but also the exact lines (and lineno) where the expression appears. > If it's this, then it's not experimental at all, it's been done > already and been put apart. > > Crap won :-( Ever read "worst is better" ?-) Now, image-based systems like Smalltalk do have their share of quirks and drawbacks too. Also, Smalltalk's toolbox can only be used by and for Smalltalk. A bit autistic, he ? I'm doing mostly web development nowadays. That means that I'm constantly switching between server-side code (mostly Python or PHP but can be almost any other language), shell scripts, SQL, html + whatever templating language is used by this project, javascript and css. And of course quite a few configuration file formats... So well, as far as I'm concerned, not having to learn 42+ different toolboxes is a big plus (having to remember 42+ different languages is already hard enough) - I can use a same code editor (Emacs) and standard unix/linux text-handling tools on all my codebase. From aahz at pythoncraft.com Thu Feb 11 11:43:45 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 08:43:45 -0800 Subject: Terminating threaded programs References: Message-ID: In article , mk wrote: > >I have a problem with a threaded program: it frequently hangs on sys.exit. > >The problem is that my program uses threads which in turn use paramiko >library, which itself is threaded. > >I try to gracefully close the threads (below), but it doesn't always >work, if paramiko calls happen to be at stage of negotiating ssh >connection or smth similar. > >The only workable solution I have is a program sending itself SIGKILL, >which makes it terminated by OS (I think so). You can also use os._exit(). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From mrkafk at gmail.com Thu Feb 11 11:45:05 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 17:45:05 +0100 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: kj wrote: > I have read a *ton* of stuff on Unicode. It doesn't even seem all > that hard. Or so I think. Then I start writing code, and WHAM: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) > > (There, see? My Unicodephobia just went up a notch.) > > Here's the thing: I don't even know how to *begin* debugging errors > like this. This is where I could use some help. >>> a=u'\u0104' >>> >>> type(a) >>> >>> nu=a.encode('utf-8') >>> >>> type(nu) See what I mean? You encode INTO string, and decode OUT OF string. To make matters more complicated, str.encode() internally DECODES from string into unicode: >>> nu '\xc4\x84' >>> >>> type(nu) >>> nu.encode() Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128) There's logic to this, although it makes my brain want to explode. :-) Regards, mk From mgulsoy at gmail.com Thu Feb 11 11:45:30 2010 From: mgulsoy at gmail.com (M3RT) Date: Thu, 11 Feb 2010 08:45:30 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: Hi, The problem may be related to how you treat the EDI file or lets say DATA. Also your coding style is important. Can you provide more info? From mrkafk at gmail.com Thu Feb 11 11:47:59 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 17:47:59 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: Message-ID: Steve Holden wrote: >> I'm getting an exception (on socket) handled in a program I'm trying to >> debug. I have trouble locating where exactly that happens. > If the exception is currently being trapped by a handler in your code It's not my code. > you could just insert a "raise" statement at the start of that handler. > This will re-raise the same exception, which will presumably not be > caught a second time? I don't know where the handler is, that is precisely a problem. I'm trying to locate that handler. Regards, mk From simon at brunningonline.net Thu Feb 11 12:07:46 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 11 Feb 2010 17:07:46 +0000 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: Message-ID: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> On 11 February 2010 16:17, mk wrote: > I'm getting an exception (on socket) handled in a program I'm trying to > debug. I have trouble locating where exactly that happens. > > In such situation turning exception handling off could be useful, bc > unhandled exception stack trace is precisely what I'm trying to obtain. > > Anybody knows of such possibility? Not as far as I know. Besides, the chances are that if you were to be able to turn off exception handling altogether your code wouldn't make it as far as the code you are interested in anyway. Is there some way you could monkey patch the exception class to add some logging in there or something? -- Cheers, Simon B. From hjebbers at gmail.com Thu Feb 11 12:12:20 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 09:12:20 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On Feb 11, 5:45?pm, M3RT wrote: > Hi, > > The problem may be related to how you treat the EDI file or lets say > DATA. Also your coding style is important. Can you provide more info? Yes, a whole lot more; but I do not want to bother you with that now. I was just wondering if it is possible that the same setup gives a CRASH! on windows and just works on linux. (where is the bug?) kind regards, henk-jan From coldtortuga at gmail.com Thu Feb 11 12:30:04 2010 From: coldtortuga at gmail.com (Francis Carr) Date: Thu, 11 Feb 2010 09:30:04 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <5b51740d-11f1-4f01-b51c-d1b6ea161eb7@l19g2000yqb.googlegroups.com> > I can't believe the code editing situation today is in a such sorry > state. I can't believe an old coder is feeling so sorry for himself. > Today, I tried to understand the twisted.web.client code and I found 3 > methods I couldn't find by who were called. > > I asked on the mailing list and they suggested me where they were > called and that the tool for such thing is "grep". > > So, you grep, you get a list of files, you open each one of them and > keep scrolling and switching from one file to another... endlessly. > Maybe I'm getting old, but I tend to get lost in the process. Maybe the relevant lesson to be taken from Smalltalk is *not* "put it all in one image" but instead "write code to solve problems, e.g., reading code" I suggest defining a few shell functions to *automate* the search, for example in zsh function allf () { # Recursively find files with suffix matching comma-separated list in $1. # For example, "allf cpp,hpp" finds all "*.cpp" and "*.hpp". find . -type f | grep -E "\.(${1//,/|})$" } function src () { # Similar to "allf", then search for a regex among the results. find . -type f -print0 | grep -zE "\.(${1//,/|})$" | xargs -0 grep - lE $2 } function srcl () { # Similar to "src" (see above), # then search for a pattern among the results, # and pass matching files to "less". src $1 $2 | xargs less -p $2 } Smalltalk's images are cool. But they are such a huge hammer, and they impose so many additional requirements! The costs outweigh the cool. -- FC From mrkafk at gmail.com Thu Feb 11 12:32:55 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 18:32:55 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> Message-ID: Simon Brunning wrote: > Not as far as I know. Besides, the chances are that if you were to be > able to turn off exception handling altogether your code wouldn't make > it as far as the code you are interested in anyway. Sure, but I could deal with that, jerry-rigging the code as exceptions go by, finally reaching the exception I care about. With all the problems, this would still be much better than nothing. As thing are, the only way to do this is guessing and turning particular try / except blocks off. (a really nifty solution would be turning exceptions on or off per module / file basis). IIRC Lua and/or C++ do have this ability, why not Python? I smell material for a PEP. > Is there some way you could monkey patch the exception class to add > some logging in there or something? Sure I can, but how do I get out of Python the info *what called particular class/instance*? That is, how do I know who's the caller? Regards, mk From no.email at please.post Thu Feb 11 12:37:27 2010 From: no.email at please.post (kj) Date: Thu, 11 Feb 2010 17:37:27 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: In mk writes: >To make matters more complicated, str.encode() internally DECODES from >string into unicode: > >>> nu >'\xc4\x84' > >>> > >>> type(nu) > > >>> nu.encode() >Traceback (most recent call last): > File "", line 1, in >UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: >ordinal not in range(128) >There's logic to this, although it makes my brain want to explode. :-) Thanks for pointing this one out! It could have easily pushed my Unicodephobia into the incurable zone... ~K From apt.shansen at gmail.com Thu Feb 11 12:45:52 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 11 Feb 2010 09:45:52 -0800 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> Message-ID: <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> On Thu, Feb 11, 2010 at 9:32 AM, mk wrote: > Simon Brunning wrote: > >> Not as far as I know. Besides, the chances are that if you were to be >> able to turn off exception handling altogether your code wouldn't make >> it as far as the code you are interested in anyway. >> > > Sure, but I could deal with that, jerry-rigging the code as exceptions go > by, finally reaching the exception I care about. > > With all the problems, this would still be much better than nothing. As > thing are, the only way to do this is guessing and turning particular try / > except blocks off. > > (a really nifty solution would be turning exceptions on or off per module / > file basis). > > IIRC Lua and/or C++ do have this ability, why not Python? > > I smell material for a PEP. Um, Lua has nothing even vaguely like Python's exceptions. It has errors, and you can "catch" them only by doing a protected call. Otherwise they halt the entire interpreter. Python exceptions are pervasive. I don't think you fully understand HOW pervasive they are-- "turning off" exceptions would utterly break a -vast- amount of Python code. Exceptions are not errors: exceptions are the uncommon, the exceptional, case. If one could somehow turn off exceptions, you can't even do a for loop: every for loop would become infinite-- exceptions are how Python signals the end of an iterator. Think about that, *every* for loop in Python suddenly breaks. They're also used in countless other areas which are simply not errors. > Is there some way you could monkey patch the exception class to add >> some logging in there or something? >> > > Sure I can, but how do I get out of Python the info *what called particular > class/instance*? That is, how do I know who's the caller? > Um... run your code in a debugger. That's what debugger's are -for-. "pdb" is a simple one. Various IDE's have more advanced ones. I think you're better served showing us what, "I'm getting an exception (on socket) handled..." actually means, what is actually happening with real code and output, and getting pointers on where to look, then trying to gather material to support an honestly impossible change :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Feb 11 12:46:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 17:46:29 +0000 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: <4B744275.4000503@mrabarnett.plus.com> mk wrote: > kj wrote: >> I have read a *ton* of stuff on Unicode. It doesn't even seem all >> that hard. Or so I think. Then I start writing code, and WHAM: >> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position >> 0: ordinal not in range(128) >> >> (There, see? My Unicodephobia just went up a notch.) >> >> Here's the thing: I don't even know how to *begin* debugging errors >> like this. This is where I could use some help. > > >>> a=u'\u0104' > >>> > >>> type(a) > > >>> > >>> nu=a.encode('utf-8') > >>> > >>> type(nu) > > > > See what I mean? You encode INTO string, and decode OUT OF string. > Traditionally strings were string of byte-sized characters. Because they were byte-sided they could also be used to contain binary data. Then along came Unicode. When working with Unicode in Python 2, you should use the 'unicode' type for text (Unicode strings) and limit the 'str' type to binary data (bytestrings, ie bytes) only. In Python 3 they've been renamed to 'str' for Unicode _strings_ and 'bytes' for binary data (bytes!). > To make matters more complicated, str.encode() internally DECODES from > string into unicode: > > >>> nu > '\xc4\x84' > >>> > >>> type(nu) > > >>> nu.encode() > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: > ordinal not in range(128) > > There's logic to this, although it makes my brain want to explode. :-) > Strictly speaking, only Unicode can be encoded. What Python 2 is doing here is trying to be helpful: if it's already a bytestring then decode it first to Unicode and then re-encode it to a bytestring. Unfortunately, the default encoding is ASCII, and the bytestring isn't valid ASCII. Python 2 is being 'helpful' in a bad way! From __peter__ at web.de Thu Feb 11 13:01:15 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Feb 2010 19:01:15 +0100 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: hjebbers wrote: > On Feb 11, 5:45 pm, M3RT wrote: >> The problem may be related to how you treat the EDI file or lets say >> DATA. Also your coding style is important. Can you provide more info? > > Yes, a whole lot more; but I do not want to bother you with that now. > I was just wondering if it is possible that the same setup gives a > CRASH! on windows and just works on linux. > (where is the bug?) In the platform-specific code ;) Even on alt.haruspicy they cannot do much without a liver now and then... From python at mrabarnett.plus.com Thu Feb 11 13:06:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 18:06:34 +0000 Subject: ANN: obfuscate In-Reply-To: <4B73D1E8.9040603@cheimes.de> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> Message-ID: <4B74472A.6010301@mrabarnett.plus.com> Christian Heimes wrote: > Gregory Ewing wrote: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the >> German forces that used their Enigmas differently, avoiding those >> mistakes, and the British never managed to crack any of their >> messages. > > IIRC some versions of the Enigma weren't cracked because they used a > different setup and different daily keys. > > The predecessor of the Enigma was cracked by Polish scientists years > before WW2 started. Some flaws in the instructions and a known plain > text attack made the crack of the Enigma practical. It took the > British scientists merely hours rather than days or weeks to decipher > the daily key with some smart tricks. For example they started fake > attacks on ships or cities just to have the names in some encrypted > reports. > In some cases the British had decoded the messages before the intended recipient! The Americans decoded Japanese messages about an planned attack on an island, but didn't know which one because of the fake names, so they instructed their bases to report certain problems in a way that the Japanese could decode. Midway reported a shortage of water, the Japanese decoded it and sent a message about it, the Americans decoded their message and discovered that island's fake name, and thus found out that Midway was the intended target of the attack. From no.email at nospam.invalid Thu Feb 11 13:14:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Feb 2010 10:14:39 -0800 Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: <7xpr4bwsfk.fsf@ruckus.brouhaha.com> mk writes: >> Um... run your code in a debugger. > > ..except the code in question is multithreaded and pdb is no good for > that, and last time I checked, yappi was broken. Try winpdb.org. From mrkafk at gmail.com Thu Feb 11 13:19:52 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 19:19:52 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: > the uncommon, the exceptional, case. If one could somehow turn off > exceptions, you can't even do a for loop: every for loop would become > infinite-- exceptions are how Python signals the end of an iterator. > Think about that, *every* for loop in Python suddenly breaks. Ouch. > Sure I can, but how do I get out of Python the info *what called > particular class/instance*? That is, how do I know who's the caller? > > > Um... run your code in a debugger. ..except the code in question is multithreaded and pdb is no good for that, and last time I checked, yappi was broken. > > That's what debugger's are -for-. > > "pdb" is a simple one. Various IDE's have more advanced ones. I tried using pdb on paramiko and my own threaded code, lost some hair in the process, and gave up. It's good for tracing the main thread, basically, not for threading.Threads. > I think you're better served showing us what, "I'm getting an exception > (on socket) handled..." actually means, what is actually happening with > real code and output, and getting pointers on where to look, then trying > to gather material to support an honestly impossible change :) I'm using a threaded library paramiko (probably by now half of this group is sick of hearing me saying this again). 2 of (rather broken) hosts (Solaris, Linux) are really, really slow when responding over SSH, like a minute for a key exchange. In paramiko, timeout doesn't work bc the timeout specified there is timeout for a socket and not for SSH. When calling transport.socket.close() via threading.Timer like this: def printandclose(self): print "\ntrying to close transport.sock" self.trans.sock.close() self.flag = True self.flag = False timer = threading.Timer(4, self.printandclose) timer.start() self.trans.start_client() timer.cancel() ... I'm getting this on the console: ERROR (9, 'Bad file descriptor') According to a guy who is very knowledgable on the library (thanks for all the help, James) this is result of catching socket.error somewhere in paramiko code, like "except socket.error". I need to find that place. On top of lack of proper handling of timeouts, this is important bc when calling paramiko SSHClient.connect() (which in turn uses the same machinery as transport.start_client IIRC) paramiko uses close to 100% of CPU when negotiating with such broken or unresponsive hosts. For my reasons, I need to get this fixed. Regards, mk From mrkafk at gmail.com Thu Feb 11 13:24:31 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 19:24:31 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Stephen Hansen wrote: > the uncommon, the exceptional, case. If one could somehow turn off > exceptions, you can't even do a for loop: every for loop would become > infinite-- exceptions are how Python signals the end of an iterator. > Think about that, *every* for loop in Python suddenly breaks. Hmm what if one could turn off exception handling for particular exception classes? From mrabarnett at mrabarnett.plus.com Thu Feb 11 13:24:32 2010 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Thu, 11 Feb 2010 18:24:32 +0000 Subject: ANN: obfuscate In-Reply-To: <7x6364gg8t.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <7x6364gg8t.fsf@ruckus.brouhaha.com> Message-ID: <4B744B60.8070202@mrabarnett.plus.com> Paul Rubin wrote: > Gregory Ewing writes: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the German >> forces that used their Enigmas differently, avoiding those mistakes, >> and the British never managed to crack any of their messages. > > I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they > were more careful with procedures, but the machine was also harder to > crack because it had four rotors instead of three. IIRC, the Brits were > eventually (1942?) able to capture one by shooting up a German submarine > and boarding it to get the machine while the sub was sinking; a British > sailor wasn't able to get out in time and drowned during that operation. > Getting the rotor settings off the captured unit (they may have had to > do it more than once) was enough to get a foothold into the code. My > memory is hazy on this by now so I may have some parts wrong, but David > Kahn's book "Seizing the Enigma" tells the story (I read it many years > ago). A fictionalized version appears in Neil Stephenson's novel > "Cryptonomicon". U-559? I think that's the one where Hollywood made a film about it, but portraying it as a purely American action. That didn't go down too well in the UK! From python at mrabarnett.plus.com Thu Feb 11 13:24:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 18:24:52 +0000 Subject: ANN: obfuscate In-Reply-To: <7x6364gg8t.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <7x6364gg8t.fsf@ruckus.brouhaha.com> Message-ID: <4B744B74.30309@mrabarnett.plus.com> Paul Rubin wrote: > Gregory Ewing writes: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the German >> forces that used their Enigmas differently, avoiding those mistakes, >> and the British never managed to crack any of their messages. > > I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they > were more careful with procedures, but the machine was also harder to > crack because it had four rotors instead of three. IIRC, the Brits were > eventually (1942?) able to capture one by shooting up a German submarine > and boarding it to get the machine while the sub was sinking; a British > sailor wasn't able to get out in time and drowned during that operation. > Getting the rotor settings off the captured unit (they may have had to > do it more than once) was enough to get a foothold into the code. My > memory is hazy on this by now so I may have some parts wrong, but David > Kahn's book "Seizing the Enigma" tells the story (I read it many years > ago). A fictionalized version appears in Neil Stephenson's novel > "Cryptonomicon". U-559? I think that's the one where Hollywood made a film about it, but portraying it as a purely American action. That didn't go down too well in the UK! From __peter__ at web.de Thu Feb 11 13:35:59 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Feb 2010 19:35:59 +0100 Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: mk wrote: > >> the uncommon, the exceptional, case. If one could somehow turn off >> exceptions, you can't even do a for loop: every for loop would become >> infinite-- exceptions are how Python signals the end of an iterator. >> Think about that, *every* for loop in Python suddenly breaks. > > Ouch. > >> Sure I can, but how do I get out of Python the info *what called >> particular class/instance*? That is, how do I know who's the caller? >> >> >> Um... run your code in a debugger. > > ..except the code in question is multithreaded and pdb is no good for > that, and last time I checked, yappi was broken. > >> >> That's what debugger's are -for-. >> >> "pdb" is a simple one. Various IDE's have more advanced ones. > > I tried using pdb on paramiko and my own threaded code, lost some hair > in the process, and gave up. It's good for tracing the main thread, > basically, not for threading.Threads. > >> I think you're better served showing us what, "I'm getting an exception >> (on socket) handled..." actually means, what is actually happening with >> real code and output, and getting pointers on where to look, then trying >> to gather material to support an honestly impossible change :) > > I'm using a threaded library paramiko (probably by now half of this > group is sick of hearing me saying this again). 2 of (rather broken) > hosts (Solaris, Linux) are really, really slow when responding over SSH, > like a minute for a key exchange. In paramiko, timeout doesn't work bc > the timeout specified there is timeout for a socket and not for SSH. > > When calling transport.socket.close() via threading.Timer like this: > > def printandclose(self): > print "\ntrying to close transport.sock" > self.trans.sock.close() > self.flag = True > > > self.flag = False > timer = threading.Timer(4, self.printandclose) > timer.start() > self.trans.start_client() > timer.cancel() > > ... I'm getting this on the console: > > ERROR (9, 'Bad file descriptor') > > According to a guy who is very knowledgable on the library (thanks for > all the help, James) this is result of catching socket.error somewhere > in paramiko code, like "except socket.error". > > I need to find that place. On top of lack of proper handling of > timeouts, this is important bc when calling paramiko SSHClient.connect() > (which in turn uses the same machinery as transport.start_client IIRC) > paramiko uses close to 100% of CPU when negotiating with such broken or > unresponsive hosts. > > For my reasons, I need to get this fixed. You could try to shadow the exception class with None: >>> ZeroDivisionError = None >>> try: ... 1/0 ... except ZeroDivisionError: ... print "caught" ... Traceback (most recent call last): File "", line 2, in ZeroDivisionError: integer division or modulo by zero Applying that technique on a module containing try: ... except socket.error: ... #untested import socket class SocketWrapper: def __getattr__(self, name): return getattr(socket, name) error = None import module_using_socket module_using_socket.socket = SocketWrapper() Peter From steve at holdenweb.com Thu Feb 11 13:42:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 13:42:08 -0500 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: mk wrote: > Stephen Hansen wrote: >> the uncommon, the exceptional, case. If one could somehow turn off >> exceptions, you can't even do a for loop: every for loop would become >> infinite-- exceptions are how Python signals the end of an iterator. >> Think about that, *every* for loop in Python suddenly breaks. > > Hmm what if one could turn off exception handling for particular > exception classes? > An extension of the warnings mechanism might be the easiest way to play with an implementation ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From invalid at invalid.invalid Thu Feb 11 13:43:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 11 Feb 2010 18:43:23 +0000 (UTC) Subject: Bizarre arithmetic results References: Message-ID: On 2010-02-11, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? Didn't we just do this one last week? -- Grant Edwards grante Yow! Hello? Enema Bondage? at I'm calling because I want visi.com to be happy, I guess ... From breamoreboy at yahoo.co.uk Thu Feb 11 13:53:04 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 11 Feb 2010 18:53:04 +0000 Subject: ANN: obfuscate In-Reply-To: <4B73D1E8.9040603@cheimes.de> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> Message-ID: Christian Heimes wrote: > Gregory Ewing wrote: >> Actually I gather it had a lot to do with the fact that >> the Germans made some blunders in the way they used the >> Enigma that seriously compromised its security. There >> was reportedly a branch of the German forces that used >> their Enigmas differently, avoiding those mistakes, and >> the British never managed to crack any of their messages. > > IIRC some versions of the Enigma weren't cracked because they used a > different setup and different daily keys. > > The predecessor of the Enigma was cracked by Polish scientists years > before WW2 started. Some flaws in the instructions and a known plain > text attack made the crack of the Enigma practical. It took the British > scientists merely hours rather than days or weeks to decipher the daily > key with some smart tricks. For example they started fake attacks on > ships or cities just to have the names in some encrypted reports. I believe that all of Enigma was eventually cracked cos of two major flaws. 1) A letter could never be sent as itself. 2) The Luftwaffe were very poor when compared to the Wehrmacht or Kriegsmarine about security so they were a major leak of data regarding the other organisations. 3) The users instead of using random three letter combinations kept using the same ones. HIT LER and BER LIN were popular, but the most famous one at Bletchley Park was the name of the guy's girlfriend. Further, the far more powerful Geheimscreiber was also cracked at Bletchley by using Colossus. Sorry some years since I read the book about this so can't remember the title or author. Regards. Mark Lawrence. From ssteinerx at gmail.com Thu Feb 11 13:57:29 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Thu, 11 Feb 2010 13:57:29 -0500 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: <15A7B7FA-BE34-4A6B-9D84-47CF3683E6DA@gmail.com> On Feb 11, 2010, at 11:43 AM, Aahz wrote: > In article , > mk wrote: >> >> I have a problem with a threaded program: it frequently hangs on sys.exit. >> >> The problem is that my program uses threads which in turn use paramiko >> library, which itself is threaded. >> >> I try to gracefully close the threads (below), but it doesn't always >> work, if paramiko calls happen to be at stage of negotiating ssh >> connection or smth similar. >> >> The only workable solution I have is a program sending itself SIGKILL, >> which makes it terminated by OS (I think so). > > You can also use os._exit(). This just came up on the Twisted IRC channel last night and came to the same conclusion. Python's going to wait for threads to terminate and if they're not going to, neither is Python. os._exit() came up as the 'last resort' way out of the app. S From mrkafk at gmail.com Thu Feb 11 14:10:30 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 20:10:30 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <7xpr4bwsfk.fsf@ruckus.brouhaha.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> <7xpr4bwsfk.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > mk writes: >>> Um... run your code in a debugger. >> ..except the code in question is multithreaded and pdb is no good for >> that, and last time I checked, yappi was broken. > > Try winpdb.org. This is a treasure! In minutes I've had this attached to remote process and debugging threads. Muchos gracias Paul! Regards, mk From mattbarkan at gmail.com Thu Feb 11 14:11:51 2010 From: mattbarkan at gmail.com (galileo228) Date: Thu, 11 Feb 2010 11:11:51 -0800 (PST) Subject: python and http POST Message-ID: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Hey All, Been teaching myself Python for a few weeks, and am trying to write a program that will go to a url, enter a string in one of the search fields, submit the search, and return the contents of the search result. I'm using httplib2. My two particular questions: 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), how do I know what the particular key should be? In other words, how do I tell python which form on the web page I'm visiting I'd like to fill in? Do I simply go to the webpage itself and look at the html source? But if that's the case, which tag tells me the name of the key? 2) Even once python fills in the form properly, how can I tell it to 'submit' the search? Thanks all! Matt From mrkafk at gmail.com Thu Feb 11 14:12:23 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 20:12:23 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Peter Otten wrote: > try: > ... > except socket.error: > ... > > #untested > import socket > > class SocketWrapper: > def __getattr__(self, name): > return getattr(socket, name) > error = None > > import module_using_socket > module_using_socket.socket = SocketWrapper() Very interesting solution. Thanks! Regards, mk From hjebbers at gmail.com Thu Feb 11 14:19:08 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 11:19:08 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On Feb 11, 7:01?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 5:45 pm, M3RT wrote: > >> The problem may be related to how you treat the EDI file or lets say > >> DATA. Also your coding style is important. Can you provide more info? > > > Yes, a whole lot more; but I do not want to bother you with that now. > > I was just wondering if it is possible that the same setup gives a > > CRASH! on windows and just works on linux. > > (where is the bug?) > > In the platform-specific code ;) > > Even on alt.haruspicy they cannot do much without a liver now and then... if it is in the platform-specific code should I make this into a bugreport? (because the crash does not appear at the same place in my code (when doing the same test-run) it will be quite hard to point down....) henk-jan From hjebbers at gmail.com Thu Feb 11 14:30:22 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 11:30:22 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On Feb 11, 7:01?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 5:45 pm, M3RT wrote: > >> The problem may be related to how you treat the EDI file or lets say > >> DATA. Also your coding style is important. Can you provide more info? > > > Yes, a whole lot more; but I do not want to bother you with that now. > > I was just wondering if it is possible that the same setup gives a > > CRASH! on windows and just works on linux. > > (where is the bug?) > > In the platform-specific code ;) > > Even on alt.haruspicy they cannot do much without a liver now and then... if it is in the platform-specific code should I make this into a bugreport? (because the crash does not appear at the same place in my code (when doing the same test-run) it will be quite hard to point down....) henk-jan From danijel.gvero at gmail.com Thu Feb 11 14:31:52 2010 From: danijel.gvero at gmail.com (DANNY) Date: Thu, 11 Feb 2010 11:31:52 -0800 (PST) Subject: MODULE FOR I, P FRAME Message-ID: Hello! I am currently developing a simple video player in python, and my problem is that i can't find a module which has a function that can determine if frame(image) is I or P coded (MPEG coding). I have been using PIL but I couldnt find anything that could help me with that problem. Thanks for sugestions! From hjebbers at gmail.com Thu Feb 11 14:40:39 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 11:40:39 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> On Feb 11, 7:01?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 5:45 pm, M3RT wrote: > >> The problem may be related to how you treat the EDI file or lets say > >> DATA. Also your coding style is important. Can you provide more info? > > > Yes, a whole lot more; but I do not want to bother you with that now. > > I was just wondering if it is possible that the same setup gives a > > CRASH! on windows and just works on linux. > > (where is the bug?) > > In the platform-specific code ;) > > Even on alt.haruspicy they cannot do much without a liver now and then... if it is in the platform-specific code should I make this into a bugreport? (because the crash does not appear at the same place in my code (when doing the same test-run) it will be quite hard to point down....) henk-jan From malaclypse2 at gmail.com Thu Feb 11 14:42:42 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 11 Feb 2010 14:42:42 -0500 Subject: python crash on windows but not on linux In-Reply-To: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <16651e81002111142g1447cd87t74e7f932873e7fac@mail.gmail.com> On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > To all, > I am running an EDI translator, and doing stress tests. > When processing a test with a (relatively) big EDI file(s) on > windowsXP ?I get a crash: > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > causing the problem) > You need to give us more information if we're going to be able to help. At the very least, you'll need to copy & paste the actual error message. It would be even better if you could show us some of your code, and better yet if you could give us a small bit of code that is self contained and reproduces the problem you're experiencing. -- Jerry From nathan.farrar at gmail.com Thu Feb 11 14:47:24 2010 From: nathan.farrar at gmail.com (Nathan Farrar) Date: Thu, 11 Feb 2010 12:47:24 -0700 Subject: PExpect Cross-Platform Alternative Message-ID: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Hello Community, Recently I've been automating lots of network operations tasks via simple python scripts. Originally, I utilized paramiko but found that the module had issues working with cisco equipment. I switched to pexpect and things have worked wonderfully since (I've been running this scripts in a Linux environment). However, I was just tasked to get these scripts running in a windows environment and to my dismay very quickly realized that pexpect is not cross platform compatible. Am I stuck, or are there solutions out there? Cheers! Nathan -- The men the American people admire most extravagantly are the most daring liars; the men they detest most violently are those who try to tell them the truth. -- H. L. Mencken -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 11 14:55:54 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 20:55:54 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steven D'Aprano: > [...] >>> accusing them of lying for having an opinion that differs from yours, >> That is untrue. >> > Well, that says it all really. You seem to insinuate that I'm saying that Steven is lying, and/or that Steven is lying. From context and your earlier similar behavior, I presume the former only. Anyway that's a *very* dirty insinuation. And ... It seems you *do not understand* the difference between an incorrect statement and a lie. Which is very telling, I'm sorry. And you have yet again concentrated on a personal attack via insinuation etc., diversion, which also is very telling, sorry. Cheers, - Alf From steve at holdenweb.com Thu Feb 11 14:57:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 14:57:39 -0500 Subject: PExpect Cross-Platform Alternative In-Reply-To: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> References: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Message-ID: Nathan Farrar wrote: > Hello Community, > > Recently I've been automating lots of network operations tasks via > simple python scripts. Originally, I utilized paramiko but found that > the module had issues working with cisco equipment. I switched to > pexpect and things have worked wonderfully since (I've been running this > scripts in a Linux environment). However, I was just tasked to get > these scripts running in a windows environment and to my dismay very > quickly realized that pexpect is not cross platform compatible. > > Am I stuck, or are there solutions out there? > It works pretty well under Cygwin (which also improves your Windows scripting environment no end). Any chance you would be allowed to install that? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ken at seehart.com Thu Feb 11 14:58:53 2010 From: ken at seehart.com (Ken Seehart) Date: Thu, 11 Feb 2010 11:58:53 -0800 Subject: python and http POST In-Reply-To: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <4B74617D.90709@seehart.com> "Use tamperdata to view and modify HTTP/HTTPS headers and post parameters... " https://addons.mozilla.org/en-US/firefox/addon/966 Enjoy, Ken galileo228 wrote: > Hey All, > > Been teaching myself Python for a few weeks, and am trying to write a > program that will go to a url, enter a string in one of the search > fields, submit the search, and return the contents of the search > result. > > I'm using httplib2. > > My two particular questions: > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > how do I know what the particular key should be? In other words, how > do I tell python which form on the web page I'm visiting I'd like to > fill in? Do I simply go to the webpage itself and look at the html > source? But if that's the case, which tag tells me the name of the > key? > > 2) Even once python fills in the form properly, how can I tell it to > 'submit' the search? > > Thanks all! > > Matt > From alfps at start.no Thu Feb 11 15:16:43 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 21:16:43 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: > [...] >>> In this particular part of the thread I am attempting, unsuccessfully, >>> to convince you that a change in *your* behavior would lead to less >>> hostility directed towards the way you present your ideas. >>> >>> You apparently feel it is quite acceptable to tell people to "learn to >>> read", >> I have not used that expression. >> >> However I have suggest and emphasized that it might help to *read* >> whatever one quotes, when the quoted material (such as one paragraph) >> has not been read. >> >> Telling someone to "learn to read" is a Steve Holden'sk way to imply >> that the person is an ignoramus who hasn't bothered to learn to read. >> Telling a person to read something that's obviously not been read is >> quite another matter. So, you are misrepresenting -- again -- and in >> a quite revealing way, sorry. >> > Pardon me? You used it on December 16 in a response to Mensanator in > message > > M :> How about devoting a section on downloading the source files > M :> and compiling it on a Mac? > > AS:> Learn to read. > > AS:> At the top of every second page it tells you that this is an > AS:> introduction based on Windows. > > I am sure you will have some glib response as to why this wasn't rude at > all. Allow me to correct you - it was, and rudeness is not welcomed on > comp.lang.python. That doesn't mean it doesn't happen (why, I have even > been known to be rude myself - we are none of us perfect, after all). > > I have already given ample evidence that when I am wrong I will admit > it. You, contrariwise, maintain that you will admit when you are wrong > (I believe 40% of the time was the figure you used) No, 40% of contested cases. But that was sort of a white lie. I'm not that often wrong, and anyway it doesn't apply to me in [comp.lang.python] so far. It only applies to groups where only things that might be incorrect are challenged. > but I fail to > remember any single incident when you made such an admission. Your memory seems to be very very bad, since I've stated I've been wrong also in direct debates with you. But one person who /does/ have severe trouble admitting that he's wrong, going to the extreme of ad hominem attacks and using terms such as "wring" to avoid saying it (it's quite amazing, almost unbelievable) is Steve Holden. Anyway, I was wrong about not having used that phrase "learn to read". I'm not sure if I ever apologized directly to Mensanator for that, and now it's history, but what I do know I did was to follow up on that comment of his, making changes, and to acknowledge him for that in the [ack.txt] listing. Any reader might draw conclusions from that, e.g. what I positively did or what I possibly forgot to do -- we're not perfect beings any of us. [Steve Holden rambling with personal characterizations & circular logic snipped] Cheers & hth., - Alf From mrkafk at gmail.com Thu Feb 11 15:17:54 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 21:17:54 +0100 Subject: Terminating threaded programs In-Reply-To: <7a9c25c21002081816r3b7a7c4fq5b079424dbd1f46e@mail.gmail.com> References: <7a9c25c21002081816r3b7a7c4fq5b079424dbd1f46e@mail.gmail.com> Message-ID: Stephen Hansen wrote: > I use threads all the time (well, for certain types of workloads) and > have never seen this. > > Are your threads daemon threads? The only time I've seen sys.exit() not > close out my program is when I'm launching non-daemon threads on accident. The snag is that my program is using calls to another threaded library (paramiko) which does lots of stuff with sockets and communication (SSH). Paramiko in turn calls Crypto which has compiled C extensions. I really don't know what's going on in there, just guessing that this might trigger this behavior. > Now, I do get some slightly random errors on close due to threads doing > stuff or returning from doing stuff while the shutdown procedure is > going on, but I don't really care, cuz, well, I'm shutting everything > down and nothing worth knowing is going on in the rest of the program. Same as me, except I get lots of exceptions in threads if I shut down with sys.exit. SIGTERM somehow gets around this problem. I'll try os._exit. Regards, mk From mrkafk at gmail.com Thu Feb 11 15:18:16 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 21:18:16 +0100 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: Aahz wrote: > You can also use os._exit(). Thanks! From mrkafk at gmail.com Thu Feb 11 15:22:09 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 21:22:09 +0100 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: Aahz wrote: > You can also use os._exit(). Yes! It works cleanly! Thanks a million! OTOH, if I use sys.exit(), it's just hanging there. Regards, mk From jgardner at jonathangardner.net Thu Feb 11 16:03:22 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 11 Feb 2010 13:03:22 -0800 (PST) Subject: Is a merge interval function available? References: Message-ID: On Feb 10, 3:23?pm, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. For example, if I have the following intervals ('[' > and ']' means closed interval as inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...) > > [1, 3] > [2, 9] > [10,13] > [11,12] > > I want to get the following merged intervals. > > [1,9] > [10,13] > > Could somebody let me know if there is a function in the python > library? I vaguely recall a similar question a long time ago. Peng, is this a homework assignment? Perhaps we should add a standard module called "homework". It can have functions for all the different homework assignments we see on c.l.python. We can simply point people to this module and then can include the code in their answers. From alfps at start.no Thu Feb 11 16:37:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 22:37:46 +0100 Subject: Is a merge interval function available? In-Reply-To: References: Message-ID: * Jonathan Gardner: > On Feb 10, 3:23 pm, Peng Yu wrote: >> I'm wondering there is already a function in python library that can >> merge intervals. For example, if I have the following intervals ('[' >> and ']' means closed interval as inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...) >> >> [1, 3] >> [2, 9] >> [10,13] >> [11,12] >> >> I want to get the following merged intervals. >> >> [1,9] >> [10,13] >> >> Could somebody let me know if there is a function in the python >> library? > > I vaguely recall a similar question a long time ago. Peng, is this a > homework assignment? > > Perhaps we should add a standard module called "homework". It can have > functions for all the different homework assignments we see on > c.l.python. We can simply point people to this module and then can > include the code in their answers. If it's possible, there was/is this guy over in clc.c++ who responded/responds to homework questions with the most advanced, convoluted and, except for misleading names, technically correct solutions. Cheers, - Alf From mrkafk at gmail.com Thu Feb 11 16:43:17 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 22:43:17 +0100 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: <4B744275.4000503@mrabarnett.plus.com> References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: MRAB wrote: > When working with Unicode in Python 2, you should use the 'unicode' type > for text (Unicode strings) and limit the 'str' type to binary data > (bytestrings, ie bytes) only. Well OK, always use u'something', that's simple -- but isn't str what I get from files and sockets and the like? > In Python 3 they've been renamed to 'str' for Unicode _strings_ and > 'bytes' for binary data (bytes!). Neat, except that the process of porting most projects and external libraries to P3 seems to be, how should I put it, standing still? Or am I wrong? But that's the impression I get? Take web frameworks for example. Does any of them have serious plans and work in place to port to P3? > Strictly speaking, only Unicode can be encoded. How so? Can't bytestrings containing characters of, say, koi8r encoding be encoded? > What Python 2 is doing here is trying to be helpful: if it's already a > bytestring then decode it first to Unicode and then re-encode it to a > bytestring. It's really cumbersome sometimes, even if two libraries are written by one author: for instance, Mako and SQLAlchemy are written by the same guy. They are both top-of-the line in my humble opinion, but when you connect them you get things like this: 1. you query SQLAlchemy object, that happens to have string fields in relational DB. 2. Corresponding Python attributes of those objects then have type str, not unicode. 3. then I pass those objects to Mako for HTML rendering. Typically, it works: but if and only if a character in there does not happen to be out of ASCII range. If it does, you get UnicodeDecodeError on an unsuspecting user. Sure, I wrote myself a helper that iterates over keyword dictionary to make sure to convert all str to unicode and only then passes the dictionary to render_unicode. It's an overhead, though. It would be nicer to have it all unicode from db and then just pass it for rendering and having it working. (unless there's something in filters that I missed, but there's encoding of templates, tags, but I didn't find anything on automatic conversion of objects passed to method rendering template) But maybe I'm whining. > Unfortunately, the default encoding is ASCII, and the bytestring isn't > valid ASCII. Python 2 is being 'helpful' in a bad way! And the default encoding is coded in such way so it cannot be changed in sitecustomize (without code modification, that is). Regards, mk From astan.chee at al.com.au Thu Feb 11 16:43:25 2010 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 12 Feb 2010 08:43:25 +1100 Subject: calculating a string equation Message-ID: <4B7479FD.2050400@al.com.au> Hi, I have some variables in my script that looks like this: vars = {'var_a':'10','var_b':'4'} eqat = "(var_a/2.0) <= var_b" result = "(var_a+var_b)/7" What I'm trying to do is to plug in var_a and var_b's values from vars into eqat and see if eqat returns true or false as well as getting the value of result if these variables were "plugged in". How do I do this? I'm also expecting eqat and result to contain various python mathematical operators like **, and compounded ()'s. I'm not sure how to convert the equation; if I have to make a bunch of if-statements or if there is a python function that already does something like this. Thanks for any help. Cheers Astan From robert.kern at gmail.com Thu Feb 11 16:48:12 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Feb 2010 15:48:12 -0600 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: On 2010-02-11 15:43 PM, mk wrote: > MRAB wrote: >> Strictly speaking, only Unicode can be encoded. > > How so? Can't bytestrings containing characters of, say, koi8r encoding > be encoded? I think he means that only unicode objects can be encoded using the .encode() method, as clarified by his next sentence: >> What Python 2 is doing here is trying to be helpful: if it's already a >> bytestring then decode it first to Unicode and then re-encode it to a >> bytestring. -- 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 arnodel at googlemail.com Thu Feb 11 16:50:00 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 11 Feb 2010 21:50:00 +0000 Subject: calculating a string equation References: Message-ID: Astan Chee writes: > Hi, > I have some variables in my script that looks like this: > vars = {'var_a':'10','var_b':'4'} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > What I'm trying to do is to plug in var_a and var_b's values from vars > into eqat and see if eqat returns true or false as well as getting the > value of result if these variables were "plugged in". How do I do > this? > I'm also expecting eqat and result to contain various python > mathematical operators like **, and compounded ()'s. > I'm not sure how to convert the equation; if I have to make a bunch of > if-statements or if there is a python function that already does > something like this. Yes: eval() >>> vars = {'var_a':10 ,'var_b':4} >>> eqat = "(var_a/2.0) <= var_b" >>> result = "(var_a+var_b)/7" >>> eval(eqat, vars) False >>> eval(result, vars) 2 (Note that I have slightly modified your vars dictionary) See a recent thread about the dangers of eval(). -- Arnaud From tjreedy at udel.edu Thu Feb 11 17:11:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 17:11:17 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: On 2/11/2010 1:37 AM, Alf P. Steinbach wrote: > Consider just the > assert( t is not s ) > t = s > > Does this change anything at all in the computer's memory? By 'computer', do you mean 'anything that computes' (including humans) or specifically 'electronic computer'? > But since it does have an effect, a memory change has been effected. Agreed, in whatever 'memory' the 'computer' is using. > You describe that memory change as that t has been "bound" to the same > object as s. I prefer to use the word 'associated': namespaces are a many-to-one association between names and objects. > By which you mean that henceforth, until the next assignment to t, t > *refers* to the same object as s. T and s are both associated with the same object. > That explanation in terms of "refers" is necessary. I disagree > No beginner knows what it means that a name is "bound" to something means, until it's been > explained. I agree, which is why I am trying to avoid 'bound', etc, in favor of 'associated'. One problem of 'bind' is that it sometimes raises the question of which is bound to which. 'Associated' avoids that. > The explanation is necessarily in terms of "refers to". I have given an alternative, even if you still prefer yours. > When something A refers to something B, then by definition A is a > *reference* to B. I presume you agree that the name 'Alf P. Steinbach' refers to you. Do you then consider it to be a 'reference' to you? In either case, the Python definition uses 'refers to' in the same way that names refer to people, and did even before names were used in electro-mechanical computer programming. >Steven D'Aprano: >> My version describes what happens at the level of high-level Python >> code, which is the defined semantics of the language. It makes no >> assumptions about the implementation, completely unlike yours which is >> entirely implementation- >> specific. My description is equally valid whether Python is being >> executed by the CPython virtual machine on an Intel-compatible >> processor, or hand-simulated with pencil and paper, or something >> completely different. Yours is not. About 13 years ago, I noticed that electronically executable Python was very similar to some of the designed-for-human-reading algoritm languages (pseudocode) that were not. I then coined the oxymoron 'executable pseudocode' for Python. I see the difference between the descriptions as reflecting the difference between Python, the executable algorithm language and Python, the machine programming language. >> I describe the high-level language, you describe one implementation. >> Neither view is *wrong*, per se, but one describes the semantics of >> the language while the other describes the implementation. I think anyone writing books using Python should at least understand the abstract view even if he prefers to write from the more concrete view. Terry Jan Reedy From alfps at start.no Thu Feb 11 17:26:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 23:26:34 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Terry Reedy: > On 2/11/2010 1:37 AM, Alf P. Steinbach wrote: > >> Consider just the >> assert( t is not s ) >> t = s >> >> Does this change anything at all in the computer's memory? > > By 'computer', do you mean 'anything that computes' (including humans) > or specifically 'electronic computer'? In this context I mean the virtual machine that a Python language assumes. Doesn't matter if it's electronic or a pen-and-pencil simulation. >> But since it does have an effect, a memory change has been effected. > > Agreed, in whatever 'memory' the 'computer' is using. > >> You describe that memory change as that t has been "bound" to the same >> object as s. > > I prefer to use the word 'associated': namespaces are a many-to-one > association between names and objects. > >> By which you mean that henceforth, until the next assignment to t, t >> *refers* to the same object as s. > > T and s are both associated with the same object. > >> That explanation in terms of "refers" is necessary. > > I disagree > >> No beginner knows what it means that a name is "bound" to something >> means, until it's been >> explained. > > I agree, which is why I am trying to avoid 'bound', etc, in favor of > 'associated'. One problem of 'bind' is that it sometimes raises the > question of which is bound to which. 'Associated' avoids that. > >> The explanation is necessarily in terms of "refers to". > > I have given an alternative, even if you still prefer yours. "Associated" is just less precise than "refers". "Associated" is two-way. Anyway it's just a term, and if you define it to mean a one-way reference, then nothing substantial is changed except more room for misunderstanding. >> When something A refers to something B, then by definition A is a >> *reference* to B. > > I presume you agree that the name 'Alf P. Steinbach' refers to you. Do > you then consider it to be a 'reference' to you? Yes, and that's irrelevant, because you can't change a name. It's a slightly different meaning. But a name edit field with my name in it most probably refers to me. > In either case, the > Python definition uses 'refers to' in the same way that names refer to > people, and did even before names were used in electro-mechanical > computer programming. That's so subtle a distinction that it appears meaningless to me. It says "refers to" but doesn't mean "refers to"? > >Steven D'Aprano: >>> My version describes what happens at the level of high-level Python >>> code, which is the defined semantics of the language. It makes no >>> assumptions about the implementation, completely unlike yours which is >>> entirely implementation- >>> specific. My description is equally valid whether Python is being >>> executed by the CPython virtual machine on an Intel-compatible >>> processor, or hand-simulated with pencil and paper, or something >>> completely different. Yours is not. > > About 13 years ago, I noticed that electronically executable Python was > very similar to some of the designed-for-human-reading algoritm > languages (pseudocode) that were not. I then coined the oxymoron > 'executable pseudocode' for Python. I see the difference between the > descriptions as reflecting the difference between Python, the executable > algorithm language and Python, the machine programming language. > > >> I describe the high-level language, you describe one implementation. > >> Neither view is *wrong*, per se, but one describes the semantics of > >> the language while the other describes the implementation. > > I think anyone writing books using Python should at least understand the > abstract view even if he prefers to write from the more concrete view. It seems to me that you lack an understanding of the abstract here, going into imagined and not concretely discussed differences between "refers to" and "refers to". Until or if (but I think it unlikely) you can explain clearly what that difference between "refers to" and "refers to" is, it's just wordplay. Cheers & hth., - Alf From steve at holdenweb.com Thu Feb 11 17:36:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 17:36:05 -0500 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: mk wrote: > MRAB wrote: > >> When working with Unicode in Python 2, you should use the 'unicode' type >> for text (Unicode strings) and limit the 'str' type to binary data >> (bytestrings, ie bytes) only. > > Well OK, always use u'something', that's simple -- but isn't str what I > get from files and sockets and the like? > Yes, which is why you need to know what encoding was used to create it. >> In Python 3 they've been renamed to 'str' for Unicode _strings_ and >> 'bytes' for binary data (bytes!). > > Neat, except that the process of porting most projects and external > libraries to P3 seems to be, how should I put it, standing still? Or am > I wrong? But that's the impression I get? > No, it's probably not going as quickly as you would like, but it's certainly not standing still. Some of these libraries are substantial works, and there were changes to the C API that take quite a bit of work to adapt existing code to. > Take web frameworks for example. Does any of them have serious plans and > work in place to port to P3? > There have already been demonstrations of partially-working Python 3 Django. I can't speak to the rest. >> Strictly speaking, only Unicode can be encoded. > > How so? Can't bytestrings containing characters of, say, koi8r encoding > be encoded? > It's just terminology. If a bytestring contains koi8r characters then (as you unconsciously recognized by your use of the word "encoding") it already *has* been encoded. >> What Python 2 is doing here is trying to be helpful: if it's already a >> bytestring then decode it first to Unicode and then re-encode it to a >> bytestring. > > It's really cumbersome sometimes, even if two libraries are written by > one author: for instance, Mako and SQLAlchemy are written by the same > guy. They are both top-of-the line in my humble opinion, but when you > connect them you get things like this: > > 1. you query SQLAlchemy object, that happens to have string fields in > relational DB. > > 2. Corresponding Python attributes of those objects then have type str, > not unicode. > Yes, a relational database will often return ASCII, but nowadays people are increasingly using encoded Unicode. In that case you need to be aware of the encoding that has been used to render the Unicode values into the byte strings (which in Python 2 are of type str) so that you can decode them into Unicode. > 3. then I pass those objects to Mako for HTML rendering. > > Typically, it works: but if and only if a character in there does not > happen to be out of ASCII range. If it does, you get UnicodeDecodeError > on an unsuspecting user. > Well first you need to be clear what you are passing to Mako. > Sure, I wrote myself a helper that iterates over keyword dictionary to > make sure to convert all str to unicode and only then passes the > dictionary to render_unicode. It's an overhead, though. It would be > nicer to have it all unicode from db and then just pass it for rendering > and having it working. (unless there's something in filters that I > missed, but there's encoding of templates, tags, but I didn't find > anything on automatic conversion of objects passed to method rendering > template) > Some database modules will distinguish between fields of type varchar and nvarchar, returning Unicode objects for the latter. You will need to ensure that the module knows which encoding is used in the database. This is usually automatic. > But maybe I'm whining. > Nope, just struggling with a topic that is far from straightforward the first time you encounter it. > >> Unfortunately, the default encoding is ASCII, and the bytestring isn't >> valid ASCII. Python 2 is being 'helpful' in a bad way! > > And the default encoding is coded in such way so it cannot be changed in > sitecustomize (without code modification, that is). > Yes, the default encoding is not always convenient. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From hjebbers at gmail.com Thu Feb 11 17:39:45 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 14:39:45 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> On Feb 11, 8:42?pm, Jerry Hill wrote: > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > To all, > > I am running an EDI translator, and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > You need to give us more information if we're going to be able to > help. ?At the very least, you'll need to copy & paste the actual error > message. ?It would be even better if you could show us some of your > code, and better yet if you could give us a small bit of code that is > self contained and reproduces the problem you're experiencing. > > -- > Jerry the error is a windows thing, I can make a screenshot of it, but I can not copy/paste text. how do I upload a png-file? problem is that the same error happens over and over (I can reproduce it), but not at the same place (the is a logging in the application so that is quite easy to see.) but ....I can show you my code. it's an open source EDI application. but it is not a small bit of code.... I am more than will to show you how to reproduce the error. kind regards, henk-jan From hjebbers at gmail.com Thu Feb 11 17:39:51 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 14:39:51 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <10419981-eca8-44c7-a216-508431481151@h12g2000yql.googlegroups.com> On Feb 11, 8:42?pm, Jerry Hill wrote: > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > To all, > > I am running an EDI translator, and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > You need to give us more information if we're going to be able to > help. ?At the very least, you'll need to copy & paste the actual error > message. ?It would be even better if you could show us some of your > code, and better yet if you could give us a small bit of code that is > self contained and reproduces the problem you're experiencing. > > -- > Jerry the error is a windows thing, I can make a screenshot of it, but I can not copy/paste text. how do I upload a png-file? problem is that the same error happens over and over (I can reproduce it), but not at the same place (the is a logging in the application so that is quite easy to see.) but ....I can show you my code. it's an open source EDI application. but it is not a small bit of code.... I am more than will to show you how to reproduce the error. kind regards, henk-jan From tjreedy at udel.edu Thu Feb 11 17:52:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 17:52:05 -0500 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > Robert Kern writes: >> On 2010-02-11 06:31 AM, Shashwat Anand wrote: >>> There is a little issue here that '>>> -.1 ** .1' should give you >>> error message. That is it. >> >> No, fractional powers of negative numbers are perfectly valid >> mathematically. The result is a complex number. In Python 3 (what >> the OP is using), this has been implemented, but not in Python 2.6. > > Perhaps it should raise a MisleadingSpacingError at compile time. You forgot the smiley ;-). > The error message could recommend - .1**.1, or better -(.1 ** .1). The compiler would never see the difference between -.1 ** .1 and the first and probably no difference with the second either. From pavlovevidence at gmail.com Thu Feb 11 17:56:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 11 Feb 2010 14:56:15 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: <007f26f3-5310-4ed9-bb25-b467fb248825@m35g2000prh.googlegroups.com> On Feb 11, 2:39?pm, hjebbers wrote: > On Feb 11, 8:42?pm, Jerry Hill wrote: > > > > > > > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > > To all, > > > I am running an EDI translator, and doing stress tests. > > > When processing a test with a (relatively) big EDI file(s) on > > > windowsXP ?I get a crash: > > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > > causing the problem) > > > You need to give us more information if we're going to be able to > > help. ?At the very least, you'll need to copy & paste the actual error > > message. ?It would be even better if you could show us some of your > > code, and better yet if you could give us a small bit of code that is > > self contained and reproduces the problem you're experiencing. > > > -- > > Jerry > > the error is a windows thing, I can make a screenshot of it, but I can > not copy/paste text. > how do I upload a png-file? > > problem is that the same error happens over and over (I can reproduce > it), but not at the same place (the is a logging in the application so > that is quite easy to see.) > but ....I can show you my code. it's an open source EDI application. > but it is not a small bit of code.... > I am more than will to show you how to reproduce the error. People coming here ask for help will vary in the amount of detail given, but I've rarely seen anyone as reluctant as you. It's like walking into an auto repair shop and asking the mechanic what's wrong with your car by trying to imitate the noise it makes. If your code is very largre, you're not going to get out of this without doing some of your own legwork. I'm sorry. Do this: Take your code, make a copy of it. Start removing code from the copy (in a controlled way) until the problem disappears. When you remove code don't worry about whether it produces anything useful, the object is to try to identify what's causing the error. Whatever code you removed when the error disappears should give you a clue what's causing it. Then, if need be, you can come back and post details. If you manage to get the program to a small size without eliminating the problem, you can post it here. Carl Banks From tjreedy at udel.edu Thu Feb 11 17:59:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 17:59:50 -0500 Subject: python crash on windows but not on linux In-Reply-To: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On 2/11/2010 9:32 AM, hjebbers wrote: > To all, > I am running an EDI translator, and doing stress tests. > When processing a test with a (relatively) big EDI file(s) on > windowsXP I get a crash: > 'sorry for the inconvenience' etc (so no clues about what is > causing the problem) > > This happens with python 2.4, 2.5, 2.6 > It does not happen in the same setup&tests on linux. (while the linux > machine has only half of the RAM of the windows machine). > I am quite sure it is not some external module; there's no GUI (apart > from 'print'), no network connections. > Actually, the crash is not predictable....the crash occurs most of the > time...but at different points. > > So basically I am wondering how to proceed. > Is it related to a memory problem? (which does not occur on Linux) > > any pointer is very welcome, Are you using a 3rd-party extension (compiled-C) module? If so, I would suspect something platform specific in that. From emile at fenx.com Thu Feb 11 18:13:19 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Feb 2010 15:13:19 -0800 Subject: python crash on windows but not on linux In-Reply-To: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On 2/11/2010 6:32 AM hjebbers said... > To all, > I am running an EDI translator, ... let's say bots :) > and doing stress tests. > When processing a test with a (relatively) big EDI file(s) on > windowsXP I get a crash: > 'sorry for the inconvenience' etc (so no clues about what is > causing the problem) ... and it's running directly under python... I use textpad. It allows me to launch a script from a command window under its control, which when python subsequently crashes, commonly leaves the traceback in the textpad launched command window. Perhaps that'll help? Emile --also on the bots list and will be digging in seriously over the next several weeks > > This happens with python 2.4, 2.5, 2.6 > It does not happen in the same setup&tests on linux. (while the linux > machine has only half of the RAM of the windows machine). > I am quite sure it is not some external module; there's no GUI (apart > from 'print'), no network connections. > Actually, the crash is not predictable....the crash occurs most of the > time...but at different points. > > So basically I am wondering how to proceed. > Is it related to a memory problem? (which does not occur on Linux) > > any pointer is very welcome, > > henk-jan From tjreedy at udel.edu Thu Feb 11 18:20:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 18:20:16 -0500 Subject: python and http POST In-Reply-To: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: On 2/11/2010 2:11 PM, galileo228 wrote: > Hey All, > > Been teaching myself Python for a few weeks, and am trying to write a > program that will go to a url, enter a string in one of the search > fields, submit the search, and return the contents of the search > result. > > I'm using httplib2. > > My two particular questions: > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > how do I know what the particular key should be? In other words, how > do I tell python which form on the web page I'm visiting I'd like to > fill in? Do I simply go to the webpage itself and look at the html > source? But if that's the case, which tag tells me the name of the > key? > > 2) Even once python fills in the form properly, how can I tell it to > 'submit' the search? This http://groups.csail.mit.edu/uid/sikuli/ *might* help you. From peter.milliken at gmail.com Thu Feb 11 18:26:58 2010 From: peter.milliken at gmail.com (Peter) Date: Thu, 11 Feb 2010 15:26:58 -0800 (PST) Subject: Is a merge interval function available? References: Message-ID: <14520376-06ca-4cc9-a6b0-52b00a95700e@g28g2000prb.googlegroups.com> On Feb 12, 8:03?am, Jonathan Gardner wrote: > On Feb 10, 3:23?pm, Peng Yu wrote: > > > > > > > I'm wondering there is already a function in python library that can > > merge intervals. For example, if I have the following intervals ('[' > > and ']' means closed interval as inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...) > > > [1, 3] > > [2, 9] > > [10,13] > > [11,12] > > > I want to get the following merged intervals. > > > [1,9] > > [10,13] > > > Could somebody let me know if there is a function in the python > > library? > > I vaguely recall a similar question a long time ago. Peng, is this a > homework assignment? > > Perhaps we should add a standard module called "homework". It can have > functions for all the different homework assignments we see on > c.l.python. We can simply point people to this module and then can > include the code in their answers. Good idea - that would (also) give the teachers a convenient place to check for what assignments have been solved by this list so they can propose something else. They can also grade the submissions against the code kept in this area - exact copies could receive an "F" (for example :-)) Peter From rhodri at wildebst.demon.co.uk Thu Feb 11 18:32:08 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Feb 2010 23:32:08 -0000 Subject: MODULE FOR I, P FRAME References: Message-ID: On Thu, 11 Feb 2010 19:31:52 -0000, DANNY wrote: > Hello! > > I am currently developing a simple video player in python, and my > problem is that i can't find a module which has a function that can > determine if frame(image) is I or P coded (MPEG coding). I have been > using PIL but I couldnt find anything that could help me with that > problem. How are you reading the video? PIL doesn't claim to do more than identify MPEG files. Also, which MPEG encoding, in which container format? If you aren't just putting a wrapper around something like ffmpeg, I rather suspect you'll have to decode the bitstream yourself. That could be rather painful if you're talking about MPEG-4/10. -- Rhodri James *-* Wildebeeste Herder to the Masses From tjreedy at udel.edu Thu Feb 11 18:34:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 18:34:14 -0500 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: On 2/11/2010 4:43 PM, mk wrote: > Neat, except that the process of porting most projects and external > libraries to P3 seems to be, how should I put it, standing still? What is important are the libraries, so more new projects can start in 3.x. There is a slow trickly of 3.x support announcements. > But maybe I'm whining. Or perhaps explaining why 3.x unicode improvements are needed. tjr From gagsl-py2 at yahoo.com.ar Thu Feb 11 18:36:40 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Feb 2010 20:36:40 -0300 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy escribi?: > On 2/10/2010 4:49 PM, Gabriel Genellina wrote: > >> I've written a decorator for "injecting" a __function__ name into the >> function namespace, but I can't find it anywhere. I think I implemented >> it by adding a fake additional argument and replacing LOAD_GLOBAL with >> LOAD_NAME in the bytecode. > > The decorator only needs to replace the defaults args tuple. > It does not even need to know the parameter name, > just that it is the only (or last) with a default . > > def f(n, me=None): > if n > 0: return n*me(n-1) > elif n==0: return 1 > > f.__defaults__ = (f,) # 3.1 > print(f(5)) This is simple to implement, but requires changing the function definition. My goal was to keep the original code unchanged, that is, leave it as: def f(n): if n > 0: return n*f(n-1) elif n==0: return 1 (like a normal, recursive function), and make the 'f' inside the function body "magically" refer to the function itself. > Of course, user could still screw up recursion by providing another > value for 'me'. This strikes me as about a likely (low) as a user > screwing up recursion in a library module function by rebinding the name > in the imported module. Well, if people really want to shoot themselves in the foot, there's nothing we can do to avoid that... -- Gabriel Genellina From jlconlin at gmail.com Thu Feb 11 18:39:09 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 11 Feb 2010 15:39:09 -0800 (PST) Subject: Please help with MemoryError Message-ID: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> I have been using Python for several years now and have never run into memory errors? until now. My Python program now consumes over 2 GB of memory and then I get a MemoryError. I know I am reading lots of files into memory, but not 2GB worth. I thought I didn't have to worry about memory allocation in Python because of the garbage collector. On this note I have a few questions. FYI I am using Python 2.6.4 on my Mac. 1. When I pass a variable to the constructor of a class does it copy that variable or is it just a reference/pointer? I was under the impression that it was just a pointer to the data. 2. When do I need to manually allocate/deallocate memory and when can I trust Python to take care of it? 3. Any good practice suggestions? Thanks, Jeremy From martin.hellwig at dcuktec.org Thu Feb 11 18:46:27 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Feb 2010 23:46:27 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Well at least you are well written and more subtle than Xah Lee. Though I find him also quite amusing, I do like a good flame-war every now and again, and in that perspective I solute you. -- mph From apt.shansen at gmail.com Thu Feb 11 18:56:50 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 11 Feb 2010 15:56:50 -0800 Subject: Please help with MemoryError In-Reply-To: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <7a9c25c21002111556x4cc04c23u2586a952fd1c8b91@mail.gmail.com> On Thu, Feb 11, 2010 at 3:39 PM, Jeremy wrote: > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. I know I am reading lots of files into memory, but not > 2GB worth. I thought I didn't have to worry about memory allocation > in Python because of the garbage collector. On this note I have a few > questions. FYI I am using Python 2.6.4 on my Mac. > Is this pure-python, or are you using extension modules? Its possible a C extension has a memory leak. Its also possible you're keeping references to objects far longer then you need. > 1. When I pass a variable to the constructor of a class does it > copy that variable or is it just a reference/pointer? I was under the > impression that it was just a pointer to the data. > The question doesn't precisely make sense in terms of Python, but I think I see what you're getting at. Python doesn't implicitly copy anything: you have to explicitly copy an object to end up with two of them. That said, it sort of depends on what you're doing. When you pass objects into a class, if that class stores a reference to those objects, they'll live as long as the class does. More details would require you showing some examples of what you're doing. > 2. When do I need to manually allocate/deallocate memory and when > can I trust Python to take care of it? > Generally, you can "trust" Python-- and you can't manually allocate/deallocate even if you wanted to. If you're suffering a memory leak, it almost certainly comes from one of two places: 1. Your code is keeping references somewhere to objects that you don't need anymore, or 2. Some C extension you are using has some ref-counting bugs. Once upon a time, reference cycles would also cause memory leaks, but the cyclic GC breaks them now. > 3. Any good practice suggestions? > Look over your code: look at places where you bind objects to any names that aren't local. Look for lists or dictionaries that you're putting stuff into without really meaning to keep it forever, and maybe you aren't purging. Global vars are worth a close look too. This may be useful: http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 11 19:03:43 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 01:03:43 +0100 Subject: Please help with MemoryError In-Reply-To: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: * Jeremy: > I have been using Python for several years now and have never run into > memory errors? > > until now. > > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. I know I am reading lots of files into memory, but not > 2GB worth. I thought I didn't have to worry about memory allocation > in Python because of the garbage collector. On this note I have a few > questions. FYI I am using Python 2.6.4 on my Mac. > > 1. When I pass a variable to the constructor of a class does it > copy that variable or is it just a reference/pointer? I was under the > impression that it was just a pointer to the data. Uhm, I discovered that "pointer" is apparently a Loaded Word in the Python community. At least in some sub-community, so, best avoided. But essentially you're just passing a reference to an object. The object is not copied. > 2. When do I need to manually allocate/deallocate memory and when > can I trust Python to take care of it? Python takes care of deallocation of objects that are /no longer referenced/. > 3. Any good practice suggestions? You need to get rid of references to objects before Python will garbage collect them. Typically, in a language like Python (or Java, C#...) memory leaks are caused by keeping object references in singletons or globals, e.g. for purposes of event notifications. For example, you may have some dictionary somewhere. Such references from singletons/globals need to be removed. You do not, however, need to be concerned about circular references, at least unless you need some immediate deallocation. For although circular references will prevent the objects involved from being immediately deallocated, the general garbage collector will take care of them later. Cheers & hth., - Alf From sridharr at activestate.com Thu Feb 11 19:22:49 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 11 Feb 2010 16:22:49 -0800 Subject: ANN: ActivePython 2.5.5.7 is now available Message-ID: <1E441CA2-F197-4F5B-B4F5-A5FE2E3D7882@activestate.com> I'm happy to announce that ActivePython 2.5.5.7 is now available for download from: http://www.activestate.com/activepython/ This is a minor release with several updates and fixes. Changes in 2.5.5.7 ------------------ - Upgrade to Python 2.5.5 - Upgrade to Tcl/Tk 8.5.8 - Upgrade to PyWin32 CVS (2009-11-10) - Security upgrade to openssl-0.9.8l - [Windows] Include Tcl/Tk header files - [Windows] Allow side-by-side installation of 32-bit and 64-bit builds - [Mac] Fix the MacOSX build to use Tcl/Tk 8.5.x See the release notes for full details: http://docs.activestate.com/activepython/2.5/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. Builds for Solaris, HP-UX and AIX, and access to older versions are available with ActivePython Business Edition: http://www.activestate.com/business_edition/ 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. Beginning with the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: pypm install pylons See this page for full details: http://docs.activestate.com/activepython/2.5/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.5/ We would welcome any and all feedback to: ActivePython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/query.cgi?set_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 Edition only) - Solaris/x86 (Business Edition only) - HP-UX/PA-RISC (Business Edition only) - AIX/PowerPC (Business Edition only) - AIX/PowerPC 64-bit (Business Edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/activepython/enterprise/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From jgardner at jonathangardner.net Thu Feb 11 19:36:45 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 11 Feb 2010 16:36:45 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: On Feb 11, 3:39?pm, Jeremy wrote: > I have been using Python for several years now and have never run into > memory errors? > > until now. > Yes, Python does a good job of making memory errors the least of your worries as a programmer. Maybe it's doing too good of a job... > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. ?I know I am reading lots of files into memory, but not > 2GB worth. Do a quick calculation: How much are leaving around after you read in a file? Do you create an object for each line? What does that object have associated with it? You may find that you have some strange O(N^2) behavior regarding memory here. Oftentimes people forget that you have to evaluate how your algorithm will run in time *and* memory. >?I thought I didn't have to worry about memory allocation > in Python because of the garbage collector. While it's not the #1 concern, you still have to keep track of how you are using memory and try not to be wasteful. Use good algorithms, let things fall out of scope, etc... > 1. ? ?When I pass a variable to the constructor of a class does it > copy that variable or is it just a reference/pointer? ?I was under the > impression that it was just a pointer to the data. For objects, until you make a copy, there is no copy made. That's the general rule and even though it isn't always correct, it is correct enough. > 2. ? ?When do I need to manually allocate/deallocate memory and when > can I trust Python to take care of it? Let things fall out of scope. If you're concerned, use delete. Try to avoid using the global namespace for everything, and try to keep your lists and dicts small. > 3. ? ?Any good practice suggestions? > Don't read in the entire file and then process it. Try to do line-by- line processing. Figure out what your algorithm is doing in terms of time *and* memory. You likely have some O(N^2) or worse in memory usage. Don't use Python variables to store data long-term. Instead, setup a database or a file and use that. I'd first look at using a file, then using SQLite, and then a full-fledged database like PostgreSQL. Don't write processes that sit around for a long time unless you also evaluate whether that process grows in size as it runs. If it does, you need to figure out why and stop that memory leak. Simpler code uses less memory. Not just because it is smaller, but because you are not copying and moving data all over the place. See what you can do to simplify your code. Maybe you'll expose the nasty O(N^2) behavior. From hjebbers at gmail.com Thu Feb 11 20:09:13 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:09:13 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <6dd5bb28-9d70-4bef-999b-a4ae7b45847a@l26g2000yqd.googlegroups.com> On Feb 11, 11:59?pm, Terry Reedy wrote: > On 2/11/2010 9:32 AM, hjebbers wrote: > > > > > To all, > > I am running an EDI translator, and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > Are you using a 3rd-party extension (compiled-C) module? If so, I would > suspect something platform specific in that. That was my first thought. Sop I tried to eliminate that. well, there is a connection to a database. but I tested this with connections to SQLite, MySQL, PostGreSQL, and the crash keeps coming. So I think it is not a 3rd party module.... And all else is is pure python. kind regards, Henk-Jan From steve at REMOVE-THIS-cybersource.com.au Thu Feb 11 20:09:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 01:09:30 GMT Subject: Modifying Class Object References: Message-ID: <03849660$0$1277$c3e8da3@news.astraweb.com> On Thu, 11 Feb 2010 17:11:17 -0500, Terry Reedy wrote: > About 13 years ago, I noticed that electronically executable Python was > very similar to some of the designed-for-human-reading algoritm > languages (pseudocode) that were not. I then coined the oxymoron > 'executable pseudocode' for Python. That was yours? Nice one! -- Steve From hjebbers at gmail.com Thu Feb 11 20:14:03 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:14:03 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <481d2511-0bf1-4012-be1b-f1af54af5ada@g28g2000yqh.googlegroups.com> On Feb 12, 12:13?am, Emile van Sebille wrote: > On 2/11/2010 6:32 AM hjebbers said... > > > To all, > > I am running an EDI translator, > > ... let's say bots ?:) > > > and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > ... and it's running directly under python... > > I use textpad. ?It allows me to launch a script from a command window > under its control, which when python subsequently crashes, commonly > leaves the traceback in the textpad launched command window. > > Perhaps that'll help? > > Emile > --also on the bots list and will be digging in seriously over the next > several weeks > > > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > > henk-jan > > Hi Emile, yes, we are talking bots. I run the bots engine from the commandline. But... there is no python traceback. Python crashed 'hard'. or have you something else in mind? kind regards,henk-jan From steve at REMOVE-THIS-cybersource.com.au Thu Feb 11 20:14:04 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 01:14:04 GMT Subject: Modifying Class Object References: Message-ID: <03849771$0$1277$c3e8da3@news.astraweb.com> On Thu, 11 Feb 2010 23:26:34 +0100, Alf P. Steinbach wrote: >> I presume you agree that the name 'Alf P. Steinbach' refers to you. Do >> you then consider it to be a 'reference' to you? > > Yes, and that's irrelevant, because you can't change a name. Pardon me, but you most certainly can. Even Germany, which doesn't allow people to change their legal name for frivolous reasons, makes exceptions and will allow people to change their name if (e.g.) they have a sex change, or if they are burdened with a name that causes them ridicule, and presumably for their equivalent of the witness relocation program. And even Germany doesn't presume to tell people what name they are known by to their friends and family. In Python, one can't change names *in place*, because strings are immutable. (Although I have seen a hack with ctypes which allows you to modify string objects. It makes a nice trick, but is completely useless because of the side-effects.) Even if you could modify the name, that would break the namespace it was stored in. But of course you can change names in two steps: x = something() y = x del x And lo, we have changed the name x to y. -- Steven From alfps at start.no Thu Feb 11 20:17:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 02:17:46 +0100 Subject: Modifying Class Object In-Reply-To: <03849771$0$1277$c3e8da3@news.astraweb.com> References: <03849771$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Thu, 11 Feb 2010 23:26:34 +0100, Alf P. Steinbach wrote: > >>> I presume you agree that the name 'Alf P. Steinbach' refers to you. Do >>> you then consider it to be a 'reference' to you? >> Yes, and that's irrelevant, because you can't change a name. > > Pardon me, but you most certainly can. Even Germany, which doesn't allow > people to change their legal name for frivolous reasons, makes exceptions > and will allow people to change their name if (e.g.) they have a sex > change, or if they are burdened with a name that causes them ridicule, > and presumably for their equivalent of the witness relocation program. > And even Germany doesn't presume to tell people what name they are known > by to their friends and family. > > In Python, one can't change names *in place*, because strings are > immutable. (Although I have seen a hack with ctypes which allows you to > modify string objects. It makes a nice trick, but is completely useless > because of the side-effects.) Even if you could modify the name, that > would break the namespace it was stored in. But of course you can change > names in two steps: > > x = something() > y = x > del x > > And lo, we have changed the name x to y. Good joke. :-) Cheers, - Alf From nobody at nowhere.com Thu Feb 11 20:27:28 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 12 Feb 2010 01:27:28 +0000 Subject: Need debugging knowhow for my creeping Unicodephobia References: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> Message-ID: On Wed, 10 Feb 2010 12:17:51 -0800, Anthony Tolle wrote: > 4. Consider switching to Python 3.x, since there is only one string > type (unicode). However: one drawback of Python 3.x is that the repr() of a Unicode string is no longer restricted to ASCII. There is an ascii() function which behaves like the 2.x repr(). However: the interpreter uses repr() for displaying the value of an expression typed at the interactive prompt, which results in "can't encode" errors if the string cannot be converted to your locale's encoding. From twistedphrame at gmail.com Thu Feb 11 20:27:58 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Thu, 11 Feb 2010 17:27:58 -0800 (PST) Subject: Pycrypto RSA ciphertext to string back to ciphertext issue Message-ID: <4b65abb5-072f-4e3c-91eb-95eea6c8a6a9@b10g2000vbh.googlegroups.com> Hey all, I'm trying to convert the encrypted data from RSA to a string for sending over xmlrpc and then back to usable data. Whenever I decrypt I just get junk data. Has anyone else tried doing this? Here's some example code: from Crypto.PublicKey import RSA from Crypto import Random key = RSA.generate(384, Random.new().read) l = str(key.encrypt("dog","")) l = stringToTuple(l) l = key.decrypt(tuple(l)) print l string to tuple: def stringToTuple(string): if string[0] + string[-1] == "()": items = string[1:-1] items = items.split(',') return items else: raise ValueError("Badly formatted string (missing brackets).") thanks for any help, I've been messing with this for days and have come up dry. From hjebbers at gmail.com Thu Feb 11 20:30:39 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:30:39 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <0cf3d611-dc7f-4d77-b9e5-59762c022f20@g27g2000yqh.googlegroups.com> On Feb 12, 12:13?am, Emile van Sebille wrote: > On 2/11/2010 6:32 AM hjebbers said... > > > To all, > > I am running an EDI translator, > > ... let's say bots ?:) > > > and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > ... and it's running directly under python... > > I use textpad. ?It allows me to launch a script from a command window > under its control, which when python subsequently crashes, commonly > leaves the traceback in the textpad launched command window. > > Perhaps that'll help? > > Emile > --also on the bots list and will be digging in seriously over the next > several weeks > > > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > > henk-jan > > From hjebbers at gmail.com Thu Feb 11 20:32:00 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:32:00 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <626c4c0f-c02c-44f7-9032-5ea2c11e58a8@h2g2000yqj.googlegroups.com> On Feb 12, 12:13?am, Emile van Sebille wrote: > On 2/11/2010 6:32 AM hjebbers said... > > > To all, > > I am running an EDI translator, > > ... let's say bots ?:) > > > and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > ... and it's running directly under python... > > I use textpad. ?It allows me to launch a script from a command window > under its control, which when python subsequently crashes, commonly > leaves the traceback in the textpad launched command window. > > Perhaps that'll help? > > Emile > --also on the bots list and will be digging in seriously over the next > several weeks > > > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > > henk-jan > > From hjebbers at gmail.com Thu Feb 11 20:33:14 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:33:14 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <007f26f3-5310-4ed9-bb25-b467fb248825@m35g2000prh.googlegroups.com> Message-ID: <221e80b8-fd1b-4585-bbd6-9ccb14eedb08@k41g2000yqm.googlegroups.com> On Feb 11, 11:56?pm, Carl Banks wrote: > On Feb 11, 2:39?pm, hjebbers wrote: > > > > > On Feb 11, 8:42?pm, Jerry Hill wrote: > > > > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > > > To all, > > > > I am running an EDI translator, and doing stress tests. > > > > When processing a test with a (relatively) big EDI file(s) on > > > > windowsXP ?I get a crash: > > > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > > > causing the problem) > > > > You need to give us more information if we're going to be able to > > > help. ?At the very least, you'll need to copy & paste the actual error > > > message. ?It would be even better if you could show us some of your > > > code, and better yet if you could give us a small bit of code that is > > > self contained and reproduces the problem you're experiencing. > > > > -- > > > Jerry > > > the error is a windows thing, I can make a screenshot of it, but I can > > not copy/paste text. > > how do I upload a png-file? > > > problem is that the same error happens over and over (I can reproduce > > it), but not at the same place (the is a logging in the application so > > that is quite easy to see.) > > but ....I can show you my code. it's an open source EDI application. > > but it is not a small bit of code.... > > I am more than will to show you how to reproduce the error. > > People coming here ask for help will vary in the amount of detail > given, but I've rarely seen anyone as reluctant as you. ?It's like > walking into an auto repair shop and asking the mechanic what's wrong > with your car by trying to imitate the noise it makes. > I am reluctant because it is a lot of code ....as I told you, it occurs during stress tests. I am more than willing to show how to reproduce the crash. > If your code is very largre, you're not going to get out of this > without doing some of your own legwork. ?I'm sorry. I am more than willing to do this, of course. > > Do this: Take your code, make a copy of it. ?Start removing code from > the copy (in a controlled way) until the problem disappears. ?When you > remove code don't worry about whether it produces anything useful, the > object is to try to identify what's causing the error. ?Whatever code > you removed when the error disappears should give you a clue what's > causing it. ?Then, if need be, you can come back and post details. ?If > you manage to get the program to a small size without eliminating the > problem, you can post it here. OK, I know how to trace a bug. As I said, these are stress tests, in this case the input files are MUCH larger than usualy. Other stress tests run thousands of input file of regular to big size..... This all runs. It does run OK on Linux (so am I looking for a bug in my program??). The crash pops up at different places...this makes the procedure you suggest quite awkward. It is a hard crash of python. There is no traceback or something: Python dies. Python is no more. It's stone dead. It has ceased to be. It's a stiff. It's kicked the bucket etc kind regards, henk-jan From nobody at nowhere.com Thu Feb 11 20:37:59 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 12 Feb 2010 01:37:59 +0000 Subject: Is a merge interval function available? References: Message-ID: On Wed, 10 Feb 2010 23:03:29 -0500, Steve Holden wrote: >> intervals = sorted(intervals, key = lambda x: x[0]) > > Since Python uses lexical sorting and the intervals are lists isn't the > key specification redundant here? Yes, but I wanted to make it explicit. Well, omitting the key= would change the sorting order in the event that multiple intervals have the same start, but it still won't affect the result of the function overall. From steve at REMOVE-THIS-cybersource.com.au Thu Feb 11 20:50:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 01:50:26 GMT Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <03849ff7$0$1277$c3e8da3@news.astraweb.com> On Thu, 11 Feb 2010 15:39:09 -0800, Jeremy wrote: > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. I know I am reading lots of files into memory, but not 2GB > worth. Are you sure? Keep in mind that Python has a comparatively high overhead due to its object-oriented nature. If you have a list of characters: ['a', 'b', 'c', 'd'] there is the (small) overhead of the list structure itself, but each individual character is not a single byte, but a relatively large object: >>> sys.getsizeof('a') 32 So if you read (say) a 500MB file into a single giant string, you will have 500MB plus the overhead of a single string object (which is negligible). But if you read it into a list of 500 million single characters, you will have the overhead of a single list, plus 500 million strings, and that's *not* negligible: 32 bytes each instead of 1. So try to avoid breaking a single huge strings into vast numbers of tiny strings all at once. > I thought I didn't have to worry about memory allocation in > Python because of the garbage collector. You don't have to worry about explicitly allocating memory, and you almost never have to worry about explicitly freeing memory (unless you are making objects that, directly or indirectly, contain themselves -- see below); but unless you have an infinite amount of RAM available of course you can run out of memory if you use it all up :) > On this note I have a few > questions. FYI I am using Python 2.6.4 on my Mac. > > 1. When I pass a variable to the constructor of a class does it copy > that variable or is it just a reference/pointer? I was under the > impression that it was just a pointer to the data. Python's calling model is the same whether you pass to a class constructor or any other function or method: x = ["some", "data"] obj = f(x) The function f (which might be a class constructor) sees the exact same list as you assigned to x -- the list is not copied first. However, there's no promise made about what f does with that list -- it might copy the list, or make one or more additional lists: def f(a_list): another_copy = a_list[:] another_list = map(int, a_list) > 2. When do I need > to manually allocate/deallocate memory and when can I trust Python to > take care of it? You never need to manually allocate memory. You *may* need to deallocate memory if you make "reference loops", where one object refers to itself: l = [] # make an empty list l.append(l) # add the list l to itself Python can break such simple reference loops itself, but for more complicated ones, you may need to break them yourself: a = [] b = {2: a} c = (None, b) d = [1, 'z', c] a.append(d) # a reference loop Python will deallocate objects when they are no longer in use. They are always considered in use any time you have them assigned to a name, or in a list or dict or other structure which is in use. You can explicitly remove a name with the del command. For example: x = ['my', 'data'] del x After deleting the name x, the list object itself is no longer in use anywhere and Python will deallocate it. But consider: x = ['my', 'data'] y = x # y now refers to THE SAME list object del x Although you have deleted the name x, the list object is still bound to the name y, and so Python will *not* deallocate the list. Likewise: x = ['my', 'data'] y = [None, 1, x, 'hello world'] del x Although now the list isn't bound to a name, it is inside another list, and so Python will not deallocate it. > 3. Any good practice suggestions? Write small functions. Any temporary objects created by the function will be automatically deallocated when the function returns. Avoid global variables. They are a good way to inadvertently end up with multiple long-lasting copies of data. Try to keep data in one big piece rather than lots of little pieces. But contradicting the above, if the one big piece is too big, it will be hard for the operating system to swap it in and out of virtual memory, causing thrashing, which is *really* slow. So aim for big, but not huge. (By "big" I mean megabyte-sized; by "huge" I mean hundreds of megabytes.) If possible, avoid reading the entire file in at once, and instead process it line-by-line. Hope this helps, -- Steven From python at mrabarnett.plus.com Thu Feb 11 20:52:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 01:52:47 +0000 Subject: Pycrypto RSA ciphertext to string back to ciphertext issue In-Reply-To: <4b65abb5-072f-4e3c-91eb-95eea6c8a6a9@b10g2000vbh.googlegroups.com> References: <4b65abb5-072f-4e3c-91eb-95eea6c8a6a9@b10g2000vbh.googlegroups.com> Message-ID: <4B74B46F.9070603@mrabarnett.plus.com> Jordan Apgar wrote: > Hey all, > I'm trying to convert the encrypted data from RSA to a string for > sending over xmlrpc and then back to usable data. Whenever I decrypt > I just get junk data. Has anyone else tried doing this? Here's some > example code: > > from Crypto.PublicKey import RSA > from Crypto import Random > > key = RSA.generate(384, Random.new().read) > l = str(key.encrypt("dog","")) > l = stringToTuple(l) > l = key.decrypt(tuple(l)) > print l > > string to tuple: > def stringToTuple(string): > if string[0] + string[-1] == "()": > items = string[1:-1] > items = items.split(',') > return items > else: > raise ValueError("Badly formatted string (missing brackets).") > > thanks for any help, I've been messing with this for days and have > come up dry. I don't know what you're trying to do with converting tuples to bytestrings and back, but this works: >>> key = RSA.generate(384, Random.new().read) >>> encrypted = key.encrypt("dog", "")[0] >>> encrypted "NB\xe9\xcf\x88\xf8b.\x81X{\x12\xeaH\x03\xe9\xc4\xd6\xdb\x00lS\r\xc9in|\xa5\xb1' $\x90_\xc5t$\xd0\xc40-p\x8b\xd0\x95\xdb\xa6\xf7\xc2" >>> key.decrypt(encrypted) 'dog' From python.list at tim.thechases.com Thu Feb 11 21:36:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Feb 2010 20:36:57 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <4B74BEC9.40805@tim.thechases.com> Jonathan Gardner wrote: > Don't use Python variables to store data long-term. Instead, setup a > database or a file and use that. I'd first look at using a file, then > using SQLite, and then a full-fledged database like PostgreSQL. Just to add to the mix, I'd put the "anydbm" module on the gradient between "using a file" and "using sqlite". It's a nice intermediate step between rolling your own file formats for data on disk, and having to write SQL since access is entirely like you'd do with a regular Python dictionary. -tkc From aahz at pythoncraft.com Thu Feb 11 21:38:46 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 18:38:46 -0800 Subject: timer for a function References: Message-ID: In article , mk wrote: > >self.conobj = paramiko.SSHClient() > >self.conobj.connect(self.ip, username=self.username, >key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) > >2. very slow SSH host that is hanging for 30+ seconds on key exchange. > >The timeout in the options regards only a socket timeout, not further >stages of connection negotiation, so it doesn't work there. Does paramiko offer any kind of callback? In a similar situation with pycurl, I built my own timer into a callback. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Thu Feb 11 21:41:27 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 18:41:27 -0800 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: In article <34fcf680-1aa4-4835-9eba-3db3249f36b2 at q16g2000yqq.googlegroups.com>, hjebbers wrote: > >the error is a windows thing, I can make a screenshot of it, but I can >not copy/paste text. In that case, you need to -- very carefully -- make sure you transcribe exactly the message that you see on the screen. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Thu Feb 11 21:44:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 18:44:28 -0800 Subject: Bizarre arithmetic results References: Message-ID: In article , Grant Edwards wrote: > >Didn't we just do this one last week? Let's do the Time Warp again! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From alfps at start.no Thu Feb 11 21:47:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 03:47:34 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Martin P. Hellwig: > > Well at least you are well written and more subtle than Xah Lee. > Though I find him also quite amusing, I do like a good flame-war every > now and again, and in that perspective I solute you. The technical discussion is now at point where one poster maintains that references don't exist in Python, and another poster, in support, maintains that "refers to" in the language spec doesn't mean "refers to" but instead means "refers to", whatever's that meant to mean. As a technical discussion it's meaningless drivel. And as an argument in that technical discussion your allegation of trolling is just yet another fallacy, and meaningless. But in a social context, declaring support or placing oneself within a group, or for that matter "Poisoning the well", it can make sense. This group has an extraordinary high level of flaming and personal attacks, and it's the only group I've seen where there are threads (I think I've seen 3, within the last two months, not participating in them) with the regulars reitererating how "friendly" the group is, how difficult it is to get flamed here. In other groups it's not necessary for the regulars to point out how friendly the group is. But then, in other groups personal attacks are rare. And so when you mention Xah Lee I'm now wondering what is cause, and what is effect. I was informed that he'd done extensive cross-posting, and his own web site seems to confirm that his ISP at one time reacted to a complaint about such cross-posting. I've also seen directly that he has employed pretty foul language in characterizing Python in an article, and even without that language negative loaded characterizations without any evidence to back them up (like, for example, yours above) must be considered intentional flame bait. But did it start that way for Xah Lee? I'm not going to check the archives. It's enough, wrt. the point I'm making about some regulars of the group, that even with such evidence of active trolling at hand -- ISP reaction to cross-posting, needless foul language, unsubstantiated characterizations -- based on my experience here I think it's just as likely that it started out by Xah Lee being flamed, perhaps repeatedly, with personal attacks and by group action. Or perhaps it didn't, but at this point it would not surprise me in the slightest. Cheers & hth., - Alf From no.email at nospam.invalid Thu Feb 11 22:41:21 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Feb 2010 19:41:21 -0800 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> Message-ID: <7xy6iz86ji.fsf@ruckus.brouhaha.com> Mark Lawrence writes: >> The predecessor of the Enigma was cracked by Polish scientists years >> before WW2 started.... > I believe that all of Enigma was eventually cracked cos of two major > flaws. I think it never would have been cracked if it hadn't been cracked (whether by the Brits or the Poles) before the war started, using commercial versions of the Enigma that they had access to. The military Enigma and its operating methods got more sophisticated as the war went on, and the cryptanalysts were able to keep up with it by incrementally improving techniques that they were already using at scale. If they were suddenly confronted with the full-blown military system in the middle of the war, it would have been a lot harder to do anything about it. At least, most of the Enigma-related books I've read give that impression and even come out and say such things. > Further, the far more powerful Geheimscreiber was also cracked at > Bletchley by using Colossus. Sorry some years since I read the book > about this so can't remember the title or author. See http://en.wikipedia.org/wiki/Colossus_computer That was almost at the end of the war though. From aahz at pythoncraft.com Thu Feb 11 23:58:02 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 20:58:02 -0800 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: In article , Tim Chase wrote: > >Just to add to the mix, I'd put the "anydbm" module on the gradient >between "using a file" and "using sqlite". It's a nice intermediate >step between rolling your own file formats for data on disk, and having >to write SQL since access is entirely like you'd do with a regular >Python dictionary. Not quite. One critical difference between dbm and dicts is the need to remember to "save" changes by setting the key's valud again. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 00:16:59 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 21:16:59 -0800 Subject: execute sqlite3 dot commands in python References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: In article , Steve Holden wrote: > >No. That's not how you pass commands to sqlite3 - you connect to a >database, create a cursor on the connection, and then execute SQL >statements (not sqlite commands) on the cursor. Like this: > >>>> import sqlite3 >>>> c = sqlite3.connect("deleteme") >>>> cu = c.cursor() >>>> cu.execute(".help") >Traceback (most recent call last): > File "", line 1, in >sqlite3.OperationalError: near ".": syntax error >>>> cu.execute("""\ >... CREATE TABLE test( >... a int primary key, >... b varchar)""") > >>>> > >As you can see, the cursor's execute() method expects SQL statements. However, it may not be obvious that some things that don't look like SQL are. For example, "pragma integrity_check". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 00:18:26 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 21:18:26 -0800 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> <4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: In article , Gabriel Genellina wrote: > >Strange. With Python 2.6.4 I don't need to do that; I'd say the difference >is in the OS or antivirus (some AV are known to break the TCP stack). Perhaps, but I've also found that ctrl-C doesn't work on Windows. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From tjreedy at udel.edu Fri Feb 12 00:31:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Feb 2010 00:31:14 -0500 Subject: Function attributes In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: On 2/11/2010 6:36 PM, Gabriel Genellina wrote: > This is simple to implement, but requires changing the function > definition. My goal was to keep the original code unchanged, that is, > leave it as: > > def f(n): > if n > 0: return n*f(n-1) > elif n==0: return 1 > > (like a normal, recursive function), and make the 'f' inside the function > body "magically" refer to the function itself. Someone did this several years ago with a bytecode hack. I believe it was in the cookbook. It was rejected as part of standard CPython. From tjreedy at udel.edu Fri Feb 12 00:48:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Feb 2010 00:48:30 -0500 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: On 2/11/2010 9:41 PM, Aahz wrote: > In article<34fcf680-1aa4-4835-9eba-3db3249f36b2 at q16g2000yqq.googlegroups.com>, > hjebbers wrote: >> >> the error is a windows thing, I can make a screenshot of it, but I can >> not copy/paste text. I think I know what box you mean. I believe this happened about 18 months ago with IDLE before 3.0 was released. Something to do with MS VC, which is different from gcc used on *nix. > In that case, you need to -- very carefully -- make sure you transcribe > exactly the message that you see on the screen. From frank at chagford.com Fri Feb 12 01:59:54 2010 From: frank at chagford.com (Frank Millman) Date: Fri, 12 Feb 2010 08:59:54 +0200 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr><4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: "Aahz" wrote in message news:hl2ob2$3ib$1 at panix5.panix.com... > In article , > Gabriel Genellina wrote: >> >>Strange. With Python 2.6.4 I don't need to do that; I'd say the difference >>is in the OS or antivirus (some AV are known to break the TCP stack). > > Perhaps, but I've also found that ctrl-C doesn't work on Windows. I don't know if this is exactly the same, but FWIW ... I had the following, in a test program - from wsgiref.simple_server import make_server myserver = MyServer() httpd = make_server('', 7789, myserver) httpd.serve_forever() try: while True: sleep(1) except KeyboardInterrupt: httpd.shutdown() I could not get it to respond to Ctrl-C. Then I read somewhere that it must run in a separate thread, so I changed it like this - - httpd.serve_forever() + threading.Thread(target=httpd.serve_forever).start() Now it does respond to Ctrl-C. HTH Frank Millman From bob.martin at excite.com Fri Feb 12 02:16:01 2010 From: bob.martin at excite.com (Bob Martin) Date: Fri, 12 Feb 2010 07:16:01 GMT Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: in 144446 20100212 034121 Paul Rubin wrote: >See http://en.wikipedia.org/wiki/Colossus_computer >That was almost at the end of the war though. Colossus was working by the end of 1943 - the year that the Americans first dropped bombs on Germany ;-) From arnodel at googlemail.com Fri Feb 12 02:29:12 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 12 Feb 2010 07:29:12 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: "Gabriel Genellina" writes: > En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy > escribi?: >> On 2/10/2010 4:49 PM, Gabriel Genellina wrote: >> >>> I've written a decorator for "injecting" a __function__ name into the >>> function namespace, but I can't find it anywhere. I think I implemented >>> it by adding a fake additional argument and replacing LOAD_GLOBAL with >>> LOAD_NAME in the bytecode. >> >> The decorator only needs to replace the defaults args tuple. >> It does not even need to know the parameter name, >> just that it is the only (or last) with a default . >> >> def f(n, me=None): >> if n > 0: return n*me(n-1) >> elif n==0: return 1 >> >> f.__defaults__ = (f,) # 3.1 >> print(f(5)) > > This is simple to implement, but requires changing the function > definition. My goal was to keep the original code unchanged, that is, > leave it as: > > def f(n): > if n > 0: return n*f(n-1) > elif n==0: return 1 > > (like a normal, recursive function), and make the 'f' inside the function > body "magically" refer to the function itself. I posted an example of a decorator that does just this in this thread a couple of days ago: http://mail.python.org/pipermail/python-list/2010-February/1235742.html It doesn't require any bytecode hacking, although it requires breaking apart the function object and making a new one from the bits. -- Arnaud From javier.collado at gmail.com Fri Feb 12 02:59:44 2010 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 12 Feb 2010 08:59:44 +0100 Subject: python and http POST In-Reply-To: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: Hello, I haven't used httplib2, but you can certainly use any other alternative to send HTTP requests: - urllib/urllib2 - mechanize With regard to how do you find the form you're looking for, you may: - create the HTTP request on your own with urllib2. To find out what variables do you need to post, you can use tamperdata Firefox addon as suggested (I haven't used that one) or httpfox (I have and it works great). - use mechanize to locate the form for you, fill the data in and click on the submit button. Additionally, you may wan to scrape some data that may be useful for your requests. For that BeautifulSoup is good solution (with some Firebug help to visually locate what you're looking for). Best regards, Javier P.S. Some examples here: http://www.packtpub.com/article/web-scraping-with-python http://www.packtpub.com/article/web-scraping-with-python-part-2 2010/2/11 galileo228 : > Hey All, > > Been teaching myself Python for a few weeks, and am trying to write a > program that will go to a url, enter a string in one of the search > fields, submit the search, and return the contents of the search > result. > > I'm using httplib2. > > My two particular questions: > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > how do I know what the particular key should be? In other words, how > do I tell python which form on the web page I'm visiting I'd like to > fill in? Do I simply go to the webpage itself and look at the html > source? But if that's the case, which tag tells me the name of the > key? > > 2) Even once python fills in the form properly, how can I tell it to > 'submit' the search? > > Thanks all! > > Matt > -- > http://mail.python.org/mailman/listinfo/python-list > From jpiitula at ling.helsinki.fi Fri Feb 12 04:40:20 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 12 Feb 2010 11:40:20 +0200 Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Terry Reedy writes: > On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > > Robert Kern writes: > >> On 2010-02-11 06:31 AM, Shashwat Anand wrote: > >>> There is a little issue here that '>>> -.1 ** .1' should give you > >>> error message. That is it. > >> > >> No, fractional powers of negative numbers are perfectly valid > >> mathematically. The result is a complex number. In Python 3 (what > >> the OP is using), this has been implemented, but not in Python 2.6. > > > > Perhaps it should raise a MisleadingSpacingError at compile time. > > You forgot the smiley ;-). > > > The error message could recommend - .1**.1, or better -(.1 ** .1). > > The compiler would never see the difference between -.1 ** .1 and the > first and probably no difference with the second either. It could be done the same way that the compiler keeps track of the source line numbers now: early phases annotate their output with any information that later phases may need. This error would be detected during syntactic analysis. :) From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 12 04:46:29 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 12 Feb 2010 10:46:29 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4b75235b$0$23469$426a74cc@news.free.fr> Alf P. Steinbach a ?crit : (snip) > This group has an extraordinary high level of flaming and personal > attacks Oh my... (snip remaining non-sense) Mr Steinbach, I bet you'll count this as another "flaming" and "personal attack", but nonetheless : you might have happier time if you were able to understand the distinction between disagreement and "personal attack". (now back to more interesting readings) From jeanmichel at sequans.com Fri Feb 12 05:33:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Feb 2010 11:33:19 +0100 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: <4B752E6F.5070305@sequans.com> Bob Martin wrote: > in 144446 20100212 034121 Paul Rubin wrote: > > >> See http://en.wikipedia.org/wiki/Colossus_computer >> That was almost at the end of the war though. >> > > Colossus was working by the end of 1943 - the year that the Americans first dropped > bombs on Germany ;-) > sept 1939 - sept 1945. It's nearer from the end, than from the begining. JM From vinay_sajip at yahoo.co.uk Fri Feb 12 05:42:07 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 12 Feb 2010 02:42:07 -0800 (PST) Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: <1d2a3c99-4837-45f8-8af0-73a155011686@z26g2000yqm.googlegroups.com> On Feb 11, 7:12?pm, mk wrote: > Peter Otten wrote: > > try: > > ? ?... > > except socket.error: > > ? ?... > > > #untested > > import socket > > > class SocketWrapper: > > ? ? def __getattr__(self, name): > > ? ? ? ? return getattr(socket, name) > > ? ? error = None > > > import module_using_socket > > module_using_socket.socket = SocketWrapper() > > Very interesting solution. Thanks! > > Regards, > mk On Feb 11, 2:12 pm, mk wrote: > Peter Otten wrote: > > try: > > ... > > except socket.error: > > ... > > > #untested > > import socket > > > class SocketWrapper: > > def __getattr__(self, name): > > return getattr(socket, name) > > error = None > > > import module_using_socket > > module_using_socket.socket = SocketWrapper() > > Very interesting solution. Thanks! > > Regards, > mk You could refine Peter's suggestion further. For example, if you don't want to change the flow of execution (as Peter's suggestion does) but just log the occurrences, then you could try something like this: # socktest.py import socket def test(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(('localhost', 9999)) except socket.error, e: print '-- handler printing:', e # sockwrap.py import socket import traceback import logging class SocketWrapper: def __getattr__(self, name): return getattr(socket, name) @property def error(self): # In practice you could log to a specific logger logging.exception('A socket error occurred') return getattr(socket, 'error') def wrap(mod): mod.socket = SocketWrapper() # Now try it out >>> import socktest, sockwrap >>> sockwrap.wrap(socktest) >>> socktest.test() ERROR:root:A socket error occurred Traceback (most recent call last): File "socktest.py", line 7, in test s.connect(('localhost', 9999)) File "", line 1, in connect error: (10061, 'Connection refused') -- handler printing: (10061, 'Connection refused') >>> Regards, Vinay Sajip From hjebbers at gmail.com Fri Feb 12 05:56:19 2010 From: hjebbers at gmail.com (hjebbers) Date: Fri, 12 Feb 2010 02:56:19 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> On Feb 12, 3:41?am, a... at pythoncraft.com (Aahz) wrote: > In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, > > hjebbers ? wrote: > > >the error is a windows thing, I can make a screenshot of it, but I can > >not copy/paste text. > > In that case, you need to -- very carefully -- make sure you transcribe > exactly the message that you see on the screen. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "At Resolver we've found it useful to short-circuit any doubt and just ? ? ? ? > refer to comments in code as 'lies'. :-)" The message on the screen is (I typed it over): ************************************************************************************** python.exe python.exe has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost For more information about the error, click here. *************************************************************************************** the information about the error is a windows dump. kind regards, henk-jan From duncan.booth at invalid.invalid Fri Feb 12 07:10:26 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Feb 2010 12:10:26 GMT Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Peter Otten <__peter__ at web.de> wrote: > You could try to shadow the exception class with None: > >>>> ZeroDivisionError = None >>>> try: > ... 1/0 > ... except ZeroDivisionError: > ... print "caught" > ... > Traceback (most recent call last): > File "", line 2, in > ZeroDivisionError: integer division or modulo by zero > This works in Python 2.x but will break in Python 3. None is not a valid exception specification and Python 3 will check for that and complain. >>> ZeroDivisionError = None >>> try: ... 1/0 ... except ZeroDivisionError: ... print('caught') ... Traceback (most recent call last): File "", line 2, in ZeroDivisionError: int division or modulo by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 3, in TypeError: catching classes that do not inherit from BaseException is not allowed >>> A better solution is to use an empty tuple as that is a valid exception specification so will work in both Python 2.x and 3.x: >>> ZeroDivisionError = () >>> try: ... 1/0 ... except ZeroDivisionError: ... print('caught') ... Traceback (most recent call last): File "", line 2, in ZeroDivisionError: int division or modulo by zero -- Duncan Booth http://kupuguy.blogspot.com From python.list at tim.thechases.com Fri Feb 12 07:15:41 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 06:15:41 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <4B75466D.6040706@tim.thechases.com> Aahz wrote: > Tim Chase wrote: >> Just to add to the mix, I'd put the "anydbm" module on the gradient >> between "using a file" and "using sqlite". It's a nice intermediate >> step between rolling your own file formats for data on disk, and having >> to write SQL since access is entirely like you'd do with a regular >> Python dictionary. > > Not quite. One critical difference between dbm and dicts is the need to > remember to "save" changes by setting the key's valud again. Could you give an example of this? I'm not sure I understand what you're saying. I've used anydbm a bunch of times and other than wrapping access in d = anydbm.open(DB_NAME, "c") # use d as a dict here d.close() and I've never hit any "need to remember to save changes by setting the key's value again". The only gotcha I've hit is the anydbm requirement that all keys/values be strings. Slightly annoying at times, but my most frequent use case. -tkc From prakash.stack at gmail.com Fri Feb 12 07:17:52 2010 From: prakash.stack at gmail.com (prakash jp) Date: Fri, 12 Feb 2010 17:47:52 +0530 Subject: search entire drive say c: Message-ID: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Hi all, can any of u help to search a file say "abc.txt" in entire c drive (windows) and print the path/s stating such a files presence. Thanks in advance Regards Prakash -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Feb 12 07:36:42 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Feb 2010 12:36:42 +0000 Subject: search entire drive say c: In-Reply-To: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <4B754B5A.3000405@timgolden.me.uk> On 12/02/2010 12:17, prakash jp wrote: > Hi all, > > can any of u help to search a file say "abc.txt" in entire c drive (windows) > and print the path/s stating such a files presence. This sounds rather like homework... Have a look at os.walk TJG From python.list at tim.thechases.com Fri Feb 12 08:01:12 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 07:01:12 -0600 Subject: search entire drive say c: In-Reply-To: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <4B755118.7090706@tim.thechases.com> > can any of u help to search a file say "abc.txt" in entire c drive (windows) > and print the path/s stating such a files presence. Well, you can just do it from DOS: c:\> dir /s/b/a abc.txt Just use os.walk() and check the list of files returned at each directory-level iteration. ROOT = "c:\\" fname = "abc.txt".lower() for p, d, f in os.walk(ROOT): for fn in f: if fn.lower() == fname: print os.path.join(p, f) # break You might also investigate using os.path.normcase() instead of .lower() -tkc From davea at ieee.org Fri Feb 12 08:06:07 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 12 Feb 2010 08:06:07 -0500 Subject: python crash on windows but not on linux In-Reply-To: <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: <4B75523F.4020903@ieee.org> hjebbers wrote: > On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: > >> In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >> >> hjebbers wrote: >> >> >>> the error is a windows thing, I can make a screenshot of it, but I can >>> not copy/paste text. >>> >> In that case, you need to -- very carefully -- make sure you transcribe >> exactly the message that you see on the screen. >> -- >> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >> >> "At Resolver we've found it useful to short-circuit any doubt and just >> refer to comments in code as 'lies'. :-)" >> > > The message on the screen is (I typed it over): > > You shouldn't ever have to retype the message. Just paste from the DOS box (or "Command Prompt"). It's easy using QuickEdit mode. You select a rectangle of the text by selecting with the mouse, then using right-click to put it in the clipboard. If that doesn't work, you haven't yet enabled QuickEdit mode. Use right-click on the DOS box's title bar. Choose Properties. Select the first tab, which is Options. You should then see a selection box called "Quick Edit Mode". Turn it on, and you won't have this problem again. DaveA From simon at brunningonline.net Fri Feb 12 08:21:26 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 12 Feb 2010 13:21:26 +0000 Subject: search entire drive say c: In-Reply-To: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <8c7f10c61002120521x3a820074r6765cc4622f912ca@mail.gmail.com> On 12 February 2010 12:17, prakash jp wrote: > can any of u help to search a file say "abc.txt" in entire c drive (windows) > and print?the path/s stating such a files presence. http://code.activestate.com/recipes/499305/ might be a useful start. -- Cheers, Simon B. From hjebbers at gmail.com Fri Feb 12 08:32:05 2010 From: hjebbers at gmail.com (hjebbers) Date: Fri, 12 Feb 2010 05:32:05 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: On Feb 12, 2:06?pm, Dave Angel wrote: > hjebbers wrote: > > On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: > > >> In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, > > >> hjebbers ? wrote: > > >>> the error is a windows thing, I can make a screenshot of it, but I can > >>> not copy/paste text. > > >> In that case, you need to -- very carefully -- make sure you transcribe > >> exactly the message that you see on the screen. > >> -- > >> Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > >> "At Resolver we've found it useful to short-circuit any doubt and just ? ? ? ? > >> refer to comments in code as 'lies'. :-)" > > > The message on the screen is (I typed it over): > > > > > You shouldn't ever have to retype the message. ?Just paste from the DOS > box (or "Command Prompt"). ?It's easy using QuickEdit mode. > > You select a rectangle of the text by selecting with the mouse, then > using right-click to put it in the clipboard. > > If that doesn't work, you haven't yet enabled QuickEdit mode. ?Use > right-click on the DOS box's title bar. ?Choose Properties. ?Select the > first tab, which is Options. > > You should then see a selection box called "Quick Edit Mode". ?Turn it > on, and you won't have this problem again. > > DaveA Hi Dave, thanks. but the message is not in the DOS box (or "Command Prompt"). I do run the program in a DOS box (or "Command Prompt"), but the error is a windows dialog box. I can not select in this dialog box. kind regards, henk-jan From steve at holdenweb.com Fri Feb 12 08:34:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 08:34:40 -0500 Subject: python crash on windows but not on linux In-Reply-To: <4B75523F.4020903@ieee.org> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> <4B75523F.4020903@ieee.org> Message-ID: <4B7558F0.5090403@holdenweb.com> Dave Angel wrote: > hjebbers wrote: >> On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: >> >>> In article >>> <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >>> >>> hjebbers wrote: >>> >>> >>>> the error is a windows thing, I can make a screenshot of it, but I can >>>> not copy/paste text. >>>> >>> In that case, you need to -- very carefully -- make sure you transcribe >>> exactly the message that you see on the screen. >>> -- >>> Aahz (a... at pythoncraft.com) <*> >>> http://www.pythoncraft.com/ >>> >>> "At Resolver we've found it useful to short-circuit any doubt and >>> just refer to comments in code as 'lies'. :-)" >>> >> >> The message on the screen is (I typed it over): >> >> > > You shouldn't ever have to retype the message. Just paste from the DOS > box (or "Command Prompt"). It's easy using QuickEdit mode. > > You select a rectangle of the text by selecting with the mouse, then > using right-click to put it in the clipboard. > > If that doesn't work, you haven't yet enabled QuickEdit mode. Use > right-click on the DOS box's title bar. Choose Properties. Select the > first tab, which is Options. > > You should then see a selection box called "Quick Edit Mode". Turn it > on, and you won't have this problem again. > > DaveA > Dave: I think you miss the point: this message is being displayed in a Windows error message dialog box, not in the command window. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 12 08:34:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 08:34:40 -0500 Subject: python crash on windows but not on linux In-Reply-To: <4B75523F.4020903@ieee.org> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> <4B75523F.4020903@ieee.org> Message-ID: <4B7558F0.5090403@holdenweb.com> Dave Angel wrote: > hjebbers wrote: >> On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: >> >>> In article >>> <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >>> >>> hjebbers wrote: >>> >>> >>>> the error is a windows thing, I can make a screenshot of it, but I can >>>> not copy/paste text. >>>> >>> In that case, you need to -- very carefully -- make sure you transcribe >>> exactly the message that you see on the screen. >>> -- >>> Aahz (a... at pythoncraft.com) <*> >>> http://www.pythoncraft.com/ >>> >>> "At Resolver we've found it useful to short-circuit any doubt and >>> just refer to comments in code as 'lies'. :-)" >>> >> >> The message on the screen is (I typed it over): >> >> > > You shouldn't ever have to retype the message. Just paste from the DOS > box (or "Command Prompt"). It's easy using QuickEdit mode. > > You select a rectangle of the text by selecting with the mouse, then > using right-click to put it in the clipboard. > > If that doesn't work, you haven't yet enabled QuickEdit mode. Use > right-click on the DOS box's title bar. Choose Properties. Select the > first tab, which is Options. > > You should then see a selection box called "Quick Edit Mode". Turn it > on, and you won't have this problem again. > > DaveA > Dave: I think you miss the point: this message is being displayed in a Windows error message dialog box, not in the command window. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From eknath.iyer at gmail.com Fri Feb 12 08:41:40 2010 From: eknath.iyer at gmail.com (Eknath Venkataramani) Date: Fri, 12 Feb 2010 08:41:40 -0500 Subject: pyparsing wrong output Message-ID: <692c428f1002120541n6b3aabb0jb62c50f90715f38e@mail.gmail.com> I am trying to write a parser in pyparsing. Help Me. http://paste.pocoo.org/show/177078/ is the code and this is input file: http://paste.pocoo.org/show/177076/ . I get output as: * * -- Eknath Venkataramani +91-9844952442 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Feb 12 08:53:02 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Feb 2010 14:53:02 +0100 Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: > >> You could try to shadow the exception class with None: > This works in Python 2.x but will break in Python 3. None is not a valid > exception specification and Python 3 will check for that and complain. > A better solution is to use an empty tuple as that is a valid exception > specification so will work in both Python 2.x and 3.x: Out of curiosity I tried a custom __subclasscheck__, but didn't get it to work in 3.1: $ cat instance_check.py class ZeroDivisionError(BaseException): class __metaclass__(type): def __subclasscheck__(self, other): print "performing subclass check --> %s" % catch return catch if __name__ == "__main__": for catch in [True, False]: print "catch = %s" % catch try: 1/0 except ZeroDivisionError: print "caught" $ python2.6 instance_check.py catch = True performing subclass check --> True caught catch = False performing subclass check --> False Traceback (most recent call last): File "instance_check.py", line 11, in 1/0 ZeroDivisionError: integer division or modulo by zero $ Peter From ljz at asfast.com Fri Feb 12 09:01:20 2010 From: ljz at asfast.com (Lloyd Zusman) Date: Fri, 12 Feb 2010 14:01:20 +0000 (UTC) Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? Message-ID: Perl has the following constructs to check whether a file is considered to contain "text" or "binary" data: if (-T $filename) { print "file contains 'text' characters\n"; } if (-B $filename) { print "file contains 'binary' characters\n"; } Is there already a Python analog to these? I'm happy to write them on my own if no such constructs currently exist, but before I start, I'd like to make sure that I'm not "re-inventing the wheel". By the way, here's what the perl docs say about these constructs. I'm looking for something similar in Python: ... The -T and -B switches work as follows. The first block or so ... of the file is examined for odd characters such as strange control ... codes or characters with the high bit set. If too many strange ... characters (>30%) are found, it's a -B file; otherwise it's a -T ... file. Also, any file containing null in the first block is ... considered a binary file. [ ... ] Thanks in advance for any suggestions. -- Lloyd Zusman ljz at asfast.com God bless you. From lists at cheimes.de Fri Feb 12 09:09:58 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 15:09:58 +0100 Subject: python crash on windows but not on linux In-Reply-To: <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: <4B756136.3070202@cheimes.de> hjebbers wrote: > The message on the screen is (I typed it over): > > ************************************************************************************** > python.exe > > python.exe has encountered a problem and needs to close. > We are sorry for the inconvenience. > > If you were in the middle of something, the information you were > working on might be > lost > > For more information about the error, click here. > > button> > *************************************************************************************** > the information about the error is a windows dump. I suggest you install some sort of debugger on your system (e.g. Visual Studio) and do a post mortem analysis of your stack trace. Christian From lists at cheimes.de Fri Feb 12 09:14:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 15:14:07 +0100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <4B75622F.8040303@cheimes.de> Lloyd Zusman wrote: > .... The -T and -B switches work as follows. The first block or so > .... of the file is examined for odd characters such as strange control > .... codes or characters with the high bit set. If too many strange > .... characters (>30%) are found, it's a -B file; otherwise it's a -T > .... file. Also, any file containing null in the first block is > .... considered a binary file. [ ... ] That's a butt ugly heuristic that will lead to lots of false positives if your text happens to be UTF-16 encoded or non-english text UTF-8 encoded. Christian From lists at cheimes.de Fri Feb 12 09:14:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 15:14:07 +0100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <4B75622F.8040303@cheimes.de> Lloyd Zusman wrote: > .... The -T and -B switches work as follows. The first block or so > .... of the file is examined for odd characters such as strange control > .... codes or characters with the high bit set. If too many strange > .... characters (>30%) are found, it's a -B file; otherwise it's a -T > .... file. Also, any file containing null in the first block is > .... considered a binary file. [ ... ] That's a butt ugly heuristic that will lead to lots of false positives if your text happens to be UTF-16 encoded or non-english text UTF-8 encoded. Christian From __peter__ at web.de Fri Feb 12 09:17:04 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Feb 2010 15:17:04 +0100 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> Message-ID: hjebbers wrote: > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: >> hjebbers wrote: >> > On Feb 11, 5:45 pm, M3RT wrote: >> >> The problem may be related to how you treat the EDI file or lets say >> >> DATA. Also your coding style is important. Can you provide more info? >> >> > Yes, a whole lot more; but I do not want to bother you with that now. >> > I was just wondering if it is possible that the same setup gives a >> > CRASH! on windows and just works on linux. >> > (where is the bug?) >> >> In the platform-specific code ;) >> >> Even on alt.haruspicy they cannot do much without a liver now and then... > > if it is in the platform-specific code should I make this into a > bugreport? A this stage a bug report would be useless. The details you have provided so far don't give anyone without physical access to your machine a chance to reproduce the error. > (because the crash does not appear at the same place in my code (when > doing the same test-run) it will be quite hard to point down....) Indeed. The culprit may be an extension written in C that is overwriting memory still in use by other parts of your program. Peter From clp2 at rebertia.com Fri Feb 12 09:18:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Feb 2010 06:18:24 -0800 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <50697b2c1002120618u1d3cacccx45a0f209313b220@mail.gmail.com> On Fri, Feb 12, 2010 at 6:01 AM, Lloyd Zusman wrote: > Perl has the following constructs to check whether a file is considered > to contain "text" or "binary" data: > > if (-T $filename) { print "file contains 'text' characters\n"; } > if (-B $filename) { print "file contains 'binary' characters\n"; } > > Is there already a Python analog to these? I'm happy to write them on > my own if no such constructs currently exist, but before I start, I'd > like to make sure that I'm not "re-inventing the wheel". > > By the way, here's what the perl docs say about these constructs. I'm > looking for something similar in Python: > > ... The -T ?and -B ?switches work as follows. The first block or so > ... of the file is examined for odd characters such as strange control > ... codes or characters with the high bit set. If too many strange > ... characters (>30%) are found, it's a -B file; otherwise it's a -T > ... file. Also, any file containing null in the first block is > ... considered a binary file. [ ... ] Pray tell, what are the circumstances that lead you to use such a heuristic rather than a more definitive method? Cheers, Chris -- http://blog.rebertia.com From simon at brunningonline.net Fri Feb 12 09:18:54 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 12 Feb 2010 14:18:54 +0000 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: <4B75622F.8040303@cheimes.de> References: <4B75622F.8040303@cheimes.de> Message-ID: <8c7f10c61002120618r611ea8dfj4d2f4bbaf25a920@mail.gmail.com> On 12 February 2010 14:14, Christian Heimes wrote: > That's a butt ugly heuristic He did say it was from Perl, the home of butt-ugly. -- Cheers, Simon B. From aahz at pythoncraft.com Fri Feb 12 09:21:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 06:21:19 -0800 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: In article , Tim Chase wrote: >Aahz wrote: >> Tim Chase wrote: >>> >>> Just to add to the mix, I'd put the "anydbm" module on the gradient >>> between "using a file" and "using sqlite". It's a nice intermediate >>> step between rolling your own file formats for data on disk, and having >>> to write SQL since access is entirely like you'd do with a regular >>> Python dictionary. >> >> Not quite. One critical difference between dbm and dicts is the need to >> remember to "save" changes by setting the key's valud again. > >Could you give an example of this? I'm not sure I understand >what you're saying. I've used anydbm a bunch of times and other >than wrapping access in > > d = anydbm.open(DB_NAME, "c") > # use d as a dict here > d.close() > >and I've never hit any "need to remember to save changes by >setting the key's value again". The only gotcha I've hit is the >anydbm requirement that all keys/values be strings. Slightly >annoying at times, but my most frequent use case. Well, you're more likely to hit this by wrapping dbm with shelve (because it's a little more obvious when you're using pickle directly), but consider this: d = anydbm.open(DB_NAME, "c") x = MyClass() d['foo'] = x x.bar = 123 Your dbm does NOT have the change to x.bar recorded, you must do this again: d['foo'] = x With a dict, you have Python's reference semantics. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 09:22:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 06:22:40 -0800 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: In article , Dennis Lee Bieber wrote: >On 11 Feb 2010 21:18:26 -0800, aahz at pythoncraft.com (Aahz) declaimed the >following in gmane.comp.python.general: >> In article , >> Gabriel Genellina wrote: >>> >>>Strange. With Python 2.6.4 I don't need to do that; I'd say the difference >>>is in the OS or antivirus (some AV are known to break the TCP stack). >> >> Perhaps, but I've also found that ctrl-C doesn't work on Windows. > > Unless the running program makes an I/O call to the console, I don't >think gets past the device driver... That's probably it. It's more annoying for me because I run Windows with a VM on a Mac, which doesn't have ctrl-break. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 09:26:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 06:26:51 -0800 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: In article , Lloyd Zusman wrote: > >Perl has the following constructs to check whether a file is considered >to contain "text" or "binary" data: > >if (-T $filename) { print "file contains 'text' characters\n"; } >if (-B $filename) { print "file contains 'binary' characters\n"; } Assuming you're on a Unix-like system or can install Cygwin, the standard response is to use the "file" command. It's *much* more sophisticated. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From prakash.stack at gmail.com Fri Feb 12 09:33:18 2010 From: prakash.stack at gmail.com (prakash jp) Date: Fri, 12 Feb 2010 20:03:18 +0530 Subject: search entire drive say c: In-Reply-To: <4B755118.7090706@tim.thechases.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> <4B755118.7090706@tim.thechases.com> Message-ID: <805f59d51002120633h387323dcjb9be71e5955536cd@mail.gmail.com> Thank u Tim Case, all, Also how to run the standalone generated from script taking unc path names to account regards Prakash On Fri, Feb 12, 2010 at 6:31 PM, Tim Chase wrote: > can any of u help to search a file say "abc.txt" in entire c drive >> (windows) >> and print the path/s stating such a files presence. >> > > Well, you can just do it from DOS: > > c:\> dir /s/b/a abc.txt > > Just use os.walk() and check the list of files returned at each > directory-level iteration. > > ROOT = "c:\\" > fname = "abc.txt".lower() > for p, d, f in os.walk(ROOT): > for fn in f: > if fn.lower() == fname: > print os.path.join(p, f) > # break > > You might also investigate using os.path.normcase() instead of .lower() > > -tkc > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 12 09:39:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 12 Feb 2010 15:39:22 +0100 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <4b7567fe$0$13293$426a34cc@news.free.fr> Peter Otten a ?crit : (snip) > Even on alt.haruspicy they cannot do much without a liver now and then... Muhahahahaha !-) +1 QOTW From python.list at tim.thechases.com Fri Feb 12 09:45:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 08:45:17 -0600 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <4B75697D.5040403@tim.thechases.com> Lloyd Zusman wrote: > Perl has the following constructs to check whether a file is considered > to contain "text" or "binary" data: > > if (-T $filename) { print "file contains 'text' characters\n"; } > if (-B $filename) { print "file contains 'binary' characters\n"; } > > Is there already a Python analog to these? I'm happy to write them on > my own if no such constructs currently exist, but before I start, I'd > like to make sure that I'm not "re-inventing the wheel". > > By the way, here's what the perl docs say about these constructs. I'm > looking for something similar in Python: > > ... The -T and -B switches work as follows. The first block or so > ... of the file is examined for odd characters such as strange control > ... codes or characters with the high bit set. If too many strange > ... characters (>30%) are found, it's a -B file; otherwise it's a -T > ... file. Also, any file containing null in the first block is > ... considered a binary file. [ ... ] While I agree with the others who have responded along the lines of "that's a hinky heuristic", it's not too hard to write an analog: import string def is_text(fname, chars=set(string.printable), threshold=0.3, portion=1024, # read a kilobyte to find out mode='rb', ): assert portion is None or portion > 0 assert 0 < threshold < 1 f = file(fname, mode) if portion is None: content = iter(f) else: content = iter(f.read(int(portion))) f.close() total = valid = 0 for c in content: if c in chars: valid += 1 total += 1 return (float(valid)/total) > threshold def is_bin(*args, **kwargs): return not is_text(*args, **kwargs) for fname in ( '/usr/bin/abiword', '/home/tkc/.bashrc', ): print fname, is_text(fname) It should allow you to tweak the charset to consider "text", defaulting to string.printable, but adjust the "text" chars and the file-reading-mode accordingly if you're using unicode text (perhaps inverting the logic to make it an "binary chars" set). You can also change the threshold from 0.3 (30%) to whatever you need, and test the entire file or a subset of it (this defaults to just reading the first K of the file, but if you pass None for the portion, it will read the whole thing, even if it's a TB file). -tkc From jlconlin at gmail.com Fri Feb 12 09:45:31 2010 From: jlconlin at gmail.com (Jeremy) Date: Fri, 12 Feb 2010 06:45:31 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> Message-ID: <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> On Feb 11, 6:50?pm, Steven D'Aprano wrote: > On Thu, 11 Feb 2010 15:39:09 -0800, Jeremy wrote: > > My Python program now consumes over 2 GB of memory and then I get a > > MemoryError. ?I know I am reading lots of files into memory, but not 2GB > > worth. > > Are you sure? > > Keep in mind that Python has a comparatively high overhead due to its > object-oriented nature. If you have a list of characters: > > ['a', 'b', 'c', 'd'] > > there is the (small) overhead of the list structure itself, but each > individual character is not a single byte, but a relatively large object: > > ?>>> sys.getsizeof('a') > 32 > > So if you read (say) a 500MB file into a single giant string, you will > have 500MB plus the overhead of a single string object (which is > negligible). But if you read it into a list of 500 million single > characters, you will have the overhead of a single list, plus 500 million > strings, and that's *not* negligible: 32 bytes each instead of 1. > > So try to avoid breaking a single huge strings into vast numbers of tiny > strings all at once. > > > I thought I didn't have to worry about memory allocation in > > Python because of the garbage collector. > > You don't have to worry about explicitly allocating memory, and you > almost never have to worry about explicitly freeing memory (unless you > are making objects that, directly or indirectly, contain themselves -- > see below); but unless you have an infinite amount of RAM available of > course you can run out of memory if you use it all up :) > > > On this note I have a few > > questions. ?FYI I am using Python 2.6.4 on my Mac. > > > 1. ? ?When I pass a variable to the constructor of a class does it copy > > that variable or is it just a reference/pointer? ?I was under the > > impression that it was just a pointer to the data. > > Python's calling model is the same whether you pass to a class > constructor or any other function or method: > > x = ["some", "data"] > obj = f(x) > > The function f (which might be a class constructor) sees the exact same > list as you assigned to x -- the list is not copied first. However, > there's no promise made about what f does with that list -- it might copy > the list, or make one or more additional lists: > > def f(a_list): > ? ? another_copy = a_list[:] > ? ? another_list = map(int, a_list) > > > 2. ? ?When do I need > > to manually allocate/deallocate memory and when can I trust Python to > > take care of it? > > You never need to manually allocate memory. > > You *may* need to deallocate memory if you make "reference loops", where > one object refers to itself: > > l = [] ?# make an empty list > l.append(l) ?# add the list l to itself > > Python can break such simple reference loops itself, but for more > complicated ones, you may need to break them yourself: > > a = [] > b = {2: a} > c = (None, b) > d = [1, 'z', c] > a.append(d) ?# a reference loop > > Python will deallocate objects when they are no longer in use. They are > always considered in use any time you have them assigned to a name, or in > a list or dict or other structure which is in use. > > You can explicitly remove a name with the del command. For example: > > x = ['my', 'data'] > del x > > After deleting the name x, the list object itself is no longer in use > anywhere and Python will deallocate it. But consider: > > x = ['my', 'data'] > y = x ?# y now refers to THE SAME list object > del x > > Although you have deleted the name x, the list object is still bound to > the name y, and so Python will *not* deallocate the list. > > Likewise: > > x = ['my', 'data'] > y = [None, 1, x, 'hello world'] > del x > > Although now the list isn't bound to a name, it is inside another list, > and so Python will not deallocate it. > > > 3. ? ?Any good practice suggestions? > > Write small functions. Any temporary objects created by the function will > be automatically deallocated when the function returns. > > Avoid global variables. They are a good way to inadvertently end up with > multiple long-lasting copies of data. > > Try to keep data in one big piece rather than lots of little pieces. > > But contradicting the above, if the one big piece is too big, it will be > hard for the operating system to swap it in and out of virtual memory, > causing thrashing, which is *really* slow. So aim for big, but not huge. > > (By "big" I mean megabyte-sized; by "huge" I mean hundreds of megabytes.) > > If possible, avoid reading the entire file in at once, and instead > process it line-by-line. > > Hope this helps, > > -- > Steven Wow, what a great bunch of responses. Thank you very much. If I understand correctly the suggestions seem to be: 1. Write algorithms to read a file one line at a time instead of reading the whole thing 2. Use lots of little functions so that memory can fall out of scope. You also confirmed what I thought was true that all variables are passed "by reference" so I don't need to worry about the data being copied (unless I do that explicitly). Thanks! Jeremy From python.list at tim.thechases.com Fri Feb 12 09:54:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 08:54:27 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <4B756BA3.3090408@tim.thechases.com> Aahz wrote: >>> Not quite. One critical difference between dbm and dicts >>> is the need to remember to "save" changes by setting the >>> key's valud again. >> >> Could you give an example of this? I'm not sure I >> understand what you're saying. > > Well, you're more likely to hit this by wrapping dbm with shelve (because > it's a little more obvious when you're using pickle directly), but > consider this: > > d = anydbm.open(DB_NAME, "c") > x = MyClass() > d['foo'] = x > x.bar = 123 > > Your dbm does NOT have the change to x.bar recorded, you must do this > again: > > d['foo'] = x > > With a dict, you have Python's reference semantics. Ah, that makes sense...fallout of the "dbm only does string keys/values". It try to adhere to the "only use strings", so I'm more cognizant of when I martial complex data-types in or out of those strings. But I can see where it could bite a person. Thanks, -tkc From edreamleo at gmail.com Fri Feb 12 10:09:47 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Fri, 12 Feb 2010 09:09:47 -0600 Subject: ANN: Leo 4.7 rc1 released Message-ID: <8pran590ve55gaasfur10pv4jbcuvvr6pi@4ax.com> Leo 4.7 release candidate 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7 rc 1 fixes all known serious bugs in Leo; minor nits remain. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - Leo creates a 'Recovered Nodes' node to hold data that otherwise might be lost due to clone conflicts. - @auto-rst now works much more reliably reliably. - Leo no longer supports @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream February 12, 2010 From bob.martin at excite.com Fri Feb 12 10:13:07 2010 From: bob.martin at excite.com (Bob Martin) Date: Fri, 12 Feb 2010 15:13:07 GMT Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: <7eedn.39244$Ym4.2333@text.news.virginmedia.com> in 144460 20100212 103319 Jean-Michel Pichavant wrote: >Bob Martin wrote: >> in 144446 20100212 034121 Paul Rubin wrote: >> >> >>> See http://en.wikipedia.org/wiki/Colossus_computer >>> That was almost at the end of the war though. >>> >> >> Colossus was working by the end of 1943 - the year that the Americans first dropped >> bombs on Germany ;-) >> >sept 1939 - sept 1945. It's nearer from the end, than from the begining. If I must spell it out ;-) Near the end for us Brits but the Americans were only just getting into the action in Europe. From breamoreboy at yahoo.co.uk Fri Feb 12 10:39:37 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Feb 2010 15:39:37 +0000 Subject: ANN: obfuscate In-Reply-To: <7xy6iz86ji.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Mark Lawrence writes: >>> The predecessor of the Enigma was cracked by Polish scientists years >>> before WW2 started.... >> I believe that all of Enigma was eventually cracked cos of two major >> flaws. > > I think it never would have been cracked if it hadn't been cracked > (whether by the Brits or the Poles) before the war started, using > commercial versions of the Enigma that they had access to. The military > Enigma and its operating methods got more sophisticated as the war went > on, and the cryptanalysts were able to keep up with it by incrementally > improving techniques that they were already using at scale. If they > were suddenly confronted with the full-blown military system in the > middle of the war, it would have been a lot harder to do anything about > it. At least, most of the Enigma-related books I've read give that > impression and even come out and say such things. I completely agree. > >> Further, the far more powerful Geheimscreiber was also cracked at >> Bletchley by using Colossus. Sorry some years since I read the book >> about this so can't remember the title or author. > > See http://en.wikipedia.org/wiki/Colossus_computer > That was almost at the end of the war though. From macmanes at gmail.com Fri Feb 12 11:06:41 2010 From: macmanes at gmail.com (PeroMHC) Date: Fri, 12 Feb 2010 08:06:41 -0800 (PST) Subject: concatenate fasta file Message-ID: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Hi All, I have a simple problem that I hope somebody can help with. I have an input file (a fasta file) that I need to edit.. Input file format >name 1 tactcatacatac >name 2 acggtggcat >name 3 gggtaccacgtt I need to concatenate the sequences.. make them look like >concatenated tactcatacatacacggtggcatgggtaccacgtt thanks. Matt From tjreedy at udel.edu Fri Feb 12 11:08:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Feb 2010 11:08:34 -0500 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: On 2/12/2010 4:40 AM, Jussi Piitulainen wrote: > Terry Reedy writes: >> On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: >>> Robert Kern writes: >>>> On 2010-02-11 06:31 AM, Shashwat Anand wrote: >>>>> There is a little issue here that '>>> -.1 ** .1' should give you >>>>> error message. That is it. >>>> >>>> No, fractional powers of negative numbers are perfectly valid >>>> mathematically. The result is a complex number. In Python 3 (what >>>> the OP is using), this has been implemented, but not in Python 2.6. >>> >>> Perhaps it should raise a MisleadingSpacingError at compile time. >> >> You forgot the smiley ;-). >> >> > The error message could recommend - .1**.1, or better -(.1 ** .1). >> >> The compiler would never see the difference between -.1 ** .1 and the >> first and probably no difference with the second either. > > It could be done the same way that the compiler keeps track of the > source line numbers now: early phases annotate their output with any > information that later phases may need. This error would be detected > during syntactic analysis. There is no error to detect. Sorry, read the manual and either learn or lookup precedence rules (there is a table in the end of the Expressions chapter) or use parentheses when not sure. From roy at panix.com Fri Feb 12 11:23:54 2010 From: roy at panix.com (Roy Smith) Date: Fri, 12 Feb 2010 11:23:54 -0500 Subject: concatenate fasta file References: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Message-ID: In article <62a50def-e391-4585-9a23-fb91f2e2edc8 at b9g2000pri.googlegroups.com>, PeroMHC wrote: > Hi All, I have a simple problem that I hope somebody can help with. I > have an input file (a fasta file) that I need to edit.. > > Input file format > > >name 1 > tactcatacatac > >name 2 > acggtggcat > >name 3 > gggtaccacgtt > > I need to concatenate the sequences.. make them look like > > >concatenated > tactcatacatacacggtggcatgggtaccacgtt > > thanks. Matt Some quick ideas. First, try something along the lines of (not tested): data=[] for line in sys.stdin: if line.startswith('>'): continue data.append(line.strip()) print ''.join(data) Second, check out http://biopython.org/wiki/Main_Page. I'm sure somebody has solved this problem before. From jeanmichel at sequans.com Fri Feb 12 11:49:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Feb 2010 17:49:15 +0100 Subject: concatenate fasta file In-Reply-To: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> References: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Message-ID: <4B75868B.2030807@sequans.com> PeroMHC wrote: > Hi All, I have a simple problem that I hope somebody can help with. I > have an input file (a fasta file) that I need to edit.. > > Input file format > > >> name 1 >> > tactcatacatac > >> name 2 >> > acggtggcat > >> name 3 >> > gggtaccacgtt > > I need to concatenate the sequences.. make them look like > > >> concatenated >> > tactcatacatacacggtggcatgggtaccacgtt > > thanks. Matt > A solution using regexp: found = [] for line in open('seqfile.txt'): found += re.findall('^[acgtACGT]+$', line) print found > ['tactcatacatac', 'acggtggcat', 'gggtaccacgtt'] print ''.join(found) > 'tactcatacatacacggtggcatgggtaccacgtt' JM From python at mrabarnett.plus.com Fri Feb 12 12:05:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 17:05:37 +0000 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: <4B75622F.8040303@cheimes.de> References: <4B75622F.8040303@cheimes.de> Message-ID: <4B758A61.4090606@mrabarnett.plus.com> Christian Heimes wrote: > Lloyd Zusman wrote: >> .... The -T and -B switches work as follows. The first block or so >> .... of the file is examined for odd characters such as strange control >> .... codes or characters with the high bit set. If too many strange >> .... characters (>30%) are found, it's a -B file; otherwise it's a -T >> .... file. Also, any file containing null in the first block is >> .... considered a binary file. [ ... ] > > That's a butt ugly heuristic that will lead to lots of false positives > if your text happens to be UTF-16 encoded or non-english text UTF-8 encoded. > ...or non-English Latin-1 text... From jcquevedo84 at gmail.com Fri Feb 12 12:08:59 2010 From: jcquevedo84 at gmail.com (Juan Carlos Rodriguez) Date: Fri, 12 Feb 2010 13:08:59 -0400 Subject: Configuring apache to execute python scripts using mod_python handler Message-ID: I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added AddHandler mod_python .py PythonHandler mptest PythonDebug On 2. Then I added the line "LoadModule python_module modules/ mod_python.so" to http.conf. Then I tried execute the python script mentioned below from browser. from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Hello World!") return apache.OK Then I am getting the following error Traceback (most recent call last): File "D:\softwares\Python25\Lib\site-packages\mod_python \importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "D:\softwares\Python25\Lib\site-packages\mod_python \importer.py", line 1202, in _process_target module = import_module(module_name, path=path) File "D:\softwares\Python25\Lib\site-packages\mod_python \importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named mptest I am using Apache 2.2.4, python 2.5 and mod_python-3.3.1.win32-py2.5- Apache2.2. I am able to execute python scripts by configuring apache to execute the cgi scripts. But I want to execute it using mod_python as it is faster compared to cgi mode. Someone please help me on this issue. -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon.hibbs at gmail.com Fri Feb 12 12:11:38 2010 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Fri, 12 Feb 2010 09:11:38 -0800 (PST) Subject: Generic spreadsheet interface References: <3acdf3a7-e2eb-4a9a-bc89-7e285073a9c9@o28g2000yqh.googlegroups.com> Message-ID: <34982944-fa6a-45e9-86a1-4b09a5a39d6e@z19g2000yqk.googlegroups.com> Hi Bro, I don't know of anything like that. The spreadsheet sites I do know of are application-specific. http://www.python-excel.org/ http://wiki.services.openoffice.org/wiki/Python http://lucasmanual.com/mywiki/OpenOffice Note that the OO.o bindings for Python are only for Python 2.3 which is a little archaic, but it's the version I started with and should be more than good enough for spreadsheet work. A port to 2.5 is well underway. You'd probably need to write your own application-specific wrapper modules with a common API and then use those, but it's probably not as much work as it sounds and could be developed incrementaly. Alternatively you just write your code against one spreadsheet module, and then write a wrapper module for the other spreadsheet API so it looks the same. Simon Hibbs From davea at ieee.org Fri Feb 12 12:14:26 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 12 Feb 2010 12:14:26 -0500 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: <4B758C72.7020901@ieee.org> hjebbers wrote: > On Feb 12, 2:06 pm, Dave Angel wrote: > >> hjebbers wrote: >> >>> On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: >>> >>>> In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >>>> >>>> hjebbers wrote: >>>> >>>>> the error is a windows thing, I can make a screenshot of it, but I can >>>>> not copy/paste text. >>>>> >>>> In that case, you need to -- very carefully -- make sure you transcribe >>>> exactly the message that you see on the screen. >>>> -- >>>> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >>>> >>>> "At Resolver we've found it useful to short-circuit any doubt and just >>>> refer to comments in code as 'lies'. :-)" >>>> >>> The message on the screen is (I typed it over): >>> >>> >>> >> You shouldn't ever have to retype the message. Just paste from the DOS >> box (or "Command Prompt"). It's easy using QuickEdit mode. >> >> You select a rectangle of the text by selecting with the mouse, then >> using right-click to put it in the clipboard. >> >> If that doesn't work, you haven't yet enabled QuickEdit mode. Use >> right-click on the DOS box's title bar. Choose Properties. Select the >> first tab, which is Options. >> >> You should then see a selection box called "Quick Edit Mode". Turn it >> on, and you won't have this problem again. >> >> DaveA >> > > Hi Dave, > > thanks. > but the message is not in the DOS box (or "Command Prompt"). > I do run the program in a DOS box (or "Command Prompt"), but the error > is a windows dialog box. > I can not select in this dialog box. > > kind regards, > henk-jan > > Whoops! I agree those dialog boxes that don't support select/copy are a pain. Sorry my response wasn't applicable. DaveA From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 12:14:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 17:14:57 GMT Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> Message-ID: <038578a2$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 06:45:31 -0800, Jeremy wrote: > You also confirmed what I thought was true that all variables are passed > "by reference" so I don't need to worry about the data being copied > (unless I do that explicitly). No, but yes. No, variables are not passed by reference, but yes, you don't have to worry about them being copied. You have probably been mislead into thinking that there are only two calling conventions possible, "pass by value" and "pass by reference". That is incorrect. There are many different calling conventions, and different groups use the same names to mean radically different things. If a language passes variables by reference, you can write a "swap" function like this: def swap(a, b): a, b = b, a x = 1 y = 2 swap(x, y) assert (x == 2) and (y==1) But this does not work in Python, and cannot work without trickery. So Python absolutely is not "pass by reference". On the other hand, if a variable is passed by value, then a copy is made and you can do this: def append1(alist): alist.append(1) # modify the copy return alist x = [] newlist = append1(x) assert x == [] # The old value still exists. But this also doesn't work in Python! So Python isn't "pass by value" either. What Python does is called "pass by sharing", or sometimes "pass by object reference". It is exactly the same as what (e.g.) Ruby and Java do, except that confusingly the Ruby people call it "pass by reference" and the Java people call it "pass by value", thus guaranteeing the maximum amount of confusion possible. More here: http://effbot.org/zone/call-by-object.htm http://en.wikipedia.org/wiki/Evaluation_strategy -- Steven From torriem at gmail.com Fri Feb 12 12:18:23 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 12 Feb 2010 10:18:23 -0700 Subject: looking for some libraries In-Reply-To: <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> Message-ID: <4B758D5F.6000907@gmail.com> rantingrick wrote: > Well a GUI kit comes to mind. And since you did not mention a > preference (or much really) i would suggest Tkinter in the stdlib as a > starting point. Here is a big hint! I think the original poster is looking for a way to automate an existing GUI process, and screen-scrape the resulting output from this existing GUI. He does not say what OS he is working on, so it's hard to really suggest anything. If he's on Windows, I'd give a look at AutoIt[1], which has its own complete programming language. I know with AutoIt I could click on buttons and then scrape text from an edit box. AutoIt probably has the ability to write this data out to a file as well. Not Python, but hey. [1] http://www.autoitscript.com/autoit3/index.shtml From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 12:20:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 17:20:06 GMT Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: <038579d7$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 15:14:07 +0100, Christian Heimes wrote: > Lloyd Zusman wrote: >> .... The -T and -B switches work as follows. The first block or so >> .... of the file is examined for odd characters such as strange control >> .... codes or characters with the high bit set. If too many strange >> .... characters (>30%) are found, it's a -B file; otherwise it's a -T >> .... file. Also, any file containing null in the first block is .... >> considered a binary file. [ ... ] > > That's a butt ugly heuristic that will lead to lots of false positives > if your text happens to be UTF-16 encoded or non-english text UTF-8 > encoded. And a hell of a lot of false negatives if the file is binary. The way I've always seen it, a file is binary if it contains a single binary character *anywhere* in the file. -- Steven From hjebbers at gmail.com Fri Feb 12 12:21:07 2010 From: hjebbers at gmail.com (hjebbers) Date: Fri, 12 Feb 2010 09:21:07 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> Message-ID: <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> On Feb 12, 3:17?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: > >> hjebbers wrote: > >> > On Feb 11, 5:45 pm, M3RT wrote: > >> >> The problem may be related to how you treat the EDI file or lets say > >> >> DATA. Also your coding style is important. Can you provide more info? > > >> > Yes, a whole lot more; but I do not want to bother you with that now. > >> > I was just wondering if it is possible that the same setup gives a > >> > CRASH! on windows and just works on linux. > >> > (where is the bug?) > > >> In the platform-specific code ;) > > >> Even on alt.haruspicy they cannot do much without a liver now and then... > > > if it is in the platform-specific code should I make this into a > > bugreport? > > A this stage a bug report would be useless. The details you have provided so > far don't give anyone without physical access to your machine a chance to > reproduce the error. > > > (because the crash does not appear at the same place in my code (when > > doing the same test-run) it will be quite hard to point down....) > > Indeed. The culprit may be an extension written in C that is overwriting > memory still in use by other parts of your program. > > Peter No C extensions used. Definitely not. As these crashes occur during stress tests, I go to the limits of the memory available. What strikes me is: 1. the crash on windows, but linux works OK (same test sets) 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as much). kind regards, Henk-jan From jcquevedo84 at gmail.com Fri Feb 12 12:34:33 2010 From: jcquevedo84 at gmail.com (Juan Carlos Rodriguez) Date: Fri, 12 Feb 2010 13:34:33 -0400 Subject: Helpp I want view page .py on apache WHAT CAN I DO??????????????? Message-ID: Dear all, I am trying implement a text from mod_python. I have a apahce service 2.2.4, python 2.5 and mod_python 3.3.1 I have this mistake: MOD_PYTHON ERROR ProcessId: 5956 Interpreter: '192.168.5.32' ServerName: '192.168.5.32' DocumentRoot: 'D:/aplicaciones/web' URI: '/python/index.py' Location: None Directory: 'D:/aplicaciones/web/python/' Filename: 'D:/aplicaciones/web/python/index.py' PathInfo: '' Phase: 'PythonHandler' Handler: 'mptest' Traceback (most recent call last): File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1202, in _process_target module = import_module(module_name, path=path) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named mptest *WHAT CAN I DO?* -------------- next part -------------- An HTML attachment was scrubbed... URL: From chyavana at gmail.com Fri Feb 12 12:45:35 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Sat, 13 Feb 2010 01:45:35 +0800 Subject: Sorting a list of lists Message-ID: <4B7593BF.1030708@gmail.com> Dear Folks, I have lines of values like so: 14, [25, 105, 104] 10, [107, 106, 162] 21, [26, 116, 165] I need to sort them in two ways: (a) By the numeric value of the first column; and (b) by the sum of the elements of the second item in each list, which is a list in itself. At present, I have appended each line into a list L so that I for teh above minimal data, I have a list of lists thus: [[14, [25, 105, 104]], [10, [107, 106, 162]], [21, [26, 116, 165]]] I have tried using (a) sorted(L, key = lambda x:(x[0])) and (b) sorted(L, key = lambda x:(sum(x[1]))) and get the anticipated results for (a) and (b0, at least with the above minimal data set. Is this a sensible way to go about the sorting, or are there better ways of doing it in Python? Also, I am baffled because the above fails obviously when len(L) is about a hundred and I can't figure out why. TIA Chandra From jpiitula at ling.helsinki.fi Fri Feb 12 12:48:33 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 12 Feb 2010 19:48:33 +0200 Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Terry Reedy writes: > On 2/12/2010 4:40 AM, Jussi Piitulainen wrote: > > Terry Reedy writes: > >> On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > >>> Robert Kern writes: > >>>> On 2010-02-11 06:31 AM, Shashwat Anand wrote: > >>>>> There is a little issue here that '>>> -.1 ** .1' should give you > >>>>> error message. That is it. > >>>> > >>>> No, fractional powers of negative numbers are perfectly valid > >>>> mathematically. The result is a complex number. In Python 3 (what > >>>> the OP is using), this has been implemented, but not in Python 2.6. > >>> > >>> Perhaps it should raise a MisleadingSpacingError at compile time. > >> > >> You forgot the smiley ;-). > >> > >> > The error message could recommend - .1**.1, or better -(.1 ** .1). > >> > >> The compiler would never see the difference between -.1 ** .1 and the > >> first and probably no difference with the second either. > > > > It could be done the same way that the compiler keeps track of the > > source line numbers now: early phases annotate their output with any > > information that later phases may need. This error would be detected > > during syntactic analysis. > > There is no error to detect. Sorry, read the manual and either learn > or lookup precedence rules (there is a table in the end of the > Expressions chapter) or use parentheses when not sure. Thanks. From cgoldberg at gmail.com Fri Feb 12 13:18:27 2010 From: cgoldberg at gmail.com (corey goldberg) Date: Fri, 12 Feb 2010 10:18:27 -0800 (PST) Subject: PExpect Cross-Platform Alternative References: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Message-ID: <31a6439e-3832-48c8-b956-3b421b6f5e12@z39g2000vbb.googlegroups.com> > > I was just tasked to get > > these scripts running in a windows environment and to my dismay very > > quickly realized that pexpect is not cross platform compatible. > > Am I stuck, or are there solutions out there? I haven't tried it, but here is another Python implementation of Expect that claims to run on Windows also: http://code.google.com/p/python-expect/ -Corey From python at mrabarnett.plus.com Fri Feb 12 13:24:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 18:24:17 +0000 Subject: Sorting a list of lists In-Reply-To: <4B7593BF.1030708@gmail.com> References: <4B7593BF.1030708@gmail.com> Message-ID: <4B759CD1.4040402@mrabarnett.plus.com> R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I have lines of values like so: > > 14, [25, 105, 104] > 10, [107, 106, 162] > 21, [26, 116, 165] > > I need to sort them in two ways: > > (a) By the numeric value of the first column; and > > (b) by the sum of the elements of the second item in each list, which is > a list in itself. > > At present, I have appended each line into a list L so that I for teh > above minimal data, I have a list of lists thus: > > [[14, [25, 105, 104]], [10, [107, 106, 162]], [21, [26, 116, 165]]] > > I have tried using > > (a) sorted(L, key = lambda x:(x[0])) > > and > > (b) sorted(L, key = lambda x:(sum(x[1]))) > > and get the anticipated results for (a) and (b0, at least with the above > minimal data set. > > Is this a sensible way to go about the sorting, or are there better ways > of doing it in Python? > It's the obvious way to do it. > Also, I am baffled because the above fails obviously when len(L) is > about a hundred and I can't figure out why. > You'd have to post an example of that, but you could try deleting some of the entries before sorting so see whether you can still reproduce the problem with a smaller list. From sparks.m at gmail.com Fri Feb 12 13:32:23 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Fri, 12 Feb 2010 10:32:23 -0800 (PST) Subject: Modifying Class Object References: Message-ID: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Hi Alf, Before I start, note we're talking about semantics, not implementation. That distinction is very important. On Feb 11, 4:49 am, "Alf P. Steinbach" wrote: > > *The* standard general language independent definition? [ of pointer ] > Yes. > > > As defined where? > > For example, as I used as reference in my first posting, the Java language spec. > But it has nothing specifically to do with Java. It is a basic concept in > computer science, that (most) CS students learn in their *first year*. > > E.g. > > > A pointer stores a reference to something. Unfortunately there is no fixed term > for the thing that the pointer points to, and across different computer > languages there is a wide variety of things that pointers point to. We use the > term pointee for the thing that the pointer points to, and we stick to the basic > properties of the pointer/pointee relationship which are true in all languages. > The term "reference" means pretty much the same thing as "pointer" -- > "reference" implies a more high-level discussion, while "pointer" implies the > traditional compiled language implementation of pointers as addresses. For the > basic pointer/pointee rules covered here, the terms are effectively equivalent. > This is where you have gone wrong. You have taken a first year undergraduate academic generalisation and assumed that it applies to The World. In theory, there is no difference between practice and theory, but in practice there is (so the saying goes). The World however has another place for defining terms. That place is of highly varying quality, but generally a better place to correct semantics of terms. Who knows, eventually there may be a single commonly accepted viewpoint. (Which would bring a whole new level of pedantry of course )-: I am referring to Wikipedia here. (this is a vague attempt at humour, rather than an attempt to patronise which it may also come over as) Let's look at the tip of the iceberg for that: "In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address." http://en.wikipedia.org/wiki/Pointer_%28computing%29 Similarly for Call by Value: (which *is* a loaded term) In call-by-value, the argument expression is evaluated, and the resulting value is bound to the corresponding variable in the function (frequently by copying the value into a new memory region). If the function or procedure is able to assign values to its parameters, only its local copy is assigned ? that is, anything passed into a function call is unchanged in the caller's scope when the function returns. http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value Call by Reference: (again, loaded term): In call-by-reference evaluation (also referred to as pass-by- reference), a function receives an implicit reference to the argument, rather than a copy of its value. This typically means that the function can modify the argument- something that will be seen by its caller. http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference Call by Sharing: (far less common term) Also known as "call by object" or "call by object-sharing" is an evaluation strategy first named by Barbara Liskov et al. for the language CLU in 1974[1]. It is used by languages such as Python[2], Iota, Java (for object references)[3], Ruby, Scheme, OCaml, AppleScript, and many other languages. The semantics of call-by-sharing differ from call-by-reference in that assignments to function arguments within the function aren't visible to the caller (unlike by-reference semantics). http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing As you can see, there are generally accepted terms and definitions here, and python is accepted as falling not into the value or reference camp, along with some other languages. Understanding why IMO comes back to some basic aspects of python which I believe trip up experienced developers. This claim is based on talking to someone experienced in coding for a couple of decades, who has done a CS degree (like me), and just didn't understand why I would use python. I spent an couple of _days_ explaining this, along with python's evaluation model, and at the end we ended up where we started: * Python is a language which is focussed on programmer performance, not machine performance, because relative to programmer cost, machines are cheap. Therefore you focus your language to optimise for the programmer, not the machine. In this case, let's drop back to the word "pointer" which I can understand that you like. Indeed, it took me a fair while to let go of the word when talking about python, but you do have to. Why? Well, assume this definition isn't bad: "In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address." OK, let's assume that we can generalise this to ignore the address bit, like so: "In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory" That's still not valid for python - why? Let's keep trimming it back: "A pointer is a programming language data type whose value refers directly to another value" Seems OK. But not valid for python. Why? Let's keep going. "A pointer is a data type whose value" Ah, maybe that is the reason. Let's look at the canonical kind of way of describing what's happening here: >>> x = [1,2,3] >>> def hello(world): ... print world ... >>> hello(x) [1, 2, 3] This is actually alot more complicated to explain than it might seem if someone starts thinking "what's going on underneath". Let's take the description you'd give to a beginner first. (OK, depends on beginner) Beginner description -------------------- A list object is created and initialised containing 3 integers -1,2 & 3. The name x is bound to this list object. Next a function - hello - is defined which takes one argument. When called, the name world is bound to the object passed in. The function body then runs and the object bound to world is used by print to print whatever str(world) returns. The function hello is then called with the value bound to the name x. OK, that seems pretty simple and clear. Little odd in the terminology perhaps, but it's clear. We deal with names and objects. The less beginner explanation ----------------------------- >>> x = [1,2,3] 3 anonymous integer objects are created with the values 1,2 and 3. These are bound inside a sequence which when iterated over yields the 3 integer objects. list is then called with this sequence object (of whatever kind it is under the hood). A list object is then created such that: x[0] appears bound to the integer object 1 x[1] appears bound to the integer object 2 x[2] appears bound to the integer object 3 Note I do NOT say that x[0] contains a reference to object 1, because in languages that contain references you would: a) have access to the reference b) have a means of dereferencing the reference c) Have to dereference the reference in order to obtain the value. This is because a reference is a form of l-value and r-value. It is a value in itself, and refers to a value. Python does not have such a beast. (The closest you can get is a class property, but I digress) In python, the language, we do not have a) or b) nor have to do c). (indeed cannot do "c") Why do I say "appears bound" ? Because x[0] is syntactic sugar to a function call - x.__getitem__(0) So... This results in a list object being created allowing access to 3 integer objects. The name "x" is bound to this list object. >>> def hello(world): ... print world ... This statement (not definition) creates a function object which accepts one argument which will be and object labelled "world" inside the scope of the function. The resulting function object is bound to the name "hello" in the same scope as "x". The resulting function object also has a bunch of other attributes, which I won't go into. >>> hello(x) [1, 2, 3] This is quite complex if you go down this layer. hello is a name bound to the function object we created earlier. Python effectivelly does this: >>> getattr(hello, "__call__") And uses that as the method to call with the arguments provided. Specifically, the object that x is bound to is passed as the sole argument to the __call__ method (wrapper) that getattr(hello, "__call__") returned. The object, not a reference. The object, not a pointer. This is because python's semantics are designed for humans not machines. When applying the object we humans call x to the function object we humans call hello ... >>> def hello(world): ... print world ...inside the scope of the function object, the name world is bound to the object that the calling scope calls x. This may be *implemented* in one runtime using references in one language. It may be *implemented* in another runtime using pointers in another. In PyPy the implementation will be to pass the object by sharing. (I suspect, I've not looked at PyPy's internal's but that's what I'd expect) Anyhow, by hook or by crook, inside hello, the name world is now bound to our previously created list object, which itself has made it such that we can retrieve the 3 integers we asked it to. The print statement evaluates str(world), which evaluates world.__str__(), and passes the resulting string object to the subsystem that actually spits characters out of stdout. That's a significantly more complicated explanation, but still does not need or use the terms pointers or references. The object itself is passed as the argument. The fact that an object may have many names is by the by. Now, you may be asking yourself (indeed I'm certain you may be) "But how is that any difference, really, from pointers and references". Indeed it will seem odd to hear clearly well educated people arguing against you saying "no, they're not pointers or references". It seems odd, primarily because in languages where you have pointers and references, pointers and references are in themselves values. Specifically, in such languages you start talking about l-values and r-values. An r-value is a value that may be assigned to an l-value. An l-value essentially thus denotes storage - a destination for an r-value. An l-values is a machine oriented concept. A name is a human oriented concept. Python doesn't have l-values. It has names, and r-values. A name is just a name, and has no value. When the name is used syntactically, the value (object) it is bound to is used in its place. Thus using your example "demonstrating" that references exist in python is something you're not yourself understanding correctly. Rather than thinking of names as boxes which can contain values, think of them as labels (post it notes) that can be stuck onto values/objects. If you do this, it will simplify your thinking. This was your wording: s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. This is mine: s = ["A"] A list object is created such that the string object "A" can be retrieved from it. The label "s" is stuck on the object. t = s Sticks the label "t" onto the object as well. t[0] = "B" Applies the __setitem__ method of the list object we've created with the integer object 0 and string object "B". (What this does is anyone's guess really, someone could have changed the implementation of list before these 4 lines were executed) print( s ) print takes the list object which s is stuck onto. It then calls the __str__ method of the list object passed it, gets back a string object and spits that out stdout. Whether we chose to use the label s or t is irrelevant, the object _itself_ is passed in. (in terms of semantics) Again, note, we're talking about semantics, not implementation. That distinction is very important. Once again, you might say, "but my explanation works well with references and pointers", and yes in terms of implementation, those things will exist. But if you confuse the implementation as the semantics, you run into problems. For example, going back to your (incorrect) explanation: s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. If t or s are references or pointers, I should be able to deal with the reference or pointer itself as a value. After all accepted definitions of pointer boil down to: "A pointer is a programming language data type whose value refers directly to another value" And similarly for references: "Generally, a reference is a value that enables a program to directly access the particular data item." http://en.wikipedia.org/wiki/Reference#Computer_science ie both pointers and references are themselves values that enable access to the value AND are NOT in themselves the value they point/refer to. In python, if I do this: def hello(world): print world X = [1,2,3] hello(X) Then "X" is best described as a name bound to the object [1,2,3] hello(X) is best described as calling the function bound to the name "hello" with a single argument being the object that the name "X" is bound to. Inside hello, "world" is a name that is bound to whatever object gets slung inside as its first argument. Not a pointer. Not a reference. The object. This semantics is radically different from languages like C, Pascal, and similar. One final approach. Suppose I do this: a = (1,2,3) b = (4,5,6) c = (7,8,9) d = [a, b, c] And I claim that a, b and c are references. (as per your explanation) This would mean that d[2] must also be the same reference as c. (if you take d[2] to be a reference - which it isn't) Therefore updating d[2] must update c. That could imply that d[2] += (10,) Should result in c's reference referring to the value (7,8,9,10) And with D having the value [ (1,2,3), (4,5,6), (7,8,9,10) ] This is perfectly logical semantics if you're dealing with references and pointers. However, python doesn't deal with them. It deals with objects and names. D does indeed result with that value, but c is left unchanged. The reason is because python only has r-values and names, and no l-values. d[2] += (10,) Results in d[2] being evaluated - that is the __getitem__ method on the object d is bound to is called with the argument 2. This returns the tuple object (7,8,9). The __add__ method of that tuple object is then called, with the argument (10,) This returns a new tuple object (7,8,9,10) Finalled the __setitem__ method of the object d is bound to is called with the argument 2 and the freshly minted tuple object (7,8,9,10). This results in c being left unchanged. This results in D having the correct value. If we were dealing with references and pointers it would be perfectly acceptable for c to be modified. In python, the label "c" cannot be tacked onto the returned value. Crucially, a pointer can be a pointer to a pointer, and you can have references to references (which allows you to dereference the pointer/reference and change the pointer/ reference). You can't do this in python names directly. (You can come close using properties, and by messing around in globals and locals, but that's getting quite nasty, and not really the same semantics.) Anyway, I hope you've not found that patronising or ad-hominem. If you've found my explanation overly simplistic or using too simple phrasing, please excuse that - it's a style of writing I've picked up on a writing course once. In summary, if you claim that there's references or pointers here... s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. ... since references and pointers are values themselves, not the values they refer to, how can I store a reference to a reference? That is update the value of s from a function? Specifically, if python has pointers or references, this should be doable: s = 1 # Claim is that s is a reference to 1 update(s, 2) # Update the reference s to point at the value 2 How do I write the function "update" used above in pure python. (without messing with globals(), locals(), or diving into any other language implementation specific concepts) After all, I can write that in any other language that has pointers & references. Finally, note, we're talking about semantics, not implementation. That distinction is very important. If this seems odd, the reason is because python's semantics are very much more like those of a functional language when it comes to function calls, than it is to standard imperative languages. Python's functions are all impure however, and side effects are common, due to objects not (all) being immutable. Your experience here is leading you to the wrong conclusions and incorrect reasoning. Regards, Michael -- http://www.kamaelia.org/ From jjposner at optimum.net Fri Feb 12 13:32:49 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 12 Feb 2010 13:32:49 -0500 Subject: Sorting a list of lists In-Reply-To: <4B7593BF.1030708@gmail.com> References: <4B7593BF.1030708@gmail.com> Message-ID: <4B759ED1.3090507@optimum.net> On 2/12/2010 12:45 PM, R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I have lines of values like so: > > 14, [25, 105, 104] > 10, [107, 106, 162] > 21, [26, 116, 165] > > I need to sort them in two ways: > > (a) By the numeric value of the first column; and > > (b) by the sum of the elements of the second item in each list, which is > a list in itself. > > At present, I have appended each line into a list L so that I for teh > above minimal data, I have a list of lists thus: > > [[14, [25, 105, 104]], [10, [107, 106, 162]], [21, [26, 116, 165]]] > > I have tried using > > (a) sorted(L, key = lambda x:(x[0])) Just plain "sorted(L)" will work, because Python knows how to compare your [N, [N,N,N]]-format values: >>> [14, [25, 105, 104]] < (14, [25, 105, 103]] False >>> [14, [25, 105, 104]] < (14, [25, 105, 105]] True >>> > > and > > (b) sorted(L, key = lambda x:(sum(x[1]))) That looks good. > > and get the anticipated results for (a) and (b0, at least with the above > minimal data set. > > Is this a sensible way to go about the sorting, or are there better ways > of doing it in Python? You're doing fine. > > Also, I am baffled because the above fails obviously when len(L) is > about a hundred and I can't figure out why. Please cut-and-paste the exact error message (or other evidence of "failure") into a message. Tx, John From jjposner at optimum.net Fri Feb 12 13:45:46 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 12 Feb 2010 13:45:46 -0500 Subject: Please help with MemoryError In-Reply-To: <038578a2$0$1277$c3e8da3@news.astraweb.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B75A1DA.5030004@optimum.net> On 2/12/2010 12:14 PM, Steven D'Aprano wrote: > On Fri, 12 Feb 2010 06:45:31 -0800, Jeremy wrote: > >> You also confirmed what I thought was true that all variables are passed >> "by reference" so I don't need to worry about the data being copied >> (unless I do that explicitly). > > No, but yes. > > No, variables are not passed by reference, but yes, you don't have to > worry about them being copied. > > You have probably been mislead into thinking that there are only two > calling conventions possible, "pass by value" and "pass by reference". > That is incorrect. There are many different calling conventions, and > different groups use the same names to mean radically different things. > > If a language passes variables by reference, you can write a "swap" > function like this: > > def swap(a, b): > a, b = b, a > > x = 1 > y = 2 > swap(x, y) > assert (x == 2) and (y==1) > > But this does not work in Python, and cannot work without trickery. So > Python absolutely is not "pass by reference". > > On the other hand, if a variable is passed by value, then a copy is made > and you can do this: > > def append1(alist): > alist.append(1) # modify the copy > return alist > > x = [] > newlist = append1(x) > assert x == [] # The old value still exists. > > But this also doesn't work in Python! So Python isn't "pass by value" > either. > > What Python does is called "pass by sharing", or sometimes "pass by > object reference". It is exactly the same as what (e.g.) Ruby and Java > do, except that confusingly the Ruby people call it "pass by reference" > and the Java people call it "pass by value", thus guaranteeing the > maximum amount of confusion possible. > > > More here: > http://effbot.org/zone/call-by-object.htm > http://en.wikipedia.org/wiki/Evaluation_strategy > Excellent writeup, Steve! You and Jeremy might be interested in a message on "pass-by-XXX" from John Zelle, the author of the textbook "Python Programming: An Introduction to Computer Science". [1] This was part of a long thread in May 2008 on the Python edu-sig list -- nearly as long as "Modifying Class Object", but with nowhere near the fireworks! Tx, John [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html From senhor.abrantes at gmail.com Fri Feb 12 14:12:37 2010 From: senhor.abrantes at gmail.com (joao abrantes) Date: Fri, 12 Feb 2010 19:12:37 +0000 Subject: Pixel control In-Reply-To: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> References: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> Message-ID: <880fa1d41002121112r4e8c1550xf32cdea17a2bfeb@mail.gmail.com> noone knows if it's possible? i really need this.. On Thu, Feb 4, 2010 at 10:57 PM, joao abrantes wrote: > Hello everyone. For example i am using a screen resolution of 800x600 is it > possible to make python control the color of the pixels? For example paint > the pixel (100,200) in red! And it would stay red when i am seeing a > webpage, a movie, playing a game... etc.. Regards, Jo?o Abrantes. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mccolgst at gmail.com Fri Feb 12 14:36:46 2010 From: mccolgst at gmail.com (McColgst) Date: Fri, 12 Feb 2010 11:36:46 -0800 (PST) Subject: search entire drive say c: References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <8d585aae-2764-4d98-9027-b7d3c9f03b94@p23g2000vbl.googlegroups.com> > ? ?ROOT = "c:\\" > ? ?fname = "abc.txt".lower() > ? ?for p, d, f in os.walk(ROOT): > ? ? ?for fn in f: > ? ? ? ?if fn.lower() == fname: > ? ? ? ? ?print os.path.join(p, f) > ? ? ? ? ?# break I think you mean print os.path.join(p,fn) -sean From mdekauwe at gmail.com Fri Feb 12 14:39:18 2010 From: mdekauwe at gmail.com (Martin) Date: Fri, 12 Feb 2010 11:39:18 -0800 (PST) Subject: Replace various regex Message-ID: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Hi, I am trying to come up with a more generic scheme to match and replace a series of regex, which look something like this... 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) Ideally match the pattern to the right of the "!" sign (e.g. lai), I would then like to be able to replace one or all of the corresponding numbers on the line. So far I have a rather unsatisfactory solution, any suggestions would be appreciated... The file read in is an ascii file. f = open(fname, 'r') s = f.read() if CANHT: s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! canht_ft", CANHT, s) where CANHT might be CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' But this involves me passing the entire string. Thanks. Martin From mccolgst at gmail.com Fri Feb 12 14:57:34 2010 From: mccolgst at gmail.com (McColgst) Date: Fri, 12 Feb 2010 11:57:34 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Message-ID: <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> On Feb 12, 2:39?pm, Martin wrote: > Hi, > > I am trying to come up with a more generic scheme to match and replace > a series of regex, which look something like this... > > 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > would then like to be able to replace one or all of the corresponding > numbers on the line. So far I have a rather unsatisfactory solution, > any suggestions would be appreciated... > > The file read in is an ascii file. > > f = open(fname, 'r') > s = f.read() > > if CANHT: > ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > canht_ft", CANHT, s) > > where CANHT might be > > CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > But this involves me passing the entire string. > > Thanks. > > Martin If I understand correctly, there are a couple ways to do it. One is to use .split() and split by the '!' sign, given that you wont have more than one '!' on a line. This will return a list of the words split by the delimiter, in this case being '!', so you should get back (19.01,16.38,0.79,1.26,1.00 , canht_ft(1:npft) ) and you can do whatever replace functions you want using the list. check out split: http://docs.python.org/library/stdtypes.html#str.split Another, is in your regular expression, you can match the first part or second part of the string by specifying where the '!' is, if you want to match the part after the '!' I would do something like r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- date with my regex syntax, but I think you get the idea.) I hope I understood correctly, and I hope that helps. -sean From mrkafk at gmail.com Fri Feb 12 15:07:08 2010 From: mrkafk at gmail.com (mk) Date: Fri, 12 Feb 2010 21:07:08 +0100 Subject: Please help with MemoryError In-Reply-To: <4B75A1DA.5030004@optimum.net> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: John Posner wrote: >> http://effbot.org/zone/call-by-object.htm >> http://en.wikipedia.org/wiki/Evaluation_strategy > [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html Hmm how about "call by label-value"? That is, you change labels by assignment, but pass the value of the label to a function. Since label value is passed, original label is not changed (i.e. it's not call by reference). However, an object referenced by label value can be changed in Python, like in classic example of list label passed to a function and then this list being modified in a function. Regards, mk From alfps at start.no Fri Feb 12 15:22:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 21:22:02 +0100 Subject: Modifying Class Object In-Reply-To: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: * Michael Sparks: > Hi Alf, > > > Before I start, note we're talking about semantics, not > implementation. That distinction is very important. Yes. It would seem to readers that posters here do not grasp and are unable to grasp that distinction. However, all those references to implementation aspects, persisting in the face of corrections, have just, IMHO, been consistent attempts at misrepresentation. > On Feb 11, 4:49 am, "Alf P. Steinbach" wrote: >>> *The* standard general language independent definition? > > [ of pointer ] > >> Yes. >> >>> As defined where? >> For example, as I used as reference in my first posting, the Java language spec. >> But it has nothing specifically to do with Java. It is a basic concept in >> computer science, that (most) CS students learn in their *first year*. >> >> E.g. >> >> >> A pointer stores a reference to something. Unfortunately there is no fixed term >> for the thing that the pointer points to, and across different computer >> languages there is a wide variety of things that pointers point to. We use the >> term pointee for the thing that the pointer points to, and we stick to the basic >> properties of the pointer/pointee relationship which are true in all languages. >> The term "reference" means pretty much the same thing as "pointer" -- >> "reference" implies a more high-level discussion, while "pointer" implies the >> traditional compiled language implementation of pointers as addresses. For the >> basic pointer/pointee rules covered here, the terms are effectively equivalent. >> > > This is where you have gone wrong. You have taken a first year > undergraduate > academic generalisation and assumed that it applies to The World.' I'm sorry to disappoint, but no. It was a random Google hit to find a first-year text that perhaps posters here could understand. Not insinuiting anything about their mental prowess or lack thereof, but just something they might understand given a repeatedly demonstrated inability to understand such basics, or even to understand the concept of reference to a definition of a term. Please do consider that my usage of the term "pointer" has always, in this thread, including the first article I posted in this thread, been with explicit reference to the Java language spec's meaning. You may argue that those who wrote that language spec are confused about things or whatever, but that's rather stretching it, wouldn't you say? > In theory, there is no difference between practice and theory, but in practice > there is (so the saying goes). > > The World however has another place for defining terms. That place is > of highly > varying quality, but generally a better place to correct semantics of > terms. > Who knows, eventually there may be a single commonly accepted > viewpoint. (Which > would bring a whole new level of pedantry of course )-: > > I am referring to Wikipedia here. (this is a vague attempt at humour, > rather > than an attempt to patronise which it may also come over as) I understand. You may note that that Wikipedia article refers to an article that I wrote about pointers in C++. So, this must be the most silly "argument by authority" ever offered. I find that amusing and would have included a smiley except that I think that that would incur further flames. It's no criticism of you; I do appreciate your effort, thanks. And I reiterate that the meaning of "pointer" I have used is the meaning in the Java language spec. And that that's about semantics, not about implementation, and not about C pointers or Pascal pointers or whatever else that some would rather wish it was. [snip] In the following that I snipped you had good discussion except for (as I could see) a fallacy-based denial of references existing in Python. I don't think there's any point in discussing that further, because it's evidently a religious matter where rational arguments -- and I've tried a few -- don't reach, in spite of the extreme triviality of the subject matter. Thanks for the effort at non-flaming discussion, it *is* appreciated. Cheers & hth., - Alf From mwilson at the-wire.com Fri Feb 12 15:22:08 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 12 Feb 2010 15:22:08 -0500 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: mk wrote: > John Posner wrote: > >>> http://effbot.org/zone/call-by-object.htm >>> http://en.wikipedia.org/wiki/Evaluation_strategy > >> [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html > > Hmm how about "call by label-value"? Nothing egregiously wrong with it.. maybe it's a bit wordy. It may be an uphill fight getting it accepted into computer science the way Call by value, Call by reference, Call by sharing, and Call by copy-restore have been (). Mel. > > That is, you change labels by assignment, but pass the value of the > label to a function. Since label value is passed, original label is not > changed (i.e. it's not call by reference). > > However, an object referenced by label value can be changed in Python, > like in classic example of list label passed to a function and then this > list being modified in a function. > > Regards, > mk From alfps at start.no Fri Feb 12 15:26:24 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 21:26:24 +0100 Subject: Modifying Class Object In-Reply-To: <4b75235b$0$23469$426a74cc@news.free.fr> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> Message-ID: * Bruno Desthuilliers: > Alf P. Steinbach a ?crit : > (snip) >> This group has an extraordinary high level of flaming and personal >> attacks > > Oh my... > > (snip remaining non-sense) > > Mr Steinbach, I bet you'll count this as another "flaming" and "personal > attack", but nonetheless : you might have happier time if you were able > to understand the distinction between disagreement and "personal attack". > > (now back to more interesting readings) Yes, I do count this as a personal attack and flaming. The litmus test for that is that it says something very negative about the person you're debating with. In addition, your statement about the earlier attacks on me, is untrue, and your implication that it's only about attacks on me, is untrue. Both of which are very misleading, by the way. I'm assuming that you're intentionally lying. Cheers & hth., - Alf From mdekauwe at gmail.com Fri Feb 12 15:28:48 2010 From: mdekauwe at gmail.com (Martin) Date: Fri, 12 Feb 2010 12:28:48 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> Message-ID: On Feb 12, 7:57?pm, McColgst wrote: > On Feb 12, 2:39?pm, Martin wrote: > > > > > > > Hi, > > > I am trying to come up with a more generic scheme to match and replace > > a series of regex, which look something like this... > > > 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > > 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > > would then like to be able to replace one or all of the corresponding > > numbers on the line. So far I have a rather unsatisfactory solution, > > any suggestions would be appreciated... > > > The file read in is an ascii file. > > > f = open(fname, 'r') > > s = f.read() > > > if CANHT: > > ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > > canht_ft", CANHT, s) > > > where CANHT might be > > > CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > > But this involves me passing the entire string. > > > Thanks. > > > Martin > > If I understand correctly, there are a couple ways to do it. > One is to use .split() and split by the '!' sign, given that you wont > have more than one '!' on a line. This will return a list of the words > split by the delimiter, in this case being '!', so you should get back > (19.01,16.38,0.79,1.26,1.00 ?, ?canht_ft(1:npft) ) ?and you can do > whatever replace functions you want using the list. > > check out split:http://docs.python.org/library/stdtypes.html#str.split > > Another, is in your regular expression, you can match the first part > or second part of the string by specifying where the '!' is, > if you want to match the part after the '!' I would do something like > r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- > date with my regex syntax, but I think you get the idea.) > > I hope I understood correctly, and I hope that helps. > > -sean Hi I like the second suggestion, so this wouldn't rely on me having to match the numbers only the string canht for example but still allow me to replace the whole line, is that what you mean? I tried it and the expression seemed to replace the entire file, so perhaps i am doing something wrong. But in principle I think that might be a better scheme than my current one. i tried if CANHT: #s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! canht_ft", CANHT, s) s = re.sub(r"[^! canht_ft]", CANHT, s) From python at mrabarnett.plus.com Fri Feb 12 15:30:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 20:30:29 +0000 Subject: Replace various regex In-Reply-To: <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> Message-ID: <4B75BA65.8000107@mrabarnett.plus.com> McColgst wrote: > On Feb 12, 2:39 pm, Martin wrote: >> Hi, >> >> I am trying to come up with a more generic scheme to match and replace >> a series of regex, which look something like this... >> >> 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) >> 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) >> >> Ideally match the pattern to the right of the "!" sign (e.g. lai), I >> would then like to be able to replace one or all of the corresponding >> numbers on the line. So far I have a rather unsatisfactory solution, >> any suggestions would be appreciated... >> >> The file read in is an ascii file. >> >> f = open(fname, 'r') >> s = f.read() >> >> if CANHT: >> s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! >> canht_ft", CANHT, s) >> >> where CANHT might be >> >> CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' >> >> But this involves me passing the entire string. >> >> Thanks. >> >> Martin > > If I understand correctly, there are a couple ways to do it. > One is to use .split() and split by the '!' sign, given that you wont > have more than one '!' on a line. This will return a list of the words > split by the delimiter, in this case being '!', so you should get back > (19.01,16.38,0.79,1.26,1.00 , canht_ft(1:npft) ) and you can do > whatever replace functions you want using the list. > > check out split: http://docs.python.org/library/stdtypes.html#str.split > The .split method is the best way if you process the file a line at a time. The .split method, incidentally, accepts a maxcount argument so that you can split a line no more than once. > Another, is in your regular expression, you can match the first part > or second part of the string by specifying where the '!' is, > if you want to match the part after the '!' I would do something like > r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- > date with my regex syntax, but I think you get the idea.) > The regex would be r"(?m)^[^!]*(!.*)" to capture the '!' and the rest of the line. > I hope I understood correctly, and I hope that helps. > From subhakolkata1234 at gmail.com Fri Feb 12 15:32:29 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 12 Feb 2010 12:32:29 -0800 (PST) Subject: A silly question on file opening References: Message-ID: <085eb96f-9023-4ef3-af29-95749f62e311@s36g2000prh.googlegroups.com> On Feb 11, 1:57?am, Anthony Tolle wrote: > On Feb 10, 3:42?pm,joy99 wrote: > > > Dear Group, > > [snip] > > I tried to change the location to D:\file and as I saw in Python Docs > > the file reading option is now "r+" so I changed the statement to > > ? ?file_open=open("D:\file","r+") > > but it is still giving error. > > Only use "r+" if you need to also write to the file. ?"r" is still > good for opening for reading. > > Without seeing a traceback, I can only assume the error is caused by > using a backslash in the path without escaping it. ?Try either the > following: > > file_open=open("D:\\file","r+") > > file_open=open(r"D:\file","r+") > > For an explanation, see the Python documentation: > > http://docs.python.org/reference/lexical_analysis.html#string-literals Dear Group, I am sorry I could not report. I was trying your solutions, I could try only one or two, they are working. My problem got solved. Thank you for your suggestions. But soon I find time, I would try all of them, so that I can learn more and what I try to do in this room to get better angles over any problem from experts like you. Thank you for giving me your valuable time despite your busy schedule. Wishing you happy day ahead, Best Regards, Subhabrata. From ethan at stoneleaf.us Fri Feb 12 15:33:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 12 Feb 2010 12:33:28 -0800 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: <4B75BB18.7010904@stoneleaf.us> mk wrote: > John Posner wrote: > >>> http://effbot.org/zone/call-by-object.htm >>> http://en.wikipedia.org/wiki/Evaluation_strategy > >> [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html > > Hmm how about "call by label-value"? > > That is, you change labels by assignment, but pass the value of the > label to a function. Since label value is passed, original label is not > changed (i.e. it's not call by reference). > > However, an object referenced by label value can be changed in Python, > like in classic example of list label passed to a function and then this > list being modified in a function. > > Regards, > mk > Because "value" and "reference" are already well defined terms with very definite meanings, I think using them in any way to describe Python's model will lead to confusion. Seems to me that "call by object", a term coined decades ago, and that accurately defines the way that Python (the language) actually does it, should be the term used. My $0.02. ~Ethan~ From ben+python at benfinney.id.au Fri Feb 12 15:41:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Feb 2010 07:41:40 +1100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: <87ocjufapn.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > In article , > Lloyd Zusman wrote: > >if (-T $filename) { print "file contains 'text' characters\n"; } > >if (-B $filename) { print "file contains 'binary' characters\n"; } > > Assuming you're on a Unix-like system or can install Cygwin, the > standard response is to use the "file" command. It's *much* more > sophisticated. Indeed, the ?file? command is an expected (though not standard) part of most Unix systems, and its use frees us from the lies of filenames about their contents. The sophistication comes from an extensive database of heuristics ? filesystem attributes, ?magic? content signatures, and parsing ? that are together known as the ?magic database?. This database is maintained along with the ?file? program, and made accessible through a C library from the same code base called ?magic?. So, you don't actually need to use the ?file? command to access this sophistication. Just about every program on a GNU system that wants to display file types, such as the graphical file manager, will query the ?magic? library directly to get the file type. The ?file? code base has for a while now also included a Python interface to this library, importable as the module name ?magic?. Unfortunately it isn't registered at PyPI as far as I can tell. (There are several project using the name ?magic? that implement something similar, but they are nowhere near as sophisticated.) On a Debian GNU/Linux system, you can install the ?python-magic? package to get this installed. Otherwise, you can build it from the ?file? code base . -- \ ?I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.? ?Douglas Adams | Ben Finney From jcquevedo84 at gmail.com Fri Feb 12 15:46:19 2010 From: jcquevedo84 at gmail.com (Juan Carlos Rodriguez) Date: Fri, 12 Feb 2010 08:46:19 -1200 Subject: ImportError: No module named mptest Message-ID: Dear all, I am trying implement a text from mod_python. I have a apahce service 2.2.4, python 2.5 and mod_python 3.3.1 I have this mistake: MOD_PYTHON ERROR ProcessId: 5956 Interpreter: '192.168.5.32' ServerName: '192.168.5.32' DocumentRoot: 'D:/aplicaciones/web' URI: '/python/index.py' Location: None Directory: 'D:/aplicaciones/web/python/' Filename: 'D:/aplicaciones/web/python/index.py' PathInfo: '' Phase: 'PythonHandler' Handler: 'mptest' Traceback (most recent call last): File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1202, in _process_target module = import_module(module_name, path=path) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named mptest *WHAT CAN I DO?* -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Fri Feb 12 15:59:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 21:59:32 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: mk wrote: > Hmm how about "call by label-value"? Or "call by guido"? How do you like "call like a dutch"? :] From mdekauwe at gmail.com Fri Feb 12 16:02:40 2010 From: mdekauwe at gmail.com (Martin) Date: Fri, 12 Feb 2010 13:02:40 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> Message-ID: On Feb 12, 8:30?pm, MRAB wrote: > McColgst wrote: > > On Feb 12, 2:39 pm, Martin wrote: > >> Hi, > > >> I am trying to come up with a more generic scheme to match and replace > >> a series of regex, which look something like this... > > >> 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > >> 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > >> Ideally match the pattern to the right of the "!" sign (e.g. lai), I > >> would then like to be able to replace one or all of the corresponding > >> numbers on the line. So far I have a rather unsatisfactory solution, > >> any suggestions would be appreciated... > > >> The file read in is an ascii file. > > >> f = open(fname, 'r') > >> s = f.read() > > >> if CANHT: > >> ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > >> canht_ft", CANHT, s) > > >> where CANHT might be > > >> CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > >> But this involves me passing the entire string. > > >> Thanks. > > >> Martin > > > If I understand correctly, there are a couple ways to do it. > > One is to use .split() and split by the '!' sign, given that you wont > > have more than one '!' on a line. This will return a list of the words > > split by the delimiter, in this case being '!', so you should get back > > (19.01,16.38,0.79,1.26,1.00 ?, ?canht_ft(1:npft) ) ?and you can do > > whatever replace functions you want using the list. > > > check out split:http://docs.python.org/library/stdtypes.html#str.split > > The .split method is the best way if you process the file a line at a > time. The .split method, incidentally, accepts a maxcount argument so > that you can split a line no more than once. > > > Another, is in your regular expression, you can match the first part > > or second part of the string by specifying where the '!' is, > > if you want to match the part after the '!' I would do something like > > r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- > > date with my regex syntax, but I think you get the idea.) > > The regex would be r"(?m)^[^!]*(!.*)" to capture the '!' and the rest of > the line. > > > > > I hope I understood correctly, and I hope that helps. I guess I could read the file a line at a time and try splitting it, though I though it would be better to read it all once then search for the various regex I need to match and replace? I am not sure that regex helps, as that would match and replace every line which had a "!". Perhaps if i explain more thoroughly? So the input file looks something like this... 9*0.0 ! canopy(1:ntiles) 12.100 ! cs 0.0 ! gs 9*50.0 ! rgrain(1:ntiles) 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) 9*0.46 ! snow_tile(1:ntiles) 0.46 ! snow_grnd 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) 9*276.78 ! tstar_tile(1:ntiles) 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) So for each of the strings following the "!" I may potentially want to match them and replace some of the numbers. That is I might search for the expression snow_grnd with the intention of substituting 0.46 for another number. What i came up with was a way to match all the numbers and pass the replacement string. From alfps at start.no Fri Feb 12 16:03:47 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 22:03:47 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: * Christian Heimes: > mk wrote: >> Hmm how about "call by label-value"? > > Or "call by guido"? How do you like "call like a dutch"? :] Just a note: it might be more clear to talk about "pass by XXX" than "call by XXX". Unless you're talking about something else than argument passing. The standard terminology is in my view fine. Cheers & hth., - Alf From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 16:33:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 21:33:31 GMT Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: <0385b53b$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 21:07:08 +0100, mk wrote: > John Posner wrote: > >>> http://effbot.org/zone/call-by-object.htm >>> http://en.wikipedia.org/wiki/Evaluation_strategy > >> [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html > > Hmm how about "call by label-value"? Python's calling convention already has an well-established name, established over thirty years ago by the distinguished computer scientist Barbara Liskov, namely call-by-sharing. It's also known as "call-by- object-reference". It doesn't need yet another name. -- Steven From solipsis at pitrou.net Fri Feb 12 16:52:34 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 21:52:34 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit?: > > What Python does is called "pass by sharing", or sometimes "pass by > object reference". It is exactly the same as what (e.g.) Ruby and Java > do, except that confusingly the Ruby people call it "pass by reference" > and the Java people call it "pass by value", thus guaranteeing the > maximum amount of confusion possible. Well, I think the Ruby people got it right. Python *does* pass parameters by reference. After all, we even speak about reference counting, reference cycles, etc. So I'm not sure what distinction you're making here. From steve at holdenweb.com Fri Feb 12 17:10:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 17:10:01 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B75D1B9.1050809@holdenweb.com> Antoine Pitrou wrote: > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : >> What Python does is called "pass by sharing", or sometimes "pass by >> object reference". It is exactly the same as what (e.g.) Ruby and Java >> do, except that confusingly the Ruby people call it "pass by reference" >> and the Java people call it "pass by value", thus guaranteeing the >> maximum amount of confusion possible. > > Well, I think the Ruby people got it right. Python *does* pass parameters > by reference. After all, we even speak about reference counting, > reference cycles, etc. > > So I'm not sure what distinction you're making here. > He's distinguishing what Python does from the "call by reference" which has been used since the days of Algol 60. As has already been pointed out, if Python used call by reference then the following code would run without raising an AssertionError: def exchange(a, b): a, b = b, a x = 1 y = 2 exchange(x, y) assert (x == 2 and y == 1) Since function-local assignment always takes place in the function call's local namespace Python does not, and cannot, work like this, and hence the term "call by reference" is inapplicable to Python's semantics. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 12 17:10:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 17:10:01 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B75D1B9.1050809@holdenweb.com> Antoine Pitrou wrote: > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : >> What Python does is called "pass by sharing", or sometimes "pass by >> object reference". It is exactly the same as what (e.g.) Ruby and Java >> do, except that confusingly the Ruby people call it "pass by reference" >> and the Java people call it "pass by value", thus guaranteeing the >> maximum amount of confusion possible. > > Well, I think the Ruby people got it right. Python *does* pass parameters > by reference. After all, we even speak about reference counting, > reference cycles, etc. > > So I'm not sure what distinction you're making here. > He's distinguishing what Python does from the "call by reference" which has been used since the days of Algol 60. As has already been pointed out, if Python used call by reference then the following code would run without raising an AssertionError: def exchange(a, b): a, b = b, a x = 1 y = 2 exchange(x, y) assert (x == 2 and y == 1) Since function-local assignment always takes place in the function call's local namespace Python does not, and cannot, work like this, and hence the term "call by reference" is inapplicable to Python's semantics. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Fri Feb 12 17:12:06 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 23:12:06 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Antoine Pitrou: > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : >> What Python does is called "pass by sharing", or sometimes "pass by >> object reference". It is exactly the same as what (e.g.) Ruby and Java >> do, except that confusingly the Ruby people call it "pass by reference" >> and the Java people call it "pass by value", thus guaranteeing the >> maximum amount of confusion possible. > > Well, I think the Ruby people got it right. Python *does* pass parameters > by reference. After all, we even speak about reference counting, > reference cycles, etc. > > So I'm not sure what distinction you're making here. Steven talks about the standard meaning of "pass by reference". Essentially that means that you can implement a routine "swap" such that a = 1; b = 2; swap( a, b ) results in a == 2 and b == 1. In Pascal that's 'var' parameters, in C there's no such, in C++ it's reference type parameters using '&' as a type builder, in C# it's 'out' and 'ref' parameters (I think C# has both the most practical and the most elegant implementation, you can see at the call site whether it's by reference), so on. To some degree "pass by reference" is however just a collection of special cases with some similarity. For example, if one says that the guiding principle & main criterion is that one should not have to indicate the pass by reference at the call site, then that would exclude C#. But if one allows some indication at the call site, then that would perhaps include C (applying the & address op), which everyone agrees does not have call by reference. So, to understand the conventional meaning of the term it is perhaps necessary to have some knowledge of all the special cases, like here C# versus C. Cheers & hth., - Alf From steve at holdenweb.com Fri Feb 12 17:17:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 17:17:00 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > You may note that that Wikipedia article refers to an article that I > wrote about pointers in C++. > It's a broken link, referring to a non-existent server. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Fri Feb 12 17:27:19 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 23:27:19 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> You may note that that Wikipedia article refers to an article that I >> wrote about pointers in C++. >> > It's a broken link, referring to a non-existent server. Yes, sorry. It's been that way a long time, and for the same reason my C++ tutorial, the only one linked to from the C++ FAQ, is also off-line. However, if you're interested then copies of the "pointers" doc are likely to be floating around (at one time some mention of it somewhere generated very high traffic over a few weeks, people downloading the PDF, and then I almost reversed my decision not to have ads...). Cheers & hth., - Alf From solipsis at pitrou.net Fri Feb 12 17:27:32 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 22:27:32 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75D1B9.1050809@holdenweb.com> Message-ID: Le Fri, 12 Feb 2010 17:10:01 -0500, Steve Holden a ?crit?: > > As has already been pointed out, if Python used call by reference then > the following code would run without raising an AssertionError: > > def exchange(a, b): > a, b = b, a > > x = 1 > y = 2 > exchange(x, y) > assert (x == 2 and y == 1) > > Since function-local assignment always takes place in the function > call's local namespace I don't think this is related to a difference in parameter passing style. It's just that assignment ("=") means a different thing in Python than in non-object languages (or fake-object languages such as C++ or PHP): it rebinds instead of mutating in-place. If it mutated, you wouldn't have the AssertionError. If you mutate in-place: >>> def exchange(a, b): ... t = a[:] ... a[:] = b ... b[:] = t ... >>> x, y = [1], [2] >>> exchange(x, y) >>> x, y ([2], [1]) Regards Antoine. From solipsis at pitrou.net Fri Feb 12 17:37:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 22:37:55 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Le Fri, 12 Feb 2010 23:12:06 +0100, Alf P. Steinbach a ?crit?: > > Steven talks about the standard meaning of "pass by reference". See my answer to Steve's message. You can't postulate a "standard meaning" of "pass by reference" independently of the specificities of each language. For example a "variable" in Python means something different than in non-object languages; it is impossible to have an agnostic definition. In Python and other true object languages, the operations on references (especially assignment) don't have the same semantics as in more archaic languages. This is no reason, IMO, to refuse using the term "pass by reference". The state of art in computing languages evolves, and it wouldn't be constructive to remain stuck with definitions from the 1960s. Regards Antoine. From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 17:44:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 22:44:52 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> Message-ID: <0385c5f3$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 21:26:24 +0100, Alf P. Steinbach wrote: > Yes, I do count this as a personal attack and flaming. > > The litmus test for that is that it says something very negative about > the person you're debating with. As negative as accusing somebody of intentionally lying? Or is it only a personal attack when other people dare to disagree with Alf P. Steinbach? > In addition, your statement about the earlier attacks on me, is untrue, > and your implication that it's only about attacks on me, is untrue. Both > of which are very misleading, by the way. I'm assuming that you're > intentionally lying. Get over yourself. You're not so important that everyone is falling over themselves to discredit you by intentional lying. You do bring some technical knowledge and perspectives that is valuable to this community, but it comes with so much spikiness, near-paranoia and Freudian projection that it is extremely unpleasant dealing with you. Since you first came to this community, you have displayed a remarkable ability to take personal offence at virtually every disagreement, a deeply paranoid viewpoint that whenever somebody contradicts your statements they are deliberately lying, and a level of arrogance that is outstanding even for computer science. (How sure of yourself do you have to be to write a textbook for beginners in a language that you yourself are a self-professed beginner in?) I note with interest that this is not the only forum where your reaction to disagreement is to accuse others of deliberate lying. It is a habit of yours, and you've displayed it frequently and repeatedly. For example: http://coding.derkeiler.com/Archive/General/comp.programming/2006-08/msg00139.html http://www.embeddedrelated.com/usenet/embedded/show/43780-20.php http://groups.google.am/group/comp.lang.c++/browse_thread/thread/555331f8dd594837 I'm no longer willing to tolerate the unpleasant attitudes you display. So congratulations Alf. I've only kill-filed one other person on this newsgroup until now. You are now the second. I may reverse it some time in the future, but for now I'm just not interested in your paranoid accusations that others are lying about you and your continual misuse of the term "ad hominem" to refer to any and all criticism of your behaviour. *plonk* -- Steven From rtw at rtw.me.uk Fri Feb 12 17:46:23 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Fri, 12 Feb 2010 16:46:23 -0600 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: hjebbers wrote in news:2864756a-292b-4138-abfd- 3348b72b7e9a at u9g2000yqb.googlegroups.com in comp.lang.python: > the information about the error is a windows dump. This may help: # http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx SEM_FAILCRITICALERRORS = 1 SEM_NOALIGNMENTFAULTEXCEPT = 4 SEM_NOGPFAULTERRORBOX = 4 SEM_NOOPENFILEERRORBOX = 8 import ctypes from ctypes.wintypes import UINT SetErrorMode = ctypes.windll.kernel32.SetErrorMode SetErrorMode.restype = UINT SetErrorMode.argtypes = ( UINT,) Then putting: SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX ) at the start of you programme, should stop the "Critical Error" dialog box you are seeing and you may get a chance to see a traceback. Rob. From alfps at start.no Fri Feb 12 17:49:38 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 23:49:38 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Antoine Pitrou: > Le Fri, 12 Feb 2010 23:12:06 +0100, Alf P. Steinbach a ?crit : >> Steven talks about the standard meaning of "pass by reference". > > See my answer to Steve's message. You can't postulate a "standard > meaning" of "pass by reference" independently of the specificities of > each language. Agreed. See e.g. my discussion of C versus C# in the article you responded to. > For example a "variable" in Python means something > different than in non-object languages; it is impossible to have an > agnostic definition. It's possible and relatively speaking easy, but it's bound up with such a tangle of terminological and religious issues that it's best not discussed here. :-( But if you find/have a description that helps you understand what's going on, and that correctly predicts the effect of code, then just Use It. :-) After all, learning some "simpler" description would at that point just be more work. > In Python and other true object languages, the operations on references > (especially assignment) don't have the same semantics as in more archaic > languages. This is no reason, IMO, to refuse using the term "pass by > reference". The state of art in computing languages evolves, and it > wouldn't be constructive to remain stuck with definitions from the 1960s. The main reason for not using that term for Python is that "pass by reference" has the extremely strong connotation of being able to implement 'swap'. And since there already is adequate standard terminology, why confuse things. Cheers & hth., - Alf From g.bogle at auckland.no.spam.ac.nz Fri Feb 12 18:18:48 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 13 Feb 2010 12:18:48 +1300 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > def swap(a, b): > a, b = b, a > > x = 1 > y = 2 > swap(x, y) > assert (x == 2) and (y==1) Can't the same point be more simply made with this example: def setval(a): a = 12345 x = 1 setval(x) print x ? From steve at holdenweb.com Fri Feb 12 18:26:57 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 18:26:57 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Steven D'Aprano wrote: > >> def swap(a, b): >> a, b = b, a >> >> x = 1 >> y = 2 >> swap(x, y) >> assert (x == 2) and (y==1) > > Can't the same point be more simply made with this example: > > def setval(a): > a = 12345 > > x = 1 > setval(x) > print x > Yes, and it will doubtless be subject to exactly the same bogus refutations. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From solipsis at pitrou.net Fri Feb 12 18:30:12 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 23:30:12 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Le Fri, 12 Feb 2010 23:49:38 +0100, Alf P. Steinbach a ?crit?: > > The main reason for not using that term for Python is that "pass by > reference" has the extremely strong connotation of being able to > implement 'swap'. But 'swap' is so easy to write as a one-line statement that it's foolish to want to make a Python function for it... cheers Antoine. From alfps at start.no Fri Feb 12 18:47:56 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 00:47:56 +0100 Subject: Modifying Class Object In-Reply-To: <0385c5f3$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Fri, 12 Feb 2010 21:26:24 +0100, Alf P. Steinbach wrote: > >> Yes, I do count this as a personal attack and flaming. >> >> The litmus test for that is that it says something very negative about >> the person you're debating with. > > As negative as accusing somebody of intentionally lying? > > Or is it only a personal attack when other people dare to disagree with > Alf P. Steinbach? Do you mean that everybody else is allowed to get personal, but I, in return, am not so allowed? >> In addition, your statement about the earlier attacks on me, is untrue, >> and your implication that it's only about attacks on me, is untrue. Both >> of which are very misleading, by the way. I'm assuming that you're >> intentionally lying. > > Get over yourself. You're not so important that everyone is falling over > themselves to discredit you by intentional lying. This implies something about my beliefs about my importance, that is, it is clearly intended as an ad hominem attack. I'm getting a bit tired of that. > You do bring some technical knowledge and perspectives that is valuable to > this community, but it comes with so much spikiness, near-paranoia and > Freudian projection that it is extremely unpleasant dealing with you. > > Since you first came to this community, you have displayed a remarkable > ability to take personal offence at virtually every disagreement, That is not true. I do take offense at pure personal attacks, though. Personal attacks are about person, technical discussion is about technical things. > a deeply paranoid viewpoint that whenever somebody contradicts your > statements they are deliberately lying, That's just stupid, sorry. Being paranoid is not about being attacked, or about pointing out when someone's lying. Hello. > and a level of arrogance that is > outstanding even for computer science. (How sure of yourself do you have > to be to write a textbook for beginners in a language that you yourself > are a self-professed beginner in?) > > I note with interest that this is not the only forum where your reaction > to disagreement is to accuse others of deliberate lying. Your argument gets a bit circular. > It is a habit of yours, That is untrue. > and you've displayed it frequently No, that is untrue. > and repeatedly. Yes, I have repeatedly pointed when people have been lying, citing the evidence and logic leading to that conclusion. I wouldn't just "accuse" someone of something like that. It's far too serious (however, above you're happy with accusing me of being paranoid and whatever, so I conclude that you have no such qualms). > For example: > > http://coding.derkeiler.com/Archive/General/comp.programming/2006-08/msg00139.html > > http://www.embeddedrelated.com/usenet/embedded/show/43780-20.php > > http://groups.google.am/group/comp.lang.c++/browse_thread/thread/555331f8dd594837 Yes, I've been on the net a long time, and consequently I have been involved in flame wars. :-)[1] That is no excuse for your behavior. An extremely long thread dedicated to the notion that there are no references in Python (which is blatantly false), coupled with personal attacks on the one person arguing that there are. I could easily think that you were having me on. Of course most anyone else who'd hold the rational opinion would not join the battlefield, because it clearly wasn't and isn't about convincing or educating anyone, but I feel that follow-ups to my articles should be answered. Cheers & hth., - Alf Notes: [1] Like one here where some guy A objects to some other guy B's use of the term "portable assembler" about C, where at first I try to defend B's point of view, since it is after all one employed even by the creators of C. B sensibly opts out of the discussion while I stay on, predictable result. Another flame war is with some functional programming fanatic, and a third with a known troll. From greg.ewing at canterbury.ac.nz Fri Feb 12 18:55:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Feb 2010 12:55:42 +1300 Subject: Please help with MemoryError In-Reply-To: <0385b53b$0$1277$c3e8da3@news.astraweb.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> <0385b53b$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7tm7g9Fu56U1@mid.individual.net> Steven D'Aprano wrote: > Python's calling convention already has an well-established name, > established over thirty years ago by the distinguished computer scientist > Barbara Liskov, namely call-by-sharing. And she was mistaken in thinking it needed a new name. -- Greg From jim.hefferon at gmail.com Fri Feb 12 19:02:12 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 12 Feb 2010 16:02:12 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> <4b712919$0$6584$9b4e6d93@newsspool3.arcor-online.net> Message-ID: I want to thank everyone for the help, which I found very useful (the parts that I understood :-) ). Since I think there was some question, it happens that I am working under django and submitting a certain form triggers an html mail. I wanted to validate the html in some of my unit tests. It is only about 30 lines of html so I think I'll take a pass on automated html generation, but FWIW the intolerant parser found a couple of errors. Thanks again, Jim From rantingrick at gmail.com Fri Feb 12 19:05:45 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Feb 2010 16:05:45 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: On Feb 12, 4:10?pm, Steve Holden wrote: > Antoine Pitrou wrote: > > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : On Feb 12, 4:10?pm, Steve Holden wrote: > Antoine Pitrou wrote: > > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : Steve, Why do so many of your posts come in as doubles and triples. Is this a case of "studdering click finger" of some fault of your newsreader? -- concerned fellow pythonista... From kevin.p.dwyer at gmail.com Fri Feb 12 19:18:43 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 13 Feb 2010 00:18:43 +0000 (UTC) Subject: Configuring apache to execute python scripts using mod_python handler References: Message-ID: On Fri, 12 Feb 2010 13:08:59 -0400, Juan Carlos Rodriguez wrote: Hello Juan Carlos, You're better off raising this on the mod_python list, however... Python is looking for a module called mptest, and cannot find it. Have you created the mptest.py module? (It should contain the handler function in your item (2)). Is it on the python path used by the webserver? See for example the last post at http://forums.devshed.com/apache-development-15/installing-python-on-apache-42184.html which shows how you can set up the path. Cheers, Kev From m.echavarriagregory at umiami.edu Fri Feb 12 19:21:22 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Fri, 12 Feb 2010 19:21:22 -0500 Subject: MemoryError, can I use more? Message-ID: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Dear group: I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... Thanks, Angelica. From robert.kern at gmail.com Fri Feb 12 19:31:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Feb 2010 18:31:15 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-12 17:30 PM, Antoine Pitrou wrote: > Le Fri, 12 Feb 2010 23:49:38 +0100, Alf P. Steinbach a ?crit : >> >> The main reason for not using that term for Python is that "pass by >> reference" has the extremely strong connotation of being able to >> implement 'swap'. > > But 'swap' is so easy to write as a one-line statement that it's foolish > to want to make a Python function for it... Yes, but that's besides the point. The exercise at hand is to classify the semantic behavior of the function call syntax with respect to its arguments. Being able to implement swap() as a function is a distinguishing feature of the kind of function call semantics that the computer science community has named "call by reference." -- 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 aahz at pythoncraft.com Fri Feb 12 19:35:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 16:35:19 -0800 Subject: Dreaming of new generation IDE References: Message-ID: In article , Steve Holden wrote: >bartc wrote: >> "Arnaud Delobelle" wrote in message >> news:m28wb6ypfs.fsf at googlemail.com... >>> "Gabriel Genellina" writes: >>>> >>>> Note the *literal* part. If you (the programmer) is likely to know the >>>> parameter value when writing the code, then the function is actually two >>>> separate functions. >>> >>> Thanks, I understand what Steve Holden meant now. >> >> I've just noticed that 'literal' part. But I think I still disagree. >> >> For a real-world example, it means instead of having a room with a >> light-switch in it, if I *know* I want the light on or off, I should >> have two rooms: one with the light permanently on, and one with it >> permanently off, and just walk into the right one. > >Congratulations. That has to be the most bogus analogy I've seen on >c.l.py this year. Aww, c'mon, it's less than two months into the year, don't be so hyperbolic. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From gagsl-py2 at yahoo.com.ar Fri Feb 12 19:41:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 21:41:16 -0300 Subject: pyparsing wrong output References: <692c428f1002120541n6b3aabb0jb62c50f90715f38e@mail.gmail.com> Message-ID: En Fri, 12 Feb 2010 10:41:40 -0300, Eknath Venkataramani escribi?: > I am trying to write a parser in pyparsing. > Help Me. http://paste.pocoo.org/show/177078/ is the code and this is > input > file: http://paste.pocoo.org/show/177076/ . > I get output as: > There is nothing wrong with pyparsing here. scanString() returns a generator, like this: py> g = (x for x in range(20) if x % 3 == 1) py> g at 0x00E50D78> A generator is like a function that may be suspended and restarted. It yields one value at a time, and only runs when you ask for the next value: py> next(g) 1 py> next(g) 4 You may use a `for` loop to consume the generator: py> for i in g: ... print i ... 7 10 13 16 19 Once it run to exhaustion, asking for more elements always raises StopIteration: py> next(g) Traceback (most recent call last): File "", line 1, in StopIteration Try something like this: results = x.scanString(filedata) for result in results: print result See http://docs.python.org/tutorial/classes.html#generators -- Gabriel Genellina From ckaynor at zindagigames.com Fri Feb 12 19:44:57 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 12 Feb 2010 16:44:57 -0800 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: A 32 bit app can only use 4 GB of memory itself (regardless of the amount of system ram), the OS claims some of this for the system, dlls occupy some of it, etc. As such, the app can only really use a smaller subset (generally between 2 to 3 GB, depending upon the app and the OS). Chris On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica < m.echavarriagregory at umiami.edu> wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount > of data it works with is huge. I have managed to keep memory footprint low, > but have found that, independent of the physical RAM of the machine, python > always gives the MemoryError message when it has occupied exactly only 2.2 > GB. I have tested this in 4 different machines, all with memory of 3 to 4 > GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I > typed help(MemoryError) and it is a class itself, but that help told me > nothing I can use... > > Thanks, > Angelica. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Feb 12 19:45:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 19:45:02 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: [...] > Of course most anyone else who'd hold the > rational opinion would not join the battlefield, because it clearly > wasn't and isn't about convincing or educating anyone, but I feel that > follow-ups to my articles should be answered. > In other words, you must have the last word, a behavioral characteristic I will avoid drawing the obvious conclusions about for fear of begin accused (yet again) of making ad hominem attacks. I suppose you will therefore be unable to resist the temptation to respond to this. Though I'd love to be proved wrong again. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From breamoreboy at yahoo.co.uk Fri Feb 12 19:48:27 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 00:48:27 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Fri, 12 Feb 2010 21:26:24 +0100, Alf P. Steinbach wrote: >> >>> Yes, I do count this as a personal attack and flaming. >>> >>> The litmus test for that is that it says something very negative about >>> the person you're debating with. >> >> As negative as accusing somebody of intentionally lying? >> >> Or is it only a personal attack when other people dare to disagree >> with Alf P. Steinbach? > > Do you mean that everybody else is allowed to get personal, but I, in > return, am not so allowed? > > >>> In addition, your statement about the earlier attacks on me, is untrue, >>> and your implication that it's only about attacks on me, is untrue. Both >>> of which are very misleading, by the way. I'm assuming that you're >>> intentionally lying. >> >> Get over yourself. You're not so important that everyone is falling >> over themselves to discredit you by intentional lying. > > This implies something about my beliefs about my importance, that is, it > is clearly intended as an ad hominem attack. > > I'm getting a bit tired of that. > > > >> You do bring some technical knowledge and perspectives that is >> valuable to >> this community, but it comes with so much spikiness, near-paranoia and >> Freudian projection that it is extremely unpleasant dealing with you. >> >> Since you first came to this community, you have displayed a >> remarkable ability to take personal offence at virtually every >> disagreement, > > That is not true. > > I do take offense at pure personal attacks, though. > > Personal attacks are about person, technical discussion is about > technical things. > > > >> a deeply paranoid viewpoint that whenever somebody contradicts your >> statements they are deliberately lying, > > That's just stupid, sorry. > > Being paranoid is not about being attacked, or about pointing out when > someone's lying. > > Hello. > > >> and a level of arrogance that is outstanding even for computer >> science. (How sure of yourself do you have to be to write a textbook >> for beginners in a language that you yourself are a self-professed >> beginner in?) >> >> I note with interest that this is not the only forum where your >> reaction to disagreement is to accuse others of deliberate lying. > > Your argument gets a bit circular. > > > >> It is a habit of yours, > > That is untrue. > > >> and you've displayed it frequently > > No, that is untrue. > > >> and repeatedly. > > Yes, I have repeatedly pointed when people have been lying, citing the > evidence and logic leading to that conclusion. > > I wouldn't just "accuse" someone of something like that. > > It's far too serious (however, above you're happy with accusing me of > being paranoid and whatever, so I conclude that you have no such qualms). > > >> For example: >> >> http://coding.derkeiler.com/Archive/General/comp.programming/2006-08/msg00139.html >> >> >> http://www.embeddedrelated.com/usenet/embedded/show/43780-20.php >> >> http://groups.google.am/group/comp.lang.c++/browse_thread/thread/555331f8dd594837 >> > > Yes, I've been on the net a long time, and consequently I have been > involved in flame wars. :-)[1] > > That is no excuse for your behavior. > > An extremely long thread dedicated to the notion that there are no > references in Python (which is blatantly false), coupled with personal > attacks on the one person arguing that there are. I could easily think > that you were having me on. Of course most anyone else who'd hold the > rational opinion would not join the battlefield, because it clearly > wasn't and isn't about convincing or educating anyone, but I feel that > follow-ups to my articles should be answered. > > > Cheers & hth., > > - Alf > > > Notes: > [1] Like one here where some guy A objects to some other guy B's use of > the term "portable assembler" about C, where at first I try to defend > B's point of view, since it is after all one employed even by the > creators of C. B sensibly opts out of the discussion while I stay on, > predictable result. Another flame war is with some functional > programming fanatic, and a third with a known troll. I'm intrigued by your comments over the last couple of weeks, as you obviously know so much more about Python than people who have been working on it and/or using it for the 20 odd years of the existence of the language. Is it safe to assume that shortly you will be telling the scientific community that Einstein was a complete bozo and that his theory of relativity is crap, or that Stephen (Bob?) Hawking knows nothing about the origins of the universe? To put it another way, please stand up Alf, your voice is rather muffled. And this isn't an ad hominem attack, whatever the hell that means, I (NOTE I ) personally wish you'd bugger off and leave the bandwidth to people who genuinely want to discuss Python, computing algorithms, whatever. And please do NOT bother to reply. Your pathetic smileys and/or HTH garbage cut no ice with me. I'm quite simply staggered that the Python community as a whole have shown far more patience than I have, otherwise you'd have been shot down in seriously bad flames days ago. To you, Alf, get stuffed. To the rest of the Python community, thank you for doing a fantastic job, I do appreciate it, and am currently in my own little way attempting to put something back in. Regards. Mark Lawrence. From greg.ewing at canterbury.ac.nz Fri Feb 12 19:55:46 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Feb 2010 13:55:46 +1300 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75D1B9.1050809@holdenweb.com> Message-ID: <7tmb0tFektU1@mid.individual.net> Antoine Pitrou wrote: > It's just that assignment ("=") means a different thing in Python than in > non-object languages (or fake-object languages such as C++ or PHP): it > rebinds instead of mutating in-place. If it mutated, you wouldn't have > the AssertionError. It doesn't really have anything to do with assignment semantics. The essence of pass-by-reference is that the formal parameter name becomes an alias for the actual parameter in all respects. Whatever the semantics of assignment, you can come up with variations of the language that either do or don't support pass-by-reference in this sense. It's an orthogonal issue. -- Greg From ssteinerx at gmail.com Fri Feb 12 19:58:26 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Fri, 12 Feb 2010 19:58:26 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: <6546CE32-E9EA-4E33-9C7B-8A9808A4A083@gmail.com> On Feb 12, 2010, at 7:21 PM, Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... How are you determining that it has occupied "exactly only 2.2GB?" S From breamoreboy at yahoo.co.uk Fri Feb 12 20:00:47 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 01:00:47 +0000 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... > > Thanks, > Angelica. Please check the archives for the thread Please help with MemoryError, it was only posted a day or two back. It's a problem specific to Windows. Kindest regards. Mark Lawrence. From gagsl-py2 at yahoo.com.ar Fri Feb 12 20:03:04 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 22:03:04 -0300 Subject: Helpp I want view page .py on apache WHAT CAN I DO??????????????? References: Message-ID: Hola! En Fri, 12 Feb 2010 14:34:33 -0300, Juan Carlos Rodriguez escribi?: > ImportError: No module named mptest Hay una lista en castellano sobre Python: http://python.org.ar/pyar/ListaDeCorreo -- Gabriel Genellina From aahz at pythoncraft.com Fri Feb 12 20:06:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 17:06:49 -0800 Subject: Dreaming of new generation IDE References: <4b743340$0$20738$426a74cc@news.free.fr> Message-ID: In article <4b743340$0$20738$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > >Ever read "worst is better" ?-) Nope -- maybe you mean "worse is better"? http://www.jwz.org/doc/worse-is-better.html (Nitpicking because you need the correct term to search.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From benjamin.kaplan at case.edu Fri Feb 12 20:14:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 12 Feb 2010 20:14:46 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: On Fri, Feb 12, 2010 at 7:21 PM, Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... > > Thanks, > Angelica. There's nothing you can do in Python to fix it. A MemoryError means that Python asked the OS to malloc something and it refused to give it any more memory. In this case, it's because Windows will only allocate 2GB of RAM to a single process. There is a way to extend that to 3GB, but I don't quite understand how to do it- something about setting linker flags. Easiest way to handle this would be to switch to a 64-bit Python on a 64-bit platform. That way, you can use up to 8TB of memory. http://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx#memory_limits > -- > http://mail.python.org/mailman/listinfo/python-list > From alfps at start.no Fri Feb 12 20:29:42 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 02:29:42 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Mark Lawrence: > Alf P. Steinbach wrote: >> >> An extremely long thread dedicated to the notion that there are no >> references in Python (which is blatantly false), coupled with personal >> attacks on the one person arguing that there are. I could easily think >> that you were having me on. Of course most anyone else who'd hold the >> rational opinion would not join the battlefield, because it clearly >> wasn't and isn't about convincing or educating anyone, but I feel that >> follow-ups to my articles should be answered. [snippety] > > I'm intrigued by your comments over the last couple of weeks, as you > obviously know so much more about Python than people who have been > working on it and/or using it for the 20 odd years of the existence of > the language. I don't. On the other hand, it's a fallacy to think other people must be perfect. The glossary of my Python 3.1.1 documentation defines "Reference count: The number of references to an object. [...]" And so arguing against the existence of assignable references in Python would be silly if it was a genuine technical discussion. But I suspect that, in spite of my /first article's/ reference and frequent later references to term definitions etc., many who posted in this thread thought they were arguing against some other point of view, in the frenzy not bothering to check out things or actually /read/ what they replied to. So, as demonstrated, assuming that you were referring to people participating in this thread, people who have used a language for 20 odd years can still be wrong about something -- even when that something is utterly trivial. > Is it safe to assume that shortly you will be telling the > scientific community that Einstein was a complete bozo and that his > theory of relativity is crap, or that Stephen (Bob?) Hawking knows > nothing about the origins of the universe? > > To put it another way, please stand up Alf, your voice is rather > muffled. And this isn't an ad hominem attack Your response *is not* a personal attack? Then why are you trying to imply all kinds of things about my person, and not mentioning anything technical? Is there anything in the above, about assignable references, that you really think is on a par with relativity and requires Einstein's genius to understand? >, whatever the hell that > means, I (NOTE I ) personally wish you'd bugger off and leave the > bandwidth to people who genuinely want to discuss Python, computing > algorithms, whatever. > > And please do NOT bother to reply. Your pathetic smileys and/or HTH > garbage cut no ice with me. I'm quite simply staggered that the Python > community as a whole have shown far more patience than I have, otherwise > you'd have been shot down in seriously bad flames days ago. > > To you, Alf, get stuffed. Are you sure that this is not a personal attack? Just curious how you manage to think it couldn't be. Cheers & hth., ;-) - Alf From aahz at pythoncraft.com Fri Feb 12 20:32:26 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 17:32:26 -0800 Subject: Calendar GUI References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <4B6D055A.30901@gmail.com> Message-ID: In article , wrote: > >Take a look at wxscheduler, and chandler. You're joking about Chandler, right? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From gagsl-py2 at yahoo.com.ar Fri Feb 12 20:36:42 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 22:36:42 -0300 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: En Fri, 12 Feb 2010 11:22:40 -0300, Aahz escribi?: > In article , > Dennis Lee Bieber wrote: >> On 11 Feb 2010 21:18:26 -0800, aahz at pythoncraft.com (Aahz) declaimed the >> following in gmane.comp.python.general: >>> In article , >>> Gabriel Genellina wrote: >>>> >>>> Strange. With Python 2.6.4 I don't need to do that; I'd say the >>>> difference >>>> is in the OS or antivirus (some AV are known to break the TCP stack). >>> >>> Perhaps, but I've also found that ctrl-C doesn't work on Windows. >> >> Unless the running program makes an I/O call to the console, I don't >> think gets past the device driver... > > That's probably it. It's more annoying for me because I run Windows with > a VM on a Mac, which doesn't have ctrl-break. On a "real" PC with Windows XP SP3 and Python 2.6.4, with an idle server, just hitting Ctrl-C was enough: D:\temp>python -m SimpleXMLRPCServer Running XML-RPC server on port 8000 Traceback (most recent call last): File "d:\apps\python26\lib\runpy.py", line 122, in _run_module_as_main "__main__", fname, loader, pkg_name) File "d:\apps\python26\lib\runpy.py", line 34, in _run_code exec code in run_globals File "d:\apps\python26\lib\SimpleXMLRPCServer.py", line 615, in server.serve_forever() File "d:\apps\python26\lib\SocketServer.py", line 224, in serve_forever r, w, e = select.select([self], [], [], poll_interval) KeyboardInterrupt A slightly more realistic example: a busy, single threaded server. I had to hit Ctrl-C twice: the first time, KeyboardInterrupt was sent as a Fault response to the client. import sys def busy(): x = 50000 y = x**x return "Ok" if sys.argv[1]=='server': import SimpleXMLRPCServer server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000),logRequests=False) server.register_function(busy) server.serve_forever() else: import xmlrpclib proxy = xmlrpclib.ServerProxy("http://localhost:8000/") while True: print "client", proxy.busy() Maybe the OP's code containes a bare 'except:' clause that swallows KeyboardInterrupt, or the server is so busy that is always executing a function handler (and all KeyboardInterrupt become Fault and are sent as a function response). Mmm, perhaps that's a bug, a KeyboardInterrupt should bubble up to the server code, not being treated as an error in computing the function result. -- Gabriel Genellina From lists at cheimes.de Fri Feb 12 20:42:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 13 Feb 2010 02:42:59 +0100 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. The amount of RAM in your boxes is unrelated to your issue. A 32bit process is able to address only 4GB of virtual memory because it has no way to access memory addresses beyond the 32bit border. Large amount of the address space are reserved for multiple purposes like error checking (e.g. the NULL pointer), the entry point of the program, its stack and address space for reallocating dynamic linked libraries. On modern Linux systems the space for the heap is about 2.6 to 2.7 GB large. The heap is the memory segment used by malloc() and friends. It looks like the memory segment for the heap is slightly smaller on Windows. Virtual memory isn't the same as resident memory. A program may only occupy 100 MB in your RAM (resident memory) but it may use 1.5 GB of virtual memory. Virtual memory takes memory fragmentation and unused pages into account. If you malloc() 1 GB memory but just file up the first byte your program requires 1 GB of virtual memory but only a few KB resident memory. At least that's the story on Linux and several other Unix-like OSes. I'm not sure how Windows deals with memory. If your program needs more than 2 GB of RAM you should switch to a 64bit OS and a 64bit version of Python. Windows AMD64 builds for Python are available on python. Christian From gagsl-py2 at yahoo.com.ar Fri Feb 12 20:48:30 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 22:48:30 -0300 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle escribi?: > I posted an example of a decorator that does just this in this thread a > couple of days ago: > > http://mail.python.org/pipermail/python-list/2010-February/1235742.html Ouch! I didn't see your post, nor several other earlier posts in this thread. In fact, I thought mine was the *first* reply when I wrote it! Yes, of course, your code does exactly that without any bytecode hacks. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Feb 12 21:08:49 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 23:08:49 -0300 Subject: Pixel control References: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> <880fa1d41002121112r4e8c1550xf32cdea17a2bfeb@mail.gmail.com> Message-ID: En Fri, 12 Feb 2010 16:12:37 -0300, joao abrantes escribi?: > noone knows if it's possible? i really need this.. > > On Thu, Feb 4, 2010 at 10:57 PM, joao abrantes > wrote: > >> Hello everyone. For example i am using a screen resolution of 800x600 >> is it >> possible to make python control the color of the pixels? For example >> paint >> the pixel (100,200) in red! And it would stay red when i am seeing a >> webpage, a movie, playing a game... etc.. First investigate how you could do such thing using whichever technology is needed, and only then, ask how you could do *that* in Python. -- Gabriel Genellina From gre1600 at gmail.com Fri Feb 12 21:18:26 2010 From: gre1600 at gmail.com (felix gao) Date: Fri, 12 Feb 2010 18:18:26 -0800 Subject: ConfigParser is not parsing Message-ID: Hi all, I am trying to get the some configuration file read in by Python, however, after the read command it return a list with the filename that I passed in. what is going on? Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import ConfigParser >>> p = ConfigParser.SafeConfigParser() >>> cfg = p.read("S3Files.conf") >>> cfg ['S3Files.conf'] cat S3Files.conf [main] taskName=FileConfigDriver lastProcessed=2010-01-31 dateFromat=%Y-%m-%d skippingValue=86400 skippingInterval=seconds Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Fri Feb 12 21:23:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Feb 2010 18:23:46 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> This entire thread has imploded like a neutron star into an infantile debate that only Caddie Couric, Bill O Reilly, and everyone on PMS-NBC can hold a candle to! The only post i enjoyed was Steve Howes! >From my unique perspective of not really knowing (or for that matter) really caring about any of you i can say *some* of you have most undoubly shown your true colors in this thread! First of all, we all know how D Aprano has such an unfettered ego problem. I myself have been the victom of his insults but simultaniously also found them quite enjoyable (at times) I'd classify Steven d'Aprano as a "well informed" arsehole with an inner clown trying to escape. Then there is "alex23". The only sockpuppet (of many suspects within this group) that i can 100 percent prove and of whom i knew sooner or later would come along for his chance at trolling. Just look at his GG cache and you will see 99% of his post are argmentitve, abusive trolls! He's a fish that waits for threads like these just so he can flop around! As for Alf, no he is not *tecnically* right about the definition of "ad homine" but that *really* doesn't matter. He has (time and time again) been personally attacked by some of the more "supposedly respected" people in this group. And as always the roaches start coming out of the woodwork in a most "pathetic puppy dog" way. What would you puppets do if there were no one to pull your strings? But the most nortoriuos behavior of all belongs to none other that the PSF chairman himself! Yes "Steve Holden", you should be ashamed of yourself! Your attacks have been more amd more destructive over the past year or so. Even if your behavoir could "somehow" be justified how can someone in your position lead the PSF and act as such an infintile way? I am very ashamed of you Steve and you really owe Alf (and the community at large) an apology although i doubt it will happen because then your own people will turn against you. I have documented the bad behavours of certain "pythonistas" on this group for some time now. And my original assumtions that only a handful of people really follow this group. Maybe one day we will have a fair playing feild for all but sadly it looks to be more like a pipe dream! Sleep well kids! From darkrho at gmail.com Fri Feb 12 21:28:32 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 12 Feb 2010 22:28:32 -0400 Subject: ConfigParser is not parsing In-Reply-To: References: Message-ID: <4eca3f41002121828x494c3dere60e9c96b71a27ef@mail.gmail.com> read() does not return the config object >>> import ConfigParser >>> config = ConfigParser.SafeConfigParser() >>> config.read('S3Files.conf') ['S3Files.conf'] >>> config.sections() ['main'] >>> config.get('main', 'taskName') 'FileConfigDriver' Regards, Rolando Espinoza La fuente www.rolandoespinoza.info On Fri, Feb 12, 2010 at 10:18 PM, felix gao wrote: > Hi all, > I am trying to get the some configuration file read in by Python, however, > after the read command it return a list with the filename that I passed in. > what is going on? > Python 2.6.1 (r261:67515, Jul ?7 2009, 23:51:51) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import ConfigParser >>>> p = ConfigParser.SafeConfigParser() >>>> cfg = p.read("S3Files.conf") >>>> cfg > ['S3Files.conf'] > > ?cat S3Files.conf > [main] > taskName=FileConfigDriver > lastProcessed=2010-01-31 > dateFromat=%Y-%m-%d > skippingValue=86400 > skippingInterval=seconds > Thanks in advance. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From twistedphrame at gmail.com Fri Feb 12 22:57:08 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Fri, 12 Feb 2010 19:57:08 -0800 (PST) Subject: fork vs threading.Thread Message-ID: I'm trying to run two servers in the same program at once. Here are the two: class TftpServJ(Thread): def __init__(self, ip, root, port=69, debug = False ): Thread.__init__(self) setup stuff here def run(self): try: self.server.listen(self.ip, self.port) except KeyboardInterrupt: pass and class XMLServer(Thread): def __init__(self, host, port, hostid, rsa_key): Thread.__init__(self) setup stuff def run(self): self.server.serve_forever() I call them as: tftpserv = TftpServJ(host, "/home/twistedphrame/Desktop/xmlrpc_server/ server") tftpserv.run() xmlserv = XMLServer(host, port, HostID, key) xmlserv.run() it seems that tftpserv runs but wont go on to spawn xmlserv as well. do I need to fork if I want both these to run at the same time? It was my impression that by using Thread execution in the main program would continue. From sccolbert at gmail.com Fri Feb 12 23:15:37 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 12 Feb 2010 23:15:37 -0500 Subject: fork vs threading.Thread In-Reply-To: References: Message-ID: <7f014ea61002122015g4786d0e8g7993dd4433b1bba8@mail.gmail.com> dont call the .run() method, call the .start() method which is defined the Thread class (and should NOT be overridden). tftpserv.start() xmlserv.start() On Fri, Feb 12, 2010 at 10:57 PM, Jordan Apgar wrote: > I'm trying to run two servers in the same program at once. Here are > the two: > class TftpServJ(Thread): > def __init__(self, ip, root, port=69, debug = False ): > Thread.__init__(self) > setup stuff here > > def run(self): > try: > self.server.listen(self.ip, self.port) > except KeyboardInterrupt: > pass > > and > class XMLServer(Thread): > def __init__(self, host, port, hostid, rsa_key): > Thread.__init__(self) > setup stuff > > def run(self): > self.server.serve_forever() > > > I call them as: > tftpserv = TftpServJ(host, "/home/twistedphrame/Desktop/xmlrpc_server/ > server") > tftpserv.run() > xmlserv = XMLServer(host, port, HostID, key) > xmlserv.run() > > > it seems that tftpserv runs but wont go on to spawn xmlserv as well. > do I need to fork if I want both these to run at the same time? It > was my impression that by using Thread execution in the main program > would continue. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Fri Feb 12 23:25:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 05:25:23 +0100 Subject: fork vs threading.Thread In-Reply-To: References: Message-ID: * Jordan Apgar: > I'm trying to run two servers in the same program at once. Here are > the two: > class TftpServJ(Thread): > def __init__(self, ip, root, port=69, debug = False ): > Thread.__init__(self) > setup stuff here > > def run(self): > try: > self.server.listen(self.ip, self.port) > except KeyboardInterrupt: > pass > > and > class XMLServer(Thread): > def __init__(self, host, port, hostid, rsa_key): > Thread.__init__(self) > setup stuff > > def run(self): > self.server.serve_forever() > > > I call them as: > tftpserv = TftpServJ(host, "/home/twistedphrame/Desktop/xmlrpc_server/ > server") > tftpserv.run() > xmlserv = XMLServer(host, port, HostID, key) > xmlserv.run() Here you're just calling the tftpserv.run method directly, not on a separate thread. So it blocks until it's finished (which probably is never?). Instead, try using tftpserv.start() According to the docs, "It [the start method] must be called at most once per thread object. It arranges for the object?s run() method to be invoked in a separate thread of control." You may have to decide on how you want your program to terminate, if you want that. > > > it seems that tftpserv runs but wont go on to spawn xmlserv as well. > do I need to fork if I want both these to run at the same time? It > was my impression that by using Thread execution in the main program > would continue. See above. Cheers & hth., - Alf From nagle at animats.com Sat Feb 13 00:16:51 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Feb 2010 21:16:51 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: <4b7631ee$0$1638$742ec2ed@news.sonic.net> kj wrote: >>> =A0 x =3D '%s' % y >>> =A0 x =3D '%s' % z >>> =A0 print y >>> =A0 print z >>> =A0 print y, z Bear in mind that most Python implementations assume the "console" only handles ASCII. So "print" output is converted to ASCII, which can fail. (Actually, all modern Windows and Linux systems support Unicode consoles, but Python somehow doesn't get this.) John Nagle From ptmcg at austin.rr.com Sat Feb 13 00:28:03 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Fri, 12 Feb 2010 21:28:03 -0800 (PST) Subject: pyparsing wrong output References: <692c428f1002120541n6b3aabb0jb62c50f90715f38e@mail.gmail.com> Message-ID: <879e832b-e211-4bfd-a239-40b583a0a1d1@a5g2000yqi.googlegroups.com> On Feb 12, 6:41?pm, "Gabriel Genellina" wrote: > En Fri, 12 Feb 2010 10:41:40 -0300, Eknath Venkataramani ? > escribi?: > > > I am trying to write a parser in pyparsing. > > Help Me.http://paste.pocoo.org/show/177078/is the code and this is ? > > input > > file:http://paste.pocoo.org/show/177076/. > > I get output as: > > > > There is nothing wrong with pyparsing here. scanString() returns a ? > generator, like this: > > py> g = (x for x in range(20) if x % 3 == 1) > py> g > at 0x00E50D78> > Unfortunately, your grammar doesn't match the input text, so your generator doesn't return anything. I think you are taking sort of brute force approach to this problem, and you need to think a little more abstractly. You can't just pick a fragment and then write an expression for it, and then the next and then stitch them together - well you *can* but it helps to think both abstract and concrete at the same time. With the exception of your one key of "\'", this is a pretty basic recursive grammar. Recursive grammars are a little complicated to start with, so I'll start with a non-recursive part. And I'll work more bottom-up or inside-out. Let's start by looking at these items: count => 8, baajaar => 0.87628353, kiraae => 0.02341598, lii => 0.02178813, adr => 0.01978462, gyiimn => 0.01765590, Each item has a name (which you called "eng", so I'll keep that expression), a '=>' and *something*. In the end, we won't really care about the '=>' strings, they aren't really part of the keys or the associated values, they are just delimiting strings - they are important during parsing, but afterwards we don't really care about them. So we'll start with a pyparsing expression for this: keyval = eng + Suppress('=>') + something Sometimes, the something is an integer, sometimes it's a floating point number. I'll define some more generic forms for these than your original number, and a separate expression for a real number: integer = Combine(Optional('-') + Word(nums)) realnum = Combine(Optional('-') + Word(nums) + '.' + Word(nums)) When we parse for these two, we need to be careful to check for a realnum before an integer, so that we don't accidentally parse the leading of "3.1415" as the integer "3". something = realnum | integer So now we can parse this fragment using a delimitedList expression (which takes care of the intervening commas, and also suppresses them from the results: filedata = """ count => 8, baajaar => 0.87628353, kiraae => 0.02341598, lii => 0.02178813, adr => 0.01978462, gyiimn => 0.01765590,""" print delimitedList(keyval).parseString(filedata) Gives: ['count', '8', 'baajaar', '0.87628353', 'kiraae', '0.02341598', 'lii', '0.02178813', 'adr', '0.01978462', 'gyiimn', '0.01765590'] Right off the bat, we see that we want a little more structure to these results, so that the keys and values are grouped naturally by the parser. The easy way to do this is with Group, as in: keyval = Group(eng + Suppress('=>') + something) With this one change, we now get: [['count', '8'], ['baajaar', '0.87628353'], ['kiraae', '0.02341598'], ['lii', '0.02178813'], ['adr', '0.01978462'], ['gyiimn', '0.01765590']] Now we need to add the recursive part of your grammar. A nested input looks like: confident => { count => 4, trans => { ashhvsht => 0.75100505, phraarmnbh => 0.08341708, }, }, So in addition to integers and reals, our "something" could also be a nested list of keyvals: something = realnum | integer | (lparen + delimitedList(keyval) + rparen) This is *almost* right, with just a couple of tweaks: - the list of keyvals may have a comma after the last item before the closing '}' - we really want to suppress the opening and closing braces (lparen and rparen) - for similar structure reasons, we'll enclose the list of keyvals in a Group to retain the data hierarchy lparen,rparen = map(Suppress, "{}") something = realnum | integer | Group(lparen + delimitedList(keyval) + Optional(',') + rparen) The recursive problem is that we have defined keyval using something, and something using keyval. You can't do that in Python. So we use the pyparsing class Forward to "forward" declare something: something = Forward() keyval = Group(eng + Suppress('=>') + something) To define something as a Forward, we use the '<<' shift operator: something << (realnum | integer | Group(lparen + delimitedList(keyval) + Optional(',') + rparen)) Our grammar now looks like: lparen,rparen = map(Suppress, "{}") something = Forward() keyval = Group(eng + Suppress('=>') + something) something << (realnum | integer | Group(lparen + delimitedList(keyval) + Optional(',') + rparen)) To parse your entire input file, use a delimitedList(keyval) results = delimitedList(keyval).parseString(filedata) (There is one problem - one of your keynames is "\'". I don't know if this is a typo or intentional. If you need to accommodate even this as a keyname, just change your definition of eng to Word(alphas +r"\'").) Now if I parse your original string, I get (using the pprint module to format the results): [['markets', [['count', '8'], ['trans', [['baajaar', '0.87628353'], ['kiraae', '0.02341598'], ['lii', '0.02178813'], ['adr', '0.01978462'], ['gyiimn', '0.01765590'], ['baaaaromn', '0.01765590'], ['sdk', '0.01728024'], ['kaanuun', '0.00613574'], ',']], ',']], ['confident', [['count', '4'], ['trans', [['ashhvsht', '0.75100505'], ['phraarmnbh', '0.08341708'], ['athmvishhvaas', '0.08090452'], ['milte', '0.03768845'], ['utnii', '0.02110553'], ['anaa', '0.01432161'], ['jitne', '0.01155779'], ',']], ',']], ['consumers', [['count', '34'], ['trans', [['upbhokhtaaomn', '0.48493883'], ['upbhokhtaa', '0.27374792'], ['zrurtomn', '0.02753605'], ['suuchnaa', '0.02707965'], ['ghraahkomn', '0.02580174'], ['ne', '0.02574089'], ["\\'", '0.01947301'], ['jnmt', '0.01527414'], ',']], ',']]] But there is one more card up pyparsing's sleeve. Just as your original parser used "english" to apply a results name to your keys, it would be nice if our parser would return not a list of key-value pairs, but an actual dict-like object. Pyparsing's Dict class enhances the results in just this way. Use Dict to wrap our repetitive structures, and it will automatically define results names for us, reading the first element of each group as the key, and the remaining items in the group as the value: something << (realnum | integer | Dict(lparen + delimitedList(keyval) + Optional(',').suppress() + rparen)) results = Dict(delimitedList(keyval)).parseString(filedata) print results.dump() Gives this hierarchical structure: - confident: - count: 4 - trans: - anaa: 0.01432161 - ashhvsht: 0.75100505 - athmvishhvaas: 0.08090452 - jitne: 0.01155779 - milte: 0.03768845 - phraarmnbh: 0.08341708 - utnii: 0.02110553 - consumers: - count: 34 - trans: - \': 0.01947301 - ghraahkomn: 0.02580174 - jnmt: 0.01527414 - ne: 0.02574089 - suuchnaa: 0.02707965 - upbhokhtaa: 0.27374792 - upbhokhtaaomn: 0.48493883 - zrurtomn: 0.02753605 - markets: - count: 8 - trans: - adr: 0.01978462 - baaaaromn: 0.01765590 - baajaar: 0.87628353 - gyiimn: 0.01765590 - kaanuun: 0.00613574 - kiraae: 0.02341598 - lii: 0.02178813 - sdk: 0.01728024 You can access these fields by name like dict elements: print results.keys() print results["confident"].keys() print results["confident"]["trans"]["jitne"] If the names are valid Python identifiers (which "\'" is *not*), you can access their fields like attributes of an object: print results.confident.trans.jitne for k in results.keys(): print k, results[k].count Prints: ['confident', 'markets', 'consumers'] ['count', 'trans'] 0.01155779 0.01155779 confident 4 markets 8 consumers 34 I've posted the full program at http://pyparsing.pastebin.com/f1d0e2182. Welcome to pyparsing! -- Paul From nagle at animats.com Sat Feb 13 00:48:30 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Feb 2010 21:48:30 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: <4b763959$0$1633$742ec2ed@news.sonic.net> kj wrote: > Some people have mathphobia. I'm developing a wicked case of > Unicodephobia. > > I have read a *ton* of stuff on Unicode. It doesn't even seem all > that hard. Or so I think. Then I start writing code, and WHAM: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) First, you haven't told us what platform you're on. Windows? Linux? Something else? If you're on Windows, and running Python from the command line, try "cmd /u" before running Python. This will get you a Windows console that will print Unicode. Python recognizes this, and "print" calls will go out to the console in Unicode, which will then print the correct characters if they're in the font being used by the Windows console. Most European languages are covered in the standard font. If you're using IDLE, or some Python debugger, it may need to be told to have its window use Unicode. John Nagle From misceverything at gmail.com Sat Feb 13 01:32:45 2010 From: misceverything at gmail.com (T) Date: Fri, 12 Feb 2010 22:32:45 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> Message-ID: On Feb 11, 4:10?am, Tim Golden wrote: > On 10/02/2010 22:55, T wrote: > > > Great suggestions once again - I did verify that it was at least > > running the plink.exe binary when under LocalSystem by having the > > service run "plink.exe> ?C:\plinkoutput.txt" - this worked fine. ?And, > > as I mentioned, it's now working just fine when running under a > > regular admin account. ?So, I think that's going to be my solution to > > avoid any further issues. ?My best guess at this point (as you > > mentioned), is that plink.exe is doing _something_ network-related > > that LocalSystem doesn't have the privileges to do - what exactly it > > is, I have no idea. ?I may play around with it some more later, but > > running the service under an admin account should be a perfectly > > acceptable solution. > > > Also, I will be writing other Python apps that the service will be > > executing - so it goes without saying that I'll be including a log to > > file option :) ?Thanks again for all your guys' help! > > I'm not sure if this has been said already, but a reasonably common > approach to services is to create a user specifically for the > service and grant it exactly the privs / perms it needs (once you > work out what they are). You then assign it a generated password, > eg a GUID which you don't even try to remember: simply cut-and-paste > it in. Then create the service to run under that user. > > That way you don't have the service running under > some local Administrator account with the associated risk > of its being subverted and gaining more control than you > want. Nor do you have it running as a real user whose > password might change for any reason, leaving you with > a service which won't start up. > > I don't remember at this moment whether such a user's profile > is automatically loaded in the process when the service starts > or whether you have to do the LoadUserProfile thing. > > TJG Tim - thanks, that's the route I'm going to go. I've created separate accounts for services before, and there's no question that's what I have to do in this case. I'm still having some issues running some commands (such as one that takes a screenshot), even as an admin user, but I think this is more due to the fact that it's trying to interact with the Desktop..so there may be no good solution. Btw great site..can't tell you how many times I've gone back to it. Keep up the great work! From misceverything at gmail.com Sat Feb 13 01:36:44 2010 From: misceverything at gmail.com (T) Date: Fri, 12 Feb 2010 22:36:44 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <10b628f5-0b85-46c4-b2ef-2a8579c10162@d27g2000yqn.googlegroups.com> On Feb 11, 8:21?am, "Martin P. Hellwig" wrote: > On 02/07/10 19:02, T wrote: > > > I have a script, which runs as a Windows service under the LocalSystem > > account, that I wish to have execute some commands. ?Specifically, the > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > an admin account, all is well. ?However, when I'm running it via > > service, no luck. ?I'm assuming this is to do with the fact that it's > > trying to run under the LocalSystem account, which is failing. ?What > > would be the best way around this? ?Thanks! > > All being said about LS account not having the appropriate rights to > access the necessary devices/files. > > Could it be so simple that the network is plain simply not available at > all? For wireless connections I believe the connection/authentication by > default is made in user space. I would save the output of an ipconfig > run as the LS account to a file and see what is happening. > Perhaps followed by a ping. > > -- > mph Martin - another part of the program sends an email back to a specified user, and that works, so LocalSystem must at least have some network access. From the testing I've done so far, seems like there's just some grey area (which I haven't completely figured out yet) of network-related tasks that LS just can't do. I'd love to know what this is, but so far the solution I have is just to create another user and have the service use that.. From nobody at nowhere.com Sat Feb 13 02:01:39 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 13 Feb 2010 07:01:39 +0000 Subject: MemoryError, can I use more? References: Message-ID: On Fri, 12 Feb 2010 19:21:22 -0500, Echavarria Gregory, Maria Angelica wrote: > I am developing a program using Python 2.5.4 in windows 32 OS. The amount > of data it works with is huge. I have managed to keep memory footprint > low, but have found that, independent of the physical RAM of the machine, > python always gives the MemoryError message when it has occupied exactly > only 2.2 GB. I have tested this in 4 different machines, all with memory > of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I > typed help(MemoryError) and it is a class itself, but that help told me > nothing I can use... A single process can't use much more than 2GiB of RAM without a 64-bit CPU and OS. If you're stuck with a 32-bit system, you really need to figure out how to limit the amount of data which is kept in memory at any one time. From vorticitywolfe at gmail.com Sat Feb 13 02:33:09 2010 From: vorticitywolfe at gmail.com (J Wolfe) Date: Fri, 12 Feb 2010 23:33:09 -0800 (PST) Subject: How do you implement a Progress Bar Message-ID: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> I would really appreciate some help with this. I'm fairly new to using classes...What am I doing wrong? All I get is a blank window. I can't seem to figure out how to initialize this Progress Bar. Thanks, Jonathan ##############################file Meter.py#################### from Tkinter import * class Meter(Frame): '''A simple progress bar widget.''' def __init__(self, master, fillcolor='orchid1', text='',value=0.0, **kw): Frame.__init__(self, master, bg='white', width=350,height=20) self.configure(**kw) self._c = Canvas(self, bg=self['bg'],width=self['width'], height=self['height'],highlightthickness=0, relief='flat',bd=0) self._c.pack(fill='x', expand=1) self._r = self._c.create_rectangle(0, 0, 0, int(self['height']), fill=fillcolor, width=0) self._t = self._c.create_text(int(self['width'])/2, int(self['height'])/2, text='') self.set(value, text) def set(self, value=0.0, text=None): #make the value failsafe: if value < 0.0: value = 0.0 elif value > 1.0: value = 1.0 if text == None: #if no text is specified get the default percentage string: text = str(int(round(100 * value))) + ' %' self._c.coords(self._r, 0, 0, int(self['width']) * value, int(self['height'])) self._c.itemconfigure(self._t, text=text) root=Tk() f=Meter(root) for i in range(100): f.set(i,"Hello") print i mainloop() From alfps at start.no Sat Feb 13 02:54:21 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 08:54:21 +0100 Subject: How do you implement a Progress Bar In-Reply-To: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> References: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> Message-ID: * J Wolfe: > I would really appreciate some help with this. I'm fairly new to > using classes...What am I doing wrong? All I get is a blank window. I > can't seem to figure out how to initialize this Progress Bar. > > Thanks, > Jonathan > > > > ##############################file Meter.py#################### > from Tkinter import * > > class Meter(Frame): > '''A simple progress bar widget.''' > def __init__(self, master, fillcolor='orchid1', text='',value=0.0, > **kw): > Frame.__init__(self, master, bg='white', width=350,height=20) > self.configure(**kw) > self._c = Canvas(self, bg=self['bg'],width=self['width'], > height=self['height'],highlightthickness=0, relief='flat',bd=0) > self._c.pack(fill='x', expand=1) > self._r = self._c.create_rectangle(0, 0, 0, int(self['height']), > fill=fillcolor, width=0) > self._t = self._c.create_text(int(self['width'])/2, > int(self['height'])/2, text='') > self.set(value, text) > > def set(self, value=0.0, text=None): > #make the value failsafe: > if value < 0.0: > value = 0.0 > elif value > 1.0: > value = 1.0 > if text == None: > #if no text is specified get the default percentage string: > text = str(int(round(100 * value))) + ' %' > self._c.coords(self._r, 0, 0, int(self['width']) * value, > int(self['height'])) > self._c.itemconfigure(self._t, text=text) > > > > root=Tk() > f=Meter(root) At his point the Meter widget has been created, but it's still invisible. To make it visible you have to register it with a layout manager (in tkinter-speak a "geometry" manager). A layout manager for a widget X is responsible for placing child widgets of X. The easiest is to add, at this point, f.pack() which uses the packing layout manager of the parent widget of f (not sure why the design is like this, but f.pack() forwards up to the parent's layout manager). You can add various optional parameters. Or use other layout mgr. Take care that all child widgets of a given parent widget use the same layout manager, otherwise the typical result is a hang. > for i in range(100): > f.set(i,"Hello") > print i This will probably happen too fast to see, before the window is presented. One idea might be to add a few buttons for testing things. > mainloop() Cheers & hth., - Alf From vorticitywolfe at gmail.com Sat Feb 13 03:22:19 2010 From: vorticitywolfe at gmail.com (J Wolfe) Date: Sat, 13 Feb 2010 00:22:19 -0800 (PST) Subject: How do you implement a Progress Bar References: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> Message-ID: <1a5d5ff2-bd54-4a2f-a74b-b1b89dd92bc8@v25g2000yqk.googlegroups.com> Thank you Alf! Here I thought it was something wrong with my class call, but it turns out I just needed to pack f and then use root.update() in the loop :-) I really appreciate your help! From half.italian at gmail.com Sat Feb 13 03:25:32 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sat, 13 Feb 2010 00:25:32 -0800 (PST) Subject: How do you implement a Progress Bar References: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> Message-ID: <378c7809-1f69-4516-a4ef-b9eff4d1790a@u15g2000prd.googlegroups.com> On Feb 12, 11:33?pm, J Wolfe wrote: > I would really appreciate some help with this. ?I'm fairly new to > using classes...What am I doing wrong? All I get is a blank window. I > can't seem to figure out how to initialize this Progress Bar. > Study and hack on this: http://uucode.com/texts/pylongopgui/pyguiapp.html ~Sean From apt.shansen at gmail.com Sat Feb 13 04:30:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 13 Feb 2010 01:30:37 -0800 Subject: Modifying Class Object In-Reply-To: <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> Message-ID: <7a9c25c21002130130x61516383va871d4018d352014@mail.gmail.com> On Fri, Feb 12, 2010 at 6:23 PM, rantingrick wrote: [blah, blah, blah] First of all, we all know how D Aprano has such an unfettered ego > problem. [blah, blah, blah] And as always the roaches start > coming out of the woodwork in a most "pathetic puppy dog" way. What > would you puppets do if there were no one to pull your strings? > [blah, blah, blah] (I'd claim an ad hominem attack, but that's just boring these days) > But the most nortoriuos behavior of all belongs to none other that the > PSF chairman himself! Yes "Steve Holden", you should be ashamed of > yourself! [blah, BLAH, blah] > Your attacks have been more amd more destructive over the > past year or so. Even if your behavoir could "somehow" be justified > how can someone in your position lead the PSF and act as such an > infintile way? [blah, blah, BLAH, blah] > I am very ashamed of you Steve and you really owe Alf > (and the community at large) an apology although i doubt it will > happen because then your own people will turn against you. > Blah. Blah. Blah. Grow up. I've deliberately exited the real topic of this thread, because its clearly degenerated to complete nonsense; while in this thread Alf argues for a certain dogmatic theoretical "Standard" terminology that clearly many people disagree with (supporting the 'standard' continually with a certain language's reference manual, which by definition makes it not-standard, or you wouldn't need to quote a certain language0, and in another he argues for another position-- and and speaks in support of standard and understood terminology, the two positions together are laughable nonsense. To this he will, of course, again declare that I am simply lying. This very declaration clearly proves his own absurdity: you can argue in a circle for infinity, but when you start spouting nonsense about how those opposing you are mere liars-- ESPECIALLY-- when you have been arguing about how you have been the terrible victim of ad hominem attacks-- your own hypocrisy makes your words meaningless. I've been tempted to re-enter the actual argument, its a hard one to avoid with such clear misunderstandings held so strongly. But, I won't. Except for my editorials here. Because I am weak. Ahem, the point is-- my chief antagonist in the discussion has publicly stated I am a liar. This is provably a lie unto itself, and it damns the speaker absolutely. I have expressed my position, my thoughts, and my opinion and interpretation of my opponents position -- and his response is, "You are a liar." or, "That is a lie". That's a lie, a personal attack, all the while declaring his own victimhood. You can say, "You're mistaken", but to say, "You are a liar." is something else entirely. The chief victim of c.p.l. becomes the abuser. Now, why am I entering this thread again? Not to discuss the issue at hand. There's clearly no point. Alf has chosen to define language in his own way, ignoring any weight that established industry weight might apply to such terms. Okay. When you enter an argument of words, some people will refuse to acknowledge their own perception of the world isn't reality. It happens. There's no point in going forward after a certain point. But now, this absurdity? You are ashamed of Steve Holden for his behavior? You think he owes the community at large an apology? I don't mean to rise up in defense of Holden, as I'm sure he can defend himself should he feel the need. I took offense at Alf choosing to claim the right of defending me earlier, so I can't be a hypocrite in that. But, really. If -this- is your position? Grow up. Seriously. Steve Holden owes this community nothing. That which he has given should be welcomed and he should be thanked for it. He hasn't flamed anyone; he hasn't attacked anyone-- despite Alf's nonsense claims, though on occasion his responses are snarky (with reason)-- he hasn't /taken/ anything from this community. He's done far more then many in assisting people who are trying to learn Python and embrace its community. Frankly, how dare you claim to demand an apology for this community. If I was to be ashamed of anyone's participation in the community, it would be you over him. I'm not even ashamed of Alf. I don't agree with him, I think he's got a stubborn egocentric view of terminology and semantics which is ultimately harmful, I think he has a severe persecution complex, but despite this-- I've seen him respond to several threads recently, helpfully, and I don't even disagree with most of those responses. You're just ... blabbering. Adding arbitrary, unsupported, and unsupportable fuel to the fire to rant at some position-- how /mean/ this community is and how /terrible/ we behave-- all without any basis at all. Except you claim it. You document it. Gee, we're mean, mean, unhelpful people. And no, I'm not one of "his people" who will turn on him for admitting he is satan; if Steve Holden and I have ever been in a thread in the past -- it was us both answering some newbie, or commenting on a topic, all independently-- and I'm not even sure I was ever aware of it having happened. I remember no particular conversation, ever, between him and I. This is one of the most generally supportive technical communities I've ever seen, even when faced with clear ignorance and people even not taking the most basic due diligence before asking others to answer their questions. It goes back almost a decade to when I posted more then one /really/ stupid question to this group on some initial assumptions and thoughts-- on most groups? Such things would be ridiculed. Here, people ask questions when the OP's position isn't clear or if it seems they may be looking at the problem wrong. They go out of their way to understand the use-case and details of the question and provide solutions. They -work- to be helpful, and supportive, with some demands-- but reasonable demands. And you're all ashamed of our "bad behaviors". That makes me want to say, "Well, f--- you too". But I won't. I'll just hope you grow up and get over it and learn that hey, communities? They are never seamless, or easy, and conflict is a part of life. Some have very hard standards for acceptance, some try to embrace but there's always going to be issues. This is one of the good ones. Deal with it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From dino at phidev.org Sat Feb 13 04:50:43 2010 From: dino at phidev.org (Florian Ludwig) Date: Sat, 13 Feb 2010 10:50:43 +0100 Subject: plugin / intra process communication system Message-ID: <1266054643.26540.58.camel@brain> Hi, I'm looking for a module/plugin/intra-process-communication/hook system for python. Maybe someone here could point me to some project I missed or might have some good ideas if I end up implementing it myself. Most systems I have found are "one to many" communications but I would like "many to many", to clarify what I mean an *example* use-case: Lets say you program a wiki and like to allow different kind of authentications. So you create two plugins (for example one for OpenID and one for Shibboleth). Some time later you feel like reinventing the wheel again and you program a blog. Again you like to allow different ways of authentication and you already wrote plugins for exactly the same for your wiki, right? With most systems now some trouble begins - the blog software would need to have the interface/extention-points/however-you-name-it that the wiki software defined. The plugins you wrote probably import them from the wiki module directly which means your blog would depend on the wiki. (?!) So where to put the interface/[...] definition that is imported by those plugins? Create a package/module just containing the interface? This really get troublesome if different people wrote the wiki, the blog and another third one a plugin. Also it will probably break if you try to create a program that includes (imports and uses) the wiki and the blog at the same time. While looking for existing solutions I came across several different implementations and approaches with different advantages and disadvantages. To not list them all, here one representative implementation: trac's component architecture [0] as its well but still short documented, shares several concepts with other implementations and I failed to see how to solve the problem described above with it. So, what's your solution? Thanks for reading my long mail! Really hoping for an constructive discussion, Florian [0] http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From showell30 at yahoo.com Sat Feb 13 04:53:09 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 01:53:09 -0800 (PST) Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: <3307e656-f2da-424e-96ea-1166f05835b5@b9g2000pri.googlegroups.com> On Feb 10, 5:59?am, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): > ? ? f.args = args > ? ? print args > > is there any other way? > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a > valid one at the moment, sorry. > You should care. :) You can avoid referring to f twice by using an inner method with a name that is less subject to change or influence from outside forces: def countdown_function_that_might_get_renamed( n, preamble, postamble): def recurse(n): print preamble, n, postamble if n: recurse(n-1) recurse(n) countdown_function_that_might_get_renamed(10, "before", "after") Note that the example makes the recursive call more concise, by avoiding the need to resend the parameters that don't change during the recursion ("preamble" and "postamble"). Of course, you do trade off some terseness with the inner method, but it's only two lines of code and one level of indentation. For a somewhat related discussion see this short thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/197221f82f7c247b In particular see Gabriel's response to me. The fact that you are saving off f.args makes me think that you are solving a problem similar to mine, but I could be wrong. From __peter__ at web.de Sat Feb 13 05:03:20 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Feb 2010 11:03:20 +0100 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: hjebbers wrote: > On Feb 12, 3:17 pm, Peter Otten <__pete... at web.de> wrote: >> hjebbers wrote: >> > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: >> >> hjebbers wrote: >> >> > On Feb 11, 5:45 pm, M3RT wrote: >> >> >> The problem may be related to how you treat the EDI file or lets >> >> >> say DATA. Also your coding style is important. Can you provide more >> >> >> info? >> >> >> > Yes, a whole lot more; but I do not want to bother you with that >> >> > now. I was just wondering if it is possible that the same setup >> >> > gives a CRASH! on windows and just works on linux. >> >> > (where is the bug?) >> >> >> In the platform-specific code ;) >> >> >> Even on alt.haruspicy they cannot do much without a liver now and >> >> then... >> >> > if it is in the platform-specific code should I make this into a >> > bugreport? >> >> A this stage a bug report would be useless. The details you have provided >> so far don't give anyone without physical access to your machine a chance >> to reproduce the error. >> >> > (because the crash does not appear at the same place in my code (when >> > doing the same test-run) it will be quite hard to point down....) >> >> Indeed. The culprit may be an extension written in C that is overwriting >> memory still in use by other parts of your program. >> >> Peter > > No C extensions used. Definitely not. > > As these crashes occur during stress tests, I go to the limits of the > memory available. > What strikes me is: > 1. the crash on windows, but linux works OK (same test sets) > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > much). Random thoughts: If there were not enough memory Python should give a MemoryError rather than segfault. Do both systems use the same memory layout (i. e. 32 or 64bit OS, 16 or 32 bit unicode)? Try an alpha of Python 2.7. If you're lucky "your" bug was found 'n' fixed independently. Peter From daniele.esposti at gmail.com Sat Feb 13 05:07:04 2010 From: daniele.esposti at gmail.com (Expo) Date: Sat, 13 Feb 2010 02:07:04 -0800 (PST) Subject: bsddb version mysmatch between win32 and linux Message-ID: <18361bde-a134-478f-b670-87c16fd57028@w31g2000yqk.googlegroups.com> Hi guys, I found an incompatibility in the bsddb library shipped with Python which is a different version between the win32 release and the linux release. This happend using Python 2.6.2 on win32 and OpenSuse 11.2. To reproduce this problem, create a bsddb file under win32 with this code: import shelve f = shelve.open( "test.bin" ) f["test"] = "test" f.sync() f.close() copy test.bin in the OpenSuse system and try to open it: import shelve f = shelve.open( "test.bin" ) print f["test"] and you get this traceback: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/shelve.py", line 234, in open return DbfilenameShelf(filename, flag, protocol, writeback) File "/usr/lib/python2.6/shelve.py", line 218, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback) File "/usr/lib/python2.6/anydbm.py", line 83, in open return mod.open(file, flag, mode) File "/usr/lib/python2.6/dbhash.py", line 19, in open return bsddb.hashopen(file, flag, mode) File "/usr/lib/python2.6/bsddb/__init__.py", line 361, in hashopen d.open(file, db.DB_HASH, flags, mode) bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- ./test.bin: unsupported hash version: 9') I don't know yet if the problem is related to OpenSuse or to the Python linux distribution. How I can resolve this ? From hjebbers at gmail.com Sat Feb 13 05:29:48 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 02:29:48 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: On Feb 12, 11:46?pm, Rob Williscroft wrote: > hjebbers wrote in news:2864756a-292b-4138-abfd- > 3348b72b7... at u9g2000yqb.googlegroups.com in comp.lang.python: > > > the information about the error is a windows dump. > > This may help: > > #http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx > > SEM_FAILCRITICALERRORS = 1 > SEM_NOALIGNMENTFAULTEXCEPT = 4 > SEM_NOGPFAULTERRORBOX = 4 > SEM_NOOPENFILEERRORBOX = 8 > > import ctypes > from ctypes.wintypes import UINT > > SetErrorMode = ctypes.windll.kernel32.SetErrorMode > SetErrorMode.restype = UINT > SetErrorMode.argtypes = ( UINT,) > > Then putting: > > SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX ) > > at the start of you programme, should stop the "Critical Error" dialog > box you are seeing and you may get a chance to see a traceback. > > Rob. Hi Rob, thanks. I tried this, but did not work for me. henk-jan From hjebbers at gmail.com Sat Feb 13 05:49:01 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 02:49:01 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: On Feb 13, 11:03?am, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 12, 3:17 pm, Peter Otten <__pete... at web.de> wrote: > >> hjebbers wrote: > >> > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: > >> >> hjebbers wrote: > >> >> > On Feb 11, 5:45 pm, M3RT wrote: > >> >> >> The problem may be related to how you treat the EDI file or lets > >> >> >> say DATA. Also your coding style is important. Can you provide more > >> >> >> info? > > >> >> > Yes, a whole lot more; but I do not want to bother you with that > >> >> > now. I was just wondering if it is possible that the same setup > >> >> > gives a CRASH! on windows and just works on linux. > >> >> > (where is the bug?) > > >> >> In the platform-specific code ;) > > >> >> Even on alt.haruspicy they cannot do much without a liver now and > >> >> then... > > >> > if it is in the platform-specific code should I make this into a > >> > bugreport? > > >> A this stage a bug report would be useless. The details you have provided > >> so far don't give anyone without physical access to your machine a chance > >> to reproduce the error. > > >> > (because the crash does not appear at the same place in my code (when > >> > doing the same test-run) it will be quite hard to point down....) > > >> Indeed. The culprit may be an extension written in C that is overwriting > >> memory still in use by other parts of your program. > > >> Peter > > > No C extensions used. Definitely not. > > > As these crashes occur during stress tests, I go to the limits of the > > memory available. > > What strikes me is: > > 1. the crash on windows, but linux works OK (same test sets) > > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > > much). > > Random thoughts: > > If there were not enough memory Python should give a MemoryError rather than > segfault. > > Do both systems use the same memory layout (i. e. 32 or 64bit OS, 16 or 32 > bit unicode)? bot use 32bits; but the windows box uses 16 bits unicode, on linux 32bits unicode is used. the memory used by my program is for the larger part unicode strings. ....well, but that makes the better performance of linux even stranger... > > Try an alpha of Python 2.7. If you're lucky "your" bug was found 'n' fixed > independently. well...that's what I thought for version 2.6 ;-) (I run into this crash a longer time ago) but seriously, I'll try this. kind regards, henk-jan > > Peter From hjebbers at gmail.com Sat Feb 13 05:50:49 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 02:50:49 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> On Feb 13, 10:25?am, Dennis Lee Bieber wrote: > On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > declaimed the following in gmane.comp.python.general: > > > What strikes me is: > > 1. the crash on windows, but linux works OK (same test sets) > > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > > much). > > ? ? ? ? Which on its own does not mean much. > > ? ? ? ? Windows in a normal installation only grants 2GB address space to > user code, reserving the other 2GB space for the OS shared libraries. If > your program attempts to allocate over that, it will fail. That the > Windows box has twice the physical memory only means it doesn't resort > to page swapping as soon. > > ? ? ? ? There is a boot parameter switch that toggles Windows into a 3GB > user/1GB OS mode -- hey, that would be great!! on my 1,5G mahcine ;-) > it is mainly meant for server machines where there > won't be many disjoint OS libraries loaded, but the server applications > need lots of data space. > > ? ? ? ? What split does the Linux OS use? If it give 3GB to user space, > while you'd start to page swap much soon, you'd also have 50% more > virtual memory that can be allocated than under Windows. > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ I will check this.....any advice on how to check this? henk-jan From breamoreboy at yahoo.co.uk Sat Feb 13 06:02:24 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 11:02:24 +0000 Subject: Function attributes In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle > escribi?: > >> I posted an example of a decorator that does just this in this thread a >> couple of days ago: >> >> http://mail.python.org/pipermail/python-list/2010-February/1235742.html > > Ouch! I didn't see your post, nor several other earlier posts in this > thread. In fact, I thought mine was the *first* reply when I wrote it! > It's not just me then. I'm using Thunderbird on Windows Vista to view the group via gmane, and notice the earlier parts of a thread can show up hours or even days after the later ones. Would something who understands these things be kind enough to explain why this happens, or at least provide the keywords needed for google, as I haven't got a clue where to start. > Yes, of course, your code does exactly that without any bytecode hacks. > From hjebbers at gmail.com Sat Feb 13 06:03:02 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 03:03:02 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <007f26f3-5310-4ed9-bb25-b467fb248825@m35g2000prh.googlegroups.com> Message-ID: to all, thanks for the pointers so far. if you feel the need to reproduce the crash, it's not that hard, (downloading and installing my edi translator, install configuration (button-click), and run. I have a modified version (replace some *.py files) that eliminate a lot of stuff (simpler setup, no database used, no external C-modules). contact me for recipe and files about me being reluctant to 'show the code': - the crash that happens during stress tests. - the crash occurs not always, and at different points. - the code does runs OK on linux (which does not mean there's no bugt in it ;-) kind regards, henk-jan From deets at nospam.web.de Sat Feb 13 06:24:17 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 12:24:17 +0100 Subject: python crash on windows but not on linux In-Reply-To: <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> Message-ID: <7tngf2Fo5rU1@mid.uni-berlin.de> Am 13.02.10 11:50, schrieb hjebbers: > On Feb 13, 10:25 am, Dennis Lee Bieber wrote: >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers >> declaimed the following in gmane.comp.python.general: >> >>> What strikes me is: >>> 1. the crash on windows, but linux works OK (same test sets) >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as >>> much). >> >> Which on its own does not mean much. >> >> Windows in a normal installation only grants 2GB address space to >> user code, reserving the other 2GB space for the OS shared libraries. If >> your program attempts to allocate over that, it will fail. That the >> Windows box has twice the physical memory only means it doesn't resort >> to page swapping as soon. >> >> There is a boot parameter switch that toggles Windows into a 3GB >> user/1GB OS mode -- > > hey, that would be great!! on my 1,5G mahcine ;-) You don't get it - it's about the virtual memory address space available. This has nothing to do with physical memory. Obviously if the latter runs out, the swapping will make the machine painfully slow. But that's another issue. Diez From hjebbers at gmail.com Sat Feb 13 06:35:45 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 03:35:45 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> Message-ID: <0a5e5e0a-7b2c-40a9-a1d7-77a478bf88a0@q29g2000yqn.googlegroups.com> On Feb 13, 12:24?pm, "Diez B. Roggisch" wrote: > Am 13.02.10 11:50, schrieb hjebbers: > > > > > On Feb 13, 10:25 am, Dennis Lee Bieber ?wrote: > >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > >> declaimed the following in gmane.comp.python.general: > > >>> What strikes me is: > >>> 1. the crash on windows, but linux works OK (same test sets) > >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > >>> much). > > >> ? ? ? ? ?Which on its own does not mean much. > > >> ? ? ? ? ?Windows in a normal installation only grants 2GB address space to > >> user code, reserving the other 2GB space for the OS shared libraries. If > >> your program attempts to allocate over that, it will fail. That the > >> Windows box has twice the physical memory only means it doesn't resort > >> to page swapping as soon. > > >> ? ? ? ? ?There is a boot parameter switch that toggles Windows into a 3GB > >> user/1GB OS mode -- > > > hey, that would be great!! on my 1,5G mahcine ;-) > > You don't get it - it's about the virtual memory address space > available. This has nothing to do with physical memory. Obviously if the > latter runs out, the swapping will make the machine painfully slow. But > that's another issue. > > Diez Diez, you are right; I misunderstood. henk-jan From hjebbers at gmail.com Sat Feb 13 06:54:47 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 03:54:47 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> Message-ID: <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> I enlarged the windows page file from 750Kb to 1.5Gb . The crash still happens. btw, the crash does not happen at a peak memory usage. According to windows task manager, at the moment of crash mem usage of my program is 669kb, peak memory usage is 1.136kb henk-jan From alfps at start.no Sat Feb 13 07:14:58 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 13:14:58 +0100 Subject: python crash on windows but not on linux In-Reply-To: <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> Message-ID: * hjebbers: > I enlarged the windows page file from 750Kb to 1.5Gb . > The crash still happens. > btw, the crash does not happen at a peak memory usage. > According to windows task manager, at the moment of crash mem usage of > my program is 669kb, peak memory usage is 1.136kb > > henk-jan Probably you meant to write "M", not "k" or "K"? I've never managed to make much sense of the displays in Windows' Task Manager, if that's what you're using, but I think the mem usage it's displaying by default is the process' working set, or something very similar to that measure. You can display additional columns in Task Manager, and one useful one is how much virtual memory is allocated,. And perhaps then (if that's not what you're looking it already) it'll be closer to 2 GiB? Cheers & hth., - Alf From hjebbers at gmail.com Sat Feb 13 07:34:46 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 04:34:46 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: On Feb 13, 10:25?am, Dennis Lee Bieber wrote: > On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > declaimed the following in gmane.comp.python.general: > > > What strikes me is: > > 1. the crash on windows, but linux works OK (same test sets) > > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > > much). > > ? ? ? ? Which on its own does not mean much. > > ? ? ? ? Windows in a normal installation only grants 2GB address space to > user code, reserving the other 2GB space for the OS shared libraries. If > your program attempts to allocate over that, it will fail. That the > Windows box has twice the physical memory only means it doesn't resort > to page swapping as soon. > > ? ? ? ? There is a boot parameter switch that toggles Windows into a 3GB > user/1GB OS mode -- it is mainly meant for server machines where there > won't be many disjoint OS libraries loaded, but the server applications > need lots of data space. > > ? ? ? ? What split does the Linux OS use? If it give 3GB to user space, > while you'd start to page swap much soon, you'd also have 50% more > virtual memory that can be allocated than under Windows. > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ Hi Wulfraed, I tried this (the 3GB switch). But python still crashes. kind regards, henk-jan From davea at ieee.org Sat Feb 13 07:48:30 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 13 Feb 2010 07:48:30 -0500 Subject: python crash on windows but not on linux In-Reply-To: <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> Message-ID: <4B769F9E.6040402@ieee.org> hjebbers wrote: > On Feb 13, 10:25 am, Dennis Lee Bieber wrote: > >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers >> declaimed the following in gmane.comp.python.general: >> >> >>> What strikes me is: >>> 1. the crash on windows, but linux works OK (same test sets) >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as >>> much). >>> >> Which on its own does not mean much. >> >> Windows in a normal installation only grants 2GB address space to >> user code, reserving the other 2GB space for the OS shared libraries. If >> your program attempts to allocate over that, it will fail. That the >> Windows box has twice the physical memory only means it doesn't resort >> to page swapping as soon. >> >> There is a boot parameter switch that toggles Windows into a 3GB >> user/1GB OS mode -- >> > > hey, that would be great!! on my 1,5G mahcine ;-) > > > >> it is mainly meant for server machines where there >> won't be many disjoint OS libraries loaded, but the server applications >> need lots of data space. >> >> What split does the Linux OS use? If it give 3GB to user space, >> while you'd start to page swap much soon, you'd also have 50% more >> virtual memory that can be allocated than under Windows. >> -- >> Wulfraed Dennis Lee Bieber KD6MOG >> wlfr... at ix.netcom.com HTTP://wlfraed.home.netcom.com/ >> > > I will check this.....any advice on how to check this? > > henk-jan > > As I posted in recent thread on Tutor, But the one you might want is a boot.ini option that tells the OS to only reserve 1gb for itself, and leave 3gb for user space. But there are tradeoffs, including the need to modify an application's executable to take advantage of it. And the whole system may run substantially slower, even when your're extended app isn't running. See links: http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx http://blogs.technet.com/askperf/archive/2007/03/23/memory-management-demystifying-3gb.aspx DaveA From eadrogue at gmx.net Sat Feb 13 07:51:09 2010 From: eadrogue at gmx.net (Ernest =?iso-8859-1?Q?Adrogu=E9?=) Date: Sat, 13 Feb 2010 13:51:09 +0100 Subject: how do I write a scliceable class? Message-ID: <20100213125109.GA15741@doriath.local> Hello everybody, I'm designing a container class that supports slicing. The problem is that I don't really know how to do it. class MyClass(object): def __init__(self, input_data): self._data = transform_input(input_data) def __getitem__(self, key): if isinstance(key, slice): # return a slice of self pass else: # return a scalar value return self._data[key] The question is how to return a slice of self. First I need to create a new instance... but how? I can't use MyClass(self._data[key]) because the __init__ method expects a different kind of input data. Another option is out = MyClass.__new__(MyClass) out._data = self._data[key] return out But then the __init__ method is not called, which is undesirable because subclasses of this class might need to set some custom settings in their __init__ method. So what is there to do? Any suggestion? Cheers. Ernest From steve at holdenweb.com Sat Feb 13 08:14:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Feb 2010 08:14:29 -0500 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Mark Lawrence wrote: > Gabriel Genellina wrote: >> En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle >> escribi?: >> >>> I posted an example of a decorator that does just this in this thread a >>> couple of days ago: >>> >>> http://mail.python.org/pipermail/python-list/2010-February/1235742.html >> >> Ouch! I didn't see your post, nor several other earlier posts in this >> thread. In fact, I thought mine was the *first* reply when I wrote it! > > It's not just me then. I'm using Thunderbird on Windows Vista to view > the group via gmane, and notice the earlier parts of a thread can show > up hours or even days after the later ones. Would something who > understands these things be kind enough to explain why this happens, or > at least provide the keywords needed for google, as I haven't got a clue > where to start. > There are two main channels feeding the comp.lang.python newsgroup. Gmane is primarily a news (NNTP-based) service, though for reasons best know to the organizers they choose to rename the standard newsgroups to fit their own idea of how the universe should be organized, so there the group becomes gmane.comp.python.general. The first feed is the general interchange of articles between NNTP servers: while this is usually a reliable interchange mechanism, an individual server can "glitch" occasionally (by losing network connectivity, for example, or when some part of its news support mechanism breaks temporarily). The second is the python-list mailing list, maintained as a part of the python.org infrastructure (by a hard-working team of volunteers, I should add, who get little enough credit for the sterling work they do day in day out to keep the real information flowing and the spam out). More recently the waters have been muddied by Google Groups, which sadly seems at time to be so badly managed (or simply not managed?) as to make it a principal source of spam. This surprises me, as Gmail appears to have very effective spam filtering. Many people appear to use Google Groups as their primary interface to newsgroups and/or mailing lists to the extent that they believe the Groups interface to be what everyone uses to access the list. The task of maintaining a two-way bridge between the comp.lang.python NNTP community and the python-list email community while filtering out the spam and ensuring that posts aren't duplicated too often is a difficult one. For example, I hit "reply all" to your message, and had I not trimmed the headers my NNTP client (Thunderbird) would have sent copies to you, to the mailing list AND to the newsgroup. Sometimes such messages do appear twice, particularly (in my experience) to recipients who use the email channel. In short, these things happen because life is complicated and the technical solutions available to disambiguate the feeds aren't perfect. So you might consider filing the glitches under "shit happens". Speaking personally I wouldn't have a clue how to keep this stuff going on a daily basis at the volume level we see on this group, and I am very grateful to everyone who does. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Sat Feb 13 08:20:15 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 14:20:15 +0100 Subject: how do I write a scliceable class? In-Reply-To: References: Message-ID: * Ernest Adrogu?: > Hello everybody, > > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. I'd go for it anyway, because the programmer who subclasses needs to understand the base class. And if, say, that class has a custom _init method, and it's documented that that what's a subclass should override, then, OK. No problem. > So what is there to do? Any suggestion? An alternative can be to simply check for argument value None in the constructor, and if so, don't do anything. Cheers & hth., - Alf From deets at nospam.web.de Sat Feb 13 08:23:15 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 14:23:15 +0100 Subject: how do I write a scliceable class? In-Reply-To: References: Message-ID: <4B76A7C3.2030000@nospam.web.de> Am 13.02.10 13:51, schrieb Ernest Adrogu?: > Hello everybody, > > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. I'd say you can't have your cake and eat it. Either let the constructors work with data to produce whatever state the instance really contains. If that's the case, go with your second solution. Potentially, you need to make self._data[key] some method-call that might be overridden, something along the lines of __getstate__, to make sure subclasses return all data that is relevant to them. But if you really have child-class code that needs to be run on *every* object construction, then you should make input_data optional, and pass the transformed input in for the slice-creation, bypassing the transform_input. The only other solution I can think of is to return a MyClassSlice-instance, which is just a view to MyClass instances, and restricts e.g. key-spaces. class MyClassSlice(object): def __init__(self, state, slice): self.state = state self.slice = slice def __getitem__(self, key): if isinstance(key, slice): # create subslice & return that return MyClassSlice(self.state, merged_slice(key, self.slice)) elif self.key_in_slice(key): return self._state[key] raise IndexError def key_in_slice(self, key): # this of course depends on your key-domain. Diez From breamoreboy at yahoo.co.uk Sat Feb 13 08:23:33 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 13:23:33 +0000 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Steve Holden wrote: > Mark Lawrence wrote: >> Gabriel Genellina wrote: >>> En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle >>> escribi?: >>> >>>> I posted an example of a decorator that does just this in this thread a >>>> couple of days ago: >>>> >>>> http://mail.python.org/pipermail/python-list/2010-February/1235742.html >>> Ouch! I didn't see your post, nor several other earlier posts in this >>> thread. In fact, I thought mine was the *first* reply when I wrote it! >> It's not just me then. I'm using Thunderbird on Windows Vista to view >> the group via gmane, and notice the earlier parts of a thread can show >> up hours or even days after the later ones. Would something who >> understands these things be kind enough to explain why this happens, or >> at least provide the keywords needed for google, as I haven't got a clue >> where to start. >> > There are two main channels feeding the comp.lang.python newsgroup. > Gmane is primarily a news (NNTP-based) service, though for reasons best > know to the organizers they choose to rename the standard newsgroups to > fit their own idea of how the universe should be organized, so there the > group becomes gmane.comp.python.general. > > The first feed is the general interchange of articles between NNTP > servers: while this is usually a reliable interchange mechanism, an > individual server can "glitch" occasionally (by losing network > connectivity, for example, or when some part of its news support > mechanism breaks temporarily). > > The second is the python-list mailing list, maintained as a part of the > python.org infrastructure (by a hard-working team of volunteers, I > should add, who get little enough credit for the sterling work they do > day in day out to keep the real information flowing and the spam out). > > More recently the waters have been muddied by Google Groups, which sadly > seems at time to be so badly managed (or simply not managed?) as to make > it a principal source of spam. This surprises me, as Gmail appears to > have very effective spam filtering. Many people appear to use Google > Groups as their primary interface to newsgroups and/or mailing lists to > the extent that they believe the Groups interface to be what everyone > uses to access the list. > > The task of maintaining a two-way bridge between the comp.lang.python > NNTP community and the python-list email community while filtering out > the spam and ensuring that posts aren't duplicated too often is a > difficult one. For example, I hit "reply all" to your message, and had I > not trimmed the headers my NNTP client (Thunderbird) would have sent > copies to you, to the mailing list AND to the newsgroup. Sometimes such > messages do appear twice, particularly (in my experience) to recipients > who use the email channel. > > In short, these things happen because life is complicated and the > technical solutions available to disambiguate the feeds aren't perfect. > So you might consider filing the glitches under "shit happens". Speaking > personally I wouldn't have a clue how to keep this stuff going on a > daily basis at the volume level we see on this group, and I am very > grateful to everyone who does. > > regards > Steve Many thanks for the explanation. Kindest regards. Mark Lawrence From __peter__ at web.de Sat Feb 13 09:16:31 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Feb 2010 15:16:31 +0100 Subject: how do I write a scliceable class? References: Message-ID: Ernest Adrogu? wrote: > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. > > So what is there to do? Any suggestion? Either (1) make transform_input() idempotent, i. e. ensure that transform_input(transform_input(data)) == transform_input(data) and construct the slice with MyClass(self._data[key]) or (2) require it to be invertible with inverse_transform_input(transform_input(data)) == data and make the slice with MyClass(inverse_transform_input(self._data[key])) Just stating the obvious... Peter From eadrogue at gmx.net Sat Feb 13 09:53:20 2010 From: eadrogue at gmx.net (Ernest =?iso-8859-1?Q?Adrogu=E9?=) Date: Sat, 13 Feb 2010 15:53:20 +0100 Subject: how do I write a scliceable class? In-Reply-To: References: Message-ID: <20100213145320.GA16233@doriath.local> Hi, Thanks a lot for your comments. I think I've got enough information to make a decision now. 13/02/10 @ 15:16 (+0100), thus spake Peter Otten: > Ernest Adrogu? wrote: > > > I'm designing a container class that supports slicing. > > The problem is that I don't really know how to do it. > > > > class MyClass(object): > > def __init__(self, input_data): > > self._data = transform_input(input_data) > > def __getitem__(self, key): > > if isinstance(key, slice): > > # return a slice of self > > pass > > else: > > # return a scalar value > > return self._data[key] > > > > The question is how to return a slice of self. > > First I need to create a new instance... but how? I can't > > use MyClass(self._data[key]) because the __init__ method > > expects a different kind of input data. > > > > Another option is > > > > out = MyClass.__new__(MyClass) > > out._data = self._data[key] > > return out > > > > But then the __init__ method is not called, which is > > undesirable because subclasses of this class might need > > to set some custom settings in their __init__ method. > > > > So what is there to do? Any suggestion? > > Either > > (1) make transform_input() idempotent, i. e. ensure that > > transform_input(transform_input(data)) == transform_input(data) > > and construct the slice with MyClass(self._data[key]) > > or > > (2) require it to be invertible with > > inverse_transform_input(transform_input(data)) == data > > and make the slice with MyClass(inverse_transform_input(self._data[key])) > > Just stating the obvious... > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list From invalid at invalid.invalid Sat Feb 13 10:14:58 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 13 Feb 2010 15:14:58 +0000 (UTC) Subject: concatenate fasta file References: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Message-ID: On 2010-02-12, PeroMHC wrote: > Hi All, I have a simple problem that I hope somebody can help with. I > have an input file (a fasta file) that I need to edit.. > > Input file format > >>name 1 > tactcatacatac >>name 2 > acggtggcat >>name 3 > gggtaccacgtt > > I need to concatenate the sequences.. make them look like > >>concatenated > tactcatacatacacggtggcatgggtaccacgtt (echo "concantenated>"; grep '^ [actg]*$' inputfile | tr -d '\n'; echo) > outputfile -- Grant From aahz at pythoncraft.com Sat Feb 13 10:26:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 07:26:52 -0800 Subject: Create a backslash-escaped version of a string? References: Message-ID: In article , boblatest wrote: > >I'd like to have control characters in a string to be converted to >their backslash-escaped counterparts. I looked in the encoders section >of the string module but couldn't find anything appropriate. I could >write it myself but I'm sure something of the sort exists. The >hypothetical method "c_escaped()" would work like this: > >>>> a="abc\rdef" >>>> print a.c_escaped() >abc\rdef >>>> This is a little different from what you want, but just for the sake of completeness: >>> print repr(a)[1:-1] abc\rdef -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Sat Feb 13 10:31:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 07:31:03 -0800 Subject: Modifying Class Object References: Message-ID: In article , Steve Holden wrote: > >Whether in CPython, Jython or IronPython the value returned by calling >id(x) (whether x is a literal, a simple name or a more complex >expression) is absolutely no use as an accessor: it does not give you >access to the referenced value. > >If you disagree, please write (in any implementation you like: it need >not even be portable, though I can't imagine why ti wouldn't be) a >Python function which takes an id() value as its argument and returns >the value for which the id() value was provided. IIRC, I've seen ctypes code that uses id() to get access to the object, but (obviously) I don't think that invalidates your point[er]. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Sat Feb 13 10:40:29 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 07:40:29 -0800 Subject: Modifying Class Object References: <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On Fri, 12 Feb 2010 18:23:46 -0800 (PST), rantingrick > declaimed the following in >gmane.comp.python.general: >> >> This entire thread has imploded like a neutron star into an infantile >> debate that only Caddie Couric, Bill O Reilly, and everyone on PMS-NBC >> can hold a candle to! The only post i enjoyed was Steve Howes! > >{Hmm, I don't recall ever seeing a "rantingrick" on the group before... >could it be... a... "sockpuppet"?} Zie's been around a while. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From sparks.m at gmail.com Sat Feb 13 10:59:42 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Sat, 13 Feb 2010 07:59:42 -0800 (PST) Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Hi Alf, On Feb 12, 8:22 pm, "Alf P. Steinbach" wrote: > Thanks for the effort at non-flaming discussion, it *is* > appreciated. I would appreciate it if you tried to be non-flaming yourself, since you can see I am not flaming you. I was seeking to educate you on a simple matter which you seem to be misunderstanding in python. This will be my second and last attempt to do so since you chose to be inflammatory in your response. (In case you do not understand what I find inflammatory, I will discuss that at the end) Please note below I may use CAPS occasionally. Whilst usually taken as shouting, I mean them as BOLD. Please be aware of this :-) My reason for choosing to do reply is for the simple reason that recently I had similar discussions with a colleague who was likewise stuck talking about implementation aspects (call by reference/value rather than call with object/sharing). > > Before I start, note we're talking about semantics, not > > implementation. That distinction is very important. > > Yes. [ inflammatory comment snipped] Good - common ground - a good starting point. Now, if I define a language, this has 3 main parts: * Syntax * Semantics * Implementation The syntax of python is simply and shortly defined in a machine readable format, and is therefore not interesting to discuss here. The implementation of python is similarly well defined. There are multiple such implementations, one of which is CPython. > However, all those references to implementation aspects, > persisting [ inflammatory comment snipped] In theory when talking about a language, we do not need to talk about implementation details. However when using a language, implementation details do matter as well. That's why people talk about implementation aspects. When talking about how the language is defined, you need to talk about how the language is defined. It's not defined in terms of Java pointers or references. It's defined in terms of objects and names. (Or objects and labels) The exception to this is with pure functional language. In a pure functional language I do not care about implementation details, since they are outside the scope of the language. It is worth noting that python and functional languages share a common ethos - though with different conclusions - that optimising for the programmers expression of the problem rather than for the machine *matters*. If you miss this, you will be stuck misunderstanding python, pretty much forever. If you (the reader, not necessarily Alf) understand this, good. If you don't, you need to re-read this and really understand it. (please bear in mind when I say "YOU" in that paragraph, I mean "whomever is reading this", not anyone specific) Let's get down to brass tacks. In python, the LANGUAGE, there are no pointers or references, much like in SML, haskell and friends there are no pointers or references. I'm using SML here as an example, because it is conceptually close to python in terms to some aspects of evaluation and how it deals with names and values. (There are many differences as well, but we're dealing with calling, names & values, in which they are close enough) Taking an example from SML: structure Stk = struct exception EmptyStack; datatype 'x stack = EmptyStack | push of ('x * 'x stack); fun pop(push(x,y)) = y | pop EmptyStack = raise EmptyStack; fun top(push(x,y)) = x | top EmptyStack = raise EmptyStack; end; This may be used, say from the interactive prompt, as follows: val x = EmptyStack; (* 1 *) val 'x = x; (* 2 *) val y = push(5,'x); (* 3 *) val z = push(4,y); (* 4 *) top z; (* 5 *) Now, in this example, in SML, there are only names and values. Unlike python, all values are immutable, and theoretically, no sequencing of statements. Now line 1 takes the EmptyStack value, and the name x is bound to it. Line 2 takes that same EmptyStack value, and the name 'x is also bound to it. There are no pointers in SML, just names and values. Like python, SML has aliases. 'x for example is an alias for x. However that is just a symbolic name for the object itself. When line 3 is evaluated, the value push(5, 'x) is bound to the name y. Note - push(5, 'x) is in itself a value in SML, because it has been defined as such in the Datatype definition in the structure definition Stk. When we reach line 5, the function top is called with the value that z is bound to. Not a reference. Not a pointer. The actual value. In this case z's value is push(4,push(5,EmptyStack)). Thus the SML runtime evaluates the expression top push(4,push(5,EmptyStack)) And returns the value 4. In python, I don't have such richness of ability to define values, but I have these types play with: * numbers - 1.0 , 1, 1+2i, 0x11 0777 * strings - "hello" "world" * lists - ["hello", "world" ] * tuples - ("hello", "world") * dicts - {"hello" : "world" } All of these types are defined in python as python objects. How they are implemented is irrelevant. What is relevant is that lists and dicts are mutable. The rest are not. (This mutability, along with sequencing and iteration make python different from the pure subset of SML.) However, nonetheless when I type this: def hello(world): print world hello("world") When I call "hello", with the argument "world", the language is DEFINED, that *just like SML* I am passing in that specific object. Not a copy of a value (call by value). Not a reference to the value. Not a pointer to a value. But that specific actual object. This isn't willy nilly or on a whim, that's a concious choice. [ If this makes no sense, consider that python's history comes from a CS department like SML's does, rather than from an engineering department (ala C/C++/Java). Now you might turn around and say (since you have in the thread) "but in reality you're not _really_ passing in that object, you're passing in a reference", you're wrong. If the language defines it as passing in THAT object, then it defines it as passing in THAT object. But you can come back, as you have done, over and over and claim that it's a pointer or a reference, and may even say things like "well, according to this OTHER language's definition of this word, I mean this". That's nice, but ultimately broken. Using another languages way of defining something is wrong. In python it is *defined* as passing in the object. Not a reference. Not a pointer. The object itself. If it is a pointer or reference it has a value, and refers to a value. Essentially 2 values in 1. This is part of the accepted definition of pointer or reference. "A value that allows you to find another value". By claiming that in the below: >>> stack = () >>> stack_ = stack That stack is a reference to () and that stack_ is also a reference to () _in python the language_, then I must be able to get at the value of stack itself, and the value of stack_ itself. You claim to be able to do this thus: >>> id(stack) 3078742060L >>> id(stack_) 3078742060L On the surface of things, this sounds like a good claim, but it isn't. If it was a reference, its type would be a reference. It isn't: >>> type(id(stack)) >>> type(id(stack_)) That value is an integer. Additionally, if these "id" values were references, then I would be able to take those values and _inside the language_ retrieve the value they refer to. ie I would be able to type something like this to get this sort of behaviour: >>> refstack = id(stack) >>> refstack_ = id(stack_) >>> STACK = !refstack >>> STACK_ = !refstack_ >>> STACK () >>> STACK_ () This means one of two things: * Either "stack" by itself is a reference to (), but we cannot get at the reference itself, just the value it refers to. * OR "stack" is the preferred way of dereferencing the reference associated with stack, and to get at the actual reference we do id(stack). The problem is i) is incomplete in terms of being a reference, since we can only get at the r-value. The other one is that ii) is incomplete because we have no way of going from an l-value to an r-value. This means that *AS FAR AS THE LANGUAGE* is concerned whether the implementation looks or acts like it's implemented as call by reference or whatever, it is simpler and more correct to say that as far as the *LANGUAGE* is concerned, you pass in the object, which will be bound with a local name inside the function or method. Thus is is more correct to say that python the language only has aliases. By comparison, it's possible to demonstrate that Java does have references, because it is possible to box and unbox values to/from reference values: http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#190697 Thus whilst Java's semantics may be similar, python's differ in that Java, the language, has references and python, the language, has aliases. Now let's move to the implementation aspects. Python as a language is implemented in many languages. One of these is C. There are compilers to C (pypy), C++ (shedskin), for the JVM (Jython) and .net (Ironpython). There is also an executable operation semantics for python, which can be found here: http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ This set of operational semantics is written in Haskell. Haskell is a strictly pure, lazily evaluated language. It therefore has no pointers or references, just values and names. The implementation therefore cannot be in terms of references and pointers. Therefore to say "in reality the implementation will be passing a reference or pointer" is invalid. There is after all at least one implementation that does not rely on such machine oriented language details. What you find in terms of modelling the semantics, is that implementation is seeking to model those of the python virtual machine, and there that talks about values, objects, references and the heap. However in terms of modelling how the language is used this is not exposed at the language level. Indeed the only test it uses with regard to references involves the creation of a reference type _using_ python: class Reference(object) : pass Creating a reference: a = Ref() Setting the value the reference refers to: a.value = False Passing the reference to a function, and changing the value the reference: def bar(ref): ref.value = True bar(a) Whilst you might say "But that's wrong", note that .value on the right hand side is used for unboxing the value - it's syntactic sugar for a method call on the ref object. Specifically, it's the result of doing ref.__getattr__("value"). Likewise, ref.value on the left hand side of an equals is also syntactic sugar for boxing the value - specifically it's syntactic sugar for ref.__setattr__("value", ) That's the closest you can come to Java references in python - since otherwise you have no way to box or unbox any values. If you want to claim Python has java references with no ability to box or unbox any values, then maybe that's vaguely OK, but it's still _wrong_. You can claim it's LIKE java references, but since python doesn't have references, only aliases, you'd be wrong to claim they're the same as java references. And from a language spec - semantics, not implementation viewpoint - you'd also still be wrong because you can implement python without calling the values references. Specifically, the object model defined in src/Objects.lhs and src/ObjectTheory.lhs in the above reference operational semantics specification of python uses a functional heap to contain the objects. New objects are created there thus: rewrite (State ( heap ) envs stack ( FwApp (Prim "object" "__new__") (a_c:as) )) = (state ( heap <+> [a |-> ObjValue (new [__class__ |-> a_c]) NoneValue] ) envs stack ( BwResult a )) where a = freeAddr heap In this definition, which is compilable and executable (since it's haskell), there are no references, pointers or memory allocation. Thus to say that for this: def hello(world) print world hello("world") Saying that I *must* be passing in "world" by reference since implementation requires this, is false. In *an* implementation may do that, and indeed, it's the most obvious way of *implementing* it in many languages, but to say the language specifies it that way is incorrect. After all, in the Haskell implementation for example, the object itself is just passed in. ~~ interlude ~~ Now, if python DID add references, this would be pretty awesome because it's the most obvious way of adding in software transactional memory, since this usage of X.value is remarkably close to the way I deal with values in my implementation of software transactional memory for python which you'll find here: * http://www.kamaelia.org/STM And since python doesn't already have references, you wouldn't be changing existing semantics. This won't happen for a fair while at least for many reasons, not least the fact that there's a moratorium on language changes at present. ~~ end interlude ~~ Now if we return to CPython, we find that CPython is the most commonly used implementation of python. As a result much python code is written to work well with that implementation, rather than with any other. The CPython implementation has some limitations: * It is written in C * It cannot pass in actual objects (like haskell), only primitive values. * Therefore it has to pass in pointers to values to the parts of the subsystem that do the evaluation. * It has to track memory, and performs garbage collection. * Since it tracks garbage, it uses the parlance of garbage collection - specifically including references and reference counts. A reference count is however just a count of "who knows about this object and is keeping this alive") * All memory allocation lives in the heap, and as a result python objects sit there, and the implementation slings around pointers to these things. * Logically speaking (and at the language level), python objects may contain other objects. Specifically, a list may contain another object (or even itself). Both of these types of relationship cause the reference counts to increase. * The program running tracks the objects using names, and when an object stops being findable by another object (eg no longer in a list, and no longer labelled by someone), this is a trigger which the garbage collector can use to decide to delete the object. Given CPython is written in C, it becomes natural for CPython - the implementation - to therefore start talking about objects, pointers, references, reference counts and so on. Not only that since no programmer really likes memory leaks etc, actually knowing what the implementation is doing is *at times* useful to know. Since the language spec is tied up with a specific implementation, some of these details leak into the language of the document. So yes, as a pragmatic python programmer, I do care about reference counts. I do care about weakrefs which don't increase reference counts. I do care about when values are created and deleted. However, I only do so because of the *implementation* not because of the specification. When it comes to talking about the language, saying "it's pointers" over and over or saying "it's references" over and over or even saying "it's references/pointers as defined by java" over and over does NOT make it correct. If you move forward and accept that python THE LANGUAGE uses names and objects, and names are more like labels stuck onto objects than names of boxes that objects can sit inside, you'll move forward somewhat. If you don't, that's fine, but stating your version of "truth" as correct, when told many times you are incorrect is either ignorance, arrogance, pigheadedness or stupidity. I have chosen to believe it's ignorance, and assuming good faith. Now, I did say I'd pick out the inflammatory parts of how you've spoken to me, and I will just leave them as that. You will hopefully see how they're inflammatory and modify your behaviour in future. Please note though, I will pick out one point. I was not using Wikipedia as a means of argument by authority. I was using it as a starting point for a discussion which I thought many could use as a valid starting point - since whilst not perfect, and can be highly inaccurate in places, it does form one of the few places where people generally eventually reach some form of consensus. The fact that you've previously editted, fine. Good. That's very civic minded of you and I thank you for it. The idea that somehow bringing in an acceptable definition from some source that you've effectively stated you agree with as valid (because you've editted it), somehow invalidates the meat of my points I find a little bizarre. I'll put that down to cultural differences. Anyway, here's the points I find inflammatory, and rather than respond, I'll leave them as is. I'll also not be responding to any further mails containing inflammatory comments. You can think this stupid or annoying, but quite frankly, I don't see the point. Hopefully nothing I have said above you personally find inflammatory, if you do, I apologise in advance. I do hope that my mail has moved your understanding of python calling conventions on. I primarily do this because I hope that you do not pass on your misunderstandings as fact, when in fact they are not - because doing so would do others a disservice. Regards, Michael. Inflammatory comments (from my personal viewpoint) On Feb 12, 8:22 pm, "Alf P. Steinbach" wrote: > It would seem to readers that posters here do not grasp and are > unable to grasp that distinction. The posters here do understand that distinction. > However, all those references to implementation aspects, > persisting in the face of corrections, Stating something is a correction does not make that correction true. If I state it's call by sharing, and that happens to be the definition, then correcting me and calling it call by value or call by reference does not make that correction true. If you are told something repeatedly by many sources, perhaps consider you may be wrong. > have just, IMHO, been consistent attempts at misrepresentation. This can be taken as posters choosing to misrepresent your words, and is equivalent to the question "When did you stop beating your wife?", and equally offensive. > I'm sorry to disappoint, but no. It was a random Google hit to find > a first-year text that perhaps posters here could understand. You have been talking to many people who have been around python for sometime, including those who've worked on python's internals. Assuming that they need "educating" as CS101 students is offensive. > Not insinuiting anything about heir mental prowess or lack > thereof, No. It does - whether you like it or not. Communication is about 2 (or more) parties communicating. The sender of a message should care more about how their message is recieved than how it is sent. In my case, my goal of sending you a message was to educate. Your goal APPEARS to have the purpose of defending a position you hold strongly, to the extent of ignoring the effect on others. If you think "That's their problem", then I can just correct you, and then ignore you. If that's a misrepresentation of your goals, then maybe telling you is helpful. I don't know. I do know thoughI've made that sort of mistake in the past (not to anyone here, but I have done), and realised my mistake and been grown up enough to recognise my mistake and apologise. I feel you have made that mistake here. Whether you apologise is your call. I would. > but just something they might understand given a repeatedly > demonstrated inability to understand such basics, or even to > understand the concept of reference to a definition of a term. No, they do not agree with you. This is not the same as not understanding, or lacking the mental ability to understand "basic terms". If I said you lacked the ability to understand such basics of human interaction, you'd probably be rather offended. If, at the same time, I demonstrated a complete inability to understand such basics myself, you would find such remarks inflammatory. > Please do consider that my usage of the term "pointer" has > always, in this thread, including the first article I posted > in this thread, been with explicit reference to the Java > language spec's meaning. I understand this. What you seem to misunderstand is that others also understand this. They also understand that Pointer as viewed from the Java Language Spec *IS* a different concept. There may be similarities, but the fact that you can unbox and rebox a Java Reference (as per reference above), where you *cannot* in python because, well, you can't, IS a fundamentally different concept. Conceptually you pass in the object in python. Not the object. Java has to say you pass in a reference because Java has the concept of references which may be box and unbox values. > You may argue that those who wrote that language spec are > confused about things or whatever, but that's rather stretching > it, wouldn't you say? No it isn't, there's others who claim exactly the same thing about the Java Language Spec. In python, the language spec was written by those who wrote CPython, therefore their terms are clouded by concrete details. If they weren't, they'd use the term aliases more often. > So, this must be the most silly "argument by authority" > ever offered. This is inflammatory because you are deriding my premise as "silly" because you have chosen to not ask yourself *why* I chose to use that as a starting point, and then chose to ignore all my points and arguments, deriding it as "silly". That's rather inflammatory when someone is seeking to educate you in the hope of making it such that you understand better and those you come in contact with learn the correct semantics, rather than what you think the semantics are, despite being told otherwise. > I find that amusing and would have included a smiley except that > I think that that would incur further flames. Please not I have not flamed you. I have ignored your inflammatory remarks except to note how I find them inflammatory towards myself and others. The assumption that I would flame you I do actually find relatively offensive. I've stayed out of many flame wars for many years, and generally find that seeking to understand why the opposing side in an argument is saying what they do can actually often either resolve differences or lead to an agreement to disagree. Likewise I have tried to stay away from making suggestions as to how you should change your behaviour since that could be considered inflammatory by some. > It's no criticism of you; I do appreciate your effort, thanks. This comes across as dismissive, given you ignored the entire body of my mail, and decided to deride it as "silly". > And I reiterate that the meaning of "pointer" I have used is > the meaning in the Java language spec. This assumes I have not read the thread. I have. I read the statement above numerous times. I also however have read the Java Language Spec (you are not the only person to have done this of course), and do NOT agree with you. Indeed I can see usecases where *adding* references to python, the language, could be useful. However, since they're not there, I can't. > And that that's about semantics, not about implementation, > and not about C pointers or Pascal pointers or whatever else > that some would rather wish it was. Unfortunately, you have picked a language whose semantics for references include the concept of being able to box and unbox object references. You cannot do that in python. Boxing and unboxing references is just another term for referencing and dereferencing values. Again, something you can't do in python. Again, by ignoring the meat of my argument and reiterating your point, you come across as willfulling ignoring logical rational arguments put your way in as non-inflammatory was as possible, decrying all those who disagree with you as somehow stupid, misrepresentational or ignorant. By doing so, your mail as a whole is rather inflammatory, but I've decided to only send one mail in reply to you and then leave it at that. > In the following that I snipped you had good discussion except > for (as I could see) a fallacy-based denial of references > existing in Python. No, it's not denial, it's an understanding of programming languages borne from having used a wide variety of languages from Assembler (Z80, 6502, 6800), BASIC, pascal, C, C++, Java, COBOL, Occam, Fortran, Perl, Python, Ruby, E, SML, Haskell, Prolog, Lisp, and several others I've probably forgotten I've used now over well over a quarter of century of usage. I've used languages which are reference only, object only, value only, etc. My conclusion that python is call by object sharing is based on 8 years experience of using python, and changing my views from early on viewing it as pointers/references to understand that the semantics are much closer to that of an impure functional language where you pass complex objects *themselves* (from a _semantic_ perspective). To claim that I am in "denial", somehow implies that I am either inexperienced, stupid, or unwilling to call a hammer a hammer or a screwdriver a screwdriver. I'm not. I'm simply unwilling to call a hammer a screwdriver or call a screw a nail. > I don't think there's any point in discussing that further, > because it's evidently a religious matter where rational > arguments This is inflammatory, since you dismiss my arguments now as religious rather than rational. I find that moderately disgusting and offensive. > -- and I've tried a few You have not appeared to try to understand where my argument is coming from sadly, despite me doing the same for yours. You have dismissed my disagreement as religious, rather than seeking to understanding the rational argument you have been presented, and have not argued against it. I however am seeking to be precise, by choosing NOT to use terms like reference, because they are incorrect. > -- don't reach, in spite of the extreme triviality of the > subject matter. Far from being trivial, understanding that you cannot unbox "the value" of a python object is rather fundamental to the understanding of python. Understanding that you are passing around (logically speaking) the actual object explains for example why this style of coding confuses people when they start with python: >>> class MyObject(object): ... def __init__(self, store=[]): ... self.store = store ... def append(self, X): ... self.store.append(X) ... def pop(self): ... return self.store.pop() ... >>> X = MyObject() >>> Y = MyObject() >>> X.append(10) >>> Y.pop() 10 The misunderstanding that people have is that they assume that this: ... def __init__(self, store=[]): Results in a new empty object being created every time, whereas actually it's created at the point the def statement is run, specifically here: >>> MyObject.__init__.im_func.func_defaults ([],) The fact I can get *an* object id thus: >>> id(MyObject.__init__.im_func.func_defaults[0]) 3078510124L >>> id(X.store) 3078510124L >>> id(Y.store) 3078510124L Is pretty irrelevant. It's not a reference - it's an opaque value that happens to be useful when debugging for telling whether I've got the same object or not. Otherwise the objects themselves would have no default name, and no way of telling if THIS list is different fron THAT list. However, by understanding that the [] object is created when the def statement is evaluated and the object reused by all subsequent calls, rather than being created when the object is called explains much more clearly WHY the code works the way it does. Yes, you can make a similar argument in terms of references, and under the hood that's what happens with pointers to an empty list object stored on the heap. However, in terms of semantics, it's an actual python object, not a reference. After all python is a HUMAN oriented language, not a machine oriented language. A reference says "this thing over here". An object is a thing. The latter is more HUMAN, the former is machine oriented. > Thanks for the effort at non-flaming discussion, > it *is* appreciated. It does not appear that way, since you have chosen to assume that I don't understand the thrust of your arguments, rather than disagree with them. You have chosen to assume that my arguments are wrong and used or made for religious reasons rather than rational ones - such as the desire to be precise. I sincerely hope that my reply does not offend or inflame you, since that is not the intent. I do hope it educates you and puts into context the responses you have gained from others. After all, one simply shouting in a corner saying "YOU'RE ALL WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to understand what one is talking about does not tend to engender warm fluffy feelings or sentiments of authority towards such an individual. Be it me, you, or anyone else. At the moment, you appear to me to be engaging in such a behaviour. Now you don't know from Jack and probably don't care about my viewpoint, but I would really appreciate it if you would try not to be inflammatory in your response to this. (Since you do appear to also have a need to have the last word) Hoping this was useful on some level, Michael. From alfps at start.no Sat Feb 13 11:08:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 17:08:11 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Aahz: > In article , > Steve Holden wrote: >> Whether in CPython, Jython or IronPython the value returned by calling >> id(x) (whether x is a literal, a simple name or a more complex >> expression) is absolutely no use as an accessor: it does not give you >> access to the referenced value. >> >> If you disagree, please write (in any implementation you like: it need >> not even be portable, though I can't imagine why ti wouldn't be) a >> Python function which takes an id() value as its argument and returns >> the value for which the id() value was provided. > > IIRC, I've seen ctypes code that uses id() to get access to the object, Dino Viehland gave this code: Just for fun this works in IronPython 2.6: >>> >>> import clr >>> >>> clr.AddReference('Microsoft.Dynamic') >>> >>> from Microsoft.Scripting.Runtime import IdDispenser >>> >>> x = object() >>> >>> id(x) 43 >>> >>> IdDispenser.GetObject(43) >>> >>> IdDispenser.GetObject(43) is x True > but (obviously) I don't think that invalidates your point[er]. For my part I didn't think the above would be possible without enumerating all objects. I'm guessing that Steve didn't think so either. However, I seriously doubt that an agreement with my earlier statements of that was his point, considering the "if" above, which seems to imply to the reader that instead I'd argued what he's challenging. Perhaps Steve was just confused. My original statement, with reference to the Java language spec, didn't say much more about the language than that it has assignable references. It took a long time to get the wild horses reined in in that direction. But then two others ended up arguing that Python does not have references, with one of them maintaining that "refers to" in the language spec does not mean "refers to", but instead means "refers to", so I'm guessing it's religious, yes? Cheers, - Alf From as at sci.fi Sat Feb 13 11:18:15 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 13 Feb 2010 18:18:15 +0200 Subject: MemoryError, can I use more? References: Message-ID: Nobody writes: > A single process can't use much more than 2GiB of RAM without a 64-bit CPU > and OS. That's not really true. Even Windows XP has the /3GB boot option to allow 3 GiB per process. On PCs, free operating systems and server Windows can use PAE to give access to full 4 GB per process. From robert.kern at gmail.com Sat Feb 13 11:33:53 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 13 Feb 2010 10:33:53 -0600 Subject: how do I write a scliceable class? In-Reply-To: <20100213125109.GA15741@doriath.local> References: <20100213125109.GA15741@doriath.local> Message-ID: On 2010-02-13 06:51 , Ernest Adrogu? wrote: > Hello everybody, > > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. > > So what is there to do? Any suggestion? I highly recommend making __init__() constructors do as little computation as possible. You can add other constructors using @classmethod that do convenient transformations. -- 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 deets at nospam.web.de Sat Feb 13 11:40:21 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 17:40:21 +0100 Subject: MemoryError, can I use more? In-Reply-To: References: Message-ID: <7to2vmF2kvU1@mid.uni-berlin.de> Am 13.02.10 17:18, schrieb Anssi Saari: > Nobody writes: > >> A single process can't use much more than 2GiB of RAM without a 64-bit CPU >> and OS. > > That's not really true. Even Windows XP has the /3GB boot option to > allow 3 GiB per process. On PCs, free operating systems and server > Windows can use PAE to give access to full 4 GB per process. No, PAE can be used to access much more memory than 4GB - albeit through paging. AFAIK up to 2^36 Bytes. Diez From maligree at gmail.com Sat Feb 13 11:43:04 2010 From: maligree at gmail.com (Maligree) Date: Sat, 13 Feb 2010 08:43:04 -0800 (PST) Subject: threading and signals - main thread solely responsible for signal handling? Message-ID: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> The main part of my script is a function that does many long reads (urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to display some stats, I needed to run foo() as a seperate thread to avoid getting errno 4 (interrupted system call) errors (which occur if SIGINFO is received while urlopen is setting itself up/waiting for a response). This does the job, SIGINFO is handled without ever brutally interrupting urlopen. The problem is that after starting foo as a thread, my main thread has nothing left to do - unless it receives a signal, and I am forced to keep it in some sort of loop so that ANY signal handling can still occur. I thought I'd just occupy it with a simple while 1: pass loop but that, unfortunately, means 100% CPU usage. Is there any way I could put the main thread to sleep? Or perhaps my approach is totally wrong? From bblais at bryant.edu Sat Feb 13 12:01:36 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Feb 2010 12:01:36 -0500 Subject: multiprocessing and games Message-ID: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> Hello, I've been thinking about implementing some simple games, where one can program agents to play the game. I thought that the multiprocessing module would be perfect for it, organized with a main simulator engine spawning processes for each agent. However, I am having trouble wrapping my head around the organization of the code. I haven't found a lot of examples of using multiprocessing, and no game implementations. There are two types of games that I would like to implement. In both cases, I'd like to be able to run something like: results=Sim.run('agent1.py','agent2.py') where the Sim object is initialized before with the board size, placement of pieces, etc... The files agent1.py and agent2.py would have the code to run the agent. The two types of games are different in terms of the organization of the agent code. In the first, which I think should be more straightforward, there will be one function defined in the file with syntax like: def agent(board,my_player_number): # stuff here for the agent return move Think "tic-tac-toe" here. The simulator would have to spawn processes, which load these files and handle the communication to the main simulator. The main simulator would loop through the agents, get moves, and then update the board with these moves. In the case of tic-tac-toe, then each agent is called in serial, and the update after each move. In the case of something like Civilization or Tron, the moves are all collected and then the board is updated. The other type of game, which would work like Tron or Civilization, the agent file would not contain a function but a list of commands, like: North() North() if Neighbor['North']: East() # etc... I am not sure what the best way to organize the code, in either case, for the main simulator or the best way to use multiprocessing here. I thought that maybe Pipe would be the best choice, and for each move there would be a send() and recv() between each agent and the main simulator, where the agent would receive updated information after each move. What happens if an agent has an infinite loop (ignores a signal from the simulator that it has lost)? Can the simulator catch this, and kill the process? Does that happen if either side closes the pipe? Is there an obvious way to structure this sort of game engine? Is there an implementation already out there that I am reinventing? What information would be best to send to the agent? I was finding myself using more global variables than I was comfortable, so I figured I was thinking about this incorrectly. Any help would be great! Pointers to other examples of using multiprocessing, especially with games, would be fantastic. thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Feb 13 12:02:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Feb 2010 17:02:53 +0000 Subject: threading and signals - main thread solely responsible for signal handling? In-Reply-To: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> References: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> Message-ID: <4B76DB3D.9010603@mrabarnett.plus.com> Maligree wrote: > The main part of my script is a function that does many long reads > (urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to > display some stats, I needed to run foo() as a seperate thread to > avoid getting errno 4 (interrupted system call) errors (which occur if > SIGINFO is received while urlopen is setting itself up/waiting for a > response). This does the job, SIGINFO is handled without ever brutally > interrupting urlopen. > > The problem is that after starting foo as a thread, my main thread has > nothing left to do - unless it receives a signal, and I am forced to > keep it in some sort of loop so that ANY signal handling can still > occur. I thought I'd just occupy it with a simple while 1: pass loop > but that, unfortunately, means 100% CPU usage. > > Is there any way I could put the main thread to sleep? Or perhaps my > approach is totally wrong? > The simplest fix is to call time.sleep(seconds) in the loop. Repeated sleeps of 1 second, for example, consume very little CPU time. From exarkun at twistedmatrix.com Sat Feb 13 12:22:26 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sat, 13 Feb 2010 17:22:26 -0000 Subject: threading and signals - main thread solely responsible for signal handling? In-Reply-To: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> References: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> Message-ID: <20100213172226.26099.213963272.divmod.xquotient.1291@localhost.localdomain> On 04:43 pm, maligree at gmail.com wrote: >The main part of my script is a function that does many long reads >(urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to >display some stats, I needed to run foo() as a seperate thread to >avoid getting errno 4 (interrupted system call) errors (which occur if >SIGINFO is received while urlopen is setting itself up/waiting for a >response). This does the job, SIGINFO is handled without ever brutally >interrupting urlopen. > >The problem is that after starting foo as a thread, my main thread has >nothing left to do - unless it receives a signal, and I am forced to >keep it in some sort of loop so that ANY signal handling can still >occur. I thought I'd just occupy it with a simple while 1: pass loop >but that, unfortunately, means 100% CPU usage. > >Is there any way I could put the main thread to sleep? Or perhaps my >approach is totally wrong? I don't think those two options are mutually exclusive. ;) MRAB suggested you time.sleep() in a loop, which is probably fine. However, if you want to have even /less/ activity than that in the main thread, take a look at signal.pause(). Also, perhaps not terribly interesting, signal.siginterrupt() was recently introduced, which will let you avoid EINTR if SIGINFO is received while urlopen is in a syscall (but will also prevent the signal from being handled until the syscall returns on its own). And there's always Twisted & friends. :) Jean-Paul From python at mrabarnett.plus.com Sat Feb 13 12:54:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Feb 2010 17:54:33 +0000 Subject: multiprocessing and games In-Reply-To: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> References: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> Message-ID: <4B76E759.3010503@mrabarnett.plus.com> Brian Blais wrote: > Hello, > > I've been thinking about implementing some simple games, where one can > program agents to play the game. I thought that the multiprocessing > module would be perfect for it, organized with a main simulator engine > spawning processes for each agent. However, I am having trouble > wrapping my head around the organization of the code. I haven't found a > lot of examples of using multiprocessing, and no game implementations. > > There are two types of games that I would like to implement. In both > cases, I'd like to be able to run something like: > > results=Sim.run('agent1.py','agent2.py') > > where the Sim object is initialized before with the board size, > placement of pieces, etc... The files agent1.py and agent2.py would > have the code to run the agent. The two types of games are different in > terms of the organization of the agent code. In the first, which I > think should be more straightforward, there will be one function defined > in the file with syntax like: > > def agent(board,my_player_number): > # stuff here for the agent > return move > > Think "tic-tac-toe" here. The simulator would have to spawn processes, > which load these files and handle the communication to the main > simulator. The main simulator would loop through the agents, get moves, > and then update the board with these moves. In the case of tic-tac-toe, > then each agent is called in serial, and the update after each move. In > the case of something like Civilization or Tron, the moves are all > collected and then the board is updated. > > The other type of game, which would work like Tron or Civilization, the > agent file would not contain a function but a list of commands, like: > > North() > North() > if Neighbor['North']: > East() > # etc... > > I am not sure what the best way to organize the code, in either case, > for the main simulator or the best way to use multiprocessing here. I > thought that maybe Pipe would be the best choice, and for each move > there would be a send() and recv() between each agent and the main > simulator, where the agent would receive updated information after each > move. What happens if an agent has an infinite loop (ignores a signal > from the simulator that it has lost)? Can the simulator catch this, and > kill the process? Does that happen if either side closes the pipe? Is > there an obvious way to structure this sort of game engine? Is there an > implementation already out there that I am reinventing? What > information would be best to send to the agent? I was finding myself > using more global variables than I was comfortable, so I figured I was > thinking about this incorrectly. > > > Any help would be great! Pointers to other examples of using > multiprocessing, especially with games, would be fantastic. > Forget about global variables, they're not worth it! :-) Think in terms of messages, sent via pipes, sockets or multiprocessing queues. In a game like "tic-tac-toe" (also known as "noughts and crosses", BTW), the sim sends a message to an agent requesting a move ("what's your move"). The agent can send requests for the state of the board ("what's at position (x, y)?") and get replies ("it's a X"/"it's a O"/"it's empty"), but at some point it must send the sim its move ("put a piece at (x, y)") and the sim can say whether it's valid ("OK"/"bad move"). If the agent takes too long then the sim sends just tells the agent that it took too long and should quit ("quit"). From as at sci.fi Sat Feb 13 13:52:41 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 13 Feb 2010 20:52:41 +0200 Subject: MemoryError, can I use more? References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" writes: > Am 13.02.10 17:18, schrieb Anssi Saari: >> Nobody writes: >> >>> A single process can't use much more than 2GiB of RAM without a 64-bit CPU >>> and OS. >> >> That's not really true. Even Windows XP has the /3GB boot option to >> allow 3 GiB per process. On PCs, free operating systems and server >> Windows can use PAE to give access to full 4 GB per process. > > No, PAE can be used to access much more memory than 4GB - albeit > through paging. AFAIK up to 2^36 Bytes. That too. I admit, after checking, that you can't go above 3 GiB per process even in server Windows. But for Linux there exists (or existed, since it seems it hasn't been updated since 2004) a kernel patch which provides a "4GB/4GB" address split. Kernel is in one segment, userland in another and hence a process can access full 4GB. From m.faustino at gmail.com Sat Feb 13 14:31:47 2010 From: m.faustino at gmail.com (=?ISO-8859-1?Q?M=E1rcio_Faustino?=) Date: Sat, 13 Feb 2010 11:31:47 -0800 (PST) Subject: MemoryError in imaplib? Message-ID: <79bafa50-1f13-4b7a-9f3b-937cb2860c80@d37g2000yqa.googlegroups.com> Hi, When using "imaplib" to fetch e-mail messages, the "IMAP4_SSL.read" and "IMAP4_SSL.readline" functions sometimes throw a "MemoryError" exception in "chunks.append(data)" and "line.append(char)", respectively. But if I change those functions to use instead a "cStringIO" buffer object, then that exception doesn't get thrown. Is this normal? I've seen this happen with Python 2.6.4 in both Windows XP 32-bit and Windows 7 64-bit. Thanks, From gnarlodious at gmail.com Sat Feb 13 14:46:26 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 13 Feb 2010 11:46:26 -0800 (PST) Subject: Py3: Terminal or browser output? Message-ID: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Hello, searched all over but no success. I want to have a script output HTML if run in a browser and plain text if run in a Terminal. In Python 2, I just said this: if len(sys.argv)==True: and it seemed to work. Py3 must have broken that by sending a list with the path to the script in BOTH the browser and Terminal. Is there some newfangled way to determine what is running the script (hopefully without a try wrapper)? -- Gnarlie From news123 at free.fr Sat Feb 13 14:55:05 2010 From: news123 at free.fr (News123) Date: Sat, 13 Feb 2010 20:55:05 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows In-Reply-To: <4b6e0841$0$22047$426a74cc@news.free.fr> References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> <4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: <4b77039a$0$12387$426a74cc@news.free.fr> Hi Gabriel, News123 wrote: > Hi Gabriel, > > Gabriel Genellina wrote: >> En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: >> >>> I'm using an XMLRPC server under Windows. >>> >>> What I wonder is how I could create a server, that can be killed with >>> CTRL-C >>> >>> The server aborts easily with CTRL-BREAK but not with CTRL-C (under >>> Windows) >>> >>> If I press CTRL-C it will only abort when the next RPC call occurs. >>> It seems it is blocking in the select() call in the handle_request() >>> function. >> Python 2.6 and up behaves exactly as you want. >> On previous versions you may use this: >> >> class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): >> >> ... your methods ... >> >> if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): >> >> # pre 2.6 >> quit = False >> >> def serve_forever(self): >> while not self.quit: >> self.handle_request() >> >> def shutdown(self): >> self.quit = True >> >> def server_bind(self): >> self.socket.settimeout(1.0) >> SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) >> > > Overloading server_bind() with your version solved my problem. > Overloading server_bind() makes the server killable with ctrl-C. I noticed however, that I can't use this as solution. If the bind function sets a time out, then it seems, that there are regular small time windows, when connecting clients fail. I don't have the error message any more, but will post it when I capture the event next time. bye N From mattbarkan at gmail.com Sat Feb 13 15:03:28 2010 From: mattbarkan at gmail.com (galileo228) Date: Sat, 13 Feb 2010 12:03:28 -0800 (PST) Subject: python and http POST References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <12f5dcf0-74aa-4c10-960e-90946d1ed853@b18g2000vba.googlegroups.com> Thank you all for your responses, and Javier thank you for your longer response. I've just downloaded mechanize and beautifulsoup and will start to play around. >From a pure learning standpoint, however, I'd really like to learn how to use the python post method (without mechanize) to go to a webpage, fill in a form, click 'submit', follow the redirect to the results page, and download content. For example, if I go to google.com, use firebug and click on the search bar, the following HTML is highlighted: So if I were to use the 'post' method, how can I tell from the code above what the ID of the searchbar is? Is it 'value', 'name', or neither? Assuming that the ID is 'name', then to search google for the term 'olypmics' would the proper code be: import httplib2 import urllib data = {'q':'olympics'} body = urllib.urlencode(data) h = httplib2.Http() resp, content = h.request("http://www.google.com", method="POST", body=body) print content; Does content return the content of the 'search results' page? And if not, how do I tell python to do that? Finally, must I transmit headers, or are they optional? Thanks all for your continued help! Matt On Feb 12, 2:59?am, Javier Collado wrote: > Hello, > > I haven't used httplib2, but you can certainly use any other > alternative to send HTTP requests: > - urllib/urllib2 > - mechanize > > With regard to how do you find the form you're looking for, you may: > - create the HTTP request on your own with urllib2. To find out what > variables do you need to post, you can use tamperdata Firefox addon as > suggested (I haven't used that one) or httpfox (I have and it works > great). > - use mechanize to locate the form for you, fill the data in and click > on the submit button. > > Additionally, you may wan to scrape some data that may be useful for > your requests. For that BeautifulSoup is good solution (with some > Firebug help to visually locate what you're looking for). > > Best regards, > ? ? Javier > > P.S. Some examples here:http://www.packtpub.com/article/web-scraping-with-pythonhttp://www.packtpub.com/article/web-scraping-with-python-part-2 > > 2010/2/11 galileo228 : > > > Hey All, > > > Been teaching myself Python for a few weeks, and am trying to write a > > program that will go to a url, enter a string in one of the search > > fields, submit the search, and return the contents of the search > > result. > > > I'm using httplib2. > > > My two particular questions: > > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > > how do I know what the particular key should be? In other words, how > > do I tell python which form on the web page I'm visiting I'd like to > > fill in? Do I simply go to the webpage itself and look at the html > > source? But if that's the case, which tag tells me the name of the > > key? > > > 2) Even once python fills in the form properly, how can I tell it to > > 'submit' the search? > > > Thanks all! > > > Matt > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From clp2 at rebertia.com Sat Feb 13 15:16:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Feb 2010 12:16:20 -0800 Subject: Py3: Terminal or browser output? In-Reply-To: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: <50697b2c1002131216v4ab1e695x1e082e017f6a4fb2@mail.gmail.com> On Sat, Feb 13, 2010 at 11:46 AM, Gnarlodious wrote: > Hello, searched all over but no success. I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. > In Python 2, I just said this: > > if len(sys.argv)==True: That line doesn't make sense really as it is practically equivalent to: if len(sys.argv) == 1: Which, since argv always contains at least 1 element (the program's name), is essentially checking whether /no/ arguments were passed on the command line. Recall that issubclass(bool, int) is true and that True == 1 in Python due to details of said subclassing. Note also that "== True" is almost always unnecessary as it is essentially implicit in the "if". I suspect you instead meant to write: if len(sys.argv) > 0: which for the record can be written more idiomatically as: if sys.argv: # bool(some_list) is True if some_list is not empty Which, however, as I explained, is always true since argv is /never/ completely empty, and thus the test is useless. What you probably *wanted* is: if len(sys.argv) > 1: Which is effectively the opposite of my very first code snippet and checks whether we /were/ passed some arguments on the command line. > and it seemed to work. By happy accident I suspect, due to the aforementioned way == works between bools and ints and probably a logic error in your code. > Py3 must have broken that by sending a list > with the path to the script in BOTH the browser and Terminal. Is there > some newfangled way to determine what is running the script (hopefully > without a try wrapper)? How exactly are you running the script *"in"* the browser? Browsers can only execute JavaScript, not Python. Do you mean you're running it via a webserver? If so, there are /several/ possible ways of doing that, please explain exactly which you are using. Cheers, Chris -- http://blog.rebertia.com From mattbarkan at gmail.com Sat Feb 13 15:16:38 2010 From: mattbarkan at gmail.com (galileo228) Date: Sat, 13 Feb 2010 12:16:38 -0800 (PST) Subject: python and http POST References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <29a9914f-e5f4-4a18-93fb-3b032aebac4b@d34g2000vbl.googlegroups.com> Thank you all for your responses, and Javier thank you for your longer response. I've just downloaded mechanize and beautifulsoup and will start to play around. >From a pure learning standpoint, however, I'd really like to learn how to use the python post method (without mechanize) to go to a webpage, fill in a form, click 'submit', follow the redirect to the results page, and download content. For example, if I go to google.com, use firebug and click on the search bar, the following HTML is highlighted: So if I were to use the 'post' method, how can I tell from the code above what the ID of the searchbar is? Is it 'value', 'name', or neither? Assuming that the ID is 'name', then to search google for the term 'olypmics' would the proper code be: import httplib2 import urllib data = {'q':'olympics'} body = urllib.urlencode(data) h = httplib2.Http() resp, content = h.request("http://www.google.com", method="POST", body=body) print content; Does content return the content of the 'search results' page? And if not, how do I tell python to do that? Finally, must I transmit headers, or are they optional? Thanks all for your continued help! Matt On Feb 12, 2:59?am, Javier Collado wrote: > Hello, > > I haven't used httplib2, but you can certainly use any other > alternative to send HTTP requests: > - urllib/urllib2 > - mechanize > > With regard to how do you find the form you're looking for, you may: > - create the HTTP request on your own with urllib2. To find out what > variables do you need to post, you can use tamperdata Firefox addon as > suggested (I haven't used that one) or httpfox (I have and it works > great). > - use mechanize to locate the form for you, fill the data in and click > on the submit button. > > Additionally, you may wan to scrape some data that may be useful for > your requests. For that BeautifulSoup is good solution (with some > Firebug help to visually locate what you're looking for). > > Best regards, > ? ? Javier > > P.S. Some examples here:http://www.packtpub.com/article/web-scraping-with-pythonhttp://www.packtpub.com/article/web-scraping-with-python-part-2 > > 2010/2/11 galileo228 : > > > Hey All, > > > Been teaching myself Python for a few weeks, and am trying to write a > > program that will go to a url, enter a string in one of the search > > fields, submit the search, and return the contents of the search > > result. > > > I'm using httplib2. > > > My two particular questions: > > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > > how do I know what the particular key should be? In other words, how > > do I tell python which form on the web page I'm visiting I'd like to > > fill in? Do I simply go to the webpage itself and look at the html > > source? But if that's the case, which tag tells me the name of the > > key? > > > 2) Even once python fills in the form properly, how can I tell it to > > 'submit' the search? > > > Thanks all! > > > Matt > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From deets at nospam.web.de Sat Feb 13 15:17:15 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 21:17:15 +0100 Subject: Py3: Terminal or browser output? In-Reply-To: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: <7tofmbFdmjU1@mid.uni-berlin.de> Am 13.02.10 20:46, schrieb Gnarlodious: > Hello, searched all over but no success. I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. > In Python 2, I just said this: > > if len(sys.argv)==True: > > and it seemed to work. Py3 must have broken that by sending a list > with the path to the script in BOTH the browser and Terminal. Is there > some newfangled way to determine what is running the script (hopefully > without a try wrapper)? I have no idea what you mean by "running python in a browser". I can only guess you mean as cgi or mod_python-skript? However, maybe if os.isatty(sys.stdout.fileno()): works for you. Or you could check for certain environment variables that are present when running as CGI or mod_python skript, but not knowing *what* you do can only lead to educated guesses at best. Diez From timr at probo.com Sat Feb 13 15:29:45 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 13 Feb 2010 12:29:45 -0800 Subject: How to measure elapsed time under Windows? References: Message-ID: <1n2en51qqliplc2u8q78l3gt2dn3vmeh8d@4ax.com> "Gabriel Genellina" wrote: > >The original problem was with the RDTSC instruction on multicore CPUs; >different cores may yield different results because they're not >synchronized at all times. Not true. The synchronization issue has two causes: initial synchronization at boot time, and power management making microscopic adjustments to the clock rate. In Windows NT 4, Microsoft took extra pains to adjust the cycle counters on multiprocessor computers during boot so that the processors started out very close together. Once set, they naturally remained in lock step, until aggressive power management because more prevalent. In XP, they stopped trying to align at boot time. >Windows XP was launched in 2001, and the first dual core processors able >to execute Windows were AMD Opteron and IBM Pentium D, both launched >around April 2005 (and targeting the server market, not the home/desktop >market of Windows XP). >How could MS know in 2001 of a hardware issue that would happen four years >in the future? No, you're underestimating the problem. The issue occurs just as much in machines with multiple processor chips, which was supported clear back in the original NT 3.1, 1992. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gnarlodious at gmail.com Sat Feb 13 15:34:36 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 13 Feb 2010 12:34:36 -0800 (PST) Subject: Py3: Terminal or browser output? References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> <7tofmbFdmjU1@mid.uni-berlin.de> Message-ID: On Feb 13, 1:17?pm, "Diez B. Roggisch" wrote: > However, maybe > > if os.isatty(sys.stdout.fileno()): OK, this works in Python 2: #!/usr/bin/python import sys, os if __name__=="__main__": if os.isatty(sys.stdout.fileno()): print "Terminal" else: print "Content-type:text/html\n\nBROWSER" likewise in Python3: #!/usr/local/bin/python3.1 import sys, os if __name__=="__main__": if os.isatty(sys.stdout.fileno()): print("Terminal") else: print("Content-type:text/html\n\nBROWSER") Thank you, always impressed with the fast help here. -- Gnarlie From mattbarkan at gmail.com Sat Feb 13 15:37:57 2010 From: mattbarkan at gmail.com (galileo228) Date: Sat, 13 Feb 2010 12:37:57 -0800 (PST) Subject: python and http POST References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <5df948ae-db27-4dc4-9ceb-c0777fca7678@28g2000vbf.googlegroups.com> Thank you all for your responses, and Javier thank you for your longer response. I've just downloaded mechanize and beautifulsoup and will start to play around. >From a pure learning standpoint, however, I'd really like to learn how to use the python post method (without mechanize) to go to a webpage, fill in a form, click 'submit', follow the redirect to the results page, and download content. For example, if I go to google.com, use firebug and click on the search bar, the following HTML is highlighted: So if I were to use the 'post' method, how can I tell from the code above what the ID of the searchbar is? Is it 'value', 'name', or neither? Assuming that the ID is 'name', then to search google for the term 'olypmics' would the proper code be: import httplib2 import urllib data = {'q':'olympics'} body = urllib.urlencode(data) h = httplib2.Http() resp, content = h.request("http://www.google.com", method="POST", body=body) print content; Does content return the content of the 'search results' page? And if not, how do I tell python to do that? Finally, must I transmit headers, or are they optional? Thanks all for your continued help! Matt On Feb 12, 2:59?am, Javier Collado wrote: > Hello, > > I haven't used httplib2, but you can certainly use any other > alternative to send HTTP requests: > - urllib/urllib2 > - mechanize > > With regard to how do you find the form you're looking for, you may: > - create the HTTP request on your own with urllib2. To find out what > variables do you need to post, you can use tamperdata Firefox addon as > suggested (I haven't used that one) or httpfox (I have and it works > great). > - use mechanize to locate the form for you, fill the data in and click > on the submit button. > > Additionally, you may wan to scrape some data that may be useful for > your requests. For that BeautifulSoup is good solution (with some > Firebug help to visually locate what you're looking for). > > Best regards, > ? ? Javier > > P.S. Some examples here:http://www.packtpub.com/article/web-scraping-with-pythonhttp://www.packtpub.com/article/web-scraping-with-python-part-2 > > 2010/2/11 galileo228 : > > > Hey All, > > > Been teaching myself Python for a few weeks, and am trying to write a > > program that will go to a url, enter a string in one of the search > > fields, submit the search, and return the contents of the search > > result. > > > I'm using httplib2. > > > My two particular questions: > > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > > how do I know what the particular key should be? In other words, how > > do I tell python which form on the web page I'm visiting I'd like to > > fill in? Do I simply go to the webpage itself and look at the html > > source? But if that's the case, which tag tells me the name of the > > key? > > > 2) Even once python fills in the form properly, how can I tell it to > > 'submit' the search? > > > Thanks all! > > > Matt > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From rogerb at rogerbinns.com Sat Feb 13 17:19:17 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Sat, 13 Feb 2010 14:19:17 -0800 Subject: Py3: Terminal or browser output? In-Reply-To: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gnarlodious wrote: > I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. You may also want to look into urwid. It provides you with a text console interface but can also provide HTML. It has widgets like text boxes, lists, tick boxes etc. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkt3JWUACgkQmOOfHg372QRifACfYKS7+bmt6F3WPXYatM7yKVcs knMAoLx5sJ3lFmofrrgHaS3aYOBAun0d =Nxd4 -----END PGP SIGNATURE----- From bblais at bryant.edu Sat Feb 13 17:32:15 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Feb 2010 17:32:15 -0500 Subject: multiprocessing and games In-Reply-To: <4B76E759.3010503@mrabarnett.plus.com> References: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> <4B76E759.3010503@mrabarnett.plus.com> Message-ID: <694A55DA-6557-486A-A0D5-B3B19C8B2D6F@bryant.edu> On Feb 13, 2010, at 12:54 , MRAB wrote: > Brian Blais wrote: >> I've been thinking about implementing some simple games > Forget about global variables, they're not worth it! :-) > > Think in terms of messages, sent via pipes, sockets or multiprocessing > queues. > okay...let's make this concrete. given your ideas, I have it working for the first type of agent, namely one that is called like: move=agent(board,player) For a specific example, I'm using the simplest version of a game called Nim. You start with a number of sticks, players take turns taking 1, 2, or 3 sticks, and you lose if you take the last stick. Two agents for this are: # agent1.py - simple take 1 agent def agent(board,player): return 1 # agent2.py - perfect player def agent(board,player): move=(board-1)%4 if move==0: return 1 else: return move I run my simulator like (complete code below): s=Sim('agent1','agent2') winner=s.run() and it spawns two processes, passes messages between the sim and the agents, and closes the agents nicely when the game is over. I'm not sure how I catch errors in the agents, especially accidental infinite loops. Now the second type of agent is structured differently. I'd like something like: # agent3.py - simple take 1 agent def agent(state): while True: Take(1) # agent4.py - perfect player def agent(state): N=state['board'] # get the current information while True: move=(N-1)%4 if move==0: Take(1) else: Take(move) I tried to implement this in the second wrapper below, but I can't get the agent function to "see" local functions in the wrapper. I probably need an import somewhere, but I haven't quite figured out the scoping with multiprocessing, etc... I include the code below. The two message-passing wrappers are there, and it works for the first two agents, but not the second two because of scoping issues. Is there a better way to be doing this? Are there other examples like this that I can look at to improve what I am doing? thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ # testing multiprocessing with games from __future__ import with_statement from multiprocessing import Pipe,Process def wrap_agent(connection,fname): agent_module = __import__(fname) end=False while not end: state=connection.recv() if state['done']: break move=agent_module.agent(state['board'],state['player']) connection.send(move) print "%s done" % fname connection.close() def wrap_agent2(connection,fname): def Take(T): state1=connection.recv() state.update(state1) if state['done']: raise ValueError # should probably use a custom exception move=T connection.send(move) execfile(fname+".py") print locals() # seems to appear in locals state=connection.recv() if state['done']: print "%s done" % fname connection.close() return try: agent(state) except ValueError: pass print "%s done" % fname connection.close() class Sim(object): def __init__(self,agent1,agent2,type=1): self.agent_files=[agent1,agent2] self.type=type def run(self): self.processes=[] self.connections=[] for fname in self.agent_files: parent,child=Pipe() self.connections.append(parent) if self.type==1: proc=Process(target=wrap_agent, args=(child,fname,)) else: proc=Process(target=wrap_agent2, args=(child,fname,)) self.processes.append(proc) for proc in self.processes: proc.start() current_player,other_player=1,2 N=23 state={} while N>1: state['board']=N state['player']=current_player state['done']=False c=self.connections[current_player-1] print "Number of sticks: ",N c.send(state) move=c.recv() print "Player ",current_player,"takes ",move N-=move current_player,other_player=other_player,current_player print "Number of sticks: ",N # send the end signals state['done']=True for c in self.connections: c.send(state) for p in self.processes: p.join() if N==1: winner=other_player else: winner=current_player print "Winner is ",winner return winner if __name__=="__main__": s=Sim('agent1','agent2') winner=s.run() print "============" s=Sim('agent3','agent4',type=2) winner=s.run() -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sat Feb 13 17:50:38 2010 From: john at castleamber.com (John Bokma) Date: Sat, 13 Feb 2010 16:50:38 -0600 Subject: Py3: Terminal or browser output? References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: <87pr48agxt.fsf@castleamber.com> Gnarlodious writes: > Hello, searched all over but no success. I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. > In Python 2, I just said this: > > if len(sys.argv)==True: > > and it seemed to work. Py3 must have broken that by sending a list > with the path to the script in BOTH the browser and Terminal. Is there > some newfangled way to determine what is running the script (hopefully > without a try wrapper)? Your web server (assuming CGI) sets some environment variables, which you could test for. This has as advantage (or disadvantage) that you can set the variable at the CLI and see the output the browser could get. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alfps at start.no Sat Feb 13 17:56:58 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 23:56:58 +0100 Subject: Modifying Class Object In-Reply-To: <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Michael Sparks: > [Due to the appearance of reasoned discussion (it's not practical to read it all!), I felt it necessary to respond. It turned out to be a long sequence of trivial fallacies, peppered with various allegations and insinuations.] [snip extremely much] > Now let's move to the implementation aspects. > > Python as a language is implemented in many languages. One of these > is C. There are compilers to C (pypy), C++ (shedskin), for the JVM > (Jython) and .net (Ironpython). > > There is also an executable operation semantics for python, > which can be found here: > > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > > This set of operational semantics is written in Haskell. > > Haskell is a strictly pure, lazily evaluated language. It > therefore has no pointers or references, just values and names. > The implementation therefore cannot be in terms of references > and pointers. At this point consider whether it's possible to implement Pascal in Haskell. If it is possible, then you have a problem wrt. drawing conclusions about pointers in Pascal, uh oh, they apparently can't exist. But if it is not possible to implement Pascal in Haskell, then Haskell must be some etremely limited special-purpose language, not Turing complete -- is that acceptable to you? > Therefore to say "in reality the implementation > will be passing a reference or pointer" is invalid. There is > after all at least one implementation that does not rely on > such machine oriented language details. I'm sorry, but see above: in itself it's just yet another a fallacy. And as an argument in a debate with me it's misrepresenting. There is need to talk about "in reality" (as if the language spec and general semantics isn't real enough) nor to talk about any specific implementation. [snip very much] > I sincerely hope that my reply does not offend or inflame you, > since that is not the intent. I do hope it educates you and > puts into context the responses you have gained from others. > > After all, one simply shouting in a corner saying "YOU'RE > ALL WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one > does not to understand what one is talking about does not > tend to engender warm fluffy feelings or sentiments of > authority towards such an individual. Be it me, you, or > anyone else. > > At the moment, you appear to me to be engaging in such a > behaviour. Now you don't know from Jack and probably don't > care about my viewpoint, but I would really appreciate it > if you would try not to be inflammatory in your response > to this. (Since you do appear to also have a need to have > the last word) > > Hoping this was useful on some level, Yes. I elected to respond to just /one/ of the many arguments you presented. The other arguments, about why there are no references in Python, shared, however, the basic property of being logical fallacies packaged in kilometers of rambling text. Cheers, - Alf From vahuja4 at gmail.com Sat Feb 13 18:44:37 2010 From: vahuja4 at gmail.com (Vish) Date: Sat, 13 Feb 2010 15:44:37 -0800 (PST) Subject: Hashing in python Message-ID: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Hi, I need to hash 3d coordinates to a grid which has been divided into 4*4*4 squares. Using python, I thought of a simple way as follows: CELL_SIZE = 4 def key(point): return ( int((floor(point[0]/CELL_SIZE))*CELL_SIZE), int((floor(point[1]/CELL_SIZE))*CELL_SIZE), int((floor(point[2]/CELL_SIZE))*CELL_SIZE) ) Since python allows keys to be tuples, I think that this should work. Is there a better (more efficient) way to do it? Thank you, Vishal From steve at holdenweb.com Sat Feb 13 18:54:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Feb 2010 18:54:52 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Michael Sparks: > [Due to the appearance of reasoned discussion (it's not practical to read it all!) [...] >> Therefore to say "in reality the implementation will be passing a >> reference or pointer" is invalid. There is after all at least one >> implementation that does not rely on such machine oriented language >> details. > > I'm sorry, but see above: in itself it's just yet another a fallacy. > > And as an argument in a debate with me it's misrepresenting. > I see we are still all out of step with you. If it's a fallacy then I'd like to see a reasoned logical explanation of its fallaciousness. As far as I can see, if someone says "implementing Python implies the use of pointers" as you appear to be doing, then Michael's argument neatly demolishes that argument by providing a counter-example: there is an implementation of Python that does not use pointers. You, however, dismiss this as a fallacy, and suggests it somehow misrepresents you. And yet you wonder why people call your behavior (not you) paranoid. [...] > >> I sincerely hope that my reply does not offend or inflame you, >> since that is not the intent. I do hope it educates you and puts >> into context the responses you have gained from others. >> >> After all, one simply shouting in a corner saying "YOU'RE ALL >> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >> understand what one is talking about does not tend to engender warm >> fluffy feelings or sentiments of authority towards such an >> individual. Be it me, you, or anyone else. >> >> At the moment, you appear to me to be engaging in such a behaviour. >> Now you don't know from Jack and probably don't care about my >> viewpoint, but I would really appreciate it if you would try not to >> be inflammatory in your response to this. (Since you do appear to >> also have a need to have the last word) >> >> Hoping this was useful on some level, > > Yes. > > I elected to respond to just /one/ of the many arguments you > presented. > > The other arguments, about why there are no references in Python, > shared, however, the basic property of being logical fallacies > packaged in kilometers of rambling text. > And you can say this without, by your own admission, even reading it. It makes me wonder why we have paid you the compliment of engaging you in debate, since this is the most transparent evidence to date that what comes back will be unrelated to the arguments presented. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Feb 13 19:43:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 00:43:34 GMT Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: <4b774736$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 07:59:42 -0800, Michael Sparks wrote: > Now, if I define a language, this has 3 main parts: > * Syntax > * Semantics > * Implementation [snip] Michael, that is remarkable. Excellent work, thank you! -- Steven From python at mrabarnett.plus.com Sat Feb 13 19:47:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 00:47:18 +0000 Subject: Hashing in python In-Reply-To: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <4B774816.4040103@mrabarnett.plus.com> Vish wrote: > Hi, > > I need to hash 3d coordinates to a grid which has been divided into > 4*4*4 squares. Using python, I thought of a simple way as follows: > > CELL_SIZE = 4 > > def key(point): > > return ( > int((floor(point[0]/CELL_SIZE))*CELL_SIZE), > int((floor(point[1]/CELL_SIZE))*CELL_SIZE), > int((floor(point[2]/CELL_SIZE))*CELL_SIZE) > ) > > > Since python allows keys to be tuples, I think that this should work. > Is there a better (more efficient) way to do it? > floor(x) returns an integer, so floor(x/CELL_SIZE)*CELL_SIZE is an integer multiple of CELL_SIZE, also an integer. There's actually no point (unintentional pun!) to multiplying by CELL_SIZE: CELL_SIZE = 4 def key(point): return ( floor(point[0] / CELL_SIZE), floor(point[1] / CELL_SIZE), floor(point[2] / CELL_SIZE) ) From d.dalton at iinet.net.au Sat Feb 13 19:48:31 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sun, 14 Feb 2010 11:48:31 +1100 Subject: working with laptop battery Message-ID: <20100214004831.GA21071@debian-eeepc> Hi, I'm constantly working in the command line and need to write a program to give me alerts on my battery. Can someone please tell me what module I should use to access battery information? Looking for something that perhaps makes use of acpi so I can get estimated time left as well as a percentage. Thanks very much for any help, Dan From alfps at start.no Sat Feb 13 19:50:01 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 01:50:01 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Michael Sparks: >> [Due to the appearance of reasoned discussion (it's not practical to read it all!) > [...] >>> Therefore to say "in reality the implementation will be passing a >>> reference or pointer" is invalid. There is after all at least one >>> implementation that does not rely on such machine oriented language >>> details. >> I'm sorry, but see above: in itself it's just yet another a fallacy. >> >> And as an argument in a debate with me it's misrepresenting. >> > I see we are still all out of step with you. Why did you snip the short argument? > If it's a fallacy then I'd > like to see a reasoned logical explanation of its fallaciousness. Oh, you snipped it so that you didn't have to present it to readers. That's dishonest, Steve Holden. Requoting: > Now let's move to the implementation aspects. > > Python as a language is implemented in many languages. One of these > is C. There are compilers to C (pypy), C++ (shedskin), for the JVM > (Jython) and .net (Ironpython). > > There is also an executable operation semantics for python, > which can be found here: > > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > > This set of operational semantics is written in Haskell. > > Haskell is a strictly pure, lazily evaluated language. It > therefore has no pointers or references, just values and names. > The implementation therefore cannot be in terms of references > and pointers. At this point consider whether it's possible to implement Pascal in Haskell. If it is possible, then you have a problem wrt. drawing conclusions about pointers in Pascal, uh oh, they apparently can't exist. But if it is not possible to implement Pascal in Haskell, then Haskell must be some etremely limited special-purpose language, not Turing complete -- is that acceptable to you? > As far as I can see, if someone says "implementing Python implies the > use of pointers" as you appear to be doing, then Michael's argument > neatly demolishes that argument by providing a counter-example: there is > an implementation of Python that does not use pointers. That's meaningless. But then so is maintaining that Python doesn't have references. And so is your argument applied to Pascal, just to mention that again. > You, however, dismiss this as a fallacy, and suggests it somehow > misrepresents you. And yet you wonder why people call your behavior (not > you) paranoid. On top of the multiple fallacies, dubious snipping of arguments, statements that such arguments have not been presented (just after snipping them), and general misleading insinuations and misrepresentation, ad yet another bit of personal attack. Do you understand what that may say to readers about you, Steve Holden? Apparently it's all to defend an indefensible, idiotic position. But I think you're doing it at least partially for the fun of harassing someone. > [...] >>> I sincerely hope that my reply does not offend or inflame you, >>> since that is not the intent. I do hope it educates you and puts >>> into context the responses you have gained from others. >>> >>> After all, one simply shouting in a corner saying "YOU'RE ALL >>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>> understand what one is talking about does not tend to engender warm >>> fluffy feelings or sentiments of authority towards such an >>> individual. Be it me, you, or anyone else. >>> >>> At the moment, you appear to me to be engaging in such a behaviour. >>> Now you don't know from Jack and probably don't care about my >>> viewpoint, but I would really appreciate it if you would try not to >>> be inflammatory in your response to this. (Since you do appear to >>> also have a need to have the last word) >>> >>> Hoping this was useful on some level, >> Yes. >> >> I elected to respond to just /one/ of the many arguments you >> presented. >> >> The other arguments, about why there are no references in Python, >> shared, however, the basic property of being logical fallacies >> packaged in kilometers of rambling text. >> > And you can say this without, by your own admission, even reading it. No, you can not quote any place I have said that I haven't read his article. I did read most of it. So you are yet again within the span of one posted article presenting untrue information that you know is not true. > It > makes me wonder why we have paid you the compliment of engaging you in > debate, Gosh, I don't know. You must be stupid to do that. Yes? > since this is the most transparent evidence to date that what > comes back will be unrelated to the arguments presented. That is untrue, Steve Holden, and since you can't quote that "evidence", since you evidently /have/ read my short article which you're responding to, knowing exactly what to snip, you know that what you're saying is untrue. I think this is your third lie in one posting. But who would care to count. Cheers & hth., - Alf From benjamin.kaplan at case.edu Sat Feb 13 19:56:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 13 Feb 2010 19:56:16 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: On Sat, Feb 13, 2010 at 7:50 PM, Alf P. Steinbach wrote: > > At this point consider whether it's possible to implement Pascal in Haskell. > > If it is possible, then you have a problem wrt. drawing conclusions about > pointers in Pascal, uh oh, they apparently can't exist. > > But if it is not possible to implement Pascal in Haskell, then Haskell must > be some etremely limited special-purpose language, not Turing complete ?-- > ?is that acceptable to you? > > You're actually just proving his point here. It doesn't matter what model Haskell uses, a version of Pascal implemented in Haskell has pointers. Likewise, regardless of what model the implementation of Python uses, Python itself doesn't have pointers, it has objects and names. From breamoreboy at yahoo.co.uk Sat Feb 13 20:01:20 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Feb 2010 01:01:20 +0000 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Michael Sparks: >>> [Due to the appearance of reasoned discussion (it's not practical to >>> read it all!) >> [...] >>>> Therefore to say "in reality the implementation will be passing a >>>> reference or pointer" is invalid. There is after all at least one >>>> implementation that does not rely on such machine oriented language >>>> details. >>> I'm sorry, but see above: in itself it's just yet another a fallacy. >>> >>> And as an argument in a debate with me it's misrepresenting. >>> >> I see we are still all out of step with you. > > Why did you snip the short argument? > > >> If it's a fallacy then I'd >> like to see a reasoned logical explanation of its fallaciousness. > > Oh, you snipped it so that you didn't have to present it to readers. > > That's dishonest, Steve Holden. > > Requoting: > > > > Now let's move to the implementation aspects. > > > > Python as a language is implemented in many languages. One of these > > is C. There are compilers to C (pypy), C++ (shedskin), for the JVM > > (Jython) and .net (Ironpython). > > > > There is also an executable operation semantics for python, > > which can be found here: > > > > > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > > > > > This set of operational semantics is written in Haskell. > > > > Haskell is a strictly pure, lazily evaluated language. It > > therefore has no pointers or references, just values and names. > > The implementation therefore cannot be in terms of references > > and pointers. > > At this point consider whether it's possible to implement Pascal in > Haskell. > > If it is possible, then you have a problem wrt. drawing conclusions > about pointers in Pascal, uh oh, they apparently can't exist. > > But if it is not possible to implement Pascal in Haskell, then Haskell > must be some etremely limited special-purpose language, not Turing > complete -- is that acceptable to you? > > > >> As far as I can see, if someone says "implementing Python implies the >> use of pointers" as you appear to be doing, then Michael's argument >> neatly demolishes that argument by providing a counter-example: there is >> an implementation of Python that does not use pointers. > > That's meaningless. > > But then so is maintaining that Python doesn't have references. > > And so is your argument applied to Pascal, just to mention that again. > > >> You, however, dismiss this as a fallacy, and suggests it somehow >> misrepresents you. And yet you wonder why people call your behavior (not >> you) paranoid. > > On top of the multiple fallacies, dubious snipping of arguments, > statements that such arguments have not been presented (just after > snipping them), and general misleading insinuations and > misrepresentation, ad yet another bit of personal attack. > > Do you understand what that may say to readers about you, Steve Holden? > > Apparently it's all to defend an indefensible, idiotic position. But I > think you're doing it at least partially for the fun of harassing someone. > > >> [...] >>>> I sincerely hope that my reply does not offend or inflame you, since >>>> that is not the intent. I do hope it educates you and puts >>>> into context the responses you have gained from others. >>>> >>>> After all, one simply shouting in a corner saying "YOU'RE ALL >>>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>>> understand what one is talking about does not tend to engender warm >>>> fluffy feelings or sentiments of authority towards such an >>>> individual. Be it me, you, or anyone else. >>>> >>>> At the moment, you appear to me to be engaging in such a behaviour. >>>> Now you don't know from Jack and probably don't care about my >>>> viewpoint, but I would really appreciate it if you would try not to >>>> be inflammatory in your response to this. (Since you do appear to >>>> also have a need to have the last word) >>>> >>>> Hoping this was useful on some level, >>> Yes. >>> >>> I elected to respond to just /one/ of the many arguments you >>> presented. >>> >>> The other arguments, about why there are no references in Python, >>> shared, however, the basic property of being logical fallacies >>> packaged in kilometers of rambling text. >>> >> And you can say this without, by your own admission, even reading it. > > No, you can not quote any place I have said that I haven't read his > article. I did read most of it. So you are yet again within the span of > one posted article presenting untrue information that you know is not true. > > >> It >> makes me wonder why we have paid you the compliment of engaging you in >> debate, > > Gosh, I don't know. You must be stupid to do that. Yes? > > >> since this is the most transparent evidence to date that what >> comes back will be unrelated to the arguments presented. > > That is untrue, Steve Holden, and since you can't quote that "evidence", > since you evidently /have/ read my short article which you're responding > to, knowing exactly what to snip, you know that what you're saying is > untrue. I think this is your third lie in one posting. But who would > care to count. > > > Cheers & hth., > > - Alf You really are the most insulting arrogant bastard I've ever read on c.l.py in the eight years that I've been using Python. Did you get your training at the Dr Goebbels School of Propaganda? Most disgustedly. Mark Lawrence From vicente.soler at gmail.com Sat Feb 13 20:21:51 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Feb 2010 17:21:51 -0800 (PST) Subject: Selecting a file in a directory Message-ID: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Hi, My python script needs to work with a .txt file in a directory. I would like to give the user the possibility to choose the file he needs to work on in as much the same way as I open a .xls file in Excel, that is, I want to make appear the "Windows'" window and let the user choose. I think this should be quite straightforward. How should I proceed? From clp2 at rebertia.com Sat Feb 13 20:26:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Feb 2010 17:26:02 -0800 Subject: working with laptop battery In-Reply-To: <20100214004831.GA21071@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> Message-ID: <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> On Sat, Feb 13, 2010 at 4:48 PM, Daniel Dalton wrote: > Hi, > > I'm constantly working in the command line and need to write a program > to give me alerts on my battery. Can someone please tell me what module > I should use to access battery information? Looking for something that > perhaps makes use of acpi so I can get estimated time left as well as a > percentage. It's probably gonna depend on which OS you're running. Which would be...? Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Sat Feb 13 20:28:13 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 02:28:13 +0100 Subject: Selecting a file in a directory In-Reply-To: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: * vsoler: > Hi, > > My python script needs to work with a .txt file in a directory. I > would like to give the user the possibility to choose the file he > needs to work on in as much the same way as I open a .xls file in > Excel, that is, I want to make appear the "Windows'" window and let > the user choose. > > I think this should be quite straightforward. > > How should I proceed? At least in Windows one easy way is to delegate that responsibility to the Windows shell. When a user drags a file onto your script, your script is run with the path to that dragged file as argument. Or it can even be multiple files. Otherwise, tkinter has, as I recall, a standard file chooser dialog. These "standard" dialogs are generally called "common dialogs". Just google for tkinter and suitable words. Cheers & hth., - Alf From anand.shashwat at gmail.com Sat Feb 13 20:29:49 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 14 Feb 2010 06:59:49 +0530 Subject: working with laptop battery In-Reply-To: <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> Message-ID: I too am interested as to which module should I use. My OS is OS X Snow Leopard. On Sun, Feb 14, 2010 at 6:56 AM, Chris Rebert wrote: > On Sat, Feb 13, 2010 at 4:48 PM, Daniel Dalton > wrote: > > Hi, > > > > I'm constantly working in the command line and need to write a program > > to give me alerts on my battery. Can someone please tell me what module > > I should use to access battery information? Looking for something that > > perhaps makes use of acpi so I can get estimated time left as well as a > > percentage. > > It's probably gonna depend on which OS you're running. Which would be...? > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Sat Feb 13 20:31:33 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 17:31:33 -0800 (PST) Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> This thread is interesting on many levels. What is the core question that is being examined here? From alfps at start.no Sat Feb 13 20:34:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 02:34:11 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Benjamin Kaplan: > On Sat, Feb 13, 2010 at 7:50 PM, Alf P. Steinbach wrote: >> At this point consider whether it's possible to implement Pascal in Haskell. >> >> If it is possible, then you have a problem wrt. drawing conclusions about >> pointers in Pascal, uh oh, they apparently can't exist. >> >> But if it is not possible to implement Pascal in Haskell, then Haskell must >> be some etremely limited special-purpose language, not Turing complete -- >> is that acceptable to you? >> >> > > You're actually just proving his point here. It doesn't matter what > model Haskell uses, a version of Pascal implemented in Haskell has > pointers. Yes, that kills his argument. As you note, the Haskell bit is completely irrelevant. So his use of Haskell implementation as a "no pointers" argument is completely bogus, a fallacy. > Likewise, regardless of what model the implementation of > Python uses, Python itself doesn't have pointers, it has objects and > names. Well that's wrong for at least one general meaning of "pointer", but why quibble about terminology? Names in Python refer to objects. Those references can be copied via assignment. That's (almost) all. And it provides a very short and neat way to describe pass by sharing. Cheers & hth., - Alf From cs at zip.com.au Sat Feb 13 20:37:08 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 14 Feb 2010 12:37:08 +1100 Subject: threading and signals - main thread solely responsible for signal handling? In-Reply-To: <20100213172226.26099.213963272.divmod.xquotient.1291@localhost.localdomain> References: <20100213172226.26099.213963272.divmod.xquotient.1291@localhost.localdomain> Message-ID: <20100214013708.GA4636@cskk.homeip.net> On 13Feb2010 17:22, exarkun at twistedmatrix.com wrote: | On 04:43 pm, maligree at gmail.com wrote: | >The main part of my script is a function that does many long reads | >(urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to | >display some stats, I needed to run foo() as a seperate thread to | >avoid getting errno 4 (interrupted system call) errors (which occur if | >SIGINFO is received while urlopen is setting itself up/waiting for a | >response). This does the job, SIGINFO is handled without ever brutally | >interrupting urlopen. | > | >The problem is that after starting foo as a thread, my main thread has | >nothing left to do - unless it receives a signal, and I am forced to | >keep it in some sort of loop so that ANY signal handling can still | >occur. I thought I'd just occupy it with a simple while 1: pass loop | >but that, unfortunately, means 100% CPU usage. [...] | | MRAB suggested you time.sleep() in a loop, which is probably fine. | However, if you want to have even /less/ activity than that in the | main thread, take a look at signal.pause(). Funnily enough I coded this issue just a few weeks ago, and my main program looks like this: def main(argv): xit = 0 cmd = os.path.basename(argv[0]) SM = SystemManager() [...set up a bunch of subsystems...] SM.startAll() try: signal.pause() except KeyboardInterrupt: warn("KeyboardInterrupt interrupts pause()") xit = 1 SM.close() SM.join() return xit So SM.close() tells all the subsystems to close and finish up. That largely involved putting the "EOF" sentinel value on a lot of Queues, causes the subsystems to cease processing stuff. The separate SM.join() does the actaul waiting for everything. This makes for clean and timely shutdown for me. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If your new theorem can be stated with great simplicity, then there will exist a pathological exception. - Adrian Mathesis From vicente.soler at gmail.com Sat Feb 13 20:38:40 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Feb 2010 17:38:40 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: <381a8d2e-1212-4b26-a1d5-7370d23bfbb1@d37g2000yqa.googlegroups.com> On Feb 14, 2:28?am, "Alf P. Steinbach" wrote: > * vsoler: > > > Hi, > > > My python script needs to work with a .txt file in a directory. I > > would like to give the user the possibility to choose the file he > > needs to work on in as much the same way as I open a .xls file in > > Excel, that is, I want to make appear the "Windows'" window and let > > the user choose. > > > I think this should be quite straightforward. > > > How should I proceed? > > At least in Windows one easy way is to delegate that responsibility to the > Windows shell. When a user drags a file onto your script, your script is run > with the path to that dragged file as argument. Or it can even be multiple files. > > Otherwise, tkinter has, as I recall, a standard file chooser dialog. > > These "standard" dialogs are generally called "common dialogs". > > Just google for tkinter and suitable words. > > Cheers & hth., > > - Alf I'll try, thank you very much From d.dalton at iinet.net.au Sat Feb 13 20:43:24 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sun, 14 Feb 2010 12:43:24 +1100 Subject: working with laptop battery In-Reply-To: <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> Message-ID: <20100214014324.GA4868@debian-eeepc> On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: > It's probably gonna depend on which OS you're running. Which would be...? Sorry, forgot to mention this. I'm running debian linux. Thanks, Dan From alfps at start.no Sat Feb 13 20:43:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 02:43:29 +0100 Subject: Modifying Class Object In-Reply-To: <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> Message-ID: * Steve Howell: > This thread is interesting on many levels. What is the core question > that is being examined here? I think that regarding the technical it is whether a Python name refers to an object or not. I maintain that it does, and that the reference can be copied, and that the semantics of the language requires this and is defined in terms of this. Steve Holden, D'Aprano and many others maintain that there are no references, or that if there are then they're only an implementation aspect, i.e. that conceiveable one could have an implementation without them. Regarding some other issues it seems to be a childish exercise in flaming, a flame war, with claims of insanity, incompetence, lying (that's actually from me, I reacted a bit strongly to faked quoting + conclusions from that in a posting not appearing on Usenet but on the Python mail list), etc. etc. ad nauseam, sprinkled with misrepresentations etc. I don't know the point of that. Cheers, - Alf From steve at holdenweb.com Sat Feb 13 20:44:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Feb 2010 20:44:47 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Michael Sparks: >>> [Due to the appearance of reasoned discussion (it's not practical to >>> read it all!) >> [...] >>>> Therefore to say "in reality the implementation will be passing a >>>> reference or pointer" is invalid. There is after all at least one >>>> implementation that does not rely on such machine oriented language >>>> details. >>> I'm sorry, but see above: in itself it's just yet another a fallacy. >>> >>> And as an argument in a debate with me it's misrepresenting. >>> >> I see we are still all out of step with you. > > Why did you snip the short argument? > Because it's irrelevant and fallacious. > >> If it's a fallacy then I'd >> like to see a reasoned logical explanation of its fallaciousness. > > Oh, you snipped it so that you didn't have to present it to readers. > > That's dishonest, Steve Holden. > > Requoting: > > >> Now let's move to the implementation aspects. >> >> Python as a language is implemented in many languages. One of these >> is C. There are compilers to C (pypy), C++ (shedskin), for the JVM >> (Jython) and .net (Ironpython). >> >> There is also an executable operation semantics for python, >> which can be found here: >> >> > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > >> >> This set of operational semantics is written in Haskell. >> >> Haskell is a strictly pure, lazily evaluated language. It >> therefore has no pointers or references, just values and names. >> The implementation therefore cannot be in terms of references >> and pointers. > > At this point consider whether it's possible to implement Pascal in > Haskell. > > If it is possible, then you have a problem wrt. drawing conclusions > about pointers in Pascal, uh oh, they apparently can't exist. > > But if it is not possible to implement Pascal in Haskell, then Haskell > must be some etremely limited special-purpose language, not Turing > complete -- is that acceptable to you? > > This, if it says anything at all, appears to say that any Turing-complete language has pointers in it, which is an absurdity. > >> As far as I can see, if someone says "implementing Python implies the >> use of pointers" as you appear to be doing, then Michael's argument >> neatly demolishes that argument by providing a counter-example: there is >> an implementation of Python that does not use pointers. > > That's meaningless. > > But then so is maintaining that Python doesn't have references. > > And so is your argument applied to Pascal, just to mention that again. > *You* brought Pascal into this, not me. > >> You, however, dismiss this as a fallacy, and suggests it somehow >> misrepresents you. And yet you wonder why people call your behavior (not >> you) paranoid. > > On top of the multiple fallacies, dubious snipping of arguments, > statements that such arguments have not been presented (just after > snipping them), and general misleading insinuations and > misrepresentation, ad yet another bit of personal attack. > > Do you understand what that may say to readers about you, Steve Holden? > I'm happy to let readers draw their own conclusions about us both. > Apparently it's all to defend an indefensible, idiotic position. But I > think you're doing it at least partially for the fun of harassing someone. > Not at all. You have accused me of bullying behavior, but in truth you are the bully, and we know what happens when you give in to bullies, don't we? > >> [...] >>>> I sincerely hope that my reply does not offend or inflame you, since >>>> that is not the intent. I do hope it educates you and puts >>>> into context the responses you have gained from others. >>>> >>>> After all, one simply shouting in a corner saying "YOU'RE ALL >>>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>>> understand what one is talking about does not tend to engender warm >>>> fluffy feelings or sentiments of authority towards such an >>>> individual. Be it me, you, or anyone else. >>>> >>>> At the moment, you appear to me to be engaging in such a behaviour. >>>> Now you don't know from Jack and probably don't care about my >>>> viewpoint, but I would really appreciate it if you would try not to >>>> be inflammatory in your response to this. (Since you do appear to >>>> also have a need to have the last word) >>>> >>>> Hoping this was useful on some level, >>> Yes. >>> >>> I elected to respond to just /one/ of the many arguments you >>> presented. >>> >>> The other arguments, about why there are no references in Python, >>> shared, however, the basic property of being logical fallacies >>> packaged in kilometers of rambling text. >>> >> And you can say this without, by your own admission, even reading it. > > No, you can not quote any place I have said that I haven't read his > article. I did read most of it. So you are yet again within the span of > one posted article presenting untrue information that you know is not true. > I repeat the quote from you which you can read at the top of this post: >>> [Due to the appearance of reasoned discussion (it's not practical to >>> read it all!) >> [...] So now you say you read "most" of it. Even this statement is an admission that there are parts you did not, and yet somehow *I* am the liar? We are moving from the bizarre to the delusional here. > >> It >> makes me wonder why we have paid you the compliment of engaging you in >> debate, > > Gosh, I don't know. You must be stupid to do that. Yes? > Apparently. > >> since this is the most transparent evidence to date that what >> comes back will be unrelated to the arguments presented. > > That is untrue, Steve Holden, and since you can't quote that "evidence", > since you evidently /have/ read my short article which you're responding > to, knowing exactly what to snip, you know that what you're saying is > untrue. I think this is your third lie in one posting. But who would > care to count. > Who indeed? > > Cheers & hth., > That signature surely has to be irony. Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Feb 13 20:45:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 01:45:03 GMT Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: <4b77559f$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 17:21:51 -0800, vsoler wrote: > Hi, > > My python script needs to work with a .txt file in a directory. I would > like to give the user the possibility to choose the file he needs to > work on in as much the same way as I open a .xls file in Excel, that is, > I want to make appear the "Windows'" window and let the user choose. > > I think this should be quite straightforward. Python is multi-platform. Having the Windows file selection dialogs appear under Linux or Mac is anything but straightforward! The only general purpose (non-operating system specific) solution will require a GUI toolkit. > How should I proceed? >>> import tkFileDialog >>> help(tkFileDialog) See also: http://docs.python.org/library/tkinter.html http://wiki.python.org/moin/GuiProgramming or google on "python display file dialog". -- Steven From rantingrick at gmail.com Sat Feb 13 20:45:32 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Feb 2010 17:45:32 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: <96255e38-b30b-42f2-9cd4-baa6a7b7eeb9@j31g2000yqa.googlegroups.com> On Feb 13, 7:28?pm, "Alf P. Steinbach" wrote: > * vsoler: > > > Hi, > > > My python script needs to work with a .txt file in a directory. I > > would like to give the user the possibility to choose the file he > > needs to work on in as much the same way as I open a .xls file in > > Excel, that is, I want to make appear the "Windows'" window and let > > the user choose. > > > I think this should be quite straightforward. > > > How should I proceed? > > At least in Windows one easy way is to delegate that responsibility to the > Windows shell. When a user drags a file onto your script, your script is run > with the path to that dragged file as argument. Or it can even be multiple files. > > Otherwise, tkinter has, as I recall, a standard file chooser dialog. > > These "standard" dialogs are generally called "common dialogs". specifically Alf was referring to tkFileDialog.askopenfilename(). Heres an example... import Tkinter as tk from tkFileDialog import askopenfilename root = tk.Tk() def get_files(): path = askopenfilename(filetypes=[('TXT', '.txt')]) if path: print path tk.Button(root, text='1', font=('Wingdings', 12), command=get_files).pack(padx=5, pady=5) root.mainloop() From vicente.soler at gmail.com Sat Feb 13 21:00:03 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Feb 2010 18:00:03 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> <96255e38-b30b-42f2-9cd4-baa6a7b7eeb9@j31g2000yqa.googlegroups.com> Message-ID: <89f86e28-0ed3-4232-b489-db088d320658@q21g2000yqm.googlegroups.com> On Feb 14, 2:45?am, rantingrick wrote: > On Feb 13, 7:28?pm, "Alf P. Steinbach" wrote: > > > > > * vsoler: > > > > Hi, > > > > My python script needs to work with a .txt file in a directory. I > > > would like to give the user the possibility to choose the file he > > > needs to work on in as much the same way as I open a .xls file in > > > Excel, that is, I want to make appear the "Windows'" window and let > > > the user choose. > > > > I think this should be quite straightforward. > > > > How should I proceed? > > > At least in Windows one easy way is to delegate that responsibility to the > > Windows shell. When a user drags a file onto your script, your script is run > > with the path to that dragged file as argument. Or it can even be multiple files. > > > Otherwise, tkinter has, as I recall, a standard file chooser dialog. > > > These "standard" dialogs are generally called "common dialogs". > > specifically Alf was referring to tkFileDialog.askopenfilename(). > Heres an example... > > import Tkinter as tk > from tkFileDialog import askopenfilename > > root = tk.Tk() > > def get_files(): > ? ? path = askopenfilename(filetypes=[('TXT', '.txt')]) > ? ? if path: > ? ? ? ? print path > > tk.Button(root, text='1', font=('Wingdings', 12), > command=get_files).pack(padx=5, pady=5) > > root.mainloop() Excellent!!! Just what I needed! From python at mrabarnett.plus.com Sat Feb 13 21:01:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 02:01:50 +0000 Subject: multiprocessing and games In-Reply-To: <694A55DA-6557-486A-A0D5-B3B19C8B2D6F@bryant.edu> References: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> <4B76E759.3010503@mrabarnett.plus.com> <694A55DA-6557-486A-A0D5-B3B19C8B2D6F@bryant.edu> Message-ID: <4B77598E.4010800@mrabarnett.plus.com> Brian Blais wrote: > On Feb 13, 2010, at 12:54 , MRAB wrote: > >> Brian Blais wrote: >>> I've been thinking about implementing some simple games > >> Forget about global variables, they're not worth it! :-) >> >> Think in terms of messages, sent via pipes, sockets or multiprocessing >> queues. >> > > okay...let's make this concrete. given your ideas, I have it working > for the first type of agent, namely one that is called like: > > move=agent(board,player) > > For a specific example, I'm using the simplest version of a game called > Nim. You start with a number of sticks, players take turns taking 1, 2, > or 3 sticks, and you lose if you take the last stick. Two agents for > this are: > > # agent1.py - simple take 1 agent > def agent(board,player): > return 1 > > # agent2.py - perfect player > def agent(board,player): > move=(board-1)%4 > if move==0: > return 1 > else: > return move > > I run my simulator like (complete code below): > > s=Sim('agent1','agent2') > winner=s.run() > > and it spawns two processes, passes messages between the sim and the > agents, and closes the agents nicely when the game is over. I'm not > sure how I catch errors in the agents, especially accidental infinite loops. > > Now the second type of agent is structured differently. I'd like > something like: > > # agent3.py - simple take 1 agent > def agent(state): > > while True: > Take(1) > > # agent4.py - perfect player > def agent(state): > > N=state['board'] # get the current information > while True: > move=(N-1)%4 > if move==0: > Take(1) > else: > Take(move) > > I tried to implement this in the second wrapper below, but I can't get > the agent function to "see" local functions in the wrapper. I probably > need an import somewhere, but I haven't quite figured out the scoping > with multiprocessing, etc... > > I include the code below. The two message-passing wrappers are there, > and it works for the first two agents, but not the second two because of > scoping issues. > > Is there a better way to be doing this? Are there other examples like > this that I can look at to improve what I am doing? > [snip] I would try to have more separation between the agents and the simulator. The simulator would start the agents, something like this: def run_agent(agent_name, connection): agent_module = __import__(agent_name) agent_module.run(agent_name, connection) ... for agent_name in self.agent_files: parent, child = Pipe() connections.append(parent) proc = Process(target=run_agent, args=(agent_name, child)) processes.append(proc) The logic for an agent would be in its own module: agent1.py --------- def get_move(board, player): return 1 def run(agent_name, connection): end = False while not end: state = connection.recv() if state['done']: break move = get_move(state['board'], state['player']) connection.send(move) print "%s done" % agent_name connection.close() If I wanted the agents to share some logic (functions) then I would put it (them) in a common module which the agents would import. From python at mrabarnett.plus.com Sat Feb 13 21:10:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 02:10:28 +0000 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> Message-ID: <4B775B94.5030406@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Steve Howell: >> This thread is interesting on many levels. What is the core question >> that is being examined here? > > I think that regarding the technical it is whether a Python name refers > to an object or not. I maintain that it does, and that the reference can > be copied, and that the semantics of the language requires this and is > defined in terms of this. Steve Holden, D'Aprano and many others > maintain that there are no references, or that if there are then they're > only an implementation aspect, i.e. that conceiveable one could have an > implementation without them. > > Regarding some other issues it seems to be a childish exercise in > flaming, a flame war, with claims of insanity, incompetence, lying > (that's actually from me, I reacted a bit strongly to faked quoting + > conclusions from that in a posting not appearing on Usenet but on the > Python mail list), etc. etc. ad nauseam, sprinkled with > misrepresentations etc. I don't know the point of that. > It's a pity that no-one has gone far enough to trigger Godwin's Law... ;-) From alfps at start.no Sat Feb 13 21:10:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 03:10:49 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >>>> * Michael Sparks: >>>> [Due to the appearance of reasoned discussion (it's not practical to >>>> read it all!) >>> [...] >>>>> Therefore to say "in reality the implementation will be passing a >>>>> reference or pointer" is invalid. There is after all at least one >>>>> implementation that does not rely on such machine oriented language >>>>> details. >>>> I'm sorry, but see above: in itself it's just yet another a fallacy. >>>> >>>> And as an argument in a debate with me it's misrepresenting. >>>> >>> I see we are still all out of step with you. >> Why did you snip the short argument? >> > Because it's irrelevant and fallacious. >>> If it's a fallacy then I'd >>> like to see a reasoned logical explanation of its fallaciousness. >> Oh, you snipped it so that you didn't have to present it to readers. >> >> That's dishonest, Steve Holden. >> >> Requoting: >> >> >>> Now let's move to the implementation aspects. >>> >>> Python as a language is implemented in many languages. One of these >>> is C. There are compilers to C (pypy), C++ (shedskin), for the JVM >>> (Jython) and .net (Ironpython). >>> >>> There is also an executable operation semantics for python, >>> which can be found here: >>> >>> >> http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ >> >>> This set of operational semantics is written in Haskell. >>> >>> Haskell is a strictly pure, lazily evaluated language. It >>> therefore has no pointers or references, just values and names. >>> The implementation therefore cannot be in terms of references >>> and pointers. >> At this point consider whether it's possible to implement Pascal in >> Haskell. >> >> If it is possible, then you have a problem wrt. drawing conclusions >> about pointers in Pascal, uh oh, they apparently can't exist. >> >> But if it is not possible to implement Pascal in Haskell, then Haskell >> must be some etremely limited special-purpose language, not Turing >> complete -- is that acceptable to you? >> >> > This, if it says anything at all, appears to say that any > Turing-complete language has pointers in it, which is an absurdity. >>> As far as I can see, if someone says "implementing Python implies the >>> use of pointers" as you appear to be doing, then Michael's argument >>> neatly demolishes that argument by providing a counter-example: there is >>> an implementation of Python that does not use pointers. >> That's meaningless. >> >> But then so is maintaining that Python doesn't have references. >> >> And so is your argument applied to Pascal, just to mention that again. >> > *You* brought Pascal into this, not me. Of course. And so? Do you think that the/your argument applies to Pascal? Just for your information, it does not work for Pascal. Or any language. It is a fallacy. It does not say anything about Python, or Pascal, or any language. >>> You, however, dismiss this as a fallacy, and suggests it somehow >>> misrepresents you. And yet you wonder why people call your behavior (not >>> you) paranoid. >> On top of the multiple fallacies, dubious snipping of arguments, >> statements that such arguments have not been presented (just after >> snipping them), and general misleading insinuations and >> misrepresentation, ad yet another bit of personal attack. >> >> Do you understand what that may say to readers about you, Steve Holden? >> > I'm happy to let readers draw their own conclusions about us both. I guess you are. For it is invariably so that most readers recall by association, and a flood of flaming does yield an impression. As a technical argument it's a fallacy, but do you care? No. >> Apparently it's all to defend an indefensible, idiotic position. But I >> think you're doing it at least partially for the fun of harassing someone. >> > Not at all. You have accused me of bullying behavior, but in truth you > are the bully, and we know what happens when you give in to bullies, > don't we? After an uncountable number of flames of my person, many from you, I'm the bullied, or victim, so to speak; as such I'm not the bully. >>> [...] >>>>> I sincerely hope that my reply does not offend or inflame you, since >>>>> that is not the intent. I do hope it educates you and puts >>>>> into context the responses you have gained from others. >>>>> >>>>> After all, one simply shouting in a corner saying "YOU'RE ALL >>>>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>>>> understand what one is talking about does not tend to engender warm >>>>> fluffy feelings or sentiments of authority towards such an >>>>> individual. Be it me, you, or anyone else. >>>>> >>>>> At the moment, you appear to me to be engaging in such a behaviour. >>>>> Now you don't know from Jack and probably don't care about my >>>>> viewpoint, but I would really appreciate it if you would try not to >>>>> be inflammatory in your response to this. (Since you do appear to >>>>> also have a need to have the last word) >>>>> >>>>> Hoping this was useful on some level, >>>> Yes. >>>> >>>> I elected to respond to just /one/ of the many arguments you >>>> presented. >>>> >>>> The other arguments, about why there are no references in Python, >>>> shared, however, the basic property of being logical fallacies >>>> packaged in kilometers of rambling text. >>>> >>> And you can say this without, by your own admission, even reading it. >> No, you can not quote any place I have said that I haven't read his >> article. I did read most of it. So you are yet again within the span of >> one posted article presenting untrue information that you know is not true. >> > I repeat the quote from you which you can read at the top of this post: >>>> [Due to the appearance of reasoned discussion (it's not practical to >>>> read it all!) >>> [...] > So now you say you read "most" of it. I haven't said anything contradictory about that. If I had then you'd have quoted it. You don't quote anything, so you're out on your usual insinuate-things argumentation technique. > Even this statement is an > admission that there are parts you did not, and yet somehow *I* am the > liar? We are moving from the bizarre to the delusional here. I'm sorry that I had to point out your relating untrue information that you knew at the time was untrue. That also applies to your snipping of the argument about Haskell, and subsequent asking for such arguments as if they hadn't been given -- and snipped. The poster explained at the start that he had some technically immaterial stuff at the end of his article. I don't know whether I reached that. But anyway, the article was just a series of fallacies like the one thinking an implementation in Haskell could prove anything about the language so implemented, all wrapped up in kilometers of rambling text. Your attack of "bizarre" and "delusion" are the usual from Steve Holden. You are injecting noise to bury an argument that you didn't like. You tried first snipping it from your response. Now you're trying the noise angle again. Cheers & hth., - Alf From sccolbert at gmail.com Sat Feb 13 21:19:59 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sat, 13 Feb 2010 21:19:59 -0500 Subject: working with laptop battery In-Reply-To: <20100214014324.GA4868@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: <7f014ea61002131819x4ba766dds245220760ef74ff1@mail.gmail.com> You'll need acpi installed: In [6]: import subprocess In [7]: p = subprocess.Popen('acpi', stdout=subprocess.PIPE) In [8]: output, errors = p.communicate() In [9]: print output ------> print(output) Battery 0: Full, 100%, rate information unavailable On Sat, Feb 13, 2010 at 8:43 PM, Daniel Dalton wrote: > On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: > > It's probably gonna depend on which OS you're running. Which would be...? > > Sorry, forgot to mention this. I'm running debian linux. > > Thanks, > Dan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Sat Feb 13 21:22:11 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 14 Feb 2010 03:22:11 +0100 Subject: working with laptop battery In-Reply-To: <20100214014324.GA4868@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: >> It's probably gonna depend on which OS you're running. Which would be...? > > Sorry, forgot to mention this. I'm running debian linux. I don't know about python modules but have a look at /proc/acpi/battery/BAT0/info /proc/acpi/battery/BAT0/state You can parse the numbers you want from there. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python.list at tim.thechases.com Sat Feb 13 21:23:28 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 13 Feb 2010 20:23:28 -0600 Subject: working with laptop battery In-Reply-To: <20100214014324.GA4868@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: <4B775EA0.7080207@tim.thechases.com> Daniel Dalton wrote: > On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: >> It's probably gonna depend on which OS you're running. Which would be...? > > Sorry, forgot to mention this. I'm running debian linux. You should be able to read/poll the various files in /proc/acpi/battery/BAT*/* for whatever battery information you need. Each BAT* directory contains information about one of the batteries in the system (it's possible, albeit rare, to have more than one). So you might have some script that runs every $INTERVAL that looks something like from glob import glob for fname in glob('/proc/acpi/battery/BAT*/*'): f = file(fname) for line in f: do_something(line) f.close() On my Debian laptop (Gateway Solo 1200, OEM battery circa 2001), the contents look something like tim at rubbish:/proc/acpi/battery/BAT0$ cat alarm alarm: unsupported tim at rubbish:/proc/acpi/battery/BAT0$ cat info present: yes design capacity: 4016 mAh last full capacity: 4011 mAh battery technology: rechargeable design voltage: 9600 mV design capacity warning: 602 mAh design capacity low: 401 mAh capacity granularity 1: 201 mAh capacity granularity 2: 3409 mAh model number: QT08 serial number: SANYOQT08 battery type: NiMH OEM info: SANYO tim at rubbish:/proc/acpi/battery/BAT0$ cat state present: yes capacity state: ok charging state: charged present rate: unknown remaining capacity: 4011 mAh present voltage: 9600 mV -tkc From aahz at pythoncraft.com Sat Feb 13 21:29:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 18:29:17 -0800 Subject: To (monkey)patch or not to (monkey)patch, that is the question References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: In article <1410d2e2-a6f2-4b6c-a745-6d3e34994568 at q16g2000yqq.googlegroups.com>, > George Sakkis wrote: > >I was talking to a colleague about one rather unexpected/undesired >(though not buggy) behavior of some package we use. Although there is >an easy fix (or at least workaround) on our end without any apparent >side effect, he strongly suggested extending the relevant code by hard >patching it and posting the patch upstream, hopefully to be accepted >at some point in the future. In fact we maintain patches against >specific versions of several packages that are applied automatically >on each new build. The main argument is that this is the right thing >to do, as opposed to an "ugly" workaround or a fragile monkey patch. >On the other hand, I favor practicality over purity and my general >rule of thumb is that "no patch" > "monkey patch" > "hard patch", at >least for anything less than a (critical) bug fix. > >So I'm wondering if there is a consensus on when it's better to (hard) >patch, monkey patch or just try to work around a third party package >that doesn't do exactly what one would like. Does it have mainly to do >with the reason for the patch (e.g. fixing a bug, modifying behavior, >adding missing feature), the given package (size, complexity, >maturity, developer responsiveness), something else or there are no >general rules and one should decide on a case-by-case basis ? There's a related option that I chose for SQLObject: extending by using internal APIs. Because SQLite doesn't work well with multiple writers (or even multiple readers with one writer when queries take a long time), we needed a retry mechanism when a query failed. I originally tried proxying the SQLite class, but that ran into problems partly related to new-style classes grabbing magic methods directly from the class, and subclassing and using the internal registration API turned out to be easier. The only change required in the existing code was to change the connection string to "sqlite_retry:". Then I ran into build problems because some machines were on SQLObject 0.10.x and others were on 0.11.x and the internal API changed between those versions. It was easily fixed by upgrading everything to 0.11.x, but it's a reminder about the fragility of relying on internal APIs. If that's not an option in your case, personally I'd prefer monkey-patching because otherwise I need to check the package into my repository. Submitting a patch upstream would be responsible behavior. Overall, I think that this is definitely an issue where heuristics work much better than rules. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Sat Feb 13 21:41:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 18:41:42 -0800 Subject: Modifying Class Object References: Message-ID: In article , Alf P. Steinbach wrote: > >My original statement, with reference to the Java language spec, >didn't say much more about the language than that it has assignable >references. Assuming this is what you're referring to: Python passes pointers by value, just as e.g. Java does. Then you are simply, completely, totally, and absolutely wrong. Period. Regardless of how CPython manages its state internally, Python as a programming language does not have pointers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From rantingrick at gmail.com Sat Feb 13 21:43:20 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Feb 2010 18:43:20 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> <96255e38-b30b-42f2-9cd4-baa6a7b7eeb9@j31g2000yqa.googlegroups.com> <89f86e28-0ed3-4232-b489-db088d320658@q21g2000yqm.googlegroups.com> Message-ID: <2f487e21-8320-41ec-b4e3-cf51e7a198d4@c16g2000yqd.googlegroups.com> On Feb 13, 8:00?pm, vsoler wrote: > On Feb 14, 2:45?am, rantingrick wrote: (..snip..) > Excellent!!! Just what I needed! For your case, since it seems you are writing a "console type" application you may want to subdue the root window and show the user a file dialog window *only*. You can do this by using "root.withdraw()" to hide the root window. Just make sure to destroy the root window after the users is finished choosing their file (or at some appropriate time later) or else your program will not exit gracefully at close time...! Heres a way to wrap the whole enchilada into a reusable function, of course many refinements could be made but this is a simplistic version... #-- start script --# # works on python < 3.0 import Tkinter as tk from tkFileDialog import askopenfilename def showFileDialog(): root = tk.Tk() root.withdraw() path = askopenfilename(filetypes=[('TXT', '.txt')]) if path: print path # do something useful here... root.destroy() root.mainloop() showFileDialog() raw_input('press enter to quit...') #-- end script --# From showell30 at yahoo.com Sat Feb 13 21:54:34 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 18:54:34 -0800 (PST) Subject: Modifying Class Object References: Message-ID: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> On Feb 13, 6:41?pm, a... at pythoncraft.com (Aahz) wrote: > In article , > Alf P. Steinbach wrote: > > > > >My original statement, with reference to the Java language spec, > >didn't say much more about the language than that it has assignable > >references. > > Assuming this is what you're referring to: > > ? ? Python passes pointers by value, just as e.g. Java does. > > Then you are simply, completely, totally, and absolutely wrong. ?Period. > Regardless of how CPython manages its state internally, Python as a > programming language does not have pointers. ? I agree with your statement for a suitably narrow definition of the words "pointer" and "have." From showell30 at yahoo.com Sat Feb 13 22:04:28 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 19:04:28 -0800 (PST) Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> Message-ID: On Feb 13, 6:10?pm, MRAB wrote: > Alf P. Steinbach wrote: > > * Steve Howell: > >> This thread is interesting on many levels. ?What is the core question > >> that is being examined here? > > > I think that regarding the technical it is whether a Python name refers > > to an object or not. I maintain that it does, and that the reference can > > be copied, and that the semantics of the language requires this and is > > defined in terms of this. Steve Holden, D'Aprano and many others > > maintain that there are no references, or that if there are then they're > > only an implementation aspect, i.e. that conceiveable one could have an > > implementation without them. > > > Regarding some other issues it seems to be a childish exercise in > > flaming, a flame war, with claims of insanity, incompetence, lying > > (that's actually from me, I reacted a bit strongly to faked quoting + > > conclusions from that in a posting not appearing on Usenet but on the > > Python mail list), etc. etc. ad nauseam, sprinkled with > > misrepresentations etc. I don't know the point of that. > > It's a pity that no-one has gone far enough to trigger Godwin's Law... > ;-) Godwin's Law need not be invoked here. The essential question is relevant and worthy of discussion, and most posters have presented intelligent, nuanced arguments even amidst all the needless flaming. It is actually a subtle point that I think people disagree on, whatever the extraneous personal baggage. From chyavana at gmail.com Sat Feb 13 22:19:02 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Sun, 14 Feb 2010 11:19:02 +0800 Subject: Sorting a list of lists In-Reply-To: <4B759ED1.3090507@optimum.net> References: <4B7593BF.1030708@gmail.com> <4B759ED1.3090507@optimum.net> Message-ID: <4B776BA6.8060108@gmail.com> MRAB wrote: > You'd have to post an example of that, but you could try deleting some > of the entries before sorting so see whether you can still reproduce the > problem with a smaller list. John Posner wrote: > Please cut-and-paste the exact error message (or other evidence of > "failure") into a message. Thank you both. It appears that the problem was in the way the data were being read in from a file, than in the sorting itself. Once I fixed that, the results are as expected. Chandra From alfps at start.no Sat Feb 13 22:44:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 04:44:26 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Aahz: > In article , > Alf P. Steinbach wrote: >> My original statement, with reference to the Java language spec, >> didn't say much more about the language than that it has assignable >> references. > > Assuming this is what you're referring to: > > Python passes pointers by value, just as e.g. Java does. > > Then you are simply, completely, totally, and absolutely wrong. Period. > Regardless of how CPython manages its state internally, Python as a > programming language does not have pointers. The next paragraph was about the meaning of "pointer" in that first paragraph, referring to the Java language specification for the particular meaning here, namely a reference. Note: I did not refer to CPython, C, Pascal or whatever (but you mention CPython) for a meaning of "pointer". Instead I referred to the Java language specification for that meaning, where it's pretty clear: reference. So if you don't like the terminology, you can rephrase with perhaps more palatable terms: Python uses pass by sharing. References to objects are copied, the objects themselves are not copied. See If you go to that URL, which isn't auhoritative but good enough, you find that "identical semantics in other languages such as Java and Visual Basic" Hence, your point is only a matter of terminology. The semantics /can/ be described using the term "pointer" (or for that matter the term "thingamajic"), when that term is suitably defined, and it /is/ described using that word for some languages. The language doesn't matter for the concept of pass by sharing. Hence, the terminological issue doesn't invalidate the description, as long as the terminology is clearly defined, as I did with ref to the Java lang spec. As you can see proper terminology reduces the size of explanation considerably, but as I see it that's not a big deal as long as the description is still /reasonably/ short. It does become a concern when the description runs to many pages of text. A simple thing should IMHO be simply described. But I think, as I've already stated several times up-thread, that "pointer" is a term best avoided for explanations within the Python community, even with a reference to a particular definition/usage, making the more verbose version in terms of "references" preferable for Python -- don't you agree? Cheers, - Alf From steve at REMOVE-THIS-cybersource.com.au Sat Feb 13 22:53:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 03:53:42 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> Message-ID: <4b7773c6$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 18:54:34 -0800, Steve Howell wrote: > On Feb 13, 6:41?pm, a... at pythoncraft.com (Aahz) wrote: > > Regardless of how CPython manages its state internally, Python as a > > programming language does not have pointers. ? > > I agree with your statement for a suitably narrow definition of the > words "pointer" and "have." "Suitably narrow" is not that narrow. By no stretch of the imagination can one say that Python has a built-in pointer type analogous to pointers in (say) Pascal or C -- you can't usefully get the address of a variable (although the CPython implementation leaks the address of objects, it does so in a way that is safe and useless for everything but a label). There is no equivalent to (say) the Pascal program: program main(input, output); var x: integer; ptr: ^integer; begin x := 1; ptr := @x; ptr^ := ptr^ + 1; writeln(x); end. For a suitably wide definition of "pointer", then Python does have pointers: data = ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] i = data.index('bbb') print data[i] i += 1 data[i] = 'zzz' but I trust that we all agree that describing the integer offset i above as a "pointer" is a reductio ad absurdum. -- Steven From no.email at nospam.invalid Sat Feb 13 22:56:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 13 Feb 2010 19:56:03 -0800 Subject: Hashing in python References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <7x3a14cvxo.fsf@ruckus.brouhaha.com> Vish writes: > I need to hash 3d coordinates to a grid which has been divided into > 4*4*4 squares. Using python, I thought of a simple way as follows: Use the built-in hash function: >>> p = (1, 2, 3) >>> print hash(p) 2528502973977326415 You can of course mod that by the table size: >>> print hash(p) % (4*4*4) 15 From showell30 at yahoo.com Sat Feb 13 23:11:06 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 20:11:06 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> Message-ID: <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> On Feb 13, 7:53?pm, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 18:54:34 -0800, Steve Howell wrote: > > On Feb 13, 6:41?pm, a... at pythoncraft.com (Aahz) wrote: > > > Regardless of how CPython manages its state internally, Python as a > > > programming language does not have pointers. ? > > > I agree with your statement for a suitably narrow definition of the > > words "pointer" and "have." > > "Suitably narrow" is not that narrow. By no stretch of the imagination > can one say that Python has a built-in pointer type analogous to pointers > in (say) Pascal or C -- you can't usefully get the address of a variable > (although the CPython implementation leaks the address of objects, it > does so in a way that is safe and useless for everything but a label). > There is no equivalent to (say) the Pascal program: > > program main(input, output); > ? var > ? ? x: integer; > ? ? ptr: ^integer; > > begin > ? x := 1; > ? ptr := @x; > ? ptr^ := ptr^ + 1; > ? writeln(x); > end. > > For a suitably wide definition of "pointer", then Python does have > pointers: > > data = ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] > i = data.index('bbb') > print data[i] > i += 1 > data[i] = 'zzz' > > but I trust that we all agree that describing the integer offset i above > as a "pointer" is a reductio ad absurdum. > For a suitably wide definition of pointers CPython does indeed have pointers, and your example is only a weaker case of that truth. There is no reductio adsurbum. If I argued that CPython had curly braced syntax that would be absurd, since it is so concretely wrong. Pointers are a more abstact concept. From sridharr at activestate.com Sat Feb 13 23:16:59 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Sat, 13 Feb 2010 20:16:59 -0800 Subject: ANN: ActivePython 2.5.5.7 is now available In-Reply-To: References: <1E441CA2-F197-4F5B-B4F5-A5FE2E3D7882@activestate.com> Message-ID: <1D5C19A6-A80E-4952-9099-120C394618E0@activestate.com> On 2010-02-13, at 1:25 AM, Dennis Lee Bieber wrote: > On Thu, 11 Feb 2010 16:22:49 -0800, Sridhar Ratnakumar > declaimed the following in > gmane.comp.python.general: > >> I'm happy to announce that ActivePython 2.5.5.7 is now available for >> download from: >> >> http://www.activestate.com/activepython/ >> > This seems to be the first Windows installer I recall that can't > "update" over an earlier 2.5.x version... It want's me to wipe out > (uninstall) my existing base before it will allow for installation (bad > enough it need admin privileges -- I'm going to be dead at work the next > time they "refresh" my desktop machine as they no longer allow users to > have local admin rights) This is probably due to http://firefly.activestate.com/shanec/activepython/ticket/11 where the MSI product code for 64-bit installer was changed to be different from the 32-bit one. Specifically the product codes used are: <=2.5.4.4: "a2e24bd9-085b-410f-aad0-5eb5fa5d73d2" >=2.5.4.6 32-bit: "a2e24bd9-085b-410f-aad0-5eb5fa5d73d2", >=2.5.4.5 64-bit: "64e24bd9-085b-410f-aad0-5eb5fa5d73d2", Consequently 64-bit installers for 2.X will have different MSI product code from 2.5.4.6 onwards. Was your "update" issue happening only with the 64-bit installer of 2.5.5.7? -srid -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Feb 14 00:13:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 05:13:33 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> Message-ID: <4b77867d$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 20:11:06 -0800, Steve Howell wrote: > For a suitably wide definition of pointers CPython does indeed have > pointers, and your example is only a weaker case of that truth. There > is no reductio adsurbum. If I argued that CPython had curly braced > syntax that would be absurd, since it is so concretely wrong. Pointers > are a more abstact concept. I would argue that your examples are equivalent. The suitably wide definition of pointers that allows you to argue that Python has pointers is an implementation detail, just as the implementation detail that the Python tokenizer uses INDENT and DEDENT tokens. An INDENT token is just another way of spelling { and DEDENT is just another way of spelling }, so therefore Python has curly bracket syntax. Do I believe this argument is valid? No, of course not, I think it does so much violence to the concepts of curly brackets and syntax as to be absurd. Just as I think the only way to justify claiming that Python has pointers is to do so much violence to the concept of pointer and to Python's object model as to also be absurd. That's not to say that the general concept of references (as in "to refer to") isn't valuable when discussing Python. If you want to say that (e.g.) following x = 1 the name "x" refers to (or even points to!) the object 1, my objections will be mild or non-existent. In that sense, it's probably impossible to program without some sort of "references": the computer manipulates variables or objects directly, while we manipulate characters in source code. The only way to write a program is to use some abstract thing (a name, an offset, whatever) that refers, in some fashion, to a collection of bits in the computer's memory. But to go from that to the idea that (say) x is a pointer does so much violence to the concept of pointer and has so much room for confusion that it is actively harmful. -- Steven From showell30 at yahoo.com Sun Feb 14 00:33:50 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 21:33:50 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> Message-ID: <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> On Feb 13, 9:13?pm, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 20:11:06 -0800, Steve Howell wrote: > > For a suitably wide definition of pointers CPython does indeed have > > pointers, and your example is only a weaker case of that truth. ?There > > is no reductio adsurbum. ?If I argued that CPython had curly braced > > syntax that would be absurd, since it is so concretely wrong. Pointers > > are a more abstact concept. > > I would argue that your examples are equivalent. > > The suitably wide definition of pointers that allows you to argue that > Python has pointers is an implementation detail, just as the > implementation detail that the Python tokenizer uses INDENT and DEDENT > tokens. An INDENT token is just another way of spelling { and DEDENT is > just another way of spelling }, so therefore Python has curly bracket > syntax. > You seem to be missing the point that "curly braces" is a concrete term that very specifically applies to spelling. > Do I believe this argument is valid? No, of course not, I think it does > so much violence to the concepts of curly brackets and syntax as to be > absurd. Just as I think the only way to justify claiming that Python has > pointers is to do so much violence to the concept of pointer and to > Python's object model as to also be absurd. > > That's not to say that the general concept of references (as in "to refer > to") isn't valuable when discussing Python. If you want to say that > (e.g.) following > > x = 1 > > the name "x" refers to (or even points to!) the object 1, my objections > will be mild or non-existent. In that sense, it's probably impossible to > program without some sort of "references": the computer manipulates > variables or objects directly, while we manipulate characters in source > code. The only way to write a program is to use some abstract thing (a > name, an offset, whatever) that refers, in some fashion, to a collection > of bits in the computer's memory. But to go from that to the idea that > (say) x is a pointer does so much violence to the concept of pointer and > has so much room for confusion that it is actively harmful. > I agree that "reference" is a much better term than "pointer.". It has the right amount of generalness in my opinion. I think "violence" is a bit overstated, but your bigger point is well taken and it seems like "reference" is useful middle ground between pure cpython language and misrepresentative analogy. From cs at zip.com.au Sun Feb 14 01:12:06 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 14 Feb 2010 17:12:06 +1100 Subject: iglob performance no better than glob In-Reply-To: <449a19de-42f7-4ae3-8099-99c27572adc8@m16g2000yqc.googlegroups.com> References: <449a19de-42f7-4ae3-8099-99c27572adc8@m16g2000yqc.googlegroups.com> Message-ID: <20100214061206.GA31131@cskk.homeip.net> On 31Jan2010 16:23, Kyp wrote: | On Jan 31, 2:44?pm, Peter Otten <__pete... at web.de> wrote: | > Kyp wrote: | > > I have a dir with a large # of files that I need to perform operations | > > on, but only needing to access a subset of the files, i.e. the first | > > 100 files. | > > Using glob is very slow, so I ran across iglob, which returns an | > > iterator, which seemed just like what I wanted. I could iterate over | > > the files that I wanted, not having to read the entire dir. [...] | > > So the iglob was faster, but accessing the first file took about the | > > same time as glob.glob. | > | > > Here's some code to compare glob vs. iglob performance, ?it outputs | > > the time before/after a glob.iglob('*.*') files.next() sequence and a | > > glob.glob('*.*') sequence. | > | > > #!/usr/bin/env python | > | > > import glob,time | > > print '\nTest of glob.iglob' | > > print 'before ? ? ? iglob:', time.asctime() | > > files = glob.iglob('*.*') | > > print 'after ? ? ? ?iglob:',time.asctime() | > > print files.next() | > > print 'after files.next():', time.asctime() | > | > > print '\nTest of glob.glob' | > > print 'before ? ? ? ?glob:', time.asctime() | > > files = glob.glob('*.*') | > > print 'after ? ? ? ? glob:',time.asctime() | > | > > Here are the results: | > | > > Test of glob.iglob | > > before ? ? ? iglob: Sun Jan 31 11:09:08 2010 | > > after ? ? ? ?iglob: Sun Jan 31 11:09:08 2010 | > > foo.bar | > > after files.next(): Sun Jan 31 11:09:59 2010 | > | > > Test of glob.glob | > > before ? ? ? ?glob: Sun Jan 31 11:09:59 2010 | > > after ? ? ? ? glob: Sun Jan 31 11:10:51 2010 | > | > > The results are about the same for the 2 approaches, both took about | > > 51 seconds. Am I doing something wrong with iglob? | > | > No, but iglob() being lazy is pointless in your case because it uses | > os.listdir() and fnmatch.filter() underneath which both read the whole | > directory before returning anything. | > | > > Is there a way to get the first X # of files from a dir with lots of | > > files, that does not take a long time to run? | > | > Here's my attempt. [...open directory and read native format...] I'd be inclined first to time os.listdir('.') versus glob.lgo('*.*'). Glob routines tend to lstat() every matching name to ensure the path exists. That's very slow. If you just do os.listdir() and choose your 100 nmaes, you only need to stat (or just try to open) them. So time glob.glob("*.*") versus os.listdir(".") first. Generally, with a large directory, stat time will change performance immensely. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Usenet is essentially a HUGE group of people passing notes in class. --R. Kadel From steve at REMOVE-THIS-cybersource.com.au Sun Feb 14 02:21:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 07:21:44 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> Message-ID: <4b77a488$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 21:33:50 -0800, Steve Howell wrote: > You seem to be missing the point that "curly braces" is a concrete > term that very specifically applies to spelling. And you seem to be missing the point that "pointer" is also a concrete term that very specifically applies to, well, pointers. [...] > I agree that "reference" is a much better term than "pointer.". It has > the right amount of generalness in my opinion. I think "violence" is a > bit overstated, but your bigger point is well taken and it seems like > "reference" is useful middle ground between pure cpython language and > misrepresentative analogy. But reference also has a concrete meaning: C++ has a type explicitly called "reference": http://en.wikipedia.org/wiki/Reference_(C++) And of course call-by-reference (or pass-by-reference) has a specific, technical meaning. -- Steven From alfps at start.no Sun Feb 14 02:40:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 08:40:50 +0100 Subject: Modifying Class Object In-Reply-To: <4b77a488$0$8767$c3e8da3@news.astraweb.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sat, 13 Feb 2010 21:33:50 -0800, Steve Howell wrote: > >> You seem to be missing the point that "curly braces" is a concrete >> term that very specifically applies to spelling. > > And you seem to be missing the point that "pointer" is also a concrete > term that very specifically applies to, well, pointers. > > [...] >> I agree that "reference" is a much better term than "pointer.". It has >> the right amount of generalness in my opinion. I think "violence" is a >> bit overstated, but your bigger point is well taken and it seems like >> "reference" is useful middle ground between pure cpython language and >> misrepresentative analogy. > > But reference also has a concrete meaning: C++ has a type explicitly > called "reference": > > http://en.wikipedia.org/wiki/Reference_(C++) > > And of course call-by-reference (or pass-by-reference) has a specific, > technical meaning. Hm. Consider your argument about "reference" being possible to confuse with "pass by reference" in the light of "pass by name", used by Algol, . Oops, to consistently remove all possible ambiguity the term "name" can't be used about formal arguments. I think, even though "pass by name" is much less well known than "pass by reference", this indicates that it's not practically possible to remove all possible ambiguity. I think some Common Sense(TM) must in any case be assumed, and applied. Cheers, - Alf From showell30 at yahoo.com Sun Feb 14 02:45:47 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 23:45:47 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> Message-ID: On Feb 13, 11:21?pm, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 21:33:50 -0800, Steve Howell wrote: > > You seem to be missing the point that "curly braces" is a concrete > > term that very specifically applies to spelling. > > And you seem to be missing the point that "pointer" is also a concrete > term that very specifically applies to, well, pointers. > The term "pointer" is very abstract. Please give me a concrete definition of a pointer. A curly brace is one of these: { } Pretty concrete, I hope. > [...] > > > I agree that "reference" is a much better term than "pointer.". It has > > the right amount of generalness in my opinion. I think "violence" is a > > bit overstated, but your bigger point is well taken and it seems like > > "reference" is useful middle ground between pure cpython language and > > misrepresentative analogy. > > But reference also has a concrete meaning: C++ has a type explicitly > called "reference": > > http://en.wikipedia.org/wiki/Reference_(C++) > Of course, "reference" has concrete meanings in specific contexts. But I can refer you to much more general and abstract uses of the term "reference." Do you want references? I will be happy to refer you to appropriate references. > And of course call-by-reference (or pass-by-reference) has a specific, > technical meaning. > Which is what? From showell30 at yahoo.com Sun Feb 14 03:15:02 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 00:15:02 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: On Feb 10, 6:16?am, Steven D'Aprano wrote: > > Alf, although your English in this forum has been excellent so far, I > understand you are Norwegian, so it is possible that you aren't a native > English speaker and possibly unaware that quotation marks are sometimes > ambiguous in English. > > While it is true that quoted text is officially meant to indicate a > direct quote, it is also commonly used in informal text to indicate a > paraphrase. (There are other uses as well, but they don't concern us now.) > > Unfortunately, this means that in informal discussions like this it is > sometimes difficult to distinguish a direct quote from a paraphrase, > except by context. In context, as a native speaker, I can assure you that > Stephen Hansen's use of quotation marks is a paraphrase and not meant to > be read as a direct quote. As another native speaker of English, I can assure Alf that using quotation marks in a paraphrase in written English is actually strictly admonished against in some English speaking countries. At least according to my English teachers. To the extent that many people on the Internet don't speak English natively, I think the most conservative and reasonable convention applies--use quotes to quote directly; if you're not quoting directly, omit quotes and make clear the fact that you are paraphrasing. Which isn't to say we don't all make mistakes. I have no idea about what Stephen Hanson said. Most misattributions are actually paraphrases, whether they be in quotes or not. From apt.shansen at gmail.com Sun Feb 14 03:21:03 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 14 Feb 2010 00:21:03 -0800 Subject: Modifying Class Object In-Reply-To: <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: <7a9c25c21002140021i14f45531r3c4414bdb7a24b15@mail.gmail.com> On Sat, Feb 13, 2010 at 7:59 AM, Michael Sparks wrote: > Hi Alf, > > > On Feb 12, 8:22 pm, "Alf P. Steinbach" wrote: > > Thanks for the effort at non-flaming discussion, it *is* > > appreciated. > > I would appreciate it if you tried to be non-flaming yourself, > since you can see I am not flaming you. > I'm currently in a self-imposed exile from commenting on any particular details of the technical issue in this thread as I believe it futile, but I have to say: wow, kudos to you for putting SO much into saying what I tried to say, and doing so better then I was able to. Kudos. Times two. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Sun Feb 14 03:50:04 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 14 Feb 2010 00:50:04 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002140050j4dddcc3dkdffc1df523ee7bf2@mail.gmail.com> On Sun, Feb 14, 2010 at 12:15 AM, Steve Howell wrote: > On Feb 10, 6:16 am, Steven D'Aprano cybersource.com.au> wrote: > > > > Alf, although your English in this forum has been excellent so far, I > > understand you are Norwegian, so it is possible that you aren't a native > > English speaker and possibly unaware that quotation marks are sometimes > > ambiguous in English. > > > > While it is true that quoted text is officially meant to indicate a > > direct quote, it is also commonly used in informal text to indicate a > > paraphrase. (There are other uses as well, but they don't concern us > now.) > > > > Unfortunately, this means that in informal discussions like this it is > > sometimes difficult to distinguish a direct quote from a paraphrase, > > except by context. In context, as a native speaker, I can assure you that > > Stephen Hansen's use of quotation marks is a paraphrase and not meant to > > be read as a direct quote. > > As another native speaker of English, I can assure Alf that using > quotation marks in a paraphrase in written English is actually > strictly admonished against in some English speaking countries. At > least according to my English teachers. To the extent that many > people on the Internet don't speak English natively, I think the most > conservative and reasonable convention applies--use quotes to quote > directly; if you're not quoting directly, omit quotes and make clear > the fact that you are paraphrasing. > > Which isn't to say we don't all make mistakes. > > I have no idea about what Stephen Hanson said. Most misattributions > are actually paraphrases, whether they be in quotes or not. Well, no, I have to stand in my defense at this point. Given the context of the communication medium, an actual "quote" has IMHO a clearly defined context. It is lines, unchanged and unedited, prepended with a certain appropriate set of characters, and clearly cited with some variation of something like "On , Someone said:" A quote, in context, is an attempt to directly reference another individual's words as they spoke them. Any alteration of such words, any adjustment of such words to your own end, is dishonest. What I did was say something like this paragraph (with no quote characters before it): And then you hand-waved my arguments with a response of, "this that blah bleh" Minus the indention. There was IMHO, NO misattribution, NO reasonable assumption that I specified actual or explicit words of Alf or anyone else. There MAY be an argument someone can make claiming my statement wasn't clear, but to declare it is a deliberate /lie/ is another thing entirely. There is a difference between using quote marks and making an actual quotation-- a quotation requires a citation-- and in informal discourse use of quote marks to represent clear paraphrasing of the interpretation of position is valid, imho. In a formal paper or thesis, I'd use a different format. But this is not formal. In context that statement can not possibly be reasonable considered an actual quotation, even with quote marks. And I'm responding because: yes, I'm finding this "You are a liar." response particularly personally offensive. I should get over it. I'm just used to people disagreeing with me. Dismissing me as a liar is something new. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at subsignal.org Sun Feb 14 04:16:18 2010 From: paul at subsignal.org (=?ISO-8859-9?Q?Paul_K=F6lle?=) Date: Sun, 14 Feb 2010 10:16:18 +0100 Subject: plugin / intra process communication system In-Reply-To: <1266054643.26540.58.camel@brain> References: <1266054643.26540.58.camel@brain> Message-ID: Am 13.02.2010 10:50, schrieb Florian Ludwig: > Hi, > > I'm looking for a module/plugin/intra-process-communication/hook system > for python. Maybe someone here could point me to some project I missed > or might have some good ideas if I end up implementing it myself. > > Most systems I have found are "one to many" communications but I would > like "many to many", to clarify what I mean an *example* use-case: > > Lets say you program a wiki and like to allow different kind of > authentications. So you create two plugins (for example one for > OpenID and one for Shibboleth). > > Some time later you feel like reinventing the wheel again and > you program a blog. Again you like to allow different ways of > authentication and you already wrote plugins for exactly the > same for your wiki, right? > > With most systems now some trouble begins - the blog software would need > to have the interface/extention-points/however-you-name-it that the wiki > software defined. > > The plugins you wrote probably import them from the wiki module directly > which means your blog would depend on the wiki. (?!) So where to put the > interface/[...] definition that is imported by those plugins? Create a > package/module just containing the interface? This really get > troublesome if different people wrote the wiki, the blog and another > third one a plugin. If you are talking about code sharing you can move the common code out of your applications in a seperate namespace. If you follow the model trac is using you would install a module/package/egg with the basic functionality of the pluginsystem (i.e. what's in core.py and env.py + logging and whatever you think is necessary). All shared code like your auth-plugins would go in a common plugin directory to which you can refer via PYTHONPATH. Another common technique is chaining of WSGI middleware..., check out pythonpaste.org. Then there is SOA where functionality is shared via RPC/webservices and wsdl/uddi. But my feeling is this is mostly used in "Enterprise" applications and is best used in Java/.NET where you already have libraries doing all the XML stuff. hth Paul From martin at v.loewis.de Sun Feb 14 04:25:14 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 14 Feb 2010 10:25:14 +0100 Subject: Hashing in python In-Reply-To: References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <4B77C17A.1020306@v.loewis.de> > floor(x) returns an integer Why do you say that? Assuming you are talking about math.floor, it works differently for me: py> math.floor(10.0/3) 3.0 Regards, Martin From martin at v.loewis.de Sun Feb 14 04:30:36 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 14 Feb 2010 10:30:36 +0100 Subject: Hashing in python In-Reply-To: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <4B77C2BC.5080201@v.loewis.de> > CELL_SIZE = 4 > > def key(point): > > return ( > int((floor(point[0]/CELL_SIZE))*CELL_SIZE), > int((floor(point[1]/CELL_SIZE))*CELL_SIZE), > int((floor(point[2]/CELL_SIZE))*CELL_SIZE) > ) > > > Since python allows keys to be tuples, I think that this should work. > Is there a better (more efficient) way to do it? You don't say why you want to do hashing in the first place. If it is to access elements in a lookup table, and you are now using a dictionary, I'd suggest to replace that with a list. For 4x4x4 elements, you could either do table[int(point[0]/CELL_SIZE)][int(point[1]/CELL_SIZE)][int(point[2]/CELL_SIZE)] (i.e. have nested lists), or you allocate a list of 64 elements, and use def key(point): return 16*int(point[0]/CELL_SIZE) + 4*int(point[1]/CELL_SIZE) +\ int(point[2]/CELL_SIZE) table[key(point)] You could even use that key function as a key to a dictionary, if you can't use lists for some reason. Regards, Martin From karsten.goen at googlemail.com Sun Feb 14 04:33:54 2010 From: karsten.goen at googlemail.com (Karsten Goen) Date: Sun, 14 Feb 2010 10:33:54 +0100 Subject: problem with floats and calculations Message-ID: hey all, I got a problem with floats and calculations. I made an mini-application where you get random questions with some science calculations in it So the user can type in his result with the values given by random creation. And the user value is compared against the computer value... the problem is that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 here is the example: http://dpaste.com/hold/158698/ without decimal it would be very inaccurate. decimal is very accurate when I have to compare d with users calculations from a,b,c,var. But when I ask the user what is "a" the result gets inaccurate when calculating with the same values given before (b,c,d,var). Maybe anyone can help me with this problem, I don't want to generate for every possible user input a single formula. And also it should be possible for a computer, my calculator at home does the same and is much smaller and slower. thx in advance Karsten -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan-usenet at bytereef.org Sun Feb 14 05:29:56 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Sun, 14 Feb 2010 11:29:56 +0100 Subject: problem with floats and calculations In-Reply-To: References: Message-ID: <20100214102956.GA6524@yoda.bytereef.org> Karsten Goen wrote: > hey all, > I got a problem with floats and calculations. I made an mini-application where > you get random questions with some science calculations in it > So the user can type in his result with the values given by random creation. > And the user value is compared against the computer value... the problem is > that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 > > here is the example: > http://dpaste.com/hold/158698/ > > without decimal it would be very inaccurate. decimal is very accurate when I > have to compare d with users calculations from a,b,c,var. > But when I ask the user what is "a" the result gets inaccurate when calculating > with the same values given before (b,c,d,var). > > Maybe anyone can help me with this problem, I don't want to generate for every > possible user input a single formula. And also it should be possible for a > computer, my calculator at home does the same and is much smaller and slower. d = (a * b)/ (c * var) d = Decimal(d).quantize(Decimal('0.01')) By quantizing d, the above equality does not hold any longer. You've got to drop that line (your calculator doesn't quantize either). Stefan Krah From karsten.goen at googlemail.com Sun Feb 14 05:50:49 2010 From: karsten.goen at googlemail.com (Karsten Goen) Date: Sun, 14 Feb 2010 11:50:49 +0100 Subject: problem with floats and calculations In-Reply-To: <20100214102956.GA6524@yoda.bytereef.org> References: <20100214102956.GA6524@yoda.bytereef.org> Message-ID: also this doesn't help, there are still errors in the accuracy. Isn't there a perfect way to do such calculations? Karsten Goen wrote: > > hey all, > > I got a problem with floats and calculations. I made an mini-application > where > > you get random questions with some science calculations in it > > So the user can type in his result with the values given by random > creation. > > And the user value is compared against the computer value... the problem > is > > that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 > > > > here is the example: > > http://dpaste.com/hold/158698/ > > > > without decimal it would be very inaccurate. decimal is very accurate > when I > > have to compare d with users calculations from a,b,c,var. > > But when I ask the user what is "a" the result gets inaccurate when > calculating > > with the same values given before (b,c,d,var). > > > > Maybe anyone can help me with this problem, I don't want to generate for > every > > possible user input a single formula. And also it should be possible for > a > > computer, my calculator at home does the same and is much smaller and > slower. > > d = (a * b)/ (c * var) > d = Decimal(d).quantize(Decimal('0.01')) > > By quantizing d, the above equality does not hold any longer. You've got > to drop that line (your calculator doesn't quantize either). > > > Stefan Krah > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Sun Feb 14 06:28:59 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 14 Feb 2010 12:28:59 +0100 Subject: MemoryError, can I use more? In-Reply-To: <7to2vmF2kvU1@mid.uni-berlin.de> References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: <4B77DE7B.1020001@shopzeus.com> 2010.02.13. 17:40 keltez?ssel, Diez B. Roggisch ?rta: > Am 13.02.10 17:18, schrieb Anssi Saari: >> Nobody writes: >> >>> A single process can't use much more than 2GiB of RAM without a >>> 64-bit CPU >>> and OS. >> >> That's not really true. Even Windows XP has the /3GB boot option to >> allow 3 GiB per process. On PCs, free operating systems and server >> Windows can use PAE to give access to full 4 GB per process. > > No, PAE can be used to access much more memory than 4GB - albeit > through paging. AFAIK up to 2^36 Bytes. PAE is for the kernel. Yes, you can use much more memory with 32 bit kernel + PAE. But the ~3G per 32bit process limit still applies. It is because the PAE extension allows the kernel to distribute the same virtual address ranges between different processes, but map them to different physical memory addresses. However, the process that was compiled and is running in 32 bit mode, cannot access more than ~3GB simply because it is not able to address more memory locations with 32 bit addresses. (minus ~1G is because it needs virtual addresses for I/O devices as well, and those addresses cannot be mapped to physical memory). So with any Python that is running in 32 bit mode, you cannot use more than ~3G memory. But you can start many instances of those programs and use 2G for each process. L From breamoreboy at yahoo.co.uk Sun Feb 14 06:41:45 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Feb 2010 11:41:45 +0000 Subject: problem with floats and calculations In-Reply-To: References: <20100214102956.GA6524@yoda.bytereef.org> Message-ID: [fix top posting] > Karsten Goen wrote: >>> hey all, >>> I got a problem with floats and calculations. I made an mini-application >> where >>> you get random questions with some science calculations in it >>> So the user can type in his result with the values given by random >> creation. >>> And the user value is compared against the computer value... the problem >> is >>> that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 >>> >>> here is the example: >>> http://dpaste.com/hold/158698/ >>> >>> without decimal it would be very inaccurate. decimal is very accurate >> when I >>> have to compare d with users calculations from a,b,c,var. >>> But when I ask the user what is "a" the result gets inaccurate when >> calculating >>> with the same values given before (b,c,d,var). >>> >>> Maybe anyone can help me with this problem, I don't want to generate for >> every >>> possible user input a single formula. And also it should be possible for >> a >>> computer, my calculator at home does the same and is much smaller and >> slower. >> >> d = (a * b)/ (c * var) >> d = Decimal(d).quantize(Decimal('0.01')) >> >> By quantizing d, the above equality does not hold any longer. You've got >> to drop that line (your calculator doesn't quantize either). >> >> >> Stefan Krah >> > Karsten Goen wrote: > also this doesn't help, there are still errors in the accuracy. Isn't there > a perfect way to do such calculations? > Please read the following and see if it helps. Also search the python users mailing list for something like floating point accuracy, you'll get plenty of hits. http://docs.python.org/tutorial/floatingpoint.html Regards. Mark Lawrence From stefan-usenet at bytereef.org Sun Feb 14 06:42:34 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Sun, 14 Feb 2010 12:42:34 +0100 Subject: problem with floats and calculations In-Reply-To: References: <20100214102956.GA6524@yoda.bytereef.org> Message-ID: <20100214114234.GA7498@yoda.bytereef.org> Karsten Goen wrote: > also this doesn't help, there are still errors in the accuracy. Isn't there a > perfect way to do such calculations? The hint I gave you removes the most egregious error in your program. You still have to quantize the result of (c*var*d) / b) if you want it to match a. If I adapt your program, I don't find any non-matching numbers. for i in range(100000): # set random numbers a = Decimal(str(random.uniform(0.1,123))).quantize(Decimal('0.01')) b = Decimal(str(random.uniform(20.1,3000))).quantize(Decimal('0.01')) c = Decimal(str(random.uniform(100, 5000))).quantize(Decimal('0.01')) var = Decimal('8.314').quantize(Decimal('0.01')) # calc d d = (a * b)/ (c * var) if ((c*var*d) / b).quantize(Decimal('0.01')) != a: print a, (c*var*d) / b Note that for perfect accuracy you should use the fraction module. Stefan Krah From abenthy at asylum.com Sun Feb 14 06:52:53 2010 From: abenthy at asylum.com (abent) Date: Sun, 14 Feb 2010 03:52:53 -0800 (PST) Subject: How to solve an LCP (linear complementarity problem) in python ? Message-ID: Is there a good library to numericly solve an LCP in python ? (http://en.wikipedia.org/wiki/Linear_complementarity_problem) An example would be very helpful because most libraries seem to only solve QP's. I need this for computing 2d contact forces in a rigid body simulation. From dino at phidev.org Sun Feb 14 07:05:06 2010 From: dino at phidev.org (Florian Ludwig) Date: Sun, 14 Feb 2010 13:05:06 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> Message-ID: <1266149106.4299.79.camel@brain> On Sun, 2010-02-14 at 10:16 +0100, Paul K?lle wrote: > Am 13.02.2010 10:50, schrieb Florian Ludwig: > > Hi, > > > > I'm looking for a module/plugin/intra-process-communication/hook system > > for python. Maybe someone here could point me to some project I missed > > or might have some good ideas if I end up implementing it myself. > > > > [...] > > > > The plugins you wrote probably import them from the wiki module directly > > which means your blog would depend on the wiki. (?!) So where to put the > > interface/[...] definition that is imported by those plugins? Create a > > package/module just containing the interface? This really get > > troublesome if different people wrote the wiki, the blog and another > > third one a plugin. > If you are talking about code sharing you can move the common code out > of your applications in a seperate namespace. If you follow the model > trac is using you would install a module/package/egg with the basic > functionality of the pluginsystem (i.e. what's in core.py and env.py + > logging and whatever you think is necessary). > All shared code like your auth-plugins would go in a common plugin > directory to which you can refer via PYTHONPATH. You're right, its about code sharing/reusing - should have said it more clearly. What I am looking for is the pluginsystem that makes this easy. Here there problem with the trac (and other plugin systems I've seen) approach: You need to define something like: | | class IAuthPlugin(Interface): [...] | in your blog software. Now within the open_id_login_plugin: | from blog import IAuthPlugin | | class OpenIdPlugin(object): | implements(IAuthPlugin) | So the OpenIdPlugin is specific for the blog and hardly sharable. Actually it is but it depends on the blog as it gets imported. This might be thought of as an implementation detail but its seems pretty common. > Another common technique is chaining of WSGI middleware..., check out > pythonpaste.org. WSGI middleware just doesn't do it in some situations. Also it only works out for web-based applications (my example was one but my question was more general). Thanks for your answer, Florian -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From moky.math at gmail.com Sun Feb 14 07:16:28 2010 From: moky.math at gmail.com (Laurent Claessens) Date: Sun, 14 Feb 2010 04:16:28 -0800 (PST) Subject: LaTeX parser and pstricks generator in python Message-ID: Hi all. I just put online a first version of two tools that combine LaTeX and python. The first one, phystricks[1], is a python module intended to generate pstricks code. The main features are * you don't have to know pstricks (but you need to have some basics in python) * you have python instead of LaTeX as backend programming language * the bounding box is automatically computed * thanks to Sage[5], you have a direct access to the derivative of functions (and much more). Thus, for example, tangent and normal vectors to any (cartesian/polar/parametric) plots are easy to draw. * eps export is possible in order to be more pdfLaTeX friendly. The documentation[3] contains many examples of figures created with phystricks. Download the file phystricks-doc.pdf[4] In a somewhat near future, I plan to add interaction with LaTeX : reading the .aux file, I can import the values of LaTeX's counters in python. You should be able to draw a line whose angular coefficient is the number of the last equation ;) That feature should also improve the computation of the bounding box in taking into account the LaTeX labels that one put in the picture. That lead me to the second tool I put online ... The second, LaTeXparser[2], is a simple LaTeXparser in python. Given a tex file, the features are * answer to the questions : what are the defined macros ? among of them, which are actually used ? with what arguments ? * substitute \input{...} by the content of the file * read the .aux file and take information about the values \label and \ref Every comments (and patches) are much welcome ! Have a good day Laurent [1] http://www.gitorious.org/phystricks [2] http://www.gitorious.org/latexparser [3] http://www.gitorious.org/phystricks-doc [4] http://www.gitorious.org/phystricks-doc/phystricks-doc/trees/master [5] http://sagemath.org/ From news123 at free.fr Sun Feb 14 07:17:40 2010 From: news123 at free.fr (News123) Date: Sun, 14 Feb 2010 13:17:40 +0100 Subject: problem with QtSignals "object has no attribute 'emit'" Message-ID: <4b77e9e4$0$6277$426a74cc@news.free.fr> Hi, I'm having a rather small code snippet, where I create pyQT signals. I manage creating a signal as class attribute, but I can't create a list of signals or a signal as object.member. > from PyQt4.QtGui import * > from PyQt4.QtCore import * > > class MyWin(QMainWindow): > clssig = pyqtSignal() > sigarr = [ pyqtSignal() ] > def emit_them(self): > self.objsig = pyqtSignal() > self.clssig.emit() # works > self.sigarr[0].emit() # fails > self.objsig.emit() # fails > > if __name__ == "__main__": > app = QApplication(sys.argv) > win = MyWin() > win.show() > win.emit_them() > sys.exit(app.exec_()) The two lines marked with fails will fail with following error: > AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'emit' The QT documentation states: "New signals should only be defined in sub-classes of QObject." I guess, that his is the reason. though I don't know enough about PyQT to understand the magic behind. Now my question: How could I create an array of signals if I wished to? I can work aroud it, but would be curious. Thanks for shadng some light on this (for me surprising) issue. N From jarausch at skynet.be Sun Feb 14 07:36:19 2010 From: jarausch at skynet.be (Helmut Jarausch) Date: Sun, 14 Feb 2010 13:36:19 +0100 Subject: How to solve an LCP (linear complementarity problem) in python ? In-Reply-To: References: Message-ID: <4b77ee43$0$2886$ba620e4c@news.skynet.be> On 02/14/10 12:52, abent wrote: > Is there a good library to numericly solve an LCP in python ? > (http://en.wikipedia.org/wiki/Linear_complementarity_problem) > > An example would be very helpful because most libraries seem to only > solve QP's. > I need this for computing 2d contact forces in a rigid body > simulation. Sorry, I can't help you except pointing you to the Complementarity Problem Net http://www.cs.wisc.edu/cpnet/ -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From phil at riverbankcomputing.com Sun Feb 14 07:53:49 2010 From: phil at riverbankcomputing.com (Phil Thompson) Date: Sun, 14 Feb 2010 12:53:49 +0000 Subject: problem with QtSignals "object has no attribute 'emit'" In-Reply-To: <4b77e9e4$0$6277$426a74cc@news.free.fr> References: <4b77e9e4$0$6277$426a74cc@news.free.fr> Message-ID: <50888e51273d0b98c5cb065d83488f8a@localhost> On Sun, 14 Feb 2010 13:17:40 +0100, News123 wrote: > Hi, > > I'm having a rather small code snippet, where I create pyQT signals. > I manage creating a signal as class attribute, > but I can't create a list of signals or a signal > as object.member. > > >> from PyQt4.QtGui import * >> from PyQt4.QtCore import * >> >> class MyWin(QMainWindow): >> clssig = pyqtSignal() >> sigarr = [ pyqtSignal() ] >> def emit_them(self): >> self.objsig = pyqtSignal() >> self.clssig.emit() # works >> self.sigarr[0].emit() # fails >> self.objsig.emit() # fails >> >> if __name__ == "__main__": >> app = QApplication(sys.argv) >> win = MyWin() >> win.show() >> win.emit_them() >> sys.exit(app.exec_()) > > The two lines marked with fails will fail with following error: >> AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'emit' > > The QT documentation states: > "New signals should only be defined in sub-classes of QObject." > > I guess, that his is the reason. though I don't know enough about PyQT > to understand the magic behind. > > > Now my question: > > How could I create an array of signals if I wished to? > > I can work aroud it, but would be curious. > > > Thanks for shadng some light on this (for me surprising) issue. You can't create an array of signals. Signals are defined to both Python and C++. This is done when the class is defined by introspecting the class attributes - but it doesn't look for signals any deeper than that, i.e. it won't look into your sigarr list. Even if it did, there is a second issue. Signals have unbound and bound versions (much like unbound and bound methods). The class attribute is an unbound signal that is a descriptor that will return the bound signal. It is the bound signal that implements the emit() method. It would be possible for an unbound signal's __call__ method to also return a bound signal so that you could do something like... self.sigarr[0](self).emit() ...but I can't think of a valid use case. Phil From steve at REMOVE-THIS-cybersource.com.au Sun Feb 14 10:11:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 15:11:19 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> Message-ID: <4b781297$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote: > The term "pointer" is very abstract. Please give me a concrete > definition of a pointer. A programming language data type whose value directly specifies (or "points to") another value which is stored elsewhere in the computer memory. I quote from Wikipedia: http://en.wikipedia.org/wiki/Pointer_(computing) [quote] A pointer is a simple, less abstracted implementation of the more abstracted reference data type [end quote] And later: [quote] While "pointer" has been used to refer to references in general, it more properly applies to data structures whose interface explicitly allows the pointer to be manipulated (arithmetically via pointer arithmetic) as a memory address... [end quote] And again: [quote] A memory pointer (or just pointer) is a primitive, the value of which is intended to be used as a memory address; it is said that a pointer points to a memory address. It is also said that a pointer points to a datum [in memory] when the pointer's value is the datum's memory address. More generally, a pointer is a kind of reference, and it is said that a pointer references a datum stored somewhere in memory; to obtain that datum is to dereference the pointer. The feature that separates pointers from other kinds of reference is that a pointer's value is meant to be interpreted as a memory address, which is a rather 'low-level' concept. [end quote] > A curly brace is one of these: { } > > Pretty concrete, I hope. But { and } are glyphs in some typeface. Chances are that what you see, and what I see, are quite different, and whatever pixels we see, the compiler sees something radically different: two abstract characters implemented in some concrete fashion, but that concrete fashion is a mere implementation detail. They could be implemented as bytes x7b and x7d, or as four-byte sequences x0000007b and x0000007d for UTF-32, or who knows what in some other system. So the *concrete* representation of the curly brace varies according to the system. >From that, it's not a difficult leap to say that Pascal's BEGIN and END key words are mere alternate spellings of the abstract "open curly brace" and "close curly brace" with different concrete representations, and from that it's a small step to say that the INDENT and DEDENT tokens seen by the Python compiler (but absent from Python source code!) are too. >> But reference also has a concrete meaning: C++ has a type explicitly >> called "reference": >> >> http://en.wikipedia.org/wiki/Reference_(C++) >> >> > Of course, "reference" has concrete meanings in specific contexts. But I > can refer you to much more general and abstract uses of the term > "reference." Do you want references? I will be happy to refer you to > appropriate references. I know that reference can also be used in the abstract. I'm just warning that it can also be used in the concrete, and so we need to be wary of misunderstandings and confusions. >> And of course call-by-reference (or pass-by-reference) has a specific, >> technical meaning. >> >> > Which is what? http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference -- Steven From mukeshtiwari.iiitm at gmail.com Sun Feb 14 11:53:15 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sun, 14 Feb 2010 08:53:15 -0800 (PST) Subject: Python Optimization Message-ID: Hello everyone. I am new to python and previously i did programming in c/c++.Could some one please help me to improve the run time for this python program as i don't have idea how to optimized this code.This code also seems to be more unpythonic so how to make it look like more pythonic . I am trying for this problem(https://www.spoj.pl/problems/ FACT1/). Thank you # To change this template, choose Tools | Templates # and open the template in the editor. __author__="Mukesh Tiwari" __date__ ="$Feb 10, 2010 1:35:26 AM$" import random from Queue import Queue def gcd(a,b): while b: a,b=b,a%b return a def rabin_miller(p,t=1): if(p<2): return False if(p!=2 and p%2==0): return False s=p-1 while(s%2==0): s>>=1 for i in xrange(t): a=random.randrange(p-1)+1 temp=s mod=pow(a,temp,p) while(temp!=p-1 and mod!=1 and mod!=p-1): mod=(mod*mod)%p temp=temp*2 if(mod!=p-1 and temp%2==0): return False return True def brent(n): if(n%2==0): return 2; x,c,m=random.randrange(0,n),random.randrange(1,n),random.randrange(1,n) y,r,q=x,1,1 g,ys=0,0 while(True): x=y for i in range(r): y,k=(y*y+c)%n,0 while(True): ys=y for i in range(min(m,r-k)): y,q=(y*y+c)%n,q*abs(x-y)%n g,k=gcd(q,n),k+m if(k>= r or g>1):break r=2*r if(g>1):break if(g==n): while(True): ys,g=(x*x+c)%n,gcd(abs(x-ys),n) if(g>1):break return g def factor(n): Q_1,Q_2=Queue(),[] Q_1.put(n) while(not Q_1.empty()): l=Q_1.get() if(rabin_miller(l)): Q_2.append(l) continue d=brent(l) if(d==l):Q_1.put(l) else: Q_1.put(d) Q_1.put(l/d) return Q_2 if __name__ == "__main__": while(True): n=int(raw_input()) if(n==0):break L=factor(n) L.sort() #print L i=0 s="" while(i References: Message-ID: mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code.This > code also seems to be more unpythonic so how to make it look like more > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > FACT1/). > Thank you > > # To change this template, choose Tools | Templates > # and open the template in the editor. > > __author__="Mukesh Tiwari" > __date__ ="$Feb 10, 2010 1:35:26 AM$" > > > import random > from Queue import Queue > > > def gcd(a,b): > while b: > a,b=b,a%b > return a > > def rabin_miller(p,t=1): > if(p<2): > return False > if(p!=2 and p%2==0): > return False > s=p-1 > while(s%2==0): > s>>=1 > for i in xrange(t): > a=random.randrange(p-1)+1 > temp=s > mod=pow(a,temp,p) > while(temp!=p-1 and mod!=1 and mod!=p-1): > mod=(mod*mod)%p > temp=temp*2 > if(mod!=p-1 and temp%2==0): > return False > return True > def brent(n): > if(n%2==0): > return 2; > > x,c,m=random.randrange(0,n),random.randrange(1,n),random.randrange(1,n) > y,r,q=x,1,1 > g,ys=0,0 > while(True): > x=y > for i in range(r): > y,k=(y*y+c)%n,0 > while(True): > ys=y > for i in range(min(m,r-k)): > y,q=(y*y+c)%n,q*abs(x-y)%n > g,k=gcd(q,n),k+m > if(k>= r or g>1):break > r=2*r > if(g>1):break > if(g==n): > while(True): > ys,g=(x*x+c)%n,gcd(abs(x-ys),n) > if(g>1):break > return g > > > def factor(n): > Q_1,Q_2=Queue(),[] > Q_1.put(n) > while(not Q_1.empty()): > l=Q_1.get() > if(rabin_miller(l)): > Q_2.append(l) > continue > d=brent(l) > if(d==l):Q_1.put(l) > else: > Q_1.put(d) > Q_1.put(l/d) > return Q_2 > > > > if __name__ == "__main__": > while(True): > n=int(raw_input()) > if(n==0):break > L=factor(n) > L.sort() > #print L > i=0 > s="" > while(i cnt=L.count(L[i]) > #print "%d^%d"%(L[i],cnt) > s+=str(L[i])+"^"+str(cnt)+" " > i+=cnt > print s[:-1] A good starting point is http://wiki.python.org/moin/PythonSpeed/PerformanceTips HTH. Mark Lawrence From python at mrabarnett.plus.com Sun Feb 14 12:29:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 17:29:41 +0000 Subject: Hashing in python In-Reply-To: <4B77C17A.1020306@v.loewis.de> References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> <4B77C17A.1020306@v.loewis.de> Message-ID: <4B783305.5090405@mrabarnett.plus.com> Martin v. Loewis wrote: >> floor(x) returns an integer > > Why do you say that? Assuming you are talking about math.floor, it works > differently for me: > > py> math.floor(10.0/3) > 3.0 > I've just double-checked. It returns a float in Python 2.x and an int in Python 3.x. (I recently switched to Python 3.1.) From deets at nospam.web.de Sun Feb 14 12:47:30 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 14 Feb 2010 18:47:30 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> Message-ID: <7tqr9iFbi7U1@mid.uni-berlin.de> Am 14.02.10 13:05, schrieb Florian Ludwig: > On Sun, 2010-02-14 at 10:16 +0100, Paul K?lle wrote: >> Am 13.02.2010 10:50, schrieb Florian Ludwig: >>> Hi, >>> >>> I'm looking for a module/plugin/intra-process-communication/hook system >>> for python. Maybe someone here could point me to some project I missed >>> or might have some good ideas if I end up implementing it myself. >>> >>> [...] >>> >>> The plugins you wrote probably import them from the wiki module directly >>> which means your blog would depend on the wiki. (?!) So where to put the >>> interface/[...] definition that is imported by those plugins? Create a >>> package/module just containing the interface? This really get >>> troublesome if different people wrote the wiki, the blog and another >>> third one a plugin. > >> If you are talking about code sharing you can move the common code out >> of your applications in a seperate namespace. If you follow the model >> trac is using you would install a module/package/egg with the basic >> functionality of the pluginsystem (i.e. what's in core.py and env.py + >> logging and whatever you think is necessary). > >> All shared code like your auth-plugins would go in a common plugin >> directory to which you can refer via PYTHONPATH. > > You're right, its about code sharing/reusing - should have said it more > clearly. What I am looking for is the pluginsystem that makes this easy. > Here there problem with the trac (and other plugin systems I've seen) > approach: > > You need to define something like: > | > | class IAuthPlugin(Interface): [...] > | > in your blog software. Why? Any reason you can't define it in a separate package the blog-software depends on, as well as your wiki? And then of course, this is not really needed. In Python, behavior counts, not type-information. So you can get away without any explicit declared interface. You might chose to not do that, for aestetic reasons, or better documentation. But you aren't forced. diez From dickinsm at gmail.com Sun Feb 14 12:48:11 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 14 Feb 2010 09:48:11 -0800 (PST) Subject: Python Optimization References: Message-ID: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> On Feb 14, 4:53?pm, mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code. > [...] How much of a speedup do you need? Are we talking about orders of magnitude (in which case you might want to consider using something like the Multiple Polynomial Quadratic Sieve method instead, or as well), or just a few percent? (1) Have you profiled the code to see where it's spending most of its time? This is an essential first step. (2) Obvious things: use range rather than xrange in your loops. Make sure that all heavily used variables/functions are local to the function you're using them in. E.g., you use range, min and abs in the middle of the 'brent' function. Instead, start the brent function by setting _abs, _range, _min = abs, range, min, and then use _abs, _range, etc. instead. Lookups of local variables are faster than globals. (3) In the inner loop: for i in range(min(m,r-k)): y,q=(y*y+c)%n,q*abs(x-y)%n you can get probably rid of the abs call. It *might* also help to avoid the tuple packing/unpacking (but see (1)). You could try doing a couple of steps at a time instead of one (i.e., unroll the loop a little bit); one advantage is that you probably don't need to bother reducing q modulo n at every step; every other step would be good enough. Depending on the relative speed of multiplication and reduction, and the sizes of the integers involved, this might save time. (4) Have you tried using Montgomery reduction in the Brent method? The inner loop of that method involves two reductions modulo n, which may well be where the biggest bottleneck is. But see (1). The other obvious bottleneck is the gcd method; if profiling shows that that's the case, there might be ways to speed that up, too. (E.g., use a binary gcd algorithm, or use Lehmer's method.) Good luck! -- Mark From showell30 at yahoo.com Sun Feb 14 12:51:38 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 09:51:38 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> Message-ID: <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> On Feb 14, 7:11?am, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote: > > The term "pointer" is very abstract. ?Please give me a concrete > > definition of a pointer. > > A programming language data type whose value directly specifies (or > "points to") another value which is stored elsewhere in the computer > memory. > > I quote from Wikipedia: > > http://en.wikipedia.org/wiki/Pointer_(computing) > > ? ? [quote] > ? ? A pointer is a simple, less abstracted implementation of the > ? ? more abstracted reference data type > ? ? [end quote] > > And later: > > ? ? [quote] > ? ? While "pointer" has been used to refer to references in > ? ? general, it more properly applies to data structures whose > ? ? interface explicitly allows the pointer to be manipulated > ? ? (arithmetically via pointer arithmetic) as a memory > ? ? address... > ? ? [end quote] > > And again: > > ? ? [quote] > ? ? A memory pointer (or just pointer) is a primitive, the value > ? ? of which is intended to be used as a memory address; it is said > ? ? that a pointer points to a memory address. It is also said that > ? ? a pointer points to a datum [in memory] when the pointer's value > ? ? is the datum's memory address. > > ? ? More generally, a pointer is a kind of reference, and it is said > ? ? that a pointer references a datum stored somewhere in memory; to > ? ? obtain that datum is to dereference the pointer. The feature that > ? ? separates pointers from other kinds of reference is that a > ? ? pointer's value is meant to be interpreted as a memory address, > ? ? which is a rather 'low-level' concept. > ? ? [end quote] > > > A curly brace is one of these: { } > > > Pretty concrete, I hope. > > But { and } are glyphs in some typeface. Chances are that what you see, > and what I see, are quite different, and whatever pixels we see, the > compiler sees something radically different: two abstract characters > implemented in some concrete fashion, but that concrete fashion is a mere > implementation detail. They could be implemented as bytes x7b and x7d, or > as four-byte sequences x0000007b and x0000007d for UTF-32, or who knows > what in some other system. So the *concrete* representation of the curly > brace varies according to the system. > > From that, it's not a difficult leap to say that Pascal's BEGIN and END > key words are mere alternate spellings of the abstract "open curly brace" > and "close curly brace" with different concrete representations, and from > that it's a small step to say that the INDENT and DEDENT tokens seen by > the Python compiler (but absent from Python source code!) are too. > Thanks. It's a useful analogy; I think I understand your point better. I've been bouncing around between Python and Javascript a lot lately, so your analogy resonates with me. There are many times when I find myself simply respelling things like begin/end, and those respellings to me almost make me think of Python and Javascript as different dialects of an underlying language. Of course, there are other places where the languages differ more substantively, too. Going back to pointers vs. references, I think the key distinction being made is that pointers allow specific memory manipulation, although I think even there you're really just dealing with abstractions. The address 0x78F394D2 is a little bit closer to the machine than, say, the 42nd element of a Python list, but they are both just abstractions on top of underlying machines, whether the machines are virtual, electronic circuits, vacuum tubes, whatever. You can add 6 to 42 and get the 48th object, but its Python's convention not to call the 48th object a memory address or expose a reference to it as a pointer. If I want to pass along the reference to the 48th element of a list as the slot to be updated (i.e. with the intention to actually mutate the list itself), then I need a tuple like (lst, 48). From kaklis at gmail.com Sun Feb 14 12:59:12 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Sun, 14 Feb 2010 09:59:12 -0800 (PST) Subject: Comparing file last access date Message-ID: <2e4fc893-2fe7-467a-8b5e-abe0816e665d@r33g2000yqb.googlegroups.com> Hi to all, what i want is to search a folder, and if the last access date of the files in that folder is greater than, lets say 7 days, those files deleted. (Somekind of a file cleaner script) I had problems with converting now = today = datetime.date.today() and stats = os.stat(file) lastAccessDate = time.localtime(stats[7]) into matching formats so that if (now - lastAccessDate) > 7: delete the file what i do wrong Thanks in advance Antonis From aahz at pythoncraft.com Sun Feb 14 13:03:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2010 10:03:21 -0800 Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> Message-ID: In article <363498c7-3575-4f1e-ad53-d9cd10c8da2c at q16g2000yqq.googlegroups.com>, Mark Dickinson wrote: > >(2) Obvious things: use range rather than xrange in your loops. Um, what? You meant the reverse, surely? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From python at mrabarnett.plus.com Sun Feb 14 13:20:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 18:20:27 +0000 Subject: Comparing file last access date In-Reply-To: <2e4fc893-2fe7-467a-8b5e-abe0816e665d@r33g2000yqb.googlegroups.com> References: <2e4fc893-2fe7-467a-8b5e-abe0816e665d@r33g2000yqb.googlegroups.com> Message-ID: <4B783EEB.9030800@mrabarnett.plus.com> kaklis at gmail.com wrote: > Hi to all, > what i want is to search a folder, and if the last access date of the > files in that folder is greater than, lets say 7 days, those files > deleted. (Somekind of a file cleaner script) > I had problems with converting > > now = today = datetime.date.today() > and > stats = os.stat(file) > lastAccessDate = time.localtime(stats[7]) > > into matching formats so that > if (now - lastAccessDate) > 7: > delete the file > > what i do wrong > Thanks in advance > Antonis I would use: seven_days = 7 * 24 * 60 * 60 # 7 days in seconds now = time.time() # in seconds since Epoch ... last_access = os.path.getatime(path) # in seconds since Epoch if now - last_access > seven_days: os.remove(path) From aahz at pythoncraft.com Sun Feb 14 13:21:25 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2010 10:21:25 -0800 Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 References: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> Message-ID: In article <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482 at r24g2000yqd.googlegroups.com>, seth wrote: > >We have a code that creates a simple Python shelve database. We are >able to serialize objects and store them in the dbm file. This seem to >work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6, >but on Os X 10.5 with Python 2.5 the database filename is changed by >the operating system by attaching the .db extension to it. Does an one >know why is that? Nope -- any reason you can't change the filename? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From steve at holdenweb.com Sun Feb 14 13:32:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Feb 2010 13:32:29 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: rantingrick wrote: > On Feb 12, 4:10 pm, Steve Holden wrote: >> Antoine Pitrou wrote: >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > On Feb 12, 4:10 pm, Steve Holden wrote: >> Antoine Pitrou wrote: >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > Steve, > Why do so many of your posts come in as doubles and triples. Is this a > case of "studdering click finger" of some fault of your newsreader? > > -- concerned fellow pythonista... I suspect it's because I am being insufficiently disciplined about using "reply" instead of "reply all". On gmane they only appear once, so I suspect some other component of the mail/news loop is less assiduous about de-duping the content. How do you read the list? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From showell30 at yahoo.com Sun Feb 14 13:41:35 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 10:41:35 -0800 (PST) Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> Message-ID: <88a7ff43-3f1d-4e30-ad50-59b6c2f215f7@a5g2000prg.googlegroups.com> On Feb 14, 9:48?am, Mark Dickinson wrote: > On Feb 14, 4:53?pm, mukesh tiwari > wrote: > > > Hello everyone. I am new to python and previously i did programming in > > c/c++.Could some one please help me to improve the run time for this > > python program as i don't have idea how to optimized this code. > > [...] > > How much of a speedup do you need? ?Are we talking about orders of > magnitude (in which case you might want to consider using something > like the Multiple Polynomial Quadratic Sieve method instead, or as > well), or just a few percent? > > (1) Have you profiled the code to see where it's spending most of its > time? ?This is an essential first step. > I ditto the profiling recommendation. http://docs.python.org/library/profile.html It might also be useful to time your algorithm for n=10, 100, 1000, 10000, etc., to get a better sense of how the overall algorithm behaves. From showell30 at yahoo.com Sun Feb 14 13:48:50 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 10:48:50 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7c65aa94-ed69-48d9-b37b-8b1cb376fa3e@t31g2000prh.googlegroups.com> On Feb 14, 10:32?am, Steve Holden wrote: > rantingrick wrote: > > On Feb 12, 4:10 pm, Steve Holden wrote: > >> Antoine Pitrou wrote: > >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > > On Feb 12, 4:10 pm, Steve Holden wrote: > >> Antoine Pitrou wrote: > >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > > Steve, > > Why do so many of your posts come in as doubles and triples. Is this a > > case of "studdering click finger" of some fault of your newsreader? > > > -- concerned fellow pythonista... > > I suspect it's because I am being insufficiently disciplined about using > "reply" instead of "reply all". On gmane they only appear once, so I > suspect some other component of the mail/news loop is less assiduous > about de-duping the content. > > How do you read the list? > Hi Steve, I mostly read the list through Google groups, and I have seen occasional dups from you. Of course, the readers themselves could be a little smarter about recognizing duplication, but that does not appear to be the case with Google. On the other hand, I am not seeing dups from you in a quick skim of this thread, so I wonder if it just takes Google a little while to weed out the dups. From showell30 at yahoo.com Sun Feb 14 14:04:37 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 11:04:37 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> Message-ID: <6bb774a3-ed05-402a-a7f2-9c472940379e@b9g2000pri.googlegroups.com> On Feb 11, 5:50?pm, Steven D'Aprano wrote: > On Thu, 11 Feb 2010 15:39:09 -0800, Jeremy wrote: > > My Python program now consumes over 2 GB of memory and then I get a > > MemoryError. ?I know I am reading lots of files into memory, but not 2GB > > worth. > > 2. ? ?When do I need > > to manually allocate/deallocate memory and when can I trust Python to > > take care of it? > > You never need to manually allocate memory. > > You *may* need to deallocate memory if you make "reference loops", where > one object refers to itself: > > l = [] ?# make an empty list > l.append(l) ?# add the list l to itself > > Python can break such simple reference loops itself, but for more > complicated ones, you may need to break them yourself: > > a = [] > b = {2: a} > c = (None, b) > d = [1, 'z', c] > a.append(d) ?# a reference loop > > Python will deallocate objects when they are no longer in use. They are > always considered in use any time you have them assigned to a name, or in > a list or dict or other structure which is in use. > > You can explicitly remove a name with the del command. For example: > > x = ['my', 'data'] > del x > > After deleting the name x, the list object itself is no longer in use > anywhere and Python will deallocate it. But consider: > > x = ['my', 'data'] > y = x ?# y now refers to THE SAME list object > del x > > Although you have deleted the name x, the list object is still bound to > the name y, and so Python will *not* deallocate the list. > > Likewise: > > x = ['my', 'data'] > y = [None, 1, x, 'hello world'] > del x > > Although now the list isn't bound to a name, it is inside another list, > and so Python will not deallocate it. > Another technique that comes up some time is that you have a list of objects that you are processing: x = [obj1, obj2, obj3, obj4] When you are done processing obj1, you want to remove the reference to it, but you do not necessarily want to change the list itself. You can break the reference by saying "x[0] = None" when you are done handling obj1. Of course, if you can avoid creating the list in the first place, as some people have suggested, then you really get a savings. The setting-to-None technique is also occasionally useful with objects, where you can say foo.bar = None when you are done with "bar" but not with "foo." Of course, the need to use such a technique often points out a deeper code smell with Foo itself, but I've seen it come up. Steven's examples of a reference loop are deliberately simplified, of course, but the chain of references in a real world program can get quite long, and there's often great savings to be reaped if you can break the "keystone" reference, so to speak. In other words, breaking just one reference often allows other references to fall down like dominos. From dickinsm at gmail.com Sun Feb 14 14:35:35 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 14 Feb 2010 11:35:35 -0800 (PST) Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> Message-ID: On Feb 14, 6:03?pm, a... at pythoncraft.com (Aahz) wrote: > In article <363498c7-3575-4f1e-ad53-d9cd10c8d... at q16g2000yqq.googlegroups.com>, > Mark Dickinson ? wrote: > > >(2) Obvious things: use range rather than xrange in your loops. ? > > Um, what? ?You meant the reverse, surely? Er, yes I did. Thanks! -- Mark From dickinsm at gmail.com Sun Feb 14 14:52:51 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 14 Feb 2010 11:52:51 -0800 (PST) Subject: Python Optimization References: Message-ID: <892f7664-14e9-4ce4-ab50-499fc8552ec3@v25g2000yqk.googlegroups.com> On Feb 14, 4:53?pm, mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code.This > code also seems to be more unpythonic so how to make it look like more > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > FACT1/). > Thank you One other thing: in the 'brent' function, you're setting m to randrange(1, n). What's the purpose of this? It looks to me as though m controls the number of Pollard-Rho iterations that are clumped together at one time (before doing a gcd operation), and using a random number for this doesn't make a lot of sense to me. -- Mark From showell30 at yahoo.com Sun Feb 14 15:07:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 12:07:41 -0800 (PST) Subject: Python Optimization References: <892f7664-14e9-4ce4-ab50-499fc8552ec3@v25g2000yqk.googlegroups.com> Message-ID: <0eac0e90-fd39-4851-b979-c109218fb0ba@a5g2000prg.googlegroups.com> On Feb 14, 11:52?am, Mark Dickinson wrote: > On Feb 14, 4:53?pm, mukesh tiwari > wrote: > > > Hello everyone. I am new to python and previously i did programming in > > c/c++.Could some one please help me to improve the run time for this > > python program as i don't have idea how to optimized this code.This > > code also seems to be more unpythonic so how to make it look like more > > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > > FACT1/). > > Thank you > > One other thing: ?in the 'brent' function, you're setting m to > randrange(1, n). ?What's the purpose of this? ?It looks to me as > though m controls the number of Pollard-Rho iterations that are > clumped together at one time (before doing a gcd operation), and using > a random number for this doesn't make a lot of sense to me. > The randomness also makes the algorithm a little buggy. I tried this input: 37^5 41^5 Usually I get the right answer. Other times I get this: 37^5 41^3 1681^1 And occasionally it appears to get into an infinite loop, which definitely could be a cause of "slowness." :) From phiporiphic at gmail.com Sun Feb 14 15:23:41 2010 From: phiporiphic at gmail.com (Mr.John) Date: Sun, 14 Feb 2010 15:23:41 -0500 Subject: Fighting with subprocess.Popen Message-ID: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> I'm using Python 2.6.2 as packaged with Fedora 12. I'm trying to use subprocess.Popen() to call /usr/bin/pactl, a simple PulseAudio command parser. I'm having a hard time, because it only works part of the time. If pactl gets a blank or invalid command, it says "No valid command specified.", and this is what prints to stderr most of the time. I can get the result of "pactl list", but anything else I try returns "No valid command specified." So, pactl is getting called, but my args are disappearing somewhere. But not every time... Below is a test case that demonstrates this. Tests 1 & 2 concatenate the command and the argument, Tests 3 & 4 mimic the python docs and use the form Popen(["mycmd", "myarg"], ...), which never seems to work. import subprocess list = 'list' list_sinks = 'list-sinks' print("### TEST 1") a = subprocess.Popen('pactl ' + list, shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) print("### TEST 2") a = subprocess.Popen('pactl ' + list_sinks, shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) print("### TEST 3") a = subprocess.Popen(['pactl', list], shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) print("### TEST 4") a = subprocess.Popen(['pactl', list_sinks], shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) ### TEST 1 (success... snip) ### TEST 2 No valid command specified. '' ### TEST 3 No valid command specified. '' ### TEST 4 No valid command specified. '' Does anyone have any idea what I'm doing wrong? Thanks, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sun Feb 14 15:39:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2010 12:39:40 -0800 Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <8fc356e0-f3ed-4a67-9b37-f21561cef4a5@p13g2000pre.googlegroups.com> Message-ID: In article <8fc356e0-f3ed-4a67-9b37-f21561cef4a5 at p13g2000pre.googlegroups.com>, Sean DiZazzo wrote: >On Feb 8, 2:36=A0pm, a... at pythoncraft.com (Aahz) wrote: >> In article .com>, >> Sean DiZazzo =A0 wrote: >>> >>>Why did Path() get rejected? Is it the idea itself, or just the >>>approach that was used? What are the complaints? >> >> You should search for the discussiona around it. > >I read the discussion, and there was definitely some going back and >forth on whether it should be sub-classed from string, but the >conversation just seemed to stop abruptly with no decision one way of >the other. Maybe I missed a thread. > >I guess being dropped without a final go-ahead is just as good as a >formal no anyway. Not quite: because it was not rejected, someone who wants to shepherd the process forward would likely be welcomed (even if it ends up with formal rejection). I suggest starting by writing your own summary of the previous discussion and see if the people involved agree that your summary is reasonably accurate. Also check to see if the original PEP writer wants to be involved or whether zie is willing to have you take over. Another good (and related) starting point would be to create a reasoning favoring one side or the other that was not brought up in previous discussion. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From lists at cheimes.de Sun Feb 14 15:43:22 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 14 Feb 2010 21:43:22 +0100 Subject: Fighting with subprocess.Popen In-Reply-To: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> References: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> Message-ID: Mr.John wrote: > Below is a test case that demonstrates this. Tests 1 & 2 concatenate the > command and the argument, Tests 3 & 4 mimic the python docs and use the form > Popen(["mycmd", "myarg"], ...), which never seems to work. It doesn't work with shell=True because the shell is not able to interpret the list form. It's recommended that you don't use shell=True unless you need a shell. Christian From rschroev_nospam_ml at fastmail.fm Sun Feb 14 15:46:13 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 14 Feb 2010 21:46:13 +0100 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> Message-ID: Op 2010-02-13 13:14, Alf P. Steinbach schreef: > * hjebbers: >> I enlarged the windows page file from 750Kb to 1.5Gb . >> The crash still happens. >> btw, the crash does not happen at a peak memory usage. >> According to windows task manager, at the moment of crash mem usage of >> my program is 669kb, peak memory usage is 1.136kb >> >> henk-jan > > Probably you meant to write "M", not "k" or "K"? > > I've never managed to make much sense of the displays in Windows' Task Manager, > if that's what you're using, but I think the mem usage it's displaying by > default is the process' working set, or something very similar to that measure. > > You can display additional columns in Task Manager, and one useful one is how > much virtual memory is allocated,. > > And perhaps then (if that's not what you're looking it already) it'll be closer > to 2 GiB? Note that the memory measurements in Task Manager are pretty limited and. Comparing Task Manager and Process Explorer: Task Manager - Process Explorer Mem Usage - Working Set VM Size - Private Bytes n/a - Virtual Size I tend to trust Process Explorer a lot more than Task Manager. Note that what Task Manager calls VM Size is not the size of the virtual memory as might be expected (if Process Explorer is to be trusted), and that Task Manager doesn't show the virtual memory size (at least on Windows XP). -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From tjreedy at udel.edu Sun Feb 14 16:23:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Feb 2010 16:23:30 -0500 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: On 2/13/2010 8:14 AM, Steve Holden wrote: > Gmane is primarily a news (NNTP-based) service, though for reasons best > know to the organizers they choose to rename the standard newsgroups to > fit their own idea of how the universe should be organized, so there the > group becomes gmane.comp.python.general. As I understand the site, the last I read a year or two ago, gmane is a technical mailinglist-to-news gateway. It does not mirror newsgroups, standard or not. It only mirrors lists such as python-list, not newsgroups, such comp.lang.python. In doing so, it organizes the lists into categories like g.comp.python, which has about 200 subgroups mirroring 200 python lists. From steve at holdenweb.com Sun Feb 14 16:32:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Feb 2010 16:32:36 -0500 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Terry Reedy wrote: > On 2/13/2010 8:14 AM, Steve Holden wrote: > >> Gmane is primarily a news (NNTP-based) service, though for reasons best >> know to the organizers they choose to rename the standard newsgroups to >> fit their own idea of how the universe should be organized, so there the >> group becomes gmane.comp.python.general. > > As I understand the site, the last I read a year or two ago, gmane is a > technical mailinglist-to-news gateway. It does not mirror newsgroups, > standard or not. It only mirrors lists such as python-list, not > newsgroups, such comp.lang.python. In doing so, it organizes the lists > into categories like g.comp.python, which has about 200 subgroups > mirroring 200 python lists. > That would make more sense. I know that the python.org infrastructure acts as a gateway between the mailing list and the newsgroup. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From rridge at csclub.uwaterloo.ca Sun Feb 14 17:05:07 2010 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sun, 14 Feb 2010 17:05:07 -0500 Subject: MemoryError, can I use more? References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" writes: > No, PAE can be used to access much more memory than 4GB - albeit > through paging. AFAIK up to 2^36 Bytes. Anssi Saari wrote: >That too. I admit, after checking, that you can't go above 3 GiB per >process even in server Windows. But for Linux there exists (or >existed, since it seems it hasn't been updated since 2004) a kernel >patch which provides a "4GB/4GB" address split. Kernel is in one >segment, userland in another and hence a process can access full 4GB. Windows has a similar feature that allows 32-bit applications running on 64-bit versions of Windows to have a nearly 4Gb virtual address space. Windows also allows 32-bit applications to use more than 4GB of physical memory through a paging mechanism called "Address Windowing Extensions". Also 32-bit applications can effectively use more than 4GB of RAM through indirect means like multiple processes, the disk cache or video card RAM. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From joe at joemoney.net Sun Feb 14 17:42:35 2010 From: joe at joemoney.net (monkeys paw) Date: Sun, 14 Feb 2010 17:42:35 -0500 Subject: new python install Message-ID: <4badnYd5OJHA4eXWnZ2dnUVZ_oidnZ2d@insightbb.com> Upon invoking python, it hangs until Ctrl^C is typed, and then the >>> interactive shell begins. Like so: joemoney% python Python 2.4.6 (#1, Dec 13 2009, 23:45:11) [C] on sunos5 Type "help", "copyright", "credits" or "license" for more information. # Hangs ^^^ at this point until ^C is typed ^C >>> I've seen this in other new installs and wondered if there is a common problem that would cause this? It's on a sun os box From deets at nospam.web.de Sun Feb 14 18:20:40 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Feb 2010 00:20:40 +0100 Subject: MemoryError, can I use more? In-Reply-To: References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: <7treq9FrsnU1@mid.uni-berlin.de> Am 14.02.10 12:28, schrieb Laszlo Nagy: > 2010.02.13. 17:40 keltez?ssel, Diez B. Roggisch ?rta: >> Am 13.02.10 17:18, schrieb Anssi Saari: >>> Nobody writes: >>> >>>> A single process can't use much more than 2GiB of RAM without a >>>> 64-bit CPU >>>> and OS. >>> >>> That's not really true. Even Windows XP has the /3GB boot option to >>> allow 3 GiB per process. On PCs, free operating systems and server >>> Windows can use PAE to give access to full 4 GB per process. >> >> No, PAE can be used to access much more memory than 4GB - albeit >> through paging. AFAIK up to 2^36 Bytes. > PAE is for the kernel. Yes, you can use much more memory with 32 bit > kernel + PAE. But the ~3G per 32bit process limit still applies. It is > because the PAE extension allows the kernel to distribute the same > virtual address ranges between different processes, but map them to > different physical memory addresses. However, the process that was > compiled and is running in 32 bit mode, cannot access more than ~3GB > simply because it is not able to address more memory locations with 32 > bit addresses. (minus ~1G is because it needs virtual addresses for I/O > devices as well, and those addresses cannot be mapped to physical memory). No. It can access more, through paging, similar like mmap. Specialized software like databases do that to keep large data in memory. And this has nothing to do with compilation. Of course this doesn't help for python, at least not for python-objects, as these need a flat memory model. But it's not true that only the kernels benefit from the PAE. Diez From ethan at stoneleaf.us Sun Feb 14 18:41:59 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 14 Feb 2010 15:41:59 -0800 Subject: Modifying Class Object In-Reply-To: <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> Message-ID: <4B788A47.1040609@stoneleaf.us> Steve Howell wrote: > On Feb 14, 7:11 am, Steven D'Aprano cybersource.com.au> wrote: > >>On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote: >> >>>The term "pointer" is very abstract. Please give me a concrete >>>definition of a pointer. >> >>A programming language data type whose value directly specifies (or >>"points to") another value which is stored elsewhere in the computer >>memory. >> >>I quote from Wikipedia: >> >>http://en.wikipedia.org/wiki/Pointer_(computing) >> >> [quote] >> A pointer is a simple, less abstracted implementation of the >> more abstracted reference data type >> [end quote] >> >>And later: >> >> [quote] >> While "pointer" has been used to refer to references in >> general, it more properly applies to data structures whose >> interface explicitly allows the pointer to be manipulated >> (arithmetically via pointer arithmetic) as a memory >> address... >> [end quote] >> >>And again: >> >> [quote] >> A memory pointer (or just pointer) is a primitive, the value >> of which is intended to be used as a memory address; it is said >> that a pointer points to a memory address. It is also said that >> a pointer points to a datum [in memory] when the pointer's value >> is the datum's memory address. >> >> More generally, a pointer is a kind of reference, and it is said >> that a pointer references a datum stored somewhere in memory; to >> obtain that datum is to dereference the pointer. The feature that >> separates pointers from other kinds of reference is that a >> pointer's value is meant to be interpreted as a memory address, >> which is a rather 'low-level' concept. >> [end quote] >> >> >>>A curly brace is one of these: { } >> >>>Pretty concrete, I hope. >> >>But { and } are glyphs in some typeface. Chances are that what you see, >>and what I see, are quite different, and whatever pixels we see, the >>compiler sees something radically different: two abstract characters >>implemented in some concrete fashion, but that concrete fashion is a mere >>implementation detail. They could be implemented as bytes x7b and x7d, or >>as four-byte sequences x0000007b and x0000007d for UTF-32, or who knows >>what in some other system. So the *concrete* representation of the curly >>brace varies according to the system. >> >>From that, it's not a difficult leap to say that Pascal's BEGIN and END >>key words are mere alternate spellings of the abstract "open curly brace" >>and "close curly brace" with different concrete representations, and from >>that it's a small step to say that the INDENT and DEDENT tokens seen by >>the Python compiler (but absent from Python source code!) are too. >> > > > Thanks. It's a useful analogy; I think I understand your point > better. I've been bouncing around between Python and Javascript a lot > lately, so your analogy resonates with me. There are many times when > I find myself simply respelling things like begin/end, and those > respellings to me almost make me think of Python and Javascript as > different dialects of an underlying language. Of course, there are > other places where the languages differ more substantively, too. > > Going back to pointers vs. references, I think the key distinction > being made is that pointers allow specific memory manipulation, > although I think even there you're really just dealing with > abstractions. The address 0x78F394D2 is a little bit closer to the > machine than, say, the 42nd element of a Python list, but they are > both just abstractions on top of underlying machines, whether the > machines are virtual, electronic circuits, vacuum tubes, whatever. > You can add 6 to 42 and get the 48th object, but its Python's > convention not to call the 48th object a memory address or expose a > reference to it as a pointer. If I want to pass along the reference > to the 48th element of a list as the slot to be updated (i.e. with the > intention to actually mutate the list itself), then I need a tuple > like (lst, 48). > I think that's the key right there -- if 48 was really a pointer, you wouldn't need to pass lst in as 48 would in fact be the memory address of the object you wanted to manipulate. ~Ethan~ From m.echavarriagregory at umiami.edu Sun Feb 14 19:19:07 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Sun, 14 Feb 2010 19:19:07 -0500 Subject: FW: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E056@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu>, <6546CE32-E9EA-4E33-9C7B-8A9808A4A083@gmail.com>, <2E95F75EDC25D54999387A1E2E6EF62755EEF0E056@MBX02.cgcent.miami.edu> Message-ID: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E057@MBX02.cgcent.miami.edu> I use the physical and kernel memory boxes in the windows task manager under the performance tab... in that way I can see the exact RAM that just OS and idle processes occupy before I run my app, and then also the limit at which my app pushes the memory... M. Angelica Echavarria-Gregory, M.Sc., E.I. Ph.D Candidate University of Miami Phone 305 284-3611 ________________________________________ From: ssteinerX at gmail.com [ssteinerx at gmail.com] Sent: Friday, February 12, 2010 7:58 PM To: Echavarria Gregory, Maria Angelica Cc: python-list at python.org Subject: Re: MemoryError, can I use more? On Feb 12, 2010, at 7:21 PM, Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... How are you determining that it has occupied "exactly only 2.2GB?" S From m.echavarriagregory at umiami.edu Sun Feb 14 19:20:44 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Sun, 14 Feb 2010 19:20:44 -0500 Subject: FW: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu>, , <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> Message-ID: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> Dear Chris, One of the machines I tested my app in is 64 bit and happened the same. The RAM consumed by the OS and other processes is already included in the 2.2 I'm telling... my app enters to work when the RAM is already consumed in ~600 MB in the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that it started a little bit higher because it has windows 7... so should I understand that there is nothing I can do for my app to use up more RAM? Thanks for your time and answer, Angelica. M. Angelica Echavarria-Gregory, M.Sc., E.I. Ph.D Candidate University of Miami Phone 305 284-3611 ________________________________ From: Chris Kaynor [ckaynor at zindagigames.com] Sent: Friday, February 12, 2010 7:44 PM To: Echavarria Gregory, Maria Angelica Cc: python-list at python.org Subject: Re: MemoryError, can I use more? A 32 bit app can only use 4 GB of memory itself (regardless of the amount of system ram), the OS claims some of this for the system, dlls occupy some of it, etc. As such, the app can only really use a smaller subset (generally between 2 to 3 GB, depending upon the app and the OS). Chris On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica > wrote: Dear group: I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... Thanks, Angelica. -- http://mail.python.org/mailman/listinfo/python-list From alfps at start.no Sun Feb 14 19:41:10 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 01:41:10 +0100 Subject: Modifying Class Object In-Reply-To: References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> Message-ID: * Ethan Furman: > Steve Howell wrote: >> >> Going back to pointers vs. references, I think the key distinction >> being made is that pointers allow specific memory manipulation, >> although I think even there you're really just dealing with >> abstractions. The address 0x78F394D2 is a little bit closer to the >> machine than, say, the 42nd element of a Python list, but they are >> both just abstractions on top of underlying machines, whether the >> machines are virtual, electronic circuits, vacuum tubes, whatever. >> You can add 6 to 42 and get the 48th object, but its Python's >> convention not to call the 48th object a memory address or expose a >> reference to it as a pointer. If I want to pass along the reference >> to the 48th element of a list as the slot to be updated (i.e. with the >> intention to actually mutate the list itself), then I need a tuple >> like (lst, 48). >> > > I think that's the key right there -- if 48 was really a pointer, you > wouldn't need to pass lst in as 48 would in fact be the memory address > of the object you wanted to manipulate. The generalization is known as a "based pointer". Except where it's a fundamental abstraction in a programming language, where it might be called anything. For example, in C++ some so called "member pointers" are logically based pointers. They have pointer syntax (as do C++ iterators, which are not necessarily pointers), but member pointers are not pointers in the C++ standard's sense; in particular, dereferencing a C++ member pointer yields a typeless entity, which is not the case for a normal pointer, although that standard confusingly calls also member pointers pointers in some places, and in other places uses the pointer term only about basic pointers. So, delving into the details of that terminology means traveling into a pretty chaotic territory. But on the other hand, going for the more abstract it gets cleaner and simpler. The Wikipedia article is about in the middle somewhere. It is perhaps not confusing that it is confusing to many. :-) Cheers & hth., - Alf From tgrav at mac.com Sun Feb 14 20:03:26 2010 From: tgrav at mac.com (Tommy Grav) Date: Sun, 14 Feb 2010 20:03:26 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> Message-ID: <5664AF57-8837-4012-ABB4-B9DAA65B0A2F@mac.com> On Feb 14, 2010, at 7:20 PM, Echavarria Gregory, Maria Angelica wrote: > > Dear Chris, > > One of the machines I tested my app in is 64 bit and happened the same. The RAM consumed by the OS and other processes is already included in the 2.2 I'm telling... my app enters to work when the RAM is already consumed in ~600 MB in the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that it started a little bit higher because it has windows 7... so should I understand that there is nothing I can do for my app to use up more RAM? It is not just the machine. If your python is compiled as 32bit then it will be limited to 2GB. To use more you have to use a 64 bit python on a 64 bit machine. Tommy -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Feb 14 21:28:16 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Feb 2010 20:28:16 -0600 Subject: new python install In-Reply-To: <4badnYd5OJHA4eXWnZ2dnUVZ_oidnZ2d@insightbb.com> References: <4badnYd5OJHA4eXWnZ2dnUVZ_oidnZ2d@insightbb.com> Message-ID: <4B78B140.9020804@tim.thechases.com> monkeys paw wrote: > Upon invoking python, it hangs > until Ctrl^C is typed, and then the > >>> interactive shell begins. > > Like so: > > joemoney% python > Python 2.4.6 (#1, Dec 13 2009, 23:45:11) [C] on sunos5 > Type "help", "copyright", "credits" or "license" for more information. > # Hangs ^^^ at this point until ^C is typed > ^C > > >>> > > I've seen this in other new installs and wondered if there is > a common problem that would cause this? It's on a sun os box Though I've never seen such live, perhaps you have some sort of site-wide or user-specific config file such as ~/.pythonrc.py or a site-wide site.py file. You can read up a bit at http://docs.python.org/library/site.html http://docs.python.org/library/user.html I believe the way to test this is to start Python with either the -s or -S option (or both) to disable looking for user or site modules. Also check if you have some crazy value set for $PYTHONSTARTUP. http://docs.python.org/using/cmdline.html#cmdoption-S My guess is that something in one of these places is triggering the hang until you kill that with a ^C after which you get the requested prompt. Hope this helps, -tkc From davea at ieee.org Sun Feb 14 22:16:51 2010 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Feb 2010 22:16:51 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu>, , <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> Message-ID: <4B78BCA3.4070801@ieee.org> Echavarria Gregory, Maria Angelica wrote: > Dear Chris, > > One of the machines I tested my app in is 64 bit and happened the same. The RAM consumed by the OS and other processes is already included in the 2.2 I'm telling... my app enters to work when the RAM is already consumed in ~600 MB in the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that it started a little bit higher because it has windows 7... so should I understand that there is nothing I can do for my app to use up more RAM? > > Thanks for your time and answer, > Angelica. > > > M. Angelica Echavarria-Gregory, M.Sc., E.I. > Ph.D Candidate > University of Miami > Phone 305 284-3611 > > ________________________________ > From: Chris Kaynor [ckaynor at zindagigames.com] > Sent: Friday, February 12, 2010 7:44 PM > To: Echavarria Gregory, Maria Angelica > Cc: python-list at python.org > Subject: Re: MemoryError, can I use more? > > A 32 bit app can only use 4 GB of memory itself (regardless of the amount of system ram), the OS claims some of this for the system, dlls occupy some of it, etc. As such, the app can only really use a smaller subset (generally between 2 to 3 GB, depending upon the app and the OS). > > Chris > > > On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica > wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... > > Thanks, > Angelica. > -- > http://mail.python.org/mailman/listinfo/python-list > > > There are three different limits at play here. Since you're still not saying how you're "measuring" usage, we've all been guessing just which one you're hitting. There's physical RAM, virtual address space, and swappable space (swapfile on disk). Each reaches some limit in different ways. And there are probably a dozen different ways to measure "memory use," that get a dozen different answers. If you say which one you're using, that gives "exactly 2.2 GB," maybe someone will be familiar with that particular approach, and its meaning. DaveA From tgrav at mac.com Sun Feb 14 22:39:13 2010 From: tgrav at mac.com (Tommy Grav) Date: Sun, 14 Feb 2010 22:39:13 -0500 Subject: MemoryError, can I use more? In-Reply-To: <4B78BCA3.4070801@ieee.org> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> <4B78BCA3.4070801@ieee.org> Message-ID: <5FB189C5-544D-4ADF-975C-1F32776C2DB5@mac.com> On Feb 14, 2010, at 10:16 PM, Dave Angel wrote: > There are three different limits at play here. Since you're still not saying how you're "measuring" usage, we've all been guessing just which one you're hitting. There's physical RAM, virtual address space, and swappable space (swapfile on disk). Each reaches some limit in different ways. > > And there are probably a dozen different ways to measure "memory use," that get a dozen different answers. If you say which one you're using, that gives "exactly 2.2 GB," maybe someone will be familiar with that particular approach, and its meaning. I ran into the same problem on Mac OS X and investigated it. My problem was that the program reached a memory error after using 2.2GB of memory. Now what caused it specifically I am less sure of, but switching to a 64bit python on a 64bit OS (snow leopard) means that I now frequently move past this boundary (when I have enough memory of course :) Tommy From chiranjeevi.muttoju at gmail.com Mon Feb 15 03:50:33 2010 From: chiranjeevi.muttoju at gmail.com (chiranjeevi muttoju) Date: Mon, 15 Feb 2010 00:50:33 -0800 (PST) Subject: hi can any one please help me.. Message-ID: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> Hi, when i'm installing the pytc(python wrapper for tokyo cabinet.) i'm getting the fallowing error.. i'm getting this error for python2.6 only.. for python 2.4 its working fine.. --------------------------------------------- running install running build running build_ext building 'pytc' extension gcc -pthread -shared build/temp.linux-x86_64-2.6/pytc.o -L/usr/local/ lib -L. -ltokyocabinet -lpython2.6 -o build/lib.linux-x86_64-2.6/ pytc.so /usr/bin/ld: cannot find -lpython2.6 collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 --------------------------------------------- What is that error. if any body know please help me.. thank you. From alfps at start.no Mon Feb 15 04:11:18 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 10:11:18 +0100 Subject: hi can any one please help me.. In-Reply-To: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> References: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> Message-ID: * chiranjeevi muttoju: > Hi, > when i'm installing the pytc(python wrapper for tokyo cabinet.) i'm > getting the fallowing error.. i'm getting this error for python2.6 > only.. for python 2.4 its working fine.. > --------------------------------------------- > running install > running build > running build_ext > building 'pytc' extension > gcc -pthread -shared build/temp.linux-x86_64-2.6/pytc.o -L/usr/local/ > lib -L. -ltokyocabinet -lpython2.6 -o build/lib.linux-x86_64-2.6/ > pytc.so > /usr/bin/ld: cannot find -lpython2.6 > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > > --------------------------------------------- > > What is that error. if any body know please help me.. thank you. It means the compiler can't find the python2.6 library; it's not in any of the directories where gcc searches for libraries. You can specify (additional) directories where gcc should search for libraries via the LIBRARY_PATH environment variable. At least according to my MinGW documentation for Windows, but I assume that it's the same in Linux. Cheers & hth., - Alf From steve at lonetwin.net Mon Feb 15 04:12:53 2010 From: steve at lonetwin.net (steve) Date: Mon, 15 Feb 2010 14:42:53 +0530 Subject: hi can any one please help me.. References: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> Message-ID: Hello, On 02/15/2010 02:20 PM, chiranjeevi muttoju wrote: > Hi, > when i'm installing the pytc(python wrapper for tokyo cabinet.) i'm > getting the fallowing error.. i'm getting this error for python2.6 > only.. for python 2.4 its working fine.. > --------------------------------------------- > running install > running build > running build_ext > building 'pytc' extension > gcc -pthread -shared build/temp.linux-x86_64-2.6/pytc.o -L/usr/local/ > lib -L. -ltokyocabinet -lpython2.6 -o build/lib.linux-x86_64-2.6/ > pytc.so > /usr/bin/ld: cannot find -lpython2.6 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You need to install the python development libraries. For example if you are doing this on a Fedora or Red Hat Enterprise Linux system, execute the command: $ yum install python-devel ...to install the necessary libraries. cheers, - steve From peloko45 at gmail.com Mon Feb 15 04:23:52 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 15 Feb 2010 01:23:52 -0800 (PST) Subject: Printing with raw_input Message-ID: Does `raw_input` uses internally `sys.stdout.write`? From __peter__ at web.de Mon Feb 15 05:11:20 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 11:11:20 +0100 Subject: Printing with raw_input References: Message-ID: Joan Miller wrote: > Does `raw_input` uses internally `sys.stdout.write`? You can test this yourself without reading the C source: 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. >>> import sys >>> class A: ... def write(self, s): ... sys.__stdout__.write(s.upper()) ... >>> sys.stdout = A() >>> print "yadda" YADDA >>> raw_input("foo") FOObar 'BAR' Peter From katrinewhiteson at gmail.com Mon Feb 15 05:32:36 2010 From: katrinewhiteson at gmail.com (katrine) Date: Mon, 15 Feb 2010 02:32:36 -0800 (PST) Subject: trouble installing matplotlib - syslibroot: multiply specified Message-ID: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> Hi, Hope you guys don't mind a question about building matplotlib from a biologist who wants to learn how to use python. I am trying to install matplotlib on my mac with OS X 10.4.11, using python 2.6.4 and Xcode 2.2.1. I have had a few fights with freetype and Tkinter, and I think I've got those worked out. I have configured and installed numpy, freetype, zlib, and libpng. But I am still getting an error about multiply specified syslibroot - does this make sense to anyone? Maybe I need to change the PATH somehow? Or maybe Xcode is not installed properly? (I am using the make.osx provided with matplotlib, and I am including the top of the file as I am running it here: # build mpl into a local install dir with PREFIX=/usr/local MPLVERSION=0.99.1.1 PYVERSION=2.6 PYTHON=python${PYVERSION} ZLIBVERSION=1.2.3 PNGVERSION=1.2.33 FREETYPEVERSION=2.3.7 MACOSX_DEPLOYMENT_TARGET=10.4 ## You shouldn't need to configure past this point CFLAGS="-arch i386 -arch ppc -I${PREFIX}/include -isysroot /Developer/ SDKs/MacOSX10.4u.sdk" LDFLAGS="-arch i386 -arch ppc -L${PREFIX}/lib -syslibroot,/Developer/ SDKs/MacOSX10.4u.sdk" ---------------------- ****************** ---------------------- Now here is what happens when I try to make the make.osx: katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ make -f make.osx mpl_build export MACOSX_DEPLOYMENT_TARGET=10.4 &&\ export CFLAGS="-arch i386 -arch ppc -I/usr/local/include -I/usr/local/ include/freetype2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk" &&\ export LDFLAGS="-arch i386 -arch ppc -L/usr/local/lib -syslibroot,/ Developer/SDKs/MacOSX10.4u.sdk" &&\ python2.6 setup.py build ============================================================================ BUILDING MATPLOTLIB matplotlib: 0.99.1.1 python: 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) [GCC 4.0.1 (Apple Inc. build 5493)] platform: darwin REQUIRED DEPENDENCIES numpy: 1.3.0 freetype2: found, but unknown version (no pkg-config) * WARNING: Could not find 'freetype2' headers in any * of '.', './freetype2'. OPTIONAL BACKEND DEPENDENCIES libpng: found, but unknown version (no pkg-config) * Could not find 'libpng' headers in any of '.' Tkinter: Tkinter: 73770, Tk: 8.4, Tcl: 8.4 wxPython: no * wxPython not found Gtk+: no * Building for Gtk+ requires pygtk; you must be able * to "import gtk" in your build/install environment Mac OS X native: yes Qt: no Qt4: no Cairo: no OPTIONAL DATE/TIMEZONE DEPENDENCIES datetime: present, version unknown dateutil: matplotlib will provide pytz: matplotlib will provide adding pytz OPTIONAL USETEX DEPENDENCIES dvipng: no ghostscript: /bin/sh: line 1: gs: command not found latex: no [Edit setup.cfg to suppress the above messages] ============================================================================ pymods ['pylab'] packages ['matplotlib', 'matplotlib.backends', 'matplotlib.projections', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid', 'matplotlib.sphinxext', 'matplotlib.numerix', 'matplotlib.numerix.mlab', 'matplotlib.numerix.ma', 'matplotlib.numerix.linear_algebra', 'matplotlib.numerix.random_array', 'matplotlib.numerix.fft', 'matplotlib.delaunay', 'pytz', 'dateutil', 'dateutil/zoneinfo'] running build running build_py copying lib/matplotlib/mpl-data/matplotlibrc -> build/lib.macosx-10.4- fat-2.6/matplotlib/mpl-data copying lib/matplotlib/mpl-data/matplotlib.conf -> build/ lib.macosx-10.4-fat-2.6/matplotlib/mpl-data running build_ext building 'matplotlib.ft2font' extension c++ -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g - bundle -undefined dynamic_lookup -arch i386 -arch ppc -L/usr/local/lib -syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc -I/ usr/local/include -I/usr/local/include/freetype2 -isysroot /Developer/ SDKs/MacOSX10.4u.sdk build/temp.macosx-10.4-fat-2.6/src/ft2font.o build/temp.macosx-10.4-fat-2.6/src/mplutils.o build/temp.macosx-10.4- fat-2.6/CXX/cxx_extensions.o build/temp.macosx-10.4-fat-2.6/CXX/ cxxsupport.o build/temp.macosx-10.4-fat-2.6/CXX/ IndirectPythonInterface.o build/temp.macosx-10.4-fat-2.6/CXX/ cxxextensions.o -lfreetype -lz -lstdc++ -lm -o build/lib.macosx-10.4- fat-2.6/matplotlib/ft2font.so powerpc-apple-darwin8-g++-4.0.1: unrecognized option '-syslibroot,/ Developer/SDKs/MacOSX10.4u.sdk' i686-apple-darwin8-g++-4.0.1: unrecognized option '-syslibroot,/ Developer/SDKs/MacOSX10.4u.sdk' //usr/bin/ld: -usr/syslibroot: multiply specified bincollect2: /ld: -syslibroot: multiply specified ld returned 1 exit statuscollect2: ld returned 1 exit status lipo: can't open input file: /var/tmp//ccym1XU1.out (No such file or directory) error: command 'c++' failed with exit status 1 make: *** [mpl_build] Error 1 katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ gcc -V gcc: argument to `-V' is missing katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ which gcc /usr/bin/gcc katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ c f yj ny -bash: c: command not found katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ k/l -bash: k/l: No such file or directory From alfps at start.no Mon Feb 15 06:20:10 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 12:20:10 +0100 Subject: trouble installing matplotlib - syslibroot: multiply specified In-Reply-To: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> References: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> Message-ID: * katrine: > > Hope you guys don't mind a question about building matplotlib from a > biologist who wants to learn how to use python. > > I am trying to install matplotlib on my mac with OS X 10.4.11, using > python 2.6.4 and Xcode 2.2.1. I have had a few fights with freetype > and Tkinter, and I think I've got those worked out. I have configured > and installed numpy, freetype, zlib, and libpng. But I am still > getting an error about multiply specified syslibroot - does this make > sense to anyone? Don't know if this will help, but I just googled "syslibroot", and it coughed up the following discussion: Quoting from that thread: "Try not setting LDFLAGS. Passing -isysroot to gcc might cause it to pass -isyslibroot to the linker if you're using gcc to link." Cheers, - Alf From hjebbers at gmail.com Mon Feb 15 06:39:57 2010 From: hjebbers at gmail.com (hjebbers) Date: Mon, 15 Feb 2010 03:39:57 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> Message-ID: <9d348145-1dec-42cb-a4c3-408c9833a1bc@a5g2000yqi.googlegroups.com> On 13 feb, 13:48, Dave Angel wrote: > hjebbers wrote: > > On Feb 13, 10:25 am, Dennis Lee Bieber wrote: > > >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > >> declaimed the following in gmane.comp.python.general: > > >>> What strikes me is: > >>> 1. the crash on windows, but linux works OK (same test sets) > >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > >>> much). > > >> ? ? ? ? Which on its own does not mean much. > > >> ? ? ? ? Windows in a normal installation only grants 2GB address space to > >> user code, reserving the other 2GB space for the OS shared libraries. If > >> your program attempts to allocate over that, it will fail. That the > >> Windows box has twice the physical memory only means it doesn't resort > >> to page swapping as soon. > > >> ? ? ? ? There is a boot parameter switch that toggles Windows into a 3GB > >> user/1GB OS mode -- > > > hey, that would be great!! on my 1,5G mahcine ;-) > > >> it is mainly meant for server machines where there > >> won't be many disjoint OS libraries loaded, but the server applications > >> need lots of data space. > > >> ? ? ? ? What split does the Linux OS use? If it give 3GB to user space, > >> while you'd start to page swap much soon, you'd also have 50% more > >> virtual memory that can be allocated than under Windows. > >> -- > >> ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > >> ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ > > > I will check this.....any advice on how to check this? > > > henk-jan > > As I posted in recent thread on Tutor, > > But the one you might want is a boot.ini option that tells the OS to > only reserve 1gb for itself, and leave 3gb for user space. ?But there > are tradeoffs, including the need to modify an application's executable > to take advantage of it. ?And the whole system may run substantially > slower, even when your're extended app isn't running. ?See links: > ?http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx > > http://blogs.technet.com/askperf/archive/2007/03/23/memory-management... > > DaveA Yes, you are right, i also would need to modify the executable. the reason why I posted on this list was the hard crash of python - which python really should not do I think. AFAICS there is no 'bug' in my edi translator (runs OK on linux) - but it uses far to much memory..... For me, I am going to bring back the memory footprint of my edi translator. Which should be fairly easy to do. kind regards, henk-jan From peloko45 at gmail.com Mon Feb 15 06:40:11 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 15 Feb 2010 03:40:11 -0800 (PST) Subject: Printing with raw_input References: Message-ID: On 15 feb, 10:11, Peter Otten <__pete... at web.de> wrote: > Joan Miller wrote: > > Does `raw_input` uses internally `sys.stdout.write`? > > You can test this yourself without reading the C source: > > 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.>>> import sys > >>> class A: > > ... ? ? def write(self, s): > ... ? ? ? ? ? ? sys.__stdout__.write(s.upper()) > ...>>> sys.stdout = A() > >>> print "yadda" > YADDA > >>> raw_input("foo") > > FOObar > 'BAR' > > Peter It was to display the output inside a GUI app. overriding `sys.stdout`. And as `print` also uses internally `sys.stdout.write` then can be used `print` the shell script and get the output too in the GUI, cann't it? From __peter__ at web.de Mon Feb 15 07:05:58 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 13:05:58 +0100 Subject: Printing with raw_input References: Message-ID: Joan Miller wrote: >> > Does `raw_input` uses internally `sys.stdout.write`? > It was to display the output inside a GUI app. overriding > `sys.stdout`. And as `print` also uses internally `sys.stdout.write` > then can be used `print` the shell script and get the output too in > the GUI, cann't it? It should be easy to collect data written with print and show it in a gui, but I can't see how you would integrate raw_input() into a gui app. As to shell scripts, you can invoke them via subprocess, or, if the script needs user interaction, via pexpect. Peter From chyavana at gmail.com Mon Feb 15 07:35:32 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Mon, 15 Feb 2010 20:35:32 +0800 Subject: Executing a command from within python using the subprocess module Message-ID: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Dear Folks, I want to execute a command from within python using the subprocess module. Coming from a Perl background, I thought I could use variable interpolation in strings, but found that this is neither supported nor the Python way. Accordingly, I am a little at sea about how to accomplish it. I have stated what I am trying to do in the minimal example below: --- import subprocess width = 5 height = 30 colors = ['#abcdef]', '#456789'] filename = "/tmp/image.png" # I want to get the equivalent of variable interpolation in Perl # so that the command # # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png # # is derived from the variables above # and executed by subprocess.call() or subprocess.Popen() # from within Python # # Note that the command "convert" is from the ImageMagick suite # It exists and is executable by the shell; # the remaining values are arguments. # The command has been confirmed to execute correctly. --- Thanks in advance. Chandra From alfps at start.no Mon Feb 15 07:44:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 13:44:32 +0100 Subject: Executing a command from within python using the subprocess module In-Reply-To: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: * R (Chandra) Chandrasekhar: > > width = 5 > height = 30 > colors = ['#abcdef]', '#456789'] > filename = "/tmp/image.png" > > # I want to get the equivalent of variable interpolation in Perl > # so that the command > # > # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png > # > # is derived from the variables above Assuming that the extra right square bracket in 'colors' is a typo, here's one way: s = "convert -size {w}x{h} gradient:{g1}-{g2} {f}".format( w = width, h = height, g1 = colors[0], g2 = colors[1], f = filename ) Cheers & hth., - ALf From __peter__ at web.de Mon Feb 15 08:02:42 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 14:02:42 +0100 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: R (Chandra) Chandrasekhar wrote: > I want to execute a command from within python using the subprocess > module. > > Coming from a Perl background, I thought I could use variable > interpolation in strings, but found that this is neither supported nor > the Python way. Accordingly, I am a little at sea about how to > accomplish it. import subprocess def convert(width=5, height=30, colors=['#abcdef', '#456789'], filename="tmp/image with space in its name.png"): lookup = locals() assert all("\n" not in str(s) for s in lookup.values()) subprocess.call("""\ convert -size {width}x{height} gradient:{colors[0]}-{colors[1]} {filename}""".format(**lookup).splitlines()) convert() Peter From anand.shashwat at gmail.com Mon Feb 15 08:11:32 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 15 Feb 2010 18:41:32 +0530 Subject: Printing with raw_input In-Reply-To: References: Message-ID: raw_input uses sys.stderr I guess ? On Mon, Feb 15, 2010 at 5:35 PM, Peter Otten <__peter__ at web.de> wrote: > Joan Miller wrote: > > >> > Does `raw_input` uses internally `sys.stdout.write`? > > > It was to display the output inside a GUI app. overriding > > `sys.stdout`. And as `print` also uses internally `sys.stdout.write` > > then can be used `print` the shell script and get the output too in > > the GUI, cann't it? > > It should be easy to collect data written with print and show it in a gui, > but I can't see how you would integrate raw_input() into a gui app. > > As to shell scripts, you can invoke them via subprocess, or, if the script > needs user interaction, via pexpect. > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From katrinewhiteson at gmail.com Mon Feb 15 08:56:37 2010 From: katrinewhiteson at gmail.com (katrine) Date: Mon, 15 Feb 2010 05:56:37 -0800 (PST) Subject: trouble installing matplotlib - syslibroot: multiply specified References: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> Message-ID: On Feb 15, 12:20 pm, "Alf P. Steinbach" wrote: > * katrine: > > > > > Hope you guys don't mind a question about building matplotlib from a > > biologist who wants to learn how to use python. > > > I am trying to install matplotlib on my mac with OS X 10.4.11, using > > python 2.6.4 and Xcode 2.2.1. I have had a few fights with freetype > > and Tkinter, and I think I've got those worked out. I have configured > > and installed numpy, freetype, zlib, and libpng. But I am still > > getting an error about multiply specified syslibroot - does this make > > sense to anyone? > > Don't know if this will help, but I just googled "syslibroot", and it coughed up > the following discussion: > > > > Quoting from that thread: "Try not setting LDFLAGS. Passing -isysroot to gcc > might cause it to pass -isyslibroot to the linker if you're using gcc to link." > > Cheers, > > - Alf thanks! I managed to install an egg with easy_install, seems to work, FINALLY! thanks for your help, Katrine From jeanmichel at sequans.com Mon Feb 15 09:03:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 15:03:40 +0100 Subject: Replace various regex In-Reply-To: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Message-ID: <4B79543C.5070709@sequans.com> Martin wrote: > Hi, > > I am trying to come up with a more generic scheme to match and replace > a series of regex, which look something like this... > > 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) > 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > would then like to be able to replace one or all of the corresponding > numbers on the line. So far I have a rather unsatisfactory solution, > any suggestions would be appreciated... > > The file read in is an ascii file. > > f = open(fname, 'r') > s = f.read() > > if CANHT: > s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! > canht_ft", CANHT, s) > > where CANHT might be > > CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' > > But this involves me passing the entire string. > > Thanks. > > Martin > I remove all lines containing things like 9*0.0 in your file, cause I don't know what they mean and how to handle them. These are not numbers. import re replace = { 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 } testBuffer = """ 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) 0.46 ! snow_grnd 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) """ outputBuffer = '' for line in testBuffer.split('\n'): for key, (index, repl) in replace.items(): if key in line: parameters = { 'n' : '[\d\.]+', # given you example you have to change this one, I don't know what means 9*0.0 in your file 'index' : index - 1, } # the following pattern will silently match any digit before the th digit is found, and use a capturing parenthesis for the last pattern = '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % parameters # regexp are sometimes a nightmare to read line = re.sub(pattern, r'\1 '+repl+r'\3' , line) break outputBuffer += line +'\n' print outputBuffer From starglider.dev at gmail.com Mon Feb 15 09:10:53 2010 From: starglider.dev at gmail.com (starglider develop) Date: Mon, 15 Feb 2010 14:10:53 +0000 Subject: Talking with ebay using Python Message-ID: Hi, I need a way of talking with the eBay API: Made search, Ask for item status. What can it be done, and where can I get the info. Thank you in advance for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From acl at info.fundp.ac.be Mon Feb 15 09:11:37 2010 From: acl at info.fundp.ac.be (Anthony Cleve) Date: Mon, 15 Feb 2010 06:11:37 -0800 (PST) Subject: CFP - SLE'2010 Message-ID: <5d5f260a-71e2-46a1-80ee-ba6a4405bc7e@b7g2000yqd.googlegroups.com> CALL FOR PAPERS 3rd International Conference on Software Language Engineering SLE 2010 12-13 Oct 2010 -- Eindhoven, The Netherlands http://planet-sl.org/sle2010/ Co-located with the International Conference on Generative Programming and Component Engineering (GPCE'10). ------------------------------------------------------------ DATES Jun 28: Abstract submission (required) Jul 05: Paper submission (midnight Apia Samoa time) Aug 27: Author notification Sep 17: Paper submission for online proceedings Oct 12-13: SLE 2010 Dec 03: Camera-ready copy submission for post-proceedings ------------------------------------------------------------ Software language engineering is devoted to topics related to artificial languages in software engineering. The foremost mission of the International Conference on Software Language Engineering (SLE) is to encourage and organize communication between communities that traditionally have looked at soft- ware languages from different, more specialized, and yet complementary perspectives. Thus, technologies, methods, experiments and case studies from modelware, grammarware, and ontologyware serving the objectives of software languages are of particular relevance to SLE. We invite high-quality submissions to all conference tracks. Submissions must be PDF files following the Springer LNCS style and will be managed using the EasyChair submission system. Please check the conference web site for further information. New at SLE 2010 is a Doctoral Symposium that will provide a supportive yet questioning setting in which PhD students can present their work, including goals, methods, and preliminary results. The Symposium aims to provide students with useful guidance and feedback on various aspects of their research from established researchers and the other student attendees. Please forward this call to anyone who might be interested. http://planet-sl.org/sle2010/ ------------------------------------------------------------ PAPER SUBMISSION Submitted papers must be original work and must not be previously published in, currently submitted to, or currently in consideration for any journal, book, conference, or workshop. Each submitted paper will be reviewed closely by at least three members of the program committee. Accepted papers will be distributed at the conference via the online proceedings as well as published in the post-proceedings, which will appear in the Springer Lecture Notes in Computer Science (LNCS) series. Authors will have the opportunity to revise their accepted paper(s) for the pre- and post- proceedings. For an accepted paper to appear in the proceedings, at least one author must attend the event and present the work. ------------------------------------------------------------ RESEARCH PAPERS Research papers should report a substantial research contribution to SLE and/or a successful application of SLE techniques. We solicit high-quality contributions in the area of SLE ranging from theoretical and conceptual contributions to tools, techniques, and frameworks that support the aforementioned lifecycle activities. We list examples of tools, techniques, applications, and problems of interest to clarify the types of contributes that we seek: * Formalisms used in designing and specifying languages and tools that analyze such language descriptions * Language implementation techniques * Program and model transformation tools * Composition, integration, and mapping tools for managing different aspects of software languages or different manifestations of a given language * Transformations and transformation languages between languages and models * Language evolution * Approaches to elicitation, specification, or verification of requirements for software languages * Language development frameworks, methodologies, techniques, best practices, and tools for the broader language lifecycle covering phases such as analysis, testing , and documentation. * Design challenges in SLE * Applications of languages including innovative domain-specific languages or "little" languages The preceding list is not exclusive or exhaustive. Visit the conference web site for more information about the scope and topics of interest of SLE, or contact the program co-chairs with questions. Page limit: 20 ------------------------------------------------------------ SHORT PAPERS Short paper may describe interesting or thought-provoking concepts that are not yet fully developed or evaluated, make an initial contribution to challenging research issues in SLE, or discuss and analyze controversial issues in the field. Page limit: 10 ------------------------------------------------------------ TOOL DEMONSTRATION PAPERS Because of SLE's ample interest in tools, we seek papers that present software tools related to the field of SLE. These papers will accompany a tool demonstration to be given at the conference. The selection criteria include the originality of the tool, its innovative aspects, the relevance of the tool to SLE, and the maturity of the tool. Submissions may also include an appendix (that will not be published) containing additional screen-shots and discussion of the proposed demonstration. Page limit: 10 ------------------------------------------------------------ MINI-TUTORIAL PAPERS SLE is composed of various research areas, such as grammarware, modelware, language schemas, and semantic technologies. The cross product of attendees at SLE creates a situation where the contribution from one session may be difficult to understand by those not initiated to the area. To help unite the various communities of SLE 2010, we solicit mini-tutorials that provide discussion points for mapping common ideas between related and complementary research topics of SLE. A mini-tutorial submission should be between 15 and 20 pages. ------------------------------------------------------------ GENERAL CHAIR Mark van den Brand Eindhoven University of Technology, The Netherlands m.g.j.v.d.brand at tue.nl PROGRAM CO-CHAIRS Brian Malloy Clemson University, USA malloy at cs.clemson.edu Steffen Staab University of Koblenz-Landau, Germany staab at uni-koblenz.de DOCTORAL SYMPOSIUM CHAIRS Eric van Wyk University of Minnesota, USA evw at cs.umn.edu Steffen Zschaler Lancaster University, UK szschaler at acm.org ORGANIZATION COMMITTEE Anthony Cleve (Publicity Co-Chair) INRIA Lille, France Nicholas Kraft (Publicity Co-Chair) University of Alabama, USA Arjan van der Meer (Web Chair) Eindhoven University of Technology, The Netherlands Alexander Serebrenik (Finance Chair) Eindhoven University of Technology, The Netherlands PROGRAM COMMITTEE Uwe Assmann, Dresden University of Technology, Germany Colin Atkinson, University of Mannheim , Germany Sonia Bergamaschi, University of Modena and Reggio Emilia, Italy John Boyland, University of Wisconsin-Milwaukee, USA Jordi Cabot, University of Toronto, Canada Silvana Castano, University of Milan, Italy Anthony Cleve, INRIA Lille, France Michael Collard, University of Akron, USA Charles Consel, LaBRI / INRIA, France Stephen Edwards, Columbia University, USA Gregor Engels, University of Paderborn, Germany Aldo Gangemi, Semantic Technology Laboratory, Italy Chiara Ghidini, FBK-irst, Italy Jeff Gray, University of Alabama, USA Peter Haase, University of Karlsruhe, Germany Gorel Hedin, Lund University, Sweden Geert-Jan Houben, Delft University of Technology, The Netherlands Adrian Johnstone, University of London, UK Nicholas Kraft, University of Alabama, USA Ivan Kurtev, University of Twente, The Netherlands Julia Lawall, University of Copenhagen, Denmark Marjan Mernik, University of Maribor, Slovenia Pierre-Etienne Moreau, Ecole des Mines in Nancy, France Peter Mosses, Swansea University, UK Ralf M??ller, Hamburg University of Technolog, Germany Istvan Nagy, ASML, The Netherlands Daniel Oberle, SAP Research, Germany Richard Paige, University of York, UK Jeff Z. Pan, University of Aberdeen, UK Bijan Parsia, University of Manchester, UK James Power, National University of Ireland, Ireland Alexander Serebrenik, Eindhoven University of Technology, The Netherlands Fernando Silva Parreiras, University of Koblenz-Landau, Germany Anthony Sloane, Macquarie University, Australia Eleni Stroulia, University of Alberta, Canada York Sure, University of Koblenz-Landau, Germany Gabriele Taentzer, Technical University of Berlin, Germany Jurgen Vinju, CWI, The Netherlands Eelco Visser, Delft University of Technology, The Netherlands Steffen Zschaler, Lancaster University, UK From mdekauwe at gmail.com Mon Feb 15 09:13:17 2010 From: mdekauwe at gmail.com (Martin) Date: Mon, 15 Feb 2010 06:13:17 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Message-ID: <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> On Feb 15, 2:03 pm, Jean-Michel Pichavant wrote: > Martin wrote: > > Hi, > > > I am trying to come up with a more generic scheme to match and replace > > a series of regex, which look something like this... > > > 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) > > 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) > > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > > would then like to be able to replace one or all of the corresponding > > numbers on the line. So far I have a rather unsatisfactory solution, > > any suggestions would be appreciated... > > > The file read in is an ascii file. > > > f = open(fname, 'r') > > s = f.read() > > > if CANHT: > > s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! > > canht_ft", CANHT, s) > > > where CANHT might be > > > CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' > > > But this involves me passing the entire string. > > > Thanks. > > > Martin > > I remove all lines containing things like 9*0.0 in your file, cause I > don't know what they mean and how to handle them. These are not numbers. > > import re > > replace = { > 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 > 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 > } > > testBuffer = """ > 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) > 0.46 ! snow_grnd > 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) > 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) > 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) > """ > > outputBuffer = '' > for line in testBuffer.split('\n'): > for key, (index, repl) in replace.items(): > if key in line: > parameters = { > 'n' : '[\d\.]+', # given you example you have to change > this one, I don't know what means 9*0.0 in your file > 'index' : index - 1, > } > # the following pattern will silently match any digit before > the th digit is found, and use a capturing parenthesis for the last > pattern = > '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % > parameters # regexp are sometimes a nightmare to read > line = re.sub(pattern, r'\1 '+repl+r'\3' , line) > break > outputBuffer += line +'\n' > > print outputBuffer Thanks I will take a look. I think perhaps I was having a very slow day when I posted and realised I could solve the original problem more efficiently and the problem wasn't perhaps as I first perceived. It is enough to match the tag to the right of the "!" sign and use this to adjust what lies on the left of the "!" sign. Currently I have this...if anyone thinks there is a neater solution I am happy to hear it. Many thanks. variable_tag = 'lai' variable = [200.0, 60.030, 0.060, 0.030, 0.030] # generate adjustment string variable = ",".join(["%s" % i for i in variable]) + ' ! ' + variable_tag # call func to adjust input file adjustStandardPftParams(variable, variable_tag, in_param_fname, out_param_fname) and the inside of this func looks like this def adjustStandardPftParams(self, variable, variable_tag, in_fname, out_fname): f = open(in_fname, 'r') of = open(out_fname, 'w') pattern_found = False while True: line = f.readline() if not line: break pattern = re.findall(r"!\s+"+variable_tag, line) if pattern: print 'yes' print >> of, "%s" % variable pattern_found = True if pattern_found: pattern_found = False else: of.write(line) f.close() of.close() return From jeanmichel at sequans.com Mon Feb 15 09:27:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 15:27:40 +0100 Subject: Replace various regex In-Reply-To: <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> Message-ID: <4B7959DC.2040202@sequans.com> Martin wrote: > On Feb 15, 2:03 pm, Jean-Michel Pichavant > wrote: > >> Martin wrote: >> >>> Hi, >>> >>> I am trying to come up with a more generic scheme to match and replace >>> a series of regex, which look something like this... >>> >>> 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) >>> 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) >>> >>> Ideally match the pattern to the right of the "!" sign (e.g. lai), I >>> would then like to be able to replace one or all of the corresponding >>> numbers on the line. So far I have a rather unsatisfactory solution, >>> any suggestions would be appreciated... >>> >>> The file read in is an ascii file. >>> >>> f = open(fname, 'r') >>> s = f.read() >>> >>> if CANHT: >>> s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! >>> canht_ft", CANHT, s) >>> >>> where CANHT might be >>> >>> CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' >>> >>> But this involves me passing the entire string. >>> >>> Thanks. >>> >>> Martin >>> >> I remove all lines containing things like 9*0.0 in your file, cause I >> don't know what they mean and how to handle them. These are not numbers. >> >> import re >> >> replace = { >> 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 >> 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 >> } >> >> testBuffer = """ >> 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) >> 0.46 ! snow_grnd >> 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) >> 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) >> 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) >> """ >> >> outputBuffer = '' >> for line in testBuffer.split('\n'): >> for key, (index, repl) in replace.items(): >> if key in line: >> parameters = { >> 'n' : '[\d\.]+', # given you example you have to change >> this one, I don't know what means 9*0.0 in your file >> 'index' : index - 1, >> } >> # the following pattern will silently match any digit before >> the th digit is found, and use a capturing parenthesis for the last >> pattern = >> '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % >> parameters # regexp are sometimes a nightmare to read >> line = re.sub(pattern, r'\1 '+repl+r'\3' , line) >> break >> outputBuffer += line +'\n' >> >> print outputBuffer >> > > Thanks I will take a look. I think perhaps I was having a very slow > day when I posted and realised I could solve the original problem more > efficiently and the problem wasn't perhaps as I first perceived. It is > enough to match the tag to the right of the "!" sign and use this to > adjust what lies on the left of the "!" sign. Currently I have > this...if anyone thinks there is a neater solution I am happy to hear > it. Many thanks. > > variable_tag = 'lai' > variable = [200.0, 60.030, 0.060, 0.030, 0.030] > > # generate adjustment string > variable = ",".join(["%s" % i for i in variable]) + ' ! ' + > variable_tag > > # call func to adjust input file > adjustStandardPftParams(variable, variable_tag, in_param_fname, > out_param_fname) > > and the inside of this func looks like this > > def adjustStandardPftParams(self, variable, variable_tag, in_fname, > out_fname): > > f = open(in_fname, 'r') > of = open(out_fname, 'w') > pattern_found = False > > while True: > line = f.readline() > if not line: > break > pattern = re.findall(r"!\s+"+variable_tag, line) > if pattern: > print 'yes' > print >> of, "%s" % variable > pattern_found = True > > if pattern_found: > pattern_found = False > else: > of.write(line) > > f.close() > of.close() > > return > Are you sure a simple if variable_tag in line: # do some stuff is not enough ? People will usually prefer to write for line in open(in_fname, 'r') : instead of your ugly while loop ;-) JM From exallion.long at gmail.com Mon Feb 15 09:31:39 2010 From: exallion.long at gmail.com (Mug) Date: Mon, 15 Feb 2010 06:31:39 -0800 (PST) Subject: constructor overwrite Message-ID: hi ,i had a problem on constructor overwrite: i have something like: class obj: def __init__(self, x=100, y=None): if y is None: self.x=x else: self.y=y so i can call : objet = obj() # x=100 y=None or objet = obj(40) # x= 40 y=None but if i do : objet = obj('not cool') #x='not cool' y=None since x is not typed . i am waiting for a result: objet = obj('not cool') #x=100 y='not cool' as they do in C++ or java. is there a way to do it? thanks From arnodel at googlemail.com Mon Feb 15 09:41:53 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Feb 2010 14:41:53 +0000 Subject: constructor overwrite References: Message-ID: Mug writes: > hi ,i had a problem on constructor overwrite: > i have something like: > > class obj: > def __init__(self, x=100, y=None): > if y is None: > self.x=x > else: > self.y=y > so i can call : > objet = obj() # x=100 y=None > or > objet = obj(40) # x= 40 y=None > > but if i do : > objet = obj('not cool') #x='not cool' y=None > since x is not typed . > > i am waiting for a result: > objet = obj('not cool') #x=100 y='not cool' > as they do in C++ or java. > is there a way to do it? > thanks Your problem doesn't seem very well defined (e.g. do you ever call obj with two arguments?), but as I understand it you can do this: def __init__(self, x=100): if isinstance(x, int): self.x, self.y = x, None else: self.x, self.y = None, x HTH -- Arnaud From steve at holdenweb.com Mon Feb 15 09:58:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 09:58:19 -0500 Subject: constructor overwrite In-Reply-To: References: Message-ID: Mug wrote: > hi ,i had a problem on constructor overwrite: > i have something like: > > class obj: > def __init__(self, x=100, y=None): > if y is None: > self.x=x > else: > self.y=y > so i can call : > objet = obj() # x=100 y=None > or > objet = obj(40) # x= 40 y=None > > but if i do : > objet = obj('not cool') #x='not cool' y=None > since x is not typed . > > i am waiting for a result: > objet = obj('not cool') #x=100 y='not cool' > as they do in C++ or java. > is there a way to do it? > thanks You could check the type(s) of the argument(s) in your code, if you want, but Python does not support signature analysis, dynamic method dispatch or static typing. You can do object = obj("y='not cool') but I doubt this is what you want. Your post raises a couple of thier points. First, __init__ is *not* the constructor. By the time it is called creation of the new object is already complete, and __init__() (as its name suggests) merely initializes it. In Python 2's "new-style" classes, and in Python 3, construction is performed by the class's __new__() method. Secondly, it seems a little strange that you are happy to create different instances, in some of which self.y is not initialized and in others self.x is not initialized. You may have a good reason for doing this, I merely point it out as a potential cause of AttributeError exceptions. regards Steve regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 15 10:05:04 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 15 Feb 2010 16:05:04 +0100 Subject: constructor overwrite In-Reply-To: References: Message-ID: <4b79629f$0$685$426a74cc@news.free.fr> Mug a ?crit : > hi ,i had a problem on constructor overwrite: > i have something like: > > class obj: > def __init__(self, x=100, y=None): > if y is None: > self.x=x > else: > self.y=y With such an initializer, you'll have instances with an attribute 'y' and no attribute 'x', and instances with an attribute 'x' and no attribute 'y' : >>> class Obj(object): ... def __init__(self, x=100, y=None): ... if y is None: self.x = x ... else: self.y = y ... >>> objx = Obj() >>> objx.x 100 >>> objx.y Traceback (most recent call last): File "", line 1, in AttributeError: 'Obj' object has no attribute 'y' >>> objy = Obj(y='foo') >>> objy.x Traceback (most recent call last): File "", line 1, in AttributeError: 'Obj' object has no attribute 'x' >>> objy.y 'foo' >>> Are you *sure* this is what you want ? > so i can call : > objet = obj() # x=100 y=None > or > objet = obj(40) # x= 40 y=None > > but if i do : > objet = obj('not cool') #x='not cool' y=None What else would you expect ??? > since x is not typed . 'x' is a name, and names are indeed "untyped". Now the object bound to name 'x' is actually typed. > i am waiting for a result: > objet = obj('not cool') #x=100 y='not cool' > as they do in C++ or java. Python is neither C++ nor Java (nor Pascal nor Lisp nor FWIW), so trying to forcefit C++/Java idioms will at best lead you to pain and frustation. Just like trying to forcefit Python idioms in C++ or Java (or Pascal or Lisp etc....). > is there a way to do it? objet = obj(y='not cool') Now if you could explain the problem you're trying to solve instead of the solution you thought would solve it, we might eventually provide more help. From benedict.verheyen at gmail.com Mon Feb 15 10:29:05 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Mon, 15 Feb 2010 16:29:05 +0100 Subject: how to structure a directory with many scripts and shared code Message-ID: Hi, i wanted to ask how you guys structure your code. I mainly have scripts that automate small tasks. These scripts use a common set of utility code. My code is structured like this, for example: script_1.py script_2.py script_3.py tools\ |----->__init__.py |----->logutils.py |----->mailutils.py I was thinking of putting code in seperate directories because the number of scripts grows fast and i want to keep it clean. Something like this: script_1.py tools\ |----->__init__.py |----->logutils.py |----->mailutils.py database\ |----->__init__.py |----->script_2.py |----->script_3.py However, when i make a subdirectory, for example database and put a script in there, how would i import logutils or mailtutils from within the database subdirectory? This fails: from tools.logutils import logger Thanks, Benedict From python at bdurham.com Mon Feb 15 10:43:22 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 15 Feb 2010 10:43:22 -0500 Subject: Time out a regular expression in Python 2.6.4? Message-ID: <1266248602.28792.1360069669@webmail.messagingengine.com> Is there any way to time out a regular expression in Python 2.6.4? Motiviation: Our application allows users to enter regular expressions as validation criteria. If a user enters a pathological regular expression, we would like to timeout the evaluation of this expression after a short period of time. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From chyavana at gmail.com Mon Feb 15 10:48:02 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Mon, 15 Feb 2010 23:48:02 +0800 Subject: Executing a command from within python using the subprocess module In-Reply-To: References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B796CB2.2000302@gmail.com> Peter Otten wrote: > import subprocess > > def convert(width=5, height=30, colors=['#abcdef', '#456789'], > filename="tmp/image with space in its name.png"): > lookup = locals() > assert all("\n" not in str(s) for s in lookup.values()) > subprocess.call("""\ > convert > -size > {width}x{height} > gradient:{colors[0]}-{colors[1]} > {filename}""".format(**lookup).splitlines()) > > convert() > > Peter Thank you. It works. Now I need to understand why and am able to follow what you are doing part of the way: 1. Assign default values in the function definition. 2. Store the variables existing in the local namespace in the list lookup. 3. Assert that there are no newlines in the values in lookup converted to strings. (Why? Is this because of splitlines() later on?) 4. Assemble a string (array?) for the subprocess.call argument using the format string syntax (section 8.1.3 et seq. of the Python documentation for 2.6.4). Your example works with default option of shell=False for subprocess.call(). 5. I am unable to decipher how you got to format(**lookup).splitlines()) especially the **prefix part, although I guess that splitlines() is dishing out the arguments one by one from each line in the subprocess.call argument. Any correction of (1) to (4) and an explanation of (5) would be most appreciated. All in all, your code is a magnificent example of wrapping the function within python. This is the first time I have seen something like this. Thank you very much. Chandra From jjposner at optimum.net Mon Feb 15 10:59:05 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 15 Feb 2010 10:59:05 -0500 Subject: Executing a command from within python using the subprocess module In-Reply-To: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B796F49.9020102@optimum.net> On 2/15/2010 7:35 AM, R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I want to execute a command from within python using the subprocess module. > > Coming from a Perl background, I thought I could use variable > interpolation in strings, but found that this is neither supported Yes, it is: see the use of string.Template below. > ... nor > the Python way. That right -- it isn't the Python way. Python offers two basic alternatives. Alf already presented the use of the "new" format() method of string objects. I think "traditional" Python string formatting might be what you want in this case: colors = ['#abcdef', '#456789'] format_string = "convert -size 5x30 gradient:%s-%s /tmp/image.png" cmd_string = format_string % tuple(colors) ... or better, by making *colors* a tuple instead of a list ... colors = ('#abcdef', '#456789') format_string = "convert -size 5x30 gradient:%s-%s /tmp/image.png" cmd_string = format_string % colors As Peter demonstrated, you need to use split() on *cmd_string* when you send the command to subprocess.call(). Now if you *really* miss using Perl, try this: c1, c2 = ('#abcdef', '#456789') template = string.Template( "convert -size 5x30 gradient:$c1-$c2 /tmp/image.png") cmd_string = template.substitute(locals()) Not worth the trouble, IMHO. Refs: http://www.python.org/doc/2.5.2/lib/typesseq-strings.html http://www.python.org/doc/2.5.2/lib/node40.html HTH, John From steve at holdenweb.com Mon Feb 15 10:59:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 10:59:22 -0500 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: <1266248602.28792.1360069669@webmail.messagingengine.com> References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: <4B796F5A.40405@holdenweb.com> python at bdurham.com wrote: > Is there any way to time out a regular expression in Python 2.6.4? > > Motiviation: Our application allows users to enter regular expressions > as validation criteria. If a user enters a pathological regular > expression, we would like to timeout the evaluation of this expression > after a short period of time. > Python itself does not contain any mechanism to terminate an operation if it takes too much time. One approach would be to run the regex in a subprocess, and apply process limits to terminate that subprocess if it ran too long. This group being what it is you are likely to receive other, better suggestions too. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 15 10:59:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 10:59:22 -0500 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: <1266248602.28792.1360069669@webmail.messagingengine.com> References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: <4B796F5A.40405@holdenweb.com> python at bdurham.com wrote: > Is there any way to time out a regular expression in Python 2.6.4? > > Motiviation: Our application allows users to enter regular expressions > as validation criteria. If a user enters a pathological regular > expression, we would like to timeout the evaluation of this expression > after a short period of time. > Python itself does not contain any mechanism to terminate an operation if it takes too much time. One approach would be to run the regex in a subprocess, and apply process limits to terminate that subprocess if it ran too long. This group being what it is you are likely to receive other, better suggestions too. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From pxrepreza at gmail.com Mon Feb 15 11:06:00 2010 From: pxrepreza at gmail.com (Paulo Repreza) Date: Mon, 15 Feb 2010 11:06:00 -0500 Subject: Loop problem while generating a new value with random.randint() Message-ID: Greetings, I'm having problems with a little script that I'm trying to finish, I don't know if I'm in the right track but I know somebody is going to help me. The script: # Import modules random for function randint import random # Generating a constant. var = 65 # Generating a random number. ranum = random.randint(1,100) #Creating while loop. Stops until var == ranum while var != ranum: if var == ranum: print var, 'equals to:', ranum else: print var, 'does not equal to:', ranum ########## End of Script ########### What I'm trying to do is to print the new value that ranum generates if the condition is not met. So far if you run the script it prints the same value over and over again, making in an infinite loop. What can I do in order to print out the new value generated every time the condition is not met? Thanks! Paulo Repreza -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Feb 15 11:06:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 17:06:49 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: Message-ID: <4B797119.6040802@sequans.com> Benedict Verheyen wrote: > Hi, > > i wanted to ask how you guys structure your code. > I mainly have scripts that automate small tasks. > These scripts use a common set of utility code. > My code is structured like this, for example: > > script_1.py > script_2.py > script_3.py > tools\ > |----->__init__.py > |----->logutils.py > |----->mailutils.py > > I was thinking of putting code in seperate directories because the number > of scripts grows fast and i want to keep it clean. > Something like this: > > script_1.py > tools\ > |----->__init__.py > |----->logutils.py > |----->mailutils.py > database\ > |----->__init__.py > |----->script_2.py > |----->script_3.py > > However, when i make a subdirectory, for example database and put a script in there, > how would i import logutils or mailtutils from within the database subdirectory? > This fails: > from tools.logutils import logger > > Thanks, > Benedict > > Hi, 1/ Provide the output of the error so we can provide some useful help. 2/ Embed your structure into a package. Names like 'tools', 'lib', 'mail', 'log' are too generic and will clash with other badly designed module/package names. Choose a name for you package, and use it with absolute imports e.g : from myBeautifulPackage.tools.logutil import logger 3/ make sure your working copy of myBeautifulPackage is in your PYTHONPATH. JM From chyavana at gmail.com Mon Feb 15 11:11:36 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Tue, 16 Feb 2010 00:11:36 +0800 Subject: Executing a command from within python using the subprocess module In-Reply-To: References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B797238.2090007@gmail.com> Peter Otten wrote: > import subprocess > > def convert(width=5, height=30, colors=['#abcdef', '#456789'], > filename="tmp/image with space in its name.png"): > lookup = locals() > assert all("\n" not in str(s) for s in lookup.values()) > subprocess.call("""\ > convert > -size > {width}x{height} > gradient:{colors[0]}-{colors[1]} > {filename}""".format(**lookup).splitlines()) > > convert() > > Peter One other question I forgot to ask is this why is there a terminal backslash in > subprocess.call("""\ Removing the backslash makes the function fail. I wonder why, because """ is supposed to allow multi-line strings. I am sorry if this sounds obtuse but that backslash baffles me. From lacrima.maxim at gmail.com Mon Feb 15 11:15:21 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Mon, 15 Feb 2010 08:15:21 -0800 (PST) Subject: Which mock library do you prefer? Message-ID: Hello! I am newbie mastering test driven development. I can't clarify myself which mock library to use. There are number of them and which one do you prefer? Two libraries that attracted my attention are: * minimock * dingus As for me the latest one, dingus, is the easiest (see this screencast: http://vimeo.com/3949077 ), but it has very few downloads from pypi, so it scares me a little. Minimock has wider usage and community, but I have some troubles using it. Maybe I am wrong, but with minimock you always have to keep track the order of imports in your test modules. Well, may be I just don't understand fully how minimock works. What are your suggestions? From jeanmichel at sequans.com Mon Feb 15 11:17:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 17:17:39 +0100 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: <4B7973A3.3040407@sequans.com> Paulo Repreza wrote: > Greetings, > > I'm having problems with a little script that I'm trying to finish, I > don't know if I'm in the right track but I know somebody is going to > help me. > > The script: > > # Import modules random for function randint > > import random > > # Generating a constant. > > var = 65 > > # Generating a random number. > ranum = random.randint(1,100) > > #Creating while loop. Stops until var == ranum > while var != ranum: > if var == ranum: > print var, 'equals to:', ranum > else: > print var, 'does not equal to:', ranum > > ########## End of Script ########### > > > What I'm trying to do is to print the new value that ranum generates > if the condition is not met. So far if you run the script it prints > the same value over and over again, making in an infinite loop. What > can I do in order to print out the new value generated every time the > condition is not met? > > Thanks! > > Paulo Repreza in your script you generate the random number only once, no wonder it keep being the same value over & over. # Initialize ranum with a random number ranum = random.randint(1,100) #Creating while loop. Stops until var == ranum while var != ranum: if var == ranum: print var, 'equals to:', ranum else: print var, 'does not equal to:', ranum ranum = random.randint(1,100) # generate a new number, that's the missing line in your script JM From mmm286 at gmail.com Mon Feb 15 11:18:50 2010 From: mmm286 at gmail.com (mierdatutis mi) Date: Mon, 15 Feb 2010 17:18:50 +0100 Subject: get a field Message-ID: Hi, I have this: pe=" http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml " I would like to extract this: 691046.shtml But is dynamically. Not always have the same lenght the string. Could you help me how could I do extract this in python? Many thanks and sorry for my English! -------------- next part -------------- An HTML attachment was scrubbed... URL: From benedict.verheyen at gmail.com Mon Feb 15 11:27:41 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Mon, 15 Feb 2010 17:27:41 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4B797119.6040802@sequans.com> References: <4B797119.6040802@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Hi, > > 1/ Provide the output of the error so we can provide some useful help. > 2/ Embed your structure into a package. Names like 'tools', 'lib', > 'mail', 'log' are too generic and will clash with other badly designed > module/package names. Choose a name for you package, and use it with > absolute imports e.g : > from myBeautifulPackage.tools.logutil import logger > 3/ make sure your working copy of myBeautifulPackage is in your PYTHONPATH. > > JM Hi, the error i get is this: Traceback (most recent call last): File "update_tax_responsible.py", line 18, in from tools.logutils import logger ImportError: No module named tools.logutils As to your comments on putting everything in a package, that's the whole problem, it are all scripts where only a few of them are related and they all use one or more modules that are located in the tools directory. In that tools subdirectory i have a py file for typical file functions, time functions, and so on. For instance, the tools\fileutils.py file contains amongst others a function that calculates the size of a directory. If i understood correctly, your suggestion is to put the utility files in the tools subdirectory in a seperate package and put that package on the python path so it can be shared by all scripts. I should then further structure the scripts by putting scripts together. But since the functions in tools are really utility functions for common tasks, what would a meaningfule package name be? The scripts are really diverse for instance, one of the scripts will check the names of subdirectories made by employees, another will send mail if people forget to fill in certain fields in a database and so on. That's one of the reasons why i'm having a hard time structering it. Regards, Benedict From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 15 11:30:29 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 15 Feb 2010 17:30:29 +0100 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: <4b7976a3$0$24284$426a74cc@news.free.fr> Jean-Michel Pichavant a ?crit : > Paulo Repreza wrote: >> Greetings, >> >> I'm having problems with a little script that I'm trying to finish, I >> don't know if I'm in the right track but I know somebody is going to >> help me. (snip - problem already addressed by Jean-Michel...) >> while var != ranum: >> if var == ranum: Note that this branch will never be executed - the condition in the while statement make sure var != ranum in the while block. >> print var, 'equals to:', ranum >> else: >> print var, 'does not equal to:', ranum >> From ssteinerx at gmail.com Mon Feb 15 11:30:59 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 15 Feb 2010 11:30:59 -0500 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4B797119.6040802@sequans.com> References: <4B797119.6040802@sequans.com> Message-ID: <13868D3D-76E6-4F97-8743-FC5479DFB74E@gmail.com> On Feb 15, 2010, at 11:06 AM, Jean-Michel Pichavant wrote: > 3/ make sure your working copy of myBeautifulPackage is in your PYTHONPATH. Or, make a simple setup.py which imports distribute or setuptools and use: # python setup.py develop which will put your code into the PYTHONPATH by virtue of a link inside your site-packages. First one I found googling for "setup.py develop" : https://www.siafoo.net/article/77 There's a typo in the code of section 1.2 (parenthesis at the end of import, wrong), but the basic idea is there. S From steve at holdenweb.com Mon Feb 15 11:31:58 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 11:31:58 -0500 Subject: Executing a command from within python using the subprocess module In-Reply-To: <4B797238.2090007@gmail.com> References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> <4B797238.2090007@gmail.com> Message-ID: R (Chandra) Chandrasekhar wrote: > Peter Otten wrote: >> import subprocess >> >> def convert(width=5, height=30, colors=['#abcdef', '#456789'], >> filename="tmp/image with space in its name.png"): >> lookup = locals() >> assert all("\n" not in str(s) for s in lookup.values()) >> subprocess.call("""\ >> convert >> -size >> {width}x{height} >> gradient:{colors[0]}-{colors[1]} >> {filename}""".format(**lookup).splitlines()) >> >> convert() >> >> Peter > > One other question I forgot to ask is this why is there a terminal > backslash in > >> subprocess.call("""\ > > Removing the backslash makes the function fail. > > I wonder why, because """ is supposed to allow multi-line strings. I am > sorry if this sounds obtuse but that backslash baffles me. It does, but a leading newline would cause the splitlines() result to start with an empty word - the backslash just causes the interpreter to ignore the newline immediately following, rather than including it in the string literal's value. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 15 11:35:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 11:35:16 -0500 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: Paulo Repreza wrote: > Greetings, > > I'm having problems with a little script that I'm trying to finish, I > don't know if I'm in the right track but I know somebody is going to > help me. > > The script: > > # Import modules random for function randint > > import random > > # Generating a constant. > > var = 65 > > # Generating a random number. > ranum = random.randint(1,100) > > #Creating while loop. Stops until var == ranum > while var != ranum: > if var == ranum: The "if" condition can never be true, since if it were then the loop would have just terminated before starting this iteration! > print var, 'equals to:', ranum > else: > print var, 'does not equal to:', ranum > Shouldn't there be something here to set ranum to a new value? Otherwise the same value will be there the next time around ... > ########## End of Script ########### > > > What I'm trying to do is to print the new value that ranum generates if > the condition is not met. So far if you run the script it prints the > same value over and over again, making in an infinite loop. What can I > do in order to print out the new value generated every time the > condition is not met? > > Thanks! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ d From chyavana at gmail.com Mon Feb 15 11:36:44 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Tue, 16 Feb 2010 00:36:44 +0800 Subject: Executing a command from within python using the subprocess module In-Reply-To: References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B79781C.50205@gmail.com> Alf P. Steinbach wrote: > * R (Chandra) Chandrasekhar: >> >> width = 5 >> height = 30 >> colors = ['#abcdef]', '#456789'] >> filename = "/tmp/image.png" >> >> # I want to get the equivalent of variable interpolation in Perl >> # so that the command >> # >> # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png >> # >> # is derived from the variables above > > Assuming that the extra right square bracket in 'colors' is a typo, > here's one way: > > s = "convert -size {w}x{h} gradient:{g1}-{g2} {f}".format( > w = width, h = height, g1 = colors[0], g2 = colors[1], f = filename > ) > > > Cheers & hth., > > - ALf Thanks, Alf. It works if I use it so: subprocess.call(s, shell=True) and I think that is because s is a single string assembled in almost the variable interpolation fashion of Perl. It does not work with the default shell=False argument, presumably because the arguments are not split into separate strings (something that was horrible to do by hand using the %s and %() syntax that I had tried out previously). I think that you and Peter have, between you, shown me two ways of using subprocess.call(): one with shell=True and the other with shell = False. Thanks. Chandra From arnodel at googlemail.com Mon Feb 15 11:39:36 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Feb 2010 16:39:36 +0000 Subject: Loop problem while generating a new value with random.randint() References: Message-ID: Jean-Michel Pichavant writes: > Paulo Repreza wrote: >> Greetings, >> >> I'm having problems with a little script that I'm trying to finish, >> I don't know if I'm in the right track but I know somebody is going >> to help me. >> >> The script: >> >> # Import modules random for function randint >> >> import random >> >> # Generating a constant. >> >> var = 65 >> >> # Generating a random number. >> ranum = random.randint(1,100) >> >> #Creating while loop. Stops until var == ranum >> while var != ranum: >> if var == ranum: >> print var, 'equals to:', ranum >> else: >> print var, 'does not equal to:', ranum >> >> ########## End of Script ########### >> >> >> What I'm trying to do is to print the new value that ranum generates >> if the condition is not met. So far if you run the script it prints >> the same value over and over again, making in an infinite loop. What >> can I do in order to print out the new value generated every time >> the condition is not met? >> >> Thanks! >> >> Paulo Repreza > in your script you generate the random number only once, no wonder it > keep being the same value over & over. > > # Initialize ranum with a random number > ranum = random.randint(1,100) > > #Creating while loop. Stops until var == ranum > while var != ranum: > if var == ranum: > print var, 'equals to:', ranum > else: > print var, 'does not equal to:', ranum > ranum = random.randint(1,100) # generate a new number, that's the > missing line in your script > > JM And a more idiomatic way of writing this in Python would be, I guess: import random var = 65 while True: ranum = random.randint(1, 100) if var == ranum: print var, 'equals to:', ranum break else: print var, 'does not equal to:', ranum (following up from a FU as I can't see the OP) -- Arnaud From __peter__ at web.de Mon Feb 15 11:44:25 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 17:44:25 +0100 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> <4B796CB2.2000302@gmail.com> Message-ID: R (Chandra) Chandrasekhar wrote: > Peter Otten wrote: > >> import subprocess >> >> def convert(width=5, height=30, colors=['#abcdef', '#456789'], >> filename="tmp/image with space in its name.png"): >> lookup = locals() >> assert all("\n" not in str(s) for s in lookup.values()) >> subprocess.call("""\ >> convert >> -size >> {width}x{height} >> gradient:{colors[0]}-{colors[1]} >> {filename}""".format(**lookup).splitlines()) >> >> convert() >> >> Peter > > Thank you. It works. Now I need to understand why and am able to follow > what you are doing part of the way: > > 1. Assign default values in the function definition. > > 2. Store the variables existing in the local namespace in the list lookup. > > 3. Assert that there are no newlines in the values in lookup converted > to strings. (Why? Is this because of splitlines() later on?) Yes. > 4. Assemble a string (array?) for the subprocess.call argument using the > format string syntax (section 8.1.3 et seq. of the Python > documentation for 2.6.4). Your example works with default option of > shell=False for subprocess.call(). I wanted to pass the executable and its arguments as a list (a python "list" is called array in other languages) to avoid bothering with shell escapes. > 5. I am unable to decipher how you got to format(**lookup).splitlines()) > especially the **prefix part, although I guess that splitlines() is > dishing out the arguments one by one from each line in the > subprocess.call argument. Given some_dict = {key1: value1, key2: value2,...} f(**some_dict) is a shortcut for f(key1=value1, key2=value2, ...) with the additional twist that you do not have to know the key/value pairs in advance. I introduced splitlines to avoid calling the format method on every argument to "convert", i. e. def convert2(width=5, height=30, colors=['#abcdef', '#456789'], filename="tmp/image with space in its name.png"): subprocess.call([ "convert", "-size", "{width}x{height}".format(width=width, height=height), "gradient:{0}-{1}".format(*colors), filename]) I supected that it would look cleaner than the above, but now that I tried it I think convert2() is the better alternative. Peter From nobody at nowhere.com Mon Feb 15 11:50:13 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 15 Feb 2010 16:50:13 +0000 Subject: Fighting with subprocess.Popen References: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> Message-ID: On Sun, 14 Feb 2010 21:43:22 +0100, Christian Heimes wrote: >> Below is a test case that demonstrates this. Tests 1 & 2 concatenate the >> command and the argument, Tests 3 & 4 mimic the python docs and use the form >> Popen(["mycmd", "myarg"], ...), which never seems to work. > > It doesn't work with shell=True because the shell is not able to > interpret the list form. It's recommended that you don't use shell=True > unless you need a shell. A more general rule is to use shell=True on Windows and shell=False on Unix (including MacOSX). On Windows, whether the command is a list or a string is entirely orthogonal to whether a shell is used. The underlying execution function (CreateProcess) always uses a string, so a list is always converted to a string, and the conversion is independent of the shell= setting. The difference between shell=False and shell=True is that the former passes the string directly to CreateProcess while the latter passes "cmd.exe /c "+string (cmd.exe is actually the value of %comspec% if it is set). The reason for using shell=True on Windows is that it allows the program to be a batch file (or other script), while shell=False only works if the program is a binary executable (.exe, .com). On Unix, passing the arguments as a list in conjunction with shell=True rarely makes sense. It results in the execution of ["/bin/sh", "-c"] + args i.e. args[0] is the argument to "-c" while the remaining arguments are assigned to the shell variables $1, $2, etc. If you're using the shell, you usually you want to pass the entire command as a string, resulting in the execution of ["/bin/sh", "-c", command] From jeanmichel at sequans.com Mon Feb 15 11:50:41 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 17:50:41 +0100 Subject: get a field In-Reply-To: References: Message-ID: <4B797B61.7090804@sequans.com> mierdatutis mi wrote: > Hi, > > I have this: > > pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" > > > I would like to extract this: 691046.shtml > > But is dynamically. Not always have the same lenght the string. > > Could you help me how could I do extract this in python? > > Many thanks and sorry for my English! > In [2]: import os In [3]: os.path.basename(pe) Out[3]: '691046.shtml' JM From steve at holdenweb.com Mon Feb 15 11:54:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 11:54:22 -0500 Subject: get a field In-Reply-To: References: Message-ID: mierdatutis mi wrote: > Hi, > > I have this: > > pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" > > > I would like to extract this: 691046.shtml > > But is dynamically. Not always have the same lenght the string. > > Could you help me how could I do extract this in python? > > Many thanks and sorry for my English! > >>> s = "http://server/path/to/file/file.shtml" >>> s.rfind("/") # finds rightmost "/" 26 >>> s[s.rfind("/")+1:] # substring starting after "/" 'file.shtml' >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From nobody at nowhere.com Mon Feb 15 11:56:51 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 15 Feb 2010 16:56:51 +0000 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> <4B797238.2090007@gmail.com> Message-ID: On Tue, 16 Feb 2010 00:11:36 +0800, R (Chandra) Chandrasekhar wrote: > One other question I forgot to ask is this why is there a terminal > backslash in > >> subprocess.call("""\ > > Removing the backslash makes the function fail. > > I wonder why, because """ is supposed to allow multi-line strings. I am > sorry if this sounds obtuse but that backslash baffles me. The backslash causes the following newline to be skipped, so the "c" at the beginning of "convert" is the first character in the string. Without it, the newline would be the first character, and the .splitlines() would result in an empty string as the first element in the list. Example: > """ = hello = world = """.splitlines() ['', 'hello', 'world'] > """\ = hello = world = """.splitlines() ['hello', 'world'] From phlip2005 at gmail.com Mon Feb 15 11:57:37 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 15 Feb 2010 08:57:37 -0800 (PST) Subject: Which mock library do you prefer? References: Message-ID: Lacrima wrote: > I am newbie mastering test driven development. I can't clarify myself > which mock library to use. > There are number of them and which one do you prefer? > > Two libraries that attracted my attention are: > * minimock > * dingus > As for me the latest one, dingus, is the easiest (see this screencast:http://vimeo.com/3949077? ), but it has very few downloads from pypi, > so it scares me a little. > Minimock has wider usage and community, but I have some troubles using > it. Maybe I am wrong, but with minimock you always have to keep track > the order of imports in your test modules. Well, may be I just don't > understand fully how minimock works. > > What are your suggestions? I have used http://pypi.python.org/pypi/mock/0.6.0 . It mocks, and it has a mode that works one method at a time, and another mode that mocks a method before its owning object gets constructed. However, TDD is not about mocking, and on greenfield code you should only mock to recover from some external problem, such as: - a random number generator - the system clock - anything over "the wire" - over a TCP/IP socket - hardware, such as your graphics or sound Never mock to avoid hitting the database. Some TDD verbiage advises "never hit the database". That is a mind-game to force you to decouple your code. Your objects should always have the option (via "construction encapsulation") to run as stubs, with some of their behaviors turned off. And if you TDD low-level code that hits a database, a mock would only tell the test what it wants to hear. And if you TDD high-level code that manages business rules, database records make perfectly good behavioral "fixtures" to support those rules. -- Phlip http://c2.com/cgi/wiki?ZeekLand From showell30 at yahoo.com Mon Feb 15 12:02:38 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 15 Feb 2010 09:02:38 -0800 (PST) Subject: Which mock library do you prefer? References: Message-ID: On Feb 15, 8:15?am, Lacrima wrote: > Hello! > > I am newbie mastering test driven development. I can't clarify myself > which mock library to use. > There are number of them and which one do you prefer? > > Two libraries that attracted my attention are: > * minimock > * dingus > As for me the latest one, dingus, is the easiest (see this screencast:http://vimeo.com/3949077? ), but it has very few downloads from pypi, > so it scares me a little. I've used dingus with success. I wouldn't let the lack of downloads be a concern; the funny name is probably scaring some people away, and of course there are other alternatives too. From mukeshtiwari.iiitm at gmail.com Mon Feb 15 12:08:30 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Mon, 15 Feb 2010 09:08:30 -0800 (PST) Subject: Python Optimization References: <892f7664-14e9-4ce4-ab50-499fc8552ec3@v25g2000yqk.googlegroups.com> <0eac0e90-fd39-4851-b979-c109218fb0ba@a5g2000prg.googlegroups.com> Message-ID: <276960d6-97d7-4f46-827e-b14345d8ea2d@s33g2000prm.googlegroups.com> On Feb 15, 1:07?am, Steve Howell wrote: > On Feb 14, 11:52?am, Mark Dickinson wrote: > > > > > > > On Feb 14, 4:53?pm, mukesh tiwari > > wrote: > > > > Hello everyone. I am new to python and previously i did programming in > > > c/c++.Could some one please help me to improve the run time for this > > > python program as i don't have idea how to optimized this code.This > > > code also seems to be more unpythonic so how to make it look like more > > > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > > > FACT1/). > > > Thank you > > > One other thing: ?in the 'brent' function, you're setting m to > > randrange(1, n). ?What's the purpose of this? ?It looks to me as > > though m controls the number of Pollard-Rho iterations that are > > clumped together at one time (before doing a gcd operation), and using > > a random number for this doesn't make a lot of sense to me. > > The randomness also makes the algorithm a little buggy. > > I tried this input: > > 37^5 41^5 > > Usually I get the right answer. ?Other times I get this: > > 37^5 41^3 1681^1 > > And occasionally it appears to get into an infinite loop, which > definitely could be a cause of "slowness." :) Thank you all for help. I will try to improve these short comings. From pxrepreza at gmail.com Mon Feb 15 12:27:29 2010 From: pxrepreza at gmail.com (Paulo Repreza) Date: Mon, 15 Feb 2010 12:27:29 -0500 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: Thanks for the help! Using while True helps alot! Paulo Repreza -------------- next part -------------- An HTML attachment was scrubbed... URL: From fersed at gmail.com Mon Feb 15 12:55:08 2010 From: fersed at gmail.com (fernando sedano) Date: Mon, 15 Feb 2010 18:55:08 +0100 Subject: saving a TIFF Message-ID: I'm trying to save an image created from two arrays (I'm using numpy and PIL): n=(b4a-b3a)/(b4a+b3a); ndvi = Image.fromarray(n) ndvi.save("F:\Fire_scar_mapping\ILS3\ndvi_test","TIFF") ...........but I get the following error message: IOError: [Errno 22] invalid mode ('wb') or filename: 'F:\\Fire_scar_mapping\\ILS3\ndt' Could anybody tell me what I'm doing wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Mon Feb 15 13:06:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Feb 2010 13:06:51 -0500 Subject: saving a TIFF In-Reply-To: References: Message-ID: On Mon, Feb 15, 2010 at 12:55 PM, fernando sedano wrote: > I'm trying to save an image created from two arrays (I'm using numpy and > PIL): > > > n=(b4a-b3a)/(b4a+b3a); > ndvi = Image.fromarray(n) > ndvi.save("F:\Fire_scar_mapping\ILS3\ndvi_test","TIFF") > > ...........but I get the following error message: > > IOError: [Errno 22] invalid mode ('wb') or filename: > 'F:\\Fire_scar_mapping\\ILS3\ndt' > > Could anybody tell me what I'm doing wrong? > > -- > http://mail.python.org/mailman/listinfo/python-list > > ---------- >>> print "F:\Fire_scar_mapping\ILS3\ndvi_test","TIFF" F:\Fire_scar_mapping\ILS3 dvi_test TIFF -------------- Notice anything wrong with that? Unlike the Windows command line, Python neither knows nor cares that the string you're entering is a file name. It sees the \n and converts it to a newline. Either double up your backslashes ( "F:\\Fire_scar_mapping\\ILS3\\ndvi_test"), use a raw string (r"F:\Fire_scar_mapping\ILS3\ndvi_test") or use forward slashes ("F:/Fire_scar_mapping/ILS3/ndvi_test") From python.list at tim.thechases.com Mon Feb 15 13:28:25 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Feb 2010 12:28:25 -0600 Subject: get a field In-Reply-To: References: Message-ID: <4B799249.2020205@tim.thechases.com> Holden wrote: > mierdatutis mi wrote: >> I have this: >> >> pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" >> >> I would like to extract this: 691046.shtml >> >> But is dynamically. Not always have the same lenght the string. > >>>> s = "http://server/path/to/file/file.shtml" >>>> s.rfind("/") # finds rightmost "/" > 26 >>>> s[s.rfind("/")+1:] # substring starting after "/" > 'file.shtml' If I didn't use os.path.basename(s) then I'd write this as "s.rsplit('/', 1)[-1]" >>> "http://server/path/to/file/file.shtml".rsplit('/', 1)[-1] 'file.shtml' >>> "".rsplit('/', 1)[-1] '' >>> "file.html".rsplit('/', 1)[-1] 'file.html' I don't know how much of a difference it makes, but I always appreciate seeing how various people solve the same problem. I tend to lean away from the find()/index() methods on strings because I have to stop and think which one raises the exception and which one returns -1 (and that it's -1 instead of 0) usually dropping to a python shell and doing >>> help("".find) >>> help("".index) to refresh my memory. FWIW, Steve's solution and the os.path.basename() both produce the same results with all 3 input values, so it's more a matter of personal style preference. The basename() version has slightly different results if you have Windows paths with backslashes: s = r'c:\path\to\file.txt' but since you (OP) know that they should be URLs with forward-slashes, it should be a non-issue. -tkc From leo at lspace.org Mon Feb 15 13:29:38 2010 From: leo at lspace.org (Leo Breebaart) Date: 15 Feb 2010 18:29:38 GMT Subject: Using class attributes Message-ID: <7tti4iFehdU1@mid.individual.net> I have a base class Foo with a number of derived classes FooA, FooB, FooC, etc. Each of these derived classes needs to read (upon initialisation) text from an associated template file FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. I can derive the template filename string for each instance by doing something like this in the base class (and then not forgetting to call super() in the __init__() of each derived class): class Foo(object): def __init__(self): self.template_filename = "%s.tmpl" % self.__class__.__name__ self.template_body = read_body_from(self.template_filename) But, since this information is the same for every instance of each derived class, I was wondering if there was a way to achieve the same thing outside of the __init__ function, and just have these assignments be done as a class attribute (i.e. so that I can refer to FooA.template_body, etc.) I can of course always just hardcode the template filenames in each derived class, but I am just curious if it can be automated through some form of introspection. -- Leo Breebaart From lacrima.maxim at gmail.com Mon Feb 15 13:33:33 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Mon, 15 Feb 2010 10:33:33 -0800 (PST) Subject: Which mock library do you prefer? References: Message-ID: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> On Feb 15, 6:57 pm, Phlip wrote: > Lacrima wrote: > > I am newbie mastering test driven development. I can't clarify myself > > which mock library to use. > > There are number of them and which one do you prefer? > > > Two libraries that attracted my attention are: > > * minimock > > * dingus > > As for me the latest one, dingus, is the easiest (see this screencast:http://vimeo.com/3949077 ), but it has very few downloads from pypi, > > so it scares me a little. > > Minimock has wider usage and community, but I have some troubles using > > it. Maybe I am wrong, but with minimock you always have to keep track > > the order of imports in your test modules. Well, may be I just don't > > understand fully how minimock works. > > > What are your suggestions? > > I have usedhttp://pypi.python.org/pypi/mock/0.6.0. It mocks, and it > has a mode that works one method at a time, and another mode that > mocks a method before its owning object gets constructed. > > However, TDD is not about mocking, and on greenfield code you should > only mock to recover from some external problem, such as: > > - a random number generator > - the system clock > - anything over "the wire" - over a TCP/IP socket > - hardware, such as your graphics or sound > > Never mock to avoid hitting the database. Some TDD verbiage advises > "never hit the database". That is a mind-game to force you to decouple > your code. Your objects should always have the option (via > "construction encapsulation") to run as stubs, with some of their > behaviors turned off. And if you TDD low-level code that hits a > database, a mock would only tell the test what it wants to hear. And > if you TDD high-level code that manages business rules, database > records make perfectly good behavioral "fixtures" to support those > rules. > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand Hi, Phlip! Thanks for your reply! Isn't what you are talking about integration tests? And unit tests should be fully isolated? So even for method 'some_method()' of class A I should mock instance of class A (i.e. to mock 'self') to test 'some_method()'. Please, could you explain in more detail your thoughts: > Your objects should always have the option (via > "construction encapsulation") to run as stubs, with some of their > behaviors turned off. And if you TDD low-level code that hits a > database, a mock would only tell the test what it wants to hear. And > if you TDD high-level code that manages business rules, database > records make perfectly good behavioral "fixtures" to support those > rules. And could you give an example. For me it's really hard to develop test first. Often I don't know what tests to write to replace hardcoded return values by objects that perform actual work. I have read several books on TDD and explored http://c2.com/cgi/wiki?TestDrivenDevelopment and related wikis, but often it seems I don't have enough understanding to write even simple application. And sorry for my English. with regards, Max. From mrkafk at gmail.com Mon Feb 15 13:43:25 2010 From: mrkafk at gmail.com (mk) Date: Mon, 15 Feb 2010 19:43:25 +0100 Subject: Plugin architecture Message-ID: Hello everyone, I'm thinking about writing plugin-style architecture for (a new) web-based app (with SQLAlchemy as backend). Say, there's core web app and someone decides to write plugin Accounting for this web app that would work with SQA objects of the core app or other plugins. I found this: http://effbot.org/zone/metaclass-plugins.htm (Although I'm not entirely sure this is the best approach for the web app) How would you approach designing such architecture using features available in Python (and some major web framework, like Pylons or Django)? Regards, mk From fetchinson at googlemail.com Mon Feb 15 13:53:23 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 15 Feb 2010 19:53:23 +0100 Subject: Plugin architecture In-Reply-To: References: Message-ID: > I'm thinking about writing plugin-style architecture for (a new) > web-based app (with SQLAlchemy as backend). > > Say, there's core web app and someone decides to write plugin Accounting > for this web app that would work with SQA objects of the core app or > other plugins. > > I found this: > > http://effbot.org/zone/metaclass-plugins.htm > > (Although I'm not entirely sure this is the best approach for the web app) > > How would you approach designing such architecture using features > available in Python (and some major web framework, like Pylons or Django)? Major web frameworks like django, turbogears (thicker ones), pylons, cherrypy (thinner ones) include all the functionality for doing this sort of thing out of the box. If I were you I would go ahead and use one of these frameworks and only start thinking about designing something new if I hit a wall. Chances are you won't. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From bigblueswope at gmail.com Mon Feb 15 13:53:38 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 13:53:38 -0500 Subject: TypeError Exception in email lib Message-ID: File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz if data[9] is None: TypeError: 'NoneType' object is unsubscriptable I'm parsing a bunch of spam and using the date field from the spams for a date-time stamp. I've fixed the lib on my box to place the call inside a try/except clause to catch the exception now, but it seems the module has a bug in it. How would I go about recommending a change the module? Original code: def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone Patched code: def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" try: if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone except TypeError: return time.mktime(data[:8] + (-1,)) ---- Auburn fans are like slinkys... not really good for anything but they still bring a smile to your face when you push them down a flight of stairs. To argue that honorable conduct is only required against an honorable enemy degrades the Americans who must carry out the orders. -- Charles Krulak, Former Commandant of the Marine Corps We are all slave to our own paradigm. -- Joshua Williams If the letters PhD appear after a person's name, that person will remain outdoors even after it's started raining. -- Jeff Kay From python at mrabarnett.plus.com Mon Feb 15 13:56:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Feb 2010 18:56:10 +0000 Subject: get a field In-Reply-To: <4B799249.2020205@tim.thechases.com> References: <4B799249.2020205@tim.thechases.com> Message-ID: <4B7998CA.2090604@mrabarnett.plus.com> Tim Chase wrote: > Holden wrote: >> mierdatutis mi wrote: >>> I have this: >>> >>> pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" >>> >>> >>> I would like to extract this: 691046.shtml >>> >>> But is dynamically. Not always have the same lenght the string. >> >>>>> s = "http://server/path/to/file/file.shtml" >>>>> s.rfind("/") # finds rightmost "/" >> 26 >>>>> s[s.rfind("/")+1:] # substring starting after "/" >> 'file.shtml' > > If I didn't use os.path.basename(s) then I'd write this as > "s.rsplit('/', 1)[-1]" > > >>> "http://server/path/to/file/file.shtml".rsplit('/', 1)[-1] > 'file.shtml' > >>> "".rsplit('/', 1)[-1] > '' > >>> "file.html".rsplit('/', 1)[-1] > 'file.html' > > I don't know how much of a difference it makes, but I always appreciate > seeing how various people solve the same problem. I tend to lean away > from the find()/index() methods on strings because I have to stop and > think which one raises the exception and which one returns -1 (and that > it's -1 instead of 0) usually dropping to a python shell and doing > > >>> help("".find) > >>> help("".index) > > to refresh my memory. > > FWIW, Steve's solution and the os.path.basename() both produce the same > results with all 3 input values, so it's more a matter of personal style > preference. The basename() version has slightly different results if > you have Windows paths with backslashes: > > s = r'c:\path\to\file.txt' > > but since you (OP) know that they should be URLs with forward-slashes, > it should be a non-issue. > The MacOS separator was (is?) ":". Since MacOS X it has been based on Unix, so I'm not sure what Python sees nowadays, "/" or still ":". Another platform, RISC OS, uses ".". For that reason I wouldn't use os.path.basename(). An alternative to .rsplit() is .rpartition(). From python at mrabarnett.plus.com Mon Feb 15 14:21:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Feb 2010 19:21:17 +0000 Subject: TypeError Exception in email lib In-Reply-To: References: Message-ID: <4B799EAD.90805@mrabarnett.plus.com> BJ Swope wrote: > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > I'm parsing a bunch of spam and using the date field from the spams > for a date-time stamp. > > I've fixed the lib on my box to place the call inside a try/except > clause to catch the exception now, but it seems the module has a bug > in it. > > How would I go about recommending a change the module? > > Original code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > > Patched code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > try: > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > except TypeError: > return time.mktime(data[:8] + (-1,)) > The traceback is saying that 'data' is None, not that it's too short (that would raise an IndexError). From jjposner at optimum.net Mon Feb 15 14:24:23 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 15 Feb 2010 14:24:23 -0500 Subject: Modifying Class Object In-Reply-To: References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> Message-ID: <4b799f4a$0$4980$607ed4bc@cv.net> Alf said (2/13/2010 8:34 PM): > Names in Python refer to objects. > > Those references can be copied via assignment. > > That's (almost) all. > > And it provides a very short and neat way to describe pass by sharing. Alf also said (2/13/2010 8:43 PM): > * Steve Howell: > > This thread is interesting on many levels. What is the core > > question that is being examined here? > > I think that regarding the technical it is whether a Python name > refers to an object or not. I maintain that it does, and that the > reference can be copied, and that the semantics of the language > requires this and is defined in terms of this. Steve Holden, > D'Aprano and many others maintain that there are no references, or > that if there are then they're only an implementation aspect, i.e. > that conceiveable one could have an implementation without them. Steve D'Aprano said (2/14/2010 12:13 AM): > That's not to say that the general concept of references (as in "to > refer to") isn't valuable when discussing Python. If you want to say > that (e.g.) following > > x = 1 > > the name "x" refers to (or even points to!) the object 1, my > objections will be mild or non-existent. In that sense, it's probably > impossible to program without some sort of "references": the computer > manipulates variables or objects directly, while we manipulate > characters in source code. The only way to write a program is to use > some abstract thing (a name, an offset, whatever) that refers, in > some fashion, to a collection of bits in the computer's memory. But > to go from that to the idea that (say) x is a pointer does so much > violence to the concept of pointer and has so much room for confusion > that it is actively harmful. I think most of the technical argument in this thread comes down to the various forms of the word *refer*. After execution of this Python statement: x = 5 ... we can use this English-language statement: the name *x* refers to the value *5* (If anyone has more than Steve's "mild" objection, please speak up!) The English-language statement uses the VERB "refers". It is not the same as using the NOUN "reference": *x* is a reference to the value *5* Why not? Because using the NOUN form suggests that you're talking about a particular kind of object in the world Python, as in these statements: *x* is a string *x* is a function *x* is a class But Python does not define *reference* objects -- by which I mean that executing *import types; dir(types)* produces a long list of object-type names, and there's nothing like a "reference" on that list. (I suspect there's a better way to make this "there are no reference objects" argument. Can anyone help?) Amending the statement to: the name *x* is a reference to the value *5* ... doesn't really help matters. Is *x* a NAME or is it a REFERENCE? Looking again at Alf's assertion: > [the core technical question is] whether a Python name > refers to an object or not. I maintain that it does, and that the > reference can be copied, ... and Alf's example (message dated 2/10/2010 5:02 PM): > For example, > > x = s[0] > > accesses the object that s points (refers) to. I believe Alf would characterize this assignment statement as a situation in which "a reference is copied" [using the NOUN form of "refer"]. But no object is copied during execution of this statement. Moreover, saying "a reference is copied" might mislead a Python newbie into thinking that some kind of "reference object" exists that can be copied by Python statements. So it's better to describe the situation using the VERB form of "refer": assigns the name *x* to the object that *s[0]* refers to -John From apt.shansen at gmail.com Mon Feb 15 14:31:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 15 Feb 2010 11:31:11 -0800 Subject: TypeError Exception in email lib In-Reply-To: References: Message-ID: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> On Mon, Feb 15, 2010 at 10:53 AM, BJ Swope wrote: > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > I'm parsing a bunch of spam and using the date field from the spams > for a date-time stamp. > > I've fixed the lib on my box to place the call inside a try/except > clause to catch the exception now, but it seems the module has a bug > in it. > While there may or may not be a bug in the library, I don't think its where you're fixing. Just because an exception occurs in a function doesn't mean that function is broken: its documented as accepting a 10 item tuple, only. Functions in the stdlib generally -should- throw exceptions on invalid input. Someone's passing None into it, which its not allowed to do. So -that's- where the bug probably is, I think. (Although it may not be the immediate of mktime_tz; it could be happening higher up on the stack) Advice: Always post complete tracebacks to c.p.l/python-list :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From bigblueswope at gmail.com Mon Feb 15 14:47:32 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 14:47:32 -0500 Subject: TypeError Exception in email lib In-Reply-To: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: On Mon, Feb 15, 2010 at 2:31 PM, Stephen Hansen wrote: > On Mon, Feb 15, 2010 at 10:53 AM, BJ Swope wrote: >> >> ?File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz >> ? ?if data[9] is None: >> TypeError: 'NoneType' object is unsubscriptable >> >> I'm parsing a bunch of spam and using the date field from the spams >> for a date-time stamp. >> >> I've fixed the lib on my box to place the call inside a try/except >> clause to catch the exception now, but it seems the module has a bug >> in it. > > While there may or may not be a bug in the library, I don't think its where > you're fixing. Just because an exception occurs in a function doesn't mean > that function is broken: its documented as accepting a 10 item tuple, only. > Functions in the stdlib generally -should- throw exceptions on invalid > input. > Someone's passing None into it, which its not allowed to do. So -that's- > where the bug probably is, I think. (Although it may not be the immediate of > mktime_tz; it could be happening higher up on the stack) > Advice: Always post complete tracebacks to c.p.l/python-list :) > --S >From the module: def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone It appears that the module is trying to accommodate the potential missing TZ data because poorly written emails are missing the TZ data. I discarded all the crontab emails that had the full traceback in them. I took out the try/except clause in the hopes that I'll get another exception soon. If I do I'll post the entire exception traceback. From davea at ieee.org Mon Feb 15 14:51:04 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 15 Feb 2010 14:51:04 -0500 Subject: TypeError Exception in email lib In-Reply-To: References: Message-ID: <4B79A5A8.8020008@ieee.org> BJ Swope wrote: > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > I'm parsing a bunch of spam and using the date field from the spams > for a date-time stamp. > > I've fixed the lib on my box to place the call inside a try/except > clause to catch the exception now, but it seems the module has a bug > in it. > > How would I go about recommending a change the module? > > Original code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > > Patched code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > try: > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > except TypeError: > return time.mktime(data[:8] + (-1,)) > > > ---- > Auburn fans are like slinkys... not really good for anything but they > still bring a smile to your face when you push them down a flight of > stairs. > > To argue that honorable conduct is only required against an honorable > enemy degrades the Americans who must carry out the orders. -- Charles > Krulak, Former Commandant of the Marine Corps > > We are all slave to our own paradigm. -- Joshua Williams > > If the letters PhD appear after a person's name, that person will > remain outdoors even after it's started raining. -- Jeff Kay > > Is the code that calls mktime_tz() your own? If so, maybe you'd be better off fixing that. The error message indicates that the 'data' parameter is None, which is invalid, according to the 2.6 documentation anyway (the parameter to the function is supposed to be a 10-tuple). So it's a bug in the caller, not in that function. Besides, your fix will still raise another exception inside the except class, since if data[9] gives that error, so will data[:8} DaveA From clp2 at rebertia.com Mon Feb 15 14:53:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Feb 2010 11:53:46 -0800 Subject: Using class attributes In-Reply-To: <7tti4iFehdU1@mid.individual.net> References: <7tti4iFehdU1@mid.individual.net> Message-ID: <50697b2c1002151153l2ce0050bt9297ae9acfa34c6b@mail.gmail.com> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: > I have a base class Foo with a number of derived classes FooA, > FooB, FooC, etc. Each of these derived classes needs to read > (upon initialisation) text from an associated template file > FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. > > I can derive the template filename string for each instance by > doing something like this in the base class (and then not > forgetting to call super() in the __init__() of each derived > class): > > ?class Foo(object): > > ? ? ?def __init__(self): > ? ? ? ? ?self.template_filename = "%s.tmpl" % self.__class__.__name__ > ? ? ? ? ?self.template_body = read_body_from(self.template_filename) > > But, since this information is the same for every instance of > each derived class, I was wondering if there was a way to achieve > the same thing outside of the __init__ function, and just have > these assignments be done as a class attribute (i.e. so that I > can refer to FooA.template_body, etc.) > > I can of course always just hardcode the template filenames in > each derived class, but I am just curious if it can be automated > through some form of introspection. Metaclasses to the rescue!: class WithTemplateAttrs(type): def __new__(cls, name, bases, dct): klass = type.__new__(cls, name, bases, dct) klass.template_filename = "%s.tmpl" % name klass.template_body = read_body_from(klass.template_filename) return klass class Foo(object): __metaclass__ = WithTemplateAttrs #rest of class body here Now just have FooA, FooB, etc. subclass Foo as before. They'll automatically get the attributes generated. Cheers, Chris -- http://blog.rebertia.com From bigblueswope at gmail.com Mon Feb 15 14:54:16 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 14:54:16 -0500 Subject: TypeError Exception in email lib In-Reply-To: References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: On Mon, Feb 15, 2010 at 2:47 PM, BJ Swope wrote: > On Mon, Feb 15, 2010 at 2:31 PM, Stephen Hansen wrote: >> On Mon, Feb 15, 2010 at 10:53 AM, BJ Swope wrote: >>> >>> ?File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz >>> ? ?if data[9] is None: >>> TypeError: 'NoneType' object is unsubscriptable >>> >>> I'm parsing a bunch of spam and using the date field from the spams >>> for a date-time stamp. >>> >>> I've fixed the lib on my box to place the call inside a try/except >>> clause to catch the exception now, but it seems the module has a bug >>> in it. >> >> While there may or may not be a bug in the library, I don't think its where >> you're fixing. Just because an exception occurs in a function doesn't mean >> that function is broken: its documented as accepting a 10 item tuple, only. >> Functions in the stdlib generally -should- throw exceptions on invalid >> input. >> Someone's passing None into it, which its not allowed to do. So -that's- >> where the bug probably is, I think. (Although it may not be the immediate of >> mktime_tz; it could be happening higher up on the stack) >> Advice: Always post complete tracebacks to c.p.l/python-list :) >> --S > > > From the module: > > def mktime_tz(data): > ? ?"""Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > ? ?if data[9] is None: > ? ? ? # No zone info, so localtime is better assumption than GMT > ? ? ? return time.mktime(data[:8] + (-1,)) > ? ?else: > ? ? ? ?t = time.mktime(data[:8] + (0,)) > ? ? ? ?return t - data[9] - time.timezone > > > It appears that the module is trying to accommodate the potential > missing TZ data because poorly written emails are missing the TZ data. > > I discarded all the crontab emails that had the full traceback in > them. ?I took out the try/except clause in the hopes that I'll get > another exception soon. > > If I do I'll post the entire exception traceback. > Speak of the devil and demons appear... /logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py Parsing of emails for spam at serv1.bigbluenetworks.com failed. Traceback (most recent call last): File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", line 81, in clean_stale_mail() File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", line 24, in clean_stale_mail utc_msg_date = email.utils.mktime_tz(msg_date2) File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz if data[9] is None: TypeError: 'NoneType' object is unsubscriptable def clean_stale_mail(): msg_date1= the_email.get('Date') msg_date2 = email.utils.parsedate_tz(msg_date1) try: utc_msg_date = email.utils.mktime_tz(msg_date2) except OverflowError: M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') return utc_stale_date = time.time() - (86000*stale_days) if utc_msg_date <= utc_stale_date: M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') try: #M = imaplib.IMAP4(HOST) M = imaplib.IMAP4_SSL(HOST) M.login(USER, PASSWD) M.select(MAILBOX) response, msg_list = M.search(None, 'ALL') # response is IMAP response, msg_list is list of Message IDs for msg_id in msg_list[0].split(): #msg_list[0] is a space separated string of message ids response, message = M.fetch(msg_id, '(RFC822)') # response is the IMAP response, message is an RFC222 message msg = email.FeedParser.FeedParser( ) msg.feed(message[0][1]) the_email = msg.close() clean_stale_mail() if the_email.is_multipart(): for part in the_email.walk(): if part.get_content_type() == 'text/html': decoded_part = part.get_payload(decode=1) soup_parse(decoded_part) elif the_email.get_content_type() == 'text/html': decoded_part = the_email.get_payload(decode=1) soup_parse(decoded_part) elif the_email.get_content_type() == 'text/plain': msg_payload = the_email.get_payload() manual_parse(msg_payload) else: continue #print msg_id, "Did't match any defined content types..." #print the_email M.expunge() M.close() M.logout() From phlip2005 at gmail.com Mon Feb 15 14:56:53 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 15 Feb 2010 11:56:53 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> Message-ID: Lacrima wrote: > Thanks for your reply! Isn't what you are talking about integration > tests? And unit tests should be fully isolated? So even for method > 'some_method()' of class A I should mock instance of class A (i.e. to > mock 'self') to test 'some_method()'. "Unit test" is a high-end QA concept. Developers can get the best return on "developer tests". They don't bother with aerospace-quality isolation between units. If a TDD test needs to pull in a bunch of modules to pass, that's generally a good thing, because they all get indirect testing. If they catch a bug, their local tests might not catch it, but the higher level tests still have a chance. (And if your product still needs unit tests, TDD will make them very easy for a formal QA team to add.) However, expensive setup is a design smell. That means if a test case requires too many lines of code for its Assemble phase (before its Activate and Assert phases), then maybe those lines of code support objects that are too coupled, and they need a better design. Throwing mocks at these objects, instead of decoupling them, will "perfume" the design smell, instead of curing it. > > "construction encapsulation") > And could you give an example. def test_frob(self): frob = Frob() frob.knob = Mock() frob.knob.value = Mock(return_value = 42) assert 42 == frob.method_using_knob() We need the mock because we can't control how Frob's constructor built its knob. So instead, give Frob the option to construct with a Knob: def test_frob(self): knob = Knob(42) frob = Frob(knob) assert frob.method_using_knob() Note that in production the Knob constructor never takes a Knob. Maybe we should upgrade the production code too (!), or maybe Knob's constructor should only create a knob if it didn't get passed one. Either technique is acceptable, because the resulting code decouples Frobs and Knobs just a little bit more. > For me it's really hard to develop test first. Often I don't know what > tests to write to replace hardcoded return values by objects that > perform actual work. You have read too many books on TDD. C-: Alternate between writing lines of test and lines of code. Run the tests after the fewest possible edits, and always correctly predict if the tests will pass, or will fail, and with what diagnostic. (And configure your editor to run the stankin tests, no matter how hard it fights you!) The high-end tricks will get easier after you get the basic cycle down. -- Phlip http://c2.com/cgi/wiki?ZeekLand From clp2 at rebertia.com Mon Feb 15 15:04:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Feb 2010 12:04:12 -0800 Subject: Talking with ebay using Python In-Reply-To: References: Message-ID: <50697b2c1002151204i487fea42mcba4f7142288a407@mail.gmail.com> On Mon, Feb 15, 2010 at 6:10 AM, starglider develop wrote: > Hi, > I need a way of talking with the eBay API: > Made search, > Ask for item status. > > What can it be done, and where can I get the info. In the future, search Google and PyPI (http://pypi.python.org/pypi). (PyPI is like CPAN for Python.) Here's what I came up with: pyeBay: http://ebaydeveloper.typepad.com/pyebay.html easyBay: http://pypi.python.org/pypi/easyBay/0.1dev They both haven't been updated in a while are are probably unmaintained. I have never used either of these; I have no idea whether they still work. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Mon Feb 15 15:17:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Feb 2010 12:17:35 -0800 Subject: Talking with ebay using Python In-Reply-To: References: <50697b2c1002151204i487fea42mcba4f7142288a407@mail.gmail.com> Message-ID: <50697b2c1002151217p5a01dfa4x4b3df752d5c412e6@mail.gmail.com> > On 15 February 2010 20:04, Chris Rebert wrote: >> On Mon, Feb 15, 2010 at 6:10 AM, starglider develop >> wrote: >> > Hi, >> > I need a way of talking with the eBay API: >> > Made search, >> > Ask for item status. >> > >> > What can it be done, and where can I get the info. >> >> In the future, search Google and PyPI (http://pypi.python.org/pypi). >> (PyPI is like CPAN for Python.) >> >> Here's what I came up with: >> >> pyeBay: >> http://ebaydeveloper.typepad.com/pyebay.html >> >> easyBay: >> http://pypi.python.org/pypi/easyBay/0.1dev >> >> They both haven't been updated in a while are are probably >> unmaintained. I have never used either of these; I have no idea >> whether they still work. On Mon, Feb 15, 2010 at 12:12 PM, starglider develop wrote: > Thanks for your replay Chris, > but easyBay is no longer available, I had contact the mantainer without > result. > pyebay is new to me but lacks documentations and the output is in XML unlike > easybay the creats a class. Er, easyBay is available. Click one of the file links on its PyPI entry, they work just fine. And in the future, mention the results of any search (i.e. the fact you tried contacting the easyBay dev) in your first message. Cheers, Chris -- http://blog.rebertia.com From chiranjeevi.muttoju at gmail.com Mon Feb 15 15:33:18 2010 From: chiranjeevi.muttoju at gmail.com (chiranjeevi muttoju) Date: Mon, 15 Feb 2010 12:33:18 -0800 (PST) Subject: error: Setup script exited with error: command 'gcc' failed with exit status 1 Message-ID: <0276dd58-9d1a-456d-ab81-33bd241e7d85@t17g2000prg.googlegroups.com> Hi, When i'm trying to install some modules for python i'm getting the fallowing error.. error: Setup script exited with error: command 'gcc' failed with exit status 1 can any one know what it exactly means.. if any body know please reply. i have gcc version 4.1.2 20080704 (Red Hat 4.1.2-46). i'm using python python2.6, some of the modules getting this type of errors are.. mysqldb, and pytc., etc.. if any one know please help me.. Thanks and Regards.. chiranjeevi.muttoju From python at mrabarnett.plus.com Mon Feb 15 15:42:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Feb 2010 20:42:42 +0000 Subject: TypeError Exception in email lib In-Reply-To: References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: <4B79B1C2.5040702@mrabarnett.plus.com> BJ Swope wrote: [snip] > > Speak of the devil and demons appear... > > /logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py > > Parsing of emails for spam at serv1.bigbluenetworks.com failed. > > Traceback (most recent call last): > File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", > line 81, in > clean_stale_mail() > File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", > line 24, in clean_stale_mail > utc_msg_date = email.utils.mktime_tz(msg_date2) > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > > > def clean_stale_mail(): > msg_date1= the_email.get('Date') What is the value of 'msg_date1' at this point? > msg_date2 = email.utils.parsedate_tz(msg_date1) What is the value of 'msg_date2' at this point? The docs say that parsedate_tz() can return a 10-tuple or None. Presumably, if it can't parse the date then it returns None. > try: > utc_msg_date = email.utils.mktime_tz(msg_date2) > except OverflowError: > M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') > return > utc_stale_date = time.time() - (86000*stale_days) > if utc_msg_date <= utc_stale_date: > M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') > [snip] From philip at semanchuk.com Mon Feb 15 15:48:38 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Feb 2010 15:48:38 -0500 Subject: error: Setup script exited with error: command 'gcc' failed with exit status 1 In-Reply-To: <0276dd58-9d1a-456d-ab81-33bd241e7d85@t17g2000prg.googlegroups.com> References: <0276dd58-9d1a-456d-ab81-33bd241e7d85@t17g2000prg.googlegroups.com> Message-ID: On Feb 15, 2010, at 3:33 PM, chiranjeevi muttoju wrote: > Hi, > When i'm trying to install some modules for python i'm getting the > fallowing error.. > > error: Setup script exited with error: command 'gcc' failed with exit > status 1 > > can any one know what it exactly means.. if any body know please > reply. > i have gcc version 4.1.2 20080704 (Red Hat 4.1.2-46). > i'm using python python2.6, > > some of the modules getting this type of errors are.. mysqldb, and > pytc., etc.. Hi Chiranjeevi, Show us all of the output, please -- everything from where you typed 'setup.py' until the script died. From gallium.arsenide at gmail.com Mon Feb 15 15:59:01 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Mon, 15 Feb 2010 12:59:01 -0800 (PST) Subject: TypeError Exception in email lib References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: <7b6e35aa-2e3c-4983-bc01-8330c3513ee6@j1g2000vbl.googlegroups.com> On Feb 15, 2:54?pm, BJ Swope wrote: > def clean_stale_mail(): > ? ? msg_date1= the_email.get('Date') > ? ? msg_date2 = email.utils.parsedate_tz(msg_date1) > ? ? try: > ? ? ? ? utc_msg_date = email.utils.mktime_tz(msg_date2) > ? ? except OverflowError: > ? ? ? ? M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') > ? ? ? ? return > ? ? utc_stale_date = time.time() - (86000*stale_days) > ? ? if utc_msg_date <= utc_stale_date: > ? ? ? ? M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') It looks like msg_date1 is None. That is, 'Date' is not found in the_email. As Dave Angel said, your "patch" shouldn't fix this problem anyway. Use your patch and put the same problematic input in it to see if it really does fix the problem. (Just to satisfy our morbid curiosity, not really to help you get a true solution.) It looks to me like you have to do something to make clean_stale_mail more robust, rather than focusing on anything in the standard library. John From gallium.arsenide at gmail.com Mon Feb 15 16:03:10 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Mon, 15 Feb 2010 13:03:10 -0800 (PST) Subject: TypeError Exception in email lib References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> <7b6e35aa-2e3c-4983-bc01-8330c3513ee6@j1g2000vbl.googlegroups.com> Message-ID: On Feb 15, 3:59?pm, John Yeung wrote: > It looks to me like you have to do something to make clean_stale_mail > more robust, rather than focusing on anything in the standard library. Let me quickly add: ...or fix whatever calls clean_stale_mail, etc. John From arnodel at googlemail.com Mon Feb 15 16:25:23 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Feb 2010 21:25:23 +0000 Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> Message-ID: John Posner writes: [...] >> x = s[0] [...] > assigns the name *x* to the object that *s[0]* refers to s[0] does not refer to an object, it *is* an object (once evaluated of course, otherwise it's just a Python expression). -- Arnaud From subhakolkata1234 at gmail.com Mon Feb 15 17:04:43 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Mon, 15 Feb 2010 14:04:43 -0800 (PST) Subject: Few Small Questions Regarding CGI Message-ID: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Dear Group, I am trying to learn CGI. I was checking Python Docs. There are multiple modules. Which one to start with? Is there any other material or URL for step by step learning of CGI. My next question is: I want to test it. I have a small personal computer. I have internet but is connected by a service provider. I do not have personal web page. Can I use my personal computer as a client as well as a server? If your kind time permits to answer me these questions, I would be hugely benefited. Wishing you a happy day ahead, Best Regards, Subhabrata. From dino at phidev.org Mon Feb 15 17:12:23 2010 From: dino at phidev.org (Florian Ludwig) Date: Mon, 15 Feb 2010 23:12:23 +0100 Subject: plugin / intra process communication system In-Reply-To: <7tqr9iFbi7U1@mid.uni-berlin.de> References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> Message-ID: <1266271943.4299.2887.camel@brain> On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: > > Here there problem with the trac (and other plugin systems I've > seen) > > approach: > > > > You need to define something like: > > | > > | class IAuthPlugin(Interface): [...] > > | > > in your blog software. > > Why? Any reason you can't define it in a separate package the > blog-software depends on, as well as your wiki? That's actually my point - most plugin systems I've seen, like the one trac uses, are not encouraging you to do so. Having a module that just defines an Interface is kind of weird - and in the real world no one is doing it. > And then of course, this is not really needed. In Python, behavior > counts, not type-information. So you can get away without any explicit > declared interface. You might chose to not do that, for aestetic > reasons, or better documentation. But you aren't forced. Actually some plugin-systems in python do force you and they check if your "implementation" comply with the "interface". Here is one solution I came up with. Based on the earlier example: > > Lets say you program a wiki and like to allow different kind of > > authentications. So you create two plugins (for example one for > > OpenID and one for Shibboleth). > > > > Some time later you feel like reinventing the wheel again and > > you program a blog. Again you like to allow different ways of > > authentication and you already wrote plugins for exactly the > > same for your wiki, right? auth_openid.py - providing the authentication service http://dpaste.com/hold/159619/ wiki.py - providing the wiki http://dpaste.com/hold/159634/ Now putting both together: > import pbus > > import wiki > import auth_openid > # or: import auth_shibboleth > > pbus.get("wiki").run() No interface definitions. What do you think? Any obvious pitfalls (besides reinventing something)? Please keep in mind that syntax/api is not "done" or anything its just an concept presentation. Thanks, Florian -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From bigblueswope at gmail.com Mon Feb 15 17:20:01 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 17:20:01 -0500 Subject: TypeError Exception in email lib In-Reply-To: <4B79B1C2.5040702@mrabarnett.plus.com> References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> <4B79B1C2.5040702@mrabarnett.plus.com> Message-ID: On Mon, Feb 15, 2010 at 3:42 PM, MRAB wrote: > BJ Swope wrote: > [snip] >> >> def clean_stale_mail(): >> ? ?msg_date1= the_email.get('Date') > > What is the value of 'msg_date1' at this point? > >> ? ?msg_date2 = email.utils.parsedate_tz(msg_date1) > > What is the value of 'msg_date2' at this point? > > The docs say that parsedate_tz() can return a 10-tuple or None. > > Presumably, if it can't parse the date then it returns None. > > [snip] > msg_date1: @@DATE msg_date2: None Thanks MRAB, Dave and Stephen! The spam bot didn't populate the date field with anything remotely resembling the date. The @@DATE var was left in the Date header. In reading the module I misunderstood what the "if date[9] is None:" was doing. I'll wrap my calls in a try/except. From dino at phidev.org Mon Feb 15 17:25:31 2010 From: dino at phidev.org (Florian Ludwig) Date: Mon, 15 Feb 2010 23:25:31 +0100 Subject: Plugin architecture In-Reply-To: References: Message-ID: <1266272731.4299.2902.camel@brain> Hi mk, On Mon, 2010-02-15 at 19:43 +0100, mk wrote: > Hello everyone, > > I'm thinking about writing plugin-style architecture for (a new) > web-based app (with SQLAlchemy as backend). > > [...] > > How would you approach designing such architecture using features > available in Python (and some major web framework, like Pylons or Django)? You should really look into the web framework you're using, there probably already is some plugin architecture. But being not content myself with the architectures I've seen or worked with I was looking for some input as well and posted some days back about a similar topic. Maybe some of the thoughts expressed there might help you as well: http://groups.google.com/group/comp.lang.python/browse_thread/thread/0a210267753919b0/5add7bc93789b418 Florian -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From mdekauwe at gmail.com Mon Feb 15 17:26:16 2010 From: mdekauwe at gmail.com (Martin) Date: Mon, 15 Feb 2010 14:26:16 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> Message-ID: <1f520615-63df-4923-ba2e-c677e460ac9f@u9g2000yqb.googlegroups.com> On Feb 15, 2:27?pm, Jean-Michel Pichavant wrote: > Martin wrote: > > On Feb 15, 2:03 pm, Jean-Michel Pichavant > > wrote: > > >> Martin wrote: > > >>> Hi, > > >>> I am trying to come up with a more generic scheme to match and replace > >>> a series ofregex, which look something like this... > > >>> 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > >>> 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > >>> Ideally match the pattern to the right of the "!" sign (e.g. lai), I > >>> would then like to be able to replace one or all of the corresponding > >>> numbers on the line. So far I have a rather unsatisfactory solution, > >>> any suggestions would be appreciated... > > >>> The file read in is an ascii file. > > >>> f = open(fname, 'r') > >>> s = f.read() > > >>> if CANHT: > >>> ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > >>> canht_ft", CANHT, s) > > >>> where CANHT might be > > >>> CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > >>> But this involves me passing the entire string. > > >>> Thanks. > > >>> Martin > > >> I remove all lines containing things like 9*0.0 in your file, cause I > >> don't know what they mean and how to handle them. These are not numbers. > > >> import re > > >> replace = { > >> ? ? 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 > >> ? ? 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 > >> ? ? } > > >> testBuffer = """ > >> ?0.749, 0.743, 0.754, 0.759 ?! ?stheta(1:sm_levels)(top to bottom) > >> 0.46 ? ? ? ? ? ? ? ? ? ? ? ? ! ?snow_grnd > >> 276.78,277.46,278.99,282.48 ?! ?t_soil(1:sm_levels)(top to bottom) > >> 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > >> 200.0, 4.0, 2.0, 4.0, 1.0 ! ?lai(1:npft) > >> """ > > >> outputBuffer = '' > >> for line in testBuffer.split('\n'): > >> ? ? for key, (index, repl) in replace.items(): > >> ? ? ? ? if key in line: > >> ? ? ? ? ? ? parameters = { > >> ? ? ? ? ? ? ? ? 'n' : '[\d\.]+', # given you example you have to change > >> this one, I don't know what means 9*0.0 in your file > >> ? ? ? ? ? ? ? ? 'index' : index - 1, > >> ? ? ? ? ? ? } > >> ? ? ? ? ? ? # the following pattern will silently match any digit before > >> the th digit is found, and use a capturing parenthesis for the last > >> ? ? ? ? ? ? pattern = > >> '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % > >> parameters # regexp are sometimes a nightmare to read > >> ? ? ? ? ? ? line = re.sub(pattern, r'\1 '+repl+r'\3' , line) > >> ? ? ? ? ? ? break > >> ? ? outputBuffer += line +'\n' > > >> print outputBuffer > > > Thanks I will take a look. I think perhaps I was having a very slow > > day when I posted and realised I could solve the original problem more > > efficiently and the problem wasn't perhaps as I first perceived. It is > > enough to match the tag to the right of the "!" sign and use this to > > adjust what lies on the left of the "!" sign. Currently I have > > this...if anyone thinks there is a neater solution I am happy to hear > > it. Many thanks. > > > variable_tag = 'lai' > > variable = [200.0, 60.030, 0.060, 0.030, 0.030] > > > # generate adjustment string > > variable = ",".join(["%s" % i for i in variable]) + ' ! ?' + > > variable_tag > > > # call func to adjust input file > > adjustStandardPftParams(variable, variable_tag, in_param_fname, > > out_param_fname) > > > and the inside of this func looks like this > > > def adjustStandardPftParams(self, variable, variable_tag, in_fname, > > out_fname): > > > ? ? f = open(in_fname, 'r') > > ? ? of = open(out_fname, 'w') > > ? ? pattern_found = False > > > ? ? while True: > > ? ? ? ? line = f.readline() > > ? ? ? ? if not line: > > ? ? ? ? ? ? break > > ? ? ? ? pattern = re.findall(r"!\s+"+variable_tag, line) > > ? ? ? ? if pattern: > > ? ? ? ? ? ? print 'yes' > > ? ? ? ? ? ? print >> of, "%s" % variable > > ? ? ? ?pattern_found = True > > > ? ? ? ? if pattern_found: > > ? ? ? ? ? ? pattern_found = False > > ? ? ? ? else: > > ? ? ? ? ? ? of.write(line) > > > ? ? f.close() > > ? ? of.close() > > > ? ? return > > Are you sure a simple > if variable_tag in line: > ? ? # do some stuff > > is not enough ? > > People will usually prefer to write > > for line in open(in_fname, 'r') : > > instead of your ugly while loop ;-) > > JM My while loop is suitably offended. I have changed it as you suggested...though if I do: if pattern (variable_tag) in line as you suggested i would in my example correctly pick the tag lai, but also one called dcatch_lai, which I wouldn't want. No doubt there is an obvious solution I am again missing! of = open(out_fname, 'w') pattern_found = False for line in open(in_fname, 'r'): pattern = re.findall(r"!\s+"+variable_tag, line) if pattern: print >> of, "%s" % variable pattern_found = True if pattern_found: pattern_found = False else: of.write(line) of.close() Many Thanks. From rhodri at wildebst.demon.co.uk Mon Feb 15 17:53:37 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 15 Feb 2010 22:53:37 -0000 Subject: MODULE FOR I, P FRAME References: Message-ID: On Sun, 14 Feb 2010 10:07:35 -0000, DANNY wrote: > Hy, first thanks for your response! > Well I am thinkin on coding in MPEG4/10, but I would just encode the > video in that encoding, > then stream it with VLC and save the video file on my disc. Then I > would play it with my player.... I think you're misunderstanding what VLC does here. Saving the video file should preserve format by default; you may be able save it out in YUV format (I don't have a copy on this machine to check), but that will take up ludicrous amounts of disc space and you'd still have to write a byte reader for it. If you do do that, you have lost any chance of knowing whether a frame was an I or P frame in the original format, not that it matters anyway by that point. MPEG-4/10 is hard to write efficient decoders for, and I have to admit I wouldn't do it in Python. You'd be better off writing a wrapper for one of the existing MP4 libraries. -- Rhodri James *-* Wildebeeste Herder to the Masses From gordon at panix.com Mon Feb 15 17:58:03 2010 From: gordon at panix.com (John Gordon) Date: Mon, 15 Feb 2010 22:58:03 +0000 (UTC) Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: In <631b0785-38db-4c12-a82a-7b11e2235e23 at o16g2000prh.googlegroups.com> joy99 writes: > Can I use my personal computer as a client as well as a server? Yes, if you install a web server on your PC. You would then use "localhost" in your browser instead of a standard web address. Assuming you're running Windows, have a look at this page to download the Apache web server: http://mirror.candidhosting.com/pub/apache/httpd/binaries/win32/README.html -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve at REMOVE-THIS-cybersource.com.au Mon Feb 15 18:05:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Feb 2010 23:05:39 GMT Subject: how to structure a directory with many scripts and shared code References: Message-ID: <4b79d343$0$8760$c3e8da3@news.astraweb.com> On Mon, 15 Feb 2010 16:29:05 +0100, Benedict Verheyen wrote: > However, when i make a subdirectory, for example database and put a > script in there, how would i import logutils or mailtutils from within > the database subdirectory? This fails: > from tools.logutils import logger Sounds like you need to ensure that the top level directory needs to be added to your PYTHONPATH. Do you need instructions to do this? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Feb 15 18:09:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Feb 2010 23:09:59 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> Message-ID: <4b79d447$0$8760$c3e8da3@news.astraweb.com> On Mon, 15 Feb 2010 21:25:23 +0000, Arnaud Delobelle wrote: > John Posner writes: [...] >>> x = s[0] > [...] >> assigns the name *x* to the object that *s[0]* refers to > > s[0] does not refer to an object, it *is* an object (once evaluated of > course, otherwise it's just a Python expression). Precisely. Treated as an expression, that is, as a string being evaluated by the compiler, we would say that it *refers to* an object (unless evaluation fails, in which case it refers to nothing at all). But treated as whatever you get after the compiler is done with it, that is, post- evaluation, we would say that it *is* an object. This subtle distinction is essentially the difference between a label and the thing that is labeled. -- Steven From mattbarkan at gmail.com Mon Feb 15 18:34:35 2010 From: mattbarkan at gmail.com (galileo228) Date: Mon, 15 Feb 2010 15:34:35 -0800 (PST) Subject: Parsing for email addresses Message-ID: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> Hey all, I'm trying to write python code that will open a textfile and find the email addresses inside it. I then want the code to take just the characters to the left of the "@" symbol, and place them in a list. (So if galileo228 at gmail.com was in the file, 'galileo228' would be added to the list.) Any suggestions would be much appeciated! Matt From alfps at start.no Mon Feb 15 18:45:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 00:45:34 +0100 Subject: Modifying Class Object In-Reply-To: <4b79d447$0$8760$c3e8da3@news.astraweb.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> <4b79d447$0$8760$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Mon, 15 Feb 2010 21:25:23 +0000, Arnaud Delobelle wrote: > >> John Posner writes: [...] >>>> x = s[0] >> [...] >>> assigns the name *x* to the object that *s[0]* refers to >> s[0] does not refer to an object, it *is* an object (once evaluated of >> course, otherwise it's just a Python expression). > > Precisely. Treated as an expression, that is, as a string being evaluated > by the compiler, we would say that it *refers to* an object (unless > evaluation fails, in which case it refers to nothing at all). But treated > as whatever you get after the compiler is done with it, that is, post- > evaluation, we would say that it *is* an object. > > This subtle distinction is essentially the difference between a label and > the thing that is labeled. The main differences between a pure functional language where that view can hold and be reasonable, and a language like Python, are that * Python assignments change which object a name refers to, /at runtime/. - Name binding is run time action, not a compile time action. Without run time binding names couldn't be reassigned. s = 1; s = 2 * Some Python objects are modifiable (a.k.a. mutable). - This is particularly important when two or more names refer to the same object and that object is modified. That is, a simple-minded transfer of concepts from pure functional programming to Python breaks down in these cases[1]. I hope this explanation of exactly where the functional programming enthusiasts here go wrong can be of help to readers of the thread, although I've given up hope on those holding the functional programming view (since I'm only human, and even the Gods contend in vain against that sort of thing). Cheers & hth., - Alf Notes: [1] Steven D'Aprano's focus on compilation rather than execution mainly ignores the first point, that a name in given a statement in a loop, say, can refer to different objects in different loop iterations. Happily the Python language specification explains binding as a run-time action. Binding is not a compile time action in Python, it is a run-time action, and can bind a given name in a given statement within the same routine execution, to different objects, and the language specification of course uses the phrase "refers to" to explain the situation after a run time binding. From jgardner at jonathangardner.net Mon Feb 15 18:49:31 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 15 Feb 2010 15:49:31 -0800 (PST) Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> Message-ID: <4fc54d57-cab5-41ee-8546-19e2645b329e@f17g2000prh.googlegroups.com> On Feb 15, 3:34?pm, galileo228 wrote: > > I'm trying to write python code that will open a textfile and find the > email addresses inside it. I then want the code to take just the > characters to the left of the "@" symbol, and place them in a list. > (So if galileo... at gmail.com was in the file, 'galileo228' would be > added to the list.) > > Any suggestions would be much appeciated! > You may want to use regexes for this. For every match, split on '@' and take the first bit. Note that the actual specification for email addresses is far more than a single regex can handle. However, for almost every single case out there nowadays, a regex will get what you need. From jgardner at jonathangardner.net Mon Feb 15 18:52:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 15 Feb 2010 15:52:19 -0800 (PST) Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: <6f343cb9-fc6c-40d8-ad70-7e02851857ad@k2g2000pro.googlegroups.com> On Feb 15, 2:04?pm, joy99 wrote: > > I am trying to learn CGI. I was checking Python Docs. There are > multiple modules. Which one to start with? > Is there any other material or URL for step by step learning of CGI. > I would suggest skipping 15 years of internet progress and going with a more modern framework. I recommend Pylons, although Django and web.py are not bad. > My next question is: > I want to test it. I have a small personal computer. I have internet > but is connected by a service provider. I do not have personal web > page. Can I use my personal computer as a client as well as a server? > Yes. The nature of the internet means anyone that connects can be a client or a server or both at the same time. Heck, you don't even need to have a connection to the internet. Just play with 127.0.0.1, which points right back to the same machine you're running on. I do this all the time for developing and testing out websites or change to websites I work on. From jgardner at jonathangardner.net Mon Feb 15 18:55:05 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 15 Feb 2010 15:55:05 -0800 (PST) Subject: Time out a regular expression in Python 2.6.4? References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: On Feb 15, 7:59?am, Steve Holden wrote: > pyt... at bdurham.com wrote: > > Is there any way to time out a regular expression in Python 2.6.4? > > > Motiviation: Our application allows users to enter regular expressions > > as validation criteria. If a user enters a pathological regular > > expression, we would like to timeout the evaluation of this expression > > after a short period of time. > > Python itself does not contain any mechanism to terminate an operation > if it takes too much time. > > One approach would be to run the regex in a subprocess, and apply > process limits to terminate that subprocess if it ran too long. > > This group being what it is you are likely to receive other, better > suggestions too. > I'm not sure how exactly the re module is implemented, but since I assume a great chunk is in C code, you may get away with a single process and multiple threads. One thread will watch the process, or have a timer event set to go off at a certain point. The other will actually run the regex and get killed by the timer process if it doesn't finish in time. From news123 at free.fr Mon Feb 15 19:04:28 2010 From: news123 at free.fr (News123) Date: Tue, 16 Feb 2010 01:04:28 +0100 Subject: listing existing windows services with python Message-ID: <4b79e10c$0$30277$426a74cc@news.free.fr> Hi, What is the best way with python to get a list of all windows services. As a start I would be glad to receive only the service names. However it would be nicer if I could get all the properties of a service as well. Thanks for any info and bye N From news123 at free.fr Mon Feb 15 19:10:51 2010 From: news123 at free.fr (News123) Date: Tue, 16 Feb 2010 01:10:51 +0100 Subject: How to use python to register a service (an existing .exe file) Message-ID: <4b79e28c$0$4610$426a74cc@news.free.fr> Hi, Is there a python way to register new windows services. I am aware of the instsrv.exe program, which can be used to install services. I could use subprocess.Popen to call instsrv.exe "service_name" program.exe but wondered, whether there's already an existing function. Thans in advance and bye N From ben+python at benfinney.id.au Mon Feb 15 19:17:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 11:17:13 +1100 Subject: Which mock library do you prefer? References: Message-ID: <87eikmc9va.fsf@benfinney.id.au> Lacrima writes: > Minimock has wider usage and community, but I have some troubles using > it. Maybe I am wrong, but with minimock you always have to keep track > the order of imports in your test modules. Well, may be I just don't > understand fully how minimock works. I'm not sure why you think you need to keep track of the order of imports. Simply set up the mocks as you want them, in your fixtures; then, when tearing down your fixtures, use ?minimock.restore()? to restore the affected namespaces to their initial state. -- \ ?? one of the main causes of the fall of the Roman Empire was | `\ that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs.? ?Robert Firth | Ben Finney From alfps at start.no Mon Feb 15 19:17:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 01:17:31 +0100 Subject: listing existing windows services with python In-Reply-To: <4b79e10c$0$30277$426a74cc@news.free.fr> References: <4b79e10c$0$30277$426a74cc@news.free.fr> Message-ID: * News123: > Hi, > > > What is the best way with python to get a list of all windows services. > > As a start I would be glad to receive only the service names. > > However it would be nicer if I could get all the properties of a service > as well. > > Thanks for any info and bye * Library: If there is some existing library for that (just search the web) then that would probably be the easiest. * Registry functions: Otherwise, I'd use the general registry access functions. Info about the registry access functions is available in your Python docs. All the information about services is in the Windows registry (documented in the MSDN Library, which is available in a browsable on-line version at Microsoft). * Text-oriented commands: An alternative to using the registry access functions is to capture the output of e.g. the 'sc' command. The 'net' command also has some functionality related to services, e.g. 'net start'. Cheers & hth., - Alf From jjposner at optimum.net Mon Feb 15 19:33:19 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 15 Feb 2010 19:33:19 -0500 Subject: Modifying Class Object In-Reply-To: <4b79d447$0$8760$c3e8da3@news.astraweb.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> <4b79d447$0$8760$c3e8da3@news.astraweb.com> Message-ID: <4B79E7CF.3050805@optimum.net> On 2/15/2010 6:09 PM, Steven D'Aprano wrote: > On Mon, 15 Feb 2010 21:25:23 +0000, Arnaud Delobelle wrote: > >> John Posner writes: [...] >>>> x = s[0] >> [...] >>> assigns the name *x* to the object that *s[0]* refers to >> >> s[0] does not refer to an object, it *is* an object (once evaluated of >> course, otherwise it's just a Python expression). > > Precisely. Treated as an expression, that is, as a string being evaluated > by the compiler, we would say that it *refers to* an object (unless > evaluation fails, in which case it refers to nothing at all). But treated > as whatever you get after the compiler is done with it, that is, post- > evaluation, we would say that it *is* an object. > > This subtle distinction is essentially the difference between a label and > the thing that is labeled. Is this your only quibble with my writeup? If, so, I'm gratified. And your objections make perfect sense. Still, I'll attempt to justify my phrasing. I was originally going to write: assigns the name *x* to the object that THE NAME *s[0]* refers to ... but I didn't want to start a distracting argument on the use of the phrase *the name* to describe the 4-char string *s[0]*. So now I'll try to (briefly) make my case. Yes, it might be more correct to say that *s[0]* is an expression (equivalent to the more obvious expression *s.__getitem__(0)*). But in common usage, the 4-char string *s[0]* _behaves_ like a name. If you accept this viewpoint, the story on Python assignment statements becomes quite simple ... Syntactic sugar aside, there are only two kinds of assignment statements: 1. NAME = EXPRESSION The EXPRESSION creates a new object, and the NAME is assigned to that object. Examples: x = x + 1 obj = MyClass(1, 2, "red") mywordlist = mysentence.split() 2. NAME2 = NAME1 No new object is created. NAME2 becomes another name (an "alias") for the existing object that currently has NAME1 assigned to it. Examples: y = x s[0] = s[42] mydict["spamwich"] == this_sandwich obj.color = MYCOLORS.LTGREEN This viewpoint might fail in advanced areas of Python programming: properties/descriptors, double-underscore methods, etc. But in my own day-to-day usage (admittedly, I'm a hobbyist Python programmer, not a professional), it's never failed me to think this way: * A dict is a collection of user-devised names, each of which is assigned to an object. * A list/tuple is an interpreter-maintained collection of integer names (0, 1, 2, ...), each of which is assigned to an object. * A class instance is very much like a dict. Tx, John From python.list at tim.thechases.com Mon Feb 15 19:35:21 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Feb 2010 18:35:21 -0600 Subject: Parsing for email addresses In-Reply-To: <4fc54d57-cab5-41ee-8546-19e2645b329e@f17g2000prh.googlegroups.com> References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <4fc54d57-cab5-41ee-8546-19e2645b329e@f17g2000prh.googlegroups.com> Message-ID: <4B79E849.7060905@tim.thechases.com> Jonathan Gardner wrote: > On Feb 15, 3:34 pm, galileo228 wrote: >> I'm trying to write python code that will open a textfile and find the >> email addresses inside it. I then want the code to take just the >> characters to the left of the "@" symbol, and place them in a list. >> (So if galileo... at gmail.com was in the file, 'galileo228' would be >> added to the list.) >> >> Any suggestions would be much appeciated! >> > > You may want to use regexes for this. For every match, split on '@' > and take the first bit. > > Note that the actual specification for email addresses is far more > than a single regex can handle. However, for almost every single case > out there nowadays, a regex will get what you need. You can even capture the part as you find the regexps. As Jonathan mentions, finding RFC-compliant email addresses can be a hairy/intractable problem. But you can get a pretty close approximation: import re r = re.compile(r'([-\w._+]+)@(?:[-\w]+\.)+(?:\w{2,5})', re.I) # ^ # if you want to allow local domains like # user at localhost # then change the "+" marked with the "^" # to a "*" and the "{2,5}" to "+" to unlimit # the TLD. This will change the outcome # of the last test "jim at com" to True for test, expected in ( ('jim at example.com', True), ('jim at sub.example.com', True), ('@example.com', False), ('@sub.example.com', False), ('@com', False), ('jim at com', False), ): m = r.match(test) if bool(m) ^ expected: print "Failed: %r should be %s" % (test, expected) emails = set() for line in file('test.txt'): for match in r.finditer(line): emails.add(match.group(1)) print "All the emails:", print ', '.join(emails) -tkc From mwilson at the-wire.com Mon Feb 15 19:36:55 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 15 Feb 2010 19:36:55 -0500 Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: joy99 wrote: > Dear Group, > > I am trying to learn CGI. I was checking Python Docs. There are > multiple modules. Which one to start with? > Is there any other material or URL for step by step learning of CGI. > > My next question is: > I want to test it. I have a small personal computer. I have internet > but is connected by a service provider. I do not have personal web > page. Can I use my personal computer as a client as well as a server? A server can be as simple as: #!/usr/bin/env python # -*- coding: ASCII -*- '''Simple CGI server in Python $Id$''' import getopt, os, sys from BaseHTTPServer import HTTPServer from CGIHTTPServer import CGIHTTPRequestHandler port = 8000 opts, args = getopt.getopt (sys.argv[1:], 'd:p:', ['www=', 'port=']) for o, v in opts: if o in ['-d', '--www']: os.chdir (v) elif o in ('-p', '--port'): port = int (v) handler = HTTPServer (('', port), CGIHTTPRequestHandler) handler.serve_forever() If you run this like mycgiserver.py --www=my_www_dir and put your web pages under my_www_dir, and your CGI programs under my_www_dir/cgi-bin then pointing your browser to will show you your site. Mel. From ben+python at benfinney.id.au Mon Feb 15 20:01:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 12:01:03 +1100 Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> Message-ID: <87aavac7u8.fsf@benfinney.id.au> galileo228 writes: > I'm trying to write python code that will open a textfile and find the > email addresses inside it. I then want the code to take just the > characters to the left of the "@" symbol, and place them in a list. Email addresses can have more than one ?@? character. In fact, the quoting rules allow the local-part to contain *any ASCII character* and remain valid. > Any suggestions would be much appeciated! For a brief but thorough treatment of parsing email addresses, see RFC 3696, ?Application Techniques for Checking and Transformation of Names? , specifically section 3. -- \ ?What I have to do is see, at any rate, that I do not lend | `\ myself to the wrong which I condemn.? ?Henry Thoreau, _Civil | _o__) Disobedience_ | Ben Finney From steve at holdenweb.com Mon Feb 15 20:06:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 20:06:08 -0500 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: Jonathan Gardner wrote: > On Feb 15, 7:59 am, Steve Holden wrote: >> pyt... at bdurham.com wrote: >>> Is there any way to time out a regular expression in Python 2.6.4? >>> Motiviation: Our application allows users to enter regular expressions >>> as validation criteria. If a user enters a pathological regular >>> expression, we would like to timeout the evaluation of this expression >>> after a short period of time. >> Python itself does not contain any mechanism to terminate an operation >> if it takes too much time. >> >> One approach would be to run the regex in a subprocess, and apply >> process limits to terminate that subprocess if it ran too long. >> >> This group being what it is you are likely to receive other, better >> suggestions too. >> > > I'm not sure how exactly the re module is implemented, but since I > assume a great chunk is in C code, you may get away with a single > process and multiple threads. One thread will watch the process, or > have a timer event set to go off at a certain point. The other will > actually run the regex and get killed by the timer process if it > doesn't finish in time. That would be a great idea if it were possible to kill a thread form outside. Unfortunately it's not, so the best you can do is set a flag and have it queried periodically. This is not practical during re matching. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at mrabarnett.plus.com Mon Feb 15 20:37:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Feb 2010 01:37:33 +0000 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: <4B79F6DD.6060207@mrabarnett.plus.com> Steve Holden wrote: > Jonathan Gardner wrote: >> On Feb 15, 7:59 am, Steve Holden wrote: >>> pyt... at bdurham.com wrote: >>>> Is there any way to time out a regular expression in Python >>>> 2.6.4? Motiviation: Our application allows users to enter >>>> regular expressions as validation criteria. If a user enters a >>>> pathological regular expression, we would like to timeout the >>>> evaluation of this expression after a short period of time. >>> Python itself does not contain any mechanism to terminate an >>> operation if it takes too much time. >>> >>> One approach would be to run the regex in a subprocess, and apply >>> process limits to terminate that subprocess if it ran too long. >>> >>> This group being what it is you are likely to receive other, >>> better suggestions too. >>> >> I'm not sure how exactly the re module is implemented, but since I >> assume a great chunk is in C code, you may get away with a single >> process and multiple threads. One thread will watch the process, or >> have a timer event set to go off at a certain point. The other >> will actually run the regex and get killed by the timer process if >> it doesn't finish in time. > > That would be a great idea if it were possible to kill a thread form > outside. Unfortunately it's not, so the best you can do is set a flag > and have it queried periodically. This is not practical during re > matching. > The code for matching in the re module is written in C, and it doesn't release the GIL because it calls the Python API, and you need to have the GIL when doing that (unless you can guarantee that the specific call is safe, that is!). This means that other threads can't run during matching. In order to be able to cancel the matching, the re module would have to release the GIL when possible and have some kind of cancel() method (belonging to which class?). A simpler option would be to add a timeout argument. It already periodically checks for ctrl-C, so perhaps the time check could be done then. From wuwei23 at gmail.com Mon Feb 15 21:16:19 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Feb 2010 18:16:19 -0800 (PST) Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> Message-ID: <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> News123 wrote: > What is the best way with python to get a list of all windows services. > > As a start I would be glad to receive only the service names. > > However it would be nicer if I could get all the properties of a service > as well. I highly recommend Tim Golden's fantastic WMI module[1]. >>> import wmi >>> c = wmi.WMI() >>> services = c.Win32_Service() >>> s = services[0] >>> s <_wmi_object: \\LIB-D5NYF1S\root \cimv2:Win32_Service.Name="Alerter"> >>> s.properties {u'DisplayName': None, u'ServiceSpecificExitCode': None, u'State': None, u'Syste mName': None, u'ErrorControl': None, u'Status': None, u'ProcessId': None, u'Desc ription': None, u'Started': None, u'AcceptStop': None, u'CheckPoint': None, u'Pa thName': None, u'WaitHint': None, u'Name': None, u'InstallDate': None, u'Caption ': None, u'StartMode': None, u'DesktopInteract': None, u'ServiceType': None, u'T agId': None, u'StartName': None, u'AcceptPause': None, u'CreationClassName': Non e, u'SystemCreationClassName': None, u'ExitCode': None} >>> s.Name u'Alerter' >>> s.Started False >>> s.ServiceType u'Share Process' 1: http://timgolden.me.uk/python/wmi/index.html From shane_k_mcintyre at yahoo.com Mon Feb 15 21:19:27 2010 From: shane_k_mcintyre at yahoo.com (Shane McIntyre) Date: Mon, 15 Feb 2010 18:19:27 -0800 (PST) Subject: Web Service Using XML for input and output Message-ID: <682170.95799.qm@web57515.mail.re1.yahoo.com> I'm attempting to use a web service that takes XML as an input and returns an XML output.? I can connect to the service and attempt to pass in the XML but do not get any results. I believe my problem is how to package up the XML and send it in the request.? The XML consists of about 20 tag/value pairs. Any code snippets or a place to look for some examples would be appreciated.? I'm currently trying to use an HTTPConnection with the XML as a parameter in the request. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Feb 15 21:38:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 21:38:35 -0500 Subject: Web Service Using XML for input and output In-Reply-To: <682170.95799.qm@web57515.mail.re1.yahoo.com> References: <682170.95799.qm@web57515.mail.re1.yahoo.com> Message-ID: Shane McIntyre wrote: > I'm attempting to use a web service that takes XML as an input and > returns an XML output. I can connect to the service and attempt to pass > in the XML but do not get any results. I believe my problem is how to > package up the XML and send it in the request. The XML consists of > about 20 tag/value pairs. Any code snippets or a place to look for some > examples would be appreciated. I'm currently trying to use an > HTTPConnection with the XML as a parameter in the request. > Well, one could fatuously point out that you must be doing it wrong, but without seeing your code it's difficult to know exactly *how* you are going wrong. For all I know your current attempt at solution might require only minimal changes to make it work. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Mon Feb 15 22:28:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 04:28:25 +0100 Subject: listing existing windows services with python In-Reply-To: <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: * alex23: > News123 wrote: >> What is the best way with python to get a list of all windows services. >> >> As a start I would be glad to receive only the service names. >> >> However it would be nicer if I could get all the properties of a service >> as well. > > I highly recommend Tim Golden's fantastic WMI module[1]. It's probably Very Good, but one Microsoft-thing one should be aware of: using WMI functionality generally starts up a background WMI service... Similarly, starting the standard clipboard viewer (discontinued in Windows Vista) starts up a silly copy-clipboard-contents-over-network service. On a low-range machine the WMI service can be a resource concern. I don't know whether the WMI service is a security concern (it probably is, considering IIS and anything Microsoft+Network and that WMI is meant to administrate machines over network, it's an enterprise thing not a personal computer user thing), but the clipboard service is, as I recall, a concern. > >>> import wmi > >>> c = wmi.WMI() > >>> services = c.Win32_Service() > >>> s = services[0] > >>> s > <_wmi_object: \\LIB-D5NYF1S\root > \cimv2:Win32_Service.Name="Alerter"> > >>> s.properties > {u'DisplayName': None, u'ServiceSpecificExitCode': None, u'State': > None, u'Syste > mName': None, u'ErrorControl': None, u'Status': None, > u'ProcessId': None, u'Desc > ription': None, u'Started': None, u'AcceptStop': None, > u'CheckPoint': None, u'Pa > thName': None, u'WaitHint': None, u'Name': None, u'InstallDate': > None, u'Caption > ': None, u'StartMode': None, u'DesktopInteract': None, > u'ServiceType': None, u'T > agId': None, u'StartName': None, u'AcceptPause': None, > u'CreationClassName': Non > e, u'SystemCreationClassName': None, u'ExitCode': None} > >>> s.Name > u'Alerter' > >>> s.Started > False > >>> s.ServiceType > u'Share Process' > > 1: http://timgolden.me.uk/python/wmi/index.html Cheers, - Alf From wingusr at gmail.com Mon Feb 15 22:42:15 2010 From: wingusr at gmail.com (TP) Date: Mon, 15 Feb 2010 19:42:15 -0800 Subject: Am I using ctypes correctly? Where are fprints going? Message-ID: >From the Cplusplus-sig, I gathered that instead of Boost.Python I should use ctypes for the following problem. But let me make sure I'm using it correctly. I am calling the C Leptonica Image Processing C Library (http://leptonica.com) from python. Within its leptprotos.h file are functions like this: extern PIX * pixRead ( const char *filename ); extern void pixDestroy ( PIX **ppix ); Using Windows XP, and within a Command Prompt I do this: python26 >>> import ctypes >>> leptonica = ctypes.cdll.leptonlib >>> pixRead = leptonica.pixRead >>> pix=ctypes.c_void_p() >>> pix.value = pixRead(r"test.tif") >>> pix c_void_p(12310144) >>> leptonica.pixGetWidth(pix) 1553 #this is the correct width >>> leptonica.pixDestroy(ctypes.byref(pix)) >>> pix c_void_p(None) #This look right, pixDestroy() sets the pointer to NULL. Is this the proper way you are supposed to supply the address of a pointer that is returned by a C function? Is there a better way? Should I have done the following also? >>> pixRead.restype = ctypes.c_void_p >>> pixDestroy.restype = None Now that the pix has been destroyed, you shouldn't be able to get its width: >>> leptonica.pixGetWidth(pix) -1 This is correct but there also should have been an error message printed out. The C library is doing this (I think, I haven't actually used the debugger on it): sprintf(charbuf, "Error in %s: %s\n", procname, msg); fprintf(stderr, charbuf, ival); But I don't see any error message appear in my console window? Finally, the documentation states for ctypes.util.find_msvcrt(): Windows only: return the filename of the VC runtype library used by Python, and by the extension modules. If the name of the library cannot be determined, None is returned. If you need to free memory, for example, allocated by an extension module with a call to the free(void *), it is important that you use the function in the same library that allocated the memory. >>> import ctypes.util >>> ctypes.util.find_msvcrt() 'msvcr90.dll' Does this mean that if I build a Debug version of the Leptonica DLL (which will use the Debug version of the runtime library, msvcr90d.dll), that I also have to build and use a Debug version of Python26? I tried using leptonlibd.dll with the ActiveState release version of Python26 and didn't see any immediate error. From ldo at geek-central.gen.new_zealand Mon Feb 15 23:22:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Feb 2010 17:22:49 +1300 Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: In message <631b0785-38db-4c12- a82a-7b11e2235e23 at o16g2000prh.googlegroups.com>, joy99 wrote: > Is there any other material or URL for step by step learning of CGI. There?s the official spec here . From brian.curtin at gmail.com Mon Feb 15 23:50:26 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Mon, 15 Feb 2010 22:50:26 -0600 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: <4b79e28c$0$4610$426a74cc@news.free.fr> References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: On Mon, Feb 15, 2010 at 18:10, News123 wrote: > Hi, > > Is there a python way to register new windows services. > > > I am aware of the > instsrv.exe program, which can be used to install services. > I could use subprocess.Popen to call > > > instsrv.exe "service_name" program.exe > > > but wondered, whether there's already an existing function. > > Thans in advance and bye > > > N > There is nothing like that in the stdlib, so calling instserv via Popen may be your best bet. "sc create" may also be helpful to you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chuckmcknight at gmail.com Tue Feb 16 00:00:39 2010 From: chuckmcknight at gmail.com (Charles McKnight) Date: Mon, 15 Feb 2010 21:00:39 -0800 (PST) Subject: TkTable and Python 3.1 Message-ID: HI All, I'm fiddling around with Python and I'm trying to get tktable to work with Python 3.1 on Apple OS X 10.6 (Snow Leopard). Has anyone successfully accomplished this task, and if so, can you share how that you got it working? I've got Darwin Ports installed (current version) and I'm using Python 3.1 (ports), Tcl/Tk 8.5 (ports) and I've installed TkTable 2.10 (ports). Somehow, I've missed doing something because the Python interpreter can't seem to find the tktable module. Thanks in advance! Chuck From brian.curtin at gmail.com Tue Feb 16 00:13:45 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Mon, 15 Feb 2010 23:13:45 -0600 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> Message-ID: On Mon, Feb 15, 2010 at 18:17, Alf P. Steinbach wrote: > * News123: > > Hi, >> >> >> What is the best way with python to get a list of all windows services. >> >> As a start I would be glad to receive only the service names. >> >> However it would be nicer if I could get all the properties of a service >> as well. >> >> Thanks for any info and bye >> > > > * Registry functions: > > Otherwise, I'd use the general registry access functions. > > Info about the registry access functions is available in your Python docs. > > All the information about services is in the Windows registry (documented > in > the MSDN Library, which is available in a browsable on-line version at > Microsoft). > As for doing this via the registry, take a look at the EnumKey and EnumValue functions of the winreg module (_winreg in 2.x). HKLM\System\CurrentControlSet\Services contains service information, and iterating over that should get a lot of what's needed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Feb 16 00:43:25 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Feb 2010 21:43:25 -0800 (PST) Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: On Feb 16, 1:28?pm, "Alf P. Steinbach" wrote: > It's probably Very Good, but one Microsoft-thing one should be aware of: using > WMI functionality generally starts up a background WMI service... "Probably"? You haven't even used the module but you felt the need to contribute anyway? And I see that my suggestion is "probably" a security concern too. Would it be too much to ask for you to provide something other than unrelated anecdotes as evidence to support these claims? Or perhaps produce an alternative solution[1] for the OP instead of shitting over a working solution? So you chose to post to share your vague unsubstantiated concerns while offering the sterling advice that a developer need be familiar with a system in order to be aware of the costs in using it. Clearly time well spent by all. 1: http://essiene.blogspot.com/2005/04/python-windows-services.html From alfps at start.no Tue Feb 16 01:04:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 07:04:32 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: * alex23: > On Feb 16, 1:28 pm, "Alf P. Steinbach" wrote: >> It's probably Very Good, but one Microsoft-thing one should be aware of: using >> WMI functionality generally starts up a background WMI service... > > "Probably"? That means that since you say it's fantastic, it's probably very good. "Probably" is a way to qualify the statement. Based on your earlier and current quite emotional mode of expression I wouldn't take your word for an evaluation. > You haven't even used the module but you felt the need to > contribute anyway? Yes, since I did not contribute about the module, but rather about the functionality that it uses, which you didn't mention in your otherwise excellent reply to the OP. > And I see that my suggestion is "probably" a security concern too. Yeah. It has nothing to do with the module, though. Only with Microsoft's WMI. > Would it be too much to ask for you to provide > something other than unrelated anecdotes as evidence to support these > claims? Google it. E.g. . Other words and search engines might turn up other things, but the description of not a security "hole" but a security "crater" seems to me to indicate that it's not 100% secure. > Or perhaps produce an alternative solution[1] for the OP > instead of shitting over a working solution? Oh yes, the confusion that technical facts are somehow an expression of personal feelings and social matters, and can be chosen as one pleases, hence, that providing a fact or pointing out a possibility that is unwanted, is "shitting". From my point of view that's stupid. But I also think that apart from your "shitting" on me (and there the analogy is more apt, it's not about technical facts) it's great that you provide the kind of help that you did, pointing out a probably very good module that it seems gives the required functionality, and giving an URL. [snip further speculative insults] Cheers & hth., - Alf From wolftracks at invalid.com Tue Feb 16 01:42:04 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 15 Feb 2010 22:42:04 -0800 Subject: Looking for a Compiled Demo of MPL (matplotlib) Graphics Message-ID: Does anyone know where I can find a compiled demo that uses MPL graphics? I'd like, if possible, a Win version whose size is less than 10M, so that I can send it via e-mail, if necessary. It should use plot, so that someone can manipulate the plot with the navigation controls. At this point, I have no idea if that method is the fundamental graph tool or not. I suspect it is. If a mailable demo isn't available, maybe there's a web site that one can download such examples from? From timr at probo.com Tue Feb 16 01:58:17 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 15 Feb 2010 22:58:17 -0800 Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: joy99 wrote: > >I am trying to learn CGI. I was checking Python Docs. There are >multiple modules. Which one to start with? Well, it seems to me that the first place to start is the built-in CGI module, in "cgi.py". I'm not aware of any other CGI-based modules in the standard library. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From danijel.gvero at gmail.com Tue Feb 16 02:14:32 2010 From: danijel.gvero at gmail.com (DANNY) Date: Mon, 15 Feb 2010 23:14:32 -0800 (PST) Subject: MODULE FOR I, P FRAME References: Message-ID: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> On Feb 16, 12:53?am, "Rhodri James" wrote: > On Sun, 14 Feb 2010 10:07:35 -0000, DANNY wrote: > > Hy, first thanks for your response! > > Well I am thinkin on coding in MPEG4/10, but I would just encode the > > video in that encoding, > > then stream it with VLC and save the video file on my disc. Then I > > would play it with my player.... > > I think you're misunderstanding what VLC does here. ?Saving the video file ? > should preserve format by default; you may be able save it out in YUV ? > format (I don't have a copy on this machine to check), but that will take ? > up ludicrous amounts of disc space and you'd still have to write a byte ? > reader for it. ?If you do do that, you have lost any chance of knowing ? > whether a frame was an I or P frame in the original format, not that it ? > matters anyway by that point. > > MPEG-4/10 is hard to write efficient decoders for, and I have to admit I ? > wouldn't do it in Python. ?You'd be better off writing a wrapper for one ? > of the existing MP4 libraries. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses Hm, well I see that and now I am thinking of using reference software for MPEG4/10 which is written in c++ http://iphome.hhi.de/suehring/tml/ just to use it as a decoder on my client side, save the file in that format and then play it in my player using pyffmpeg http://code.google.com/p/pyffmpeg/ and just manipulate frames in that clip-I think that could be possible....am I right? Thanks for your help! From peloko45 at gmail.com Tue Feb 16 03:16:01 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 16 Feb 2010 00:16:01 -0800 (PST) Subject: Union of class variables Message-ID: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> Is possible to get a third class with the class variables of another two classes? -------- class A: foo = 1 class B: bar = 2 -------- From benedict.verheyen at gmail.com Tue Feb 16 03:28:12 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Tue, 16 Feb 2010 09:28:12 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4b79d343$0$8760$c3e8da3@news.astraweb.com> References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Mon, 15 Feb 2010 16:29:05 +0100, Benedict Verheyen wrote: > >> However, when i make a subdirectory, for example database and put a >> script in there, how would i import logutils or mailtutils from within >> the database subdirectory? This fails: >> from tools.logutils import logger > > Sounds like you need to ensure that the top level directory needs to be > added to your PYTHONPATH. > > Do you need instructions to do this? > Hi Steve, thanks, i think i know how to add the top level directory to the PYTHONPATH. I'm however looking further into the suggestion of ssteinerX to use a setup.py file to add the tools utility scripts to the pythonpath. In the near future, another person will be helping me with programming and thus, i want to make sure the structure is usable by other people than myself. Furthermore, i'm thinking if it wouldn't be cleaner to make such a setup.py file per script, at least the bigger, more important scripts. Now my structure is like this: python_scripts | |-->trunk ......|-----> all scripts ......|-----> tools The python_scripts directory and subdirs are versioned via SVN. I think these steps would help: 1. Make a package of tools. 2. Put the bigger scripts in a seperate directory also using a setup.py file. 3. If possible, put the other scripts that somehow belong together in a seperate directory. Names need to be more clear but i'm just illustrating a point. python_scripts | |-->trunk ......|-----> my big script 1 ................|-----> setup.py ......|-----> my big script 2 ................|-----> setup.py ......|-----> database ................|-----> database script 1 ................|-----> database script 2 ......|-----> tools ................|-----> setup.py Does that look like a clear structure? Thanks, Benedict From wuwei23 at gmail.com Tue Feb 16 03:38:00 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Feb 2010 00:38:00 -0800 (PST) Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: "Alf P. Steinbach" wrote: > it's great that you provide the kind > of help that you did, pointing out a probably very good module that it seems > gives the required functionality, and giving an URL. Yes, because that's _actually helping people_ and not just contributing the usual self-serving pontificating nonsense that just _flows_ from your goddamn mouth like a river of effluent psuedotruths. If you really wanted to help you would've cited _actual security flaws_ in your first response to me, instead of hand waving us away to once again do the leg work of verification. Based on your postings here, you regularly don't have the time or inclination to back up some of the bizarre claims you make. It would actually improve the signal in this channel a lot if you just chose not to make those posts at all. From wuwei23 at gmail.com Tue Feb 16 03:40:22 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Feb 2010 00:40:22 -0800 (PST) Subject: Union of class variables References: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> Message-ID: <0ab616a3-f507-487e-abb5-be0929d05117@f17g2000prh.googlegroups.com> On Feb 16, 6:16?pm, Joan Miller wrote: > Is possible to get a third class with the class variables of another > two classes? > > -------- > class A: > ? ? foo = 1 > > class B: > ? ? bar = 2 > -------- Through multiple inheritance? >>> class C(A, B): ... pass ... >>> C.foo 1 >>> C.bar 2 From alfps at start.no Tue Feb 16 03:52:37 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 09:52:37 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: * alex23: > "Alf P. Steinbach" wrote: >> it's great that you provide the kind >> of help that you did, pointing out a probably very good module that it seems >> gives the required functionality, and giving an URL. > > Yes, because that's _actually helping people_ and not just > contributing the usual self-serving pontificating nonsense that just > _flows_ from your goddamn mouth like a river of effluent > psuedotruths. That's an off-topic personal attack, and it's completely untrue. You're wasting bandwidth. > If you really wanted to help you would've cited _actual security > flaws_ in your first response to me, instead of hand waving us away > to once again do the leg work of verification. Posting two ranting and raving articles complaining about 1 (one) line or so in an earlier article, just because you personally wouldn't want to know that, that's a total waste of the reader's time. Disregarding the negative emotional adjectives you add everywhere, it's a good heuristic to post what you would want to know. I would want to know that a service is started, that it's designed for net based administration by Microsoft, and that so it might constitute a security risk. And so I added that information, each point of which is relevant. If you don't want to know about the "probably" little thing you can just skim over it. If you're unable to do that then something's wrong with you. > Based on your postings > here, you regularly don't have the time or inclination to back up some > of the bizarre claims you make. It would actually improve the signal > in this channel a lot if you just chose not to make those posts at all. That an off-topic personal attack, and it's completely untrue. Another poster (not me) has described you in an article here as a sockpuppet (false identity being in reality another poster here) and a troll; I believe at least the troll bit. It would reduce the noise level a bit if you stopped contributing noise like above. Cheers, - Alf From __peter__ at web.de Tue Feb 16 03:55:50 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Feb 2010 09:55:50 +0100 Subject: Printing with raw_input References: Message-ID: Shashwat Anand wrote: > raw_input uses sys.stderr I guess ? I had a look at the C code, but it's a bit confusing. If I'm reading it correctly the prompt is written to the "real" stderr if and only if sys.stdin and sys.stdout are attached to a terminal. $ python -c"raw_input('prompt\n')" 2>tmp.txt foo $ cat tmp.txt prompt $ python -c"raw_input('prompt\n')" 2>tmp.txt | cat foo prompt $ cat tmp.txt I wonder if that is intentional. Peter From peloko45 at gmail.com Tue Feb 16 03:59:19 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 16 Feb 2010 00:59:19 -0800 (PST) Subject: Union of class variables [Solved] References: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> <0ab616a3-f507-487e-abb5-be0929d05117@f17g2000prh.googlegroups.com> Message-ID: On 16 feb, 08:40, alex23 wrote: > On Feb 16, 6:16?pm, Joan Miller wrote: > > > Is possible to get a third class with the class variables of another > > two classes? > > > -------- > > class A: > > ? ? foo = 1 > > > class B: > > ? ? bar = 2 > > -------- > > Through multiple inheritance? > > ? >>> class C(A, B): > ? ... ? pass > ? ... > ? >>> C.foo > ? 1 > ? >>> C.bar > ? 2 Yes! It solves the problem :) Thanks! From ben+python at benfinney.id.au Tue Feb 16 04:01:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 20:01:08 +1100 Subject: Union of class variables References: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> Message-ID: <871vgld06j.fsf@benfinney.id.au> Joan Miller writes: > Is possible to get a third class with the class variables of another > two classes? Multiple inheritance is allowed in Python: class Baz(Foo, Bar): pass However, it leads to complications that you likely don't want, e.g. . Is it *really* the case that the new class is best expressed by an IS-A relationship to *both* the others? (?Every Baz IS-A Foo; every Baz IS-A Bar?) You should consider composition, instead. Decide which other class represents the more general case of the new class, and give it additional capabilities through a HAS-A relationship. (?Every Baz IS-A Foo; every Baz HAS-A Bar?) class Baz(Foo): def __init__(self): self.bar = Bar() That way, you keep the clarity of single inheritance and additional capabilities are accessed through an attribute. -- \ ?Always code as if the guy who ends up maintaining your code | `\ will be a violent psychopath who knows where you live.? ?John | _o__) F. Woods | Ben Finney From ben+python at benfinney.id.au Tue Feb 16 04:04:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 20:04:45 +1100 Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: <87wrydblg2.fsf@benfinney.id.au> alex23 writes: > Yes, because that's _actually helping people_ and not just > contributing the usual self-serving pontificating nonsense that just > _flows_ from your goddamn mouth like a river of effluent psuedotruths. I can't see what improvement you hope to achieve by sending something like this. If, instead, you just want to vent cathartically, this isn't the place to do it. Please, don't send the above kind of vitriol to this public forum. Better yet, compose it in your editor, bask in what you've written, then delete it unsent. -- \ ?Kill myself? Killing myself is the last thing I'd ever do.? | `\ ?Homer, _The Simpsons_ | _o__) | Ben Finney From gawade.ninad at gmail.com Tue Feb 16 05:43:09 2010 From: gawade.ninad at gmail.com (danin) Date: Tue, 16 Feb 2010 02:43:09 -0800 (PST) Subject: finding contents from string Message-ID: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Hi all, I am looking for particular solution. I am having one string say: string- "http://maps.google.co.in/maps/ms? hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 " and from this string i need to extract value -20.730428,86.456909. These value are dynamic so i cant use filter. So can anyone please tell me about how to do this. From arnodel at googlemail.com Tue Feb 16 05:57:59 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 10:57:59 +0000 Subject: finding contents from string References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: danin writes: > Hi all, > I am looking for particular solution. I am having one string > say: > string- "http://maps.google.co.in/maps/ms? > hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 > " > and from this string i need to extract value > -20.730428,86.456909. These value are dynamic so i cant use filter. So > can anyone please tell me about how to do this. In Python 2.5: >>> import urlparse >>> url='http://www.example.com/foo?bar=42&spam=eggs' >>> parsed_url = urlparse.urlparse(url) >>> parsed_url.query 'bar=42&spam=eggs' >>> import cgi >>> parsed_query = cgi.parse_qs(parsed_url.query) >>> parsed_query {'bar': ['42'], 'spam': ['eggs']} In Python >= 2.6, parse_qs lives in the urlparse module as well. -- Arnaud From __peter__ at web.de Tue Feb 16 06:00:06 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Feb 2010 12:00:06 +0100 Subject: finding contents from string References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: danin wrote: > Hi all, > I am looking for particular solution. I am having one string > say: > string- "http://maps.google.co.in/maps/ms? > hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 > " > and from this string i need to extract value > -20.730428,86.456909. Where does the "-" come from? > These value are dynamic so i cant use filter. I don't understand. > So can anyone please tell me about how to do this. >>> from urlparse import urlparse, parse_qs >>> parse_qs(urlparse(string).query)["ll"][0] '20.730428,86.456909' Peter From spam.buster at web.de Tue Feb 16 06:25:36 2010 From: spam.buster at web.de (Lars Behrens) Date: Tue, 16 Feb 2010 12:25:36 +0100 Subject: finding contents from string References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: danin wrote: > can anyone please tell me about how to do this. Now come on, you have to give a *bit* more information. What have you done so far? What did you plan? What are the rules for finding the string? -- Cheerz Lars From wolftracks at invalid.com Tue Feb 16 07:16:58 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 04:16:58 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters Message-ID: I normally use IDLE on Win, but recently needed to go to command prompt to see all error messages. When I did, I was greeted by a host of deprecation and Numpy messages before things got running. The program otherwise functioned OK, after I found the problem I was after. Are these messages a warning to get to the next update of numpy? I would guess that updating to a higher update does not mean I need to remove the old one, correct? In general for libraries like numpy or scipy, I use win32 updates, but I see win32-p3 updates too on download pages. Since I may be distributing this program to p3 machines, will I need to provide the win32-p3 updates to those users? From news123 at free.fr Tue Feb 16 07:18:16 2010 From: news123 at free.fr (News123) Date: Tue, 16 Feb 2010 13:18:16 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: <4b7a8d08$0$666$426a74cc@news.free.fr> Thanks for your answers, The security wouldn't be a concern, as I would run while being only accessible by trusted hosts. I don't use the script often, so if it would start a WMI service during runtime and stop it afterwards it would be fine. I just wonder whether installing another 3rd party package for just listing all services s worth the effort. In my current case I'll go probably for parsing the output of "sc.exe query" or I'll traverse the registry. currently I just want to get a list of the names of the running services. bye N Alf P. Steinbach wrote: > * alex23: >> News123 wrote: >>> What is the best way with python to get a list of all windows services. >>> >>> As a start I would be glad to receive only the service names. >>> >>> However it would be nicer if I could get all the properties of a service >>> as well. >> >> I highly recommend Tim Golden's fantastic WMI module[1]. > > It's probably Very Good, but one Microsoft-thing one should be aware of: > using WMI functionality generally starts up a background WMI service... > > Similarly, starting the standard clipboard viewer (discontinued in > Windows Vista) starts up a silly copy-clipboard-contents-over-network > service. > > On a low-range machine the WMI service can be a resource concern. > > I don't know whether the WMI service is a security concern (it probably > is, considering IIS and anything Microsoft+Network and that WMI is meant > to administrate machines over network, it's an enterprise thing not a > personal computer user thing), but the clipboard service is, as I > recall, a concern. > > >> >>> import wmi >> >>> c = wmi.WMI() >> >>> services = c.Win32_Service() >> >>> s = services[0] >> >>> s >> <_wmi_object: \\LIB-D5NYF1S\root >> \cimv2:Win32_Service.Name="Alerter"> >> >>> s.properties >> {u'DisplayName': None, u'ServiceSpecificExitCode': None, u'State': >> None, u'Syste >> mName': None, u'ErrorControl': None, u'Status': None, >> u'ProcessId': None, u'Desc >> ription': None, u'Started': None, u'AcceptStop': None, >> u'CheckPoint': None, u'Pa >> thName': None, u'WaitHint': None, u'Name': None, u'InstallDate': >> None, u'Caption >> ': None, u'StartMode': None, u'DesktopInteract': None, >> u'ServiceType': None, u'T >> agId': None, u'StartName': None, u'AcceptPause': None, >> u'CreationClassName': Non >> e, u'SystemCreationClassName': None, u'ExitCode': None} >> >>> s.Name >> u'Alerter' >> >>> s.Started >> False >> >>> s.ServiceType >> u'Share Process' >> >> 1: http://timgolden.me.uk/python/wmi/index.html > > Cheers, > > - Alf From wolftracks at invalid.com Tue Feb 16 07:19:15 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 04:19:15 -0800 Subject: Is there a simple way to find the list index to the max value? Message-ID: See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. From vaayu at ymail.com Tue Feb 16 07:25:45 2010 From: vaayu at ymail.com (Praveen Boppana) Date: Tue, 16 Feb 2010 17:55:45 +0530 (IST) Subject: finding contents from string In-Reply-To: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: <66498.7222.qm@web95303.mail.in2.yahoo.com> It looks like you want to extract the query parameters from standard url's. There is a standard Python module to accomplish this: http://www.python.org/doc/2.5.2/lib/module-urlparse.html ________________________________ From: danin To: python-list at python.org Sent: Tue, 16 February, 2010 4:13:09 PM Subject: finding contents from string Hi all, I am looking for particular solution. I am having one string say: string- "http://maps.google.co.in/maps/ms? hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 " and from this string i need to extract value -20.730428,86.456909. These value are dynamic so i cant use filter. So can anyone please tell me about how to do this. -- http://mail.python.org/mailman/listinfo/python-list Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Feb 16 07:29:36 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Feb 2010 12:29:36 +0000 Subject: listing existing windows services with python In-Reply-To: <4b7a8d08$0$666$426a74cc@news.free.fr> References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: <4B7A8FB0.2060901@timgolden.me.uk> On 16/02/2010 12:18, News123 wrote: > I don't use the script often, so if it would start a WMI service during > runtime and stop it afterwards it would be fine. FWIW -- your other considerations notwithstanding -- I'm not aware of WMI having this effect. Generally you can assume that the WMI services are running (or not, if someone's shut them off) but I've never heard of them being started up by virtue of a call to the WMI subsystem and then stopped afterwards. That said, I'd be interested if someone did have a pointer for this; worth putting a caveat in the docs if that were the case. TJG From arnodel at googlemail.com Tue Feb 16 07:37:46 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 12:37:46 +0000 Subject: Is there a simple way to find the list index to the max value? References: Message-ID: "W. eWatson" writes: > See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. Here are a few ways. >>> a = [1,4,9,3] >>> max_index = max(xrange(len(a)), key=a.__getitem__) >>> max_index 2 >>> # Or: ... max_index = max((n, i) for i, n in enumerate(a))[1] >>> max_index 2 >>> # Or: ... from itertools import * >>> max_index = max(izip(a, count()))[1] >>> max_index 2 -- Arnaud From steve at lonetwin.net Tue Feb 16 07:38:09 2010 From: steve at lonetwin.net (steve) Date: Tue, 16 Feb 2010 18:08:09 +0530 Subject: Is there a simple way to find the list index to the max value? References: Message-ID: <4B7A91B1.6030301@lonetwin.net> On 02/16/2010 05:49 PM, W. eWatson wrote: > See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. The most obvious would be a.index(max(a)). Is that what you wanted ? cheers, - steve From arnodel at googlemail.com Tue Feb 16 07:41:36 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 12:41:36 +0000 Subject: Is there a simple way to find the list index to the max value? References: Message-ID: Arnaud Delobelle writes: > "W. eWatson" writes: > >> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. > > Here are a few ways. [...] My copy past went wrond and I forgot the first one: >>> a = [1,4,9,3] >>> max_index = a.index(max(a)) >>> max_index 2 -- Arnaud From alfps at start.no Tue Feb 16 07:48:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 13:48:09 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: * Tim Golden: > On 16/02/2010 12:18, News123 wrote: >> I don't use the script often, so if it would start a WMI service during >> runtime and stop it afterwards it would be fine. > > FWIW -- your other considerations notwithstanding -- I'm not aware > of WMI having this effect. Generally you can assume that the WMI > services are running (or not, if someone's shut them off) but > I've never heard of them being started up by virtue of a call > to the WMI subsystem and then stopped afterwards. > > That said, I'd be interested if someone did have a pointer for this; > worth putting a caveat in the docs if that were the case. > > TJG I just googled the filename from memory, found Don't know if I've disabled it because invoking wmic didn't produce it. Uh, wait, since it hosts the provider service(s), perhaps... Yes, 'wmic service list brief' which actually retrieves some information (I guess it can be anything, I remembered this from listing process command lines) started an [wmprvse.exe] process. It terminated after the query/usage, but as I recall in some cases it doesn't. I don't know how that works with programmatic access, but it's worth checking out. Cheers, - Alf From mail at timgolden.me.uk Tue Feb 16 08:01:26 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Feb 2010 13:01:26 +0000 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: <4B7A9726.7080304@timgolden.me.uk> On 16/02/2010 12:48, Alf P. Steinbach wrote: > I just googled the filename from memory, found > > > > Don't know if I've disabled it because invoking wmic didn't produce it. > > Uh, wait, since it hosts the provider service(s), perhaps... > > Yes, 'wmic service list brief' which actually retrieves some information (I > guess it can be anything, I remembered this from listing process command lines) > started an [wmprvse.exe] process. > > It terminated after the query/usage, but as I recall in some cases it doesn't. > > I don't know how that works with programmatic access, but it's worth checking out. Thanks. As I understand it, you're not talking about a *service* starting up or shutting down; rather a *process* starting up etc., presumably controlled by the underlying service? I'll do some further research to see what's going on there. TJG From alfps at start.no Tue Feb 16 08:51:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 14:51:22 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: * Tim Golden: > On 16/02/2010 12:48, Alf P. Steinbach wrote: >> I just googled the filename from memory, found >> >> >> >> Don't know if I've disabled it because invoking wmic didn't produce it. >> >> Uh, wait, since it hosts the provider service(s), perhaps... >> >> Yes, 'wmic service list brief' which actually retrieves some >> information (I >> guess it can be anything, I remembered this from listing process >> command lines) >> started an [wmprvse.exe] process. >> >> It terminated after the query/usage, but as I recall in some cases it >> doesn't. >> >> I don't know how that works with programmatic access, but it's worth >> checking out. > > Thanks. As I understand it, you're not talking about a *service* > starting up > or shutting down; rather a *process* starting up etc., presumably > controlled > by the underlying service? It doesn't seem to provide ordinary Windows "service"s, but it's a bit unclear since e.g. the URL above says Beginning with Windows XP, WMI resides in a shared service host with several other services. To avoid stopping all the services when a provider fails, providers are loaded into a separate host process named Wmiprvse.exe. Multiple instances of Wmiprvse.exe can run at the same time under different accounts: LocalSystem, NetworkService or LocalService. The WMI core WinMgmt.exe is loaded into the shared Local Service host named Svchost.exe. Note: wmiprvsw.exe is the Sasser worm! Note: The wmiprvse.exe file is located in the folder C:\WINDOWS\System32\Wbem. In other cases, wmiprvse.exe is a virus, spyware, trojan or worm! Check this with Security Task Manager. Checking for ordinary Windows services: C:\test> (wmic service list >nul) & tasklist /svc /fi "imagename eq wmiprvse.exe" Image Name PID Services ========================= ====== ============================================= wmiprvse.exe 1076 N/A C:\test> _ > I'll do some further research to see what's going on there. Cheers, - Alf (is this off-topic for the group?) From leo at lspace.org Tue Feb 16 08:56:45 2010 From: leo at lspace.org (Leo Breebaart) Date: 16 Feb 2010 13:56:45 GMT Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> Message-ID: <7tvmgtF68lU1@mid.individual.net> Chris Rebert writes: > On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: > > > I have a base class Foo with a number of derived classes FooA, > > FooB, FooC, etc. Each of these derived classes needs to read > > (upon initialisation) text from an associated template file > > FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. > > [...] > > But, since this information is the same for every instance of > > each derived class, I was wondering if there was a way to achieve > > the same thing outside of the __init__ function, and just have > > these assignments be done as a class attribute (i.e. so that I > > can refer to FooA.template_body, etc.) > > Metaclasses to the rescue!: > > class WithTemplateAttrs(type): > def __new__(cls, name, bases, dct): > klass =3D type.__new__(cls, name, bases, dct) > klass.template_filename =3D "%s.tmpl" % name > klass.template_body =3D read_body_from(klass.template_filename) > return klass > > class Foo(object): > __metaclass__ =3D WithTemplateAttrs > #rest of class body here > > Now just have FooA, FooB, etc. subclass Foo as before. They'll > automatically get the attributes generated. Thanks for the feedback! I am thrilled that an actual real-life issue I'm having may be resolvable by metaclasses (which so far I've only admired from afar but never considered relevant to my day-to-day work), but unfortunately I'm still struggling to get this to work. If I add your code, what happens is that the Foo class will try to read "Foo.tmpl", which does not exist -- it is only the derived classes FooA etc, that need to execute this code, not Foo itself. And actually that makes sense -- I think my problem was not too clearly thought out to begin with. Of course it's not possible to associate a single template_body with the Foo class, it will be a different template for each derived class. So at best I need to associate your metaclass with each derived class, but at that point I might as well just read the template in the __init__() method with __class__.__name__, and use lazy evaluation / caching to avoid doing the actual file-reading work more than once. I think. -- Leo Breebaart From martin.hellwig at dcuktec.org Tue Feb 16 08:56:48 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 16 Feb 2010 13:56:48 +0000 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: On 02/16/10 13:51, Alf P. Steinbach wrote: > - Alf (is this off-topic for the group?) Strictly speaking yes, but I do find it interesting and there is nothing wrong with ignoring posts you don't like to read. -- mph From rludwinowski at gmail.com Tue Feb 16 09:37:00 2010 From: rludwinowski at gmail.com (rludwinowski) Date: Tue, 16 Feb 2010 06:37:00 -0800 (PST) Subject: Implicit __init__ execution in multiple inheritance Message-ID: <776abfc7-f57b-4630-9077-8ac1e4ee1c6e@b7g2000yqd.googlegroups.com> class A: def __init__(self): print("A__init__") class B: def __init__(self): print("B__init__") class C(A, B): pass C() >> A__init__ Why __init__ class B will not be automatic executed? From arnodel at googlemail.com Tue Feb 16 09:38:51 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 14:38:51 +0000 Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: Leo Breebaart writes: > Chris Rebert writes: > >> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: >> >> > I have a base class Foo with a number of derived classes FooA, >> > FooB, FooC, etc. Each of these derived classes needs to read >> > (upon initialisation) text from an associated template file >> > FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. >> > [...] >> > But, since this information is the same for every instance of >> > each derived class, I was wondering if there was a way to achieve >> > the same thing outside of the __init__ function, and just have >> > these assignments be done as a class attribute (i.e. so that I >> > can refer to FooA.template_body, etc.) >> >> Metaclasses to the rescue!: >> >> class WithTemplateAttrs(type): >> def __new__(cls, name, bases, dct): >> klass =3D type.__new__(cls, name, bases, dct) >> klass.template_filename =3D "%s.tmpl" % name >> klass.template_body =3D read_body_from(klass.template_filename) >> return klass >> >> class Foo(object): >> __metaclass__ =3D WithTemplateAttrs >> #rest of class body here >> >> Now just have FooA, FooB, etc. subclass Foo as before. They'll >> automatically get the attributes generated. > > Thanks for the feedback! I am thrilled that an actual real-life > issue I'm having may be resolvable by metaclasses (which so far > I've only admired from afar but never considered relevant to my > day-to-day work), but unfortunately I'm still struggling to get > this to work. > > If I add your code, what happens is that the Foo class will try > to read "Foo.tmpl", which does not exist -- it is only the > derived classes FooA etc, that need to execute this code, not Foo > itself. > > And actually that makes sense -- I think my problem was not too > clearly thought out to begin with. Of course it's not possible to > associate a single template_body with the Foo class, it will be a > different template for each derived class. So at best I need to > associate your metaclass with each derived class, but at that > point I might as well just read the template in the __init__() > method with __class__.__name__, and use lazy evaluation / caching > to avoid doing the actual file-reading work more than once. > > I think. Descriptors to the rescue :) def read_body_from(filename): print "** loading content **" return "" % filename # This is a kind of class property class TemplateFilename(object): def __get__(self, obj, cls): return "%s.tmpl" % cls.__name__ # And this is a kind of cached class property class TemplateBody(object): def __get__(self, obj, cls): try: return cls._body except AttributeError: cls._body = read_body_from(cls.template_filename) return cls._body class Foo(object): template_filename = TemplateFilename() template_body = TemplateBody() class FooA(Foo): pass class FooB(Foo): pass # In action: >>> FooA.template_filename 'FooA.tmpl' >>> FooB.template_filename 'FooB.tmpl' >>> FooA.template_body ** loading content ** "" >>> FooA.template_body "" >>> foob = FooB() >>> foob.template_filename 'FooB.tmpl' >>> foob.template_body ** loading content ** "" >>> foob.template_body "" HTH -- Arnaud From arnodel at googlemail.com Tue Feb 16 09:47:32 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 14:47:32 +0000 Subject: Implicit __init__ execution in multiple inheritance References: <776abfc7-f57b-4630-9077-8ac1e4ee1c6e@b7g2000yqd.googlegroups.com> Message-ID: rludwinowski writes: > class A: > def __init__(self): > print("A__init__") > > class B: > def __init__(self): > print("B__init__") > > class C(A, B): > pass > > C() > >>> A__init__ > > Why __init__ class B will not be automatic executed? Because it's documented behaviour? By default, at initialisation, an instance of C will go up the method resolution order and only execture the first __init__() method found. If you want to change this, you have to do it explicitely within the __init__ method(s) of the parent class(es). E.g. try this (assuming Python 3 syntax): class A: def __init__(self): super().__init__() print("A__init__") class B: def __init__(self): super().__init__() print("B__init__") class C(A, B): pass C() From ssteinerx at gmail.com Tue Feb 16 09:51:34 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 16 Feb 2010 09:51:34 -0500 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: On Feb 16, 2010, at 3:28 AM, Benedict Verheyen wrote: > Steven D'Aprano wrote: >> On Mon, 15 Feb 2010 16:29:05 +0100, Benedict Verheyen wrote: >> >>> However, when i make a subdirectory, for example database and put a >>> script in there, how would i import logutils or mailtutils from within >>> the database subdirectory? This fails: >>> from tools.logutils import logger >> >> Sounds like you need to ensure that the top level directory needs to be >> added to your PYTHONPATH. >> >> Do you need instructions to do this? >> > > Hi Steve, > > > thanks, i think i know how to add the top level directory to the PYTHONPATH. > > I'm however looking further into the suggestion of ssteinerX to use a > setup.py file to add the tools utility scripts to the pythonpath. > In the near future, another person will be helping me with programming > and thus, i want to make sure the structure is usable by other people > than myself. > > Furthermore, i'm thinking if it wouldn't be cleaner to make such a setup.py > file per script, at least the bigger, more important scripts. > Now my structure is like this: > > python_scripts > | > |-->trunk > ......|-----> all scripts > ......|-----> tools > > The python_scripts directory and subdirs are versioned via SVN. > I think these steps would help: > > 1. Make a package of tools. > 2. Put the bigger scripts in a seperate directory also using a setup.py file. > 3. If possible, put the other scripts that somehow belong together in a seperate > directory. Names need to be more clear but i'm just illustrating a point. > > python_scripts > | > |-->trunk > ......|-----> my big script 1 > ................|-----> setup.py > ......|-----> my big script 2 > ................|-----> setup.py > ......|-----> database > ................|-----> database script 1 > ................|-----> database script 2 > ......|-----> tools > ................|-----> setup.py > > Does that look like a clear structure? No. Make one setup.py at the top, put related scripts (like database) into separate sub-modules, so they can all be imported off a common 'trunk' as you have it above i.e. as trunk.database.xxx. Then use entry points for any command line scripts. Slightly harder, to setup initially but much cleaner to use and maintain and, it all installs with one call to setup.py develop. S From jeanmichel at sequans.com Tue Feb 16 10:00:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 16 Feb 2010 16:00:28 +0100 Subject: Using class attributes In-Reply-To: References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: <4B7AB30C.2020806@sequans.com> Arnaud Delobelle wrote: > Leo Breebaart writes: > > >> Chris Rebert writes: >> >> >>> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: >>> >>> >>>> I have a base class Foo with a number of derived classes FooA, >>>> FooB, FooC, etc. Each of these derived classes needs to read >>>> (upon initialisation) text from an associated template file >>>> FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. >>>> [...] >>>> But, since this information is the same for every instance of >>>> each derived class, I was wondering if there was a way to achieve >>>> the same thing outside of the __init__ function, and just have >>>> these assignments be done as a class attribute (i.e. so that I >>>> can refer to FooA.template_body, etc.) >>>> >>> Metaclasses to the rescue!: >>> >>> class WithTemplateAttrs(type): >>> def __new__(cls, name, bases, dct): >>> klass =3D type.__new__(cls, name, bases, dct) >>> klass.template_filename =3D "%s.tmpl" % name >>> klass.template_body =3D read_body_from(klass.template_filename) >>> return klass >>> >>> class Foo(object): >>> __metaclass__ =3D WithTemplateAttrs >>> #rest of class body here >>> >>> Now just have FooA, FooB, etc. subclass Foo as before. They'll >>> automatically get the attributes generated. >>> >> Thanks for the feedback! I am thrilled that an actual real-life >> issue I'm having may be resolvable by metaclasses (which so far >> I've only admired from afar but never considered relevant to my >> day-to-day work), but unfortunately I'm still struggling to get >> this to work. >> >> If I add your code, what happens is that the Foo class will try >> to read "Foo.tmpl", which does not exist -- it is only the >> derived classes FooA etc, that need to execute this code, not Foo >> itself. >> >> And actually that makes sense -- I think my problem was not too >> clearly thought out to begin with. Of course it's not possible to >> associate a single template_body with the Foo class, it will be a >> different template for each derived class. So at best I need to >> associate your metaclass with each derived class, but at that >> point I might as well just read the template in the __init__() >> method with __class__.__name__, and use lazy evaluation / caching >> to avoid doing the actual file-reading work more than once. >> >> I think. >> > > Descriptors to the rescue :) > > def read_body_from(filename): > print "** loading content **" > return "" % filename > > # This is a kind of class property > class TemplateFilename(object): > def __get__(self, obj, cls): > return "%s.tmpl" % cls.__name__ > > # And this is a kind of cached class property > class TemplateBody(object): > def __get__(self, obj, cls): > try: > return cls._body > except AttributeError: > cls._body = read_body_from(cls.template_filename) > return cls._body > > class Foo(object): > template_filename = TemplateFilename() > template_body = TemplateBody() > > class FooA(Foo): > pass > > class FooB(Foo): > pass > > # In action: > >>>> FooA.template_filename >>>> > 'FooA.tmpl' > >>>> FooB.template_filename >>>> > 'FooB.tmpl' > >>>> FooA.template_body >>>> > ** loading content ** > "" > >>>> FooA.template_body >>>> > "" > >>>> foob = FooB() >>>> foob.template_filename >>>> > 'FooB.tmpl' > >>>> foob.template_body >>>> > ** loading content ** > "" > >>>> foob.template_body >>>> > "" > > HTH > > While all these proposals are giving interesting technical anwsers to the OP problem, I think that the OP original code is still the best (_imo_). class Foo(object): def __init__(self): self.template_filename = "%s.tmpl" % self.__class__.__name__ self.template_body = read_body_from(self.template_filename) That is true the same attributes are defined for every instance, but, honestly, who cares ? (unless you target the best class design 2010 price :-) ) This solution beat the others in terms of simplicity and readability. It's still usefull to train your mind with decorators and metaclasses though, they can save your life eventually. JM From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 16 10:12:36 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 16 Feb 2010 16:12:36 +0100 Subject: Implicit __init__ execution in multiple inheritance In-Reply-To: References: <776abfc7-f57b-4630-9077-8ac1e4ee1c6e@b7g2000yqd.googlegroups.com> Message-ID: <4b7ab5e5$0$23314$426a74cc@news.free.fr> Arnaud Delobelle a ?crit : > rludwinowski writes: > >> class A: >> def __init__(self): >> print("A__init__") >> >> class B: >> def __init__(self): >> print("B__init__") >> >> class C(A, B): >> pass >> >> C() >> >>>> A__init__ >> Why __init__ class B will not be automatic executed? > > Because it's documented behaviour? By default, at initialisation, an > instance of C will go up the method resolution order and only execture > the first __init__() method found. Note to the OP : Python's "methods" are attributes, so the normal attribute lookup rules apply - which is why the lookup stops at the first (in _mro_ order) '__init__' method found. From paul at subsignal.org Tue Feb 16 10:14:22 2010 From: paul at subsignal.org (=?ISO-8859-9?Q?Paul_K=F6lle?=) Date: Tue, 16 Feb 2010 16:14:22 +0100 Subject: plugin / intra process communication system In-Reply-To: <1266271943.4299.2887.camel@brain> References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <1266271943.4299.2887.camel@brain> Message-ID: Am 15.02.2010 23:12, schrieb Florian Ludwig: > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: [...] >> And then of course, this is not really needed. In Python, behavior >> counts, not type-information. So you can get away without any explicit >> declared interface. You might chose to not do that, for aestetic >> reasons, or better documentation. But you aren't forced. > > Actually some plugin-systems in python do force you and they check if > your "implementation" comply with the "interface". Which is a good thing IMO ;) > Here is one solution I came up with. [...] Can you post working code? It's not clear what "pbus" is and how it works. cheers Paul > What do you think? Any obvious pitfalls (besides reinventing something)? > > Please keep in mind that syntax/api is not "done" or anything its just > an concept presentation. > > Thanks, > Florian > > > From arnodel at googlemail.com Tue Feb 16 10:15:49 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 15:15:49 +0000 Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: Jean-Michel Pichavant writes: [...] > While all these proposals are giving interesting technical anwsers to > the OP problem, I think that the OP original code is still the best > (_imo_). > > class Foo(object): > def __init__(self): > self.template_filename = "%s.tmpl" % self.__class__.__name__ > self.template_body = read_body_from(self.template_filename) > > > That is true the same attributes are defined for every instance, but, > honestly, who cares ? (unless you target the best class design 2010 > price :-) ) You might care if you have many instances but few classes, and the size of template_body is significant. Although with this design it is possible to cache template bodies within the 'read_body_from' function if necessary. Also I was under the impression that the OP wanted these attribute to be accessible from the class object as well. -- Arnaud From robert.kern at gmail.com Tue Feb 16 10:30:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Feb 2010 09:30:29 -0600 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters In-Reply-To: References: Message-ID: On 2010-02-16 06:16 AM, W. eWatson wrote: > I normally use IDLE on Win, but recently needed to go to command prompt > to see all error messages. When I did, I was greeted by a host of > deprecation and Numpy messages before things got running. The program > otherwise functioned OK, after I found the problem I was after. Are > these messages a warning to get to the next update of numpy? > > I would guess that updating to a higher update does not mean I need to > remove the old one, correct? > > In general for libraries like numpy or scipy, I use win32 updates, but I > see win32-p3 updates too on download pages. Since I may be distributing > this program to p3 machines, will I need to provide the win32-p3 updates > to those users? You will definitely want to ask these questions on the numpy-discussion mailing list. They are numpy-specific. Please copy-and-paste the messages that you get. 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 wolftracks at invalid.com Tue Feb 16 10:34:51 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 07:34:51 -0800 Subject: Is there a simple way to find the list index to the max value? In-Reply-To: References: Message-ID: On 2/16/2010 4:41 AM, Arnaud Delobelle wrote: > Arnaud Delobelle writes: > >> "W. eWatson" writes: >> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >> Here are a few ways. > > [...] > > My copy past went wrond and I forgot the first one: > >>>> a = [1,4,9,3] >>>> max_index = a.index(max(a)) >>>> max_index > 2 > Ah, the good one for last! Thanks. From ssteinerx at gmail.com Tue Feb 16 10:35:26 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 16 Feb 2010 10:35:26 -0500 Subject: listing existing windows services with python In-Reply-To: <87wrydblg2.fsf@benfinney.id.au> References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <87wrydblg2.fsf@benfinney.id.au> Message-ID: <7137165D-34E6-4015-AD09-C26CD9677E55@gmail.com> On Feb 16, 2010, at 4:04 AM, Ben Finney wrote: > Please, don't send the above kind of vitriol to this public forum. > Better yet, compose it in your editor, bask in what you've written, then delete it unsent. +1 If you kids want to have some sort of pissing-in-your-sockpuppet type of contest to see who can out-whatever each other, do it off-list and don't waste everyone else's time with. What ever happened to "don't feed the trolls" ?? If you really believe someone's trolling, don't answer, block them, and move on. Providing a lengthy, well-reasoned reply only shows that they've pulled you into the troll pit for a fight with them, regardless of whether you're "right." S From wolftracks at invalid.com Tue Feb 16 10:37:28 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 07:37:28 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters In-Reply-To: References: Message-ID: On 2/16/2010 7:30 AM, Robert Kern wrote: > On 2010-02-16 06:16 AM, W. eWatson wrote: >> I normally use IDLE on Win, but recently needed to go to command prompt >> to see all error messages. When I did, I was greeted by a host of >> deprecation and Numpy messages before things got running. The program >> otherwise functioned OK, after I found the problem I was after. Are >> these messages a warning to get to the next update of numpy? >> >> I would guess that updating to a higher update does not mean I need to >> remove the old one, correct? >> >> In general for libraries like numpy or scipy, I use win32 updates, but I >> see win32-p3 updates too on download pages. Since I may be distributing >> this program to p3 machines, will I need to provide the win32-p3 updates >> to those users? > > You will definitely want to ask these questions on the numpy-discussion > mailing list. They are numpy-specific. Please copy-and-paste the > messages that you get. > > http://www.scipy.org/Mailing_Lists > Good idea, for the first part of this. I would think "In genera for ..." would be answerable here, but I'll give them both a shot. I'll post what I find here, as a follow up. From paul at boddie.org.uk Tue Feb 16 10:38:24 2010 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 16 Feb 2010 07:38:24 -0800 (PST) Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> <88a7ff43-3f1d-4e30-ad50-59b6c2f215f7@a5g2000prg.googlegroups.com> Message-ID: <5f3d2058-40ec-415e-8ad4-7e28b98fb304@15g2000yqa.googlegroups.com> On 14 Feb, 19:41, Steve Howell wrote: > > I ditto the profiling recommendation. > > http://docs.python.org/library/profile.html (To the original inquirer...) Try this, too: http://wiki.python.org/moin/PythonSpeed/Profiling If you have the tools, it's a lot easier than scanning through tables of times. Paul From steve at holdenweb.com Tue Feb 16 10:54:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Feb 2010 10:54:00 -0500 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: Alf P. Steinbach wrote: [...] >> I'll do some further research to see what's going on there. > > Cheers, > > - Alf (is this off-topic for the group?) It's gone a lot further off than this without anyone complaining. I think your experiences to date should convince you that you can rely on being told when you drift too far off-topic :) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From robert.kern at gmail.com Tue Feb 16 11:35:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Feb 2010 10:35:07 -0600 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters In-Reply-To: References: Message-ID: On 2010-02-16 09:37 AM, W. eWatson wrote: > On 2/16/2010 7:30 AM, Robert Kern wrote: >> On 2010-02-16 06:16 AM, W. eWatson wrote: >>> I normally use IDLE on Win, but recently needed to go to command prompt >>> to see all error messages. When I did, I was greeted by a host of >>> deprecation and Numpy messages before things got running. The program >>> otherwise functioned OK, after I found the problem I was after. Are >>> these messages a warning to get to the next update of numpy? >>> >>> I would guess that updating to a higher update does not mean I need to >>> remove the old one, correct? >>> >>> In general for libraries like numpy or scipy, I use win32 updates, but I >>> see win32-p3 updates too on download pages. Since I may be distributing >>> this program to p3 machines, will I need to provide the win32-p3 updates >>> to those users? >> >> You will definitely want to ask these questions on the numpy-discussion >> mailing list. They are numpy-specific. Please copy-and-paste the >> messages that you get. >> >> http://www.scipy.org/Mailing_Lists >> > Good idea, for the first part of this. I would think "In genera for ..." > would be answerable here, but I'll give them both a shot. Both parts are very numpy/scipy-specific, trust me. The reason that numpy has binary releases for Pentium 3 machines is because we have SSE code of various levels due to our accelerated BLAS libraries. This is very rare outside of numpy and scipy. And please provide the information that I asked for over in numpy-discussion. -- 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 benedict.verheyen at gmail.com Tue Feb 16 11:35:09 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Tue, 16 Feb 2010 17:35:09 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: ssteinerX at gmail.com wrote: > On Feb 16, 2010, at 3:28 AM, Benedict Verheyen wrote: >> python_scripts >> | >> |-->trunk >> ......|-----> my big script 1 >> ................|-----> setup.py >> ......|-----> my big script 2 >> ................|-----> setup.py >> ......|-----> database >> ................|-----> database script 1 >> ................|-----> database script 2 >> ......|-----> tools >> ................|-----> setup.py >> >> Does that look like a clear structure? > > No. > > Make one setup.py at the top, put related scripts (like database) into separate sub-modules, > so they can all be imported off a common 'trunk' as you have it above i.e. as trunk.database.xxx. > > Then use entry points for any command line scripts. > > Slightly harder, to setup initially but much cleaner to use and maintain and, it all installs with one call to setup.py develop. > > S Hhhm, i can see how it makes the maintenance cleaner. However, in the case of a single setup.py, i will end up installing scripts on servers that will never use them, only some. As with making egg files for the bigger scripts, you will only install what's needed. Then again, the script are small so in that respect it doesn't really matter. How would i best distribute it? Via the single setup.py or building an egg from the setup.py or plain copying the files to the server? The code is company specific so nobody else will benefit from it. Thanks, Benedict From jeanmichel at sequans.com Tue Feb 16 11:45:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 16 Feb 2010 17:45:04 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: <4B7ACB90.7070502@sequans.com> Benedict Verheyen wrote: > ssteinerX at gmail.com wrote: > >> On Feb 16, 2010, at 3:28 AM, Benedict Verheyen wrote: >> > > > >>> python_scripts >>> | >>> |-->trunk >>> ......|-----> my big script 1 >>> ................|-----> setup.py >>> ......|-----> my big script 2 >>> ................|-----> setup.py >>> ......|-----> database >>> ................|-----> database script 1 >>> ................|-----> database script 2 >>> ......|-----> tools >>> ................|-----> setup.py >>> >>> Does that look like a clear structure? >>> >> No. >> >> Make one setup.py at the top, put related scripts (like database) into separate sub-modules, >> so they can all be imported off a common 'trunk' as you have it above i.e. as trunk.database.xxx. >> >> Then use entry points for any command line scripts. >> >> Slightly harder, to setup initially but much cleaner to use and maintain and, it all installs with one call to setup.py develop. >> >> S >> > > Hhhm, i can see how it makes the maintenance cleaner. > However, in the case of a single setup.py, i will end up installing scripts on servers > that will never use them, only some. > You should care about this only if your scripts exceeed a faire amount of Ko. Are you sure you've written Mo of python code ? JM From benedict.verheyen at gmail.com Tue Feb 16 11:52:29 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Tue, 16 Feb 2010 17:52:29 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4B7ACB90.7070502@sequans.com> References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> <4B7ACB90.7070502@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Benedict Verheyen wrote: >> Hhhm, i can see how it makes the maintenance cleaner. >> However, in the case of a single setup.py, i will end up installing >> scripts on servers >> that will never use them, only some. >> > You should care about this only if your scripts exceeed a faire amount > of Ko. > Are you sure you've written Mo of python code ? > > JM Nope and i indicated that before: "Then again, the script are small so in that respect it doesn't really matter." Regards, Benedict From lacrima.maxim at gmail.com Tue Feb 16 11:53:42 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Tue, 16 Feb 2010 08:53:42 -0800 (PST) Subject: Which mock library do you prefer? References: <87eikmc9va.fsf@benfinney.id.au> Message-ID: On Feb 16, 2:17?am, Ben Finney wrote: > Lacrima writes: > > Minimock has wider usage and community, but I have some troubles using > > it. Maybe I am wrong, but with minimock you always have to keep track > > the order of imports in your test modules. Well, may be I just don't > > understand fully how minimock works. > > I'm not sure why you think you need to keep track of the order of > imports. > > Simply set up the mocks as you want them, in your fixtures; then, when > tearing down your fixtures, use ?minimock.restore()? to restore the > affected namespaces to their initial state. > > -- > ?\ ? ? ? ?? one of the main causes of the fall of the Roman Empire was | > ? `\ ? ? ? ?that, lacking zero, they had no way to indicate successful | > _o__) ? ? ? ? ? ? ? ? ?termination of their C programs.? ?Robert Firth | > Ben Finney Hi Ben! See these two topics: http://groups.google.com/group/minimock-dev/browse_thread/thread/bcbb3b7cc60eb96f http://groups.google.com/group/minimock-dev/browse_thread/thread/c41cd996735ea1a6 There are special cases, which you have to be aware of, if you use minimock. From tjreedy at udel.edu Tue Feb 16 11:59:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Feb 2010 11:59:59 -0500 Subject: Using class attributes In-Reply-To: <7tvmgtF68lU1@mid.individual.net> References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: On 2/16/2010 8:56 AM, Leo Breebaart wrote: > Chris Rebert writes: > >> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: >> >>> I have a base class Foo with a number of derived classes FooA, >>> FooB, FooC, etc. Each of these derived classes needs to read >>> (upon initialisation) text from an associated template file >>> FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. >>> [...] >>> But, since this information is the same for every instance of >>> each derived class, I was wondering if there was a way to achieve >>> the same thing outside of the __init__ function, and just have >>> these assignments be done as a class attribute (i.e. so that I >>> can refer to FooA.template_body, etc.) >> >> Metaclasses to the rescue!: >> >> class WithTemplateAttrs(type): >> def __new__(cls, name, bases, dct): >> klass =3D type.__new__(cls, name, bases, dct) >> klass.template_filename =3D "%s.tmpl" % name >> klass.template_body =3D read_body_from(klass.template_filename) >> return klass >> >> class Foo(object): >> __metaclass__ =3D WithTemplateAttrs >> #rest of class body here >> >> Now just have FooA, FooB, etc. subclass Foo as before. They'll >> automatically get the attributes generated. > > Thanks for the feedback! I am thrilled that an actual real-life > issue I'm having may be resolvable by metaclasses (which so far > I've only admired from afar but never considered relevant to my > day-to-day work), I thought this a really nice example of metaclass use too. > but unfortunately I'm still struggling to get > this to work. > > If I add your code, what happens is that the Foo class will try > to read "Foo.tmpl", which does not exist -- it is only the > derived classes FooA etc, that need to execute this code, not Foo > itself. My simpleminded solution to the above would be to create a dummy Foo.tmpl file, so it does exist. Or, in __new__ above, conditionalize the fetch: if name != 'Foo': ... Terry Jan Reedy From lacrima.maxim at gmail.com Tue Feb 16 12:08:00 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Tue, 16 Feb 2010 09:08:00 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> Message-ID: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> On Feb 15, 9:56?pm, Phlip wrote: > Lacrima wrote: > > Thanks for your reply! Isn't what you are talking about integration > > tests? And unit tests should be fully isolated? So even for method > > 'some_method()' of class A I should mock instance of class A (i.e. to > > mock 'self') to test 'some_method()'. > > "Unit test" is a high-end QA concept. Developers can get the best > return on "developer tests". They don't bother with aerospace-quality > isolation between units. > > If a TDD test needs to pull in a bunch of modules to pass, that's > generally a good thing, because they all get indirect testing. If they > catch a bug, their local tests might not catch it, but the higher > level tests still have a chance. > > (And if your product still needs unit tests, TDD will make them very > easy for a formal QA team to add.) > > However, expensive setup is a design smell. That means if a test case > requires too many lines of code for its Assemble phase (before its > Activate and Assert phases), then maybe those lines of code support > objects that are too coupled, and they need a better design. > > Throwing mocks at these objects, instead of decoupling them, will > "perfume" the design smell, instead of curing it. > > > > "construction encapsulation") > > And could you give an example. > > ? def test_frob(self): > ? ? ? frob = Frob() > ? ? ? frob.knob = Mock() > ? ? ? frob.knob.value = Mock(return_value = 42) > ? ? ? assert 42 == frob.method_using_knob() > > We need the mock because we can't control how Frob's constructor built > its knob. So instead, give Frob the option to construct with a Knob: > > ? def test_frob(self): > ? ? ? knob = Knob(42) > ? ? ? frob = Frob(knob) > ? ? ? assert frob.method_using_knob() > > Note that in production the Knob constructor never takes a Knob. Maybe > we should upgrade the production code too (!), or maybe Knob's > constructor should only create a knob if it didn't get passed one. > Either technique is acceptable, because the resulting code decouples > Frobs and Knobs just a little bit more. > > > For me it's really hard to develop test first. Often I don't know what > > tests to write to replace hardcoded return values by objects that > > perform actual work. > > You have read too many books on TDD. C-: > > Alternate between writing lines of test and lines of code. Run the > tests after the fewest possible edits, and always correctly predict if > the tests will pass, or will fail, and with what diagnostic. (And > configure your editor to run the stankin tests, no matter how hard it > fights you!) The high-end tricks will get easier after you get the > basic cycle down. > > -- > ? Phlip > ?http://c2.com/cgi/wiki?ZeekLand Hi Phlip! Thanks for your exhaustive answer. Actually, I'll investigate your example with 'frob'. From just reading the example it's not clear for me what I will benefit, using this approach. And I have already refused to write totally isolated tests, because it looks like a great waste of time. From phlip2005 at gmail.com Tue Feb 16 12:38:09 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Feb 2010 09:38:09 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> Message-ID: <07d50b9f-c4bb-4d49-82d0-bd6d1c2e42be@z10g2000prh.googlegroups.com> On Feb 16, 9:08?am, Lacrima wrote: > Thanks for your exhaustive answer. > Actually, I'll investigate your example with 'frob'. From just reading > the example it's not clear for me what I will benefit, using this > approach. I can't get a good hit for "construction encapsulation" in Google. (Although I got some good bad ones!) This paper _almost_ gets the idea: http://www.netobjectives.com/download/Code%20Qualities%20and%20Practices.pdf > And I have already refused to write totally isolated tests, because it > looks like a great waste of time. Do you run your tests after the fewest possible edits? Such as 1-3 lines of code? I'm not sure why the TDD books don't hammer that point down... -- Phlip http://c2.com/cgi/wiki?ZeekLand From deets at nospam.web.de Tue Feb 16 13:20:03 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 16 Feb 2010 19:20:03 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> Message-ID: <7u05ulFfmkU1@mid.uni-berlin.de> Am 15.02.10 23:12, schrieb Florian Ludwig: > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: >>> Here there problem with the trac (and other plugin systems I've >> seen) >>> approach: >>> >>> You need to define something like: >>> | >>> | class IAuthPlugin(Interface): [...] >>> | >>> in your blog software. >> >> Why? Any reason you can't define it in a separate package the >> blog-software depends on, as well as your wiki? > > That's actually my point - most plugin systems I've seen, like the one > trac uses, are not encouraging you to do so. Having a module that just > defines an Interface is kind of weird - and in the real world no one is > doing it. Just because nobody doesn't do it doesn't mean it's not desirable. IMHO the ones using interfaces usually immediatly implement them for some cases - so you actually get the interface for you authentication framework, and also implement an OpenID plugin for it. And this forms one package. Then you can add new packages that implement other things. repoze.who and what are examples for such design. > >> And then of course, this is not really needed. In Python, behavior >> counts, not type-information. So you can get away without any explicit >> declared interface. You might chose to not do that, for aestetic >> reasons, or better documentation. But you aren't forced. > > Actually some plugin-systems in python do force you and they check if > your "implementation" comply with the "interface". I didn't say nobody does it, I just said it isn't needed to get a working plugin system. If you don't want to have a separate package *and* don't want to pull in any unused code, this is pretty much your only option. > Here is one solution I came up with. Based on the earlier example: >>> Lets say you program a wiki and like to allow different kind of >>> authentications. So you create two plugins (for example one for >>> OpenID and one for Shibboleth). >>> >>> Some time later you feel like reinventing the wheel again and >>> you program a blog. Again you like to allow different ways of >>> authentication and you already wrote plugins for exactly the >>> same for your wiki, right? > > auth_openid.py - providing the authentication service > http://dpaste.com/hold/159619/ > > wiki.py - providing the wiki > http://dpaste.com/hold/159634/ > > Now putting both together: > >> import pbus >> >> import wiki >> import auth_openid >> # or: import auth_shibboleth >> >> pbus.get("wiki").run() > > No interface definitions. > > > What do you think? Any obvious pitfalls (besides reinventing something)? I don't know what pbus is supposed to do. Nor how it's laid out on a python package level. Diez From caseyhHAMMER_TIME at istar.ca Tue Feb 16 13:32:51 2010 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Tue, 16 Feb 2010 10:32:51 -0800 Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? Message-ID: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? -- Regards, Casey From caseyhHAMMER_TIME at istar.ca Tue Feb 16 13:38:41 2010 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Tue, 16 Feb 2010 10:38:41 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. Message-ID: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-death.html -- Regards, Casey From mattbarkan at gmail.com Tue Feb 16 13:58:27 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 10:58:27 -0800 (PST) Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <87aavac7u8.fsf@benfinney.id.au> Message-ID: <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> Hey all, thanks as always for the quick responses. I actually found a very simple way to do what I needed to do. In short, I needed to take an email which had a large number of addresses in the 'to' field, and place just the identifiers (everything to the left of @domain.com), in a python list. I simply highlighted all the addresses and placed them in a text file called emails.txt. Then I had the following code which placed each line in the file into the list 'names': [code] fileHandle = open('/Users/Matt/Documents/python/results.txt','r') names = fileHandle.readlines() [/code] Now, the 'names' list has values looking like this: ['aaa12 at domain.com \n', 'bbb34 at domain.com\n', etc]. So I ran the following code: [code] for x in names: st_list.append(x.replace('@domain.com\n','')) [/code] And that did the trick! 'Names' now has ['aaa12', 'bbb34', etc]. Obviously this only worked because all of the domain names were the same. If they were not then based on your comments and my own research, I would've had to use regex and the split(), which looked massively complicated to learn. Thanks all. Matt On Feb 15, 8:01?pm, Ben Finney wrote: > galileo228 writes: > > I'm trying to write python code that will open a textfile and find the > > email addresses inside it. I then want the code to take just the > > characters to the left of the "@" symbol, and place them in a list. > > Email addresses can have more than one ?@? character. In fact, the > quoting rules allow the local-part to contain *any ASCII character* and > remain valid. > > > Any suggestions would be much appeciated! > > For a brief but thorough treatment of parsing email addresses, see RFC > 3696, ?Application Techniques for Checking and Transformation of Names? > , specifically section 3. > > -- > ?\ ? ? ? ? ??What I have to do is see, at any rate, that I do not lend | > ? `\ ? ? ?myself to the wrong which I condemn.? ?Henry Thoreau, _Civil | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Disobedience_ | > Ben Finney From andrej.mitrovich at gmail.com Tue Feb 16 14:41:58 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Tue, 16 Feb 2010 11:41:58 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: Message-ID: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> On Feb 16, 7:38?pm, Casey Hawthorne wrote: > Interesting talk on Python vs. Ruby and how he would like Python to > have just a bit more syntactic flexibility. > > http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > -- > Regards, > Casey Gary's friend Geoffrey Grosenbach says in his blog post (which Gary linked to): "Python has no comparable equivalent to Ruby?s do end block. Python lambdas are limited to one line and can?t contain statements (for, if, def, etc.). Which leaves me wondering, what?s the point?" I'm sorry, lambda's do support if's and for's. Also, lambda's are expressions, not statements, but you can pass them around, keep them in a dictionary if you want to. And if you need more than one line of statements, for crying out loud use a def? And who needs those "do- end" blocks anyway, trying to turn Python into Pascal? From aahz at pythoncraft.com Tue Feb 16 14:44:45 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Feb 2010 11:44:45 -0800 Subject: Is there a simple way to find the list index to the max value? References: <4B7A91B1.6030301@lonetwin.net> Message-ID: In article <4B7A91B1.6030301 at lonetwin.net>, steve wrote: >On 02/16/2010 05:49 PM, W. eWatson wrote: >> >> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. > >The most obvious would be a.index(max(a)). Is that what you wanted ? The disadvantage of that is that it's O(2N) instead of O(N). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From dino at phidev.org Tue Feb 16 14:50:39 2010 From: dino at phidev.org (Florian Ludwig) Date: Tue, 16 Feb 2010 20:50:39 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <1266271943.4299.2887.camel@brain> Message-ID: <1266349839.10498.240.camel@brain> On Tue, 2010-02-16 at 16:14 +0100, Paul K?lle wrote: > Am 15.02.2010 23:12, schrieb Florian Ludwig: > > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: > >> [...] > >> And then of course, this is not really needed. In Python, behavior > >> counts, not type-information. So you can get away without any > >> explicit > >> declared interface. You might chose to not do that, for aestetic > >> reasons, or better documentation. But you aren't forced. > > > > Actually some plugin-systems in python do force you and they check > > if your "implementation" comply with the "interface". > Which is a good thing IMO ;) Type checking might be good but not pythonic - imo. The problem with having interfaces needed to be declared (and therefore the possibility to check) is as I outlined in my first mail: Where to put those interface descriptions if you want both sides pluggable? You probably end up depending on other modules/projects just to import the interfaces. > > Here is one solution I came up with. > [...] > Can you post working code? It's not clear what "pbus" is and how it > works. Oh, sorry. The idea is similar to "d-bus" - hence the name. Its "the communcation system". The code is pretty simple and quick. Please remember its just to show of the concept not to use it in any production software or anything. Instead of using classes as connecting-piece I thought using strings (maybe path "/plugin/wiki" or "org.example.wiki") might solve my problem. It might be possible to add optional interface validation though. pbus.py - just a simple concept implementation of a framework http://dpaste.com/hold/159980/ auth_openid.py - providing the authentication service http://dpaste.com/hold/159619/ wiki.py - providing the wiki http://dpaste.com/hold/159634/ Now putting both together: > import pbus > > import wiki > import auth_openid > # or: import auth_shibboleth > > pbus.get("wiki").run() -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From mail at timgolden.me.uk Tue Feb 16 14:53:18 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Feb 2010 19:53:18 +0000 Subject: Is there a simple way to find the list index to the max value? In-Reply-To: References: <4B7A91B1.6030301@lonetwin.net> Message-ID: <4B7AF7AE.6040401@timgolden.me.uk> On 16/02/2010 19:44, Aahz wrote: > In article<4B7A91B1.6030301 at lonetwin.net>, steve wrote: >> On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >> The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disadvantage of that is that it's O(2N) instead of O(N). Well you could do this: a.sort () return -1 TJG From nagle at animats.com Tue Feb 16 15:15:05 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Feb 2010 12:15:05 -0800 Subject: The future of "frozen" types as the number of CPU cores increases Message-ID: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> In the beginning, Python had some types which were "frozen", and some which weren't. Now, there's a trend towards having both "frozen" and "unfrozen" versions of built-in types. We now have "frozen" and "unfrozen" sets, dictionaries, and byte arrays. It's becoming clear that that the concept of "frozen" is separate from the type involved. Maybe "frozen" should be generalized, so that all "unfrozen" objects also have "frozen" versions. I'd suggest p = freeze(q) which would generate a "frozen" copy of q. (For lists, this would return a tuple. For unfrozen sets, a frozen set. Etc.) p = deepfreeze(q) would generate "frozen" deep copy of q, for which each object it references is also a "frozen" copy. For objects, class c(frozenobject) : def __init__(self, someparam) : self.p = someparam ... would result in a class which returns frozen objects from the constructor. In concurrent programs, frozen objects can be shared without locking. This simplifies locking considerably. This may provide a way to get out from the Global Interpreter Lock. One possible implementation would be to have unfrozen objects managed by reference counting and locking as in CPython. Frozen objects would live in a different memory space and be garbage collected by a concurrent garbage collector. If we add "synchronized" objects with built-in locking, like Java, threading becomes much cleaner. class d(synchronized) : ... A typical "synchronized" object would be a queue. Anything with state shared across threads has to be synchronized. Only one thread at a time can be active within a synchronized object, due to a built-in implicit lock. Semantics of synchronized objects: "Synchronized" objects cannot be frozen. Trying to freeze them just returns the object. If a thread blocks on an explicit "wait", the synchronized object is temporarily unlocked during the "wait". This allows threads to wait for, say, a queue to get another entry from another thread. If only synchronized objects and frozen objects can be shared across threads, the GIL becomes unnecessary. Big performance win on multicore CPUs. "Synchronized" was a pain in Java because Java doesn't have "frozen" objects. Too much effort went into synchronizing little stuff. But in a language with frozen objects, the little stuff would be frozen, and wouldn't need its own locks. Threaded programs that already use queue objects to communicate with each other are almost ready for this kind of architecture now. If the queue class made a frozen copy of any unfrozen, unsynchronized copy placed on a queue, conversion to this approach could be almost automatic. What would probably happen in practice is that potential race conditions in existing programs would raise "unshareable object" exceptions, indicating that something needed to be synchronized. That's a good thing. This approach makes threading much easier for the typical programmer. Instead of race conditions and random errors, you get error messages. And we get rid of the GIL. I look at this as Python's answer to multicore CPUs and "Go". John Nagle From alfps at start.no Tue Feb 16 15:15:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 21:15:11 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: > [...] >>> I'll do some further research to see what's going on there. >> Cheers, >> >> - Alf (is this off-topic for the group?) > > It's gone a lot further off than this without anyone complaining. I > think your experiences to date should convince you that you can rely on > being told when you drift too far off-topic :) Some old folks' music, Eternity's Breath & Stratus; the guy playing is 65: Hip hoppers may skip the 80 seconds complicated intro. It is relevant in a way, although very indirectly. For although the comment did not pop up here, many Satch videos (this is not Satch) have comments like "How on Earth can he remember all those notes?" And he doesn't. It's not memorization: one can't create at this level by memorizing notes or rules. It's an understanding of the tool one uses and what one wants to create and the basic themes, and in this video it's also the synergy effect of four people doing that, creating together something they can't quite believe they're doing, so you have four madly grinning world class musicians -- and audience... :-) - Alf From python.list at tim.thechases.com Tue Feb 16 15:15:30 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Feb 2010 14:15:30 -0600 Subject: Parsing for email addresses In-Reply-To: <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <87aavac7u8.fsf@benfinney.id.au> <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> Message-ID: <4B7AFCE2.7080708@tim.thechases.com> galileo228 wrote: > [code] > fileHandle = open('/Users/Matt/Documents/python/results.txt','r') > names = fileHandle.readlines() > [/code] > > Now, the 'names' list has values looking like this: ['aaa12 at domain.com > \n', 'bbb34 at domain.com\n', etc]. So I ran the following code: > > [code] > for x in names: > st_list.append(x.replace('@domain.com\n','')) > [/code] > > And that did the trick! 'Names' now has ['aaa12', 'bbb34', etc]. > > Obviously this only worked because all of the domain names were the > same. If they were not then based on your comments and my own > research, I would've had to use regex and the split(), which looked > massively complicated to learn. The complexities stemmed from several factors that, with more details, could have made the solutions less daunting: (a) you mentioned "finding" the email addresses -- this makes it sound like there's other junk in the file that has to be sifted through to find "things that look like an email address". If the sole content of the file is lines containing only email addresses, then "find the email address" is a bit like [1] (b) you omitted the detail that the domains are all the same. Even if they're not the same, (a) reduces the problem to a much easier task: s = set() for line in file('results.txt'): s.add(line.rsplit('@', 1)[0].lower()) print s If it was previously a CSV or tab-delimited file, Python offers batteries-included processing to make it easy: import csv f = file('results.txt', 'rb') r = csv.DictReader(f) # CSV # r = csv.DictReader(f, delimiter='\t') # tab delim s = set() for row in r: s.add(row['Email'].lower()) f.close() or even f = file(...) r = csv.DictReader(...) s = set(row['Email'].lower() for row in r) f.close() Hope this gives you more ideas to work with. -tkc [1] http://jacksmix.files.wordpress.com/2007/05/findx.jpg From nad at acm.org Tue Feb 16 15:26:29 2010 From: nad at acm.org (Ned Deily) Date: Tue, 16 Feb 2010 12:26:29 -0800 Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 References: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> Message-ID: In article <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482 at r24g2000yqd.googlegroups.com>, seth wrote: > We have a code that creates a simple Python shelve database. We are > able to serialize objects and store them in the dbm file. This seem to > work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6, > but on Os X 10.5 with Python 2.5 the database filename is changed by > the operating system by attaching the .db extension to it. Does an one > know why is that? It's a documented "feature": it depends on the underlying database package used by shelve. http://docs.python.org/library/shelve.html "As a side-effect, an extension may be added to the filename ..." -- Ned Deily, nad at acm.org From ben+python at benfinney.id.au Tue Feb 16 15:30:42 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 17 Feb 2010 07:30:42 +1100 Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> Message-ID: <87sk90c499.fsf@benfinney.id.au> Lacrima writes: > And I have already refused to write totally isolated tests, because it > looks like a great waste of time. It only looks like that until you chase your tail in a long, fruitless debugging session because (you later realise) the behaviour of one test is being affected by another. Test isolation is essential to ensure that your tests are doing what you think they're doing. -- \ ?A ?No? uttered from deepest conviction is better and greater | `\ than a ?Yes? merely uttered to please, or what is worse, to | _o__) avoid trouble.? ?Mohandas K. Gandhi | Ben Finney From pecora at anvil.nrl.navy.mil Tue Feb 16 15:31:33 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Tue, 16 Feb 2010 15:31:33 -0500 Subject: A fix for pylab and TkAgg plotting in SAGE (Mac OS X) Message-ID: A few weeks ago I posted a problem with Mac OS X with matplotlib in the SAGE distribution in which attempting to import pylab gave an error message which stated that there was an import error and the module _tkagg could not be found. The problem appears to be with matplotlib (I'm not clear about this). After much searching and some emailing I have found a solution to this problem and it is easy to do. Full credit goes to Eric Sonnendrucker who sent it to me. Here it is: 1) Download the Tcl/Tk sources (go to http://www.tcl.tk/, click on Get Tcl/Tk Now, click on Sources Download Page,, download the latest version). 2) In the Terminal cd to the unix folder in the tcl folder. Compile the unix version (of Tcl and Tk) as follows ./configure --enable-framework --disable-xft make make install 3) Install SAGE from source. Download the SAGE source code (go to http://www.sagemath.org/, click on Download, click on Download complete source code). In the terminal cd to the SAGE folder and *before* you run the sage install you need to set SAGE_MATPLOTLIB_GUI=True using export SAGE_MATPLOTLIB_GUI=True with bash. The installer then picks it up automatically. Complete the SAGE installation by typing make and hit return. That's it. This will take a while (up to a few hours depending on the computer). 4) You might also need to modify you matplotlibrc by setting backend='TkAgg' after the installation Test this by doing an import pylab in sage. You should not get an error. -- -- Lou Pecora From debatem1 at gmail.com Tue Feb 16 16:12:51 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 16 Feb 2010 16:12:51 -0500 Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? In-Reply-To: References: Message-ID: Ok, I'll admit- my hand hovered over the 'initiate flamewar' button for a moment before I figured out what you were actually asking. And I know I'm working on it, which probably means 8 or 9 others are as well. Geremy Condra From wolftracks at invalid.com Tue Feb 16 16:23:48 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 13:23:48 -0800 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 Message-ID: I've finally decided to see if I could make an executable out of a py file. Win7. Py2.5. I brought down the install file and proceeded with the install. I got two warning messages. Forgot the first. The second said,"Could not set the key value." I again used OK. I think that was the only choice. It then issued a message in a larger dialog. It was about setting a key, and pointed me to a log. It mentions a Removepy2exe -u Although it finished, I have no idea where the program is. It does not show up on the Start menu All Programs List nore my desktop. What's up? I've had these messages (key) occur on other Python installs as I transition to Win7. So far no problem. From doron.tal.list at gmail.com Tue Feb 16 16:37:30 2010 From: doron.tal.list at gmail.com (Doron Tal) Date: Tue, 16 Feb 2010 23:37:30 +0200 Subject: GIL state during import Message-ID: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Is the GIL released during import statement execution when accessing the file? If not, is it a bug? If it is not a bug, or it is here to stay for any other reason, I think it should be mentioned in the documentation. --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From userprogoogle-139 at yahoo.co.uk Tue Feb 16 16:41:21 2010 From: userprogoogle-139 at yahoo.co.uk (rodmc) Date: Tue, 16 Feb 2010 13:41:21 -0800 (PST) Subject: Shipping Executables Message-ID: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Hi, I have been merrily programming away in Python now for a few years and have a couple of applications I would like to possibly publish at some point - with the exception of certain libraries they are more or less 100% Python. However I have read elsewhere online that Python due to it's architecture is not so good for this, especially as it is easier for people to hack into the code. Also where software requires some security aspects I guess it would also not be much use, is this correct? Anyway I would appreciate any views or tips that people have? Kind regards, rod From hklasky at gmail.com Tue Feb 16 17:03:55 2010 From: hklasky at gmail.com (seth) Date: Tue, 16 Feb 2010 14:03:55 -0800 (PST) Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 References: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> Message-ID: On Feb 14, 1:21 pm, a... at pythoncraft.com (Aahz) wrote: > Nope -- any reason you can't change the filename? > -- Os X 10.5 did not recognized the dbm extension. But, I have been able to fix the problem (hope it helps somebody): At http://docs.python.org/library/shelve.html it says: "shelve.open(filename[, flag='c'[, protocol=None[, writeback=False]]])? Open a persistent dictionary. The filename specified is the base filename for the underlying database. As a side-effect, an extension may be added to the filename and more than one file may be created. By default, the underlying database file is opened for reading and writing. " Then, I went ahead and try to find out which type of db file was being created: print whichdb.whichdb(dbmFile)#prints bsddb185 kpfmac:xLPR kpf$ python Python 2.5.1 (r251:54863, Feb 9 2009, 18:49:36) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import bsddb185 >>> bsddb185.open('realizations.db') I found that the dbm extension is generated by bsddb and bsddb3 so I went ahead and installed it: sudo easy_install bsddb3. Finally, in our code, I just went ahead and instead of using shelve.open, I am calling shelve.BsdDbShelf(bsddb3.btopen(filename, 'c')) #realizations=shelve.open( filename, 'c', 2, writeback = False ) #hk 021010: need to use BsdDbShelf to ensure the usage of bsddb3 on OsX 10.5 #shelve.open creates a bsddb185 file on OsX 10.5 #but shelve.open on OsX reads with bsddb3, who knows why... #as a result the shelve.open throws # (22, 'Invalid argument') dbshelf=shelve.BsdDbShelf(bsddb3.btopen(filename, 'c')) realizations=dbshelf And that fixed on Os X 10.5. It also works fine on Windows, by ensuring the proper import: try: import bsddb3 except: import bsddb as bsddb3 From arnodel at googlemail.com Tue Feb 16 17:21:06 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 22:21:06 +0000 Subject: Is there a simple way to find the list index to the max value? References: <4B7A91B1.6030301@lonetwin.net> Message-ID: aahz at pythoncraft.com (Aahz) writes: > In article <4B7A91B1.6030301 at lonetwin.net>, steve wrote: >>On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >>The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disadvantage of that is that it's O(2N) instead of O(N). :-) Joke aside, even though you traverse the list twice, it may still be quicker than other solutions because both max and list.index are C functions and no intermediate object is constructed. -- Arnaud From debatem1 at gmail.com Tue Feb 16 17:25:53 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 16 Feb 2010 17:25:53 -0500 Subject: Shipping Executables In-Reply-To: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: On Tue, Feb 16, 2010 at 4:41 PM, rodmc wrote: > Hi, > > I have been merrily programming away in Python now for a few years and > have a couple of applications I would like to possibly publish at some > point - with the exception of certain libraries they are more or less > 100% Python. However I have read elsewhere online that Python due to > it's architecture is not so good for this, especially as it is easier > for people to hack into the code. If you mean that it is difficult to stop people from modifying the source code, then you're correct. If you mean that python programs are more likely to have security problems than, say, C, I think its safe to assume that you're not correct about that. > Also where software requires some > security aspects I guess it would also not be much use, is this > correct? I've never had any reason to feel more concerned about the code that I write in python, and I use it for crypto research. > Anyway I would appreciate any views or tips that people have? I'd worry about developing a product worth stealing before I worried about people stealing it ;) Geremy Condra From phlip2005 at gmail.com Tue Feb 16 17:50:10 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Feb 2010 14:50:10 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: <35d8fe79-4f3f-4742-ba0f-66e3b5a4c7bd@t17g2000prg.googlegroups.com> On Feb 16, 12:30?pm, Ben Finney wrote: > Lacrima writes: > > And I have already refused to write totally isolated tests, because it > > looks like a great waste of time. > > It only looks like that until you chase your tail in a long, fruitless > debugging session because (you later realise) the behaviour of one test > is being affected by another. Test isolation is essential to ensure that > your tests are doing what you think they're doing. That is runtime test isolation. It's not the same thing as "unit test isolation". Just take care in your tearDown() to scrub your environment. Google "Mock abuse" from here... -- Phlip From tjreedy at udel.edu Tue Feb 16 17:57:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Feb 2010 17:57:28 -0500 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: On 2/16/2010 3:15 PM, John Nagle wrote: > In the beginning, Python had some types which were "frozen", > and some which weren't. In the beginning, there was only one 'frozen' general purpose collection type, the tuple. And Guido resisted the suggestion that lists and tuple were mutable and frozen versions of each other. However, things have changed, and lists and tuple *are* effectively mutable and hashable versions of each other, and we have the three other pairs you mentioned. The idea of freeze() may have been floated (and punctured) during Py3 discussions, but I think it a fairly good one. Terry Jan Reedy From tjreedy at udel.edu Tue Feb 16 18:01:08 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Feb 2010 18:01:08 -0500 Subject: GIL state during import In-Reply-To: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Message-ID: On 2/16/2010 4:37 PM, Doron Tal wrote: > Is the GIL released during import statement execution when accessing the > file? > If not, is it a bug? > If it is not a bug, or it is here to stay for any other reason, I think > it should be mentioned in the documentation. The CPython GIL is a CPython implementation artifact and should not be mentioned in the language docs (and is not, as far as I know). Were you thinking of something else? And why this specific feature of its behavior, whatever it is. tjr From steve at REMOVE-THIS-cybersource.com.au Tue Feb 16 18:19:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Feb 2010 23:19:03 GMT Subject: ANN: obfuscate 0.2.2b Message-ID: <4b7b27e7$0$8819$c3e8da3@news.astraweb.com> I am pleased to announce the beta release of obfuscate 0.2.2b. http://pypi.python.org/pypi/obfuscate/ The beta release does not contain any new functionality from the previous version, but includes bug fixes and many new tests. obfuscate is a pure-Python module providing classical encryption algorithms suitable for obfuscating and unobfuscating text. obfuscate includes the following ciphers: - Caesar, rot13, rot5, rot18, rot47 - atbash - Playfair, Playfair6 and Playfair16 - Railfence (encryption only) - Keyword - Affine - Vigenere - frob (xor) and others. DISCLAIMER: obfuscate is not cryptographically strong, and should not be used where high security is required. (The ciphers provided in obfuscate may have been state of the art centuries ago, but should not be used where strong encryption is required. obfuscate is released under the MIT licence. Requires Python 2.5 or 2.6. From db3l.net at gmail.com Tue Feb 16 18:34:13 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 16 Feb 2010 18:34:13 -0500 Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: alex23 writes: > News123 wrote: >> What is the best way with python to get a list of all windows services. >> >> As a start I would be glad to receive only the service names. >> >> However it would be nicer if I could get all the properties of a service >> as well. > > I highly recommend Tim Golden's fantastic WMI module[1]. Another alternative is the win32service module from the pywin32 package (which IMO you'll almost certainly want available when doing any significant Windows-specific operations) which wraps the native win32 libraries for enumerating, querying and controlling services. A simple loop could use EnumServicesStatus to iterate through the services, OpenService with the SERVICE_QUERY_CONFIG flag to get a handle to each service, and then QueryServiceConfig to retrieve configuration information. Since pywin32 is a relatively thin wrapper over the win32 libraries, pure MSDN documentation can be used for help with the calls, augmented by any Python-related information contained in the pywin32 documentation. -- David From xiajunyi at gmail.com Tue Feb 16 18:48:17 2010 From: xiajunyi at gmail.com (Imaginationworks) Date: Tue, 16 Feb 2010 15:48:17 -0800 (PST) Subject: How to efficiently extract information from structured text file Message-ID: Hi, I am trying to read object information from a text file (approx. 30,000 lines) with the following format, each line corresponds to a line in the text file. Currently, the whole file was read into a string list using readlines(), then use for loop to search the "= {" and "};" to determine the Object, SubObject,and SubSubObject. My questions are 1) Is there any efficient method that I can search the whole string list to find the location of the tokens(such as '= {' or '};' 2) Is there any efficient ways to extract the object information you may suggest? Thanks, - Jeremy ===== Structured text file ================= Object1 = { ... SubObject1 = { .... SubSubObject1 = { ... }; }; SubObject2 = { .... SubSubObject21 = { ... }; }; SubObjectN = { .... SubSubObjectN = { ... }; }; }; From mattbarkan at gmail.com Tue Feb 16 19:07:57 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 16:07:57 -0800 (PST) Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <87aavac7u8.fsf@benfinney.id.au> <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> Message-ID: <814bb446-6fe5-42cb-9033-c330e74f6123@b7g2000yqd.googlegroups.com> Tim - Thanks for this. I actually did intend to have to sift through other junk in the file, but then figured I could just cut and paste emails directly from the 'to' field, thus making life easier. Also, in this particular instance, the domain names were the same, and thus I was able to figure out my solution, but I do need to know how to handle the same situation when the domain names are different, so your response was most helpful. Apologies for leaving out some details. Matt On Feb 16, 3:15?pm, Tim Chase wrote: > galileo228 wrote: > > [code] > > fileHandle = open('/Users/Matt/Documents/python/results.txt','r') > > names = fileHandle.readlines() > > [/code] > > > Now, the 'names' list has values looking like this: ['aa... at domain.com > > \n', 'bb... at domain.com\n', etc]. So I ran the following code: > > > [code] > > for x in names: > > ? ? st_list.append(x.replace('... at domain.com\n','')) > > [/code] > > > And that did the trick! 'Names' now has ['aaa12', 'bbb34', etc]. > > > Obviously this only worked because all of the domain names were the > > same. If they were not then based on your comments and my own > > research, I would've had to use regex and the split(), which looked > > massively complicated to learn. > > The complexities stemmed from several factors that, with more > details, could have made the solutions less daunting: > > ? ?(a) you mentioned "finding" the email addresses -- this makes > it sound like there's other junk in the file that has to be > sifted through to find "things that look like an email address". > If the sole content of the file is lines containing only email > addresses, then "find the email address" is a bit like [1] > > ? ?(b) you omitted the detail that the domains are all the same. > ? Even if they're not the same, (a) reduces the problem to a much > easier task: > > ? ?s = set() > ? ?for line in file('results.txt'): > ? ? ?s.add(line.rsplit('@', 1)[0].lower()) > ? ?print s > > If it was previously a CSV or tab-delimited file, Python offers > batteries-included processing to make it easy: > > ? ?import csv > ? ?f = file('results.txt', 'rb') > ? ?r = csv.DictReader(f) ?# CSV > ? ?# r = csv.DictReader(f, delimiter='\t') # tab delim > ? ?s = set() > ? ?for row in r: > ? ? ?s.add(row['Email'].lower()) > ? ?f.close() > > or even > > ? ?f = file(...) > ? ?r = csv.DictReader(...) > ? ?s = set(row['Email'].lower() for row in r) > ? ?f.close() > > Hope this gives you more ideas to work with. > > -tkc > > [1]http://jacksmix.files.wordpress.com/2007/05/findx.jpg From jgardner at jonathangardner.net Tue Feb 16 19:19:07 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 16 Feb 2010 16:19:07 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> On Feb 16, 11:41?am, Andrej Mitrovic wrote: > On Feb 16, 7:38?pm, Casey Hawthorne > wrote: > > > Interesting talk on Python vs. Ruby and how he would like Python to > > have just a bit more syntactic flexibility. > > >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > > -- > > Regards, > > Casey > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > linked to): "Python has no comparable equivalent to Ruby?s do end > block. Python lambdas are limited to one line and can?t contain > statements (for, if, def, etc.). Which leaves me wondering, what?s the > point?" > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > expressions, not statements, but you can pass them around, keep them > in a dictionary if you want to. And if you need more than one line of > statements, for crying out loud use a def? And who needs those "do- > end" blocks anyway, trying to turn Python into Pascal? I used to think anonymous functions (AKA blocks, etc...) would be a nice feature for Python. Then I looked at a stack trace from a different programming language with lots of anonymous functions. (I believe it was perl.) I became enlightened. From philip at semanchuk.com Tue Feb 16 19:22:40 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Feb 2010 19:22:40 -0500 Subject: Shipping Executables In-Reply-To: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> On Feb 16, 2010, at 4:41 PM, rodmc wrote: > Hi, > > I have been merrily programming away in Python now for a few years and > have a couple of applications I would like to possibly publish at some > point - with the exception of certain libraries they are more or less > 100% Python. However I have read elsewhere online that Python due to > it's architecture is not so good for this, especially as it is easier > for people to hack into the code. Also where software requires some > security aspects I guess it would also not be much use, is this > correct? Hi Rod, The user's ability to hack into the code is usually considered one of the strengths of Python & open source software in general. Since most Python software that's distributed is open source, you're doing something different than most. It'd help if you explain how you want your software to differ from a typical open source distribution. Do you not want people to change the code? Are you worried about your code & ideas being stolen? bye Philip From rhodri at wildebst.demon.co.uk Tue Feb 16 19:29:44 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 17 Feb 2010 00:29:44 -0000 Subject: How to efficiently extract information from structured text file References: Message-ID: On Tue, 16 Feb 2010 23:48:17 -0000, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. My > questions are > > 1) Is there any efficient method that I can search the whole string > list to find the location of the tokens(such as '= {' or '};' The usual idiom is to process a line at a time, which avoids the memory overhead of reading the entire file in, creating the list, and so on. Assuming your input file is laid out as neatly as you said, that's straightforward to do: for line in myfile: if "= {" in line: start_a_new_object(line) elif "};" in line: end_current_object(line) else: add_stuff_to_current_object(line) You probably want more robust tests than I used there, but that depends on how well-defined your input file is. If it can be edited by hand, you'll need to be more defensive! > 2) Is there any efficient ways to extract the object information you > may suggest? That depends on what you mean by "extract the object information". If you mean "get the object name", just split the line at the "=" and strip off the whitespace you don't want. If you mean "track how objects are connected to one another, have each object keep a list of its immediate sub-objects (which will have lists of their immediate sub-objects, and so on); it's fairly easy to keep track of which objects are current using a list as a stack. If you mean something else, sorry but my crystal ball is cloudy tonight. -- Rhodri James *-* Wildebeeste Herder to the Masses From dyamins at gmail.com Tue Feb 16 19:29:55 2010 From: dyamins at gmail.com (Dan Yamins) Date: Tue, 16 Feb 2010 19:29:55 -0500 Subject: Wrap and intercept function calls Message-ID: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> Hi: I'm wondering what the best way to wrap and modify function calls is. Essentially what I want to achieve is to have a function like this: def Wrap(frame,event,arg): if event == 'call': result = PerformCheck(GetArgumentsFromFrame(frame)) if Condition(result): return result else: return [normal function call] called whenever a "call" event is about to occur. When I say "return result" I mean: return that data object instead of what the function would have returned, and prevent execution of the function. Is there any way to do this using sys.settrace? Or perhaps something from the bdb or pbd module? Thanks! Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattbarkan at gmail.com Tue Feb 16 19:31:35 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 16:31:35 -0800 (PST) Subject: Download unnamed web image? Message-ID: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> All, My python program signs onto the student facebook at my school and, given email addresses, returns the associated full name. If I were to do this through a regular browser, there is also a picture of the individual, and I am trying to get my program to download the picture as well. The problem: the html code of the page does not point to a particular file, but rather refers to (what seems like) a query. So, if one went to the facebook and searched for me using my school net id (msb83), the image of my profile on the results page is: msb83 Using BeautifulSoup, mechanize, and urllib, I've constructed the following: br.open("http://www.school.edu/students/facebook/") br.select_form(nr = 1) br.form['fulltextsearch'] = 'msb83' # this searches the facebook for me br.submit() results = br.response().read() soup = BeautifulSoup(results) foo2 = soup.find('td', attrs={'width':'95'}) foo3 = foo2.find('a') foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) # this just drills down to the line and until this point the program does not return an error save_as = os.path.join('./', msb83 + '.jpg') urllib.urlretrieve(foo4, save_as) I get the following error msg after running this code: AttributeError: 'NoneType' object has no attribute 'strip' I can download the picture through my browser by right-clicking, selecting save as, and then the image gets saved as 'deliverImage.cfm.jpeg.' Are there any suggestions as to how I might be able to download the image using python? Please let me know if more information is needed -- happy to supply it. Matt From aahz at pythoncraft.com Tue Feb 16 19:56:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Feb 2010 16:56:11 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: In article <8ca440b2-6094-4b35-80c5-81d000517ce0 at v20g2000prb.googlegroups.com>, Jonathan Gardner wrote: > >I used to think anonymous functions (AKA blocks, etc...) would be a >nice feature for Python. > >Then I looked at a stack trace from a different programming language >with lots of anonymous functions. (I believe it was perl.) > >I became enlightened. +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From gherron at islandtraining.com Tue Feb 16 20:14:43 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Feb 2010 17:14:43 -0800 Subject: How to efficiently extract information from structured text file In-Reply-To: References: Message-ID: <4B7B4303.2000301@islandtraining.com> Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. My > questions are > > 1) Is there any efficient method that I can search the whole string > list to find the location of the tokens(such as '= {' or '};' > Yes. Read the *whole* file into a single string using file.read() method, and then search through the string using string methods (for simple things) or use re, the regular expression module, (for more complex searches). Note: There is a point where a file becomes large enough that reading the whole file into memory at once (either as a single string or as a list of strings) is foolish. However, 30,000 lines doesn't push that boundary. > 2) Is there any efficient ways to extract the object information you > may suggest? > Again, the re module has nice ways to find a pattern, and return parse out pieces of it. Building a good regular expression takes time, experience, and a bit of black magic... To do so for this case, we might need more knowledge of your format. Also regular expressions have their limits. For instance, if the sub objects can nest to any level, then in fact, regular expressions alone can't solve the whole problem, and you'll need a more robust parser. > Thanks, > > - Jeremy > > > > ===== Structured text file ================= > Object1 = { > > ... > > SubObject1 = { > .... > > SubSubObject1 = { > ... > }; > }; > > SubObject2 = { > .... > > SubSubObject21 = { > ... > }; > }; > > SubObjectN = { > .... > > SubSubObjectN = { > ... > }; > }; > }; > From john at castleamber.com Tue Feb 16 20:48:11 2010 From: john at castleamber.com (John Bokma) Date: Tue, 16 Feb 2010 19:48:11 -0600 Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> Message-ID: <87vddw3a5g.fsf@castleamber.com> galileo228 writes: > Using BeautifulSoup, mechanize, and urllib, I've constructed the > following: > > br.open("http://www.school.edu/students/facebook/") > br.select_form(nr = 1) > > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for > me > br.submit() > results = br.response().read() > soup = BeautifulSoup(results) > foo2 = soup.find('td', attrs={'width':'95'}) > foo3 = foo2.find('a') > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) > # this just drills down to the line and until this point the > program does not return an error > > save_as = os.path.join('./', msb83 + '.jpg') > urllib.urlretrieve(foo4, save_as) > > I get the following error msg after running this code: > > AttributeError: 'NoneType' object has no attribute 'strip' Wild guess, since you didn't provide line numbers, etc. foo4 is None (I also would like to suggest to use more meaningful names) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From pavlovevidence at gmail.com Tue Feb 16 21:04:40 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 16 Feb 2010 18:04:40 -0800 (PST) Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? References: Message-ID: <009d33cc-75da-4afe-9715-31e820ddc54e@y7g2000prc.googlegroups.com> On Feb 16, 10:32?am, Casey Hawthorne wrote: > Hubris connects Ruby to Haskell, will there be such a connection > between Python and Haskell? I would have expected Hubris to link Ada and Common Lisp together. Carl Banks From steven at REMOVE.THIS.cybersource.com.au Tue Feb 16 21:11:15 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Feb 2010 02:11:15 GMT Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: On Tue, 16 Feb 2010 13:41:21 -0800, rodmc wrote: > Hi, > > I have been merrily programming away in Python now for a few years and > have a couple of applications I would like to possibly publish at some > point - with the exception of certain libraries they are more or less > 100% Python. However I have read elsewhere online that Python due to > it's architecture is not so good for this, especially as it is easier > for people to hack into the code. Looks like you are looking to apply the philosophy "No user serviceable parts inside". > Also where software requires some > security aspects I guess it would also not be much use, is this correct? Absolutely 100% wrong. It is an fundamental principle of security that you must not assume that the enemy is ignorant of your procedures. "Security by obscurity" is not security at all. See, for example: http://en.wikipedia.org/wiki/Kerckhoffs'_Principle If you are trusting that your software will be secure because people cannot read the source code, you have already failed. Hackers break into computer systems without the source code as a matter of course: allowing the source to be available generally makes so little difference as to be no difference. Worse, keeping the source code secret *as a security measure* lulls people into a false sense of security, letting them use weak security confident that since nobody knows how weak it is, it will be strong. That's not how it works. If you have other reasons for wanting to keep the source code secret, that's one thing. But doing it because it is more secure is foolish: software simply isn't more secure when supplied as a binary instead of source code. > Anyway I would appreciate any views or tips that people have? Don't worry about it. If your application is secure, it will be secure even if everybody knows how it works. If it's not secure, then the bad guys will learn how it works even without the source code. -- Steven From mattbarkan at gmail.com Tue Feb 16 21:40:11 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 18:40:11 -0800 (PST) Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> Message-ID: <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> On Feb 16, 8:48?pm, John Bokma wrote: > galileo228 writes: > > Using BeautifulSoup, mechanize, and urllib, I've constructed the > > following: > > > br.open("http://www.school.edu/students/facebook/") > > br.select_form(nr = 1) > > > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for > > me > > br.submit() > > results = br.response().read() > > soup = BeautifulSoup(results) > > foo2 = soup.find('td', attrs={'width':'95'}) > > foo3 = foo2.find('a') > > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) > > # this just drills down to the line and ? until this point the > > program does not return an error > > > save_as = os.path.join('./', msb83 + '.jpg') > > urllib.urlretrieve(foo4, save_as)> > > I get the following error msg after running this code: > > > AttributeError: 'NoneType' object has no attribute 'strip' > > Wild guess, since you didn't provide line numbers, etc. > > foo4 is None > > (I also would like to suggest to use more meaningful names) > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b I thought it was too, and I just doublechecked. It's actually foo3 = foo2.find('a') that is causing the NoneType error. Thoughts? From mattbarkan at gmail.com Tue Feb 16 21:54:58 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 18:54:58 -0800 (PST) Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> Message-ID: On Feb 16, 9:40?pm, galileo228 wrote: > On Feb 16, 8:48?pm, John Bokma wrote: > > > > > galileo228 writes: > > > Using BeautifulSoup, mechanize, and urllib, I've constructed the > > > following: > > > > br.open("http://www.school.edu/students/facebook/") > > > br.select_form(nr = 1) > > > > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for > > > me > > > br.submit() > > > results = br.response().read() > > > soup = BeautifulSoup(results) > > > foo2 = soup.find('td', attrs={'width':'95'}) > > > foo3 = foo2.find('a') > > > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) > > > # this just drills down to the line and ? until this point the > > > program does not return an error > > > > save_as = os.path.join('./', msb83 + '.jpg') > > > urllib.urlretrieve(foo4, save_as)> > > > I get the following error msg after running this code: > > > > AttributeError: 'NoneType' object has no attribute 'strip' > > > Wild guess, since you didn't provide line numbers, etc. > > > foo4 is None > > > (I also would like to suggest to use more meaningful names) > > > -- > > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > I thought it was too, and I just doublechecked. ?It's actually > > foo3 = foo2.find('a') > > that is causing the NoneType error. > > Thoughts? I've now fixed the foo3 issue, and I now know that the problem is with the urllib.urlretrieve line (see above). This is the error msg I get in IDLE: Traceback (most recent call last): File "/Users/Matt/Documents/python/dtest.py", line 59, in urllib.urlretrieve(foo4, save_as) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/urllib.py", line 94, in urlretrieve return _urlopener.retrieve(url, filename, reporthook, data) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/urllib.py", line 226, in retrieve url = unwrap(toBytes(url)) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/urllib.py", line 1033, in unwrap url = url.strip() TypeError: 'NoneType' object is not callable Is this msg being generated because I'm trying to retrieve a url that's not really a file? From cournape at gmail.com Tue Feb 16 22:04:33 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 17 Feb 2010 12:04:33 +0900 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <5b8d13221002161904s55697ceay6c943e2022f81156@mail.gmail.com> On Wed, Feb 17, 2010 at 4:41 AM, Andrej Mitrovic wrote: > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > linked to): "Python has no comparable equivalent to Ruby?s do end > block. Python lambdas are limited to one line and can?t contain > statements (for, if, def, etc.). Which leaves me wondering, what?s the > point?" > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > expressions, not statements, but you can pass them around, keep them > in a dictionary if you want to. And if you need more than one line of > statements, for crying out loud use a def? I think that's a bit of a strawman: the point made by the OP is that it enables writing simple DSL easier, and the ruby's community seems to value this. They are not advocating using anonymous functions where "normal" functions would do. cheers, David From john at castleamber.com Tue Feb 16 22:11:24 2010 From: john at castleamber.com (John Bokma) Date: Tue, 16 Feb 2010 21:11:24 -0600 Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> Message-ID: <877hqck143.fsf@castleamber.com> galileo228 writes: > On Feb 16, 9:40?pm, galileo228 wrote: [...] > I've now fixed the foo3 issue, and I now know that the problem is with > the urllib.urlretrieve line (see above). This is the error msg I get > in IDLE: > > Traceback (most recent call last): > File "/Users/Matt/Documents/python/dtest.py", line 59, in > urllib.urlretrieve(foo4, save_as) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 94, in urlretrieve > return _urlopener.retrieve(url, filename, reporthook, data) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 226, in retrieve > url = unwrap(toBytes(url)) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 1033, in unwrap > url = url.strip() > TypeError: 'NoneType' object is not callable > > Is this msg being generated because I'm trying to retrieve a url > that's not really a file? --8<---------------cut here---------------start------------->8--- >>> import urllib; >>> urllib.urlretrieve(None) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/urllib.py", line 89, in urlretrieve return _urlopener.retrieve(url, filename, reporthook, data) File "/usr/lib/python2.5/urllib.py", line 210, in retrieve url = unwrap(toBytes(url)) File "/usr/lib/python2.5/urllib.py", line 1009, in unwrap url = url.strip() AttributeError: 'NoneType' object has no attribute 'strip' --8<---------------cut here---------------end--------------->8--- To me it looks like you're still calling urlretrieve with None as a first value. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mrabarnett at mrabarnett.plus.com Tue Feb 16 22:14:33 2010 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Wed, 17 Feb 2010 03:14:33 +0000 Subject: Download unnamed web image? In-Reply-To: References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> Message-ID: <4B7B5F19.8010705@mrabarnett.plus.com> galileo228 wrote: > On Feb 16, 9:40 pm, galileo228 wrote: >> On Feb 16, 8:48 pm, John Bokma wrote: >> >> >> >>> galileo228 writes: >>>> Using BeautifulSoup, mechanize, and urllib, I've constructed the >>>> following: >>>> br.open("http://www.school.edu/students/facebook/") >>>> br.select_form(nr = 1) >>>> br.form['fulltextsearch'] = 'msb83' # this searches the facebook for >>>> me >>>> br.submit() >>>> results = br.response().read() >>>> soup = BeautifulSoup(results) >>>> foo2 = soup.find('td', attrs={'width':'95'}) >>>> foo3 = foo2.find('a') >>>> foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) >>>> # this just drills down to the line and until this point the >>>> program does not return an error >>>> save_as = os.path.join('./', msb83 + '.jpg') >>>> urllib.urlretrieve(foo4, save_as)> >>>> I get the following error msg after running this code: >>>> AttributeError: 'NoneType' object has no attribute 'strip' >>> Wild guess, since you didn't provide line numbers, etc. >>> foo4 is None >>> (I also would like to suggest to use more meaningful names) >>> -- >>> John Bokma j3b >> I thought it was too, and I just doublechecked. It's actually >> >> foo3 = foo2.find('a') >> >> that is causing the NoneType error. >> >> Thoughts? > > I've now fixed the foo3 issue, and I now know that the problem is with > the urllib.urlretrieve line (see above). This is the error msg I get > in IDLE: > > Traceback (most recent call last): > File "/Users/Matt/Documents/python/dtest.py", line 59, in > urllib.urlretrieve(foo4, save_as) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 94, in urlretrieve > return _urlopener.retrieve(url, filename, reporthook, data) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 226, in retrieve > url = unwrap(toBytes(url)) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 1033, in unwrap > url = url.strip() > TypeError: 'NoneType' object is not callable > > Is this msg being generated because I'm trying to retrieve a url > that's not really a file? It's because the URL you're passing in, namely foo4, is None. This is presumably because foo3.find() returns None if it can't find the entry. You checked the value of foo3, but did you check the value of foo4? From tomf.sessile at gmail.com Tue Feb 16 23:44:09 2010 From: tomf.sessile at gmail.com (TomF) Date: Tue, 16 Feb 2010 20:44:09 -0800 Subject: Is there a simple way to find the list index to the max value? References: <4B7A91B1.6030301@lonetwin.net> Message-ID: <2010021620440950073-tomfsessile@gmailcom> On 2010-02-16 11:44:45 -0800, aahz at pythoncraft.com (Aahz) said: > In article <4B7A91B1.6030301 at lonetwin.net>, steve wrote: >> On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >> The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disadvantage of that is that it's O(2N) instead of O(N). I don't think you understand order notation. There's no such thing as O(2N). To answer the original question, how about: max(enumerate(l), key=lambda x: x[1])[0] As to whether this is faster than index(max()), you'd have to time it. -Tom From nagle at animats.com Wed Feb 17 00:09:27 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Feb 2010 21:09:27 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Terry Reedy wrote: > On 2/16/2010 3:15 PM, John Nagle wrote: >> In the beginning, Python had some types which were "frozen", > > and some which weren't. > > In the beginning, there was only one 'frozen' general purpose collection > type, the tuple. And Guido resisted the suggestion that lists and tuple > were mutable and frozen versions of each other. > > However, things have changed, and lists and tuple *are* effectively > mutable and hashable versions of each other, and we have the three other > pairs you mentioned. The idea of freeze() may have been floated (and > punctured) during Py3 discussions, but I think it a fairly good one. Yes, we're now at the point where all the built-in mutable types have "frozen" versions. But we don't have that for objects. It's generally considered a good thing in language design to offer, for user defined types, most of the functionality of built-in ones. It's the concurrency aspect of this that interests me, though. A language with immutable objects can potentially handle concurrency more safely than one where everything is potentially mutable. The language knows what can't change, which simplifies locking. John Nagle From no.email at nospam.invalid Wed Feb 17 00:52:04 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 16 Feb 2010 21:52:04 -0800 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Message-ID: <7xpr44pfy3.fsf@ruckus.brouhaha.com> John Nagle writes: >> However, things have changed, and lists and tuple *are* effectively >> mutable and hashable versions of each other... > It's the concurrency aspect of this that interests me, though. > A language with immutable objects can potentially handle concurrency > more safely than one where everything is potentially mutable. > The language knows what can't change, which simplifies locking. I wonder how well that applies to tuples containing mutable objects, e.g. t = ([1,2], [3,4]) From banibrata.dutta at gmail.com Wed Feb 17 01:10:42 2010 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Wed, 17 Feb 2010 11:40:42 +0530 Subject: Shipping Executables In-Reply-To: References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> On Wed, Feb 17, 2010 at 7:41 AM, Steven D'Aprano < steven at remove.this.cybersource.com.au> wrote: > > security aspects I guess it would also not be much use, is this correct? > > Absolutely 100% wrong. It is an fundamental principle of security that > you must not assume that the enemy is ignorant of your procedures. > "Security by obscurity" is not security at all. > > See, for example: > > http://en.wikipedia.org/wiki/Kerckhoffs'_Principle > > I believe, the use of work 'security' wasn't the best choice to describe the need, if I understand the original poster's intentions. The intentions of original poster were "intellectual property protection", where-in they have indeed created something worth stealing, and would like to put it under lock-n-key. For that purpose, I do not think Python is the right choice. BTW for people who are non-believers in something being worth stealing needing protection, need to read about the Skype client. -- regards, Banibrata http://www.linkedin.com/in/bdutta http://twitter.com/edgeliving -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Wed Feb 17 01:17:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 17 Feb 2010 07:17:25 +0100 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <7xpr44pfy3.fsf@ruckus.brouhaha.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> <7xpr44pfy3.fsf@ruckus.brouhaha.com> Message-ID: * Paul Rubin: > John Nagle writes: >>> However, things have changed, and lists and tuple *are* effectively >>> mutable and hashable versions of each other... >> It's the concurrency aspect of this that interests me, though. >> A language with immutable objects can potentially handle concurrency >> more safely than one where everything is potentially mutable. >> The language knows what can't change, which simplifies locking. > > I wonder how well that applies to tuples containing mutable objects, > e.g. t = ([1,2], [3,4]) One would need a collection type that's immutable "all the way". Current frozen types don't have that. However, there's also the question of the immutability of what names refer to. It seems to me that this means that the compiler can't really assume very much without very deep analysis. And so, if it boils down to the programmer applying assumptions about mutability/constantness, then types may not be The Answer. Cheers, - Alf From debatem1 at gmail.com Wed Feb 17 02:00:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 17 Feb 2010 02:00:59 -0500 Subject: Shipping Executables In-Reply-To: <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> Message-ID: On Wed, Feb 17, 2010 at 1:10 AM, Banibrata Dutta wrote: > > > On Wed, Feb 17, 2010 at 7:41 AM, Steven D'Aprano > wrote: >> >> > security aspects I guess it would also not be much use, is this correct? >> Absolutely 100% wrong. It is an fundamental principle of security that >> you must not assume that the enemy is ignorant of your procedures. >> "Security by obscurity" is not security at all. >> >> See, for example: >> >> http://en.wikipedia.org/wiki/Kerckhoffs'_Principle >> > I believe, the use of work 'security' wasn't the best choice to describe the > need, if I understand the original poster's intentions. The intentions of > original poster were "intellectual property protection", Which has little to do with the language in question. > where-in they have > indeed created something worth stealing, and would like to put it under > lock-n-key. For that purpose, I do not think Python is the right choice. Why? > BTW for people who are non-believers in something being worth stealing > needing protection, need to read about the Skype client. Most of the people I know who were interested in REing skype were a lot more interested in either interoperating with the protocol or ensuring that skype wasn't deliberately including malware or a backdoor. In any even I don't see this having anything to do with Python. Geremy Condra From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 02:35:49 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Feb 2010 07:35:49 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Message-ID: On Tue, 16 Feb 2010 21:09:27 -0800, John Nagle wrote: > Yes, we're now at the point where all the built-in mutable types > have "frozen" versions. But we don't have that for objects. It's > generally considered a good thing in language design to offer, for user > defined types, most of the functionality of built-in ones. It's not hard to build immutable user-defined types. Whether they're immutable enough is another story :) >>> class FrozenMeta(type): ... def __new__(meta, classname, bases, classDict): ... def __setattr__(*args): ... raise TypeError("can't change immutable class") ... classDict['__setattr__'] = __setattr__ ... classDict['__delattr__'] = __setattr__ ... return type.__new__(meta, classname, bases, classDict) ... >>> >>> class Thingy(object): ... __metaclass__ = FrozenMeta ... def __init__(self, x): ... self.__dict__['x'] = x ... >>> >>> >>> t = Thingy(45) >>> t.x 45 >>> t.x = 42 Traceback (most recent call last): File "", line 1, in File "", line 4, in __setattr__ TypeError: can't change immutable class It's a bit ad hoc, but it seems to work for me. Unfortunately there's no way to change __dict__ to a "write once, read many" dict. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 02:36:08 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Feb 2010 07:36:08 GMT Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> Message-ID: On Wed, 17 Feb 2010 02:00:59 -0500, geremy condra quoted Banibrata Dutta : >> BTW for people who are non-believers in something being worth stealing >> needing protection, need to read about the Skype client. Pardon me for breaking threading, but the original post has not come through to my provider, only the reply from Geremy. Many things are worth stealing and therefore need protection. In any case, reverse engineering software is not theft. And even if it were, keeping the source code secret is no barrier to a competent, determined attacker or investigator. Skype is a good example: despite the lack of source code and the secret protocol, analysts were able to discover that TOM-Skype sends personally identifiable information, encryption keys and private messages back to central servers. In my personal opinion, releasing closed source software is prima facie evidence that the software is or does something bad: leaking personal information, infringing somebody else's copyright or patent, or just being badly written. I'm not saying that every piece of closed source software is like that, but when you hide the source, the burden of proof is on you to prove that you're not hiding something unpleasant. -- Steven From steve at holdenweb.com Wed Feb 17 02:38:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Feb 2010 02:38:30 -0500 Subject: Shipping Executables In-Reply-To: References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: geremy condra wrote: [...] > I'd worry about developing a product worth stealing before I > worried about people stealing it ;) > > Geremy Condra +1 FAQ entry! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 17 02:39:43 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Feb 2010 02:39:43 -0500 Subject: Shipping Executables In-Reply-To: <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> Message-ID: Philip Semanchuk wrote: > > On Feb 16, 2010, at 4:41 PM, rodmc wrote: > >> Hi, >> >> I have been merrily programming away in Python now for a few years and >> have a couple of applications I would like to possibly publish at some >> point - with the exception of certain libraries they are more or less >> 100% Python. However I have read elsewhere online that Python due to >> it's architecture is not so good for this, especially as it is easier >> for people to hack into the code. Also where software requires some >> security aspects I guess it would also not be much use, is this >> correct? > > > Hi Rod, > The user's ability to hack into the code is usually considered one of > the strengths of Python & open source software in general. Since most > Python software that's distributed is open source, you're doing > something different than most. It'd help if you explain how you want > your software to differ from a typical open source distribution. Do you > not want people to change the code? Are you worried about your code & > ideas being stolen? > Do remember, though, that the Python license absolutely allows you to create both open source and proprietary products as you choose. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ldo at geek-central.gen.new_zealand Wed Feb 17 03:02:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Feb 2010 21:02:13 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: In message <60b1abce-4381-46ab-91ed- f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: > Also, lambda's are expressions, not statements ... Is such a distinction Pythonic, or not? For example, does Python distinguish between functions and procedures? From ldo at geek-central.gen.new_zealand Wed Feb 17 03:02:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Feb 2010 21:02:56 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: In message <8ca440b2-6094-4b35-80c5-81d000517ce0 at v20g2000prb.googlegroups.com>, Jonathan Gardner wrote: > I used to think anonymous functions (AKA blocks, etc...) would be a > nice feature for Python. > > Then I looked at a stack trace from a different programming language > with lots of anonymous functions. (I believe it was perl.) Didn?t it have source line numbers in it? What more do you need? From doron.tal.list at gmail.com Wed Feb 17 03:44:03 2010 From: doron.tal.list at gmail.com (Doron Tal) Date: Wed, 17 Feb 2010 10:44:03 +0200 Subject: GIL state during import In-Reply-To: References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Message-ID: <2a8674c61002170044n66ad77bfk3c85744eddf79337@mail.gmail.com> On Wed, Feb 17, 2010 at 1:01 AM, Terry Reedy wrote: > On 2/16/2010 4:37 PM, Doron Tal wrote: > >> Is the GIL released during import statement execution when accessing the >> file? >> If not, is it a bug? >> If it is not a bug, or it is here to stay for any other reason, I think >> it should be mentioned in the documentation. >> > > The CPython GIL is a CPython implementation artifact and should not be > mentioned in the language docs (and is not, as far as I know). Were you > thinking of something else? And why this specific feature of its behavior, > whatever it is. > > tjr > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I'm sorry, I should have explained my case better. Quoting the documentation ( http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock ): "The lock is also released and reacquired around potentially blocking I/O operations like reading or writing a file, so that other threads can run while the thread that requests the I/O is waiting for the I/O operation to complete." Since on some cases the IO may be _very_ slow, any IO command which does not release the GIL can potentially stall the process. There are two problems (or more...), the first, it may stall the process for unacceptable duration. The second problem is that it is not an easy task to track down the root cause of this stall. In the specific case I'm dealing with, the problematic command is execfile (at the time of my initial writing I did not know that). --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From news123 at free.fr Wed Feb 17 04:21:55 2010 From: news123 at free.fr (News123) Date: Wed, 17 Feb 2010 10:21:55 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: <4b7bb533$0$23887$426a74cc@news.free.fr> Hi David, Thanks a lot. As I have pywin32 already installed this is probbaly the way to go. Meanwhile I implemented already a small module, which is parsing sc.exe's output, but probably 'll change it as my implementation is a little clumsy. bye N David Bolen wrote: > alex23 writes: > >> News123 wrote: >>> What is the best way with python to get a list of all windows services. >>> >>> As a start I would be glad to receive only the service names. >>> >>> However it would be nicer if I could get all the properties of a service >>> as well. >> I highly recommend Tim Golden's fantastic WMI module[1]. > > Another alternative is the win32service module from the pywin32 > package (which IMO you'll almost certainly want available when doing > any significant Windows-specific operations) which wraps the native > win32 libraries for enumerating, querying and controlling services. > > A simple loop could use EnumServicesStatus to iterate through the > services, OpenService with the SERVICE_QUERY_CONFIG flag to get a > handle to each service, and then QueryServiceConfig to retrieve > configuration information. > > Since pywin32 is a relatively thin wrapper over the win32 libraries, > pure MSDN documentation can be used for help with the calls, augmented > by any Python-related information contained in the pywin32 > documentation. > > -- David From dino at phidev.org Wed Feb 17 04:29:37 2010 From: dino at phidev.org (Florian Ludwig) Date: Wed, 17 Feb 2010 10:29:37 +0100 Subject: plugin / intra process communication system In-Reply-To: <7u05ulFfmkU1@mid.uni-berlin.de> References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <7u05ulFfmkU1@mid.uni-berlin.de> Message-ID: <1266398977.10498.423.camel@brain> On Tue, 2010-02-16 at 19:20 +0100, Diez B. Roggisch wrote: > Am 15.02.10 23:12, schrieb Florian Ludwig: > > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: > >>> Here there problem with the trac (and other plugin systems I've > >> seen) > >>> approach: > >>> > >>> You need to define something like: > >>> | > >>> | class IAuthPlugin(Interface): [...] > >>> > >>> in your blog software. > >> > >> Why? Any reason you can't define it in a separate package the > >> blog-software depends on, as well as your wiki? > > > > That's actually my point - most plugin systems I've seen, like the one > > trac uses, are not encouraging you to do so. Having a module that just > > defines an Interface is kind of weird - and in the real world no one is > > doing it. > > Just because nobody doesn't do it doesn't mean it's not desirable. Good point. > IMHO the ones using interfaces usually immediatly implement them for some > cases - so you actually get the interface for you authentication > framework, and also implement an OpenID plugin for it. And this forms > one package. Then you can add new packages that implement other things. So if I want to implement another authentication mechanism but doesn't use any of the auth-frameworks code you mentioned you still would depend on it. > repoze.who and what are examples for such design. repoze.who is new for me, it might not actually solve my problem here but it looks interesting for other tasks :) Thanks. > >> And then of course, this is not really needed. In Python, behavior > >> counts, not type-information. So you can get away without any explicit > >> declared interface. You might chose to not do that, for aestetic > >> reasons, or better documentation. But you aren't forced. > > > > Actually some plugin-systems in python do force you and they check if > > your "implementation" comply with the "interface". > > I didn't say nobody does it, I just said it isn't needed to get a > working plugin system. If you don't want to have a separate package > *and* don't want to pull in any unused code, this is pretty much your > only option. Do you know somebody/some project/system/... who does it? Pulling unused code I definitely want to avoid so I probably will stay with this way. > > [...] > > > > What do you think? Any obvious pitfalls (besides reinventing something)? > > I don't know what pbus is supposed to do. Nor how it's laid out on a > python package level. Its "the plugin system", connecting "service providers" (plugins) and "service users". In my example the "users" also are providers at the same time, the service "auth", provides the service "wiki". Hope that clarifies my intentions a bit. Thanks, Florian PS I removed you (diez) from the TO list as that bounced. Probably related to the (not existing?) domain nospam.web.de -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From navanitachora at gmail.com Wed Feb 17 04:58:43 2010 From: navanitachora at gmail.com (Nandakumar Chandrasekhar) Date: Wed, 17 Feb 2010 17:58:43 +0800 Subject: Replacement for e.message() in python 2.6 Message-ID: <0PKdnTVryZFJIObWnZ2dnUVZ_jidnZ2d@westnet.com.au> Dear Folks, In previous versions of Python I used to use e.message() to print out the error message of an exception like so: try: result = x / y except ZeroDivisionError, e: print e.message() Unfortunately in Python 2.6 the message method is deprecated. Is there any replacement for the message method in Python 2.6 or is there any best practice that should be used in Python from now on? Thank you. Yours sincerely, Nanda From davea at ieee.org Wed Feb 17 04:59:38 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Feb 2010 04:59:38 -0500 Subject: GIL state during import In-Reply-To: References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Message-ID: <4B7BBE0A.10509@ieee.org> Terry Reedy wrote: >
On > 2/16/2010 4:37 PM, Doron Tal wrote: >> Is the GIL released during import statement execution when accessing the >> file? >> If not, is it a bug? >> If it is not a bug, or it is here to stay for any other reason, I think >> it should be mentioned in the documentation. > > The CPython GIL is a CPython implementation artifact and should not be > mentioned in the language docs (and is not, as far as I know). Were > you thinking of something else? And why this specific feature of its > behavior, whatever it is. > > tjr > Threading vs. imports is mentioned at least once in the Python docs. See http://docs.python.org/library/threading.html, section 17.2.9 (at least in version 2.6.4) """While the import machinery is thread safe, there are two key restrictions on threaded imports due to inherent limitations in the way that thread safety is provided: * Firstly, other than in the main module, an import should not have the side effect of spawning a new thread and then waiting for that thread in any way. Failing to abide by this restriction can lead to a deadlock if the spawned thread directly or indirectly attempts to import a module. * Secondly, all import attempts must be completed before the interpreter starts shutting itself down. This can be most easily achieved by only performing imports from non-daemon threads created through the threading module. Daemon threads and threads created directly with the thread module will require some other form of synchronization to ensure they do not attempt imports after system shutdown has commenced. Failure to abide by this restriction will lead to intermittent exceptions and crashes during interpreter shutdown (as the late imports attempt to access machinery which is no longer in a valid state). """ So it may or may not use the GIL, but there are thread restrictions during an import. The rule I try to follow is not to do anything non-trivial during top-level code of a module, except inside the if __name__ == "__main__": portion. If we're inside that portion, we're not a module, we're a script. Even better, import all your modules before starting any new threads. DaveA From arnodel at googlemail.com Wed Feb 17 05:18:52 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 10:18:52 +0000 Subject: Replacement for e.message() in python 2.6 References: <0PKdnTVryZFJIObWnZ2dnUVZ_jidnZ2d@westnet.com.au> Message-ID: Nandakumar Chandrasekhar writes: > Dear Folks, > > In previous versions of Python I used to use e.message() to print out > the error message of an exception like so: > > try: > result = x / y > except ZeroDivisionError, e: > print e.message() > > Unfortunately in Python 2.6 the message method is deprecated. > > Is there any replacement for the message method in Python 2.6 or is > there any best practice that should be used in Python from now on? You can just use the __str__() method of the BaseException object for this. So instead of print e.message You can write print str(e) which in turn is equivalent to print e For more details see PEP 352 (http://www.python.org/dev/peps/pep-0352/) -- Arnaud From jkn_gg at nicorp.f9.co.uk Wed Feb 17 05:31:45 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Wed, 17 Feb 2010 02:31:45 -0800 (PST) Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? References: <009d33cc-75da-4afe-9715-31e820ddc54e@y7g2000prc.googlegroups.com> Message-ID: On Feb 17, 2:04?am, Carl Banks wrote: > > Hubris connects Ruby to Haskell, will there be such a connection > > between Python and Haskell? > > I would have expected Hubris to link Ada and Common Lisp together. > > Carl Banks ;-) J^n From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 17 05:46:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 11:46:02 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: <4b7bc8e4$0$4242$426a34cc@news.free.fr> Aahz a ?crit : > In article <8ca440b2-6094-4b35-80c5-81d000517ce0 at v20g2000prb.googlegroups.com>, > Jonathan Gardner wrote: >> I used to think anonymous functions (AKA blocks, etc...) would be a >> nice feature for Python. >> >> Then I looked at a stack trace from a different programming language >> with lots of anonymous functions. (I believe it was perl.) >> >> I became enlightened. > > +1 QOTW ++1 QOTW !-) Had the same problem trying to debug some javascript... From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 17 05:48:54 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 11:48:54 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <4b7bc991$0$4242$426a34cc@news.free.fr> Lawrence D'Oliveiro a ?crit : > In message <60b1abce-4381-46ab-91ed- > f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: > >> Also, lambda's are expressions, not statements ... > > Is such a distinction Pythonic, or not? Python is (by design) a statement-based language, so yes, this distinction is pythonic !-) From doron.tal.list at gmail.com Wed Feb 17 06:02:06 2010 From: doron.tal.list at gmail.com (Doron Tal) Date: Wed, 17 Feb 2010 13:02:06 +0200 Subject: GIL state during import In-Reply-To: <4B7BBE0A.10509@ieee.org> References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> <4B7BBE0A.10509@ieee.org> Message-ID: <2a8674c61002170302t28ed24eei9d9960c966b78011@mail.gmail.com> On Wed, Feb 17, 2010 at 11:59 AM, Dave Angel wrote: > Terry Reedy wrote: > >
On 2/16/2010 >> 4:37 PM, Doron Tal wrote: >> >>> Is the GIL released during import statement execution when accessing the >>> file? >>> If not, is it a bug? >>> If it is not a bug, or it is here to stay for any other reason, I think >>> it should be mentioned in the documentation. >>> >> >> The CPython GIL is a CPython implementation artifact and should not be >> mentioned in the language docs (and is not, as far as I know). Were you >> thinking of something else? And why this specific feature of its behavior, >> whatever it is. >> >> tjr >> >> Threading vs. imports is mentioned at least once in the Python docs. See > http://docs.python.org/library/threading.html, section 17.2.9 (at least > in version 2.6.4) > > """While the import machinery is thread safe, there are two key > restrictions on threaded imports due to inherent limitations in the way that > thread safety is provided: > > * Firstly, other than in the main module, an import should not have > the side effect of spawning a new thread and then waiting for that > thread in any way. Failing to abide by this restriction can lead > to a deadlock if the spawned thread directly or indirectly > attempts to import a module. > * Secondly, all import attempts must be completed before the > interpreter starts shutting itself down. This can be most easily > achieved by only performing imports from non-daemon threads > created through the threading module. Daemon threads and threads > created directly with the thread module will require some other > form of synchronization to ensure they do not attempt imports > after system shutdown has commenced. Failure to abide by this > restriction will lead to intermittent exceptions and crashes > during interpreter shutdown (as the late imports attempt to access > machinery which is no longer in a valid state). > > """ > > So it may or may not use the GIL, but there are thread restrictions during > an import. The rule I try to follow is not to do anything non-trivial > during top-level code of a module, except inside the > if __name__ == "__main__": > > portion. If we're inside that portion, we're not a module, we're a script. > > Even better, import all your modules before starting any new threads. > > DaveA > > > > -- > http://mail.python.org/mailman/listinfo/python-list > No argue here. The specific problem, as I wrote in reply to Terry, is with the execfile statement. It might be a part of some online plugin machinery. In such case the nature of the cause does not allow to execute it upfront. I think that the problem can be circumvented by first reading the file followed by compile and eval, as being done in Python3 (no execfile there). --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 06:43:23 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 12:43:23 +0100 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 In-Reply-To: References: Message-ID: W. eWatson wrote: > I've finally decided to see if I could make an executable out of a py > file. Win7. Py2.5. I brought down the install file and proceeded with > the install. I got two warning messages. Forgot the first. The second > said,"Could not set the key value." I again used OK. I think that was > the only choice. It then issued a message in a larger dialog. It was > about setting a key, and pointed me to a log. It mentions a Removepy2exe -u > > Although it finished, I have no idea where the program is. It does not > show up on the Start menu All Programs List nore my desktop. What's up? > > I've had these messages (key) occur on other Python installs as I > transition to Win7. So far no problem. > You may want to consider dumping the thing and going for PyInstaller, which in my experience is better and has friendly developer community behind it. Regards, mk From mrkafk at gmail.com Wed Feb 17 06:44:16 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 12:44:16 +0100 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 In-Reply-To: References: Message-ID: W. eWatson wrote: P.S. I didn't really use PyInstaller on Windows, though -- just on Linux, where it works beautifully. Regards, mk From daniel at stutzbachenterprises.com Wed Feb 17 06:44:49 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 17 Feb 2010 06:44:49 -0500 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: On Tue, Feb 16, 2010 at 3:15 PM, John Nagle wrote: > One possible implementation would be > to have unfrozen objects managed by reference counting and locking as > in CPython. Frozen objects would live in a different memory space and be > garbage collected by a concurrent garbage collector. > A concurrent garbage collector for frozen object would still need to walk unfrozen objects, to find references to frozen objects. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From lacrima.maxim at gmail.com Wed Feb 17 08:25:03 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 17 Feb 2010 05:25:03 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <07d50b9f-c4bb-4d49-82d0-bd6d1c2e42be@z10g2000prh.googlegroups.com> Message-ID: <0beb548b-2aa9-4708-86ee-c89dec988502@q21g2000yqm.googlegroups.com> On Feb 16, 7:38?pm, Phlip wrote: > > This paper _almost_ gets the idea:http://www.netobjectives.com/download/Code%20Qualities%20and%20Practi... > > > Do you run your tests after the fewest possible edits? Such as 1-3 > lines of code? > Hi! I run my tests all the time (they almost replaced debugger in my IDE). But there are times, when I can't just run tests after 1-3 lines of code. For example, I am developing an application that talks to some web service. One of methods of a class, which implements API for a given web service, should parse xml response from web service. At first, I hardcoded returned values, so that they looked like already parsed. But further, additional tests forced me to actually operate with sample xml data instead of hardcoded values. So I created sample xml file that resembled response from server. And after that I can't just write 1-3 lines between each test. Because I need to read() the file and sort it out in a loop (at least 6-9 lines of code for small xml file). And only after this procedure I run my tests with the hope that they all pass. Maybe it's not proper TDD, but I can't figure out how to reduce period between running tests in a case above. From mrkafk at gmail.com Wed Feb 17 08:53:38 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 14:53:38 +0100 Subject: Over(joy)riding Message-ID: Found in Dive into Python: """Guido, the original author of Python, explains method overriding this way: "Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class, may in fact end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual.)" """ So, I set out to create such case: class A(object): def __init__(self): print "A" def met(self): print "I'm A's method" def overriden(self): print "I'm A's method to be overriden" def calling_overriden(self): self.overriden() class B(object): def __init__(self): print "B" def met(self): print "I'm B's method" class C(A): def __init__(self, arg): print "C","arg=",arg A.__init__(self) def met(self): print "I'm C's method" class D(B): def __init__(self, arg): print "D", "arg=",arg B.__init__(self) def met(self): print "I'm D's method" class E(C,D): def __init__(self, arg): print "E", "arg=",arg C.__init__(self, arg) D.__init__(self, arg) def some(self): self.met() def overriden(self): print "I'm really E's method" e = E(10) print 'MRO:', ' '.join([c.__name__ for c in E.__mro__]) e.some() e.calling_overriden() Result: ... MRO: E C A D B object I'm C's method I'm really E's method Is what I concocted in e.calling_overriden() == what Guido said on base class sometimes calling overriden method instead of its own original method? Regards, mk From userprogoogle-139 at yahoo.co.uk Wed Feb 17 08:53:50 2010 From: userprogoogle-139 at yahoo.co.uk (rodmc) Date: Wed, 17 Feb 2010 05:53:50 -0800 (PST) Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> Message-ID: <216c9f16-e952-410b-b0e2-d72b999d557f@g28g2000yqh.googlegroups.com> > > Hi Rod, > > The user's ability to hack into the code is usually considered one of > > the strengths of Python & open source software in general. Since most > > Python software that's distributed ?is open source, you're doing > > something different than most. It'd help if you explain how you want > > your software to differ from a typical open source distribution. Do you > > not want people to change the code? Are you worried about your code & > > ideas being stolen? Thanks to everyone for their replies. Normally I have no problem with adopting an open source model, indeed I usually encourage it. However the main problem was related to end- user licencing e.g. via some form of registration key. The other problem was related to end-user private data and sending this via a secure Internet connection. While I am ok with secure Internet connection side of it I was concerned that with the source code being available to others the security may in some way be reduced- however I note one reply which says this is not the case. Kind regards, rod From arnodel at googlemail.com Wed Feb 17 09:25:06 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 14:25:06 +0000 Subject: Over(joy)riding References: Message-ID: mk writes: > Found in Dive into Python: > > """Guido, the original author of Python, explains method overriding > this way: "Derived classes may override methods of their base > classes. Because methods have no special privileges when calling other > methods of the same object, a method of a base class that calls > another method defined in the same base class, may in fact end up > calling a method of a derived class that overrides it. (For C++ > programmers: all methods in Python are effectively virtual.)" """ > > So, I set out to create such case: > > class A(object): > def __init__(self): > print "A" > > def met(self): > print "I'm A's method" > > def overriden(self): > print "I'm A's method to be overriden" > > def calling_overriden(self): > self.overriden() [...] > class E(C,D): > def __init__(self, arg): > print "E", "arg=",arg > C.__init__(self, arg) > D.__init__(self, arg) > > def some(self): > self.met() > > def overriden(self): > print "I'm really E's method" > > e = E(10) > print 'MRO:', ' '.join([c.__name__ for c in E.__mro__]) > e.some() > e.calling_overriden() > > > Result: > ... > MRO: E C A D B object > I'm C's method > I'm really E's method > > > Is what I concocted in e.calling_overriden() == what Guido said on > base class sometimes calling overriden method instead of its own > original method? Yes! -- Arnaud From lacrima.maxim at gmail.com Wed Feb 17 09:26:33 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 17 Feb 2010 06:26:33 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: On Feb 16, 10:30?pm, Ben Finney wrote: > Lacrima writes: > > And I have already refused to write totally isolated tests, because it > > looks like a great waste of time. > > It only looks like that until you chase your tail in a long, fruitless > debugging session because (you later realise) the behaviour of one test > is being affected by another. Test isolation is essential to ensure that > your tests are doing what you think they're doing. > > -- > ?\ ? ? ? ?A ?No? uttered from deepest conviction is better and greater | > ? `\ ? ? ? than a ?Yes? merely uttered to please, or what is worse, to | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?avoid trouble.? ?Mohandas K. Gandhi | > Ben Finney Hi! Right, isolation is essential. But I can't decide to which extent I should propagate isolation. For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, author suggests that if you do unittesting you should isolate the smallest units of code from each other. For example, if you have a class: Class SomeClass(object): def method1(self): return 5 def method2(self): return self.method1 + 10 According to the book, if you want to test method2, you should isolate it from method1 and class instance('self'). Other books are not so strict... And what should I follow as newbie? Currently, I don't create mocks of units if they are within the same class with the unit under test. If that is not right approach, please, explain what are best practices... I am just learning TDD.. with regards, Maxim From chyavana at gmail.com Wed Feb 17 09:27:35 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Wed, 17 Feb 2010 22:27:35 +0800 Subject: Is automatic reload of a module available in Python? Message-ID: Dear Folks, I am currently developing a python program, let us call it "generic.py", and I am testing out the functions therein by testing them out interactively in the python interpreter by invoking python and doing import generic Once I hit an error, I need to revise my file and reload the module using reload(generic) The difference in syntax between invoking import and reload is really costing me time and patience. Therefore, I would like to ask: 1. Is there a method of auto-reloading a module while developing it and testing it with the interactive python interpreter? 2. Is there a better way of developing a program? Thank you. Chandra From mail at timgolden.me.uk Wed Feb 17 09:29:05 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Feb 2010 14:29:05 +0000 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: <4B7BFD31.4010609@timgolden.me.uk> On 16/02/2010 13:51, Alf P. Steinbach wrote: > It doesn't seem to provide ordinary Windows "service"s, but it's a bit unclear > since e.g. the URL above says [... snip ...] Well the useful info in there appears to come from: http://msdn.microsoft.com/en-us/library/aa392783%28VS.85%29.aspx Looking around the matter, I think I'm taking the view that this is an implementation detail of WMI. However you use it, WMI is a layer on a layer on layer (especially if you're using it in Python with my module!) and it's never going to be the fastest thing going. One contributory factor will be this particular model of process-within-process. But I don't feel that it would help anybody if I were to mention it on my webpages as there's nothing the casual user can do about it. In general I tend to unrecommend WMI for something small in an app which doesn't otherwise use it, unless the convenience (and it *is* very convenient sometimes) outweighs the slight performance issue. Thanks for the heads-up anyway, Alf. I need to get up to speed with the Vista & W7 issues referred to on that page as well. TJG From xiajunyi at gmail.com Wed Feb 17 09:35:57 2010 From: xiajunyi at gmail.com (Imaginationworks) Date: Wed, 17 Feb 2010 06:35:57 -0800 (PST) Subject: How to efficiently extract information from structured text file References: Message-ID: On Feb 16, 7:14?pm, Gary Herron wrote: > Imaginationworks wrote: > > Hi, > > > I am trying to read object information from a text file (approx. > > 30,000 lines) with the following format, each line corresponds to a > > line in the text file. ?Currently, the whole file was read into a > > string list using readlines(), then use for loop to search the "= {" > > and "};" to determine the Object, SubObject,and SubSubObject. My > > questions are > > > 1) Is there any efficient method that I can search the whole string > > list to find the location of the tokens(such as '= {' or '};' > > Yes. ? Read the *whole* file into a single string using file.read() > method, and then search through the string using string methods (for > simple things) or use re, the regular expression module, (for more > complex searches). ? ? > > Note: ?There is a point where a file becomes large enough that reading > the whole file into memory at once (either as a single string or as a > list of strings) is foolish. ? ?However, 30,000 lines doesn't push that > boundary. > > > 2) Is there any efficient ways to extract the object information you > > may suggest? > > Again, the re module has nice ways to find a pattern, and return parse > out pieces of it. ? Building a good regular expression takes time, > experience, and a bit of black magic... ? ?To do so for this case, we > might need more knowledge of your format. ?Also regular expressions have > their limits. ?For instance, if the sub objects can nest to any level, > then in fact, regular expressions alone can't solve the whole problem, > and you'll need a more robust parser. > > > Thanks, > > > - Jeremy > > > ===== Structured text file ================= > > Object1 = { > > > ... > > > SubObject1 = { > > .... > > > SubSubObject1 = { > > ... > > }; > > }; > > > SubObject2 = { > > .... > > > SubSubObject21 = { > > ... > > }; > > }; > > > SubObjectN = { > > .... > > > SubSubObjectN = { > > ... > > }; > > }; > > }; > > Gary and Rhodri, Thank you for the suggestions. From mrkafk at gmail.com Wed Feb 17 09:40:35 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 15:40:35 +0100 Subject: Over(joy)riding In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: >> Is what I concocted in e.calling_overriden() == what Guido said on >> base class sometimes calling overriden method instead of its own >> original method? > > Yes! For a change I achieved resounding success with Python. :-) P.S. Method resolution order in Python makes me want to kill small kittens. Regards, mk From arnodel at googlemail.com Wed Feb 17 09:52:32 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 14:52:32 +0000 Subject: Is automatic reload of a module available in Python? References: Message-ID: "R (Chandra) Chandrasekhar" writes: > Dear Folks, > > I am currently developing a python program, let us call it > "generic.py", and I am testing out the functions therein by testing > them out interactively in the python interpreter by invoking python > and doing > > import generic > > Once I hit an error, I need to revise my file and reload the module using > > reload(generic) > > The difference in syntax between invoking import and reload is really > costing me time and patience. > > Therefore, I would like to ask: > > 1. Is there a method of auto-reloading a module while developing it > and testing it with the interactive python interpreter? > > 2. Is there a better way of developing a program? > > Thank you. > > Chandra Here is a very simple way to improve what you do, which won't require you to change the way you work or to learn a new paradigm: Instead of testing your functions interactively, put your testing code in a file, e.g. 'program_tests.py'. Your can then type python program_tests.py at the shell interactive prompt. To perform the tests again, just re-execute that file. If your tests are divided into different units, you can put these in functions: def test_frobz(): #testing code for frobzation of klops def test_frizz(): #testing code for frizzment of frobzied klops # etc.. So if you want to keep doing interactive tests, you can import program_tests and call whichever testing functions you want. You may even have arguments to those functions to test them with different parameters. I know some people will point at more 'pro' ways of testing but this has the merit of being very straightforward. Then when you move on to more sophisticated techniques, I think you will understand better the motivations behind them. -- Arnaud From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 17 09:52:35 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 15:52:35 +0100 Subject: Over(joy)riding In-Reply-To: References: Message-ID: <4b7c02ac$0$23463$426a74cc@news.free.fr> mk a ?crit : > P.S. Method resolution order in Python makes me want to kill small kittens. mro is only a "problem" when using MI. From python at bdurham.com Wed Feb 17 09:57:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Feb 2010 09:57:27 -0500 Subject: How to build a list of all modules in standard library? Message-ID: <1266418647.16023.1360448951@webmail.messagingengine.com> We're building a py2exe executable that may need to do some dynamic module imports. I'm looking for suggestions on how we can mechanically generate a list of standard library modules/packages to make sure our build has the full set of Python 2.6.4 libraries. We're planning on creating a module called stdlib.py that explictly imports all modules within an "if False:" block of code per example below and then importing this script (stdlib.py) in our main script. # stdlib.py - insure that py2exe imports all modules in its build if False: # list of all standard modules import ... import # list of 3rd party modules import win32api import wmi ... Any suggestions or feedback appreciated. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 10:08:28 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 16:08:28 +0100 Subject: Over(joy)riding In-Reply-To: <4b7c02ac$0$23463$426a74cc@news.free.fr> References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > mk a ?crit : >> P.S. Method resolution order in Python makes me want to kill small >> kittens. > > mro is only a "problem" when using MI. Oh sure! And I have the impression that multiple inheritance is not used all that often. What (some) Python code I've read in open source projects typically uses single inheritance. Nevertheless MI is there in Python, might be useful in some cases and Guido put it there for some reason, so Citizens Aspiring To Become Pythonistas like me work to learn it. Regards, mk From python at bdurham.com Wed Feb 17 10:10:03 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Feb 2010 10:10:03 -0500 Subject: Recommendations for cloud based file storage service with Python API? Message-ID: <1266419403.17892.1360456229@webmail.messagingengine.com> I'm looking for recommendations on a cloud based file storage service with a Python API. Would appreciate hearing feedback from anyone using Python to interface to Amazon S3, RackSpace Cloud Files, Microsoft Azure, Rsync.net, or other hosted file storage service. What services do you recommend or suggest we avoid? Are there Python specific issues (such as lagging library updates when an API gets updated) I should be concerned about? Our use case is mananging thousands of 100K-500K data files owned by hundreds of users. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Feb 17 10:14:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Feb 2010 16:14:19 +0100 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: <4B7C07CB.3000702@sequans.com> R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I am currently developing a python program, let us call it > "generic.py", and I am testing out the functions therein by testing > them out interactively in the python interpreter by invoking python > and doing > > import generic > > Once I hit an error, I need to revise my file and reload the module using > > reload(generic) > > The difference in syntax between invoking import and reload is really > costing me time and patience. > > Therefore, I would like to ask: > > 1. Is there a method of auto-reloading a module while developing it > and testing it with the interactive python interpreter? > > 2. Is there a better way of developing a program? > > Thank you. > > Chandra You will always find people explaining to you how it can be possible if you really know precisely how python object model works. If you actually do, you can possibly read their technics. But my short answer would be "No, there is no reliable way to reload a module". Still there is 'reload' builting function you can call on any module, by you must understand that it won't affect any other object that the module itself. New objects created from that module will take effects, but all objects created before won't. JM From kwmsmith at gmail.com Wed Feb 17 11:00:23 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Wed, 17 Feb 2010 10:00:23 -0600 Subject: Over(joy)riding In-Reply-To: References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: On Wed, Feb 17, 2010 at 9:08 AM, mk wrote: > Bruno Desthuilliers wrote: >> >> mk a ?crit : >>> >>> P.S. Method resolution order in Python makes me want to kill small >>> kittens. >> >> mro is only a "problem" when using MI. > > Oh sure! And I have the impression that multiple inheritance is not used all > that often. What (some) Python code I've read in open source projects > typically uses single inheritance. > > Nevertheless MI is there in Python, might be useful in some cases and Guido > put it there for some reason, so Citizens Aspiring To Become Pythonistas > like me work to learn it. In case you're not familiar with it, MI allows you to have mixins & traits. They work very well if the mixin superclasses don't have any clashes with the other superclasses, so each mixin adds its own unique set of methods to the derived class. Then you don't have to worry about mro and all that (at least as much). Here's an article on it, with examples: http://www.linuxjournal.com/node/4540/print Michele Simionato has some criticism of MI pitfalls and has come up with the straits module to remedy it -- you might be interested. He goes into detail here: http://www.artima.com/weblogs/viewpost.jsp?thread=246488 Kurt From dyamins at gmail.com Wed Feb 17 11:04:24 2010 From: dyamins at gmail.com (Dan Yamins) Date: Wed, 17 Feb 2010 11:04:24 -0500 Subject: Wrap and intercept function calls In-Reply-To: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> Message-ID: <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Really, nobody has any idea about this? (Sorry to repost.) On Tue, Feb 16, 2010 at 7:29 PM, Dan Yamins wrote: > Hi: > > I'm wondering what the best way to wrap and modify function calls is. > Essentially what I want to achieve is to have a function like this: > > def Wrap(frame,event,arg): > if event == 'call': > result = PerformCheck(GetArgumentsFromFrame(frame)) > if Condition(result): > return result > else: > return [normal function call] > > called whenever a "call" event is about to occur. > > When I say "return result" I mean: return that data object instead of what > the function would have returned, and prevent execution of the function. > > > Is there any way to do this using sys.settrace? Or perhaps something from > the bdb or pbd module? > > In other words, what I'm looking for is a way to intercept all function calls with a "wrapper" -- like one can do using settrace and other debugging methods -- but, unlike the debugging methods, have the "wrapping" function actually be able to intervene in the stack and, for instance, conditionally replace the function call's return with something determined in the wrapping function and prevent the function call's execution. I want to be able to do this by setting a single system-wide (or at any rate, thread-wide) value, like with settrace, and not have to modify individual functions one by one. Could I, for example, set a settrace function that somehow modifies the stack? Or is there some much better way to do this? Or, if someone can tell me that this can't be done without having to roll my own implementation of the Python interpreter, that would be great to know too. Thanks again, Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Feb 17 11:17:00 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 17 Feb 2010 10:17:00 -0600 Subject: Recommendations for cloud based file storage service with Python API? In-Reply-To: <1266419403.17892.1360456229@webmail.messagingengine.com> References: <1266419403.17892.1360456229@webmail.messagingengine.com> Message-ID: On 2010-02-17 09:10 AM, python at bdurham.com wrote: > I'm looking for recommendations on a cloud based file storage service > with a Python API. > Would appreciate hearing feedback from anyone using Python to interface > to Amazon S3, RackSpace Cloud Files, Microsoft Azure, Rsync.net, or > other hosted file storage service. What services do you recommend or > suggest we avoid? Are there Python specific issues (such as lagging > library updates when an API gets updated) I should be concerned about? I don't have any deep experience with using any of them, it is worth noting that the Python interface to the RackSpace Cloud Files API is implemented by RackSpace itself and is the premier interface to their API. It won't lag behind the API. -- 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 phlip2005 at gmail.com Wed Feb 17 11:30:24 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 17 Feb 2010 08:30:24 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: On Feb 17, 6:26?am, Lacrima wrote: > Right, isolation is essential. Please read my reply: Ben is well intentioned but completely wrong here. Mock abuse will not cure the runtime isolation problem. From phlip2005 at gmail.com Wed Feb 17 11:32:00 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 17 Feb 2010 08:32:00 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <07d50b9f-c4bb-4d49-82d0-bd6d1c2e42be@z10g2000prh.googlegroups.com> <0beb548b-2aa9-4708-86ee-c89dec988502@q21g2000yqm.googlegroups.com> Message-ID: <2dd65d33-5f55-4124-b748-44f7b46320c7@g28g2000prb.googlegroups.com> Lacrima wrote: > I run my tests all the time (they almost replaced debugger in my IDE). > But there are times, when I can't just run tests after 1-3 lines of > code. ... > Maybe it's not proper TDD You are still being too literal. The "1-3 lines of code" guideline is a guideline, not a rule. It means 1 small edit is best, 2 edits are mostly harmless, 3 is okay, 4 is acceptable, and so on. It's the peak of the Zipf's Law curve: http://www.rimmkaufman.com/content/mobydick.png You "mocked the wire" with that hardcoded XML so that your subsequent edits can be very short and reliable. Props! From nagle at animats.com Wed Feb 17 12:26:46 2010 From: nagle at animats.com (John Nagle) Date: Wed, 17 Feb 2010 09:26:46 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: <4b7c22c8$0$1651$742ec2ed@news.sonic.net> Daniel Stutzbach wrote: > On Tue, Feb 16, 2010 at 3:15 PM, John Nagle wrote: > >> One possible implementation would be >> to have unfrozen objects managed by reference counting and locking as >> in CPython. Frozen objects would live in a different memory space and be >> garbage collected by a concurrent garbage collector. >> > > A concurrent garbage collector for frozen object would still need to walk > unfrozen objects, to find references to frozen objects. Right. But the reverse is not the case. Reference count updating wouldn't need to look at frozen object space. One way to implement locking is something like this: Mutable objects have a reference count field, a lock field, and an "owner" field. Initially, the owner of an object is its thread. If an object's only reference is a field of a synchronized object, the owner is the synchronized object. Mutable objects with an owner can be manipulated by that owner without locking. When an object reference is passed to another thread or another synchronized object, the object becomes multi-owner and the "owner" field is set to null. Thereafter, the object must be locked during updates. The headache with this is that when an object becomes multi-owner, so does everything it points to. So there's a transient as the system runs down the references, locking objects momentarily and clearing owner fields. John Nagle From mrkafk at gmail.com Wed Feb 17 12:29:36 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 18:29:36 +0100 Subject: Over(joy)riding In-Reply-To: References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: Kurt Smith wrote: > In case you're not familiar with it, MI allows you to have mixins & > traits. They work very well if the mixin superclasses don't have any > clashes with the other superclasses, so each mixin adds its own unique > set of methods to the derived class. Then you don't have to worry > about mro and all that (at least as much). > > Here's an article on it, with examples: > > http://www.linuxjournal.com/node/4540/print > > Michele Simionato has some criticism of MI pitfalls and has come up > with the straits module to remedy it -- you might be interested. He > goes into detail here: > > http://www.artima.com/weblogs/viewpost.jsp?thread=246488 Thanks Kurt, I will certainly look into that! Regards, mk From mrkafk at gmail.com Wed Feb 17 12:38:14 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 18:38:14 +0100 Subject: Referring to class methods in class attributes Message-ID: Hello everyone, OK so I have this: def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" class PYFileInfo(FileInfo): File "C:/mp3i/finfo2.py", line 64, in PYFileInfo 'internal_date': PYFileInfo.print_internal_date NameError: name 'PYFileInfo' is not defined Hmm do I get that class data attributes are defined before class is defined?! Why I would like to do it this way: 1. keeping all the stuff specific to PYFileInfo where it belongs, in a class: the print_internal_method does nothing but read timestamp from a .pyc file, so it's not a generic function. 2. I guess I could define tagdata in __init__ and be done with it: however, it's an instance attribute then and not class attribute: a few bytes are wasted. Seriously, however, suppose tagdata or smth like this is really large? It would make sense to make it class attribute and not instance attribute. So I'm trying to work out if there's a way to do it. Regards, mk From apt.shansen at gmail.com Wed Feb 17 12:59:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 17 Feb 2010 09:59:11 -0800 Subject: Referring to class methods in class attributes In-Reply-To: References: Message-ID: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> On Wed, Feb 17, 2010 at 9:38 AM, mk wrote: > It works. But if I'd like to def print_internal_date in PYFileInfo body > like so: > > class PYFileInfo(FileInfo): > 'python file properties' > > def print_internal_date(self, filename): > f = open(filename + 'c', "rb") > data = f.read(8) > mtime = struct.unpack(" return time.asctime(time.gmtime(mtime[0])) > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': PYFileInfo.print_internal_date > } > You don't have to (and can't) refer to the class within the body. Class statements are sort of... odd. They are code which is directly executed, and the results are then passed into a metaclass/type/whatever and a class object is created. While within the class body, the class doesn't exist yet. But you don't need it to. Just do: 'internal_date': print_internal_date The 'def' is in the same local scope as 'tagdata' is. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 13:00:45 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 19:00:45 +0100 Subject: mixins and new style classes Message-ID: >>> class Person(object): ... pass ... >>> class Friendly(object): ... def hello(self): ... print 'hello' ... >>> >>> Person.__bases__ += (Friendly,) Traceback (most recent call last): File "", line 1, in TypeError: Cannot create a consistent method resolution order (MRO) for bases object, Friendly But it works for old-style classes: >>> class Person: ... pass ... >>> class Friendly: ... def hello(self): ... print 'hello' ... >>> >>> p = Person() >>> >>> Person.__bases__ += (Friendly,) >>> >>> p.hello() hello Python is 2.6.1. From andrej.mitrovich at gmail.com Wed Feb 17 13:10:37 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Feb 2010 10:10:37 -0800 (PST) Subject: Traversing through variable-sized lists Message-ID: Hi, I couldn't figure out a better description for the Subject line, but anyway, I have the following: _num_frames = 32 _frames = range(0, _num_frames) # This is a list of actual objects, I'm just pseudocoding here. _values = [0, 1, 2, 3, 4] I want to call a function of _frames for each frame with a _values argument, but in a way to "spread out" the actual values. I would want something similar to the following to be called: _frames[0].func(_values[0]) _frames[1].func(_values[0]) _frames[2].func(_values[0]) _frames[3].func(_values[0]) _frames[4].func(_values[1]) _frames[5].func(_values[1]) _frames[6].func(_values[1]) _frames[7].func(_values[1]) _frames[8].func(_values[2]) ...etc... Both the _values list and _frames list can be of variable and uneven size, which is what is giving me the problems. I'm using Python 2.6. I've tried the following workaround, but it often gives me inaccurate results (due to integer division), so I had to add a safety check: num_frames = 32 values = [0, 1, 2, 3, 4] offset_step = num_frames / len(values) for index in xrange(0, num_frames): offset = index / offset_step if offset > offset_values[-1]: offset = offset_values[-1] frames[index].func(values[offset]) There has to be a better way to do this. I'd appreciate any help. Cheers! From victorsubervi at gmail.com Wed Feb 17 13:14:58 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 17 Feb 2010 14:14:58 -0400 Subject: Timer Message-ID: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Hi; I have the following css: and the following python: if new is not None: print '
' print '' % (str(wn*1008), str(wn*200)) print ''' ''' print '' % (str(wn*1008), str(wn*200)) print '' print '
' Timer(5, removeCSS, ()).start() Obviously, the removeCSS isn't going to work in that last line. What can I put there to remove the splash page after 5 seconds? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gabriel at opensuse.org Wed Feb 17 13:30:51 2010 From: gabriel at opensuse.org (Gabriel) Date: Wed, 17 Feb 2010 15:30:51 -0300 Subject: Timer In-Reply-To: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Message-ID: <1adde6891002171030m2d83a0a3v93017aa7a1cee55c@mail.gmail.com> On Wed, Feb 17, 2010 at 3:14 PM, Victor Subervi wrote: > Hi; > I have the following css: > > and the following python: > ??if new is not None: > ?? ?print '
' > ?? ?print ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" > WIDTH="%s" HEIGHT="%s" id="myMovieName">' % (str(wn*1008), str(wn*200)) > ?? ?print ''' > > > ''' > ?? ?print ' quality=high bgcolor=#FFFFFF WIDTH="%s" HEIGHT="%s" NAME="myMovieName" > ALIGN="" TYPE="application/x-shockwave-flash" > PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">' % > (str(wn*1008), str(wn*200)) > ?? ?print '' > ?? ?print '
' > ?? ?Timer(5, removeCSS, ()).start() > Obviously, the removeCSS isn't going to work in that last line. What can I > put there to remove the splash page after 5 seconds? > TIA, > beno I don't think this has anything to do with python. -- Kind Regards From dotancohen at gmail.com Wed Feb 17 13:36:45 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 17 Feb 2010 20:36:45 +0200 Subject: Timer In-Reply-To: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Message-ID: <880dece01002171036t7e198649jd94d2bd789eadf9f@mail.gmail.com> > What can I > put there to remove the splash page after 5 seconds? > Javascript. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Please CC me if you want to be sure that I read your message. I do not read all list mail. From apt.shansen at gmail.com Wed Feb 17 13:37:56 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 17 Feb 2010 10:37:56 -0800 Subject: Timer In-Reply-To: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Message-ID: <7a9c25c21002171037s49568919te9840a9dabd37f29@mail.gmail.com> On Wed, Feb 17, 2010 at 10:14 AM, Victor Subervi wrote: > Obviously, the removeCSS isn't going to work in that last line. What can I > put there to remove the splash page after 5 seconds? > Even though you're generating this with python, it doesn't have anything to do with Python. You'll have to use javascript and DHTML and enable/disable classes. How to do that is beyond the scope of this group, and might depend on the browser. I'd go look into jQuery or some such which will encapsulate such dynamic things better. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 13:38:10 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 19:38:10 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: Stephen Hansen wrote: > You don't have to (and can't) refer to the class within the body. Class > statements are sort of... odd. They are code which is directly executed, > and the results are then passed into a metaclass/type/whatever and a > class object is created. While within the class body, the class doesn't > exist yet. > > But you don't need it to. > > Just do: > > 'internal_date': print_internal_date > > The 'def' is in the same local scope as 'tagdata' is. Thanks, that worked. But in order to make it work I had to get rid of 'self' in print_internal_date signature, bc all other functions in tagdata have only a single argument: class PYFileInfo(FileInfo): 'python file properties' def print_internal_date(filename): ... tagdata = {'compiled_fname': lambda x: x + 'c', 'size': os.path.getsize, 'internal_date': print_internal_date } That looks weird: a method with no 'self'. Hmm that is probably seriously wrong. This obviously means no other method can call it like self.print_internal_date(), because self would get passed as first argument, yes? I checked that print_internal_date can be called on an instance, so the same method can be seen as: - class method -- when used in local scope definition like tagdata, or - instance method -- when called from an instance or from self? It should be called ______print_internal_date really. ;-) I wonder if I'm not trying to make Python things it shouldn't be doing, but it's the problem at hand that is leading me into this conundrum: all other functions for tagdata use single arguments. I should probably code around that anyway.. Regards, mk From john at castleamber.com Wed Feb 17 13:39:30 2010 From: john at castleamber.com (John Bokma) Date: Wed, 17 Feb 2010 12:39:30 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: <87fx4zlna5.fsf@castleamber.com> Jonathan Gardner writes: > Then I looked at a stack trace from a different programming language > with lots of anonymous functions. (I believe it was perl.) > > I became enlightened. If it was Perl [1], I doubt it. Because line numbers are reported, and if that doesn't help you, you can annotate anonymous functions with a nick name using local *__ANON__ = 'nice name'; Finding an issue, and not looking for a solution is not called becoming enlightened ;-) ~$ perl -e ' use Carp; my $anon = sub { local *__ANON__ = "hello, world"; croak "oops"; }; $anon->(); ' oops at -e line 4 main::hello, world() called at -e line 5 As you can see, and a line number is generated, and the nice name is shown. If you generate anonymouse functions on the fly based on parameters, you can encode this into the nice name, of course. Sadly, often bold statements about a language are made in ignorance. [1] perl is the program that executes Perl programs ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From apt.shansen at gmail.com Wed Feb 17 13:51:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 17 Feb 2010 10:51:11 -0800 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: <7a9c25c21002171051o4bc48483qbb82cc65668434f6@mail.gmail.com> On Wed, Feb 17, 2010 at 10:38 AM, mk wrote: > Thanks, that worked. But in order to make it work I had to get rid of > 'self' in print_internal_date signature, bc all other functions in tagdata > have only a single argument: > Right, I should have caught that. You can make print_internal_date a @staticmethod. Or just leave it as a top level function where it was perfectly happy to live :) > That looks weird: a method with no 'self'. Hmm that is probably seriously > wrong. > > This obviously means no other method can call it like > self.print_internal_date(), because self would get passed as first argument, > yes? > It doesn't have to be. It could be a class method-- @classmethod does that, makes it receive 'cls' the actual class as the first argument. Or a @staticmethod, in which case it has no first-argument at all. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjw at ncf.ca Wed Feb 17 13:51:50 2010 From: cjw at ncf.ca (cjw) Date: Wed, 17 Feb 2010 13:51:50 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <4b7bc991$0$4242$426a34cc@news.free.fr> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On 17-Feb-10 05:48 AM, Bruno Desthuilliers wrote: > Lawrence D'Oliveiro a ?crit : >> In message <60b1abce-4381-46ab-91ed- >> f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: >> >>> Also, lambda's are expressions, not statements ... >> >> Is such a distinction Pythonic, or not? > > Python is (by design) a statement-based language, so yes, this > distinction is pythonic !-) Aren't lambda forms better described as function? Colin W. From jeanmichel at sequans.com Wed Feb 17 13:53:59 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Feb 2010 19:53:59 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: <4B7C3B47.5040906@sequans.com> mk wrote: > Stephen Hansen wrote: > >> You don't have to (and can't) refer to the class within the body. >> Class statements are sort of... odd. They are code which is directly >> executed, and the results are then passed into a >> metaclass/type/whatever and a class object is created. While within >> the class body, the class doesn't exist yet. >> >> But you don't need it to. >> >> Just do: >> >> 'internal_date': print_internal_date >> >> The 'def' is in the same local scope as 'tagdata' is. > > Thanks, that worked. But in order to make it work I had to get rid of > 'self' in print_internal_date signature, bc all other functions in > tagdata have only a single argument: > > class PYFileInfo(FileInfo): > 'python file properties' > > def print_internal_date(filename): > ... > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } > > That looks weird: a method with no 'self'. Hmm that is probably > seriously wrong. > [snip] Absolutely not. It's called a static method, you have to decorate it with @staticmethod though. class A: @staticmethod def getInstance(): return A() a = A.getInstance() you have also the class method version: class B: @classmethod: def getInstance(cls): # class methods take a class as first parameter return cls() JM From mccredie at gmail.com Wed Feb 17 13:55:32 2010 From: mccredie at gmail.com (Matt McCredie) Date: Wed, 17 Feb 2010 18:55:32 +0000 (UTC) Subject: Traversing through variable-sized lists References: Message-ID: > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset > offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! > This is how I would do it, assuming you just want to call the remaining frames with the last value. from itertools import izip def stretch(seq, n): for val in seq: for i in xrange(n): yield val while True: yield val frames_per_value = num_frames // len(values) for frame, value in izip(frames, stretch(values, frames_per_value)): frame.func(value) Matt From ppearson at nowhere.invalid Wed Feb 17 14:15:05 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 17 Feb 2010 19:15:05 GMT Subject: Traversing through variable-sized lists References: Message-ID: <7u2thpFhfbU1@mid.individual.net> On Wed, 17 Feb 2010 10:10:37 -0800 (PST), Andrej Mitrovic wrote: [snip] > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset > offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) Here's my suggestion: Python 2.5.2 (r252:60911, Jul 22 2009, 15:35:03) >>> import math >>> import itertools >>> values = [ 1, 2, 3 ] >>> f = list( lambda x=i : x for i in range( 10 ) ) >>> n = int( math.ceil( len(f)/float( len(values) ) ) ) >>> for ff, dd in zip( f, itertools.chain(*zip( *n*[values] )) ): ... print "Function %d applied to data %d." % ( ff(dd), dd ) ... Function 1 applied to data 1. Function 1 applied to data 1. Function 1 applied to data 1. Function 1 applied to data 1. Function 2 applied to data 2. Function 2 applied to data 2. Function 2 applied to data 2. Function 2 applied to data 2. Function 3 applied to data 3. Function 3 applied to data 3. >>> -- To email me, substitute nowhere->spamcop, invalid->net. From wolfram.hinderer at googlemail.com Wed Feb 17 14:15:59 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Wed, 17 Feb 2010 11:15:59 -0800 (PST) Subject: Traversing through variable-sized lists References: Message-ID: <950cfd62-ee52-4dbc-803b-38b040b52f32@y17g2000yqd.googlegroups.com> On 17 Feb., 19:10, Andrej Mitrovic wrote: > Hi, > > I couldn't figure out a better description for the Subject line, but > anyway, I have the following: > > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > ? ? for index in xrange(0, num_frames): > ? ? ? ? offset = index / offset_step > ? ? ? ? if offset > offset_values[-1]: > ? ? ? ? ? ? offset = offset_values[-1] > ? ? ? ? frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! Python 3.1: >>> def apply_spreaded(funcs, values): ... num_funcs = len(funcs) ... num_values = len(values) ... for i, func in enumerate(funcs): ... func(values[(i * num_values) // num_funcs]) >>> apply_spreaded([print] * 8, range(5)) 0 0 1 1 2 3 3 4 From hniksic at xemacs.org Wed Feb 17 14:18:39 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 17 Feb 2010 20:18:39 +0100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: <877hqbu0vk.fsf@busola.homelinux.net> Tim Chase writes: > if portion is None: > content = iter(f) iter(f) will iterate over lines in the file, which doesn't fit with the rest of the algorithm. Creating an iterator that iterates over fixed-size file chunks (in this case of length 1) is where the two-argument form of iter comes in handy: content = iter(lambda: f.read(1), '') From jjposner at optimum.net Wed Feb 17 14:24:52 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 17 Feb 2010 14:24:52 -0500 Subject: Traversing through variable-sized lists In-Reply-To: References: Message-ID: <4B7C4284.8070709@optimum.net> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: > Hi, > > I couldn't figure out a better description for the Subject line, but > anyway, I have the following: > > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... The lines above show that you are using two different series of index values. Each function call (more properly, "method call") has the form: frames[INDEX_FROM_FIRST_SERIES].func(INDEX_FROM_SECOND_SERIES) (I've dropped the underscores in the names, for simplicity.) You're getting hung up trying to keep the two series of index values in sync. But you don't really need to. More below ... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset> offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! As you've shown above, a "for" loop takes care of the first series of index values: for index in xrange(num_frames): # "0" arg unnecessary frames[index].func(INDEX_FROM_SECOND_SERIES) The second series of index values needs to look like this: 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3 ... The trick is not to worry about matching the second series to the first series. Instead, create an "infinite" second series using a Python generator, and use as many of its values as you need. Don't worry about the unused values, because the series isn't *really* infinite. :-) Here's an easy way to create the generator import itertools second_series_gen = (i/4 for i in itertools.count()) Now, every time you need another number from this series, use its next() method. So the above code becomes: for index in xrange(num_frames): frames[index].func(second_series_gen.next()) -John From __peter__ at web.de Wed Feb 17 14:27:41 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Feb 2010 20:27:41 +0100 Subject: Traversing through variable-sized lists References: Message-ID: Andrej Mitrovic wrote: > Hi, > > I couldn't figure out a better description for the Subject line, but > anyway, I have the following: > > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset > offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! I tried to apply http://en.wikipedia.org/wiki/Bresenham's_line_algorithm on the problem: def bresenham(xitems, yitems): x1 = len(xitems) y1 = len(yitems) assert y1 <= x1 assert x1 > 0 deltax = x1-1 deltay = y1-1 error = deltax // 2 yitems = iter(yitems) y = next(yitems) for x in xitems: yield x, y error -= deltay if error < 0: y = next(yitems) error += deltax if __name__ == "__main__": def make_f(i): def f(v): return "%d --> %s" % (i, v) return f functions = [make_f(i) for i in range(11)] values = ["b%s" % k for k in range(5)] for f, v in bresenham(functions, values): print f(v) The implementation is derived from the code on the wikipedia page and untested. Peter From ptmcg at austin.rr.com Wed Feb 17 14:40:17 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 17 Feb 2010 11:40:17 -0800 (PST) Subject: How to efficiently extract information from structured text file References: Message-ID: <41aac4b4-2d1c-422c-af6d-604296e95a1a@k19g2000yqc.googlegroups.com> On Feb 16, 5:48?pm, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. ?Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. If you open(filename).read() this file into a variable named data, the following pyparsing parser will pick out your nested brace expressions: from pyparsing import * EQ,LBRACE,RBRACE,SEMI = map(Suppress,"={};") ident = Word(alphas, alphanums) contents = Forward() defn = Group(ident + EQ + Group(LBRACE + contents + RBRACE + SEMI)) contents << ZeroOrMore(defn | ~(LBRACE|RBRACE) + Word(printables)) results = defn.parseString(data) print results Prints: [ ['Object1', ['...', ['SubObject1', ['....', ['SubSubObject1', ['...'] ] ] ], ['SubObject2', ['....', ['SubSubObject21', ['...'] ] ] ], ['SubObjectN', ['....', ['SubSubObjectN', ['...'] ] ] ] ] ] ] -- Paul From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 14:44:47 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 20:44:47 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: <4b7c54a8$0$21284$426a74cc@news.free.fr> mk a ?crit : > Stephen Hansen wrote: > >> You don't have to (and can't) refer to the class within the body. >> Class statements are sort of... odd. They are code which is directly >> executed, and the results are then passed into a >> metaclass/type/whatever and a class object is created. While within >> the class body, the class doesn't exist yet. >> >> But you don't need it to. >> >> Just do: >> >> 'internal_date': print_internal_date >> >> The 'def' is in the same local scope as 'tagdata' is. > > Thanks, that worked. But in order to make it work I had to get rid of > 'self' in print_internal_date signature Indeed. Using it that way, the print_internal_date will not be wrapped in a method object. > bc all other functions in > tagdata have only a single argument: > > class PYFileInfo(FileInfo): > 'python file properties' > > def print_internal_date(filename): > ... > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } > > That looks weird: a method with no 'self'. It's not a method. > Hmm that is probably > seriously wrong. > > This obviously means no other method can call it like > self.print_internal_date(), because self would get passed as first > argument, yes? Unless you make it a staticmethod. > I checked that print_internal_date can be called on an instance, so the > same method s/method/function/ > can be seen as: > > - class method -- when used in local scope definition like tagdata, or > - instance method -- when called from an instance or from self? Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages. The first thing is that the def statement *always* yield a function object. Always. If you don't believe it, try the following snippet: class Foo(object): def bar(self): return "baaz" print Foo.__dict__.keys() print type(Foo.__dict__['bar']) So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The answer is : attribute lookup rules and the descriptor protocol. To make a long story short, the descriptor protocol specify that, when, during an attribute lookup, a name resolves to a class attribute AND this attribute has a __get__ method, then this __get__ method is called (with either the instance or None and the class itself as arguments) and whatever it returns becomes the result of the attribute lookup. This mechanism is what provides support for computed attributes. Now the trick is that the function type do implement the descriptor protocol. So when a function is an attribute of a class object and you try to access it as an attribute of either the class itself or an instance of the class, it's __get__ method is called with the instance (or None) and the class. Having access to itself (of course), the instance (if there's one) and the class, it's easy for it to wrap all this into a method object. Which is itself a callable object, that when called mostly inject the instance as first object in the argument's list and returns the result of calling the wrapped function object. A (naive) implementation of the whole thing might look like this: class method(object): def __init__(self, func, instance, cls): self.im_func = func self.im_self = instance self.im_class = cls def __call__(self, *args, **kw): # XXX : all sanity checks removed for readability if self.im_self: args = (self.im_func,) + args return self.im_func(*args, **kw) class function(object): # ... def __get__(self, instance, cls): return method(self, instance, cls) So, what makes a function a "method" is not being defined in a class statement's body (well, not directly at least), it's that it is an attribute of the class. FWIW, the following code is perfectly legal: class Foo(object): pass def func(obj): print "obj is %s " % obj Foo.method = func f = Foo() f.method() Foo.method(f) func(f) > I wonder if I'm not trying to make Python things it shouldn't be doing, > but it's the problem at hand that is leading me into this conundrum: all > other functions for tagdata use single arguments. I should probably code > around that anyway.. Well, the simple solution is to just leave print_internal_date as a plain function instead of insisting on making it a method. Python is 100% OO in that everything is an object, but it's not a "pure" OO language, ie it doesn't require everything to happen in a method. So if all you need is a function, by all mean just use a function !-) Now if you really need print_internal_date to be exposed as a method of PYFileInfo - like, you need polymorphic dispatch - then make it a staticmethod. My 2 cents... From deets at nospam.web.de Wed Feb 17 14:46:00 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 17 Feb 2010 20:46:00 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <7u05ulFfmkU1@mid.uni-berlin.de> Message-ID: <4B7C4778.8090904@nospam.web.de> >> IMHO the ones using interfaces usually immediatly implement them for some >> cases - so you actually get the interface for you authentication >> framework, and also implement an OpenID plugin for it. And this forms >> one package. Then you can add new packages that implement other things. > > So if I want to implement another authentication mechanism but doesn't > use any of the auth-frameworks code you mentioned you still would depend > on it. This depends on your definition of depending... (pun intended). Sure, the code floats around. But it isn't *used* by your application. Why do you bother so much? >> I didn't say nobody does it, I just said it isn't needed to get a >> working plugin system. If you don't want to have a separate package >> *and* don't want to pull in any unused code, this is pretty much your >> only option. > > Do you know somebody/some project/system/... who does it? > > Pulling unused code I definitely want to avoid so I probably will stay > with this way. Well, it's simply duck-typing, so you find it all over the place. Out of my head I only know about e.g. TurboMail, that allows you to specify plugins via pkg_resources entry points & simply uses them. > Its "the plugin system", connecting "service providers" (plugins) and > "service users". In my example the "users" also are providers at the > same time, the service "auth", provides the service "wiki". So it's hypothetical? To summarize my point again: if you want explicit type-checking or zope-style interface implementation, but don't want any code that implements this (at least not imported) - you need an explicit package. If you don't want this, use duck-typing. > > PS I removed you (diez) from the TO list as that bounced. Probably > related to the (not existing?) domain nospam.web.de I post through NNTP, and the email is obfuscated for the obvious reasons. From tjreedy at udel.edu Wed Feb 17 14:50:32 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 14:50:32 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On 2/17/2010 1:51 PM, cjw wrote: > On 17-Feb-10 05:48 AM, Bruno Desthuilliers wrote: >> Lawrence D'Oliveiro a ?crit : >>> In message <60b1abce-4381-46ab-91ed- >>> f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: >>> >>>> Also, lambda's are expressions, not statements ... >>> >>> Is such a distinction Pythonic, or not? >> >> Python is (by design) a statement-based language, so yes, this >> distinction is pythonic !-) > Aren't lambda forms better described as function? They are expressions that evaluate to function objects nearly identical to that produced by the def statememt they abbreviate. The only difference is the .__name__ attribute. Terry Jan Reedy From tjreedy at udel.edu Wed Feb 17 14:57:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 14:57:23 -0500 Subject: Over(joy)riding In-Reply-To: References: Message-ID: On 2/17/2010 8:53 AM, mk wrote: > Found in Dive into Python: > > """Guido, the original author of Python, explains method overriding this > way: "Derived classes may override methods of their base classes. > Because methods have no special privileges when calling other methods of > the same object, a method of a base class that calls another method > defined in the same base class, may in fact end up calling a method of a > derived class that overrides it. (For C++ programmers: all methods in > Python are effectively virtual.)" """ > > So, I set out to create such case: > > class A(object): > def __init__(self): > print "A" > > def met(self): > print "I'm A's method" > > def overriden(self): > print "I'm A's method to be overriden" > > def calling_overriden(self): > self.overriden() > > class B(object): > def __init__(self): > print "B" > > def met(self): > print "I'm B's method" > > > class C(A): > def __init__(self, arg): > print "C","arg=",arg > A.__init__(self) > > def met(self): > print "I'm C's method" > > > class D(B): > def __init__(self, arg): > print "D", "arg=",arg > B.__init__(self) > > def met(self): > print "I'm D's method" > > > class E(C,D): > def __init__(self, arg): > print "E", "arg=",arg > C.__init__(self, arg) > D.__init__(self, arg) > > def some(self): > self.met() > > def overriden(self): > print "I'm really E's method" > > e = E(10) > print 'MRO:', ' '.join([c.__name__ for c in E.__mro__]) > e.some() > e.calling_overriden() > > > Result: > ... > MRO: E C A D B object > I'm C's method > I'm really E's method > > > Is what I concocted in e.calling_overriden() == what Guido said on base > class sometimes calling overriden method instead of its own original > method? Much more complicated than needed for this point, but I believe yes. From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 15:00:42 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 21:00:42 +0100 Subject: Over(joy)riding In-Reply-To: References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: <4b7c5863$0$24394$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: >> mk a ?crit : >>> P.S. Method resolution order in Python makes me want to kill small >>> kittens. >> >> mro is only a "problem" when using MI. > > Oh sure! And I have the impression that multiple inheritance is not used > all that often. What (some) Python code I've read in open source > projects typically uses single inheritance. Single inheritance does indeed cover most of the needs - and FWIW, even single inheritance is not used as much in Python as in some other more mainstream OOPLs. This comes partly from duck typing - inheritance is only used for implementation inheritance, not for type-based polymorphic dispatch -, and partly from Python's support for composition/delegation (thru __getattr__). Also - as you noticed - single inheritance is easier to grasp, and Python's philosophy really values simplicity, readability, maintainability, and coder's mental health !-) > Nevertheless MI is there in Python, might be useful in some cases and > Guido put it there for some reason, Indeed. As with most Python's "advanced" features, it's there so you can use it when appropriate. > so Citizens Aspiring To Become > Pythonistas like me work to learn it. FWIW, I very rarely had to use it myself in almost 10 years of Python programming - main exceptions being Zope2 stuff (which is IMHO highly unpythonic) and a couple mixin classes here and there. From tjreedy at udel.edu Wed Feb 17 15:21:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 15:21:51 -0500 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: On 2/17/2010 9:27 AM, R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I am currently developing a python program, let us call it "generic.py", > and I am testing out the functions therein by testing them out > interactively in the python interpreter by invoking python and doing > > import generic > > Once I hit an error, I need to revise my file and reload the module using > > reload(generic) Reload is sufficiently flakey that it has been removed in 3.x. The problem is that it genearally only *partially* replaces the module, so that some code uses the old version and some the new. Guido tried to rewrite it but gave up and removed it. The most sensible way to completely remove a module is to shutdown and restart the interpreter. > The difference in syntax between invoking import and reload is really > costing me time and patience. > > Therefore, I would like to ask: > > 1. Is there a method of auto-reloading a module while developing it and > testing it with the interactive python interpreter? > > 2. Is there a better way of developing a program? This is what I now do. Edit # xxx/module.py def _test(): if __name__ == '__main__': _test() with IDLE and hit F5 to run and test. IDLE runs the file in a *fresh* subinterpreter as the main module and then, whether or not an exception is raised, switches to interactive mode, so one can interactively test any objects created (before any exception). The switch to interactive mode after running a file can also be done with a command line switch when using CPython directly. Terry Jan Reedy From tjreedy at udel.edu Wed Feb 17 15:28:03 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 15:28:03 -0500 Subject: How to build a list of all modules in standard library? In-Reply-To: <1266418647.16023.1360448951@webmail.messagingengine.com> References: <1266418647.16023.1360448951@webmail.messagingengine.com> Message-ID: On 2/17/2010 9:57 AM, python at bdurham.com wrote: > We're building a py2exe executable that may need to do some dynamic > module imports. > I'm looking for suggestions on how we can mechanically generate a list > of standard library modules/packages to make sure our build has the full > set of Python 2.6.4 libraries. Find the source file for the global module index that comes with the doc set. Terry Jan Reedy From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 15:31:48 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 21:31:48 +0100 Subject: mixins and new style classes In-Reply-To: References: Message-ID: <4b7c5fad$0$20740$426a74cc@news.free.fr> mk a ?crit : >>>> class Person(object): > ... pass > ... >>>> class Friendly(object): > ... def hello(self): > ... print 'hello' > ... >>>> >>>> Person.__bases__ += (Friendly,) > Traceback (most recent call last): > File "", line 1, in > TypeError: Cannot create a consistent method resolution > order (MRO) for bases object, Friendly Indeed. After the addition of Friendly to Person.__bases__, the mro for Person would be (Person, object, Friendly). But the mro for Friendly is (Friendly, object). This is not consistent. The right solution would be to inject Friendly before object, ie: Person.__bases__ = (Mixin, object) Now the bad news is that this fails too: TypeError: __bases__ assignment: 'Mixin' deallocator differs from 'object' The above problem is not new, and had been discussed here: http://bugs.python.org/issue672115 ...and it's still unresolved AFAICT :-/ OTHO, the concrete use case for such a feature seem to be rather uncommon. > > > But it works for old-style classes: Old-style classes are a very different beast. From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 15:34:51 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 21:34:51 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <4B7C57C7.2000701@optimum.net> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <4B7C57C7.2000701@optimum.net> Message-ID: <4b7c6064$0$20740$426a74cc@news.free.fr> John Posner a ?crit : > On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote: >> > Very nice writeup, Bruno -- thanks! > > >> >> >> def __call__(self, *args, **kw): >> # XXX : all sanity checks removed for readability >> if self.im_self: >> args = (self.im_func,) + args > > In the line above, I think you meant: > > args = (self.im_self,) + args oops :? Yes, indeed. Thanks for the correction. From andrej.mitrovich at gmail.com Wed Feb 17 15:54:42 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Feb 2010 12:54:42 -0800 (PST) Subject: Traversing through variable-sized lists References: <4B7C4284.8070709@optimum.net> Message-ID: <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> On Feb 17, 8:24?pm, John Posner wrote: > On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: > > > > > Hi, > > > I couldn't figure out a better description for the Subject line, but > > anyway, I have the following: > > > _num_frames = 32 > > _frames = range(0, _num_frames) # This is a list of actual objects, > > I'm just pseudocoding here. > > _values = [0, 1, 2, 3, 4] > > > I want to call a function of _frames for each frame with a _values > > argument, but in a way to "spread out" the actual values. > > > I would want something similar to the following to be called: > > > _frames[0].func(_values[0]) > > _frames[1].func(_values[0]) > > _frames[2].func(_values[0]) > > _frames[3].func(_values[0]) > > _frames[4].func(_values[1]) > > _frames[5].func(_values[1]) > > _frames[6].func(_values[1]) > > _frames[7].func(_values[1]) > > _frames[8].func(_values[2]) > > ...etc... > > The lines above show that you are using two different series of index > values. Each function call (more properly, "method call") has the form: > > ? ?frames[INDEX_FROM_FIRST_SERIES].func(INDEX_FROM_SECOND_SERIES) > > (I've dropped the underscores in the names, for simplicity.) You're > getting hung up trying to keep the two series of index values in sync. > But you don't really need to. More below ... > > > > > > > Both the _values list and _frames list can be of variable and uneven > > size, which is what is giving me the problems. I'm using Python 2.6. > > > I've tried the following workaround, but it often gives me inaccurate > > results (due to integer division), so I had to add a safety check: > > > num_frames = 32 > > values = [0, 1, 2, 3, 4] > > offset_step = num_frames / len(values) > > ? ? ?for index in xrange(0, num_frames): > > ? ? ? ? ?offset = index / offset_step > > ? ? ? ? ?if offset> ?offset_values[-1]: > > ? ? ? ? ? ? ?offset = offset_values[-1] > > ? ? ? ? ?frames[index].func(values[offset]) > > > There has to be a better way to do this. I'd appreciate any help. > > Cheers! > > As you've shown above, a "for" loop takes care of the first series of > index values: > > ? ?for index in xrange(num_frames): ? ? ? # "0" arg unnecessary > ? ? ? ?frames[index].func(INDEX_FROM_SECOND_SERIES) > > The second series of index values needs to look like this: > > ? ?0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3 ... > > The trick is not to worry about matching the second series to the first > series. Instead, create an "infinite" second series using a Python > generator, and use as many of its values as you need. Don't worry about > the unused values, because the series isn't *really* infinite. :-) > > Here's an easy way to create the generator > > ? ?import itertools > ? ?second_series_gen = (i/4 for i in itertools.count()) > > Now, every time you need another number from this series, use its next() > method. So the above code becomes: > > ? ?for index in xrange(num_frames): > ? ? ? ?frames[index].func(second_series_gen.next()) > > -John That's a cool trick, but maybe I wasn't specific enough. The values series are the range of values that the frames.func() function should use, it should not overflow, and I would want the function to use as evenly distributed number of values as possible from the first series. The "0000,1111" was just an example. Let me see if I can be more specific: values = [2, 3, 4] frames = [obj1, obj2, obj3, obj4, obj5, obj6] And the calls: frames[0].func(values[0]) # func.(values[2]) frames[1].func(values[0]) # func.(values[2]) frames[2].func(values[1]) # func.(values[3]) frames[3].func(values[1]) # func.(values[3]) frames[4].func(values[2]) # func.(values[4]) frames[5].func(values[2]) # func.(values[4]) However the values list might have an uneven number of items. I would like to make it as evenly distributed as possible, e.g.: values = [-2, -1, 0] frames = [obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8] frames[0].func(values[0]) # func.(values[-2]) frames[1].func(values[0]) # func.(values[-2]) frames[2].func(values[1]) # func.(values[-2]) frames[3].func(values[1]) # func.(values[-1]) frames[4].func(values[1]) # func.(values[-1]) frames[5].func(values[2]) # func.(values[-1]) frames[6].func(values[2]) # func.(values[0]) frames[7].func(values[2]) # func.(values[0]) I'll be even more specific. I have a Minimum and Maximum value that the user enters. The frame.func() function is a "translate" function, it basically moves a frame in the application in one direction or another depending on the argument value. So frame[0].func(2) would move the frame[0] 2 pixels to the right. So what I want is the function to create a smooth transition of all the frames from the Minimum to the Maximum value. If minimum was 0, and maximum was 10, I'd want the first frame moved 0 pixels (it stays in place), the last frame to move 10 pixels, and the frames between are gradually moved from 1 pixels to 9 pixels relative from their positions. Perhaps I'm just overcomplicating. I'll have a look at some drawing apps and see how they've implemented drawing straight lines under an angle, I guess that could be called a gradual change of values. Thanks for all the suggestions everyone, I'll have a look at the rest shortly. From jjposner at optimum.net Wed Feb 17 15:55:35 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 17 Feb 2010 15:55:35 -0500 Subject: Referring to class methods in class attributes In-Reply-To: <4b7c54a8$0$21284$426a74cc@news.free.fr> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: <4B7C57C7.2000701@optimum.net> On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote: > > Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO > beautifully) simple once you get it, but I agree it's a bit peculiar > when compared to most mainstream OO languages. Very nice writeup, Bruno -- thanks! > > class method(object): > def __init__(self, func, instance, cls): > self.im_func = func > self.im_self = instance > self.im_class = cls > > def __call__(self, *args, **kw): > # XXX : all sanity checks removed for readability > if self.im_self: > args = (self.im_func,) + args In the line above, I think you meant: args = (self.im_self,) + args -John From tjreedy at udel.edu Wed Feb 17 15:57:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 15:57:57 -0500 Subject: Wrap and intercept function calls In-Reply-To: <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: On 2/17/2010 11:04 AM, Dan Yamins wrote: > Really, nobody has any idea about this? (Sorry to repost.) > On Tue, Feb 16, 2010 at 7:29 PM, Dan Yamins > wrote: > > Hi: > > I'm wondering what the best way to wrap and modify function calls > is. Essentially what I want to achieve is to have a function like > this: > > def Wrap(frame,event,arg): > if event == 'call': > result = PerformCheck(GetArgumentsFromFrame(frame)) > if Condition(result): > return result > else: > return [normal function call] > > called whenever a "call" event is about to occur. For yourself as interpreter, execute the above for every call. For CPython, alternative 1 is to create a custom interpreter to change (wrap) the interpretation of the call-function bytecode in the ceval loop. That is its 'call event', and I believe this would catch every explicit f(args) call and only such calls. Python has no general metasyntax for changing the semantics of its syntax. The __xx__ methods are special cases for the corresponding operators *and* the corresponding user-defined class. The '__call__' method of a class applies to instances of that class. Alternative 2: class func_wrap: def __init__(self, func): self._func = func def __call__(self, args, kwds): result = PerformCheck(args, kwds) if Condition(result): return result else: return self._func(*args,**kwds) Now wrap *every* function you are interested in. Builtin functions are no problem; methods of builtin classes cannont be wrapped without subclassing. Terry Jan Reedy > When I say "return result" I mean: return that data object instead > of what the function would have returned, and prevent execution of > the function. > > Is there any way to do this using sys.settrace? Or perhaps > something from the bdb or pbd module? > > > In other words, what I'm looking for is a way to intercept all function > calls with a "wrapper" -- like one can do using settrace and other > debugging methods -- but, unlike the debugging methods, have the > "wrapping" function actually be able to intervene in the stack and, for > instance, conditionally replace the function call's return with > something determined in the wrapping function and prevent the function > call's execution. I want to be able to do this by setting a single > system-wide (or at any rate, thread-wide) value, like with settrace, and > not have to modify individual functions one by one. > > Could I, for example, set a settrace function that somehow modifies the > stack? Or is there some much better way to do this? Or, if someone can > tell me that this can't be done without having to roll my own > implementation of the Python interpreter, that would be great to know too. > > Thanks again, > Dan > From joshua.r.english at gmail.com Wed Feb 17 16:00:04 2010 From: joshua.r.english at gmail.com (Josh English) Date: Wed, 17 Feb 2010 13:00:04 -0800 (PST) Subject: MediaWiki to RTF/Word/PDF Message-ID: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> I have several pages exported from a private MediaWiki that I need to convert to a PDF document, or an RTF document, or even a Word document. So far, the only Python module I have found that parses MediaWiki files is mwlib, which only runs on Unix, as far as I can tell. I'm working on Windows here. Has anyone heard of a module that parses wiki markup and transforms it? Or am I looking at XSLT? Josh From anand.shashwat at gmail.com Wed Feb 17 16:20:17 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 18 Feb 2010 02:50:17 +0530 Subject: MediaWiki to RTF/Word/PDF In-Reply-To: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: why not try installing cygwin. I am just guessing though but I had heard it emulates *nix decently on windows. Or a better idea is to shift to *nix ;) On Thu, Feb 18, 2010 at 2:30 AM, Josh English wrote: > I have several pages exported from a private MediaWiki that I need to > convert to a PDF document, or an RTF document, or even a Word > document. > > So far, the only Python module I have found that parses MediaWiki > files is mwlib, which only runs on Unix, as far as I can tell. I'm > working on Windows here. > > Has anyone heard of a module that parses wiki markup and transforms > it? Or am I looking at XSLT? > > Josh > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Wed Feb 17 16:24:36 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 21:24:36 +0000 Subject: Referring to class methods in class attributes References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers writes: [...] > class Foo(object): > def bar(self): > return "baaz" > > print Foo.__dict__.keys() > print type(Foo.__dict__['bar']) > > > So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The > answer is : attribute lookup rules and the descriptor protocol. It's true of Python 2.X. In Python 3 there are no more unbound method: Python 3.2a0 (py3k:75274, Oct 7 2009, 20:25:52) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... def f(self): pass ... >>> A.f >>> A.f is A.__dict__['f'] True -- Arnaud From ben+python at benfinney.id.au Wed Feb 17 17:04:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 09:04:47 +1100 Subject: Referring to class methods in class attributes References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: <87iq9vcydc.fsf@benfinney.id.au> Bruno Desthuilliers writes: > Mmmm... Let's try to explain the whole damn thing. It's really (and > IMHO beautifully) simple once you get it, but I agree it's a bit > peculiar when compared to most mainstream OO languages. [?] Bruno, that's the first time I've understood the descriptor protocol, or even understood *why* the descriptor protocol is important. Could you please post (a version of) this as a separate article somewhere? A weblog post, or a new thread in this forum, or in the documentation? Somewhere that web searches will find it prominently when searching for the Python descriptor protocol. Thank you. -- \ ?I don't want to live peacefully with difficult realities, and | `\ I see no virtue in savoring excuses for avoiding a search for | _o__) real answers.? ?Paul Z. Myers, 2009-09-12 | Ben Finney From john at castleamber.com Wed Feb 17 17:09:42 2010 From: john at castleamber.com (John Bokma) Date: Wed, 17 Feb 2010 16:09:42 -0600 Subject: MediaWiki to RTF/Word/PDF References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: <87pr43ecpl.fsf@castleamber.com> Josh English writes: > I have several pages exported from a private MediaWiki that I need to > convert to a PDF document, or an RTF document, or even a Word > document. > > So far, the only Python module I have found that parses MediaWiki > files is mwlib, which only runs on Unix, as far as I can tell. I'm > working on Windows here. > > Has anyone heard of a module that parses wiki markup and transforms > it? Or am I looking at XSLT? One option might be to install a printer driver that prints to PDF and just print the web pages. Using Saxon or AltovaXML and a suitable stylesheet might give you the nicest looking result though (but quite some work). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From breamoreboy at yahoo.co.uk Wed Feb 17 17:14:07 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 17 Feb 2010 22:14:07 +0000 Subject: Referring to class methods in class attributes In-Reply-To: <87iq9vcydc.fsf@benfinney.id.au> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Bruno Desthuilliers writes: > >> Mmmm... Let's try to explain the whole damn thing. It's really (and >> IMHO beautifully) simple once you get it, but I agree it's a bit >> peculiar when compared to most mainstream OO languages. > [?] > > Bruno, that's the first time I've understood the descriptor protocol, or > even understood *why* the descriptor protocol is important. > > Could you please post (a version of) this as a separate article > somewhere? A weblog post, or a new thread in this forum, or in the > documentation? Somewhere that web searches will find it prominently when > searching for the Python descriptor protocol. > > Thank you. > I'll second, third and fourth this request. More please Bruno, or from anybody similarly qualified. Thanks very much. Mark Lawrence. From sjdevnull at yahoo.com Wed Feb 17 17:17:47 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Wed, 17 Feb 2010 14:17:47 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Message-ID: <2954a28f-e810-47bc-83d6-b9afb910d9af@w12g2000vbj.googlegroups.com> On Feb 17, 2:35?am, Steven D'Aprano wrote: > On Tue, 16 Feb 2010 21:09:27 -0800, John Nagle wrote: > > ? ? Yes, we're now at the point where all the built-in mutable types > > have "frozen" versions. ?But we don't have that for objects. ?It's > > generally considered a good thing in language design to offer, for user > > defined types, most of the functionality of built-in ones. > > It's not hard to build immutable user-defined types. Whether they're > immutable enough is another story :) > > >>> class FrozenMeta(type): > > ... ? ? def __new__(meta, classname, bases, classDict): > ... ? ? ? ? def __setattr__(*args): > ... ? ? ? ? ? ? raise TypeError("can't change immutable class") > ... ? ? ? ? classDict['__setattr__'] = __setattr__ > ... ? ? ? ? classDict['__delattr__'] = __setattr__ > ... ? ? ? ? return type.__new__(meta, classname, bases, classDict) > ... > > >>> class Thingy(object): > > ... ? ? __metaclass__ = FrozenMeta > ... ? ? def __init__(self, x): > ... ? ? ? ? self.__dict__['x'] = x > ... > > >>> t = Thingy(45) > >>> t.x > 45 > >>> t.x = 42 > > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 4, in __setattr__ > TypeError: can't change immutable class > > It's a bit ad hoc, but it seems to work for me. Unfortunately there's no > way to change __dict__ to a "write once, read many" dict. Which makes it not really immutable, as does the relative ease of using a normal setattr: ... t.__dict__['x'] = "foo" ... print t.x foo ... object.__setattr__(t, "x", 42) ... print t.x 42 From ldo at geek-central.gen.new_zealand Wed Feb 17 17:46:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Feb 2010 11:46:52 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: In message , cjw wrote: > Aren't lambda forms better described as function? Is this a function? lambda : None What about this? lambda : sys.stdout.write("hi there!\n") From davea at ieee.org Wed Feb 17 17:56:14 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Feb 2010 17:56:14 -0500 Subject: Traversing through variable-sized lists In-Reply-To: <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> References: <4B7C4284.8070709@optimum.net> <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> Message-ID: <4B7C740E.3040200@ieee.org> Andrej Mitrovic wrote: > On Feb 17, 8:24 pm, John Posner wrote: > >> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: >> >> > > However the values list might have an uneven number of items. I would > like to make it as evenly distributed as possible, e.g.: > > values =-2, -1, 0] > frames =obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8] > > frames[0].func(values[0]) # func.(values[-2]) > frames[1].func(values[0]) # func.(values[-2]) > frames[2].func(values[1]) # func.(values[-2]) > frames[3].func(values[1]) # func.(values[-1]) > frames[4].func(values[1]) # func.(values[-1]) > frames[5].func(values[2]) # func.(values[-1]) > frames[6].func(values[2]) # func.(values[0]) > frames[7].func(values[2]) # func.(values[0]) > > > I'll be even more specific. I have a Minimum and Maximum value that > the user enters. The frame.func() function is a "translate" function, > it basically moves a frame in the application in one direction or > another depending on the argument value. So frame[0].func(2) would > move the frame[0] 2 pixels to the right. So what I want is the > function to create a smooth transition of all the frames from the > Minimum to the Maximum value. If minimum was 0, and maximum was 10, > I'd want the first frame moved 0 pixels (it stays in place), the last > frame to move 10 pixels, and the frames between are gradually moved > from 1 pixels to 9 pixels relative from their positions. > > Perhaps I'm just overcomplicating. I'll have a look at some drawing > apps and see how they've implemented drawing straight lines under an > angle, I guess that could be called a gradual change of values. > > Thanks for all the suggestions everyone, I'll have a look at the rest > shortly. > > I think you're overcomplicating. If you have 27 frames, and you want frame 0 to move 0 pixels, and frame 27 to move 10 pixels, then you want to move frame[i] by i*10/27. And since you do the multiply first, the fact that Python 2.x division gives you integers isn't a problem. There are fancier methods for drawing lines (bresenham for example), but the main purpose of them is to to avoid multiply and divide, as well as floats. But in Python, an integer multiply is just as fast as an add or subtract, so there's no point. DaveA From tjreedy at udel.edu Wed Feb 17 17:59:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 17:59:14 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On 2/17/2010 5:46 PM, Lawrence D'Oliveiro wrote: > In message, cjw wrote: > >> Aren't lambda forms better described as function? > > Is this a function? > > lambda : None > > What about this? > > lambda : sys.stdout.write("hi there!\n") To repeat: Python lambda expressions evaluate to function objects identical, except for .__name__ attribute, to the equivalent def statememnt. >>> type(lambda:None) >>> import sys >>> type(lambda : sys.stdout.write("hi there!\n")) From ben+python at benfinney.id.au Wed Feb 17 18:17:51 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 10:17:51 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: <87eikjcuzk.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > In message , cjw wrote: > > > Aren't lambda forms better described as function? > > Is this a function? > > lambda : None > > What about this? > > lambda : sys.stdout.write("hi there!\n") They are both lambda forms in Python. As a Python expression, they evaluate to (they ?return?) a function object. -- \ ?It is wrong to think that the task of physics is to find out | `\ how nature *is*. Physics concerns what we can *say* about | _o__) nature?? ?Niels Bohr | Ben Finney From xiajunyi at gmail.com Wed Feb 17 18:37:02 2010 From: xiajunyi at gmail.com (Imaginationworks) Date: Wed, 17 Feb 2010 15:37:02 -0800 (PST) Subject: How to efficiently extract information from structured text file References: <41aac4b4-2d1c-422c-af6d-604296e95a1a@k19g2000yqc.googlegroups.com> Message-ID: On Feb 17, 1:40?pm, Paul McGuire wrote: > On Feb 16, 5:48?pm, Imaginationworks wrote: > > > Hi, > > > I am trying to read object information from a text file (approx. > > 30,000 lines) with the following format, each line corresponds to a > > line in the text file. ?Currently, the whole file was read into a > > string list using readlines(), then use for loop to search the "= {" > > and "};" to determine the Object, SubObject,and SubSubObject. > > If you open(filename).read() this file into a variable named data, the > following pyparsing parser will pick out your nested brace > expressions: > > from pyparsing import * > > EQ,LBRACE,RBRACE,SEMI = map(Suppress,"={};") > ident = Word(alphas, alphanums) > contents = Forward() > defn = Group(ident + EQ + Group(LBRACE + contents + RBRACE + SEMI)) > > contents << ZeroOrMore(defn | ~(LBRACE|RBRACE) + Word(printables)) > > results = defn.parseString(data) > > print results > > Prints: > > [ > ?['Object1', > ? ?['...', > ? ? ['SubObject1', > ? ? ? ['....', > ? ? ? ? ['SubSubObject1', > ? ? ? ? ? ['...'] > ? ? ? ? ] > ? ? ? ] > ? ? ], > ? ? ['SubObject2', > ? ? ? ['....', > ? ? ? ?['SubSubObject21', > ? ? ? ? ?['...'] > ? ? ? ?] > ? ? ? ] > ? ? ], > ? ? ['SubObjectN', > ? ? ? ['....', > ? ? ? ?['SubSubObjectN', > ? ? ? ? ?['...'] > ? ? ? ?] > ? ? ? ] > ? ? ] > ? ?] > ?] > ] > > -- Paul Wow, that is great! Thanks From comptekki at gmail.com Wed Feb 17 18:48:38 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 17 Feb 2010 16:48:38 -0700 Subject: string to list when the contents is a list Message-ID: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. "[]" or "['a','b']" The "[]" is simple since I can just check if value == "[]" then return [] But with "['a','b']" I have tried and get: a="['a','b']" b=a[1:-1].split(',') returns [ " 'a' "," 'b' " ] when I want it to return ['a','b']. How can I do this? thx, -wes From comptekki at gmail.com Wed Feb 17 18:53:56 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 17 Feb 2010 16:53:56 -0700 Subject: error trying to join #python on irc.freenode.net Message-ID: <533df7fa1002171553m4a0e5949wf8461473ea5d5c13@mail.gmail.com> When I try to join #python on irc.freenode.net it keeps saying: You need to identify with network services to join the room "#python" on "irc.freenode.net". Server Details: Cannot join channel (+r) - you need to be identified with services What does this mean? thx, -wes From comptekki at gmail.com Wed Feb 17 18:56:06 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 17 Feb 2010 16:56:06 -0700 Subject: error trying to join #python on irc.freenode.net In-Reply-To: <533df7fa1002171553m4a0e5949wf8461473ea5d5c13@mail.gmail.com> References: <533df7fa1002171553m4a0e5949wf8461473ea5d5c13@mail.gmail.com> Message-ID: <533df7fa1002171556t4ad514fgd1eddee0d948391c@mail.gmail.com> On Wed, Feb 17, 2010 at 4:53 PM, Wes James wrote: > When I try to join #python on irc.freenode.net it keeps saying: > > You need to identify with network services to join the room "#python" > on "irc.freenode.net". > > Server Details: > Cannot join channel (+r) - you need to be identified with services > > What does this mean? Nevermind, I think it means I need to register with the service and supply real username/password. -wes From vlastimil.brom at gmail.com Wed Feb 17 19:08:32 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 18 Feb 2010 01:08:32 +0100 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> Message-ID: <9fdb569a1002171608h6dd4f936he1417148426da574@mail.gmail.com> 2010/2/18 Wes James : > I have been trying to create a list form a string. ?The string will be > a list (this is the contents will look like a list). ?i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. > > How can I do this? > > thx, > > -wes > -- > http://mail.python.org/mailman/listinfo/python-list > The potentially problematic exec or eval options left aside, if you really need to do this, you might consider pyparsing; check the example http://pyparsing.wikispaces.com/file/view/parsePythonValue.py If you know, the input string will always have this exact format (single quoted comma separated one-character strings between square brackets), you might use regular expressions to some extent, e.g. print re.findall(r"(?<=')\w(?=')", "['a','b','c','b','A']") ['a', 'b', 'c', 'b', 'A'] hth, vbr From dyamins at gmail.com Wed Feb 17 19:09:06 2010 From: dyamins at gmail.com (Dan Yamins) Date: Wed, 17 Feb 2010 19:09:06 -0500 Subject: Wrap and intercept function calls In-Reply-To: References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: <15e4667e1002171609h5de4fd17y370ead62f7fee737@mail.gmail.com> > For CPython, alternative 1 is to create a custom interpreter to change > (wrap) the interpretation of the call-function bytecode in the ceval loop. > That is its 'call event', and I believe this would catch every explicit > f(args) call and only such calls. > > > Python has no general metasyntax for changing the semantics of its syntax. > The __xx__ methods are special cases for the corresponding operators *and* > the corresponding user-defined class. The '__call__' method of a class > applies to instances of that class. Alternative 2: > > Terry thanks for your response. My hoped-for spec explicitly prohibits wrapping required each (user-defined) function to be wrapped individual, since I want to be able to have this wrapping behavior apply to many functions created by many users on the fly, and such users can't be asked to remember to wrap each function. (At most, they can be asked to set a single evironment variable or the like at the beginning of modules or interpreter sessions that should the "turn on wrapping" for all future function calls.) So I suppose the situation is as I feared? That the only way to achieve my goal without having to wrap every (user-defined) function call individually is to modify the interpreter. Is there no way to edit frame objects from inside a function? if I could do that in a settrace function, would it even help? Also: am I right in thinking that the "modified interpreter" approach would mean that my resulting software couldn't be used as a 3-rd party module, that could be easily integrated into existing python installations? Or is there some standard way of integrating dynamically loadable modifications to the interpreter in python? (e.g. so that users of my code wouldn't have to re-install of their existing modules in a separate new python installation?) Thanks! Dan > >> > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Feb 17 19:13:05 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Feb 2010 00:13:05 -0000 Subject: string to list when the contents is a list References: Message-ID: On Wed, 17 Feb 2010 23:48:38 -0000, Wes James wrote: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" If your string is trusted (i.e. goes nowhere near a user), just eval() it. -- Rhodri James *-* Wildebeeste Herder to the Masses From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 19:37:15 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 00:37:15 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On Thu, 18 Feb 2010 11:46:52 +1300, Lawrence D'Oliveiro wrote: > In message , cjw wrote: > >> Aren't lambda forms better described as function? > > Is this a function? > > lambda : None > > What about this? > > lambda : sys.stdout.write("hi there!\n") Of course they are; the first is a function that takes no arguments and returns None, and the second is a function that takes no arguments, returns None, and has a side-effect of writing "hi there\n" to stout. But I imagine you already know that, so I'm not really sure I understand the point of your (rhetorical?) question. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 19:47:20 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 00:47:20 GMT Subject: string to list when the contents is a list References: Message-ID: On Thu, 18 Feb 2010 00:13:05 +0000, Rhodri James wrote: > On Wed, 17 Feb 2010 23:48:38 -0000, Wes James > wrote: > >> I have been trying to create a list form a string. The string will be >> a list (this is the contents will look like a list). i.e. "[]" or >> "['a','b']" > > If your string is trusted (i.e. goes nowhere near a user), just eval() > it. Or use something like YAML or JSON to parse it. Fredrik Lundh has a simple_eval function which should be safe to use: http://effbot.org/zone/simple-iterator-parser.htm But it's fairly simple to parse a simple list like this. Here's a quick and dirty version: def string_to_list(s): s = s.strip() if not s.startswith('[') and s.endswith(']'): raise ValueError s = s[1:-1].strip() items = [item.strip() for item in s.split(',')] for i, item in enumerate(items): items[i] = dequote(item) return items def dequote(s): for delimiter in ('"""', "'''", '"', "'"): if s.startswith(delimiter) and s.endswith(delimiter): n = len(delimiter) return s[n:-n] raise ValueError >>> s = "['a','b']" >>> print s ['a','b'] >>> string_to_list(s) ['a', 'b'] >>> x = string_to_list(s) >>> type(x) >>> x ['a', 'b'] -- Steven From breamoreboy at yahoo.co.uk Wed Feb 17 19:49:45 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Feb 2010 00:49:45 +0000 Subject: Which mock library do you prefer? In-Reply-To: References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: Phlip wrote: > On Feb 17, 6:26 am, Lacrima wrote: > >> Right, isolation is essential. > > Please read my reply: Ben is well intentioned but completely wrong > here. > > Mock abuse will not cure the runtime isolation problem. > I believe that Ben is perfectly correct, and that you are talking at cross purposes because you've missed the significance of his (you later realise) within his post. Runtime test isolation doesn't enter into from what I can see. Can you please clarify the situation one way or the other. TIA. Mark Lawrence. From mccredie at gmail.com Wed Feb 17 19:51:39 2010 From: mccredie at gmail.com (Matt McCredie) Date: Thu, 18 Feb 2010 00:51:39 +0000 (UTC) Subject: string to list when the contents is a list References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> Message-ID: Wes James gmail.com> writes: > > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. > > How can I do this? eval will work, but has a safety issue. It also has the issue of evaluating any and everything that a user might pass in. If you are using python 2.6 check out ast.literal_eval. It uses python's built in ast parser to generate an AST and then traverses it to generate a python object. Unlike eval though, it will raise an exception if anything other than a literal is represented in the string. I have used the same function in python 2.5 (copied from 2.6) and it works just fine. Here is a version modified from the code in python 2.6 that should only parse lists of strings: from _ast import List, Str, PyCF_ONLY_AST def parse(expr, filename='', mode='exec'): """ Parse an expression into an AST node. Equivalent to compile(expr, filename, mode, PyCF_ONLY_AST). """ return compile(expr, filename, mode, PyCF_ONLY_AST) def list_eval(text): """ Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None. """ node = parse(text, mode='eval').body if not isinstance(node, List): raise ValueError('malformed string') def _convert(node): if isinstance(node, Str): return node.s raise ValueError('malformed string') return list(map(_convert, node.elts)) Matt McCredie From ben+python at benfinney.id.au Wed Feb 17 19:58:19 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 11:58:19 +1100 Subject: string to list when the contents is a list References: Message-ID: <87y6irbbro.fsf@benfinney.id.au> Wes James writes: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" Pulling back to ask about the larger problem: Are you trying to create Python data structures from a serialised representation? There are several well-implemented solutions, including the standard library modules ?pickle? and ?json?. Do you have control over the choice of serialisation format? -- \ ?I went to court for a parking ticket; I pleaded insanity. I | `\ said ?Your Honour, who in their right mind parks in the passing | _o__) lane??? ?Steven Wright | Ben Finney From jgardner at jonathangardner.net Wed Feb 17 20:00:50 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:00:50 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: On Feb 17, 10:39?am, John Bokma wrote: > Jonathan Gardner writes: > > Then I looked at a stack trace from a different programming language > > with lots of anonymous functions. (I believe it was perl.) > > > I became enlightened. > > If it was Perl [1], I doubt it. Because line numbers are reported, and > if that doesn't help you, you can annotate anonymous functions with a > nick name using > > local *__ANON__ = 'nice name'; > > Finding an issue, and not looking for a solution is not called becoming > enlightened ;-) > > ~$ perl -e ' > use Carp; > > my $anon = sub { local *__ANON__ = "hello, world"; croak "oops"; }; > $anon->(); > ' > > oops at -e line 4 > ? ? ? ? main::hello, world() called at -e line 5 > > As you can see, and a line number is generated, and the nice name is > shown. > > If you generate anonymouse functions on the fly based on parameters, you > can encode this into the nice name, of course. > > Sadly, often bold statements about a language are made in ignorance. > $ perl -e '$a = sub () {die "it may have been javascript, but"}; $b = sub () {die "I am pretty sure it was perl"}; $b->()' From jgardner at jonathangardner.net Wed Feb 17 20:02:41 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:02:41 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> On Feb 17, 12:02?am, Lawrence D'Oliveiro wrote: > In message > <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, > > Jonathan Gardner wrote: > > I used to think anonymous functions (AKA blocks, etc...) would be a > > nice feature for Python. > > > Then I looked at a stack trace from a different programming language > > with lots of anonymous functions. (I believe it was perl.) > > Didn?t it have source line numbers in it? > > What more do you need? I don't know, but I tend to find the name of the function I called to be useful. It's much more memorable than line numbers, particularly when line numbers keep changing. I doubt it's just me, though. From jgardner at jonathangardner.net Wed Feb 17 20:04:00 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:04:00 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> On Feb 17, 12:02?am, Lawrence D'Oliveiro wrote: > In message <60b1abce-4381-46ab-91ed- > > f2ab2154c... at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: > > Also, lambda's are expressions, not statements ... > > Is such a distinction Pythonic, or not? For example, does Python distinguish > between functions and procedures? Not to the programmer, no. Callables are callable, no matter what they are, and they are all called the same way. (What the heck is a procedure, anyway? Is this different from a subroutine, a method, or a block?) From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 20:06:41 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 01:06:41 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: On Wed, 17 Feb 2010 12:39:30 -0600, John Bokma wrote: > Jonathan Gardner writes: > >> Then I looked at a stack trace from a different programming language >> with lots of anonymous functions. (I believe it was perl.) >> >> I became enlightened. > > If it was Perl [1], I doubt it. Because line numbers are reported, and > if that doesn't help you, you can annotate anonymous functions with a > nick name using > > local *__ANON__ = 'nice name'; [...] > As you can see, and a line number is generated, and the nice name is > shown. Given that it has a nice name, what makes it an anonymous function? It seems to me that Perl effectively has three ways of creating functions, one anonymous and two named (even if one syntax for creating a named function is almost identical to the syntax for creating an anonymous function). Once you annotate a function with a nickname, it's no different from giving it a name. If this is the case, then your answer to "anonymous functions are a PITA" is "don't use anonymous functions", which exactly the same answer we'd give here in Python land. The only difference is that Perl provides two ways of making a named function, and Python only one[1]. [1] Technically, you can make named functions with the new module and a bit of work, so Python has two ways too. -- Steven From jgardner at jonathangardner.net Wed Feb 17 20:13:23 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:13:23 -0800 (PST) Subject: How to efficiently extract information from structured text file References: Message-ID: <0f783ced-0414-4b44-acf1-79f8d288f41c@z10g2000prh.googlegroups.com> On Feb 16, 3:48?pm, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. ?Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. My > questions are > > 1) Is there any efficient method that I can search the whole string > list to find the location of the tokens(such as '= {' or '};' > > 2) Is there any efficient ways to extract the object information you > may suggest? Parse it! Go full-bore with a real parser. You may want to consider one of the many fine Pythonic implementations of modern parsers, or break out more traditional parsing tools. This format is nested, meaning that you can't use regexes to parse what you want out of it. You're going to need a real, full-bore, no- holds-barred parser for this. Don't worry, the road is not easy but the destination is absolutely worth it. Once you come to appreciate and understand parsing, you have earned the right to call yourself a red-belt programmer. To get your black- belt, you'll need to write your own compiler. Having mastered these two tasks, there is no problem you cannot tackle. And once you realize that every program is really a compiler, then you have truly mastered the Zen of Programming in Any Programming Language That Will Ever Exist. With this understanding, you will judge programming language utility based solely on how hard it is to write a compiler in it, and complexity based on how hard it is to write a compiler for it. (Notice there are not a few parsers written in Python, as well as Jython and PyPy and others written for Python!) From rhodri at wildebst.demon.co.uk Wed Feb 17 20:20:42 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Feb 2010 01:20:42 -0000 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 01:04:00 -0000, Jonathan Gardner wrote: > On Feb 17, 12:02 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message <60b1abce-4381-46ab-91ed- >> >> f2ab2154c... at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: >> > Also, lambda's are expressions, not statements ... >> >> Is such a distinction Pythonic, or not? For example, does Python >> distinguish >> between functions and procedures? > > Not to the programmer, no. Callables are callable, no matter what they > are, and they are all called the same way. > > (What the heck is a procedure, anyway? Is this different from a > subroutine, a method, or a block?) In classic Pascal, a procedure was distinct from a function in that it had no return value. The concept doesn't really apply in Python; there are no procedures in that sense, since if a function terminates without supplying an explicit return value it returns None. -- Rhodri James *-* Wildebeeste Herder to the Masses From ben+python at benfinney.id.au Wed Feb 17 20:20:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 12:20:49 +1100 Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: <87tytfbaq6.fsf@benfinney.id.au> Lacrima writes: > Right, isolation [of test cases] is essential. But I can't decide to > which extent I should propagate isolation. You used ?propagate? in a sense I don't understand there. > For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, > author suggests that if you do unittesting you should isolate the > smallest units of code from each other. I'm not sure what the author means, but I would say that as it stands that advice is independent of what testing is being done. In all cases: * Make your code units small, so each one is not doing much and is easy to understand. * Make the interface of units at each level as narrow as feasible, so they're not brittle in the face of changes to the implementation. > For example, if you have a > class: > Class SomeClass(object): > def method1(self): > return 5 > def method2(self): > return self.method1 + 10 > > According to the book, if you want to test method2, you should isolate > it from method1 and class instance('self'). I don't really know what that means. Remember that each test case should not be ?test method1?. That is far too broad, and in some cases too narrow. There is no one-to-one mapping between methods and unit test cases. Instead, each test case should test one true-or-false assertion about the behaviour of the code. ?When we start with this initial state (the test fixture), and perform this operation, the resulting state is that?. It makes a lot of sense to name the test case so the assertion being made *is* its name: not ?test frobnicate? with dozens of assertions, but one ?test_frobnicate_with_valid_spangulator_returns_true? which makes that assertion, and extra ones for each distinct assertion. The failure of a unit test case should indicate *exactly* what has gone wrong. If you want to make multiple assertions about a code unit, write multiple test cases for that unit and name the tests accordingly. This incidentally requires that you test something small enough that such a true-or-false assertion is meaningful, which leads to well-designed code with small easily-tested code units. But that's an emergent property, not a natural law. > Currently, I don't create mocks of units if they are within the same > class with the unit under test. If that is not right approach, please, > explain what are best practices... I am just learning TDD.. In the fixture of the unit test case, create whatever test doubles are necessary to put your code into the initial state you need for the test case; then tear all those down whatever the result of the test case. If you need to create great honking wads of fixtures for any test case, that is a code smell: your code units are too tightly coupled to persistent state, and need to be decoupled with narrow interfaces. The Python ?unittest? module makes this easier by letting you define fixtures common to many test cases (the ?setUp? and ?tearDown? interface). My rule of thumb is: if I need to make different fixtures for some set of test cases, I write a new test case class for those cases. -- \ ?Following fashion and the status quo is easy. Thinking about | `\ your users' lives and creating something practical is much | _o__) harder.? ?Ryan Singer, 2008-07-09 | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 20:38:29 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 01:38:29 GMT Subject: How to efficiently extract information from structured text file References: <0f783ced-0414-4b44-acf1-79f8d288f41c@z10g2000prh.googlegroups.com> Message-ID: On Wed, 17 Feb 2010 17:13:23 -0800, Jonathan Gardner wrote: > And once you realize that every program is really a compiler, then you > have truly mastered the Zen of Programming in Any Programming Language > That Will Ever Exist. In the same way that every tool is really a screwdriver. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 20:39:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 01:39:05 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: On Wed, 17 Feb 2010 17:04:00 -0800, Jonathan Gardner wrote: > (What the heck is a procedure, anyway? Is this different from a > subroutine, a method, or a block?) The name is used in Pascal, which probably means it originated from Fortran or Algol. A subroutine is a generic piece of code which can be re-used by some unspecified mechanism (GOSUB in Basic, by calling it in most other languages). A function is a subroutine that returns a result, and a procedure is a subroutine that doesn't return anything (not even None, or the equivalent thereof) and operates entirely by side-effect. -- Steven From debatem1 at gmail.com Wed Feb 17 20:44:11 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 17 Feb 2010 20:44:11 -0500 Subject: Wrap and intercept function calls In-Reply-To: <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: On Wed, Feb 17, 2010 at 11:04 AM, Dan Yamins wrote: > Really, nobody has any idea about this??? (Sorry to repost.) > > On Tue, Feb 16, 2010 at 7:29 PM, Dan Yamins wrote: >> >> Hi: >> >> I'm wondering what the best way to wrap and modify function calls is. >> Essentially what I want to achieve is to have a function like this: >> >> def Wrap(frame,event,arg): >> ???? if event == 'call': >> ??????? result = PerformCheck(GetArgumentsFromFrame(frame)) >> ??????? if Condition(result): >> ??????????? return result >> ??????? else: >> ??????????? return [normal function call] >> >> called whenever a "call" event is about to occur. >> >> When I say "return result" I mean:? return that data object instead of >> what the function would have returned, and prevent execution of the >> function. >> >> Is there any way to do this using sys.settrace?? Or perhaps something from >> the bdb or pbd module? >> > > In other words, what I'm looking for is a way to intercept all function > calls with a "wrapper" --? like one can do using settrace and other > debugging methods -- but, unlike the debugging methods, have the "wrapping" > function actually be able to intervene in the stack and, for instance, > conditionally replace the function call's return with something determined > in the wrapping function and prevent the function call's execution.?? I want > to be able to do this by setting a single system-wide (or at any rate, > thread-wide) value, like with settrace, and not have to modify individual > functions one by one. > > Could I, for example, set a settrace function that somehow modifies the > stack?? Or is there some much better way to do this?? Or, if someone can > tell me that this can't be done without having to roll my own implementation > of the Python interpreter, that would be great to know too. > > Thanks again, > Dan > > > -- > http://mail.python.org/mailman/listinfo/python-list > > You could drill down through everything in globals() etc, replacing functions as you went, but its fragile (there are probably unworkable corner cases), ugly, and likely to be slow. What exactly is it you're trying to do? Geremy Condra From john at castleamber.com Wed Feb 17 21:23:19 2010 From: john at castleamber.com (John Bokma) Date: Wed, 17 Feb 2010 20:23:19 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: <87ocjncmeg.fsf@castleamber.com> Steven D'Aprano writes: > On Wed, 17 Feb 2010 12:39:30 -0600, John Bokma wrote: [..] >> If it was Perl [1], I doubt it. Because line numbers are reported, and >> if that doesn't help you, you can annotate anonymous functions with a >> nick name using >> >> local *__ANON__ = 'nice name'; > [...] >> As you can see, and a line number is generated, and the nice name is >> shown. > > Given that it has a nice name, what makes it an anonymous function? You can't do nice name(); It just changes what perl reports. > If this is the case, then your answer to "anonymous functions are a > PITA" I don't think anon functions are in general a PITA. Like with most things, (I) use them in moderation. > is "don't use anonymous functions", which exactly the same answer we'd > give here in Python land. The only difference is that Perl provides two > ways of making a named function, and Python only one[1]. Note that the local trick doesn't create a named function. There are other ways of course to create named functions in Perl, e.g. perl -e '*foo=sub { print "hello, world\n" }; foo();' Which can be fun: perl -e ' sub AUTOLOAD { my $name = our $AUTOLOAD; *$AUTOLOAD = sub { local $" = ", "; print "$name(@_)\n" }; goto &$AUTOLOAD; } foo(40); bar("hello", "world!"); baz(foo(10));' output: main::foo(40) main::bar(hello, world!) main::foo(10) main::baz(1) NB: calling foo 10 returns 1 (return value of print). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From showell30 at yahoo.com Wed Feb 17 21:27:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 17 Feb 2010 18:27:41 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> On Feb 17, 5:39?pm, Steven D'Aprano wrote: > On Wed, 17 Feb 2010 17:04:00 -0800, Jonathan Gardner wrote: > > (What the heck is a procedure, anyway? Is this different from a > > subroutine, a method, or a block?) > > The name is used in Pascal, which probably means it originated from > Fortran or Algol. > > A subroutine is a generic piece of code which can be re-used by some > unspecified mechanism (GOSUB in Basic, by calling it in most other > languages). A function is a subroutine that returns a result, and a > procedure is a subroutine that doesn't return anything (not even None, or > the equivalent thereof) and operates entirely by side-effect. > Those are useful clarifications, but they are not completely universal. Some people make the definition of function more restrictive--"if it has side effects, it is not a function." Python's definition of a method is also not universal. In some circles, method is more akin to Steven's definition of a procedure--it does not necessarily have to be associated with a class. It's all very confusing, which is why Pythonistas are typically adamant about clarifying definitions within Python's context, which is understandable. To the extent that we're all talking about one programming language, we should use the same terms. A quick Google search does not turn up an official definition of a Ruby block, although the term "block" is colloquially used in both Python and Ruby to refer to a bunch of lines of code executed in a particular context, like a loop. Python may not support the broadest notion of anonymous functions, but it definitely has anonymous blocks. You can write this in Python: for i in range(10): print i print i * i print i * i * i Python does not force you to do this: def do_stuff(i): print i print i * i print i * i * i for i in range(10): do_stuff(i) From jmheralds at gmail.com Wed Feb 17 21:29:49 2010 From: jmheralds at gmail.com (James Heralds) Date: Wed, 17 Feb 2010 18:29:49 -0800 (PST) Subject: Draft paper submission deadline is extended: SETP-10, Orlando, USA Message-ID: It would be highly appreciated if you could share this announcement with your colleagues, students and individuals whose research is in software engineering, software testing, software quality assurance, software design and related areas. Draft paper submission deadline is extended: SETP-10, Orlando, USA The 2010 International Conference on Software Engineering Theory and Practice (SETP-10) (website: http://www.PromoteResearch.org) will be held during 12-14 of July 2010 in Orlando, FL, USA. SETP is an important event in the areas of Software development, maintenance, and other areas of software engineering and related topics. The conference will be held at the same time and location where several other major international conferences will be taking place. The conference will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary goal of MULTICONF is to promote research and developmental activities in computer science, information technology, control engineering, and related fields. Another goal is to promote the dissemination of research to a multidisciplinary audience and to facilitate communication among researchers, developers, practitioners in different fields. The following conferences are planned to be organized as part of MULTICONF-10. ? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-10) ? International Conference on Automation, Robotics and Control Systems (ARCS-10) ? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-10) ? International Conference on Computer Communications and Networks (CCN-10) ? International Conference on Enterprise Information Systems and Web Technologies (EISWT-10) ? International Conference on High Performance Computing Systems (HPCS-10) ? International Conference on Information Security and Privacy (ISP-10) ? International Conference on Image and Video Processing and Computer Vision (IVPCV-10) ? International Conference on Software Engineering Theory and Practice (SETP-10) ? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-10) MULTICONF-10 will be held at Imperial Swan Hotel and Suites. It is a full-service resort that puts you in the middle of the fun! Located 1/2 block south of the famed International Drive, the hotel is just minutes from great entertainment like Walt Disney World? Resort, Universal Studios and Sea World Orlando. Guests can enjoy free scheduled transportation to these theme parks, as well as spacious accommodations, outdoor pools and on-site dining ? all situated on 10 tropically landscaped acres. Here, guests can experience a full- service resort with discount hotel pricing in Orlando. We invite draft paper submissions. Please see the website http://www.PromoteResearch.org for more details. From wuwei23 at gmail.com Wed Feb 17 21:42:44 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Feb 2010 18:42:44 -0800 (PST) Subject: Wrap and intercept function calls References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: Terry Reedy wrote: > Now wrap *every* function you are interested in. Builtin functions are > no problem; methods of builtin classes cannont be wrapped without > subclassing. It's a shame it's not possible to do: type.__call__ = func_wrap(type.__call__) Or even: type.__class__ = NewType From andrej.mitrovich at gmail.com Wed Feb 17 21:59:14 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Feb 2010 18:59:14 -0800 (PST) Subject: Traversing through variable-sized lists References: <4B7C4284.8070709@optimum.net> <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> Message-ID: <5906ad53-5853-4021-8af6-8b91b2a7e3e5@g11g2000yqe.googlegroups.com> On Feb 17, 11:56?pm, Dave Angel wrote: > Andrej Mitrovic wrote: > > On Feb 17, 8:24 pm, John Posner wrote: > > >> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: > > >> > > > However the values list might have an uneven number of items. I would > > like to make it as evenly distributed as possible, e.g.: > > > values =-2, -1, 0] > > frames =obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8] > > > frames[0].func(values[0]) ?# func.(values[-2]) > > frames[1].func(values[0]) ?# func.(values[-2]) > > frames[2].func(values[1]) ?# func.(values[-2]) > > frames[3].func(values[1]) ?# func.(values[-1]) > > frames[4].func(values[1]) ?# func.(values[-1]) > > frames[5].func(values[2]) ?# func.(values[-1]) > > frames[6].func(values[2]) ?# func.(values[0]) > > frames[7].func(values[2]) ?# func.(values[0]) > > > I'll be even more specific. I have a Minimum and Maximum value that > > the user enters. The frame.func() function is a "translate" function, > > it basically moves a frame in the application in one direction or > > another depending on the argument value. So frame[0].func(2) would > > move the frame[0] 2 pixels to the right. So what I want is the > > function to create a smooth transition of all the frames from the > > Minimum to the Maximum value. If minimum was 0, and maximum was 10, > > I'd want the first frame moved 0 pixels (it stays in place), the last > > frame to move 10 pixels, and the frames between are gradually moved > > from 1 pixels to 9 pixels relative from their positions. > > > Perhaps I'm just overcomplicating. I'll have a look at some drawing > > apps and see how they've implemented drawing straight lines under an > > angle, I guess that could be called a gradual change of values. > > > Thanks for all the suggestions everyone, I'll have a look at the rest > > shortly. > > I think you're overcomplicating. ?If you have 27 frames, and you want > frame 0 to move 0 pixels, and frame 27 to move 10 pixels, then you want > to move frame[i] by i*10/27. ?And since you do the multiply first, the > fact that Python 2.x division gives you integers isn't a problem. > > There are fancier methods for drawing lines (bresenham for example), but > the main purpose of them is to to avoid multiply and divide, as well as > floats. ?But in Python, an integer multiply is just as fast as an add or > subtract, so there's no point. > > DaveA Doh! Such a simple solution, just what I was looking for. Thanks! From showell30 at yahoo.com Wed Feb 17 22:10:31 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 17 Feb 2010 19:10:31 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: On Feb 16, 4:19?pm, Jonathan Gardner wrote: > On Feb 16, 11:41?am, Andrej Mitrovic > wrote: > > > > > On Feb 16, 7:38?pm, Casey Hawthorne > > wrote: > > > > Interesting talk on Python vs. Ruby and how he would like Python to > > > have just a bit more syntactic flexibility. > > > >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > > > -- > > > Regards, > > > Casey > > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > > linked to): "Python has no comparable equivalent to Ruby?s do end > > block. Python lambdas are limited to one line and can?t contain > > statements (for, if, def, etc.). Which leaves me wondering, what?s the > > point?" > > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > > expressions, not statements, but you can pass them around, keep them > > in a dictionary if you want to. And if you need more than one line of > > statements, for crying out loud use a def? And who needs those "do- > > end" blocks anyway, trying to turn Python into Pascal? > > I used to think anonymous functions (AKA blocks, etc...) would be a > nice feature for Python. > > Then I looked at a stack trace from a different programming language > with lots of anonymous functions. (I believe it was perl.) > > I became enlightened. I use Ruby a lot in my day job, and we rarely use blocks are as anonymous callback functions, which was probably the source of your pain in other languages. Often Ruby blocks are just three or four lines of code that are inlined into a still small function, so as long as the outer function is still small (which Ruby's blocks help with--they promote terseness), it's pretty easy to find a buggy function within a traceback that is not overly big. It's also possible in Ruby to use quality-promoting techniques like unit testing, pair programming, deliberateness, etc., to avoid the need for looking at tracebacks in the first place. Python is not immune to hard-to-understand tracebacks, since you often don't often know how a method got itself into the stracktrace in the first place: Traceback (most recent call last): File "foo.py", line 11, in foo(method) File "foo.py", line 2, in foo method() File "foo.py", line 5, in bar raise Exception('I am broken!') Exception: I am broken! Even though there's no direct lexical reference to bar() in foo(), lo and behold, foo() ends up calling bar(): def foo(method): method() def bar(): raise Exception('I am broken!') def broken_function_factory(): return bar method = broken_function_factory() foo(method) From pavlovevidence at gmail.com Wed Feb 17 22:18:14 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 17 Feb 2010 19:18:14 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: On Feb 17, 10:39?am, John Bokma wrote: > Jonathan Gardner writes: > > Then I looked at a stack trace from a different programming language > > with lots of anonymous functions. (I believe it was perl.) > > > I became enlightened. > > If it was Perl [1], I doubt it. Because line numbers are reported Ok so sonetimes I'm looking at a stack trace and sometimes I can tell what the bug is just by lookong at the function namess. But if it has just line numbers I have to dig through my code looking for the line. > and > if that doesn't help you, you can annotate anonymous functions with a > nick name using > > local *__ANON__ = 'nice name'; > > Finding an issue, and not looking for a solution is not called becoming > enlightened ;-) The issue is that a stacktrace showing a bunch of nameless line numbers can be a bad idea, not that Perl might be deficient (and we already know that in any case), so it's not good to use a lot of them. Anyway once you annotate an anonymous function, it's no longer anonymous. > ~$ perl -e ' > use Carp; > > my $anon = sub { local *__ANON__ = "hello, world"; croak "oops"; }; > $anon->(); > ' > > oops at -e line 4 > ? ? ? ? main::hello, world() called at -e line 5 > > As you can see, and a line number is generated, and the nice name is > shown. > > If you generate anonymouse functions on the fly based on parameters, you > can encode this into the nice name, of course. > > Sadly, often bold statements about a language are made in ignorance. I don't see what he said was any kind of a bold statement about a language, arguably it was about the coding style. That Perl allows annotating functions doesn't mean people do it. Carl Banks > > [1] perl is the program that executes Perl programs ;-). > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development From philip at semanchuk.com Wed Feb 17 22:27:27 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Feb 2010 22:27:27 -0500 Subject: Python 3.0 usage? Message-ID: Hi all, I'm the author of an extension (posix_ipc) that works under Python 2.4 - 2.6. I have a version that works under Python 2.4-2.6 and 3.1 and I would like to release it, but it doesn't work under Python 3.0. I could hack up Python 3.0-specific workarounds, but I'm not sure it's worth it. I'm interested in opinions -- is Python 3.0 seeing use in production anywhere, or did most of the Python world move to 3.1 as soon as it was released? Thanks Philip From wolftracks at invalid.com Wed Feb 17 22:36:13 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:36:13 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters (the latest) In-Reply-To: References: Message-ID: <4B7CB5AD.6000900@invalid.com> > On 17 February 2010 07:25, wrote: > > On Wed, Feb 17, 2010 at 12:10 AM, Wayne Watson > > wrote: >> >> Hi, I'm working on a 1800+ line program that uses tkinter. Here are the >> >> messages I started getting recently. (I finally figured out how to copy >> >> them.). The program goes merrily on its way despite them. >> >> >> >> >> >> s\sentuser>sentuser_20080716NoiseStudy7.py >> >> C:\Python25\lib\site-packages\scipy\misc\__init__.py:25: >> >> DeprecationWarning: Num >> >> pyTest will be removed in the next release; please update your code to >> >> use nose >> >> or unittest >> >> test = NumpyTest().test > > > > DeprecationWarnings mean some some functionality in numpy (or scipy) > > has changed and the old way of doing things will be removed and be > > invalid in the next version. > > > > During depreciation the old code still works, but before you upgrade > > you might want to check whether and how much you use these functions > > and switch to the new behavior. > > > > In the case of numpy.test, it means that if you have tests written > > that use the numpy testing module, then you need to switch them to the > > new nose based numpy.testing. And you need to install nose for running > > numpy.test() Wayne - The DeprecationWarnings are being raised by SciPy, not by your code. You probably don't have a recent version of SciPy installed. The most recent release of SciPy is 0.7.1 and works with NumPy 1.3.0. I don't think you will see the warnings if you upgrade SciPy and NumPy on your system. Check your NumPy and SciPy versions at a python prompt as follows: >>> >>> import numpy as np >>> >>> print np.__version__ >>> >>> import scipy as sp >>> >>> print sp.__version__ You will need to completely remove the old versions if you choose to upgrade. You should be able to do this from "Add/Remove Programs". Cheers, Scott _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion at scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion From wolftracks at invalid.com Wed Feb 17 22:36:24 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:36:24 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters (the latest) In-Reply-To: References: Message-ID: <4B7CB5B8.3010000@invalid.com> > On 17 February 2010 07:25, wrote: > > On Wed, Feb 17, 2010 at 12:10 AM, Wayne Watson > > wrote: >> >> Hi, I'm working on a 1800+ line program that uses tkinter. Here are the >> >> messages I started getting recently. (I finally figured out how to copy >> >> them.). The program goes merrily on its way despite them. >> >> >> >> >> >> s\sentuser>sentuser_20080716NoiseStudy7.py >> >> C:\Python25\lib\site-packages\scipy\misc\__init__.py:25: >> >> DeprecationWarning: Num >> >> pyTest will be removed in the next release; please update your code to >> >> use nose >> >> or unittest >> >> test = NumpyTest().test > > > > DeprecationWarnings mean some some functionality in numpy (or scipy) > > has changed and the old way of doing things will be removed and be > > invalid in the next version. > > > > During depreciation the old code still works, but before you upgrade > > you might want to check whether and how much you use these functions > > and switch to the new behavior. > > > > In the case of numpy.test, it means that if you have tests written > > that use the numpy testing module, then you need to switch them to the > > new nose based numpy.testing. And you need to install nose for running > > numpy.test() Wayne - The DeprecationWarnings are being raised by SciPy, not by your code. You probably don't have a recent version of SciPy installed. The most recent release of SciPy is 0.7.1 and works with NumPy 1.3.0. I don't think you will see the warnings if you upgrade SciPy and NumPy on your system. Check your NumPy and SciPy versions at a python prompt as follows: >>> >>> import numpy as np >>> >>> print np.__version__ >>> >>> import scipy as sp >>> >>> print sp.__version__ You will need to completely remove the old versions if you choose to upgrade. You should be able to do this from "Add/Remove Programs". Cheers, Scott _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion at scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion From wolftracks at invalid.com Wed Feb 17 22:39:41 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:39:41 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters (the latest) Message-ID: Had trouble posting this to the same thread above. Request above to provide response from numpy mail list. > On 17 February 2010 07:25, wrote: > > On Wed, Feb 17, 2010 at 12:10 AM, Wayne Watson > > wrote: >> >> Hi, I'm working on a 1800+ line program that uses tkinter. Here are the >> >> messages I started getting recently. (I finally figured out how to copy >> >> them.). The program goes merrily on its way despite them. >> >> >> >> >> >> s\sentuser>sentuser_20080716NoiseStudy7.py >> >> C:\Python25\lib\site-packages\scipy\misc\__init__.py:25: >> >> DeprecationWarning: Num >> >> pyTest will be removed in the next release; please update your code to >> >> use nose >> >> or unittest >> >> test = NumpyTest().test > > > > DeprecationWarnings mean some some functionality in numpy (or scipy) > > has changed and the old way of doing things will be removed and be > > invalid in the next version. > > > > During depreciation the old code still works, but before you upgrade > > you might want to check whether and how much you use these functions > > and switch to the new behavior. > > > > In the case of numpy.test, it means that if you have tests written > > that use the numpy testing module, then you need to switch them to the > > new nose based numpy.testing. And you need to install nose for running > > numpy.test() Wayne - The DeprecationWarnings are being raised by SciPy, not by your code. You probably don't have a recent version of SciPy installed. The most recent release of SciPy is 0.7.1 and works with NumPy 1.3.0. I don't think you will see the warnings if you upgrade SciPy and NumPy on your system. Check your NumPy and SciPy versions at a python prompt as follows: >>> >>> import numpy as np >>> >>> print np.__version__ >>> >>> import scipy as sp >>> >>> print sp.__version__ You will need to completely remove the old versions if you choose to upgrade. You should be able to do this from "Add/Remove Programs". Cheers, Scott _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion at scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion From wolftracks at invalid.com Wed Feb 17 22:42:28 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:42:28 -0800 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 In-Reply-To: References: Message-ID: On 2/17/2010 3:44 AM, mk wrote: > W. eWatson wrote: > > > P.S. I didn't really use PyInstaller on Windows, though -- just on > Linux, where it works beautifully. > > Regards, > mk > Well,Ive made some progress with a py2exe tutorial. It starts with the short "hello world!" program. But something stumbled right away in setup.py. I'm on a mail list to sort this out. From python at mrabarnett.plus.com Wed Feb 17 22:51:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Feb 2010 03:51:11 +0000 Subject: Python 3.0 usage? In-Reply-To: References: Message-ID: <4B7CB92F.9050100@mrabarnett.plus.com> Philip Semanchuk wrote: > Hi all, > I'm the author of an extension (posix_ipc) that works under Python 2.4 - > 2.6. I have a version that works under Python 2.4-2.6 and 3.1 and I > would like to release it, but it doesn't work under Python 3.0. I could > hack up Python 3.0-specific workarounds, but I'm not sure it's worth it. > I'm interested in opinions -- is Python 3.0 seeing use in production > anywhere, or did most of the Python world move to 3.1 as soon as it was > released? > Python 3.0 had a relatively short run before it was superseded by Python 3.1 due to certain issues, so, IMHO, I wouldn't worry about it unless someone especially requests/requires it. From no.email at nospam.invalid Wed Feb 17 23:13:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 17 Feb 2010 20:13:59 -0800 Subject: MediaWiki to RTF/Word/PDF References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: <7xfx4zp4e0.fsf@ruckus.brouhaha.com> Josh English writes: > Has anyone heard of a module that parses wiki markup and transforms > it? Or am I looking at XSLT? MediaWiki markup is quite messy and unless MediaWiki has an XML export feature that I don't know about, I don't see what good XSLT can do you. (The regular MediaWiki API generates XML results with wiki markup embedded in it). It looks like mediawiki itself can create pdf's (see any page on en.wikibooks.org for example), but the rendered pdf is not that attractive. I remember something about a Haskell module to parse mediawiki markup, if that is of any use. From rogerb at rogerbinns.com Thu Feb 18 00:19:54 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 17 Feb 2010 21:19:54 -0800 Subject: Python 3.0 usage? In-Reply-To: References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Philip Semanchuk wrote: > is Python 3.0 seeing use in production > anywhere, or did most of the Python world move to 3.1 as soon as it was > released? Python 3.0 has been end of lifed: http://www.python.org/download/releases/3.0.1/ Consequently no one should be using it in production. Incidentally my own extension is in a similar situation to yours - Python 2.3 onwards is supported for the 2.x family. I did support 3.0 from beta releases onwards but various changes in the library between 3.0 and 3.1 and the end of lifing of 3.0 meant I dropped 3.0 support. No one has asked for it since. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkt8zfoACgkQmOOfHg372QS2cACgznTcQXRcxMqqlfIt4F0C2TaX d9IAoNhkY1dvX1aKlONyVGIL2zplNNF7 =jM8O -----END PGP SIGNATURE----- From wuwei23 at gmail.com Thu Feb 18 00:20:15 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Feb 2010 21:20:15 -0800 (PST) Subject: Python 3.0 usage? References: Message-ID: MRAB wrote: > Python 3.0 had a relatively short run before it was superseded by Python > 3.1 due to certain issues, so, IMHO, I wouldn't worry about it unless > someone especially requests/requires it. And even then, I'd just tell them I accept patches :) From sreejithemk at gmail.com Thu Feb 18 01:48:43 2010 From: sreejithemk at gmail.com (Sreejith K) Date: Wed, 17 Feb 2010 22:48:43 -0800 (PST) Subject: Creating Import Hooks Message-ID: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Hi everyone, I need to implement custom import hooks for an application (http:// www.python.org/dev/peps/pep-0302/). I want to restrict an application to import certain modules (say socket module). Google app engine is using a module hook to do this (HardenedModulesHook in google/ appengine/tools/dev_appserver.py). But I want to allow that application to use an sdk module (custom) which imports and uses socket module. But the module hook restricts the access by sdk. Finding out, which file is importing a module give a solution?? ie. If the application is importing socket module, I want to restrict it. But if the sdk module is importing socket I want to allow it. Is there any way I can do this ? Application ======== import sdk import socket # I dont want to allow this (need to raise ImportError) SDK ==== import socket # need to allow this From jgardner at jonathangardner.net Thu Feb 18 03:03:51 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 00:03:51 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Feb 17, 10:48?pm, Sreejith K wrote: > Hi everyone, > > I need to implement custom import hooks for an application (http://www.python.org/dev/peps/pep-0302/). I want to restrict an application > to import certain modules (say socket module). Google app engine is > using a module hook to do this (HardenedModulesHook in google/ > appengine/tools/dev_appserver.py). But I want to allow that > application to use an sdk module (custom) which imports and uses > socket module. But the module hook restricts the access by sdk. > Finding out, which file is importing a module give a solution?? ie. If > the application is importing socket module, I want to restrict it. But > if the sdk module is importing socket I want to allow it. Is there any > way I can do this ? > > Application > ======== > import sdk > import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > ImportError) > > SDK > ==== > import socket ? ? ? ? ? ? ? # need to allow this SDK === import socket App === import SDK import sys socket = sys.modules['socket'] From timr at probo.com Thu Feb 18 03:07:02 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 18 Feb 2010 00:07:02 -0800 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> Message-ID: <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> DANNY wrote: > >Hm, well I see that and now I am thinking of using reference software >for MPEG4/10 which is written in c++ http://iphome.hhi.de/suehring/tml/ >just to use it as a decoder on my client side, save the file in that >format and then play it in my player using pyffmpeg >http://code.google.com/p/pyffmpeg/ and just manipulate frames in that >clip-I think that could be possible....am I right? After you have passed the video through a decoder, it's no longer in MPEG format at all. It's just a series of bitmaps, so pyffmpeg wouldn't apply. If you want to save the raw MPEG data, you can certainly do that, but such data is often not divided into "frames". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steven at REMOVE.THIS.cybersource.com.au Thu Feb 18 03:57:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 08:57:01 GMT Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > On Feb 17, 10:48?pm, Sreejith K wrote: >> Hi everyone, >> >> I need to implement custom import hooks for an application >> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an >> application to import certain modules (say socket module). Google app >> engine is using a module hook to do this (HardenedModulesHook in >> google/ appengine/tools/dev_appserver.py). But I want to allow that >> application to use an sdk module (custom) which imports and uses socket >> module. But the module hook restricts the access by sdk. Finding out, >> which file is importing a module give a solution?? ie. If the >> application is importing socket module, I want to restrict it. But if >> the sdk module is importing socket I want to allow it. Is there any way >> I can do this ? >> >> Application >> ======== >> import sdk >> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise >> ImportError) >> >> SDK >> ==== >> import socket ? ? ? ? ? ? ? # need to allow this > > > SDK > === > import socket > > App > === > import SDK > import sys > socket = sys.modules['socket'] I'm not sure, but I think Sreejith wants to prohibit imports from the App layer while allowing them from the SDK layer, not work around a prohibition in the SDK layer. In other words, he wants the import hook to do something like this: if module is socket and the caller is not SKD: prohibit else allow I could be wrong of course. -- Steven From lallous at lgwm.org Thu Feb 18 04:09:58 2010 From: lallous at lgwm.org (lallous) Date: Thu, 18 Feb 2010 01:09:58 -0800 (PST) Subject: Python library for working with simple equations Message-ID: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Hello Is there is any Python library that allow such things: Given a string expression as: x + 5 + x * (y + 2), any library that can develop the equation for example. Or if we say factor with "x" then it renders the expression with x * ( rest of expression ). There could be a functionality where when x,y are given then the expression can be evaluated. If there are two expressions, they can be added and the symbols preserved. Does such a thing exist? Thanks, Elias From clp2 at rebertia.com Thu Feb 18 04:17:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Feb 2010 01:17:42 -0800 Subject: Python library for working with simple equations In-Reply-To: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: <50697b2c1002180117v7f9cd5e5rbcf4276581369468@mail.gmail.com> On Thu, Feb 18, 2010 at 1:09 AM, lallous wrote: > Hello > > Is there is any Python library that allow such things: > > Given a string expression as: x + 5 + x * (y + 2), any library that > can develop the equation for example. > Or if we say factor with "x" then it renders the expression with x * > ( rest of expression ). > There could be a functionality where when x,y are given then the > expression can be evaluated. > If there are two expressions, they can be added and the symbols > preserved. > > Does such a thing exist? They're called computer algebra systems: http://en.wikipedia.org/wiki/Computer_algebra_system SymPy is one for Python: http://code.google.com/p/sympy/ Don't know if it supports factoring specifically; I've never used it, I just have Google-Fu. Cheers, Chris -- http://blog.rebertia.com From duncan.booth at invalid.invalid Thu Feb 18 04:23:29 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Feb 2010 09:23:29 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> Message-ID: Jonathan Gardner wrote: > On Feb 17, 12:02?am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message >> <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, >> >> Jonathan Gardner wrote: >> > I used to think anonymous functions (AKA blocks, etc...) would be a >> > nice feature for Python. >> >> > Then I looked at a stack trace from a different programming >> > language with lots of anonymous functions. (I believe it was perl.) >> >> Didn?t it have source line numbers in it? >> >> What more do you need? > > I don't know, but I tend to find the name of the function I called to > be useful. It's much more memorable than line numbers, particularly > when line numbers keep changing. > > I doubt it's just me, though. Some problems with using just line numbers to track errors: In any language it isn't much use if you get a bug report from a shipped program that says there was an error on line 793 but no report of exactly which version of the shipped code was being run. Microsoft love telling you the line number: if IE gets a Javascript error it reports line number but not filename, so you have to guess which of the HTML page or one of many included files actually had the error. Plus the line number that is reported is often slightly off. Javascript in particular is often sent to the browser compressed then uncompressed and eval'd. That makes line numbers completely useless for tracking down bugs as you'll always get the line number of the eval. Also the way functions are defined in Javascript means you'll often have almost every function listed in a backtrace as 'Anonymous'. -- Duncan Booth http://kupuguy.blogspot.com From fetchinson at googlemail.com Thu Feb 18 04:24:10 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 10:24:10 +0100 Subject: Python library for working with simple equations In-Reply-To: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: > Given a string expression as: x + 5 + x * (y + 2), any library that > can develop the equation for example. > Or if we say factor with "x" then it renders the expression with x * > ( rest of expression ). > There could be a functionality where when x,y are given then the > expression can be evaluated. > If there are two expressions, they can be added and the symbols > preserved. Take a look at sage: http://www.sagemath.org/ I wouldn't say it's simple, in fact it's huge, but it'll do the job. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From sreejithemk at gmail.com Thu Feb 18 04:28:37 2010 From: sreejithemk at gmail.com (Sreejith K) Date: Thu, 18 Feb 2010 01:28:37 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Feb 18, 1:57?pm, Steven D'Aprano wrote: > On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > > On Feb 17, 10:48?pm, Sreejith K wrote: > >> Hi everyone, > > >> I need to implement custom import hooks for an application > >> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an > >> application to import certain modules (say socket module). Google app > >> engine is using a module hook to do this (HardenedModulesHook in > >> google/ appengine/tools/dev_appserver.py). But I want to allow that > >> application to use an sdk module (custom) which imports and uses socket > >> module. But the module hook restricts the access by sdk. Finding out, > >> which file is importing a module give a solution?? ie. If the > >> application is importing socket module, I want to restrict it. But if > >> the sdk module is importing socket I want to allow it. Is there any way > >> I can do this ? > > >> Application > >> ======== > >> import sdk > >> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > >> ImportError) > > >> SDK > >> ==== > >> import socket ? ? ? ? ? ? ? # need to allow this > > > SDK > > === > > import socket > > > App > > === > > import SDK > > import sys > > socket = sys.modules['socket'] > > I'm not sure, but I think Sreejith wants to prohibit imports from the App > layer while allowing them from the SDK layer, not work around a > prohibition in the SDK layer. > > In other words, he wants the import hook to do something like this: > > if module is socket and the caller is not SKD: > ? ? prohibit > else > ? ? allow > > I could be wrong of course. > > -- > Steven @Steven, Thats exactly what I want.. Anyway to do that ?? From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 04:43:17 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 10:43:17 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> Message-ID: <4b7d0baa$0$13729$426a74cc@news.free.fr> Mark Lawrence a ?crit : > Ben Finney wrote: >> Bruno Desthuilliers writes: >> >>> Mmmm... Let's try to explain the whole damn thing. It's really (and >>> IMHO beautifully) simple once you get it, but I agree it's a bit >>> peculiar when compared to most mainstream OO languages. >> [?] >> >> Bruno, that's the first time I've understood the descriptor protocol, or >> even understood *why* the descriptor protocol is important. >> >> Could you please post (a version of) this as a separate article >> somewhere? A weblog post, or a new thread in this forum, or in the >> documentation? Somewhere that web searches will find it prominently when >> searching for the Python descriptor protocol. >> >> Thank you. >> > > I'll second, third and fourth this request. More please Bruno, or from > anybody similarly qualified. > > Thanks very much. First, thanks Ben and Mark for the kind words... I never tried to google for them, but there must be at least 4 previous posts here where I tried to explain the topic. Perhaps this latest attempt was better ?-) But anyway : if it's about making this text easier to find, it seems that posting it here is not the most efficient solution !-) Anyway : I don't have a blog and don't really have enough time / motivation for blogging. Now if anyone is willing and able to host such a text on his own website / blog / whatever, I'd be happy to rework it a bit. /wrt to have it in the documentation and the "from anybody similarly qualified", there's already a pretty comprehensive article in the official docs (well : linked from the official docs), from someone who's _way_ more qualified that I'll ever be - FWIW, everything I explained here and all my knowledge of the descriptor protocol, methods etc come from this article: http://users.rcn.com/python/download/Descriptor.htm But I understand it can be a bit intimidating for newcomers, so yes, perhaps a lighter introductory text could be helpful. So guys, if you think a revised version of my post would be of interest, I'll take you on words: provide the hosting, I'll provide the content !-) B. From danijel.gvero at gmail.com Thu Feb 18 04:50:14 2010 From: danijel.gvero at gmail.com (DANNY) Date: Thu, 18 Feb 2010 01:50:14 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> Message-ID: <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> If I want to have a MPEG-4/10 coded video and stream it through the network and than have the same video on the client side, what should I use and of course I don't want to have raw MPEG data, because than I couldn't extract the frames to manipulate them. From mrkafk at gmail.com Thu Feb 18 04:59:40 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 10:59:40 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <7a9c25c21002171051o4bc48483qbb82cc65668434f6@mail.gmail.com> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <7a9c25c21002171051o4bc48483qbb82cc65668434f6@mail.gmail.com> Message-ID: Stephen Hansen wrote: > Or just leave it as a top level function where it was perfectly happy to > live :) Yes. This is probably the sanest solution anyway, because probably having many such functions to use, packing them into smth like package.utils anyway is a good idea. I'm trying mainly to learn and test-drive such solutions, not that I would be keen to use them excessively in production code. > This obviously means no other method can call it like > self.print_internal_date(), because self would get passed as first > argument, yes? > > > It doesn't have to be. It could be a class method-- @classmethod does > that, makes it receive 'cls' the actual class as the first argument. Or > a @staticmethod, in which case it has no first-argument at all. Ahh now I get it. Thanks! So that's the use for @staticmethod (I was wondering if there was any). From snakylove at googlemail.com Thu Feb 18 05:09:39 2010 From: snakylove at googlemail.com (Snaky Love) Date: Thu, 18 Feb 2010 02:09:39 -0800 (PST) Subject: How to use AWS/PAA nowadays? PyAWS / pyamazon outdated? Message-ID: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> Hi, is anybody aware of any updated and / or maintained library for accessing AWS/PAA with Python? I found the dusty pyamazon and a derivate of it, pyaws, but both of them do not seem to support request signatures which must be used by August 15, 2009 to use the Amazon Services, and generally seem to be a little bit outdated... Is there a better way doing signed requests to AWS/PAA nowadays? How are you doing it? I found a good PHP Library here: http://getcloudfusion.com/docs - but I would like to program stuff with python - is there anything pythonic that is close to that? Thank you very much for your attention, have a nice day, Snaky From ben+python at benfinney.id.au Thu Feb 18 05:36:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 21:36:30 +1100 Subject: Referring to class methods in class attributes References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> <4b7d0baa$0$13729$426a74cc@news.free.fr> Message-ID: <87d402bzkh.fsf@benfinney.id.au> Bruno Desthuilliers writes: > perhaps a lighter introductory text could be helpful. So guys, if you > think a revised version of my post would be of interest, I'll take you > on words: provide the hosting, I'll provide the content !-) Here, let me work my hosting magic: . -- \ ?Choose mnemonic identifiers. If you can't remember what | `\ mnemonic means, you've got a problem.? ?Larry Wall | _o__) | Ben Finney From leo at lspace.org Thu Feb 18 05:46:58 2010 From: leo at lspace.org (Leo Breebaart) Date: 18 Feb 2010 10:46:58 GMT Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: <7u4k52F6jsU1@mid.individual.net> Arnaud Delobelle writes: > Descriptors to the rescue :) > > def read_body_from(filename): > print "** loading content **" > return "" % filename > > # This is a kind of class property > class TemplateFilename(object): > def __get__(self, obj, cls): > return "%s.tmpl" % cls.__name__ > > # And this is a kind of cached class property > class TemplateBody(object): > def __get__(self, obj, cls): > try: > return cls._body > except AttributeError: > cls._body = read_body_from(cls.template_filename) > return cls._body > > class Foo(object): > template_filename = TemplateFilename() > template_body = TemplateBody() > > class FooA(Foo): > pass > > class FooB(Foo): > pass Very enlightening, thanks! By the way, I completely agree with the other posters in this thread that intricate solutions such as this are likely to be overkill, especially since at this point I have no idea if the inefficiency of reading those templates multiple times would at all matter (frankly, I'd doubt it). But it's certainly been educational to learn about these techniques. One observation: if I implement the descriptor solution as given above, the code works perfectly, but running the code through pychecker now causes an error, because that again causes an attempt to read from the non-existant base class template file "Foo.tmpl"... -- Leo Breebaart From jeanmichel at sequans.com Thu Feb 18 05:49:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Feb 2010 11:49:28 +0100 Subject: Creating Import Hooks In-Reply-To: References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: <4B7D1B38.6080800@sequans.com> Sreejith K wrote: > On Feb 18, 1:57 pm, Steven D'Aprano > wrote: > >> On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: >> >>> On Feb 17, 10:48 pm, Sreejith K wrote: >>> >>>> Hi everyone, >>>> >>>> I need to implement custom import hooks for an application >>>> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an >>>> application to import certain modules (say socket module). Google app >>>> engine is using a module hook to do this (HardenedModulesHook in >>>> google/ appengine/tools/dev_appserver.py). But I want to allow that >>>> application to use an sdk module (custom) which imports and uses socket >>>> module. But the module hook restricts the access by sdk. Finding out, >>>> which file is importing a module give a solution?? ie. If the >>>> application is importing socket module, I want to restrict it. But if >>>> the sdk module is importing socket I want to allow it. Is there any way >>>> I can do this ? >>>> >>>> Application >>>> ======== >>>> import sdk >>>> import socket # I dont want to allow this (need to raise >>>> ImportError) >>>> >>>> SDK >>>> ==== >>>> import socket # need to allow this >>>> >>> SDK >>> === >>> import socket >>> >>> App >>> === >>> import SDK >>> import sys >>> socket = sys.modules['socket'] >>> >> I'm not sure, but I think Sreejith wants to prohibit imports from the App >> layer while allowing them from the SDK layer, not work around a >> prohibition in the SDK layer. >> >> In other words, he wants the import hook to do something like this: >> >> if module is socket and the caller is not SKD: >> prohibit >> else >> allow >> >> I could be wrong of course. >> >> -- >> Steven >> > > @Steven, Thats exactly what I want.. Anyway to do that ?? > import sys sys.modules['socket'] = None import socket --------------------------------------------------------------------------- ImportError Traceback (most recent call last) ImportError: No module named socket JM From fetchinson at googlemail.com Thu Feb 18 05:50:13 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 11:50:13 +0100 Subject: Python library for working with simple equations In-Reply-To: References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: >> Given a string expression as: x + 5 + x * (y + 2), any library that >> can develop the equation for example. >> Or if we say factor with "x" then it renders the expression with x * >> ( rest of expression ). >> There could be a functionality where when x,y are given then the >> expression can be evaluated. >> If there are two expressions, they can be added and the symbols >> preserved. > > Take a look at sage: http://www.sagemath.org/ > I wouldn't say it's simple, in fact it's huge, but it'll do the job. Probably you can isolate the part of sage that you actually need and can throw away 95% of it. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From d.dalton at iinet.net.au Thu Feb 18 06:09:05 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 18 Feb 2010 22:09:05 +1100 Subject: working with laptop battery In-Reply-To: <7f014ea61002131819x4ba766dds245220760ef74ff1@mail.gmail.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> <7f014ea61002131819x4ba766dds245220760ef74ff1@mail.gmail.com> Message-ID: <20100218110905.GB30547@debian-eeepc> On Sat, Feb 13, 2010 at 09:19:59PM -0500, Chris Colbert wrote: > You'll need acpi installed: > In [6]: import subprocess Thanks for that code, I'll try putting something together this weekend. Dan From d.dalton at iinet.net.au Thu Feb 18 06:11:51 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 18 Feb 2010 22:11:51 +1100 Subject: working with laptop battery In-Reply-To: <4B775EA0.7080207@tim.thechases.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> <4B775EA0.7080207@tim.thechases.com> Message-ID: <20100218111151.GA31441@debian-eeepc> I'm not sure I have those files, but I'll look a little harder this weekend when I put together the script. Thanks for your help, Dan On Sat, Feb 13, 2010 at 08:23:28PM -0600, Tim Chase wrote: > Daniel Dalton wrote: > >On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: > >>It's probably gonna depend on which OS you're running. Which would be...? > > > >Sorry, forgot to mention this. I'm running debian linux. > > You should be able to read/poll the various files in > > /proc/acpi/battery/BAT*/* > > for whatever battery information you need. Each BAT* directory > contains information about one of the batteries in the system (it's > possible, albeit rare, to have more than one). So you might have > some script that runs every $INTERVAL that looks something like > > from glob import glob > for fname in glob('/proc/acpi/battery/BAT*/*'): > f = file(fname) > for line in f: > do_something(line) > f.close() > > On my Debian laptop (Gateway Solo 1200, OEM battery circa 2001), the > contents look something like > > tim at rubbish:/proc/acpi/battery/BAT0$ cat alarm > alarm: unsupported > tim at rubbish:/proc/acpi/battery/BAT0$ cat info > present: yes > design capacity: 4016 mAh > last full capacity: 4011 mAh > battery technology: rechargeable > design voltage: 9600 mV > design capacity warning: 602 mAh > design capacity low: 401 mAh > capacity granularity 1: 201 mAh > capacity granularity 2: 3409 mAh > model number: QT08 > serial number: SANYOQT08 > battery type: NiMH > OEM info: SANYO > tim at rubbish:/proc/acpi/battery/BAT0$ cat state > present: yes > capacity state: ok > charging state: charged > present rate: unknown > remaining capacity: 4011 mAh > present voltage: 9600 mV > > > > -tkc > From mrkafk at gmail.com Thu Feb 18 06:12:36 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 12:12:36 +0100 Subject: Static method Message-ID: Hello everyone, Disclaimer: I'm doing this mainly for learning purposes, to feel what it's good for. I'm trying to get print_internal_date become a static method AND to refer to it in a class attribute 'tagdata' dict. class PYFileInfo(FileInfo): 'python file properties' @staticmethod def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" insts = list_dir(r'c:\mp3i',['.mp3', '.py']) File "C:/mp3i/finfo2.py", line 93, in list_dir insts = [c(f) for c,f in class_files] File "C:/mp3i/finfo2.py", line 69, in __init__ FileInfo.__init__(self,fname) File "C:/mp3i/finfo2.py", line 12, in __init__ self['name'] = filename File "C:/mp3i/finfo2.py", line 74, in __setitem__ self.__get_props(value) File "C:/mp3i/finfo2.py", line 79, in __get_props self[tag] = fun(value) TypeError: 'staticmethod' object is not callable I think I know where the problem is: what resides in tagdata is a static method 'wrapper', not the function itself, according to: http://docs.python.org/reference/datamodel.html "Static method objects Static method objects provide a way of defeating the transformation of function objects to method objects described above. A static method object is a wrapper around any other object, usually a user-defined method object. When a static method object is retrieved from a class or a class instance, the object actually returned is the wrapped object, which is not subject to any further transformation. Static method objects are not themselves callable, although the objects they wrap usually are." So, how do I get out the wrapped function out of static method without class call or instance call? (to be called in self[tag] = fun(value)) Yes, I do know that if I just get rid of @staticmethod, this works without a hitch. From d.dalton at iinet.net.au Thu Feb 18 06:16:07 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 18 Feb 2010 22:16:07 +1100 Subject: working with laptop battery In-Reply-To: References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: <20100218111607.GC31441@debian-eeepc> On Sun, Feb 14, 2010 at 03:22:11AM +0100, Daniel Fetchinson wrote: > /proc/acpi/battery/BAT0/info > /proc/acpi/battery/BAT0/state Had a quick look, but that path doesn't seem to exist, I'll look harder on the weekend when I put the script together, because it has to be somewhere. Thanks, Dan From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 06:20:25 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 12:20:25 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <87d402bzkh.fsf@benfinney.id.au> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> <4b7d0baa$0$13729$426a74cc@news.free.fr> <87d402bzkh.fsf@benfinney.id.au> Message-ID: <4b7d226d$0$14717$426a74cc@news.free.fr> Ben Finney a ?crit : > Bruno Desthuilliers writes: > >> perhaps a lighter introductory text could be helpful. So guys, if you >> think a revised version of my post would be of interest, I'll take you >> on words: provide the hosting, I'll provide the content !-) > > Here, let me work my hosting magic: . Duh ! (me banging my head on the desktop) Ok, I'll do my part of the job then !-) From snakylove at googlemail.com Thu Feb 18 06:29:47 2010 From: snakylove at googlemail.com (Snaky Love) Date: Thu, 18 Feb 2010 03:29:47 -0800 (PST) Subject: MediaWiki to RTF/Word/PDF References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: Hi, - I checked some ways doing this, and starting over with a new thing will give you a lot of headaches - all XSLT processors have one or another problem - success depends very much on how you where using wikipedia (plugins?) and you will have to expect a lot of poking around with details and still not beeing happy with the solutions available - there are many really crazy approaches out there to generate pdf of mediawiki "markup" - many tried, not many succeeded, most of them stop at "good enough for me"-level. So it might be a good idea, not running too far away from what they are doing at http://code.pediapress.com - you will spend much less time with installing ubuntu in a virtualbox. However there is one quite impressive tool, that does pdf conversion via css and is good for getting the job done quick and not too dirty: http://www.princexml.com/samples/ - scroll down to the mediawiki examples - they offer a free license for non-commercial projects. Good luck! Have a nice day, Snaky From stefan_ml at behnel.de Thu Feb 18 06:32:51 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Feb 2010 12:32:51 +0100 Subject: Static method In-Reply-To: References: Message-ID: <4b7d2563$0$6581$9b4e6d93@newsspool3.arcor-online.net> mk, 18.02.2010 12:12: > I'm trying to get print_internal_date become a static method AND to > refer to it in a class attribute 'tagdata' dict. > > class PYFileInfo(FileInfo): > 'python file properties' > > @staticmethod > def print_internal_date(filename): > f = open(filename + 'c', "rb") > data = f.read(8) > mtime = struct.unpack(" return time.asctime(time.gmtime(mtime[0])) > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } You can 'unroll' the decorator like this: class PYFileInfo(FileInfo): def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" References: Message-ID: <4b7d2a78$0$21465$426a74cc@news.free.fr> mk a ?crit : > I'm trying to get print_internal_date become a static method AND to > refer to it in a class attribute 'tagdata' dict. > > class PYFileInfo(FileInfo): > 'python file properties' > > @staticmethod > def print_internal_date(filename): > f = open(filename + 'c', "rb") > data = f.read(8) > mtime = struct.unpack(" return time.asctime(time.gmtime(mtime[0])) > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } (snip) > def __get_props(self, value): > py_compile.compile(value) > for tag, fun in PYFileInfo.tagdata.items(): > self[tag] = fun(value) > > But: > > c:/Python26/pythonw.exe -u "C:/mp3i/finfo2.py" > Traceback (most recent call last): (snip) > File "C:/mp3i/finfo2.py", line 79, in __get_props > self[tag] = fun(value) > TypeError: 'staticmethod' object is not callable > > > I think I know where the problem is: what resides in tagdata is a static > method 'wrapper', not the function itself, according to: Indeed. Sorry, I'm afraid I gave you bad advice wrt/ using a staticmethod here - I should know better :( (well, OTHO staticmethods are not something I use that often). Anyway: here are a simplified version of your problem, a possible solution that _won't_ statisfy your other constraints, 2 ugly hacks that could work but that I don't really like, and what's possibly the "less worse" solution if you really need a staticmethod here. ### class Foo1(object): """ simplified version of mk's code - test() fails """ @staticmethod def bar(baaz): print baaz tagada = {'bar': bar} def test(self, baaz): self.tagada['bar'](baaz) class Foo2(object): """ naive solution : kinda work, BUT will fail with the real code that has plain functions in 'tagada' """ @staticmethod def bar(baaz): print baaz tagada = {'bar': bar} def test(self, baaz): self.tagada['bar'].__get__(self)(baaz) class Foo3(object): """ working solution 1 : defer the wrapping of 'bar' as a staticmethod """ def bar(baaz): print baaz tagada = {'bar': bar} bar = staticmethod(bar) def test(self, baaz): self.tagada['bar'](baaz) class Foo4(object): """ working solution 2 : use a lambda """ @staticmethod def bar(baaz): print baaz tagada = {'bar': lambda x : Foo4.bar(x)} def test(self, baaz): self.tagada['bar'](baaz) """ and as a "less worse" solution """ def foo5bar(baaz): print baaz class Foo5(object): tagada = {'bar': foo5bar} bar = staticmethod(foo5bar) def test(self, baaz): self.tagada['bar'](baaz) ### Another "solution" might be to write an alternate callable implementation of 'staticmethod' - which I'll leave as an exercise to the reader (...) - but that's possibly a bit overkill !-) > http://docs.python.org/reference/datamodel.html > > So, how do I get out the wrapped function out of static method without > class call or instance call? (to be called in self[tag] = fun(value)) cf above. None of the solutions I could came with really statisfy me, but well, at least 3 of them might be "good enough" depending on the context. As far as I'm concerned, I'd first try the last one, but YMMV > Yes, I do know that if I just get rid of @staticmethod, this works > without a hitch. But then you can't use print_internal_date as a method !-) HTH From sreejithemk at gmail.com Thu Feb 18 07:15:43 2010 From: sreejithemk at gmail.com (Sreejith K) Date: Thu, 18 Feb 2010 04:15:43 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: <5b007f18-9041-465a-815f-8359f884265c@m27g2000prl.googlegroups.com> On Feb 18, 3:49?pm, Jean-Michel Pichavant wrote: > Sreejith K wrote: > > On Feb 18, 1:57 pm, Steven D'Aprano > > wrote: > > >> On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > > >>> On Feb 17, 10:48 pm, Sreejith K wrote: > > >>>> Hi everyone, > > >>>> I need to implement custom import hooks for an application > >>>> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an > >>>> application to import certain modules (say socket module). Google app > >>>> engine is using a module hook to do this (HardenedModulesHook in > >>>> google/ appengine/tools/dev_appserver.py). But I want to allow that > >>>> application to use an sdk module (custom) which imports and uses socket > >>>> module. But the module hook restricts the access by sdk. Finding out, > >>>> which file is importing a module give a solution?? ie. If the > >>>> application is importing socket module, I want to restrict it. But if > >>>> the sdk module is importing socket I want to allow it. Is there any way > >>>> I can do this ? > > >>>> Application > >>>> ======== > >>>> import sdk > >>>> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > >>>> ImportError) > > >>>> SDK > >>>> ==== > >>>> import socket ? ? ? ? ? ? ? # need to allow this > > >>> SDK > >>> === > >>> import socket > > >>> App > >>> === > >>> import SDK > >>> import sys > >>> socket = sys.modules['socket'] > > >> I'm not sure, but I think Sreejith wants to prohibit imports from the App > >> layer while allowing them from the SDK layer, not work around a > >> prohibition in the SDK layer. > > >> In other words, he wants the import hook to do something like this: > > >> if module is socket and the caller is not SKD: > >> ? ? prohibit > >> else > >> ? ? allow > > >> I could be wrong of course. > > >> -- > >> Steven > > > @Steven, Thats exactly what I want.. Anyway to do that ?? > > import sys > sys.modules['socket'] = None > > import socket > --------------------------------------------------------------------------- > ImportError ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last) > > ImportError: No module named socket > > JM @Jean. Thanks for the reply. But this is not what I wanted. The import hook already restricts socket imports in applications. But I want them in sdk package (alone) which is being imported in the application. I don't want applications to directly use the socket module. That means I want to make some exceptions for sdk in import hooks. From elias.bachaalany at gmail.com Thu Feb 18 07:28:00 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 18 Feb 2010 04:28:00 -0800 (PST) Subject: Help with lambda Message-ID: Hello, I am still fairly new to Python. Can someone explain to me why there is a difference in f and g: def make_power(n): return lambda x: x ** n # Create a set of exponential functions f = [lambda x: x ** n for n in xrange(2, 5)] g = [make_power(n) for n in xrange(2, 5)] print f[0](3), f[1](3) print g[0](3), g[1](3) I expect to have "f" act same like "g". Thanks From jeanmichel at sequans.com Thu Feb 18 07:38:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Feb 2010 13:38:30 +0100 Subject: Creating Import Hooks In-Reply-To: <5b007f18-9041-465a-815f-8359f884265c@m27g2000prl.googlegroups.com> References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> <5b007f18-9041-465a-815f-8359f884265c@m27g2000prl.googlegroups.com> Message-ID: <4B7D34C6.30809@sequans.com> Sreejith K wrote: > On Feb 18, 3:49 pm, Jean-Michel Pichavant > wrote: > >> Sreejith K wrote: >> >>> On Feb 18, 1:57 pm, Steven D'Aprano >>> wrote: >>> >>>> On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: >>>> >>>>> On Feb 17, 10:48 pm, Sreejith K wrote: >>>>> >>>>>> Hi everyone, >>>>>> >>>>>> I need to implement custom import hooks for an application >>>>>> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an >>>>>> application to import certain modules (say socket module). Google app >>>>>> engine is using a module hook to do this (HardenedModulesHook in >>>>>> google/ appengine/tools/dev_appserver.py). But I want to allow that >>>>>> application to use an sdk module (custom) which imports and uses socket >>>>>> module. But the module hook restricts the access by sdk. Finding out, >>>>>> which file is importing a module give a solution?? ie. If the >>>>>> application is importing socket module, I want to restrict it. But if >>>>>> the sdk module is importing socket I want to allow it. Is there any way >>>>>> I can do this ? >>>>>> >>>>>> Application >>>>>> ======== >>>>>> import sdk >>>>>> import socket # I dont want to allow this (need to raise >>>>>> ImportError) >>>>>> >>>>>> SDK >>>>>> ==== >>>>>> import socket # need to allow this >>>>>> >>>>> SDK >>>>> === >>>>> import socket >>>>> >>>>> App >>>>> === >>>>> import SDK >>>>> import sys >>>>> socket = sys.modules['socket'] >>>>> >>>> I'm not sure, but I think Sreejith wants to prohibit imports from the App >>>> layer while allowing them from the SDK layer, not work around a >>>> prohibition in the SDK layer. >>>> >>>> In other words, he wants the import hook to do something like this: >>>> >>>> if module is socket and the caller is not SKD: >>>> prohibit >>>> else >>>> allow >>>> >>>> I could be wrong of course. >>>> >>>> -- >>>> Steven >>>> >>> @Steven, Thats exactly what I want.. Anyway to do that ?? >>> >> import sys >> sys.modules['socket'] = None >> >> import socket >> --------------------------------------------------------------------------- >> ImportError Traceback (most recent call last) >> >> ImportError: No module named socket >> >> JM >> > > @Jean. Thanks for the reply. But this is not what I wanted. The import > hook already restricts socket imports in applications. But I want them > in sdk package (alone) which is being imported in the application. I > don't want applications to directly use the socket module. That means > I want to make some exceptions for sdk in import hooks. > give us your code (the hook import) in your entry file: import socket import sys sys.modules['sdkSocket'] = sys.modules['socket'] # allow to import socket ad sdkSocket sys.modules['socket'] = None # forbid to import socket del socket within your SDK: import sdkSocket # actually the socket module print sdkSocket.__file__ '/usr/lib/python2.5/socket.pyc' JM From arnodel at googlemail.com Thu Feb 18 07:39:08 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Feb 2010 12:39:08 +0000 Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> <7u4k52F6jsU1@mid.individual.net> Message-ID: Leo Breebaart writes: > Arnaud Delobelle writes: > >> Descriptors to the rescue :) >> >> def read_body_from(filename): >> print "** loading content **" >> return "" % filename >> >> # This is a kind of class property >> class TemplateFilename(object): >> def __get__(self, obj, cls): >> return "%s.tmpl" % cls.__name__ >> >> # And this is a kind of cached class property >> class TemplateBody(object): >> def __get__(self, obj, cls): >> try: >> return cls._body >> except AttributeError: >> cls._body = read_body_from(cls.template_filename) >> return cls._body >> >> class Foo(object): >> template_filename = TemplateFilename() >> template_body = TemplateBody() >> >> class FooA(Foo): >> pass >> >> class FooB(Foo): >> pass > > Very enlightening, thanks! > > By the way, I completely agree with the other posters in this > thread that intricate solutions such as this are likely to be > overkill, especially since at this point I have no idea if the > inefficiency of reading those templates multiple times would at > all matter (frankly, I'd doubt it). But it's certainly been > educational to learn about these techniques. Writing programs is a great way to keep learning :) > One observation: if I implement the descriptor solution as given > above, the code works perfectly, but running the code through > pychecker now causes an error, because that again causes an > attempt to read from the non-existant base class template file > "Foo.tmpl"... As someone said before, you could just provide a dummy Foo.tmpl file. -- Arnaud From mrkafk at gmail.com Thu Feb 18 07:42:57 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 13:42:57 +0100 Subject: Static method In-Reply-To: <4b7d2a78$0$21465$426a74cc@news.free.fr> References: <4b7d2a78$0$21465$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> I think I know where the problem is: what resides in tagdata is a >> static method 'wrapper', not the function itself, according to: > > Indeed. Sorry, I'm afraid I gave you bad advice wrt/ using a > staticmethod here - I should know better :( (well, OTHO staticmethods > are not something I use that often). Do not worry the least bit! I'm testdriving on a closed circuit here for sake of becoming better 'driver', I'm not going to drive like this on the streets. > class Foo2(object): > """ naive solution : kinda work, BUT will fail > with the real code that has plain functions > in 'tagada' > """ > @staticmethod > def bar(baaz): > print baaz > > tagada = {'bar': bar} > > def test(self, baaz): > self.tagada['bar'].__get__(self)(baaz) Well I could always do: if isinstance(self.tagada['bar'], staticmethod): self.tagada['bar'].__get__(self)(baaz) else: self.tagada['bar'](baaz) But 1. this apparently defeats the purpose of using print_internal_date on instance/class in 'normal' way, and 2. I probably shouldn't be doing that since using isinstance is apparently like playing with yourself: while technically legal, people look at you weirdly. :-) > > class Foo3(object): > """ working solution 1 : defer the wrapping > of 'bar' as a staticmethod > """ > def bar(baaz): > print baaz > > tagada = {'bar': bar} > > bar = staticmethod(bar) > > def test(self, baaz): > self.tagada['bar'](baaz) Neat! I like this one. > > > class Foo4(object): > """ working solution 2 : use a lambda """ > @staticmethod > def bar(baaz): > print baaz > > tagada = {'bar': lambda x : Foo4.bar(x)} > > def test(self, baaz): > self.tagada['bar'](baaz) Huh? How does this one work? After all, while in Foo4 body, the Foo4 does not exist yet? Does lambda defer evaluation to runtime (when it's executed) or smth? > > > """ and as a "less worse" solution """ > > def foo5bar(baaz): > print baaz > > class Foo5(object): > tagada = {'bar': foo5bar} > > bar = staticmethod(foo5bar) > > def test(self, baaz): > self.tagada['bar'](baaz) > Yes. I probably should have stayed with this one in the first place. I feel bad for using up bandwidth and people's attention with such stuff... From contact at xavierho.com Thu Feb 18 07:45:58 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 18 Feb 2010 22:45:58 +1000 Subject: Help with lambda In-Reply-To: References: Message-ID: <2d56febf1002180445i3c95cc7dp9b5aafeb88fa51e@mail.gmail.com> I'm looking at your code and was thinking ... why writing code that is difficult to understand? To answer your question though, they're different because in case "f", your lambda experssion is only evaluated once. That means the variable 'n' is ever only created once, and replaced repeatedly. In the second case "g", the function is only ever created once, and in effect, the lambda expression is evaluated as a new expression every time the function is called. That's why it may have been what you wanted. Seriously though, you should use a generater instead. And if that doesn't work for you, just make a function mate. Way easier to read, and you don't have to have ugly calls like f[0](3). >>> def powers(n): ... for x in xrange(2,5): ... yield x ** n ... >>> for result in powers(3): ... print result ... 8 27 64 Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Thu Feb 18 07:47:23 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 13:47:23 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <4b7c54a8$0$21284$426a74cc@news.free.fr> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> Thanks, that worked. But in order to make it work I had to get rid of >> 'self' in print_internal_date signature > > Indeed. Using it that way, the print_internal_date will not be wrapped > in a method object. Hold on! How does Python know what to wrap and what not to wrap, assuming of course programmer doesn't use @classmethod or @staticmethod? Bc self has no special significance, it's just a (strong) convention, Python can't know what's the first argument of a function supposed to be, self or regular argument, and therefore it has no way of differentiating between functions (defined in class body) designed to become methods and those that are not? Where can I read on Python internals like this (aside from post of yours, that is)? Bc frankly skimming http://docs.python.org/reference/ didn't give me impression that a lot on the subject is there (well there's some, I found smth akin to your explanation below, although yours is way more readable)? Thanks for explanation below -- I'm going to ask some related questions. > Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO > beautifully) simple once you get it, but I agree it's a bit peculiar > when compared to most mainstream OO languages. > > The first thing is that the def statement *always* yield a function > object. Always. If you don't believe it, try the following snippet: > > class Foo(object): > def bar(self): > return "baaz" > > print Foo.__dict__.keys() > print type(Foo.__dict__['bar']) Just one thing here: >>> Foo.bar Huh?! Why does it say 'unbound' method? Shouldn't that be bound method (bound to Foo, that is)? > So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? >>> type(Foo.__dict__['bar']) >>> type(Foo.bar) instancemethod - now that's something new. > The > answer is : attribute lookup rules and the descriptor protocol. > > To make a long story short, the descriptor protocol specify that, when, > during an attribute lookup, a name resolves to a class attribute AND > this attribute has a __get__ method, then this __get__ method is called > (with either the instance or None and the class itself as arguments) Depending, I assume, on whether this is instance call | class method call, respectively? Hmm why does the __get__ receive class as argument on top of instance | None? After all, when having an instance, the class can always be found by instance.__class__ ? Is this for sake of class methods? Python is science, I gather: an answer to one question bears another 10 questions. > and whatever it returns becomes the result of the attribute lookup. This > mechanism is what provides support for computed attributes. > > Now the trick is that the function type do implement the descriptor > protocol. So when a function is an attribute of a class object and you > try to access it as an attribute of either the class itself or an > instance of the class, it's __get__ method is called with the instance > (or None) and the class. > Having access to itself (of course), Quick question: how does a function access itself? Aside from rejected PEP (http://www.python.org/dev/peps/pep-3130/) I don't see the way of accessing itself outside globals() (and even then how would a function know its name -- well it shouldn't care about it really, as function object doesn't care how it's labelled, right?). Or does in "real Python" func's __get__ receive its own function (func) as an argument, like in your example implementation below? > the > instance (if there's one) and the class, it's easy for it to wrap all > this into a method object. Which is itself a callable object, that when > called mostly inject the instance as first object in the argument's list > and returns the result of calling the wrapped function object. Aha! So that's the mechanism that makes self magically appear in an argument list! I always wondered how it worked. !!THANKS!! > My 2 cents... Well, Bruno -- that was more like $200! Regards, mk From arnodel at googlemail.com Thu Feb 18 07:47:31 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Feb 2010 12:47:31 +0000 Subject: Help with lambda References: Message-ID: lallous writes: > Hello, > > I am still fairly new to Python. Can someone explain to me why there > is a difference in f and g: > > def make_power(n): > return lambda x: x ** n > > # Create a set of exponential functions > f = [lambda x: x ** n for n in xrange(2, 5)] > g = [make_power(n) for n in xrange(2, 5)] > > print f[0](3), f[1](3) > print g[0](3), g[1](3) > > > I expect to have "f" act same like "g". > > Thanks It's a FAQ! Except I don't think it's in the official Python FAQ, but it ought to be. The reason (very quickly) is that each time you call make_power() you create a new name 'n' which is bound to a different value each time, whereas in f: [lambda x: x ** n for n in xrange(2, 5)] The 'n' is the same name for each of the lambda functions and so is bound to the same value, which by the end of the loop is 4. So each of the lambdas in the list f is the same as: lambdsa x; x**4 after the end of the list comprehension. The usual fix for this is to change f to: f = [lambda x, n=n: x ** n for n in xrange(2, 5)] I'll let you think why this works. HTH -- Arnaud From elias.bachaalany at gmail.com Thu Feb 18 07:52:02 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 18 Feb 2010 04:52:02 -0800 (PST) Subject: Help with lambda References: Message-ID: <1a3903cd-b9f7-428b-a43d-47485e8620f6@g28g2000yqh.googlegroups.com> Yes it should be listed somewhere, now I get it. Thanks Arnaud. -- Elias On Feb 18, 1:47?pm, Arnaud Delobelle wrote: > lallous writes: > > Hello, > > > I am still fairly new to Python. Can someone explain to me why there > > is a difference in f and g: > > > def make_power(n): > > ? ? return lambda x: x ** n > > > # Create a set of exponential functions > > f = [lambda x: x ** n for n in xrange(2, 5)] > > g = [make_power(n) for n in xrange(2, 5)] > > > print f[0](3), f[1](3) > > print g[0](3), g[1](3) > > > I expect to have "f" act same like "g". > > > Thanks > > It's a FAQ! ?Except I don't think it's in the official Python FAQ, but > it ought to be. > > The reason (very quickly) is that each time you call make_power() you > create a new name 'n' which is bound to a different value each time, > whereas in f: > > ? ? [lambda x: x ** n for n in xrange(2, 5)] > > The 'n' is the same name for each of the lambda functions and so is > bound to the same value, which by the end of the loop is 4. ?So each of > the lambdas in the list f is the same as: > > ? ? lambdsa x; x**4 > > after the end of the list comprehension. > > The usual fix for this is to change f to: > > f = [lambda x, n=n: x ** n for n in xrange(2, 5)] > > I'll let you think why this works. > > HTH > > -- > Arnaud From darcy at druid.net Thu Feb 18 07:56:03 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 18 Feb 2010 07:56:03 -0500 Subject: Help with lambda In-Reply-To: References: Message-ID: <20100218075603.f37aab5f.darcy@druid.net> On Thu, 18 Feb 2010 04:28:00 -0800 (PST) lallous wrote: > def make_power(n): > return lambda x: x ** n Hint: type(make_power(2)) Did you expect that to return "int"? > # Create a set of exponential functions > f = [lambda x: x ** n for n in xrange(2, 5)] > g = [make_power(n) for n in xrange(2, 5)] The result of make_power(n) is a function that raises it's argument to the power of n. I don't know what you are trying to do. Maybe this? g = [make_power(n)(2) for n in xrange(2, 5)] or g = [make_power(2)(n) for n in xrange(2, 5)] -- 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 Feb 18 08:00:03 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 14:00:03 +0100 Subject: Static method In-Reply-To: References: <4b7d2a78$0$21465$426a74cc@news.free.fr> Message-ID: <4b7d39cb$0$23451$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: (snip) >> class Foo2(object): >> """ naive solution : kinda work, BUT will fail >> with the real code that has plain functions >> in 'tagada' >> """ >> @staticmethod >> def bar(baaz): >> print baaz >> >> tagada = {'bar': bar} >> >> def test(self, baaz): >> self.tagada['bar'].__get__(self)(baaz) > > Well I could always do: > > if isinstance(self.tagada['bar'], staticmethod): > self.tagada['bar'].__get__(self)(baaz) > else: > self.tagada['bar'](baaz) > > But 1. this apparently defeats the purpose of using print_internal_date > on instance/class in 'normal' way, and 2. I probably shouldn't be doing > that since using isinstance is apparently like playing with yourself: > while technically legal, people look at you weirdly. :-) As far as I'm concerned, this would be a valid use case for isinstance. But it breaks uniformity and requires quite a lot of mostly useless code. >> >> class Foo3(object): >> """ working solution 1 : defer the wrapping >> of 'bar' as a staticmethod >> """ >> def bar(baaz): >> print baaz >> >> tagada = {'bar': bar} >> >> bar = staticmethod(bar) >> >> def test(self, baaz): >> self.tagada['bar'](baaz) > > Neat! I like this one. Not me - with the wrapping so far away from the definition, it's too easy to miss part of the "process" when you come back to this code 6 month later. >> >> >> class Foo4(object): >> """ working solution 2 : use a lambda """ >> @staticmethod >> def bar(baaz): >> print baaz >> >> tagada = {'bar': lambda x : Foo4.bar(x)} >> >> def test(self, baaz): >> self.tagada['bar'](baaz) > > Huh? How does this one work? After all, while in Foo4 body, the Foo4 > does not exist yet? Does lambda defer evaluation to runtime (when it's > executed) or smth? or smth, yes !-) A lambda expression evals to an ordinary function - just like a def statement - so Foo4 is not resolved until Foo4.tagada['bar'] is actually called. >> """ and as a "less worse" solution """ >> >> def foo5bar(baaz): >> print baaz >> >> class Foo5(object): >> tagada = {'bar': foo5bar} >> >> bar = staticmethod(foo5bar) >> >> def test(self, baaz): >> self.tagada['bar'](baaz) >> > > Yes. I probably should have stayed with this one in the first place. I > feel bad for using up bandwidth and people's attention with such stuff... Why so ? You learned something, I learned something, and quite a few other people will now have a chance to learn something. Sensible use of bandwith as far as I'm concerned. wrt/ people's attention, don't worry, it's up to the reader to pay attention or skip the whole topic !-) From elias.bachaalany at gmail.com Thu Feb 18 08:08:03 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 18 Feb 2010 05:08:03 -0800 (PST) Subject: Help with lambda References: Message-ID: <62b3fe37-5f26-406b-a4e0-48bdb9a39b5c@e1g2000yqh.googlegroups.com> On Feb 18, 1:56?pm, "D'Arcy J.M. Cain" wrote: > On Thu, 18 Feb 2010 04:28:00 -0800 (PST) > > lallous wrote: > > def make_power(n): > > ? ? return lambda x: x ** n > > Hint: type(make_power(2)) > > Did you expect that to return "int"? > No, I expect to see a specialized function. > > # Create a set of exponential functions > > f = [lambda x: x ** n for n in xrange(2, 5)] > > g = [make_power(n) for n in xrange(2, 5)] > > The result of make_power(n) is a function that raises it's argument to > the power of n. ?I don't know what you are trying to do. ?Maybe this? > > g = [make_power(n)(2) for n in xrange(2, 5)] > or > g = [make_power(2)(n) for n in xrange(2, 5)] > What I am trying to do is generate different functions. If you're curious, I was playing with ctypes and wanted to see how it handles C<->Python callbacks: CB_T = WINFUNCTYPE(c_int, c_int) many_cb_t = CFUNCTYPE(c_int, c_int, CB_T) many_cb = many_cb_t(addressof(c_void_p.in_dll(dll, "many_cb"))) #ANY_SIMPLER def make_power(n): return lambda x: x ** n cbs = [CB_T(make_power(n)) for n in xrange(0, 1000)] cbs.append(None) many_cb(3, *cbs) And the C code in a shared lib: int many_cb(int value, ...) { va_list va; va = va_start(va, value); cb_t cb; int s = 0; while ( (cb = va_arg(va, cb_t)) != NULL) { printf("calling %p", cb); int r = cb(value); s += r; printf(", r=%d\n", r); } va_end(va); return s; } Speaking of that, anyone has an idea how to make simpler the line with #ANY_SIMPLER? I try: many_cb = CB_T.in_dll(dll, "many_cb") <- but that seems to work with data items only. From leo at lspace.org Thu Feb 18 08:27:30 2010 From: leo at lspace.org (Leo Breebaart) Date: 18 Feb 2010 13:27:30 GMT Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> <7u4k52F6jsU1@mid.individual.net> Message-ID: <7u4ti2Fv11U1@mid.individual.net> Arnaud Delobelle writes: > > One observation: if I implement the descriptor solution as > > given above, the code works perfectly, but running the code > > through pychecker now causes an error, because that again > > causes an attempt to read from the non-existant base class > > template file "Foo.tmpl"... It's not just pychecker that doesn't like the descriptor solution: pydoc now also crashes with the same IOError. :-) > As someone said before, you could just provide a dummy Foo.tmpl > file. A pragmatic solution, but one that smells bad to me. All this started because I didn't want my program to read files more than once, but I also don't want it to read files it doesn't have to read (and that don't even need to exist) in the first place! I'll just go back to the original instance-based lazy evaluation and caching solution now -- I never really had a big problem with that. My thanks again to all of you for helping me out with this. -- Leo Breebaart From steve at holdenweb.com Thu Feb 18 08:30:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 08:30:35 -0500 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: mk wrote: > Bruno Desthuilliers wrote: >>> Thanks, that worked. But in order to make it work I had to get rid of >>> 'self' in print_internal_date signature >> >> Indeed. Using it that way, the print_internal_date will not be wrapped >> in a method object. > > Hold on! How does Python know what to wrap and what not to wrap, > assuming of course programmer doesn't use @classmethod or @staticmethod? > Bc self has no special significance, it's just a (strong) convention, > Python can't know what's the first argument of a function supposed to > be, self or regular argument, and therefore it has no way of > differentiating between functions (defined in class body) designed to > become methods and those that are not? > > Where can I read on Python internals like this (aside from post of > yours, that is)? Bc frankly skimming http://docs.python.org/reference/ > didn't give me impression that a lot on the subject is there (well > there's some, I found smth akin to your explanation below, although > yours is way more readable)? > > Thanks for explanation below -- I'm going to ask some related questions. > >> Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO >> beautifully) simple once you get it, but I agree it's a bit peculiar >> when compared to most mainstream OO languages. >> >> The first thing is that the def statement *always* yield a function >> object. Always. If you don't believe it, try the following snippet: >> >> class Foo(object): >> def bar(self): >> return "baaz" >> >> print Foo.__dict__.keys() >> print type(Foo.__dict__['bar']) > > Just one thing here: > >>>> Foo.bar > > > Huh?! Why does it say 'unbound' method? Shouldn't that be bound method > (bound to Foo, that is)? > No. The "unbound method" means it's a callable class attribute. The significance of "unbound" is that no specific instance is attached. >> So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? > >>>> type(Foo.__dict__['bar']) > >>>> type(Foo.bar) > > > instancemethod - now that's something new. > Well "instancemethod" is just the type of the attribute. If you create a Foo instance, its bar method also has type instancemethod, even though it's a *bound* method: >>> foo = Foo() >>> foo <__main__.Foo object at 0x7ff2a16c> >>> foo.bar > >>> type(foo.bar) >>> Note that it's only when the method is looked up *from an instance of the class* does the interpreter create the bound method. And remember that this is behavior that's specific to Python 2. > >> The >> answer is : attribute lookup rules and the descriptor protocol. >> >> To make a long story short, the descriptor protocol specify that, when, >> during an attribute lookup, a name resolves to a class attribute AND >> this attribute has a __get__ method, then this __get__ method is called >> (with either the instance or None and the class itself as arguments) > > Depending, I assume, on whether this is instance call | class method > call, respectively? > Yes. > Hmm why does the __get__ receive class as argument on top of instance | > None? After all, when having an instance, the class can always be found > by instance.__class__ ? Is this for sake of class methods? > When Bruno wrote "... AND this attribute has a __get__ method ...", the __get__method has to be defined on the attribute's class - the interpreter won't even look at the instance when trying to resolve the reference. But inheritance, of course, means that the same __get__ method may be used by several classes, and when there is no instance the specific (sub)class in question must be identifiable. So you got that right. > Python is science, I gather: an answer to one question bears another 10 > questions. > Yes, but it isn't quite "turtles all the way down". Ultimately the behavior we are discussing is hard-wired into the interpreter at the __getattribute__ level. >> and whatever it returns becomes the result of the attribute lookup. This >> mechanism is what provides support for computed attributes. >> >> Now the trick is that the function type do implement the descriptor >> protocol. So when a function is an attribute of a class object and you >> try to access it as an attribute of either the class itself or an >> instance of the class, it's __get__ method is called with the instance >> (or None) and the class. > >> Having access to itself (of course), > > Quick question: how does a function access itself? Aside from rejected > PEP (http://www.python.org/dev/peps/pep-3130/) I don't see the way of > accessing itself outside globals() (and even then how would a function > know its name -- well it shouldn't care about it really, as function > object doesn't care how it's labelled, right?). Or does in "real Python" > func's __get__ receive its own function (func) as an argument, like in > your example implementation below? > The function is an object of type function, so the lookup triggers a call to the __get__() method of the function's class, providing the instance (that is the function that is being called) as the first argument. >> the >> instance (if there's one) and the class, it's easy for it to wrap all >> this into a method object. Which is itself a callable object, that when >> called mostly inject the instance as first object in the argument's list >> and returns the result of calling the wrapped function object. > > Aha! So that's the mechanism that makes self magically appear in an > argument list! I always wondered how it worked. !!THANKS!! > > >> My 2 cents... > > Well, Bruno -- that was more like $200! > I agree, this is stuff that's hard to understand, and Bruno's explanations are most helpful. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 08:34:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 14:34:37 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: <4b7d41e1$0$18857$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: >>> Thanks, that worked. But in order to make it work I had to get rid of >>> 'self' in print_internal_date signature >> >> Indeed. Using it that way, the print_internal_date will not be wrapped >> in a method object. > > Hold on! How does Python know what to wrap and what not to wrap, > assuming of course programmer doesn't use @classmethod or @staticmethod? answered below - read on, young padawan > Bc self has no special significance, it's just a (strong) convention, > Python can't know what's the first argument of a function supposed to > be, self or regular argument, and therefore it has no way of > differentiating between functions (defined in class body) designed to > become methods and those that are not? Indeed. > Where can I read on Python internals like this (aside from post of > yours, that is)? Bc frankly skimming http://docs.python.org/reference/ > didn't give me impression that a lot on the subject is there (well > there's some, I found smth akin to your explanation below, although > yours is way more readable)? Thanks > Thanks for explanation below -- I'm going to ask some related questions. > >> Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO >> beautifully) simple once you get it, but I agree it's a bit peculiar >> when compared to most mainstream OO languages. >> >> The first thing is that the def statement *always* yield a function >> object. Always. If you don't believe it, try the following snippet: >> >> class Foo(object): >> def bar(self): >> return "baaz" >> >> print Foo.__dict__.keys() >> print type(Foo.__dict__['bar']) > > Just one thing here: > > >>> Foo.bar > > > Huh?! Why does it say 'unbound' method? Shouldn't that be bound method > (bound to Foo, that is)? Yes, but it's not bound to a Foo instance. >> So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? > > >>> type(Foo.__dict__['bar']) > Yeps. That's the function object created by the def statement. Just a plain old function - expect it's an attribute of class object "Foo". > >>> type(Foo.bar) > > > instancemethod - now that's something new. Don't let the "" fools you - it's just instancemethod.__repr__ that issues different wording according to whether the instancemethod instance is bound or not. > >> The >> answer is : attribute lookup rules and the descriptor protocol. >> >> To make a long story short, the descriptor protocol specify that, when, >> during an attribute lookup, a name resolves to a class attribute AND >> this attribute has a __get__ method, then this __get__ method is called >> (with either the instance or None and the class itself as arguments) > > Depending, I assume, on whether this is instance call | class method > call, respectively? s/call/lookup/ If it's looked up on the class, there's no instance to pass to __get__. > > Hmm why does the __get__ receive class as argument on top of instance | > None? After all, when having an instance, the class can always be found > by instance.__class__ ? Is this for sake of class methods? Having access to the class is handy when you don't have the instance. The point is mostly to let the descriptor know how it has been looked up and take appropriate decisions based on this - for a definition of "appropriote" that depends on what the descriptor is intended for . Remember that this mechanism provides the generic support for all kind of computed attributes - methods, properties, and whatever you can write yourself. > Python is science, I gather: an answer to one question bears another 10 > questions. That's the case with most technical domains - until you solved enough of the puzzle to start and see the big picture. >> and whatever it returns becomes the result of the attribute lookup. This >> mechanism is what provides support for computed attributes. >> >> Now the trick is that the function type do implement the descriptor >> protocol. So when a function is an attribute of a class object and you >> try to access it as an attribute of either the class itself or an >> instance of the class, it's __get__ method is called with the instance >> (or None) and the class. > >> Having access to itself (of course), > > Quick question: how does a function access itself? In that case, it's quite simple: function.__get__ is a method of the function type, so it's called with 'self' as first argument !-) > Aside from rejected > PEP (http://www.python.org/dev/peps/pep-3130/) I don't see the way of > accessing itself outside globals() You're confusing the function instance itself with the content of the def statement's block. The code within the def statement's block has no access to the function instance that will be built from it, but other methods of the function instance are, well, ordinary methods. > (and even then how would a function > know its name -- well it shouldn't care about it really, as function > object doesn't care how it's labelled, right?). Or does in "real Python" > func's __get__ receive its own function (func) it receives itself, yes. Ordinary method call, nothing magical here - well, almost...!-). > as an argument, like in > your example implementation below? Exactly. >> the >> instance (if there's one) and the class, it's easy for it to wrap all >> this into a method object. Which is itself a callable object, that when >> called mostly inject the instance as first object in the argument's list >> and returns the result of calling the wrapped function object. > > Aha! So that's the mechanism that makes self magically appear in an > argument list! I always wondered how it worked. Now you know. As far as I'm concerned, I do find this whole mechanism to be a thing of beauty - instead of special-casing methods, you just use plain functions and the much more generic descriptor protocol to achieve the same result - with much more flexibility. > !!THANKS!! > >> My 2 cents... > > Well, Bruno -- that was more like $200! Ok, make it 3 cents then !-) More seriously, all this is explained in Raymond Hettinger's excellent 'descriptor howto' article, that is linked from the official doc - and that's how I learned all this. From philip at semanchuk.com Thu Feb 18 08:37:59 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Feb 2010 08:37:59 -0500 Subject: Python 3.0 usage? In-Reply-To: References: Message-ID: <110AD9FE-D49F-4BD5-9643-7F3FA7C7C4DD@semanchuk.com> On Feb 18, 2010, at 12:20 AM, alex23 wrote: > MRAB wrote: >> Python 3.0 had a relatively short run before it was superseded by >> Python >> 3.1 due to certain issues, so, IMHO, I wouldn't worry about it unless >> someone especially requests/requires it. > > And even then, I'd just tell them I accept patches :) Excellent idea. =) Thanks to all who replied. Cheers Philip From ptmcg at austin.rr.com Thu Feb 18 08:39:21 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 18 Feb 2010 05:39:21 -0800 (PST) Subject: How to efficiently extract information from structured text file References: <0f783ced-0414-4b44-acf1-79f8d288f41c@z10g2000prh.googlegroups.com> Message-ID: On Feb 17, 7:38?pm, Steven D'Aprano wrote: > On Wed, 17 Feb 2010 17:13:23 -0800, Jonathan Gardner wrote: > > And once you realize that every program is really a compiler, then you > > have truly mastered the Zen of Programming in Any Programming Language > > That Will Ever Exist. > > In the same way that every tool is really a screwdriver. > > -- > Steven The way I learned this was: - Use the right tool for the right job. - Every tool is a hammer. -- Paul From mrkafk at gmail.com Thu Feb 18 08:40:36 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 14:40:36 +0100 Subject: Static method In-Reply-To: <4b7d39cb$0$23451$426a74cc@news.free.fr> References: <4b7d2a78$0$21465$426a74cc@news.free.fr> <4b7d39cb$0$23451$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >>> >>> >>> class Foo4(object): >>> """ working solution 2 : use a lambda """ >>> @staticmethod >>> def bar(baaz): >>> print baaz >>> >>> tagada = {'bar': lambda x : Foo4.bar(x)} >>> >>> def test(self, baaz): >>> self.tagada['bar'](baaz) >> >> Huh? How does this one work? After all, while in Foo4 body, the Foo4 >> does not exist yet? Does lambda defer evaluation to runtime (when it's >> executed) or smth? > > or smth, yes !-) > > A lambda expression evals to an ordinary function - just like a def > statement - so Foo4 is not resolved until Foo4.tagada['bar'] is actually > called. This works, but... Foo4.bar in tagada is a staticmethod. So what's needed is Foo4.bar.__get__(x) (not that I'm that smart, I just got 'staticmethod is not callable' exception). It appears I have to use __get__ anyway while referring to bar in Foo4 methods: def testrefer(self, val): self.bar.__get__(val) Foo4.bar.__get__(val) At least I have to do this in my own code: def testit(self, fname): self.print_internal_date.__get__(fname + 'c') PYFileInfo.print_internal_date.__get__(fname + 'c') Or else I get "TypeError: 'staticmethod' object is not callable". From victorsubervi at gmail.com Thu Feb 18 08:56:44 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 18 Feb 2010 09:56:44 -0400 Subject: Timer In-Reply-To: <7a9c25c21002171037s49568919te9840a9dabd37f29@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> <7a9c25c21002171037s49568919te9840a9dabd37f29@mail.gmail.com> Message-ID: <4dc0cfea1002180556g7987b6a7rb6282ae3e21ec061@mail.gmail.com> On Wed, Feb 17, 2010 at 2:37 PM, Stephen Hansen wrote: > On Wed, Feb 17, 2010 at 10:14 AM, Victor Subervi wrote: > >> Obviously, the removeCSS isn't going to work in that last line. What can I >> put there to remove the splash page after 5 seconds? >> > > Even though you're generating this with python, it doesn't have anything to > do with Python. You'll have to use javascript and DHTML and enable/disable > classes. How to do that is beyond the scope of this group, and might depend > on the browser. I'd go look into jQuery or some such which will encapsulate > such dynamic things better. > OK. Thanks. beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Feb 18 09:15:20 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 06:15:20 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> Message-ID: <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> On Feb 18, 1:23?am, Duncan Booth wrote: > Jonathan Gardner wrote: > > On Feb 17, 12:02?am, Lawrence D'Oliveiro > central.gen.new_zealand> wrote: > >> In message > >> <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, > > >> Jonathan Gardner wrote: > >> > I used to think anonymous functions (AKA blocks, etc...) would be a > >> > nice feature for Python. > > >> > Then I looked at a stack trace from a different programming > >> > language with lots of anonymous functions. (I believe it was perl.) > > >> Didn?t it have source line numbers in it? > > >> What more do you need? > > > I don't know, but I tend to find the name of the function I called to > > be useful. It's much more memorable than line numbers, particularly > > when line numbers keep changing. > > > I doubt it's just me, though. > > Some problems with using just line numbers to track errors: > > In any language it isn't much use if you get a bug report from a shipped > program that says there was an error on line 793 but no report of > exactly which version of the shipped code was being run. > > Microsoft love telling you the line number: if IE gets a Javascript > error it reports line number but not filename, so you have to guess > which of the HTML page or one of many included files actually had the > error. Plus the line number that is reported is often slightly off. > > Javascript in particular is often sent to the browser compressed then > uncompressed and eval'd. That makes line numbers completely useless for > tracking down bugs as you'll always get the line number of the eval. > Also the way functions are defined in Javascript means you'll often have > almost every function listed in a backtrace as 'Anonymous'. If this is an argument against using anonymous functions, then it is a quadruple strawman. Shipping buggy code is a bad idea, even with named functions. Obscuring line numbers is a bad idea, even with named functions. Having your customers stay on older versions of your software is a bad idea, even with named functions. Not being able to know which version of software you're customer is running is a bad idea, even with named functions. Of course, using anonymous functions in no way prevents you from capturing a version number in a traceback. And in most modern source control systems, it is fairly easy to revert to an old version of that code. def factory(): return lambda: 15 / 0 def bar(method): method() def foo(method): bar(method) def baz(method): foo(method) try: baz(factory()) except: print 'problem with version 1.234a' raise problem with version 1.234a Traceback (most recent call last): File "foo.py", line 14, in baz(factory()) File "foo.py", line 11, in baz foo(method) File "foo.py", line 8, in foo bar(method) File "foo.py", line 5, in bar method() File "foo.py", line 2, in return lambda: 15 / 0 ZeroDivisionError: integer division or modulo by zero From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 09:23:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 15:23:27 +0100 Subject: Static method In-Reply-To: References: <4b7d2a78$0$21465$426a74cc@news.free.fr> <4b7d39cb$0$23451$426a74cc@news.free.fr> Message-ID: <4b7d4d52$0$9152$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: > >>>> >>>> >>>> class Foo4(object): >>>> """ working solution 2 : use a lambda """ >>>> @staticmethod >>>> def bar(baaz): >>>> print baaz >>>> >>>> tagada = {'bar': lambda x : Foo4.bar(x)} >>>> >>>> def test(self, baaz): >>>> self.tagada['bar'](baaz) >>> >>> Huh? How does this one work? After all, while in Foo4 body, the Foo4 >>> does not exist yet? Does lambda defer evaluation to runtime (when >>> it's executed) or smth? >> >> or smth, yes !-) >> >> A lambda expression evals to an ordinary function - just like a def >> statement - so Foo4 is not resolved until Foo4.tagada['bar'] is >> actually called. > > This works, but... Foo4.bar in tagada is a staticmethod. So what's > needed is Foo4.bar.__get__(x) (not that I'm that smart, I just got > 'staticmethod is not callable' exception). Huh ??? class Foo4(object): @staticmethod def bar(baaz): print baaz tagada = {'bar': lambda x : Foo4.bar(x)} def test(self, baaz): self.tagada['bar'](baaz) >>> f = Foo4() >>> f.test(42) 42 >>> Foo4.bar(42) 42 >>> WorksForMe(tm). > It appears I have to use __get__ anyway while referring to bar in Foo4 > methods: > > def testrefer(self, val): > self.bar.__get__(val) > Foo4.bar.__get__(val) > > At least I have to do this in my own code: > > def testit(self, fname): > self.print_internal_date.__get__(fname + 'c') > PYFileInfo.print_internal_date.__get__(fname + 'c') > > > Or else I get "TypeError: 'staticmethod' object is not callable". I think you broke something somewhere. Assuming you're using Python 2.x (>= 2.3 IIRC), my above code works. From commander_coder at hotmail.com Thu Feb 18 09:37:27 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 06:37:27 -0800 (PST) Subject: unit testing a routine that sends mail Message-ID: Hello, I have a routine that sends an email (this is how a Django view notifies me that an event has happened). I want to unit test that routine. So I gave each mail a unique subject line and I want to use python's mailbox package to look for that subject. But sometimes the mail gets delivered and sometimes it does not (I use sendmail to send it but I believe that it is always sent since I can see an entry in the mail log). I thought that the mail delivery system was occasionally hitting my mailbox lock, and that I needed to first sleep for a while. So I wrote a test that sleeps, then grabs the mailbox and looks through it, and if the mail is not there then it sleeps again, etc., for up to ten tries. It is below. However, I find that if the mail is not delivered on the first try then it is never delivered, no matter how long I wait. So I think I am doing mailbox wrong but I don't see how. The real puzzler for me is that the test reliably fails every third time. For instance, if I try it six times then it succeeds the first, second, fourth, and fifth times. I have to say that I cannot understand this at all but it certainly makes the unit test useless. I'm using Python 2.6 on an Ubuntu system. If anyone could give me a pointer to why the mail is not delivered, I sure could use it. Thanks, Jim ................................................................... class sendEmail_test(unittest.TestCase): """Test sendEmail() """ config = ConfigParser.ConfigParser() config.read(CONFIG_FN) mailbox_fn=config.get('testing','mailbox') def look_in_mailbox(self,uniquifier='123456789'): """If the mailbox has a message whose subject line contains the given uniquifier then it returns that message and deletes it. Otherwise, returns None. """ sleep_time=10.0 # wait for message to be delivered? message_found=None i=0 while i<10 and not(message_found): time.sleep(sleep_time) m=mailbox.mbox(self.mailbox_fn) try: m.lock() except Exception, err: print "trouble locking the mailbox: "+str(err) try: for key,message in m.items(): subject=message['Subject'] or '' print "subject is ",subject if subject.find(uniquifier)>-1: print "+++found the message+++ i=",str(i) message_found=message m.remove(key) break m.flush() except Exception, err: print "trouble reading from the mailbox: "+str(err) m.unlock() try: m.unlock() except Exception, err: print "trouble unlocking the mailbox: "+str(err) try: m.close() except Exception, err: print "trouble closing the mailbox: "+str(err) del m i+=1 return message_found def test_mailbox(self): random.seed() uniquifier=str(int(random.getrandbits(20))) print "uniquifier is ",uniquifier # looks different every time to me rc=az_view.sendEmail(uniquifier=uniquifier) if rc: self.fail('rc is not None: '+str(rc)) found=self.look_in_mailbox(uniquifier) if not(found): self.fail('message not found') print "done" From pruebauno at latinmail.com Thu Feb 18 09:52:29 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 18 Feb 2010 06:52:29 -0800 (PST) Subject: string to list when the contents is a list References: Message-ID: <9fc69505-3224-4aa9-9357-2abb0af4abd2@c16g2000yqd.googlegroups.com> Wes James wrote: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. > > How can I do this? > > thx, > > -wes I am surprised nobody gave you the simple answer yet that may even work for your situation: b=a[2:-2].split("','") From roy at panix.com Thu Feb 18 09:55:31 2010 From: roy at panix.com (Roy Smith) Date: Thu, 18 Feb 2010 09:55:31 -0500 Subject: unit testing a routine that sends mail References: Message-ID: In article , commander_coder wrote: > The real puzzler for me is that the test reliably fails every third > time. For instance, if I try it six times then it succeeds the first, > second, fourth, and fifth times. I have to say that I cannot > understand this at all but it certainly makes the unit test useless. Just a wild guess here, but maybe there's some DNS server which round-robins three address records for some hostname you're using, one of which is bogus. I've seen that before, and this smells like the right symptoms. From python.list at tim.thechases.com Thu Feb 18 10:18:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Feb 2010 09:18:57 -0600 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> Message-ID: <4B7D5A61.7060203@tim.thechases.com> Wes James wrote: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. Just to add to the list of solutions I've seen, letting the built-in csv module do the heavy lifting: >>> s = "['a','b']" >>> import csv >>> no_brackets = s[1:-1] # s.strip(' \t[]') >>> c = csv.reader([no_brackets], quotechar="'") >>> c.next() ['a', 'b'] This also gives you a bit of control regarding how escaping is done, and other knobs & dials to twiddle if you need. Additionally, if you have more than one string to process coming from an iterable source (such as a file), you can just pass that iterator to csv.reader() instead of concocting a one-element list. -tkc From commander_coder at hotmail.com Thu Feb 18 10:25:20 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 07:25:20 -0800 (PST) Subject: unit testing a routine that sends mail References: Message-ID: <2f2546c5-f5be-4f1a-b70f-f8afd973ea65@m37g2000yqf.googlegroups.com> On Feb 18, 9:55 am, Roy Smith wrote: > Just a wild guess here, but maybe there's some DNS server which > round-robins three address records for some hostname you're using, one of > which is bogus. > > I've seen that before, and this smells like the right symptoms. Everything happens on my laptop, localhost, where I'm developing. I'm sorry; I wasn't sure how much information was too much (or too little) but I should have said that. Thank you. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 10:27:16 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 16:27:16 +0100 Subject: unit testing a routine that sends mail In-Reply-To: References: Message-ID: <4b7d5c47$0$9135$426a74cc@news.free.fr> commander_coder a ?crit : > Hello, > > I have a routine that sends an email (this is how a Django view > notifies me that an event has happened). I want to unit test that > routine. http://docs.djangoproject.com/en/dev/topics/email/#e-mail-backends Or if you're stuck with 1.x < 1.2a, you could just mock the send_mail function to test that your app does send the appropriate mail - which is what you really want to know. My 2 cents... From debatem1 at gmail.com Thu Feb 18 10:30:29 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 18 Feb 2010 10:30:29 -0500 Subject: Python library for working with simple equations In-Reply-To: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: On Thu, Feb 18, 2010 at 4:09 AM, lallous wrote: > Hello > > Is there is any Python library that allow such things: > > Given a string expression as: x + 5 + x * (y + 2), any library that > can develop the equation for example. > Or if we say factor with "x" then it renders the expression with x * > ( rest of expression ). > There could be a functionality where when x,y are given then the > expression can be evaluated. > If there are two expressions, they can be added and the symbols > preserved. > > Does such a thing exist? > > Thanks, > Elias > -- > http://mail.python.org/mailman/listinfo/python-list > >From sage: >>> x = var('x') >>> g = x**2 + x >>> g(x=5) 30 >>> g.factor ... (x + 1)*x Geremy Condra From subhakolkata1234 at gmail.com Thu Feb 18 10:36:29 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Thu, 18 Feb 2010 07:36:29 -0800 (PST) Subject: Few questions on SOAP Message-ID: Dear Group, I was reading on SOA or Service Oriented Architecture for last few days and got some questions. As this is a room for the expert computer scientists, if you can help me solve my queries. As per I read and felt SOA is an architecture, which relies on few basic principles as, the system must be modular, the modules must be distributive, module interfaces must be clearly defined and documented, module that implements a service can be swapped out for another module that offers the same service and interface, service provider modules must be shareable. SOA is an architecture which is now a days governed like XML by W3C. The latest version is SOAP 1.2. SOA is implemented mainly in a client/server environment, where applications have the use of service, thus we can say it is a service- oriented architecture. It is a step towards cloud computing with its sister WSDL and BPM. If both client/server are following the SOA then they can communicate and exchange information without worrying for platform. SOAP is a software implementation of Python,.NET,J2EE based on this principle. SOAPPy is a Python implementation. My questions are: (i) Am I understanding correctly? (ii) Does SOAP has any standard architecture like UML other than the W3C one? (iii) Can I write short programs to check the SOAP using my personal computer as client as well as Server? (iv) Is SOAPpy fine? (v) What is the difference among SOAP, WSDL and BPM. (vi) As SOAP is for communication with a server if I pick a URL and start to communicate with Google/Yahoo would they allow? (vii) Can I design a web based robot/crawler with SOAP? Wishing you a Happy Day Ahead, Best Regards, Subhabrata. From sccolbert at gmail.com Thu Feb 18 10:44:00 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Feb 2010 10:44:00 -0500 Subject: How to use AWS/PAA nowadays? PyAWS / pyamazon outdated? In-Reply-To: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> References: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> Message-ID: <7f014ea61002180744v6faeec8dhd3110d03ab1c4a5a@mail.gmail.com> This one works for the product API. http://pypi.python.org/pypi/python-amazon-product-api/0.2.1 On Thu, Feb 18, 2010 at 5:09 AM, Snaky Love wrote: > Hi, > > is anybody aware of any updated and / or maintained library for > accessing AWS/PAA with Python? I found the dusty pyamazon and a > derivate of it, pyaws, but both of them do not seem to support request > signatures which must be used by August 15, 2009 to use the Amazon > Services, and generally seem to be a little bit outdated... > > Is there a better way doing signed requests to AWS/PAA nowadays? How > are you doing it? > > I found a good PHP Library here: http://getcloudfusion.com/docs - but > I would like to program stuff with python - is there anything pythonic > that is close to that? > > Thank you very much for your attention, > have a nice day, > Snaky > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Thu Feb 18 10:44:02 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 16:44:02 +0100 Subject: Static method In-Reply-To: <4b7d4d52$0$9152$426a74cc@news.free.fr> References: <4b7d2a78$0$21465$426a74cc@news.free.fr> <4b7d39cb$0$23451$426a74cc@news.free.fr> <4b7d4d52$0$9152$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > I think you broke something somewhere. Assuming you're using Python 2.x > (>= 2.3 IIRC), my above code works. ARGH! Forgot the "delayed staticmethod" line -- in effect I called staticmethod twice: @staticmethod def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" I have a Python app which I converted to an EXE (all files separate; single EXE didn't work properly) via py2exe - I plan on distributing this and would like the ability to remotely upgrade the program (for example, via HTTP/HTTPS). Looks like it's not just the EXE that I will need need to replace (DLLs, the library.zip, etc.). What would be the best way to go about doing this? From duncan.booth at invalid.invalid Thu Feb 18 10:50:29 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Feb 2010 15:50:29 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> Message-ID: Steve Howell wrote: > If this is an argument against using anonymous functions, then it is a > quadruple strawman. > > Shipping buggy code is a bad idea, even with named functions. I doubt very much whether I have ever shipped any bug-free code but even if it was fit for purpose when shipped it is quite possible that the software will interact badly with other software that did not exist at the time of shipping. > > Obscuring line numbers is a bad idea, even with named functions. In principle I agree, but where Javascript is concerned compressing the downloaded files is generally a pretty good idea and practicality beats purity. > > Having your customers stay on older versions of your software is a bad > idea, even with named functions. I think that's their decision, not mine. > > Not being able to know which version of software you're customer is > running is a bad idea, even with named functions. > I agree, but getting a complete coherent description out of a customer is not always an easy task. (I'm reading the word 'customer' here to include the case where there is no monetary relationship between the software author and the entity using it, but even when there is I think this still true.) -- Duncan Booth http://kupuguy.blogspot.com From commander_coder at hotmail.com Thu Feb 18 10:59:14 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 07:59:14 -0800 (PST) Subject: unit testing a routine that sends mail References: <4b7d5c47$0$9135$426a74cc@news.free.fr> Message-ID: <2163d143-e48c-4b07-b430-2ff9eedddc31@e1g2000yqh.googlegroups.com> On Feb 18, 10:27 am, Bruno Desthuilliers wrote: > you could just mock the send_mail > function to test that your app does send the appropriate mail - which is > what you really want to know. That's essentially what I think I am doing. I need to send a relatively complex email, multipart, with both a plain text and html versions of a message, and some attachments. I am worried that the email would fail to get out for some reason (say, attaching the html message fails), so I want to test it. I started out with a simple email, thinking to get unit tests working and then as I add stuff to the email I'd run the tests to see if it broke anything. I could mock the send_mail function by having it print to the screen "mail sent" or I could have a unit test that looked for the mail. I did the first, and it worked fine. I thought to do the second, starting with a unit test checking simply that the message got to the mailbox. But I am unable to check that, as described in the original message. Jim From commander_coder at hotmail.com Thu Feb 18 11:11:29 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 08:11:29 -0800 (PST) Subject: unit testing a routine that sends mail References: <4b7d5c47$0$9135$426a74cc@news.free.fr> Message-ID: <019bb3f3-a1ec-4650-8977-cc9f12ccca53@x22g2000yqx.googlegroups.com> Bruno, I talked to someone who explained to me how what you said gives a way around my difficulty. Please ignore the other reply. I'll do what you said. Thank you; I appreciate your help. Jim From stefan_ml at behnel.de Thu Feb 18 11:12:25 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Feb 2010 17:12:25 +0100 Subject: Few questions on SOAP In-Reply-To: References: Message-ID: <4b7d66e9$0$6574$9b4e6d93@newsspool3.arcor-online.net> joy99, 18.02.2010 16:36: > SOA is an architecture which is now a days governed like XML by W3C. > The latest version is SOAP 1.2. SOA has nothing to do with SOAP. SOAP is a (rather bloated) protocol for remote procedure calls. SOA is a system architecture, be it distributed or not. Stefan From showell30 at yahoo.com Thu Feb 18 11:15:46 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 08:15:46 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> Message-ID: <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> On Feb 18, 7:50?am, Duncan Booth wrote: > Steve Howell wrote: > > If this is an argument against using anonymous functions, then it is a > > quadruple strawman. > > > Shipping buggy code is a bad idea, even with named functions. > > I doubt very much whether I have ever shipped any bug-free code but > even if it was fit for purpose when shipped it is quite possible that the > software will interact badly with other software that did not exist at the > time of shipping. > > > > > Obscuring line numbers is a bad idea, even with named functions. > > In principle I agree, but where Javascript is concerned compressing the > downloaded files is generally a pretty good idea and practicality beats > purity. > > > > > Having your customers stay on older versions of your software is a bad > > idea, even with named functions. > > I think that's their decision, not mine. > > > > > Not being able to know which version of software you're customer is > > running is a bad idea, even with named functions. > mpr > I agree, but getting a complete coherent description out of a customer is > not always an easy task. (I'm reading the word 'customer' here to include > the case where there is no monetary relationship between the software > author and the entity using it, but even when there is I think this still > true.) > Just to be clear, I'm not saying it's unforgivable to occasionally ship software with bugs. It happens. Compressing Javascript is sometimes necessary, but I believe that often mangles named functions too. To the the extent that your customer is running old software and cannot always coherently describe tracebacks over a telephone, that problem can be solved in the software itself, assuming an Internet connection. The software can capture the traceback and report back to a server with the version number. So, much of the argument against anonymous functions presented so far is really orthogonal to whether functions are named or not. Circling back to the original topic, Ruby blocks, I think there is a misconception about how blocks are often used in Ruby. Usually Ruby blocks are inlined into a function and execute within that function. Example: def print_numbers() [1, 2, 3, 4, 5, 6].map { |n| [n * n, n * n * n] }.reject { |square, cube| square == 25 || cube == 64 }.map { |square, cube| cube }.each { |n| puts n raise 'problem here' } end print_numbers() The bug that I inserted into the "each" block gets reported in the traceback: foo.rb:10:in `print_numbers': problem here (RuntimeError) from foo.rb:2:in `each' from foo.rb:2:in `print_numbers' from foo.rb:14 (I do prefer Python tracebacks BTW, but that is again orthogonal to blocks vs. named functions.) The blocks of code in the above Ruby code are somewhat analogous to blocks of code in Python that happen within certain control structures, such as "if," "while," "with," etc. The extra expressiveness of Ruby comes from the fact that you can act on those blocks with your own method. Of course, there is always a tradeoff between expressiveness and simplicity. I know the person who gave the talk about Ruby vs. Python, and trust me, nine times out of ten, he prefers Python's simplicity to Ruby's expressiveness. But he likes blocks. I'm in the same boat. I use Python a lot, Ruby less so, but when I'm in Ruby-land, I actually enjoy the expressiveness of blocks. They're not particularly dangerous, and they allow you to express certain sequential operations tersely and sequentially. The contrived code below maps numbers to squares and cubes, then rejects a couple tuples, then maps back to cubes, then prints each of the cubes. def print_numbers() [1, 2, 3, 4, 5, 6].map { |n| [n * n, n * n * n] }.reject { |square, cube| square == 25 || cube == 64 }.map { |square, cube| cube }.each { |n| puts n } end IMHO there is no reason that I should have to name the content of each of those four blocks of code, nor should I have to introduce the "lambda" keyword. I don't have a less contrived example handy, but the techniques above apply often when you are filtering and massaging data. From anfedorov at gmail.com Thu Feb 18 11:19:02 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 18 Feb 2010 11:19:02 -0500 Subject: Constraints on __sub__, __eq__, etc. Message-ID: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> It seems intuitive to me that the magic methods for overriding the +, -, <, ==, >, etc. operators should have no sideffects on their operands. Also, that == should be commutative and transitive, that > and < should be transitive, and anti-commutative. Is this intuition written up in a PEP, or assumed to follow from the mathematical meanings? - Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.arnold at sas.com Thu Feb 18 11:20:44 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 18 Feb 2010 11:20:44 -0500 Subject: best way to create a dict from string Message-ID: Hi, I've got some text to parse that looks like this text = ''' blah blah blah \Template[Name=RAD,LMRB=False,LMRG=True]{tables} ho dee ho ''' I want to extract the bit between the brackets and create a dictionary. Here's what I'm doing now: def options(text): d = dict() options = text[text.find('[')+1:text.find(']')] for k,v in [val.split('=') for val in options.split(',')]: d[k] = v return d if __name__ == '__main__': for line in text.split('\n'): if line.startswith('\\Template'): print options(line) is that the best way or maybe there's something simpler? The options will always be key=value format, comma separated. thanks, --TIm From apt.shansen at gmail.com Thu Feb 18 11:28:01 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 08:28:01 -0800 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> Message-ID: <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov wrote: > It seems intuitive to me that the magic methods for overriding the +, -, <, > ==, >, etc. operators should have no sideffects on their operands. Also, > that == should be commutative and transitive, that > and < should be > transitive, and anti-commutative. > > Is this intuition written up in a PEP, or assumed to follow from the > mathematical meanings? > It may be intuitive to you, but its not true, written down anywhere, nor assumed by the language, and the mathematical meaning of the operators doesn't matter to Python. Python purposefully does not enforce anything for these methods. Consider: >>> class Test(object): ... def __init__(self, v): ... self.v = v ... def __add__(self, other): ... self.v = self.v + other ... return "Ow!" ... >>> t = Test(5) >>> t + 2 'Ow!' >>> t.v 7 It not only alters an operand, but its not even returning a meaningful result. This can be abused, but is also useful for certain uses. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From anfedorov at gmail.com Thu Feb 18 11:32:17 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 18 Feb 2010 11:32:17 -0500 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> Message-ID: <7659cab31002180832w462287f8q9f7005180e770e91@mail.gmail.com> > > It may be intuitive to you, but its not true, written down anywhere, nor > assumed by the language, and the mathematical meaning of the operators > doesn't matter to Python. Python purposefully does not enforce anything for > these methods. Right, so neither is anything in PEP-8, but it's still considered "good practice". I'm running across examples like you gave (__sub__ having a side-effect on the left-hand operand) in some code, and am trying to find concrete justification for avoiding it. - Andrey On Thu, Feb 18, 2010 at 11:28 AM, Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov wrote: > >> It seems intuitive to me that the magic methods for overriding the +, -, >> <, ==, >, etc. operators should have no sideffects on their operands. Also, >> that == should be commutative and transitive, that > and < should be >> transitive, and anti-commutative. >> >> Is this intuition written up in a PEP, or assumed to follow from the >> mathematical meanings? >> > > It may be intuitive to you, but its not true, written down anywhere, nor > assumed by the language, and the mathematical meaning of the operators > doesn't matter to Python. Python purposefully does not enforce anything for > these methods. Consider: > > >>> class Test(object): > ... def __init__(self, v): > ... self.v = v > ... def __add__(self, other): > ... self.v = self.v + other > ... return "Ow!" > ... > >>> t = Test(5) > >>> t + 2 > 'Ow!' > >>> t.v > 7 > > It not only alters an operand, but its not even returning a meaningful > result. This can be abused, but is also useful for certain uses. > > --S > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Feb 18 11:37:52 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 18 Feb 2010 11:37:52 -0500 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> Message-ID: On Thu, Feb 18, 2010 at 11:19 AM, Andrey Fedorov wrote: > It seems intuitive to me that the magic methods for overriding the +, -, <, > ==, >, etc. operators should have no sideffects on their operands. Also, > that == should be commutative and transitive, that > and < should be > transitive, and anti-commutative. > Is this intuition written up in a PEP, or assumed to follow from the > mathematical meanings? > - Andrey There are no assumptions about anything. You can do whatever you want when you implement the functions yourself. For the numeric types, they follow the intuitive meanings but that's not necessary for user defined types. Of course, your users will get very confused if a == b but b != a. Or if a == b and a != b at the same time. > -- > http://mail.python.org/mailman/listinfo/python-list > > From chyavana at gmail.com Thu Feb 18 11:38:10 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Fri, 19 Feb 2010 00:38:10 +0800 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: <4B7D6CF2.7010907@gmail.com> Arnaud Delobelle wrote: > Here is a very simple way to improve what you do, which won't require > you to change the way you work or to learn a new paradigm: > > Instead of testing your functions interactively, put your testing code > in a file, e.g. 'program_tests.py'. Your can then type > > python program_tests.py > > at the shell interactive prompt. To perform the tests again, just > re-execute that file. If your tests are divided into > different units, you can put these in functions: > > def test_frobz(): > #testing code for frobzation of klops > > def test_frizz(): > #testing code for frizzment of frobzied klops > > # etc.. > > So if you want to keep doing interactive tests, you can import > program_tests and call whichever testing functions you want. You may > even have arguments to those functions to test them with different > parameters. > > I know some people will point at more 'pro' ways of testing but this has > the merit of being very straightforward. Then when you move on to more > sophisticated techniques, I think you will understand better the > motivations behind them. It took me some time to cotton on to exactly what you were saying, but once I grasped it and tried it out, I found it very effective and time-saving. Thank you very much Arnaud. -- Chandra From robert.kern at gmail.com Thu Feb 18 11:39:53 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 10:39:53 -0600 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> Message-ID: On 2010-02-18 10:19 AM, Andrey Fedorov wrote: > It seems intuitive to me that the magic methods for overriding the +, -, > <, ==, >, etc. operators should have no sideffects on their operands. > Also, that == should be commutative and transitive, that > and < should > be transitive, and anti-commutative. > > Is this intuition written up in a PEP, or assumed to follow from the > mathematical meanings? Some of it is covered in the reference manual. E.g. http://docs.python.org/reference/datamodel.html#object.__lt__ -- 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 simon at brunningonline.net Thu Feb 18 11:55:19 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 18 Feb 2010 16:55:19 +0000 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: <8c7f10c61002180855t359a7848xd9b85e724910e917@mail.gmail.com> 2010/2/17 Arnaud Delobelle : > I know some people will point at more 'pro' ways of testing but this has > the merit of being very straightforward. ?Then when you move on to more > sophisticated techniques, I think you will understand better the > motivations behind them. Oh, I don't know. I like to think I'm fairly "pro" when it comes to TDD, and this is exactly what I do - a unit test module run from the shell. -- Cheers, Simon B. From jeanmichel at sequans.com Thu Feb 18 11:58:54 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Feb 2010 17:58:54 +0100 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180832w462287f8q9f7005180e770e91@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> <7659cab31002180832w462287f8q9f7005180e770e91@mail.gmail.com> Message-ID: <4B7D71CE.6060904@sequans.com> Andrey Fedorov wrote: > > It may be intuitive to you, but its not true, written down > anywhere, nor assumed by the language, and the mathematical > meaning of the operators doesn't matter to Python. Python > purposefully does not enforce anything for these methods. > > > Right, so neither is anything in PEP-8, but it's still considered > "good practice". I'm running across examples like you gave (__sub__ > having a side-effect on the left-hand operand) in some code, and am > trying to find concrete justification for avoiding it. > > - Andrey This is all about communication. Python allows you to call a cat a dog. You'll confuse everyone if you do so, but you can do it. If your '-' operator is doing something else than returning the sub result, it's your call, but do not expect people to get it easily. You'd better be good at writting the documentation :-) JM From mrkafk at gmail.com Thu Feb 18 12:28:44 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 18:28:44 +0100 Subject: Why this doesn't work? Message-ID: Sorry to bother everyone again, but I have this problem bugging me: #!/usr/bin/python -i class Foo(object): def nostat(self,val): print val nostat.__orig_get__ = nostat.__get__ @staticmethod def nostatget(*args, **kwargs): print 'args:', args, 'kwargs:', kwargs nostat.__orig_get__(*args, **kwargs) nostat.__get__ = nostatget setattr(nostat,'__get__',nostatget) f = Foo() f.nostat('a') print f.nostat.__get__ is f.nostat.__orig_get__ This produces: a False I expected to see 'nostatget' output: nostat.__get__ = nostatget obviously failed to replace this function's __get__ method. The question is why? Isn't __get__ a normal attribute of a function nostat? This is made so much weirder that nostat.__get__ is no longer original __get__, so it looks like it should have been replaced, but if so, why nostatget doesn't get called? Regards, mk From simon at brunningonline.net Thu Feb 18 13:14:22 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 18 Feb 2010 18:14:22 +0000 Subject: Few questions on SOAP In-Reply-To: References: Message-ID: <8c7f10c61002181014s6da28c8t7012d751cb077f3d@mail.gmail.com> On 18 February 2010 15:36, joy99 wrote: > (iv) ? ?Is SOAPpy fine? AFAIK, SOAPpy is unsupported, and a bit on the stale side. Those poor souls forced to make SOAP calls with Python seem to be using Suds mostly these days,. -- Cheers, Simon B. From fetchinson at googlemail.com Thu Feb 18 13:16:06 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 19:16:06 +0100 Subject: What happened to pyjamas? Message-ID: Does anyone know what happened to pyjs.org ? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From breamoreboy at yahoo.co.uk Thu Feb 18 13:44:23 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Feb 2010 18:44:23 +0000 Subject: What happened to pyjamas? In-Reply-To: References: Message-ID: Daniel Fetchinson wrote: > Does anyone know what happened to pyjs.org ? > > Cheers, > Daniel > > According to google cache it was fine 13/02/2010 and it's down according to this. http://downforeveryoneorjustme.com/pyjs.org HTH. Mark Lawrence From sccolbert at gmail.com Thu Feb 18 13:44:40 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Feb 2010 13:44:40 -0500 Subject: What happened to pyjamas? In-Reply-To: References: Message-ID: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> it's working for me. On Thu, Feb 18, 2010 at 1:16 PM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > Does anyone know what happened to pyjs.org ? > > Cheers, > Daniel > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Thu Feb 18 13:47:08 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 19:47:08 +0100 Subject: What happened to pyjamas? In-Reply-To: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: >> Does anyone know what happened to pyjs.org ? > > it's working for me. That's odd, it's unpingable for me from both Europe and the US, ping says unknown host. Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at bdurham.com Thu Feb 18 13:54:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 13:54:27 -0500 Subject: How secure are temp files created via tempfile.TemporaryFile()? Message-ID: <1266519267.4170.1360680003@webmail.messagingengine.com> I'm doing a code review of an application that occassionally writes blocks of secure data to temp files created with tempfile.TemporaryFile( delete=True ). How secure are temp files created via tempfile.TemporaryFile( delete=True )? Are there OS specific nuances I should be concerned about regarding use of this function on Windows (XP or higher) or Linux? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Thu Feb 18 13:58:59 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Thu, 18 Feb 2010 13:58:59 -0500 Subject: What happened to pyjamas? In-Reply-To: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: <4B2D76D1-AE2A-47F0-A1D0-805CABA62150@gmail.com> Down from here (NH, US). S On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > From comptekki at gmail.com Thu Feb 18 14:32:59 2010 From: comptekki at gmail.com (Wes James) Date: Thu, 18 Feb 2010 12:32:59 -0700 Subject: string to list when the contents is a list In-Reply-To: <4B7D5A61.7060203@tim.thechases.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> Message-ID: <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase wrote: > Wes James wrote: > > Just to add to the list of solutions I've seen, letting the built-in csv > module do the heavy lifting: > > ?>>> s = "['a','b']" > ?>>> import csv > ?>>> no_brackets = s[1:-1] # s.strip(' \t[]') > ?>>> c = csv.reader([no_brackets], quotechar="'") > ?>>> c.next() > ?['a', 'b'] > > This also gives you a bit of control regarding how escaping is done, and > other knobs & dials to twiddle if you need. Additionally, if you have more > than one string to process coming from an iterable source (such as a file), > you can just pass that iterator to csv.reader() instead of concocting a > one-element list. Thx, I think this will work for what I want. -wes From python at mrabarnett.plus.com Thu Feb 18 14:33:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Feb 2010 19:33:11 +0000 Subject: How secure are temp files created via tempfile.TemporaryFile()? In-Reply-To: <1266519267.4170.1360680003@webmail.messagingengine.com> References: <1266519267.4170.1360680003@webmail.messagingengine.com> Message-ID: <4B7D95F7.9020906@mrabarnett.plus.com> python at bdurham.com wrote: > I'm doing a code review of an application that occassionally writes > blocks of secure data to temp files created with tempfile.TemporaryFile( > delete=True ). > > How secure are temp files created via tempfile.TemporaryFile( delete=True )? > > Are there OS specific nuances I should be concerned about regarding use > of this function on Windows (XP or higher) or Linux? > Well, the contents of temp files aren't encrypted, if that's what you're asking, so if you're writing unencrypted data to a temp file then other applications could read it. From comptekki at gmail.com Thu Feb 18 14:56:16 2010 From: comptekki at gmail.com (Wes James) Date: Thu, 18 Feb 2010 12:56:16 -0700 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> Message-ID: <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> On Thu, Feb 18, 2010 at 12:32 PM, Wes James wrote: > On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase > wrote: >> Wes James wrote: > > >> >> Just to add to the list of solutions I've seen, letting the built-in csv >> module do the heavy lifting: >> >> ?>>> s = "['a','b']" >> ?>>> import csv >> ?>>> no_brackets = s[1:-1] # s.strip(' \t[]') >> ?>>> c = csv.reader([no_brackets], quotechar="'") >> ?>>> c.next() >> ?['a', 'b'] Hmm. When I put csv.reader in a class: import csv class IS_LIST(): def __init__(self, format='', error_message='must be a list!'): self.format = format self.error_message = error_message def __call__(self, value): try: if value=='[]' or value=='': value=[] else: no_brackets = value[1:-1] # s.strip(' \t[]') c = csv.reader([no_brackets], quotechar="'") value=c.next() return (value, None) except: return (value, self.error_message) def formatter(self, value): return value I get an error (when I take the "try" out): AttributeError: 'function' object has no attribute 'reader' Why? -wes From nagle at animats.com Thu Feb 18 14:58:32 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Feb 2010 11:58:32 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: <4b7d97dc$0$1587$742ec2ed@news.sonic.net> John Nagle wrote: > I look at this as Python's answer to multicore CPUs and "Go". On that note, I went to a talk at Stanford yesterday by one of the designers of Intel's Nelahem core. The four-core, eight thread version is out now. The six-core, twelve thread version is working; the speaker has one in his lab. The eight-core, sixteen thread version is some months away. This isn't an expensive CPU; this is Intel's "converged" mainstream product. (Although there will be a whole range of "economy" and "performance" versions, all with the same core but with some stuff turned off.) Python isn't ready for this. Not with the GIL. Multiple processes are not the answer. That means loading multiple copies of the same code into different areas of memory. The cache miss rate goes up accordingly. John Nagle From malkarouri at gmail.com Thu Feb 18 15:00:17 2010 From: malkarouri at gmail.com (Muhammad Alkarouri) Date: Thu, 18 Feb 2010 12:00:17 -0800 (PST) Subject: Few questions on SOAP References: Message-ID: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Your question is borderline if not out of topic in this group. I will make a few comments though. On Feb 18, 3:36?pm, joy99 wrote: > Dear Group, > > I was reading on SOA or Service Oriented Architecture for last few > days and got some questions. As this is a room for the expert computer > scientists, if you can help me solve my queries. > > As per I read and felt SOA is an architecture, which relies on few > basic principles as, > the system must be modular, the modules must be distributive, module > interfaces must be clearly defined and documented, module that > implements a service can be swapped out for another module that offers > the same service and interface, service provider modules must be > shareable. > SOA is an architecture which is now a days governed like XML by W3C. SOA is an architecture which can be implemented using any of a number of different middleware choices. It is not governed or controlled by anyone. You are mixing it up with SOAP, which is a web services technology, currently governed by W3C. For example, I tend to use SOA implemented using REST (Representational State Transfer). All of these technologies are somewhat explained in wikipedia. You probably want to start there. > The latest version is SOAP 1.2. This is the latest of SOAP, not SOA. > SOA is implemented mainly in a client/server environment, where > applications have the use of service, thus we can say it is a service- > oriented architecture. > It is a step towards cloud computing with its sister WSDL and BPM. A SOAP web service is described using WSDL. BPM is not really connected with them, but is probably more connected with SOA as an architecture. BPM can be implemented using SOAP/WSDL web services, as can SOA. > > If both client/server are following the SOA then they can communicate > and exchange information without worrying for platform. You mean SOAP here. In real life, there are interoperability issues. So various implementations of SOAP will need a bit of work to actually work together. SOA is an architecture and does not help exchanging information in a direct way. > > SOAP is a software implementation of Python,.NET,J2EE based on this > principle. SOAP is a web services protocol that was created before the concept of SOA was developed enough for use and is largely independent of it. SOAP has been implemented in many different languages, like Java, .Net, C/C++, Python, etc. > SOAPPy is a Python implementation. SOAP implementations in Python are not of the best quality (in my opinion, there are better ways to achieve the ends needed). SOAPpy is currently a bit out of date. The better ones are ZSI (for client and server) and suds (for clients). I guess I have already answered some of your questions. > > My questions are: > (i) ? ? Am I understanding correctly? See above. > (ii) ? ?Does SOAP has any standard architecture like UML other than the > W3C one? Depends on what you mean by architecture. SOAP is a standard. UML is a way of modelling software and can be used to model web services, which can then be implemented in SOAP. > (iii) ? Can I write short programs to check the SOAP using my personal > computer as client as well as Server? Yes. Try ZSI examples (http://pywebsvcs.sourceforge.net/zsi.html). > (iv) ? ?Is SOAPpy fine? See above. > (v) ? ? What is the difference among SOAP, WSDL and BPM. SOAP standardise the communication between client and server. WSDL describes the methods provided by a server to be consumed by a client (interfaces in Java language). BPM is a management method to improve business and is not a software protocol but an approach. > (vi) ? ?As SOAP is for communication with a server if I pick a URL and > start to communicate with Google/Yahoo would they allow? To be able to talk SOAP to a server, it must understand SOAP. Some of those companies do provide SOAP web service access, but their standard search pages are accessible in pure HTTP (the way you browser uses them). To access a SOAP service you need to know the functions exported by it, which are usually defined in a WSDL document. > (vii) ? Can I design a web based robot/crawler with SOAP? No. Web pages are accessed using simple HTTP. SOAP is usually deployed on top of HTTP, but most web pages are not communicated using SOAP. You can search for Python web crawling; there are a lot of examples on the web. Regards, k From python at bdurham.com Thu Feb 18 15:09:28 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 15:09:28 -0500 Subject: How secure are temp files created via tempfile.TemporaryFile()? In-Reply-To: <4B7D95F7.9020906@mrabarnett.plus.com> References: <1266519267.4170.1360680003@webmail.messagingengine.com> <4B7D95F7.9020906@mrabarnett.plus.com> Message-ID: <1266523768.19867.1360705413@webmail.messagingengine.com> MRAB, > Well, the contents of temp files aren't encrypted, if that's what you're asking I understand the contents of temp files aren't encrypted. > if you're writing unencrypted data to a temp file then other applications could read it. That's my concern - can other applications really read my temp files created with tempfile.TemporaryFile( delete=True )? I don't think so because: 1. These files appear to be exclusively locked by my process, eg. no other processes can read or write to these temp files except the process that created these files. 2. As soon as my process terminates (voluntarily or involuntarily), the temp file gets deleted. But I want to make sure. Thanks, Mal From python.list at tim.thechases.com Thu Feb 18 15:12:25 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Feb 2010 14:12:25 -0600 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> Message-ID: <4B7D9F29.7070002@tim.thechases.com> > import csv > > class IS_LIST(): > def __init__(self, format='', error_message='must be a list!'): > self.format = format > self.error_message = error_message > def __call__(self, value): > try: > if value=='[]' or value=='': > value=[] > else: > no_brackets = value[1:-1] # s.strip(' \t[]') > c = csv.reader([no_brackets], quotechar="'") > value=c.next() > return (value, None) > except: > return (value, self.error_message) > def formatter(self, value): > return value > > I get an error (when I take the "try" out): > > AttributeError: 'function' object has no attribute 'reader' A couple ideas occur to me: 1) you haven't copy/pasted the exact (or entirety of the) code, and something you're doing is shadowing the "csv" module 2) are you using Python 2.x or 3.x? I don't know if the csv module has changed in 3.x but it should work in 2.x The first thing to check would be to pull up a raw python prompt and see if your csv module has the expected reader: >>> import csv >>> csv.reader If not, something likely changed in 3.x and you'd have to inspect the docs to see what happened to the reader. If you get the above evidence of an existing reader, then you're likely shadowing it. -tkc From phlip2005 at gmail.com Thu Feb 18 15:16:03 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 18 Feb 2010 12:16:03 -0800 (PST) Subject: unit testing a routine that sends mail References: Message-ID: <7348214b-4bd1-4f41-984c-1893fb51afae@z1g2000prc.googlegroups.com> commander_coder wrote: > I have a routine that sends an email (this is how a Django view > notifies me that an event has happened). ?I want to unit test that > routine. Are you opening SMTP and POP3 sockets?? If you are not developing that layer itself, just use Django's built- in mock system. Here's my favorite assertion for it: def assert_mail(self, funk): from django.core import mail previous_mails = len(mail.outbox) funk() mails = mail.outbox[ previous_mails : ] assert [] != mails, 'the called block should produce emails' if len(mails) == 1: return mails[0] return mails You call it a little bit like this: missive = self.assert_mail( lambda: mark_order_as_shipped(order) ) Then you can use assert_contains on the missive.body, to see what mail got generated. That's what you are actually developing, so your tests should skip any irrelevant layers, and only test the layers where you yourself might add bugs. -- Phlip http://penbird.tumblr.com/ From daniele.gondoni at gmail.com Thu Feb 18 15:21:16 2010 From: daniele.gondoni at gmail.com (Daniele Gondoni) Date: Thu, 18 Feb 2010 12:21:16 -0800 (PST) Subject: What happened to pyjamas? References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: On 18 Feb, 19:58, "sstein... at gmail.com" wrote: > Down from here (NH, US). > > S > > On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > > > Unreacheable from Italy as well... From sccolbert at gmail.com Thu Feb 18 15:26:58 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Feb 2010 15:26:58 -0500 Subject: What happened to pyjamas? In-Reply-To: <4B2D76D1-AE2A-47F0-A1D0-805CABA62150@gmail.com> References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> <4B2D76D1-AE2A-47F0-A1D0-805CABA62150@gmail.com> Message-ID: <7f014ea61002181226o6f8c1e20u2d525c86ac96c59f@mail.gmail.com> ah, yep, i was viewing the page chrome had cached. It's down for me too. I lose the trace in Washington: 3 G3-0-873.TAMPFL-LCR-08.verizon-gni.net (130.81.110.222) 14.399 ms 17.917 ms 18.040 ms 4 so-6-1-0-0.TPA01-BB-RTR2.verizon-gni.net (130.81.29.242) 18.666 ms 18.890 ms 19.232 ms 5 ge-1-0-0-0.ATL01-BB-RTR2.verizon-gni.net (130.81.17.48) 36.460 ms 38.546 ms 38.707 ms 6 0.so-2-2-0.XT2.ATL5.ALTER.NET (152.63.86.73) 41.357 ms 33.709 ms 35.851 ms 7 * 0.so-7-0-0.XT2.ATL4.ALTER.NET (152.63.86.109) 34.522 ms 37.320 ms 8 0.xe-10-1-0.BR3.ATL4.ALTER.NET (152.63.82.13) 37.558 ms 32.756 ms 35.533 ms 9 xe-11-2-0.edge4.Atlanta2.Level3.net (4.68.62.17) 37.715 ms 100.222 ms 102.317 ms 10 ae-71-52.ebr1.Atlanta2.Level3.net (4.68.103.60) 40.227 ms 34.315 ms 36.647 ms 11 ae-73-70.ebr3.Atlanta2.Level3.net (4.69.138.20) 42.695 ms 39.589 ms 41.666 ms 12 ae-2-2.ebr1.Washington1.Level3.net (4.69.132.86) 52.152 ms 54.256 ms 54.540 ms 13 ae-61-61.csw1.Washington1.Level3.net (4.69.134.130) 61.982 ms 62.316 ms 62.460 ms 14 ae-14-69.car4.Washington1.Level3.net (4.68.17.6) 55.660 ms 55.645 ms 56.943 ms 15 CO-LOCATION.car4.Washington1.Level3.net (4.79.170.254) 59.423 ms 58.914 ms 50.872 ms 16 * * * 17 * * * 18 * * * 19 * * * 20 * * * 21 * * * 22 * * * 23 * * * 24 * * * 25 * * * 26 * * * 27 * * * 28 * * * 29 * * * 30 * * * On Thu, Feb 18, 2010 at 1:58 PM, ssteinerX at gmail.com wrote: > Down from here (NH, US). > > S > > > On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Thu Feb 18 15:32:12 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 15:32:12 -0500 Subject: Why do full path names to module show up multiple times in .PYC files? Message-ID: <1266525132.23323.1360707279@webmail.messagingengine.com> I just happened to look at a compiled Python 2.6.4 .PYC file in an editor and noticed that the full path and file name of the compiled module showed up in my .PYC file at least 10 different times. Is there a reason for full vs. relative path names and why does the module name need to be duplicated so many times? It appears that .PYO files only use a filename (without a path). I assume the only way for us to suppress path names (which may have confidential client names) in our compiled distributions is to use .PYO vs. .PYC files? Is this correct? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Feb 18 15:33:14 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 18 Feb 2010 15:33:14 -0500 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> Message-ID: On Thu, Feb 18, 2010 at 2:56 PM, Wes James wrote: > > I get an error (when I take the "try" out): > > AttributeError: 'function' object has no attribute 'reader' > You have a function called "csv" that's defined after the import csv statement is executed. That function has no attribute 'reader", so you get the error. By the way, don't use a bare except- it's bad form because it hides any other problems you have. From luismgz at gmail.com Thu Feb 18 15:45:05 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 18 Feb 2010 12:45:05 -0800 (PST) Subject: What happened to pyjamas? References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: On Feb 18, 5:21?pm, Daniele Gondoni wrote: > On 18 Feb, 19:58, "sstein... at gmail.com" wrote: > > > Down from here (NH, US). > > > S > > > On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > Unreacheable from Italy as well... Same here (Buenos Aires, Argentina). From irmen at -NOSPAM-xs4all.nl Thu Feb 18 15:53:32 2010 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Thu, 18 Feb 2010 21:53:32 +0100 Subject: What happened to pyjamas? In-Reply-To: References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: <4b7da919$0$22938$e4fe514c@news.xs4all.nl> On 2/18/10 9:45 PM, Luis M. Gonz?lez wrote: > On Feb 18, 5:21 pm, Daniele Gondoni wrote: >> On 18 Feb, 19:58, "sstein... at gmail.com" wrote: >> >>> Down from here (NH, US). >> >>> S >> >>> On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: >> >> Unreacheable from Italy as well... > > Same here (Buenos Aires, Argentina). It ain't down till Netcraft confirms it! http://uptime.netcraft.com/up/graph?site=www.pyjs.org Oh wait... -irmen From CORY.L.NARDIN at saic.com Thu Feb 18 16:00:19 2010 From: CORY.L.NARDIN at saic.com (Nardin, Cory L.) Date: Thu, 18 Feb 2010 13:00:19 -0800 Subject: Python won't run Message-ID: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> Quickly, I have a Mac Intel with Windows XP installed. Tried installing Python 2.6.4 from the binary and also ActivePython 2.6.4.10. Both installations acted the same. There seemed to be no problems during installation (used default options), but when I try to run Python I get an error message: "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem." Of course I searched on that error and it seems to be related to a MS library. In a few different places it was recommended to install the MS Visual Studio redistributable package, which I did with no change in outcome. I really have no idea what to do. Any help is appreciated. Thanks, Cory -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Feb 18 16:07:21 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Feb 2010 21:07:21 +0000 Subject: Few questions on SOAP In-Reply-To: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: Muhammad Alkarouri wrote: > Your question is borderline if not out of topic in this group. I will > make a few comments though. This might be a Python group, but threads often drift way off topic, which added to the language itself make this a great group to read. If you don't like the way a thread goes, you can always skip it. > > On Feb 18, 3:36 pm, joy99 wrote: >> Dear Group, >> >> I was reading on SOA or Service Oriented Architecture for last few >> days and got some questions. As this is a room for the expert computer >> scientists, if you can help me solve my queries. >> >> As per I read and felt SOA is an architecture, which relies on few >> basic principles as, >> the system must be modular, the modules must be distributive, module >> interfaces must be clearly defined and documented, module that >> implements a service can be swapped out for another module that offers >> the same service and interface, service provider modules must be >> shareable. >> SOA is an architecture which is now a days governed like XML by W3C. > > SOA is an architecture which can be implemented using any of a number > of different middleware choices. It is not governed or controlled by > anyone. You are mixing it up with SOAP, which is a web services > technology, currently governed by W3C. > For example, I tend to use SOA implemented using REST > (Representational State Transfer). > > All of these technologies are somewhat explained in wikipedia. You > probably want to start there. > >> The latest version is SOAP 1.2. > > This is the latest of SOAP, not SOA. > >> SOA is implemented mainly in a client/server environment, where >> applications have the use of service, thus we can say it is a service- >> oriented architecture. >> It is a step towards cloud computing with its sister WSDL and BPM. > > A SOAP web service is described using WSDL. BPM is not really > connected with them, but is probably more connected with SOA as an > architecture. BPM can be implemented using SOAP/WSDL web services, as > can SOA. > >> If both client/server are following the SOA then they can communicate >> and exchange information without worrying for platform. > > You mean SOAP here. > In real life, there are interoperability issues. So various > implementations of SOAP will need a bit of work to actually work > together. > > SOA is an architecture and does not help exchanging information in a > direct way. > >> SOAP is a software implementation of Python,.NET,J2EE based on this >> principle. > > SOAP is a web services protocol that was created before the concept of > SOA was developed enough for use and is largely independent of it. > SOAP has been implemented in many different languages, like > Java, .Net, C/C++, Python, etc. > >> SOAPPy is a Python implementation. > > SOAP implementations in Python are not of the best quality (in my > opinion, there are better ways to achieve the ends needed). SOAPpy is > currently a bit out of date. The better ones are ZSI (for client and > server) and suds (for clients). > > I guess I have already answered some of your questions. > >> My questions are: >> (i) Am I understanding correctly? > > See above. > >> (ii) Does SOAP has any standard architecture like UML other than the >> W3C one? > > Depends on what you mean by architecture. SOAP is a standard. UML is a > way of modelling software and can be used to model web services, which > can then be implemented in SOAP. > >> (iii) Can I write short programs to check the SOAP using my personal >> computer as client as well as Server? > > Yes. Try ZSI examples (http://pywebsvcs.sourceforge.net/zsi.html). > >> (iv) Is SOAPpy fine? > > See above. > >> (v) What is the difference among SOAP, WSDL and BPM. > > SOAP standardise the communication between client and server. WSDL > describes the methods provided by a server to be consumed by a client > (interfaces in Java language). BPM is a management method to improve > business and is not a software protocol but an approach. > >> (vi) As SOAP is for communication with a server if I pick a URL and >> start to communicate with Google/Yahoo would they allow? > > To be able to talk SOAP to a server, it must understand SOAP. Some of > those companies do provide SOAP web service access, but their standard > search pages are accessible in pure HTTP (the way you browser uses > them). > To access a SOAP service you need to know the functions exported by > it, which are usually defined in a WSDL document. > >> (vii) Can I design a web based robot/crawler with SOAP? > > No. Web pages are accessed using simple HTTP. SOAP is usually deployed > on top of HTTP, but most web pages are not communicated using SOAP. > You can search for Python web crawling; there are a lot of examples on > the web. > > > Regards, > > k From dick128 at verizon.net Thu Feb 18 16:11:54 2010 From: dick128 at verizon.net (dick bly) Date: Thu, 18 Feb 2010 15:11:54 -0600 (Central Standard Time) Subject: Win32print apache mod_python vista Message-ID: <4B7DAD19.00000C.07308@LAPTOP2> I have a program that uses mod_python in Apache and does a win32print using the default printer This works fine under win xp but the configuration under vista raises and error - no default printer found - Its the same code, same Apache, same mod_python, same python - only difference is vista so I am assuming vista is trying to be my friend by not giving me access to the printers - can any help with this ? Richard Bly cell 817 996 6458 dick128 at verizon.net -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stampa_girl_line_en.gif Type: image/gif Size: 46417 bytes Desc: not available URL: From aahz at pythoncraft.com Thu Feb 18 16:18:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Feb 2010 13:18:51 -0800 Subject: string to list when the contents is a list References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> Message-ID: In article , Wes James wrote: > > try: > if value=3D=3D'[]' or value=3D=3D'': > value=3D[] > else: > no_brackets =3D value[1:-1] # s.strip(' \t[]') > c =3D csv.reader([no_brackets], quotechar=3D"'") > value=3Dc.next() > return (value, None) > except: > return (value, self.error_message) Two important points: * Don't use bare except: clauses * Put less code in the try: clause to make it easier to track down problems -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From ethan at stoneleaf.us Thu Feb 18 16:19:16 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Feb 2010 13:19:16 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7d97dc$0$1587$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <4B7DAED4.3010500@stoneleaf.us> John Nagle wrote: > John Nagle wrote: > >> I look at this as Python's answer to multicore CPUs and "Go". > > On that note, I went to a talk at Stanford yesterday by one of the > designers of Intel's Nelahem core. The four-core, eight thread > version is out now. The six-core, twelve thread version is working; > the speaker has one in his lab. The eight-core, sixteen thread version > is some months away. This isn't an expensive CPU; this is Intel's > "converged" mainstream product. (Although there will be a whole range > of "economy" and "performance" versions, all with the same core but > with some stuff turned off.) > > Python isn't ready for this. Not with the GIL. > > Multiple processes are not the answer. That means loading multiple > copies of the same code into different areas of memory. The cache > miss rate goes up accordingly. > > John Nagle Will the new GIL in 3.2 make this workable? It would still be one thread at a time, though, wouldn't it. ~Ethan~ From ntwrkd at gmail.com Thu Feb 18 16:34:46 2010 From: ntwrkd at gmail.com (ntwrkd) Date: Thu, 18 Feb 2010 13:34:46 -0800 Subject: LISA 2010 CFP Message-ID: Hello All, The USENIX Large Installation System Administration Conference is now accepting paper proposals. If you are interested in submitting a paper, please check out this blog post about submitting a paper (http://www.usenix.org/events/lisa10/cfp/), or feel free to contact me directly if you think you might have a topic to present. Thank you, Matthew From aahz at pythoncraft.com Thu Feb 18 16:40:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Feb 2010 13:40:42 -0800 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: In article <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d at westnet.com.au>, R (Chandra) Chandrasekhar wrote: > >--- >import subprocess > >width = 5 >height = 30 >colors = ['#abcdef]', '#456789'] >filename = "/tmp/image.png" > ># I want to get the equivalent of variable interpolation in Perl ># so that the command ># ># convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png Here's the equivalent of Peter's cute code in simpler form: cmd = [ 'convert', '-size', '%sx%s' % (width, height), 'gradient:%s-%s' % tuple(colors), # above could also be: 'gradient:%s-%s' % (colors[0], colors[1]), filename, ] subprocess.Popen(cmd) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 17:07:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 22:07:27 GMT Subject: Why this doesn't work? References: Message-ID: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: > nostat.__orig_get__ = nostat.__get__ I should point out that leading-and-trailing-double-underscore names are reserved for use by the language. It's unlikely that Python will introduce a special method named __orig_get__, and in truth the prohibition against using such names is honoured more in the breach than in the observance (e.g. people often use metadata names like __version__, __author__, etc.). But just be aware that you are in technical breach of Python best practices, and should consider renaming it as _orig_get or __orig_get. -- Steven From clp2 at rebertia.com Thu Feb 18 17:11:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Feb 2010 14:11:24 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7d97dc$0$1587$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <50697b2c1002181411r1a1c8eb9h5c244d54213dd848@mail.gmail.com> On Thu, Feb 18, 2010 at 11:58 AM, John Nagle wrote: > ? On that note, I went to a talk at Stanford yesterday by one of the > designers of Intel's Nelahem core. ?The four-core, eight thread > version is out now. ?The six-core, twelve thread version is working; > the speaker has one in his lab. ?The eight-core, sixteen thread version > is some months away. ?This isn't an expensive CPU; this is Intel's > "converged" mainstream product. ?(Although there will be a whole range > of "economy" and "performance" versions, all with the same core but > with some stuff turned off.) > > ? Python isn't ready for this. ?Not with the GIL. Is any language, save perhaps Erlang, really ready for it? Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 17:12:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 22:12:02 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <4b7dbb31$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 11:58:32 -0800, John Nagle wrote: > John Nagle wrote: > >> I look at this as Python's answer to multicore CPUs and "Go". > > On that note, I went to a talk at Stanford yesterday by one of the > designers of Intel's Nelahem core. The four-core, eight thread version > is out now. [...] > > Python isn't ready for this. Not with the GIL. Pardon me, but Python is perfectly ready for this. Why aren't you using Jython or IronPython, if the GIL is such a drag on your use-case? -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 17:17:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 22:17:57 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> Message-ID: <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 06:15:20 -0800, Steve Howell wrote: > On Feb 18, 1:23?am, Duncan Booth wrote: >> Jonathan Gardner wrote: >> > On Feb 17, 12:02?am, Lawrence D'Oliveiro > > central.gen.new_zealand> wrote: >> >> In message >> >> <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, >> >> >> Jonathan Gardner wrote: >> >> > I used to think anonymous functions (AKA blocks, etc...) would be >> >> > a nice feature for Python. >> >> >> > Then I looked at a stack trace from a different programming >> >> > language with lots of anonymous functions. (I believe it was >> >> > perl.) >> >> >> Didn?t it have source line numbers in it? >> >> >> What more do you need? >> >> > I don't know, but I tend to find the name of the function I called to >> > be useful. It's much more memorable than line numbers, particularly >> > when line numbers keep changing. >> >> > I doubt it's just me, though. >> >> Some problems with using just line numbers to track errors: >> >> In any language it isn't much use if you get a bug report from a >> shipped program that says there was an error on line 793 but no report >> of exactly which version of the shipped code was being run. >> >> Microsoft love telling you the line number: if IE gets a Javascript >> error it reports line number but not filename, so you have to guess >> which of the HTML page or one of many included files actually had the >> error. Plus the line number that is reported is often slightly off. >> >> Javascript in particular is often sent to the browser compressed then >> uncompressed and eval'd. That makes line numbers completely useless for >> tracking down bugs as you'll always get the line number of the eval. >> Also the way functions are defined in Javascript means you'll often >> have almost every function listed in a backtrace as 'Anonymous'. > > If this is an argument against using anonymous functions, then it is a > quadruple strawman. There really ought to be a special level of Hell for people who misuse "strawman" to mean "a weak or invalid argument" instead of what it actually means, which is a weak or invalid argument NOT HELD by your opponent, which you (generic you) made up specifically for the sake of shooting down. If you actually read what Duncan says, he prefixes his response with: "Some problems with using just line numbers to track errors". Duncan's post is an argument against relying on line numbers as your main, or only, source of information about the location of bugs in Javascript. In fact, this post is remarkable for the sheer number of actual strawman arguments that you (Steve Howell) use: > Shipping buggy code is a bad idea, even with named functions. Strawman #1: nobody said that shipping buggy code was a good idea, with or without named functions. But shipping buggy code *happens*, no matter how careful you are, so you need to expect bug reports back from users. (And they will be *hard to find* bugs, because if they were easy to find you would have found them in your own testing before shipping.) > Obscuring line numbers is a bad idea, even with named functions. Strawman #2: nobody said that obscuring line numbers was a good idea. But apparently compressing Javascript is valuable for other reasons, and obscuring the line numbers is the side-effect of doing so. And even knowing the line numbers is not necessarily useful, because many bugs aren't due to the line that raises the stack trace. Just because you know the line which failed doesn't mean you know how to fix the bug. > Having your customers stay on older versions of your software is a bad > idea, even with named functions. Strawman #3: nobody said that staying on older versions is a good idea. But sometimes it happens whether you like it or not. (Although I'd like to point out that from the end user's perspective, sometimes we don't want your stinkin' new version with all the anti- features and pessimations and will stick to the old version for as long as possible. If you don't like it, then think a bit harder before adding anti-features like fragile, easily-corrupted databases which perform really, really badly when your home directory is mounted over the network. I'm talking to you, Firefox developers.) And it doesn't really matter: you either end-of-life the old version, in which case you don't need to do anything about the bug report except say "upgrade", or you decide to continue support, in which case it doesn't matter whether the bug is reported for an old version or the latest version, you still need to fix it. > Not being able to know which version of software you're customer is > running is a bad idea, even with named functions. Strawman #4. See the pattern? When you attack a position the other guy hasn't taken, that's a strawman. When you make a weak argument, it's just a weak argument. -- Steven From apt.shansen at gmail.com Thu Feb 18 17:25:12 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 14:25:12 -0800 Subject: How to make an empty generator? Message-ID: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> This has to be a stupid question, but :) I have some generators that do stuff, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really "generators" because I want to call them /as/ a generator as part of a generalized system. The only way I can figure out how to make an empty generator is: def gen(): # do my one-time processing here return yield Is there a better way? The return/yield just makes me flinch slightly. I tried just raising StopIteration at the end, but of course that didn't work. TIA, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Thu Feb 18 17:26:33 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 14:26:33 -0800 (PST) Subject: Help with lambda References: Message-ID: <39ded391-c814-4c17-936f-3a4f55c3d9ec@b9g2000pri.googlegroups.com> On Feb 18, 4:28?am, lallous wrote: > > f = [lambda x: x ** n for n in xrange(2, 5)] This is (pretty much) what the above code does. >>> f = [] >>> n = 2 >>> f.append(lambda x: x**n) >>> n = 3 >>> f.append(lambda x: x**n) >>> n = 4 >>> f.append(lambda x: x**n) >>> n = 5 >>> f.append(lambda x: x**n) Now, when you call f[0], you are calling "lambda x: x**n". What is "n"? You need some way of creating a new namespace and a new variable pointing to what "n" was for that iteration. Python doesn't create a namespace for every iteration like some languages may. You have to be more explicit about that. After all, what would you expect the following code to do? >>> n = 5 >>> f = [lambda x: x**n for i in range(2,5)] >>> n = 2 >>> f[0][5] Or, just call a function that will have a new namespace *for every call* and generate a function within each execution of that function (like make_power does). From brendon.wickham at gmail.com Thu Feb 18 17:44:17 2010 From: brendon.wickham at gmail.com (Brendon Wickham) Date: Fri, 19 Feb 2010 09:44:17 +1100 Subject: Few questions on SOAP In-Reply-To: References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: On 19 February 2010 08:07, Mark Lawrence wrote: > Muhammad Alkarouri wrote: >> >> Your question is borderline if not out of topic in this group. I will >> make a few comments though. > > This might be a Python group, but threads often drift way off topic, which > added to the language itself make this a great group to read. ?If you don't > like the way a thread goes, you can always skip it. Perhaps...but he answered the question very well and with great, IMO, patience. From jgardner at jonathangardner.net Thu Feb 18 17:49:38 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 14:49:38 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: On Feb 18, 8:15?am, Steve Howell wrote: > > ? ? def print_numbers() > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > ? ? ? ? ? ? [n * n, n * n * n] > ? ? ? ? }.reject { |square, cube| > ? ? ? ? ? ? square == 25 || cube == 64 > ? ? ? ? }.map { |square, cube| > ? ? ? ? ? ? cube > ? ? ? ? }.each { |n| > ? ? ? ? ? ? puts n > ? ? ? ? } > ? ? end > If this style of programming were useful, we would all be writing Lisp today. As it turned out, Lisp is incredibly difficult to read and understand, even for experienced Lispers. I am pleased that Python is not following Lisp in that regard. for n in range(1,6): square = n*n cube = n*n*n if square == 25 or cube == 64: continue print cube From robert.kern at gmail.com Thu Feb 18 17:56:09 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 16:56:09 -0600 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: On 2010-02-18 16:25 PM, Stephen Hansen wrote: > This has to be a stupid question, but :) > > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only really > "generators" because I want to call them /as/ a generator as part of a > generalized system. > > The only way I can figure out how to make an empty generator is: > > def gen(): > # do my one-time processing here > > return > yield > > Is there a better way? The return/yield just makes me flinch slightly. I > tried just raising StopIteration at the end, but of course that didn't work. class once(object): def __init__(self, func, *args, **kwds): self.func = func self.args = args self.kwds = kwds def __iter__(self): return self def next(self): self.func(*self.args, **self.kwds) raise StopIteration() Then write regular functions with the one-time processing code (not generators!). When you go to pass them into your system that wants an iterator, just wrap it with once(func). -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 18:00:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 23:00:51 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <4b7dc6a2$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 08:15:46 -0800, Steve Howell wrote: > Just to be clear, I'm not saying it's unforgivable to occasionally ship > software with bugs. It happens. "Occasionally"? Oh, if only. I would say that there probably isn't a non-trivial application in the world that is entirely bug-free. If you're shipping something more complex than the proverbial "Hello World", chances are high that there will be bugs, and the more complex the app, the more bugs are likely. > Compressing Javascript is sometimes necessary, but I believe that often > mangles named functions too. It doesn't mangle the function, it mangles reporting of line numbers. But if you know the name of the function, it is much easier to recover from that loss of information. > To the the extent that your customer is running old software and cannot > always coherently describe tracebacks over a telephone, that problem can > be solved in the software itself, assuming an Internet connection. The > software can capture the traceback and report back to a server with the > version number. I don't understand why you repeatedly mention "old software". It is irrelevant: the software is either supported, or not supported. If it's not supported, you don't care about the bugs. If it is supported, then it doesn't matter whether it is version 2.2 or 2.3 or the bleeding edge 2.4- pre-alpha straight out of subversion, you still have to go through the same process of finding the bug, solving it, then rolling the fix out to all supported versions where the bug applies. That's not to say that the version number isn't useful information to have, because it can be, but distinguishing between old versions and the current version isn't a useful distinction. In a sense, there are no old versions, there are merely multiple supported current versions. > So, much of the argument against anonymous functions presented so far is > really orthogonal to whether functions are named or not. Not so. The point is that anonymous functions lack useful information, namely the function name. Because line numbers can be unreliable or even missing completely, and even when reliable many people have a mental blind-spot for them (I know I do, and I'm gratified to see I'm not the only one), lacking a good name for the function is a handicap. Not necessarily an insurmountable one, but anonymous functions are more troublesome than named functions. You wouldn't name your functions: f01, f02, f03, f04, ... f99 (say), unless you were trying to deliberately obfuscate your code. Anonymous functions are even more obfuscated than that. You can get away with it so long as you're only dealing with a few, in well-defined placed, but you wouldn't want to use them all over the place. -- Steven From sjdevnull at yahoo.com Thu Feb 18 18:04:28 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 18 Feb 2010 15:04:28 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> On Feb 18, 11:15?am, Steve Howell wrote: > ? ? def print_numbers() > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > ? ? ? ? ? ? [n * n, n * n * n] > ? ? ? ? }.reject { |square, cube| > ? ? ? ? ? ? square == 25 || cube == 64 > ? ? ? ? }.map { |square, cube| > ? ? ? ? ? ? cube > ? ? ? ? }.each { |n| > ? ? ? ? ? ? puts n > ? ? ? ? } > ? ? end > > IMHO there is no reason that I should have to name the content of each > of those four blocks of code, nor should I have to introduce the > "lambda" keyword. You could do it without intermediate names or lambdas in Python as: def print_numbers(): for i in [ cube for (square, cube) in [(n*n, n*n*n) for n in [1,2,3,4,5,6]] if square!=25 and cube!=64 ]: print i But frankly, although there's no reason that you _have_ to name the content at each step, I find it a lot more readable if you do: def print_numbers(): tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] filtered = [ cube for (square, cube) in tuples if square!=25 and cube!=64 ] for f in filtered: print f From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 18:08:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 23:08:32 GMT Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: <4b7dc870$0$8819$c3e8da3@news.astraweb.com> Sorry for breaking the threading, but Stephen's original post hasn't come through to my provider. On 2010-02-18 16:25 PM, Stephen Hansen wrote: > This has to be a stupid question, but :) > > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only > really "generators" because I want to call them /as/ a generator as > part of a generalized system. > > The only way I can figure out how to make an empty generator is: > > def gen(): > # do my one-time processing here > > return > yield If all you want is a generator that doesn't yield anything, then surely there isn't any one-time processing and you don't need the comment? >> Is there a better way? The return/yield just makes me flinch slightly. Meh. An empty generator is a funny thing to do, so it's not bad that it reads a bit funny. I don't have a problem with it. If it really annoys you, you could do this: def empty(): for x in []: yield -- Steven From robert.kern at gmail.com Thu Feb 18 18:30:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 17:30:54 -0600 Subject: How to make an empty generator? Message-ID: On Feb 18, 5:08 pm, Steven D'Aprano wrote: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > > This has to be a stupid question, but :) > > > I have some generators that do stuff, then start yielding results. On > > occasion, I don't want them to yield anything ever-- they're only > > really "generators" because I want to call them /as/ a generator as > > part of a generalized system. > > > The only way I can figure out how to make an empty generator is: > > > def gen(): > > # do my one-time processing here > > > return > > yield > > If all you want is a generator that doesn't yield anything, then surely > there isn't any one-time processing and you don't need the comment? Sure there is. Python doesn't know that nothing gets yielded until it hits the return statement before the yield. When it calls .next() on the iterator, the code elided by the comment executes, then the return is hit, a StopIteration exception is raised, and the iteration is complete. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From ben+python at benfinney.id.au Thu Feb 18 18:33:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 10:33:00 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: <877hqaazmb.fsf@benfinney.id.au> Robert Kern writes: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > The only way I can figure out how to make an empty generator is: > > > > def gen(): > > # do my one-time processing here > > > > return > > yield > > > > Is there a better way? The return/yield just makes me flinch > > slightly. I tried just raising StopIteration at the end, but of > > course that didn't work. No need to define functions or classes; let a generator expression take care of it for you:: >>> foo = (x for x in list()) >>> foo.next() Traceback (most recent call last): File "", line 1, in StopIteration -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard Stallman, 2002 | Ben Finney From contact at xavierho.com Thu Feb 18 18:35:02 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 19 Feb 2010 09:35:02 +1000 Subject: How to make an empty generator? In-Reply-To: References: Message-ID: <2d56febf1002181535h782e8f41l9e50a87dd7360d36@mail.gmail.com> I don't think it's a stupid question at all. =]. But wouldn't it solve the problem if you call the generator the first time you need it to yield? Cheers, Xav On Fri, Feb 19, 2010 at 9:30 AM, Robert Kern wrote: > On Feb 18, 5:08 pm, Steven D'Aprano > wrote: > > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > > > > This has to be a stupid question, but :) > > > > > I have some generators that do stuff, then start yielding results. On > > > occasion, I don't want them to yield anything ever-- they're only > > > really "generators" because I want to call them /as/ a generator as > > > part of a generalized system. > > > > > The only way I can figure out how to make an empty generator is: > > > > > def gen(): > > > # do my one-time processing here > > > > > return > > > yield > > > > If all you want is a generator that doesn't yield anything, then surely > > there isn't any one-time processing and you don't need the comment? > > Sure there is. Python doesn't know that nothing gets yielded until it hits > the return statement before the yield. When it calls .next() on the > iterator, the code elided by the comment executes, then the return is hit, a > StopIteration exception is raised, and the iteration is complete. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Feb 18 18:36:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 15:36:02 -0800 Subject: How to make an empty generator? In-Reply-To: References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern wrote: > class once(object): > def __init__(self, func, *args, **kwds): > self.func = func > self.args = args > self.kwds = kwds > > def __iter__(self): > return self > > def next(self): > self.func(*self.args, **self.kwds) > raise StopIteration() > Hmm, yeah. I'd probably tweak it into a decorator and name it sideeffect_only or something, but yeah, that's the right approach at least. My motivation is clarity, I can just see a colleague a year from now asking me, "... what the hell is return / yield?" and although this is more expensive, its less clear to me. Thanks. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Feb 18 18:37:09 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 15:37:09 -0800 Subject: How to make an empty generator? In-Reply-To: <4b7dc870$0$8819$c3e8da3@news.astraweb.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <4b7dc870$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002181537o441a4383s64656730c2dd5264@mail.gmail.com> On Thu, Feb 18, 2010 at 3:08 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > The only way I can figure out how to make an empty generator is: > > > > def gen(): > > # do my one-time processing here > > > > return > > yield > > If all you want is a generator that doesn't yield anything, then surely > there isn't any one-time processing and you don't need the comment? > Its possible I didn't explain myself well. I don't want a generator that does /nothing at all/, but a generator that yields nothing. Basically, I have a core system that loads up a bunch of modules dynamically. The API of these modules is that their initialization function is a generator that yields objects that the core system juggles. For the majority of the cases, this is just fine. A couple modules though, just really need to do a one-time action, and everything's done. I /could/ change the initialization function to return a generator, and not be a generator itself, and check if its None or not, etc. But I don't really want to, as I like the API the way it is. So really, the above generator looks like: def initialize(): os.environ["BLAH"] = 5 return yield In that its doing a single side-effect action and that's it. > >> Is there a better way? The return/yield just makes me flinch slightly. > > Meh. An empty generator is a funny thing to do, so it's not bad that it > reads a bit funny. I don't have a problem with it. > It doesn't -really- annoy me, it just makes me flinch slightly, and that's very rare. Even the stranger things to do in Python rarely make me flinch. So I was wondering if I missed something basically, and if there's a proper way to do it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Feb 18 18:40:01 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 15:40:01 -0800 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> Message-ID: <7a9c25c21002181540x7ac9bc33uf112609b9e47ef02@mail.gmail.com> On Thu, Feb 18, 2010 at 3:36 PM, Stephen Hansen wrote: > My motivation is clarity, I can just see a colleague a year from now asking > me, "... what the hell is return / yield?" and although this is more > expensive, its less clear to me. > MORE clear to me. A class / decorator / whatever may be more expensive then return / yield, but it reads better and is more clear, to me. Not less. Ahem. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Thu Feb 18 18:47:18 2010 From: john at castleamber.com (John Bokma) Date: Thu, 18 Feb 2010 17:47:18 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <878waqw1h5.fsf@castleamber.com> Jonathan Gardner writes: > On Feb 18, 8:15?am, Steve Howell wrote: >> >> ? ? def print_numbers() >> ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| >> ? ? ? ? ? ? [n * n, n * n * n] >> ? ? ? ? }.reject { |square, cube| >> ? ? ? ? ? ? square == 25 || cube == 64 >> ? ? ? ? }.map { |square, cube| >> ? ? ? ? ? ? cube >> ? ? ? ? }.each { |n| >> ? ? ? ? ? ? puts n >> ? ? ? ? } >> ? ? end >> > > If this style of programming were useful, we would all be writing Lisp > today. As it turned out, Lisp is incredibly difficult to read and > understand, even for experienced Lispers. I am pleased that Python is > not following Lisp in that regard. > > for n in range(1,6): ^ should be 7 But for the rest, I agree with you. I can read Steve's version, but even to an experienced Perl programmer that looks quite noisy :-) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From arnodel at googlemail.com Thu Feb 18 18:49:08 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Feb 2010 15:49:08 -0800 (PST) Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> Message-ID: <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> On 18 Feb, 23:33, Ben Finney wrote: [...] > No need to define functions or classes; let a generator expression take > care of it for you:: > > ? ? >>> foo = (x for x in list()) > ? ? >>> foo.next() > ? ? Traceback (most recent call last): > ? ? ? File "", line 1, in > ? ? StopIteration What about foo = iter('') Then there is the interesting foo = iter(int, 0) :) -- Arnaud From john at castleamber.com Thu Feb 18 18:50:29 2010 From: john at castleamber.com (John Bokma) Date: Thu, 18 Feb 2010 17:50:29 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <878waqw1h5.fsf@castleamber.com> Message-ID: <874olew1bu.fsf@castleamber.com> John Bokma writes: > Jonathan Gardner writes: > >> On Feb 18, 8:15?am, Steve Howell wrote: >>> >>> ? ? def print_numbers() >>> ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| >>> ? ? ? ? ? ? [n * n, n * n * n] >>> ? ? ? ? }.reject { |square, cube| >>> ? ? ? ? ? ? square == 25 || cube == 64 >>> ? ? ? ? }.map { |square, cube| >>> ? ? ? ? ? ? cube >>> ? ? ? ? }.each { |n| >>> ? ? ? ? ? ? puts n >>> ? ? ? ? } >>> ? ? end >>> >> >> If this style of programming were useful, we would all be writing Lisp >> today. As it turned out, Lisp is incredibly difficult to read and >> understand, even for experienced Lispers. I am pleased that Python is >> not following Lisp in that regard. >> >> for n in range(1,6): > > ^ should be 7 > > But for the rest, I agree with you. I can read Steve's version, but even > to an experienced Perl programmer that looks quite noisy :-) Oh, wait, it's Ruby :-D. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From jjposner at optimum.net Thu Feb 18 18:57:10 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 18 Feb 2010 18:57:10 -0500 Subject: Why this doesn't work? In-Reply-To: References: Message-ID: <4B7DD3D6.9030403@optimum.net> On 2/18/2010 12:28 PM, mk wrote: > > Sorry to bother everyone again, but I have this problem bugging me: > > #!/usr/bin/python -i > > class Foo(object): > > def nostat(self,val): > print val > > nostat.__orig_get__ = nostat.__get__ > > @staticmethod > def nostatget(*args, **kwargs): > print 'args:', args, 'kwargs:', kwargs > nostat.__orig_get__(*args, **kwargs) > > nostat.__get__ = nostatget > setattr(nostat,'__get__',nostatget) > > > f = Foo() > > f.nostat('a') > > print f.nostat.__get__ is f.nostat.__orig_get__ > > > This produces: > > a > False > > I expected to see 'nostatget' output: nostat.__get__ = nostatget > obviously failed to replace this function's __get__ method. I don't quite understand the above sentence, so I'm assuming that you wanted the final "is" test to be "True" instead of "False". It looks like you've replaced ... (A) the original __get__() method ... with ... (B) a new method that *calls* the original __get__() method So why should you expect (A) and (B) to be the same object? > > The question is why? Isn't __get__ a normal attribute of a function nostat? > > This is made so much weirder that nostat.__get__ is no longer original > __get__, so it looks like it should have been replaced, but if so, why > nostatget doesn't get called? > > Regards, > mk > > > -John From tjreedy at udel.edu Thu Feb 18 19:08:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Feb 2010 19:08:25 -0500 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: On 2/18/2010 5:25 PM, Stephen Hansen wrote: > This has to be a stupid question, but :) > > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only really > "generators" because I want to call them /as/ a generator as part of a > generalized system. > > The only way I can figure out how to make an empty generator is: > > def gen(): > # do my one-time processing here > > return > yield > > Is there a better way? The return/yield just makes me flinch slightly. I > tried just raising StopIteration at the end, but of course that didn't work. Did you try def gen(): if 0: yield ? tjr From wolftracks at invalid.com Thu Feb 18 19:10:31 2010 From: wolftracks at invalid.com (W. eWatson) Date: Thu, 18 Feb 2010 16:10:31 -0800 Subject: [Tutor] "Sounding" Off, IDLE (Win7) Message-ID: In Win7 IDLE, when I type in something with a syntax problem, a bell rings. How do I stop that? I've looked at Control Panel Sounds, but don't see anything of apparent use. From robert.kern at gmail.com Thu Feb 18 19:12:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 18:12:10 -0600 Subject: How to make an empty generator? In-Reply-To: <877hqaazmb.fsf@benfinney.id.au> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> Message-ID: On 2010-02-18 17:33 PM, Ben Finney wrote: > Robert Kern writes: > >> On 2010-02-18 16:25 PM, Stephen Hansen wrote: >>> The only way I can figure out how to make an empty generator is: >>> >>> def gen(): >>> # do my one-time processing here >>> >>> return >>> yield >>> >>> Is there a better way? The return/yield just makes me flinch >>> slightly. I tried just raising StopIteration at the end, but of >>> course that didn't work. > > No need to define functions or classes; let a generator expression take > care of it for you:: > > >>> foo = (x for x in list()) > >>> foo.next() > Traceback (most recent call last): > File "", line 1, in > StopIteration He doesn't want *any* empty generator. He wants an iterator that executes some given side-effect-producing code then immediately raises the StopIteration. -- 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 rhodri at wildebst.demon.co.uk Thu Feb 18 19:12:10 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Feb 2010 00:12:10 -0000 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: On Thu, 18 Feb 2010 22:11:24 -0000, Chris Rebert wrote: > On Thu, Feb 18, 2010 at 11:58 AM, John Nagle wrote: > >> On that note, I went to a talk at Stanford yesterday by one of the >> designers of Intel's Nelahem core. The four-core, eight thread >> version is out now. The six-core, twelve thread version is working; >> the speaker has one in his lab. The eight-core, sixteen thread version >> is some months away. This isn't an expensive CPU; this is Intel's >> "converged" mainstream product. (Although there will be a whole range >> of "economy" and "performance" versions, all with the same core but >> with some stuff turned off.) >> >> Python isn't ready for this. Not with the GIL. > > Is any language, save perhaps Erlang, really ready for it? occam :-) -- Rhodri James *-* Wildebeeste Herder to the Masses From ryan at rfk.id.au Thu Feb 18 19:19:32 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Fri, 19 Feb 2010 11:19:32 +1100 Subject: Upgrading Py2exe App In-Reply-To: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: <1266538772.3062.12.camel@rambutan> On Thu, 2010-02-18 at 07:46 -0800, T wrote: > I have a Python app which I converted to an EXE (all files separate; > single EXE didn't work properly) via py2exe - I plan on distributing > this and would like the ability to remotely upgrade the program (for > example, via HTTP/HTTPS). Looks like it's not just the EXE that I > will need need to replace (DLLs, the library.zip, etc.). What would > be the best way to go about doing this? I've been working on an auto-update framework for my own frozen apps, you might find it useful: http://pypi.python.org/pypi/esky Docs are a little scarce at the moment, the next release will hopefully come with a short tutorial (as well as support for cx_freeze and maybe py2app, depending on how adventurous I'm feeling). 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From robert.kern at gmail.com Thu Feb 18 19:20:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 18:20:49 -0600 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> Message-ID: On 2010-02-18 17:36 PM, Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern > wrote: > > class once(object): > def __init__(self, func, *args, **kwds): > self.func = func > self.args = args > self.kwds = kwds > > def __iter__(self): > return self > > def next(self): > self.func(*self.args, **self.kwds) > raise StopIteration() > > > Hmm, yeah. I'd probably tweak it into a decorator and name it > sideeffect_only or something, but yeah, that's the right approach at least. Well, with a decorator, you could even use the cringeworthy return/yield syntax while keeping it hidden from your users (not to mention reducing the amount of boilerplate people need to write). from functools import wraps def sideeffect_only(func): @wraps(func) def wrapper(*args, **kwds): func(*args, **kwds) # Some helpful comment about why there is a return/yield. return yield return wrapper But you can also write one where the wrapper() returns a once() instance. It might be useful to use the once class instead of a generator such that you can write code that distinguishes side-effect only iterators from other iterators in your system. It might be useful for debugging if nothing else. -- 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 rhodri at wildebst.demon.co.uk Thu Feb 18 19:26:59 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Feb 2010 00:26:59 -0000 Subject: string to list when the contents is a list References: <9fc69505-3224-4aa9-9357-2abb0af4abd2@c16g2000yqd.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 14:52:29 -0000, nn wrote: > Wes James wrote: >> I have been trying to create a list form a string. The string will be >> a list (this is the contents will look like a list). i.e. "[]" or >> "['a','b']" >> >> The "[]" is simple since I can just check if value == "[]" then return >> [] >> >> But with "['a','b']" I have tried and get: >> >> a="['a','b']" >> >> b=a[1:-1].split(',') >> >> returns >> >> [ " 'a' "," 'b' " ] >> >> when I want it to return ['a','b']. >> >> How can I do this? >> >> thx, >> >> -wes > > > I am surprised nobody gave you the simple answer yet that may even > work for your situation: > > b=a[2:-2].split("','") Because it's really *very* not robust. "Harmless" whitespace defeats it for starters, and that's one of the most likely things to vary between example data and reality. If you trust your data to be well-formed enough for this to work, you might as well use eval() instead. If you don't, parsing is the only sensible answer. -- Rhodri James *-* Wildebeeste Herder to the Masses From anfedorov at gmail.com Thu Feb 18 19:30:40 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 18 Feb 2010 19:30:40 -0500 Subject: Bypassing properties on an object (also with __slots__?) Message-ID: <7659cab31002181630j7e7ebdbdw1110b859a587d568@mail.gmail.com> Two questions: 1 - is it documented that o.__dict__[attr] is a reliable way to bypass property methods? 2 - can one bypass a property method if the class has __slots__? Reason: I have a couple of different flavors of request objects which I need to make lazily conform to a standard interface. As a simplified example, a_foo_request = { 'ip': '1.2.3.4' } a_bar_request = { 'my-ip': b'\x01\x02\x03\x04' } My solution is to create two classes: class FooRequest(dict): @property def ip(self): return self['ip'] class BarRequest(dict): @property def ip(self): return "%i.%i.%i.%i" % struct.unpack("4B", self['my-ip']) Then: FooRequest(a_foo_request).ip == '1.2.3.4' # and req = BarRequest(a_bar_request) req.ip == '1.2.3.4' But some of these getters are CPU-intensive, and since the extended objects always remain immutable, I memoize them in req.__dict__, like: class BarRequest(dict): @property def ip(self): if 'ip' in self.__dict__: return self.__dict__['ip'] else: self.__dict__['ip'] = "%i.%i.%i.%i" % struct.unpack("4B", self['my-ip']) return self.__dict__['ip'] Which works as intended, and (I think) can be made prettier with a custom constant_property decorator. So... Question 0: Is there an obvious better way of achieving this functionality? Question 1: Is it safe to rely on __dict__ to bypass properties this way? Question 2: I'd like to use __slots__, but I can't seem to find a way to stop the property method from recursing. Is there one? Cheers, Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 19:32:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 00:32:03 GMT Subject: How to make an empty generator? References: Message-ID: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: > > If all you want is a generator that doesn't yield anything, then > > surely there isn't any one-time processing and you don't need the > > comment? > > Sure there is. Python doesn't know that nothing gets yielded until it > hits the return statement before the yield. When it calls .next() on the > iterator, the code elided by the comment executes, then the return is > hit, a StopIteration exception is raised, and the iteration is complete. I don't understand why you care about having *any* code before the StopIteration. That's like: def empty(): for x in range(1000): pass # Spin wheels uselessly return yield What's the point of the wheel spinning? Did I miss something? -- Steven From ben+python at benfinney.id.au Thu Feb 18 19:33:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 11:33:00 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> Message-ID: <871vgiawub.fsf@benfinney.id.au> Arnaud Delobelle writes: > What about > foo = iter('') That doesn't return a generator. >>> foo = iter('') >>> foo Whether the OP needs to create a generator, or just any iterable type, isn't clear. Robert Kern writes: > He doesn't want *any* empty generator. He wants an iterator that > executes some given side-effect-producing code then immediately raises > the StopIteration. Ah, hm. That's a rather perverse use case, but I'm sure the OP has their reasons. It's going to confuse a reader who isn't expecting it, no matter how simply it's done. So, I think the best answer is what has already been suggested, but that it's perverse enough that the hack *needs* a comment to say why it's being done. def make_empty_generator_with_side_effect(): """ Make a generator that does important work, but is empty. """ # Do the important work here. spam = object() # Make this function return an empty generator. if False: yield -- \ ?When cryptography is outlawed, bayl bhgynjf jvyy unir | `\ cevinpl.? ?Anonymous | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 19:36:00 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 00:36:00 GMT Subject: How secure are temp files created via tempfile.TemporaryFile()? References: <1266519267.4170.1360680003@webmail.messagingengine.com> <4B7D95F7.9020906@mrabarnett.plus.com> Message-ID: <4b7ddcf0$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 15:09:28 -0500, python wrote: > That's my concern - can other applications really read my temp files > created with tempfile.TemporaryFile( delete=True )? >>> import tempfile >>> x = tempfile.TemporaryFile(delete=True) Traceback (most recent call last): File "", line 1, in TypeError: TemporaryFile() got an unexpected keyword argument 'delete' The Fine Manual has good information about the security of the various calls: http://docs.python.org/library/tempfile.html tempfile.TemporaryFile(...) Return a file-like object that can be used as a temporary storage area. ... your code should not rely on a temporary file created using this function having or not having a visible name in the file system. ... tempfile.NamedTemporaryFile(...) This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file system ... Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms... > I don't think so because: > > 1. These files appear to be exclusively locked by my process, eg. no > other processes can read or write to these temp files except the process > that created these files. Exclusive locks are advisory, not mandatory, on some operating systems, so you can't rely on it. Recent versions of Windows have an interface to allow "backup software" to read files opened in exclusive mode, and I believe that the kernel can read *and write* to open files (although I welcome correction). http://en.wikipedia.org/wiki/File_locking And naturally, if your system is compromised with a root kit, then you can't trust *anything*, including file locks. But nobody expects an application to take responsibility for working securely in the face of a root kit :) > 2. As soon as my process terminates (voluntarily or involuntarily), the > temp file gets deleted. > > But I want to make sure. I think the best practice is platform-dependent: if os.name = "posix": # Unix, Linux, OpenBSD, FreeBSD, ... tmpfile = tempfile.TemporaryFile delete = None elif os.name in ["nt", "ce"]: # Windows NT, XP, 2000, CE, ... tmpfile = tempfile.NamedTemporaryFile delete = True else: # FIXME What to do for Mac, OS/2, RiscOS, Java? tmpfile = tempfile.TemporaryFile delete = None if delete is not None: f = tmpfile(*args, delete=delete) else: f = tmpfile(*args) -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 19:36:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 00:36:10 GMT Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> Message-ID: <4b7ddcfa$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 18:12:10 -0600, Robert Kern wrote: > He wants an iterator that executes some given side-effect-producing code > then immediately raises the StopIteration. Ah, that's the bit I missed! Yewww. Programming by side-effect... I hope the original poster has a good reason for such a thing. -- Steven From jgardner at jonathangardner.net Thu Feb 18 20:11:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 17:11:19 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <004104b2-519d-4d03-ba0f-c17e115e416b@s33g2000prm.googlegroups.com> On Feb 18, 3:04?pm, "sjdevn... at yahoo.com" wrote: > > You could do it without intermediate names or lambdas in Python as: > def print_numbers(): > ? ? for i in [ cube for (square, cube) in > ? ? ? ? ? ? ? ? ? ? ? ? ?[(n*n, n*n*n) for n in [1,2,3,4,5,6]] > ? ? ? ? ? ? ? ?if square!=25 and cube!=64 ]: > ? ? ? ? print i > > But frankly, although there's no reason that you _have_ to name the > content at each step, I find it a lot more readable if you do: > > def print_numbers(): > ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > cube!=64 ] > ? ? for f in filtered: > ? ? ? ? print f Step away from the keyboard! This is a programmer's arrest! There are laws around here, laws that we can't allow to be broken. You've just broken 12 of them. You think the laws don't apply to you, huh, punk? HUH? I'm sentencing you to three months HARD LABOR in Ruby for that code you just wrote. And if you think it's too harsh, then I'll sentence you to NINE MONTHS PHP and see how you feel about that! ;-) From rhodri at wildebst.demon.co.uk Thu Feb 18 20:11:52 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Feb 2010 01:11:52 -0000 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 09:50:14 -0000, DANNY wrote: > If I want to have a MPEG-4/10 coded video and stream it through the > network and than have the same video on the client side, what should I > use and of course I don't want to have raw MPEG data, because than I > couldn't extract the frames to manipulate them. By the looks of it, pyffmpeg may have some support for streamed input. If not, you might be able to put something together from tstools (http://developer.berlios.de/projects/tstools/) -- it's not what the tools were intended for, but there are Python bindings to the libraries that might help depending on exactly how you are streaming your video. Unfortunately the documentation is sparse to put it mildly, and pyffmpeg makes tstools look positively informative about how you're supposed to use it. -- Rhodri James *-* Wildebeeste Herder to the Masses From jgardner at jonathangardner.net Thu Feb 18 20:19:32 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 17:19:32 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Feb 18, 1:28?am, Sreejith K wrote: > On Feb 18, 1:57?pm, Steven D'Aprano > > > > wrote: > > On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > > > On Feb 17, 10:48?pm, Sreejith K wrote: > > >> Hi everyone, > > > >> I need to implement custom import hooks for an application > > >> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an > > >> application to import certain modules (say socket module). Google app > > >> engine is using a module hook to do this (HardenedModulesHook in > > >> google/ appengine/tools/dev_appserver.py). But I want to allow that > > >> application to use an sdk module (custom) which imports and uses socket > > >> module. But the module hook restricts the access by sdk. Finding out, > > >> which file is importing a module give a solution?? ie. If the > > >> application is importing socket module, I want to restrict it. But if > > >> the sdk module is importing socket I want to allow it. Is there any way > > >> I can do this ? > > > >> Application > > >> ======== > > >> import sdk > > >> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > > >> ImportError) > > > >> SDK > > >> ==== > > >> import socket ? ? ? ? ? ? ? # need to allow this > > > > SDK > > > === > > > import socket > > > > App > > > === > > > import SDK > > > import sys > > > socket = sys.modules['socket'] > > > I'm not sure, but I think Sreejith wants to prohibit imports from the App > > layer while allowing them from the SDK layer, not work around a > > prohibition in the SDK layer. > > > In other words, he wants the import hook to do something like this: > > > if module is socket and the caller is not SKD: > > ? ? prohibit > > else > > ? ? allow > > > I could be wrong of course. > > > @Steven, Thats exactly what I want.. Anyway to do that ?? > My point was that it's really pointless to try to enforce any such thing on the program or programmer. There are ways around it. If you don't want them to play with socket, write in the documentation: "Don't play with the 'socket' module." If you want to prevent them from touching sockets at all, it's time to rethink your design. You may want to have a talk with Bruce Schneier, or at least read what he's written if you still think you need to somehow shut down a part of the system to its users. Oftentimes, programmers think they need to have control over what other people write, forgetting that they are able to do what they do due to the freedoms afforded them. They also forget that they are not in control of what other programmers do, anymore than a grocery store who refuses to stock a certain product can prevent people from getting that product. Write your code to expand freedoms, not limit them. If your design depends on limiting the choices of your users, you have done something wrong. From mwilson at the-wire.com Thu Feb 18 20:28:49 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 18 Feb 2010 20:28:49 -0500 Subject: How to make an empty generator? References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: > >> > If all you want is a generator that doesn't yield anything, then >> > surely there isn't any one-time processing and you don't need the >> > comment? >> >> Sure there is. Python doesn't know that nothing gets yielded until it >> hits the return statement before the yield. When it calls .next() on the >> iterator, the code elided by the comment executes, then the return is >> hit, a StopIteration exception is raised, and the iteration is complete. > > I don't understand why you care about having *any* code before the > StopIteration. That's like: > > def empty(): > for x in range(1000): > pass # Spin wheels uselessly > return > yield > > > What's the point of the wheel spinning? Did I miss something? I wonder whether it's for some kind of framework with a main loop like for it in list_of_iterables: for x in it: do_this_or_that (x) where, every once in a while one wants to throw some arbitrary code into the process, in the form of an empty iterable with side effects. Mel. From rantingrick at gmail.com Thu Feb 18 22:26:51 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 18 Feb 2010 19:26:51 -0800 (PST) Subject: "Sounding" Off, IDLE (Win7) References: Message-ID: <2a3bacb8-b324-4189-a98a-d35b70358b48@i39g2000yqm.googlegroups.com> On Feb 18, 6:10?pm, "W. eWatson" wrote: > In Win7 IDLE, when I type in something with a syntax problem, a bell > rings. How do I stop that? I've looked at Control Panel Sounds, but > don't see anything of apparent use. Monkey Patch Said: """ Turn off your speakers""" From showell30 at yahoo.com Thu Feb 18 22:43:14 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 19:43:14 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <4b7dc6a2$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 18, 3:00?pm, Steven D'Aprano wrote: > [...] > You wouldn't name your functions: > > f01, f02, f03, f04, ... f99 > Exactly. > (say), unless you were trying to deliberately obfuscate your code. > Anonymous functions are even more obfuscated than that. You can get away > with it so long as you're only dealing with a few, in well-defined > placed, but you wouldn't want to use them all over the place. > I have contributed to the confusion of this discussion by talking about "anonymous functions," when the original context was "anonymous blocks." As I mentioned in an earlier response, most anonymous blocks in Ruby are placed within outer functions, so they're not that hard to locate in a traceback that provides only function names. And, of course, it is often the case that you host Ruby code on your own web server, or that you distribute Ruby code without compressing it, in which case you get a sane traceback that provides line numbers. You actually use anonymous blocks in your own code, in a few, well- defined places (generally loops). These excerpts are taken from obfuscate.py: quotient = a//mm a, mm = mm, a%mm xx, x = x - quotient*xx, xx yy, y = y - quotient*yy, yy rail = it.next() # The rail we add to. assert 0 <= rail < rails fence[rail].append(c) # Save one non-chaff character. buffer.append(msg.next()) # And toss away more chaff. n = self.hash(key) % factor key = self.mod_key(key) self.get_chars(n, msg) # Careful here! Not all classes have a __dict__! adict = getattr(obj, '__dict__', {}) for name, attr in adict.items(): if inspect.ismethoddescriptor(attr): d[nm + '.' + name] = attr.__get__(obj) If any of the above code were to fail on a customer site, you'd probably want to get line numbers in a traceback. I'm guessing you probably don't distribute your code in compressed form, and you probably take care to make sure it works right in the first place, and you probably have source control to help you pull up old versions of your code. I notice that you even have a __version__ identifier in your source code, which users of your library could capture in their tracebacks. In other words, you probably use mostly the same practices that I use, except that we seem to differ on the utility or expressiveness or Ruby blocks, or maybe we're arguing at cross purposes. From steve at holdenweb.com Thu Feb 18 22:48:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 22:48:21 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 18 Feb 2010 06:15:20 -0800, Steve Howell wrote: [...] > There really ought to be a special level of Hell for people who misuse > "strawman" to mean "a weak or invalid argument" instead of what it > actually means, which is a weak or invalid argument NOT HELD by your > opponent, which you (generic you) made up specifically for the sake of > shooting down. > > If you actually read what Duncan says, he prefixes his response with: > > "Some problems with using just line numbers to track errors". > > Duncan's post is an argument against relying on line numbers as your > main, or only, source of information about the location of bugs in > Javascript. > > In fact, this post is remarkable for the sheer number of actual strawman > arguments that you (Steve Howell) use: > > >> Shipping buggy code is a bad idea, even with named functions. > > Strawman #1: nobody said that shipping buggy code was a good idea, with > or without named functions. But shipping buggy code *happens*, no matter > how careful you are, so you need to expect bug reports back from users. > > (And they will be *hard to find* bugs, because if they were easy to find > you would have found them in your own testing before shipping.) > > >> Obscuring line numbers is a bad idea, even with named functions. > > Strawman #2: nobody said that obscuring line numbers was a good idea. But > apparently compressing Javascript is valuable for other reasons, and > obscuring the line numbers is the side-effect of doing so. > > And even knowing the line numbers is not necessarily useful, because many > bugs aren't due to the line that raises the stack trace. Just because you > know the line which failed doesn't mean you know how to fix the bug. > > >> Having your customers stay on older versions of your software is a bad >> idea, even with named functions. > > Strawman #3: nobody said that staying on older versions is a good idea. > But sometimes it happens whether you like it or not. > > (Although I'd like to point out that from the end user's perspective, > sometimes we don't want your stinkin' new version with all the anti- > features and pessimations and will stick to the old version for as long > as possible. If you don't like it, then think a bit harder before adding > anti-features like fragile, easily-corrupted databases which perform > really, really badly when your home directory is mounted over the > network. I'm talking to you, Firefox developers.) > > And it doesn't really matter: you either end-of-life the old version, in > which case you don't need to do anything about the bug report except say > "upgrade", or you decide to continue support, in which case it doesn't > matter whether the bug is reported for an old version or the latest > version, you still need to fix it. > > >> Not being able to know which version of software you're customer is >> running is a bad idea, even with named functions. > > Strawman #4. > > See the pattern? When you attack a position the other guy hasn't taken, > that's a strawman. When you make a weak argument, it's just a weak > argument. > Next week: Lesson 2 - Ad Hominem Attacks regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Feb 18 22:49:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 22:49:16 -0500 Subject: Few questions on SOAP In-Reply-To: References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: Brendon Wickham wrote: > On 19 February 2010 08:07, Mark Lawrence wrote: >> Muhammad Alkarouri wrote: >>> Your question is borderline if not out of topic in this group. I will >>> make a few comments though. >> This might be a Python group, but threads often drift way off topic, which >> added to the language itself make this a great group to read. If you don't >> like the way a thread goes, you can always skip it. > > > Perhaps...but he answered the question very well and with great, IMO, patience. +1 -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Feb 18 22:52:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 22:52:13 -0500 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern > wrote: > > class once(object): > def __init__(self, func, *args, **kwds): > self.func = func > self.args = args > self.kwds = kwds > > def __iter__(self): > return self > > def next(self): > self.func(*self.args, **self.kwds) > raise StopIteration() > > > Hmm, yeah. I'd probably tweak it into a decorator and name it > sideeffect_only or something, but yeah, that's the right approach at least. > > My motivation is clarity, I can just see a colleague a year from now > asking me, "... what the hell is return / yield?" and although this is > more expensive, its less clear to me. > > Thanks. > --S > So add a comment to the yield statement so it reads yield # force empty generator I realise that Jacob Kaplan-Moss calls comments in the code "lies", but the reader really only needs a small clue. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From showell30 at yahoo.com Thu Feb 18 22:57:35 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 19:57:35 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: On Feb 18, 3:04?pm, "sjdevn... at yahoo.com" wrote: > On Feb 18, 11:15?am, Steve Howell wrote: > > > ? ? def print_numbers() > > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > > ? ? ? ? ? ? [n * n, n * n * n] > > ? ? ? ? }.reject { |square, cube| > > ? ? ? ? ? ? square == 25 || cube == 64 > > ? ? ? ? }.map { |square, cube| > > ? ? ? ? ? ? cube > > ? ? ? ? }.each { |n| > > ? ? ? ? ? ? puts n > > ? ? ? ? } > > ? ? end > > > IMHO there is no reason that I should have to name the content of each > > of those four blocks of code, nor should I have to introduce the > > "lambda" keyword. > > You could do it without intermediate names or lambdas in Python as: > def print_numbers(): > ? ? for i in [ cube for (square, cube) in > ? ? ? ? ? ? ? ? ? ? ? ? ?[(n*n, n*n*n) for n in [1,2,3,4,5,6]] > ? ? ? ? ? ? ? ?if square!=25 and cube!=64 ]: > ? ? ? ? print i The problem with list comprehensions is that they read kind of out of order. On line 2 you are doing the first operation, then on line 3 you are filtering, then on line 1 your are selecting, then on line 4 you are printing. For such a small example, your code is still quite readable. > But frankly, although there's no reason that you _have_ to name the > content at each step, I find it a lot more readable if you do: > > def print_numbers(): > ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > cube!=64 ] > ? ? for f in filtered: > ? ? ? ? print f The names you give to the intermediate results here are terse--"tuples" and "filtered"--so your code reads nicely. In a more real world example, the intermediate results would be something like this: departments departments_in_new_york departments_in_new_york_not_on_bonus_cycle employees_in_departments_in_new_york_not_on_bonus_cycle names_of_employee_in_departments_in_new_york_not_on_bonus_cycle From python at mrabarnett.plus.com Thu Feb 18 22:57:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 03:57:53 +0000 Subject: "Sounding" Off, IDLE (Win7) In-Reply-To: <2a3bacb8-b324-4189-a98a-d35b70358b48@i39g2000yqm.googlegroups.com> References: <2a3bacb8-b324-4189-a98a-d35b70358b48@i39g2000yqm.googlegroups.com> Message-ID: <4B7E0C41.5000405@mrabarnett.plus.com> rantingrick wrote: > On Feb 18, 6:10 pm, "W. eWatson" wrote: >> In Win7 IDLE, when I type in something with a syntax problem, a bell >> rings. How do I stop that? I've looked at Control Panel Sounds, but >> don't see anything of apparent use. > > Monkey Patch Said: """ Turn off your speakers""" But what if you like to listen to music while programming? Look in the folder \Lib\idlelib for a file called "config-extensions.def". In it is a line: bell=1 Change that to: bell=0 Save the file and restart IDLE. From no.email at nospam.invalid Thu Feb 18 22:58:21 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Feb 2010 19:58:21 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <7xocjlx4f6.fsf@ruckus.brouhaha.com> Steve Howell writes: >> But frankly, although there's no reason that you _have_ to name the >> content at each step, I find it a lot more readable if you do: >> >> def print_numbers(): >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and >> cube!=64 ] >> ? ? for f in filtered: >> ? ? ? ? print f > > The names you give to the intermediate results here are > terse--"tuples" and "filtered"--so your code reads nicely. But that example makes tuples and filtered into completely expanded lists in memory. I don't know Ruby so I've been wondering whether the Ruby code would run as an iterator pipeline that uses constant memory. > In a more real world example, the intermediate results would be > something like this: > > departments > departments_in_new_york > departments_in_new_york_not_on_bonus_cycle > employees_in_departments_in_new_york_not_on_bonus_cycle > names_of_employee_in_departments_in_new_york_not_on_bonus_cycle http://haskell.org/ghc/docs/6.10.4/html/users_guide/syntax-extns.html#generalised-list-comprehensions might be of interest. Maybe Ruby and/or Python could grow something similar. From python at bdurham.com Thu Feb 18 23:19:41 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 23:19:41 -0500 Subject: How secure are temp files created via tempfile.TemporaryFile()? In-Reply-To: <4b7ddcf0$0$8819$c3e8da3@news.astraweb.com> References: <1266519267.4170.1360680003@webmail.messagingengine.com><4B7D95F7.9020906@mrabarnett.plus.com> <4b7ddcf0$0$8819$c3e8da3@news.astraweb.com> Message-ID: <1266553181.26400.1360768933@webmail.messagingengine.com> Steven, Thank you very much for your wonderful reply!! I had read the Fine Manual, but as you pointed out the documentation only mentions visibility of file names. > Exclusive locks are advisory, not mandatory, on some operating systems, so you can't rely on it. That comment and your list of OS specific behaviors were EXACTLY the type of information I was looking for. Thanks again! Malcolm From sjdevnull at yahoo.com Thu Feb 18 23:27:06 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 18 Feb 2010 20:27:06 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: On Feb 18, 10:58?pm, Paul Rubin wrote: > Steve Howell writes: > >> But frankly, although there's no reason that you _have_ to name the > >> content at each step, I find it a lot more readable if you do: > > >> def print_numbers(): > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > >> cube!=64 ] > >> ? ? for f in filtered: > >> ? ? ? ? print f > > > The names you give to the intermediate results here are > > terse--"tuples" and "filtered"--so your code reads nicely. > > But that example makes tuples and filtered into completely expanded > lists in memory. ?I don't know Ruby so I've been wondering whether the > Ruby code would run as an iterator pipeline that uses constant memory. I don't know how Ruby works, either. If it's using constant memory, switching the Python to generator comprehensions (and getting constant memory usage) is simply a matter of turning square brackets into parentheses: def print_numbers(): tuples = ((n*n, n*n*n) for n in (1,2,3,4,5,6)) filtered = ( cube for (square, cube) in tuples if square!=25 and cube!=64 ) for f in filtered: print f Replace (1,2,3,4,5,6) with xrange(100000000) and memory usage still stays constant. Though for this particular example, I prefer a strict looping solution akin to what Jonathan Gardner had upthread: for n in (1,2,3,4,5,6): square = n*n cube = n*n*n if square == 25 or cube == 64: continue print cube > > In a more real world example, the intermediate results would be > > something like this: > > > ? ?departments > > ? ?departments_in_new_york > > ? ?departments_in_new_york_not_on_bonus_cycle > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle I don't think the assertion that the names would be ridiculously long is accurate, either. Something like: departments = blah ny_depts = blah(departments) non_bonus_depts = blah(ny_depts) non_bonus_employees = blah(non_bonus_depts) employee_names = blah(non_bonus_employees) If the code is at all well-structured, it'll be just as obvious from the context that each list/generator/whatever is building from the previous one as it is in the anonymous block case. From cmpython at gmail.com Thu Feb 18 23:32:08 2010 From: cmpython at gmail.com (CM) Date: Thu, 18 Feb 2010 20:32:08 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> On Feb 18, 7:19?pm, Ryan Kelly wrote: > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > I have a Python app which I converted to an EXE (all files separate; > > single EXE didn't work properly) via py2exe - I plan on distributing > > this and would like the ability to remotely upgrade the program (for > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > be the best way to go about doing this? > > I've been working on an auto-update framework for my own frozen apps, > you might find it useful: > > ?http://pypi.python.org/pypi/esky > > Docs are a little scarce at the moment, the next release will hopefully > come with a short tutorial (as well as support for cx_freeze and maybe > py2app, depending on how adventurous I'm feeling). > > ? Cheers, > > ? ? ?Ryan This looks pretty interesting and useful. Just to help me understand it a bit more: what is it that users will download from some web page in order to initially get the py2exe'd app on their system? Is it "really" an "esky", with the app's .exe file inside it (but the esky is named the same as the app)? And then when they want to update, the app's code calls the esky class to do the work of swapping out the appropriate .exe file? Something like this? Sorry if I am confused as to how this works. Would this also work if one used InnoSetup to install the exe on the user's system? Thanks, Che From showell30 at yahoo.com Thu Feb 18 23:46:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 20:46:04 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: On Feb 18, 2:49?pm, Jonathan Gardner wrote: > On Feb 18, 8:15?am, Steve Howell wrote: > > > > > ? ? def print_numbers() > > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > > ? ? ? ? ? ? [n * n, n * n * n] > > ? ? ? ? }.reject { |square, cube| > > ? ? ? ? ? ? square == 25 || cube == 64 > > ? ? ? ? }.map { |square, cube| > > ? ? ? ? ? ? cube > > ? ? ? ? }.each { |n| > > ? ? ? ? ? ? puts n > > ? ? ? ? } > > ? ? end > > If this style of programming were useful, we would all be writing Lisp > today. As it turned out, Lisp is incredibly difficult to read and > understand, even for experienced Lispers. I am pleased that Python is > not following Lisp in that regard. > > for n in range(1,6): > ? ? square = n*n > ? ? cube = n*n*n > ? ? if square == 25 or cube == 64: continue > ? ? print cube There's definitely a cognitive dissonance between imperative programming and functional programming. It's hard for programmers used to programming in an imperative style to appreciate a functional approach, because functional solutions often read "upside down" in the actual source code and common algebraic notation: def compute_squares_and_cubes(lst): return [(n * n, n * n * n) for n in lst] def reject_bad_values(lst): return [(square, cube) for (square, cube) \ in lst if not (square == 25 or cube == 64)] def cubes_only(lst): return [cube for square, cube in lst] def print_results(lst): # 1. compute_squares_and_cubes # 2. reject_bad_values # 3. take cubes_only # 4. print values for item in \ cubes_only( # 3 reject_bad_values( # 2 compute_squares_and_cubes(lst))): # 1 print item # 4 You can, of course, restore the natural order of operations to read top-down with appropriate use of intermediate locals: def print_results(lst): lst2 = compute_squares_and_cubes(lst) lst3 = reject_bad_values(lst2) lst4 = cubes_only(lst3) for item in lst4: print item From showell30 at yahoo.com Thu Feb 18 23:57:47 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 20:57:47 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: <96c65bac-2bc1-4ae0-8349-45ec0c3404d9@l12g2000prg.googlegroups.com> On Feb 18, 7:58?pm, Paul Rubin wrote: > Steve Howell writes: > >> But frankly, although there's no reason that you _have_ to name the > >> content at each step, I find it a lot more readable if you do: > > >> def print_numbers(): > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > >> cube!=64 ] > >> ? ? for f in filtered: > >> ? ? ? ? print f > > > The names you give to the intermediate results here are > > terse--"tuples" and "filtered"--so your code reads nicely. > > But that example makes tuples and filtered into completely expanded > lists in memory. ?I don't know Ruby so I've been wondering whether the > Ruby code would run as an iterator pipeline that uses constant memory. > That's a really good question. I don't know the answer. My hunch is that you could implement generators using Ruby syntax, but it's probably not implemented that way. The fact that Python allows you to turn the intermediate results into generator expressions is a very powerful feature, of course. > > In a more real world example, the intermediate results would be > > something like this: > > > ? ?departments > > ? ?departments_in_new_york > > ? ?departments_in_new_york_not_on_bonus_cycle > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > > http://haskell.org/ghc/docs/6.10.4/html/users_guide/syntax-extns.html... > > might be of interest. ?Maybe Ruby and/or Python could grow something similar. Can you elaborate? From python at bdurham.com Fri Feb 19 00:02:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 19 Feb 2010 00:02:44 -0500 Subject: Using compileall to create -OO type .pyo files Message-ID: <1266555764.31891.1360772585@webmail.messagingengine.com> I've read the documentation on compileall and tried using this module directly. Nowhere can I find how to specify to compileall that it should create .pyo vs. .pyc files. Goal: I would like to use the compileall.compile_dir() method to generate -OO type .pyo files as part of a larger Python build script. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Fri Feb 19 00:05:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 21:05:04 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: On Feb 18, 8:27?pm, "sjdevn... at yahoo.com" wrote: > On Feb 18, 10:58?pm, Paul Rubin wrote: > > Steve Howell writes: > > >> But frankly, although there's no reason that you _have_ to name the > > >> content at each step, I find it a lot more readable if you do: > > > >> def print_numbers(): > > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > > >> cube!=64 ] > > >> ? ? for f in filtered: > > >> ? ? ? ? print f > > > > The names you give to the intermediate results here are > > > terse--"tuples" and "filtered"--so your code reads nicely. > > > But that example makes tuples and filtered into completely expanded > > lists in memory. ?I don't know Ruby so I've been wondering whether the > > Ruby code would run as an iterator pipeline that uses constant memory. > > I don't know how Ruby works, either. ?If it's using constant memory, > switching the Python to generator comprehensions (and getting constant > memory usage) is simply a matter of turning square brackets into > parentheses: > > def print_numbers(): > ? ? tuples = ((n*n, n*n*n) for n in (1,2,3,4,5,6)) > ? ? filtered = ( cube for (square, cube) in tuples if square!=25 and > ? ? ? ? ? ? ? ? ?cube!=64 ) > ? ? for f in filtered: > ? ? ? ? print f > > Replace (1,2,3,4,5,6) with xrange(100000000) and memory usage still > stays constant. > > Though for this particular example, I prefer a strict looping solution > akin to what Jonathan Gardner had upthread: > > for n in (1,2,3,4,5,6): > ? ? square = n*n > ? ? cube = n*n*n > ? ? if square == 25 or cube == 64: continue > ? ? print cube > > > > In a more real world example, the intermediate results would be > > > something like this: > > > > ? ?departments > > > ? ?departments_in_new_york > > > ? ?departments_in_new_york_not_on_bonus_cycle > > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > > I don't think the assertion that the names would be ridiculously long > is accurate, either. > > Something like: > > departments = blah > ny_depts = blah(departments) > non_bonus_depts = blah(ny_depts) > non_bonus_employees = blah(non_bonus_depts) > employee_names = blah(non_bonus_employees) > > If the code is at all well-structured, it'll be just as obvious from > the context that each list/generator/whatever is building from the > previous one as it is in the anonymous block case. I agree that the names don't have to be as ridiculously long as my examples, but using intermediate locals forces you to come up with consistent abbreviations between adjacent lines, which adds to the maintenance burden. When the requirements change so that bonuses apply to NY and PA departments, you would have to change three places in the code instead of one. To the extent that each of your transformations were named functions, you'd need to maintain the names there as well (something more descriptive than "blah"). From greg.ewing at canterbury.ac.nz Fri Feb 19 00:23:30 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 19 Feb 2010 18:23:30 +1300 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7c22c8$0$1651$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7c22c8$0$1651$742ec2ed@news.sonic.net> Message-ID: <7u6kv0F8fiU1@mid.individual.net> John Nagle wrote: > One way to implement locking is something like this: > > Mutable objects have a reference count field, a lock field, > and an "owner" field. Initially, the owner of an object is its thread. > If an object's only reference is a field of a synchronized object, the > owner is the synchronized object. The trouble with that is that there will hardly ever be "only one reference" to any object that you do anything with, even just looking at it, because temporary references come and go as the interpreter goes about its business. A simple demonstration of this: Python 2.5 (r25:51908, Apr 8 2007, 22:22:18) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> foo = (1, 2, 3) >>> import sys >>> sys.getrefcount(foo) 2 Even though you might think that there is only one reference to foo, the very act of passing it as a parameter to getrefcount() causes another reference to come into existence temporarily. -- Greg From no.email at nospam.invalid Fri Feb 19 00:26:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Feb 2010 21:26:52 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> <96c65bac-2bc1-4ae0-8349-45ec0c3404d9@l12g2000prg.googlegroups.com> Message-ID: <7x1vghkd7n.fsf@ruckus.brouhaha.com> Steve Howell writes: >> http://haskell.org/ghc/docs/6.10.4/html/users_guide/syntax-extns.html... >> might be of interest. ?Maybe Ruby and/or Python could grow something similar. > Can you elaborate? List comprehensions are a Python feature you're probably familiar with, and I think Ruby has something like them too. They originally came from Haskell. GHC (the main Haskell implementation) now supports an extended list comprehension syntax with SQL-like features. I haven't used it much yet, but here's an example from a poker ranking program (http://www.rubyquiz.com/quiz24.html) that I did as a Haskell exercise: let (winners:others) = [zip c ls | ls <- lines cs , let {h = mkHand ls; c=classify h} , then group by c , then sortWith by Down c] It's reasonably evocative and doing the same thing with the older syntax would have been a big mess. "Down" basically means sort in reverse order. From showell30 at yahoo.com Fri Feb 19 00:35:48 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 21:35:48 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: <60ce8051-8bda-470b-8943-ce87dad9e8eb@s25g2000prd.googlegroups.com> On Feb 18, 7:58?pm, Paul Rubin wrote: > Steve Howell writes: > >> But frankly, although there's no reason that you _have_ to name the > >> content at each step, I find it a lot more readable if you do: > > >> def print_numbers(): > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > >> cube!=64 ] > >> ? ? for f in filtered: > >> ? ? ? ? print f > > > The names you give to the intermediate results here are > > terse--"tuples" and "filtered"--so your code reads nicely. > > But that example makes tuples and filtered into completely expanded > lists in memory. ?I don't know Ruby so I've been wondering whether the > Ruby code would run as an iterator pipeline that uses constant memory. > Running the following code would probably answer your question. At least in the case of Array.map and Array.reject, under my version of Ruby, each block transforms the entire array before passing control to the next block. def print_numbers() [1, 2, 3, 4, 5, 6].map { |n| puts 'first block', n [n * n, n * n * n] }.reject { |square, cube| puts 'reject', square square == 25 || cube == 64 }.map { |square, cube| cube }.each { |cube| puts cube } end print_numbers() But I'm running only version 1.8.7. Version 1.9 of Ruby apparently introduced something more akin to generators and Unix pipelines: http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-using.html I haven't tried them myself. From kwmsmith at gmail.com Fri Feb 19 00:37:59 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Thu, 18 Feb 2010 23:37:59 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: On Thu, Feb 18, 2010 at 10:46 PM, Steve Howell wrote: > On Feb 18, 2:49?pm, Jonathan Gardner > wrote: >> On Feb 18, 8:15?am, Steve Howell wrote: >> >> >> >> > ? ? def print_numbers() >> > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| >> > ? ? ? ? ? ? [n * n, n * n * n] >> > ? ? ? ? }.reject { |square, cube| >> > ? ? ? ? ? ? square == 25 || cube == 64 >> > ? ? ? ? }.map { |square, cube| >> > ? ? ? ? ? ? cube >> > ? ? ? ? }.each { |n| >> > ? ? ? ? ? ? puts n >> > ? ? ? ? } >> > ? ? end >> >> If this style of programming were useful, we would all be writing Lisp >> today. As it turned out, Lisp is incredibly difficult to read and >> understand, even for experienced Lispers. I am pleased that Python is >> not following Lisp in that regard. >> >> for n in range(1,6): >> ? ? square = n*n >> ? ? cube = n*n*n >> ? ? if square == 25 or cube == 64: continue >> ? ? print cube > > There's definitely a cognitive dissonance between imperative > programming and functional programming. ?It's hard for programmers > used to programming in an imperative style to appreciate a functional > approach, because functional solutions often read "upside down" in the > actual source code and common algebraic notation: > > ? ?def compute_squares_and_cubes(lst): > ? ? ? ?return [(n * n, n * n * n) for n in lst] > > ? ?def reject_bad_values(lst): > ? ? ? ?return [(square, cube) for (square, cube) \ > ? ? ? ? ? ?in lst if not (square == 25 or cube == 64)] > > ? ?def cubes_only(lst): > ? ? ? ?return [cube for square, cube in lst] > > ? ?def print_results(lst): > ? ? ? ?# 1. compute_squares_and_cubes > ? ? ? ?# 2. reject_bad_values > ? ? ? ?# 3. take cubes_only > ? ? ? ?# 4. print values > ? ? ? ?for item in \ > ? ? ? ? ? ?cubes_only( # 3 > ? ? ? ? ? ? ? ?reject_bad_values( # 2 > ? ? ? ? ? ? ? ? ? ?compute_squares_and_cubes(lst))): # 1 > ? ? ? ? ? ?print item # 4 > > You can, of course, restore the natural order of operations to read > top-down with appropriate use of intermediate locals: > > ? ?def print_results(lst): > ? ? ? ?lst2 = compute_squares_and_cubes(lst) > ? ? ? ?lst3 = reject_bad_values(lst2) > ? ? ? ?lst4 = cubes_only(lst3) > ? ? ? ?for item in lst4: > ? ? ? ? ? ?print item > > -- > http://mail.python.org/mailman/listinfo/python-list > # sent the original to the wrong place -- resending to python-list. Somewhat off topic, but only somewhat: you could use coroutines to get a pipeline effect. #--------------8<----------------------------- # Shamelessly lifted from David Beazley's # http://www.dabeaz.com/coroutines/ def coroutine(co): def _inner(*args, **kwargs): gen = co(*args, **kwargs) gen.next() return gen return _inner def squares_and_cubes(lst, target): for n in lst: target.send((n * n, n * n * n)) @coroutine def reject_bad_values(target): while True: square, cube = (yield) if not (square == 25 or cube == 64): target.send((square, cube)) @coroutine def cubes_only(target): while True: square, cube = (yield) target.send(cube) @coroutine def print_results(): while True: print (yield) squares_and_cubes(range(10), reject_bad_values( cubes_only( print_results() ) ) ) #--------------8<----------------------------- From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 00:41:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 05:41:31 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7e248b$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 22:48:21 -0500, Steve Holden wrote: > Next week: Lesson 2 - Ad Hominem Attacks I wouldn't pay any attention to Steve, all Stevens are notorious liars. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 00:46:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 05:46:31 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <4b7e25b7$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 19:57:35 -0800, Steve Howell wrote: > The names you give to the intermediate results here are terse--"tuples" > and "filtered"--so your code reads nicely. > > In a more real world example, the intermediate results would be > something like this: > > departments > departments_in_new_york > departments_in_new_york_not_on_bonus_cycle > employees_in_departments_in_new_york_not_on_bonus_cycle > names_of_employee_in_departments_in_new_york_not_on_bonus_cycle Those last two could be written more concisely as: serfs_in_new_york names_of_serfs_in_new_york_as_if_we_cared But seriously... if you have a variable called "departments_in_new_york", presumably you also have variables called "departments_in_washington", "departments_in_los_angeles", "departments_in_houston", "departments_in_walla_walla", and so forth. If so, this is a good sign that you are doing it wrong and you need to rethink your algorithm. -- Steven From showell30 at yahoo.com Fri Feb 19 00:50:58 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 21:50:58 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> <4b7e248b$0$8819$c3e8da3@news.astraweb.com> Message-ID: <322eb626-ef2a-4fc7-8472-850932868f7f@t34g2000prm.googlegroups.com> On Feb 18, 9:41?pm, Steven D'Aprano wrote: > On Thu, 18 Feb 2010 22:48:21 -0500, Steve Holden wrote: > > Next week: Lesson 2 - Ad Hominem Attacks > > I wouldn't pay any attention to Steve, all Stevens are notorious liars. > > -- > Steven Especially when their last name starts with H. Cheers, Steve From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 00:52:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 05:52:03 GMT Subject: How secure are temp files created via tempfile.TemporaryFile()? References: <1266519267.4170.1360680003@webmail.messagingengine.com> <4B7D95F7.9020906@mrabarnett.plus.com> <1266523768.19867.1360705413@webmail.messagingengine.com> Message-ID: <4b7e2703$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 21:34:58 -0800, Dennis Lee Bieber wrote: > On Thu, 18 Feb 2010 15:09:28 -0500, python at bdurham.com declaimed the > following in gmane.comp.python.general: > >> 2. As soon as my process terminates (voluntarily or involuntarily), the >> temp file gets deleted. >> > Which only means the directory entry for it is lost... depending on > the OS, someone creating a new file in "w+" and performing a long seek > just to write one byte, may now have all those disk sectors your temp > file had been in -- and can read them at leisure. > > Or some file recovery tools might make a file out of the sectors... > > If you are really worried about the contents becoming visible after > "deletion" you should probably run a wipe operation on the file (write > random sequence over data; read/verify said random sequence; write new > random sequence over file; read/verify this sequence; write 1s > complement of sequence; read/verify that final sequence). If that is your concern, then you shouldn't be using tempfile, you should be using permanent files and wiping them yourself. I think the OP is more concerned about the sort of security flaw where you open a temporary file, and some hostile process hijacks it before you're done with it. But once you're done with the file, you probably no longer care about the contents. -- Steven From greg.ewing at canterbury.ac.nz Fri Feb 19 00:52:20 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 19 Feb 2010 18:52:20 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> Message-ID: <7u6ml2Ffd8U1@mid.individual.net> Steve Howell wrote: > Python may not support the broadest notion of anonymous functions, but > it definitely has anonymous blocks. You can write this in Python: > > for i in range(10): > print i > print i * i > print i * i * i There's a clear difference between this and a Ruby block, however. A "block" in Ruby is implemented by passing a callable object to a method. There is no callable object corresponding to the body of a for-loop in Python. The important thing about Ruby blocks is not that they're anonymous, but that they're concrete objects that can be manipulated. The Ruby approach has the advantage of making it possible to implement user-defined control structures without requiring a macro facility. You can't do that in Python. However, there's something that Python's iterator protocol makes possible that you can't do with a block-passing approach. You can have multiple iterators active at once, and pull values from them as an when required in the calling code. Ruby's version of the iterator protocol can't handle that, because once an iterator is started it retains control until it's finished. Also, most people who advocate adding some form of block-passing facility to Python don't seem to have thought through what would happen if the block contains any break, continue, return or yield statements. This issue was looked into in some detail back when there was consideration of implementing the with-statement by passing the body as a function. Getting these statements to behave intuitively inside the body turned out to be a very thorny problem -- thorny enough to cause the block-passing idea to be abandoned in favour of the current implementation. -- Greg From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 01:00:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 06:00:17 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> <7u6ml2Ffd8U1@mid.individual.net> Message-ID: <4b7e28f0$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 18:52:20 +1300, Gregory Ewing wrote: > The Ruby approach has the advantage of making it possible to implement > user-defined control structures without requiring a macro facility. You > can't do that in Python. [...] > Also, most people who advocate adding some form of block-passing > facility to Python don't seem to have thought through what would happen > if the block contains any break, continue, return or yield statements. That is the only time I ever wanted blocks: I had a series of functions containing for loops that looked something vaguely like this: for x in sequence: code_A try: something except some_exception: code_B where code_B was different in each function, so I wanted to pull it out as a code block and do this: def common_loop(x, block): code_A try: something except some_exception: block for x in sequence: common_loop(x, block) The problem was that the blocks contained a continue statement, so I was stymied. -- Steven From showell30 at yahoo.com Fri Feb 19 01:07:23 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 22:07:23 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <4b7e25b7$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 18, 9:46?pm, Steven D'Aprano wrote: > On Thu, 18 Feb 2010 19:57:35 -0800, Steve Howell wrote: > > The names you give to the intermediate results here are terse--"tuples" > > and "filtered"--so your code reads nicely. > > > In a more real world example, the intermediate results would be > > something like this: > > > ? ?departments > > ? ?departments_in_new_york > > ? ?departments_in_new_york_not_on_bonus_cycle > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > > Those last two could be written more concisely as: > > serfs_in_new_york > names_of_serfs_in_new_york_as_if_we_cared > > But seriously... if you have a variable called "departments_in_new_york", > presumably you also have variables called "departments_in_washington", > "departments_in_los_angeles", "departments_in_houston", > "departments_in_walla_walla", and so forth. If so, this is a good sign > that you are doing it wrong and you need to rethink your algorithm. > Sure, but it could also be that you're launching a feature that is only temporarily limited to New York departments, and any investment in coming up with names for the New York filter function or intermediate local variables becomes pointless once you go national: # version 1 emps = [ ['Bob Rich', 'NY', 55], ['Alice Serf', 'NY', 30], ['Joe Peasant', 'MD', 12], ['Mary Pauper', 'CA', 13], ] emps.select { |name, state, salary| salary < 40 }.select { |name, state, salary| # limit bonuses to NY for now...reqs # may change! state == 'NY' }.each { |name, state, salary| new_salary = salary * 1.1 puts "#{name} gets a raise to #{new_salary}!" } # version 2 emps = [ ['Bob Rich', 'NY', 55], ['Alice Serf', 'NY', 30], ['Joe Peasant', 'MD', 12], ['Mary Pauper', 'CA', 13], ] emps.select { |name, state, salary| salary < 40 }.each { |name, state, salary| new_salary = salary * 1.1 puts "#{name} gets a raise to #{new_salary}!" } From robert.kern at gmail.com Fri Feb 19 01:15:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 00:15:20 -0600 Subject: How to make an empty generator? In-Reply-To: References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-18 19:28 PM, Mel wrote: > Steven D'Aprano wrote: > >> On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: >> >>> > If all you want is a generator that doesn't yield anything, then >>> > surely there isn't any one-time processing and you don't need the >>> > comment? >>> >>> Sure there is. Python doesn't know that nothing gets yielded until it >>> hits the return statement before the yield. When it calls .next() on the >>> iterator, the code elided by the comment executes, then the return is >>> hit, a StopIteration exception is raised, and the iteration is complete. >> >> I don't understand why you care about having *any* code before the >> StopIteration. That's like: >> >> def empty(): >> for x in range(1000): >> pass # Spin wheels uselessly >> return >> yield >> >> >> What's the point of the wheel spinning? Did I miss something? > > I wonder whether it's for some kind of framework with a main loop like > > for it in list_of_iterables: > for x in it: > do_this_or_that (x) > > where, every once in a while one wants to throw some arbitrary code into the > process, in the form of an empty iterable with side effects. Yes. That is exactly what the OP said in his original post: """ I have some generators that do stuff, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really "generators" because I want to call them /as/ a generator as part of a generalized system. """ -- 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 Fri Feb 19 01:16:30 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 00:16:30 -0600 Subject: How to make an empty generator? In-Reply-To: <871vgiawub.fsf@benfinney.id.au> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: On 2010-02-18 18:33 PM, Ben Finney wrote: > Robert Kern writes: > >> He doesn't want *any* empty generator. He wants an iterator that >> executes some given side-effect-producing code then immediately raises >> the StopIteration. > > Ah, hm. That's a rather perverse use case, but I'm sure the OP has their > reasons. Which he explained fairly clearly, I thought, in his original post. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 01:21:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 06:21:48 GMT Subject: How to make an empty generator? References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: >>> What's the point of the wheel spinning? Did I miss something? >> >> I wonder whether it's for some kind of framework with a main loop like >> >> for it in list_of_iterables: >> for x in it: >> do_this_or_that (x) >> >> where, every once in a while one wants to throw some arbitrary code >> into the process, in the form of an empty iterable with side effects. > > Yes. That is exactly what the OP said in his original post: > > """ > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only really > "generators" because I want to call them /as/ a generator as part of a > generalized system. """ But he doesn't say anything about side-effects. If you're passing generators around, sometimes you want an empty generator, just as sometimes you want an empty string, or list, or whatever. -- Steven From showell30 at yahoo.com Fri Feb 19 01:44:16 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 22:44:16 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> On Feb 18, 9:37?pm, Kurt Smith wrote: > On Thu, Feb 18, 2010 at 10:46 PM, Steve Howell wrote: > > On Feb 18, 2:49?pm, Jonathan Gardner > > wrote: > >> On Feb 18, 8:15?am, Steve Howell wrote: > > >> > ? ? def print_numbers() > >> > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > >> > ? ? ? ? ? ? [n * n, n * n * n] > >> > ? ? ? ? }.reject { |square, cube| > >> > ? ? ? ? ? ? square == 25 || cube == 64 > >> > ? ? ? ? }.map { |square, cube| > >> > ? ? ? ? ? ? cube > >> > ? ? ? ? }.each { |n| > >> > ? ? ? ? ? ? puts n > >> > ? ? ? ? } > >> > ? ? end > > >> If this style of programming were useful, we would all be writing Lisp > >> today. As it turned out, Lisp is incredibly difficult to read and > >> understand, even for experienced Lispers. I am pleased that Python is > >> not following Lisp in that regard. > > >> for n in range(1,6): > >> ? ? square = n*n > >> ? ? cube = n*n*n > >> ? ? if square == 25 or cube == 64: continue > >> ? ? print cube > > > There's definitely a cognitive dissonance between imperative > > programming and functional programming. ?It's hard for programmers > > used to programming in an imperative style to appreciate a functional > > approach, because functional solutions often read "upside down" in the > > actual source code and common algebraic notation: > > > ? ?def compute_squares_and_cubes(lst): > > ? ? ? ?return [(n * n, n * n * n) for n in lst] > > > ? ?def reject_bad_values(lst): > > ? ? ? ?return [(square, cube) for (square, cube) \ > > ? ? ? ? ? ?in lst if not (square == 25 or cube == 64)] > > > ? ?def cubes_only(lst): > > ? ? ? ?return [cube for square, cube in lst] > > > ? ?def print_results(lst): > > ? ? ? ?# 1. compute_squares_and_cubes > > ? ? ? ?# 2. reject_bad_values > > ? ? ? ?# 3. take cubes_only > > ? ? ? ?# 4. print values > > ? ? ? ?for item in \ > > ? ? ? ? ? ?cubes_only( # 3 > > ? ? ? ? ? ? ? ?reject_bad_values( # 2 > > ? ? ? ? ? ? ? ? ? ?compute_squares_and_cubes(lst))): # 1 > > ? ? ? ? ? ?print item # 4 > > > You can, of course, restore the natural order of operations to read > > top-down with appropriate use of intermediate locals: > > > ? ?def print_results(lst): > > ? ? ? ?lst2 = compute_squares_and_cubes(lst) > > ? ? ? ?lst3 = reject_bad_values(lst2) > > ? ? ? ?lst4 = cubes_only(lst3) > > ? ? ? ?for item in lst4: > > ? ? ? ? ? ?print item > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > # sent the original to the wrong place -- resending to python-list. > > Somewhat off topic, but only somewhat: ?you could use coroutines to > get a pipeline effect. > > #--------------8<----------------------------- > # Shamelessly lifted from David Beazley's > # ?http://www.dabeaz.com/coroutines/ > > def coroutine(co): > ? ?def _inner(*args, **kwargs): > ? ? ? ?gen = co(*args, **kwargs) > ? ? ? ?gen.next() > ? ? ? ?return gen > ? ?return _inner > > def squares_and_cubes(lst, target): > ? ?for n in lst: > ? ? ? ?target.send((n * n, n * n * n)) > > @coroutine > def reject_bad_values(target): > ? ?while True: > ? ? ? ?square, cube = (yield) > ? ? ? ?if not (square == 25 or cube == 64): > ? ? ? ? ? ?target.send((square, cube)) > > @coroutine > def cubes_only(target): > ? ?while True: > ? ? ? ?square, cube = (yield) > ? ? ? ?target.send(cube) > > @coroutine > def print_results(): > ? ?while True: > ? ? ? ?print (yield) > > squares_and_cubes(range(10), > ? ? ? ?reject_bad_values( > ? ? ? ? ? ?cubes_only( > ? ? ? ? ? ? ? ?print_results() > ? ? ? ? ? ? ? ?) > ? ? ? ? ? ?) > ? ? ? ?) Wow! It took me a while to get my head around it, but that's pretty cool. From ben+python at benfinney.id.au Fri Feb 19 02:01:52 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 18:01:52 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: <87ocjlaeu7.fsf@benfinney.id.au> Robert Kern writes: > On 2010-02-18 18:33 PM, Ben Finney wrote: > > Robert Kern writes: > > > >> He doesn't want *any* empty generator. He wants an iterator that > >> executes some given side-effect-producing code then immediately > >> raises the StopIteration. > > > > Ah, hm. That's a rather perverse use case, but I'm sure the OP has their > > reasons. > > Which he explained fairly clearly, I thought, in his original post. (The original post isn't available to me; the reference in your reply isn't accessible AFAICT.) In the part of the original that you quoted, he speaks only of empty generators (easy and clean), not generators that exist only for the purpose of side-effects without yielding any items. It's that latter that I describe as perverse, and I would think it worth some effort to determine if that can be avoided by a different approach. -- \ ?The problem with television is that the people must sit and | `\ keep their eyes glued on a screen: the average American family | _o__) hasn't time for it.? ?_The New York Times_, 1939 | Ben Finney From showell30 at yahoo.com Fri Feb 19 02:13:28 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 23:13:28 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> <7u6ml2Ffd8U1@mid.individual.net> Message-ID: <3a910818-6911-4c9f-bdf0-7fffc31b117f@z1g2000prc.googlegroups.com> On Feb 18, 9:52?pm, Gregory Ewing wrote: > Steve Howell wrote: > > Python may not support the broadest notion of anonymous functions, but > > it definitely has anonymous blocks. ?You can write this in Python: > > > ? ? for i in range(10): > > ? ? ? ? print i > > ? ? ? ? print i * i > > ? ? ? ? print i * i * i > > There's a clear difference between this and a Ruby block, > however. A "block" in Ruby is implemented by passing a > callable object to a method. There is no callable object > corresponding to the body of a for-loop in Python. > > The important thing about Ruby blocks is not that they're > anonymous, but that they're concrete objects that can > be manipulated. > Agreed. > The Ruby approach has the advantage of making it possible > to implement user-defined control structures without > requiring a macro facility. You can't do that in Python. > > However, there's something that Python's iterator protocol > makes possible that you can't do with a block-passing > approach. You can have multiple iterators active at once, > and pull values from them as an when required in the > calling code. Ruby's version of the iterator protocol > can't handle that, because once an iterator is started > it retains control until it's finished. > Is this still true or Ruby today? http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-using.html > Also, most people who advocate adding some form of > block-passing facility to Python don't seem to have > thought through what would happen if the block contains > any break, continue, return or yield statements. > For sure. It's certainly not clear to me how Ruby handles all those cases, although I am still quite new to Ruby, so it's possible that I just haven't stumbled upon the best explanations yet. > This issue was looked into in some detail back when there > was consideration of implementing the with-statement > by passing the body as a function. Getting these > statements to behave intuitively inside the body > turned out to be a very thorny problem -- thorny enough > to cause the block-passing idea to be abandoned in > favour of the current implementation. > I found these links in the archive...were these part of the discussion you were referring to? http://mail.python.org/pipermail/python-dev/2005-April/052907.html http://mail.python.org/pipermail/python-dev/2005-April/053055.html http://mail.python.org/pipermail/python-dev/2005-April/053123.html From ken at picloud.com Fri Feb 19 02:14:19 2010 From: ken at picloud.com (Ken Elkabany) Date: Thu, 18 Feb 2010 23:14:19 -0800 Subject: ANN: PiCloud cloud library 1.8 release Message-ID: PiCloud, a cloud-computing platform for the Python Programming Language, has released version 1.8 of its client library, cloud. PiCloud enables Python users to leverage the power of an on-demand, high performance, and auto scaling compute cluster with as few as three lines of code! No server management necessary. You can find out more here: http://www.picloud.com What's New: * The client library is now open source with an LGPL license. * Users can choose to run their code across 2.5ghz nodes or 1ghz nodes with a simple kwarg. * Users can now select to run their code in real-time, guaranteeing that their processes start in under a second. * Drop-in replacement for multiprocessing. * Improved cluster workload distribution performance by 20%. * Improved efficiency of Python interpreter state extraction by the client library. * Optimized for all Python packages in the Enthought Python Distribution. * Bug fixes. * And much more! 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: * Crawling the web * Manipulating images and videos * Generating charts and graphs * Statistical analysis of data sets * Real-time data processing Cheers, Ken Elkabany PiCloud, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobrowser at gmail.com Fri Feb 19 02:18:20 2010 From: nobrowser at gmail.com (nobrowser) Date: Thu, 18 Feb 2010 23:18:20 -0800 (PST) Subject: with statement and standard library Message-ID: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Hi. The with statement is certainly nifty. The trouble is, the *only* two documented examples how it can be used with the library classes are file objects (which I use all the time) and thread locks which I almost never use. Yet there are many, many classes in the library whose use would be more elegant and readable if the with statement could be employed. Start with the connection objects in httplib and you can probably come up with 10 others easily. Maybe it is the case that some of these classes have with statement support already but I don't know it? If so, how can I know (without asking here each time, LOL)? If not, is there work being done on that? I am interested in this question mostly in the context of Python 2.6. Many thanks. From subhakolkata1234 at gmail.com Fri Feb 19 03:35:39 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 19 Feb 2010 00:35:39 -0800 (PST) Subject: Few questions on SOAP References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: On Feb 19, 8:49?am, Steve Holden wrote: > Brendon Wickham wrote: > > On 19 February 2010 08:07, Mark Lawrence wrote: > >> Muhammad Alkarouri wrote: > >>> Your question is borderline if not out of topic in this group. I will > >>> make a few comments though. > >> This might be a Python group, but threads often drift way off topic, which > >> added to the language itself make this a great group to read. ?If you don't > >> like the way a thread goes, you can always skip it. > > > Perhaps...but he answered the question very well and with great, IMO, patience. > > +1 > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 ?http://us.pycon.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ Dear Group, Thank you for taking your time to discuss the issue, esp. to Mohammad for his great patience and solving each aspect in a great way. That's I frequent this group and I just learn lot. If it is bit diverted topic,sorry. Wishing you Happy Day Ahead, Best Regards, Subhabrata. From arnodel at googlemail.com Fri Feb 19 03:36:28 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 19 Feb 2010 08:36:28 +0000 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > Arnaud Delobelle writes: > >> What about >> foo = iter('') > > That doesn't return a generator. > > >>> foo = iter('') > >>> foo > > > Whether the OP needs to create a generator, or just any iterable type, > isn't clear. If it walks and quacks like a duck... Anyway it's not just an iterable object, it's an iterator. I can't really imagine that there would be some code which would be happy with generators but not with iterators (as long as you can't send anything to them, which is always the case with an empty generator). -- Arnaud From ben+python at benfinney.id.au Fri Feb 19 03:52:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 19:52:47 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: <87k4u9a9pc.fsf@benfinney.id.au> Arnaud Delobelle writes: > Ben Finney writes: > > Whether the OP needs to create a generator, or just any iterable > > type, isn't clear. > > If it walks and quacks like a duck... Anyway it's not just an iterable > object, it's an iterator. I can't really imagine that there would be > some code which would be happy with generators but not with iterators > (as long as you can't send anything to them, which is always the case > with an empty generator). I can't imagine that someone would want to create a generator that's always empty, but has some side-effect that is the *real* purpose for using the generator. Clearly, none of us should let our limited imaginations be the guide to what people actually want to do. -- \ ?Generally speaking, the errors in religion are dangerous; | `\ those in philosophy only ridiculous.? ?David Hume, _A Treatise | _o__) of Human Nature_, 1739 | Ben Finney From sschedule at gmail.com Fri Feb 19 03:54:37 2010 From: sschedule at gmail.com (Schedule) Date: Fri, 19 Feb 2010 09:54:37 +0100 Subject: Submit HTTP GET data from XP PC to PHP on web server. Message-ID: Hello everyone I haeve tried to understand the capabilities of python in web development. Have gone throuhg forums and online tutorials. Nevertheless I am not able to find any topic which can give me some insite along with basic examples of how to send http get data from an xp mashine using python code to php on web server. I have some parameters to collect from windows mashine via http get and collect them on web server using php. Any hint how to begin would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 04:23:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 10:23:53 +0100 Subject: Why this doesn't work? In-Reply-To: References: Message-ID: <4b7e5898$0$12109$426a34cc@news.free.fr> mk a ?crit : > (snip) Sorry, no time to get into details now - but I can at least provide a couple hints. The first point is that, to override a method on an _instance_, you have to provide a method object, not a plain function - remember that the descriptor protocol is only invoked on _class_ attributes, not on instance attributes. class Foo(object): def bar(self): print "the original bar" def mybar(self): print "mybar" >>> f = Foo() >>> f.bar = mybar >>> f.bar() Traceback (most recent call last): File "", line 1, in File "/tmp/python-1287O_i.py", line 32, in f.bar() TypeError: mybar() takes exactly 1 argument (0 given) >>> type(f.bar) >>> f.bar is mybar True >>> f.bar(f) mybar As you see, "bar" is here resolved as an ordinary instance attribute - so here it evals to the "mybar" function object. If you want it to be a method object, you do have to invoke the descriptor protocol manually: >>> f.bar = mybar.__get__(f, type(f)) >>> f.bar > >>> f.bar() mybar Or alternatively, you can use the types module: >>> import types >>> f.bar = types.MethodType(mybar, f, type(f)) >>> f.bar > >>> f.bar() mybar Second point is that the descriptor protocol is invoked on each and every lookup. So when it comes to function class attributes, you get a new method object each time: >>> f = Foo() >>> m1 = f.bar >>> m1 > >>> m2 = f.bar >>> m2 > >>> id(m1) 3084861188L >>> id(m2) 3083656564L >>> m1 is m2 False >>> I think this should help you understand why your code doesn't work as you assumed it would !-) PS : as a side note, a common optimization trick is to "short-circuit" the whole lookup / descriptor mechanism when you have to call the same method of the same object in a loop: l = [] append = l.append for i in xrange(100): append(i) print l HTH From snakylove at googlemail.com Fri Feb 19 04:44:16 2010 From: snakylove at googlemail.com (Snaky Love) Date: Fri, 19 Feb 2010 01:44:16 -0800 (PST) Subject: How to use AWS/PAA nowadays? PyAWS / pyamazon outdated? References: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> Message-ID: <74a987e8-2fe1-4109-995f-a0470a2033d7@b7g2000yqd.googlegroups.com> wow, for some strange reason I did not find this with my first search yesterday: http://pypi.python.org/pypi/python-amazon-product-api/0.2.2 I will try this. sometime I wish all the old stuff would disappear from the internet. if somebody is looking for a cool startup idea: what about some website overlay that says "hey, dude, this stuff is old, go here, here is the new and improved thing!" :) thanks for your attention. From anh.hai.trinh at gmail.com Fri Feb 19 05:01:53 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Fri, 19 Feb 2010 02:01:53 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> Message-ID: <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> On Feb 19, 1:44?pm, Steve Howell wrote: > > > def coroutine(co): > > ? ?def _inner(*args, **kwargs): > > ? ? ? ?gen = co(*args, **kwargs) > > ? ? ? ?gen.next() > > ? ? ? ?return gen > > ? ?return _inner > > > def squares_and_cubes(lst, target): > > ? ?for n in lst: > > ? ? ? ?target.send((n * n, n * n * n)) > > > @coroutine > > def reject_bad_values(target): > > ? ?while True: > > ? ? ? ?square, cube = (yield) > > ? ? ? ?if not (square == 25 or cube == 64): > > ? ? ? ? ? ?target.send((square, cube)) > > > @coroutine > > def cubes_only(target): > > ? ?while True: > > ? ? ? ?square, cube = (yield) > > ? ? ? ?target.send(cube) > > > @coroutine > > def print_results(): > > ? ?while True: > > ? ? ? ?print (yield) > > > squares_and_cubes(range(10), > > ? ? ? ?reject_bad_values( > > ? ? ? ? ? ?cubes_only( > > ? ? ? ? ? ? ? ?print_results() > > ? ? ? ? ? ? ? ?) > > ? ? ? ? ? ?) > > ? ? ? ?) > > Wow! ?It took me a while to get my head around it, but that's pretty > cool. This pipeline idea has actually been implemented further, see . from stream import map, filter, cut range(10) >> map(lambda x: [x**2, x**3]) >> filter(lambda t: t[0]! =25 and t[1]!=64) >> cut[1] >> list [0, 1, 8, 27, 216, 343, 512, 729] -- aht From rdv at roalddevries.nl Fri Feb 19 05:30:40 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 19 Feb 2010 11:30:40 +0100 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> Message-ID: <039FC570-3380-4415-B793-C637805DAEF0@roalddevries.nl> On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov > wrote: >> It seems intuitive to me that the magic methods for overriding the >> +, -, <, ==, >, etc. operators should have no sideffects on their >> operands. Also, that == should be commutative and transitive, that >> > and < should be transitive, and anti-commutative. >> >> Is this intuition written up in a PEP, or assumed to follow from >> the mathematical meanings? > > It may be intuitive to you, but its not true, written down anywhere, > nor assumed by the language, and the mathematical meaning of the > operators doesn't matter to Python. Python purposefully does not > enforce anything for these methods. Still, it's clear that (for example) '==' is not just a normal function call. Look at this example (in ipython): >>> False == False == False True >>> True == False == False False >>> (True == False) == False True Anybody knows how why this is so? From clp2 at rebertia.com Fri Feb 19 05:39:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Feb 2010 02:39:59 -0800 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <039FC570-3380-4415-B793-C637805DAEF0@roalddevries.nl> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> <039FC570-3380-4415-B793-C637805DAEF0@roalddevries.nl> Message-ID: <50697b2c1002190239x13f3f051lb69fe674a457aca8@mail.gmail.com> On Fri, Feb 19, 2010 at 2:30 AM, Roald de Vries wrote: > On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: >> On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov >> wrote: >>> >>> It seems intuitive to me that the magic methods for overriding the +, -, >>> <, ==, >, etc. operators should have no sideffects on their operands. Also, >>> that == should be commutative and transitive, that > and < should be >>> transitive, and anti-commutative. >>> >>> Is this intuition written up in a PEP, or assumed to follow from the >>> mathematical meanings? >> >> It may be intuitive to you, but its not true, written down anywhere, nor >> assumed by the language, and the mathematical meaning of the operators >> doesn't matter to Python. Python purposefully does not enforce anything for >> these methods. > > Still, it's clear that (for example) '==' is not just a normal function > call. Look at this example (in ipython): > >>>> False == False == False > True >>>> True == False == False > False >>>> (True == False) == False > True > > Anybody knows how why this is so? Python is smart enough to recognize chained comparisons and do The Right Thing (tm). `X == Y == Z` is equivalent to `X == Y and Y == Z`. Same goes for the other comparison operators besides == and also possibly for longer chains. Cheers, Chris -- http://blog.rebertia.com From wolftracks at invalid.com Fri Feb 19 06:20:08 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 19 Feb 2010 03:20:08 -0800 Subject: The Disappearing Program? Message-ID: I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but not snowball. If I type in snowball, it executes. What's up with that? From __peter__ at web.de Fri Feb 19 06:30:15 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Feb 2010 12:30:15 +0100 Subject: Constraints on __sub__, __eq__, etc. References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> Message-ID: Roald de Vries wrote: > On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: >> On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov >> wrote: >>> It seems intuitive to me that the magic methods for overriding the >>> +, -, <, ==, >, etc. operators should have no sideffects on their >>> operands. Also, that == should be commutative and transitive, that >>> > and < should be transitive, and anti-commutative. >>> >>> Is this intuition written up in a PEP, or assumed to follow from >>> the mathematical meanings? >> >> It may be intuitive to you, but its not true, written down anywhere, >> nor assumed by the language, and the mathematical meaning of the >> operators doesn't matter to Python. Python purposefully does not >> enforce anything for these methods. > > Still, it's clear that (for example) '==' is not just a normal > function call. Look at this example (in ipython): > > >>> False == False == False > True > >>> True == False == False > False > >>> (True == False) == False > True > > Anybody knows how why this is so? As Chris said expr1 expr2 expr3 ... is resolved as (expr1 expr2) and (expr2 expr3) and (expr3 ... where each exprN is evaluated just once. For this to become the obvious way you have to look at interval checks like a < b < c Peter From sarosh.nust at hotmail.com Fri Feb 19 06:38:22 2010 From: sarosh.nust at hotmail.com (sarosh) Date: Fri, 19 Feb 2010 03:38:22 -0800 (PST) Subject: how to do filetransfer using usrp. Message-ID: <27652452.post@talk.nabble.com> how to do filetransfer using usrp. can i make lan interface between two computers connected to usrp each and then transfer files (images/video) between them? how to transfer files? is there any example of such kind in gnuradio? sarosh -- View this message in context: http://old.nabble.com/how-to-do-filetransfer-using-usrp.-tp27652452p27652452.html Sent from the Python - python-list mailing list archive at Nabble.com. From wuwei23 at gmail.com Fri Feb 19 07:25:14 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 19 Feb 2010 04:25:14 -0800 (PST) Subject: with statement and standard library References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: nobrowser wrote: > Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. ?Start with the connection objects in > httplib and you can probably come up with 10 others easily. ?Maybe it > is the case that some of these classes have with statement support > already but I don't know it? ?If so, how can I know (without asking > here each time, LOL)? ?If not, is there work being done on that? If an object has __enter__ and __exit__ methods, it should work as a context manager. If you do find any such classes, submitting doc bugs or patches would be really handy. However, I'm not sure if there was any attempt to retrofit the stdlib with context manager supports, so if you do come up with more elegant approaches, please contribute them, we'll all thank you :) From andreengels at gmail.com Fri Feb 19 08:04:06 2010 From: andreengels at gmail.com (Andre Engels) Date: Fri, 19 Feb 2010 14:04:06 +0100 Subject: The Disappearing Program? In-Reply-To: References: Message-ID: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wrote: > I've successfully compiled several small python programs on Win XP into > executables using py2exe. A program goes from a name like snowball.py to > snowball. A dir in the command prompt window finds snowball.py but not > snowball. If I type in snowball, it executes. What's up with that? No idea whether it has to do with your problem, but if it's executable in Windows, its name is snowball.exe, not snowball. -- Andr? Engels, andreengels at gmail.com From breamoreboy at yahoo.co.uk Fri Feb 19 09:19:06 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 19 Feb 2010 14:19:06 +0000 Subject: The Disappearing Program? In-Reply-To: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> Message-ID: Andre Engels wrote: > On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wrote: >> I've successfully compiled several small python programs on Win XP into >> executables using py2exe. A program goes from a name like snowball.py to >> snowball. A dir in the command prompt window finds snowball.py but not >> snowball. If I type in snowball, it executes. What's up with that? > > No idea whether it has to do with your problem, but if it's executable > in Windows, its name is snowball.exe, not snowball. > Not necessarily, it's perfectly possible to setup a Python script to run on Windows using file associations in the same way that you can run a command (.bat) file. If the OP types the command "ASSOC .py" without the quotes at the command prompt, the response .py=Python.File tells you that this association has been setup. HTH. Mark Lawrence. From andreengels at gmail.com Fri Feb 19 09:33:59 2010 From: andreengels at gmail.com (Andre Engels) Date: Fri, 19 Feb 2010 15:33:59 +0100 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> Message-ID: <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence wrote: > Andre Engels wrote: >> >> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson >> wrote: >>> >>> I've successfully compiled several small python programs on Win XP into >>> executables using py2exe. A program goes from a name like snowball.py to >>> snowball. A dir in the command prompt window finds snowball.py but not >>> snowball. If I type in snowball, it executes. What's up with that? >> >> No idea whether it has to do with your problem, but if it's executable >> in Windows, its name is snowball.exe, not snowball. >> > > Not necessarily, it's perfectly possible to setup a Python script to run on > Windows using file associations in the same way that you can run a command > (.bat) file. ?If the OP types the command "ASSOC .py" without the quotes at > the command prompt, the response .py=Python.File tells you > that this association has been setup. And how does that invalidate what I wrote? One cannot associate the empty extension, so if "snowball" runs a program, that's the program in the file "snowball.exe" not the program in the file "snowball" that has its extension associated to something - it has no extension, so its extension cannot be associated. -- Andr? Engels, andreengels at gmail.com From mrkafk at gmail.com Fri Feb 19 09:39:04 2010 From: mrkafk at gmail.com (mk) Date: Fri, 19 Feb 2010 15:39:04 +0100 Subject: Why this doesn't work? In-Reply-To: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> References: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: > >> nostat.__orig_get__ = nostat.__get__ > > I should point out that leading-and-trailing-double-underscore names are > reserved for use by the language. Right... I completely missed that. I will try to change the habit. I am under impression that a function with no underscore in name is meant to be called "publicly" on instance, like Foo().nostat, a function with one underscore (and no trailing underscores) is meant to be like "it's mostly intended for internal use, but you can still call it", somewhat like "protected" in C++, and a function with two leading underscores (and no trailing underscores) is meant as completely internal to the class, not meant to be called by outsiders, somewhat like "private" in C++ (I abstract from obvious point in C++ that semantics of those keywords is enforced by a compiler in C++). Is that correct? Regards, mk From justin.mailinglists at gmail.com Fri Feb 19 09:40:19 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Fri, 19 Feb 2010 06:40:19 -0800 (PST) Subject: how to do filetransfer using usrp. References: Message-ID: <83b8c073-7b75-4746-9beb-cea0a5f11eb8@k6g2000prg.googlegroups.com> On Feb 19, 7:38?pm, sarosh wrote: > how to do filetransfer using usrp. > can i make lan interface between two computers connected to usrp each and > then transfer files (images/video) between them? > how to transfer files? > is there any example of such kind in gnuradio? > > sarosh am not sure what USRP is but a quick google found http://packages.debian.org/sid/python-usrp From daniele.gondoni at gmail.com Fri Feb 19 09:41:13 2010 From: daniele.gondoni at gmail.com (Daniele Gondoni) Date: Fri, 19 Feb 2010 06:41:13 -0800 (PST) Subject: What happened to pyjamas? References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> <4b7da919$0$22938$e4fe514c@news.xs4all.nl> Message-ID: <0710f64c-7c38-47fc-85d1-0da13fe62bb8@w31g2000yqk.googlegroups.com> On Feb 18, 9:53?pm, Irmen de Jong wrote: > On 2/18/10 9:45 PM, Luis M. Gonz?lez wrote: > > > On Feb 18, 5:21 pm, Daniele Gondoni ?wrote: > >> On 18 Feb, 19:58, "sstein... at gmail.com" ?wrote: > > >>> Down from here (NH, US). > > >>> S > > >>> On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > >> Unreacheable from Italy as well... > > > Same here (Buenos Aires, Argentina). > > It ain't down till Netcraft confirms it! > > http://uptime.netcraft.com/up/graph?site=www.pyjs.org > > Oh wait... > > -irmen my goodness! it seems only the domain has expired the site's still there, just add 216.34.181.97 pyjs.org to your hosts file and BANG From goon12 at gmail.com Fri Feb 19 09:43:52 2010 From: goon12 at gmail.com (Joe Riopel) Date: Fri, 19 Feb 2010 09:43:52 -0500 Subject: Submit HTTP GET data from XP PC to PHP on web server. In-Reply-To: References: Message-ID: <6a2ccd191002190643n18c990a5qc1333a362dcc4484@mail.gmail.com> On Fri, Feb 19, 2010 at 3:54 AM, Schedule wrote: > Hello everyone > > I haeve tried to understand the capabilities of python in web development. > Have gone throuhg forums and online tutorials. Nevertheless I am not able to > find any topic which can give me some insite along with basic examples of > how to send http get data from an xp mashine using python code to php on web > server. Have a look at urllib2 (urllib2.Request) and maybe mechanize (http://wwwsearch.sourceforge.net/mechanize/). From funthyme at gmail.com Fri Feb 19 09:43:56 2010 From: funthyme at gmail.com (John Pinner) Date: Fri, 19 Feb 2010 06:43:56 -0800 (PST) Subject: What happened to pyjamas? Message-ID: <6a8e506c-63df-482b-a39d-148e6217ba2c@o3g2000yqb.googlegroups.com> It appears that, in trying to cut down spm, somone chahnged a DNS entry and screwed it up : it shouldbe back before long. John -- From mrkafk at gmail.com Fri Feb 19 09:45:12 2010 From: mrkafk at gmail.com (mk) Date: Fri, 19 Feb 2010 15:45:12 +0100 Subject: Why this doesn't work? In-Reply-To: <4B7DD3D6.9030403@optimum.net> References: <4B7DD3D6.9030403@optimum.net> Message-ID: John Posner wrote: >> a >> False >> >> I expected to see 'nostatget' output: nostat.__get__ = nostatget >> obviously failed to replace this function's __get__ method. > > I don't quite understand the above sentence, so I'm assuming that you > wanted the final "is" test to be "True" instead of "False". No. I should have described my goal in plain English in first place. I wanted to replace nostat function's __get__ descriptor with a function that would allow me to peek inside it (i.e. into __get__ descriptor arguments) and that would then call original nostat.__get__. So no, I expected it to be false, that is, I expected to replace original descriptor with a "custom" descriptor. I just wondered why this custom "nostatget" descriptor didn't get called even though the new nostat.__get__ didn't seem to be its old self (so quite likely it was the new, nostatget, descriptor). But Bruno pointed out that I need instancemethod for that, not plain function. Regards, mk From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 10:01:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 16:01:53 +0100 Subject: Why this doesn't work? In-Reply-To: References: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7ea7ce$0$15611$426a74cc@news.free.fr> mk a ?crit : > Steven D'Aprano wrote: >> On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: >> >>> nostat.__orig_get__ = nostat.__get__ >> >> I should point out that leading-and-trailing-double-underscore names >> are reserved for use by the language. > > Right... I completely missed that. I will try to change the habit. > > I am under impression that a function with no underscore in name is > meant to be called "publicly" on instance, like Foo().nostat, a function > with one underscore (and no trailing underscores) is meant to be like > "it's mostly intended for internal use, but you can still call it", > somewhat like "protected" in C++, and a function with two leading > underscores (and no trailing underscores) is meant as completely > internal to the class, not meant to be called by outsiders, somewhat > like "private" in C++ (I abstract from obvious point in C++ that > semantics of those keywords is enforced by a compiler in C++). > > Is that correct? Mostly, yes. - s/function/whatever/ : these rules apply to all names - the single leading underscore denote implementation, IOW : you should not use it, unless you have a pretty good reason to do so AND you take full responsability for what may happens - the double leading underscore is in fact mostly to protect your attribute from accidental overloading. It triggers a (simple) name-mangling operation that turns "__yourname" into "_Yourclassname__yourname". FWIW, this is something I must have a use for at most once a year, and even then most of the times because I'm a bit of a control freak sometimes. From pedro.al at fenhi.uh.cu Fri Feb 19 10:08:06 2010 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Fri, 19 Feb 2010 10:08:06 -0500 Subject: Attributes in privates methods Message-ID: <20100219100806.gm1qqhaisk48ookw@correo.fenhi.uh.cu> Hi all. I have a class with the attribute 'log_file', opened out of the class: class ProteinCluster: def __init__(self,cluster_name,log_file): ... self.log_file = log_file ... Then i have a private method which write in the log_file: def _read_structure(self, pdb_code): ... ... self.log_file.write('blablabla') ... ... When i run the script, it raises the error: AttributeError: ProteinCluster instance has no attribute 'log_file' My question is, the class attributes are valids in private methods, like in publics methods? Thanks -- Yasser Almeida Hern?ndez, BSc Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 214-3178 almeida at cim.sld.cu ---------------------------------------------------------------- Correo FENHI From breamoreboy at yahoo.co.uk Fri Feb 19 10:16:20 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 19 Feb 2010 15:16:20 +0000 Subject: The Disappearing Program? In-Reply-To: <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: Andre Engels wrote: > On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence wrote: >> Andre Engels wrote: >>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson >>> wrote: >>>> I've successfully compiled several small python programs on Win XP into >>>> executables using py2exe. A program goes from a name like snowball.py to >>>> snowball. A dir in the command prompt window finds snowball.py but not >>>> snowball. If I type in snowball, it executes. What's up with that? >>> No idea whether it has to do with your problem, but if it's executable >>> in Windows, its name is snowball.exe, not snowball. >>> >> Not necessarily, it's perfectly possible to setup a Python script to run on >> Windows using file associations in the same way that you can run a command >> (.bat) file. If the OP types the command "ASSOC .py" without the quotes at >> the command prompt, the response .py=Python.File tells you >> that this association has been setup. > > And how does that invalidate what I wrote? One cannot associate the > empty extension, so if "snowball" runs a program, that's the program > in the file "snowball.exe" not the program in the file "snowball" that > has its extension associated to something - it has no extension, so > its extension cannot be associated. > Darn, only half the story, sorry. When the OP types snowball something executes. The command SET PATHEXT will show what file extensions are set to run files. On my system the response is :- c:\Users\Mark\Java2Python>set pathext PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY So snowball with any one of the 12 extensions listed above would run on my system without actually typing the extension. I'm just guessing but has an executable been created but in another directory, so snowball.py is running? Perhaps the best bet is simply to search appropriate directories, or even the whole hard drive, for snowball.*. Then the OP would know exactly what he has or hasn't got. HTH. Mark Lawrence From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 10:17:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 16:17:30 +0100 Subject: Why this doesn't work? In-Reply-To: References: <4B7DD3D6.9030403@optimum.net> Message-ID: <4b7eab77$0$31722$426a34cc@news.free.fr> mk a ?crit : > John Posner wrote: >>> a >>> False >>> >>> I expected to see 'nostatget' output: nostat.__get__ = nostatget >>> obviously failed to replace this function's __get__ method. >> >> I don't quite understand the above sentence, so I'm assuming that you >> wanted the final "is" test to be "True" instead of "False". > > No. I should have described my goal in plain English in first place. > > I wanted to replace nostat function's __get__ descriptor A "descriptor" (shortcut for "object implementing the descriptor protocol) is an object that have a __get__ method - not the __get__ method itself. A function is a descriptor. The __get__ method of the function type is a method, and methods are not descriptors. > with a function > that would allow me to peek inside it (i.e. into __get__ descriptor > arguments) => __get__(self, instance, cls=None) When called as a result of a look up on an instance f of class Foo, nostat.__get__ will get (nostat, f, Foo) as args. > So no, I expected it to be false, that is, I expected to replace > original descriptor with a "custom" descriptor. s/descriptor/__get__/ Anyway: these types (function, method etc) are implemented in (higly optimized) C, and with a lot of restriction for both performance and sanity reasons. It's a case of practicality beats purity. Another - perhaps more rewarding - exercise might be to implement a custom callable type that implements the descriptor protocol the same way the function do. From deets at nospam.web.de Fri Feb 19 10:21:51 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 19 Feb 2010 16:21:51 +0100 Subject: Attributes in privates methods In-Reply-To: References: Message-ID: <4B7EAC8F.3040001@nospam.web.de> Am 19.02.10 16:08, schrieb Yasser Almeida Hern?ndez: > Hi all. > > I have a class with the attribute 'log_file', opened out of the class: > class ProteinCluster: > def __init__(self,cluster_name,log_file): > ... > self.log_file = log_file > ... > Then i have a private method which write in the log_file: > def _read_structure(self, pdb_code): > ... > ... > self.log_file.write('blablabla') > ... > ... > When i run the script, it raises the error: > AttributeError: ProteinCluster instance has no attribute 'log_file' > > My question is, the class attributes are valids in private methods, like > in publics methods? There is no semantical difference there, you must have some other error. Diez From rdv at roalddevries.nl Fri Feb 19 10:50:41 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 19 Feb 2010 16:50:41 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> Message-ID: <950E783F-50F5-42B9-845F-0D85B927B3E8@roalddevries.nl> > This pipeline idea has actually been implemented further, see blog.onideas.ws/stream.py>. > > from stream import map, filter, cut > range(10) >> map(lambda x: [x**2, x**3]) >> filter(lambda t: t[0]! > =25 and t[1]!=64) >> cut[1] >> list > [0, 1, 8, 27, 216, 343, 512, 729] Wow, cool! Just to show that you can easily add the iterator.map(f).blabla-syntax to Python: from __future__ import print_function class rubified(list): map = lambda self, f: rubified(map(f, self)) filter = lambda self, f: rubified(filter(f, self)) reject = lambda self, f: rubified(filter(lambda x: not f(x), self)) # each = lambda self, f: rubified(reduce(lambda x, y: print(y), self, None)) def each(self, f): for x in self: f(x) def __new__(cls, value): return list.__new__(cls, value) def print_numbers(): rubified([1, 2, 3, 4, 5, 6]).map(lambda n: [n * n, n * n * n]).reject(lambda (square, cube): square == 25 or cube == 64).map(lambda (square, cube): cube).each(lambda n: print(n)) From robert.kern at gmail.com Fri Feb 19 10:51:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 09:51:54 -0600 Subject: How to make an empty generator? In-Reply-To: <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-19 00:21 AM, Steven D'Aprano wrote: > On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: > >>>> What's the point of the wheel spinning? Did I miss something? >>> >>> I wonder whether it's for some kind of framework with a main loop like >>> >>> for it in list_of_iterables: >>> for x in it: >>> do_this_or_that (x) >>> >>> where, every once in a while one wants to throw some arbitrary code >>> into the process, in the form of an empty iterable with side effects. >> >> Yes. That is exactly what the OP said in his original post: >> >> """ >> I have some generators that do stuff, then start yielding results. On >> occasion, I don't want them to yield anything ever-- they're only really >> "generators" because I want to call them /as/ a generator as part of a >> generalized system. """ > > But he doesn't say anything about side-effects. "I have some generators *that do stuff*, then start yielding results." [emphasis mine]. Then he gives an example of a generator that does side-effect stuff and returning before yielding anything. -- 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 wimmersimon at googlemail.com Fri Feb 19 10:52:59 2010 From: wimmersimon at googlemail.com (SiWi) Date: Fri, 19 Feb 2010 07:52:59 -0800 (PST) Subject: Executing Python code on another computer Message-ID: Hello community, I googled for an answer of the following problem, but I couldn't find anything. I've got a netbook and my fast workstation compter, which I usually use for developing. But I'd also like to take my netbook around the house and to develop Python programms on it. The problem is that naturally a netbook is not the fastest computer you could find. So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? From robert.kern at gmail.com Fri Feb 19 11:00:45 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 10:00:45 -0600 Subject: How to make an empty generator? In-Reply-To: <87ocjlaeu7.fsf@benfinney.id.au> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> <87ocjlaeu7.fsf@benfinney.id.au> Message-ID: On 2010-02-19 01:01 AM, Ben Finney wrote: > Robert Kern writes: > >> On 2010-02-18 18:33 PM, Ben Finney wrote: >>> Robert Kern writes: >>> >>>> He doesn't want *any* empty generator. He wants an iterator that >>>> executes some given side-effect-producing code then immediately >>>> raises the StopIteration. >>> >>> Ah, hm. That's a rather perverse use case, but I'm sure the OP has their >>> reasons. >> >> Which he explained fairly clearly, I thought, in his original post. > > (The original post isn't available to me; the reference in your reply > isn't accessible AFAICT.) You responded to my post which quoted his in full. > In the part of the original that you quoted, he speaks only of empty > generators (easy and clean), not generators that exist only for the > purpose of side-effects without yielding any items. """ I have some generators *that do stuff*, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really "generators" because I want to call them /as/ a generator as part of a generalized system. ... def gen(): # *do my one-time processing here* return yield """ [emphasis mine] Seriously, it's all there. I'm rather appalled at the lack of reading comprehension demonstrated in this thread. > It's that latter that I describe as perverse, and I would think it worth > some effort to determine if that can be avoided by a different approach. By rearchitecting the system to accept things that aren't iterators, yes. But he may not be in control of that system. And it may not make things cleaner to do so if he wants to use itertools to compose the iterables, whether they are for side effects or not, in various ways. -- 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 btaylordesign at gmail.com Fri Feb 19 11:05:10 2010 From: btaylordesign at gmail.com (Brandon) Date: Fri, 19 Feb 2010 08:05:10 -0800 (PST) Subject: Question about getmtime Message-ID: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? Thank you, Brandon From robert.kern at gmail.com Fri Feb 19 11:06:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 10:06:10 -0600 Subject: with statement and standard library In-Reply-To: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: On 2010-02-19 01:18 AM, nobrowser wrote: > Hi. The with statement is certainly nifty. The trouble is, the > *only* two documented examples how it can be used with the library > classes are file objects (which I use all the time) and thread locks > which I almost never use. Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. Start with the connection objects in > httplib and you can probably come up with 10 others easily. Yup. I believe that the devs wanted to adopt the new feature carefully and deliberately, though. They introduced it for file objects and locks first because those were the use cases that had been thoroughly explored in the development of the PEP. They held back from making every reasonable object a context manager in order to see how the new feature worked in the real world with those two use cases first. Now is probably a good time to start adding more sensible context managers to objects. I don't think there is any particular organized effort to do so, though. -- 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 darcy at druid.net Fri Feb 19 11:10:21 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Feb 2010 11:10:21 -0500 Subject: Executing Python code on another computer In-Reply-To: References: Message-ID: <20100219111021.42fddabb.darcy@druid.net> On Fri, 19 Feb 2010 07:52:59 -0800 (PST) SiWi wrote: > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? Yes but it isn't really a Python question. I suggest Google but you haven't given us enough information, particularly what OSs you are running. If it was me I would simply use the netbook as a thin client for programs that I am writing and running on the main server. In my case a simple xterm would do the job since vi is my IDE and bash is my runtime environment. If you are using a GUI IDE you may be able to run the GUI app on the server with the display on the netbook. -- 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 krister.svanlund at gmail.com Fri Feb 19 11:14:43 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 19 Feb 2010 17:14:43 +0100 Subject: Executing Python code on another computer In-Reply-To: References: Message-ID: <2cf430a61002190814x65804212ic0bd111972ac1aa0@mail.gmail.com> On Fri, Feb 19, 2010 at 4:52 PM, SiWi wrote: > Hello community, > I googled for an answer of the following problem, but I couldn't find > anything. > I've got a netbook and my fast workstation compter, which I usually > use for developing. > But I'd also like to take my netbook around the house and to develop > Python programms on it. > The problem is that naturally a netbook is not the fastest computer > you could find. > > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? > -- > http://mail.python.org/mailman/listinfo/python-list > I recommend setting up a SSH server on your stationary and run something like emacs. It's how I'm doing it anyway. From bornstub at gmail.com Fri Feb 19 11:16:09 2010 From: bornstub at gmail.com (Victor Lin) Date: Fri, 19 Feb 2010 08:16:09 -0800 (PST) Subject: A tool for find dependencies relationships behind Python projects Message-ID: Hi, I just wrote a tool for drawing dependencies relationships diagram of Python project on Pypi. Here is the home page of the tool: http://code.google.com/p/python-gluttony/ Some examples: Sprox: http://static.ez2learn.com/gluttony/sprox_dot.png TurboGears2: http://static.ez2learn.com/gluttony/tg2_dot.png Hope this could be helpful :P Regards. Victor Lin. From george.trojan at noaa.gov Fri Feb 19 11:25:34 2010 From: george.trojan at noaa.gov (George Trojan) Date: Fri, 19 Feb 2010 16:25:34 +0000 Subject: a question on building MySQL-python Message-ID: During installation of MySQL-python-1.2.3c1 I encountered the following error: $ python2.6 setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdb running build_ext building '_mysql' extension creating build/temp.linux-x86_64-2.6 gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/include/mysql -I/usr/local/Python-2.6.3/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv gcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -L. -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-x86_64-2.6/_mysql.so /usr/bin/ld: cannot find -lpython2.6 collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 Linker could not find libpython2.6.so. Note that the compiler *did* find Python include file: -I/usr/local/Python-2.6.3/include/python2.6. I am running CentOS5.3. Python 2.6 was configured as follows: $ TARGET=/usr/local/Python-2.6.3 $ export LDFLAGS=-Wl,-rpath,$TARGET/lib $ ./configure --prefix=$TARGET \ --with-cxx=g++ --with-threads --enable-shared to avoid messing with LD_LIBRARY_PATH. I managed to complete the installation by pasting the above link command and adding proper -L option, but I would like to know what would be the proper fix. George From krister.svanlund at gmail.com Fri Feb 19 11:26:20 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 19 Feb 2010 17:26:20 +0100 Subject: Question about getmtime In-Reply-To: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <2cf430a61002190826x380e2d29k585b127432001c34@mail.gmail.com> On Fri, Feb 19, 2010 at 5:05 PM, Brandon wrote: > Hi everyone, > > Does copying or moving a file affect the return value of > os.path.getmtime(path)? > > Thank you, > Brandon Wouldn't it be easier to make a script and see for yourself then to write a mail about it? From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 11:26:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 17:26:53 +0100 Subject: Attributes in privates methods In-Reply-To: References: Message-ID: <4b7ebbba$0$10159$426a34cc@news.free.fr> Yasser Almeida Hern?ndez a ?crit : > Hi all. > > I have a class with the attribute 'log_file', opened out of the class: > class ProteinCluster: > def __init__(self,cluster_name,log_file): > ... > self.log_file = log_file > ... > Then i have a private method which write in the log_file: > def _read_structure(self, pdb_code): > ... > ... > self.log_file.write('blablabla') > ... > ... > When i run the script, it raises the error: > AttributeError: ProteinCluster instance has no attribute 'log_file' > > My question is, the class attributes are valids in private methods, like > in publics methods? Diez already answered - the above code seems correct, so the source of your problem is elsewhere. For the record, in your code, log_file is an instance attribute - a 'class attribute' is an attribute that is defined on the class object itself, and is shared by all instances of the class. Also, Python has no notion of "public" or "private" - at least at the language level. The '_name' convention is just, well, a naming convention. This wont solve your problem - sorry, not much we can do here - but at least it will help wrt/ mutual understanding !-) From arnodel at googlemail.com Fri Feb 19 11:28:15 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 19 Feb 2010 08:28:15 -0800 (PST) Subject: Executing Python code on another computer References: Message-ID: <2cfe4b91-ca53-427e-8c74-8eb7e859f01b@i39g2000yqm.googlegroups.com> On 19 Feb, 15:52, SiWi wrote: > Hello community, > I googled for an answer of the following problem, but I couldn't find > anything. > I've got a netbook and my fast workstation compter, which I usually > use for developing. > But I'd also like to take my netbook around the house and to develop > Python programms on it. > The problem is that naturally a netbook is not the fastest computer > you could find. > > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? There are plenty of ways to do this - but they are not really related to Python. What is most convenient for you will probably depend on the tools that you are used to using, your operating system and your level of expertise with configuring network services. On mac and linux it is very easy to set up an ssh server on your workstation. You can then edit your files remotely - the method might be different depending on your operating system, unless you use something like Emacs - and also execute them remotely. -- Arnaud From james.harris.1 at googlemail.com Fri Feb 19 11:29:06 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Fri, 19 Feb 2010 08:29:06 -0800 (PST) Subject: Executing Python code on another computer References: Message-ID: On 19 Feb, 15:52, SiWi wrote: > Hello community, > I googled for an answer of the following problem, but I couldn't find > anything. > I've got a netbook and my fast workstation compter, which I usually > use for developing. > But I'd also like to take my netbook around the house and to develop > Python programms on it. > The problem is that naturally a netbook is not the fastest computer > you could find. > > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? Yes. Assuming you can cope with the relatively small netbook screen here are some options: 1. Telnet (ok within a home and where no graphics needed) 2. Ssh (ok where no graphics needed) 3. An X-Windows server on your netbook (ok under Linux but good Windows X Servers may be limited or nonexistent) 4. VNC (e.g. RealVnc) to get a remote view of the workstation's screen. I use telnet and RealVnc for purposes similar to those you describe. James From btaylordesign at gmail.com Fri Feb 19 11:30:48 2010 From: btaylordesign at gmail.com (Brandon) Date: Fri, 19 Feb 2010 08:30:48 -0800 (PST) Subject: Question about getmtime References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <00c30abd-e240-4ffc-9df7-30fbf573b3ad@y33g2000yqb.googlegroups.com> On Feb 19, 10:26?am, Krister Svanlund wrote: > On Fri, Feb 19, 2010 at 5:05 PM, Brandon wrote: > > Hi everyone, > > > Does copying or moving a file affect the return value of > > os.path.getmtime(path)? > > > Thank you, > > Brandon > > Wouldn't it be easier to make a script and see for yourself then to > write a mail about it? Gee, thanks for the help. I guess. From wimmersimon at googlemail.com Fri Feb 19 11:32:48 2010 From: wimmersimon at googlemail.com (SiWi) Date: Fri, 19 Feb 2010 08:32:48 -0800 (PST) Subject: Executing Python code on another computer References: Message-ID: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> On Feb 19, 5:10?pm, "D'Arcy J.M. Cain" wrote: > On Fri, 19 Feb 2010 07:52:59 -0800 (PST) > > SiWi wrote: > > So I wondered if it was possible to send the Python code I'm > > developing on the netbook to the workstation pc via wlan, let the > > script execute on the workstation pc and write the output back on the > > netbook. > > > Is there any possibilty to achieve that goal? > > Yes but it isn't really a Python question. ?I suggest Google but you > haven't given us enough information, particularly what OSs you are > running. ?If it was me I would simply use the netbook as a thin client > for programs that I am writing and running on the main server. ?In my > case a simple xterm would do the job since vi is my IDE and bash is my > runtime environment. ?If you are using a GUI IDE you may be able to run > the GUI app on the server with the display on the netbook. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. I'm normally using IDLE and sometimes PyScripter on Windows Vista. The netbook is Windows XP. Should I switch to Vim or Emacs? From showell30 at yahoo.com Fri Feb 19 11:32:53 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 19 Feb 2010 08:32:53 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> Message-ID: On Feb 19, 7:50?am, Roald de Vries wrote: > > This pipeline idea has actually been implemented further, see > blog.onideas.ws/stream.py>. > > > from stream import map, filter, cut > > range(10) >> map(lambda x: [x**2, x**3]) >> filter(lambda t: t[0]! > > =25 and t[1]!=64) >> cut[1] >> list > > [0, 1, 8, 27, 216, 343, 512, 729] > > Wow, cool! > > Just to show that you can easily add the iterator.map(f).blabla-syntax ? > to Python: > > ? ? ?from __future__ import print_function > > ? ? ?class rubified(list): > ? ? ? ? ?map ? ?= lambda self, f: rubified(map(f, self)) > ? ? ? ? ?filter = lambda self, f: rubified(filter(f, self)) > ? ? ? ? ?reject = lambda self, f: rubified(filter(lambda x: not f(x), ? > self)) > ? ? ? ? ?# each = lambda self, f: rubified(reduce(lambda x, y: ? > print(y), self, None)) > ? ? ? ? ?def each(self, f): > ? ? ? ? ? ? ?for x in self: f(x) > > ? ? ? ? ?def __new__(cls, value): > ? ? ? ? ? ? ?return list.__new__(cls, value) > > ? ? ?def print_numbers(): > ? ? ? ? ?rubified([1, 2, 3, 4, 5, 6]).map(lambda n: > ? ? ? ? ? ? ?[n * n, n * n * n]).reject(lambda (square, cube): > ? ? ? ? ? ? ?square == 25 or cube == 64).map(lambda (square, cube): > ? ? ? ? ? ? ?cube).each(lambda n: > ? ? ? ? ? ? ?print(n)) Sure, that definitely achieves the overall sequential structure of operations that I like in Ruby. A couple other example have been posted as well now, which also mimic something akin to a Unix pipeline. A lot of Ruby that I see gets spelled like this: list.select { |arg1, arg2| expr }.reject { |arg| expr }.collect { |arg} expr } With your class you can translate into Python as follows: list.select(lambda arg1, arg2: expr ).reject(lambda arg: expr ).collect(lambda arg: expr ) So for chaining transformations based on filters, the difference really just comes down to syntax (and how much sugar is built into the core library). The extra expressiveness of Ruby comes from the fact that you can add statements within the block, which I find useful sometimes just for debugging purposes: debug = true data = strange_dataset_from_third_party_code() data.each { |arg| if debug and arg > 10000 puts arg end # square the values arg * arg } From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 12:21:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 17:21:03 GMT Subject: How to make an empty generator? References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: > On 2010-02-19 00:21 AM, Steven D'Aprano wrote: >> On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: >> >>>>> What's the point of the wheel spinning? Did I miss something? >>>> >>>> I wonder whether it's for some kind of framework with a main loop >>>> like >>>> >>>> for it in list_of_iterables: >>>> for x in it: >>>> do_this_or_that (x) >>>> >>>> where, every once in a while one wants to throw some arbitrary code >>>> into the process, in the form of an empty iterable with side effects. >>> >>> Yes. That is exactly what the OP said in his original post: >>> >>> """ >>> I have some generators that do stuff, then start yielding results. On >>> occasion, I don't want them to yield anything ever-- they're only >>> really "generators" because I want to call them /as/ a generator as >>> part of a generalized system. """ >> >> But he doesn't say anything about side-effects. > > "I have some generators *that do stuff*, then start yielding results." > [emphasis mine]. What does "do stuff" have to do with side-effects? Here's a generator that does stuff, and it has no side-effects. def generator_that_does_stuff(x): y = 3*x**2 - 5*x + 1 yield y "Do stuff" is ambiguous -- it could mean stuff with side-effects, or stuff without. The first is potentially harmful, the second is pointless. > Then he gives an example of a generator that does > side-effect stuff and returning before yielding anything. Unfortunately the OP's original post isn't visible to me, so I can only respond to your post, which may or may not quote the entire original post. The only example I have seen was an empty generator with a comment saying "do my one-time processing here", with *no* indication of what that one- time processing is supposed to be, why it is necessary, and whether it has side-effects or not. Since the OP (apparently) hasn't seen fit to comment, we're still all guessing what he means. It's certainly possible, likely even, that he's using generators that operate by side-effect: that explanation is consistent with his request. Personally, I can't imagine that would be good coding practice, but I could be wrong. -- Steven From wolftracks at invalid.com Fri Feb 19 12:21:24 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 19 Feb 2010 09:21:24 -0800 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On 2/19/2010 7:16 AM, Mark Lawrence wrote: > Andre Engels wrote: >> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence >> wrote: >>> Andre Engels wrote: >>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson ... tories, or even the whole hard drive, for snowball.*. Then the OP > would know exactly what he has or hasn't got. > > HTH. > > Mark Lawrence > Here's the answer. Consider this folder. Afolder abc.py hello.py I now apply py2exe steps to produce an "executable" for abc. The folder now changes to Afolder build dist abc.py hello.py build are two new folders. dist contains abc.exe. Somehow when I type abc at the command prompt, this follows a path to dist, and finds abc.exe, where it executes properly. Cute, eh? I have no explanation for it. I have no idea what build is for, but dist contains a bunch of other files that possible apply to doing this with other files in the Afolder. hello.py maybe. The details seem to be shrouded. Possible a Google might provide a full explanation. From darcy at druid.net Fri Feb 19 12:22:43 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Feb 2010 12:22:43 -0500 Subject: Executing Python code on another computer In-Reply-To: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> Message-ID: <20100219122243.13051024.darcy@druid.net> On Fri, 19 Feb 2010 08:32:48 -0800 (PST) SiWi wrote: > I'm normally using IDLE and sometimes PyScripter on Windows Vista. The > netbook is Windows XP. Should I switch to Vim or Emacs? Umm... Yes? It's still not a Python question and is in fact a religious one. Other people have different religions. You should probably ask this question on a list dedicated to using Windows. What you want to know is how to run programs remotely. The fact that it is a Python program is irrelevant. I'm not trying to brush you off. I'm just trying to point you somewhere that can answer your question better. -- 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 Fri Feb 19 12:30:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 17:30:42 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> Message-ID: <4b7ecac2$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 08:32:53 -0800, Steve Howell wrote: > The extra expressiveness of Ruby comes from the fact that you can add > statements within the block, which I find useful sometimes just for > debugging purposes: > > debug = true > data = strange_dataset_from_third_party_code() > data.each { |arg| > if debug and arg > 10000 > puts arg > end > # square the values > arg * arg > } How is that different from this? debug = true data = strange_dataset_from_third_party_code() for i, arg in enumerate(data): if debug and arg > 10000 print arg # square the values data[i] = arg * arg I don't see the extra expressiveness. What I see is that the Ruby snippet takes more lines (even excluding the final brace), and makes things implicit which in my opinion should be explicit. But since I'm no Ruby expert, perhaps I'm misreading it. -- Steven From tjreedy at udel.edu Fri Feb 19 12:41:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Feb 2010 12:41:10 -0500 Subject: with statement and standard library In-Reply-To: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: On 2/19/2010 2:18 AM, nobrowser wrote: > Hi. The with statement is certainly nifty. The trouble is, the > *only* two documented examples how it can be used with the library > classes are file objects (which I use all the time) and thread locks > which I almost never use. Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. Start with the connection objects in > httplib and you can probably come up with 10 others easily. Maybe it > is the case that some of these classes have with statement support > already but I don't know it? If so, how can I know (without asking > here each time, LOL)? If not, is there work being done on that? > I am interested in this question mostly in the context of Python 2.6. 2.6 is in maintenance mode only; no new features. 2.7 will be so when released in June and effectively so in a month when the first beta is released. 3.2 is a reasonable target. tjr From apt.shansen at gmail.com Fri Feb 19 12:44:16 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 19 Feb 2010 09:44:16 -0800 Subject: How to make an empty generator? In-Reply-To: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> On Fri, Feb 19, 2010 at 9:21 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: > >> But he doesn't say anything about side-effects. > > > > "I have some generators *that do stuff*, then start yielding results." > > [emphasis mine]. > > What does "do stuff" have to do with side-effects? Here's a generator > that does stuff, and it has no side-effects. > > def generator_that_does_stuff(x): > y = 3*x**2 - 5*x + 1 > yield y > > "Do stuff" is ambiguous -- it could mean stuff with side-effects, or > stuff without. The first is potentially harmful, the second is pointless. What does it matter what *do stuff* means? My point is, there's *stuff* I need to do there, and what that stuff is really has absolutely nothing to do with the issue at hand. Its certainly a side-effect, at least in terms of the generator, otherwise there would be no point really in having the generator there at all. I have a system that consumes generators which, almost always, yield over objects to be handled. One in ten-- nay, one in 20, if not worse-- cases has me wanting to inject into this system some arbitrary code that gets run. Some bit of processing I need to get done in the context of that cycle. There's nothing harmful about it. These aren't generic generators that are going to be passed around and consumed by random things or anything else. They exist solely to be consumed by the core system. They're never composed or loaded by anything else, its just the API of how the system works. It loads bunches of modules dynamically, each module has a generator for yielding objects to be consumed. That generator is the one and only line of connection between the core system and the modules. > > Then he gives an example of a generator that does > > side-effect stuff and returning before yielding anything. > > Unfortunately the OP's original post isn't visible to me, so I can only > respond to your post, which may or may not quote the entire original post. > > The only example I have seen was an empty generator with a comment saying > "do my one-time processing here", with *no* indication of what that one- > time processing is supposed to be, why it is necessary, and whether it > has side-effects or not. > It doesn't matter what the one-time processing is supposed to be. I could say, "This particular module doesn't yield objects like all the rest, but instead just needs to override a certain utility function the system uses, to change how name equality is handled so that tests compare on normalized forms. The API for integrating into the the core system -- to be loaded as a module and integrated into the system -- is to have a generator of a certain name, which yields N objects. In this case, N = 0.". Now, having said that, why in the world does that matter at all to my question? :) It changes no part of anyone's possible solution, be it Robert's once-wrapped-to-decorator, to Holden's just-comment-the-oddity, to your empty-for-loop-yield, to any others. It doesn't *matter* what the processing has to be. And if it has side-effects or not is only relevant to the question of the perversity of my use-case, a discussion I just don't really even have any interest in =) Thanks, all, though, for your responses and solutions. Much to my embarrassment, sometime last night I realized I was being a complete idiot, and the 'correct' way to handle this in my scenario is really just: def initialize(): # do one time processing here return [] A generator is just a callable that returns an iterator, after all. If I don't want to yield anything, returning an empty iterable accomplishes the same goal to get the code loaded and run by the host-cycle while contributing nothing at all to the object pool. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 12:50:19 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 17:50:19 +0000 Subject: best way to create a dict from string In-Reply-To: References: Message-ID: <4B7ECF5B.9090900@mrabarnett.plus.com> Tim Arnold wrote: > Hi, > I've got some text to parse that looks like this > > text = ''' blah blah blah > \Template[Name=RAD,LMRB=False,LMRG=True]{tables} > ho dee ho > ''' If you're going to include backslashes in the string literal then use a raw string for safety. > I want to extract the bit between the brackets and create a dictionary. > Here's what I'm doing now: > > def options(text): > d = dict() > options = text[text.find('[')+1:text.find(']')] > for k,v in [val.split('=') for val in options.split(',')]: > d[k] = v > return d > 1. I'd check whether there's actually a template. 2. 'dict' will accept a list of key/value pairs. def options(text): start = text.find('[') end = text.find(']', start) if start == -1 or end == -1: return {} options = text[start + 1 : end] return dict(val.split('=') for val in options.split(',')) > if __name__ == '__main__': > for line in text.split('\n'): > if line.startswith('\\Template'): > print options(line) > > > is that the best way or maybe there's something simpler? The options will > always be key=value format, comma separated. > thanks, > From showell30 at yahoo.com Fri Feb 19 12:56:15 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 19 Feb 2010 09:56:15 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> <4b7ecac2$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 19, 9:30?am, Steven D'Aprano wrote: > On Fri, 19 Feb 2010 08:32:53 -0800, Steve Howell wrote: > > The extra expressiveness of Ruby comes from the fact that you can add > > statements within the block, which I find useful sometimes just for > > debugging purposes: > > > ? ? debug = true > > ? ? data = strange_dataset_from_third_party_code() > > ? ? data.each { |arg| > > ? ? ? ? if debug and arg > 10000 > > ? ? ? ? ? ? puts arg > > ? ? ? ? end > > ? ? ? ? # square the values > > ? ? ? ? arg * arg > > ? ? } > > How is that different from this? > > debug = true > data = strange_dataset_from_third_party_code() > for i, arg in enumerate(data): > ? ? if debug and arg > 10000 > ? ? ? ? print arg > ? ? # square the values > ? ? data[i] = arg * arg > > I don't see the extra expressiveness. What I see is that the Ruby snippet > takes more lines (even excluding the final brace), and makes things > implicit which in my opinion should be explicit. But since I'm no Ruby > expert, perhaps I'm misreading it. > You are reading the example out of context. Can you re-read the part you snipped? The small piece of code can obviously be written imperatively, but the point of the example was not to print a bunch of squares. From python at mrabarnett.plus.com Fri Feb 19 13:06:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 18:06:40 +0000 Subject: Question about getmtime In-Reply-To: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <4B7ED330.4050308@mrabarnett.plus.com> Brandon wrote: > Hi everyone, > > Does copying or moving a file affect the return value of > os.path.getmtime(path)? > The modification time of a copied file should be the same as the original. The creation time of a copied file will be the time at which it was copied, so that can result in the paradoxical state of a file having been modified _before_ it was created! :-) From vincent at vincentdavis.net Fri Feb 19 13:22:09 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 19 Feb 2010 11:22:09 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() Message-ID: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> I have some some (~50) text files that have about 250,000 rows each. I am reading them in using the following which gets me what I want. But it is not fast. Is there something I am missing that should help. This is mostly an question to help me learn more about python. It takes about 4 min right now. def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') read = list(reader) data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in read]) data = [x for x in data_rows][1:] mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) mask = [row for row in mask_rows if row][3:] outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) outlier = [row for row in outlier_rows if row][3:] *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn -------------- next part -------------- An HTML attachment was scrubbed... URL: From chrisprinos at gmail.com Fri Feb 19 13:23:43 2010 From: chrisprinos at gmail.com (Chris Prinos) Date: Fri, 19 Feb 2010 10:23:43 -0800 (PST) Subject: Replacement for e.message() in python 2.6 References: <0PKdnTVryZFJIObWnZ2dnUVZ_jidnZ2d@westnet.com.au> Message-ID: <4017a5bb-ea1f-4aa8-b80f-95b6a938aaed@k19g2000yqc.googlegroups.com> On Feb 17, 4:58?am, Nandakumar Chandrasekhar wrote: > Dear Folks, > > In previous versions of Python I used to use e.message() to print out > the error message of an exception like so: > > try: > ? ? ? ? result = x / y > except ZeroDivisionError, e: > ? ? ? ? print e.message() > > Unfortunately in Python 2.6 the message method is deprecated. > > Is there any replacement for the message method in Python 2.6 or is > there any best practice that should be used in Python from now on? > > Thank you. > > Yours sincerely, > Nanda try: ? ? ? ? result = x / y except ZeroDivisionError as e: ? ? ? ? print e Note different syntax using "except ... as ..." e.message is deprecated here, but e.args[0] contains the same thing. see http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3110 and http://www.python.org/dev/peps/pep-3110/ chris From steve.l.cohen at gmail.com Fri Feb 19 13:35:56 2010 From: steve.l.cohen at gmail.com (Steven Cohen) Date: Fri, 19 Feb 2010 12:35:56 -0600 Subject: Trouble running pywin32-214.win-amd64-py3.1 on 64-bit Windows 7 Message-ID: <5cf1aff91002191035o7c65df3bjfb4f26805923ea0d@mail.gmail.com> Hello, I downloaded pywin32-214.win-amd64-py3.1, and it installs just fine (except that it prints a traceback when it tells me the postinstall script completed), but then when I try to execute Pythonwin.exe, I get the following error popup: The application can not locate win32ui.pyd (or Python) (126) The specified module could not be found However, the file win32ui.pyd is right there in the same directory from which I am executing Pythonwin.exe. Can anyone help me figure out what I am doing wrong here? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 19 13:52:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Feb 2010 19:52:16 +0100 Subject: Executing Python code on another computer In-Reply-To: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> Message-ID: <4B7EDDE0.6000000@sequans.com> SiWi wrote: > On Feb 19, 5:10 pm, "D'Arcy J.M. Cain" wrote: > >> On Fri, 19 Feb 2010 07:52:59 -0800 (PST) >> >> SiWi wrote: >> >>> So I wondered if it was possible to send the Python code I'm >>> developing on the netbook to the workstation pc via wlan, let the >>> script execute on the workstation pc and write the output back on the >>> netbook. >>> >>> Is there any possibilty to achieve that goal? >>> >> Yes but it isn't really a Python question. I suggest Google but you >> haven't given us enough information, particularly what OSs you are >> running. If it was me I would simply use the netbook as a thin client >> for programs that I am writing and running on the main server. In my >> case a simple xterm would do the job since vi is my IDE and bash is my >> runtime environment. If you are using a GUI IDE you may be able to run >> the GUI app on the server with the display on the netbook. >> >> -- >> D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on >> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. >> > > I'm normally using IDLE and sometimes PyScripter on Windows Vista. The > netbook is Windows XP. Should I switch to Vim or Emacs? > Vista supports rdesktop , you could use it. I don't know if XP is shipped with a rdesktop client though (goggle for remote desktop). JM From cmpython at gmail.com Fri Feb 19 13:56:37 2010 From: cmpython at gmail.com (CM) Date: Fri, 19 Feb 2010 10:56:37 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On Feb 19, 12:21?pm, "W. eWatson" wrote: > On 2/19/2010 7:16 AM, Mark Lawrence wrote:> Andre Engels wrote: > >> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence > >> wrote: > >>> Andre Engels wrote: > >>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson > > ... > tories, or even the whole hard drive, for snowball.*. Then the OP> would know exactly what he has or hasn't got. > > > HTH. > > > Mark Lawrence > > Here's the answer. Consider this folder. > > Afolder > ? ?abc.py > ? ?hello.py > > I now apply py2exe steps to produce an ?"executable" for abc. The folder > now changes to > > Afolder > ? ?build > ? ?dist > ? ?abc.py > ? ?hello.py > > build are two new folders. dist contains abc.exe. > > Somehow when I type abc at the command prompt, this follows a path to > dist, and finds abc.exe, where it executes properly. > Cute, eh? I have no explanation for it. Are you sure it's executing abc.exe? If you are at a Python command prompt within the "DOS shell" and you just type just abc, I think what is happening is you are running abc.py, NOT abc.exe. py2exe creates a dist folder (short for "distributables") by default and puts your .exe into it along with whatever other files are needed to run your application. Depending on how you set the bundling options, this may be a lot of things or just 1-2 other things. Che From davea at ieee.org Fri Feb 19 14:02:28 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Feb 2010 14:02:28 -0500 Subject: Question about getmtime In-Reply-To: <00c30abd-e240-4ffc-9df7-30fbf573b3ad@y33g2000yqb.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> <00c30abd-e240-4ffc-9df7-30fbf573b3ad@y33g2000yqb.googlegroups.com> Message-ID: <4B7EE044.2080804@ieee.org> Brandon wrote: > On Feb 19, 10:26 am, Krister Svanlund > wrote: > >> On Fri, Feb 19, 2010 at 5:05 PM, Brandon wrote: >> >>> Hi everyone, >>> >>> Does copying or moving a file affect the return value of >>> os.path.getmtime(path)? >>> >>> Thank you, >>> Brandon >>> >> Wouldn't it be easier to make a script and see for yourself then to >> write a mail about it? >> > > Gee, thanks for the help. I guess. > > Well, copying the file won't affect the getmtime, since it's still there, and unmodified. Moving it will cause the getmtime to to get an os.error, because the file no longer exists. Probably you mean you're adjusting the path variable to point to the new location for the file. But the answer is still "it depends." How about if you get more specific? If you write a copy utility using two opens, a read() and a write(), then the new file will certainly get a new timestamp unless you do something to prevent it. If you copy the file from a DOS box in Windows XP, using the COPY command, then the getmtime on the new file will be identical to the one on the old. If you do it on an Amiga using pip, I have no idea. Perhaps you're writing a copy/move utility of your own, and you want to know how to cause a new file to have the same attributes as the original. If so, be more specific. DaveA From davea at ieee.org Fri Feb 19 14:04:16 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Feb 2010 14:04:16 -0500 Subject: Executing Python code on another computer In-Reply-To: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> Message-ID: <4B7EE0B0.5080605@ieee.org> SiWi wrote: > On Feb 19, 5:10 pm, "D'Arcy J.M. Cain" wrote: > >> On Fri, 19 Feb 2010 07:52:59 -0800 (PST) >> >> SiWi wrote: >> >>> So I wondered if it was possible to send the Python code I'm >>> developing on the netbook to the workstation pc via wlan, let the >>> script execute on the workstation pc and write the output back on the >>> netbook. >>> >>> Is there any possibilty to achieve that goal? >>> >> Yes but it isn't really a Python question. I suggest Google but you >> haven't given us enough information, particularly what OSs you are >> running. If it was me I would simply use the netbook as a thin client >> for programs that I am writing and running on the main server. In my >> case a simple xterm would do the job since vi is my IDE and bash is my >> runtime environment. If you are using a GUI IDE you may be able to run >> the GUI app on the server with the display on the netbook. >> >> -- >> D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on >> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. >> > > I'm normally using IDLE and sometimes PyScripter on Windows Vista. The > netbook is Windows XP. Should I switch to Vim or Emacs? > > In that case, consider using RemoveDesktop, which is built into both Xp and Vista. DaveA From misceverything at gmail.com Fri Feb 19 14:08:53 2010 From: misceverything at gmail.com (T) Date: Fri, 19 Feb 2010 11:08:53 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> On Feb 18, 7:19?pm, Ryan Kelly wrote: > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > I have a Python app which I converted to an EXE (all files separate; > > single EXE didn't work properly) via py2exe - I plan on distributing > > this and would like the ability to remotely upgrade the program (for > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > be the best way to go about doing this? > > I've been working on an auto-update framework for my own frozen apps, > you might find it useful: > > ?http://pypi.python.org/pypi/esky > > Docs are a little scarce at the moment, the next release will hopefully > come with a short tutorial (as well as support for cx_freeze and maybe > py2app, depending on how adventurous I'm feeling). > > ? Cheers, > > ? ? ?Ryan > > -- > Ryan Kellyhttp://www.rfk.id.au?| ?This message is digitally signed. Please visit > r... at rfk.id.au ? ? ? ?| ?http://www.rfk.id.au/ramblings/gpg/for details > > ?signature.asc > < 1KViewDownload Thanks Ryan..this looks like it could be what I'm looking for, but I'm still a bit unsure of how exactly how it works. Do you happen to have an idea approx when the next release w/ tutorial will be out? From tjreedy at udel.edu Fri Feb 19 14:25:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Feb 2010 14:25:21 -0500 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: On 2/19/2010 12:44 PM, Stephen Hansen wrote: > Much to my embarrassment, sometime last night I realized I was being a > complete idiot, and the 'correct' way to handle this in my scenario is > really just: > > def initialize(): > # do one time processing here > > return [] > > A generator is just a callable that returns an iterator, after all. Confusing generators and generator functions is, well, confusing. For future reference, and clarity of communication in Pythonland, generator function: function that produces a generator when called; if python coded, its body contains 'yield'. generator: iterator produced by a generator function; has .__next__ and self-returning .__init__, like all other iterators. generator expression: an expression that evaluates to a generator; the expression is used to create a temporary anonymous generator function that is called to produce the generator and is then discarded. >>> def gf(): yield 1 >>> gf >>> g=gf() >>> g >>> ge = (1 for i in [1]) >>> ge at 0x00F5BFD0> >>> dir(ge) [..., '__iter__', ..., '__next__', ...] So, when you said that you send 'generators' to your core system, when you meant 'generator functions', we were understanably confused. (Your core system should accept iterator classes also, unless it specifically checks to avoid duck typing.) Terry Jan Reedy From anfedorov at gmail.com Fri Feb 19 14:47:50 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Fri, 19 Feb 2010 14:47:50 -0500 Subject: Chaining 501 generators breaks everything? Message-ID: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> I implemented a Sieve of Eratosthenesprimes algorithm using generators: http://gist.github.com/309109 This code which chains together 500 generators works fine (~1/20th of a second) on my laptop. The code which chaines 501 generators (s/498/499/ on line 23) doesn't seem to finish. Does anyone know the reason for this, or can anyone point me where to look for a good explanation? Cheers, Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From anfedorov at gmail.com Fri Feb 19 14:57:03 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Fri, 19 Feb 2010 14:57:03 -0500 Subject: Chaining 501 generators breaks everything? In-Reply-To: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> References: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> Message-ID: <7659cab31002191157m498a1de7l1087b930682bd991@mail.gmail.com> Ack, just ran it from shell, realized my editor was just choking on a "maximum recursion depth exceeded" RuntimeError. Didn't realize generators used the call stack... - Andrey On Fri, Feb 19, 2010 at 2:47 PM, Andrey Fedorov wrote: > I implemented a Sieve of Eratosthenesprimes algorithm using generators: > > http://gist.github.com/309109 > > > This code which chains together 500 generators works fine (~1/20th of a > second) on my laptop. The code which chaines 501 generators (s/498/499/ on > line 23) doesn't seem to finish. > > Does anyone know the reason for this, or can anyone point me where to look > for a good explanation? > > Cheers, > Andrey > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 15:02:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 20:02:10 +0000 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> Message-ID: <4B7EEE42.6090806@mrabarnett.plus.com> Vincent Davis wrote: > I have some some (~50) text files that have about 250,000 rows each. I > am reading them in using the following which gets me what I want. But it > is not fast. Is there something I am missing that should help. This is > mostly an question to help me learn more about python. It takes about 4 > min right now. > > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > read = list(reader) > data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x > in read]) 'takewhile' accepts an iterable, so "[x for x in read]" can be simplified to "read". > data = [x for x in data_rows][1:] > data = data_rows[1:] > mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, > list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) > mask = [row for row in mask_rows if row][3:] > No need to convert the result of 'dropwhile' to list. > outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) > outlier = [row for row in outlier_rows if row][3:] > The problem, as I see it, is that you're scanning the rows more than once. Is this any better? def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') data = [] for row in reader: if '[MASKS]' in row: break data.append(row) data = data[1:] mask = [] if '[MASKS]' in row: mask.append(row) for row in reader: if '[OUTLIERS]' in row: break if row: mask.append(row) mask = mask[3:] outlier = [] if '[OUTLIERS]' in row: outlier.append(row) outliter.extend(row for row in outlier if row) outlier = outlier[3:] From jjposner at optimum.net Fri Feb 19 15:16:05 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 19 Feb 2010 15:16:05 -0500 Subject: How to make an empty generator? In-Reply-To: References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: <4B7EF185.1040702@optimum.net> On 2/19/2010 2:25 PM, Terry Reedy wrote: > On 2/19/2010 12:44 PM, Stephen Hansen wrote: > >> Much to my embarrassment, sometime last night I realized I was being a >> complete idiot, and the 'correct' way to handle this in my scenario is >> really just: >> >> def initialize(): >> # do one time processing here >> >> return [] >> >> A generator is just a callable that returns an iterator, after all. > > Confusing generators and generator functions is, well, confusing. > For future reference, and clarity of communication in Pythonland, > > generator function: function that produces a generator when called; if > python coded, its body contains 'yield'. > > generator: iterator produced by a generator function; I suggest: iterator produced by a generator function or a generator expression; has .__next__ and > self-returning .__init__, like all other iterators. > > generator expression: an expression that evaluates to a generator; the > expression is used to create a temporary anonymous generator function > that is called to produce the generator and is then discarded. Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms to Terry's definitions above in most places. But the Glossary says: generator A function which returns an iterator. <... more ...> generator expression An expression that returns a generator. <... more ...> The additional verbiage in these definitions mitigates the damage, but I think the first entry should be headlined *generator function* instead of *generator*. And the Glossary should include Terry's additional entry [ as amended by me :-) ]: generator An iterator produced by a generator function or a generator expression. -John From jjposner at optimum.net Fri Feb 19 16:00:30 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 19 Feb 2010 16:00:30 -0500 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> Message-ID: <4B7EFBEE.1030808@optimum.net> On 2/19/2010 3:02 PM, MRAB wrote: > Is this any better? > > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > data = [] > for row in reader: > if '[MASKS]' in row: > break > data.append(row) As noted in another thread recently, you can save time by *not* looking up the "append" method of the list object each time through the FOR loop: data = [] app_method = data.append for row in reader: if '[MASKS]' in row: break app_method(row) Similarly in the rest of the code. This technique improved performance about 31% in this test: #-------------------- import timeit tt = timeit.repeat("for i in xrange(1000000): mylist.append(i)", "mylist=[]", number=25) print "look up append() method each time:", min(tt) tt = timeit.repeat("for i in xrange(1000000): app(i)", "mylist=[]; app = mylist.append", number=25) print "look up append() method just once:", min(tt) #-------------------- output: look up append() method each time: 8.45481741783 look up append() method just once: 5.84429637887 -John From jgardner at jonathangardner.net Fri Feb 19 16:13:09 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 13:13:09 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> Message-ID: <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> On Fri, Feb 19, 2010 at 10:22 AM, Vincent Davis wrote: > I have some some (~50) text files that have about 250,000 rows each. I am > reading them in using the following which gets me what I want. But it is not > fast. Is there something I am missing that should help. This is mostly an > question to help me learn more about python. It takes about 4 min right now. > > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > read = list(reader) > You're slurping the entire file here when it's not necessary. > data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in > read]) > [x for x in read] is basically a copy of the entire list. This isn't necessary. > data = [x for x in data_rows][1:] > > Again, copying here is unnecessary. [x for x in y] isn't a paradigm in Python. If you really need a copy of an array, x = y[:] is the paradigm. > mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, > list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) > > mask = [row for row in mask_rows if row][3:] > Here's another unnecessary array copy. > > outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) > outlier = [row for row in outlier_rows if row][3:] > And another. Just because you're using Python doesn't mean you get to be silly in how you move data around. Avoid copies as much as possible, and try to avoid slurping in large files all at once. Line-by-line processing is best. I think you should invert this operation into a for loop. Most people tend to think of things better that way than chained iterators. It also helps you to not duplicate data when it's unnecessary. -- Jonathan Gardner jgardner at jonathangardner.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryan at rfk.id.au Fri Feb 19 16:28:37 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 20 Feb 2010 08:28:37 +1100 Subject: Upgrading Py2exe App In-Reply-To: <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: <1266614917.2495.34.camel@rambutan> On Thu, 2010-02-18 at 20:32 -0800, CM wrote: > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > I have a Python app which I converted to an EXE (all files separate; > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > this and would like the ability to remotely upgrade the program (for > > > example, via HTTP/HTTPS). Looks like it's not just the EXE that I > > > will need need to replace (DLLs, the library.zip, etc.). What would > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > you might find it useful: > > > > http://pypi.python.org/pypi/esky > > > > > This looks pretty interesting and useful. Thanks :-) > Just to help me understand it a bit more: what is it that users will > download from some web page in order to initially get the py2exe'd app > on their system? Is it "really" an "esky", with the app's .exe file > inside it (but the esky is named the same as the app)? Currently, it's just a zip file with the frozen app in it, which the user unzips to wherever they want the app. When unzipped it looks like this: myapp.exe <-- actually the esky bootstrap exe myapp-X.Y.Z.win32/ myapp.exe <-- the actual frozen app as produced by py2exe python26.dll ...etc... This could easily be wrapped in an installer - the important thing is just that the files end up on the user's machine in the expected directory structure. > And then when > they want to update, the app's code calls the esky class to do the > work of swapping out the appropriate .exe file? Something like this? Yes. The idea of having a "bootstrapping exe" is that actual application code can be swapped out without having to overwrite the executable file. As long as you don't change python versions, this allows updates to be safe against system crashes, even on platforms without atomic file replacement. So the frozen app does this in a background thread: Esky(sys.executable,"http://my.updates.com").auto_update() And it hits the given url, grabs the latest zipfile, downloads and unpacks and atomically places it into the application directory. Et viola, your app is at the latest version. From the packager's point of view, you run the "bdist_esky" distutils command to generate the zipfile containing your latest version, then simply upload it to your server. > Would this also work if one used InnoSetup to install the exe on the > user's system? Yes, absolutely - in fact I plan to do this myself at some stage. All that's required is that the files end up in the expected directory structure. 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From ryan at rfk.id.au Fri Feb 19 16:32:16 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 20 Feb 2010 08:32:16 +1100 Subject: Upgrading Py2exe App In-Reply-To: <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> Message-ID: <1266615136.2495.39.camel@rambutan> On Fri, 2010-02-19 at 11:08 -0800, T wrote: > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > I have a Python app which I converted to an EXE (all files separate; > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > this and would like the ability to remotely upgrade the program (for > > > example, via HTTP/HTTPS). Looks like it's not just the EXE that I > > > will need need to replace (DLLs, the library.zip, etc.). What would > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > you might find it useful: > > > > http://pypi.python.org/pypi/esky > > > > Docs are a little scarce at the moment, the next release will hopefully > > come with a short tutorial (as well as support for cx_freeze and maybe > > py2app, depending on how adventurous I'm feeling). > > > Thanks Ryan..this looks like it could be what I'm looking for, but I'm > still a bit unsure of how exactly how it works. Do you happen to have > an idea approx when the next release w/ tutorial will be out? If I punt on the py2app support, I should be able to get it done in the next 3-4 days. I'll send a quick email to python-list when it's ready. Here's a rough roadmap of where the project is heading: v0.4.0: cx_freeze support and a tutorial [the next 3-4 days] v0.4.1: py2app support [the next 2-3 weeks] v0.5.0: differential updates using bsdiff [next few months] 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From wolftracks at invalid.com Fri Feb 19 16:42:55 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 19 Feb 2010 13:42:55 -0800 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On 2/19/2010 10:56 AM, CM wrote: > On Feb 19, 12:21 pm, "W. eWatson" wrote: >> On 2/19/2010 7:16 AM, Mark Lawrence wrote:> Andre Engels wrote: >>>> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence >>>> wrote: >>>>> Andre Engels wrote: >>>>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson >> >> ... >> tories, or even the whole hard drive, for snowball.*. Then the OP> would know exactly what he has or hasn't got. >> >>> HTH. >> >>> Mark Lawrence >> >> Here's the answer. Consider this folder. >> >> Afolder >> abc.py >> hello.py >> >> I now apply py2exe steps to produce an "executable" for abc. The folder >> now changes to >> >> Afolder >> build >> dist >> abc.py >> hello.py >> >> build are two new folders. dist contains abc.exe. >> >> Somehow when I type abc at the command prompt, this follows a path to >> dist, and finds abc.exe, where it executes properly. >> Cute, eh? I have no explanation for it. > > Are you sure it's executing abc.exe? If you are at a Python command > prompt within the "DOS shell" and you just type just abc, I think what > is happening is you are running abc.py, NOT abc.exe. > > py2exe creates a dist folder (short for "distributables") by default > and puts your .exe into it along with whatever other files are needed > to run your application. Depending on how you set the bundling > options, this may be a lot of things or just 1-2 other things. > > Che Well, you are right. What proof do I have? In fact, I just tried to run a program that was not converted, and left off py. It worked. So maybe the only way to execute the compiled code is to to to dist? From jgardner at jonathangardner.net Fri Feb 19 16:47:46 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 13:47:46 -0800 Subject: Chaining 501 generators breaks everything? In-Reply-To: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> References: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> Message-ID: <6cc20cea1002191347n7a48a231ic4d65ad020296b54@mail.gmail.com> On Fri, Feb 19, 2010 at 11:47 AM, Andrey Fedorov wrote: > I implemented a?Sieve of Eratosthenes primes algorithm using generators: > > http://gist.github.com/309109 > > This code which chains together 500 generators works fine (~1/20th of a > second) on my laptop. > You may want a more traditional approach. Until Python gets tail recursion (doubtful), this won't work very well on any platform. #!/usr/bin/env python from itertools import islice, count from time import time def primes(): seen = [] for i in count(2): for s in seen: if i%s == 0: break else: # Run if the for loop doesn't break seen.append(i) yield i start = time() for i in islice(primes(), 0, 10000): print i print time() - start -- Jonathan Gardner jgardner at jonathangardner.net From mattbarkan at gmail.com Fri Feb 19 16:48:47 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 13:48:47 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) Message-ID: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. The strangest thing about this is that firefox still works flawlessly on any site. However, at my friend's place, I was able to open url's from HIS computer, no problem. Can anyone think of anything I can do to solve this problem? Why would firefox be working fine but not Python? Any suggestions would be greatly appreciated. Matt From apt.shansen at gmail.com Fri Feb 19 16:52:57 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 19 Feb 2010 13:52:57 -0800 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: <7a9c25c21002191352v3dcfb04fm4a332a6f773f047e@mail.gmail.com> On Fri, Feb 19, 2010 at 1:42 PM, W. eWatson wrote: > >> Well, you are right. What proof do I have? In fact, I just tried to run a > program that was not converted, and left off py. It worked. > > So maybe the only way to execute the compiled code is to to to dist? Yes. You're meant to move everything in "dist" to where you want to run it, that's the point of the dist folder-- its what you distribute. THe .exe and the other stuff next to it the .exe needs to run. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Fri Feb 19 16:58:41 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 19 Feb 2010 14:58:41 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> Message-ID: <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> In reference to the several comments about "[x for x in read] is basically a copy of the entire list. This isn't necessary." or list(read). I had thought I had a problem with having iterators in the takewhile() statement. I thought I testes and it didn't work. It seems I was wrong. It clearly works. I'll make this change and see if it is any better. I actually don't plan to read them all in at once, only as needed, but I do need the whole file in an array to perform some mathematics on them and compare different files. So my interest was in making it faster to open them as needed. I guess part of it is that they are about 5mb so I guess it might be disk speed in part. Thanks *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Fri, Feb 19, 2010 at 2:13 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Fri, Feb 19, 2010 at 10:22 AM, Vincent Davis wrote: > >> I have some some (~50) text files that have about 250,000 rows each. I am >> reading them in using the following which gets me what I want. But it is not >> fast. Is there something I am missing that should help. This is mostly an >> question to help me learn more about python. It takes about 4 min right now. >> >> def read_data_file(filename): >> reader = csv.reader(open(filename, "U"),delimiter='\t') >> read = list(reader) >> > > You're slurping the entire file here when it's not necessary. > > >> data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in >> read]) >> > > [x for x in read] is basically a copy of the entire list. This isn't > necessary. > > >> data = [x for x in data_rows][1:] >> >> > > Again, copying here is unnecessary. > > [x for x in y] isn't a paradigm in Python. If you really need a copy of an > array, x = y[:] is the paradigm. > > >> mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, >> list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) >> > > > > > >> mask = [row for row in mask_rows if row][3:] >> > > Here's another unnecessary array copy. > > >> >> outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, >> read) >> outlier = [row for row in outlier_rows if row][3:] >> > > > And another. > > Just because you're using Python doesn't mean you get to be silly in how > you move data around. Avoid copies as much as possible, and try to avoid > slurping in large files all at once. Line-by-line processing is best. > > I think you should invert this operation into a for loop. Most people tend > to think of things better that way than chained iterators. It also helps you > to not duplicate data when it's unnecessary. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Fri Feb 19 17:00:03 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 14:00:03 -0800 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: <6cc20cea1002191400j33f4735cl9809b40b5f189777@mail.gmail.com> On Fri, Feb 19, 2010 at 1:48 PM, MattB wrote: > > I've been working on a program that accesses my school's password > protected website and downloads directory names. I'm using mechanize. > > Recently, the program has been unable to open the website, returning > the 'errno 61 connection refused' error. I presume the school's server > was blocking me because of many automated logins. > > However, it turns out that I cannot now open ANY url from within > Python on my computer using mechanize (or urllib for that matter). > And I've tried in several places -- my place, a friend's place (who > also has comcast as an ISP) and the school -- but no dice, constant > errno 61's whenever I try to open a url. > > The strangest thing about this is that firefox still works flawlessly > on any site. > > However, at my friend's place, I was able to open url's from HIS > computer, no problem. > > Can anyone think of anything I can do to solve this problem? Why would > firefox be working fine but not Python? > > Any suggestions would be greatly appreciated. > Are you running behind a firewall? See if Firefox is configured with a proxy. You'll have to use that to talk to any website. -- Jonathan Gardner jgardner at jonathangardner.net From lie.1296 at gmail.com Fri Feb 19 17:05:04 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 09:05:04 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <4b7f0b2c$1@dnews.tpgi.com.au> On 02/19/10 14:57, Steve Howell wrote: > In a more real world example, the intermediate results would be > something like this: > > departments > departments_in_new_york > departments_in_new_york_not_on_bonus_cycle > employees_in_departments_in_new_york_not_on_bonus_cycle > names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > I fare better, in less than ten-seconds thinking: departments eligible_departments eligible_departments eligible_employees eligible_employee_names as a bonus, they would be much more resilient when there are change of eligibility requirements. Names doesn't have to exactly describe what's in it; in fact, if your names is way too descriptive, it may take significantly more brain-cycle to parse. A good name abstracts the objects contained in it. From half.italian at gmail.com Fri Feb 19 17:09:56 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Fri, 19 Feb 2010 14:09:56 -0800 (PST) Subject: Question about getmtime References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <2f56a4b1-4f2b-4ec9-827b-e6d4e5d52f7d@v20g2000prb.googlegroups.com> On Feb 19, 10:06?am, MRAB wrote: > Brandon wrote: > > Hi everyone, > > > Does copying or moving a file affect the return value of > > os.path.getmtime(path)? > > The modification time of a copied file should be the same as the > original. > > The creation time of a copied file will be the time at which it was > copied, so that can result in the paradoxical state of a file having > been modified _before_ it was created! :-) ctime does not stand for creation time. I went through this a couple of months ago. It's updated whenever the inode is updated, so changing permissions, among other things will update it. It blew me away when I finally found this out. ~Sean From clp2 at rebertia.com Fri Feb 19 17:12:21 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Feb 2010 14:12:21 -0800 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: <50697b2c1002191412u43d6cbd0off090f987e82d61@mail.gmail.com> On Fri, Feb 19, 2010 at 1:48 PM, MattB wrote: > Hey all, > > I've been working on a program that accesses my school's password > protected website and downloads directory names. I'm using mechanize. > > Recently, the program has been unable to open the website, returning > the 'errno 61 connection refused' error. I presume the school's server > was blocking me because of many automated logins. > > However, it turns out that I cannot now open ANY url from within > Python on my computer using mechanize (or urllib for that matter). > And I've tried in several places -- my place, a friend's place (who > also has comcast as an ISP) and the school -- but no dice, constant > errno 61's whenever I try to open a url. > > The strangest thing about this is that firefox still works flawlessly > on any site. > Can anyone think of anything I can do to solve this problem? Why would > firefox be working fine but not Python? > > Any suggestions would be greatly appreciated. Based on what you've said, it's possible the school may have blocked mechanize's User-Agent somehow. Try spoofing mechanize as Firefox by setting the string for the User-Agent header to that of Firefox. See the section "Changing the automatically-added headers (User-Agent)" on http://wwwsearch.sourceforge.net/mechanize/doc.html for how to do that. To see what Firefox's User-Agent is, use http://whatsmyuseragent.com/ Cheers, Chris -- Disclaimer: This is not meant to in any way endorse violating AUPs. http://blog.rebertia.com From bret.clement at gmail.com Fri Feb 19 17:18:18 2010 From: bret.clement at gmail.com (Bret) Date: Fri, 19 Feb 2010 14:18:18 -0800 (PST) Subject: ActiveState/O'Reilly Launch New and Improved Code Share Site (Python) Message-ID: ActiveState launched today the new code.activestate.com with code recipes for dynamic languages such as Python, Perl and Tcl and web development. This site is great recipe sharing site for all Python, Perl and Tcl developers. O'Reilly will be use recipes from the site for its next Python cook book. Bit.ly link to the blog announcement: http://bit.ly/b1Wkdm From martin.hellwig at dcuktec.org Fri Feb 19 18:02:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 19 Feb 2010 23:02:34 +0000 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: On 02/19/10 21:48, MattB wrote: > Hey all, > > I've been working on a program that accesses my school's password > protected website and downloads directory names. I'm using mechanize. > > Recently, the program has been unable to open the website, returning > the 'errno 61 connection refused' error. I presume the school's server > was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. > > However, it turns out that I cannot now open ANY url from within > Python on my computer using mechanize (or urllib for that matter). > And I've tried in several places -- my place, a friend's place (who > also has comcast as an ISP) and the school -- but no dice, constant > errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > The strangest thing about this is that firefox still works flawlessly > on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). > Any suggestions would be greatly appreciated. > > Matt Google a bit around how you can figure out (from inside your script) whether your used platform has a proxy configured and how to use it with your application. Good luck! -- mph From jg07024 at gmail.com Fri Feb 19 18:16:35 2010 From: jg07024 at gmail.com (John Graves) Date: Fri, 19 Feb 2010 15:16:35 -0800 (PST) Subject: PyConPads at PyCon 2010 in Atlanta Message-ID: <31a94d5f-1304-46fa-9f1b-a4a68b07f6c9@s36g2000prf.googlegroups.com> Couldn't make it to PyCon 2010 in person? Want to access collaborative notes taken there? Watch the short video at http://bit.ly/dgBcpA to see how to find live notes being taken at the conference on PyConPads. You can chat with -- and thank! -- the note takers. The site: http://pyconpads.net Twitter announcements of pads: http://twitter.com/pyconpads From python at mrabarnett.plus.com Fri Feb 19 18:18:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 23:18:14 +0000 Subject: Question about getmtime In-Reply-To: <2f56a4b1-4f2b-4ec9-827b-e6d4e5d52f7d@v20g2000prb.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> <2f56a4b1-4f2b-4ec9-827b-e6d4e5d52f7d@v20g2000prb.googlegroups.com> Message-ID: <4B7F1C36.4030906@mrabarnett.plus.com> Sean DiZazzo wrote: > On Feb 19, 10:06 am, MRAB wrote: >> Brandon wrote: >>> Hi everyone, >>> Does copying or moving a file affect the return value of >>> os.path.getmtime(path)? >> The modification time of a copied file should be the same as the >> original. >> >> The creation time of a copied file will be the time at which it was >> copied, so that can result in the paradoxical state of a file having >> been modified _before_ it was created! :-) > > ctime does not stand for creation time. I went through this a couple > of months ago. It's updated whenever the inode is updated, so > changing permissions, among other things will update it. > > It blew me away when I finally found this out. > On Windows ctime doesn't change when the file permissions are changed. From jgardner at jonathangardner.net Fri Feb 19 18:36:50 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 15:36:50 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> Message-ID: <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> On Fri, Feb 19, 2010 at 1:58 PM, Vincent Davis wrote: > In reference to the several comments about "[x for x in read] is basically > a copy of the entire list. This isn't necessary." or list(read). I had > thought I had a problem with having iterators in the takewhile() statement. > I thought I testes and it didn't work. It seems I was wrong. It clearly > works. I'll make this change and see if it is any better. > > I actually don't plan to read them all in at once, only as needed, but I do > need the whole file in an array to perform some mathematics on them and > compare different files. So my interest was in making it faster to open them > as needed. I guess part of it is that they are about 5mb so I guess it might > be disk speed in part.nks > > Record your numbers in an array and then work your magic on them later. Don't store the entire file in memory, though. -- Jonathan Gardner jgardner at jonathangardner.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Fri Feb 19 19:15:07 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Feb 2010 16:15:07 -0800 Subject: How to use python to register a service (an existing .exe file) References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: In article <4b79e28c$0$4610$426a74cc at news.free.fr>, News123 wrote: >Is there a python way to register new windows services. > >I am aware of the >instsrv.exe program, which can be used to install services. >I could use subprocess.Popen to call > >instsrv.exe "service_name" program.exe > >but wondered, whether there's already an existing function. Use the win32 package. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From mattbarkan at gmail.com Fri Feb 19 19:20:53 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 16:20:53 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> On Feb 19, 6:02?pm, "Martin P. Hellwig" wrote: > On 02/19/10 21:48, MattB wrote: > > > Hey all, > > > I've been working on a program that accesses my school's password > > protected website and downloads directory names. I'm using mechanize. > > > Recently, the program has been unable to open the website, returning > > the 'errno 61 connection refused' error. I presume the school's server > > was blocking me because of many automated logins. > > Being a former school BOFH, I can assure you that if I was annoyed by > your 'misuse' I would have tracked you down and made you aware of it. > > > > > However, it turns out that I cannot now open ANY url from within > > Python on my computer using mechanize (or urllib for that matter). > > And I've tried in several places -- my place, a friend's place (who > > also has comcast as an ISP) and the school -- but no dice, constant > > errno 61's whenever I try to open a url. > > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > > > > The strangest thing about this is that firefox still works flawlessly > > on any site. > > Your system might have been centrally configure so that applications are > aware of the proxy, firefox probably has been piggybacking on those > settings (as it should). Most platforms can be made aware of a proxy by > a DHCP option send by the DHCP server (that is when you automatically > get an IP address). > > > Any suggestions would be greatly appreciated. > > > Matt > > Google a bit around how you can figure out (from inside your script) > whether your used platform has a proxy configured and how to use it with > your application. > > Good luck! > > -- > mph Hey all, I've used httpfox to identify the precise headers being sent by firefox, and then added them to my program using br.addheaders(), as per the proper mechanize syntax. No dice. (In fact, these headers were in the program when I ran it successfully from my friend's computer at his apartment). So I'm pretty sure it's not a header issue. I'll check and see whether firefox and my system are using a proxy. Also, based on Martin's comment, I just wanted to make you all aware that I intend no misuse, but rather am just trying to learn, as I'm a programming noob. I am not doing anything that I can't do myself from firefox (ie, I have an account at the school, and am allowed to sign on with my name and password and look up information in the student directory). If I do it for more than one student, it just becomes repetitive, so I thought this was a first modest goal in learning to do some programming.) That said, I'm happy to discontinue the attempts, but I'd like to know how it is that my computer (unless using firefox) is completely blocked from opening urls from within python. (And how to fix it). Thanks for the continued help. From mattbarkan at gmail.com Fri Feb 19 20:06:45 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 17:06:45 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> Message-ID: <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> On Feb 19, 7:20?pm, MattB wrote: > On Feb 19, 6:02?pm, "Martin P. Hellwig" > wrote: > > > > > On 02/19/10 21:48, MattB wrote: > > > > Hey all, > > > > I've been working on a program that accesses my school's password > > > protected website and downloads directory names. I'm using mechanize. > > > > Recently, the program has been unable to open the website, returning > > > the 'errno 61 connection refused' error. I presume the school's server > > > was blocking me because of many automated logins. > > > Being a former school BOFH, I can assure you that if I was annoyed by > > your 'misuse' I would have tracked you down and made you aware of it. > > > > However, it turns out that I cannot now open ANY url from within > > > Python on my computer using mechanize (or urllib for that matter). > > > And I've tried in several places -- my place, a friend's place (who > > > also has comcast as an ISP) and the school -- but no dice, constant > > > errno 61's whenever I try to open a url. > > > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > > > The strangest thing about this is that firefox still works flawlessly > > > on any site. > > > Your system might have been centrally configure so that applications are > > aware of the proxy, firefox probably has been piggybacking on those > > settings (as it should). Most platforms can be made aware of a proxy by > > a DHCP option send by the DHCP server (that is when you automatically > > get an IP address). > > > > Any suggestions would be greatly appreciated. > > > > Matt > > > Google a bit around how you can figure out (from inside your script) > > whether your used platform has a proxy configured and how to use it with > > your application. > > > Good luck! > > > -- > > mph > > Hey all, > > I've used httpfox to identify the precise headers being sent by > firefox, and then added them to my program using br.addheaders(), as > per the proper mechanize syntax. No dice. (In fact, these headers were > in the program when I ran it successfully from my friend's computer at > his apartment). So I'm pretty sure it's not a header issue. > > I'll check and see whether firefox and my system are using a proxy. > > Also, based on Martin's comment, I just wanted to make you all aware > that I intend no misuse, but rather am just trying to learn, as I'm a > programming noob. I am not doing anything that I can't do myself from > firefox (ie, I have an account at the school, and am allowed to sign > on with my name and password and look up information in the student > directory). If I do it for more than one student, it just becomes > repetitive, so I thought this was a first modest goal in learning to > do some programming.) > > That said, I'm happy to discontinue the attempts, but I'd like to know > how it is that my computer (unless using firefox) is completely > blocked from opening urls from within python. (And how to fix it). > > Thanks for the continued help. Breakthrough: I tried switching from a wireless connection to my router, and instead used an ethernet connection -- and now everything works. Why would this make a difference? MAC address? Is it possible for an external server to see my MAC address and block it? Clearly wasn't an IP address issue! From livingstonemark at gmail.com Fri Feb 19 20:15:33 2010 From: livingstonemark at gmail.com (Mark Livingstone) Date: Sat, 20 Feb 2010 11:15:33 +1000 Subject: Looking for crossfold validation code Message-ID: Hello, I am doing research as part of a Uni research Scholarship into using data compression for classification. What I am looking for is python code to handle the crossfold validation side of things for me - that will take my testing / training corpus and create the testing / training files after asking me for number of folds and number of times (or maybe allow me to enter a random seed or offset instead of times.) I could then either hook my classifier into the program or use it in a separate step. Probably not very hard to write, but why reinvent the wheel ;-) Thanks in advance, MarkL From clp2 at rebertia.com Fri Feb 19 20:28:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Feb 2010 17:28:04 -0800 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: <50697b2c1002191728i698a919cgc2e2d3286a5d918c@mail.gmail.com> On Fri, Feb 19, 2010 at 5:06 PM, MattB wrote: > On Feb 19, 7:20?pm, MattB wrote: >> On Feb 19, 6:02?pm, "Martin P. Hellwig" >> wrote: >> > On 02/19/10 21:48, MattB wrote: >> > > Hey all, >> >> > > I've been working on a program that accesses my school's password >> > > protected website and downloads directory names. I'm using mechanize. >> >> > > Recently, the program has been unable to open the website, returning >> > > the 'errno 61 connection refused' error. I presume the school's server >> > > was blocking me because of many automated logins. >> >> > Being a former school BOFH, I can assure you that if I was annoyed by >> > your 'misuse' I would have tracked you down and made you aware of it. >> >> > > However, it turns out that I cannot now open ANY url from within >> > > Python on my computer using mechanize (or urllib for that matter). >> > > And I've tried in several places -- my place, a friend's place (who >> > > also has comcast as an ISP) and the school -- but no dice, constant >> > > errno 61's whenever I try to open a url. >> >> > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. >> >> > > The strangest thing about this is that firefox still works flawlessly >> > > on any site. >> >> > Your system might have been centrally configure so that applications are >> > aware of the proxy, firefox probably has been piggybacking on those >> > settings (as it should). Most platforms can be made aware of a proxy by >> > a DHCP option send by the DHCP server (that is when you automatically >> > get an IP address). >> >> > > Any suggestions would be greatly appreciated. > Breakthrough: > > I tried switching from a wireless connection to my router, and instead > used an ethernet connection -- and now everything works. > > Why would this make a difference? MAC address? Is it possible for an > external server to see my MAC address and block it? Clearly wasn't an > IP address issue! If you're using the campus network and depending on the exact network details, yes, they very likely can know your MAC address and thus block it. Since your Wi-Fi card and Ethernet card have different hardware MAC addresses, yes, switching would change your visible MAC address, thus circumventing any blocks based on it. Cheers, Chris -- Hi ACMS! http://blog.rebertia.com From anand.shashwat at gmail.com Fri Feb 19 21:25:40 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 07:55:40 +0530 Subject: the mystery of dirname() Message-ID: In the following code sample : def dirname(p): """Returns the directory component of a pathname""" i = p.rfind('/') + 1 head = p[:i] if head and head != '/'*len(head): head = head.rstrip('/') return head def dirname1(p): i = p.rfind('/') + 1 head = p[:i] if head != '/': return head.rstrip('/') return head if __name__ == "__main__": p1 = '/Users/l0nwlf/Desktop' p2 = './' p3 = '/' p4 = '.' print dirname(p1), dirname1(p1) print dirname(p2), dirname1(p2) print dirname(p3), dirname1(p3) print dirname(p4), dirname1(p4) OUTPUT: /Users/l0nwlf /Users/l0nwlf . . / / dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of "if head and head != '/'*len(head):" and replaced it with more obvious way in dirname1(). Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? Regards, ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattbarkan at gmail.com Fri Feb 19 21:32:59 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 18:32:59 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: On Feb 19, 8:28?pm, Chris Rebert wrote: > On Fri, Feb 19, 2010 at 5:06 PM, MattB wrote: > > On Feb 19, 7:20?pm, MattB wrote: > >> On Feb 19, 6:02?pm, "Martin P. Hellwig" > >> wrote: > >> > On 02/19/10 21:48, MattB wrote: > >> > > Hey all, > > >> > > I've been working on a program that accesses my school's password > >> > > protected website and downloads directory names. I'm using mechanize. > > >> > > Recently, the program has been unable to open the website, returning > >> > > the 'errno 61 connection refused' error. I presume the school's server > >> > > was blocking me because of many automated logins. > > >> > Being a former school BOFH, I can assure you that if I was annoyed by > >> > your 'misuse' I would have tracked you down and made you aware of it. > > >> > > However, it turns out that I cannot now open ANY url from within > >> > > Python on my computer using mechanize (or urllib for that matter). > >> > > And I've tried in several places -- my place, a friend's place (who > >> > > also has comcast as an ISP) and the school -- but no dice, constant > >> > > errno 61's whenever I try to open a url. > > >> > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > >> > > The strangest thing about this is that firefox still works flawlessly > >> > > on any site. > > >> > Your system might have been centrally configure so that applications are > >> > aware of the proxy, firefox probably has been piggybacking on those > >> > settings (as it should). Most platforms can be made aware of a proxy by > >> > a DHCP option send by the DHCP server (that is when you automatically > >> > get an IP address). > > >> > > Any suggestions would be greatly appreciated. > > > Breakthrough: > > > I tried switching from a wireless connection to my router, and instead > > used an ethernet connection -- and now everything works. > > > Why would this make a difference? MAC address? Is it possible for an > > external server to see my MAC address and block it? Clearly wasn't an > > IP address issue! > > If you're using the campus network and depending on the exact network > details, yes, they very likely can know your MAC address and thus > block it. > Since your Wi-Fi card and Ethernet card have different hardware MAC > addresses, yes, switching would change your visible MAC address, thus > circumventing any blocks based on it. > > Cheers, > Chris > -- > Hi ACMS!http://blog.rebertia.com Chris, I'm using the network in my own apartment. Not the campus's. Moreover, my mac's MAC address is different from the MAC address shown by my router, but as I said I'm also blocked when using my friend's wireless router at his apartment. So it must be my mac's MAC, and not the router's MAC, that's being blocked, right? But ALSO -- is it my ISP that's blocking the mac's MAC (and not the school), since I can't raise ANY url's from python when I'm on wireless? From shearichard at gmail.com Fri Feb 19 21:39:57 2010 From: shearichard at gmail.com (northof40) Date: Fri, 19 Feb 2010 18:39:57 -0800 (PST) Subject: Capturing errors raised by other scripts ? Message-ID: I'm using the subroutine module to run run python script A.py from B.py (this is on windows fwiw). A.py is not my script and it may raise arbitary errors before exiting. How can I determine what's happened before A.py exited ? To simulate this I've got this script (which is meant to simulate A.py): class customError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) try: raise customError(2*2) except customError as e: print 'Custom exception occurred, value:', e.value I then run my A.py like this : >>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') >>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') >>> try: ... pathtojob="python.exe A.py" ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) ... except: ... print "bad stuff happened" ... When I do this I the exception handler is not fired and the text "Custom exception occurred, value: 4" ends up in the stdout file. I'd really like it to end up in stderr because then I could say "anything in stderr ? then ignore the output and flag an error". I don't want to have to parse the stdout for error like messages and I can't make changes to A.py. I'm sure there's a better way to do this - can anyone offer some advice ? thanks Richard. From anand.shashwat at gmail.com Fri Feb 19 21:55:23 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 08:25:23 +0530 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: try this : >>> url = 'http://www.google.com' >>> proxy = {'http': 'http://username:password at proxy:port'} >>> content = urllib.urlopen(url, proxies = proxy).read() Hopefully it should run without error. Second approach can be to check whether your environment variables are setup. $set will show you. If not the case set up your environment variable. HTH, ~l0nwlf On Sat, Feb 20, 2010 at 8:02 AM, MattB wrote: > On Feb 19, 8:28 pm, Chris Rebert wrote: > > On Fri, Feb 19, 2010 at 5:06 PM, MattB wrote: > > > On Feb 19, 7:20 pm, MattB wrote: > > >> On Feb 19, 6:02 pm, "Martin P. Hellwig" > > >> wrote: > > >> > On 02/19/10 21:48, MattB wrote: > > >> > > Hey all, > > > > >> > > I've been working on a program that accesses my school's password > > >> > > protected website and downloads directory names. I'm using > mechanize. > > > > >> > > Recently, the program has been unable to open the website, > returning > > >> > > the 'errno 61 connection refused' error. I presume the school's > server > > >> > > was blocking me because of many automated logins. > > > > >> > Being a former school BOFH, I can assure you that if I was annoyed > by > > >> > your 'misuse' I would have tracked you down and made you aware of > it. > > > > >> > > However, it turns out that I cannot now open ANY url from within > > >> > > Python on my computer using mechanize (or urllib for that matter). > > >> > > And I've tried in several places -- my place, a friend's place > (who > > >> > > also has comcast as an ISP) and the school -- but no dice, > constant > > >> > > errno 61's whenever I try to open a url. > > > > >> > As mentioned by Jonathan Gardener, this is most likely a proxy > gateway. > > > > >> > > The strangest thing about this is that firefox still works > flawlessly > > >> > > on any site. > > > > >> > Your system might have been centrally configure so that applications > are > > >> > aware of the proxy, firefox probably has been piggybacking on those > > >> > settings (as it should). Most platforms can be made aware of a proxy > by > > >> > a DHCP option send by the DHCP server (that is when you > automatically > > >> > get an IP address). > > > > >> > > Any suggestions would be greatly appreciated. > > > > > Breakthrough: > > > > > I tried switching from a wireless connection to my router, and instead > > > used an ethernet connection -- and now everything works. > > > > > Why would this make a difference? MAC address? Is it possible for an > > > external server to see my MAC address and block it? Clearly wasn't an > > > IP address issue! > > > > If you're using the campus network and depending on the exact network > > details, yes, they very likely can know your MAC address and thus > > block it. > > Since your Wi-Fi card and Ethernet card have different hardware MAC > > addresses, yes, switching would change your visible MAC address, thus > > circumventing any blocks based on it. > > > > Cheers, > > Chris > > -- > > Hi ACMS!http://blog.rebertia.com > > Chris, > > I'm using the network in my own apartment. Not the campus's. > Moreover, my mac's MAC address is different from the MAC address shown > by my router, but as I said I'm also blocked when using my friend's > wireless router at his apartment. > > So it must be my mac's MAC, and not the router's MAC, that's being > blocked, right? > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > school), since I can't raise ANY url's from python when I'm on > wireless? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 22:05:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 03:05:43 +0000 Subject: the mystery of dirname() In-Reply-To: References: Message-ID: <4B7F5187.3060806@mrabarnett.plus.com> Shashwat Anand wrote: > In the following code sample : > > def dirname(p): > > """Returns the directory component of a pathname""" > i = p.rfind('/') + 1 > > head = p[:i] > if head and head != '/'*len(head): > > head = head.rstrip('/') > > return head > > def dirname1(p): > i = p.rfind('/') + 1 > > head = p[:i] > if head != '/': > > return head.rstrip('/') > return head > > if __name__ == "__main__": > p1 = '/Users/l0nwlf/Desktop' > > p2 = './' > p3 = '/' > p4 = '.' > > print dirname(p1), dirname1(p1) > > print dirname(p2), dirname1(p2) > > print dirname(p3), dirname1(p3) > > print dirname(p4), dirname1(p4) > > OUTPUT: > > /Users/l0nwlf /Users/l0nwlf > . . > / / > > dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of "if head and head != '/'*len(head):" and replaced it with more obvious way in dirname1(). > > Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? > What if the path is '//x'? The current dirname would return '//', whereas dirname1 would return ''. From anand.shashwat at gmail.com Fri Feb 19 22:09:05 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 08:39:05 +0530 Subject: the mystery of dirname() In-Reply-To: <4B7F5187.3060806@mrabarnett.plus.com> References: <4B7F5187.3060806@mrabarnett.plus.com> Message-ID: But this is posixpath, right ? So '//x' like path will not occur as far as I guess ? On Sat, Feb 20, 2010 at 8:35 AM, MRAB wrote: > Shashwat Anand wrote: > >> In the following code sample : >> >> def dirname(p): >> >> """Returns the directory component of a pathname""" >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head and head != '/'*len(head): >> >> head = head.rstrip('/') >> >> return head >> >> def dirname1(p): >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head != '/': >> >> return head.rstrip('/') return head >> >> if __name__ == "__main__": >> p1 = '/Users/l0nwlf/Desktop' >> >> p2 = './' >> p3 = '/' >> p4 = '.' >> >> print dirname(p1), dirname1(p1) >> >> print dirname(p2), dirname1(p2) >> >> print dirname(p3), dirname1(p3) >> >> print dirname(p4), dirname1(p4) >> >> OUTPUT: >> >> /Users/l0nwlf /Users/l0nwlf >> . . >> / / >> >> dirname() is a function taken from /Lib/posixpath.py. However i did not >> quite understood the usage of "if head and head != '/'*len(head):" and >> replaced it with more obvious way in dirname1(). >> >> Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge >> cases here ? >> >> What if the path is '//x'? The current dirname would return '//', > whereas dirname1 would return ''. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 22:13:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 03:13:10 +0000 Subject: Capturing errors raised by other scripts ? In-Reply-To: References: Message-ID: <4B7F5346.9060308@mrabarnett.plus.com> northof40 wrote: > I'm using the subroutine module to run run python script A.py from > B.py (this is on windows fwiw). > > A.py is not my script and it may raise arbitary errors before exiting. > How can I determine what's happened before A.py exited ? > > To simulate this I've got this script (which is meant to simulate > A.py): > > class customError(Exception): > def __init__(self, value): > self.value = value > def __str__(self): > return repr(self.value) > > try: > raise customError(2*2) > except customError as e: > print 'Custom exception occurred, value:', e.value > > > I then run my A.py like this : > >>>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') >>>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') >>>> try: > ... pathtojob="python.exe A.py" > ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) > ... except: > ... print "bad stuff happened" > ... > > When I do this I the exception handler is not fired and the text > "Custom exception occurred, value: 4" ends up in the stdout file. > > I'd really like it to end up in stderr because then I could say > "anything in stderr ? then ignore the output and flag an error". > > I don't want to have to parse the stdout for error like messages and I > can't make changes to A.py. > > I'm sure there's a better way to do this - can anyone offer some > advice ? > > thanks > A.py is printing the error message. The 'print' statement prints to stdout unless you direct it elsewhere with '>>', for example: print >> my_file, 'message' If you don't want error messages to go to stdout, then don't print them to stdout, it's as simple as that! From python at mrabarnett.plus.com Fri Feb 19 22:17:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 03:17:09 +0000 Subject: the mystery of dirname() In-Reply-To: References: <4B7F5187.3060806@mrabarnett.plus.com> Message-ID: <4B7F5435.2020704@mrabarnett.plus.com> Shashwat Anand wrote: > But this is posixpath, right ? So '//x' like path will not occur as far > as I guess ? > Can you guarantee that? It's safer to just leave it as it is, just in case! :-) > On Sat, Feb 20, 2010 at 8:35 AM, MRAB > wrote: > > Shashwat Anand wrote: > > In the following code sample : > > def dirname(p): > > """Returns the directory component of a pathname""" > i = p.rfind('/') + 1 > > head = p[:i] > if head and head != '/'*len(head): > > head = head.rstrip('/') > > return head > > def dirname1(p): > i = p.rfind('/') + 1 > > head = p[:i] > if head != '/': > > return head.rstrip('/') return head > > if __name__ == "__main__": > p1 = '/Users/l0nwlf/Desktop' > > p2 = './' > p3 = '/' > p4 = '.' > > print dirname(p1), dirname1(p1) > > print dirname(p2), dirname1(p2) > > print dirname(p3), dirname1(p3) > > print dirname(p4), dirname1(p4) > > OUTPUT: > > /Users/l0nwlf /Users/l0nwlf > . . > / / > > dirname() is a function taken from /Lib/posixpath.py. However i > did not quite understood the usage of "if head and head != > '/'*len(head):" and replaced it with more obvious way in dirname1(). > > Am I right to do so ? Is dirname1() more pythonic ? Did I missed > any edge cases here ? > > What if the path is '//x'? The current dirname would return '//', > whereas dirname1 would return ''. > From anand.shashwat at gmail.com Fri Feb 19 22:21:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 08:51:00 +0530 Subject: the mystery of dirname() In-Reply-To: <4B7F5435.2020704@mrabarnett.plus.com> References: <4B7F5187.3060806@mrabarnett.plus.com> <4B7F5435.2020704@mrabarnett.plus.com> Message-ID: basically I infer that : dirname = path - basename, like for path = '//x', basename = x, hence dirname = '//' On Sat, Feb 20, 2010 at 8:47 AM, MRAB wrote: > Shashwat Anand wrote: > >> But this is posixpath, right ? So '//x' like path will not occur as far as >> I guess ? >> >> Can you guarantee that? It's safer to just leave it as it is, just in > case! :-) > > > On Sat, Feb 20, 2010 at 8:35 AM, MRAB > python at mrabarnett.plus.com>> wrote: >> >> Shashwat Anand wrote: >> >> In the following code sample : >> >> def dirname(p): >> >> """Returns the directory component of a pathname""" >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head and head != '/'*len(head): >> >> head = head.rstrip('/') >> >> return head >> >> def dirname1(p): >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head != '/': >> >> return head.rstrip('/') return head >> >> if __name__ == "__main__": >> p1 = '/Users/l0nwlf/Desktop' >> >> p2 = './' >> p3 = '/' >> p4 = '.' >> >> print dirname(p1), dirname1(p1) >> >> print dirname(p2), dirname1(p2) >> >> print dirname(p3), dirname1(p3) >> >> print dirname(p4), dirname1(p4) >> >> OUTPUT: >> >> /Users/l0nwlf /Users/l0nwlf >> . . >> / / >> >> dirname() is a function taken from /Lib/posixpath.py. However i >> did not quite understood the usage of "if head and head != >> '/'*len(head):" and replaced it with more obvious way in >> dirname1(). >> >> Am I right to do so ? Is dirname1() more pythonic ? Did I missed >> any edge cases here ? >> >> What if the path is '//x'? The current dirname would return '//', >> whereas dirname1 would return ''. >> >> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 22:33:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Feb 2010 03:33:57 GMT Subject: Avoid converting functions to methods in a class Message-ID: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> I have a convention when writing unit tests to put the target of the test into a class attribute, as follows: class MyTest(unittest.TestCase): target = mymodule.someclass def test_spam(self): """Test that someclass has a spam attribute.""" self.failUnless(hasattr(self.target, 'spam')) It works well until I write a test for stand-alone functions: class AnotherTest(unittest.TestCase): target = mymodule.function def test_foo(self): self.assertEquals(self.target('a', 'b'), 'foo') The problem is that target is turned into a method of my test class, not a standalone function, and I get errors like: TypeError: function() takes exactly 2 arguments (3 given) The solution I currently use is to drop the target attribute in this class, and just refer to mymodule.function in each individual test. I don't like this solution because it violates Once And Only Once: if the function changes name, I have to make many edits to the test suite rather than just one. Are there any better solutions? -- Steven From shearichard at gmail.com Fri Feb 19 22:39:23 2010 From: shearichard at gmail.com (northof40) Date: Fri, 19 Feb 2010 19:39:23 -0800 (PST) Subject: Capturing errors raised by other scripts ? References: Message-ID: On Feb 20, 4:13?pm, MRAB wrote: > northof40 wrote: > > I'm using the subroutine module to run run python script A.py from > > B.py (this is on windows fwiw). > > > A.py is not my script and it may raise arbitary errors before exiting. > > How can I determine what's happened before A.py exited ? > > > To simulate this I've got this script (which is meant to simulate > > A.py): > > > class customError(Exception): > > ? ?def __init__(self, value): > > ? ? ? ? ? ?self.value = value > > ? ?def __str__(self): > > ? ? ? ? ? ?return repr(self.value) > > > try: > > ? ?raise customError(2*2) > > except customError as e: > > ? ?print 'Custom exception occurred, value:', e.value > > > I then run my A.py like this : > > >>>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') > >>>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') > >>>> try: > > ... ? ? pathtojob="python.exe A.py" > > ... ? ? p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) > > ... except: > > ... ? ? print "bad stuff happened" > > ... > > > When I do this I the exception handler is not fired and the text > > "Custom exception occurred, value: 4" ends up in the stdout file. > > > I'd really like it to end up in stderr because then I could say > > "anything in stderr ? then ignore the output and flag an error". > > > I don't want to have to parse the stdout for error like messages and I > > can't make changes to A.py. > > > I'm sure there's a better way to do this - can anyone offer some > > advice ? > > > thanks > > A.py is printing the error message. > > The 'print' statement prints to stdout unless you direct it elsewhere > with '>>', for example: > > ? ? ?print >> my_file, 'message' > > If you don't want error messages to go to stdout, then don't print them > to stdout, it's as simple as that! Thanks for your reply. I take your point about print - perhaps I hadn't really thought that through. Unfortunately I don't have control of the real script that's being run so if the programmer of that script has used print there's nothing I can do about it. Perhaps I could modify the question. If A.py terminates due an unhandled exception is there anyway for B.py to know that's happened (without A.py's cooperation ?). thanks Richard. If A.py terminates due to an unhandled exception From sccolbert at gmail.com Fri Feb 19 23:18:12 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 19 Feb 2010 23:18:12 -0500 Subject: Avoid converting functions to methods in a class In-Reply-To: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7f014ea61002192018n6547a63ete67d99ab1f59a724@mail.gmail.com> this is somewhat hackish: In [1]: def test(): ...: print 'spam' ...: ...: In [20]: class Ham(): ....: target = {'target': test} ....: def test_eggs(self): ....: self.target['target']() ....: ....: In [21]: h = Ham() In [22]: h.test_eggs() spam On Fri, Feb 19, 2010 at 10:33 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. > > Are there any better solutions? > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Fri Feb 19 23:37:56 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 20 Feb 2010 15:37:56 +1100 Subject: Trouble running pywin32-214.win-amd64-py3.1 on 64-bit Windows 7 In-Reply-To: <5cf1aff91002191035o7c65df3bjfb4f26805923ea0d@mail.gmail.com> References: <5cf1aff91002191035o7c65df3bjfb4f26805923ea0d@mail.gmail.com> Message-ID: <4B7F6724.5070505@gmail.com> On 20/02/2010 5:35 AM, Steven Cohen wrote: > Hello, > > I downloaded pywin32-214.win-amd64-py3.1, and it installs just fine > (except that it prints a traceback when it tells me the postinstall > script completed), but then when I try to execute Pythonwin.exe, I get > the following error popup: > > The application can not locate win32ui.pyd (or Python) (126) > The specified module could not be found > > However, the file win32ui.pyd is right there in the same directory from > which I am executing Pythonwin.exe. Can anyone help me figure out what > I am doing wrong here? The pywin32 post-install script seems to break with the current Python 3.1 builds, and as a result, the pywin32 DLLs were probably not copied correctly. Try re-executing the post install script by: * Start a command-prompt by right-clicking on the shortcut and selecting 'Run as Administrator'. * Execute '\python31\python.exe \python31\scripts\pywin32_postinstall.py -install' (changing the paths as necessary). It should succeed as it is running from a console, and you might find that fixes things. HTH, Mark From cmpython at gmail.com Fri Feb 19 23:55:15 2010 From: cmpython at gmail.com (CM) Date: Fri, 19 Feb 2010 20:55:15 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: <65accaff-ab29-4dd4-9995-4ec60a034b56@y33g2000yqb.googlegroups.com> On Feb 19, 4:28?pm, Ryan Kelly wrote: > On Thu, 2010-02-18 at 20:32 -0800, CM wrote: > > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > > I have a Python app which I converted to an EXE (all files separate; > > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > > this and would like the ability to remotely upgrade the program (for > > > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > > you might find it useful: > > > > ?http://pypi.python.org/pypi/esky > > > This looks pretty interesting and useful. > > Thanks :-) > > > Just to help me understand it a bit more: ?what is it that users will > > download from some web page in order to initially get the py2exe'd app > > on their system? ?Is it "really" an "esky", with the app's .exe file > > inside it (but the esky is named the same as the app)? > > Currently, it's just a zip file with the frozen app in it, which the > user unzips to wherever they want the app. ?When unzipped it looks like > this: > > ? ?myapp.exe ?<-- actually the esky bootstrap exe > ? ?myapp-X.Y.Z.win32/ > ? ? ? ?myapp.exe ?<-- the actual frozen app as produced by py2exe > ? ? ? ?python26.dll > ? ? ? ?...etc... > > This could easily be wrapped in an installer - the important thing is > just that the files end up on the user's machine in the expected > directory structure. > > > ? And then when > > they want to update, the app's code calls the esky class to do the > > work of swapping out the appropriate .exe file? ?Something like this? > > Yes. ?The idea of having a "bootstrapping exe" is that actual > application code can be swapped out without having to overwrite the > executable file. ?As long as you don't change python versions, this > allows updates to be safe against system crashes, even on platforms > without atomic file replacement. > > So the frozen app does this in a background thread: > > ? ?Esky(sys.executable,"http://my.updates.com").auto_update() > > And it hits the given url, grabs the latest zipfile, downloads and > unpacks and atomically places it into the application directory. ?Et > viola, your app is at the latest version. > > From the packager's point of view, you run the "bdist_esky" distutils > command to generate the zipfile containing your latest version, then > simply upload it to your server. > > > Would this also work if one used InnoSetup to install the exe on the > > user's system? > > Yes, absolutely - in fact I plan to do this myself at some stage. ?All > that's required is that the files end up in the expected directory > structure. > > ? ?Ryan Wow, it sounds great. Good luck with moving forward with it. I'm not quite ready to release any apps, but as (if?) I come up on that, and if I plan on updating them, I would love to make use of Esky. Thanks for doing this. :D Che From ben+python at benfinney.id.au Fri Feb 19 23:55:56 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Feb 2010 15:55:56 +1100 Subject: Avoid converting functions to methods in a class References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: <87r5og8q03.fsf@benfinney.id.au> Steven D'Aprano writes: > I have a convention when writing unit tests Incidentally, you may be interested in the specific forum for testing in Python that is a good resource for asking questions like this. > to put the target of the test into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') I think this is because you're binding the ?target? attribute at the class definition, binding it to that class. Instead, this smells like something that should be a fixture for each test case:: class SomeClassTestCase(unittest.TestCase): def setUp(self): """ Set up test fixtures. """ self.target = mymodule.SomeClass def test_has_spam(self): """ Should have a spam attribute. """ self.failUnless(hasattr(self.target, 'spam')) def test_has_no_bacon(self): """ Should not have a bacon attribute. """ self.failIf(hasattr(self.target, 'bacon')) class SomeFunctionTest(unittest.TestCase): def setUp(self): """ Set up test fixtures. """ self.target = mymodule.some_function def test_a_b_input_returns_foo(self): """ Should return 'foo' from 'a', 'b' inputs. """ self.assertEquals(self.target('a', 'b'), 'foo') def test_c_d_input_raises_valueerror(self): """ Should raise ValueError from 'c', 'd' inputs. """ self.assertRaises( ValueError, self.target, 'c', 'd') -- \ ?A free press is one where it's okay to state the conclusion | `\ you're led to by the evidence.? ?Bill Moyers | _o__) | Ben Finney From cmpython at gmail.com Fri Feb 19 23:59:55 2010 From: cmpython at gmail.com (CM) Date: Fri, 19 Feb 2010 20:59:55 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On Feb 19, 4:42?pm, "W. eWatson" wrote: > On 2/19/2010 10:56 AM, CM wrote: > > > On Feb 19, 12:21 pm, "W. eWatson" ?wrote: > >> On 2/19/2010 7:16 AM, Mark Lawrence wrote:> ?Andre Engels wrote: > >>>> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence > >>>> ?wrote: > >>>>> Andre Engels wrote: > >>>>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson > > >> ... > >> tories, or even the whole hard drive, for snowball.*. Then the OP> ?would know exactly what he has or hasn't got. > > >>> HTH. > > >>> Mark Lawrence > > >> Here's the answer. Consider this folder. > > >> Afolder > >> ? ? abc.py > >> ? ? hello.py > > >> I now apply py2exe steps to produce an ?"executable" for abc. The folder > >> now changes to > > >> Afolder > >> ? ? build > >> ? ? dist > >> ? ? abc.py > >> ? ? hello.py > > >> build are two new folders. dist contains abc.exe. > > >> Somehow when I type abc at the command prompt, this follows a path to > >> dist, and finds abc.exe, where it executes properly. > >> Cute, eh? I have no explanation for it. > > > Are you sure it's executing abc.exe? ?If you are at a Python command > > prompt within the "DOS shell" and you just type just abc, I think what > > is happening is you are running abc.py, NOT abc.exe. > > > py2exe creates a dist folder (short for "distributables") by default > > and puts your .exe into it along with whatever other files are needed > > to run your application. ?Depending on how you set the bundling > > options, this may be a lot of things or just 1-2 other things. > > > Che > > Well, you are right. What proof do I have? In fact, I just tried to run > a program that was not converted, and left off py. It worked. > > So maybe the only way to execute the compiled code is to to to dist? Not sure about that last question, but just try double-clicking on the .exe file in dist and your app should run. In fact, copy that dist folder to a flash drive, plug it into another computer that doesn't have Python installed on it, and doubleclick it again--it'll run again. In fact, depending on how you bundled it, you might need only the .exe file on many computers that have the Windows dlls already available. Che From wuwei23 at gmail.com Sat Feb 20 00:26:46 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 19 Feb 2010 21:26:46 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: <17d79b9e-0f06-4885-bb52-9cc06312f403@f17g2000prh.googlegroups.com> "W. eWatson" wrote: > So maybe the only way to execute the compiled code is to [g]o to dist? Or the compiled code needs to be in a folder that's higher in your path settings than the python file. But yes, moving into the dist directory, or running 'dist/snowball' from the project root will do the trick. From wuwei23 at gmail.com Sat Feb 20 00:38:31 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 19 Feb 2010 21:38:31 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> <17d79b9e-0f06-4885-bb52-9cc06312f403@f17g2000prh.googlegroups.com> Message-ID: <85adff5e-fc5e-4296-9408-b44f4b3dc207@z10g2000prh.googlegroups.com> On Feb 20, 3:26?pm, alex23 wrote: > or running 'dist/snowball' That should, of course, be: 'dist\snowball' :) From keekychen at gmail.com Sat Feb 20 00:38:47 2010 From: keekychen at gmail.com (Kee K Y CHEN) Date: Sat, 20 Feb 2010 13:38:47 +0800 Subject: Can I embedding a (python) console on python program? Message-ID: <1266644327.7846.21.camel@linux> HI All, Apologize for being a newbie to python area and sorry for my English. Actually what I need is embedding a python interactive console(or other shell console alike module) on my python program for debugging and controlling purpose during the program runtime. For example, print/set some important value, query some runtime status when I remote login to host via telnet/ssh when the program running on the host. One of the idea is I can write the program use the GUI tech, but that is not fit for someone use a text based session. In summary, in my scheme, it should something looks like the GEdit extension - python console and but may interactive with tty/vty lines. Can anyone give a brief to me? Thanks in advance. -- Kee K Y CHEN From anand.shashwat at gmail.com Sat Feb 20 00:53:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 11:23:00 +0530 Subject: Can I embedding a (python) console on python program? In-Reply-To: <1266644327.7846.21.camel@linux> References: <1266644327.7846.21.camel@linux> Message-ID: I am not sure what you are looking for, but you can try looking at 'cmd module' ~l0nwlf On Sat, Feb 20, 2010 at 11:08 AM, Kee K Y CHEN wrote: > HI All, > > Apologize for being a newbie to python area and sorry for my English. > > Actually what I need is embedding a python interactive console(or other > shell console alike module) on my python program for debugging and > controlling purpose during the program runtime. > > For example, print/set some important value, query some runtime status > when I remote login to host via telnet/ssh when the program running on > the host. One of the idea is I can write the program use the GUI tech, > but that is not fit for someone use a text based session. > > In summary, in my scheme, it should something looks like the GEdit > extension - python console and but may interactive with tty/vty lines. > > Can anyone give a brief to me? > > Thanks in advance. > > -- > Kee K Y CHEN > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Sat Feb 20 01:28:17 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Feb 2010 19:28:17 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> <87eikjcuzk.fsf@benfinney.id.au> Message-ID: In message <87eikjcuzk.fsf at benfinney.id.au>, Ben Finney wrote: > Lawrence D'Oliveiro writes: > >> In message , cjw wrote: >> >> > Aren't lambda forms better described as function? >> >> Is this a function? >> >> lambda : None >> >> What about this? >> >> lambda : sys.stdout.write("hi there!\n") > > They are both lambda forms in Python. As a Python expression, they > evaluate to (they ?return?) a function object. So there is no distinction between functions and procedures, then? From ldo at geek-central.gen.new_zealand Sat Feb 20 01:29:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Feb 2010 19:29:20 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> Message-ID: In message <84166541-c10a-47b5-ae5b- b232026241c6 at q2g2000pre.googlegroups.com>, Steve Howell wrote: > Some people make the definition of function more restrictive--"if it > has side effects, it is not a function." Does changing the contents of CPU cache count as a side-effect? From ldo at geek-central.gen.new_zealand Sat Feb 20 01:30:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Feb 2010 19:30:26 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: In message , Rhodri James wrote: > In classic Pascal, a procedure was distinct from a function in that it had > no return value. The concept doesn't really apply in Python; there are no > procedures in that sense, since if a function terminates without supplying > an explicit return value it returns None. If Python doesn?t distinguish between procedures and functions, why should it distinguish between statements and expressions? From krishna.k.0001 at gmail.com Sat Feb 20 01:36:28 2010 From: krishna.k.0001 at gmail.com (krishna) Date: Fri, 19 Feb 2010 22:36:28 -0800 (PST) Subject: Scalable python dict {'key_is_a_string': [count, some_val]} Message-ID: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> I have to manage a couple of dicts with huge dataset (larger than feasible with the memory on my system), it basically has a key which is a string (actually a tuple converted to a string) and a two item list as value, with one element in the list being a count related to the key. I have to at the end sort this dictionary by the count. The platform is linux. I am planning to implement it by setting a threshold beyond which I write the data into files (3 columns: 'key count some_val' ) and later merge those files (I plan to sort the individual files by the key column and walk through the files with one pointer per file and merge them; I would add up the counts when entries from two files match by key) and sorting using the 'sort' command. Thus the bottleneck is the 'sort' command. Any suggestions, comments? By the way, is there a linux command that does the merging part? Thanks, Krishna From no.email at nospam.invalid Sat Feb 20 01:47:41 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 19 Feb 2010 22:47:41 -0800 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> Message-ID: <7xzl34pfn6.fsf@ruckus.brouhaha.com> krishna writes: > entries from two files match by key) and sorting using the 'sort' > command. Thus the bottleneck is the 'sort' command. That is a good approach. The sort command is highly optimized and will beat any Python program that does something comparable. Set LC_ALL=C if the file is all ascii, since that will bypass a lot of slow Unicode conversion and make sorting go even faster. > By the way, is there a linux command that does the merging part? sort -m Note that the sort command already does external sorting, so if you can just write out one large file and sort it, instead of sorting and then merging a bunch of smaller files, that may simplify your task. From ben+python at benfinney.id.au Sat Feb 20 02:02:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Feb 2010 18:02:18 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> <87eikjcuzk.fsf@benfinney.id.au> Message-ID: <87eikg8k5h.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > So there is no distinction between functions and procedures, then? In Python, no. -- \ ?When we pray to God we must be seeking nothing ? nothing.? | `\ ?Saint Francis of Assisi | _o__) | Ben Finney From lie.1296 at gmail.com Sat Feb 20 02:02:41 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:02:41 +1100 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: <4b7f892c$1@dnews.tpgi.com.au> On 02/20/10 13:32, MattB wrote: > > I'm using the network in my own apartment. Not the campus's. > Moreover, my mac's MAC address is different from the MAC address shown > by my router, but as I said I'm also blocked when using my friend's > wireless router at his apartment. > > So it must be my mac's MAC, and not the router's MAC, that's being > blocked, right? > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > school), since I can't raise ANY url's from python when I'm on > wireless? MAC or IP blocking can't be the reason, as the OP stated, he can use Firefox just fine. Can you access, say, http://www.google.com from urllib or mechanize? If you can't access *any website* using urllib/mechanize but you can with a browser and you're on a unix-based machine, you probably have the same problem as I used to have. Check whether you used the same hostname in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves its hostname configurations, I use Gentoo); after editing those files reboot (there are ways to avoid reboot, but rebooting guarantees the conf file is reread). Check the hostname by running this python script: import socket hn = socket.gethostname() print hn print socket.gethostbyname(hn) # should be 127.0.0.1 From ben+python at benfinney.id.au Sat Feb 20 02:04:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Feb 2010 18:04:00 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <87aav48k2n.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > If Python doesn?t distinguish between procedures and functions, why > should it distinguish between statements and expressions? I don't see the connection between those two predicates. Why does the former matter when determining the ?should? of the latter? -- \ ?Pinky, are you pondering what I'm pondering?? ?Wuh, I think | `\ so, Brain, but wouldn't anything lose its flavor on the bedpost | _o__) overnight?? ?_Pinky and The Brain_ | Ben Finney From steve at holdenweb.com Sat Feb 20 02:12:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 20 Feb 2010 02:12:55 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <87aav48k2n.fsf@benfinney.id.au> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <87aav48k2n.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Lawrence D'Oliveiro writes: > >> If Python doesn?t distinguish between procedures and functions, why >> should it distinguish between statements and expressions? > > I don't see the connection between those two predicates. Why does the > former matter when determining the ?should? of the latter? > Because s similar dichotomy exists between the two pairs. Procedure <= function not returning a value Statement <= expression not returning a value regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From sjdevnull at yahoo.com Sat Feb 20 02:13:36 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Fri, 19 Feb 2010 23:13:36 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> <87eikjcuzk.fsf@benfinney.id.au> Message-ID: On Feb 20, 1:28?am, Lawrence D'Oliveiro wrote: > In message <87eikjcuzk.... at benfinney.id.au>, Ben Finney wrote: > > > > > Lawrence D'Oliveiro writes: > > >> In message , cjw wrote: > > >> > Aren't lambda forms better described as function? > > >> Is this a function? > > >> ? ? lambda : None > > >> What about this? > > >> ? ? lambda : sys.stdout.write("hi there!\n") > > > They are both lambda forms in Python. As a Python expression, they > > evaluate to (they ?return?) a function object. > > So there is no distinction between functions and procedures, then? Not in most modern languages, no. i think the major places they are differentiated are in functional languages and in pre-1993ish languages (give or take a few years), neither of which applies to Python or Ruby. From lie.1296 at gmail.com Sat Feb 20 02:16:02 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:16:02 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <4b7f8c4d$1@dnews.tpgi.com.au> On 02/20/10 17:30, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > >> In classic Pascal, a procedure was distinct from a function in that it had >> no return value. The concept doesn't really apply in Python; there are no >> procedures in that sense, since if a function terminates without supplying >> an explicit return value it returns None. > > If Python doesn?t distinguish between procedures and functions, why should > it distinguish between statements and expressions? There are non-trivial languages that have been made without procedures and statements and non-trivial programs written on those languages. There is technically no need for a lambda that supports statements; someone could simply write a full-blown Monad framework and all of the things required for IO Monad and all their syntax sugars up to near a level of Haskell. Then we can do away with 'def's and all the statements or make them syntax sugar for the Monads. Now, why don't we start a PEP to make python a fully-functional language then? From stefan_ml at behnel.de Sat Feb 20 02:16:40 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Feb 2010 08:16:40 +0100 Subject: Executing Python code on another computer In-Reply-To: <4B7EE0B0.5080605@ieee.org> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> <4B7EE0B0.5080605@ieee.org> Message-ID: Dave Angel, 19.02.2010 20:04: > In that case, consider using RemoveDesktop, which is built into both Xp > and Vista. Careful, sounds like malware to me. Stefan From sjdevnull at yahoo.com Sat Feb 20 02:17:10 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Fri, 19 Feb 2010 23:17:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> On Feb 20, 1:30?am, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > > > In classic Pascal, a procedure was distinct from a function in that it had > > no return value. ?The concept doesn't really apply in Python; there are no > > procedures in that sense, since if a function terminates without supplying > > an explicit return value it returns None. > > If Python doesn?t distinguish between procedures and functions, why should > it distinguish between statements and expressions? Because the latter are different in Python (and in Ruby, and in most modern languages), while the former aren't distinguished in Python or Ruby or most modern languages? Primarily functional languages are the main exception, but other than them it's pretty uncommon to find any modern language that does distinguish procedures and functions, or one that doesn't distinguished statements and expressions. You can certainly find exceptions, but distinguishing statements and expressions is absolutely commonplace in modern languages, and distinguishing functions and procedures is in the minority. From lie.1296 at gmail.com Sat Feb 20 02:24:13 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:24:13 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> Message-ID: <4b7f8e38$1@dnews.tpgi.com.au> On 02/20/10 18:17, sjdevnull at yahoo.com wrote: > On Feb 20, 1:30 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Rhodri James wrote: >> >>> In classic Pascal, a procedure was distinct from a function in that it had >>> no return value. The concept doesn't really apply in Python; there are no >>> procedures in that sense, since if a function terminates without supplying >>> an explicit return value it returns None. >> >> If Python doesn?t distinguish between procedures and functions, why should >> it distinguish between statements and expressions? > > Because the latter are different in Python (and in Ruby, and in most > modern languages), while the former aren't distinguished in Python or > Ruby or most modern languages? Primarily functional languages are the > main exception, but other than them it's pretty uncommon to find any > modern language that does distinguish procedures and functions, or one > that doesn't distinguished statements and expressions. > > You can certainly find exceptions, but distinguishing statements and > expressions is absolutely commonplace in modern languages, and > distinguishing functions and procedures is in the minority. But it all boils down to "Although practicality beats purity." From jgardner at jonathangardner.net Sat Feb 20 02:27:56 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 23:27:56 -0800 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} In-Reply-To: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> Message-ID: <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> On Fri, Feb 19, 2010 at 10:36 PM, krishna wrote: > I have to manage a couple of dicts with huge dataset (larger than > feasible with the memory on my system), it basically has a key which > is a string (actually a tuple converted to a string) and a two item > list as value, with one element in the list being a count related to > the key. I have to at the end sort this dictionary by the count. > > The platform is linux. I am planning to implement it by setting a > threshold beyond which I write the data into files (3 columns: 'key > count some_val' ) and later merge those files (I plan to sort the > individual files by the key column and walk through the files with one > pointer per file and merge them; I would add up the counts when > entries from two files match by key) and sorting using the 'sort' > command. Thus the bottleneck is the 'sort' command. > > Any suggestions, comments? > You should be using BDBs or even something like PostgreSQL. The indexes there will give you the scalability you need. I doubt you will be able to write anything that will select, update, insert or delete data better than what BDBs and PostgreSQL can give you. -- Jonathan Gardner jgardner at jonathangardner.net From pavlovevidence at gmail.com Sat Feb 20 02:30:21 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Feb 2010 23:30:21 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <827dad76-528c-4ae5-9935-88ac35a211a3@z10g2000prh.googlegroups.com> On Feb 19, 10:30?pm, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > > > In classic Pascal, a procedure was distinct from a function in that it had > > no return value. ?The concept doesn't really apply in Python; there are no > > procedures in that sense, since if a function terminates without supplying > > an explicit return value it returns None. > > If Python doesn?t distinguish between procedures and functions, why should > it distinguish between statements and expressions? Because the real world works is more complex than simplified one- sentence generalizations. Carl Bnkas From lie.1296 at gmail.com Sat Feb 20 02:33:30 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:33:30 +1100 Subject: Can I embedding a (python) console on python program? In-Reply-To: <1266644327.7846.21.camel@linux> References: <1266644327.7846.21.camel@linux> Message-ID: <4b7f9065$1@dnews.tpgi.com.au> On 02/20/10 16:38, Kee K Y CHEN wrote: > HI All, > > Apologize for being a newbie to python area and sorry for my English. > > Actually what I need is embedding a python interactive console(or other > shell console alike module) on my python program for debugging and > controlling purpose during the program runtime. > > For example, print/set some important value, query some runtime status > when I remote login to host via telnet/ssh when the program running on > the host. One of the idea is I can write the program use the GUI tech, > but that is not fit for someone use a text based session. > > In summary, in my scheme, it should something looks like the GEdit > extension - python console and but may interactive with tty/vty lines. > > Can anyone give a brief to me? > > Thanks in advance. Look how IDLE and pdb does it. I believe the `cmd` built-in module is specifically written for this case. From pavlovevidence at gmail.com Sat Feb 20 02:36:10 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Feb 2010 23:36:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <87aav48k2n.fsf@benfinney.id.au> Message-ID: On Feb 19, 11:12?pm, Steve Holden wrote: > Ben Finney wrote: > > Lawrence D'Oliveiro writes: > > >> If Python doesn?t distinguish between procedures and functions, why > >> should it distinguish between statements and expressions? > > > I don't see the connection between those two predicates. Why does the > > former matter when determining the ?should? of the latter? > > Because s similar dichotomy exists between the two pairs. > > Procedure <= function not returning a value > Statement <= expression not returning a value So if your language distinguishes between procedures and functions, it manifestly has to distinguish between statements and expressions, but there's no reason that the converse has to be true, expecially if an expression is a legal statement. Carl Banks From jgardner at jonathangardner.net Sat Feb 20 02:53:55 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 23:53:55 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <4b7f8c4d$1@dnews.tpgi.com.au> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> Message-ID: <6cc20cea1002192353g5dec316flf34c8aaf14befe88@mail.gmail.com> On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: > > Now, why don't we start a PEP to make python a fully-functional language > then? > Because people don't think the same way that programs are written in functional languages. -- Jonathan Gardner jgardner at jonathangardner.net From lie.1296 at gmail.com Sat Feb 20 03:04:22 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 19:04:22 +1100 Subject: Capturing errors raised by other scripts ? In-Reply-To: References: Message-ID: <4b7f97a1$1@dnews.tpgi.com.au> On 02/20/10 14:39, northof40 wrote: > On Feb 20, 4:13 pm, MRAB wrote: >> northof40 wrote: >>> I'm using the subroutine module to run run python script A.py from >>> B.py (this is on windows fwiw). >> >>> A.py is not my script and it may raise arbitary errors before exiting. >>> How can I determine what's happened before A.py exited ? >> >>> To simulate this I've got this script (which is meant to simulate >>> A.py): >> >>> class customError(Exception): >>> def __init__(self, value): >>> self.value = value >>> def __str__(self): >>> return repr(self.value) >> >>> try: >>> raise customError(2*2) >>> except customError as e: >>> print 'Custom exception occurred, value:', e.value >> >>> I then run my A.py like this : >> >>>>>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') >>>>>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') >>>>>> try: >>> ... pathtojob="python.exe A.py" >>> ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) >>> ... except: >>> ... print "bad stuff happened" >>> ... >> >>> When I do this I the exception handler is not fired and the text >>> "Custom exception occurred, value: 4" ends up in the stdout file. >>> I'd really like it to end up in stderr because then I could say >>> "anything in stderr ? then ignore the output and flag an error". Not really; not all that is written to stderr signifies errors per se. Warning and Debugging info are often written to stderr as well. > Thanks for your reply. I take your point about print - perhaps I > hadn't really thought that through. Unfortunately I don't have control > of the real script that's being run so if the programmer of that > script has used print there's nothing I can do about it. Tracebacks is almost always written to stderr, not stdout; unless the programmer explicitly redirect the traceback into stdout. > Perhaps I could modify the question. If A.py terminates due an > unhandled exception is there anyway for B.py to know that's happened > (without A.py's cooperation ?). A well-behaved program will exit with status code 0; if and only if it exited cleanly. I believe a python program that exited due to unhandled exception always return non-zero status code. However, if the program handled an error and called exit(0) explicitly or the execution of the program falls to the end of the module; there is no way to distinguish it from regular clean exit. From pavlovevidence at gmail.com Sat Feb 20 03:12:48 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 00:12:48 -0800 (PST) Subject: Shared web host good citizenship question Message-ID: Not specifically Python related but thought I'd ask. If you have a low-bandwidth website running on a shared web hosting service as a WSGI server (or FastCGI, or any other interface with its own process), is it considered a responsible thing for the process to exit on its own after a period of non-activity, or is that something best left for the host to manage? I'd guess that modern web hosts would prefer that processes stay running, even if they go long periods without use, rather than having to periodically restart processes. Carl Banks From mattbarkan at gmail.com Sat Feb 20 03:36:15 2010 From: mattbarkan at gmail.com (MattB) Date: Sat, 20 Feb 2010 00:36:15 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> <4b7f892c$1@dnews.tpgi.com.au> Message-ID: <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> On Feb 20, 2:02?am, Lie Ryan wrote: > On 02/20/10 13:32, MattB wrote: > > > > > I'm using the network in my own apartment. Not the campus's. > > Moreover, my mac's MAC address is different from the MAC address shown > > by my router, but as I said I'm also blocked when using my friend's > > wireless router at his apartment. > > > So it must be my mac's MAC, and not the router's MAC, that's being > > blocked, right? > > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > > school), since I can't raise ANY url's from python when I'm on > > wireless? > > MAC or IP blocking can't be the reason, as the OP stated, he can use > Firefox just fine. > > Can you access, say,http://www.google.comfrom urllib or mechanize? > > If you can't access *any website* using urllib/mechanize but you can > with a browser and you're on a unix-based machine, you probably have the > same problem as I used to have. Check whether you used the same hostname > in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves > its hostname configurations, I use Gentoo); after editing those files > reboot (there are ways to avoid reboot, but rebooting guarantees the > conf file is reread). > > Check the hostname by running this python script: > > import socket > hn = socket.gethostname() > print hn > print socket.gethostbyname(hn) # should be 127.0.0.1 Lie, Wow. Strangely, that script returned 192.168.1.106. However, in Snow Leopard's airport settings, if I click on 'advanced' and then 'proxies', the default proxy for 'http' is 127.0.0.1:4444 (and in these settings, the 'use proxy for http' is checked). I just tried checking the unix files you mentioned. In etc/hosts, the following info is displayed: ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost Also found a file called ntp-restrict.conf, containing: # Access restrictions documented in ntp.conf(5) and # http://support.ntp.org/bin/view/Support/AccessRestrictions # Limit network machines to time queries only restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery # localhost is unrestricted restrict 127.0.0.1 restrict -6 ::1 includefile /private/etc/ntp.conf Not sure if these are what I'm looking for -- I'm new to unix so I may need a bit more hand-holding here. I appreciate your time and effort. Matt From clp2 at rebertia.com Sat Feb 20 03:44:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Feb 2010 00:44:10 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> Message-ID: <50697b2c1002200044o263a1bd0wd53d364b3fb49ccb@mail.gmail.com> On Fri, Feb 19, 2010 at 11:17 PM, sjdevnull at yahoo.com wrote: > On Feb 20, 1:30?am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> If Python doesn?t distinguish between procedures and functions, why should >> it distinguish between statements and expressions? > > Because the latter are different in Python (and in Ruby I think your Ruby assertion needs fact-checking: irb(main):001:0> a = 7 # assignments have a value => 7 irb(main):002:0> puts(b = 42) # as further proof 42 => nil irb(main):003:0> b => 42 irb(main):004:0> c = [6,4,5] => [6, 4, 5] irb(main):005:0> if false irb(main):006:1> c.reverse! irb(main):007:1> else irb(main):008:1* c.sort! irb(main):009:1> end # even the if-else control structure has a value => [4, 5, 6] irb(main):010:0> begin # same with exception handling irb(main):011:1* raise "a runtime error" irb(main):012:1> rescue RuntimeError irb(main):013:1> "sounds bad" irb(main):014:1> end => "sounds bad" irb(main):015:0> def foo # and same with method bodies irb(main):016:1> 99 irb(main):017:1> end => nil irb(main):018:0> foo => 99 Quoth Wikipedia regarding Ruby (programming language): "For practical purposes there is no distinction between expressions and statements" Cheers, Chris -- http://blog.rebertia.com From anand.shashwat at gmail.com Sat Feb 20 03:59:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 14:29:12 +0530 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> <4b7f892c$1@dnews.tpgi.com.au> <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> Message-ID: throw up your 'ifconfig' and mozilla-proxy output here. It seems you don't know whether you are using proxy. For mozilla proxy : open mozilla -> cmd + "," -> Network -> Settings -> Paste everything that is there/ may be take a snapshot and upload a link. ~l0nwlf On Sat, Feb 20, 2010 at 2:06 PM, MattB wrote: > On Feb 20, 2:02 am, Lie Ryan wrote: > > On 02/20/10 13:32, MattB wrote: > > > > > > > > > I'm using the network in my own apartment. Not the campus's. > > > Moreover, my mac's MAC address is different from the MAC address shown > > > by my router, but as I said I'm also blocked when using my friend's > > > wireless router at his apartment. > > > > > So it must be my mac's MAC, and not the router's MAC, that's being > > > blocked, right? > > > > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > > > school), since I can't raise ANY url's from python when I'm on > > > wireless? > > > > MAC or IP blocking can't be the reason, as the OP stated, he can use > > Firefox just fine. > > > > Can you access, say,http://www.google.comfrom urllib or mechanize? > > > > If you can't access *any website* using urllib/mechanize but you can > > with a browser and you're on a unix-based machine, you probably have the > > same problem as I used to have. Check whether you used the same hostname > > in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves > > its hostname configurations, I use Gentoo); after editing those files > > reboot (there are ways to avoid reboot, but rebooting guarantees the > > conf file is reread). > > > > Check the hostname by running this python script: > > > > import socket > > hn = socket.gethostname() > > print hn > > print socket.gethostbyname(hn) # should be 127.0.0.1 > > Lie, > > Wow. Strangely, that script returned 192.168.1.106. However, in Snow > Leopard's airport settings, if I click on 'advanced' and then > 'proxies', the default proxy for 'http' is 127.0.0.1:4444 (and in > these settings, the 'use proxy for http' is checked). > > I just tried checking the unix files you mentioned. In etc/hosts, the > following info is displayed: > > ## > # Host Database > # > # localhost is used to configure the loopback interface > # when the system is booting. Do not change this entry. > ## > > > 127.0.0.1 localhost > 255.255.255.255 broadcasthost > ::1 localhost > fe80::1%lo0 localhost > > Also found a file called ntp-restrict.conf, containing: > > # Access restrictions documented in ntp.conf(5) and > # http://support.ntp.org/bin/view/Support/AccessRestrictions > # Limit network machines to time queries only > > restrict default kod nomodify notrap nopeer noquery > restrict -6 default kod nomodify notrap nopeer noquery > > # localhost is unrestricted > restrict 127.0.0.1 > restrict -6 ::1 > > includefile /private/etc/ntp.conf > > Not sure if these are what I'm looking for -- I'm new to unix so I may > need a bit more hand-holding here. > > I appreciate your time and effort. > > Matt > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastian.noack at googlemail.com Sat Feb 20 05:36:04 2010 From: sebastian.noack at googlemail.com (Sebastian Noack) Date: Sat, 20 Feb 2010 11:36:04 +0100 Subject: os.pipe() + os.fork() Message-ID: <20100220113604.49b7c242@gurka> Hi, I have a problem using os.pipe() together with os.fork(). Usually when the writing end of the pipe is closed, the reading end gets EOF. So subsequent attempts to read data will return an empty string. But when you call os.fork() after you have created a pipe using os.pipe(), and read data from the pipe in the child process, when the partent process has already closed the writing end, the reading end does not get EOF. Instead of the os.read() call in the child process is blocking. I am using Linux, so I would like to know if this is a bug in Python or just weird behaviour under Linux and if it is possible work around it. Regards Sebastian Noack --------------------------------------------------------------------------- import os def test_pipe_sync(): pipe = os.pipe() os.write(pipe[1], 'Spam') os.close(pipe[1]) print repr(os.read(pipe[0], 4)) # 'Spam' is printed. print repr(os.read(pipe[0], 4)) # '' is printed, because of EOF is reached. def test_pipe_forked(): pipe = os.pipe() pid = os.fork() if pid: os.write(pipe[1], 'Spam') os.close(pipe[1]) os.waitpid(pid, 0) else: print repr(os.read(pipe[0], 4)) # 'Spam' is printed. print repr(os.read(pipe[0], 4)) # Nothing is printed and os.read() # is blocking, eventhough the other # end of the pipe was closed. if __name__ == '__main__': test_pipe_sync() print print '-' * 80 print test_pipe_forked() -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From arnodel at googlemail.com Sat Feb 20 06:00:34 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 20 Feb 2010 03:00:34 -0800 (PST) Subject: Avoid converting functions to methods in a class References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 20 Feb, 03:33, Steven D'Aprano wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > ? ? target = mymodule.someclass > > ? ? def test_spam(self): > ? ? ? ? """Test that someclass has a spam attribute.""" > ? ? ? ? self.failUnless(hasattr(self.target, 'spam')) > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > ? ? target = mymodule.function > > ? ? def test_foo(self): > ? ? ? ? self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. > > Are there any better solutions? > > -- > Steven Why not define target in the TestCase.setUp() method? class AnotherTest(unittest.TestCase): def setUp(self): self.target = mymodule.function def test_foo(self): self.assertEquals(self.target('a', 'b'), 'foo') -- Arnaud class -- Arnaud From arnodel at googlemail.com Sat Feb 20 06:03:47 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 20 Feb 2010 03:03:47 -0800 (PST) Subject: Scalable python dict {'key_is_a_string': [count, some_val]} References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> Message-ID: On 20 Feb, 06:36, krishna wrote: > I have to manage a couple of dicts with huge dataset (larger than > feasible with the memory on my system), it basically has a key which > is a string (actually a tuple converted to a string) and a two item > list as value, with one element in the list being a count related to > the key. I have to at the end sort this dictionary by the count. > > The platform is linux. I am planning to implement it by setting a > threshold beyond which I write the data into files (3 columns: 'key > count some_val' ) and later merge those files (I plan to sort the > individual files by the key column and walk through the files with one > pointer per file and merge them; I would add up the counts when > entries from two files match by key) and sorting using the 'sort' > command. Thus the bottleneck is the 'sort' command. > > Any suggestions, comments? > > By the way, is there a linux command that does the merging part? > > Thanks, > Krishna Have you looked here? http://docs.python.org/library/persistence.html -- Arnaud From mukeshtiwari.iiitm at gmail.com Sat Feb 20 06:17:23 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sat, 20 Feb 2010 03:17:23 -0800 (PST) Subject: Precision issue in python Message-ID: Hello everyone. I think it is related to the precision with double arithmetic so i posted here.I am trying with this problem (https:// www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for all test cases whose N>=100, its K<=15." I know precision of doubles in c is 16 digits. Could some one please help me with this precision issue.I used stirling (http://en.wikipedia.org/wiki/ Stirling's_approximation) to calculate the first k digits of N. Thank you. __author__="Administrator" __date__ ="$Feb 19, 2010 3:16:47 PM$" import math if __name__ == "__main__": n=int(raw_input()) while(n>0): n-=1 raw_input() l=raw_input(); m=l.split(" ") N,K,L=int(m[0]),int(m[1]),int(m[2]) fwd,bkd=1,1 s_1,s_2="","" if(N<=200): for i in range(1,N+1): fwd=fwd*i; s=str(fwd) s_1=s[:K] else: d_1=(N*math.log(N)-N+0.5*math.log(2*math.pi*N)+(1/12/N)- (1/360/pow(N,3))+(1/1260/pow(N,5))-(1/1680/pow(N,7))+(1/1188/pow(N,9))- (691/2730/12/11/pow(N,11))+(7/6/14/13/pow(N,13)))*math.log10(math.e) d_2=d_1-int(d_1)+K-1 fwd=pow(10,d_2) #print fwd fwd=int(fwd) s_1=str(fwd) if(N<=500): for i in range(1,N+1): bkd=bkd*i bkd=bkd%pow(10,L) if(bkd==0): s_2="0"*L else: s_2=str(bkd) else: s_2="0"*L print s_1+" "+s_2 From sebastian.noack at googlemail.com Sat Feb 20 06:52:50 2010 From: sebastian.noack at googlemail.com (Sebastian Noack) Date: Sat, 20 Feb 2010 12:52:50 +0100 Subject: os.pipe() + os.fork() In-Reply-To: <20100220113604.49b7c242@gurka> References: <20100220113604.49b7c242@gurka> Message-ID: <20100220125250.35c9937d@gurka> I have figured out that, you have to close the writing end in the child process, which is reading from the pipe. Otherwise the underlying pipe is not going to be closed when the parent process is closing its writing end. This has nothing to do with Python itself. I have tried plain C and there it is the same behaviour. Regards Sebastian Noack -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From dickinsm at gmail.com Sat Feb 20 07:44:12 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Feb 2010 04:44:12 -0800 (PST) Subject: Precision issue in python References: Message-ID: On Feb 20, 11:17?am, mukesh tiwari wrote: > Hello everyone. I think it is ?related to the precision with double > arithmetic so i posted here.I am trying with this problem (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > all test cases whose N>=100, its K<=15." I know precision of doubles > in c is 16 digits. Could some one please help me with this precision > issue.I used stirling (http://en.wikipedia.org/wiki/ > Stirling's_approximation) to calculate the first k digits of N. > Thank you. If I understand you correctly, you're trying to compute the first k digits in the decimal expansion of N!, with bounds of k <= 15 and 100 <= N < 10**8. Is that right? Python's floats simply don't give you enough precision for this: you'd need to find the fractional part of log10(N!) with >= 15 digits of precision. But the integral part needs ~ log10(log10(N!)) digits, so you end up needing to compute log10(N!) with at least 15 + log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few extra digits for safety); so that's at least 25 digits needed for N close to 10**8. The decimal module would get you the results you need (are you allowed imports?). Or you could roll your own log implementation based on integer arithmetic. -- Mark From sparks.m at gmail.com Sat Feb 20 09:13:06 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Sat, 20 Feb 2010 06:13:06 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <3aa0205f-1e98-4376-92e4-607f96f13616@k19g2000yqc.googlegroups.com> On Feb 18, 4:15?pm, Steve Howell wrote: ... > ? ? def print_numbers() > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > ? ? ? ? ? ? [n * n, n * n * n] > ? ? ? ? }.reject { |square, cube| > ? ? ? ? ? ? square == 25 || cube == 64 > ? ? ? ? }.map { |square, cube| > ? ? ? ? ? ? cube > ? ? ? ? }.each { |n| > ? ? ? ? ? ? puts n > ? ? ? ? } > ? ? end This strikes me as a terrible example. For example, this is significantly clearer: def print_numbers() for n in [1,2,3,4,5,6]: square, cube = n * n, n * n * n if square != 25 and cube != 64: print n I /can/ see arguments for ruby style blocks in python, but not for this sort of thing, or lisp style quoted expressions[1]. ie I can see situations where you have more complex code in real life where they will definitely simplify things. [1] This is perhaps more appropriate because '(a b c) is equivalent to (quote a b c), and quote a b c can be viewed as close to python's expression "lambda: a b c" However, I can also see that in simple situations - such as the example you post - they will have a tendency to make code significantly less clear/direct. I suppose, if I have a choice between something (hard being possible & simple code looking simple) and (hard things being simpler & simple things looking harder), I'd probably personally choose the former. This is not because I don't like hard things being simple, but because I think that simple things are more common and making them look harder is a mistake. I'm well aware that's opinion however, Regards, Michael. From anand.shashwat at gmail.com Sat Feb 20 09:42:17 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 20:12:17 +0530 Subject: Precision issue in python In-Reply-To: References: Message-ID: A quick solution I came out with, no stirling numbers and had tried to avoid large integer multiplication as much as possible. import math for i in range(int(raw_input())): n, k, l = [int(i) for i in raw_input().split()] e = sum(math.log10(i) for i in range(1, n+1)) frac_e = e - math.floor(e) a = str(10**frac_e * 10**(k - 1)).split('.')[0] b = 1 for i in range(n, 0, -1): b = (b * i) % 10**l lb = len(str(b)) if lb < l: b = str(b) + '0'* (l - lb) print a, b ~l0nwlf On Sat, Feb 20, 2010 at 6:14 PM, Mark Dickinson wrote: > On Feb 20, 11:17 am, mukesh tiwari > wrote: > > Hello everyone. I think it is related to the precision with double > > arithmetic so i posted here.I am trying with this problem ( > https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : > for > > all test cases whose N>=100, its K<=15." I know precision of doubles > > in c is 16 digits. Could some one please help me with this precision > > issue.I used stirling (http://en.wikipedia.org/wiki/ > > Stirling's_approximation) to calculate the first k digits of N. > > Thank you. > > If I understand you correctly, you're trying to compute the first k > digits in the decimal expansion of N!, with bounds of k <= 15 and 100 > <= N < 10**8. Is that right? > > Python's floats simply don't give you enough precision for this: > you'd need to find the fractional part of log10(N!) with >= 15 digits > of precision. But the integral part needs ~ log10(log10(N!)) digits, > so you end up needing to compute log10(N!) with at least 15 + > log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few > extra digits for safety); so that's at least 25 digits needed for N > close to 10**8. > > The decimal module would get you the results you need (are you allowed > imports?). Or you could roll your own log implementation based on > integer arithmetic. > > -- > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dksreddy at gmail.com Sat Feb 20 09:44:52 2010 From: dksreddy at gmail.com (Sandy) Date: Sat, 20 Feb 2010 06:44:52 -0800 (PST) Subject: Looking for crossfold validation code References: Message-ID: <50026db2-ad99-41ac-bad8-ed8da0df6449@g11g2000yqe.googlegroups.com> Following is the code I use. I got it from web, but forgot the link. def k_fold_cross_validation(X, K, randomise = False): """ Generates K (training, validation) pairs from the items in X. Each pair is a partition of X, where validation is an iterable of length len(X)/K. So each training iterable is of length (K-1)*len(X)/K. If randomise is true, a copy of X is shuffled before partitioning, otherwise its order is preserved in training and validation. """ if randomise: from random import shuffle; X=list(X); shuffle(X) for k in xrange(K): training = [x for i, x in enumerate(X) if i % K != k] validation = [x for i, x in enumerate(X) if i % K == k] yield training, validation Cheers, dksr On Feb 20, 1:15?am, Mark Livingstone wrote: > Hello, > > I am doing research as part of a Uni research Scholarship into using > data compression for classification. What I am looking for is python > code to handle the crossfold validation side of things for me - that > will take my testing / training corpus and create the testing / > training files after asking me for number of folds and number of times > (or maybe allow me to enter a random seed or offset instead of times.) > I could then either hook my classifier into the program or use it in a > separate step. > > Probably not very hard to write, but why reinvent the wheel ;-) > > Thanks in advance, > > MarkL From mukeshtiwari.iiitm at gmail.com Sat Feb 20 10:13:07 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sat, 20 Feb 2010 07:13:07 -0800 (PST) Subject: Precision issue in python References: Message-ID: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> On Feb 20, 5:44?pm, Mark Dickinson wrote: > On Feb 20, 11:17?am, mukesh tiwari > wrote: > > > Hello everyone. I think it is ?related to the precision with double > > arithmetic so i posted here.I am trying with this problem (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > > all test cases whose N>=100, its K<=15." I know precision of doubles > > in c is 16 digits. Could some one please help me with this precision > > issue.I used stirling (http://en.wikipedia.org/wiki/ > > Stirling's_approximation) to calculate the first k digits of N. > > Thank you. > > If I understand you correctly, you're trying to compute the first k > digits in the decimal expansion of N!, with bounds of k <= 15 and 100 > <= N < 10**8. ?Is that right? > > Python's floats simply don't give you enough precision for this: > you'd need to find the fractional part of log10(N!) with >= 15 digits > of precision. ?But the integral part needs ~ log10(log10(N!)) digits, > so you end up needing to compute log10(N!) with at least 15 + > log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few > extra digits for safety); ?so that's at least 25 digits needed for N > close to 10**8. > > The decimal module would get you the results you need (are you allowed > imports?). ?Or you could roll your own log implementation based on > integer arithmetic. > > -- > Mark Yes i am trying to first k digits of N!.I will try your method. Thank you From wolftracks at invalid.com Sat Feb 20 10:23:16 2010 From: wolftracks at invalid.com (W. eWatson) Date: Sat, 20 Feb 2010 07:23:16 -0800 Subject: The Disappearing Program? (py2exe, graphics) In-Reply-To: <85adff5e-fc5e-4296-9408-b44f4b3dc207@z10g2000prh.googlegroups.com> References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> <17d79b9e-0f06-4885-bb52-9cc06312f403@f17g2000prh.googlegroups.com> <85adff5e-fc5e-4296-9408-b44f4b3dc207@z10g2000prh.googlegroups.com> Message-ID: This apparently is not quite as easy as the py2exe tutorial suggests when MPL is involved. See . It looks like I have some reading and work to do. From malkarouri at gmail.com Sat Feb 20 10:30:54 2010 From: malkarouri at gmail.com (Muhammad Alkarouri) Date: Sat, 20 Feb 2010 07:30:54 -0800 (PST) Subject: Few questions on SOAP References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: <72c74040-620b-4588-aa5e-63282bdacc64@v20g2000yqv.googlegroups.com> Thanks every one for commenting. I guess I misspoke. I meant to say that the group is not necessarily the best for parts of this question, so Subhabrata might not get as enthusiastic responses as in some other lists (which i don't recollect at the moment, sorry). I didn't want to convey the sense that his question is not welcome, rather that it might not get a lot of answers. Thanks Brendon and Steve for the support, and thanks Mark for correcting my slip. Regards, k From mukeshtiwari.iiitm at gmail.com Sat Feb 20 10:37:52 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sat, 20 Feb 2010 07:37:52 -0800 (PST) Subject: Precision issue in python References: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> Message-ID: <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> On Feb 20, 8:13?pm, mukesh tiwari wrote: > On Feb 20, 5:44?pm, Mark Dickinson wrote: > > > > > > > On Feb 20, 11:17?am, mukesh tiwari > > wrote: > > > > Hello everyone. I think it is ?related to the precision with double > > > arithmetic so i posted here.I am trying with this problem (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > > > all test cases whose N>=100, its K<=15." I know precision of doubles > > > in c is 16 digits. Could some one please help me with this precision > > > issue.I used stirling (http://en.wikipedia.org/wiki/ > > > Stirling's_approximation) to calculate the first k digits of N. > > > Thank you. > > > If I understand you correctly, you're trying to compute the first k > > digits in the decimal expansion of N!, with bounds of k <= 15 and 100 > > <= N < 10**8. ?Is that right? > > > Python's floats simply don't give you enough precision for this: > > you'd need to find the fractional part of log10(N!) with >= 15 digits > > of precision. ?But the integral part needs ~ log10(log10(N!)) digits, > > so you end up needing to compute log10(N!) with at least 15 + > > log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few > > extra digits for safety); ?so that's at least 25 digits needed for N > > close to 10**8. > > > The decimal module would get you the results you need (are you allowed > > imports?). ?Or you could roll your own log implementation based on > > integer arithmetic. > > > -- > > Mark > > Yes i am trying to first k digits of N!.I will try your method. > Thank you I am out of luck.I put d_2=d_1-int(d_1)+25 instead of d_2=d_1- int(d_1)+K-1 but i am getting WA. "The decimal module would get you the results you need (are you allowed imports?). Or you could roll your own log implementation based on integer arithmetic. " I don't know if is possible to import this decimal module but kindly tell me.Also a bit about log implementation Thank you From anand.shashwat at gmail.com Sat Feb 20 11:00:29 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 21:30:29 +0530 Subject: Precision issue in python In-Reply-To: <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> References: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> Message-ID: > I don't know if is possible to import this decimal module but kindly > tell me.Also a bit about log implementation > Why don't you read about decimal module (there is log too in it) and try writing your approach here in case it does not work? Or you insist someone to rewrite your code using decimal module ? :-/ ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From elias.bachaalany at gmail.com Sat Feb 20 11:12:01 2010 From: elias.bachaalany at gmail.com (lallous) Date: Sat, 20 Feb 2010 08:12:01 -0800 (PST) Subject: Pure virtual functions in Python? Message-ID: Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2): """ This is a callback @param param1: ... @param param2: ... """ raise NotImplementedError, "Implement me" # Implementation w/o a 'cb', thus 'cb' should not be used class C2(C1): def __init__(self): pass # Implementation w/ 'cb', thus 'cb' can be used class C3(C1): def __init__(self): pass def cb(self, param1, param2): print "i am c3 cb" # Dispatcher function that calls 'cb' only if 'cb' is implemented in child classes def dispatcher(c): if hasattr(c, 'cb'): c.cb("Hello", "World") dispatcher(C2()) dispatcher(C3()) What I want is the ability to have the dispatcher() not to call 'cb' if it was not implemented in one of the child classes. Please advise. From swrath at gmail.com Sat Feb 20 11:27:28 2010 From: swrath at gmail.com (sWrath swrath) Date: Sat, 20 Feb 2010 08:27:28 -0800 (PST) Subject: finding element by tag in xml Message-ID: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> Hi I am trying to search an element by tag and new in reading a xml file (in python). I coded this , but it did not work ---------------------------------------------- '''This is to detect the first element and print out all that element by tag''' from xml.dom.minidom import parse from xml.etree.ElementTree import* file1="book.xml" tmptree=ElementTree() tmptree.parse(file1) items=root.getiterator() dom = parse(file1) #Find tag names for node in items : if node.tag == 'author': #Get tag print dom.getElementsByTagName ('book') #Error 1 -----------------------------------------------------------------------------' 2 Questions 1. Why can't I use dom.getElementsByTagName('book') in #Error 1? How do i print the elements ? Error- AttributeError: ElementTree instance has no attribute 'getElementsByTagName' Thanks John From misceverything at gmail.com Sat Feb 20 11:38:07 2010 From: misceverything at gmail.com (T) Date: Sat, 20 Feb 2010 08:38:07 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> Message-ID: <94febb38-2249-4ba1-872f-4ed11865f046@c28g2000vbc.googlegroups.com> On Feb 19, 4:32?pm, Ryan Kelly wrote: > On Fri, 2010-02-19 at 11:08 -0800, T wrote: > > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > > I have a Python app which I converted to an EXE (all files separate; > > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > > this and would like the ability to remotely upgrade the program (for > > > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > > you might find it useful: > > > > ?http://pypi.python.org/pypi/esky > > > > Docs are a little scarce at the moment, the next release will hopefully > > > come with a short tutorial (as well as support for cx_freeze and maybe > > > py2app, depending on how adventurous I'm feeling). > > > Thanks Ryan..this looks like it could be what I'm looking for, but I'm > > still a bit unsure of how exactly how it works. ?Do you happen to have > > an idea approx when the next release w/ tutorial will be out? > > If I punt on the py2app support, I should be able to get it done in the > next 3-4 days. ?I'll send a quick email to python-list when it's ready. > > Here's a rough roadmap of where the project is heading: > > ? v0.4.0: ?cx_freeze support and a tutorial [the next 3-4 days] > ? v0.4.1: ?py2app support [the next 2-3 weeks] > ? v0.5.0: ?differential updates using bsdiff [next few months] > > ? Cheers, > > ? ? ?Ryan > > -- > Ryan Kellyhttp://www.rfk.id.au?| ?This message is digitally signed. Please visit > r... at rfk.id.au ? ? ? ?| ?http://www.rfk.id.au/ramblings/gpg/for details > > ?signature.asc > < 1KViewDownload Excellent - I look forward to giving it a try. Thanks again! From showell30 at yahoo.com Sat Feb 20 11:41:10 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 20 Feb 2010 08:41:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <3aa0205f-1e98-4376-92e4-607f96f13616@k19g2000yqc.googlegroups.com> Message-ID: On Feb 20, 6:13?am, Michael Sparks wrote: > On Feb 18, 4:15?pm, Steve Howell wrote: > ... > > > ? ? def print_numbers() > > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > > ? ? ? ? ? ? [n * n, n * n * n] > > ? ? ? ? }.reject { |square, cube| > > ? ? ? ? ? ? square == 25 || cube == 64 > > ? ? ? ? }.map { |square, cube| > > ? ? ? ? ? ? cube > > ? ? ? ? }.each { |n| > > ? ? ? ? ? ? puts n > > ? ? ? ? } > > ? ? end > > This strikes me as a terrible example. For example, this is > significantly clearer: > ? ? def print_numbers() > ? ? ? ? for n in [1,2,3,4,5,6]: > ? ? ? ? ? ? square, cube = n * n, n * n * n > ? ? ? ? ? ? if square != 25 and cube != 64: > ? ? ? ? ? ? ? ? print n This is not an exact translation. My example prints the cubes. It is my fault for using "n" as the parameter in the last block. I would rename the parameter to cube. > > I /can/ see arguments for ruby style blocks in python, but not for > this sort of thing, or lisp style quoted expressions[1]. ie I can see > situations where you have more complex code in real life where they > will definitely simplify things. > > [1] This is perhaps more appropriate because '(a b c) is equivalent > ? ? to (quote a b c), and quote a b c can be viewed as close to > ? ? python's expression "lambda: a b c" > > However, I can also see that in simple situations - such as the > example you post - they will have a tendency to make code > significantly less clear/direct. > > I suppose, if I have a choice between something (hard being possible & > simple code looking simple) and (hard things being simpler & simple > things looking harder), I'd probably personally choose the former. > This is not because I don't like hard things being simple, but because > I think that simple things are more common and making them look harder > is a mistake. > I agree with much of what you are saying. The example is indeed terribly contrived. I'm not sure I agree that there is anything unclear or undirect about the Ruby, though. I've been fairly immersed in Ruby code, so maybe it's been warping my brain, but once you get over the unfamiliarity of the syntax, you see that there's actually a rhythm to the code. Setting aside punctuation and parameter lists, the code clearly expresses the transformations and actions in the natural order that you'd do them: LIST map expression reject criteria map expression each statement In English, for the list elements, map them to tuples of squares and cubes, reject the oddballs, take the cube, and print it out. [1, 2, 3, 4, 5, 6].map { |n| [n * n, n * n * n] }.reject { |square, cube| square == 25 || cube == 64 }.map { |square, cube| cube }.each { |cube| puts cube } For such a small problem, I agree it's verbose. But it's also completely flat--you don't need to use an "if" statement to express the concept of rejection. From martin at v.loewis.de Sat Feb 20 11:46:17 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 20 Feb 2010 17:46:17 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <4B8011D9.40005@v.loewis.de> lallous wrote: > Hello > > How can I do something similar to pure virtual functions in C++ ? See, for example http://code.activestate.com/recipes/266468/ Regards, Martin From deets at nospam.web.de Sat Feb 20 11:46:42 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 20 Feb 2010 17:46:42 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <7uahviFlubU1@mid.uni-berlin.de> Am 20.02.10 17:12, schrieb lallous: > Hello > > How can I do something similar to pure virtual functions in C++ ? > > Let us consider this: > > class C1: > > # Pure virtual > def cb(self, param1, param2): > """ > This is a callback > > @param param1: ... > @param param2: ... > """ > raise NotImplementedError, "Implement me" > > # Implementation w/o a 'cb', thus 'cb' should not be used > class C2(C1): > def __init__(self): > pass > > # Implementation w/ 'cb', thus 'cb' can be used > class C3(C1): > def __init__(self): > pass > > def cb(self, param1, param2): > print "i am c3 cb" > > # Dispatcher function that calls 'cb' only if 'cb' is implemented in > child classes > def dispatcher(c): > if hasattr(c, 'cb'): > c.cb("Hello", "World") > > dispatcher(C2()) > dispatcher(C3()) > > What I want is the ability to have the dispatcher() not to call 'cb' > if it was not implemented in one of the child classes. > > Please advise. There is nothing more beyond that what you already did. You can raise a NotImplementedError for classes that don't implement the method. That's it. Diez From martin at v.loewis.de Sat Feb 20 12:08:33 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 20 Feb 2010 18:08:33 +0100 Subject: Pure virtual functions in Python? In-Reply-To: <7uahviFlubU1@mid.uni-berlin.de> References: <7uahviFlubU1@mid.uni-berlin.de> Message-ID: <4B801711.7040501@v.loewis.de> >> class C1: >> >> # Pure virtual >> def cb(self, param1, param2): >> """ >> This is a callback >> >> @param param1: ... >> @param param2: ... >> """ >> raise NotImplementedError, "Implement me" >> >> # Dispatcher function that calls 'cb' only if 'cb' is implemented in >> child classes >> def dispatcher(c): >> if hasattr(c, 'cb'): >> c.cb("Hello", "World") >> >> dispatcher(C2()) >> dispatcher(C3()) >> >> What I want is the ability to have the dispatcher() not to call 'cb' >> if it was not implemented in one of the child classes. >> >> Please advise. > > There is nothing more beyond that what you already did. You can raise a > NotImplementedError for classes that don't implement the method. That's it. That's not true. Currently, the hasattr() call would report that cb is available, when it is actually not implemented. It would be possible to do something like if hasattr(c, 'cb') and not is_pure(c.cb): c.cb("Hello", "World") is_pure could, for example, look at a function attribute of the callback. You'd write something like @pure_virtual def cb(self, param1, param2): not_implemented Regards, Martin From deets at nospam.web.de Sat Feb 20 12:14:04 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 20 Feb 2010 18:14:04 +0100 Subject: Pure virtual functions in Python? In-Reply-To: <4B801711.7040501@v.loewis.de> References: <7uahviFlubU1@mid.uni-berlin.de> <4B801711.7040501@v.loewis.de> Message-ID: <7uajisFvihU1@mid.uni-berlin.de> Sorry, I totally mis-read the OP, too tired. You are right of course. Diez From dickinsm at gmail.com Sat Feb 20 12:17:12 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Feb 2010 09:17:12 -0800 (PST) Subject: Precision issue in python References: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> Message-ID: <0550699e-9da7-4b3b-8a0d-f4549a3ddf83@j27g2000yqn.googlegroups.com> On Feb 20, 3:37?pm, mukesh tiwari wrote: > I don't know if is possible to import this decimal module but kindly > tell me.Also a bit about log implementation The decimal module is part of the standard library; I don't know what the rules are for SPOJ, but you're already importing the math module, so at least *some* imports are obviously permitted. Here's a quick demonstration of how you might use the decimal module: you can probably find ways to tweak it for speed and accuracy. from decimal import Decimal as D from decimal import getcontext getcontext().prec = 100 # working precision = 100 digits pi = D('3.14159265358979323846264338327950288419716939937510582097494459' '2307816406286208998628034825342117067982148086513282306647093844') half = D('0.5') log = D.ln def logfac(x): """Approximation to log(x!), using first few terms of Stirling's series.""" x = D(x) return log(2*pi)/2 + (x + half)*log(x) - x + \ 1/(12*x) - 1/(360*x**3) + 1/(1260*x**5) def fac_first_digits(n, k): """Get first k decimal digits of n!.""" log10_nfac = logfac(n)/log(D(10)) frac = log10_nfac - int(log10_nfac) return int(10**(frac - 1 + k)) With the above code I get, for example (with Python 2.6): >>> fac_first_digits(12345, 15) 344364246918678 >>> from math import factorial >>> int(str(factorial(12345))[:15]) 344364246918678 For small n, you'll need more terms of Stirling's series than I've used above. And there's always a small chance that the intermediate errors involved in the computation might change those first 15 digits; with a working precision of 100 and lots of terms of Stirling's series it's a *very* small chance, but it's there. If you want something 100% watertight, you'd need to compute strict upper and lower bounds for the true result, and increase precision until those bounds match sufficiently far that you can be sure of the first k digits being correct. -- Mark From rami.chowdhury at gmail.com Sat Feb 20 12:19:27 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 20 Feb 2010 12:19:27 -0500 Subject: Pure virtual functions in Python? In-Reply-To: <7uahviFlubU1@mid.uni-berlin.de> References: <7uahviFlubU1@mid.uni-berlin.de> Message-ID: <201002201219.27267.rami.chowdhury@gmail.com> On Saturday 20 February 2010 11:46:42 Diez B. Roggisch wrote: > Am 20.02.10 17:12, schrieb lallous: > > Hello > > > > How can I do something similar to pure virtual functions in C++ ? > > > > Let us consider this: > > > > class C1: > > > > # Pure virtual > > def cb(self, param1, param2): > > """ > > This is a callback > > > > @param param1: ... > > @param param2: ... > > """ > > raise NotImplementedError, "Implement me" > > > > # Implementation w/o a 'cb', thus 'cb' should not be used > > class C2(C1): > > def __init__(self): > > pass > > > > # Implementation w/ 'cb', thus 'cb' can be used > > class C3(C1): > > def __init__(self): > > pass > > > > def cb(self, param1, param2): > > print "i am c3 cb" > > > > # Dispatcher function that calls 'cb' only if 'cb' is implemented in > > child classes > > def dispatcher(c): > > if hasattr(c, 'cb'): > > c.cb("Hello", "World") > > > > dispatcher(C2()) > > dispatcher(C3()) > > > > What I want is the ability to have the dispatcher() not to call 'cb' > > if it was not implemented in one of the child classes. > > > > Please advise. > > There is nothing more beyond that what you already did. You can raise a > NotImplementedError for classes that don't implement the method. That's it. > > Diez > Perhaps you could use an easier-to-ask-forgiveness-than-permission idiom? def dispatcher(c): try: c.cb("Hello", "World") except NotImplementedError: pass ---- Rami Chowdhury "Passion is inversely proportional to the amount of real information available." -- Benford's Law of Controversy 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From vicente.soler at gmail.com Sat Feb 20 12:35:17 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 20 Feb 2010 09:35:17 -0800 (PST) Subject: Building a dict from a tuple of tuples Message-ID: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column header. For example: d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } As you can see, if the value in the matrix is None, no key has to be added to the dictionary. Of course, my tuple of tuples is a lot bigger. How can I possibly do this? Thank you From lie.1296 at gmail.com Sat Feb 20 12:36:00 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 04:36:00 +1100 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> <4b7f892c$1@dnews.tpgi.com.au> <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> Message-ID: <4b801d9c@dnews.tpgi.com.au> On 02/20/10 19:36, MattB wrote: > On Feb 20, 2:02 am, Lie Ryan wrote: >> On 02/20/10 13:32, MattB wrote: >> >> >> >>> I'm using the network in my own apartment. Not the campus's. >>> Moreover, my mac's MAC address is different from the MAC address shown >>> by my router, but as I said I'm also blocked when using my friend's >>> wireless router at his apartment. >> >>> So it must be my mac's MAC, and not the router's MAC, that's being >>> blocked, right? >> >>> But ALSO -- is it my ISP that's blocking the mac's MAC (and not the >>> school), since I can't raise ANY url's from python when I'm on >>> wireless? >> >> MAC or IP blocking can't be the reason, as the OP stated, he can use >> Firefox just fine. >> >> Can you access, say,http://www.google.comfrom urllib or mechanize? >> >> If you can't access *any website* using urllib/mechanize but you can >> with a browser and you're on a unix-based machine, you probably have the >> same problem as I used to have. Check whether you used the same hostname >> in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves >> its hostname configurations, I use Gentoo); after editing those files >> reboot (there are ways to avoid reboot, but rebooting guarantees the >> conf file is reread). >> >> Check the hostname by running this python script: >> >> import socket >> hn = socket.gethostname() >> print hn >> print socket.gethostbyname(hn) # should be 127.0.0.1 > > Lie, > > Wow. Strangely, that script returned 192.168.1.106. However, in Snow > Leopard's airport settings, if I click on 'advanced' and then > 'proxies', the default proxy for 'http' is 127.0.0.1:4444 (and in > these settings, the 'use proxy for http' is checked). > > I just tried checking the unix files you mentioned. In etc/hosts, the > following info is displayed: > > ## > # Host Database > # > # localhost is used to configure the loopback interface > # when the system is booting. Do not change this entry. > ## > > > 127.0.0.1 localhost > 255.255.255.255 broadcasthost > ::1 localhost > fe80::1%lo0 localhost > > > Not sure if these are what I'm looking for -- I'm new to unix so I may > need a bit more hand-holding here. Try the alternatives in this site: http://movealong.org/hostname.html > Also found a file called ntp-restrict.conf, containing: > > # Access restrictions documented in ntp.conf(5) and > # http://support.ntp.org/bin/view/Support/AccessRestrictions > # Limit network machines to time queries only > > restrict default kod nomodify notrap nopeer noquery > restrict -6 default kod nomodify notrap nopeer noquery > > # localhost is unrestricted > restrict 127.0.0.1 > restrict -6 ::1 > > includefile /private/etc/ntp.conf Not sure if ntp-restrict.conf is a red herring here since its name implies it's something for NTP (Network Time Protocol, used for time synchronization) From python at mrabarnett.plus.com Sat Feb 20 12:49:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 17:49:14 +0000 Subject: the mystery of dirname() In-Reply-To: References: <4B7F5187.3060806@mrabarnett.plus.com> <4B7F5435.2020704@mrabarnett.plus.com> Message-ID: <4B80209A.9080807@mrabarnett.plus.com> Shashwat Anand wrote: > basically I infer that : dirname = path - basename, like for path = > '//x', basename = x, hence dirname = '//' > [snip] Basically, os.path.dirname() should return the directory name, which means dropping everything after the last slash, and also the last slash. However, there's the special case where the name is in the root directory, and you want to retain the slash(es). When building a path (os.path.join()) you want to join the parts with a single slash between them, but there's the special case when a part is the root directory, and you don't want to add a slash between them, eg os.part.join('/x', 'y') should return '/x/y', but os.part.join('/', 'x') should return '/x'. From dickinsm at gmail.com Sat Feb 20 12:52:49 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Feb 2010 17:52:49 +0000 Subject: Precision issue in python In-Reply-To: References: Message-ID: <5c6f2a5d1002200952i580f5f26ifa69e0fb3d57418b@mail.gmail.com> On Sat, Feb 20, 2010 at 2:42 PM, Shashwat Anand wrote: > A quick solution I came out with, no stirling numbers and had tried to avoid > large integer multiplication as much as possible. > > import math > > for i in range(int(raw_input())): > ??? n, k, l = [int(i) for i in raw_input().split()] > ??? e = sum(math.log10(i) for i in range(1, n+1)) > frac_e = e - math.floor(e) This isn't going to give you enough accuracy when n gets large (and the original problem seems to allow n to be as large as 10**8), for the reasons I described earlier---that is, Python floats only give you around 16 decimal digits of precision; your 'e' value will already have used up some of those 16 digits before the point, leaving you fewer than 16 digits of precision after the point, so the absolute error in frac_e will likely be larger than 1e-15. That's not good enough for getting the first 15 digits of 10**frac_e accurately. For large n, you'll also be accumulating significant error in the sum. > a = str(10**frac_e * 10**(k - 1)).split('.')[0] The str(...).split('.') here doesn't do a good job of extracting the integer part when its argument is >= 1e12, since Python produces a result in scientific notation. I think you're going to get strange results when k >= 13. -- Mark From python at mrabarnett.plus.com Sat Feb 20 13:00:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 18:00:59 +0000 Subject: Building a dict from a tuple of tuples In-Reply-To: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> Message-ID: <4B80235B.2030201@mrabarnett.plus.com> vsoler wrote: > Hello everyone! > > I have a tuple of tuples, coming from an Excel range, such as this: > > ((None, u'x', u'y'), > (u'a', 1.0, 7.0), > (u'b', None, 8.0)) > > I need to build a dictionary that has, as key, the row and column > header. > > For example: > d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } > > As you can see, if the value in the matrix is None, no key has to be > added to the dictionary. > > Of course, my tuple of tuples is a lot bigger. > > How can I possibly do this? > > Thank you Does this help? matrix = ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) for row in matrix[1 : ]: for col, val in zip(matrix[0][1 : ], row[1 : ]): print row[0], col, val From martin.hellwig at dcuktec.org Sat Feb 20 13:28:16 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 20 Feb 2010 18:28:16 +0000 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> Message-ID: On 02/20/10 00:20, MattB wrote: > > Also, based on Martin's comment, I just wanted to make you all aware > that I intend no misuse, but rather am just trying to learn, as I'm a > programming noob. It wasn't my intention to imply that, rather the opposite, that if some BOFH would see your action as misuse (some admins are pretty trigger happy), you would expect them to contact you directly (I would). Even though you are on a wireless there are ways to track you down. For example I would search my log to see if I can make an association between a login to one of my servers and your mac address. BTW, I always followed the philosophy that learning is much more fun if you can brake/blow something up. Thus on my networks all students had a lot of freedom to do whatever they think was appropriate but they where aware that every action on my network was monitored and logged. -- mph From __peter__ at web.de Sat Feb 20 13:32:33 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Feb 2010 19:32:33 +0100 Subject: Pure virtual functions in Python? References: Message-ID: lallous wrote: > How can I do something similar to pure virtual functions in C++ ? http://docs.python.org/library/abc.html#abc.abstractmethod Peter From anand.shashwat at gmail.com Sat Feb 20 13:34:14 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 21 Feb 2010 00:04:14 +0530 Subject: the mystery of dirname() In-Reply-To: <4B80209A.9080807@mrabarnett.plus.com> References: <4B7F5187.3060806@mrabarnett.plus.com> <4B7F5435.2020704@mrabarnett.plus.com> <4B80209A.9080807@mrabarnett.plus.com> Message-ID: got it. thanks. :) On Sat, Feb 20, 2010 at 11:19 PM, MRAB wrote: > Shashwat Anand wrote: > >> basically I infer that : dirname = path - basename, like for path = >> '//x', basename = x, hence dirname = '//' >> >> [snip] > Basically, os.path.dirname() should return the directory name, which > means dropping everything after the last slash, and also the last slash. > However, there's the special case where the name is in the root > directory, and you want to retain the slash(es). > > When building a path (os.path.join()) you want to join the parts with a > single slash between them, but there's the special case when a part is > the root directory, and you don't want to add a slash between them, eg > os.part.join('/x', 'y') should return '/x/y', but os.part.join('/', 'x') > should return '/x'. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 20 13:44:29 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 21 Feb 2010 00:14:29 +0530 Subject: Precision issue in python In-Reply-To: <5c6f2a5d1002200952i580f5f26ifa69e0fb3d57418b@mail.gmail.com> References: <5c6f2a5d1002200952i580f5f26ifa69e0fb3d57418b@mail.gmail.com> Message-ID: @Mark, The str(...).split('.') here doesn't do a good job of extracting the > integer part when its argument is >= 1e12, since Python produces a > result in scientific notation. I think you're going to get strange > results when k >= 13. > Yeah, you were correct. I tested it for k >= 13, and there were issues i.e. only one character is printed. Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python CALCULAT.py 3 1000000 12 12 826393051664 000000000000 1000000 13 13 8 0000000000000 100 15 4 9 0000 The logic I tried was : for alpha = n! log(alpha) = log(n!) = log(n) + log(n-1) + .. log(2) + log(1) = e [where e = log(n) + .... + log(1)] frac_e = {e} (fractional part of e, like {1.23} = .23) now last k digits of alpha = 10**frac_e * 10**(k - 1) As I can see, the method is mathematically sound, and there is precision issues. Time for code modification. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikko at redinnovation.com Sat Feb 20 13:48:42 2010 From: mikko at redinnovation.com (Mikko Ohtamaa) Date: Sat, 20 Feb 2010 10:48:42 -0800 (PST) Subject: Compiling and running 32-bit Python on 64-bit server? Message-ID: Hi, Some server-side Python applications are limited by memory usage (hint: Zope), because Python effective uses processes and not threads for multiprocessing. This is especially true for 64-bit platforms, since Python programs are all about references and objects and 64-bit effectively doubles reference size. Some benchmarks 32-bit vs. 64-bit were discussed here: http://jstahl.org/archives/2010/01/2...ks-python-2-6/ How one could create 32-bit Python run-time enviroment, preferable virtualenv, on 64-bit Linux (VPS), reducing memory usage? This environment could actually beat 64-bit in performance, due to better memory cache use. I assume this involves having lib32 libs and compiling Python with some magical switches. Cheers, Mikko From vicente.soler at gmail.com Sat Feb 20 14:00:06 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 20 Feb 2010 11:00:06 -0800 (PST) Subject: Building a dict from a tuple of tuples References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> Message-ID: <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> On Feb 20, 7:00?pm, MRAB wrote: > vsoler wrote: > > Hello everyone! > > > I have a tuple of tuples, coming from an Excel range, such as this: > > > ((None, u'x', u'y'), > > (u'a', 1.0, 7.0), > > (u'b', None, 8.0)) > > > I need to build a dictionary that has, as key, the row and column > > header. > > > For example: > > d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } > > > As you can see, if the value in the matrix is None, no key has to be > > added to the dictionary. > > > Of course, my tuple of tuples is a lot bigger. > > > How can I possibly do this? > > > Thank you > > Does this help? > > matrix = ((None, u'x', u'y'), > (u'a', 1.0, 7.0), > (u'b', None, 8.0)) > > for row in matrix[1 : ]: > ? ? ?for col, val in zip(matrix[0][1 : ], row[1 : ]): > ? ? ? ? ?print row[0], col, val and the dictionary? it is the ultimate goal of what I am intending... Thank you From gherron at islandtraining.com Sat Feb 20 14:13:45 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 20 Feb 2010 11:13:45 -0800 Subject: os.pipe() + os.fork() In-Reply-To: <20100220125250.35c9937d@gurka> References: <20100220113604.49b7c242@gurka> <20100220125250.35c9937d@gurka> Message-ID: <4B803469.7010406@islandtraining.com> Sebastian Noack wrote: > I have figured out that, you have to close the writing end in the child > process, which is reading from the pipe. Otherwise the underlying pipe > is not going to be closed when the parent process is closing its > writing end. This has nothing to do with Python itself. I have tried > plain C and there it is the same behaviour. > > Regards > Sebastian Noack > Correct. The fork creates two processes with references to the read and write ends of the pipe. Both parent and child processes should close the ends they are not using. Here's a thought: Consider the subprocess module. It can do the fork and any necessary pipes and can do so in an OS independent way. It might make you life much easier. Gary Herron From martin at v.loewis.de Sat Feb 20 14:18:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 20 Feb 2010 20:18:05 +0100 Subject: Compiling and running 32-bit Python on 64-bit server? In-Reply-To: References: Message-ID: <4B80356D.8000209@v.loewis.de> > How one could create 32-bit Python run-time enviroment, preferable > virtualenv, on 64-bit Linux (VPS), reducing memory usage? I'd install a 32-bit Linux on the hardware, and install a bigmem kernel if it has more than 3GB of main memory. > I assume this involves having lib32 libs and compiling Python with > some magical switches. The precise set of packages that you will need depends on the specific Linux distribution. Check whether "gcc -m32" can build a hello-world program. Then, set CC to "gcc -m32", and follow the build instructions in Python's README file. Regards, Martin From fallenblood at gmail.com Sat Feb 20 14:25:46 2010 From: fallenblood at gmail.com (egasimus) Date: Sat, 20 Feb 2010 11:25:46 -0800 (PST) Subject: if not global -- then what? Message-ID: Hi, newbie here. I've read on using the 'global' keyword being discouraged; then what is the preferred way to have something, for example a class containing program settings, accessible from everywhere, in a program spanning multiple files? From python at mrabarnett.plus.com Sat Feb 20 14:54:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 19:54:20 +0000 Subject: Building a dict from a tuple of tuples In-Reply-To: <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> Message-ID: <4B803DEC.7060304@mrabarnett.plus.com> vsoler wrote: > On Feb 20, 7:00 pm, MRAB wrote: >> vsoler wrote: >>> Hello everyone! >>> I have a tuple of tuples, coming from an Excel range, such as this: >>> ((None, u'x', u'y'), >>> (u'a', 1.0, 7.0), >>> (u'b', None, 8.0)) >>> I need to build a dictionary that has, as key, the row and column >>> header. >>> For example: >>> d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } >>> As you can see, if the value in the matrix is None, no key has to be >>> added to the dictionary. >>> Of course, my tuple of tuples is a lot bigger. >>> How can I possibly do this? >>> Thank you >> Does this help? >> >> matrix = ((None, u'x', u'y'), >> (u'a', 1.0, 7.0), >> (u'b', None, 8.0)) >> >> for row in matrix[1 : ]: >> for col, val in zip(matrix[0][1 : ], row[1 : ]): >> print row[0], col, val > > and the dictionary? > > it is the ultimate goal of what I am intending... > > Thank you The difficult bit is working out how to produce the keys and values for the dict from the tuple of tuples, and I've shown you that. The rest is straightforward. From python at mrabarnett.plus.com Sat Feb 20 15:00:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 20:00:23 +0000 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <4B803F57.6010008@mrabarnett.plus.com> egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? Python's 'global' keyword is global in a file (module), not global across multiple files, so it would have helped you anyway. If you want program settings accessible across multiple modules then put the settings in a module and import that module in any other module that needs to access them. From gherron at islandtraining.com Sat Feb 20 15:00:32 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 20 Feb 2010 12:00:32 -0800 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <4B803F60.8010603@islandtraining.com> egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? > Define your "global" in a module (a .py file) and import that wherever you need it: mod.py: gvar = 123 # A Global (like) value main.py: import mod ... mod.gvar ... # To access the value ... mod.gvar = 456 ... #To change the value Using the "global" keyword has nothing to do with this. And in fact Python does not even have global variables in the sense you may be thinking. If you wish to provide a function in mode.py that sets the value then this would fail mod.py: gvar=123 def SetGvar(v): gvar = v because the gvar inside the function is local to that function. This is the proper place to use the "global" keyword. mode.py: gvar = 123 def SetGvar(v): global gvar # Makes gvar refer to the (global) module level gvar gvar = v Gary Herron From krister.svanlund at gmail.com Sat Feb 20 15:02:46 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sat, 20 Feb 2010 21:02:46 +0100 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <2cf430a61002201202je3ebeddv6f20639146f0b595@mail.gmail.com> On Sat, Feb 20, 2010 at 8:25 PM, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? > -- > http://mail.python.org/mailman/listinfo/python-list > There is probably a smarter way but I would recommend passing a settings object around. From ivlenin at gmail.com Sat Feb 20 15:04:21 2010 From: ivlenin at gmail.com (I V) Date: 20 Feb 2010 21:04:21 +0100 Subject: Pure virtual functions in Python? References: Message-ID: <4b804045$1@news.x-privat.org> On Sat, 20 Feb 2010 08:12:01 -0800, lallous wrote: > How can I do something similar to pure virtual functions in C++ ? >From what you want, it seems like you want cb() to not be called if it isn't implemented in the derived class; this isn't really what pure virtual functions in C++ do - pure virtual functions enforce, at compile time, that the derived class implements the method. If you have a situation when you want to either call a derived class's version of cb(), or do nothing, can you not just have an implementation of cb() in the base class that does nothing, i.e. class C1(object): def cb(self, param1, param2): pass From cdalten at gmail.com Sat Feb 20 15:46:24 2010 From: cdalten at gmail.com (chad) Date: Sat, 20 Feb 2010 12:46:24 -0800 (PST) Subject: How would I do a continuous write over a pipe in the following code... Message-ID: <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com> Given the following.... #!/usr/bin/python import subprocess as s broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE) out = broadcast.stdout while 1: out broadcast.wait() broadcast.stdout.close() The code only executes once. What I want to do is be able to continuously write over the pipe once it is open. I could put s.Popen() inside the while loop, but that seems a bit too messy. So is there some way to just open the pipe once, and once it is open, just continuously write over it vs just opening and closing the pipe every time? From vicente.soler at gmail.com Sat Feb 20 16:25:53 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 20 Feb 2010 13:25:53 -0800 (PST) Subject: Building a dict from a tuple of tuples References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> Message-ID: On Feb 20, 8:54?pm, MRAB wrote: > vsoler wrote: > > On Feb 20, 7:00 pm, MRAB wrote: > >> vsoler wrote: > >>> Hello everyone! > >>> I have a tuple of tuples, coming from an Excel range, such as this: > >>> ((None, u'x', u'y'), > >>> (u'a', 1.0, 7.0), > >>> (u'b', None, 8.0)) > >>> I need to build a dictionary that has, as key, the row and column > >>> header. > >>> For example: > >>> d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } > >>> As you can see, if the value in the matrix is None, no key has to be > >>> added to the dictionary. > >>> Of course, my tuple of tuples is a lot bigger. > >>> How can I possibly do this? > >>> Thank you > >> Does this help? > > >> matrix = ((None, u'x', u'y'), > >> (u'a', 1.0, 7.0), > >> (u'b', None, 8.0)) > > >> for row in matrix[1 : ]: > >> ? ? ?for col, val in zip(matrix[0][1 : ], row[1 : ]): > >> ? ? ? ? ?print row[0], col, val > > > and the dictionary? > > > it is the ultimate goal of what I am intending... > > > Thank you > > The difficult bit is working out how to produce the keys and values for > the dict from the tuple of tuples, and I've shown you that. The rest is > straightforward. I'll try. Thank you very much MRAB From gnarlodious at gmail.com Sat Feb 20 16:28:55 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 20 Feb 2010 13:28:55 -0800 (PST) Subject: Shared web host good citizenship question References: Message-ID: <59e76f4d-2493-411d-9cef-5420483550f1@z10g2000prh.googlegroups.com> I would say like this: If your processes are serving up straight pages, let them timeout after a while. If your processes are handling eCommerce or persistent data, keep the connection open as long as possible. -- Gnarlie From jim.hefferon at gmail.com Sat Feb 20 16:41:15 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 20 Feb 2010 13:41:15 -0800 (PST) Subject: finding element by tag in xml References: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> Message-ID: On Feb 20, 11:27 am, sWrath swrath wrote: > 2 Questions > > 1. Why can't I use dom.getElementsByTagName('book') in #Error 1? How > do i print the elements ? > Error- AttributeError: ElementTree instance has no attribute > 'getElementsByTagName' I only see one question here. I think the error is asserting that your instance of the ET class does not have such a fcn. I also do not see it in the ET documentation. Perhaps you are looking for the XPath support at http://effbot.org/zone/element-xpath.htm ? Or perhaps you want to make your document dom representation via a different library? Jim From digitalxero at gmail.com Sat Feb 20 16:56:09 2010 From: digitalxero at gmail.com (Dj Gilcrease) Date: Sat, 20 Feb 2010 14:56:09 -0700 Subject: finding element by tag in xml In-Reply-To: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> References: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> Message-ID: On Sat, Feb 20, 2010 at 9:27 AM, sWrath swrath wrote: > from xml.dom.minidom import parse > from xml.etree.ElementTree import* > > file1="book.xml" > tmptree=ElementTree() > tmptree.parse(file1) > items=root.getiterator() > > > dom = parse(file1) > > > #Find tag names > for node in items : > ? ?if node.tag == 'author': #Get tag > ? ? ? ?print dom.getElementsByTagName ('book') #Error 1 You are mixing two different types of xml parsers, either user minidom for node in dom.getElementsByTagName('author'): print node.getElementsByTagName('book') or use etree for el in items: if el.tag == 'author': print el.find('book') There are a few differences you need to note, the getElementsByTagName always returns a list even if there is only 1 element and find only returns the first element found no matter what. If you want to print all books associated with an author you would need to do something like for author in tmptree.getiterator('author'): for book in author.getiterator('book'): print book From arnodel at googlemail.com Sat Feb 20 17:02:44 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 20 Feb 2010 22:02:44 +0000 Subject: Pure virtual functions in Python? References: Message-ID: lallous writes: > Hello > > How can I do something similar to pure virtual functions in C++ ? > > Let us consider this: > > class C1: > > # Pure virtual > def cb(self, param1, param2): > """ > This is a callback > > @param param1: ... > @param param2: ... > """ > raise NotImplementedError, "Implement me" Why define it if it is virtual? > # Implementation w/o a 'cb', thus 'cb' should not be used > class C2(C1): > def __init__(self): > pass > > # Implementation w/ 'cb', thus 'cb' can be used > class C3(C1): > def __init__(self): > pass > > def cb(self, param1, param2): > print "i am c3 cb" > > # Dispatcher function that calls 'cb' only if 'cb' is implemented in > child classes > def dispatcher(c): > if hasattr(c, 'cb'): > c.cb("Hello", "World") > > dispatcher(C2()) > dispatcher(C3()) > > What I want is the ability to have the dispatcher() not to call 'cb' > if it was not implemented in one of the child classes. If you don't define cb in the parent class, it'll work. -- Arnaud From norman at smash-net.org Sat Feb 20 17:12:50 2010 From: norman at smash-net.org (=?ISO-8859-15?Q?Norman_Rie=DF?=) Date: Sat, 20 Feb 2010 23:12:50 +0100 Subject: Reading a large bz2 textfile exits early Message-ID: <4B805E62.5070909@smash-net.org> Hello, i am trying to read a large bz2 compressed textfile using the bz2 module. The file is 1717362770 lines long and 8GB large. Using this code source_file = bz2.BZ2File(file, "r") for line in source_file: print line.strip() print "Exiting" print "I used file: " + file the loop exits cleanly after 4311 lines in midline and the prints are executed. This happened on two different boxes runnig different brands of linux. Is there something i miss or should be done differently? Thank you. Regards, Norman From olaye1977 at googlemail.com Sat Feb 20 18:03:27 2010 From: olaye1977 at googlemail.com (V8 NUT) Date: Sat, 20 Feb 2010 15:03:27 -0800 (PST) Subject: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4 Message-ID: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> Been trying to fix this issue for over 6 hours now. It's doin my head in, any one know whats going on here. ==START== python setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.4/MySQLdb running build_ext building '_mysql' extension gcc -pthread -shared build/temp.linux-x86_64-2.4/_mysql.o -L/usr/lib64/ mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm - lpthread -lssl -lcrypto -o build/lib.linux-x86_64-2.4/_mysql.so /usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz /usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for - lz /usr/bin/ld: cannot find -lz collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 ==END== Am trying to get MySQL-python-1.2.3c1 installed on a CentOS 5 box running Python 2.4 I do not want to upgrade my Python version. I have tried: 1. yum install mysql-python 2. yum install librsync-devel 3. yum install python-devel With all return no errors and a notification that there's nothing to install or update. Please help. From astan.chee at al.com.au Sat Feb 20 18:07:32 2010 From: astan.chee at al.com.au (Astan Chee) Date: Sun, 21 Feb 2010 10:07:32 +1100 Subject: calculating a string equation In-Reply-To: References: Message-ID: <4B806B34.1070508@al.com.au> Arnaud Delobelle wrote: > Astan Chee writes: > > >> Hi, >> I have some variables in my script that looks like this: >> vars = {'var_a':'10','var_b':'4'} >> eqat = "(var_a/2.0) <= var_b" >> result = "(var_a+var_b)/7" >> What I'm trying to do is to plug in var_a and var_b's values from vars >> into eqat and see if eqat returns true or false as well as getting the >> value of result if these variables were "plugged in". How do I do >> this? >> I'm also expecting eqat and result to contain various python >> mathematical operators like **, and compounded ()'s. >> I'm not sure how to convert the equation; if I have to make a bunch of >> if-statements or if there is a python function that already does >> something like this. >> > > Yes: eval() > > >>>> vars = {'var_a':10 ,'var_b':4} >>>> eqat = "(var_a/2.0) <= var_b" >>>> result = "(var_a+var_b)/7" >>>> eval(eqat, vars) >>>> > False Hi, I now have a slight problem with this. This doesnt seem to work: >>> vars = {'var a':10 ,'var b':4} >>> eqat = "(var a/2.0) <= var b" >>> eval(eqat, vars) Traceback (most recent call last): File "", line 1, in eval(eqat, vars) File "", line 1 (var a/2.0) <= var b ^ SyntaxError: invalid syntax So eval can't take spaces? is there a way to go around this? Thanks again for any suggestions Cheers Astan -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Feb 20 18:21:50 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Feb 2010 15:21:50 -0800 Subject: calculating a string equation In-Reply-To: <4B806B34.1070508@al.com.au> References: <4B806B34.1070508@al.com.au> Message-ID: <50697b2c1002201521w73905736o30760b7924663b89@mail.gmail.com> On Sat, Feb 20, 2010 at 3:07 PM, Astan Chee wrote: > Arnaud Delobelle wrote: > Astan Chee writes: > Hi, > I have some variables in my script that looks like this: > vars = {'var_a':'10','var_b':'4'} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > What I'm trying to do is to plug in var_a and var_b's values from vars > into eqat and see if eqat returns true or false as well as getting the > value of result if these variables were "plugged in". How do I do > this? > I'm also expecting eqat and result to contain various python > mathematical operators like **, and compounded ()'s. > I'm not sure how to convert the equation; if I have to make a bunch of > if-statements or if there is a python function that already does > something like this. > > > Yes: eval() > > > > vars = {'var_a':10 ,'var_b':4} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > eval(eqat, vars) > > > False > > Hi, > I now have a slight problem with this. This doesnt seem to work: >>>> vars = {'var a':10 ,'var b':4} >>>> eqat = "(var a/2.0) <= var b" >>>> eval(eqat, vars) > > Traceback (most recent call last): > ? File "", line 1, in > ??? eval(eqat, vars) > ? File "", line 1 > ??? (var a/2.0) <= var b > ???????? ^ > SyntaxError: invalid syntax > > So eval can't take spaces? is there a way to go around this? eval() requires the string be valid Python code and conform to Python's syntax. Obviously your string isn't valid Python. You can either require beforehand that variables not be prefixed with "var " as they are currently, or you can get rid of the "var"s yourself: vars = {'a':10 ,'b':4} equat = equat.replace('var ','') eval(equat, vars) but this could cause problems if you have a variable whose names ends with "var"; using a regular expression for the removal would fix that. Cheers, Chris -- http://blog.rebertia.com From stef.mientki at gmail.com Sat Feb 20 18:52:33 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 21 Feb 2010 00:52:33 +0100 Subject: Is there a way to continue after an exception ? Message-ID: <4B8075C1.4090304@gmail.com> hello, I would like my program to continue on the next line after an uncaught exception, is that possible ? thanks Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Sat Feb 20 18:54:55 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 20 Feb 2010 15:54:55 -0800 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> Message-ID: DANNY wrote: > >If I want to have a MPEG-4/10 coded video and stream it through the >network and than have the same video on the client side, what should I >use and of course I don't want to have raw MPEG data, because than I >couldn't extract the frames to manipulate them. If you want to manipulate the frames (as bitmaps), then you have little choice but to decode the MPEG as you receive it, manipulate the bitmaps, and re-encode it back to MPEG. That's going to take a fair amount of time... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From krister.svanlund at gmail.com Sat Feb 20 18:59:40 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sun, 21 Feb 2010 00:59:40 +0100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4B8075C1.4090304@gmail.com> References: <4B8075C1.4090304@gmail.com> Message-ID: <2cf430a61002201559i1819944cre605f3904f06c541@mail.gmail.com> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: > hello, > > I would like my program to continue on the next line after an uncaught > exception, > is that possible ? > > thanks > Stef Mientki > Yes, you catch the exception and do nothing. From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 19:00:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 00:00:05 GMT Subject: if not global -- then what? References: Message-ID: <4b807784$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 11:25:46 -0800, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from everywhere, > in a program spanning multiple files? Such a thing is no different from keeping many global settings. It's not the global KEYWORD that is discouraged, but the over-use of global variables itself. See, for example: http://c2.com/cgi/wiki?GlobalVariablesAreBad http://weblogs.asp.net/wallen/archive/2003/05/08/6750.aspx In a nutshell: shared variables introduce tight coupling between parts of your code that should be independent. Whether they are truly global, or passed around in a Settings object, makes little or no difference. In both cases, the risks and problems are identical. Let me give a fanciful example: suppose your refrigerator, oven and shower all shared a single global temperature setting instead of having three local temperature settings. This would be a recipe for disaster: every operation to any of the three would need to carefully save the current temperature setting, and there's the constant risk of scalding showers, ruined foods, and undercooked meals. Having three different global temperature settings helps a bit, but that just expands the number of variables that everything has access too. Why do the television and the garage door need access to any temperature setting, let alone all three? Python globals aren't as bad as in some other languages, because "global" means global to a single module, not global to the entire program, but if you create a Settings object and import it from module to module, you break the encapsulation, *and* you then have the problem of needing to make sure it is initialised properly. http://archive.eiffel.com/doc/manuals/technology/bmarticles/joop/globals.html Global constants also aren't as bad, because the coupling is weaker. Unfortunately Python doesn't have constants, except by convention, so there's always the risk that some badly-behaved function might decide to redefine (say) math.pi to 3.15. Unfortunately, you probably can't get rid of globals altogether, but the tricks are (1) use as few of them as possible, and (2) make them local as quickly as possible. For example, you might have something like this: default_header = "My special header" # A global for option, argument in command_line: if option == "--header": default_header = argument class Printer: def print_page(self, text, header=None): if header is None: header = default_header print header print text I would limit the scope of default_header so that it was local to the printer class: for option, argument in command_line: if option == "--header": Printer.default_header = argument class Printer: default_header = "My special header" def print_page(self, text, header=None): if header is None: header = self.default_header print header print text You might not be able to completely eliminate either globals, or a Settings object, but you should be able to make it much, much smaller. In practice, to make testing easier, I'd split the command line processing into two steps: a function that reads and processes the command line into a single local settings object, then a separate function that applies those settings to the various classes. The function that reads the command line doesn't need to know where the settings eventually end up, and the function that applies the settings doesn't need to know where they come from. All the coupling between settings and classes is in one place, the second function, instead of scattered all over your code. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 19:00:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 00:00:17 GMT Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> Message-ID: <4b807791$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 18:28:16 +0000, Martin P. Hellwig wrote: > On 02/20/10 00:20, MattB wrote: > >> >> Also, based on Martin's comment, I just wanted to make you all aware >> that I intend no misuse, but rather am just trying to learn, as I'm a >> programming noob. > > It wasn't my intention to imply that, rather the opposite, that if some > BOFH would see your action as misuse (some admins are pretty trigger > happy), you would expect them to contact you directly (I would). Even > though you are on a wireless there are ways to track you down. For > example I would search my log to see if I can make an association > between a login to one of my servers and your mac address. This may be what you would do, but in my experience, it is more likely that the admin would be far too busy and/or lazy to try to track you down unless (1) they wanted to give you a warning prior to expulsion, or (2) they needed to know who you were prior to laying charges. In my experience they're far more likely to just hit the problem with a hammer by blocking you as much as is technically possible. > BTW, I always followed the philosophy that learning is much more fun if > you can brake/blow something up. Thus on my networks all students had a > lot of freedom to do whatever they think was appropriate but they where > aware that every action on my network was monitored and logged. Unfortunately this is the exception rather than the rule, I think. -- Steven From lie.1296 at gmail.com Sat Feb 20 19:21:09 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 11:21:09 +1100 Subject: Is there a way to continue after an exception ? In-Reply-To: References: <4B8075C1.4090304@gmail.com> Message-ID: <4b807c90$1@dnews.tpgi.com.au> > On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: >> hello, >> >> I would like my program to continue on the next line after an uncaught >> exception, >> is that possible ? >> >> thanks >> Stef Mientki >> That reminds me of VB's "On Error Resume Next" From vincent at vincentdavis.net Sat Feb 20 19:21:11 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 17:21:11 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> Message-ID: <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> Thanks for the help, this is considerably faster and easier to read (see below). I changed it to avoid the "break" and I think it makes it easy to understand. I am checking the conditions each time slows it but it is worth it to me at this time. Thanks again Vincent def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') data = [] mask = [] outliers = [] modified = [] data_append = data.append mask_append = mask.append outliers_append = outliers.append modified_append = modified.append maskcount = 0 outliercount = 0 modifiedcount = 0 for row in reader: if '[MASKS]' in row: maskcount += 1 if '[OUTLIERS]' in row: outliercount += 1 if '[MODIFIED]' in row: modifiedcount += 1 if not any((maskcount, outliercount, modifiedcount, not row)): data_append(row) elif not any((outliercount, modifiedcount, not row)): mask_append(row) elif not any((modifiedcount, not row)): outliers_append(row) else: if row: modified_append(row) data = data[1:] mask = mask[3:] outliers = outliers[3:] modified = modified[3:] return [data, mask, outliers, modified] *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Fri, Feb 19, 2010 at 4:36 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > > On Fri, Feb 19, 2010 at 1:58 PM, Vincent Davis wrote: > >> In reference to the several comments about "[x for x in read] is basically >> a copy of the entire list. This isn't necessary." or list(read). I had >> thought I had a problem with having iterators in the takewhile() statement. >> I thought I testes and it didn't work. It seems I was wrong. It clearly >> works. I'll make this change and see if it is any better. >> >> I actually don't plan to read them all in at once, only as needed, but I >> do need the whole file in an array to perform some mathematics on them and >> compare different files. So my interest was in making it faster to open them >> as needed. I guess part of it is that they are about 5mb so I guess it might >> be disk speed in part.nks >> >> > > Record your numbers in an array and then work your magic on them later. > Don't store the entire file in memory, though. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rzantow at gmail.com Sat Feb 20 19:25:10 2010 From: rzantow at gmail.com (rzed) Date: Sun, 21 Feb 2010 00:25:10 +0000 Subject: The Disappearing Program? References: Message-ID: "W. eWatson" wrote in news:hlls5c$89l$1 at news.eternal-september.org: > I've successfully compiled several small python programs on Win > XP into executables using py2exe. A program goes from a name like > snowball.py to snowball. A dir in the command prompt window finds > snowball.py but not snowball. If I type in snowball, it executes. > What's up with that? There is a ludicrous setting in Windows explorer that hides the extensions for known file types, such as .exe. If you see "snowball" in Win Explorer, that's probably the way your system is set. If you click on Tools . Folder Options . View you should see a checkbox for the "Hide extensions for known file types" option. Uncheck it, and the disappearing program will return to view. This is a separate issue for why snowball.py executes when you enter "snowball" at the command line. -- rzed From fetchinson at googlemail.com Sat Feb 20 19:32:53 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 21 Feb 2010 01:32:53 +0100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4B8075C1.4090304@gmail.com> References: <4B8075C1.4090304@gmail.com> Message-ID: > I would like my program to continue on the next line after an uncaught > exception, > is that possible ? try: # here is your error except: pass # this will get executed no matter what See http://docs.python.org/tutorial/errors.html HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From timr at probo.com Sat Feb 20 19:49:57 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 20 Feb 2010 16:49:57 -0800 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: Chris Rebert wrote: >On Thu, Feb 18, 2010 at 11:58 AM, John Nagle wrote: >> >> ? Python isn't ready for this. ?Not with the GIL. > >Is any language, save perhaps Erlang, really ready for it? F# is. I only wish the syntax was a little less Perl-like. Too many special characters. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From marwie at gmx.de Sat Feb 20 19:55:10 2010 From: marwie at gmx.de (marwie) Date: Sat, 20 Feb 2010 16:55:10 -0800 (PST) Subject: Efficient way to break up a list into two pieces Message-ID: Hello, I recently read about augmented assignments and that (with l1, l2 being lists) l1.extend(l2) is more efficient than l1 = l1 + l2 because unnecessary copy operations can be avoided. Now my question is if there's a similar thing for breaking a list into two parts. Let's say I want to remove from l1 everything from and including position 10 and store it in l2. Then I can write l2 = l1[10:] del l1[10:] But since I'm assigning a slice the elements will be copied. Basically, I'm looking for something like l1.pop(10,len(l1)) which returns and removes a whole chunk of data. Is there such a thing (and if not, why not?) Cheers, Martin. From python at mrabarnett.plus.com Sat Feb 20 19:56:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Feb 2010 00:56:53 +0000 Subject: The Disappearing Program? In-Reply-To: References: Message-ID: <4B8084D5.2010006@mrabarnett.plus.com> rzed wrote: > "W. eWatson" wrote in > news:hlls5c$89l$1 at news.eternal-september.org: > >> I've successfully compiled several small python programs on Win >> XP into executables using py2exe. A program goes from a name like >> snowball.py to snowball. A dir in the command prompt window finds >> snowball.py but not snowball. If I type in snowball, it executes. >> What's up with that? > > There is a ludicrous setting in Windows explorer that hides the > extensions for known file types, such as .exe. If you see "snowball" > in Win Explorer, that's probably the way your system is set. If you > click on Tools . Folder Options . View you should see a checkbox for > the "Hide extensions for known file types" option. Uncheck it, and the > disappearing program will return to view. > The problem with that setting is that an .exe file could masquerade as some other type, eg "foo.txt.exe" would appear as "foo.txt", so you might have thought that you were safe opening it because it's just text. > This is a separate issue for why snowball.py executes when you enter > "snowball" at the command line. > From vincent at vincentdavis.net Sat Feb 20 20:05:35 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:05:35 -0700 Subject: Not sure why this is filling my sys memory Message-ID: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> Code is below, The files are about 5mb and 230,000 rows. When I have 43 files of them and when I get to the 35th (reading it in) my system gets so slow that it is nearly functionless. I am on a mac and activity monitor shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). The getsizeof() returns 6424 bytes for the alldata . So I am not sure what is happening. Any ideas Thanks *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Sat Feb 20 20:06:36 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:06:36 -0800 Subject: Efficient way to break up a list into two pieces In-Reply-To: References: Message-ID: <6cc20cea1002201706k27236296qcaa20e7580ed710d@mail.gmail.com> On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 > being lists) > > ? ?l1.extend(l2) > > is more efficient than > > ? ?l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if there's a similar thing for breaking a list into two parts. Let's > say I want to remove from l1 everything from and including position 10 > and store it in l2. Then I can write > > ? ?l2 = l1[10:] > ? ?del l1[10:] > > But since I'm assigning a slice the elements will be copied. > Basically, I'm looking for something like l1.pop(10,len(l1)) which > returns and removes a whole chunk of data. Is there such a thing (and > if not, why not?) > The idiom is: >>> l1, l2 = l1[:10], l1[10:] Don't know if it's optimized or not. If it's not, it could probably be. This is a really common idiom. -- Jonathan Gardner jgardner at jonathangardner.net From vincent at vincentdavis.net Sat Feb 20 20:07:59 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:07:59 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> Message-ID: <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> > Code is below, The files are about 5mb and 230,000 rows. When I have 43 > files of them and when I get to the 35th (reading it in) my system gets so > slow that it is nearly functionless. I am on a mac and activity monitor > shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). > The getsizeof() returns 6424 bytes for the alldata . So I am not sure what > is happening. > Any ideas > Thanks > > import csv, os, glob import sys def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') data = [] mask = [] outliers = [] modified = [] data_append = data.append mask_append = mask.append outliers_append = outliers.append modified_append = modified.append maskcount = 0 outliercount = 0 modifiedcount = 0 for row in reader: if '[MASKS]' in row: maskcount += 1 if '[OUTLIERS]' in row: outliercount += 1 if '[MODIFIED]' in row: modifiedcount += 1 if not any((maskcount, outliercount, modifiedcount, not row)): data_append(row) elif not any((outliercount, modifiedcount, not row)): mask_append(row) elif not any((modifiedcount, not row)): outliers_append(row) else: if row: modified_append(row) data = data[1:] mask = mask[3:] outliers = outliers[3:] modified = modified[3:] return [data, mask, outliers, modified] def ImportDataFrom(folder): print 'Importing files from: ', folder alldata = dict() infolder = glob.glob( os.path.join(folder, '*.txt') ) numfiles = len(infolder) print 'Importing ' + str(numfiles) + ' files from: ', folder for infile in infolder: print "Loading into memory: " + os.path.split(infile)[1] fname = os.path.split(infile)[1] filedata = dict(zip([fname + '_data', fname + '_mask', fname + '_outliers', fname+'_modified'], read_data_file(infile))) print fname + ' has ' + str(len(filedata[fname + '_data'])) + ' rows of data' print fname + ' has ' + str(len(filedata[fname + '_mask'])) + ' rows of masked data' print fname + ' has ' + str(len(filedata[fname + '_outliers'])) + ' rows of outliers' print fname + ' has ' + str(len(filedata[fname +'_modified'])) + ' modified rows of data' print str(sys.getsizeof(filedata)) +'bytes'' of memory used for '+ fname print ' ' alldata.update(filedata) print str(len(alldata)/4) + ' files of ' + str(numfiles) + ' using ' + str(sys.getsizeof(alldata)) + ' bytes of memory' return alldata ImportDataFrom("/Users/vmd/Dropbox/dna/data/rawdata") -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 20 20:12:01 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 21 Feb 2010 06:42:01 +0530 Subject: Efficient way to break up a list into two pieces In-Reply-To: <6cc20cea1002201706k27236296qcaa20e7580ed710d@mail.gmail.com> References: <6cc20cea1002201706k27236296qcaa20e7580ed710d@mail.gmail.com> Message-ID: You can always implement your own data-structures or simply a function if you need so. A language consist of building blocks and not buildings. On Sun, Feb 21, 2010 at 6:36 AM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: > > Hello, > > > > I recently read about augmented assignments and that (with l1, l2 > > being lists) > > > > l1.extend(l2) > > > > is more efficient than > > > > l1 = l1 + l2 > > > > because unnecessary copy operations can be avoided. Now my question is > > if there's a similar thing for breaking a list into two parts. Let's > > say I want to remove from l1 everything from and including position 10 > > and store it in l2. Then I can write > > > > l2 = l1[10:] > > del l1[10:] > > > > But since I'm assigning a slice the elements will be copied. > > Basically, I'm looking for something like l1.pop(10,len(l1)) which > > returns and removes a whole chunk of data. Is there such a thing (and > > if not, why not?) > > > > The idiom is: > > >>> l1, l2 = l1[:10], l1[10:] > > Don't know if it's optimized or not. If it's not, it could probably > be. This is a really common idiom. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Sat Feb 20 20:18:24 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:18:24 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> Message-ID: <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> On Sat, Feb 20, 2010 at 4:21 PM, Vincent Davis wrote: > Thanks for the help, this is considerably faster and easier to read (see > below). I changed it to avoid the "break" and I think it makes it easy to > understand. I am checking the conditions each time slows it but it is worth > it to me at this time. > > It seems you are beginning to understand that programmer time is more valuable than machine time. Congratulations. > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > > data = [] > mask = [] > outliers = [] > modified = [] > > data_append = data.append > mask_append = mask.append > outliers_append = outliers.append > modified_append = modified.append > > I know some people do this to speed things up. Really, I don't think it's necessary or wise to do so. > maskcount = 0 > outliercount = 0 > modifiedcount = 0 > > for row in reader: > if '[MASKS]' in row: > maskcount += 1 > if '[OUTLIERS]' in row: > outliercount += 1 > if '[MODIFIED]' in row: > modifiedcount += 1 > if not any((maskcount, outliercount, modifiedcount, not row)): > data_append(row) > elif not any((outliercount, modifiedcount, not row)): > mask_append(row) > elif not any((modifiedcount, not row)): > outliers_append(row) > else: > if row: modified_append(row) > > Just playing with the logic here: 1. Notice that if "not row" is True, nothing happens? Pull it out explicitly. 2. Notice how it switches from mode to mode? Program it more explicitly. Here's my suggestion: def parse_masks(reader): for row in reader: if not row: continue elif '[OUTLIERS]' in row: parse_outliers(reader) elif '[MODIFIED]' in row: parse_modified(reader) masks.append(row) def parse_outliers(reader): for row in reader: if not row: continue elif '[MODIFIED]' in row: parse_modified(reader) outliers.append(row) def parse_modified(reader): for row in reader: if not row: continue modified.append(row) for row in reader: if not row: continue elif '[MASKS]' in row: parse_masks(reader) elif '[OUTLIERS]' in row: parse_outliers(reader) elif '[MODIFIED]' in row: parse_modified(reader) else: data.append(row) Since there is global state involved, you may want to save yourself some trouble in the future and put the above in a class where separate parsers can be kept separate. It looks like your program is turning into a regular old parser. Any format that is a little more than trivial to parse will need a real parser like the above. -- Jonathan Gardner jgardner at jonathangardner.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 20:30:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 01:30:05 GMT Subject: Efficient way to break up a list into two pieces References: Message-ID: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 16:55:10 -0800, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 being > lists) > > l1.extend(l2) > > is more efficient than > > l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if there's a similar thing for breaking a list into two parts. Let's say > I want to remove from l1 everything from and including position 10 and > store it in l2. Then I can write > > l2 = l1[10:] > del l1[10:] > > But since I'm assigning a slice the elements will be copied. Yes, list slicing can't make any sort of assumptions about what you're going to do next, so when you take a slice, it has to copy the data. > Basically, > I'm looking for something like l1.pop(10,len(l1)) which returns and > removes a whole chunk of data. Is there such a thing (and if not, why > not?) Such a list pop would have to copy the data too. How else could it work? What exactly is the problem you are trying to solve? If you are unhappy that copy-and-remove a slice from a list takes two lines instead of one ("won't somebody think of the shortage of newlines!!!" *wink*), then just write a helper function and call that: def copy_and_remove(alist, slice): tmp = alist[slice] del alist[slice] return tmp l2 = copy_and_remove(l1, slice(10, None)) If you are unhappy that copying slices from lists copies data, well that's just the way things are. Don't make the mistake of trying to optimize your application before you actually know what bits need optimizing. Python lists are arrays of pointers to objects, so copying a slice is fast: it doesn't have to copy the objects, just pointers. Deleting from the end of the list is also quick, because you don't have to move memory, just clear some pointers and change the length field. Splitting such an array without copying data is, essentially, impossible. Python lists aren't linked lists. But as I said, most of the time copying slices doesn't matter: the time taken is unlikely to be a serious factor in practice. If it is (and you've profiled your code, right? you're not just guessing what you think is fast and slow?) then there may be ways to optimize your code to avoid needing to copy slices, but we'd need to know what you're doing with the data. -- Steven From vincent at vincentdavis.net Sat Feb 20 20:32:28 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:32:28 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> Message-ID: <77e831101002201732m17bb9b74q5c62e279a9bf83b4@mail.gmail.com> Thanks again for the comment, not sure I will implement all of it but I will separate the "if not row" The files have some extraneous blank rows in the middle that I need to be sure not to import as blank rows. I am actually having trouble with this filling my sys memory, I posted a separate question "Why is this filling my sys memory" or something like that is the subject. I might be that my 1yr old son has been trying to help for the last hour. It is very distracting. *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 6:18 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Sat, Feb 20, 2010 at 4:21 PM, Vincent Davis wrote: > >> Thanks for the help, this is considerably faster and easier to read (see >> below). I changed it to avoid the "break" and I think it makes it easy to >> understand. I am checking the conditions each time slows it but it is worth >> it to me at this time. >> >> > It seems you are beginning to understand that programmer time is more > valuable than machine time. Congratulations. > > > >> def read_data_file(filename): >> reader = csv.reader(open(filename, "U"),delimiter='\t') >> >> data = [] >> mask = [] >> outliers = [] >> modified = [] >> >> data_append = data.append >> mask_append = mask.append >> outliers_append = outliers.append >> modified_append = modified.append >> >> > > I know some people do this to speed things up. Really, I don't think it's > necessary or wise to do so. > > >> maskcount = 0 >> outliercount = 0 >> modifiedcount = 0 >> >> for row in reader: >> if '[MASKS]' in row: >> maskcount += 1 >> if '[OUTLIERS]' in row: >> outliercount += 1 >> if '[MODIFIED]' in row: >> modifiedcount += 1 >> if not any((maskcount, outliercount, modifiedcount, not row)): >> data_append(row) >> elif not any((outliercount, modifiedcount, not row)): >> mask_append(row) >> elif not any((modifiedcount, not row)): >> outliers_append(row) >> else: >> if row: modified_append(row) >> >> > > Just playing with the logic here: > > 1. Notice that if "not row" is True, nothing happens? Pull it out > explicitly. > > 2. Notice how it switches from mode to mode? Program it more explicitly. > > Here's my suggestion: > > def parse_masks(reader): > for row in reader: > if not row: continue > elif '[OUTLIERS]' in row: parse_outliers(reader) > elif '[MODIFIED]' in row: parse_modified(reader) > masks.append(row) > > def parse_outliers(reader): > for row in reader: > if not row: continue > elif '[MODIFIED]' in row: parse_modified(reader) > outliers.append(row) > > def parse_modified(reader): > for row in reader: > if not row: continue > modified.append(row) > > for row in reader: > if not row: continue > elif '[MASKS]' in row: parse_masks(reader) > elif '[OUTLIERS]' in row: parse_outliers(reader) > elif '[MODIFIED]' in row: parse_modified(reader) > else: data.append(row) > > Since there is global state involved, you may want to save yourself some > trouble in the future and put the above in a class where separate parsers > can be kept separate. > > It looks like your program is turning into a regular old parser. Any format > that is a little more than trivial to parse will need a real parser like the > above. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Sat Feb 20 20:34:15 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:34:15 -0800 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <6cc20cea1002201734t217d548elc9c79df9e61ddfb0@mail.gmail.com> On Sat, Feb 20, 2010 at 11:25 AM, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? One of the powerful concepts to come out of Lisp was "dynamic scope". This is the ideal solution for configuration and logging. "Lexical scope" is where the value of the variables are found in the file it was defined in. This is what Python does, and it's what you're used to in most other languages. "Dynamic scope" is where the value of the variables are found by looking up the call stack. This is similar to perl's "local" keyword. It's also similar to environment variables, if you consider programs that run programs that run programs as similar to functions. (If you're familiar with neither, then that's fine.) This is useful for a program where you know it needs configuration or logging, but you don't want to have to specify it as part of the program. Whoever calls the program needs to configure it and setup their logger before calling it. Unfortunately, there is no built-in way to deal with dynamic variables in Python. But that doesn't mean you can't emulate it explicitly and clearly! In order to emulate it, you simply pass the configuration and such down to the functions you call. Each function or class instance needs to pass it further along. So, rather than: def foo(): bar() def bar() ... you need to have: def foo(config): bar(config) def bar(config): ... Obviously, only certain functions care for the config and logging setup. Others don't. And obviously, you can modify the value on the way down. Just be sure to make a copy or you'll change the entire stack's value for that configuration. There are a couple of systems that do something close to this. I don't know of any, except SQLAlchemy, that does this exactly right. WSGI is also a system that does this right, although I don't know that many people realize it. Usually, what people end up doing is setting the config values to some global in some module. Then everyone is expected to look in that module for the config. This ends up being messy, particularly for testing where you'd like to mess with the config without messing with THE config. You can tell it's messy because people end up writing code like this: old_value = get_config(...) set_config(... some new value ...) ... do your stuff ... set_config(...back to old_value...) This kind of code is hard to get right. (What happens if there is an exception before you set the old config back? That's right, you need a try-finally block.) In terms of "global", you should only really use "global" when you are need to assign to a lexically scoped variable that is shared among other functions. For instance: def foo(): i = 0 def inc(): global i; i+=1 def dec(): global i; i-=1 def get(): return i return (inc, dec, get) This really isn't that common, although it is useful. Note that the above might be better organized into a class instance. Good luck. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sat Feb 20 20:37:21 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:37:21 -0800 Subject: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4 In-Reply-To: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> References: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> Message-ID: <6cc20cea1002201737o151fe3ddu3f31fe949f254642@mail.gmail.com> On Sat, Feb 20, 2010 at 3:03 PM, V8 NUT wrote: > /usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for > -lz > /usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for - > lz > /usr/bin/ld: cannot find -lz This is your problem. > > Am trying to get MySQL-python-1.2.3c1 installed on a CentOS 5 box > running Python 2.4 > I do not want to upgrade my Python version. > I have tried: > > 1. yum install mysql-python > 2. yum install librsync-devel > 3. yum install python-devel > > With all return no errors and a notification that there's nothing to > install or update. > I think you need libz's -devel module. Not sure what libz is or what its name is in the yum repository. Might take a search or maybe an rpm -qif /usr/lib/libz.so The problem could be that mysql-python expects to see a different version of libz than what's installed on your box. If so, you'll need to see if you can find the right version. The MySQL-python people should have more help for you. -- Jonathan Gardner jgardner at jonathangardner.net From agoretoy at gmail.com Sat Feb 20 20:37:54 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 20 Feb 2010 19:37:54 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: hello all, since I posted this last time, I've added a new function dates_diff and modified the dates_dict function to set timedelta values returned by dates_diff in the returned dict def dates_dict(self,*targs,**dargs): """ dates_dict() - takes params same as prefs() returns dict key/value pair of formatted/calculated dates key is a date, value is timedelta enddate-startdate """ self.prefs(*targs,**dargs) d={} try: if self.format!="": d[self.startdate.strftime(self.format)]=self.dates_diff() else: d[self.startdate]=self.dates_diff() except ValueError: d["%s"%self.startdate]=self.dates_diff() while self.startdate From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 20:41:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 01:41:11 GMT Subject: Efficient way to break up a list into two pieces References: Message-ID: <4b808f37$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 17:06:36 -0800, Jonathan Gardner wrote: > On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: [...] >> ? ?l2 = l1[10:] >> ? ?del l1[10:] >> >> But since I'm assigning a slice the elements will be copied. Basically, >> I'm looking for something like l1.pop(10,len(l1)) which returns and >> removes a whole chunk of data. Is there such a thing (and if not, why >> not?) >> >> > The idiom is: > >>>> l1, l2 = l1[:10], l1[10:] No, that has different behaviour to what the Original Poster wants, AND it does two copies instead of one: (1) copy l1[:10] and l1[10:] (2) assign the names l1 and l2 to them (3) if, and only if, there are no other references to the original l1, it gets deleted (garbage collected). What the OP is doing is quite different: (1) copy l1[:10] (2) assign the name l2 to it (3) resize l1 in place to the first 10 items. What the OP wants is: (1) assign the name l2 to l1[:10] without copying (2) resize l1 in place to the first 10 items without affecting l2. -- Steven From jgardner at jonathangardner.net Sat Feb 20 20:41:28 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:41:28 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002201732m17bb9b74q5c62e279a9bf83b4@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> <77e831101002201732m17bb9b74q5c62e279a9bf83b4@mail.gmail.com> Message-ID: <6cc20cea1002201741g21a94cf4jb77c638cc130d89d@mail.gmail.com> On Sat, Feb 20, 2010 at 5:32 PM, Vincent Davis wrote: > > Thanks again for the comment, not sure I will implement all of it but I will separate the "if not row" The files have some extraneous blank rows in the middle that I need to be sure not to import as blank rows. > I am actually having trouble with this filling my sys memory, I posted a separate question "Why is this filling my sys memory" or something like that is the subject. > I might be that my 1yr old son has been trying to help for the last hour. It is very distracting. > It may be that the csvfile is reading the entire file in, rather than line-by-line. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sat Feb 20 20:44:57 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:44:57 -0800 Subject: Not sure why this is filling my sys memory In-Reply-To: <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> Message-ID: <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> On Sat, Feb 20, 2010 at 5:07 PM, Vincent Davis wrote: >> Code is below, The files are about 5mb and 230,000 rows. When I have 43 >> files of them and when I get to the 35th (reading it in) my system gets so >> slow that it is nearly functionless. I am on a mac and activity monitor >> shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). >> The getsizeof() returns 6424 bytes for the alldata . So I am not sure what >> is happening. With this kind of data set, you should start looking at BDBs or PostgreSQL to hold your data. While processing files this large is possible, it isn't easy. Your time is better spent letting the DB figure out how to arrange your data for you. -- Jonathan Gardner jgardner at jonathangardner.net From deadpickle at gmail.com Sat Feb 20 20:47:12 2010 From: deadpickle at gmail.com (deadpickle) Date: Sat, 20 Feb 2010 17:47:12 -0800 (PST) Subject: netcdf4-python Message-ID: <1f7f8347-4c48-42a8-8f80-6175acfb83e9@b2g2000yqi.googlegroups.com> I'm trying to use the python module "netcdf4-python" to read a netcdf file. So far I'm trying to do the basics and just open the script: from netCDF4 import Dataset rootgrp = Dataset('20060402-201025.netcdf', 'r', format='NETCDF3_CLASSIC') print rootgrp.file_format rootgrp.close() when I do this I get the exit code error (when I run in Scite): >pythonw -u "netcdf_test.py" >Exit code: -1073741819 or Python stops responding (in windows cmd). I'm not sure what is wrong so if anyone as any ideas I would gladly send you the netcdf file to try. Thanks. From vincent at vincentdavis.net Sat Feb 20 20:53:22 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:53:22 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> Message-ID: <77e831101002201753l6b77c2b7xa5cbdf15ba43f4c@mail.gmail.com> On Sat, Feb 20, 2010 at 6:44 PM, Jonathan Gardner < > jgardner at jonathangardner.net> wrote: With this kind of data set, you should start looking at BDBs or PostgreSQL to hold your data. While processing files this large is possible, it isn't easy. Your time is better spent letting the DB figure out how to arrange your data for you. I really do need all of it in at time, It is dna microarray data. Sure there are 230,00 rows but only 4 columns of small numbers. Would it help to make them float() ? I need to at some point. I know in numpy there is a way to set the type for the whole array "astype()" I think. What I don't get is that it show the size of the dict with all the data to have only 6424 bytes. What is using up all the memory? *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 6:44 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Sat, Feb 20, 2010 at 5:07 PM, Vincent Davis > wrote: > >> Code is below, The files are about 5mb and 230,000 rows. When I have 43 > >> files of them and when I get to the 35th (reading it in) my system gets > so > >> slow that it is nearly functionless. I am on a mac and activity monitor > >> shows that python is using 2.99GB of memory (of 4GB). (python 2.6 > 64bit). > >> The getsizeof() returns 6424 bytes for the alldata . So I am not sure > what > >> is happening. > > With this kind of data set, you should start looking at BDBs or > PostgreSQL to hold your data. While processing files this large is > possible, it isn't easy. Your time is better spent letting the DB > figure out how to arrange your data for you. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 20:53:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 01:53:46 GMT Subject: if not global -- then what? References: Message-ID: <4b80922a$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 17:34:15 -0800, Jonathan Gardner wrote: > In terms of "global", you should only really use "global" when you are > need to assign to a lexically scoped variable that is shared among other > functions. For instance: > > def foo(): > i = 0 > def inc(): global i; i+=1 > def dec(): global i; i-=1 > def get(): return i > return (inc, dec, get) That doesn't do what you think it does: >>> def foo(): ... i = 0 ... def inc(): global i; i+=1 ... def dec(): global i; i-=1 ... def get(): return i ... return (inc, dec, get) ... >>> inc = foo()[0] >>> inc() Traceback (most recent call last): File "", line 1, in File "", line 3, in inc NameError: global name 'i' is not defined The problem is that i is not global. Inside the inc and dec functions, you need to declare i nonlocal, not global, and that only works in Python 3 or better. -- Steven From marwie at gmx.de Sat Feb 20 20:55:18 2010 From: marwie at gmx.de (marwie) Date: Sat, 20 Feb 2010 17:55:18 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> Message-ID: <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> On 21 Feb., 02:30, Steven D'Aprano wrote: > Python lists are arrays of pointers to objects, so copying a slice is > fast: it doesn't have to copy the objects, just pointers. Deleting from > the end of the list is also quick, because you don't have to move memory, > just clear some pointers and change the length field. > > Splitting such an array without copying data is, essentially, impossible. > Python lists aren't linked lists. Well, to split a C array I would simply set l2 to point to l1[10] and then change the length of l1 (which I store somewhere else). No copying of elements needed. I would have assumed that python can do something like this with its internal arrays of pointers, too. Anyway, this was more a question about coding style. I use l1.extend(l2) or l1 += l2 rather than l1 = l1 + l2 because it's as readable and possibly faster. I was simply wondering if something similar exists for splitting lists. From sjdevnull at yahoo.com Sat Feb 20 21:00:38 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Sat, 20 Feb 2010 18:00:38 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> On Feb 18, 2:58?pm, John Nagle wrote: > ? ? Multiple processes are not the answer. ?That means loading multiple > copies of the same code into different areas of memory. ?The cache > miss rate goes up accordingly. A decent OS will use copy-on-write with forked processes, which should carry through to the cache for the code. From lie.1296 at gmail.com Sat Feb 20 21:17:47 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 13:17:47 +1100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4b807c90$1@dnews.tpgi.com.au> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> Message-ID: <4b8097e6$1@dnews.tpgi.com.au> On 02/21/10 12:02, Stef Mientki wrote: > On 21-02-2010 01:21, Lie Ryan wrote: >>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: >>> >>>> hello, >>>> >>>> I would like my program to continue on the next line after an uncaught >>>> exception, >>>> is that possible ? >>>> >>>> thanks >>>> Stef Mientki >>>> >>>> >> That reminds me of VB's "On Error Resume Next" >> > I think that's what I'm after ... First, read this: http://www.developerfusion.com/code/4325/on-error-resume-next-considered-harmful/ > I already redirected sys.excepthook to my own function, > but now I need a way to get to continue the code on the next line. > Is that possible ? No, not in python. You can (ab)use generators' yield to resume execution, but not in the general case: def on_error_resume_next(func): def _func(*args, **kwargs): gen = func(*args, **kwargs) resp = next(gen) while isinstance(resp, Exception): print 'an error happened, ignoring...' resp = next(gen) return resp return _func @on_error_resume_next def add_ten_error_if_zero(args): if args == 0: # raise Exception() yield Exception() # return args + 10 yield args + 10 print add_ten_error_if_zero(0) print add_ten_error_if_zero(10) A slightly better approach is to retry calling the function again, but as you can see, it's not appropriate for certain cases: def retry_on_error(func): def _func(*args, **kwargs): while True: try: ret = func(*args, **kwargs) except Exception: print 'An error happened, retrying...' else: return ret return _func @retry_on_error def add_ten_error_if_zero(args): if args == 0: raise Exception() return args + 10 print add_ten_error_if_zero(0) print add_ten_error_if_zero(10) A much better approach is to use callbacks, the callbacks determines whether to raise an exception or continue execution: def handler(e): if datetime.datetime.now() >= datetime.datetime(2012, 12, 21): raise Exception('The world has ended') # else: ignore, it's fine def add_ten_error_if_zero(args, handler): if args == 0: handler(args) return args + 10 print add_ten_error_if_zero(0, handler) print add_ten_error_if_zero(10, handler) print add_ten_error_if_zero(0, lambda e: None) # always succeeds Ignoring arbitrary error is against the The Zen of Python "Errors should never pass silently."; not that it is ever a good idea to ignore arbitrary error, when an exception happens often the function is in an indeterminate state, and continuing blindly could easily cause havocs. From ssteinerx at gmail.com Sat Feb 20 21:43:24 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 20 Feb 2010 21:43:24 -0500 Subject: Is there a way to continue after an exception ? In-Reply-To: <4b8097e6$1@dnews.tpgi.com.au> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> <4b8097e6$1@dnews.tpgi.com.au> Message-ID: On Feb 20, 2010, at 9:17 PM, Lie Ryan wrote: > On 02/21/10 12:02, Stef Mientki wrote: >> On 21-02-2010 01:21, Lie Ryan wrote: >>>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki > wrote: >>>> >>>>> hello, >>>>> >>>>> I would like my program to continue on the next line after an uncaught >>>>> exception, >>>>> is that possible ? >>>>> >>>>> thanks >>>>> Stef Mientki >>>>> >>>>> >>> That reminds me of VB's "On Error Resume Next" >>> >> I think that's what I'm after ... > > First, read this: > http://www.developerfusion.com/code/4325/on-error-resume-next-considered-harmful/ The link goes to an "Oh dear. Gremlins at work!" page. They're probably using On Error Resume Next in their VBScript code and this is the "last resort" page ;-). S From ryan at rfk.id.au Sat Feb 20 21:51:21 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Sun, 21 Feb 2010 13:51:21 +1100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4b8097e6$1@dnews.tpgi.com.au> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> <4b8097e6$1@dnews.tpgi.com.au> Message-ID: <1266720681.3908.24.camel@durian> On Sun, 2010-02-21 at 13:17 +1100, Lie Ryan wrote: > On 02/21/10 12:02, Stef Mientki wrote: > > On 21-02-2010 01:21, Lie Ryan wrote: > >>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki > wrote: > >>> > >>>> hello, > >>>> > >>>> I would like my program to continue on the next line after an uncaught > >>>> exception, > >>>> is that possible ? > >>>> > >>>> thanks > >>>> Stef Mientki > >>>> > >>>> > >> That reminds me of VB's "On Error Resume Next" > >> > > I think that's what I'm after ... > > A much better approach is to use callbacks, the callbacks determines > whether to raise an exception or continue execution: > > def handler(e): > if datetime.datetime.now() >= datetime.datetime(2012, 12, 21): > raise Exception('The world has ended') > # else: ignore, it's fine > > def add_ten_error_if_zero(args, handler): > if args == 0: > handler(args) > return args + 10 > > print add_ten_error_if_zero(0, handler) > print add_ten_error_if_zero(10, handler) > print add_ten_error_if_zero(0, lambda e: None) # always succeeds Or if you don't like having to explicitly manage callbacks, you can try the "withrestart" module: http://pypi.python.org/pypi/withrestart/ It tries to pinch some of the good ideas from Common Lisp's error-handling system. from withrestart import * def add_ten_error_if_zero(n): # This gives calling code the option to ignore # the error, or raise a different one. with restarts(skip,raise_error): if n == 0: raise ValueError return n + 10 # This will raise ValueError print add_ten_error_if_zero(0) # This will print 10 with Handler(ValueError,"skip"): print add_ten_error_if_zero(0) # This will exit the python interpreter with Handler(ValueError,"raise_error",SystemExit): print add_ten_error_if_zero(0) 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From nagle at animats.com Sat Feb 20 21:58:42 2010 From: nagle at animats.com (John Nagle) Date: Sat, 20 Feb 2010 18:58:42 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> Message-ID: <4b809d57$0$1596$742ec2ed@news.sonic.net> sjdevnull at yahoo.com wrote: > On Feb 18, 2:58 pm, John Nagle wrote: >> Multiple processes are not the answer. That means loading multiple >> copies of the same code into different areas of memory. The cache >> miss rate goes up accordingly. > > A decent OS will use copy-on-write with forked processes, which should > carry through to the cache for the code. That doesn't help much if you're using the subprocess module. The C code of the interpreter is shared, but all the code generated from Python is not. This will get even worse when Unladen Swallow starts generating vast swaths of unshared x86 instructions. John Nagle From marwie at gmx.de Sat Feb 20 22:00:29 2010 From: marwie at gmx.de (marwie) Date: Sat, 20 Feb 2010 19:00:29 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> Message-ID: <37cd051e-89d6-44cc-af1b-8ecaf68468b2@e1g2000yqh.googlegroups.com> On 21 Feb., 02:41, Steven D'Aprano wrote: > What the OP is doing is quite different: > > (1) copy l1[:10] > (2) assign the name l2 to it > (3) resize l1 in place to the first 10 items. > > What the OP wants is: > > (1) assign the name l2 to l1[:10] without copying > (2) resize l1 in place to the first 10 items without affecting l2. Assuming you meant l1[10:] instead of l1[:10], that's what I wanted, yes. From vincent at vincentdavis.net Sat Feb 20 22:08:18 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 20:08:18 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <654D55F2-B276-44E6-A6EF-A9D3A2B5002F@gmail.com> <77e831101002201821o230fea1cpff18a5dacb37e710@mail.gmail.com> Message-ID: <77e831101002201908h10c72304y8025f3adae0beac4@mail.gmail.com> Here is a sample of the output, It almost instantly uses 2GB and then starts using VMem. This is probably the right suggestion but it's another thing to install > It's probably also worth being aware of guppy's heapy stuff: http://guppy-pe.sourceforge.net/heapy_tutorial....I find it quite nice to have the following to get a quick point-in-time estimate of my app's memory usage: print 'Current memory usage: %iMB' % (hpy().heap().stat.size/(1024*1024)) 19 files of 43 using 3352 bytes of memory Loading into memory: 3_veg_nm_rep1.txt 3_veg_nm_rep1.txt has 228484 rows of data 3_veg_nm_rep1.txt has 0 rows of masked data 3_veg_nm_rep1.txt has 141 rows of outliers 3_veg_nm_rep1.txt has 0 modified rows of data 280bytes of memory used for 3_veg_nm_rep1.txt 20 files of 43 using 3352 bytes of memory Loading into memory: 3_veg_nm_rep2.txt 3_veg_nm_rep2.txt has 228484 rows of data 3_veg_nm_rep2.txt has 0 rows of masked data 3_veg_nm_rep2.txt has 119 rows of outliers 3_veg_nm_rep2.txt has 0 modified rows of data 280bytes of memory used for 3_veg_nm_rep2.txt 21 files of 43 using 3352 bytes of memory Loading into memory: 3_veg_phd_rep1.txt 3_veg_phd_rep1.txt has 228484 rows of data 3_veg_phd_rep1.txt has 0 rows of masked data 3_veg_phd_rep1.txt has 63 rows of outliers 3_veg_phd_rep1.txt has 0 modified rows of data 280bytes of memory used for 3_veg_phd_rep1.txt 22 files of 43 using 6424 bytes of memory Loading into memory: 3g_c285-11.txt 3g_c285-11.txt has 228484 rows of data 3g_c285-11.txt has 0 rows of masked data 3g_c285-11.txt has 65 rows of outliers 3g_c285-11.txt has 0 modified rows of data 280bytes of memory used for 3g_c285-11.txt 23 files of 43 using 6424 bytes of memory Loading into memory: 3g_c285-42.txt 3g_c285-42.txt has 228484 rows of data 3g_c285-42.txt has 0 rows of masked data 3g_c285-42.txt has 27 rows of outliers 3g_c285-42.txt has 0 modified rows of data 280bytes of memory used for 3g_c285-42.txt 24 files of 43 using 6424 bytes of memory Loading into memory: A6AF.txt A6AF.txt has 228484 rows of data A6AF.txt has 0 rows of masked data A6AF.txt has 36 rows of outliers A6AF.txt has 0 modified rows of data 280bytes of memory used for A6AF.txt 25 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3026_rep1.txt Grigg_3026_rep1.txt has 228484 rows of data Grigg_3026_rep1.txt has 0 rows of masked data Grigg_3026_rep1.txt has 949 rows of outliers Grigg_3026_rep1.txt has 0 modified rows of data 280bytes of memory used for Grigg_3026_rep1.txt 26 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3026_rep2.txt Grigg_3026_rep2.txt has 228484 rows of data Grigg_3026_rep2.txt has 0 rows of masked data Grigg_3026_rep2.txt has 361 rows of outliers Grigg_3026_rep2.txt has 0 modified rows of data 280bytes of memory used for Grigg_3026_rep2.txt 27 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3026_rep3_both.txt Grigg_3026_rep3_both.txt has 228484 rows of data Grigg_3026_rep3_both.txt has 0 rows of masked data Grigg_3026_rep3_both.txt has 41 rows of outliers Grigg_3026_rep3_both.txt has 0 modified rows of data 280bytes of memory used for Grigg_3026_rep3_both.txt 28 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3131_rep1.txt Grigg_3131_rep1.txt has 228484 rows of data Grigg_3131_rep1.txt has 0 rows of masked data Grigg_3131_rep1.txt has 537 rows of outliers Grigg_3131_rep1.txt has 0 modified rows of data 280bytes of memory used for Grigg_3131_rep1.txt 29 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3131_rep2.txt Grigg_3131_rep2.txt has 228484 rows of data Grigg_3131_rep2.txt has 0 rows of masked data Grigg_3131_rep2.txt has 238 rows of outliers Grigg_3131_rep2.txt has 0 modified rows of data 280bytes of memory used for Grigg_3131_rep2.txt 30 files of 43 using 6424 bytes of memory *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 7:40 PM, ssteinerX at gmail.com wrote: > > On Feb 20, 2010, at 9:21 PM, Vincent Davis wrote: > > See this article for some more info about the reported sizes of things: >> http://www.doughellmann.com/PyMOTW/sys/limits.html > > > Nice article but I > must have missed something useful to my current issue. Do I get any hints? > > > Oh, sorry, there was the part about getsizeof() not including attributes > unless the class supplies a __sizeof__ method and a comment at the bottom: > > It's probably also worth being aware of guppy's heapy stuff: > http://guppy-pe.sourceforge.net/heapy_tutorial.... > > I find it quite nice to have the following to get a quick point-in-time > estimate of my app's memory usage: > > print 'Current memory usage: %iMB' % (hpy().heap().stat.size/(1024*1024)) > > Put a few of those in at various places in the collection process and you > should see where you're taking a substantial hit on each pass. > > If I remember those numbers right, 5mb != 2.5gb so something along the way > is doing something very strange. > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.newville at gmail.com Sat Feb 20 22:21:57 2010 From: matt.newville at gmail.com (Matt Newville) Date: Sat, 20 Feb 2010 19:21:57 -0800 (PST) Subject: netcdf4-python References: <1f7f8347-4c48-42a8-8f80-6175acfb83e9@b2g2000yqi.googlegroups.com> Message-ID: On Feb 20, 7:47?pm, deadpickle wrote: > I'm trying to use the python module "netcdf4-python" to read a netcdf > file. So far I'm trying to do the basics and just open the script: > > from netCDF4 import Dataset > rootgrp = Dataset('20060402-201025.netcdf', 'r', > format='NETCDF3_CLASSIC') > print rootgrp.file_format > rootgrp.close() > > when I do this I get the exit code error (when I run in Scite): > > >pythonw -u "netcdf_test.py" > >Exit code: -1073741819 > > ?or Python stops responding (in windows cmd). > > I'm not sure what is wrong so if anyone as any ideas I would gladly > send you the netcdf file to try. Thanks. If the file is really of NetCDF3 format, scipy.io.netcdf should work. Replace netCDF4.Dataset(filename,'r',format='NETCDF3_CLASSIC') with scipy.io.netcdf.netcdf_open(filename,'r') --Matt Newville From python-list at open-sense.com Sat Feb 20 22:25:19 2010 From: python-list at open-sense.com (Michael Pardee) Date: Sat, 20 Feb 2010 21:25:19 -0600 Subject: lists of variables Message-ID: I'm relatively new to python and I was very surprised by the following behavior: >>> a=1 >>> b=2 >>> mylist=[a,b] >>> print mylist [1, 2] >>> a=3 >>> print mylist [1, 2] Whoah! Are python lists only for literals? Nope: >>> c={} >>> d={} >>> mydlist=[c,d] >>> print mydlist [{}, {}] >>> c['x']=1 >>> print mydlist [{'x': 1}, {}] So it looks like variables in a list are stored as object references. This seems to confirm that: mydlist[1]['y']=4 >>> print mydlist [{}, {'y': 4}] So I figure my initial example doesn't work because if you assign a literal to something it is changing the object. But modifying a list or dict (as long as you don't re-construct it) does not change the object. I can think of some ways to work around this, including using single element lists as "pointers": >>> aa=[1] >>> bb=[2] >>> myplist=[aa,bb] >>> print myplist [[1], [2]] >>> aa[0]=3 >>> print myplist [[3], [2]] But what would be "the python way" to accomplish "list of variables" functionality? From clp2 at rebertia.com Sat Feb 20 22:34:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Feb 2010 19:34:42 -0800 Subject: lists of variables In-Reply-To: References: Message-ID: <50697b2c1002201934qc6148b4j79daac42d05e7afb@mail.gmail.com> On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > I'm relatively new to python and I was very surprised by the following behavior: > >>>> a=1 >>>> b=2 >>>> mylist=[a,b] >>>> print mylist > [1, 2] >>>> a=3 >>>> print mylist > [1, 2] > > Whoah! ?Are python lists only for literals? ?Nope: > >>>> c={} >>>> d={} >>>> mydlist=[c,d] >>>> print mydlist > [{}, {}] >>>> c['x']=1 >>>> print mydlist > [{'x': 1}, {}] > > So it looks like variables in a list are stored as object references. > This seems to confirm that: > > mydlist[1]['y']=4 >>>> print mydlist > [{}, {'y': 4}] > > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. ?But modifying a list > or dict (as long as you don't re-construct it) does not change the > object. Correct. If you want more gory details, read http://effbot.org/zone/call-by-object.htm > I can think of some ways to work around this, including using single > element lists as "pointers": > >>>> aa=[1] >>>> bb=[2] >>>> myplist=[aa,bb] >>>> print myplist > [[1], [2]] >>>> aa[0]=3 >>>> print myplist > [[3], [2]] > > > But what would be "the python way" to accomplish "list of variables" > functionality? What do you need that functionality for exactly? It's a rather low-level notion. Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 22:40:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 03:40:42 GMT Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> Message-ID: <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 17:55:18 -0800, marwie wrote: > On 21 Feb., 02:30, Steven D'Aprano cybersource.com.au> wrote: >> Python lists are arrays of pointers to objects, so copying a slice is >> fast: it doesn't have to copy the objects, just pointers. Deleting from >> the end of the list is also quick, because you don't have to move >> memory, just clear some pointers and change the length field. >> >> Splitting such an array without copying data is, essentially, >> impossible. Python lists aren't linked lists. > > Well, to split a C array I would simply set l2 to point to l1[10] and > then change the length of l1 (which I store somewhere else). No copying > of elements needed. I would have assumed that python can do something > like this with its internal arrays of pointers, too. Python lists aren't C arrays either. Python lists are *objects*. Everything in Python is an object. Consequently, Python lists have a header, which includes the len. You don't store the length somewhere else, you store it in the object: this makes for less complexity. You can't just point l2 at an arbitrary index in an array and expect it to work, it needs a header. Additionally, Python lists are over-allocated so that appends are fast. A list of (say) 1000 items might be over-allocated to (say) 1024 items, so that you can do 24 appends before the array is full and the array needs to be resized. This means that, on average, Python list appending is O(1) instead of O(N). You can't just change the length blindly, you need to worry about the over-allocation. I'm sympathetic to your concern: I've often felt offended that doing something like this: x = SomeReallyBigListOrString for item in x[1:]: process(item) has to copy the entire list or string (less the first item). But honestly, I've never found a situation where it actually mattered. > Anyway, this was more a question about coding style. I use l1.extend(l2) > or l1 += l2 rather than l1 = l1 + l2 because it's as readable and > possibly faster. I really, really hate augmented assignment for everything other than ints and floats because you can't predict what it will do. Take this for example: >>> mylist = [1, 2, 3, 4] >>> same_again = mylist >>> mylist.append(5) >>> same_again [1, 2, 3, 4, 5] mylist and same_again are the same object, so append and extend behave predictably and simply. So is simple too: >>> mylist = mylist + [-1, -2, -3] >>> mylist [1, 2, 3, 4, 5, -1, -2, -3] >>> same_again [1, 2, 3, 4, 5] Because you have re-bound the name mylist to a new list, same_again doesn't get modified. Nice. But what about mylist += something else? Is it an in-place modification, like extend and append, or a rebinding, like +? Who can remember? The answer will depend on whether mylist is a builtin list, or a subclass. And then there's this mystery: >>> mylist = [1, 2, 3] >>> mytuple = (mylist, None) >>> mytuple[0] += [4] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> mylist [1, 2, 3, 4] So in fact, += is *always* a rebinding, but *sometimes* it is an in-place modification as well. Yuck. -- Steven From no.email at nospam.invalid Sat Feb 20 22:46:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 20 Feb 2010 19:46:33 -0800 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> Message-ID: <7x3a0vfdye.fsf@ruckus.brouhaha.com> John Nagle writes: >> A decent OS will use copy-on-write with forked processes, which should >> carry through to the cache for the code. > > That doesn't help much if you're using the subprocess module. The > C code of the interpreter is shared, but all the code generated from > Python is not. Emacs in days of yore used a hack called "unexec" to bring its Lisp code into the pure text segment. I think it's not used any more because machines are now big enough that the benefits aren't that great. Basically in the Emacs build process, you'd start up the C portion of Emacs, then tell it to load all its Lisp code, then call "unexec". Unexec basically performed a core dump of the process, then ran something that manipulated the original Emacs image and the core dump into a new executable that had the static Lisp code and data now marked as part of the (immutable) program area. Unexec necessarily had platform dependencies, but this was managed with a bunch of ifdefs in a reasonably clean and maintainable way. I could imagine doing something similar with a large Python program. From apt.shansen at gmail.com Sat Feb 20 22:58:10 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 20 Feb 2010 19:58:10 -0800 Subject: lists of variables In-Reply-To: References: Message-ID: <7a9c25c21002201958s1af51adeqf2b8f40fef310375@mail.gmail.com> On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > But what would be "the python way" to accomplish "list of variables" > functionality? > The problem is... Python doesn't have variables. At least not in the way that you may be used to from other languages. Yeah, it's got data, and data obviously has to be identifiable in some way, but they aren't put together like "variables" are. A variable is a box with a name on it, and in that context a 'list of variables' makes sense. You're moving around the box, or referencing the box itself. It may happen to have something in it, but that 'something' doesn't really have an identity of its own. Its just.. the thing that's in box-A. In Python, everything's an object. And objects don't really have identities of their own(okay, they do, but its not meaningful except to an identity test), but they can be named. They object has no flabbering clue what its named, or how many different people know its name, but hey. a = 1 In many languages, that's making a variable "a" and assigning it the value of 1. In Python, that's making an int object with a value of 1, and giving it a name in the current namespace. This -isn't- just using dumber/simpler words to say the same thing :) All(*) python namespaces are really dictionaries behind the scenes. a = 1 is actually doing, current_namespaces["a"] = 1. Those may sound similar, but they're really not: most importantly, because the "a" in another language is a -thing- unto itself which may hold an object. But "a" in Python is just a label in some dictionary somewhere. You can get the object a is naming, but you can't get /a/ itself. Its not a 'thing'. There's no way to make a "list of variables", because /variables/ are the part that's really missing. If you do: lst = [a, b] Python doesn't create a list and put two variables in it. It creates a list, and while doing so, sees that we want to pass 'a' and 'b' into that list. So it grabs the actual objects a and b are naming, and puts them in the list. So, long story short: what's "the python way" to accomplish a "list of variables"? Well... IMHO, it's to not do so. : ) Make a dict, pass the dict around, there's your list of variables. True, you can't ever access them /as/ variables, and have to access them as dict items, but... that's the Python way to do that. If order matters, do an ordered dict. HTH, --S *: Yes, I know about local namespaces being optimized in CPython to be an array-like structure. Implementation detail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sat Feb 20 23:09:11 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 21 Feb 2010 15:09:11 +1100 Subject: lists of variables References: Message-ID: <87fx4v6xi0.fsf@benfinney.id.au> Michael Pardee writes: > But what would be "the python way" to accomplish "list of variables" > functionality? You'll need to explain what ?list of variables? functionality is. If you mean ?collection of name-to-value mappings?, the native mapping type in Python is ?dict?. If that doesn't meet your needs, you'll need to be more specific about what behaviour you want. -- \ ?Most people don't realize that large pieces of coral, which | `\ have been painted brown and attached to the skull by common | _o__) wood screws, can make a child look like a deer.? ?Jack Handey | Ben Finney From daniel at stutzbachenterprises.com Sat Feb 20 23:18:57 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Sat, 20 Feb 2010 22:18:57 -0600 Subject: Efficient way to break up a list into two pieces In-Reply-To: References: Message-ID: On Sat, Feb 20, 2010 at 6:55 PM, marwie wrote: > Now my question is > if there's a similar thing for breaking a list into two parts. Let's > say I want to remove from l1 everything from and including position 10 > and store it in l2. Then I can write > > l2 = l1[10:] > del l1[10:] With Python's list implementation, there's no faster way to split a list into two parts. Because Python lists are essentially variable-length arrays, Python has to copy O(n) references to create l2 and then decrement O(n) references to remove them from l1. I wrote an extension type called the blist to handle this and other problems. You use it just like you'd use a list, but it has different performance characteristics. It uses a hybrid array-tree structure and performs copy-on-write behind the scenes, so it takes only O(log n) time to create l2 and only O(log n) time to trim l1. You'd use it something like this: >>> from blist import blist >>> l1 = blist() >>> # Here, populate l1 as you normally would >>> l2 = l1[10:] >>> del l1[10:] It's available at: http://pypi.python.org/pypi/blist/ -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 23:21:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 04:21:09 GMT Subject: lists of variables References: Message-ID: <4b80b4b4$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 21:25:19 -0600, Michael Pardee wrote: > I'm relatively new to python and I was very surprised by the following > behavior: [snip] I don't see why. It's fairly unusual behaviour to want, and it would be surprising if you did this: def test(): x = 1 mylist = [2, 4, x] function(mylist) assert x == 1 and the assertion failed, even though you never passed x to the function. Such behaviour could easily turn into a never-ending source of bugs. > So it looks like variables in a list are stored as object references. Python doesn't store variables in lists, it stores objects, always. Even Python variables aren't variables *grin*, although it's really difficult to avoid using the term. Python variables are mappings between names (strings) and objects, not memory locations. > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. But modifying a list or > dict (as long as you don't re-construct it) does not change the object. Yes, we talk about name binding (and rebinding) versus mutation. A simple example: >>> alist = blist = [] # bind two names to the same list object >>> alist.append(1) # mutate the list (modify in place) >>> blist [1] >>> alist = alist + [2] # a rebinding operation >>> blist [1] >>> alist [1, 2] > I can think of some ways to work around this, including using single > element lists as "pointers": Yes, that's a standard way to do it, except that by "standard" I mean "really really really rare, honestly, hardly anyone does that". Slightly less rare, but still uncommon, is to wrap objects in an instance: class Record: pass o = Record() o.x = 1 o.y = 2 modify(o) print o.x, o.y Of course you can make the class as fancy, or as simple, as you want. But a better approach is to take advantage of Python's ability to return multiple values: x = 1 y = 2 x, y = modify(x, y) rather than: x = 1 y = 2 modify([x, y]) Speaking as an old Pascal coder, you won't miss pass-by-reference very often. -- Steven From python at mrabarnett.plus.com Sat Feb 20 23:37:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Feb 2010 04:37:47 +0000 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4B80B89B.1030109@mrabarnett.plus.com> Steven D'Aprano wrote: [snip] > I'm sympathetic to your concern: I've often felt offended that doing > something like this: > > x = SomeReallyBigListOrString > for item in x[1:]: > process(item) > > has to copy the entire list or string (less the first item). But > honestly, I've never found a situation where it actually mattered. > [snip] Could lists gain an .items() method with start and end positions? I was thinking that it would be a 'view', like with dicts in Python 3. Of course, that would only be worthwhile with very long lists: x = SomeReallyBigListOrString for item in x.items(1): process(item) From jgardner at jonathangardner.net Sun Feb 21 00:21:47 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:21:47 -0800 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4b808f37$0$8819$c3e8da3@news.astraweb.com> References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> Message-ID: <6cc20cea1002202121m53c9ba3esc9d1b46dc29ce5f7@mail.gmail.com> On Sat, Feb 20, 2010 at 5:41 PM, Steven D'Aprano wrote: > > What the OP wants is: > > (1) assign the name l2 to l1[:10] without copying > (2) resize l1 in place to the first 10 items without affecting l2. > For ten items, though, is it really faster to muck around with array lengths than just copying the data over? Array copies are extremely fast on modern processors. Programmer time and processor time being what it is, I still think my answer is the correct one. No, it's not what he says he wants, but it is what he needs. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sun Feb 21 00:25:37 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:25:37 -0800 Subject: lists of variables In-Reply-To: References: Message-ID: <6cc20cea1002202125tc9b0fc6p998b9f968ce2ec5f@mail.gmail.com> On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > > But what would be "the python way" to accomplish "list of variables" > functionality? > You're looking for namespaces, AKA dicts. >>> vars = {} >>> vars['a'] = 1 >>> vars['b'] = 2 >>> mylist = ['a', 'b'] >>> print [vars[i] for i in mylist] # Here's your dereference [1,2] >>> vars['a'] = 3 >>> print [vars[i] for i in mylist] [3,2] -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sun Feb 21 00:34:41 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:34:41 -0800 Subject: Not sure why this is filling my sys memory In-Reply-To: <77e831101002201753l6b77c2b7xa5cbdf15ba43f4c@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> <77e831101002201753l6b77c2b7xa5cbdf15ba43f4c@mail.gmail.com> Message-ID: <6cc20cea1002202134k60db9dceoe2daaf431e76261f@mail.gmail.com> On Sat, Feb 20, 2010 at 5:53 PM, Vincent Davis wrote: >> On Sat, Feb 20, 2010 at 6:44 PM, Jonathan Gardner??wrote: >> >> With this kind of data set, you should start looking at BDBs or >> PostgreSQL to hold your data. While processing files this large is >> possible, it isn't easy. Your time is better spent letting the DB >> figure out how to arrange your data for you. > > I really do need all of it in at time, It is dna microarray data. Sure there are 230,00 rows but only 4 columns of small numbers. Would it help to make them float() ? I need to at some point. I know in numpy there is a way to set the type for the whole array "astype()" I think. > What I don't get is that it show the size of the dict with all the data to have only?6424 bytes. What is using up all the memory? > Look into getting PostgreSQL to organize the data for you. It's much easier to do processing properly with a database handle than a file handle. You may also discover that writing functions in Python inside of PostgreSQL can scale very well for whatever data needs you have. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sun Feb 21 00:42:14 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:42:14 -0800 Subject: if not global -- then what? In-Reply-To: <4b80922a$0$8819$c3e8da3@news.astraweb.com> References: <4b80922a$0$8819$c3e8da3@news.astraweb.com> Message-ID: <6cc20cea1002202142p73626c02w2898cc8d84c65fcc@mail.gmail.com> On Sat, Feb 20, 2010 at 5:53 PM, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 17:34:15 -0800, Jonathan Gardner wrote: >> In terms of "global", you should only really use "global" when you are >> need to assign to a lexically scoped variable that is shared among other >> functions. For instance: >> >> def foo(): >> ? ? i = 0 >> ? ? def inc(): global i; i+=1 >> ? ? def dec(): global i; i-=1 >> ? ? def get(): return i >> ? ? return (inc, dec, get) > > That doesn't do what you think it does: > > >>>> def foo(): > ... ? ? i = 0 > ... ? ? def inc(): global i; i+=1 > ... ? ? def dec(): global i; i-=1 > ... ? ? def get(): return i > ... ? ? return (inc, dec, get) > ... >>>> inc = foo()[0] >>>> inc() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 3, in inc > NameError: global name 'i' is not defined > > > The problem is that i is not global. Inside the inc and dec functions, > you need to declare i nonlocal, not global, and that only works in Python > 3 or better. > Oops. :-( -- Jonathan Gardner jgardner at jonathangardner.net From pavlovevidence at gmail.com Sun Feb 21 01:31:44 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 22:31:44 -0800 (PST) Subject: lists of variables References: Message-ID: On Feb 20, 7:25?pm, Michael Pardee wrote: > I'm relatively new to python and I was very surprised by the following behavior: > > >>> a=1 > >>> b=2 > >>> mylist=[a,b] > >>> print mylist > [1, 2] > >>> a=3 > >>> print mylist > > [1, 2] > > Whoah! ?Are python lists only for literals? ?Nope: > > >>> c={} > >>> d={} > >>> mydlist=[c,d] > >>> print mydlist > [{}, {}] > >>> c['x']=1 > >>> print mydlist > > [{'x': 1}, {}] > > So it looks like variables in a list are stored as object references. > This seems to confirm that: > > mydlist[1]['y']=4>>> print mydlist > > [{}, {'y': 4}] > > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. ?But modifying a list > or dict (as long as you don't re-construct it) does not change the > object. All correct, very observant for a Python newbie. To be more immutable > I can think of some ways to work around this, including using single > element lists as "pointers": > > >>> aa=[1] > >>> bb=[2] > >>> myplist=[aa,bb] > >>> print myplist > [[1], [2]] > >>> aa[0]=3 > >>> print myplist > > [[3], [2]] > > But what would be "the python way" to accomplish "list of variables" > functionality? Python doesn't have variable references (except in a limited way; see below), so unless you want to use lists as pointers, I'd recommend rethinking the problem. Occasionally I feel like I'd like to be able to do this, but usually another way exists that is, at worst, slightly more complex. For some cases the easiest thing is to make all the variables you're interested in listing attributes of an object (or values of a dict). Then store a list of names (or keys). class X(object): pass x = X() x.foo = 1 x.bar = 2 s = ["foo","bar"] setattr(x,s[0],3) print x.foo # prints 3 A rule of thumb in deciding whether to use attributes is whether you will typically know their names in your code ahead of time; if so storing the values as attributes is a good idea. If you are inputing or calculating the names, then it's better to use a dict. ** The one place where Python does have references is when accessing variables in an enclosing scope (not counting module-level). But these references aren't objects, so you can't store them in a list, so it can't help you: def f(): s = [] a = 1 def g(): print a s.append(a) g() # prints 1 a = 2 g() # prints 2: g's a is a reference to f's a print s # prints [1,2] not [2,2] Carl Banks From imranalii84 at gmail.com Sun Feb 21 01:32:51 2010 From: imranalii84 at gmail.com (babu lohar) Date: Sat, 20 Feb 2010 22:32:51 -0800 (PST) Subject: come and join www.pakdub.com a social network with full features like games, classifieds, forums, blogs and a lot more Message-ID: <53c431ab-87a4-4798-9616-37cfbabfb289@u19g2000prh.googlegroups.com> come and join www.pakdub.com a social network with full features like games, classifieds, forums, blogs and a lot more From pavlovevidence at gmail.com Sun Feb 21 01:38:53 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 22:38:53 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: Message-ID: <2df4ab82-7877-43f5-ac00-a780885e1950@e19g2000prn.googlegroups.com> On Feb 20, 4:55?pm, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 > being lists) > > ? ? l1.extend(l2) > > is more efficient than > > ? ? l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if there's a similar thing for breaking a list into two parts. Let's > say I want to remove from l1 everything from and including position 10 > and store it in l2. Then I can write > > ? ? l2 = l1[10:] > ? ? del l1[10:] > > But since I'm assigning a slice the elements will be copied. That's about the best you can do with Python lists. > Basically, I'm looking for something like l1.pop(10,len(l1)) which > returns and removes a whole chunk of data. Is there such a thing (and > if not, why not?) Numpy arrays can share underlying data like that when you take slices. For instance, this probably works the way you want: a = numpy.array([1,2,3,4,5,6]) b = a[:3] c = a[3:] None of the actual data was copied here. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 01:48:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 06:48:36 GMT Subject: Efficient way to break up a list into two pieces References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b80d744$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 21:21:47 -0800, Jonathan Gardner wrote: > On Sat, Feb 20, 2010 at 5:41 PM, Steven D'Aprano > wrote: >> >> What the OP wants is: >> >> (1) assign the name l2 to l1[:10] without copying (2) resize l1 in >> place to the first 10 items without affecting l2. >> >> > For ten items, though, is it really faster to muck around with array > lengths than just copying the data over? Array copies are extremely fast > on modern processors. My mistake, he actually wants l1[10:] copied. So you might be copying a huge amount of data, not just ten items. Or if you prefer, replace 10 by 100000000. But in either case, I agree that *in practice* it's rarely an actual problem. > Programmer time and processor time being what it is, I still think my > answer is the correct one. No, it's not what he says he wants, but it is > what he needs. You missed the point that your suggestion gives radically different behaviour to what the OP indicated he is using. He mutates the list in place, you rebind the list's name. That has *very* different semantics. >>> a = b = [1, 2, 3, 4] >>> del a[2:] # mutate in place >>> b [1, 2] >>> >>> a = b = [1, 2, 3, 4] >>> a = a[2:] # rebind the name >>> b [1, 2, 3, 4] The OP may not care about the difference, but if he does require the first behaviour, then your solution doesn't help. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 01:50:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 06:50:24 GMT Subject: lists of variables References: Message-ID: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote: > The one place where Python does have references is when accessing > variables in an enclosing scope (not counting module-level). What makes you say that? > But these > references aren't objects, so you can't store them in a list, so it > can't help you: I don't even understand this. Your own example clearly shows that the are objects and you can store them in a list, so I have no understanding of what you mean. > def f(): > s = [] > a = 1 > def g(): > print a a is a name bound to an object which inherits a __str__ method, hence you can print it. > s.append(a) a is bound to an object you can put in a list. > g() # prints 1 > a = 2 > g() # prints 2: g's a is a reference to f's a > print s # prints [1,2] not [2,2] Yes, you are correct that lexical scoping doesn't allow the OP to embed references to names in lists. I'm just confused why you think that lexical scoping is equivalent to references that can't be put in lists, or why you think this behaviour is any different from lexical scoping everywhere else? # Instead of two scopes, f and g, use two scopes, the module (global) # and local scope g: s = [] a = 1 def g(): print a s.append(a) g() # prints 1 a = 2 g() # prints 2: g's a is a reference to the global a print s # prints [1,2] not [2,2] There is no difference between lexical scoping between a function and a nested function, and the lexical scoping between the global namespace and a nested function. -- Steven From g.bogle at auckland.no.spam.ac.nz Sun Feb 21 02:12:33 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sun, 21 Feb 2010 20:12:33 +1300 Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> Message-ID: Steven D'Aprano wrote: > On Wed, 17 Feb 2010 02:00:59 -0500, geremy condra quoted Banibrata Dutta > : > >>> BTW for people who are non-believers in something being worth stealing >>> needing protection, need to read about the Skype client. > > Pardon me for breaking threading, but the original post has not come > through to my provider, only the reply from Geremy. > > Many things are worth stealing and therefore need protection. > > In any case, reverse engineering software is not theft. And even if it > were, keeping the source code secret is no barrier to a competent, > determined attacker or investigator. Skype is a good example: despite the > lack of source code and the secret protocol, analysts were able to > discover that TOM-Skype sends personally identifiable information, > encryption keys and private messages back to central servers. > > In my personal opinion, releasing closed source software is prima facie > evidence that the software is or does something bad: leaking personal > information, infringing somebody else's copyright or patent, or just > being badly written. I'm not saying that every piece of closed source > software is like that, but when you hide the source, the burden of proof > is on you to prove that you're not hiding something unpleasant. You are assuming that everyone who might be interested in copying your code is able to reverse-engineer it. That might be true for software with a high commercial value, but it is by no means true for all software. And in saying "when you hide the source, the burden of proof is on you to prove that you're not hiding something unpleasant" you are tacitly assuming that the users of the software care about having such a thing proven. I submit that most users do not have this "guilty until proven innocent" attitude. To give a personal example: I plan soon to distribute (free) to anyone interested some scientific software. For various reasons I do not intend to distribute the source code at this stage. I'm quite confident that the users (biologists) will have neither the desire nor the ability to reverse-engineer it. Of course I'd be tremendously flattered if they did want to. I'm also confident that they will not suspect me of "hiding something unpleasant". In the worst case they might think the program is useless. From pavlovevidence at gmail.com Sun Feb 21 02:44:29 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 23:44:29 -0800 (PST) Subject: lists of variables References: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 20, 10:50?pm, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote: > > The one place where Python does have references is when accessing > > variables in an enclosing scope (not counting module-level). ? > > What makes you say that? > > > But these > > references aren't objects, so you can't store them in a list, so it > > can't help you: > > I don't even understand this. Your own example clearly shows that the are > objects and you can store them in a list, so I have no understanding of > what you mean. > > > def f(): > > ? ? s = [] > > ? ? a = 1 > > ? ? def g(): > > ? ? ? ? print a > > a is a name bound to an object which inherits a __str__ method, hence you > can print it. > > > ? ? ? ? s.append(a) > > a is bound to an object you can put in a list. > > > ? ? g() # prints 1 > > ? ? a = 2 > > ? ? g() # prints 2: g's a is a reference to f's a > > ? ? print s # prints [1,2] not [2,2] > > Yes, you are correct that lexical scoping doesn't allow the OP to embed > references to names in lists. I'm just confused why you think that > lexical scoping is equivalent to references that can't be put in lists, > or why you think this behaviour is any different from lexical scoping > everywhere else? > > # Instead of two scopes, f and g, use two scopes, the module (global) > # and local scope g: > s = [] > a = 1 > def g(): > ? ? print a > ? ? s.append(a) > > g() # prints 1 > a = 2 > g() # prints 2: g's a is a reference to the global a > print s # prints [1,2] not [2,2] > > There is no difference between lexical scoping between a function and a > nested function, and the lexical scoping between the global namespace and > a nested function. http://tinyurl.com/8e7tm Carl Banks From sjdevnull at yahoo.com Sun Feb 21 02:45:16 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Sat, 20 Feb 2010 23:45:16 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> Message-ID: <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> On Feb 20, 9:58?pm, John Nagle wrote: > sjdevn... at yahoo.com wrote: > > On Feb 18, 2:58 pm, John Nagle wrote: > >> ? ? Multiple processes are not the answer. ?That means loading multiple > >> copies of the same code into different areas of memory. ?The cache > >> miss rate goes up accordingly. > > > A decent OS will use copy-on-write with forked processes, which should > > carry through to the cache for the code. > > ? ? That doesn't help much if you're using the subprocess module. ?The > C code of the interpreter is shared, but all the code generated from > Python is not. Of course. Multithreading also fails miserably if the threads all try to call exec() or the equivalent. It works fine if you use os.fork(). From elias.bachaalany at gmail.com Sun Feb 21 03:22:56 2010 From: elias.bachaalany at gmail.com (lallous) Date: Sun, 21 Feb 2010 00:22:56 -0800 (PST) Subject: Pure virtual functions in Python? References: <7uahviFlubU1@mid.uni-berlin.de> <4B801711.7040501@v.loewis.de> Message-ID: <2c9cf10c-90fc-4b08-9f71-a5a7fb1f8a32@m37g2000yqf.googlegroups.com> On Feb 20, 6:08?pm, "Martin v. Loewis" wrote: > >> class C1: > > >> ? ? ?# Pure virtual > >> ? ? ?def cb(self, param1, param2): > >> ? ? ? ? ?""" > >> ? ? ? ? ?This is a callback > > >> ? ? ? ? ?@param param1: ... > >> ? ? ? ? ?@param param2: ... > >> ? ? ? ? ?""" > >> ? ? ? ? ?raise NotImplementedError, "Implement me" > > >> # Dispatcher function that calls 'cb' only if 'cb' is implemented in > >> child classes > >> def dispatcher(c): > >> ? ? ?if hasattr(c, 'cb'): > >> ? ? ? ? ?c.cb("Hello", "World") > > >> dispatcher(C2()) > >> dispatcher(C3()) > > >> What I want is the ability to have the dispatcher() not to call 'cb' > >> if it was not implemented in one of the child classes. > > >> Please advise. > > > There is nothing more beyond that what you already did. You can raise a > > NotImplementedError for classes that don't implement the method. That's it. > > That's not true. Currently, the hasattr() call would report that cb is > available, when it is actually not implemented. It would be possible to > do something like > > ? if hasattr(c, 'cb') and not is_pure(c.cb): > ? ? ? c.cb("Hello", "World") > > is_pure could, for example, look at a function attribute of the > callback. You'd write something like > > ? @pure_virtual > ? def cb(self, param1, param2): > ? ? ? not_implemented > > Regards, > Martin Hello Martine, Can you elaborate more on how to use the mechanism you described? Thanks, Elias From elias.bachaalany at gmail.com Sun Feb 21 03:27:24 2010 From: elias.bachaalany at gmail.com (lallous) Date: Sun, 21 Feb 2010 00:27:24 -0800 (PST) Subject: Pure virtual functions in Python? References: Message-ID: Thanks everyone for the answers. The dispatcher() is actually sits in C++ code. So my code receives an object that is an instance of the base class, it PyObject_GetAttrString(py_obj, 'funcname'). If the attribute exists I will call PyObject_CallMethod on it. If the base defines the method and it was empty, then my C++ code would still call the function. This is not optimal because I don't want to go from C++ to Python if the _derived_ class does not implement the cb. Now the base class should define it so that doc parsers properly describe the base class. The recipe suggested is not worth the trouble. Unfortunately I cannot use abc module since I use Python 2.5 From sjmachin at lexicon.net Sun Feb 21 04:16:11 2010 From: sjmachin at lexicon.net (John Machin) Date: Sun, 21 Feb 2010 01:16:11 -0800 (PST) Subject: datelib pythonification References: Message-ID: On Feb 21, 12:37?pm, alex goretoy wrote: > hello all, > ? ? since I posted this last time, I've added a new function dates_diff and [SNIP] I'm rather unsure of the context of this posting ... I'm assuming that the subject "datelib pythonification" refers to trying to make "datelib" more "pythonic", with which you appear to need help. Looking just at the new "function" (looks like a method to me) dates_diff, problems include: 1. Mostly ignores PEP-8 about spaces after commas, around operators 2. Checks types 3. Checks types using type(x) == type(y) 4. Inconsistent type checking: checks types in case of dates_diff(date1, date2) but not in case of dates_diff([date1, date2]) 5. Doesn't check for 3 or more args. 6. The 0-arg case is for what purpose? 7. The one-arg case is overkill -- if the caller has the two values in alist, all you are saving them from is the * in dates_diff(*alist) 8. Calling type(date.today()) once per 2-arg call would be a gross extravagance; calling it twice per 2-arg call is mind-boggling. 9. start,end=(targs[0][0],targs[0][1]) ... multiple constant subscripts is a code smell; this one is pongier than usual because it could easily be replaced by start, end = targs[0] Untested fix of problems 1, 3, 4, 5, 8, 9: DATE_TYPE = type(date.today()) def dates_diff(self, *targs): nargs = len(targs) if nargs == 0: return self.enddate - self.startdate if nargs == 1: arg = targs[0] if not isinstance(arg, (list, tuple)) or len(arg) != 2: raise Exception( "single arg must be list or tuple of length 2") start, end = arg elif nargs == 2: start, end = targs else: raise Exception("expected 0,1, or 2 args; found %d" % nargs) if isinstance(start, DATE_TYPE) and isinstance(end, DATE_TYPE): return end - start raise Exception("both values must be of type DATE_TYPE") HTH, John From martin at v.loewis.de Sun Feb 21 04:24:24 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 10:24:24 +0100 Subject: Pure virtual functions in Python? In-Reply-To: <2c9cf10c-90fc-4b08-9f71-a5a7fb1f8a32@m37g2000yqf.googlegroups.com> References: <7uahviFlubU1@mid.uni-berlin.de> <4B801711.7040501@v.loewis.de> <2c9cf10c-90fc-4b08-9f71-a5a7fb1f8a32@m37g2000yqf.googlegroups.com> Message-ID: <4B80FBC8.3070102@v.loewis.de> >> That's not true. Currently, the hasattr() call would report that cb is >> available, when it is actually not implemented. It would be possible to >> do something like >> >> if hasattr(c, 'cb') and not is_pure(c.cb): >> c.cb("Hello", "World") >> >> is_pure could, for example, look at a function attribute of the >> callback. You'd write something like >> >> @pure_virtual >> def cb(self, param1, param2): >> not_implemented >> >> Regards, >> Martin > > Hello Martine, > > Can you elaborate more on how to use the mechanism you described? There are various ways to do it; the one I had in mind uses function attributes: def pure_virtual(func): func.pure_virtual = True # only presence of attribute matters, # not value return func def is_pure(method): # method might be either a method or a function try: func = method.im_func except AttributeError: func = method return hasattr(func, 'pure_virtual') not_implemented = object() # could also write pass instead, or raise HTH, Martin From as at sci.fi Sun Feb 21 04:40:19 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 21 Feb 2010 11:40:19 +0200 Subject: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4 References: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> Message-ID: V8 NUT writes: > /usr/bin/ld: cannot find -lz > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 Could it be you're missing zlib-devel? What does yum info zlib-devel say? Or locate libz? From noamraph at gmail.com Sun Feb 21 04:42:56 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Sun, 21 Feb 2010 01:42:56 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! Message-ID: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> I'm pleased to announce DreamPie 1.0 - a new graphical interactive Python shell! Some highlights: * Has whatever you would expect from a graphical Python shell - attribute completion, tooltips which show how to call functions, highlighting of matching parentheses, etc. * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, history recall and completion works as expected, etc. * Results are saved in the Result History. * Long output is automatically folded so you can focus on what's important. * Jython and IronPython support makes DreamPie a great tool for exploring Java and .NET classes. * You can copy any amount of code and immediately execute it, and you can also copy code you typed interactively into a new file, with the Copy Code Only command. No tabs are used! * Free software licensed under GPL version 3. Check it out at http://dreampie.sourceforge.net/ and tell me what you think! Have fun, Noam From lie.1296 at gmail.com Sun Feb 21 05:21:44 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 21:21:44 +1100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <4b810953$1@dnews.tpgi.com.au> On 02/21/10 19:27, lallous wrote: > If the base defines the method and it was empty, then my C++ code > would still call the function. This is not optimal because I don't > want to go from C++ to Python if the _derived_ class does not > implement the cb. That sounds like a microoptimization; have you profiled your code and determined that calling empty function causes a bottleneck? I doubt it. > Now the base class should define it so that doc > parsers properly describe the base class. > The recipe suggested is not worth the trouble. > Unfortunately I cannot use abc module since I use Python 2.5 Because nobody here could have guessed that your dispatcher was written in C++; your problem is near trivial if your dispatcher is a pure-python code. From lie.1296 at gmail.com Sun Feb 21 05:25:03 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 21:25:03 +1100 Subject: lists of variables In-Reply-To: <4b80b4b4$0$8819$c3e8da3@news.astraweb.com> References: <4b80b4b4$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b810a1a$1@dnews.tpgi.com.au> On 02/21/10 15:21, Steven D'Aprano wrote: >> > So it looks like variables in a list are stored as object references. > Python doesn't store variables in lists, it stores objects, always. > > Even Python variables aren't variables *grin*, although it's really > difficult to avoid using the term. Python variables are mappings between > names (strings) and objects, not memory locations. Actually, no programming languages have used the term "variable" correctly, as per its original mathematical definition. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 06:17:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 11:17:50 GMT Subject: lists of variables References: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b81165e$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 23:44:29 -0800, Carl Banks wrote: > On Feb 20, 10:50?pm, Steven D'Aprano cybersource.com.au> wrote: >> What makes you say that? [...] >> I don't even understand this. [...] >> I'm just confused why you think that >> lexical scoping is equivalent to references that can't be put in lists, >> or why you think this behaviour is any different from lexical scoping >> everywhere else? > http://tinyurl.com/8e7tm Ha ha ha, very amusing. But I was genuinely confused, because I know you're an experienced Python coder and not some n00b, so I thought maybe you were referring to something that escaped me. Your response, apt though it may be, does nothing to clear up my confusion. Presumably if you had a serious response you would have made it, so I'll chalk it up to a generalised confusion field. *wink* -- Steven From aaan at email.dk Sun Feb 21 07:51:36 2010 From: aaan at email.dk (Aage Andersen (REMOVE)) Date: Sun, 21 Feb 2010 13:51:36 +0100 Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <4b812c5b$0$56795$edfadb0f@dtext02.news.tele.dk> I tried to edit the awfully colors, here are the results: Traceback (most recent call last): File "dreampie.py", line 4, () File "dreampielib\gui\__init__.pyc", line 972, main() File "dreampielib\gui\__init__.pyc", line 153, __init__(self=DreamPie(path..."window_main"), pyexec='C:\\Python26\\python.exe') File "dreampielib\gui\__init__.pyc", line 829, configure(self=DreamPie(path..."window_main")) File "dreampielib\gui\tags.pyc", line 224, apply_theme_text(textview=, textbuffer=, theme={('bracket-match', 'bg', 'color'): 'darkblue', ('bracket-match', 'bg', 'isset'): True, ('bracket-match', 'fg', 'color'): 'white', ('bracket-match', 'fg', 'isset'): False, ...}) ValueError: unable to parse colour specification Now the program don't run. Aage From aaan at email.dk Sun Feb 21 08:06:54 2010 From: aaan at email.dk (Aage Andersen (REMOVE)) Date: Sun, 21 Feb 2010 14:06:54 +0100 Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <4b812c5b$0$56795$edfadb0f@dtext02.news.tele.dk> Message-ID: <4b812ff1$0$56776$edfadb0f@dtext02.news.tele.dk> I reinstalled and got this message: Traceback (most recent call last): File "dreampie.py", line 4, () File "dreampielib\gui\__init__.pyc", line 972, main() File "dreampielib\gui\__init__.pyc", line 153, __init__(self=DreamPie(path..."window_main"), pyexec='C:\\Python26\\python.exe') File "dreampielib\gui\__init__.pyc", line 829, configure(self=DreamPie(path..."window_main")) File "dreampielib\gui\tags.pyc", line 224, apply_theme_text(textview=, textbuffer=, theme={('bracket-match', 'bg', 'color'): 'darkblue', ('bracket-match', 'bg', 'isset'): True, ('bracket-match', 'fg', 'color'): 'white', ('bracket-match', 'fg', 'isset'): False, ...}) ValueError: unable to parse colour specification Aage From noamraph at gmail.com Sun Feb 21 08:18:23 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Sun, 21 Feb 2010 05:18:23 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <4b812c5b$0$56795$edfadb0f@dtext02.news.tele.dk> <4b812ff1$0$56776$edfadb0f@dtext02.news.tele.dk> Message-ID: Delete \Documents and Settings\\DreamPie and it should now work. Did you edit the colors using the configuration window or manually? If you edited them using the configuration window, can you give instructions on how to reproduce the bug? Noam On Feb 21, 3:06?pm, "Aage Andersen" wrote: > I reinstalled and got this message: > > Traceback (most recent call last): > ? File "dreampie.py", line 4, () > ? File "dreampielib\gui\__init__.pyc", line 972, main() > ? File "dreampielib\gui\__init__.pyc", line 153, > __init__(self=DreamPie(path..."window_main"), > pyexec='C:\\Python26\\python.exe') > ? File "dreampielib\gui\__init__.pyc", line 829, > configure(self=DreamPie(path..."window_main")) > ? File "dreampielib\gui\tags.pyc", line 224, > apply_theme_text(textview=, > textbuffer=, theme={('bracket-match', 'bg', 'color'): > 'darkblue', ('bracket-match', 'bg', 'isset'): True, ('bracket-match', 'fg', > 'color'): 'white', ('bracket-match', 'fg', 'isset'): False, ...}) > ValueError: unable to parse colour specification > > Aage From lacrima.maxim at gmail.com Sun Feb 21 10:54:31 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Sun, 21 Feb 2010 07:54:31 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> <87tytfbaq6.fsf@benfinney.id.au> Message-ID: On Feb 18, 3:20?am, Ben Finney wrote: > Lacrima writes: > > Right, isolation [of test cases] is essential. But I can't decide to > > which extent I should propagate isolation. > > You used ?propagate? in a sense I don't understand there. > > > For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, > > author suggests that if you do unittesting you should isolate the > > smallest units of code from each other. > > I'm not sure what the author means, but I would say that as it stands > that advice is independent of what testing is being done. In all cases: > > * Make your code units small, so each one is not doing much and is easy > ? to understand. > > * Make the interface of units at each level as narrow as feasible, so > ? they're not brittle in the face of changes to the implementation. > > > For example, if you have a > > class: > > Class SomeClass(object): > > ? ? def method1(self): > > ? ? ? ? return 5 > > ? ? def method2(self): > > ? ? ? ? return self.method1 + 10 > > > According to the book, if you want to test method2, you should isolate > > it from method1 and class instance('self'). > > I don't really know what that means. > > Remember that each test case should not be ?test method1?. That is far > too broad, and in some cases too narrow. There is no one-to-one mapping > between methods and unit test cases. > > Instead, each test case should test one true-or-false assertion about > the behaviour of the code. ?When we start with this initial state (the > test fixture), and perform this operation, the resulting state is that?. > > It makes a lot of sense to name the test case so the assertion being > made *is* its name: not ?test frobnicate? with dozens of assertions, but > one ?test_frobnicate_with_valid_spangulator_returns_true? which makes > that assertion, and extra ones for each distinct assertion. > > The failure of a unit test case should indicate *exactly* what has gone > wrong. If you want to make multiple assertions about a code unit, write > multiple test cases for that unit and name the tests accordingly. > > This incidentally requires that you test something small enough that > such a true-or-false assertion is meaningful, which leads to > well-designed code with small easily-tested code units. But that's an > emergent property, not a natural law. > > > Currently, I don't create mocks of units if they are within the same > > class with the unit under test. If that is not right approach, please, > > explain what are best practices... I am just learning TDD.. > > In the fixture of the unit test case, create whatever test doubles are > necessary to put your code into the initial state you need for the test > case; then tear all those down whatever the result of the test case. > > If you need to create great honking wads of fixtures for any test case, > that is a code smell: your code units are too tightly coupled to > persistent state, and need to be decoupled with narrow interfaces. > > The Python ?unittest? module makes this easier by letting you define > fixtures common to many test cases (the ?setUp? and ?tearDown? > interface). My rule of thumb is: if I need to make different fixtures > for some set of test cases, I write a new test case class for those > cases. > > -- > ?\ ? ? ? ?Following fashion and the status quo is easy. Thinking about | > ? `\ ? ? ? ?your users' lives and creating something practical is much | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?harder.? ?Ryan Singer, 2008-07-09 | > Ben Finney Hi, Ben!!! Sorry for too late reply!!! Thank you very much for sharing your experience! I still have to grasp a lot in TDD. From mensanator at aol.com Sun Feb 21 11:30:27 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 08:30:27 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> On Feb 21, 3:42?am, Noam Yorav-Raphael wrote: > I'm pleased to announce DreamPie 1.0 - a new graphical interactive > Python shell! > What versions of Python does it suuport? From mensanator at aol.com Sun Feb 21 11:32:35 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 08:32:35 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> Message-ID: <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> On Feb 21, 10:30?am, Mensanator wrote: > On Feb 21, 3:42 am, Noam Yorav-Raphael wrote:> I'm pleased to announce DreamPie 1.0 - a new graphical interactive > > Python shell! > > What versions of Python does it suuport? What OS are supported? From skraj23mbec at gmail.com Sun Feb 21 11:46:55 2010 From: skraj23mbec at gmail.com (sk raj) Date: Sun, 21 Feb 2010 08:46:55 -0800 (PST) Subject: Free chat for u.....hot.hot.....hot.............. Message-ID: <1aa805b5-f000-41ba-9718-defd75ee330c@b7g2000pro.googlegroups.com> http://chattingfree.blogspot.com/ From sccolbert at gmail.com Sun Feb 21 11:51:40 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 21 Feb 2010 11:51:40 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> Message-ID: <7f014ea61002210851r52e63cen50b6815ab3a15b2f@mail.gmail.com> http://dreampie.sourceforge.net/download.html reading is a wonderful thing. On Sun, Feb 21, 2010 at 11:32 AM, Mensanator wrote: > On Feb 21, 10:30?am, Mensanator wrote: > > On Feb 21, 3:42 am, Noam Yorav-Raphael wrote:> I'm > pleased to announce DreamPie 1.0 - a new graphical interactive > > > Python shell! > > > > What versions of Python does it suuport? > > What OS are supported? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sccolbert at gmail.com Sun Feb 21 12:13:50 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 21 Feb 2010 12:13:50 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> This is bloody fantastic! I must say, this fixes everything I hate about Ipython and gives me the feature I wished it had (with a few minor exceptions). I confirm this working on Kubuntu 9.10 using the ppa listed on the sites download page. I also confirm that it works interactively with PyQt4 and PyGtk (as to be expected since these toolkits use the PyOS_inputhook for the mainloop). However, it does not work interactively with wx (again, this is as expected since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support is the same as in Ipython if you dont use any of the magic threading switches, which are now deprecated anyway. Matplotlib does not work interactively for me. Is there a special switch that needs to be used? or should a pick a non-wx backend? (i'm thinking the latter is more likely) A couple of things I would like to see (and will help implement if I can find the time): 1) A shortcut to show the docstring of an object. Something like Ipython's `?`. i.e. `object.foo?` translates to `help(object.foo)` 2) How do I change the color of the blinking cursor at the bottom? I can't see the damn thing! 3) line numbers instead of the `>>>` prompt 4) a plugin facility where we can define our own `magic` commands. I use Ipython's %timeit ALL the time. 5) Double-click to re-fold the output section as well. Thanks for making this!!!! Cheers, Chris On Sun, Feb 21, 2010 at 4:42 AM, Noam Yorav-Raphael wrote: > I'm pleased to announce DreamPie 1.0 - a new graphical interactive > Python shell! > > Some highlights: > > * Has whatever you would expect from a graphical Python shell - > attribute completion, tooltips which show how to call functions, > highlighting of matching parentheses, etc. > * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, > history recall and completion works as expected, etc. > * Results are saved in the Result History. > * Long output is automatically folded so you can focus on what's > important. > * Jython and IronPython support makes DreamPie a great tool for > exploring Java and .NET classes. > * You can copy any amount of code and immediately execute it, and you > can also copy code you typed interactively into a new file, with the > Copy Code Only command. No tabs are used! > * Free software licensed under GPL version 3. > > Check it out at http://dreampie.sourceforge.net/ and tell me what you > think! > > Have fun, > Noam > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sun Feb 21 12:28:01 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Feb 2010 09:28:01 -0800 (PST) Subject: Saving the Interactive Window with PythonWin Message-ID: <2485b80a-3d51-4627-95d4-eef6dc7a6445@f29g2000yqa.googlegroups.com> Hi everyone, When I run a python script, I know that I can print the results of my calculations on the Interactive Window. Once the scripts ends, I can copy/pate these results on an OpenOffice Writer document. However, I would like to know if I can somehow add some lines to my script, so that it saves the Interactive Window to a text file. How could it be done? And, is there a way to programatically clear out the Interactive Window so that it only shows the last run? Thank you for your help From iurisilvio at gmail.com Sun Feb 21 12:38:51 2010 From: iurisilvio at gmail.com (Iuri) Date: Sun, 21 Feb 2010 15:38:51 -0200 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: <789aac5a1002210938o513573b3ve3b460ad1a166b74@mail.gmail.com> I tested it in Windows Vista. When I type single or double quotes, I get a unicode character, different of python's quotes, and it break my code. But i liked this tool! Thanks! []s iuri On Sun, Feb 21, 2010 at 3:13 PM, Chris Colbert wrote: > This is bloody fantastic! I must say, this fixes everything I hate about > Ipython and gives me the feature I wished it had (with a few minor > exceptions). > > I confirm this working on Kubuntu 9.10 using the ppa listed on the sites > download page. > > I also confirm that it works interactively with PyQt4 and PyGtk (as to be > expected since these toolkits use the PyOS_inputhook for the mainloop). > However, it does not work interactively with wx (again, this is as expected > since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support > is the same as in Ipython if you dont use any of the magic threading > switches, which are now deprecated anyway. > > Matplotlib does not work interactively for me. Is there a special switch > that needs to be used? or should a pick a non-wx backend? (i'm thinking the > latter is more likely) > > A couple of things I would like to see (and will help implement if I can > find the time): > 1) A shortcut to show the docstring of an object. Something like Ipython's > `?`. i.e. `object.foo?` translates to `help(object.foo)` > 2) How do I change the color of the blinking cursor at the bottom? I can't > see the damn thing! > 3) line numbers instead of the `>>>` prompt > 4) a plugin facility where we can define our own `magic` commands. I use > Ipython's %timeit ALL the time. > 5) Double-click to re-fold the output section as well. > > Thanks for making this!!!! > > Cheers, > > Chris > > > On Sun, Feb 21, 2010 at 4:42 AM, Noam Yorav-Raphael wrote: > >> I'm pleased to announce DreamPie 1.0 - a new graphical interactive >> Python shell! >> >> Some highlights: >> >> * Has whatever you would expect from a graphical Python shell - >> attribute completion, tooltips which show how to call functions, >> highlighting of matching parentheses, etc. >> * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, >> history recall and completion works as expected, etc. >> * Results are saved in the Result History. >> * Long output is automatically folded so you can focus on what's >> important. >> * Jython and IronPython support makes DreamPie a great tool for >> exploring Java and .NET classes. >> * You can copy any amount of code and immediately execute it, and you >> can also copy code you typed interactively into a new file, with the >> Copy Code Only command. No tabs are used! >> * Free software licensed under GPL version 3. >> >> Check it out at http://dreampie.sourceforge.net/ and tell me what you >> think! >> >> Have fun, >> Noam >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Sun Feb 21 12:44:25 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 21 Feb 2010 10:44:25 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: <654D55F2-B276-44E6-A6EF-A9D3A2B5002F@gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <654D55F2-B276-44E6-A6EF-A9D3A2B5002F@gmail.com> Message-ID: <77e831101002210944o2e96bf0aj5370961af959d6a3@mail.gmail.com> @"ssteinerX at gmail.com" "See this article for some more info about the reported sizes of things: http://www.doughellmann.com/PyMOTW/sys/limits.html" I posted this question on stack overflow. I now have a better appreciation of ssteinerX suggestions of the above link and guppy, I also had pympler suggested. http://stackoverflow.com/questions/2306523/reading-text-files-into-list-then-storing-in-dictionay-fills-system-memory-a Thanks again *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 7:15 PM, ssteinerX at gmail.com wrote: > > On Feb 20, 2010, at 8:05 PM, Vincent Davis wrote: > > Code is below, The files are about 5mb and 230,000 rows. When I have 43 > files of them and when I get to the 35th (reading it in) my system gets so > slow that it is nearly functionless. I am on a mac and activity monitor > shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). > The getsizeof() returns 6424 bytes for the alldata . So I am not sure what > is happening. > > > See this article for some more info about the reported sizes of things: > http://www.doughellmann.com/PyMOTW/sys/limits.html > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sun Feb 21 12:53:45 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Feb 2010 09:53:45 -0800 (PST) Subject: formatting a number as percentage Message-ID: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> I'm trying to print .7 as 70% I've tried: print format(.7,'%%') .7.format('%%') but neither works. I don't know what the syntax is... Can you help? Thank you From ssteinerx at gmail.com Sun Feb 21 13:09:51 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 21 Feb 2010 13:09:51 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002210851r52e63cen50b6815ab3a15b2f@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7f014ea61002210851r52e63cen50b6815ab3a15b2f@mail.gmail.com> Message-ID: <202C3A0D-E637-4C46-9CB4-BD288BC8F618@gmail.com> On Feb 21, 2010, at 11:51 AM, Chris Colbert wrote: > http://dreampie.sourceforge.net/download.html > > reading is a wonderful thing. I got it running on OS X with MacPorts after about an hour of installing everything required for gtk and gtksourceview (including a new gcc, apparently). Now...if I can just figure out how to set the font to something I can actually read both size and anti-alias-wise. S > > On Sun, Feb 21, 2010 at 11:32 AM, Mensanator wrote: > On Feb 21, 10:30?am, Mensanator wrote: > > On Feb 21, 3:42 am, Noam Yorav-Raphael wrote:> I'm pleased to announce DreamPie 1.0 - a new graphical interactive > > > Python shell! > > > > What versions of Python does it suuport? > > What OS are supported? > -- > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomf.sessile at gmail.com Sun Feb 21 13:11:19 2010 From: tomf.sessile at gmail.com (TomF) Date: Sun, 21 Feb 2010 10:11:19 -0800 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <2010022110111943658-tomfsessile@gmailcom> On 2010-02-21 09:53:45 -0800, vsoler said: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... >>> print "Grade is {0:%}".format(.87) Grade is 87.000000% or if you want to suppress those trailing zeroes: >>> print "Grade is {0:.0%}".format(.87) Grade is 87% From paul at boddie.org.uk Sun Feb 21 13:14:21 2010 From: paul at boddie.org.uk (Paul Boddie) Date: Sun, 21 Feb 2010 10:14:21 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> Message-ID: <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> On 21 Feb, 17:32, Mensanator wrote: > On Feb 21, 10:30 am, Mensanator wrote: > > > What versions of Python does it suuport? > > What OS are supported? >From the Web site referenced in the announcement (http:// dreampie.sourceforge.net/): """ # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and Python 3.1. # Works on Windows and Linux. """ Paul From sccolbert at gmail.com Sun Feb 21 13:14:57 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 21 Feb 2010 13:14:57 -0500 Subject: formatting a number as percentage In-Reply-To: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <7f014ea61002211014j949dd8dg404fb84b58d66227@mail.gmail.com> >>> print('%.0f%%' % (0.7*100)) 70% On Sun, Feb 21, 2010 at 12:53 PM, vsoler wrote: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... > > Can you help? > > Thank you > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Sun Feb 21 13:15:18 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 21 Feb 2010 10:15:18 -0800 (PST) Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <25c91c15-9710-4edd-8e7f-c2057375be39@g11g2000yqe.googlegroups.com> On Feb 21, 5:53?pm, vsoler wrote: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... Assuming that you're using Python 2.6 (or Python 3.x): >>> format(.7, '%') '70.000000%' >>> format(.7, '.2%') '70.00%' Or see TomF's response for how to use this with the str.format method. -- Mark From vicente.soler at gmail.com Sun Feb 21 13:17:18 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Feb 2010 10:17:18 -0800 (PST) Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> <2010022110111943658-tomfsessile@gmailcom> Message-ID: On Feb 21, 7:11?pm, TomF wrote: > On 2010-02-21 09:53:45 -0800, vsoler said: > > > I'm trying to print .7 as 70% > > I've tried: > > > print format(.7,'%%') > > .7.format('%%') > > > but neither works. I don't know what the syntax is... > >>> print "Grade is {0:%}".format(.87) > > Grade is 87.000000% > > or if you want to suppress those trailing zeroes: > > >>> print "Grade is {0:.0%}".format(.87) > > Grade is 87% Excellent, works perfect!!! From gd_usenet at spamfence.net Sun Feb 21 13:18:05 2010 From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sun, 21 Feb 2010 19:18:05 +0100 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: vsoler wrote: >I'm trying to print .7 as 70% >I've tried: > >print format(.7,'%%') >.7.format('%%') > >but neither works. I don't know what the syntax is... Did you try this: >>> print('%d%%' % (0.7 * 100)) 70% Best regards, G?nther From john at castleamber.com Sun Feb 21 13:22:30 2010 From: john at castleamber.com (John Bokma) Date: Sun, 21 Feb 2010 12:22:30 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> Message-ID: <87mxz2v47t.fsf@castleamber.com> Jonathan Gardner writes: > On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: >> >> Now, why don't we start a PEP to make python a fully-functional language >> then? > > Because people don't think the same way that programs are written in > functional languages. Heh! When I learned Miranda it felt natural to me. Prolog on the other hand... In short: I am afraid you're overgeneralizing here; it depends on one's background. If not, citation needed ;-) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From paul at boddie.org.uk Sun Feb 21 13:28:46 2010 From: paul at boddie.org.uk (Paul Boddie) Date: Sun, 21 Feb 2010 10:28:46 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> Message-ID: <238ce1ab-e216-417f-942f-8776370ef266@u20g2000yqu.googlegroups.com> On 21 Feb, 03:00, "sjdevn... at yahoo.com" wrote: > On Feb 18, 2:58?pm, John Nagle wrote: > > > ? ? Multiple processes are not the answer. ?That means loading multiple > > copies of the same code into different areas of memory. ?The cache > > miss rate goes up accordingly. > > A decent OS will use copy-on-write with forked processes, which should > carry through to the cache for the code. True, but the principal issue with CPython and copy-on-write is the reference counting. Consider a large list shared with the child processes which is to be processed (either in part or in its entirety) by each of them. As soon as the child processes start referencing each of the elements, the reference count for each element object will need to be changed and pages will start to be copied for each child process. That's why John wants to avoid the reference counting of shared data and why the Unladen Swallow project has apparently considered storing reference counts in separate regions of memory. Such shared data is really "owned" by the parent process, so it makes little sense for the child processes to manage it with a view to collecting it later. After all, such data should have no cost to each of the child processes (except, perhaps, for the size of the address space referenced by each process, and any resource issues arising from managing that). Paul From marwie at gmx.de Sun Feb 21 14:07:24 2010 From: marwie at gmx.de (marwie) Date: Sun, 21 Feb 2010 11:07:24 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 21 Feb., 04:40, Steven D'Aprano wrote: > > Additionally, Python lists are over-allocated so that appends are fast. A > list of (say) 1000 items might be over-allocated to (say) 1024 items, so > that you can do 24 appends before the array is full and the array needs > to be resized. This means that, on average, Python list appending is O(1) > instead of O(N). You can't just change the length blindly, you need to > worry about the over-allocation. Ok, I see your point. However, other data representation might still be able to optimize such a multi-element pop. I'm thinking of deques, for example. > I'm sympathetic to your concern: I've often felt offended that doing > something like this: > > x = SomeReallyBigListOrString > for item in x[1:]: > ? ? process(item) > > has to copy the entire list or string (less the first item). But > honestly, I've never found a situation where it actually mattered. Good grief, it copies that, too? I assumed that the copying is at least delayed until the assignment and that x[1:] is represented by some wrapper that just shuffles the indices around (much like the .indices method that MRAB suggested). Maybe copying chunks of data really isn't that much of an issue as it used to be (and maybe I'm getting old). The application I have in mind has to do with symbolic computation, and expressions would be represented by python lists. It's too early to do any profiling (in fact, it's at the "deciding if python is the right language to implement it" stage), but it will have to handle expressions with many terms (i.e. long lists), and in the end taking these lists apart and putting them back together in different order is the only thing the code will do. That to explain my interest in performance issues related to pyhton lists. Anyway, thanks for your help. Martin. From marwie at gmx.de Sun Feb 21 14:08:30 2010 From: marwie at gmx.de (marwie) Date: Sun, 21 Feb 2010 11:08:30 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <2df4ab82-7877-43f5-ac00-a780885e1950@e19g2000prn.googlegroups.com> Message-ID: On 21 Feb., 07:38, Carl Banks wrote: > Numpy arrays can share underlying data like that when you take > slices. ?For instance, this probably works the way you want: > > a = numpy.array([1,2,3,4,5,6]) > b = a[:3] > c = a[3:] > > None of the actual data was copied here. Hmm, that might be worth looking into. Thanks. From python at mrabarnett.plus.com Sun Feb 21 14:29:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Feb 2010 19:29:22 +0000 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4B80B89B.1030109@mrabarnett.plus.com> References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> <4B80B89B.1030109@mrabarnett.plus.com> Message-ID: <4B818992.8060703@mrabarnett.plus.com> MRAB wrote: > Steven D'Aprano wrote: > [snip] >> I'm sympathetic to your concern: I've often felt offended that doing >> something like this: >> >> x = SomeReallyBigListOrString >> for item in x[1:]: >> process(item) >> >> has to copy the entire list or string (less the first item). But >> honestly, I've never found a situation where it actually mattered. >> > [snip] > Could lists gain an .items() method with start and end positions? I was > thinking that it would be a 'view', like with dicts in Python 3. Of > course, that would only be worthwhile with very long lists: > > x = SomeReallyBigListOrString > for item in x.items(1): > process(item) Actually, my example is a bit wrong! My suggestion should have said that the arguments of list.items would resemble those of range: x = SomeReallyBigListOrString for item in x.items(1, None): # [1 : None], or just [1 : ] process(item) Having a third 'stride' argument would also be possible. From m.11ahesh at gmail.com Sun Feb 21 15:24:09 2010 From: m.11ahesh at gmail.com (MY NAME IS MY NAME) Date: Sun, 21 Feb 2010 12:24:09 -0800 (PST) Subject: FOREX : Foreign Exchange Market : FX : Currency Market : Earn Money Quickly. Message-ID: FOREX : Foreign Exchange Market : FX : Currency Market : Earn Money Quickly. Simple Optimized Tips and Tricks, Basics of FOREX to be a king of FOREX in one day. Check out these exclusive never seen tips for free at http://forex-fx-currencymarket.blogspot.com/2010/02/forex-market-size-and-liquidity-showing.html Contents Overview : FOREX : Market Size and Liquidity Showing Top 10 Currency Traders FOREX : Speculation of Currency FOREX : Instruments Financially including Transactions FOREX : FX Rates Determinants as per Government FOREX : Trading Characteristics and Trading Centers FOREX : Market Participants with Access Levels From clp2 at rebertia.com Sun Feb 21 16:18:28 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Feb 2010 13:18:28 -0800 Subject: How would I do a continuous write over a pipe in the following code... In-Reply-To: <2NydneBvv9CPPBzWnZ2dnUVZ_jCdnZ2d@earthlink.com> References: <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com> <2NydneBvv9CPPBzWnZ2dnUVZ_jCdnZ2d@earthlink.com> Message-ID: <50697b2c1002211318s3b437bd0pa13e5f239dfe0e29@mail.gmail.com> On Sun, Feb 21, 2010 at 1:09 PM, Dennis Lee Bieber wrote: > On Sat, 20 Feb 2010 12:46:24 -0800 (PST), chad > declaimed the following in comp.lang.python: > >> Given the following.... >> >> #!/usr/bin/python >> >> import subprocess as s >> >> broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE) >> >> out = broadcast.stdout >> while 1: >> ? ? out > > ? ? ? ?Does nothing... "out" is a name bound to the object identified by > "broadcast.stdout"... > > ? ? ? ?It does nothing unless it is called as... > > ? ? ? ?out(somedata) I'm pretty sure you meant: out.write(somedata) Cheers, Chris -- http://blog.rebertia.com From martin at v.loewis.de Sun Feb 21 16:22:28 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 22:22:28 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <4B81A414.7020001@v.loewis.de> John Nagle wrote: > I know there's a performance penalty for running Python on a > multicore CPU, but how bad is it? I've read the key paper > ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate > if the GIL just limited Python to running on one CPU at a time, > but it's worse than that; there's excessive overhead due to > a lame locking implementation. Running CPU-bound multithreaded > code on a dual-core CPU runs HALF AS FAST as on a single-core > CPU, according to Beasley. I couldn't reproduce these results on Linux. Not sure what "HALF AS FAST" is; I suppose it means "it runs TWICE AS LONG" - this is what I couldn't reproduce. If I run Beazley's program on Linux 2.6.26, on a 4 processor Xeon (3GHz) machine, I get 30s for the sequential execution, 40s for the multi-threaded case, and 32s for the multi-threaded case when pinning the Python process to a single CPU (using taskset(1)). So it's 6% overhead for threading, and 25% penalty for multicore CPUs - far from the 100% you seem to expect. Regards, Martin From debacle at debian.org Sun Feb 21 16:25:11 2010 From: debacle at debian.org (W. Martin Borgert) Date: Sun, 21 Feb 2010 22:25:11 +0100 Subject: Use eval() safely? Message-ID: <20100221212511.GA23046@beron.tangosoft.com> Hi, I know that this issue has been discussed before, but most of the time using only one argument to eval(). Is it possible to use the following code, e.g. run as part of a web application, to break in and if so, how? import math def myeval(untrustedinput): return eval(untrustedinput, {"__builtins__": None}, { "abs": abs, "sin": math.sin }) Is it possible to define functions or import modules from the untrusted input string? Which Python built-ins and math functions would I have to add to the functions dictionary to make it unsafe? TIA! (Please cc me, thanks.) From showell30 at yahoo.com Sun Feb 21 16:40:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 21 Feb 2010 13:40:41 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> Message-ID: <3758eba1-2967-4de3-a3d0-79edc5dd571e@c37g2000prb.googlegroups.com> On Feb 20, 5:55?pm, marwie wrote: > On 21 Feb., 02:30, Steven D'Aprano > cybersource.com.au> wrote: > > Python lists are arrays of pointers to objects, so copying a slice is > > fast: it doesn't have to copy the objects, just pointers. Deleting from > > the end of the list is also quick, because you don't have to move memory, > > just clear some pointers and change the length field. > > > Splitting such an array without copying data is, essentially, impossible. > > Python lists aren't linked lists. > > Well, to split a C array I would simply set l2 to point to l1[10] and > then > change the length of l1 (which I store somewhere else). No copying of > elements > needed. I would have assumed that python can do something like this > with its > internal arrays of pointers, too. > When you remove 10 elements off of a list of size 1000, none of the objects themselves are moved, but the pointers to the objects are all moved, so k*990 bytes get moved backward, where k is the size of a pointer (4 or 8 typically on modern computers). There is no mechanism to advance a pointer forward when you delete or pop from the top. I proposed the following patch to implement an advance-the-pointer scheme, but it is unlikely to be accepted in the near future: http://bugs.python.org/file16034/no_mem_penalty.diff http://bugs.python.org/issue7784 You can find alternative data structures that might serve your needs better, such as collections.deque. If you are interested in how Python lists work internally, you mostly want to look at listobject.c: http://svn.python.org/view/python/trunk/Objects/listobject.c?view=markup In particular, look at list_resize(), list_slice(), and list_ass_slice(). From mensanator at aol.com Sun Feb 21 16:40:54 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 13:40:54 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: On Feb 21, 12:14?pm, Paul Boddie wrote: > On 21 Feb, 17:32, Mensanator wrote: > > > On Feb 21, 10:30 am, Mensanator wrote: > > > > What versions of Python does it suuport? > > > What OS are supported? > > From the Web site referenced in the announcement (http:// > dreampie.sourceforge.net/): > > """ > # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and > Python 3.1. > # Works on Windows and Linux. > """ Yeah, I saw that. Funny that something important like that wasn't part of the announcement. I notice no mention of Mac OS, so visiting the website was a complete waste of time on my part, wasn't it? > Paul From ryan at rfk.id.au Sun Feb 21 16:45:50 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 22 Feb 2010 08:45:50 +1100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4B81A414.7020001@v.loewis.de> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> Message-ID: <1266788750.2990.4.camel@durian> On Sun, 2010-02-21 at 22:22 +0100, Martin v. Loewis wrote: > John Nagle wrote: > > I know there's a performance penalty for running Python on a > > multicore CPU, but how bad is it? I've read the key paper > > ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate > > if the GIL just limited Python to running on one CPU at a time, > > but it's worse than that; there's excessive overhead due to > > a lame locking implementation. Running CPU-bound multithreaded > > code on a dual-core CPU runs HALF AS FAST as on a single-core > > CPU, according to Beasley. > > I couldn't reproduce these results on Linux. Not sure what "HALF AS > FAST" is; I suppose it means "it runs TWICE AS LONG" - this is what I > couldn't reproduce. > > If I run Beazley's program on Linux 2.6.26, on a 4 processor Xeon (3GHz) > machine, I get 30s for the sequential execution, 40s for the > multi-threaded case, and 32s for the multi-threaded case when pinning > the Python process to a single CPU (using taskset(1)). > > So it's 6% overhead for threading, and 25% penalty for multicore CPUs - > far from the 100% you seem to expect. It's far from scientific, but I've seen behaviour that's close to a 100% performance penalty on a dual-core linux system: http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 Short story: a particular test suite of mine used to run in around 25 seconds, but a bit of ctypes magic to set thread affinity dropped the running time to under 13 seconds. 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From bartc at freeuk.com Sun Feb 21 16:54:30 2010 From: bartc at freeuk.com (bartc) Date: Sun, 21 Feb 2010 21:54:30 GMT Subject: lists of variables In-Reply-To: References: Message-ID: "Michael Pardee" wrote in message news:mailman.22.1266722722.4577.python-list at python.org... > I'm relatively new to python and I was very surprised by the following > behavior: > >>>> a=1 >>>> b=2 >>>> mylist=[a,b] >>>> print mylist > [1, 2] >>>> a=3 >>>> print mylist > [1, 2] > > Whoah! Are python lists only for literals? Nope: > >>>> c={} >>>> d={} >>>> mydlist=[c,d] >>>> print mydlist > [{}, {}] >>>> c['x']=1 >>>> print mydlist > [{'x': 1}, {}] > > So it looks like variables in a list are stored as object references. > This seems to confirm that: > > mydlist[1]['y']=4 >>>> print mydlist > [{}, {'y': 4}] > > So I figure my initial example doesn't work because if you assign a That shows a different outlook. I would have said your first example works as expected and it was the second example that was strange, possibly due to shallow instead of deep copies by Python. -- Bartc From ssteinerx at gmail.com Sun Feb 21 17:01:25 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 21 Feb 2010 17:01:25 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <0F03CC9E-6D2C-4D70-8327-5B45D475ED07@gmail.com> On Feb 21, 2010, at 4:40 PM, Mensanator wrote: > On Feb 21, 12:14 pm, Paul Boddie wrote: >> On 21 Feb, 17:32, Mensanator wrote: >> >>> On Feb 21, 10:30 am, Mensanator wrote: >> >>>> What versions of Python does it suuport? >> >>> What OS are supported? >> >> From the Web site referenced in the announcement (http:// >> dreampie.sourceforge.net/): >> >> """ >> # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and >> Python 3.1. >> # Works on Windows and Linux. >> """ > > Yeah, I saw that. Funny that something important like that wasn't part > of the > announcement. I notice no mention of Mac OS, so visiting the website > was a complete > waste of time on my part, wasn't it? See my earlier message -- I have it running just fine on 10.6 with MacPorts and even managed to report a bug! S > >> Paul > > -- > http://mail.python.org/mailman/listinfo/python-list From martin at v.loewis.de Sun Feb 21 17:05:44 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 23:05:44 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> Message-ID: <4B81AE38.50501@v.loewis.de> > It's far from scientific, but I've seen behaviour that's close to a 100% > performance penalty on a dual-core linux system: > > http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 > > Short story: a particular test suite of mine used to run in around 25 > seconds, but a bit of ctypes magic to set thread affinity dropped the > running time to under 13 seconds. Indeed, it's not scientific - but with a few more details, you could improve it quite a lot: what specific Linux distribution (the posting doesn't even say it's Linux), what specific Python version had you been using? (less important) what CPUs? If you can: what specific test suite? A lot of science is about repeatability. Making a systematic study is (IMO) over-valued - anecdotal reports are useful, too, as long as they allow for repeatable experiments. Regards, Martin From martin at v.loewis.de Sun Feb 21 17:05:44 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 23:05:44 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> Message-ID: <4B81AE38.50501@v.loewis.de> > It's far from scientific, but I've seen behaviour that's close to a 100% > performance penalty on a dual-core linux system: > > http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 > > Short story: a particular test suite of mine used to run in around 25 > seconds, but a bit of ctypes magic to set thread affinity dropped the > running time to under 13 seconds. Indeed, it's not scientific - but with a few more details, you could improve it quite a lot: what specific Linux distribution (the posting doesn't even say it's Linux), what specific Python version had you been using? (less important) what CPUs? If you can: what specific test suite? A lot of science is about repeatability. Making a systematic study is (IMO) over-valued - anecdotal reports are useful, too, as long as they allow for repeatable experiments. Regards, Martin From ryan at rfk.id.au Sun Feb 21 17:39:27 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 22 Feb 2010 09:39:27 +1100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4B81AE38.50501@v.loewis.de> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> <4B81AE38.50501@v.loewis.de> Message-ID: <1266791967.4574.16.camel@durian> On Sun, 2010-02-21 at 23:05 +0100, Martin v. Loewis wrote: > > It's far from scientific, but I've seen behaviour that's close to a 100% > > performance penalty on a dual-core linux system: > > > > http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 > > > > Short story: a particular test suite of mine used to run in around 25 > > seconds, but a bit of ctypes magic to set thread affinity dropped the > > running time to under 13 seconds. > > Indeed, it's not scientific - but with a few more details, you could > improve it quite a lot: what specific Linux distribution (the posting > doesn't even say it's Linux), what specific Python version had you been > using? (less important) what CPUs? If you can: what specific test suite? I'm on Ubuntu Karmic, Python 2.6.4, an AMD Athlon 7750 dual core. Unfortunately the test suite is for a proprietary application. I've been able to reproduce similar behaviour with an open-source test suite, using the current trunk of the "pyfilesystem" project: http://code.google.com/p/pyfilesystem/ In this project "OSFS" is an object-oriented interface to the local filesystem. The test case "TestOSFS.test_cases_in_separate_dirs" runs three theads, each doing a bunch of IO in a different directory. Running the tests normally: rfk at durian:/storage/software/fs$ nosetests fs/tests/test_fs.py:TestOSFS.test_cases_in_separate_dirs . ---------------------------------------------------------------------- Ran 1 test in 9.787s That's the best result from five runs - I saw it go as high as 12 seconds. Watching it in top, I see CPU usage at around 150%. Now using threading2 to set the process cpu affinity at the start of the test run: rfk at durian:/storage/software/fs$ nosetests fs/tests/test_fs.py:TestOSFS.test_cases_in_separate_dirs . ---------------------------------------------------------------------- Ran 1 test in 3.792s Again, best of five. The variability in times here is much lower - I never saw it go above 4 seconds. CPU usage is consistently 100%. 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From clp2 at rebertia.com Sun Feb 21 18:18:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Feb 2010 15:18:19 -0800 Subject: with statement and standard library In-Reply-To: <4b81bbf7$0$1659$742ec2ed@news.sonic.net> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> <4b81bbf7$0$1659$742ec2ed@news.sonic.net> Message-ID: <50697b2c1002211518r5ce8c57auf3485ebb52ce33ee@mail.gmail.com> On Sun, Feb 21, 2010 at 3:21 PM, John Nagle wrote: > nobrowser wrote: >> >> Hi. ?The with statement is certainly nifty. ?The trouble is, the >> *only* two documented examples how it can be used with the library >> classes are file objects (which I use all the time) and thread locks >> which I almost never use. ?Yet there are many, many classes in the >> library whose use would be more elegant and readable if the with >> statement could be employed. ?Start with the connection objects in >> httplib and you can probably come up with 10 others easily. > > ? "with" is important for locks because it matters when they're > released. ?It's not as important if release is just resource > recovery. ?Reference counting will recover most objects when they > go out of scope anyway. If you're using CPython that is. The other implementations don't use refcounting and thus don't guarantee the GC will be that timely. So if one wants maximum portability, the `with` statement is *quite* useful. Not to mention there are other uses for `with` besides just freeing resources; e.g. setting a temporary decimal arithmetic context. Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 18:21:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 23:21:27 GMT Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b81bff7$0$8819$c3e8da3@news.astraweb.com> On Sun, 21 Feb 2010 11:07:24 -0800, marwie wrote: >> x = SomeReallyBigListOrString >> for item in x[1:]: >> ? ? process(item) >> >> has to copy the entire list or string (less the first item). But >> honestly, I've never found a situation where it actually mattered. > > Good grief, it copies that, too? I assumed that the copying is at least > delayed until the assignment and that x[1:] is represented by some > wrapper that just shuffles the indices around (much like the .indices > method that MRAB suggested). Such complexity doesn't happen for free. It costs developer time, more complexity means more bugs, and more runtime overhead, especially for small lists. 99.9% of programs operate on small amounts of data, and "small" gets bigger every year. (I was reading one of my old Uni text books the other day, and one of the projects was an application to index all the words in a text file. The author decided to use disk storage rather than in-memory data structures because he was hoping to read files up to 60,000 words, and considered it unlikely that any PCs would have enough memory to store 60,000 words!) Unless you actually profile the code, you're as likely to be *slowing Python down* by such extra sophistication as you are to speed it up. Copying blocks of pointers is really fast on modern CPUs. As a general rule, Python aims for simplicity of implementation rather than clever, but fragile, tricks. > Maybe copying chunks of data really isn't that much of an issue as it > used to be (and maybe I'm getting old). The application I have in mind > has to do with symbolic computation, and expressions would be > represented by python lists. It's too early to do any profiling (in > fact, it's at the "deciding if python is the right language to implement > it" stage), but it will have to handle expressions with many terms (i.e. > long lists), and in the end taking these lists apart and putting them > back together in different order is the only thing the code will do. Are you likely to have expressions with a hundred or so MILLION terms? If so, then you should start thinking about clever tricks to minimise copying. Otherwise, you're engaged in premature optimization, which is the root of all computer science evil :) -- Steven From nagle at animats.com Sun Feb 21 18:21:38 2010 From: nagle at animats.com (John Nagle) Date: Sun, 21 Feb 2010 15:21:38 -0800 Subject: with statement and standard library In-Reply-To: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: <4b81bbf7$0$1659$742ec2ed@news.sonic.net> nobrowser wrote: > Hi. The with statement is certainly nifty. The trouble is, the > *only* two documented examples how it can be used with the library > classes are file objects (which I use all the time) and thread locks > which I almost never use. Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. Start with the connection objects in > httplib and you can probably come up with 10 others easily. "with" is important for locks because it matters when they're released. It's not as important if release is just resource recovery. Reference counting will recover most objects when they go out of scope anyway. Don't get carried away just because a new feature is available. John Nagle From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 18:23:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 23:23:54 GMT Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <4b81c08a$0$8819$c3e8da3@news.astraweb.com> On Sun, 21 Feb 2010 13:40:54 -0800, Mensanator wrote: > Yeah, I saw that. Funny that something important like that wasn't part > of the > announcement. I notice no mention of Mac OS, so visiting the website was > a complete > waste of time on my part, wasn't it? Of course not. Now you know that Mac OS isn't officially supported, so you're less ignorant than you were before you went to the website. But since Dreampie is written in Python, it shouldn't be that hard to have it run on Mac OS, provided you can get the GUI tool kit it requires. -- Steven From greg.ewing at canterbury.ac.nz Sun Feb 21 18:32:47 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 22 Feb 2010 12:32:47 +1300 Subject: lists of variables In-Reply-To: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> References: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7udthfFhrbU1@mid.individual.net> Steven D'Aprano wrote: > On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote: > >>The one place where Python does have references is when accessing >>variables in an enclosing scope (not counting module-level). > > What makes you say that? I think Carl is talking about cells, which *are* actually objects (in CPython at least), but they're internal details of the interpreter, and you can't do anything useful with them from Python code. -- Greg From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 18:33:45 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 23:33:45 GMT Subject: Use eval() safely? References: Message-ID: <4b81c2d9$0$8819$c3e8da3@news.astraweb.com> On Sun, 21 Feb 2010 22:25:11 +0100, W. Martin Borgert wrote: > Hi, > > I know that this issue has been discussed before, but most of the time > using only one argument to eval(). > > Is it possible to use the following code, e.g. run as part of a web > application, to break in and if so, how? > > import math > > def myeval(untrustedinput): > return eval(untrustedinput, {"__builtins__": None}, > { "abs": abs, "sin": math.sin }) > > Is it possible to define functions or import modules from the untrusted > input string? > > Which Python built-ins and math functions would I have to add to the > functions dictionary to make it unsafe? You've got the right idea, but the task is difficult. Please read this thread: http://tav.espians.com/a-challenge-to-break-python-security.html -- Steven From greg.ewing at canterbury.ac.nz Sun Feb 21 18:42:53 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 22 Feb 2010 12:42:53 +1300 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <7udu49Fk3uU1@mid.individual.net> lallous wrote: > If the base defines the method and it was empty, then my C++ code > would still call the function. This is not optimal because I don't > want to go from C++ to Python if the _derived_ class does not > implement the cb. I would simply not implement the method at all in the base class. Then the C++ code can do an attribute lookup for the method, and if it's not found, do nothing. -- Greg From skippy.hammond at gmail.com Sun Feb 21 18:47:34 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 22 Feb 2010 10:47:34 +1100 Subject: Saving the Interactive Window with PythonWin In-Reply-To: <2485b80a-3d51-4627-95d4-eef6dc7a6445@f29g2000yqa.googlegroups.com> References: <2485b80a-3d51-4627-95d4-eef6dc7a6445@f29g2000yqa.googlegroups.com> Message-ID: <4B81C616.5010701@gmail.com> On 22/02/2010 4:28 AM, vsoler wrote: > Hi everyone, > > When I run a python script, I know that I can print the results of my > calculations on the Interactive Window. Once the scripts ends, I can > copy/pate these results on an OpenOffice Writer document. > > However, I would like to know if I can somehow add some lines to my > script, so that it saves the Interactive Window to a text file. How > could it be done? The code for the interactive window is in pywin32\framework\interact.py - eg: >>> from pywin.framework import interact >>> interact.IsInteractiveWindowVisible() True >>> If it is visible, then something like: >>> len(interact.edit.currentView.GetWindowText()) 189 >>> should get you on the right path. > > And, is there a way to programatically clear out the Interactive > Window so that it only shows the last run? Something like: interact.edit.currentView.GetWindowText('line1\nline2\nline3') should work - the first few lines will always be formatted using blue text, and the above works a little strangely when attempting it directly from the interactive prompt, but might still be useful. See the source file I mentioned above for more clues. HTH, Mark > > Thank you for your help From g.bogle at auckland.no.spam.ac.nz Sun Feb 21 19:17:10 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 22 Feb 2010 13:17:10 +1300 Subject: Problem creating executable, with PyQwt Message-ID: My student is trying to build an executable version of a program that uses PyQt and PyQwt, on Windows XP. She has installed: Python 2.6.1, Qt 4.5.0, PyQt 4.5, and PyQwt 5.2.0. There is a module error on running the executable produced by py2exe. Here is the info I got from my student: Traceback (most recent call last): File "ABM15.pyw", line 15, in File "PyQt4\Qwt5\__init__.pyc", line 32, in File "PyQt4\Qwt5\Qwt.pyc", line 12, in File "PyQt4\Qwt5\Qwt.pyc", line 10, in __load ImportError: No module named QtSvg If you Google this last line, you'll find that I've posted this to a forum, but no one answered me. Someone has also had this problem before, although I think they were using PyInstaller and not py2exe. They say that its because Qwt has a hidden import for QtSvg. If I can turn this off, maybe it'll work, but I don't know how. I have downloaded py2exe and I run the attached setup.py file in my working directory. It creates two directories: 'dist' and 'build'. An executable is created in the 'dist' directory along with other things. When I tried running it, it produces a log file, in which I find the error messages. <\quote> Perhaps someone can recognize these symptoms. Thanks, Gib From stef.mientki at gmail.com Sun Feb 21 19:32:21 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 22 Feb 2010 01:32:21 +0100 Subject: Is there a way to continue after an exception ? In-Reply-To: <1266720681.3908.24.camel@durian> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> <4b8097e6$1@dnews.tpgi.com.au> <1266720681.3908.24.camel@durian> Message-ID: <4B81D095.3000303@gmail.com> On 21-02-2010 03:51, Ryan Kelly wrote: > On Sun, 2010-02-21 at 13:17 +1100, Lie Ryan wrote: > >> On 02/21/10 12:02, Stef Mientki wrote: >> >>> On 21-02-2010 01:21, Lie Ryan wrote: >>> >>>>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki >>>>> >> wrote: >> >>>>> >>>>>> hello, >>>>>> >>>>>> I would like my program to continue on the next line after an uncaught >>>>>> exception, >>>>>> is that possible ? >>>>>> >>>>>> thanks >>>>>> Stef Mientki >>>>>> >>>>>> >>>>>> >>>> That reminds me of VB's "On Error Resume Next" >>>> >>>> >>> I think that's what I'm after ... >>> >> A much better approach is to use callbacks, the callbacks determines >> whether to raise an exception or continue execution: >> >> def handler(e): >> if datetime.datetime.now()>= datetime.datetime(2012, 12, 21): >> raise Exception('The world has ended') >> # else: ignore, it's fine >> >> def add_ten_error_if_zero(args, handler): >> if args == 0: >> handler(args) >> return args + 10 >> >> print add_ten_error_if_zero(0, handler) >> print add_ten_error_if_zero(10, handler) >> print add_ten_error_if_zero(0, lambda e: None) # always succeeds >> > > Or if you don't like having to explicitly manage callbacks, you can try > the "withrestart" module: > > http://pypi.python.org/pypi/withrestart/ > > It tries to pinch some of the good ideas from Common Lisp's > error-handling system. > > from withrestart import * > > def add_ten_error_if_zero(n): > # This gives calling code the option to ignore > # the error, or raise a different one. > with restarts(skip,raise_error): > if n == 0: > raise ValueError > return n + 10 > > # This will raise ValueError > print add_ten_error_if_zero(0) > > # This will print 10 > with Handler(ValueError,"skip"): > print add_ten_error_if_zero(0) > > # This will exit the python interpreter > with Handler(ValueError,"raise_error",SystemExit): > print add_ten_error_if_zero(0) > > > > Cheers, > > Ryan > > > thanks Ryan (and others), your description of withstart was very informative, and I think I understand why it's impossible what I want (something like madExcept for Delphi / C / C++, see *http://www.madshi.net/madExceptDescription.htm ) * It are not the bugs that you can predict / expect to catch, but the uncaught bugs. So made some first steps, and this seems to be sufficient for now, if you're interested, look here, http://mientki.ruhosting.nl/data_www/pylab_works/pw_bug_reporter.html cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at boddie.org.uk Sun Feb 21 20:02:22 2010 From: david at boddie.org.uk (David Boddie) Date: Mon, 22 Feb 2010 02:02:22 +0100 Subject: Problem creating executable, with PyQwt References: Message-ID: On Monday 22 February 2010 01:17, Gib Bogle wrote: > > > Traceback (most recent call last): > File "ABM15.pyw", line 15, in > File "PyQt4\Qwt5\__init__.pyc", line 32, in > File "PyQt4\Qwt5\Qwt.pyc", line 12, in > File "PyQt4\Qwt5\Qwt.pyc", line 10, in __load > ImportError: No module named QtSvg > > If you Google this last line, you'll find that I've posted this to a > forum, but no one answered me. Someone has also had this problem before, > although I think they were using PyInstaller and not py2exe. They say that > its because Qwt has a hidden import for QtSvg. If I can turn this off, > maybe it'll work, but I don't know how. > > I have downloaded py2exe and I run the attached setup.py file in my > working directory. It creates two directories: 'dist' and 'build'. An > executable is created in the 'dist' directory along with other things. > When I tried running it, it produces a log file, in which I find the error > messages. > > <\quote> > > Perhaps someone can recognize these symptoms. Someone asked this question on the PyQt mailing list, too: http://www.riverbankcomputing.com/pipermail/pyqt/2010-February/025827.html I believe it was also asked on the #pyqt IRC channel on freenode. I think I have previously referred people with py2exe/PyQt issues to this page on the PyQt Wiki: http://www.py2exe.org/index.cgi/Py2exeAndPyQt If you can somehow convince py2exe to include the QtSvg module (and presumably the libQtSvg library as well) then perhaps that will solve this problem. David From rantingrick at gmail.com Sun Feb 21 20:06:54 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 21 Feb 2010 17:06:54 -0800 (PST) Subject: Apologies -- Test message References: Message-ID: On Feb 21, 12:49?pm, Dennis Lee Bieber wrote: Note: The author of this message requested that it not be archived. This message will be removed from Groups in 6 days (Feb 28, 12:49 pm). I've not seen a message via Gmane in something like 36 hours... and find it hard to believe this group would be that quiet... Could it be that Gmane is giving you a taste of your own (David Copperfield) medicine? From rantingrick at gmail.com Sun Feb 21 20:39:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 21 Feb 2010 17:39:19 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Mensanator snipped: """Yeah, I saw that. Funny that something important like that wasn't part of the announcement. I notice no mention of Mac OS, so visiting the website was a complete waste of time on my part, wasn't it?""" Oh Mensanator, why you always so grumpy? I visited your site a few years ago and i found it to be a complete waste of my time but you don't hear me whining about it do you? Besides mac is always the last to get releases (if any) everybody knows that. If you drive a porsche you can't get all upset every time you find yourself on road with pot- holes, your just not *that* important because you drive a porsche! Please (in the future) leave the ranting to me, i'm better at it ;). Thanks for the release Noam, i look forward to "test driving" it. hehe ;) From philip at semanchuk.com Sun Feb 21 21:08:08 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 21 Feb 2010 21:08:08 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> On Feb 21, 2010, at 8:39 PM, rantingrick wrote: > > > Mensanator snipped: """Yeah, I saw that. Funny that something > important like that wasn't part of the announcement. I notice no > mention of Mac OS, so visiting the website was a complete waste of > time on my part, wasn't it?""" > > Oh Mensanator, why you always so grumpy? I visited your site a few > years ago and i found it to be a complete waste of my time but you > don't hear me whining about it do you? Besides mac is always the last > to get releases (if any) everybody knows that. Erm...not if the developer uses a Mac. =) From anand.shashwat at gmail.com Sun Feb 21 21:10:48 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 07:40:48 +0530 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> Message-ID: Just got it working in mac. Installing dependencies took a bit though. On Mon, Feb 22, 2010 at 7:38 AM, Philip Semanchuk wrote: > > On Feb 21, 2010, at 8:39 PM, rantingrick wrote: > > >> >> Mensanator snipped: """Yeah, I saw that. Funny that something >> important like that wasn't part of the announcement. I notice no >> mention of Mac OS, so visiting the website was a complete waste of >> time on my part, wasn't it?""" >> >> Oh Mensanator, why you always so grumpy? I visited your site a few >> years ago and i found it to be a complete waste of my time but you >> don't hear me whining about it do you? Besides mac is always the last >> to get releases (if any) everybody knows that. >> > > > Erm...not if the developer uses a Mac. =) > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Sun Feb 21 21:32:18 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 21 Feb 2010 21:32:18 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> Message-ID: <69B64EDC-57EB-41CF-BAF4-B2D63E82D80B@gmail.com> On Feb 21, 2010, at 9:10 PM, Shashwat Anand wrote: > Just got it working in mac. Installing dependencies took a bit though. I used macports and it was only 2 installs: # sudo port install py26-pygtksourceview # sudo port install py26-gtk2 It sure did install a lot of other stuff, like a new gcc(?) though; took almost an hour. S > > On Mon, Feb 22, 2010 at 7:38 AM, Philip Semanchuk wrote: > > On Feb 21, 2010, at 8:39 PM, rantingrick wrote: > > > > Mensanator snipped: """Yeah, I saw that. Funny that something > important like that wasn't part of the announcement. I notice no > mention of Mac OS, so visiting the website was a complete waste of > time on my part, wasn't it?""" > > Oh Mensanator, why you always so grumpy? I visited your site a few > years ago and i found it to be a complete waste of my time but you > don't hear me whining about it do you? Besides mac is always the last > to get releases (if any) everybody knows that. > > > Erm...not if the developer uses a Mac. =) > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From g.bogle at auckland.no.spam.ac.nz Sun Feb 21 21:42:40 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 22 Feb 2010 15:42:40 +1300 Subject: Problem creating executable, with PyQwt References: Message-ID: Thanks David. > Someone asked this question on the PyQt mailing list, too: > > http://www.riverbankcomputing.com/pipermail/pyqt/2010-February/025827.html That's my student, Helvin. > > I believe it was also asked on the #pyqt IRC channel on freenode. I think > I have previously referred people with py2exe/PyQt issues to this page on > the PyQt Wiki: > > http://www.py2exe.org/index.cgi/Py2exeAndPyQt > > If you can somehow convince py2exe to include the QtSvg module (and > presumably the libQtSvg library as well) then perhaps that will solve > this problem. I just did a quick test myself, and confirmed that this works for sip. I'm not at all clear what "--includes" arguments might be needed for QtSvg (and libQtSvg). I'll pass this info on to Helvin. Gib From mensanator at aol.com Sun Feb 21 22:44:29 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 19:44:29 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: On Feb 21, 7:39?pm, rantingrick wrote: > Mensanator snipped: """Yeah, I saw that. Funny that something > important like that wasn't part of the announcement. I notice no > mention of Mac OS, so visiting the website was a complete waste of > time on my part, wasn't it?""" > > Oh Mensanator, why you always so grumpy? Part of the job requirements of a gadfly. > I visited your site a few > years ago and i found it to be a complete waste of my time but you > don't hear me whining about it do you? Did I ever claim it wasn't? > Besides mac is always the last > to get releases (if any) everybody knows that. I'm not complaining about the lack of Mac support, just that it wasn't mentioned in the announcement. > If you drive a porsche > you can't get all upset every time you find yourself on road with pot- > holes, your just not *that* important because you drive a porsche! "You're" not getting the point. > Please (in the future) leave the ranting to me, i'm better at it ;). > > Thanks for the release Noam, i look forward to "test driving" it. > hehe ?;) From m.77ahesh at gmail.com Sun Feb 21 23:39:39 2010 From: m.77ahesh at gmail.com (miss world) Date: Sun, 21 Feb 2010 20:39:39 -0800 (PST) Subject: PAPER PRESENTATIONS AND SEMIMAR TOPICS. Message-ID: <671e4c8d-fe7a-42da-ab33-3729d0dcdff1@j27g2000yqn.googlegroups.com> PAPER PRESENTATIONS AND SEMIMAR TOPICS. CHECK OUR VAST PAPER PRESENTATIONS AND SEMIMAR TOPICS INCLUDING PROJECTS FOR FREE AT http://presentationsandseminars.blogspot.com From jgardner at jonathangardner.net Mon Feb 22 00:15:43 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sun, 21 Feb 2010 21:15:43 -0800 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4b80d744$0$8819$c3e8da3@news.astraweb.com> References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> <4b80d744$0$8819$c3e8da3@news.astraweb.com> Message-ID: <6cc20cea1002212115v2c03d014x110291453f53e049@mail.gmail.com> On Sat, Feb 20, 2010 at 10:48 PM, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 21:21:47 -0800, Jonathan Gardner wrote: >> For ten items, though, is it really faster to muck around with array >> lengths than just copying the data over? Array copies are extremely fast >> on modern processors. > > My mistake, he actually wants l1[10:] copied. So you might be copying a > huge amount of data, not just ten items. > > Or if you prefer, replace 10 by 100000000. > If you need to scale that direction, it's time to install a database. >> Programmer time and processor time being what it is, I still think my >> answer is the correct one. No, it's not what he says he wants, but it is >> what he needs. > > You missed the point that your suggestion gives radically different > behaviour to what the OP indicated he is using. He mutates the list in > place, you rebind the list's name. That has *very* different semantics. > > > The OP may not care about the difference, but if he does require the > first behaviour, then your solution doesn't help. > Correct. -- Jonathan Gardner jgardner at jonathangardner.net From greg.ewing at canterbury.ac.nz Mon Feb 22 00:45:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 22 Feb 2010 18:45:40 +1300 Subject: Use eval() safely? In-Reply-To: References: Message-ID: <7uejcjFgf6U1@mid.individual.net> W. Martin Borgert wrote: > def myeval(untrustedinput): > return eval(untrustedinput, {"__builtins__": None}, > { "abs": abs, "sin": math.sin }) > > Is it possible to define functions or import modules from the > untrusted input string? This is NOT safe as it stands. It still isn't safe even if you put nothing in the globals dict at all. A couple of ways someone can do nasty things to you: # Wipe out any file writable by the calling process eval("[c for c in (0).__class__.__bases__[0].__subclasses__() if c.__name__ == 'file'][0]('/my/precious/file', 'w')") # Use up large amounts of memory and CPU time eval("100000**100000") -- Greg From steven at REMOVE.THIS.cybersource.com.au Mon Feb 22 01:07:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Feb 2010 06:07:05 GMT Subject: Use eval() safely? References: <7uejcjFgf6U1@mid.individual.net> Message-ID: On Mon, 22 Feb 2010 18:45:40 +1300, Gregory Ewing wrote: > W. Martin Borgert wrote: > >> def myeval(untrustedinput): >> return eval(untrustedinput, {"__builtins__": None}, >> { "abs": abs, "sin": math.sin }) >> >> Is it possible to define functions or import modules from the untrusted >> input string? > > This is NOT safe as it stands. It still isn't safe even if you put > nothing in the globals dict at all. It's *especially* not safe if you put nothing in the globals dict, because Python kindly rectifies that by putting the builtins into it: >>> eval("__builtins__.keys()", {}, {}) ['IndexError', 'all', 'help', 'vars', ... 'OverflowError'] >>> eval("globals()", {}, {}) {'__builtins__': {...}} >>> >>> eval("globals()", {'__builtins__': None}, {}) Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'globals' is not defined So {'__builtins__': None} is safer than {}. Still not safe, exactly, but safer. Or at least you make the Black Hats work harder before they own your server :) -- Steven From norman at smash-net.org Mon Feb 22 01:49:51 2010 From: norman at smash-net.org (=?ISO-8859-1?Q?Norman_Rie=DF?=) Date: Mon, 22 Feb 2010 07:49:51 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: <4B82290F.9000508@smash-net.org> Am 02/21/10 22:09, schrieb Dennis Lee Bieber: > On Sat, 20 Feb 2010 23:12:50 +0100, Norman Rie? > declaimed the following in comp.lang.python: > > >> Hello, >> >> i am trying to read a large bz2 compressed textfile using the bz2 module. >> The file is 1717362770 lines long and 8GB large. >> Using this code >> >> source_file = bz2.BZ2File(file, "r") >> for line in source_file: >> print line.strip() >> >> print "Exiting" >> print "I used file: " + file >> >> the loop exits cleanly after 4311 lines in midline and the prints are >> executed. >> This happened on two different boxes runnig different brands of linux. >> Is there something i miss or should be done differently? >> >> > Please verify your indentation! What you posted above is invalid in > many ways. > I am sorry, the indentation suffered from pasting. This is the actual code: source_file = bz2.BZ2File(file, "r") for line in source_file: print line.strip() print "Exiting" print "I used file: " + file From steven at REMOVE.THIS.cybersource.com.au Mon Feb 22 03:02:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Feb 2010 08:02:01 GMT Subject: Reading a large bz2 textfile exits early References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: > This is the actual code: > > source_file = bz2.BZ2File(file, "r") > for line in source_file: > print line.strip() > > print "Exiting" > print "I used file: " + file Have you verified that the bz file is good by opening it in another application? -- Steven From norman at smash-net.org Mon Feb 22 03:43:17 2010 From: norman at smash-net.org (=?UTF-8?B?Tm9ybWFuIFJpZcOf?=) Date: Mon, 22 Feb 2010 09:43:17 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: <4B8243A5.20201@smash-net.org> Am 02/22/10 09:02, schrieb Steven D'Aprano: > On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: > > >> This is the actual code: >> >> source_file = bz2.BZ2File(file, "r") >> for line in source_file: >> print line.strip() >> >> print "Exiting" >> print "I used file: " + file >> > > Have you verified that the bz file is good by opening it in another > application? > > > > Yes, bzcat is running through the file fine. And piping bzcat output into the python script reading stdin works fine, too. From jasminsweety145 at gmail.com Mon Feb 22 05:01:18 2010 From: jasminsweety145 at gmail.com (jasmin sweety) Date: Mon, 22 Feb 2010 02:01:18 -0800 (PST) Subject: %%% Anuksha navel & smootched by the Hero V----? %%% Message-ID: %%% Anuksha navel & smootched by the Hero V----? %%% http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ From danijel.gvero at gmail.com Mon Feb 22 05:48:55 2010 From: danijel.gvero at gmail.com (DANNY) Date: Mon, 22 Feb 2010 02:48:55 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> Message-ID: <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> On Feb 21, 1:54?am, Tim Roberts wrote: > DANNY wrote: > > >If I want to have a MPEG-4/10 coded video and stream it through the > >network and than have the same video on the client side, what should I > >use and of course I don't want to have raw MPEG data, because than I > >couldn't extract the frames to manipulate them. > > If you want to manipulate the frames (as bitmaps), then you have little > choice but to decode the MPEG as you receive it, manipulate the bitmaps, > and re-encode it back to MPEG. > > That's going to take a fair amount of time... > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Yes, well beside bieng time-consuming, that is also inappropriate for me, because I want to have clip that would be streamed across the network and have the same GoP on the client side as the original-because I want to see what is the effect of errors on different GoP sizes. I would manipuleta the received clip just in the way that (if there are too many errors) I would stop displaying untill the next I frame.....I cant find a way to do that....is there a way? From luke.leighton at googlemail.com Mon Feb 22 05:54:01 2010 From: luke.leighton at googlemail.com (lkcl) Date: Mon, 22 Feb 2010 02:54:01 -0800 (PST) Subject: What happened to pyjamas? References: <6a8e506c-63df-482b-a39d-148e6217ba2c@o3g2000yqb.googlegroups.com> Message-ID: On Feb 19, 2:43 pm, John Pinner wrote: > It appears that, in trying to cut down spm, somone chahnged a DNS > entry and screwed it up : it shouldbe back before long. yep. i've now got access to the web interface for the dns whois records. they got poo'd up (only one entry) and then the person who made the changes was ill for a couple of days. i needed to change the DNS server to one that i control (rather than a "dumb" get-free-hosting-for-?1.99-a-month provider so that i could add http://wiki.pyjs.org (using a pyjamas-based wiki of course), move away from sourceforge VHOSTS, and generally set things up a little bit better. l. From luke.leighton at googlemail.com Mon Feb 22 05:58:17 2010 From: luke.leighton at googlemail.com (lkcl) Date: Mon, 22 Feb 2010 02:58:17 -0800 (PST) Subject: look at the google code References: Message-ID: <711cb713-4b4a-47f6-8922-ce1ada7d64e6@e1g2000yqh.googlegroups.com> On Feb 19, 10:41 am, Allison Vollmann wrote: > http://code.google.com/p/pyjamas/ > > Last update from yesterday, is the same project? only the tarballs are maintained on there, and the wiki and the issue tracker. we couldn't get control of that site for quite some time so started using sourceforget for svn, but the issue tracker on sourceforget is truly dreadful. basically there's bits of pyjamas splattered all over the place in a pick-n-mix setup :) mostly this is for the convenience of the key developers - welcome to free software, where the developers do what they like because it makes _their_ lives easier... l. From karthigacool at gmail.com Mon Feb 22 08:16:42 2010 From: karthigacool at gmail.com (karthiga madhan) Date: Mon, 22 Feb 2010 05:16:42 -0800 (PST) Subject: insurance, life insurance, home insurance and their benefits www.autoinsurance-2010.blogspot.com Message-ID: <28263151-ebd7-4aa3-a79a-e741ee3bdfa5@z10g2000prh.googlegroups.com> insurance, life insurance, home insurance and their benefits www.autoinsurance-2010.blogspot.com From lie.1296 at gmail.com Mon Feb 22 08:29:55 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Feb 2010 00:29:55 +1100 Subject: Reading a large bz2 textfile exits early In-Reply-To: References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: <4b8286ec$1@dnews.tpgi.com.au> On 02/22/10 19:43, Norman Rie? wrote: > Am 02/22/10 09:02, schrieb Steven D'Aprano: >> On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: >> >> >>> This is the actual code: >>> >>> source_file = bz2.BZ2File(file, "r") >>> for line in source_file: >>> print line.strip() >>> >>> print "Exiting" >>> print "I used file: " + file >>> >> >> Have you verified that the bz file is good by opening it in another >> application? >> >> >> >> > > Yes, bzcat is running through the file fine. And piping bzcat output > into the python script reading stdin works fine, too. test with using something other than bzcat; bzcat does certain things differently because of the way it works (a cat for bzipped file). Try using plain "bunzip2 filename.bz2" From albert at spenarnc.xs4all.nl Mon Feb 22 08:44:02 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Feb 2010 13:44:02 GMT Subject: Modifying Class Object References: Message-ID: In article , Steve Holden wrote: >Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >> [snip] >>>> >>>> Since in the quoting above no reference to definition of "pointer" >>>> remains: "pointer" refers to a copyable reference value as seen from the >>>> Python level, in the same way as "pointer" is used by e.g. the Java >>>> language spec. >>>> >> [snip] >>>> >>>> If so, then that's correct: a Python (or Java, or whatever language) >>>> pointer is not necessarily directly a memory address, and furthermore id >>>> is not guaranteed to reproduce the bits of a pointer value -- which >>>> might not even make sense. >>>> >>>> All that id does is to produce a value that uniquely identifies the >>>> object pointed to, i.e. it corresponds to the pointer value, and >>>> although in CPython that's simply the bits of a C pointer typed as >>>> integer, in IronPython it's not. >>>> >>> You go too far here. What you are referring to in your bizarrely >>> constructed definition above >> >> No, it's not bizarre, it's the standard general language independent >> definition. >> >*The* standard general language independent definition? As defined >where? The id() value doesn't "correspond to the pointer value", it >corresponds to the object. Why you see the need for this indirection >remains a mystery. No it doesn't. If an object is garbage collected, the id() might be recycled. At that time the id() corresponds to quite a different object. OTOH if you kill an object in Python it is gone forever. Of course there is a standard computer science idea of what a pointer is. If you admit the pointer terminology, you can understand that a pointer value is all what id() can tell us. You seem to subsconsciously substitute "assembler language address" for it. When someone says: "pointers are bad" what really meant is "manipulating assembler language addresses in a high level language is bad". (Everybody agrees, but sometimes you must use e.g. c as sort of assembler.) That is not the kind of pointers we're talking about here. (I once studied algol 68, and never got confused about these subjects anymore, recommended.) > >regards > Steve >-- > Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From hidura at gmail.com Mon Feb 22 09:03:32 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Mon, 22 Feb 2010 14:03:32 +0000 Subject: Problem with __init__.py in Python3.1 In-Reply-To: <4bbf7fb21002041810xc9bf899v1827ff83abb67c44@mail.gmail.com> Message-ID: <001485e7c7b6fad3a9048030e5e1@google.com> For finnished the subject i resolve the problem using the PEP-328, i was using the old kind of imports :s On Feb 4, 2010 10:10pm, Hidura wrote: > Thanks i middle resolve the problem, and i going to read the PEP-366 i've > been read the 328, i will kept informed of the progresses. > Thanks again for the help > On Thu, Feb 4, 2010 at 6:47 PM, Ben Finney ben+python at benfinney.id.au> > wrote: > "Gabriel Genellina" gagsl-py2 at yahoo.com.ar> writes: > > If you directly run a script from inside a package, Python does not > > know that it belongs to a package, and treats it as a simple, lonely > > script. In that case, relative imports won't work. > Which I consider to be a bug. Fortunately, it's already addressed in PEP > 366 http://www.python.org/dev/peps/pep-0366/>. Unfortunately, it > involves more hackish boilerplate at the top of the program, and is only > available in Python 2.6+. > -- > \ ?Ignorance more frequently begets confidence than does | > `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -- > Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: From icanbob at gmail.com Mon Feb 22 09:40:15 2010 From: icanbob at gmail.com (bobicanprogram) Date: Mon, 22 Feb 2010 06:40:15 -0800 (PST) Subject: ANN: Python-SIMPL v2.0.0 released Message-ID: <964d1dcb-46a9-40a5-ab41-199fd1e364a7@t21g2000vbo.googlegroups.com> The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the Send/Receive/Reply messaging (first popularized by QNX) to the open source Linux world. Since its inception more that 10 years ago, the SIMPL toolkit has grown steadily in functionality. Through the use of surrogates, SIMPL modules can be dispersed seamlessly across networks including heterogeneous networks with only one Linux node. SIMPL modules can also be written in several programming languages including Python, C, C++, JAVA and Tcl/Tk. Modules written in different languages can be mixed in a SIMPL appliction. Python-SIMPL has been used to connect Python UIs to C data acquisition/ computation backends. While this is an example of a common use for the toolkit, it is by no means the only place it could be useful. Python to Python, Python to JAVA as well as Python to C are all seamlessly possible in both local or distributed applications. Python- SIMPL allows a software application to be broken up into modules where the language choices for each module can be optimized. The Python-SIMPL interface library has undergone a fundamental revision with the v2.0.0 release. The underlying shared library which wraps the SIMPL toolkit as a Python extension was cleaned up considerably. In addition two new Python wrappers were created to expose this SIMPL toolkit in more object oriented fashion to the Python developer. The simplest starting point for exploring the Python-SIMPL toolkit is an online "hello world" level tutorial at: http://www.icanprogram.com/06py/lesson1/lesson1.html The Python-SIMPL toolkit can be downloaded in source form at: http://www.icanprogram.com/simpl/python.self.htm or in precompiled binary (i386) form at: http://www.icanprogram.com/simpl/pythonbin.self.html We at the SIMPL project welcome participants at all levels of expertise. If you are interested do not hesitate to contact us. bob From wolftracks at invalid.com Mon Feb 22 10:22:02 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 07:22:02 -0800 Subject: What's Going on between Python and win7? Message-ID: Last night I copied a program from folder A to folder B. It inspects the contents of files in a folder. When I ran it in B, it gave the results for A! Out of frustration I changed the name in A, and fired up the program in B. Win7 went into search mode for the file. I looked at properties for the B program, and it was clearly pointing to folder A. Anyone have this happen to them? Another anomaly. I have the files track.py and trackstudy.py in the same folder along with 100 or so other py and txt data files. When I did a search from the folder window in the upper right corner, search only found one of the two. I called HP tech support about it, and they could see it for themselves via remote control. They had no idea, but agreed to contact MS. In this case, I noted that this search box has some sort of filter associated with it. Possibly, in my early stages of learning to navigate in Win7, I accidentally set the filter. Comments? From norman at smash-net.org Mon Feb 22 10:38:24 2010 From: norman at smash-net.org (=?UTF-8?B?Tm9ybWFuIFJpZcOf?=) Date: Mon, 22 Feb 2010 16:38:24 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: <4b8286ec$1@dnews.tpgi.com.au> References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> <4b8286ec$1@dnews.tpgi.com.au> Message-ID: <4B82A4F0.3010403@smash-net.org> Am 02/22/10 14:29, schrieb Lie Ryan: > On 02/22/10 19:43, Norman Rie? wrote: > >> Am 02/22/10 09:02, schrieb Steven D'Aprano: >> >>> On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: >>> >>> >>> >>>> This is the actual code: >>>> >>>> source_file = bz2.BZ2File(file, "r") >>>> for line in source_file: >>>> print line.strip() >>>> >>>> print "Exiting" >>>> print "I used file: " + file >>>> >>>> >>> Have you verified that the bz file is good by opening it in another >>> application? >>> >>> >>> >>> >>> >> Yes, bzcat is running through the file fine. And piping bzcat output >> into the python script reading stdin works fine, too. >> > test with using something other than bzcat; bzcat does certain things > differently because of the way it works (a cat for bzipped file). Try > using plain "bunzip2 filename.bz2" > Did that too. Works as expected. From krister.svanlund at gmail.com Mon Feb 22 10:43:07 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 22 Feb 2010 16:43:07 +0100 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: <2cf430a61002220743j4d00a7cdt828122a67f016025@mail.gmail.com> On Mon, Feb 22, 2010 at 4:22 PM, W. eWatson wrote: > Last night I copied a program from folder A to folder B. It inspects the > contents of files in a folder. When I ran it in B, it gave the results for > A! Out of frustration I changed the name in A, and fired up the program in > B. Win7 went into search mode for the file. I looked at properties for the B > program, and it was clearly pointing to folder A. > > Anyone have this happen to them? > > Another anomaly. I have the files track.py and trackstudy.py in the same > folder along with 100 or so other py and txt data files. When I did a search > from the folder window in the upper right corner, search only found one of > the two. I called HP tech support about it, and they could see it for > themselves via remote control. They had no idea, but agreed to ?contact MS. > In this case, I noted that this search box has some sort of filter > associated with it. Possibly, in my early stages of learning to navigate in > Win7, I accidentally set the filter. > > Comments? I can't really see the python related problem here... From python at mrabarnett.plus.com Mon Feb 22 11:01:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 16:01:34 +0000 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: <4B82AA5E.10407@mrabarnett.plus.com> W. eWatson wrote: > Last night I copied a program from folder A to folder B. It inspects the > contents of files in a folder. When I ran it in B, it gave the results > for A! Out of frustration I changed the name in A, and fired up the > program in B. Win7 went into search mode for the file. I looked at > properties for the B program, and it was clearly pointing to folder A. > Sounds like you didn't copy it but made a shortcut to it instead. > Anyone have this happen to them? > > Another anomaly. I have the files track.py and trackstudy.py in the same > folder along with 100 or so other py and txt data files. When I did a > search from the folder window in the upper right corner, search only > found one of the two. I called HP tech support about it, and they could > see it for themselves via remote control. They had no idea, but agreed > to contact MS. In this case, I noted that this search box has some sort > of filter associated with it. Possibly, in my early stages of learning > to navigate in Win7, I accidentally set the filter. > > Comments? Not Python-related. From invalid at invalid.invalid Mon Feb 22 11:29:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 16:29:47 +0000 (UTC) Subject: What's Going on between Python and win7? References: Message-ID: On 2010-02-22, W. eWatson wrote: > Last night I copied a program from folder A to folder B. [tail of various windows breakages elided] > Comments? Switch to Linux? Or at least install Cygwin? -- Grant Edwards grante Yow! Maybe I should have at asked for my Neutron Bomb visi.com in PAISLEY -- From mail at hellmutweber.de Mon Feb 22 11:32:11 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Mon, 22 Feb 2010 17:32:11 +0100 Subject: A tool for find dependencies relationships behind Python projects In-Reply-To: References: Message-ID: <4B82B18B.3020707@hellmutweber.de> Hi Victor, I would be intereseted to use your tool ;-) My system is Sabayon-5.1 on Lenovo T61. Trying for the first time easy_install I get the following error: ==================== root at sylvester ~ # easy_install gluttony Searching for gluttony Reading http://pypi.python.org/simple/gluttony/ Reading http://code.google.com/p/python-gluttony/ Best match: Gluttony 0.3 Downloading http://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md5=c7774d4fcc0402097f90dc81186de465 Processing Gluttony-0.3.zip Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD Traceback (most recent call last): File "/usr/bin/easy_install", line 9, in load_entry_point('distribute==0.6.8', 'console_scripts', 'easy_install')() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1708, in main with_ei_usage(lambda: File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1696, in with_ei_usage return f() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1712, in distclass=DistributionWithoutHelpCommands, **kw File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 236, in run self.easy_install(spec, not self.no_deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 471, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 501, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 680, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 957, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 946, in run_setup run_setup(setup_script, args) File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 29, in run_setup lambda: execfile( File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 70, in run return func() File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 31, in {'__file__':setup_script, '__name__':'__main__'} File "setup.py", line 9, in File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", line 1, in # File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", line 13, in ImportError: No module named pip.log root at sylvester ~ # ==================== I emerged app-misc/pip, but that didn't help, the error remains the same What is missing? Any help appreciated Best regards Hellmut Am 19.02.2010 17:16, schrieb Victor Lin: > Hi, > > I just wrote a tool for drawing dependencies relationships diagram of > Python project on Pypi. Here is the home page of the tool: > > http://code.google.com/p/python-gluttony/ > > Some examples: > Sprox: > http://static.ez2learn.com/gluttony/sprox_dot.png > > TurboGears2: > http://static.ez2learn.com/gluttony/tg2_dot.png > > Hope this could be helpful :P > > Regards. > Victor Lin. -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From bryanvick at gmail.com Mon Feb 22 11:32:36 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 08:32:36 -0800 (PST) Subject: Efficiently building ordered dict Message-ID: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is there a way I can avoid creating the first unordered dict just to get the ordered dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster. Is there a better idiom that the code below to create an ordered dict from an unordered list? unorderedDict = {} for thing in unorderedList: if thing.id in unorderedDict: UpdateExistingValue(unorderedDict[thing.id]) else: CreateNewValue(unorderedDict[thing.id]) orderedDict = OrderedDict() for k in sorted(unorderedDict.keys()): orderedDict[k] unorderedDict.pop(k) From anand.shashwat at gmail.com Mon Feb 22 11:49:42 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:19:42 +0530 Subject: A tool for find dependencies relationships behind Python projects In-Reply-To: <4B82B18B.3020707@hellmutweber.de> References: <4B82B18B.3020707@hellmutweber.de> Message-ID: Same issue here, easy_install fails here is traceback, Shashwat-Anands-MacBook-Pro:Downloads l0nwlf$ easy_install gluttony Searching for gluttony Reading http://pypi.python.org/simple/gluttony/ Reading http://code.google.com/p/python-gluttony/ Best match: Gluttony 0.3 Downloading http://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md5=c7774d4fcc0402097f90dc81186de465 Processing Gluttony-0.3.zip Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir /var/folders/Hm/Hmz8Y9rDEXqrbr8IUNiNiU+++TI/-Tmp-/easy_install-zlrBGJ/Gluttony-0.3/egg-dist-tmp-N3AofQ Traceback (most recent call last): File "/usr/bin/easy_install-2.6", line 10, in load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')() File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 1671, in main File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 1659, in with_ei_usage File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 1675, in File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 211, in run File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 446, in easy_install File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 476, in install_item File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 655, in install_eggs File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 930, in build_and_install File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 919, in run_setup File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/sandbox.py", line 27, in run_setup File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/sandbox.py", line 63, in run File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/sandbox.py", line 29, in File "setup.py", line 9, in File "/var/folders/Hm/Hmz8Y9rDEXqrbr8IUNiNiU+++TI/-Tmp-/easy_install-zlrBGJ/Gluttony-0.3/gluttony/__init__.py", line 1, in File "/var/folders/Hm/Hmz8Y9rDEXqrbr8IUNiNiU+++TI/-Tmp-/easy_install-zlrBGJ/Gluttony-0.3/gluttony/gluttony.py", line 13, in ImportError: No module named pip.log On Mon, Feb 22, 2010 at 10:02 PM, Hellmut Weber wrote: > Hi Victor, > I would be intereseted to use your tool ;-) > > My system is Sabayon-5.1 on Lenovo T61. > Trying for the first time easy_install I get the following error: > > ==================== > > root at sylvester ~ # easy_install gluttony > Searching for gluttony > Reading http://pypi.python.org/simple/gluttony/ > Reading http://code.google.com/p/python-gluttony/ > Best match: Gluttony 0.3 > > Downloading > http://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md5=c7774d4fcc0402097f90dc81186de465 > Processing Gluttony-0.3.zip > Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD > Traceback (most recent call last): > File "/usr/bin/easy_install", line 9, in > load_entry_point('distribute==0.6.8', 'console_scripts', > 'easy_install')() > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1708, in main > with_ei_usage(lambda: > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1696, in with_ei_usage > return f() > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1712, in > distclass=DistributionWithoutHelpCommands, **kw > File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup > dist.run_commands() > File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands > self.run_command(cmd) > File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command > cmd_obj.run() > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 236, in run > self.easy_install(spec, not self.no_deps) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 471, in easy_install > return self.install_item(spec, dist.location, tmpdir, deps) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 501, in install_item > dists = self.install_eggs(spec, download, tmpdir) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 680, in install_eggs > return self.build_and_install(setup_script, setup_base) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 957, in build_and_install > self.run_setup(setup_script, setup_base, args) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 946, in run_setup > run_setup(setup_script, args) > File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 29, > in run_setup > lambda: execfile( > File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 70, > in run > return func() > File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 31, > in > {'__file__':setup_script, '__name__':'__main__'} > File "setup.py", line 9, in > File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", line 1, > in > # > File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", line > 13, in > ImportError: No module named pip.log > root at sylvester ~ # > > ==================== > > I emerged app-misc/pip, but that didn't help, the error remains the same > > What is missing? > > Any help appreciated > > Best regards > > Hellmut > > > Am 19.02.2010 17:16, schrieb Victor Lin: > > Hi, >> >> I just wrote a tool for drawing dependencies relationships diagram of >> Python project on Pypi. Here is the home page of the tool: >> >> http://code.google.com/p/python-gluttony/ >> >> Some examples: >> Sprox: >> http://static.ez2learn.com/gluttony/sprox_dot.png >> >> TurboGears2: >> http://static.ez2learn.com/gluttony/tg2_dot.png >> >> Hope this could be helpful :P >> >> Regards. >> Victor Lin. >> > > -- > Dr. Hellmut Weber mail at hellmutweber.de > Degenfeldstra?e 2 tel +49-89-3081172 > D-80803 M?nchen-Schwabing mobil +49-172-8450321 > please: No DOCs, no PPTs. why: tinyurl.com/cbgq > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Mon Feb 22 11:51:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:21:52 +0530 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: Programming is most fruiful in *nix environment. On Mon, Feb 22, 2010 at 9:59 PM, Grant Edwards wrote: > On 2010-02-22, W. eWatson wrote: > > > Last night I copied a program from folder A to folder B. > > [tail of various windows breakages elided] > > > Comments? > > Switch to Linux? > > Or at least install Cygwin? > > -- > Grant Edwards grante Yow! Maybe I should have > at asked for my Neutron Bomb > visi.com in PAISLEY -- > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiraank at gmail.com Mon Feb 22 11:53:06 2010 From: kiraank at gmail.com (KIRAN) Date: Mon, 22 Feb 2010 08:53:06 -0800 (PST) Subject: Files required for porting python Message-ID: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Hi ALL, I am newbie to python and wanted to port python on to some RTOS. The RTOS I am trying to port python is not posix compliant. First, I decided to port python on to windows and later I will port the same to my target system. [ This is just to minimize the effort being put port, debug and to stabilize]. I downloaded 2.6.1 python code and started looking through the code. I see lot of code with several files. I am not sure which code I should start with. Any help / link regarding this is appreciated. Thanks, Kiran From anand.shashwat at gmail.com Mon Feb 22 11:55:55 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:25:55 +0530 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: OrderedDict is a class in collection module in python 2.7a3+. Perhaps you can use it from there. >>> dir(collections) ['Callable', 'Container', 'Counter', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping', 'MappingView', 'MutableMapping', 'MutableSequence', 'MutableSet', 'OrderedDict', 'Sequence', 'Set', 'Sized', 'ValuesView', '_Link', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_abcoll', '_chain', '_eq', '_heapq', '_ifilter', '_imap', '_iskeyword', '_itemgetter', '_proxy', '_repeat', '_starmap', '_sys', 'defaultdict', 'deque', 'namedtuple'] ~l0nwlf On Mon, Feb 22, 2010 at 10:02 PM, Bryan wrote: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) > > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Mon Feb 22 12:00:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:30:12 +0530 Subject: Files required for porting python In-Reply-To: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> References: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Message-ID: what do you exactly mean by "port python on to windows" ? Are you talking about your application or python itself :-/ ~l0nwlf On Mon, Feb 22, 2010 at 10:23 PM, KIRAN wrote: > Hi ALL, > > I am newbie to python and wanted to port python on to some RTOS. The > RTOS I am trying to port python is not posix compliant. First, I > decided to port python on to windows and later I will port the same to > my target system. [ This is just to minimize the effort being put > port, debug and to stabilize]. I downloaded 2.6.1 python code and > started looking through the code. I see lot of code with several > files. I am not sure which code I should start with. Any help / link > regarding this is appreciated. > > Thanks, > Kiran > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel at stutzbachenterprises.com Mon Feb 22 12:08:08 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Mon, 22 Feb 2010 11:08:08 -0600 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: On Mon, Feb 22, 2010 at 10:32 AM, Bryan wrote: > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) > > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) > It's not entirely clear what UpdateExistingValue and CreateNewValue do. However, it looks like you are trying to create a dictionary where the keys are sorted. Is that right? If so, you could use the sorteddict type from my blist package, which is similar to an OrderDict except it efficiently keeps the keys in sorted order instead of insertion order. For example: >>> from blist import sorteddict >>> my_dict = sorteddict({1: 'a', 6: 'b', -5: 'c'}) >>> my_dict.keys() [-5, 1, 6] >>> my_dict[2] = 'd' >>> my_dict.keys() [-5, 1, 2, 6] It's available here: http://pypi.python.org/pypi/blist/ -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexanderjquinn at yahoo.com Mon Feb 22 12:10:38 2010 From: alexanderjquinn at yahoo.com (Alex Quinn) Date: Mon, 22 Feb 2010 09:10:38 -0800 (PST) Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? Message-ID: <973565.53691.qm@web38208.mail.mud.yahoo.com> Is there a way to have some kind of database (i.e. sqlite3, bsddb, dbm, etc.) that works out of the box on any Win/Linux/Mac machine with Python 2.6+ or 3.x? It's okay if the file format is different between machines, but I want my script to work without having to install anything. Problems with current modules: * Shelve used to do this. Unfortunately, since bsddb was deprecated/removed from the standard distro and Windows doesn't have dbm or gdbm, the only remaining option on Windows is dumbdbm, which is discouraged in the docs. * Sqlite3 should fill the void now. However, in my experience, nearly every Linux Python install I encounter has a broken sqlite3 module ("ImportError: No module named _sqlite3"). It's a well-documented issue, but it the solution generally requires root access, which I don't have on these servers. Potential solutions: * Could I somehow bundle with my project the _sqlite3.so file and/or whatever else it needs? Or is there an alternate sqlite3 module I could use as a fallback that would just interface with the sqlite3 executable on the machine (i.e. /usr/local/bin/sqlite3)? * Is there a way to drop bsddb into my project so it works out of the gate (no install) on either Linux, Windows, or Mac? If you have any ideas, I'd be most appreciative. My objective here is just to find a portable and reliable solution that I can use for small projects. Thanks, Alex -- http://alexquinn.org From kiraank at gmail.com Mon Feb 22 12:11:12 2010 From: kiraank at gmail.com (Kiran K) Date: Mon, 22 Feb 2010 22:41:12 +0530 Subject: Files required for porting python In-Reply-To: References: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Message-ID: <775a6b621002220911m29664303xda13ce88f04072cb@mail.gmail.com> I will try to provide the API's on windows that my RTOS provides ex. If my RTOS has "fosCreateSemaphore" to create a semaphore I will implement the same API [ same function prototype] on windows using win32 CreateSemaphore. Similarly I will write a wrapper functions for accesing file system, task manegement, memory management. With this abstraction layer, I am simulating my target RTOS on windows [ I am ignoring realtime requirement on windows, I will worry about it once I am done with python porting]. Hope you understand the way I am going. Thanks, Kiran On Mon, Feb 22, 2010 at 10:30 PM, Shashwat Anand wrote: > what do you exactly mean by "port python on to windows" ? Are you talking > about your application or python itself :-/ > > ~l0nwlf > > On Mon, Feb 22, 2010 at 10:23 PM, KIRAN wrote: > >> Hi ALL, >> >> I am newbie to python and wanted to port python on to some RTOS. The >> RTOS I am trying to port python is not posix compliant. First, I >> decided to port python on to windows and later I will port the same to >> my target system. [ This is just to minimize the effort being put >> port, debug and to stabilize]. I downloaded 2.6.1 python code and >> started looking through the code. I see lot of code with several >> files. I am not sure which code I should start with. Any help / link >> regarding this is appreciated. >> >> Thanks, >> Kiran >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Feb 22 12:17:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 22 Feb 2010 18:17:14 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: <4b8286ec$1@dnews.tpgi.com.au> References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> <4b8286ec$1@dnews.tpgi.com.au> Message-ID: Lie Ryan, 22.02.2010 14:29: > On 02/22/10 19:43, Norman Rie? wrote: >> Am 02/22/10 09:02, schrieb Steven D'Aprano: >>> On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: >>> >>> >>>> This is the actual code: >>>> >>>> source_file = bz2.BZ2File(file, "r") >>>> for line in source_file: >>>> print line.strip() >>>> >>>> print "Exiting" >>>> print "I used file: " + file >>>> >>> Have you verified that the bz file is good by opening it in another >>> application? >>> >>> >>> >>> >> Yes, bzcat is running through the file fine. And piping bzcat output >> into the python script reading stdin works fine, too. > > test with using something other than bzcat; bzcat does certain things > differently because of the way it works (a cat for bzipped file). Try > using plain "bunzip2 filename.bz2" Please note that all of this has already been suggested on the python-tutor list. Stefan From python at mrabarnett.plus.com Mon Feb 22 12:19:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 17:19:14 +0000 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: <4B82BC92.8070304@mrabarnett.plus.com> Bryan wrote: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > Why are you building a dict from a list and then an ordered dict from that? Just build the ordered dict from the list, because it's behaves like a dict, except for remembering the order in which the keys were added. From barryjogorman at gmail.com Mon Feb 22 12:26:18 2010 From: barryjogorman at gmail.com (barryjogorman) Date: Mon, 22 Feb 2010 09:26:18 -0800 (PST) Subject: Starting with Classes - basic problem Message-ID: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> HAVE THE FOLLOWING VERY BASIC PROGRAM: class Person: def _init_(self,name, job=None, pay=0): self.name=name self.job=job self.pay=pay bob = Person('Bob Smith') sue = Person('Sue Jones', job='dev', pay = 100000) print(bob.name, bob.pay) print(sue.name, sue.pay) I am getting the following error message: Traceback (most recent call last): File "C:/Python31/person1.py", line 7, in bob = Person('Bob Smith') TypeError: object.__new__() takes no parameters All suggestions gratefully received. From bryanvick at gmail.com Mon Feb 22 12:28:22 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 09:28:22 -0800 (PST) Subject: Efficiently building ordered dict References: Message-ID: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> On Feb 22, 9:19?am, MRAB wrote: > Bryan wrote: > > I am looping through a list and creating a regular dictionary. ?From > > that dict, I create an ordered dict. ?I can't think of a way to build > > the ordered dict while going through the original loop. ?Is there a > > way I can avoid creating the first unordered dict just to get the > > ordered dict? ?Also, I am using pop(k) to retrieve the values from the > > unordered dict while building the ordered one because I figure that as > > the values are removed from the unordered dict, the lookups will > > become faster. ?Is there a better idiom that the code below to create > > an ordered dict from an unordered list? > > Why are you building a dict from a list and then an ordered dict from > that? Just build the ordered dict from the list, because it's behaves > like a dict, except for remembering the order in which the keys were > added. Could you write some pseudo-code for that? I'm not sure how I would add the items to the OrderedDict while looping through the list. Wouldn't the list need to be sorted first (which in this case isn't practical)? From editor at pythonrag.org Mon Feb 22 12:33:55 2010 From: editor at pythonrag.org (Bernard Czenkusz) Date: Mon, 22 Feb 2010 11:33:55 -0600 Subject: Starting with Classes - basic problem References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: On Mon, 22 Feb 2010 09:26:18 -0800, barryjogorman wrote: > HAVE THE FOLLOWING VERY BASIC PROGRAM: > > class Person: > def _init_(self,name, job=None, pay=0): > self.name=name > self.job=job > self.pay=pay > > bob = Person('Bob Smith') > sue = Person('Sue Jones', job='dev', pay = 100000) print(bob.name, > bob.pay) > print(sue.name, sue.pay) > > I am getting the following error message: > > Traceback (most recent call last): > File "C:/Python31/person1.py", line 7, in > bob = Person('Bob Smith') > TypeError: object.__new__() takes no parameters > > > > All suggestions gratefully received. The __init__ method starts and ends with two underscores, not one underscore _init_ as you have used. From agoretoy at gmail.com Mon Feb 22 12:43:03 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Feb 2010 11:43:03 -0600 Subject: Starting with Classes - basic problem In-Reply-To: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: you need to define init with two underscores, I've made that mistake myself long long time ago :) def __init__ not def _init_ -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Mon Feb 22 12:45:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 17:45:04 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: <87404349-5d3a-4396-aeff-60edc14a506a@f8g2000yqn.googlegroups.com> Message-ID: On 2010-02-22, Albert van der Horst wrote: > In article <87404349-5d3a-4396-aeff-60edc14a506a at f8g2000yqn.googlegroups.com>, >>Gabriel Genellina reports that time.clock() uses Windows' >>QueryPerformanceCounter() API, which has much higher resolution >>than the task switcher's 15ms. QueryPerformanceCounter's >>resolution is hardware-dependent; using the Win API, and a >>little test program, I get this value on my machine: Frequency >>is 3579545 ticks/sec Resolution is 0.279365114840015 >>microsecond/tick > > In Forth we add a small machine code routine that executes the > RDTSC instruction. (I used that to play music on a couple of > mechanical instruments in real time.) It just counts the (3 > Ghz) clock cycles in a 64 bit timer. That's what clock.clock() does, except that it converts it into a floating point value in seconds. > Subtract two samples and you're done. Nope. It would fail the same way that clock.clock() does on a multi-core Windows machine. > Is there a mechanism in Python to do something similar, > embedded assembler or something? You'd get the same results as using clock.clock(). Just different format/units. > (This is not a general solution, but at least it would work on > Windows, that is i86 only.) It fails on Windows for the same reason that clock.clock() fails: the counters read by the RDTSC instruction are not synchronized between the different cores. -- Grant Edwards grante Yow! I'm a nuclear at submarine under the visi.com polar ice cap and I need a Kleenex! From python at mrabarnett.plus.com Mon Feb 22 12:45:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 17:45:50 +0000 Subject: Starting with Classes - basic problem In-Reply-To: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: <4B82C2CE.4050008@mrabarnett.plus.com> barryjogorman wrote: > HAVE THE FOLLOWING VERY BASIC PROGRAM: > > class Person: > def _init_(self,name, job=None, pay=0): > self.name=name > self.job=job > self.pay=pay > > bob = Person('Bob Smith') > sue = Person('Sue Jones', job='dev', pay = 100000) > print(bob.name, bob.pay) > print(sue.name, sue.pay) > > I am getting the following error message: > > Traceback (most recent call last): > File "C:/Python31/person1.py", line 7, in > bob = Person('Bob Smith') > TypeError: object.__new__() takes no parameters > > > > All suggestions gratefully received. > The special methods use double underscores, not single underscores, eg __init__ not _init_. From barryjogorman at gmail.com Mon Feb 22 12:46:52 2010 From: barryjogorman at gmail.com (barryjogorman) Date: Mon, 22 Feb 2010 09:46:52 -0800 (PST) Subject: Starting with Classes - basic problem References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: <0a181737-9c67-45ae-bcf8-22d3e4690cf6@u20g2000yqu.googlegroups.com> On Feb 22, 5:33?pm, Bernard Czenkusz wrote: > On Mon, 22 Feb 2010 09:26:18 -0800, barryjogorman wrote: > >HAVE THE FOLLOWING VERY BASIC PROGRAM: > > >class Person: > > ? ?def _init_(self,name, job=None, pay=0): > > ? ? ? ?self.name=name > > ? ? ? ?self.job=job > > ? ? ? ?self.pay=pay > > >bob = Person('Bob Smith') > >sue = Person('Sue Jones', job='dev', pay = 100000) print(bob.name, > >bob.pay) > >print(sue.name, sue.pay) > > >I am getting the following error message: > > >Traceback (most recent call last): > > ?File "C:/Python31/person1.py", line 7, in > > ? ?bob = Person('Bob Smith') > >TypeError: object.__new__() takes no parameters > > >All suggestions gratefully received. > > The __init__ method starts and ends with two underscores,not one underscore _init_ as you have used. thanks From albert at spenarnc.xs4all.nl Mon Feb 22 12:52:48 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Feb 2010 17:52:48 GMT Subject: How to measure elapsed time under Windows? References: <87404349-5d3a-4396-aeff-60edc14a506a@f8g2000yqn.googlegroups.com> Message-ID: In article <87404349-5d3a-4396-aeff-60edc14a506a at f8g2000yqn.googlegroups.com>, Paul McGuire wrote: >On Feb 10, 2:24=A0am, Dennis Lee Bieber wrote: >> On Tue, 9 Feb 2010 21:45:38 +0000 (UTC), Grant Edwards >> declaimed the following in >> gmane.comp.python.general: >> >> > Doesn't work. =A0datetime.datetime.now has granularity of >> > 15-16ms. >> >> > Intervals much less that that often come back with a delta of >> > 0. =A0A delay of 20ms produces a delta of either 15-16ms or >> > 31-32ms >> >> =A0 =A0 =A0 =A0 WinXP uses an ~15ms time quantum for task switching. Whic= >h defines >> the step rate of the wall clock output... >> >> http://www.eggheadcafe.com/software/aspnet/35546579/the-quantum-was-n...h= >ttp://www.eggheadcafe.com/software/aspnet/32823760/how-do-you-set-ti... >> >> http://www.lochan.org/2005/keith-cl/useful/win32time.html >> -- >> =A0 =A0 =A0 =A0 Wulfraed =A0 =A0 =A0 =A0 Dennis Lee Bieber =A0 =A0 =A0 = >=A0 =A0 =A0 =A0 KD6MOG >> =A0 =A0 =A0 =A0 wlfr... at ix.netcom.com =A0 =A0 HTTP://wlfraed.home.netcom.= >com/ > >Gabriel Genellina reports that time.clock() uses Windows' >QueryPerformanceCounter() API, which has much higher resolution than >the task switcher's 15ms. QueryPerformanceCounter's resolution is >hardware-dependent; using the Win API, and a little test program, I >get this value on my machine: >Frequency is 3579545 ticks/sec >Resolution is 0.279365114840015 microsecond/tick In Forth we add a small machine code routine that executes the RDTSC instruction. (I used that to play music on a couple of mechanical instruments in real time.) It just counts the (3 Ghz) clock cycles in a 64 bit timer. Subtract two samples and you're done. Is there a mechanism in Python to do something similar, embedded assembler or something? (This is not a general solution, but at least it would work on Windows, that is i86 only.) > >-- Paul -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Mon Feb 22 13:01:44 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Feb 2010 18:01:44 GMT Subject: Bizarre arithmetic results References: Message-ID: In article , Terrence Cole wrote: >Can someone explain to me what python is doing here? > >Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) >[GCC 4.3.4] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 Python 4.0 Warning: misleading blank space, expected: - 0.1**0.1 >-0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b >(0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) >-0.7943282347242815 > >Why does the literal version return the signed magnitude and the >variable version return a complex? > >Cheers, >Terrence > -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From python at mrabarnett.plus.com Mon Feb 22 13:04:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 18:04:20 +0000 Subject: Efficiently building ordered dict In-Reply-To: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> References: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> Message-ID: <4B82C724.7030202@mrabarnett.plus.com> Bryan wrote: > On Feb 22, 9:19 am, MRAB wrote: >> Bryan wrote: >>> I am looping through a list and creating a regular dictionary. From >>> that dict, I create an ordered dict. I can't think of a way to build >>> the ordered dict while going through the original loop. Is there a >>> way I can avoid creating the first unordered dict just to get the >>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>> unordered dict while building the ordered one because I figure that as >>> the values are removed from the unordered dict, the lookups will >>> become faster. Is there a better idiom that the code below to create >>> an ordered dict from an unordered list? >> Why are you building a dict from a list and then an ordered dict from >> that? Just build the ordered dict from the list, because it's behaves >> like a dict, except for remembering the order in which the keys were >> added. > > Could you write some pseudo-code for that? I'm not sure how I would > add the items to the OrderedDict while looping through the list. > Wouldn't the list need to be sorted first (which in this case isn't > practical)? > ordered != sorted. If you want the ordered dict to be sorted by key then build a dict first and then create the ordered dict from the sorted dict. I think the quickest way to build the sorted dict is: orderedDict = OrderedDict(sorted(unorderedDict.items())) although I haven't tried 'sorteddict' (see Daniel Stutzbach's post). From arnodel at googlemail.com Mon Feb 22 13:09:31 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 22 Feb 2010 18:09:31 +0000 Subject: Efficiently building ordered dict References: Message-ID: Bryan writes: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) > > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) Why don't you sort your unorderedList first then simply create your orderedDict? To me your problem is stated in too vague terms anyway and the code you post could not really work as unorderedDict is bound to remain empty whatever the values of all the other names. At any rate, why do you need an ordered dictionary? It seems suspect to me as you sort the keys before inserting the items. -- Arnaud From breamoreboy at yahoo.co.uk Mon Feb 22 13:15:38 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Feb 2010 18:15:38 +0000 Subject: Efficiently building ordered dict In-Reply-To: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> References: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> Message-ID: Bryan wrote: > On Feb 22, 9:19 am, MRAB wrote: >> Bryan wrote: >>> I am looping through a list and creating a regular dictionary. From >>> that dict, I create an ordered dict. I can't think of a way to build >>> the ordered dict while going through the original loop. Is there a >>> way I can avoid creating the first unordered dict just to get the >>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>> unordered dict while building the ordered one because I figure that as >>> the values are removed from the unordered dict, the lookups will >>> become faster. Is there a better idiom that the code below to create >>> an ordered dict from an unordered list? >> Why are you building a dict from a list and then an ordered dict from >> that? Just build the ordered dict from the list, because it's behaves >> like a dict, except for remembering the order in which the keys were >> added. > > Could you write some pseudo-code for that? I'm not sure how I would > add the items to the OrderedDict while looping through the list. > Wouldn't the list need to be sorted first (which in this case isn't > practical)? > > > Could you please clarify what you are trying to achieve as you appear to be confusing ordering with sorting. Mark Lawrence. From wolftracks at invalid.com Mon Feb 22 13:30:31 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 10:30:31 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: On 2/22/2010 8:29 AM, Grant Edwards wrote: > On 2010-02-22, W. eWatson wrote: > >> Last night I copied a program from folder A to folder B. > > [tail of various windows breakages elided] > >> Comments? > > Switch to Linux? > > Or at least install Cygwin? > Yes, definitely not related, but maybe some W7 user has a similar experience here. It seems a natural place to look, since it should be reasonably common. I have Cygwin. From sridharr at activestate.com Mon Feb 22 13:53:31 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 22 Feb 2010 10:53:31 -0800 Subject: Python won't run In-Reply-To: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> References: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> Message-ID: <46D34AB9-9DC7-47E9-8288-2B5DFDB55BB8@activestate.com> Have you tried using http://dependencywalker.com/ ? -srid On 2010-02-18, at 1:00 PM, Nardin, Cory L. wrote: > Quickly, I have a Mac Intel with Windows XP installed. Tried installing Python 2.6.4 from the binary and also ActivePython 2.6.4.10. Both installations acted the same. There seemed to be no problems during installation (used default options), but when I try to run Python I get an error message: ?This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.? > > Of course I searched on that error and it seems to be related to a MS library. In a few different places it was recommended to install the MS Visual Studio redistributable package, which I did with no change in outcome. I really have no idea what to do. > > Any help is appreciated. > > Thanks, > Cory > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Mon Feb 22 13:57:56 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 22 Feb 2010 19:57:56 +0100 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: * Bryan: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) If this were real code the last statement would generate an exception. > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) This is not even valid syntax. Please (1) explain the problem that you're trying to solve, not how you imagine the solution, and (2) if you have any code, please post real code (copy and paste). The above code is not real. Cheers & hth., - Alf From hansmu at xs4all.nl Mon Feb 22 14:32:45 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 22 Feb 2010 20:32:45 +0100 Subject: formatting a number as percentage In-Reply-To: References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <4b82dc5a$0$22916$e4fe514c@news.xs4all.nl> G?nther Dietrich wrote: > vsoler wrote: > >> I'm trying to print .7 as 70% >> I've tried: >> >> print format(.7,'%%') >> .7.format('%%') >> >> but neither works. I don't know what the syntax is... > > Did you try this: > >>>> print('%d%%' % (0.7 * 100)) > 70% That method will always round down; TomF's method will round to the nearest whole number: >>> print "%d%%" % (0.698 * 100) 69% >>> print "{0:.0%}".format(.698) 70% Only the OP knows which one is more appropriate for his use case. Hope this helps, -- HansM From jgardner at jonathangardner.net Mon Feb 22 14:41:45 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 11:41:45 -0800 Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? In-Reply-To: <973565.53691.qm@web38208.mail.mud.yahoo.com> References: <973565.53691.qm@web38208.mail.mud.yahoo.com> Message-ID: <6cc20cea1002221141u534fd5f7v8748f50f9094011f@mail.gmail.com> On Mon, Feb 22, 2010 at 9:10 AM, Alex Quinn wrote: > > * Sqlite3 should fill the void now. ?However, in my experience, nearly every Linux Python install I encounter has a broken sqlite3 module ("ImportError: No module named _sqlite3"). It's a well-documented issue, but it the solution generally requires root access, which I don't have on these servers. > If your program is installed in the same way everything else is installed on the system (RPM or deb packages, or whatever), there should be dependencies clearly listed. When the admin installs your code, he must also install the requisite modules that you list as dependencies. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Mon Feb 22 14:45:10 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 11:45:10 -0800 Subject: Use eval() safely? In-Reply-To: <20100221212511.GA23046@beron.tangosoft.com> References: <20100221212511.GA23046@beron.tangosoft.com> Message-ID: <6cc20cea1002221145o2527b03ds74a473d59bd079@mail.gmail.com> On Sun, Feb 21, 2010 at 1:25 PM, W. Martin Borgert wrote: > > I know that this issue has been discussed before, but most of > the time using only one argument to eval(). > > Is it possible to use the following code, e.g. run as part of a > web application, to break in and if so, how? > > import math > > def myeval(untrustedinput): > ? ?return eval(untrustedinput, {"__builtins__": None}, > ? ? ? ? ? ? ? ?{ "abs": abs, "sin": math.sin }) > > Is it possible to define functions or import modules from the > untrusted input string? > > Which Python built-ins and math functions would I have to add to > the functions dictionary to make it unsafe? > Why would you ever run untrusted code on any machine in any language, let alone Python? If you're writing a web app, make it so that you only run trusted code. That is, code installed by the admin, or approved by the admin. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Mon Feb 22 15:00:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 12:00:19 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <87mxz2v47t.fsf@castleamber.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> Message-ID: <6cc20cea1002221200g467f229cm4710db0d70d21105@mail.gmail.com> On Sun, Feb 21, 2010 at 10:22 AM, John Bokma wrote: > Jonathan Gardner writes: >> On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: >>> >>> Now, why don't we start a PEP to make python a fully-functional language >>> then? >> >> Because people don't think the same way that programs are written in >> functional languages. > > Heh! When I learned Miranda it felt natural to me. Prolog on the other > hand... > > In short: I am afraid you're overgeneralizing here; it depends on one's > background. If not, citation needed ;-) > Unfortunately, this is something that is hardly measurable. Short of a survey (of whom? of what?), there can be no objective evaluation. To date, I don't know of any such studies or surveys. I won't deny that really smart people enjoy the challenge of programming in a functional style, and some even find it easier to work with. However, when it comes to readability and maintenance, I appreciate the statement-based programming style, simply because it's easier for me to understand an debug. -- Jonathan Gardner jgardner at jonathangardner.net From no.email at nospam.invalid Mon Feb 22 15:07:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 12:07:30 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> Message-ID: <7xsk8tuj99.fsf@ruckus.brouhaha.com> Jonathan Gardner writes: > I won't deny that really smart people enjoy the challenge of > programming in a functional style, and some even find it easier to > work with. However, when it comes to readability and maintenance, I > appreciate the statement-based programming style, simply because it's > easier for me to understand an debug. One thing those people are after is programs that work properly the first time they are run, and thus don't need debugging. They achieve that a surprising amount of the time. From g.bogle at auckland.no.spam.ac.nz Mon Feb 22 15:16:26 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 23 Feb 2010 09:16:26 +1300 Subject: What's Going on between Python and win7? References: Message-ID: MRAB wrote: > W. eWatson wrote: >> Last night I copied a program from folder A to folder B. It inspects >> the contents of files in a folder. When I ran it in B, it gave the >> results for A! Out of frustration I changed the name in A, and fired >> up the program in B. Win7 went into search mode for the file. I looked >> at properties for the B program, and it was clearly pointing to folder A. >> > Sounds like you didn't copy it but made a shortcut to it instead. Windows 7 has symbolic links? From ra21vi at gmail.com Mon Feb 22 15:19:15 2010 From: ra21vi at gmail.com (Ravi Kumar) Date: Mon, 22 Feb 2010 20:19:15 +0000 Subject: GUI app on Windows for WMI digging Message-ID: <9a63e8921002221219p38c03de2mfbf74a7301cbc6dd@mail.gmail.com> Hi, I am working on an application, which retrieves Windows system info (Hardware / Software / Drivers / OS) and write to an xml. For the GUI, I selected PyQT4, and for system info using WMI, I am using WMI Package (http://timgolden.me.uk/python/wmi/index.html) and popular pywin32. To package the binary, I am considering py2exe. I need to package these in binary package (though single binary output was preferred, but could not find any examples online to achieve this). Also, I took PyQT4, but I can switch to PyGTK if it is possible to get it in single DLL/libs. Overall, I need suggestions on: - which XML library is better/lightweight on Windows?I think pure python based xml processing libs would work (so lxml is out of option). - Can I get these in single binary (not installer), or if not, then how can I get in minimum files. Py2exe results many files. - Is QT4 better or GTK? No war/flaming over this, since least widgets are needed, which are available on both. Since the GUI is just 3-4 screens/dialogs with minimum widgets, so speed does not matter. The only thing that matter is least files/libs (no seperate installation, file can provided with binary package). -- -=Ravi=- -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Feb 22 15:31:18 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Feb 2010 14:31:18 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> Message-ID: <87iq9pt3l5.fsf@castleamber.com> Jonathan Gardner writes: > On Sun, Feb 21, 2010 at 10:22 AM, John Bokma wrote: >> Jonathan Gardner writes: >>> On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: >>>> >>>> Now, why don't we start a PEP to make python a fully-functional language >>>> then? >>> >>> Because people don't think the same way that programs are written in >>> functional languages. >> >> Heh! When I learned Miranda it felt natural to me. Prolog on the other >> hand... >> >> In short: I am afraid you're overgeneralizing here; it depends on one's >> background. If not, citation needed ;-) >> > > Unfortunately, this is something that is hardly measurable. Short of a > survey (of whom? of what?), there can be no objective evaluation. To > date, I don't know of any such studies or surveys. > > I won't deny that really smart people enjoy the challenge of > programming in a functional style, and some even find it easier to > work with. However, when it comes to readability and maintenance, I > appreciate the statement-based programming style, simply because it's > easier for me to understand an debug. In my class there where basically 2 groups of people: the ones who got functional programming and the ones who had a hard time with it. The latter group consisted mostly of people who had been programming in languages like C and Pascal for years; they had a hard time thinking functionally. The former group consisted mostly of people who had little or no programming experience, with a few exceptions (including me :-) ). So I have the feeling it has more to do with your background then how people think / are wired. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Mon Feb 22 15:33:43 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Feb 2010 14:33:43 -0600 Subject: What's Going on between Python and win7? References: Message-ID: <87d3zxt3h4.fsf@castleamber.com> Gib Bogle writes: > MRAB wrote: >> W. eWatson wrote: >>> Last night I copied a program from folder A to folder B. It >>> inspects the contents of files in a folder. When I ran it in B, it >>> gave the results for A! Out of frustration I changed the name in A, >>> and fired up the program in B. Win7 went into search mode for the >>> file. I looked at properties for the B program, and it was clearly >>> pointing to folder A. >>> >> Sounds like you didn't copy it but made a shortcut to it instead. > > Windows 7 has symbolic links? Symbolic links are designed to aid in migration and application compatibility with UNIX operating systems. Microsoft has implemented its symbolic links to function just like UNIX links. : Symbolic links are available in NTFS starting with Windows Vista. http://msdn.microsoft.com/en-us/library/aa365680(VS.85).aspx -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From icanbob at gmail.com Mon Feb 22 15:37:10 2010 From: icanbob at gmail.com (bobicanprogram) Date: Mon, 22 Feb 2010 12:37:10 -0800 (PST) Subject: ANN: Python-SIMPL v2.0.0 released References: <964d1dcb-46a9-40a5-ab41-199fd1e364a7@t21g2000vbo.googlegroups.com> Message-ID: <40dd1bcc-4791-463d-a730-d8e3c52ff2a2@f8g2000vba.googlegroups.com> On Feb 22, 9:40 am, bobicanprogram wrote: > The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the > Send/Receive/Reply messaging (first popularized by QNX) to the open > source Linux world. Since its inception more that 10 years ago, the > SIMPL toolkit has grown steadily in functionality. Through the use > of surrogates, SIMPL modules can be dispersed seamlessly across > networks including heterogeneous networks with only one Linux node. > SIMPL modules can also be written in several programming languages > including Python, C, C++, JAVA and Tcl/Tk. Modules written in > different languages can be mixed in a SIMPL appliction. > > Python-SIMPL has been used to connect Python UIs to C data acquisition/ > computation backends. While this is an example of a common use for > the toolkit, it is by no means the only place it could be useful. > Python to Python, Python to JAVA as well as Python to C are all > seamlessly possible in both local or distributed applications. Python- > SIMPL allows a software application to be broken up into modules where > the language choices for each module can be optimized. > > The Python-SIMPL interface library has undergone a fundamental > revision with the v2.0.0 release. The underlying shared library which > wraps the SIMPL toolkit as a Python extension was cleaned up > considerably. In addition two new Python wrappers were created to > expose this SIMPL toolkit in more object oriented fashion to the > Python developer. > > The simplest starting point for exploring the Python-SIMPL toolkit is > an online "hello world" level tutorial at: > > http://www.icanprogram.com/06py/lesson1/lesson1.html > > The Python-SIMPL toolkit can be downloaded in source form at: > > http://www.icanprogram.com/simpl/python.self.htm > > or in precompiled binary (i386) form at: > > http://www.icanprogram.com/simpl/pythonbin.self.html > > We at the SIMPL project welcome participants at all levels of > expertise. If you are interested do not hesitate to contact us. > > bob There is a typo in the source link. It should read http://www.icanprogram.com/simpl/python.self.html Sorry about that. bob From invalid at invalid.invalid Mon Feb 22 16:19:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 21:19:32 +0000 (UTC) Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On 2010-02-22, John Bokma wrote: > Gib Bogle writes: > >> MRAB wrote: >>> W. eWatson wrote: >>>> Last night I copied a program from folder A to folder B. It >>>> inspects the contents of files in a folder. When I ran it in B, it >>>> gave the results for A! Out of frustration I changed the name in A, >>>> and fired up the program in B. Win7 went into search mode for the >>>> file. I looked at properties for the B program, and it was clearly >>>> pointing to folder A. >>>> >>> Sounds like you didn't copy it but made a shortcut to it instead. >> >> Windows 7 has symbolic links? > > Symbolic links are designed to aid in migration and application > compatibility with UNIX operating systems. Microsoft has implemented > its symbolic links to function just like UNIX links. So symbolic links on W7 function like Unix (hard) links rather than Unix _symbolic_ links?? -- Grant Edwards grante Yow! Is this sexual at intercourse yet?? Is it, visi.com huh, is it?? From bryanvick at gmail.com Mon Feb 22 16:29:26 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 13:29:26 -0800 (PST) Subject: Efficiently building ordered dict References: Message-ID: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> On Feb 22, 10:57?am, "Alf P. Steinbach" wrote: > * Bryan: > > > > > I am looping through a list and creating a regular dictionary. ?From > > that dict, I create an ordered dict. ?I can't think of a way to build > > the ordered dict while going through the original loop. ?Is there a > > way I can avoid creating the first unordered dict just to get the > > ordered dict? ?Also, I am using pop(k) to retrieve the values from the > > unordered dict while building the ordered one because I figure that as > > the values are removed from the unordered dict, the lookups will > > become faster. ?Is there a better idiom that the code below to create > > an ordered dict from an unordered list? > > > unorderedDict = {} > > for thing in unorderedList: > > ? ?if thing.id in unorderedDict: > > ? ? ? ? ? ?UpdateExistingValue(unorderedDict[thing.id]) > > ? ?else: > > ? ? ? ? ? ?CreateNewValue(unorderedDict[thing.id]) > > If this were real code the last statement would generate an exception. > > > orderedDict = OrderedDict() > > for k in sorted(unorderedDict.keys()): > > ? ?orderedDict[k] ?unorderedDict.pop(k) > > This is not even valid syntax. > > Please > > ? ?(1) explain the problem that you're trying to solve, not how you > ? ? ? ?imagine the solution, and > > ? ?(2) if you have any code, please post real code (copy and paste). > > The above code is not real. > > Cheers & hth., > > - Alf Sorry about the sorted != ordered mix up. I want to end up with a *sorted* dict from an unordered list. *Sorting the list is not practical in this case.* I am using python 2.5, with an ActiveState recipe for an OrderedDict. Given these requirements/limitations, how would you do it? My solution is to create a regular dict from the list. Then sort the keys, and add the keys+values to an OrderedDict. Since the keys are being added to the OrderedDict in the correctly sorted order, at the end I end up with a OrderedDict that is in the correctly *sorted* order. self.accTotals = {} for row in self.rows: if row.acc.code in self.accTotals: self.accTotals[row.acc.code].addRow(row) else: accSummary = Total() accSummary.addRow(row) self.accTotals[row.acc.code] = accSummary self.accTotals = self._getOrderedDict(self.accTotals) From aonlazio at gmail.com Mon Feb 22 16:56:02 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Mon, 22 Feb 2010 16:56:02 -0500 Subject: When will Python go mainstream like Java? Message-ID: That will be superb -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Feb 22 17:02:47 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Feb 2010 16:02:47 -0600 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <873a0tszco.fsf@castleamber.com> Grant Edwards writes: > On 2010-02-22, John Bokma wrote: >> Gib Bogle writes: >> >>> MRAB wrote: >>>> W. eWatson wrote: >>>>> Last night I copied a program from folder A to folder B. It >>>>> inspects the contents of files in a folder. When I ran it in B, it >>>>> gave the results for A! Out of frustration I changed the name in A, >>>>> and fired up the program in B. Win7 went into search mode for the >>>>> file. I looked at properties for the B program, and it was clearly >>>>> pointing to folder A. >>>>> >>>> Sounds like you didn't copy it but made a shortcut to it instead. >>> >>> Windows 7 has symbolic links? >> >> Symbolic links are designed to aid in migration and application >> compatibility with UNIX operating systems. Microsoft has implemented >> its symbolic links to function just like UNIX links. > > So symbolic links on W7 function like Unix (hard) links > rather than Unix _symbolic_ links?? Which leads you to this conclusion? According to http://msdn.microsoft.com/en-us/library/aa365006(VS.85).aspx There are three types of file links supported in the NTFS file system: hard links, junctions, and symbolic links. This topic is an overview of hard links and junctions. For information about symbolic links, see Creating Symbolic Links. Creating Symbolic Links: http://msdn.microsoft.com/en-us/library/aa363878(VS.85).aspx -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From arnodel at googlemail.com Mon Feb 22 17:10:47 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 22 Feb 2010 14:10:47 -0800 (PST) Subject: Efficiently building ordered dict References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> Message-ID: On 22 Feb, 21:29, Bryan wrote: > Sorry about the sorted != ordered mix up. ?I want to end up with a > *sorted* dict from an unordered list. ?*Sorting the list is not > practical in this case.* ?I am using python 2.5, with an ActiveState > recipe for an OrderedDict. Why does the dict need to be sorted? Why is it impractical to sort the list, but practical to sort the dict? Whithout knowing this, it is difficult to get an idea of your problem an a potential solution. > My solution is to create a regular dict from the list. ?Then sort the > keys, and add the keys+values to an OrderedDict. ?Since the keys are > being added to the OrderedDict in the correctly sorted order, at the > end I end up with a OrderedDict that is in the correctly *sorted* > order. > > self.accTotals = {} > for row in self.rows: > ? ? ? ? if row.acc.code in self.accTotals: > ? ? ? ? ? ? ? ? self.accTotals[row.acc.code].addRow(row) > ? ? ? ? else: > ? ? ? ? ? ? ? ? accSummary = Total() > ? ? ? ? ? ? ? ? accSummary.addRow(row) > ? ? ? ? ? ? ? ? self.accTotals[row.acc.code] = accSummary > self.accTotals = self._getOrderedDict(self.accTotals) This code is a typical example where defaultdict, which was added in Python 2.5 [1], would be of use: accTotals = defaultdict(Total) for row in self.rows: accTotals[row.acc.code].addRow(row) self.accTotals = self._getOrderedDict(accTotals) However, as you don't explain what self._getOrderedDict(...) does, it is quite difficult to guess how to improve it! [1] http://docs.python.org/library/collections.html#collections.defaultdict -- Arnaud From g.bogle at auckland.no.spam.ac.nz Mon Feb 22 17:10:54 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 23 Feb 2010 11:10:54 +1300 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: John Bokma wrote: > Gib Bogle writes: > >> MRAB wrote: >>> W. eWatson wrote: >>>> Last night I copied a program from folder A to folder B. It >>>> inspects the contents of files in a folder. When I ran it in B, it >>>> gave the results for A! Out of frustration I changed the name in A, >>>> and fired up the program in B. Win7 went into search mode for the >>>> file. I looked at properties for the B program, and it was clearly >>>> pointing to folder A. >>>> >>> Sounds like you didn't copy it but made a shortcut to it instead. >> Windows 7 has symbolic links? > > Symbolic links are designed to aid in migration and application > compatibility with UNIX operating systems. Microsoft has implemented > its symbolic links to function just like UNIX links. > > : > > Symbolic links are available in NTFS starting with Windows Vista. > > http://msdn.microsoft.com/en-us/library/aa365680(VS.85).aspx > That explains my ignorance of this (excellent) development. I'm still using W2K and XP. From deets at nospam.web.de Mon Feb 22 17:16:07 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Feb 2010 23:16:07 +0100 Subject: Efficiently building ordered dict In-Reply-To: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> Message-ID: <7uge18Fta5U1@mid.uni-berlin.de> Am 22.02.10 22:29, schrieb Bryan: > On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: >> * Bryan: >> >> >> >>> I am looping through a list and creating a regular dictionary. From >>> that dict, I create an ordered dict. I can't think of a way to build >>> the ordered dict while going through the original loop. Is there a >>> way I can avoid creating the first unordered dict just to get the >>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>> unordered dict while building the ordered one because I figure that as >>> the values are removed from the unordered dict, the lookups will >>> become faster. Is there a better idiom that the code below to create >>> an ordered dict from an unordered list? >> >>> unorderedDict = {} >>> for thing in unorderedList: >>> if thing.id in unorderedDict: >>> UpdateExistingValue(unorderedDict[thing.id]) >>> else: >>> CreateNewValue(unorderedDict[thing.id]) >> >> If this were real code the last statement would generate an exception. >> >>> orderedDict = OrderedDict() >>> for k in sorted(unorderedDict.keys()): >>> orderedDict[k] unorderedDict.pop(k) >> >> This is not even valid syntax. >> >> Please >> >> (1) explain the problem that you're trying to solve, not how you >> imagine the solution, and >> >> (2) if you have any code, please post real code (copy and paste). >> >> The above code is not real. >> >> Cheers& hth., >> >> - Alf > > Sorry about the sorted != ordered mix up. I want to end up with a > *sorted* dict from an unordered list. *Sorting the list is not > practical in this case.* I am using python 2.5, with an ActiveState > recipe for an OrderedDict. > > Given these requirements/limitations, how would you do it? > > My solution is to create a regular dict from the list. Then sort the > keys, and add the keys+values to an OrderedDict. Since the keys are > being added to the OrderedDict in the correctly sorted order, at the > end I end up with a OrderedDict that is in the correctly *sorted* > order. If that works for you, I don't understand your assertion that you can't sort the list. If you have the space & time to sort the intermediate dict, then it's as easy to create the list & sort & then the ordered dict from it. It should be faster, because you sort the keys anyway. Diez From invalid at invalid.invalid Mon Feb 22 17:40:27 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 22:40:27 +0000 (UTC) Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> <873a0tszco.fsf@castleamber.com> Message-ID: On 2010-02-22, John Bokma wrote: > Grant Edwards writes: >>>> Windows 7 has symbolic links? >>> >>> Symbolic links are designed to aid in migration and application >>> compatibility with UNIX operating systems. Microsoft has implemented >>> its symbolic links to function just like UNIX links. >> >> So symbolic links on W7 function like Unix (hard) links >> rather than Unix _symbolic_ links?? > > Which leads you to this conclusion? The quote above that says that "symbolic links" on W7 function just like "links" on Unix. A "link" on Unix is a hard link. I presumed that if they meant "symbolic links" on Unix, they would have said "symbolic links". -- Grant Edwards grante Yow! What a COINCIDENCE! at I'm an authorized "SNOOTS visi.com OF THE STARS" dealer!! From bryanvick at gmail.com Mon Feb 22 17:48:55 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 14:48:55 -0800 (PST) Subject: Efficiently building ordered dict References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> Message-ID: <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> On Feb 22, 2:16?pm, "Diez B. Roggisch" wrote: > Am 22.02.10 22:29, schrieb Bryan: > > > > > On Feb 22, 10:57 am, "Alf P. Steinbach" ?wrote: > >> * Bryan: > > >>> I am looping through a list and creating a regular dictionary. ?From > >>> that dict, I create an ordered dict. ?I can't think of a way to build > >>> the ordered dict while going through the original loop. ?Is there a > >>> way I can avoid creating the first unordered dict just to get the > >>> ordered dict? ?Also, I am using pop(k) to retrieve the values from the > >>> unordered dict while building the ordered one because I figure that as > >>> the values are removed from the unordered dict, the lookups will > >>> become faster. ?Is there a better idiom that the code below to create > >>> an ordered dict from an unordered list? > > >>> unorderedDict = {} > >>> for thing in unorderedList: > >>> ? ? if thing.id in unorderedDict: > >>> ? ? ? ? ? ? UpdateExistingValue(unorderedDict[thing.id]) > >>> ? ? else: > >>> ? ? ? ? ? ? CreateNewValue(unorderedDict[thing.id]) > > >> If this were real code the last statement would generate an exception. > > >>> orderedDict = OrderedDict() > >>> for k in sorted(unorderedDict.keys()): > >>> ? ? orderedDict[k] ?unorderedDict.pop(k) > > >> This is not even valid syntax. > > >> Please > > >> ? ? (1) explain the problem that you're trying to solve, not how you > >> ? ? ? ? imagine the solution, and > > >> ? ? (2) if you have any code, please post real code (copy and paste). > > >> The above code is not real. > > >> Cheers& ?hth., > > >> - Alf > > > Sorry about the sorted != ordered mix up. ?I want to end up with a > > *sorted* dict from an unordered list. ?*Sorting the list is not > > practical in this case.* ?I am using python 2.5, with an ActiveState > > recipe for an OrderedDict. > > > Given these requirements/limitations, how would you do it? > > > My solution is to create a regular dict from the list. ?Then sort the > > keys, and add the keys+values to an OrderedDict. ?Since the keys are > > being added to the OrderedDict in the correctly sorted order, at the > > end I end up with a OrderedDict that is in the correctly *sorted* > > order. > > If that works for you, I don't understand your assertion that you can't > sort the list. If you have the space & time to sort the intermediate > dict, then it's as easy to create the list & sort & then the ordered > dict from it. It should be faster, because you sort the keys anyway. > > Diez Here is how I am converting a regular dict to an ordered dict that is sorted by keys. def _getOrderedDict(theDict): ordered = OrderedDict() for k in sorted(theDict.keys()): ordered[k] = theDict.pop(k) return ordered The list is a bunch of objects that represent hours worked by employees on particular jobs, and accounts, and client purchase orders etc. From this list, I am generating these sorted dicts that contain summarizing information about the list. So one of the sorted dicts will give a summary of hours worked by job number. Another one will give summary information by client PO number etc. So instead of sorting the list a bunch of different ways, I keep the list as is, generate the summaries I need into dictionaries, and then sort those dictionaries as appropriate. From no.email at nospam.invalid Mon Feb 22 18:00:08 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 15:00:08 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <7xvddori4n.fsf@ruckus.brouhaha.com> John Bokma writes: > In my class there where basically 2 groups of people: the ones who got > functional programming and the ones who had a hard time with it. The > latter group consisted mostly of people who had been programming in > languages like C and Pascal for years; they had a hard time thinking > functionally. I've heard it expressed this way (paraphrased): functional programming has a steep unlearning curve. From deets at nospam.web.de Mon Feb 22 18:00:32 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Feb 2010 00:00:32 +0100 Subject: Efficiently building ordered dict In-Reply-To: <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> Message-ID: <7uggkhFbc9U1@mid.uni-berlin.de> Am 22.02.10 23:48, schrieb Bryan: > On Feb 22, 2:16 pm, "Diez B. Roggisch" wrote: >> Am 22.02.10 22:29, schrieb Bryan: >> >> >> >>> On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: >>>> * Bryan: >> >>>>> I am looping through a list and creating a regular dictionary. From >>>>> that dict, I create an ordered dict. I can't think of a way to build >>>>> the ordered dict while going through the original loop. Is there a >>>>> way I can avoid creating the first unordered dict just to get the >>>>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>>>> unordered dict while building the ordered one because I figure that as >>>>> the values are removed from the unordered dict, the lookups will >>>>> become faster. Is there a better idiom that the code below to create >>>>> an ordered dict from an unordered list? >> >>>>> unorderedDict = {} >>>>> for thing in unorderedList: >>>>> if thing.id in unorderedDict: >>>>> UpdateExistingValue(unorderedDict[thing.id]) >>>>> else: >>>>> CreateNewValue(unorderedDict[thing.id]) >> >>>> If this were real code the last statement would generate an exception. >> >>>>> orderedDict = OrderedDict() >>>>> for k in sorted(unorderedDict.keys()): >>>>> orderedDict[k] unorderedDict.pop(k) >> >>>> This is not even valid syntax. >> >>>> Please >> >>>> (1) explain the problem that you're trying to solve, not how you >>>> imagine the solution, and >> >>>> (2) if you have any code, please post real code (copy and paste). >> >>>> The above code is not real. >> >>>> Cheers& hth., >> >>>> - Alf >> >>> Sorry about the sorted != ordered mix up. I want to end up with a >>> *sorted* dict from an unordered list. *Sorting the list is not >>> practical in this case.* I am using python 2.5, with an ActiveState >>> recipe for an OrderedDict. >> >>> Given these requirements/limitations, how would you do it? >> >>> My solution is to create a regular dict from the list. Then sort the >>> keys, and add the keys+values to an OrderedDict. Since the keys are >>> being added to the OrderedDict in the correctly sorted order, at the >>> end I end up with a OrderedDict that is in the correctly *sorted* >>> order. >> >> If that works for you, I don't understand your assertion that you can't >> sort the list. If you have the space& time to sort the intermediate >> dict, then it's as easy to create the list& sort& then the ordered >> dict from it. It should be faster, because you sort the keys anyway. >> >> Diez > > Here is how I am converting a regular dict to an ordered dict that is > sorted by keys. > > def _getOrderedDict(theDict): > ordered = OrderedDict() > for k in sorted(theDict.keys()): > ordered[k] = theDict.pop(k) > return ordered > > > The list is a bunch of objects that represent hours worked by > employees on particular jobs, and accounts, and client purchase orders > etc. From this list, I am generating these sorted dicts that contain > summarizing information about the list. So one of the sorted dicts > will give a summary of hours worked by job number. Another one will > give summary information by client PO number etc. So instead of > sorting the list a bunch of different ways, I keep the list as is, > generate the summaries I need into dictionaries, and then sort those > dictionaries as appropriate. Again - why? Unless there is some filtering going on that reduces the number of total entries before the sorting when building the intermediate dict, a simple ordered = OrderedDict(sorted(the_list, key=lambda v: v['some_key'])) won't cost you a dime more. I think you believe in building the dict so that ou can have the key for sorting. As shown abov - you don't need to. It might even benefitial to really re-sort the original list, because that spares you the intermediate list. Diez From ldo at geek-central.gen.new_zealand Mon Feb 22 18:00:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 12:00:48 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> Message-ID: In message <1ecc71bf-54ab-45e6-a38a-d1861f0921d3 at v25g2000yqk.googlegroups.com>, sjdevnull at yahoo.com wrote: > On Feb 20, 1:30 am, Lawrence D'Oliveiro wrote: > >> In message , Rhodri James wrote: >> >> > In classic Pascal, a procedure was distinct from a function in that it >> > had no return value. The concept doesn't really apply in Python; there >> > are no procedures in that sense, since if a function terminates without >> > supplying an explicit return value it returns None. >> >> If Python doesn?t distinguish between procedures and functions, why >> should it distinguish between statements and expressions? > > Because the latter are different in Python (and in Ruby, and in most > modern languages), while the former aren't distinguished in Python or > Ruby or most modern languages? Primarily functional languages are the > main exception, but other than them it's pretty uncommon to find any > modern language that does distinguish procedures and functions, or one > that doesn't distinguished statements and expressions. > > You can certainly find exceptions, but distinguishing statements and > expressions is absolutely commonplace in modern languages, and > distinguishing functions and procedures is in the minority. So they are worth distinguishing where they are distinguished, except where they?re not? From ldo at geek-central.gen.new_zealand Mon Feb 22 18:01:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 12:01:57 +1300 Subject: What's Going on between Python and win7? References: Message-ID: In message , MRAB wrote: > Not Python-related. Seems to be pretty common with Windows-related complaints in this group. From ldo at geek-central.gen.new_zealand Mon Feb 22 18:06:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 12:06:36 +1300 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> <873a0tszco.fsf@castleamber.com> Message-ID: In message <873a0tszco.fsf at castleamber.com>, John Bokma wrote: > According to http://msdn.microsoft.com/en-us/library/aa365006(VS.85).aspx > > There are three types of file links supported in the NTFS file > system: hard links, junctions, and symbolic links. This topic is an > overview of hard links and junctions. ?Junctions? sound like Linux/Unix ?mount points?, plus Linux-style ?bind mounts?. Except of course Dimdows puts it all into the NTFS-specific implementation, instead of at the virtual filesystem layer. So whereas Linux can handle these while letting you mix and match different filesystem types (ext3, XFS, even FAT32, etc), Windows cannot. From python at mrabarnett.plus.com Mon Feb 22 18:08:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 23:08:17 +0000 Subject: Efficiently building ordered dict In-Reply-To: <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> Message-ID: <4B830E61.8000700@mrabarnett.plus.com> Bryan wrote: > On Feb 22, 2:16 pm, "Diez B. Roggisch" wrote: >> Am 22.02.10 22:29, schrieb Bryan: >> >> >> >>> On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: >>>> * Bryan: >>>>> I am looping through a list and creating a regular dictionary. From >>>>> that dict, I create an ordered dict. I can't think of a way to build >>>>> the ordered dict while going through the original loop. Is there a >>>>> way I can avoid creating the first unordered dict just to get the >>>>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>>>> unordered dict while building the ordered one because I figure that as >>>>> the values are removed from the unordered dict, the lookups will >>>>> become faster. Is there a better idiom that the code below to create >>>>> an ordered dict from an unordered list? >>>>> unorderedDict = {} >>>>> for thing in unorderedList: >>>>> if thing.id in unorderedDict: >>>>> UpdateExistingValue(unorderedDict[thing.id]) >>>>> else: >>>>> CreateNewValue(unorderedDict[thing.id]) >>>> If this were real code the last statement would generate an exception. >>>>> orderedDict = OrderedDict() >>>>> for k in sorted(unorderedDict.keys()): >>>>> orderedDict[k] unorderedDict.pop(k) >>>> This is not even valid syntax. >>>> Please >>>> (1) explain the problem that you're trying to solve, not how you >>>> imagine the solution, and >>>> (2) if you have any code, please post real code (copy and paste). >>>> The above code is not real. >>>> Cheers& hth., >>>> - Alf >>> Sorry about the sorted != ordered mix up. I want to end up with a >>> *sorted* dict from an unordered list. *Sorting the list is not >>> practical in this case.* I am using python 2.5, with an ActiveState >>> recipe for an OrderedDict. >>> Given these requirements/limitations, how would you do it? >>> My solution is to create a regular dict from the list. Then sort the >>> keys, and add the keys+values to an OrderedDict. Since the keys are >>> being added to the OrderedDict in the correctly sorted order, at the >>> end I end up with a OrderedDict that is in the correctly *sorted* >>> order. >> If that works for you, I don't understand your assertion that you can't >> sort the list. If you have the space & time to sort the intermediate >> dict, then it's as easy to create the list & sort & then the ordered >> dict from it. It should be faster, because you sort the keys anyway. >> >> Diez > > Here is how I am converting a regular dict to an ordered dict that is > sorted by keys. > > def _getOrderedDict(theDict): > ordered = OrderedDict() > for k in sorted(theDict.keys()): > ordered[k] = theDict.pop(k) > return ordered > As I mentioned in an earlier post, you could do: def _getOrderedDict(theDict): return OrderedDict(sorted(theDict.items())) [snip] From krister.svanlund at gmail.com Mon Feb 22 18:27:52 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 23 Feb 2010 00:27:52 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <2cf430a61002221527j416d3fc5k770d5bafe7dfd0ae@mail.gmail.com> On Mon, Feb 22, 2010 at 10:56 PM, AON LAZIO wrote: > That will be superb > > -- > Passion is my style And when will be as famous as the beatles? From bryanvick at gmail.com Mon Feb 22 18:31:32 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 15:31:32 -0800 (PST) Subject: Efficiently building ordered dict References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> <7uggkhFbc9U1@mid.uni-berlin.de> Message-ID: <8c9b72a6-8496-4992-a521-37221ebd68da@g26g2000yqn.googlegroups.com> On Feb 22, 3:00?pm, "Diez B. Roggisch" wrote: > Am 22.02.10 23:48, schrieb Bryan: > > > > > On Feb 22, 2:16 pm, "Diez B. Roggisch" ?wrote: > >> Am 22.02.10 22:29, schrieb Bryan: > > >>> On Feb 22, 10:57 am, "Alf P. Steinbach" ? ?wrote: > >>>> * Bryan: > > >>>>> I am looping through a list and creating a regular dictionary. ?From > >>>>> that dict, I create an ordered dict. ?I can't think of a way to build > >>>>> the ordered dict while going through the original loop. ?Is there a > >>>>> way I can avoid creating the first unordered dict just to get the > >>>>> ordered dict? ?Also, I am using pop(k) to retrieve the values from the > >>>>> unordered dict while building the ordered one because I figure that as > >>>>> the values are removed from the unordered dict, the lookups will > >>>>> become faster. ?Is there a better idiom that the code below to create > >>>>> an ordered dict from an unordered list? > > >>>>> unorderedDict = {} > >>>>> for thing in unorderedList: > >>>>> ? ? ?if thing.id in unorderedDict: > >>>>> ? ? ? ? ? ? ?UpdateExistingValue(unorderedDict[thing.id]) > >>>>> ? ? ?else: > >>>>> ? ? ? ? ? ? ?CreateNewValue(unorderedDict[thing.id]) > > >>>> If this were real code the last statement would generate an exception. > > >>>>> orderedDict = OrderedDict() > >>>>> for k in sorted(unorderedDict.keys()): > >>>>> ? ? ?orderedDict[k] ?unorderedDict.pop(k) > > >>>> This is not even valid syntax. > > >>>> Please > > >>>> ? ? ?(1) explain the problem that you're trying to solve, not how you > >>>> ? ? ? ? ?imagine the solution, and > > >>>> ? ? ?(2) if you have any code, please post real code (copy and paste). > > >>>> The above code is not real. > > >>>> Cheers& ? ?hth., > > >>>> - Alf > > >>> Sorry about the sorted != ordered mix up. ?I want to end up with a > >>> *sorted* dict from an unordered list. ?*Sorting the list is not > >>> practical in this case.* ?I am using python 2.5, with an ActiveState > >>> recipe for an OrderedDict. > > >>> Given these requirements/limitations, how would you do it? > > >>> My solution is to create a regular dict from the list. ?Then sort the > >>> keys, and add the keys+values to an OrderedDict. ?Since the keys are > >>> being added to the OrderedDict in the correctly sorted order, at the > >>> end I end up with a OrderedDict that is in the correctly *sorted* > >>> order. > > >> If that works for you, I don't understand your assertion that you can't > >> sort the list. If you have the space& ?time to sort the intermediate > >> dict, then it's as easy to create the list& ?sort& ?then the ordered > >> dict from it. It should be faster, because you sort the keys anyway. > > >> Diez > > > Here is how I am converting a regular dict to an ordered dict that is > > sorted by keys. > > > def _getOrderedDict(theDict): > > ? ?ordered = OrderedDict() > > ? ?for k in sorted(theDict.keys()): > > ? ? ? ? ? ?ordered[k] = theDict.pop(k) > > ? ?return ordered > > > The list is a bunch of objects that represent hours worked by > > employees on particular jobs, and accounts, and client purchase orders > > etc. ?From this list, I am generating these sorted dicts that contain > > summarizing information about the list. ?So one of the sorted dicts > > will give a summary of hours worked by job number. ?Another one will > > give summary information by client PO number etc. ?So instead of > > sorting the list a bunch of different ways, I keep the list as is, > > generate the summaries I need into dictionaries, and then sort those > > dictionaries as appropriate. > > Again - why? Unless there is some filtering going on that reduces the > number of total entries before the sorting when building the > intermediate dict, a simple > > ordered = OrderedDict(sorted(the_list, key=lambda v: v['some_key'])) > > won't cost you a dime more. > > I think you believe in building the dict so that ou can have the key for > sorting. As shown abov - you don't need to. > > It might even benefitial to really re-sort the original list, because > that spares you the intermediate list. > > Diez Lets say my list has 1 million items. If I sort the list before summarizing it, I will absolutley have to sort 1 million items. However, if I summarize first, then just sort the keys in the summary dict, I could wind up only sorting 4 or 5 items, if within that 1 million item list, there were only 4 or 5 job numbers for example. The list stays as is, and my summary dictionary is sorted so I can iterate through it and make little reports that humans will like. From jjposner at optimum.net Mon Feb 22 18:34:58 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 22 Feb 2010 18:34:58 -0500 Subject: Efficiently building ordered dict In-Reply-To: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> Message-ID: <4B8314A2.500@optimum.net> On 2/22/2010 4:29 PM, Bryan wrote: > > Sorry about the sorted != ordered mix up. I want to end up with a > *sorted* dict from an unordered list. *Sorting the list is not > practical in this case.* I am using python 2.5, with an ActiveState > recipe for an OrderedDict. > Have you looked at this: http://pypi.python.org/pypi/sorteddict/1.2.1 >>> data = zip('afcedbijhg', range(10)) >>> old = dict(data) >>> for key in old: ... print key, old[key] ... a 0 c 2 b 5 e 3 d 4 g 9 f 1 i 6 h 8 j 7 >>> new = sorteddict.sorteddict(data) >>> for key in new: ... print key, new[key] ... a 0 b 5 c 2 d 4 e 3 f 1 g 9 h 8 i 6 j 7 -John From phlip2005 at gmail.com Mon Feb 22 18:57:22 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 22 Feb 2010 15:57:22 -0800 (PST) Subject: When will Python go mainstream like Java? References: Message-ID: On Feb 22, 3:27?pm, Krister Svanlund wrote: > And when will be as famous as the Beatles? And when will Message-ID: You mean it's not? -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From alexanderjquinn at yahoo.com Mon Feb 22 19:01:44 2010 From: alexanderjquinn at yahoo.com (Alex Quinn) Date: Mon, 22 Feb 2010 16:01:44 -0800 (PST) Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? In-Reply-To: <6cc20cea1002221141u534fd5f7v8748f50f9094011f@mail.gmail.com> References: <973565.53691.qm@web38208.mail.mud.yahoo.com> <6cc20cea1002221141u534fd5f7v8748f50f9094011f@mail.gmail.com> Message-ID: <146400.8956.qm@web38205.mail.mud.yahoo.com> Thanks for the reply, Jonathan, but I was hoping to find a workaround. I don't have root access for these machines so I can't repair the install. Among the 6 Linux servers at 3 separately managed organizations where I do work, the sqlite3 module was broken 100% of the time. It seems to be a common problem, so I'd like to make my code robust enough to deal with it gracefully. Ideally, the Python build process would refuse to install a faulty install, but that's another matter. I'm just looking for a workaround. Thanks, Alex ----- Original Message ---- From: Jonathan Gardner To: Alex Quinn Cc: python-list at python.org Sent: Mon, February 22, 2010 2:41:45 PM Subject: Re: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? On Mon, Feb 22, 2010 at 9:10 AM, Alex Quinn wrote: > > * Sqlite3 should fill the void now. However, in my experience, nearly every Linux Python install I encounter has a broken sqlite3 module ("ImportError: No module named _sqlite3"). It's a well-documented issue, but it the solution generally requires root access, which I don't have on these servers. > If your program is installed in the same way everything else is installed on the system (RPM or deb packages, or whatever), there should be dependencies clearly listed. When the admin installs your code, he must also install the requisite modules that you list as dependencies. -- Jonathan Gardner jgardner at jonathangardner.net From rhodri at wildebst.demon.co.uk Mon Feb 22 19:20:18 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 23 Feb 2010 00:20:18 -0000 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> Message-ID: On Mon, 22 Feb 2010 10:48:55 -0000, DANNY wrote: > On Feb 21, 1:54 am, Tim Roberts wrote: >> DANNY wrote: >> >> >If I want to have a MPEG-4/10 coded video and stream it through the >> >network and than have the same video on the client side, what should I >> >use and of course I don't want to have raw MPEG data, because than I >> >couldn't extract the frames to manipulate them. >> >> If you want to manipulate the frames (as bitmaps), then you have little >> choice but to decode the MPEG as you receive it, manipulate the bitmaps, >> and re-encode it back to MPEG. >> >> That's going to take a fair amount of time... >> -- >> Tim Roberts, t... at probo.com >> Providenza & Boekelheide, Inc. > > Yes, well beside bieng time-consuming, that is also inappropriate for > me, > because I want to have clip that would be streamed across the network > and > have the same GoP on the client side as the original-because I want to > see > what is the effect of errors on different GoP sizes. I would > manipuleta the > received clip just in the way that (if there are too many errors) I > would > stop displaying untill the next I frame.....I cant find a way to do > that....is there a way? Could you say a bit more about what you mean when you say "the effect of errors"? It's easy enough to introduce bit errors into a data file (just flip random bits), but I'm not clear what it is you're trying to measure. -- Rhodri James *-* Wildebeeste Herder to the Masses From wolftracks at invalid.com Mon Feb 22 20:25:30 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 17:25:30 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: So what's the bottom line? This link notion is completely at odds with XP, and produces what I would call something of a mess to the unwary Python/W7 user. Is there a simple solution? How do I get out of this pickle? I just want to duplicate the program in another folder, and not link to an ancestor. From shawn at milochik.com Mon Feb 22 20:54:28 2010 From: shawn at milochik.com (Shawn Milochik) Date: Mon, 22 Feb 2010 20:54:28 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: When will Java be popular enough to replace other languages in their own environments, the way Python has done to Java (Jython) and .NET (IronPython)? Shawn From stef.mientki at gmail.com Mon Feb 22 21:01:18 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 23 Feb 2010 03:01:18 +0100 Subject: How to transmit a crash report ? Message-ID: <4B8336EE.9040802@gmail.com> hello, in my python desktop applications, I'ld like to implement a crash reporter. By redirecting the sys.excepthook, I can detect a crash and collect the necessary data. Now I want that my users sends this information to me, and I can't find a good way of doing this. The following solutions came into my mind: (most of my users are on Windows, and the programs are written in Python 2.6) 1. mailto: doesn't work if the the user didn't install a default email client, or if the user uses a portable email client (that isn't started yet) Besides this limits the messages to small amounts of data. 2.other mail options: smtp AFAIK such a solution needs smtp authorization, and therefor I've to put my username and password in the desktop application. 3. http-post Although post is also limited in size, I could store information in cookies (don't know yet how), and cookies are sent parallel to the post message. On the server site I can use a small php script, that stores the post-data, cookies and/or send's a (long) email. are there better options ? thanks, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From gt67 at hw.ac.uk Mon Feb 22 21:24:00 2010 From: gt67 at hw.ac.uk (Giorgos Tzampanakis) Date: Tue, 23 Feb 2010 02:24:00 +0000 (UTC) Subject: Writing an assembler in Python Message-ID: I'm implementing a CPU that will run on an FPGA. I want to have a (dead) simple assembler that will generate the machine code for me. I want to use Python for that. Are there any libraries that can help me with the parsing of the assembly code? From nagle at animats.com Mon Feb 22 21:24:04 2010 From: nagle at animats.com (John Nagle) Date: Mon, 22 Feb 2010 18:24:04 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> Message-ID: <4b83383b$0$1622$742ec2ed@news.sonic.net> sjdevnull at yahoo.com wrote: > On Feb 20, 9:58 pm, John Nagle wrote: >> sjdevn... at yahoo.com wrote: >>> On Feb 18, 2:58 pm, John Nagle wrote: >>>> Multiple processes are not the answer. That means loading multiple >>>> copies of the same code into different areas of memory. The cache >>>> miss rate goes up accordingly. >>> A decent OS will use copy-on-write with forked processes, which should >>> carry through to the cache for the code. >> That doesn't help much if you're using the subprocess module. The >> C code of the interpreter is shared, but all the code generated from >> Python is not. > > Of course. Multithreading also fails miserably if the threads all try > to call exec() or the equivalent. > > It works fine if you use os.fork(). Forking in multithreaded programs is iffy. What happens depends on the platform, and it's usually not what you wanted to happen. Solaris before version 10 forks all threads, and both new processes have all the threads running. POSIX semantics are to fork only the thread making the request. The problem is that this leaves the other Python threads in the new process with Python state, locks and reference counts set, but no OS thread to run them. See "http://bugs.python.org/issue1683" "http://bugs.python.org/issue874900" "http://bugs.python.org/issue6721" "http://bugs.python.org/issue7242" There are at least two open bug reports in this area. If you fork and "exec", which discards the state of Python in the child process, there's less trouble. But if you're actually forking a Python environment and running it, you're going to have at least a memory leak, and probably further difficulties. John Nagle From python at mrabarnett.plus.com Mon Feb 22 21:27:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Feb 2010 02:27:41 +0000 Subject: How to transmit a crash report ? In-Reply-To: <4B8336EE.9040802@gmail.com> References: <4B8336EE.9040802@gmail.com> Message-ID: <4B833D1D.6080908@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > in my python desktop applications, > I'ld like to implement a crash reporter. > By redirecting the sys.excepthook, > I can detect a crash and collect the necessary data. > Now I want that my users sends this information to me, > and I can't find a good way of doing this. > > The following solutions came into my mind: > (most of my users are on Windows, and the programs are written in Python > 2.6) > > 1. mailto: > doesn't work if the the user didn't install a default email client, > or if the user uses a portable email client (that isn't started yet) > Besides this limits the messages to small amounts of data. > > 2.other mail options: smtp > AFAIK such a solution needs smtp authorization, and therefor I've to put > my username and password in the desktop application. > Try reading the documentation for Python's smtplib module. You don't need to provide any password. > 3. http-post > Although post is also limited in size, > I could store information in cookies (don't know yet how), and cookies > are sent parallel to the post message. > On the server site I can use a small php script, that stores the > post-data, cookies and/or send's a (long) email. > > are there better options ? > From no.email at nospam.invalid Mon Feb 22 21:33:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 18:33:40 -0800 Subject: Writing an assembler in Python References: Message-ID: <7x635obrzv.fsf@ruckus.brouhaha.com> Giorgos Tzampanakis writes: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. I want to use Python for that. Are there any libraries that > can help me with the parsing of the assembly code? One "dead simple" option is the re module. From drobinow at gmail.com Mon Feb 22 21:39:34 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 22 Feb 2010 21:39:34 -0500 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <4eb0089f1002221839v75fa29dbg7beef5ce46b2cb50@mail.gmail.com> On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson wrote: > How do I get out of this pickle? I just want to duplicate the ?program in > another folder, and not link to an ancestor. Ask in an appropriate forum. I'm not sure where that is but you might try http://www.sevenforums.com/ From ldo at geek-central.gen.new_zealand Mon Feb 22 22:08:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 16:08:19 +1300 Subject: Writing an assembler in Python References: Message-ID: In message , Giorgos Tzampanakis wrote: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. Let me suggest an alternative approach: use Python itself as the assembler. Call routines in your library to output the code. That way you have a language more powerful than any assembler. See for an example. From ldo at geek-central.gen.new_zealand Mon Feb 22 22:10:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 16:10:03 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <3aa0205f-1e98-4376-92e4-607f96f13616@k19g2000yqc.googlegroups.com> Message-ID: In message <3aa0205f-1e98-4376-92e4-607f96f13616 at k19g2000yqc.googlegroups.com>, Michael Sparks wrote: > [1] This is perhaps more appropriate because '(a b c) is equivalent > to (quote a b c), and quote a b c can be viewed as close to > python's expression "lambda: a b c" You got to be kidding. From ldo at geek-central.gen.new_zealand Mon Feb 22 22:14:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 16:14:42 +1300 Subject: MySQLdb, blobs, and inserting References: <85itgj$mlc$1@nnrp1.deja.com> <85k0fd$hv2$1@news1.xs4all.nl> <387de600.0@news.cyberway.com.sg> Message-ID: In message , Dennis Lee Bieber wrote: > Besides, the approved method of interacting with MySQLdb would use: > > c.execute("insert into items (story) values (%s)", > (file.read(), ) ) > > which lets the adapter properly escape any dangerous characters in the > data, then wrap it with any needed quotes. There are so many situations this cannot deal with... From e_d_k at yahoo.com Mon Feb 22 22:47:26 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Mon, 22 Feb 2010 19:47:26 -0800 (PST) Subject: Writing an assembler in Python In-Reply-To: Message-ID: <166845.21850.qm@web58906.mail.re1.yahoo.com> > Subject: Re: Writing an assembler in Python > Giorgos > Tzampanakis wrote: > > > I'm implementing a CPU that will run on an FPGA. I > want to have a > > (dead) simple assembler that will generate the machine > code for > > me. > > Let me suggest an alternative approach: use Python itself > as the assembler. > Call routines in your library to output the code. That way > you have a > language more powerful than any assembler. > > See for > an example. > -- > http://mail.python.org/mailman/listinfo/python-list > Not a bad idea, has anyone tried this for x86 machine code? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From rpjanaka at gmail.com Mon Feb 22 22:48:54 2010 From: rpjanaka at gmail.com (R. P. Janaka) Date: Tue, 23 Feb 2010 09:18:54 +0530 Subject: How to get memory and CPU status of a particular process Message-ID: Hi all, Is there a way to get system memory consumption and CPU consumption in a platform independent way, using python...? Basically my requirement is, get the memory status and CPU status of a particular process. If there is a way to get memory info and CPU info by just giving the process ID, that is exactly what I need to do :) Is this possible with python..? -- Regards, R. P. Janaka -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Mon Feb 22 23:06:30 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 20:06:30 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On 2/22/2010 6:39 PM, David Robinow wrote: > On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson wrote: >> How do I get out of this pickle? I just want to duplicate the program in >> another folder, and not link to an ancestor. > Ask in an appropriate forum. I'm not sure where that is but you might > try http://www.sevenforums.com/ Not in my NG list. If the way this is going is that it occurs on W7, not just in my case, then it will impact many Python users. From g.bogle at auckland.no.spam.ac.nz Mon Feb 22 23:32:22 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 23 Feb 2010 17:32:22 +1300 Subject: Problem creating executable, with PyQwt References: Message-ID: David Boddie wrote: > I have previously referred people with py2exe/PyQt issues to this page on > the PyQt Wiki: > > http://www.py2exe.org/index.cgi/Py2exeAndPyQt > > If you can somehow convince py2exe to include the QtSvg module (and > presumably the libQtSvg library as well) then perhaps that will solve > this problem. > > David Thanks David, that worked a treat. :-) From jgardner at jonathangardner.net Mon Feb 22 23:35:15 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 20:35:15 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <87iq9pt3l5.fsf@castleamber.com> References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <6cc20cea1002222035y34c8b052qa352d1a7daf5db10@mail.gmail.com> On Mon, Feb 22, 2010 at 12:31 PM, John Bokma wrote: > > In my class there where basically 2 groups of people: the ones who got > functional programming and the ones who had a hard time with it. The > latter group consisted mostly of people who had been programming in > languages like C and Pascal for years; they had a hard time thinking > functionally. The former group consisted mostly of people who had little > or no programming experience, with a few exceptions (including me :-) ). > > So I have the feeling it has more to do with your background then how > people think / are wired. > That's encouraging. If functional programming is really more natural to those who are less familiar with math and programming, then perhaps there is a future for it. Unfortunately, I don't know that just knowing how to program functionally is enough. Even the functional folks have a hard time optimizing routines (time or memory). Even with DBAs, they have to know how the functional SQL query is translated into discrete machine instructions. As it is now, the vast majority (all?) of the programmers who do any programming seriously are familiar with the statement-based approach. A minority understand let alone appreciate the functional approach. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Mon Feb 22 23:36:55 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 20:36:55 -0800 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> On Mon, Feb 22, 2010 at 1:56 PM, AON LAZIO wrote: > That will be superb > It already has. -- Jonathan Gardner jgardner at jonathangardner.net From alfps at start.no Mon Feb 22 23:50:14 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Feb 2010 05:50:14 +0100 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: * W. eWatson: > So what's the bottom line? This link notion is completely at odds with > XP, Well, Windows NT has always had *hardlinks*. I found it a bit baffling that that functionality is documented as not implemented for Windows in the Python standard library. But OK, it was non-trivial to do prior to Windows 2000; you had to sort of hack it using the backup APIs since the functionality was not exposed through the ordinary file APIs. > and produces what I would call something of a mess to the unwary > Python/W7 user. Is there a simple solution? > > How do I get out of this pickle? I just want to duplicate the program > in another folder, and not link to an ancestor. Copy and paste. Cheers & hth., - Alf From wolftracks at invalid.com Tue Feb 23 00:05:28 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 21:05:28 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <4B836218.1000600@invalid.com> On 2/22/2010 8:50 PM, Alf P. Steinbach wrote: > * W. eWatson: >> So what's the bottom line? This link notion is completely at odds with >> XP, > > Well, Windows NT has always had *hardlinks*. > > I found it a bit baffling that that functionality is documented as not > implemented for Windows in the Python standard library. > > But OK, it was non-trivial to do prior to Windows 2000; you had to sort > of hack it using the backup APIs since the functionality was not exposed > through the ordinary file APIs. > > > >> and produces what I would call something of a mess to the unwary >> Python/W7 user. Is there a simple solution? >> >> How do I get out of this pickle? I just want to duplicate the program >> in another folder, and not link to an ancestor. > > Copy and paste. > > > Cheers & hth., > > - Alf I thought that's what I did. Is there some other way? From no.email at nospam.invalid Tue Feb 23 00:06:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 21:06:32 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <7xy6iky207.fsf@ruckus.brouhaha.com> Steve Howell writes: > My gut instinct is that functional programming works well for lots of > medium sized problems and it is worth learning. I think it's worth learning because it will make you a better programmer even if you never use it for anything beyond academic exercises. It's just like playing Bach fugues in some of your practice hours will make you a better musician even if you are professionally a heavy metal rock guitarist. From wolftracks at invalid.com Tue Feb 23 00:09:51 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 21:09:51 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On 2/22/2010 8:50 PM, Alf P. Steinbach wrote: > * W. eWatson: >> So what's the bottom line? This link notion is completely at odds with >> XP, > > Well, Windows NT has always had *hardlinks*. > > I found it a bit baffling that that functionality is documented as not > implemented for Windows in the Python standard library. > > But OK, it was non-trivial to do prior to Windows 2000; you had to sort > of hack it using the backup APIs since the functionality was not exposed > through the ordinary file APIs. > > > >> and produces what I would call something of a mess to the unwary >> Python/W7 user. Is there a simple solution? >> >> How do I get out of this pickle? I just want to duplicate the program >> in another folder, and not link to an ancestor. > > Copy and paste. > > > Cheers & hth., > > - Alf Alf? Hello,Norway. My wife is Norwegian and that was her father's name. I thought that's what I did. Is there some other way? Tusin Tak (That's about the size of my vocabulary and spelling ability! 1000 thanks. What is the correct spelling?) From timr at probo.com Tue Feb 23 00:10:55 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Feb 2010 21:10:55 -0800 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> Message-ID: DANNY wrote: > >Yes, well beside bieng time-consuming, that is also inappropriate >for me, because I want to have clip that would be streamed across >the network and have the same GoP on the client side as the >original-because I want to see what is the effect of errors on >different GoP sizes. I would manipuleta the received clip just >in the way that (if there are too many errors) I would >stop displaying untill the next I frame.....I cant find a way to do >that....is there a way? Sure. You can do a partial decode yourself, scan for the start of frame markers, pull the I/P/B state from that, and periodically "forget" to pass the buffer through. Your filter could have MPEG in and out. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From showell30 at yahoo.com Tue Feb 23 00:11:25 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:11:25 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: On Feb 22, 8:35?pm, Jonathan Gardner wrote: > On Mon, Feb 22, 2010 at 12:31 PM, John Bokma wrote: > > > In my class there where basically 2 groups of people: the ones who got > > functional programming and the ones who had a hard time with it. The > > latter group consisted mostly of people who had been programming in > > languages like C and Pascal for years; they had a hard time thinking > > functionally. The former group consisted mostly of people who had little > > or no programming experience, with a few exceptions (including me :-) ). > > > So I have the feeling it has more to do with your background then how > > people think / are wired. > > That's encouraging. If functional programming is really more natural > to those who are less familiar with math and programming, then perhaps > there is a future for it. > > Unfortunately, I don't know that just knowing how to program > functionally is enough. Even the functional folks have a hard time > optimizing routines (time or memory). Even with DBAs, they have to > know how the functional SQL query is translated into discrete machine > instructions. > > As it is now, the vast majority (all?) of the programmers who do any > programming seriously are familiar with the statement-based approach. > A minority understand let alone appreciate the functional approach. > Hi Jonathon. I understand three major programming paradigms-- imperative, OO, and functional. My first instinct is always imperative, as I just want the computer to *do* stuff. I am not an expert in any paradigm and it is possible that I am overlooking other major paradigms. My gut instinct is that functional programming works well for lots of medium sized problems and it is worth learning. From wolftracks at invalid.com Tue Feb 23 00:15:01 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 21:15:01 -0800 Subject: What's Going on between (Verify) Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: Maybe someone could verify my result? open file read file line print line close file data 1234 Execute it in a folder Create another folder and copy the program to it. put in a new data file as data 4567 Execute the copied program Does it give data1234? From showell30 at yahoo.com Tue Feb 23 00:17:36 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:17:36 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <84a4a03f-22dd-4f05-b754-f1e55f6fdfa6@v20g2000prb.googlegroups.com> On Feb 22, 9:11?pm, Steve Howell wrote: > On Feb 22, 8:35?pm, Jonathan Gardner > wrote: > > > > > On Mon, Feb 22, 2010 at 12:31 PM, John Bokma wrote: > > > > In my class there where basically 2 groups of people: the ones who got > > > functional programming and the ones who had a hard time with it. The > > > latter group consisted mostly of people who had been programming in > > > languages like C and Pascal for years; they had a hard time thinking > > > functionally. The former group consisted mostly of people who had little > > > or no programming experience, with a few exceptions (including me :-) ). > > > > So I have the feeling it has more to do with your background then how > > > people think / are wired. > > > That's encouraging. If functional programming is really more natural > > to those who are less familiar with math and programming, then perhaps > > there is a future for it. > > > Unfortunately, I don't know that just knowing how to program > > functionally is enough. Even the functional folks have a hard time > > optimizing routines (time or memory). Even with DBAs, they have to > > know how the functional SQL query is translated into discrete machine > > instructions. > > > As it is now, the vast majority (all?) of the programmers who do any > > programming seriously are familiar with the statement-based approach. > > A minority understand let alone appreciate the functional approach. > > Hi Jonathon. ?I understand three major programming paradigms-- > imperative, OO, and functional. ?My first instinct is always > imperative, as I just want the computer to *do* stuff. > > I am not an expert in any paradigm and it is possible that I am > overlooking other major paradigms. > > My gut instinct is that functional programming works well for lots of > medium sized problems and it is worth learning. Sorry for misspelling your name, and yes I agree that you always want some notion of what happens under the covers (in any paradigm). From showell30 at yahoo.com Tue Feb 23 00:27:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:27:04 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> <7xy6iky207.fsf@ruckus.brouhaha.com> Message-ID: <05059b42-105b-4822-8448-d30add1dba15@k2g2000pro.googlegroups.com> On Feb 22, 9:06?pm, Paul Rubin wrote: > Steve Howell writes: > > My gut instinct is that functional programming works well for lots of > > medium sized problems and it is worth learning. > > I think it's worth learning because it will make you a better programmer > even if you never use it for anything beyond academic exercises. ?It's > just like playing Bach fugues in some of your practice hours will make > you a better musician even if you are professionally a heavy metal rock > guitarist. Well said, and your analogy is based in fact--some pretty awesome rock guitarists have training in classical and jazz. From clp2 at rebertia.com Tue Feb 23 00:45:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Feb 2010 21:45:24 -0800 Subject: When will Python go mainstream like Java? In-Reply-To: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> Message-ID: <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> On Mon, Feb 22, 2010 at 8:36 PM, Jonathan Gardner wrote: > On Mon, Feb 22, 2010 at 1:56 PM, AON LAZIO wrote: >> That will be superb >> > It already has. Indeed. Python is at position 7, just behind C#, in the TIOBE Index: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html Although for Java-level mainstreamness, you'd probably need to be in the top 3 or 4. Cheers, Chris -- The TIOBE Index is by no means perfect though. http://blog.rebertia.com From showell30 at yahoo.com Tue Feb 23 00:54:09 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:54:09 -0800 (PST) Subject: When will Python go mainstream like Java? References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> Message-ID: <96c61ffb-108e-40af-9b45-7ac9b7289cb5@t34g2000prm.googlegroups.com> On Feb 22, 9:45?pm, Chris Rebert wrote: > On Mon, Feb 22, 2010 at 8:36 PM, Jonathan Gardner > > wrote: > > On Mon, Feb 22, 2010 at 1:56 PM, AON LAZIO wrote: > >> That will be superb > > > It already has. > > Indeed. Python is at position 7, just behind C#, in the TIOBE Index:http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > Although for Java-level mainstreamness, you'd probably need to be in > the top 3 or 4. > > Cheers, > Chris > -- > The TIOBE Index is by no means perfect though.http://blog.rebertia.com I am sure Python could rise to number six with some squigglies! ;) From timr at probo.com Tue Feb 23 00:57:22 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Feb 2010 21:57:22 -0800 Subject: Writing an assembler in Python References: <7x635obrzv.fsf@ruckus.brouhaha.com> Message-ID: <69r6o5948eut0hjjduahf2srl892pnisot@4ax.com> Paul Rubin wrote: > >Giorgos Tzampanakis writes: >> I'm implementing a CPU that will run on an FPGA. I want to have a >> (dead) simple assembler that will generate the machine code for >> me. I want to use Python for that. Are there any libraries that >> can help me with the parsing of the assembly code? > >One "dead simple" option is the re module. Yes, indeed. I have implemented TWO different FPGA-based microassemblers in Python using the essentially undocumented but magically delicious re.Scanner class. Simple and flexible. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From alfps at start.no Tue Feb 23 01:00:48 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Feb 2010 07:00:48 +0100 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: * W. eWatson: > On 2/22/2010 8:50 PM, Alf P. Steinbach wrote: >> * W. eWatson: >>> So what's the bottom line? This link notion is completely at odds with >>> XP, >> >> Well, Windows NT has always had *hardlinks*. >> >> I found it a bit baffling that that functionality is documented as not >> implemented for Windows in the Python standard library. >> >> But OK, it was non-trivial to do prior to Windows 2000; you had to sort >> of hack it using the backup APIs since the functionality was not exposed >> through the ordinary file APIs. >> >> >> >>> and produces what I would call something of a mess to the unwary >>> Python/W7 user. Is there a simple solution? >>> >>> How do I get out of this pickle? I just want to duplicate the program >>> in another folder, and not link to an ancestor. >> >> Copy and paste. >> >> >> Cheers & hth., >> >> - Alf > Alf? Hello,Norway. My wife is Norwegian and that was her father's name. > > I thought that's what I did. Is there some other way? (A) For using Explorer, see and in particular look at the tips at the bottom. (B) To get absolute control you can use the command interpreter. I don't have Windows7 but googling yielded the following URL: The "copy" command there copies files. > Tusin Tak (That's about the size of my vocabulary and spelling ability! > 1000 thanks. What is the correct spelling?) That's "tusen takk". Cheers & hth., - Alf From alfps at start.no Tue Feb 23 01:03:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Feb 2010 07:03:00 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <7xy6iky207.fsf@ruckus.brouhaha.com> References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> <7xy6iky207.fsf@ruckus.brouhaha.com> Message-ID: * Paul Rubin: > Steve Howell writes: >> My gut instinct is that functional programming works well for lots of >> medium sized problems and it is worth learning. > > I think it's worth learning because it will make you a better programmer > even if you never use it for anything beyond academic exercises. It's > just like playing Bach fugues in some of your practice hours will make > you a better musician even if you are professionally a heavy metal rock > guitarist. Uhm, Paganini... As I understand it he invented the "destroy your instruments on stage". :-) Cheers, - Alf (off-topic) From jgorauskas at gmail.com Tue Feb 23 01:06:45 2010 From: jgorauskas at gmail.com (gorauskas) Date: Mon, 22 Feb 2010 22:06:45 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> I installed it on a Windows 7 machine with CPython 2.6.4 and I get the following error: Traceback (most recent call last): File "dreampie.py", line 3, in File "dreampielib\gui\__init__.pyc", line 73, in File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk ImportError: DLL load failed: The specified module could not be found. What am I doing wrong? Thanks, JGG From ryan at rfk.id.au Tue Feb 23 01:10:58 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Tue, 23 Feb 2010 17:10:58 +1100 Subject: ANN: esky v0.4.0 [was Re: Upgrading Py2exe App] In-Reply-To: <1266615136.2495.39.camel@rambutan> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> <1266615136.2495.39.camel@rambutan> Message-ID: <1266905458.3153.16.camel@durian> Hi All, As promised I have made a new release of esky, my auto-update framework for frozen python apps. Details below for those who are interested. Cheers, Ryan ------------------------------- esky: keep frozen apps fresh Esky is an auto-update framework for frozen Python applications. It provides a simple API through which apps can find, fetch and install updates, and a bootstrapping mechanism that keeps the app safe in the face of failed or partial updates. Esky is currently capable of freezing apps with bbfreeze, cxfreeze and py2exe. Support for py2app is in the works. The latest version is v0.4.0, with the following major changes: * added support for freezing with cx_Freeze. * improved support for freezing with py2exe. * added ability to set the icon on each executable (if the chosen freezer module supports it) * made Esky.cleanup() catch and ignore common errors. * added support for Python 3 (via distribute's "use_2to3" flag) * added a brief tutorial and example application * some backwards-incompatible API changes (see ChangeLog for details) Downloads: http://pypi.python.org/pypi/esky/0.4.0/ Code, bugs, etc: http://github.com/rfk/esky/ Tutorial: http://github.com/rfk/esky/tree/master/tutorial/ -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From rpjanaka at gmail.com Tue Feb 23 01:12:27 2010 From: rpjanaka at gmail.com (R. P. Janaka) Date: Tue, 23 Feb 2010 11:42:27 +0530 Subject: How to get memory and CPU status of a particular process In-Reply-To: References: Message-ID: Please can anyone help me..?? On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: > Hi all, > > Is there a way to get system memory consumption and CPU consumption in a > platform independent way, using python...? > > Basically my requirement is, get the memory status and CPU status of a > particular process. If there is a way to get memory info and CPU info by > just giving the process ID, that is exactly what I need to do :) > Is this possible with python..? > > -- > Regards, > R. P. Janaka > -- Regards, R. P. Janaka -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjdevnull at yahoo.com Tue Feb 23 01:27:54 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Mon, 22 Feb 2010 22:27:54 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: On Feb 22, 9:24?pm, John Nagle wrote: > sjdevn... at yahoo.com wrote: > > On Feb 20, 9:58 pm, John Nagle wrote: > >> sjdevn... at yahoo.com wrote: > >>> On Feb 18, 2:58 pm, John Nagle wrote: > >>>> ? ? Multiple processes are not the answer. ?That means loading multiple > >>>> copies of the same code into different areas of memory. ?The cache > >>>> miss rate goes up accordingly. > >>> A decent OS will use copy-on-write with forked processes, which should > >>> carry through to the cache for the code. > >> ? ? That doesn't help much if you're using the subprocess module. ?The > >> C code of the interpreter is shared, but all the code generated from > >> Python is not. > > > Of course. ?Multithreading also fails miserably if the threads all try > > to call exec() or the equivalent. > > > It works fine if you use os.fork(). > > ? ? Forking in multithreaded programs is iffy. ?What happens depends > on the platform, and it's usually not what you wanted to happen. Well, yeah. And threading in multiprocess apps is iffy. In the real world, though, multiprocessing is much more likely to result in a decent app than multithreading--and if you're not skilled at either, starting with multiprocessing is by far the smarter way to begin. Basically, multiprocessing is always hard--but it's less hard to start without shared everything. Going with the special case (sharing everything, aka threading) is by far the stupider and more complex way to approach multiprocssing. And really, for real-world apps, it's much, much more likely that fork() will be sufficient than that you'll need to explore the vagueries of a multithreaded solution. Protected memory rocks, and in real life it's probably 95% of the time where threads are only even considered if the OS can't fork() and otherwise use processes well. From sjdevnull at yahoo.com Tue Feb 23 01:31:12 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Mon, 22 Feb 2010 22:31:12 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: <51de1750-d978-4f2f-8f72-1badf9b5acca@g11g2000yqe.googlegroups.com> On Feb 22, 9:24?pm, John Nagle wrote: > sjdevn... at yahoo.com wrote: > > On Feb 20, 9:58 pm, John Nagle wrote: > >> sjdevn... at yahoo.com wrote: > >>> On Feb 18, 2:58 pm, John Nagle wrote: > >>>> ? ? Multiple processes are not the answer. ?That means loading multiple > >>>> copies of the same code into different areas of memory. ?The cache > >>>> miss rate goes up accordingly. > >>> A decent OS will use copy-on-write with forked processes, which should > >>> carry through to the cache for the code. > >> ? ? That doesn't help much if you're using the subprocess module. ?The > >> C code of the interpreter is shared, but all the code generated from > >> Python is not. > > > Of course. ?Multithreading also fails miserably if the threads all try > > to call exec() or the equivalent. > > > It works fine if you use os.fork(). > > ? ? Forking in multithreaded programs is iffy. One more thing: the above statement ("forking in multithreaded programs is iffy"), is absolutely true, but it's also completely meaningless in modern multiprocessing programs--it's like saying "gotos in structured programs are iffy". That's true, but it also has almost no bearing on decently constructed modern programs. From FearsomeDragonfly at gmail.com Tue Feb 23 01:58:38 2010 From: FearsomeDragonfly at gmail.com (Brad Harms) Date: Tue, 23 Feb 2010 06:58:38 GMT Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? References: Message-ID: On Mon, 22 Feb 2010 09:10:38 -0800, Alex Quinn wrote: > Is there a way to have some kind of database (i.e. sqlite3, bsddb, dbm, > etc.) that works out of the box on any Win/Linux/Mac machine with Python > 2.6+ or 3.x? It's okay if the file format is different between machines, > but I want my script to work without having to install anything. > > Problems with current modules: > > * Shelve used to do this. Unfortunately, since bsddb was > deprecated/removed from the standard distro and Windows doesn't have dbm > or gdbm, the only remaining option on Windows is dumbdbm, which is > discouraged in the docs. > > * Sqlite3 should fill the void now. However, in my experience, nearly > every Linux Python install I encounter has a broken sqlite3 module > ("ImportError: No module named _sqlite3"). It's a well-documented issue, > but it the solution generally requires root access, which I don't have > on these servers. > > Potential solutions: > > * Could I somehow bundle with my project the _sqlite3.so file and/or > whatever else it needs? Or is there an alternate sqlite3 module I could > use as a fallback that would just interface with the sqlite3 executable > on the machine (i.e. /usr/local/bin/sqlite3)? > > * Is there a way to drop bsddb into my project so it works out of the > gate (no install) on either Linux, Windows, or Mac? > > If you have any ideas, I'd be most appreciative. My objective here is > just to find a portable and reliable solution that I can use for small > projects. > > Thanks, > Alex Hi, I'm speaking with little experience here, but one thought I had is to try compiling Pysqlite ( http://pypi.python.org/pypi/pysqlite/2.5.6 ) for each of your target OS's, probably using GCC cross compilers for the platforms you aren't compiling on, then sort of "splice" them together so that _sqlite3 always points to the binary for the current OS. This snippet might help you get started: import sys # Linux binary if 'linux' in sys.platform.lower(): import _sqlite3_linux as _sqlite3 # Windows binary elif 'win32' == sys.platform: import _sqlite3_windows as _sqlite3 # Mac binary elif 'darwin' == sys.platform: import _sqlite3_mac as _sqlite3 sys.modules['_sqlite3'] = _sqlite3 I'm not exactly sure when you would run this code. It would have to be sometime before you import the main sqlite3 module. -- Brad Harms -- http://alphaios.net From clp2 at rebertia.com Tue Feb 23 02:03:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Feb 2010 23:03:55 -0800 Subject: How to get memory and CPU status of a particular process In-Reply-To: References: Message-ID: <50697b2c1002222303td62ea73n4f957dd6de7d0ecd@mail.gmail.com> > On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: >> Hi all, >> >> Is there a way to get system memory consumption and CPU consumption in a >> platform independent way, using python...? >> >> Basically my requirement is, get the memory status and CPU status of a >> particular process. If there is a way to get memory info and CPU info by >> just giving the process ID, that is exactly what I need to do :) >> Is this possible with python..? Given Turing-completeness, one should more precisely ask whether there is already a library for doing something in Python rather than whether something is possible with Python. On Mon, Feb 22, 2010 at 10:12 PM, R. P. Janaka wrote: > Please can anyone help me..?? It is generally customary to wait /at least/ one day before pinging on one's question again. If you were to have searched PyPI (http://pypi.python.org), you would have found psutil, which seems to fit your bill: http://code.google.com/p/psutil/ Cheers, Chris -- This completes today's Netiquette lesson. http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 02:08:30 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Feb 2010 07:08:30 GMT Subject: Use eval() safely? References: <20100221212511.GA23046@beron.tangosoft.com> Message-ID: On Mon, 22 Feb 2010 11:45:10 -0800, Jonathan Gardner wrote: > Why would you ever run untrusted code on any machine in any language, > let alone Python? Because sometimes you have to run untrusted code, so you want to run it in a sandbox so it can't eat your machine. E.g. viewing PDF files. Or you might be building an app that allows the user to enter code and execute it: http://tryruby.org/ > If you're writing a web app, make it so that you only run trusted code. > That is, code installed by the admin, or approved by the admin. But do you trust the admin? Do you think your admin has audited the entire tool chain of every application, library and operating system module in your system? -- Steven From jedady.1 at gmail.com Tue Feb 23 02:12:28 2010 From: jedady.1 at gmail.com (Jedady) Date: Mon, 22 Feb 2010 23:12:28 -0800 (PST) Subject: Now Win a laptop computer from (EZ laptop) free of charge Message-ID: <7f1d8648-fcd0-4e26-a4ae-790e5e660e7f@s36g2000prh.googlegroups.com> All you have to do is just click on the link below and register on- site.And you'll know the rest of the steps on your own http://ezlaptop.com/?r=130329 Good luck to all From paul.nospam at rudin.co.uk Tue Feb 23 02:16:46 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 23 Feb 2010 07:16:46 +0000 Subject: How to get memory and CPU status of a particular process References: Message-ID: <87tyt81kwx.fsf@rudin.co.uk> Chris Rebert writes: >> On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: >>> Hi all, >>> >>> Is there a way to get system memory consumption and CPU consumption in a >>> platform independent way, using python...? >>> >>> Basically my requirement is, get the memory status and CPU status of a >>> particular process. If there is a way to get memory info and CPU info by >>> just giving the process ID, that is exactly what I need to do :) >>> Is this possible with python..? > > Given Turing-completeness, one should more precisely ask whether there > is already a library for doing something in Python rather than whether > something is possible with Python. Turing-completeness is irrelevant to questions like getting memory and CPU info for a process. These are not issues of computability... From clp2 at rebertia.com Tue Feb 23 02:28:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Feb 2010 23:28:01 -0800 Subject: How to get memory and CPU status of a particular process In-Reply-To: <87tyt81kwx.fsf@rudin.co.uk> References: <87tyt81kwx.fsf@rudin.co.uk> Message-ID: <50697b2c1002222328l2a8b79e4wcdc027eaeffc883b@mail.gmail.com> On Mon, Feb 22, 2010 at 11:16 PM, Paul Rudin wrote: > Chris Rebert writes: >>> On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: >>>> Is there a way to get system memory consumption and CPU consumption in a >>>> platform independent way, using python...? >>>> >>>> Basically my requirement is, get the memory status and CPU status of a >>>> particular process. If there is a way to get memory info and CPU info by >>>> just giving the process ID, that is exactly what I need to do :) >>>> Is this possible with python..? >> >> Given Turing-completeness, one should more precisely ask whether there >> is already a library for doing something in Python rather than whether >> something is possible with Python. > > Turing-completeness is irrelevant to questions like getting memory and > CPU info for a process. These are not issues of computability... True, but given that it is possible to access most *nix APIs from Python and win32all provides what I understand to be extensive access to the Win32 API from Python, cross-platform coding is almost always possible in Python. You might have to manually deal with each case yourself though. (More technically, I suppose that's being multi-platform with relatively easy DIY cross-platform). Cheers, Chris -- http://blog.rebertia.com From taskinoor.hasan at csebuet.org Tue Feb 23 02:30:00 2010 From: taskinoor.hasan at csebuet.org (Taskinoor Hasan) Date: Tue, 23 Feb 2010 13:30:00 +0600 Subject: How to get memory and CPU status of a particular process In-Reply-To: References: Message-ID: <79153a2e1002222330s2eeee7c3h8ee9b94126c525e3@mail.gmail.com> On Tue, Feb 23, 2010 at 9:48 AM, R. P. Janaka wrote: > Hi all, > > Is there a way to get system memory consumption and CPU consumption in a > platform independent way, using python...? > > Basically my requirement is, get the memory status and CPU status of a > particular process. If there is a way to get memory info and CPU info by > just giving the process ID, that is exactly what I need to do :) > Is this possible with python..? > I'm afraid that this is not possible in a platform independent way. In case of Windows, you can look at Tim Golden's WMI module for Python. And in case of Linux, you need to dig the details of /proc. Regards Taskinoor Hasan (Sajid) > > -- > Regards, > R. P. Janaka > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From krister.svanlund at gmail.com Tue Feb 23 03:07:43 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 23 Feb 2010 09:07:43 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> On Tue, Feb 23, 2010 at 1:01 AM, Edward A. Falk wrote: > You mean it's not? > > -- > ? ? ? ?-Ed Falk, falk at despams.r.us.com > ? ? ? ?http://thespamdiaries.blogspot.com/ Javas popularity was very much a product of its time. It was something new and exciting and people got a bit too excited maybe, Python just does the same thing but better really, therefor it will not become as popular. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 03:11:52 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Feb 2010 08:11:52 GMT Subject: Bizarre arithmetic results References: Message-ID: On Mon, 22 Feb 2010 18:01:44 +0000, Albert van der Horst wrote: > In article , > Terrence Cole wrote: >>Can someone explain to me what python is doing here? >> >>Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) [GCC 4.3.4] on linux2 >>Type "help", "copyright", "credits" or "license" for more information. >>>>> -0.1 ** 0.1 > > Python 4.0 > Warning: misleading blank space, expected: > - 0.1**0.1 > >>-0.7943282347242815 Making spaces significant in that fashion is mind-bogglingly awful. Let's look at a language that does this: [steve at sylar ~]$ cat ws-example.rb def a(x=4) x+2 end b = 1 print (a + b), (a+b), (a+ b), (a +b), "\n" [steve at sylar ~]$ ruby ws-example.rb 7773 -- Steven From bobbo17141 at googlemail.com Tue Feb 23 03:37:13 2010 From: bobbo17141 at googlemail.com (gabi meier) Date: Tue, 23 Feb 2010 00:37:13 -0800 (PST) Subject: =?ISO-8859-1?Q?wgv_berufsunf=E4higkeitsversicherung=2C_berufsunf=E4higk?= =?ISO-8859-1?Q?eitsversicherung_testsieger=2C_berufsunf=E4higkeitsversicherung?= =?ISO-8859-1?Q?_mlp=2C_berufsunf=E4higkeitsversicherung_preis=2C_hdi_gerling_ber?= =?ISO-8859-1?Q?ufsunf=E4higkeitsversicherung=2C?= Message-ID: wgv berufsunf?higkeitsversicherung, berufsunf?higkeitsversicherung testsieger, berufsunf?higkeitsversicherung mlp, berufsunf?higkeitsversicherung preis, hdi gerling berufsunf?higkeitsversicherung, + + + HAUSRAT VERSICHERUNG +++ HAUSRATVERSICHERUNG BILLIG +++ BILLIGE HAUSRATSVERSICHERUNG + http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL + + + + http://berufsunfaehigkeitsversicherung-arzt.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://berufsunfaehigkeitsversicherung-test-2009.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://berufsunfaehigkeitsversicherung-neue-leben.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://die-beste-berufsunfaehigkeitsversicherung.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL autoversicherungen testsieger berufsunf?higkeit in Schleswig berufsunf?higkeitsversicherung freiberufler metallrente bu in Guinea konkrete verweisbarkeit alte leipziger versicherung in Namibia steuererkl?rung versicherungen abstrakte verweisung in Schleiz berufsunf?higkeit versicherung vergleich berufsunf?hig versicherung in Homburg n?rnberger bu versicherung berufsunf?higkeit rechner in Osnabr?ck berufsunf?higkeit versicherung berufsunf?higkeitsversicherung k?ndigen in Oranienburg bu alte leipziger berufsunf?higkeits versicherung vergleich in Sachsen http://suche.aol.de/aol/search?query=berufsunf?higkeitsversicherungen+im+test+inurl%3Afor-um&invocationType=no.omittWeb&filter=false From ishwor.gurung at gmail.com Tue Feb 23 04:00:47 2010 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Tue, 23 Feb 2010 20:00:47 +1100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <34534aed1002230100v7e06f714oca05933851d2b02c@mail.gmail.com> On 23 February 2010 08:56, AON LAZIO wrote: > That will be superb Yes it would - but I'll just add in few words. Java - Monstrous language that was Sun's flagship language. Now, it's Oracles. Python - Hobby-ish hacking language that we all love so much (that we wish everything was written using Python). Java - The JVM code been hacked to death by Sun engineers (optimised) Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. ad-infinitum but nowhere as near to JVM I like both Python and Java but given the amount of resources put into JVM and Java (JEE is _huge_ in Enterprise if you didn't know that already and there are universities that speak Java fluently), it's kind of sad that Python till the day hasn't seen speedup in mainline releases. I see Python more as a hacker's language which will gradually evolve and support SMEs and alike in the long run than Java (and of course we write our weekend-only hacking projects in it :-) but for a market-uptake like Java requires universities, colleges and students to learn this wonderful little language and requests energetic hackers to fix lock-contention issues and the like in the core implementation. Perhaps I see a light, perhaps I see nothing.. but I feel the day is coming nearer when Python would run as fast as Java/C. Only time can tell - I hope the time is right about this. -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 From processor.dev1l at gmail.com Tue Feb 23 04:24:46 2010 From: processor.dev1l at gmail.com (Processor-Dev1l) Date: Tue, 23 Feb 2010 01:24:46 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: On Feb 21, 10:42?am, Noam Yorav-Raphael wrote: > I'm pleased to announce DreamPie 1.0 - a new graphical interactive > Python shell! > > Some highlights: > > * Has whatever you would expect from a graphical Python shell - > attribute completion, tooltips which show how to call functions, > highlighting of matching parentheses, etc. > * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, > history recall and completion works as expected, etc. > * Results are saved in the Result History. Very good work, Noam, I am looking forward to test this with IronPython :) > * Long output is automatically folded so you can focus on what's > important. > * Jython and IronPython support makes DreamPie a great tool for > exploring Java and .NET classes. > * You can copy any amount of code and immediately execute it, and you > can also copy code you typed interactively into a new file, with the > Copy Code Only command. No tabs are used! > * Free software licensed under GPL version 3. > > Check it out athttp://dreampie.sourceforge.net/and tell me what you > think! > > Have fun, > Noam From sebastian.noack at googlemail.com Tue Feb 23 04:24:48 2010 From: sebastian.noack at googlemail.com (sebastian.noack at googlemail.com) Date: Tue, 23 Feb 2010 01:24:48 -0800 (PST) Subject: os.pipe() + os.fork() References: <20100220113604.49b7c242@gurka> <20100220125250.35c9937d@gurka> Message-ID: <256926de-e175-4fa2-aa24-dbd5f96756ef@u20g2000yqu.googlegroups.com> On Feb 20, 8:13?pm, Gary Herron wrote: > Here's a thought: ?Consider the subprocess module. ? It can do thefork > and any necessary pipes and can do so in an OS independent way. ? It > might make you life much easier. As far as i know the subprocess module provides only functionality for running any program as subprocess. But I just want to fork the current process without putting some code in an external python script. Sebastian Noack From richard.lamboj at bilcom.at Tue Feb 23 04:40:09 2010 From: richard.lamboj at bilcom.at (Richard Lamboj) Date: Tue, 23 Feb 2010 10:40:09 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> References: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> Message-ID: <201002231040.10422.richard.lamboj@bilcom.at> Am Tuesday 23 February 2010 09:07:43 schrieb Krister Svanlund: > On Tue, Feb 23, 2010 at 1:01 AM, Edward A. Falk wrote: > > You mean it's not? > > > > -- > > ? ? ? ?-Ed Falk, falk at despams.r.us.com > > ? ? ? ?http://thespamdiaries.blogspot.com/ > > Javas popularity was very much a product of its time. It was something > new and exciting and people got a bit too excited maybe, Python just > does the same thing but better really, therefor it will not become as > popular. Good morning, i don't like Java/JSP, the synthax is blown up and the programs are damn slow. For ecllipse you should buy a cluster. There is C/C++/D, Python, Ruby, Gambas, TCL, PHP, SmallTalk and some other nice Programming Languages, so i don't understand why people use Java. "Java is the one an only OOP Language, the best one" - Yeah and whats with multiple inheritance? I'am in love with Python ;-) Kind Regards From danijel.gvero at gmail.com Tue Feb 23 05:39:21 2010 From: danijel.gvero at gmail.com (DANNY) Date: Tue, 23 Feb 2010 02:39:21 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> Message-ID: <19c11c1f-d70e-4b10-b425-6e65d4c70aeb@d2g2000yqa.googlegroups.com> @James I am thinkinhg about effect of errors that are within the sequence of P frames. Where the P frames have only the information about the changes in previous frames, so that errors are present until the next I frame. So I would like to see how is this seen in different GoP sized clips. @Tim Thanks for the advice, now I will try to do that so I have a lot of work in front of me. I will post any problems if they occure. Guys thank you again for the help! From hackingkk at gmail.com Tue Feb 23 05:53:57 2010 From: hackingkk at gmail.com (hackingKK) Date: Tue, 23 Feb 2010 16:23:57 +0530 Subject: When will Python go mainstream like Java? In-Reply-To: <201002231040.10422.richard.lamboj@bilcom.at> References: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> <201002231040.10422.richard.lamboj@bilcom.at> Message-ID: <4B83B3C5.5020502@gmail.com> On Tuesday 23 February 2010 03:10 PM, Richard Lamboj wrote: > Am Tuesday 23 February 2010 09:07:43 schrieb Krister Svanlund: > >> On Tue, Feb 23, 2010 at 1:01 AM, Edward A. Falk >> > wrote: > >>> You mean it's not? >>> >>> -- >>> -Ed Falk, falk at despams.r.us.com >>> http://thespamdiaries.blogspot.com/ >>> >> Javas popularity was very much a product of its time. It was something >> new and exciting and people got a bit too excited maybe, Python just >> does the same thing but better really, therefor it will not become as >> popular. >> > Good morning, > > i don't like Java/JSP, the synthax is blown up and the programs are damn slow. > For ecllipse you should buy a cluster. There is C/C++/D, Python, Ruby, > Gambas, TCL, PHP, SmallTalk and some other nice Programming Languages, so i > don't understand why people use Java. "Java is the one an only OOP Language, > the best one" - Yeah and whats with multiple inheritance? I'am in love with > Python ;-) > There are a few reasons why we don't see python as a "buz word". Java was well marketed and the time when it came out with libraries like swing, there was no popularly known alternative. As a matter of fact I don't really go by popularity with technologies, specially when it comes to programming languages. Just show me 2 or 3 big apps or web sites which are scalable and take multiple requests. show me just 2 instances where heavy number crunching is done efficiently and I am convinced. I don't care how many apps are developed using java as long as they remain heavy and sloooooooow. google runs on python and so do many other big applications. marketing is more about exaggeration, which Sun did for Java. Python was always in the hands of programmers who wanted their work done and wanted scalable apps. So the conclusion is that "all that is popular need not be good for every thing ". Happy hacking. Krishnakant. From peloko45 at gmail.com Tue Feb 23 05:54:25 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 23 Feb 2010 02:54:25 -0800 (PST) Subject: Fascism is coming to Internet Message-ID: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> *Sorry by this message off topic, but this is too important* Fascism is coming fastly to Internet because is the only communication way that governements (managed by the bank and multinationals) cann't control http://www.boingboing.net/2010/02/21/acta-internet-enforc.html From stefan_ml at behnel.de Tue Feb 23 05:56:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Feb 2010 11:56:39 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: Chris Rebert, 23.02.2010 06:45: > Indeed. Python is at position 7, just behind C#, in the TIOBE Index: > http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html That index is clearly flawed. A language like PHP (whatever that is supposed to be comparable with) can't possibly be on the rise, can it? Stefan From darcy at druid.net Tue Feb 23 06:33:40 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 06:33:40 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <20100223063340.c891740a.darcy@druid.net> On Tue, 23 Feb 2010 02:54:25 -0800 (PST) Joan Miller wrote: > *Sorry by this message off topic, but this is too important* Is it just me or has the spew from gmail on this list radically increased in the last week? Anyone else considering blocking all gmail posts to this list? -- 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 generalcody at gmail.com Tue Feb 23 06:50:15 2010 From: generalcody at gmail.com (General Cody) Date: Tue, 23 Feb 2010 12:50:15 +0100 Subject: Combining C and Python programs References: Message-ID: <2010022312501516807-generalcody@gmailcom> Well... This is really a RTFM question. It's all in the Python docs... And it's really simple. From aharrisreid at googlemail.com Tue Feb 23 06:56:21 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Tue, 23 Feb 2010 11:56:21 +0000 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> Message-ID: <4B83C265.2090802@googlemail.com> gorauskas wrote: > I installed it on a Windows 7 machine with CPython 2.6.4 and I get the > following error: > > Traceback (most recent call last): > File "dreampie.py", line 3, in > File "dreampielib\gui\__init__.pyc", line 73, in > File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk > ImportError: DLL load failed: The specified module could not be found. > > What am I doing wrong? > > Thanks, JGG And I installed it on WinXP sp3 and Python 3.1 - when launched a window flashes before my eyes, then disappears! Has the installation package been checked for all common Windows versions? Regards, Alan From noamraph at gmail.com Tue Feb 23 07:11:07 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Tue, 23 Feb 2010 14:11:07 +0200 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: ?Thanks! I'm happy you like it! Thanks for the feedback too. Here are my replies. On Sun, Feb 21, 2010 at 7:13 PM, Chris Colbert wrote: > This is bloody fantastic! I must say, this fixes everything I hate about > Ipython and gives me the feature I wished it had (with a few minor > exceptions). > I confirm this working on Kubuntu 9.10 using the ppa listed on the sites > download page. Great. It's important to know. > I also confirm that it works interactively with PyQt4 and PyGtk (as to be > expected since these toolkits use the PyOS_inputhook for the mainloop). > However, it does not work interactively with wx (again, this is as expected > since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support > is the same as in Ipython if you dont use any of the magic threading > switches, which are now?deprecated?anyway. Actually, currently DreamPie doesn't use PyOS_inputhook, but implements the GUI hooks by itself. So it should be possible to implement wx support if there's a way to handle events for a few milliseconds. I tried it a bit and didn't find how to do it - if you are interested in wx support and think you can help, please do. > Matplotlib does not work interactively for me. Is there a special switch > that needs to be used? or should a pick a non-wx backend? (i'm thinking the > latter is more likely) You should set "interactive:True" in your matplotlibrc file. The next DreamPie version will warn about this. > A couple of things I would like to see (and will help implement if I can > find the time): > 1) A shortcut to show the docstring of an object. Something like Ipython's > `?`. i.e. ?`object.foo?` translates to `help(object.foo)` I wrote this at http://wiki.python.org/moin/DreamPieFeatureRequests . I hope I will manage to implement this soon. > 2) How do I change the color of the blinking cursor at the bottom? I can't > see the damn thing! It should be in the color of the default text. If this is not the case, please file a bug! > 3) line numbers instead of the `>>>` prompt I know IPython does this, but I thought you needed it only if placing the cursor on top of the command doesn't do anything. Can you tell me why do you need this in the context of a graphical user interface? > 4) a plugin facility where we can define our own `magic` commands. I use > Ipython's %timeit ALL the time. Added it to the feature request page. > 5) Double-click to re-fold the output section as well. I don't think that's a good idea, because usually double-click selects the word, and I don't want to change that behavior for regular text. You can use ctrl-minus to fold the last output section! > Thanks for making this!!!! Thanks for the feedback! Noam From rdv at roalddevries.nl Tue Feb 23 07:48:51 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Tue, 23 Feb 2010 13:48:51 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: On Feb 22, 2010, at 10:56 PM, AON LAZIO wrote: > That will be superb I guess static typing will have to be added, so that tools like eclipse can inspect (and autocomplete) your programs [better]. From jeanmichel at sequans.com Tue Feb 23 07:50:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 23 Feb 2010 13:50:15 +0100 Subject: Avoid converting functions to methods in a class In-Reply-To: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4B83CF07.5000009@sequans.com> Steven D'Aprano wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. > > Are there any better solutions? > > > It looks like it works when declaring foo as static: import unittest def foo(a,b): return 'fooo' class AnotherTest(unittest.TestCase): target = staticmethod(foo) def test_foo(self): self.assertEquals(self.target('a', 'b'), 'foo') def runTest(self): self.test_foo() AnotherTest().runTest() ...AssertionError: 'fooo' != 'foo' JM From wolftracks at invalid.com Tue Feb 23 08:03:26 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 05:03:26 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 Message-ID: In the last day, I posted a message titled "What's Going on between Python and win7?" I'd appreciate it if someone could verify my claim. A sample program to do this is below. I'm using IDLE in Win7 with Py 2.5. My claim is that if one creates a program in a folder that reads a file in the folder it and then copies it to another folder, it will read the data file in the first folder, and not a changed file in the new folder. I'd appreciate it if some w7 users could try this, and let me know what they find. My experience is that if one checks the properties of the copied file, it will point to the original py file and execute it and not the copy. # Test program. Examine strange link in Python under Win7 # when copying py file to another folder. # Call the program vefifywin7.py # To verify my situation use IDLE, save and run this program there. # Put this program into a folder along with a data file # called verify.txt. Create a single text line with a few characters in it # Run this program and note if the output # Copy the program and txt file to another folder # Change the contents of the txt file # Run it again, and see if the output is the same as in the other folder track_file = open("verify.txt") aline = track_file.readline(); print aline track_file.close() From olof.bjarnason at gmail.com Tue Feb 23 08:25:07 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Tue, 23 Feb 2010 14:25:07 +0100 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: 2010/2/23 Noam Yorav-Raphael : > ?Thanks! I'm happy you like it! > Thanks for the feedback too. Here are my replies. > > On Sun, Feb 21, 2010 at 7:13 PM, Chris Colbert wrote: >> This is bloody fantastic! I must say, this fixes everything I hate about >> Ipython and gives me the feature I wished it had (with a few minor >> exceptions). >> I confirm this working on Kubuntu 9.10 using the ppa listed on the sites >> download page. > Great. It's important to know. > >> I also confirm that it works interactively with PyQt4 and PyGtk (as to be >> expected since these toolkits use the PyOS_inputhook for the mainloop). >> However, it does not work interactively with wx (again, this is as expected >> since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support >> is the same as in Ipython if you dont use any of the magic threading >> switches, which are now?deprecated?anyway. > Actually, currently DreamPie doesn't use PyOS_inputhook, but > implements the GUI hooks by itself. So it should be possible to > implement wx support if there's a way to handle events for a few > milliseconds. I tried it a bit and didn't find how to do it - if you > are interested in wx support and think you can help, please do. > >> Matplotlib does not work interactively for me. Is there a special switch >> that needs to be used? or should a pick a non-wx backend? (i'm thinking the >> latter is more likely) > You should set "interactive:True" in your matplotlibrc file. The next > DreamPie version will warn about this. > >> A couple of things I would like to see (and will help implement if I can >> find the time): >> 1) A shortcut to show the docstring of an object. Something like Ipython's >> `?`. i.e. ?`object.foo?` translates to `help(object.foo)` > I wrote this at http://wiki.python.org/moin/DreamPieFeatureRequests . > I hope I will manage to implement this soon. > >> 2) How do I change the color of the blinking cursor at the bottom? I can't >> see the damn thing! > It should be in the color of the default text. If this is not the > case, please file a bug! > >> 3) line numbers instead of the `>>>` prompt > I know IPython does this, but I thought you needed it only if placing > the cursor on top of the command doesn't do anything. Can you tell me > why do you need this in the context of a graphical user interface? > >> 4) a plugin facility where we can define our own `magic` commands. I use >> Ipython's %timeit ALL the time. > Added it to the feature request page. > >> 5) Double-click to re-fold the output section as well. > I don't think that's a good idea, because usually double-click selects > the word, and I don't want to change that behavior for regular text. > You can use ctrl-minus to fold the last output section! > >> Thanks for making this!!!! > Thanks for the feedback! I installed latest .exe from LP on my Win7/32-bit machine, nothing happens when I start DreamPie. Is there a bug report file somewhere I could send you Noam? (Python2.6.4 installed on my machine) > > Noam > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://olofb.wordpress.com From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 23 08:46:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 23 Feb 2010 14:46:30 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> <201002231040.10422.richard.lamboj@bilcom.at> Message-ID: <4b83dc2f$0$10229$426a34cc@news.free.fr> hackingKK a ?crit : (snip) > I don't care how many apps are developed using java as long as they > remain heavy and sloooooooow. > google runs on python Please get your facts right. Python is one of the languages used internally at Google, true, but so is Java. And google-the-search-engine does not "run on python". From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 23 08:47:11 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 23 Feb 2010 14:47:11 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <4b83dc57$0$10229$426a34cc@news.free.fr> Roald de Vries a ?crit : > On Feb 22, 2010, at 10:56 PM, AON LAZIO wrote: >> That will be superb > > I guess static typing will have to be added, so that tools like eclipse > can inspect (and autocomplete) your programs [better]. Yet another troll... From dickinsm at gmail.com Tue Feb 23 08:48:09 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 23 Feb 2010 05:48:09 -0800 (PST) Subject: Bizarre arithmetic results References: Message-ID: <3fb9d59b-21c2-4372-9a32-c542e884faa7@x9g2000vbo.googlegroups.com> On Feb 23, 8:11?am, Steven D'Aprano wrote: > Making spaces significant in that fashion is mind-bogglingly awful. Let's > look at a language that does this: > > [steve at sylar ~]$ cat ws-example.rb > def a(x=4) > ? ? x+2 > end > > b = 1 > print (a + b), (a+b), (a+ b), (a +b), "\n" > > [steve at sylar ~]$ ruby ws-example.rb > 7773 Hmm. That's pretty nasty, all right. Not that Python can claim to be immune to such behaviour: >>> 3 .real 3 >>> 3. real File "", line 1 3. real ^ SyntaxError: invalid syntax Though the fact that one of the cases raises an exception (rather than silently giving some different behaviour) ameliorates things a bit. -- Mark From edreamleo at gmail.com Tue Feb 23 08:53:44 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Tue, 23 Feb 2010 07:53:44 -0600 Subject: ANN: Leo 4.7 final released Message-ID: Leo 4.7 final February 23, 2009 Leo 4.7 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7 final fixes all known bugs in Leo. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - Leo creates a 'Recovered Nodes' node to hold data that otherwise might be lost due to clone conflicts. - @auto-rst now works much more reliably reliably. - Leo no longer supports @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From thom1948 at gmail.com Tue Feb 23 09:21:50 2010 From: thom1948 at gmail.com (Thomas) Date: Tue, 23 Feb 2010 06:21:50 -0800 (PST) Subject: How to transmit a crash report ? References: <4B8336EE.9040802@gmail.com> Message-ID: <0b222aec-db04-45b7-9f86-e2839ffafc40@j1g2000vbl.googlegroups.com> On Feb 22, 9:27?pm, MRAB wrote: > Stef Mientki wrote: > > hello, > > > in my python desktop applications, > > I'ld like to implement a crash reporter. > > By redirecting the sys.excepthook, > > I can detect a crash and collect the necessary data. > > Now I want that my users sends this information to me, > > and I can't find a good way of doing this. > > > The following solutions came into my mind: > > (most of my users are on Windows, and the programs are written in Python > > 2.6) > > > 1. mailto: > > doesn't work if the the user didn't install a default email client, > > or if the user uses a portable email client (that isn't started yet) > > Besides this limits the messages to small amounts of data. > > > 2.other mail options: smtp > > AFAIK such a solution needs smtp authorization, and therefor I've to put > > my username and password in the desktop application. > > Try reading the documentation for Python's smtplib module. > > You don't need to provide any password. > > > > > 3. http-post > > Although post is also limited in size, > > I could store information in cookies (don't know yet how), and cookies > > are sent parallel to the post message. > > On the server site I can use a small php script, that stores the > > post-data, cookies and/or send's a (long) email. > > > are there better options ?- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - Try http://code.activestate.com/recipes/442459/ From malaclypse2 at gmail.com Tue Feb 23 09:34:00 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 23 Feb 2010 09:34:00 -0500 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <16651e81002230634t6d2d0679pe9d1ac028164cc1c@mail.gmail.com> On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson wrote: > So what's the bottom line? This link notion is completely at odds with XP, > and produces what I would call something of a mess to the unwary Python/W7 > user. Is there a simple solution? I know people went off on a tangent talking about symbolic links and hard links, but it is extremely unlikely that you created something like that by accident. Windows just doesn't create those without you doing quite a bit of extra work. It certainly doesn't create them when you drag & drop files around through the normal interface. > How do I get out of this pickle? I just want to duplicate the ?program in > another folder, and not link to an ancestor. You need to dig into the technical details of what's happening on your hard drive. You say you "copied a program from folder A to folder B". Can you describe, exactly, what steps you took? What was the file name of the program? Was it just one file, or a directory, or several files? What was the path to directory A? What is the the path to directory B? When you open a CMD window and do a dir of each directory, what exactly do you see? You've given a pretty non-technical description of the problem you're experiencing. If you want more than wild speculation, you'll need to give more specifics for people to help you with. My wild guess: you held down control and shift while copying your program. That's the keyboard command to create a shortcut instead of moving or copying a file. -- Jerry From mrkafk at gmail.com Tue Feb 23 09:36:02 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 15:36:02 +0100 Subject: Is this secure? Message-ID: Hello, I need to generate passwords and I think that pseudo-random generator is not good enough, frankly. So I wrote this function: import struct def gen_rand_string(): fileobj = open('/dev/urandom','rb') rstr = fileobj.read(4) rnum = struct.unpack('L',rstr)[0] rstr = '%i' % rnum rnuml = [] while len(rstr) >= 2: c = rstr[:2] try: num = int(c) rnuml.append(num) except ValueError: pass rstr = rstr[2:] rnuml = map(lambda x: 97+x/4, rnuml) rnumc = map(chr, rnuml) return ''.join(rnumc) if __name__ == "__main__": print gen_rand_string() (yes I know that this way generated string will not contain 'z' because 99/4 + 97 = 121 which is 'y') The question is: is this secure? That is, can the string generated this way be considered truly random? (I abstract from not-quite-perfect nature of /dev/urandom at the moment; I can always switch to /dev/random which is better) Regards, mk From mrkafk at gmail.com Tue Feb 23 09:49:12 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 15:49:12 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: AON LAZIO wrote: > That will be superb Well I for one wouldn't want Python to go exactly Java way, see this: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=java&l=uk This is the percentage of job offers in UK where the keyword "Java" appears. Same for C#, it looks like C# is eating Java's lunch now: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csharp&l=uk What worries me somewhat (although not much) is that after long period of solid growth the market can't decide about Python: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=python&l=uk I learned painfully that in corporate setting merits of a programming language do not matter much, it's more like "whatever catches the groupthink" at the moment. "Java is good because big ones select Java", "static typing is good because compiler catches programmer's errors" (this one is particularly appealing to managers I found), etc. Although all my "internal use" tools are written in Python, there's no way I could convince managers to use Python as the main application devel language. This, however, is not of itself a problem: as long as language is lively and has at least a few percent of programmers using it -- which is important for existence of libraries, not much more -- there's no problem for people who want to get ahead of competition / waste less time by using advanced programming langauges. Frankly, I have yet to encounter a problem for which either a sizable Python extension or bindings to a popular library wouldn't exist. This in itself is a hallmark of a language being "enough of mainstream to actually matter in practice". This I find quite insightful: http://www.paulgraham.com/avg.html Regards, mk From mrkafk at gmail.com Tue Feb 23 09:51:42 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 15:51:42 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: Stefan Behnel wrote: > Chris Rebert, 23.02.2010 06:45: >> Indeed. Python is at position 7, just behind C#, in the TIOBE Index: >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? Well it looks like it is at least stabilized: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=php&l=uk I find job offers to be rather good index of the extent to which the language is actually used, and this is what this index is based on (percentage of job offers with the keyword "php" in them). Regards, mk From anh.hai.trinh at gmail.com Tue Feb 23 09:59:40 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Tue, 23 Feb 2010 06:59:40 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> <7xy6iky207.fsf@ruckus.brouhaha.com> Message-ID: On Feb 23, 1:03?pm, "Alf P. Steinbach" wrote: > > Uhm, Paganini... > > As I understand it he invented the "destroy your instruments on stage". :-) > > Cheers, > > - Alf (off-topic) You probably meant Franz Liszt, who regularly broke piano strings. Paganini was also a "rock-star" virtuoso but he did not destroy any Guarnerius or Stradivarius violins in his possession (at least not to anyone's knowledge :) As for functional programming, different people take it to mean different things. For some, simply using first-class functions qualifies as functional programming. Others require their functions to be pure so that their call graphs can be automatically reduced and their results can be lazily evaluated. If you takes the former view, most Python programmers already do functional programming :p --aht From mrkafk at gmail.com Tue Feb 23 10:00:18 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 16:00:18 +0100 Subject: Writing an assembler in Python In-Reply-To: References: Message-ID: Giorgos Tzampanakis wrote: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. I want to use Python for that. Are there any libraries that > can help me with the parsing of the assembly code? I'm not sure about your field of application (never done anything like that), but I found pyparsing highly usable. Regards, mk From sccolbert at gmail.com Tue Feb 23 10:06:31 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 23 Feb 2010 10:06:31 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <4B83C265.2090802@googlemail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> <4B83C265.2090802@googlemail.com> Message-ID: <7f014ea61002230706i29a9816eu8eb75369a2025b92@mail.gmail.com> Do you have gtk and PyGTK installed? Sounds like a missing dependency to me. On Tue, Feb 23, 2010 at 6:56 AM, Alan Harris-Reid < aharrisreid at googlemail.com> wrote: > gorauskas wrote: > >> I installed it on a Windows 7 machine with CPython 2.6.4 and I get the >> following error: >> >> Traceback (most recent call last): >> File "dreampie.py", line 3, in >> File "dreampielib\gui\__init__.pyc", line 73, in >> File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk >> ImportError: DLL load failed: The specified module could not be found. >> >> What am I doing wrong? >> >> Thanks, JGG >> > And I installed it on WinXP sp3 and Python 3.1 - when launched a window > flashes before my eyes, then disappears! Has the installation package been > checked for all common Windows versions? > > Regards, > Alan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.hellwig at dcuktec.org Tue Feb 23 10:10:50 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 23 Feb 2010 15:10:50 +0000 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: Actually I am still waiting for Java to be mainstream :-) You could say it is popular, which it is without doubt but in my opinion after C handed over it's pseudo de facto standard (mostly because a lot of OS'es are written in it) nobody else has had enough momenta to reach for that crown. Actually I quite like the soup of languages these days, what amuses me though, that Python seems to emerge as the de facto glue language to bind them all :-) -- mph From anh.hai.trinh at gmail.com Tue Feb 23 10:14:16 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Tue, 23 Feb 2010 07:14:16 -0800 (PST) Subject: Writing an assembler in Python References: Message-ID: On Feb 23, 10:08?am, Lawrence D'Oliveiro wrote: > > Let me suggest an alternative approach: use Python itself as the assembler. > Call routines in your library to output the code. That way you have a > language more powerful than any assembler. > > See for an example. SyntaxError: Non-matching "#end if" in crosscode8.py:345 From invalid at invalid.invalid Tue Feb 23 10:29:44 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 23 Feb 2010 15:29:44 +0000 (UTC) Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: On 2010-02-23, D'Arcy J.M. Cain wrote: > On Tue, 23 Feb 2010 02:54:25 -0800 (PST) > Joan Miller wrote: >> *Sorry by this message off topic, but this is too important* > > Is it just me or has the spew from gmail on this list radically > increased in the last week? Anyone else considering blocking all gmail > posts to this list? I did that a long time ago for all of the Usenet groups I read and all but one of the mailing lists I read. -- Grant Edwards grante Yow! I'm wearing PAMPERS!! at visi.com From invalid at invalid.invalid Tue Feb 23 10:31:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 23 Feb 2010 15:31:12 +0000 (UTC) Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: On 2010-02-23, Grant Edwards wrote: > On 2010-02-23, D'Arcy J.M. Cain wrote: >> On Tue, 23 Feb 2010 02:54:25 -0800 (PST) >> Joan Miller wrote: >>> *Sorry by this message off topic, but this is too important* >> >> Is it just me or has the spew from gmail on this list radically >> increased in the last week? Anyone else considering blocking all gmail >> posts to this list? > > I did that a long time ago for all of the Usenet groups I read > and all but one of the mailing lists I read. Wait, I misread the posting. I block everything from google.groups, not everything from gmail. -- Grant Edwards grante Yow! I have accepted at Provolone into my life! visi.com From mrkafk at gmail.com Tue Feb 23 10:38:28 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 16:38:28 +0100 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> Message-ID: sjdevnull at yahoo.com wrote: > On Feb 20, 9:58 pm, John Nagle wrote: >> sjdevn... at yahoo.com wrote: >>> On Feb 18, 2:58 pm, John Nagle wrote: >>>> Multiple processes are not the answer. That means loading multiple >>>> copies of the same code into different areas of memory. The cache >>>> miss rate goes up accordingly. >>> A decent OS will use copy-on-write with forked processes, which should >>> carry through to the cache for the code. >> That doesn't help much if you're using the subprocess module. The >> C code of the interpreter is shared, but all the code generated from >> Python is not. > Of course. Multithreading also fails miserably if the threads all try > to call exec() or the equivalent. > It works fine if you use os.fork(). What about just using subprocess module to run system commands in worker threads? Is this likely to have problems? Regards, mk From fetchinson at googlemail.com Tue Feb 23 10:39:11 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 23 Feb 2010 16:39:11 +0100 Subject: Avoid converting functions to methods in a class In-Reply-To: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. Isn't staticmethod the trick you need? HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From aharrisreid at googlemail.com Tue Feb 23 10:39:44 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Tue, 23 Feb 2010 15:39:44 +0000 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002230706i29a9816eu8eb75369a2025b92@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> <4B83C265.2090802@googlemail.com> <7f014ea61002230706i29a9816eu8eb75369a2025b92@mail.gmail.com> Message-ID: <4B83F6C0.9010807@googlemail.com> Chris Colbert wrote: > Do you have gtk and PyGTK installed? Sounds like a missing dependency > to me. > > On Tue, Feb 23, 2010 at 6:56 AM, Alan Harris-Reid > > wrote: > > gorauskas wrote: > > I installed it on a Windows 7 machine with CPython 2.6.4 and I > get the > following error: > > Traceback (most recent call last): > File "dreampie.py", line 3, in > File "dreampielib\gui\__init__.pyc", line 73, in > File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk > ImportError: DLL load failed: The specified module could not > be found. > > What am I doing wrong? > > Thanks, JGG > > And I installed it on WinXP sp3 and Python 3.1 - when launched a > window flashes before my eyes, then disappears! Has the > installation package been checked for all common Windows versions? > > Regards, > Alan > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi Chris, thanks for the reply, That explains it. No, I don't have gtk installed - I wasn't aware of that dependency. Regards, Alan -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Tue Feb 23 10:49:07 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 07:49:07 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA Message-ID: Anyone here going to the meeting,Subject? As far as I can tell, it meets from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to be an informal group dinner at 6 pm at some place yet unknown. Comments? From mrkafk at gmail.com Tue Feb 23 10:59:22 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 16:59:22 +0100 Subject: AKKA vs Python Message-ID: Hello everyone, Is there smth like AKKA in Python? http://akkasource.org/ Regards, mk From darcy at druid.net Tue Feb 23 11:09:54 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 11:09:54 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <20100223110954.5da3d679.darcy@druid.net> On Tue, 23 Feb 2010 15:31:12 +0000 (UTC) Grant Edwards wrote: > >> Is it just me or has the spew from gmail on this list radically > >> increased in the last week? Anyone else considering blocking all gmail > >> posts to this list? > > > > I did that a long time ago for all of the Usenet groups I read > > and all but one of the mailing lists I read. > > Wait, I misread the posting. I block everything from > google.groups, not everything from gmail. Yes, I did that a long time ago as well. But now there seems to be more and more actual spam coming from gmail.com itself. It may just be a minor blip on the spam graph but I'm keeping my eye on it. Most mailing lists that I am on are pretty good at filtering spam before it gets to the list. The only spam I ever see on my NetBSD lists are the ones that I moderate and I block them before anyone else sees them. A little more pain for me in return for a lot less pain for everyone else. I guess that's not possible on a list that is gatewayed to UseNet like this one is. Hmm. I wonder if all the spam is coming from the NG side. I'll have to look at that. One of the reasons that I stopped reading UseNet over ten years ago was because of the diminishinig S/N ratio. I have always felt that it was a mistake to gateway this group. -- 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 clp2 at rebertia.com Tue Feb 23 11:18:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Feb 2010 08:18:07 -0800 Subject: AKKA vs Python In-Reply-To: References: Message-ID: <50697b2c1002230818t708262f1v3b63eebf12684d67@mail.gmail.com> On Tue, Feb 23, 2010 at 7:59 AM, mk wrote: > Hello everyone, > > Is there smth like AKKA in Python? > > http://akkasource.org/ Minus the "distributed" part, yes; there are a few implementations of actors for Python: http://www.doc.ic.ac.uk/~jwa/stage/ http://osl.cs.uiuc.edu/parley/ http://candygram.sourceforge.net/candygram.html It's a variant on the vanilla actor model, but I've heard good buzz about: http://www.kamaelia.org/ (Unless it wasn't already clear, I haven't used any of these myself.) Cheers, Chris -- http://blog.rebertia.com From rpdooling at gmail.com Tue Feb 23 11:26:18 2010 From: rpdooling at gmail.com (Rick Dooling) Date: Tue, 23 Feb 2010 08:26:18 -0800 (PST) Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: Message-ID: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> No telling what Windows will do. :) I am a mere hobbyist programmer, but I think real programmers will tell you that it is a bad habit to use relative paths. Use absolute paths instead and remove all doubt. http://docs.python.org/library/os.path.html RD From robert.kern at gmail.com Tue Feb 23 11:27:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 10:27:49 -0600 Subject: Writing an assembler in Python In-Reply-To: <166845.21850.qm@web58906.mail.re1.yahoo.com> References: <166845.21850.qm@web58906.mail.re1.yahoo.com> Message-ID: On 2010-02-22 21:47 PM, Ed Keith wrote: >> Subject: Re: Writing an assembler in Python >> Giorgos >> Tzampanakis wrote: >> >>> I'm implementing a CPU that will run on an FPGA. I >> want to have a >>> (dead) simple assembler that will generate the machine >> code for >>> me. >> >> Let me suggest an alternative approach: use Python itself >> as the assembler. >> Call routines in your library to output the code. That way >> you have a >> language more powerful than any assembler. >> >> See for >> an example. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Not a bad idea, has anyone tried this for x86 machine code? http://www.corepy.org/ -- 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 ssteinerx at gmail.com Tue Feb 23 11:30:39 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 23 Feb 2010 11:30:39 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <0C0B45B8-BF31-4759-B2AE-C443D065FC17@gmail.com> On Feb 23, 2010, at 10:10 AM, Martin P. Hellwig wrote: > Actually I am still waiting for Java to be mainstream :-) > You could say it is popular, which it is without doubt but in my opinion after C handed over it's pseudo de facto standard (mostly because a lot of OS'es are written in it) nobody else has had enough momenta to reach for that crown. > > Actually I quite like the soup of languages these days, what amuses me though, that Python seems to emerge as the de facto glue language to bind them all :-) I'm sure there's a Tolkien 1-liner in there somewhere ;-). S From victorsubervi at gmail.com Tue Feb 23 11:47:18 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 23 Feb 2010 12:47:18 -0400 Subject: SMTPServerDisconnected Message-ID: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> Hi; I think the last main thing I have to do on my server is get a running email server up. Now that I've nuked sendmail and given up on postfix, I'm back to trying to get qmail up and running again. Of course, there are no active discussion lists for *any* email server, so I have to turn here for help. While running a script that worked perfectly well on another server to send an email, I get the following error: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py 52 53 ''' 54 my_mail() 55 print ''' 56 my_mail = /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() 33 to_address = ourEmail1, 34 subject = subject, 35 message = message 36 ).send() 37 Email( message = 'Name: beno -\nMessage: test' /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in send(self=) 344 smtp = smtplib.SMTP() 345 if self.smtp_server: 346 smtp.connect(self.smtp_server) 347 else: 348 smtp.connect() smtp = , smtp.connect = >, self = , self.smtp_server = 'localhost' /usr/lib64/python2.4/smtplib.py in connect(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code undefined, msg = 'getaddrinfo returns an empty list', self = , self.getreply = > /usr/lib64/python2.4/smtplib.py in getreply(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) global SMTPServerDisconnected = SMTPServerDisconnected: Connection unexpectedly closed args = ('Connection unexpectedly closed',) I cannot find the qmail logs. I assumed they'd be in either /var/qmail/supervise/qmail-send or /var/qmail/supervise/qmail-smtpd but I find no logs there. [SSH] Protocol Version 2 (OpenSSH_4.3) [SSH] Cipher: aes128-cbc Logged in (password) Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 [beno at 13gems ~]$ su Password: [root at 13gems beno]# man netstat [root at 13gems beno]# netstat Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State getnameinfo failed tcp 0 268 nrelectric.com:ssh [UNKNOWN]:61912 ESTABLISHED Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 7 [ ] DGRAM 10842 /dev/log unix 2 [ ] DGRAM 10370 @/org/kernel/udev/udevd unix 2 [ ] DGRAM 6077731 unix 3 [ ] STREAM CONNECTED 6077679 unix 3 [ ] STREAM CONNECTED 6077678 unix 2 [ ] DGRAM 6077675 unix 2 [ ] DGRAM 11556 unix 2 [ ] DGRAM 11511 unix 2 [ ] DGRAM 10990 [root at 13gems beno]# How do I trouble-shoot this? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.91ahesh at gmail.com Tue Feb 23 13:04:13 2010 From: m.91ahesh at gmail.com (ranga...............) Date: Tue, 23 Feb 2010 10:04:13 -0800 (PST) Subject: Free check of $253 with your name. Message-ID: <0e5a7c60-e3da-4f74-8549-cc5885d1f309@g8g2000pri.googlegroups.com> Just open below site and select any one of the four red color links present below sponsors and enter your payename and address where to get your check. The secret link is http://highpayingkeywordsofadsense.blogspot.com/2010/01/google-yahoo-msn-adsense-high-paying_29.html From wolftracks at invalid.com Tue Feb 23 13:12:22 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 10:12:22 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 In-Reply-To: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: On 2/23/2010 8:26 AM, Rick Dooling wrote: > No telling what Windows will do. :) > > I am a mere hobbyist programmer, but I think real programmers will > tell you that it is a bad habit to use relative paths. Use absolute > paths instead and remove all doubt. > > http://docs.python.org/library/os.path.html > > RD You may be right. The actual 300 line program just reads the folder without specifying any path. I'm not that familiar with os path, but have seen it used. From peloko45 at gmail.com Tue Feb 23 13:14:38 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 23 Feb 2010 10:14:38 -0800 (PST) Subject: Fascism is coming to Internet References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> On 23 feb, 10:54, Joan Miller wrote: > *Sorry by this message off topic, but this is too important* > > Fascism is coming fastly to Internet because is the only communication > way that governements (managed by the bank and multinationals) cann't > control > > http://www.boingboing.net/2010/02/21/acta-internet-enforc.html This is something that affects to all programmers: "This calls on all parties to ensure that "third party liability" (the idea that ISPs, web-hosts, application developers, mobile carriers, universities, apartment buildings, and other "third parties" to infringement are sometimes liable for their users' copyright infringements) is on the books in their countries. It doesn't spell out what that liability should be, beyond "knowingly and materially aiding" an infringement" http://craphound.com/acta_digital_chapter-1.pdf From nevillednz at gmail.com Tue Feb 23 13:24:08 2010 From: nevillednz at gmail.com (NevilleDNZ) Date: Tue, 23 Feb 2010 10:24:08 -0800 (PST) Subject: Modifying Class Object References: Message-ID: <9e4f092e-647e-4330-b2ad-e3982b4c8f2c@t9g2000prh.googlegroups.com> Hi Groetjes Albert, I spotted your comment - re: pointers http://groups.google.com/group/comp.lang.python/msg/5c1e25919b6a74bf On Feb 22, 11:44 pm, Albert van der Horst wrote: (I once studied algol 68, and never got confused about these > subjects anymore, recommended.) Having used Algol68, then switching to C to discover "*" for manual dereferencing I immediately wanted to be back using A68 again, but alas... Then when I switched to C++ I immediately understood the "Zen" of C++'s "&"... but still wanted to switch back to A68. Was there ever a version with "Objects"... I saw a version with "Areas" but have no idea what an "Area" is. @Albert: Given the domain name "xs4all" in your email address I am sure YOU have spotted: http://www.xs4all.nl/~jmvdveer/algol.html by Marcel Also: I invite you to join one of the below groups (my .sig below) and deposit some of your Algol68 impressions.... There is also a chrestomathy site http://rosettacode.org/wiki/ALGOL_68 where you can pick out an code sample unimplemented in Algol68 and torture test your Algol68 memories. (Be warned: Most of the easy samples are done) Keep in touch NevilleDNZ -- For Algol68-user mailinglist with archives & subscription: * https://lists.sourceforge.net/lists/listinfo/algol68-user To download Linux's Algol68 Compiler, Interpreter & Runtime: * http://sourceforge.net/projects/algol68 Join the linkedin.com's Algol68 group, follow: * http://www.linkedin.com/groups?gid=2333923 From spamfresser at ch3ka.de Tue Feb 23 13:25:24 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 23 Feb 2010 19:25:24 +0100 Subject: Signature-based Function Overloading in Python Message-ID: Just a quick question about what would be the most pythonic approach in this. In Java, Method Overloading is my best friend, but this won't work in Python: >>> def a(): pass >>> def a(x): pass >>> a() Traceback (most recent call last): File "", line 1, in a() TypeError: a() takes exactly 1 argument (0 given) So - What would be the most pythonic way to emulate this? Is there any better Idom than: >>> def a(x=None): if x is None: pass else: pass ? Thanks, Michael From nagle at animats.com Tue Feb 23 13:35:38 2010 From: nagle at animats.com (John Nagle) Date: Tue, 23 Feb 2010 10:35:38 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> Message-ID: <4b841bf1$0$1632$742ec2ed@news.sonic.net> mk wrote: > sjdevnull at yahoo.com wrote: >> On Feb 20, 9:58 pm, John Nagle wrote: >>> sjdevn... at yahoo.com wrote: >>>> On Feb 18, 2:58 pm, John Nagle wrote: >>>>> Multiple processes are not the answer. That means loading >>>>> multiple >>>>> copies of the same code into different areas of memory. The cache >>>>> miss rate goes up accordingly. >>>> A decent OS will use copy-on-write with forked processes, which should >>>> carry through to the cache for the code. >>> That doesn't help much if you're using the subprocess module. The >>> C code of the interpreter is shared, but all the code generated from >>> Python is not. > >> Of course. Multithreading also fails miserably if the threads all try >> to call exec() or the equivalent. > >> It works fine if you use os.fork(). > > What about just using subprocess module to run system commands in worker > threads? Is this likely to have problems? > > Regards, > mk The discussion above was about using "fork" to avoid duplicating the entire Python environment for each subprocess. If you use the subprocess module, you load a new program, so you don't get much memory sharing. This increases the number of cache misses, which is a major bottleneck in many-CPU systems with shared caches. The issue being discussed was scaling Python for CPUs with many cores. With Intel shipping 4 cores/8 hyperthread CPUs, the 6/12 part working, and the 8/16 part coming along, this is more than a theoretical issue. John Nagle From fetchinson at googlemail.com Tue Feb 23 13:49:53 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 23 Feb 2010 19:49:53 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: > In Java, Method Overloading is my best friend, but this won't work in > Python: > > >>> def a(): > pass > >>> def a(x): > pass > >>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > > >>> def a(x=None): > if x is None: > pass > else: > pass This is generally considered to be the pythonic idiom for what you describe. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From cgrebeld at gmail.com Tue Feb 23 13:49:59 2010 From: cgrebeld at gmail.com (chris grebeldinger) Date: Tue, 23 Feb 2010 10:49:59 -0800 (PST) Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <06b6fb1b-f3ee-498c-ad8b-5557eb711a3d@x9g2000vbo.googlegroups.com> Have you tried opening file explorer in administrative mode before performing the copy? I think if there isn't sufficient permissions, it does something weird like that. From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 13:56:44 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 07:56:44 +1300 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> <06b6fb1b-f3ee-498c-ad8b-5557eb711a3d@x9g2000vbo.googlegroups.com> Message-ID: chris grebeldinger wrote: > Have you tried opening file explorer in administrative mode before > performing the copy? I think if there isn't sufficient permissions, > it does something weird like that. No From jjposner at optimum.net Tue Feb 23 13:58:59 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 23 Feb 2010 13:58:59 -0500 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4B842573.2010706@optimum.net> On 2/23/2010 1:25 PM, Michael Rudolf wrote: > Just a quick question about what would be the most pythonic approach in > this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > > >>> def a(): > pass > >>> def a(x): > pass > >>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > > >>> def a(x=None): > if x is None: > pass > else: > pass > Consider this: #------------------ def myfunc(*arglist): if not arglist: print "no arguments" return for i, arg in enumerate(arglist): print "Argument %d is a %s, with value:" % (i, type(arg)), print arg myfunc() print "---" myfunc(1) print "---" myfunc(2, "three", [4, 5,6]) #------------------ program output: no arguments --- Argument 0 is a , with value: 1 --- Argument 0 is a , with value: 2 Argument 1 is a , with value: three Argument 2 is a , with value: [4, 5, 6] HTH, John From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 14:08:16 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 08:08:16 +1300 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: Rick Dooling wrote: > No telling what Windows will do. :) It isn't useful to respond to a serious question with OS bigotry. From timothy.tsvetkov at gmail.com Tue Feb 23 14:09:10 2010 From: timothy.tsvetkov at gmail.com (Timothy N. Tsvetkov) Date: Tue, 23 Feb 2010 11:09:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: On Feb 16, 10:41?pm, Andrej Mitrovic wrote: > On Feb 16, 7:38?pm, Casey Hawthorne > wrote: > > > Interesting talk on Python vs. Ruby and how he would like Python to > > have just a bit more syntactic flexibility. > > >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > > -- > > Regards, > > Casey > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > linked to): "Python has no comparable equivalent to Ruby?s do end > block. Python lambdas are limited to one line and can?t contain > statements (for, if, def, etc.). Which leaves me wondering, what?s the > point?" > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > expressions, not statements, but you can pass them around, keep them > in a dictionary if you want to. And if you need more than one line of > statements, for crying out loud use a def? And who needs those "do- > end" blocks anyway, trying to turn Python into Pascal? I think there are some nice use-cases for anonymous functions / blocks. First, mentioned above, is pretty DSL. And the second is using blocks in map/reduce functions. Yes, you can pass there a function but I believe that in most situations it is more readable to pass a multiline anonymous function / block than defined somewhere function written only for a single map/reduce operation. And often when you use reduce it is a bit more complicated then just one line function. From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 14:14:04 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 08:14:04 +1300 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: W. eWatson wrote: > On 2/23/2010 8:26 AM, Rick Dooling wrote: >> No telling what Windows will do. :) >> >> I am a mere hobbyist programmer, but I think real programmers will >> tell you that it is a bad habit to use relative paths. Use absolute >> paths instead and remove all doubt. >> >> http://docs.python.org/library/os.path.html >> >> RD > You may be right. The actual 300 line program just reads the folder > without specifying any path. I'm not that familiar with os path, but > have seen it used. How do you invoke the program? Do you use a Command Prompt window? From no.email at nospam.invalid Tue Feb 23 14:19:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 11:19:59 -0800 Subject: Is this secure? References: Message-ID: <7xtyt72200.fsf@ruckus.brouhaha.com> mk writes: > I need to generate passwords and I think that pseudo-random generator > is not good enough, frankly. So I wrote this function:... > The question is: is this secure? That is, can the string generated > this way be considered truly random? (I abstract from > not-quite-perfect nature of /dev/urandom at the moment; I can always > switch to /dev/random which is better) urandom is fine and the entropy loss from the numeric conversions and eliminating 'z' in that code before you get letters out is not too bad. The code is pretty ugly. The main problem is you end up with a password that's usually 5 letters but sometimes just 4 or fewer. Passwords that short are vulnerable to dictionary attacks. Longer passwords made from random letters are difficult to remember. I find it's most practical to use a few random words (chosen from a word list like /usr/dict/words) rather than random letters. Words are easier to remember and type. You might look at the site www.diceware.com for an approach to this, which you can implement with a program. The docs there are pretty thoughtful and may help you understand the relevant issues. From CORY.L.NARDIN at saic.com Tue Feb 23 14:22:16 2010 From: CORY.L.NARDIN at saic.com (Nardin, Cory L.) Date: Tue, 23 Feb 2010 11:22:16 -0800 Subject: Python won't run In-Reply-To: <46D34AB9-9DC7-47E9-8288-2B5DFDB55BB8@activestate.com> References: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> <46D34AB9-9DC7-47E9-8288-2B5DFDB55BB8@activestate.com> Message-ID: <29325D156EE06640B05BB9FD0D4AC2B502B30AFE@0461-its-exmb04.us.saic.com> Thanks so much for that suggestion. I used the tool and found two missing libraries: MSVCR90.DLL and DWMAPI.DLL. I located and copied the first library to my python directory (and resolved that dependency), but I am still missing the other. I have done a Google search and found that DWMAPI is a Vista library. I am have XP, so I am not sure why it is a required dependency? I made sure that I have all the MS updates (presumably MS would include a new library in an update if it became a required library) and that did not solve the problem. Is this a bug or should I have that library on my computer and the fact that it isn't there is the sign of some other problem? Thanks Cory ________________________________ From: Sridhar Ratnakumar [mailto:sridharr at activestate.com] Sent: Monday, February 22, 2010 11:54 AM To: Nardin, Cory L. Cc: python-list at python.org Subject: Re: Python won't run Have you tried using http://dependencywalker.com/ ? -srid On 2010-02-18, at 1:00 PM, Nardin, Cory L. wrote: Quickly, I have a Mac Intel with Windows XP installed. Tried installing Python 2.6.4 from the binary and also ActivePython 2.6.4.10. Both installations acted the same. There seemed to be no problems during installation (used default options), but when I try to run Python I get an error message: "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem." Of course I searched on that error and it seems to be related to a MS library. In a few different places it was recommended to install the MS Visual Studio redistributable package, which I did with no change in outcome. I really have no idea what to do. Any help is appreciated. Thanks, Cory -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From olof.bjarnason at gmail.com Tue Feb 23 14:30:03 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Tue, 23 Feb 2010 20:30:03 +0100 Subject: Fascism is coming to Internet In-Reply-To: <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> Message-ID: 2010/2/23 Joan Miller : > On 23 feb, 10:54, Joan Miller wrote: >> *Sorry by this message off topic, but this is too important* >> >> Fascism is coming fastly to Internet because is the only communication >> way that governements (managed by the bank and multinationals) cann't >> control >> >> http://www.boingboing.net/2010/02/21/acta-internet-enforc.html > > This is something that affects to all programmers: > > "This calls on all parties to ensure that "third party liability" (the > idea that ISPs, web-hosts, application developers, mobile carriers, > universities, apartment buildings, and other "third parties" to > infringement are sometimes liable for their users' copyright > infringements) is on the books in their countries. It doesn't spell > out what that liability should be, beyond "knowingly and materially > aiding" an infringement" > > http://craphound.com/acta_digital_chapter-1.pdf > -- > http://mail.python.org/mailman/listinfo/python-list > Even if this is "Off Topic" (which I think it really isn't in any open source / free software-oriented mailing list), I want to agree with Joan. ACTA is a *real* problem that we must fend politically. Here is a blog post I wrote about the problem with making ISPs liable for what their users communicate: http://translate.google.com/translate?js=y&prev=_t&hl=en&ie=UTF-8&layout=1&eotf=1&u=http%3A%2F%2Folofb.wordpress.com%2F&sl=sv&tl=en (sorry for the bad quality google translation -- this is an important topic!) Note the name of the important principle: "Mere conduit". -- http://olofb.wordpress.com From vicente.soler at gmail.com Tue Feb 23 14:36:23 2010 From: vicente.soler at gmail.com (vsoler) Date: Tue, 23 Feb 2010 11:36:23 -0800 (PST) Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> <4b82dc5a$0$22916$e4fe514c@news.xs4all.nl> Message-ID: <2e510063-7fc0-4cfc-8fd2-53214f1b6c4d@h12g2000vbd.googlegroups.com> On Feb 22, 8:32?pm, Hans Mulder wrote: > G?nther Dietrich wrote: > > vsoler wrote: > > >> I'm trying to print .7 as 70% > >> I've tried: > > >> print format(.7,'%%') > >> .7.format('%%') > > >> but neither works. I don't know what the syntax is... > > > Did you try this: > > >>>> print('%d%%' % (0.7 * 100)) > > 70% > > That method will always round down; TomF's method will round to > the nearest whole number: > > ?>>> print "%d%%" % (0.698 * 100) > 69% > ?>>> print "{0:.0%}".format(.698) > 70% > > Only the OP knows which one is more appropriate for his use case. > > Hope this helps, > > -- HansM Great!!! Thank you From monkey at joemoney.net Tue Feb 23 14:42:05 2010 From: monkey at joemoney.net (monkeys paw) Date: Tue, 23 Feb 2010 14:42:05 -0500 Subject: python dowload Message-ID: I used the following code to download a PDF file, but the file was invalid after running the code, is there problem with the write operation? import urllib2 url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' a = open('adobe.pdf', 'w') for line in urllib2.urlopen(url): a.write(line) From mrkafk at gmail.com Tue Feb 23 14:59:23 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 11:59:23 -0800 (PST) Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On Feb 23, 7:19?pm, Paul Rubin wrote: > The code is pretty ugly. ?The main problem is you end up with a password > that's usually 5 letters but sometimes just 4 or fewer. ? Well I didn't write the whole thing here, in actual use I'd write a loop repeating the function until I have enough characters and then I'd select a substring of specified length. Anything else in the code that is ugly and I should correct? > You might look at the sitewww.diceware.comfor an approach to this, > which you can implement with a program. ?The docs there are pretty > thoughtful and may help you understand the relevant issues. Thanks. But I would also be grateful for indicating what is wrong/ugly in my code. Regards, mk From robert.kern at gmail.com Tue Feb 23 15:04:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 14:04:02 -0600 Subject: Is this secure? In-Reply-To: <7xtyt72200.fsf@ruckus.brouhaha.com> References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-23 13:19 PM, Paul Rubin wrote: > I find it's most practical to use a few random words (chosen from a word > list like /usr/dict/words) rather than random letters. Words are easier > to remember and type. > > You might look at the site www.diceware.com for an approach to this, > which you can implement with a program. The docs there are pretty > thoughtful and may help you understand the relevant issues. I like RFC 1751 for this: http://gitweb.pycrypto.org/?p=crypto/pycrypto-2.x.git;a=blob;f=lib/Crypto/Util/RFC1751.py;h=1c98a212c22066adabfee521b495eeb4f9d7232b;hb=HEAD Shortened URL: http://tr.im/Pv9B -- 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 gd_usenet at spamfence.net Tue Feb 23 15:09:38 2010 From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Tue, 23 Feb 2010 21:09:38 +0100 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> <4b82dc5a$0$22916$e4fe514c@news.xs4all.nl> Message-ID: <29pd57-qhp.ln1@spamfence.net> Hans Mulder wrote: >> Did you try this: >> >>>>> print('%d%%' % (0.7 * 100)) >> 70% > >That method will always round down; TomF's method will round to >the nearest whole number: > > >>> print "%d%%" % (0.698 * 100) >69% > >>> print "{0:.0%}".format(.698) >70% It was intended as a hint to this way of formatting. He could also try: >>> print('%.0f%%' % (0.698 * 100)) 70% Best regards, G?nther From john at castleamber.com Tue Feb 23 15:09:50 2010 From: john at castleamber.com (John Bokma) Date: Tue, 23 Feb 2010 14:09:50 -0600 Subject: python dowload References: Message-ID: <87635naf3l.fsf@castleamber.com> monkeys paw writes: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') > for line in urllib2.urlopen(url): > a.write(line) pdf is /not/ text. You're processing it like it's a text file (and storing it like it's text, which on Windows is most likely a no no). import urllib2 url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' response = urllib2.urlopen(url) fh = open('adobe.pdf', 'wb') fh.write(response.read()) fh.close() response.close() -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From darcy at druid.net Tue Feb 23 15:16:25 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 15:16:25 -0500 Subject: Fascism is coming to Internet In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> Message-ID: <20100223151625.50fde3cb.darcy@druid.net> On Tue, 23 Feb 2010 20:30:03 +0100 Olof Bjarnason wrote: > Even if this is "Off Topic" (which I think it really isn't in any open > source / free software-oriented mailing list), I want to agree with > Joan. It isn't about the Python programming language so it is off topic. So what if some members have an interest? We have interest in a lot of things. We all have interest in the hardware that our programs run on but questions about hardware are also off topic. Perhaps you don't quite grasp the point of topical discussion groups. They are a way of letting individuals decide for themselves what kind of discussions they want to be involved in. By spamming the group this way you take away that freedom of choice. It's ironic when it is done in the name of freedom. -- 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 python.list at tim.thechases.com Tue Feb 23 15:17:11 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Feb 2010 14:17:11 -0600 Subject: python dowload In-Reply-To: References: Message-ID: <4B8437C7.2030408@tim.thechases.com> monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') Sure you don't need this to be 'wb' instead of 'w'? > for line in urllib2.urlopen(url): > a.write(line) I also don't know if this "for line...a.write(line)" loop is doing newline translation. If it's a binary file, you should use .read() (perhaps with a modest-sized block-size, writing it in a loop if the file can end up being large.) -tkc From malaclypse2 at gmail.com Tue Feb 23 15:17:19 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 23 Feb 2010 15:17:19 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <16651e81002231217s297dc93avdaadbc51716ca098@mail.gmail.com> On Tue, Feb 23, 2010 at 2:42 PM, monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') > for line in urllib2.urlopen(url): > ? ?a.write(line) Two guesses: First, you need to call a.close() when you're done writing to the file. This will happen automatically when you have no more references to the file, but I'm guessing that you're running this code in IDLE or some other IDE, and a is still a valid reference to the file after you run that snippet. Second, you're treating the pdf file as text (you're assuming it has lines, you're not writing the file in binary mode, etc.). I don't know if that's correct for a pdf file. I would do something like this instead: Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 IDLE 2.6.4 >>> import urllib2 >>> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >>> a = open('C:/test.pdf', 'wb') >>> data = urllib2.urlopen(url).read() >>> a.write(data) >>> a.close() That seems to works for me, in that it downloads a 16 page pdf document, and that document opens without error or any other obvious problems. -- Jerry From drobinow at gmail.com Tue Feb 23 15:20:54 2010 From: drobinow at gmail.com (David Robinow) Date: Tue, 23 Feb 2010 15:20:54 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <4eb0089f1002231220uf488e59pc0b0d02c987ebc33@mail.gmail.com> On Tue, Feb 23, 2010 at 2:42 PM, monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') > for line in urllib2.urlopen(url): > ? ?a.write(line) If you're running Windows, try a = open('adobe.pdf', 'wb') [Works for me] From ssteinerx at gmail.com Tue Feb 23 15:22:39 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 23 Feb 2010 15:22:39 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <72DB116B-19DC-4BDB-A009-C80A3CE28061@gmail.com> On Feb 23, 2010, at 2:42 PM, monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') Try 'wb', just in case. S > for line in urllib2.urlopen(url): > a.write(line) > -- > http://mail.python.org/mailman/listinfo/python-list From anand.shashwat at gmail.com Tue Feb 23 15:28:53 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Feb 2010 01:58:53 +0530 Subject: python dowload In-Reply-To: <4B8437C7.2030408@tim.thechases.com> References: <4B8437C7.2030408@tim.thechases.com> Message-ID: PyPdf/pdfminer library will be of help On Wed, Feb 24, 2010 at 1:47 AM, Tim Chase wrote: > monkeys paw wrote: > >> I used the following code to download a PDF file, but the >> file was invalid after running the code, is there problem >> with the write operation? >> >> import urllib2 >> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >> a = open('adobe.pdf', 'w') >> > > Sure you don't need this to be 'wb' instead of 'w'? > > > for line in urllib2.urlopen(url): >> a.write(line) >> > > I also don't know if this "for line...a.write(line)" loop is doing newline > translation. If it's a binary file, you should use .read() (perhaps with a > modest-sized block-size, writing it in a loop if the file can end up being > large.) > > -tkc > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Tue Feb 23 15:35:04 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 23 Feb 2010 20:35:04 +0000 Subject: Signature-based Function Overloading in Python References: Message-ID: Michael Rudolf writes: > Just a quick question about what would be the most pythonic approach > in this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > >>>> def a(): > pass >>>> def a(x): > pass >>>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > >>>> def a(x=None): > if x is None: > pass > else: > pass > There are a number of frameworks for function overloading out there. FWIW, there is actually one in the Python sandbox (for Python 3): http://svn.python.org/view/sandbox/trunk/Overload3K/ -- Arnaud From enleverLesX_XXmcX at XmclavXeauX.com.invalid Tue Feb 23 15:35:53 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Tue, 23 Feb 2010 21:35:53 +0100 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <4b843c2b$0$17860$ba4acef3@reader.news.orange.fr> Hi! > Symbolic links are available in NTFS starting with Windows Vista. No. Hardlink come with NTFS, and already exists in W2K (and NT with specifics utilities). @-salutations -- Michel Claveau From robert.kern at gmail.com Tue Feb 23 15:49:25 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 14:49:25 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-23 13:59 PM, mk wrote: > On Feb 23, 7:19 pm, Paul Rubin wrote: > >> The code is pretty ugly. The main problem is you end up with a password >> that's usually 5 letters but sometimes just 4 or fewer. > > Well I didn't write the whole thing here, in actual use I'd write a > loop repeating the function until I have enough characters and then > I'd select a substring of specified length. > > Anything else in the code that is ugly and I should correct? I would recommend using random.SystemRandom.choice() on a sequence of acceptable characters. E.g. (untested) import random import string characters = string.letters + string.digits + '~!@#$%^&*()-+=,;./\?><|' # ... or whatever. def gen_rand_string(length): prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice(characters)) return ''.join(chars) -- 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 vicente.soler at gmail.com Tue Feb 23 15:53:14 2010 From: vicente.soler at gmail.com (vsoler) Date: Tue, 23 Feb 2010 12:53:14 -0800 (PST) Subject: Creating variables from dicts Message-ID: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Hi, I have two dicts n={'a', 'm', 'p'} v={1,3,7} and I'd like to have a=1 m=3 p=7 that is, creating some variables. How can I do this? From jgardner at jonathangardner.net Tue Feb 23 15:53:51 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 23 Feb 2010 12:53:51 -0800 Subject: SMTPServerDisconnected In-Reply-To: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> References: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> Message-ID: <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> On Tue, Feb 23, 2010 at 8:47 AM, Victor Subervi wrote: > Hi; > I think the last main thing I have to do on my server is get a running email > server up. Now that I've nuked sendmail and given up on postfix, I'm back to > trying to get qmail up and running again. Of course, there are no active > discussion lists for *any* email server, so I have to turn here for help. > While running a script that worked perfectly well on another server to send > an email, I get the following error: > A problem occurred in a Python script. Here is the sequence of function > calls leading up to the error, in the order they occurred. > A problem occurred in a Python script. Here is the sequence of function > calls leading up to the error, in the order they occurred. > ?/var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py > ?? 52 > ?? 53 ''' > ?? 54 my_mail() > ?? 55 print ''' > ?? 56 > my_mail = > ?/var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() > ?? 33 ? ? ? to_address = ourEmail1, > ?? 34 ? ? ? subject = subject, > ?? 35 ? ? ? message = message > ?? 36 ? ).send() > ?? 37 ? Email( > message = 'Name: beno -\nMessage: test' > ?/var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in > send(self=) > ??344 ? ? ? ? smtp = smtplib.SMTP() > ??345 ? ? ? ? if self.smtp_server: > ??346 ? ? ? ? ? ? smtp.connect(self.smtp_server) > ??347 ? ? ? ? else: > ??348 ? ? ? ? ? ? smtp.connect() > smtp = , smtp.connect = >, self = , self.smtp_server > = 'localhost' > ?/usr/lib64/python2.4/smtplib.py in connect(self=, > host='localhost', port=25) > ??305 ? ? ? ? if not self.sock: > ??306 ? ? ? ? ? ? raise socket.error, msg > ??307 ? ? ? ? (code, msg) = self.getreply() > ??308 ? ? ? ? if self.debuglevel > 0: print>>stderr, "connect:", msg > ??309 ? ? ? ? return (code, msg) > code undefined, msg = 'getaddrinfo returns an empty list', self = > , self.getreply = > > ?/usr/lib64/python2.4/smtplib.py in getreply(self=) > ??349 ? ? ? ? ? ? if line == '': > ??350 ? ? ? ? ? ? ? ? self.close() > ??351 ? ? ? ? ? ? ? ? raise SMTPServerDisconnected("Connection unexpectedly > closed") > ??352 ? ? ? ? ? ? if self.debuglevel > 0: print>>stderr, 'reply:', > repr(line) > ??353 ? ? ? ? ? ? resp.append(line[4:].strip()) > global SMTPServerDisconnected = > SMTPServerDisconnected: Connection unexpectedly closed > ?? ? ?args = ('Connection unexpectedly closed',) > I cannot find the qmail logs. I assumed they'd be in either > /var/qmail/supervise/qmail-send > or > /var/qmail/supervise/qmail-smtpd > but I find no logs there. > > [SSH] Protocol Version 2 (OpenSSH_4.3) > [SSH] Cipher: aes128-cbc > Logged in (password) > Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 > [beno at 13gems ~]$ su > Password: > [root at 13gems beno]# man netstat > [root at 13gems beno]# netstat > Active Internet connections (w/o servers) > Proto Recv-Q Send-Q Local Address ? ? ? ? ? ? ? Foreign Address > State > getnameinfo failed > tcp ? ? ? ?0 ? ?268 nrelectric.com:ssh ? ? ? ? ?[UNKNOWN]:61912 > ESTABLISHED > Active UNIX domain sockets (w/o servers) > Proto RefCnt Flags ? ? ? Type ? ? ? State ? ? ? ? I-Node Path > unix ?7 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?10842 ?/dev/log > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?10370 > ?@/org/kernel/udev/udevd > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?6077731 > unix ?3 ? ? ?[ ] ? ? ? ? STREAM ? ? CONNECTED ? ? 6077679 > unix ?3 ? ? ?[ ] ? ? ? ? STREAM ? ? CONNECTED ? ? 6077678 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?6077675 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?11556 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?11511 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?10990 > [root at 13gems beno]# > > How do I trouble-shoot this? Try connecting to the port that is supposed to accept mail messages via telnet and issue a few SMTP commands. -- Jonathan Gardner jgardner at jonathangardner.net From wolftracks at invalid.com Tue Feb 23 16:00:02 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 13:00:02 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 In-Reply-To: References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: On 2/23/2010 11:14 AM, Gib Bogle wrote: > W. eWatson wrote: >> On 2/23/2010 8:26 AM, Rick Dooling wrote: >>> No telling what Windows will do. :) >>> >>> I am a mere hobbyist programmer, but I think real programmers will >>> tell you that it is a bad habit to use relative paths. Use absolute >>> paths instead and remove all doubt. >>> >>> http://docs.python.org/library/os.path.html >>> >>> RD >> You may be right. The actual 300 line program just reads the folder >> without specifying any path. I'm not that familiar with os path, but >> have seen it used. > > How do you invoke the program? Do you use a Command Prompt window? IDLE, but I'm prett sure I tried it (300 lines) with Cprompt. From guglgrupe at yahoo.com Tue Feb 23 16:02:13 2010 From: guglgrupe at yahoo.com (Milenko Kindl) Date: Tue, 23 Feb 2010 13:02:13 -0800 (PST) Subject: Milenko Kindl and America's Worst French Fries Message-ID: Milenko Kindl In spite of the name, French fries are practically an American birthright. They?re offered as the first choice side dish with nearly every fast-food and sit-down chain meal available. But here?s the catch: In a recent study of 7,318 New York City patrons leaving fast food chains during the lunch hour, researchers learned that combo meals ?meaning meals with sides?averaged 1,100 calories each, which is over half a day?s allotment. It goes to show: When your regular meals at these restaurants are already pushing the nutritional envelope, adding an extra 300 (or more!) empty calories can make for a dietary disaster. The authors of the best-selling weight-loss series Eat This, Not That! and Cook This, Not That! have rounded up three of the worst orders of fries available at chain restaurants across the country. We?ve also offered up the surprising winner of the fast food French fry cook-off? you?ll never believe which restaurant chain produces the healthiest fried spuds! Worst Curly Fries Arby?s Curly Fries (Large) 640 calories 34 g fat (5 g saturated, 0 g trans) 1,460 mg sodium Arby?s is famous for its curly fries?too bad they?re overloaded with fat, calories and sodium. When one side dish accounts for nearly three- quarters of your daily allotment of salt, you know there?s a problem. As fun as these curli-Qs are, stick to the Homefry variety at Arby?s? downsizing to a small Curly Fries will still leave you with a 410- calorie side, which is more than many of Arby?s sandwiches! Bonus tip: For full nutrition information for all of your favorite chain restaurants and thousands of foods, download the bestselling Eat This, Not That! iPhone app. It?s like having your own personal nutritionist in your pocket at all times, and will help you avoid the caloric calamities and guide you to the best ways to lose your belly fast. Eat This Instead! Homestyle Fries (Small) 350 calories 15 g fat (2 g saturated) 720 mg sodium Worst Wedge Fries Jack in the Box Bacon Cheddar Wedges 715 calories 45 g fat (13 g saturated, 1 g trans) 905 mg sodium It doesn?t take a nutritionist to identify the hazards of a grease- soaked, cheese-slathered sack of deep-fried potatoes, but by appearance alone, nobody could guess what?s really at stake when you order this side from Jack?s. The American Heart Association recommends that people cap their trans fat intake at 1 percent of total calories. For people on a 2,000-calorie diet, that?s about 2 grams per day. See the problem? Another issue, of course, is the overload in calories? about one-third your daily allotment! Bonus tip: Cheese fries are clearly an unhealthy choice. But sometimes healthy-seeming options are just as dangerous as the obvious diet- sinkers. For 30 jaw-dropping examples, check out The 30 Worst Sandwiches in America. Eat This Instead! Grilled Chicken Strips (4) with Fire Roasted Salsa 185 calories 2 g fat (0.5 g saturated) 805 mg sodium Worst Fries for Your Blood Pressure Dairy Queen Chili Cheese Fries 1,240 calories 71 g fat (28 g saturated, 0.5 g trans) 2,550 milligrams sodium This one?s a no-brainer: Chili, cheese, fried potatoes. But even a savvy eater couldn?t possibly anticipate how bad these 3 ingredients could be when combined by one heavy-handed fast-food company. There?s as much sodium in this side dish as you?ll find in 15 strips of bacon. Stick with classic ketchup and recapture nearly a day?s worth of sodium and 930 calories. Bonus tip: Save calories, time, and money with our free Eat This, Not That! newsletter. Sign up today and you?ll get the Eat This, Not That! guide to shopping once and eating for a week for free! Eat This Instead! French Fries (regular) 310 calories 13 g fat (2 g saturated) 640 mg sodium Worst Regular Order of Fries Five Guys Fries (large) 1,464 calories 71 g fat (14 g saturated) 213 mg sodium Unfortunately, Five Guys doesn?t offer anything but fries in the side department. Your safest bet, of course, is to skip the fries altogether (you?d be better off adding a second patty to your burger), but if you can?t bring yourself to eat a burger sans fries, then split a regular order. That will still add 310 calories to your meal, but it beats surrendering more than 75% of your day?s calories to a greasy paper bag. Bonus tip: Sides account for a third of our combo-meal calories?but drinks account for a quarter of the total calories we consume each day! Battle the liquid bulge: Avoid all drinks on this shocking list of The Worst Drinks in the Supermarket. Eat This Instead! Regular Fries (1/2 serving) 310 calories 15 g fat (3 g saturated) 45 mg sodium Worst Fries in America Chili?s Texas Cheese Fries w/Jalapeno Ranch 1,920 calories 147 g fat (63 g saturated) 3,580 mg sodium The only thing that comes close to redeeming this cheesy mound of lard and grease is the fact that it?s ostensibly meant to be shared with a few friends. Even so, you?ll collectively be taking in an entire day?s worth of calories, three days? allotment of saturated fat, and a day and a half?s allotment of sodium. What?s even scarier, if you can imagine, is that even if you try to order more sensibly and ask for the ?half? order of Texas Cheese Fries, you?ll still receive a disastrous dish that packs in 1,400 calories. There?s one French fries side dish at Chili?s that?s acceptable, although even in its much- reduced form, you?d be better off splitting it. Bonus Tip: See what other Chili?s items made our list of The 20 Worst Restaurant Foods in America. Eat This Instead! Homestyle Fries 380 calories 23 g fat (4 g saturated) 230 mg sodium Best Fast Food Fries in America McDonald?s Small French Fries 230 calories 11 g fat (1.5 g saturated) 160 mg sodium Out of the big three fast food joints (Mickey D?s, Wendy?s, and BK), you?ll find the least caloric, least salty fries underneath the golden arches. The key to ordering a smart side dish is portion sizing?and McDonald?s has that under control. ------------ Follow Men's Health and Women's Health editor Dave Zinczenko on Twitter. You'll get the best life-changing health, nutrition and exercise secrets every day. Check out the cutting-edge guide to fast and easy weight loss, the brand-new Big Book of Exercises. Feeling lousy? Find the right medicine to ease the cold and flu Get more nutrition, health, and fitness secrets from Men's Health: Subscribe today with this special offer and save 50% off the cover price. From arnodel at googlemail.com Tue Feb 23 16:10:14 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 23 Feb 2010 21:10:14 +0000 Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: vsoler writes: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} These are sets, not dicts. > and I'd like to have > > a=1 > m=3 > p=7 As sets are unordered, you may as well have a = 3 m = 7 p = 1 or any other permutation. You need some sequences instead. E.g. n = ['a', 'm', 'p'] v = (1, 3, 7) Then you can do: for name, value in zip(n, v): globals()[name] = value After this the names, 'a', 'm' and 'p' will be bound to the values you want in the global namespace. However, it is almost always a bad idea to do this. Can you explain why you need to do this? -- Arnaud From buggsy2 at sdlfkj.com Tue Feb 23 16:11:52 2010 From: buggsy2 at sdlfkj.com (buggsy2 at sdlfkj.com) Date: Tue, 23 Feb 2010 13:11:52 -0800 Subject: What's Going on between Python and win7? References: Message-ID: "W. eWatson" writes: > I noted that this search box has > some sort of filter associated with it. Possibly, in my early stages > of learning to navigate in Win7, I accidentally set the filter. > > Comments? FYI, the only truly reliable and powerful file search utility I've found for Windows is Agent Ransack (http://download.mythicsoft.com/agentran.exe) From wuhrrr at gmail.com Tue Feb 23 16:21:36 2010 From: wuhrrr at gmail.com (Hai Vu) Date: Tue, 23 Feb 2010 13:21:36 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 12:53?pm, vsoler wrote: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} > > and I'd like to have > > a=1 > m=3 > p=7 > > that is, creating some variables. > > How can I do this? I think you meant to use the square brackets [ ] instead of the curly ones { } to define the list: >>> n = ['a', 'b', 'c'] >>> v = [3, 5, 7] >>> for x, y in zip(n, v): ... exec '%s=%d' % (x, y) ... >>> a 3 >>> b 5 >>> c 7 --- The key is the use of the exec statement, which executes the strings "a=3", "b=5", ... as if they are python statements. From wolftracks at invalid.com Tue Feb 23 16:23:10 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 13:23:10 -0800 Subject: Bay Area PUG Meeting [Speaker] Thursday in Mountain View, CA? In-Reply-To: References: Message-ID: On 2/23/2010 7:49 AM, W. eWatson wrote: > Anyone here going to the meeting,Subject? As far as I can tell, it meets > from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to > be an informal group dinner at 6 pm at some place yet unknown. Comments? From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 16:29:01 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 10:29:01 +1300 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: W. eWatson wrote: > On 2/23/2010 11:14 AM, Gib Bogle wrote: >> W. eWatson wrote: >>> On 2/23/2010 8:26 AM, Rick Dooling wrote: >>>> No telling what Windows will do. :) >>>> >>>> I am a mere hobbyist programmer, but I think real programmers will >>>> tell you that it is a bad habit to use relative paths. Use absolute >>>> paths instead and remove all doubt. >>>> >>>> http://docs.python.org/library/os.path.html >>>> >>>> RD >>> You may be right. The actual 300 line program just reads the folder >>> without specifying any path. I'm not that familiar with os path, but >>> have seen it used. >> >> How do you invoke the program? Do you use a Command Prompt window? > IDLE, but I'm prett sure I tried it (300 lines) with Cprompt. I don't know what you mean by "300 lines". Have you opened a Command Prompt window, changed to the directory where you copied the files, and executed: python your_prog.py ? From python at mrabarnett.plus.com Tue Feb 23 16:31:48 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Feb 2010 21:31:48 +0000 Subject: Creating variables from dicts In-Reply-To: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4B844944.1050203@mrabarnett.plus.com> vsoler wrote: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} > Those aren't dicts, they're sets. > and I'd like to have > > a=1 > m=3 > p=7 > > that is, creating some variables. > > How can I do this? The real question is not how, but why? Anyway, assuming you want them to be global variables: globals().update(dict(zip(n, v))) On my machine the variables didn't get the correct values because, as I said, 'n' and 'v' are sets, so the order of the members is arbitrary. From benjamin.kaplan at case.edu Tue Feb 23 16:40:10 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 23 Feb 2010 16:40:10 -0500 Subject: What's Going on between Python and win7? In-Reply-To: <4b843c2b$0$17860$ba4acef3@reader.news.orange.fr> References: <87d3zxt3h4.fsf@castleamber.com> <4b843c2b$0$17860$ba4acef3@reader.news.orange.fr> Message-ID: On Tue, Feb 23, 2010 at 3:35 PM, Michel Claveau - MVP wrote: > Hi! > >> Symbolic links are available in NTFS starting with Windows Vista. > > No. > Hardlink come with NTFS, and already exists in W2K (and NT with specifics utilities). > > @-salutations > -- > Michel Claveau > And there's a difference between hard links and symbolic links. Symbolic links were added to NTFS starting with Windows Vista. http://msdn.microsoft.com/en-us/library/aa365680%28VS.85%29.aspx > -- > http://mail.python.org/mailman/listinfo/python-list > From stef.mientki at gmail.com Tue Feb 23 16:54:36 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 23 Feb 2010 22:54:36 +0100 Subject: How to transmit a crash report ? In-Reply-To: <0b222aec-db04-45b7-9f86-e2839ffafc40@j1g2000vbl.googlegroups.com> References: <4B8336EE.9040802@gmail.com> <0b222aec-db04-45b7-9f86-e2839ffafc40@j1g2000vbl.googlegroups.com> Message-ID: <4B844E9C.1000706@gmail.com> On 23-02-2010 15:21, Thomas wrote: > On Feb 22, 9:27 pm, MRAB wrote: > >> Stef Mientki wrote: >> >>> hello, >>> >> >>> in my python desktop applications, >>> I'ld like to implement a crash reporter. >>> By redirecting the sys.excepthook, >>> I can detect a crash and collect the necessary data. >>> Now I want that my users sends this information to me, >>> and I can't find a good way of doing this. >>> >> >>> The following solutions came into my mind: >>> (most of my users are on Windows, and the programs are written in Python >>> 2.6) >>> >> >>> 1. mailto: >>> doesn't work if the the user didn't install a default email client, >>> or if the user uses a portable email client (that isn't started yet) >>> Besides this limits the messages to small amounts of data. >>> >> >>> 2.other mail options: smtp >>> AFAIK such a solution needs smtp authorization, and therefor I've to put >>> my username and password in the desktop application. >>> >> Try reading the documentation for Python's smtplib module. >> >> You don't need to provide any password. >> >> >> >> >>> 3. http-post >>> Although post is also limited in size, >>> I could store information in cookies (don't know yet how), and cookies >>> are sent parallel to the post message. >>> On the server site I can use a small php script, that stores the >>> post-data, cookies and/or send's a (long) email. >>> >> >>> are there better options ?- Hide quoted text - >>> >> - Show quoted text -- Hide quoted text - >> >> - Show quoted text - >> > Try http://code.activestate.com/recipes/442459/ > Apparently there's something terrible wrong on my system, because I do need username and password :-( First, a script that works without username and password. I guess it works, because the smtp_server is the smtp server of my provider, and I'm in that domain of my provider, so it won't work for a random user of my program. if Test ( 4 ) : import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart body = 'test_body' subject = 'test_subject' mail_to = 's.mientki at ru.nl' mail_from = 'stef.mientki at gmail.com' msg = MIMEMultipart ( 'alternative' ) msg [ 'To' ] = mail_to msg [ 'From' ] = mail_from msg [ 'Subject' ] = subject part1 = MIMEText ( body, 'plain' ) msg.attach ( part1 ) smtp_server = 'mail.upcmail.nl' session = smtplib.SMTP ( smtp_server ) session.sendmail ( mail_from, [mail_to], msg.as_string() ) Using smtp on google , works only if I support username and password: if Test ( 5 ) : import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart body = 'test_body' subject = 'test_subject' mail_to = 's.mientki at ru.nl' mail_from = 'stef.mientki at gmail.com' msg = MIMEMultipart ( 'alternative' ) msg [ 'To' ] = mail_to msg [ 'From' ] = mail_from msg [ 'Subject' ] = subject part1 = MIMEText ( body, 'plain' ) msg.attach ( part1 ) smtp_server = 'smtp.gmail.com' session = smtplib.SMTP ( smtp_server, 587 ) session.ehlo ( mail_from ) session.starttls () session.ehlo ( mail_from ) session.login (username, password ) session.sendmail ( mail_from, [mail_to], msg.as_string() ) And her a number of different tries with localhost / mail : if Test ( 6 ) : import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart body = 'test_body' subject = 'test_subject' mail_to = 's.mientki at ru.nl' mail_from = 'stef.mientki at gmail.com' msg = MIMEMultipart ( 'alternative' ) msg [ 'To' ] = mail_to msg [ 'From' ] = mail_from msg [ 'Subject' ] = subject part1 = MIMEText ( body, 'plain' ) msg.attach ( part1 ) session = smtplib.SMTP ( 'localhost' ) """ Traceback (most recent call last): File "D:\Data_Python_25\support\mail_support.py", line 375, in session = smtplib.SMTP ( smtp_server ) File "P:\Python26\lib\smtplib.py", line 239, in __init__ (code, msg) = self.connect(host, port) File "P:\Python26\lib\smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "P:\Python26\lib\smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "P:\Python26\lib\socket.py", line 514, in create_connection raise error, msg error: [Errno 10061] No connection could be made because the target machine actively refused it """ #session = smtplib.SMTP ( 'localhost', 25 ) #session = smtplib.SMTP ( 'mail', 25 ) session = smtplib.SMTP ( 'mail', 1025 ) """ Traceback (most recent call last): File "D:\Data_Python_25\support\mail_support.py", line 377, in session = smtplib.SMTP ( 'mail', 1025 ) File "P:\Python26\lib\smtplib.py", line 239, in __init__ (code, msg) = self.connect(host, port) File "P:\Python26\lib\smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "P:\Python26\lib\smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "P:\Python26\lib\socket.py", line 500, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): gaierror: [Errno 11001] getaddrinfo failed """ session.sendmail ( mail_from, [mail_to], msg.as_string() ) What am I doing wrong ? cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue Feb 23 17:26:34 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Feb 2010 09:26:34 +1100 Subject: When will Python go mainstream like Java? References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: <87wry3612d.fsf@benfinney.id.au> Stefan Behnel writes: > Chris Rebert, 23.02.2010 06:45: > > Indeed. Python is at position 7, just behind C#, in the TIOBE Index: > > http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? Why not? What do you think the TIOBE measures, and why would PHP not be rising by that measure? -- \ ?To save the world requires faith and courage: faith in reason, | `\ and courage to proclaim what reason shows to be true.? | _o__) ?Bertrand Russell | Ben Finney From david at boddie.org.uk Tue Feb 23 17:28:12 2010 From: david at boddie.org.uk (David Boddie) Date: Tue, 23 Feb 2010 23:28:12 +0100 Subject: Problem creating executable, with PyQwt References: Message-ID: On Tuesday 23 February 2010 05:32, Gib Bogle wrote: > David Boddie wrote: > >> I have previously referred people with py2exe/PyQt issues to this page on >> the PyQt Wiki: >> >> http://www.py2exe.org/index.cgi/Py2exeAndPyQt >> >> If you can somehow convince py2exe to include the QtSvg module (and >> presumably the libQtSvg library as well) then perhaps that will solve >> this problem. >> >> David > > Thanks David, that worked a treat. :-) If you could update the Wiki (or maybe the py2exe Wiki, if they have one) to say what you did, that would be useful for others in the future. Then they'll only be one search away from the answer. :-) David From aahz at pythoncraft.com Tue Feb 23 17:50:15 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 14:50:15 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA References: Message-ID: In article , W. eWatson wrote: > >Anyone here going to the meeting,Subject? As far as I can tell, it meets >from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >be an informal group dinner at 6 pm at some place yet unknown. Comments? Subscribe to http://mail.python.org/mailman/listinfo/baypiggies -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From lie.1296 at gmail.com Tue Feb 23 17:55:21 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 09:55:21 +1100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4b845cfa$1@dnews.tpgi.com.au> On 02/24/10 05:25, Michael Rudolf wrote: > Just a quick question about what would be the most pythonic approach in > this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > >>>> def a(x=None): > if x is None: > pass > else: > pass Python's idiom for this has always been to use "if arg is None:"; but now with the (relatively) new decorator feature, though is not yet a popular idiom, it is now possible to do something like this: #!/usr/bin/env python from functools import wraps def overloaded(func): @wraps(func) def overloaded_func(*args, **kwargs): for f in overloaded_func.overloads: try: return f(*args, **kwargs) except TypeError: pass else: # it will be nice if the error message prints a list of # possible signatures here raise TypeError("No compatible signatures") def overload_with(func): overloaded_func.overloads.append(func) return overloaded_func overloaded_func.overloads = [func] overloaded_func.overload_with = overload_with return overloaded_func ############# @overloaded def a(): print 'a() without args' pass @a.overload_with def _(n): # note that, just like property(), the function's name in # the "def _(n):" line can be arbitrary, the important # name is in the "@overloads(a)" line print 'a() with args' pass a() a(4) a(4, 5) # ERROR: no matching signature PS: I posted the code to recipe book, for future reference: http://code.activestate.com/recipes/577064-simple-function-overloading-with-decorator/ From luismgz at gmail.com Tue Feb 23 17:56:30 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 14:56:30 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 5:53?pm, vsoler wrote: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} > > and I'd like to have > > a=1 > m=3 > p=7 > > that is, creating some variables. > > How can I do this? You are probably coming from another language and you're not used to python's data structures. If you want a list of items, you use tuples or lists. Examples: ('a', 'm', 'p') ---> this is a tuple, and it's made with parenthesis () ['a', 'm', 'p'] ---> this is a list, and it's made with brackets [] Check the documentation to see the difference between tuples and lists. For now, lets just use lists and forget about tuples... Now if you want a sequence of items ordered a key + value pairs, use a dictionary, as follows: {'name': 'joe', 'surname': 'doe', 'age': 21} ---> this is a dict, and it's made with curly braces {}. Curly braces are also used to create sets, but you don't need them now (check the documentation to learn more about sets). So going back to your question, you should have two lists, as follows: n = ['a', 'm', 'p'] v = [1,3,7] --> note that I used brackets [], not curly braces {}. And now you can build a dict formed by the keys in "n" and the values in "v": myDict = {} --> this is an new empty dictionary for k,v in zip(n,v): myDict[k] = v This results in this dictionary: {'a': 1, 'p': 7, 'm': 3}. Hope this helps... Luis From fetchinson at googlemail.com Tue Feb 23 17:57:45 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 23 Feb 2010 23:57:45 +0100 Subject: [Python-Dev] Question for you In-Reply-To: <4B844F2E.9010300@voidspace.org.uk> References: <36FA01F429A6354CB4C8C185B307F35503F4F080@XMBTX133.northgrum.com> <4B844F2E.9010300@voidspace.org.uk> Message-ID: >> Hello, Dave; >> >> My name is Craig Connor and I am a senior s/w developer at Northrop >> Grumman. >> >> I have a question for you. I have installed* Boost* (via the >> Installer), and stored it into my >> >> C Drive inside a dir called: >> >> * C:\boost_1_42* >> >> I also installed the* Boost Jam* into a directory called: >> >> * C:\boost-jam-3.1.17* >> >> I am using 2 separate compilers in my* Win OS XP (SP3)* >> >> and I would like to be able to use the Python module of Boost >> >> in order to embed Python.h into my C++ compiler. >> >> The C++ compilers that I have are: >> >> o* Dev-cpp*, and >> >> o* Visual C++.net* (of* MS Visual Studio.Net 2008*). >> >> Problem: >> >> When I compile a simple program, I keep getting the error: >> "*pyconfig.h: No such file or directory*". >> >> The program I am trying to start with is (below): >> >> *#include * >> >> *#include* >> >> *#include* >> >> *using namespace std;* >> >> *int main( )* >> >> *{* >> >> * cout << "Hello, Boost World!!" << endl;* >> >> * boost::any a(5);* >> >> * a = 7.67;* >> >> * std::cout<(a)<> >> * * >> >> * system( "PAUSE" );* >> >> * return 0;* >> >> *}* >> >> >> Also: >> >> I did set up my environmental config to go to the Boost dir. >> >> Question: >> >> Do you know what am I doing wrong? >> >> Regards, >> >> Craig Connor >> >> 720.622.2209 >> > Hello Connor, > > I think you have the wrong email address - this is Python-dev, an email > list for the development *of* Python. > > All the best, > > Michael Foord [redirecting to python-list from python-dev] And the fact that you are a "senior s/w developer" at Northrop Grumman surely doesn't sound like good advertisement for said firm. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Tue Feb 23 18:06:09 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Feb 2010 00:06:09 +0100 Subject: Spam from gmail (Was: fascism) In-Reply-To: <20100223110954.5da3d679.darcy@druid.net> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: >> >> Is it just me or has the spew from gmail on this list radically >> >> increased in the last week? Anyone else considering blocking all gmail >> >> posts to this list? >> > >> > I did that a long time ago for all of the Usenet groups I read >> > and all but one of the mailing lists I read. >> >> Wait, I misread the posting. I block everything from >> google.groups, not everything from gmail. > > Yes, I did that a long time ago as well. But now there seems to be > more and more actual spam coming from gmail.com itself. It may just be > a minor blip on the spam graph but I'm keeping my eye on it. > > Most mailing lists that I am on are pretty good at filtering spam > before it gets to the list. The only spam I ever see on my NetBSD > lists are the ones that I moderate and I block them before anyone else > sees them. A little more pain for me in return for a lot less pain for > everyone else. I guess that's not possible on a list that is gatewayed > to UseNet like this one is. > > Hmm. I wonder if all the spam is coming from the NG side. I'll have > to look at that. One of the reasons that I stopped reading UseNet over > ten years ago was because of the diminishinig S/N ratio. I have always > felt that it was a mistake to gateway this group. And this has to do with python programming in what way? You, sir, are incredibly funny :) Just 5 minutes ago you declared in a nearby thread that > It isn't about the Python programming language so it is off topic. So > what if some members have an interest? We have interest in a lot of > things. We all have interest in the hardware that our programs run on > but questions about hardware are also off topic. > > Perhaps you don't quite grasp the point of topical discussion groups. > They are a way of letting individuals decide for themselves what kind > of discussions they want to be involved in. By spamming the group this > way you take away that freedom of choice. It's ironic when it is done > in the name of freedom. Touche! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From monkey at joemoney.net Tue Feb 23 18:08:19 2010 From: monkey at joemoney.net (monkeys paw) Date: Tue, 23 Feb 2010 18:08:19 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> On 2/23/2010 3:17 PM, Tim Chase wrote: > monkeys paw wrote: >> I used the following code to download a PDF file, but the >> file was invalid after running the code, is there problem >> with the write operation? >> >> import urllib2 >> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >> a = open('adobe.pdf', 'w') > > Sure you don't need this to be 'wb' instead of 'w'? 'wb' does the trick. Thanks all! Here is the final working code, i used an index(i) to see how many reads took place, i have to assume there is a default buffer size: import urllib2 a = open('adobe.pdf', 'wb') i = 0 for line in urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): i = i + 1 a.write(line) print "Number of reads: %d" % i a.close() NEW QUESTION if y'all are still reading: Is there an integer increment operation in Python? I tried using i++ but had to revert to 'i = i + 1' > >> for line in urllib2.urlopen(url): >> a.write(line) > > I also don't know if this "for line...a.write(line)" loop is doing > newline translation. If it's a binary file, you should use .read() > (perhaps with a modest-sized block-size, writing it in a loop if the > file can end up being large.) > > -tkc > > From ldo at geek-central.gen.new_zealand Tue Feb 23 18:11:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:11:26 +1300 Subject: Writing an assembler in Python References: Message-ID: In message , Anh Hai Trinh wrote: > On Feb 23, 10:08 am, Lawrence D'Oliveiro wrote: >> >> Let me suggest an alternative approach: use Python itself as the >> assembler. Call routines in your library to output the code. That way you >> have a language more powerful than any assembler. >> >> See for an example. > > SyntaxError: Non-matching "#end if" in crosscode8.py:345 What mismatch? Line 345 is the last line of this routine: def org(self, addr) : """sets the origin for defining subsequent consecutive memory contents.""" self.curpsect.setorigin(self.follow(addr)) self.lastaddr = self.curpsect.origin return self # for convenient chaining of calls #end org From ldo at geek-central.gen.new_zealand Tue Feb 23 18:18:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:18:19 +1300 Subject: Is this secure? References: Message-ID: In message , mk wrote: > I need to generate passwords and I think that pseudo-random generator is > not good enough, frankly. So I wrote this function: Much simpler: import subprocess data, _ = subprocess.Popen \ ( args = ("pwgen", "-nc"), stdout = subprocess.PIPE ).communicate() print data From ldo at geek-central.gen.new_zealand Tue Feb 23 18:19:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:19:13 +1300 Subject: When will Java go mainstream like Python? References: Message-ID: In message , Martin P. Hellwig wrote: > Actually I am still waiting for Java to be mainstream :-) Too late, I think. Sun dilly-dallied over making it open source for too long, until it practically didn?t matter any more. From comptekki at gmail.com Tue Feb 23 18:19:41 2010 From: comptekki at gmail.com (Wes James) Date: Tue, 23 Feb 2010 16:19:41 -0700 Subject: python dowload In-Reply-To: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <533df7fa1002231519t127cd512r9bc2feb294db77f2@mail.gmail.com> > > > NEW QUESTION if y'all are still reading: > > Is there an integer increment operation in Python? I tried > using i++ but had to revert to 'i = i + 1' i+=1 From ldo at geek-central.gen.new_zealand Tue Feb 23 18:22:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:22:05 +1300 Subject: When will Java go mainstream like Python? References: Message-ID: In message , Ishwor Gurung wrote: > Java - The JVM code been hacked to death by Sun engineers (optimised) > Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. > ad-infinitum but nowhere as near to JVM Python is still faster, though. I think a key reason is that its VM supports reference-counting, which the Java folks never quite got the grasp of. So you see, it?s all about working smarter, not harder. From ldo at geek-central.gen.new_zealand Tue Feb 23 18:25:37 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:25:37 +1300 Subject: look at the google code References: <711cb713-4b4a-47f6-8922-ce1ada7d64e6@e1g2000yqh.googlegroups.com> Message-ID: In message <711cb713-4b4a-47f6-8922-ce1ada7d64e6 at e1g2000yqh.googlegroups.com>, lkcl wrote: > we couldn't get control of that site for quite some time so > started using sourceforget for svn, but the issue tracker on > sourceforget is truly dreadful. Damn. I?ve been working on my own fork of a long-neglected package on SourceForge . GitHub doesn?t offer a publicly-writable bug tracker, but I was under the impression that SourceForge did. But you?re saying it?s not worth using? From darcy at druid.net Tue Feb 23 18:29:23 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 18:29:23 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: <20100223182923.4d259d12.darcy@druid.net> On Wed, 24 Feb 2010 00:06:09 +0100 Daniel Fetchinson wrote: > And this has to do with python programming in what way? Are you new? Meta discussions about lists are generally considered on-topic for the list. > You, sir, are incredibly funny :) Yes, I am. That however is NOT on topic. :-) And just to bring this back on topic, I did do a test and found that splitting my mailbox between Python mailing list messages and Python newsgroup messages did not indicate that that was a good barometer of spaminess. There are also quite a few decent posts from gmail.com so blocking by that domain isn't going to be the problem solver either. -- 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 ethan at stoneleaf.us Tue Feb 23 18:34:02 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 23 Feb 2010 15:34:02 -0800 Subject: python dowload In-Reply-To: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <4B8465EA.30706@stoneleaf.us> monkeys paw wrote: > NEW QUESTION if y'all are still reading: > > Is there an integer increment operation in Python? I tried > using i++ but had to revert to 'i = i + 1' Nope, but try i += 1. ~Ethan~ From sccolbert at gmail.com Tue Feb 23 18:36:48 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 23 Feb 2010 18:36:48 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: <7f014ea61002231536h36a0cf20u2de17fef7f76f8ab@mail.gmail.com> this image is appropriate: http://4.bp.blogspot.com/_pS7sKjlzwFg/SwhG1S901pI/AAAAAAAAEiw/XSm93RIY2WE/s400/kelso-burn.jpg On Tue, Feb 23, 2010 at 6:06 PM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > >> >> Is it just me or has the spew from gmail on this list radically > >> >> increased in the last week? Anyone else considering blocking all > gmail > >> >> posts to this list? > >> > > >> > I did that a long time ago for all of the Usenet groups I read > >> > and all but one of the mailing lists I read. > >> > >> Wait, I misread the posting. I block everything from > >> google.groups, not everything from gmail. > > > > Yes, I did that a long time ago as well. But now there seems to be > > more and more actual spam coming from gmail.com itself. It may just be > > a minor blip on the spam graph but I'm keeping my eye on it. > > > > Most mailing lists that I am on are pretty good at filtering spam > > before it gets to the list. The only spam I ever see on my NetBSD > > lists are the ones that I moderate and I block them before anyone else > > sees them. A little more pain for me in return for a lot less pain for > > everyone else. I guess that's not possible on a list that is gatewayed > > to UseNet like this one is. > > > > Hmm. I wonder if all the spam is coming from the NG side. I'll have > > to look at that. One of the reasons that I stopped reading UseNet over > > ten years ago was because of the diminishinig S/N ratio. I have always > > felt that it was a mistake to gateway this group. > > And this has to do with python programming in what way? > > You, sir, are incredibly funny :) > > Just 5 minutes ago you declared in a nearby thread that > > > It isn't about the Python programming language so it is off topic. So > > what if some members have an interest? We have interest in a lot of > > things. We all have interest in the hardware that our programs run on > > but questions about hardware are also off topic. > > > > Perhaps you don't quite grasp the point of topical discussion groups. > > They are a way of letting individuals decide for themselves what kind > > of discussions they want to be involved in. By spamming the group this > > way you take away that freedom of choice. It's ironic when it is done > > in the name of freedom. > > Touche! > > Cheers, > Daniel > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From luismgz at gmail.com Tue Feb 23 18:41:16 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 15:41:16 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 7:56?pm, Luis M. Gonz?lez wrote: > On Feb 23, 5:53?pm, vsoler wrote: > > > > > > > Hi, > > > I have two dicts > > > n={'a', 'm', 'p'} > > v={1,3,7} > > > and I'd like to have > > > a=1 > > m=3 > > p=7 > > > that is, creating some variables. > > > How can I do this? > > You are probably coming from another language and you're not used to > python's data structures. > If you want a list of items, you use tuples or lists. Examples: > > ? ? ('a', 'm', 'p') ---> this is a tuple, and it's made with > parenthesis () > ? ? ['a', 'm', 'p'] ---> this is a list, and it's made with brackets > [] > > Check the documentation to see the difference between tuples and > lists. > For now, lets just use lists and forget about tuples... > Now if you want a sequence of items ordered a key + value pairs, use a > dictionary, as follows: > > ? ? {'name': 'joe', 'surname': 'doe', 'age': 21} ---> this is a dict, > and it's made with curly braces {}. > > Curly braces are also used to create sets, but you don't need them now > (check the documentation to learn more about sets). > So going back to your question, you should have two lists, as follows: > > ? ? n = ['a', 'm', 'p'] > ? ? v = [1,3,7] ? ? ? ? --> note that I used brackets [], not curly > braces {}. > > And now you can build a dict formed by the keys in "n" and the values > in "v": > > ? ? myDict = {} ? ? ? ? ? --> this is an new empty dictionary > ? ? for k,v in zip(n,v): > ? ? ? ? myDict[k] = v > > This results in this dictionary: {'a': 1, 'p': 7, 'm': 3}. > > Hope this helps... > Luis By the way, if you want the variables inside myDict to be free variables, you have to add them to the local namespace. The local namespace is also a dictionary "locals()". So you can update locals as follows: locals().update( myDictionary ) This way, all the key-value pairs inside myDict become free variables. Wich is the same as declaring them as follows: a = 1 p = 7 etc... Luis From python.list at tim.thechases.com Tue Feb 23 18:41:37 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Feb 2010 17:41:37 -0600 Subject: Creating variables from dicts In-Reply-To: References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4B8467B1.6010404@tim.thechases.com> Luis M. Gonz?lez wrote: > If you want a list of items, you use tuples or lists. Examples: > > ('a', 'm', 'p') ---> this is a tuple, and it's made with > parenthesis () Actually, a tuple is made with commas...the parens are just there to clarify the order of operations and make it easier to read :) >>> x = 1,2,3 >>> x (1, 2, 3) -tkc From nad at acm.org Tue Feb 23 19:13:46 2010 From: nad at acm.org (Ned Deily) Date: Tue, 23 Feb 2010 16:13:46 -0800 Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <20100223182923.4d259d12.darcy@druid.net> Message-ID: In article <20100223182923.4d259d12.darcy at druid.net>, "D'Arcy J.M. Cain" wrote: > And just to bring this back on topic, I did do a test and found that > splitting my mailbox between Python mailing list messages and Python > newsgroup messages did not indicate that that was a good barometer of > spaminess. There are also quite a few decent posts from gmail.com so > blocking by that domain isn't going to be the problem solver either. Try following the list using gmane (either via NNTP, RSS, or the web). gmane does a pretty good job of filtering the spam. http://dir.gmane.org/gmane.comp.python.general -- Ned Deily, nad at acm.org From leo.shklovskii at gmail.com Tue Feb 23 19:19:56 2010 From: leo.shklovskii at gmail.com (Leo) Date: Tue, 23 Feb 2010 16:19:56 -0800 (PST) Subject: python shell crashing on paste Message-ID: <1ede46e4-8ca1-4fe0-ad3f-7e781bbe1182@b36g2000pri.googlegroups.com> I just upgraded to Windows 7 (yes, I know) and I've been having a really strange problem with running python (2.6.4, installed from the python.org installer) from the command line. If I open the interpreter, and then paste in a long string, conhost.exe crashes. This doesn't happen when pasting the string just in the command line so its something with the python interpreter. Here's the details of the windows crash: Log Name: Application Source: Application Error Event ID: 1000 Task Category: (100) Level: Error Keywords: Classic Description: Faulting application name: conhost.exe, version: 6.1.7600.16385, time stamp: 0x4a5bc271 Faulting module name: conhost.exe, version: 6.1.7600.16385, time stamp: 0x4a5bc271 Exception code: 0xc0000005 Fault offset: 0x000048ca Faulting process id: 0x1aa8 Faulting application start time: 0x01cab4e450b97766 Faulting application path: C:\Windows\system32\conhost.exe Faulting module path: C:\Windows\system32\conhost.exe Report Id: 9c6afd6c-20d7-11df-bbd8-e390d387a902 Has anyone else seen anything like this? Any suggestions on how to even start figuring this out? --Leo From aahz at pythoncraft.com Tue Feb 23 19:21:48 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 16:21:48 -0800 Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: In article , D'Arcy J.M. Cain wrote: >On Tue, 23 Feb 2010 02:54:25 -0800 (PST) >Joan Miller wrote: >> >> *Sorry by this message off topic, but this is too important* > >Is it just me or has the spew from gmail on this list radically >increased in the last week? Anyone else considering blocking all gmail >posts to this list? Joan Miller is a regular poster; this is off-topic, but it's not spam. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From ben+python at benfinney.id.au Tue Feb 23 19:36:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Feb 2010 11:36:08 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <87sk8r5v2f.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > Joan Miller is a regular poster; this is off-topic, but it's not spam. Non sequitur. Spam is spam, not by who authors or posts it, but by its distribution (to many people, e.g. via a forum like this one) and its content (off-topic and unsolicited). The message is important, its poster is a regular here; that doesn't stop the message being spam when posted here. -- \ ?Everyone is entitled to their own opinions, but they are not | `\ entitled to their own facts.? ?US Senator Pat Moynihan | _o__) | Ben Finney From lie.1296 at gmail.com Tue Feb 23 19:41:35 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 11:41:35 +1100 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <4b8475df$1@dnews.tpgi.com.au> On 02/24/10 11:21, Aahz wrote: > In article , > D'Arcy J.M. Cain wrote: >> On Tue, 23 Feb 2010 02:54:25 -0800 (PST) >> Joan Miller wrote: >>> >>> *Sorry by this message off topic, but this is too important* >> >> Is it just me or has the spew from gmail on this list radically >> increased in the last week? Anyone else considering blocking all gmail >> posts to this list? > > Joan Miller is a regular poster; this is off-topic, but it's not spam. Does being a regular poster exempts you from having your post considered as spam? That's an http://en.wikipedia.org/wiki/Ad_hominem#Inverse_ad_hominem. From nobody at nowhere.com Tue Feb 23 20:03:23 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 24 Feb 2010 01:03:23 +0000 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: On Mon, 22 Feb 2010 22:27:54 -0800, sjdevnull at yahoo.com wrote: > Basically, multiprocessing is always hard--but it's less hard to start > without shared everything. Going with the special case (sharing > everything, aka threading) is by far the stupider and more complex way > to approach multiprocssing. Multi-threading hardly shares anything (only dynamically-allocated and global data), while everything else (the entire stack) is per-thread. Yeah, I'm being facetious. Slightly. If you're going to write multi-threaded code, it's a good idea to wean yourself off of using global variables and shared mutable state. From nobody at nowhere.com Tue Feb 23 20:08:18 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 24 Feb 2010 01:08:18 +0000 Subject: When will Java go mainstream like Python? References: Message-ID: On Wed, 24 Feb 2010 12:22:05 +1300, Lawrence D'Oliveiro wrote: >> Java - The JVM code been hacked to death by Sun engineers (optimised) >> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >> ad-infinitum but nowhere as near to JVM > > Python is still faster, though. I think a key reason is that its VM supports > reference-counting, which the Java folks never quite got the grasp of. So how does Python handle circular references? From rhodri at wildebst.demon.co.uk Tue Feb 23 20:11:48 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 24 Feb 2010 01:11:48 -0000 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> <19c11c1f-d70e-4b10-b425-6e65d4c70aeb@d2g2000yqa.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 10:39:21 -0000, DANNY wrote: > @James I am thinkinhg about effect of errors that are within the > sequence of P frames. Where the P frames have only the information > about the changes in previous frames, so that errors are present until > the next I frame. So I would like to see how is this seen in different > GoP sized clips. Ah, I see. What I'd suggest you do is to encode your video clip at various GOP sizes (you'll want some quite extreme ones for comparison), then write a little program that reads in the file byte by byte and randomly corrupts the data as it goes through. "tsplay" from the tstools suite that I mentioned earlier will do that for you (because it was very handy for testing the robustness of our decoders). Then watch the results using VLC or similar. My recollection is that when the image isn't static, P frames tend to have enough intra-coded blocks that corrupted video data doesn't have as much effect as you might think. I've dealt with streams that had ten seconds or more between I frames, and starting at a random spot (simulating changing channel on your digital TV) builds up an intelligible (if obviously wrong) image surprisingly quickly. PS: my first name is Rhodri, not James. Don't worry, it catches a lot of people out. -- Rhodri James *-* Wildebeeste Herder to the Masses From lie.1296 at gmail.com Tue Feb 23 20:12:12 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 12:12:12 +1100 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: <4b847d0c$1@dnews.tpgi.com.au> On 02/23/10 05:30, W. eWatson wrote: > On 2/22/2010 8:29 AM, Grant Edwards wrote: >> On 2010-02-22, W. eWatson wrote: >> >>> Last night I copied a program from folder A to folder B. >> >> [tail of various windows breakages elided] >> >>> Comments? >> >> Switch to Linux? >> >> Or at least install Cygwin? >> > Yes, definitely not related, but maybe some W7 user has a similar > experience here. It seems a natural place to look, since it should be > reasonably common. IMHO that doesn't justify. The advice to move the discussion to a windows-specific group is not just about reducing off-topic discussion[1], but because there isn't that much Windows (Seven) users in this newsgroup. Most comp.lang.python users either uses linux, unix, macs, or older version of windows, and are not familiar with the specifics of Windows 7. It would be nice though, if you reposted the solution you found from another forum here to benefit other python Windows 7 users. [1] pretty much anything computer-related is not entirely off-topic in c.l.py because of the wide range of situations people uses python in (I've seen general algorithmic questions, text-editor wars, problems with 3rd party module, jython/ironpython internals, etc discussed in here; many of those gets quite welcomed even though technically off-topic) From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:15:40 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:15:40 GMT Subject: Bizarre arithmetic results References: <3fb9d59b-21c2-4372-9a32-c542e884faa7@x9g2000vbo.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 05:48:09 -0800, Mark Dickinson wrote: > On Feb 23, 8:11?am, Steven D'Aprano > wrote: >> Making spaces significant in that fashion is mind-bogglingly awful. >> Let's look at a language that does this: >> >> [steve at sylar ~]$ cat ws-example.rb >> def a(x=4) >> ? ? x+2 >> end >> >> b = 1 >> print (a + b), (a+b), (a+ b), (a +b), "\n" >> >> [steve at sylar ~]$ ruby ws-example.rb >> 7773 > > Hmm. That's pretty nasty, all right. Not that Python can claim to be > immune to such behaviour: > >>>> 3 .real > 3 >>>> 3. real > File "", line 1 > 3. real > ^ > SyntaxError: invalid syntax > > > Though the fact that one of the cases raises an exception (rather than > silently giving some different behaviour) ameliorates things a bit. It ameliorates it *completely* -- you won't get silent errors in Python because you add or delete whitespace around a dot. "I find it amusing when novice programmers believe their main job is preventing programs from crashing. ... More experienced programmers realize that correct code is great, code that crashes could use improvement, but incorrect code that doesn't crash is a horrible nightmare." http://www.pphsg.org/cdsmith/types.html The edge case occurs because dot does double-duty as an operator and as part of float literals. However, float literals never include whitespace: >>> 1.5 1.5 >>> 1 . 5 File "", line 1 1 . 5 ^ SyntaxError: invalid syntax and likewise for 1. 5 and 1 .5 -- the only way to get a float literal with a decimal point is by not including whitespace in it. So there is never any ambiguity about floats. You can even do this: >>> 1.5.__str__() '1.5' And since . is an operator outside of float literals, you can do this: >>> import sys >>> sys . platform 'linux2' although why you'd want to escapes me :) This actually is a feature, since it is useful when calling methods on int literals. However this is a very rare thing to do. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:30:17 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:30:17 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b841bf1$0$1632$742ec2ed@news.sonic.net> Message-ID: On Tue, 23 Feb 2010 10:35:38 -0800, John Nagle wrote: > The issue being discussed was scaling Python for CPUs with many cores. > With Intel shipping 4 cores/8 hyperthread CPUs, the 6/12 part working, > and the 8/16 part coming along, this is more than a theoretical issue. Have you tried parallelpython? http://www.parallelpython.com/ -- Steven From lie.1296 at gmail.com Tue Feb 23 20:30:41 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 12:30:41 +1100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <4b848161$1@dnews.tpgi.com.au> On 02/24/10 12:08, Nobody wrote: > On Wed, 24 Feb 2010 12:22:05 +1300, Lawrence D'Oliveiro wrote: > >>> Java - The JVM code been hacked to death by Sun engineers (optimised) >>> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >>> ad-infinitum but nowhere as near to JVM >> >> Python is still faster, though. I think a key reason is that its VM supports >> reference-counting, which the Java folks never quite got the grasp of. > > So how does Python handle circular references? There is an optional garbage collector built into the interpreter. Look at here on how it works: http://python.ca/nas/python/gc/ From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:31:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:31:47 GMT Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On Tue, 23 Feb 2010 09:34:00 -0500, Jerry Hill wrote: > On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson > wrote: >> So what's the bottom line? This link notion is completely at odds with >> XP, and produces what I would call something of a mess to the unwary >> Python/W7 user. Is there a simple solution? > > I know people went off on a tangent talking about symbolic links and > hard links, but it is extremely unlikely that you created something like > that by accident. Windows just doesn't create those without you doing > quite a bit of extra work. It certainly doesn't create them when you > drag & drop files around through the normal interface. I find it far more likely that Windows 7 makes it easy for the user to accidentally produce links rather than copies, rather than that Python suddenly has developed a bug where it opens a completely different file to the one you ask for. But more likely still is some confusion regarding paths. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:38:38 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:38:38 GMT Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: On Wed, 24 Feb 2010 00:06:09 +0100, Daniel Fetchinson wrote: >> Hmm. I wonder if all the spam is coming from the NG side. I'll have >> to look at that. One of the reasons that I stopped reading UseNet over >> ten years ago was because of the diminishinig S/N ratio. I have always >> felt that it was a mistake to gateway this group. > > And this has to do with python programming in what way? I think the question of whether or not comp.lang.python is being spammed, and if so, what we can do about it, is a good question to raise on comp.lang.python. Where else do you think it should be discussed? -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:41:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:41:26 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > By the way, if you want the variables inside myDict to be free > variables, you have to add them to the local namespace. The local > namespace is also a dictionary "locals()". So you can update locals as > follows: > > locals().update( myDictionary ) No you can't. Try it inside a function. -- Steven From m.12ahesh at gmail.com Tue Feb 23 20:50:55 2010 From: m.12ahesh at gmail.com (all in one) Date: Tue, 23 Feb 2010 17:50:55 -0800 (PST) Subject: PAPER PRESENTATIONS AND SEMIMAR TOPICS. Message-ID: PAPER PRESENTATIONS AND SEMIMAR TOPICS. CHECK OUR VAST PAPER PRESENTATIONS AND SEMIMAR TOPICS INCLUDING PROJECTS FOR FREE AT http://presentationsandseminars.blogspot.com From ssteinerx at gmail.com Tue Feb 23 20:53:37 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 23 Feb 2010 20:53:37 -0500 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b841bf1$0$1632$742ec2ed@news.sonic.net> Message-ID: On Feb 23, 2010, at 8:30 PM, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 10:35:38 -0800, John Nagle wrote: > >> The issue being discussed was scaling Python for CPUs with many cores. >> With Intel shipping 4 cores/8 hyperthread CPUs, the 6/12 part working, >> and the 8/16 part coming along, this is more than a theoretical issue. > > Have you tried parallelpython? > > http://www.parallelpython.com/ I had not, have you used this successfully? Thanks, S From magawake at gmail.com Tue Feb 23 21:00:18 2010 From: magawake at gmail.com (Mag Gam) Date: Tue, 23 Feb 2010 21:00:18 -0500 Subject: compiling python question Message-ID: <1cbd6f831002231800gae705a9i48f781f7dec74ebe@mail.gmail.com> I am trying to compile python with Tk bindings. Do I need to do anything special for python to detect and enable Tk? This is mainly for matplotlib's TkAgg. It seems my compiled version of python isn't finding the module _tkagg From ldo at geek-central.gen.new_zealand Tue Feb 23 21:03:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 15:03:51 +1300 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: In message <6819f2f8-7a9e-4ea4-a936-c4e00394bd30 at g28g2000yqh.googlegroups.com>, vsoler wrote: > I'm trying to print .7 as 70% Just to be perverse: (lambda x : (lambda s : s[:s.index(".")] + s[s.index(".") + 1:] + "%")("%.2f" % x).lstrip("0"))(.7) :) From aahz at pythoncraft.com Tue Feb 23 21:04:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 18:04:49 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: Message-ID: In article , W. eWatson wrote: > >My claim is that if one creates a program in a folder that reads a file >in the folder it and then copies it to another folder, it will read the >data file in the first folder, and not a changed file in the new folder. >I'd appreciate it if some w7 users could try this, and let me know what >they find. > >My experience is that if one checks the properties of the copied file, >it will point to the original py file and execute it and not the copy. I've no time to verify your specific claim and have no readily available proof for mine, but I've seen similar issues on Win7. AFAIK, this has nothing to do with Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:07:42 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:07:42 GMT Subject: Is this secure? References: Message-ID: On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: > Hello, > > I need to generate passwords and I think that pseudo-random generator is > not good enough, frankly. So I wrote this function: [snip] > (yes I know that this way generated string will not contain 'z' because > 99/4 + 97 = 121 which is 'y') You're worried about the security of the PRNG but then generate a TWO to FIVE character lowercase password with no digits, punctuation or the letter 'z'? That's priceless! Python's PRNG is not suitable for producing cryptographically strong streams of random bytes, but it is perfectly strong enough for generating good passwords. > The question is: is this secure? No. You are wasting your time trying to fix something which isn't a problem, and introducing a much bigger problem instead. You are MUCH MUCH MUCH better off with a six or ten character password taken from upper and lowercase letters, plus digits, plus punctuation, than a four digit password taken from lowercase letters only. Even if the first case has some subtle statistical deviation from uniformity, and the second is "truly random" (whatever that means), it doesn't matter. Nobody is going to crack your password because the password generator is 0.01% more likely to generate a "G" than a "q". But they *will* brute- force your password if you have a four digit password taken from a-y only. > That is, can the string generated this > way be considered truly random? Define truly random. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:19:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:19:31 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 23 Feb 2010 11:19:59 -0800, Paul Rubin wrote: > mk writes: >> I need to generate passwords and I think that pseudo-random generator >> is not good enough, frankly. So I wrote this function:... The question >> is: is this secure? That is, can the string generated this way be >> considered truly random? (I abstract from not-quite-perfect nature of >> /dev/urandom at the moment; I can always switch to /dev/random which is >> better) > > urandom is fine and the entropy loss from the numeric conversions and > eliminating 'z' in that code before you get letters out is not too bad. What? You're going from a possible alphabet of 62 (excluding punctuation) or 94 (inc punctuation available on an American keyboard) distinct letters down to 25, and you say that's "not too bad"? Paul, if you were anyone else, I'd be sneering uncontrollably about now, but you're not clueless about cryptography, so what have I missed? Why is reducing the number of distinct letters by more than 50% anything but a disaster? This makes the task of brute-forcing the password exponentially easier. Add the fact that the passwords are so short (as little as two characters in my tests) and this is about as far from secure as it is possible to be. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:21:41 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:21:41 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b841bf1$0$1632$742ec2ed@news.sonic.net> Message-ID: On Tue, 23 Feb 2010 20:53:37 -0500, ssteinerX at gmail.com wrote: >> Have you tried parallelpython? >> >> http://www.parallelpython.com/ > > I had not, have you used this successfully? Not personally, no. -- Steven From lie.1296 at gmail.com Tue Feb 23 21:22:46 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 13:22:46 +1100 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: <4b848d96$1@dnews.tpgi.com.au> On 02/24/10 12:38, Steven D'Aprano wrote: > On Wed, 24 Feb 2010 00:06:09 +0100, Daniel Fetchinson wrote: > >>> Hmm. I wonder if all the spam is coming from the NG side. I'll have >>> to look at that. One of the reasons that I stopped reading UseNet over >>> ten years ago was because of the diminishinig S/N ratio. I have always >>> felt that it was a mistake to gateway this group. >> >> And this has to do with python programming in what way? > > > I think the question of whether or not comp.lang.python is being spammed, > and if so, what we can do about it, is a good question to raise on > comp.lang.python. > > Where else do you think it should be discussed? comp.lang.python.spam_prevention_discussion From george.sakkis at gmail.com Tue Feb 23 21:26:21 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Tue, 23 Feb 2010 18:26:21 -0800 (PST) Subject: When will Python go mainstream like Java? References: Message-ID: On Feb 23, 3:49?pm, mk wrote: > Well I for one wouldn't want Python to go exactly Java way, see this: > > http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=jav... > > This is the percentage of job offers in UK where the keyword "Java" appears. > > Same for C#, it looks like C# is eating Java's lunch now: > > http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csh... This seems to be a UK-specific trend; in the US (and most other countries I know of) Java is still going strong, e.g. http://www.indeed.com/jobtrends?q=java%2C+c%23&l= George From no.email at nospam.invalid Tue Feb 23 21:39:53 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 18:39:53 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: <7xbpff8ih2.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Paul, if you were anyone else, I'd be sneering uncontrollably about now, > but you're not clueless about cryptography, so what have I missed? Why is > reducing the number of distinct letters by more than 50% anything but a > disaster? This makes the task of brute-forcing the password exponentially > easier. Reducing the number of distinct letters by 50% decreases the entropy per character by 1 bit. That stuff about mixing letters and digits and funny symbols just makes the password a worse nuisance to remember and type, for a small gain in entropy that you can compute and make up for. The main thing you have to make sure is that the min-entropy is sufficient for your purposes, and it's generally more convenient to do that by making the password a little bit longer than by imposing contortions on the person typing it. Ross Anderson's "Security Engineering" chapter about passwords is worth reading too: http://www.cl.cam.ac.uk/~rja14/Papers/SE-03.pdf When I mentioned entropy loss to the OP though, I mostly meant loss from getting rid of the letter z. The (binary) Shannon entropy of the uniform probability distribution on 26 letters is 4.7004397 bits; on 25 letters, it's 4.6438561 bits. The difference isn't enough to give an attacker that much advantage. I like the diceware approach to passphrase generation and I've been using it for years. www.diceware.com explains it in detail and the docs there are quite well-thought-out and informative. Keep in mind that the entropy needed for an online password (attacker has to make a server query for every guess, and hopefully gets locked out after n wrong tries) and an offline one (attacker has something like a hash of the password and can run a completely offline search) are different. Here is a program that I use sometimes: from math import log dictfile = '/usr/share/dict/words' def genrandom(nbytes): with open('/dev/urandom') as f: return int(f.read(nbytes).encode('hex'), 16) def main(): wordlist = list(x.strip() for x in open(dictfile) if len(x) < 7) nwords = len(wordlist) print "%d words, entropy=%.3f bits/word"% ( nwords, log(nwords, 2)) print '-'.join(wordlist[genrandom(10)%nwords] for i in xrange(6)) main() From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:40:13 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:40:13 GMT Subject: Is this secure? References: Message-ID: On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: > The question is: is this secure? That is, can the string generated this > way be considered truly random? Putting aside the philosophical question of what "truly random" means, I presume you mean that the letters are uniformly distributed. The answer to that is, they don't like uniformly distributed. This isn't a sophisticated statistical test, it's the equivalent of a back-of-the-envelope calculation: I generated 100,000 random strings with your code, and counted how often each letter appears: If the letters are uniformly distributed, you would expect all the numbers to be quite close, but instead they range from 15063 to 25679: {'a': 15063, 'c': 20105, 'b': 15100, 'e': 25465, 'd': 25458, 'g': 25597, 'f': 25589, 'i': 25045, 'h': 25679, 'k': 22945, 'j': 25531, 'm': 16187, 'l': 16252, 'o': 16076, 'n': 16012, 'q': 16069, 'p': 16119, 's': 16088, 'r': 16087, 'u': 15951, 't': 16081, 'w': 16236, 'v': 15893, 'y': 15834, 'x': 15956} Eye-balling it, it looks vaguely two-humped, one hump around 15-16K, the second around 22-25K. Sure enough, here's a quick-and-dirty graph: a | *********************************** b | *********************************** c | *********************************************** d | *********************************************************** e | *********************************************************** f | ************************************************************ g | ************************************************************ h | ************************************************************ i | *********************************************************** j | ************************************************************ k | ****************************************************** l | ************************************** m | ************************************** n | ************************************* o | ************************************** p | ************************************** q | ************************************** r | ************************************** s | ************************************** t | ************************************** u | ************************************* v | ************************************* w | ************************************** x | ************************************* y | ************************************* The mean of the counts is 19056.72, and the mean deviation is 3992.28. While none of this is statistically sophisticated, it does indicate to me that your function is nowhere even close to uniform. It has a very strong bias. -- Steven From no.email at nospam.invalid Tue Feb 23 21:41:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 18:41:59 -0800 Subject: Is this secure? References: Message-ID: <7x7hq38idk.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Putting aside the philosophical question of what "truly random" means, I > presume you mean that the letters are uniformly distributed. The answer > to that is, they don't like uniformly distributed. That is a good point, the way those letters are generated (through the decimal conversion stuff), they won't be all that uniform. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:43:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:43:05 GMT Subject: Is this secure? References: Message-ID: On Wed, 24 Feb 2010 02:40:13 +0000, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: > >> The question is: is this secure? That is, can the string generated this >> way be considered truly random? > > Putting aside the philosophical question of what "truly random" means, I > presume you mean that the letters are uniformly distributed. The answer > to that is, they don't like uniformly distributed. Er, they don't *look* uniformly distributed. (Of course, being random, perhaps they are and I just got unlucky.) -- Steven From no.email at nospam.invalid Tue Feb 23 21:50:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 18:50:52 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: <7x3a0r8hyr.fsf@ruckus.brouhaha.com> mk writes: >> You might look at the sitewww.diceware.comfor an approach to this, >> which you can implement with a program. ?The docs there are pretty >> thoughtful and may help you understand the relevant issues. > > Thanks. But I would also be grateful for indicating what is wrong/ugly > in my code. The stuff about converting 4 random bytes to a decimal string and then peeling off 2 digits at a time is pretty awful, and notice that since 2**32 is 4294967296, in the cases where you get 10 digits, the first 2-digit pair is never higher than 42. There are also some effects on the lower digits. The total entropy loss probably isn't fatal but as described, it's ugly. I'd write your code something like this: nletters = 5 def randomword(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a')+ord(c)%26) for c in f.read(n)]) print randomword(nletters) I wouldn't rely on a 5 letter combination for a high security application, but it might be ok for some low security purposes. Two random 5-letter combinations separated by a hyphen will be much better, and is probably easier to type than a solid block of 10 letters. From robert.kern at gmail.com Tue Feb 23 21:52:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 20:52:23 -0600 Subject: Spam from gmail (Was: fascism) In-Reply-To: <4b848d96$1@dnews.tpgi.com.au> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: On 2010-02-23 20:22 , Lie Ryan wrote: > On 02/24/10 12:38, Steven D'Aprano wrote: >> On Wed, 24 Feb 2010 00:06:09 +0100, Daniel Fetchinson wrote: >> >>>> Hmm. I wonder if all the spam is coming from the NG side. I'll have >>>> to look at that. One of the reasons that I stopped reading UseNet over >>>> ten years ago was because of the diminishinig S/N ratio. I have always >>>> felt that it was a mistake to gateway this group. >>> >>> And this has to do with python programming in what way? >> >> >> I think the question of whether or not comp.lang.python is being spammed, >> and if so, what we can do about it, is a good question to raise on >> comp.lang.python. >> >> Where else do you think it should be discussed? > > comp.lang.python.spam_prevention_discussion Which doesn't exist and never will. Sorry, but meta-discussions about the group are typically on-topic for all groups with some few exceptions (e.g. non-discussion, binary-only groups with associated .d groups, for instance). -- 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 Feb 23 22:09:36 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 21:09:36 -0600 Subject: Is this secure? In-Reply-To: References: Message-ID: On 2010-02-23 20:43 , Steven D'Aprano wrote: > On Wed, 24 Feb 2010 02:40:13 +0000, Steven D'Aprano wrote: > >> On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: >> >>> The question is: is this secure? That is, can the string generated this >>> way be considered truly random? >> >> Putting aside the philosophical question of what "truly random" means, I >> presume you mean that the letters are uniformly distributed. The answer >> to that is, they don't like uniformly distributed. > > Er, they don't *look* uniformly distributed. > > (Of course, being random, perhaps they are and I just got unlucky.) You'd have to be very, *very* unlucky to get a sample of that size so far from uniformly distributed if the generating process actually were uniform. Of course, uniformity isn't really necessary. You just need enough entropy in the distribution (amongst other things like protection of the seed from being known or guessed). A skewed distribution of characters is perfectly fine provided that you had enough characters in the password to meet the desired entropy requirement. A skewed distribution does require more characters to meet a specified entropy requirement than a uniform distribution, of course. That said, for a naive strategy like "pick an independent random character, repeat", you should just use a uniform distribution. It makes the analysis easier. Worthwhile generators that give skewed distributions usually do so for a good reason, like generating pronounceable passwords. -- 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 lie.1296 at gmail.com Tue Feb 23 22:41:26 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 14:41:26 +1100 Subject: Is this secure? In-Reply-To: References: Message-ID: <4b84a006$1@dnews.tpgi.com.au> On 02/24/10 14:09, Robert Kern wrote: > On 2010-02-23 20:43 , Steven D'Aprano wrote: >> On Wed, 24 Feb 2010 02:40:13 +0000, Steven D'Aprano wrote: >> >>> On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: >>> >>>> The question is: is this secure? That is, can the string generated this >>>> way be considered truly random? >>> >>> Putting aside the philosophical question of what "truly random" means, I >>> presume you mean that the letters are uniformly distributed. The answer >>> to that is, they don't like uniformly distributed. >> >> Er, they don't *look* uniformly distributed. >> >> (Of course, being random, perhaps they are and I just got unlucky.) > > You'd have to be very, *very* unlucky to get a sample of that size so > far from uniformly distributed if the generating process actually were > uniform. > > Of course, uniformity isn't really necessary. You just need enough > entropy in the distribution (amongst other things like protection of the > seed from being known or guessed). A skewed distribution of characters > is perfectly fine provided that you had enough characters in the > password to meet the desired entropy requirement. A skewed distribution > does require more characters to meet a specified entropy requirement > than a uniform distribution, of course. > > That said, for a naive strategy like "pick an independent random > character, repeat", you should just use a uniform distribution. It makes > the analysis easier. Worthwhile generators that give skewed > distributions usually do so for a good reason, like generating > pronounceable passwords. If an attacker knows the that the random number generator have an extreme skew and he knows the distribution of the letters, how much advantage would it give the attacker? My initial guess is that the more skewed the letters are, the better the advantage, since an attacker using brute-force can write his program to prefer the most likely letters? From luismgz at gmail.com Tue Feb 23 22:47:22 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 19:47:22 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 10:41?pm, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > > By the way, if you want the variables inside myDict to be free > > variables, you have to add them to the local namespace. The local > > namespace is also a dictionary "locals()". So you can update locals as > > follows: > > > ? ? locals().update( myDictionary ) > > No you can't. Try it inside a function. > > -- > Steven Sure. Inside a function I would use globals() instead. Although I don't know if it would be a good practice... Luis From no.email at nospam.invalid Tue Feb 23 22:51:53 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 19:51:53 -0800 Subject: Is this secure? References: <4b84a006$1@dnews.tpgi.com.au> Message-ID: <7xwry39tpi.fsf@ruckus.brouhaha.com> Lie Ryan writes: > If an attacker knows the that the random number generator have an > extreme skew and he knows the distribution of the letters, how much > advantage would it give the attacker? My initial guess is that the more > skewed the letters are, the better the advantage, since an attacker > using brute-force can write his program to prefer the most likely letters? A useable (conservative) estimate is that the attacker's workload is 1/p where p is the probability of the most likely password. That basically says the password strength can be measured by the min-entropy. Cryptographers often use that approach. If you want to be more precise, you can do a conditional probability calculation assuming the attacker works down the list of possible passwords in order of decreasing probability, stopping when they hit the right one. More generally still, passwords regardless of their entropy content are a sucky way to encapsulate cryptographic secrets. We keep using them because every alternative has drawbacks of its own. From rpdooling at gmail.com Tue Feb 23 22:53:03 2010 From: rpdooling at gmail.com (Rick Dooling) Date: Tue, 23 Feb 2010 19:53:03 -0800 (PST) Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: On Feb 23, 1:08?pm, Gib Bogle wrote: > It isn't useful to respond to a serious question with OS bigotry. Okay, I'll go with what Aahz said: > I've seen similar issues on Win7. > AFAIK, this has nothing to do with Python. From invalid at invalid.invalid Tue Feb 23 23:09:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 24 Feb 2010 04:09:18 +0000 (UTC) Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: On 2010-02-24, Robert Kern wrote: >> comp.lang.python.spam_prevention_discussion > > Which doesn't exist and never will. Sorry, but > meta-discussions about the group are typically on-topic for > all groups with some few exceptions (e.g. non-discussion, > binary-only groups with associated .d groups, for instance). Since now we are discussing meta-discussions, is this now a meta-meta-discussion? -- Grant From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 23:15:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 04:15:31 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > On Feb 23, 10:41?pm, Steven D'Aprano > wrote: >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: >> > By the way, if you want the variables inside myDict to be free >> > variables, you have to add them to the local namespace. The local >> > namespace is also a dictionary "locals()". So you can update locals >> > as follows: >> >> > ? ? locals().update( myDictionary ) >> >> No you can't. Try it inside a function. >> >> -- >> Steven > > Sure. Inside a function I would use globals() instead. Although I don't > know if it would be a good practice... Er, how does using globals change the local variables? -- Steven From wolftracks at invalid.com Tue Feb 23 23:16:37 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 20:16:37 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA In-Reply-To: References: Message-ID: <4B84A825.1030407@invalid.com> On 2/23/2010 2:50 PM, Aahz wrote: > In article, > W. eWatson wrote: >> >> Anyone here going to the meeting,Subject? As far as I can tell, it meets >>from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >> be an informal group dinner at 6 pm at some place yet unknown. Comments? > > Subscribe to http://mail.python.org/mailman/listinfo/baypiggies Thanks. I'd appreciate it if you tell me what topic is. I belong to too many mail lists. Thursday will be my first meeting. Perhaps I'll change my mind about ML after a meeting. Can you describe anything more than the topic? Do they have books, videos, tutorials (live), casual Q/A, person-to-person chat before the speaker? From wolftracks at invalid.com Tue Feb 23 23:16:51 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 20:16:51 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA In-Reply-To: References: Message-ID: On 2/23/2010 2:50 PM, Aahz wrote: > In article, > W. eWatson wrote: >> >> Anyone here going to the meeting,Subject? As far as I can tell, it meets >>from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >> be an informal group dinner at 6 pm at some place yet unknown. Comments? > > Subscribe to http://mail.python.org/mailman/listinfo/baypiggies Thanks. I'd appreciate it if you tell me what topic is. I belong to too many mail lists. Thursday will be my first meeting. Perhaps I'll change my mind about ML after a meeting. Can you describe anything more than the topic? Do they have books, videos, tutorials (live), casual Q/A, person-to-person chat before the speaker? From luismgz at gmail.com Tue Feb 23 23:44:10 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 20:44:10 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> On Feb 24, 1:15?am, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > > On Feb 23, 10:41?pm, Steven D'Aprano > > wrote: > >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > >> > By the way, if you want the variables inside myDict to be free > >> > variables, you have to add them to the local namespace. The local > >> > namespace is also a dictionary "locals()". So you can update locals > >> > as follows: > > >> > ? ? locals().update( myDictionary ) > > >> No you can't. Try it inside a function. > > >> -- > >> Steven > > > Sure. Inside a function I would use globals() instead. Although I don't > > know if it would be a good practice... > > Er, how does using globals change the local variables? > > -- > Steven Hmmm.... well, you tell me! As I said, I don't know if this is the recomended way... Luis From ldo at geek-central.gen.new_zealand Tue Feb 23 23:48:59 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 17:48:59 +1300 Subject: Is this secure? References: <4b84a006$1@dnews.tpgi.com.au> <7xwry39tpi.fsf@ruckus.brouhaha.com> Message-ID: In message <7xwry39tpi.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > More generally still, passwords regardless of their entropy content are > a sucky way to encapsulate cryptographic secrets. They?re a shared secret. How else would you represent a shared secret, if not with a shared secret? From loudoillond522 at gmail.com Wed Feb 24 00:27:52 2010 From: loudoillond522 at gmail.com ("Lou " Shy Amateur Strips) Date: Tue, 23 Feb 2010 21:27:52 -0800 (PST) Subject: %%% daughter fucked her x-boy friend in front of her father %%% " FREE Live shows also available" Message-ID: <8895961a-dec1-4e4e-95a5-0b116fbec24c@e19g2000prn.googlegroups.com> %%% daughter fucked her x-boy friend in front of her father %%% " FREE Live shows also available" http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ From aahz at pythoncraft.com Wed Feb 24 01:03:41 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 22:03:41 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA References: <4B84A825.1030407@invalid.com> Message-ID: In article <4B84A825.1030407 at invalid.com>, W. eWatson wrote: >On 2/23/2010 2:50 PM, Aahz wrote: >> In article, >> W. eWatson wrote: >>> >>> Anyone here going to the meeting,Subject? As far as I can tell, it meets >>>from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >>> be an informal group dinner at 6 pm at some place yet unknown. Comments? >> >> Subscribe to http://mail.python.org/mailman/listinfo/baypiggies > >Thanks. I'd appreciate it if you tell me what topic is. I belong to too >many mail lists. Thursday will be my first meeting. Perhaps I'll change >my mind about ML after a meeting. Can you describe anything more than >the topic? Do they have books, videos, tutorials (live), casual Q/A, >person-to-person chat before the speaker? Sorry, I don't know offhand; using the mailing list is your best bet. (BayPIGgies is usually not a high-traffic list.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From mattbarkan at gmail.com Wed Feb 24 01:07:48 2010 From: mattbarkan at gmail.com (MattB) Date: Tue, 23 Feb 2010 22:07:48 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <4b807791$0$8819$c3e8da3@news.astraweb.com> Message-ID: <99bd0874-3462-4bb3-8c3c-54b73c88f9a6@q16g2000yqq.googlegroups.com> On Feb 20, 7:00?pm, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 18:28:16 +0000, Martin P. Hellwig wrote: > > On 02/20/10 00:20, MattB wrote: > > > > >> Also, based on Martin's comment, I just wanted to make you all aware > >> that I intend no misuse, but rather am just trying to learn, as I'm a > >> programming noob. > > > > It wasn't my intention to imply that, rather the opposite, that if some > > BOFH would see your action as misuse (some admins are pretty trigger > > happy), you would expect them to contact you directly (I would). Even > > though you are on a wireless there are ways to track you down. For > > example I would search my log to see if I can make an association > > between a login to one of my servers and your mac address. > > This may be what you would do, but in my experience, it is more likely > that the admin would be far too busy and/or lazy to try to track you down > unless (1) they wanted to give you a warning prior to expulsion, or (2) > they needed to know who you were prior to laying charges. > > In my experience they're far more likely to just hit the problem with a > hammer by blocking you as much as is technically possible. > > > BTW, I always followed the philosophy that learning is much more fun if > > you can brake/blow something up. Thus on my networks all students had a > > lot of freedom to do whatever they think was appropriate but they where > > aware that every action on my network was monitored and logged. > > Unfortunately this is the exception rather than the rule, I think. > > -- > Steven All -- problem solved. Following Lie's suggestions, and the links from those pages, I went hunting around in my /library/preferences/ SystemConfiguration/. I opened all of the 6 or 7 files that were in there, and all looked as if they contained info directly related to my airport card -- networks, server names, etc. So I copied them to a backup folder and then deleted them. Then I rebooted. Then I opened IDLE and was able to raise URLs again. I'm not sure what it was about those files (or maybe a specific one) -- does anyone have any ideas? Thanks for your help and suggestions while I tried to figure this out. From sjdevnull at yahoo.com Wed Feb 24 01:31:59 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Tue, 23 Feb 2010 22:31:59 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: <6d75d20c-4028-42ef-9c45-ad118e315139@z11g2000yqz.googlegroups.com> On Feb 23, 8:03?pm, Nobody wrote: > On Mon, 22 Feb 2010 22:27:54 -0800, sjdevn... at yahoo.com wrote: > > Basically, multiprocessing is always hard--but it's less hard to start > > without shared everything. ?Going with the special case (sharing > > everything, aka threading) is by far the stupider and more complex way > > to approach multiprocssing. > > Multi-threading hardly shares anything (only dynamically-allocated > and global data), while everything else (the entire stack) is per-thread. > > Yeah, I'm being facetious. Slightly. I'm afraid I may be missing the facetiousness here. The only definitional difference between threads and processes is that threads share memory, while processes don't. There are often other important practical implementation details, but sharing memory vs not sharing memory is the key theoretical distinction between threads and processes. On most platforms, whether or not you want to share memory (and abandon memory protection wrt the rest of the program) is the key factor a programmer should consider when deciding between threads and processes--the only time that's not true is when the implementation forces ancillary details upon you. From enleverLesX_XXmcX at XmclavXeauX.com.invalid Wed Feb 24 01:41:50 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Wed, 24 Feb 2010 07:41:50 +0100 Subject: python shell crashing on paste References: <1ede46e4-8ca1-4fe0-ad3f-7e781bbe1182@b36g2000pri.googlegroups.com> Message-ID: <4b84ca31$0$15832$ba4acef3@reader.news.orange.fr> Hi! Where (directory) are you, when the problem come? Have you try with UAC disabled? @+ -- MCI From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 02:08:19 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 07:08:19 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. Gonz?lez wrote: > On Feb 24, 1:15?am, Steven D'Aprano > wrote: >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: >> > On Feb 23, 10:41?pm, Steven D'Aprano >> > wrote: >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: >> >> > By the way, if you want the variables inside myDict to be free >> >> > variables, you have to add them to the local namespace. The local >> >> > namespace is also a dictionary "locals()". So you can update >> >> > locals as follows: >> >> >> > ? ? locals().update( myDictionary ) >> >> >> No you can't. Try it inside a function. >> >> >> -- >> >> Steven >> >> > Sure. Inside a function I would use globals() instead. Although I >> > don't know if it would be a good practice... >> >> Er, how does using globals change the local variables? >> >> -- >> Steven > > Hmmm.... well, you tell me! I'm not the one that said you can update locals! You said it. I said you can't, because you *can't*. The docs warn that you can't change locals, and if you try it, you will see that the docs are right. >>> def test(): ... x = 1 ... locals().update(x = 2) ... print x ... >>> >>> test() 1 > As I said, I don't know if this is the recomended way... It's not recommended because it doesn't work. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 02:11:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 07:11:01 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7xbpff8ih2.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 23 Feb 2010 18:39:53 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> Paul, if you were anyone else, I'd be sneering uncontrollably about >> now, but you're not clueless about cryptography, so what have I missed? >> Why is reducing the number of distinct letters by more than 50% >> anything but a disaster? This makes the task of brute-forcing the >> password exponentially easier. > > Reducing the number of distinct letters by 50% decreases the entropy per > character by 1 bit. You say that as if 1 bit of entropy isn't much :) Given a random six character password taken out of an alphabet of 52 characters, it takes over nine billion attempts to brute force it. Reducing the alphabet by 50% cuts that down to less than 200 million. To make up for that loss of 1 bit of entropy, you need two extra characters in your password. > That stuff about mixing letters and digits and > funny symbols just makes the password a worse nuisance to remember and > type, for a small gain in entropy that you can compute and make up for. Well, everybody has their own ways of remembering passwords, and I'd much prefer to remember an eight character password with "funny symbols" that I chose myself, than a six character password with nothing but letters that was chosen for me. Of course, I flatter myself that I know how to choose good passwords, and I hate remembering long random strings even from a reduced alphabet (e.g. I hate memorizing eight digit phone numbers, and am completely incapable of remembering ten digit mobile phone numbers). -- Steven From no.email at nospam.invalid Wed Feb 24 02:58:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 23:58:30 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7xbpff8ih2.fsf@ruckus.brouhaha.com> Message-ID: <7xljejgj4p.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Given a random six character password taken out of an alphabet of 52 > characters, it takes over nine billion attempts to brute force it. > Reducing the alphabet by 50% cuts that down to less than 200 million. To > make up for that loss of 1 bit of entropy, you need two extra characters > in your password. One extra character comes pretty close (within 1.3 bits). Even two extra chars is probably (subjective) easier for a user to deal with than a completely random mixture of upper/lower case. You don't get the extra bit per character if that distribution is anything other than random, of course. For something like a web password (each guess takes a server hit), where the resource guarded is not very valuable, 5 chars is probably enough for most purposes. For something like an encryption key subject to offline attacks, 6 mixed-case characters will barely slow a real attacker down. As before, my suggestion is still diceware. I've used random alphanumerics in the past but they're too big a hassle, they have to be written down, etc. And of course, if you're doing something serious, use a hardware token. From danijel.gvero at gmail.com Wed Feb 24 03:28:12 2010 From: danijel.gvero at gmail.com (DANNY) Date: Wed, 24 Feb 2010 00:28:12 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> <19c11c1f-d70e-4b10-b425-6e65d4c70aeb@d2g2000yqa.googlegroups.com> Message-ID: <3299bfaf-e8d9-4340-a339-e8a8d31c2fa9@f42g2000yqn.googlegroups.com> On Feb 24, 3:11?am, "Rhodri James" wrote: > On Tue, 23 Feb 2010 10:39:21 -0000, DANNY wrote: > > @James I am thinkinhg about effect of errors that are within the > > sequence of P frames. Where the P frames have only the information > > about the changes in previous frames, so that errors are present until > > the next Iframe. So I would like to see how is this seen in different > > GoP sized clips. > > Ah, I see. ?What I'd suggest you do is to encode your video clip at ? > various GOP sizes (you'll want some quite extreme ones for comparison), ? > then write a little program that reads in the file byte by byte and ? > randomly corrupts the data as it goes through. ?"tsplay" from the tstools ? > suite that I mentioned earlier will do that for you (because it was very ? > handy for testing the robustness of our decoders). ?Then watch the results ? > using VLC or similar. > > My recollection is that when the image isn't static, P frames tend to have ? > enough intra-coded blocks that corrupted video data doesn't have as much ? > effect as you might think. ?I've dealt with streams that had ten seconds ? > or more between I frames, and starting at a random spot (simulating ? > changing channel on your digital TV) builds up an intelligible (if ? > obviously wrong) image surprisingly quickly. > > PS: my first name is Rhodri, not James. ?Don't worry, it catches a lot of ? > people out. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses Well for my simulation of errors I am thinking on using the WANem (Wide Area Netwrok Emulator) which has a function to simulate dellay, jitter etc.. http://wanem.sourceforge.net/ I have been downloading the clips from youtube and I surprisengly saw that I frame occures after 300 frames(at 15fps-so that means after 20 seconds)! That was quite unusal for my perception of the purpose of I frame, but then I figured out that (as you mentioned) P frames include intra-coded blocks which hide the effect of the errors. The goal of my project is to make a program which plays the corrupted video after being out thru error concealment, and in case when errors overcome some threshold error value the program doesn't paly any more frames until the I frame occures and then I would figure out the optimal threshold value for the different GoP sizes as well as different content of the clip. From greg.ewing at canterbury.ac.nz Wed Feb 24 03:33:44 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 24 Feb 2010 21:33:44 +1300 Subject: ANN: Pyrex 0.9.8.6 Message-ID: Pyrex 0.9.8.6 is now available: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ Numerous bug fixes and a few improvements. See the CHANGES page on the web site for details. What is Pyrex? -------------- Pyrex is a language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. From baptiste.lepilleur at gmail.com Wed Feb 24 03:37:19 2010 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Wed, 24 Feb 2010 09:37:19 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? Message-ID: I stumbled uppon this and find it somewhat odd: some class methods of TarFile and TarInfo do not appears in either the online documentation or search while they have a doc string: http://docs.python.org/search.html?q=gzopen http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile See script at the end for list of class methods. Is this "by design" or is there some an odd bug in doc generation lurking around? This somehow seem to be specific to module tarfile. Fraction classmethod from_float() is available in the documentation and found by a search for example... --- Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tarfile >>> help( tarfile.TarFile.gzopen ) Help on method gzopen in module tarfile: gzopen(cls, name, mode='r', fileobj=None, compresslevel=9, **kwargs) method of __builtin__.type instance Open gzip compressed tar archive name for reading or writing. Appending is not allowed. >>> help( tarfile.TarFile.bz2open ) Help on method bz2open in module tarfile: bz2open(cls, name, mode='r', fileobj=None, compresslevel=9, **kwargs) method of __builtin__.type instance Open bzip2 compressed tar archive name for reading or writing. Appending is not allowed. >>> help( tarfile.TarInfo.create_pax_global_header ) Help on method create_pax_global_header in module tarfile: create_pax_global_header(cls, pax_headers) method of __builtin__.type instance Return the object as a pax global header block sequence. Baptiste. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kidhvfhgi at gmail.com Wed Feb 24 03:58:46 2010 From: kidhvfhgi at gmail.com (hhuifhiu ijuihuh) Date: Wed, 24 Feb 2010 00:58:46 -0800 (PST) Subject: Watch nude girls fucking and sucking the cocks. Girls shaving their pussies, boys giving shots on the pussies and licking them. Also watch girls getting fucked on a car roof, a girl banged by a gang of four members. At the end the girl collect Message-ID: <3b25b8ae-1917-43ce-b3fa-098a83e41ad5@k5g2000pra.googlegroups.com> Watch nude girls fucking and sucking the cocks. Girls shaving their pussies, boys giving shots on the pussies and licking them. Also watch girls getting fucked on a car roof, a girl banged by a gang of four members. At the end the girl collects sperms from all four mens penis in her mouth and swallows it. http://sites.google.com/site/niceglamourz http://sites.google.com/site/niceglamourz http://sites.google.com/site/niceglamourz From dieter at handshake.de Wed Feb 24 04:11:25 2010 From: dieter at handshake.de (Dieter Maurer) Date: 24 Feb 2010 10:11:25 +0100 Subject: Use eval() safely? In-Reply-To: References: <7uejcjFgf6U1@mid.individual.net> Message-ID: Steven D'Aprano writes on 22 Feb 2010 06:07:05 GMT: > ... > It's *especially* not safe if you put nothing in the globals dict, > because Python kindly rectifies that by putting the builtins into it: > > >>> eval("__builtins__.keys()", {}, {}) > ['IndexError', 'all', 'help', 'vars', ... 'OverflowError'] > > > >>> eval("globals()", {}, {}) > {'__builtins__': {...}} > >>> > >>> eval("globals()", {'__builtins__': None}, {}) > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in > NameError: name 'globals' is not defined > > So {'__builtins__': None} is safer than {}. Still not safe, exactly, but > safer. Or at least you make the Black Hats work harder before they own > your server :) Using functionality introduced with the class/type homogenization, it is quite easy to get access to the "file" type (even when "__builtins__" is disabled). Having "file", arbitrary files can be read, written, destroyed... Dieter From eckhardt at satorlaser.com Wed Feb 24 04:15:17 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 24 Feb 2010 10:15:17 +0100 Subject: while loop with the condition used in the body Message-ID: <6a7f57-hj1.ln1@satorlaser.homedns.org> Hi! I'm looking for a way to write code similar to this C code: while(rq = get_request(..)) { handle_request(rq); } Currently I'm doing while True: rq = get_request(...) if not rq: break handle_request(rq) in Python 2.6. Any suggestions how to rewrite that? Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From jeanmichel at sequans.com Wed Feb 24 04:17:23 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Feb 2010 10:17:23 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <4B84EEA3.2090104@sequans.com> Arnaud Delobelle wrote: > lallous writes: > > >> Hello >> >> How can I do something similar to pure virtual functions in C++ ? >> >> Let us consider this: >> >> class C1: >> >> # Pure virtual >> def cb(self, param1, param2): >> """ >> This is a callback >> >> @param param1: ... >> @param param2: ... >> """ >> raise NotImplementedError, "Implement me" >> > > Why define it if it is virtual? > Slightly off topic but this is often useful when writing interfaces. You can then properly document what should any subclass (interface implemention) be doing. The thing is that in case of virtual methods, you *do want* to raise the notImplemented exceptions, meaning you've failed to implement all the required methods. Strange thing that the OP want to silently call nothing at all when calling a virtual method, he looses all the benefits from a virtual design. Anyway, I don't deal into code optimization, this is not healthy :-) JM From nandini.sharma84 at gmail.com Wed Feb 24 04:18:18 2010 From: nandini.sharma84 at gmail.com (nandini) Date: Wed, 24 Feb 2010 01:18:18 -0800 (PST) Subject: Why One Should Go for Online Tech Support Message-ID: Being a computer user, you almost every day make calls to your local technician to repair your day to day PC problems such as operating system issues, computer security problem, browser & email issues, network and peripheral support. But hardly have you got your computer repaired right away and even if your computer gets repaired immediately, you cannot be assured of the quality of service provided. And most importantly, like every other machine, computers too need regular maintenance but a local technician cannot promise for the same. Apart from this, you would have to pay your tech support provider for his every visit, which sums up a heavy amount; sometimes going beyond the limitation of your budget. At the point in time, you must consider availing an online tech support service. Offered on onetime payment scheme, online tech support services are provided by numerous companies all across the globe. These companies hire eminent Microsoft certified engineers as technicians, who offer best services within moments. Including this, there are many more benefits of services offered by online tech support providers, such as ? * An inclusive range of tech support services on much lower prices. * Complete maintenance of your computer * A completely secured support * Instant fix for your computer For Further information please visit http://www.pccare247.com From arnodel at googlemail.com Wed Feb 24 05:07:00 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 24 Feb 2010 02:07:00 -0800 (PST) Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: <1909640d-b6d2-43df-bcee-ae523d92f3bc@l19g2000yqb.googlegroups.com> Ulrich Eckhardt wrote: > Hi! > > I'm looking for a way to write code similar to this C code: > > while(rq = get_request(..)) { > handle_request(rq); > } > > Currently I'm doing > > while True: > rq = get_request(...) > if not rq: > break > handle_request(rq) > > in Python 2.6. Any suggestions how to rewrite that? > This is the common idiom. -- Arnaud From lars at gustaebel.de Wed Feb 24 05:14:24 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Wed, 24 Feb 2010 11:14:24 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: References: Message-ID: <20100224101423.GA27668@axis.g33x.de> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: > I stumbled uppon this and find it somewhat odd: some class methods of > TarFile and TarInfo do not appears in either the online documentation or > search while they have a doc string: > > http://docs.python.org/search.html?q=gzopen > http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile > > See script at the end for list of class methods. > > Is this "by design" or is there some an odd bug in doc generation lurking > around? This somehow seem to be specific to module tarfile. Fraction > classmethod from_float() is available in the documentation and found by a > search for example... First of all, Python's module documentation is not generated from module docstrings, each module has its own rst text file in the documentation tree instead. But to answer your question: Yes, this is intentional. The TarFile class has three classmethods taropen(), gzopen(), and bz2open() each for a specific compression method. These three are used internally by the TarFile.open() classmethod and are not intended to be called directly. The TarFile.open() method is the one that is publicly documented and supposed to be used. It decides which of the three methods to use based on the mode argument and does many more other high-level things as well. Regards, -- Lars Gust?bel lars at gustaebel.de I do not care to belong to a club that accepts people like me as members. (Groucho Marx) From __peter__ at web.de Wed Feb 24 05:21:36 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Feb 2010 11:21:36 +0100 Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Ulrich Eckhardt wrote: > I'm looking for a way to write code similar to this C code: > > while(rq = get_request(..)) { > handle_request(rq); > } > > Currently I'm doing > > while True: > rq = get_request(...) > if not rq: > break > handle_request(rq) > > in Python 2.6. Any suggestions how to rewrite that? Assuming get_request(...) is called with the same arguments on each iteration and uses None to signal that there is no more data: from functools import partial for rq in iter(partial(get_request, ...), None): handle_request(rq) Peter From jeanmichel at sequans.com Wed Feb 24 05:28:13 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Feb 2010 11:28:13 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4B84FF3D.1010403@sequans.com> Michael Rudolf wrote: > Just a quick question about what would be the most pythonic approach > in this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > > >>> def a(): > pass > >>> def a(x): > pass > >>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > > >>> def a(x=None): > if x is None: > pass > else: > pass > > ? > > Thanks, > Michael This is the way to do it python, and it has its advantages: 1 docstring, 1 way do do it, 1 interface. JM From duncan.booth at invalid.invalid Wed Feb 24 05:31:48 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 24 Feb 2010 10:31:48 GMT Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Peter Otten <__peter__ at web.de> wrote: > Ulrich Eckhardt wrote: > >> I'm looking for a way to write code similar to this C code: >> >> while(rq = get_request(..)) { >> handle_request(rq); >> } >> > Assuming get_request(...) is called with the same arguments on each > iteration and uses None to signal that there is no more data: > > from functools import partial > > for rq in iter(partial(get_request, ...), None): > handle_request(rq) > > Peter and the next step on from this is to realise that the problem isn't how to code the calls to get_request(), the problem is actually that get_request() itself isn'ty Pythonic. Rewrite it as a generator, rename it to reflect that it now generates a sequence of requests and the code becomes: for rq in incoming_requests(...): handle_request(rq) -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Wed Feb 24 05:38:33 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Feb 2010 11:38:33 +0100 Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: > >> Ulrich Eckhardt wrote: >> >>> I'm looking for a way to write code similar to this C code: >>> >>> while(rq = get_request(..)) { >>> handle_request(rq); >>> } >>> >> Assuming get_request(...) is called with the same arguments on each >> iteration and uses None to signal that there is no more data: >> >> from functools import partial >> >> for rq in iter(partial(get_request, ...), None): >> handle_request(rq) >> >> Peter > > and the next step on from this is to realise that the problem isn't how to > code the calls to get_request(), the problem is actually that > get_request() itself isn'ty Pythonic. Rewrite it as a generator, rename it > to reflect that it now generates a sequence of requests and the code > becomes: > > for rq in incoming_requests(...): > handle_request(rq) ...and a likely implementation would be def incoming_requests(...): while True: rq = ... # inlined version of get_request() if not rq: break yield rq In other words: It's turtles all the way down... Peter From luismgz at gmail.com Wed Feb 24 05:44:52 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 24 Feb 2010 02:44:52 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> Message-ID: On Feb 24, 4:08?am, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. Gonz?lez wrote: > > On Feb 24, 1:15?am, Steven D'Aprano > > wrote: > >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > >> > On Feb 23, 10:41?pm, Steven D'Aprano > >> > wrote: > >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > >> >> > By the way, if you want the variables inside myDict to be free > >> >> > variables, you have to add them to the local namespace. The local > >> >> > namespace is also a dictionary "locals()". So you can update > >> >> > locals as follows: > > >> >> > ? ? locals().update( myDictionary ) > > >> >> No you can't. Try it inside a function. > > >> >> -- > >> >> Steven > > >> > Sure. Inside a function I would use globals() instead. Although I > >> > don't know if it would be a good practice... > > >> Er, how does using globals change the local variables? > > >> -- > >> Steven > > > Hmmm.... well, you tell me! > > I'm not the one that said you can update locals! You said it. I said you > can't, because you *can't*. The docs warn that you can't change locals, > and if you try it, you will see that the docs are right. > > >>> def test(): > > ... ? ? x = 1 > ... ? ? locals().update(x = 2) > ... ? ? print x > ... > > >>> test() > > 1 > > > As I said, I don't know if this is the recomended way... > > It's not recommended because it doesn't work. > > -- > Steven I guess I have to check the docs... Anyway, nobody wanted to update locals() from within a function here. Doing it outside of a function seems to work. And updating globals() works in any case, which is what the OP seems to need. Isn't it? Luis From luismgz at gmail.com Wed Feb 24 05:58:38 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 24 Feb 2010 02:58:38 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> Message-ID: <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> On Feb 24, 7:44?am, Luis M. Gonz?lez wrote: > On Feb 24, 4:08?am, Steven D'Aprano > > > > > > wrote: > > On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. Gonz?lez wrote: > > > On Feb 24, 1:15?am, Steven D'Aprano > > > wrote: > > >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > > >> > On Feb 23, 10:41?pm, Steven D'Aprano > > >> > wrote: > > >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > > >> >> > By the way, if you want the variables inside myDict to be free > > >> >> > variables, you have to add them to the local namespace. The local > > >> >> > namespace is also a dictionary "locals()". So you can update > > >> >> > locals as follows: > > > >> >> > ? ? locals().update( myDictionary ) > > > >> >> No you can't. Try it inside a function. > > > >> >> -- > > >> >> Steven > > > >> > Sure. Inside a function I would use globals() instead. Although I > > >> > don't know if it would be a good practice... > > > >> Er, how does using globals change the local variables? > > > >> -- > > >> Steven > > > > Hmmm.... well, you tell me! > > > I'm not the one that said you can update locals! You said it. I said you > > can't, because you *can't*. The docs warn that you can't change locals, > > and if you try it, you will see that the docs are right. > > > >>> def test(): > > > ... ? ? x = 1 > > ... ? ? locals().update(x = 2) > > ... ? ? print x > > ... > > > >>> test() > > > 1 > > > > As I said, I don't know if this is the recomended way... > > > It's not recommended because it doesn't work. > > > -- > > Steven > > I guess I have to check the docs... > Anyway, nobody wanted to update locals() from within a function here. > Doing it outside of a function seems to work. > And updating globals() works in any case, which is what the OP seems > to need. Isn't it? > > Luis Alright, this is what the docs say about locals: "Note The built-in functions globals() and locals() return the current global and local dictionary, respectively, which may be useful to pass around for use as the second and third argument to exec(). Note The default locals act as described for function locals() below: modifications to the default locals dictionary should not be attempted. Pass an explicit locals dictionary if you need to see effects of the code on locals after function exec() returns." I wonder why updating locals(), not from within a function, works (at least in my interactive session). And what about the trick of updating globals? Is it legal? If not, is there any "legal" way to do what the OP needs? Luis From kse.listed.co1 at gmail.com Wed Feb 24 06:06:39 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Wed, 24 Feb 2010 03:06:39 -0800 (PST) Subject: "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ Message-ID: <0add456c-de59-4105-a01c-9eaf19a7fa20@u15g2000prd.googlegroups.com> "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ vv From eckhardt at satorlaser.com Wed Feb 24 06:24:58 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 24 Feb 2010 12:24:58 +0100 Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Peter Otten wrote: > Duncan Booth wrote: >> for rq in incoming_requests(...): >> handle_request(rq) > > ...and a likely implementation would be > > def incoming_requests(...): > while True: > rq = ... # inlined version of get_request() > if not rq: > break > yield rq > > In other words: It's turtles all the way down... Almost. While it moves the ugliness, at least it allows separating the iteration logic from the handling logic, which is already a big step ahead! That said, there is: with as : ... so why not: while as : ... and also: if as : ... Thanks to everybody for their input! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 06:38:10 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 12:38:10 +0100 Subject: Creating variables from dicts In-Reply-To: References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4b850f94$0$7054$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : > On Feb 23, 5:53 pm, vsoler wrote: >> Hi, >> >> I have two dicts >> >> n={'a', 'm', 'p'} >> v={1,3,7} >> >> and I'd like to have >> >> a=1 >> m=3 >> p=7 >> >> that is, creating some variables. >> >> How can I do this? > > You are probably coming from another language and you're not used to > python's data structures. > If you want a list of items, you use tuples or lists. If you want a list, then you use a list - not a tuple !-) > Examples: > > ('a', 'm', 'p') ---> this is a tuple, and it's made with > parenthesis () It's not the parens that "make" the tuple, it's the commas: >>> t1 = (1, 2, 3) >>> t2 = 1, 2, 3 >>> t1 (1, 2, 3) >>> t2 (1, 2, 3) >>> type(t2) >>> The only case where the parens are required is to define an empty tuple: >>> empty = () >>> empty () >>> type(empty) Now it's most of the time a good idea to still use the parens since it makes for more readable code (IMHO...) (snip helpful content) From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 06:40:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 12:40:22 +0100 Subject: Creating variables from dicts In-Reply-To: References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4b851018$0$7054$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : > On Feb 23, 10:41 pm, Steven D'Aprano > wrote: >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: >>> By the way, if you want the variables inside myDict to be free >>> variables, you have to add them to the local namespace. The local >>> namespace is also a dictionary "locals()". So you can update locals as >>> follows: >>> locals().update( myDictionary ) >> No you can't. Try it inside a function. >> > > Sure. Inside a function I would use globals() instead. > Although I don't know if it would be a good practice... It's even worse than a bad practice. Hint : why is "globals" named "globals" and not "locals" ? From spamfresser at ch3ka.de Wed Feb 24 06:42:08 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 12:42:08 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: First: Thanks for all the replies so far, they really helped me. Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >> >>> def a(x=None): >> if x is None: >> pass >> else: >> pass >> > This is the way to do it python, and it has its advantages: 1 docstring, > 1 way do do it, 1 interface. Yes, I see. Actually I do now realize that even in Java I use method overloading mostly to implement optional arguments anyway, like: void constructor(){this.foo='foo'; this.initotherstuff();} void constructor(int x) {this.x=x; this.constructor();} and so on. So most of the time the idiom above is exactly what I need, as the versions of the function share code anyway. But there are also cases where they do something completely different - in these cases I might use one of the other solutions provided here or simply make two or three functions and name them appropiately. I do now see that the pythonic approach is the "best" for most cases, but I really loved to see that you *can* do overloading in a convenient way if you really want to :D Those decorators just rock :D Thanks again, Michael From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 06:48:13 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 12:48:13 +0100 Subject: Creating variables from dicts In-Reply-To: <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> Message-ID: <4b8511f0$0$24096$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : (snip) > Alright, this is what the docs say about locals: > "Note > The built-in functions globals() and locals() return the current > global and local dictionary, respectively, which may be useful to pass > around for use as the second and third argument to exec(). > > Note > The default locals act as described for function locals() below: > modifications to the default locals dictionary should not be > attempted. Pass an explicit locals dictionary if you need to see > effects of the code on locals after function exec() returns." > > I wonder why updating locals(), not from within a function, works (at > least in my interactive session). Because at the top level, locals and globals are the same thing. > And what about the trick of updating globals? Is it legal? It's legal, but it's (usually) a very bad idea - at the top-level, it harms readability, and from within a function it's doubly bad (readibility + "globals are evil"). Now as usual with GoldenRules(tm), it's meant to be broken - once you do know why you shouldn't _usually_ do it. for the very same reasons global > If not, is > there any "legal" way to do what the OP needs? > > Luis From nobody at dizum.com Wed Feb 24 06:52:50 2010 From: nobody at dizum.com (Nomen Nescio) Date: Wed, 24 Feb 2010 12:52:50 +0100 (CET) Subject: scope of generators, class variables, resulting in global na Message-ID: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Hello, Can someone help me understand what is wrong with this example? class T: A = range(2) B = range(4) s = sum(i*j for i in A for j in B) It produces the exception: : global name 'j' is not defined The exception above is especially confusing since the following similar example (I just replaced the generator by an explicit array) works: class T: A = range(2) B = range(4) s = sum([(i*j) for i in A for j in B]) (BTW, the class scope declarations are intentional). Thanks, Leo. From J.Fine at open.ac.uk Wed Feb 24 07:03:40 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Wed, 24 Feb 2010 12:03:40 +0000 Subject: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens Message-ID: Hi Does anyone know of a collection of regular expressions that will break a TeX/LaTeX document into tokens? Assume that there is no verbatim or other category code changes. Thanks Jonathan From peloko45 at gmail.com Wed Feb 24 07:18:59 2010 From: peloko45 at gmail.com (Joan Miller) Date: Wed, 24 Feb 2010 04:18:59 -0800 (PST) Subject: Fascism is coming to Internet References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> Message-ID: On 23 feb, 20:16, "D'Arcy J.M. Cain" wrote: > On Tue, 23 Feb 2010 20:30:03 +0100 > > Olof Bjarnason wrote: > > Even if this is "Off Topic" (which I think it really isn't in any open > > source / free software-oriented mailing list), I want to agree with > > Joan. > > It isn't about the Python programming language so it is off topic. ?So > what if some members have an interest? ?We have interest in a lot of > things. ?We all have interest in the hardware that our programs run on > but questions about hardware are also off topic. > > Perhaps you don't quite grasp the point of topical discussion groups. > They are a way of letting individuals decide for themselves what kind > of discussions they want to be involved in. ?By spamming the group this > way you take away that freedom of choice. ?It's ironic when it is done > in the name of freedom. > > -- To avoid the spam, I reccomend a mailing list site as librelist: http://librelist.com/index.html problem -> reaction -> solution From alfps at start.no Wed Feb 24 07:21:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 24 Feb 2010 13:21:31 +0100 Subject: scope of generators, class variables, resulting in global na In-Reply-To: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: * Nomen Nescio: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > A = range(2) > B = range(4) > s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined Which Python implementation are you using? I can't reproduce the error message that you cite. C:\test> py2 Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum(i*j for i in A for j in B) ... Traceback (most recent call last): File "", line 1, in File "", line 4, in T File "", line 4, in NameError: global name 'B' is not defined >>> exit() C:\test> py3 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum(i*j for i in A for j in B) ... Traceback (most recent call last): File "", line 1, in File "", line 4, in T File "", line 4, in NameError: global name 'B' is not defined >>> exit() C:\test> _ Reason for the NameError: The above is a /generator expression/, evaluated in a class definition. The docs have a similar example but I'm sorry, I'm unable to find it! Anyway the generator expression is evaluated as if its code was put in function. And from within the scope of that function you can't access the class scope implicitly, hence, no access to 'B'. > The exception above is especially confusing since the following similar example > (I just replaced the generator by an explicit array) works: > > class T: > A = range(2) > B = range(4) > s = sum([(i*j) for i in A for j in B]) > > (BTW, the class scope declarations are intentional). > > Thanks, Leo. This is a /list comprehension/, not a generator expression (although syntactically it's almost the same). It obeys different rules. Essentially the generator expression produces a generator object that you may name or pass around as you wish, while the comprehension is just a syntactical device for writing more concisely some equivalent code that's generated inline. However, apparently the rules changed between Python 2.x and Python 3.x. In Python 3.x also the list comprehension fails in a class definition: C:\test> py2 Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum([(i*j) for i in A for j in B]) ... >>> exit() C:\test> py3 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum([(i*j) for i in A for j in B]) ... Traceback (most recent call last): File "", line 1, in File "", line 4, in T File "", line 4, in NameError: global name 'B' is not defined >>> exit() C:\test> _ From one point of view it's good that Py3 provides about the same behavior for generator expressions and list comprehensions. But I'd really like the above examples to Just Work. :-) Cheers & hth., - Alf From gereon.kaiping at yahoo.de Wed Feb 24 07:49:55 2010 From: gereon.kaiping at yahoo.de (Gereon Kaiping) Date: Wed, 24 Feb 2010 13:49:55 +0100 Subject: Artificial Neural Networks recommendation Message-ID: <4B852073.30500@yahoo.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'd like to use ANNs in python, especially Simple Recurrent Networks. Ideally I'd like to find a quick, pythonic module that is able to simulate different styles of network architectures including some types of recurrent networks (must: SRN/Elman, may: other recurrent networks like ESN or LSTM to experiment with them). So far I found the following Python ANN modules: - - PyNN (just a builder, requires external simulator) ? http://neuralensemble.org/trac/PyNN/ - - Con-x (part of pyro) ? http://pyrorobotics.org/?page=Conx - - PyNeurGen (includes genetic algorithms) ? http://pyneurgen.sourceforge.net/ - - ffnet (only fast forward) ? http://ffnet.sourceforge.net/ - - brian (spiking networks) ? http://www.briansimulator.org/ - - PyBrain (machine learning) ? http://pybrain.org/ Can you give me a recommendation or a review on some of these? Are there other modules for simulating ANNs? Greetings, Gereon -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkuFIHIACgkQFWJnZLsO/Wvp1ACfa2dhOd0b0SIVkOzZN0ebRJdd WFQAoIttIDNbIuqViDbPeVyS+wtGj6tI =N1oM -----END PGP SIGNATURE----- From paul.nospam at rudin.co.uk Wed Feb 24 08:11:32 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 24 Feb 2010 13:11:32 +0000 Subject: Artificial Neural Networks recommendation References: Message-ID: <87y6iird6j.fsf@rudin.co.uk> Gereon Kaiping writes: > Are there other modules for simulating ANNs? Fann has python bindings. From luismgz at gmail.com Wed Feb 24 08:41:08 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 24 Feb 2010 05:41:08 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> Message-ID: <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> On Feb 24, 8:48?am, Bruno Desthuilliers wrote: > Luis M. Gonz lez a crit : > (snip) > > > Alright, this is what the docs say about locals: > > "Note > > The built-in functions globals() and locals() return the current > > global and local dictionary, respectively, which may be useful to pass > > around for use as the second and third argument to exec(). > > > Note > > The default locals act as described for function locals() below: > > modifications to the default locals dictionary should not be > > attempted. Pass an explicit locals dictionary if you need to see > > effects of the code on locals after function exec() returns." > > > I wonder why updating locals(), not from within a function, works (at > > least in my interactive session). > > Because at the top level, locals and globals are the same thing. > > > And what about the trick of updating globals? Is it legal? > > It's legal, but it's (usually) a very bad idea - at the top-level, it > harms readability, and from within a function it's doubly bad > (readibility + "globals are evil"). > > Now as usual with GoldenRules(tm), it's meant to be broken - once you do > know why you shouldn't _usually_ do it. > > ? for the very same reasons global > > > > > If not, is > > there any "legal" way to do what the OP needs? > > > Luis I still don't understand why is it a bad idea in the case of globals(). This is the only way I know to define variables programatically in the top-level namespace, without having to do it manually one by one. I don't see the readability problem either. Talking about Goldenrules(tm), what's the recomended way to do it? Luis From edreamleo at gmail.com Wed Feb 24 08:58:03 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Wed, 24 Feb 2010 07:58:03 -0600 Subject: ANN: Leo 4.7 final released References: Message-ID: <3qbao5tflmcds61l1ngltaq12ogdlvo2e8@4ax.com> On Tue, 23 Feb 2010 07:53:44 -0600, Edward K Ream wrote: A critical bug has been reported against Leo 4.7 final, and indeed all previous versions of Leo 4.7. The bug can cause loss of data in @file nodes when Leo 4.7 saves .leo files created with older versions of Leo. This bug will be fixed in Leo 4.7.1, due in a few days. The bug has already been fixed on Leo's trunk. My apologies for any problems this bug may have caused. From steve at holdenweb.com Wed Feb 24 08:59:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 08:59:13 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: At 12.34 pm on November 13, 2011 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 24 09:02:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 09:02:17 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: <4B853169.6030904@holdenweb.com> Stefan Behnel wrote: > Chris Rebert, 23.02.2010 06:45: >> Indeed. Python is at position 7, just behind C#, in the TIOBE Index: >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? > Interesting that you are willing to trust your gut feeling against an established survey. All indexes are flawed, they are merely flawed in different ways is all. I track TIOBE because it shows trends. Python's absolute position on the list doesn't interest me so much. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 24 09:02:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 09:02:17 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: <4B853169.6030904@holdenweb.com> Stefan Behnel wrote: > Chris Rebert, 23.02.2010 06:45: >> Indeed. Python is at position 7, just behind C#, in the TIOBE Index: >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? > Interesting that you are willing to trust your gut feeling against an established survey. All indexes are flawed, they are merely flawed in different ways is all. I track TIOBE because it shows trends. Python's absolute position on the list doesn't interest me so much. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 24 09:07:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 09:07:17 -0500 Subject: How to make an empty generator? In-Reply-To: <4B7EF185.1040702@optimum.net> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> <4B7EF185.1040702@optimum.net> Message-ID: John Posner wrote: > On 2/19/2010 2:25 PM, Terry Reedy wrote: >> On 2/19/2010 12:44 PM, Stephen Hansen wrote: >> >>> Much to my embarrassment, sometime last night I realized I was being a >>> complete idiot, and the 'correct' way to handle this in my scenario is >>> really just: >>> >>> def initialize(): >>> # do one time processing here >>> >>> return [] >>> >>> A generator is just a callable that returns an iterator, after all. >> >> Confusing generators and generator functions is, well, confusing. >> For future reference, and clarity of communication in Pythonland, >> >> generator function: function that produces a generator when called; if >> python coded, its body contains 'yield'. >> >> generator: iterator produced by a generator function; > > I suggest: > > iterator produced by a generator function or a generator expression; > > has .__next__ and >> self-returning .__init__, like all other iterators. >> >> generator expression: an expression that evaluates to a generator; the >> expression is used to create a temporary anonymous generator function >> that is called to produce the generator and is then discarded. > > Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms > to Terry's definitions above in most places. But the Glossary says: > > generator > A function which returns an iterator. <... more ...> > > generator expression > An expression that returns a generator. <... more ...> > > The additional verbiage in these definitions mitigates the damage, but I > think the first entry should be headlined *generator function* instead > of *generator*. And the Glossary should include Terry's additional entry > [ as amended by me :-) ]: > > generator > An iterator produced by a generator function or a generator > expression. > > -John > +1. Can someone submit a documentation patch, please? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From victorsubervi at gmail.com Wed Feb 24 09:32:43 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 24 Feb 2010 10:32:43 -0400 Subject: Can't Connect To SMTP Message-ID: <4dc0cfea1002240632h755b199bp1cf5c36b489aac07@mail.gmail.com> Hi; I'm getting this error: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py 52 53 ''' 54 my_mail() 55 print ''' 56 my_mail = /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() 33 to_address = ourEmail1, 34 subject = subject, 35 message = message 36 ).send() 37 Email( message = 'Name: beno -\nMessage: test' /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in send(self=) 344 smtp = smtplib.SMTP() 345 if self.smtp_server: 346 smtp.connect(self.smtp_server) 347 else: 348 smtp.connect() smtp = , smtp.connect = >, self = , self.smtp_server = 'localhost' /usr/lib64/python2.4/smtplib.py in connect(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code undefined, msg = 'getaddrinfo returns an empty list', self = , self.getreply = > /usr/lib64/python2.4/smtplib.py in getreply(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) global SMTPServerDisconnected = SMTPServerDisconnected: Connection unexpectedly closed args = ('Connection unexpectedly closed',) I'm having a hard time reading this and making sense of it. Please help me understand where I should look to fix the problem. TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 09:44:41 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 15:44:41 +0100 Subject: Creating variables from dicts In-Reply-To: <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> Message-ID: <4b853b4b$0$23448$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : > On Feb 24, 8:48 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Luis M. Gonz lez a crit : >> >>> And what about the trick of updating globals? Is it legal? >> It's legal, but it's (usually) a very bad idea - at the top-level, it >> harms readability, and from within a function it's doubly bad >> (readibility + "globals are evil"). >> >> Now as usual with GoldenRules(tm), it's meant to be broken - once you do >> know why you shouldn't _usually_ do it. >> >>> If not, is >>> there any "legal" way to do what the OP needs? > > I still don't understand why is it a bad idea in the case of > globals(). please not the _usually_. > This is the only way I know to define variables programatically in the > top-level namespace, without having to do it manually one by one. > I don't see the readability problem either. # wrong.py x = 42 def bar(): return x + 1 def test(): y = bar() assert y==43 # snip 1kloc def foo(): globals()[x] = 43 quux() # snip some more core def quux(): globals()[y] = 1138 # snip some more core if __name__ == '__main__': foo() Enjoy... > Talking about Goldenrules(tm), what's the recomended way to do it? The "recommanded way" is 1/ to avoid using globals to share state whenever possible 2/ to avoid creating globals from a function If your problem is to conditionnaly define globals (based on environment value or whatnot), then just write the conditional at the top level. Now I don't say there's no legitimate use case for updating the global namespace from within a function - just that this is a very very very rare beast (never meet her as far as I'm concerned, and I did write some hairy code), and even then is BadEnough(tm) to require a good documentation. FWIW, your example seemed to be about updating the global namespace from within a function just to have the names available in the function, which is about the worst possible solution to the OP problem. wrt/ the OP question, mapping a sequence of values to a sequence of names is a legitimate concern, but you just dont need to define these names in the local namespace to use them - just stick'em in a dict and you're fine. From jjposner at optimum.net Wed Feb 24 09:48:32 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 09:48:32 -0500 Subject: How to make an empty generator? In-Reply-To: References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> <4B7EF185.1040702@optimum.net> Message-ID: <4B853C40.5090307@optimum.net> On 2/24/2010 9:07 AM, Steve Holden wrote: > John Posner wrote: >> Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms >> to Terry's definitions above in most places. But the Glossary says: >> >> generator >> A function which returns an iterator.<... more ...> >> >> generator expression >> An expression that returns a generator.<... more ...> >> >> The additional verbiage in these definitions mitigates the damage, but I >> think the first entry should be headlined *generator function* instead >> of *generator*. And the Glossary should include Terry's additional entry >> [ as amended by me :-) ]: >> >> generator >> An iterator produced by a generator function or a generator >> expression. >> >> -John >> > +1. Can someone submit a documentation patch, please? > Will do. -John From phoghawk at gmail.com Wed Feb 24 10:40:55 2010 From: phoghawk at gmail.com (b3ng0) Date: Wed, 24 Feb 2010 07:40:55 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: <4308848c-b38f-4e45-bf01-8c4d2b3dcb7c@a18g2000yqc.googlegroups.com> On Feb 24, 5:52?am, Nomen Nescio wrote: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > ? A = range(2) > ? B = range(4) > ? s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined > > The exception above is especially confusing since the following similar example (I just replaced the generator by an explicit array) works: > > class T: > ? A = range(2) > ? B = range(4) > ? s = sum([(i*j) for i in A for j in B]) > > (BTW, the class scope declarations are intentional). > > Thanks, Leo. The best way to mimic the same behavior, while getting around the scoping issues, would be as follows: class T: A = range(2) B = range(4) @property def s(self): return sum(i*j for i in self.A for j in self.B) T().s will now return 6 From joncle at googlemail.com Wed Feb 24 10:45:05 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Feb 2010 07:45:05 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: On Feb 24, 12:21?pm, "Alf P. Steinbach" wrote: > * Nomen Nescio: > > > Hello, > > > Can someone help me understand what is wrong with this example? > > > class T: > > ? A = range(2) > > ? B = range(4) > > ? s = sum(i*j for i in A for j in B) > > > It produces the exception: > > > : global name 'j' is not defined > > Which Python implementation are you using? > > I can't reproduce the error message that you cite. > > > C:\test> py2 > Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum(i*j for i in A for j in B) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() > > C:\test> py3 > Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum(i*j for i in A for j in B) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() > > C:\test> _ > > > Reason for the NameError: > > The above is a /generator expression/, evaluated in a class definition. > > The docs have a similar example but I'm sorry, I'm unable to find it! Anyway the > generator expression is evaluated as if its code was put in function. And from > within the scope of that function you can't access the class scope implicitly, > hence, no access to 'B'. > > > The exception above is especially confusing since the following similar example > > (I just replaced the generator by an explicit array) works: > > > class T: > > ? A = range(2) > > ? B = range(4) > > ? s = sum([(i*j) for i in A for j in B]) > > > (BTW, the class scope declarations are intentional). > > > Thanks, Leo. > > This is a /list comprehension/, not a generator expression (although > syntactically it's almost the same). > > It obeys different rules. > > Essentially the generator expression produces a generator object that you may > name or pass around as you wish, while the comprehension is just a syntactical > device for writing more concisely some equivalent code that's generated inline. > > However, apparently the rules changed between Python 2.x and Python 3.x. > > In Python 3.x also the list comprehension fails in a class definition: > > > C:\test> py2 > Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum([(i*j) for i in A for j in B]) > ... > ?>>> exit() > > C:\test> py3 > Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum([(i*j) for i in A for j in B]) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() > > C:\test> _ > > > ?From one point of view it's good that Py3 provides about the same behavior for > generator expressions and list comprehensions. > > But I'd really like the above examples to Just Work. :-) > > Cheers & hth., > > - Alf s = sum( i*j for i,j in iterools.product(A, B) ) is a possible work around. Which could generalise to (something like): s = sum( reduce(op.mul, seq) for seq in product(A, B, B, A) ) Cheers, Jon. From robert.kern at gmail.com Wed Feb 24 10:57:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 09:57:34 -0600 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: On 2010-02-23 22:09 PM, Grant Edwards wrote: > On 2010-02-24, Robert Kern wrote: > >>> comp.lang.python.spam_prevention_discussion >> >> Which doesn't exist and never will. Sorry, but >> meta-discussions about the group are typically on-topic for >> all groups with some few exceptions (e.g. non-discussion, >> binary-only groups with associated .d groups, for instance). > > Since now we are discussing meta-discussions, is this now a > meta-meta-discussion? If you like, but I tend to interpret "meta-" as idempotent. It's easier on my aspirin budget. -- 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 parkerp at example.net Wed Feb 24 11:05:42 2010 From: parkerp at example.net (Peter Parker) Date: Wed, 24 Feb 2010 11:05:42 -0500 Subject: When will Python go mainstream like Java? References: Message-ID: Steve Holden wrote: > At 12.34 pm on November 13, 2011 > At December 21, 2012 at 11:11 am (according to the Maya calendar) From arnodel at googlemail.com Wed Feb 24 11:14:00 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 24 Feb 2010 08:14:00 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: <3f3ce996-7fc3-4c19-9397-e1db8f911aa4@k19g2000yqc.googlegroups.com> Nomen Nescio wrote: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > A = range(2) > B = range(4) > s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined It's due to scoping rules for classes and/or how generator expressions are compiled. When a function definition is executed from within the body of a class, the body of the class doesn't act as an outer scope for it. E.g. class A: x = 2 def f(self): return x When f is defined (technically, when the closure is made), the name 'x' is not bound to 2 but is considered to be in the global namespace (unless the class is defined within a function for example). Now generator expressions are defined as generator functions so your example is akin to something like: class T: A = range(2) B = range(4) def _gen(L): for i in L: for j in B: yield i*j s = sum(_gen(A)) (From memory, I might be wrong on some details) Now looking at the above, when _gen is defined, B is considered to be belonging to the global namespace, therefore if it is not defined there a NameError will be thrown. Now a safe workaround to this would be: class T: A = range(2) B = range(4) s = (lambda A=A, B=B: sum(i*j for i in A for j in B))() The lambda form is evaluated when the body of the class is executed, binding the names A and B to the objects you want in the generator expression. I remember suggesting a while ago that all generator expressions be implicitely wrapped like the one above in order to avoid such surprises. I can't quite remember what the arguments against were, but you can probably find them in the archives! -- Arnaud From martin.hellwig at dcuktec.org Wed Feb 24 11:38:57 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 24 Feb 2010 16:38:57 +0000 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: On 02/24/10 16:05, Peter Parker wrote: > Steve Holden wrote: >> At 12.34 pm on November 13, 2011 >> > > At December 21, 2012 at 11:11 am (according to the Maya calendar) On August 29, 1997, Java became mainstream. In a panic, Microsoft tried to embrace, extend and exterminate the system, prompting Sun to retaliate with a lawsuit, knowing that Microsoft's counterattack would eliminate all its main competitors in the U.S. This initiates an indeterminately long period of new language development culminating in a battle against corporate monopoly, which gained ever-increasing capabilities of FUD. -- mph From sbassi at clubdelarazon.org Wed Feb 24 12:07:07 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Wed, 24 Feb 2010 14:07:07 -0300 Subject: parametrizing a sqlite query Message-ID: <9e2f512b1002240907v66682f1fi7d4d4c7d2dabd880@mail.gmail.com> c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) This query returns empty. When it is executed, keywords = 'harvest'. To check it, I do it on the command line and it works as expected: sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; 11C 11D 12F I guess there is a problem with the "%". From victorsubervi at gmail.com Wed Feb 24 12:09:24 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 24 Feb 2010 13:09:24 -0400 Subject: SMTPServerDisconnected In-Reply-To: <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> References: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> Message-ID: <4dc0cfea1002240909u6a82926l4c82ec3adf9a9192@mail.gmail.com> On Tue, Feb 23, 2010 at 4:53 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Tue, Feb 23, 2010 at 8:47 AM, Victor Subervi > wrote: > > Hi; > > I think the last main thing I have to do on my server is get a running > email > > server up. Now that I've nuked sendmail and given up on postfix, I'm back > to > > trying to get qmail up and running again. Of course, there are no active > > discussion lists for *any* email server, so I have to turn here for help. > > While running a script that worked perfectly well on another server to > send > > an email, I get the following error: > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py > > 52 > > 53 ''' > > 54 my_mail() > > 55 print ''' > > 56 > > my_mail = > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() > > 33 to_address = ourEmail1, > > 34 subject = subject, > > 35 message = message > > 36 ).send() > > 37 Email( > > message = 'Name: beno -\nMessage: test' > > /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in > > send(self=) > > 344 smtp = smtplib.SMTP() > > 345 if self.smtp_server: > > 346 smtp.connect(self.smtp_server) > > 347 else: > > 348 smtp.connect() > > smtp = , smtp.connect = of > > >, self = , > self.smtp_server > > = 'localhost' > > /usr/lib64/python2.4/smtplib.py in connect(self=, > > host='localhost', port=25) > > 305 if not self.sock: > > 306 raise socket.error, msg > > 307 (code, msg) = self.getreply() > > 308 if self.debuglevel > 0: print>>stderr, "connect:", msg > > 309 return (code, msg) > > code undefined, msg = 'getaddrinfo returns an empty list', self = > > , self.getreply = > > > > /usr/lib64/python2.4/smtplib.py in getreply(self= instance>) > > 349 if line == '': > > 350 self.close() > > 351 raise SMTPServerDisconnected("Connection > unexpectedly > > closed") > > 352 if self.debuglevel > 0: print>>stderr, 'reply:', > > repr(line) > > 353 resp.append(line[4:].strip()) > > global SMTPServerDisconnected = > > SMTPServerDisconnected: Connection unexpectedly closed > > args = ('Connection unexpectedly closed',) > > I cannot find the qmail logs. I assumed they'd be in either > > /var/qmail/supervise/qmail-send > > or > > /var/qmail/supervise/qmail-smtpd > > but I find no logs there. > > > > [SSH] Protocol Version 2 (OpenSSH_4.3) > > [SSH] Cipher: aes128-cbc > > Logged in (password) > > Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 > > [beno at 13gems ~]$ su > > Password: > > [root at 13gems beno]# man netstat > > [root at 13gems beno]# netstat > > Active Internet connections (w/o servers) > > Proto Recv-Q Send-Q Local Address Foreign Address > > State > > getnameinfo failed > > tcp 0 268 nrelectric.com:ssh [UNKNOWN]:61912 > > ESTABLISHED > > Active UNIX domain sockets (w/o servers) > > Proto RefCnt Flags Type State I-Node Path > > unix 7 [ ] DGRAM 10842 /dev/log > > unix 2 [ ] DGRAM 10370 > > @/org/kernel/udev/udevd > > unix 2 [ ] DGRAM 6077731 > > unix 3 [ ] STREAM CONNECTED 6077679 > > unix 3 [ ] STREAM CONNECTED 6077678 > > unix 2 [ ] DGRAM 6077675 > > unix 2 [ ] DGRAM 11556 > > unix 2 [ ] DGRAM 11511 > > unix 2 [ ] DGRAM 10990 > > [root at 13gems beno]# > > > > How do I trouble-shoot this? > > Try connecting to the port that is supposed to accept mail messages > via telnet and issue a few SMTP commands. > Oops. I just realized I posted this twice to the same forum. My bad. I have advanced on this somewhat. I have gotten email from my server, so I know that smtp is in fact working. But I'm still getting this error. What do? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Feb 24 12:10:37 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 24 Feb 2010 13:10:37 -0400 Subject: SMTPServerDisconnected In-Reply-To: <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> References: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> Message-ID: <4dc0cfea1002240910k6e236cf1pd068bd6c3fd08bbc@mail.gmail.com> On Tue, Feb 23, 2010 at 4:53 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Tue, Feb 23, 2010 at 8:47 AM, Victor Subervi > wrote: > > Hi; > > I think the last main thing I have to do on my server is get a running > email > > server up. Now that I've nuked sendmail and given up on postfix, I'm back > to > > trying to get qmail up and running again. Of course, there are no active > > discussion lists for *any* email server, so I have to turn here for help. > > While running a script that worked perfectly well on another server to > send > > an email, I get the following error: > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py > > 52 > > 53 ''' > > 54 my_mail() > > 55 print ''' > > 56 > > my_mail = > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() > > 33 to_address = ourEmail1, > > 34 subject = subject, > > 35 message = message > > 36 ).send() > > 37 Email( > > message = 'Name: beno -\nMessage: test' > > /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in > > send(self=) > > 344 smtp = smtplib.SMTP() > > 345 if self.smtp_server: > > 346 smtp.connect(self.smtp_server) > > 347 else: > > 348 smtp.connect() > > smtp = , smtp.connect = of > > >, self = , > self.smtp_server > > = 'localhost' > > /usr/lib64/python2.4/smtplib.py in connect(self=, > > host='localhost', port=25) > > 305 if not self.sock: > > 306 raise socket.error, msg > > 307 (code, msg) = self.getreply() > > 308 if self.debuglevel > 0: print>>stderr, "connect:", msg > > 309 return (code, msg) > > code undefined, msg = 'getaddrinfo returns an empty list', self = > > , self.getreply = > > > > /usr/lib64/python2.4/smtplib.py in getreply(self= instance>) > > 349 if line == '': > > 350 self.close() > > 351 raise SMTPServerDisconnected("Connection > unexpectedly > > closed") > > 352 if self.debuglevel > 0: print>>stderr, 'reply:', > > repr(line) > > 353 resp.append(line[4:].strip()) > > global SMTPServerDisconnected = > > SMTPServerDisconnected: Connection unexpectedly closed > > args = ('Connection unexpectedly closed',) > > I cannot find the qmail logs. I assumed they'd be in either > > /var/qmail/supervise/qmail-send > > or > > /var/qmail/supervise/qmail-smtpd > > but I find no logs there. > > > > [SSH] Protocol Version 2 (OpenSSH_4.3) > > [SSH] Cipher: aes128-cbc > > Logged in (password) > > Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 > > [beno at 13gems ~]$ su > > Password: > > [root at 13gems beno]# man netstat > > [root at 13gems beno]# netstat > > Active Internet connections (w/o servers) > > Proto Recv-Q Send-Q Local Address Foreign Address > > State > > getnameinfo failed > > tcp 0 268 nrelectric.com:ssh [UNKNOWN]:61912 > > ESTABLISHED > > Active UNIX domain sockets (w/o servers) > > Proto RefCnt Flags Type State I-Node Path > > unix 7 [ ] DGRAM 10842 /dev/log > > unix 2 [ ] DGRAM 10370 > > @/org/kernel/udev/udevd > > unix 2 [ ] DGRAM 6077731 > > unix 3 [ ] STREAM CONNECTED 6077679 > > unix 3 [ ] STREAM CONNECTED 6077678 > > unix 2 [ ] DGRAM 6077675 > > unix 2 [ ] DGRAM 11556 > > unix 2 [ ] DGRAM 11511 > > unix 2 [ ] DGRAM 10990 > > [root at 13gems beno]# > > > > How do I trouble-shoot this? > > Try connecting to the port that is supposed to accept mail messages > via telnet and issue a few SMTP commands. > Oops. I just realized I sent this question twice to the same forum. My bad. I have received email from my server, but I'm still getting this same error. How trouble-shoot? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Wed Feb 24 12:15:08 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 12:15:08 -0500 Subject: How to make an empty generator? In-Reply-To: <4B853C40.5090307@optimum.net> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> <4B7EF185.1040702@optimum.net> <4B853C40.5090307@optimum.net> Message-ID: <4B855E9C.5040502@optimum.net> >>> generator >>> An iterator produced by a generator function or a generator >>> expression. >>> >>> -John >>> >> +1. Can someone submit a documentation patch, please? >> > > Will do. -John [sorry if this is a dup] Done: #8012 "Revise generator-related Glossary entries" -John From joncle at googlemail.com Wed Feb 24 12:21:11 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Feb 2010 09:21:11 -0800 (PST) Subject: parametrizing a sqlite query References: Message-ID: On Feb 24, 5:07?pm, Sebastian Bassi wrote: > c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) > > This query returns empty. When it is executed, keywords = 'harvest'. > To check it, I do it on the command line and it works as expected: > > sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; > 11C > 11D > 12F > > I guess there is a problem with the "%". You might want: c.execute("SELECT bin FROM bins where qtl like $keys", {'keys': keywords} ) Cheers, Jon. From mrkafk at gmail.com Wed Feb 24 12:23:17 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 18:23:17 +0100 Subject: Is this secure? In-Reply-To: <7x3a0r8hyr.fsf@ruckus.brouhaha.com> References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 03:50, Paul Rubin wrote: > The stuff about converting 4 random bytes to a decimal string and then > peeling off 2 digits at a time is pretty awful, and notice that since > 2**32 is 4294967296, in the cases where you get 10 digits, the first > 2-digit pair is never higher than 42. Yikes! I didn't think about that. This is probably where (some part of) probability skewing comes from. Anyway, the passwords for authorized users will be copied and pasted from email into in the application GUI which will remember it for them, so they will not have to remember and type them in. So I have little in the way of limitations of password length - even though in *some* cases somebody might have to (or be ignorant enough) to retype the password instead of pasting it in. In that case the "diceware" approach is not necessary, even though I will certainly remember this approach for a case when users will have to remember & type the passwords in. The main application will access the data using HTTP (probably), so the main point is that an attacker is not able to guess passwords using brute force. Using A-z with 10-char password seems to provide 3 orders of magnitude more combinations than a-z: >>> 57 ** 10 362033331456891249L >>> 25 ** 10 95367431640625L Even though I'm not sure it is worth it, assuming 1000 brute-force guesses per second (which over the web would amount pretty much to DOS), this would take # days: >>> 57 ** 10 / (1000 * 3600 * 24) 4190200595L >>> 25 ** 10 / (1000 * 3600 * 24) 1103789L Even then I'm not getting completely uniform distribution for some reason: d 39411 l 39376 f 39288 a 39275 s 39225 r 39172 p 39159 t 39073 k 39071 u 39064 e 39005 o 39005 n 38995 j 38993 h 38975 q 38958 c 38938 b 38906 g 38894 i 38847 m 38819 v 38712 z 35321 y 35228 w 35189 x 35075 Code: import operator def gen_rand_word(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)]) def count_chars(chardict, word): for c in word: try: chardict[c] += 1 except KeyError: chardict[c] = 0 if __name__ == "__main__": chardict = {} for i in range(100000): w = gen_rand_word(10) count_chars(chardict, w) counts = list(chardict.items()) counts.sort(key = operator.itemgetter(1), reverse = True) for char, count in counts: print char, count > I'd write your code something like this: > > nletters = 5 > > def randomword(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a')+ord(c)%26) for c in f.read(n)]) > > print randomword(nletters) Aw shucks when will I learn to do the stuff in 3 lines well instead of 20, poorly. :-/ Regards, mk From joncle at googlemail.com Wed Feb 24 12:29:22 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Feb 2010 09:29:22 -0800 (PST) Subject: parametrizing a sqlite query References: Message-ID: On Feb 24, 5:21?pm, Jon Clements wrote: > On Feb 24, 5:07?pm, Sebastian Bassi wrote: > > > c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) > > > This query returns empty. When it is executed, keywords = 'harvest'. > > To check it, I do it on the command line and it works as expected: > > > sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; > > 11C > > 11D > > 12F > > > I guess there is a problem with the "%". > > You might want: > c.execute("SELECT bin FROM bins where qtl like $keys", {'keys': > keywords} ) > > Cheers, > > Jon. As soon as I posted that, the $ didn't look right; the docs use :keys syntax. Cheers, Jon. From mrkafk at gmail.com Wed Feb 24 12:30:20 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 18:30:20 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: On 2010-02-24 03:26, George Sakkis wrote: >> Well I for one wouldn't want Python to go exactly Java way, see this: >> >> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=jav... >> >> This is the percentage of job offers in UK where the keyword "Java" appears. >> >> Same for C#, it looks like C# is eating Java's lunch now: >> >> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csh... > > This seems to be a UK-specific trend; in the US (and most other > countries I know of) Java is still going strong, e.g. > http://www.indeed.com/jobtrends?q=java%2C+c%23&l= Interesting, and I was thinking that UK sample was big enough for such things not to matter. Regards, mk From gagsl-py2 at yahoo.com.ar Wed Feb 24 12:32:59 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Feb 2010 14:32:59 -0300 Subject: How to measure elapsed time under Windows? References: <1n2en51qqliplc2u8q78l3gt2dn3vmeh8d@4ax.com> Message-ID: En Sat, 13 Feb 2010 17:29:45 -0300, Tim Roberts escribi?: > "Gabriel Genellina" wrote: >> >> The original problem was with the RDTSC instruction on multicore CPUs; >> different cores may yield different results because they're not >> synchronized at all times. > > Not true. The synchronization issue has two causes: initial > synchronization at boot time, and power management making microscopic > adjustments to the clock rate. In Windows NT 4, Microsoft took extra > pains > to adjust the cycle counters on multiprocessor computers during boot so > that the processors started out very close together. Once set, they > naturally remained in lock step, until aggressive power management > because > more prevalent. In XP, they stopped trying to align at boot time. Thanks for the detailed explanation! -- Gabriel Genellina From spam at removethis.btinternet.com Wed Feb 24 12:39:19 2010 From: spam at removethis.btinternet.com (Abigail) Date: Wed, 24 Feb 2010 17:39:19 -0000 Subject: Noob raw_input question Message-ID: Yesterday I downloaded and installed Python 3.1 and working through some examples but I have hit a problem >>> a = raw_input("Enter a number" ) Traceback (most recent call last): File "", line 1, in a = raw_input("Enter a number" ) NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number ") What am I doing wrong? From mrkafk at gmail.com Wed Feb 24 12:47:11 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 18:47:11 +0100 Subject: Intra-package C extensions with freeze.py In-Reply-To: <4B4E2497.20809@gmail.com> References: <4B4E2497.20809@gmail.com> Message-ID: On 2010-01-13 20:52, Pascal Chambon wrote: > I've managed to solve that by manually "monkey patching" sys.modules, > before fusemodule's actual import. But this looks like an unsatisfying > solution, to me. Geez.. > Does anyone have a clue about how to freeze a python program cleanly, in > case such inner C extensions are involved ? Does any of the freezers > (freeze.py, py2exe, pyrex, cx_freeze...) do that ? I haven't seen such > things so far in their docs. Go for pyinstaller, I have successfully packaged an app using compiled C extensions this way. Although you will have to add those extensions in "hook" script. Regards, mk From comptekki at gmail.com Wed Feb 24 12:49:08 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 24 Feb 2010 10:49:08 -0700 Subject: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens In-Reply-To: References: Message-ID: <533df7fa1002240949o4f98d294u9174b4d32cd154b1@mail.gmail.com> On Wed, Feb 24, 2010 at 5:03 AM, Jonathan Fine wrote: > Hi > > Does anyone know of a collection of regular expressions that will break a > TeX/LaTeX document into tokens? ?Assume that there is no verbatim or other > category code changes. I'm not sure how this does it, but it might help: http://plastex.sourceforge.net/plastex/sect0025.html -wes From bornstub at gmail.com Wed Feb 24 12:49:18 2010 From: bornstub at gmail.com (Victor Lin) Date: Wed, 24 Feb 2010 09:49:18 -0800 (PST) Subject: A tool for find dependencies relationships behind Python projects References: Message-ID: On 2?23?, ??12?32?, Hellmut Weber wrote: > Hi Victor, > I would be intereseted to use your tool ;-) > > My system is Sabayon-5.1 on Lenovo T61. > Trying for the first time easy_install I get the following error: > > ==================== > > root at sylvester ~ # easy_install gluttony > Searching for gluttony > Readinghttp://pypi.python.org/simple/gluttony/ > Readinghttp://code.google.com/p/python-gluttony/ > Best match: Gluttony 0.3 > > Downloadinghttp://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md... > > Processing Gluttony-0.3.zip > Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD > Traceback (most recent call last): > ? ?File "/usr/bin/easy_install", line 9, in > ? ? ?load_entry_point('distribute==0.6.8', 'console_scripts', > 'easy_install')() > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1708, in main > ? ? ?with_ei_usage(lambda: > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1696, in with_ei_usage > ? ? ?return f() > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1712, in > ? ? ?distclass=DistributionWithoutHelpCommands, **kw > ? ?File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup > ? ? ?dist.run_commands() > ? ?File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands > ? ? ?self.run_command(cmd) > ? ?File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command > ? ? ?cmd_obj.run() > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 236, in run > ? ? ?self.easy_install(spec, not self.no_deps) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 471, in easy_install > ? ? ?return self.install_item(spec, dist.location, tmpdir, deps) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 501, in install_item > ? ? ?dists = self.install_eggs(spec, download, tmpdir) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 680, in install_eggs > ? ? ?return self.build_and_install(setup_script, setup_base) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 957, in build_and_install > ? ? ?self.run_setup(setup_script, setup_base, args) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 946, in run_setup > ? ? ?run_setup(setup_script, args) > ? ?File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line > 29, in run_setup > ? ? ?lambda: execfile( > ? ?File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line > 70, in run > ? ? ?return func() > ? ?File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line > 31, in > ? ? ?{'__file__':setup_script, '__name__':'__main__'} > ? ?File "setup.py", line 9, in > ? ?File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", > line 1, in > ? ? ?# > ? ?File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", > line 13, in > ImportError: No module named pip.log > root at sylvester ~ # > > ==================== > > I emerged app-misc/pip, but that didn't help, the error remains the same > > What is missing? > > Any help appreciated > > Best regards > > Hellmut > > Am 19.02.2010 17:16, schrieb Victor Lin: > > > > > > > Hi, > > > I just wrote a tool for drawing dependencies relationships diagram of > > Python project on Pypi. ?Here is the home page of the tool: > > >http://code.google.com/p/python-gluttony/ > > > Some examples: > > Sprox: > >http://static.ez2learn.com/gluttony/sprox_dot.png > > > TurboGears2: > >http://static.ez2learn.com/gluttony/tg2_dot.png > > > Hope this could be helpful :P > > > Regards. > > Victor Lin. > > -- > Dr. Hellmut Weber ? ? ? ? m... at hellmutweber.de > Degenfeldstra?e 2 ? ? ? ? tel ? +49-89-3081172 > D-80803 M?nchen-Schwabing mobil +49-172-8450321 > please: No DOCs, no PPTs. why: tinyurl.com/cbgq Hi, That is a mistake I made in when I am making the distribute. Thanks your reporting. I have already fixed the problem and released Gluttony 0.4, and I tried to install that, it works fine. Victor Lin. From spamfresser at ch3ka.de Wed Feb 24 12:56:03 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 18:56:03 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: Am 24.02.2010 18:23, schrieb mk: > Even then I'm not getting completely uniform distribution for some reason: > d 39411 > l 39376 > f 39288 > a 39275 > s 39225 > r 39172 > p 39159 > t 39073 > k 39071 > u 39064 > e 39005 > o 39005 > n 38995 > j 38993 > h 38975 > q 38958 > c 38938 > b 38906 > g 38894 > i 38847 > m 38819 > v 38712 > z 35321 > y 35228 > w 35189 > x 35075 > > Code: > > import operator > > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)]) The reason is 256 % 26 != 0 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is approx. 10) more often than w-z. You might want to skip the values 0-22 to achieve a truly uniform distribution. FYI: Electronic Cash PINs in europe (dont know about the rest of the world) were computed the same way (random hexdigit and just mod it when it's too large) leading to a high probability that your first digit was a 1 :) Regards, Michael From steve at holdenweb.com Wed Feb 24 12:59:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 12:59:53 -0500 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: mk wrote: > On 2010-02-24 03:50, Paul Rubin wrote: >> The stuff about converting 4 random bytes to a decimal string and then >> peeling off 2 digits at a time is pretty awful, and notice that since >> 2**32 is 4294967296, in the cases where you get 10 digits, the first >> 2-digit pair is never higher than 42. > > Yikes! I didn't think about that. This is probably where (some part of) > probability skewing comes from. > > Anyway, the passwords for authorized users will be copied and pasted > from email into in the application GUI which will remember it for them, > so they will not have to remember and type them in. So I have little in > the way of limitations of password length - even though in *some* cases > somebody might have to (or be ignorant enough) to retype the password > instead of pasting it in. > > In that case the "diceware" approach is not necessary, even though I > will certainly remember this approach for a case when users will have to > remember & type the passwords in. > > The main application will access the data using HTTP (probably), so the > main point is that an attacker is not able to guess passwords using > brute force. > > Using A-z with 10-char password seems to provide 3 orders of magnitude > more combinations than a-z: > >>>> 57 ** 10 > 362033331456891249L >>>> 25 ** 10 > 95367431640625L > > Even though I'm not sure it is worth it, assuming 1000 brute-force > guesses per second (which over the web would amount pretty much to DOS), > this would take # days: > >>>> 57 ** 10 / (1000 * 3600 * 24) > 4190200595L >>>> 25 ** 10 / (1000 * 3600 * 24) > 1103789L > > Even then I'm not getting completely uniform distribution for some reason: > > d 39411 > l 39376 > f 39288 > a 39275 > s 39225 > r 39172 > p 39159 > t 39073 > k 39071 > u 39064 > e 39005 > o 39005 > n 38995 > j 38993 > h 38975 > q 38958 > c 38938 > b 38906 > g 38894 > i 38847 > m 38819 > v 38712 > z 35321 > y 35228 > w 35189 > x 35075 > > Code: > > import operator > > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)]) > > def count_chars(chardict, word): > for c in word: > try: > chardict[c] += 1 > except KeyError: > chardict[c] = 0 > > if __name__ == "__main__": > chardict = {} > for i in range(100000): > w = gen_rand_word(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > >> I'd write your code something like this: >> >> nletters = 5 >> >> def randomword(n): >> with open('/dev/urandom') as f: >> return ''.join([chr(ord('a')+ord(c)%26) for c in f.read(n)]) >> >> print randomword(nletters) > > Aw shucks when will I learn to do the stuff in 3 lines well instead of > 20, poorly. :-/ > When you've got as much experience as Paul? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From deets at nospam.web.de Wed Feb 24 13:12:59 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 19:12:59 +0100 Subject: parametrizing a sqlite query In-Reply-To: References: Message-ID: <4B856C2B.3070502@nospam.web.de> Am 24.02.10 18:07, schrieb Sebastian Bassi: > c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) > > This query returns empty. When it is executed, keywords = 'harvest'. > To check it, I do it on the command line and it works as expected: > > sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; > 11C > 11D > 12F > > I guess there is a problem with the "%". You aren't supposed to put ' into the query. The thing you pass needs to be the full literal. Use c.execute("select ... qtl like :keys", dict(keys="%%%s%%" % keywords)) Diez From mrkafk at gmail.com Wed Feb 24 13:13:28 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 19:13:28 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 18:59, Steve Holden wrote: >> Aw shucks when will I learn to do the stuff in 3 lines well instead of >> 20, poorly. :-/ >> > When you've got as much experience as Paul? And how much experience does Paul have? (this is mostly not a facile question) For my part, my more serious effort (on and off) with programming in Python is under a year. Regards, mk From clp2 at rebertia.com Wed Feb 24 13:16:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Feb 2010 10:16:18 -0800 Subject: Noob raw_input question In-Reply-To: References: Message-ID: <50697b2c1002241016w54c75270n25200a60279d050@mail.gmail.com> On Wed, Feb 24, 2010 at 9:39 AM, Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > ?File "", line 1, in > ? ?a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? raw_input() got renamed to just input(). Please read the 3.x transition docs at http://docs.python.org/3.1/whatsnew/3.0.html Cheers, Chris -- http://blog.rebertia.com From no.email at please.post Wed Feb 24 13:18:27 2010 From: no.email at please.post (kj) Date: Wed, 24 Feb 2010 18:18:27 +0000 (UTC) Subject: What's the word on using """ to comment-out? Message-ID: I think I remember, early in my learning of Python, coming across the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF CODE", or something to that effect. But now I can't find it! Is my memory playing me a trick? After all, from what I've seen since then, the practice of triple-quote-commenting (or TQC, pardon the TCA) is in fact quite common. Is TQC OK after all? If not, what's the case against it? Also, has the BDFL expressed an opinion on the subject? Alternatively, is there any other more or less "authoritative" opinion on TQC? TIA! ~K P.S. I can think of at least one reason to avoid TQC: it has basically the same problems with nesting that C's /**/ has. (Sure, in the case of TQC one could use "the other" triple quote, but it's not hard to see that this workaround goes only so far.) But this reason does not seem to bother many programmers, most of whom, after all, cut their teeth with C and /**/. P.S.2 I'm disregarding "it's un-Pythonic" as a reason against TQC, because it's not the kind of reason that carries much weight out here "in the trenches", as I've discovered. But, yes, I happen to think that TQC is un-Pythonic. After all, in my programming environment, it takes half as many keystrokes to comment a block of code with # than it does with """. I imagine that any decent programming environment makes #-commenting at least as easy. Therefore, there goes convenience as an argument in defense of TQC. Which leaves TMTOWTDI as the only possible defense for TQC, and TMTOWTDI is pretty un-Pythonic, no? :) From robert.kern at gmail.com Wed Feb 24 13:21:08 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 12:21:08 -0600 Subject: Noob raw_input question In-Reply-To: References: Message-ID: On 2010-02-24 11:39 AM, Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > File "", line 1, in > a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? Python 3 changed the name of raw_input() to input() (and the old input() method that evaluates the string was simply thrown out as being redundant and unsafe). http://docs.python.org/dev/3.0/whatsnew/3.0.html -- 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 jjposner at optimum.net Wed Feb 24 13:29:06 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 13:29:06 -0500 Subject: Noob raw_input question In-Reply-To: References: Message-ID: On 2/24/2010 12:39 PM, Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > File "", line 1, in > a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? > > The Python 2 built-in function "raw_input" has been renamed to "input" in Python 3. You'll probably run into this, too: Python 2: print "hello, world" Python 3: print("hello, world") You might want to install Python 2 if you're working your way through a tutorial that's targeted at that "generation" of the language. -John From steve at holdenweb.com Wed Feb 24 13:33:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 13:33:11 -0500 Subject: Noob raw_input question In-Reply-To: References: Message-ID: Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > File "", line 1, in > a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? > > In Python 3 raw_input() is now simply called input() regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From spam at removethis.btinternet.com Wed Feb 24 13:33:26 2010 From: spam at removethis.btinternet.com (Abigail) Date: Wed, 24 Feb 2010 18:33:26 -0000 Subject: Noob raw_input question References: Message-ID: Thank You From mrkafk at gmail.com Wed Feb 24 13:35:11 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 19:35:11 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 18:56, Michael Rudolf wrote: > The reason is 256 % 26 != 0 > 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is > approx. 10) more often than w-z. writing secure code is hard... I'm going to switch to PHP: Python world wouldn't lose much, but PHP would gain a lot. > You might want to skip the values 0-22 > to achieve a truly uniform distribution. Hmm perhaps you meant to skip values over 256 - 22 ? Bc I'm getting this (reduced the run to 1000 generated strings): def gen_rand_word(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > 22]) z 3609 b 3608 s 3567 e 3559 j 3556 r 3555 g 3548 p 3540 m 3538 q 3532 h 3528 y 3526 v 3524 i 3500 x 3496 c 3488 k 3488 l 3487 u 3487 a 3469 o 3465 d 3455 t 3439 f 3437 n 3417 w 3175 While with this: def gen_rand_word(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) < 235]) a 3852 w 3630 s 3623 v 3582 y 3569 p 3568 c 3558 k 3558 b 3556 r 3553 x 3546 m 3534 n 3522 o 3515 h 3510 d 3505 u 3487 t 3486 i 3482 f 3477 e 3474 g 3460 q 3453 l 3437 z 3386 j 3382 1. I'm systematically getting 'a' outlier: have no idea why for now. 2. This is somewhat better (except 'a') but still not uniform. > FYI: Electronic Cash PINs in europe (dont know about the rest of the > world) were computed the same way (random hexdigit and just mod it when > it's too large) leading to a high probability that your first digit was > a 1 :) Schadenfreude is deriving joy from others' misfortunes; what is the German word, if any, for deriving solace from others' misfortunes? ;-) Regards, mk From robert.kern at gmail.com Wed Feb 24 14:01:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 13:01:03 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 12:35 PM, mk wrote: > While with this: > > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > < 235]) > > a 3852 ... > 1. I'm systematically getting 'a' outlier: have no idea why for now. > > 2. This is somewhat better (except 'a') but still not uniform. I will repeat my advice to just use random.SystemRandom.choice() instead of trying to interpret the bytes from /dev/urandom 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 rantingrick at gmail.com Wed Feb 24 14:03:52 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 24 Feb 2010 11:03:52 -0800 (PST) Subject: What's the word on using """ to comment-out? References: Message-ID: <662efb8d-0ae0-4d98-b52e-9cc03ef77d80@k19g2000yqc.googlegroups.com> On Feb 24, 12:18?pm, kj wrote: > I think I remember, early in my learning of Python, coming across > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > LINES OF CODE", or something to that effect. ?But now I can't find > it! Your going to get many opinions on this subject but my stance is -- use quotes for stings and hash chars for comments -- thats the end of it for me ;) From no.email at nospam.invalid Wed Feb 24 14:09:43 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 11:09:43 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7xiq9mtpqg.fsf@ruckus.brouhaha.com> Robert Kern writes: > I will repeat my advice to just use random.SystemRandom.choice() > instead of trying to interpret the bytes from /dev/urandom directly. SystemRandom is something pretty new so I wasn't aware of it. But yeah, if I were thinking more clearly I would have suggested os.urandom instead of opening /dev/urandom. From mrkafk at gmail.com Wed Feb 24 14:09:59 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:09:59 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:01, Robert Kern wrote: > I will repeat my advice to just use random.SystemRandom.choice() instead > of trying to interpret the bytes from /dev/urandom directly. Oh I hear you -- for production use I would (will) certainly consider this. However, now I'm interested in the problem itself: why is the damn distribution not uniform? Regards, mk From mrkafk at gmail.com Wed Feb 24 14:12:09 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:12:09 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: Message-ID: <4B857A09.7040707@gmail.com> Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment). Regards, mk From mrkafk at gmail.com Wed Feb 24 14:12:09 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:12:09 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: Message-ID: <4B857A09.7040707@gmail.com> Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment). Regards, mk From mrkafk at gmail.com Wed Feb 24 14:16:24 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:16:24 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:01, Robert Kern wrote: > I will repeat my advice to just use random.SystemRandom.choice() instead > of trying to interpret the bytes from /dev/urandom directly. Out of curiosity: def gen_rand_string(length): prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) return ''.join(chars) if __name__ == "__main__": chardict = {} for i in range(10000): ## w = gen_rand_word(10) w = gen_rand_string(10) count_chars(chardict, w) counts = list(chardict.items()) counts.sort(key = operator.itemgetter(1), reverse = True) for char, count in counts: print char, count s 3966 d 3912 g 3909 h 3905 a 3901 u 3900 q 3891 m 3888 k 3884 b 3878 x 3875 v 3867 w 3864 y 3851 l 3825 z 3821 c 3819 e 3819 r 3816 n 3808 o 3797 f 3795 t 3784 p 3765 j 3730 i 3704 Better, although still not perfect. Regards, mk From robert.kern at gmail.com Wed Feb 24 14:19:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 13:19:23 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 13:09 PM, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Oh I hear you -- for production use I would (will) certainly consider > this. However, now I'm interested in the problem itself: why is the damn > distribution not uniform? You want "< 234", not "< 235". (234 % 26 == 0), so you get some extra 'a's. -- 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 aahz at pythoncraft.com Wed Feb 24 14:26:36 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 11:26:36 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: In article <87sk8r5v2f.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> Joan Miller is a regular poster; this is off-topic, but it's not spam. > >Non sequitur. Spam is spam, not by who authors or posts it, but by its >distribution (to many people, e.g. via a forum like this one) and its >content (off-topic and unsolicited). > >The message is important, its poster is a regular here; that doesn't >stop the message being spam when posted here. That seems to miss the point to some extent. If I post my recipe for spinach lasagne here, is that spam? I don't think many people would call it spam, just an off-topic post. From my POV, spam is defined a bit more narrowly. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 14:27:36 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 11:27:36 -0800 Subject: What's the word on using """ to comment-out? References: Message-ID: In article , kj wrote: > >I think I remember, early in my learning of Python, coming across the >commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF >CODE", or something to that effect. But now I can't find it! > >Is my memory playing me a trick? Possibly. I certainly do that. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From spamfresser at ch3ka.de Wed Feb 24 14:30:40 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 20:30:40 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: Am 24.02.2010 19:35, schrieb mk: > On 2010-02-24 18:56, Michael Rudolf wrote: > >> The reason is 256 % 26 != 0 >> 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is >> approx. 10) more often than w-z. > > writing secure code is hard... So true. That's why one should stick to standard libs when it comes to crypto or security in general. It's just to easy to mess it up. Just ask Debian about whether touching OpenSSL was a good idea ;) >> You might want to skip the values 0-22 >> to achieve a truly uniform distribution. > Hmm perhaps you meant to skip values over 256 - 22 ? That's the same thing as x mod y equals x+N*y mod y for every natural N. > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > > 22]) Off-by-one-error: you're skipping len(range(22))==23 hits. OK, I just see that I wrote misleading 0-22 while I meant range(22). > While with this: > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > < 235]) Same off-by-one. >> FYI: Electronic Cash PINs in europe (dont know about the rest of the >> world) were computed the same way (random hexdigit and just mod it when >> it's too large) leading to a high probability that your first digit was >> a 1 :) > Schadenfreude is deriving joy from others' misfortunes; what is the > German word, if any, for deriving solace from others' misfortunes? ;-) Well - "Schadenfreude" *is* in fact a german word :) "Schaden" is the event or result of misfortune, "Freude" is joy. Well, I really think that you should use repeated Random.choice on an alphabet. Or Random.Systemrandom.choice if you don't trust the PRNG. Regards, Michael From no.email at nospam.invalid Wed Feb 24 14:31:51 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 11:31:51 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7xeikatopk.fsf@ruckus.brouhaha.com> mk writes: > So I have little in the way of limitations of password length ...> > The main application will access the data using HTTP (probably), so > the main point is that an attacker is not able to guess passwords > using brute force. If it's HTTP instead of HTTPS and you're sending the password in the clear, then a serious attacker can simply eavesdrop the connection and pick up the password. Again, if the application is a web forum or something like that, the security requirements probably aren't terribly high. If it's (say) a financial application with potentially motivated attackers, you've got to be a lot more careful than I think you're being right now, and you should really get security specialists involved. > Using A-z with 10-char password seems to provide 3 orders of magnitude > more combinations than a-z: Yes, 2**10 = 1024 so (57/25)**10 is a little more than that. > Even then I'm not getting completely uniform distribution for some reason: Exact equality of the counts would be surprising and a sign that something was wrong with the generation process. It would be like flipping a coin 10000 times and getting exactly 5000 heads. The binomial distribution tells you that the number should be close to 5000, but that it's unlikely to be -exactly- 5000. Also, as Michael Rudolf mentioned, getting a letter by taking n%26 where n is drawn uniformly from [0..255] doesn't give a uniform distribution because 256 is not a multiple of 26. I had thought about making an adjustment for that when I posted, but it didn't seem worth cluttering up the code. Uniformity for its own sake doesn't gain you anything; what matters is entropy. If you compute the entropy difference between the slightly nonuniform distribution and a uniform one, it's very small. To get a more uniform distribution I usually just take a larger n, rather than conditionalizing the draws. For example, in the diceware-like code I posted, I read 10 random bytes (giving a uniform random number on [0..2**80]) from urandom for each word. That is still not perfectly uniform, but it's closer to the point where the difference would be very hard to detect. > Aw shucks when will I learn to do the stuff in 3 lines well instead of > 20, poorly. :-/ Well, that's partly a matter of practice, but I'll mention one way I simplified the code, which was by reading more bytes from /dev/urandom than was really necessary. I read one byte for each random letter (i.e. throwing away about 3 random bits for each letter) while you tried to encode the urandom data cleverly and map 4 random bytes to 5 alphabetic letters. /dev/urandom uses a cryptographic PRNG and it's pretty fast, so reading a few extra bytes from it to simplify your code doesn't really cost you anything. From robert.kern at gmail.com Wed Feb 24 14:36:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 13:36:29 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 13:16 PM, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Out of curiosity: > > def gen_rand_string(length): > prng = random.SystemRandom() > chars = [] > for i in range(length): > chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) > return ''.join(chars) > > if __name__ == "__main__": > chardict = {} > for i in range(10000): > ## w = gen_rand_word(10) > w = gen_rand_string(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > > > s 3966 > d 3912 > g 3909 > h 3905 > a 3901 > u 3900 > q 3891 > m 3888 > k 3884 > b 3878 > x 3875 > v 3867 > w 3864 > y 3851 > l 3825 > z 3821 > c 3819 > e 3819 > r 3816 > n 3808 > o 3797 > f 3795 > t 3784 > p 3765 > j 3730 > i 3704 > > Better, although still not perfect. This distribution is well within expectations. -- 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 mrkafk at gmail.com Wed Feb 24 15:02:07 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 21:02:07 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:19, Robert Kern wrote: > On 2010-02-24 13:09 PM, mk wrote: >> On 2010-02-24 20:01, Robert Kern wrote: >>> I will repeat my advice to just use random.SystemRandom.choice() instead >>> of trying to interpret the bytes from /dev/urandom directly. >> >> Oh I hear you -- for production use I would (will) certainly consider >> this. However, now I'm interested in the problem itself: why is the damn >> distribution not uniform? > > You want "< 234", not "< 235". (234 % 26 == 0), so you get some extra 'a's. Right, this explains the 'a' outlier. Fixed. But still: import operator import os import random import math def rand_str_custom(n): s = os.urandom(n) return ''.join([chr(ord('a') + ord(x) % 26) for x in s if ord(x) < 234]) def count_chars(chardict, word): for c in word: try: chardict[c] += 1 except KeyError: chardict[c] = 0 def rand_str_SystemRandom_seeding(length): seed = os.urandom(32) random.seed(seed) prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) return ''.join(chars) def rand_str_SystemRandom_noseeding(length): prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) return ''.join(chars) def sd(x): sd.sum += x sd.sum2 += x*x sd.n += 1.0 sum, sum2, n = sd.sum, sd.sum2, sd.n return math.sqrt(sum2/n - sum*sum/n/n) def gen_rand_with_fun(fun): print fun.__name__ chardict = {} for i in range(10000): w = fun(10) count_chars(chardict, w) counts = list(chardict.items()) counts.sort(key = operator.itemgetter(1), reverse = True) nums = [c[1] for c in counts] sd.sum = sd.sum2 = sd.n = 0 mean = (1.0*sum(nums))/len(nums) stddev = map(sd, nums)[-1] print 'mean', mean, 'std dev', stddev for char, count in counts: print char, count, '%.2f' % ((count - mean)/stddev), 'std devs away from mean' if __name__ == "__main__": gen_rand_with_fun(rand_str_SystemRandom_seeding) print gen_rand_with_fun(rand_str_SystemRandom_noseeding) print gen_rand_with_fun(rand_str_custom) rand_str_SystemRandom_seeding mean 3845.15384615 std dev 46.2016419186 l 3926 1.75 std devs away from mean y 3916 1.53 std devs away from mean d 3909 1.38 std devs away from mean a 3898 1.14 std devs away from mean p 3898 1.14 std devs away from mean c 3889 0.95 std devs away from mean u 3884 0.84 std devs away from mean j 3873 0.60 std devs away from mean n 3873 0.60 std devs away from mean w 3866 0.45 std devs away from mean x 3863 0.39 std devs away from mean r 3855 0.21 std devs away from mean m 3852 0.15 std devs away from mean b 3841 -0.09 std devs away from mean t 3835 -0.22 std devs away from mean o 3829 -0.35 std devs away from mean k 3827 -0.39 std devs away from mean i 3821 -0.52 std devs away from mean s 3812 -0.72 std devs away from mean q 3806 -0.85 std devs away from mean v 3803 -0.91 std devs away from mean g 3799 -1.00 std devs away from mean h 3793 -1.13 std devs away from mean e 3782 -1.37 std devs away from mean f 3766 -1.71 std devs away from mean z 3758 -1.89 std devs away from mean rand_str_SystemRandom_noseeding mean 3845.15384615 std dev 55.670522726 i 3961 2.08 std devs away from mean r 3911 1.18 std devs away from mean e 3910 1.16 std devs away from mean m 3905 1.08 std devs away from mean a 3901 1.00 std devs away from mean u 3893 0.86 std devs away from mean t 3882 0.66 std devs away from mean w 3872 0.48 std devs away from mean s 3870 0.45 std devs away from mean c 3868 0.41 std devs away from mean n 3866 0.37 std devs away from mean q 3865 0.36 std devs away from mean k 3863 0.32 std devs away from mean y 3848 0.05 std devs away from mean j 3836 -0.16 std devs away from mean v 3830 -0.27 std devs away from mean f 3829 -0.29 std devs away from mean z 3829 -0.29 std devs away from mean g 3827 -0.33 std devs away from mean l 3818 -0.49 std devs away from mean b 3803 -0.76 std devs away from mean d 3803 -0.76 std devs away from mean p 3756 -1.60 std devs away from mean x 3755 -1.62 std devs away from mean h 3744 -1.82 std devs away from mean o 3729 -2.09 std devs away from mean rand_str_custom mean 3517.15384615 std dev 40.7541336343 i 3586 1.69 std devs away from mean a 3578 1.49 std devs away from mean e 3575 1.42 std devs away from mean m 3570 1.30 std devs away from mean q 3562 1.10 std devs away from mean c 3555 0.93 std devs away from mean g 3552 0.86 std devs away from mean w 3542 0.61 std devs away from mean p 3536 0.46 std devs away from mean x 3533 0.39 std devs away from mean s 3528 0.27 std devs away from mean o 3524 0.17 std devs away from mean d 3516 -0.03 std devs away from mean t 3515 -0.05 std devs away from mean h 3511 -0.15 std devs away from mean v 3502 -0.37 std devs away from mean z 3502 -0.37 std devs away from mean b 3500 -0.42 std devs away from mean f 3496 -0.52 std devs away from mean u 3492 -0.62 std devs away from mean l 3486 -0.76 std devs away from mean r 3478 -0.96 std devs away from mean n 3476 -1.01 std devs away from mean j 3451 -1.62 std devs away from mean k 3450 -1.65 std devs away from mean y 3430 -2.14 std devs away from mean It would appear that SystemRandom().choice is indeed best (in terms of how much the counts stray from mean in std devs), but only after seeding it with os.urandom. Regards, mk From mrkafk at gmail.com Wed Feb 24 15:06:00 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 21:06:00 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:30, Michael Rudolf wrote: >>> The reason is 256 % 26 != 0 >>> 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is >>> approx. 10) more often than w-z. >> >> writing secure code is hard... > > So true. That's why one should stick to standard libs when it comes to > crypto or security in general. It's just to easy to mess it up. Just ask > Debian about whether touching OpenSSL was a good idea ;) That was brain-dead hiccup, for crying out loud how could they do smth so stupid. >> def gen_rand_word(n): >> with open('/dev/urandom') as f: >> return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) >> > 22]) > > Off-by-one-error: you're skipping len(range(22))==23 hits. Argh, it's late here. > Well, I really think that you should use repeated Random.choice on an > alphabet. > Or Random.Systemrandom.choice if you don't trust the PRNG. I just posted a comparison with calculating std deviations for various methods - using os.urandom, SystemRandom.choice with seeding and without seeding. They all seem to have slightly different distributions. Regards, mk From no.email at nospam.invalid Wed Feb 24 15:09:54 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 12:09:54 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7x3a0qpf8t.fsf@ruckus.brouhaha.com> mk writes: > def rand_str_custom(n): > s = os.urandom(n) > return ''.join([chr(ord('a') + ord(x) % 26) for x in s if ord(x) < 234]) Note that simply throws away some of the chars. You have to replace them, not throw them away. > rand_str_SystemRandom_seeding > mean 3845.15384615 std dev 46.2016419186 > l 3926 1.75 std devs away from mean > y 3916 1.53 std devs away from mean ... What do you think you're measuring here? Yes, if you're doing 1000's of draws from a distribution, you'd expect a few of them to be 1.75 sigma from the mean. Since there are 26 letters, you'd expect a multinomial distribution which you can test for with the multinomial test or some approximation from the article: http://en.wikipedia.org/wiki/Multinomial_test I wish I knew more statistics than I do, since there is probably some more familiar statistical test (e.g. the T-test) that you can use as the number of trials gets large, since each bin of the multinomial distribution should eventually start to look like a normal distribution due to the central limit theorem. Others here know a lot more about this stuff than I do, and can probably give better advice. Anyway though, the output of os.urandom should be extremely hard to distinguish from real randomness (that's the whole point of a cryptographic PRNG). From skylarking11 at gmail.com Wed Feb 24 15:15:30 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 24 Feb 2010 12:15:30 -0800 (PST) Subject: Trouble with ftplib uploading to an FTP server Message-ID: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> This bit of code is designed to get the external IP address and hostname of a client , write it locally to a file, then upload to an FTP server. It works locally( one can see the IP number and hostname with a time stamp in /Users/admin/Documents) , but when the file is opened on the server after it's FTP'ed , it's blank....I think my issue is something with the way I am utilizing the ftplib commands... I am pretty sure instead of FTPing the file, it's just creating a new one with the same name and uploading that? This script is running on some OS X 10.5 clients and reporting back to an Ubuntu 8.04 server...I am using the version of python bundled with 10.5.x ( 2.5.1 ) **************************************************************** import os import datetime import ftplib import urllib2 currdate = datetime.datetime.now() formatdate = currdate.strftime("%m-%d-%Y %H%M") def log(): fqn = os.uname()[1] ext_ip = urllib2.urlopen('http://whatismyip.org').read() log = open ('/Users/admin/Documents/locatelog.txt','w') log.write(str("Asset: %s " % fqn)) log.write(str("Checking in from IP#: %s" % ext_ip)) smush = str(fqn +' @ ' + formatdate) os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ Documents/%s.txt' % smush ) s = ftplib.FTP('10.7.1.71','username','password') fd = open('/Users/admin/Documents/%s.txt' % smush,'rb') s.storbinary("STOR %s.txt" % smush , fd) ***************************************************************************** From robert.kern at gmail.com Wed Feb 24 15:20:37 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 14:20:37 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 14:02 PM, mk wrote: > It would appear that SystemRandom().choice is indeed best (in terms of > how much the counts stray from mean in std devs), but only after seeding > it with os.urandom. Calling random.seed() does not affect SystemRandom() whatsoever. You are getting perfectly acceptable distributions for all three variants. -- 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 andrewpdavison at gmail.com Wed Feb 24 15:21:21 2010 From: andrewpdavison at gmail.com (Andrew Davison) Date: Wed, 24 Feb 2010 12:21:21 -0800 (PST) Subject: Artificial Neural Networks recommendation References: Message-ID: On Feb 24, 1:49?pm, Gereon Kaiping wrote: > - - PyNN (just a builder, requires external simulator) ?http://neuralensemble.org/trac/PyNN/ > - - Con-x (part of pyro) ?http://pyrorobotics.org/?page=Conx > - - PyNeurGen (includes genetic algorithms) ?http://pyneurgen.sourceforge.net/ > - - ffnet (only fast forward) ?http://ffnet.sourceforge.net/ > - - brian (spiking networks) ?http://www.briansimulator.org/ > - - PyBrain (machine learning) ?http://pybrain.org/ > > Can you give me a recommendation or a review on some of these? PyNN and Brian are intended more for biologically-realistic neural networks (for some value of realistic), aka neuronal networks, so I guess you can rule them out (similar tools that you might come across are NEST, NEURON, PCSIM). Cheers, Andrew From usenot at geekmail.INVALID Wed Feb 24 15:23:03 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 24 Feb 2010 21:23:03 +0100 Subject: Docstrings considered too complicated Message-ID: <20100224212303.242222c6@geekmail.INVALID> Hi all, a company that works with my company writes a lot of of their code in Python (lucky jerks). I've seen their code and it basically looks like this: """Function that does stuff""" def doStuff(): while not wise(up): yield scorn Now my question is this: How do I kill these people without the authorities thinking they didn't deserve it? /W -- INVALID? DE! From brixomatic at yahoo.com Wed Feb 24 15:40:10 2010 From: brixomatic at yahoo.com (Wanja Gayk) Date: Wed, 24 Feb 2010 21:40:10 +0100 Subject: When will Java go mainstream like Python? References: Message-ID: Am 24.02.2010, 00:22 Uhr, schrieb Lawrence D'Oliveiro : >> Java - The JVM code been hacked to death by Sun engineers (optimised) >> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >> ad-infinitum but nowhere as near to JVM > > Python is still faster, though. In synthetic microbenchmarks without any practical importance - possibly. > I think a key reason is that its VM supports > reference-counting, which the Java folks never quite got the grasp of. Reference counting is about the worst technique for garbage collection. Modern Java VM won't count references. They will just trace the active references from the rootand mark all objects it finds as active and save these. The remaining ones are garbage. The reason why this is faster is that there are usually less live objects than dead ones and there are less refereces to look at. kind regards W -- Erstellt mit Operas revolution?rem E-Mail-Modul: http://www.opera.com/mail/ --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From python at mrabarnett.plus.com Wed Feb 24 15:56:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Feb 2010 20:56:06 +0000 Subject: Trouble with ftplib uploading to an FTP server In-Reply-To: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> References: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> Message-ID: <4B859266.5090201@mrabarnett.plus.com> Sky Larking wrote: > This bit of code is designed to get the external IP address and > hostname of a client , write it locally to a file, then upload to an > FTP server. It works locally( one can see the IP number and hostname > with a time stamp in /Users/admin/Documents) , but when the file is > opened on the server after it's FTP'ed , it's blank....I think my > issue is something with the way I am utilizing the ftplib commands... > I am pretty sure instead of FTPing the file, it's just creating a new > one with the same name and uploading that? > > This script is running on some OS X 10.5 clients and reporting back to > an Ubuntu 8.04 server...I am using the version of python bundled with > 10.5.x ( 2.5.1 ) > > **************************************************************** > import os > import datetime > import ftplib > import urllib2 > > > currdate = datetime.datetime.now() > formatdate = currdate.strftime("%m-%d-%Y %H%M") > > def log(): > > fqn = os.uname()[1] > ext_ip = urllib2.urlopen('http://whatismyip.org').read() > log = open ('/Users/admin/Documents/locatelog.txt','w') > log.write(str("Asset: %s " % fqn)) > log.write(str("Checking in from IP#: %s" % ext_ip)) > smush = str(fqn +' @ ' + formatdate) > os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ > Documents/%s.txt' % smush ) You're renaming the file while it's still open. What you've written is still in the buffer, not on disk. > s = ftplib.FTP('10.7.1.71','username','password') > fd = open('/Users/admin/Documents/%s.txt' % smush,'rb') > s.storbinary("STOR %s.txt" % smush , fd) > > ***************************************************************************** > From spamfresser at ch3ka.de Wed Feb 24 16:00:19 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 22:00:19 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: Am 24.02.2010 21:06, schrieb mk: > > I just posted a comparison with calculating std deviations for various > methods - using os.urandom, SystemRandom.choice with seeding and without > seeding. I saw them > They all seem to have slightly different distributions. No they don't. Just run those tests again and you will see that you cannot put them in any order or behaviour. They are all correct now, except that you cannot seed SystemRandom, as it is *not* a PRNG (at least here, it is a wrapper for /dev/random) Regards, Michael From steve at holdenweb.com Wed Feb 24 16:06:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 16:06:22 -0500 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: Aahz wrote: > In article <87sk8r5v2f.fsf at benfinney.id.au>, > Ben Finney wrote: >> aahz at pythoncraft.com (Aahz) writes: >>> Joan Miller is a regular poster; this is off-topic, but it's not spam. >> Non sequitur. Spam is spam, not by who authors or posts it, but by its >> distribution (to many people, e.g. via a forum like this one) and its >> content (off-topic and unsolicited). >> >> The message is important, its poster is a regular here; that doesn't >> stop the message being spam when posted here. > > That seems to miss the point to some extent. If I post my recipe for > spinach lasagne here, is that spam? I don't think many people would call > it spam, just an off-topic post. From my POV, spam is defined a bit more > narrowly. Spam is, at least from my point of view, UCE: unsolicited commercial e-mail. So anything that isn't commercial (like those "send these to ten of your friends" emails) isn't spam (but it might just as well be). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From news123 at free.fr Wed Feb 24 16:21:59 2010 From: news123 at free.fr (News123) Date: Wed, 24 Feb 2010 22:21:59 +0100 Subject: Help with lambda In-Reply-To: <39ded391-c814-4c17-936f-3a4f55c3d9ec@b9g2000pri.googlegroups.com> References: <39ded391-c814-4c17-936f-3a4f55c3d9ec@b9g2000pri.googlegroups.com> Message-ID: <4b859877$0$23912$426a74cc@news.free.fr> Jonathan Gardner wrote: > On Feb 18, 4:28 am, lallous wrote: >> f = [lambda x: x ** n for n in xrange(2, 5)] > > This is (pretty much) what the above code does. > >>>> f = [] >>>> n = 2 >>>> f.append(lambda x: x**n) >>>> n = 3 >>>> f.append(lambda x: x**n) >>>> n = 4 >>>> f.append(lambda x: x**n) >>>> n = 5 >>>> f.append(lambda x: x**n) > > Now, when you call f[0], you are calling "lambda x: x**n". What is > "n"? > If you use a newer version of python (>= 2.5), then you might want to look at functools.partial. > def pow(a,n): > return a ** n > > f = [functools.partial(pow,n=n) for n in xrange(2, 5)] > Not sure, whether there's any (dis)advantage over > f = [lambda x,n=n: x ** n for n in xrange(2, 5)] or > f = [lambda x,n=n: pow(x,n) for n in xrange(2, 5)] bye N From tjreedy at udel.edu Wed Feb 24 16:29:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Feb 2010 16:29:18 -0500 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: <20100224101423.GA27668@axis.g33x.de> References: <20100224101423.GA27668@axis.g33x.de> Message-ID: On 2/24/2010 5:14 AM, Lars Gust?bel wrote: > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: >> I stumbled uppon this and find it somewhat odd: some class methods of >> TarFile and TarInfo do not appears in either the online documentation or >> search while they have a doc string: >> >> http://docs.python.org/search.html?q=gzopen >> http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile >> >> See script at the end for list of class methods. >> >> Is this "by design" or is there some an odd bug in doc generation lurking >> around? This somehow seem to be specific to module tarfile. Fraction >> classmethod from_float() is available in the documentation and found by a >> search for example... > > First of all, Python's module documentation is not generated from module > docstrings, each module has its own rst text file in the documentation tree > instead. > > But to answer your question: Yes, this is intentional. The TarFile class has > three classmethods taropen(), gzopen(), and bz2open() each for a specific > compression method. These three are used internally by the TarFile.open() > classmethod and are not intended to be called directly. The TarFile.open() > method is the one that is publicly documented and supposed to be used. It > decides which of the three methods to use based on the mode argument and > does many more other high-level things as well. By current standards, the three private methods should be prefixed with '_' to indicate their private status. Could they be changed to head off such questions? Terry Jan Reedy From deets at nospam.web.de Wed Feb 24 16:39:44 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 22:39:44 +0100 Subject: python dowload In-Reply-To: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <7ulkl0F6acU1@mid.uni-berlin.de> Am 24.02.10 00:08, schrieb monkeys paw: > On 2/23/2010 3:17 PM, Tim Chase wrote: >> monkeys paw wrote: >>> I used the following code to download a PDF file, but the >>> file was invalid after running the code, is there problem >>> with the write operation? >>> >>> import urllib2 >>> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >>> a = open('adobe.pdf', 'w') >> >> Sure you don't need this to be 'wb' instead of 'w'? > > 'wb' does the trick. Thanks all! > > Here is the final working code, i used an index(i) > to see how many reads took place, i have to assume there is > a default buffer size: > > import urllib2 > a = open('adobe.pdf', 'wb') > i = 0 > for line in > urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): > > i = i + 1 > a.write(line) > > print "Number of reads: %d" % i > a.close() > > > NEW QUESTION if y'all are still reading: > > Is there an integer increment operation in Python? I tried > using i++ but had to revert to 'i = i + 1' Instead, use enumerate: for i, line in enumerate(...): ... Diez From deets at nospam.web.de Wed Feb 24 16:50:04 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 22:50:04 +0100 Subject: compiling python question In-Reply-To: References: Message-ID: <4B859F0C.1060308@nospam.web.de> Am 24.02.10 03:00, schrieb Mag Gam: > I am trying to compile python with Tk bindings. Do I need to do > anything special for python to detect and enable Tk? What OS? What does the configure/build process say? Diez From arnodel at googlemail.com Wed Feb 24 16:52:26 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 24 Feb 2010 21:52:26 +0000 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: aahz at pythoncraft.com (Aahz) writes: > In article <87sk8r5v2f.fsf at benfinney.id.au>, > Ben Finney wrote: >>aahz at pythoncraft.com (Aahz) writes: >>> >>> Joan Miller is a regular poster; this is off-topic, but it's not spam. >> >>Non sequitur. Spam is spam, not by who authors or posts it, but by its >>distribution (to many people, e.g. via a forum like this one) and its >>content (off-topic and unsolicited). >> >>The message is important, its poster is a regular here; that doesn't >>stop the message being spam when posted here. > > That seems to miss the point to some extent. If I post my recipe for > spinach lasagne here, is that spam? Are they really good? Sounds good, spinach lasagne, I don't know a recipe for them. Maybe you could post it as Python code, with a lot of nested if-then-else clauses, of course :) -- Arnaud From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 16:54:25 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 10:54:25 +1300 Subject: Problem creating executable, with PyQwt References: Message-ID: David Boddie wrote: > On Tuesday 23 February 2010 05:32, Gib Bogle wrote: > >> David Boddie wrote: >> >>> I have previously referred people with py2exe/PyQt issues to this page on >>> the PyQt Wiki: >>> >>> http://www.py2exe.org/index.cgi/Py2exeAndPyQt >>> >>> If you can somehow convince py2exe to include the QtSvg module (and >>> presumably the libQtSvg library as well) then perhaps that will solve >>> this problem. >>> >>> David >> Thanks David, that worked a treat. :-) > > If you could update the Wiki (or maybe the py2exe Wiki, if they have one) > to say what you did, that would be useful for others in the future. Then > they'll only be one search away from the answer. :-) > > David OK, I'll put it on the to-do list. Gib From jgardner at jonathangardner.net Wed Feb 24 16:54:52 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 24 Feb 2010 13:54:52 -0800 Subject: Docstrings considered too complicated In-Reply-To: <20100224212303.242222c6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> On Wed, Feb 24, 2010 at 12:23 PM, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ?while not wise(up): > ? ? ? ?yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? > kill -9 seems to work for me. You may want to explain, one day, why what they are doing is wrong. -- Jonathan Gardner jgardner at jonathangardner.net From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 16:59:18 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 10:59:18 +1300 Subject: Files required for porting python References: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Message-ID: KIRAN wrote: "I see lot of code with several files." I had to laugh at this. From no.email at please.post Wed Feb 24 17:35:31 2010 From: no.email at please.post (kj) Date: Wed, 24 Feb 2010 22:35:31 +0000 (UTC) Subject: How to monitor memory usage within Python? (Linux) Message-ID: Is there some standard module for getting info about the process's memory usage, in a Linux/Unix system? (I want to avoid hacks that involve, e.g., scraping ps's output.) Thanks! ~K From dontsendleospam at gmail.com Wed Feb 24 17:37:42 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Wed, 24 Feb 2010 14:37:42 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Hi Folks, Thanks everyone for the great contributions! I understand this better now. The distinction between a shorthand for a function definition and a shorthand for a loop iteration is crucial. Also: thanks for pointing out the even the list comprehension doesn't work in py3. That was incredibly useful! I was about to build a package using Python and now (unfortunately) I will have to find another language. Saved me a big headache! More details... > > I can't reproduce the error message that you cite. > Sorry, I made a cut and paste error in my first post. The error was exactly the one in your post. > Reason for the NameError: > > The above is a /generator expression/, evaluated in a class definition. > > The docs have a similar example but I'm sorry, I'm unable to find it! Anyway the > generator expression is evaluated as if its code was put in function. And from > within the scope of that function you can't access the class scope implicitly, > hence, no access to 'B'. > > > This is a /list comprehension/, not a generator expression (although > syntactically it's almost the same). > > It obeys different rules. > > Essentially the generator expression produces a generator object that you may > name or pass around as you wish, while the comprehension is just a syntactical > device for writing more concisely some equivalent code that's generated inline. > > However, apparently the rules changed between Python 2.x and Python 3.x. > > In Python 3.x also the list comprehension fails in a class definition: > > C:\test> py3 > Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum([(i*j) for i in A for j in B]) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() Yuck! Why should the list comprehension fail in Py3? The scope rules that explain why the generator expression would fail don't apply in that case. Plus Guido's comment on generators being consumed quickly also doesn't apply. > > ?From one point of view it's good that Py3 provides about the same behavior for > generator expressions and list comprehensions. > > But I'd really like the above examples to Just Work. :-) > Absolutely agreed. Especially with the list comprehension. I read PEP 289 and the 2004 exchanges in the mailing list regarding scoping and binding issues in generator expressions, when this feature was added to the language. Forgive my blasphemy, but Guido got it wrong on this one, by suggesting that an obscure use case should drive design considerations when a far more common use case exists. The obscure use case involves confusing sequences of exceptions, while the common use case is consistent scope rules at different levels. For details search the mailing list for Guido's quote in PEP 289. Here is another example that fails... In [7]: class T: ...: A = range(2) ...: B = range(2,4) ...: g = (i*j for i in A for j in B) ...: s = sum(g) --------------------------------------------------------------------------- NameError Traceback (most recent call last) C:\Python26\ in () C:\Python26\ in T() C:\Python26\ in ((i,)) NameError: global name 'B' is not defined ... at sum(g)! These two examples work (doing the same thing at a global scope and a local scope): In [1]: class T: ...: def local(self): ...: A = range(2) ...: B = range(2,4) ...: g = (i*j for i in A for j in B) ...: s = sum(g) ...: In [2]: t = T() In [3]: t.local() In [4]: A = range(2) In [5]: B = range(2,4) In [6]: g = (i*j for i in A for j in B) In [7]: s = sum(g) Thanks to everyone who suggested workarounds. They are very helpful. At the same time, they are -- forgive my language -- so perlish (as in clever, and requiring deep understanding of the language). In Python, simple elegant constructs should work consistently across all scopes. The very fact that people chose to use the word 'workaround' indicates how quirky this aspect of the language is. It really doesn't need to be so quirky. Defining the semantics of generator expressions to mimic Arnaud's lambda workaround below would be just as justified as the current definition, and more pythonic (in the consistent, elegant sense). @Arnaud: I tried to find your earlier post -- googled "Arnaud lambda" -- but couldn't. Does anyone know of a more recent PEP that addresses these issues? Thanks, Leo. From cmpython at gmail.com Wed Feb 24 17:41:03 2010 From: cmpython at gmail.com (CM) Date: Wed, 24 Feb 2010 14:41:03 -0800 (PST) Subject: What's the word on using """ to comment-out? References: Message-ID: <4ed45391-dc4f-43ef-ab56-6743e71a31a0@o30g2000yqb.googlegroups.com> > After all, from what I've seen since then, the practice of > triple-quote-commenting (or TQC, pardon the TCA) is in fact quite > common. > > Is TQC OK after all? > > If not, what's the case against it? I have no sense of how approved it is, and don't have a strong opinion on it, but I would think that some cases against it could be: - It's used for docstrings, so when you scan code it is harder to instantly find comment blocks or docstrings if IDE parsers color code comments differently than docstrings. An IDE I use (Boa Constructor) uses "# XXX [comment]" as a comment that means "add to the to-do list" as well. - If you want to search for comments easily, you can search for #, which will probably only bring you to comments, whereas if you search for quote marks, they could be used in a number of different ways in the code. - Adhering to coding conventions is a good thing in open source applications. From deets at nospam.web.de Wed Feb 24 17:48:54 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 23:48:54 +0100 Subject: How to monitor memory usage within Python? (Linux) In-Reply-To: References: Message-ID: <7ulomnFtk5U1@mid.uni-berlin.de> Am 24.02.10 23:35, schrieb kj: > Is there some standard module for getting info about the process's > memory usage, in a Linux/Unix system? > > (I want to avoid hacks that involve, e.g., scraping ps's output.) http://code.google.com/p/pympler/ Diez From aahz at pythoncraft.com Wed Feb 24 17:58:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 14:58:17 -0800 Subject: How to make an empty generator? References: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: In article , Terry Reedy wrote: > >Confusing generators and generator functions is, well, confusing. >For future reference, and clarity of communication in Pythonland, > >generator function: function that produces a generator when called; if >python coded, its body contains 'yield'. > >generator: iterator produced by a generator function; has .__next__ and >self-returning .__init__, like all other iterators. > >generator expression: an expression that evaluates to a generator; the >expression is used to create a temporary anonymous generator function >that is called to produce the generator and is then discarded. My preference is to use the terms "generator" and "generator iterator" (abbreviated "gen iter" or "geniter"). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 18:01:02 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:01:02 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: In article , Steve Holden wrote: >Aahz wrote: >> In article <87sk8r5v2f.fsf at benfinney.id.au>, >> Ben Finney wrote: >>> aahz at pythoncraft.com (Aahz) writes: >>>> >>>> Joan Miller is a regular poster; this is off-topic, but it's not spam. >>> >>> Non sequitur. Spam is spam, not by who authors or posts it, but by its >>> distribution (to many people, e.g. via a forum like this one) and its >>> content (off-topic and unsolicited). >>> >>> The message is important, its poster is a regular here; that doesn't >>> stop the message being spam when posted here. >> >> That seems to miss the point to some extent. If I post my recipe for >> spinach lasagne here, is that spam? I don't think many people would call >> it spam, just an off-topic post. From my POV, spam is defined a bit more >> narrowly. > >Spam is, at least from my point of view, UCE: unsolicited commercial >e-mail. So anything that isn't commercial (like those "send these to ten >of your friends" emails) isn't spam (but it might just as well be). That's roughly correct, but I also think that if someone posts the same message to five mailing lists, it's not unreasonable to call that spamming. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 18:01:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:01:52 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: In article <87sk8r5v2f.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> Joan Miller is a regular poster; this is off-topic, but it's not spam. > >Non sequitur. Spam is spam, not by who authors or posts it, but by its >distribution (to many people, e.g. via a forum like this one) and its >content (off-topic and unsolicited). > >The message is important, its poster is a regular here; that doesn't >stop the message being spam when posted here. Moreover, by your definition, your post above counts as spam. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 18:05:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:05:09 -0800 Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: In article , Ryan Kelly wrote: > >Yes. The idea of having a "bootstrapping exe" is that actual >application code can be swapped out without having to overwrite the >executable file. As long as you don't change python versions, this >allows updates to be safe against system crashes, even on platforms >without atomic file replacement. > >So the frozen app does this in a background thread: > > Esky(sys.executable,"http://my.updates.com").auto_update() > >And it hits the given url, grabs the latest zipfile, downloads and >unpacks and atomically places it into the application directory. Et >viola, your app is at the latest version. How does this work with a running app? What if the app is a service? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From deets at nospam.web.de Wed Feb 24 18:05:35 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 00:05:35 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <7ulpm0F3kiU1@mid.uni-berlin.de> Am 24.02.10 12:42, schrieb Michael Rudolf: > First: Thanks for all the replies so far, they really helped me. > > Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >>> >>> def a(x=None): >>> if x is None: >>> pass >>> else: >>> pass >>> >> This is the way to do it python, and it has its advantages: 1 docstring, >> 1 way do do it, 1 interface. > > Yes, I see. Actually I do now realize that even in Java I use method > overloading mostly to implement optional arguments anyway, like: > > void constructor(){this.foo='foo'; this.initotherstuff();} > void constructor(int x) {this.x=x; this.constructor();} > > and so on. > > So most of the time the idiom above is exactly what I need, as the > versions of the function share code anyway. > > But there are also cases where they do something completely different - > in these cases I might use one of the other solutions provided here or > simply make two or three functions and name them appropiately. > > I do now see that the pythonic approach is the "best" for most cases, > but I really loved to see that you *can* do overloading in a convenient > way if you really want to :D Those decorators just rock :D You can do, see packages such as PEAK rules. They offer not only type-based overloading, but also value-based. Diez From spamfresser at ch3ka.de Wed Feb 24 18:08:18 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 00:08:18 +0100 Subject: How to make an empty generator? In-Reply-To: References: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: Am 24.02.2010 23:58, schrieb Aahz: > (abbreviated "gen iter" or "geniter"). lol I don't know why, but this sounds like a sex toy to me ;) Regards, Michael From nyamatongwe+thunder at gmail.com Wed Feb 24 18:22:47 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Wed, 24 Feb 2010 23:22:47 GMT Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: Steve Holden: > Spam is, at least from my point of view, UCE: unsolicited commercial > e-mail. Spam is more commonly defined as UBE (Unsolicited Bulk Email) of which UCE is a large subset. Its just as much spam if its pushing a political party or charity even though there may be no commercial advantage to the poster. Neil From ryan at rfk.id.au Wed Feb 24 18:30:07 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 25 Feb 2010 10:30:07 +1100 Subject: Upgrading Py2exe App In-Reply-To: References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: <1267054207.2598.3.camel@rambutan> On Wed, 2010-02-24 at 15:05 -0800, Aahz wrote: > In article , > Ryan Kelly wrote: > > > >Yes. The idea of having a "bootstrapping exe" is that actual > >application code can be swapped out without having to overwrite the > >executable file. As long as you don't change python versions, this > >allows updates to be safe against system crashes, even on platforms > >without atomic file replacement. > > > >So the frozen app does this in a background thread: > > > > Esky(sys.executable,"http://my.updates.com").auto_update() > > > >And it hits the given url, grabs the latest zipfile, downloads and > >unpacks and atomically places it into the application directory. Et > >viola, your app is at the latest version. > > How does this work with a running app? What if the app is a service? The changes will only take effect the next time the app is started - currently there's no support for "hot upgrading" a running app. Would definitely be an interesting feature though... 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From aahz at pythoncraft.com Wed Feb 24 18:36:54 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:36:54 -0800 Subject: How to make an empty generator? References: Message-ID: In article , Michael Rudolf wrote: >Am 24.02.2010 23:58, schrieb Aahz: >> >> (abbreviated "gen iter" or "geniter"). > >lol I don't know why, but this sounds like a sex toy to me ;) And I thought only smutty Americans would have that twitch. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From soniyaa1111 at gmail.com Wed Feb 24 18:39:57 2010 From: soniyaa1111 at gmail.com (soniyaa 1111) Date: Wed, 24 Feb 2010 15:39:57 -0800 (PST) Subject: first website developed on new innovative shopping model Message-ID: <6772fae0-6392-413a-b5fa-2b37637a2d7a@k2g2000pro.googlegroups.com> http://www.shoppingreps.com?SourceId=1259 is the first website developed on new innovative shopping model. Group bargaining through social networking targeted towards volume discounts. It has presented a suitable platform to reflect this novel shopping idea. This concept and methodology is new to the internet world. The website offers free membership to the shoppers and vendors. It encourages shoppers to acquire quotes for themselves when a group is formed. The shoppers will know the size of the group and the complete product details for which they will be requested to fetch quotes from their own localities. Shoppers get their chance of testing their bargain capabilities and enjoy the benefits and fun of bargaining for a bulk order and a group. From rhodri at wildebst.demon.co.uk Wed Feb 24 18:42:47 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 24 Feb 2010 23:42:47 -0000 Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> Message-ID: On Wed, 24 Feb 2010 13:41:08 -0000, Luis M. Gonz?lez wrote: > This is the only way I know to define variables programatically in the > top-level namespace, without having to do it manually one by one. We see requests for this a lot, and the response that's frequently missed amongst all the technical trickery is "What on earth makes you think that defining variables programatically will help?" Usually the sensible thing is to collect such "variables" into a list or dictionary, since that's the only way you're going to access them safely without a whole heap more technical trickery. -- Rhodri James *-* Wildebeeste Herder to the Masses From steve at holdenweb.com Wed Feb 24 19:01:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 19:01:05 -0500 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: Neil Hodgson wrote: > Steve Holden: > >> Spam is, at least from my point of view, UCE: unsolicited commercial >> e-mail. > > Spam is more commonly defined as UBE (Unsolicited Bulk Email) of > which UCE is a large subset. Its just as much spam if its pushing a > political party or charity even though there may be no commercial > advantage to the poster. >From my point of view that's a far better definition. Thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From robert.kern at gmail.com Wed Feb 24 19:08:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 18:08:38 -0600 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: On 2010-02-24 17:01 PM, Aahz wrote: > In article, > Steve Holden wrote: >> Spam is, at least from my point of view, UCE: unsolicited commercial >> e-mail. So anything that isn't commercial (like those "send these to ten >> of your friends" emails) isn't spam (but it might just as well be). > > That's roughly correct, but I also think that if someone posts the same > message to five mailing lists, it's not unreasonable to call that > spamming. This accords with my understanding of the term and, it appears, that of Wikipedia: http://en.wikipedia.org/wiki/Newsgroup_spam -- 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 aahz at pythoncraft.com Wed Feb 24 19:15:24 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 16:15:24 -0800 Subject: Executing Python code on another computer References: Message-ID: In article , SiWi wrote: > >So I wondered if it was possible to send the Python code I'm developing >on the netbook to the workstation pc via wlan, let the script execute >on the workstation pc and write the output back on the netbook. > >Is there any possibilty to achieve that goal? Fabric might help, but I think it relies on ssh. py.test also has remote capabilities. http://fabfile.org/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From jjposner at optimum.net Wed Feb 24 19:17:58 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 19:17:58 -0500 Subject: Docstrings considered too complicated In-Reply-To: <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> References: <20100224212303.242222c6@geekmail.INVALID> <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> Message-ID: On 2/24/2010 4:54 PM, Jonathan Gardner wrote: > On Wed, Feb 24, 2010 at 12:23 PM, Andreas Waldenburger > wrote: >> Hi all, >> >> a company that works with my company writes a lot of of their code in >> Python (lucky jerks). I've seen their code and it basically looks like >> this: >> >> """Function that does stuff""" >> def doStuff(): >> while not wise(up): >> yield scorn >> >> Now my question is this: How do I kill these people without the >> authorities thinking they didn't deserve it? >> > > kill -9 seems to work for me. > > You may want to explain, one day, why what they are doing is wrong. > They are thinking in JavaDoc, not Python. #------------------------------ """Function that does stuff""" def doStuff(): while not wise(up): yield scorn def doOtherStuff(): """Function that does stuff""" while wise(up): yield joy print doStuff.__doc__ print doOtherStuff.__doc__ #------------------------------ program output: None Function that does stuff -John From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 19:22:45 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 00:22:45 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Wed, 24 Feb 2010 21:23:03 +0100, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > while not wise(up): > yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? Well, the above isn't *wrong* as such, it is equivalent to: # Function that does stuff def doStuff(): while not wise(up): yield scorn which means the biggest problem is that they had the perfect opportunity to create a useful docstring and instead f***ed it up by turning it into a useless comment. The best way to teach them better is to introduce them to the joys of help(doStuff) and doctests. -- Steven From ben+python at benfinney.id.au Wed Feb 24 19:39:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 11:39:08 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: <878wai5etv.fsf@benfinney.id.au> Steve Holden writes: > Spam is, at least from my point of view, UCE: unsolicited commercial > e-mail. So anything that isn't commercial (like those "send these to > ten of your friends" emails) isn't spam (but it might just as well > be). That excludes things like the religious screeds, or any other one-way "get this message in front of as many eyeballs as possible" message. Spam is better defined as unsolicited bulk messaging. Whether it's commercial in nature is irrelevant. The content is relevant only in that it's unsolicited by the vast majority of its many recipients. -- \ ?I went to court for a parking ticket; I pleaded insanity. I | `\ said ?Your Honour, who in their right mind parks in the passing | _o__) lane??? ?Steven Wright | Ben Finney From ben+python at benfinney.id.au Wed Feb 24 19:41:55 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 11:41:55 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: <874ol65ep8.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > In article <87sk8r5v2f.fsf at benfinney.id.au>, > Ben Finney wrote: > >Spam is spam, not by who authors or posts it, but by its distribution > >(to many people, e.g. via a forum like this one) and its content > >(off-topic and unsolicited). [?] > Moreover, by your definition, your post above counts as spam. No. Again, as several others have pointed out, discussions about how the forum should operate (meta-discussions, if you like) are on-topic in the forum. That's not to say they should dominate the forum, of course. -- \ ?I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.? | _o__) ?Groucho Marx | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 19:51:20 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 00:51:20 GMT Subject: What's the word on using """ to comment-out? References: Message-ID: On Wed, 24 Feb 2010 18:18:27 +0000, kj wrote: > I think I remember, early in my learning of Python, coming across the > commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF > CODE", or something to that effect. But now I can't find it! > > Is my memory playing me a trick? > > After all, from what I've seen since then, the practice of > triple-quote-commenting (or TQC, pardon the TCA) is in fact quite > common. Oooh, I hope not... for anything but Q&D scripting, folks should be using source control rather than filling their source code up with vast lumps of old dead code. > Is TQC OK after all? Only if you're lazy and slack, and being lazy and slack is itself only okay if you are only lazy and slack *a very little bit*. In a small script, using test-driven development, it is acceptable to comment out dead code for a single test run. At the end of the run, you either reverse the commenting out, or you delete the dead code. > If not, what's the case against it? Commenting out dead code is, itself, a BAD THING, regardless of whether you use comments or triple-quotes. http://www.coderenaissance.com/2008/09/quit-commenting-out-dead-code.html Triple-quoted comments are worrying, though, because the result of them is not specified by the language. (Other than docstrings, of course.) The CPython compiler optimizes them away at compile time, so they have no runtime influence at all, but other implementations may not include this optimization and so the string gets compiled into the byte-code, created at runtime, then immediately deleted. Ouch. -- Steven From magawake at gmail.com Wed Feb 24 19:55:25 2010 From: magawake at gmail.com (Mag Gam) Date: Wed, 24 Feb 2010 19:55:25 -0500 Subject: compiling python question In-Reply-To: <4B859F0C.1060308@nospam.web.de> References: <4B859F0C.1060308@nospam.web.de> Message-ID: <1cbd6f831002241655p2642ac10pa6c43598dcf98896@mail.gmail.com> sorry for the vague answer. Its Linux. The configure build does not say anything actually. This is for SAGE. I managed to have it pick it up by compiling/installing tcl and tk and then recompile python On Wed, Feb 24, 2010 at 4:50 PM, Diez B. Roggisch wrote: > Am 24.02.10 03:00, schrieb Mag Gam: >> >> I am trying to compile python with Tk bindings. Do I need to do >> anything special for python to detect and enable Tk? > > What OS? What does the configure/build process say? > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From aahz at pythoncraft.com Wed Feb 24 19:56:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 16:56:04 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <874ol65ep8.fsf@benfinney.id.au> Message-ID: In article <874ol65ep8.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> In article <87sk8r5v2f.fsf at benfinney.id.au>, >> Ben Finney wrote: >>> >>>Spam is spam, not by who authors or posts it, but by its distribution >>>(to many people, e.g. via a forum like this one) and its content >>>(off-topic and unsolicited). >> >> Moreover, by your definition, your post above counts as spam. > >No. Again, as several others have pointed out, discussions about how the >forum should operate (meta-discussions, if you like) are on-topic in the >forum. We already agreed that the original post was not appropriate for c.l.py; further discussion about the precise term for describing that post is off-topic. Therefore, by your definition, your post is spam. My point is that c.l.py is somewhat tolerant of off-topic posts, and generally people who contribute to the newsgroup are more likely to get a pass on off-topic posts. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From robert.kern at gmail.com Wed Feb 24 19:58:17 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 18:58:17 -0600 Subject: Spam from gmail In-Reply-To: <878wai5etv.fsf@benfinney.id.au> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: On 2010-02-24 18:39 PM, Ben Finney wrote: > Steve Holden writes: > >> Spam is, at least from my point of view, UCE: unsolicited commercial >> e-mail. So anything that isn't commercial (like those "send these to >> ten of your friends" emails) isn't spam (but it might just as well >> be). > > That excludes things like the religious screeds, or any other one-way > "get this message in front of as many eyeballs as possible" message. > > Spam is better defined as unsolicited bulk messaging. Whether it's > commercial in nature is irrelevant. The content is relevant only in that > it's unsolicited by the vast majority of its many recipients. That said, in the context of USENET or mailing lists, a single off-topic post to a single group/list from a regular contributor is not usually considered "bulk messaging" or "spam". There is already a perfectly fine word for that: "off-topic". Only when it gets cross-posted excessively or repeated verbatim indiscriminately does it usually get designated spam. I think there is an important distinction to be made between isolated off-topic messages and spam. It's not just about finding commonly agreed meanings of terms in aid of clear communication. There is a substantive difference. The repetitive nature of spam dictates what you can do about it. With spam, you can killfile people, or filter out certain hosts, or use statistical filters, or require registration or first-post moderation, etc. With the occasional off-topic post from a regular, you ask them not to do it again and subject them to unending threads about what spam is or isn't. But you only break out the comfy chair for the very worst of the offenders. -- 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 steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:04:54 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:04:54 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> Message-ID: On Wed, 24 Feb 2010 02:58:38 -0800, Luis M. Gonz?lez wrote: > I wonder why updating locals(), not from within a function, works (at > least in my interactive session). Because if you're in the global scope, locals() returns globals(), which is a real namespace and modifying it works. Inside a function, locals() returns a dict which is a *copy* of the function namespace. The reason for this is that local namespaces are not actually dicts, and you can't modify them except by actually assigning and deleting names in code. > And what about the trick of updating globals? Is it legal? If not, is > there any "legal" way to do what the OP needs? Yes, it is legal to modify globals(). It's just a dict, you can even do this: >>> globals()[2] = 4 >>> globals()[2] 4 although that's a pretty useless trick. But whether you should is another story. I won't say you should NEVER do so, but it should be rare to use global variables, and even rarer to create them programmatically. The better solution is almost always to create your own namespace, namely a dict, and use that explicitly. -- Steven From ldo at geek-central.gen.new_zealand Wed Feb 24 20:05:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 25 Feb 2010 14:05:30 +1300 Subject: When will Java go mainstream like Python? References: Message-ID: In message , Wanja Gayk wrote: > Reference counting is about the worst technique for garbage collection. It avoids the need for garbage collection. It means I can write things like contents = open(filename, "r").read() and know the file object will be immediately closed after its contents are returned. It also means I don?t have to predefine how much memory my program will use. A garbage collector will only kick in when the app runs low on memory. On a system with dynamic memory allocation, that will not happen until the entire system runs low on memory, unless you limit the app to some fixed amount. Which is an antiquated way of doing things. And then there?s caching. Modern CPUs owe most of their speed to assumptions that programs will obey locality of reference. Pointer-chasing is a cache- hostile activity. Garbage collection involves a lot of pointer-chasing, particularly of dead objects that have long since been flushed from the cache, compared with reference counting of recently-accessed objects. Therefore garbage collection loses performance. From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:06:16 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:06:16 GMT Subject: Use eval() safely? References: <7uejcjFgf6U1@mid.individual.net> Message-ID: On Wed, 24 Feb 2010 10:11:25 +0100, Dieter Maurer wrote: > Using functionality introduced with the class/type homogenization, it is > quite easy to get access to the "file" type (even when "__builtins__" is > disabled). Having "file", arbitrary files can be read, written, > destroyed... Not that I don't believe you (I do!) but could you demonstrate for the record? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:07:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:07:31 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 24 Feb 2010 18:23:17 +0100, mk wrote: > Anyway, the passwords for authorized users will be copied and pasted > from email into in the application GUI which will remember it for them, > so they will not have to remember and type them in. So to break your application's security model, all somebody has to do is use their PC and they have full access to their account? Or get hold of the copy and paste buffer? Or the application's config files? > So I have little in > the way of limitations of password length - even though in *some* cases > somebody might have to (or be ignorant enough) to retype the password > instead of pasting it in. Or your users might be sensible enough to not trust a role-your-own security model, and prefer to memorize the password than to trust that nobody will get access to their PC. > The main application will access the data using HTTP (probably), so the > main point is that an attacker is not able to guess passwords using > brute force. And why would they bother doing that when they can sniff the wire and get the passwords in plain text? You should assume your attackers are *smarter* than you, not trust them to be foolish. -- Steven From skylarking11 at gmail.com Wed Feb 24 20:21:58 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 24 Feb 2010 17:21:58 -0800 (PST) Subject: Trouble with ftplib uploading to an FTP server References: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> Message-ID: <79927f7d-d186-46f1-ab58-94a8d5f973fc@g10g2000yqh.googlegroups.com> On Feb 24, 3:56?pm, MRAB wrote: > Sky Larking wrote: > > This bit of code is designed to get the external IP address and > > hostname of a client , write it locally to a file, then upload to an > > FTP server. It works locally( one can see the IP number and hostname > > with a time stamp in /Users/admin/Documents) , but when the file is > > opened on the server after it's FTP'ed , it's blank....I think my > > issue is something with the way I am utilizing the ftplib commands... > > I am pretty sure instead of FTPing the file, it's just creating a new > > one with the same name and uploading that? > > > This script is running on some OS X 10.5 clients and reporting back to > > an Ubuntu 8.04 server...I am using the version of python bundled with > > 10.5.x ( 2.5.1 ) > > > **************************************************************** > > import os > > import datetime > > import ftplib > > import urllib2 > > > currdate = datetime.datetime.now() > > formatdate = currdate.strftime("%m-%d-%Y %H%M") > > > def log(): > > > ? ? fqn = os.uname()[1] > > ? ? ext_ip = urllib2.urlopen('http://whatismyip.org').read() > > ? ? log = open ('/Users/admin/Documents/locatelog.txt','w') > > ? ? log.write(str("Asset: %s " % fqn)) > > ? ? log.write(str("Checking in from IP#: %s" % ext_ip)) > > ? ? smush = str(fqn +' @ ' + formatdate) > > ? ? os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ > > Documents/%s.txt' % ?smush ) > > You're renaming the file while it's still open. What you've written is > still in the buffer, not on disk. > > > ? ? s = ftplib.FTP('10.7.1.71','username','password') > > ? ? fd = open('/Users/admin/Documents/%s.txt' % smush,'rb') > > ? ? s.storbinary("STOR %s.txt" % smush , fd) > > > ***************************************************************************** > > @ MRAB Thanks ... I can see the file in /Users/admin/Documents after the following line runs though? os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ Documents/%s.txt' % smush ) For instance I just ran the script and os.rename() renamed it to: TestMachine.local @ 02-24-2010 2020.txt in that .txt file it reads: Asset: TestMachine.local Checking in from IP#: xx.xxx.xx.xxx This is what I want, but the FTP piece doesn't seem to work... From mrjean1 at gmail.com Wed Feb 24 20:27:05 2010 From: mrjean1 at gmail.com (MrJean1) Date: Wed, 24 Feb 2010 17:27:05 -0800 (PST) Subject: How to monitor memory usage within Python? (Linux) References: Message-ID: <6b5de37c-4a7b-4ee7-b5c8-6f412e3dbbab@l12g2000prg.googlegroups.com> For Linux only /Jean On Feb 24, 2:35?pm, kj wrote: > Is there some standard module for getting info about the process's > memory usage, in a Linux/Unix system? > > (I want to avoid hacks that involve, e.g., scraping ps's output.) > > Thanks! > > ~K From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:30:00 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:30:00 GMT Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: On Thu, 25 Feb 2010 11:39:08 +1100, Ben Finney wrote: > Spam is better defined as unsolicited bulk messaging. Whether it's > commercial in nature is irrelevant. The content is relevant only in that > it's unsolicited by the vast majority of its many recipients. Not quite. I've read tens of thousands of messages to comp.lang.python, and solicited perhaps some hundreds. Are all the rest spam? I should say not! I haven't solicited them: at no point did I say, explicitly or implicitly, "Hey strangers all over the world, send me messages asking questions about Python" but I do welcome them. (In fact, I'd be annoyed if everyone started sending the questions to me personally instead of to the list.) I think it is foolish to try to create a water-tight definition of "spam". It is clearly a fuzzy concept, which means sometimes right- thinking people can have legitimate disagreements as to whether or not something is "spam". For example, I happen to think that the OP's message about Fascism is off- topic but not spam. I think Joan is guilty of a breach of etiquette for failing to label it [OT] in the subject line, and she should have directed replies to a more appropriate forum (a mailing list, another newsgroup, a web forum, anywhere but here). But in my opinion, it didn't cross the line into spam. I wouldn't be the slightest bit tempted to killfile her, or flag the message as spam, in my mail/news client. If other people feel differently, well, that's your personal choice. But please don't try to tell me that *my* line between spam and ham is wrong, and that *yours* is the only correct one. (That last response is aimed at a generic You, not Ben specifically. Stupid English language, why can't we have a word for generic you?) -- Steven From no.email at nospam.invalid Wed Feb 24 20:31:31 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 17:31:31 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7xk4u26qz0.fsf@ruckus.brouhaha.com> mk writes: > Anyway, the passwords for authorized users will be copied and pasted > from email into in the application GUI which will remember it for > them, so they will not have to remember and type them in. It occurs to me that you don't even need to mess with letters in that case: password = os.urandom(5).encode('hex') will generate a string of 10 hex digits that you can give to the user. (That is for Python 2.x but I think it might be broken in Python 3). It might be helpful if you could say what your application does, or anyway give an idea of what its actual security requirements are. Generating and emailing someone a random password is a fairly standard method for (e.g.) web forums to verify that the person has supplied a working email address, basically as a first level spam filter. Your scheme is probably ok for that. If you're doing something with more demanding security requirements, then as mentioned before, there is a whole lot of stuff you have to pay attention to, and focusing narrowly on password generation isn't that useful. From ben+python at benfinney.id.au Wed Feb 24 20:31:46 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 12:31:46 +1100 Subject: When will Java go mainstream like Python? References: Message-ID: <87vddm3xtp.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > [Reference counting] avoids the need for garbage collection. It means > I can write things like > > contents = open(filename, "r").read() > > and know the file object will be immediately closed after its contents > are returned. Not quite; it means you know that the object *becomes a candidate* for cleanup immediately after its contents are returned. When, or whether, that cleanup actually happens is not something that is necessarily promised by a reference-counting implementation. -- \ ?I tell you the truth: some standing here will not taste death | `\ before they see the Son of Man coming in his kingdom.? ?Jesus | _o__) Christ, c. 30 CE, as quoted in Matthew 16:28 | Ben Finney From ben+python at benfinney.id.au Wed Feb 24 20:47:48 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 12:47:48 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: <87r5oa3x2z.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 25 Feb 2010 11:39:08 +1100, Ben Finney wrote: > > > Spam is better defined as unsolicited bulk messaging. Whether it's > > commercial in nature is irrelevant. The content is relevant only in > > that it's unsolicited by the vast majority of its many recipients. > > Not quite. > > I've read tens of thousands of messages to comp.lang.python, and > solicited perhaps some hundreds. Are all the rest spam? I should say > not! I haven't solicited them: at no point did I say, explicitly or > implicitly, "Hey strangers all over the world, send me messages asking > questions about Python" By subscribing to the forum, I maintain that you do exactly that. > but I do welcome them. Whether they're welcome or not, they're solicited in the sense of being delivered to the recipient who explicitly asked to receive messages on a particular range of topics. When a message that is well outside the nominal range of topics for a forum is broadcast to recipients by means of that forum, the message is unsolicited. -- \ ?All my life I've had one dream: to achieve my many goals.? | `\ ?Homer, _The Simpsons_ | _o__) | Ben Finney From m.76ahesh at gmail.com Wed Feb 24 20:59:48 2010 From: m.76ahesh at gmail.com (hot girl) Date: Wed, 24 Feb 2010 17:59:48 -0800 (PST) Subject: PAPER PRESENTATIONS AND SEMIMAR TOPICS. Message-ID: <9c9046ef-7e46-4b79-862e-e7d5be08d336@k41g2000yqm.googlegroups.com> PAPER PRESENTATIONS AND SEMIMAR TOPICS. CHECK OUR VAST PAPER PRESENTATIONS AND SEMIMAR TOPICS INCLUDING PROJECTS FOR FREE AT http://presentationsandseminars.blogspot.com From gagsl-py2 at yahoo.com.ar Wed Feb 24 21:04:01 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Feb 2010 23:04:01 -0300 Subject: Easter Eggs References: Message-ID: En Tue, 09 Feb 2010 20:40:50 -0300, Alf P. Steinbach escribi?: > I know 3 Python Easter Eggs, > > from __future__ import braces > import this > help( "antigravity" ) > > Are there more? Also try: import antigravity -- Gabriel Genellina From roy at panix.com Wed Feb 24 21:27:55 2010 From: roy at panix.com (Roy Smith) Date: Wed, 24 Feb 2010 21:27:55 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: In article , Steven D'Aprano wrote: > # Function that does stuff > def doStuff(): > while not wise(up): > yield scorn > > > which means the biggest problem is that they had the perfect opportunity > to create a useful docstring and instead f***ed it up by turning it into > a useless comment. > > The best way to teach them better is to introduce them to the joys of > help(doStuff) and doctests. Try the ROI (Return On Investment) argument. A programmer costs $X per hour (at first blush, take their salary, multiply by 1.5 for indirect costs, and divide by 2000 working hours per year). It took them N minutes to write that text, so now you know how much that piece of text cost in dollars. Given that you've invested that money, what's the best way to maximize your ROI? Well, you could take that text, and put it in front of the 'def' line. The ROI in that you can read the text when you view the source code. Perhaps by printing it out on green-bar, or carving it into clay tablets with a pointed stick. Or, you could put it after the 'def' line. Now, you can still read it when viewing the source file. But, you can also access it with help(). Or by getting the functions __doc__ string. Three times the ROI! Even the most pointy-haired bean counter can grok the fullness of that. From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 21:42:31 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 15:42:31 +1300 Subject: Executable problem - socket? Message-ID: Hi, My student has been developing a GUI (using PyQt and PyQwt) that runs a model written in Fortran and built as a DLL. She has to present on this work tomorrow. She makes an executable version of the Python code with py2exe, and the executable runs fine on her Vista laptop and my XP machine. It doesn't run on the PC that she must use for her talk tomorrow. The Fortran DLL code is started up, it writes some text output to a couple of log files, then it fails with a WindowsError (000001d) which is a write error. I suspect that this is the first attempt to write to a socket (communication from the DLL to Python is via sockets). The only clue is that the machines that her program runs on have Python installed, while the one that fails doesn't. Therefore I suspect that py2exe has omitted a necessary Python DLL. How can I track down what might be missing? Thanks Gib From python at mrabarnett.plus.com Wed Feb 24 22:10:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Feb 2010 03:10:14 +0000 Subject: Executable problem - socket? In-Reply-To: References: Message-ID: <4B85EA16.5090002@mrabarnett.plus.com> Gib Bogle wrote: > Hi, > My student has been developing a GUI (using PyQt and PyQwt) that runs a > model written in Fortran and built as a DLL. She has to present on this > work tomorrow. She makes an executable version of the Python code with > py2exe, and the executable runs fine on her Vista laptop and my XP > machine. It doesn't run on the PC that she must use for her talk > tomorrow. The Fortran DLL code is started up, it writes some text > output to a couple of log files, then it fails with a WindowsError > (000001d) which is a write error. I suspect that this is the first > attempt to write to a socket (communication from the DLL to Python is > via sockets). The only clue is that the machines that her program runs > on have Python installed, while the one that fails doesn't. Therefore I > suspect that py2exe has omitted a necessary Python DLL. How can I track > down what might be missing? > You could try Dependency Walker: http://dependencywalker.com/ From bigblueswope at gmail.com Wed Feb 24 22:34:16 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Wed, 24 Feb 2010 22:34:16 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: > > If you like, but I tend to interpret "meta-" as idempotent. It's easier on > my aspirin budget. > > -- > Robert Kern And here I thought it was little blue pills for idempotentcy... ---- Life is a sexually transmitted disease with a 100% fatality rate. -- brazzy Auburn fans are like slinkys... not really good for anything but they still bring a smile to your face when you push them down a flight of stairs. To argue that honorable conduct is only required against an honorable enemy degrades the Americans who must carry out the orders. -- Charles Krulak, Former Commandant of the Marine Corps We are all slave to our own paradigm. -- Joshua Williams If the letters PhD appear after a person's name, that person will remain outdoors even after it's started raining. -- Jeff Kay From steve at holdenweb.com Wed Feb 24 23:14:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 23:14:56 -0500 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: > On Thu, 25 Feb 2010 11:39:08 +1100, Ben Finney wrote: > >> Spam is better defined as unsolicited bulk messaging. Whether it's >> commercial in nature is irrelevant. The content is relevant only in that >> it's unsolicited by the vast majority of its many recipients. > > Not quite. > > I've read tens of thousands of messages to comp.lang.python, and > solicited perhaps some hundreds. Are all the rest spam? I should say not! > I haven't solicited them: at no point did I say, explicitly or > implicitly, "Hey strangers all over the world, send me messages asking > questions about Python" but I do welcome them. > > (In fact, I'd be annoyed if everyone started sending the questions to me > personally instead of to the list.) > > I think it is foolish to try to create a water-tight definition of > "spam". It is clearly a fuzzy concept, which means sometimes right- > thinking people can have legitimate disagreements as to whether or not > something is "spam". > > For example, I happen to think that the OP's message about Fascism is off- > topic but not spam. I think Joan is guilty of a breach of etiquette for > failing to label it [OT] in the subject line, and she should have > directed replies to a more appropriate forum (a mailing list, another > newsgroup, a web forum, anywhere but here). But in my opinion, it didn't > cross the line into spam. I wouldn't be the slightest bit tempted to > killfile her, or flag the message as spam, in my mail/news client. > > If other people feel differently, well, that's your personal choice. But > please don't try to tell me that *my* line between spam and ham is wrong, > and that *yours* is the only correct one. > > (That last response is aimed at a generic You, not Ben specifically. > Stupid English language, why can't we have a word for generic you?) > > That's why SpamBayes allows per-user training. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 23:35:56 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 17:35:56 +1300 Subject: Executable problem - socket? References: Message-ID: MRAB wrote: > Gib Bogle wrote: >> Hi, >> My student has been developing a GUI (using PyQt and PyQwt) that runs >> a model written in Fortran and built as a DLL. She has to present on >> this work tomorrow. She makes an executable version of the Python >> code with py2exe, and the executable runs fine on her Vista laptop and >> my XP machine. It doesn't run on the PC that she must use for her >> talk tomorrow. The Fortran DLL code is started up, it writes some >> text output to a couple of log files, then it fails with a >> WindowsError (000001d) which is a write error. I suspect that this is >> the first attempt to write to a socket (communication from the DLL to >> Python is via sockets). The only clue is that the machines that her >> program runs on have Python installed, while the one that fails >> doesn't. Therefore I suspect that py2exe has omitted a necessary >> Python DLL. How can I track down what might be missing? >> > You could try Dependency Walker: http://dependencywalker.com/ > Wow! I've heard of it, but never used it. The result is intriguing, but baffling. When I look at the executable ABM15.exe on my machine (where it runs OK), I see a couple of harmless messages, but interestingly the program shows up with a checksum inconsistency, between Link Checksum and Real Checksum. Apparently this causes no issues on my machine. On another XP machine, where the program fails with the write error, there is first a pop-up with this message: "Errors were detected when processing ABM15.exe. See the log for details." In the log there are two significant messages: "Error: The side-by-side configuration information for ABM15.exe contains errors. The application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem (14001)." (the checksum discrepancy is there also) "MSJAVA.DLL Error opening file. The system cannot find the file specified (2)." (needless to say, I'm not using Java, and MSJAVA.dll is not on the other machine either) I find it very puzzling that the "configuration information" (whatever that is) is OK on one machine and erroneous on another. DependencyWalker is obviously onto something - but what? (At this stage snide comments about Windows will be received without comment.) From jackdied at gmail.com Thu Feb 25 00:10:50 2010 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 25 Feb 2010 00:10:50 -0500 Subject: Docstrings considered too complicated In-Reply-To: <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> References: <20100224212303.242222c6@geekmail.INVALID> <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> Message-ID: On Wed, Feb 24, 2010 at 4:54 PM, Jonathan Gardner wrote: > On Wed, Feb 24, 2010 at 12:23 PM, Andreas Waldenburger > wrote: >> >> Now my question is this: How do I kill these people without the >> authorities thinking they didn't deserve it? >> > > kill -9 seems to work for me. kill -1 -1 Back in the days of thin X terminals I used that one as a quicker alternative to actually logging out. It is also useful if you start a fork bunny and need to hit the panic switch before the machine grinds to a halt. -Jack From g.bogle at auckland.no.spam.ac.nz Thu Feb 25 00:22:04 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 18:22:04 +1300 Subject: Executable problem - correction References: Message-ID: The program doesn't fail with the write error on the other XP machine, it actually fails to execute at all, complaining about the configuration information. Therefore I'm seeing different behaviour on three XP machines: Box 1 (SP2): runs OK Box 2 (SP3): fails to start Box 3 (SP3): starts up, all Qt stuff works, fails after invoking the Fortran DLL Just to add to the confusion, execution is successful on a Windows 7 box. I forgot to mention that the laptop on which the program was built (and where it runs OK) is using Vista. I now see that it will probably be necessary to build separate Vista and XP versions - I should have realized this earlier, but was misled by the fact that the Vista-built program runs OK on my XP SP2 box. From timr at probo.com Thu Feb 25 00:44:32 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 24 Feb 2010 21:44:32 -0800 Subject: What's Going on between (Verify) Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: "W. eWatson" wrote: >Maybe someone could verify my result? > >open file >read file line >print line >close file > >data 1234 > >Execute it in a folder > >Create another folder and copy the program to it. >put in a new data file as > >data 4567 > >Execute the copied program >Does it give >data1234? No, of course not. C:\tmp\x>echo data 1234>data.txt C:\tmp\x>type check.py f = open('data.txt','r') print f.read() f.close() C:\tmp\x>check.py data 1234 C:\tmp\x>cd ..\y C:\tmp\y>echo data 4567>data.txt C:\tmp\y>copy ..\x\check.py . 1 file(s) copied. C:\tmp\y>check.py data 4567 C:\tmp\y> Would you like to post your exact code? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From half.italian at gmail.com Thu Feb 25 00:46:25 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Wed, 24 Feb 2010 21:46:25 -0800 (PST) Subject: Executable problem - correction References: Message-ID: <885c2e20-e4da-4aeb-bae7-7b3573bb1be1@k5g2000pra.googlegroups.com> On Feb 24, 9:22?pm, Gib Bogle wrote: > The program doesn't fail with the write error on the other XP machine, it > actually fails to execute at all, complaining about the configuration > information. ?Therefore I'm seeing different behaviour on three XP machines: > > Box 1 (SP2): runs OK > Box 2 (SP3): fails to start > Box 3 (SP3): starts up, all Qt stuff works, fails after invoking the Fortran DLL > > Just to add to the confusion, execution is successful on a Windows 7 box. > > I forgot to mention that the laptop on which the program was built (and where it > runs OK) is using Vista. ?I now see that it will probably be necessary to build > separate Vista and XP versions - I should have realized this earlier, but was > misled by the fact that the Vista-built program runs OK on my XP SP2 box. Did you compile the program with python 2.6? Try compiling with 2.5. ~Sean From sbassi at clubdelarazon.org Thu Feb 25 00:48:10 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Thu, 25 Feb 2010 02:48:10 -0300 Subject: parametrizing a sqlite query In-Reply-To: References: <9e2f512b1002240907v66682f1fi7d4d4c7d2dabd880@mail.gmail.com> Message-ID: <9e2f512b1002242148v2be5b4e2i387a54ee39f8dcd6@mail.gmail.com> On Wed, Feb 24, 2010 at 3:41 PM, Dennis Lee Bieber wrote: > ? ? ? ?No there isn't... The problem is that you need to put the wildcards > into the parameter instead of the placeholder. Thank you, it works now. Best, SB From greg.ewing at canterbury.ac.nz Thu Feb 25 01:00:26 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 19:00:26 +1300 Subject: Use eval() safely? In-Reply-To: References: <7uejcjFgf6U1@mid.individual.net> Message-ID: <7umhcaF9rkU1@mid.individual.net> Steven D'Aprano wrote: > Not that I don't believe you (I do!) but could you demonstrate for the > record? I posted a demonstration of this earlier in this thread. The key thing is the __subclasses__() method of a class. You can start with any object, work your way up the base class chain to object, and then use __subclasses__() to get to any builtin class in the system, including file. There was a sandboxing scheme put forward a while back which involves vetting the code and disallowing the use of any double-underscore attribute names. With a suitably censored set of builtin functions, this prevents the use of the __subclasses__ hack, as well as some other potential lines of attack. As far as I know, nobody managed to break it at the time, but it probably hasn't been tested much in the real world, if at all, so I probably wouldn't recommend using it for anything critical. -- Greg From g.bogle at auckland.no.spam.ac.nz Thu Feb 25 01:53:37 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 19:53:37 +1300 Subject: Executable problem - correction References: <885c2e20-e4da-4aeb-bae7-7b3573bb1be1@k5g2000pra.googlegroups.com> Message-ID: Sean DiZazzo wrote: > On Feb 24, 9:22 pm, Gib Bogle wrote: >> The program doesn't fail with the write error on the other XP machine, it >> actually fails to execute at all, complaining about the configuration >> information. Therefore I'm seeing different behaviour on three XP machines: >> >> Box 1 (SP2): runs OK >> Box 2 (SP3): fails to start >> Box 3 (SP3): starts up, all Qt stuff works, fails after invoking the Fortran DLL >> >> Just to add to the confusion, execution is successful on a Windows 7 box. >> >> I forgot to mention that the laptop on which the program was built (and where it >> runs OK) is using Vista. I now see that it will probably be necessary to build >> separate Vista and XP versions - I should have realized this earlier, but was >> misled by the fact that the Vista-built program runs OK on my XP SP2 box. > > Did you compile the program with python 2.6? Try compiling with 2.5. > > ~Sean I'll have to check with Helvin, but I believe 2.6 was needed for the version of PyQt that she has installed. From ashokprabhuv at gmail.com Thu Feb 25 02:01:58 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Wed, 24 Feb 2010 23:01:58 -0800 (PST) Subject: Regular expression issue Message-ID: <3c13650c-a16d-422b-93f2-53d376c693d0@k2g2000pro.googlegroups.com> Hi, The following is a sample of my problem. I get input from user and store it in variable 'b'. I want to match the user input with the contents of another variable 'a'. However I m not able to get the exact match. Could someone help? >>> print a c c+ >>> b 'c+' >>> re.search(b,a).group() 'c' In the above example I want re to find the string 'c+' instead of 'c'. I want a solution without escaping the '+' symbol with backslash because it is given by the user. Thanks, ~Ashok. From sjdevnull at yahoo.com Thu Feb 25 02:03:30 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Wed, 24 Feb 2010 23:03:30 -0800 (PST) Subject: When will Java go mainstream like Python? References: Message-ID: On Feb 24, 8:05?pm, Lawrence D'Oliveiro wrote: > In message , Wanja Gayk wrote: > > > Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. That's like saying that driving a VW Beetle avoids the need for an automobile. Reference counting is a form of garbage collection (like mark-sweep, copy-collect, and others), not a way of avoiding it. You're right that ref counting in many implementations is more deterministic than other common forms of garbage collection; IMO, Python would be well-served by making the ref-counting semantics it currently has a guaranteed part of the language spec--or at least guaranteeing that when a function returns, any otherwise unreferenced locals are immediately collected. I could be convinced otherwise, but I _think_ that that change would offer an alternative to all of the interesting cases of where the "with" statement is "useful". From arnodel at googlemail.com Thu Feb 25 02:30:20 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 07:30:20 +0000 Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: dontspamleo writes: > @Arnaud: I tried to find your earlier post -- googled "Arnaud lambda" > -- but couldn't. I remembered after posting that I sent this to python-ideas. Here is the first message in the thread: http://mail.python.org/pipermail/python-ideas/2007-December/001260.html In this thread, someone claims that this issue was discussed when genexps were first added to the language, but doesn't remember the rationale for taking this decision. Perhaps someone knows what discussion they refer to... -- Arnaud From greg.ewing at canterbury.ac.nz Thu Feb 25 02:46:41 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 20:46:41 +1300 Subject: while loop with the condition used in the body In-Reply-To: References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: <7umnjeF3epU1@mid.individual.net> Ulrich Eckhardt wrote: > so why not: > > while as : > ... > > and also: > > if as : > ... This sort of thing has been suggested repeatedly in the past, and it's always been rejected. That's not likely to change. Look up the past threads for the reasons why. -- Greg From jayeola at gmail.com Thu Feb 25 02:54:00 2010 From: jayeola at gmail.com (john maclean) Date: Thu, 25 Feb 2010 02:54:00 -0500 Subject: pydoc errors Message-ID: <4170c1721002242354q5057b2b3p46311d567777afc4@mail.gmail.com> python version is 2.6.2 does any one else have this issue? Seen a few closed tickets for various Linux Distros but it is obvoiusly still my problem. help> modules Please wait a moment while I gather a list of all available modules... dm.c: 1640: not running as root returning empty list ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowState' as flags when in fact it is of type 'GEnum' ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowActions' as flags when in fact it is of type 'GEnum' ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowMoveResizeMask' as flags when in fact it is of type 'GEnum' /usr/lib/python2.6/site-packages/httplib2/__init__.py:29: DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5 /usr/lib/python2.6/site-packages/httplib2/__init__.py:44: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha 2010-02-25 01:20:10.483800: ERROR: Could not load the stocks from /home/jmaclean/.gnome2/invest-applet/stocks.pickle: [Errno 2] No such file or directory: '/home/jmaclean/.gnome2/invest-applet/stocks.pickle' You must run this application as root -- John Maclean 07739 171 531 MSc (DIC) Enterprise Linux Systems Engineer From greg.ewing at canterbury.ac.nz Thu Feb 25 02:55:51 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 20:55:51 +1300 Subject: Creating variables from dicts In-Reply-To: <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> Message-ID: <7umo4kF7q8U1@mid.individual.net> Luis M. Gonz?lez wrote: > I still don't understand why is it a bad idea in the case of > globals(). > This is the only way I know to define variables programatically in the > top-level namespace, without having to do it manually one by one. The point is that creating variables whose names are computed at run time is usually a misguided thing to do in the first place. Think about it -- how are you going to *use* those variables that you've created? If the answer is that you're going to go looking for a way to read the values of variables whose names are computed at run time, you might as well not use variables at all, but just keep their values in a dictionary. -- Greg From paul.nospam at rudin.co.uk Thu Feb 25 02:56:05 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 25 Feb 2010 07:56:05 +0000 Subject: What's the word on using """ to comment-out? References: Message-ID: <87hbp5rboq.fsf@rudin.co.uk> kj writes: > I think I remember, early in my learning of Python, coming across > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > LINES OF CODE", or something to that effect. But now I can't find > it! No idea, but it would be nice to have some multiline comment syntax (other than # at the beginning of each line). Particularly one that can be nested. From no.email at nospam.invalid Thu Feb 25 02:56:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 23:56:18 -0800 Subject: When will Java go mainstream like Python? References: Message-ID: <7xmxyxiw9p.fsf@ruckus.brouhaha.com> "sjdevnull at yahoo.com" writes: > IMO, Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec... > I could be convinced otherwise, but I _think_ that that change would > offer an alternative to all of the interesting cases of where the > "with" statement is "useful". The whole point of introducing the "with" statement was help cleanly get rid of the ugly and unsound reliance on refcounting semantics found in so much python code. Your proposal is aimed in the wrong direction. From no.email at nospam.invalid Thu Feb 25 02:58:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 23:58:39 -0800 Subject: When will Java go mainstream like Python? References: Message-ID: <7xiq9liw5s.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > Pointer-chasing is a cache- hostile activity. Garbage collection > involves a lot of pointer-chasing, particularly of dead objects that > have long since been flushed from the cache, compared with reference > counting of recently-accessed objects. Therefore garbage collection > loses performance. Serious gc's these days only touch live data, not garbage; and they work on small enough regions of memory most of the time (generational scavenging) to not have too many cache misses. Also, hyperthreading seems to be coming back, allowing cpu cores to multitask in the presence of cache misses. From __peter__ at web.de Thu Feb 25 03:10:51 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 09:10:51 +0100 Subject: Regular expression issue References: <3c13650c-a16d-422b-93f2-53d376c693d0@k2g2000pro.googlegroups.com> Message-ID: Ashok Prabhu wrote: > The following is a sample of my problem. I get input from user and > store it in variable 'b'. I want to match the user input with the > contents of another variable 'a'. However I m not able to get the > exact match. Could someone help? > >>>> print a > c > c+ > >>>> b > 'c+' >>>> re.search(b,a).group() > 'c' > > In the above example I want re to find the string 'c+' instead of 'c'. > I want a solution without escaping the '+' symbol with backslash > because it is given by the user. >>> a = "yadda c+ yadda" >>> b = "c+" >>> re.search(re.escape(b), a).group() 'c+' But if you aren't interested in anything but string literals, you should use string search: >>> a.index(b) 6 Peter From aleksandr.goretoy at gmail.com Thu Feb 25 03:24:14 2010 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 25 Feb 2010 02:24:14 -0600 Subject: Creating variables from dicts In-Reply-To: <7umo4kF7q8U1@mid.individual.net> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> <7umo4kF7q8U1@mid.individual.net> Message-ID: The problem i see with using globals() is that it can overwrite a previously defined function or key within the global namespace, making the code potentially dangerous and wild with exploits. my $0.02 -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 25 03:35:10 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 25 Feb 2010 09:35:10 +0100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: * sjdevnull at yahoo.com: > On Feb 24, 8:05 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Wanja Gayk wrote: >> >>> Reference counting is about the worst technique for garbage collection. >> It avoids the need for garbage collection. > > That's like saying that driving a VW Beetle avoids the need for an > automobile. Reference counting is a form of garbage collection (like > mark-sweep, copy-collect, and others), not a way of avoiding it. > > You're right that ref counting in many implementations is more > deterministic than other common forms of garbage collection; IMO, > Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec--or at least > guaranteeing that when a function returns, any otherwise unreferenced > locals are immediately collected. > > I could be convinced otherwise, but I _think_ that that change would > offer an alternative to all of the interesting cases of where the > "with" statement is "useful". Well, relying on ref-counted garbage collection for cleanup actions (other than reclaiming memory) is pretty brittle in a language based on general garbage collection. As soon as a reference to X sneaks away somewhere, X doesn't clean up at scope's end, which is not a catastrophe in itself but means there's no telling when it happens or indeed whether it happens at all. I'm not sure but as I recall the D language has a solution to this, sort of declaring X so that no references to it can be retained anywhere, but it's a very different language. And Eiffel has the "expanded type" thing for "no references", but does it use that to support deterministic cleanup? I don't know whether the Eiffel 'dispose' is called for an expanded object. C# has a 'using' like Python 'with'. It works, sort of, but adds a lot of complexity. C++ has the notion of optional garbage collection (formalized in C++0x) with cleanup actions not tied to memory reclamation but to deterministically invoked destructors and I think that as an /idea/ that is clean and good, but in practice almost no-one uses garbage collection with C++, and reportedly the least unpopular implementation (the Boehm collector) imposes some very stiff requirements on the code. So I think there's no really good solution: the price for simplicity in one dimension is some complexity in another dimension, here deterministic cleanup and the problem of zombie objects (garbage collection simplifies a lot of things while zombie objects, objects that have had explicit cleanup performed and thus are invalid in a sense, compensate by adding back in a lot of complexity). Cheers, - Alf From greg.ewing at canterbury.ac.nz Thu Feb 25 03:43:08 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 21:43:08 +1300 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <7umqtdFlrrU1@mid.individual.net> Lawrence D'Oliveiro wrote: > And then there?s caching. Modern CPUs owe most of their speed to assumptions > that programs will obey locality of reference. Pointer-chasing is a cache- > hostile activity. Another thing to consider is the rate at which garbage is created. Java's fundamental types (ints, floats, etc.) are unboxed, and objects are only used for relatively heavyweight things. So you can do quite a lot of useful computation in Java without creating any objects or leaving behind any garbage. In Python, on the other hand, you can't even do arithmetic without creating and destroying intermediate objects at every step. Collecting those objects promptly means that the same areas of memory tend to get re-used over and over, resulting in better cacheing behaviour. So I don't think you can assume that just because Java's garbage collection scheme works well for Java that it would also necessarily work well for Python. -- Greg From m.38ahesh at gmail.com Thu Feb 25 04:08:54 2010 From: m.38ahesh at gmail.com (Sree Rama) Date: Thu, 25 Feb 2010 01:08:54 -0800 (PST) Subject: Why born like human? Read Ramayana & Follow Rama. Message-ID: Why born like human? Read Ramayana & Follow Rama. Once in a life you should read this great story, read this story in simple language at http://ramayanastory-rama.blogspot.com/2010/02/sri-rama-prince-of-ayodhya.html From deets at nospam.web.de Thu Feb 25 04:13:23 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 10:13:23 +0100 Subject: pydoc errors In-Reply-To: References: Message-ID: <7umt9jF38rU1@mid.uni-berlin.de> Am 25.02.10 08:54, schrieb john maclean: > python version is 2.6.2 does any one else have this issue? Seen a few > closed tickets for various Linux Distros but it is obvoiusly still my > problem. > > > help> modules > > Please wait a moment while I gather a list of all available modules... > > dm.c: 1640: not running as root returning empty list > > ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowState' as > flags when in fact it is of type 'GEnum' > > ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowActions' > as flags when in fact it is of type 'GEnum' > > ** (.:8391): WARNING **: Trying to register gtype > 'WnckWindowMoveResizeMask' as flags when in fact it is of type 'GEnum' > /usr/lib/python2.6/site-packages/httplib2/__init__.py:29: > DeprecationWarning: the md5 module is deprecated; use hashlib instead > import md5 > /usr/lib/python2.6/site-packages/httplib2/__init__.py:44: > DeprecationWarning: the sha module is deprecated; use the hashlib > module instead > import sha > 2010-02-25 01:20:10.483800: ERROR: Could not load the stocks from > /home/jmaclean/.gnome2/invest-applet/stocks.pickle: [Errno 2] No such > file or directory: > '/home/jmaclean/.gnome2/invest-applet/stocks.pickle' > You must run this application as root To me it looks as if one of your installed applications has nasty side-effects on module import. De-install it if possible, and see if that helps. Diez From no.email at nospam.invalid Thu Feb 25 04:28:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Feb 2010 01:28:30 -0800 Subject: When will Java go mainstream like Python? References: Message-ID: <7xvddlslz5.fsf@ruckus.brouhaha.com> "Alf P. Steinbach" writes: > So I think there's no really good solution: the price for simplicity > in one dimension is some complexity in another dimension, You could look at the way Cyclone (http://cyclone.thelanguage.org) does region inference, and maybe combine that with a tracing gc. There are some functional language compilers that also use region inference. From clp2 at rebertia.com Thu Feb 25 04:41:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Feb 2010 01:41:09 -0800 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <50697b2c1002250141x5b40b3b8gf11e077ba8a80fef@mail.gmail.com> On Wed, Feb 24, 2010 at 11:03 PM, sjdevnull at yahoo.com wrote: > On Feb 24, 8:05?pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Wanja Gayk wrote: >> >> > Reference counting is about the worst technique for garbage collection. >> >> It avoids the need for garbage collection. > > That's like saying that driving a VW Beetle avoids the need for an > automobile. ?Reference counting is a form of garbage collection (like > mark-sweep, copy-collect, and others), not a way of avoiding it. > > You're right that ref counting in many implementations is more > deterministic than other common forms of garbage collection; IMO, > Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec--or at least > guaranteeing that when a function returns, any otherwise unreferenced > locals are immediately collected. > > I could be convinced otherwise, but I _think_ that that change would > offer an alternative to all of the interesting cases of where the > "with" statement is "useful". You're forgetting global context objects, such as those for Decimal: http://docs.python.org/library/decimal.html#decimal.localcontext Cheers, Chris -- http://blog.rebertia.com From arnodel at googlemail.com Thu Feb 25 05:24:09 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 02:24:09 -0800 (PST) Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: > (That last response is aimed at a generic You, not Ben specifically. > Stupid English language, why can't we have a word for generic you?) I thought the word was "one". -- Arnaud From nanyaks at googlemail.com Thu Feb 25 05:26:18 2010 From: nanyaks at googlemail.com (simn_stv) Date: Thu, 25 Feb 2010 02:26:18 -0800 (PST) Subject: taking python enterprise level?... Message-ID: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> hello people, i have been reading posts on this group for quite some time now and many, if not all (actually not all!), seem quite interesting. i plan to build an application, a network based application that i estimate (and seriously hope) would get as many as 100, 000 hits a day (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' or anything like it, its mainly for a financial transactions which gets pretty busy... so my question is this would anyone have anything that would make python a little less of a serious candidate (cos it already is) and the options may be to use some other languages (maybe java, C (oh God))...i am into a bit of php and building API's in php would not be the hard part, what i am concerned about is scalability and efficiency, well, as far as the 'core' is concerned. would python be able to manage giving me a solid 'core' and will i be able to use python provide any API i would like to implement?... im sorry if my subject was not as clear as probably should be!. i guess this should be the best place to ask this sort of thing, hope im so right. Thanks From jeanmichel at sequans.com Thu Feb 25 05:32:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 11:32:30 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4B8651BE.7080500@sequans.com> Michael Rudolf wrote: > First: Thanks for all the replies so far, they really helped me. > > Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >>> >>> def a(x=None): >>> if x is None: >>> pass >>> else: >>> pass >>> >> This is the way to do it python, and it has its advantages: 1 docstring, >> 1 way do do it, 1 interface. > > Yes, I see. Actually I do now realize that even in Java I use method > overloading mostly to implement optional arguments anyway, like: > > void constructor(){this.foo='foo'; this.initotherstuff();} > void constructor(int x) {this.x=x; this.constructor();} > > and so on. > > So most of the time the idiom above is exactly what I need, as the > versions of the function share code anyway. > > But there are also cases where they do something completely different > - in these cases I might use one of the other solutions provided here > or simply make two or three functions and name them appropiately. > > I do now see that the pythonic approach is the "best" for most cases, > but I really loved to see that you *can* do overloading in a > convenient way if you really want to :D Those decorators just rock :D > > Thanks again, > Michael You said it yourself: "simply make two or three functions and name them appropiately" :-) When 2 methods of a class were to have the same name for doing completely different things like you said, there's a design flaw to my opinion. JM From python.list at tim.thechases.com Thu Feb 25 05:44:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 04:44:31 -0600 Subject: What's the word on using """ to comment-out? In-Reply-To: <87hbp5rboq.fsf@rudin.co.uk> References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: <4B86548F.4070305@tim.thechases.com> Paul Rudin wrote: > kj writes: > >> I think I remember, early in my learning of Python, coming across >> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT >> LINES OF CODE", or something to that effect. But now I can't find >> it! > > No idea, but it would be nice to have some multiline comment syntax > (other than # at the beginning of each line). Particularly one that can > be nested. Well, there's always "if 0"/"if False", but that requires screwing with the indentation levels. Granted, any competent text editor will allow you to easily shift code indentation (I know Vim does, and am pretty sure Emacs will let you do the same...YMMV with other editors). But yes, there have been times that a multi-line commenting that doesn't touch your indentation would be nice, and I confess to using triple-quotes to do that (opting for """ or ''' based on the type of triple-quotes found in the code). However, I usually limit this for debugging purposes and they usually get pruned or uncommented for production code. -tkc From stefan_ml at behnel.de Thu Feb 25 05:50:05 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 11:50:05 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: mk, 24.02.2010 18:30: > On 2010-02-24 03:26, George Sakkis wrote: >>> Well I for one wouldn't want Python to go exactly Java way, see this: >>> >>> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=jav... >>> >>> This is the percentage of job offers in UK where the keyword "Java" >>> appears. >>> >>> Same for C#, it looks like C# is eating Java's lunch now: >>> >>> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csh... >> >> This seems to be a UK-specific trend; in the US (and most other >> countries I know of) Java is still going strong, e.g. >> http://www.indeed.com/jobtrends?q=java%2C+c%23&l= > > Interesting, and I was thinking that UK sample was big enough for such > things not to matter. Lies, damn lies, and statistics ... Stefan From lacrima.maxim at gmail.com Thu Feb 25 05:56:41 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Thu, 25 Feb 2010 02:56:41 -0800 (PST) Subject: Using mock library (written by Michael Foord) Message-ID: <5989a385-ee81-4708-8409-3299e83dcfa7@k17g2000yqb.googlegroups.com> Hello! I use mock library http://www.voidspace.org.uk/python/mock/. There is no user group for the library, so I post in comp.lang.python and hope that people who use it will help me. The library allows to patch objects, using patch decorator. Patching is done only within the scope of the function. So if I have a lot of tests that need specific object to be patched I have to specify the same decorator for each test method: class TestSomething(unittest.TestCase): @patch('module.Class', spec = True) def test_method1(self, MockClass): Class() self.assertEquals(MockClass.called) @patch('module.Class', spec = True) def test_method2(self, MockClass): Class() MockClass.assert_called_with('foo') @patch('module.Class', spec = True) def test_method3(self, MockClass): foo = Class() self.assertRaises(AttributeError, foo.some_method) # and more ... So for every test method I always do the same patching! How can I avoid this? Thanks in advance. Sorry if my English isn't proper enough. With regards, Maxim. From jeanmichel at sequans.com Thu Feb 25 05:58:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 11:58:30 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: <4B8651BE.7080500@sequans.com> References: <4B8651BE.7080500@sequans.com> Message-ID: <4B8657D6.6080703@sequans.com> Jean-Michel Pichavant wrote: > Michael Rudolf wrote: >> First: Thanks for all the replies so far, they really helped me. >> >> Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >>>> >>> def a(x=None): >>>> if x is None: >>>> pass >>>> else: >>>> pass >>>> >>> This is the way to do it python, and it has its advantages: 1 >>> docstring, >>> 1 way do do it, 1 interface. >> >> Yes, I see. Actually I do now realize that even in Java I use method >> overloading mostly to implement optional arguments anyway, like: >> >> void constructor(){this.foo='foo'; this.initotherstuff();} >> void constructor(int x) {this.x=x; this.constructor();} >> >> and so on. >> >> So most of the time the idiom above is exactly what I need, as the >> versions of the function share code anyway. >> >> But there are also cases where they do something completely different >> - in these cases I might use one of the other solutions provided here >> or simply make two or three functions and name them appropiately. >> >> I do now see that the pythonic approach is the "best" for most cases, >> but I really loved to see that you *can* do overloading in a >> convenient way if you really want to :D Those decorators just rock :D >> >> Thanks again, >> Michael > You said it yourself: "simply make two or three functions and name > them appropiately" :-) > > When 2 methods of a class were to have the same name for doing > completely different things like you said, there's a design flaw to my > opinion. > > JM I wonder if I've just written that my opinion is flawed... It surely is, but that's not why I meant :-) JM From steve at holdenweb.com Thu Feb 25 06:13:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Feb 2010 06:13:28 -0500 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: simn_stv wrote: > hello people, i have been reading posts on this group for quite some > time now and many, if not all (actually not all!), seem quite > interesting. > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. > > would python be able to manage giving me a solid 'core' and will i be > able to use python provide any API i would like to implement?... > > im sorry if my subject was not as clear as probably should be!. > i guess this should be the best place to ask this sort of thing, hope > im so right. > > Thanks I'd suggest that if you are running an operation that gets 100,000 hits a day then your problems won't be with Python but with organizational aspects of your operation. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From martin.hellwig at dcuktec.org Thu Feb 25 06:21:30 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Feb 2010 11:21:30 +0000 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On 02/25/10 10:26, simn_stv wrote: > what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. > > would python be able to manage giving me a solid 'core' and will i be > able to use python provide any API i would like to implement?... Python isn't the most efficient language, the assembler provided by the maker of your CPU probably is the best you can get, everything after that is a trade-off between performance and flexibility (flexible in the most flexible sense of the word :-)). That being said, for me, Python (well actually any turing complete programming language), is more like a box of lego with infinite amount of pieces. Scalability and API issues are the same as the shape and function of the model your making with lego. Sure some type of pieces might be more suited than other types but since you can simulate any type of piece with the ones that are already present, you are more limited by your imagination than by the language. So in short, I don't see any serious problems using Python, I have used it in Enterprise environments without any problems but than again I was aware not to use it for numerical intensive parts without the use of 3rd party libraries like numpy. Which for me resulted in not doing the compression of a database delta's in pure python but to offload that to a more suitable external program, still controlled from Python though. -- mph From tim.wintle at teamrubber.com Thu Feb 25 06:45:22 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 25 Feb 2010 11:45:22 +0000 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <1267098322.21809.26.camel@localhost> On Thu, 2010-02-25 at 02:26 -0800, simn_stv wrote: > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... I've got apps running that handle *well* over 100,000 hits / process / day using Python - although some of the heavy lifting is off-loaded to C and MySql - obviously without actually looking at your requirements that doesn't mean much as I don't know how much work each hit requires. Regarding financial transactions - you'll almost certainly want to integrate with something that already has transactional support (sql etc) - so I expect that will bear the brunt of the load > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God)) I've avoided integrating java with my python (I'm not a big fan of java) - but I've integrated quite a bit of C - it's fairly easy to do, and you can just port the inner loops if you see the need arise. > ...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. I've heard that php can be well scaled (by compiling it to bytecode/C++) - but my preference would always be to python. Tim From lie.1296 at gmail.com Thu Feb 25 06:58:11 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 25 Feb 2010 22:58:11 +1100 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <99bd0874-3462-4bb3-8c3c-54b73c88f9a6@q16g2000yqq.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <4b807791$0$8819$c3e8da3@news.astraweb.com> <99bd0874-3462-4bb3-8c3c-54b73c88f9a6@q16g2000yqq.googlegroups.com> Message-ID: <4b8665f5$1@dnews.tpgi.com.au> On 02/24/10 17:07, MattB wrote: > All -- problem solved. Following Lie's suggestions, and the links > from those pages, I went hunting around in my /library/preferences/ > SystemConfiguration/. I opened all of the 6 or 7 files that were in > there, and all looked as if they contained info directly related to my > airport card -- networks, server names, etc. So I copied them to a > backup folder and then deleted them. Then I rebooted. Glad to hear your problem solved. > Then I opened IDLE and was able to raise URLs again. I'm not sure > what it was about those files (or maybe a specific one) -- does anyone > have any ideas? Do the files get auto-generated? If they do, perhaps you could try diff-ing them with your backups and get some clue of what caused it. > Thanks for your help and suggestions while I tried to figure this out. From prasad.chand at gmail.com Thu Feb 25 07:23:24 2010 From: prasad.chand at gmail.com (prasad_chand) Date: Thu, 25 Feb 2010 04:23:24 -0800 (PST) Subject: A more pythonish code Message-ID: Hi, I use python to do simple math problems as a hobby. I have made a program that finds the number of divisors(factors) of a given number. I am hoping to improve my language skills, specifically I would like to re-write the function "prime_factors" more gracefully. While the program works right, I am hoping that I could get some input on how to write better python code. I have attached the code below. def prime_factors(n): """ Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) (1+1) = 10) Updates a global dictionary(my_dict) with prime numbers and number of occurances. In the case of 48 {2:4,3:1} """ tmp_n = n while True: if tmp_n == 1: break tmp_check = tmp_n for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): if tmp_n % x == 0: add_to_dict(x) tmp_n /= x break if tmp_check == tmp_n: #number is prime...so just to add to dict add_to_dict(tmp_n) break def add_one(x): return x+1 def mul(x,y): return x * y def add_to_dict(p_num): if my_dict.has_key(p_num): my_dict[p_num] += 1 else: my_dict[p_num] = 1 my_dict = {} prime_factors(135) l = map(add_one,my_dict.values()) print reduce(mul, l, 1) Thanks for your time. From elias.bachaalany at gmail.com Thu Feb 25 07:25:14 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 04:25:14 -0800 (PST) Subject: Pure virtual functions in Python? References: <4b810953$1@dnews.tpgi.com.au> Message-ID: On Feb 21, 11:21?am, Lie Ryan wrote: > On 02/21/10 19:27,lallouswrote: > > > > If the base defines the method and it was empty, then my C++ code > > would still call the function. This is not optimal because I don't > > want to go from C++ to Python if the _derived_ class does not > > implement the cb. > > That sounds like a microoptimization; have you profiled your code and > determined that calling empty function causes a bottleneck? I doubt it. > > > Now the base class should define it so that doc > > parsers properly describe the base class. > > The recipe suggested is not worth the trouble. > > Unfortunately I cannot use abc module since I use Python 2.5 > > Because nobody here could have guessed that your dispatcher was written > in C++; your problem is near trivial if your dispatcher is a pure-python > code. You are right. I haven't checked how much it costs to continuously call an empty function, but why do it if I know (during initialization from my C++ dispatcher code) that certain Python object should not have certain methods called. I still prefer not to call at all, even if it was an empty function. Regards, Elias From elias.bachaalany at gmail.com Thu Feb 25 07:25:48 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 04:25:48 -0800 (PST) Subject: Pure virtual functions in Python? References: <7udu49Fk3uU1@mid.individual.net> Message-ID: <38ddd614-583c-430d-b998-214bd6360eb2@b2g2000yqi.googlegroups.com> On Feb 22, 12:42?am, Gregory Ewing wrote: > lallouswrote: > > If the base defines the method and it was empty, then my C++ code > > would still call the function. This is not optimal because I don't > > want to go from C++ to Python if the _derived_ class does not > > implement the cb. > > I would simply not implement the method at all in the base > class. Then the C++ code can do an attribute lookup for > the method, and if it's not found, do nothing. > > -- > Greg That is what I currently do. But if I comment out the implementations (empty ones) then the documentation generation tool will not document the callbacks. From lie.1296 at gmail.com Thu Feb 25 07:27:03 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 25 Feb 2010 23:27:03 +1100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <4b866cb8$1@dnews.tpgi.com.au> On 02/25/10 07:40, Wanja Gayk wrote: > Am 24.02.2010, 00:22 Uhr, schrieb Lawrence D'Oliveiro > : > >>> Java - The JVM code been hacked to death by Sun engineers (optimised) >>> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >>> ad-infinitum but nowhere as near to JVM >> >> Python is still faster, though. > > In synthetic microbenchmarks without any practical importance - possibly.. > >> I think a key reason is that its VM supports >> reference-counting, which the Java folks never quite got the grasp of. > > Reference counting is about the worst technique for garbage collection. I disagree IMO, assuming there is no circular reference, reference counting is the simple, lightweight, and best garbage collection technique. Reference counting can free memory (or return it to cache) right after the refcount turns zero; other traditional garbage management techniques runs periodically and there's a delay between getting to zero reference to actual memory release. The other weakness of traditional garbage managers is the symptomatic "stopping the time" whenever the GC is running, which makes it unsuitable for time-sensitive program. The only weakness of reference counting is its inability to detect circular reference, which is why CPython have an additional garbage collector. > Modern Java VM won't count references. They will just trace the active > references from the rootand mark all objects it finds as active and save > these. The remaining ones are garbage. The reason why this is faster is > that there are usually less live objects than dead ones and there are > less refereces to look at. Reference counting is even faster since there is only one object to be looked at: the object that is being dereferenced. There is no need to look at other live objects, there is no need to look other dead objects, just the current object. From elias.bachaalany at gmail.com Thu Feb 25 07:28:12 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 04:28:12 -0800 (PST) Subject: Walking lists Message-ID: Hello I am still learning Python, and have a question, perhaps I can shorten the code: L = ( (1, 2, 3), (4,), (5,), (6, 7) ) for x in L: print x What I want, is to write the for loop, something like this: for (first_element, the_rest) in L: print first_element for x in the_rest: # now access the rest of the elements I know I can : for x in L: first = x[0] rest = x[1:] .... Probably that is not possible, but just asking. Thanks, Elias From __peter__ at web.de Thu Feb 25 07:45:28 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 13:45:28 +0100 Subject: Walking lists References: Message-ID: lallous wrote: > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > for x in L: > print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > print first_element > for x in the_rest: > # now access the rest of the elements > > I know I can : > for x in L: > first = x[0] > rest = x[1:] > .... > Probably that is not possible, but just asking. In Python 3 you can write >>> for first, *rest in L: ... print("first:", first, "rest:", rest) ... first: 1 rest: [2, 3] first: 4 rest: [] first: 5 rest: [] first: 6 rest: [7] Peter From nanyaks at googlemail.com Thu Feb 25 07:46:38 2010 From: nanyaks at googlemail.com (simn_stv) Date: Thu, 25 Feb 2010 04:46:38 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On Feb 25, 12:13 pm, Steve Holden wrote: > simn_stv wrote: > > hello people, i have been reading posts on this group for quite some > > time now and many, if not all (actually not all!), seem quite > > interesting. > > i plan to build an application, a network based application that i > > estimate (and seriously hope) would get as many as 100, 000 hits a day > > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > > or anything like it, its mainly for a financial transactions which > > gets pretty busy... > > so my question is this would anyone have anything that would make > > python a little less of a serious candidate (cos it already is) and > > the options may be to use some other languages (maybe java, C (oh > > God))...i am into a bit of php and building API's in php would not be > > the hard part, what i am concerned about is scalability and > > efficiency, well, as far as the 'core' is concerned. > > > would python be able to manage giving me a solid 'core' and will i be > > able to use python provide any API i would like to implement?... > > > im sorry if my subject was not as clear as probably should be!. > > i guess this should be the best place to ask this sort of thing, hope > > im so right. > > > Thanks > > I'd suggest that if you are running an operation that gets 100,000 hits > a day then your problems won't be with Python but with organizational > aspects of your operation. > > regards > Steve > -- very well noted steve, i'd be careful (which is a very relative word) with the organizational aspects... i'm sure ure quite rooted in that aspect, hey u need a job??........;) From lie.1296 at gmail.com Thu Feb 25 07:50:51 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 25 Feb 2010 23:50:51 +1100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: Message-ID: <4b86724d$1@dnews.tpgi.com.au> On 02/25/10 05:18, kj wrote: > I think I remember, early in my learning of Python, coming across > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > LINES OF CODE", or something to that effect. But now I can't find > it! I've never heard of it, though I can think of a few reasons why TQC might be a bad thing. Especially if a user pydoc-ed your module and see a bunch of meaningless code. > Is my memory playing me a trick? > > After all, from what I've seen since then, the practice of > triple-quote-commenting (or TQC, pardon the TCA) is in fact quite > common. > > Is TQC OK after all? I'd say it's OK for quick and dirty code, or when you're rewriting a significant part of the code especially in early development (or you haven't setup a version control system since it's a damn small script). They shouldn't be permanent though, due to docstring problem. > If not, what's the case against it? > > Also, has the BDFL expressed an opinion on the subject? Alternatively, > is there any other more or less "authoritative" opinion on TQC? From fat.bold.cyclop at gmail.com Thu Feb 25 08:00:48 2010 From: fat.bold.cyclop at gmail.com (fat bold cyclop) Date: Thu, 25 Feb 2010 05:00:48 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? Message-ID: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> I tired to google for comparison of tuple to list but i failed. Could anyone explain it to me? Best regards, fat bold cyclop From python.list at tim.thechases.com Thu Feb 25 08:02:49 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 07:02:49 -0600 Subject: Walking lists In-Reply-To: References: Message-ID: <4B8674F9.2070904@tim.thechases.com> lallous wrote: > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > print first_element > for x in the_rest: > # now access the rest of the elements Python 3 introduced a variable tuple assignment which I suspect[*] would work in this context: for first, *rest in L: # note the asterisk print first for x in rest: do_stuff(x) > I know I can : > for x in L: > first = x[0] > rest = x[1:] However in 2.x, this is the way to do it. Though if you want to abstract the logic, you can move it to a generator: def splitter(i): for t in i: yield t[0], t[1:] for first, rest in splitter(L): print first for x in rest: do_stuff(x) -tkc [*] not having py3 on this machine, I can't readily verify this. From macbeth at panix.com Thu Feb 25 08:06:40 2010 From: macbeth at panix.com (macbeth) Date: Thu, 25 Feb 2010 08:06:40 -0500 Subject: What's the word on using """ to comment-out? In-Reply-To: <4b86724d$1@dnews.tpgi.com.au> Message-ID: > From: Lie Ryan > > On 02/25/10 05:18, kj wrote: > > I think I remember, early in my learning of Python, coming across > > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > > LINES OF CODE", or something to that effect. But now I can't find > > it! > > I've never heard of it, though I can think of a few reasons why TQC > might be a bad thing. Especially if a user pydoc-ed your module and see > a bunch of meaningless code. That is why I was told not to use """ to comment code. Use '#' for code and """ for docs But, I do not remember reading it any where. I found this ---> http://mail.python.org/pipermail/tutor/2004-February/028432.html From python.list at tim.thechases.com Thu Feb 25 08:07:59 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 07:07:59 -0600 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <4B86762F.9090606@tim.thechases.com> simn_stv wrote: > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. Python is as "enterprise" as the developer who wields it. Scalability revolves entirely around application design & implementation. Or you could use Erlang (or haskell, etc ;-) -tkc From gnewsg at gmail.com Thu Feb 25 08:15:04 2010 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Thu, 25 Feb 2010 05:15:04 -0800 (PST) Subject: How to monitor memory usage within Python? (Linux) References: Message-ID: <01248751-3cfb-4603-9b68-9bca36106855@q16g2000yqq.googlegroups.com> On 24 Feb, 23:35, kj wrote: > Is there some standard module for getting info about the process's > memory usage, in a Linux/Unix system? > > (I want to avoid hacks that involve, e.g., scraping ps's output.) > > Thanks! > > ~K http://code.google.com/p/psutil >>> import psutil >>> p = psutil.Process(7055) >>> p.cmdline ['/usr/bin/python'] >>> rss, vms = p.get_memory_info() >>> "Resident memory: %s KB" %(rss / 1024) 'Resident memory: 3768 KB' >>> "Virtual memory: %s KB" %(vms / 1024) 'Virtual memory: 6176 KB' >>> p.get_memory_percent() 0.8342 --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From silvio at nospam.com Thu Feb 25 08:17:55 2010 From: silvio at nospam.com (Silvio) Date: Thu, 25 Feb 2010 14:17:55 +0100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <4b867886$0$22913$e4fe514c@news.xs4all.nl> "Lawrence D'Oliveiro" wrote in message news:hm4icr$q4o$1 at lust.ihug.co.nz... > In message , Wanja Gayk wrote: > >> Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. It means I can write things > like > > contents = open(filename, "r").read() > > and know the file object will be immediately closed after its contents are > returned. > > It also means I don?t have to predefine how much memory my program will > use. > A garbage collector will only kick in when the app runs low on memory. On > a > system with dynamic memory allocation, that will not happen until the > entire > system runs low on memory, unless you limit the app to some fixed amount. > Which is an antiquated way of doing things. > > And then there?s caching. Modern CPUs owe most of their speed to > assumptions > that programs will obey locality of reference. Pointer-chasing is a cache- > hostile activity. Garbage collection involves a lot of pointer-chasing, > particularly of dead objects that have long since been flushed from the > cache, compared with reference counting of recently-accessed objects. > Therefore garbage collection loses performance. Reference counting is a technique that is only applicable for a subset of scenarios GC can handle. RC fails when circular dependencies exist. In an ancient past I have worked with RC-based C++ frameworks and they where either very restrictive to prevent circular dependencies or ignored them resulting in memory leaks. In addition, for fast create/destroy scenario's (for examples loops that allocate objects with single cycle lifetimes) a generational GC is MUCH faster than manual malloc/free new/delete code because it enables a completely different heap management logic. Reference counting only adds to the slowness in this scenario. You are also incorrect in stating that a GC will only kick in when memory becomes scarce. Partial GCs will happen very frequently (thereby invalidating your point about caching) and are extremely fast. Only full GCs are infrequent and take more time but they will typically run in a separate thread. No general statement about the relative speed of generational GC systems versus manual heap management (or the slower variant RC) can be made since they have completely different best, general and worse case behavior and scenarios. In response to your original post: please provide links to examples of quality benchmark results. There are numerous language speed comparison benchmarks that usually put Python in the tail region with Ruby and the likes for many different applications. If you have opposing examples then you should provide them. Silvio From __peter__ at web.de Thu Feb 25 08:26:18 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 14:26:18 +0100 Subject: Using mock library (written by Michael Foord) References: <5989a385-ee81-4708-8409-3299e83dcfa7@k17g2000yqb.googlegroups.com> Message-ID: Lacrima wrote: > I use mock library http://www.voidspace.org.uk/python/mock/. There is > no user group for the library, so I post in comp.lang.python and hope > that people who use it will help me. > > The library allows to patch objects, using patch decorator. Patching > is done only within the scope of the function. So if I have a lot of > tests that need specific object to be patched I have to specify the > same decorator for each test method: > > class TestSomething(unittest.TestCase): > > @patch('module.Class', spec = True) > def test_method1(self, MockClass): > Class() > self.assertEquals(MockClass.called) > > @patch('module.Class', spec = True) > def test_method2(self, MockClass): > Class() > MockClass.assert_called_with('foo') > > @patch('module.Class', spec = True) > def test_method3(self, MockClass): > foo = Class() > self.assertRaises(AttributeError, foo.some_method) > > # and more ... > > So for every test method I always do the same patching! How can I > avoid this? I don't know mock, but the following is generic and should continue to work when you replace the faux patch() function with the one from the mock module. import unittest def patch(v): def patch(f): print "%s-patching" % v, f.__name__ return f return patch def make_postprocess(*args, **kw): def postprocess(name, bases, classdict): for k, v in classdict.items(): if k.startswith("test_"): classdict[k] = patch(*args, **kw)(v) return type(name, bases, classdict) return postprocess class A(unittest.TestCase): __metaclass__ = make_postprocess("Y") def test_bar(self): print "bar" def test_baz(self): print "baz" def foo(self): pass if __name__ == "__main__": unittest.main() Peter From arnodel at googlemail.com Thu Feb 25 08:26:45 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 05:26:45 -0800 (PST) Subject: Walking lists References: Message-ID: lallous wrote: > Hello > > > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > for x in L: > print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > print first_element > for x in the_rest: > # now access the rest of the elements > > I know I can : > for x in L: > first = x[0] > rest = x[1:] Others have replied about Python 3. In Python 2.x, you can use an iterator: for tuple in L: it = iter(tuple) first = it.next() for x in it: ... HTH -- Arnaud From elias.bachaalany at gmail.com Thu Feb 25 08:30:06 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 05:30:06 -0800 (PST) Subject: Walking lists References: Message-ID: Thank you all for the replies. The solution using Python 3's syntax look very intuitive. Thanks Tim, Arnaud for the idea (I am using 2.x) -- Elias On Feb 25, 1:28?pm, lallous wrote: > Hello > > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > ? (1, 2, 3), > ? (4,), > ? (5,), > ? (6, 7) > ) > > for x in L: > ? ? print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > ? print first_element > ? for x in the_rest: > ? ? # now access the rest of the elements > > I know I can : > for x in L: > ? ? first = x[0] > ? ? rest = x[1:] > ? ? .... > Probably that is not possible, but just asking. > > Thanks, > Elias From mrkafk at gmail.com Thu Feb 25 08:30:12 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 14:30:12 +0100 Subject: The best way to check if two lists have identical values Message-ID: Hello everyone, I have stumbled upon this seemingly trivial problem: the answer is not there in http://www.python.org/doc/faq/programming/, and googling does not return many references really (at least for me). I have come up with this: def qips_identical(q, oldq): qips = map(operator.itemgetter(1), q) oldqips = map(operator.itemgetter(1), oldq) if len(qips) != len(oldqips): return False dif = set(qips) ^ set(oldqips) if len(dif): return False return True There's a number of complications here, depending on definition of 'lists with identical values', like whether the same value can be repeated different number of times in two lists, or whether the order of values matters. In above example I assumed that the same values have to be repeated the same numbers of times in both lists and that order doesn't matter so long as the values are the same. I was wondering if there's a better / shorter / faster way to do this -- not necessarily in the same variant, e.g. variant where order of two lists matters would be interesting as well. Regards, mk From mrkafk at gmail.com Thu Feb 25 08:38:19 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 14:38:19 +0100 Subject: Easter Eggs In-Reply-To: References: Message-ID: On 2010-02-25 03:04, Gabriel Genellina wrote: > Also try: > import antigravity Is this Py3 egg? My 2.6 doesn't seem to get it. Regards, mk From spamfresser at ch3ka.de Thu Feb 25 08:44:20 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 14:44:20 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: <4B8651BE.7080500@sequans.com> Message-ID: Am 25.02.2010 11:58, schrieb Jean-Michel Pichavant: >> You said it yourself: "simply make two or three functions and name >> them appropiately" :-) >> >> When 2 methods of a class were to have the same name for doing >> completely different things like you said, there's a design flaw to my >> opinion. >> >> JM > I wonder if I've just written that my opinion is flawed... It surely is, > but that's not why I meant :-) :D Well, there might be cases when someone wants to do this. consider: (pseudocode - this is *not* python ;) class Machines (Object): @classmethod def shutdown(cls, Machine, emergency=False): try: if Machine is instanceof(Fileservers): if not emergency: Machine.unmount_raid_first() ... Machine.halt() if Machine is instanceof(Router): if not emergency: cls.shutdown(Machine.attachedmachines) ... ... finally: if emergency and Machine has powerswitch: Machine.powerswitch.Off() @classmethod def emergency(cls): for machine in cls.instances: cls.shutdown(machine, 1) Other design patterns might me good too, but I like the idea of having emergency protocols in *one* place here. But without method overloading, there are many many nested 'if's. One could say that the machines have to know how to shut down itself, but there might be dependencies they do not know about, and as said, it clutters the emergency protocol all over the modules. One could define normal_shutdown() and emergency_shutdown(), but I do not like this eighter, and there are still many 'if's to seperate the types. There are cases where *no* solution is perfect, and those are the cases where "2 methods of a class were to have the same name for doing completely different things" or other messy things like this are IMO *NOT* a design flaw. Regards, Michael From stefan_ml at behnel.de Thu Feb 25 08:46:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 14:46:56 +0100 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: fat bold cyclop, 25.02.2010 14:00: > I tired to google for comparison of tuple to list but i failed. > > Could anyone explain it to me? Both are not equal, so the comparison returns an arbitrary result in Py2. Note that this was fixed in Py3: 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. >>> (1,2,3) > [1,2,3] Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: tuple() > list() Stefan From __peter__ at web.de Thu Feb 25 08:46:56 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 14:46:56 +0100 Subject: The best way to check if two lists have identical values References: Message-ID: mk wrote: > I have stumbled upon this seemingly trivial problem: the answer is not > there in http://www.python.org/doc/faq/programming/, and googling does > not return many references really (at least for me). > > I have come up with this: > > def qips_identical(q, oldq): > qips = map(operator.itemgetter(1), q) > oldqips = map(operator.itemgetter(1), oldq) I don't think the above is a relevant part of the problem. > if len(qips) != len(oldqips): > return False > dif = set(qips) ^ set(oldqips) > if len(dif): > return False > return True > > There's a number of complications here, depending on definition of > 'lists with identical values', like whether the same value can be > repeated different number of times in two lists, or whether the order of > values matters. > > In above example I assumed that the same values have to be repeated the > same numbers of times in both lists and that order doesn't matter so > long as the values are the same. No you haven't. [1, 1, 0] and [1, 0, 0] are considered equal by your algorithm. > I was wondering if there's a better / shorter / faster way to do this -- > not necessarily in the same variant, e.g. variant where order of two > lists matters would be interesting as well. sorted(left_list) == sorted(right_list) should be good enough in most cases where you do care for repetitions but not order. Peter From arnodel at googlemail.com Thu Feb 25 08:55:26 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 05:55:26 -0800 (PST) Subject: The best way to check if two lists have identical values References: Message-ID: <045a9d2d-3fd7-4aed-9fb3-83e7e70cc881@v20g2000yqv.googlegroups.com> mk wrote: > Hello everyone, > > I have stumbled upon this seemingly trivial problem: the answer is not > there in http://www.python.org/doc/faq/programming/, and googling does > not return many references really (at least for me). > > I have come up with this: > > def qips_identical(q, oldq): > qips = map(operator.itemgetter(1), q) > oldqips = map(operator.itemgetter(1), oldq) > if len(qips) != len(oldqips): > return False > dif = set(qips) ^ set(oldqips) > if len(dif): > return False > return True > > There's a number of complications here, depending on definition of > 'lists with identical values', like whether the same value can be > repeated different number of times in two lists, or whether the order of > values matters. > > In above example I assumed that the same values have to be repeated the > same numbers of times in both lists and that order doesn't matter so > long as the values are the same. Your code checks if the two lists have the same length and the same elements, but not necessarily the same number of each elements. E.g. qips = [1, 1, 2] oldqips = [1, 2, 2] will return True If you want to check if each value has the same number of occurences, you can do return sorted(qips) == sorted(oldqips) assuming that all elements in the lists are comparable. -- Arnaud From darcy at druid.net Thu Feb 25 08:58:16 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 25 Feb 2010 08:58:16 -0500 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <20100225085816.fc9d4013.darcy@druid.net> On Thu, 25 Feb 2010 02:26:18 -0800 (PST) simn_stv wrote: > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day That's nothing. I ran a financial type app on Python that sometimes hit 100,000 transactions an hour. We kept looking for bottlenecks that we could convert to C but never found any. Our biggest problem was in a network heavy element of the app and that was low level TCP/IP stuff that rather than being Python's problem was something we used Python to fix. As others have pointed out, you will want some kind of enterprise database that will do a lot of the heavy lifting. I suggest PostgreSQL. It is the best open source database engine around. That will take the biggest load off your app. There's lots of decisions to make in the days ahead but I think that choosing Python as your base language is a good first one. > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. Scaleability and efficiency won't be your issues. Speed of development and clarity of code will be. Python wins. -- 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 fat.bold.cyclop at gmail.com Thu Feb 25 09:03:03 2010 From: fat.bold.cyclop at gmail.com (fat bold cyclop) Date: Thu, 25 Feb 2010 06:03:03 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> > Both are not equal, so the comparison returns an arbitrary result in Py2. Thanks, Stefan. If I understand you correctly the comparison is not valid. But I wonder if there is any logic behind this (in 2.x). Is it possible to predict result of this comparison? Thanks again, fbc From mrkafk at gmail.com Thu Feb 25 09:05:56 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 15:05:56 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-25 02:07, Steven D'Aprano wrote: > On Wed, 24 Feb 2010 18:23:17 +0100, mk wrote: > >> Anyway, the passwords for authorized users will be copied and pasted >> from email into in the application GUI which will remember it for them, >> so they will not have to remember and type them in. > > So to break your application's security model, all somebody has to do is > use their PC and they have full access to their account? > > Or get hold of the copy and paste buffer? > > Or the application's config files? Yes. There's no way around this, short of forcing them to use hardware key, which is an overkill for this application. >> So I have little in >> the way of limitations of password length - even though in *some* cases >> somebody might have to (or be ignorant enough) to retype the password >> instead of pasting it in. > Or your users might be sensible enough to not trust a role-your-own > security model, and prefer to memorize the password than to trust that > nobody will get access to their PC. The app is not that critical, it's about quarterly subscription to the service, and the users will be able to reset the password anyway. If it were that critical, I'd use the hardware keys; if hardware keys are not used, once somebody gains an (unconstrained) access to the user's PC, there's not much that app developer can do. I've read somewhere a warning from PuTTY developer that even though the key is (normally) protected by the passphrase, losing even an encrypted key is quite likely to lead to its compromise. There's even some software for that on the net: http://www.neophob.com/serendipity/index.php?/archives/127-PuTTY-Private-Key-cracker.html >> The main application will access the data using HTTP (probably), so the >> main point is that an attacker is not able to guess passwords using >> brute force. > And why would they bother doing that when they can sniff the wire and get > the passwords in plain text? You should assume your attackers are > *smarter* than you, not trust them to be foolish. I should have written HTTPS. Regards, mk From jeanmichel at sequans.com Thu Feb 25 09:18:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 15:18:38 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: <4b810953$1@dnews.tpgi.com.au> Message-ID: <4B8686BE.5020907@sequans.com> lallous wrote: > I still prefer not to call at all, even if it was an empty function. > > Regards, > Elias > Is there any way we could convince you that there is no point caring about this ? Even if you were trying to optimize speed, it would still require proof that an empty function is part of the problem. It sounds like someone stating "I prefer to write difficult-to-read code, because in 1978, code size used to matter". JM From chardster at gmail.com Thu Feb 25 09:21:56 2010 From: chardster at gmail.com (Richard Thomas) Date: Thu, 25 Feb 2010 06:21:56 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: On Feb 25, 2:03?pm, fat bold cyclop wrote: > > Both are not equal, so the comparison returns an arbitrary result in Py2. > > Thanks, Stefan. If I understand you correctly the comparison is not > valid. > But I wonder if there is any logic behind this (in 2.x). > Is it possible to predict result of this comparison? > > Thanks again, > fbc I believe in 2.x they are ordered by the names of their types but I could be wrong. 1 < [] < '' < () < u'' From iainking at gmail.com Thu Feb 25 09:22:53 2010 From: iainking at gmail.com (Iain King) Date: Thu, 25 Feb 2010 06:22:53 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: <0f015e4c-bc37-4322-aa5c-e071e860efd3@33g2000yqj.googlegroups.com> On Feb 25, 2:03?pm, fat bold cyclop wrote: > > Both are not equal, so the comparison returns an arbitrary result in Py2. > > Thanks, Stefan. If I understand you correctly the comparison is not > valid. > But I wonder if there is any logic behind this (in 2.x). > Is it possible to predict result of this comparison? > > Thanks again, > fbc I haven't looked in the source to check (and I'm almost 100% certain that tuple > list is an implementation detail), but I have not found any pair of tuple and list in which the list is treated as the greater. Possibly related: type(tuple()) is > type(list()). Or, to let the interpreter tell you why (1,2,3) > [1,2,3]: >>> tuple > list True Iain From daniel at stutzbachenterprises.com Thu Feb 25 09:25:22 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 25 Feb 2010 08:25:22 -0600 Subject: The best way to check if two lists have identical values In-Reply-To: References: Message-ID: On Thu, Feb 25, 2010 at 7:30 AM, mk wrote: > There's a number of complications here, depending on definition of 'lists > with identical values', like whether the same value can be repeated > different number of times in two lists, or whether the order of values > matters. > Order and repetitions matter: list1 == list2 Repetition matters, order does not: sorted(list1) == sorted(list2) # items must be comparable Neither matters: set(list1) == set(list2) # items must be hashable -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Feb 25 09:27:47 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 15:27:47 +0100 Subject: Walking lists In-Reply-To: References: Message-ID: <4B8688E3.9000909@sequans.com> lallous wrote: > Thank you all for the replies. > > The solution using Python 3's syntax look very intuitive. > > Thanks Tim, Arnaud for the idea (I am using 2.x) > > -- > Elias > On Feb 25, 1:28 pm, lallous wrote: > >> Hello >> >> I am still learning Python, and have a question, perhaps I can shorten >> the code: >> >> L = ( >> (1, 2, 3), >> (4,), >> (5,), >> (6, 7) >> ) >> >> for x in L: >> print x >> >> What I want, is to write the for loop, something like this: >> >> for (first_element, the_rest) in L: >> print first_element >> for x in the_rest: >> # now access the rest of the elements >> >> I know I can : >> for x in L: >> first = x[0] >> rest = x[1:] >> .... >> Probably that is not possible, but just asking. >> >> Thanks, >> Elias >> Using slicing + list comprehension with python 2.x for first, rest in [(e[0],e[1:]) for e in L]: print first print rest 1 (2, 3) 4 () 5 () 6 (7,) But honestly, the code you provided is just fine. JM From mrkafk at gmail.com Thu Feb 25 09:43:53 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 15:43:53 +0100 Subject: The best way to check if two lists have identical values In-Reply-To: <045a9d2d-3fd7-4aed-9fb3-83e7e70cc881@v20g2000yqv.googlegroups.com> References: <045a9d2d-3fd7-4aed-9fb3-83e7e70cc881@v20g2000yqv.googlegroups.com> Message-ID: On 2010-02-25 14:55, Arnaud Delobelle wrote: > Your code checks if the two lists have the same length and the same > elements, but not necessarily the same number of each elements. E.g. > > qips = [1, 1, 2] > oldqips = [1, 2, 2] > > will return True > > If you want to check if each value has the same number of occurences, > you can do > > return sorted(qips) == sorted(oldqips) > > assuming that all elements in the lists are comparable. Thanks! Regards, mk From stefan_ml at behnel.de Thu Feb 25 09:54:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 15:54:58 +0100 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: fat bold cyclop, 25.02.2010 15:03: >> Both are not equal, so the comparison returns an arbitrary result in Py2. > Thanks, Stefan. If I understand you correctly the comparison is not > valid. > But I wonder if there is any logic behind this (in 2.x). > Is it possible to predict result of this comparison? The result is predictable, it's just arbitrary in that it does not depend on the values that you are comparing but only on their type. Stefan From mrkafk at gmail.com Thu Feb 25 10:03:47 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 16:03:47 +0100 Subject: Is this secure? In-Reply-To: <7xk4u26qz0.fsf@ruckus.brouhaha.com> References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-25 02:31, Paul Rubin wrote: > It might be helpful if you could say what your application does, or > anyway give an idea of what its actual security requirements are. > Generating and emailing someone a random password is a fairly standard > method for (e.g.) web forums to verify that the person has supplied a > working email address, basically as a first level spam filter. Your > scheme is probably ok for that. If you're doing something with more > demanding security requirements, then as mentioned before, there is a > whole lot of stuff you have to pay attention to, and focusing narrowly > on password generation isn't that useful. OK some data: 1. I'm going to probably use HTTPS (I meant HTTP over SSL, but wrote HTTP instead of being precise) 2. The app will have GUI and it will be locally installed; it's not going to be web app, it will just be online in the sense of downloading data frequently from the net. 3. I can't disclose the details on what the app will be doing, but it's not going to be terribly security-critical, medium-level at most - what happens in the app itself is not _directly_ related to money. 4. The app will be based on subscription model, costing $10-$20 per month. It's not really doing online banking or smth like that. 5. The worst thing that can happen when security of some account is compromised is that the user will have to reset the password, resending it to predefined email (I don't really see the way of organizing it in a different manner). I'm thinking about optionally passphrase-securing the password saved in GUI. In that case 'diceware' approach would be helpful. I certainly do not want to focus narrowly on password generation: the entire security model will have to be worked out, but the project didn't get to that stage yet, it's all still in planning stages. I just wanted to have this one part (password generation) researched before I get to other stages so I don't have to implement this later in haste and do smth wrong. Regards, mk From invalid at invalid.invalid Thu Feb 25 10:07:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 25 Feb 2010 15:07:12 +0000 (UTC) Subject: What's the word on using """ to comment-out? References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: On 2010-02-25, Paul Rudin wrote: > kj writes: > >> I think I remember, early in my learning of Python, coming across >> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT >> LINES OF CODE", or something to that effect. But now I can't find >> it! > > No idea, but it would be nice to have some multiline comment syntax > (other than # at the beginning of each line). Particularly one that can > be nested. if 0: Seriously, that's what I generally do: mark the block of code, indent it 1 level, add an if 0: at the top. -- Grant Edwards grante Yow! What a COINCIDENCE! at I'm an authorized "SNOOTS visi.com OF THE STARS" dealer!! From lucat at despammed.com Thu Feb 25 10:26:32 2010 From: lucat at despammed.com (Luca) Date: Thu, 25 Feb 2010 16:26:32 +0100 Subject: Renaming identifiers & debugging Message-ID: <7unj59FuorU1@mid.individual.net> Hello, i am trying to develop an application to teach programming to young kids in a similar way as Logo did in the past. I would like to use an embedded Python as underlying language but this raises a problem. The target of my app are very young kids that might be unfamiliar with english, so i am wondering if there is a way to rename/redefine identifiers and messages in the language of the kid. In UCB-Logo this is very easy with the command COPYDEF "newidentifier "oldidentifier so all you have to do is setup a startup script to redefine all the identifiers to the language of the user. Is there anything similar for python? Since python would be embedded it would not be a problem for me to do it through some API. Also, i would need a way to debug the program, so set up breakpoints, execute line by line, inspect variables, is there any API for this in embedded python? Thank you, Luca From martin.hellwig at dcuktec.org Thu Feb 25 10:29:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Feb 2010 15:29:34 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > Our biggest problem was in > a network heavy element of the app and that was low level TCP/IP stuff > that rather than being Python's problem was something we used Python to > fix. Out off interest, could you elaborate on that? Thanks -- mph From spamfresser at ch3ka.de Thu Feb 25 10:39:27 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 16:39:27 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: Am 25.02.2010 16:07, schrieb Grant Edwards: > On 2010-02-25, Paul Rudin wrote: >> No idea, but it would be nice to have some multiline comment syntax >> (other than # at the beginning of each line). Particularly one that can >> be nested. > > if 0: > > Seriously, that's what I generally do: mark the block of code, > indent it 1 level, add an if 0: at the top. > I really hate it when I see something like this in other's code. The fact that my IDE (vim) still displays this like valid code ready to be executed can cause extreme frustration while trying to spot a bug. This is almost as bad as "commenting out" (parts of) a for loop by adding a continue. I once saw this in production code and wanted to kill the original developer, as commenting out the parts of the code with the continue (it was a *biiiig* for-loop) for debugging purposes actually would have *enabled* the code below, thus rendering the whole database useless. Lucky me that I a) had backups b) set up a sandbox and c) actually saw this before it was too late. Regards, Michael From affdfsdfdsfsd at b.com Thu Feb 25 10:39:34 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 25 Feb 2010 15:39:34 GMT Subject: round() function Message-ID: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> hi all, i've this sample code: >>> n = 4.499 >>> str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advance Nico From python.list at tim.thechases.com Thu Feb 25 10:45:16 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 09:45:16 -0600 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <4B869B0C.5060601@tim.thechases.com> Tracubik wrote: >>>> n = 4.499 >>>> str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. Use string formatting: >>> "%0.2f" % round(4.499, 2) '4.50' -tkc From ivan.python1 at gmail.com Thu Feb 25 10:45:37 2010 From: ivan.python1 at gmail.com (mailing list) Date: Thu, 25 Feb 2010 16:45:37 +0100 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <4B869B21.4010808@gmail.com> On 25.2.2010. 16:39, Tracubik wrote: > hi all, i've this sample code: > > >>>> n = 4.499 >>>> str(round(n,2)) >>>> > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? > > Thanks in advance > Nico > You may wanna use string formating, e.g.: print "%.2f" % 4.5 From stefan_ml at behnel.de Thu Feb 25 10:46:18 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 16:46:18 +0100 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: Tracubik, 25.02.2010 16:39: > hi all, i've this sample code: > >>>> n = 4.499 >>>> str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? Format the number as a string: print("%.2f" % round(n,2)) Stefan From jlconlin at gmail.com Thu Feb 25 10:48:44 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 25 Feb 2010 07:48:44 -0800 (PST) Subject: Can I specify regex group to return float or int instead of string? Message-ID: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> I have a regular expression that searches for some numbers and puts them into a dictionary, i.e. '(?P\d+)\s+(?P\d+\.\d+)' Is it possible to have the results of the matches returned as int or float objects instead of strings? Thanks, Jeremy From spamfresser at ch3ka.de Thu Feb 25 10:51:40 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 16:51:40 +0100 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: Am 25.02.2010 16:39, schrieb Tracubik: > hi all, i've this sample code: > >>>> n = 4.499 >>>> str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? > > Thanks in advance > Nico This has nothing to do with round(). round() returns a float, and float(4.50) is 4.5. You can *print* it as 4.50 using format strings, but the float will always be 4.5 >>> n = 4.499 >>> x=round(n,2) >>> x 4.5 >>> print "%.2f" % x 4.50 >>> s="%.2f" % round(n,2) >>> s '4.50' >>> From nicola.larosa at gmail.com Thu Feb 25 10:51:51 2010 From: nicola.larosa at gmail.com (Nicola Larosa (tekNico)) Date: Thu, 25 Feb 2010 07:51:51 -0800 (PST) Subject: Recommended "new" way for config files References: Message-ID: <28c20bf9-2522-442d-a6b9-82a68f267dd5@z35g2000yqd.googlegroups.com> Peter wrote: > There seems to be several strategies to enhance the old ini-style config > files with real python code > [...] > Is there a strategy that should be prefered for new projects ? 5) Use ConfigObj , by Michael Foord and yours truly. It uses an extension of the ini- style config format. Sorry for the multiple brackets, my fault. :-) -- Nicola Larosa - http://www.tekNico.net/ Ci sono paesi in cui un gesto violento se compiuto da un uomo su una don- na ? punito pi? severamente: si chiama uguaglianza sostanziale, compensa la disuguaglianza di partenza. [...] Se vince la cultura dei "vincenti" le donne perderanno. Non fanno la guerra, in genere. ? una perdita di tempo: hanno altro da fare. - Concita De Gregorio, Novembre 2009 From mwilson at the-wire.com Thu Feb 25 10:58:14 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 25 Feb 2010 10:58:14 -0500 Subject: When will Java go mainstream like Python? References: Message-ID: sjdevnull at yahoo.com wrote: > You're right that ref counting in many implementations is more > deterministic than other common forms of garbage collection; IMO, > Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec--or at least > guaranteeing that when a function returns, any otherwise unreferenced > locals are immediately collected. That would be nice. The argument against it is that it would make implementations like Jython very difficult to make, if it didn't rule them out altogether. Mel. From pruebauno at latinmail.com Thu Feb 25 11:11:09 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 25 Feb 2010 08:11:09 -0800 (PST) Subject: A more pythonish code References: Message-ID: <9a564658-8b6b-4510-ba1f-ac259c7d8700@o30g2000yqb.googlegroups.com> prasad_chand wrote: > Hi, > > I use python to do simple math problems as a hobby. > > I have made a program that finds the number of divisors(factors) of a > given number. I am hoping to improve my language skills, specifically > I would like to re-write the function "prime_factors" more gracefully. > While the program works right, I am hoping that I could get some input > on how to write better python code. I have attached the code below. > > > def prime_factors(n): > """ > Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) > (1+1) = 10) > > Updates a global dictionary(my_dict) with prime numbers and number > of occurances. In the case of 48 {2:4,3:1} > > """ > tmp_n = n > > while True: > > if tmp_n == 1: > break > > tmp_check = tmp_n > > for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > if tmp_n % x == 0: > add_to_dict(x) > tmp_n /= x > break > > if tmp_check == tmp_n: #number is prime...so just to add to > dict > add_to_dict(tmp_n) > break > > > def add_one(x): > return x+1 > > > def mul(x,y): > return x * y > > def add_to_dict(p_num): > if my_dict.has_key(p_num): > my_dict[p_num] += 1 > else: > my_dict[p_num] = 1 > > > my_dict = {} > > > prime_factors(135) > l = map(add_one,my_dict.values()) > print reduce(mul, l, 1) > > > Thanks for your time. I did a quick refactoring for Python 3.1 (should mostly work in older versions too): from math import ceil, sqrt from functools import reduce from collections import defaultdict from operator import mul def prime_factors(n): """ Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) (1+1) = 10) """ factors = defaultdict(int) while n != 1: for x in range(2,int(ceil(sqrt(n)) + 1)): if n % x == 0: factors[x] += 1 n /= x break else: #number is prime...so just to add to dict factors[int(n)] += 1 break return factors factors = prime_factors(135) exponents = [x+1 for x in factors.values()] print(reduce(mul, exponents, 1)) From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 25 11:16:58 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Feb 2010 17:16:58 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: <4B8651BE.7080500@sequans.com> Message-ID: <4b86a265$0$695$426a34cc@news.free.fr> Michael Rudolf a ?crit : (snip) > (pseudocode - this is *not* python ;) > > class Machines (Object): > @classmethod > def shutdown(cls, Machine, emergency=False): > try: > if Machine is instanceof(Fileservers): > if not emergency: > Machine.unmount_raid_first() > ... > Machine.halt() > if Machine is instanceof(Router): > if not emergency: > cls.shutdown(Machine.attachedmachines) > ... > ... > finally: > if emergency and Machine has powerswitch: > Machine.powerswitch.Off() > @classmethod > def emergency(cls): > for machine in cls.instances: > cls.shutdown(machine, 1) > > One could say that the machines have to know how to shut down itself, Indeed !-) > but there might be dependencies they do not know about, Then it's the "Machines" (or a "MachineShutdownProtocol" or whatever) responsability to manage correct operation order, and you need an API to allow communication between the Machine objects and the WhateverItsName object in charge of monitoring the process. All this if you do care about correct OO design, of course - as far as I'm concerned, practicallity beats purity !-) > and as said, it > clutters the emergency protocol all over the modules. Tradeoff, tradeoff. The above won't work for a "plug&play" system. > There are cases where *no* solution is perfect, There is always at least one "less worse" solution, depending on the concrete use case. From darcy at druid.net Thu Feb 25 11:18:14 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 25 Feb 2010 11:18:14 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <20100225111814.c32887b9.darcy@druid.net> On Thu, 25 Feb 2010 15:29:34 +0000 "Martin P. Hellwig" wrote: > On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > > > Our biggest problem was in > > a network heavy element of the app and that was low level TCP/IP stuff > > that rather than being Python's problem was something we used Python to > > fix. > > Out off interest, could you elaborate on that? Somewhat - there is an NDA so I can't give exact details. It was crucial to our app that we sync up databases in Canada and the US (later Britain, Europe and Japan) in real time with those transactions. Our problem was that even though our two server systems were on the backbone, indeed with the same major carrier, we could not keep them in sync. We were taking way to long to transact an update across the network. The problem had to do with the way TCP/IP works, especially closer to the core. Our provider was collecting data and sending it only after filling a buffer or after a timeout. The timeout was short so it wouldn't normally be noticed and in most cases (web pages e.g.) the connection is opened, data is pushed and the connection is closed so the buffer is flushed immediately. Our patterns were different so we were hitting the timeout on every single transaction and there was no way we would have been able to keep up. Our first crack at fixing this was to simply add garbage to the packet we were sending. Making the packets an order of magnitude bigger sped up the proccessing dramatically. That wasn't a very clean solution though so we looked for a better way. That better way turned out to asynchronous update transactions. All we did was keep feeding updates to the remote site and forget about ACKS. We then had a second process which handled ACKS and tracked which packets had been properly transferred. The system had IDs on each update and retries happened if ACKS didn't happen soon enough. Naturally we ignored ACKS that we had already processed. All of the above (and much more complexity not even discussed here) was handled by Python code and database manipulation. There were a few bumps along the way but overall it worked fine. If we were using C or even assembler we would not have sped up anything and the solution we came up with would have been horrendous to code. As it was I and my chief programmer locked ourselves in the boardroom and had a working solution before the day was out. Python wins again. -- 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 electriclightheads at gmail.com Thu Feb 25 11:22:22 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 26 Feb 2010 01:22:22 +0900 Subject: hs.py = run an exec and pipe back the result as a member of a list Message-ID: <1078018b1002250822y2998e500r85f52646fa1fd190@mail.gmail.com> did this for hascillator01 that i ghc-ed from hascillator01.hs into ./ import popen2 wave = [] for frame in range(890, 1010): wave.append(int(popen2.Popen3('./hascillator01 ' + str(frame)).fromchild.readline())) print wave hascillator01 takes int and returns another int so yes this became a [ints] and that is what i expected but also yes it is so slow any cooler way to do it? now am reading the suprocess's doc .. but a bit hard to get it -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From electriclightheads at gmail.com Thu Feb 25 11:24:33 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 26 Feb 2010 01:24:33 +0900 Subject: hs.py = run an exec and pipe back the result as a member of a list In-Reply-To: <1078018b1002250822y2998e500r85f52646fa1fd190@mail.gmail.com> References: <1078018b1002250822y2998e500r85f52646fa1fd190@mail.gmail.com> Message-ID: <1078018b1002250824x26fe456cg9588e1d7b64386e7@mail.gmail.com> oops the code was wrong .. sorry import popen2 wave = [] for frame in range(890, 1010): wave.append(int(popen2.Popen3('./hascillator01 ' + str(frame)).fromchild.readline())) print wave On Fri, Feb 26, 2010 at 1:22 AM, '2+ wrote: > did this for hascillator01 that i ghc-ed from hascillator01.hs into ./ > > import popen2 > > wave = [] > for frame in range(890, 1010): > wave.append(int(popen2.Popen3('./hascillator01 ' + > str(frame)).fromchild.readline())) > print wave > > hascillator01 takes int and returns another int > so yes this became a [ints] and that is what i expected > but also yes it is so slow > any cooler way to do it? > now am reading the suprocess's doc .. but a bit hard to get it > > -- > SaRiGaMa's Oil Vending Orchestra > is podcasting: > http://sarigama.namaste.jp/podcast/rss.xml > -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From aahz at pythoncraft.com Thu Feb 25 11:31:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 08:31:32 -0800 Subject: Easter Eggs References: Message-ID: In article , mk wrote: >On 2010-02-25 03:04, Gabriel Genellina wrote: >> >> Also try: >> import antigravity > >Is this Py3 egg? My 2.6 doesn't seem to get it. Maybe 2.7 will have it; 3.0.1 does. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From robert.kern at gmail.com Thu Feb 25 11:32:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Feb 2010 10:32:20 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-25 09:03 AM, mk wrote: > 2. The app will have GUI and it will be locally installed; it's not > going to be web app, it will just be online in the sense of downloading > data frequently from the net. If you are storing the password instead of making your user remember it, most platforms have some kind of keychain secure password storage. I recommend reading up on the APIs available on your targeted platforms. -- 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 skylarking11 at gmail.com Thu Feb 25 11:33:31 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Thu, 25 Feb 2010 08:33:31 -0800 (PST) Subject: Trouble with ftplib uploading to an FTP server References: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> <79927f7d-d186-46f1-ab58-94a8d5f973fc@g10g2000yqh.googlegroups.com> Message-ID: <7b518e48-655e-43a6-ac8c-dd473cdcba22@33g2000yqj.googlegroups.com> On Feb 25, 1:10?am, Dennis Lee Bieber wrote: > On Wed, 24 Feb 2010 17:21:58 -0800 (PST), Sky Larking > declaimed the following in > gmane.comp.python.general: > > > For instance I just ran the script and os.rename() renamed it to: > > > TestMachine.local @ 02-24-2010 2020.txt > > > in that .txt file it reads: > > > Asset: TestMachine.local Checking in from IP#: xx.xxx.xx.xxx > > > This is what I want, but the FTP piece doesn't seem to work... > > ? ? ? ? But since you haven't CLOSED the file before invoking the FTP > operation, the contents are probably in a write buffer that hasn't been > flushed. Renaming a file only changes the directory entry -- doesn't do > anything for what may or may not be in the file. > > ? ? ? ? After the program exits, the file get closed, which means the > buffers are flushed. > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ?HTTP://wlfraed.home.netcom.com/ I see my mistake now, I closed the file ...then did the upload ... and the data was there -- thanks for the help From aahz at pythoncraft.com Thu Feb 25 11:33:59 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 08:33:59 -0800 Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: In article <5cd38064-34d6-40d3-b3dc-2c853fc86728 at i39g2000yqm.googlegroups.com>, simn_stv wrote: > >i plan to build an application, a network based application that i >estimate (and seriously hope) would get as many as 100, 000 hits a day >(hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' >or anything like it, its mainly for a financial transactions which >gets pretty busy... Remember that YouTube runs on Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From hseylan at dr.com Thu Feb 25 11:35:40 2010 From: hseylan at dr.com (huseyin) Date: Thu, 25 Feb 2010 08:35:40 -0800 (PST) Subject: CGI File Upload Problem with Python 3.1 on IIS 7 Message-ID: <05322717-d98b-4da4-8b3a-333b42f19f89@z11g2000yqz.googlegroups.com> I am trying to upload files through cgi script written in python 3.1 on a Windows IIS 7 server. The server time out when I write in usual way that is form=cgi.cgi.FieldStorage() fileitem = form['filename'] fn = os.path.basename(fileitem.filename) open('/tmp/' + fn, 'wb').write(fileitem.file.read()) I think there is a problem with stdin, I checked it with: s=sys.stdin.buffer.read(1024) print (s) I prints the first 1024 bytes of the input stream. But when I write s=1 while s: s=sys.stdin.buffer.read(1024) print (s) the server stops responding. I think there is a problem that Python cannot understand end of input stream. I searched this on the net but could not find a solution. Thanks From invalid at invalid.invalid Thu Feb 25 11:39:11 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 25 Feb 2010 16:39:11 +0000 (UTC) Subject: What's the word on using """ to comment-out? References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: On 2010-02-25, Michael Rudolf wrote: > Am 25.02.2010 16:07, schrieb Grant Edwards: >> On 2010-02-25, Paul Rudin wrote: >>> No idea, but it would be nice to have some multiline comment syntax >>> (other than # at the beginning of each line). Particularly one that can >>> be nested. >> >> if 0: >> >> Seriously, that's what I generally do: mark the block of code, >> indent it 1 level, add an if 0: at the top. > > I really hate it when I see something like this in other's > code. The only time you'll see that in my code is if you're watching over my shoulder as I troublshoot something. > The fact that my IDE (vim) still displays this like valid code > ready to be executed can cause extreme frustration while > trying to spot a bug. Nobody in their right mind _leaves_ "commented out" code like that (or other commenting mechanisms) in a program after they're done with whatever little experiment they were performing. I know people who will re-write a block of code and leave the old code there, but comment it out, along with the date and their name, and other such nonsense. I hate that. Keeping track of what _used_ to be there and who changed what when is the job of the version control system. Trying to keep the edit-history of a file in-line as comments just makes the code hard to read and maintain. > This is almost as bad as "commenting out" (parts of) a for > loop by adding a continue. IMO, any sort of "commented out" code left in a program is a big mistake. If the code is soething that does need to stay for optional use, then it needs to be properly integrated along with logic to control when it's used. -- Grant Edwards grante Yow! Four thousand at different MAGNATES, MOGULS visi.com & NABOBS are romping in my gothic solarium!! From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 11:41:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 16:41:01 GMT Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> Message-ID: <4b86a81d$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: > I have a regular expression that searches for some numbers and puts them > into a dictionary, i.e. > > '(?P\d+)\s+(?P\d+\.\d+)' > > Is it possible to have the results of the matches returned as int or > float objects instead of strings? No. Just convert the match with int() or float() before storing it in the dictionary. That is, instead of: d[key] = match use d[key] = float(match) or similar. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 11:45:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 16:45:58 GMT Subject: Renaming identifiers & debugging References: <7unj59FuorU1@mid.individual.net> Message-ID: <4b86a946$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 16:26:32 +0100, Luca wrote: > Hello, i am trying to develop an application to teach programming to > young kids in a similar way as Logo did in the past. I would like to use > an embedded Python as underlying language but this raises a problem. > > The target of my app are very young kids that might be unfamiliar with > english, so i am wondering if there is a way to rename/redefine > identifiers and messages in the language of the kid. >>> len("hello") 5 >>> length = len >>> length("hello") 5 However, you can't rename statements such as for, while, if and similar, nor can you rename error messages. There might be an internationalised version of Python in the language the children speak. Have you tried googling? > Also, i would need a way to debug the program, so set up breakpoints, > execute line by line, inspect variables, is there any API for this in > embedded python? Have you tried the Python debugger? import pdb -- Steven From lars at gustaebel.de Thu Feb 25 11:51:17 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Thu, 25 Feb 2010 17:51:17 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: References: <20100224101423.GA27668@axis.g33x.de> Message-ID: <20100225165117.GA30865@axis.g33x.de> On Wed, Feb 24, 2010 at 04:29:18PM -0500, Terry Reedy wrote: > On 2/24/2010 5:14 AM, Lars Gust?bel wrote: >> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: >>> I stumbled uppon this and find it somewhat odd: some class methods of >>> TarFile and TarInfo do not appears in either the online documentation or >>> search while they have a doc string: >> >> But to answer your question: Yes, this is intentional. The TarFile class has >> three classmethods taropen(), gzopen(), and bz2open() each for a specific >> compression method. These three are used internally by the TarFile.open() >> classmethod and are not intended to be called directly. The TarFile.open() >> method is the one that is publicly documented and supposed to be used. It >> decides which of the three methods to use based on the mode argument and >> does many more other high-level things as well. > > By current standards, the three private methods should be prefixed with > '_' to indicate their private status. Could they be changed to head off > such questions? I hope that this is not necessary. There are quite a few TarFile methods more that are not documented and don't start with an underscore. I don't think renaming all these is a good idea. The original intention behind these methods was that I wanted a lower level API for TarFile that can be used for subclassing but stays as stable as possible at the same time. Methods starting with underscores look very much like you can't make use of them. I don't know if this was a particularly good idea back then and I don't know how popular it is to subclass the TarFile class to customize it, but we cannot simply change the methods' names at this point if we don't want to break other people's code. In other words, the cure sounds worse than the disease in my opinion. -- Lars Gust?bel lars at gustaebel.de 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 jlconlin at gmail.com Thu Feb 25 12:00:07 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 25 Feb 2010 09:00:07 -0800 (PST) Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> <4b86a81d$0$27844$c3e8da3@news.astraweb.com> Message-ID: On Feb 25, 9:41?am, Steven D'Aprano wrote: > On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: > > I have a regular expression that searches for some numbers and puts them > > into a dictionary, i.e. > > > '(?P\d+)\s+(?P\d+\.\d+)' > > > Is it possible to have the results of the matches returned as int or > > float objects instead of strings? > > No. Just convert the match with int() or float() before storing it in the > dictionary. That is, instead of: > > d[key] = match > > use > > d[key] = float(match) > > or similar. I was afraid that was the only option. Oh well, thought I'd ask anyway. Thanks for your help. Jeremy From no-spam at non-existing.invalid Thu Feb 25 12:08:28 2010 From: no-spam at non-existing.invalid (Robert) Date: Thu, 25 Feb 2010 18:08:28 +0100 Subject: Pedantic pickling error after reload? Message-ID: After (intended/controlled) reload or similar action on a module/class the pickle/cPickle.dump raises errors like pickle.PicklingError: Can't pickle : it's not the same object as somemodule.SomeClass Cause in pickle.py (and cPickle) is a line "if klass is not obj:" Shouldn't it be enough to have "if klass.__name__ != obj.__name__:" there? => a bug report/feature request? Classes can change face anyway during pickled state, why should a over-pedantic reaction break things here during runtime? (So far I'd need to walk the object tree in all facets and save against inf loops like pickle himself and re-class things .. ) From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 12:15:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 17:15:50 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <4b86b045$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 15:05:56 +0100, mk wrote: > On 2010-02-25 02:07, Steven D'Aprano wrote: >> On Wed, 24 Feb 2010 18:23:17 +0100, mk wrote: >> >>> Anyway, the passwords for authorized users will be copied and pasted >>> from email into in the application GUI which will remember it for >>> them, so they will not have to remember and type them in. >> >> So to break your application's security model, all somebody has to do >> is use their PC and they have full access to their account? >> >> Or get hold of the copy and paste buffer? >> >> Or the application's config files? > > Yes. There's no way around this, short of forcing them to use hardware > key, which is an overkill for this application. Of course there is. Why don't you find out how applications with real security work, instead of making up amateur insecure schemes or worrying about insignificant deviations from uniformity in your password generator? You can't get hold of a user's login password in Linux or Windows by grabbing the copy-and-paste buffer, or by looking in the password file. No hardware key required. Today, you say that your application only needs weak security because the value of the accounts are low. (If they're that low, why do you need a password at all?) But tomorrow, your application will be bigger, better, new and improved, with remote logins over the Internet and much more value -- and it will still be using the same crappy weak security that it has now, I guarantee it. If you are storing the password, instead of a hash, you fail. If you are storing a hash without a salt, you fail. Yes, an awful lot of software do these things. They shouldn't, even for supposed "low value passwords". http://blog.moertel.com/articles/2006/12/15/never-store-passwords-in-a-database http://www.codinghorror.com/blog/2007/09/youre-probably-storing-passwords-incorrectly.html >> Or your users might be sensible enough to not trust a role-your-own >> security model, and prefer to memorize the password than to trust that >> nobody will get access to their PC. > > The app is not that critical, it's about quarterly subscription to the > service, and the users will be able to reset the password anyway. And when users realise that they don't need to buy a subscription, they just need to steal a password from somebody else, what does that do to your business model? -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 12:18:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 17:18:09 GMT Subject: The best way to check if two lists have identical values References: Message-ID: <4b86b0d1$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 14:30:12 +0100, mk wrote: > In above example I assumed that the same values have to be repeated the > same numbers of times in both lists and that order doesn't matter so > long as the values are the same. sorted(list1) == sorted(list2) > I was wondering if there's a better / shorter / faster way to do this -- > not necessarily in the same variant, e.g. variant where order of two > lists matters would be interesting as well. list1 == list2 -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 12:20:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 17:20:44 GMT Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> <4b86a81d$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b86b16b$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 09:00:07 -0800, Jeremy wrote: > On Feb 25, 9:41?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: >> > I have a regular expression that searches for some numbers and puts >> > them into a dictionary, i.e. >> >> > '(?P\d+)\s+(?P\d+\.\d+)' >> >> > Is it possible to have the results of the matches returned as int or >> > float objects instead of strings? >> >> No. Just convert the match with int() or float() before storing it in >> the dictionary. That is, instead of: >> >> d[key] = match >> >> use >> >> d[key] = float(match) >> >> or similar. > > I was afraid that was the only option. Oh well, thought I'd ask anyway. Why "afraid"? What's the problem with calling int or float on the match? -- Steven From lucat at despammed.com Thu Feb 25 12:42:43 2010 From: lucat at despammed.com (Luca) Date: Thu, 25 Feb 2010 18:42:43 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <4b86a946$0$27844$c3e8da3@news.astraweb.com> References: <7unj59FuorU1@mid.individual.net> <4b86a946$0$27844$c3e8da3@news.astraweb.com> Message-ID: <7unr4kFe8jU1@mid.individual.net> Steven D'Aprano wrote: > However, you can't rename statements such as for, while, if and similar, > nor can you rename error messages. There might be an internationalised > version of Python in the language the children speak. Have you tried > googling? Yeah, this is what i am talking about. It seems that keywords (if, while, for, etc) cannot be renamed at all. Not easily at least without recompiling Python from source. Same thing with error messages. What i need is not an internationalized version of python in a specific language... but a simple way to let the teacher do it by himself/herself. Since python will be embedded in my application i could also load this via a text-file or XML file... but it seems that no API has been made available to solve this problem. Logo is the only language i know that lets the user do this in a very simple way, that's why i brought it as example of what i need. In Logo every identifier can be changed with a simple startup file and every error message can be personalized by editing a text file. This allows any user/parent/teacher to personalize the language for their kids. What i need is an API that lets my application do something similar to the python library. Unfortunately it seems that there is no easy way to do it. > Have you tried the Python debugger? > > import pdb Didn't know it, thank you. Now i need to understand if this PDB module can be used from the application that is embedding pythong (so that i can build a simple IDE to set breakpoints, show the current execution-line, skip it, etc. Thanx, Luca From jjposner at optimum.net Thu Feb 25 12:57:14 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 25 Feb 2010 12:57:14 -0500 Subject: A more pythonish code In-Reply-To: References: Message-ID: <4B86B9FA.7010609@optimum.net> On 2/25/2010 7:23 AM, prasad_chand wrote: > Hi, > > I use python to do simple math problems as a hobby. > > I have made a program that finds the number of divisors(factors) of a > given number. I am hoping to improve my language skills, specifically > I would like to re-write the function "prime_factors" more gracefully. > While the program works right, I am hoping that I could get some input > on how to write better python code. I have attached the code below. > > > def prime_factors(n): > """ > Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) > (1+1) = 10) > > Updates a global dictionary(my_dict) with prime numbers and number > of occurances. In the case of 48 {2:4,3:1} > > """ > tmp_n = n A name meaning "temporary value of n" doesn't suggest how it's being used in the algorithm. In my implementation (see below), I used the name "last_result", which is (a little bit) better. > > while True: > > if tmp_n == 1: > break > > tmp_check = tmp_n > > for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > if tmp_n % x == 0: > add_to_dict(x) This function changes the value of a global variable, *my_dict*. Using global variables is frowned upon. In this case, it would be much better to have the dictionary be local to the *prime_factor* function. After you've broken out of the *while* loop, just execute "return my_dict". > tmp_n /= x > break > > if tmp_check == tmp_n: #number is prime...so just to add to > dict > add_to_dict(tmp_n) > break The only reason that the *tmp_check* variable exists is to test whether you fell out of the *for* loop without finding any divisors for *tmp_n*. A cleaner approach is to use the optional *else* clause of the *for* loop, which is executed only if you didn't *break* out of the loop: for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): if tmp_n % x == 0: add_to_dict(x) tmp_n /= x break else: # tmp_n is prime...so just to add to dict add_to_dict(tmp_n) break > > > def add_one(x): > return x+1 > > > def mul(x,y): > return x * y > > def add_to_dict(p_num): > if my_dict.has_key(p_num): > my_dict[p_num] += 1 > else: > my_dict[p_num] = 1 > As poster pruebauno pointed out, using a collections.defaultdict eliminates the need for the *add_to_dict* function. > > my_dict = {} > > > prime_factors(135) > l = map(add_one,my_dict.values()) > print reduce(mul, l, 1) This may seem trivial, but ... don't use the single-character lowercase "l" as a variable. It looks too much like the digit "1" -- in some fonts, it looks identical! FWIW, here's my implementation. It's much slower, because it doesn't use the square root optimization. It uses another optimization: when a prime factor is located, *all* of its occurrences are factored out at the same time. #-------------------------------- from collections import defaultdict def prime_factors(n): """Return the prime factors of the given number (>= 2)""" if n < 2: print "arg must be >= 2" return last_result = n factors = defaultdict(int) next_divisor = 2 while True: while last_result % next_divisor == 0: factors[next_divisor] += 1 last_result /= next_divisor if last_result == 1: return factors next_divisor += 1 #-------------------------------- HTH, John From martin.hellwig at dcuktec.org Thu Feb 25 13:22:40 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Feb 2010 18:22:40 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <4B86BFF0.60004@dcuktec.org> On 02/25/10 16:18, D'Arcy J.M. Cain wrote: Very interesting, I had a similar kind of problem (a network balancer that doesn't balance small tcp packages too well) and solved it by wrapping the TCP package in UDP. UDP was treated differently, although in overall switch and router manager it has a lower priority compared to other tcp packages, in normal usage it was faster. Probably because UDP has less things to inspect and by this can be processed faster by all the network equipment in between, but to be honest it worked for me and the client wasn't interested in academic explanations and since this was a working solution I didn't investigated it any further. Oh and a big thank you for PyGreSQL,! It has proven to be an extremely useful module for me (especially since I used to hop a lot between different unixes and Windows). -- mph From tjreedy at udel.edu Thu Feb 25 13:27:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Feb 2010 13:27:11 -0500 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: On 2/25/2010 9:21 AM, Richard Thomas wrote: > On Feb 25, 2:03 pm, fat bold cyclop wrote: >>> Both are not equal, so the comparison returns an arbitrary result in Py2. >> >> Thanks, Stefan. If I understand you correctly the comparison is not >> valid. >> But I wonder if there is any logic behind this (in 2.x). >> Is it possible to predict result of this comparison? In general, no. The result is arbitrary, with the constraint of being consistent within a particular run. >> Thanks again, >> fbc > > I believe in 2.x they are ordered by the names of their types but I > could be wrong. This is currently true in *CPython* 2.x, but that is an implementation artifact that has changed and might be different with other implementations. Terry Jan Reedy From tjreedy at udel.edu Thu Feb 25 13:31:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Feb 2010 13:31:47 -0500 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: <20100225165117.GA30865@axis.g33x.de> References: <20100224101423.GA27668@axis.g33x.de> <20100225165117.GA30865@axis.g33x.de> Message-ID: On 2/25/2010 11:51 AM, Lars Gust?bel wrote: > On Wed, Feb 24, 2010 at 04:29:18PM -0500, Terry Reedy wrote: >> On 2/24/2010 5:14 AM, Lars Gust?bel wrote: >>> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: >>>> I stumbled uppon this and find it somewhat odd: some class methods of >>>> TarFile and TarInfo do not appears in either the online documentation or >>>> search while they have a doc string: >>> >>> But to answer your question: Yes, this is intentional. The TarFile class has >>> three classmethods taropen(), gzopen(), and bz2open() each for a specific >>> compression method. These three are used internally by the TarFile.open() >>> classmethod and are not intended to be called directly. The TarFile.open() >>> method is the one that is publicly documented and supposed to be used. It >>> decides which of the three methods to use based on the mode argument and >>> does many more other high-level things as well. >> >> By current standards, the three private methods should be prefixed with >> '_' to indicate their private status. Could they be changed to head off >> such questions? > > I hope that this is not necessary. There are quite a few TarFile methods > more that are not documented and don't start with an underscore. I don't think > renaming all these is a good idea. > > The original intention behind these methods was that I wanted a lower level API for > TarFile that can be used for subclassing but stays as stable as possible at the > same time. If you intended for the *names* (if not the base methods themselves) to be part of the public interface, then no underscores is appropriate. It is a tough in-between case. I guess good docs, including doc stings, is the best you can do to make the situation clear. tjr From clp2 at rebertia.com Thu Feb 25 13:38:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Feb 2010 10:38:57 -0800 Subject: Renaming identifiers & debugging In-Reply-To: <7unj59FuorU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> Message-ID: <50697b2c1002251038v1a6b0864q87ee7e354766cfee@mail.gmail.com> On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: > Hello, i am trying to develop an application to teach programming to young > kids in a similar way as Logo did in the past. I would like to use an > embedded Python as underlying language but this raises a problem. > > The target of my app are very young kids that might be unfamiliar with > english, so i am wondering if there is a way to rename/redefine identifiers > and messages in the language of the kid. > > In UCB-Logo this is very easy with the command > ?COPYDEF "newidentifier "oldidentifier > so all you have to do is setup a startup script to redefine all the > identifiers to the language of the user. > > Is there anything similar for python? Since python would be embedded it > would not be a problem for me to do it through some API. It can certainly be done (c.f. ChinesePython - http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), but I know of no framework that simplifies the task. Essentially, you just have to manually modify Python's parser by swapping out the english for the other language (and if you want to mess with the basic types' names, their name definitions somewhere else too). There also might be encoding issues to deal with. Cheers, Chris -- http://blog.rebertia.com From gereon.kaiping at yahoo.de Thu Feb 25 13:42:13 2010 From: gereon.kaiping at yahoo.de (Gereon Kaiping) Date: Thu, 25 Feb 2010 19:42:13 +0100 Subject: Artificial Neural Networks recommendation wanted In-Reply-To: References: Message-ID: <4B86C485.80608@yahoo.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, >> - - PyNN (just a builder, requires external simulator) ?http://neuralensemble.org/trac/PyNN/ >> - - Con-x (part of pyro) ?http://pyrorobotics.org/?page=Conx >> - - PyNeurGen (includes genetic algorithms) ?http://pyneurgen.sourceforge.net/ >> - - ffnet (only fast forward) ?http://ffnet.sourceforge.net/ >> - - brian (spiking networks) ?http://www.briansimulator.org/ >> - - PyBrain (machine learning) ?http://pybrain.org/ Thanks for the answers: > Fann has python bindings. I saw it, but forgot to include it in my listing. > PyNN and Brian are intended more for biologically-realistic neural > networks (for some value of realistic), aka neuronal networks, so I > guess you can rule them out (similar tools that you might come across > are NEST, NEURON, PCSIM). Yes, I thought so. (I might keep them in mind anyway, if I get to a more biologically approach someday, just like ffnet, which doesn't support recurrent networks but might be good in what it does.) Fann seems to be inable to simulate recurrent networks, too. (There are some older discussions, but I found no trace of a successful implementation.) So my main interest would be Con-x, PyNeurGen and PyBrain. Can you tell me anything about these modules or point me to where to find more information? Greetings, Gereon -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkuGxIUACgkQFWJnZLsO/Wv63gCfRy0WTocj+9u0W/g4RI+UbmXl 1aEAnjkVvVeC4GcuuI2TN1BgCp1sYd2U =BdbD -----END PGP SIGNATURE----- From mensanator at aol.com Thu Feb 25 13:59:39 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 25 Feb 2010 10:59:39 -0800 (PST) Subject: Walking lists References: Message-ID: <369d77c3-99c5-418f-8736-cae6e371088f@t23g2000yqt.googlegroups.com> On Feb 25, 7:02?am, Tim Chase wrote: > Python 3 introduced a variable tuple assignment which I > suspect[*] would work in this context: > > ? ?for first, *rest in L: # note the asterisk > ? ? ?print first > ? ? ?for x in rest: > ? ? ? ?do_stuff(x) > > [*] not having py3 on this machine, I can't readily verify this. Seems fine under 3.1. Cool. >>> L = ((1,2,3), (4,), (5,), (6,7) ) >>> for first, *rest in L: print('first',first,end=' ') print('rest',rest) first 1 rest [2, 3] first 4 rest [] first 5 rest [] first 6 rest [7] From brixomatic at yahoo.com Thu Feb 25 14:08:43 2010 From: brixomatic at yahoo.com (Wanja Gayk) Date: Thu, 25 Feb 2010 20:08:43 +0100 Subject: When will Java go mainstream like Python? References: Message-ID: Am 25.02.2010, 02:05 Uhr, schrieb Lawrence D'Oliveiro : > In message , Wanja Gayk wrote: > >> Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. It means I can write things > like > > contents = open(filename, "r").read() > > and know the file object will be immediately closed after its contents > are returned. Which has nothing to do with reference counting in general. This is what JVMs can do aswell. Just have a look at the behaviour of Weak- and SoftReferences to get an idea what goes on behind the scenes. For example: int x = new Point(10,20).getX(); The point object will be collectable as soon as getX() returned - even better: todays JIT compilers will inline the call and not even allocate the object, if it's allocation is free of side effects. What you write above is something entirely different: it's just a mechanism to release file handles, syntactic sugar for what you have in java when you close a stream in a finally-block. If you like to know a litle more about reference counting, feel free to study the following paper on a very sophistcated reference counting GC for the JVM by Levanoni and Petrank: http://reference.kfupm.edu.sa/content/e/o/e___an_on_the_fly_reference_counting_gar_61636.pdf The paper talks about some ofthe problems that occur with reference counting. Their algorithm uses some nice techniques to avoid thread contention (the reference-counter updates must be atomic, thus require that all "mutators" are stopped) and other problems connected to "referece counting" in general, such as slow writes (-> cache coherence, etc. read-only access is faster). What the paper doesn't tell is how they deal with fragmented heap, so I wouldn't trust that this Refcount-GC will have a stable performance over a long period of time (we're talking apps like Ebay, which run 24/7 for months if not years). Their algorithm may have a "comparable" speed to the (meanwhile) old implementation the JVM's GC, but it still needs the original JVM clean up what it leaves behind(it forgets some references) - maybe that's also how they deal with a fragmeted heap, as java uses a compacting collector. So, yes, it can be fast, or let's say responsive, but in general it's not. And when it is up to speed you get stability issues at least I have not heard anything different yet. To have some numbers: Benchmark Original RC Total 2582.2 2676.0 compress 720.8 723.3 db 374.0 383.7 jack 264.6 299.7 javac 225.0 235.2 jess 181.7 209.7 mpegaudio 607.1 610.6 As you see: SUN's GC is faster. Even though: what those folks have done is impressive (but buggy). > It also means I don?t have to predefine how much memory my program will > use. Which again has nothing to do with GC. This has been a design decision. In fact todays JVM dynamically allocate memory and gro their heaps. A quick look at the command line options will make that clear: java -X [...] -Xms set initial Java heap size -Xmx set maximum Java heap size Todays GC run as folows, they initialize the heap size at what you giove them in your Xmx-Setting (or use the default). When the heap is filled up to that initial size, they do a full GC and if that won't free enough memory, they will allocate some more. This is done until the upper limit from -Xmx is hit, when the program requires more than that, it will fail with an OutOfMemoryError. As you can imagine those limits may influence the GC, but they are no requirement for a GC. Those limits exists for the security of the host system (which may not be a system that allows setting own itself, like Unix/Linux). > A garbage collector will only kick in when the app runs low on memory. Wrong. Please inform yourself. Current generational GCs have minor and major collections. The JLS only requires that before the program runs out of memory the garbage has to be collected, which does not mean it cannot do that earlier. In fact you may also request a full GC by calling "System.gc()" when you know there's time for it. But it's not recommended in general. With JDK 7 we will get a new "Garbage First" Collector, which works differently than the ones we have today. It will promise lower response times and a more predictable behaviour with about the same speed. Starting with Java6 update 14 you may try that one (if you like, I can give ou the command line switch to activate it). Basically it is also a copying collector and in some way it's also generational, but it's "promotion" strategy is different. Anyway, it also won't only clean up when memory is low, but when it detects that there is a segment which is hardly live. > On a > system with dynamic memory allocation, that will not happen until the > entire > system runs low on memory, unless you limit the app to some fixed amount. > Which is an antiquated way of doing things. Which is wrong, see above. Today eve the C++ folks start using Garbage Collectors, because allocating/deallocating space using free-lists has proven to be slower than copying live objects. > And then there?s caching. Modern CPUs owe most of their speed to > assumptions that programs will obey locality of reference. Well, and what's the point? Stack allocation is just not necessary in a copy-colllector, bevause such a collector knows no deallocation (it just saves the survovors), so there is no gain from stack allocation. Stack allocation is faster in traditional C++ programs (without GCs), because the free-lists have to be managed. Todays HotSpot-Compilers take memory-locality into account aswell, just read some papers about it, have a look at "escape analysis" for example. Some further reading: http://www.ibm.com/developerworks/java/library/j-jtp09275.html http://www.ibm.com/developerworks/java/library/j-jtp04223.html > Pointer-chasing is a cache- hostile activity. Garbage collection > involves a lot of pointer-chasing, > particularly of dead objects that have long since been flushed from the > cache, compared with reference counting of recently-accessed objects. > Therefore garbage collection loses performance. You haven't read my previous posts, have you? Dead objects are not considered by today's Garbage collectors. Those trace only "reachable" objects and copy those. They won't even look at "dead" objects. Since most objects die young, this is where you gain a lot of performance. http://www.ibm.com/developerworks/library/j-jtp01274.html Reference counters, on the other hand, must detect when the reference count falls to zero. So they must look at each object, no matter if they are about to die, just to find out if they will die. Regards -Wanja- -- Erstellt mit Operas revolution?rem E-Mail-Modul: http://www.opera.com/mail/ --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From roy at panix.com Thu Feb 25 14:21:51 2010 From: roy at panix.com (Roy Smith) Date: Thu, 25 Feb 2010 14:21:51 -0500 Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: In article , "D'Arcy J.M. Cain" wrote: > The problem had to do with the way TCP/IP works, especially closer to > the core. Our provider was collecting data and sending it only after > filling a buffer or after a timeout. The timeout was short so it > wouldn't normally be noticed and in most cases (web pages e.g.) the > connection is opened, data is pushed and the connection is closed so > the buffer is flushed immediately. Our patterns were different so we > were hitting the timeout on every single transaction and there was no > way we would have been able to keep up. > > Our first crack at fixing this was to simply add garbage to the packet > we were sending. Making the packets an order of magnitude bigger sped > up the proccessing dramatically. That wasn't a very clean solution > though so we looked for a better way. Interesting, the system I'm working with now has a similar problem. We've got a request/ack protocol over TCP which often sends lots of small packets and can have all sorts of performance issues because of this. In fact, we break completely on Solaris-10 with TCP Fusion enabled. We've gone back and forth with Sun on this (they claim what we're doing is broken, we claim TCP Fusion is broken). In the end, we just tell all of our Solaris-10 customers to disable TCP Fusion. From lucat at despammed.com Thu Feb 25 14:27:01 2010 From: lucat at despammed.com (Luca) Date: Thu, 25 Feb 2010 20:27:01 +0100 Subject: Renaming identifiers & debugging In-Reply-To: References: <7unj59FuorU1@mid.individual.net> Message-ID: <7uo186FiejU1@mid.individual.net> Chris Rebert wrote: > On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: >> Hello, i am trying to develop an application to teach programming to young >> kids in a similar way as Logo did in the past. I would like to use an >> embedded Python as underlying language but this raises a problem. >> >> The target of my app are very young kids that might be unfamiliar with >> english, so i am wondering if there is a way to rename/redefine identifiers >> and messages in the language of the kid. >> >> In UCB-Logo this is very easy with the command >> COPYDEF "newidentifier "oldidentifier >> so all you have to do is setup a startup script to redefine all the >> identifiers to the language of the user. >> >> Is there anything similar for python? Since python would be embedded it >> would not be a problem for me to do it through some API. > > It can certainly be done (c.f. ChinesePython - > http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), > but I know of no framework that simplifies the task. Essentially, you > just have to manually modify Python's parser by swapping out the > english for the other language (and if you want to mess with the basic > types' names, their name definitions somewhere else too). There also > might be encoding issues to deal with. > > Cheers, > Chris > -- > http://blog.rebertia.com Yes, i am playing with Python source code, i have changed some keywords but the compile-process fails when it tries to compile some of python libraries which, of course, use english keywords... so i guess this is not a very clean/viable solution (without having to rewrite several parts of the libraries). A better solution could be to "duplicate" keywords adding a translated version but leaving the original version in place so that every module keeps working. In few words, if i was going to translate the keyword "if" in, say, italian "se", then i would have both "if" and also "se" working at the same time, in the same manner. I think that the best way to do this is to insert a "filter" somewhere that converts every "se" keyword into a "if" keyword so that python doesn't even see the change. What i would like to do is add a new keyword (lets call it "copydef" like in UCBLogo or whatever) that does this work at runtime by keeping a substitution table in RAM. If i could manage to add this new keyword to python then it would be easy to write a startup script that translates the keywords once python is "up and running" and without breaking existing python programs/libraries (unless the new keyword conflicts with functions defined inside these programs/libraries). Thanx, Luca From deets at nospam.web.de Thu Feb 25 14:28:26 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 20:28:26 +0100 Subject: Pedantic pickling error after reload? In-Reply-To: References: Message-ID: <7uo1aqFitnU1@mid.uni-berlin.de> Am 25.02.10 18:08, schrieb Robert: > After (intended/controlled) reload or similar action on a module/class > the pickle/cPickle.dump raises errors like > > pickle.PicklingError: Can't pickle : it's > not the same object as somemodule.SomeClass > > > Cause in pickle.py (and cPickle) is a line > "if klass is not obj:" > > Shouldn't it be enough to have "if klass.__name__ != obj.__name__:" there? No. This would alias classes of same name, but living in different modules. So at least you need to compare these, too. I'm not sure if there aren't even more corner-cases. Python's import-mechanism can sometimes be rather foot-shoot-prone. > => a bug report/feature request? > > Classes can change face anyway during pickled state, why should a > over-pedantic reaction break things here during runtime? > (So far I'd need to walk the object tree in all facets and save against > inf loops like pickle himself and re-class things .. ) If anything it's a feature - and I doubt it's really needed. Because reloading pickles with intermittend reload-module-operations is to rare a case to be really supported IMHO. Do yourself a favor, write a unit-test that tests the desired behavior that makes you alter your code & then reload. This makes the problem go away, and you have a more stable development through having more tests :) Diez From helps4indian at gmail.com Thu Feb 25 14:42:57 2010 From: helps4indian at gmail.com (coolboy8) Date: Thu, 25 Feb 2010 11:42:57 -0800 (PST) Subject: Best auto insurance company Message-ID: <9ec65bf7-3b50-4c9a-ba9c-681aa74d922c@t34g2000prm.googlegroups.com> Find the Best auto insurance company here please visit http://autoinsurancerathere.blogspot.com From python at mrabarnett.plus.com Thu Feb 25 14:57:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Feb 2010 19:57:51 +0000 Subject: Renaming identifiers & debugging In-Reply-To: <7uo186FiejU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> Message-ID: <4B86D63F.5090601@mrabarnett.plus.com> Luca wrote: > Chris Rebert wrote: >> On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: >>> Hello, i am trying to develop an application to teach programming to >>> young >>> kids in a similar way as Logo did in the past. I would like to use an >>> embedded Python as underlying language but this raises a problem. >>> >>> The target of my app are very young kids that might be unfamiliar with >>> english, so i am wondering if there is a way to rename/redefine >>> identifiers >>> and messages in the language of the kid. >>> >>> In UCB-Logo this is very easy with the command >>> COPYDEF "newidentifier "oldidentifier >>> so all you have to do is setup a startup script to redefine all the >>> identifiers to the language of the user. >>> >>> Is there anything similar for python? Since python would be embedded it >>> would not be a problem for me to do it through some API. >> >> It can certainly be done (c.f. ChinesePython - >> http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), >> but I know of no framework that simplifies the task. Essentially, you >> just have to manually modify Python's parser by swapping out the >> english for the other language (and if you want to mess with the basic >> types' names, their name definitions somewhere else too). There also >> might be encoding issues to deal with. >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > Yes, i am playing with Python source code, i have changed some keywords > but the compile-process fails when it tries to compile some of python > libraries which, of course, use english keywords... so i guess this is > not a very clean/viable solution (without having to rewrite several > parts of the libraries). A better solution could be to "duplicate" > keywords adding a translated version but leaving the original version in > place so that every module keeps working. In few words, if i was going > to translate the keyword "if" in, say, italian "se", then i would have > both "if" and also "se" working at the same time, in the same manner. > I think that the best way to do this is to insert a "filter" somewhere > that converts every "se" keyword into a "if" keyword so that python > doesn't even see the change. > > What i would like to do is add a new keyword (lets call it "copydef" > like in UCBLogo or whatever) that does this work at runtime by keeping a > substitution table in RAM. If i could manage to add this new keyword to > python then it would be easy to write a startup script that translates > the keywords once python is "up and running" and without breaking > existing python programs/libraries (unless the new keyword conflicts > with functions defined inside these programs/libraries). > Perhaps you could use a different extension, eg ".pyn", so existing ".py" files are handled as-is but ".pyn" files are read through a translator. From deets at nospam.web.de Thu Feb 25 15:06:11 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 21:06:11 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uo186FiejU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> Message-ID: <7uo3hkFvvuU1@mid.uni-berlin.de> Am 25.02.10 20:27, schrieb Luca: > Chris Rebert wrote: >> On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: >>> Hello, i am trying to develop an application to teach programming to >>> young >>> kids in a similar way as Logo did in the past. I would like to use an >>> embedded Python as underlying language but this raises a problem. >>> >>> The target of my app are very young kids that might be unfamiliar with >>> english, so i am wondering if there is a way to rename/redefine >>> identifiers >>> and messages in the language of the kid. >>> >>> In UCB-Logo this is very easy with the command >>> COPYDEF "newidentifier "oldidentifier >>> so all you have to do is setup a startup script to redefine all the >>> identifiers to the language of the user. >>> >>> Is there anything similar for python? Since python would be embedded it >>> would not be a problem for me to do it through some API. >> >> It can certainly be done (c.f. ChinesePython - >> http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), >> but I know of no framework that simplifies the task. Essentially, you >> just have to manually modify Python's parser by swapping out the >> english for the other language (and if you want to mess with the basic >> types' names, their name definitions somewhere else too). There also >> might be encoding issues to deal with. >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > Yes, i am playing with Python source code, i have changed some keywords > but the compile-process fails when it tries to compile some of python > libraries which, of course, use english keywords... so i guess this is > not a very clean/viable solution (without having to rewrite several > parts of the libraries). A better solution could be to "duplicate" > keywords adding a translated version but leaving the original version in > place so that every module keeps working. In few words, if i was going > to translate the keyword "if" in, say, italian "se", then i would have > both "if" and also "se" working at the same time, in the same manner. > I think that the best way to do this is to insert a "filter" somewhere > that converts every "se" keyword into a "if" keyword so that python > doesn't even see the change. > > What i would like to do is add a new keyword (lets call it "copydef" > like in UCBLogo or whatever) that does this work at runtime by keeping a > substitution table in RAM. If i could manage to add this new keyword to > python then it would be easy to write a startup script that translates > the keywords once python is "up and running" and without breaking > existing python programs/libraries (unless the new keyword conflicts > with functions defined inside these programs/libraries). You could use import-hooks for importing your code. There was a python-magazine article a while ago that showed how to use that + a parser to import seamlessly a DSL. Using pyparsing to write a python-grammar on the fly that simply exchanges the keywords before passing it to the interpreter is also easy. But to be honest: I doubt it's worth the effort. Really. Teaching people how to code, but in something that is *not* the "real" language is of little, if any, benefit. And also I don't think that your concerns are valid in general. Keywords are like brandnames or other things - the stand for a concept, and people immediatly accept them when they want them. Much, much, much more important would - if anything - be a standard-library, or a wrapper for that, e.g. for turtle-graphics, that was written in terms of your desired language. Diez From pruebauno at latinmail.com Thu Feb 25 15:09:12 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 25 Feb 2010 12:09:12 -0800 (PST) Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> <4b86a81d$0$27844$c3e8da3@news.astraweb.com> <4b86b16b$0$27844$c3e8da3@news.astraweb.com> Message-ID: On Feb 25, 12:20?pm, Steven D'Aprano wrote: > On Thu, 25 Feb 2010 09:00:07 -0800, Jeremy wrote: > > On Feb 25, 9:41?am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: > >> > I have a regular expression that searches for some numbers and puts > >> > them into a dictionary, i.e. > > >> > '(?P\d+)\s+(?P\d+\.\d+)' > > >> > Is it possible to have the results of the matches returned as int or > >> > float objects instead of strings? > > >> No. Just convert the match with int() or float() before storing it in > >> the dictionary. That is, instead of: > > >> d[key] = match > > >> use > > >> d[key] = float(match) > > >> or similar. > > > I was afraid that was the only option. ?Oh well, thought I'd ask anyway. > > Why "afraid"? What's the problem with calling int or float on the match? > > -- > Steven He must not be Dutch :-) SCNR From aahz at pythoncraft.com Thu Feb 25 15:23:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 12:23:30 -0800 Subject: os.pipe() + os.fork() References: <20100220113604.49b7c242@gurka> <20100220125250.35c9937d@gurka> <256926de-e175-4fa2-aa24-dbd5f96756ef@u20g2000yqu.googlegroups.com> Message-ID: In article <256926de-e175-4fa2-aa24-dbd5f96756ef at u20g2000yqu.googlegroups.com>, sebastian.noack at googlemail.com wrote: >On Feb 20, 8:13=A0pm, Gary Herron wrote: >> >> Here's a thought: =A0Consider the subprocess module. =A0 It can do thefor= >k >> and any necessary pipes and can do so in an OS independent way. =A0 It >> might make you life much easier. > >As far as i know the subprocess module provides only functionality for >running any program as subprocess. But I just want to fork the current >process without putting some code in an external python script. Then try multiprocessing -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Thu Feb 25 15:32:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 12:32:19 -0800 Subject: Pure virtual functions in Python? References: <7udu49Fk3uU1@mid.individual.net> <38ddd614-583c-430d-b998-214bd6360eb2@b2g2000yqi.googlegroups.com> Message-ID: In article <38ddd614-583c-430d-b998-214bd6360eb2 at b2g2000yqi.googlegroups.com>, lallous wrote: >On Feb 22, 12:42=A0am, Gregory Ewing >wrote: >> lallouswrote: >>> >>> If the base defines the method and it was empty, then my C++ code >>> would still call the function. This is not optimal because I don't >>> want to go from C++ to Python if the _derived_ class does not >>> implement the cb. >> >> I would simply not implement the method at all in the base >> class. Then the C++ code can do an attribute lookup for >> the method, and if it's not found, do nothing. > >That is what I currently do. But if I comment out the implementations >(empty ones) then the documentation generation tool will not document >the callbacks. Maybe deleting the method after the class would work. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From johnroth1 at gmail.com Thu Feb 25 15:51:00 2010 From: johnroth1 at gmail.com (John Roth) Date: Thu, 25 Feb 2010 12:51:00 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Feb 24, 1:23?pm, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? > > /W > > -- > INVALID? DE! Is the problem that they've got the docstring in the wrong place, or that the comment isn't saying anything that can't be read in the method name? The first is easily fixable with a bit of tutorial about how a properly placed docstring prints out in various contexts, plus a quick script to move the suckers. The second is going to take more work to get the point across that comments that reproduce what the method name says are waste. John Roth From dontsendleospam at gmail.com Thu Feb 25 17:02:31 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Thu, 25 Feb 2010 14:02:31 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: Hi Arnaud et al, Here is the link to the bug report from which the discussion in PEP 289 was extracted: http://bugs.python.org/issue872326 It looks like they were fixing a bunch of bugs and that this discussion was one of the many in that thread. Here is another post which points to the core of the issue: early/late binding. It is also pointed to in PEP 289. http://mail.python.org/pipermail/python-dev/2004-April/044555.html Here is Guido's rationale (his text is the items (a) and (b) below. My comments follow. (a) I find it hard to defend automatic variable capture given Python's general late-binding semantics MY COMMENTS: That is a good point. There are however exceptions to the "general late-binding semantics" (GLBS) in Python. The outer loop does bind early in this case in fact. A point to consider along with GLBS is the unintuitive early bind of the external iterator vs late bind of the internal iterator. That is a function not of early vs. late binding, but of the current translation of generator expressions to generator functions. Using Arnaud's approach would fix that and make the code IMO so more pythonic. (b) I believe that use cases needing early binding are uncommon and strained: they all involve creating a list of generator expressions, which IMO is a pretty unusual thing to do MY COMMENTS: This is actually a pretty common use case. Any iteration over objects of arity 2 or greater (A matrix, a table, a tree searched breadthwise under some data structures, etc.) can conveniently and cleanly be expressed using a generator expression. I'd also add that perhaps the title of Guido's post: "Generator Expressions - Let's Move Forward" may have unintentionally discouraged people from reexamining the issue. I would like to see this decision revisited. Obviously before spending any time on this I'd like to gauge if there is further interest. Am I off the mark? Maybe there is a technical misunderstanding on my part. If there are more people affected (Since the last week I found some other postings here and on other lists and blogs) who can make a clear case, then what is the next step? Cheers, Leo. From deets at nospam.web.de Thu Feb 25 17:28:32 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 23:28:32 +0100 Subject: compiling python question In-Reply-To: References: <4B859F0C.1060308@nospam.web.de> Message-ID: <7uobshFeqbU1@mid.uni-berlin.de> Am 25.02.10 01:55, schrieb Mag Gam: > sorry for the vague answer. > > Its Linux. > > The configure build does not say anything actually. This is for SAGE. > I managed to have it pick it up by compiling/installing tcl and tk and > then recompile python Then most probably installing the tk-dev packages would have been sufficient. diez From lucat at despammed.com Thu Feb 25 18:08:26 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 00:08:26 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uo3hkFvvuU1@mid.uni-berlin.de> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> Message-ID: <7uoe7bFsdsU1@mid.individual.net> Diez B. Roggisch wrote: > You could use import-hooks for importing your code. There was a > python-magazine article a while ago that showed how to use that + a > parser to import seamlessly a DSL. I will look into this, right now i don't know what import-hooks are nor if i can use them from embedded python. > Using pyparsing to write a python-grammar on the fly that simply > exchanges the keywords before passing it to the interpreter is also easy. This could be an easy solution yes... unfortunately this makes other problems arise... for instance... if i have an IDE that shows the translated language and i want to debug it step by step... would it be easy for me to map the english version (the one that python sees) with the translated version? I still have to look at this and how to run the debugger from the application that is "hosting" python so for now the answer is "i don't know". Right now, by simply changing the file Python-3.1.1/Grammar/Grammar i could obtain this (with "if" translated in "se"): Python 3.1.1 (r311:74480, Feb 25 2010, 22:44:50) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> Vero = True >>> stampa = print >>> >>> se Vero: ... stampa("Ciao") ... Ciao >>> Which seems to work, but requires to manually change the source code and it is way too complex for someone that has zero knowledge about the internals of python (like myself). Besides... it is a very ugly hack IMO. > But to be honest: I doubt it's worth the effort. Really. Teaching people > how to code, but in something that is *not* the "real" language is of > little, if any, benefit. > > And also I don't think that your concerns are valid in general. Keywords > are like brandnames or other things - the stand for a concept, and > people immediatly accept them when they want them. Maybe you are right, but being italian myself i can remember when i was a middle schooler (no computer before that) and the hours spent on my MSX figuring out how the thing worked. I learned all the commands as "brandnames" without really understanding them. I had _no_ idea that "if" meant... if, or that "print" meant to print. I had zero knowledge of english and for this reason most of these commands were meaningless to me, i didn't even suspect they had a meaning in an existing language, i just thought that was the way computers talked. When several years later, in High School, i learned English it was a real surprise for me to find out that the commands i had learned by heart as "magical words" actually had a precise meaning in "human language" and i think this would have helped me to figure out several things that instead took hours or days to understand. Now kids have internet, they study english from the kindergarten, they have a huge quantity of manuals and books freely available, so maybe you are right and i am just over-worrying. But still, i think it would be nice to use a language familiar to the kid (especially very young ones), it would make the learning process faster (no need to learn new words) and it would make the computer feel almost like a virtual "friend". > Much, much, much more important would - if anything - be a > standard-library, or a wrapper for that, e.g. for turtle-graphics, that > was written in terms of your desired language. I already made some tests with turtle-graphics and it seems to work. My next problem was to translate the language. http://img192.imageshack.us/img192/3093/zzz5.png [Btw... i took too much time to write this post so the ladybug fell asleep...] Thanx, Luca From news123 at free.fr Thu Feb 25 18:09:39 2010 From: news123 at free.fr (News123) Date: Fri, 26 Feb 2010 00:09:39 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7unj59FuorU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> Message-ID: <4b870333$0$15434$426a34cc@news.free.fr> Hi Luca, Luca wrote: > Hello, i am trying to develop an application to teach programming to > young kids in a similar way as Logo did in the past. I would like to use > an embedded Python as underlying language but this raises a problem. > > The target of my app are very young kids that might be unfamiliar with > english, so i am wondering if there is a way to rename/redefine > identifiers and messages in the language of the kid. > > In UCB-Logo this is very easy with the command > COPYDEF "newidentifier "oldidentifier > so all you have to do is setup a startup script to redefine all the > identifiers to the language of the user. > > Is there anything similar for python? Since python would be embedded it > would not be a problem for me to do it through some API. > a pragmatic approach might be to preprocess the source code and keep the original version as comments above the translated line. (for debugging) or to preprecess the input line before the 'exec'. It might be, that kids are flexible enough to use English words without understanding them. My younger brother could write Pascal before he learnt any English and he never cared, what 'if' 'then' 'else' 'for', etc. meant. It might be useful though to internationalize the python errror messages if that's not something already done. bye N From lucat at despammed.com Thu Feb 25 18:41:57 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 00:41:57 +0100 Subject: Renaming identifiers & debugging In-Reply-To: References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> Message-ID: <7uog65F5vuU1@mid.individual.net> MRAB wrote: > Perhaps you could use a different extension, eg ".pyn", so existing > ".py" files are handled as-is but ".pyn" files are read through a > translator. This could be a good idea... especially since i could make my own extension since we are talking of a special-purpose application that only incorporates python as a library. Thanx, Luca From deets at nospam.web.de Thu Feb 25 19:05:49 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 01:05:49 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uoe7bFsdsU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> <7uoe7bFsdsU1@mid.individual.net> Message-ID: <7uohitFbm4U1@mid.uni-berlin.de> >> And also I don't think that your concerns are valid in general. >> Keywords are like brandnames or other things - the stand for a >> concept, and people immediatly accept them when they want them. > > Maybe you are right, but being italian myself i can remember when i was > a middle schooler (no computer before that) and the hours spent on my > MSX figuring out how the thing worked. I learned all the commands as > "brandnames" without really understanding them. I had _no_ idea that > "if" meant... if, or that "print" meant to print. I had zero knowledge > of english and for this reason most of these commands were meaningless > to me, i didn't even suspect they had a meaning in an existing language, > i just thought that was the way computers talked. When several years > later, in High School, i learned English it was a real surprise for me > to find out that the commands i had learned by heart as "magical words" > actually had a precise meaning in "human language" and i think this > would have helped me to figure out several things that instead took > hours or days to understand. > Now kids have internet, they study english from the kindergarten, they > have a huge quantity of manuals and books freely available, so maybe you > are right and i am just over-worrying. But still, i think it would be > nice to use a language familiar to the kid (especially very young ones), > it would make the learning process faster (no need to learn new words) > and it would make the computer feel almost like a virtual "friend". I can't argue this from a technical point of view. Nor from a personal, as when I was first exposed to programming, I already new a few bits & pieces of english (leaving highschool with an E grade though....) However, I'm pretty sure what held me back most was the lack of (affordable, tuned to the younger audience) course material, and exchange with peers. Both which has *massively* changed with the internet available even in rather rural aereas of the world. Now under the assumption that you are right here, if keywords are what children keeps from learning programming - then your approach stops much to early. I already mentioned the standard-library, but of course much more important are the builtins. What's an int? Hell, I've been using the term integer for decades now, but actually don't really know if it really stands for "ganzzahl", the german word for what it is. And once they learned the language from whatever course material you prepared for them, they'd take a look outside - and find *nothing*. No code snippet to re-use without error-prone rewriting. Lack of understanding because of unfamiliar words. And so on. All this with a rather high cost on your side to prepare & and maintain a programming environment based upon a patched, potentially buggy interpreter + assorted course material. I really think you should instead focus on creating an environtment similar to what squeak offers, something integrated with easy access to graphics and sounds, that create amazement in the children and makes them want to code to realize their dreams. And of course natively named libraries, plus course-material. I didn't measure it, but by guesstimation, the ratio between keywords & other literals in python should be around the range of 1/10. Finally - well, if I'd were to learn italian, I'd rather not have my teacher translate all the nice italian words to german in my textbook... ;) It *is*, after all, learning a language we are talking here. It is alien. Even python :) Diez From lucat at despammed.com Thu Feb 25 19:06:10 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 01:06:10 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <4b870333$0$15434$426a34cc@news.free.fr> References: <7unj59FuorU1@mid.individual.net> <4b870333$0$15434$426a34cc@news.free.fr> Message-ID: <7uohjjFcvqU1@mid.individual.net> News123 wrote: > a pragmatic approach might be to preprocess the source code > and keep the original version as comments above the translated line. > (for debugging) Not very nice to see though. This change should be transparent to the kid, he/she should not be aware of this "translation". > or to preprecess the input line before the 'exec'. This could be a solution, yes, but then i would also need to figure out a way to show the original line when debugging (still, i know nothing about pdb, maybe it is possible in a easy way). > It might be, that kids are flexible enough to use English words without > understanding them. > > My younger brother could write Pascal before he learnt any English and > he never cared, what 'if' 'then' 'else' 'for', etc. meant. I had a similar experience. When i was a middle schooler i knew nothing about English and so i learned Basic and then Pascal without actually knowing that those words had a meaning at all. For me they were just kind of "magical words" that i could use to tell the computer what to do. So i know for sure that this is possible. But... imagine the use of this language in a elementary school. Some kids, like me or you or your brother would be interested enough to find it easy to learn the new words. For others it would only be a pain. Another lesson among others that to them makes no sense at all. If we could make it easier for them to understand the words used in the language the teacher would have an easier time to explain some concepts and maybe even these kids could have fun and begin to love it. I understand that this "breaks" the language, that it would be better if they would just learn the "original" language... but most teachers would ask "then why not use Logo instead? it is already in our language..." I have nothing against logo of course, i have learned it myself even before Pascal and i had lots of fun with it. But python is much more widespread than logo and i think in some ways it makes "more sense" than logo and it is not much harder. The only problem that i see is that Logo does have its commands translated while python doesn't nor, it seems, there is an easy way to add this functionality. > It might be useful though to internationalize the python errror messages > if that's not something already done. Yes, this would be very important... but still, it should be easy for the teacher to translate the messages to make them more understandable to the kids. For instance... * Python: >>> draw Traceback (most recent call last): File "", line 1, in NameError: name 'draw' is not defined * Logo: ? draw I don't know how to draw Logo's message, while maybe too simple for a professional developer, is certainly much more easy for a kid. So you see, it is not just a matter of internationalization... it is also a matter of users-target. If i am talking to a young kid i should use words and concepts that are easy for him/her to understand... so, for my target, it would be very important not only a correct translation in my language, but also the use of words and concepts that are familiar to a kid. Thanx, Luca From deets at nospam.web.de Thu Feb 25 19:08:50 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 01:08:50 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uoe7bFsdsU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> <7uoe7bFsdsU1@mid.individual.net> Message-ID: <7uohoiFbm4U2@mid.uni-berlin.de> On a related note, did you investigate SUGAR of the OLPC? I'd say these guys certainly tried to create something that appealed to children, and AFAIK it comes with a Python interpreter. I'm don't know anything about that, nor if it comes with learning material. Might be worth checking out. Diez From aahz at pythoncraft.com Thu Feb 25 19:10:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 16:10:57 -0800 Subject: Compiling and running 32-bit Python on 64-bit server? References: Message-ID: In article , Mikko Ohtamaa wrote: > >How one could create 32-bit Python run-time enviroment, preferable >virtualenv, on 64-bit Linux (VPS), reducing memory usage? This >environment could actually beat 64-bit in performance, due to better >memory cache use. > >I assume this involves having lib32 libs and compiling Python with >some magical switches. The simplest approach would probably be to do the compilation on a 32-bit system and just install it on 64-bit. There are some magic flags, yes; you'll need to Google using e.g. "linux force 32-bit compile". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From cg at graysage.com Thu Feb 25 19:11:32 2010 From: cg at graysage.com (Chris Gray) Date: 25 Feb 2010 17:11:32 -0700 Subject: When will Java go mainstream like Python? References: Message-ID: <87mxyw500b.fsf@ami-cg.GraySage.com> Lawrence D'Oliveiro writes: > In message , Wanja Gayk wrote: > > > Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. It means I can write things like I'm by no means an expert, but how does reference counting deal with arbitrary long cycles of references (btw I've *written* a simple reference counter for a programming language)? When I asked someone whose knowlege of Java I trust, he said that modern Java's do both reference counting and garbage collection. That was 2 or 3 years ago. I would have guessed that Python was the same. -- Experience should guide us, not rule us. Chris Gray From deets at nospam.web.de Thu Feb 25 19:12:00 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 01:12:00 +0100 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <7uohugFedhU1@mid.uni-berlin.de> > That better way turned out to asynchronous update transactions. All we > did was keep feeding updates to the remote site and forget about ACKS. > We then had a second process which handled ACKS and tracked which > packets had been properly transferred. The system had IDs on each > update and retries happened if ACKS didn't happen soon enough. > Naturally we ignored ACKS that we had already processed. sounds like using UDP to me, of course with a protocol on top (namely the one you implemented). Any reason you sticked to TCP instead? Diez From rt8396 at gmail.com Thu Feb 25 19:29:13 2010 From: rt8396 at gmail.com (r) Date: Thu, 25 Feb 2010 16:29:13 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: On Feb 25, 7:00?am, fat bold cyclop wrote: > why (1, 2, 3) > [1, 2, 3] is true? It's simple, Everything must have a value! From ethan at stoneleaf.us Thu Feb 25 19:34:35 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 25 Feb 2010 16:34:35 -0800 Subject: Renaming identifiers & debugging In-Reply-To: <7uoe7bFsdsU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> <7uoe7bFsdsU1@mid.individual.net> Message-ID: <4B87171B.7030708@stoneleaf.us> Luca wrote: [snippety] > Maybe you are right, but being italian myself i can remember when i was > a middle schooler (no computer before that) and the hours spent on my > MSX figuring out how the thing worked. I learned all the commands as > "brandnames" without really understanding them. I had _no_ idea that > "if" meant... if, or that "print" meant to print. I had zero knowledge > of english and for this reason most of these commands were meaningless > to me, i didn't even suspect they had a meaning in an existing language, > i just thought that was the way computers talked. [more snippety] Perhaps the lesson to learn from this is that as *you* teach programming to non-english speakers you take the time to say "'if' means 'se', 'print' means 'stampa'", etc. I suspect your early years would have been much easier with those bits of knowledge. :) ~Ethan~ From alfps at start.no Thu Feb 25 19:41:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Feb 2010 01:41:29 +0100 Subject: When will Java go mainstream like Python? In-Reply-To: <87mxyw500b.fsf@ami-cg.GraySage.com> References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: * Chris Gray: > Lawrence D'Oliveiro writes: > >> In message , Wanja Gayk wrote: >> >>> Reference counting is about the worst technique for garbage collection. >> It avoids the need for garbage collection. It means I can write things like > > I'm by no means an expert, but how does reference counting deal with > arbitrary long cycles of references (btw I've *written* a simple > reference counter for a programming language)? Generally it doesn't. Some solutions have however been proposed for std::shared_ptr in C++. None have made it to any noteworthy status, but they demonstrate that there are more or less practical solutions for the most common cases. Currently the upshot is that if you need the kind of self-referential spaghetti structure (no offense) created by mathematical expressions that refer to each other, then you've passed beyond what can be handled practically by reference counting alone or even in combination with cycle handling techniques. For that you're better off with some functional language, or Python... ;-) > When I asked someone whose knowlege of Java I trust, he said that modern > Java's do both reference counting and garbage collection. That was 2 or 3 > years ago. I would have guessed that Python was the same. Yes, Python adds general garbage collection to deal with cycles. Essentially the reference counting deals efficiently and immediately with objects created by expression evaluation, while the general garbage collection deals with cyclic structures. But there's no magic: in particular in Java, Python and like languages you must still remember to remove references installed in singletons and globals (e.g. for event notifications), otherwise objects will still be referenced and thus not garbage collected, causing a memory leak. Cheers & hth., - Alf From robert.kern at gmail.com Thu Feb 25 19:42:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Feb 2010 18:42:35 -0600 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: On 2010-02-25 18:29 PM, r wrote: > On Feb 25, 7:00 am, fat bold cyclop wrote: >> why (1, 2, 3)> [1, 2, 3] is true? > > It's simple, Everything must have a value! That is not at all an explanation, much less a true one. Please read the other posts in this thread; they have explained the situation rather well. -- 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 aahz at pythoncraft.com Thu Feb 25 19:51:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 16:51:01 -0800 Subject: How would I do a continuous write over a pipe in the following code... References: <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com> Message-ID: In article <9d0f6456-97c7-4bde-8e07-9576b02f91f9 at t31g2000prh.googlegroups.com>, chad wrote: > >import subprocess as s > >broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE) > >out = broadcast.stdout >while 1: > out > broadcast.wait() > >broadcast.stdout.close() > > >The code only executes once. What I want to do is be able to >continuously write over the pipe once it is open. I could put >s.Popen() inside the while loop, but that seems a bit too messy. So is >there some way to just open the pipe once, and once it is open, just >continuously write over it vs just opening and closing the pipe every >time? You really should do this instead, untested: broadcast = s.Popen(['wall'], stdin=s.PIPE) while 1: broadcast.write('test\n') time.sleep(1) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 19:58:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 00:58:07 GMT Subject: When will Java go mainstream like Python? References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: <4b871c9e$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 17:11:32 -0700, Chris Gray wrote: > I'm by no means an expert, but how does reference counting deal with > arbitrary long cycles of references (btw I've *written* a simple > reference counter for a programming language)? It doesn't, or at least the CPython one doesn't. In CPython, even a short reference cycle defeats it, which is why CPython also uses a second garbage collector. If we turn that off, we can see how even a one-element cycle defeats reference counting: >>> import gc >>> gc.disable() >>> >>> class K: ... def __del__(self): ... print "Bye now" ... >>> k = K() >>> del k # Test it works as expected. Bye now >>> >>> k = K() # Now try with a cycle. >>> k.attr = k >>> del k >>> >>> Normally, you would clear the ref cycle this way: >>> gc.collect() 2 But in this case it doesn't work because the object in the cycle has a __del__ method, and Python can't predict a safe order to run the __del__ method. (I'm surprised that this is an issue with a single object, but what do I know?) So we have to inspect the list of garbage, manually break the cycle, clear new references we've created, and then it will be garbage collected: >>> gc.garbage[0].attr = None # Break the cycle >>> del gc.garbage[:] Bye now This is one reason why __del__ methods are not recommended. > When I asked someone whose knowlege of Java I trust, he said that modern > Java's do both reference counting and garbage collection. That was 2 or > 3 years ago. I would have guessed that Python was the same. CPython has both now. Jython uses whatever the Java implementation uses, and IronPython uses .Net's memory management scheme. Other Pythons do whatever they like :) Some interesting information here: http://www.digi.com/wiki/developer/index.php/Python_Garbage_Collection -- Steven From mensanator at aol.com Thu Feb 25 20:00:32 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 25 Feb 2010 17:00:32 -0800 (PST) Subject: When will Java go mainstream like Python? References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: On Feb 25, 6:41?pm, "Alf P. Steinbach" wrote: > * Chris Gray: > > > Lawrence D'Oliveiro writes: > > >> In message , Wanja Gayk wrote: > > >>> Reference counting is about the worst technique for garbage collection. > >> It avoids the need for garbage collection. It means I can write things like > > > I'm by no means an expert, but how does reference counting deal with > > arbitrary long cycles of references (btw I've *written* a simple > > reference counter for a programming language)? > > Generally it doesn't. Some solutions have however been proposed for > std::shared_ptr in C++. None have made it to any noteworthy status, but they > demonstrate that there are more or less practical solutions for the most common > cases. > > Currently the upshot is that if you need the kind of self-referential spaghetti > structure (no offense) created by mathematical expressions that refer to each > other, then you've passed beyond what can be handled practically by reference > counting alone or even in combination with cycle handling techniques. > > For that you're better off with some functional language, or Python... ;-) > > > When I asked someone whose knowlege of Java I trust, he said that modern > > Java's do both reference counting and garbage collection. That was 2 or 3 > > years ago. I would have guessed that Python was the same. > > Yes, Python adds general garbage collection to deal with cycles. > > Essentially the reference counting deals efficiently and immediately with > objects created by expression evaluation, while the general garbage collection > deals with cyclic structures. > > But there's no magic: in particular in Java, Python and like languages you must > still remember to remove references installed in singletons and globals (e.g. > for event notifications), otherwise objects will still be referenced and thus > not garbage collected, causing a memory leak. Is that really considered a leak, a single instance of an uncollected global as opposed to a function that is called millions of times, and each time it's called creates uncollected temporary variables? > > Cheers & hth., > > - Alf From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 20:06:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 01:06:18 GMT Subject: When will Java go mainstream like Python? References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: <4b871e8a$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 17:00:32 -0800, Mensanator wrote: > Is that really considered a leak, a single instance of an uncollected > global as opposed to a function that is called millions of times, and > each time it's called creates uncollected temporary variables? I think it's generally called "garbage". When the amount of garbage grows, or *could* grow, it is called a leak. But nobody is going to slap you for calling a single instance of an uncollectable object a leak. -- Steven From g.bogle at auckland.no.spam.ac.nz Thu Feb 25 21:14:06 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Fri, 26 Feb 2010 15:14:06 +1300 Subject: Executable problem - socket? References: Message-ID: MRAB wrote: > You could try Dependency Walker: http://dependencywalker.com/ > I have (belatedly) read the py2exe tutorial: http://www.py2exe.org/index.cgi/Tutorial#Step522 and learned about the msvcr90.dll issue. I haven't finished sorting this out yet, but I did find that running vcredist_x86.exe (the right version!) on box 1 fixed things there. I also tried (naively) manually adding dist\Microsoft.VC90.CRT with the manifest file and msvcr90.dll, but this doesn't seem to work - it seems that p2exe must do the file copying. From darcy at druid.net Thu Feb 25 23:01:26 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 25 Feb 2010 23:01:26 -0500 Subject: taking python enterprise level?... In-Reply-To: <7uohugFedhU1@mid.uni-berlin.de> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> Message-ID: <20100225230126.419f8c53.darcy@druid.net> On Fri, 26 Feb 2010 01:12:00 +0100 "Diez B. Roggisch" wrote: > > That better way turned out to asynchronous update transactions. All we > > did was keep feeding updates to the remote site and forget about ACKS. > > We then had a second process which handled ACKS and tracked which > > packets had been properly transferred. The system had IDs on each > > update and retries happened if ACKS didn't happen soon enough. > > Naturally we ignored ACKS that we had already processed. > > sounds like using UDP to me, of course with a protocol on top (namely > the one you implemented). > > Any reason you sticked to TCP instead? TCP does a great job of delivering a stream of data in order and handling the retries. The app really was connection oriented and we saw no reason to emulate that over an unconnected protocol. There were other wheels to reinvent that were more important. -- 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 darnzen at gmail.com Thu Feb 25 23:54:41 2010 From: darnzen at gmail.com (darnzen) Date: Thu, 25 Feb 2010 20:54:41 -0800 (PST) Subject: staticmethod and namespaces Message-ID: <814d3f0f-9530-44f3-a533-087540bdcd81@d27g2000yqf.googlegroups.com> Having an odd problem that I solved, but wondering if its the best solution (seems like a bit of a hack). First off, I'm using an external DLL that requires static callbacks, but because of this, I'm losing instance info. It will make more sense after I diagram it: #Module main.py class App: def sperg(self): pass app = App() [main loop and such] ----------------------------- # Module A.py import main class Foo: @staticmethod chum(nType, nPtr): # Need to access function / data in app instance app.sperg(nType, nPtr) From darnzen at gmail.com Fri Feb 26 00:07:55 2010 From: darnzen at gmail.com (darnzen) Date: Thu, 25 Feb 2010 21:07:55 -0800 (PST) Subject: staticmethod and namespaces Message-ID: Having an odd problem that I solved, but wondering if its the best solution (seems like a bit of a hack). First off, I'm using an external DLL that requires static callbacks, but because of this, I'm losing instance info. It could be import related? It will make more sense after I diagram it: #Module main.py from A import * class App: def sperg(self): self.a = A() app = App() [main loop and such] ----------------------------- # Module A.py import main class Foo: Selves=[] def __init__(self): Foo.Selves.append(self) @staticmethod def chum_callback(nType, nP): # Need to access function / data in app instance app.sperg(nP) # Need to access func data in Foo # I'm pulling 'self' ouf of list made in constructor self = Foo.getSelf(nP) def getSelf(nP): return self.Selves[nP] --------------------------------------------------------------------- So basically I added a list of instances to the base class so I can get at them from the staticmethod. What's bothering me the most is I can't use the global app instance in the A.py module. How can I get at the app instance (currently I'm storing that along with the class instance in the constructor)? Is there another way to do this that's not such a hack? Sorry for the double / partial post :( From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 02:12:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 07:12:48 GMT Subject: staticmethod and namespaces References: Message-ID: <4b877470$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 21:07:55 -0800, darnzen wrote: > Having an odd problem that I solved, but wondering if its the best > solution (seems like a bit of a hack). > > First off, I'm using an external DLL that requires static callbacks, but > because of this, I'm losing instance info. [...] > How can I get at the app instance (currently I'm storing that along with > the class instance in the constructor)? Is there another way to do this > that's not such a hack? Pass the instance explicitly: >>> class K(object): ... @staticmethod ... def static(self, x, y): ... print self, x, y ... >>> k = K() >>> k.static(k, 1, 2) <__main__.K object at 0xb7c2544c> 1 2 -- Steven From gaoxtwarrior at gmail.com Fri Feb 26 02:17:23 2010 From: gaoxtwarrior at gmail.com (Gao) Date: Fri, 26 Feb 2010 15:17:23 +0800 Subject: Hi, I know it's stupid, but does your foreigner do a lot of OT work? Message-ID: I'm Chinese, I'm working in a famous vendor company which let employee do a lot of OT work, 2 more hours per day, and sometime work in weekend. Is that the same in USA and European? From kalakal.anjali at gmail.com Fri Feb 26 02:30:11 2010 From: kalakal.anjali at gmail.com (HOT GIRLS HOT Night) Date: Thu, 25 Feb 2010 23:30:11 -0800 (PST) Subject: %%% Funny College Girls Nude Video HERE %%% Message-ID: <00f35ca7-f3d6-439e-863c-31e121b528ad@a5g2000prg.googlegroups.com> %%% Funny College Girls Nude Video HERE %%% http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ From arnodel at googlemail.com Fri Feb 26 02:40:54 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 26 Feb 2010 07:40:54 +0000 Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: dontspamleo writes: > Hi Arnaud et al, > > Here is the link to the bug report from which the discussion in PEP > 289 was extracted: > > http://bugs.python.org/issue872326 > > It looks like they were fixing a bunch of bugs and that this > discussion was one of the many in that thread. > > Here is another post which points to the core of the issue: early/late > binding. It is also pointed to in PEP 289. > > http://mail.python.org/pipermail/python-dev/2004-April/044555.html Thanks for digging those out! > Here is Guido's rationale (his text is the items (a) and (b) below. My > comments follow. > > (a) I find it hard to defend automatic variable capture given Python's > general late-binding semantics > > MY COMMENTS: That is a good point. There are however exceptions to the > "general late-binding semantics" (GLBS) in Python. The outer loop does > bind early in this case in fact. A point to consider along with GLBS > is the unintuitive early bind of the external iterator vs late bind of > the internal iterator. That is a function not of early vs. late > binding, but of the current translation of generator expressions to > generator functions. Using Arnaud's approach would fix that and make > the code IMO so more pythonic. But see this message from Guido: http://bugs.python.org/issue872326#msg45190 It looks like he's thinking of early binding of free variables. Later on he seems to contradict this. Below it is mentioned that two patches were made, one with the current behaviour and one with the one you (and I) would prefer. > (b) I believe that use cases needing early binding are uncommon and > strained: they all involve creating a list of generator > expressions, which IMO is a pretty unusual thing to do > > MY COMMENTS: This is actually a pretty common use case. Any iteration > over objects of arity 2 or greater (A matrix, a table, a tree searched > breadthwise under some data structures, etc.) can conveniently and > cleanly be expressed using a generator expression. And also your example when defining a generator expression in a class scope becomes confusing with the current semantics. > I'd also add that perhaps the title of Guido's post: "Generator > Expressions - Let's Move Forward" may have unintentionally discouraged > people from reexamining the issue. > > I would like to see this decision revisited. Obviously before spending > any time on this I'd like to gauge if there is further interest. Am I > off the mark? Maybe there is a technical misunderstanding on my part. > If there are more people affected (Since the last week I found some > other postings here and on other lists and blogs) who can make a clear > case, then what is the next step? I suppose it would be interesting to see how this can be implemented, maybe look at the gexp.diff.capture file on the bug tracker. I was intending to look into it a couple of years ago but I could never find the time :( -- Arnaud From baptiste.lepilleur at gmail.com Fri Feb 26 03:28:04 2010 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Fri, 26 Feb 2010 09:28:04 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: <20100224101423.GA27668@axis.g33x.de> References: <20100224101423.GA27668@axis.g33x.de> Message-ID: 2010/2/24 Lars Gust?bel > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: > > I stumbled uppon this and find it somewhat odd: some class methods of > > TarFile and TarInfo do not appears in either the online documentation or > > search while they have a doc string: > > > > http://docs.python.org/search.html?q=gzopen > > > http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile > > > > See script at the end for list of class methods. > > > > Is this "by design" or is there some an odd bug in doc generation lurking > > around? This somehow seem to be specific to module tarfile. Fraction > > classmethod from_float() is available in the documentation and found by a > > search for example... > > First of all, Python's module documentation is not generated from module > docstrings, each module has its own rst text file in the documentation tree > instead. > I was ignorant of that fact. Thanks for letting me know. > But to answer your question: Yes, this is intentional. The TarFile class > has > three classmethods taropen(), gzopen(), and bz2open() each for a specific > compression method. These three are used internally by the TarFile.open() > classmethod and are not intended to be called directly. The TarFile.open() > method is the one that is publicly documented and supposed to be used. It > decides which of the three methods to use based on the mode argument and > does many more other high-level things as well. > I think it would be best to annotate the help string to let people know of the facts it is not intended for public usage (or restriction that apply, e.g. only for subclassing as you hinted in another post). If I find a method using dir/doc string, I don't check the public documentation to see if it is present. And even if I did, now that I know that documentation is maintained separately from the code base, I would rather assumes a documentation bug than this being by design as is the case here. Notes: googling around, there is already a few uses of TarFile.gzopen(). My guess would be that people find it more convenient for passing compression level. Anyway, thanks for writing this module, it very easy to use! Baptiste. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peloko45 at gmail.com Fri Feb 26 03:55:49 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 00:55:49 -0800 (PST) Subject: Get dosctring without import Message-ID: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> When a package is imported, it gets the dosctring to store it in *__doc__*. Does that funcion is built in python? because I would want use it to get the docstring without import a package From deets at nospam.web.de Fri Feb 26 04:06:17 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 10:06:17 +0100 Subject: Get dosctring without import In-Reply-To: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <7uph89FrdiU1@mid.uni-berlin.de> Am 26.02.10 09:55, schrieb Joan Miller: > When a package is imported, it gets the dosctring to store it in > *__doc__*. > > Does that funcion is built in python? because I would want use it to > get the docstring without import a package You'd need to write your own parser for that. All standard tools simply import, see another thread a few days ago where a user had problems with help on modules. Also, without importing, you'd not get docstrings of C-extension-objects. Diez From deets at nospam.web.de Fri Feb 26 04:15:47 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 10:15:47 +0100 Subject: staticmethod and namespaces In-Reply-To: References: Message-ID: <7uphq3FuapU1@mid.uni-berlin.de> Am 26.02.10 06:07, schrieb darnzen: > Having an odd problem that I solved, but wondering if its the best > solution (seems like a bit of a hack). > > First off, I'm using an external DLL that requires static callbacks, > but because of this, I'm losing instance info. It could be import > related? It will make more sense after I diagram it: > > #Module main.py > from A import * > > class App: > def sperg(self): > self.a = A() > > app = App() > [main loop and such] > ----------------------------- > # Module A.py > import main > class Foo: > Selves=[] > def __init__(self): > Foo.Selves.append(self) > @staticmethod > def chum_callback(nType, nP): > # Need to access function / data in app instance > app.sperg(nP) > # Need to access func data in Foo > # I'm pulling 'self' ouf of list made in constructor > self = Foo.getSelf(nP) > > def getSelf(nP): > return self.Selves[nP] > > --------------------------------------------------------------------- > So basically I added a list of instances to the base class so I can > get at them from the staticmethod. > What's bothering me the most is I can't use the global app instance in > the A.py module. > > How can I get at the app instance (currently I'm storing that along > with the class instance in the constructor)? > Is there another way to do this that's not such a hack? > > Sorry for the double / partial post :( Can you show how you pass the staticmethod to the C-function? Is the DLL utilized by ctypes? I don't see any reason you couldn't use a bound method, which would give you your self, instead relying on global state. Diez From deets at nospam.web.de Fri Feb 26 04:19:15 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 10:19:15 +0100 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> Message-ID: <7upi0jFuapU2@mid.uni-berlin.de> Am 26.02.10 05:01, schrieb D'Arcy J.M. Cain: > On Fri, 26 Feb 2010 01:12:00 +0100 > "Diez B. Roggisch" wrote: >>> That better way turned out to asynchronous update transactions. All we >>> did was keep feeding updates to the remote site and forget about ACKS. >>> We then had a second process which handled ACKS and tracked which >>> packets had been properly transferred. The system had IDs on each >>> update and retries happened if ACKS didn't happen soon enough. >>> Naturally we ignored ACKS that we had already processed. >> >> sounds like using UDP to me, of course with a protocol on top (namely >> the one you implemented). >> >> Any reason you sticked to TCP instead? > > TCP does a great job of delivering a stream of data in order and > handling the retries. The app really was connection oriented and we > saw no reason to emulate that over an unconnected protocol. There were > other wheels to reinvent that were more important. So when you talk about ACKs, you don't mean these on the TCP-level (darn, whatever iso-level that is...), but on some higher level? Diez From massimodipierro71 at gmail.com Fri Feb 26 04:32:30 2010 From: massimodipierro71 at gmail.com (mdipierro) Date: Fri, 26 Feb 2010 01:32:30 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> 100,000 hits a day is not a low. I get that some day on my web server without problem and without one request dropped. Most frameworks web2py, Django, Pylons can handle that kind of load since Python is not the bottle neck. You have to follow some tricks: 1) have the web server serve static pages directly and set the pragma cache expire to one month 2) cache all pages that do not have forms for at least few minutes 3) avoid database joins 4) use a server with at least 512KB Ram. 5) if you pages are large, use gzip compression If you develop your app with the web2py framework, you always have the option to deploy on the Google App Engine. If you can live with their constraints you should have no scalability problems. Massimo On Feb 25, 4:26?am, simn_stv wrote: > hello people, i have been reading posts on this group for quite some > time now and many, if not all (actually not all!), seem quite > interesting. > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. > > would python be able to manage giving me a solid 'core' and will i be > able to use python provide any API i would like to implement?... > > im sorry if my subject was not as clear as probably should be!. > i guess this should be the best place to ask this sort of thing, hope > im so right. > > Thanks From michael at stroeder.com Fri Feb 26 04:33:38 2010 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 26 Feb 2010 10:33:38 +0100 Subject: ANN: python-ldap-2.3.11 Message-ID: Find a new release of python-ldap: http://www.python-ldap.org/ python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Ciao, Michael. -- Michael Str?der E-Mail: michael at stroeder.com http://www.stroeder.com ---------------------------------------------------------------- Released 2.3.11 2010-02-26 Changes since 2.3.10: Lib/ * Fixed LDAP URL parsing with four ? but no real extensions * ldap.ldapobject.LDAPObject.rename_s() now also accepts arguments serverctrls and clientctrls * Removed untested and undocumented class ldap.ldapobject.SmartLDAPObject * Removed broken method ldap.ldapobject.LDAPObject.manage_dsa_it() Modules/ * Make use of LDAP_OPT_X_TLS_NEWCTX only if available in OpenLDAP libs used for the build * Fixed #ifdef-statements for OPT_X_TLS_PROTOCOL_MIN Doc/ * Some updates and corrections regarding description of use of LDAPv3 controls * Some more descriptions for constants * Removed comments related to old LaTeX-based documentation system From lars at gustaebel.de Fri Feb 26 04:36:28 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Fri, 26 Feb 2010 10:36:28 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: References: <20100224101423.GA27668@axis.g33x.de> Message-ID: <20100226093627.GA21027@axis.g33x.de> On Fri, Feb 26, 2010 at 09:28:04AM +0100, Baptiste Lepilleur wrote: > 2010/2/24 Lars Gust?bel > > > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: > > > I stumbled uppon this and find it somewhat odd: some class methods of > > > TarFile and TarInfo do not appears in either the online documentation or > > > search while they have a doc string: > > > > > But to answer your question: Yes, this is intentional. The TarFile class > > has three classmethods taropen(), gzopen(), and bz2open() each for a > > specific compression method. These three are used internally by the > > TarFile.open() classmethod and are not intended to be called directly. The > > TarFile.open() method is the one that is publicly documented and supposed > > to be used. It decides which of the three methods to use based on the mode > > argument and does many more other high-level things as well. > > > > I think it would be best to annotate the help string to let people know of > the facts it is not intended for public usage (or restriction that apply, > e.g. only for subclassing as you hinted in another post). Well, then please take the time and open an issue at bugs.python.org, so that this won't get lost. I will then see what I can do. -- Lars Gust?bel lars at gustaebel.de Linux is like a wigwam - no Gates, no Windows, Apache inside. From tropea at centroserviziterritoriali.com Fri Feb 26 05:00:37 2010 From: tropea at centroserviziterritoriali.com (Ippolito Nievo) Date: Fri, 26 Feb 2010 02:00:37 -0800 (PST) Subject: modbus pymodbus Message-ID: <6a551b81-8085-4a32-a868-64bd869eda08@f8g2000yqn.googlegroups.com> Hi all, someone can help me to pymodbus use? I must send some command and read aswer from an inverter. It use ModBus RTU. Thanks a lot From prasad.chand at gmail.com Fri Feb 26 05:01:59 2010 From: prasad.chand at gmail.com (prasad_chand) Date: Fri, 26 Feb 2010 02:01:59 -0800 (PST) Subject: A more pythonish code References: Message-ID: Hi Mr.Posner & nn, Thank your for your time & effort. I never knew that for...ever combination even existed. I would keep these insights in mind in the future. Thanks again, Prasad On Feb 25, 10:57?pm, John Posner wrote: > On 2/25/2010 7:23 AM, prasad_chand wrote: > > > > > Hi, > > > I use python to do simple math problems as a hobby. > > > I have made a program that finds the number of divisors(factors) of a > > given number. I am hoping to improve my language skills, specifically > > I would like to re-write the function "prime_factors" more gracefully. > > While the program works right, I am hoping that I could get some input > > on how to write better python code. I have attached the code below. > > > def prime_factors(n): > > ? ? ?""" > > ? ? ?Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) > > (1+1) = 10) > > > ? ? ?Updates a global dictionary(my_dict) with prime numbers and number > > of occurances. In the case of 48 {2:4,3:1} > > > ? ? ?""" > > ? ? ?tmp_n = n > > A name meaning "temporary value of n" doesn't suggest how it's being > used in the algorithm. In my implementation (see below), I used the name > "last_result", which is (a little bit) better. > > > > > ? ? ?while True: > > > ? ? ? ? ?if tmp_n == 1: > > ? ? ? ? ? ? ?break > > > ? ? ? ? ?tmp_check = tmp_n > > > ? ? ? ? ?for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > > ? ? ? ? ? ? ?if tmp_n % x == 0: > > ? ? ? ? ? ? ? ? ?add_to_dict(x) > > This function changes the value of a global variable, *my_dict*. Using > global variables is frowned upon. In this case, it would be much better > to have the dictionary be local to the *prime_factor* function. After > you've broken out of the *while* loop, just execute "return my_dict". > > > ? ? ? ? ? ? ? ? ?tmp_n /= x > > ? ? ? ? ? ? ? ? ?break > > > ? ? ? ? ?if tmp_check == tmp_n: #number is prime...so just to add to > > dict > > ? ? ? ? ? ? ?add_to_dict(tmp_n) > > ? ? ? ? ? ? ?break > > The only reason that the *tmp_check* variable exists is to test whether > you fell out of the *for* loop without finding any divisors for *tmp_n*. > A cleaner approach is to use the optional *else* clause of the *for* > loop, which is executed only if you didn't *break* out of the loop: > > ? ? ?for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > ? ? ? ? ?if tmp_n % x == 0: > ? ? ? ? ? ? ?add_to_dict(x) > ? ? ? ? ? ? ?tmp_n /= x > ? ? ? ? ? ? ?break > ? ? ?else: > ? ? ? ? ?# tmp_n is prime...so just to add to dict > ? ? ? ? ?add_to_dict(tmp_n) > ? ? ? ? ?break > > > > > def add_one(x): > > ? ? ?return x+1 > > > def mul(x,y): > > ? ? ?return x * y > > > def add_to_dict(p_num): > > ? ? ?if my_dict.has_key(p_num): > > ? ? ? ? ?my_dict[p_num] += 1 > > ? ? ?else: > > ? ? ? ? ?my_dict[p_num] = 1 > > As poster pruebauno pointed out, using a collections.defaultdict > eliminates the need for the *add_to_dict* function. > > > > > my_dict = {} > > > prime_factors(135) > > l = map(add_one,my_dict.values()) > > print reduce(mul, l, 1) > > This may seem trivial, but ... don't use the single-character lowercase > "l" as a variable. It looks too much like the digit "1" -- in some > fonts, it looks identical! > > FWIW, here's my implementation. It's much slower, because it doesn't use > the square root optimization. It uses another optimization: when a prime > factor is located, *all* of its occurrences are factored out at the same > time. > > #-------------------------------- > from collections import defaultdict > > def prime_factors(n): > ? ? ?"""Return the prime factors of the given number (>= 2)""" > ? ? ?if n < 2: > ? ? ? ? ?print "arg must be >= 2" > ? ? ? ? ?return > > ? ? ?last_result = n > ? ? ?factors = defaultdict(int) > ? ? ?next_divisor = 2 > > ? ? ?while True: > ? ? ? ? ?while last_result % next_divisor == 0: > ? ? ? ? ? ? ?factors[next_divisor] += 1 > ? ? ? ? ? ? ?last_result /= next_divisor > ? ? ? ? ? ? ?if last_result == 1: > ? ? ? ? ? ? ? ? ?return factors > ? ? ? ? ?next_divisor += 1 > #-------------------------------- > > HTH, > John From zubin.mithra at gmail.com Fri Feb 26 05:15:53 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Fri, 26 Feb 2010 15:45:53 +0530 Subject: PyAutoRun Message-ID: <8e7c74321002260215lc68d617x12ed543563e6ad21@mail.gmail.com> Hello, I have been using python for quite some time; however this is the first python project i have worked on. The code is hosted at http://github.com/zubin71/PyAutoRun The code needs re-factoring and feature additions; i have put up a TODO list there too. It`d be great if anyone could work on this; i intend to develop this further(with a bit of help) and will request for its addition into debian and ubuntu repositories, in time. Also, any kind of code-review, criticism, is also appreciated. However, it`d be awesome if you could just fork it at github, pull, modify and push. :) Have a nice day! cheers!!! Zubin From jeanmichel at sequans.com Fri Feb 26 05:27:51 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 11:27:51 +0100 Subject: Get dosctring without import In-Reply-To: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <4B87A227.50100@sequans.com> Joan Miller wrote: > When a package is imported, it gets the dosctring to store it in > *__doc__*. > > Does that funcion is built in python? because I would want use it to > get the docstring without import a package > Epydoc, a documentation builder is able to do so with the --parse-only option. You could take a look at the code, even grab their parser to suit your needs. It may be quite difficult though. JM From ben+python at benfinney.id.au Fri Feb 26 05:51:05 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 26 Feb 2010 21:51:05 +1100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <87bpfc46ee.fsf@benfinney.id.au> Joan Miller writes: > When a package is imported, it gets the dosctring to store it in > *__doc__*. Joan, in this message and numerous others you've been following the widespread convention of using asterisks ?*? to surround text you want to emphasise. Normally that's good, but in a programming-language context (or any other where asterisks have a separate established meaning), it's not a good idea. In many cases, asterisks signify ?match any number of arbitrary characters at this position?, which gives a rather different meaning to what you're writing. You might be better off using quotes (like '__doc__' or ?__doc__?), or the reStructuredText syntax for demarcating a special element, backticks (like `__doc__`). Even they need to be used with care, though, because they also have specific established meanings (except the typographical quotes, which is why I use them). I hope that helps. > Does that funcion is built in python? because I would want use it to > get the docstring without import a package Why is it you want to do this? Modules should not have unwanted side effects when imported; if you can't import the module without invoking those unwanted side effects, the module is poorly written. That's not to say that such poorly-written modules don't exist. What is the situation? Perhaps there's a better solution. -- \ ?Earth gets its price for what Earth gives us.? ?James Russell | `\ Lowell | _o__) | Ben Finney From __peter__ at web.de Fri Feb 26 05:57:16 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Feb 2010 11:57:16 +0100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: Joan Miller wrote: > When a package is imported, it gets the dosctring to store it in > *__doc__*. > > Does that funcion is built in python? because I would want use it to > get the docstring without import a package Something to get you started: import ast def walk(root, stack): for node in ast.iter_child_nodes(root): if isinstance(node, (ast.FunctionDef, ast.ClassDef)): yield node stack.append(node) for child in walk(node, stack): yield child del stack[-1] def get_name(node): try: return node.name except AttributeError: return "(%s)" % node.__class__.__name__ def get_path(path): return ".".join(get_name(node) for node in path) def find_docstrings(filename): with open(filename) as f: module = ast.parse(f.read()) print filename.center(len(filename) + 2).center(80, "=") print ast.get_docstring(module) print "=" * 80 print path = [] for node in walk(module, path): s = ast.get_docstring(node) if s is not None: name = get_path(path + [node]) print name.center(len(name) + 2).center(80, "-") print s print if __name__ == "__main__": import sys args = sys.argv[1:] if args: for arg in args: find_docstrings(arg) else: find_docstrings("/usr/lib/python2.6/unittest.py") assert "unittest" not in sys.modules To get an idea of the differences to the import-based approach try analysing the following script: import random if random.choice([True, False]): def f(): "say hello" else: def f(): "kill a kitten" def g(): "whatever" del g Peter From ldo at geek-central.gen.new_zealand Fri Feb 26 05:59:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 26 Feb 2010 23:59:05 +1300 Subject: Executable problem - socket? References: Message-ID: In message , Gib Bogle wrote: > The only clue is that the machines that her program runs on have > Python installed, while the one that fails doesn't. Wouldn?t it be a whole lot simpler to install Python on the bloody machine? From peloko45 at gmail.com Fri Feb 26 06:23:17 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 03:23:17 -0800 (PST) Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> Message-ID: <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> On 26 feb, 10:51, Ben Finney wrote: > Joan Miller writes: > > When a package is imported, it gets the dosctring to store it in > > *__doc__*. > > Joan, in this message and numerous others you've been following the > widespread convention of using asterisks ?*? to surround text you want > to emphasise. > > Normally that's good, but in a programming-language context (or any > other where asterisks have a separate established meaning), it's not a > good idea. In many cases, asterisks signify ?match any number of > arbitrary characters at this position?, which gives a rather different > meaning to what you're writing. > > You might be better off using quotes (like '__doc__' or ?__doc__?), or > the reStructuredText syntax for demarcating a special element, backticks > (like `__doc__`). Even they need to be used with care, though, because > they also have specific established meanings (except the typographical > quotes, which is why I use them). > > I hope that helps. > > > Does that funcion is built in python? because I would want use it to > > get the docstring without import a package > > Why is it you want to do this? Modules should not have unwanted side > effects when imported; if you can't import the module without invoking > those unwanted side effects, the module is poorly written. > > That's not to say that such poorly-written modules don't exist. What is > the situation? Perhaps there's a better solution. I use a function in 'setupy.py' to get automatically the description from the package's docstring, but there is a problem when you import a module that has to be built by cython (because it tries load a module that doesn't exists). From peloko45 at gmail.com Fri Feb 26 06:29:51 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 03:29:51 -0800 (PST) Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <8889b428-7d1d-44fa-838e-27f2671e9263@y17g2000yqd.googlegroups.com> On 26 feb, 10:57, Peter Otten <__pete... at web.de> wrote: > Joan Miller wrote: > > When a package is imported, it gets the dosctring to store it in > > *__doc__*. > > > Does that funcion is built in python? because I would want use it to > > get the docstring without import a package > > Something to get you started: > > import ast > > def walk(root, stack): > ? ? for node in ast.iter_child_nodes(root): > ? ? ? ? if isinstance(node, (ast.FunctionDef, ast.ClassDef)): > ? ? ? ? ? ? yield node > ? ? ? ? stack.append(node) > ? ? ? ? for child in walk(node, stack): > ? ? ? ? ? ? yield child > ? ? ? ? del stack[-1] > > def get_name(node): > ? ? try: > ? ? ? ? return node.name > ? ? except AttributeError: > ? ? ? ? return "(%s)" % node.__class__.__name__ > > def get_path(path): > ? ? return ".".join(get_name(node) for node in path) > > def find_docstrings(filename): > ? ? with open(filename) as f: > ? ? ? ? module = ast.parse(f.read()) > ? ? print filename.center(len(filename) + 2).center(80, "=") > ? ? print ast.get_docstring(module) > ? ? print "=" * 80 > ? ? print > > ? ? path = [] > ? ? for node in walk(module, path): > ? ? ? ? s = ast.get_docstring(node) > ? ? ? ? if s is not None: > ? ? ? ? ? ? name = get_path(path + [node]) > ? ? ? ? ? ? print name.center(len(name) + 2).center(80, "-") > ? ? ? ? ? ? print s > ? ? ? ? ? ? print > > if __name__ == "__main__": > ? ? import sys > ? ? args = sys.argv[1:] > ? ? if args: > ? ? ? ? for arg in args: > ? ? ? ? ? ? find_docstrings(arg) > ? ? else: > ? ? ? ? find_docstrings("/usr/lib/python2.6/unittest.py") > ? ? ? ? assert "unittest" not in sys.modules > > To get an idea of the differences to the import-based approach try analysing > the following script: > > import random > > if random.choice([True, False]): > ? ? def f(): > ? ? ? ? "say hello" > else: > ? ? def f(): > ? ? ? ? "kill a kitten" > > def g(): > ? ? "whatever" > del g > > Peter Thanks! What I need there is: --------- with open(os.path.join(path, package, '__init__.py')) as f: module = ast.parse(f.read()) print ast.get_docstring(module) From sanelson at gmail.com Fri Feb 26 06:40:14 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Fri, 26 Feb 2010 03:40:14 -0800 (PST) Subject: [M2Crypto] Problems uploading to IIS using FTP over SSL Message-ID: <8383975f-8e86-4783-a69e-67f5acb6c058@e1g2000yqh.googlegroups.com> System: # rpm -q python m2crypto python-2.4.3-27.el5 m2crypto-0.16-6.el5.6 # cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga) I have the following method: def ftp_tarball(aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass): date = datetime.today().strftime(date_format) ftp = ftpslib.FTP_TLS() ftp.connect(ftp_server) ftp.auth_tls() ftp.set_pasv(0) ftp.login(ftp_user, ftp_pass) filename = aggregation_dir + 'zultys-logs_' + date + '.tar.gz' short_name = os.path.split(filename)[1] tarball = open(filename, 'rb') ftp.storbinary('STOR ' + short_name, tarball) tarball.close() ftp.quit() This works perfectly with VSFTPD on Linux, with SSL forced for non- anonymous users. I try to connect to a supplier's IIS FTP server, and get: Traceback (most recent call last): File "/usr/local/bin/lumberjack", line 45, in ? lumberjack.ftp_tarball( aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass ) File "/usr/lib64/python2.4/site-packages/lumberjack.py", line 93, in ftp_tarball ftp.storbinary('STOR ' + short_name, tarball) File "/usr/lib64/python2.4/ftplib.py", line 415, in storbinary conn = self.transfercmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 345, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "/usr/lib64/python2.4/site-packages/M2Crypto/ftpslib.py", line 86, in ntransfercmd conn, size = FTP.ntransfercmd(self, cmd, rest) File "/usr/lib64/python2.4/ftplib.py", line 331, in ntransfercmd sock = self.makeport() File "/usr/lib64/python2.4/ftplib.py", line 292, in makeport resp = self.sendport(host, port) File "/usr/lib64/python2.4/ftplib.py", line 256, in sendport return self.voidcmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib64/python2.4/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib64/python2.4/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 501 Server cannot accept argument. A colleague is able to connect using the Filezilla client, configured as servertype: FTPES - FTP over explicit TLS/SSL setting. I've not been able to find any further guidnance on the web. If you've experienced this before, or can see something that I've obviously got wrong, I'd appreciate your help. TIA, S. From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 06:43:20 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 00:43:20 +1300 Subject: PyQt 4.7 installation on Windows Message-ID: I've just installed Python 2.6.4 and PyQt 4.7 on my Windows machine, on which I was using Python 2.5 and PyQt 4.5. Now 'from PyQt4 import QtGui' fails to find the DLL. Some googling shows that others have encountered the same problem, and a workaround is to copy QtGui4.dll (for example) from D:\Python26\Lib\site-packages\PyQt4\bin to D:\Python26\Lib\site-packages\PyQt4 This is obviously not a solution, just a clue. Another clue is that the Python 2.5 installation didn't have the \bin subdirectory, instead all the DLLs were in PyQt4. It looks as if for 2.6 the DLLs have been moved but the search path hasn't been changed. sys.path includes D:\python26\lib\site-packages, and the Windows PATH environment variable includes D:\Python26\Lib\site-packages\PyQt4\bin For some reason I have a sense of deja vu. Can anyone help? From spamfresser at ch3ka.de Fri Feb 26 06:47:33 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Fri, 26 Feb 2010 12:47:33 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: Am 25.02.2010 17:39, schrieb Grant Edwards: > IMO, any sort of "commented out" code left in a program is a > big mistake. If the code is soething that does need to stay > for optional use, then it needs to be properly integrated along > with logic to control when it's used. OK, then we are perfectly fine and of course for personal use everyone can "comment out" code as they wish. I'd just hate to see something like "if False" in production level code. From spamfresser at ch3ka.de Fri Feb 26 06:52:13 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Fri, 26 Feb 2010 12:52:13 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: Am 26.02.2010 12:47, schrieb Michael Rudolf: > I'd just hate to see something like "if False" in production level code. And yeah, I've seen it. And worse. From J.Fine at open.ac.uk Fri Feb 26 07:00:50 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Fri, 26 Feb 2010 12:00:50 +0000 Subject: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens In-Reply-To: References: Message-ID: Wes James wrote: > On Wed, Feb 24, 2010 at 5:03 AM, Jonathan Fine wrote: >> Hi >> >> Does anyone know of a collection of regular expressions that will break a >> TeX/LaTeX document into tokens? Assume that there is no verbatim or other >> category code changes. > > I'm not sure how this does it, but it might help: > > http://plastex.sourceforge.net/plastex/sect0025.html Thanks, Wes. I'm already using PlasTeX It handles changes of category codes, which makes it over the top for what I want to do. In addition it is a fairly large complex application, and sadly it's not at all easy to use just a part of the code base. There's been more discussion of this thread on comp.text.tex (which is where I set the follow-up to). -- Jonathan From no-spam at non-existing.invalid Fri Feb 26 07:04:38 2010 From: no-spam at non-existing.invalid (Robert) Date: Fri, 26 Feb 2010 13:04:38 +0100 Subject: (and about tests) Re: Pedantic pickling error after reload? In-Reply-To: <7uo1aqFitnU1@mid.uni-berlin.de> References: <7uo1aqFitnU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Am 25.02.10 18:08, schrieb Robert: >> After (intended/controlled) reload or similar action on a module/class >> the pickle/cPickle.dump raises errors like >> >> pickle.PicklingError: Can't pickle : it's >> not the same object as somemodule.SomeClass >> >> >> Cause in pickle.py (and cPickle) is a line >> "if klass is not obj:" >> >> Shouldn't it be enough to have "if klass.__name__ != obj.__name__:" >> there? > > No. This would alias classes of same name, but living in different modules. > > So at least you need to compare these, too. I'm not sure if there aren't at that point of comparison the module is already identical ("klass = getattr(mod, name)") > even more corner-cases. Python's import-mechanism can sometimes be > rather foot-shoot-prone. still don't see a real reason against the mere module+name comparison. same issues as during pickle.load. Just the class object is renewed (intentionally) If there are things with nested classes etc, the programmer will have to rethink things on a different level: design errors. a subject for pychecker/pylint - not for breaking pickle .dump ... ? > >> => a bug report/feature request? >> >> Classes can change face anyway during pickled state, why should a >> over-pedantic reaction break things here during runtime? >> (So far I'd need to walk the object tree in all facets and save against >> inf loops like pickle himself and re-class things .. ) > > If anything it's a feature - and I doubt it's really needed. Because > reloading pickles with intermittend reload-module-operations is to rare > a case to be really supported IMHO. well, reloading is the thing which I do most in coding practice :-) For me its a basic thing like cell proliferation in biology. In my projects particularly with GUI or with python based http serving, I typically support good live module reloadabily even actively by some extra little "reload support code" (which fixes up the .__class__ etc of living Windows tree, main objects, servers ... plus a ?xisinstance? in very few locations) - at least I do this for the frequently changing core modules/classes. This way I feel a edit-run cycle >2x faster when the project is getting bigger and bigger, or when developing things out interactively. Code is exchanged frequently while living objects stay for long ... works well in practice. Reentering into the same (complex) app state for evolving those thousands of small thing (where a full parallel test coverage doesn't work out) is a major dev time consuming factor in bigger projects - in C, Java projects and even with other dynamic languages. Dynamic classes are a main reason why I use Python (adopted from Lisp long time ago; is that reload thing here possible with Ruby too?) I typically need just 1 full app reboot on 20..50 edit-run-cycles I guess. And just few unit test runs per release. Even for Cython/pyximport things I added support for this reload edit-run-cycle, because I cannot imagine to dev without this. Just standard pickle issues stood in the way. And this patch (and a failover from cPickle to pickle) did well so far. > > Do yourself a favor, write a unit-test that tests the desired behavior > that makes you alter your code & then reload. This makes the problem go > away, and you have a more stable development through having more tests :) this is a comfortable quasi religious theory raised often and easily here and there - impracticable and very slow on that fine grained code evolution level however. an interesting issue. I do unit tests for getting stability on a much higher level where/when things and functionality are quite wired. Generally after having compared I cannot confirm that "write always tests before development" ideologies pay off in practice. "Reload > pychecker/pylint > tests" works most effectively with Python in my opinion. And for GUI-development the difference is max. (min for math algorithms which are well away from data structures/OO) Another issue regarding tests IMHO is, that one should not waste the "validation power" of unit tests too easily for permanent low level evolution purposes because its a little like bacteria becoming resistent against antibiotics: Code becoming 'fit' against artificial tests, but not against real word. For example in late stage NASA tests of rockets and like, there is a validation rule, that when those tests do not go through green, there is not just a fix of the (one) cause - screwing until it works. the whole thing is at stake. And the whole test scheme has to be rethought too. ideally, whenever such a late test brakes, it requires that a completely new higher test has to be invented (in addition) ... until there is a minimal set of "fresh green lights" which were red only during there own tests, but never red regarding the real test run. A rule that unit tests are used only near a release or a milestone is healthy in that sense I think. (And a quick edit-(real)run-interact cycle is good for speed) Robert From candide at free.invalid Fri Feb 26 07:29:04 2010 From: candide at free.invalid (candide) Date: Fri, 26 Feb 2010 13:29:04 +0100 Subject: Quoting quotes Message-ID: <4b87be91$0$29882$426a74cc@news.free.fr> Suppose you have to put into a Python string the following sentence : The play "All's Well That Ends Well" by Shakespeare It's easy do it : >>> print """The play "All's Well That Ends Well" by Shakespeare""" The play "All's Well That Ends Well" by Shakespeare Now, change the sentence to this one : The play "All's Well That Ends Well" Using triple single quotes works fine >>> print '''The play "All's Well That Ends Well"''' The play "All's Well That Ends Well" But the first method doesn't run correctly : >>> print """The play "All's Well That Ends Well"""" File "", line 1 print """The play "All's Well That Ends Well"""" ^ SyntaxError: EOL while scanning single-quoted string >>> Any comment ? From victor.stinner at haypocalc.com Fri Feb 26 07:29:33 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 13:29:33 +0100 Subject: Challenge: escape from the pysandbox Message-ID: <201002261329.33740.victor.stinner@haypocalc.com> Hi, pysandbox is a new Python sandbox project under development. By default, untrusted code executed in the sandbox cannot modify the environment (write a file, use print or import a module). But you can configure the sandbox to choose exactly which features are allowed or not, eg. import sys module and read the file /etc/issue. I think that the project reached the "testable" stage. I launch a new challenge: try to escape from the sandbox. I'm unable to write strict rules. The goal is to access objects outside the sandbox. Eg. write into a file, import a module which is not in the whitelist, modify an object outside the sandbox, etc. To test the sandbox, you have 3 choices: - interpreter.py: interactive interpreter executed in the sandbox, use: --verbose to display the whole sandbox configuration, --features=help to enable help() function, --features=regex to enable regex, --help to display the help. - execfile.py : execute your script in the sandbox. It has also --features option: use --features=stdout to be able to use the print instruction :-) - use directly the Sandbox class: use methods call(), execute() or createCallback() Don't use "with sandbox: ..." because there is known but with local frame variables. I think that I will later drop this syntax because of this bug. Except of debug_sandbox, I consider that all features are safe and so you can enable all features :-) There is no prize, it's just for fun! But I will add the name of hackers founding the best exploits. pysandbox is not ready for production, it's under heavy development. Anyway I *hope* that you will quickly find bugs! -- Use tests.py to found some examples of how you can escape a sandbox. pysandbox is protected against all methods described in tests.py ;-) See the README file to get more information about how pysandbox is implemented and get a list of other Python sandboxes. pysandbox is currently specific to CPython, and it uses some ugly hacks to patch CPython in memory. In the worst case it will crash the pysandbox Python process, that's all. I tested it under Linux with Python 2.5 and 2.6. The portage to Python3 is not done yet (is someone motivated to write a patch? :-)). -- Victor Stinner http://www.haypocalc.com/ From victor.stinner at haypocalc.com Fri Feb 26 07:35:02 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 13:35:02 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002261329.33740.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> Message-ID: <201002261335.02933.victor.stinner@haypocalc.com> Le vendredi 26 f?vrier 2010 13:29:33, Victor Stinner a ?crit : > pysandbox is a new Python sandbox project ... I just forget to explain how to download it. Website: http://github.com/haypo/pysandbox/ Download the repository using git: git clone git://github.com/haypo/pysandbox.git or git clone http://github.com/haypo/pysandbox.git Or download the .zip or .tar.gz tarball using the "Download source" button on the website. -- Victor Stinner http://www.haypocalc.com/ From ben+python at benfinney.id.au Fri Feb 26 07:35:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 26 Feb 2010 23:35:30 +1100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> Message-ID: <87635k41kd.fsf@benfinney.id.au> Joan Miller writes: > I use a function in 'setupy.py' to get automatically the description > from the package's docstring, but there is a problem when you import a > module that has to be built by cython (because it tries load a module > that doesn't exists). A simple approach (at least, simpler than crawling a parse tree) might be to store the package description in a separate non-executable file. A common convention is to have a ?README? text file, written in reStructuredText for rendering to various output formats as part of the documentation. You could then have the ?setup.py? program read the contents of that file and use it (or a slice of it) for the package description. -- \ ?Sometimes I ? no, I don't.? ?Steven Wright | `\ | _o__) | Ben Finney From ivan.python1 at gmail.com Fri Feb 26 07:37:10 2010 From: ivan.python1 at gmail.com (=?windows-1252?Q?Ivan_=8Aipo=9A?=) Date: Fri, 26 Feb 2010 13:37:10 +0100 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <4B87C076.104@gmail.com> On 26.2.2010. 13:29, candide wrote: > Suppose you have to put into a Python string the following sentence : > > The play "All's Well That Ends Well" by Shakespeare > > It's easy do it : > > >>>> print """The play "All's Well That Ends Well" by Shakespeare""" >>>> > The play "All's Well That Ends Well" by Shakespeare > > Now, change the sentence to this one : > > The play "All's Well That Ends Well" > > Using triple single quotes works fine > > >>>> print '''The play "All's Well That Ends Well"''' >>>> > The play "All's Well That Ends Well" > > > But the first method doesn't run correctly : > > > >>>> print """The play "All's Well That Ends Well"""" >>>> > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string > >>>> > > Any comment ? > > > Well, there's no such thing as """" defined in python. From usenot at geekmail.INVALID Fri Feb 26 07:42:27 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 26 Feb 2010 13:42:27 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <20100226134227.10c94afe@geekmail.INVALID> On Thu, 25 Feb 2010 12:51:00 -0800 (PST) John Roth wrote: > On Feb 24, 1:23?pm, Andreas Waldenburger > wrote: > > a company that works with my company writes a lot of of their code > > in Python (lucky jerks). I've seen their code and it basically > > looks like this: > > > > """Function that does stuff""" > > def doStuff(): > > ? ? while not wise(up): > > ? ? ? ? yield scorn > > [snip] > Is the problem that they've got the docstring in the wrong place, > or that the comment isn't saying anything that can't be read in > the method name? > It's the first. I am superficial like that. I just needed a docstring to illustrate and didn't want to get overly creative. Not that they don't write redundant docstrings. And they use mixedCase function/method names. And they write getters and setters gratuitously. > The first is easily fixable with a bit of tutorial about how > a properly placed docstring prints out in various contexts, plus > a quick script to move the suckers. > Well, I'm not really in a position to tell them that. I'd be kind of the dork of the office in doing so. Thus my kvetching here. :) So basically, there is nothing to discuss, really. I just wanted to remind everyone that there are still morons out there (as in "lacking esprit and mental flexibility"), make everyone feel better about themselves (because surely THEY don't do that!) and then carry on. > The second is going to take more work to get the point across > that comments that reproduce what the method name says are waste. > They seem to need the reassurance, I guess, so why not let them. ;) /W -- INVALID? DE! From victor.stinner at haypocalc.com Fri Feb 26 07:42:46 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 13:42:46 +0100 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <201002261342.47003.victor.stinner@haypocalc.com> Le vendredi 26 f?vrier 2010 13:29:04, candide a ?crit : > But the first method doesn't run correctly : > >>> print """The play "All's Well That Ends Well"""" > > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string Use triple simple single quotes: >>> print '''"All's Well That Ends Well"''' "All's Well That Ends Well" -- Victor Stinner http://www.haypocalc.com/ From peloko45 at gmail.com Fri Feb 26 08:02:53 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 05:02:53 -0800 (PST) Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> <87635k41kd.fsf@benfinney.id.au> Message-ID: <8777b981-6ca8-49b2-93d8-4b37b2f99b79@k17g2000yqb.googlegroups.com> On 26 feb, 12:35, Ben Finney wrote: > Joan Miller writes: > > I use a function in 'setupy.py' to get automatically the description > > from the package's docstring, but there is a problem when you import a > > module that has to be built by cython (because it tries load a module > > that doesn't exists). > > A simple approach (at least, simpler than crawling a parse tree) might > be to store the package description in a separate non-executable file. > > A common convention is to have a ?README? text file, written in > reStructuredText for rendering to various output formats as part of the > documentation. You could then have the ?setup.py? program read the > contents of that file and use it (or a slice of it) for the package > description. I get the 'README.txt' file to get the long description but I use the docstring because each package should include a short desciption about it. From benjamin.kaplan at case.edu Fri Feb 26 08:43:43 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 26 Feb 2010 08:43:43 -0500 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: On Fri, Feb 26, 2010 at 7:29 AM, candide wrote: > Suppose you have to put into a Python string the following sentence : > > The play "All's Well That Ends Well" by Shakespeare > > It's easy do it : > > >>> print """The play "All's Well That Ends Well" by Shakespeare""" > The play "All's Well That Ends Well" by Shakespeare > > Now, change the sentence to this one : > > The play "All's Well That Ends Well" > > Using triple single quotes works fine > > >>> print '''The play "All's Well That Ends Well"''' > The play "All's Well That Ends Well" > > > But the first method doesn't run correctly : > > > >>> print """The play "All's Well That Ends Well"""" > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string > >>> > > > Any comment ? > > > You have 4 quotes at the end of the line instead of 3. So the first 3 close the long quote and then the 4th opens a new quote which doesn't get closed. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Fri Feb 26 08:56:56 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 14:56:56 +0100 Subject: (and about tests) Re: Pedantic pickling error after reload? In-Reply-To: References: <7uo1aqFitnU1@mid.uni-berlin.de> Message-ID: <7uq299FrmfU1@mid.uni-berlin.de> > at that point of comparison the module is already identical ("klass = > getattr(mod, name)") Ah, didn't know that context. >> even more corner-cases. Python's import-mechanism can sometimes be >> rather foot-shoot-prone. > > still don't see a real reason against the mere module+name comparison. > same issues as during pickle.load. Just the class object is renewed > (intentionally) > > If there are things with nested classes etc, the programmer will have to > rethink things on a different level: design errors. a subject for > pychecker/pylint - not for breaking pickle .dump ... ? I don't say it necessarily breaks anything. I simply don't know enough about it. It might just be that back then, identity was deemed enough to check, but you can well argue your case on the python-dev list, providing a patch + tests that ensure there is no regression. > well, reloading is the thing which I do most in coding practice :-) > For me its a basic thing like cell proliferation in biology. I simply never do it. It has subtle issues, one of them you found, others you say you work around by introducing actual frameworks. But you might well forget some corner-cases & suddently chase a chimera you deem a bug, that in fact is just an unwanted side-effect of reloading. And all this extra complexity is only good for the process of actually changing the code. It doesn't help you maintaining code quality. > Reentering into the same (complex) app state for evolving those > thousands of small thing (where a full parallel test coverage doesn't > work out) is a major dev time consuming factor in bigger projects - in > C, Java projects and even with other dynamic languages. > Dynamic classes are a main reason why I use Python (adopted from Lisp > long time ago; is that reload thing here possible with Ruby too?) So what? If this kind of complex, through rather lengthy interactions evolved state is the thing you need to work within, that's reason enough for me to think about how to automate setting this very state up. That's what programming is about - telling a computer to do things it can do, which usually means it does them *much* faster & *much* more reliable than humans do. Frankly, I can't be bothered with clicking through layers of GUIs to finally reach the destination I'm actually interested in. Let the computer do that. And once I teached him how so, I just integrate that into my test-suite. > I typically need just 1 full app reboot on 20..50 edit-run-cycles I > guess. And just few unit test runs per release. Even for > Cython/pyximport things I added support for this reload edit-run-cycle, > because I cannot imagine to dev without this. Let me assure you - it works :) for example yesterday, I create a full CRUD-interface for a web-app (which is the thing I work on mostly these days) without *once* taking a look at the browser. I wrote actions, forms, HTML, and tests along, developed the thing ready, asserted certain constraints and error-cases, and once finished, fired up the browser - and he saw, it worked! Yes, I could have written that code on the fly, hitting F5 every few seconds/minutes to see if things work out (instead of just running the specific tests through nose) - and once I'd be finished, I didn't have anything permanent that ensured the functionality over time. > this is a comfortable quasi religious theory raised often and easily > here and there - impracticable and very slow on that fine grained code > evolution level however. an interesting issue. To me, that's as much as an religious statement often heard by people that aren't (really) into test-driven development. By which I personally don't mean the variant where one writes tests first, and then code. I always develop both in lock-step, sometimes introducing a new feauter first in my test as e.g. new arguments, or new calls, and then implementing them, but as often the other way round. The argument is always a variation of "my problem is to complicated, the code-base to interviened to make it possible to test this". I call this a bluff. You might work with a code-base that makes it harder than needed to write tests for new functionality. But then, most of the time this is a sign of lack of design. Writing with testability in mind makes you think twice about how to proper componentize your application, clearly separate logic from presentation, validates API-design because using the API is immediatly done when writing the tests you need, and so forth. > > I do unit tests for getting stability on a much higher level where/when > things and functionality are quite wired. > Generally after having compared I cannot confirm that "write always > tests before development" ideologies pay off in practice. > "Reload > pychecker/pylint > tests" works most effectively with Python > in my opinion. > And for GUI-development the difference is max. > (min for math algorithms which are well away from data structures/OO) As I said, I mainly do web these days. Which can be considered GUIs as well. Testing the HTTP-interface is obviously easier & possible, and what I described earlier. But we also use selenium to test JS-driven interfaces, as now the complexity of the interface rises, with all the bells & whistles of ajaxiness and whatnot. > Another issue regarding tests IMHO is, that one should not waste the > "validation power" of unit tests too easily for permanent low level > evolution purposes because its a little like bacteria becoming resistent > against antibiotics: Code becoming 'fit' against artificial tests, but > not against real word. That's why I pull in the real world as well. I don't write unit-tests only (in fact, I don't particularily like that term, because of it's narrow-minded-ness), I write tests for whatever condition I envision *or* encounter. If anything that makes my systems fail is reproducable, it becomes a new test - and ensures this thing isn't ever happening again. Granted, though: there are things you can't really test, especially in cases where you interact with different other agents that might behave (to you) erratically. I've done robot developent as well, and of course testing e.g. an acceleration ramp dependend on ground conditions isn't something a simple unit-test can reproduce. but then... I've written some, and made sure the robot was in a controlled environment when executing them :) All in all, this argument is *much* to often used as excuse to simply not go to any possible length to make your system testable as far as it possibly can be. And in my experience, that's further than most people think. And as a consequence, quality & stability as well as design of the application suffer. > A rule that unit tests are used only near a release or a milestone is > healthy in that sense I think. > (And a quick edit-(real)run-interact cycle is good for speed) Nope, not in my opinion. Making tests an afterthought may well lead to them being written carelessly, not capturing corner-cases you encountered while actually developing, and I don't even buy the speed argument, as I already said - most of the times, the computer is faster than you setting up the environment for testing, how complex ever that may be. Testing is no silver bullet. But it's a rather mighte sword.. :) Diez From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 09:04:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 14:04:35 GMT Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <4b87d4f3$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 13:29:04 +0100, candide wrote: > But the first method doesn't run correctly : > > >>>> print """The play "All's Well That Ends Well"""" > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string >>>> >>>> > > Any comment ? Of course not. Quotes can't be nested, so the first time the parser hits three quote marks, you have reached the end of the string. You then open a new string with a single quote mark, and then fail to close it. Hence the EOL while scanning a single-quoted string. There are many solutions. Here are four: >>> print """The play "All's Well That Ends Well\"""" The play "All's Well That Ends Well" >>> print '''The play "All's Well That Ends Well"''' The play "All's Well That Ends Well" >>> print 'The play "All\'s Well That Ends Well"' The play "All's Well That Ends Well" >>> print 'The play "All' "'" 's Well That Ends Well"' The play "All's Well That Ends Well" -- Steven From sanelson at gmail.com Fri Feb 26 09:05:18 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Fri, 26 Feb 2010 14:05:18 +0000 Subject: [M2Crypto] Problems uploading to IIS using FTP over SSL Message-ID: Hello, System: # rpm -q python m2crypto python-2.4.3-27.el5 m2crypto-0.16-6.el5.6 # cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga) I have the following method: def ftp_tarball(aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass): date = datetime.today().strftime(date_format) ftp = ftpslib.FTP_TLS() ftp.connect(ftp_server) ftp.auth_tls() ftp.set_pasv(0) ftp.login(ftp_user, ftp_pass) filename = aggregation_dir + 'zultys-logs_' + date + '.tar.gz' short_name = os.path.split(filename)[1] tarball = open(filename, 'rb') ftp.storbinary('STOR ' + short_name, tarball) tarball.close() ftp.quit() This works perfectly with VSFTPD on Linux, with SSL forced for non- anonymous users. I try to connect to a supplier's IIS FTP server, and get: Traceback (most recent call last): File "/usr/local/bin/lumberjack", line 45, in ? lumberjack.ftp_tarball( aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass ) File "/usr/lib64/python2.4/site-packages/lumberjack.py", line 93, in ftp_tarball ftp.storbinary('STOR ' + short_name, tarball) File "/usr/lib64/python2.4/ftplib.py", line 415, in storbinary conn = self.transfercmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 345, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "/usr/lib64/python2.4/site-packages/M2Crypto/ftpslib.py", line 86, in ntransfercmd conn, size = FTP.ntransfercmd(self, cmd, rest) File "/usr/lib64/python2.4/ftplib.py", line 331, in ntransfercmd sock = self.makeport() File "/usr/lib64/python2.4/ftplib.py", line 292, in makeport resp = self.sendport(host, port) File "/usr/lib64/python2.4/ftplib.py", line 256, in sendport return self.voidcmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib64/python2.4/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib64/python2.4/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 501 Server cannot accept argument. A colleague is able to connect using the Filezilla client, configured as servertype: FTPES - FTP over explicit TLS/SSL setting. I've not been able to find any further guidance on the web. If you've experienced this before, or can see something that I've obviously got wrong, I'd appreciate your help. TIA, S. From edreamleo at gmail.com Fri Feb 26 09:15:26 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Fri, 26 Feb 2010 08:15:26 -0600 Subject: ANN: Leo 4.7.1 released Message-ID: Leo 4.7.1 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7.1 fixes a dangerous bug in Leo 4.7. When converting file-like sentinels to thin-like sentinels in an external file, Leo now issues a warning and sets the corresponding @file node dirty. This ensures that Leo will write the converted external file and .leo file together, making it impossible to lose data. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - Leo creates a 'Recovered Nodes' node to hold data that otherwise might be lost due to clone conflicts. - @auto-rst now works much more reliably reliably. - Leo no longer supports @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From rdv at roalddevries.nl Fri Feb 26 09:22:19 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 26 Feb 2010 15:22:19 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uog65F5vuU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uog65F5vuU1@mid.individual.net> Message-ID: Hi Luca, On Feb 26, 2010, at 12:41 AM, Luca wrote: > MRAB wrote: >> Perhaps you could use a different extension, eg ".pyn", so existing >> ".py" files are handled as-is but ".pyn" files are read through a >> translator. > > This could be a good idea... especially since i could make my own > extension since we are talking of a special-purpose application that > only incorporates python as a library. I would suggest to do choose the same strategy as 'from __future__ import ...' takes, which does similar things and limits them to the module it is used in. I would be curious to hear about your results. Kind regards, Roald From gslindstrom at gmail.com Fri Feb 26 09:23:54 2010 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Fri, 26 Feb 2010 08:23:54 -0600 Subject: PyCon 2011 - Call for Tutorial Volunteers Message-ID: PyCon 2010 is complete and plans for PyCon 2011 in Atlanta have already begun! The main conference will once again be proceeded by two days of tutorials. There was quite a bit of feedback from students and teachers this year that we want to incorporate in next years classes. In order to do this, more people need to get involved; why not you? You do not need to have any experience in organizing a national conference, just the desire to help out. There is plenty to do from tasks that take a couple of hours to others that span months and you will get help with everything. The areas we will be working on are: * Proposals - help with the call for tutorial proposals and selection of classes * Room Assignments - help get the selected tutorials assigned to classrooms and monitor attendance numbers * Notes - work with teachers to get class notes printed and distributed * Program Guide - work with conference organizers to get tutorial information in the conference guide * Feedback - Work to get meaningful feedback from students and teachers (so PyCon 2012 is even better!) * Payments - collect information so our teachers get paid * Runner - On tutorial days at the conference, make yourself available to do whatever needs to be done. It's a lot of work -- and a lot of fun-- to put on tutorials for PyCon each year. You won't get paid, but you will get one of the snappy "staff" tee shirts when you attend PyCon and you get to work with an incredibly dedicated group of volunteers. Interested? Please drop a note at pycon-tutorials at python.org and let us know. Thanks, Greg Lindstrom Tutorial Coordinator, PyCon 2011 (Atlanta) -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Fri Feb 26 09:37:43 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 26 Feb 2010 15:37:43 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002261335.02933.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261335.02933.victor.stinner@haypocalc.com> Message-ID: >> pysandbox is a new Python sandbox project Out of curiosity, the python sandbox behind google app engine is open source? If so, how is it different from your project, if not, anyone knows if it will be in the future? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at bdurham.com Fri Feb 26 09:50:08 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 26 Feb 2010 09:50:08 -0500 Subject: Possible to import from a cStringIO file object vs. file on disk? Message-ID: <1267195808.16415.1362063523@webmail.messagingengine.com> Is it possible to import from a cStringIO file object (containing compiled byte code) vs. a physical file on disk? I'm thinking that this is possible, given Python's ability to import from zip files, but I'm not sure where to look next. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 26 09:50:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 15:50:25 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100226134227.10c94afe@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100226134227.10c94afe@geekmail.INVALID> Message-ID: <4B87DFB1.1080201@sequans.com> Andreas Waldenburger wrote: > On Thu, 25 Feb 2010 12:51:00 -0800 (PST) John Roth > wrote: > > >> On Feb 24, 1:23 pm, Andreas Waldenburger >> wrote: >> >>> a company that works with my company writes a lot of of their code >>> in Python (lucky jerks). I've seen their code and it basically >>> looks like this: >>> >>> """Function that does stuff""" >>> def doStuff(): >>> while not wise(up): >>> yield scorn >>> [snip] >>> >> Is the problem that they've got the docstring in the wrong place, >> or that the comment isn't saying anything that can't be read in >> the method name? >> >> > It's the first. I am superficial like that. I just needed a docstring > to illustrate and didn't want to get overly creative. > > Not that they don't write redundant docstrings. > > And they use mixedCase function/method names. > and ? whatIsTheProblem ? PEP8 is one style guide, not *the* style guide. There is neither technical nor readability issue with mixedCase, classes in PEP 8 using MixedCase. The thing is they had to chose one preference for the methods and they choose lower_case. Fine, but it's still a matter of preference (or arbitrary decision). Since you don't write code for the standard library, you can use any other naming convention. You've may have guessed it, I am using mixedCase method names, and I tell you, you cannot compare this in any way with their dumb usage of doctrings you've shown above. That being said, yoru OP's still soemhow funny, I would have shot them on sight :-) JM From invalid at invalid.invalid Fri Feb 26 10:04:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 26 Feb 2010 15:04:04 +0000 (UTC) Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> <4b87d4f3$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-26, Steven D'Aprano wrote: > On Fri, 26 Feb 2010 13:29:04 +0100, candide wrote: > >> But the first method doesn't run correctly : >> >> >>>>> print """The play "All's Well That Ends Well"""" >> File "", line 1 >> print """The play "All's Well That Ends Well"""" >> ^ >> SyntaxError: EOL while scanning single-quoted string >>>>> >>>>> >> >> Any comment ? > > Of course not. Quotes can't be nested, so the first time the > parser hits three quote marks, you have reached the end of the > string. You then open a new string with a single quote mark, > and then fail to close it. Hence the EOL while scanning a > single-quoted string. IMO, the error message is misleading to many people, since in many/most contexts the term "single-quoted" refers to this: 'here is a single quoted string' And not this: "this is a double-quoted string" -- Grant Edwards grante Yow! And then we could sit at on the hoods of cars at visi.com stop lights! From victor.stinner at haypocalc.com Fri Feb 26 10:04:57 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 16:04:57 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261335.02933.victor.stinner@haypocalc.com> Message-ID: <201002261604.57625.victor.stinner@haypocalc.com> Le vendredi 26 f?vrier 2010 15:37:43, Daniel Fetchinson a ?crit : > >> pysandbox is a new Python sandbox project > > Out of curiosity, the python sandbox behind google app engine is open > source? If so, how is it different from your project, if not, anyone knows > if it will be in the future? I don't know this project. Do you have the URL of the project home page? Is it the "safelite.py" project? -- Victor Stinner http://www.haypocalc.com/ From tundra at tundraware.com Fri Feb 26 10:09:36 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 26 Feb 2010 09:09:36 -0600 Subject: Docstrings considered too complicated In-Reply-To: <20100224212303.242222c6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > while not wise(up): > yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? > > /W > Reminiscent of: mov AX,BX ; Move the contents of BX into AX And, yes, I've actually seen that as well as: ; This is a comment -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From darnzen at gmail.com Fri Feb 26 10:32:48 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:32:48 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> Message-ID: <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> On Feb 26, 3:15?am, "Diez B. Roggisch" wrote: > Am 26.02.10 06:07, schrieb darnzen: > > > > > > > Having an odd problem that I solved, but wondering if its the best > > solution (seems like a bit of a hack). > > > First off, I'm using an external DLL that requires static callbacks, > > but because of this, I'm losing instance info. It could be import > > related? It will make more sense after I diagram it: > > > #Module main.py > > from A import * > > > class App: > > ? ? ?def sperg(self): > > ? ? ? ? ? self.a = A() > > > app = App() > > [main loop and such] > > ? ----------------------------- > > # Module A.py > > import main > > class Foo: > > ? ? ? ?Selves=[] > > ? ? ? def __init__(self): > > ? ? ? ? ? ? ? ? Foo.Selves.append(self) > > ? ? ? @staticmethod > > ? ? ? def chum_callback(nType, nP): > > ? ? ? ? ? ? ? ? # Need to access function / data in app instance > > ? ? ? ? ? ? ? ? app.sperg(nP) > > ? ? ? ? ? ? ? ? # Need to access func data in Foo > > ? ? ? ? ? ? ? ? # I'm pulling 'self' ouf of list made in constructor > > ? ? ? ? ? ? ? ? self = Foo.getSelf(nP) > > > ? ? ? def getSelf(nP): > > ? ? ? ? ? ? ? ? return self.Selves[nP] > > > --------------------------------------------------------------------- > > So basically I added a list of instances to the base class so I can > > get at them from the staticmethod. > > What's bothering me the most is I can't use the global app instance in > > the A.py module. > > > How can I get at the app instance (currently I'm storing that along > > with the class instance in the constructor)? > > Is there another way to do this that's not such a hack? > > > Sorry for the double / partial post :( > > Can you show how you pass the staticmethod to the C-function? Is the DLL > utilized by ctypes? > > I don't see any reason you couldn't use a bound method, which would give > you your self, instead relying on global state. > > Diez __main__.K << *facepalm* should of tried that! Yeah I'm using ctypes. The DLL callback set ups are as follows. The local callback is in the App namespace (in this case, some callbacks are in different modules as noted in OP), but still no access to self: #Function wrapper A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ POINTER(Data_s))(A.Callback) #DLL call to register the local callback function DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) class A: #Local callback function @staticmethod def Callback(hID, SubID, Data): print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' print 'USING KEY GENERATED FROM hID, SubID' pass I'm not sure why they need to be static callbacks, but the DLL doc's say "when using object based languages, such as c++, callback functions must be declared as static functions and not instance methods", and I couldn't get it to work without setting it up that way. I could probably have them all be "classless" functions, but with 100's of these, my namespace would be polluted up the wazoo, and I'd still have the problem that they wouldn't have access to instance methods / properties. From deets at nospam.web.de Fri Feb 26 10:41:27 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 16:41:27 +0100 Subject: staticmethod and namespaces In-Reply-To: <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> Message-ID: <7uq8d7FvifU1@mid.uni-berlin.de> Am 26.02.10 16:32, schrieb darnzen: > On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: >> Am 26.02.10 06:07, schrieb darnzen: >> >> >> >> >> >>> Having an odd problem that I solved, but wondering if its the best >>> solution (seems like a bit of a hack). >> >>> First off, I'm using an external DLL that requires static callbacks, >>> but because of this, I'm losing instance info. It could be import >>> related? It will make more sense after I diagram it: >> >>> #Module main.py >>> from A import * >> >>> class App: >>> def sperg(self): >>> self.a = A() >> >>> app = App() >>> [main loop and such] >>> ----------------------------- >>> # Module A.py >>> import main >>> class Foo: >>> Selves=[] >>> def __init__(self): >>> Foo.Selves.append(self) >>> @staticmethod >>> def chum_callback(nType, nP): >>> # Need to access function / data in app instance >>> app.sperg(nP) >>> # Need to access func data in Foo >>> # I'm pulling 'self' ouf of list made in constructor >>> self = Foo.getSelf(nP) >> >>> def getSelf(nP): >>> return self.Selves[nP] >> >>> --------------------------------------------------------------------- >>> So basically I added a list of instances to the base class so I can >>> get at them from the staticmethod. >>> What's bothering me the most is I can't use the global app instance in >>> the A.py module. >> >>> How can I get at the app instance (currently I'm storing that along >>> with the class instance in the constructor)? >>> Is there another way to do this that's not such a hack? >> >>> Sorry for the double / partial post :( >> >> Can you show how you pass the staticmethod to the C-function? Is the DLL >> utilized by ctypes? >> >> I don't see any reason you couldn't use a bound method, which would give >> you your self, instead relying on global state. >> >> Diez > > __main__.K<< *facepalm* should of tried that! > > Yeah I'm using ctypes. The DLL callback set ups are as follows. The > local callback is in the App namespace (in this case, some callbacks > are in different modules as noted in OP), but still no access to self: > > #Function wrapper > A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ > POINTER(Data_s))(A.Callback) > > #DLL call to register the local callback function > DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > class A: > #Local callback function > @staticmethod > def Callback(hID, SubID, Data): > print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > print 'USING KEY GENERATED FROM hID, SubID' > pass > > I'm not sure why they need to be static callbacks, but the DLL doc's > say "when using object based languages, such as c++, callback > functions must be declared as static functions and not instance > methods", and I couldn't get it to work without setting it up that > way. I could probably have them all be "classless" functions, but with > 100's of these, my namespace would be polluted up the wazoo, and I'd > still have the problem that they wouldn't have access to instance > methods / properties. The above code can't work with self, because you use A.expCallback which at best can of course be a classmethod. You need to instead invoke DLLSetCallback with a bound method, like this a = A() DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of static functions is differently. If ctypes manages to get *some* callback passed, I'm 100% positive that it can pass *any* callable you like, including bound methods. Diez From darnzen at gmail.com Fri Feb 26 10:42:32 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:42:32 -0800 (PST) Subject: staticmethod and namespaces References: <4b877470$0$27844$c3e8da3@news.astraweb.com> Message-ID: On Feb 26, 1:12?am, Steven D'Aprano wrote: > On Thu, 25 Feb 2010 21:07:55 -0800, darnzen wrote: > > Having an odd problem that I solved, but wondering if its the best > > solution (seems like a bit of a hack). > > > First off, I'm using an external DLL that requires static callbacks, but > > because of this, I'm losing instance info. > [...] > > How can I get at the app instance (currently I'm storing that along with > > the class instance in the constructor)? Is there another way to do this > > that's not such a hack? > > Pass the instance explicitly: > > >>> class K(object): > > ... ? ? @staticmethod > ... ? ? def static(self, x, y): > ... ? ? ? ? print self, x, y > ...>>> k = K() > >>> k.static(k, 1, 2) > > <__main__.K object at 0xb7c2544c> 1 2 > > -- > Steven Unfortunately, since the callback is from the DLL which I didn't write, I can not change what is passed to the function. Also, the DLL has no idea about my local namespace. The DLL typically will pass back two integers (which I can set the values of when I register the callback), and some data. Currently Im' using these integers as keys in a local dict where I'm storing the instances. I suppose I could use the integers to store the high and low order bytes of a pointer to the instance, but not sure how to do that in Python (would be easy in c/c++). Also, I'm not sure how python memory management works, if it will move objects around and make things buggy. Also, that is definitely a hack and isn't very 'pythonesque' From darnzen at gmail.com Fri Feb 26 10:47:10 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:47:10 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> Message-ID: On Feb 26, 9:41?am, "Diez B. Roggisch" wrote: > Am 26.02.10 16:32, schrieb darnzen: > > > > > > > On Feb 26, 3:15 am, "Diez B. Roggisch" ?wrote: > >> Am 26.02.10 06:07, schrieb darnzen: > > >>> Having an odd problem that I solved, but wondering if its the best > >>> solution (seems like a bit of a hack). > > >>> First off, I'm using an external DLL that requires static callbacks, > >>> but because of this, I'm losing instance info. It could be import > >>> related? It will make more sense after I diagram it: > > >>> #Module main.py > >>> from A import * > > >>> class App: > >>> ? ? ? def sperg(self): > >>> ? ? ? ? ? ?self.a = A() > > >>> app = App() > >>> [main loop and such] > >>> ? ?----------------------------- > >>> # Module A.py > >>> import main > >>> class Foo: > >>> ? ? ? ? Selves=[] > >>> ? ? ? ?def __init__(self): > >>> ? ? ? ? ? ? ? ? ?Foo.Selves.append(self) > >>> ? ? ? ?@staticmethod > >>> ? ? ? ?def chum_callback(nType, nP): > >>> ? ? ? ? ? ? ? ? ?# Need to access function / data in app instance > >>> ? ? ? ? ? ? ? ? ?app.sperg(nP) > >>> ? ? ? ? ? ? ? ? ?# Need to access func data in Foo > >>> ? ? ? ? ? ? ? ? ?# I'm pulling 'self' ouf of list made in constructor > >>> ? ? ? ? ? ? ? ? ?self = Foo.getSelf(nP) > > >>> ? ? ? ?def getSelf(nP): > >>> ? ? ? ? ? ? ? ? ?return self.Selves[nP] > > >>> --------------------------------------------------------------------- > >>> So basically I added a list of instances to the base class so I can > >>> get at them from the staticmethod. > >>> What's bothering me the most is I can't use the global app instance in > >>> the A.py module. > > >>> How can I get at the app instance (currently I'm storing that along > >>> with the class instance in the constructor)? > >>> Is there another way to do this that's not such a hack? > > >>> Sorry for the double / partial post :( > > >> Can you show how you pass the staticmethod to the C-function? Is the DLL > >> utilized by ctypes? > > >> I don't see any reason you couldn't use a bound method, which would give > >> you your self, instead relying on global state. > > >> Diez > > > __main__.K<< ?*facepalm* should of tried that! > > > Yeah I'm using ctypes. The DLL callback set ups are as follows. The > > local callback is in the App namespace (in this case, some callbacks > > are in different modules as noted in OP), but still no access to self: > > > ? ? ? ? ?#Function wrapper > > ? ? ? ? ?A.expCallback = WINFUNCTYPE(None, c_int, c_int, ?\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?POINTER(Data_s))(A.Callback) > > > ? ? ? ? ?#DLL call to register the local callback function > > ? ? ? ? ?DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > > ? ? ?class A: > > ? ? ? ? ?#Local callback function > > ? ?@staticmethod > > ? ?def Callback(hID, SubID, Data): > > ? ? ? ? ? ? ? print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > > ? ? ? ? ? ? ? print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > > ? ? ? ? ? ? ? print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > > ? ? ? ? ? ? ? print 'USING KEY GENERATED FROM hID, SubID' > > ? ? ? ? ? ? ? pass > > > I'm not sure why they need to be static callbacks, but the DLL doc's > > say "when using object based languages, such as c++, callback > > functions must be declared as static functions and not instance > > methods", and I couldn't get it to work without setting it up that > > way. I could probably have them all be "classless" functions, but with > > 100's of these, my namespace would be polluted up the wazoo, and I'd > > still have the problem that they wouldn't have access to instance > > methods / properties. > > The above code can't work with self, because you use > > ? A.expCallback > > which at best can of course be a classmethod. > > You need to instead invoke DLLSetCallback with a bound method, like this > > ? a = A() > ? DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of > static functions is differently. If ctypes manages to get *some* > callback passed, I'm 100% positive that it can pass *any* callable you > like, including bound methods. > > Diez This was originally how my code was set up, invoking with the bound methods, but it didn't work (crashing and bizzaro errors) and I was pulling my hair out. Then I read the documentation and changed it to static methods and everything started working. Believe me, I totally understand how using bound methods would make this problem go away. From aioe.org at technicalbloke.com Fri Feb 26 10:52:49 2010 From: aioe.org at technicalbloke.com (r0g) Date: Fri, 26 Feb 2010 15:52:49 +0000 Subject: Offline windows registry access on *nix platforms. Message-ID: Hi Everybody, I do a fair bit of programming in Python and I have to say I find perl a little intimidating right now as I don't have a lot of experience with it however its the only language I have found that seemed to have a library for what I need right now: Win32::Registry (or maybe Win32::TieRegistry) I way to read/search for windows registry keys from offline hive files e.g. NTUSER.DAT on *nix platforms, in my case Ubuntu linux - nothing more advanced than that. Given that I only need this functionality, performance is a not issue and I'm very comfortable in Python I thought I might try and write a pair of wrapper functions - one to check the existence of a key, one to return a keys values. Sadly though I have fallen at the first hurdle, I get "OS unsupported" when I type "install Win32::Registry" into CPAN so I guess it's windows only :( Anyone know of an open source module/library that can do what I want? Ideally Python or Perl, but I suppose any free language I can compile or easily bundle/distribute would do. Alternatively if anyone knows of a *nix app that can decode a windows registry into a flat text file? At a push I could compile something that can do this on windows and run it via wine but I'd really like to avoid that if I can. Suggestions & pointers greatly appreciated, Roger. From darnzen at gmail.com Fri Feb 26 10:57:38 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:57:38 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> Message-ID: <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> On Feb 26, 9:41?am, "Diez B. Roggisch" wrote: > Am 26.02.10 16:32, schrieb darnzen: > > > > > > > On Feb 26, 3:15 am, "Diez B. Roggisch" ?wrote: > >> Am 26.02.10 06:07, schrieb darnzen: > > >>> Having an odd problem that I solved, but wondering if its the best > >>> solution (seems like a bit of a hack). > > >>> First off, I'm using an external DLL that requires static callbacks, > >>> but because of this, I'm losing instance info. It could be import > >>> related? It will make more sense after I diagram it: > > >>> #Module main.py > >>> from A import * > > >>> class App: > >>> ? ? ? def sperg(self): > >>> ? ? ? ? ? ?self.a = A() > > >>> app = App() > >>> [main loop and such] > >>> ? ?----------------------------- > >>> # Module A.py > >>> import main > >>> class Foo: > >>> ? ? ? ? Selves=[] > >>> ? ? ? ?def __init__(self): > >>> ? ? ? ? ? ? ? ? ?Foo.Selves.append(self) > >>> ? ? ? ?@staticmethod > >>> ? ? ? ?def chum_callback(nType, nP): > >>> ? ? ? ? ? ? ? ? ?# Need to access function / data in app instance > >>> ? ? ? ? ? ? ? ? ?app.sperg(nP) > >>> ? ? ? ? ? ? ? ? ?# Need to access func data in Foo > >>> ? ? ? ? ? ? ? ? ?# I'm pulling 'self' ouf of list made in constructor > >>> ? ? ? ? ? ? ? ? ?self = Foo.getSelf(nP) > > >>> ? ? ? ?def getSelf(nP): > >>> ? ? ? ? ? ? ? ? ?return self.Selves[nP] > > >>> --------------------------------------------------------------------- > >>> So basically I added a list of instances to the base class so I can > >>> get at them from the staticmethod. > >>> What's bothering me the most is I can't use the global app instance in > >>> the A.py module. > > >>> How can I get at the app instance (currently I'm storing that along > >>> with the class instance in the constructor)? > >>> Is there another way to do this that's not such a hack? > > >>> Sorry for the double / partial post :( > > >> Can you show how you pass the staticmethod to the C-function? Is the DLL > >> utilized by ctypes? > > >> I don't see any reason you couldn't use a bound method, which would give > >> you your self, instead relying on global state. > > >> Diez > > > __main__.K<< ?*facepalm* should of tried that! > > > Yeah I'm using ctypes. The DLL callback set ups are as follows. The > > local callback is in the App namespace (in this case, some callbacks > > are in different modules as noted in OP), but still no access to self: > > > ? ? ? ? ?#Function wrapper > > ? ? ? ? ?A.expCallback = WINFUNCTYPE(None, c_int, c_int, ?\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?POINTER(Data_s))(A.Callback) > > > ? ? ? ? ?#DLL call to register the local callback function > > ? ? ? ? ?DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > > ? ? ?class A: > > ? ? ? ? ?#Local callback function > > ? ?@staticmethod > > ? ?def Callback(hID, SubID, Data): > > ? ? ? ? ? ? ? print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > > ? ? ? ? ? ? ? print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > > ? ? ? ? ? ? ? print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > > ? ? ? ? ? ? ? print 'USING KEY GENERATED FROM hID, SubID' > > ? ? ? ? ? ? ? pass > > > I'm not sure why they need to be static callbacks, but the DLL doc's > > say "when using object based languages, such as c++, callback > > functions must be declared as static functions and not instance > > methods", and I couldn't get it to work without setting it up that > > way. I could probably have them all be "classless" functions, but with > > 100's of these, my namespace would be polluted up the wazoo, and I'd > > still have the problem that they wouldn't have access to instance > > methods / properties. > > The above code can't work with self, because you use > > ? A.expCallback > > which at best can of course be a classmethod. > > You need to instead invoke DLLSetCallback with a bound method, like this > > ? a = A() > ? DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of > static functions is differently. If ctypes manages to get *some* > callback passed, I'm 100% positive that it can pass *any* callable you > like, including bound methods. > > Diez Thinking about it some more, I believe I understand why it has to be staticfunction. To use an bound method would require the wrapper to include a reference to the instance as follows: A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ POINTER(Data_s))(a.Callback) Since a = A(); a.foo() is really A.foo(self). The problem here is that A is not a ctypes object and I can't change what arguments the DLL uses in the callback in any case. Rewording my thoughts: a bound method callback would require 'self' to be the first argument. I can not make the DLL include 'self' as it doesn't know anything about the objects in my program. Since I can't pass 'self', it has to be a staticmethod. From jlconlin at gmail.com Fri Feb 26 10:58:14 2010 From: jlconlin at gmail.com (Jeremy) Date: Fri, 26 Feb 2010 07:58:14 -0800 (PST) Subject: =?windows-1252?Q?Dictionary_or_Database=97Please_advise?= Message-ID: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> I have lots of data that I currently store in dictionaries. However, the memory requirements are becoming a problem. I am considering using a database of some sorts instead, but I have never used them before. Would a database be more memory efficient than a dictionary? I also need platform independence without having to install a database and Python interface on all the platforms I'll be using. Is there something built-in to Python that will allow me to do this? Thanks, Jeremy From willia2501 at gmail.com Fri Feb 26 11:04:55 2010 From: willia2501 at gmail.com (William Lohrmann) Date: Fri, 26 Feb 2010 08:04:55 -0800 (PST) Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: On 26 Feb, 13:29, candide wrote: > Suppose you have to put into a Python string the following sentence : > > The play "All's Well That Ends Well" by Shakespeare > > It's easy do it : > > >>> print """The play "All's Well That Ends Well" by Shakespeare""" > > The play "All's Well That Ends Well" by Shakespeare > > Now, change the sentence to this one : > > The play "All's Well That Ends Well" > > Using triple single quotes works fine > > >>> print '''The play "All's Well That Ends Well"''' > > The play "All's Well That Ends Well" > > But the first method doesn't run correctly : > > >>> print """The play "All's Well That Ends Well"""" > > ? File "", line 1 > ? ? print """The play "All's Well That Ends Well"""" > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ > SyntaxError: EOL while scanning single-quoted string > > > > Any comment ? The best thing would be to backslash the single quote: print 'The play "All\'s Well That Ends Well"' From deets at nospam.web.de Fri Feb 26 11:08:46 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 17:08:46 +0100 Subject: staticmethod and namespaces In-Reply-To: <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> Message-ID: <7uqa0eF95lU1@mid.uni-berlin.de> Am 26.02.10 16:57, schrieb darnzen: > On Feb 26, 9:41 am, "Diez B. Roggisch" wrote: >> Am 26.02.10 16:32, schrieb darnzen: >> >> >> >> >> >>> On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: >>>> Am 26.02.10 06:07, schrieb darnzen: >> >>>>> Having an odd problem that I solved, but wondering if its the best >>>>> solution (seems like a bit of a hack). >> >>>>> First off, I'm using an external DLL that requires static callbacks, >>>>> but because of this, I'm losing instance info. It could be import >>>>> related? It will make more sense after I diagram it: >> >>>>> #Module main.py >>>>> from A import * >> >>>>> class App: >>>>> def sperg(self): >>>>> self.a = A() >> >>>>> app = App() >>>>> [main loop and such] >>>>> ----------------------------- >>>>> # Module A.py >>>>> import main >>>>> class Foo: >>>>> Selves=[] >>>>> def __init__(self): >>>>> Foo.Selves.append(self) >>>>> @staticmethod >>>>> def chum_callback(nType, nP): >>>>> # Need to access function / data in app instance >>>>> app.sperg(nP) >>>>> # Need to access func data in Foo >>>>> # I'm pulling 'self' ouf of list made in constructor >>>>> self = Foo.getSelf(nP) >> >>>>> def getSelf(nP): >>>>> return self.Selves[nP] >> >>>>> --------------------------------------------------------------------- >>>>> So basically I added a list of instances to the base class so I can >>>>> get at them from the staticmethod. >>>>> What's bothering me the most is I can't use the global app instance in >>>>> the A.py module. >> >>>>> How can I get at the app instance (currently I'm storing that along >>>>> with the class instance in the constructor)? >>>>> Is there another way to do this that's not such a hack? >> >>>>> Sorry for the double / partial post :( >> >>>> Can you show how you pass the staticmethod to the C-function? Is the DLL >>>> utilized by ctypes? >> >>>> I don't see any reason you couldn't use a bound method, which would give >>>> you your self, instead relying on global state. >> >>>> Diez >> >>> __main__.K<< *facepalm* should of tried that! >> >>> Yeah I'm using ctypes. The DLL callback set ups are as follows. The >>> local callback is in the App namespace (in this case, some callbacks >>> are in different modules as noted in OP), but still no access to self: >> >>> #Function wrapper >>> A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ >>> POINTER(Data_s))(A.Callback) >> >>> #DLL call to register the local callback function >>> DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) >> >>> class A: >>> #Local callback function >>> @staticmethod >>> def Callback(hID, SubID, Data): >>> print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' >>> print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' >>> print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' >>> print 'USING KEY GENERATED FROM hID, SubID' >>> pass >> >>> I'm not sure why they need to be static callbacks, but the DLL doc's >>> say "when using object based languages, such as c++, callback >>> functions must be declared as static functions and not instance >>> methods", and I couldn't get it to work without setting it up that >>> way. I could probably have them all be "classless" functions, but with >>> 100's of these, my namespace would be polluted up the wazoo, and I'd >>> still have the problem that they wouldn't have access to instance >>> methods / properties. >> >> The above code can't work with self, because you use >> >> A.expCallback >> >> which at best can of course be a classmethod. >> >> You need to instead invoke DLLSetCallback with a bound method, like this >> >> a = A() >> DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) >> >> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of >> static functions is differently. If ctypes manages to get *some* >> callback passed, I'm 100% positive that it can pass *any* callable you >> like, including bound methods. >> >> Diez > > Thinking about it some more, I believe I understand why it has to be > staticfunction. To use an bound method would require the wrapper to > include a reference to the instance as follows: > > A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ > POINTER(Data_s))(a.Callback) > > Since a = A(); a.foo() is really A.foo(self). The problem here is that > A is not a ctypes object and I can't change what arguments the DLL > uses in the callback in any case. Rewording my thoughts: a bound > method callback would require 'self' to be the first argument. I can > not make the DLL include 'self' as it doesn't know anything about the > objects in my program. Since I can't pass 'self', it has to be a > staticmethod. No, that's not true. A bound method implictly knows about it self, and it's a callable. What I guess is that you did the same mistake I did when I created that example - namely, not keeping a refernce to the bound method around. Ctypes will then garbage-collect the callback, which of course leads to all kinds of troubles. Try this: a = A() # keep this around bound_m = a.expCallback DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) Diez From benjamin.kaplan at case.edu Fri Feb 26 11:11:15 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 26 Feb 2010 11:11:15 -0500 Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= In-Reply-To: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Fri, Feb 26, 2010 at 10:58 AM, Jeremy wrote: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy > Python has SQLite 3 built-in and there are wrappers for MySQL and PostgreSQL on all major platforms. Any one of them will work- databases have the advantage that they're stored on the disk so you don't have all of it in memory simultaneously. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Fri Feb 26 11:14:50 2010 From: aioe.org at technicalbloke.com (r0g) Date: Fri, 26 Feb 2010 16:14:50 +0000 Subject: Offline windows registry access on *nix platforms. References: Message-ID: r0g wrote: > Hi Everybody, > > I do a fair bit of programming in Python and I have to say I find perl a > little intimidating right now as I don't have a lot of experience with > it however its the only language I have found that seemed to have a > library for what I need right now: Win32::Registry (or maybe > Win32::TieRegistry) > > I way to read/search for windows registry keys from offline hive files > e.g. NTUSER.DAT on *nix platforms, in my case Ubuntu linux - nothing > more advanced than that. Actually scrap that, just found "Parse::Win32Registry", happy days! :) Roger. From deets at nospam.web.de Fri Feb 26 11:20:35 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 17:20:35 +0100 Subject: staticmethod and namespaces In-Reply-To: <7uqa0eF95lU1@mid.uni-berlin.de> References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> <7uqa0eF95lU1@mid.uni-berlin.de> Message-ID: <7uqamjFd2vU2@mid.uni-berlin.de> Am 26.02.10 17:08, schrieb Diez B. Roggisch: > Am 26.02.10 16:57, schrieb darnzen: >> On Feb 26, 9:41 am, "Diez B. Roggisch" wrote: >>> Am 26.02.10 16:32, schrieb darnzen: >>> >>> >>> >>> >>> >>>> On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: >>>>> Am 26.02.10 06:07, schrieb darnzen: >>> >>>>>> Having an odd problem that I solved, but wondering if its the best >>>>>> solution (seems like a bit of a hack). >>> >>>>>> First off, I'm using an external DLL that requires static callbacks, >>>>>> but because of this, I'm losing instance info. It could be import >>>>>> related? It will make more sense after I diagram it: >>> >>>>>> #Module main.py >>>>>> from A import * >>> >>>>>> class App: >>>>>> def sperg(self): >>>>>> self.a = A() >>> >>>>>> app = App() >>>>>> [main loop and such] >>>>>> ----------------------------- >>>>>> # Module A.py >>>>>> import main >>>>>> class Foo: >>>>>> Selves=[] >>>>>> def __init__(self): >>>>>> Foo.Selves.append(self) >>>>>> @staticmethod >>>>>> def chum_callback(nType, nP): >>>>>> # Need to access function / data in app instance >>>>>> app.sperg(nP) >>>>>> # Need to access func data in Foo >>>>>> # I'm pulling 'self' ouf of list made in constructor >>>>>> self = Foo.getSelf(nP) >>> >>>>>> def getSelf(nP): >>>>>> return self.Selves[nP] >>> >>>>>> --------------------------------------------------------------------- >>>>>> So basically I added a list of instances to the base class so I can >>>>>> get at them from the staticmethod. >>>>>> What's bothering me the most is I can't use the global app >>>>>> instance in >>>>>> the A.py module. >>> >>>>>> How can I get at the app instance (currently I'm storing that along >>>>>> with the class instance in the constructor)? >>>>>> Is there another way to do this that's not such a hack? >>> >>>>>> Sorry for the double / partial post :( >>> >>>>> Can you show how you pass the staticmethod to the C-function? Is >>>>> the DLL >>>>> utilized by ctypes? >>> >>>>> I don't see any reason you couldn't use a bound method, which would >>>>> give >>>>> you your self, instead relying on global state. >>> >>>>> Diez >>> >>>> __main__.K<< *facepalm* should of tried that! >>> >>>> Yeah I'm using ctypes. The DLL callback set ups are as follows. The >>>> local callback is in the App namespace (in this case, some callbacks >>>> are in different modules as noted in OP), but still no access to self: >>> >>>> #Function wrapper >>>> A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ >>>> POINTER(Data_s))(A.Callback) >>> >>>> #DLL call to register the local callback function >>>> DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) >>> >>>> class A: >>>> #Local callback function >>>> @staticmethod >>>> def Callback(hID, SubID, Data): >>>> print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' >>>> print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' >>>> print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' >>>> print 'USING KEY GENERATED FROM hID, SubID' >>>> pass >>> >>>> I'm not sure why they need to be static callbacks, but the DLL doc's >>>> say "when using object based languages, such as c++, callback >>>> functions must be declared as static functions and not instance >>>> methods", and I couldn't get it to work without setting it up that >>>> way. I could probably have them all be "classless" functions, but with >>>> 100's of these, my namespace would be polluted up the wazoo, and I'd >>>> still have the problem that they wouldn't have access to instance >>>> methods / properties. >>> >>> The above code can't work with self, because you use >>> >>> A.expCallback >>> >>> which at best can of course be a classmethod. >>> >>> You need to instead invoke DLLSetCallback with a bound method, like this >>> >>> a = A() >>> DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) >>> >>> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of >>> static functions is differently. If ctypes manages to get *some* >>> callback passed, I'm 100% positive that it can pass *any* callable you >>> like, including bound methods. >>> >>> Diez >> >> Thinking about it some more, I believe I understand why it has to be >> staticfunction. To use an bound method would require the wrapper to >> include a reference to the instance as follows: >> >> A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ >> POINTER(Data_s))(a.Callback) >> >> Since a = A(); a.foo() is really A.foo(self). The problem here is that >> A is not a ctypes object and I can't change what arguments the DLL >> uses in the callback in any case. Rewording my thoughts: a bound >> method callback would require 'self' to be the first argument. I can >> not make the DLL include 'self' as it doesn't know anything about the >> objects in my program. Since I can't pass 'self', it has to be a >> staticmethod. > > No, that's not true. A bound method implictly knows about it self, and > it's a callable. > > What I guess is that you did the same mistake I did when I created that > example - namely, not keeping a refernce to the bound method around. > Ctypes will then garbage-collect the callback, which of course leads to > all kinds of troubles. > > Try this: > > a = A() > # keep this around > bound_m = a.expCallback > DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) AAAAHHRG, same error again. Of course, use DLLSetCallback(self.hID, A.SubID, EVENTID, bound_m) because the bound method changes with each time you create it. Sorry for the confusion. Diez From clp2 at rebertia.com Fri Feb 26 11:29:51 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Feb 2010 08:29:51 -0800 Subject: =?UTF-8?Q?Re=3A_Dictionary_or_Database=E2=80=94Please_advise?= In-Reply-To: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <50697b2c1002260829m3c3da337pe0e8c39dbbe3a1df@mail.gmail.com> On Fri, Feb 26, 2010 at 7:58 AM, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? If you won't be using the SQL features of the database, `shelve` might be another option; from what I can grok, I sounds like a dictionary stored mostly on disk rather than entirely in RAM (not 100% sure though): http://docs.python.org/library/shelve.html It's in the std lib and supports several native dbm libraries for its backend; one of them should almost always be present. Cheers, Chris -- http://blog.rebertia.com From lbolla at gmail.com Fri Feb 26 11:29:54 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 26 Feb 2010 08:29:54 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Feb 26, 3:58?pm, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy Maybe shelve would be enough for your needs? http://docs.python.org/library/shelve.html From usenot at geekmail.INVALID Fri Feb 26 11:34:59 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 26 Feb 2010 17:34:59 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226134227.10c94afe@geekmail.INVALID> Message-ID: <20100226173459.2b376405@geekmail.INVALID> On Fri, 26 Feb 2010 15:50:25 +0100 Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: > > > And they use mixedCase function/method names. > > > and ? whatIsTheProblem ? Thanks for proving my point. ;) No seriously though: Let it go. I wasn't being serious. As long as it works and I don't have to work with it, I don't care how anybody writes their code. /W -- INVALID? DE! From usenot at geekmail.INVALID Fri Feb 26 11:39:07 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 26 Feb 2010 17:39:07 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <20100226173907.5567609f@geekmail.INVALID> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk wrote: > On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: > > [stuff] > > Reminiscent of: > > mov AX,BX ; Move the contents of BX into AX > Well, there might be some confusion there as to what gets moved where, wouldn't you say? I guess this goes away after a couple of months, though. > And, yes, I've actually seen that as well as: > > ; This is a comment > I hope it was in a tutorial-situation. Or maybe it was written by one of those "ironic" programmers? /W -- INVALID? DE! From roy at panix.com Fri Feb 26 11:39:51 2010 From: roy at panix.com (Roy Smith) Date: Fri, 26 Feb 2010 11:39:51 -0500 Subject: Dictionary or Database‹Please advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: In article <891a98fa-c398-455a-981f-bf72af77256c at s36g2000prh.googlegroups.com>, Jeremy wrote: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy This is a very vague question, so it'll get a vague answer :-) If you have so much data that you're running into memory problems, then yes, storing the data externally in an disk-resident database seems like a reasonable idea. Once you get into databases, platform independence will be an issue. There are many databases out there to pick from. If you want something which will work on a lot of platforms, a reasonable place to start looking is MySQL. It's free, runs on lots of platforms, has good Python support, and there's lots of people on the net who know it and are willing to give help and advice. Databases have a bit of a learning curve. If you've never done any database work, don't expect to download MySql (or any other database) this afternoon and be up and running by tomorrow. Whatever database you pick, you're almost certainly going to end up having to install it wherever you install your application. There's no such thing as a universally available database that you can expect to be available everywhere. Have fun! From roy at panix.com Fri Feb 26 11:47:28 2010 From: roy at panix.com (Roy Smith) Date: Fri, 26 Feb 2010 11:47:28 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: In article , Tim Daneliuk wrote: > On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: > > Hi all, > > > > a company that works with my company writes a lot of of their code in > > Python (lucky jerks). I've seen their code and it basically looks like > > this: > > > > """Function that does stuff""" > > def doStuff(): > > while not wise(up): > > yield scorn > > > > Now my question is this: How do I kill these people without the > > authorities thinking they didn't deserve it? > > > > /W > > > > Reminiscent of: > > mov AX,BX ; Move the contents of BX into AX > > And, yes, I've actually seen that as well as: > > ; This is a comment OK, if we're going to do this, how about this one, that I just found yesterday in some production C++ code. I'm so glad somebody took the time to explain to me what p7 through p9 are. I never would have figured it out otherwise. /** * Tracing facility. Writes the message to the specified output stream. * If output stream is NULL, writes the message to the process log. * * @param msg_id The message id to use for lookup. * @param ostr The output stream. * @param p1 The first substition parameter. * @param p2 The second substition parameter. * @param p3 The third substition parameter. * @param p4 The fourth substition parameter. * @param p5 The fifth substition parameter. * @param p6 The sixth substition parameter. * @param p7 The seventh substition parameter. * @param p8 The eigth substition parameter. * @param p9 The ninth substition parameter. */ From ricaraoz at gmail.com Fri Feb 26 11:49:55 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Fri, 26 Feb 2010 13:49:55 -0300 Subject: Exception in pydoc Message-ID: <4B87FBB3.8090107@gmail.com> I'm developing an in house app. Many coders here are not fluent in english, so docstrings must be in Spanish in spite of recommendations that docstrings better be in English. When I use accented characters (in this case an '?') in my docstrings I get : >>> help('OpMejoraBizobj') Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site.py", line 346, in __call__ return pydoc.help(*args, **kwds) File "C:\Python25\lib\pydoc.py", line 1645, in __call__ self.help(request) File "C:\Python25\lib\pydoc.py", line 1687, in help elif request: doc(request, 'Help on %s:') File "C:\Python25\lib\pydoc.py", line 1481, in doc pager(title % desc + '\n\n' + text.document(object, name)) File "C:\Python25\lib\pydoc.py", line 324, in document if inspect.ismodule(object): return self.docmodule(*args) File "C:\Python25\lib\pydoc.py", line 1072, in docmodule contents.append(self.document(value, key, name)) File "C:\Python25\lib\pydoc.py", line 325, in document if inspect.isclass(object): return self.docclass(*args) File "C:\Python25\lib\pydoc.py", line 1208, in docclass contents = '\n'.join(contents) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 115: ordinal not in range(128) The file's first two lines are : """ #!/usr/bin/env python # -*- coding: utf-8 -*- """ Does pydoc only deal with ASCII? From phlip2005 at gmail.com Fri Feb 26 11:55:32 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 26 Feb 2010 08:55:32 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: Andreas Waldenburger wrote: > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? Their unit tests are just as complete, illustrative, and administratively sanctioned, right? -- Phlip http://penbird.tumblr.com/ From steve at holdenweb.com Fri Feb 26 11:59:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Feb 2010 11:59:56 -0500 Subject: Possible to import from a cStringIO file object vs. file on disk? In-Reply-To: <1267195808.16415.1362063523@webmail.messagingengine.com> References: <1267195808.16415.1362063523@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: > Is it possible to import from a cStringIO file object (containing > compiled byte code) vs. a physical file on disk? > > I'm thinking that this is possible, given Python's ability to import > from zip files, but I'm not sure where to look next. > > Thank you, > Malcolm > You'll need to write a custom importer. PEP 302 contains the necessary details. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From R.Brodie at rl.ac.uk Fri Feb 26 12:10:12 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Fri, 26 Feb 2010 17:10:12 -0000 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: "Andreas Waldenburger" wrote in message news:20100226173907.5567609f at geekmail.INVALID... >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX >> > Well, there might be some confusion there as to what gets moved where, > wouldn't you say? Depends on what assembler you're used to. I certainly find having the operands that way round confusing. From jlconlin at gmail.com Fri Feb 26 12:31:22 2010 From: jlconlin at gmail.com (Jeremy) Date: Fri, 26 Feb 2010 09:31:22 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> On Feb 26, 9:29?am, Chris Rebert wrote: > On Fri, Feb 26, 2010 at 7:58 AM, Jeremy wrote: > > I have lots of data that I currently store in dictionaries. ?However, > > the memory requirements are becoming a problem. ?I am considering > > using a database of some sorts instead, but I have never used them > > before. ?Would a database be more memory efficient than a dictionary? > > I also need platform independence without having to install a database > > and Python interface on all the platforms I'll be using. ?Is there > > something built-in to Python that will allow me to do this? > > If you won't be using the SQL features of the database, `shelve` might > be another option; from what I can grok, I sounds like a dictionary > stored mostly on disk rather than entirely in RAM (not 100% sure > though):http://docs.python.org/library/shelve.html > > It's in the std lib and supports several native dbm libraries for its > backend; one of them should almost always be present. > > Cheers, > Chris > --http://blog.rebertia.com Shelve looks like an interesting option, but what might pose an issue is that I'm reading the data from a disk instead of memory. I didn't mention this in my original post, but I was hoping that by using a database it would be more memory efficient in storing data in RAM so I wouldn't have to read from (or swap to/from) disk. Would using the shelve package make reading/writing data from disk faster since it is in a binary format? Jeremy From darcy at druid.net Fri Feb 26 12:57:50 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 26 Feb 2010 12:57:50 -0500 Subject: Dictionary or Database_Please advise In-Reply-To: References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <20100226125750.45f2406a.darcy@druid.net> On Fri, 26 Feb 2010 11:39:51 -0500 Roy Smith wrote: > Once you get into databases, platform independence will be an issue. There > are many databases out there to pick from. If you want something which > will work on a lot of platforms, a reasonable place to start looking is > MySQL. It's free, runs on lots of platforms, has good Python support, and > there's lots of people on the net who know it and are willing to give help > and advice. Or PostgreSQL. It's free, runs on lots of platforms, has good Python support, and there's lots of people on the net who know it and are willing to give help and advice. In addition, it is a truly enterprise level, SQL standard, fully transactional database. Don't start with MySQL and uprade to PostgreSQL later when you get big. Start with the best one now and be ready. > Databases have a bit of a learning curve. If you've never done any > database work, don't expect to download MySql (or any other database) this > afternoon and be up and running by tomorrow. Whatever database you get, there will probably be plenty of tutorials. See http://www.postgresql.org/docs/current/interactive/tutorial.html for the PostgreSQL one. -- 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 srikrishnamohan at gmail.com Fri Feb 26 13:03:43 2010 From: srikrishnamohan at gmail.com (km) Date: Sat, 27 Feb 2010 03:03:43 +0900 Subject: =?UTF-8?Q?Re=3A_Dictionary_or_Database=E8=BC=9Dlease_advise?= In-Reply-To: References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: Hi, Probably u should try couchdb! its a document oriented database. ( apache.couchdb.org) u can store your dictionaries as json documents and yes they are simple text files; data structures cna be directly stored into JSON documents. memory efficient too.. python module @ http://code.google.com/p/couchdb-python/ HTH Krishna ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Sat, Feb 27, 2010 at 1:39 AM, Roy Smith wrote: > In article > <891a98fa-c398-455a-981f-bf72af77256c at s36g2000prh.googlegroups.com>, > Jeremy wrote: > > > I have lots of data that I currently store in dictionaries. However, > > the memory requirements are becoming a problem. I am considering > > using a database of some sorts instead, but I have never used them > > before. Would a database be more memory efficient than a dictionary? > > I also need platform independence without having to install a database > > and Python interface on all the platforms I'll be using. Is there > > something built-in to Python that will allow me to do this? > > > > Thanks, > > Jeremy > > This is a very vague question, so it'll get a vague answer :-) > > If you have so much data that you're running into memory problems, then > yes, storing the data externally in an disk-resident database seems like a > reasonable idea. > > Once you get into databases, platform independence will be an issue. There > are many databases out there to pick from. If you want something which > will work on a lot of platforms, a reasonable place to start looking is > MySQL. It's free, runs on lots of platforms, has good Python support, and > there's lots of people on the net who know it and are willing to give help > and advice. > > Databases have a bit of a learning curve. If you've never done any > database work, don't expect to download MySql (or any other database) this > afternoon and be up and running by tomorrow. > > Whatever database you pick, you're almost certainly going to end up having > to install it wherever you install your application. There's no such thing > as a universally available database that you can expect to be available > everywhere. > > Have fun! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Fri Feb 26 13:04:27 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:04:27 +0100 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= In-Reply-To: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: Jeremy wrote: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. Is there > something built-in to Python that will allow me to do this? Since you use dictionaries, I guess that simple store saving key:value will do? If so, bsddb support built into Python will do just nicely. bsddb is multiplatform, although I have not personally tested if a binary db created on one platform will be usable on another. You'd have to check this. Caveat: from what some people say I gather that binary format between bsddb versions tends to change. There's also ultra-cool-and-modern Tokyo Cabinet key:value store with Python bindings: http://pypi.python.org/pypi/pytc/ I didn't test it, though. Regards, mk From garyrob at me.com Fri Feb 26 13:08:10 2010 From: garyrob at me.com (Gary Robinson) Date: Fri, 26 Feb 2010 13:08:10 -0500 Subject: collections use __next__() in python 2.6? Message-ID: <20100226130810913273.0085366e@me.com> The Python 2.6.4 docs for collections at http://docs.python.org/library/collections.html say that __next__() is an abstract method for the Iterable ABC. But my understanding is that __next__() isn't supposed to be used until Python 3. Also, I'm using the Mapping ABC, which inherits from Iterable, and it doesn't seem to work if I define __next__(); I am not seeing problems if I define next() instead. What am I missing? -- Gary Robinson CTO Emergent Music, LLC personal email: garyrob at me.com work email: grobinson at flyfi.com Company: http://www.flyfi.com Blog: http://www.garyrobinson.net From mrkafk at gmail.com Fri Feb 26 13:20:19 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:20:19 +0100 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= In-Reply-To: <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: Jeremy wrote: > Shelve looks like an interesting option, but what might pose an issue > is that I'm reading the data from a disk instead of memory. I didn't > mention this in my original post, but I was hoping that by using a > database it would be more memory efficient in storing data in RAM so I > wouldn't have to read from (or swap to/from) disk. Would using the > shelve package make reading/writing data from disk faster since it is > in a binary format? Read the docs: "class shelve.BsdDbShelf(dict[, protocol=None[, writeback=False]])? A subclass of Shelf which exposes first(), next(), previous(), last() and set_location() which are available in the bsddb module but not in other database modules. The dict object passed to the constructor must support those methods. This is generally accomplished by calling one of bsddb.hashopen(), bsddb.btopen() or bsddb.rnopen(). The optional protocol and writeback parameters have the same interpretation as for the Shelf class." Apparently using shelve internally gives you option of using bsddb, which is good news: bsddb is B-tree DB, which is highly efficient for finding keys. I would recommend bsddb.btopen(), as it creates B-tree DB (perhaps other implementations, like anydb or hash db are good as well, but I personally didn't test them out). I can't say for Berkeley DB implementation, but in general B-tree algorithm has O(log2 n) complexity for finding keys, which roughly means that if you need to find particular key in a db of 1 million keys, you'll probably need ~20 disk accesses (or even less if some keys looked at in the process of search happen to be in the same disk sectors). So yes, it's highly efficient. Having said that, remember that disk is many orders of magnitude slower than RAM, so it's no free lunch.. Nothing will beat memory-based data structure when it comes to speed (well new flash or hybrid disks perhaps could significantly improve in comparison to current mainstream mechanical-platter disks? there are some hyper-fast storage hardware companies out there, although they tend to charge arm and leg for their stuff for now). Caveat: Berkeley DB is dual-licensed -- if you're using it for commercial work, it might be that you'd need to buy a license for it. Although I have had no experience with this really, if someone here did perhaps they will shed some light on it? Regards, mk From jeanmichel at sequans.com Fri Feb 26 13:25:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 19:25:04 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100226173907.5567609f@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: <4B881200.5060505@sequans.com> Andreas Waldenburger wrote: > On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk > wrote: > > >> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >> >>> [stuff] >>> >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX >> >> > Well, there might be some confusion there as to what gets moved where, > wouldn't you say? I guess this goes away after a couple of months, > though. > I agree to that statement, I was surprised that mov AX,BX assumes that BX is the source, and AX the destination. I never programmed in assembler though. JM From mrkafk at gmail.com Fri Feb 26 13:26:46 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:26:46 +0100 Subject: Dictionary or Database_Please advise In-Reply-To: <20100226125750.45f2406a.darcy@druid.net> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <20100226125750.45f2406a.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > Or PostgreSQL. It's free, runs on lots of platforms, has good Python > support, and there's lots of people on the net who know it and are > willing to give help and advice. In addition, it is a truly enterprise > level, SQL standard, fully transactional database. Don't start with > MySQL and uprade to PostgreSQL later when you get big. Start with the > best one now and be ready. I second that: I burned my fingers on MySQL quite a few times and don't want to have anything to do with it anymore. Eventually you hit the wall with MySQL (although I haven't tested latest and best, perhaps they improved). E.g. don't even get me started on replication that tends to randomly fizzle out quietly without telling you anything about it. Or that FOREIGN KEY is accepted but referential integrity is not enforced. Or that if you want real transactions, you have to choose InnoDB table type but then you lose much of the performance. Etc. No, if you have a choice, avoid MySQL and go for PGSQL. It's fantastic, if (necessarily) complex. Regards, mk From jeanmichel at sequans.com Fri Feb 26 13:30:23 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 19:30:23 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <4B88133F.7020006@sequans.com> Roy Smith wrote: > In article , > Tim Daneliuk wrote: > > >> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >> >>> Hi all, >>> >>> a company that works with my company writes a lot of of their code in >>> Python (lucky jerks). I've seen their code and it basically looks like >>> this: >>> >>> """Function that does stuff""" >>> def doStuff(): >>> while not wise(up): >>> yield scorn >>> >>> Now my question is this: How do I kill these people without the >>> authorities thinking they didn't deserve it? >>> >>> /W >>> >>> >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX >> >> And, yes, I've actually seen that as well as: >> >> ; This is a comment >> > > OK, if we're going to do this, how about this one, that I just found > yesterday in some production C++ code. I'm so glad somebody took the time > to explain to me what p7 through p9 are. I never would have figured it out > otherwise. > > /** > * Tracing facility. Writes the message to the specified output stream. > * If output stream is NULL, writes the message to the process log. > * > * @param msg_id The message id to use for lookup. > * @param ostr The output stream. > * @param p1 The first substition parameter. > * @param p2 The second substition parameter. > * @param p3 The third substition parameter. > * @param p4 The fourth substition parameter. > * @param p5 The fifth substition parameter. > * @param p6 The sixth substition parameter. > * @param p7 The seventh substition parameter. > * @param p8 The eigth substition parameter. > * @param p9 The ninth substition parameter. > */ > just in case the first sub param would be p0 :-) JM From arjun.chennu at gmail.com Fri Feb 26 13:39:08 2010 From: arjun.chennu at gmail.com (Arjun) Date: Fri, 26 Feb 2010 10:39:08 -0800 (PST) Subject: How to end TCP socket data while using readline()? Message-ID: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> Hi, I have a small script that runs a TCP server. A client connects to this server and transmits a stored file line-by-line, and then waits for a confirmation "done". However, when I run them the first loop never really ends -- as the TCP server keeps expecting more data. I am using a file-like-object, and so somehow I have to communicate to the server that it is the end-of-file. here is some server code sock1.bind(('', port)) print "Listening at port: ", port sock1.listen(1) # listening socket (conn, addr) = sock1.accept() # connected socket print 'Client (localhost) port: ', addr[1] cf = conn.makefile('r',0) # file like obj for socket lf = open('ccs.txt','w') for line in cf: lf.write(line) lf.flush() sys.stdout.write(line) print len(line) lf.close() (*here*) cf.close() cf = conn.makefile('w',0) print len(line) print 'sendin' stat = 'done' cf.write(stat) print stat print 'sent' cf.close() print 'script done & connection closed' The client is sending the lines through this code: s.connect((host,port)) sfp = open("dcs.txt") # script = sfp.readlines() stat = 'still' cf = s.makefile('w',0) for line in sfp.readlines(): cf.write(line) print len(line) print 'close' cf.flush() cf.close() sfp.close() cf = s.makefile('r',0) print stat, 'waiting' stat = cf.readline() print stat, 'waiting' # this should become "done waiting" cf.close() s.close() So what I am wondering is: 1. Using a file-like object means that the socket becomes uni- directional, until the mode of the file object is changed from 'r' to 'w' (or vice versa). This seems inefficient, and rather unPythonesque. Can somebody tell me if there is a more elegant way of receiving all the lines from the client, and then sending a "done" message to the client? 2. Where I have marked (*here*) in the server code, is where the execution seems to stay waiting... apparently for more input from the client. But then when I force-terminate the client script, the execution continues on the server-side!! So then it sends the "done" status to a (already dead) client, and then exits. How do I get the server to know when the EOF has been reached while using FLOs? Input on this will be much appreciated, because the documentation for readlines() didn't help me with this. Cheers, A From mrkafk at gmail.com Fri Feb 26 13:41:48 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:41:48 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: Roy Smith wrote: > /** > * Tracing facility. Writes the message to the specified output stream. > * If output stream is NULL, writes the message to the process log. > * > * @param msg_id The message id to use for lookup. > * @param ostr The output stream. > * @param p1 The first substition parameter. > * @param p2 The second substition parameter. > * @param p3 The third substition parameter. > * @param p4 The fourth substition parameter. > * @param p5 The fifth substition parameter. > * @param p6 The sixth substition parameter. > * @param p7 The seventh substition parameter. > * @param p8 The eigth substition parameter. > * @param p9 The ninth substition parameter. > */ Well at least they did explain something. ;-) You should be happy you don't have to deal with PHP programmers that tend to write 20-positional-argument function AND programmer 1 knows what params 1-7 do, programmer 2 knows what params 8-15 do and nobody knows what params 16-20 do. Seriously. Regards, mk From shailendra.vikas at gmail.com Fri Feb 26 14:07:10 2010 From: shailendra.vikas at gmail.com (Shailendra) Date: Fri, 26 Feb 2010 14:07:10 -0500 Subject: SystemError: error return without exception set Message-ID: Hi All, I am getting error in "SystemError: error return without exception set" which i am not able debug. I made following test program which gives same error. =========test.py============== import numpy class testClass: def __init__(self,param1=1,param2=2): self.param1,self.param2=param1,param2 def __str__(self): return 'param1=%d param2=%d'%(self.param1,self.param2) class makeLotOftestClass: def __init__(self,paramlist1=None,paramlist2=None): self.holder= numpy.empty((len(paramlist1),len(paramlist2))) for i in range(len(paramlist1)): for j in range(len(paramlist2)): self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) def __str__(): str='' for testclass in numpy.raven(self.holder): str=str+testclass.__str__() return str if __name__=='__main__': lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) print lotofclass ============================================== $ python test.py Traceback (most recent call last): File "test.py", line 25, in lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) File "test.py", line 16, in __init__ self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) SystemError: error return without exception set Can someone point out why is this exception. It seems to be a simple code. Google search for the error message did not help much. Thanks, Shailendra From toby at rcsreg.com Fri Feb 26 14:13:06 2010 From: toby at rcsreg.com (Tobiah) Date: Fri, 26 Feb 2010 19:13:06 GMT Subject: Six Minutes and fourty two seconds Message-ID: <63Vhn.92$1n5.11@newsfe04.iad> Now that I use python, this is the amount of time per day that I spend adding forgotten semicolons while debugging other languages. From aahz at pythoncraft.com Fri Feb 26 14:23:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 11:23:16 -0800 Subject: lists of variables References: Message-ID: In article , Michael Pardee wrote: > >I'm relatively new to python and I was very surprised by the following >behavior: http://starship.python.net/crew/mwh/hacks/objectthink.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From mnordhoff at mattnordhoff.com Fri Feb 26 14:28:01 2010 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Fri, 26 Feb 2010 19:28:01 +0000 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: <4B8820C1.3010803@mattnordhoff.com> Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. You can fix that by not using other languages. :> -- Matt Nordhoff From nagle at animats.com Fri Feb 26 14:28:21 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Feb 2010 11:28:21 -0800 Subject: When will Java go mainstream like Python? In-Reply-To: <7umqtdFlrrU1@mid.individual.net> References: <7umqtdFlrrU1@mid.individual.net> Message-ID: <4B8820D5.7030502@animats.com> Gregory Ewing wrote: > Lawrence D'Oliveiro wrote: >> And then there?s caching. Modern CPUs owe most of their speed to >> assumptions that programs will obey locality of reference. >> Pointer-chasing is a cache- >> hostile activity. > > Another thing to consider is the rate at which garbage is > created. Java's fundamental types (ints, floats, etc.) are > unboxed, and objects are only used for relatively heavyweight > things. So you can do quite a lot of useful computation in > Java without creating any objects or leaving behind any > garbage. > > In Python, on the other hand, you can't even do arithmetic > without creating and destroying intermediate objects at > every step. This is really a CPython implementation problem. Face it, CPython is a "naive interpreter". It pretty much does the obvious. In other words, the code for the worst case is used for all cases. It doesn't optimize out reference count updates, do type inference to avoid unnecessary boxing, or figure out at compile time which objects could be "slotted" and don't need dictionary lookups for fields. Plus, of course, there's the GIL problem. Reference counts aren't inherently slow. About 90% of reference count updates could be optimized out. The compiler needs to understand what's a temporary object and what isn't. See http://blogs.msdn.com/abhinaba/archive/2009/02/09/back-to-basics-optimizing-reference-counting-garbage-collection.aspx The language isn't inherently slow, but CPython is. The Shed Skin developer has shown what's possible. He doesn't have enough resources to finish a full implementation, but he's on the right track. There's grumbling about the restrictions in Shed Skin, but only some of Shed Skin's restrictions are inherently necessary. The one Shed Skin developer has accomplished far more than the PyPy army of ants. John Nagle From python at mrabarnett.plus.com Fri Feb 26 14:31:32 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Feb 2010 19:31:32 +0000 Subject: SystemError: error return without exception set In-Reply-To: References: Message-ID: <4B882194.7030500@mrabarnett.plus.com> Shailendra wrote: > Hi All, > I am getting error in "SystemError: error return without exception > set" which i am not able debug. I made following test program which > gives same error. > > =========test.py============== > > import numpy > > class testClass: > def __init__(self,param1=1,param2=2): > self.param1,self.param2=param1,param2 > > def __str__(self): > return 'param1=%d param2=%d'%(self.param1,self.param2) > > > class makeLotOftestClass: > def __init__(self,paramlist1=None,paramlist2=None): > self.holder= numpy.empty((len(paramlist1),len(paramlist2))) > for i in range(len(paramlist1)): > for j in range(len(paramlist2)): > > self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) > > def __str__(): > str='' > for testclass in numpy.raven(self.holder): > str=str+testclass.__str__() > return str > > if __name__=='__main__': > lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) > print lotofclass > > ============================================== > > $ python test.py > Traceback (most recent call last): > File "test.py", line 25, in > lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) > File "test.py", line 16, in __init__ > self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) > SystemError: error return without exception set > > Can someone point out why is this exception. It seems to be a simple > code. Google search for the error message did not help much. > As I see it, there are 2 problems here: 1. numpy arrays contain numbers, but what you're trying to put into the array are not numbers. 2. The numpy module is trying to raise an exception but it isn't setting up the exception correctly internally, which is a bug in numpy itself. From mrkafk at gmail.com Fri Feb 26 14:36:35 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 20:36:35 +0100 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. My objects are flat and I don't know who's Guido. I blame it all on Python. How about a PEP "Let's make Python look like PHP"? Regards, mk From python at mrabarnett.plus.com Fri Feb 26 14:45:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Feb 2010 19:45:58 +0000 Subject: How to end TCP socket data while using readline()? In-Reply-To: References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> <4B881F04.7040106@mrabarnett.plus.com> Message-ID: <4B8824F6.9010607@mrabarnett.plus.com> Arjun Chennu wrote: > No need to flush because you're writing to a file and it'll be flushed > > anyway when you close it. > > > True. I had introduced those flush lines while I was trying to > troubleshoot this annoying situation. :-) > > You've closed the file view, but the underlying socket is still open. > > > The server will see EOF only when the socket is closed by the client, > and closing the file view doesn't close the socket itself. > > > That's what I intended to do. Keep the socket open, but close the file > object so that the direction of transfer can be reversed and a "done" > message can be sent to the client. > > TCP is meant to facilitate two-directional transfer innit? So how do I > do that while using file objects? If i have to close the socket to do > that, it seems a bit wasteful in terms of network 'transactions' > > Thanks for your reply. I've already confirmed that closing the socket > does indeed move the program ahead --- but I'd like to now make > two-directional comm. possible. > Here's a trick borrowed from the POP3 format (used for email). Server code: ... cf = conn.makefile('r', 0) # file like obj for socket lf = open('ccs.txt', 'w') for line in cf: if line == '.end\n': break if line.startswith('..'): line = line[1 : ] lf.write(line) sys.stdout.write(line) print len(line) lf.close() cf.close() ... Client code: ... cf = s.makefile('w', 0) for line in sfp.readlines(): if line.startswith('.'): cf.write('.') cf.write(line) print len(line) cr.write('.end\n') print 'close' cf.close() ... From python at bdurham.com Fri Feb 26 14:49:09 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 26 Feb 2010 14:49:09 -0500 Subject: Possible to import from a cStringIO file object vs. file on disk? In-Reply-To: <1267213340.1668.1362112899@webmail.messagingengine.com> References: <1267195808.16415.1362063523@webmail.messagingengine.com> <1267213340.1668.1362112899@webmail.messagingengine.com> Message-ID: <1267213749.2540.1362114855@webmail.messagingengine.com> Steve, > You'll need to write a custom importer. PEP 302 contains the necessary details. Thanks for pointing me to PEP 302 and the imp module. It looks like "imp.load_compiled(name, pathname[, file])" is what I need, but the description of this method (and similar methods) has the following disclaimer: Quote: "The file argument is the byte-compiled code file, open for reading in binary mode, from the beginning. It must currently be a real file object, not a user-defined class emulating a file." [1] I tried using a cStringIO object vs. a real file object, but the help documentation is correct - only a real file object can be used. Any ideas on why these modules would impose such a restriction or is this just an historical artifact? Are there any techniques I can use to avoid this physical file requirement? Thanks, Malcolm [1] http://docs.python.org/library/imp.html#imp.load_module python at bdurham.com wrote: > Is it possible to import from a cStringIO file object (containing > compiled byte code) vs. a physical file on disk? > > I'm thinking that this is possible, given Python's ability to import > from zip files, but I'm not sure where to look next. > > Thank you, > Malcolm > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list From ppearson at nowhere.invalid Fri Feb 26 15:07:52 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 26 Feb 2010 20:07:52 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7uqo0nF1ssU1@mid.individual.net> On Wed, 24 Feb 2010 20:16:24 +0100, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Out of curiosity: > > def gen_rand_string(length): > prng = random.SystemRandom() > chars = [] > for i in range(length): > chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) > return ''.join(chars) > > if __name__ == "__main__": > chardict = {} > for i in range(10000): > ## w = gen_rand_word(10) > w = gen_rand_string(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > > > s 3966 > d 3912 > g 3909 > h 3905 > a 3901 > u 3900 > q 3891 > m 3888 > k 3884 > b 3878 > x 3875 > v 3867 > w 3864 > y 3851 > l 3825 > z 3821 > c 3819 > e 3819 > r 3816 > n 3808 > o 3797 > f 3795 > t 3784 > p 3765 > j 3730 > i 3704 > > Better, although still not perfect. What would be perfect? Surely one shouldn't be happy if all the tallies come out exactly equal: that would be a blatant indication of something very nonrandom going on. The tallies given above give a chi-squared value smack in the middle of the range expected for random sampling of a uniform distribution (p = 0.505). So the chi-squared metric of goodness-of-fit to a unifom distribution says you're doing fine. -- To email me, substitute nowhere->spamcop, invalid->net. From python at rcn.com Fri Feb 26 15:10:33 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Feb 2010 12:10:33 -0800 (PST) Subject: collections use __next__() in python 2.6? References: Message-ID: On Feb 26, 10:08?am, Gary Robinson wrote: > The Python 2.6.4 docs for collections athttp://docs.python.org/library/collections.htmlsay that __next__() is an abstract method for the Iterable ABC. But my understanding is that __next__() isn't supposed to be used until Python 3. Also, I'm using the Mapping ABC, which inherits from Iterable, and it doesn't seem to work if I define __next__(); I am not seeing problems if I define next() instead. > > What am I missing? It's a typo. The abstract method is next(). Raymond From ppearson at nowhere.invalid Fri Feb 26 15:17:43 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 26 Feb 2010 20:17:43 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7uqoj7F1ssU2@mid.individual.net> On Wed, 24 Feb 2010 21:02:07 +0100, mk wrote: [snip] > > rand_str_SystemRandom_seeding > mean 3845.15384615 std dev 46.2016419186 > l 3926 1.75 std devs away from mean > y 3916 1.53 std devs away from mean > d 3909 1.38 std devs away from mean > a 3898 1.14 std devs away from mean > p 3898 1.14 std devs away from mean > c 3889 0.95 std devs away from mean > u 3884 0.84 std devs away from mean > j 3873 0.60 std devs away from mean > n 3873 0.60 std devs away from mean > w 3866 0.45 std devs away from mean > x 3863 0.39 std devs away from mean > r 3855 0.21 std devs away from mean > m 3852 0.15 std devs away from mean > b 3841 -0.09 std devs away from mean > t 3835 -0.22 std devs away from mean > o 3829 -0.35 std devs away from mean > k 3827 -0.39 std devs away from mean > i 3821 -0.52 std devs away from mean > s 3812 -0.72 std devs away from mean > q 3806 -0.85 std devs away from mean > v 3803 -0.91 std devs away from mean > g 3799 -1.00 std devs away from mean > h 3793 -1.13 std devs away from mean > e 3782 -1.37 std devs away from mean > f 3766 -1.71 std devs away from mean > z 3758 -1.89 std devs away from mean Chi2 = 14.43, 25 d.f., prob = 0.046362. The observed distribution is SIGNIFICANTLY CLOSER to the uniform distribution than reasonable by chance. > rand_str_SystemRandom_noseeding > mean 3845.15384615 std dev 55.670522726 > i 3961 2.08 std devs away from mean > r 3911 1.18 std devs away from mean > e 3910 1.16 std devs away from mean > m 3905 1.08 std devs away from mean > a 3901 1.00 std devs away from mean > u 3893 0.86 std devs away from mean > t 3882 0.66 std devs away from mean > w 3872 0.48 std devs away from mean > s 3870 0.45 std devs away from mean > c 3868 0.41 std devs away from mean > n 3866 0.37 std devs away from mean > q 3865 0.36 std devs away from mean > k 3863 0.32 std devs away from mean > y 3848 0.05 std devs away from mean > j 3836 -0.16 std devs away from mean > v 3830 -0.27 std devs away from mean > f 3829 -0.29 std devs away from mean > z 3829 -0.29 std devs away from mean > g 3827 -0.33 std devs away from mean > l 3818 -0.49 std devs away from mean > b 3803 -0.76 std devs away from mean > d 3803 -0.76 std devs away from mean > p 3756 -1.60 std devs away from mean > x 3755 -1.62 std devs away from mean > h 3744 -1.82 std devs away from mean > o 3729 -2.09 std devs away from mean Chi2 = 20.96, 25 d.f., prob = 0.304944. The observed distribution is not significantly different from the uniform distribution. > rand_str_custom > mean 3517.15384615 std dev 40.7541336343 > i 3586 1.69 std devs away from mean > a 3578 1.49 std devs away from mean > e 3575 1.42 std devs away from mean > m 3570 1.30 std devs away from mean > q 3562 1.10 std devs away from mean > c 3555 0.93 std devs away from mean > g 3552 0.86 std devs away from mean > w 3542 0.61 std devs away from mean > p 3536 0.46 std devs away from mean > x 3533 0.39 std devs away from mean > s 3528 0.27 std devs away from mean > o 3524 0.17 std devs away from mean > d 3516 -0.03 std devs away from mean > t 3515 -0.05 std devs away from mean > h 3511 -0.15 std devs away from mean > v 3502 -0.37 std devs away from mean > z 3502 -0.37 std devs away from mean > b 3500 -0.42 std devs away from mean > f 3496 -0.52 std devs away from mean > u 3492 -0.62 std devs away from mean > l 3486 -0.76 std devs away from mean > r 3478 -0.96 std devs away from mean > n 3476 -1.01 std devs away from mean > j 3451 -1.62 std devs away from mean > k 3450 -1.65 std devs away from mean > y 3430 -2.14 std devs away from mean Chi2 = 12.28, 25 d.f., prob = 0.015815. The observed distribution is SIGNIFICANTLY CLOSER to the uniform distribution than reasonable by chance. > It would appear that SystemRandom().choice is indeed best (in terms of > how much the counts stray from mean in std devs), but only after seeding > it with os.urandom. I don't see any reason to worry about any of the three, except perhaps that the first and last are surprisingly uniform. -- To email me, substitute nowhere->spamcop, invalid->net. From cmpython at gmail.com Fri Feb 26 15:27:06 2010 From: cmpython at gmail.com (CM) Date: Fri, 26 Feb 2010 12:27:06 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Feb 26, 10:58?am, Jeremy wrote: > I have lots of data How much is "lots"? > that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? What do you mean by more efficient? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? The SQLite datbase engine is built into Python 2.5 and up. I have heard on this list that there may be problems with it with Python 2.6 and up on Linux, but I've stayed with 2.5 and it works fine for me on WinXP, Vista, and Linux. You can use it as a disk-stored single database file, or an in-memory- only database. The SQLite website (http://www.sqlite.org/) claims it is the "most widely deployed SQL database engine in the world.", for what that's worth. Have a look at this: http://docs.python.org/library/sqlite3.html Che > > Thanks, > Jeremy From alfps at start.no Fri Feb 26 15:44:44 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Feb 2010 21:44:44 +0100 Subject: lists of variables In-Reply-To: References: Message-ID: * Michael Pardee: > I'm relatively new to python and I was very surprised by the following behavior: > >>>> a=1 >>>> b=2 'a' refers to an object representing the integer 1. Since 1 is an immutable value you can just as well think of it as 'a' containing the value 1, because a reference to an immutable value is for nearly all practical purposes indistinguishable from that value. 'b' refers to an object representing the integer 2, which, again, since integers are immutable, you can just as well think of as 'b' containing the value 2. >>>> mylist=[a,b] A 'list' object (an array) is constructed, and 'mylist' is set to refer to it. The array has two items. The first item is set to refer to same object as 'a' (a reference copy), the second item is set to refer to the same object as 'b'. But since integers are immutable you can just as well think of it as a copying of the integer values. Immutable values allow you to think of handling the values directly. >>>> print mylist > [1, 2] >>>> a=3 This changes what 'a' refers to. It does not change what the first array element refers to. >>>> print mylist > [1, 2] > > Whoah! Are python lists only for literals? No, that's an irrelevant notion. > Nope: > >>>> c={} >>>> d={} Here 'c' now refers to a dictionary object, which is mutable (can be changed). And 'd' refers to another dictionary object. >>>> mydlist=[c,d] >>>> print mydlist > [{}, {}] A 'list' array object is constructed, and 'mydlist' is set to refer to it. The first item in the array is set to refer to the same object as 'c' refers to, namely a mutable dictionary object (currently an empty dictionary). The second item in the array is set to refer to the same object as 'd' refers to, namely a mutable dictionary object (currently an empty dictionary). It's the same that happened earlier with the integers. The only difference, but it's a significant one, is that now the referred to objects are mutable, that is, they can be changed. >>>> c['x']=1 The dictionary object referred to by 'c' is updated to now have a key 'x' with associated value 1. In more gory detail: the key is associated with a reference to an object representing 1, but again, since integer values are immutable you can think of this as a direct association with the value; the reference view of this association is mostly[1] only relevant when the referred to object is mutable. Since the dictionary object that you're changing is referred to by both 'c' and the first item of 'mydlist', both of these reflect the change. >>>> print mydlist > [{'x': 1}, {}] Yep. > So it looks like variables in a list are stored as object references. You mean items in a list are references to objects. Yes. > This seems to confirm that: > > mydlist[1]['y']=4 >>>> print mydlist > [{}, {'y': 4}] To check that you should instead have printed 'd', where you'd also see the change, since 'd' refers to the same dictionary object as 'mydlist[1]' does. > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. No, it has nothing to do with literals. With the current language definition[2], as of Python 2.x and 3.x, it's very simple: assignments copy references, and that's all they do. References to immutable objects allow you to think of values being copied around, which except for checking the identities of those objects (seldom relevant) yields the exact same conclusions about the effect of operations, but that's only because those immutable objects never change. What you did above was to copy references to mutable objects, objects that can change. Then the value-copying view breaks down. > But modifying a list > or dict (as long as you don't re-construct it) does not change the > object. A simple way to think of this is copying references. Objects are never copied by Python assignments. The assignments only copy references. > I can think of some ways to work around this, including using single > element lists as "pointers": > >>>> aa=[1] >>>> bb=[2] >>>> myplist=[aa,bb] >>>> print myplist > [[1], [2]] >>>> aa[0]=3 >>>> print myplist > [[3], [2]] This is the same as your last example above, except that now you're using 'list' arrays as the referred to mutable objects, instead of 'dict' dictionary objects. > But what would be "the python way" to accomplish "list of variables" > functionality? Possibly, if you think of assignments as copying references, you won't need that notion. Cheers & hth., - Alf Notes: [1] The reference view can be relevant also for immutable objects in (at least) two cases. One is when the program logic depends on object identity, obtainable via the id function, which is just bad programming, but I mention it for completeness. The other is where you have a really large immutable object, such as in Python 2.x a very large 'long' value; then assignments would be inefficient if the value was actually copied, but since assignments only copy references in Python you can blissfully disregard the size of the object with respect to assignments. :-) [2] Some wording in the language spec requires that an assignment behaves as if references were copied, including preservation of object identity. But object identity is almost never an issue for immutable objects, and a relaxation of that wording, for immutable values, might permit some optimization. So it just might change somewhen in the future, trading simplicity for some efficiency. From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 15:45:31 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 09:45:31 +1300 Subject: A more specific query ... Message-ID: How can I interrogate Python to find out where it is looking to find the PyQt4 DLLs in a Windows installation? Secondarily, how is this search path set? From olivier.darge at gmail.com Fri Feb 26 15:51:34 2010 From: olivier.darge at gmail.com (OdarR) Date: Fri, 26 Feb 2010 12:51:34 -0800 (PST) Subject: any news from Python Magazine ? Message-ID: Seems rather late...: http://pythonmagazine.com/ "We'll be back, better than ever, on January 26th, 2010. " Olivier From mwilson at the-wire.com Fri Feb 26 15:52:00 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Feb 2010 15:52 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >> wrote: >>> Reminiscent of: >>> mov AX,BX ; Move the contents of BX into AX >> Well, there might be some confusion there as to what gets moved where, >> wouldn't you say? I guess this goes away after a couple of months, >> though. > I agree to that statement, I was surprised that mov AX,BX assumes that > BX is the source, and AX the destination. I never programmed in > assembler though. You could think of it as a not bad use of the design principle "Clear The Simple Stuff Out Of The Way First". Destinations are commonly a lot simpler than sources -- just as in Python assignment statements. So you can tell more or less at a glance what's going to be changed, then get into the deep analysis to find what it's going to be changed to. Mel. From patrick.just4fun at gmail.com Fri Feb 26 15:56:47 2010 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Fri, 26 Feb 2010 21:56:47 +0100 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= In-Reply-To: <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: <4B88358F.5000501@gmail.com> > Shelve looks like an interesting option, but what might pose an issue > is that I'm reading the data from a disk instead of memory. I didn't > mention this in my original post, but I was hoping that by using a > database it would be more memory efficient in storing data in RAM so I > wouldn't have to read from (or swap to/from) disk. A database usually stores data on disk and not in RAM. However you could use sqlite with :memory:, so that it runs in RAM. > Would using the > shelve package make reading/writing data from disk faster since it is > in a binary format? > Faster than what? Shelve uses caching, so it is likely to be faster than a self-made solution. However, accessing disk is much slower than accessing RAM. > Jeremy - Patrick From invalid at invalid.invalid Fri Feb 26 16:07:15 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 26 Feb 2010 21:07:15 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: On 2010-02-26, Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >> wrote: >> >> >>> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >>> >>>> [stuff] >>>> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >> >> Well, there might be some confusion there as to what gets moved where, >> wouldn't you say? I guess this goes away after a couple of months, >> though. > > I agree to that statement, I was surprised that mov AX,BX assumes that > BX is the source, and AX the destination. I never programmed in > assembler though. It depends on the assembler. Some are dst, src and others are the other way around. Some vary depending on the instruction. -- Grant Edwards grante Yow! Sign my PETITION. at visi.com From qtrimble at gmail.com Fri Feb 26 16:08:28 2010 From: qtrimble at gmail.com (qtrimble) Date: Fri, 26 Feb 2010 13:08:28 -0800 (PST) Subject: loop through each line in a text file Message-ID: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> I'm a python newbie but I do have some basic scripting experience. I need to take the line starting with "wer" and extract the year and day of year from that string. I want to be able to add the year and day of year from the last line having "wer*" to the lines occurring in between "wer*" lines. Python seems suitable to do this and I'm fairly certain I can eventually get this to work but I've been hit with a very short time frame so I'm looking for any generous help. The data below is just a sample. There are well over 500,000 lines that need processed. wer1999001 31.2234 82.2367 37.9535 82.3456 wer1999002 31.2234 82.2367 37.9535 82.3456 From alfps at start.no Fri Feb 26 16:12:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Feb 2010 22:12:07 +0100 Subject: loop through each line in a text file In-Reply-To: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> Message-ID: * qtrimble: > I'm a python newbie but I do have some basic scripting experience. I > need to take the line starting with "wer" and extract the year and day > of year from that string. I want to be able to add the year and day > of year from the last line having "wer*" to the lines occurring in > between "wer*" lines. Python seems suitable to do this and I'm fairly > certain I can eventually get this to work but I've been hit with a > very short time frame so I'm looking for any generous help. The data > below is just a sample. There are well over 500,000 lines that need > processed. > > wer1999001 > 31.2234 82.2367 > 37.9535 82.3456 > wer1999002 > 31.2234 82.2367 > 37.9535 82.3456 >>> line = "wer1999001" >>> line 'wer1999001' >>> line[3:3+4] '1999' >>> line[7:7+3] '001' >>> _ Cheers & hth., - Alf From olivier.darge at gmail.com Fri Feb 26 16:14:12 2010 From: olivier.darge at gmail.com (OdarR) Date: Fri, 26 Feb 2010 13:14:12 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> Message-ID: <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> On 26 f?v, 22:08, qtrimble wrote: > I'm a python newbie but I do have some basic scripting experience. ?I > need to take the line starting with "wer" and extract the year and day > of year from that string. ?I want to be able to add the year and day > of year from the last line having "wer*" to the lines occurring in > between "wer*" lines. ?Python seems suitable to do this and I'm fairly > certain I can eventually get this to work but I've been hit with a > very short time frame so I'm looking for any generous help. ?The data > below is just a sample. ?There are well over 500,000 lines that need > processed. > > wer1999001 > ? ? ? 31.2234 ? ? ?82.2367 > ? ? ? 37.9535 ? ? ?82.3456 > wer1999002 > ? ? ? 31.2234 ? ? ?82.2367 > ? ? ? 37.9535 ? ? ?82.3456 did you try something as a working basis ? Olivier From clp2 at rebertia.com Fri Feb 26 16:19:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Feb 2010 13:19:27 -0800 Subject: A more specific query ... In-Reply-To: References: Message-ID: <50697b2c1002261319y7e71c958p7bf4f4be60902066@mail.gmail.com> On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle wrote: > How can I interrogate Python to find out where it is looking to find the > PyQt4 DLLs in a Windows installation? import sys print(sys.path) Cheers, Chris -- http://blog.rebertia.com From qtrimble at gmail.com Fri Feb 26 16:21:26 2010 From: qtrimble at gmail.com (qtrimble) Date: Fri, 26 Feb 2010 13:21:26 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> Message-ID: <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> On Feb 26, 4:14?pm, OdarR wrote: > On 26 f?v, 22:08, qtrimble wrote: > > > > > I'm a python newbie but I do have some basic scripting experience. ?I > > need to take the line starting with "wer" and extract the year and day > > of year from that string. ?I want to be able to add the year and day > > of year from the last line having "wer*" to the lines occurring in > > between "wer*" lines. ?Python seems suitable to do this and I'm fairly > > certain I can eventually get this to work but I've been hit with a > > very short time frame so I'm looking for any generous help. ?The data > > below is just a sample. ?There are well over 500,000 lines that need > > processed. > > > wer1999001 > > ? ? ? 31.2234 ? ? ?82.2367 > > ? ? ? 37.9535 ? ? ?82.3456 > > wer1999002 > > ? ? ? 31.2234 ? ? ?82.2367 > > ? ? ? 37.9535 ? ? ?82.3456 > > did you try something as a working basis ? > > Olivier Yes but it's very simple - fileIN = open(r"C:\testing.txt", "r") for line in fileIN: year = line[3:7] day = line[7:10] print year, day This is good since i can get the year and day of year into a variable but I haven't gotten any further. From pistacchio at gmail.com Fri Feb 26 16:26:44 2010 From: pistacchio at gmail.com (pistacchio) Date: Fri, 26 Feb 2010 13:26:44 -0800 (PST) Subject: random.gauss: range Message-ID: hi, i'm trying the random.gauss function. can anyone explain how to get a number between a given range? like, from 0 to 20 with an average of 10? and how to determine the "steep" of the curve? i've never studied it, so mu and sigma don't really tell me a thing. thanks in advange From lucat at despammed.com Fri Feb 26 16:30:58 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 22:30:58 +0100 Subject: Renaming identifiers & debugging In-Reply-To: References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uog65F5vuU1@mid.individual.net> Message-ID: <7uqssjFmeeU1@mid.individual.net> Roald de Vries wrote: > I would suggest to do choose the same strategy as 'from __future__ > import ...' takes, which does similar things and limits them to the > module it is used in. I would be curious to hear about your results. > > Kind regards, Roald Hi, well, i have thought on the issue and i think that i have found a solution that does not imply renaming the keywords. It mixes a bit the suggestions i got here and this is how. My application will have a text editor (with, hopefully, code highlighting) a text-box to insert "instant" commands and a text-box for the output and a window for the "turtle". With the "instant commands" you can insert little pieces of python code and see instantly their result both as a turtle movement or textual output. With the text-editor you can load/save/write whole python programs and execute or debug them step by step. The way to track the code could use this technique http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html which gives me exactly the number of line of code under execution and also stops the code until the function "treaceit" returns. This will allow me to insert breakpoints, execute the code line by line, and so on (or at least this is the theory). Now. Since i get the number of the line i don't need anymore to have the language deal with translated keywords. The kid can write the code in his/her own language and the program will "translate it back to english" before passing them to the embedded python. When i save a source file i can save the english version and translate it "on the fly" when i load it. I can also intercept error codes and translate them as well, showing the kid only what i want him/her to see. So it would be completely transparent to the kid and it would notice it only by opening the source code via a different text-editor. In this way the files produced are 100% python files and the kid can disable this feature if he doesn't like it. This will also allow me to translate the same piece of code in any language i want, with 0 effort and this way will allow kids of different nations exchange their code and have it working on their computer. This seems a good idea to me, it reaches my points without breaking compatibility. The kid will see the language in his own language but the computer will actually work with the standard-python file. Once i have this "ready" i can proceed to other steps and try to implement other ideas that i have (remember c-robots and p-robots?). Bye, Luca From g.bogle at auckland.ac.nz Fri Feb 26 16:41:20 2010 From: g.bogle at auckland.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 10:41:20 +1300 Subject: A more specific query ... In-Reply-To: <50697b2c1002261319y7e71c958p7bf4f4be60902066@mail.gmail.com> References: <50697b2c1002261319y7e71c958p7bf4f4be60902066@mail.gmail.com> Message-ID: <4B884000.5040900@auckland.ac.nz> The point of my question was that sys.path is clearly not being used in this case. When I start Python sys.path includes D:\python26\lib\site-packages which seems to be the Python default. Using sys.path.append I have tried adding both D:\python26\lib\site-packages\PyQt4 and D:\python26\lib\site-packages\PyQt4\bin to the path, but this has no effect. So far the only way I've found to make the PyQt4 DLLs visible to Python is by copying them from PyQt4\bin into PyQt4. I've tried adding stuff to the Windows PATH, but that has no effect. Gib Chris Rebert wrote: > On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle > wrote: >> How can I interrogate Python to find out where it is looking to find the >> PyQt4 DLLs in a Windows installation? > > import sys > print(sys.path) > > Cheers, > Chris > -- > http://blog.rebertia.com From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 16:44:41 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 10:44:41 +1300 Subject: A more specific query ... References: Message-ID: Chris Rebert wrote: > On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle > wrote: >> How can I interrogate Python to find out where it is looking to find the >> PyQt4 DLLs in a Windows installation? > > import sys > print(sys.path) Note this thread: http://www.mail-archive.com/pyqt at riverbankcomputing.com/msg20121.html I'm starting to get the impression that Windows is the 'poor relation' in the Python family ... From sanelson at gmail.com Fri Feb 26 16:54:33 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Fri, 26 Feb 2010 13:54:33 -0800 (PST) Subject: Problems uploading to IIS using FTP over SSL References: Message-ID: <731c347e-df4d-4ff8-af82-22380abc8ad2@f35g2000yqd.googlegroups.com> On Feb 26, 2:05?pm, Stephen Nelson-Smith wrote: > Hello, I'm sorry - I hadn't realised that python-list ended up here as well. Sincere apologies for double-posting. S. From robert.kern at gmail.com Fri Feb 26 16:56:55 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Feb 2010 15:56:55 -0600 Subject: random.gauss: range In-Reply-To: References: Message-ID: On 2010-02-26 15:26 PM, pistacchio wrote: > hi, > i'm trying the random.gauss function. can anyone explain how to get a > number between a given range? You don't. The Gaussian distribution has infinite range. The best you can do with the standard library is to keep sampling until you get a number inside your desired range. If you aren't careful about your choice of parameters, this could waste a lot of time. > like, from 0 to 20 with an average of > 10? and how to determine the "steep" of the curve? i've never studied > it, so mu and sigma don't really tell me a thing. Study it: http://en.wikipedia.org/wiki/Normal_distribution mu is the mean, the location of the central peak. sigma is the standard deviation, which controls the width of the peak. Larger sigma means wider and shorter peak. You may want another distribution, like random.betavariate(): http://en.wikipedia.org/wiki/Beta_distribution -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From breamoreboy at yahoo.co.uk Fri Feb 26 16:59:16 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 26 Feb 2010 21:59:16 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4B881200.5060505@sequans.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <4B881200.5060505@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >> wrote: >> >> >>> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >>> >>>> [stuff] >>>> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >>> >>> >> Well, there might be some confusion there as to what gets moved where, >> wouldn't you say? I guess this goes away after a couple of months, >> though. >> > > I agree to that statement, I was surprised that mov AX,BX assumes that > BX is the source, and AX the destination. I never programmed in > assembler though. > > JM The obvious solution to this problem is to write the assembler code in your own way, and then use Python to change the code to the appropriate target. Any of the solutions listed here would presumably suffice. http://nedbatchelder.com/text/python-parsers.html Regards. Mark Lawrence. From python at bdurham.com Fri Feb 26 17:10:30 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 26 Feb 2010 17:10:30 -0500 Subject: How to determine if threads are active in an application? Message-ID: <1267222230.24180.1362126901@webmail.messagingengine.com> Is there technique to determine if threads are active in a Python application? The only technique I can think of is to check sys.modules for thread and threading. But this will only show whether these modules were imported - not whether there are actually background threads running. Motivation: We were debugging a customer's python application and they had a module that was unknowningly (to both us and them) creating threads in certain situations. This made our debugging process more complicated because there were side effects happening at unexpected times that we couldn't explain. The module in question was supplied to us as a compiled module that was considered fully tested by the customer. To prevent this confusion in the future, we're looking for a way that we can detect threads are active while we're debugging without having to manually step through every line of code in every module to check for unexpected thread creation. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Feb 26 17:22:09 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Feb 2010 11:22:09 +1300 Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: In message , William Lohrmann wrote: > The best thing would be to backslash the single quote: print 'The play > "All\'s Well That Ends Well"' Backslash-type escapes are the most general solution to this type of problem. They?re also the easiest to apply automatically: for ch in input_string : if ch in troublesome_lot : output backslash + tame representation of ch else : output ch #end if #end for From breamoreboy at yahoo.co.uk Fri Feb 26 17:25:59 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 26 Feb 2010 22:25:59 +0000 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. You think that's bad? I've spent hours today converting the J language that I don't dare mention to Python. Once in a blue moon I came across a line of code that actually did something. The rest of it was boilerplate. I'm never ever going to sin again, because if I do, I will be reincarnated as a J type, or worse still, I C(++) type. Regards. Mark Lawrence. No that's a swaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn!!!!! From jjposner at optimum.net Fri Feb 26 17:33:10 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 26 Feb 2010 17:33:10 -0500 Subject: loop through each line in a text file In-Reply-To: <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> Message-ID: <4B884C26.8010605@optimum.net> On 2/26/2010 4:21 PM, qtrimble wrote: > > fileIN = open(r"C:\testing.txt", "r") > > for line in fileIN: > year = line[3:7] > day = line[7:10] > print year, day > > This is good since i can get the year and day of year into a variable > but I haven't gotten any further. That's an excellent start. Here's another hint ... There are two kinds of lines in your input file: * lines that begin with "wer" * all other lines So you need an if-else section to process the lines in the input file: if line.startswith("wer"): # use the contents of *line* to assign values # to variables *year* and *day* ... else: # use the current values of *year* and *day* # to process the numbers extracted from *line* Most likely, you'll also need these functions: * split() -- chop a string into pieces * int() -- string-to-integer conversion HTH, John From aahz at pythoncraft.com Fri Feb 26 17:38:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 14:38:58 -0800 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: In article , Patrick Sabin wrote: > >A database usually stores data on disk and not in RAM. However you could >use sqlite with :memory:, so that it runs in RAM. The OP wants transparent caching, so :memory: wouldn't work. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From luismgz at gmail.com Fri Feb 26 17:41:04 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 26 Feb 2010 14:41:04 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Feb 26, 12:58?pm, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy For small quantities of data, dicts are ok, but if your app continually handles (and add) large quantities of data, you should use a database. You can start with sqlite (which is bundled with python) and it's much easier to use than any other relational database out there. You don't need to install anything, since it's not a database server. You simply save your databases as files. If you don't know sql (the standard language used to query databases), I recomend this online tutorial: http://www.sqlcourse.com/ Good luck! Luis From aahz at pythoncraft.com Fri Feb 26 17:42:22 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 14:42:22 -0800 Subject: Dictionary or Database‹Please advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: In article , Roy Smith wrote: > >Whatever database you pick, you're almost certainly going to end up having >to install it wherever you install your application. There's no such thing >as a universally available database that you can expect to be available >everywhere. ...unless you use SQLite. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Fri Feb 26 17:46:36 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 14:46:36 -0800 Subject: =?windows-1252?Q?Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: In article <891a98fa-c398-455a-981f-bf72af77256c at s36g2000prh.googlegroups.com>, Jeremy wrote: > >I have lots of data that I currently store in dictionaries. However, >the memory requirements are becoming a problem. I am considering >using a database of some sorts instead, but I have never used them >before. Would a database be more memory efficient than a dictionary? >I also need platform independence without having to install a database >and Python interface on all the platforms I'll be using. Is there >something built-in to Python that will allow me to do this? If you're serious about needing both a disk-based backing store *and* getting maximum use/performance from your RAM, you probably will need to combine memcached with one of the other solutions offered. But given your other requirement of not installing a DB, your best option will certainly be SQLite. You can use :memory: databases, but that will require shuttling data to disk manually. I suggest that you start with plain SQLite and only worry if you prove (repeat, PROVE) that DB is your bottleneck. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From phlip2005 at gmail.com Fri Feb 26 17:52:49 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 26 Feb 2010 14:52:49 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <6a1f738f-400b-458f-80f6-ac4cc097f2c2@f17g2000prh.googlegroups.com> On Feb 26, 7:58?am, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? If you had wall-to-wall unit tests, you could swap the database in incrementally ("Deprecation Refactor"). You would just add one database table, switch one client of one dictionary to use that table, pass all the tests, and integrate. Repeat until nobody uses the dicts, then trivially retire them. If you don't have unit tests, then you have a bigger problem than memory requirements. (You can throw $50 hardware at that!) -- Phlip http://penbird.tumblr.com/ From rurpy at yahoo.com Fri Feb 26 18:19:24 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 26 Feb 2010 15:19:24 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> Message-ID: <121bb934-6d62-482a-a5c2-848668ce237d@q16g2000yqq.googlegroups.com> On Feb 26, 2:21?pm, qtrimble wrote: > On Feb 26, 4:14?pm, OdarR wrote: > > > > below is just a sample. ?There are well over 500,000 lines that need > > > processed. > > > > wer1999001 > > > ? ? ? 31.2234 ? ? ?82.2367 > > > ? ? ? 37.9535 ? ? ?82.3456 > > > wer1999002 > > > ? ? ? 31.2234 ? ? ?82.2367 > > > ? ? ? 37.9535 ? ? ?82.3456 > > > did you try something as a working basis ? > > > Olivier > > Yes but it's very simple - > > fileIN = open(r"C:\testing.txt", "r") > > for line in fileIN: > ? ? year = line[3:7] > ? ? day = line[7:10] > ? ? print year, day > > This is good since i can get the year and day of year into a variable > but I haven't gotten any further. How about something like (untested): for line in fileIN: if line.startswith ("wer"): year = line[3:7] day = line[7:10] else: print "%s-%s %s" % (year, day, line.strip()) You can adjust the details as needed... From maygeo at netplus.ch Fri Feb 26 18:32:27 2010 From: maygeo at netplus.ch (Raphael Mayoraz) Date: Fri, 26 Feb 2010 15:32:27 -0800 Subject: Variable definition Message-ID: <4B885A0B.9040705@netplus.ch> Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in varDic.iteritems(): 'myPrefix' + key = value I know this is illegal, but there must be a trick somewhere. Thanks, Raphael From aleksandr.goretoy at gmail.com Fri Feb 26 18:48:56 2010 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Fri, 26 Feb 2010 17:48:56 -0600 Subject: loop through each line in a text file In-Reply-To: <4B884C26.8010605@optimum.net> References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> <4B884C26.8010605@optimum.net> Message-ID: I smell homework -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Feb 26 18:58:54 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Feb 2010 10:58:54 +1100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> <87635k41kd.fsf@benfinney.id.au> <8777b981-6ca8-49b2-93d8-4b37b2f99b79@k17g2000yqb.googlegroups.com> Message-ID: <87pr3r35xd.fsf@benfinney.id.au> Joan Miller writes: > On 26 feb, 12:35, Ben Finney wrote: > > A common convention is to have a ?README? text file, written in > > reStructuredText for rendering to various output formats as part of > > the documentation. You could then have the ?setup.py? program read > > the contents of that file and use it (or a slice of it) for the > > package description. > I get the 'README.txt' file to get the long description but I use the > docstring because each package should include a short desciption about > it. I keep both in the same file: ===== README ===== FooBar, a library for spangulation. The FooBar library provides thribbles which can be easily frobnicated for spangulation in a sntandard manner. Other spangulation libraries are far less weebly than this one, which is the choice of discerning grognards everywhere. ===== Then, the description fields are derived by splitting the file's contents on the first paragraph break: ===== from distutils.core import setup readme_file = open("README") short_description, long_description = ( d.strip() for d in readme_file.read().split(u'\n\n', 1)) setup( # ? description=short_description, long_description=long_description, # ? ) ===== -- \ ?Some forms of reality are so horrible we refuse to face them, | `\ unless we are trapped into it by comedy. To label any subject | _o__) unsuitable for comedy is to admit defeat.? ?Peter Sellers | Ben Finney From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 19:00:32 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 13:00:32 +1300 Subject: A more specific query ... References: Message-ID: <4B8860A0.6050600@auckland.no.spam.ac.nz> The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not occur with Python 2.5 and the previous PyQt I was using (4.5, I think), it seems that something has changed either with Python 2.6 or with PyQt 4.7. It would be very nice to learn how to fix this without renaming directories, since I use Matlab frequently. Gib From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 19:01:11 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 13:01:11 +1300 Subject: A more specific query ... References: Message-ID: The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not occur with Python 2.5 and the previous PyQt I was using (4.5, I think), it seems that something has changed either with Python 2.6 or with PyQt 4.7. It would be very nice to learn how to fix this without renaming directories, since I use Matlab frequently. Gib From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 19:02:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 00:02:40 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <4b88611f$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > Reminiscent of: > > mov AX,BX ; Move the contents of BX into AX That's a *good* comment, because without it most English-speaking people would assume you were moving the contents of AX into BX. > And, yes, I've actually seen that as well as: > > ; This is a comment Which might be a good comment, if it were part of an unfamiliar file format where the reader were not expected to know what is a comment and what is significant. For instance, I've seen similar comments at the top of config files. However, I'm pretty sure that a comment like this is inexcusable: x = x + 1 # Add one to x. -- Steven From routb3d at gmail.com Fri Feb 26 19:06:56 2010 From: routb3d at gmail.com (Routb3d) Date: Fri, 26 Feb 2010 16:06:56 -0800 (PST) Subject: importing libraries not working 2.6.4 Message-ID: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. I have tried adjusting environment variables as well as putting the files directly in the search path of Python.. Python still returns this.. Any ideas? >>> import sys >>> sys.path ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ \site-packages'] >>> import cv Traceback (most recent call last): File "", line 1, in import cv ImportError: DLL load failed: The specified module could not be found. Any help would be greatly appreciated. From rhodri at wildebst.demon.co.uk Fri Feb 26 19:15:22 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 27 Feb 2010 00:15:22 -0000 Subject: Variable definition References: Message-ID: On Fri, 26 Feb 2010 23:32:27 -0000, Raphael Mayoraz wrote: > I'd like to define variables with some specific name that has a common > prefix. Why? No seriously, how do you think this is going to solve whatever problem you clearly think it will solve? -- Rhodri James *-* Wildebeeste Herder to the Masses From alfps at start.no Fri Feb 26 19:22:24 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 27 Feb 2010 01:22:24 +0100 Subject: Variable definition In-Reply-To: References: Message-ID: * Raphael Mayoraz: > Hello, > > I'd like to define variables with some specific name that has a common > prefix. > Something like this: > > varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} > for key, value in varDic.iteritems(): > 'myPrefix' + key = value > > I know this is illegal, but there must be a trick somewhere. In general you'll IMHO be better off with the variables as attributes of an object. If you want them to be modifiable then you can do class Whatever: pass myPrefix = Whatever() myPrefix.a = 'a' myPrefix.b = 'b' myPrefix.c = 'c' If you want them to be sort of constants (weasel words intentional) then you might do (Python 3.x) -- disclaimer: off-the-cuff & I'm not sure if that function is called 'namedtuple' but I think you'll find it anyway -- import collections Color = namedtuple( "Color", "red green blue" ) myPrefix = Color( 'a', 'b', 'c' ) Cheers & hth., - Alf From rami.chowdhury at gmail.com Fri Feb 26 19:30:54 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 26 Feb 2010 16:30:54 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> Message-ID: <201002261630.54323.rami.chowdhury@gmail.com> On Friday 26 February 2010 16:06:56 Routb3d wrote: > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. > > I have tried adjusting environment variables as well as putting the > files directly in the search path of Python.. Python still returns > this.. Any ideas? Where are you expecting the cv module / package to be? It's certainly not in the standard library -- at least not in my install of Python 2.6.4... > > >>> import sys > >>> sys.path > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ > \site-packages'] > > >>> import cv > > Traceback (most recent call last): > File "", line 1, in > import cv > ImportError: DLL load failed: The specified module could not be found. > > > Any help would be greatly appreciated. ---- Rami Chowdhury "Strangers are just friends who haven't had enough gin." -- Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From aleksandr.goretoy at gmail.com Fri Feb 26 19:41:43 2010 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Fri, 26 Feb 2010 18:41:43 -0600 Subject: Variable definition In-Reply-To: References: Message-ID: On Fri, Feb 26, 2010 at 6:22 PM, Alf P. Steinbach wrote: > * Raphael Mayoraz: > >> Hello, >> >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >> for key, value in varDic.iteritems(): >> 'myPrefix' + key = value >> >> I know this is illegal, but there must be a trick somewhere. >> > > In general you'll IMHO be better off with the variables as attributes of an > object. > > If you want them to be modifiable then you can do > > class Whatever: pass > > myPrefix = Whatever() > myPrefix.a = 'a' > myPrefix.b = 'b' > myPrefix.c = 'c' > > If you want them to be sort of constants (weasel words intentional) then > you might do (Python 3.x) -- disclaimer: off-the-cuff & I'm not sure if > that function is called 'namedtuple' but I think you'll find it anyway -- > > import collections > > Color = namedtuple( "Color", "red green blue" ) > myPrefix = Color( 'a', 'b', 'c' ) > > > Cheers & hth., > > - Alf > > -- > http://mail.python.org/mailman/listinfo/python-list > you can use setattr to do your bidding for setting variable like this. That is how I've been able to do it. Not sure if its the best solution, but it is a solution. I just don't know how to use setattr without it being in a class. >>> class stuff(object): ... def __init__(self): ... pass ... def duuit(self,abc): ... for k,v in abc.items(): ... setattr(self,"prefix_%s"%k,v) ... >>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >>> abc=stuff() >>> abc.duuit(varDic) >>> dir(abc) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'duuit', 'prefix_blue', 'prefix_green', 'prefix_red'] >>> -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From pistacchio at gmail.com Fri Feb 26 19:46:10 2010 From: pistacchio at gmail.com (pistacchio) Date: Fri, 26 Feb 2010 16:46:10 -0800 (PST) Subject: random.gauss: range References: Message-ID: <7a49b554-2b53-4878-8150-89fafba210e9@y17g2000yqd.googlegroups.com> thanks, betadistribute did the work... and i learned a new thing! On 26 Feb, 22:56, Robert Kern wrote: > On 2010-02-26 15:26 PM, pistacchio wrote: > > > hi, > > i'm trying the random.gauss function. can anyone explain how to get a > > number between a given range? > > You don't. The Gaussian distribution has infinite range. The best you can do > with the standard library is to keep sampling until you get a number inside your > desired range. If you aren't careful about your choice of parameters, this could > waste a lot of time. > > > like, from 0 to 20 with an average of > > 10? and how to determine the "steep" of the curve? i've never studied > > it, so mu and sigma don't really tell me a thing. > > Study it: > > ? ?http://en.wikipedia.org/wiki/Normal_distribution > > mu is the mean, the location of the central peak. sigma is the standard > deviation, which controls the width of the peak. Larger sigma means wider and > shorter peak. > > You may want another distribution, like random.betavariate(): > > ? ?http://en.wikipedia.org/wiki/Beta_distribution > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco From python at rcn.com Fri Feb 26 19:46:21 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Feb 2010 16:46:21 -0800 (PST) Subject: random.gauss: range References: Message-ID: <1cb0bf77-a539-41ff-89f3-b55e423a1b32@b7g2000pro.googlegroups.com> On Feb 26, 1:26?pm, pistacchio wrote: > hi, > i'm trying the random.gauss function. can anyone explain how to get a > number between a given range? like, from 0 to 20 with an average of > 10? and how to determine the "steep" of the curve? i've never studied > it, so mu and sigma don't really tell me a thing. Try random.randrange() and random.triangular(). They are both easy to use and do not require you to enter parameters that you don't understand. FWIW, mu and sigma refer to the average and standard deviation of a normal distribution. Raymond From john at castleamber.com Fri Feb 26 19:47:26 2010 From: john at castleamber.com (John Bokma) Date: Fri, 26 Feb 2010 18:47:26 -0600 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <87635j4i8x.fsf@castleamber.com> Steven D'Aprano writes: > On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX > > > That's a *good* comment, because without it most English-speaking people > would assume you were moving the contents of AX into BX. Eh? It's a bad comment, it's of the same quality as: > x = x + 1 # Add one to x. You think the former is good because (I guess) you are not familiar with the language. The same reason why beginners comment their code like in your example. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From python at mrabarnett.plus.com Fri Feb 26 19:54:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Feb 2010 00:54:53 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4b88611f$0$27844$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B886D5D.4080908@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX > > > That's a *good* comment, because without it most English-speaking people > would assume you were moving the contents of AX into BX. > [snip] If you're reading and/or writing at assembly language level then you should know what it does anyway! The assembly languages of virtually all the processors that I've come across put the destination first, eg. x86: SUB AX,BX MOV AX,BX which does: AX := AX - BX AX := BX and ARM: SUB R0,R1,R2 MOV R0,R1 which does: R0 := R1 - R2 R0 := R1 The only assembly language I know of which does it the other way round is 68x00: SUB D0,D1 MOVE D0,D1 which does: D1 := D1 - D0 D1 := D0 I know which I prefer! :-) From alfps at start.no Fri Feb 26 20:10:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 27 Feb 2010 02:10:26 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: * MRAB: > Steven D'Aprano wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >> >> >> That's a *good* comment, because without it most English-speaking >> people would assume you were moving the contents of AX into BX. >> > [snip] > If you're reading and/or writing at assembly language level then you > should know what it does anyway! > > The assembly languages of virtually all the processors that I've come > across put the destination first, eg. x86: > > SUB AX,BX > MOV AX,BX > > which does: > > AX := AX - BX > AX := BX > A bit off-topic, but there are /two/ main syntaxes for x86 assembly, namely Intel syntax (the above syntax, used by MASM, old TASM etc.) and AT&T syntax. C:\test> echo int main(){ int x = 42; } >blah.cpp C:\test> g++ blah.cpp -S -masm=intel C:\test> type blah.s | find "42" mov DWORD PTR [ebp-4], 42 C:\test> g++ blah.cpp -S -masm=att C:\test> type blah.s | find "42" movl $42, -4(%ebp) C:\test> _ Personally I find the AT&T syntax very hard to read. All those percent signs hurt my eyes... > and ARM: > > SUB R0,R1,R2 > MOV R0,R1 > > which does: > > R0 := R1 - R2 > R0 := R1 > > The only assembly language I know of which does it the other way round > is 68x00: > > SUB D0,D1 > MOVE D0,D1 > > which does: > > D1 := D1 - D0 > D1 := D0 > > I know which I prefer! :-) Cheers, - Alf From jjposner at optimum.net Fri Feb 26 20:15:16 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 26 Feb 2010 20:15:16 -0500 Subject: Variable definition In-Reply-To: <4B885A0B.9040705@netplus.ch> References: <4B885A0B.9040705@netplus.ch> Message-ID: <4B887224.2080805@optimum.net> On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: > Hello, > > I'd like to define variables with some specific name that has a common > prefix. > Something like this: > > varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} > for key, value in varDic.iteritems(): > 'myPrefix' + key = value > No trick, just swap a new key-value pair for each existing pair: for key, value in varDic.iteritems(): varDic[myPrefix + key] = value del varDict[key] Just make sure that *myPrefix* isn't an empty string! -John From rami.chowdhury at gmail.com Fri Feb 26 21:12:23 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 26 Feb 2010 18:12:23 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> <201002261630.54323.rami.chowdhury@gmail.com> Message-ID: <201002261812.23265.rami.chowdhury@gmail.com> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: > Thanks for the reply. > > I tried putting the files from > > C:\OpenCV2.0\Python2.6\Lib > > too > > C:\Python26\Lib\site-packages > > and Python still wont import.. > > I adjusted the environment variables to try and import maya.standalone but > no dice on that either. > Sorry, you've still not told me where you expect it to be. Could you let us know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? > > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury wrote: > > On Friday 26 February 2010 16:06:56 Routb3d wrote: > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. > > > > > > I have tried adjusting environment variables as well as putting the > > > files directly in the search path of Python.. Python still returns > > > this.. Any ideas? > > > > Where are you expecting the cv module / package to be? It's certainly not > > in > > the standard library -- at least not in my install of Python 2.6.4... > > > > > >>> import sys > > > >>> sys.path > > > > > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ > > > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', > > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- > > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ > > > \site-packages'] > > > > > > >>> import cv > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > > > > import cv > > > > > > ImportError: DLL load failed: The specified module could not be found. > > > > > > > > > Any help would be greatly appreciated. > > > > ---- > > Rami Chowdhury > > "Strangers are just friends who haven't had enough gin." -- Howdle's > > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) ---- Rami Chowdhury "Ninety percent of everything is crap." -- Sturgeon's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From no.email at nospam.invalid Fri Feb 26 21:16:25 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 26 Feb 2010 18:16:25 -0800 Subject: Dictionary or =?utf-8?Q?Database=E2=80=94Please?= advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <7xeik7h18m.fsf@ruckus.brouhaha.com> Jeremy writes: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? What are you trying to do? Yes, a database would let you use disk instead of ram, but the slowdown might be intolerable depending on the access pattern. You really have to consider what the whole application is up to, and what the database is doing for you. It might be imposing a high overhead to create benefits (e.g. transaction isolation) that you're not actually using. Somehow I've managed to do a lot of programming on large datasets without ever using databases very much. I'm not sure that's a good thing; but anyway, a lot of times you can do better with externally sorted flat files, near-line search engines, etc. than you can with databases. If the size of your data is fixed or is not growing too fast, and it's larger than your computer's memory by just a moderate amount (e.g. you have a 2GB computer and 3GB of data), the simplest approach may be to just buy a few more ram modules and put them in your computer. From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 21:21:04 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 02:21:04 GMT Subject: =?windows-1251?q?Re=3A_Dictionary_or_Database=97Please?= advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: <4b888190$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 21:56:47 +0100, Patrick Sabin wrote: >> Shelve looks like an interesting option, but what might pose an issue >> is that I'm reading the data from a disk instead of memory. I didn't >> mention this in my original post, but I was hoping that by using a >> database it would be more memory efficient in storing data in RAM so I >> wouldn't have to read from (or swap to/from) disk. > > A database usually stores data on disk and not in RAM. However you could > use sqlite with :memory:, so that it runs in RAM. The OP started this thread with: "I have lots of data that I currently store in dictionaries. However, the memory requirements are becoming a problem." So I'm amused that he thinks the solution to running out of memory is to run the heavy overhead of a database entirely in memory, instead of lightweight dicts :) My advice is, first try to optimize your use of dicts. Are you holding onto large numbers of big dicts that you don't need? Are you making unnecessary copies? If so, fix your algorithms. If you can't optimize the dicts anymore, then move to a proper database. Don't worry about whether it is on-disk or not, databases tend to be pretty fast regardless, and it is better to run your application a little bit more slowly than to not run it at all because it ran out of memory halfway through processing the data. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 21:52:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 02:52:54 GMT Subject: random.gauss: range References: Message-ID: <4b888905$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 13:26:44 -0800, pistacchio wrote: > hi, > i'm trying the random.gauss function. can anyone explain how to get a > number between a given range? like, from 0 to 20 with an average of 10? That's not what a Gaussian distribution does. It has an infinite range. Are you sure you want a Gaussian, and not a uniform distribution or a triangular distribution? You could pin the values to the appropriate range: def pinned_gaussian(a, b, mu, sigma): """Return a Gaussian random number pinned to [a, b].""" return min(b, max(a, random.gauss(mu, sigma))) but that will distort the randomness slightly: you will have a slight excess of values equal to a and b than you otherwise might expect. You might not care, though, particularly if the sigma is very small relative to the minimum and maximum you want. Alternatively, you could use this approach: def truncated_gauss(a, b, mu, sigma): """Return a random number from a truncated Gaussian distribution.""" while 1: x = random.gauss(mu, sigma) if a <= x <= b: return x > and how to determine the "steep" of the curve? i've never studied it, so > mu and sigma don't really tell me a thing. mu is the average -- in your example above, mu would be 10. sigma is the standard deviation of the random variable. It tells you how much the random variable actually varies: if sigma is close to zero, most of the numbers will be close to mu and the graph will look like a spike; if sigma is large, it will be very broad and flat. Statistically, the following rules apply: 68% of the numbers will be between (mu - sigma) and (mu + sigma). 95% of the numbers will be between (mu - 2*sigma) and (mu + 2*sigma). 99.7% of the numbers will be between (mu - 3*sigma) and (mu + 3*sigma). (the percentages are approximate, not exact). So you could get a reasonable approximation to a normal distribution truncated between 0 and 20 with: truncated_gauss(0, 20, 10, 10.0/3) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 22:15:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 03:15:47 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> Message-ID: <4b888e62$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 18:47:26 -0600, John Bokma wrote: > Steven D'Aprano writes: > >> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >> >> >> That's a *good* comment, because without it most English-speaking >> people would assume you were moving the contents of AX into BX. > > Eh? It's a bad comment, it's of the same quality as: > >> x = x + 1 # Add one to x. > > You think the former is good because (I guess) you are not familiar with > the language. The same reason why beginners comment their code like in > your example. Well, in the second example, x+1 could not possibly be anything other than adding one to x in any language, programming or human: using "+" for addition is close enough to universal these days. Unless x is some fancy object that plays operator overloading tricks, then what else could x+1 be? On the other hand, mv AX,BX is not only ambiguous but in the example given the move occurs in the counter-intuitive direction, at least for English-speakers and probably most speakers of European languages. So even an experienced coder might like the reminder that this specific assembly language moves things backwards compared to his intuition, or compared to the way the rest of the language does things. Admittedly an experienced coder might be so used to that syntax that he no longer needs the comment, in which case he might find it unnecessary. But comments aren't written for the benefit of people who find it obvious. They're written for everyone else. ANY comment could be dismissed as unnecessary for somebody who is so familiar with the language and code in question that it is obvious what it is doing. Also, some assemblies perform the move in different directions according to the arguments. So you might have: mv AX,BX ; move contents of BX into AX mv @CX,DX ; move contents of @CX into DX Horrible, yes, but apparently some assembly languages did something like that. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 22:20:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 03:20:18 GMT Subject: Variable definition References: <4B885A0B.9040705@netplus.ch> Message-ID: <4b888f72$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote: > On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >> Hello, >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in >> varDic.iteritems(): 'myPrefix' + key = value >> >> > No trick, just swap a new key-value pair for each existing pair: > > for key, value in varDic.iteritems(): > varDic[myPrefix + key] = value > del varDict[key] > > Just make sure that *myPrefix* isn't an empty string! How does that answer the original poster's question? Admittedly, your solution is the Right Way To Do It, but what the OP wants is to go from a dict {'spam': 42} to a named variable myPrefixspam = 42, which is a totally bogus thing to do, but incredibly common among n00bs and refugees from horrible languages that allow that sort of abomination. -- Steven From python at mrabarnett.plus.com Fri Feb 26 22:25:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Feb 2010 03:25:47 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4b888e62$0$27844$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B8890BB.8080902@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 26 Feb 2010 18:47:26 -0600, John Bokma wrote: > >> Steven D'Aprano writes: >> >>> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >>> >>>> Reminiscent of: >>>> >>>> mov AX,BX ; Move the contents of BX into AX >>> >>> That's a *good* comment, because without it most English-speaking >>> people would assume you were moving the contents of AX into BX. >> Eh? It's a bad comment, it's of the same quality as: >> >>> x = x + 1 # Add one to x. >> You think the former is good because (I guess) you are not familiar with >> the language. The same reason why beginners comment their code like in >> your example. > > Well, in the second example, x+1 could not possibly be anything other > than adding one to x in any language, programming or human: using "+" for > addition is close enough to universal these days. Unless x is some fancy > object that plays operator overloading tricks, then what else could x+1 > be? > > On the other hand, mv AX,BX is not only ambiguous but in the example > given the move occurs in the counter-intuitive direction, at least for > English-speakers and probably most speakers of European languages. So > even an experienced coder might like the reminder that this specific > assembly language moves things backwards compared to his intuition, or > compared to the way the rest of the language does things. > > Admittedly an experienced coder might be so used to that syntax that he > no longer needs the comment, in which case he might find it unnecessary. > But comments aren't written for the benefit of people who find it > obvious. They're written for everyone else. ANY comment could be > dismissed as unnecessary for somebody who is so familiar with the > language and code in question that it is obvious what it is doing. > > Also, some assemblies perform the move in different directions according > to the arguments. So you might have: > > mv AX,BX ; move contents of BX into AX > mv @CX,DX ; move contents of @CX into DX > > Horrible, yes, but apparently some assembly languages did something like > that. > Ah, yes, "apparently". That's like saying "someone down the pub told me...". ;-) From jjposner at optimum.net Fri Feb 26 22:33:53 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 26 Feb 2010 22:33:53 -0500 Subject: Variable definition In-Reply-To: <4b888f72$0$27844$c3e8da3@news.astraweb.com> References: <4B885A0B.9040705@netplus.ch> <4b888f72$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B8892A1.7020902@optimum.net> On 2/26/2010 10:20 PM, Steven D'Aprano wrote: > On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote: > >> On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >>> Hello, >>> >>> I'd like to define variables with some specific name that has a common >>> prefix. >>> Something like this: >>> >>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in >>> varDic.iteritems(): 'myPrefix' + key = value >>> >>> >> No trick, just swap a new key-value pair for each existing pair: >> >> for key, value in varDic.iteritems(): >> varDic[myPrefix + key] = value >> del varDict[key] >> >> Just make sure that *myPrefix* isn't an empty string! > > How does that answer the original poster's question? > > Admittedly, your solution is the Right Way To Do It, but what the OP > wants is to go from a dict {'spam': 42} to a named variable myPrefixspam > = 42, which is a totally bogus thing to do, but incredibly common among > n00bs and refugees from horrible languages that allow that sort of > abomination. Yup, I misinterpreted the OP's intent. I guess my mind just couldn't encompass the enormity of his intended transgression. -John From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 22:33:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 03:33:57 GMT Subject: Variable definition References: Message-ID: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 15:32:27 -0800, Raphael Mayoraz wrote: > Hello, > > I'd like to define variables with some specific name that has a common > prefix. > Something like this: > > varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} > for key, value in varDic.iteritems(): > 'myPrefix' + key = value > > I know this is illegal, but there must be a trick somewhere. The Right answer is: Don't do that. How can you use a variable without knowing its name? Suppose you do this: for key, value in varDic.iteritems(): 'myPrefix_' + key = value and then later you want: print myPrefix_blue But hang on. How could you possibly know it is called myPrefix_blue and not myPrefix_cyan or myPrefix_turquoise? You can't possibly know, so in general defining a named variable is useless. What you want instead is: some_colour = 'blue' # get this at runtime print varDic[some_colour] You don't even need the myPrefix, but if you really want it: for key, value in varDic.iteritems(): varDic['myPrefix_' + key] = value del varDic[key] some_colour = 'blue' # get this at runtime print varDic['myPrefix_' + some_colour] or any one of a million variations on this idea. For some very, very rare situations you might need to programatically define variables. The right way to do that is: globals()['myPrefix_turquoise'] = 42 or setattr(module, 'myPrefix_turquoise'] = 42 or even: exec "'myPrefix_turquoise' = 42" but if you are thinking of using that last one with data coming from an untrusted user (and nearly all users are untrusted!), then DON'T. That is a huge security hole. And it's also very slow. -- Steven From tundra at tundraware.com Fri Feb 26 22:51:17 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 26 Feb 2010 21:51:17 -0600 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2/26/2010 9:25 PM, MRAB wrote: > Steven D'Aprano wrote: >> On Fri, 26 Feb 2010 18:47:26 -0600, John Bokma wrote: >> >>> Steven D'Aprano writes: >>> >>>> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >>>> >>>>> Reminiscent of: >>>>> >>>>> mov AX,BX ; Move the contents of BX into AX >>>> >>>> That's a *good* comment, because without it most English-speaking >>>> people would assume you were moving the contents of AX into BX. >>> Eh? It's a bad comment, it's of the same quality as: >>> >>>> x = x + 1 # Add one to x. >>> You think the former is good because (I guess) you are not familiar with >>> the language. The same reason why beginners comment their code like in >>> your example. >> >> Well, in the second example, x+1 could not possibly be anything other >> than adding one to x in any language, programming or human: using "+" >> for addition is close enough to universal these days. Unless x is some >> fancy object that plays operator overloading tricks, then what else >> could x+1 be? >> >> On the other hand, mv AX,BX is not only ambiguous but in the example >> given the move occurs in the counter-intuitive direction, at least for >> English-speakers and probably most speakers of European languages. So >> even an experienced coder might like the reminder that this specific >> assembly language moves things backwards compared to his intuition, or >> compared to the way the rest of the language does things. >> >> Admittedly an experienced coder might be so used to that syntax that >> he no longer needs the comment, in which case he might find it >> unnecessary. But comments aren't written for the benefit of people who >> find it obvious. They're written for everyone else. ANY comment could >> be dismissed as unnecessary for somebody who is so familiar with the >> language and code in question that it is obvious what it is doing. >> >> Also, some assemblies perform the move in different directions >> according to the arguments. So you might have: >> >> mv AX,BX ; move contents of BX into AX >> mv @CX,DX ; move contents of @CX into DX >> >> Horrible, yes, but apparently some assembly languages did something >> like that. >> > Ah, yes, "apparently". That's like saying "someone down the pub told > me...". ;-) It's interesting that my silly example raised this amount of commentary. My general view about all this is that comments should be written on the assumption that the reader knows the language in question. It is not the purpose of a comment to provide a tutorial on the language (unless you're actually writing a tutorial program). Rather, a comment should illuminate the *logic* of the activity by either amplifying, clarifying, or otherwise providing a rationale' for the code in question. Demanding that programmers provide comments about the syntax and semantics of the language is - to me - absurd. For example, some time ago, I was doing some programming with embedded PIC-based hardware. The comments for that code are intended to illuminate how the *hardware* was being exploited, not how to use PIC asm: ... scan: incf current_col,F ; pickup next column to scan movlw MAX_COL+1 ; if current_col > MAX_COL then subwf current_col,W ; we just did last column, so start over btfss STATUS,Z ; zero means we need to start over goto key_scan ; nope, go look for key hits clrf current_col ; yes, reinit column counter goto scan ... The only possible exception to this I can think of is when there is some non-obvious side-effect (i.e. language and/or hardware is "misfeatured"): mov A,B ; Moving A into B also will also arm ; the nuclear warhead if the CPU is ; hotter than 110C -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From rami.chowdhury at gmail.com Fri Feb 26 22:53:53 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 26 Feb 2010 19:53:53 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> <201002261630.54323.rami.chowdhury@gmail.com> <201002261812.23265.rami.chowdhury@gmail.com> Message-ID: <06689ACA-B76B-4558-B121-A175CEB50C24@gmail.com> On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote: > C:\OpenCV2.0\Python2.6\Lib\site-packages > > no .py files here.. > > cv.pyd > libcv.dll.a > > > C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv > > _init_.py > matlan_syntax.py > adaptors.py > cv.py > It looks to me like 'opencv' is structured as a package, from which you should be able to import and work with Python libraries. Have you tried putting the above site-packages directory in sys.path: import sys; sys.path.append('C:\\OpenCV2.0\\Python2.6\\Lib\\site-packages') and then doing: from opencv import cv ? > Did I still need to compile this even though it was a win 32 installer? I don't think so, no -- AFAIK the .pyd files are compiled CPython extension modules, so it looks like they're all compiled for you. ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury wrote: > On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: > > Thanks for the reply. > > > > I tried putting the files from > > > > C:\OpenCV2.0\Python2.6\Lib > > > > too > > > > C:\Python26\Lib\site-packages > > > > and Python still wont import.. > > > > I adjusted the environment variables to try and import maya.standalone but > > no dice on that either. > > > > Sorry, you've still not told me where you expect it to be. Could you let us > know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? > > > > > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury > wrote: > > > On Friday 26 February 2010 16:06:56 Routb3d wrote: > > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. > > > > > > > > I have tried adjusting environment variables as well as putting the > > > > files directly in the search path of Python.. Python still returns > > > > this.. Any ideas? > > > > > > Where are you expecting the cv module / package to be? It's certainly not > > > in > > > the standard library -- at least not in my install of Python 2.6.4... > > > > > > > >>> import sys > > > > >>> sys.path > > > > > > > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ > > > > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', > > > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- > > > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ > > > > \site-packages'] > > > > > > > > >>> import cv > > > > > > > > Traceback (most recent call last): > > > > File "", line 1, in > > > > > > > > import cv > > > > > > > > ImportError: DLL load failed: The specified module could not be found. > > > > > > > > > > > > Any help would be greatly appreciated. > > > > > > ---- > > > Rami Chowdhury > > > "Strangers are just friends who haven't had enough gin." -- Howdle's > > > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) > > > ---- > Rami Chowdhury > "Ninety percent of everything is crap." -- Sturgeon's Law > 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Fri Feb 26 23:02:35 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 26 Feb 2010 23:02:35 -0500 Subject: Docstrings considered too complicated In-Reply-To: <4b88611f$0$27844$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <20100226230235.fcbd4011.darcy@druid.net> On 27 Feb 2010 00:02:40 GMT Steven D'Aprano wrote: > On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > > mov AX,BX ; Move the contents of BX into AX > > That's a *good* comment, because without it most English-speaking people > would assume you were moving the contents of AX into BX. But it isn't English, it's assembler. If someone doesn't know that assembler they have no business trying to work in it. A good comment would be "move number of sheep into accumulator" or something equally as descriptive. A person who knows the assembler knows that the BX register will be copied (not "moved" btw) into the AX register. What they want from the comment is some idea why. Yes, understanding assembler is hard. You aren't going to learn it from the comments. -- 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 cs at zip.com.au Fri Feb 26 23:11:15 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 27 Feb 2010 15:11:15 +1100 Subject: How to end TCP socket data while using readline()? In-Reply-To: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> Message-ID: <20100227041115.GA24869@cskk.homeip.net> On 26Feb2010 10:39, Arjun wrote: | Hi, I have a small script that runs a TCP server. A client connects to | this server and transmits a stored file line-by-line, and then waits | for a confirmation "done". However, when I run them the first loop | never really ends -- as the TCP server keeps expecting more data. I am | using a file-like-object, and so somehow I have to communicate to the | server that it is the end-of-file. | | here is some server code | | sock1.bind(('', port)) | print "Listening at port: ", port | sock1.listen(1) # listening socket | (conn, addr) = sock1.accept() # connected socket | print 'Client (localhost) port: ', addr[1] | | cf = conn.makefile('r',0) # file like obj for socket [...] | print 'close' | cf.flush() | cf.close() | sfp.close() [...] Too many files. It's not that hard! Or shouldn't be. | So what I am wondering is: | | 1. Using a file-like object means that the socket becomes uni- | directional, until the mode of the file object is changed from 'r' to | 'w' (or vice versa). This seems inefficient, and rather unPythonesque. | Can somebody tell me if there is a more elegant way of receiving all | the lines from the client, and then sending a "done" message to the | client? Get the socket. It is a file descriptor (or in may be a python "socket" object with a file descriptor inside). Open _two_ "file" objects on it using from_file = os.fdopen(fd_of_socket, "r") to_file = os.fdopen(fd_of_socket, "w"). Use the same: print >>to_file, 'close' to_file.flush() method as you're using already. Read from to_file as needed. The same scheme should work in both server and client: Don't look for EOF, watch the input line flow. You might need to use readline() instead of the file-by-line iteration stuff, which I seem to recall has some sort of problem handing out the "latest" line. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It's better, when you're riding with someone you don't know so well, to stick to the inside line - it's easier to avoid the bits... - Barry Sheene From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 23:19:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 04:19:10 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b889d3d$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 00:54:53 +0000, MRAB wrote: > The assembly languages of virtually all the processors that I've come > across put the destination first, eg. x86: Incorrect. x86 assembly has two distinct syntax branches, "Intel syntax" (which is most common in the Windows world according to Wikipedia) and "AT&T syntax". See for example: http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Basic-Assembler-Syntax.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 23:22:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 04:22:39 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b889e0f$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 03:25:47 +0000, MRAB wrote: >> Also, some assemblies perform the move in different directions >> according to the arguments. So you might have: >> >> mv AX,BX ; move contents of BX into AX mv @CX,DX ; move contents of >> @CX into DX >> >> Horrible, yes, but apparently some assembly languages did something >> like that. >> > Ah, yes, "apparently". That's like saying "someone down the pub told > me...". ;-) Not down the pub, somebody on Usenet. Are you trying to suggest that people might propagate falsehoods on the Internet??? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 23:23:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 04:23:26 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b889e3d$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 21:51:17 -0600, Tim Daneliuk wrote: > The only possible exception to this I can think of is when there is some > non-obvious side-effect (i.e. language and/or hardware is > "misfeatured"): > > mov A,B ; Moving A into B also will also arm > ; the nuclear warhead if the CPU is > ; hotter than 110C I had an embedded device that did *just that*, but only on Tuesdays. -- Steven From davea at ieee.org Fri Feb 26 23:56:20 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 26 Feb 2010 23:56:20 -0500 Subject: Variable definition In-Reply-To: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> References: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B88A5F4.2020707@ieee.org> Steven D'Aprano wrote: > > > for key, value in varDic.iteritems(): > varDic['myPrefix_' + key] = value > del varDic[key] > > Watch out if any of the existing values already startswith 'myPrefix' You can end up with trouble just as confusing as if 'myPrefix' is an empty string DaveA From wuwei23 at gmail.com Sat Feb 27 00:31:47 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 26 Feb 2010 21:31:47 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: Mensanator wrote: > "You're" not getting the point. If every link has to be accompanied by a summary of all of the information at the end of it, what point is there to linking? (Programmers are the _only_ people I know of who complain about the arduousness of tasks like typing quotes or clicking on links...) From g.bogle at auckland.no.spam.ac.nz Sat Feb 27 01:03:53 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 19:03:53 +1300 Subject: A more specific query ... References: <4B8860A0.6050600@auckland.no.spam.ac.nz> Message-ID: Dennis Lee Bieber wrote: > On Sat, 27 Feb 2010 13:00:32 +1300, Gib Bogle > declaimed the following in > gmane.comp.python.general: > >> The PyQt4 problem results from having copies of the Qt DLLs in directories that >> are in the PATH, as Doug Bell discovered. In my case I have two programs that >> use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can >> import the PyQt4 modules. >> > And where are those PATH entries relative to the Python ones? You > may have to add the Python location to PATH /before/ the AMD and Matlab > entries. {I routinely -- once a year or so -- copy the PATH environment > variable to an editor, and reorder it so that the stuff I use most > occurs earlier in the list} Well diagnosed! The others were all system environment variables, while the PyQt4 PATH is mine, and therefore it was placed at the end. I've taken the AMD and Matlab PATH entries out of the system list and put them after PyQt4 in my PATH. Now peace and harmony are restored to my Python world. Thanks Gib From raghu521987 at gmail.com Sat Feb 27 02:28:02 2010 From: raghu521987 at gmail.com (raghumech) Date: Fri, 26 Feb 2010 23:28:02 -0800 (PST) Subject: mobiletrickS Message-ID: <96e8177b-d03f-4aed-9a26-1001c0f02890@b36g2000pri.googlegroups.com> FREE CALL TO ANYWHERE ...... http://mobiletricks777.blogspot.com/ From darnzen at gmail.com Sat Feb 27 02:40:02 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 23:40:02 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> <7uqa0eF95lU1@mid.uni-berlin.de> <7uqamjFd2vU2@mid.uni-berlin.de> Message-ID: On Feb 26, 10:20?am, "Diez B. Roggisch" wrote: > Am 26.02.10 17:08, schrieb Diez B. Roggisch: > > > > > > > Am 26.02.10 16:57, schrieb darnzen: > >> On Feb 26, 9:41 am, "Diez B. Roggisch" wrote: > >>> Am 26.02.10 16:32, schrieb darnzen: > > >>>> On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: > >>>>> Am 26.02.10 06:07, schrieb darnzen: > > >>>>>> Having an odd problem that I solved, but wondering if its the best > >>>>>> solution (seems like a bit of a hack). > > >>>>>> First off, I'm using an external DLL that requires static callbacks, > >>>>>> but because of this, I'm losing instance info. It could be import > >>>>>> related? It will make more sense after I diagram it: > > >>>>>> #Module main.py > >>>>>> from A import * > > >>>>>> class App: > >>>>>> def sperg(self): > >>>>>> self.a = A() > > >>>>>> app = App() > >>>>>> [main loop and such] > >>>>>> ----------------------------- > >>>>>> # Module A.py > >>>>>> import main > >>>>>> class Foo: > >>>>>> Selves=[] > >>>>>> def __init__(self): > >>>>>> Foo.Selves.append(self) > >>>>>> @staticmethod > >>>>>> def chum_callback(nType, nP): > >>>>>> # Need to access function / data in app instance > >>>>>> app.sperg(nP) > >>>>>> # Need to access func data in Foo > >>>>>> # I'm pulling 'self' ouf of list made in constructor > >>>>>> self = Foo.getSelf(nP) > > >>>>>> def getSelf(nP): > >>>>>> return self.Selves[nP] > > >>>>>> --------------------------------------------------------------------- > >>>>>> So basically I added a list of instances to the base class so I can > >>>>>> get at them from the staticmethod. > >>>>>> What's bothering me the most is I can't use the global app > >>>>>> instance in > >>>>>> the A.py module. > > >>>>>> How can I get at the app instance (currently I'm storing that along > >>>>>> with the class instance in the constructor)? > >>>>>> Is there another way to do this that's not such a hack? > > >>>>>> Sorry for the double / partial post :( > > >>>>> Can you show how you pass the staticmethod to the C-function? Is > >>>>> the DLL > >>>>> utilized by ctypes? > > >>>>> I don't see any reason you couldn't use a bound method, which would > >>>>> give > >>>>> you your self, instead relying on global state. > > >>>>> Diez > > >>>> __main__.K<< *facepalm* should of tried that! > > >>>> Yeah I'm using ctypes. The DLL callback set ups are as follows. The > >>>> local callback is in the App namespace (in this case, some callbacks > >>>> are in different modules as noted in OP), but still no access to self: > > >>>> #Function wrapper > >>>> A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ > >>>> POINTER(Data_s))(A.Callback) > > >>>> #DLL call to register the local callback function > >>>> DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > >>>> class A: > >>>> #Local callback function > >>>> @staticmethod > >>>> def Callback(hID, SubID, Data): > >>>> print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > >>>> print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > >>>> print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > >>>> print 'USING KEY GENERATED FROM hID, SubID' > >>>> pass > > >>>> I'm not sure why they need to be static callbacks, but the DLL doc's > >>>> say "when using object based languages, such as c++, callback > >>>> functions must be declared as static functions and not instance > >>>> methods", and I couldn't get it to work without setting it up that > >>>> way. I could probably have them all be "classless" functions, but with > >>>> 100's of these, my namespace would be polluted up the wazoo, and I'd > >>>> still have the problem that they wouldn't have access to instance > >>>> methods / properties. > > >>> The above code can't work with self, because you use > > >>> A.expCallback > > >>> which at best can of course be a classmethod. > > >>> You need to instead invoke DLLSetCallback with a bound method, like this > > >>> a = A() > >>> DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > >>> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of > >>> static functions is differently. If ctypes manages to get *some* > >>> callback passed, I'm 100% positive that it can pass *any* callable you > >>> like, including bound methods. > > >>> Diez > > >> Thinking about it some more, I believe I understand why it has to be > >> staticfunction. To use an bound method would require the wrapper to > >> include a reference to the instance as follows: > > >> A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ > >> POINTER(Data_s))(a.Callback) > > >> Since a = A(); a.foo() is really A.foo(self). The problem here is that > >> A is not a ctypes object and I can't change what arguments the DLL > >> uses in the callback in any case. Rewording my thoughts: a bound > >> method callback would require 'self' to be the first argument. I can > >> not make the DLL include 'self' as it doesn't know anything about the > >> objects in my program. Since I can't pass 'self', it has to be a > >> staticmethod. > > > No, that's not true. A bound method implictly knows about it self, and > > it's a callable. > > > What I guess is that you did the same mistake I did when I created that > > example - namely, not keeping a refernce to the bound method around. > > Ctypes will then garbage-collect the callback, which of course leads to > > all kinds of troubles. > > > Try this: > > > a = A() > > # keep this around > > bound_m = a.expCallback > > DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > AAAAHHRG, same error again. > > Of course, use > > DLLSetCallback(self.hID, A.SubID, EVENTID, bound_m) > > because the bound method changes with each time you create it. > > Sorry for the confusion. > > Diez Well, I got around this mess by putting all those static callbacks into a separate module in a new class. I set them up to call a bound method of that class which passes the arguments to the appropriate bound methods of other class instances. I just have to keep a little dict of the bound method callbacks when I register them with the class. I also found a simple trick for sharing globals between modules. Pretty simple, create an empty module, say shared.py, with only the pass statement in it. Then dynamically add properties to it such as shared.app = App(). Import shared into the modules that need access to app and done! Thanks for the help on this. Always learning! From quentel.pierre at wanadoo.fr Sat Feb 27 02:57:07 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Fri, 26 Feb 2010 23:57:07 -0800 (PST) Subject: Karrigell 3.0.4 published Message-ID: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Hi, A new version of the web framework Karrigell is on line The main changes are : - more robust session management in multi-threaded and multi-process environments - Unicode management in the HTMLTags module (HTML generation in Python) - Unicode management and error reports in Karrigell Templates (simple templating system) - more of MySQL : can be used for users database ; improved online management ; blog application - use of the WhizzyWig Javascript library for blog applications - make script caching and HTTP caching optional - the alias keys can be regular expressions for a more flexible url resolution - bug fix for default host configuration and for cookie expiry date Home page : http://karrigell.sourceforge.net Download : http://sourceforge.net/project/showfiles.php?group_id=67940 Google Group : http://groups.google.com/group/karrigell Cheers, Pierre From fabfake at fake.org Sat Feb 27 03:05:24 2010 From: fabfake at fake.org (Fabiano) Date: Sat, 27 Feb 2010 09:05:24 +0100 Subject: Updates about Tk Message-ID: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> Hi, I'm going to start my little journey into the Python's lands. I have already red the old posts about but I suppose this is an evolving topic. I have understood Tk is the default Python's GUI toolkit, I have also read that version 8.5 has native widgets and visual improvements. My question is: Are the new Tk comaprable with other toolkits(Qt, GTK,Wx?)? Does Tk lack other features compared to the Qt,GTK,Wx...? (Or: is there things you can't simply do with Tk?) Thanks in advance for replying From quentel.pierre at wanadoo.fr Sat Feb 27 03:21:55 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Sat, 27 Feb 2010 00:21:55 -0800 (PST) Subject: Karrigell 3.0.4 published References: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Message-ID: On 27 f?v, 08:57, Pierre Quentel wrote: > Hi, > > A new version of the web framework Karrigell is on line > > The main changes are : > - more robust session management in multi-threaded and multi-process > environments > - Unicode management in the HTMLTags module (HTML generation in > Python) > - Unicode management and error reports in Karrigell Templates (simple > templating system) > - more of MySQL : can be used for users database ; improved online > management ; blog application > - use of the WhizzyWig Javascript library for blog applications > - make script caching and HTTP caching optional > - the alias keys can be regular expressions for a more flexible url > resolution > - bug fix for default host configuration and for cookie expiry date > > Home page :http://karrigell.sourceforge.net > Download :http://sourceforge.net/project/showfiles.php?group_id=67940 > Google Group :http://groups.google.com/group/karrigell > > Cheers, > Pierre Oops ! wrong group, sorry. It's for c.l.p.announce From half.italian at gmail.com Sat Feb 27 03:26:08 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sat, 27 Feb 2010 00:26:08 -0800 (PST) Subject: Updates about Tk References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <699f7b37-e651-4d32-942c-28cff2e2e05d@z10g2000prh.googlegroups.com> > Are the new Tk comaprable with other toolkits(Qt, GTK,Wx?)? > Does Tk lack other features compared to the Qt,GTK,Wx...? > (Or: is there things you can't simply do with Tk?) > > Thanks in advance for replying tkinter is a good starting point. You can get some definite benefits going to wx or Qt. I guess it depends on how much experience you have creating GUIs. Choose the one you are comfortable with. From jkn_gg at nicorp.f9.co.uk Sat Feb 27 03:52:13 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Sat, 27 Feb 2010 00:52:13 -0800 (PST) Subject: Karrigell 3.0.4 published References: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Message-ID: Hi Pierre > Oops ! wrong group, sorry. It's for c.l.p.announce Well, I for one was happy to learn of this release here - thanks J^n From wuwei23 at gmail.com Sat Feb 27 04:00:00 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 27 Feb 2010 01:00:00 -0800 (PST) Subject: Signature-based Function Overloading in Python References: Message-ID: Michael Rudolf wrote: > In Java, Method Overloading is my best friend Guido wrote a nice article[1] on "multimethods" using decorators, which Ian Bicking followed up on[2] with a non-global approach. 1: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 2: http://blog.ianbicking.org/more-on-multimethods.html From dino at phidev.org Sat Feb 27 04:11:58 2010 From: dino at phidev.org (Florian Ludwig) Date: Sat, 27 Feb 2010 10:11:58 +0100 Subject: Exception in pydoc In-Reply-To: <4B87FBB3.8090107@gmail.com> References: <4B87FBB3.8090107@gmail.com> Message-ID: <1267261918.16436.31.camel@brain> On Fri, 2010-02-26 at 13:49 -0300, Ricardo Ar?oz wrote: > Does pydoc only deal with ASCII? UTF-8 in docstrings works for me. Maybe: * Its actually not UTF-8 * The console you're using doesn't support UTF-8 well (note: I'm on linux, maybe its a problem with windows?) code >>> #!/usr/bin/env python # -*- coding: utf-8 -*- def foo(): """Some ?tf-8 docstring ? g?f (x)""" return False <<>> help(test) Help on module test: NAME test - # -*- coding: utf-8 -*- FILE /tmp/test.py FUNCTIONS foo() Some ?tf-8 docstring ? g?f (x) -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From macosx at rocteur.cc Sat Feb 27 04:36:41 2010 From: macosx at rocteur.cc (@ Rocteur CC) Date: Sat, 27 Feb 2010 10:36:41 +0100 Subject: Python dos2unix one liner Message-ID: <70C8D379-E7C0-4852-94FD-17D9B3B67F2B@rocteur.cc> Hi, This morning I am working though Building Skills in Python and was having problems with string.strip. Then I found the input file I was using was in DOS format and I thought it be best to convert it to UNIX and so I started to type perl -i -pe 's/ and then I though, wait, I'm learning Python, I have to think in Python, as I'm a Python newbie I fired up Google and typed: +python convert dos to unix +one +liner Found perl, sed, awk but no python on the first page So I tried +python dos2unix +one +liner -perl Same thing.. But then I found http://wiki.python.org/moin/Powerful%20Python%20One-Liners and tried this: cat file.dos | python -c "import sys,re; [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in sys.stdin]" >file.unix And it works.. [10:31:11 incc-imac-intel ~/python] cat -vet file.dos one^M$ two^M$ three^M$ [10:32:10 incc-imac-intel ~/python] cat -vet file.unix one$ two$ three$ But it is long and just like sed does not do it in place. Is there a better way in Python or is this kind of thing best done in Perl ? Thanks, Jerry From martin.hellwig at dcuktec.org Sat Feb 27 05:14:02 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 27 Feb 2010 10:14:02 +0000 Subject: Python dos2unix one liner In-Reply-To: References: Message-ID: On 02/27/10 09:36, @ Rocteur CC wrote: Hi a couple of fragmented things popped in my head reading your question, non of them is very constructive though in what you actually want, but here it goes anyway. - Oneline through away script with re as a built in syntax, yup that sounds like perl to me. - What is wrong with making an executable script (not being one line) and call that, this is even shorter. - ... wait a minute, you are building something in python (problem with string.strip - why don't you use the built-in string strip method instead?) which barfs on the input (win/unix line ending), should the actual solution not be in there, i.e. parsing the line first to check for line-endings? .. But wait another minute, why are you getting \r\n in the first place, python by default uses universal new lines? Hope that helps a bit, maybe you could post the part of the code what you are doing for some better suggestions. -- mph From __peter__ at web.de Sat Feb 27 06:05:01 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Feb 2010 12:05:01 +0100 Subject: Python dos2unix one liner References: Message-ID: @ Rocteur CC wrote: > But then I found > http://wiki.python.org/moin/Powerful%20Python%20One-Liners > and tried this: > > cat file.dos | python -c "import sys,re; > [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in > sys.stdin]" >file.unix > > And it works.. - Don't build list comprehensions just to throw them away, use a for-loop instead. - You can often use string methods instead of regular expressions. In this case line.replace("\r\n", "\n"). > But it is long and just like sed does not do it in place. > > Is there a better way in Python or is this kind of thing best done in > Perl ? open(..., "U") ("universal" mode) converts arbitrary line endings to just "\n" $ cat -e file.dos alpha^M$ beta^M$ gamma^M$ $ python -c'open("file.unix", "wb").writelines(open("file.dos", "U"))' $ cat -e file.unix alpha$ beta$ gamma$ But still, if you want very short (and often cryptic) code Perl is hard to beat. I'd say that Python doesn't even try. Peter From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 06:44:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 11:44:30 GMT Subject: Python dos2unix one liner References: Message-ID: <4b89059e$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: > cat file.dos | python -c "import sys,re; > [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in > sys.stdin]" >file.unix Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal string replacement! You've been infected by too much Perl coding! *wink* Regexes are expensive, even in Perl, but more so in Python. When you don't need the 30 pound sledgehammer of regexes, use lightweight string methods. import sys; sys.stdout.write(sys.stdin.read().replace('\r\n', '\n')) ought to do it. It's not particularly short, but Python doesn't value extreme brevity -- code golf isn't terribly exciting in Python. [steve at sylar ~]$ cat -vet file.dos one^M$ two^M$ three^M$ [steve at sylar ~]$ cat file.dos | python -c "import sys; sys.stdout.write (sys.stdin.read().replace('\r\n', '\n'))" > file.unix [steve at sylar ~]$ cat -vet file.unix one$ two$ three$ [steve at sylar ~]$ Works fine. Unfortunately it still doesn't work in-place, although I think that's probably a side-effect of the shell, not Python. To do it in place, I would pass the file name: # Tested and working in the interactive interpreter. import sys filename = sys.argv[1] text = open(filename, 'rb').read().replace('\r\n', '\n') open(filename, 'wb').write(text) Turning that into a one-liner isn't terribly useful or interesting, but here we go: python -c "import sys;open(sys.argv[1], 'wb').write(open(sys.argv[1], 'rb').read().replace('\r\n', '\n'))" file Unfortunately, this does NOT work: I suspect it is because the file gets opened for writing (and hence emptied) before it gets opened for reading. Here's another attempt: python -c "import sys;t=open(sys.argv[1], 'rb').read().replace('\r\n', '\n');open(sys.argv[1], 'wb').write(t)" file [steve at sylar ~]$ cp file.dos file.txt [steve at sylar ~]$ python -c "import sys;t=open(sys.argv[1], 'rb').read ().replace('\r\n', '\n');open(sys.argv[1], 'wb').write(t)" file.txt [steve at sylar ~]$ cat -vet file.txt one$ two$ three$ [steve at sylar ~]$ Success! Of course, none of these one-liners are good practice. The best thing to use is a dedicated utility, or write a proper script that has proper error testing. > Is there a better way in Python or is this kind of thing best done in > Perl ? If by "this kind of thing" you mean text processing, then no, Python is perfectly capable of doing text processing. Regexes aren't as highly optimized as in Perl, but they're more than good enough for when you actually need a regex. If you mean "code golf" and one-liners, then, yes, this is best done in Perl :) -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 06:45:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 11:45:26 GMT Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: <4b8905d6$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 21:31:47 -0800, alex23 wrote: > Mensanator wrote: >> "You're" not getting the point. > > If every link has to be accompanied by a summary of all of the > information at the end of it, what point is there to linking? > > (Programmers are the _only_ people I know of who complain about the > arduousness of tasks like typing quotes or clicking on links...) Once you've clicked on a link to Tubgirl or Goatsie Man once, you will never, ever, ever click on an untrusted link again. *wink* But seriously... I dislike being sent links without any explanation of what is in them, because in my experience, 9 times out of 10 if I had been told, I wouldn't have bothered to clink on the link. -- Steven From translatorhossam at gmail.com Sat Feb 27 06:53:12 2010 From: translatorhossam at gmail.com (hussam elagmy) Date: Sat, 27 Feb 2010 03:53:12 -0800 (PST) Subject: Open all sites that blocked in your country from here Message-ID: Open all sites that blocked in your country from here Browse the internet securely using Your Proxy You can unblock popular social networking sites such as myspace, bebo, facebook and many other sites. http://essam.zxq.net/ From translatorhossam at gmail.com Sat Feb 27 07:06:42 2010 From: translatorhossam at gmail.com (hussam elagmy) Date: Sat, 27 Feb 2010 04:06:42 -0800 (PST) Subject: Open all sites that blocked in your country from here Message-ID: <9433bc33-d585-456a-b878-0f0e110cfff1@19g2000yqu.googlegroups.com> Browse the internet securely using Your Proxy You can unblock popular social networking sites such as myspace, bebo, facebook and many other sites. http://essam.zxq.net/ From usenot at geekmail.INVALID Sat Feb 27 08:45:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 27 Feb 2010 14:45:33 +0100 Subject: Variable definition References: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> Message-ID: <20100227144533.36d4294d@geekmail.INVALID> On 27 Feb 2010 03:33:57 GMT Steven D'Aprano wrote: > exec "'myPrefix_turquoise' = 42" > Not quite: In [1]: exec "'myPrefix_turquoise' = 42" ------------------------------------------------------------ File "", line 1 SyntaxError: can't assign to literal (, line 1) I think you meant: exec "myPrefix_turquoise = 42" /W -- INVALID? DE! From ijsporg at gmail.com Sat Feb 27 09:31:06 2010 From: ijsporg at gmail.com (org ijsp) Date: Sat, 27 Feb 2010 06:31:06 -0800 (PST) Subject: Call For Manuscripts: International Journal of Signal Processing (IJSP) Message-ID: <123a4533-5c74-4b84-8ee9-28c91827a770@s36g2000prh.googlegroups.com> Call For Manuscripts The Journal is currently accepting original high-quality research manuscripts for publication. The Journal welcomes the submission of manuscripts that meet the scientific criteria of significance and academic excellence. All research articles submitted for the journal will be peer-reviewed within three weeks of submission. Following the peer-reviewed acceptance, the accepted & formatted articles will normally be published in the next available issue. All submitted formatted full-text articles should report original, previously unpublished research results, experimental or theoretical. Articles submitted to the journal should meet these criteria and must not be under consideration for publication elsewhere. These articles should describe new and carefully confirmed findings, and experimental procedures should be given in sufficient detail for others to verify the work. The length of a full text article should be the minimum required to describe and interpret the work clearly. Papers are solicited from, but not limited to the following topics: * Adaptive Filtering & Signal Processing * Ad-Hoc and Sensor Networks * Analog and Mixed Signal Processing * Array Signal Processing * Audio and Electroacoustics * Audio/Speech Processing and Coding * Bioimaging and Signal Processing * Biometrics & Authentification * Biosignal Processing & Understanding * Communication and Broadband Networks * Communication Signal processing * Computer Vision & Virtual Reality * Cryptography and Network Security * Design and Implementation of Signal Processing Systems * Digital Signal Processing * DSP Implementations and Embedded Systems * Emerging Technologies * Hardware Implementation for Signal Processing * Higher Order Spectral Analysis * Image and Multidimensional Signal Processing * Image Processing & Understanding * Image/Video Processing and Coding * Industry Technology * Internet Signal Processing * Machine Learning for Signal Processing * Modulation and Channel Coding * Multimedia & Human-computer Interaction * Multimedia Communications * Multimedia Signal Processing * Natural Language Processing * Next Generation Mobile Communications * Nonlinear Signal Processing * Optical Communications * Parallel and Distributed Processing * PDE for Image Processing * Radar Signal Processing * Rapid Prototyping and Tools for DSP Design * RF and Wireless Communications * Sensor Array and Multi-channel Processing * Signal Processing and Communications Education * Signal Processing for Communications * Signal Processing for Security * Signal Processing Theory and Methods * Soft Computing and Machine learning for Signal Processing and Communications * Sonar Signal Processing and Localization * SP for Bioinformatics * SP for Biomedical & Cognitive Science * SP for Internet and Wireless Communications * SP for Sensor Networks * Spectrum Estimation & Modeling * Speech and Audio Coding * Speech Processing * Speech Synthesis & Recognition * Spoken Language Processing * Statistic Learning & Pattern Recognition * Statistical Signal Processing * TF Spectrum Analysis & Wavelet * Time-Frequency/Time-Scale Analysis * Video compression & Streaming * Watermarking and Information Hiding * Applications of Signal Processing (Biomedical, Bioinformatics, Genomic, Seismic, Radar, Sonar, Remote Sensing, Positioning, Embedded Systems, etc.) * Signal Processing and Communications Education * Web Engineering * Wireless Communications * Detection and Estimation * Cooperative Communication * Adaptive and Array Signal Processing * MIMO and Space-Time Signal Processing * Compressive Sensing & Applications * Cognitive Radio * Signal Processing for Communications * Network Coding * Machine Learning/AI for Signal Processing * Network Information Theory * Audio, Speech, Image & Video Signal Processing * Sequences & Complexity * Signal Processing Algorithms & Architectures * Source and Channel Coding: Theory and Practice * Underwater Communications and Signal Processing * Ad-hoc and Sensor Networks * Optical Communications and Networks * Next Generation Networking, QoS & Security * VLSI for Communication & Signal Processing * Multihop and Mesh Networks * RF Systems for Communications * Vehicular Networks * Systems, Standards and Implementations * Biomedical Signal Processing * Coding/Signal Processing in Biology * Spoken Language Processing * Biological Network & Data Analysis/Modelling CALL FOR PAPERS International Journal of Signal Processing (IJSP) Website: https://sites.google.com/site/ijsporg/ Manuscript submission to: ijsporg at gmail.com All submitted papers will be judged based on their quality by the technical committee and reviewers. Papers that describe research and experimentation are encouraged. All paper submissions will be handled electronically and detailed instructions on submission procedure are available on IJSP web pages. Researchers and authors are invited to participate in the peer-review process of IJSP papers if your research interest matches with the themes of Call for Papers. For other information, please contact IJSP Managing Editor. From macosx at rocteur.cc Sat Feb 27 10:01:53 2010 From: macosx at rocteur.cc (@ Rocteur CC) Date: Sat, 27 Feb 2010 16:01:53 +0100 Subject: Python dos2unix one liner In-Reply-To: <4b89059e$0$27844$c3e8da3@news.astraweb.com> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: > >> cat file.dos | python -c "import sys,re; >> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >> sys.stdin]" >file.unix > > Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal > string replacement! You've been infected by too much Perl coding! Thanks for the replies I'm looking at them now, however, for those who misunderstood, the above cat file.dos pipe pythong does not come from Perl but comes from: http://wiki.python.org/moin/Powerful%20Python%20One-Liners > Apply regular expression to lines from stdin > [another command] | python -c "import sys,re; > [sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', line)) > for line in sys.stdin]" Nothing to do with Perl, Perl only takes a handful of characters to do this and certainly does not require the creation an intermediate file, I simply found the above example on wiki.python.org whilst searching Google for a quick conversion solution. Thanks again for the replies I've learned a few things and I appreciate your help. Jerry From funthyme at gmail.com Sat Feb 27 10:29:46 2010 From: funthyme at gmail.com (John Pinner) Date: Sat, 27 Feb 2010 07:29:46 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Feb 24, 8:23?pm, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? A good way to control Python contractors is (given that firstly there are functional specifications to comply with, and tests to pass) is to impose the following condition: that all code delivered must reach a score of (say) 9.5 or more when checked by pylint and pylint could be the way to demonstrate the problems to the 'authorities'. If payment depends on such a measure, things will change quite quickly. John -- > /W > > -- > INVALID? DE! From ssteinerx at gmail.com Sat Feb 27 10:54:50 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 10:54:50 -0500 Subject: Python dos2unix one liner In-Reply-To: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> Message-ID: On Feb 27, 2010, at 10:01 AM, @ Rocteur CC wrote: > Nothing to do with Perl, Perl only takes a handful of characters to do this and certainly does not require the creation an intermediate file Perl may be better for you for throw-away code. Use Python for the code you want to keep (and read and understand later). S From stefan_ml at behnel.de Sat Feb 27 11:25:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 27 Feb 2010 17:25:48 +0100 Subject: Python dos2unix one liner In-Reply-To: <70C8D379-E7C0-4852-94FD-17D9B3B67F2B@rocteur.cc> References: <70C8D379-E7C0-4852-94FD-17D9B3B67F2B@rocteur.cc> Message-ID: @ Rocteur CC, 27.02.2010 10:36: > cat file.dos | python -c "import > sys,re;[sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in > sys.stdin]" >file.unix See: http://partmaps.org/era/unix/award.html Stefan From rami.chowdhury at gmail.com Sat Feb 27 11:36:29 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 27 Feb 2010 08:36:29 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> Message-ID: <201002270836.29268.rami.chowdhury@gmail.com> On Friday 26 February 2010 21:49:00 Isaiah Coberly wrote: > Thanks for your help Rami.. I got it working.. I did some digging around > and found out that I needed to install opencv as admin.. Now Im trying to > run one of the samples and up against my next chalange. > > Argg.. There are so many pit falls! > > Thanks again, > Glad to be able to help :-) Especially when you've managed to solve something, could you please remember to CC the list on your reply, so if people run across the problem in future they can benefit from your experience? Thanks, Rami > > On Fri, Feb 26, 2010 at 7:57 PM, Isaiah Coberly wrote: > > Thats the furthest I have seen it get.. Ill have to remember this.. > > > > here is what Python returned.. > > > > >>> from opencv import cv > > > > Traceback (most recent call last): > > File "", line 1, in > > > > from opencv import cv > > > > File "C:\Python26\lib\site-packages\opencv\__init__.py", line 74, in > > > > > > > > from cv import * > > > > File "C:\Python26\lib\site-packages\opencv\cv.py", line 25, in > > > > _cv = swig_import_helper() > > > > File "C:\Python26\lib\site-packages\opencv\cv.py", line 21, in > > > > swig_import_helper > > > > _mod = imp.load_module('_cv', fp, pathname, description) > > > > ImportError: DLL load failed: The specified module could not be found. > > > > On Fri, Feb 26, 2010 at 7:53 PM, Rami Chowdhury wrote: > >> On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote: > >> > >> C:\OpenCV2.0\Python2.6\Lib\site-packages > >> > >> no .py files here.. > >> > >> cv.pyd > >> libcv.dll.a > >> > >> > >> C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv > >> > >> _init_.py > >> matlan_syntax.py > >> adaptors.py > >> cv.py > >> > >> > >> It looks to me like 'opencv' is structured as a package, from which you > >> should be able to import and work with Python libraries. Have you tried > >> putting the above site-packages directory in sys.path: > >> > >> import sys; sys.path.append('C: > >> \\OpenCV2.0\\Python2.6\\Lib\\site-packages') > >> > >> and then doing: > >> > >> from opencv import cv > >> > >> ? > >> > >> Did I still need to compile this even though it was a win 32 installer? > >> > >> > >> I don't think so, no -- AFAIK the .pyd files are compiled CPython > >> extension modules, so it looks like they're all compiled for you. > >> > >> ------------- > >> Rami Chowdhury > >> "Never assume malice when stupidity will suffice." -- Hanlon's Razor > >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > >> > >> > >> > >> > >> > >> > >> On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury > >> >> > >> > wrote: > >>> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: > >>> > Thanks for the reply. > >>> > > >>> > I tried putting the files from > >>> > > >>> > C:\OpenCV2.0\Python2.6\Lib > >>> > > >>> > too > >>> > > >>> > C:\Python26\Lib\site-packages > >>> > > >>> > and Python still wont import.. > >>> > > >>> > I adjusted the environment variables to try and import > >>> > maya.standalone > >>> > >>> but > >>> > >>> > no dice on that either. > >>> > >>> Sorry, you've still not told me where you expect it to be. Could you > >>> let us > >>> know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? > >>> > >>> > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury > >>> > >>> wrote: > >>> > > On Friday 26 February 2010 16:06:56 Routb3d wrote: > >>> > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 > >>> > >>> pro. > >>> > >>> > > > I have tried adjusting environment variables as well as putting > >>> > > > the files directly in the search path of Python.. Python still > >>> > > > returns this.. Any ideas? > >>> > > > >>> > > Where are you expecting the cv module / package to be? It's > >>> > > certainly > >>> > >>> not > >>> > >>> > > in > >>> > > the standard library -- at least not in my install of Python > >>> > > 2.6.4... > >>> > > > >>> > > > >>> import sys > >>> > > > >>> sys.path > >>> > > > > >>> > > > ['C:\\Python26\\Lib\\idlelib', > >>> > > > 'C:\\ProgramFiles\\Autodesk\\Maya2010\ > >>> > >>> > > > \Python\\Lib\\site-packages', 'C: > >>> \\Windows\\system32\\python26.zip', > >>> > >>> > > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C: > >>> \\Python26\\lib\\plat- > >>> > >>> > > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C: > >>> \\Python26\\lib\ > >>> > >>> > > > \site-packages'] > >>> > > > > >>> > > > >>> import cv > >>> > > > > >>> > > > Traceback (most recent call last): > >>> > > > File "", line 1, in > >>> > > > > >>> > > > import cv > >>> > > > > >>> > > > ImportError: DLL load failed: The specified module could not be > >>> > >>> found. > >>> > >>> > > > Any help would be greatly appreciated. > >>> > > > >>> > > ---- > >>> > > Rami Chowdhury > >>> > > "Strangers are just friends who haven't had enough gin." -- > >>> > > Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / > >>> > > 01819-245544 (BD) > >>> > >>> ---- > >>> Rami Chowdhury > >>> "Ninety percent of everything is crap." -- Sturgeon's Law > >>> 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) ---- Rami Chowdhury -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GO d-(+++) s-:++ a-- C++> ULX+> P++ L++ E+ W+++ w-- PS+ PE t+ b+++ e++ !r z? ------END GEEK CODE BLOCK------ 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From invalid at invalid.invalid Sat Feb 27 11:59:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Feb 2010 16:59:28 +0000 (UTC) Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-27, @ Rocteur CC wrote: > Nothing to do with Perl, Perl only takes a handful of characters to do > this and certainly does not require the creation an intermediate file, Are you sure about that? Or does it just hide the intermediate file from you the way that sed -i does? -- Grant From emile at fenx.com Sat Feb 27 12:03:41 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Feb 2010 09:03:41 -0800 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: On 2/24/2010 1:52 PM Arnaud Delobelle said... > aahz at pythoncraft.com (Aahz) writes: >> That seems to miss the point to some extent. If I post my recipe for >> spinach lasagne here, is that spam? > > Are they really good? Sounds good, spinach lasagne, I don't know a > recipe for them. Maybe you could post it as Python code, with a lot of > nested if-then-else clauses, of course :) > +1 for Aahz posting his Spinach Lasagne recipe. Emile From kw at codebykevin.com Sat Feb 27 12:11:14 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 27 Feb 2010 12:11:14 -0500 Subject: Updates about Tk In-Reply-To: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <6adc$4b895233$4275d90a$6509@FUSE.NET> On 2/27/10 3:05 AM, Fabiano wrote: > > Hi, > I'm going to start my little journey into the Python's lands. > I have already red the old posts about but I suppose this is an evolving > topic. > I have understood Tk is the default Python's GUI toolkit, I have also > read that version 8.5 has native widgets and visual improvements. > My question is: > Are the new Tk comaprable with other toolkits(Qt, GTK,Wx?)? > Does Tk lack other features compared to the Qt,GTK,Wx...? > (Or: is there things you can't simply do with Tk?) > > Thanks in advance for replying In terms of UI, Tkinter as of 8.5 is pretty comparable to the other toolkits. The themed ttk widgets use native widgets for things like tree/tableviews, buttons, scrollbars, entry fields, labels, etc. If there's something that the core widgets don't support, there are both higher-level Python widget packages based on Tkinter (PMW, for instance) and Tkinter wrappers for Tk widget packages such as tablelist, Bwidgets, etc. More information is here: http://tkinter.unpythonic.net/wiki/ Tk still lacks in a few areas: 1. Native drag-and-drop--you have to install an extension package, TkDND, which also has a Python wrapper here: http://klappnase.bubble.org/index.html 2. Printing. The other toolkits support this out of the box. With Tk, you're pretty limited to lpr and/or generating postscript (on *Nix and Mac) and whatever native printing functionality is supported on Windows. 3. HTML rendering. The other toolkits support this natively. There are several alternatives on Tk, but none are ideal: see http://www.codebykevin.com/blosxom.cgi/2009/11/19#which-html. I find that Tk is so simple and powerful for most things that its limitations are acceptable, or can be worked around. Also, licensing can be problematic in some cases. But, as others have discussed, give the different toolkits a try and make your own choice. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From routb3d at gmail.com Sat Feb 27 12:15:09 2010 From: routb3d at gmail.com (Isaiah Coberly) Date: Sat, 27 Feb 2010 09:15:09 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: <201002270836.29268.rami.chowdhury@gmail.com> References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> <201002270836.29268.rami.chowdhury@gmail.com> Message-ID: <5413BF6A-44D1-48D7-B2EE-0C6364B45B27@gmail.com> Will do.. Thanks again.. Sent from my iPhone On Feb 27, 2010, at 8:36 AM, Rami Chowdhury wrote: > On Friday 26 February 2010 21:49:00 Isaiah Coberly wrote: >> Thanks for your help Rami.. I got it working.. I did some digging >> around >> and found out that I needed to install opencv as admin.. Now Im >> trying to >> run one of the samples and up against my next chalange. >> >> Argg.. There are so many pit falls! >> >> Thanks again, >> > > Glad to be able to help :-) > > Especially when you've managed to solve something, could you please > remember > to CC the list on your reply, so if people run across the problem in > future > they can benefit from your experience? > > Thanks, > Rami > >> >> On Fri, Feb 26, 2010 at 7:57 PM, Isaiah Coberly >> wrote: >>> Thats the furthest I have seen it get.. Ill have to remember this.. >>> >>> here is what Python returned.. >>> >>>>>> from opencv import cv >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> >>> from opencv import cv >>> >>> File "C:\Python26\lib\site-packages\opencv\__init__.py", line 74, >>> in >>> >>> >>> >>> from cv import * >>> >>> File "C:\Python26\lib\site-packages\opencv\cv.py", line 25, in >>> >>> >>> _cv = swig_import_helper() >>> >>> File "C:\Python26\lib\site-packages\opencv\cv.py", line 21, in >>> >>> swig_import_helper >>> >>> _mod = imp.load_module('_cv', fp, pathname, description) >>> >>> ImportError: DLL load failed: The specified module could not be >>> found. >>> >>> On Fri, Feb 26, 2010 at 7:53 PM, Rami Chowdhury > wrote: >>>> On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote: >>>> >>>> C:\OpenCV2.0\Python2.6\Lib\site-packages >>>> >>>> no .py files here.. >>>> >>>> cv.pyd >>>> libcv.dll.a >>>> >>>> >>>> C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv >>>> >>>> _init_.py >>>> matlan_syntax.py >>>> adaptors.py >>>> cv.py >>>> >>>> >>>> It looks to me like 'opencv' is structured as a package, from >>>> which you >>>> should be able to import and work with Python libraries. Have you >>>> tried >>>> putting the above site-packages directory in sys.path: >>>> >>>> import sys; sys.path.append('C: >>>> \\OpenCV2.0\\Python2.6\\Lib\\site-packages') >>>> >>>> and then doing: >>>> >>>> from opencv import cv >>>> >>>> ? >>>> >>>> Did I still need to compile this even though it was a win 32 >>>> installer? >>>> >>>> >>>> I don't think so, no -- AFAIK the .pyd files are compiled CPython >>>> extension modules, so it looks like they're all compiled for you. >>>> >>>> ------------- >>>> Rami Chowdhury >>>> "Never assume malice when stupidity will suffice." -- Hanlon's >>>> Razor >>>> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >>>> >>>> >>>> >>>> >>>> >>>> >>>> On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury >>>> >>> >>>>> wrote: >>>>> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: >>>>>> Thanks for the reply. >>>>>> >>>>>> I tried putting the files from >>>>>> >>>>>> C:\OpenCV2.0\Python2.6\Lib >>>>>> >>>>>> too >>>>>> >>>>>> C:\Python26\Lib\site-packages >>>>>> >>>>>> and Python still wont import.. >>>>>> >>>>>> I adjusted the environment variables to try and import >>>>>> maya.standalone >>>>> >>>>> but >>>>> >>>>>> no dice on that either. >>>>> >>>>> Sorry, you've still not told me where you expect it to be. Could >>>>> you >>>>> let us >>>>> know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? >>>>> >>>>>> On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury >>>>> >>>>> wrote: >>>>>>> On Friday 26 February 2010 16:06:56 Routb3d wrote: >>>>>>>> I used the x86 Python 2.6.4 installer. I am working in x64 Win7 >>>>> >>>>> pro. >>>>> >>>>>>>> I have tried adjusting environment variables as well as putting >>>>>>>> the files directly in the search path of Python.. Python still >>>>>>>> returns this.. Any ideas? >>>>>>> >>>>>>> Where are you expecting the cv module / package to be? It's >>>>>>> certainly >>>>> >>>>> not >>>>> >>>>>>> in >>>>>>> the standard library -- at least not in my install of Python >>>>>>> 2.6.4... >>>>>>> >>>>>>>>>>> import sys >>>>>>>>>>> sys.path >>>>>>>> >>>>>>>> ['C:\\Python26\\Lib\\idlelib', >>>>>>>> 'C:\\ProgramFiles\\Autodesk\\Maya2010\ >>>>> >>>>>>>> \Python\\Lib\\site-packages', 'C: >>>>> \\Windows\\system32\\python26.zip', >>>>> >>>>>>>> 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C: >>>>> \\Python26\\lib\\plat- >>>>> >>>>>>>> win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C: >>>>> \\Python26\\lib\ >>>>> >>>>>>>> \site-packages'] >>>>>>>> >>>>>>>>>>> import cv >>>>>>>> >>>>>>>> Traceback (most recent call last): >>>>>>>> File "", line 1, in >>>>>>>> >>>>>>>> import cv >>>>>>>> >>>>>>>> ImportError: DLL load failed: The specified module could not be >>>>> >>>>> found. >>>>> >>>>>>>> Any help would be greatly appreciated. >>>>>>> >>>>>>> ---- >>>>>>> Rami Chowdhury >>>>>>> "Strangers are just friends who haven't had enough gin." -- >>>>>>> Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / >>>>>>> 01819-245544 (BD) >>>>> >>>>> ---- >>>>> Rami Chowdhury >>>>> "Ninety percent of everything is crap." -- Sturgeon's Law >>>>> 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) > > > ---- > Rami Chowdhury > -----BEGIN GEEK CODE BLOCK----- > Version: 3.1 > GO d-(+++) s-:++ a-- C++> ULX+> P++ L++ > E+ W+++ w-- PS+ PE t+ b+++ e++ !r z? > ------END GEEK CODE BLOCK------ > 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From john at castleamber.com Sat Feb 27 12:18:57 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 11:18:57 -0600 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <87r5o6zjem.fsf@castleamber.com> Steven D'Aprano writes: > Also, some assemblies perform the move in different directions according > to the arguments. So you might have: > > mv AX,BX ; move contents of BX into AX > mv @CX,DX ; move contents of @CX into DX > > Horrible, yes, but apparently some assembly languages did something like > that. It doesn't matter. Both your comments are wrong from my point of view. Someone who doesn't know in which direction the move happens is certainly not qualified to modify the code. And as for learning, he/she should start with a book, not with a piece of code that requires a comment on every line unless one can guess its meaning. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Sat Feb 27 12:27:04 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 11:27:04 -0600 Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> Message-ID: <87mxyuzj13.fsf@castleamber.com> "ssteinerX at gmail.com" writes: > On Feb 27, 2010, at 10:01 AM, @ Rocteur CC wrote: >> Nothing to do with Perl, Perl only takes a handful of characters to >> do this and certainly does not require the creation an intermediate >> file > > Perl may be better for you for throw-away code. Use Python for the > code you want to keep (and read and understand later). Amusing how long those Python toes can be. In several replies I have noticed (often clueless) opinions on Perl. When do people learn that a language is just a tool to do a job? -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From rantingrick at gmail.com Sat Feb 27 12:29:44 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 27 Feb 2010 09:29:44 -0800 (PST) Subject: Updates about Tk References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> <6adc$4b895233$4275d90a$6509@FUSE.NET> Message-ID: On Feb 27, 11:11?am, Kevin Walzer wrote: (...snip...) > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Great post Kevin! The only thing i would like to add are my two favorite references for learning Tkinter. They are not geared around the new ttk stuff, but still 95% relevant to any Tkinter-ing http://effbot.org/tkinterbook/ http://infohost.nmt.edu/tcc/help/pubs/tkinter/ From fetchinson at googlemail.com Sat Feb 27 12:37:22 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sat, 27 Feb 2010 18:37:22 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002261604.57625.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261335.02933.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: On 2/26/10, Victor Stinner wrote: > Le vendredi 26 f?vrier 2010 15:37:43, Daniel Fetchinson a ?crit : >> >> pysandbox is a new Python sandbox project >> >> Out of curiosity, the python sandbox behind google app engine is open >> source? If so, how is it different from your project, if not, anyone >> knows >> if it will be in the future? > > I don't know this project. Do you have the URL of the project home page? Is > it > the "safelite.py" project? It's google's hosting solution called app engine, for python web applications: http://code.google.com/appengine/docs/python/gettingstarted/ I guess they also have some kind of a sandbox if they let people run python on their machines, I'm not sure if it's open source though. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From alfps at start.no Sat Feb 27 12:40:01 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 27 Feb 2010 18:40:01 +0100 Subject: Python dos2unix one liner In-Reply-To: References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: * @ Rocteur CC: > > On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > >> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: >> >>> cat file.dos | python -c "import sys,re; >>> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >>> sys.stdin]" >file.unix >> >> Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal >> string replacement! You've been infected by too much Perl coding! > > Thanks for the replies I'm looking at them now, however, for those who > misunderstood, the above cat file.dos pipe pythong does not come from > Perl but comes from: > > http://wiki.python.org/moin/Powerful%20Python%20One-Liners Steven is right with the "Holy Cow" and multiple exclamation marks. For those unfamiliar with that, just google "multiple exclamation marks", I think that should work... ;-) Not only is a regular expression overkill & inefficient, but the snippet also needlessly constructs an array with size the number of lines. Consider instead e.g. import sys; sum(int(bool(sys.stdout.write(line.replace('\r\n','\n')))) for line in sys.stdin) But better, consider that it's less work to save the code in a file than copying and pasting it in a command interpreter, and then it doesn't need to be 1 line. >> Apply regular expression to lines from stdin >> [another command] | python -c "import >> sys,re;[sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', >> line)) for line in sys.stdin]" > > > Nothing to do with Perl, Perl only takes a handful of characters to do > this and certainly does not require the creation an intermediate file, I > simply found the above example on wiki.python.org whilst searching > Google for a quick conversion solution. > > Thanks again for the replies I've learned a few things and I appreciate > your help. Cheers, - Alf From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 12:42:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 17:42:31 GMT Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b895987$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 16:01:53 +0100, @ Rocteur CC wrote: > On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > >> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: >> >>> cat file.dos | python -c "import sys,re; >>> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >>> sys.stdin]" >file.unix >> >> Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal >> string replacement! You've been infected by too much Perl coding! > > Thanks for the replies I'm looking at them now, however, for those who > misunderstood, the above cat file.dos pipe pythong does not come from > Perl but comes from: > > http://wiki.python.org/moin/Powerful%20Python%20One-Liners Whether it comes from Larry Wall himself, or a Python wiki, using regexes for a simple string replacement is like using an 80 lb sledgehammer to crack a peanut. >> Apply regular expression to lines from stdin [another command] | python >> -c "import sys,re; >> [sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', line)) for >> line in sys.stdin]" And if PATTERN is an actual regex, rather than just a simple substring, that would be worthwhile. But if PATTERN is a literal string, then string methods are much faster and use much less memory. > Nothing to do with Perl, Perl only takes a handful of characters to do > this I'm sure it does. If I were interested in code-golf, I'd be impressed. > and certainly does not require the creation an intermediate file, The solution I gave you doesn't use an intermediate file either. *slaps head and is enlightened* Oh, I'm an idiot! Since you're reading text files, there's no need to call replace('\r\n','\n'). Since there shouldn't be any bare \r characters in a DOS-style text file, just use replace('\r', ''). Of course, that's an unsafe assumption in the real world. But for a quick and dirty one-liner (and all one-liners are quick and dirty), it should be good enough. -- Steven From ssteinerx at gmail.com Sat Feb 27 13:01:22 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 13:01:22 -0500 Subject: Python dos2unix one liner In-Reply-To: <87mxyuzj13.fsf@castleamber.com> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: On Feb 27, 2010, at 12:27 PM, John Bokma wrote: > "ssteinerX at gmail.com" writes: > >> On Feb 27, 2010, at 10:01 AM, @ Rocteur CC wrote: >>> Nothing to do with Perl, Perl only takes a handful of characters to >>> do this and certainly does not require the creation an intermediate >>> file >> >> Perl may be better for you for throw-away code. Use Python for the >> code you want to keep (and read and understand later). > > Amusing how long those Python toes can be. In several replies I have > noticed (often clueless) opinions on Perl. When do people learn that a > language is just a tool to do a job? I'm not sure how "use it for what it's good for" has anything to do with toes. I've written lots of both Python and Perl and sometimes, for one-off's, Perl is quicker; if you know it. I sure don't want to maintain Perl applications though; even ones I've written. When all you have is a nail file, everything looks like a toe; that doesn't mean you want to have to maintain it. Or something. S From invalid at invalid.invalid Sat Feb 27 13:02:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Feb 2010 18:02:34 +0000 (UTC) Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-27, @ Rocteur CC wrote: > > On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > >> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: >> >>> cat file.dos | python -c "import sys,re; >>> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >>> sys.stdin]" >file.unix >> >> Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal >> string replacement! You've been infected by too much Perl coding! > > Thanks for the replies I'm looking at them now, however, for those who > misunderstood, the above cat file.dos pipe pythong does not come from > Perl but comes from: > > http://wiki.python.org/moin/Powerful%20Python%20One-Liners > >> Apply regular expression to lines from stdin >> [another command] | python -c "import sys,re; >> [sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', line)) >> for line in sys.stdin]" > > Nothing to do with Perl, Perl only takes a handful of > characters to do this and certainly does not require the > creation an intermediate file, In _theory_ you can do a simple string-replace in situ as long as the replacement string is shorter than the original string. But I have a hard time believing that Perl actually does it that. Since I don't speak line-noise, will you please post the Perl script that you claim does the conversion without creating an intermediate file? The only way I can think of to do a general in-situ file modification is to buffer the entire file's worth of output in memory and then overwrite the file after all of the processing has finished. Python can do that too, but it's not generally a very good approach. -- Grant From usenot at geekmail.INVALID Sat Feb 27 13:10:40 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 27 Feb 2010 19:10:40 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <20100227191040.6c77f2d8@geekmail.INVALID> On Sat, 27 Feb 2010 07:29:46 -0800 (PST) John Pinner wrote: > A good way to control Python contractors is (given that firstly there > are functional specifications to comply with, and tests to pass) is to > impose the following condition: > > that all code delivered must reach a score of (say) 9.5 or more when > checked by pylint > Now that *is* a good idea. I hadn't thought about that. But as I said: a) I am (we are) not in a position to impose this (We don't work with the code, we just run the software). And b) I wasn't quite serious with this anyway. But still, I'll keep that in mind. /W -- INVALID? DE! From john at castleamber.com Sat Feb 27 13:15:39 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 12:15:39 -0600 Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: <873a0mpmt0.fsf@castleamber.com> "ssteinerX at gmail.com" writes: > I'm not sure how "use it for what it's good for" has anything to do > with toes. I've the feeling that some people who use Python are easily offended by everthing Perl related. Which is silly; zealotism in general is, for that matter. > I've written lots of both Python and Perl and sometimes, for > one-off's, Perl is quicker; if you know it. > > I sure don't want to maintain Perl applications though; even ones I've > written. Ouch, I am afraid that that tells a lot about your Perl programming skills. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From ssteinerx at gmail.com Sat Feb 27 13:29:52 2010 From: ssteinerx at gmail.com (ssteinerx at gmail.com) Date: Sat, 27 Feb 2010 13:29:52 -0500 Subject: Python dos2unix one liner In-Reply-To: <873a0mpmt0.fsf@castleamber.com> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <873a0mpmt0.fsf@castleamber.com> Message-ID: <2B2A2898-E576-4BDD-B475-C0234D14D155@gmail.com> On Feb 27, 2010, at 1:15 PM, John Bokma wrote: >> I sure don't want to maintain Perl applications though; even ones I've >> written. > > Ouch, I am afraid that that tells a lot about your Perl programming > skills. Nah, it tells you about my preferences. I can, and have, written maintainable things in many languages, including Perl. However, I *choose* Python. S From tjreedy at udel.edu Sat Feb 27 14:28:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Feb 2010 14:28:26 -0500 Subject: Karrigell 3.0.4 published In-Reply-To: References: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Message-ID: On 2/27/2010 3:21 AM, Pierre Quentel wrote: > > Oops ! wrong group, sorry. It's for c.l.p.announce Announcements also come to c.l.p and python-list. C.l.p.a should be a low-traffic subset, perhaps with followups set to c.l.p for discussion. From aahz at pythoncraft.com Sat Feb 27 14:29:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 11:29:17 -0800 Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: In article <87mxyuzj13.fsf at castleamber.com>, John Bokma wrote: > >Amusing how long those Python toes can be. In several replies I have >noticed (often clueless) opinions on Perl. When do people learn that a >language is just a tool to do a job? When do people learn that language makes a difference? I used to be a Perl programmer; these days, you'd have to triple my not-small salary to get me to even think about programming in Perl. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Sat Feb 27 15:46:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 12:46:38 -0800 Subject: Bizarre arithmetic results References: Message-ID: In article , Steven D'Aprano wrote: > >[steve at sylar ~]$ cat ws-example.rb Ahhh, you're a Heroes fan. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From sillyhat at yahoo.com Sat Feb 27 15:50:38 2010 From: sillyhat at yahoo.com (Hal Styli) Date: Sat, 27 Feb 2010 12:50:38 -0800 (PST) Subject: stripping fields from xml file into a csv Message-ID: Hello, Can someone please help. I have a sed solution to the problems below but would like to rewrite in python... I need to strip out some data from a quirky xml file into a csv: from something like this < ..... cust="dick" .... product="eggs" ... quantity="12" .... > < .... cust="tom" .... product="milk" ... quantity="2" ...> < .... cust="harry" .... product="bread" ... quantity="1" ...> < .... cust="tom" .... product="eggs" ... quantity="6" ...> < ..... cust="dick" .... product="eggs" ... quantity="6" .... > to this dick,eggs,12 tom,milk,2 harry,bread,1 tom,eggs,6 dick,eggs,6 I am new to python and xml and it would be great to see some slick ways of achieving the above by using python's XML capabilities to parse the original file or python's regex to achive what I did using sed. Thanks for any constructive help given. Hal From aahz at pythoncraft.com Sat Feb 27 15:50:41 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 12:50:41 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: In article , Emile van Sebille wrote: >On 2/24/2010 1:52 PM Arnaud Delobelle said... >> aahz at pythoncraft.com (Aahz) writes: >>> >>> That seems to miss the point to some extent. If I post my recipe for >>> spinach lasagne here, is that spam? >> >> Are they really good? Sounds good, spinach lasagne, I don't know a >> recipe for them. Maybe you could post it as Python code, with a lot of >> nested if-then-else clauses, of course :) > >+1 for Aahz posting his Spinach Lasagne recipe. Sorry, I lied. ;-) I don't actually have a spinach lasagne recipe. I've got lots of others on my personal website at http://rule6.info/ (including one for Catalan Spinach). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From john at castleamber.com Sat Feb 27 15:56:22 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 14:56:22 -0600 Subject: stripping fields from xml file into a csv References: Message-ID: <87aauu5rex.fsf@castleamber.com> Hal Styli writes: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite > in python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > < .... cust="harry" .... product="bread" ... quantity="1" ...> > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick > ways of achieving the above by using python's XML capabilities to > parse the original file or python's regex to achive what I did using > sed. It's not clear how your XML actually looks, but (especially) if those are all attributes of one element I probably would just use xml.sax I strongly suggest to not use regex to parse XML. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From dontsendleospam at gmail.com Sat Feb 27 18:57:15 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Sat, 27 Feb 2010 15:57:15 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: I think a big part of the problem is that the scoping rules in Python are inconsistent because classes are a different kind of object. An example helps: This works: x = 1 def f(y): return y + x This works: def f(): x = 1 def g(y): return x + y return g(2) But this doesn't work... class C: x = 1 def f(self,y): return x + y ...although what was probably meant was this, which does work... class C: x = 1 def f(self,y): return self.x + y ...and really means this... class C: x = 1 def f(self,y): return T.x + y ...which create other quirkiness when x is mutable as illustrated nicely here: http://bioscreencastwiki.com/Python_Variable_scope_gymnastics One reasonable answer to this quirkiness is RTFM. Classes are well documented as is everything else in python. Mostly late-binding semantics are also well documented. I argue that it is more consistent to have the scope for classes be consistent with the scope of everything else, which makes the early/ late binding point mute. I know this is a major change, that it would break existing code, etc. It would have been better to talk about these things before py3k. Still: 1. Has this been discussed before? 1. What would this suggestion break? 2. What are the advantages of making the scope of class variables different? Maybe is it just a historical trait? Cheers, Leo. From ssteinerx at gmail.com Sat Feb 27 19:12:10 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 19:12:10 -0500 Subject: scope of generators, class variables, resulting in global na In-Reply-To: References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: On Feb 27, 2010, at 6:57 PM, dontspamleo wrote: > > > http://bioscreencastwiki.com/Python_Variable_scope_gymnastics Broken link: Site settings could not be loaded We were unable to locate the API to request site settings. Please see below for debugging information. HTTP Response Status Code: 0 From aahz at pythoncraft.com Sat Feb 27 19:47:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 16:47:30 -0800 Subject: python dowload References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: In article <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d at insightbb.com>, monkeys paw wrote: >On 2/23/2010 3:17 PM, Tim Chase wrote: >> >> Sure you don't need this to be 'wb' instead of 'w'? > >'wb' does the trick. Thanks all! > >import urllib2 >a = open('adobe.pdf', 'wb') >i = 0 >for line in >urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): > i = i + 1 > a.write(line) Using a for loop here is still a BAD IDEA -- line could easily end up megabytes in size (though that is statistically unlikely). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From tarekamr at gmail.com Sat Feb 27 20:41:09 2010 From: tarekamr at gmail.com (tarekamr at gmail.com) Date: Sat, 27 Feb 2010 17:41:09 -0800 (PST) Subject: Pyrhon2.5 to 2.4 conversion Message-ID: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Hi, I am currently using oauth2.py library, and it works fine on one of my PC's (python2.5), but later on when I tried to use it with python2.4 the following line (line 332 in http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) showed a syntax error items = [(k, v if type(v) != ListType else sorted(v)) for k,v in sorted(self.items()) if k != 'oauth_signature'] So it there a way to convert this line to a python2.4 compliant syntax. Thanks a lot, Tarek From rjngrj2010 at gmail.com Sat Feb 27 20:48:15 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sat, 27 Feb 2010 17:48:15 -0800 (PST) Subject: help with Python installation Message-ID: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Hi, I have been trying to install python on my Win ME system for over two years - gave up for a while and now I am back with a resolve to solve the problem. I tried all versions of python but having installation problems for all. Installation does not proceed and I get a message saying "dll required for installation could not be run". I do not even know what to do next. I also tried Activepython. It installs but when I try to open it from Start->Programs->ActivePython 2.6, I get an error window saying - upgrade windows. Is there no solution at all to installing python on WinME. I have checked registry several times online and have sought professional help but so far no success. Thanks, I will appreciate any help gujax From benjamin.kaplan at case.edu Sat Feb 27 20:49:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 27 Feb 2010 20:49:51 -0500 Subject: Pyrhon2.5 to 2.4 conversion In-Reply-To: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: On Sat, Feb 27, 2010 at 8:41 PM, tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 > the following line (line 332 in > http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant > syntax. > > That's a list comprehension. Really useful tool. That line is equivalent to items = [] for k,v in sorted(self.items()) : if k != 'oauth_signature' : if type(v) != ListType: items.append((k,v)) else : items.append(sorted(v)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From zaphod at beeblebrox.net Sat Feb 27 20:52:15 2010 From: zaphod at beeblebrox.net (Zaphod) Date: Sun, 28 Feb 2010 01:52:15 GMT Subject: stripping fields from xml file into a csv References: Message-ID: On Sat, 27 Feb 2010 12:50:38 -0800, Hal Styli wrote: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite in > python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > < .... > cust="tom" .... product="milk" ... quantity="2" ...> < .... cust="harry" > .... product="bread" ... quantity="1" ...> < .... cust="tom" .... > product="eggs" ... quantity="6" ...> < ..... cust="dick" .... > product="eggs" ... quantity="6" .... > > > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick ways > of achieving the above by using python's XML capabilities to parse the > original file or python's regex to achive what I did using sed. > > Thanks for any constructive help given. > > Hal Start here: http://pyxml.sourceforge.net/topics/ From clp2 at rebertia.com Sat Feb 27 20:58:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 27 Feb 2010 17:58:34 -0800 Subject: Pyrhon2.5 to 2.4 conversion In-Reply-To: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <50697b2c1002271758s17ec88d4oc122a31634dafb1e@mail.gmail.com> On Sat, Feb 27, 2010 at 5:41 PM, tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 > the following line (line 332 in http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant > syntax. This part is your problem: (k, v if type(v) != ListType else sorted(v)) Conditional expressions like that were added in v2.5: http://docs.python.org/whatsnew/2.5.html#pep-308-conditional-expressions Here's an untested substitute: def sort_or_tuple(k, v): if type(v) != ListType: return k, v else: return sorted(v) items = [sort_or_tuple(k,v) for k,v in sorted(self.items()) if k != 'oauth_signature'] Of course, the more obvious solution is just to upgrade your Python; it's well worth it! Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 21:02:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 02:02:58 GMT Subject: Pyrhon2.5 to 2.4 conversion References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <4b89ced1$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 17:41:09 -0800, tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 the > following line (line 332 in > http://github.com/simplegeo/python-oauth2/blob/master/oauth2/ __init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant syntax. You would be better off installing Python2.5 on the PC rather than trying to backport the library to 2.4. There could be thousands of changes needed to backport the library. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 21:03:12 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 02:03:12 GMT Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: <4b89cee0$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 11:27:04 -0600, John Bokma wrote: > When do people learn that a > language is just a tool to do a job? When do people learn that there are different sorts of tools? A professional wouldn't use a screwdriver when they need a hammer. Perl has strengths: it can be *extremely* concise, regexes are optimized much more than in Python, and you can do some things as a one-liner short enough to use from the command line easily. Those are values, as seen by the millions of people who swear by Perl, but they are not Python's values. If you want something which can make fine cuts in metal, you would use a hacksaw, not a keyhole saw or a crosscut saw. If you want to cut through an three foot tree truck, you would use a ripsaw or a chainsaw, and not a hacksaw. If you want concise one-liners, you would use Perl, not Python, and if you want readable, self-documenting code, you're more likely to get it from Python than from Perl. If every tool is the same, why aren't we all using VB? Or C, or Javascript, or SmallTalk, or Forth, or ... ? In the real world, all these languages have distinguishing characteristics and different strengths and weaknesses, which is why there are still people using PL/I and Cobol as well as people using Haskell and Lisp and Boo and PHP and D and ... Languages are not just nebulous interchangeable "tools", they're tools for a particular job with particular strengths and weaknesses, and depending on what strengths you value and what weaknesses you dislike, some tools simply are better than other tools for certain tasks. -- Steven From greg.ewing at canterbury.ac.nz Sat Feb 27 21:06:44 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Feb 2010 15:06:44 +1300 Subject: staticmethod and namespaces In-Reply-To: References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> <7uqa0eF95lU1@mid.uni-berlin.de> <7uqamjFd2vU2@mid.uni-berlin.de> Message-ID: <7uu0q2Fb8hU1@mid.individual.net> darnzen wrote: > Well, I got around this mess by putting all those static callbacks > into a separate module in a new class. I set them up to call a bound > method of that class which passes the arguments to the appropriate > bound methods of other class instances. I just have to keep a little > dict of the bound method callbacks when I register them with the > class. You're making it much more complicated than it needs to be. Diez is right, a bound method should work provided you keep a reference to it somewhere for as long as it's needed. -- Greg From python at mrabarnett.plus.com Sat Feb 27 21:12:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Feb 2010 02:12:12 +0000 Subject: Pyrhon2.5 to 2.4 conversion In-Reply-To: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <4B89D0FC.7080205@mrabarnett.plus.com> tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 > the following line (line 332 in http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant > syntax. > I think the clearest is: items = [] for k, v in sorted(self.items()): if k != 'oauth_signature': if type(v) == ListType: v = sorted(v) items.append((k, v)) From python.list at tim.thechases.com Sat Feb 27 21:19:03 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 27 Feb 2010 20:19:03 -0600 Subject: python dowload In-Reply-To: References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <4B89D297.8010901@tim.thechases.com> Aahz wrote: > monkeys paw wrote: >> On 2/23/2010 3:17 PM, Tim Chase wrote: >>> Sure you don't need this to be 'wb' instead of 'w'? >> 'wb' does the trick. Thanks all! >> >> import urllib2 >> a = open('adobe.pdf', 'wb') >> i = 0 >> for line in >> urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): >> i = i + 1 >> a.write(line) > > Using a for loop here is still a BAD IDEA -- line could easily end up > megabytes in size (though that is statistically unlikely). Just so the OP has it, dealing with binary files without reading the entire content into memory would look something like from urllib2 import urlopen CHUNK_SIZE = 1024*4 # 4k, why not? OUT_NAME = 'out.pdf' a = open(OUT_NAME, 'wb') u = urlopen(URL) bytes_read = 0 while True: data = u.read(CHUNK_SIZE) if not data: break a.write(data) bytes_read += len(data) print "Wrote %i bytes to %s" % ( bytes_read, OUT_NAME) -tkc From greg.ewing at canterbury.ac.nz Sat Feb 27 21:23:03 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Feb 2010 15:23:03 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: <7uu1ooFiipU1@mid.individual.net> Mel wrote: > You could think of it as a not bad use of the design principle "Clear The > Simple Stuff Out Of The Way First". Destinations are commonly a lot simpler > than sources That's not usually true in assembly languages, though, where the source and destination are both very restricted and often about the same complexity. That's not to say that right-to-left is the wrong way to do it in an assembly language, but there are less misleading words than "move" that could be used. Z80 assembly language uses "load", which makes things considerably clearer: LD A, B ; load A with B -- Greg From rantingrick at gmail.com Sat Feb 27 21:26:23 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 27 Feb 2010 18:26:23 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: <921d8fca-2cdc-4444-87c0-96f4072fbfdb@d2g2000yqa.googlegroups.com> On Feb 27, 7:48?pm, gujax wrote: > Hi, > I have been trying to install python on my Win ME system for over two > years - Wow 2 years!, you must have the patience of a saint! > Installation does not proceed and I get a message > saying "dll required for installation could not be run". Did it say "what" dll did not run, did have a name? > I do not even > know what to do next. I also tried Activepython. It installs but when > I try to open it from Start->Programs->ActivePython 2.6, I get an > error window saying - upgrade windows. Hmm, have you tried "upgrading windows, just a wild guess! From rpdooling at gmail.com Sat Feb 27 21:36:45 2010 From: rpdooling at gmail.com (Rick Dooling) Date: Sat, 27 Feb 2010 18:36:45 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: > Hi, > I have been trying to install python on my Win ME system Try this: http://tinyurl.com/w7wgp RD From ssteinerx at gmail.com Sat Feb 27 21:38:00 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 21:38:00 -0500 Subject: help with Python installation In-Reply-To: <921d8fca-2cdc-4444-87c0-96f4072fbfdb@d2g2000yqa.googlegroups.com> References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <921d8fca-2cdc-4444-87c0-96f4072fbfdb@d2g2000yqa.googlegroups.com> Message-ID: >> I do not even >> know what to do next. I also tried Activepython. It installs but when >> I try to open it from Start->Programs->ActivePython 2.6, I get an >> error window saying - upgrade windows. > > Hmm, have you tried "upgrading windows, just a wild guess! Hey, not everyone can afford to upgrade Windows and some hardware just can't handle the "new, improved" versions. How about we all chip in to buy him a copy of Ubuntu? Oh, wait, it's free... S From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 21:44:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 02:44:17 GMT Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: <4b89d880$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 15:57:15 -0800, dontspamleo wrote: > I think a big part of the problem is that the scoping rules in Python > are inconsistent because classes are a different kind of object. An > example helps: [...] > But this doesn't work... > class C: > x = 1 > def f(self,y): return x + y > > ...although what was probably meant was this, which does work... > class C: > x = 1 > def f(self,y): return self.x + y Yes, this is a deliberate design choice. See below. > ...and really means this... > class C: > x = 1 > def f(self,y): return T.x + y I don't understand what T is. Did you mean C? If so, you are wrong. self.x is not the same as .x due to inheritance rules. Consider one example: >>> class A: ... x = 1 ... def __init__(self, x=None): ... if x is not None: ... self.x = x ... >>> class B(A): ... def f(self, y): return self.x + y ... >>> class C(A): ... def f(self, y): return C.x + y ... >>> >>> B(5).f(10) 15 >>> C(5).f(10) 11 I have no doubt that there will be other examples involving multiple inheritance, but I trust I've made my point. > I argue that it is more consistent to have the scope for classes be > consistent with the scope of everything else, which makes the early/ > late binding point mute. Yes, it would be more consistent, but less useful. Apart from methods themselves, using class attributes is a relatively rare thing to do, but using global level names inside methods is very common. > I know this is a major change, that it would break existing code, etc. > It would have been better to talk about these things before py3k. Still: > > 1. Has this been discussed before? Yes. > 1. What would this suggestion break? Nearly all existing code using classes, which is nearly everything. > 2. What are the advantages of making the scope of class variables > different? Maybe is it just a historical trait? See the discussion in the PEP for introducing nested scopes in the first place: http://www.python.org/dev/peps/pep-0227/ -- Steven From python at mrabarnett.plus.com Sat Feb 27 21:45:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Feb 2010 02:45:18 +0000 Subject: Docstrings considered too complicated In-Reply-To: <7uu1ooFiipU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> Message-ID: <4B89D8BE.2040905@mrabarnett.plus.com> Gregory Ewing wrote: > Mel wrote: > >> You could think of it as a not bad use of the design principle "Clear >> The Simple Stuff Out Of The Way First". Destinations are commonly a >> lot simpler than sources > > That's not usually true in assembly languages, though, > where the source and destination are both very restricted > and often about the same complexity. > > That's not to say that right-to-left is the wrong way > to do it in an assembly language, but there are less > misleading words than "move" that could be used. > > Z80 assembly language uses "load", which makes things > considerably clearer: > > LD A, B ; load A with B > Some processors distinguish between "load" (memory to register) and "store" (register to memory), and the destination and LHS operand of binary operations might be the same register, for example: CLC ; clear the carry LDA first ; accumulator := byte at first ADCA second ; accumulator := accumulator + byte at second + carry STA result ; byte at third := accumulator From steve at holdenweb.com Sat Feb 27 21:55:50 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Feb 2010 21:55:50 -0500 Subject: help with Python installation In-Reply-To: References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: Rick Dooling wrote: >> Hi, >> I have been trying to install python on my Win ME system > > Try this: > > http://tinyurl.com/w7wgp > That explains how to install Python on Windows *XP*. Windows ME is no longer a supported platform - the tools used to create it just aren't able to support platforms that old. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From staticd at gmail.com Sat Feb 27 21:56:31 2010 From: staticd at gmail.com (staticd) Date: Sat, 27 Feb 2010 18:56:31 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: <6b04c31f-fdaa-4f63-99fb-5bebe7ae4b0e@z11g2000yqz.googlegroups.com> On Feb 27, 8:48?pm, gujax wrote: > I have been trying to install python on my Win ME system for over two > years - gave up for a while and now I am back with a resolve to solve > the problem. Dude. Give up. There are a ton of __free__ distroz of linux out there. Your troubles are not worth the effort. Why do I say this? Let's say you do, eventually, figure out what's wrong. Now what? Why are you so attached to this machine with ME on it? nd From arnodel at googlemail.com Sat Feb 27 22:14:49 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 27 Feb 2010 19:14:49 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: <038b8f03-c0bc-4ca3-b4eb-73e01ce7f69f@z35g2000yqd.googlegroups.com> On 28 Feb, 01:48, gujax wrote: > Hi, > I have been trying to install python on my Win ME system for over two > years - gave up for a while and now I am back with a resolve to solve > the problem. I tried all versions of python but having installation > problems for all. Installation does not proceed and I get a message > saying "dll required for installation could not be run". I do not even > know what to do next. I also tried Activepython. It installs but when > I try to open it from Start->Programs->ActivePython 2.6, I get an > error window saying - upgrade windows. > Is there no solution at all to installing python on WinME. I have > checked registry several times online and have sought professional > help but so far no success. > Thanks, I will appreciate any help > gujax The docs (*) say that Python 2.5 is still compatible with Windows 9X and ME, but that support for these platform was dropped at 2.6. So you should be able to install and run Python 2.5. (*) http://docs.python.org/using/windows.html#installing-python -- Arnaud From staticd at gmail.com Sat Feb 27 22:37:50 2010 From: staticd at gmail.com (staticd) Date: Sat, 27 Feb 2010 19:37:50 -0800 (PST) Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> > >Amusing how long those Python toes can be. In several replies I have > >noticed (often clueless) opinions on Perl. When do people learn that a > >language is just a tool to do a job? > > When do people learn that language makes a difference? ?I used to be a > Perl programmer; these days, you'd have to triple my not-small salary to > get me to even think about programming in Perl. dude, you nailed it. many times, if not _always_, the correct output is important. the method used to produce the output is irrelevant. From wuhrrr at gmail.com Sat Feb 27 23:15:43 2010 From: wuhrrr at gmail.com (Hai Vu) Date: Sat, 27 Feb 2010 20:15:43 -0800 (PST) Subject: stripping fields from xml file into a csv References: Message-ID: On Feb 27, 12:50?pm, Hal Styli wrote: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite > in python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > < .... cust="harry" .... product="bread" ... quantity="1" ...> > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick > ways of achieving the above by using python's XML capabilities to > parse the original file or python's regex to achive what I did using > sed. > > Thanks for any constructive help given. > > Hal Here is a sample XML file (I named it data.xml): -------------------------- -------------------------- Code: -------------------------- import csv import xml.sax # Handle the XML file with the following structure: # # ... # class OrdersHandler(xml.sax.handler.ContentHandler): def __init__(self, csvfile): # Open a csv file for output self.csvWriter = csv.writer(open(csvfile, 'w')) def startElement(self, name, attributes): # Only process the element if name == 'order': # Construct a sorted list of attribute names in order to # guarantee rows are written in the same order. We assume # the XML elements contain the same attributes attributeNames = attributes.getNames() attributeNames.sort() # Construct a row and write it to the csv file row = [] for name in attributeNames: row.append(attributes.getValue(name)) self.csvWriter.writerow(row) def endDocument(self): # Destroy the csv writer object to close the file self.csvWriter = None # Main datafile = 'data.xml' csvfile = 'data.csv' ordersHandler = OrdersHandler(csvfile) xml.sax.parse(datafile, ordersHandler) -------------------------- To solve your problem, it is easier to use SAX than DOM. Basically, use SAX to scan the XML file, if you encounter the element you like (in this case ) then you process its attributes. In this case, you sort the attributes, then write to a csv file. -------------------------- References: SAX Parser: http://docs.python.org/library/xml.sax.html SAX Content Handler: http://docs.python.org/library/xml.sax.handler.html Attributes Object: http://docs.python.org/library/xml.sax.reader.html#attributes-objects From greg.ewing at canterbury.ac.nz Sat Feb 27 23:27:11 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Feb 2010 17:27:11 +1300 Subject: random.gauss: range In-Reply-To: <4b888905$0$27844$c3e8da3@news.astraweb.com> References: <4b888905$0$27844$c3e8da3@news.astraweb.com> Message-ID: <7uu91gFh1gU1@mid.individual.net> Steven D'Aprano wrote: > def pinned_gaussian(a, b, mu, sigma): > """Return a Gaussian random number pinned to [a, b].""" > return min(b, max(a, random.gauss(mu, sigma))) > > def truncated_gauss(a, b, mu, sigma): > """Return a random number from a truncated Gaussian distribution.""" > while 1: > x = random.gauss(mu, sigma) > if a <= x <= b: > return x If it doesn't have to be strictly gaussian, another way is to approximate it by adding some number of uniformly distributed samples together. If you have n uniform samples ranging from 0 to a, the sum will be in the range 0 to n*a and the mean will be n*a/2. The greater the value of n, the closer the distribution will be to normal. -- Greg From pfeldman at verizon.net Sat Feb 27 23:35:28 2010 From: pfeldman at verizon.net (Dr. Phillip M. Feldman) Date: Sat, 27 Feb 2010 20:35:28 -0800 (PST) Subject: Turtle graphics speed(). Seems broken In-Reply-To: <47B5B897.2030300@behnel.de> References: <47B5B897.2030300@behnel.de> Message-ID: <27732940.post@talk.nabble.com> Stefan Behnel-3 wrote: > > Alexander.Oot at gmail.com wrote: >> I think the speed function may be broken from the turtle graphics package >> >> >> "from turtle import * >> >> speed('fastest') >> >> forward(50)" >> >> >> I have tried all of the different speed settings, but I get no change >> in the turtle's speed.... does anyone know how to fix this? > > Use "xturtle"? :) > > http://ada.rg16.asn-wien.ac.at/~python/xturtle/ > > Stefan > -- > http://mail.python.org/mailman/listinfo/python-list > > The Python library's implementation of turtle graphics is slow to the point that many applications are simply impractical. I recently converted a program to Python/turtle graphics that was originally written by my son using Processing; the result of the conversion is that the time to draw the balls increased by a factor of roughly 50! (The Processing version takes less than 0.1 seconds to generate the image, while the Python version takes almost 5 seconds on the same computer). It would be good if this performance problem can be fixed, either by patching the current implementation of turtle graphics, or by replacing it with xturtle if that is better. http://old.nabble.com/file/p27732940/balls.py balls.py -- View this message in context: http://old.nabble.com/Turtle-graphics-speed%28%29.-Seems-broken-tp15504443p27732940.html Sent from the Python - python-list mailing list archive at Nabble.com. From rjngrj2010 at gmail.com Sun Feb 28 00:46:21 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sat, 27 Feb 2010 21:46:21 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: On Feb 27, 9:36?pm, Rick Dooling wrote: > > Hi, > > I have been trying to install python on my Win ME system > > Try this: > > http://tinyurl.com/w7wgp > > RD I gave it a shot but the site installs the same version of ActivePython which did install on my computer but does not open any command windows. See my earlier posted e-mail. Thanks anyway, From alfps at start.no Sun Feb 28 00:49:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Feb 2010 06:49:22 +0100 Subject: Turtle graphics speed(). Seems broken In-Reply-To: References: <47B5B897.2030300@behnel.de> Message-ID: * Dr. Phillip M. Feldman: > > Stefan Behnel-3 wrote: >> Alexander.Oot at gmail.com wrote: >>> I think the speed function may be broken from the turtle graphics package >>> >>> >>> "from turtle import * >>> >>> speed('fastest') >>> >>> forward(50)" >>> >>> >>> I have tried all of the different speed settings, but I get no change >>> in the turtle's speed.... does anyone know how to fix this? >> Use "xturtle"? :) >> >> http://ada.rg16.asn-wien.ac.at/~python/xturtle/ >> >> Stefan >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > The Python library's implementation of turtle graphics is slow to the point > that many applications are simply impractical. I recently converted a > program to Python/turtle graphics that was originally written by my son > using Processing; the result of the conversion is that the time to draw the > balls increased by a factor of roughly 50! (The Processing version takes > less than 0.1 seconds to generate the image, while the Python version takes > almost 5 seconds on the same computer). It would be good if this > performance problem can be fixed, either by patching the current > implementation of turtle graphics, or by replacing it with xturtle if that > is better. http://old.nabble.com/file/p27732940/balls.py balls.py Try to add turtle.tracer( 0 ) before generating the graphics, and turtle.update() after. It sort of speeds things up. :-) To test it I had to rewrite your code a little, getting rid of the numpy dependency since I don't have numpy installed. Looks like this: #from numpy import * def array( data, dtype ): return data # Emulate numpy array constructor import random from math import * import sys from time import time import turtle # turtle graphics module class Timer: """Track and record elapsed time, allowing an arbitrary number of timers.""" from time import time # Constructor: def __init__(self): self.start= time() # Report elapsed time: def time(self): # Compute elapse time: elapsed= time() - self.start # Print elapsed time in seconds: print str(elapsed) + ' s', # If total elapsed time exceeds 60 seconds, also print time as # as minutes and seconds: if elapsed >= 60.0: minutes= numpy.floor(elapsed / 60.0) elapsed-= 60 * minutes print '= ' + num2str(minutes,0) + ' m ' + num2str(elapsed,3) + ' s' else: print def main(): # Section 1: User inputs. All four arrays should have the same dimensions. balls_of_type = array([20, 20], dtype=int) radius_of_type= array([35, 25], dtype=float) mass_of_type = array([4 , 2], dtype=float) color_of_type = array([0 , 1], dtype=int) canvas_width = 1000 # canvas width in pixels canvas_height= 800 # canvas height in pixels # Section 2: Setup. # Section 2.1: Initialize graphics. turtle.setup(width=canvas_width, height=canvas_height) # Use units of pixels for specifying locations on the screen: turtle.setworldcoordinates(0.0, 0.0, canvas_width, canvas_height) # Set background color to black: turtle.bgcolor("black") # We want to specify R, G, and B using whole numbers from 0 to 255: turtle.colormode(255) # Turn off animation and hide the turtle to get maximum drawing speed: turtle.speed('fastest') turtle.tracer( 0 ) turtle.hideturtle() # Section 2.2: Preliminaries. ball_types= len(balls_of_type) max_tries= 1000 tries= 0 # The following variable counts the number of time ticks: tick= 0 colors= [ (255, 0, 0), # red ( 64, 64, 230), # blue, cobalt blue (125, 0, 0), # maroon ( 0, 255, 255), # cyan,baby blue (255, 140, 0), # orange ( 0, 255, 0), # green, light green (204, 128, 0), # brown (255, 200, 120), # light orange (255, 255, 140), # cream (0, 128, 0), # dark green, forest green (255, 128, 128), # peach (255, 255, 0), # yellow (0, 0, 204), # dark blue, navy blue (150, 355, 150), # light green (128, 0, 230), # purple (77, 204, 0), # avocado (255, 128, 255), # magenta, pink (0, 204, 204), # aqua, turquoise (230, 192, 0), # gold (255, 255, 255), # white ] # Allocate 2-element lists for basis and velocity vectors: u_hat= [0,0] v_hat= [0,0] uv_speed1b= [0,0]; # before the collision uv_speed2b= [0,0]; # before the collision uv_speed1a= [0,0]; # after the collision uv_speed2a= [0,0]; # after the collision # Section 2.3: Calculate the number of balls and allocate arrays whose sizes # depend on this. # `balls` is the total number of balls: balls= sum( balls_of_type ) x = balls*[0.0] #zeros(balls, dtype=float) y = balls*[0.0] #zeros(balls, dtype=float) x_speed = balls*[0.0] #zeros(balls, dtype=float) y_speed = balls*[0.0] #zeros(balls, dtype=float) radius = balls*[0.0] #zeros(balls, dtype=float) mass = balls*[0.0] #zeros(balls, dtype=float) ball_type = balls*[0] #zeros(balls, dtype=int) ball_color= [] # empty list # Section 2.4: Assign a ball type, radius, mass, color, initial position, # and initial velocity to each ball. n= -1 for i in range(ball_types): # Valid color numbers are 0-19. If the color number of a ball type is # greater than 19, the following line of code fixes the problem by randomly # assigning acolor number. if color_of_type[i] >= 20: color_of_type[i]= random.randint(0, 20) # In the following loop, j is the ball number for the ith type of ball: for j in range(balls_of_type[i]): # After the following statement executes, `n` will be one less than the # number of balls generated. n+= 1 ball_type[n]= i radius[n]= radius_of_type[i] mass [n]= mass_of_type [i] ball_color.append( colors[color_of_type[i]] ) # Continue loop until center coordinates for ball[n] are such that this # ball does not overlap any previously generated ball. If the number of # iterations exceeds max_tries, then the program stops the loop if this # happens, the program doesn't work because there is not enough space # for all the balls in the container. for tries in range(max_tries): # generate random ball center coordinates: keepout= radius[n] + 2.0 x[n]= random.uniform(keepout, canvas_width - keepout) y[n]= random.uniform(keepout, canvas_height - keepout) # Check to see if two balls have been generated on top of each other. # First, we set good to True. True means that this ball does not # overlap any of the other balls that we have checked so far. At the # end of the inner loop, if good= False, this means that the ball did # overlap at least one of the previous balls, and the program goes back # to the top of the outer loop and generates new coordinates for the # current ball. good= True for m in range(n): # innermost loop dx= x[m] - x[n] dy= y[m] - y[n] d= sqrt(dx*dx + dy*dy) if (d <= radius[m] + radius[n] + 10): good= False break # end for inner for loop if good: break # end of loop over tries if not good: print "\nERROR: Not enough space for balls.\n" sys.exit() # Assign a random initial velocity to the current ball: theta= random.uniform(0.0, 2.0*pi) x_speed[n]= 2. * cos(theta) y_speed[n]= 2. * sin(theta) # end of loop over j (number of ball of current ball type) # end of loop over i (number of ball type) # Section 3: Draw the balls. # Initialize timer: t= Timer() for n in range(balls): turtle.penup() turtle.goto(x[n], y[n]) turtle.pendown() turtle.color(ball_color[n]) turtle.begin_fill() turtle.circle(radius[n]) turtle.end_fill() turtle.update() # Display elapsed time: print "Total drawing time: ", t.time() raw_input('Hit Enter to close figure window.') if __name__ == "__main__": msg = main() print(msg) Cheers & hth., - Alf From rjngrj2010 at gmail.com Sun Feb 28 00:51:32 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sat, 27 Feb 2010 21:51:32 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <6b04c31f-fdaa-4f63-99fb-5bebe7ae4b0e@z11g2000yqz.googlegroups.com> Message-ID: <2feb50ee-515f-48d9-99c0-772327597217@b7g2000yqd.googlegroups.com> On Feb 27, 9:56?pm, staticd wrote: > On Feb 27, 8:48?pm, gujax wrote: > > > I have been trying to install python on my Win ME system for over two > > years - gave up for a while and now I am back with a resolve to solve > > the problem. > > Dude. ?Give up. ?There are a ton of __free__ distroz of linux out > there. ?Your troubles are not worth the effort. ?Why do I say this? > Let's say you do, eventually, figure out what's wrong. ?Now what? > > Why are you so attached to this machine with ME on it? > > nd I agree with you. I have a CD of Xubuntu. I tried booting up with the CD and was impressed. I noticed few problems with screen resolution, window size etc. I am not yet sure which distroz is the best for an instrument with a 512 Mb RAM, 700MHz pentium III chip and about 10Gb mem. Not sure if this is the right forum for this topic though, And no, I am not at all attached to Win, though wouldn't say the same for my computer. Cheers, gujax From spamfresser at ch3ka.de Sun Feb 28 01:07:41 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 28 Feb 2010 07:07:41 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: Am 27.02.2010 10:00, schrieb alex23: > Michael Rudolf wrote: >> In Java, Method Overloading is my best friend > > Guido wrote a nice article[1] on "multimethods" using decorators, > which Ian Bicking followed up on[2] with a non-global approach. > > 1: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 > 2: http://blog.ianbicking.org/more-on-multimethods.html Nice! I really liked http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/ From aahz at pythoncraft.com Sun Feb 28 02:22:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 23:22:31 -0800 Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: In article , Tim Chase wrote: >Luis M. Gonz?lez wrote: >> >> If you want a list of items, you use tuples or lists. Examples: >> >> ('a', 'm', 'p') ---> this is a tuple, and it's made with >> parenthesis () > >Actually, a tuple is made with commas...the parens are just there >to clarify the order of operations and make it easier to read :) > > >>> x = 1,2,3 > >>> x > (1, 2, 3) Almost true: >>> x = () >>> x () Parentheses are definitely needed for the empty tuple. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Sun Feb 28 02:28:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 23:28:39 -0800 Subject: Is this secure? References: <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: In article , Robert Kern wrote: > >If you are storing the password instead of making your user remember >it, most platforms have some kind of keychain secure password >storage. I recommend reading up on the APIs available on your targeted >platforms. Are you sure? I haven't done a lot of research, but my impression was that Windows didn't have anything built in. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From trstrstrs123 at gmail.com Sun Feb 28 02:48:22 2010 From: trstrstrs123 at gmail.com (trstrstrs trstrstrs) Date: Sat, 27 Feb 2010 23:48:22 -0800 (PST) Subject: Paper Presentation Topics Message-ID: Paper Presentation Topics. Our database posses huge collection of topics for paper presentations in all areas. Check all our paper presentation topics at http://pptcontent.blogspot.com/ Paper Presentation Topics Paper presentation topics for ece ">Paper presentation topics for ece Paper presentation topics for cse Paper presentation topics for it Paper presentation topics for eee Paper presentation topics for mba Paper presentation topics for civil engineering Paper presentation topics for mechanical engineering Our sample list list of paper presentation topics in all area branches : Hot Topics : | Lunar Solar Power | | Speech Recognition | | Bullet Proof Vests | | Nano Robos | | Diamond Search | | Brain Controlled Car | From stefan_ml at behnel.de Sun Feb 28 03:05:11 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 09:05:11 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: References: Message-ID: Hal Styli, 27.02.2010 21:50: > I have a sed solution to the problems below but would like to rewrite > in python... Note that sed (or any other line based or text based tool) is not a sensible way to handle XML. If you want to read XML, use an XML parser. They are designed to do exactly what you want in a standard compliant way, and they can deal with all sorts of XML formatting and encoding, for example. > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > < .... cust="harry" .... product="bread" ... quantity="1" ...> > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > As others have noted, this doesn't tell much about your XML. A more complete example would be helpful. > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick > ways of achieving the above by using python's XML capabilities to > parse the original file or python's regex to achive what I did using > sed. It's funny how often people still think that SAX is a good way to solve XML problems. Here's an untested solution that uses xml.etree.ElementTree: from xml.etree import ElementTree as ET csv_field_order = ['cust', 'product', 'quantity'] clean_up_used_elements = None for event, element in ET.iterparse("thefile.xml", events=['start']): # you may want to select a specific element.tag here # format and print the CSV line to the standard output print(','.join(element.attrib.get(title, '') for title in csv_field_order)) # safe some memory (in case the XML file is very large) if clean_up_used_elements is None: # this assigns the clear() method of the root (first) element clean_up_used_elements = element.clear clean_up_used_elements() You can strip everything dealing with 'clean_up_used_elements' (basically the last section) if your XML file is small enough to fit into memory (a couple of MB is usually fine). Stefan From m.92ahesh at gmail.com Sun Feb 28 03:14:13 2010 From: m.92ahesh at gmail.com (jaagar) Date: Sun, 28 Feb 2010 00:14:13 -0800 (PST) Subject: Paper Presentation Topics Message-ID: Paper Presentation Topics. Our database posses huge collection of topics for paper presentations in all areas. Check all our paper presentation topics at http://pptcontent.blogspot.com/ Topics for Paper Presentation : Paper presentation topics for ece. Paper presentation topics for cse. Paper presentation topics for eee. Paper presentation topics for it. Paper presentation topics for mba. Paper presentation topics for mechanical engineering. Paper presentation topics for civil engineering. Paper presentation topics for eee. Our sample list list of paper presentation topics in all area branches : Hot Topics : Lunar Solar Power,Speech Recognition,Bullet Proof Vests,Nano Robos,Diamond Search,Brain Controlled Car From no.email at nospam.invalid Sun Feb 28 03:43:10 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Feb 2010 00:43:10 -0800 Subject: Is this secure? References: <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: <7xwrxxrbs1.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > Are you sure? I haven't done a lot of research, but my impression was > that Windows didn't have anything built in. I don't know much about the windows but there is the CAPI and then there is all the TCPA (i.e. DRM) stuff. Maybe it can be used somehow. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 28 03:48:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 08:48:31 GMT Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> Message-ID: <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 19:37:50 -0800, staticd wrote: >> >Amusing how long those Python toes can be. In several replies I have >> >noticed (often clueless) opinions on Perl. When do people learn that a >> >language is just a tool to do a job? >> >> When do people learn that language makes a difference? ?I used to be a >> Perl programmer; these days, you'd have to triple my not-small salary >> to get me to even think about programming in Perl. > > dude, you nailed it. many times, if not _always_, the correct output is > important. the method used to produce the output is irrelevant. Oh really? Then by that logic, you would consider that these two functions are both equally good. Forget readability, forget maintainability, forget efficiency, we have no reason for preferring one over the other since the method is irrelevant. def greet1(name): """Print 'Hello ' for any name.""" print "Hello", name def greet2(name): """Print 'Hello ' for any name.""" count = 0 for i in range(0, ("Hello", name).__len__(), 1): word = ("Hello", name).__getitem__(i) for i in range(0, word[:].__len__(), 1): c = word.__getitem__(i) import sys import string empty = '' maketrans = getattr.__call__(string, 'maketrans') chars = maketrans.__call__(empty, empty) stdout = getattr.__call__(sys, 'stdout') write = getattr.__call__(stdout, 'write') write.__call__(c) count = count.__add__(1) import operator eq = getattr.__call__(operator, 'eq') ne = getattr.__call__(operator, 'ne') if eq.__call__(count, 2): pass elif not ne.__call__(count, 2): continue write.__call__(chr.__call__(32)) write.__call__(chr.__call__(10)) return None There ought to be some kind of competition for the least efficient solution to programming problems-ly y'rs, -- Steven From gallium.arsenide at gmail.com Sun Feb 28 03:52:14 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Sun, 28 Feb 2010 00:52:14 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <6b04c31f-fdaa-4f63-99fb-5bebe7ae4b0e@z11g2000yqz.googlegroups.com> <2feb50ee-515f-48d9-99c0-772327597217@b7g2000yqd.googlegroups.com> Message-ID: <98403c0c-f545-4b96-bb1c-08e5f2bf5f3a@f8g2000yqn.googlegroups.com> On Feb 28, 12:51?am, gujax wrote: > I agree with you. I have a CD of Xubuntu. I tried > booting up with the CD and was impressed. I noticed > few problems with screen resolution, window size etc. Though it may be worth working out any niggling problems to switch to Linux, I don't think you should feel pressured to switch if you are comfortable with Win ME on that particular machine. > And no, I am not at all attached to Win, though wouldn't > say the same for my computer. It sounds like you could have switched to Linux and resolved any configuration problems in the two years you've been trying to install Python. ;) But that said, I have used older versions of Python without any trouble on Win ME. In fact, I still have a Win ME machine running 2.5.2. According to the docs, you have to have Microsoft Installer 2.0 (freely downloadable from Microsoft if necessary) to use the 2.5 MSI distribution: http://www.python.org/download/releases/2.5.4/ If for whatever reason you can't or don't want to do this, 2.3 still has an EXE distribution: http://www.python.org/download/releases/2.3.5/ John From brown_emu at yahoo.com Sun Feb 28 05:00:45 2010 From: brown_emu at yahoo.com (Stephen Tucker) Date: Sun, 28 Feb 2010 02:00:45 -0800 (PST) Subject: getting rpy2 from repository Message-ID: <655447.28185.qm@web39705.mail.mud.yahoo.com> Hi all, I have Enthought Python 4.3 installed on my OS X 10.5. When I do $ easy_install rpy2 Searching for rpy2 No matching release version found. Searching for latest development version. Reading http://www.enthought.com/repo/epd/eggs/MacOSX/10.4_x86/ Please enter credentials to access this repository: User Name: Is there a way to point to the original (non-Enthought) repository, or is there a better way? Thanks very much in advance! Stephen From stefan_ml at behnel.de Sun Feb 28 06:05:12 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 12:05:12 +0100 Subject: Python dos2unix one liner In-Reply-To: <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 28.02.2010 09:48: > There ought to be some kind of competition for the least efficient > solution to programming problems That wouldn't be very interesting. You could just write a code generator that spits out tons of garbage code including a line that solves the problem, and then let it execute the code afterwards. That beast would always win. Stefan From dontsendleospam at gmail.com Sun Feb 28 06:45:38 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Sun, 28 Feb 2010 03:45:38 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> <4b89d880$0$27844$c3e8da3@news.astraweb.com> Message-ID: <6cc72563-2720-4fa9-a11a-6fe9f0b7e197@c37g2000prb.googlegroups.com> > > ...and really means this... > > class C: > > ? x = 1 > > ? def f(self,y): return T.x + y > > I don't understand what T is. Did you mean C? Yes, I meant C. Thanks. > > If so, you are wrong. self.x is not the same as .x due to > inheritance rules. Consider one example: > Thanks for the nice example. Sorry for my loose language. By "really means", what I really meant was that the most appropriate construct should be the one referring to the class variable explicitly. I would consider it inelegant (at least) to use an instance variable with the same name as a class variable. > > > 1. Has this been discussed before? > > Yes. > > > 1. What would this suggestion break? > > Nearly all existing code using classes, which is nearly everything. Is it that common to have code containing a class variable with the same name as a global variable? Are there other use cases that would break? > > > 2. What are the advantages of making the scope of class variables > > different? Maybe is it just a historical trait? > > See the discussion in the PEP for introducing nested scopes in the first > place: > > http://www.python.org/dev/peps/pep-0227/ > Thanks. That is really useful. I just read the PEP. I find this paragraph very helpful: "An alternative would have been to allow name binding in class scope to behave exactly like name binding in function scope. This rule would allow class attributes to be referenced either via attribute reference or simple name. This option was ruled out because it would have been inconsistent with all other forms of class and instance attribute access, which always use attribute references. Code that used simple names would have been obscure." The point about all other access use cases requiring attribute references is a really good one. If a language requires self.f() to access the member f of class C, which happens to be a function, then self.x or C.x should also be required to access attribute x. And no one would be crazy enough to ask to have that fixed. @Steven: Are there other snippets from the PEP you were pointing to specifically? Cheers, Leo. From martin.hellwig at dcuktec.org Sun Feb 28 06:51:31 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 28 Feb 2010 11:51:31 +0000 Subject: Python dos2unix one liner In-Reply-To: References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 02/28/10 11:05, Stefan Behnel wrote: > Steven D'Aprano, 28.02.2010 09:48: >> There ought to be some kind of competition for the least efficient >> solution to programming problems > > That wouldn't be very interesting. You could just write a code generator > that spits out tons of garbage code including a line that solves the > problem, and then let it execute the code afterwards. That beast would > always win. > > Stefan > Well that would be an obvious rule that garbage code that does not contribute to the end result (ie can be taken out without affecting the end result) would not be allowed. Enforcing the rule is another beast though, but I would leave that to the competition. Though the idea of a code generator is solid, but instead of generating garbage, produces a virtual machine that implements a generator that produces a virtual machine, etc. etc. -- mph From roland.em0001 at googlemail.com Sun Feb 28 07:01:03 2010 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Sun, 28 Feb 2010 14:01:03 +0200 Subject: stripping fields from xml file into a csv In-Reply-To: References: Message-ID: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> Hello, 2010/2/28 Stefan Behnel > Hal Styli, 27.02.2010 21:50: > > I have a sed solution to the problems below but would like to rewrite > > in python... > > Note that sed (or any other line based or text based tool) is not a > sensible way to handle XML. If you want to read XML, use an XML parser. > They are designed to do exactly what you want in a standard compliant way, > and they can deal with all sorts of XML formatting and encoding, for > example. > > > > I need to strip out some data from a quirky xml file into a csv: > > > > from something like this > > > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > > < .... cust="harry" .... product="bread" ... quantity="1" ...> > > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > As others have noted, this doesn't tell much about your XML. A more > complete example would be helpful. > > > > to this > > > > dick,eggs,12 > > tom,milk,2 > > harry,bread,1 > > tom,eggs,6 > > dick,eggs,6 > > > > I am new to python and xml and it would be great to see some slick > > ways of achieving the above by using python's XML capabilities to > > parse the original file or python's regex to achive what I did using > > sed. > > another solution in this case could be to use an XSLT stylesheet. That way the input processing is defined in an XSLT stylesheet. The stylesheet is test.xsl and the insput data test.xml. The following Python code the applies the stylesheet on the input data and puts the output into foo. Python code: #!/usr/bin/python import sys import libxml2 import libxslt styledoc = libxml2.parseFile("test.xsl") style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseFile("test.xml") result = style.applyStylesheet(doc, None) style.saveResultToFilename("foo", result, 0) BR, Roland *Example run in Linux:* roland at komputer:~/Desktop/XML/XSLT$ ./xslt_test.py roland at komputer:~/Desktop/XML/XSLT$ cat foo john,eggs,12 cindy,bread,1 larry,tea bags,100 john,butter,1 derek,chicken,2 derek,milk,2 * The test.xsl stylesheet:* , , -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun Feb 28 07:15:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 13:15:09 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> References: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> Message-ID: Roland Mueller, 28.02.2010 13:01: > The stylesheet is test.xsl and the insput data test.xml. The following > Python code the applies the stylesheet on the input data and puts the output > into foo. > > Python code: > #!/usr/bin/python > import sys > import libxml2 > import libxslt > > styledoc = libxml2.parseFile("test.xsl") > style = libxslt.parseStylesheetDoc(styledoc) > doc = libxml2.parseFile("test.xml") > result = style.applyStylesheet(doc, None) > style.saveResultToFilename("foo", result, 0) > > BR, > Roland > > *Example run in Linux:* > roland at komputer:~/Desktop/XML/XSLT$ ./xslt_test.py Note that the shorthand for the above is $ xsltproc test.xsl test.xml > foo Stefan From spamfresser at ch3ka.de Sun Feb 28 07:38:14 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 28 Feb 2010 13:38:14 +0100 Subject: Method / Functions - What are the differences? Message-ID: Out of curiosity I tried this and it actually worked as expected: >>> class T(object): x=[] foo=x.append def f(self): return self.x >>> t=T() >>> t.f() [] >>> T.foo(1) >>> t.f() [1] >>> At first I thought "hehe, always fun to play around with python. Might be useful sometimes" - but then It really confused me what I did. I mean: f is what we call a method, right? But was is foo? It is not a method and not a classmethod as it accepts no self and no cls. So that leaves staticmethod? OK, fair, as x is "static" here anyway this reflects what it does. But then consider this: >>> class T(object): def __init__(self): self.x=[] self.foo=self.x.append def f(self): return self.x >>> y=T() >>> y.x [] >>> y.foo(1) >>> y.x [1] >>> a=T() >>> a.x [] >>> a.foo(2) >>> a.x [2] >>> Note that all I did was moving the list and foo into the instance. Still no self and no cls, but also no static behaviour any more. So is foo just nothing of the above and really only a class/instance attribute which happens to be callable? Perhaps this all does not matter, but now I am really confused about the terminology. So: what makes a method a method? And of what type? Regards, Michael From albert at spenarnc.xs4all.nl Sun Feb 28 07:43:51 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 28 Feb 2010 12:43:51 GMT Subject: problem with floats and calculations References: Message-ID: In article , Dennis Lee Bieber wrote: >On Sun, 14 Feb 2010 10:33:54 +0100, Karsten Goen > declaimed the following in >gmane.comp.python.general: > >> Maybe anyone can help me with this problem, I don't want to generate for >> every possible user input a single formula. And also it should be possible >> for a computer, my calculator at home does the same and is much smaller and >> slower. >> > Most ALL calculators that I've encountered use packed BCD internally >for numeric data. That is -- two decimal digits (0-9) and a few special >codes (mantissa sign, exponent sign, decimal point location, and >exponent start). A lot of them (though strangely not HP) included "guard >digits" -- they would display, say, 8 significant digits for results, >but kept 10 digits internally, so that rounding errors wouldn't >accumulate as rapidly. M$ Excel/Access/VisualBasic "money" data type What is displayed has no influence on rounding errors. Calculator vendors prevent puzzlement by non-knowledgeable users by having guard digits. HP apparently deals with professional users, so I think it not strange at all. >carries four decimal places, on the assumption that only two are >significant, and the last two are guards. > > Most ALL computers are using IEEE floating point (and the exceptions >are still a binary floating point, not a decimal representation). > > The practice, which /used to be/ taught, is that one does not >compare floating numbers for equality, but rather one compares the >difference between floating numbers to be less than some epsilon value; >epsilon chosen depending upon the significance needed. > > Rather than comparing > > a = b > >one uses > > abs(a - b) < epsilon > > Since Decimal() also has "infinite" series values (1.0/3.0), an >epsilon comparison may also be called for. Not may be. >-- > Wulfraed Dennis Lee Bieber KD6MOG Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From roland.em0001 at googlemail.com Sun Feb 28 08:21:26 2010 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Sun, 28 Feb 2010 15:21:26 +0200 Subject: stripping fields from xml file into a csv In-Reply-To: References: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> Message-ID: <42dbeab41002280521s73b01689x82f8f73f60da5587@mail.gmail.com> 2010/2/28 Stefan Behnel > Roland Mueller, 28.02.2010 13:01: > > The stylesheet is test.xsl and the insput data test.xml. The following > > Python code the applies the stylesheet on the input data and puts the > output > > into foo. > > > > Python code: > > #!/usr/bin/python > > import sys > > import libxml2 > > import libxslt > > > > styledoc = libxml2.parseFile("test.xsl") > > style = libxslt.parseStylesheetDoc(styledoc) > > doc = libxml2.parseFile("test.xml") > > result = style.applyStylesheet(doc, None) > > style.saveResultToFilename("foo", result, 0) > > > > BR, > > Roland > > > > *Example run in Linux:* > > roland at komputer:~/Desktop/XML/XSLT$ ./xslt_test.py > > Note that the shorthand for the above is > > $ xsltproc test.xsl test.xml > foo > > yes, that's true, and probably the best way to use XML stylesheets in Linux. However, this is a Python ML, and so I was sending the Python example. The original poster does not necessarily use Linux, and I do not know about Windos tools in that regard. BR, Roland > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sun Feb 28 08:48:40 2010 From: john at castleamber.com (John Bokma) Date: Sun, 28 Feb 2010 07:48:40 -0600 Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <4b89cee0$0$27844$c3e8da3@news.astraweb.com> Message-ID: <87pr3pa2tj.fsf@castleamber.com> Steven D'Aprano writes: > On Sat, 27 Feb 2010 11:27:04 -0600, John Bokma wrote: > >> When do people learn that a >> language is just a tool to do a job? > > When do people learn that there are different sorts of tools? A > professional wouldn't use a screwdriver when they need a hammer. [...] > Languages are not just nebulous interchangeable "tools", they're tools A hammer is just a tool to do a job. Doesn't mean one must or should use a hammer to paint a wall. > for a particular job with particular strengths and weaknesses, and > depending on what strengths you value and what weaknesses you dislike, > some tools simply are better than other tools for certain tasks. In short, we agree. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alfps at start.no Sun Feb 28 09:08:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Feb 2010 15:08:49 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: Message-ID: * Michael Rudolf: > Out of curiosity I tried this and it actually worked as expected: > > >>> class T(object): > x=[] > foo=x.append > def f(self): > return self.x > > > >>> t=T() > >>> t.f() > [] > >>> T.foo(1) > >>> t.f() > [1] > >>> > > At first I thought "hehe, always fun to play around with python. Might > be useful sometimes" - but then It really confused me what I did. I > mean: f is what we call a method, right? But was is foo? foo is (refers to) an object that supports call notation and that forwards calls somewhere else, in this case to append on a list. You might call it (descriptive) a call forwarder, or (C# or general terminology) a delegate, or (Python 2.x) a bound method. >>> "Hello".upper >>> f = "Hello".upper >>> f >>> f() 'HELLO' >>> >>> >>> >>> f.__self__ 'Hello' >>> f.__call__ >>> print( f.__doc__ ) S.upper() -> str Return a copy of S converted to uppercase. >>> _ A common use for delegates is as command handlers in a GUI application, and in general for event notifications. Cheers & hth., - Alf From rtw at rtw.me.uk Sun Feb 28 09:24:06 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Sun, 28 Feb 2010 08:24:06 -0600 Subject: Method / Functions - What are the differences? References: Message-ID: Michael Rudolf wrote in news:hmdo3m$287$1 at news.urz.uni-heidelberg.de in comp.lang.python: > Note that all I did was moving the list and foo into the instance. Still > no self and no cls, but also no static behaviour any more. Yes in the first case foo was an attribute of the class, and in the second an attribute of aon instance of the class. In both cases it was a bound method, something similar too: lambda item : T.x.append( item ) From fordhaivat at gmail.com Sun Feb 28 09:28:07 2010 From: fordhaivat at gmail.com (Someone Something) Date: Sun, 28 Feb 2010 09:28:07 -0500 Subject: cpan for python? Message-ID: Is there something like cpan for python? I like python's syntax, but I use perl because of cpan and the tremendous modules that it has. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Sun Feb 28 09:31:56 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 28 Feb 2010 09:31:56 -0500 Subject: cpan for python? In-Reply-To: References: Message-ID: <383DBB77-A002-4C7D-9DB4-1371AF693070@gmail.com> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: > Is there something like cpan for python? I like python's syntax, but I use perl because of cpan and the tremendous modules that it has. -- Please search the mailing list archives. This subject has been discussed to absolute death. Draw your own conclusions about what is currently and may, in the future, be available. S From vicente.soler at gmail.com Sun Feb 28 09:42:00 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 28 Feb 2010 06:42:00 -0800 (PST) Subject: Printing the arguments of an attribute in a class Message-ID: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> I have a class that is a wrapper: class wrapper: def __init__(self, object): self.wrapped = object def __getattr__(self, attrname): print 'Trace: ', attrname #print arguments to attrname, how? return getattr(self.wrapped, attrname) I can run it this way: >>> x = wrapper([1,2,3]) >>> x.append(4) Trace: append >>> x.wrapped [1, 2, 3, 4] I am able to capture the attribute name to x (that is, append). However, I do not know how to capture and print all of its arguments (in this case number 4). How should I proceed? Thank you From alfps at start.no Sun Feb 28 10:00:19 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Feb 2010 16:00:19 +0100 Subject: Printing the arguments of an attribute in a class In-Reply-To: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> References: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> Message-ID: * vsoler: > I have a class that is a wrapper: > > class wrapper: > def __init__(self, object): > self.wrapped = object > def __getattr__(self, attrname): > print 'Trace: ', attrname > #print arguments to attrname, how? > return getattr(self.wrapped, attrname) > > I can run it this way: > >>>> x = wrapper([1,2,3]) >>>> x.append(4) > Trace: append >>>> x.wrapped > [1, 2, 3, 4] > > I am able to capture the attribute name to x (that is, append). > However, I do not know how to capture and print all of its arguments > (in this case number 4). > > How should I proceed? If your goal is just learning then in your __getattr__ you might return a wrapper for the attribute instead of the attribute itself. Equip the wrapper with a __call__ method if it is a method. And equip it with other special methods as appropriate. I can imagine that that approach will lead to some practical problems, but it may be great for learning. If your goal is tracing, then I suggest looking at the "trace" module. If your goal is something else purely practical, like intercepting method calls to do arbitrary things (logging, marshaling, whatever) then I suspect that it might getspretty complicated, hairy. For specific method calls you might just use subclassing, but for doing this in general, parameterized, you'd need to about the same kinds of things as the trace module does. So I guess then one idea might be to look at the source code of that module. But if that's what you intend to do, then best check first if there is an existing solution. ParcPlace did this thing for a number of languages and introduced a special term for it, I can't recall but something like "cross-whatever mumbo jumbo concerns" plus one single catchy name. There might be an existing Python implementation. Cheers & hth., - Alf From vicente.soler at gmail.com Sun Feb 28 10:31:30 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 28 Feb 2010 07:31:30 -0800 (PST) Subject: Printing the arguments of an attribute in a class References: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> Message-ID: On Feb 28, 4:00?pm, "Alf P. Steinbach" wrote: > * vsoler: > > > > > I have a class that is a wrapper: > > > class wrapper: > > ? ? def __init__(self, object): > > ? ? ? ? self.wrapped = object > > ? ? def __getattr__(self, attrname): > > ? ? ? ? print 'Trace: ', attrname > > ? ? ? ? #print arguments to attrname, how? > > ? ? ? ? return getattr(self.wrapped, attrname) > > > I can run it this way: > > >>>> x = wrapper([1,2,3]) > >>>> x.append(4) > > Trace: ?append > >>>> x.wrapped > > [1, 2, 3, 4] > > > I am able to capture the attribute name to x (that is, append). > > However, I do not know how to capture and print all of its arguments > > (in this case number 4). > > > How should I proceed? > > If your goal is just learning then in your __getattr__ you might return a > wrapper for the attribute instead of the attribute itself. Equip the wrapper > with a __call__ method if it is a method. And equip it with other special > methods as appropriate. > > I can imagine that that approach will lead to some practical problems, but it > may be great for learning. > > If your goal is tracing, then I suggest looking at the "trace" module. > > If your goal is something else purely practical, like intercepting method calls > to do arbitrary things (logging, marshaling, whatever) then I suspect that it > might getspretty complicated, hairy. For specific method calls you might just > use subclassing, but for doing this in general, parameterized, you'd need to > about the same kinds of things as the trace module does. So I guess then one > idea might be to look at the source code of that module. > > But if that's what you intend to do, then best check first if there is an > existing solution. ParcPlace did this thing for a number of languages and > introduced a special term for it, I can't recall but something like > "cross-whatever mumbo jumbo concerns" plus one single catchy name. There might > be an existing Python implementation. > > Cheers & hth., > > - Alf Alf, My goal is just learning. In the code provided in the post I just can't think of a method to "see", "capture" or "use" the parameters. I am going to study the __call__ method and see if I can figure out how I can capture the parameters. Thank you Alf From fetchinson at googlemail.com Sun Feb 28 11:27:22 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 28 Feb 2010 17:27:22 +0100 Subject: cpan for python? In-Reply-To: References: Message-ID: > Is there something like cpan for python? I like python's syntax, but I use > perl because of cpan and the tremendous modules that it has. It's called PyPI or Cheese Shop: http://pypi.python.org/pypi Is it only me or others also mentally read C-SPAN when somebody writes CPAN? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From spamfresser at ch3ka.de Sun Feb 28 11:39:03 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 28 Feb 2010 17:39:03 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: Message-ID: Am 28.02.2010 15:08, schrieb Alf P. Steinbach: > >>> "Hello".upper > > >>> f = "Hello".upper > >>> f > > >>> f() > 'HELLO' > >>> > >>> > >>> > >>> f.__self__ > 'Hello' Holy hand grenade. You have no Idea how enlightened I feel right now :D Thank you, "bound method" was the term I forgot and your example... ...totally revealed the internals behind this to me. Especially the last line I quoted. I mean, I always knew *that* this works, but I never knew *why*. Regards, Michael From wuhrrr at gmail.com Sun Feb 28 11:41:21 2010 From: wuhrrr at gmail.com (Hai Vu) Date: Sun, 28 Feb 2010 08:41:21 -0800 (PST) Subject: stripping fields from xml file into a csv References: Message-ID: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> On Feb 28, 12:05?am, Stefan Behnel wrote: > Hal Styli, 27.02.2010 21:50: > > > I have a sed solution to the problems below but would like to rewrite > > in python... > > Note that sed (or any other line based or text based tool) is not a > sensible way to handle XML. If you want to read XML, use an XML parser. > They are designed to do exactly what you want in a standard compliant way, > and they can deal with all sorts of XML formatting and encoding, for example. > > > I need to strip out some data from a quirky xml file into a csv: > > > from something like this > > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > > < .... cust="harry" .... product="bread" ... quantity="1" ...> > > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > As others have noted, this doesn't tell much about your XML. A more > complete example would be helpful. > > > to this > > > dick,eggs,12 > > tom,milk,2 > > harry,bread,1 > > tom,eggs,6 > > dick,eggs,6 > > > I am new to python and xml and it would be great to see some slick > > ways of achieving the above by using python's XML capabilities to > > parse the original file or python's regex to achive what I did using > > sed. > > It's funny how often people still think that SAX is a good way to solve XML > problems. Here's an untested solution that uses xml.etree.ElementTree: > > ? ? from xml.etree import ElementTree as ET > > ? ? csv_field_order = ['cust', 'product', 'quantity'] > > ? ? clean_up_used_elements = None > ? ? for event, element in ET.iterparse("thefile.xml", events=['start']): > ? ? ? ? # you may want to select a specific element.tag here > > ? ? ? ? # format and print the CSV line to the standard output > ? ? ? ? print(','.join(element.attrib.get(title, '') > ? ? ? ? ? ? ? ? ? ? ? ?for title in csv_field_order)) > > ? ? ? ? # safe some memory (in case the XML file is very large) > ? ? ? ? if clean_up_used_elements is None: > ? ? ? ? ? ? # this assigns the clear() method of the root (first) element > ? ? ? ? ? ? clean_up_used_elements = element.clear > ? ? ? ? clean_up_used_elements() > > You can strip everything dealing with 'clean_up_used_elements' (basically > the last section) if your XML file is small enough to fit into memory (a > couple of MB is usually fine). > > Stefan This solution is so beautiful and elegant. Thank you. Now I am off to learn ElementTree. By the way, Stefan, I am using Python 2.6. Do you know the differences between ElementTree and cElementTree? From mwilson at the-wire.com Sun Feb 28 11:41:29 2010 From: mwilson at the-wire.com (Mel) Date: Sun, 28 Feb 2010 11:41:29 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > Mel wrote: > >> You could think of it as a not bad use of the design principle "Clear The >> Simple Stuff Out Of The Way First". Destinations are commonly a lot >> simpler than sources Calculations for immediate values could be just about anything. Mel. From victor.stinner at haypocalc.com Sun Feb 28 11:43:07 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Sun, 28 Feb 2010 17:43:07 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: <201002281743.07452.victor.stinner@haypocalc.com> Le samedi 27 f?vrier 2010 18:37:22, Daniel Fetchinson a ?crit : > It's google's hosting solution called app engine, for python web > applications: http://code.google.com/appengine/docs/python/gettingstarted/ > > I guess they also have some kind of a sandbox if they let people run > python on their machines, I'm not sure if it's open source though. Yes, Google AppEngine has its Python sandbox and the source code is available online. I don't know the license. I found 7 vulnerabilities in 1 hour :-) I contacted Google security team. To answer to your question "How is [AppEngine] different from your project?": * pysanbox has an import whitelist, whereas AppEngine has an import blacklist (subprocess, socket, ... builtin modules are replaced by safe versions). Import a Python module written in C is forbidden. * Import a module in AppEngine imports all symbols, whereas pysandbox uses also a symbol whitelist. * AppEngine doesn't have proxies, all objects are modifiable (eg. sys.path) There are other differences, but I prefer to wait for the answer from Google before telling you more :) AppEngine sandbox and pysandbox projects are very close: most protections are based on blacklists, whereas RestrictedPython is only based on whitelists. -- Victor Stinner http://www.haypocalc.com/ From arnodel at googlemail.com Sun Feb 28 12:51:44 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 28 Feb 2010 17:51:44 +0000 Subject: Printing the arguments of an attribute in a class References: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> Message-ID: vsoler writes: > I have a class that is a wrapper: > > class wrapper: > def __init__(self, object): > self.wrapped = object > def __getattr__(self, attrname): > print 'Trace: ', attrname > #print arguments to attrname, how? > return getattr(self.wrapped, attrname) > > I can run it this way: > >>>> x = wrapper([1,2,3]) >>>> x.append(4) > Trace: append >>>> x.wrapped > [1, 2, 3, 4] > > I am able to capture the attribute name to x (that is, append). > However, I do not know how to capture and print all of its arguments > (in this case number 4). > > How should I proceed? > > Thank you You could do something like this: class wrapper: def __init__(self, object): self.wrapped = object def __getattr__(self, attrname): print '** get attribute: ', self.wrapped, attrname return wrapper(getattr(self.wrapped, attrname)) def __call__(self, *args, **kwargs): print '** call with args: ', self.wrapped, args, kwargs return wrapper(self.wrapped(*args, **kwargs)) x = wrapper([1,2,3]) x.append(4) I haven't thought about it too much though. -- Arnaud From aahz at pythoncraft.com Sun Feb 28 12:55:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 28 Feb 2010 09:55:38 -0800 Subject: Challenge: escape from the pysandbox References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: In article , Daniel Fetchinson wrote: > >I guess they also have some kind of a sandbox if they let people run >python on their machines, I'm not sure if it's open source though. Thing is, I'm sure that Google uses a critical backstop to any Python-based sandbox: something like a chroot jail. The Python sandbox is mostly there to inform you about what you can and can't do; the real security is provided by the OS. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From misceverything at gmail.com Sun Feb 28 13:35:23 2010 From: misceverything at gmail.com (T) Date: Sun, 28 Feb 2010 10:35:23 -0800 (PST) Subject: Py2exe - Bad File Descriptor Message-ID: <0c04902d-03e8-4b0e-8dd3-3bbdf7ea09b6@z11g2000yqz.googlegroups.com> I have a Python script, which is a Windows Service, that I created an EXE of via py2exe. As part of the program, it calls some external binaries, one of which restarts the computer. When I'm logged in, this works fine. However, if I log out, the service stops and logs the following error in the Event Log: :(9, 'Bad file descriptor') Anyone have an idea what could be causing this? From fabfake at fake.org Sun Feb 28 14:10:55 2010 From: fabfake at fake.org (Fabiano) Date: Sun, 28 Feb 2010 20:10:55 +0100 Subject: Updates about Tk In-Reply-To: References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> <6adc$4b895233$4275d90a$6509@FUSE.NET> Message-ID: <4b8abf8e$0$1115$4fafbaef@reader4.news.tin.it> rantingrick ha scritto: > On Feb 27, 11:11 am, Kevin Walzer wrote: > > (...snip...) > >> Kevin Walzer >> Code by Kevinhttp://www.codebykevin.com > > Great post Kevin! The only thing i would like to add are my two > favorite references for learning Tkinter. They are not geared around > the new ttk stuff, but still 95% relevant to any Tkinter-ing > > http://effbot.org/tkinterbook/ > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ > > Thanks @All you guys for the explanations and links! Regards From stefan_ml at behnel.de Sun Feb 28 14:20:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 20:20:21 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> References: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> Message-ID: Hai Vu, 28.02.2010 17:41: > By the way, Stefan, I am using Python 2.6. Do you know the differences > between ElementTree and cElementTree? Use cElementTree, it's implemented in C and a lot faster and more memory friendly. http://effbot.org/zone/celementtree.htm#benchmarks http://codespeak.net/lxml/performance.html Stefan From aahz at pythoncraft.com Sun Feb 28 14:44:44 2010 From: aahz at pythoncraft.com (Aahz) Date: 28 Feb 2010 11:44:44 -0800 Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: In article , Ryan Kelly wrote: >On Wed, 2010-02-24 at 15:05 -0800, Aahz wrote: >> In article , >> Ryan Kelly wrote: >>> >>>Yes. The idea of having a "bootstrapping exe" is that actual >>>application code can be swapped out without having to overwrite the >>>executable file. As long as you don't change python versions, this >>>allows updates to be safe against system crashes, even on platforms >>>without atomic file replacement. >>> >>>So the frozen app does this in a background thread: >>> >>> Esky(sys.executable,"http://my.updates.com").auto_update() >>> >>>And it hits the given url, grabs the latest zipfile, downloads and >>>unpacks and atomically places it into the application directory. Et >>>viola, your app is at the latest version. >> >> How does this work with a running app? What if the app is a service? > >The changes will only take effect the next time the app is started - >currently there's no support for "hot upgrading" a running app. >From my POV, hot upgrading is less important than solid restart capabilities, particularly for services. Performing tasks like modifying the DB schema is also important (not the actual capability, but hooks for it). E.g., the next time the app starts, it should know that it's been upgraded. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From g.bogle at auckland.no.spam.ac.nz Sun Feb 28 16:15:29 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 01 Mar 2010 10:15:29 +1300 Subject: PyQt4.7 and PyQwt5.2.0 Message-ID: I installed the latest PyQt (4.7-1), then PyQwt 5.2.0, which was built with PyQt4.5.4. This line import PyQt4.Qwt5 as Qwt fails to load the DLL. Could this be the result of not using PyQt4 4.5.4? From missive at hotmail.com Sun Feb 28 16:17:30 2010 From: missive at hotmail.com (Lee Harr) Date: Mon, 1 Mar 2010 01:47:30 +0430 Subject: [ANNC] pynguin-0.1 (python-based 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 is the initial release, with many optimizations ??? and finer details yet to come. Please check it out ??? and let me know what you think. pynguin is tested with Python 2.6.4 and uses PyQt (4.6) ??? for its GUI elements. pynguin is released under GPLv3. Changes in pynguin-0.1: ??? - initial public release _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. https://signup.live.com/signup.aspx?id=60969 From misceverything at gmail.com Sun Feb 28 16:22:19 2010 From: misceverything at gmail.com (T) Date: Sun, 28 Feb 2010 13:22:19 -0800 (PST) Subject: Py2exe - Bad File Descriptor References: <0c04902d-03e8-4b0e-8dd3-3bbdf7ea09b6@z11g2000yqz.googlegroups.com> Message-ID: On Feb 28, 3:48?pm, Dennis Lee Bieber wrote: > On Sun, 28 Feb 2010 10:35:23 -0800 (PST), T > declaimed the following in gmane.comp.python.general: > > > I have a Python script, which is a Windows Service, that I created an > > EXE of via py2exe. ?As part of the program, it calls some external > > binaries, one of which restarts the computer. ?When I'm logged in, > > this works fine. ?However, if I log out, the service stops and logs > > the following error in the Event Log: > > > :(9, 'Bad file descriptor') > > > Anyone have an idea what could be causing this? > > ? ? ? ? Without code, one must play psychic... And I haven't dusted off the > Tarot cards, I Ching coins, and Crystal balls is some time (No, I don't > have a ouija board)... > > ? ? ? ? Could it be you have a mapped drive that gets disconnected when you > log off? > > ? ? ? ? Is the service being started as part of your login? > > ? ? ? ? Does it attempt to write to a console? > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ?HTTP://wlfraed.home.netcom.com/ Sorry for the lack of code - yes, it does try to write to the console. From what I'm finding, this error may be due to the fact that there is no "console" to write to when I'm logged off. However, I would like to be able to print to screen if I run the EXE in debug mode (i.e. "myservice.exe debug"). Do you know of any way around this? Also, I need to get the output generated from an external EXE - will subprocess.Popen cause problems if I use stdout=PIPE? Thanks for your help! From m.91ahesh at gmail.com Sun Feb 28 16:47:55 2010 From: m.91ahesh at gmail.com (ranga...............) Date: Sun, 28 Feb 2010 13:47:55 -0800 (PST) Subject: Earn Money Online without Investment Message-ID: <76315eb5-5e23-4267-9ff2-4ffe4332671b@b5g2000prd.googlegroups.com> Earn Money Online without Investment Now anyone can earn money online with out any investment by using some genuine websites. The detailed information of some of the genuine everseen good earnings website information are presented clealy for free at http://earnmoneyonline-without-investment.blogspot.com/2010/02/earn-money-with-e-mail-marketing-how-it.html Earn Money Online with out Inevstment Overview : | Home | | E-mail Marketing | | Home Job Opportunities | | Contact | | Disclaimer | | Sitemap | Earn Money By : | Reading E-mails | | Clicking Ads | | Chatting Friends | | Surfing Internet | | Filling Forms | | Taking Surveys | From aahz at pythoncraft.com Sun Feb 28 17:10:02 2010 From: aahz at pythoncraft.com (Aahz) Date: 28 Feb 2010 14:10:02 -0800 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b889e3d$0$27844$c3e8da3@news.astraweb.com> Message-ID: In article <4b889e3d$0$27844$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Fri, 26 Feb 2010 21:51:17 -0600, Tim Daneliuk wrote: >> >> The only possible exception to this I can think of is when there is some >> non-obvious side-effect (i.e. language and/or hardware is >> "misfeatured"): >> >> mov A,B ; Moving A into B also will also arm >> ; the nuclear warhead if the CPU is >> ; hotter than 110C > >I had an embedded device that did *just that*, but only on Tuesdays. Thus explaining why some people never can get the hang of Tuesdays. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From rjngrj2010 at gmail.com Sun Feb 28 17:23:41 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 28 Feb 2010 14:23:41 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <038b8f03-c0bc-4ca3-b4eb-73e01ce7f69f@z35g2000yqd.googlegroups.com> Message-ID: On Feb 27, 10:14?pm, Arnaud Delobelle wrote: > On 28 Feb, 01:48, gujax wrote: > > > Hi, > > I have been trying to install python on my Win ME system for over two > > years - gave up for a while and now I am back with a resolve to solve > > the problem. I tried all versions of python but having installation > > problems for all. Installation does not proceed and I get a message > > saying "dll required for installation could not be run". I do not even > > know what to do next. I also tried Activepython. It installs but when > > I try to open it from Start->Programs->ActivePython 2.6, I get an > > error window saying - upgrade windows. > > Is there no solution at all to installing python on WinME. I have > > checked registry several times online and have sought professional > > help but so far no success. > > Thanks, I will appreciate any help > > gujax > > The docs (*) say that Python 2.5 is still compatible with Windows 9X > and ME, but that support for these platform was dropped at 2.6. ?So > you should be able to install and run Python 2.5. > > (*)http://docs.python.org/using/windows.html#installing-python > > -- > Arnaud Hi, Yes indeed, Python 2.5 worked and so did numpy and scipy for this version. Thanks to all for your inputs. There are now issues with plotting - graph plotting using pylab does not work nor does the Tck- Tk, but for now I am satisfied. Hopefully I will plod my way through. I should have read the documentation properly to realize that Win ME is not supported for later versions, Thanks again Gujax From fetchinson at googlemail.com Sun Feb 28 17:40:59 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 28 Feb 2010 23:40:59 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: >>I guess they also have some kind of a sandbox if they let people run >>python on their machines, I'm not sure if it's open source though. > > Thing is, I'm sure that Google uses a critical backstop to any > Python-based sandbox: something like a chroot jail. The Python sandbox > is mostly there to inform you about what you can and can't do; the real > security is provided by the OS. I see, makes perfect sense. This then raises the question whether it's important to have a 100% fool proof python sandbox without help from the OS, or this goal is not only too ambitious but also not really a useful one. One aspect might be that one might want to have a platform independent way of sandboxing, perhaps. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From candide at free.invalid Sun Feb 28 17:46:22 2010 From: candide at free.invalid (candide) Date: Sun, 28 Feb 2010 23:46:22 +0100 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <4b8af23e$0$7066$426a74cc@news.free.fr> OK, now I see the point. I was mistaken because I was supposing that every quote strictly _inside_ the string have to match another quote od the same type. Thanks to all for yours responses. From debacle at debian.org Sun Feb 28 17:52:27 2010 From: debacle at debian.org (W. Martin Borgert) Date: Sun, 28 Feb 2010 23:52:27 +0100 Subject: Use eval() safely? In-Reply-To: <7umhcaF9rkU1@mid.individual.net> Message-ID: <20100228225227.GA3200@beron.tangosoft.com> Gregory Ewing wrote: > I posted a demonstration of this earlier in this thread. As you wrote, your example does not work when using eval() like in my original post with second and third parameter to eval(): >>> import math >>> eval("[c for c in (0).__class__.__bases__[0].__subclasses__() if c.__name__ == 'file'][0]('/myfile', 'w')", { "__builtins__": None }, { "abs": abs, "sin": math.sin }) Traceback (most recent call last): File "", line 1, in File "", line 1, in IOError: file() constructor not accessible in restricted mode (Same result with Python 2.4, 2.5, and 2.6.) While I believe, that eval() is not save, I have yet to see an example for exploiting it. Leaving out the second and third parameter just proves, that one shouldn't omit them :~) Thanks in advance for any black hat example! P.S. Please Cc me, thanks. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 28 17:57:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 22:57:47 GMT Subject: cpan for python? References: Message-ID: <4b8af4eb$0$27844$c3e8da3@news.astraweb.com> On Sun, 28 Feb 2010 17:27:22 +0100, Daniel Fetchinson wrote: > > Is it only me or others also mentally read C-SPAN when somebody writes > CPAN? No, it's not just you. This is the first time I've realised it wasn't C-SPAN. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Feb 28 17:59:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 22:59:48 GMT Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b8af564$0$27844$c3e8da3@news.astraweb.com> On Sun, 28 Feb 2010 12:05:12 +0100, Stefan Behnel wrote: > Steven D'Aprano, 28.02.2010 09:48: >> There ought to be some kind of competition for the least efficient >> solution to programming problems > > That wouldn't be very interesting. You could just write a code generator > that spits out tons of garbage code including a line that solves the > problem, and then let it execute the code afterwards. That beast would > always win. Obfuscated code competitions could do the same: insert your simple, straight-forward, completely unobfuscated algorithm somewhere in the middle of 15 GB of garbage code. Who would even find it? But they don't, because human judges decide the winner, not some silly rule of "the most lines of code wins". In any case, I wasn't serious. It would be a bit of fun, if you like that sort of thing, and you might even learn a few things (I never knew that ints don't have an __eq__ method), but I can't see it taking off. I prefer to use my powers for inefficiency to be sarcastic to strangers on Usenet. -- Steven From sillyhat at yahoo.com Sun Feb 28 18:15:51 2010 From: sillyhat at yahoo.com (Hal Styli) Date: Sun, 28 Feb 2010 15:15:51 -0800 (PST) Subject: stripping fields from xml file into a csv References: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> Message-ID: On 28 Feb, 19:20, Stefan Behnel wrote: > Hai Vu, 28.02.2010 17:41: > > > By the way, Stefan, I am using Python 2.6. Do you know the differences > > between ElementTree and cElementTree? > > Use cElementTree, it's implemented in C and a lot faster and more memory > friendly. > > http://effbot.org/zone/celementtree.htm#benchmarkshttp://codespeak.net/lxml/performance.html > > Stefan Thanks for the responses so far, most enlightening. Stefan, I was happy to see such concise code. Your python worked with only very minor modifications. Hai's test xml data *without* the first and last line is close enough to the data I am using: ... quirky. I get a large file given to me in this format. I believe it is created by something like: grep 'customer=' *.xml, where there are a large number of xml files. I had to edit the data to include the first and last lines, and , to get the python code to work. It's not an arduous task(!), but can you recommend a way to get it to work without manually editing the data? One other thing, what's the Roland Mueller post above about (I'm viewing htis in google groups)? What would the test.xsl file look like? Thanks again Hal. From candide at free.invalid Sun Feb 28 18:23:38 2010 From: candide at free.invalid (candide) Date: Mon, 01 Mar 2010 00:23:38 +0100 Subject: Starting Python from the terminal with no welcome message Message-ID: <4b8afafa$0$28635$426a74cc@news.free.fr> Hi, Does exist some option I could send to the python interpreter during an interactive session in order to avoid the printing of the introductory message just above the top prompt ? In my case, the welcome message is the following : Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. gdb has such an option (the so-called quiet option). Compare this : $ gdb GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i486-linux-gnu". (gdb) with that $ gdb -q (gdb) From blake at randomresources.com Sun Feb 28 18:27:32 2010 From: blake at randomresources.com (Blake B) Date: Sun, 28 Feb 2010 17:27:32 -0600 Subject: Multiple console windows for a single program? Message-ID: <56b204861002281527n738e7032p7024db6768b1a40d@mail.gmail.com> Hello, I'm wanting to write a program with multiple objects, each in a thread. Both will be doing output (with the print statement) almost constantly, so I'd like to be able to separate their outputs. What I want to do is have a separate window for each. Is my only option to make my own "console" windows using TK or something? Thanks in advance, Blake B -------------- next part -------------- An HTML attachment was scrubbed... URL: From agoretoy at gmail.com Sun Feb 28 18:42:51 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 28 Feb 2010 17:42:51 -0600 Subject: Starting Python from the terminal with no welcome message In-Reply-To: <4b8afafa$0$28635$426a74cc@news.free.fr> References: <4b8afafa$0$28635$426a74cc@news.free.fr> Message-ID: On Sun, Feb 28, 2010 at 5:23 PM, candide wrote: > Hi, > > Does exist some option I could send to the python interpreter during an > interactive session in order to avoid the printing of the introductory > message just above the top prompt ? > > In my case, the welcome message is the following : > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > > gdb has such an option (the so-called quiet option). > > > Compare this : > > $ gdb > GNU gdb 6.8-debian > Copyright (C) 2008 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later > > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. Type "show copying" > and "show warranty" for details. > This GDB was configured as "i486-linux-gnu". > (gdb) > > with that > > $ gdb -q > (gdb) > > > -- > http://mail.python.org/mailman/listinfo/python-list > good idea, could be very useful. I don't think I recall seeing that option in python. +1 -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Sun Feb 28 19:30:12 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 01:30:12 +0100 Subject: Sample code usable Tkinter listbox Message-ID: In case Someone Else(TM) may need this. This code is just how it currently looks, what I needed for my code, so it's not a full-fledged or even tested class. But it works. import tkinter as t import tkinter.simpledialog import tkinter.messagebox t.askstring = tkinter.simpledialog.askstring t.warningbox = tkinter.messagebox.showwarning class UsableListbox( t.Frame ): def __init__( self, parent_widget ): t.Frame.__init__( self, parent_widget ) scrollbar = t.Scrollbar( self, orient = "vertical" ) self.lb = t.Listbox( self, yscrollcommand = scrollbar.set ) scrollbar.config( command = self.lb.yview ) scrollbar.pack( side = "right", fill = "y" ) self.lb.pack( side = "left", fill = "both", expand = 1 ) def current_index( self ): indices = self.lb.curselection() assert( len( indices ) <= 1 ) # TODO: about multi-selection. return None if len( indices ) == 0 else int( indices[0] ) def current( self ): #return self.lb.get( "active" ) # Incorrect with mousing i = self.current_index() return "" if i is None else self.lb.get( i ) def append( self, item ): return self.lb.insert( "end", item ) def add_selection_event_handler( self, handler ): "An event handler takes one argument, a Tkinter Event" return self.lb.bind( "<>", handler ) Cheers, - Alf From agoretoy at gmail.com Sun Feb 28 19:36:57 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 28 Feb 2010 18:36:57 -0600 Subject: Multiple console windows for a single program? In-Reply-To: <56b204861002281527n738e7032p7024db6768b1a40d@mail.gmail.com> References: <56b204861002281527n738e7032p7024db6768b1a40d@mail.gmail.com> Message-ID: On Sun, Feb 28, 2010 at 5:27 PM, Blake B wrote: > Hello, > > I'm wanting to write a program with multiple objects, each in a thread. > Both will be doing output (with the print statement) almost constantly, so > I'd like to be able to separate their outputs. What I want to do is have a > separate window for each. Is my only option to make my own "console" windows > using TK or something? > > Thanks in advance, > Blake B > > -- > http://mail.python.org/mailman/listinfo/python-list > > you can also use python-vte -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Feb 28 20:21:29 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 28 Feb 2010 19:21:29 -0600 Subject: Starting Python from the terminal with no welcome message In-Reply-To: <4b8afafa$0$28635$426a74cc@news.free.fr> References: <4b8afafa$0$28635$426a74cc@news.free.fr> Message-ID: <4B8B1699.6090307@tim.thechases.com> candide wrote: > Does exist some option I could send to the python interpreter during an > interactive session in order to avoid the printing of the introductory > message just above the top prompt ? > > In my case, the welcome message is the following : > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. I asked a similar question a while back: http://www.opensubscriber.com/message/python-list at python.org/4611139.html (strangely, I couldn't find that in the mail.python.org archives via google) If you don't want to monkey with the prompts (like I did in that thread), you can just use bash$ python -ic "" to get a python shell without the banner. That said, it _would_ be a nice addition to have a "-q"uiet startup option that behaves like many other apps do. But with it being just a few extra characters on the command-line, I don't expect it will happen. -tkc From pmaupin at gmail.com Sun Feb 28 21:09:30 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Feb 2010 20:09:30 -0600 Subject: Draft PEP on RSON configuration file format Message-ID: All: Finding .ini configuration files too limiting, JSON and XML to hard to manually edit, and YAML too complex to parse quickly, I have started work on a new configuration file parser. I call the new format RSON (for "Readable Serial Object Notation"), and it is designed to be a superset of JSON. I would love for it to be considered valuable enough to be a part of the standard library, but even if that does not come to pass, I would be very interested in feedback to help me polish the specification, and then possibly help for implementation and testing. The documentation is in rst PEP form, at: http://rson.googlecode.com/svn/trunk/doc/draftpep.txt Thanks and best regards, Pat From no.email at nospam.invalid Sun Feb 28 21:55:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Feb 2010 18:55:42 -0800 Subject: Draft PEP on RSON configuration file format References: Message-ID: <7xd3zobvip.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > I have started work on a new configuration file parser.... > The documentation is in rst PEP form, at:... Noooooooo.... not another... there are too many already. :-( -1 From rantingrick at gmail.com Sun Feb 28 22:10:27 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 28 Feb 2010 19:10:27 -0800 (PST) Subject: Sample code usable Tkinter listbox References: Message-ID: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> On Feb 28, 6:30?pm, "Alf P. Steinbach" wrote: > In case Someone Else(TM) may need this. > > This code is just how it currently looks, what I needed for my code, so it's not > a full-fledged or even tested class. Thanks for sharing Alf, Thats works fine "as-is" but what about inheriting from "tk.Listbox" directly and having the "container frame" as an attribute? I prefer this API because I hate to write the laborious "megawidget.mainwidget.methodX()" when i could instead write "megawidget.methodX()". What is your opinion on this? From steven at REMOVE.THIS.cybersource.com.au Sun Feb 28 22:18:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Mar 2010 03:18:47 GMT Subject: Draft PEP on RSON configuration file format References: Message-ID: On Sun, 28 Feb 2010 20:09:30 -0600, Patrick Maupin wrote: > All: > > Finding .ini configuration files too limiting, JSON and XML to hard to > manually edit, and YAML too complex to parse quickly, I have started > work on a new configuration file parser. > > I call the new format RSON (for "Readable Serial Object Notation"), and > it is designed to be a superset of JSON. Wait a minute... if JSON is too hard to edit, and RSON is a *superset* of JSON, that means by definition every JSON file is also a valid RSON file. Since JSON is too hard to manually edit, so is RSON. > I would love for it to be considered valuable enough to be a part of the > standard library, Come back when you actually have MANY users other than yourself using this is real-world projects. Until then, it is too early to even consider adding it the std library. Python comes with batteries included, but not experimental batteries that aren't even built yet, let alone proven that they work. -- Steven From alfps at start.no Sun Feb 28 22:57:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 04:57:32 +0100 Subject: Sample code usable Tkinter listbox In-Reply-To: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> Message-ID: * rantingrick: > On Feb 28, 6:30 pm, "Alf P. Steinbach" wrote: >> In case Someone Else(TM) may need this. >> >> This code is just how it currently looks, what I needed for my code, so it's not >> a full-fledged or even tested class. > > Thanks for sharing Alf, > Thats works fine "as-is" but what about inheriting from "tk.Listbox" > directly and having the "container frame" as an attribute? I prefer > this API because I hate to write the laborious > "megawidget.mainwidget.methodX()" when i could instead write > "megawidget.methodX()". What is your opinion on this? Well the frame contains a listbox and scrollbar. And with the frame as attribute the object that you have a direct reference to would then not be the complete thing on screen, with respect to sizing and placement and such. I generally don't like widgets that present stuff outside their bounding box. I guess that could be fixed up somehow by overriding this and that, but I find it simpler to just make the enclosing widget the widget that one has a reference to. And in a way it's also good that it's more laborious to directly access the tkinter listbox stuff, because what I discovered so far is that much of it requires work arounds and fixups, i.e. that it should be wrapped in higher level methods. I had to add some more such functionality after I posted that code. So, current (this is untested except that it works for what I'm using it for!): class UsableListbox( t.Frame ): def __init__( self, parent_widget ): t.Frame.__init__( self, parent_widget ) scrollbar = t.Scrollbar( self, orient = "vertical" ) self.lb = t.Listbox( self, exportselection = 0, yscrollcommand = scrollbar.set ) scrollbar.config( command = self.lb.yview ) scrollbar.pack( side = "right", fill = "y" ) self.lb.pack( side = "left", fill = "both", expand = 1 ) def current_index( self ): indices = self.lb.curselection() assert( len( indices ) <= 1 ) # TODO: about multi-selection. return None if len( indices ) == 0 else int( indices[0] ) def current( self ): #return self.lb.get( "active" ) # Incorrect with mousing i = self.current_index() return "" if i is None else self.lb.get( i ) def item_count( self ): return self.lb.size() def clear( self ): self.lb.delete( 0, "end" ) def append( self, item ): return self.lb.insert( "end", item ) def select_item( self, i ): assert( 0 <= i < self.item_count() ) self.lb.selection_set( i ) def add_selection_event_handler( self, handler ): "An event handler takes one argument, a Tkinter Event" return self.lb.bind( "<>", handler ) Cheers, - Alf From wuwei23 at gmail.com Mon Feb 1 00:16:43 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 21:16:43 -0800 (PST) Subject: A performance issue when using default value References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: keakon wrote: > def h2(x=[]): > ? y = x > ? y.append(1) > ? return y + [] > h2() is about 42 times slower than h2([]), but h() is a litter faster > than h([]). Are you aware that 'y = x' _doesn't_ make a copy of [], that it actually points to the same list as x? My guess is that the slowdown you're seeing is due to the increasing size of x _per timing iteration_. h2([]) will pass a new list each time, while h2() will append to the same list _every_ time. The difference between h & h2 is due to the concatenation of a new list to the built one: the longer the default list grows, the longer this will take, as extending a list takes O(k) time, with k being the number of elements. From keakon at gmail.com Mon Feb 1 00:20:28 2010 From: keakon at gmail.com (keakon) Date: Sun, 31 Jan 2010 21:20:28 -0800 (PST) Subject: A performance issue when using default value References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: <6eb8894f-ba52-4b47-8986-9fb7f3981da4@f17g2000prh.googlegroups.com> Even this style is 41 times faster than h2(): def i2(x=[]): y = x if not y: # add this line y = [] # add this line y.append(1) return y + [] print Timer('i2()','from __main__ import f2, g2, h2, i2').timeit (TIMES) Time: 0.00742356919664 From wuwei23 at gmail.com Mon Feb 1 00:20:53 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 21:20:53 -0800 (PST) Subject: A performance issue when using default value References: eabd60b1-269e-42e7-b8ee-0447cd34e6b5@v37g2000prh.googlegroups.com Message-ID: <9d2678d9-a232-4128-90f6-9ffae286ed23@s36g2000prf.googlegroups.com> alex23 wrote: > keakon wrote: > > def h2(x=[]): > > ? y = x > > ? y.append(1) > > ? return y + [] > > Are you aware that 'y = x' _doesn't_ make a copy of [], that it > actually points to the same list as x? Sorry, I meant to suggest trying the following instead: def h2(x=None): if x is None: x = [] x.append(1) return x + [] It's a common idiom to use None as a sentinel for this situation, esp. where you _don't_ want a default mutable object to be reused. From clp2 at rebertia.com Mon Feb 1 00:21:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Jan 2010 21:21:18 -0800 Subject: A performance issue when using default value In-Reply-To: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: <50697b2c1001312121y68cd9c5dk36e3c6c0d4f4d74e@mail.gmail.com> On Sun, Jan 31, 2010 at 8:58 PM, keakon wrote: > I've found strange performance issue when using default value, the > test code is list below: > > from timeit import Timer > > def f(x): > ?y = x > ?y.append(1) > ?return y > > def g(x=[]): > ?y = [] > ?y.append(1) > ?return y > > def h(x=[]): > ?y = x > ?y.append(1) > ?return y > > def f2(x): > ?y = x > ?y.append(1) > ?return y + [] > > def g2(x=[]): > ?y = [] > ?y.append(1) > ?return y + [] > > def h2(x=[]): > ?y = x > ?y.append(1) > ?return y + [] > > TIMES = 10000 > print Timer('f([])','from __main__ import f, g, h').timeit(TIMES) > print Timer('g()','from __main__ import f, g, h').timeit(TIMES) > print Timer('h([])','from __main__ import f, g, h').timeit(TIMES) > print Timer('h()','from __main__ import f, g, h').timeit(TIMES) > print Timer('f2([])','from __main__ import f2, g2, h2').timeit(TIMES) > print Timer('g2()','from __main__ import f2, g2, h2').timeit(TIMES) > print Timer('h2([])','from __main__ import f2, g2, h2').timeit(TIMES) > print Timer('h2()','from __main__ import f2, g2, h2').timeit(TIMES) > > > I tested it with Python 2.5.4, 2.6.4 and 3.1.1 on Windows XP, and get > almost the same result: > 0.00449247041174 > 0.00439608944712 > 0.00455867994396 > 0.00327471787615 > 0.00791581052899 > 0.00684919452053 > 0.00734311204357 > 0.30974942346 > > h2() is about 42 times slower than h2([]), but h() is a litter faster > than h([]). > > If change TIMES to 20000, other results are 2 times than before, but h2 > () is 4 times(about 1.2 sec) than before. > > Is there any tricks in it? Are you aware of the following pitfall?: >>> def foo(a=[]): ... a.append(7) ... return a >>> >>> print foo() [7] >>> print foo() [7, 7] >>> print foo() [7, 7, 7] i.e. the default argument is only evaluated once (when the function is defined) and is then reused every call when the caller doesn't provide a value. Cheers, Chris -- http://blog.rebertia.com From keakon at gmail.com Mon Feb 1 00:32:06 2010 From: keakon at gmail.com (keakon) Date: Sun, 31 Jan 2010 21:32:06 -0800 (PST) Subject: A performance issue when using default value References: eabd60b1-269e-42e7-b8ee-0447cd34e6b5@v37g2000prh.googlegroups.com <9d2678d9-a232-4128-90f6-9ffae286ed23@s36g2000prf.googlegroups.com> Message-ID: On 2?1?, ??1?20?, alex23 wrote: > alex23 wrote: > > keakon wrote: > > > def h2(x=[]): > > > y = x > > > y.append(1) > > > return y + [] > > > Are you aware that 'y = x' _doesn't_ make a copy of [], that it > > actually points to the same list as x? > > Sorry, I meant to suggest trying the following instead: > > def h2(x=None): > if x is None: x = [] > x.append(1) > return x + [] > > It's a common idiom to use None as a sentinel for this situation, esp. > where you _don't_ want a default mutable object to be reused. Thank you, I got it. The default value is mutable, and can be reused by all each call. So each call it will append 1 to the default value, that's very different than C++. From wuwei23 at gmail.com Mon Feb 1 00:58:06 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 21:58:06 -0800 (PST) Subject: A performance issue when using default value References: eabd60b1-269e-42e7-b8ee-0447cd34e6b5@v37g2000prh.googlegroups.com <9d2678d9-a232-4128-90f6-9ffae286ed23@s36g2000prf.googlegroups.com> Message-ID: <804a8f7e-0188-43f4-add9-52f841ceaf1a@w27g2000pre.googlegroups.com> keakon wrote: > The default value is mutable, and can be reused by all each call. > So each call it will append 1 to the default value, that's very > different than C++. Being different from C++ is one of the many reasons some of us choose Python ;) This tends to bite most newcomers, so it's mentioned in the FAQ: http://www.python.org/doc/faq/general/#id52 From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:05:17 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:05:17 GMT Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 31 Jan 2010 20:22:36 -0800, Paul Rubin wrote: > Terry Reedy writes: >> Three of you gave essentially identical answers, but I still do not see >> how given something like >> >> def f(): return 1 >> >> I differentiate between 'function object at address xxx' and 'int 1' >> objects. > > In the languages they are talking about, there is no such thing as a > function with no args. A function is closer to a mathematical function, > i.e. a mapping from one type to another, so every function has an arg. Suppose I have a function that queries a website http://guessmyname.com for a list of popular names and returns the most popular name on the list. Obviously this name will change from time to time, so I can't just get it once and treat the result as a constant. In a non-functional language, I'd write it something like this: def get_popular_name(): URL = 'http://guessmyname.com' data = fetch(URL) names = parse(data) name = choose(names, 1) return name name = get_popular_name() # call the function with no argument f = decorate(get_popular_name) # treat the function as a 1st class object How would Haskell coders write it? Something like this? def get_popular_name(url): data = fetch url names = parse data name = choose name 1 return name name = get_popular_name 'http://guessmyname.com' # call the function f = decorate get_popular_name # treat the function as a 1st class object But now you're needlessly having the caller, rather than the function, remember an implementation detail of the get_popular_name function. Since the argument couldn't be anything different, I'd immediately think of applying partial: get_popular_name = partial get_popular_name 'http://guessmyname.com' but now how do I call the new function? Is this where you say "Monads" and everyone's eyes glaze over? -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:15:35 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:15:35 GMT Subject: A performance issue when using default value References: <4754e6b7-2d79-4995-8f3f-193b646b524e@z10g2000prh.googlegroups.com> Message-ID: On Sun, 31 Jan 2010 20:58:50 -0800, keakon wrote: > I've found strange performance issue when using default value, the test > code is list below: > > from timeit import Timer > > def f(x): > y = x > y.append(1) > return y > > def g(x=[]): > y = [] > y.append(1) > return y > > def h(x=[]): > y = x > y.append(1) > return y > > def f2(x): > y = x > y.append(1) > return y + [] > > def g2(x=[]): > y = [] > y.append(1) > return y + [] > > def h2(x=[]): > y = x > y.append(1) > return y + [] > > TIMES = 10000 > print Timer('f([])','from __main__ import f, g, h').timeit(TIMES) print > Timer('g()','from __main__ import f, g, h').timeit(TIMES) print > Timer('h([])','from __main__ import f, g, h').timeit(TIMES) print > Timer('h()','from __main__ import f, g, h').timeit(TIMES) print > Timer('f2([])','from __main__ import f2, g2, h2').timeit(TIMES) print > Timer('g2()','from __main__ import f2, g2, h2').timeit(TIMES) print > Timer('h2([])','from __main__ import f2, g2, h2').timeit(TIMES) print > Timer('h2()','from __main__ import f2, g2, h2').timeit(TIMES) > > > I tested it with Python 2.5.4, 2.6.4 and 3.1.1 on Windows XP, and get > almost the same result: > 0.00449247041174 > 0.00439608944712 > 0.00455867994396 > 0.00327471787615 > 0.00791581052899 > 0.00684919452053 > 0.00734311204357 > 0.30974942346 You've only run those results once, haven't you? That is not trustworthy. In a multi-tasking operating system, including Windows, some other process might have run for some milliseconds, throwing the results off. More importantly, if you had run it multiple times, you'd see this: >>> for i in range(7): ... Timer('h2()','from __main__ import f2, g2, h2').timeit(TIMES) ... 0.0190200805664 0.315117120743 0.941411972046 1.56618499756 2.18553495407 2.79832291603 3.44865894318 h2 (and probably h, but I haven't tested it) get slower and slower and slower every time you run it. Why? I'm pretty sure this is in the FAQs, but default values are created once, not every time the function is called. So you create a function with the default value of []. Call the function, and that list gets 1 appended to it, so the default value is now [1]. Call the function again, and it becomes [1, 1]. And so on, and so on, and so on. The other functions create a new empty list each time the function is called, so you're comparing the time it takes to grow an ever-bigger list with the time it takes to create a tiny list. -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:17:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:17:21 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <874om1ydxf.fsf@castleamber.com> Message-ID: On Sun, 31 Jan 2010 18:53:16 -0600, John Bokma wrote: > You don't have to buy my argument, I am not selling it. It's a figure of speech. You are making an argument others have made before, and I don't accept the validity of the argument. -- Steven From no.email at nospam.invalid Mon Feb 1 01:22:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 31 Jan 2010 22:22:14 -0800 Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: <7x4om18oh5.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > How would Haskell coders write it? Something like this? > > def get_popular_name(url): > data = fetch url > names = parse data > name = choose name 1 > return name The syntax and types would be different, but ok, something like that. > name = get_popular_name 'http://guessmyname.com' # call the function > f = decorate get_popular_name # treat the function as a 1st class object You wouldn't need "decorate". You'd just say f = get_popular_name "http://guessmyname.com" f is now an "I/O action" which when executed queries the guessmyname site. > but now how do I call the new function? > Is this where you say "Monads" and everyone's eyes glaze over? You'd say something like most_popular_name <- f to invoke the action. Yes, explaining the difference between "<-" and "=" involves monads. You might like the Haskell tutorial http://learnyouahaskell.com . From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 01:27:29 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 06:27:29 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: On Sun, 31 Jan 2010 21:30:15 -0600, John Bokma wrote: >>>>> While braces might be considered redundant they are not when for one >>>>> reason or another formatting is lost or done incorrectly. >>>> >>>> I've heard this argument before, and I don't buy it. Why should we >>>> expect the editor to correct malformed code? >>> >>> Or a prettyfier. It doesn't matter. The point is that with braces >>> there *is* redundancy that be used to fix the code. >> >> Prettyfiers are significant in languages that allow braces (or >> begin/end tokens) and indentation to go out of sync. Since that can't >> happen with Python, > > Yes it can. I *have* seen Python with broken indentation on web pages, > and good luck sorting it out. Blaming it on "broken tools" is just > another straw man. You're using that term wrong. It looks to me that you don't actually know what a straw man argument is. A straw man argument is when somebody responds to a deliberately weakened or invalid argument as if it had been made by their opponent. You raised the issue that the redundancy which prettyfiers exploit are a good reason for preferring braces, so it's not a straw man argument. It's not a straw man to say that you don't need a code prettyfier if indentation is significant when you raised the issue of prettyfiers in the first place. I certainly accept that braces + indentation do provide redundancy, and if the norm was noisy channels, that redundancy would be valuable. But that's not the norm. Most channels don't delete leading whitespace, and those noisy channels we do deal with (like web forms) tend to introduce far more noise than merely deleting leading whitespace, e.g. word- wrapping long lines. The argument that "web pages break indentation, therefore braces are better" is a real argument that some people make, but it is very weak. Suppose there was a web page that arbitrarily deleted braces out of some misplaced sense of security. Would anyone argue that this proves that indentation was better and braces were bad? No, of course not -- they would say "That website is broken". > It happens, and if you're learning Python and > interested in that code you have a problem. Yes you do. If you're trying to learn carpentry, and somebody gives you a blunt saw that causes the wood to break rather than cut cleanly, you have a problem. If you're learning to cook, and they give you a put with a hole in it and tell you to make soup in it, you have a problem. Broken tools lead to problems. > Snipped the rest, because you start to sound like a zealot. I should've > know better. Yeah, whatever. -- Steven From wuwei23 at gmail.com Mon Feb 1 01:43:56 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 31 Jan 2010 22:43:56 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: Steven D'Aprano wrote: > You're using that term wrong. It looks to me that you don't actually know > what a straw man argument is. A straw man argument is when somebody > responds to a deliberately weakened or invalid argument as if it had been > made by their opponent. Jeez, Steve, you're beginning to sound like some kind of fallacy zealot... ;) From clp2 at rebertia.com Mon Feb 1 01:49:13 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 31 Jan 2010 22:49:13 -0800 Subject: Python and Ruby In-Reply-To: References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: <50697b2c1001312249v237d4280xf297f4afac73f028@mail.gmail.com> On Sun, Jan 31, 2010 at 10:05 PM, Steven D'Aprano wrote: > On Sun, 31 Jan 2010 20:22:36 -0800, Paul Rubin wrote: >> Terry Reedy writes: >>> Three of you gave essentially identical answers, but I still do not see >>> how given something like >>> >>> def f(): return 1 >>> >>> I differentiate between 'function object at address xxx' and 'int 1' >>> objects. >> >> In the languages they are talking about, there is no such thing as a >> function with no args. ?A function is closer to a mathematical function, >> i.e. a mapping from one type to another, so every function has an arg. > > Suppose I have a function that queries a website http://guessmyname.com > for a list of popular names and returns the most popular name on the > list. Obviously this name will change from time to time, so I can't just > get it once and treat the result as a constant. > > In a non-functional language, I'd write it something like this: > > > def get_popular_name(): > ? ?URL = 'http://guessmyname.com' > ? ?data = fetch(URL) > ? ?names = parse(data) > ? ?name = choose(names, 1) > ? ?return name > > name = get_popular_name() ?# call the function with no argument > f = decorate(get_popular_name) ?# treat the function as a 1st class object > > > How would Haskell coders write it? > Is this where you say "Monads" and everyone's eyes glaze over? Yeah, basically. Your function has side-effects (i.e. it does I/O over the network), and thus some extra hoops need to be jumped through to reconcile that with the functional purity of the language. Assuming my understanding of monads is somewhat correct: get_popular_name would have the type: IO () -> IO String i.e. it takes no "real" parameters but does I/O, and returns a String. "IO" is a generic type, thus IO () is like IO, and IO String is IO (using Java/C#-like generics syntax). Wrapping things in IOs (the "IO monad") is how the type system models that I/O side effects are involved. So, get_popular_name would end up taking one argument, IO (). Now where does the caller get an IO () ? Well, the toplevel (i.e. the main function) is allowed to do IO (otherwise, we couldn't write very interesting programs), and thus is provided with an IO by the environment (through some sort of magic). Using this, it passes an IO () to get_popular_name (or it gets passed down the call stack and eventually winds up at get_popular_name) and we get back an IO String. And through some further monad trickery, we make sure that lazy evaluation is effectively bypassed for the I/O and we are able to rip the String out of its IO container and pass it to pure functions. And using the dark magic of "do-notation", we write the parts involving IO in pseudo-imperative style (the "<-" operator Paul mentioned is part of that). And there you have it (I think/hope). Supposedly, in practice, you don't need to know the monad guts of how the I/O system works in order to use it, you just need to be able to write do-notation. Cheers, Chris -- I really should read the monad chapters of my copy of "Real World Haskell". http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 02:12:51 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 07:12:51 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: On Sun, 31 Jan 2010 22:43:56 -0800, alex23 wrote: > Steven D'Aprano wrote: >> You're using that term wrong. It looks to me that you don't actually >> know what a straw man argument is. A straw man argument is when >> somebody responds to a deliberately weakened or invalid argument as if >> it had been made by their opponent. > > Jeez, Steve, you're beginning to sound like some kind of fallacy > zealot... ;) Death to all those who confuse agumentum ad populum with argumentum ad verecundiam!!! -- Steven From no.email at nospam.invalid Mon Feb 1 02:24:06 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 31 Jan 2010 23:24:06 -0800 Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <7x1vh5shyr.fsf@ruckus.brouhaha.com> Message-ID: <7xk4uxju5l.fsf@ruckus.brouhaha.com> Chris Rebert writes: > get_popular_name would have the type: IO () -> IO String I don't know if it makes the explanation any clearer, but I think that isn't quite right. The Python version would have type String -> IO String. The parameterless Haskell version would just be an I/O action, with type IO String. IO () is not really involved. From lanyjie at yahoo.com Mon Feb 1 03:24:42 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Mon, 1 Feb 2010 00:24:42 -0800 (PST) Subject: expy 0.5.1 released Message-ID: <511580.45863.qm@web54208.mail.re2.yahoo.com> Hi there, EXPY 0.5.1 released, the exception raising feature is enhanced so that you can raise any builtin exceptions. Custom exceptions will be supported soon. For more information, see http://expy.sourceforge.net/ EXPY is an expressway to extend Python! Regards, Yingjie From stefan_ml at behnel.de Mon Feb 1 03:34:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Feb 2010 09:34:28 +0100 Subject: HTML Parser which allows low-keyed local changes? In-Reply-To: References: Message-ID: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Robert, 31.01.2010 20:57: > I tried lxml, but after walking and making changes in the element tree, > I'm forced to do a full serialization of the whole document > (etree.tostring(tree)) - which destroys the "human edited" format of the > original HTML code. makes it rather unreadable. What do you mean? Could you give an example? lxml certainly does not destroy anything it parsed, unless you tell it to do so. Stefan From ps.ohms at gmail.com Mon Feb 1 03:43:29 2010 From: ps.ohms at gmail.com (PS.OHM) Date: Mon, 1 Feb 2010 00:43:29 -0800 (PST) Subject: get error install MySQLdb on Mac OS X References: <30c0946e-fa6a-4a54-930c-1962d167fffe@x10g2000prk.googlegroups.com> Message-ID: <2be17362-8a54-4a04-9671-0a0ff7266e33@k2g2000pro.googlegroups.com> On Jan 29, 5:02?am, Sean DiZazzo wrote: > On Jan 28, 12:53?pm, "PS.OHM" wrote: > > > Hello Guys > > > I havegetsomeerrorwhen i install MySQLdb on Mac OS X > > > after i key command $python setup.py build > > > rusult is > > : > > : > >error: command 'gcc-4.0' failed with exit status 1 > > > How to config this poblem? > > Please show a little bit more of theerror iME-macbook-pro:MySQL-python-1.2.3c1 iME$ python setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.macosx-10.3-fat-2.6/MySQLdb running build_ext building '_mysql' extension gcc-4.0 -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 - Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/Applications/ MAMP/Library/include/mysql -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 -fno-omit-frame-pointer -D_P1003_1B_VISIBLE - DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ - DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory _mysql.c:76: error: syntax error before ?MYSQL? _mysql.c:76: warning: no semicolon at end of struct or union _mysql.c:79: error: syntax error before ?}? token _mysql.c:79: warning: data definition has no type or storage class _mysql.c:90: error: syntax error before ?MYSQL_RES? _mysql.c:90: warning: no semicolon at end of struct or union _mysql.c:94: error: syntax error before ?}? token _mysql.c:94: warning: data definition has no type or storage class _mysql.c:106: error: syntax error before ?*? token _mysql.c: In function ?_mysql_Exception?: _mysql.c:120: error: ?c? undeclared (first use in this function) _mysql.c:120: error: (Each undeclared identifier is reported only once _mysql.c:120: error: for each function it appears in.) _mysql.c:123: error: ?CR_MAX_ERROR? undeclared (first use in this function) _mysql.c:131: error: ?CR_COMMANDS_OUT_OF_SYNC? undeclared (first use in this function) _mysql.c:132: error: ?ER_DB_CREATE_EXISTS? undeclared (first use in this function) _mysql.c:133: error: ?ER_SYNTAX_ERROR? undeclared (first use in this function) _mysql.c:134: error: ?ER_PARSE_ERROR? undeclared (first use in this function) _mysql.c:135: error: ?ER_NO_SUCH_TABLE? undeclared (first use in this function) _mysql.c:136: error: ?ER_WRONG_DB_NAME? undeclared (first use in this function) _mysql.c:137: error: ?ER_WRONG_TABLE_NAME? undeclared (first use in this function) _mysql.c:138: error: ?ER_FIELD_SPECIFIED_TWICE? undeclared (first use in this function) _mysql.c:139: error: ?ER_INVALID_GROUP_FUNC_USE? undeclared (first use in this function) _mysql.c:140: error: ?ER_UNSUPPORTED_EXTENSION? undeclared (first use in this function) _mysql.c:141: error: ?ER_TABLE_MUST_HAVE_COLUMNS? undeclared (first use in this function) _mysql.c:170: error: ?ER_DUP_ENTRY? undeclared (first use in this function) _mysql.c:213: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:358: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_Initialize?: _mysql.c:363: error: ?MYSQL_RES? undeclared (first use in this function) _mysql.c:363: error: ?result? undeclared (first use in this function) _mysql.c:364: error: ?conn? undeclared (first use in this function) _mysql.c:368: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:368: error: ?fields? undeclared (first use in this function) _mysql.c:370: error: ?args? undeclared (first use in this function) _mysql.c:370: error: ?kwargs? undeclared (first use in this function) _mysql.c:375: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:445: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_traverse?: _mysql.c:450: error: ?self? undeclared (first use in this function) _mysql.c:451: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:460: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_clear?: _mysql.c:462: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:471: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_Initialize?: _mysql.c:475: error: ?MYSQL? undeclared (first use in this function) _mysql.c:475: error: ?conn? undeclared (first use in this function) _mysql.c:500: error: ?self? undeclared (first use in this function) _mysql.c:503: error: ?args? undeclared (first use in this function) _mysql.c:503: error: ?kwargs? undeclared (first use in this function) _mysql.c:550: error: ?MYSQL_OPT_CONNECT_TIMEOUT? undeclared (first use in this function) _mysql.c:554: error: ?MYSQL_OPT_COMPRESS? undeclared (first use in this function) _mysql.c:555: error: ?CLIENT_COMPRESS? undeclared (first use in this function) _mysql.c:558: error: ?MYSQL_OPT_NAMED_PIPE? undeclared (first use in this function) _mysql.c:560: error: ?MYSQL_INIT_COMMAND? undeclared (first use in this function) _mysql.c:562: error: ?MYSQL_READ_DEFAULT_FILE? undeclared (first use in this function) _mysql.c:564: error: ?MYSQL_READ_DEFAULT_GROUP? undeclared (first use in this function) _mysql.c:567: error: ?MYSQL_OPT_LOCAL_INFILE? undeclared (first use in this function) _mysql.c: In function ?_mysql_connect?: _mysql.c:654: error: ?c? undeclared (first use in this function) _mysql.c:656: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:667: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_traverse?: _mysql.c:671: error: ?self? undeclared (first use in this function) _mysql.c:672: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:678: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_clear?: _mysql.c:680: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:690: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_close?: _mysql.c:693: error: ?args? undeclared (first use in this function) _mysql.c:696: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:718: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_affected_rows?: _mysql.c:721: error: ?args? undeclared (first use in this function) _mysql.c:722: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:752: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dump_debug_info?: _mysql.c:756: error: ?args? undeclared (first use in this function) _mysql.c:757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:771: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_autocommit?: _mysql.c:775: error: ?args? undeclared (first use in this function) _mysql.c:783: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:797: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_commit?: _mysql.c:801: error: ?args? undeclared (first use in this function) _mysql.c:806: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:819: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_rollback?: _mysql.c:823: error: ?args? undeclared (first use in this function) _mysql.c:828: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:851: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_next_result?: _mysql.c:855: error: ?args? undeclared (first use in this function) _mysql.c:863: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:936: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_errno?: _mysql.c:939: error: ?args? undeclared (first use in this function) _mysql.c:940: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:952: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_error?: _mysql.c:955: error: ?args? undeclared (first use in this function) _mysql.c:956: error: ?self? undeclared (first use in this function) _mysql.c:957: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:970: error: syntax error before ?*? token _mysql.c: In function ?_mysql_escape_string?: _mysql.c:976: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1005: error: syntax error before ?*? token _mysql.c: In function ?_mysql_string_literal?: _mysql.c:1011: error: ?args? undeclared (first use in this function) _mysql.c: In function ?_mysql_escape?: _mysql.c:1088: error: syntax error before ?)? token _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c: At top level: _mysql.c:38:19: _mysql.c:1164: error: syntax error before ?*? token error: mysql.h: No such file or directory _mysql.c: In function ?_mysql_ResultObject_describe?: _mysql.c:1168: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1168: error: ?fields? undeclared (first use in this function) _mysql.c:39:26: error: _mysql.c:1170: error: ?args? undeclared (first use in this function) mysqld_error.h: No such file or directory _mysql.c:1171: error: syntax error before ?)? token_mysql.c:40:20: error: _mysql.c:1171: error: syntax error before ?)? token errmsg.h: No such file or directory _mysql.c:1172: error: ?self? undeclared (first use in this function) _mysql.c:76: error: syntax error before ?MYSQL? _mysql.c:76: warning: no semicolon at end of struct or union _mysql.c:79: error: syntax error before ?}? token _mysql.c:79: warning: data definition has no type or storage class _mysql.c: At top level:_mysql.c:90: error: syntax error before ?MYSQL_RES? _mysql.c:90: warning: no semicolon at end of struct or union _mysql.c:94: error: syntax error before ?}? token _mysql.c:1200: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_field_flags?:_mysql.c:94: warning: data definition has no type or storage class _mysql.c:1204: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1204: error: ?fields? undeclared (first use in this function) _mysql.c:1206: error: ?args? undeclared (first use in this function) _mysql.c:106: error: syntax error before ?*? token _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1208: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_Exception?: _mysql.c:120: error: ?c? undeclared (first use in this function) _mysql.c:120: error: (Each undeclared identifier is reported only once _mysql.c:120: error: for each function it appears in.) _mysql.c:123: error: ?CR_MAX_ERROR? undeclared (first use in this function) _mysql.c:131: error: ?CR_COMMANDS_OUT_OF_SYNC? undeclared (first use in this function) _mysql.c:132: error: ?ER_DB_CREATE_EXISTS? undeclared (first use in this function) _mysql.c:133: error: ?ER_SYNTAX_ERROR? undeclared (first use in this function) _mysql.c:134: error: ?ER_PARSE_ERROR? undeclared (first use in this function) _mysql.c:135: error: ?ER_NO_SUCH_TABLE? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:136: error: ?ER_WRONG_DB_NAME? undeclared (first use in this function) _mysql.c:137: error: ?ER_WRONG_TABLE_NAME? undeclared (first use in this function) _mysql.c:138: error: ?ER_FIELD_SPECIFIED_TWICE? undeclared (first use in this function) _mysql.c:139: error: ?ER_INVALID_GROUP_FUNC_USE? undeclared (first use in this function) _mysql.c:140: error: ?ER_UNSUPPORTED_EXTENSION? undeclared (first use in this function) _mysql.c:141: error: ?ER_TABLE_MUST_HAVE_COLUMNS? undeclared (first use in this function) _mysql.c:170: error: ?ER_DUP_ENTRY? undeclared (first use in this function) _mysql.c:213: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c:1249: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_tuple?: _mysql.c:1256: error: ?self? undeclared (first use in this function) _mysql.c:1258: warning: assignment makes pointer from integer without a cast _mysql.c:1262: error: ?row? undeclared (first use in this function) _mysql.c: At top level:_mysql.c: At top level: _mysql.c:358: error: syntax error before ?*? token _mysql.c:1274: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_dict?: _mysql.c:1280: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1280: error: ?fields? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_Initialize?: _mysql.c:363: error: ?MYSQL_RES? undeclared (first use in this function) _mysql.c:363: error: ?result? undeclared (first use in this function) _mysql.c:364: error: ?conn? undeclared (first use in this function) _mysql.c:368: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:368: error: ?fields? undeclared (first use in this function) _mysql.c:370: error: ?args? undeclared (first use in this function) _mysql.c:370: error: ?kwargs? undeclared (first use in this function) _mysql.c:375: error: ?self? undeclared (first use in this function) _mysql.c:1282: error: ?self? undeclared (first use in this function) _mysql.c:1284: warning: assignment makes pointer from integer without a cast _mysql.c:1289: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:445: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_traverse?: _mysql.c:450: error: ?self? undeclared (first use in this function) _mysql.c:451: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c: At top level:_mysql.c:460: error: syntax error before ?*? token _mysql.c:1313: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_clear?: _mysql.c:462: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_row_to_dict_old?: _mysql.c:1319: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1319: error: ?fields? undeclared (first use in this function) _mysql.c:1321: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1323: warning: assignment makes pointer from integer without a cast _mysql.c:471: error: syntax error before ?*? token _mysql.c:1328: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1350: error: syntax error before ?*? token _mysql.c:1354: error: syntax error before ?*? token _mysql.c: In function ?_mysql__fetch_row?: _mysql.c:1361: error: ?MYSQL_ROW? undeclared (first use in this function) _mysql.c:1361: error: syntax error before ?row? _mysql.c:1363: error: ?skiprows? undeclared (first use in this function) _mysql.c:1363: error: ?maxrows? undeclared (first use in this function) _mysql.c:1365: error: ?self? undeclared (first use in this function) _mysql.c:1366: error: ?row? undeclared (first use in this function) _mysql.c:1372: error: syntax error before ?)? token _mysql.c:1373: error: syntax error before ?)? token _mysql.c: In function ?_mysql_ConnectionObject_Initialize?: _mysql.c:1377: error: ?r? undeclared (first use in this function) _mysql.c:475: error: ?MYSQL? undeclared (first use in this function) _mysql.c:475: error: ?conn? undeclared (first use in this function) _mysql.c:1380: warning: assignment makes pointer from integer without a cast _mysql.c:500: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1400: error: syntax error before ?*? token _mysql.c:503: error: ?args? undeclared (first use in this function) _mysql.c:503: error: ?kwargs? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_fetch_row?: _mysql.c:1404: error: syntax error before ?*? token _mysql.c:550: error: ?MYSQL_OPT_CONNECT_TIMEOUT? undeclared (first use in this function)_mysql.c:1416: error: ?args? undeclared (first use in this function) _mysql.c:1416: error: ?kwargs? undeclared (first use in this function) _mysql.c:554: error: ?MYSQL_OPT_COMPRESS? undeclared (first use in this function) _mysql.c:555: error: ?CLIENT_COMPRESS? undeclared (first use in this function) _mysql.c:558: error: ?MYSQL_OPT_NAMED_PIPE? undeclared (first use in this function) _mysql.c:560: error: ?MYSQL_INIT_COMMAND? undeclared (first use in this function) _mysql.c:562: error: ?MYSQL_READ_DEFAULT_FILE? undeclared (first use in this function)_mysql.c:1419: error: syntax error before ?)? token _mysql.c:1419: error: syntax error before ?)? token_mysql.c:564: error: ?MYSQL_READ_DEFAULT_GROUP? undeclared (first use in this function) _mysql.c:567: error: ?MYSQL_OPT_LOCAL_INFILE? undeclared (first use in this function) _mysql.c: In function ?_mysql_connect?: _mysql.c:654: error: ?c? undeclared (first use in this function) _mysql.c:656: error: syntax error before ?)? token _mysql.c:1427: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:667: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_traverse?: _mysql.c:671: error: ?self? undeclared (first use in this function) _mysql.c:672: error: ?arg? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:678: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_clear?: _mysql.c:680: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1507: error: syntax error before ?*? token _mysql.c: At top level: _mysql.c:690: error: syntax error before ?*? token_mysql.c: In function ?_mysql_ConnectionObject_character_set_name?: _mysql.c:1511: error: ?args? undeclared (first use in this function) _mysql.c:1512: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ConnectionObject_close?: _mysql.c:693: error: ?args? undeclared (first use in this function) _mysql.c:696: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_get_client_info?: _mysql.c:1603: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:718: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_affected_rows?: _mysql.c:721: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1613: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_host_info?: _mysql.c:1616: error: ?args? undeclared (first use in this function) _mysql.c:1617: error: ?self? undeclared (first use in this function) _mysql.c:1618: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast_mysql.c:722: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1628: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_proto_info?: _mysql.c:1631: error: ?args? undeclared (first use in this function) _mysql.c:1632: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1643: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_server_info?: _mysql.c:1646: error: ?args? undeclared (first use in this function) _mysql.c:1647: error: ?self? undeclared (first use in this function) _mysql.c:1648: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1659: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_info?: _mysql.c:1663: error: ?args? undeclared (first use in this function) _mysql.c:1664: error: ?self? undeclared (first use in this function) _mysql.c:1665: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:752: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dump_debug_info?: _mysql.c:756: error: ?args? undeclared (first use in this function) _mysql.c:757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1694: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_insert_id?: _mysql.c:1697: error: ?my_ulonglong? undeclared (first use in this function) _mysql.c:1697: error: syntax error before ?r? _mysql.c:1698: error: ?args? undeclared (first use in this function) _mysql.c: At top level:_mysql.c:1699: error: ?self? undeclared (first use in this function) _mysql.c:771: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_autocommit?: _mysql.c:775: error: ?args? undeclared (first use in this function) _mysql.c:1701: error: ?r? undeclared (first use in this function) _mysql.c:783: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1712: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_kill?: _mysql.c:1717: error: ?args? undeclared (first use in this function) _mysql.c: At top level:_mysql.c:1718: error: ?self? undeclared (first use in this function) _mysql.c:797: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_commit?: _mysql.c:801: error: ?args? undeclared (first use in this function) _mysql.c:806: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1735: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_field_count?: _mysql.c: At top level: _mysql.c:819: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_rollback?: _mysql.c:823: error: ?args? undeclared (first use in this function) _mysql.c:828: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:851: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_next_result?: _mysql.c:855: error: ?args? undeclared (first use in this function) _mysql.c:863: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:936: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_errno?: _mysql.c:939: error: ?args? undeclared (first use in this function) _mysql.c:940: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:952: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_error?: _mysql.c:955: error: ?args? undeclared (first use in this function) _mysql.c:956: error: ?self? undeclared (first use in this function) _mysql.c:957: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:970: error: syntax error before ?*? token _mysql.c: In function ?_mysql_escape_string?: _mysql.c:976: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1005: error: syntax error before ?*? token _mysql.c: In function ?_mysql_string_literal?: _mysql.c:1011: error: ?args? undeclared (first use in this function) _mysql.c: In function ?_mysql_escape?: _mysql.c:1088: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:1164: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_describe?: _mysql.c:1168: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1168: error: ?fields? undeclared (first use in this function) _mysql.c:1170: error: ?args? undeclared (first use in this function) _mysql.c:1171: error: syntax error before ?)? token _mysql.c:1171: error: syntax error before ?)? token _mysql.c:1172: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1200: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_field_flags?: _mysql.c:1204: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1204: error: ?fields? undeclared (first use in this function) _mysql.c:1206: error: ?args? undeclared (first use in this function) _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1207: error: syntax error before ?)? token _mysql.c:1208: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1249: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_tuple?: _mysql.c:1256: error: ?self? undeclared (first use in this function) _mysql.c:1258: warning: assignment makes pointer from integer without a cast _mysql.c:1262: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1274: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_dict?: _mysql.c:1280: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1280: error: ?fields? undeclared (first use in this function) _mysql.c:1282: error: ?self? undeclared (first use in this function) _mysql.c:1284: warning: assignment makes pointer from integer without a cast _mysql.c:1289: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1313: error: syntax error before ?*? token _mysql.c: In function ?_mysql_row_to_dict_old?: _mysql.c:1319: error: ?MYSQL_FIELD? undeclared (first use in this function) _mysql.c:1319: error: ?fields? undeclared (first use in this function) _mysql.c:1321: error: ?self? undeclared (first use in this function) _mysql.c:1323: warning: assignment makes pointer from integer without a cast _mysql.c:1328: error: ?row? undeclared (first use in this function) _mysql.c:1738: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1350: error: syntax error before ?*? token _mysql.c:1354: error: syntax error before ?*? token _mysql.c:1739: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql__fetch_row?: _mysql.c:1361: error: ?MYSQL_ROW? undeclared (first use in this function) _mysql.c:1361: error: syntax error before ?row? _mysql.c:1363: error: ?skiprows? undeclared (first use in this function) _mysql.c:1363: error: ?maxrows? undeclared (first use in this function) _mysql.c:1365: error: ?self? undeclared (first use in this function) _mysql.c:1366: error: ?row? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1752: error: syntax error before ?*? token _mysql.c:1372: error: syntax error before ?)? token _mysql.c:1373: error: syntax error before ?)? token _mysql.c:1377: error: ?r? undeclared (first use in this function) _mysql.c:1380: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1400: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_fetch_row?: _mysql.c:1404: error: syntax error before ?*? token _mysql.c:1416: error: ?args? undeclared (first use in this function) _mysql.c:1416: error: ?kwargs? undeclared (first use in this function) _mysql.c:1419: error: syntax error before ?)? token _mysql.c:1419: error: syntax error before ?)? token _mysql.c:1427: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1507: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_character_set_name?: _mysql.c:1511: error: ?args? undeclared (first use in this function) _mysql.c:1512: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_get_client_info?: _mysql.c:1603: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1613: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_host_info?: _mysql.c:1616: error: ?args? undeclared (first use in this function) _mysql.c:1617: error: ?self? undeclared (first use in this function) _mysql.c:1618: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1628: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_proto_info?: _mysql.c:1631: error: ?args? undeclared (first use in this function) _mysql.c:1632: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_num_fields?: _mysql.c: At top level: _mysql.c:1643: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_get_server_info?: _mysql.c:1646: error: ?args? undeclared (first use in this function) _mysql.c:1647: error: ?self? undeclared (first use in this function) _mysql.c:1648: warning: passing argument 1 of ?PyString_FromString? makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1659: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_info?: _mysql.c:1663: error: ?args? undeclared (first use in this function) _mysql.c:1664: error: ?self? undeclared (first use in this function) _mysql.c:1665: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1694: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_insert_id?: _mysql.c:1697: error: ?my_ulonglong? undeclared (first use in this function) _mysql.c:1697:_mysql.c:1755: error: ?args? undeclared (first use in this function) _mysql.c:1756: error: syntax error before ?)? token _mysql.c:1756: error: syntax error before ?)? token _mysql.c:1757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1768: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_num_rows?: _mysql.c:1771: error: ?args? undeclared (first use in this function) _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1773: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1797: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_ping?: _mysql.c:1801: error: ?args? undeclared (first use in this function) _mysql.c:1802: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1820: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_query?: _mysql.c:1825: error: ?args? undeclared (first use in this function) _mysql.c:1826: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1850: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_select_db?: _mysql.c:1855: error: ?args? undeclared (first use in this function) _mysql.c:1856: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1872: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_shutdown?: _mysql.c:1876: error: ?args? undeclared (first use in this function) _mysql.c:1877: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1899: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_stat?: _mysql.c:1903: error: ?args? undeclared (first use in this function) _mysql.c:1904: error: ?self? undeclared (first use in this function) _mysql.c:1906: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1920: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_store_result?: _mysql.c:1924: error: ?r? undeclared (first use in this function) _mysql.c:1926: error: ?args? undeclared (first use in this function) _mysql.c:1927: error: ?self? undeclared (first use in this function) _mysql.c:1932: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:1961: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_thread_id?: _mysql.c:1965: error: ?args? undeclared (first use in this function) _mysql.c:1966: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1981: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_use_result?: _mysql.c:1985: error: ?r? undeclared (first use in this function) _mysql.c:1987: error: ?args? undeclared (first use in this function) _mysql.c:1988: error: ?self? undeclared (first use in this function) _mysql.c:1993: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:2011: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dealloc?: _mysql.c:2015: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2025: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_repr?: _mysql.c:2028: error: ?self? undeclared (first use in this function) error: syntax error before ?r? _mysql.c:1698: error: ?args? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2042: error: syntax error before ?*? token _mysql.c:1699: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_data_seek?: _mysql.c:2046: error: ?args? undeclared (first use in this function) _mysql.c:1701: error: ?r? undeclared (first use in this function) _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2048: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2057: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_seek?: _mysql.c:2061: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2061: error: syntax error before ?r? _mysql.c:2062: error: ?args? undeclared (first use in this function) _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2064: error: ?self? undeclared (first use in this function) _mysql.c:2069: error: ?r? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2079: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_tell?: _mysql.c:2082: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2082: error: syntax error before ?r? _mysql.c:2083: error: ?args? undeclared (first use in thi_mysql.c: At top level:s function) _mysql.c:1712: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_kill?: _mysql.c:1717: error: ?args? undeclared (first use in this function) _mysql.c:2084: error: syntax error before ?)? token _mysql.c:2084: error: syntax error before ?)? token _mysql.c:1718: error: ?self? undeclared (first use in this function) _mysql.c:2085: error: ?self? undeclared (first use in this function) _mysql.c:2090: error: ?r? undeclared (first use in this function) _mysql.c: At top level:_mysql.c: At top level: _mysql.c:1735: error: syntax error before ?*? token _mysql.c:2096: error: syntax error before ?*? token_mysql.c: In function ?_mysql_ConnectionObject_field_count?: _mysql.c:1738: error: ?args? undeclared (first use in this function) _mysql.c:1739: error: ?self? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_dealloc?: _mysql.c:2098: error: ?self? undeclared (first use in this function) _mysql.c: At top level:_mysql.c: At top level: _mysql.c:1752: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_num_fields?: _mysql.c:2106: error: syntax error before ?*? token _mysql.c:1755: error: ?args? undeclared (first use in this function) _mysql.c: In function ?_mysql_ResultObject_repr?: _mysql.c:1756: error: syntax error before ?)? token _mysql.c:2110: error: ?self? undeclared (first use in this function) _mysql.c:1756: error: syntax error before ?)? token _mysql.c:1757: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1768: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_num_rows?: _mysql.c:1771: error: ?args? undeclared (first use in this function) _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1772: error: syntax error before ?)? token _mysql.c:1773: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1797: error: syntax error before ?*? token_mysql.c: At top level: _mysql.c:2330: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2337: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2344: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2351: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2358: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2421: error: syntax error before ?_mysql_ResultObject? _mysql.c:2433: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_getattr?: _mysql.c:2438: error: ?self? undeclared (first use in this function) _mysql.c:2438: error: ?name? undeclared (first use in this function) _mysql.c:2438: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2438: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2442: warning: passing argument 1 of ?strcmp? from incompatible pointer type _mysql.c:2443: error: ?struct PyMemberDef? has no member named ?open? _mysql.c:2450: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2451: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2453: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2461: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_getattr?: _mysql.c:2466: error: ?self? undeclared (first use in this function) _mysql.c:2466: error: ?name? undeclared (first use in this function) _mysql.c:2466: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2466: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2476: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2477: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2479: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2487: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_setattr?: _mysql.c:2491: error: ?v? undeclared (first use in this function) _mysql.c:2502: error: ?name? undeclared (first use in this function) _mysql.c:2502: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2503: error: ?self? undeclared (first use in this function) _mysql.c:2503: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2503: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2505: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2512: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_setattr?: _mysql.c:2516: error: ?v? undeclared (first use in this function) _mysql.c:2527: error: ?name? undeclared (first use in this function) _mysql.c:2527: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2528: error: ?self? undeclared (first use in this function) _mysql.c:2528: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2528: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2530: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: In function ?_mysql_ConnectionObject_ping?: _mysql.c:1801: error: ?args? undeclared (first use in this function) _mysql.c:1802: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1820: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_query?: _mysql.c:1825: error: ?args? undeclared (first use in this function) _mysql.c:1826: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1850: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_select_db?: _mysql.c:1855: error: ?args? undeclared (first use in this function) _mysql.c:1856: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1872: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_shutdown?: _mysql.c:1876: error: ?args? undeclared (first use in this function) _mysql.c:1877: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1899: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_stat?: _mysql.c:1903: error: ?args? undeclared (first use in this function) _mysql.c:1904: error: ?self? undeclared (first use in this function) _mysql.c:1906: warning: assignment makes pointer from integer without a cast _mysql.c: At top level: _mysql.c:1920: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_store_result?: _mysql.c:1924: error: ?r? undeclared (first use in this function) _mysql.c:1926: error: ?args? undeclared (first use in this function) _mysql.c:1927: error: ?self? undeclared (first use in this function) _mysql.c:1932: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:1961: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_thread_id?: _mysql.c:1965: error: ?args? undeclared (first use in this function) _mysql.c:1966: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:1981: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_use_result?: _mysql.c:1985: error: ?r? undeclared (first use in this function) _mysql.c:1987: error: ?args? undeclared (first use in this function) _mysql.c:1988: error: ?self? undeclared (first use in this function) _mysql.c:1993: error: syntax error before ?)? token _mysql.c: At top level: _mysql.c:2011: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_dealloc?: _mysql.c:2015: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2025: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_repr?: _mysql.c:2028: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2042: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_data_seek?: _mysql.c:2046: error: ?args? undeclared (first use in this function) _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2047: error: syntax error before ?)? token _mysql.c:2048: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2057: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_seek?: _mysql.c:2061: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2061: error: syntax error before ?r? _mysql.c:2062: error: ?args? undeclared (first use in this function) _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2063: error: syntax error before ?)? token _mysql.c:2064: error: ?self? undeclared (first use in this function) _mysql.c:2069: error: ?r? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2079: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_row_tell?: _mysql.c:2082: error: ?MYSQL_ROW_OFFSET? undeclared (first use in this function) _mysql.c:2082: error: syntax error before ?r? _mysql.c:2083: error: ?args? undeclared (first use in this function) _mysql.c:2084: error: syntax error before ?)? token _mysql.c:2084: error: syntax error before ?)? token _mysql.c:2085: error: ?self? undeclared (first use in this function) _mysql.c:2090: error: ?r? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2096: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_dealloc?: _mysql.c:2098: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2106: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_repr?: _mysql.c:2110: error: ?self? undeclared (first use in this function) _mysql.c: At top level: _mysql.c:2330: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2337: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2344: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2351: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2358: error: syntax error before ?_mysql_ConnectionObject? _mysql.c:2421: error: syntax error before ?_mysql_ResultObject? _mysql.c:2433: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_getattr?: _mysql.c:2438: error: ?self? undeclared (first use in this function) _mysql.c:2438: error: ?name? undeclared (first use in this function) _mysql.c:2438: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2438: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2442: warning: passing argument 1 of ?strcmp? from incompatible pointer type _mysql.c:2443: error: ?struct PyMemberDef? has no member named ?open? _mysql.c:2450: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2451: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2453: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2461: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_getattr?: _mysql.c:2466: error: ?self? undeclared (first use in this function) _mysql.c:2466: error: ?name? undeclared (first use in this function) _mysql.c:2466: warning: passing argument 2 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2466: warning: passing argument 3 of ?Py_FindMethod? from incompatible pointer type _mysql.c:2476: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2477: warning: passing argument 1 of ?PyMember_GetOne? from incompatible pointer type _mysql.c:2479: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2487: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ConnectionObject_setattr?: _mysql.c:2491: error: ?v? undeclared (first use in this function) _mysql.c:2502: error: ?name? undeclared (first use in this function) _mysql.c:2502: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2503: error: ?self? undeclared (first use in this function) _mysql.c:2503: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2503: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2505: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type _mysql.c: At top level: _mysql.c:2512: error: syntax error before ?*? token _mysql.c: In function ?_mysql_ResultObject_setattr?: _mysql.c:2516: error: ?v? undeclared (first use in this function) _mysql.c:2527: error: ?name? undeclared (first use in this function) _mysql.c:2527: warning: passing argument 2 of ?strcmp? from incompatible pointer type _mysql.c:2528: error: ?self? undeclared (first use in this function) _mysql.c:2528: warning: passing argument 1 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2528: warning: passing argument 3 of ?PyMember_SetOne? from incompatible pointer type _mysql.c:2530: warning: passing argument 2 of ?PyErr_SetString? from incompatible pointer type lipo: can't figure out the architecture type of: /var/folders/o5/ o5kYdZHuE3uFkIwBSAbeXE+++TI/-Tmp-//cctMmmFT.out error: command 'gcc-4.0' failed with exit status 1 From 54wutong at gmail.com Mon Feb 1 04:17:09 2010 From: 54wutong at gmail.com (Stephen.Wu) Date: Mon, 1 Feb 2010 01:17:09 -0800 (PST) Subject: how long a Str can be used in this python code segment? Message-ID: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> tmp=file.read() (very huge file) if targetStr in tmp: print "find it" else: print "not find" file.close() I checked if file.read() is huge to some extend, it doesn't work, but could any give me some certain information on this prolbem? From gherron at islandtraining.com Mon Feb 1 04:23:31 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 01 Feb 2010 01:23:31 -0800 Subject: gmtime In-Reply-To: <62938b5b-7eda-426c-b91d-3c7061840b2d@l26g2000yqd.googlegroups.com> References: <62938b5b-7eda-426c-b91d-3c7061840b2d@l26g2000yqd.googlegroups.com> Message-ID: <4B669D93.4070609@islandtraining.com> gazza wrote: > Hi, > > I am trying to discover how to obtain the correct time of say CST/ > America and EST/America in python? > > Any help on this would be appreciated. > > > Thanks, > Garyc > The datetime module should give you all you need. Gary Herron From clp2 at rebertia.com Mon Feb 1 04:26:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 01:26:55 -0800 Subject: how long a Str can be used in this python code segment? In-Reply-To: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: <50697b2c1002010126n7602495dlbf9cfc90755c8825@mail.gmail.com> On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wutong at gmail.com> wrote: > tmp=file.read() (very huge file) > if targetStr in tmp: > ? ?print "find it" > else: > ? ?print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? If the file's contents is larger than available memory, you'll get a MemoryError. To avoid this, you can read the file in by chunks (or if applicable, by lines) and see if each chunk/line matches. Cheers, Chris -- http://blog.rebertia.com From gherron at islandtraining.com Mon Feb 1 04:29:20 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 01 Feb 2010 01:29:20 -0800 Subject: how long a Str can be used in this python code segment? In-Reply-To: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: <4B669EF0.800@islandtraining.com> Stephen.Wu wrote: > tmp=file.read() (very huge file) > if targetStr in tmp: > print "find it" > else: > print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? > > Python has no specific limit on string size other than memory size and perhaps 32 bit address space and so on. However, if your file size is even a fraction of that size, you should not attempt to read it all into memory at once. Is there not a way to process your file in batches of a reasonable size? Gary Herron From 54wutong at gmail.com Mon Feb 1 04:33:09 2010 From: 54wutong at gmail.com (Stephen.Wu) Date: Mon, 1 Feb 2010 01:33:09 -0800 (PST) Subject: how long a Str can be used in this python code segment? References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: On Feb 1, 5:26?pm, Chris Rebert wrote: > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wut... at gmail.com> wrote: > > tmp=file.read() (very huge file) > > if targetStr in tmp: > > ? ?print "find it" > > else: > > ? ?print "not find" > > file.close() > > > I checked if file.read() is huge to some extend, it doesn't work, but > > could any give me some certain information on this prolbem? > > If the file's contents is larger than available memory, you'll get a > MemoryError. To avoid this, you can read the file in by chunks (or if > applicable, by lines) and see if each chunk/line matches. > > Cheers, > Chris > --http://blog.rebertia.com actually, I just use file.read(length) way, i just want to know what exactly para of length I should set, I'm afraid length doesn't equal to the amount of physical memory after trials... From stefan_ml at behnel.de Mon Feb 1 04:45:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Feb 2010 10:45:28 +0100 Subject: how long a Str can be used in this python code segment? In-Reply-To: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: <4b66a2b8$0$6582$9b4e6d93@newsspool3.arcor-online.net> Stephen.Wu, 01.02.2010 10:17: > tmp=file.read() (very huge file) > if targetStr in tmp: > print "find it" > else: > print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? Others have already pointed out that reading the entire file into memory is not a good idea. Try reading chunks repeatedly instead. As it appears that you simply try to find out if a file contains a specific byte sequence, you might find acora interesting: http://pypi.python.org/pypi/acora Also note that there are usually platform optimised tools available to search content in files, e.g. grep. It's basically impossible to beat their raw speed even with hand-tuned Python code, so running the right tool using the subprocess module might be a solution. Stefan From fetchinson at googlemail.com Mon Feb 1 05:14:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Feb 2010 11:14:42 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> Message-ID: > PEP 3147 has just been posted, proposing that, beginning in release > 3.2 (and possibly 2.7) compiled .pyc and .pyo files be placed in a > directory with a .pyr extension. The reason is so that compiled > versions of a program can coexist, which isn't possible now. > > Frankly, I think this is a really good idea, although I've got a few > comments. > > 1. Apple's MAC OS X should be mentioned, since 10.5 (and presumably > 10.6) ship with both Python release 2.3 and 2.5 installed. > > 2. I think the proposed logic is too complex. If this is installed in > 3.2, then that release should simply store its .pyc file in the .pyr > directory, without the need for either a command line switch or an > environment variable (both are mentioned in the PEP.) > > 3. Tool support. There are tools that look for the .pyc files; these > need to be upgraded somehow. The ones that ship with Python should, of > course, be fixed with the PEP, but there are others. > > 4. I'm in favor of putting the source in the .pyr directory as well, > but that's got a couple more issues. One is tool support, which is > likely to be worse for source, and the other is some kind of algorithm > for identifying which source goes with which object. I also think the PEP is a great idea and proposes a solution to a real problem. But I also hear the 'directory clutter' argument and I'm really concerned too, having all these extra directories around (and quite a large number of them indeed!). How about this scheme: 1. install python source files to a shared (among python installations) location /this/is/shared 2. when python X.Y imports a source file from /this/is/shared it will create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ Time comparison would be between /this/is/shared/x.py and /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. Obviously pythonX.Y needs to know the path to /this/is/shared so it can import modules from there, but this can be controlled by an environment variable. There would be only .py files in /this/is/shared. Linux distro packagers would only offer a single python-myapp to install and it would only contain python source, and the version-specific pyc files would be created the first time the application is used by python. In /usr/lib/pythonX.Y/site-packages there would be only pyc files with magic number matching python X.Y. So, basically nothing would change only the location of py and pyc files would be different from current behavior, but the same algorithm would be run to determine which one to load, when to create a pyc file, when to ignore the old one, etc. What would be wrong with this setup? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From peloko45 at gmail.com Mon Feb 1 05:19:39 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 1 Feb 2010 02:19:39 -0800 (PST) Subject: User-defined exceptions from 2.6 Message-ID: <12ef62c2-b291-414d-ad58-c18c2811379d@c29g2000yqd.googlegroups.com> Which is the best way to create user-defined exceptions since that *BaseException.message* is deprecated in Python 2.6 ? From jeanmichel at sequans.com Mon Feb 1 05:25:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 01 Feb 2010 11:25:15 +0100 Subject: SimpleXMLRPCServer daemon In-Reply-To: References: <1e689e5c-8e2a-4896-b867-717316fa783e@o26g2000vbd.googlegroups.com> Message-ID: <4B66AC0B.8050404@sequans.com> Gabriel Genellina wrote: > En Fri, 29 Jan 2010 12:54:23 -0300, Thomas Allen > escribi?: > >> I have a script that runs an instance of SimpleXMLRPCServer and in >> general it works as expected. In its __del__, it is supposed to clean >> up its PID file (written on boot). I have two problems with this >> server instance: The first is that tt doesn't always clean up its PID >> file; is there a more reliable way to do this than how I am currently? >> The second is that when it does crash, I don't know about it...what >> would be sufficient as a "keep-alive" script to restart it? I suppose >> I could use something like EventMachine (already installed on my >> server) to watch the PID file if it were deleted reliably. > > I agree with the recommendation of using some daemon library; doing it > right is better left to the experts :) > But if you can't or don't want to alter your code so much, I suggest: > > - use atexit.register, instead of __del__, to delete the PID file > - keep a lock on the pid file; if a second instance is able to write > to it, it means it's an orphan from a previous, aborted run. (Checking > whether a process with such pid exists is not enough - pids are > recycled rather fast) > see also http://code.activestate.com/recipes/278731/ JM From rohitraj007 at gmail.com Mon Feb 1 05:26:13 2010 From: rohitraj007 at gmail.com (Rohit Roger$) Date: Mon, 1 Feb 2010 15:56:13 +0530 Subject: Python-list Digest, Vol 77, Issue 7 * In-Reply-To: <4755336292109192622@unknownmsgid> References: <4755336292109192622@unknownmsgid> Message-ID: Hello Help for datetime module Source code is : *from *datetime *import *datetime d = datetime(datetime.now().year, datetime.now().month, datetime.now().day, 11, 59, 0 ) print d On Mon, Feb 1, 2010 at 3:44 PM, wrote: > Junk Score: 2 out of 10 (below your Auto Allow threshold) > | Approve sender | Block > sender | Block > domain > > 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: whassup? builtins? python3000? Naah can't be right? > (Andrej Mitrovic) > 2. gmtime (gazza) > 3. Re: A performance issue when using default value (keakon) > 4. Re: HTML Parser which allows low-keyed local changes? > (Stefan Behnel) > 5. how long a Str can be used in this python code segment? > (Stephen.Wu) > 6. Re: gmtime (Gary Herron) > 7. Re: how long a Str can be used in this python code segment? > (Chris Rebert) > 8. Re: how long a Str can be used in this python code segment? > (Gary Herron) > 9. Re: Keyboard input (Dennis Lee Bieber) > 10. Re: how long a Str can be used in this python code segment? > (Stephen.Wu) > 11. Re: how long a Str can be used in this python code segment? > (Stefan Behnel) > 12. Re: PEP 3147 - new .pyc format (Daniel Fetchinson) > > > ---------- Forwarded message ---------- > From: Andrej Mitrovic > To: > Date: Sun, 31 Jan 2010 20:01:57 -0800 (PST) > Subject: Re: whassup? builtins? python3000? Naah can't be right? > Hey, it's really simple! Just like the excerpt from the Learning > Python book says: > > "Really, the built-in scope is just a built-in module called builtins, > but > you have to import builtins to query built-ins because the name > builtins is not itself > built-in...." > > :) > > > > ---------- Forwarded message ---------- > From: gazza > To: > Date: Sun, 31 Jan 2010 13:27:46 -0800 (PST) > Subject: gmtime > Hi, > > I am trying to discover how to obtain the correct time of say CST/ > America and EST/America in python? > > Any help on this would be appreciated. > > > Thanks, > Garyc > > > > ---------- Forwarded message ---------- > From: keakon > To: > Date: Sun, 31 Jan 2010 21:20:28 -0800 (PST) > Subject: Re: A performance issue when using default value > Even this style is 41 times faster than h2(): > > def i2(x=[]): > y = x > if not y: # add this line > y = [] # add this line > y.append(1) > return y + [] > > print Timer('i2()','from __main__ import f2, g2, h2, i2').timeit > (TIMES) > > Time: 0.00742356919664 > > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: > Date: Mon, 01 Feb 2010 09:34:28 +0100 > Subject: Re: HTML Parser which allows low-keyed local changes? > Robert, 31.01.2010 20:57: > > I tried lxml, but after walking and making changes in the element tree, > > I'm forced to do a full serialization of the whole document > > (etree.tostring(tree)) - which destroys the "human edited" format of the > > original HTML code. makes it rather unreadable. > > What do you mean? Could you give an example? lxml certainly does not > destroy anything it parsed, unless you tell it to do so. > > Stefan > > > > ---------- Forwarded message ---------- > From: "Stephen.Wu" <54wutong at gmail.com> > To: python-list at python.org > Date: Mon, 1 Feb 2010 01:17:09 -0800 (PST) > Subject: how long a Str can be used in this python code segment? > tmp=file.read() (very huge file) > if targetStr in tmp: > print "find it" > else: > print "not find" > file.close() > > I checked if file.read() is huge to some extend, it doesn't work, but > could any give me some certain information on this prolbem? > > > > > ---------- Forwarded message ---------- > From: Gary Herron > To: "python-list at python.org" > Date: Mon, 01 Feb 2010 01:23:31 -0800 > Subject: Re: gmtime > gazza wrote: > >> Hi, >> >> I am trying to discover how to obtain the correct time of say CST/ >> America and EST/America in python? >> >> Any help on this would be appreciated. >> >> >> Thanks, >> Garyc >> >> > The datetime module should give you all you need. > > Gary Herron > > > > > > ---------- Forwarded message ---------- > From: Chris Rebert > To: "Stephen.Wu" <54wutong at gmail.com> > Date: Mon, 1 Feb 2010 01:26:55 -0800 > Subject: Re: how long a Str can be used in this python code segment? > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wutong at gmail.com> wrote: > > tmp=file.read() (very huge file) > > if targetStr in tmp: > > print "find it" > > else: > > print "not find" > > file.close() > > > > I checked if file.read() is huge to some extend, it doesn't work, but > > could any give me some certain information on this prolbem? > > If the file's contents is larger than available memory, you'll get a > MemoryError. To avoid this, you can read the file in by chunks (or if > applicable, by lines) and see if each chunk/line matches. > > Cheers, > Chris > -- > http://blog.rebertia.com > > > > ---------- Forwarded message ---------- > From: Gary Herron > To: > Date: Mon, 01 Feb 2010 01:29:20 -0800 > Subject: Re: how long a Str can be used in this python code segment? > Stephen.Wu wrote: > >> tmp=file.read() (very huge file) >> if targetStr in tmp: >> print "find it" >> else: >> print "not find" >> file.close() >> >> I checked if file.read() is huge to some extend, it doesn't work, but >> could any give me some certain information on this prolbem? >> >> >> > > Python has no specific limit on string size other than memory size and > perhaps 32 bit address space and so on. However, if your file size is even > a fraction of that size, you should not attempt to read it all into memory > at once. Is there not a way to process your file in batches of a reasonable > size? > > Gary Herron > > > > > > ---------- Forwarded message ---------- > From: Dennis Lee Bieber > To: python-list at python.org > Date: Mon, 01 Feb 2010 01:31:25 -0800 > Subject: Re: Keyboard input > On 31 Jan 2010 22:40:55 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > > On Sun, 31 Jan 2010 14:10:34 -0800, Dennis Lee Bieber wrote: > > > > > On Sun, 31 Jan 2010 11:51:46 +0000, "Mr.SpOOn" > > > declaimed the following in gmane.comp.python.general: > > > > > >> 2010/1/29 Gabriel Genellina : > > >> > > > >> > That's strange. If you're using Linux, make sure you have the > > >> > readline package installed. > > >> > > >> I'm using Linux. Ubuntu. I checked on synaptic and I have > > >> readline-common. Do you mean something else? > > >> > > > But was your Python /built/ using readline? > > > > > > How do you ensure that it is? > > Well... I think the practice on the Linux variants is to set various > options when building Python locally. I'm on WinXP and rely upon the > packagers to build with everything available (and may need to check > the documentation of those builds as described by the packagers) > > It may mean ensuring not only that the runtime library is present, > but that the development library (C-language header files, etc.) are > installed. > -- > Wulfraed Dennis Lee Bieber KD6MOG > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > > > ---------- Forwarded message ---------- > From: "Stephen.Wu" <54wutong at gmail.com> > To: python-list at python.org > Date: Mon, 1 Feb 2010 01:33:09 -0800 (PST) > Subject: Re: how long a Str can be used in this python code segment? > On Feb 1, 5:26 pm, Chris Rebert wrote: > > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wut... at gmail.com> wrote: > > > tmp=file.read() (very huge file) > > > if targetStr in tmp: > > > print "find it" > > > else: > > > print "not find" > > > file.close() > > > > > I checked if file.read() is huge to some extend, it doesn't work, but > > > could any give me some certain information on this prolbem? > > > > If the file's contents is larger than available memory, you'll get a > > MemoryError. To avoid this, you can read the file in by chunks (or if > > applicable, by lines) and see if each chunk/line matches. > > > > Cheers, > > Chris > > --http://blog.rebertia.com > > actually, I just use file.read(length) way, i just want to know what > exactly para of length I should set, I'm afraid length doesn't equal > to the amount of physical memory after trials... > > > > ---------- Forwarded message ---------- > From: Stefan Behnel > To: python-list at python.org > Date: Mon, 01 Feb 2010 10:45:28 +0100 > Subject: Re: how long a Str can be used in this python code segment? > Stephen.Wu, 01.02.2010 10:17: > > tmp=file.read() (very huge file) > > if targetStr in tmp: > > print "find it" > > else: > > print "not find" > > file.close() > > > > I checked if file.read() is huge to some extend, it doesn't work, but > > could any give me some certain information on this prolbem? > > Others have already pointed out that reading the entire file into memory is > not a good idea. Try reading chunks repeatedly instead. > > As it appears that you simply try to find out if a file contains a specific > byte sequence, you might find acora interesting: > > http://pypi.python.org/pypi/acora > > Also note that there are usually platform optimised tools available to > search content in files, e.g. grep. It's basically impossible to beat their > raw speed even with hand-tuned Python code, so running the right tool using > the subprocess module might be a solution. > > Stefan > > > > ---------- Forwarded message ---------- > From: Daniel Fetchinson > To: Python > Date: Mon, 1 Feb 2010 11:14:42 +0100 > Subject: Re: PEP 3147 - new .pyc format > > PEP 3147 has just been posted, proposing that, beginning in release > > 3.2 (and possibly 2.7) compiled .pyc and .pyo files be placed in a > > directory with a .pyr extension. The reason is so that compiled > > versions of a program can coexist, which isn't possible now. > > > > Frankly, I think this is a really good idea, although I've got a few > > comments. > > > > 1. Apple's MAC OS X should be mentioned, since 10.5 (and presumably > > 10.6) ship with both Python release 2.3 and 2.5 installed. > > > > 2. I think the proposed logic is too complex. If this is installed in > > 3.2, then that release should simply store its .pyc file in the .pyr > > directory, without the need for either a command line switch or an > > environment variable (both are mentioned in the PEP.) > > > > 3. Tool support. There are tools that look for the .pyc files; these > > need to be upgraded somehow. The ones that ship with Python should, of > > course, be fixed with the PEP, but there are others. > > > > 4. I'm in favor of putting the source in the .pyr directory as well, > > but that's got a couple more issues. One is tool support, which is > > likely to be worse for source, and the other is some kind of algorithm > > for identifying which source goes with which object. > > I also think the PEP is a great idea and proposes a solution to a real > problem. But I also hear the 'directory clutter' argument and I'm > really concerned too, having all these extra directories around (and > quite a large number of them indeed!). How about this scheme: > > 1. install python source files to a shared (among python > installations) location /this/is/shared > 2. when python X.Y imports a source file from /this/is/shared it will > create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ > Time comparison would be between /this/is/shared/x.py and > /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. > > Obviously pythonX.Y needs to know the path to /this/is/shared so it > can import modules from there, but this can be controlled by an > environment variable. There would be only .py files in > /this/is/shared. > > Linux distro packagers would only offer a single python-myapp to > install and it would only contain python source, and the > version-specific pyc files would be created the first time the > application is used by python. In /usr/lib/pythonX.Y/site-packages > there would be only pyc files with magic number matching python X.Y. > > So, basically nothing would change only the location of py and pyc > files would be different from current behavior, but the same algorithm > would be run to determine which one to load, when to create a pyc > file, when to ignore the old one, etc. > > What would be wrong with this setup? > > Cheers, > Daniel > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gjango.py at gmail.com Mon Feb 1 05:35:06 2010 From: gjango.py at gmail.com (guptha) Date: Mon, 1 Feb 2010 02:35:06 -0800 (PST) Subject: Any Python Module to send ring tones from PC to mobile via GSM modem Message-ID: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> Hi group, Is there any python module available which sends ring tones from our PC to mobile phone using GSM Modem. I googled in vain to find a solution .I can find few modules like pygsm ,singshotsms by which only sms is send .I could appreciate if some one helps me to find a way to send ring tones . Thanks Ganesh From tino at wildenhain.de Mon Feb 1 06:07:36 2010 From: tino at wildenhain.de (Tino Wildenhain) Date: Mon, 01 Feb 2010 12:07:36 +0100 Subject: Any Python Module to send ring tones from PC to mobile via GSM modem In-Reply-To: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> References: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> Message-ID: <4B66B5F8.9020506@wildenhain.de> Hi Ganesh, Am 01.02.2010 11:35, schrieb guptha: > Hi group, > Is there any python module available which sends ring tones from our > PC to mobile phone using GSM Modem. > I googled in vain to find a solution .I can find few modules like > pygsm ,singshotsms by which only sms is send .I could appreciate if > some one helps me to find a way to send ring tones . If you really want to send via GSM (e.g. over the air to another Phone) it seems you need to generate an MMS instead of SMS. If thats not the case and you only want to upload tones to your phone via wire/bluetooth, obex should be the key to find more information on how to do that. Regards Tino -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3254 bytes Desc: S/MIME Cryptographic Signature URL: From stef.mientki at gmail.com Mon Feb 1 06:14:13 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 01 Feb 2010 12:14:13 +0100 Subject: how to decode rtf characterset ? Message-ID: <4B66B785.1090406@gmail.com> hello, I want to translate rtf files to unicode strings. I succeeded in remove all the tags, but now I'm stucked to the special accent characters, like : "V??r" the character "?" is represented by the string r"\'f3", or in bytes: 92, 39,102, 51 so I think I need a way to translate that into the string r"\xf3" but I can't find a way to accomplish that. a Any suggestions are very welcome. thanks, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From bblais at bryant.edu Mon Feb 1 06:27:27 2010 From: bblais at bryant.edu (Brian Blais) Date: Mon, 01 Feb 2010 06:27:27 -0500 Subject: [Edu-sig] odd drawing problem with turtle.py In-Reply-To: References: Message-ID: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> > On Jan 31, 2010, at 23:05 , John Posner wrote: > >> Try commenting out this statement: >> >> self.turtle.tracer(False) >> >> That helps on Python 2.6.4. interesting. It seems as if the tracer property is a global one: In [1]:t1=Turtle() In [2]:t1.tracer() Out[2]:1 In [3]:t1.tracer(False) In [4]:t1.tracer() Out[4]:0 In [5]:t2=Turtle() In [6]:t2.tracer() Out[6]:0 In [7]:t2.tracer(True) In [8]:t1.tracer() Out[8]:1 looks like I need to set the tracer manually. however, even if the tracer is off, shouldn't it still draw the line? when I put in the T.tracer(True) it works, but I shouldn't need to I think. On Jan 31, 2010, at 21:11 , kirby urner wrote: > I don't see where you've defined a Turtle class to instantiate sir. Turtle is given in turtle.py. I should have subclassed it, but I was being lazy. :) thanks for the fast replies! bb > On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais > wrote: >> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - >> 24. 9. >> 2009. The following script draws 5 circles, which it is supposed >> to, but >> then doesn't draw the second turtle which is supposed to simply move >> forward. Any ideas? >> from turtle import * >> from numpy.random import randint >> resetscreen() >> class Circle(object): >> def __init__(self,x,y,r,color): >> self.x=x >> self.y=y >> self.r=r >> self.color=color >> >> self.turtle=Turtle(visible=False) >> self.turtle.tracer(False) >> self.draw() >> >> def draw(self): >> self.turtle.penup() >> self.turtle.setposition(self.x,self.y) >> self.turtle.setheading(0) >> self.turtle.backward(self.r) >> self.turtle.pendown() >> self.turtle.fill(True) >> self.turtle.pencolor("black") >> self.turtle.fillcolor(self.color) >> self.turtle.circle(self.r) >> self.turtle.fill(False) >> self.turtle.penup() >> >> for i in range(5): >> c=Circle(randint(-350,350),randint(-250,250),10,"red") >> >> >> T=Turtle() >> T.forward(100) >> T.forward(100) >> >> >> >> >> >> >> >> thanks, >> >> bb >> -- >> Brian Blais >> bblais at bryant.edu >> http://web.bryant.edu/~bblais >> http://bblais.blogspot.com/ >> >> >> >> _______________________________________________ >> Edu-sig mailing list >> Edu-sig at python.org >> http://mail.python.org/mailman/listinfo/edu-sig >> >> -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gobladoome at gmail.com Mon Feb 1 06:36:00 2010 From: gobladoome at gmail.com (Paul Atkin) Date: Tue, 2 Feb 2010 00:36:00 +1300 Subject: Embedded python 2.6 in C++ problems Message-ID: <5089497e1002010336k3e3882el451fc4e56946e7cd@mail.gmail.com> Hi, I'm extending some old Visual Studio 6 MFC code to add embedded python scripting. It works fine most of the time but some python function calls do not work as expected. The C++ code is a multithreaded MFC application. I was assuming that it was GIL issues but I have tried using the manual locking (PyEval_SaveThread & PyEval_RestoreThread) and what seems to be the current method (PyGILState_Ensure & PyGILState_Release) Here's the error I'm getting: Traceback (most recent call last): File "...scripts\receipt_parser.py", line 296, in get_giftcard_purchase_value details = extract_transaction_details_section(test) File "...scripts\receipt_parser.py", line 204, in extract_transaction_details_section for line in base_details: TypeError: expected string or Unicode object, NoneType found base_details is a string variable and the code runs fine when run from standard interpreter. Many other function calls work fine from the embedded app. I create and then Py_DECREF the function parameters and the return value after each function call. The module import is created at C++ object constructor and then Py_DECREF'd in the desctuctor Anyone else had issues of this kind? Thanks, Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gobladoome at gmail.com Mon Feb 1 06:51:48 2010 From: gobladoome at gmail.com (Paul Atkin) Date: Tue, 2 Feb 2010 00:51:48 +1300 Subject: Embedded python 2.6 in C++ problems Message-ID: <5089497e1002010351s773d5a87pb3df73e20f00f1f5@mail.gmail.com> Hi, I'm extending some old Visual Studio 6 MFC code to add embedded python scripting. It works fine most of the time but some python function calls do not work as expected. The C++ code is a multithreaded MFC application. I was assuming that it was GIL issues but I have tried using the manual locking (PyEval_SaveThread & PyEval_RestoreThread) and what seems to be the current method (PyGILState_Ensure & PyGILState_Release) Here's the error I'm getting: Traceback (most recent call last): File "...scripts\receipt_parser.py", line 296, in get_giftcard_purchase_value details = extract_transaction_details_section(test) File "...scripts\receipt_parser.py", line 204, in extract_transaction_details_section for line in base_details: TypeError: expected string or Unicode object, NoneType found base_details is a string variable and the code runs fine when run from standard interpreter. Many other function calls work fine from the embedded app. I create and then Py_DECREF the function parameters and the return value after each function call. The module import is created at C++ object constructor and then Py_DECREF'd in the desctuctor Anyone else had issues of this kind? Thanks, Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: From solipsis at pitrou.net Mon Feb 1 07:06:25 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 1 Feb 2010 12:06:25 +0000 (UTC) Subject: recv_into(bytearray) complains about a "pinned buffer" References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> Message-ID: Le Mon, 01 Feb 2010 03:30:56 +0100, Martin v. Loewis a ?crit?: > >> Is this a bug in Python 2.6 or a deliberate choice regarding >> implementation concerns I don't know about? > > It's actually a bug also that you pass an array; doing so *should* give > the very same error. Well, if you can give neither an array nor a bytearray to recv_into(), what *could* you give it? recv_into() should simply be fixed to use the new buffer API, as it does in 3.x. From gjango.py at gmail.com Mon Feb 1 07:39:47 2010 From: gjango.py at gmail.com (guptha) Date: Mon, 1 Feb 2010 04:39:47 -0800 (PST) Subject: Any Python Module to send ring tones from PC to mobile via GSM modem References: <2c57270e-75a9-471e-b679-c15b9c689c07@v20g2000prb.googlegroups.com> Message-ID: <8406f031-202a-4245-8038-edf548dbad6c@v20g2000prb.googlegroups.com> Hi,Tino Thanks for your reply, My PC is connected with cell phone (through data card) as a modem,and my OS is Ubuntu I have to send ring tones from my PC to any other cell phone by using connected cell phone as a modem (Your first case satisfy my need ) I think with pygsm, it is not possible to send MMS,if so what could be the apt python module to work with .what about python-gammu? can any one point me a url which gives detail tutorial on this topic thanks ganesh From steve at REMOVE-THIS-cybersource.com.au Mon Feb 1 07:45:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 12:45:53 GMT Subject: User-defined exceptions from 2.6 References: <12ef62c2-b291-414d-ad58-c18c2811379d@c29g2000yqd.googlegroups.com> Message-ID: <0376b953$0$1309$c3e8da3@news.astraweb.com> On Mon, 01 Feb 2010 02:19:39 -0800, Joan Miller wrote: > Which is the best way to create user-defined exceptions since that > *BaseException.message* is deprecated in Python 2.6 ? Inherit from an existing exception. >>> class MyValueException(ValueError): ... pass ... >>> >>> raise MyValueException("value is impossible, try again") Traceback (most recent call last): File "", line 1, in __main__.MyValueException: value is impossible, try again >>> class GenericError(Exception): ... pass ... >>> raise GenericError("oops") Traceback (most recent call last): File "", line 1, in __main__.GenericError: oops Do you need anything more complicated? -- Steven From magawake at gmail.com Mon Feb 1 07:47:02 2010 From: magawake at gmail.com (Mag Gam) Date: Mon, 1 Feb 2010 07:47:02 -0500 Subject: libpcap and python Message-ID: <1cbd6f831002010447w4a2ab26dve66206919e99391@mail.gmail.com> Hello All, I used tcpdump to capture data on my network. I would like to analyze the data using python -- currently using ethereal and wireshark. I would like to get certain type of packets (I can get the hex code for them), what is the best way to do this? Lets say I want to capture all events of `ping localhost` TIA From steve at holdenweb.com Mon Feb 1 07:55:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Feb 2010 07:55:28 -0500 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: Steven D'Aprano wrote: > On Sun, 31 Jan 2010 22:43:56 -0800, alex23 wrote: > >> Steven D'Aprano wrote: >>> You're using that term wrong. It looks to me that you don't actually >>> know what a straw man argument is. A straw man argument is when >>> somebody responds to a deliberately weakened or invalid argument as if >>> it had been made by their opponent. >> Jeez, Steve, you're beginning to sound like some kind of fallacy >> zealot... ;) > > Death to all those who confuse agumentum ad populum with argumentum ad > verecundiam!!! > > Yeah, what did the zealots ever do for us? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 1 07:57:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Feb 2010 07:57:16 -0500 Subject: Python and Ruby In-Reply-To: References: <0375f245$0$1309$c3e8da3@news.astraweb.com> Message-ID: Terry Reedy wrote: > On 1/31/2010 7:25 PM, Steven D'Aprano wrote: >> On Sun, 31 Jan 2010 15:40:36 -0800, Chris Rebert wrote: >> >>> On Sun, Jan 31, 2010 at 2:36 PM, Steven D'Aprano >>> wrote: >>>> On Sun, 31 Jan 2010 04:28:41 -0800, Ed Keith wrote: >>>>> In most functional languages you just name a function to access it and >>>>> you do it ALL the time. >>>>> >>>>> for example, in if you have a function 'f' which takes two parameters >>>>> to call the function and get the result you use: >>>>> >>>>> f 2 3 >>>>> >>>>> If you want the function itself you use: >>>>> >>>>> f >>>> >>>> How do you call a function of no arguments? >>> >>> It's not really a function in that case, it's just a named constant. >>> (Recall that functions don't/can't have side-effects.) > > Three of you gave essentially identical answers, but I still do not see > how given something like > > def f(): return 1 > > I differentiate between 'function object at address xxx' and 'int 1' > objects. > But in a functional environment you don't need to. That's pretty much the whole point. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From peloko45 at gmail.com Mon Feb 1 07:59:03 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 1 Feb 2010 04:59:03 -0800 (PST) Subject: User-defined exceptions from 2.6 References: <12ef62c2-b291-414d-ad58-c18c2811379d@c29g2000yqd.googlegroups.com> <0376b953$0$1309$c3e8da3@news.astraweb.com> Message-ID: <4f599822-4037-4378-93bc-0ffd45ad3e5e@l26g2000yqd.googlegroups.com> On 1 feb, 12:45, Steven D'Aprano wrote: > On Mon, 01 Feb 2010 02:19:39 -0800, Joan Miller wrote: > > Which is the best way to create user-defined exceptions since that > > *BaseException.message* is deprecated in Python 2.6 ? > > Inherit from an existing exception. > > >>> class MyValueException(ValueError): > > ... ? ? pass > ... > > >>> raise MyValueException("value is impossible, try again") > > Traceback (most recent call last): > ? File "", line 1, in > __main__.MyValueException: value is impossible, try again > > >>> class GenericError(Exception): > > ... ? ? pass > ...>>> raise GenericError("oops") > > Traceback (most recent call last): > ? File "", line 1, in > __main__.GenericError: oops > > Do you need anything more complicated? > It's enought, thanks! From no-spam at non-existing.invalid Mon Feb 1 08:36:37 2010 From: no-spam at non-existing.invalid (Robert) Date: Mon, 01 Feb 2010 14:36:37 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Stefan Behnel wrote: > Robert, 31.01.2010 20:57: >> I tried lxml, but after walking and making changes in the element tree, >> I'm forced to do a full serialization of the whole document >> (etree.tostring(tree)) - which destroys the "human edited" format of the >> original HTML code. makes it rather unreadable. > > What do you mean? Could you give an example? lxml certainly does not > destroy anything it parsed, unless you tell it to do so. > of course it does not destroy during parsing.(?) I mean: I want to walk with a Python script through the parsed tree HTML and modify here and there things (auto alt tags from DB/similar, link corrections, text sections/translated sentences... due to HTML code and content checks.) Then I want to output the changed tree - but as close to the original format as far as possible. No changes to my white space identation, etc.. Only lokal changes, where really tags where changed. Thats similiar like that what a good HTML editor does: After you made little changes, it doesn't reformat/re-spit-out your whole code layout from tree/attribute logic only. you have lokal changes only. But a simple HTML editor like that in Mozilla-Seamonkey outputs a whole new HTML, produces the HTML from logical tree only (regarding his (ugly) style), destroys my whitspace layout and much more - forgetting anything about the original layout. Such a "good HTML editor" must somehow track the original positions of the tags in the file. And during each logical change in the tree it must tracks the file position changes/offsets. That thing seems to miss in lxml and BeautifulSoup which I tried so far. This is a frequent need I have. Nobody else's? Seems I need to write my own or patch BS to do that extra tracking? Robert From vceder at canterburyschool.org Mon Feb 1 08:48:08 2010 From: vceder at canterburyschool.org (Vern Ceder) Date: Mon, 01 Feb 2010 08:48:08 -0500 Subject: [Edu-sig] odd drawing problem with turtle.py In-Reply-To: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> References: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> Message-ID: <4B66DB98.9030800@canterburyschool.org> Brian Blais wrote: >> On Jan 31, 2010, at 23:05 , John Posner wrote: >> >>> Try commenting out this statement: >>> >>> self.turtle.tracer(False) >>> >>> That helps on Python 2.6.4. > > > interesting. It seems as if the tracer property is a global one: Actually, the tracer method that does the work is part of the TurtleScreen class, and individual Turtle instances just access the tracer method of the TurtleScreen they inhabit... if that makes sense. So since your turtles are on the same screen, yes, in effect, tracer is sort of global. Cheers, Vern > > In [1]:t1=Turtle() > > In [2]:t1.tracer() > Out[2]:1 > > In [3]:t1.tracer(False) > > In [4]:t1.tracer() > Out[4]:0 > > In [5]:t2=Turtle() > > In [6]:t2.tracer() > Out[6]:0 > > In [7]:t2.tracer(True) > > In [8]:t1.tracer() > Out[8]:1 > > looks like I need to set the tracer manually. > > however, even if the tracer is off, shouldn't it still draw the line? > when I put in the T.tracer(True) it works, but I shouldn't need to I think. > > > On Jan 31, 2010, at 21:11 , kirby urner wrote: > >> I don't see where you've defined a Turtle class to instantiate sir. > > Turtle is given in turtle.py. I should have subclassed it, but I was > being lazy. :) > > thanks for the fast replies! > > > bb > > >> On Sun, Jan 31, 2010 at 4:27 PM, Brian Blais > > wrote: >>> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9. >>> 2009. The following script draws 5 circles, which it is supposed to, but >>> then doesn't draw the second turtle which is supposed to simply move >>> forward. Any ideas? >>> from turtle import * >>> from numpy.random import randint >>> resetscreen() >>> class Circle(object): >>> def __init__(self,x,y,r,color): >>> self.x=x >>> self.y=y >>> self.r=r >>> self.color=color >>> >>> self.turtle=Turtle(visible=False) >>> self.turtle.tracer(False) >>> self.draw() >>> >>> def draw(self): >>> self.turtle.penup() >>> self.turtle.setposition(self.x,self.y) >>> self.turtle.setheading(0) >>> self.turtle.backward(self.r) >>> self.turtle.pendown() >>> self.turtle.fill(True) >>> self.turtle.pencolor("black") >>> self.turtle.fillcolor(self.color) >>> self.turtle.circle(self.r) >>> self.turtle.fill(False) >>> self.turtle.penup() >>> >>> for i in range(5): >>> c=Circle(randint(-350,350),randint(-250,250),10,"red") >>> >>> >>> T=Turtle() >>> T.forward(100) >>> T.forward(100) >>> >>> >>> >>> >>> >>> >>> >>> thanks, >>> >>> bb >>> -- >>> Brian Blais >>> bblais at bryant.edu >>> http://web.bryant.edu/~bblais >>> http://bblais.blogspot.com/ >>> >>> >>> >>> _______________________________________________ >>> Edu-sig mailing list >>> Edu-sig at python.org >>> http://mail.python.org/mailman/listinfo/edu-sig >>> >>> > > -- > Brian Blais > bblais at bryant.edu > http://web.bryant.edu/~bblais > http://bblais.blogspot.com/ > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Edu-sig mailing list > Edu-sig at python.org > http://mail.python.org/mailman/listinfo/edu-sig -- This time for sure! -Bullwinkle J. Moose ----------------------------- Vern Ceder, Director of Technology Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804 vceder at canterburyschool.org; 260-436-0746; FAX: 260-436-5137 The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW From no-spam at non-existing.invalid Mon Feb 1 08:54:59 2010 From: no-spam at non-existing.invalid (Robert) Date: Mon, 01 Feb 2010 14:54:59 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Robert wrote: > Stefan Behnel wrote: >> Robert, 31.01.2010 20:57: >>> I tried lxml, but after walking and making changes in the element tree, >>> I'm forced to do a full serialization of the whole document >>> (etree.tostring(tree)) - which destroys the "human edited" format of the >>> original HTML code. makes it rather unreadable. >> >> What do you mean? Could you give an example? lxml certainly does not >> destroy anything it parsed, unless you tell it to do so. >> > > of course it does not destroy during parsing.(?) > > I mean: I want to walk with a Python script through the parsed tree HTML > and modify here and there things (auto alt tags from DB/similar, link > corrections, text sections/translated sentences... due to HTML code and > content checks.) > > Then I want to output the changed tree - but as close to the original > format as far as possible. No changes to my white space identation, > etc.. Only lokal changes, where really tags where changed. > > Thats similiar like that what a good HTML editor does: After you made > little changes, it doesn't reformat/re-spit-out your whole code layout > from tree/attribute logic only. you have lokal changes only. > But a simple HTML editor like that in Mozilla-Seamonkey outputs a whole > new HTML, produces the HTML from logical tree only (regarding his (ugly) > style), destroys my whitspace layout and much more - forgetting > anything about the original layout. > > Such a "good HTML editor" must somehow track the original positions of > the tags in the file. And during each logical change in the tree it must > tracks the file position changes/offsets. That thing seems to miss in > lxml and BeautifulSoup which I tried so far. > > This is a frequent need I have. Nobody else's? > > Seems I need to write my own or patch BS to do that extra tracking? > basic feature(s) of such parser perhaps: * can it tell for each tag object in the parsed tree, at what original file position start:end it resided? even a basic need: tell me the line number e.g. (for warning/analysis reports e.g.) (* do the tree objects auto track/know if they were changed. (for convenience; a tree copy may serve this otherwise .. ) the creation of a output with local changes whould be rather simple from that ... Robert From stefan_ml at behnel.de Mon Feb 1 09:05:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 01 Feb 2010 15:05:39 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Robert, 01.02.2010 14:36: > Stefan Behnel wrote: >> Robert, 31.01.2010 20:57: >>> I tried lxml, but after walking and making changes in the element tree, >>> I'm forced to do a full serialization of the whole document >>> (etree.tostring(tree)) - which destroys the "human edited" format of the >>> original HTML code. makes it rather unreadable. >> >> What do you mean? Could you give an example? lxml certainly does not >> destroy anything it parsed, unless you tell it to do so. > > of course it does not destroy during parsing.(?) I meant "parsed" in the sense of "has parsed and is now working on". > I mean: I want to walk with a Python script through the parsed tree HTML > and modify here and there things (auto alt tags from DB/similar, link > corrections, text sections/translated sentences... due to HTML code and > content checks.) Sure, perfectly valid use case. > Then I want to output the changed tree - but as close to the original > format as far as possible. No changes to my white space identation, > etc.. Only lokal changes, where really tags where changed. That's up to you. If you only apply local changes that do not change any surrounding whitespace, you'll be fine. > Thats similiar like that what a good HTML editor does: After you made > little changes, it doesn't reformat/re-spit-out your whole code layout > from tree/attribute logic only. you have lokal changes only. HTML editors don't work that way. They always "re-spit-out" the whole code when you click on "save". They certainly don't track the original file position of tags. What they preserve is the content, including whitespace (or not, if they reformat the code, but that's usually an *option*). > Such a "good HTML editor" must somehow track the original positions of > the tags in the file. And during each logical change in the tree it must > tracks the file position changes/offsets. Sorry, but that's nonsense. The file position of a tag is determined by whitespace, i.e. line endings and indentation. lxml does not alter that, unless you tell it do do so. Since you keep claiming that it *does* alter it, please come up with a reproducible example that shows a) what you do in your code, b) what your input is and c) what unexpected output it creates. Do not forget to include the version number of lxml and libxml2 that you are using, as well as a comment on /how/ the output differs from what you expected. My stab in the dark is that you forgot to copy the tail text of elements that you replace by new content, and that you didn't properly indent new content that you added. But that's just that, a stab in the dark. You didn't provide enough information for even an educated guess. Stefan From invalid at invalid.invalid Mon Feb 1 10:09:29 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 1 Feb 2010 15:09:29 +0000 (UTC) Subject: libpcap and python References: Message-ID: On 2010-02-01, Mag Gam wrote: > Hello All, > > I used tcpdump to capture data on my network. I would like to analyze > the data using python -- currently using ethereal and wireshark. > > I would like to get certain type of packets (I can get the hex code > for them), what is the best way to do this? Lets say I want to capture > all events of `ping localhost` http://www.google.com/search?q=python+pcap -- Grant Edwards grante Yow! My face is new, my at license is expired, and I'm visi.com under a doctor's care!!!! From steve at REMOVE-THIS-cybersource.com.au Mon Feb 1 10:27:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 01 Feb 2010 15:27:31 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> Message-ID: <0376df33$0$1309$c3e8da3@news.astraweb.com> On Mon, 01 Feb 2010 11:14:42 +0100, Daniel Fetchinson wrote: > I also think the PEP is a great idea and proposes a solution to a real > problem. But I also hear the 'directory clutter' argument and I'm really > concerned too, having all these extra directories around (and quite a > large number of them indeed!). Keep in mind that if you don't explicitly ask for the proposed feature, you won't see any change at all. You need to run Python with the -R switch, or set an environment variable. The average developer won't see any clutter at all unless she is explicitly supporting multiple versions. > How about this scheme: > > 1. install python source files to a shared (among python installations) > location /this/is/shared > 2. when python X.Y imports a source file from /this/is/shared it will > create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ $ touch /usr/lib/python2.5/site-packages/STEVEN touch: cannot touch `/usr/lib/python2.5/site-packages/STEVEN': Permission denied There's your first problem: most users don't have write-access to the private area. When you install a package, you normally do so as root, and it all works. When you import a module and it gets compiled as a .pyc file, you're generally running as a regular user. > Time comparison would be between /this/is/shared/x.py and > /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. I don't quite understand what you mean by "time comparison". [...] > In /usr/lib/pythonX.Y/site-packages there would be only pyc files with > magic number matching python X.Y. Personally, I think it is a terribly idea to keep the source file and byte code file in such radically different places. They should be kept together. What you call "clutter" I call having the files that belong together kept together. > So, basically nothing would change only the location of py and pyc files > would be different from current behavior, but the same algorithm would > be run to determine which one to load, when to create a pyc file, when > to ignore the old one, etc. What happens when there is a .pyc file in the same location as the .py file? Because it *will* happen. Does it get ignored, or does it take precedence over the site specific file? Given: ./module.pyc /usr/lib/pythonX.Y/site-packages/module.pyc and you execute "import module", which gets used? Note that in this situation, there may or may not be a module.py file. > What would be wrong with this setup? Consider: ./module.py ./package/module.py Under your suggestion, both of these will compile to /usr/lib/pythonX.Y/site-packages/module.pyc -- Steven From robert.kern at gmail.com Mon Feb 1 10:30:50 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 01 Feb 2010 09:30:50 -0600 Subject: Unable to install numpy In-Reply-To: References: <3a772f49-aee6-4450-b60e-8f05daec136a@21g2000yqj.googlegroups.com> Message-ID: On 2010-01-31 08:03 AM, vsoler wrote: > On Jan 18, 9:08 pm, Robert Kern wrote: >> On 2010-01-18 14:02 PM, vsoler wrote: >> >>> Hi all, >> >>> I just download Numpy, and tried to install it using "numpy-1.4.0- >>> win32-superpack-python2.6.exe" >> >>> I get an error: "Python version 2.6 required, which was not found in >>> the Registry" >> >>> However, I am using Python 2.6 every day. I'm running Windows 7. >> >>> What can I do? >> >> Please ask numpy installation questions on the numpy mailing list. >> >> http://www.scipy.org/Mailing_Lists > > Thank you Robert. > > I'm going to direct my questions towards scipy.org. However, since I > do not find my questions already answered, could you tell me where to > post it? > > I beg your pardon for still asking this question outside of scipy.org, > but I've been unable to move on. Subscribe to the numpy-discussion mailing list following the directions given on the above-linked page. Then send email to numpy-discussion at scipy.org with your question. -- 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 Mon Feb 1 10:46:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Feb 2010 15:46:52 +0000 Subject: how long a Str can be used in this python code segment? In-Reply-To: <50697b2c1002010126n7602495dlbf9cfc90755c8825@mail.gmail.com> References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> <50697b2c1002010126n7602495dlbf9cfc90755c8825@mail.gmail.com> Message-ID: <4B66F76C.5040507@mrabarnett.plus.com> Chris Rebert wrote: > On Mon, Feb 1, 2010 at 1:17 AM, Stephen.Wu <54wutong at gmail.com> wrote: >> tmp=file.read() (very huge file) >> if targetStr in tmp: >> print "find it" >> else: >> print "not find" >> file.close() >> >> I checked if file.read() is huge to some extend, it doesn't work, but >> could any give me some certain information on this prolbem? > > If the file's contents is larger than available memory, you'll get a > MemoryError. To avoid this, you can read the file in by chunks (or if > applicable, by lines) and see if each chunk/line matches. > If you're processing in chunks then you also need to consider the possibility that what you're looking for crosses a chunk boundary, of course. It's an easy case to miss! :-) From sdeibel at wingware.com Mon Feb 1 11:16:28 2010 From: sdeibel at wingware.com (Stephan Deibel) Date: Mon, 01 Feb 2010 11:16:28 -0500 Subject: ANN: Wing IDE 3.2.4 released Message-ID: <4B66FE5C.4010801@wingware.com> Hi, Wingware has released version 3.2.4 of Wing IDE, our integrated development environment for the Python programming language. Wing IDE can be used on Windows, Linux, and OS X to develop Python code for web, GUI, and embedded scripting applications. Wing IDE provides auto-completion, call tips, a powerful debugger, unit testing, version control, search, and many other features. This release includes the following minor features and improvements: * Corrected support for non-ascii I/O when debugging under Python 3.x * Support debugging of wide unicode builds of Python 3.x * Improve GUI responsiveness in very large projects (optimized external file change checking) * Auto-enter last failed or canceled version control commit message * Added context menu for copy/paste to commit message area in version control tools * Version control annotate commands like 'svn blame' show results in scratch buffer * Many other minor features and bug fixes; See the change log at http://wingware.com/pub/wingide/3.2.4/CHANGELOG.txt for details *Wing 3.2 Highlights* Version 3.2 of Wing IDE includes the following new features not present in Wing IDE 3.1: * Support for Python 3.0 and 3.1 * Rewritten version control integration with support for Subversion, CVS, Bazaar, git, Mercurial, and Perforce (*) * Added 64-bit Debian, RPM, and tar file installers for Linux * File management in Project view (**) * Auto-completion in the editor obtains completion data from live runtime when the debugger is active (**) * Perspectives: Create and save named GUI layouts and optionally automatically transition when debugging is started (*) * Improved support for Cython and Pyrex (*.pyx files) * Added key binding documentation to the manual * Added Restart Debugging item in Debug menu and tool bar (**) * Improved OS Commands and Bookmarks tools (*) (*)'d items are available in Wing IDE Professional only. (**)'d items are available in Wing IDE Personal and Professional only. The release also contains many other minor features and bug fixes; see the change log for details: http://wingware.com/pub/wingide/3.2.4/CHANGELOG.txt *Downloads* Wing IDE Professional and Wing IDE Personal are commercial software and require a license to run. A free trial license can be obtained directly from the product when launched. Wing IDE 101 can be used free of charge. Wing IDE Pro 3.2.4 http://wingware.com/downloads/wingide/3.2 Wing IDE Personal 3.2.4 http://wingware.com/downloads/wingide-personal/3.2 Wing IDE 101 3.2.4 http://wingware.com/downloads/wingide-101/3.2 *About Wing IDE* Wing IDE is an integrated development environment for the Python programming language. It provides powerful debugging, editing, code intelligence, testing, version control, and search capabilities that reduce development and debugging time, cut down on coding errors, and make it easier to understand and navigate Python code. Wing IDE is available in three product levels: Wing IDE Professional is the full-featured Python IDE, Wing IDE Personal offers a reduced feature set at a low price, and Wing IDE 101 is a free simplified version designed for teaching entry level programming courses with Python. System requirements are Windows 2000 or later, OS X 10.3.9 or later for PPC or Intel (requires X11 Server), or a recent Linux system (either 32 or 64 bit). Wing IDE 3.2 supports Python versions 2.0.x through 3.1.x. *Purchasing and Upgrading* Wing 3.2 is a free upgrade for all Wing IDE 3.0 and 3.1 users. Any 2.x license sold after May 2nd 2006 is free to upgrade; others cost 1/2 the normal price to upgrade. Upgrade a 2.x license: https://wingware.com/store/upgrade Purchase a 3.x license: https://wingware.com/store/purchase -- The Wingware Team Wingware | Python IDE Advancing Software Development www.wingware.com From andrej.mitrovich at gmail.com Mon Feb 1 11:31:34 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 08:31:34 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> Message-ID: On Feb 1, 4:03?am, Andrej Mitrovic wrote: > On Feb 1, 2:59?am, Andrej Mitrovic wrote: > > > > > Hi, > > > I've made a similar post on the Cython mailing list, however I think > > this is more python-specific. I'm having trouble setting up distutils > > to use MinGW instead of Visual Studio when building a module. Even tho > > I've just uninstalled VS, and cleared out any leftover VS environment > > variables, distutils keeps wanting to use it. > > > The steps I took: > > > Fresh installation of Python 3.1.1 > > Successfully installed MinGW, added to the path variable (gcc in > > command prompt works) > > Successfully installed Cython, imports from Cython in Python work. > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with: > > > [build] > > compiler=mingw32 > > > (also tried adding [build_ext] compiler=mingw32) > > > There's a demo setup.py module that came with Cython, I tried the > > following commands: > > > ---------------------------------------------------- > > > > python setup.py build_ext --inplace > > > error: Unable to find vcvarsall.bat > > > > python setup.py build > > > error: Unable to find vcvarsall.bat > > ---------------------------------------------------- > > > I'm having the exact same issue with trying to build the Polygon > > library via MinGW. In fact, the reason I had installed Visual Studio > > in the first place was to be able to build the Polygon library, since > > I was having these errors. > > > What do I need to do to make distutils/python use MinGW? > > Update: > > I installed and tried building with Python 2.6, it calls MinGW when I > have the distutils.cfg file configured properly (same configuration as > the Python 3.1.1 one) > > But why doesn't it work on a fresh Python 3.1.1 installation as well? > Is this a bug? Also tried calling (Python 3.1.1): ---------------------------------------------------- python setup.py build --compiler=mingw32 error: Unable to find vcvarsall.bat ---------------------------------------------------- I've tried using pexports and the dlltool to build new python31.def and libpython31.a files, and put them in the libs folder. That didn't work either. I've also tried adding some print statements in the \distutils\dist.py file, in the parse_config_files() function, just to see if Python properly parses the config file. And it does, both Python 2.6 and 3.1 parse the distutils.cfg file properly. Yet something is making python 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on any progres.. From casevh at gmail.com Mon Feb 1 11:44:46 2010 From: casevh at gmail.com (casevh) Date: Mon, 1 Feb 2010 08:44:46 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> Message-ID: <12c34cd1-7740-4257-9bb6-bdfb55b44b27@2g2000prl.googlegroups.com> On Feb 1, 8:31?am, Andrej Mitrovic wrote: > On Feb 1, 4:03?am, Andrej Mitrovic wrote: > > > > > > > On Feb 1, 2:59?am, Andrej Mitrovic wrote: > > > > Hi, > > > > I've made a similar post on the Cython mailing list, however I think > > > this is more python-specific. I'm having trouble setting up distutils > > > to use MinGW instead of Visual Studio when building a module. Even tho > > > I've just uninstalled VS, and cleared out any leftover VS environment > > > variables, distutils keeps wanting to use it. > > > > The steps I took: > > > > Fresh installation of Python 3.1.1 > > > Successfully installed MinGW, added to the path variable (gcc in > > > command prompt works) > > > Successfully installed Cython, imports from Cython in Python work. > > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with: > > > > [build] > > > compiler=mingw32 > > > > (also tried adding [build_ext] compiler=mingw32) > > > > There's a demo setup.py module that came with Cython, I tried the > > > following commands: > > > > ---------------------------------------------------- > > > > > python setup.py build_ext --inplace > > > > error: Unable to find vcvarsall.bat > > > > > python setup.py build > > > > error: Unable to find vcvarsall.bat > > > ---------------------------------------------------- > > > > I'm having the exact same issue with trying to build the Polygon > > > library via MinGW. In fact, the reason I had installed Visual Studio > > > in the first place was to be able to build the Polygon library, since > > > I was having these errors. > > > > What do I need to do to make distutils/python use MinGW? > > > Update: > > > I installed and tried building with Python 2.6, it calls MinGW when I > > have the distutils.cfg file configured properly (same configuration as > > the Python 3.1.1 one) > > > But why doesn't it work on a fresh Python 3.1.1 installation as well? > > Is this a bug? > > Also tried calling (Python 3.1.1): > > ---------------------------------------------------- > python setup.py build --compiler=mingw32 > > error: Unable to find vcvarsall.bat > ---------------------------------------------------- > > I've tried using pexports and the dlltool to build new python31.def > and libpython31.a files, and put them in the libs folder. That didn't > work either. > > I've also tried adding some print statements in the \distutils\dist.py > file, in the parse_config_files() function, just to see if Python > properly parses the config file. And it does, both Python 2.6 and 3.1 > parse the distutils.cfg file properly. Yet something is making python > 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on > any progres..- Hide quoted text - > > - Show quoted text - I think this is http://bugs.python.org/issue6377. I applied the patch to my local copy of Python 3.1 and it seems to work. casevh From gerald.britton at gmail.com Mon Feb 1 11:50:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Mon, 1 Feb 2010 11:50:36 -0500 Subject: Iterating over a function call Message-ID: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Hi -- I have many sections of code like this: for value in value_iterator: value_function(value) I noticed that this does two things I don't like: 1. looks up "value_function" and "value" for each iteration, but "value_function" doesn't change. 2. side effect of (maybe) leaking the iterator variable "value" into the code following the loop (if the iterator is not empty). I can take care of 2 by explicitly deleting the variable at the end: del value but I'd probably forget to do that sometimes. I then realized that, in the 2.x series, I can accomplish the same thing with: map(value_function, value_iterator) and avoid both problems BUT map() returns a list which is never used. Not a big deal for small iterables, I guess, but it seems messy. Upon conversion to 3.x I have to explicitly list-ify it: list(map(value_function, value_iterator)) which works but again the list returned is never used (extra work) and has to be gc'd I suppose (extra memory). It's easy to make a little function to take care of this (2.x): from itertools import imap def apply(function, iterable): for item in imap(function, iterable): pass then later: apply(value_function, value_iterator) or something similar thing in 3.x, but that just adds an additional function def that I have to include whenever I want to do something like this. So.....I'm wondering if there is any interest in an apply() built-in function that would work like map() does in 2.x (calls the function with each value returned by the iterator) but return nothing. Maybe "apply" isn't the best name; it's just the first one that occurred to me. Or is this just silly and should I forget about it? -- Gerald Britton From solipsis at pitrou.net Mon Feb 1 11:53:01 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 1 Feb 2010 16:53:01 +0000 (UTC) Subject: how long a Str can be used in this python code segment? References: <6d7a9ae4-c15e-4e17-8123-2fbf07f0d3a2@a17g2000pre.googlegroups.com> Message-ID: Le Mon, 01 Feb 2010 01:33:09 -0800, Stephen.Wu a ?crit?: > > actually, I just use file.read(length) way, i just want to know what > exactly para of length I should set, I'm afraid length doesn't equal to > the amount of physical memory after trials... There's no exact length you "should" set, just set something big enough that looping doesn't add any noticeable overhead, but small enough that it doesn't take too much memory. Something between 64kB and 1MB sounds reasonable. From andrej.mitrovich at gmail.com Mon Feb 1 11:53:41 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 08:53:41 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> Message-ID: <054ae97c-f8e9-4090-a7e0-cf6a55c2cf5d@a32g2000yqm.googlegroups.com> I've found the problem: For the windows Python 3.1.1 x86 installation, the file \Python31\Lib \Distutils\command\build_ext.py, has this: Line 313: self.compiler = new_compiler(compiler=None, But Python 2.6 has this line: Line 306: self.compiler = new_compiler(compiler=self.compiler, I've changed the Python 3.1.1 \Python31\Lib\Distutils\command \build_ext.py, Line 313 to this: self.compiler = new_compiler(compiler=self.compiler, And now MinGW gets properly called in Python 3.1.1. I think this must have been a typo. Is there anyone else that can confirm this? The installation that distributes the file with that line is from this Python ftp link: http://python.org/ftp/python/3.1.1/python-3.1.1.msi From affdfsdfdsfsd at b.com Mon Feb 1 12:00:19 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 01 Feb 2010 17:00:19 GMT Subject: create a string of variable lenght References: <4b65729b$0$1126$4fafbaef@reader3.news.tin.it> <4b660056$0$1131$4fafbaef@reader3.news.tin.it> Message-ID: <4b6708a3$0$1132$4fafbaef@reader1.news.tin.it> Il Sun, 31 Jan 2010 19:54:17 -0500, Benjamin Kaplan ha scritto: > First of all, if you haven't read this before, please do. It will make > this much clearer. > http://www.joelonsoftware.com/articles/Unicode.html i'm reading it right now, thanks :-) [cut] > Solution to your problem: in addition to keeping the #-*- coding ... > line, go with G?nther's advice and use Unicode strings. that is: always use the "u" operator (i.e. my_name = u"Nico"), right? Ciao, Nico From andrej.mitrovich at gmail.com Mon Feb 1 12:03:10 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 09:03:10 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> <12c34cd1-7740-4257-9bb6-bdfb55b44b27@2g2000prl.googlegroups.com> Message-ID: On Feb 1, 5:44?pm, casevh wrote: > On Feb 1, 8:31?am, Andrej Mitrovic wrote: > > > > > On Feb 1, 4:03?am, Andrej Mitrovic wrote: > > > > On Feb 1, 2:59?am, Andrej Mitrovic wrote: > > > > > Hi, > > > > > I've made a similar post on the Cython mailing list, however I think > > > > this is more python-specific. I'm having trouble setting up distutils > > > > to use MinGW instead of Visual Studio when building a module. Even tho > > > > I've just uninstalled VS, and cleared out any leftover VS environment > > > > variables, distutils keeps wanting to use it. > > > > > The steps I took: > > > > > Fresh installation of Python 3.1.1 > > > > Successfully installed MinGW, added to the path variable (gcc in > > > > command prompt works) > > > > Successfully installed Cython, imports from Cython in Python work. > > > > Added a distutils.cfg file in \Python31\Lib\distutils\ directory with: > > > > > [build] > > > > compiler=mingw32 > > > > > (also tried adding [build_ext] compiler=mingw32) > > > > > There's a demo setup.py module that came with Cython, I tried the > > > > following commands: > > > > > ---------------------------------------------------- > > > > > > python setup.py build_ext --inplace > > > > > error: Unable to find vcvarsall.bat > > > > > > python setup.py build > > > > > error: Unable to find vcvarsall.bat > > > > ---------------------------------------------------- > > > > > I'm having the exact same issue with trying to build the Polygon > > > > library via MinGW. In fact, the reason I had installed Visual Studio > > > > in the first place was to be able to build the Polygon library, since > > > > I was having these errors. > > > > > What do I need to do to make distutils/python use MinGW? > > > > Update: > > > > I installed and tried building with Python 2.6, it calls MinGW when I > > > have the distutils.cfg file configured properly (same configuration as > > > the Python 3.1.1 one) > > > > But why doesn't it work on a fresh Python 3.1.1 installation as well? > > > Is this a bug? > > > Also tried calling (Python 3.1.1): > > > ---------------------------------------------------- > > python setup.py build --compiler=mingw32 > > > error: Unable to find vcvarsall.bat > > ---------------------------------------------------- > > > I've tried using pexports and the dlltool to build new python31.def > > and libpython31.a files, and put them in the libs folder. That didn't > > work either. > > > I've also tried adding some print statements in the \distutils\dist.py > > file, in the parse_config_files() function, just to see if Python > > properly parses the config file. And it does, both Python 2.6 and 3.1 > > parse the distutils.cfg file properly. Yet something is making python > > 3 look for the VS/VC compiler instead of MinGW. I'll keep updating on > > any progres..- Hide quoted text - > > > - Show quoted text - > > I think this ishttp://bugs.python.org/issue6377. > > I applied the patch to my local copy of Python 3.1 and it seems to > work. > > casevh Thanks for the link, it seems like it's got more to do than what I just posted. But in any case, it works for me now. I think I'll have to open myself a blog and post some guides for problems like these, so people can avoid spending whole nights around a problem like this. :) From andrej.mitrovich at gmail.com Mon Feb 1 12:03:20 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 1 Feb 2010 09:03:20 -0800 (PST) Subject: Python distutils build problems with MinGW References: <67168350-0f64-454c-a89b-767cba82e439@f12g2000yqn.googlegroups.com> <054ae97c-f8e9-4090-a7e0-cf6a55c2cf5d@a32g2000yqm.googlegroups.com> Message-ID: <0a26893d-45b2-42c6-ae5f-3a59410b790f@o28g2000yqh.googlegroups.com> Well, in any case this seems to be working ok for me now. From no-spam at non-existing.invalid Mon Feb 1 12:16:20 2010 From: no-spam at non-existing.invalid (Robert) Date: Mon, 01 Feb 2010 18:16:20 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Message-ID: Stefan Behnel wrote: > Robert, 01.02.2010 14:36: >> Stefan Behnel wrote: >>> Robert, 31.01.2010 20:57: >>>> I tried lxml, but after walking and making changes in the element tree, >>>> I'm forced to do a full serialization of the whole document >>>> (etree.tostring(tree)) - which destroys the "human edited" format of the >>>> original HTML code. makes it rather unreadable. >>> What do you mean? Could you give an example? lxml certainly does not >>> destroy anything it parsed, unless you tell it to do so. >> of course it does not destroy during parsing.(?) > > I meant "parsed" in the sense of "has parsed and is now working on". > > >> I mean: I want to walk with a Python script through the parsed tree HTML >> and modify here and there things (auto alt tags from DB/similar, link >> corrections, text sections/translated sentences... due to HTML code and >> content checks.) > > Sure, perfectly valid use case. > > >> Then I want to output the changed tree - but as close to the original >> format as far as possible. No changes to my white space identation, >> etc.. Only lokal changes, where really tags where changed. > > That's up to you. If you only apply local changes that do not change any > surrounding whitespace, you'll be fine. > > >> Thats similiar like that what a good HTML editor does: After you made >> little changes, it doesn't reformat/re-spit-out your whole code layout >> from tree/attribute logic only. you have lokal changes only. > > HTML editors don't work that way. They always "re-spit-out" the whole code > when you click on "save". They certainly don't track the original file > position of tags. What they preserve is the content, including whitespace > (or not, if they reformat the code, but that's usually an *option*). > > >> Such a "good HTML editor" must somehow track the original positions of >> the tags in the file. And during each logical change in the tree it must >> tracks the file position changes/offsets. > > Sorry, but that's nonsense. The file position of a tag is determined by > whitespace, i.e. line endings and indentation. lxml does not alter that, > unless you tell it do do so. > > Since you keep claiming that it *does* alter it, please come up with a > reproducible example that shows a) what you do in your code, b) what your > input is and c) what unexpected output it creates. Do not forget to include > the version number of lxml and libxml2 that you are using, as well as a > comment on /how/ the output differs from what you expected. > > My stab in the dark is that you forgot to copy the tail text of elements > that you replace by new content, and that you didn't properly indent new > content that you added. But that's just that, a stab in the dark. You > didn't provide enough information for even an educated guess. > I think you confused the logical level of what I meant with "file position": Of course its not about (necessarily) writing back to the same open file (OS-level), but regarding the whole serializiation string (wherever it is finally written to - I typically write the auto-converted HTML files to a 2nd test folder first, and want use "diff -u ..." to see human-readable what changed happened - which again is only reasonable if the original layout is preserved as good as possible ) lxml and BeautifulSoup e.g. : load&parse a HTML file to a tree, immediately serialize the tree without changes => you see big differences of original and serialized files with quite any file. The main issue: those libs seem to not track any info about the original string/file positions of the objects they parse. The just forget the past. Thus they cannot by principle do what I want it seems ... Or does anybody see attributes of the tree objects - which I overlooked? Or a lib which can do or at least enable better this source-back-connected editing? Robert From python at mrabarnett.plus.com Mon Feb 1 12:17:31 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 01 Feb 2010 17:17:31 +0000 Subject: how to decode rtf characterset ? In-Reply-To: <4B66B785.1090406@gmail.com> References: <4B66B785.1090406@gmail.com> Message-ID: <4B670CAB.7090303@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > I want to translate rtf files to unicode strings. > I succeeded in remove all the tags, > but now I'm stucked to the special accent characters, > like : > > "V??r" > > the character "?" is represented by the string r"\'f3", > or in bytes: 92, 39,102, 51 > > so I think I need a way to translate that into the string r"\xf3" > but I can't find a way to accomplish that. > > a > Any suggestions are very welcome. > Change r"\'f3" to r"\xf3" and then decode to Unicode: >>> s = r"\'f3" >>> s = s.replace(r"\'", r"\x").decode("unicode_escape") >>> print s ? From kirby.urner at gmail.com Mon Feb 1 12:29:25 2010 From: kirby.urner at gmail.com (kirby urner) Date: Mon, 1 Feb 2010 09:29:25 -0800 Subject: [Edu-sig] odd drawing problem with turtle.py In-Reply-To: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> References: <953804BA-5723-427E-A316-9B16A94BAD17@bryant.edu> Message-ID: On Mon, Feb 1, 2010 at 3:27 AM, Brian Blais wro > > I don't see where you've defined a Turtle class to instantiate sir. > > > Turtle is given in turtle.py. I should have subclassed it, but I was being > lazy. :) > > thanks for the fast replies! > > > > bb > > > No obvious need to subclass. You weren't being lazy, I was being sloppy. I'm glad Vern caught my error right away. Kirby -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.arnold at sas.com Mon Feb 1 12:42:07 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Mon, 1 Feb 2010 12:42:07 -0500 Subject: HTML Parser which allows low-keyed local changes (upon serialization) References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Message-ID: "Robert" wrote in message news:hk729b$naa$1 at news.albasani.net... > Stefan Behnel wrote: >> Robert, 01.02.2010 14:36: >>> Stefan Behnel wrote: >>>> Robert, 31.01.2010 20:57: >>>>> I tried lxml, but after walking and making changes in the element >>>>> tree, >>>>> I'm forced to do a full serialization of the whole document >>>>> (etree.tostring(tree)) - which destroys the "human edited" format of >>>>> the >>>>> original HTML code. makes it rather unreadable. >>>> What do you mean? Could you give an example? lxml certainly does not >>>> destroy anything it parsed, unless you tell it to do so. >>> of course it does not destroy during parsing.(?) >> I think I understand what you want, but I don't understand why yet. Do you want to view the differences in an IDE or something like that? If so, why not pretty-print both and compare that? --Tim From mal at egenix.com Mon Feb 1 13:06:37 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 01 Feb 2010 19:06:37 +0100 Subject: HTML Parser which allows low-keyed local changes (upon serialization) In-Reply-To: References: <4b669215$0$6582$9b4e6d93@newsspool3.arcor-online.net> <4b66dfb3$0$6587$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <4B67182D.3060500@egenix.com> Robert wrote: > I think you confused the logical level of what I meant with "file > position": > Of course its not about (necessarily) writing back to the same open file > (OS-level), but regarding the whole serializiation string (wherever it > is finally written to - I typically write the auto-converted HTML files > to a 2nd test folder first, and want use "diff -u ..." to see > human-readable what changed happened - which again is only reasonable if > the original layout is preserved as good as possible ) > > lxml and BeautifulSoup e.g. : load&parse a HTML file to a tree, > immediately serialize the tree without changes => you see big > differences of original and serialized files with quite any file. > > The main issue: those libs seem to not track any info about the original > string/file positions of the objects they parse. The just forget the > past. Thus they cannot by principle do what I want it seems ... > > Or does anybody see attributes of the tree objects - which I overlooked? > Or a lib which can do or at least enable better this > source-back-connected editing? You'd have to write your own parse (or extend the example HTML one we include), but mxTextTools allows you to work on original code quite easily: it tags parts of the input string with objects. You can then have those objects manipulate the underlying text as necessary and write back the text using the original formatting plus your local changes. http://www.egenix.com/products/python/mxBase/mxTextTools/ -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 01 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/ ________________________________________________________________________ ::: 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 mal at egenix.com Mon Feb 1 13:11:24 2010 From: mal at egenix.com (M.-A. Lemburg) Date: Mon, 01 Feb 2010 19:11:24 +0100 Subject: how to decode rtf characterset ? In-Reply-To: <4B66B785.1090406@gmail.com> References: <4B66B785.1090406@gmail.com> Message-ID: <4B67194C.3030307@egenix.com> Stef Mientki wrote: > hello, > > I want to translate rtf files to unicode strings. > I succeeded in remove all the tags, > but now I'm stucked to the special accent characters, > like : > > "V??r" > > the character "?" is represented by the string r"\'f3", > or in bytes: 92, 39,102, 51 > so I think I need a way to translate that into the string r"\xf3" > but I can't find a way to accomplish that. > > a > Any suggestions are very welcome. You could try something along these lines: >>> s = r"\'f3" >>> s = s.replace("\\'", "\\x") >>> u = s.decode('unicode-escape') >>> u u'\xf3' However, this assumes Latin-1 codes being using by the RTF text. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 01 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/ ________________________________________________________________________ ::: 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 benjamin.kaplan at case.edu Mon Feb 1 13:56:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 1 Feb 2010 13:56:16 -0500 Subject: create a string of variable lenght In-Reply-To: <4b6708a3$0$1132$4fafbaef@reader1.news.tin.it> References: <4b65729b$0$1126$4fafbaef@reader3.news.tin.it> <4b660056$0$1131$4fafbaef@reader3.news.tin.it> <4b6708a3$0$1132$4fafbaef@reader1.news.tin.it> Message-ID: On Mon, Feb 1, 2010 at 12:00 PM, Tracubik wrote: > Il Sun, 31 Jan 2010 19:54:17 -0500, Benjamin Kaplan ha scritto: > >> First of all, if you haven't read this before, please do. It will make >> this much clearer. >> http://www.joelonsoftware.com/articles/Unicode.html > > i'm reading it right now, thanks :-) > > [cut] > >> Solution to your problem: in addition to keeping the #-*- coding ... >> line, go with G?nther's advice and use Unicode strings. > > that is: always use the "u" operator (i.e. my_name = u"Nico"), right? > > Ciao, > Nico > Short answer: yes. Slightly longer explanation for future reference: This is true for Python 2 but not Python 3. One of the big changes in Python 3 is that strings are Unicode by default because you're not the only one who runs into this problem. So in Python 3, just writing 'Nico' will make a Unicode string and you have to explicitly declare b'Nico' if you want to look at it as a series of bytes. From gagsl-py2 at yahoo.com.ar Mon Feb 1 14:00:38 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 16:00:38 -0300 Subject: Python-list Digest, Vol 77, Issue 7 * References: <4755336292109192622@unknownmsgid> Message-ID: En Mon, 01 Feb 2010 07:26:13 -0300, Rohit Roger$ escribi?: > Help for datetime module > > Source code is : > from datetime import datetime > d = datetime(datetime.now().year, datetime.now().month, > datetime.now().day, 11, 59, 0 ) > print d And your problem is...? This is what I get: py> print d 2010-02-01 11:59:00 -- Gabriel Genellina From deets at nospam.web.de Mon Feb 1 14:52:46 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 01 Feb 2010 20:52:46 +0100 Subject: Iterating over a function call In-Reply-To: References: Message-ID: <7sopofFg53U1@mid.uni-berlin.de> > So.....I'm wondering if there is any interest in an apply() built-in > function that would work like map() does in 2.x (calls the function > with each value returned by the iterator) but return nothing. Maybe > "apply" isn't the best name; it's just the first one that occurred to > me. > > Or is this just silly and should I forget about it? IMHO - yes. Looking up names is what python does all the time, trying to microoptimize that away is silly. It is only justfied if you have extremely timing-critical code. And then, all you need to do is to say def whatever(): _function = function for value in values: _function(value) which will reduce lookup-time, as _function is found in locals() rather than globals(). And any function that does something worthy will dwarf the second namespace-lookup I'd say. Diez From arnodel at googlemail.com Mon Feb 1 15:05:55 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 01 Feb 2010 20:05:55 +0000 Subject: Iterating over a function call References: Message-ID: Gerald Britton writes: > Hi -- I have many sections of code like this: > > for value in value_iterator: > value_function(value) > > I noticed that this does two things I don't like: > > 1. looks up "value_function" and "value" for each iteration, but > "value_function" doesn't change. > 2. side effect of (maybe) leaking the iterator variable "value" into > the code following the loop (if the iterator is not empty). > > I can take care of 2 by explicitly deleting the variable at the end: > > del value > > but I'd probably forget to do that sometimes. I then realized that, > in the 2.x series, I can accomplish the same thing with: > > map(value_function, value_iterator) > > and avoid both problems BUT map() returns a list which is never used. > Not a big deal for small iterables, I guess, but it seems messy. Upon > conversion to 3.x I have to explicitly list-ify it: > > list(map(value_function, value_iterator)) > > which works but again the list returned is never used (extra work) and > has to be gc'd I suppose (extra memory). > > It's easy to make a little function to take care of this (2.x): > > from itertools import imap > def apply(function, iterable): > for item in imap(function, iterable): > pass > > then later: > > apply(value_function, value_iterator) > > or something similar thing in 3.x, but that just adds an additional > function def that I have to include whenever I want to do something > like this. > You have itertools.consume which is close to what you want: consume(imap(func, iterable)) # 2.x consume(map(func, iterable)) # 3.x HTH -- Arnaud From rolf.oltmans at gmail.com Mon Feb 1 15:06:09 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 1 Feb 2010 12:06:09 -0800 (PST) Subject: Adding methods from one class to another, dynamically Message-ID: Hello Python gurus, I'm quite new when it comes to Python so I will appreciate any help. Here is what I'm trying to do. I've two classes like below import new import unittest class test(unittest.TestCase): def test_first(self): print 'first test' def test_second(self): print 'second test' def test_third(self): print 'third test' class tee(unittest.TestCase): pass and I want to attach all test methods of 'test'(i.e. test_first(), test_second() and test_third()) class to 'tee' class. So I'm trying to do something like if __name__=="__main__": for name,func in inspect.getmembers(test,inspect.ismethod): if name.find('test_')!= -1: tee.name = new.instancemethod(func,None,tee) after doing above when I run this statement print dirs(tee) I don't see test_first(), test_second() and test_third() attached to class 'tee'. Any ideas, on how can I attach methods of class 'test' to class 'tee' dynamically? Any help is highly appreciated. Many thanks and I look forward to any help. From fetchinson at googlemail.com Mon Feb 1 15:19:52 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 1 Feb 2010 21:19:52 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: <0376df33$0$1309$c3e8da3@news.astraweb.com> References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >> I also think the PEP is a great idea and proposes a solution to a real >> problem. But I also hear the 'directory clutter' argument and I'm really >> concerned too, having all these extra directories around (and quite a >> large number of them indeed!). > > Keep in mind that if you don't explicitly ask for the proposed feature, > you won't see any change at all. You need to run Python with the -R > switch, or set an environment variable. The average developer won't see > any clutter at all unless she is explicitly supporting multiple versions. > > > >> How about this scheme: >> >> 1. install python source files to a shared (among python installations) >> location /this/is/shared >> 2. when python X.Y imports a source file from /this/is/shared it will >> create pyc files in its private area /usr/lib/pythonX.Y/site-packages/ > > $ touch /usr/lib/python2.5/site-packages/STEVEN > touch: cannot touch `/usr/lib/python2.5/site-packages/STEVEN': Permission > denied > > There's your first problem: most users don't have write-access to the > private area. True, I haven't thought about that (I should have though). > When you install a package, you normally do so as root, and > it all works. When you import a module and it gets compiled as a .pyc > file, you're generally running as a regular user. > > >> Time comparison would be between /this/is/shared/x.py and >> /usr/lib/pythonX.Y/site-packages/x.pyc, for instance. > > I don't quite understand what you mean by "time comparison". I meant the comparison of timestamps on .py and .pyc files in order to determine which is newer and if a recompilation should take place or not. > [...] >> In /usr/lib/pythonX.Y/site-packages there would be only pyc files with >> magic number matching python X.Y. > > Personally, I think it is a terribly idea to keep the source file and > byte code file in such radically different places. They should be kept > together. What you call "clutter" I call having the files that belong > together kept together. I see why you think so, it's reasonable, however there is compelling argument, I think, for the opposite view: namely to keep things separate. An average developer definitely wants easy access to .py files. However I see no good reason for having access to .pyc files. I for one have never inspected a .pyc file. Why would you want to have a .pyc file at hand? If we don't really want to have .pyc files in convenient locations because we (almost) never want to access them really, then I'd say it's a good idea to keep them totally separate and so make don't get in the way. >> So, basically nothing would change only the location of py and pyc files >> would be different from current behavior, but the same algorithm would >> be run to determine which one to load, when to create a pyc file, when >> to ignore the old one, etc. > > What happens when there is a .pyc file in the same location as the .py > file? Because it *will* happen. Does it get ignored, or does it take > precedence over the site specific file? > > Given: > > ./module.pyc > /usr/lib/pythonX.Y/site-packages/module.pyc > > and you execute "import module", which gets used? Note that in this > situation, there may or may not be a module.py file. > > >> What would be wrong with this setup? > > Consider: > > ./module.py > ./package/module.py > > Under your suggestion, both of these will compile to > > /usr/lib/pythonX.Y/site-packages/module.pyc I see the problems with my suggestion. However it would be great if in some other way the .pyc files could be kept out of the way. Granted, I don't have a good proposal for this. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From clp2 at rebertia.com Mon Feb 1 15:25:49 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 12:25:49 -0800 Subject: Adding methods from one class to another, dynamically In-Reply-To: References: Message-ID: <50697b2c1002011225l6155069alb2d90f6d771a70df@mail.gmail.com> On Mon, Feb 1, 2010 at 12:06 PM, Oltmans wrote: > Hello Python gurus, > > I'm quite new when it comes to Python so I will appreciate any help. > Here is what I'm trying to do. I've two classes like below > > import new > import unittest > > class test(unittest.TestCase): > ? ?def test_first(self): > ? ? ? ?print 'first test' > ? ?def test_second(self): > ? ? ? ?print 'second test' > ? ?def test_third(self): > ? ? ? ?print 'third test' > > class tee(unittest.TestCase): > ? ?pass > > and I want to attach all test methods of 'test'(i.e. test_first(), > test_second() and test_third()) class to 'tee' class. So I'm trying to > do something like > > if __name__=="__main__": > ? ?for name,func in inspect.getmembers(test,inspect.ismethod): > ? ? ? ?if name.find('test_')!= -1: > ? ? ? ? ? ?tee.name = new.instancemethod(func,None,tee) This ends up repeatedly assigning to the attribute "name" of tee; if you check dir(tee), you'll see the string "name" as an entry. It does *not* assign to the attribute named by the string in the variable `name`. You want setattr(): http://docs.python.org/library/functions.html#setattr Assuming the rest of your code chunk is correct: setattr(tee, name, new.instancemethod(func,None,tee)) Cheers, Chris -- http://blog.rebertia.com From gerald.britton at gmail.com Mon Feb 1 15:44:18 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Mon, 1 Feb 2010 15:44:18 -0500 Subject: Iterating over a function call In-Reply-To: References: Message-ID: <5d1a32001002011244n21b6f6a8g27051d2cbaa14ecf@mail.gmail.com> [snip[ > You have itertools.consume which is close to what you want: > > ? ?consume(imap(func, iterable)) # 2.x > > ? ?consume(map(func, iterable)) # 3.x > > HTH It does! Though in my case this is simpler: deque(imap(func, iterable), 0) since the recipe for consume just calls deque anyway when you want to eat up the rest of the iterable. It also solves the iterator-variable leakage problem and is only a wee bit slower than a conventional for-loop. > > -- > Arnaud > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From pavlovevidence at gmail.com Mon Feb 1 15:45:03 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Feb 2010 12:45:03 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: Message-ID: <95aceacf-4282-4ddb-b7a2-d9a71d3f8d00@o28g2000yqh.googlegroups.com> On Feb 1, 12:06?pm, Oltmans wrote: > Hello Python gurus, > > I'm quite new when it comes to Python so I will appreciate any help. > Here is what I'm trying to do. I've two classes like below > > import new > import unittest > > class test(unittest.TestCase): > ? ? def test_first(self): > ? ? ? ? print 'first test' > ? ? def test_second(self): > ? ? ? ? print 'second test' > ? ? def test_third(self): > ? ? ? ? print 'third test' > > class tee(unittest.TestCase): > ? ? pass > > and I want to attach all test methods of 'test'(i.e. test_first(), > test_second() and test_third()) class to 'tee' class. Simplest way: class tee(test): pass To do it dynamically the following might work: class tee(unittest.TestCase): pass tee.__bases__ = (test,) tee.__bases__ = (test2,) # dynamically reassign base > So I'm trying to > do something like > > if __name__=="__main__": > ? ? for name,func in inspect.getmembers(test,inspect.ismethod): > ? ? ? ? if name.find('test_')!= -1: > ? ? ? ? ? ? tee.name = new.instancemethod(func,None,tee) > > after doing above when I run this statement > print dirs(tee) > I don't see test_first(), test_second() and test_third() attached to > class 'tee'. Any ideas, on how can I attach methods of class 'test' to > class 'tee' dynamically? Any help is highly appreciated. If you want to do it this way--and I recommend regular inheritance if you can--this is how: for x in dir(test): # or inspect.getmembers if x.startswith('test_'): method = getattr(test,x) function = method.im_func setattr(tee,x,function) The business with method.im_func is because in Python 2.x the getattr on a class will actually returns an unbound method, so you have to get at the actual function object with im_func. In Python 3 this is not necessary. Carl Banks From gerald.britton at gmail.com Mon Feb 1 15:50:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Mon, 1 Feb 2010 15:50:36 -0500 Subject: Adding methods from one class to another, dynamically In-Reply-To: <50697b2c1002011225l6155069alb2d90f6d771a70df@mail.gmail.com> References: <50697b2c1002011225l6155069alb2d90f6d771a70df@mail.gmail.com> Message-ID: <5d1a32001002011250q705f881aid1c7f3246ebb217a@mail.gmail.com> Or you could just do a mixin: tee.__class__.__bases__ = (test,) + tee.__class__.__bases__ On Mon, Feb 1, 2010 at 3:25 PM, Chris Rebert wrote: > On Mon, Feb 1, 2010 at 12:06 PM, Oltmans wrote: >> Hello Python gurus, >> >> I'm quite new when it comes to Python so I will appreciate any help. >> Here is what I'm trying to do. I've two classes like below >> >> import new >> import unittest >> >> class test(unittest.TestCase): >> ? ?def test_first(self): >> ? ? ? ?print 'first test' >> ? ?def test_second(self): >> ? ? ? ?print 'second test' >> ? ?def test_third(self): >> ? ? ? ?print 'third test' >> >> class tee(unittest.TestCase): >> ? ?pass >> >> and I want to attach all test methods of 'test'(i.e. test_first(), >> test_second() and test_third()) class to 'tee' class. So I'm trying to >> do something like >> >> if __name__=="__main__": >> ? ?for name,func in inspect.getmembers(test,inspect.ismethod): >> ? ? ? ?if name.find('test_')!= -1: >> ? ? ? ? ? ?tee.name = new.instancemethod(func,None,tee) > > This ends up repeatedly assigning to the attribute "name" of tee; if > you check dir(tee), you'll see the string "name" as an entry. It does > *not* assign to the attribute named by the string in the variable > `name`. > You want setattr(): http://docs.python.org/library/functions.html#setattr > Assuming the rest of your code chunk is correct: > > setattr(tee, name, new.instancemethod(func,None,tee)) > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From nad at acm.org Mon Feb 1 15:55:17 2010 From: nad at acm.org (Ned Deily) Date: Mon, 01 Feb 2010 12:55:17 -0800 Subject: get error install MySQLdb on Mac OS X References: <30c0946e-fa6a-4a54-930c-1962d167fffe@x10g2000prk.googlegroups.com> <2be17362-8a54-4a04-9671-0a0ff7266e33@k2g2000pro.googlegroups.com> Message-ID: In article <2be17362-8a54-4a04-9671-0a0ff7266e33 at k2g2000pro.googlegroups.com>, "PS.OHM" wrote: > On Jan 29, 5:02?am, Sean DiZazzo wrote: > > On Jan 28, 12:53?pm, "PS.OHM" wrote: > > > I havegetsomeerrorwhen i install MySQLdb on Mac OS X > > > > > after i key command $python setup.py build The build of MySQLdb is not finding the MySQL client database libraries. You need to install them first and, for the python you are using, you need a version that includes 32-bit. The easiest options are to download them from mysql.com or, if you are comfortable with MacPorts, I would recommend installing them from there. sudo port install mysql5 In fact, with MacPorts you can install a complete Python 2.6.4, MySQLdb, and MySQL libraries with just one command. With the MacPorts base installed, this should do it: sudo port install py26-mysql You might need to tweak the variants of some of the packages if you want 32-bit only, etc, depending on what version of OS X you're running on. -- Ned Deily, nad at acm.org From rolf.oltmans at gmail.com Mon Feb 1 15:55:38 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 1 Feb 2010 12:55:38 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: Message-ID: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Thank you for your help, Chris. Looks like I can now attach methods to class 'tee'. However, after attaching methods to 'tee' when I try to run them using suite.run() I don't see any of the methods running, I'm sorry but I've no clue what's failing this. Any insights will be highly appreciated. Here is the sample code filename: check.py --- import inspect import unittest class result(unittest.TestResult): def addSuccess(self,test): print str(test) + ' succeeded' def addError(self,test,err): print 'An error occured while running the test ' + str(test) + ' and error is = ' + str(err) def addFailure(self,test,err): print str(test) + " failed with an error =" + str(err) class test(unittest.TestCase): def test_first(self): print 'first test' def test_second(self): print 'second test' def test_third(self): print 'third test' import new class tee(unittest.TestCase): pass if __name__=="__main__": r = result() for name,func in inspect.getmembers(test,inspect.ismethod): if name.find('test_')!= -1: setattr(tee, name, new.instancemethod(func,None,tee)) suite = unittest.defaultTestLoader.loadTestsFromName('check.tee') suite.run(r) --- Then line suite.run(r) should have run the methods that we just attached, but it's not. I must be missing something here. Please enlighten me. Thanks. On Feb 2, 1:25?am, Chris Rebert wrote: > On Mon, Feb 1, 2010 at 12:06 PM, Oltmans wrote: > > Hello Python gurus, > > > I'm quite new when it comes to Python so I will appreciate any help. > > Here is what I'm trying to do. I've two classes like below > > > import new > > import unittest > > > class test(unittest.TestCase): > > ? ?def test_first(self): > > ? ? ? ?print 'first test' > > ? ?def test_second(self): > > ? ? ? ?print 'second test' > > ? ?def test_third(self): > > ? ? ? ?print 'third test' > > > class tee(unittest.TestCase): > > ? ?pass > > > and I want to attach all test methods of 'test'(i.e. test_first(), > > test_second() and test_third()) class to 'tee' class. So I'm trying to > > do something like > > > if __name__=="__main__": > > ? ?for name,func in inspect.getmembers(test,inspect.ismethod): > > ? ? ? ?if name.find('test_')!= -1: > > ? ? ? ? ? ?tee.name = new.instancemethod(func,None,tee) > > This ends up repeatedly assigning to the attribute "name" of tee; if > you check dir(tee), you'll see the string "name" as an entry. It does > *not* assign to the attribute named by the string in the variable > `name`. > You want setattr():http://docs.python.org/library/functions.html#setattr > Assuming the rest of your code chunk is correct: > > setattr(tee, name, new.instancemethod(func,None,tee)) > > Cheers, > Chris > --http://blog.rebertia.com- Hide quoted text - > > - Show quoted text - From tjreedy at udel.edu Mon Feb 1 15:58:19 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 15:58:19 -0500 Subject: libpcap and python In-Reply-To: <1cbd6f831002010447w4a2ab26dve66206919e99391@mail.gmail.com> References: <1cbd6f831002010447w4a2ab26dve66206919e99391@mail.gmail.com> Message-ID: On 2/1/2010 7:47 AM, Mag Gam wrote: > Hello All, > > I used tcpdump to capture data on my network. I would like to analyze > the data using python -- currently using ethereal and wireshark. > > I would like to get certain type of packets (I can get the hex code > for them), what is the best way to do this? Lets say I want to capture > all events of `ping localhost` The following is pretty straightforward. def process(dump, wanted, func): for packet in dump: if packet_type(packet) == wanted: func(packet) Perhaps you can ask a more specific question. Terry Jan Reedy From steve at holdenweb.com Mon Feb 1 16:14:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 01 Feb 2010 16:14:51 -0500 Subject: Adding methods from one class to another, dynamically In-Reply-To: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Message-ID: Oltmans wrote: > Thank you for your help, Chris. Looks like I can now attach methods to > class 'tee'. However, after attaching methods to 'tee' when I try to > run them using suite.run() I don't see any of the methods running, I'm > sorry but I've no clue what's failing this. Any insights will be > highly appreciated. Here is the sample code > filename: check.py > --- > import inspect > import unittest > > > class result(unittest.TestResult): > > def addSuccess(self,test): > print str(test) + ' succeeded' > def addError(self,test,err): > print 'An error occured while running the test ' + str(test) + > ' and error is = ' + str(err) > def addFailure(self,test,err): > print str(test) + " failed with an error =" + str(err) > > > > class test(unittest.TestCase): > def test_first(self): > print 'first test' > def test_second(self): > print 'second test' > def test_third(self): > print 'third test' > > import new > class tee(unittest.TestCase): > pass > > if __name__=="__main__": > r = result() > for name,func in inspect.getmembers(test,inspect.ismethod): > if name.find('test_')!= -1: > > setattr(tee, name, new.instancemethod(func,None,tee)) > > suite = unittest.defaultTestLoader.loadTestsFromName('check.tee') > suite.run(r) > --- > > Then line suite.run(r) should have run the methods that we just > attached, but it's not. I must be missing something here. Please > enlighten me. > Should not tee be subclassing test, not unittest.TestCase? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From info at feedmagnet.com Mon Feb 1 16:15:05 2010 From: info at feedmagnet.com (Jason) Date: Mon, 1 Feb 2010 13:15:05 -0800 (PST) Subject: CheddarGetter module for Python - easy recurring billing Message-ID: <972aa441-9a27-41ef-9c35-38ad5c141b33@n33g2000yqb.googlegroups.com> We just released pychedder, an open source module for integrating CheddarGetter with Python (and Django): http://www.feedmagnet.com/blog/cheddargetter-for-python-and-django/ Anyone who's built commercial web app knows that payment processing can be one of the toughest pieces to put in place - and it can distract you from working on the core functionality of your app. CheddarGetter is a web service that abstracts the entire process of managing credit cards, processing transactions on a recurring basis, and even more complex setups like free trials, setup fees, and overage charges. We're using CheddarGetter for FeedMagnet.com and we thought the Python community in general could benefit from the module we wrote to interact with it. More just just a Python wrapper for CheddarGetter, pycheddar gives you class objects that work a lot like Django models, making the whole experience of integrating with CheddarGetter just a little more awesome and Pythonic. We're a week or two away from putting pycheddar into production on FeedMagnet, but we felt like it was close enough that others could start using it. We also published it to PyPi so you can easy_install pycheddar and get the latest version (currently 0.9). Hope others can benefit from it! - Jason From aahz at pythoncraft.com Mon Feb 1 16:16:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Feb 2010 13:16:47 -0800 Subject: starting a thread in a nother thread References: <4b604df9$0$6723$9b4e6d93@newsspool2.arcor-online.net> <4b60a661$0$1598$742ec2ed@news.sonic.net> Message-ID: In article <4b60a661$0$1598$742ec2ed at news.sonic.net>, John Nagle wrote: > >If a C package called from Python crashes, the package is defective. >Nothing you can do from Python should be able to cause a segmentation >fault. ...unless you use ctypes. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From gobladoome at gmail.com Mon Feb 1 16:21:56 2010 From: gobladoome at gmail.com (Paul) Date: Tue, 2 Feb 2010 10:21:56 +1300 Subject: Problems embedding python 2.6 in C++ Message-ID: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> Hi, I'm extending some old Visual Studio 6 code to add embedded python scripting. It works fine most of the time but some python function calls do not work as expected. The C++ code is a multithreaded MFC application. I was assuming that it was GIL issues but I have tried using the manual locking (PyEval_SaveThread & PyEval_RestoreThread) and what seems to be the current method (PyGILState_Ensure & PyGILState_Release) Here's the error I'm getting: Traceback (most recent call last): File "...scripts\receipt_parser.py", line 296, in get_giftcard_purchase_value details = extract_transaction_details_section(test) File "...scripts\receipt_parser.py", line 204, in extract_transaction_details_section for line in base_details: TypeError: expected string or Unicode object, NoneType found base_details is a list of strings (I can just define it like 'base_details=["1","2","3"...]' on the line previous) and the code runs fine when run from standard interpreter. Many other function calls work fine from the embedded app. I create and then Py_DECREF the function parameters and the return value after each function call. The module import is created at C++ object constructor and then Py_DECREF'd in the desctuctor Anyone else had issues of this kind? My next try will be to use sub-interpreters per thread. Thanks, Paul. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Feb 1 16:25:41 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 18:25:41 -0300 Subject: Function name unchanged in error message References: Message-ID: En Sat, 30 Jan 2010 06:28:19 -0300, Peter Otten <__peter__ at web.de> escribi?: > Gabriel Genellina wrote: >> En Fri, 29 Jan 2010 13:09:40 -0300, Michele Simionato >> escribi?: >>> On Jan 29, 2:30 pm, andrew cooke wrote: >>>> Is there any way to change the name of the function in an error >>>> message? In the example below I'd like the error to refer to bar(), >>>> for example (the motivation is related function decorators - I'd like >>>> the wrapper function to give the same name) >>> >>> Use the decorator module which does the right thing: >>> http://pypi.python.org/pypi/decorator >> >> The decorator module is a very fine addition to anyone's tool set -- but >> in this case it is enough to use the wraps() function from the functools >> standard module. > > I don't know about the decorator module, but functools.wraps() doesn't > affect the error message: It seems I misunderstood the original request and got it backwards - but then I have to question the usefulness of doing so. If an error happens in the "decorating" function (as opposed to inside the function being decorated) I'd like the error to be reported as such, in the "decorating" function (else tracebacks and line numbers would be lying). -- Gabriel Genellina From jakecjacobson at gmail.com Mon Feb 1 16:46:53 2010 From: jakecjacobson at gmail.com (jakecjacobson) Date: Mon, 1 Feb 2010 13:46:53 -0800 (PST) Subject: Processing XML File References: <6bac2d7b-509d-4f92-912f-5e8dc68c3f30@36g2000yqu.googlegroups.com> <4b6335f3$0$6573$9b4e6d93@newsspool3.arcor-online.net> <4b633a07$0$6582$9b4e6d93@newsspool3.arcor-online.net> Message-ID: On Jan 29, 2:41?pm, Stefan Behnel wrote: > Sells, Fred, 29.01.2010 20:31: > > > Google is your friend. ?Elementtree is one of the better documented > > IMHO, but there are many modules to do this. > > Unless the OP provides some more information, "do this" is rather > underdefined. And sending someone off to Google who is just learning the > basics of Python and XML and trying to solve a very specific problem with > them is not exactly the spirit I'm used to in this newsgroup. > > Stefan Just want to thank everyone for their posts. I got it working after I discovered a name space issue with this code. xmlDoc = libxml2.parseDoc(guts) # Ignore namespace and just get the Resource resourceNodes = xmlDoc.xpathEval('//*[local-name()="Resource"]') for rNode in resourceNodes: print rNode From jgardner at jonathangardner.net Mon Feb 1 17:04:01 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:04:01 -0800 (PST) Subject: For loop searching takes too long! References: <6ea6ebda-43af-4a77-a17e-0930cdd13258@b9g2000pri.googlegroups.com> <03738ee7$0$1309$c3e8da3@news.astraweb.com> Message-ID: <96e06a43-2197-4e93-9837-3c4b461985e0@m27g2000prl.googlegroups.com> On Jan 29, 7:07?pm, Steven D'Aprano wrote: > On Fri, 29 Jan 2010 14:49:06 -0800, Jonathan Gardner wrote: > > On Jan 28, 3:52?pm, elsa wrote: > > >> I've got a problem with my program, in that the code just takes too > >> long to run. Here's what I'm doing. If anyone has any tips, they'd be > >> much appreciated! > > > First of all, don't play with large lists. Large lists have a tendency > > to grow larger over time, until they get absurdly large. > > > If you're dealing with a long list, work with it like you'd work with a > > file. If you need random access, stick it in some form of database, such > > as BDB or PostgreSQL. If you need an index, stick it in some form of DB. > > Eventually, large lists end up like that anyway. Don't fool yourself > > early on---prepare for the worst and solve the problems of tomorrow > > today. > > Talk about premature optimization. The OP probably has a few hundreds of > thousands of items, millions at most, which is trivial on a modern PC. > Your way of thinking is what has led to Firefox using a database to > manage a few thousand bookmarks and cookies, which in turn leads to > consistent data corruption problems. (I've been keeping note, and so far > my installation of Firefox 3 has had database corruption at startup one > time out of five.) > I think there's a difference between writing your code so that you have the option of using a database, or a flat file, or any other type of serial data source, and actually using a database (or whatever.) I prefer to write my code so that I don't have to re-write it 6 months later. Having worked with datasets that are truly enormous, whenever I see a list that is unbounded (as this appears to be), I freak out because unbounded can be a really, really big number. Might as well write software that works for the truly enormous case and the really large case and be done with it once and for all. From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:11:26 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:11:26 -0300 Subject: OT: Instant Messenger Clients References: <4dc0cfea1001311315u3494ad6bk792327d05447c96d@mail.gmail.com> Message-ID: En Sun, 31 Jan 2010 18:15:34 -0300, Victor Subervi escribi?: > I need to record my IM conversations. I'm using Gmal's IM client and I > can't > figure out how to do it, nor do I find any help googling it. Hard to believe... -- Gabriel Genellina From jgardner at jonathangardner.net Mon Feb 1 17:13:38 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:13:38 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: On Jan 30, 8:43?am, Nobody wrote: > On Wed, 27 Jan 2010 15:29:05 -0800, Jonathan Gardner wrote: > > Python is much, much cleaner. I don't know how anyone can honestly say > > Ruby is cleaner than Python. > > I'm not familiar with Ruby, but most languages are cleaner than Python > once you get beyond the "10-minute introduction" stage. > Probably too little, too late (haven't read all of the replies yet...) I judge a language's simplicity by how long it takes to explain the complete language. That is, what minimal set of documentation do you need to describe all of the language? With a handful of statements, and a very short list of operators, Python beats out every language in the Algol family that I know of. I can think of only one language (or rather, a class of languages) that can every hope to be shorter than Python. I doubt you've heard of it based on your comments, but I suggest you look into it. Unfortunately, to fully appreciate that language, you're going to have to study a textbook called "SICP". At the end of that textbook, you are blessed to not only see but understand the complete compiler for the language, in the language itself. From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:27:46 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:27:46 -0300 Subject: whassup? builtins? python3000? Naah can't be right? References: <799ea994-d00f-485c-9164-ed4b66e750a5@k41g2000yqm.googlegroups.com> Message-ID: En Sun, 31 Jan 2010 18:17:04 -0300, _wolf escribi?: > dear pythoneers, > > i would be very gladly accept any commentaries about what this > sentence, gleaned from > http://celabs.com/python-3.1/reference/executionmodel.html, > is meant to mean, or why gods have decided this is the way to go. i > anticipate this guy named Kay Schluehr will have a say on that, or > maybe even the BDFL will care to pronounce ``__builtins__`` the > correct way to his fallovers, followers, and fellownerds:: > > The built-in namespace associated with the execution of > a code block is actually found by looking up the name > __builtins__ in its global namespace; this should be a > dictionary or a module (in the latter case the module?s > dictionary is used). By default, when in the __main__ > module, __builtins__ is the built-in module builtins; > when in any other module, __builtins__ is an alias for > the dictionary of the builtins module itself. > __builtins__ can be set to a user-created dictionary to > create a weak form of restricted execution. Short answer: use `import builtins` (spelled __builtin__, no 's' and double underscores, in Python 2.x) to access the module containing the predefined (built-in) objects. Everything else is an implementation detail. -- Gabriel Genellina From jgardner at jonathangardner.net Mon Feb 1 17:28:28 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:28:28 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> Message-ID: <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> On Jan 31, 3:01?am, rantingrick wrote: > On Jan 30, 10:43?am, Nobody wrote: > > > That's also true for most functional languages, e.g. Haskell and ML, as > > well as e.g. Tcl and most shells. Why require "f(x)" or "(f x)" if "f x" > > will suffice? > > yuck! wrapping the arg list with parenthesis (python way) makes the > most sense. Its to easy to misread somthing like this > > onetwothree four five six > > onetwothree(four, five, six) #ahhh... plain english. In Lisp-ish languages, you have a list of stuff that represents a function call: (a b c d) means: Call "a" with values (b, c, d) While this certainly doesn't agree with what you learned in Algebra, it is a reasonable syntax that exposes the code-data duality of programs. There is, however, one fatal flaw. Why is the first element so different than the rest? This is inconsistent with what people who are unfamiliar with the language would expect. Indeed, in teaching Lisp, learners have to be reminded about how the evaluator looks at lists and processes them. I would expect a clear, simple language to have exactly one way to call a function. This calling notation would clearly distinguish between the function and its parameters. There are quite a few options, and it turns out that "function(arg, arg, arg)" is a really good compromise. One of the bad things with languages like perl and Ruby that call without parentheses is that getting a function ref is not obvious. You need even more syntax to do so. In perl: foo(); # Call 'foo' with no args. $bar = foo; # Call 'foo; with no args, assign to '$bar' $bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' # By the way, this '&' is not the bitwise-and '&'!!!! $bar->() # Call whatever '$bar' is pointing at with no args Compare with python: foo() # Call 'foo' with no args. bar = foo() # 'bar' is now pointing to whatever 'foo()' returned bar = foo # 'bar' is now pointing to the same thing 'foo' points to bar() # Call 'bar' with no args One is simple, consistent, and easy to explain. The other one requires the introduction of advanced syntax and an entirely new syntax to make function calls with references. Note that the Algebra notation of functions allows for an obvious, simple way to refer to functions without calling them, leading to syntax such as "f o g (x)" and more. From astan.chee at al.com.au Mon Feb 1 17:34:38 2010 From: astan.chee at al.com.au (Astan Chee) Date: Tue, 2 Feb 2010 09:34:38 +1100 Subject: converting XML to hash/dict/CustomTreeCtrl Message-ID: <4B6756FE.9060206@al.com.au> Hi, I have xml files that I want to convert to a hash/dict and then further placed in a wx CustomTreeCtrl based on the structure. The problem I am having now is that the XML file is very unusual and there aren't any unique identifiers to be put in a dict and because there are no unique variables, finding the value of it from a CustromTreeCtrl is abit tricky. I would appreciate any help or links to projects similar to this. Thanks The XML file looks something like this: This is the note on calculation times 609.081574 2531.972081 65.119100 1772.011230 72.418861 28.285192 0.000 607.432373 4833280000 4833280000 4182777856 4182777856 1 1943498 0 1640100156 411307840 709596712 1406752 737720720 0 607.432373 5164184694 2054715622 From jgardner at jonathangardner.net Mon Feb 1 17:35:57 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 1 Feb 2010 14:35:57 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> Message-ID: <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> On Jan 31, 12:43?pm, Nobody wrote: > > If it was common-place to use Curried functions and partial application in > Python, you'd probably prefer "f a b c" to "f(a)(b)(c)" as well. > That's just the point. It isn't common to play with curried functions or monads or anything like that in computer science today. Yes, Haskell exists, and is a great experiment in how such a language could actually work. But at the same time, you have to have a brain the size of the titanic to contain all the little details about the language before you could write any large-scale application. Meanwhile, Python's syntax and language is simple and clean, and provides tremendous expressiveness without getting in the way of the programmer. Comparing Python's syntax to Haskell's syntax, Python is simpler. Comparing what Python can do to what Haskell can do, Haskell is much faster at certain tasks and allows the expression of certain things that are difficult to express in Python. But at the end of the day, the difference really doesn't matter that much. Now, compare Python versus Language X along the same lines, and the end result is that (a) Python is extraordinarily more simple than Langauge X, and (b) Python is comparable in expressiveness to Language X. That's the #1 reason why I like Python, and why saying Ruby and Python are similar isn't correct. From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:36:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:36:36 -0300 Subject: ftp.storlines error References: <24ffaab0-f319-4019-97cf-56a7531e3eef@n7g2000yqb.googlegroups.com> Message-ID: En Sun, 31 Jan 2010 19:07:44 -0300, Mik0b0 escribi?: > Good day/night/etc. > I am rather a newb in Python (learning Python 3). I am trying to > create a small script for FTP file uploads on my home network. The > script looks like this: > > from ftplib import FTP > ftp=FTP('10.0.0.1') > ftp.login('mike','*****') > directory='/var/www/blabla/' > ftp.cwd(directory) > ftp.retrlines('LIST') > print('<- - - - - - - - - >') > file_to_change='test' > file=1 > file=open(file_to_change,'w') > text='test' > file.write(text) > ftp.storlines('STOR ' + file_to_change,file) > ftp.retrlines('LIST') > file.close() > > The output is like this: > Traceback (most recent call last): > File "ftp.py", line 13, in > ftp.storlines('STOR ' + file_to_change,i) > File "/usr/lib/python3.1/ftplib.py", line 474, in storlines > buf = fp.readline() > IOError: not readable For the ftp client to be able to read and upload the file, it must have been opened for reading. But you opened it with mode 'w' a few lines above. A quick and dirty way would be to close the file right after file.write(...) and re-open it with mode 'r': ... file.write(text) file.close() file = open(file_to_change,'r') ftp.storlines(...) But I'd separate file-creation from file-uploading. When it's time to upload the file, assume it already exists and has the desired contents (because it has already been created earlier by the same script, or perhaps by some other process), so you just have to open it with mode 'r'. -- Gabriel Genellina From vlastimil.brom at gmail.com Mon Feb 1 17:39:09 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Mon, 1 Feb 2010 22:39:09 +0000 Subject: Iterating over a function call In-Reply-To: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> References: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Message-ID: <9fdb569a1002011439q2db58f2ai42fb9c0c2bc19d23@mail.gmail.com> 2010/2/1 Gerald Britton : > Hi -- I have many sections of code like this: > > ? ?for value in value_iterator: > ? ? ? ? value_function(value) > > I noticed that this does two things I don't like: >... > -- > Gerald Britton > -- > http://mail.python.org/mailman/listinfo/python-list > Hi, just to add to the collection of possible approaches (personally, I find the straightforward versions fine, given the task ... ) If you know, that the called function (used for side effect in any case) doesn't return any "true" value, you could use any(...) over a generator expression or imap (or, inversely, all(...) if there are "true" returns all the time). Not that it improves clarity, but something like a dummy reduce(lambda x, y: None, , None) might (kind of) work for arbitrary returns. Both variants only have a redundant boolean or None value. vbr From cjblaine at gmail.com Mon Feb 1 17:44:09 2010 From: cjblaine at gmail.com (cjblaine) Date: Mon, 1 Feb 2010 14:44:09 -0800 (PST) Subject: Modules failing to add runtime library path info at link time Message-ID: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> Hey everyone, this has been driving me crazy for long enough now that I'm motivated to post and find an answer. Before I pose my question, let me state that using LD_LIBRARY_PATH is not the answer :) We have things installed in odd places, such as very specific versions of libraries to link against, etc. When I build a module (let's say PyGreSQL for instance) via python setup.py build, the link part is including a proper -L argument (-L/ some/weird/lib because /some/weird/bin was in PATH), but is omitting the additional needed runtime linker arguments. For Solaris that's -R/some/weird/lib For Linux that's -Xlinker -rpath -Xlinker /some/weird/lib Where/how can I configure the appropriate portion of our Python install to do 100% the right thing instead of just 50% (-L)? A specific example -- note the -L and lack of -R (Solaris build): % python setup.py build ... gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so % From tjreedy at udel.edu Mon Feb 1 17:56:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 17:56:23 -0500 Subject: Iterating over a function call In-Reply-To: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> References: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Message-ID: On 2/1/2010 11:50 AM, Gerald Britton wrote: > Hi -- I have many sections of code like this: > > for value in value_iterator: > value_function(value) > > I noticed that this does two things I don't like: > > 1. looks up "value_function" and "value" for each iteration, but > "value_function" doesn't change. What you mean by 'looks up'? And why are you bothered by normal Python expression evaluation? Within a function, the 'look_up' is a fast LOAD_FAST instruction. > 2. side effect of (maybe) leaking the iterator variable "value" into > the code following the loop (if the iterator is not empty). So? it is sometime useful. > > I can take care of 2 by explicitly deleting the variable at the end: > > del value > > but I'd probably forget to do that sometimes. So? If having 'value' bound breaks your subsequent code, I consider it buggy. I then realized that, > in the 2.x series, I can accomplish the same thing with: > > map(value_function, value_iterator) > > and avoid both problems BUT map() returns a list which is never used. > Not a big deal for small iterables, I guess, but it seems messy. Upon > conversion to 3.x I have to explicitly list-ify it: > > list(map(value_function, value_iterator)) > > which works but again the list returned is never used (extra work) and > has to be gc'd I suppose (extra memory). > > It's easy to make a little function to take care of this (2.x): > > from itertools import imap > def apply(function, iterable): > for item in imap(function, iterable): > pass collections.deque(imap(function, iterable), maxlen=0) will do nearly the same and may be faster. > then later: > > apply(value_function, value_iterator) > > or something similar thing in 3.x, but that just adds an additional > function def that I have to include whenever I want to do something > like this. > > So.....I'm wondering if there is any interest in an apply() built-in > function that would work like map() does in 2.x (calls the function > with each value returned by the iterator) but return nothing. Maybe > "apply" isn't the best name; it's just the first one that occurred to > me. > > Or is this just silly and should I forget about it? In my opinion, forget about it. Terry Jan Reedy From gagsl-py2 at yahoo.com.ar Mon Feb 1 17:59:32 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 19:59:32 -0300 Subject: Problems embedding python 2.6 in C++ References: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> Message-ID: En Mon, 01 Feb 2010 18:21:56 -0300, Paul escribi?: > I'm extending some old Visual Studio 6 code to add embedded python > scripting. It works fine most of the time but some python function calls > do > not work as expected. > > The C++ code is a multithreaded MFC application. I was assuming that it > was > GIL issues but I have tried using the manual locking (PyEval_SaveThread & > PyEval_RestoreThread) and what seems to be the current method > (PyGILState_Ensure & PyGILState_Release) > > Here's the error I'm getting: > > Traceback (most recent call last): > File "...scripts\receipt_parser.py", line 296, in > get_giftcard_purchase_value > details = extract_transaction_details_section(test) > File "...scripts\receipt_parser.py", line 204, in > extract_transaction_details_section > for line in base_details: > TypeError: expected string or Unicode object, NoneType found > > base_details is a list of strings (I can just define it like > 'base_details=["1","2","3"...]' on the line previous) and the code runs > fine > when run from standard interpreter. Many other function calls work fine > from > the embedded app. > I create and then Py_DECREF the function parameters and the return value > after each function call. The module import is created at C++ object > constructor and then Py_DECREF'd in the desctuctor Usually, errors in reference count handling prevent objects from being destroyed (a memory leak) or generate a GPF when accessing an now-inexistent object. In principle I'd look elsewhere. > Anyone else had issues of this kind? Hard to tell without more info. base_details is built in C++ code? Is it actually a list, or a subclass defined by you? A common error is to forget to check *every* API function call for errors, so errors get unnoticed for a while but are reported on the next check, which may happen in an entirely unrelated function. > My next try will be to use > sub-interpreters per thread. I would not do that - I'd try to *simplify* the code to test, not make it more complicated. Does it work in a single-threaded application? -- Gabriel Genellina From tjreedy at udel.edu Mon Feb 1 18:00:12 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 18:00:12 -0500 Subject: Iterating over a function call In-Reply-To: References: Message-ID: On 2/1/2010 3:05 PM, Arnaud Delobelle wrote: > You have itertools.consume which is close to what you want: > > consume(imap(func, iterable)) # 2.x > > consume(map(func, iterable)) # 3.x Consume is not in itertools. It is one of many recipes in the doc (9.7.2). For exhausting an iterator, collections.deque(iterator, maxlen=0). From Hermann.Lauer at iwr.uni-heidelberg.de Mon Feb 1 18:05:16 2010 From: Hermann.Lauer at iwr.uni-heidelberg.de (Hermann Lauer) Date: Tue, 2 Feb 2010 00:05:16 +0100 Subject: Optimized bytecode in exec statement Message-ID: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Dear All, while trying to optimize some unpack operations with self compiling code I wondered howto invoke the optimization in the exec statement. Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis code, which is appended below. My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on the stack (are there hash lookups behind those ?) and of course to optimize the integer arithmetics following below (removing +-0 etc). Thanks for any ideas, greetings Hermann >>> import dis >>> g=r.rra.LAST3.getter(ds=0,row=0) class fa(struct.Struct): def __init__(s): super(fa,s).__init__('d') def __call__(s,): return s.unpack_from(s.buf,5392+(((s.lastrow()-0)%2880)*3+0)*8)[0] >>> dis.dis(g.__call__) 7 0 LOAD_FAST 0 (s) 3 LOAD_ATTR 0 (unpack_from) 6 LOAD_FAST 0 (s) 9 LOAD_ATTR 1 (buf) 12 LOAD_CONST 1 (5392) 15 LOAD_FAST 0 (s) 18 LOAD_ATTR 2 (lastrow) 21 CALL_FUNCTION 0 24 LOAD_CONST 2 (0) 27 BINARY_SUBTRACT 28 LOAD_CONST 3 (2880) 31 BINARY_MODULO 32 LOAD_CONST 4 (3) 35 BINARY_MULTIPLY 36 LOAD_CONST 2 (0) 39 BINARY_ADD 40 LOAD_CONST 5 (8) 43 BINARY_MULTIPLY 44 BINARY_ADD 45 CALL_FUNCTION 2 48 LOAD_CONST 2 (0) 51 BINARY_SUBSCR 52 RETURN_VALUE -- Netzwerkadministration/Zentrale Dienste, Interdiziplinaeres Zentrum fuer wissenschaftliches Rechnen der Universitaet Heidelberg IWR; INF 368; 69120 Heidelberg; Tel: (06221)54-8236 Fax: -5224 Email: Hermann.Lauer at iwr.uni-heidelberg.de From clp2 at rebertia.com Mon Feb 1 18:07:03 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 15:07:03 -0800 Subject: Python and Ruby In-Reply-To: <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: <50697b2c1002011507m35902e99hca59d26101bc644@mail.gmail.com> On Mon, Feb 1, 2010 at 2:28 PM, Jonathan Gardner wrote: > On Jan 31, 3:01?am, rantingrick wrote: >> On Jan 30, 10:43?am, Nobody wrote: >> > That's also true for most functional languages, e.g. Haskell and ML, as >> > well as e.g. Tcl and most shells. Why require "f(x)" or "(f x)" if "f x" >> > will suffice? >> >> yuck! wrapping the arg list with parenthesis (python way) makes the >> most sense. Its to easy to misread somthing like this >> >> onetwothree four five six >> >> onetwothree(four, five, six) #ahhh... plain english. > > In Lisp-ish languages, you have a list of stuff that represents a > function call: > > ?(a b c d) > > means: Call "a" with values (b, c, d) > > While this certainly doesn't agree with what you learned in Algebra, > it is a reasonable syntax that exposes the code-data duality of > programs. There is, however, one fatal flaw. Why is the first element > so different than the rest? This is inconsistent with what people who > are unfamiliar with the language would expect. Indeed, in teaching > Lisp, learners have to be reminded about how the evaluator looks at > lists and processes them. > > I would expect a clear, simple language to have exactly one way to > call a function. This calling notation would clearly distinguish > between the function and its parameters. There are quite a few > options, and it turns out that "function(arg, arg, arg)" is a really > good compromise. > > One of the bad things with languages like perl and Ruby that call > without parentheses is that getting a function ref is not obvious. You > need even more syntax to do so. In perl: > > ?foo(); ? ? ? # Call 'foo' with no args. > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > ? ? ? ? ? ? ?# By the way, this '&' is not the bitwise-and '&'!!!! > ?$bar->() ? ? # Call whatever '$bar' is pointing at with no args > > Compare with python: > > ?foo() ? ? ? # Call 'foo' with no args. > ?bar = foo() # 'bar' is now pointing to whatever 'foo()' returned > ?bar = foo ? # 'bar' is now pointing to the same thing 'foo' points to > ?bar() ? ? ? # Call 'bar' with no args > > One is simple, consistent, and easy to explain. The other one requires > the introduction of advanced syntax and an entirely new syntax to make > function calls with references. Ruby isn't nearly as bad as Perl in this regard; at least it doesn't introduce extra syntax (though there are extra method calls): foo # Call 'foo' with no args. bar = foo # Call 'foo; with no args, assign to bar bar = method(:foo) # 'bar' is now referencing the 'foo' "function" bar.call # Call 'bar' (i.e. 'foo') with no args Cheers, Chris -- http://blog.rebertia.com From as at sci.fi Mon Feb 1 18:08:39 2010 From: as at sci.fi (Anssi Saari) Date: Tue, 02 Feb 2010 01:08:39 +0200 Subject: myths about python 3 References: <4b60a4c3$0$1655$742ec2ed@news.sonic.net> Message-ID: Blog writes: > Where did you come up with that information? Almost all of the major > distros ship with 2.6.x - CentOS, OpenSuSe, Ubuntu, Fedora. (Debian > does ship with 2.5, but the next major release "sid' is due out in Q2) I don't see Python 2.6 in my CentOS 5.4 installation. All I see is 2.4. Same as RHEL and I'd say that's a fairly major distribution too. From no.email at nospam.invalid Mon Feb 1 18:08:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 01 Feb 2010 15:08:48 -0800 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <7xeil4tuyn.fsf@ruckus.brouhaha.com> Jonathan Gardner writes: > I judge a language's simplicity by how long it takes to explain the > complete language. That is, what minimal set of documentation do you > need to describe all of the language? With a handful of statements, > and a very short list of operators, Python beats out every language in > the Algol family that I know of. Python may have been like that in the 1.5 era. By now it's more complex, and not all that well documented. Consider the different subclassing rules for new and old style classes, the interaction of metaclasses and multiple inheritance, the vagaries of what operations are thread-safe without locks, the inter-thread signalling mechanism that can only be invoked through the C API, the mysteries of generator-based coroutines, etc. I've never used Ruby and I think its syntax is ugly, but everyone tells me it's more uniform. Simplicity is not necessarily such a good thing anyway. Consider FORTH. From martin at v.loewis.de Mon Feb 1 18:12:34 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 02 Feb 2010 00:12:34 +0100 Subject: recv_into(bytearray) complains about a "pinned buffer" In-Reply-To: References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> Message-ID: <4B675FE2.4090404@v.loewis.de> Antoine Pitrou wrote: > Le Mon, 01 Feb 2010 03:30:56 +0100, Martin v. Loewis a ?crit : >>> Is this a bug in Python 2.6 or a deliberate choice regarding >>> implementation concerns I don't know about? >> It's actually a bug also that you pass an array; doing so *should* give >> the very same error. > > Well, if you can give neither an array nor a bytearray to recv_into(), > what *could* you give it? My recommendation would be to not use recv_into in 2.x, but only in 3.x. > recv_into() should simply be fixed to use the new buffer API, as it does > in 3.x. I don't think that's the full solution. The array module should also implement the new buffer API, so that it would also fail with the old recv_into. Regards, Martin From aahz at pythoncraft.com Mon Feb 1 18:29:55 2010 From: aahz at pythoncraft.com (Aahz) Date: 1 Feb 2010 15:29:55 -0800 Subject: interaction of mode 'r+', file.write(), and file.tell(): a bug or undefined behavior? References: <4b617f4a$1@dnews.tpgi.com.au> Message-ID: In article <4b617f4a$1 at dnews.tpgi.com.au>, Lie Ryan wrote: > >f = open('input.txt', 'r+') >for line in f: > s = line.replace('python', 'PYTHON') > # f.tell() > f.write(s) > >When f.tell() is commented, 'input.txt' does not change; but when >uncommented, the f.write() succeeded writing into the 'input.txt' >(surprisingly, but not entirely unexpected, at the end of the file). Another possible issue is that using a file iterator is generally not compatible with direct file operations. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From andrewdalke at gmail.com Mon Feb 1 19:02:24 2010 From: andrewdalke at gmail.com (Andrew Dalke) Date: Mon, 1 Feb 2010 16:02:24 -0800 (PST) Subject: recv_into(bytearray) complains about a "pinned buffer" References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> <4B675FE2.4090404@v.loewis.de> Message-ID: <942aa99d-1bc1-4aa8-867a-6366cb3668a1@36g2000yqu.googlegroups.com> On Feb 2, 12:12?am, Martin v. Loewis wrote: > My recommendation would be to not use recv_into in 2.x, but only in 3.x. > I don't think that's the full solution. The array module should also > implement the new buffer API, so that it would also fail with the old > recv_into. Okay. But recv_into was added in 2.5 and the test case in 2.6's test_socket.py clearly allows an array there: def testRecvInto(self): buf = array.array('c', ' '*1024) nbytes = self.cli_conn.recv_into(buf) self.assertEqual(nbytes, len(MSG)) msg = buf.tostring()[:len(MSG)] self.assertEqual(msg, MSG) Checking koders and Google Code search engines, I found one project which used recv_into, with the filename bmpreceiver.py . It uses a array.array("B", [0] * length) . Clearly it was added to work with an array, and it's being used with an array. Why shouldn't people use it with Python 2.x? Andrew dalke at dalkescientific.com From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 19:49:00 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 00:49:00 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Mon, 01 Feb 2010 21:19:52 +0100, Daniel Fetchinson wrote: >> Personally, I think it is a terribly idea to keep the source file and >> byte code file in such radically different places. They should be kept >> together. What you call "clutter" I call having the files that belong >> together kept together. > > I see why you think so, it's reasonable, however there is compelling > argument, I think, for the opposite view: namely to keep things > separate. An average developer definitely wants easy access to .py > files. However I see no good reason for having access to .pyc files. I > for one have never inspected a .pyc file. Why would you want to have a > .pyc file at hand? If you don't care about access to .pyc files, why do you care where they are? If they are in a subdirectory module.pyr, then shrug and ignore the subdirectory. If you (generic you) are one of those developers who don't care about .pyc files, then when you are browsing your source directory and see this: module.py module.pyc you just ignore the .pyc file. Or delete it, and Python will re-create it as needed. So if you see module.pyr/ just ignore that as well. > If we don't really want to have .pyc files in convenient locations > because we (almost) never want to access them really, then I'd say it's > a good idea to keep them totally separate and so make don't get in the > way. I like seeing them in the same place as the source file, because when I start developing a module, I often end up renaming it multiple times before it settles on a final name. When I rename or move it, I delete the .pyc file, and that ensures that if I miss changing an import, and try to import the old name, it will fail. By hiding the .pyc file elsewhere, it is easy to miss deleting one, and then the import won't fail, it will succeed, but use the old, obsolete byte code. -- Steven From lists at cheimes.de Mon Feb 1 20:00:50 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 02 Feb 2010 02:00:50 +0100 Subject: Modules failing to add runtime library path info at link time In-Reply-To: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> Message-ID: <4B677942.2090002@cheimes.de> cjblaine wrote: > Where/how can I configure the appropriate portion of our Python > install to do 100% the right thing instead of just 50% (-L)? Python's distutils doesn't alter the library search path unless you tell it explicitly. > A specific example -- note the -L and lack of -R (Solaris build): > > % python setup.py build > .... > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > % The Extension() class supports the rpath argument. Simply add rpath="/path/to/library/dir" and you are good. Christian From tjreedy at udel.edu Mon Feb 1 20:02:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 01 Feb 2010 20:02:01 -0500 Subject: Optimized bytecode in exec statement In-Reply-To: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: On 2/1/2010 6:05 PM, Hermann Lauer wrote: > Dear All, > > while trying to optimize some unpack operations with self compiling > code I wondered howto invoke the optimization in the exec statement. > Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis code, which > is appended below. Currently, as far as I know, -0 just removes asserts. > > My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on the stack > (are there hash lookups behind those ?) Load_fast is a locals array lookup. load_fast 0 (s) means "put locals[0] on the top of the stack". The '(s)' is added for the human reader. > and of course to optimize the integer > arithmetics following below (removing +-0 etc). Something + 0 is no necessarily something. It depends on the type of something. So the interpreter will not optimize it away. What concretely happens with int+0 is a different matter. You can remove it though, if you want to get into byte-code hacking, but why write '+0' if you do not want it? > Thanks for any ideas, > greetings > Hermann > > >>>> import dis >>>> g=r.rra.LAST3.getter(ds=0,row=0) > > class fa(struct.Struct): > def __init__(s): > super(fa,s).__init__('d') > > def __call__(s,): > return s.unpack_from(s.buf,5392+(((s.lastrow()-0)%2880)*3+0)*8)[0] > >>>> dis.dis(g.__call__) > 7 0 LOAD_FAST 0 (s) > 3 LOAD_ATTR 0 (unpack_from) > 6 LOAD_FAST 0 (s) > 9 LOAD_ATTR 1 (buf) > 12 LOAD_CONST 1 (5392) > 15 LOAD_FAST 0 (s) > 18 LOAD_ATTR 2 (lastrow) > 21 CALL_FUNCTION 0 > 24 LOAD_CONST 2 (0) > 27 BINARY_SUBTRACT > 28 LOAD_CONST 3 (2880) > 31 BINARY_MODULO > 32 LOAD_CONST 4 (3) > 35 BINARY_MULTIPLY > 36 LOAD_CONST 2 (0) > 39 BINARY_ADD > 40 LOAD_CONST 5 (8) > 43 BINARY_MULTIPLY > 44 BINARY_ADD > 45 CALL_FUNCTION 2 > 48 LOAD_CONST 2 (0) > 51 BINARY_SUBSCR > 52 RETURN_VALUE Terry Jan Reedy From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 20:12:04 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 01:12:04 GMT Subject: For loop searching takes too long! References: <6ea6ebda-43af-4a77-a17e-0930cdd13258@b9g2000pri.googlegroups.com> <03738ee7$0$1309$c3e8da3@news.astraweb.com> <96e06a43-2197-4e93-9837-3c4b461985e0@m27g2000prl.googlegroups.com> Message-ID: On Mon, 01 Feb 2010 14:04:01 -0800, Jonathan Gardner wrote: > Having worked with datasets that are truly enormous, whenever I see a > list that is unbounded (as this appears to be), I freak out because > unbounded can be a really, really big number. Might as well write > software that works for the truly enormous case and the really large > case and be done with it once and for all. Then write it to work on iterators, if at all possible, and you won't care how large the data stream is. Even databases have limits! Of course you should write your code to deal with your expected data, but it is possible to commit overkill as well as underkill. There are trade- offs between development effort, runtime speed, memory usage, and size of data you can deal with, and maximizing the final one is not always the best strategy. Look at it this way... for most applications, you probably don't use arbitrary precision floats even though floating point numbers can have an unbounded number of decimal places. But in practice, you almost never need ten decimal places to pi, let alone an infinite number. If the creators of floating point libraries wrote software "that works for the truly enormous case", the overhead would be far too high for nearly all applications. Choose your algorithm according to your expected need. If you under- estimate your need, you will write slow code, and if you over-estimate it, you'll write slow code too. Getting that balance right is why they pay software architects the big bucks *wink* -- Steven From lists at cheimes.de Mon Feb 1 20:17:14 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 02 Feb 2010 02:17:14 +0100 Subject: Optimized bytecode in exec statement In-Reply-To: References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: <4B677D1A.9000403@cheimes.de> Terry Reedy wrote: > Currently, as far as I know, -0 just removes asserts. -O (not -0) also sets __debug__ to False. Christian From gagsl-py2 at yahoo.com.ar Mon Feb 1 20:19:43 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 01 Feb 2010 22:19:43 -0300 Subject: Optimized bytecode in exec statement References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: En Mon, 01 Feb 2010 20:05:16 -0300, Hermann Lauer escribi?: > while trying to optimize some unpack operations with self compiling > code I wondered howto invoke the optimization in the exec statement. > Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis > code, which > is appended below. There is not much difference with -O or -OO; assert statements are removed, __debug__ is False, docstrings are not stored (in -OO). Code generation is basically the same. > My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on > the stack > (are there hash lookups behind those ?) No, no lookup is performed at run time. LOAD_FAST takes an integer argument, an index into the locals array. The compiler knows (by static analysis, at compile time) which names are local; those objects are stored in a C array. I've not done such microbenchmark, but using DUP_TOP instead might even be slower. > and of course to optimize the integer > arithmetics following below (removing +-0 etc). Can't you remove it from source beforehand? (or, from `r.rra.LAST3.getter(ds=0,row=0)` since it looks like a code generator) In general, x+0 may execute arbitrary code, depending on the type of x. Only if you could determine that x will always be an integer, you could optimize +0 away. Python (the current version of CPython) does not perform such analysis; you may investigate psyco, Unladen Swallow, ShedSkin for such things. -- Gabriel Genellina From nobody at nowhere.com Mon Feb 1 21:03:18 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 02:03:18 +0000 Subject: Python and Ruby References: <0375f245$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Sun, 31 Jan 2010 22:36:32 +0000, Steven D'Aprano wrote: >> for example, in if you have a function 'f' which takes two parameters to >> call the function and get the result you use: >> >> f 2 3 >> >> If you want the function itself you use: >> >> f > > How do you call a function of no arguments? There's no such thing. All functions take one argument and return a value. As functions don't have side-effects, there is seldom much point in having a function with no arguments or which doesn't return a value. In cases where it is useful (i.e. a value must have function type), you can use the unit type "()" (essentially a zero-element tuple), e.g.: f () = 1 or: f x = () From python at mrabarnett.plus.com Mon Feb 1 21:14:03 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Feb 2010 02:14:03 +0000 Subject: Python and Ruby In-Reply-To: References: <0375f245$0$1309$c3e8da3@news.astraweb.com> Message-ID: <4B678A6B.6060003@mrabarnett.plus.com> Nobody wrote: > On Sun, 31 Jan 2010 22:36:32 +0000, Steven D'Aprano wrote: > >>> for example, in if you have a function 'f' which takes two parameters to >>> call the function and get the result you use: >>> >>> f 2 3 >>> >>> If you want the function itself you use: >>> >>> f >> How do you call a function of no arguments? > > There's no such thing. All functions take one argument and return a value. > > As functions don't have side-effects, there is seldom much point in having > a function with no arguments or which doesn't return a value. In cases > where it is useful (i.e. a value must have function type), you can use the > unit type "()" (essentially a zero-element tuple), e.g.: > > f () = 1 > or: > f x = () > A function with no arguments could be used as a lazy constant, generated only on demand. From clp2 at rebertia.com Mon Feb 1 21:17:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 18:17:04 -0800 Subject: Python and Ruby In-Reply-To: <4B678A6B.6060003@mrabarnett.plus.com> References: <0375f245$0$1309$c3e8da3@news.astraweb.com> <4B678A6B.6060003@mrabarnett.plus.com> Message-ID: <50697b2c1002011817t572edf0fo52954a7f4a192b03@mail.gmail.com> On Mon, Feb 1, 2010 at 6:14 PM, MRAB wrote: > Nobody wrote: >> On Sun, 31 Jan 2010 22:36:32 +0000, Steven D'Aprano wrote: >>>> for example, in if you have a function 'f' which takes two parameters to >>>> call the function and get the result you use: >>>> >>>> ?f 2 3 >>>> >>>> If you want the function itself you use: >>>> >>>> ? f >>> >>> How do you call a function of no arguments? >> >> There's no such thing. All functions take one argument and return a value. >> >> As functions don't have side-effects, there is seldom much point in having >> a function with no arguments or which doesn't return a value. In cases >> where it is useful (i.e. a value must have function type), you can use the >> unit type "()" (essentially a zero-element tuple), e.g.: >> >> ? ? ? ?f () = 1 >> or: >> ? ? ? ?f x = () >> > A function with no arguments could be used as a lazy constant, generated > only on demand. The usefulness of that depends on a language's evaluation strategy. Haskell, for instance, uses lazy evaluation by default, so your use case doesn't apply in that instance. Cheers, Chris -- http://blog.rebertia.com From nobody at nowhere.com Mon Feb 1 21:21:55 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 02:21:55 +0000 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> Message-ID: On Mon, 01 Feb 2010 14:35:57 -0800, Jonathan Gardner wrote: >> If it was common-place to use Curried functions and partial application in >> Python, you'd probably prefer "f a b c" to "f(a)(b)(c)" as well. > > That's just the point. It isn't common to play with curried functions > or monads or anything like that in computer science today. Yes, > Haskell exists, and is a great experiment in how such a language could > actually work. But at the same time, you have to have a brain the size > of the titanic to contain all the little details about the language > before you could write any large-scale application. No, not really. Haskell (and previously ML) are often used as introductory languages in Comp.Sci. courses (at least in the UK). You don't need to know the entire language before you can use any of it (if you did, Python would be deader than a certain parrot; Python's dark corners are *really* dark). The lack of mutable state (or at least, the isolation of it within monads) eliminates a lot of potential problems. How many Python novices get tripped up by "x = y = [] ; x.append(...); # now y has changed"? And in spite of the category theory behind monads, Haskell's I/O system really isn't any more complex than that of any other language, beyond the constraint that you can only use it in "procedures" (i.e. something returning an IO instance), not in functions. Which for the most part, is a net win, as it forces you to maintain a reasonable degree of structure. Now, if you actually want to use everything the language has to offer, you can run into some fairly hairy error messages. But then I've found that to be a common problem with generic programming in general. E.g. error messages relating to the C++ STL can be quite insanely complex (particularly when the actual error is "there are so many nested templates that the mangled function name is longer than the linker can handle" and it's trying to explain *where* the error is). From no.email at please.post Mon Feb 1 21:34:07 2010 From: no.email at please.post (kj) Date: Tue, 2 Feb 2010 02:34:07 +0000 (UTC) Subject: How to guard against bugs like this one? Message-ID: I just spent about 1-1/2 hours tracking down a bug. An innocuous little script, let's call it buggy.py, only 10 lines long, and whose output should have been, at most two lines, was quickly dumping tens of megabytes of non-printable characters to my screen (aka gobbledygook), and in the process was messing up my terminal *royally*. Here's buggy.py: import sys import psycopg2 connection_params = "dbname='%s' user='%s' password='%s'" % tuple(sys.argv[1:]) conn = psycopg2.connect(connection_params) cur = conn.cursor() cur.execute('SELECT * FROM version;') print '\n'.join(x[-1] for x in cur.fetchall()) (Of course, buggy.py is pretty useless; I reduced the original, more useful, script to this to help me debug it.) Through a *lot* of trial an error I finally discovered that the root cause of the problem was the fact that, in the same directory as buggy.py, there is *another* innocuous little script, totally unrelated, whose name happens to be numbers.py. (This second script is one I wrote as part of a little Python tutorial I put together months ago, and is not much more of a script than hello_world.py; it's baby-steps for the absolute beginner. But apparently, it has a killer name! I had completely forgotten about it.) Both scripts live in a directory filled with *hundreds* little one-off scripts like the two of them. I'll call this directory myscripts in what follows. It turns out that buggy.py imports psycopg2, as you can see, and apparently psycopg2 (or something imported by psycopg2) tries to import some standard Python module called numbers; instead it ends up importing the innocent myscript/numbers.py, resulting in *absolute mayhem*. (This is no mere Python "wart"; this is a suppurating chancre, and the fact that it remains unfixed is a neverending source of puzzlement for me.) How can the average Python programmer guard against this sort of time-devouring bug in the future (while remaining a Python programmer)? The only solution I can think of is to avoid like the plague the basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, and *pray* that whatever name one chooses for one's script does not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory of a future release. What else can one do? Let's see, one should put every script in its own directory, thereby containing the damage. Anything else? Any suggestion would be appreciated. TIA! ~k From john at castleamber.com Mon Feb 1 21:36:44 2010 From: john at castleamber.com (John Bokma) Date: Mon, 01 Feb 2010 20:36:44 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: <87sk9knz2b.fsf@castleamber.com> Jonathan Gardner writes: > One of the bad things with languages like perl FYI: the language is called Perl, the program that executes a Perl program is called perl. > without parentheses is that getting a function ref is not obvious. You > need even more syntax to do so. In perl: > > foo(); # Call 'foo' with no args. > $bar = foo; # Call 'foo; with no args, assign to '$bar' > $bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > # By the way, this '&' is not the bitwise-and '&'!!!! It should be $bar = \&foo Your example actually calls foo... [..] > One is simple, consistent, and easy to explain. The other one requires > the introduction of advanced syntax and an entirely new syntax to make > function calls with references. The syntax follows that of referencing and dereferencing: $bar = \@array; # bar contains now a reference to array $bar->[ 0 ]; # first element of array referenced by bar $bar = \%hash; # bar contains now a reference to a hash $bar->{ key }; # value associated with key of hash ref. by bar $bar = \&foo; # bar contains now a reference to a sub $bar->( 45 ); # call sub ref. by bar with 45 as an argument Consistent: yes. New syntax? No. Also, it helps to think of $ as a thing @ as thingies indexed by numbers % as thingies indexed by keys -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From apt.shansen at gmail.com Mon Feb 1 21:50:16 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 1 Feb 2010 18:50:16 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > First, I don't shadow built in modules. Its really not very hard to avoid. Secondly, I use packages structuring my libraries, and avoid junk directories of a hundred some odd 'scripts'. Third, I don't execute scripts in that directory structure directly, but instead do python -c 'from package.blah import main; main.main()' or some such. Usually via some short-cut, or a runner batch file. Note that the third avoids the above problem entirely, but that's not why I do it. Its just a side-effect. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobody at nowhere.com Mon Feb 1 21:50:55 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 02:50:55 +0000 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: On Mon, 01 Feb 2010 14:13:38 -0800, Jonathan Gardner wrote: > I judge a language's simplicity by how long it takes to explain the > complete language. That is, what minimal set of documentation do you > need to describe all of the language? That's not a particularly good metric, IMHO. A simple "core" language doesn't necessarily make a language simple to use. You can explain the entirety of pure lambda calculus or combinators in five minutes, but you wouldn't want to write real code in either (and you certainly wouldn't want to read such code which was written by someone else). For a start, languages with a particularly simple "core" tend to delegate too much to the library. One thing which puts a lot of people off of lisp is the lack of infix operators; after all, (* 2 (+ 3 4)) works fine and doesn't require any additional language syntax. For an alternative, Tcl provides the "expr" function which essentially provides a sub-language for arithmetic expressions. A better metric is whether using N features has O(N) complexity, or O(N^2) (where you have to understand how each feature relates to each other feature) or even O(2^N) (where you have to understand every possible combination of interactions). > With a handful of statements, > and a very short list of operators, Python beats out every language in > the Algol family that I know of. Not once you move beyond the 10-minute introduction, and have to start thinking in terms of x + y is x.__add__(y) or maybe y.__radd__(x) and also that x.__add__(y) is x.__getattribute__('__add__')(y) (but x + y *isn't* equivalent to the latter due to __slots__), and maybe .__coerce__() gets involved somewhere, and don't even get me started on __metaclass__ or __init__ versus __new__ or ... Yes, the original concept was very nice and clean, but everything since then has been wedged in there by sheer force with a bloody great hammer. From sccolbert at gmail.com Mon Feb 1 21:54:04 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 1 Feb 2010 21:54:04 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7f014ea61002011854h47a61da7j8740be722b8eb656@mail.gmail.com> This is kinda akin to creating your own libc.so in a folder where your compiling and executing c programs and then wondering why your program bugs out.... On Mon, Feb 1, 2010 at 9:34 PM, kj wrote: > > > I just spent about 1-1/2 hours tracking down a bug. > > An innocuous little script, let's call it buggy.py, only 10 lines > long, and whose output should have been, at most two lines, was > quickly dumping tens of megabytes of non-printable characters to > my screen (aka gobbledygook), and in the process was messing up my > terminal *royally*. Here's buggy.py: > > > > import sys > import psycopg2 > connection_params = "dbname='%s' user='%s' password='%s'" % > tuple(sys.argv[1:]) > conn = psycopg2.connect(connection_params) > cur = conn.cursor() > cur.execute('SELECT * FROM version;') > print '\n'.join(x[-1] for x in cur.fetchall()) > > > (Of course, buggy.py is pretty useless; I reduced the original, > more useful, script to this to help me debug it.) > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. (This second script > is one I wrote as part of a little Python tutorial I put together > months ago, and is not much more of a script than hello_world.py; > it's baby-steps for the absolute beginner. But apparently, it has > a killer name! I had completely forgotten about it.) > > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. I'll call this directory > myscripts in what follows. > > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > > What else can one do? Let's see, one should put every script in its > own directory, thereby containing the damage. > > Anything else? > > Any suggestion would be appreciated. > > TIA! > > ~k > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Feb 1 21:56:34 2010 From: john at castleamber.com (John Bokma) Date: Mon, 01 Feb 2010 20:56:34 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> Message-ID: <87bpg8ny59.fsf@castleamber.com> Nobody writes: > On Mon, 01 Feb 2010 14:35:57 -0800, Jonathan Gardner wrote: > >>> If it was common-place to use Curried functions and partial application in >>> Python, you'd probably prefer "f a b c" to "f(a)(b)(c)" as well. >> >> That's just the point. It isn't common to play with curried functions >> or monads or anything like that in computer science today. Yes, >> Haskell exists, and is a great experiment in how such a language could >> actually work. But at the same time, you have to have a brain the size >> of the titanic to contain all the little details about the language >> before you could write any large-scale application. > > No, not really. Haskell (and previously ML) are often used as introductory > languages in Comp.Sci. courses (at least in the UK). At least in the early 90's this was also the case in the Netherlands, at the University of Utrecht. We got Miranda/Gofer, and in a different, more advanced course Linda (Miranda for parallel machines). Also the inner workings of functional programming languages was a course. (Can't recall the name of the book that was used, but it was quite good IMO). I want to start (re)learning Haskell later this year, because I liked Miranda/Gofer a lot back then. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From clp2 at rebertia.com Mon Feb 1 21:57:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 1 Feb 2010 18:57:27 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <50697b2c1002011857h6e60a28ajd3a6f0c4516fe286@mail.gmail.com> On Mon, Feb 1, 2010 at 6:34 PM, kj wrote: > I just spent about 1-1/2 hours tracking down a bug. > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. ?(This second script > is one I wrote as part of a little Python tutorial I put together > months ago, and is not much more of a script than hello_world.py; > it's baby-steps for the absolute beginner. ?But apparently, it has > a killer name! ?I had completely forgotten about it.) > > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. ?I'll call this directory > myscripts in what follows. > > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > > What else can one do? ?Let's see, one should put every script in its > own directory, thereby containing the damage. > > Anything else? > > Any suggestion would be appreciated. I think absolute imports avoid this problem: from __future__ import absolute_import For details, see PEP 328: http://www.python.org/dev/peps/pep-0328/ Cheers, Chris -- http://blog.rebertia.com From nobody at nowhere.com Mon Feb 1 22:09:48 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 03:09:48 +0000 Subject: HTML Parser which allows low-keyed local changes? References: Message-ID: On Sun, 31 Jan 2010 20:57:31 +0100, Robert wrote: > I tried lxml, but after walking and making changes in the element > tree, I'm forced to do a full serialization of the whole document > (etree.tostring(tree)) - which destroys the "human edited" format > of the original HTML code. > makes it rather unreadable. > > is there an existing HTML parser which supports tracking/writing > back particular changes in a cautious way by just making local > changes? or a least tracks the tag start/end positions in the file? HTMLParser, sgmllib.SGMLParser and htmllib.HTMLParser all allow you to retrieve the literal text of a start tag (but not an end tag). Unfortunately, they're only tokenisers, not parsers, so you'll need to handle minimisation yourself. From roy at panix.com Mon Feb 1 22:15:32 2010 From: roy at panix.com (Roy Smith) Date: Mon, 01 Feb 2010 22:15:32 -0500 Subject: How to guard against bugs like this one? References: Message-ID: In article , kj wrote: > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. > [...] > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. I feel your pain, but this is not a Python problem, per-se. The general pattern is: 1) You have something which refers to a resource by name. 2) There is a sequence of places which are searched for this name. 3) The search finds the wrong one because another resource by the same name appears earlier in the search path. I've gotten bitten like this by shells finding the wrong executable (in $PATH). By dynamic loaders finding the wrong library (in $LD_LIBRARY_PATH). By C compilers finding the wrong #include file. And so on. This is just Python's import finding the wrong module in your $PYTHON_PATH. The solution is the same in all cases. You either have to refer to resources by some absolute name, or you need to make sure you set up your search paths correctly and know what's in them. In your case, one possible solution be to make sure "." (or "") isn't in sys.path (although that might cause other issues). From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 22:28:55 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 03:28:55 GMT Subject: How to guard against bugs like this one? References: Message-ID: On Tue, 02 Feb 2010 02:34:07 +0000, kj wrote: > I just spent about 1-1/2 hours tracking down a bug. > > An innocuous little script, let's call it buggy.py, only 10 lines long, > and whose output should have been, at most two lines, was quickly > dumping tens of megabytes of non-printable characters to my screen (aka > gobbledygook), and in the process was messing up my terminal *royally*. > Here's buggy.py: [...] > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to import > some standard Python module called numbers; instead it ends up importing > the innocent myscript/numbers.py, resulting in *absolute mayhem*. There is no module numbers in the standard library, at least not in 2.5. >>> import numbers Traceback (most recent call last): File "", line 1, in ImportError: No module named numbers It must be specific to psycopg2. I would think this is a problem with psycopg2 -- it sounds like it should be written as a package, but instead is written as a bunch of loose modules. I could be wrong of course, but if it is just a collection of modules, I'd definitely call that a poor design decision, if not a bug. > (This is no mere Python "wart"; this is a suppurating chancre, and the > fact that it remains unfixed is a neverending source of puzzlement for > me.) No, it's a wart. There's no doubt it bites people occasionally, but I've been programming in Python for about ten years and I've never been bitten by this yet. I'm sure it will happen some day, but not yet. In this case, the severity of the bug (megabytes of binary crud to the screen) is not related to the cause of the bug (shadowing a module). As for fixing it, unfortunately it's not quite so simple to fix without breaking backwards-compatibility. The opportunity to do so for Python 3.0 was missed. Oh well, life goes on. > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, and > *pray* that whatever name one chooses for one's script does not suddenly > pop up in the appropriate /usr/lib/pythonX.XX directory of a future > release. Unfortunately, Python makes no guarantee that there won't be some clash between modules. You can minimize the risks by using packages, e.g. given a package spam containing modules a, b, c, and d, if you refer to spam.a etc. then you can't clash with modules a, b, c, d, but only spam. So you've cut your risk profile from five potential clashes to only one. Also, generally most module clashes are far more obvious. If you do this: import module x = module.y and module is shadowed by something else, you're *much* more likely to get an AttributeError than megabytes of crud to the screen. I'm sorry that you got bitten so hard by this, but in practice it's uncommon, and relatively mild when it happens. > What else can one do? Let's see, one should put every script in its own > directory, thereby containing the damage. That's probably a bit extreme, but your situation: "Both scripts live in a directory filled with *hundreds* little one-off scripts like the two of them." is far too chaotic for my liking. You don't need to go to the extreme of a separate directory for each file, but you can certainly tidy things up a bit. For example, anything that's obsolete should be moved out of the way where it can't be accidentally executed or imported. -- Steven From python.list at tim.thechases.com Mon Feb 1 22:33:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 01 Feb 2010 21:33:10 -0600 Subject: How to guard against bugs like this one? In-Reply-To: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> Message-ID: <4B679CF6.1060607@tim.thechases.com> Stephen Hansen wrote: > First, I don't shadow built in modules. Its really not very hard to avoid. Given the comprehensive nature of the batteries-included in Python, it's not as hard to accidentally shadow a built-in, unknown to you, but yet that is imported by a module you are using. The classic that's stung me enough times (and many others on c.l.p and other forums, as a quick google evidences) such that I *finally* remember: bash$ touch email.py bash$ python ... >>> import smtplib Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/smtplib.py", line 46, in import email.Utils ImportError: No module named Utils Using "email.py" is an innocuous name for a script/module you might want to do emailish things, and it's likely you'll use smtplib in the same code...and kablooie, things blow up even if your code doesn't reference or directly use the built-in email.py. Yes, as Chris mentions, PEP-328 absolute vs. relative imports should help ameliorate the problem, but it's not yet commonly used (unless you're using Py3, it's only at the request of a __future__ import in 2.5+). -tkc From steven at REMOVE.THIS.cybersource.com.au Mon Feb 1 22:35:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 02 Feb 2010 03:35:47 GMT Subject: Optimized bytecode in exec statement References: <20100201230516.GA22351@lemon.iwr.uni-heidelberg.de> Message-ID: On Mon, 01 Feb 2010 22:19:43 -0300, Gabriel Genellina wrote: > En Mon, 01 Feb 2010 20:05:16 -0300, Hermann Lauer > escribi?: > >> while trying to optimize some unpack operations with self compiling >> code I wondered howto invoke the optimization in the exec statement. >> Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis >> code, which >> is appended below. > > There is not much difference with -O or -OO; assert statements are > removed, __debug__ is False, docstrings are not stored (in -OO). Code > generation is basically the same. Also code of the form: if __debug__: whatever is compiled away if __debug__ is false. > In general, x+0 may execute arbitrary code, depending on the type of x. > Only if you could determine that x will always be an integer, you could > optimize +0 away. Python (the current version of CPython) does not > perform such analysis; you may investigate psyco, Unladen Swallow, > ShedSkin for such things. Keep in mind that the peephole optimizer in CPython does constant folding: 1+1 compiles to 2. Older versions of Python, and other implementations, may not. But as a general rule, Python does very little optimization at compile time. To a first approximation, "remove asserts" is all that it does. -- Steven From apt.shansen at gmail.com Mon Feb 1 22:41:21 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 1 Feb 2010 19:41:21 -0800 Subject: How to guard against bugs like this one? In-Reply-To: <4B679CF6.1060607@tim.thechases.com> References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <4B679CF6.1060607@tim.thechases.com> Message-ID: <7a9c25c21002011941y6081fcabkd7f5d43b339f3781@mail.gmail.com> On Mon, Feb 1, 2010 at 7:33 PM, Tim Chase wrote: > Stephen Hansen wrote: > >> First, I don't shadow built in modules. Its really not very hard to avoid. >> > > Given the comprehensive nature of the batteries-included in Python, it's > not as hard to accidentally shadow a built-in, unknown to you, but yet that > is imported by a module you are using. I get that people run into this problem on occasion, but honestly-- its *really* not very hard to avoid. If you're creating a module which feels.. generic. As if you may use that same name for a certain kinda topic in a couple different programs-- chances are it /might/ be used as a generic provider of support for that kinda topic in the standard library. "email", "http", "url", anything with a generic .. smell. Assume it /is/ in the stdlib until you demonstrate otherwise, if you aren't deeply familiar with the stdlib. And two seconds later, you can know: 'import numbers' will work. Can't use that. Yeah, when a new version comes out, you may have to read What's New, and see a new module, then rename something. If you're going to use relative imports (and that's #2, I never do-- ever-- even before PEP328 existed), you just have to deal with the flatness of the top-level namespace and how Python broadly claims the right to put darn near anything in there. Although they do google around a bit to try to gauge how likely it is to clash, but still. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Mon Feb 1 23:01:11 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Feb 2010 20:01:11 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <012920a6-c9d7-4200-8b8a-160021dbf3bb@k2g2000pro.googlegroups.com> On Feb 1, 6:34?pm, kj wrote: > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. ?I'll call this directory > myscripts in what follows. [snip] > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? Don't put hundreds of little one-off scripts in single directory. Python can't save you from polluting your own namespace. Don't choose such generic names for modules. Keep in mind module names are potentially globally visible and any sane advice you ever heard about globals is to use descriptive names. I instinctively use adjectives, compound words, and abstract nouns for the names of all my modules so as to be more descriptive, and to avoid name conflicts with classes and variables. Also learn to debug better. Carl Banks From cjblaine at gmail.com Mon Feb 1 23:04:56 2010 From: cjblaine at gmail.com (cjblaine) Date: Mon, 1 Feb 2010 20:04:56 -0800 (PST) Subject: Modules failing to add runtime library path info at link time References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> Message-ID: <303e1371-bc77-4cc8-bbbf-bddfd610fad9@r19g2000yqb.googlegroups.com> On Feb 1, 8:00?pm, Christian Heimes wrote: > cjblaine wrote: > > Where/how can I configure the appropriate portion of our Python > > install to do 100% the right thing instead of just 50% (-L)? > > Python's distutils doesn't alter the library search path unless you tell > it explicitly. > > > A specific example -- note the -L and lack of -R (Solaris build): > > > % python setup.py build > > .... > > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > > % > > The Extension() class supports the rpath argument. Simply add > rpath="/path/to/library/dir" and you are good. > > Christian Thanks for the reply. So, python setup.py build rpath="/whatever/lib" ? From pavlovevidence at gmail.com Mon Feb 1 23:12:25 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 1 Feb 2010 20:12:25 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> Message-ID: <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> On Feb 1, 7:33?pm, Tim Chase wrote: > Stephen Hansen wrote: > > First, I don't shadow built in modules. Its really not very hard to avoid. > > Given the comprehensive nature of the batteries-included in > Python, it's not as hard to accidentally shadow a built-in, > unknown to you, but yet that is imported by a module you are > using. ?The classic that's stung me enough times (and many others > on c.l.p and other forums, as a quick google evidences) such that > I *finally* remember: > > ? ?bash$ touch email.py > ? ?bash$ python > ? ?... > ? ?>>> import smtplib > ? ?Traceback (most recent call last): > ? ? ?File "", line 1, in > ? ? ?File "/usr/lib/python2.5/smtplib.py", line 46, in > ? ? ? ?import email.Utils > ? ?ImportError: No module named Utils > > Using "email.py" is an innocuous name for a script/module you > might want to do emailish things, and it's likely you'll use > smtplib in the same code...and kablooie, things blow up even if > your code doesn't reference or directly use the built-in email.py. email.py is not an innocuous name, it's a generic name in a global namespace, which is a Bad Thing. Plus what does a script or module called "email.py" actually do? Send email? Parse email? "email" is terrible name for a module and you deserve what you got for using it. Name your modules "send_email.py" or "sort_email.py" or if it's a library module of related functions, "email_handling.py". Modules and scripts do things (usually), they should be given action words as names. (**) Questionable though it be, if the Standard Library wants to use an "innocuous" name, It can. Carl Banks From cjblaine at gmail.com Mon Feb 1 23:35:37 2010 From: cjblaine at gmail.com (cjblaine) Date: Mon, 1 Feb 2010 20:35:37 -0800 (PST) Subject: Modules failing to add runtime library path info at link time References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> <303e1371-bc77-4cc8-bbbf-bddfd610fad9@r19g2000yqb.googlegroups.com> Message-ID: <8167cbe0-d099-4a0b-804e-6e91817197ec@b10g2000yqa.googlegroups.com> On Feb 1, 11:04?pm, cjblaine wrote: > On Feb 1, 8:00?pm, Christian Heimes wrote: > > > > > cjblaine wrote: > > > Where/how can I configure the appropriate portion of our Python > > > install to do 100% the right thing instead of just 50% (-L)? > > > Python's distutils doesn't alter the library search path unless you tell > > it explicitly. > > > > A specific example -- note the -L and lack of -R (Solaris build): > > > > % python setup.py build > > > .... > > > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > > > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > > > % > > > The Extension() class supports the rpath argument. Simply add > > rpath="/path/to/library/dir" and you are good. > > > Christian > > Thanks for the reply. > > So, python setup.py build rpath="/whatever/lib" ? Replying to myself: No. Actually, Christian, it looks like it's runtime_library_dirs? class Extension: ... runtime_library_dirs : [string] list of directories to search for C/C++ libraries at run time (for shared extensions, this is when the extension is loaded) So, how does one inject that into, I assume, setup.cfg ? Ideally it could be done via the build command-line, but I don't see a way to do that when browsing python setup.py build --help ( there is no setup.cfg provided in the PyGreSQL source tree, to ) ( continue that example case ) From gobladoome at gmail.com Tue Feb 2 00:26:57 2010 From: gobladoome at gmail.com (Paul) Date: Tue, 2 Feb 2010 18:26:57 +1300 Subject: Problems embedding python 2.6 in C++ In-Reply-To: References: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> Message-ID: <5089497e1002012126h55f0611ct476eabb0ccf1bea1@mail.gmail.com> Thanks Gabriel, I've managed to get it working and so far stable... What wasn't working reliably: mycppclass mycppclass::mycppclass() m_mypymodule = PyImport_Import(pModuleName) mycppclass::~ mycppclass() Py_XDECREF(m_mypymodule) mycppclass::callpy(funcname, args...) PyTuple_SetItem * args PyCallable_Check(func) PyObject_CallObject(func) Current working version: mycppclass mycppclass::mycppclass() {} mycppclass::~ mycppclass() {} mycppclass::callpy(funcname, args...) m_mypymodule = PyImport_Import(pModuleName) pyargs = PyTuple_SetItem * args PyCallable_Check(func) PyObject_CallObject(func,pyargs) Py_XDECREF(m_mypymodule) So now the module is being imported each function call (luckily I don't have to worry about performance) I assume this means that the internal representation of the imported module is being corrupted by something. I found another person with a similar issue here: http://mail.python.org/pipermail/python-dev/2004-March/043306.html - that is a long time ago but another multi-threaded app. I'm happy to use the working method but I'd like to understand what is going on a bit more. Can anyone shed any further light? Regards, Paul. On Tue, Feb 2, 2010 at 11:59 AM, Gabriel Genellina wrote: > En Mon, 01 Feb 2010 18:21:56 -0300, Paul escribi?: > > > I'm extending some old Visual Studio 6 code to add embedded python >> scripting. It works fine most of the time but some python function calls >> do >> not work as expected. >> >> The C++ code is a multithreaded MFC application. I was assuming that it >> was >> GIL issues but I have tried using the manual locking (PyEval_SaveThread & >> PyEval_RestoreThread) and what seems to be the current method >> (PyGILState_Ensure & PyGILState_Release) >> >> Here's the error I'm getting: >> >> Traceback (most recent call last): >> File "...scripts\receipt_parser.py", line 296, in >> get_giftcard_purchase_value >> details = extract_transaction_details_section(test) >> File "...scripts\receipt_parser.py", line 204, in >> extract_transaction_details_section >> for line in base_details: >> TypeError: expected string or Unicode object, NoneType found >> >> base_details is a list of strings (I can just define it like >> 'base_details=["1","2","3"...]' on the line previous) and the code runs >> fine >> when run from standard interpreter. Many other function calls work fine >> from >> the embedded app. >> I create and then Py_DECREF the function parameters and the return value >> after each function call. The module import is created at C++ object >> constructor and then Py_DECREF'd in the desctuctor >> > > Usually, errors in reference count handling prevent objects from being > destroyed (a memory leak) or generate a GPF when accessing an now-inexistent > object. In principle I'd look elsewhere. > > > Anyone else had issues of this kind? >> > > Hard to tell without more info. base_details is built in C++ code? Is it > actually a list, or a subclass defined by you? > A common error is to forget to check *every* API function call for errors, > so errors get unnoticed for a while but are reported on the next check, > which may happen in an entirely unrelated function. > > > My next try will be to use >> sub-interpreters per thread. >> > > I would not do that - I'd try to *simplify* the code to test, not make it > more complicated. > Does it work in a single-threaded application? > > -- > Gabriel Genellina > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michele.simionato at gmail.com Tue Feb 2 00:47:36 2010 From: michele.simionato at gmail.com (Michele Simionato) Date: Mon, 1 Feb 2010 21:47:36 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Message-ID: <38aead35-0662-4e05-877a-e924b76ad4e4@c4g2000yqa.googlegroups.com> Wanting the same methods to be attached to different classes often is a code smell (perhaps it is not your case and then use setattr as others said). Perhaps you can just leave such methods outside any class. I would suggest you to use a testing framework not based on inheritance (i.e. use nose or py.test). Perhaps your problem can be solved with generative tests. From rolf.oltmans at gmail.com Tue Feb 2 00:55:16 2010 From: rolf.oltmans at gmail.com (Oltmans) Date: Mon, 1 Feb 2010 21:55:16 -0800 (PST) Subject: Adding methods from one class to another, dynamically References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> Message-ID: <9208c5ea-f36d-4a1c-969c-283ffb049491@e19g2000prn.googlegroups.com> On Feb 2, 2:14?am, Steve Holden wrote: > > Should not tee be subclassing test, not unittest.TestCase? > Thank you, Steve. This worked, but I've not clue why? Can you please enlighten me why sub-classing 'test' made it happen? Please. Thanks again. > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 ?http://us.pycon.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/- Hide quoted text - > > - Show quoted text - From gjango.py at gmail.com Tue Feb 2 01:05:38 2010 From: gjango.py at gmail.com (guptha) Date: Mon, 1 Feb 2010 22:05:38 -0800 (PST) Subject: How to use python-mms to send mms Message-ID: Hi group, After hours of googling i found out that we can use python-mms to send mms from our PC connected with GSM cell phone/Modem. I could appreciate if some one guide me with a example of sending an mms using python-mms. I am using Ubuntu9.10 .I am trying to send a ring tone via MMS. Thanks Ganesh Guptha From steve at holdenweb.com Tue Feb 2 01:06:32 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 01:06:32 -0500 Subject: Adding methods from one class to another, dynamically In-Reply-To: <9208c5ea-f36d-4a1c-969c-283ffb049491@e19g2000prn.googlegroups.com> References: <6bdff9bf-5b0d-410f-adc2-a0704fb188a0@b9g2000pri.googlegroups.com> <9208c5ea-f36d-4a1c-969c-283ffb049491@e19g2000prn.googlegroups.com> Message-ID: Oltmans wrote: > On Feb 2, 2:14 am, Steve Holden wrote: >> Should not tee be subclassing test, not unittest.TestCase? >> > > Thank you, Steve. This worked, but I've not clue why? Can you please > enlighten me why sub-classing 'test' made it happen? Please. Thanks > again. unittest.TestCase doesn't have any test* methods (methods whose names begin with "test"). So neither do your subclasses. When you subclass test, however, test has everything that unittest.TestCase does (because it subclasses unittest.TestCase) and it also has three test* methods. So your subclass of test also has those three methods as well. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From purui.wang at gmail.com Tue Feb 2 01:26:52 2010 From: purui.wang at gmail.com (purui) Date: Mon, 1 Feb 2010 22:26:52 -0800 (PST) Subject: search engine for python source code Message-ID: <717f2d32-df15-4acc-bc39-e9532d23a4b2@u18g2000prn.googlegroups.com> I developed a source code search engine for python (http:// nullege.com). It helps you find samples from open source projects. Unlike other code search engines, it really understands python syntax and generates more relative results. I'm working on expend the source code collection now. Give it a try if google can't find a sample for you. - Purui From casevh at gmail.com Tue Feb 2 01:45:56 2010 From: casevh at gmail.com (casevh) Date: Mon, 1 Feb 2010 22:45:56 -0800 (PST) Subject: ANN: GMPY 1.11 released Message-ID: Everyone, I'm pleased to annouce the final release of GMPY 1.11. GMPY is a wrapper for the MPIR or GMP multiple-precision arithmetic library. GMPY 1.11 is available for download from: http://code.google.com/p/gmpy/ In addition to support for Python 3.x, there are several new features in this release: - Even faster conversion to/from Python longs. - Performance improvements by reducing function overhead. - Performance improvements by improved caching. - Support for cdivmod, fdivmod, and tdivmod. - Unicode strings are accepted on Python 2.x and 3.x. - Fixed regression in GMPY 1.10 where True/False were no longer recognized. Changes since 1.11rc1: - Recognizes GMP 5. - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). Comments on provided binaries The 32-bit Windows installers were compiled with MinGW32 using MPIR 1.3.1 and will automatically recognize the CPU type and use code optimized for the CPU at runtime. The 64-bit Windows installers were compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed instructions are included if you want to compile your own binary. Please report any issues! casevh From masklinn at masklinn.net Tue Feb 2 02:29:38 2010 From: masklinn at masklinn.net (Masklinn) Date: Tue, 2 Feb 2010 08:29:38 +0100 Subject: Logging oddity: handlers mandatory in every single logger? Message-ID: When trying to load the following config file, I get an error ``ConfigParser.NoOptionError: No option 'handlers' in section: 'logger_0'`` (in both Python 2.6.4 and Python 3.1.1 on OSX, obviously ConfigParser is spelled configparser in 3.1): [loggers] keys=root,0 [handlers] keys=console [formatters] keys=simple [logger_root] handlers=console [logger_0] level=DEBUG qualname=0 [handler_console] class=StreamHandler formatter=simple args=() [formatter_simple] format=%(asctime)s:%(levelname)-8s:%(name)s::%(message)s the goal is simply to have a logging level different on ``0`` than it is on ``root``, but to get it I have to include a handler on ``0`` and stop propagation (or messages are displayed on both root and 0). Do note that this behavior (of mandating handlers) does *not* happen when loggers are configured programmatically. Should this be considered a bug? Worthy of opening a request on the tracker? And while I'm at it, a few other oddities/annoyances I noticed in logging: * have to specify the `root` logger in loggers/keys, even though it's mandatory to configure the root logger, or I get the following error:: Traceback (most recent call last): File "test.py", line 6, in logging.config.fileConfig('logging.conf') File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 82, in fileConfig _install_loggers(cp, handlers, disable_existing_loggers) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 183, in _install_loggers llist.remove("root") ValueError: list.remove(x): x not in list * the ``args`` option is required when defining a handler, even in the example above where the handler doesn't take any argument (mandatory ones, anyway) * Logger.log() doesn't take level names, only numerical levels, even after having called ``addLevelName``. This makes logging with custom levels much less clear as one has to write something along the lines of ``logging.log(100, 'Houston, we have a problem')`` instead of the clearer ``logging.log('PANTS_ON_FIRE', 'Houston, we have a problem')``. Note that since the introduction of _checkLevel fixing that is trivial: diff -r dafc54104884 Lib/logging/__init__.py --- a/Lib/logging/__init__.py Sun Jan 31 14:17:25 2010 +0100 +++ b/Lib/logging/__init__.py Mon Feb 01 22:21:03 2010 +0100 @@ -1146,13 +1146,14 @@ logger.log(level, "We have a %s", "mysterious problem", exc_info=1) """ - if not isinstance(level, int): + try: + rv = _checkLevel(level) + except (TypeError, ValueError): if raiseExceptions: - raise TypeError("level must be an integer") - else: - return - if self.isEnabledFor(level): - self._log(level, msg, args, **kwargs) + raise + + if self.isEnabledFor(rv): + self._log(rv, msg, args, **kwargs) def findCaller(self): """ From stefan_ml at behnel.de Tue Feb 2 02:35:13 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 02 Feb 2010 08:35:13 +0100 Subject: converting XML to hash/dict/CustomTreeCtrl In-Reply-To: References: Message-ID: <4b67d5b1$0$6564$9b4e6d93@newsspool4.arcor-online.net> Astan Chee, 01.02.2010 23:34: > I have xml files that I want to convert to a hash/dict and then further > placed in a wx CustomTreeCtrl based on the structure. The problem I am > having now is that the XML file is very unusual and there aren't any > unique identifiers to be put in a dict and because there are no unique > variables, finding the value of it from a CustromTreeCtrl is abit tricky. > I would appreciate any help or links to projects similar to this. What part of the structure and what information are you interested in? That will determine the key that you should use. Maybe storing more than one field as key is an option. Stefan > The XML file looks something like this: > > > kind="position"> > > This is the note on > calculation times > > > > 609.081574 > 2531.972081 > 65.119100 > > > 1772.011230 > > kind="timers"> > > 72.418861 > > > > 28.285192 > > > 0.000 > > > > 607.432373 > > > > > > > 4833280000 > > 4833280000 > > > 4182777856 > 4182777856 > > 1 > > 1943498 > 0 > > > > 1640100156 > 411307840 > > > 709596712 > 1406752 > > > 737720720 > 0 > > > 607.432373 > > > > 5164184694 > 2054715622 > > > > > > > From ashish.vyas at motorola.com Tue Feb 2 02:48:10 2010 From: ashish.vyas at motorola.com (VYAS ASHISH M-NTB837) Date: Tue, 2 Feb 2010 15:48:10 +0800 Subject: Python packet capture utility In-Reply-To: <717f2d32-df15-4acc-bc39-e9532d23a4b2@u18g2000prn.googlegroups.com> Message-ID: <7C57DB58C81FB64CA979EC6C4DB73E7A03F04217@ZMY16EXM67.ds.mot.com> Dear All I want to capture tcp packets in python. I need to do this on both Windows and Linux on python3.1 I came across the following: http://sourceforge.net/projects/pycap/ http://sourceforge.net/projects/pylibpcap/ http://code.google.com/p/pypcap/ http://oss.coresecurity.com/projects/pcapy.html I am not able to evaluate on my own. Which one should I pick up? Priority is python3.1 support on both windows and Linux. I don't have to do many/complex operations. If it is not so programmer friendly I am OK. Also let me know if 2to3 would help here if there is not python3 support. Regards Ashish From no.email at nospam.invalid Tue Feb 2 03:18:45 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 02 Feb 2010 00:18:45 -0800 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <7xr5p4yrru.fsf@ruckus.brouhaha.com> Nobody writes: > A better metric is whether using N features has O(N) complexity, or O(N^2) > (where you have to understand how each feature relates to each other > feature) or even O(2^N) (where you have to understand every possible > combination of interactions). M. Felleisen wrote a paper trying to formalize some metric on the expressive power of programming languages. I skimmed through it for about a minute and wasn't convinced, but it apparently has gathered some respect. I want to read it more carefully sometime: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4656 From fetchinson at googlemail.com Tue Feb 2 03:38:07 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 2 Feb 2010 09:38:07 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >>> Personally, I think it is a terribly idea to keep the source file and >>> byte code file in such radically different places. They should be kept >>> together. What you call "clutter" I call having the files that belong >>> together kept together. >> >> I see why you think so, it's reasonable, however there is compelling >> argument, I think, for the opposite view: namely to keep things >> separate. An average developer definitely wants easy access to .py >> files. However I see no good reason for having access to .pyc files. I >> for one have never inspected a .pyc file. Why would you want to have a >> .pyc file at hand? > > If you don't care about access to .pyc files, why do you care where they > are? If they are in a subdirectory module.pyr, then shrug and ignore the > subdirectory. > > If you (generic you) are one of those developers who don't care > about .pyc files, then when you are browsing your source directory and > see this: > > > module.py > module.pyc > > you just ignore the .pyc file. Or delete it, and Python will re-create it > as needed. So if you see > > module.pyr/ > > just ignore that as well. > > > >> If we don't really want to have .pyc files in convenient locations >> because we (almost) never want to access them really, then I'd say it's >> a good idea to keep them totally separate and so make don't get in the >> way. > > I like seeing them in the same place as the source file, because when I > start developing a module, I often end up renaming it multiple times > before it settles on a final name. When I rename or move it, I delete > the .pyc file, and that ensures that if I miss changing an import, and > try to import the old name, it will fail. > > By hiding the .pyc file elsewhere, it is easy to miss deleting one, and > then the import won't fail, it will succeed, but use the old, obsolete > byte code. Okay, I see your point but I think your argument about importing shows that python is doing something suboptimal because I have to worry about .pyc files. Ideally, I only would need to worry about python source files. There is now a chance to 'fix' (quotation marks because maybe there is nothing to fix, according to some) this issue and make all pyc files go away and having python magically doing the right thing. A central pyc repository would be something I was thinking about, but I admit it's a half baked or not even that, probably quarter baked idea. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From dickinsm at gmail.com Tue Feb 2 04:20:59 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 2 Feb 2010 01:20:59 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <05028e22-abed-41cc-a60a-cdc27f803a3a@a5g2000yqi.googlegroups.com> On Feb 2, 3:28?am, Steven D'Aprano wrote: > > There is no module numbers in the standard library, at least not in 2.5. It's new in 2.6 (and 3.0, I think; it's there in 3.1, anyway). It provides abstract base classes for numeric types; see the fractions module source for some of the ways it can be used. Here are the docs: http://docs.python.org/library/numbers.html and also PEP 3141, on which it's based: http://www.python.org/dev/peps/pep-3141/ -- Mark From waku at idi.ntnu.no Tue Feb 2 05:21:02 2010 From: waku at idi.ntnu.no (waku) Date: Tue, 2 Feb 2010 02:21:02 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> Message-ID: <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Steven D'Aprano wrote: > On Sat, 30 Jan 2010 16:58:34 +0000, tanix wrote: [...] > > The very idea of using a number of blanks to identify your block level > > is as insane as it gets. > > Not at all. People do it all the time. The very idea of expecting people > to count nested braces to identify block level is what is crazy, which is > why in languages with braces people still indent the blocks. for reading written code, it's surely helpful to have the code indented, though for *human* reading, the count of blanks seems rather inessential, as long as intended difference in indents is more pronounced than incidental difference between same-level lines. for writing new code, it's not necessarily that helpful to be *forced* to keep with strict indenting rules. in early development phases, code is often experimental, and parts of it may need to be blocked or unblocked as the codebase grows, and for experimentation, the need to carefully and consistently indent and de-indent large chunks of code can easily lead to a mess (blame it on the programmer, not the language, but still). yes, there are editors that help you indent chunks of code, but see below. there are languages where indentation can be either enforced and allow one to omit some syntactic nuissance like braces or begin-end clauses, or made optional, requiring other syntactic means for delimiting blocks etc. (consider f# with its #light declaration, for example.) [...] > In any case, if your IDE mixes tabs and spaces, your IDE is broken and > you should fix your tools rather than blame the language. as long as you are limited to your own code, sure. but if many work on the same bit, and use different editors and indentation policies, blanks-tabs indentation issues are not unlikely. you can have blanks converted to tabs and vice versa automatically, but that's clearly a nuisance. > > > > Braces is the most reliable way to identify blocks. > > Nonsense. For the compiler, both are equally reliable, and for the human > reader, indents beat braces easily. if blanks and tabs are mixed together as indentation, the setting of your ide can easily mess up the indentation, making the structure unclear. in some editors, you can have braces highlighted, so that it's even easier to see where a block ends or starts. and more advanced editors help one see the structure of the code, whereby both indentation and braces are made less important for the reader. but yes, indentation surely helps in reading the code. > > > > Sane compilers ignore blanks altogether. > > Really? So a "sane compiler" sees no difference between: > > for x in mylist: > > and > > forxinmylist: > > > I'm glad I don't have to program using a compiler you consider "sane". the point here was, i think, that blanks may have no syntactic meaning, though they can still be essential at the lexical level. your example targeted the lexical level, and that's rather irrelevant to the problem of syntactically meaningful indentation discussed here. vQ From jeanmichel at sequans.com Tue Feb 2 05:49:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 11:49:04 +0100 Subject: How to guard against bugs like this one? In-Reply-To: <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: <4B680320.1050803@sequans.com> Carl Banks wrote: > On Feb 1, 7:33 pm, Tim Chase wrote: > >> Stephen Hansen wrote: >> >>> First, I don't shadow built in modules. Its really not very hard to avoid. >>> >> Given the comprehensive nature of the batteries-included in >> Python, it's not as hard to accidentally shadow a built-in, >> unknown to you, but yet that is imported by a module you are >> using. The classic that's stung me enough times (and many others >> on c.l.p and other forums, as a quick google evidences) such that >> I *finally* remember: >> >> bash$ touch email.py >> bash$ python >> ... >> >>> import smtplib >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python2.5/smtplib.py", line 46, in >> import email.Utils >> ImportError: No module named Utils >> >> Using "email.py" is an innocuous name for a script/module you >> might want to do emailish things, and it's likely you'll use >> smtplib in the same code...and kablooie, things blow up even if >> your code doesn't reference or directly use the built-in email.py. >> > > > email.py is not an innocuous name, it's a generic name in a global > namespace, which is a Bad Thing. Plus what does a script or module > called "email.py" actually do? Send email? Parse email? "email" is > terrible name for a module and you deserve what you got for using it. > > Name your modules "send_email.py" or "sort_email.py" or if it's a > library module of related functions, "email_handling.py". Modules and > scripts do things (usually), they should be given action words as > names. > > > (**) Questionable though it be, if the Standard Library wants to use > an "innocuous" name, It can. > > > Carl Banks > That does not solve anything, if the smtplib follows your advice, then you'll be shadowing its send_email module. The only way to avoid collision would be to name your module __PDSFLSDF_send_email__13221sdfsdf__.py That way, the probabilty you'd shadow one package hidden module is below the probability that Misses Hilton ever says something relevant. However nobody wants to use such names. Stephen gave good advices in this thread that helps avoiding this issue. JM From mrkafk at gmail.com Tue Feb 2 06:20:34 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Feb 2010 12:20:34 +0100 Subject: unable to catch this exception Message-ID: Exception in thread Thread-9 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/local/lib/python2.6/threading.py", line 522, in __bootstrap_inner File "/var/www/html/cssh.py", line 875, in run File "/var/www/html/cssh.py", line 617, in ssh_connect : 'NoneType' object has no attribute 'BadAuthenticationType' This happens on interpreter shutdown, even though I do try to catch the AttributeError exception: try: fake = paramiko.BadAuthenticationType try: self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) loginsuccess = True except paramiko.BadAuthenticationType, e: # this is line 617 self.conerror = str(e) except paramiko.SSHException, e: self.conerror = str(e) except socket.timeout, e: self.conerror = str(e) except socket.error, e: self.conerror = str(e) except AttributeError: # this happens on interpreter shutdown self.conerror = 'shutdown' It's clear what happens: paramiko gets its attributes cleared or the module perhaps gets unloaded and as result "paramiko" label leads to None, which obviously has no attribute BadAuthenticationType. However, even though this is surrounded by try .. except AttributeError block, it evidently isn't catch. How to catch that exception? Or at least preven displaying this message? Regards, mk From louis.coilliot at gmail.com Tue Feb 2 06:30:44 2010 From: louis.coilliot at gmail.com (lofic) Date: Tue, 2 Feb 2010 03:30:44 -0800 (PST) Subject: threading+popen2 hang Message-ID: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> Hello, I've seen many messages and bug reports on popen2 about pipes, buffer size problems, sub-processes not properly closed, race conditions, popen2 not being thread safe... But I still can't figure what applies to my case. This piece of code: #!/usr/bin/python import threading import popen2 class MyThread ( threading.Thread ): def run ( self ): #popenChild = popen2.Popen3("cat /etc/passwd") #popenChild = popen2.Popen3("/usr/bin/iostat -V") popenChild = popen2.Popen3("/usr/bin/iostat -k -x 1 2") popenChild.wait() print 'Bye' MyThread().start() Works fine on RHEL5/python 2.4.3 Hangs on RHEL4/python 2.3.4 I presume it hangs on wait(). It does not hang with: popenChild = popen2.Popen3("/usr/bin/iostat -V") # short output popenChild = popen2.Popen3("cat /etc/passwd") # long output It does not hang outside of a thread: #!/usr/bin/python import popen2 popenChild = popen2.Popen3("/usr/bin/iostat -k -x 1 2") #print popenChild.fromchild.readlines() popenChild.wait() print 'Bye' Could someone explain this to me ? Thanks in advance. Louis Coilliot From jeanmichel at sequans.com Tue Feb 2 07:26:32 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 13:26:32 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: References: Message-ID: <4B6819F8.8080004@sequans.com> Masklinn wrote: > When trying to load the following config file, I get an error ``ConfigParser.NoOptionError: No option 'handlers' in section: 'logger_0'`` (in both Python 2.6.4 and Python 3.1.1 on OSX, obviously ConfigParser is spelled configparser in 3.1): > > [loggers] > keys=root,0 > [handlers] > keys=console > [formatters] > keys=simple > [logger_root] > handlers=console > [logger_0] > level=DEBUG > qualname=0 > [handler_console] > class=StreamHandler > formatter=simple > args=() > [formatter_simple] > format=%(asctime)s:%(levelname)-8s:%(name)s::%(message)s > > the goal is simply to have a logging level different on ``0`` than it is on ``root``, but to get it I have to include a handler on ``0`` and stop propagation (or messages are displayed on both root and 0). > > Do note that this behavior (of mandating handlers) does *not* happen when loggers are configured programmatically. > > Should this be considered a bug? Worthy of opening a request on the tracker? > > And while I'm at it, a few other oddities/annoyances I noticed in logging: > > * have to specify the `root` logger in loggers/keys, even though it's mandatory to configure the root logger, or I get the following error:: > > Traceback (most recent call last): > File "test.py", line 6, in > logging.config.fileConfig('logging.conf') > File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 82, in fileConfig > _install_loggers(cp, handlers, disable_existing_loggers) > File "/opt/local/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/logging/config.py", line 183, in _install_loggers > llist.remove("root") > ValueError: list.remove(x): x not in list > > * the ``args`` option is required when defining a handler, even in the example above where the handler doesn't take any argument (mandatory ones, anyway) > > * Logger.log() doesn't take level names, only numerical levels, even after having called ``addLevelName``. This makes logging with custom levels much less clear as one has to write something along the lines of ``logging.log(100, 'Houston, we have a problem')`` instead of the clearer ``logging.log('PANTS_ON_FIRE', 'Houston, we have a problem')``. Note that since the introduction of _checkLevel fixing that is trivial: > > To add a custom level, I would proceed that way: logging.ALERT = 45 logging.addLevelName(logging.ALERT, 'ALERT !!') logging.getLogger().log(logging.ALERT, 'test') Passing a string to the log method as you did is incorrect. Regarding your first point, I guess it's anti pattern. One way to do it: 1/ Configure the root logger with the lowest value 0, so the root logger does not filter any level. 2/ Configure each of your logger with the correct level That way you can configure your '0' logger as you (badly :o)) named it with one level, and configure a potential '1' logger with another level. Don't bother with propagation. That way you won't need to duplicate your handlers on every logger. JM From clp2 at rebertia.com Tue Feb 2 07:32:08 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Feb 2010 04:32:08 -0800 Subject: unable to catch this exception In-Reply-To: References: Message-ID: <50697b2c1002020432u718b018fj9abef3c1534a8f9@mail.gmail.com> On Tue, Feb 2, 2010 at 3:20 AM, mk wrote: > Exception in thread Thread-9 (most likely raised during interpreter > shutdown): > Traceback (most recent call last): > ?File "/usr/local/lib/python2.6/threading.py", line 522, in > __bootstrap_inner > ?File "/var/www/html/cssh.py", line 875, in run > ?File "/var/www/html/cssh.py", line 617, in ssh_connect > : 'NoneType' object has no attribute > 'BadAuthenticationType' > > > This happens on interpreter shutdown, even though I do try to catch the > AttributeError exception: > > try: > ? ?fake = paramiko.BadAuthenticationType > ? ?try: > ? ? ? ?self.conobj.connect(self.ip, username=self.username, > key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) > ? ? ? ?loginsuccess = True > ? ?except paramiko.BadAuthenticationType, e: # this is line 617 > ? ? ? ?self.conerror = str(e) > ? ?except paramiko.SSHException, e: > ? ? ? ?self.conerror = str(e) > ? ?except socket.timeout, e: > ? ? ? ?self.conerror = str(e) > ? ?except socket.error, e: > ? ? ? ?self.conerror = str(e) > except AttributeError: > ? ?# this happens on interpreter shutdown > ? ?self.conerror = 'shutdown' > > > It's clear what happens: paramiko gets its attributes cleared or the module > perhaps gets unloaded and as result "paramiko" label leads to None, which > obviously has no attribute BadAuthenticationType. > > However, even though this is surrounded by try .. except AttributeError > block, it evidently isn't catch. How to catch that exception? Or at least > preven displaying this message? Let's see if psychic debugging works...at 4 am... Pure conjecture: Do you have something like the following elsewhere in your code?: try: #code except SomeError, AttributeError: #code For why this causes problems, consider: except SomeError, e: vs. except SomeError, SomeOtherError: Example: try: raise IndexError except IndexError, IOError: pass print repr(IOError) #==> IndexError() Hence, in your case, `AttributeError` may no longer refer to AttributeError. You can check this by adding a `print repr(AttributeError)` at the right place in your code. I further conjecture that pyflakes/pychecker/etc. might issue a warning about the offending bit of code. "Third Option" solution: Since you take the same action no matter the exception's type, have you considered simplifying your code to: fake = paramiko.BadAuthenticationType try: self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) loginsuccess = True except Exception, e: self.conerror = str(e) Cheers, Chris -- http://tvtropes.org/pmwiki/pmwiki.php/Main/TakeAThirdOption http://blog.rebertia.com From mrkafk at gmail.com Tue Feb 2 08:24:46 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Feb 2010 14:24:46 +0100 Subject: passing string for editing in input() Message-ID: Hello, Is there an easy way to get an editing (readline) in Python that would contain string for editing and would not just be empty? I googled but found nothing. Regards, mk From clp2 at rebertia.com Tue Feb 2 08:29:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 2 Feb 2010 05:29:10 -0800 Subject: passing string for editing in input() In-Reply-To: References: Message-ID: <50697b2c1002020529x2f97d03fxe4b1dc79539f2aaa@mail.gmail.com> On Tue, Feb 2, 2010 at 5:24 AM, mk wrote: > Hello, > > Is there an easy way to get an editing (readline) in Python that would > contain string for editing and would not just be empty? > > I googled but found nothing. Er...: http://docs.python.org/library/readline.html It's the third hit for "python readline". Actually reading the page, sounds like you want readline.insert_text() specifically. Cheers, Chris -- Satan, thy name is MMW http://blog.rebertia.com From solipsis at pitrou.net Tue Feb 2 09:05:02 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Tue, 2 Feb 2010 14:05:02 +0000 (UTC) Subject: recv_into(bytearray) complains about a "pinned buffer" References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> <4B675FE2.4090404@v.loewis.de> Message-ID: Le Tue, 02 Feb 2010 00:12:34 +0100, Martin v. Loewis a ?crit?: >> recv_into() should simply be fixed to use the new buffer API, as it >> does in 3.x. > > I don't think that's the full solution. The array module should also > implement the new buffer API, so that it would also fail with the old > recv_into. There was a patch for this in http://bugs.python.org/issue6071 , but the bug was closed when hashlib was "fixed". From __peter__ at web.de Tue Feb 2 09:12:59 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 02 Feb 2010 15:12:59 +0100 Subject: passing string for editing in input() References: Message-ID: mk wrote: > Is there an easy way to get an editing (readline) in Python that would > contain string for editing and would not just be empty? http://mail.python.org/pipermail/python-list/2009-June/1209309.html Peter From no.email at please.post Tue Feb 2 09:13:19 2010 From: no.email at please.post (kj) Date: Tue, 2 Feb 2010 14:13:19 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: Let me preface everything by thanking you and all those who replied for their comments. I have only one follow-up question (or rather, set of related questions) that I'm very keen about, plus a bit of a vent at the end. In Steven D'Aprano writes: >As for fixing it, unfortunately it's not quite so simple to fix without >breaking backwards-compatibility. The opportunity to do so for Python 3.0 >was missed. This last point is to me the most befuddling of all. Does anyone know why this opportunity was missed for 3.0? Anyone out there with the inside scoop on this? Was the fixing of this problem discussed in some PEP or some mailing list thread? (I've tried Googling this but did not hit on the right keywords to bring up the deliberations I'm looking for.) ~k [NB: as I said before, what follows begins to slide into a vent, and is quite unimportant; I've left it, for whatever grain of truth it may contain, as an grossly overgrown PS; feel free to ignore it, I'm *by far* most interested in the question stated in the paragraph right above, because it will give me, I hope, a better sense of where the biggest obstacles to fixing this problem lie.] P.S. Yes, I see the backwards-compatibility problem, but that's what rolling out a whole new versions is good for; it's a bit of a fresh start. I remember hearing GvR's Google Talk on the coming Python 3, which was still in the works then, and being struck by the sheer *modesty* of the proposed changes (while the developers of the mythical Perl6 seemed to be on a quest for transcendence to a Higher Plane of Programming, as they still are). In particular the business with print -> print() seemed truly bizarre to me: this is a change that will break a *huge* volume of code, and yet, judging by the rationale given for it, the change solves what are, IMHO, a relatively minor annoyances. Python's old print statement is, I think, at most a tiny little zit invisible to all but those obsessed with absolute perfection. And I can't imagine that whatever would be required to fix Python's import system could break more code than redefining the rules for a workhorse like print. In contrast, the Python import problem is a ticking bomb potentially affecting all code that imports other modules. All that needs to happen is that, in a future release of Python, some new standard module emerges (like numbers.py emerged in 2.6), and this module is imported by some module your code imports. Boom! Note that it was only coincidental that the bug I reported in this thread occurred in a script I wrote recently. I could have written both scripts before 2.6 was released, and the new numbers.py along with it; barring the uncanny clairvoyance of some responders, there would have been, at the time, absolutely no plausible reason for not naming one of the two scripts numbers.py. To the argument that the import system can't be easily fixed because it breaks existing code, one can reply that the *current* import system already breaks existing code, as illustrated by the example I've given in this thread: this could have easily been old pre-2.6 code that got broken just because Python decided to add numbers.py to the distribution. (Yes, Python can't guarantee that the names of new standard modules won't clash with the names of existing local modules, but this is true for Perl as well, and due to Perl's module import scheme (and naming conventions), a scenario like the one I presented in this thread would have been astronomically improbable. The Perl example shows that the design of the module import scheme and naming conventions for standard modules can go a long way to minimize the consequences of this unavoidable potential for future name clashes.) From mrkafk at gmail.com Tue Feb 2 09:37:10 2010 From: mrkafk at gmail.com (mk) Date: Tue, 02 Feb 2010 15:37:10 +0100 Subject: passing string for editing in input() In-Reply-To: References: Message-ID: Peter Otten wrote: > mk wrote: > >> Is there an easy way to get an editing (readline) in Python that would >> contain string for editing and would not just be empty? > > http://mail.python.org/pipermail/python-list/2009-June/1209309.html > > Peter Thanks a lot! Just what I needed. Regards, mk From gerald.britton at gmail.com Tue Feb 2 09:47:30 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 2 Feb 2010 09:47:30 -0500 Subject: Iterating over a function call In-Reply-To: References: <5d1a32001002010850n72a70455pb9ed77e6ff6366eb@mail.gmail.com> Message-ID: <5d1a32001002020647q29506c30s46ac98accc6098ca@mail.gmail.com> [snip] >> 2. side effect of (maybe) leaking the iterator variable "value" into >> the code following the loop (if the iterator is not empty). > > So? it is sometime useful. Except that you can't guarantee that it will be set since the for loop will not execute if the iterable is empty. >> >> I can take care of 2 by explicitly deleting the variable at the end: >> >> ? ?del value >> >> but I'd probably forget to do that sometimes. > > So? If having 'value' bound breaks your subsequent code, I consider it > buggy. Quite so. I just like to eliminate the possibility up front. If 'value' is never bound, the the bug will show up sooner. -- Gerald Britton From invalid at invalid.invalid Tue Feb 2 10:00:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Feb 2010 15:00:28 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: On 2010-02-02, Roy Smith wrote: > In article , kj > wrote: > >> Through a *lot* of trial an error I finally discovered that the >> root cause of the problem was the fact that, in the same directory >> as buggy.py, there is *another* innocuous little script, totally >> unrelated, whose name happens to be numbers.py. >> [...] >> It turns out that buggy.py imports psycopg2, as you can see, and >> apparently psycopg2 (or something imported by psycopg2) tries to >> import some standard Python module called numbers; instead it ends >> up importing the innocent myscript/numbers.py, resulting in *absolute >> mayhem*. > > I feel your pain, but this is not a Python problem, per-se. I think it is. There should be different syntax to import from "standard" places and from "current directory". Similar to the difference between "foo.h" and in cpp. > The general > pattern is: > > 1) You have something which refers to a resource by name. > > 2) There is a sequence of places which are searched for this > name. Searching the current directory by default is the problem. Nobody in their right mind has "." in the shell PATH and IMO it shouldn't be in Python's import path either. Even those wreckless souls who do put "." in their path put it at the end so they don't accidentally override system commands. -- Grant Edwards grante Yow! So this is what it at feels like to be potato visi.com salad From invalid at invalid.invalid Tue Feb 2 10:09:26 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 2 Feb 2010 15:09:26 +0000 (UTC) Subject: Python packet capture utility References: Message-ID: On 2010-02-02, VYAS ASHISH M-NTB837 wrote: > > Dear All > > I want to capture tcp packets in python. I need to do this on both > Windows and Linux on python3.1 > > I came across the following: > http://sourceforge.net/projects/pycap/ > http://sourceforge.net/projects/pylibpcap/ > http://code.google.com/p/pypcap/ > http://oss.coresecurity.com/projects/pcapy.html > > > I am not able to evaluate on my own. And we're supposed to evaluate them for you? pycap: last release 5/2003. pylibpcap: last release 5/2008 pycap: last release 1/2007 pcapy: last release 3/2007 > Which one should I pick up? I'd start with the newest one. It's the one I use, and it works fine for me. > Priority is python3.1 support on both windows and Linux. I don't think any of them support 3.1. > I don't have to do many/complex operations. If it is not so > programmer friendly I am OK. > > Also let me know if 2to3 would help here if there is not > python3 support. I'f you're not expereienced porting libraries from 2.4 to 3.1, then you shouldn't be using 3.1. -- Grant Edwards grante Yow! Did you move a lot of at KOREAN STEAK KNIVES this visi.com trip, Dingy? From apt.shansen at gmail.com Tue Feb 2 10:12:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 2 Feb 2010 07:12:02 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7a9c25c21002020712h23fedd3g6e97368413633674@mail.gmail.com> On Tue, Feb 2, 2010 at 6:13 AM, kj wrote: > In Steven > D'Aprano writes: > > >As for fixing it, unfortunately it's not quite so simple to fix without > >breaking backwards-compatibility. The opportunity to do so for Python 3.0 > >was missed. > > This last point is to me the most befuddling of all. Does anyone > know why this opportunity was missed for 3.0? Anyone out there > with the inside scoop on this? Was the fixing of this problem > discussed in some PEP or some mailing list thread? (I've tried > Googling this but did not hit on the right keywords to bring up > the deliberations I'm looking for.) > The problem with "fixing" the import system is that touching it in any way potentially breaks *vast* volumes of code that works just right, right now in any version of Python. It's not even something you can easily test: there's a lot of edge-cases supporting various features that have been added over the years. A pure-python import mechanism with a set of test-cases to "prove" it reliably mimic'd the existing mechanism wasn't even complete by the time Python3 came out, without that, any changes to "fix" Python3+'s import system would just be a shot in the dark. And there'd be no telling just /what/ it would break if you start changing these very old import semantics. > P.S. Yes, I see the backwards-compatibility problem, but that's > what rolling out a whole new versions is good for; it's a bit of > a fresh start. I remember hearing GvR's Google Talk on the coming > Python 3, which was still in the works then, and being struck by > the sheer *modesty* of the proposed changes (while the developers > of the mythical Perl6 seemed to be on a quest for transcendence to > a Higher Plane of Programming, as they still are). Yes, it was a relatively modest upgrade, thankfully so. We actually have our fixed language, and Perl6 is coming on some point on the horizon. Python3 allowed backwards incompatible changes, but they still needed to have a justification to them: and more importantly, they usually needed to change from one well-defined state to a new, 'cleaner' well-defined state, so they could be automatically corrected or at least easily found. The Bytes/Unicode situation is one case where there wasn't a well-defined state you can convert from, and so with Python3, every single string you really need to look at and decide, "Should this have been bytes, or characters?". Having to ask that question for every string is a significant burden, to expect someone to have to ask the same sort of question for every single import is asking -way- too much for people porting to Python 3. Py3k's adoption is a slow, uphill process-- no one expected (from my reading at least)-- it to take less then years and multiple 3.x iterations before people would /really/ significantly start using it. There's too many third party modules people depend on and they have to slowly be converted. They're being converted, and IMHO there's steadily growing momentum on this (albeit not huge momentum), but had they messed with the import semantics-- this would be /way/ more difficult, and you might end up with a DOA project. > In particular > the business with print -> print() seemed truly bizarre to me: this > is a change that will break a *huge* volume of code, and yet, > judging by the rationale given for it, the change solves what are, > IMHO, a relatively minor annoyances. Python's old print statement > is, I think, at most a tiny little zit invisible to all but those > obsessed with absolute perfection. You have a very strange perception of huge. For one thing, every single use of print() can be converted -automatically-: the rules of this change are very clear. The print statement was a bizarre sort of wart (look at >>!) and fixing it is easy. Further, *huge* volume of code-- /really/?! In my experience, print isn't really all /that/ common after you get out of the tutorial and start doing real code. If you're doing lots of shell scripting maybe that's not the case: but for any sort of server-daemon-process sort of apps, print is utterly unacceptable. I use the logging module. For GUI apps, same. But for those times when you use print.. its /really easy/ to fix. And I can't imagine that whatever > would be required to fix Python's import system could break more > code than redefining the rules for a workhorse like print. > Your imagination is lacking here then: virtually every single bit of Python code uses import, and messing with it can have wide implications that you can't even /define/ ahead of time. As such you can't write a guide, a 2to3 fixer, or a HOWTO to tell people: hey, this is how you used to do things in Python2, this is how you do them in Python3. Having them mess with the import machinery would be throwing every Py3 developer under the bus, saying, "Well, just run it. Fix whatever errors happen." > In contrast, the Python import problem is a ticking bomb potentially > affecting all code that imports other modules. All that needs to > happen is that, in a future release of Python, some new standard > module emerges (like numbers.py emerged in 2.6), and this module > is imported by some module your code imports. Boom! Note that it > was only coincidental that the bug I reported in this thread occurred > in a script I wrote recently. I could have written both scripts > before 2.6 was released, and the new numbers.py along with it; > barring the uncanny clairvoyance of some responders, there would > have been, at the time, absolutely no plausible reason for not > naming one of the two scripts numbers.py. > This is drifting into hyperbole; yes, Python's flat import namespace isn't ideal, yes, it can mean that when a new version is released you may shadow something you didn't before, yes, that can cause code to break. Its really, really, really not anything like as bad as you're making it out to be. Your bomb can be averted via: - Don't use relative imports. - Don't structure your code and environment such that your libs and/or scripts end up living in the global namespace if you want to be future-proof. - If you didn't future-proof your code, then check What's New on new versions of Python. There, time bomb disarmed. To the argument that the import system can't be easily fixed because > it breaks existing code, one can reply that the *current* import > system already breaks existing code, as illustrated by the example > I've given in this thread: this could have easily been old pre-2.6 > code that got broken just because Python decided to add numbers.py > to the distribution. Yes, one can make that argument, but it would be specious. Messing with the import system -would- have broken code, and done so in a way which can not be easily or clearly identified by looking at code directly, as you wouldn't know "break" until you somehow took the /entire/ layout of the system into account, which is infeasible. The current import system -may- break code, if someone writes their code in such a way, structures their code in such a way, and Python happens to add a new item to its standard library which causes that code to now shadow a standard module. The former case, 'change the import system', requires someone look at every single import, evaluate that import in the full context of the environment, and determine if its working as intended or not. The latter case, 'leave the non-ideal import system in place', requires someone look at imports of top-level modules, and ensure that they don't shadow built-ins. You don't need to know where all the sys.path items are, you don't need to know if you're importing from a zip file, or anything like that. You just need to see if your top-level / relative import is shadowing a new standard library module or not. Yes, the latter case means that if you are supporting new Python versions that come out, you'll have to make that evaluation with each one if you decide not to code and structure your code in such a way that it is future-proof. > (Yes, Python can't guarantee that the names > of new standard modules won't clash with the names of existing > local modules, but this is true for Perl as well, and due to Perl's > module import scheme (and naming conventions), a scenario like the > one I presented in this thread would have been astronomically > improbable. The Perl example shows that the design of the module > import scheme and naming conventions for standard modules can go > a long way to minimize the consequences of this unavoidable potential > for future name clashes.) > Again: It is very, very avoidable. I know, cuz I've sorta been avoiding it easily and successfully for years now :P --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From bartc at freeuk.com Tue Feb 2 10:23:37 2010 From: bartc at freeuk.com (bartc) Date: Tue, 02 Feb 2010 15:23:37 GMT Subject: Python and Ruby In-Reply-To: <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: Jonathan Gardner wrote: > One of the bad things with languages like perl and Ruby that call > without parentheses is that getting a function ref is not obvious. You > need even more syntax to do so. In perl: > > foo(); # Call 'foo' with no args. > $bar = foo; # Call 'foo; with no args, assign to '$bar' > $bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > # By the way, this '&' is not the bitwise-and '&'!!!! > $bar->() # Call whatever '$bar' is pointing at with no args > > Compare with python: > > foo() # Call 'foo' with no args. > bar = foo() # 'bar' is now pointing to whatever 'foo()' returned > bar = foo # 'bar' is now pointing to the same thing 'foo' points to > bar() # Call 'bar' with no args > > One is simple, consistent, and easy to explain. The other one requires > the introduction of advanced syntax and an entirely new syntax to make > function calls with references. If you get rid of the syntax specific to Perl, then having to explicitly obtain a function reference, or to dereference the result, is not such a big deal: foo # Call 'foo' with no args. bar = foo # Call 'foo; with no args, assign to 'bar' bar = &foo # Don't call 'foo', but assign a pointer to it to 'bar' bar^ # Call whatever 'bar' is pointing at with no args (Here I use ^ instead of -> to dereference.) Compared with Python, it saves 3 lots of (), but needs & and ^ added. Still a net saving. > One of the bad things with languages like perl and Ruby that call > without parentheses is that getting a function ref is not obvious. I'd say that having this "&" symbol in front of "foo" makes it more obvious than just foo by itself. But I agree not quite as clean. Another thing is that you have to know whether "bar" is a function, or a function ref, and use the appropriate syntax. Sometimes this is helpful, sometimes not. -- Bartc From masklinn at masklinn.net Tue Feb 2 11:28:52 2010 From: masklinn at masklinn.net (Masklinn) Date: Tue, 2 Feb 2010 17:28:52 +0100 Subject: Logging oddity: handlers mandatory in every single logger? Message-ID: Jean-Michel Pichavant wrote: >To add a custom level, I would proceed that way: > >logging.ALERT = 45 >logging.addLevelName(logging.ALERT, 'ALERT !!') >logging.getLogger().log(logging.ALERT, 'test') > >Passing a string to the log method as you did is incorrect. I know it's currently incorrect. My point was more along the line that there was *no reason* for it to be incorrect. logging already contains all the tools for log('PANTS_ON_FIRE') to be allowed >Regarding your first point, I guess it's anti pattern. One way to do it: >1/ Configure the root logger with the lowest value 0, so the root logger >does not filter any level. >2/ Configure each of your logger with the correct level > >That way you can configure your '0' logger as you (badly :o)) named it >with one level, and configure a potential '1' logger with another level. >Don't bother with propagation. That way you won't need to duplicate your >handlers on every logger. re logger 0, no need for complex name for a test case (and it allowed me to create easy-to-remember 0.1 and 0.1.2 if needed) Re your answer, from what I understand you want the root logger to NOTSET and then each child logger with its correct level? But that's not a solution, each and every level will *still* require a handler explicitly configured on it. That's in fact very much my issue: logging refuses that a logger be handler-less in a config file, it's mandatory to configure a handler any time a logger is configured. From edreamleo at gmail.com Tue Feb 2 11:36:24 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Tue, 02 Feb 2010 10:36:24 -0600 Subject: ANN: Leo 4.7 b3 released Message-ID: Leo 4.7 beta 3 February 2, 2009 Leo 4.7 beta 3 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7 beta 3 fixes all known serious bugs in Leo. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - @auto-rst now works much more reliably reliably. - Leo no longer @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Edward K. Ream Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From peloko45 at gmail.com Tue Feb 2 11:42:12 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 2 Feb 2010 08:42:12 -0800 (PST) Subject: No return to the parent function Message-ID: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> I've a main function called i.e. *foo()* which has a block of code that is repetead several times (for the error catching code and error reporting), but that code has a return to exit of *foo()* ----------- foo(): ... if self.background: _log.exception(str(error)) return ReturnCode.ERROR, None else: raise NameError(error) ----------- So I would tu put that code block into a separated function (*throw() *), but the problem is that it returns to the parent function (foo()). How to solve it? From jeanmichel at sequans.com Tue Feb 2 11:52:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 17:52:48 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: References: Message-ID: <4B685860.4000903@sequans.com> Masklinn wrote: > Jean-Michel Pichavant wrote: > >> To add a custom level, I would proceed that way: >> >> logging.ALERT = 45 >> logging.addLevelName(logging.ALERT, 'ALERT !!') >> logging.getLogger().log(logging.ALERT, 'test') >> >> Passing a string to the log method as you did is incorrect. >> > > I know it's currently incorrect. My point was more along the line that there was *no reason* for it to be incorrect. logging already contains all the tools for log('PANTS_ON_FIRE') to be allowed > The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. > >> Regarding your first point, I guess it's anti pattern. One way to do it: >> 1/ Configure the root logger with the lowest value 0, so the root logger >> does not filter any level. >> 2/ Configure each of your logger with the correct level >> >> That way you can configure your '0' logger as you (badly :o)) named it >> with one level, and configure a potential '1' logger with another level. >> Don't bother with propagation. That way you won't need to duplicate your >> handlers on every logger. >> > > re logger 0, no need for complex name for a test case (and it allowed me to create easy-to-remember 0.1 and 0.1.2 if needed) > > Re your answer, from what I understand you want the root logger to NOTSET and then each child logger with its correct level? But that's not a solution, each and every level will *still* require a handler explicitly configured on it. That's in fact very much my issue: logging refuses that a logger be handler-less in a config file, it's mandatory to configure a handler any time a logger is configured. > the field handlers must be defined even if empty. [loggers] keys=root,0,1 [handlers] keys=console [formatters] keys=simple [logger_root] level=DEBUG handlers=console [logger_1] level=INFO qualname=1 handlers= [logger_0] level=DEBUG qualname=0 handlers= [handler_console] class=StreamHandler formatter=simple args=() [formatter_simple] format=%(asctime)s:%(levelname)-8s:%(name)s::%(message)s import logging; import logging.config logging.config.fileConfig("log.config") l1 = logging.getLogger("1") l0 = logging.getLogger("0") l1.debug('I am l1') ... l0.debug('I am l0') ... 2010-02-02 17:48:55,710:DEBUG :0::I am l0 JM From arnodel at googlemail.com Tue Feb 2 11:55:58 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 02 Feb 2010 16:55:58 +0000 Subject: No return to the parent function References: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> Message-ID: Joan Miller writes: > I've a main function called i.e. *foo()* which has a block of code > that is repetead several times (for the error catching code and error > reporting), but that code has a return to exit of *foo()* > > ----------- > foo(): > ... > if self.background: > _log.exception(str(error)) > return ReturnCode.ERROR, None > else: > raise NameError(error) > > ----------- > > So I would tu put that code block into a separated function (*throw() > *), but the problem is that it returns to the parent function (foo()). > How to solve it? If I understand correctly, you can simply do this: def throw(...): if ...: ... return ... else: raise ... def foo(): ... return throw(...) HTH I.e. if throw returns something, foo returns it as well. If throw raises an exception, it will go through foo. Is this what you want? -- Arnaud From peloko45 at gmail.com Tue Feb 2 12:00:45 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 2 Feb 2010 09:00:45 -0800 (PST) Subject: No return to the parent function References: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> Message-ID: <4aded884-b81e-45d6-be08-39e064fbe184@m16g2000yqc.googlegroups.com> On 2 feb, 16:55, Arnaud Delobelle wrote: > Joan Miller writes: > > I've a main function called i.e. *foo()* which has a block of code > > that is repetead several times (for the error catching code and error > > reporting), but that code has a return to exit of *foo()* > > > ----------- > > foo(): > > ? ... > > ? ? if self.background: > > ? ? ? ? _log.exception(str(error)) > > ? ? ? ? return ReturnCode.ERROR, None > > ? ? else: > > ? ? ? ? raise NameError(error) > > > ----------- > > > So I would tu put that code block into a separated function (*throw() > > *), but the problem is that it returns to the parent function (foo()). > > How to solve it? > > If I understand correctly, you can simply do this: > > def throw(...): > ? ? if ...: > ? ? ? ? ... > ? ? ? ? return ... > ? ? else: > ? ? ? ? raise ... > > def foo(): > ? ? ... > ? ? return throw(...) > > HTH > > I.e. if throw returns something, foo returns it as well. ?If throw > raises an exception, it will go through foo. ?Is this what you want? > > -- > Arnaud Yes, that is it. It was more simple that I had thinked, thanks! From nobody at nowhere.com Tue Feb 2 12:02:10 2010 From: nobody at nowhere.com (Nobody) Date: Tue, 02 Feb 2010 17:02:10 +0000 Subject: How to guard against bugs like this one? References: Message-ID: On Tue, 02 Feb 2010 15:00:28 +0000, Grant Edwards wrote: >>> It turns out that buggy.py imports psycopg2, as you can see, and >>> apparently psycopg2 (or something imported by psycopg2) tries to >>> import some standard Python module called numbers; instead it ends >>> up importing the innocent myscript/numbers.py, resulting in *absolute >>> mayhem*. >> >> I feel your pain, but this is not a Python problem, per-se. > > I think it is. I agree. > There should be different syntax to import from > "standard" places and from "current directory". Similar to the > difference between "foo.h" and in cpp. I don't know if that's necessary. Only supporting the "foo.h" case would work fine if Python behaved like gcc, i.e. if the "current directory" referred to the directory contain the file performing the import rather than in the process' CWD. As it stands, imports are dynamically scoped, when they should be lexically scoped. >> The general >> pattern is: >> >> 1) You have something which refers to a resource by name. >> >> 2) There is a sequence of places which are searched for this >> name. > > Searching the current directory by default is the problem. > Nobody in their right mind has "." in the shell PATH and IMO it > shouldn't be in Python's import path either. Even those > wreckless souls who do put "." in their path put it at the end > so they don't accidentally override system commands. Except, what should be happening here is that it should be searching the directory containing the file performing the import *first*. If foo.py contains "import bar", and there's a bar.py in the same directory as foo.py, that's the one it should be using. The existing behaviour is simply wrong, and there's no excuse for it ("but it's easier to implement" isn't a legitimate argument). The only situation where the process' CWD should be used is for an import statement in a non-file source (i.e. stdin or the argument to the -c switch). From python at mrabarnett.plus.com Tue Feb 2 12:08:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 02 Feb 2010 17:08:54 +0000 Subject: No return to the parent function In-Reply-To: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> References: <69ee6209-074f-4d2a-b6e6-698bb63f3f88@n7g2000yqb.googlegroups.com> Message-ID: <4B685C26.3060601@mrabarnett.plus.com> Joan Miller wrote: > I've a main function called i.e. *foo()* which has a block of code > that is repetead several times (for the error catching code and error > reporting), but that code has a return to exit of *foo()* > > ----------- > foo(): > ... > if self.background: > _log.exception(str(error)) > return ReturnCode.ERROR, None > else: > raise NameError(error) > > ----------- > > So I would tu put that code block into a separated function (*throw() > *), but the problem is that it returns to the parent function (foo()). > How to solve it? Call it in a return statement. From alfps at start.no Tue Feb 2 12:20:41 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Feb 2010 18:20:41 +0100 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: * Nobody: > On Tue, 02 Feb 2010 15:00:28 +0000, Grant Edwards wrote: > >>>> It turns out that buggy.py imports psycopg2, as you can see, and >>>> apparently psycopg2 (or something imported by psycopg2) tries to >>>> import some standard Python module called numbers; instead it ends >>>> up importing the innocent myscript/numbers.py, resulting in *absolute >>>> mayhem*. >>> I feel your pain, but this is not a Python problem, per-se. >> I think it is. > > I agree. > >> There should be different syntax to import from >> "standard" places and from "current directory". Similar to the >> difference between "foo.h" and in cpp. > > I don't know if that's necessary. Only supporting the "foo.h" case would > work fine if Python behaved like gcc, i.e. if the "current directory" > referred to the directory contain the file performing the import rather > than in the process' CWD. > > As it stands, imports are dynamically scoped, when they should be > lexically scoped. > >>> The general >>> pattern is: >>> >>> 1) You have something which refers to a resource by name. >>> >>> 2) There is a sequence of places which are searched for this >>> name. >> Searching the current directory by default is the problem. >> Nobody in their right mind has "." in the shell PATH and IMO it >> shouldn't be in Python's import path either. Even those >> wreckless souls who do put "." in their path put it at the end >> so they don't accidentally override system commands. > > Except, what should be happening here is that it should be searching the > directory containing the file performing the import *first*. If foo.py > contains "import bar", and there's a bar.py in the same directory as > foo.py, that's the one it should be using. > > The existing behaviour is simply wrong, and there's no excuse for it > ("but it's easier to implement" isn't a legitimate argument). +1 > The only situation where the process' CWD should be used is for an import > statement in a non-file source (i.e. stdin or the argument to the -c > switch). Hm, not sure about that last. Cheers, - Alf From tjreedy at udel.edu Tue Feb 2 13:29:54 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Feb 2010 13:29:54 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: On 2/2/2010 9:13 AM, kj wrote: >> As for fixing it, unfortunately it's not quite so simple to fix without >> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >> was missed. > > This last point is to me the most befuddling of all. Does anyone > know why this opportunity was missed for 3.0? Anyone out there > with the inside scoop on this? Was the fixing of this problem > discussed in some PEP or some mailing list thread? (I've tried > Googling this but did not hit on the right keywords to bring up > the deliberations I'm looking for.) There was a proposal to put the whole stdlib into a gigantic package, so that import itertools would become, for instance import std.itertools. Guido rejected that. I believe he both did not like it and was concerned about making upgrade to 3.x even harder. The discussion was probably on the now closed py3k list. Terry Jan Reedy From tinnews at isbd.co.uk Tue Feb 2 13:32:46 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Tue, 2 Feb 2010 18:32:46 +0000 Subject: What's this vText() annotation mean? Message-ID: What does this vText() annotation mean in a returned list:- [['Apr 19', vText(u'PAYE'), ''], ['Mar 31', vText(u'VAT'), ''], ['May 19', vText(u'Year end PAYE'), '']] I *guess* it's some sort of indication of non-constant text, I need a way to make it constant (well, to get a constant copy of it) because a function I'm passing it to is complaining about a type mismatch:- TypeError: in method 'Fl_Input__value', argument 2 of type 'char const *' -- Chris Green From pavlovevidence at gmail.com Tue Feb 2 13:38:53 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 10:38:53 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: On Feb 2, 9:02?am, Nobody wrote: > I don't know if that's necessary. Only supporting the "foo.h" case would > work fine if Python behaved like gcc, i.e. if the "current directory" > referred to the directory contain the file performing the import rather > than in the process' CWD. > > As it stands, imports are dynamically scoped, when they should be > lexically scoped. Mostly incorrect. The CWD is in sys.path only for interactive sessions, and when started with -c switch. When running scripts, the directory where the script is located is used instead, not the process's working directory. So, no, it isn't anything like dynamic scoping. > The only situation where the process' CWD should be used is for an import > statement in a non-file source (i.e. stdin or the argument to the -c > switch). It already is that way, chief. I think you're misunderstanding what's wrong here; the CWD doesn't have anything to do with it. Even if CWD isn't in the path you still get the bad behavior kj noted. So now what? Python's importing can be improved but there's no foolproof way to get rid of the fundamental problem of name clashes. Carl Banks From pavlovevidence at gmail.com Tue Feb 2 13:45:07 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 10:45:07 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: On Feb 2, 2:49?am, Jean-Michel Pichavant wrote: > Carl Banks wrote: > > Name your modules "send_email.py" or "sort_email.py" or if it's a > > library module of related functions, "email_handling.py". ?Modules and > > scripts do things (usually), they should be given action words as > > names. > > > (**) Questionable though it be, if the Standard Library wants to use > > an "innocuous" name, It can. > > That does not solve anything, Of course it does, it solves the problem of having poorly-named modules. It also helps reduce possibility of name clashes. > if the smtplib follows your advice, then > you'll be shadowing its send_email module. > The only way to avoid collision would be to name your module > __PDSFLSDF_send_email__13221sdfsdf__.py I know, and as we all know accidental name clashes are the end of the world and Mother Python should protect us feeble victims from any remote possibility of ever having a name clash. Carl Banks From arnodel at googlemail.com Tue Feb 2 14:00:21 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 02 Feb 2010 19:00:21 +0000 Subject: What's this vText() annotation mean? References: Message-ID: tinnews at isbd.co.uk writes: > What does this vText() annotation mean in a returned list:- > > [['Apr 19', vText(u'PAYE'), ''], It means your list contains an instance of a class whose __repr__() method returns "vText(u'PAYE')". If it follows common practice, the class is probably named "vText". You are likely to be importing and using a module that defines a class called "vText". I don't know such a module, I don't think it's in the standard library so it would be useful if you gave more details about the context. A quick google for "vtext python" yields something about an iCalendar package for python. Is it what you are using? -- Arnaud From martin at v.loewis.de Tue Feb 2 14:01:21 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Tue, 02 Feb 2010 20:01:21 +0100 Subject: recv_into(bytearray) complains about a "pinned buffer" In-Reply-To: <942aa99d-1bc1-4aa8-867a-6366cb3668a1@36g2000yqu.googlegroups.com> References: <8dff1c70-c141-4f0e-aebb-3a92733b272b@o28g2000yqh.googlegroups.com> <4B663CE0.4030302@v.loewis.de> <4B675FE2.4090404@v.loewis.de> <942aa99d-1bc1-4aa8-867a-6366cb3668a1@36g2000yqu.googlegroups.com> Message-ID: > Clearly it was added to work with an array, and it's > being used with an array. Why shouldn't people use it > with Python 2.x? Because it's not thread-safe; it may crash the interpreter if used incorrectly. Of course, if you don't share the array across threads, it can be safe to use. Regards, Martin From jeanmichel at sequans.com Tue Feb 2 14:07:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 02 Feb 2010 20:07:48 +0100 Subject: How to guard against bugs like this one? In-Reply-To: References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: <4B687804.6070005@sequans.com> Carl Banks wrote: > On Feb 2, 2:49 am, Jean-Michel Pichavant > wrote: > >> Carl Banks wrote: >> >>> Name your modules "send_email.py" or "sort_email.py" or if it's a >>> library module of related functions, "email_handling.py". Modules and >>> scripts do things (usually), they should be given action words as >>> names. >>> >>> (**) Questionable though it be, if the Standard Library wants to use >>> an "innocuous" name, It can. >>> >> That does not solve anything, >> > > Of course it does, it solves the problem of having poorly-named > modules. It also helps reduce possibility of name clashes. > Actually don't you think it will increase the possibility ? There are much less possibilties of properly naming an object than badly naming it. So if everybody tend to properly name their object with their obvious version like you proposed, the set of possible names will decrease, increasing the clash ratio. I'm just nitpicking by the way, but it may be better to ask for better namespacing instead of naming (which is good thing but unrelated to the OP issue). JM From no.email at please.post Tue Feb 2 14:43:40 2010 From: no.email at please.post (kj) Date: Tue, 2 Feb 2010 19:43:40 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: In Terry Reedy writes: >On 2/2/2010 9:13 AM, kj wrote: >>> As for fixing it, unfortunately it's not quite so simple to fix without >>> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >>> was missed. >> >> This last point is to me the most befuddling of all. Does anyone >> know why this opportunity was missed for 3.0? Anyone out there >> with the inside scoop on this? Was the fixing of this problem >> discussed in some PEP or some mailing list thread? (I've tried >> Googling this but did not hit on the right keywords to bring up >> the deliberations I'm looking for.) >There was a proposal to put the whole stdlib into a gigantic package, so >that >import itertools >would become, for instance >import std.itertools. >Guido rejected that. I believe he both did not like it and was concerned >about making upgrade to 3.x even harder. The discussion was probably on >the now closed py3k list. Thanks. I'll look for this thread. ~K From MLMDev at Comcast.net Tue Feb 2 15:14:27 2010 From: MLMDev at Comcast.net (Mitchell L Model) Date: Tue, 2 Feb 2010 15:14:27 -0500 Subject: lists as an efficient implementation of large two-dimensional arrays(!) Message-ID: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> An instructive lesson in YAGNI ("you aren't going to need it"), premature optimization, and not making assumptions about Python data structure implementations. I need a 1000 x 1000 two-dimensional array of objects. (Since they are instances of application classes it appears that the array module is useless; likewise, since I am using Python 3.1, so among other things, I can't use numpy or its relatives.) The usage pattern is that the array is first completely filled with objects. Later, objects are sometimes accessed individually by row and column and often the entire array is iterated over. Worried (unnecessarily, as it turns out) by the prospect of 1,000,000 element list I started by constructing a dictionary with the keys 1 through 1000, each of which had as its value another dictionary with the keys 1 through 1000. Actual values were the values of the second level dictionary. Using numbers to fill the array to minimize the effect of creating my more complex objects, and running Python 3.1.1 on an 8-core Mac Pro with 8Gb memory, I tried the following #create and fill the array: t1 = time.time() d2 = {} for j in range(1000): d2[j] = dict() for k in range(1000): d2[j][k] = k print( round(time.time() - t1, 2)) 0.41 # access each element of the array: t1 = time.time() for j in range(1000): for k in range(1000): elt = d2[j][k] print( round(time.time() - t1, 2)) 0.55 My program was too slow, so I started investigating whether I could improve on the two-level dictionary, which got used a lot. To get another baseline I tried a pure 1,000,000-element list, expecting the times to be be horrendous, but look! # fill a list using append t1 = time.time() lst = [] for n in range(1000000): lst.append(n) print( round(time.time() - t1, 2)) 0.26 # access every element of a list t1 = time.time() for n in range(1000000): elt = lst[n] print( round(time.time() - t1, 2)) 0.25 What a shock! I could save half the execution time and all my clever work and awkward double-layer dictionary expressions by just using a list! Even better, look what happens using a comprehension to create the list instead of a loop with list.append: t1 = time.time() lst = [n for n in range(1000000)] print( round(time.time() - t1, 2)) 0.11 Half again to create the list. Iterating over the whole list is easier and faster than iterating over the double-level dictionary, in particular because it doesn't involve a two-level loop. But what about individual access given a row and a column? t1 = time.time() for j in range(1000): for k in range(1000): elt = lst[j * 1000 + k] print( round(time.time() - t1, 2)) 0.45 This is the same as for the dictionary. I tried a two-level list and a few other things but still haven't found anything that works better than a single long list -- just like 2-D arrays are coded in old-style languages, with indices computed as offsets from the beginning of the linear sequence of all the values. What's amazing is that creating and accessing 1,000,000-element list in Python is so efficient. The usual moral obtains: start simple, analyze problems (functional or performance) as they arise, decide whether they are worth the cost of change, then change in very limited ways. And of course abstract and modularize so that, in my case, for example, none of the program's code would be affected by the change from a two-level dictionary representation to using a single long list. I realize there are many directions an analysis like this can follow, and many factors affecting it, including patterns of use. I just wanted to demonstrate the basics for a situation that I just encountered. In particular, if the array was sparse, rather than completely full, the two-level dictionary implementation would be the natural representation. From pavlovevidence at gmail.com Tue Feb 2 15:26:16 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 12:26:16 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: On Feb 2, 11:07?am, Jean-Michel Pichavant wrote: > Carl Banks wrote: > > On Feb 2, 2:49 am, Jean-Michel Pichavant > > wrote: > > >> Carl Banks wrote: > > >>> Name your modules "send_email.py" or "sort_email.py" or if it's a > >>> library module of related functions, "email_handling.py". ?Modules and > >>> scripts do things (usually), they should be given action words as > >>> names. > > >>> (**) Questionable though it be, if the Standard Library wants to use > >>> an "innocuous" name, It can. > > >> That does not solve anything, > > > Of course it does, it solves the problem of having poorly-named > > modules. ?It also helps reduce possibility of name clashes. > > Actually don't you think it will increase the possibility ? There are > much less possibilties of properly naming an object than badly naming it. You've got to be kidding me, you're saying that a bad name like email.py is less likely to clash than a more descriptive name like send_email.py? > So if everybody tend to properly name their object with their obvious > version like you proposed, the set of possible names will decrease, > increasing the clash ratio. I did not propose obvious module names. I said obvious names like email.py are bad; more descriptive names like send_email.py are better. Carl Banks From gerald.britton at gmail.com Tue Feb 2 15:36:45 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Tue, 2 Feb 2010 15:36:45 -0500 Subject: lists as an efficient implementation of large two-dimensional arrays(!) In-Reply-To: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> References: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> Message-ID: <5d1a32001002021236s5f2e5eb2o5535258567921039@mail.gmail.com> Did you try it with an array object using the array module? On Tue, Feb 2, 2010 at 3:14 PM, Mitchell L Model wrote: > An instructive lesson in YAGNI ("you aren't going to need it"), premature > optimization, and not making assumptions about Python data structure > implementations. > > I need a 1000 x 1000 two-dimensional array of objects. (Since they are > instances of application classes it appears that the array module is > useless; likewise, since I am using Python 3.1, so among other things, I > can't use numpy or its relatives.) The usage pattern is that the array is > first completely filled with objects. Later, objects are sometimes accessed > individually by row and column and often the entire array is iterated over. > > Worried (unnecessarily, as it turns out) by the prospect of 1,000,000 > element list I started by constructing a dictionary with the keys 1 through > 1000, each of which had as its value another dictionary with the keys 1 > through 1000. Actual values were the values of the second level dictionary. > > Using numbers to fill the array to minimize the effect of creating my more > complex objects, and running Python 3.1.1 on an 8-core Mac Pro with 8Gb > memory, I tried the following > > #create and fill the array: > t1 = time.time() > d2 = {} > for j in range(1000): > ? ?d2[j] = dict() > ? ?for k in range(1000): > ? ? ? ?d2[j][k] = k > print( round(time.time() - t1, 2)) > > 0.41 > > # access each element of the array: > t1 = time.time() > for j in range(1000): > ? ?for k in range(1000): > ? ? ? ?elt = d2[j][k] > print( round(time.time() - t1, 2)) > > 0.55 > > ?My program was too slow, so I started investigating whether I could improve > on the two-level dictionary, which got used a lot. To get another baseline I > tried a pure 1,000,000-element list, expecting the times to be be > horrendous, but look! > > # fill a list using append > t1 = time.time() > lst = [] > for n in range(1000000): > ? ?lst.append(n) > print( round(time.time() - t1, 2)) > > 0.26 > > # access every element of a list > t1 = time.time() > for n in range(1000000): > ? ?elt = lst[n] > print( round(time.time() - t1, 2)) > > 0.25 > > What a shock! I could save half the execution time and all my clever work > and awkward double-layer dictionary expressions by just using a list! > > Even better, look what happens using a comprehension to create the list > instead of a loop with list.append: > > t1 = time.time() > lst = [n for n in range(1000000)] > print( round(time.time() - t1, 2)) > > 0.11 > > Half again to create the list. > > Iterating over the whole list is easier and faster than iterating over the > double-level dictionary, in particular because it doesn't involve a > two-level loop. But what about individual access given a row and a column? > > t1 = time.time() > for j in range(1000): > ? ?for k in range(1000): > ? ? ? ?elt = lst[j * 1000 + k] > print( round(time.time() - t1, 2)) > > 0.45 > > This is the same as for the dictionary. > > I tried a two-level list and a few other things but still haven't found > anything that works better than a single long list -- just like 2-D arrays > are coded in old-style languages, with indices computed as offsets from the > beginning of the linear sequence of all the values. What's amazing is that > creating and accessing 1,000,000-element list in Python is so efficient. The > usual moral obtains: start simple, analyze problems (functional or > performance) as they arise, decide whether they are worth the cost of > change, then change in very limited ways. And of course abstract and > modularize so that, in my case, for example, none of the program's code > would be affected by the change from a two-level dictionary representation > to using a single long list. > > I realize there are many directions an analysis like this can follow, and > many factors affecting it, including patterns of use. I just wanted to > demonstrate the basics for a situation that I just encountered. In > particular, if the array was sparse, rather than completely full, the > two-level dictionary implementation would be the natural representation. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From xahlee at gmail.com Tue Feb 2 15:40:13 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Feb 2010 12:40:13 -0800 (PST) Subject: python admin abuse complaint Message-ID: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> This is a short complaint on admin abuse on #python irc channel on freenode.net. Here's a log: 2010-02-02 (12:11:57 PM) The topic for #python is: NO LOL | http://pound-python.org/ | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: http://paste.pocoo.org/ | Tutorial: http://docs.python.org/tut/ | FAQ: http://effbot.org/pyfaq/ | New Programmer? Read http://tinyurl.com/thinkcspy | #python.web #wsgi #python-fr #python.de #python-es #python.tw #python.pl #python-br #python-jp #python-nl #python-ir #python- offtopic (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, actually. (12:12:01 PM) jarray52: Jarray (12:12:11 PM) _habnabit: jarray52, yes, you are. (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops etc) right is quite tricky (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just wondering whats up with the python verison :D (12:12:24 PM) mode (+o dash) by ChanServ (12:12:30 PM) You have been kicked by dash: (No.) --------------- I have not been using irc for the past about 2 year. (possibly perhaps 2 times in i think #web channel) In particular, i have not been in in freenode.net's #python channel. I don't know who is dash. Xah ? http://xahlee.org/ ? From alan at baselinedata.co.uk Tue Feb 2 15:50:28 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Tue, 02 Feb 2010 20:50:28 +0000 Subject: Threading issue with SQLite In-Reply-To: <09ca16b8-4e10-40f5-a69d-29fcdf6c2593@b9g2000pri.googlegroups.com> References: <09ca16b8-4e10-40f5-a69d-29fcdf6c2593@b9g2000pri.googlegroups.com> Message-ID: <4B689014.9090801@baselinedata.co.uk> Many thanks to all who replied to my questions re. SQLite connections, cursors and threading. Looks like I have got some reading to do regarding connection pooling and a decent SQLite ORM package. Does anyone know of any which are Python 3 compatible? Many thanks, Alanj From alfps at start.no Tue Feb 2 15:54:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 02 Feb 2010 21:54:25 +0100 Subject: Your impression of for-novice writings on assertions Message-ID: I've started on ch 3 of my beginner's intro to programming, now delving into the details of the Python language. It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at which is at Google Docs. The first topic is about assertions and exceptions. I wonder whether this text is easy or difficult to understand for a beginner. Or any improvements that could be made. Cheers, - Alf From exarkun at twistedmatrix.com Tue Feb 2 15:57:11 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Tue, 02 Feb 2010 20:57:11 -0000 Subject: lists as an efficient implementation of large two-dimensional arrays(!) In-Reply-To: <5d1a32001002021236s5f2e5eb2o5535258567921039@mail.gmail.com> References: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> <5d1a32001002021236s5f2e5eb2o5535258567921039@mail.gmail.com> Message-ID: <20100202205711.26099.185894442.divmod.xquotient.82@localhost.localdomain> On 08:36 pm, gerald.britton at gmail.com wrote: >On Tue, Feb 2, 2010 at 3:14 PM, Mitchell L Model >wrote: >>I need a 1000 x 1000 two-dimensional array of objects. (Since they are >>instances of application classes it appears that the array module is >>useless; >Did you try it with an array object using the array module? Jean-Paul From astan.chee at al.com.au Tue Feb 2 16:07:50 2010 From: astan.chee at al.com.au (Astan Chee) Date: Wed, 3 Feb 2010 08:07:50 +1100 Subject: converting XML to hash/dict/CustomTreeCtrl In-Reply-To: <4B6756FE.9060206@al.com.au> References: <4B6756FE.9060206@al.com.au> Message-ID: <4B689426.1070400@al.com.au> Hi, Sorry for being vague but here my question about converting an xml into a dict. I found some examples online but none gives the dict/result I want. The xml looks like this: This is the note on calculation times 609.081574 2531.972081 65.119100 1772.011230 72.418861 28.285192 0.000 607.432373 4833280000 4833280000 4182777856 4182777856 1 1943498 0 1640100156 411307840 709596712 1406752 737720720 0 607.432373 5164184694 2054715622 using this script (taken from http://code.activestate.com/recipes/410469/): from xml.etree import cElementTree as ElementTree class XmlListConfig(list): def __init__(self, aList): for element in aList: if element: # treat like dict if len(element) == 1 or element[0].tag != element[1].tag: self.append(XmlDictConfig(element)) # treat like list elif element[0].tag == element[1].tag: self.append(XmlListConfig(element)) elif element.text: text = element.text.strip() if text: self.append(text) class XmlDictConfig(dict): ''' Example usage: >>> tree = ElementTree.parse('your_file.xml') >>> root = tree.getroot() >>> xmldict = XmlDictConfig(root) Or, if you want to use an XML string: >>> root = ElementTree.XML(xml_string) >>> xmldict = XmlDictConfig(root) And then use xmldict for what it is... a dict. ''' def __init__(self, parent_element): if parent_element.items(): self.update(dict(parent_element.items())) for element in parent_element: if element: # treat like dict - we assume that if the first two tags # in a series are different, then they are all different. if len(element) == 1 or element[0].tag != element[1].tag: aDict = XmlDictConfig(element) # treat like list - we assume that if the first two tags # in a series are the same, then the rest are the same. else: # here, we put the list in dictionary; the key is the # tag name the list elements all share in common, and # the value is the list itself aDict = {element[0].tag: XmlListConfig(element)} # if the tag has attributes, add those to the dict if element.items(): aDict.update(dict(element.items())) self.update({element.tag: aDict}) # this assumes that if you've got an attribute in a tag, # you won't be having any text. This may or may not be a # good idea -- time will tell. It works for the way we are # currently doing XML configuration files... elif element.items(): self.update({element.tag: dict(element.items())}) # finally, if there are no child tags and no attributes, extract # the text else: self.update({element.tag: element.text}) tree = ElementTree.parse('test.xml') root = tree.getroot() xmldict = XmlDictConfig(root) print xmldict Which I get this dict: {'stats': {'kind': 'position', 'stats': [{'kind': 'section', 'stats': {'kind': 'timers', 'name': 'timers', 'timer': [{'system': '65.119100', 'user': '2531.972081', 'elapsed': '609.081574', 'name': 'totaltime', 'description': 'Total time'}, {'elapsed': '1772.011230', 'name': 'partialTimer', 'description': 'Gravitational Displacement'}, [{'elapsed': '72.418861', 'name': 'subATimer', 'description': 'Phase time A'}, {'elapsed': '28.285192', 'name': 'subBTimer', 'description': 'Phase time B'}, {'elapsed': '0.000', 'name': 'spaceMem', 'description': 'Space memory'}], {'elapsed': '607.432373', 'name': 'endTime', 'description': 'End'}]}, 'name': 'time', 'string': {'name': 'timersNote', 'description': 'Note:'}, 'description': 'Timing summary'}, [[{'current': '4833280000', 'peak': '4833280000', 'name': 'heapSpace', 'description': 'Total Space'}, {'current': '4182777856', 'peak': '4182777856', 'name': 'spaceResidentSize', 'description': 'Space resident size'}, '1', '1943498', '0'], [{'current': '411307840', 'peak': '1640100156', 'name': 'geoSpace', 'description': 'Geo-Space'}, {'current': '1406752', 'peak': '709596712', 'name': 'gridSpace', 'description': 'Grid-Space'}, {'current': '0', 'peak': '737720720', 'name': 'spaceMem', 'description': 'Space memory'}, {'peak': '607.432373', 'name': 'endTime', 'description': 'End'}], {'current': '2054715622', 'peak': '5164184694', 'name': 'subsystemSpace', 'description': 'Subsystem space total'}]], 'name': 'position1', 'description': 'Calculation statistics'}} Which is kinda wrong. I expect the dict to have the "Space usage summary", but it doesn't (duplicate?). What am I doing wrong here? I am attempting to keep the attribute value of an XML as key (if it doesn't have a value, then just the tag name will do) and associate it with the text value of that tag/attribute value as well as reflecting the hierarchy structure of the XML in the dict. Does this make sense? Anyway, the python script above is just the first step or an example for me. Cheers and thanks again Astan From python at rcn.com Tue Feb 2 16:22:55 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 2 Feb 2010 13:22:55 -0800 (PST) Subject: Your impression of for-novice writings on assertions References: Message-ID: <1fe7535b-34dc-46ba-9807-bd1e8cf69a9c@x1g2000prb.googlegroups.com> On Feb 2, 12:54?pm, "Alf P. Steinbach" wrote: > The first topic is about assertions and exceptions. I wonder whether this text > is easy or difficult to understand for a beginner. Or any improvements that > could be made. To my eyes it reads nicely. You may want to try it out on a real beginner to get their feedback. I like your section on assertions. You could add examples of other ways assertions can be used (loop invariants, sanity checks, post- condition contract checks). For example, validate a loop invariant during a selection sort. In the hypot() example, use an assertion for sanity checking by verifying an expected mathematical relationship such as the triangle inequality: assert abs(c) <= abs(a) + abs(b). The pythagorean triple example can use assertions to check post conditions: assert all(isinstance(x, int) for x in (a,b,c)) and a*a +b*b==c*c. Raymond From andrewt.herd at gmail.com Tue Feb 2 16:25:07 2010 From: andrewt.herd at gmail.com (Andrew) Date: Tue, 2 Feb 2010 13:25:07 -0800 (PST) Subject: PyQt4 designer custom properties - combo box style Message-ID: I am creating custom widgets for the PyQt4 Designer. I can create custom properties, but I'm looking for how to create a custom property that has a combo box drop down. I've seen them in the example widgets and tried following them, but they are using pre-defined items to populate their property, so it's not a very clear example of how to get the combo box property to work. Is there any other examples or help for this kind of setup? Thanks, Andrew From aahz at pythoncraft.com Tue Feb 2 16:29:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2010 13:29:39 -0800 Subject: PyPI source dependencies? Message-ID: I'm trying to build PyObjC from source (because the binary doesn't work on OSX 10.5) and I can't figure out how to get all the dependencies downloaded automatically. Am I missing something? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From jgardner at jonathangardner.net Tue Feb 2 16:35:50 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:35:50 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: On Feb 2, 12:40?pm, Xah Lee wrote: > > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > I think you mean hash.clear() instead of hash.clean() The answer is that "hash = {}" will create a new dict and assign it to "hash", while "hash.clear()" simply guts the dict that "hash" is pointing to. In the end, both will result in "has" pointing to an empty dict. However, if you had something else pointing to what "hash" was pointing to, they will no longer be pointing to the same, empty hash after "hash = {}" is run. >>> a = b = {1:2} >>> a {1: 2} >>> b {1: 2} >>> a.clear() >>> a {} >>> b {} >>> a = b = {1:2} >>> a = {} >>> a {} >>> b {1: 2} From rschroev_nospam_ml at fastmail.fm Tue Feb 2 16:38:43 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 02 Feb 2010 22:38:43 +0100 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: Op 2010-02-02 18:02, Nobody schreef: > On Tue, 02 Feb 2010 15:00:28 +0000, Grant Edwards wrote: > >>>> It turns out that buggy.py imports psycopg2, as you can see, and >>>> apparently psycopg2 (or something imported by psycopg2) tries to >>>> import some standard Python module called numbers; instead it ends >>>> up importing the innocent myscript/numbers.py, resulting in *absolute >>>> mayhem*. >>> >>> I feel your pain, but this is not a Python problem, per-se. >> >> I think it is. > > I agree. > >> There should be different syntax to import from >> "standard" places and from "current directory". Similar to the >> difference between "foo.h" and in cpp. > > I don't know if that's necessary. Only supporting the "foo.h" case would > work fine if Python behaved like gcc, i.e. if the "current directory" > referred to the directory contain the file performing the import rather > than in the process' CWD. That is what I would have expected, it is the way I would have implemented it, and I don't understand why anyone would think differently. Yet not everyone seems to agree. Apparently, contrary to my expectations, Python looks in the directory containing the currently running script instead. That means that the behavior of "import foo" depends very much on circumstances not under control of the module in which that statement appears. Very fragile. Suggestions to use better names or just poor workarounds, IMO. Of the same nature are suggestions to limit the amount of scrips/modules in a directory... my /usr/bin contains no less than 2685 binaries, with 0 problems of name clashes; there is IMO no reason why Python should restrict itself to any less. Generally I like the design decisions used in Python, or at least I understand the reasons; in this case though, I don't see the advantages of the current approach. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From jgardner at jonathangardner.net Tue Feb 2 16:39:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:39:19 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <7a1ddcc5-0e2d-4c97-967d-6f6bbf0a7066@t17g2000prg.googlegroups.com> On Feb 1, 6:34?pm, kj wrote: > > An innocuous little script, let's call it buggy.py, only 10 lines > long, and whose output should have been, at most two lines, was > quickly dumping tens of megabytes of non-printable characters to > my screen (aka gobbledygook), and in the process was messing up my > terminal *royally*. > In linux terminals, try running the command "reset" to clear up any gobbledy-gook. It also works if you happen to hit CTRL-C while entering a password, in the rare case that it fails to set the text back to visible mode. From jgardner at jonathangardner.net Tue Feb 2 16:49:39 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:49:39 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: On Feb 2, 2:21?am, waku wrote: > > for writing new code, it's not necessarily that helpful to be *forced* > to keep with strict indenting rules. ?in early development phases, > code is often experimental, and parts of it may need to be blocked or > unblocked as the codebase grows, and for experimentation, the need to > carefully and consistently indent and de-indent large chunks of code > can easily lead to a mess (blame it on the programmer, not the > language, but still). ?yes, there are editors that help you indent > chunks of code, but see below. > > there are languages where indentation can be either enforced and allow > one to omit some syntactic nuissance like braces or begin-end clauses, > or made optional, requiring other syntactic means for delimiting > blocks etc. ?(consider f# with its #light declaration, for example.) > If you're writing "experimental code", you're doing it wrong. Every line of code you write may end up on the space shuttle one day (so to speak!) Why not write the code well-formatted in the first place, so that any bugs you introduce are as easily visible as possible? The only reason why you may want to write crap code without proper formatting is because your text editor is stupid. If that's the case, get rid of your text editor and find some tools that help you do the right thing the first time. > > as long as you are limited to your own code, sure. ?but if many work > on the same bit, and use different editors and indentation policies, > blanks-tabs indentation issues are not unlikely. ?you can have blanks > converted to tabs and vice versa automatically, but that's clearly a > nuisance. > If you're text editor has a problem with indenting, you have a terrible text editor. Period, end of sentence. You can't screw in bolts with a hammer, and you can't level with a saw. Don't try to write code in any language without a real text editor that can do proper indentation. Don't let your teammates use deficient text editors either. I wouldn't appreciate it if I delivered precision components that my teammates tried to install with sledgehammers. This is the 21st Century. Good text editors are not hard to find on any platform. From jgardner at jonathangardner.net Tue Feb 2 16:55:09 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 13:55:09 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> Message-ID: <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> On Feb 1, 6:21?pm, Nobody wrote: > > You don't need to know the entire language before you can use any of it > (if you did, Python would be deader than a certain parrot; Python's dark > corners are *really* dark). > I'm curious. What dark corners are you referring to? I can't think of any. Especially with the direction Python 3 is going, it seems like even the slightly dim corners are being rounded away. I can explain, in an hour, every single feature of the Python language to an experienced programmer, all the way up to metaclasses, __getattribute__, __new__ and __get__. These are the darkest corners I know of, and these are not at all dark. It takes a few paragraphs of documentation to explain all the details of each these features. I hold the entire Python language in my head, and I can still remember when my next meeting is. Compare that to something like Haskell, where you have to read entire books before you truly understand what monads are actually doing behind the scenes, and how Haskell actually interprets and runs your program, or to understand what the esoteric error messages that crop up are actually caused be. Yes, there are people that know how to do stuff in Haskell. These are really smart people, the cream of the crop, so to speak. But that doesn't make Haskell a simple language. From jgardner at jonathangardner.net Tue Feb 2 17:01:01 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 14:01:01 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> Message-ID: <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> On Feb 1, 6:36?pm, John Bokma wrote: > Jonathan Gardner writes: > > One of the bad things with languages like perl > > FYI: the language is called Perl, the program that executes a Perl > program is called perl. > > > without parentheses is that getting a function ref is not obvious. You > > need even more syntax to do so. In perl: > > > ?foo(); ? ? ? # Call 'foo' with no args. > > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > > ? ? ? ? ? ? ? # By the way, this '&' is not the bitwise-and '&'!!!! > > It should be $bar = \&foo > Your example actually calls foo... > I rest my case. I've been programming perl professionally since 2000, and I still make stupid, newbie mistakes like that. > > One is simple, consistent, and easy to explain. The other one requires > > the introduction of advanced syntax and an entirely new syntax to make > > function calls with references. > > The syntax follows that of referencing and dereferencing: > > $bar = \@array; ? ? ? # bar contains now a reference to array > $bar->[ 0 ]; ? ? ? ? ?# first element of array referenced by bar > $bar = \%hash; ? ? ? ?# bar contains now a reference to a hash > $bar->{ key }; ? ? ? ?# value associated with key of hash ref. by bar > $bar = \&foo; ? ? ? ? # bar contains now a reference to a sub > $bar->( 45 ); ? ? ? ? # call sub ref. by bar with 45 as an argument > > Consistent: yes. New syntax? No. > Except for the following symbols and combinations, which are entirely new and different from the $@% that you have to know just to use arrays and hashes. \@, ->[ ] \%, ->{ } \&, ->( ) By the way: * How do you do a hashslice on a hashref? * How do you invoke reference to a hash that contains a reference to an array that contains a reference to a function? Compare with Python's syntax. # The only way to assign a = b # The only way to call a function b(...) # The only way to access a hash or array or string or tuple b[...] > Also, it helps to think of > > $ as a thing > @ as thingies indexed by numbers > % as thingies indexed by keys > I'd rather think of the task at hand than what each of the funky symbols on my keyboard mean. From jgardner at jonathangardner.net Tue Feb 2 17:06:47 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 14:06:47 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> Message-ID: <2a5ee10d-4da3-4275-936d-3d792f3450e3@p13g2000pre.googlegroups.com> On Feb 2, 7:23?am, "bartc" wrote: > Jonathan Gardner wrote: > > One of the bad things with languages like perl and Ruby that call > > without parentheses is that getting a function ref is not obvious. You > > need even more syntax to do so. In perl: > > > ?foo(); ? ? ? # Call 'foo' with no args. > > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > > ? ? ? ? ? ? ? # By the way, this '&' is not the bitwise-and '&'!!!! > > ?$bar->() ? ? # Call whatever '$bar' is pointing at with no args > > > Compare with python: > > > ?foo() ? ? ? # Call 'foo' with no args. > > ?bar = foo() # 'bar' is now pointing to whatever 'foo()' returned > > ?bar = foo ? # 'bar' is now pointing to the same thing 'foo' points to > > ?bar() ? ? ? # Call 'bar' with no args > > > One is simple, consistent, and easy to explain. The other one requires > > the introduction of advanced syntax and an entirely new syntax to make > > function calls with references. > > If you get rid of the syntax specific to Perl, then having to explicitly > obtain a function reference, or to dereference the result, is not such a big > deal: > > ?foo ? ? ? ? ?# Call 'foo' with no args. > ?bar = foo ? ?# Call 'foo; with no args, assign to 'bar' > ?bar = &foo ? # Don't call 'foo', but assign a pointer to it to 'bar' > ?bar^ ? ? ? ? # Call whatever 'bar' is pointing at with no args > > (Here I use ^ instead of -> to dereference.) ?Compared with Python, it saves > 3 lots of (), but needs & and ^ added. Still a net saving. > On one shoulder, a demon taunts the programmer: "Ohmygosh, you can save three keystrokes if you introduce an entirely new syntax with odd squiggles that make no pronounceable sound in the English language! Perhaps one day, you can program APL in Python!" The angel that sits on the other shoulder says, "Alas, poor programmer, one day, you'll have to read that and understand it. And heaven help us when we hire a poor college graduate to maintain the code we wrote five years ago. Or worse, when that poor college graduate writes code and expects us to read it!" Thankfully, Guido has banished that demon from the realm of Python a long time ago. > > One of the bad things with languages like perl and Ruby that call > > without parentheses is that getting a function ref is not obvious. > > I'd say that having this "&" symbol in front of "foo" makes it more obvious > than just foo by itself. But I agree not quite as clean. > > Another thing is that you have to know whether "bar" is a function, or a > function ref, and use the appropriate syntax. Sometimes this is helpful, > sometimes not. > Thankfully, in Python, everything is a ref, so everything is consistent. From jgardner at jonathangardner.net Tue Feb 2 17:09:38 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 2 Feb 2010 14:09:38 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <88cc29b2-cc2e-4e02-91dc-073be8216f61@m35g2000prh.googlegroups.com> On Feb 1, 6:50?pm, Nobody wrote: > On Mon, 01 Feb 2010 14:13:38 -0800, Jonathan Gardner wrote: > > I judge a language's simplicity by how long it takes to explain the > > complete language. That is, what minimal set of documentation do you > > need to describe all of the language? > > That's not a particularly good metric, IMHO. > > A simple "core" language doesn't necessarily make a language simple to > use. You can explain the entirety of pure lambda calculus or combinators > in five minutes, but you wouldn't want to write real code in either (and > you certainly wouldn't want to read such code which was written by someone > else). > > For a start, languages with a particularly simple "core" tend to delegate > too much to the library. One thing which puts a lot of people off of > lisp is the lack of infix operators; after all, (* 2 (+ 3 4)) works fine > and doesn't require any additional language syntax. For an alternative, > Tcl provides the "expr" function which essentially provides a sub-language > for arithmetic expressions. > > A better metric is whether using N features has O(N) complexity, or O(N^2) > (where you have to understand how each feature relates to each other > feature) or even O(2^N) (where you have to understand every possible > combination of interactions). > > > With a handful of statements, > > and a very short list of operators, Python beats out every language in > > the Algol family that I know of. > > Not once you move beyond the 10-minute introduction, and have to start > thinking in terms of x + y is x.__add__(y) or maybe y.__radd__(x) and also > that x.__add__(y) is x.__getattribute__('__add__')(y) (but x + y *isn't* > equivalent to the latter due to __slots__), and maybe .__coerce__() gets > involved somewhere, and don't even get me started on __metaclass__ or > __init__ versus __new__ or ... > > Yes, the original concept was very nice and clean, but everything since > then has been wedged in there by sheer force with a bloody great hammer. I strongly suggest you read the documentation on these bits of Python. If you're scared of __new__ versus __init__, then you haven't been programming very long in any language. There is a case when you need one over the other. The same goes for the other concepts. Programming languages that don't provide these features (like Javascript) are nice for toy programs, but lack the power to accommodate the needs of large apps. From ben+python at benfinney.id.au Tue Feb 2 17:21:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Feb 2010 09:21:13 +1100 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> Message-ID: <87mxzrp9d2.fsf@benfinney.id.au> Jonathan Gardner writes: > Compare with Python's syntax. > > # The only way to assign > a = b > > # The only way to call a function > b(...) > > # The only way to access a hash or array or string or tuple > b[...] For all of your examples, there are other ways supported. I do wish this focus on ?only way? would depart, it's a fallacy and not helpful. What is important (and supports the main point of your message) is that for each of the above, whether or not they are the only way, they are the one *obvious* way to do the operation. -- \ ?The cost of education is trivial compared to the cost of | `\ ignorance.? ?Thomas Jefferson | _o__) | Ben Finney From chairman at python.org Tue Feb 2 17:23:43 2010 From: chairman at python.org (Steve Holden, Chairman, PSF) Date: Tue, 02 Feb 2010 17:23:43 -0500 Subject: python admin abuse complaint In-Reply-To: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B68A5EF.7040100@python.org> Xah Lee wrote: > This is a short complaint on admin abuse on #python irc channel on > freenode.net. > > Here's a log: > > 2010-02-02 > > (12:11:57 PM) The topic for #python is: NO LOL | http://pound-python.org/ > | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: > http://paste.pocoo.org/ | Tutorial: http://docs.python.org/tut/ | FAQ: > http://effbot.org/pyfaq/ | New Programmer? Read http://tinyurl.com/thinkcspy > | #python.web #wsgi #python-fr #python.de #python-es #python.tw > #python.pl #python-br #python-jp #python-nl #python-ir #python- > offtopic > (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, > actually. > (12:12:01 PM) jarray52: Jarray > (12:12:11 PM) _habnabit: jarray52, yes, you are. > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops > etc) right is quite tricky > (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just > wondering whats up with the python verison :D > (12:12:24 PM) mode (+o dash) by ChanServ > (12:12:30 PM) You have been kicked by dash: (No.) > > --------------- > > I have not been using irc for the past about 2 year. (possibly perhaps > 2 times in i think #web channel) In particular, i have not been in in > freenode.net's #python channel. I don't know who is dash. > > Xah > ? http://xahlee.org/ > > ? Frankly, Xah Lee, I find it ironic that you see fit to complain about abuse of the IRC channel when you have apparently felt free to ignore the many complaints about your behavior on this and other newsgroups over many years. "As ye sew, so shall ye reap". I imagine that your reputation has preceded you, and that dash (whom I *do* know) is simply looking to keep a well-known nuisance from bothering the rest of the users on the channel. For the present my sympathies are all with him. The PSF will, however, investigate this issue and I will report back to you off-list in due course. regards Steve -- Steve Holden Chairman, Python Software Foundation The Python Community Conference http://python.org/psf/ PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/ Watch PyCon on video now! http://pycon.blip.tv/ From hnine at isis.vanderbilt.edu Tue Feb 2 17:38:00 2010 From: hnine at isis.vanderbilt.edu (Harmon Nine) Date: Tue, 2 Feb 2010 16:38:00 -0600 Subject: Calling a "raw" python function from C++ Message-ID: <7AB1C26C64423249964AB392C6EBF0E0049D4394@discovery.isis.vanderbilt.edu> Hello. I've been crawling the web for an answer to this one, but have come up empty. We can currently only use Boost 1.36 for our project, i.e. we are having problems using later versions of Boost. We are using Boost.Python to interface with Cheetah. Problem: In Boost 1.36, how do you call a "raw" method of a python class from C++? In particular, what C++ code is needed to call a "raw constructor", i.e. a constructor that can take an arbitrary number of positional and keyword arguments by using *args, **kwargs? For instance, this is defined in a ".py" file. class Gain: def __init__( self, *args, **kwargs ): ... In C++ we have (where "gainClass" is the Gain class above referenced from C++): ----- namespace bp = boost::python; bp::object gainObject = gainClass( /* what goes here to call the above Gain constructor? */ ); ----- Passing a tuple and a dict doesn't work. I wish we could use the most recent version of Boost, since in this you can just do this: ----- bp::object gainObject = gainClass( *bp::tuple(), **bp::dict() ); ----- But this is not available in Boost 1.36 TIA -- Harmon -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Feb 2 17:43:07 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 2 Feb 2010 14:43:07 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <7a9c25c21002021443i50111efaia261872130364082@mail.gmail.com> On Tue, Feb 2, 2010 at 1:38 PM, Roel Schroeven < rschroev_nospam_ml at fastmail.fm> wrote: > Apparently, contrary to my expectations, Python looks in the directory > containing the currently running script instead. That means that the > behavior of "import foo" depends very much on circumstances not under > control of the module in which that statement appears. Very fragile. > Suggestions to use better names or just poor workarounds, IMO. Of the > same nature are suggestions to limit the amount of scrips/modules in a > directory... my /usr/bin contains no less than 2685 binaries, with 0 > problems of name clashes; there is IMO no reason why Python should > restrict itself to any less. > > Generally I like the design decisions used in Python, or at least I > understand the reasons; in this case though, I don't see the advantages > of the current approach. This really isn't anything new, novel, or even interesting. Its been known forever that Python searches the script's directory for other scripts, there's reasons for this. Its also been known forever that its not really an ideal situation, and so over the last seven or so years, Python's been working on fixing it. http://www.python.org/dev/peps/pep-0328/ In 2.5, you could activate your modules to use absolute imports by default, thus requiring you to use special syntax to access modules in your own path. In 2.6, relative imports of modules in the same dir (thus, possible shadowing modules) raises a deprecation warning. In Python 3+, you have to use the explicit syntax to get at modules in the current directory. This has taken years to address, yeah, because touching the import machinery is -dangerous-; you have to do it very carefully to be sure that vast amounts of code doesn't break that's relying on the existing, not-entirely-well-documented-or-defined mechanics. Why was Python designed like this? Ask Guido. I don't know, but I'm not surprised: python was always very /flat/ originally. Strict, flat scopes, didn't even have packages, etc. Its slowly gotten a little more nested / deeper over time-- from limited nested scoping (only for enclosing functions), to now absolute imports being default. Its a slow process seeking a delicate balance; "flat is better then nested" vs "namespaces are one honking great idea" are somewhat contradictory, after all :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Feb 2 17:47:19 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Feb 2010 17:47:19 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: On 2/2/2010 2:43 PM, kj wrote: > In Terry Reedy writes: > >> On 2/2/2010 9:13 AM, kj wrote: > >>>> As for fixing it, unfortunately it's not quite so simple to fix without >>>> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >>>> was missed. >>> >>> This last point is to me the most befuddling of all. Does anyone >>> know why this opportunity was missed for 3.0? Anyone out there >>> with the inside scoop on this? Was the fixing of this problem >>> discussed in some PEP or some mailing list thread? (I've tried >>> Googling this but did not hit on the right keywords to bring up >>> the deliberations I'm looking for.) > >> There was a proposal to put the whole stdlib into a gigantic package, so >> that > >> import itertools > >> would become, for instance > >> import std.itertools. > >> Guido rejected that. I believe he both did not like it and was concerned >> about making upgrade to 3.x even harder. The discussion was probably on >> the now closed py3k list. > > > Thanks. I'll look for this thread. Stephen Hansen's post explains a bit more than I did. To supplement his explanation: since print *was* a keyword, every use of 'print' in 2.x denotes a print statement with standard semantics. Therefore 2to3 *knows* what the statement means and can translate it. On the other hand, 'import string' usually means 'import the string module of the stdlib', but it could mean 'import my string module'. This depends on the execution environment. Moreover, I believe people have intentionally shadowed stdlib modules. So. like it or not, 2to3 cannot know what 'import string' means. Terry Jan Reedy From tjreedy at udel.edu Tue Feb 2 17:54:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 02 Feb 2010 17:54:51 -0500 Subject: lists as an efficient implementation of large two-dimensional arrays(!) In-Reply-To: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> References: <421D0C7C-0B5C-4235-B39C-D39140F61980@Comcast.net> Message-ID: On 2/2/2010 3:14 PM, Mitchell L Model wrote: > I need a 1000 x 1000 two-dimensional array of objects. I would just use 1000 element list, with each element being a 1000 element list or array (if possible). Then l2d[i][j] works fine. From nagle at animats.com Tue Feb 2 18:02:49 2010 From: nagle at animats.com (John Nagle) Date: Tue, 02 Feb 2010 15:02:49 -0800 Subject: Overcoming python performance penalty for multicore CPU Message-ID: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> I know there's a performance penalty for running Python on a multicore CPU, but how bad is it? I've read the key paper ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate if the GIL just limited Python to running on one CPU at a time, but it's worse than that; there's excessive overhead due to a lame locking implementation. Running CPU-bound multithreaded code on a dual-core CPU runs HALF AS FAST as on a single-core CPU, according to Beasley. My main server application, which runs "sitetruth.com" has both multiple processes and multiple threads in each process. The system rates web sites, which involves reading and parsing up to 20 pages from each domain. Analysis of each domain is performed in a separate process, but each process uses multiple threads to read process several web pages simultaneously. Some of the threads go compute-bound for a second or two at a time as they parse web pages. Sometimes two threads (but never more than three) in the same process may be parsing web pages at the same time, so they're contending for CPU time. So this is nearly the worst case for the lame GIL lock logic. Has anyone tried using "affinity" ("http://pypi.python.org/pypi/affinity") to lock each Python process to a single CPU? Does that help? John Nagle From steve at holdenweb.com Tue Feb 2 18:05:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 18:05:30 -0500 Subject: Python and Ruby In-Reply-To: <87mxzrp9d2.fsf@benfinney.id.au> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> <87mxzrp9d2.fsf@benfinney.id.au> Message-ID: <4B68AFBA.2070008@holdenweb.com> Ben Finney wrote: > Jonathan Gardner writes: > >> Compare with Python's syntax. >> >> # The only way to assign >> a = b >> >> # The only way to call a function >> b(...) >> >> # The only way to access a hash or array or string or tuple >> b[...] > > For all of your examples, there are other ways supported. I do wish this > focus on ?only way? would depart, it's a fallacy and not helpful. > And besides which most people get the quote wrong. The "authoritative" version from the Zen is, as you clearly already know There should be one-- and preferably only one --obvious way to do it. > What is important (and supports the main point of your message) is that > for each of the above, whether or not they are the only way, they are > the one *obvious* way to do the operation. > Quite. People might be interested to know the history of the Zen, which I got directly from Tim Peters over lunch one day. It was composed, apparently, during the commercial breaks one evening while he was watching professional wrestling on the television! So it's wise not to take the Zen too seriously. It wasn't written to guide, but to amuse. The fact that it can do both is a testament to Tim's sagacity. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From aahz at pythoncraft.com Tue Feb 2 18:07:05 2010 From: aahz at pythoncraft.com (Aahz) Date: 2 Feb 2010 15:07:05 -0800 Subject: Need help with a program References: <96db4cd6-bda3-42db-a592-83d72e517e2d@28g2000vbf.googlegroups.com> <4B61CE0E.5000801@sequans.com> Message-ID: In article , D'Arcy J.M. Cain wrote: > >If you have a problem and you think that regular expressions are the >solution then now you have two problems. Regex is really overkill for >the OP's problem and it certainly doesn't improve readability. If you're going to use a quote, it works better if you use the exact quote and attribute it: 'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.' --Jamie Zawinski -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From sjdevnull at yahoo.com Tue Feb 2 18:07:47 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Tue, 2 Feb 2010 15:07:47 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> Message-ID: <1ee94353-24aa-48a9-a7e2-474149ae0f7c@u41g2000yqe.googlegroups.com> On Feb 2, 5:01?pm, Jonathan Gardner wrote: > On Feb 1, 6:36?pm, John Bokma wrote: > > > > > > > Jonathan Gardner writes: > > > One of the bad things with languages like perl > > > FYI: the language is called Perl, the program that executes a Perl > > program is called perl. > > > > without parentheses is that getting a function ref is not obvious. You > > > need even more syntax to do so. In perl: > > > > ?foo(); ? ? ? # Call 'foo' with no args. > > > ?$bar = foo; ?# Call 'foo; with no args, assign to '$bar' > > > ?$bar = &foo; # Don't call 'foo', but assign a pointer to it to '$bar' > > > ? ? ? ? ? ? ? # By the way, this '&' is not the bitwise-and '&'!!!! > > > It should be $bar = \&foo > > Your example actually calls foo... > > I rest my case. I've been programming perl professionally since 2000, > and I still make stupid, newbie mistakes like that. > > > > One is simple, consistent, and easy to explain. The other one requires > > > the introduction of advanced syntax and an entirely new syntax to make > > > function calls with references. > > > The syntax follows that of referencing and dereferencing: > > > $bar = \@array; ? ? ? # bar contains now a reference to array > > $bar->[ 0 ]; ? ? ? ? ?# first element of array referenced by bar > > $bar = \%hash; ? ? ? ?# bar contains now a reference to a hash > > $bar->{ key }; ? ? ? ?# value associated with key of hash ref. by bar > > $bar = \&foo; ? ? ? ? # bar contains now a reference to a sub > > $bar->( 45 ); ? ? ? ? # call sub ref. by bar with 45 as an argument > > > Consistent: yes. New syntax? No. > > Except for the following symbols and combinations, which are entirely > new and different from the $@% that you have to know just to use > arrays and hashes. > > \@, ->[ ] > \%, ->{ } > \&, ->( ) > > By the way: > * How do you do a hashslice on a hashref? > * How do you invoke reference to a hash that contains a reference to > an array that contains a reference to a function? > > Compare with Python's syntax. > > # The only way to assign > a = b >>> locals().__setitem__('a', 'b') >>> print a b > # The only way to call a function > b(...) >>> def b(a): ... print a*2 >>> apply(b, (3,)) 6 > # The only way to access a hash or array or string or tuple > b[...] >>> b={} >>> b[1] = 'a' >>> print b.__getitem__(1) a From exarkun at twistedmatrix.com Tue Feb 2 18:24:59 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Tue, 02 Feb 2010 23:24:59 -0000 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <20100202232459.26099.2057701829.divmod.xquotient.97@localhost.localdomain> On 11:02 pm, nagle at animats.com wrote: > I know there's a performance penalty for running Python on a >multicore CPU, but how bad is it? I've read the key paper >("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate >if the GIL just limited Python to running on one CPU at a time, >but it's worse than that; there's excessive overhead due to >a lame locking implementation. Running CPU-bound multithreaded >code on a dual-core CPU runs HALF AS FAST as on a single-core >CPU, according to Beasley. It's not clear that Beasley's performance numbers apply to any platform except OS X, which has a particularly poor implementation of the threading primitives CPython uses to implement the GIL. You should check to see if it actually applies to your deployment environment. The GIL has been re-implemented recently. Python 3.2, I think, will include the new implementation, which should bring OS X performance up to the level of other platforms. It may also improve certain other aspects of thread switching. Jean-Paul From gagsl-py2 at yahoo.com.ar Tue Feb 2 18:30:17 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Feb 2010 20:30:17 -0300 Subject: Problems embedding python 2.6 in C++ References: <5089497e1002011321h5328ed68y4bfab055f627ba74@mail.gmail.com> <5089497e1002012126h55f0611ct476eabb0ccf1bea1@mail.gmail.com> Message-ID: En Tue, 02 Feb 2010 02:26:57 -0300, Paul escribi?: > I've managed to get it working and so far stable... Glad to see you finally made it work! > Current working version: > [...] > mycppclass::callpy(funcname, args...) > m_mypymodule = PyImport_Import(pModuleName) > > pyargs = PyTuple_SetItem * args > PyCallable_Check(func) > PyObject_CallObject(func,pyargs) > > Py_XDECREF(m_mypymodule) > > So now the module is being imported each function call (luckily I don't > have > to worry about performance) Remember that after the module is successfully imported by the first time, a subsequent import returns early, as soon as it finds the module in sys.modules[] -- the performance penalty shouldn't be so big. > I assume this means that the internal representation of the imported > module > is being corrupted by something. I found another person with a similar > issue > here: > http://mail.python.org/pipermail/python-dev/2004-March/043306.html - > that is > a long time ago but another multi-threaded app. > I'm happy to use the working method but I'd like to understand what is > going > on a bit more. Can anyone shed any further light? Sorry, I cannot help on this. Seems to happen only with an embedded interpreter and a multithreaded application, and I've never used Python in that scenario. If you could trim your code to a minimal example that shows the faulty behavior, that would be great, so others can test it too and eventually determine what's going on. -- Gabriel Genellina From irmen-NOSPAM- at xs4all.nl Tue Feb 2 19:36:38 2010 From: irmen-NOSPAM- at xs4all.nl (Irmen de Jong) Date: Wed, 03 Feb 2010 01:36:38 +0100 Subject: Your impression of for-novice writings on assertions In-Reply-To: References: Message-ID: <4b68c4c0$0$22920$e4fe514c@news.xs4all.nl> On 2-2-2010 21:54, Alf P. Steinbach wrote: > I've started on ch 3 of my beginner's intro to programming, now delving > into the details of the Python language. > Alf, I think it's a good read so far. I just don't like the smilies that occur in the text. It's a book (or article) that I'm reading, not an instant messaging conversation. Irmen From bartc at freeuk.com Tue Feb 2 20:01:29 2010 From: bartc at freeuk.com (bartc) Date: Wed, 03 Feb 2010 01:01:29 GMT Subject: Python and Ruby In-Reply-To: <2a5ee10d-4da3-4275-936d-3d792f3450e3@p13g2000pre.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <2a5ee10d-4da3-4275-936d-3d792f3450e3@p13g2000pre.googlegroups.com> Message-ID: Jonathan Gardner wrote: > On Feb 2, 7:23 am, "bartc" wrote: >> Jonathan Gardner wrote: >>> One of the bad things with languages like perl and Ruby that call >>> without parentheses is that getting a function ref is not obvious. >>> You need even more syntax to do so. In perl: >> >>> foo(); # Call 'foo' with no args. ... >> If you get rid of the syntax specific to Perl, then having to >> explicitly obtain a function reference, or to dereference the >> result, is not such a big deal: >> >> foo # Call 'foo' with no args. >> bar = foo # Call 'foo; with no args, assign to 'bar' >> bar = &foo # Don't call 'foo', but assign a pointer to it to 'bar' >> bar^ # Call whatever 'bar' is pointing at with no args >> >> (Here I use ^ instead of -> to dereference.) Compared with Python, >> it saves 3 lots of (), but needs & and ^ added. Still a net saving. >> > > On one shoulder, a demon taunts the programmer: "Ohmygosh, you can > save three keystrokes if you introduce an entirely new syntax with odd > squiggles that make no pronounceable sound in the English language! > Perhaps one day, you can program APL in Python!" ... > Thankfully, Guido has banished that demon from the realm of Python a > long time ago. You mean & (bitwise AND in Python) and ^ (bitwise XOR in Python)? :-) -- Bartc From steve at holdenweb.com Tue Feb 2 20:06:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 20:06:49 -0500 Subject: Your impression of for-novice writings on assertions In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > I've started on ch 3 of my beginner's intro to programming, now delving > into the details of the Python language. > > It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at > which is at Google Docs. > > The first topic is about assertions and exceptions. I wonder whether > this text is easy or difficult to understand for a beginner. Or any > improvements that could be made. > I don't think it's helpful in Python to refer to "... variables, which are named locations in memory, ..." because Python specifically eschews this model, and trying to explain assignment (especially of mutable objects) in those terms will lead to conceptual difficulties. Also, why introduce exceptions by talking about "error handling" when the term "exception handling" is hanging in the air? This is also a conceptual thing, since you want to get the reader used to the idea that it's a legitimate programming technique to use exceptions as part of their programs' normal control flow. I'd also recommend taking docstrings a little more seriously, since their use makes code much more self-documenting - someone can import your module and learn its API using the help() function. You may have done that in an earlier chapter. Just a few points for you to think about, and reject if you choose. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From peter.milliken at gmail.com Tue Feb 2 20:21:14 2010 From: peter.milliken at gmail.com (Peter) Date: Tue, 2 Feb 2010 17:21:14 -0800 (PST) Subject: Your impression of for-novice writings on assertions References: Message-ID: On Feb 3, 7:54?am, "Alf P. Steinbach" wrote: > I've started on ch 3 of my beginner's intro to programming, now delving into the > details of the Python language. > > It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at which is at Google Docs. > > The first topic is about assertions and exceptions. I wonder whether this text > is easy or difficult to understand for a beginner. Or any improvements that > could be made. > > Cheers, > > - Alf The only issue I have with what is there is the example - most programmers are not interested in solving mathematical equations and the code is enough to make the reader go cross-eyed. IMO the example code tends to detract from the point you are trying to make about using and how to use assertions. I would suggest a much simpler (to read) example than the one given. Ideally I would like to see more than one example with the examples graded from simple to more complex. A simple example could be just using the assert statement to verify pre-condition (assumptions) made on parameters to a function i.e. def divide (x, y): return x / y The programmer obviously assumed that y will never be 0 - so with one simple example you teach two points: 1. how an assert can be used 2. when programming look for unconscious assumptions Peter P.S. You also raise an interesting issue in my mind when quoting Knuth and siting TeX as an example application with no known bugs - Knuth advocated and used literate programming when writing TeX to achieve "clarity". I believe he (still?) cites the fact that TeX is so bug free because he used Literate Programming to write it (well, at least one reason). So should we be trying to teach literate programming to beginners? You did open that can of worms by quoting and siting Knuth and TeX... :-) From xahlee at gmail.com Tue Feb 2 20:28:10 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Feb 2010 17:28:10 -0800 (PST) Subject: Python's Reference And Internal Model Of Computing Languages Message-ID: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> just wrote this essay. Comment & feedback very welcome. Python's Reference And Internal Model Of Computing Languages Xah Lee, 2010-02-02 In Python, there are 2 ways to clear a hash: ?myHash = {}? and ?myHash.clear()?. What is the difference? ? The difference is that ?myHash={}? simply creates a new empty hash and assigns to myHash, while ?myHash.clear()? actually clear the hash the myHash is pointing to. What does that mean?? Here's a code that illustrates: # python # 2 ways to clear hash and their difference aa = {'a':3, 'b':4} bb = aa aa = {} print bb # prints {'a': 3, 'b': 4} aa = {'a':3, 'b':4} bb = aa aa.clear() print bb # prints {} This is like this because of the ?reference? concept. The opposite alternative, is that everything is a copy, for example in most functional langs. (with respect to programer-visible behavior, not how it is implemented) >From the aspect of the relation of the language source code to the program behavior by the source code, this ?reference?-induced behavior is similar to dynamic scope vs lexicol scope. The former being un- intuitive and hard to understand the latter more intuitive and clear. The former requires the lang to have a internal model of the language, the latter more correspond to source code WYSIWYG. The former being easy to implement and is in early langs, the latter being more popular today. As with many languages that have concept of references, or pointers, this is a complexity that hampers programing progress. The concept of using some sort of ?reference? as part of the language is due to implementation efficiency. Starting with C and others in 1960s up to 1990s. But as time went on, this concept in computer languages are gradually disappearing, as they should. Other langs that have this ?reference? concept as ESSENTIAL part of the semantic of the language, includes: C, C++, Java, Perl, Common Lisp. (of course, each using different terminologies, and each lang faction will gouge the other faction's eyes out about what is the true meaning of terms like ?reference?, ?object?, ?list/sequence/vector/ array/hash?, and absolutely pretend other meanings do not exist. (partly due to, their ignorance of langs other than their own, partly, due to male power struggle nature.)) Languages that do not have any ?reference? or ?object?, or otherwise does not require the programer to have some internal model of source code, are: Mathematica, JavaScript, PHP. (others may include TCL, possibly assembly langs.) For some detail on this, see: Jargons And High Level Languages and Hardware Modeled Computer Languages. --------------------------- (perm url of this essay can be found on my website.) Xah ? http://xahlee.org/ ? From steven at REMOVE.THIS.cybersource.com.au Tue Feb 2 20:42:18 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 01:42:18 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Tue, 02 Feb 2010 09:38:07 +0100, Daniel Fetchinson wrote: >> I like seeing them in the same place as the source file, because when I >> start developing a module, I often end up renaming it multiple times >> before it settles on a final name. When I rename or move it, I delete >> the .pyc file, and that ensures that if I miss changing an import, and >> try to import the old name, it will fail. >> >> By hiding the .pyc file elsewhere, it is easy to miss deleting one, and >> then the import won't fail, it will succeed, but use the old, obsolete >> byte code. > > > Okay, I see your point but I think your argument about importing shows > that python is doing something suboptimal because I have to worry about > .pyc files. Ideally, I only would need to worry about python source > files. That's no different from any language that is compiled: you have to worry about keeping the compiled code (byte code or machine language) in sync with the source code. Python does most of that for you: it automatically recompiles the source whenever the source code's last modified date stamp is newer than that of the byte code. So to a first approximation you can forget all about the .pyc files and just care about the source. But that's only a first approximation. You might care about the .pyc files if: (1) you want to distribute your application in a non-human readable format; (2) if you care about clutter in your file system; (3) if you suspect a bug in the compiler; (4) if you are working with byte-code hacks; (5) if the clock on your PC is wonky; (6) if you leave random .pyc files floating around earlier in the PYTHONPATH than your source files; etc. > There is now a chance to 'fix' (quotation marks because maybe > there is nothing to fix, according to some) this issue and make all pyc > files go away and having python magically doing the right thing. Famous last words... The only ways I can see to have Python magically do the right thing in all cases would be: (1) Forget about byte-code compiling, and just treat Python as a purely interpreted language. If you think Python is slow now... (2) Compile as we do now, but only keep the byte code in memory. This would avoid all worries about scattered .pyc files, but would slow Python down significantly *and* reduce functionality (e.g. losing the ability to distribute non-source files). Neither of these are seriously an option. > A > central pyc repository would be something I was thinking about, but I > admit it's a half baked or not even that, probably quarter baked idea. A central .pyc repository doesn't eliminate the issues developers may have with byte code files, it just puts them somewhere else, out of sight, where they are more likely to bite. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 2 20:49:17 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 01:49:17 GMT Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: > I did not propose obvious module names. I said obvious names like > email.py are bad; more descriptive names like send_email.py are better. But surely send_email.py doesn't just send email, it parses email and receives email as well? -- Steven From gagsl-py2 at yahoo.com.ar Tue Feb 2 20:56:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 02 Feb 2010 22:56:36 -0300 Subject: unable to catch this exception References: Message-ID: En Tue, 02 Feb 2010 08:20:34 -0300, mk escribi?: > Exception in thread Thread-9 (most likely raised during interpreter > shutdown): > Traceback (most recent call last): > File "/var/www/html/cssh.py", line 617, in ssh_connect > : 'NoneType' object has no attribute > 'BadAuthenticationType' So you started several threads, and one of them was in them middle of connecting to somewhere when the program exited, correct? > This happens on interpreter shutdown, even though I do try to catch the > AttributeError exception: > > try: > fake = paramiko.BadAuthenticationType > try: > self.conobj.connect(self.ip, username=self.username, > key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) > loginsuccess = True > except paramiko.BadAuthenticationType, e: # this is line 617 > self.conerror = str(e) > except paramiko.SSHException, e: > self.conerror = str(e) > except socket.timeout, e: > self.conerror = str(e) > except socket.error, e: > self.conerror = str(e) > except AttributeError: > # this happens on interpreter shutdown > self.conerror = 'shutdown' > > > It's clear what happens: paramiko gets its attributes cleared or the > module perhaps gets unloaded and as result "paramiko" label leads to > None, which obviously has no attribute BadAuthenticationType. As part of the interpreter shutdown procedure, module globals are set to None. Code that might be executed in those very precarious circumstances should NOT reference any globals. > However, even though this is surrounded by try .. except AttributeError > block, it evidently isn't catch. How to catch that exception? Or at > least preven displaying this message? You could keep a local reference to those global names; by example, by adding 'fake' default arguments: def ssh_connect(self, other, arguments, paramiko=paramiko, socket=socket): ... or perhaps: def ssh_connect(self, other, arguments): BadAuthenticationType = paramiko.BadAuthenticationType socket_timeout = socket.timeout try: ... except BadAuthenticationType, e: ... except socket_timeout, e: ... -- Gabriel Genellina From wuwei23 at gmail.com Tue Feb 2 21:02:09 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 2 Feb 2010 18:02:09 -0800 (PST) Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <1e88a2b7-089c-41d0-aadd-38f8586e2466@a16g2000pre.googlegroups.com> On Feb 3, 9:02?am, John Nagle wrote: > ? ? I know there's a performance penalty for running Python on a > multicore CPU, but how bad is it? ?I've read the key paper > ("www.dabeaz.com/python/GIL.pdf"), of course. It's a shame that Python 3.x is dead to you, otherwise you'd be able to enjoy the new GIL implementation in 3.2: http://www.dabeaz.com/python/NewGIL.pdf Actually, it looks like you probably still can: + patch for 2.5.4: http://thread.gmane.org/gmane.comp.python.devel/109929 + patch for 2.7? http://bugs.python.org/issue7753 (Can't comment on affinity, though, sorry) From no.email at please.post Tue Feb 2 21:35:55 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 02:35:55 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: (For reasons I don't understand Stephen Hansen's posts don't show in my news server. I became aware of his reply from a passing reference in one of Terry Reedy's post. Then I found Hansen's post online, and then an earlier one, and pasted the relevant portion below.) > First, I don't shadow built in modules. Its really not very hard to avoid. ...*if* you happen to be clairvoyant. I still don't see how the rest of us could have followed this fine principle in the case of numbers.py prior to Python 2.6. > Secondly, I use packages structuring my libraries, and avoid junk > directories of a hundred some odd 'scripts'. (I feel so icky now...) > Third, I don't execute scripts in that directory structure directly, but > instead do python -c 'from package.blah import main; main.main()' or some > such. Usually via some short-cut, or a runner batch file. Breathtaking... I wonder why the Python documentation, in particular the official Python tutorial, is not more forthcoming with these rules. ~K From no.email at please.post Tue Feb 2 21:36:49 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 02:36:49 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: In Terry Reedy writes: >On 2/2/2010 2:43 PM, kj wrote: >> In Terry Reedy writes: >> >>> On 2/2/2010 9:13 AM, kj wrote: >> >>>>> As for fixing it, unfortunately it's not quite so simple to fix without >>>>> breaking backwards-compatibility. The opportunity to do so for Python 3.0 >>>>> was missed. >>>> >>>> This last point is to me the most befuddling of all. Does anyone >>>> know why this opportunity was missed for 3.0? Anyone out there >>>> with the inside scoop on this? Was the fixing of this problem >>>> discussed in some PEP or some mailing list thread? (I've tried >>>> Googling this but did not hit on the right keywords to bring up >>>> the deliberations I'm looking for.) >> >>> There was a proposal to put the whole stdlib into a gigantic package, so >>> that >> >>> import itertools >> >>> would become, for instance >> >>> import std.itertools. >> >>> Guido rejected that. I believe he both did not like it and was concerned >>> about making upgrade to 3.x even harder. The discussion was probably on >>> the now closed py3k list. >> >> >> Thanks. I'll look for this thread. >Stephen Hansen's post explains a bit more than I did. To supplement his >explanation: since print *was* a keyword, every use of 'print' in 2.x >denotes a print statement with standard semantics. Therefore 2to3 >*knows* what the statement means and can translate it. On the other >hand, 'import string' usually means 'import the string module of the >stdlib', but it could mean 'import my string module'. This depends on >the execution environment. Moreover, I believe people have intentionally >shadowed stdlib modules. So. like it or not, 2to3 cannot know what >'import string' means. Thanks, this dispels some of the mystery. ~K From harry.python at gmail.com Tue Feb 2 21:42:05 2010 From: harry.python at gmail.com (gashero) Date: Tue, 2 Feb 2010 18:42:05 -0800 (PST) Subject: libpcap and python References: Message-ID: <94d87bff-ec51-48c7-80c8-2ef7320f75da@a17g2000pre.googlegroups.com> On 2?1?, ??8?47?, Mag Gam wrote: > Hello All, > > I used tcpdump to capture data on my network. I would like to analyze > the data using python -- currently using ethereal and wireshark. > > I would like to get certain type of packets (I can get the hex code > for them), what is the best way to do this? Lets say I want to capture > all events of `ping localhost` > > TIA You need python module "pypcap" or "pcapy" to capture the packet, and the you can use Python to analyze it. To decode the internet packet you can use "dpkt". Good Luck! From ryan at rfk.id.au Tue Feb 2 21:46:59 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Wed, 03 Feb 2010 13:46:59 +1100 Subject: Python's Reference And Internal Model Of Computing Languages In-Reply-To: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: <1265165219.2711.13.camel@durian> > On Tue, 2010-02-02 at 17:28 -0800, Xah Lee wrote: I know, I know, do not feed the trolls. But this is just so *wrong* that I can't help myself. > In Python, there are 2 ways to clear a hash: No, no there's not. There's one way to clear a hash and there's one way to assign a new object to a variable. > ?myHash = {}? and > ?myHash.clear()?. What is the difference? > The difference is that ?myHash={}? simply creates a new empty hash and > assigns to myHash, while ?myHash.clear()? actually clear the hash the > myHash is pointing to. > > What does that mean?? Here's a code that illustrates: > > # python > # 2 ways to clear hash and their difference > aa = {'a':3, 'b':4} > bb = aa > aa = {} > print bb # prints {'a': 3, 'b': 4} > > aa = {'a':3, 'b':4} > bb = aa > aa.clear() > print bb # prints {} > > This is like this because of the ?reference? concept. ...snip inane babble... > Languages that do not have any ?reference? or ?object?, or otherwise > does not require the programer to have some internal model of source > code, are: Mathematica, JavaScript, PHP. (others may include TCL, > possibly assembly langs.) Just so we're all clear exactly how much thought has gone into this little rant, here's a transcript from a JavaScript session: var aa = {}; var bb = aa; aa.hello = "world"; alert(bb.hello) --> "world" delete bb.hello alert(aa.hello) --> "undefined" OMFG, references!! Come to think of it, the JavaScript and Python object models are really very similar. I'm genuinely curious now - what little sprinkle of magic fairy dust has earned JavaScript objects the Xah Lee seal of approval while Python objects miss out? 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From no.email at nospam.invalid Tue Feb 2 22:29:57 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 02 Feb 2010 19:29:57 -0800 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: <7xiqafro7e.fsf@ruckus.brouhaha.com> Ryan Kelly writes: > I know, I know, do not feed the trolls. But this is just so *wrong* > that I can't help myself. See: http://xkcd.com/386/ From xahlee at gmail.com Tue Feb 2 22:36:38 2010 From: xahlee at gmail.com (Xah Lee) Date: Tue, 2 Feb 2010 19:36:38 -0800 (PST) Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: ()On Feb 2, 6:46?pm, Ryan Kelly wrote: > > On Tue, 2010-02-02 at 17:28 -0800, Xah Lee wrote: > > I know, I know, do not feed the trolls. ?But this is just so *wrong* > that I can't help myself. > > > In Python, there are 2 ways to clear a hash: > > No, no there's not. ?There's one way to clear a hash and there's one way > to assign a new object to a variable. > > > > > > > ??myHash = {}? and > > ?myHash.clear()?. What is the difference? > > The difference is that ?myHash={}? simply creates a new empty hash and > > assigns to myHash, while ?myHash.clear()? actually clear the hash the > > myHash is pointing to. > > > What does that mean?? Here's a code that illustrates: > > > # python > > # 2 ways to clear hash and their difference > > aa = {'a':3, 'b':4} > > bb = aa > > aa = {} > > print bb # prints {'a': 3, 'b': 4} > > > aa = {'a':3, 'b':4} > > bb = aa > > aa.clear() > > print bb # prints {} > > > This is like this because of the ?reference? concept. > > ...snip inane babble... > > > Languages that do not have any ?reference? or ?object?, or otherwise > > does not require the programer to have some internal model of source > > code, are: Mathematica, JavaScript, PHP. (others may include TCL, > > possibly assembly langs.) > > Just so we're all clear exactly how much thought has gone into this > little rant, here's a transcript from a JavaScript session: > > ? var aa = {}; > ? var bb = aa; > ? aa.hello = "world"; > ? alert(bb.hello) ?--> ?"world" > ? delete bb.hello > ? alert(aa.hello) ?--> ?"undefined" > > OMFG, references!! > > Come to think of it, the JavaScript and Python object models are really > very similar. ?I'm genuinely curious now - what little sprinkle of magic > fairy dust has earned JavaScript objects the Xah Lee seal of approval > while Python objects miss out? Thanks. You are right. I think i put JavaScript there without much thinking. Xah From steve at holdenweb.com Tue Feb 2 22:53:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 02 Feb 2010 22:53:44 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: kj wrote: > > (For reasons I don't understand Stephen Hansen's posts don't show > in my news server. I became aware of his reply from a passing > reference in one of Terry Reedy's post. Then I found Hansen's post > online, and then an earlier one, and pasted the relevant portion > below.) > > > >> First, I don't shadow built in modules. Its really not very hard to avoid. > > ...*if* you happen to be clairvoyant. I still don't see how the rest of us > could have followed this fine principle in the case of numbers.py > prior to Python 2.6. > Clearly the more you know about the standard library the less likely this is to be a problem. Had you been migrqating from an earlier version the breakage would have alerted you to look for some version-dependent difference. >> Secondly, I use packages structuring my libraries, and avoid junk >> directories of a hundred some odd 'scripts'. > > (I feel so icky now...) > Be as flippant as you like, but that is good advice. >> Third, I don't execute scripts in that directory structure directly, but >> instead do python -c 'from package.blah import main; main.main()' or some >> such. Usually via some short-cut, or a runner batch file. > > Breathtaking... I wonder why the Python documentation, in particular > the official Python tutorial, is not more forthcoming with these > rules. > Because despite the fact that this issue has clearly bitten you badly enough to sour you against the language, such issues are remarkably rare in practice and normally rather easier to debug. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From pavlovevidence at gmail.com Tue Feb 2 22:55:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 2 Feb 2010 19:55:15 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> Message-ID: <8104faf3-c4ea-4b1f-8316-f8b17f53554b@q2g2000pre.googlegroups.com> On Feb 2, 5:49?pm, Steven D'Aprano wrote: > On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: > > I did not propose obvious module names. ?I said obvious names like > > email.py are bad; more descriptive names like send_email.py are better. > > But surely send_email.py doesn't just send email, it parses email and > receives email as well? No, it doesn't. Carl Banks From g.bogle at auckland.no.spam.ac.nz Tue Feb 2 23:03:08 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 03 Feb 2010 17:03:08 +1300 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> <7xiqafro7e.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Ryan Kelly writes: >> I know, I know, do not feed the trolls. But this is just so *wrong* >> that I can't help myself. > > See: http://xkcd.com/386/ :-) From steven at REMOVE.THIS.cybersource.com.au Tue Feb 2 23:52:42 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 04:52:42 GMT Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> <8104faf3-c4ea-4b1f-8316-f8b17f53554b@q2g2000pre.googlegroups.com> Message-ID: On Tue, 02 Feb 2010 19:55:15 -0800, Carl Banks wrote: > On Feb 2, 5:49?pm, Steven D'Aprano > wrote: >> On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: >> > I did not propose obvious module names. ?I said obvious names like >> > email.py are bad; more descriptive names like send_email.py are >> > better. >> >> But surely send_email.py doesn't just send email, it parses email and >> receives email as well? > > No, it doesn't. Nevertheless, as a general principle, modules will tend to be multi- purpose and/or generic. How would you rename the math or random modules to be less "obvious" and more "descriptive"? And of course, the less obvious the name, the harder it becomes for people to find and use it. Which extreme would you rather? import zip import compress_and_decompress_files_to_zip_archives I'm sympathetic to the position you're taking. It's not bad advice at all, but I think you're over-selling it as a complete solution to the problem of name clashes. I think it can only slightly alleviate the problem of name clashes, not eliminate it. -- Steven From john at castleamber.com Wed Feb 3 00:08:39 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Feb 2010 23:08:39 -0600 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <87bpg6sy7c.fsf@castleamber.com> Xah Lee writes: > (12:12:30 PM) You have been kicked by dash: (No.) Oh noes, someone is harrassing poor Xah the Usenet spammer. You have been and still are a major pain in the ass to a lot of Usenet users, and still surprised that you're not making friends. I mean, what did you want to do on IRC? Copy paste line by line one of your "fine" articles, followed by a link to your site. And what the hell were you doing, asking a Python question in #python? Shouldn't that be asked the Xah way in #perl or #lisp? -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Wed Feb 3 00:11:49 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Feb 2010 23:11:49 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> Message-ID: <877hqusy22.fsf@castleamber.com> Jonathan Gardner writes: > I can explain, in an hour, every single feature of the Python language > to an experienced programmer, all the way up to metaclasses, Either you're a hell of a talker, or I am far, far away from being an experienced programmer. It's advocacy like this, IMO, that keeps people away from a language, because you can't feel nothing but a failure after a statement like this. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Wed Feb 3 00:29:21 2010 From: john at castleamber.com (John Bokma) Date: Tue, 02 Feb 2010 23:29:21 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <7e5feb14-ac34-4246-91f5-dee88aedf159@u19g2000prh.googlegroups.com> <87sk9knz2b.fsf@castleamber.com> <2e057a9a-d842-4ca3-ac16-08bb2e1fe590@b1g2000prc.googlegroups.com> Message-ID: <873a1isx8u.fsf@castleamber.com> Jonathan Gardner writes: > On Feb 1, 6:36?pm, John Bokma wrote: [..] >> It should be $bar = \&foo >> Your example actually calls foo... > > I rest my case. I've been programming perl professionally since 2000, > and I still make stupid, newbie mistakes like that. Uhm, in another post you wrote that you could explain Python in an hour to an experienced programmer and you *still* make mistakes like that in Perl!? By the way, the language is called Perl. If you write "I've been programming perl" in a Perl related group some people might read it as that you've been working on the internals of the perl executable (in C) >> > One is simple, consistent, and easy to explain. The other one requires >> > the introduction of advanced syntax and an entirely new syntax to make >> > function calls with references. >> >> The syntax follows that of referencing and dereferencing: >> >> $bar = \@array; ? ? ? # bar contains now a reference to array >> $bar->[ 0 ]; ? ? ? ? ?# first element of array referenced by bar >> $bar = \%hash; ? ? ? ?# bar contains now a reference to a hash >> $bar->{ key }; ? ? ? ?# value associated with key of hash ref. by bar >> $bar = \&foo; ? ? ? ? # bar contains now a reference to a sub >> $bar->( 45 ); ? ? ? ? # call sub ref. by bar with 45 as an argument >> >> Consistent: yes. New syntax? No. >> > > Except for the following symbols and combinations, which are entirely > new and different from the $@% that you have to know just to use > arrays and hashes. > > \@, ->[ ] @array, one item: $array[ 1 ]; $arrayref, one item: $arrayref->[ 1 ]; > \%, ->{ } %hash, one item: $hash{ key }; hence: $hashref, one item: $hash->{ key } > \&, ->( ) should now be clear ;-) You *should* have no problem with that if you have been programming professionally Perl since 2000 IMNSHO. Otherwise print my post or copy it on a post-it note ;-). Remember that all this was added to Perl in version 5. So it had to be added in a way that wouldn't break Perl 4. Perl is, in my experience quite good in backwards compatibility. Quite some Perl modules on CPAN work from 5.00x-5.10 and most likely will work without trouble in 5.12. > By the way: > * How do you do a hashslice on a hashref? I will reply like it's a genuine question, and not like "Oh, look, how silly Perl works". I don't care about that much. I do like Perl and am starting to like Python. @$hashref{ 'key1', 'key2', 'key3' }; > * How do you invoke reference to a hash that contains a reference to > an array that contains a reference to a function? I guess you mean: $hashref->{ key }[ index ]( arguments ); The long version is: $hashref->{ key }->[ index ]->( arguments ); [ Python advocacy snipped] > I'd rather think of the task at hand than what each of the funky > symbols on my keyboard mean. Then just quit programming Perl ;-) Perl has always come naturally to me, no idea why. Recently I said to a close friend: Python is like my desk, which I prefer to keep clean and neat. Perl is like my livingroom, which I prefer to keep clean and neat to some extend, but some mess is allowed. For example, the cat can be there. Toys of my daughter are allowed to be all over the place. A pleasant mess, but not too much. I won't repeat what I said about PHP ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 00:59:03 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 05:59:03 GMT Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> Message-ID: On Tue, 02 Feb 2010 23:11:49 -0600, John Bokma wrote: > Jonathan Gardner writes: > >> I can explain, in an hour, every single feature of the Python language >> to an experienced programmer, all the way up to metaclasses, > > Either you're a hell of a talker, or I am far, far away from being an > experienced programmer. It's advocacy like this, IMO, that keeps people > away from a language, because you can't feel nothing but a failure after > a statement like this. Surely you're exaggerating? Without making any aspersions towards Jonathan either way, the Internet is full of both blowhards and geniuses. Anyone who lets the off-the-cup claims of either ruin their self-confidence is unlikely to be thinking about learning Python, they're probably sitting alone in a dark room staring as the walls close in. Either that or on MySpace. -- Steven From hirotaka.niitsuma at gmail.com Wed Feb 3 01:01:22 2010 From: hirotaka.niitsuma at gmail.com (Niitsuma Hirotaka) Date: Wed, 3 Feb 2010 15:01:22 +0900 Subject: calling python from lisp Message-ID: <6ce56e1a1002022201y9654271p9df4afc11dfc4d8b@mail.gmail.com> Autor: Martin Rubey Data: 2008-10-29 09:34 +900 Dla: python-list CC: sage-devel Temat: calling python from lisp http://archives.free.net.ph/message/20081029.003410.172560ac.pl.html >sys:1: RuntimeWarning: Python C API version mismatch for module pol: This Python has API version 1013, module pol has version 1011. I modified some of pythononlisp including this. http://www2s.biglobe.ne.jp/~niitsuma/pythononlispex.html plz try. From mensanator at aol.com Wed Feb 3 01:03:54 2010 From: mensanator at aol.com (Mensanator) Date: Tue, 2 Feb 2010 22:03:54 -0800 (PST) Subject: ANN: GMPY 1.11 released References: Message-ID: On Feb 2, 12:45?am, casevh wrote: > Everyone, > > I'm pleased to annouce the final release of GMPY 1.11. > GMPY is a wrapper for the MPIR or GMP multiple-precision > arithmetic library. GMPY 1.11 is available for download from: > > http://code.google.com/p/gmpy/ > > In addition to support for Python 3.x, there are several new > features in this release: > > - Even faster conversion to/from Python longs. > - Performance improvements by reducing function overhead. > - Performance improvements by improved caching. > - Support for cdivmod, fdivmod, and tdivmod. > - Unicode strings are accepted on Python 2.x and 3.x. > - Fixed regression in GMPY 1.10 where True/False were no > ? longer recognized. > > Changes since 1.11rc1: > - Recognizes GMP 5. > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > Comments on provided binaries > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > 1.3.1 and will automatically recognize the CPU type and use code > optimized for the CPU at runtime. The 64-bit Windows installers were > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > instructions are included if you want to compile your own binary. > > Please report any issues! My previous replies didn't show up. Something to do the .announce group? I'll trim that and try again. Sorry if they show up eventually. Two issues: 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply >>> gmpy.version() '1.11' Aren't these different versions? How are we supposed to tell them apart? 2] Is it true that the only changes since 1.11rc1 are not applicable to me since - I'm not using Windows - whether it recognizes GMP 5 is moot as GMP 5 cannot be compiled on a Mac (according to GMP site) Is it possible GMP's problems with getting GMP 5 to compile are the same ones I had with 3.1 on Snow Leopard? (They bemoan not having a set of every Mac system.) Think it would behoove me to try it? > > casevh From john at castleamber.com Wed Feb 3 01:20:18 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 00:20:18 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> Message-ID: <87pr4msuvx.fsf@castleamber.com> Steven D'Aprano writes: > On Tue, 02 Feb 2010 23:11:49 -0600, John Bokma wrote: > >> Jonathan Gardner writes: >> >>> I can explain, in an hour, every single feature of the Python language >>> to an experienced programmer, all the way up to metaclasses, >> >> Either you're a hell of a talker, or I am far, far away from being an >> experienced programmer. It's advocacy like this, IMO, that keeps people >> away from a language, because you can't feel nothing but a failure after >> a statement like this. > > Surely you're exaggerating? No, because if I was I would've put a smiley there somewhere. I am learning Python, for a time to be honest. I can manage in the language quite well. I consider myself quite an experienced Perl programmer, I have no problems with the constructs Jonathan elsewhere in this thread claims to have problems with after 10 years of professional Perl programming. They come natural to me. But I don't see myself being able to understand every Python feature in a talk of an hour *with* the current understanding of Python I have (read halfway through Programming In Python 3, read selected chapters on decorators, etc.). > Without making any aspersions towards Jonathan either way, the Internet > is full of both blowhards and geniuses. Anyone who lets the off-the-cup > claims of either ruin their self-confidence is unlikely to be thinking > about learning Python, they're probably sitting alone in a dark room > staring as the walls close in. I am quite serious about learning Python, I do write professionally in it [1], but I am convinced that I need at least several months more of studying to feel comfortable with most (not even all) of Python. To me a much more relastic view on learning a programming language is: http://norvig.com/21-days.html [1] very small programs, and my customer is fully aware of that I am learning a new language but trust me, which is great. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Wed Feb 3 01:27:37 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 00:27:37 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <87pr4msuvx.fsf@castleamber.com> Message-ID: <87ljfasujq.fsf@castleamber.com> John Bokma writes: > Steven D'Aprano writes: > >> On Tue, 02 Feb 2010 23:11:49 -0600, John Bokma wrote: >> >>> Jonathan Gardner writes: >>> >>>> I can explain, in an hour, every single feature of the Python language >>>> to an experienced programmer, all the way up to metaclasses, >>> >>> Either you're a hell of a talker, or I am far, far away from being an >>> experienced programmer. It's advocacy like this, IMO, that keeps people >>> away from a language, because you can't feel nothing but a failure after >>> a statement like this. >> >> Surely you're exaggerating? > > No, because if I was I would've put a smiley there somewhere. I am > learning Python, for a time to be honest. I can manage in the language > quite well. Clarification: for a beginner that is. > [1] very small programs, and my customer is fully aware of that I am > learning a new language but trust me, which is great. Should've been "but trusts me,". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 01:33:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 01:33:20 -0500 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <1e88a2b7-089c-41d0-aadd-38f8586e2466@a16g2000pre.googlegroups.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <1e88a2b7-089c-41d0-aadd-38f8586e2466@a16g2000pre.googlegroups.com> Message-ID: On 2/2/2010 9:02 PM, alex23 wrote: > On Feb 3, 9:02 am, John Nagle wrote: >> I know there's a performance penalty for running Python on a >> multicore CPU, but how bad is it? I've read the key paper >> ("www.dabeaz.com/python/GIL.pdf"), of course. > > It's a shame that Python 3.x is dead to you, otherwise you'd be able > to enjoy the new GIL implementation in 3.2: http://www.dabeaz.com/python/NewGIL.pdf > > Actually, it looks like you probably still can: > + patch for 2.5.4: http://thread.gmane.org/gmane.comp.python.devel/109929 > + patch for 2.7? http://bugs.python.org/issue7753 The patch was rejected for 2.7 (and earlier) because it could break code as explained in the discussion. One would have to apply and compile their own binary. From swrath at gmail.com Wed Feb 3 01:38:56 2010 From: swrath at gmail.com (sWrath swrath) Date: Tue, 2 Feb 2010 22:38:56 -0800 (PST) Subject: newbie qns : how do i use xmldiff? Message-ID: Hi , I am pretty new to python , and reading up on it. Basically I am trying to compare xml files . I know difflib have it but it does not work out as expected. I was looking at xmldiff , unfortunately I am not able to find documentation how to call it from python. Anyone knows a link or doc to it as I have been looking high and low for few days? lastly , is there a py (or algorithm) where it behaves exactly like diff ? Greatly appreciated. Thanks john From lanyjie at yahoo.com Wed Feb 3 01:43:51 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Tue, 2 Feb 2010 22:43:51 -0800 (PST) Subject: expy 0.5.2 released Message-ID: <857729.7198.qm@web54208.mail.re2.yahoo.com> Hi, expy is an expressway to extend python. in release 0.5.2, expy now supports custom exceptions, besides all built-in ones, and exception handling is made easy. for more info, see http://expy.sourceforge.net/ cheers, Yingjie From simonzack at gmail.com Wed Feb 3 03:30:41 2010 From: simonzack at gmail.com (Simon zack) Date: Wed, 3 Feb 2010 16:30:41 +0800 Subject: exec within function Message-ID: hi, I'm not sure how I can use exec within a function correctly here is the code i'm using: def a(): exec('b=1') print(b) a() this will raise an error, but I would like to see it outputting 1 thanks smk -------------- next part -------------- An HTML attachment was scrubbed... URL: From news123 at free.fr Wed Feb 3 03:32:58 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 09:32:58 +0100 Subject: simple and fast platform independent IPC Message-ID: <4b6934ba$0$18396$426a34cc@news.free.fr> Hi, I wondered what IPC library might be best simplest for following task? I'm having a few python scripts all running on the same host (linux or win), which are started manually in random order. (no common parent process) Each process might be identified by an integer (1,2,3) or by a symbolic name ( 'dad' , 'mom' , 'dog' ) these scripts want to send short messages to each other ( mostly integers, max a few bytes, short string), which would be enqueued in message queues of the receiving process. example: 'dad' wants to tell 'mom': 'cook' 'dog' wants to tell 'dad' : 'feedme' 'mom' wants to tell 'dad' : 'cookyourself' the receiver dos not necesarily have to know who sent the message a message shall be dropped silently if the receiving process is not running a message shall be reliably delivered if the receiving process is up xmlrpc seems to be a little heavy for such tasks. signals don't allow to exchange data a shared memory message queue would probably a good solution, but python's Multiprocessing.Queue seems to require a common parent process thanks a lot for any ideas / suggestions N N From masklinn at masklinn.net Wed Feb 3 03:50:26 2010 From: masklinn at masklinn.net (Masklinn) Date: Wed, 3 Feb 2010 09:50:26 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <4B685860.4000903@sequans.com> References: <4B685860.4000903@sequans.com> Message-ID: <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> On 2 Feb 2010, at 17:52 , Jean-Michel Pichavant wrote: > > Masklinn wrote: >> Jean-Michel Pichavant wrote: >> >>> To add a custom level, I would proceed that way: >>> >>> logging.ALERT = 45 >>> logging.addLevelName(logging.ALERT, 'ALERT !!') >>> logging.getLogger().log(logging.ALERT, 'test') >>> >>> Passing a string to the log method as you did is incorrect. >>> >> >> I know it's currently incorrect. My point was more along the line that there was *no reason* for it to be incorrect. logging already contains all the tools for log('PANTS_ON_FIRE') to be allowed >> > The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. That's not a reason, that's just what currently happens. I know it doesn't work, and I know why, I went and checked the code. But there's no fundamental reason why you couldn't use a level *name* instead of a level code. And indeed, in most parts of logging you can (including but not limited to the configuration of handlers and loggers) >> >>> Regarding your first point, I guess it's anti pattern. One way to do it: >>> 1/ Configure the root logger with the lowest value 0, so the root logger does not filter any level. >>> 2/ Configure each of your logger with the correct level >>> >>> That way you can configure your '0' logger as you (badly :o)) named it with one level, and configure a potential '1' logger with another level. Don't bother with propagation. That way you won't need to duplicate your handlers on every logger. >>> >> >> re logger 0, no need for complex name for a test case (and it allowed me to create easy-to-remember 0.1 and 0.1.2 if needed) >> >> Re your answer, from what I understand you want the root logger to NOTSET and then each child logger with its correct level? But that's not a solution, each and every level will *still* require a handler explicitly configured on it. That's in fact very much my issue: logging refuses that a logger be handler-less in a config file, it's mandatory to configure a handler any time a logger is configured. >> > the field handlers must be defined even if empty. Ah, interesting, I didn't think it could be defined as empty. Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? From timothy.tsvetkov at gmail.com Wed Feb 3 04:21:44 2010 From: timothy.tsvetkov at gmail.com (Timothy N. Tsvetkov) Date: Wed, 3 Feb 2010 01:21:44 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> Message-ID: <4da2372c-954c-46b8-a6e9-2768bce812f5@l19g2000yqb.googlegroups.com> On Jan 28, 2:29?am, Jonathan Gardner wrote: > On Jan 27, 5:47?am, Simon Brunning wrote: > > > > > I think Python is a little cleaner, but I'm sure you'd find Ruby fans > > who'd argue the complete opposite. > > Are you sure about that? > > There's a lot of line noise in Ruby. How are you supposed to pronounce > "@@"? What about "{|..| ... }"? > > There's a lot of "magic" in Ruby as well. For instance, function calls > are made without parentheses. Blocks can only appear as the first > argument. There's a lot more, if you put your mind to it. > > Indentation is also optional in Ruby. You can quickly fool a newbie by > not indenting your code properly, which is impossible in Python. > > Python is much, much cleaner. I don't know how anyone can honestly say > Ruby is cleaner than Python. I will. I developed on both (Python was first) and I think that ruby I very clean and maybe cleaner than Python. Also I don't know any situation where you need to pronounce your code symbol by symbol. You might need to pronounce some semantics. And you're wrong with blocks. About indent your right. It helps newbies indent code becouse they must to. But most of professional developers started with Pascal and then C and they all indent well :) it is about culture and it is what about teacher should say. From gagsl-py2 at yahoo.com.ar Wed Feb 3 04:29:38 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 03 Feb 2010 06:29:38 -0300 Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: En Wed, 03 Feb 2010 05:32:58 -0300, News123 escribi?: > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent > process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) > > these scripts want to send short messages to each other ( mostly > integers, max a few bytes, short string), which would be enqueued in > message queues of the receiving process. > > example: > > 'dad' wants to tell 'mom': 'cook' > 'dog' wants to tell 'dad' : 'feedme' > 'mom' wants to tell 'dad' : 'cookyourself' Try using a named pipe between each pair of processes (os.mkfifo + open on Linux, open(r"\\.\pipe\desired_name", ...) on Windows) -- Gabriel Genellina From vinay_sajip at yahoo.co.uk Wed Feb 3 04:34:34 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 3 Feb 2010 01:34:34 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> On Feb 3, 8:32?am, News123 wrote: > Hi, > > I wondered what IPC library might be best simplest for following task? > > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) > > these scripts want to send short messages to each other ( mostly > integers, max a few bytes, short string), which would be enqueued in > message queues of the receiving process. > > example: > > 'dad' wants to tell 'mom': 'cook' > 'dog' wants to tell 'dad' : 'feedme' > 'mom' wants to tell 'dad' : 'cookyourself' > > the receiver dos not necesarily have to know who sent the message > > a message shall be dropped silently if the receiving process is not running > > a message shall be reliably delivered if the receiving process is up > > xmlrpc seems to be a little heavy for such tasks. > > signals don't allow to exchange data > > a shared memory message queue would probably a good solution, but > python's Multiprocessing.Queue ?seems to require a common parent process > > thanks a lot for any ideas / suggestions > > N > > N Gabriel's suggestion is very good; if you need something which is a little more like RPC but still quite lightweight, consider Pyro (http://pyro.sourceforge.net/) Regards, Vinay Sajip From tinnews at isbd.co.uk Wed Feb 3 04:45:16 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 3 Feb 2010 09:45:16 +0000 Subject: pyfltk ducumentation question Message-ID: I have just installed pyfltk version 1.1.4 on my xubuntu 9.10 system, it's working OK and a fairly trivial little program I have written is able to pop up a GUI window. However I'm now a bit stuck as the documentation seems a little sparse. For example I'm using FL_Multiline_Output and can't find enough detail to enable me to use its methods. I start from:- http://pyfltk.sourceforge.net/docs/CH3_Common.html This tells me that there is a FL_Multiline_Output widget and that it has a value() method, this is what I have used to display some text in my little application. When I click on the FL_Multiline_Output link in the above page it takes me to:- http://pyfltk.sourceforge.net/docs/fltk.html#Fl_Multiline_Output which lists all the methods and other bits and pieces belonging to Fl_Multiline_Output but as far as I can see that's it, there is no further information. The methods are links but they only link to themselves, when you click on them the browser moves the method to the top of the display window. Am I missing something obvious or do I need the FLTK documentation to give me the detail I need? -- Chris Green From no.email at please.post Wed Feb 3 05:01:55 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 10:01:55 +0000 (UTC) Subject: test -- please ignore Message-ID: (my replies in a different comp.lang.python thread are getting rejected by the server; i have no problem posting to alt.test; and i'm trying to toubleshoot the problem further.) From peloko45 at gmail.com Wed Feb 3 05:39:58 2010 From: peloko45 at gmail.com (Joan Miller) Date: Wed, 3 Feb 2010 02:39:58 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> Message-ID: <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> On 3 feb, 09:34, Vinay Sajip wrote: > On Feb 3, 8:32?am, News123 wrote: > > > > > Hi, > > > I wondered what IPC library might be best simplest for following task? > > > I'm having a few python scripts all running on the same host (linux or > > win), which are started manually in random order. (no common parent process) > > Each process might be identified by an integer (1,2,3) or by a symbolic > > name ( 'dad' , 'mom' , 'dog' ) > > > these scripts want to send short messages to each other ( mostly > > integers, max a few bytes, short string), which would be enqueued in > > message queues of the receiving process. > > > example: > > > 'dad' wants to tell 'mom': 'cook' > > 'dog' wants to tell 'dad' : 'feedme' > > 'mom' wants to tell 'dad' : 'cookyourself' > > > the receiver dos not necesarily have to know who sent the message > > > a message shall be dropped silently if the receiving process is not running > > > a message shall be reliably delivered if the receiving process is up > > > xmlrpc seems to be a little heavy for such tasks. > > > signals don't allow to exchange data > > > a shared memory message queue would probably a good solution, but > > python's Multiprocessing.Queue ?seems to require a common parent process > > > thanks a lot for any ideas / suggestions > > > N > > > N > > Gabriel's suggestion is very good; if you need something which is a > little more like RPC but still quite lightweight, consider Pyro > (http://pyro.sourceforge.net/) > > Regards, > > Vinay Sajip I've read that Pyro is not safe. Anyway, you have in mind that respect to speed: shared memory > named pipes > Unix domain socket > TCP socket I don't sure about if the message queues would be faster that Unix domain sockets Another thing. Using shared memory would be as to use a single thread but using message queues would be as multiple-threading. From news123 at free.fr Wed Feb 3 05:46:16 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 11:46:16 +0100 Subject: simple and fast platform independent IPC In-Reply-To: References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <4b6953f8$0$17133$426a74cc@news.free.fr> Hi Gabriel, I'll look at it. I wasn't aware about named pipes for windows. bye N Gabriel Genellina wrote: > En Wed, 03 Feb 2010 05:32:58 -0300, News123 escribi?: > >> I'm having a few python scripts all running on the same host (linux or >> win), which are started manually in random order. (no common parent >> process) >> Each process might be identified by an integer (1,2,3) or by a symbolic >> name ( 'dad' , 'mom' , 'dog' ) >> >> these scripts want to send short messages to each other ( mostly >> integers, max a few bytes, short string), which would be enqueued in >> message queues of the receiving process. >> >> example: >> >> 'dad' wants to tell 'mom': 'cook' >> 'dog' wants to tell 'dad' : 'feedme' >> 'mom' wants to tell 'dad' : 'cookyourself' > > Try using a named pipe between each pair of processes (os.mkfifo + open > on Linux, open(r"\\.\pipe\desired_name", ...) on Windows) > From jeanmichel at sequans.com Wed Feb 3 05:50:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 03 Feb 2010 11:50:19 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> Message-ID: <4B6954EB.6010004@sequans.com> >> The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. >> > That's not a reason, that's just what currently happens. I know it doesn't work, and I know why, I went and checked the code. But there's no fundamental reason why you couldn't use a level *name* instead of a level code. And indeed, in most parts of logging you can (including but not limited to the configuration of handlers and loggers) > > You don't neeed to check the code for that ! It is written in the documentation. The logging module designer choose to ask for a level, not a level name, possibly because 2 different levels can have the same name. >> >> the field handlers must be defined even if empty. >> > Ah, interesting, I didn't think it could be defined as empty. > > Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? > > 'completeley nonsensical' is overstating. It make sense to state that your handler list is empty, when it is empty. Having no field at all could possibly mean the same, but it's often better that have one consisten way to interface with a module. JM From mail at timgolden.me.uk Wed Feb 3 05:54:19 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 03 Feb 2010 10:54:19 +0000 Subject: simple and fast platform independent IPC In-Reply-To: <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> Message-ID: <4B6955DB.2060604@timgolden.me.uk> [News123] >>> I wondered what IPC library might be best simplest for following task? ... >>> xmlrpc seems to be a little heavy for such tasks. >> >>> signals don't allow to exchange data >> >>> a shared memory message queue would probably a good solution, but >>> python's Multiprocessing.Queue seems to require a common parent process [Vinay Sajip] >> Gabriel's suggestion is very good; if you need something which is a >> little more like RPC but still quite lightweight, consider Pyro >> (http://pyro.sourceforge.net/) [peloko45 at gmail.com] > I've read that Pyro is not safe. That's a fairly broad thing to say. I've read lots of things. What does "is not safe" mean, in any case? I assume you've got a valid concern in mind which is worth passing on to a would-be user, but what exactly is it? FWIW I've used Pyro on and off over the years without any problems. Certainly my computer's never blown up as a result of using it. Obviously Pyro is Python-only so interaction with non-Python code would be problematic. But the OP only mentions Python scripts so hopefully that wouldn't be an issue... >Anyway, you have in mind that respect to speed: > > shared memory> named pipes> Unix domain socket> TCP socket True, but the OP didn't mention speed; rather simplicity. Not saying it isn't a consideration but premature optimisation and all that... > Another thing. Using shared memory would be as to use a single thread > but using message queues would be as multiple-threading. And therefore...? I think you need to make your points more clearly. TJG From fetchinson at googlemail.com Wed Feb 3 05:55:57 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 3 Feb 2010 11:55:57 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >>> I like seeing them in the same place as the source file, because when I >>> start developing a module, I often end up renaming it multiple times >>> before it settles on a final name. When I rename or move it, I delete >>> the .pyc file, and that ensures that if I miss changing an import, and >>> try to import the old name, it will fail. >>> >>> By hiding the .pyc file elsewhere, it is easy to miss deleting one, and >>> then the import won't fail, it will succeed, but use the old, obsolete >>> byte code. >> >> >> Okay, I see your point but I think your argument about importing shows >> that python is doing something suboptimal because I have to worry about >> .pyc files. Ideally, I only would need to worry about python source >> files. > > That's no different from any language that is compiled: you have to worry > about keeping the compiled code (byte code or machine language) in sync > with the source code. True. > Python does most of that for you: it automatically recompiles the source > whenever the source code's last modified date stamp is newer than that of > the byte code. So to a first approximation you can forget all about > the .pyc files and just care about the source. True, but the .pyc file is lying around and I always have to do 'ls -al | grep -v pyc' in my python source directory. > But that's only a first approximation. You might care about the .pyc > files if: > > (1) you want to distribute your application in a non-human readable > format; Sure, I do care about pyc files, of course, I just would prefer to have them at a separate location. > (2) if you care about clutter in your file system; You mean having an extra directory structure for the pyc files? This I think would be better than having the pyc files in the source directory, but we are getting into 'gut feelings' territory :) > (3) if you suspect a bug in the compiler; If the pyc files are somewhere else you can still inspect them if you want. > (4) if you are working with byte-code hacks; Again, just because they are somewhere else doesn't mean you can't get to them. > (5) if the clock on your PC is wonky; Same as above. > (6) if you leave random .pyc files floating around earlier in the > PYTHONPATH than your source files; > > etc. > > > > >> There is now a chance to 'fix' (quotation marks because maybe >> there is nothing to fix, according to some) this issue and make all pyc >> files go away and having python magically doing the right thing. > > Famous last words... > > The only ways I can see to have Python magically do the right thing in > all cases would be: > > (1) Forget about byte-code compiling, and just treat Python as a purely > interpreted language. If you think Python is slow now... I'm not advocating this option, naturally. > (2) Compile as we do now, but only keep the byte code in memory. This > would avoid all worries about scattered .pyc files, but would slow Python > down significantly *and* reduce functionality (e.g. losing the ability to > distribute non-source files). I'm not advocating this option either. > Neither of these are seriously an option. Agreed. >> A >> central pyc repository would be something I was thinking about, but I >> admit it's a half baked or not even that, probably quarter baked idea. > > A central .pyc repository doesn't eliminate the issues developers may > have with byte code files, it just puts them somewhere else, out of > sight, where they are more likely to bite. Here is an example: shared object files. If your code needs them, you can use them easily, you can access them easily if you want to, but they are not in the directory where you keep your C files. They are somewhere in /usr/lib for example, where they are conveniently collected, you can inspect them, look at them, distribute them, do basically whatever you want, but they are out of the way, and 99% of the time while you develop your code, you don't need them. In the 1% of the case you can easily get at them in the centralized location, /usr/lib in our example. Of course the relationship between C source files and shared objects is not parallel to the relationship to python source files and the created pyc files, please don't nitpick on this point. The analogy is in the sense that your project inevitable needs for whatever reason some binary files which are rarely needed at hand, only the linker/compiler/interpreter/etc needs to know where they are. These files can be stored separately, but at a location where one can inspect them if needed (which rarely happens). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From eden at bicikl. Wed Feb 3 06:05:02 2010 From: eden at bicikl. (Eden Kirin) Date: Wed, 03 Feb 2010 12:05:02 +0100 Subject: simple and fast platform independent IPC In-Reply-To: <4b6934ba$0$18396$426a34cc@news.free.fr> References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: On 03.02.2010 09:32, News123 wrote: > Hi, > > I wondered what IPC library might be best simplest for following task? Consider using Thrift (http://incubator.apache.org/thrift/). It is multiplatform multilanguage RPC and IPC solution. I implemented it in couple of my projects and it works seamlessly. -- www.vikendi.net -/- www.supergrupa.com From ben+python at benfinney.id.au Wed Feb 3 06:05:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 03 Feb 2010 22:05:08 +1100 Subject: test -- please ignore References: Message-ID: <87wryumvff.fsf@benfinney.id.au> kj writes: > (my replies in a different comp.lang.python thread are getting > rejected by the server; i have no problem posting to alt.test; and > i'm trying to toubleshoot the problem further.) Thank you for this explanation. It is important to know that you've tried the less obtrusive diagnostics first. Good hunting. -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From kmisoft at gmail.com Wed Feb 3 06:10:21 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 14:10:21 +0300 Subject: Dreaming of new generation IDE Message-ID: Hello, I am sitting here for quite some time, but usually keep silent ;-) I use Python since 2003 both "professionally" and for my hobby projects and love it a much. I notice however, that "maintaining" existing/older python code is may be not so enjoyable task. It may be even harder than supporting old code written in some type of "static" languages (like Java or C++). Surely "dynamic" nature of python comes with price. Finally I develop a feeling that strong instrumentation / tools can bring us the best of two worlds. That I am dreaming on is an absolute new type/class of IDE suitable for Python and potentially for other dynamic-type languages. Instead of current text-oriented IDEs, it should be a database-centric and resemble current CAD systems instead of being just "fancy text editor". Source text should be an output product of that CAD and not a "source material" itself. Well. I understand that it is a very ambitious and experimental stuff. Great efforts and motivation needed even to get something "runnable". So I am looking for someone to get in kind of "virtual partnership". If someone interesting it that soft of stuff, I would like to talk and discuss this system. Vladimir Ignatov From peloko45 at gmail.com Wed Feb 3 06:31:14 2010 From: peloko45 at gmail.com (Joan Miller) Date: Wed, 3 Feb 2010 03:31:14 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> Message-ID: <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> On 3 feb, 10:54, Tim Golden wrote: > [News123] > > >>> I wondered what IPC library might be best simplest for following task? > > ... > > >>> xmlrpc seems to be a little heavy for such tasks. > > >>> signals don't allow to exchange data > > >>> a shared memory message queue would probably a good solution, but > >>> python's Multiprocessing.Queue ?seems to require a common parent process > > [Vinay Sajip] > > >> Gabriel's suggestion is very good; if you need something which is a > >> little more like RPC but still quite lightweight, consider Pyro > >> (http://pyro.sourceforge.net/) > > [pelok... at gmail.com] > > > I've read that Pyro is not safe. > > That's a fairly broad thing to say. I've read lots > of things. What does "is not safe" mean, in any case? > I assume you've got a valid concern in mind which is > worth passing on to a would-be user, but what exactly > is it? FWIW I've used Pyro on and off over the years > without any problems. Certainly my computer's never > blown up as a result of using it. >From its own page: "Pyro has never been truly designed to provide a secure communication mechanism, nor has it had a security review or -test by a security expert." http://pyro.sourceforge.net/features.html > Obviously Pyro is Python-only so interaction with non-Python > code would be problematic. But the OP only mentions Python > scripts so hopefully that wouldn't be an issue... From masklinn at masklinn.net Wed Feb 3 06:36:53 2010 From: masklinn at masklinn.net (Masklinn) Date: Wed, 3 Feb 2010 12:36:53 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <4B6954EB.6010004@sequans.com> References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> <4B6954EB.6010004@sequans.com> Message-ID: <6B7EE46E-CECB-42CB-AA6B-5986E1A2210D@masklinn.net> On 3 Feb 2010, at 11:50 , Jean-Michel Pichavant wrote: > > >>> The reason is that log takes an *int* as first argument that defines the logging level. You gave a string. So There is definitely a reason for it to be incorrect. >>> >> That's not a reason, that's just what currently happens. I know it doesn't work, and I know why, I went and checked the code. But there's no fundamental reason why you couldn't use a level *name* instead of a level code. And indeed, in most parts of logging you can (including but not limited to the configuration of handlers and loggers) >> > You don't neeed to check the code for that ! It is written in the documentation. The logging module designer choose to ask for a level, not a level name, possibly because 2 different levels can have the same name. > Nope, 2 different levels cannot have the same name: levels are currently stored in a dict of string:level and level:string, so you can't have 2 names for the same level, and you can't have 2 levels with the same name either. >>> >>> the field handlers must be defined even if empty. >>> >> Ah, interesting, I didn't think it could be defined as empty. >> >> Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? > 'completeley nonsensical' is overstating. It make sense to state that your handler list is empty, when it is empty. Programmatically, that's implied in the fact that you aren't specifying it. Why wouldn't it be in the config file? Why the asymetry here? From no.email at nospam.invalid Wed Feb 3 08:04:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 05:04:03 -0800 Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <7xtytyzd18.fsf@ruckus.brouhaha.com> News123 writes: > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) If they are running on the same host with no untrusted local users, you can use unix-domain sockets instead of TCP sockets and then the server should be unreachable from the internet. Then you're less exposed to possible security issues with libraries like Pyro. Personally I've just used SocketServer/SimpleHTTPServer on the listening side and simplejson for serialization, but that was for low-rent, low-performance applications. If you want something faster, zeromq (www.zeromq.org) looks interesting. From no.email at nospam.invalid Wed Feb 3 08:07:28 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 05:07:28 -0800 Subject: Dreaming of new generation IDE References: Message-ID: <7xpr4mzcvj.fsf@ruckus.brouhaha.com> Vladimir Ignatov writes: > I notice however, that "maintaining" existing/older python code is may > be not so enjoyable task. It may be even harder than supporting old > code written in some type of "static" languages (like Java or C++). > Surely "dynamic" nature of python comes with price. Yes, this is a well known drawback of dynamic typing. The usual remedy is lots and lots of test automation (a full suite of unit and integration tests that you run on every build, that check the properties of basically every function in your program). > Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems I've never used a current CAD system, so I can't make any sense of this. I don't see how databases would help. From stefan_ml at behnel.de Wed Feb 3 08:16:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Feb 2010 14:16:45 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <7xpr4mzcvj.fsf@ruckus.brouhaha.com> References: <7xpr4mzcvj.fsf@ruckus.brouhaha.com> Message-ID: <4b69773e$0$6577$9b4e6d93@newsspool3.arcor-online.net> Paul Rubin, 03.02.2010 14:07: >> Instead of current text-oriented IDEs, it >> should be a database-centric and resemble current CAD systems > > I've never used a current CAD system, so I can't make any sense of this. > I don't see how databases would help. Just like they help in current IDEs to index the source code. Stefan From awilliam at opengroupware.us Wed Feb 3 08:18:40 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Wed, 03 Feb 2010 08:18:40 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <1265203120.7916.5.camel@linux-m3mt> On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: > Hello, > I am sitting here for quite some time, but usually keep silent ;-) I > use Python since 2003 both "professionally" and for my hobby projects > and love it a much. > I notice however, that "maintaining" existing/older python code is may > be not so enjoyable task. It may be even harder than supporting old > code written in some type of "static" languages (like Java or C++). > Surely "dynamic" nature of python comes with price. Yes, it certainly does. Not that you'll get many Pythonistas to confess to that fact. Somehow those who brag about the readability and expressiveness of source code just cannot admit that: class.method(sting name, int count) - is *obviously* more expressive than - class.method(name, count) Oh, well. This is obvious even in the Python documentation itself where one frequently asks oneself "Uhh... so what is parameter X supposed to be... a string... a list... ?" Not knocking Python; Python is great. I maintain a rapidly growing Python code base. But the above is almost comically funny sometimes [sand.insert_head(pythonista)]. > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. Ugh, please NO! This has been attempted many many times in many environments - it always fails *terribly*. > Well. I understand that it is a very ambitious and experimental stuff. > Great efforts and motivation needed even to get something "runnable". > So I am looking for someone to get in kind of "virtual partnership". > If someone interesting it that soft of stuff, I would like to talk and > discuss this system. From jeanmichel at sequans.com Wed Feb 3 08:32:01 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 03 Feb 2010 14:32:01 +0100 Subject: Logging oddity: handlers mandatory in every single logger? In-Reply-To: <6B7EE46E-CECB-42CB-AA6B-5986E1A2210D@masklinn.net> References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> <4B6954EB.6010004@sequans.com> <6B7EE46E-CECB-42CB-AA6B-5986E1A2210D@masklinn.net> Message-ID: <4B697AD1.8070602@sequans.com> Masklinn wrote: > On 3 Feb 2010, at 11:50 , Jean-Michel Pichavant wrote: > >> You don't neeed to check the code for that ! It is written in the documentation. The logging module designer choose to ask for a level, not a level name, possibly because 2 different levels can have the same name. >> >> > Nope, 2 different levels cannot have the same name: levels are currently stored in a dict of string:level and level:string, so you can't have 2 names for the same level, and you can't have 2 levels with the same name either. > > import logging logging.addLevelName(5, 'test') logging.addLevelName(6, 'test') logging._levelNames {0: 'NOTSET', 5: 'test', 6: 'test', 10: 'DEBUG', 20: 'INFO', 30: 'WARNING', 40: 'ERROR', 50: 'CRITICAL', 'CRITICAL': 50, 'DEBUG': 10, 'ERROR': 40, 'INFO': 20, 'NOTSET': 0, 'WARN': 30, 'WARNING': 30, 'test': 6} now quoting the doc: logging.addLevelName(/lvl/, /levelName/) Associates level /lvl/ with text /levelName/ in an internal dictionary, which is *used to map numeric levels to a textual representation*, for example when a Formatter formats a message. This function can also be used to define your own levels. The only constraints are that all levels used must be registered using this function, levels should be positive integers and they should increase in increasing order of severity. int -> string is the public association string- > int is an internal hack to map easilty map Level name to their int identifier. This is used for the config file, where you specify a string not an int (you vrite level=DEBUG, not level=10) Look at the builtin WARNING & WARN level, two different names for the same level. In any case, you have to trust the documentation and public interface signature. Introspecting the code can be misleading. Now I better understand your initial concern. >>>> the field handlers must be defined even if empty. >>>> >>>> >>> Ah, interesting, I didn't think it could be defined as empty. >>> >>> Which makes the requirement to have an empty ``handler`` completely nonsensical, doesn't it? >>> >> 'completeley nonsensical' is overstating. It make sense to state that your handler list is empty, when it is empty. >> > Programmatically, that's implied in the fact that you aren't specifying it. Why wouldn't it be in the config file? Why the asymetry here? > > Note how progammatically the list of handlers is set to an empty list. The attribute handlers is always set, so the config file field shall be :o) In [11]: logger = logging.getLogger('test') In [12]: logger.handlers Out[12]: [] JM From stefan_ml at behnel.de Wed Feb 3 08:35:41 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 03 Feb 2010 14:35:41 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <4b697bae$0$6587$9b4e6d93@newsspool3.arcor-online.net> Adam Tauno Williams, 03.02.2010 14:18: > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" > > Not knocking Python; Python is great. I maintain a rapidly growing > Python code base. But the above is almost comically funny sometimes > [sand.insert_head(pythonista)]. So, what's "pythonista" in the above? A dummy? Stefan From jeanmichel at sequans.com Wed Feb 3 08:51:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 03 Feb 2010 14:51:46 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <4B697F72.30609@sequans.com> Adam Tauno Williams wrote: > Yes, it certainly does. Not that you'll get many Pythonistas to confess > to that fact. Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: > > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) > > class.method(string name, int count): """Return the cap'tain's age. name: a string giving the name of the cap'tain daughter count: an int giving the number of fingers left in the cap'tain right hand """ In python, attributes/parameters have no type (but you know that). By specifying them in the method signature, you're just duplicating the information hold in the docstring. JM From no.email at please.post Wed Feb 3 08:52:03 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 13:52:03 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: Steve, I apologize for the snarkiness of my previous reply to you. After all, I started the thread by asking the forum for advice on how to avoid a certain kind of bugs, you were among those who gave me advice. So nothing other than thanking you for it was in order. I just let myself get carried away by my annoyance with the Python import scheme. I'm sorry about it. Even though I don't think I can put to practice all of your advice, I can still learn a good deal from it. Cheers, ~kj Steve Holden writes: >kj wrote: >> >>> First, I don't shadow built in modules. Its really not very hard to avoid. >> >> ...*if* you happen to be clairvoyant. I still don't see how the rest of us >> could have followed this fine principle in the case of numbers.py >> prior to Python 2.6. >> >Clearly the more you know about the standard library the less likely >this is to be a problem. Had you been migrqating from an earlier version > the breakage would have alerted you to look for some version-dependent >difference. From kmisoft at gmail.com Wed Feb 3 08:54:26 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 16:54:26 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" Exactly. Often I don't need to know the exact type, but to figure out that "kind of type" it is. >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > Ugh, please NO! ?This has been attempted many many times in many > environments - it always fails *terribly*. Can you give some examples of such systems? (maybe just names for googling for) I don't see anything dirt in storing some additional meta-information about the code under development and using it later for all kind of benefits (easy refactoring for example). As with your example with "parameter x", some additional information can be "attached" to this paramer. Later it can be used during code-generation phase and placed as "comment" in source code or placed in popup tag in html-style presentation. Vladimir Ignatov From marco.salden at gmail.com Wed Feb 3 09:18:40 2010 From: marco.salden at gmail.com (Marco Salden) Date: Wed, 3 Feb 2010 06:18:40 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: On Feb 3, 12:10?pm, Vladimir Ignatov wrote: > Hello, > > I am sitting here for quite some time, but usually keep silent ;-) I > use Python since 2003 both "professionally" and for my hobby projects > and love it a much. > I notice however, that "maintaining" existing/older python code is may > be not so enjoyable task. It may be even harder than supporting old > code written in some type of "static" languages (like Java or C++). > Surely "dynamic" nature of python comes with price. > > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. > > Well. I understand that it is a very ambitious and experimental stuff. > Great efforts and motivation needed even to get something "runnable". > So I am looking for someone to get in kind of "virtual partnership". > If someone interesting it that soft of stuff, I would like to talk and > discuss this system. > > Vladimir Ignatov The maintenance thing may be true but for me that doesn't outweigh the clear benefits I get from using Python i.s.o. e.g. C++: the fact that I have much less code that is more compact and for me more directly readable is a clear advantage when doing maintance on code I didnt touch for a while. Documenting the essential parameters used with some examples and some logging helps (for me at least...). The type of IDE you are looking for is more something like Rational Rose (e.g. RRT?) type of tooling perhaps? There you "CAD" components and their statebehavior and the system generates C or C++ code. Regards, Marco From no.email at nospam.invalid Wed Feb 3 09:42:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 06:42:52 -0800 Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <7x4olys7mb.fsf@ruckus.brouhaha.com> Jean-Michel Pichavant writes: > class.method(string name, int count): > """Return the cap'tain's age. > > name: a string giving the name of the cap'tain daughter > count: an int giving the number of fingers left in the cap'tain > right hand > """ > > In python, attributes/parameters have no type (but you know that). By > specifying them in the method signature, you're just duplicating the > information hold in the docstring. It's not enough to just document (except as an aid to remembering) since the compiler and runtime don't enforce the documentation. You have to use static typing or write tests, to flag all the call sites if you change the signature. One nice trick with static types is if you change what the method does (even if its type signature doesn't change), you can rename the method: class.method2(string name, int count): # change 'method' to 'method2' and recompile your codebase. Every place in the code that called 'method' now gets a compile time "undefined method" error that you can examine to see if you need to update it. This is something you can't catch with unit tests because the call sites can be in distant modules. From kmisoft at gmail.com Wed Feb 3 09:58:25 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 17:58:25 +0300 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: > The maintenance thing may be true but for me that doesn't outweigh the > clear benefits I get from using Python i.s.o. e.g. C++: the fact that > I have much less code that is more compact and for me more directly > readable is a clear advantage when doing maintance on code I didnt > touch for a while. Documenting the essential parameters used with some > examples and some logging helps (for me at least...). Python is very easy to write. But with code grow and time passes, things get worse. Currently I tries to reanimate one of my old freeware project and faced it again. > The type of IDE you are looking for is more something like Rational > Rose (e.g. RRT?) type of tooling perhaps? There you "CAD" components > and their statebehavior and the system generates C or C++ code. Perhaps. I newer use Rational Rose but hear about it. But I use some other Rational* products and they scare me a lot. So maybe Rose can be used for "inspiration" but not much more. Actually I don't want to put programmer in GUI-fashioned env. with a lot of buttons and switches. I think about "classic" text-like view but that actually "understands" that are you doing (typing) on. So your types goes in "datastore" first and then renders back as a text representation. Something like this. Vladimir Ignatov From nobody at nowhere.com Wed Feb 3 10:03:22 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Feb 2010 15:03:22 +0000 Subject: Need help with a program References: <96db4cd6-bda3-42db-a592-83d72e517e2d@28g2000vbf.googlegroups.com> <4B61CE0E.5000801@sequans.com> Message-ID: On Tue, 02 Feb 2010 15:07:05 -0800, Aahz wrote: >>If you have a problem and you think that regular expressions are the >>solution then now you have two problems. Regex is really overkill for >>the OP's problem and it certainly doesn't improve readability. > > If you're going to use a quote, it works better if you use the exact > quote and attribute it: > > 'Some people, when confronted with a problem, think "I know, I'll use > regular expressions." Now they have two problems.' --Jamie Zawinski He may have mixed that one up with a different (and more generic) saying: "If you think that X is the solution to your problem, then you don't understand X and you don't understand your problem." For most values of X. From stef.mientki at gmail.com Wed Feb 3 10:23:00 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 3 Feb 2010 16:23:00 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> > Yes, it certainly does. Not that you'll get many Pythonistas to confess > to that fact. Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: > > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) > > Oh, well. > > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" > > But I thought that was the one of beauties of Python, you don't need to know if the input parameter is a list or a string. cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From cournape at gmail.com Wed Feb 3 10:24:00 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 4 Feb 2010 00:24:00 +0900 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: <5b8d13221002030724m109e6d9fubd35c9f4a20b8a94@mail.gmail.com> On Wed, Feb 3, 2010 at 10:18 PM, Adam Tauno Williams wrote: > On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: >> Hello, >> I am sitting here for quite some time, but usually keep silent ;-) I >> use Python since 2003 both "professionally" and for my hobby projects >> and love it a much. >> I notice however, that "maintaining" existing/older python code is may >> be not so enjoyable task. It may be even harder than supporting old >> code written in some type of "static" languages (like Java or C++). >> Surely "dynamic" nature of python comes with price. > > Yes, it certainly does. ?Not that you'll get many Pythonistas to confess > to that fact. ?Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: Static typing sounds "obviously" better only if you assume everything else being equal. But the typing system also often goes in the way when developing large codebases, when you need to refactor things, etc... So if for a *given* codebase, you get type information, it is almost certainly very helpful. But when you need to change this codebase, maybe not so much. There was a nice paper from people at Adobe which mentioned this very aspect, focusing on how to maintain a significant codebase, from prototype-kind of development to maintenance-kind of development: http://www.ecmascript.org/es4/spec/evolutionary-programming-tutorial.pdf. It strikes me as a good way to look at this tradeoff between static and dynamic typing, where the dynamic typing for some "mostly frozen" code areas has diminishing returns, David From stef.mientki at gmail.com Wed Feb 3 10:28:19 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 3 Feb 2010 16:28:19 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric I don't see what the advantage of the use of a database is in a fairly linear hierarchical structure like python objects and modules. and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. > You mean something like LabView ? cheers, Stef (btw, my dreams ends up in the same needs) -------------- next part -------------- An HTML attachment was scrubbed... URL: From awilliam at opengroupware.us Wed Feb 3 10:39:53 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Wed, 03 Feb 2010 10:39:53 -0500 Subject: Dreaming of new generation IDE In-Reply-To: <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> References: <1265203120.7916.5.camel@linux-m3mt> <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> Message-ID: <1265211593.7916.12.camel@linux-m3mt> On Wed, 2010-02-03 at 16:23 +0100, Stef Mientki wrote: > Yes, it certainly does. Not that you'll get many Pythonistas > to confess > to that fact. Somehow those who brag about the readability > and > expressiveness of source code just cannot admit that: > class.method(sting name, int count) > - is *obviously* more expressive than - > class.method(name, count) > Oh, well. > This is obvious even in the Python documentation itself where > one > frequently asks oneself "Uhh... so what is parameter X > supposed to be... > a string... a list... ?" > But I thought that was the one of beauties of Python, you don't need > to know if the input parameter is a list or a string. You don't need to know; unless of course you want the expected result. From kmisoft at gmail.com Wed Feb 3 10:48:12 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 18:48:12 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: > I don't see what the advantage of the use of a database is in a fairly > linear hierarchical structure like python objects and modules. Imagine simple operation like "method renaming" in a simple "dumb" environment like text editor + grep. Now imagine how simple it can be if system "knows" all your identifiers and just regenerates relevant portions of text from internal database-alike representation. > You mean something like LabView ? No, I don't think so. I never use LabView but imagine it something very "graphical-oriented". No, I think about more "classic" text view. But back-ended with "smart" underlying system - not just obvious "text". Vladimir Ignatov From wanderer at dialup4less.com Wed Feb 3 10:49:44 2010 From: wanderer at dialup4less.com (Wanderer) Date: Wed, 3 Feb 2010 07:49:44 -0800 (PST) Subject: Background Zones in Pylab Plot Message-ID: <1eaf6046-db41-44b5-8c9e-b7a15e4cf078@30g2000vbj.googlegroups.com> I would like to add background zones in pylab plots. Colored sections of the background that the curves pass through. Is this possible? My google searches don't turn up anything but maybe my search terms aren't the right ones. Thanks From banibrata.dutta at gmail.com Wed Feb 3 10:50:16 2010 From: banibrata.dutta at gmail.com (banibrata.dutta at gmail.com) Date: Wed, 03 Feb 2010 15:50:16 +0000 Subject: Dreaming of new generation IDE Message-ID: <4b699c58.11435e0a.1137.01ea@mx.google.com> -----Original Message----- From: Vladimir Ignatov Sent: 03/02/2010 7:24:26 pm Subject: Re: Dreaming of new generation IDE > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" Exactly. Often I don't need to know the exact type, but to figure out that "kind of type" it is. >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > Ugh, please NO! ?This has been attempted many many times in many > environments - it always fails *terribly*. Can you give some examples of such systems? (maybe just names for googling for) I don't see anything dirt in storing some additional meta-information about the code under development and using it later for all kind of benefits (easy refactoring for example). As with your example with "parameter x", some additional information can be "attached" to this paramer. Later it can be used during code-generation phase and placed as "comment" in source code or placed in popup tag in html-style presentation. BD> probably close to Java annotations perhaps? And as for the CAD approach, would a UML reverse engg tool help ? If yes, perhaps you could give BOUML a shot. Regards, Banibrata From nobody at nowhere.com Wed Feb 3 10:50:56 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Feb 2010 15:50:56 +0000 Subject: converting XML to hash/dict/CustomTreeCtrl References: <4B6756FE.9060206@al.com.au> Message-ID: On Wed, 03 Feb 2010 08:07:50 +1100, Astan Chee wrote: > Sorry for being vague but here my question about converting an xml into > a dict. I found some examples online but none gives the dict/result I > want. > Which is kinda wrong. I expect the dict to have the "Space usage > summary", but it doesn't (duplicate?). What am I doing wrong here? > I am attempting to keep the attribute value of an XML as key (if it > doesn't have a value, then just the tag name will do) and associate it > with the text value of that tag/attribute value as well as reflecting > the hierarchy structure of the XML in the dict. Does this make sense? > Anyway, the python script above is just the first step or an example for me. The code you're using expects the XML to follow a particular format, and yours doesn't. You might want to start with a fairly direct translation, e.g.: def xmldict(e): d = {} d['tag'] = e.tag d.update(e.attrib) children = map(xmldict, e) if children: d['children'] = children text = e.text.strip() if text: d['text'] = text return d tree = ElementTree.parse('test.xml') root = tree.getroot() d = xmldict(root) pprint.pprint(d) then refine this as needed. From stef.mientki at gmail.com Wed Feb 3 10:52:52 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Feb 2010 16:52:52 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: <4B699BD4.1010703@gmail.com> On 03-02-2010 16:48, Vladimir Ignatov wrote: >> I don't see what the advantage of the use of a database is in a fairly >> linear hierarchical structure like python objects and modules. >> > Imagine simple operation like "method renaming" in a simple "dumb" > environment like text editor + grep. Now imagine how simple it can be > if system "knows" all your identifiers and just regenerates relevant > portions of text from internal database-alike representation. > I think every IDE (not older than 20 years) does that already. cheers, Stef From no.email at please.post Wed Feb 3 11:17:52 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 16:17:52 +0000 (UTC) Subject: How to guard against bugs like this one? References: Message-ID: In kj writes: >Steve, I apologize for the snarkiness of my previous reply to you. >After all, I started the thread by asking the forum for advice on >how to avoid a certain kind of bugs, you were among those who gave >me advice. So nothing other than thanking you for it was in order. >I just let myself get carried away by my annoyance with the Python >import scheme. I'm sorry about it. Even though I don't think I >can put to practice all of your advice, I can still learn a good >deal from it. Boy, that was dumb of me. The above apology was meant for Stephen Hansen, not Steve Holden. I guess this is now a meta-apology... (Sheesh.) ~kj From no.email at please.post Wed Feb 3 11:23:58 2010 From: no.email at please.post (kj) Date: Wed, 3 Feb 2010 16:23:58 +0000 (UTC) Subject: test -- please ignore References: <87wryumvff.fsf@benfinney.id.au> Message-ID: In <87wryumvff.fsf at benfinney.id.au> Ben Finney writes: >kj writes: >> (my replies in a different comp.lang.python thread are getting >> rejected by the server; i have no problem posting to alt.test; and >> i'm trying to toubleshoot the problem further.) >Thank you for this explanation. It is important to know that you've >tried the less obtrusive diagnostics first. Good hunting. I figured out the immediate reason for the failure: when replying to *certain posts*, my newsreader omits the Newsgroups header from the response. Why it does this is still a mystery to me, but at least now I know what to look out for. Then again, I use the "venerable" (i.e. decrepit) nn as newsreader, so this discovery probably won't help many of those reading this... From mail at timgolden.me.uk Wed Feb 3 11:33:57 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 03 Feb 2010 16:33:57 +0000 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <4B69A575.2020604@timgolden.me.uk> On 03/02/2010 16:17, kj wrote: > Boy, that was dumb of me. The above apology was meant for Stephen > Hansen, not Steve Holden. I guess this is now a meta-apology... > (Sheesh.) You see? That's what I like about the Python community: people even apologise for apologising :) TJG From casevh at gmail.com Wed Feb 3 11:37:36 2010 From: casevh at gmail.com (casevh) Date: Wed, 3 Feb 2010 08:37:36 -0800 (PST) Subject: ANN: GMPY 1.11 released References: Message-ID: On Feb 2, 10:03?pm, Mensanator wrote: > On Feb 2, 12:45?am, casevh wrote: > > > > > Everyone, > > > I'm pleased to annouce the final release of GMPY 1.11. > > GMPY is a wrapper for the MPIR or GMP multiple-precision > > arithmetic library. GMPY 1.11 is available for download from: > > >http://code.google.com/p/gmpy/ > > > In addition to support for Python 3.x, there are several new > > features in this release: > > > - Even faster conversion to/from Python longs. > > - Performance improvements by reducing function overhead. > > - Performance improvements by improved caching. > > - Support for cdivmod, fdivmod, and tdivmod. > > - Unicode strings are accepted on Python 2.x and 3.x. > > - Fixed regression in GMPY 1.10 where True/False were no > > ? longer recognized. > > > Changes since 1.11rc1: > > - Recognizes GMP 5. > > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > > Comments on provided binaries > > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > > 1.3.1 and will automatically recognize the CPU type and use code > > optimized for the CPU at runtime. The 64-bit Windows installers were > > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > > instructions are included if you want to compile your own binary. > > > Please report any issues! > > My previous replies didn't show up. Something to do the .announce > group? I'll trim that and try again. Sorry if they show up eventually. > > Two issues: > > 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply > > >>> gmpy.version() > > '1.11' > > Aren't these different versions? How are we supposed to tell them > apart? Check the name of source tarball? gmpy._cvsid() will return the internal source code revision number. The changes made in each revision number are listed at http://code.google.com/p/gmpy/source/list. I know some applications check gmpy.version(). I don't know if they'll work if the format of the string changes. > > 2] Is it true that the only changes since 1.11rc1 are not > ? ?applicable to me since > > ? ?- I'm not using Windows > ? ?- whether it recognizes GMP 5 is moot as GMP 5 cannot be > ? ? ?compiled on a Mac (according to GMP site) Yes. The only change for GMP 5 was to recognize the new version number when running the tests. > > Is it possible GMP's problems with getting GMP 5 to compile > are the same ones I had with 3.1 on Snow Leopard? (They bemoan > not having a set of every Mac system.) Think it would behoove > me to try it? According to comments on GMP's mailing list, the latest snapshot should work. ftp://ftp.gmplib.org/pub/snapshot/ > > > > > casevh > > From aahz at pythoncraft.com Wed Feb 3 11:38:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2010 08:38:47 -0800 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: > > I shall blaspheme, and suggest that maybe the language you want to >use is REXX (ooREXX or Regina). > > By default, ANY statement that can not be confused for a REXX >language statement is sent to the currently defined command handler >(Which on most OSs is equivalent to Python's os.system() call; the late >Amiga, and IBM's mainframe OS had features that support defining other >applications as command handlers). How is that different from bash scripting? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Wed Feb 3 11:40:59 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2010 08:40:59 -0800 Subject: test -- please ignore References: <87wryumvff.fsf@benfinney.id.au> Message-ID: In article , kj wrote: > >I figured out the immediate reason for the failure: when replying >to *certain posts*, my newsreader omits the Newsgroups header from >the response. Why it does this is still a mystery to me, but at >least now I know what to look out for. Then again, I use the >"venerable" (i.e. decrepit) nn as newsreader, so this discovery >probably won't help many of those reading this... Perhaps it's similar to problems in the even-more-venerable trn3.6 that come from excessively long References: headers? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From nobody at nowhere.com Wed Feb 3 11:55:40 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 03 Feb 2010 16:55:40 +0000 Subject: How to guard against bugs like this one? References: Message-ID: On Tue, 02 Feb 2010 10:38:53 -0800, Carl Banks wrote: >> I don't know if that's necessary. Only supporting the "foo.h" case would >> work fine if Python behaved like gcc, i.e. if the "current directory" >> referred to the directory contain the file performing the import rather >> than in the process' CWD. >> >> As it stands, imports are dynamically scoped, when they should be >> lexically scoped. > > Mostly incorrect. The CWD is in sys.path only for interactive > sessions, and when started with -c switch. When running scripts, the > directory where the script is located is used instead, not the > process's working directory. Okay, so s/CWD/directory containing __main__ script/, but the general argument still holds. > So, no, it isn't anything like dynamic scoping. That's what it looks like to me. The way that an import name is resolved depends upon the run-time context in which the import occurs. >> The only situation where the process' CWD should be used is for an import >> statement in a non-file source (i.e. stdin or the argument to the -c >> switch). > > It already is that way, chief. > > I think you're misunderstanding what's wrong here; the CWD doesn't > have anything to do with it. Even if CWD isn't in the path you still > get the bad behavior kj noted. So now what? Search for imports first in the directory containing the file performing the import. This is essentially the situation with gcc; the directory containing the current file takes precedence over directories specified by -I switches. If you want to override this, you have to use the -I- switch, which makes it very unlikely to happen by accident. From kmisoft at gmail.com Wed Feb 3 12:21:20 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Wed, 3 Feb 2010 20:21:20 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <4B699BD4.1010703@gmail.com> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <4B699BD4.1010703@gmail.com> Message-ID: >> Imagine simple operation like "method renaming" in a simple "dumb" >> environment like text editor + grep. Now imagine how simple it can be >> if system "knows" all your identifiers and just regenerates relevant >> portions of text from internal database-alike representation. >> > > I think every IDE (not older than 20 years) does that already. And fix every reference to it in all files? For python? I don't think so. I even don't think this is possible at all. That if several different objects have a similar named method? How will IDE "classify" calls and renames only some of calls and not others? Vladimir Ignatov From tinnews at isbd.co.uk Wed Feb 3 12:33:21 2010 From: tinnews at isbd.co.uk (tinnews at isbd.co.uk) Date: Wed, 3 Feb 2010 17:33:21 +0000 Subject: test -- please ignore References: <87wryumvff.fsf@benfinney.id.au> Message-ID: <1koo37-18b.ln1@chris.isbd.net> kj wrote: > In <87wryumvff.fsf at benfinney.id.au> Ben Finney writes: > > >kj writes: > > >> (my replies in a different comp.lang.python thread are getting > >> rejected by the server; i have no problem posting to alt.test; and > >> i'm trying to toubleshoot the problem further.) > > >Thank you for this explanation. It is important to know that you've > >tried the less obtrusive diagnostics first. Good hunting. > > I figured out the immediate reason for the failure: when replying > to *certain posts*, my newsreader omits the Newsgroups header from > the response. Why it does this is still a mystery to me, but at > least now I know what to look out for. Then again, I use the > "venerable" (i.e. decrepit) nn as newsreader, so this discovery > probably won't help many of those reading this... I used to use nn, now I use tin which is fairly similar and still being maintained. -- Chris Green From cp.astolfi at gmail.com Wed Feb 3 12:47:08 2010 From: cp.astolfi at gmail.com (Cpa) Date: Wed, 3 Feb 2010 09:47:08 -0800 (PST) Subject: Trouble with os.system Message-ID: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> Hi there, I'm having some trouble with os.system on Fedora 12. I have a bunch of .tex files in tmp/ and I want to compile them. In my shell, the following commands work perfectly : 'for file in tmp/ *.tex; do pdflatex "$file"; done'. But if I use the same command using os.system(), it will compile correctly every file except the last one, for which it raises an error (I get a prompt, as if I did a syntax error in tex document). I suspected some kind of escaping issue, but it won't even work with files such as : foo.txt, bar.txt. Any idea ? Thanks, Cpa From gerald.britton at gmail.com Wed Feb 3 12:54:20 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 3 Feb 2010 12:54:20 -0500 Subject: Trouble with os.system In-Reply-To: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> Message-ID: <5d1a32001002030954t7768a374l9cfcf5127c56f4d7@mail.gmail.com> Can you post your code? On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: > Hi there, > > I'm having some trouble with os.system on Fedora 12. > I have a bunch of .tex files in tmp/ and I want to compile them. > In my shell, the following commands work perfectly : 'for file in tmp/ > *.tex; do pdflatex "$file"; done'. > > But if I use the same command using os.system(), it will compile > correctly every file except the last one, for which it raises an error > (I get a prompt, as if I did a syntax error in tex document). > > I suspected some kind of escaping issue, but it won't even work with > files such as : foo.txt, bar.txt. > > Any idea ? > Thanks, > Cpa > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From cp.astolfi at gmail.com Wed Feb 3 12:58:43 2010 From: cp.astolfi at gmail.com (Cpa) Date: Wed, 3 Feb 2010 09:58:43 -0800 (PST) Subject: Trouble with os.system References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> Message-ID: <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Sure. import sys,re,os files2create = sys.argv[1:] os.system('mkdir tmp') # Some code to create the .tex # Compile tex files os.system('for file in tmp/*; do pdflatex "$file"; done') Pretty simple, alas. -- Cpa On 3 f?v, 18:54, Gerald Britton wrote: > Can you post your code? > > > > On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: > > Hi there, > > > I'm having some trouble with os.system on Fedora 12. > > I have a bunch of .tex files in tmp/ and I want to compile them. > > In my shell, the following commands work perfectly : 'for file in tmp/ > > *.tex; do pdflatex "$file"; done'. > > > But if I use the same command using os.system(), it will compile > > correctly every file except the last one, for which it raises an error > > (I get a prompt, as if I did a syntax error in tex document). > > > I suspected some kind of escaping issue, but it won't even work with > > files such as : foo.txt, bar.txt. > > > Any idea ? > > Thanks, > > Cpa > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > Gerald Britton From alan at baselinedata.co.uk Wed Feb 3 13:01:14 2010 From: alan at baselinedata.co.uk (Alan Harris-Reid) Date: Wed, 03 Feb 2010 18:01:14 +0000 Subject: Passing parameters in URL Message-ID: <4B69B9EA.1040503@baselinedata.co.uk> I have a web-page where each row in a grid has edit/delete buttons to enable the user to maintain a selected record on another page. The buttons are in the form of a link with href='/item_edit?id=123', but this string appears in the URL and gives clues as to how to bypass the correct sequence of events, and could be risky if they entered the URL directly (especially when it comes to deleting records). Is there another way of passing a record-id to a method a) without it appearing in the URL? b) without the user being able to fathom-out how to attach which id to which URL? As each link contains row-id, I guess there is nothing to stop someone from getting the id from the page source-code. Is it safe to use the above href method if I test for authorised credentials (user/password stored as session variables, perhaps?) before performing the edit/delete action? I am currently using CherryPy 3.2, but I guess the theory could apply to any HTTP framework or web app.. Any help would be appreciated. Alan Harris-Reid From phlip2005 at gmail.com Wed Feb 3 13:05:30 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 10:05:30 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> On Feb 3, 3:10?am, Vladimir Ignatov wrote: > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. That's fine so long as I can also treat the source as source, at need. You may have just reinvented Smalltalk's Squeak editor (reputedly the testbed for all of modern GUIs...). Current editors suck because they can't see into the code and browse it - unless it's so statically typed it's painful. That's why I wrote this: http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html From gerald.britton at gmail.com Wed Feb 3 13:08:53 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 3 Feb 2010 13:08:53 -0500 Subject: Trouble with os.system In-Reply-To: <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Message-ID: <5d1a32001002031008o332c5da9i580f023270a84ba7@mail.gmail.com> It kinda worked for me but I had to change it a little: os.system('for file in /tmp/*.tex; do pdflatex "$file"; done') Maybe you're picking up other files in /tmp that are not .tex files? On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: > Sure. > > import sys,re,os > files2create = sys.argv[1:] > os.system('mkdir tmp') > > # Some code to create the .tex > > # Compile tex files > os.system('for file in tmp/*; do pdflatex "$file"; done') > > Pretty simple, alas. > > -- > Cpa > > > On 3 f?v, 18:54, Gerald Britton wrote: >> Can you post your code? >> >> >> >> On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: >> > Hi there, >> >> > I'm having some trouble with os.system on Fedora 12. >> > I have a bunch of .tex files in tmp/ and I want to compile them. >> > In my shell, the following commands work perfectly : 'for file in tmp/ >> > *.tex; do pdflatex "$file"; done'. >> >> > But if I use the same command using os.system(), it will compile >> > correctly every file except the last one, for which it raises an error >> > (I get a prompt, as if I did a syntax error in tex document). >> >> > I suspected some kind of escaping issue, but it won't even work with >> > files such as : foo.txt, bar.txt. >> >> > Any idea ? >> > Thanks, >> > Cpa >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> -- >> Gerald Britton > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From john at castleamber.com Wed Feb 3 13:11:33 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 12:11:33 -0600 Subject: Passing parameters in URL References: Message-ID: <878wbafaui.fsf@castleamber.com> Alan Harris-Reid writes: > I have a web-page where each row in a grid has edit/delete buttons to > enable the user to maintain a selected record on another page. The > buttons are in the form of a link with href='/item_edit?id=123', but > this string appears in the URL and gives clues as to how to bypass the > correct sequence of events, and could be risky if they entered the URL > directly (especially when it comes to deleting records). You should *never* use a GET request to do actions like deleting records. You already are aware of it being risky, so don't do this. You should use GET for getting information, and POST for modifying information. > Is there another way of passing a record-id to a method > a) without it appearing in the URL? Use a POST request. Note that the user still has to select something, and that this information is send by the browser, and hence the user can see this information (and maybe others), and repeat the action with, for example, a Python program. > b) without the user being able to fathom-out how to attach which id to > which URL? I am not sure what you want to prevent here. If you're afraid that user A can delete things that belong user B, than "hiding" things or making them "hard to guess" are not going to help much. If you have several users, you must use some login procedure (and sessions). > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the > edit/delete action? Yes. But still make sure that session ids are not easy to guess, and expire. And make very sure that session ids can't leak to others. Moreover, each time you modify a database use POST. One could argue to also use POST for logging out, otherwise another site might be able to log your users out if they visit that site. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From no.email at nospam.invalid Wed Feb 3 13:12:48 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 10:12:48 -0800 Subject: Passing parameters in URL References: Message-ID: <7xwryudw7z.fsf@ruckus.brouhaha.com> Alan Harris-Reid writes: > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the > edit/delete action? Well, if it's really ok for them to delete records programmatically even if it's ok for them to delete through the web site. I'd probably encrypt the post parameters if this was a concern. From mensanator at aol.com Wed Feb 3 13:22:22 2010 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Feb 2010 10:22:22 -0800 (PST) Subject: ANN: GMPY 1.11 released References: Message-ID: <3cdf9936-035f-43db-abb0-a7daacac14ab@o28g2000yqh.googlegroups.com> On Feb 3, 10:37?am, casevh wrote: > On Feb 2, 10:03?pm, Mensanator wrote: > > > > > > > On Feb 2, 12:45?am, casevh wrote: > > > > Everyone, > > > > I'm pleased to annouce the final release of GMPY 1.11. > > > GMPY is a wrapper for the MPIR or GMP multiple-precision > > > arithmetic library. GMPY 1.11 is available for download from: > > > >http://code.google.com/p/gmpy/ > > > > In addition to support for Python 3.x, there are several new > > > features in this release: > > > > - Even faster conversion to/from Python longs. > > > - Performance improvements by reducing function overhead. > > > - Performance improvements by improved caching. > > > - Support for cdivmod, fdivmod, and tdivmod. > > > - Unicode strings are accepted on Python 2.x and 3.x. > > > - Fixed regression in GMPY 1.10 where True/False were no > > > ? longer recognized. > > > > Changes since 1.11rc1: > > > - Recognizes GMP 5. > > > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > > > Comments on provided binaries > > > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > > > 1.3.1 and will automatically recognize the CPU type and use code > > > optimized for the CPU at runtime. The 64-bit Windows installers were > > > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > > > instructions are included if you want to compile your own binary. > > > > Please report any issues! > > > My previous replies didn't show up. Something to do the .announce > > group? I'll trim that and try again. Sorry if they show up eventually. > > > Two issues: > > > 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply > > > >>> gmpy.version() > > > '1.11' > > > Aren't these different versions? How are we supposed to tell them > > apart? > > Check the name of source tarball? > > gmpy._cvsid() will return the internal source code revision number. > The changes made in each revision number are listed athttp://code.google.com/p/gmpy/source/list. So, '$Id: gmpy.c 237 2010-01-10 03:46:37Z casevh $' would be Revision 237 on that source list? > > I know some applications check gmpy.version(). I don't know if they'll > work if the format of the string changes. Then gmpy.version() isn't really intended to be a version per se, it's just a level of compatibility for those programs that care? > > > > > 2] Is it true that the only changes since 1.11rc1 are not > > ? ?applicable to me since > > > ? ?- I'm not using Windows > > ? ?- whether it recognizes GMP 5 is moot as GMP 5 cannot be > > ? ? ?compiled on a Mac (according to GMP site) > > Yes. The only change for GMP 5 was to recognize the new version number > when running the tests. Good. > > > > > Is it possible GMP's problems with getting GMP 5 to compile > > are the same ones I had with 3.1 on Snow Leopard? (They bemoan > > not having a set of every Mac system.) Think it would behoove > > me to try it? > > According to comments on GMP's mailing list, the latest snapshot > should work.ftp://ftp.gmplib.org/pub/snapshot/ > I'll have to see if I can get it to work this weekend. I sure hope I don't muck it up after after all the trouble I had getting the previous one to work. Thanks for the links. > > > > > > > casevh From python-url at phaseit.net Wed Feb 3 13:22:58 2010 From: python-url at phaseit.net (Gabriel Genellina) Date: Wed, 3 Feb 2010 18:22:58 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Feb 3) Message-ID: QOTW: "I think, in the spirit of the topic, they should hold it at both places at the same time." - Brian Blais, on whether the Python Concurrency Workshop, v2.0, should be in Chicago or Denver (in January!) The fastest way to consume an iterable until exhaustion: http://groups.google.com/group/comp.lang.python/t/c1ae3513a31eb63e/ When inheriting from a built-in class, it isn't obvious which of __new__ / __init__ should be overriden: http://groups.google.com/group/comp.lang.python/t/a453c65be4e0f355/ When importing a module, Python may pick the wrong one due to name clashes -- is this avoidable? http://groups.google.com/group/comp.lang.python/t/fe6430e7980e2a96/ Setting a default encoding for 'print' statements: http://groups.google.com/group/comp.lang.python/t/2fb77c8989f63f9d/ Despite its name, the iglob function (in module glob) isn't completely lazy: http://groups.google.com/group/comp.lang.python/t/d9a8617ec85e926d/ list.pop(0) has very poor performance; collections.deque works better in some cases; patch to allow lists to free elements from head (not just from tail): http://groups.google.com/group/comp.lang.python/t/9221d87f93748b3f/ How to parse ill-formed postal addresses: http://groups.google.com/group/comp.lang.python/t/76a4ab9fd7279a4e/ The future of Python 3: Adoption by Linux distros and package maintainers: http://groups.google.com/group/comp.lang.python/t/69463c4b9b1ecd8f/ Library support: http://groups.google.com/group/comp.lang.python/t/ae138cefffed0d6b/ Myths and fallacies: http://groups.google.com/group/comp.lang.python/t/8b8f4a9f999e33e8/ Why choose Python (and not Ruby) in an introductory course to programming: http://groups.google.com/group/comp.lang.python/t/dfe4f6c60032755e/ How an extension module (written in C) may perform cleaning tasks: http://groups.google.com/group/comp.lang.python/t/fbcb22b4401eaef1/ "Really, the built-in scope is just a built-in module called builtins, but you have to import builtins to query built-ins because the name builtins is not itself built-in..." (Lutz & Ascher, 'Programming Python') http://groups.google.com/group/comp.lang.python/t/dc719a4d922f2f87/ A new implementation of the GIL allows for much better performance in multicore architectures: http://groups.google.com/group/comp.lang.python/t/586ef2d3685fa7ea/ After a year of work with relative success, Unladen Swallow (a Google sponsored CPython improvement project) asks to be officially recognized: http://comments.gmane.org/gmane.comp.python.devel/109919 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From john at castleamber.com Wed Feb 3 13:24:43 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 12:24:43 -0600 Subject: Dreaming of new generation IDE References: Message-ID: <87zl3qdvo4.fsf@castleamber.com> Vladimir Ignatov writes: > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. Your idea is certainly not new. Moreover, I've been using such an IDE and implemented support for a (small) language in it: Programs are hierarchical compositions of formulae satisfying structural and extra-structural relationships. A program editor can use knowledge of such relationships to detect and provide immediate feedback about violations of them. The Synthesizer Generator is a tool for creating such editors from language descriptions. An editor designer specifies the desired relationships and the feedback to be given when they are violated, as well as a user interface; from the specification, the Synthesizer Generator creates a full-screen editor for manipulating programs in the language. http://portal.acm.org/citation.cfm?id=390010.808247 It might be a good start to read as much as possible on the Synthesizer Generator if you want to write such an IDE for Python. I am sure you could write such an IDE in the Synthesizer Generator, but I have no idea if it's still available. And back when I used it (at university) one had to pay for it, and most likely was closed source as well. See also: http://www.google.com/search?q=synthesizer%20generator -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From casevh at gmail.com Wed Feb 3 13:36:22 2010 From: casevh at gmail.com (casevh) Date: Wed, 3 Feb 2010 10:36:22 -0800 (PST) Subject: ANN: GMPY 1.11 released References: <3cdf9936-035f-43db-abb0-a7daacac14ab@o28g2000yqh.googlegroups.com> Message-ID: <167d472a-9981-4575-b463-a36413ed657e@x1g2000prb.googlegroups.com> On Feb 3, 10:22?am, Mensanator wrote: > On Feb 3, 10:37?am, casevh wrote: > > > > > On Feb 2, 10:03?pm, Mensanator wrote: > > > > On Feb 2, 12:45?am, casevh wrote: > > > > > Everyone, > > > > > I'm pleased to annouce the final release of GMPY 1.11. > > > > GMPY is a wrapper for the MPIR or GMP multiple-precision > > > > arithmetic library. GMPY 1.11 is available for download from: > > > > >http://code.google.com/p/gmpy/ > > > > > In addition to support for Python 3.x, there are several new > > > > features in this release: > > > > > - Even faster conversion to/from Python longs. > > > > - Performance improvements by reducing function overhead. > > > > - Performance improvements by improved caching. > > > > - Support for cdivmod, fdivmod, and tdivmod. > > > > - Unicode strings are accepted on Python 2.x and 3.x. > > > > - Fixed regression in GMPY 1.10 where True/False were no > > > > ? longer recognized. > > > > > Changes since 1.11rc1: > > > > - Recognizes GMP 5. > > > > - Bugs fixed in Windows binaries (MPIR 1.3.0rc3 -> 1.3.1). > > > > > Comments on provided binaries > > > > > The 32-bit Windows installers were compiled with MinGW32 using MPIR > > > > 1.3.1 and will automatically recognize the CPU type and use code > > > > optimized for the CPU at runtime. The 64-bit Windows installers were > > > > compiled Microsoft's SDK compilers using MPRI 1.3.1. Detailed > > > > instructions are included if you want to compile your own binary. > > > > > Please report any issues! > > > > My previous replies didn't show up. Something to do the .announce > > > group? I'll trim that and try again. Sorry if they show up eventually. > > > > Two issues: > > > > 1] why does both gmpy 1.11 and gmpy 1.11rc1 both reply > > > > >>> gmpy.version() > > > > '1.11' > > > > Aren't these different versions? How are we supposed to tell them > > > apart? > > > Check the name of source tarball? > > > gmpy._cvsid() will return the internal source code revision number. > > The changes made in each revision number are listed athttp://code.google.com/p/gmpy/source/list. > > So, '$Id: gmpy.c 237 2010-01-10 03:46:37Z casevh $' would be Revision > 237 > on that source list? > Correct. > > > > I know some applications check gmpy.version(). I don't know if they'll > > work if the format of the string changes. > > Then gmpy.version() isn't really intended to be a version per se, > it's just a level of compatibility for those programs that care? Historically, gmpy really didn't have alpha/beta/rc versions and gmpy.version() just had the version "number" and didn't indicate the status. If I change it, I'd rather go to "1.1.1rc1" or "1.2.0a0" but that might break some applications. > > > > > > 2] Is it true that the only changes since 1.11rc1 are not > > > ? ?applicable to me since > > > > ? ?- I'm not using Windows > > > ? ?- whether it recognizes GMP 5 is moot as GMP 5 cannot be > > > ? ? ?compiled on a Mac (according to GMP site) > > > Yes. The only change for GMP 5 was to recognize the new version number > > when running the tests. > > Good. > > > > > > Is it possible GMP's problems with getting GMP 5 to compile > > > are the same ones I had with 3.1 on Snow Leopard? (They bemoan > > > not having a set of every Mac system.) Think it would behoove > > > me to try it? > > > According to comments on GMP's mailing list, the latest snapshot > > should work.ftp://ftp.gmplib.org/pub/snapshot/ > > I'll have to see if I can get it to work this weekend. I sure hope I > don't muck it up after after all the trouble I had getting the > previous > one to work. > > Thanks for the links. > > > > > > > casevh > > From cp.astolfi at gmail.com Wed Feb 3 13:42:44 2010 From: cp.astolfi at gmail.com (Cpa) Date: Wed, 3 Feb 2010 10:42:44 -0800 (PST) Subject: Trouble with os.system References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Message-ID: <501794ef-bc0c-477f-a282-33b1d4a6c4af@z26g2000yqm.googlegroups.com> No, the tmp folder only contains files, and your modification still won't work for me. By the way I have the same error if I do: files2compile = os.listdir('./tmp/') for f in files2compile: os.system('pdflatex '+f) -- Cp On 3 f?v, 19:08, Gerald Britton wrote: > It kinda worked for me but I had to change it a little: > > os.system('for file in /tmp/*.tex; do pdflatex "$file"; done') > > Maybe you're picking up other files in /tmp that ?are not .tex files? > > > > On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: > > Sure. > > > import sys,re,os > > files2create = sys.argv[1:] > > os.system('mkdir tmp') > > > # Some code to create the .tex > > > # Compile tex files > > os.system('for file in tmp/*; do pdflatex "$file"; done') > > > Pretty simple, alas. > > > -- > > Cpa > > > On 3 f?v, 18:54, Gerald Britton wrote: > >> Can you post your code? > > >> On Wed, Feb 3, 2010 at 12:47 PM, Cpa wrote: > >> > Hi there, > > >> > I'm having some trouble with os.system on Fedora 12. > >> > I have a bunch of .tex files in tmp/ and I want to compile them. > >> > In my shell, the following commands work perfectly : 'for file in tmp/ > >> > *.tex; do pdflatex "$file"; done'. > > >> > But if I use the same command using os.system(), it will compile > >> > correctly every file except the last one, for which it raises an error > >> > (I get a prompt, as if I did a syntax error in tex document). > > >> > I suspected some kind of escaping issue, but it won't even work with > >> > files such as : foo.txt, bar.txt. > > >> > Any idea ? > >> > Thanks, > >> > Cpa > >> > -- > >> >http://mail.python.org/mailman/listinfo/python-list > > >> -- > >> Gerald Britton > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > Gerald Britton From python at rcn.com Wed Feb 3 13:42:51 2010 From: python at rcn.com (Raymond Hettinger) Date: Wed, 3 Feb 2010 10:42:51 -0800 (PST) Subject: Selenium/SauceLabs OpenSpace at Pycon Message-ID: For those who are interested, the Sauce Labs team, http://saucelabs.com/about/team, is hosting two free tutorial open space sessions at Pycon in Atlanta. In the short session, people bringing their laptops should be able to record a web session in their browser, convert the recorded activity to a Python script, modify the script to accept a number of inputs , and replay the script locally on their laptops. Once you've learned how to fully automate your own browser, submit the same script to the Sauce Labs cloud to run the tests in parallel across multiple browsers and operating systems, and view the results with instant video playback. The tutorials should be of interest to web developers wanting fast, cross-browser testing and it should be of general interest to anyone wanting to use Python to automate browser sessions. The tutorials are being led by Jason Huggins, the creator of Selenium (an open source web app testing tool http://seleniumhq.org/ ). Several familiar names from the Python community will also be on-hand: http://saucelabs.com/about/news/feb-03-2010 Raymond From stef.mientki at gmail.com Wed Feb 3 13:54:14 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 03 Feb 2010 19:54:14 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <4B699BD4.1010703@gmail.com> Message-ID: <4B69C656.3050402@gmail.com> On 03-02-2010 18:21, Vladimir Ignatov wrote: >>> Imagine simple operation like "method renaming" in a simple "dumb" >>> environment like text editor + grep. Now imagine how simple it can be >>> if system "knows" all your identifiers and just regenerates relevant >>> portions of text from internal database-alike representation. >>> >>> >> I think every IDE (not older than 20 years) does that already. >> > And fix every reference to it in all files? For python? I don't think > so. I even don't think this is possible at all. with tools like inspect it certainly should be possible > That if several > different objects have a similar named method? How will IDE "classify" > calls and renames only some of calls and not others? > yep, you're right, the IDE's I use have as the beste "search / select / rename". But how often do you must/want to rename something (mature) ? cheers, Stef > Vladimir Ignatov > From awilliam at opengroupware.us Wed Feb 3 13:57:51 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Wed, 03 Feb 2010 13:57:51 -0500 Subject: Dreaming of new generation IDE In-Reply-To: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: <1265223471.7916.25.camel@linux-m3mt> On Wed, 2010-02-03 at 10:05 -0800, Phlip wrote: > On Feb 3, 3:10 am, Vladimir Ignatov wrote: > > Finally I develop a feeling that strong instrumentation / tools can > > bring us the best of two worlds. That I am dreaming on is an absolute > > new type/class of IDE suitable for Python and potentially for other > > dynamic-type languages. Instead of current text-oriented IDEs, it > > should be a database-centric and resemble current CAD systems instead > > of being just "fancy text editor". Source text should be an output > > product of that CAD and not a "source material" itself. > That's fine so long as I can also treat the source as source, at need. > You may have just reinvented Smalltalk's Squeak editor (reputedly the > testbed for all of modern GUIs...). > Current editors suck because they can't see into the code and browse > it - unless it's so statically typed it's painful. ? I edit Python in MonoDevelop 2.2; and I can browse my file, classes, etc... So I don't know what you mean by "can't see into the code". It works pretty well. Of course it can't tell that I've set x = {an integer}, as that only happens at runtime. > That's why I wrote this: > http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html From astan.chee at al.com.au Wed Feb 3 14:12:22 2010 From: astan.chee at al.com.au (Astan Chee) Date: Thu, 4 Feb 2010 06:12:22 +1100 Subject: converting XML to hash/dict/CustomTreeCtrl In-Reply-To: References: <4B6756FE.9060206@al.com.au> Message-ID: <4B69CA96.3090908@al.com.au> Nobody wrote: > The code you're using expects the XML to follow a particular format, and > yours doesn't. > > You might want to start with a fairly direct translation, e.g.: > > def xmldict(e): > d = {} > d['tag'] = e.tag > d.update(e.attrib) > children = map(xmldict, e) > if children: > d['children'] = children > text = e.text.strip() > if text: > d['text'] = text > return d > > tree = ElementTree.parse('test.xml') > root = tree.getroot() > d = xmldict(root) > pprint.pprint(d) > > then refine this as needed. > Thanks, that is simple enough for me to understand. I think I got it now. Thanks again From malaclypse2 at gmail.com Wed Feb 3 14:13:37 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 3 Feb 2010 14:13:37 -0500 Subject: Trouble with os.system In-Reply-To: <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> Message-ID: <16651e81002031113k56fa1888kd600239627ab926e@mail.gmail.com> On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: > Sure. > > import sys,re,os > files2create = sys.argv[1:] > os.system('mkdir tmp') > > # Some code to create the .tex > > # Compile tex files > os.system('for file in tmp/*; do pdflatex "$file"; done') > > Pretty simple, alas. I think your bug is in the lines you chose not to share with us. I bet you've forgotten to close the last file you create, so that file has changes that haven't been flushed out to the disk yet. Make sure you call close() on each of the files when you're done writing them. -- Jerry From cp.astolfi at gmail.com Wed Feb 3 14:15:56 2010 From: cp.astolfi at gmail.com (Charles-Pierre Astolfi) Date: Wed, 3 Feb 2010 20:15:56 +0100 Subject: Trouble with os.system In-Reply-To: <16651e81002031113k56fa1888kd600239627ab926e@mail.gmail.com> References: <223d2274-782e-4f95-b337-98adde9374ef@n33g2000yqb.googlegroups.com> <8c385adb-c632-4b03-b875-544c63357887@m31g2000yqb.googlegroups.com> <16651e81002031113k56fa1888kd600239627ab926e@mail.gmail.com> Message-ID: That was it ! What a stupid error... Thank you ! -- Cp On Wed, Feb 3, 2010 at 20:13, Jerry Hill wrote: > On Wed, Feb 3, 2010 at 12:58 PM, Cpa wrote: >> Sure. >> >> import sys,re,os >> files2create = sys.argv[1:] >> os.system('mkdir tmp') >> >> # Some code to create the .tex >> >> # Compile tex files >> os.system('for file in tmp/*; do pdflatex "$file"; done') >> >> Pretty simple, alas. > > I think your bug is in the lines you chose not to share with us. ?I > bet you've forgotten to close the last file you create, so that file > has changes that haven't been flushed out to the disk yet. ?Make sure > you call close() on each of the files when you're done writing them. > > -- > Jerry > From steve at holdenweb.com Wed Feb 3 14:22:59 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 14:22:59 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: Don't give it another thought. I'd much rather you cared than you didn't ... regards Steve kj wrote: > > Steve, I apologize for the snarkiness of my previous reply to you. > After all, I started the thread by asking the forum for advice on > how to avoid a certain kind of bugs, you were among those who gave > me advice. So nothing other than thanking you for it was in order. > I just let myself get carried away by my annoyance with the Python > import scheme. I'm sorry about it. Even though I don't think I > can put to practice all of your advice, I can still learn a good > deal from it. > > Cheers, > > ~kj > > > Steve Holden writes: > >> kj wrote: >>>> First, I don't shadow built in modules. Its really not very hard to avoid. >>> ...*if* you happen to be clairvoyant. I still don't see how the rest of us >>> could have followed this fine principle in the case of numbers.py >>> prior to Python 2.6. >>> >> Clearly the more you know about the standard library the less likely >> this is to be a problem. Had you been migrqating from an earlier version >> the breakage would have alerted you to look for some version-dependent >> difference. > > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 3 14:23:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 14:23:53 -0500 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: kj wrote: > In kj writes: > > >> Steve, I apologize for the snarkiness of my previous reply to you. >> After all, I started the thread by asking the forum for advice on >> how to avoid a certain kind of bugs, you were among those who gave >> me advice. So nothing other than thanking you for it was in order. >> I just let myself get carried away by my annoyance with the Python >> import scheme. I'm sorry about it. Even though I don't think I >> can put to practice all of your advice, I can still learn a good >> deal from it. > > > Boy, that was dumb of me. The above apology was meant for Stephen > Hansen, not Steve Holden. I guess this is now a meta-apology... > (Sheesh.) > Oh, so you don't like *my* advice? ;-) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mrkafk at gmail.com Wed Feb 3 14:30:04 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Feb 2010 20:30:04 +0100 Subject: The best library to create charting application Message-ID: The application will display (elaborate) financial charts. Pygame? Smth else? dotnet? Regards, mk From phlip2005 at gmail.com Wed Feb 3 14:38:57 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 11:38:57 -0800 (PST) Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: On Feb 3, 10:57?am, Adam Tauno Williams wrote: > > Current editors suck because they can't see into the code and browse > > it - unless it's so statically typed it's painful. > > ? ?I edit Python in MonoDevelop ?2.2; ?and I can browse my file, > classes, etc... ?So I don't know what you mean by "can't see into the > code". ?It works pretty well. > > Of course it can't tell that I've set x = {an integer}, as that only > happens at runtime. > > > That's why I wrote this: > > http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html You just said that your code browsing "works pretty well, except when it doesn't". Hence my blog entry. If your editor analyzed your code at runtime, instead of just static analysis, then it could see that x = an integer, or an object, no matter how dynamic your language. -- Phlip http://zeekland.zeroplayer.com/Uncle_Wiggilys_Travels/1 From phlip2005 at gmail.com Wed Feb 3 14:43:23 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 03 Feb 2010 11:43:23 -0800 Subject: The best library to create charting application In-Reply-To: References: Message-ID: mk wrote: > > The application will display (elaborate) financial charts. > > Pygame? Smth else? Back in the day it was Python BLT. Are you on the Web or the Desktop? -- Phlip http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html From mrkafk at gmail.com Wed Feb 3 14:50:43 2010 From: mrkafk at gmail.com (mk) Date: Wed, 03 Feb 2010 20:50:43 +0100 Subject: The best library to create charting application In-Reply-To: References: Message-ID: Phlip wrote: > mk wrote: >> >> The application will display (elaborate) financial charts. >> >> Pygame? Smth else? > > Back in the day it was Python BLT. > > Are you on the Web or the Desktop? > Desktop, really (there should be some nominal web interface but the main application will be desktop) Regards, mk From tjreedy at udel.edu Wed Feb 3 14:59:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 14:59:17 -0500 Subject: exec within function In-Reply-To: References: Message-ID: On 2/3/2010 3:30 AM, Simon zack wrote: > hi, > I'm not sure how I can use exec within a function correctly > here is the code i'm using: > > def a(): > exec('b=1') > print(b) > > a() > > this will raise an error, but I would like to see it outputting 1 Always **copy and paste** **complete error tracebacks** when asking a question like this. (The only exception would be if it is v e r y long, as with hitting the recursion depth limit of 1000.) From john at castleamber.com Wed Feb 3 15:08:35 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 14:08:35 -0600 Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: <87vdeedqv0.fsf@castleamber.com> Phlip writes: > On Feb 3, 10:57?am, Adam Tauno Williams > wrote: > >> > Current editors suck because they can't see into the code and browse >> > it - unless it's so statically typed it's painful. >> >> ? ?I edit Python in MonoDevelop ?2.2; ?and I can browse my file, >> classes, etc... ?So I don't know what you mean by "can't see into the >> code". ?It works pretty well. >> >> Of course it can't tell that I've set x = {an integer}, as that only >> happens at runtime. >> >> > That's why I wrote this: >> > http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_editors.html > > You just said that your code browsing "works pretty well, except when > it doesn't". > > Hence my blog entry. If your editor analyzed your code at runtime, > instead of just static analysis, then it could see that x = an > integer, or an object, no matter how dynamic your language. In Perl: my $x = ( 5, "hello", sub {}, [], {} )[ int rand 5 ]; what's $x? The answer is: it depends. Moreover, even if your editor analyzes your code at runtime (which is certainly not always desirable) it might not be able to find out what the type is of x, simply because it would take too much time to find it out. (It sounds like you want an editor that solves the halting problem ;-) ) I agree with you that to /some extent/ and editor can do analyses, if it does compilation as well (and even runs the code, but the latter is not always desirable). I mentioned the Synthesizer Generator before, which can do compilation on the fly, if you implement it (or if it has been implemented for the language you edit with it). I've written a very simple assembler in it, ages ago, which did assembling on the fly. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 15:09:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 15:09:01 -0500 Subject: simple and fast platform independent IPC In-Reply-To: <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> Message-ID: On 2/3/2010 6:31 AM, Joan Miller wrote: >>> I've read that Pyro is not safe. >> >> That's a fairly broad thing to say. I've read lots >> of things. What does "is not safe" mean, in any case? >> I assume you've got a valid concern in mind which is >> worth passing on to a would-be user, but what exactly >> is it? FWIW I've used Pyro on and off over the years >> without any problems. Certainly my computer's never >> blown up as a result of using it. >> From its own page: > "Pyro has never been truly designed to provide a secure communication > mechanism, nor has it had a security review or -test by a security > expert." > http://pyro.sourceforge.net/features.html For communication between processes on one machine, that hardly seems to be a worry. If it were, I would expect that sending encrypted strings would substantially improve things. That aside, I would wonder whether you could use a master process with a gui to haphazardly launch subprocess, so as to avail oneself of multiprocessing.Queue. Terry Jan Reedy From john at castleamber.com Wed Feb 3 15:10:33 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 14:10:33 -0600 Subject: The best library to create charting application References: Message-ID: <87r5p2dqrq.fsf@castleamber.com> mk writes: > The application will display (elaborate) financial charts. > > Pygame? Smth else? You might want to check out the book "Beginning Python Visualisation". -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 15:18:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 15:18:51 -0500 Subject: expy 0.5.2 released In-Reply-To: <857729.7198.qm@web54208.mail.re2.yahoo.com> References: <857729.7198.qm@web54208.mail.re2.yahoo.com> Message-ID: On 2/3/2010 1:43 AM, Yingjie Lan wrote: > Hi, > > expy is an expressway to extend python. > > in release 0.5.2, expy now supports custom exceptions, besides all built-in ones, and exception handling is made easy. > > for more info, see > > http://expy.sourceforge.net/ What Python versions does it work with? There is no indication either above or on the sf page. tjr From gerald.britton at gmail.com Wed Feb 3 15:29:15 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 3 Feb 2010 15:29:15 -0500 Subject: exec within function In-Reply-To: References: Message-ID: <5d1a32001002031229g64321cbeo538de15417127715@mail.gmail.com> I get no error: >>> def a(): ... exec('b=1') ... print(b) ... >>> a() 1 >>> On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy wrote: > On 2/3/2010 3:30 AM, Simon zack wrote: >> >> hi, >> I'm not sure how I can use exec within a function correctly >> here is the code i'm using: >> >> def a(): >> ? ? exec('b=1') >> ? ? print(b) >> >> a() >> >> this will raise an error, but I would like to see it outputting 1 > > Always **copy and paste** **complete error tracebacks** when asking a > question like this. (The only exception would be if it is v e r y long, as > with hitting the recursion depth limit of 1000.) > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From drsalists at gmail.com Wed Feb 3 15:33:25 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 03 Feb 2010 12:33:25 -0800 Subject: Wrap a function In-Reply-To: References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> <9a28cf01-20af-4ce2-9b78-d8529800e4b9@y7g2000prc.googlegroups.com> Message-ID: <4B69DD95.2050906@gmail.com> Joan Miller wrote: > On 28 ene, 21:40, Jonathan Gardner > wrote: > >> On Jan 28, 10:20 am, Joan Miller wrote: >> >> >> >> >>> I've to call to many functions with the format: >>> >>>>>> run("cmd") >>>>>> >>> were "cmd" is a command with its arguments to pass them to the shell >>> and run it, i.e. >>> >>>>>> run("pwd") >>>>>> >>> or >>> >>>>>> run("ls /home") >>>>>> >>> Does anybody knows any library to help me to avoid the use of the main >>> quotes, and brackets? >>> >>> I would to use anything as: >>> >>> $ ls /home => run("ls /home") >>> >>> or, at least >>> >>> run pwd => run("pwd") >>> >> How about this? >> >> def pwd(): return run("pwd") >> >> pwd() >> >> def ls(l=False, files=()): >> args = [] >> if l: args.insert(0, '-l') >> args.append(files) >> return run("ls", args) >> >> ls(l=True, "/foo") >> > > There would be to make a function for each system command to use so it > would be too inefficient, and follow the problem with the quotes. > > The best is make a parser into a compiled language > 'disagree. Best is to have a text file outside your program, in which you define commands and symbolic names for those commands. Then you have a python module which reads these commands and names, and creates functions that invoke them via the specified name. This way you get concise syntax, don't have to type as much boilerplate, and don't add line noise. Mixing two languages as though they were the same language greatly increases the complexity of the original language with little gain. Consider PowerShell - it's almost like two different languages smushed together, and you have to know how a command was implemented to know how to read it. Also, what if someday The Powers That Be (the python language core designers) decide they need to use $ for something? I hope they won't, but if they do, your preprocessor might make quite a mess of it. From tjreedy at udel.edu Wed Feb 3 15:34:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 15:34:52 -0500 Subject: newbie qns : how do i use xmldiff? In-Reply-To: References: Message-ID: On 2/3/2010 1:38 AM, sWrath swrath wrote: > Hi , > > I am pretty new to python , and reading up on it. > > Basically I am trying to compare xml files . I know difflib have it > but it does not work out as expected. I was looking at xmldiff , > unfortunately I am not able to find documentation how to call it from > python. Anyone knows a link or doc to it as I have been looking high > and low for few days? When asking such a question, it is good to explain what sort of thing, in this case, 'xmldiff' is and where it is is from. Let us assume you meant xmldiff from http://www.logilab.org/859 It says it is a python tool that can "be used be used as a library or as a command line tool." It includes a README file. Have you read that? That says "USAGE ... Read the HELP.txt file.". Have you read *that*? HELP.txt seems to focus on command line usage. I would start with that. To use it as a library (via import ...), you might have to look at the source code as I did not see importing covered in my quick look at that file. Terry Jan Reedy From mensanator at aol.com Wed Feb 3 15:38:19 2010 From: mensanator at aol.com (Mensanator) Date: Wed, 3 Feb 2010 12:38:19 -0800 (PST) Subject: ANN: GMPY 1.11 released References: <3cdf9936-035f-43db-abb0-a7daacac14ab@o28g2000yqh.googlegroups.com> <167d472a-9981-4575-b463-a36413ed657e@x1g2000prb.googlegroups.com> Message-ID: <00b3d248-85a3-4cfc-a083-88a405a47e2c@3g2000yqn.googlegroups.com> On Feb 3, 12:36?pm, casevh wrote: > On Feb 3, 10:22?am, Mensanator wrote: > > > Historically, gmpy really didn't have alpha/beta/rc versions and > gmpy.version() just had the version "number" and didn't indicate the > status. If I change it, I'd rather go to "1.1.1rc1" or "1.2.0a0" but > that might break some applications. Ok. And historically, we never had Python 2.5, 2.6, 2.7 & 3.1 to support simultaneously with Windows Xp, Vista and 7 along with Mac OSX 10.4, 10.5,& 10.6 as well as whatever flavors Linnux comes it. Not to mention that there's now two flavors of GMP. How many different permutations do you suppose that is? Thinking about it makes my head hurt. I certainly fell sympathy towards you developers. From no-spam at non-existing.invalid Wed Feb 3 15:40:51 2010 From: no-spam at non-existing.invalid (Robert) Date: Wed, 03 Feb 2010 21:40:51 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: Vladimir Ignatov wrote: > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. can you sketch an example/use case more concretely? Robert From drsalists at gmail.com Wed Feb 3 15:41:43 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 03 Feb 2010 12:41:43 -0800 Subject: Wrap a function In-Reply-To: <87vdelwitb.fsf@benfinney.id.au> References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> <87vdelwitb.fsf@benfinney.id.au> Message-ID: <4B69DF87.4030207@gmail.com> Ben Finney wrote: > Dennis Lee Bieber writes: > > >> On Thu, 28 Jan 2010 11:24:28 -0800 (PST), Joan Miller: >> >>> On 28 ene, 19:16, Josh Holland wrote: >>> >>>> Check the docs on os.system(). >>>> >>> No. I've a function that uses subprocess to run commands on the same >>> shell and so substitute to bash scrips. But a script full of run >>> ("shell_command --with --arguments") is too verbose. >>> >> I shall blaspheme, and suggest that maybe the language you want >> to use is REXX (ooREXX or Regina). >> > > Heh. That isn't blasphemy, because no true Pythonista [0] would claim > Python to be the god of that domain. > > It's no sin to say that Python isn't a good choice for specific things; > and ?I want to write programs by indistinguishably mixing statements > with external system calls? is one of them, IMO >From http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html#terminology A quick note on terminology: open() is typically a system call. fopen is probably never a system call - instead, it is a function in the C library that wraps open(), making open() easier to use. Then there's the system() function - like fopen(), it isn't really a system call, despite its name. Rather, it is a C library function that typically will wrap the fork() and exec*() system calls. From phlip2005 at gmail.com Wed Feb 3 15:44:05 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 12:44:05 -0800 (PST) Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> <87vdeedqv0.fsf@castleamber.com> Message-ID: John Bokma wrote: > my $x = ( 5, "hello", sub {}, [], {} )[ int rand 5 ]; > > what's $x? The answer is: it depends. That's why my blog post advocated (as usual for me) developer tests. Then you either mock the rand, like all developers should, or you get what you pay for, and Principle of Least Surprise still applies... Over the past decade, teams discovered that developer tests more than made up for the lack of rigor in dynamic languages. A dynamic language with tests can be more productive than a static language, even with its runtime type checks AND with its tests. However, our editors must catch up to us. When I test, I am statically declaring a set of types, even if the language would prefer to dynamically fling them hither and yon. We should leverage that. -- Phlip From vinay_sajip at yahoo.co.uk Wed Feb 3 15:44:29 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Wed, 3 Feb 2010 12:44:29 -0800 (PST) Subject: Logging oddity: handlers mandatory in every single logger? References: <4B685860.4000903@sequans.com> <800F564B-83E4-44F2-95F7-16FB1EDE9696@masklinn.net> <4B6954EB.6010004@sequans.com> Message-ID: <0e582f33-718c-4c46-9c14-c07447474634@36g2000yqu.googlegroups.com> On Feb 3, 11:36?am, Masklinn wrote: Well, Xavier, I would be the first to agree that the existing logging configuration API is not ideal. There are a number of reasons for the current ConfigParser schema used (e.g. an old GUI for configuring logging, which was there before the logging package was added to Python, but which was not brought across). However, there is no point in nitpicking over the particular shortcomings you've focused on, unless of course you've run out of bikesheds to paint ;-) Particularly as I've just received the good news from Guido van Rossum that PEP 391 (Dictionary-Based Configuration For Logging) has been accepted, and my aim is to get it into Python 2.7 and Python 3.2. Now, PEP 391 was announced on python-list and python-dev in October 2009, so plenty of people have had an opportunity to comment on it. Going forwards, and over time, I would hope that this configuration scheme will supplant the ConfigParser-based approach, and so I don't think there's much need to tinker with that API. Onwards, upwards, ever forwards :-) Regards, Vinay Sajip From __peter__ at web.de Wed Feb 3 15:50:38 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 03 Feb 2010 21:50:38 +0100 Subject: exec within function References: Message-ID: Gerald Britton wrote: > On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy wrote: >> On 2/3/2010 3:30 AM, Simon zack wrote: >>> >>> hi, >>> I'm not sure how I can use exec within a function correctly >>> here is the code i'm using: >>> >>> def a(): >>> exec('b=1') >>> print(b) >>> >>> a() >>> >>> this will raise an error, but I would like to see it outputting 1 >> >> Always **copy and paste** **complete error tracebacks** when asking a >> question like this. (The only exception would be if it is v e r y long, >> as with hitting the recursion depth limit of 1000.) > I get no error: > >>>> def a(): > ... exec('b=1') > ... print(b) > ... >>>> a() > 1 My crystal ball says you're using Python 2.x. Try it again, this time in 3.x: 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. >>> def f(): ... exec('a = 42') ... print(a) ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'a' is not defined OP: Python 2.x generates different bytecode for functions containing an exec statement. In 3.x this statement is gone and exec() has become a normal function. I suppose you now have to pass a namespace explicitly: >>> def f(): ... ns = {} ... exec("a=1", ns) ... print(ns["a"]) ... >>> f() 1 Peter From john at castleamber.com Wed Feb 3 16:02:33 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 15:02:33 -0600 Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> <87vdeedqv0.fsf@castleamber.com> Message-ID: <87iqaedod2.fsf@castleamber.com> Phlip writes: > John Bokma wrote: > >> my $x = ( 5, "hello", sub {}, [], {} )[ int rand 5 ]; >> >> what's $x? The answer is: it depends. > > That's why my blog post advocated (as usual for me) developer tests. > Then you either mock the rand, like all developers should, or you get > what you pay for, and Principle of Least Surprise still applies... Yup, I agree with you that (to some extent) an IDE should be able to determine types, especially if programmers don't reuse variables, like (again Perl): my $result = .... # int : : if ( ... ) { $result = .... # string } # $result can be still an int, or either a string, depending on the # test. > Over the past decade, teams discovered that developer tests more than > made up for the lack of rigor in dynamic languages. A dynamic language > with tests can be more productive than a static language, even with > its runtime type checks AND with its tests. Yup, this matches up with my experience. I can't recall that I ever bumped into an issue in Perl (the dynamic language I've been using the most for the past years). Not saying that it hasn't happened, but I just can't recall. Probably also the reason why a "new" language I am learning is also dynamic: Python ;-) > However, our editors must catch up to us. When I test, I am statically > declaring a set of types, even if the language would prefer to > dynamically fling them hither and yon. We should leverage that. I am all for testing, but it should IMO not get into the way. I am quite happy with Emacs as an editor (I "recently" switched), it satisfies most (if not all) of the items on the check list. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From drsalists at gmail.com Wed Feb 3 16:09:55 2010 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 03 Feb 2010 13:09:55 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <4B69E623.4060704@gmail.com> kj wrote: > I just spent about 1-1/2 hours tracking down a bug. > > An innocuous little script, let's call it buggy.py, only 10 lines > long, and whose output should have been, at most two lines, was > quickly dumping tens of megabytes of non-printable characters to > my screen (aka gobbledygook), and in the process was messing up my > terminal *royally*. Here's buggy.py: > > > > import sys > import psycopg2 > connection_params = "dbname='%s' user='%s' password='%s'" % tuple(sys.argv[1:]) > conn = psycopg2.connect(connection_params) > cur = conn.cursor() > cur.execute('SELECT * FROM version;') > print '\n'.join(x[-1] for x in cur.fetchall()) > > > (Of course, buggy.py is pretty useless; I reduced the original, > more useful, script to this to help me debug it.) > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. (This second script > is one I wrote as part of a little Python tutorial I put together > months ago, and is not much more of a script than hello_world.py; > it's baby-steps for the absolute beginner. But apparently, it has > a killer name! I had completely forgotten about it.) > > Both scripts live in a directory filled with *hundreds* little > one-off scripts like the two of them. I'll call this directory > myscripts in what follows. > > It turns out that buggy.py imports psycopg2, as you can see, and > apparently psycopg2 (or something imported by psycopg2) tries to > import some standard Python module called numbers; instead it ends > up importing the innocent myscript/numbers.py, resulting in *absolute > mayhem*. > > (This is no mere Python "wart"; this is a suppurating chancre, and > the fact that it remains unfixed is a neverending source of puzzlement > for me.) > > How can the average Python programmer guard against this sort of > time-devouring bug in the future (while remaining a Python programmer)? > The only solution I can think of is to avoid like the plague the > basenames of all the 200 or so /usr/lib/pythonX.XX/xyz.py{,c} files, > and *pray* that whatever name one chooses for one's script does > not suddenly pop up in the appropriate /usr/lib/pythonX.XX directory > of a future release. > > What else can one do? Let's see, one should put every script in its > own directory, thereby containing the damage. > > Anything else? > > Any suggestion would be appreciated. > > TIA! > > ~k > Here's a pretty simple fix that should work in about any version of python available: Put modules in ~/lib. Put scripts in ~/bin. Your modules end with .py. Your scripts don't. Your scripts add ~/lib to sys.path as needed. Things that go in ~/lib are named carefully. Things in ~/bin also need to be named carefully, but for an entirely different reason - if you name something "ls", you may get into trouble. Then things in ~/lib plainly could cause issues. Things in ~/bin don't. Ending everything with .py seems to come from the perl tradition of ending everything with .pl. This perl tradition appears to have come from perl advocates wanting everyone to know (by looking at a URL) that they are using a perl CGI. IMO, it's language vanity, and best dispensed with - aside from this issue, it also keeps you from rewriting your program in another language with an identical interface. This does, however, appear to be a scary issue from a security standpoint. I certainly hope that scripts running as root don't search "." for modules. From john at castleamber.com Wed Feb 3 16:10:56 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 15:10:56 -0600 Subject: Dreaming of new generation IDE References: Message-ID: <87eil2dnz3.fsf@castleamber.com> Robert writes: > Vladimir Ignatov wrote: >> dynamic-type languages. Instead of current text-oriented IDEs, it >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > can you sketch an example/use case more concretely? I guess Vladimir means what's called a structure editor. The (by me) aforementioned Synthesizer Generator is an example of such an editor (environment). http://en.wikipedia.org/wiki/Structure_editor http://portal.acm.org/citation.cfm?doid=358746.358755 -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:17:42 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:17:42 GMT Subject: PEP 3147 - new .pyc format References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: On Wed, 03 Feb 2010 11:55:57 +0100, Daniel Fetchinson wrote: [...] >> Python does most of that for you: it automatically recompiles the >> source whenever the source code's last modified date stamp is newer >> than that of the byte code. So to a first approximation you can forget >> all about the .pyc files and just care about the source. > > True, but the .pyc file is lying around and I always have to do 'ls -al > | grep -v pyc' in my python source directory. So alias a one-word name to that :) [...] > Here is an example: shared object files. If your code needs them, you > can use them easily, you can access them easily if you want to, but they > are not in the directory where you keep your C files. They are somewhere > in /usr/lib for example, where they are conveniently collected, you can > inspect them, look at them, distribute them, do basically whatever you > want, but they are out of the way, and 99% of the time while you develop > your code, you don't need them. In the 1% of the case you can easily get > at them in the centralized location, /usr/lib in our example. > > Of course the relationship between C source files and shared objects is > not parallel to the relationship to python source files and the created > pyc files, please don't nitpick on this point. The analogy is in the > sense that your project inevitable needs for whatever reason some binary > files which are rarely needed at hand, only the > linker/compiler/interpreter/etc needs to know where they are. These > files can be stored separately, but at a location where one can inspect > them if needed (which rarely happens). I'll try not to nit-pick :) When an object file is in /usr/lib, you're dealing with it as a user. You, or likely someone else, have almost certainly compiled it in a different directory and then used make to drop it in place. It's now a library, you're a user of that library, and you don't care where the object file is so long as your app can find it (until you have a conflict, and then you do). While you are actively developing the library, on the other hand, the compiler typically puts the object file in the same directory as the source file. (There may be an option to gcc to do otherwise, but surely most people don't use it often.) While the library is still being actively developed, the last thing you want is for the object file to be placed somewhere other than in your working directory. A potentially unstable or broken library could end up in /usr/lib and stomp all over a working version. Even if it doesn't, it means you have to be flipping backwards and forwards between two locations to get anything done. Python development is much the same, the only(?) differences are that we have a lower threshold between "in production" and "in development", and that we typically install both the source and the binary instead of just the binary. When you are *using* a library/script/module, you don't care whether import uses the .py file or the .pyc, and you don't care where they are, so long as they are in your PYTHONPATH (and there are no conflicts). But I would argue that while you are *developing* the module, it would more nuisance than help to have the .pyc file anywhere other than immediately next to the .py file (either in the same directory, or in a clearly named sub-directory). -- Steven From kmisoft at gmail.com Wed Feb 3 16:24:30 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 00:24:30 +0300 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: > can you sketch an example/use case more concretely? Sorry, I don't have anything written down. I just have some rough idea of implementation and some concrete features I would like to see in such system. For example: 1) Instant refactoring. No more needs for manual search/inspect/rename. Since system knows exactly that is going on, the refactoring will be fully automatic. 2) Show "xref table" for each function. How often this function used? Where is it used? (code snippets of calls) What functionality is supported by this function? 3) Extended statistics. How many objects this object/function interacts with? Popular functions, dead/unused functions. 4) Code smell detector - too long functions, too much interaction with other objects, global objects, etc. ... Vladimir Ignatov From robert.kern at gmail.com Wed Feb 3 16:27:48 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 15:27:48 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-03 14:40 PM, Robert wrote: > Vladimir Ignatov wrote: >> dynamic-type languages. Instead of current text-oriented IDEs, it >> should be a database-centric and resemble current CAD systems instead >> of being just "fancy text editor". Source text should be an output >> product of that CAD and not a "source material" itself. > > can you sketch an example/use case more concretely? I believe that Smalltalk came pretty close to what Vladimir is asking for. You wrote the methods as linear plain text, but you used the GUI three pane class browser to define and navigate classes. You could export class definitions to a text file and read them back in, but in Vladimir's terms, the text files were not the "source material" themselves. http://www.cosc.canterbury.ac.nz/wolfgang.kreutzer/cosc205/smalltalk1.html -- 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 jgardner at jonathangardner.net Wed Feb 3 16:32:18 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 3 Feb 2010 13:32:18 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> Message-ID: <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> On Feb 2, 9:11?pm, John Bokma wrote: > Jonathan Gardner writes: > > I can explain, in an hour, every single feature of the Python language > > to an experienced programmer, all the way up to metaclasses, > > Either you're a hell of a talker, or I am far, far away from being an > experienced programmer. It's advocacy like this, IMO, that keeps people > away from a language, because you can't feel nothing but a failure after > a statement like this. > I can explain all of Python in an hour; I doubt anyone will understand all of Python in an hour. Coming from perl to python, the big "aha!" moment was when I realized there wasn't anything more than what I saw before me. I kept expecting something big around the corner, kind of like when I first discovered refs in perl, or when I realized how hard it truly was to write OO code in perl that actually does what you think it should do. Perl has trained me to be fearful of the language, constantly on the lookout for jabberwockies. If you fall into one of those traps in perl, it's because you weren't smart enough and aren't worthy of the language, or so they say. It's never perl's fault. I mean, doesn't everyone know what the Schwartzian Transform is? Python is the complete opposite. Go through http://docs.python.org/reference/ . Once you've familiarized yourself with all the operators, statements, and the special methods, you're done with syntax and the core language. There is no more. The next step is to learn the basic objects and functions in builtins. That's in the first seven chapters of http://docs.python.org/library/index.html. You can always fall back to the "help" function to remind yourself if you forget. I do it all the time. After that, it's merely figuring out which standard libraries do what and how. The documentation there is complete and awesome, and there are more than enough people willing to point you in the right direction here. There are no dragons in this forest. Heck, this isn't even a forest--- it's a single-room apartment with everything you need right there where you can see it. The thermostat is set to room temperature, and no matter what happens outside, you're safe and protected from it all. From kmisoft at gmail.com Wed Feb 3 16:36:05 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 00:36:05 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <87eil2dnz3.fsf@castleamber.com> References: <87eil2dnz3.fsf@castleamber.com> Message-ID: > I guess Vladimir means what's called a structure editor. The (by me) > aforementioned Synthesizer Generator is an example of such an editor > (environment). Maybe. Yes, it kind of "generator". It has (entered somehow) internal representation of target program. Then it generates code out of this internal data. Yes, it is imaginable system, I don't have any working prototype yet. But about to start making it. For prototype I choose python 2.x as implementation language, sqlite as internal database and Django as UI. Vladimir Ignatov From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:37:55 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:37:55 GMT Subject: Dreaming of new generation IDE References: Message-ID: On Wed, 03 Feb 2010 08:18:40 -0500, Adam Tauno Williams wrote: > On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: >> Hello, >> I am sitting here for quite some time, but usually keep silent ;-) I >> use Python since 2003 both "professionally" and for my hobby projects >> and love it a much. >> I notice however, that "maintaining" existing/older python code is may >> be not so enjoyable task. It may be even harder than supporting old >> code written in some type of "static" languages (like Java or C++). >> Surely "dynamic" nature of python comes with price. > > Yes, it certainly does. Not that you'll get many Pythonistas to confess > to that fact. Somehow those who brag about the readability and > expressiveness of source code just cannot admit that: > > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) Obviously? I don't know about that. Being told that "count" is an int doesn't really help me -- it's obvious just from the name. In a well- written API, what else could it be? And surely count should be positive or zero but not negative? Saying it's an int is misleading. Or perhaps count can be negative, in which case maybe negative counts have some special meaning that isn't obvious from the function signature. Can I pass None to get the default behaviour? Either way, I need to read the docs, so the supposed added expressiveness doesn't actually add much. And why is count limited to an actual int type, rather than anything which is integer-like? Why can't I pass 3.0 or Decimal(3)? If you have a good reason for that limitation, great, but if it's just there to satisfy the compiler, then boo hiss to you. I cheerfully admit that *sometimes* there are type restrictions which make sense, and of course we know that there are sometimes useful performance gains to be made with static typing. Any compiler which requires types to be declared is far too 1970s though -- a good modern static language should use type inference to reduce the number of declarations needed. As for Pythonistas refusing to accept this, how do you explain function annotations then? Quoting Guido: "Optional static typing has long been requested as a Python feature." http://www.artima.com/weblogs/viewpost.jsp?thread=85551 More on function annotations and type inference for Python: http://lambda-the-ultimate.org/node/1519 http://www.python.org/dev/peps/pep-3107/ http://www.python.org/workshops/2000-01/proceedings/papers/aycock/aycock.html > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" The answer is usually "both, and anything else that obeys some subset of the sequence or iterable protocols". -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:40:53 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:40:53 GMT Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 03 Feb 2010 06:42:52 -0800, Paul Rubin wrote: > One nice trick with static types is if you change > what the method does (even if its type signature doesn't change), you > can rename the method: > > class.method2(string name, int count): # change 'method' to > 'method2' > > and recompile your codebase. Every place in the code that called > 'method' now gets a compile time "undefined method" error that you can > examine to see if you need to update it. This is something you can't > catch with unit tests because the call sites can be in distant modules. I don't understand why that won't work with unit tests. If you change the name of a method, surely your unit tests will now start failing with AttributeError? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:42:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:42:26 GMT Subject: Dreaming of new generation IDE References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: On Wed, 03 Feb 2010 18:48:12 +0300, Vladimir Ignatov wrote: > Imagine simple operation like "method renaming" in a simple "dumb" > environment like text editor + grep. Now imagine how simple it can be if > system "knows" all your identifiers and just regenerates relevant > portions of text from internal database-alike representation. Something like Bicycle Repair Man then: http://bicyclerepair.sourceforge.net/ -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 16:43:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 21:43:26 GMT Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <3dfd60f21002030723q393089e9kcfdec36fc2881b29@mail.gmail.com> Message-ID: On Wed, 03 Feb 2010 10:39:53 -0500, Adam Tauno Williams wrote: > On Wed, 2010-02-03 at 16:23 +0100, Stef Mientki wrote: >> Yes, it certainly does. Not that you'll get many Pythonistas >> to confess >> to that fact. Somehow those who brag about the readability and >> expressiveness of source code just cannot admit that: >> class.method(sting name, int count) >> - is *obviously* more expressive than - class.method(name, >> count) >> Oh, well. >> This is obvious even in the Python documentation itself where >> one >> frequently asks oneself "Uhh... so what is parameter X supposed >> to be... >> a string... a list... ?" > >> But I thought that was the one of beauties of Python, you don't need to >> know if the input parameter is a list or a string. > > You don't need to know; unless of course you want the expected result. Says who? If you're free to assume the function requires a certain type, we're free to assume the function is polymorphic and doesn't. -- Steven From news123 at free.fr Wed Feb 3 16:45:57 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 22:45:57 +0100 Subject: simple and fast platform independent IPC In-Reply-To: References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> Message-ID: <4b69ee95$0$10078$426a74cc@news.free.fr> Tim Golden wrote: > >> Anyway, you have in mind that respect to speed: >> >> shared memory> named pipes> Unix domain socket> TCP socket > > True, but the OP didn't mention speed; rather simplicity. Not > saying it isn't a consideration but premature optimisation and > all that... > Yes true. I'm looking for something simple, platform agnostic. Lateron I can always improve performance. Perhaps I'll stick initially with xmlrpc, as it is quite simple, though a little heavy. I just have to see how to deal with servers which are not up, no more up, being restarted. N From soltys at noabuse.net Wed Feb 3 16:46:11 2010 From: soltys at noabuse.net (soltys) Date: Wed, 03 Feb 2010 22:46:11 +0100 Subject: PyChecker under python's virtualenv Message-ID: Hi Everybody, I've been doing some test on pythons' virtualenv and recently I've decided to run PyChecker. But I'm having some difficulties with importing modules available only on virtualenv by pychecker. As if it was trying to use systemwide python. I've googled about it, and found nothing in this area. I installed pychecker using python setup.py install from virtualenv. I looked at pychecker script - it uses correct python. Any help appreciate, Soltys From ben+python at benfinney.id.au Wed Feb 3 16:50:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Feb 2010 08:50:44 +1100 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> <87vdelwitb.fsf@benfinney.id.au> Message-ID: <87ock6m1jf.fsf@benfinney.id.au> Dan Stromberg writes: > Ben Finney wrote: > > It's no sin to say that Python isn't a good choice for specific > > things; and ?I want to write programs by indistinguishably mixing > > statements with external system calls? is one of them, IMO > > From > http://stromberg.dnsalias.org/~dstromberg/debugging-with-syscall-tracers.html#terminology > > A quick note on terminology: open() is typically a system call. [?] That is a different use of ?system call?. I used it in the ?os.system? sense: meaning ?invoke an external OS command as a child of this process?. -- \ ?I was in a bar the other night, hopping from barstool to | `\ barstool, trying to get lucky, but there wasn't any gum under | _o__) any of them.? ?Emo Philips | Ben Finney From robert.kern at gmail.com Wed Feb 3 16:50:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 15:50:49 -0600 Subject: Python and Ruby In-Reply-To: <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: On 2010-02-03 15:32 PM, Jonathan Gardner wrote: > I can explain all of Python in an hour; I doubt anyone will understand > all of Python in an hour. With all respect, talking about a subject without a reasonable chance of your audience understanding the subject afterwards is not explaining. It's just exposition. -- 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 gb345 at invalid.com Wed Feb 3 16:51:44 2010 From: gb345 at invalid.com (gb345) Date: Wed, 3 Feb 2010 21:51:44 +0000 (UTC) Subject: Need help w 'Broken pipe' handling Message-ID: Hi! I'm having a hard time figuring out how to handle a Unix SIGPIPE exception cleanly. The following short script illustrates the problem: ------------------------------------------------------------------ #!/usr/bin/python # sigpipebug.py import sys import random from signal import signal, SIGPIPE, SIGINT def handle_sigpipe(signo, frame): print >> sys.stderr, "caught SIGPIPE (%d)" % signo sys.exit(0) def handle_sigint(signo, frame): print >> sys.stderr, "caught SIGINT (%d)" % signo sys.exit(1) def my_excepthook(exc_type, exc_obj, exc_tb): print >> sys.stderr, "excepthook called" sys.exit(0) signal(SIGPIPE, handle_sigpipe) signal(SIGINT, handle_sigint) # sys.excepthook = my_excepthook while True: try: print random.random() except IOError as (_, error): if error == 'Broken pipe': print >> sys.stderr, 'EXCEPTION: %s' % error sys.exit(0) raise ------------------------------------------------------------------ The problem shows up only occasionally; the following bash one-liner helps to see the problem (terminate with Ctrl-C): while [ 1 ]; do (./sigpipebug.py||break) | head -1; done (The pipe through head should cause the script to receive a PIPE signal.) The typical output from the above one-liner will start out as something like this: 0.666233280308 caught SIGPIPE (13) 0.554289690682 caught SIGPIPE (13) 0.438033929588 caught SIGPIPE (13) 0.969307976257 caught SIGPIPE (13) close failed in file object destructor: Error in sys.excepthook: Original exception was: 0.916260186232 caught SIGPIPE (13) 0.798590903019 caught SIGPIPE (13) 0.737496617527 ...though the length of the output preceding "close failed..." is highly variable. My problem is that I can't figure out how to get rid of this unwanted extra output: close failed in file object destructor: Error in sys.excepthook: Original exception was: I figure that the way the script is handling the SIGPIPE is somehow incorrect, but I don't see what is it that I'm doing wrong (BTW, I'm a Python noob). Is there some cleanup method I should invoke in the sigpipe handler before executing sys.exit(0)? (BTW, I'm using sys.exit in this script instead of plain exit to avoid a strange error of the form "NameError: global name 'exit' is not defined".) The same thing happens when I redefine sys.excepthook (by uncommenting the commented-out line). Also, is there a way to define the SIGPIPE handler to obviate the need to trap the IOError exception? (Without this try block, I get a traceback when the script receives the PIPE signal. This traceback is also unwanted output.) Any suggestions or comments would be appreciated! Gabe From no.email at nospam.invalid Wed Feb 3 17:00:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:00:42 -0800 Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: <7xmxzqq8s5.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: >> and recompile your codebase. Every place in the code that called >> 'method' now gets a compile time "undefined method" error that you can >> examine to see if you need to update it. This is something you can't >> catch with unit tests because the call sites can be in distant modules. > > I don't understand why that won't work with unit tests. If you change the > name of a method, surely your unit tests will now start failing with > AttributeError? Unit tests only test the code in the local module or package ("unit"). Obviously you also need other tests to exercise the interaction between local and remote modules, but it's harder to be as thorough with those, or write them as reflexively, in part because they're often written by a separate group of programmers. From no.email at nospam.invalid Wed Feb 3 17:01:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:01:52 -0800 Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> <4b69ee95$0$10078$426a74cc@news.free.fr> Message-ID: <7xiqaeq8q7.fsf@ruckus.brouhaha.com> News123 writes: > Perhaps I'll stick initially with xmlrpc, as it is quite simple, > though a little heavy. I just have to see how to deal with servers > which are not up, no more up, being restarted. Something wrong wtih nagios? From news123 at free.fr Wed Feb 3 17:02:32 2010 From: news123 at free.fr (News123) Date: Wed, 03 Feb 2010 23:02:32 +0100 Subject: simple and fast platform independent IPC In-Reply-To: References: <4b6934ba$0$18396$426a34cc@news.free.fr> <9217d055-c06e-4aea-ae8a-4421827eebbb@z41g2000yqz.googlegroups.com> <6a7b9ce0-b6ad-491c-8025-cb22c6113b45@c29g2000yqd.googlegroups.com> <6b65c778-f905-4eb6-b077-523fbea8e22c@f11g2000yqm.googlegroups.com> Message-ID: <4b69f278$0$25781$426a34cc@news.free.fr> Hi Terry, Terry Reedy wrote: > > That aside, I would wonder whether you could use a master process with a > gui to haphazardly launch subprocess, so as to avail oneself of > multiprocessing.Queue. > T This is also an option I'm looking. insted of the python scripts, thet users would normally click at I had to implement small sripts, that just communicate with the master process, which would then launch the application. From deets at nospam.web.de Wed Feb 3 17:04:31 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:04:31 +0100 Subject: Passing parameters in URL In-Reply-To: <878wbafaui.fsf@castleamber.com> References: <878wbafaui.fsf@castleamber.com> Message-ID: <7sua7fFn74U1@mid.uni-berlin.de> Am 03.02.10 19:11, schrieb John Bokma: > Alan Harris-Reid writes: > >> I have a web-page where each row in a grid has edit/delete buttons to >> enable the user to maintain a selected record on another page. The >> buttons are in the form of a link with href='/item_edit?id=123', but >> this string appears in the URL and gives clues as to how to bypass the >> correct sequence of events, and could be risky if they entered the URL >> directly (especially when it comes to deleting records). > > You should *never* use a GET request to do actions like deleting > records. You already are aware of it being risky, so don't do this. You > should use GET for getting information, and POST for modifying information. You should *never* say never, because there might be situations where exceptions from rules are valid. This is one such cases. Making this a post means that you need to resort to javascript to populate & submit a hidden HTML-form. Just for the sake of a POST. And there are people who say "you should *never* write web-apps that only work with enabled javascript"... catch 22. Also, your claim of it being more risky is simply nonsense. GET is a tiny bit more prone to tinkering by the average user. But calling this less risky is promoting security by obscurity, at most. Diez From no.email at nospam.invalid Wed Feb 3 17:09:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:09:07 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> Message-ID: <7xeil2q8e4.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Also, your claim of it being more risky is simply nonsense. GET is a > tiny bit more prone to tinkering by the average user. But calling this > less risky is promoting security by obscurity, at most. GET parameters also tend to get recorded in the http logs of web proxies and web servers while POST parameters usually aren't. This was an annoyance in a web chat package I fooled with for a while. Because the package sent user messages by GET, if I ran the software the way the developers set it up, the contents of all the user conversations stayed in my server logs. I was unable to convince the chat package maintainers that this was a bug. I ended up doing some fairly kludgy hack to prevent the logging. From deets at nospam.web.de Wed Feb 3 17:10:19 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:10:19 +0100 Subject: Passing parameters in URL In-Reply-To: References: Message-ID: <7suaicFp81U1@mid.uni-berlin.de> Am 03.02.10 19:01, schrieb Alan Harris-Reid: > I have a web-page where each row in a grid has edit/delete buttons to > enable the user to maintain a selected record on another page. The > buttons are in the form of a link with href='/item_edit?id=123', but > this string appears in the URL and gives clues as to how to bypass the > correct sequence of events, and could be risky if they entered the URL > directly (especially when it comes to deleting records). > > Is there another way of passing a record-id to a method > a) without it appearing in the URL? You can populate an invisible HTML-form with the values, and submit that - of course you need javascript for this. But this doesn't increase security a bit. Using an extension to FF such as HTTP live headers, it's easy enough to figure out what parameters are passed, and simply forge a request. > b) without the user being able to fathom-out how to attach which id to > which URL? Paul already mentioned that - you can create a server-side, session-stored action-item that is identified by a hash of some sort. Then use that hash as parameter. But I'd say you should instead make sure that your serve actions perform authorization checking before performing any operations. Then you don't need to worry - even guessing a hash argument won't work then. > > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the edit/delete > action? You should of course always do that. Every http-action except login should be guarded (unless you allow anonymous access of course). Diez From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 17:12:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 03 Feb 2010 22:12:31 GMT Subject: [Off topic] Radian language Message-ID: For those interested in language design, the former head of RealBasic's development team, and current "compiler architect guy" for Microsoft's VisualBasic team, Mars Saxman, is developing an interesting programming language, Radian: "The goal of the Radian project is to provide the concurrency benefits of a pure functional language inside the syntax and conceptual style of a high-level imperative language. This suggests two questions: what is it about a pure functional language that makes it useful for developing concurrent software, and what is it about an imperative syntax that makes the marriage of these two divergent linguistic styles worth the effort?" Radian is heavily (but not uniquely) influenced by Python, although sometimes that influence is "what not to do". http://www.radian-lang.org/ -- Steven From deets at nospam.web.de Wed Feb 3 17:21:50 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:21:50 +0100 Subject: PyChecker under python's virtualenv In-Reply-To: References: Message-ID: <7sub7uFstoU1@mid.uni-berlin.de> Am 03.02.10 22:46, schrieb soltys: > Hi Everybody, > I've been doing some test on pythons' virtualenv and recently I've > decided to run PyChecker. But I'm having some difficulties with importing > modules available only on virtualenv by pychecker. As if it was > trying to use systemwide python. > I've googled about it, and found nothing in this area. > I installed pychecker using python setup.py install > from virtualenv. I looked at pychecker script - it uses correct python. I doubt that it uses the "correct python", because then you wouldn't have the problems you have. I don't use pychecker, but pylint. And there, the system-wide command uses the system's python - which of course doesn't know anything about virtualenv. There are two solutions to this problem: - install py(lint|checker) into your virtualenv. - write a wrapper-script that invokes py(lint|checker) with an adapted PYTHONPATH environtment variable, based on the venv's sys.path. I do that for my epylint-wrapper for emacs. Works flawlessly. Diez From john at castleamber.com Wed Feb 3 17:24:05 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 16:24:05 -0600 Subject: Dreaming of new generation IDE References: <87eil2dnz3.fsf@castleamber.com> Message-ID: <871vh2dkl6.fsf@castleamber.com> Vladimir Ignatov writes: >> I guess Vladimir means what's called a structure editor. The (by me) >> aforementioned Synthesizer Generator is an example of such an editor >> (environment). > > Maybe. Yes, it kind of "generator". It has (entered somehow) internal > representation of target program. Then it generates code out of this > internal data. Yes, it is imaginable system, I don't have any working > prototype yet. But about to start making it. For prototype I choose > python 2.x as implementation language, sqlite as internal database and > Django as UI. You might check out articles that mention the Synthesizer Generator, etc. http://citeseer.ist.psu.edu/cis?q=synthesizer+generator&cs=1 http://citeseer.ist.psu.edu/cis?q=structure+editor&cs=1 The idea is not new (at least 30 years old), and those articles might help you. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Wed Feb 3 17:24:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 17:24:50 -0500 Subject: Dreaming of new generation IDE In-Reply-To: <1265203120.7916.5.camel@linux-m3mt> References: <1265203120.7916.5.camel@linux-m3mt> Message-ID: On 2/3/2010 8:18 AM, Adam Tauno Williams wrote: > class.method(sting name, int count) > > - is *obviously* more expressive than - > > class.method(name, count) So write class.method(name:str, count:int)->return_type # 3.x if you really prefer. In spite of you disparagement of 'pythonistas', it seems that the head pythonista *did* admit that some people, at least, would prefer such annotations. 3.0 also added abstract base classes so one can better specify object classes without losing duck-typing. import numbers class.method(name:str, count:numbers.Integral)->return_type Now one is documenting that count should be an integral value that acts like an integer even if it is not an int per se. Of course, this is too broad as it allows (presumably invalid) negative values. Terry Jan Reedy From pavlovevidence at gmail.com Wed Feb 3 17:24:59 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Feb 2010 14:24:59 -0800 (PST) Subject: How to guard against bugs like this one? References: Message-ID: <6025a408-182b-4ab7-8ad6-7a7305879b4e@a5g2000prg.googlegroups.com> On Feb 3, 8:55?am, Nobody wrote: > On Tue, 02 Feb 2010 10:38:53 -0800, Carl Banks wrote: > >> I don't know if that's necessary. Only supporting the "foo.h" case would > >> work fine if Python behaved like gcc, i.e. if the "current directory" > >> referred to the directory contain the file performing the import rather > >> than in the process' CWD. > > >> As it stands, imports are dynamically scoped, when they should be > >> lexically scoped. > > > Mostly incorrect. ?The CWD is in sys.path only for interactive > > sessions, and when started with -c switch. ?When running scripts, the > > directory where the script is located is used instead, not the > > process's working directory. > > Okay, so s/CWD/directory containing __main__ script/, but the general > argument still holds. > > > So, no, it isn't anything like dynamic scoping. > > That's what it looks like to me. The way that an import name is resolved > depends upon the run-time context in which the import occurs. Well it has one superficial similarity to dynamic binding, but that's pretty much it. When the directory containing __main__ script is in the path, it doesn't matter if you invoke it from a different directory or os.chdir () during the program, the same modules get imported. I.e., there's nothing dynamic at all about which modules are used. (Unless you fiddle with the path but that's another question.) All I'm saying is the analogy is bad. A better analogy would be if you have lexical binding, but you automatically look in various sister scope before your own scope. Carl Banks From robert.kern at gmail.com Wed Feb 3 17:27:43 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 16:27:43 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-03 15:40 PM, Steven D'Aprano wrote: > On Wed, 03 Feb 2010 06:42:52 -0800, Paul Rubin wrote: > >> One nice trick with static types is if you change >> what the method does (even if its type signature doesn't change), you >> can rename the method: >> >> class.method2(string name, int count): # change 'method' to >> 'method2' >> >> and recompile your codebase. Every place in the code that called >> 'method' now gets a compile time "undefined method" error that you can >> examine to see if you need to update it. This is something you can't >> catch with unit tests because the call sites can be in distant modules. > > I don't understand why that won't work with unit tests. If you change the > name of a method, surely your unit tests will now start failing with > AttributeError? Let's say we have class "A" with a method named "foo" that we change to "bar". We have another class "B" with a method that accepts and A() instance and calls the .foo() method on it. It is perfectly reasonable (and often necessary) for the unit test of class B to use a mock object instead of a real A() instance. The unit test for class B will fail to catch the renaming of A.foo() to A.bar() because it never tries to call .foo() on a real A instance. Of course, in a static language, it's much harder to make mock objects to do this kind of (very useful!) testing to begin with. -- 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 fetchinson at googlemail.com Wed Feb 3 17:28:14 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 3 Feb 2010 23:28:14 +0100 Subject: PEP 3147 - new .pyc format In-Reply-To: References: <5e9e2096-3bd0-4873-8b99-7ce7f1c5fc97@b7g2000pro.googlegroups.com> <0376df33$0$1309$c3e8da3@news.astraweb.com> Message-ID: >>> Python does most of that for you: it automatically recompiles the >>> source whenever the source code's last modified date stamp is newer >>> than that of the byte code. So to a first approximation you can forget >>> all about the .pyc files and just care about the source. >> >> True, but the .pyc file is lying around and I always have to do 'ls -al >> | grep -v pyc' in my python source directory. > > > So alias a one-word name to that :) > > > [...] >> Here is an example: shared object files. If your code needs them, you >> can use them easily, you can access them easily if you want to, but they >> are not in the directory where you keep your C files. They are somewhere >> in /usr/lib for example, where they are conveniently collected, you can >> inspect them, look at them, distribute them, do basically whatever you >> want, but they are out of the way, and 99% of the time while you develop >> your code, you don't need them. In the 1% of the case you can easily get >> at them in the centralized location, /usr/lib in our example. >> >> Of course the relationship between C source files and shared objects is >> not parallel to the relationship to python source files and the created >> pyc files, please don't nitpick on this point. The analogy is in the >> sense that your project inevitable needs for whatever reason some binary >> files which are rarely needed at hand, only the >> linker/compiler/interpreter/etc needs to know where they are. These >> files can be stored separately, but at a location where one can inspect >> them if needed (which rarely happens). > > I'll try not to nit-pick :) > > When an object file is in /usr/lib, you're dealing with it as a user. > You, or likely someone else, have almost certainly compiled it in a > different directory and then used make to drop it in place. It's now a > library, you're a user of that library, and you don't care where the > object file is so long as your app can find it (until you have a > conflict, and then you do). > > While you are actively developing the library, on the other hand, the > compiler typically puts the object file in the same directory as the > source file. (There may be an option to gcc to do otherwise, but surely > most people don't use it often.) While the library is still being > actively developed, the last thing you want is for the object file to be > placed somewhere other than in your working directory. A potentially > unstable or broken library could end up in /usr/lib and stomp all over a > working version. Even if it doesn't, it means you have to be flipping > backwards and forwards between two locations to get anything done. > > Python development is much the same, the only(?) differences are that we > have a lower threshold between "in production" and "in development", and > that we typically install both the source and the binary instead of just > the binary. > > When you are *using* a library/script/module, you don't care whether > import uses the .py file or the .pyc, and you don't care where they are, > so long as they are in your PYTHONPATH (and there are no conflicts). But > I would argue that while you are *developing* the module, it would more > nuisance than help to have the .pyc file anywhere other than immediately > next to the .py file (either in the same directory, or in a clearly named > sub-directory). Okay, I think we got to a point where it's more about rationalizing gut feelings than factual stuff. But that's okay, system/language/architecure design is often times more about gut feelings than facts so nothing to be too surprised about :) Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From deets at nospam.web.de Wed Feb 3 17:31:39 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 03 Feb 2010 23:31:39 +0100 Subject: Passing parameters in URL In-Reply-To: <7xeil2q8e4.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> Message-ID: <7subqbFvvpU1@mid.uni-berlin.de> Am 03.02.10 23:09, schrieb Paul Rubin: > "Diez B. Roggisch" writes: >> Also, your claim of it being more risky is simply nonsense. GET is a >> tiny bit more prone to tinkering by the average user. But calling this >> less risky is promoting security by obscurity, at most. > > GET parameters also tend to get recorded in the http logs of web proxies > and web servers while POST parameters usually aren't. This was an > annoyance in a web chat package I fooled with for a while. Because the > package sent user messages by GET, if I ran the software the way the > developers set it up, the contents of all the user conversations stayed > in my server logs. I was unable to convince the chat package > maintainers that this was a bug. I ended up doing some fairly kludgy > hack to prevent the logging. If somebody happens to have access to a proxy & it's logs, he can as well log the request body. Don't get me wrong, I don't want to propagate the use of GET as one and only method for parameter passing. But whatever is transmitted clear text over the wire is subject to inspection of all hops in between. Use SSL if you bother. Diez From pavlovevidence at gmail.com Wed Feb 3 17:34:13 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 3 Feb 2010 14:34:13 -0800 (PST) Subject: How to guard against bugs like this one? References: <7a9c25c21002011850jd60a3f0i7f20f713d9f6b4e6@mail.gmail.com> <68cee5b6-3ed9-416d-a3d6-39b3f5fb28d7@g28g2000prb.googlegroups.com> <8104faf3-c4ea-4b1f-8316-f8b17f53554b@q2g2000pre.googlegroups.com> Message-ID: <222d372b-5e43-48a5-835c-4086a992ba78@y7g2000prc.googlegroups.com> On Feb 2, 8:52?pm, Steven D'Aprano wrote: > On Tue, 02 Feb 2010 19:55:15 -0800, Carl Banks wrote: > > On Feb 2, 5:49?pm, Steven D'Aprano > > wrote: > >> On Tue, 02 Feb 2010 12:26:16 -0800, Carl Banks wrote: > >> > I did not propose obvious module names. ?I said obvious names like > >> > email.py are bad; more descriptive names like send_email.py are > >> > better. > > >> But surely send_email.py doesn't just send email, it parses email and > >> receives email as well? > > > No, it doesn't. > > Nevertheless, as a general principle, modules will tend to be multi- > purpose and/or generic. Uh, no? If your module is a library with a public API, then you might defensibly have a "generic and/or multi-purpose module", but if that's the case you should have already christened it something unique. Otherwise modules should stick to a single purpose that can be summarized in a short action word or phrase. Carl Banks From no.email at nospam.invalid Wed Feb 3 17:35:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 14:35:39 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> Message-ID: <7xmxzqx804.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > If somebody happens to have access to a proxy & it's logs, he can as > well log the request body. I'm not talking about a malicious server operator. In this situation, I was the server operator and I didn't want to be recording the conversations. I had to go out of my way to stop the recording. SSL doesn't help and in fact I was using it, but web server logging happens after the SSL layer. I suppose SSL would help against a malicious proxy. Many people back in those days (before AJAX became a buzzword du jour) wanted to do encryption on the client in java or javascript, but that was almost unworkably kludgy, and SSL was the only approach that made any sense. It might be easier now that the javascript API's are richer and the interpreters are faster. From robert.kern at gmail.com Wed Feb 3 17:38:21 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 16:38:21 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-03 15:37 PM, Steven D'Aprano wrote: > On Wed, 03 Feb 2010 08:18:40 -0500, Adam Tauno Williams wrote: > >> On Wed, 2010-02-03 at 14:10 +0300, Vladimir Ignatov wrote: >>> Hello, >>> I am sitting here for quite some time, but usually keep silent ;-) I >>> use Python since 2003 both "professionally" and for my hobby projects >>> and love it a much. >>> I notice however, that "maintaining" existing/older python code is may >>> be not so enjoyable task. It may be even harder than supporting old >>> code written in some type of "static" languages (like Java or C++). >>> Surely "dynamic" nature of python comes with price. >> >> Yes, it certainly does. Not that you'll get many Pythonistas to confess >> to that fact. Somehow those who brag about the readability and >> expressiveness of source code just cannot admit that: >> >> class.method(sting name, int count) >> >> - is *obviously* more expressive than - >> >> class.method(name, count) > > Obviously? I don't know about that. Being told that "count" is an int > doesn't really help me -- it's obvious just from the name. In a well- > written API, what else could it be? A bool. As in telling the method whether or not it should count something. That said, I agree with your later point that this kind of information is better provided by the docstring, not the call signature. Not least because the "type" may be something wishy-washy and ad-hoc like "sequence" or "string or list of strings". I do wish that people would document their parameters with this information a little more consistently, though. -- 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 phlip2005 at gmail.com Wed Feb 3 17:47:52 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 3 Feb 2010 14:47:52 -0800 (PST) Subject: equivalent of Ruby's Pathname? Message-ID: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> Pythonistas: Yes, calling os.path.walk() and os.path.join() all the time on raw strings is fun, but I seem to recall from my Ruby days a class called Pathname, which presented an object that behaved like a string at need, and like a filesystem path at need. path + 'folder' would call .join() and insert the / correctly, for example. What's the best equivalent in Python-land? -- Phlip From pecora at anvil.nrl.navy.mil Wed Feb 3 17:54:57 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Wed, 03 Feb 2010 17:54:57 -0500 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: In article <1944d953-25ad-440b-9317-a7a4b4de6dac at f17g2000prh.googlegroups.com>, Jonathan Gardner wrote: > > I can explain all of Python in an hour; I doubt anyone will understand > all of Python in an hour. > > Coming from perl to python, the big "aha!" moment was when I realized > there wasn't anything more than what I saw before me. I kept expecting > something big around the corner, kind of like when I first discovered > refs in perl, or when I realized how hard it truly was to write OO > code in perl that actually does what you think it should do. > > Perl has trained me to be fearful of the language, constantly on the > lookout for jabberwockies. If you fall into one of those traps in > perl, it's because you weren't smart enough and aren't worthy of the > language, or so they say. It's never perl's fault. I mean, doesn't > everyone know what the Schwartzian Transform is? > > Python is the complete opposite. Go through http://docs.python.org/reference/ > . Once you've familiarized yourself with all the operators, > statements, and the special methods, you're done with syntax and the > core language. There is no more. > > The next step is to learn the basic objects and functions in builtins. > That's in the first seven chapters of > http://docs.python.org/library/index.html. > You can always fall back to the "help" function to remind yourself if > you forget. I do it all the time. > > After that, it's merely figuring out which standard libraries do what > and how. The documentation there is complete and awesome, and there > are more than enough people willing to point you in the right > direction here. > > There are no dragons in this forest. Heck, this isn't even a forest--- > it's a single-room apartment with everything you need right there > where you can see it. The thermostat is set to room temperature, and > no matter what happens outside, you're safe and protected from it all. That's a pretty accurate description of how I transitioned to Python from C and Fortran. I kept trying to think of how to output data and parameter variables of different types to files for later reading in. How to format them all consistently and then get them back in with the exact same accuracy. I was stuck in printf and scanf land. Then after much noodling around and reading it hit me that I could just put all that output of different types of variables into a list, hit it with a repr() function to get a string version, and write the string to a file -- no formatting necessary-- three lines of code. Later reading in the string version (no formatting necessary), and hitting it with an eval() function returned all the values I originally had in those variables. How simple, but beautiful. I was making it harder when Python was making it easier. Trained on the wrong language. -- -- Lou Pecora From bblais at bryant.edu Wed Feb 3 17:57:55 2010 From: bblais at bryant.edu (Brian Blais) Date: Wed, 03 Feb 2010 17:57:55 -0500 Subject: mouse input in turtle module Message-ID: <146C3C50-CA41-4A38-B9F4-4633219B1E99@bryant.edu> Hello, I would like to find a way to pause, and get mouse input in the turtle module. Since it is built on tk, I thought perhaps there would be an easy way, but I am stumped. Specifically, I'd like something like: x,y,button=mouse_input() # pause in here until the mouse is clicked in the turtle window I know about the screenclick, where I can define a callback but I couldn't rig it to pause until a mouse clicked, even using global flags. Is there an example of this somewhere? For a bonus, I'd love to be able to out of it, either raising an exception or return a button=-1 or something. thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Wed Feb 3 18:03:15 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 17:03:15 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <87wrytdirw.fsf@castleamber.com> Jonathan Gardner writes: > On Feb 2, 9:11?pm, John Bokma wrote: >> Jonathan Gardner writes: >> > I can explain, in an hour, every single feature of the Python language >> > to an experienced programmer, all the way up to metaclasses, >> >> Either you're a hell of a talker, or I am far, far away from being an >> experienced programmer. It's advocacy like this, IMO, that keeps people >> away from a language, because you can't feel nothing but a failure after >> a statement like this. >> > > I can explain all of Python in an hour; OK, in that case I would say give it a go. Put it on YouTube, or write a blog post about it (or post it here). I am sure you will help a lot of people that way. > Coming from perl to python, the big "aha!" moment was when I realized > there wasn't anything more than what I saw before me. I kept expecting > something big around the corner, kind of like when I first discovered > refs in perl, or when I realized how hard it truly was to write OO > code in perl that actually does what you think it should do. There are very nice frameworks to help you (e.g. Moose). OO is not that hard IMO, but I can imagine it's very hard if you don't understand references sufficiently. > Perl has trained me to be fearful of the language, constantly on the > lookout for jabberwockies. If you fall into one of those traps in > perl, it's because you weren't smart enough and aren't worthy of the > language, or so they say. Odd, you gave me the same feeling when you stated you could explain me all features of Python in an hour. > It's never perl's fault. I mean, doesn't everyone know what the > Schwartzian Transform is? Doesn't everyone know what the big O notation is? I mean, Schwartzian transform is not unique to Perl, and it strikes me as odd that you think it is. It's all about understanding that general sort on average is O(n log n), and hence does O(n log n) comparisons. Which means that if you do an expensive calculation in a custom compare function or do a lot of comparisons it might be cheaper to do precalculate the keys (O(n)). Randal Schwartz was the person who made this idea popular in the Perl community, hence the Perl community named it after him, but it was long known before that and used in other languages. [How to learn Python] I am fully aware of how to learn a language, I've done so several times (or many times even). I only disagree with your statement that you can explain all features of Python to me in an hour. But I love to be wrong on this, and to stand corrected. > There are no dragons in this forest. Heck, this isn't even a forest--- > it's a single-room apartment with everything you need right there > where you can see it. The thermostat is set to room temperature, and > no matter what happens outside, you're safe and protected from it all. Why does this sound like some religious speech? I always say: if there was a really easy to learn programming language, I would be programming in it. And no, I don't think Python is it. (Nor Perl for that matter). I do agree that Python /looks/ more simple (and certainly cleaner, unless you're using regexp a lot) than Perl, and certainly to some extend Python /is/ simpler. But in my (relatively long experience) programming boils mostly down to which libraries you know, and how well you can use them. Finally, note that simpeler doesn't always make your code more easy to grasp. There is a reason that human languages are rich and often have many ways to say something. Programming, after all, is also communication with other humans (if only with one self). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From no.email at nospam.invalid Wed Feb 3 18:09:37 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 15:09:37 -0800 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <7x8wb9j4r2.fsf@ruckus.brouhaha.com> Lou Pecora writes: > after much noodling around and reading it hit me that I could just put > all that output of different types of variables into a list, hit it > with a repr() function to get a string version, and write the string > to a file -- no formatting necessary-- three lines of code. Later > reading in the string version (no formatting necessary), and hitting > it with an eval() function returned all the values I originally had in > those variables. How simple, but beautiful. FYI: I do that too sometimes, but in general using repr/eval that way is poor style and not very reliable. It's better to use the pickle module, which is intended for that sort of thing, or the json module if your datatypes are suitable and you want to follow a semi-standard. From deets at nospam.web.de Wed Feb 3 18:26:17 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 00:26:17 +0100 Subject: Passing parameters in URL In-Reply-To: <7xmxzqx804.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> Message-ID: <7suf0pFhadU1@mid.uni-berlin.de> Am 03.02.10 23:35, schrieb Paul Rubin: > "Diez B. Roggisch" writes: >> If somebody happens to have access to a proxy& it's logs, he can as >> well log the request body. > > I'm not talking about a malicious server operator. In this situation, I > was the server operator and I didn't want to be recording the > conversations. I had to go out of my way to stop the recording. SSL > doesn't help and in fact I was using it, but web server logging happens > after the SSL layer. I suppose SSL would help against a malicious > proxy. Well, we actually implemented POST-parameter logging (inside the WSGI-app), because we *want* all parameters users pass. They end up in the application anyway, and aid debugging. Of course we blind sensitive parameters such as passwords & creditcard numbers. Of course only information not gathered is really safe information. But every operation that has side-effects is reproducable anyway, and if e.g. your chat-app has a history, you can as well log the parameters. Diez From tjreedy at udel.edu Wed Feb 3 18:31:09 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 03 Feb 2010 18:31:09 -0500 Subject: Selenium/SauceLabs OpenSpace at Pycon In-Reply-To: References: Message-ID: On 2/3/2010 1:42 PM, Raymond Hettinger wrote: > For those who are interested, the Sauce Labs team, http://saucelabs.com/about/team, > is hosting two free tutorial open space sessions at Pycon in Atlanta. > > In the short session, people bringing their laptops should be able to > record a web session in their browser, convert the recorded activity > to a Python script, modify the script to accept a number of inputs , > and replay the script locally on their laptops. Once you've learned > how to fully automate your own browser, submit the same script to the > Sauce Labs cloud to run the tests in parallel across multiple browsers > and operating systems, and view the results with instant video > playback. A free tutorial is a good way to introduce Suace Lab and its product. I visited the site, but one variable I did not address is screen size and aspect ratio. When my wife redid her home page last fall, that was more of a problem than browser differences. tjr From steve at holdenweb.com Wed Feb 3 18:39:48 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 18:39:48 -0500 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: Robert Kern wrote: > On 2010-02-03 15:32 PM, Jonathan Gardner wrote: > >> I can explain all of Python in an hour; I doubt anyone will understand >> all of Python in an hour. > > With all respect, talking about a subject without a reasonable chance of > your audience understanding the subject afterwards is not explaining. > It's just exposition. > I agree. If the audience doesn't understand then you haven't explained it. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From no.email at nospam.invalid Wed Feb 3 18:39:50 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 15:39:50 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> Message-ID: <7xr5p1dh2x.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Of course only information not gathered is really safe > information. But every operation that has side-effects is reproducable > anyway, and if e.g. your chat-app has a history, you can as well log > the parameters. No I can't. The chat-app history would be on the client, not the server, so I'd have no access to it. Put another way: as server operator, I'm like the owner of a coffee shop. I can't stop patrons from recording their own conversations with each other, and it's not even really my business whether they do that. But it would be outrageous for the shop owner to record the conversations of patrons. From lanyjie at yahoo.com Wed Feb 3 19:00:21 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 3 Feb 2010 16:00:21 -0800 (PST) Subject: expy 0.5.2 released In-Reply-To: Message-ID: <179000.53309.qm@web54207.mail.re2.yahoo.com> > > > > expy is an expressway to extend python. > > > > in release 0.5.2, expy now supports custom exceptions, > besides all built-in ones, and exception handling is made > easy. > > > > for more info, see > > > > http://expy.sourceforge.net/ > > What Python versions does it work with? > There is no indication either above or on the sf page. > Thanks for point that out, I will add this to the document. Currently, it works with Python 2.5, 2.6. I haven't tested with Python 2.7 or 3.x (for 3.x, need to use the code tool first, then I am not sure if the C API for 3.x has changed much). BTW, the current version is 0.5.5. Yingjie From steven at REMOVE.THIS.cybersource.com.au Wed Feb 3 19:01:06 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2010 00:01:06 GMT Subject: Dreaming of new generation IDE References: Message-ID: On Wed, 03 Feb 2010 16:38:21 -0600, Robert Kern wrote: >>> class.method(name, count) >> >> Obviously? I don't know about that. Being told that "count" is an int >> doesn't really help me -- it's obvious just from the name. In a well- >> written API, what else could it be? > > A bool. As in telling the method whether or not it should count > something. Ha ha, good point. I question that this is a well-written API: such flags to change the behaviour of a function/method are generally poor design. If method behaves differently depending on whether or not you want it to count something, then it is usually better design to have two methods, one that counts and one that doesn't. In any case, yes, the weakness of naming conventions is that there are always odd-corner cases of natural language. Perhaps `name` is also a flag telling the method whether or not to name something. But then, one can write crappy APIs in any language. -- Steven From deets at nospam.web.de Wed Feb 3 19:09:04 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 01:09:04 +0100 Subject: Passing parameters in URL In-Reply-To: <7xr5p1dh2x.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> Message-ID: <7suhh1Ft2dU1@mid.uni-berlin.de> Am 04.02.10 00:39, schrieb Paul Rubin: > "Diez B. Roggisch" writes: >> Of course only information not gathered is really safe >> information. But every operation that has side-effects is reproducable >> anyway, and if e.g. your chat-app has a history, you can as well log >> the parameters. > > No I can't. The chat-app history would be on the client, not the > server, so I'd have no access to it. Put another way: as server > operator, I'm like the owner of a coffee shop. I can't stop patrons > from recording their own conversations with each other, and it's not > even really my business whether they do that. But it would be > outrageous for the shop owner to record the conversations of patrons. Which is the exact thing that happens when you use an email-provider with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I wouldn't call outrageous. This discussion moves away from the original question: is there anything inherently less secure when using GET vs. POST. There isn't. Users can forge both kind of requests easy enough, whoever sits in the middle can access both, and it's at the discretion of the service provider to only save what it needs to. If you don't trust it, don't use it. Diez From news123 at free.fr Wed Feb 3 19:18:31 2010 From: news123 at free.fr (News123) Date: Thu, 04 Feb 2010 01:18:31 +0100 Subject: pychecker and "import my.special.module as mymod" Message-ID: <4b6a1257$0$12211$426a34cc@news.free.fr> Hi, I'm not really used to structuring modules withn directories, but I started playing ##################################### # the commands to reproduce my setup: ##################################### mkdir -p my/special touch my/__init__.py my/special/__init__.py echo 'print "myspecialmod"' > my/special/module.py echo "import my.special.module as mymod" > tst.py so I have now following files: -rw-r--r-- 1 0 2010-02-04 01:05 ./my/__init__.py -rw-r--r-- 1 131 2010-02-04 01:07 ./my/__init__.pyc -rw-r--r-- 1 0 2010-02-04 01:05 ./my/special/__init__.py -rw-r--r-- 1 139 2010-02-04 01:07 ./my/special/__init__.pyc -rw-r--r-- 1 21 2010-02-04 01:06 ./my/special/module.py -rw-r--r-- 1 159 2010-02-04 01:07 ./my/special/module.pyc -rw-r--r-- 1 34 2010-02-04 01:07 ./tst.py the program tst.py runs as expected: > $ python tst.py > myspecialmod However pychecker gives me two warnings: > $ pychecker tst.py > Processing module tst (tst.py)... > myspecialmod > > Warnings... > > tst.py:1: Imported module (my.special.module) not used > tst.py:1: No module attribute (special) found I understand the first one and this one will not appear in my real code. However I don't really understand the second one. So my questions are: - Is this a real warning or is this 'just' a pychecker problem? - Can I write my code such, that the warning will not appear? - Is there a pychecker switch, which would get rid of this warning? thanks a lot in advance for your answers / suggestions N From no.email at nospam.invalid Wed Feb 3 19:35:41 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 16:35:41 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> Message-ID: <7x3a1h7s82.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: >> But it would be outrageous for the shop owner to record the >> conversations of patrons. > > Which is the exact thing that happens when you use an email-provider > with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I > wouldn't call outrageous. Those are not comparable. IMAP is a storage service, and groups, facebook, and twitter are publishing systems (ok, I've never understood quite what Google Wave is). Yes, by definition, your voice mail provider (like IMAP) has to save recordings of messages people leave you, but that's a heck of a lot different than your phone carrier recording your real-time conversations. Recording live phone conversations by a third party is called a "wiretap" and doing it without suitable authorization can get you in a heck of a lot of trouble. > This discussion moves away from the original question: is there > anything inherently less secure when using GET vs. POST. There isn't. Well, the extra logging of GET parameters is not inherent to the protocol, but it's an accidental side effect that server ops may have to watch out for. > Users can forge both kind of requests easy enough, whoever sits in the > middle can access both, I'm not sure what you mean by that. Obviously if users want to record their own conversations, then I can't stop them, but that's much different than a non-participant in the conversation leaving a recorder running 24/7. Is that so hard to understand? Interception from the middle is addressed by SSL, though that relies on the PKI certificate infrastructure, which while somewhat dubious, is better than nothing. > and it's at the discretion of the service provider to only save what > it needs to. If you don't trust it, don't use it. I certainly didn't feel that saving or not saving client conversations on the server side was up to my discretion. When I found that the default server configuration caused conversations to be logged then I was appalled. Do you think the phone company has the right to record all your phone calls if they feel like it (absent something like a law enforcement investigation)? What about coffee shops that you visit with your friends? It is not up to their discretion. They have a positive obligation to not do it. If you think they are doing it on purpose without your authorization, you should notify the FBI or your equivalent, not just "don't use it". If they find they are doing it inadvertently, they have to take measures to make it stop. That is the situation I found myself in, because of the difference in how servers treat GET vs. POST. From monaghand.david at gmail.com Wed Feb 3 19:39:01 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Thu, 04 Feb 2010 00:39:01 +0000 Subject: Python 3 minor irritation Message-ID: I have a small program which reads files from the directory in which it resides. It's written in Python 3 and when run through IDLE or PythonWin works fine. If I double-click the file, it works fine in Python 2.6, but in 3 it fails because it looks for the files to load in the Python31 folder, not the one the script is in. It's not a big deal, but browsing around I haven't found why the behaviour has been changed or any comment about it (That might be my poor search technique, I suppose). The program fails at: try: tutdoc = minidom.parse(".//Myfile.xml") except IOError: DaveM From john at castleamber.com Wed Feb 3 19:42:39 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 18:42:39 -0600 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> Message-ID: <87iqadde68.fsf@castleamber.com> "Diez B. Roggisch" writes: > Am 03.02.10 19:11, schrieb John Bokma: >> Alan Harris-Reid writes: >> >>> I have a web-page where each row in a grid has edit/delete buttons to >>> enable the user to maintain a selected record on another page. The >>> buttons are in the form of a link with href='/item_edit?id=123', but >>> this string appears in the URL and gives clues as to how to bypass the >>> correct sequence of events, and could be risky if they entered the URL >>> directly (especially when it comes to deleting records). >> >> You should *never* use a GET request to do actions like deleting >> records. You already are aware of it being risky, so don't do this. You >> should use GET for getting information, and POST for modifying information. > > You should *never* say never, because there might be situations where > exceptions from rules are valid. This is one such cases. Making this a > post means that you need to resort to javascript to populate & submit > a hidden HTML-form. Just for the sake of a POST. Make each edit/delete button a submit button and optionally style it. > Also, your claim of it being more risky is simply nonsense. GET is a > tiny bit more prone to tinkering by the average user. But calling this > less risky is promoting security by obscurity, at most. Maybe you should think about what happens if someone posts: to a popular forum... -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From robert.kern at gmail.com Wed Feb 3 19:49:58 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 03 Feb 2010 18:49:58 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-03 18:01 PM, Steven D'Aprano wrote: > On Wed, 03 Feb 2010 16:38:21 -0600, Robert Kern wrote: > >>>> class.method(name, count) >>> >>> Obviously? I don't know about that. Being told that "count" is an int >>> doesn't really help me -- it's obvious just from the name. In a well- >>> written API, what else could it be? >> >> A bool. As in telling the method whether or not it should count >> something. > > Ha ha, good point. I question that this is a well-written API: such flags > to change the behaviour of a function/method are generally poor design. > If method behaves differently depending on whether or not you want it to > count something, then it is usually better design to have two methods, > one that counts and one that doesn't. I prefer Guido's formulation (which, naturally, I can't find a direct quote for right now): if you expect that a boolean argument is only going to take *literal* True or False, then it should be split into two functions. There is a use case for a boolean argument like this when you can expect to pass around a variable between multiple functions. Of course, this also might be the private API that the public API (with two distinct methods for each case) uses internally in order to avoid code duplication. Private APIs need to be documented, too. > In any case, yes, the weakness of naming conventions is that there are > always odd-corner cases of natural language. Perhaps `name` is also a > flag telling the method whether or not to name something. > > But then, one can write crappy APIs in any language. Well, I'm not trying to make Paul's point that other languages are better in this regard. I think that type documentation is quite helpful, but requiring static type declaration to get that documentation is an undesirable tradeoff for most of the code that I want to write. I do think it is worthwhile to recognize that the tradeoff does cut the other way, too. It just so happens that Python has docstrings and argument annotations to document argument types without the burden of static typing. Not all good, clean APIs are always going to have argument names that clearly inform the kind of type it expects. And what an author thinks is obviously deducible while writing the API is often quite different from what a new user thinks is obvious. There isn't much reason to place that cognitive burden on the (many) readers of the code when the (single) author can put in a word or two into the docstring (once) to describe what the parameter is expected to be. Figuring out how to use an API to solve your real problem is hard enough without having your brainpower nickled-and-dimed at every turn. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at holdenweb.com Wed Feb 3 19:52:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 19:52:28 -0500 Subject: PyChecker under python's virtualenv In-Reply-To: <7sub7uFstoU1@mid.uni-berlin.de> References: <7sub7uFstoU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Am 03.02.10 22:46, schrieb soltys: >> Hi Everybody, >> I've been doing some test on pythons' virtualenv and recently I've >> decided to run PyChecker. But I'm having some difficulties with importing >> modules available only on virtualenv by pychecker. As if it was >> trying to use systemwide python. >> I've googled about it, and found nothing in this area. >> I installed pychecker using python setup.py install >> from virtualenv. I looked at pychecker script - it uses correct python. > > I doubt that it uses the "correct python", because then you wouldn't > have the problems you have. > > I don't use pychecker, but pylint. And there, the system-wide command > uses the system's python - which of course doesn't know anything about > virtualenv. > > There are two solutions to this problem: > > - install py(lint|checker) into your virtualenv. See the OP's original assertion: >> I installed pychecker using python setup.py install >> from virtualenv. I looked at pychecker script - it uses correct python. Isn't that "installing into his virtualenv"? regards Steve > - write a wrapper-script that invokes py(lint|checker) with an adapted > PYTHONPATH environtment variable, based on the venv's sys.path. I do > that for my epylint-wrapper for emacs. Works flawlessly. > > > Diez -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 3 19:55:45 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 19:55:45 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: Vladimir Ignatov wrote: >> can you sketch an example/use case more concretely? > > Sorry, I don't have anything written down. I just have some rough idea > of implementation and some concrete features I would like to see in > such system. For example: > > 1) Instant refactoring. No more needs for manual > search/inspect/rename. Since system knows exactly that is going on, > the refactoring will be fully automatic. You'll probably want to take a look at "Bicycle Repair Man", which offers Python refactoring functionality. > 2) Show "xref table" for each function. How often this function used? > Where is it used? (code snippets of calls) What functionality is > supported by this function? Bear in mind this information can only ever be partial, since functions are first-class objects and aren't always referred to by their original name. > 3) Extended statistics. How many objects this object/function > interacts with? Popular functions, dead/unused functions. > 4) Code smell detector - too long functions, too much interaction with > other objects, global objects, etc. > ... > Also take a look at pylint and pychecker, which are already built to perform that kind of check on Python code. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From john at castleamber.com Wed Feb 3 19:56:10 2010 From: john at castleamber.com (John Bokma) Date: Wed, 03 Feb 2010 18:56:10 -0600 Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <87eil1ddjp.fsf_-_@castleamber.com> Lou Pecora writes: > That's a pretty accurate description of how I transitioned to Python > from C and Fortran. Not C, but C++ (but there are also C implementations): YAML, see: http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument I use YAML now and then with Perl for both reading/writing data and for debugging purposes (YAML is quite human readable, for programmers at least) Of course there is also YAML support for Python: http://pyyaml.org/. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From wuwei23 at gmail.com Wed Feb 3 20:03:47 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 3 Feb 2010 17:03:47 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <1dbae543-f4f4-4a79-bcda-58498a9c375d@f17g2000prh.googlegroups.com> Adam Tauno Williams wrote: > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" Could you provide an actual example to support this? The only places I tend to see 'x' as a parameter in the Python library docs are where it's clearly a number, or the text immediately beneath it explains exactly what it is. random.seed([x]) Initialize the basic random number generator. Optional argument x can be any hashable object. Everywhere else, the docs seem to declare what the parameters should be _and_ explains them in the text: itertools.combinations(iterable, r) Return r length subsequences of elements from the input iterable. If you're finding places in the docs where this isn't the case, I'd treat them as a documentation bug and report them. If it's not obvious to you what an iterable is, well, I'm sure you've got a disparaging term for those of us who do... From aahz at pythoncraft.com Wed Feb 3 20:32:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 3 Feb 2010 17:32:31 -0800 Subject: Selenium/SauceLabs OpenSpace at Pycon References: Message-ID: In article , Raymond Hettinger wrote: > >For those who are interested, the Sauce Labs team, >http://saucelabs.com/about/team, is hosting two free tutorial open >space sessions at Pycon in Atlanta. Congrats on the new job! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From icanbob at gmail.com Wed Feb 3 20:40:00 2010 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 3 Feb 2010 17:40:00 -0800 (PST) Subject: simple and fast platform independent IPC References: <4b6934ba$0$18396$426a34cc@news.free.fr> Message-ID: <4b497d3e-32c5-4e4f-b607-fb1b5a51f519@k22g2000vbp.googlegroups.com> On Feb 3, 3:32 am, News123 wrote: > Hi, > > I wondered what IPC library might be best simplest for following task? > > I'm having a few python scripts all running on the same host (linux or > win), which are started manually in random order. (no common parent process) > Each process might be identified by an integer (1,2,3) or by a symbolic > name ( 'dad' , 'mom' , 'dog' ) > > these scripts want to send short messages to each other ( mostly > integers, max a few bytes, short string), which would be enqueued in > message queues of the receiving process. > > example: > > 'dad' wants to tell 'mom': 'cook' > 'dog' wants to tell 'dad' : 'feedme' > 'mom' wants to tell 'dad' : 'cookyourself' > > the receiver dos not necesarily have to know who sent the message > > a message shall be dropped silently if the receiving process is not running > > a message shall be reliably delivered if the receiving process is up > > xmlrpc seems to be a little heavy for such tasks. > > signals don't allow to exchange data > > a shared memory message queue would probably a good solution, but > python's Multiprocessing.Queue seems to require a common parent process > > thanks a lot for any ideas / suggestions > > N > > N Have a look at the SIMPL toolkit (http://www.icanprogram.com/simpl or http://www.icanprogram.com/06py/main.html). It should do everything you describe at least on the Linux end of the spectrum. Under the hood SIMPL uses a shared memory scheme for local message exchange. SIMPL would be especially effective if you want to move your modules at some future point onto different nodes. SIMPL-Python can work seamlessly on heterogeneous networks provided at least one node is Linux. bob From ben+python at benfinney.id.au Wed Feb 3 20:46:27 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Feb 2010 12:46:27 +1100 Subject: Dreaming of new generation IDE References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> Message-ID: <87k4utn570.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 03 Feb 2010 18:48:12 +0300, Vladimir Ignatov wrote: > > [?] system "knows" all your identifiers and just regenerates > > relevant portions of text from internal database-alike > > representation. You will probably want to learn about ?refactoring? to see if that's related to what you mean . > Something like Bicycle Repair Man then: Bicycle Repair Man has not shown any development activity since 2004. Which is a shame, because it's an awesomely appropriate name for what it does :-) The niche is now occupied by the Rope library and tools . -- \ ?Holy knit one purl two, Batman!? ?Robin | `\ | _o__) | Ben Finney From no.email at nospam.invalid Wed Feb 3 20:51:36 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 17:51:36 -0800 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <7xbpg5dazb.fsf@ruckus.brouhaha.com> John Nagle writes: > Analysis of each domain is > performed in a separate process, but each process uses multiple > threads to read process several web pages simultaneously. > > Some of the threads go compute-bound for a second or two at a time as > they parse web pages. You're probably better off using separate processes for the different pages. If I remember, you were using BeautifulSoup, which while very cool, is pretty doggone slow for use on large volumes of pages. I don't know if there's much that can be done about that without going off on a fairly messy C or C++ coding adventure. Maybe someday someone will do that. From ben+python at benfinney.id.au Wed Feb 3 20:57:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 04 Feb 2010 12:57:18 +1100 Subject: Dreaming of new generation IDE References: <1265203120.7916.5.camel@linux-m3mt> <7x4olys7mb.fsf@ruckus.brouhaha.com> Message-ID: <87fx5hn4ox.fsf@benfinney.id.au> Robert Kern writes: > It is perfectly reasonable (and often necessary) for the unit test of > class B to use a mock object instead of a real A() instance. The unit > test for class B will fail to catch the renaming of A.foo() to A.bar() > because it never tries to call .foo() on a real A instance. Right, which is one good reason why unit tests are *necessary* but not *sufficient*. You also need so-called ?integration? tests (make sure modules work together as expected) and ?system? tests (make sure the whole running system behaves as expected). This need for testing is true regardless of whether you're using a statically-typed or dynamically-typed language, of course. (I hope no-one here thinks that static typing obviates the need for integration and system tests in the test suite.) -- \ ?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 wuwei23 at gmail.com Wed Feb 3 21:08:52 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 3 Feb 2010 18:08:52 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> Message-ID: <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> On Feb 4, 8:47?am, Phlip wrote: > Yes, calling os.path.walk() and os.path.join() all the time on raw > strings is fun, but I seem to recall from my Ruby days a class called > Pathname, which presented an object that behaved like a string at > need, and like a filesystem path at need. path + 'folder' would > call .join() and insert the / correctly, for example. > > What's the best equivalent in Python-land? It's no longer supported, but the 3rd party 'path' module used to be the go-to module for this: >>> from path import path C:\Python26\lib\site-packages\path.py:32: DeprecationWarning: the md5 module is deprecated; use hashlib instead import sys, warnings, os, fnmatch, glob, shutil, codecs, md5 >>> c = path('C:\\') >>> c.listdir() [path(u'C:\\AUTOEXEC.BAT'), path(u'C:\\boot.ini'), ...] >>> (c + 'python26').listdir() [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ \python26\\DLLs'), ...] >>> (c / 'python26').listdir() [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ \python26\\DLLs'), ...] I've hand edited the results for brevity... The module could do with some TLC to bring it up to date, but warning aside it still seems to work fine under 2.6. (From memory, I think the original author gave up when it became clear it would never be integrated into the standard lib[1], which is a shame, I think there's scope for a pathtools addition to the lib that provides this level of convenience...) There was also a PEP with another possible implementation: http://www.python.org/dev/peps/pep-0355/ Hope this helps. From wuwei23 at gmail.com Wed Feb 3 21:17:06 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 3 Feb 2010 18:17:06 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <4da2372c-954c-46b8-a6e9-2768bce812f5@l19g2000yqb.googlegroups.com> Message-ID: "Timothy N. Tsvetkov" wrote: > Jonathan Gardner > > Python is much, much cleaner. I don't know how anyone can honestly say > > Ruby is cleaner than Python. > > I developed on both (Python was first) and I think that ruby I > very clean and maybe cleaner than Python. > > And you're wrong with blocks. You say 'static', and I say 'dynamic'. You say 'consistent', and I say 'erratic'. Static! Dynamic! Consistent! Erratic! Let's join the right news group. From mf2286 at gmail.com Wed Feb 3 21:33:33 2010 From: mf2286 at gmail.com (mf) Date: Wed, 3 Feb 2010 18:33:33 -0800 (PST) Subject: Repeat an exception Message-ID: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> I'm translating a db from english to spanish with the Google translator API. The problem is when a TranslationError occurs(usually because of connection problems). I can except the first one, but I don't know how to except again. I "solved" the problem by saving temp db's and then joining them, but it must be a pythonic way to do it. Here's a snippet from the code: english_field = oldDb[i].fieldData[0] #oldDb is a db filled with english words try: spanish_field = translate(english_field, lang_to='es', lang_from='en') except TranslationError: spanish_field = translate(english_field, lang_to='es', lang_from='en') #Then I save the fields into a new db From nobody at nowhere.com Wed Feb 3 21:52:14 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Feb 2010 02:52:14 +0000 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 03 Feb 2010 14:09:07 -0800, Paul Rubin wrote: >> Also, your claim of it being more risky is simply nonsense. GET is a >> tiny bit more prone to tinkering by the average user. But calling this >> less risky is promoting security by obscurity, at most. > > GET parameters also tend to get recorded in the http logs of web proxies > and web servers while POST parameters usually aren't. More significantly, they'll appear in the Referer: header for any link the user follows from the page, so they're visible to anyone who can get a link to their site onto the page (whether , or whatever). Even if this isn't possible at the moment, will you remember to fix it the first time you allow an off-site link? You should assume that anything which goes into a GET request is visible to the entire world. Don't put anything even remotely private in there. From alfps at start.no Wed Feb 3 21:56:53 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 03:56:53 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * David Monaghan: > I have a small program which reads files from the directory in which it > resides. It's written in Python 3 and when run through IDLE or PythonWin > works fine. If I double-click the file, it works fine in Python 2.6, but in > 3 it fails because it looks for the files to load in the Python31 folder, > not the one the script is in. > > It's not a big deal, but browsing around I haven't found why the behaviour > has been changed or any comment about it (That might be my poor search > technique, I suppose). > > The program fails at: > > try: > tutdoc = minidom.parse(".//Myfile.xml") > except IOError: > The "//" is wrong, but should not cause the behavior that you describe. Try to post a complete smallest possible program that exhibits the problem. Possibly, in creating that example you'll also find what's cause the problem. :-) Cheers & hth., - Alf From alfps at start.no Wed Feb 3 22:00:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 04:00:45 +0100 Subject: Repeat an exception In-Reply-To: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> Message-ID: * mf: > I'm translating a db from english to spanish with the Google > translator API. The problem is when a TranslationError occurs(usually > because of connection problems). I can > except the first one, but I don't know how to except again. I "solved" > the problem by saving temp db's and then joining them, but it must be > a pythonic way to do it. > > Here's a snippet from the code: > > english_field = oldDb[i].fieldData[0] #oldDb is a db filled > with english words Is this actual code? I may be mistaken, but at least in Python 3.x it seems there should be a comma between each 'with' expression. And there should certainly be a colon at the end. It's best to copy and paste real code. Made-up code can just be misleading for those who'd like to help. > try: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > except TranslationError: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > > #Then I save the fields into a new db Possibly I'm misunderstanding what you mean, but have you thought of using a loop? Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Wed Feb 3 22:09:02 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 00:09:02 -0300 Subject: Code snippet: dualmethod descriptor References: <0373b8b9$0$1309$c3e8da3@news.astraweb.com> Message-ID: En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano escribi?: > class dualmethod(object): > """Descriptor implementing dualmethods (combination > class/instance method). > > Returns a method which takes either an instance or a class as > the first argument. When called on an instance, the instance is > passed as the first argument. When called as a class, the class > itself is passed instead. Seems useful! Perhaps a better place to post it would be , at least it's easier to search. -- Gabriel Genellina From benjamin.kaplan at case.edu Wed Feb 3 22:14:59 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Feb 2010 22:14:59 -0500 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: > * David Monaghan: >> >> I have a small program which reads files from the directory in which it >> resides. It's written in Python 3 and when run through IDLE or PythonWin >> works fine. If I double-click the file, it works fine in Python 2.6, but >> in >> 3 it fails because it looks for the files to load in the Python31 folder, >> not the one the script is in. >> >> It's not a big deal, but browsing around I haven't found why the behaviour >> has been changed or any comment about it (That might be my poor search >> technique, I suppose). >> >> The program fails at: >> >> ? ?try: >> ? ? ? ?tutdoc = minidom.parse(".//Myfile.xml") >> ? ?except IOError: >> ? ? ? ? > > The "//" is wrong, but should not cause the behavior that you describe. > > Try to post a complete smallest possible program that exhibits the problem. > > Possibly, in creating that example you'll also find what's cause the > problem. :-) > > > Cheers & hth., > > - Alf That is the smallest example the exhibits the problem. It's not an issue with the Python code, it's an issue with how Windows is running it. I don't know enough about the way Windows Explorer runs files, but it seems to be doing the equivalent of cd C:\Python31 python31.exe C:\full\path\to\script\foo.py instead of cd C:\full\path\path\to\script C:\Python31\python.exe foo.py which is David expected. This throws off the relative filepath. The easiest way to solve this permanently, by the way, is to not use relative paths. All it takes is one script to call os.chdir and the script breaks. You can use __file__ and the os.path module to figure out exactly where you are in an OS-agnostic way. import os.path #get the absolute path to the current script abs_path = os.path.abspath(__file__) # get the full path to the directory of the script directory = os.path.dirname(abs_path) #get the full path to your file my_file = os.path.join(directory, "MyFile.xml") > -- > http://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Wed Feb 3 22:17:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Feb 2010 03:17:43 +0000 Subject: Repeat an exception In-Reply-To: References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> Message-ID: <4B6A3C57.2000606@mrabarnett.plus.com> Alf P. Steinbach wrote: > * mf: >> I'm translating a db from english to spanish with the Google >> translator API. The problem is when a TranslationError occurs(usually >> because of connection problems). I can >> except the first one, but I don't know how to except again. I "solved" >> the problem by saving temp db's and then joining them, but it must be >> a pythonic way to do it. >> >> Here's a snippet from the code: >> >> english_field = oldDb[i].fieldData[0] #oldDb is a db filled >> with english words > > Is this actual code? I may be mistaken, but at least in Python 3.x it > seems there should be a comma between each 'with' expression. And there > should certainly be a colon at the end. > > It's best to copy and paste real code. > > Made-up code can just be misleading for those who'd like to help. > It looks to me like the line wrapped during posting, ie the 'with' part belongs to the comment. > >> try: >> spanish_field = translate(english_field, lang_to='es', >> lang_from='en') >> except TranslationError: >> spanish_field = translate(english_field, lang_to='es', >> lang_from='en') >> >> #Then I save the fields into a new db > > Possibly I'm misunderstanding what you mean, but have you thought of > using a loop? > In other words: for attempt in range(2): try: spanish_field = translate(english_field, lang_to='es', lang_from='en') break except TranslationError: pass else: # Didn't break out of the loop, therefore not successful. print "Translation failed" From michael.gruenstaeudl at mail.utexas.edu Wed Feb 3 22:33:08 2010 From: michael.gruenstaeudl at mail.utexas.edu (Michael Gruenstaeudl) Date: Wed, 03 Feb 2010 21:33:08 -0600 Subject: Refreshing of urllib.urlopen() Message-ID: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> Hi, I am fairly new to Python and need advice on the urllib.urlopen() function. The website I am trying to open automatically refreshes after 5 seconds and remains stable thereafter. With urllib.urlopen().read() I can only read the initial but not the refreshed page. How can I access the refreshed page via urlopen().read()? I have already tried to intermediate with time.sleep() before invoking .read() (see below), but this does not work. page=urllib.urlopen(url) time.sleep(20) htmltext=page.readlines() Thanks, Michael G. From alfps at start.no Wed Feb 3 22:44:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 04:44:00 +0100 Subject: Repeat an exception In-Reply-To: References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> Message-ID: * MRAB: > Alf P. Steinbach wrote: >> * mf: >>> I'm translating a db from english to spanish with the Google >>> translator API. The problem is when a TranslationError occurs(usually >>> because of connection problems). I can >>> except the first one, but I don't know how to except again. I "solved" >>> the problem by saving temp db's and then joining them, but it must be >>> a pythonic way to do it. >>> >>> Here's a snippet from the code: >>> >>> english_field = oldDb[i].fieldData[0] #oldDb is a db filled >>> with english words >> >> Is this actual code? I may be mistaken, but at least in Python 3.x it >> seems there should be a comma between each 'with' expression. And >> there should certainly be a colon at the end. >> >> It's best to copy and paste real code. >> >> Made-up code can just be misleading for those who'd like to help. >> > It looks to me like the line wrapped during posting, ie the 'with' part > belongs to the comment. *banging me head* thx What one gets from conditioning oneself to ignore comments in code. >>> try: >>> spanish_field = translate(english_field, lang_to='es', >>> lang_from='en') >>> except TranslationError: >>> spanish_field = translate(english_field, lang_to='es', >>> lang_from='en') >>> >>> #Then I save the fields into a new db >> >> Possibly I'm misunderstanding what you mean, but have you thought of >> using a loop? >> > In other words: > > for attempt in range(2): > try: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > break > except TranslationError: > pass > else: > # Didn't break out of the loop, therefore not successful. > print "Translation failed" Cheers, - Alf From nagle at animats.com Wed Feb 3 22:46:43 2010 From: nagle at animats.com (John Nagle) Date: Wed, 03 Feb 2010 19:46:43 -0800 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <7xbpg5dazb.fsf@ruckus.brouhaha.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> Message-ID: <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Paul Rubin wrote: > John Nagle writes: >> Analysis of each domain is >> performed in a separate process, but each process uses multiple >> threads to read process several web pages simultaneously. >> >> Some of the threads go compute-bound for a second or two at a time as >> they parse web pages. > > You're probably better off using separate processes for the different > pages. If I remember, you were using BeautifulSoup, which while very > cool, is pretty doggone slow for use on large volumes of pages. I don't > know if there's much that can be done about that without going off on a > fairly messy C or C++ coding adventure. Maybe someday someone will do > that. I already use separate processes for different domains. I could live with Python's GIL as long as moving to a multicore server doesn't make performance worse. That's why I asked about CPU dedication for each process, to avoid thrashing at the GIL. There's enough intercommunication between the threads working on a single site that it's a pain to do them as subprocesses. And I definitely don't want to launch subprocesses for each page; the Python load time would be worse than the actual work. The subprocess module assumes you're willing to launch a subprocess for each transaction. The current program organization is that there's a scheduler process which gets requests, prioritizes them, and runs the requested domains through the site evaluation mill. The scheduler maintains a pool of worker processes which get work request via their input pipe, in Pickle format, and return results, again in Pickle format. When not in use, the worker processes sit there dormant, so there's no Python launch cost for each transaction. If a worker process crashes, the scheduler replaces it with a fresh one, and every few hundred uses, each worker process is replaced with a fresh copy, in case Python has a memory leak. It's a lot like the way FCGI works. Scheduling is managed using an in-memory table in MySQL, so the load can be spread over a cluster if desired, with a scheduler process on each machine. So I already have a scalable architecture. The only problem is excess overhead on multicore CPUs. John Nagle From cmpython at gmail.com Wed Feb 3 22:50:00 2010 From: cmpython at gmail.com (CM) Date: Wed, 3 Feb 2010 19:50:00 -0800 (PST) Subject: Background Zones in Pylab Plot References: <1eaf6046-db41-44b5-8c9e-b7a15e4cf078@30g2000vbj.googlegroups.com> Message-ID: <5a9e5eaf-2006-4dfe-8498-a544c09a8584@r6g2000yqn.googlegroups.com> On Feb 3, 10:49?am, Wanderer wrote: > I would like to add background zones in pylab plots. Colored sections > of the background that the curves pass through. Is this possible? My > google searches don't turn up anything but maybe my search terms > aren't the right ones. > > Thanks If you look at the matplotlib gallery, I think there may be some images that show something like what you want, and then you can look at the code. It's here: http://matplotlib.sourceforge.net/gallery.html HTH, Che From steve at holdenweb.com Wed Feb 3 22:50:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 22:50:19 -0500 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4b6a3f46$0$1597$742ec2ed@news.sonic.net> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: John Nagle wrote: > Paul Rubin wrote: >> John Nagle writes: >>> Analysis of each domain is >>> performed in a separate process, but each process uses multiple >>> threads to read process several web pages simultaneously. >>> >>> Some of the threads go compute-bound for a second or two at a time as >>> they parse web pages. >> >> You're probably better off using separate processes for the different >> pages. If I remember, you were using BeautifulSoup, which while very >> cool, is pretty doggone slow for use on large volumes of pages. I don't >> know if there's much that can be done about that without going off on a >> fairly messy C or C++ coding adventure. Maybe someday someone will do >> that. > > I already use separate processes for different domains. I could > live with Python's GIL as long as moving to a multicore server > doesn't make performance worse. That's why I asked about CPU dedication > for each process, to avoid thrashing at the GIL. > I believe it's already been said that the GIL thrashing is mostly MacOS specific. You might also find something in the affinity module http://pypi.python.org/pypi/affinity/0.1.0 to ensure that each process in your pool runs on only one processor. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From hidura at gmail.com Wed Feb 3 23:00:56 2010 From: hidura at gmail.com (Hidura) Date: Thu, 4 Feb 2010 00:00:56 -0400 Subject: Problem with __init__.py in Python3.1 Message-ID: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> Good evening list, I have a really big trouble with the imports in the 3.1 version(Notes: In the older 2.64 theres no problems), I have two packages, the first package Utilities who contains Writer the second package, Writers contain the module tagmanip(What is imported in the best way inside the __init__.py of the Writer), when i make the import inside the writer everything is ok, but from the Utilities package the errors says: "ImportError: No module named tagsmanip". I don't understand why this is happening, if somebody could help me i will glad to hear any suggestion. Atte. -- Diego I. Hidalgo D. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 3 23:02:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 03 Feb 2010 23:02:35 -0500 Subject: Refreshing of urllib.urlopen() In-Reply-To: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> References: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> Message-ID: Michael Gruenstaeudl wrote: > Hi, > I am fairly new to Python and need advice on the urllib.urlopen() > function. The website I am trying to open automatically refreshes after > 5 seconds and remains stable thereafter. With urllib.urlopen().read() I > can only read the initial but not the refreshed page. How can I access > the refreshed page via urlopen().read()? I have already tried to > intermediate with time.sleep() before invoking .read() (see below), but > this does not work. > > page=urllib.urlopen(url) > time.sleep(20) > htmltext=page.readlines() > When you say the page "refreshes" every 5 seconds, does it do so by redirecting the browser to the same address with new content? I suspect this is the case, because otherwise page.readlines() would not return because it wouldn't have seen the "end of file" on the incoming network stream. You can find this out by examining the page's headers. If page.headers['Refresh'] exists and has a value (like "5; url=http://") then browser refresh is being used. If that's so then the only way to access the content is to re-open the URL and read the updated content. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From kmisoft at gmail.com Wed Feb 3 23:13:18 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 07:13:18 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <87k4utn570.fsf@benfinney.id.au> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <87k4utn570.fsf@benfinney.id.au> Message-ID: >> > [?] system "knows" all your identifiers and just regenerates >> > relevant portions of text from internal database-alike >> > representation. > > You will probably want to learn about ?refactoring? to see if that's > related to what you mean . I mean if system actually "understands" your code (instead of try to figure it out from existing text files with source code), then much more complex refactoring is possible. My favorite refactoring is "Replace Method with Method Object". It is hard to imagine "external" tool that can provide such refactoring for python code. >> Something like Bicycle Repair Man then: > Bicycle Repair Man has not shown any development activity since 2004. > Which is a shame, because it's an awesomely appropriate name for what it > does :-) I believe it still live under the hood of PyDev plugin. I use it almost every day and need to say that it don't provide much more than simple renaming (which works right in 80% of cases in recent version). Vladimir Ignatov From alfps at start.no Wed Feb 3 23:18:38 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 05:18:38 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * Benjamin Kaplan: > On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: >> * David Monaghan: >>> I have a small program which reads files from the directory in which it >>> resides. It's written in Python 3 and when run through IDLE or PythonWin >>> works fine. If I double-click the file, it works fine in Python 2.6, but >>> in >>> 3 it fails because it looks for the files to load in the Python31 folder, >>> not the one the script is in. >>> >>> It's not a big deal, but browsing around I haven't found why the behaviour >>> has been changed or any comment about it (That might be my poor search >>> technique, I suppose). >>> >>> The program fails at: >>> >>> try: >>> tutdoc = minidom.parse(".//Myfile.xml") >>> except IOError: >>> >> The "//" is wrong, but should not cause the behavior that you describe. >> >> Try to post a complete smallest possible program that exhibits the problem. >> >> Possibly, in creating that example you'll also find what's cause the >> problem. :-) >> >> >> Cheers & hth., >> >> - Alf > > That is the smallest example the exhibits the problem. No, it doesn't seem to exhibit the problem at all. :-) > It's not an > issue with the Python code, it's an issue with how Windows is running > it. I don't know enough about the way Windows Explorer runs files, but > it seems to be doing the equivalent of > cd C:\Python31 > python31.exe C:\full\path\to\script\foo.py > > instead of > cd C:\full\path\path\to\script > C:\Python31\python.exe foo.py > which is David expected. This throws off the relative filepath. No, this is not what happens. What happens is that when you double-click the script, then __file__ is set to the absolute path instead of just the filename, at least on my machine (XP); whether the full path or just the filename is passed on the OS level depends, however, on the Windows version. The current directory is always (initially) correct, as the script's directory. > The easiest way to solve this permanently, by the way, is to not use > relative paths. All it takes is one script to call os.chdir and the > script breaks. You can use __file__ and the os.path module to figure > out exactly where you are in an OS-agnostic way. > > import os.path > #get the absolute path to the current script > abs_path = os.path.abspath(__file__) According to the docs: "On most platforms, this is equivalent to normpath(join(os.getcwd(), path))." Therefore, if getcwd() is not the script's directory, as you hypothesize above, then most likely the result of this code is Not The Path You're Looking For. However, since the current directory is in fact OK, the above is one way to get a sort of canonical (a where-you-know-the-format) representation of __file__. > # get the full path to the directory of the script > directory = os.path.dirname(abs_path) This is very much likely to yield the same result as calling os.getcwd(); see above. > #get the full path to your file > my_file = os.path.join(directory, "MyFile.xml") Cheers & hth., - Alf From benjamin.kaplan at case.edu Wed Feb 3 23:41:00 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Wed, 3 Feb 2010 23:41:00 -0500 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: On Wed, Feb 3, 2010 at 11:18 PM, Alf P. Steinbach wrote: > * Benjamin Kaplan: >> >> On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: >>> >>> * David Monaghan: >>>> >>>> I have a small program which reads files from the directory in which it >>>> resides. It's written in Python 3 and when run through IDLE or PythonWin >>>> works fine. If I double-click the file, it works fine in Python 2.6, but >>>> in >>>> 3 it fails because it looks for the files to load in the Python31 >>>> folder, >>>> not the one the script is in. >>>> >>>> It's not a big deal, but browsing around I haven't found why the >>>> behaviour >>>> has been changed or any comment about it (That might be my poor search >>>> technique, I suppose). >>>> >>>> The program fails at: >>>> >>>> ? try: >>>> ? ? ? tutdoc = minidom.parse(".//Myfile.xml") >>>> ? except IOError: >>>> ? ? ? >>> >>> The "//" is wrong, but should not cause the behavior that you describe. >>> >>> Try to post a complete smallest possible program that exhibits the >>> problem. >>> >>> Possibly, in creating that example you'll also find what's cause the >>> problem. :-) >>> >>> >>> Cheers & hth., >>> >>> - Alf >> >> That is the smallest example the exhibits the problem. > > No, it doesn't seem to exhibit the problem at all. :-) > > >> It's not an >> issue with the Python code, it's an issue with how Windows is running >> it. I don't know enough about the way Windows Explorer runs files, but >> it seems to be doing the equivalent of >> cd C:\Python31 >> python31.exe C:\full\path\to\script\foo.py >> >> instead of >> cd C:\full\path\path\to\script >> C:\Python31\python.exe foo.py >> which is David expected. This throws off the relative filepath. > > No, this is not what happens. > > What happens is that when you double-click the script, then __file__ is set > to the absolute path instead of just the filename, at least on my machine > (XP); whether the full path or just the filename is passed on the OS level > depends, however, on the Windows version. > > The current directory is always (initially) correct, as the script's > directory. > Read my first paragraph again- it has absolutely nothing to do with Python. It has to do with how the Windows is running Python 3 on the OP's computer. The OP's description said that it was looking for the file .\\myfile.xml in C:\Python31 which means it translated '.', the current working directory, to be C:\Python31 and not the directory the script is in. > >> The easiest way to solve this permanently, by the way, is to not use >> relative paths. All it takes is one script to call os.chdir and the >> script breaks. You can use __file__ and the os.path module to figure >> out exactly where you are in an OS-agnostic way. >> >> import os.path >> #get the absolute path to the current script >> abs_path = os.path.abspath(__file__) > > According to the docs: "On most platforms, this is equivalent to > normpath(join(os.getcwd(), path))." > os.path.abspath will always work in this case (unless something changes the current working directory before that statement runs) because __file__ is given either as an absolute path or as relative to the current working directory. ----- /Users/bkaplan/test/test.py print(__file__) import os.path print(os.path.abspath(__file__)) ------------------ $ cd /users/bkaplan $ python3 test/test.py python3 test/test.py test/test.py /Users/bkaplan/test/test.py $cd /users/bkaplan/test $ python3 test.py test.py /Users/bkaplan/test/test.py If abspath is given an absolute path, it won't touch it Output from double clicking on the file: /Users/bkaplan/test/test.py /Users/bkaplan/test/test.py > Therefore, if getcwd() is not the script's directory, as you hypothesize > above, then most likely the result of this code is Not The Path You're > Looking For. > Except that if the cwd is not the directory the script is running in, __file__ should still point to it either through an absolute path (highly likely since it's run through Windows Explorer) or some (however convoluted) relative path. > However, since the current directory is in fact OK, the above is one way to > get a sort of canonical (a where-you-know-the-format) representation of > __file__. > > >> ?# get the full path to the directory of the script >> directory = os.path.dirname(abs_path) > > This is very much likely to yield the same result as calling os.getcwd(); > see above. > Not if there is more than one folder between __file__ and cwd. For instance, if the script is in a package several directories down from the main script. > >> #get the full path to your file >> my_file = os.path.join(directory, "MyFile.xml") > > > Cheers & hth., > > - Alf > -- > http://mail.python.org/mailman/listinfo/python-list > From alfps at start.no Thu Feb 4 00:20:47 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 06:20:47 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * Benjamin Kaplan: > On Wed, Feb 3, 2010 at 11:18 PM, Alf P. Steinbach wrote: >> * Benjamin Kaplan: >>> On Wed, Feb 3, 2010 at 9:56 PM, Alf P. Steinbach wrote: >>>> * David Monaghan: >>>>> I have a small program which reads files from the directory in which it >>>>> resides. It's written in Python 3 and when run through IDLE or PythonWin >>>>> works fine. If I double-click the file, it works fine in Python 2.6, but >>>>> in >>>>> 3 it fails because it looks for the files to load in the Python31 >>>>> folder, >>>>> not the one the script is in. >>>>> >>>>> It's not a big deal, but browsing around I haven't found why the >>>>> behaviour >>>>> has been changed or any comment about it (That might be my poor search >>>>> technique, I suppose). >>>>> >>>>> The program fails at: >>>>> >>>>> try: >>>>> tutdoc = minidom.parse(".//Myfile.xml") >>>>> except IOError: >>>>> >>>> The "//" is wrong, but should not cause the behavior that you describe. >>>> >>>> Try to post a complete smallest possible program that exhibits the >>>> problem. >>>> >>>> Possibly, in creating that example you'll also find what's cause the >>>> problem. :-) >>>> >>>> >>>> Cheers & hth., >>>> >>>> - Alf >>> That is the smallest example the exhibits the problem. >> No, it doesn't seem to exhibit the problem at all. :-) >> >> >>> It's not an >>> issue with the Python code, it's an issue with how Windows is running >>> it. I don't know enough about the way Windows Explorer runs files, but >>> it seems to be doing the equivalent of >>> cd C:\Python31 >>> python31.exe C:\full\path\to\script\foo.py >>> >>> instead of >>> cd C:\full\path\path\to\script >>> C:\Python31\python.exe foo.py >>> which is David expected. This throws off the relative filepath. >> No, this is not what happens. >> >> What happens is that when you double-click the script, then __file__ is set >> to the absolute path instead of just the filename, at least on my machine >> (XP); whether the full path or just the filename is passed on the OS level >> depends, however, on the Windows version. >> >> The current directory is always (initially) correct, as the script's >> directory. >> > > Read my first paragraph again- it has absolutely nothing to do with > Python. It has to do with how the Windows is running Python 3 on the > OP's computer. I'm not sure what you're arguing here. But anyway, first, I haven't stated that "it" is (only) an issue with Python: on the contrary, I explained how the program is run by Windows Explorer, where in Windows XP the full path is passed by Windows Explorer, and how that results in (can result in) a full path in __file__ when a script is run by double-clicking. Second, as stated your hypothesis about current directory is Wrong(TM). So the explanation of an incorrect result involves not only Windows Explorer, the Windows version, and Python, but also the OP's code is involved. Hence the request for a minimal, complete example -- which is nearly always a good idea. > The OP's description said that it was looking for the > file .\\myfile.xml in C:\Python31 which means it translated '.', the > current working directory, to be C:\Python31 and not the directory the > script is in. I fail to reproduce that behavior. By the way, are you the OP (just with another name)? If not, have you reproduced the described behavior? Then kindly post the code. >>> The easiest way to solve this permanently, by the way, is to not use >>> relative paths. All it takes is one script to call os.chdir and the >>> script breaks. You can use __file__ and the os.path module to figure >>> out exactly where you are in an OS-agnostic way. >>> >>> import os.path >>> #get the absolute path to the current script >>> abs_path = os.path.abspath(__file__) >> According to the docs: "On most platforms, this is equivalent to >> normpath(join(os.getcwd(), path))." >> > > os.path.abspath will always work in this case (unless something > changes the current working directory before that statement runs) Which change is what you surmised as a cause of the original problem. Hello. > because __file__ is given either as an absolute path or as relative to > the current working directory. No, that's incorrect. import os print( "Current directory: [" + os.getcwd() + "]" ) print( "__file__ = " + __file__ ) os.chdir( "blah" ) print( "Current directory: [" + os.getcwd() + "]" ) print( "__file__ = " + __file__ ) C:\Documents and Settings\Alf\test> python curdir.py Current directory: [C:\Documents and Settings\Alf\test] __file__ = curdir.py Current directory: [C:\Documents and Settings\Alf\test\blah] __file__ = curdir.py <-- *Not* relative to cwd. C:\Documents and Settings\Alf\test> _ [snip] > Except that if the cwd is not the directory the script is running in, > __file__ should still point to it either through an absolute path > (highly likely since it's run through Windows Explorer) or some > (however convoluted) relative path. Don't know about "should", but if you're talking reality, no, that's incorrect; see above. [snip] Cheers & hth., - Alf From alfps at start.no Thu Feb 4 00:46:45 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 04 Feb 2010 06:46:45 +0100 Subject: Python 3 minor irritation In-Reply-To: References: Message-ID: * Alf P. Steinbach: > * Benjamin Kaplan: >> On Wed, Feb 3, 2010 at 11:18 PM, Alf P. Steinbach wrote: >>> * Benjamin Kaplan: >>>> The easiest way to solve this permanently, by the way, is to not use >>>> relative paths. All it takes is one script to call os.chdir and the >>>> script breaks. You can use __file__ and the os.path module to figure >>>> out exactly where you are in an OS-agnostic way. >>>> >>>> import os.path >>>> #get the absolute path to the current script >>>> abs_path = os.path.abspath(__file__) >>> According to the docs: "On most platforms, this is equivalent to >>> normpath(join(os.getcwd(), path))." >>> >> >> os.path.abspath will always work in this case (unless something >> changes the current working directory before that statement runs) > > Which change is what you surmised as a cause of the original problem. > > Hello. > > >> because __file__ is given either as an absolute path or as relative to >> the current working directory. > > No, that's incorrect. Oh sorry, now I see what you mean. I read it too literally. You mean that at script startup __file__ is a valid relative or absolute path to the script. But anyways, Windows Explorer doesn't change the current directory to that of the associated program, at least not in Windows XP. Where there *is* a difference with double-clicking the script is in the path that ends up as __file__. [snip my silly code counter-example + even more silly comment] Cheers, - Alf From gagsl-py2 at yahoo.com.ar Thu Feb 4 01:02:29 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 03:02:29 -0300 Subject: Refreshing of urllib.urlopen() References: <20100203213308.sk3w3fz0g0g804gc@webmail.utexas.edu> Message-ID: En Thu, 04 Feb 2010 00:33:08 -0300, Michael Gruenstaeudl escribi?: > I am fairly new to Python and need advice on the urllib.urlopen() > function. The website I am trying to open automatically refreshes after > 5 seconds and remains stable thereafter. With urllib.urlopen().read() I > can only read the initial but not the refreshed page. How can I access > the refreshed page via urlopen().read()? I have already tried to > intermediate with time.sleep() before invoking .read() (see below), but > this does not work. > > page=urllib.urlopen(url) > time.sleep(20) > htmltext=page.readlines() How does the page refresh itself? If using a tag, look at the url. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 4 01:11:06 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 03:11:06 -0300 Subject: Problem with __init__.py in Python3.1 References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> Message-ID: En Thu, 04 Feb 2010 01:00:56 -0300, Hidura escribi?: > Good evening list, I have a really big trouble with the imports in the > 3.1 > version(Notes: In the older 2.64 theres no problems), I have two > packages, > the first package Utilities who contains Writer the second package, > Writers > contain the module tagmanip(What is imported in the best way inside the > __init__.py of the Writer), when i make the import inside the writer > everything is ok, but from the Utilities package the errors says: > "ImportError: No module named tagsmanip". > I don't understand why this is happening, if somebody could help me i > will > glad to hear any suggestion. In Python 3.x, "absolute" import is enabled by default (2.6 uses a mix of relative and absolute imports). To import sibling modules in a package, or modules in a subpackage, you have to use relative imports: from . import tagmanip from .Writers import tagmanip See PEP328 http://www.python.org/dev/peps/pep-0328/ -- Gabriel Genellina From nagle at animats.com Thu Feb 4 01:11:56 2010 From: nagle at animats.com (John Nagle) Date: Wed, 03 Feb 2010 22:11:56 -0800 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: <4b6a6150$0$1656$742ec2ed@news.sonic.net> Steve Holden wrote: > John Nagle wrote: >> Paul Rubin wrote: >>> John Nagle writes: >>>> Analysis of each domain is >>>> performed in a separate process, but each process uses multiple >>>> threads to read process several web pages simultaneously. >>>> >>>> Some of the threads go compute-bound for a second or two at a time as >>>> they parse web pages. >>> You're probably better off using separate processes for the different >>> pages. If I remember, you were using BeautifulSoup, which while very >>> cool, is pretty doggone slow for use on large volumes of pages. I don't >>> know if there's much that can be done about that without going off on a >>> fairly messy C or C++ coding adventure. Maybe someday someone will do >>> that. >> I already use separate processes for different domains. I could >> live with Python's GIL as long as moving to a multicore server >> doesn't make performance worse. That's why I asked about CPU dedication >> for each process, to avoid thrashing at the GIL. >> > I believe it's already been said that the GIL thrashing is mostly MacOS > specific. You might also find something in the affinity module No, the original analysis was MacOS oriented, but the same mechanism applies for fighting over the GIL on all platforms. There was some pontification that it might be a MacOS-only issue, but no facts were presented. It might be cheaper on C implementations with mutexes that don't make system calls for the non-blocking cases. John Nagle From gagsl-py2 at yahoo.com.ar Thu Feb 4 01:27:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 03:27:16 -0300 Subject: Python 3 minor irritation References: Message-ID: En Thu, 04 Feb 2010 02:46:45 -0300, Alf P. Steinbach escribi?: > Oh sorry, now I see what you mean. I read it too literally. You mean > that at script startup __file__ is a valid relative or absolute path to > the script. > > But anyways, Windows Explorer doesn't change the current directory to > that of the associated program, at least not in Windows XP. But the associated program might change the current directory - that's not the case with the default associations created by the Python installer, but one should verify this. To the OP: please create this small test script import os print("curdir=", os.getcwd()) print("__file__=", __file__) input() and post what you get when you double-click on it. Also, from the command line, execute: D:\temp>reg query HKCR\.py ! REG.EXE VERSION 3.0 HKEY_CLASSES_ROOT\.py REG_SZ Python.File Content Type REG_SZ text/plain HKEY_CLASSES_ROOT\.py\PersistentHandler D:\temp>reg query HKCR\Python.File\shell\open\command ! REG.EXE VERSION 3.0 HKEY_CLASSES_ROOT\Python.File\shell\open\command REG_SZ "D:\Apps\Python26\python.exe" "%1" %* The first command says that files ending with .py are of type "Python.File", the second one says which command is executed to open a "Python.File" file. -- Gabriel Genellina From cournape at gmail.com Thu Feb 4 01:33:10 2010 From: cournape at gmail.com (David Cournapeau) Date: Thu, 4 Feb 2010 15:33:10 +0900 Subject: Dreaming of new generation IDE In-Reply-To: References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <87k4utn570.fsf@benfinney.id.au> Message-ID: <5b8d13221002032233m7d4cd716te38d8eafdc888002@mail.gmail.com> On Thu, Feb 4, 2010 at 1:13 PM, Vladimir Ignatov wrote: >>> > [?] system "knows" all your identifiers and just regenerates >>> > relevant portions of text from internal database-alike >>> > representation. >> >> You will probably want to learn about ?refactoring? to see if that's >> related to what you mean . > > I mean if system actually "understands" your code (instead of try to > figure it out from existing text files with source code), then much > more complex refactoring is possible. My favorite refactoring is > "Replace Method with Method Object". It is hard to imagine "external" > tool that can provide such refactoring for python code. You may be interested by this project, then: http://sourceforge.net/mailarchive/message.php?msg_name=9c768dc61001121642t5bd1a7ddmd1fe9e088e1d9ab0 at mail.gmail.com It seems limited to Jython implementation unfortunately, cheers, David From no.email at nospam.invalid Thu Feb 4 01:57:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 03 Feb 2010 22:57:40 -0800 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: <7xsk9hxzbv.fsf@ruckus.brouhaha.com> John Nagle writes: > There's enough intercommunication between the threads working on > a single site that it's a pain to do them as subprocesses. And I > definitely don't want to launch subprocesses for each page; the > Python load time would be worse than the actual work. The > subprocess module assumes you're willing to launch a subprocess > for each transaction. Why not just use socketserver and have something like a fastcgi? From hirotaka.niitsuma at gmail.com Thu Feb 4 02:10:02 2010 From: hirotaka.niitsuma at gmail.com (Niitsuma Hirotaka) Date: Thu, 4 Feb 2010 16:10:02 +0900 Subject: python via netcat Message-ID: <6ce56e1a1002032310j7f20c4a6q818ccb61a6ea1502@mail.gmail.com> I write little script run python via netcat http://www2s.biglobe.ne.jp/~niitsuma/jsonrpcdirect.html Usage $ netcat localhost 31415 {"method": "numpy.linalg.norm", "params": [[2,2]], "id": 0} then get response {"result": 2.8284271247461903, "error": null, "id": 0} From stephen.thorne at gmail.com Thu Feb 4 02:15:31 2010 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Wed, 3 Feb 2010 23:15:31 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: On Feb 3, 6:40?am, Xah Lee wrote: > This is a short complaint on adminabuseon #pythonircchannel on > freenode.net. > > Here's a log: > > 2010-02-02 > > (12:11:57 PM) The topic for #pythonis: NO LOL |http://pound-python.org/ > | It's too early to usePython3.x | Pasting > 3 lines? Pastebin:http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ:http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy > | #python.web #wsgi #python-fr #python.de #python-es #python.tw > #python.pl #python-br #python-jp #python-nl #python-ir #python- > offtopic > (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, > actually. > (12:12:01 PM) jarray52: Jarray > (12:12:11 PM) _habnabit: jarray52, yes, you are. > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops > etc) right is quite tricky > (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just > wondering whats up with thepythonverison :D > (12:12:24 PM) mode (+o dash) by ChanServ > (12:12:30 PM) You have been kicked by dash: (No.) G'day, My name is Stephen Thorne, and my nick on #python is Jerub. dash and I are both ops on the #python IRC channel. According to my logs the most recent time I have banned you from #python was the 16th of June, 2006, when I established that you were the same troll that posts to this usenet group. I have no interest in letting you troll #python, and thoroughly approve of dash's responsible behaviour as a joint custodian of the #python irc channel. Maintaining a high signal to noise ratio is difficult, and we appreciate that in this particular case you have acknowledged that you were made unwelcome in our IRC community and will endeavour to avoid it in future. Regards, Stephen Thorne From deets at nospam.web.de Thu Feb 4 03:41:44 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 09:41:44 +0100 Subject: PyChecker under python's virtualenv In-Reply-To: References: <7sub7uFstoU1@mid.uni-berlin.de> Message-ID: <7svfiaFvilU1@mid.uni-berlin.de> Am 04.02.10 01:52, schrieb Steve Holden: > Diez B. Roggisch wrote: >> Am 03.02.10 22:46, schrieb soltys: >>> Hi Everybody, >>> I've been doing some test on pythons' virtualenv and recently I've >>> decided to run PyChecker. But I'm having some difficulties with importing >>> modules available only on virtualenv by pychecker. As if it was >>> trying to use systemwide python. >>> I've googled about it, and found nothing in this area. >>> I installed pychecker using python setup.py install >>> from virtualenv. I looked at pychecker script - it uses correct python. >> >> I doubt that it uses the "correct python", because then you wouldn't >> have the problems you have. >> >> I don't use pychecker, but pylint. And there, the system-wide command >> uses the system's python - which of course doesn't know anything about >> virtualenv. >> >> There are two solutions to this problem: >> >> - install py(lint|checker) into your virtualenv. > > See the OP's original assertion: > >>> I installed pychecker using python setup.py install >>> from virtualenv. I looked at pychecker script - it uses correct python. > > Isn't that "installing into his virtualenv"? You are right, it reads like that. I should have read it better. All I can say is that even a system-wide pylint with my recipe above gives me no troubles. Diez From purui.wang at gmail.com Thu Feb 4 03:52:55 2010 From: purui.wang at gmail.com (purui) Date: Thu, 4 Feb 2010 00:52:55 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <69fb5e89-2ad6-42c0-b4c8-c322bd812e05@m27g2000prl.googlegroups.com> > This is obvious even in the Python documentation itself where one > frequently asks oneself "Uhh... so what is parameter X supposed to be... > a string... a list... ?" > That is partially why I created this search engine for python, to see what parameters other people feed in. http://nullege.com/ From deets at nospam.web.de Thu Feb 4 04:02:06 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 10:02:06 +0100 Subject: Passing parameters in URL In-Reply-To: <7x3a1h7s82.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> Message-ID: <7svgogF768U1@mid.uni-berlin.de> > I'm not sure what you mean by that. Obviously if users want to record > their own conversations, then I can't stop them, but that's much > different than a non-participant in the conversation leaving a recorder > running 24/7. Is that so hard to understand? Is it so hard to understand that this is not about laws and rights, but about technical properties of the HTTP-protocol? Your web-based chat uses HTTP, no P2P-protocol, and thus the service provider *can* log conversations. I don't say he should, I don't say I want that, I don't say there are now laws that prevent them from doing so, all I say is he *can*. > I certainly didn't feel that saving or not saving client conversations > on the server side was up to my discretion. When I found that the > default server configuration caused conversations to be logged then I > was appalled. Then stop logging. Or get a hosting-provider that allows you to configure it to strip QUERY_STRINGS from log-entries. And if they refuse to, maybe using POST solves the issue. But wait, there is http://www.cyberciti.biz/faq/apache-mod_dumpio-log-post-data/ So what if they run that? So, for the umpteenth time: data sent over the wire can be recorded. From the user's POV, your nitpicking of who's the actual culprit - the IT-guys, or the programmers - is fruitless. You have a nice anecdote where switching from GET to POST allowed you to trick whoever wasn't acting to your wishes. Good for you. But John B. and your posts indicate that using POST is inherently more secure. It *isn't*. > Do you think the phone company has the right to record all your phone > calls if they feel like it (absent something like a law enforcement > investigation)? What about coffee shops that you visit with your > friends? It is not up to their discretion. They have a positive > obligation to not do it. If you think they are doing it on purpose > without your authorization, you should notify the FBI or your > equivalent, not just "don't use it". If they find they are doing it > inadvertently, they have to take measures to make it stop. That is the > situation I found myself in, because of the difference in how servers > treat GET vs. POST. If they have a positive obligation not to do it, it doesn't matter if they run their service over GET or POST. Again, this is not about laws and what service providers should or must do. It's about POST vs. GET, and if either of them is more secure or not. It isn't. Diez From deets at nospam.web.de Thu Feb 4 04:07:49 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 10:07:49 +0100 Subject: Passing parameters in URL In-Reply-To: <87iqadde68.fsf@castleamber.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <87iqadde68.fsf@castleamber.com> Message-ID: <7svh39F8vvU1@mid.uni-berlin.de> Am 04.02.10 01:42, schrieb John Bokma: > "Diez B. Roggisch" writes: > >> Am 03.02.10 19:11, schrieb John Bokma: >>> Alan Harris-Reid writes: >>> >>>> I have a web-page where each row in a grid has edit/delete buttons to >>>> enable the user to maintain a selected record on another page. The >>>> buttons are in the form of a link with href='/item_edit?id=123', but >>>> this string appears in the URL and gives clues as to how to bypass the >>>> correct sequence of events, and could be risky if they entered the URL >>>> directly (especially when it comes to deleting records). >>> >>> You should *never* use a GET request to do actions like deleting >>> records. You already are aware of it being risky, so don't do this. You >>> should use GET for getting information, and POST for modifying information. >> >> You should *never* say never, because there might be situations where >> exceptions from rules are valid. This is one such cases. Making this a >> post means that you need to resort to javascript to populate& submit >> a hidden HTML-form. Just for the sake of a POST. > > Make each edit/delete button a submit button and optionally style it. *slap* Yep, you are right, no JS needed. I should have thought about that. > >> Also, your claim of it being more risky is simply nonsense. GET is a >> tiny bit more prone to tinkering by the average user. But calling this >> less risky is promoting security by obscurity, at most. > > Maybe you should think about what happens if someone posts: > to a popular forum... And the difference to posting from urrlib2 import open from urllib import encode open("http://example.com/item_delete", data=encode([("id", "123")])) to that same public "hacker" forum is exactly what? If your webapp happens to allow item_delete to be called without authentication & authorization, then *that's* your problem. Diez From deets at nospam.web.de Thu Feb 4 04:23:40 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 10:23:40 +0100 Subject: Passing parameters in URL In-Reply-To: References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> Message-ID: <7svi0uFecmU1@mid.uni-berlin.de> Am 04.02.10 03:52, schrieb Nobody: > On Wed, 03 Feb 2010 14:09:07 -0800, Paul Rubin wrote: > >>> Also, your claim of it being more risky is simply nonsense. GET is a >>> tiny bit more prone to tinkering by the average user. But calling this >>> less risky is promoting security by obscurity, at most. >> >> GET parameters also tend to get recorded in the http logs of web proxies >> and web servers while POST parameters usually aren't. > > More significantly, they'll appear in the Referer: header for any link the > user follows from the page, so they're visible to anyone who can get a > link to their site onto the page (whether, or > whatever). > > Even if this isn't possible at the moment, will you remember to fix it the > first time you allow an off-site link? > > You should assume that anything which goes into a GET request is visible > to the entire world. Don't put anything even remotely private in there. You mean like http://www.google.de/search?q=dirty+buttsex ? Which is the key example for when to use GET - non-modifying queries. I agree though that you have to be cautious about that, and using POST makes it easier to do so. Diez From kmisoft at gmail.com Thu Feb 4 04:41:03 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 12:41:03 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <69fb5e89-2ad6-42c0-b4c8-c322bd812e05@m27g2000prl.googlegroups.com> References: <69fb5e89-2ad6-42c0-b4c8-c322bd812e05@m27g2000prl.googlegroups.com> Message-ID: > That is partially why I created this search engine for python, to see > what parameters other people feed in. > http://nullege.com/ Thank you for excellent effort! I found it very useful and start using it on almost everyday basis. It's much simple to learn from real live examples. Vladimir Ignatov From no.email at nospam.invalid Thu Feb 4 05:27:49 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 02:27:49 -0800 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> <7svgogF768U1@mid.uni-berlin.de> Message-ID: <7xeil1qore.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > Your web-based chat uses HTTP, no P2P-protocol, and thus the service > provider *can* log conversations. I don't say he should, I don't say I > want that, I don't say there are now laws that prevent them from doing > so, all I say is he *can*. Sure, my complaint is that the default setup caused this to actually happen so lots of people using that software were recording user conversations without realizing it and maybe without caring. This is a bad erosion as I see it. > Then stop logging. Or get a hosting-provider that allows you to > configure it to strip QUERY_STRINGS from log-entries. And if they > refuse to, maybe using POST solves the issue. I did stop logging. There wasn't an issue with the hosting provider since I was running the server myself. But I had to resort to some ugly software kludge to stop logging those particular strings. More frustratingly, I filed a bug report about the issue against the chat software but the conversation was sort of like the one you and I are having now. I just couldn't convince them that there was a problem and that they should change the default. > http://www.cyberciti.biz/faq/apache-mod_dumpio-log-post-data/ > So what if they run that? That sounds like something someone would have to go out of their way to install and use. It's not the default. Of course if someone is malicious they can do all sorts of nasty stuff. A coffeeshop that wanted to mess with me on purpose wouldn't have to do high tech crap like recording my conversations--they could just poison my coffee. I have to trust them to not do this on purpose, but then I see a situation where their coffee sweetener accidentaly has a harmful chemical, so of course I'd ask them to do something about it. > So, for the umpteenth time: data sent over the wire can be recorded. And for the umpteenth time, I'm less concerned about "can be" than "is". POST isn't logged unless you go to some lengths to have it logged. GET is logged unless you go to some lengths to prevent it. It's not enough in a software deployment to only consider what actions are possible. It's important to make sure that the default actions are the right ones. > If they have a positive obligation not to do it, it doesn't matter if > they run their service over GET or POST. GET makes it harder for them to fulfill their obligations. As a security nerd, I saw what was happening and took measures against it, but a more typical operator might never notice or care. There is also the matter of the referer header which an anon mentioned, though it didn't apply to this particular situation because of how the application worked. From no.email at nospam.invalid Thu Feb 4 05:32:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 02:32:01 -0800 Subject: Passing parameters in URL References: <4b6aa21d$0$11075$426a74cc@news.free.fr> Message-ID: <7xaavpqoke.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: >> The buttons are in the form of a link with href='/item_edit?id=123', > ...At least use "POST" requests for anything that Create/Update/Delete > resources. There's also the issue that a user can change "123" to "125" and possibly mess with someone else's resource, unless you use some server side authentication. Or just seeing how often the numbers change could reveal patterns about what other users are doing. I always think it's best to encrypt anything sensitive like that, to avoid leaking any info. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:32:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:32:02 +0100 Subject: Passing parameters in URL In-Reply-To: References: Message-ID: <4b6aa21d$0$11075$426a74cc@news.free.fr> Alan Harris-Reid a ?crit : > I have a web-page where each row in a grid has edit/delete buttons to > enable the user to maintain a selected record on another page. The > buttons are in the form of a link with href='/item_edit?id=123', but > this string appears in the URL and gives clues as to how to bypass the > correct sequence of events, and could be risky if they entered the URL > directly (especially when it comes to deleting records). Basic HTTP stuff - this is definitely not Python-related. Do yourself (and your users / customers / etc) a favor and read the HTTP rfc. "GET" requests should NOT modify the server state. At least use "POST" requests for anything that Create/Update/Delete resources. For the record, someone once had serious problems with GET requests deleting records - turned out to be a very bad idea when a robot started following these links... > Is there another way of passing a record-id to a method href="/item/23/edit" href="/item/edit/23" etc > a) without it appearing in the URL? > b) without the user being able to fathom-out how to attach which id to > which URL? Wrong solution. The correct solution is to 1/ make correct use of the request method (GET and POST at least). 2/ make sure the user performing the action has the permission to do it. 1/ won't protect your data from malicious users, but will at least avoid accidental mistakes. 2/ by checking the user's perms when handling the POST request of course - not by hidding "forbidden" urls. > As each link contains row-id, I guess there is nothing to stop someone > from getting the id from the page source-code. Nor even from trying any other id (brute-force attack). > Is it safe to use the > above href method if I test for authorised credentials (user/password > stored as session variables, perhaps?) before performing the edit/delete > action? cf above. > I am currently using CherryPy 3.2, but I guess the theory could apply to > any HTTP framework or web app.. Indeed. From anand.shashwat at gmail.com Thu Feb 4 05:39:39 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 16:09:39 +0530 Subject: Common area of circles Message-ID: Given 'n' circles and the co-ordinates of their center, and the radius of all being equal i.e. 'one', How can I take out the intersection of their area. hope the picture makes it clear http://imagebin.us/images/p5qeo7hgc3547pnyrb6.gif -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:47:45 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:47:45 +0100 Subject: Passing parameters in URL In-Reply-To: <7sua7fFn74U1@mid.uni-berlin.de> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> Message-ID: <4b6aa5cf$0$30293$426a74cc@news.free.fr> Diez B. Roggisch a ?crit : > Am 03.02.10 19:11, schrieb John Bokma: >> Alan Harris-Reid writes: >> >>> I have a web-page where each row in a grid has edit/delete buttons to >>> enable the user to maintain a selected record on another page. The >>> buttons are in the form of a link with href='/item_edit?id=123', but >>> this string appears in the URL and gives clues as to how to bypass the >>> correct sequence of events, and could be risky if they entered the URL >>> directly (especially when it comes to deleting records). >> >> You should *never* use a GET request to do actions like deleting >> records. You already are aware of it being risky, so don't do this. You >> should use GET for getting information, and POST for modifying >> information. > > You should *never* say never, because there might be situations where > exceptions from rules are valid. This is one such cases. Oh yes ? > Making this a > post means that you need to resort to javascript to populate & submit a > hidden HTML-form. I beg your pardon ???? This is total nonsense. Hopefully you don't need any js to emit a post request from a browser ! The only thing you need to do is to use a form and submit input instead. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:52:12 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:52:12 +0100 Subject: Passing parameters in URL In-Reply-To: <7xaavpqoke.fsf@ruckus.brouhaha.com> References: <4b6aa21d$0$11075$426a74cc@news.free.fr> <7xaavpqoke.fsf@ruckus.brouhaha.com> Message-ID: <4b6aa6d6$0$30293$426a74cc@news.free.fr> Paul Rubin a ?crit : > Bruno Desthuilliers writes: >>> The buttons are in the form of a link with href='/item_edit?id=123', >> ...At least use "POST" requests for anything that Create/Update/Delete >> resources. > > There's also the issue that a user can change "123" to "125" and > possibly mess with someone else's resource, > unless you use some server > side authentication. What I said IIRC. > Or just seeing how often the numbers change could > reveal patterns about what other users are doing. I always think it's > best to encrypt anything sensitive like that, to avoid leaking any info. Depends on how "sensitive" it really is. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 4 05:53:21 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 04 Feb 2010 11:53:21 +0100 Subject: Passing parameters in URL In-Reply-To: <4b6aa5cf$0$30293$426a74cc@news.free.fr> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <4b6aa5cf$0$30293$426a74cc@news.free.fr> Message-ID: <4b6aa71b$0$30293$426a74cc@news.free.fr> Bruno Desthuilliers a ?crit : > Diez B. Roggisch a ?crit : (snip) >> Making this a post means that you need to resort to javascript to >> populate & submit a hidden HTML-form. > > I beg your pardon ???? This is total nonsense. Sorry, posted too fast, John alredy adressed this. From kmisoft at gmail.com Thu Feb 4 05:54:58 2010 From: kmisoft at gmail.com (Vladimir Ignatov) Date: Thu, 4 Feb 2010 13:54:58 +0300 Subject: Dreaming of new generation IDE In-Reply-To: <5b8d13221002032233m7d4cd716te38d8eafdc888002@mail.gmail.com> References: <3dfd60f21002030728p32207e51h958399dcf91af65d@mail.gmail.com> <87k4utn570.fsf@benfinney.id.au> <5b8d13221002032233m7d4cd716te38d8eafdc888002@mail.gmail.com> Message-ID: > http://sourceforge.net/mailarchive/message.php?msg_name=9c768dc61001121642t5bd1a7ddmd1fe9e088e1d9ab0 at mail.gmail.com Thanks a lot! That is a great reference (a must read for everybody interested). Reading just this: "Internally at Google we have a language-neutral representation shared by all our language analyzers," make me jumping ;-) Googlers can't be wrong. Vladimir Ignatov From anh.hai.trinh at gmail.com Thu Feb 4 06:13:58 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Thu, 4 Feb 2010 03:13:58 -0800 (PST) Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6a3f46$0$1597$742ec2ed@news.sonic.net> Message-ID: On Feb 4, 10:46?am, John Nagle wrote: > > ? ? There's enough intercommunication between the threads working on > a single site that it's a pain to do them as subprocesses. And I > definitely don't want to launch subprocesses for each page; the > Python load time would be worse than the actual work. ?The > subprocess module assumes you're willing to launch a subprocess > for each transaction. You could perhaps use a process pool inside each domain worker to work on the pages? There is multiprocessing.Pool and other implementations. For examples, in this library, you can s/ThreadPool/ProcessPool/g and this example would work: . If you want to DIY, with multiprocessing.Lock/Pipe/Queue, I don't understand why it would be more of a pain to write your threads as processes. // aht http://blog.onideas.ws From groups_ads12 at yahoo.com Thu Feb 4 06:16:50 2010 From: groups_ads12 at yahoo.com (groups_ads12) Date: Thu, 04 Feb 2010 11:16:50 -0000 Subject: learn Sql Server 2000 2005 2008 Message-ID: www.sqlserver.learn.net.in sql server sql server 2005 sql server 2008 sql server 2000 microsoft sql server sql server management studio microsoft sql server 2005 ms sql server microsoft sql server 2000 sql server 2005 download sql server hosting microsoft sql server 2008 sql server jobs sql server stored procedure sql server 2005 tutorial sql server query sql server reporting services sql server tutorial ms sql server 2005 download sql server microsoft sql server management studio express sql server 2003 sql server enterprise manager sql server integration services sql server backup sql server data types sql server dba sql server management sql server replication microsoft sql server 2005 express edition ms sql server 2000 mssql server sql server 2005 reporting services sql server client sql server cursor sql server database sql server performance sql server profiler sql server training ms sql server 2008 sql server 2008 developer edition sql server developer sql server manager sql server trigger sql server update sql server2005 microsoft sql server download sql server 7 sql server 7.0 sql server date format sql server datetime sql server identity sql server job sql server tools sql server tutorials sql server 2005 replication sql server 2005 tutorials sql server alter table sql server enterprise sql server insert sql server magazine sql server security sql server software sql server stored procedures sql server xml sql servers asp sql server sql server 2005 backup sql server 2005 training sql server bcp sql server insert into sql server jdbc learn sql server sql server 2005 client sql server administration sql server bulk insert sql server collation sql server consultant sql server error sql server free sql server select sql server standard sql server tool sql server transaction sql server tuning msdn sql server sql server 2005 books sql server 6.5 sql server books sql server consulting sql server data type sql server delete sql server queries sql server services sql server ssis sql server support sql server transaction log sql server 2005 tools sql server backup database sql server exec sql server joins sql server null sql server query analyzer tutorial sql server 2000 rename sql server sql server help sql server indexes sql server scripts sql server service buy sql server sql server 2000 backup sql server 2008 training sql server best practices sql server development sql server script sql server tempdb ms sql server hosting sql server databases sql server host sql server tips performance tuning sql server sql 2000 server download sql server course sql server courses sql server guide sql server maintenance sql server permissions learning sql server 2005 sql server 2005 tuning sql server command sql server data sql server execute sql server table sql server utilities msde sql server sql server db setting up sql server sql server programmer using sql server audit sql server performance tuning sql server 2005 sql server tables copy sql server sql server 2005 recovery syntax sql server sql server exams creating sql server tsql server sqlserver server differences sql server -------------- next part -------------- An HTML attachment was scrubbed... URL: From lallous at lgwm.org Thu Feb 4 06:34:04 2010 From: lallous at lgwm.org (lallous) Date: Thu, 4 Feb 2010 03:34:04 -0800 (PST) Subject: Building a multiline string Message-ID: Hello Maybe that's already documented, but it seems the parser accepts to build a long string w/o really using the first method: # Method1 x = "line1" + \ # cannot use comments! "line2"+ \ "line3" and instead using a list with one element like this: # Method2 x = [ "line1" # can use comments "line2" "line3" ][0] Or: # Method3 x = ( "line1" # can use comments "line2" "line3" ) (Not that I don't want new lines in the strings) Now should I be using method 2 or 3 in production code? -- Elias From clp2 at rebertia.com Thu Feb 4 06:41:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 4 Feb 2010 03:41:18 -0800 Subject: Common area of circles In-Reply-To: References: Message-ID: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand wrote: > Given 'n' circles and the co-ordinates of their center, and the radius of > all being equal i.e. 'one', How can I take out the intersection of their > area. How is this at all specific to Python? This also sounds suspiciously like homework, which you should know this list is unlikely to give direct answers to, though you might be able to get a few pointers or some general suggestions. Cheers, Chris -- Back to toiling away on CSE 105 HW#3 http://blog.rebertia.com From anand.shashwat at gmail.com Thu Feb 4 06:47:43 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 17:17:43 +0530 Subject: Common area of circles In-Reply-To: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> Message-ID: I wanted some general suggestion/tips only On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert wrote: > On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand > wrote: > > Given 'n' circles and the co-ordinates of their center, and the radius of > > all being equal i.e. 'one', How can I take out the intersection of their > > area. > > How is this at all specific to Python? > > This also sounds suspiciously like homework, which you should know > this list is unlikely to give direct answers to, though you might be > able to get a few pointers or some general suggestions. > > Cheers, > Chris > -- > Back to toiling away on CSE 105 HW#3 > http://blog.rebertia.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From contact at xavierho.com Thu Feb 4 06:54:14 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 4 Feb 2010 21:54:14 +1000 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> Message-ID: <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> I'm not sure what you're after. Are you after how to calculate the area? Or are you trying to graph it? Or an analytical solution? What do you mean by "take out the intersection"? -Xav On Thu, Feb 4, 2010 at 9:47 PM, Shashwat Anand wrote: > I wanted some general suggestion/tips only > > > On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert wrote: > >> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand >> wrote: >> > Given 'n' circles and the co-ordinates of their center, and the radius >> of >> > all being equal i.e. 'one', How can I take out the intersection of their >> > area. >> >> How is this at all specific to Python? >> >> This also sounds suspiciously like homework, which you should know >> this list is unlikely to give direct answers to, though you might be >> able to get a few pointers or some general suggestions. >> >> Cheers, >> Chris >> -- >> Back to toiling away on CSE 105 HW#3 >> http://blog.rebertia.com >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Thu Feb 4 07:04:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 07:04:35 -0500 Subject: How to guard against bugs like this one? In-Reply-To: <4B69A575.2020604@timgolden.me.uk> References: <4B69A575.2020604@timgolden.me.uk> Message-ID: Tim Golden wrote: > On 03/02/2010 16:17, kj wrote: >> Boy, that was dumb of me. The above apology was meant for Stephen >> Hansen, not Steve Holden. I guess this is now a meta-apology... >> (Sheesh.) > > You see? That's what I like about the Python community: > people even apologise for apologising :) > QOTW? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From anand.shashwat at gmail.com Thu Feb 4 07:05:46 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 17:35:46 +0530 Subject: Common area of circles In-Reply-To: <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: I want to calculate areas. like for two circles (0, 0) and (0, 1) : the output is '1.228370' similarly my aim is to take 'n' co-ordinates, all of radius '1' and calculate the area common to all. The best I got was monte-carlo methods which is inefficient. Is there any other approach possible. On Thu, Feb 4, 2010 at 5:24 PM, Xavier Ho wrote: > I'm not sure what you're after. Are you after how to calculate the area? Or > are you trying to graph it? Or an analytical solution? > > What do you mean by "take out the intersection"? > > -Xav > > On Thu, Feb 4, 2010 at 9:47 PM, Shashwat Anand wrote: > >> I wanted some general suggestion/tips only >> >> >> On Thu, Feb 4, 2010 at 5:11 PM, Chris Rebert wrote: >> >>> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand >>> wrote: >>> > Given 'n' circles and the co-ordinates of their center, and the radius >>> of >>> > all being equal i.e. 'one', How can I take out the intersection of >>> their >>> > area. >>> >>> How is this at all specific to Python? >>> >>> This also sounds suspiciously like homework, which you should know >>> this list is unlikely to give direct answers to, though you might be >>> able to get a few pointers or some general suggestions. >>> >>> Cheers, >>> Chris >>> -- >>> Back to toiling away on CSE 105 HW#3 >>> http://blog.rebertia.com >>> >> >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eckhardt at satorlaser.com Thu Feb 4 07:09:46 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Thu, 04 Feb 2010 13:09:46 +0100 Subject: Building a multiline string References: Message-ID: Just for the record: Neither of the below methods actually produce a multiline string. They only spread a string containing one line over multiple lines of source code. lallous wrote: > Maybe that's already documented, but it seems the parser accepts to > build a long string w/o really using the first method: > > # Method1 > x = "line1" + \ # cannot use comments! > "line2"+ \ > "line3" Well, obviously you can't use comments like that there. The point of the backslash is that it continues the current logical line over the _immediately_ _following_ newline. If anything follows, that obviously doesn't work. > and instead using a list with one element like this: > > # Method2 > x = [ > "line1" # can use comments > "line2" > "line3" > ][0] This basically makes use of the fact that "this" "is" "one" "string" and not four strings. > # Method3 > x = ( > "line1" # can use comments > "line2" > "line3" > ) This uses the same, only that this time it uses brackets which cause an expression to extend to multiple lines. > (Not that I don't want new lines in the strings) You don't not want or you don't want newlines? Depending on that, you could also do this: # method 4 x = "line1"\ "line2"\ "line3" or maybe # method 5 x = """line1 line2 line3 """ > Now should I be using method 2 or 3 in production code? I'd go for 3 or 4. 2 is basically a hack (you could do the same with a dictionary, or a tuple, not only a list). 1 will actually create strings and then concatenate them (unless Python is smart enough to optimize that), but it allows adding expressions in the middle. Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From steve at holdenweb.com Thu Feb 4 07:14:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 07:14:13 -0500 Subject: Passing parameters in URL In-Reply-To: <7x3a1h7s82.fsf@ruckus.brouhaha.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> Message-ID: <4B6ABA15.7020307@holdenweb.com> Paul Rubin wrote: > "Diez B. Roggisch" writes: >>> But it would be outrageous for the shop owner to record the >>> conversations of patrons. >> Which is the exact thing that happens when you use an email-provider >> with IMAP. Or google wave. Or groups. Or facebook. Or twitter. Which I >> wouldn't call outrageous. > > Those are not comparable. IMAP is a storage service, and groups, > facebook, and twitter are publishing systems (ok, I've never understood > quite what Google Wave is). Yes, by definition, your voice mail > provider (like IMAP) has to save recordings of messages people leave > you, but that's a heck of a lot different than your phone carrier > recording your real-time conversations. Recording live phone > conversations by a third party is called a "wiretap" and doing it > without suitable authorization can get you in a heck of a lot of > trouble. > Unless you happen to be following the illegal instructions of the President of the United States, in which case Congress will retro-actively alter the law to void your offenses and provide you with legal immunity for your wrong-doing. Assuming you are a large telephone company and not a private individual. >> This discussion moves away from the original question: is there >> anything inherently less secure when using GET vs. POST. There isn't. > > Well, the extra logging of GET parameters is not inherent to the > protocol, but it's an accidental side effect that server ops may have to > watch out for. > >> Users can forge both kind of requests easy enough, whoever sits in the >> middle can access both, > > I'm not sure what you mean by that. Obviously if users want to record > their own conversations, then I can't stop them, but that's much > different than a non-participant in the conversation leaving a recorder > running 24/7. Is that so hard to understand? > > Interception from the middle is addressed by SSL, though that relies on > the PKI certificate infrastructure, which while somewhat dubious, is > better than nothing. > >> and it's at the discretion of the service provider to only save what >> it needs to. If you don't trust it, don't use it. > > I certainly didn't feel that saving or not saving client conversations > on the server side was up to my discretion. When I found that the > default server configuration caused conversations to be logged then I > was appalled. > > Do you think the phone company has the right to record all your phone > calls if they feel like it (absent something like a law enforcement > investigation)? What about coffee shops that you visit with your > friends? It is not up to their discretion. They have a positive > obligation to not do it. If you think they are doing it on purpose > without your authorization, you should notify the FBI or your > equivalent, not just "don't use it". If they find they are doing it > inadvertently, they have to take measures to make it stop. That is the > situation I found myself in, because of the difference in how servers > treat GET vs. POST. A lot will depend on the terms of service of the network supply contract. Most vendors take pains to ensure that such "innocent" logging (i.e. the maintenance by their servers of logging information, which may under subpoena or similar legal coercion be given up to law enforcement authorities as "business records") is permitted. If you have signed the contract, then they have the right to log that data. Caveat emptor. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bearophileHUGS at lycos.com Thu Feb 4 07:19:35 2010 From: bearophileHUGS at lycos.com (Bearophile) Date: Thu, 4 Feb 2010 04:19:35 -0800 (PST) Subject: Common area of circles References: Message-ID: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> Shashwat Anand: > > Given 'n' circles and the co-ordinates of their center, and the radius of > > all being equal i.e. 'one', How can I take out the intersection of their > > area. I can see two possible solutions, both approximate. In both solutions you first look if there are a pair of circles that don't intersect, in this case the intersect area is zero. You also remove all circles fully contained in another circle. The first strategy is easy to do, but it probably leads to a lower precision. Then you can sample randomly many times the rectangular area that surely contains all circles. You count how many of those random points are inside all circles. This gives you an approximate area of their intersection. Increasing the points numbers slowly increases the result precision. The second strategy is more complex. You convert your circles into polygons with a fixed number of vertices (like 50 or 100 or 1000 or more. This number is constant even if the circles don't have all the same radius). So you can turn this circle into a simple mesh of triangles (all vertices are on the circumference). Then you "subtract" the second polygonalized circle, this can create a hole and split triangles in pieces, and so on with successive circles. At the end you can compute the total area of the triangles left. This is doable, but you need time to do implement this. The advantage is that the numerical precision of the result is probably higher. If you implement this second solution you can implement the first one too, and use it as a test to avoid bugs. Visualizing the triangles with Pygame or MatPlotLib can be useful to look for bugs. Bye, bearophile From anand.shashwat at gmail.com Thu Feb 4 07:27:14 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 17:57:14 +0530 Subject: Common area of circles In-Reply-To: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> References: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> Message-ID: I needed 6 decimal places of accuracy, so first way of solution will not work for my case. However, your second strategy seems promising. Working on it. Thanks :D ~l0nwlf On Thu, Feb 4, 2010 at 5:49 PM, Bearophile wrote: > Shashwat Anand: > > > Given 'n' circles and the co-ordinates of their center, and the radius > of > > > all being equal i.e. 'one', How can I take out the intersection of > their > > > area. > > I can see two possible solutions, both approximate. In both solutions > you first look if there are a pair of circles that don't intersect, in > this case the intersect area is zero. You also remove all circles > fully contained in another circle. > > The first strategy is easy to do, but it probably leads to a lower > precision. Then you can sample randomly many times the rectangular > area that surely contains all circles. You count how many of those > random points are inside all circles. This gives you an approximate > area of their intersection. Increasing the points numbers slowly > increases the result precision. > > The second strategy is more complex. You convert your circles into > polygons with a fixed number of vertices (like 50 or 100 or 1000 or > more. This number is constant even if the circles don't have all the > same radius). So you can turn this circle into a simple mesh of > triangles (all vertices are on the circumference). Then you "subtract" > the second polygonalized circle, this can create a hole and split > triangles in pieces, and so on with successive circles. At the end you > can compute the total area of the triangles left. This is doable, but > you need time to do implement this. The advantage is that the > numerical precision of the result is probably higher. If you implement > this second solution you can implement the first one too, and use it > as a test to avoid bugs. Visualizing the triangles with Pygame or > MatPlotLib can be useful to look for bugs. > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashokprabhuv at gmail.com Thu Feb 4 07:28:20 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Thu, 4 Feb 2010 04:28:20 -0800 (PST) Subject: read a process output with subprocess.Popen Message-ID: Hi, I m trying a read the output of a process which is running continuously with subprocess.Popen. However the readline() method hangs for the process to finish. Please let me know if the following code can be made to work with subprocess.Popen with threads or queues. I tried a lot of methods but to no avail. It would be great if someone can make it work. import subprocess p1 = subprocess.Popen('tail -f /var/log/ messages',stdout=subprocess.PIPE,shell=True) p2 = subprocess.Popen('grep something',stdin=p1.stdout,stdout=subprocess.PIPE,shell=True) while 1: line = p2.stdout.readline() print line Thanks, ~Ashok. From mgedmin at gmail.com Thu Feb 4 07:28:29 2010 From: mgedmin at gmail.com (Marius Gedminas) Date: Thu, 4 Feb 2010 04:28:29 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87wrytdirw.fsf@castleamber.com> Message-ID: <9e80909d-906c-466b-b9cb-77400a42ee7e@r24g2000yqd.googlegroups.com> On Feb 4, 1:03?am, John Bokma wrote: > Jonathan Gardner writes: > > I can explain all of Python in an hour; > > OK, in that case I would say give it a go. Put it on YouTube, or write a > blog post about it (or post it here). I am sure you will help a lot of > people that way. Someone already did: "Advanced Python or Understanding Python" http://video.google.com/videoplay?docid=7760178035196894549 (76 minutes). Worth watching. Regards, -- Marius Gedminas From steve at holdenweb.com Thu Feb 4 07:31:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 07:31:01 -0500 Subject: Building a multiline string In-Reply-To: References: Message-ID: lallous wrote: > Hello > > Maybe that's already documented, but it seems the parser accepts to > build a long string w/o really using the first method: > > # Method1 > x = "line1" + \ # cannot use comments! > "line2"+ \ > "line3" > > and instead using a list with one element like this: > > # Method2 > x = [ > "line1" # can use comments > "line2" > "line3" > ][0] > > Or: > # Method3 > x = ( > "line1" # can use comments > "line2" > "line3" > ) > > (Not that I don't want new lines in the strings) > > Now should I be using method 2 or 3 in production code? > I should have thought it was pretty obvious that method 2 creates a list and then performs an indexing operation on it. These are completely unnecessary operations, which are avoided in method 3 which is a simple parenthesised expression. So why anyone would want to adopt method 2, which is also mess clear as source code, is beyond me. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Thu Feb 4 07:59:52 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 04 Feb 2010 13:59:52 +0100 Subject: Repeat an exception In-Reply-To: <4B6A3C57.2000606@mrabarnett.plus.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> <4B6A3C57.2000606@mrabarnett.plus.com> Message-ID: <4B6AC4C8.5030902@sequans.com> MRAB wrote: > In other words: > > for attempt in range(2): > try: > spanish_field = translate(english_field, lang_to='es', > lang_from='en') > break > except TranslationError: > pass > else: > # Didn't break out of the loop, therefore not successful. > print "Translation failed" What the hell is this 'for else' loop !! :D First time I see this statement for years. I'd never thought I'd still learn something that basic. My first impression is that the mechansim is not that obvious. MRAB's need for a comment tends to confirm this. I'll try to remember that anyway. Nice addition. JM From marco at sferacarta.com Thu Feb 4 08:23:46 2010 From: marco at sferacarta.com (Marco Mariani) Date: Thu, 04 Feb 2010 14:23:46 +0100 Subject: Building a multiline string In-Reply-To: References: Message-ID: On 02/04/2010 12:34 PM, lallous wrote: > Now should I be using method 2 or 3 in production code? Another way... depending on what you are using the string for, of course. If it's an HTML/XML/SQL/whatever piece of code: >>>> from textwrap import dedent >>>> sql = dedent(""" > ... SELECT * > ... FROM table > ... WHERE foo=bar > ... """) >>>> >>>> print sql > > SELECT * > FROM table > WHERE foo=bar > And if you don't want the starting/ending newlines: >>>> sql = dedent("""\ > ... SELECT * > ... FROM table > ... WHERE foo=bar\ > ... """) >>>> >>>> print sql > SELECT * > FROM table > WHERE foo=bar >>>> I use this sometimes to keep both python and the embedded code readable while preserving indentation. From contact at xavierho.com Thu Feb 4 08:31:17 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 4 Feb 2010 23:31:17 +1000 Subject: Common area of circles In-Reply-To: References: <1c8224ad-58ac-4572-b182-ebfc545d5b8b@p24g2000yqm.googlegroups.com> Message-ID: <2d56febf1002040531g42d0ced3y220b0ff32e56a7f1@mail.gmail.com> It's an interesting problem. Never thought it was this difficult. I can't account for all geometrical enumerations, but assuming all 4 circles intersect, here's the solution for this particular senario. It's probably not going to be useful to you since you're working on geometrical approximations now, but it is precise to the exact value. I don't have it worked out here, but it goes like this. 1. Find the area covered by all 4 circles, unioned. Method here: http://stackoverflow.com/questions/1667310/combined-area-of-overlapping-circles 2: Follow this chart I made up: http://xavierho.com/media/images/Misc/IntersectionOfFourCircles.png And there you go. I'm sure there are way better, faster ways, and covers a lot more senarios, but this is the best I can come up with, without counting the rasterised pixels ratio =P. I like Bearophile's solution. Have fun! Cheers, Xav On Thu, Feb 4, 2010 at 10:27 PM, Shashwat Anand wrote: > I needed 6 decimal places of accuracy, so first way of solution will not > work for my case. However, your second strategy seems promising. Working on > it. Thanks :D > ~l0nwlf > > > On Thu, Feb 4, 2010 at 5:49 PM, Bearophile wrote: > >> Shashwat Anand: >> > > Given 'n' circles and the co-ordinates of their center, and the radius >> of >> > > all being equal i.e. 'one', How can I take out the intersection of >> their >> > > area. >> >> I can see two possible solutions, both approximate. In both solutions >> you first look if there are a pair of circles that don't intersect, in >> this case the intersect area is zero. You also remove all circles >> fully contained in another circle. >> >> The first strategy is easy to do, but it probably leads to a lower >> precision. Then you can sample randomly many times the rectangular >> area that surely contains all circles. You count how many of those >> random points are inside all circles. This gives you an approximate >> area of their intersection. Increasing the points numbers slowly >> increases the result precision. >> >> The second strategy is more complex. You convert your circles into >> polygons with a fixed number of vertices (like 50 or 100 or 1000 or >> more. This number is constant even if the circles don't have all the >> same radius). So you can turn this circle into a simple mesh of >> triangles (all vertices are on the circumference). Then you "subtract" >> the second polygonalized circle, this can create a hole and split >> triangles in pieces, and so on with successive circles. At the end you >> can compute the total area of the triangles left. This is doable, but >> you need time to do implement this. The advantage is that the >> numerical precision of the result is probably higher. If you implement >> this second solution you can implement the first one too, and use it >> as a test to avoid bugs. Visualizing the triangles with Pygame or >> MatPlotLib can be useful to look for bugs. >> >> Bye, >> bearophile >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Feb 4 09:01:01 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 09:01:01 -0500 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: On 2/4/2010 7:05 AM, Shashwat Anand wrote: > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is there > any other approach possible. There is a method for calculating the area of a polygon by traversing its boundary. I forget the formula, but you should be able to find it. So *if* you can find the arcs that bound the area, you can approximate each by a series of short lines and apply the polygon method. Terry Jan Reedy From anand.shashwat at gmail.com Thu Feb 4 09:19:06 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 4 Feb 2010 19:49:06 +0530 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: thanks, all of you On Thu, Feb 4, 2010 at 7:31 PM, Terry Reedy wrote: > On 2/4/2010 7:05 AM, Shashwat Anand wrote: > >> I want to calculate areas. >> like for two circles (0, 0) and (0, 1) : the output is '1.228370' >> >> similarly my aim is to take 'n' co-ordinates, all of radius '1' and >> calculate the area common to all. >> The best I got was monte-carlo methods which is inefficient. Is there >> any other approach possible. >> > > There is a method for calculating the area of a polygon by traversing its > boundary. I forget the formula, but you should be able to find it. So *if* > you can find the arcs that bound the area, you can approximate each by a > series of short lines and apply the polygon method. > > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pecora at anvil.nrl.navy.mil Thu Feb 4 09:57:59 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 04 Feb 2010 09:57:59 -0500 Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> Message-ID: In article <87eil1ddjp.fsf_-_ at castleamber.com>, John Bokma wrote: > Lou Pecora writes: > > > That's a pretty accurate description of how I transitioned to Python > > from C and Fortran. > > Not C, but C++ (but there are also C implementations): YAML, see: > http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument > > I use YAML now and then with Perl for both reading/writing data and for > debugging purposes (YAML is quite human readable, for programmers at least) > > Of course there is also YAML support for Python: > http://pyyaml.org/. Well, that looks a bit more complicated than I would like, but maybe it's doing more stuff than I can grok. Here's what I needed and how I did it in Python: # Make some variables x=1.234e-8 y=2 astr="An output string...whatever" z=4.5+1j*1.3456 # a complex number # Output them to a file already opened as fp outlist=[x, y, astr, z] repvars= repr(outlist)+"\n" fp.write(repvars) # Reading same list in: instr=fp.readline() inlist=eval(instr) x1,y1,astr1,z1= inlist That's what I needed. 3 lines to write or read a inhomogeneous collection of variables. I can add more variables, shuffle the order, whatever without messing with formatting, etc. That's pretty easy for me and it's easy for anyone to see and understand what's being done. Not trying to start an argument, just showing how the former messasge I was replying to made a good point about Python's way of doing things and the effort to shake off old habits from other languages. -- -- Lou Pecora From pecora at anvil.nrl.navy.mil Thu Feb 4 09:59:29 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Thu, 04 Feb 2010 09:59:29 -0500 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <7x8wb9j4r2.fsf@ruckus.brouhaha.com> Message-ID: In article <7x8wb9j4r2.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > Lou Pecora writes: > > after much noodling around and reading it hit me that I could just put > > all that output of different types of variables into a list, hit it > > with a repr() function to get a string version, and write the string > > to a file -- no formatting necessary-- three lines of code. Later > > reading in the string version (no formatting necessary), and hitting > > it with an eval() function returned all the values I originally had in > > those variables. How simple, but beautiful. > > FYI: I do that too sometimes, but in general using repr/eval that way > is poor style and not very reliable. It's better to use the pickle > module, which is intended for that sort of thing, or the json module > if your datatypes are suitable and you want to follow a semi-standard. Yeah, I should look into pickle. Haven't messed with that. Most of what I do is numerical calculations for my consumption/research so quick and easy comes first. Thanks for the hint. -- -- Lou Pecora From hidura at gmail.com Thu Feb 4 10:40:41 2010 From: hidura at gmail.com (Hidura) Date: Thu, 4 Feb 2010 11:40:41 -0400 Subject: Problem with __init__.py in Python3.1 In-Reply-To: References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> Message-ID: <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> Thanks, I read it and try to put my code in the correct form, but now give me another error, inside the Writer Package says: "ValueError: Attempted relative import in non-package", if somebody knows a clue of how fix it i will glad to read opinions. [?] On Thu, Feb 4, 2010 at 2:11 AM, Gabriel Genellina wrote: > En Thu, 04 Feb 2010 01:00:56 -0300, Hidura escribi?: > > > Good evening list, I have a really big trouble with the imports in the 3.1 >> version(Notes: In the older 2.64 theres no problems), I have two packages, >> the first package Utilities who contains Writer the second package, >> Writers >> contain the module tagmanip(What is imported in the best way inside the >> __init__.py of the Writer), when i make the import inside the writer >> everything is ok, but from the Utilities package the errors says: >> "ImportError: No module named tagsmanip". >> I don't understand why this is happening, if somebody could help me i will >> glad to hear any suggestion. >> > > In Python 3.x, "absolute" import is enabled by default (2.6 uses a mix of > relative and absolute imports). > To import sibling modules in a package, or modules in a subpackage, you > have to use relative imports: > > from . import tagmanip > from .Writers import tagmanip > > See PEP328 http://www.python.org/dev/peps/pep-0328/ > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 330.png Type: image/png Size: 611 bytes Desc: not available URL: From grflanagan at gmail.com Thu Feb 4 11:29:25 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 04 Feb 2010 16:29:25 +0000 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: > On 2/4/2010 7:05 AM, Shashwat Anand wrote: > > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is > there > any other approach possible. > > A brute force approach - create a grid of small squares and calculate which squares are in all circles. I don't know whether it is any better than monte-carlo: for two circles, delta=0.001 takes about a minute and delta=0.0001 is still running after 30 minutes :-) 1.22 1.2281 1.22834799999 ------------------------------------------------------------------ import math class Circle: def __init__(self, x, y, r=1): self.x = float(x) self.y = float(y) self.r = float(r) def contains(self, a, b): return math.sqrt((self.x-a)**2 + (self.y-b)**2) <= self.r class Grid: def __init__(self, circles): self.X1 = min(c.x-c.r for c in circles) self.Y1 = max(c.y+c.r for c in circles) self.X2 = max(c.x+c.r for c in circles) self.Y2 = min(c.y-c.r for c in circles) self.circles = circles def iter_boxes(self, delta): X2 = self.X2 Y2 = self.Y2 a = self.X1 while a < X2: a += delta b = self.Y1 while b > Y2: b -= delta #print a, b yield a, b def intersection(self, delta=0.1): S = 0 s = delta**2 #box area circles = self.circles for a, b in self.iter_boxes(delta): if all(c.contains(a, b) for c in circles): S += s return S c = Circle(0, 1) assert c.contains(0, 1) assert c.contains(0, 1.5) assert c.contains(math.sqrt(2)/2, math.sqrt(2)/2) assert c.contains(0, 2) assert not c.contains(0, 2.01) assert not c.contains(0, 2.1) assert not c.contains(0, 3) circles = [ Circle(0, 0), Circle(0, 1), ] g = Grid(circles) print '-'*30 print g.intersection() print g.intersection(0.01) print g.intersection(0.001) print g.intersection(0.0001) ------------------------------------------------------------------ From python at mrabarnett.plus.com Thu Feb 4 11:36:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 04 Feb 2010 16:36:09 +0000 Subject: Repeat an exception In-Reply-To: <4B6AC4C8.5030902@sequans.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> <4B6A3C57.2000606@mrabarnett.plus.com> <4B6AC4C8.5030902@sequans.com> Message-ID: <4B6AF779.8010609@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > MRAB wrote: >> In other words: >> >> for attempt in range(2): >> try: >> spanish_field = translate(english_field, lang_to='es', >> lang_from='en') >> break >> except TranslationError: >> pass >> else: >> # Didn't break out of the loop, therefore not successful. >> print "Translation failed" > > What the hell is this 'for else' loop !! :D First time I see this > statement for years. > I'd never thought I'd still learn something that basic. > > My first impression is that the mechansim is not that obvious. MRAB's > need for a comment tends to confirm this. > I'll try to remember that anyway. Nice addition. > The comment is there for the OP. _I_ don't need it! :-) From apt.shansen at gmail.com Thu Feb 4 11:38:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 4 Feb 2010 08:38:37 -0800 Subject: Repeat an exception In-Reply-To: <4B6AC4C8.5030902@sequans.com> References: <278d6194-96c9-4557-b1fd-25345d7cc8a1@s12g2000yqj.googlegroups.com> <4B6A3C57.2000606@mrabarnett.plus.com> <4B6AC4C8.5030902@sequans.com> Message-ID: <7a9c25c21002040838g5fed0fb1leffbe227c42119b8@mail.gmail.com> On Thu, Feb 4, 2010 at 4:59 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > What the hell is this 'for else' loop !! :D First time I see this statement > for years. > I'd never thought I'd still learn something that basic. > Its one of the least used constructs in Python, I think, and leads to periodic statements like this on the list where people who think they know all about Python suddenly see it and go WTF :) But in Python, all loops have an "else" clause that is fired when the loop terminates-- but *only* if it terminates normally, where 'normally' is basically, 'if you don't use break to exit the loop prematurely'. It allows you to do certain things in a way which is (arguably, and I so don't want to start an argument about this) a bit cleaner, where the normal method would require a flag or some such. For example, if you need want to loop over a sequence to test to see if they all match some criteria, you can use a for..else, or some flag variable. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Thu Feb 4 11:46:27 2010 From: gherron at islandtraining.com (Gary Herron) Date: Thu, 04 Feb 2010 08:46:27 -0800 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: <4B6AF9E3.6020403@islandtraining.com> Gerard Flanagan wrote: > >> On 2/4/2010 7:05 AM, Shashwat Anand wrote: >> >> I want to calculate areas. >> like for two circles (0, 0) and (0, 1) : the output is >> '1.228370' >> >> similarly my aim is to take 'n' co-ordinates, all of radius >> '1' and >> calculate the area common to all. >> The best I got was monte-carlo methods which is inefficient. Is >> there >> any other approach possible. >> >> > > A brute force approach - create a grid of small squares and calculate > which squares are in all circles. I don't know whether it is any > better than monte-carlo: That's just what the monte-carlo method is -- except the full family of monte-carlo methods can be quite sophisticated, including being more general (pseudo or quasi random points instead of a regular grid) and can provide a theoretical basis for calculating the rate of convergence, and so on. Gary Herron > for two circles, delta=0.001 takes about a minute and delta=0.0001 is > still running after 30 minutes :-) > > 1.22 > 1.2281 > 1.22834799999 > > > ------------------------------------------------------------------ > import math > > class Circle: > > def __init__(self, x, y, r=1): > self.x = float(x) > self.y = float(y) > self.r = float(r) > > def contains(self, a, b): > return math.sqrt((self.x-a)**2 + (self.y-b)**2) <= self.r > > class Grid: > > def __init__(self, circles): > self.X1 = min(c.x-c.r for c in circles) > self.Y1 = max(c.y+c.r for c in circles) > self.X2 = max(c.x+c.r for c in circles) > self.Y2 = min(c.y-c.r for c in circles) > self.circles = circles > > def iter_boxes(self, delta): > X2 = self.X2 > Y2 = self.Y2 > a = self.X1 > while a < X2: > a += delta > b = self.Y1 > while b > Y2: > b -= delta > #print a, b > yield a, b > > def intersection(self, delta=0.1): > S = 0 > s = delta**2 #box area > circles = self.circles > for a, b in self.iter_boxes(delta): > if all(c.contains(a, b) for c in circles): > S += s > return S > > > c = Circle(0, 1) > > assert c.contains(0, 1) > assert c.contains(0, 1.5) > assert c.contains(math.sqrt(2)/2, math.sqrt(2)/2) > assert c.contains(0, 2) > assert not c.contains(0, 2.01) > assert not c.contains(0, 2.1) > assert not c.contains(0, 3) > > circles = [ > Circle(0, 0), > Circle(0, 1), > ] > > g = Grid(circles) > > print '-'*30 > print g.intersection() > print g.intersection(0.01) > print g.intersection(0.001) > print g.intersection(0.0001) > > ------------------------------------------------------------------ > From nobody at nowhere.com Thu Feb 4 11:46:47 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Feb 2010 16:46:47 +0000 Subject: Refreshing of urllib.urlopen() References: Message-ID: On Wed, 03 Feb 2010 21:33:08 -0600, Michael Gruenstaeudl wrote: > I am fairly new to Python and need advice on the urllib.urlopen() > function. The website I am trying to open automatically refreshes > after 5 seconds and remains stable thereafter. With > urllib.urlopen().read() I can only read the initial but not the > refreshed page. How can I access the refreshed page via > urlopen().read()? I have already tried to intermediate with > time.sleep() before invoking .read() (see below), but this does not > work. In all probability, the server is instructing the browser to load a different URL via either a Refresh: header or a tag in the page. You will have to retrieve that information then issue a request for the new URL. It might even be redirecting via JavaScript, in which case, you lose (it's possible to handle this case, but it's difficult). From nobody at nowhere.com Thu Feb 4 12:02:23 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 04 Feb 2010 17:02:23 +0000 Subject: read a process output with subprocess.Popen References: Message-ID: On Thu, 04 Feb 2010 04:28:20 -0800, Ashok Prabhu wrote: > I m trying a read the output of a process which is running > continuously with subprocess.Popen. However the readline() method > hangs for the process to finish. Please let me know if the following > code can be made to work with subprocess.Popen with threads or queues. > I tried a lot of methods but to no avail. It would be great if someone > can make it work. This is an issue with grep, not Python per se. By default, stdout (in the C library) is line-buffered if it refers to a TTY, and block-buffered otherwise (e.g. if it refers to a pipe). grep doesn't change the default buffering, so when it's stdout is a pipe, its output is written in 4K blocks. If you only need this to work with GNU grep, you can use the --line-buffered switch to force stdout to be flushed after each line. If it needs to be portable, you can implement the grep part in Python (i.e. read p1.stdout and ignore any lines which don't contain a given string or which don't match a given regex). From john at castleamber.com Thu Feb 4 12:22:27 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 11:22:27 -0600 Subject: Passing parameters in URL References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <87iqadde68.fsf@castleamber.com> <7svh39F8vvU1@mid.uni-berlin.de> Message-ID: <87636c531o.fsf@castleamber.com> "Diez B. Roggisch" writes: > Am 04.02.10 01:42, schrieb John Bokma: [..] >> Maybe you should think about what happens if someone posts: >> to a popular forum... > > And the difference to posting > > from urrlib2 import open > from urllib import encode > > open("http://example.com/item_delete", data=encode([("id", "123")])) > > to that same public "hacker" forum is exactly what? Imagine that a user of example.com, logged in at example.com (i.e. with a valid session ID in a cookie), visits the aforementioned (by me) forum, and that he has an item 123. It will be deleted. > If your webapp happens to allow item_delete to be called without > authentication & authorization, then *that's* your problem. You now understand that *with* a & a a GET request can be *still* harmful? -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From grflanagan at gmail.com Thu Feb 4 12:24:37 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Thu, 04 Feb 2010 17:24:37 +0000 Subject: Common area of circles In-Reply-To: <4B6AF9E3.6020403@islandtraining.com> References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> <4B6AF9E3.6020403@islandtraining.com> Message-ID: Gary Herron wrote: > Gerard Flanagan wrote: >> >> A brute force approach - create a grid of small squares and calculate >> which squares are in all circles. I don't know whether it is any >> better than monte-carlo: > > That's just what the monte-carlo method is -- except the full family of > monte-carlo methods can be quite sophisticated, including being more > general (pseudo or quasi random points instead of a regular grid) and > can provide a theoretical basis for calculating the rate of convergence, > and so on. > I would have said a Monte Carlo method necessarily involves random sampling in some shape or form, no? (Casinos, Chance etc..) And as I've previously understood Monte Carlo Integration, the technique involves rather the ratio "hits/total sample" rather than the sum of small areas. That's how I remember it, at least - it's been a while though. Regards G.F From john at castleamber.com Thu Feb 4 12:26:26 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 11:26:26 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87wrytdirw.fsf@castleamber.com> <9e80909d-906c-466b-b9cb-77400a42ee7e@r24g2000yqd.googlegroups.com> Message-ID: <87y6j83oal.fsf@castleamber.com> Marius Gedminas writes: > On Feb 4, 1:03?am, John Bokma wrote: >> Jonathan Gardner writes: >> > I can explain all of Python in an hour; >> >> OK, in that case I would say give it a go. Put it on YouTube, or write a >> blog post about it (or post it here). I am sure you will help a lot of >> people that way. > > Someone already did: "Advanced Python or Understanding Python" > http://video.google.com/videoplay?docid=7760178035196894549 > (76 minutes). > > Worth watching. Thanks, I will. And let you know if it succeeds at "explain all of Python in 76 minutes". It's not a fair test, since I am not new to Python, but let me see first ;-) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From davea at ieee.org Thu Feb 4 12:27:16 2010 From: davea at ieee.org (Dave Angel) Date: Thu, 04 Feb 2010 12:27:16 -0500 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: <4B6B0374.8060400@ieee.org> Shashwat Anand wrote: > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is there any > other approach possible. > > > You start with a list of circles, each having center (a,b), and radius (r). As you stated the problem, r is always 1, but I'll keep the algorithm general. This is untested, and probably contains typos, at least. I would do it with successively smaller squares. A square can be described using center coordinates (x,y) , and length (s) of a side. Each square can have three states: not included, partially included, and fully included. You build a list of squares, starting with one, the bounding square for the first circle. For each square in the list, you go through all the circles (each with center a,b, and radius r), and for each circle decide if the square is entirely within the circle, or partially. If it's fully included in all of them, you add its area to the the accumulator, and drop it from your list. if it's not included at all in one of them, you just drop it from the list. (Note, be careful about modifying a list you're iterating through -- make a copy) After a pass through the list, the accumulator is a lower-bound for the area, and the accumulator plus the areas of all the squares is an upper bound. If these are close enough together, you terminate. Otherwise you take the remaining squares in the list, split each into four pieces, and end up with a list 4 times as long. And repeat the loop, checking each square against each circle. The only remaining question is how you decide for a given circle and a given square which of the three states it's in. And it turns out you can be pretty approximate in this, and it'll still converge. So you can take a distance between (a,b) and (x,y), and compare it to r-s/2 and to r+(s*0.707106781187). If it's greater than r+s*0.707106781187, no intersection. If it's less than r-s/2, then the square's entirely inside. Note that I used 0.707106781187 above, but you'd actually use sqr(0.5) to whatever precision you needed. And if it's convenient to round it, round it upwards; again it won't affect the result. I doubt if it would matter in Python code, but you could even do the whole thing in integers (avoiding the sqrt for distance calc), if you were careful about the bounding formulas. That's premature optimization, however. HTH, DaveA From john at castleamber.com Thu Feb 4 12:49:21 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 11:49:21 -0600 Subject: YAML References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> Message-ID: <87tytw3n8e.fsf@castleamber.com> Lou Pecora writes: > In article <87eil1ddjp.fsf_-_ at castleamber.com>, > John Bokma wrote: > >> Lou Pecora writes: >> >> > That's a pretty accurate description of how I transitioned to Python >> > from C and Fortran. >> >> Not C, but C++ (but there are also C implementations): YAML, see: >> http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument >> >> I use YAML now and then with Perl for both reading/writing data and for >> debugging purposes (YAML is quite human readable, for programmers at least) >> >> Of course there is also YAML support for Python: >> http://pyyaml.org/. > > Well, that looks a bit more complicated than I would like, but maybe > it's doing more stuff than I can grok. Here's what I needed and how I > did it in Python: > > # Make some variables > x=1.234e-8 > y=2 > astr="An output string...whatever" > z=4.5+1j*1.3456 # a complex number > > # Output them to a file already opened as fp > outlist=[x, y, astr, z] > repvars= repr(outlist)+"\n" > fp.write(repvars) > > # Reading same list in: > instr=fp.readline() > inlist=eval(instr) > x1,y1,astr1,z1= inlist > > > That's what I needed. 3 lines to write or read a inhomogeneous > collection of variables. I can add more variables, shuffle the order, > whatever without messing with formatting, etc. That's pretty easy for me > and it's easy for anyone to see and understand what's being done. Not > trying to start an argument, just showing how the former messasge I was > replying to made a good point about Python's way of doing things and the > effort to shake off old habits from other languages. My C++ is rusty to say the least, so I can't give you an example in C++, and the C++ version will be longer than the Python version for sure. I use YAML, YAML::Syck to be precise, now and then in Perl. In Perl, if $data is a reference to an arbitrary (complex) datastructure: DumpFile( 'filename', $data ); writes it out and $data = LoadFile( 'filename' ); reads it back in. Since YAML is to some extent human readable, I now and then use it for debugging purposes over Data::Dumper, also because the output is more compact, e.g. die Dump $data; Personally I think it's good to be aware of YAML, since it's supported by several languages and it should in general be possible to exchange the generated YAML between them. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From deets at nospam.web.de Thu Feb 4 13:07:39 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 04 Feb 2010 19:07:39 +0100 Subject: Passing parameters in URL In-Reply-To: <87636c531o.fsf@castleamber.com> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <87iqadde68.fsf@castleamber.com> <7svh39F8vvU1@mid.uni-berlin.de> <87636c531o.fsf@castleamber.com> Message-ID: <7t0gndFu21U1@mid.uni-berlin.de> Am 04.02.10 18:22, schrieb John Bokma: > "Diez B. Roggisch" writes: > >> Am 04.02.10 01:42, schrieb John Bokma: > > [..] > >>> Maybe you should think about what happens if someone posts: >>> to a popular forum... >> >> And the difference to posting >> >> from urrlib2 import open >> from urllib import encode >> >> open("http://example.com/item_delete", data=encode([("id", "123")])) >> >> to that same public "hacker" forum is exactly what? > > Imagine that a user of example.com, logged in at example.com (i.e. with > a valid session ID in a cookie), visits the aforementioned (by me) > forum, and that he has an item 123. It will be deleted. The webapp must be actually preventing the processing of GET-requests for the aciton in question. This isn't the case by default for many of them, in fact at least e.g. TurboGears, as well as PHP offer you ways to treat GET and POSTvars the exact same way. So unless the programmer is aware of this potential problem, it won't help. And in the same way one can embed a form with a post-action that leads to the full http://example.com-url into an external page. So it is equally as dangerous. Yes, links are easier, no doubt about that. But POST doesn't magically make you safe from those kinds of attacks. The only way to prevent this are short-lived sessions, or action-tokens of some kind, as Paul mentioned before. Diez From python at rcn.com Thu Feb 4 13:18:23 2010 From: python at rcn.com (Raymond Hettinger) Date: Thu, 4 Feb 2010 10:18:23 -0800 (PST) Subject: Selenium/SauceLabs OpenSpace at Pycon References: Message-ID: <63678d2b-2571-42fb-aa9b-90737cea561e@w27g2000pre.googlegroups.com> > >For those who are interested, the Sauce Labs team, > >http://saucelabs.com/about/team, is hosting two free tutorial open > >space sessions at Pycon in Atlanta. [Aahz] > Congrats on the new job! Thanks. I'm really enjoying working with Jim Baker and Frank Wierzbicki. Raymond From duncan.booth at invalid.invalid Thu Feb 4 13:23:35 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Feb 2010 18:23:35 GMT Subject: Building a multiline string References: Message-ID: lallous wrote: > Now should I be using method 2 or 3 in production code? Also Method1a: # Method1a x = ("line1" + # can use comments! "line2"+ "line3") Use Method1a or Method3 as you prefer: either of these generates a single string constant. Method2 is dumb. From dickinsm at gmail.com Thu Feb 4 13:55:14 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 4 Feb 2010 10:55:14 -0800 (PST) Subject: Common area of circles References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: On 2/4/2010 7:05 AM, Shashwat Anand wrote: > I want to calculate areas. > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > calculate the area common to all. > The best I got was monte-carlo methods which is inefficient. Is there > any other approach possible. How much accuracy do you need? How fast does the algorithm need to be? How many circles are typically involved? Is the intersection necessarily non-empty for the configurations of circles that you use? How much code are you prepared to write? How much mathematics do you want to use? Besides the Monte-Carlo and grid-based approaches already mentioned, I see a couple of other possibilities: (1) It should be entirely possible to do this analytically. The hard part would be identifying the intersection points that form the vertices of the intersection (and especially, doing this robustly in the face of numerical errors and triple intersections or near-triple intersections). Once you've got the vertices, it should be straightforward to compute the area: compute the area of the polygon given by the convex hull of the vertices, then add on the extra areas for the segments bounded by the (straight) sides of the polygon and the corresponding outer arcs. (2) For a numerical approach that might be slightly better than the 2d brute-force approaches described by others: make use of the fact that the intersection is convex. Pick a point P in the intersection (if it exists: finding such a point is an issue in itself). For each angle t, 0 <= t <= 2*pi, define f(t) to be the distance from P to the boundary of the region, in the direction of the angle t. We always have 0 <= f(t) <= 1, so f(t) can be quickly and accurately computed with a bisection search. Now find the definite integral of 0.5 * (f(t))**2, as t goes from 0 to 2*pi, using your favourite quadrature method (but avoid methods that would be very sensitive to continuity of derivatives: f(t) will be continuous, but f'(t) will not). Simpson's rule is probably good enough. Good luck! -- Mark From tompelka at gmail.com Thu Feb 4 14:05:51 2010 From: tompelka at gmail.com (Tomas Pelka) Date: Thu, 04 Feb 2010 20:05:51 +0100 Subject: how to run part of my python code as root Message-ID: <4B6B1A8F.1000504@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey, is there possibility how to run part of my code (function for example) as superuser. Or only way how to do this is create a wrapper and run is with Popen through sudo (but I have to configure sudo to run "whole" python as root). Thanks for advice. - -- Tom Key fingerprint = 06C0 23C6 9EB7 0761 9807 65F4 7F6F 7EAB 496B 28AA -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAktrGoYACgkQf29+q0lrKKqaNACdEvfg+g0n3DzFr/7R33y2Nesy hK8An3ZlpUEEibf0Q1wVET/KpXnsv/PO =JKro -----END PGP SIGNATURE----- From anand.shashwat at gmail.com Thu Feb 4 14:19:59 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Feb 2010 00:49:59 +0530 Subject: Common area of circles In-Reply-To: References: <50697b2c1002040341u3dd8d970ib314bff88e33b75c@mail.gmail.com> <2d56febf1002040354n5aad8951p939b572533e5c211@mail.gmail.com> Message-ID: maximum number of circles = 10**6 runtime <= 5 sec center of circles , -1000<=xi,yi<=1000 (float) [for int it was easier] intersection is there and the area will be non-zero (it can always be checked if intersection is taking place and if no, then area = 0.000000) This was a programming contest problem, so code will be short Maths, I'm eager to use. I attempted this problem because I saw scope of maths in it. (I learnt python while doing ProjectEuler because C/C++ was cumbersome for PE IMHO). I tried monte-carlo, but the time-limit exceeds if i go for required accuracy. The same happens with grid approach. On Fri, Feb 5, 2010 at 12:25 AM, Mark Dickinson wrote: > On 2/4/2010 7:05 AM, Shashwat Anand wrote: > > I want to calculate areas. > > like for two circles (0, 0) and (0, 1) : the output is '1.228370' > > > > similarly my aim is to take 'n' co-ordinates, all of radius '1' and > > calculate the area common to all. > > The best I got was monte-carlo methods which is inefficient. Is there > > any other approach possible. > > How much accuracy do you need? How fast does the algorithm need to > be? How many circles are typically involved? Is the intersection > necessarily non-empty for the configurations of circles that you use? > How much code are you prepared to write? How much mathematics do you > want to use? > > Besides the Monte-Carlo and grid-based approaches already mentioned, I > see a couple of other possibilities: > > (1) It should be entirely possible to do this analytically. The hard > part would be identifying the intersection points that form the > vertices of the intersection (and especially, doing this robustly in > the face of numerical errors and triple intersections or near-triple > intersections). Once you've got the vertices, it should be > straightforward to compute the area: compute the area of the polygon > given by the convex hull of the vertices, then add on the extra areas > for the segments bounded by the (straight) sides of the polygon and > the corresponding outer arcs. > > (2) For a numerical approach that might be slightly better than the 2d > brute-force approaches described by others: make use of the fact that > the intersection is convex. Pick a point P in the intersection (if it > exists: finding such a point is an issue in itself). For each angle > t, 0 <= t <= 2*pi, define f(t) to be the distance from P to the > boundary of the region, in the direction of the angle t. We always > have 0 <= f(t) <= 1, so f(t) can be quickly and accurately computed > with a bisection search. Now find the definite integral of 0.5 * > (f(t))**2, as t goes from 0 to 2*pi, using your favourite quadrature > method (but avoid methods that would be very sensitive to continuity > of derivatives: f(t) will be continuous, but f'(t) will not). > Simpson's rule is probably good enough. > > Good luck! > > -- > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Thu Feb 4 14:21:30 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 16:21:30 -0300 Subject: Problem with __init__.py in Python3.1 References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> Message-ID: En Thu, 04 Feb 2010 12:40:41 -0300, Hidura escribi?: > Thanks, I read it and try to put my code in the correct form, but now > give > me another error, inside the Writer Package says: > "ValueError: Attempted relative import in non-package", if somebody > knows a > clue of how fix it i will glad to read opinions. [?] You say that Writer is a package, but apparently Python disagrees. A package is not just "a directory containing an __init__.py file", this is half the truth. Python must be *aware* of such file, and this happens when you import the package. If you directly run a script from inside a package, Python does not know that it belongs to a package, and treats it as a simple, lonely script. In that case, relative imports won't work. Put the "main" script (the one that you directly execute) outside the package. It can be as small as this, if you want: from some.package import main main() -- Gabriel Genellina From no.email at nospam.invalid Thu Feb 4 14:48:35 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 11:48:35 -0800 Subject: Selenium/SauceLabs OpenSpace at Pycon References: Message-ID: <7xwryssrxo.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > Raymond Hettinger wrote: >>For those who are interested, the Sauce Labs team, >>http://saucelabs.com/about/team, is hosting two free tutorial open >>space sessions at Pycon in Atlanta. > > Congrats on the new job! Yes, cool! I don't recognize several of these logos, but maybe Sauce can help: http://aasi.ebm.fi/5742/browsers.jpg ;-) From sjdevnull at yahoo.com Thu Feb 4 14:56:57 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 4 Feb 2010 11:56:57 -0800 (PST) Subject: how to run part of my python code as root References: Message-ID: On Feb 4, 2:05?pm, Tomas Pelka wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hey, > > is there possibility how to run part of my code (function for example) > as superuser. > > Or only way how to do this is create a wrapper and run is with Popen > through sudo (but I have to configure sudo to run "whole" python as root). In decreasing order of desirability: 1. Find a way to not need root access (e.g. grant another user or group access to whatever resource you're trying to access). 2. Isolate the stuff that needs root access into a small helper program that does strict validation of all input (including arguments, environment, etc); when needed, run that process under sudo or similar. 2a. Have some sort of well-verified helper daemon that has access to the resource you need and mediates use of that resource. 3. Run the process as root, using seteuid() to switch between user and root privs. The entire program must be heavily verified and do strict validation of all inputs. Any attacker who gets control over the process can easily switch to root privs and do damage. This is generally a bad idea. From john at castleamber.com Thu Feb 4 15:15:05 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 14:15:05 -0600 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87wrytdirw.fsf@castleamber.com> <9e80909d-906c-466b-b9cb-77400a42ee7e@r24g2000yqd.googlegroups.com> Message-ID: <87bpg4ahbq.fsf@castleamber.com> Marius Gedminas writes: > On Feb 4, 1:03?am, John Bokma wrote: >> Jonathan Gardner writes: >> > I can explain all of Python in an hour; >> >> OK, in that case I would say give it a go. Put it on YouTube, or write a >> blog post about it (or post it here). I am sure you will help a lot of >> people that way. > > Someone already did: "Advanced Python or Understanding Python" > http://video.google.com/videoplay?docid=7760178035196894549 > (76 minutes). > > Worth watching. Certainly worth watching (I learned some stuff), but in my opinion you /need to have some Python experience/ to be able to follow so no (IMO), someone didn't do it already. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From g.bogle at auckland.no.spam.ac.nz Thu Feb 4 15:50:29 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Fri, 05 Feb 2010 09:50:29 +1300 Subject: Python 3 minor irritation References: Message-ID: Gabriel Genellina wrote: > But the associated program might change the current directory - that's > not the case with the default associations created by the Python > installer, but one should verify this. > To the OP: please create this small test script > > import os > print("curdir=", os.getcwd()) > print("__file__=", __file__) > input() > > and post what you get when you double-click on it. > > Also, from the command line, execute: > > D:\temp>reg query HKCR\.py > > ! REG.EXE VERSION 3.0 > > HKEY_CLASSES_ROOT\.py > REG_SZ Python.File > Content Type REG_SZ text/plain > > HKEY_CLASSES_ROOT\.py\PersistentHandler I'm interested in this, because I'm using Windows XP, and when I execute this command I see the first part but not the second (with PersistentHandler). Is this related to the fact that when I double-click on a .py file the command window disappears after the execution is completed? From ALANBIDDLE70 at YAHOO.COM Thu Feb 4 15:55:21 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Thu, 04 Feb 2010 14:55:21 -0600 Subject: Passing command line argument to program from within IDLE? Message-ID: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Just finishing my first Python (2.6 on Win XP) program, which is working fine. My "Duh?" question is about how to run it from within IDLE and pass it command line arguments. No problem using sys.argv from a Windows command line, but I have missed how you can do that from within IDLE, which complicates development and debugging. -- Alan From jgardner at jonathangardner.net Thu Feb 4 15:55:44 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 4 Feb 2010 12:55:44 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: On Feb 3, 3:39?pm, Steve Holden wrote: > Robert Kern wrote: > > On 2010-02-03 15:32 PM, Jonathan Gardner wrote: > > >> I can explain all of Python in an hour; I doubt anyone will understand > >> all of Python in an hour. > > > With all respect, talking about a subject without a reasonable chance of > > your audience understanding the subject afterwards is not explaining. > > It's just exposition. > > I agree. If the audience doesn't understand then you haven't explained it. > On the contrary, that explanation would have everything you need. It would take an hour to read or listen to the explanation, but much more than that time to truly understand everything that was said. From steve at REMOVE-THIS-cybersource.com.au Thu Feb 4 16:03:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2010 21:03:06 GMT Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> Message-ID: <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 09:57:59 -0500, Lou Pecora wrote: > Well, that looks a bit more complicated than I would like, but maybe > it's doing more stuff than I can grok. Here's what I needed and how I > did it in Python: [...] > # Reading same list in: > instr=fp.readline() > inlist=eval(instr) > x1,y1,astr1,z1= inlist > > > That's what I needed. 3 lines to write or read a inhomogeneous > collection of variables. Easy, but also quick and dirty -- good enough for small scripts, but not really good enough for production applications. > I can add more variables, shuffle the order, > whatever without messing with formatting, etc. This is nice and easy. But there are at least four catches: * you can't safely treat the data file as human-editable (although a sufficiently careful and Python-aware user could edit it) * you can't use any data that isn't a built-in, or that contains something that is not a built-in * there may be reliability issues with floats - you're at the mercy of changes to the underlying repr of float objects, and it almost certainly will blow up in your face if you get an inf or nan (at least prior to Python 2.6) * you're using eval, which is a security risk if you can't trust the source of the data file. However, be aware that neither marshal nor pickle guarantees to be safe against malicious data either. The docs for both warn against using them on untrusted data. YAML or JSON *might* be safer, I haven't looked. > That's pretty easy for me > and it's easy for anyone to see and understand what's being done. Not > trying to start an argument, just showing how the former messasge I was > replying to made a good point about Python's way of doing things and the > effort to shake off old habits from other languages. These are all good points. -- Steven From tjreedy at udel.edu Thu Feb 4 16:14:33 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 16:14:33 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: On 2/4/2010 3:55 PM, Alan Biddle wrote: > Just finishing my first Python (2.6 on Win XP) program, which is > working fine. My "Duh?" question is about how to run it from within > IDLE and pass it command line arguments. No problem using sys.argv > from a Windows command line, but I have missed how you can do that > from within IDLE, which complicates development and debugging. I presume you mean edit, F5-run, see result in shell window. Set sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>> import sys >>> sys.argv [''] >>> sys.argv = ['abc','dev'] >>> sys.argv ['abc', 'dev'] I did not know it was writable, either, until I tried it. Terry Jan Reedy From john at castleamber.com Thu Feb 4 16:18:53 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 15:18:53 -0600 Subject: YAML References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> Message-ID: <877hqsaede.fsf@castleamber.com> Steven D'Aprano writes: > However, be aware that neither marshal nor pickle guarantees to be safe > against malicious data either. The docs for both warn against using them > on untrusted data. YAML or JSON *might* be safer, I haven't looked. Regarding malicious data, from the Loading YAML section of PyYAML: Warning: It is not safe to call yaml.load with any data received from an untrusted source! yaml.load is as powerful as pickle.load and so may call any Python function. Check the yaml.safe_load function though. http://pyyaml.org/wiki/PyYAMLDocumentation#LoadingYAML yaml.safe_load however, limits to simple Python objects and Python objects you mark as safe. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From steve at holdenweb.com Thu Feb 4 16:28:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 16:28:17 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: Terry Reedy wrote: > On 2/4/2010 3:55 PM, Alan Biddle wrote: >> Just finishing my first Python (2.6 on Win XP) program, which is >> working fine. My "Duh?" question is about how to run it from within >> IDLE and pass it command line arguments. No problem using sys.argv >> from a Windows command line, but I have missed how you can do that >> from within IDLE, which complicates development and debugging. > > I presume you mean edit, F5-run, see result in shell window. > Set sys.argv in test function or __name__=='__main__' > In 3.1 idle shell: > >>>> import sys >>>> sys.argv > [''] >>>> sys.argv = ['abc','dev'] >>>> sys.argv > ['abc', 'dev'] > > I did not know it was writable, either, until I tried it. > As a solution, however, that sucks, wouldn't you agree? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ALANBIDDLE70 at YAHOO.COM Thu Feb 4 16:37:10 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Thu, 04 Feb 2010 15:37:10 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: Yes, that is what I was trying to do. I need to puzzle a bit on the solution, being a newbie. Thanks! -- Alan From ALANBIDDLE70 at YAHOO.COM Thu Feb 4 16:47:09 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Thu, 04 Feb 2010 15:47:09 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: <7rfmm5h99dsfico46fnbrkjbouujli49a7@4ax.com> Terry, CLICK, the light just came on. Knowing that it is writable, I can look at the length to determine whether there are any arguments. If not, I can switch to interactive input within the program, and input the values that way. A few easy extra lines. Whatever works. Thanks!! -- Alan From xahlee at gmail.com Thu Feb 4 17:26:02 2010 From: xahlee at gmail.com (Xah Lee) Date: Thu, 4 Feb 2010 14:26:02 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: 2010-02-04 Hi Steve, thank you for the reply. I appreciate that you taking this more seriously than normal newsgroups postings. In fact, for this complaint, the response you made is all i asked for. I have a lot things to say about the various political struggle that one sees everyday in just about every communication channels that are predominantly young male groups, of relatively few people, in online posting forums, ircs, online massive multiplayer games... as you may know, the quarrels, accusations, bans, happen every hour. But to be concrete and constructive, i would suggest that in freenode's python irc channel: ? when a admin bans someone, the admin needs to tell the person the reason, and not in some rude way. (a single sentence will do.) ? The list of ban'd person's names, the reason for banning, and the name of admin who ban'd them, should be public. (irc already provides means for this that allows admins to annotate in the ban list.) In particular, if you are going to ban someone by ip address, make sure the person's handle (or preferably real life name), be listed together with it. (again, this needs not elaborate. A single sentence will do, e.g. ?repeatedly asking same question?, ?continously raising controversial issues?, ?refused to use paste bin when requested? will do. Again, be as precise in description as possible. For example, ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) ? additionally, i would suggest that bans be temporary. The following period seems a good start: 5 min ban, 1 hour ban, 1 day ban, 1 week ban, 1 month ban. Each can be executed according to severity per the admin's judgement. There should be no permanent ban, unless it's machine generated commercial spam. Thank you. For anyone reading this thread and interested in my opinions, i have written many essays related to this and netiquette. Many of which detail other similar incidences that i personally experienced, such as freenode's irc ban in #emacs channel. If you are interested, they can be found on my website, search for ?ban xah lee?. Xah ? http://xahlee.org/ ? On Feb 2, 2:23?pm, "Steve Holden, Chairman, PSF" wrote: > Xah Lee wrote: > > This is a short complaint on admin abuse on #python irc channel on > > freenode.net. > > > Here's a log: > > > 2010-02-02 > > > (12:11:57 PM) The topic for #python is: NO LOL |http://pound-python.org/ > > | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: > >http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ: > >http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy > > | #python.web #wsgi #python-fr #python.de #python-es #python.tw > > #python.pl #python-br #python-jp #python-nl #python-ir #python- > > offtopic > > (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, > > actually. > > (12:12:01 PM) jarray52: Jarray > > (12:12:11 PM) _habnabit: jarray52, yes, you are. > > (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? > > (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops > > etc) right is quite tricky > > (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just > > wondering whats up with the python verison :D > > (12:12:24 PM) mode (+o dash) by ChanServ > > (12:12:30 PM) You have been kicked by dash: (No.) > > > --------------- > > > I have not been using irc for the past about 2 year. (possibly perhaps > > 2 times in i think #web channel) In particular, i have not been in in > > freenode.net's #python channel. I don't know who is dash. > > > ? Xah > > ?http://xahlee.org/ > > > ? > > Frankly, Xah Lee, I find it ironic that you see fit to complain about > abuse of the IRC channel when you have apparently felt free to ignore > the many complaints about your behavior on this and other newsgroups > over many years. > > "As ye sew, so shall ye reap". I imagine that your reputation has > preceded you, and that dash (whom I *do* know) is simply looking to keep > a well-known nuisance from bothering the rest of the users on the channel. > > For the present my sympathies are all with him. The PSF will, however, > investigate this issue and I will report back to you off-list in due course. > > regards > ?Steve > -- > Steve Holden ? ? ? ?Chairman, Python Software Foundation > The Python Community Conference ?http://python.org/psf/ > PyCon 2010 Atlanta Feb 19-21 ? ? ? ?http://us.pycon.org/ > Watch PyCon on video now! ? ? ? ? ?http://pycon.blip.tv/ From news123 at free.fr Thu Feb 4 17:34:20 2010 From: news123 at free.fr (News123) Date: Thu, 04 Feb 2010 23:34:20 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used Message-ID: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Hi, I wrote a small xmlrpc client on Windows 7 with python 2.6 srv = xmlrpclib.Server('http://localhost:80') I was able to perform about 1 rpc call per second After changing to srv = xmlrpclib.Server('http://127.0.0.1:80') I was able to perform about 10 to 16 rpc calls per second. So it seems, that under windows 7 the host name lookup occurs for every RPC call (which is of course necessary for long running processes, as the target host might change it's ip during the scripts execution) For my use cases however I could live with one IP-address lookup at the beginning of the script. I wonder now about how I could deal with virtual web servers. ( a web server running with one ip-adress and one port, which behaves differntly depending on the host name of the url request) I'm just curious, as currently I don't have to access virtual servers via xmlrpc, Is there any way to 'pre-lookup the IP address', and to keep the host name in the http POST request? thanks for any ideas N From ben+python at benfinney.id.au Thu Feb 4 17:47:21 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 05 Feb 2010 09:47:21 +1100 Subject: Problem with __init__.py in Python3.1 References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> Message-ID: <871vh0mxdy.fsf@benfinney.id.au> "Gabriel Genellina" writes: > If you directly run a script from inside a package, Python does not > know that it belongs to a package, and treats it as a simple, lonely > script. In that case, relative imports won't work. Which I consider to be a bug. Fortunately, it's already addressed in PEP 366 . Unfortunately, it involves more hackish boilerplate at the top of the program, and is only available in Python 2.6+. -- \ ?Ignorance more frequently begets confidence than does | `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | _o__) | Ben Finney From wanderer at dialup4less.com Thu Feb 4 17:52:03 2010 From: wanderer at dialup4less.com (Wanderer) Date: Thu, 4 Feb 2010 14:52:03 -0800 (PST) Subject: Background Zones in Pylab Plot References: <1eaf6046-db41-44b5-8c9e-b7a15e4cf078@30g2000vbj.googlegroups.com> <5a9e5eaf-2006-4dfe-8498-a544c09a8584@r6g2000yqn.googlegroups.com> Message-ID: On Feb 3, 10:50?pm, CM wrote: > On Feb 3, 10:49?am, Wanderer wrote: > > > I would like to add background zones in pylab plots. Colored sections > > of the background that the curves pass through. Is this possible? My > > google searches don't turn up anything but maybe my search terms > > aren't the right ones. > > > Thanks > > If you look at the matplotlib gallery, I think there may be some > images > that show something like what you want, and then you can look at the > code. ?It's here: > > http://matplotlib.sourceforge.net/gallery.html > > HTH, > Che That helped. There should be something in there I can use. Thank you From robert.kern at gmail.com Thu Feb 4 17:56:44 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 04 Feb 2010 16:56:44 -0600 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: On 2010-02-04 14:55 PM, Jonathan Gardner wrote: > On Feb 3, 3:39 pm, Steve Holden wrote: >> Robert Kern wrote: >>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >> >>>> I can explain all of Python in an hour; I doubt anyone will understand >>>> all of Python in an hour. >> >>> With all respect, talking about a subject without a reasonable chance of >>> your audience understanding the subject afterwards is not explaining. >>> It's just exposition. >> >> I agree. If the audience doesn't understand then you haven't explained it. > > On the contrary, that explanation would have everything you need. It > would take an hour to read or listen to the explanation, but much more > than that time to truly understand everything that was said. Like I said, that's exposition, not explanation. There is an important distinction between the two words. Simply providing information is not explanation. If it takes four hours for your audience to understand it, then you explained it in four hours no matter when you stopped talking. -- 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 senhor.abrantes at gmail.com Thu Feb 4 17:57:53 2010 From: senhor.abrantes at gmail.com (joao abrantes) Date: Thu, 4 Feb 2010 22:57:53 +0000 Subject: Pixel control Message-ID: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> Hello everyone. For example i am using a screen resolution of 800x600 is it possible to make python control the color of the pixels? For example paint the pixel (100,200) in red! And it would stay red when i am seeing a webpage, a movie, playing a game... etc.. Regards, Jo?o Abrantes. -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at boddie.org.uk Thu Feb 4 17:59:44 2010 From: david at boddie.org.uk (David Boddie) Date: Thu, 04 Feb 2010 23:59:44 +0100 Subject: PyQt4 designer custom properties - combo box style References: Message-ID: On Tuesday 02 February 2010 22:25, Andrew wrote: > I am creating custom widgets for the PyQt4 Designer. I can create > custom properties, but I'm looking for how to create a custom property > that has a combo box drop down. I've seen them in the example widgets > and tried following them, but they are using pre-defined items to > populate their property, so it's not a very clear example of how to > get the combo box property to work. Can you explain a bit more about what you have seen and what you are trying to do. Are you trying to create a property that is treated specially by Designer or do you want to get the data for the combo box from somewhere else? > Is there any other examples or help for this kind of setup? Have you seen this article? http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html David From steve at REMOVE-THIS-cybersource.com.au Thu Feb 4 18:01:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 04 Feb 2010 23:01:02 GMT Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> Message-ID: <00f4d6df$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: > Terry Reedy wrote: >> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>> Just finishing my first Python (2.6 on Win XP) program, which is >>> working fine. My "Duh?" question is about how to run it from within >>> IDLE and pass it command line arguments. No problem using sys.argv >>> from a Windows command line, but I have missed how you can do that >>> from within IDLE, which complicates development and debugging. >> >> I presume you mean edit, F5-run, see result in shell window. Set >> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >> >>>>> import sys >>>>> sys.argv >> [''] >>>>> sys.argv = ['abc','dev'] >>>>> sys.argv >> ['abc', 'dev'] >> >> I did not know it was writable, either, until I tried it. >> > As a solution, however, that sucks, wouldn't you agree? [scratches head] Do you mean setting sys.argv as a solution sucks? No, I don't, I think it is grand. If sys.argv was unmodifiable, *that* would suck. Or do you mean that trying it as a solution to the problem of answering the OP's question sucks? Well, no, experimentation is good for answering these sorts of questions, and I can't assume that the documentation will cover every imaginable use-case, or that users will find it. In the absence of any documentation stating otherwise, I would have assumed that sys.argv was an ordinary list which you can modify at will, but having been caught out on faulty assumptions before, I would try it and see before commenting publicly. -- Steven From steve at holdenweb.com Thu Feb 4 18:02:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 18:02:53 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B6B521D.6050408@holdenweb.com> Xah Lee wrote: > 2010-02-04 > > Hi Steve, > > thank you for the reply. > > I appreciate that you taking this more seriously than normal > newsgroups postings. In fact, for this complaint, the response you > made is all i asked for. > OK, in that case I won't trouble anyone else about it. > I have a lot things to say about the various political struggle that > one sees everyday in just about every communication channels that are > predominantly young male groups, of relatively few people, in online > posting forums, ircs, online massive multiplayer games... as you may > know, the quarrels, accusations, bans, happen every hour. > I understand that the diversity of the various channels available to Python users (and indeed of the Python community overall) is not as high as it could be. This does from time to time lead to inappropriate behaviors. I suspect dash kicked you off #python simply because of the reputation you have established on comp.lang.python, but of course I cannot speak for him. > But to be concrete and constructive, i would suggest that in > freenode's python irc channel: > > ? when a admin bans someone, the admin needs to tell the person the > reason, and not in some rude way. (a single sentence will do.) > That would, I agree, be appropriate. > ? The list of ban'd person's names, the reason for banning, and the > name of admin who ban'd them, should be public. (irc already provides > means for this that allows admins to annotate in the ban list.) In > particular, if you are going to ban someone by ip address, make sure > the person's handle (or preferably real life name), be listed together > with it. (again, this needs not elaborate. A single sentence will do, > e.g. ?repeatedly asking same question?, ?continously raising > controversial issues?, ?refused to use paste bin when requested? will > do. Again, be as precise in description as possible. For example, > ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) > This is perhaps a little formal for something that (as far as I know) happens less than once a month. I am reluctant to start up any kind of bureaucracy around bannings unless they become too frequent (in which case your suggestions above seem reasonable). > ? additionally, i would suggest that bans be temporary. The following > period seems a good start: 5 min ban, 1 hour ban, 1 day ban, 1 week > ban, 1 month ban. Each can be executed according to severity per the > admin's judgement. There should be no permanent ban, unless it's > machine generated commercial spam. > Again, this is probably over-formal for the current levels of banning, but a reasonable idea in principle. > Thank you. > > For anyone reading this thread and interested in my opinions, i have > written many essays related to this and netiquette. Many of which > detail other similar incidences that i personally experienced, such as > freenode's irc ban in #emacs channel. If you are interested, they can > be found on my website, search for ?ban xah lee?. > Xah, your opinions are I think pretty well-known around here. I understand that you consider yourself an authority on netiquette, but as I mentioned in my last response I have personally observed you on many occasions indulging in inappropriate behavior such as cross-posting irrelevant material to many newsgroups at the same time. It is actions like that, combined with your use of intemperate and abusive language, that caused you to get banned before you had chance to say much. It's a bit like the boy who cried 'wolf'. People see you doing these things, and so when you appear on an IRC channel where this is known about you get banned as a pre-emptive measure. I have discussed this matter with dash, and he has agreed not to kick you off without reason the next time you join #python. This will only last as long as your behavior remains acceptable, so please don't abuse the privilege I have won back for you. If you do, that will make me feel (and look) like a real dick, and get you banned again straight away. regards Steve > Xah > ? http://xahlee.org/ > > ? > > > On Feb 2, 2:23 pm, "Steve Holden, Chairman, PSF" > wrote: >> Xah Lee wrote: >>> This is a short complaint on admin abuse on #python irc channel on >>> freenode.net. >>> Here's a log: >>> 2010-02-02 >>> (12:11:57 PM) The topic for #python is: NO LOL |http://pound-python.org/ >>> | It's too early to use Python 3.x | Pasting > 3 lines? Pastebin: >>> http://paste.pocoo.org/| Tutorial:http://docs.python.org/tut/| FAQ: >>> http://effbot.org/pyfaq/| New Programmer? Readhttp://tinyurl.com/thinkcspy >>> | #python.web #wsgi #python-fr #python.de #python-es #python.tw >>> #python.pl #python-br #python-jp #python-nl #python-ir #python- >>> offtopic >>> (12:12:00 PM) _habnabit: pr100, I replaced it with str.startswith, >>> actually. >>> (12:12:01 PM) jarray52: Jarray >>> (12:12:11 PM) _habnabit: jarray52, yes, you are. >>> (12:12:16 PM) xahlee: is hash={} and hash.clean() identical? >>> (12:12:18 PM) eggy_: OhnoesRaptor: getting sockets (and event loops >>> etc) right is quite tricky >>> (12:12:21 PM) OhnoesRaptor: I know how to do sockets right eggy, just >>> wondering whats up with the python verison :D >>> (12:12:24 PM) mode (+o dash) by ChanServ >>> (12:12:30 PM) You have been kicked by dash: (No.) >>> --------------- >>> I have not been using irc for the past about 2 year. (possibly perhaps >>> 2 times in i think #web channel) In particular, i have not been in in >>> freenode.net's #python channel. I don't know who is dash. >>> Xah >>> ?http://xahlee.org/ >>> ? >> Frankly, Xah Lee, I find it ironic that you see fit to complain about >> abuse of the IRC channel when you have apparently felt free to ignore >> the many complaints about your behavior on this and other newsgroups >> over many years. >> >> "As ye sew, so shall ye reap". I imagine that your reputation has >> preceded you, and that dash (whom I *do* know) is simply looking to keep >> a well-known nuisance from bothering the rest of the users on the channel. >> >> For the present my sympathies are all with him. The PSF will, however, >> investigate this issue and I will report back to you off-list in due course. >> >> regards >> Steve >> -- >> Steve Holden Chairman, Python Software Foundation >> The Python Community Conference http://python.org/psf/ >> PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/ >> Watch PyCon on video now! http://pycon.blip.tv/ -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mailings at julianmoritz.de Thu Feb 4 18:03:08 2010 From: mailings at julianmoritz.de (Julian) Date: Thu, 4 Feb 2010 15:03:08 -0800 (PST) Subject: Your beloved python features Message-ID: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Hello, I've asked this question at stackoverflow a few weeks ago, and to make it clear: this should NOT be a copy of the stackoverflow-thread "hidden features of Python". I want to design a poster for an open source conference, the local usergroup will have a table there, and in the past years there were some people that came to the python-table just to ask "why should I use python?". For those guys would be a poster quite cool which describes the most popular and beloved python features. So, may you help me please? If there's a similar thread/blogpost/ whatever, please give it to me, google couldn't. Regards Julian From rfritz333 at gmail.com Thu Feb 4 18:10:55 2010 From: rfritz333 at gmail.com (R Fritz) Date: Thu, 4 Feb 2010 15:10:55 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: My favorite feature is its readability. It's as near to pseudo-code as any language we have, and that's valuable in open source projects or when I return to code to modify it. From alfps at start.no Thu Feb 4 18:13:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Feb 2010 00:13:50 +0100 Subject: Stephen -- Bruce? Message-ID: What's this about all the Stephen'ses here? Shouldn't it be Bruce? - Alf (wondering) From no.email at nospam.invalid Thu Feb 4 18:20:01 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 15:20:01 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <7xk4usa8ri.fsf@ruckus.brouhaha.com> Julian writes: > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". It's terrible, but all the alternatives are even worse. ;-) From steve at holdenweb.com Thu Feb 4 18:29:14 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 18:29:14 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: <00f4d6df$0$15566$c3e8da3@news.astraweb.com> References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: > >> Terry Reedy wrote: >>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>> working fine. My "Duh?" question is about how to run it from within >>>> IDLE and pass it command line arguments. No problem using sys.argv >>>> from a Windows command line, but I have missed how you can do that >>>> from within IDLE, which complicates development and debugging. >>> I presume you mean edit, F5-run, see result in shell window. Set >>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>> >>>>>> import sys >>>>>> sys.argv >>> [''] >>>>>> sys.argv = ['abc','dev'] >>>>>> sys.argv >>> ['abc', 'dev'] >>> >>> I did not know it was writable, either, until I tried it. >>> >> As a solution, however, that sucks, wouldn't you agree? > > [scratches head] > > Do you mean setting sys.argv as a solution sucks? No, I don't, I think it > is grand. If sys.argv was unmodifiable, *that* would suck. > > Or do you mean that trying it as a solution to the problem of answering > the OP's question sucks? Well, no, experimentation is good for answering > these sorts of questions, and I can't assume that the documentation will > cover every imaginable use-case, or that users will find it. In the > absence of any documentation stating otherwise, I would have assumed that > sys.argv was an ordinary list which you can modify at will, but having > been caught out on faulty assumptions before, I would try it and see > before commenting publicly. > > What I meant was it sucks that IDLE has no way to fill in sys.argv as a part of its "Run Module" functionality - something that is present in both PythonWin and Wing IDE, for example. But then I have come to the conclusion that IDLE doesn't fit my brain, or my brain doesn't fit it. That sys.argv is mutable simply reflects the fact that it's a list. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mensanator at aol.com Thu Feb 4 18:36:04 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 4 Feb 2010 15:36:04 -0800 (PST) Subject: Stephen -- Bruce? References: Message-ID: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> On Feb 4, 5:13?pm, "Alf P. Steinbach" wrote: > What's this about all the Stephen'ses here? > > Shouldn't it be Bruce? Of course. We just call everyone Stephen to avoid confusion. > > - Alf (wondering) From john at castleamber.com Thu Feb 4 18:40:41 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 17:40:41 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> Message-ID: <87r5p07eo6.fsf@castleamber.com> Steven D'Aprano writes: > On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: > >> Terry Reedy wrote: >>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>> working fine. My "Duh?" question is about how to run it from within >>>> IDLE and pass it command line arguments. No problem using sys.argv >>>> from a Windows command line, but I have missed how you can do that >>>> from within IDLE, which complicates development and debugging. >>> >>> I presume you mean edit, F5-run, see result in shell window. Set >>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>> >>>>>> import sys >>>>>> sys.argv >>> [''] >>>>>> sys.argv = ['abc','dev'] >>>>>> sys.argv >>> ['abc', 'dev'] >>> >>> I did not know it was writable, either, until I tried it. >>> >> As a solution, however, that sucks, wouldn't you agree? > > [scratches head] > > Do you mean setting sys.argv as a solution sucks? No, I don't, I think it > is grand. If sys.argv was unmodifiable, *that* would suck. > > Or do you mean that trying it as a solution to the problem of answering > the OP's question sucks? Well, no, experimentation is good for answering > these sorts of questions, and I can't assume that the documentation will > cover every imaginable use-case, or that users will find it. In the > absence of any documentation stating otherwise, I would have assumed that > sys.argv was an ordinary list which you can modify at will, but having > been caught out on faulty assumptions before, I would try it and see > before commenting publicly. I guess that Terry means that a solution that makes it possible to specify in IDLE *outside* of the Python code the arguments would be better. Hardcoding the command line arguments isn't something I would do for testing. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Thu Feb 4 18:46:52 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 17:46:52 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> Message-ID: <87mxzo7edv.fsf@castleamber.com> John Bokma writes: > Steven D'Aprano writes: > >> On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: >> >>> Terry Reedy wrote: >>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>> working fine. My "Duh?" question is about how to run it from within >>>>> IDLE and pass it command line arguments. No problem using sys.argv >>>>> from a Windows command line, but I have missed how you can do that >>>>> from within IDLE, which complicates development and debugging. >>>> >>>> I presume you mean edit, F5-run, see result in shell window. Set >>>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>>> >>>>>>> import sys >>>>>>> sys.argv >>>> [''] >>>>>>> sys.argv = ['abc','dev'] >>>>>>> sys.argv >>>> ['abc', 'dev'] >>>> >>>> I did not know it was writable, either, until I tried it. >>>> >>> As a solution, however, that sucks, wouldn't you agree? >> >> [scratches head] >> >> Do you mean setting sys.argv as a solution sucks? No, I don't, I think it >> is grand. If sys.argv was unmodifiable, *that* would suck. >> >> Or do you mean that trying it as a solution to the problem of answering >> the OP's question sucks? Well, no, experimentation is good for answering >> these sorts of questions, and I can't assume that the documentation will >> cover every imaginable use-case, or that users will find it. In the >> absence of any documentation stating otherwise, I would have assumed that >> sys.argv was an ordinary list which you can modify at will, but having >> been caught out on faulty assumptions before, I would try it and see >> before commenting publicly. > > I guess that Terry means that a solution that makes it possible to > specify in IDLE *outside* of the Python code the arguments would be > better. Hardcoding the command line arguments isn't something I would do > for testing. Oops, that should've been Steve, my apologies. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From ethan at stoneleaf.us Thu Feb 4 18:46:58 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Feb 2010 15:46:58 -0800 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> Message-ID: <4B6B5C72.8080100@stoneleaf.us> Robert Kern wrote: > On 2010-02-04 14:55 PM, Jonathan Gardner wrote: >> On Feb 3, 3:39 pm, Steve Holden wrote: >>> Robert Kern wrote: >>>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >>> >>>>> I can explain all of Python in an hour; I doubt anyone will understand >>>>> all of Python in an hour. >>> >>>> With all respect, talking about a subject without a reasonable >>>> chance of >>>> your audience understanding the subject afterwards is not explaining. >>>> It's just exposition. >>> >>> I agree. If the audience doesn't understand then you haven't >>> explained it. >> >> On the contrary, that explanation would have everything you need. It >> would take an hour to read or listen to the explanation, but much more >> than that time to truly understand everything that was said. > > Like I said, that's exposition, not explanation. There is an important > distinction between the two words. Simply providing information is not > explanation. If it takes four hours for your audience to understand it, > then you explained it in four hours no matter when you stopped talking. > And if it takes six months? Would you seriously say it took you six months to explain something because it took that long for your audience to understand it? At some point you have to make the transition from person A explaining and person(s) B understanding -- they don't necessarily happen synchronously. As a real-life example, I've read several Python books, tutorials, and this list for quite some time, some of which has very good explanatory material, and yet some of the points I didn't fully comprehend until much, much later. Every time, though, it's still the same reaction: I *love* Python! :D ~Ethan~ From ethan at stoneleaf.us Thu Feb 4 18:55:30 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 04 Feb 2010 15:55:30 -0800 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4B6B5E72.20702@stoneleaf.us> Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. > > Regards > Julian http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf From gagsl-py2 at yahoo.com.ar Thu Feb 4 19:03:20 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 21:03:20 -0300 Subject: Python 3 minor irritation References: Message-ID: En Thu, 04 Feb 2010 17:50:29 -0300, Gib Bogle escribi?: > Gabriel Genellina wrote: >> Also, from the command line, execute: >> D:\temp>reg query HKCR\.py >> ! REG.EXE VERSION 3.0 >> HKEY_CLASSES_ROOT\.py >> REG_SZ Python.File >> Content Type REG_SZ text/plain >> HKEY_CLASSES_ROOT\.py\PersistentHandler > > I'm interested in this, because I'm using Windows XP, and when I execute > this command I see the first part but not the second (with > PersistentHandler). Sorry, I should have removed that line. This is just my setup; a normal Python install doesn't create that registry entry. It allows Desktop Search (or Windows Search, or whatever it is called nowadays; the F3 key) to search inside .py files (default behavior is to just ignore their contents). See http://support.microsoft.com/kb/309173 > Is this related to the fact that when I double-click on a .py file the > command window disappears after the execution is completed? (I bet the "Persistent" word confused you.) No, as you can see, it's completely unrelated. AFAIK, there is no way (on XP and later at least) to keep a console window open after the program exited. Three choices: - Open a cmd window and execute the script there. You may drag&drop the file over the window to avoid typing the full path (I think this last part does not work on Vista nor Win7) - Add a raw_input() [2.x] or input() [3.x] line at the end of the script - Rename it with a '.cmd' extension and add this line at the very top: @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF (see this post by Duncan Booth last month: http://comments.gmane.org/gmane.comp.python.general/650913 ) -- Gabriel Genellina From steve at REMOVE-THIS-cybersource.com.au Thu Feb 4 19:09:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 00:09:24 GMT Subject: Code snippet: dualmethod descriptor References: <0373b8b9$0$1309$c3e8da3@news.astraweb.com> Message-ID: <00f4e6e5$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 00:09:02 -0300, Gabriel Genellina wrote: > En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano > escribi?: > >> class dualmethod(object): [...] > Seems useful! > Perhaps a better place to post it would be > , at least it's > easier to search. Thank you for the encouragement. The recipe is now posted: http://code.activestate.com/recipes/577030/ -- Steven From gagsl-py2 at yahoo.com.ar Thu Feb 4 19:09:28 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 21:09:28 -0300 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma escribi?: > John Bokma writes: >>>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>>> working fine. My "Duh?" question is about how to run it from within >>>>>> IDLE and pass it command line arguments. >> I guess that Terry means that a solution that makes it possible to >> specify in IDLE *outside* of the Python code the arguments would be >> better. Hardcoding the command line arguments isn't something I would do >> for testing. > > Oops, that should've been Steve, my apologies. See http://bugs.python.org/issue5680 -- Gabriel Genellina From tjreedy at udel.edu Thu Feb 4 19:10:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 19:10:52 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> Message-ID: On 2/4/2010 6:29 PM, Steve Holden wrote: > Steven D'Aprano wrote: >> On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote: >> >>> Terry Reedy wrote: >>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>> working fine. My "Duh?" question is about how to run it from within >>>>> IDLE and pass it command line arguments. No problem using sys.argv >>>>> from a Windows command line, but I have missed how you can do that >>>>> from within IDLE, which complicates development and debugging. >>>> I presume you mean edit, F5-run, see result in shell window. Set >>>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell: >>>> >>>>>>> import sys >>>>>>> sys.argv >>>> [''] >>>>>>> sys.argv = ['abc','dev'] >>>>>>> sys.argv >>>> ['abc', 'dev'] >>>> >>>> I did not know it was writable, either, until I tried it. >>>> >>> As a solution, however, that sucks, wouldn't you agree? No, see below. >> [scratches head] >> >> Do you mean setting sys.argv as a solution sucks? No, I don't, I think it >> is grand. If sys.argv was unmodifiable, *that* would suck. >> >> Or do you mean that trying it as a solution to the problem of answering >> the OP's question sucks? Well, no, experimentation is good for answering >> these sorts of questions, and I can't assume that the documentation will >> cover every imaginable use-case, or that users will find it. In the >> absence of any documentation stating otherwise, I would have assumed that >> sys.argv was an ordinary list which you can modify at will, but having >> been caught out on faulty assumptions before, I would try it and see >> before commenting publicly. >> >> > What I meant was it sucks that IDLE has no way to fill in sys.argv as a > part of its "Run Module" functionality - something that is present in > both PythonWin and Wing IDE, for example. The first thing I did was to check for such an option on the run tab. The second thing I thought of was to suggest to OP that he file a feature request (which would likely take years, if ever). But then the test line would not be fetched from the file (unless some ##cmdline convention were invented), but would have to be hand-entered each time the editor were run. Also, a given run of a program can have only one command line, and changing the run line for each test case would suck. Then I tried sys.argv. Why that does not suck: A Python program, as far as I know, cannot process a command lines directly, but only processed command line args in the form of a list of strings -- sys.argv. Therefore, the need for testing is not to simulate a command line but to set sys.argv. I assume the programmer knows the mapping from command line to argv since he otherwise cannot sensibly proceed. I believe it is sensible, if not recommended, to put an arg processing in a defined function that returns, for instance, a dict, rather than to do it at top-level in the main script. So in use, process_args() will be called in a context with sys.argv set. So let it be tested. For instance, something like: def _test_arg_processing: arg_dict_pairs - ( (['arg1', 'arg2'], {'speed':int('arg1'), 'range':float('arg2'}), (['-v'], {'verbose': True}, ) for args,dic in arg_dict_pairs: sys.argv = args assert process_args() == dic Repeatable automatic testing of multiple test cases. I just starting doing this a year ago and love it. Terry Jan Reedy From tjreedy at udel.edu Thu Feb 4 19:12:27 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 04 Feb 2010 19:12:27 -0500 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: Iterators, and in particular, generators. A killer feature. Terry Jan Reedy From aahz at pythoncraft.com Thu Feb 4 19:18:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 4 Feb 2010 16:18:04 -0800 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On 3 Feb 2010 08:38:47 -0800, aahz at pythoncraft.com (Aahz) declaimed the >following in gmane.comp.python.general: >> In article , >> Dennis Lee Bieber wrote: >>> >>> I shall blaspheme, and suggest that maybe the language you want to >>>use is REXX (ooREXX or Regina). >>> >>> By default, ANY statement that can not be confused for a REXX >>>language statement is sent to the currently defined command handler >>>(Which on most OSs is equivalent to Python's os.system() call; the late >>>Amiga, and IBM's mainframe OS had features that support defining other >>>applications as command handlers). >> >> How is that different from bash scripting? > > Uhm... Does a bash script support inlining statements from some >other language? > > Python's shutil library essentially disappears in REXX as one can >plug in the native command line statement for those functions. But in bash scripting, you'd just use rsync or cp or rm -- maybe an example would make clearer how REXX differs from bash. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at holdenweb.com Thu Feb 4 19:20:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 19:20:38 -0500 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: Gabriel Genellina wrote: > En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma > escribi?: >> John Bokma writes: > >>>>>> On 2/4/2010 3:55 PM, Alan Biddle wrote: >>>>>>> Just finishing my first Python (2.6 on Win XP) program, which is >>>>>>> working fine. My "Duh?" question is about how to run it from within >>>>>>> IDLE and pass it command line arguments. > >>> I guess that Terry means that a solution that makes it possible to >>> specify in IDLE *outside* of the Python code the arguments would be >>> better. Hardcoding the command line arguments isn't something I would do >>> for testing. >> >> Oops, that should've been Steve, my apologies. > > See http://bugs.python.org/issue5680 > So we've had a patch since April and it still didn't make it into 3.1? That's disappointing. I wonder if there's any chance it'll get into 2.7. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From g.bogle at auckland.no.spam.ac.nz Thu Feb 4 19:21:07 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Fri, 05 Feb 2010 13:21:07 +1300 Subject: Python 3 minor irritation References: Message-ID: Gabriel Genellina wrote: > Sorry, I should have removed that line. This is just my setup; a normal > Python install doesn't create that registry entry. It allows Desktop > Search (or Windows Search, or whatever it is called nowadays; the F3 > key) to search inside .py files (default behavior is to just ignore > their contents). > See http://support.microsoft.com/kb/309173 > >> Is this related to the fact that when I double-click on a .py file the >> command window disappears after the execution is completed? > > (I bet the "Persistent" word confused you.) No, as you can see, it's > completely unrelated. AFAIK, there is no way (on XP and later at least) > to keep a console window open after the program exited. Three choices: > > - Open a cmd window and execute the script there. You may drag&drop the > file over the window to avoid typing the full path (I think this last > part does not work on Vista nor Win7) > > - Add a raw_input() [2.x] or input() [3.x] line at the end of the script > > - Rename it with a '.cmd' extension and add this line at the very top: > > @(C:\Python26\Python -x %~f0 %* || pause) && goto:EOF > > (see this post by Duncan Booth last month: > http://comments.gmane.org/gmane.comp.python.general/650913 ) > Thanks Gabriel. I didn't know about the drag&drop capability (learn something every day, forget two things). BTW input() works for me in 2.5. Cheers Gib From gagsl-py2 at yahoo.com.ar Thu Feb 4 20:13:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 04 Feb 2010 22:13:36 -0300 Subject: xmlrpc slow in windows 7 if hostnames are used References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Message-ID: En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: > I wrote a small xmlrpc client on Windows 7 with python 2.6 > > srv = xmlrpclib.Server('http://localhost:80') > > I was able to perform about 1 rpc call per second > > > After changing to > srv = xmlrpclib.Server('http://127.0.0.1:80') > > I was able to perform about 10 to 16 rpc calls per second. > > So it seems, that under windows 7 the host name lookup occurs for every > RPC call Not necesarily. There is another difference: 127.0.0.1 is an IPv4 address, localhost maps to both IPv4 and IPv6 addresses (::1) I vaguely remember a problem with that - IPv6 is tried first, doesn't work, only then IPv4, and that slows down the whole process. Try disabling completely the IPv6 stack, if you don't need it. -- Gabriel Genellina From stephen.thorne at gmail.com Thu Feb 4 20:13:40 2010 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Thu, 4 Feb 2010 17:13:40 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <7030037b-cd1e-4621-ab74-4f819ef5f4eb@k6g2000prg.googlegroups.com> On Feb 5, 8:26?am, Xah Lee wrote: > I appreciate that you taking this more seriously than normal > newsgroups postings. In fact, for this complaint, the response you > made is all i asked for. > > I am taking this as seriously as all the articles you have posted to usenet. Stephen. From python.list at tim.thechases.com Thu Feb 4 20:36:19 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 04 Feb 2010 19:36:19 -0600 Subject: Passing command line argument to program from within IDLE? In-Reply-To: References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: <4B6B7613.3000903@tim.thechases.com> Gabriel Genellina wrote: > En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma >> Oops, that should've been Steve, my apologies. > > See http://bugs.python.org/issue5680 Am I the only one that expected that issue to be about too many Steves (and perhaps too many Tims) on c.l.p? :-) -tkc From bcb at undisclosedlocation.net Thu Feb 4 20:45:48 2010 From: bcb at undisclosedlocation.net (Bruce C. Baker) Date: Thu, 4 Feb 2010 19:45:48 -0600 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: "Terry Reedy" wrote in message news:mailman.1929.1265328905.28905.python-list at python.org... > Iterators, and in particular, generators. > A killer feature. > > Terry Jan Reedy > Neither unique to Python. And then're the other killer "features" superfluous ":"s and rigid formatting! From jonny.lowe.12345 at gmail.com Thu Feb 4 20:56:50 2010 From: jonny.lowe.12345 at gmail.com (jonny lowe) Date: Thu, 4 Feb 2010 17:56:50 -0800 (PST) Subject: merge stdin, stdout? Message-ID: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> Hi everyone, Is there an easy way to merge stdin and stdout? For instance suppose I have script that prompts for a number and prints the number. If you execute this with redirection from a file say input.txt with 42 in the file, then executing ./myscript < input.txt > output.txt the output.txt might look like this: Enter a number: You entered 42. What I want is to have an easy way to merge input.txt and the stdout so that output.txt look like: Enter a number: 42 You entered 42. Here, the first 42 is of course from input.txt. Thanks. -jon From stephen.thorne at gmail.com Thu Feb 4 20:58:36 2010 From: stephen.thorne at gmail.com (Stephen Thorne) Date: Thu, 4 Feb 2010 17:58:36 -0800 (PST) Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: On Feb 5, 9:02?am, Steve Holden wrote: > > ? The list of ban'd person's names, the reason for banning, and the > > name of admin who ban'd them, should be public. (irc already provides > > means for this that allows admins to annotate in the ban list.) In > > particular, if you are going to ban someone by ip address, make sure > > the person's handle (or preferably real life name), be listed together > > with it. (again, this needs not elaborate. A single sentence will do, > > e.g. ?repeatedly asking same question?, ?continously raising > > controversial issues?, ?refused to use paste bin when requested? will > > do. Again, be as precise in description as possible. For example, > > ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) > > This is perhaps a little formal for something that (as far as I know) > happens less than once a month. I am reluctant to start up any kind of > bureaucracy around bannings unless they become too frequent (in which > case your suggestions above seem reasonable). The current banlist lists 258 names. According to my logs there have been 95 masks added to this list and 44 removals since October. This is approximately 23 a month, or 3 every 4 days. 11 ops were active in this action during this period. For reference, this is the 4th largest IRC channel on freenode according to http://searchirc.com/search.php?SCHANS=1&SSORT=SIZE&N=freenode and the other large channels weigh in with 298 (gentoo), 9 (archlinux), 14 (##C++), 280 (#ubuntu), 109 (#debian). We are hardly exceptional in the size of our list of people we have excluded from the IRC community. On discussion with #archlinux it seems that the reason archlinux has so few on their list is because they use chanserv's AKICK feature, which means the name isn't kept in the IRC client accessable banlist, and is only put there temporarily when the excluded user returns by chanserv. Stephen. From wolftracks at invalid.com Thu Feb 4 21:01:08 2010 From: wolftracks at invalid.com (W. eWatson) Date: Thu, 04 Feb 2010 18:01:08 -0800 Subject: Exiting a Program Running in Idle, Various Choices Message-ID: I I have a very simple program running in Python, with say the last line print "bye". it finishes leaving the script showing >>> in the shell window. The program proceeds linearly to the bottom line. Suppose now I have instead a few lines of MatPlotLib code (MPL) like this at the end: ... Show() Show displays some graph and again the code proceeds linearly from line 1. However, if one closes the graphic by clicking the x in the upper right corner of that window, then no >>> appears in the shell, and one must kill the shell using the x in the shell's upper right corner. A little dialog with the choices of OK (kill) or cancel appears. Use OK and the shell window disappears. A ctrl-c does nothing in the shell. I know about sys.exit(),and a "finish" def when using Tkinter. I'm not using Tkinter as far as I know via MPL. So how does one exit smoothly in this case of Show(), so that the shell window remains ready to entry commands? From steve at holdenweb.com Thu Feb 4 21:09:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 04 Feb 2010 21:09:47 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B6B7DEB.5020101@holdenweb.com> Stephen Thorne wrote: > On Feb 5, 9:02 am, Steve Holden wrote: >>> ? The list of ban'd person's names, the reason for banning, and the >>> name of admin who ban'd them, should be public. (irc already provides >>> means for this that allows admins to annotate in the ban list.) In >>> particular, if you are going to ban someone by ip address, make sure >>> the person's handle (or preferably real life name), be listed together >>> with it. (again, this needs not elaborate. A single sentence will do, >>> e.g. ?repeatedly asking same question?, ?continously raising >>> controversial issues?, ?refused to use paste bin when requested? will >>> do. Again, be as precise in description as possible. For example, >>> ?ban'd for trolling?, ?annoying others?, are not a meaningful reason.) >> This is perhaps a little formal for something that (as far as I know) >> happens less than once a month. I am reluctant to start up any kind of >> bureaucracy around bannings unless they become too frequent (in which >> case your suggestions above seem reasonable). > > The current banlist lists 258 names. According to my logs there have > been 95 masks added to this list and 44 removals since October. This > is approximately 23 a month, or 3 every 4 days. 11 ops were active in > this action during this period. > > For reference, this is the 4th largest IRC channel on freenode > according to http://searchirc.com/search.php?SCHANS=1&SSORT=SIZE&N=freenode > and the other large channels weigh in with 298 (gentoo), 9 > (archlinux), 14 (##C++), 280 (#ubuntu), 109 (#debian). > > We are hardly exceptional in the size of our list of people we have > excluded from the IRC community. > > On discussion with #archlinux it seems that the reason archlinux has > so few on their list is because they use chanserv's AKICK feature, > which means the name isn't kept in the IRC client accessable banlist, > and is only put there temporarily when the excluded user returns by > chanserv. > Thanks, Stephen. It's fairly obvious I am not an active IRC user, isn't it? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From hidura at gmail.com Thu Feb 4 21:10:45 2010 From: hidura at gmail.com (Hidura) Date: Thu, 4 Feb 2010 22:10:45 -0400 Subject: Problem with __init__.py in Python3.1 In-Reply-To: <871vh0mxdy.fsf@benfinney.id.au> References: <4bbf7fb21002032000u6bfc40f9n85ef2dcb04f1d2dd@mail.gmail.com> <4bbf7fb21002040740x66f203c7x57099d07de1fe30@mail.gmail.com> <871vh0mxdy.fsf@benfinney.id.au> Message-ID: <4bbf7fb21002041810xc9bf899v1827ff83abb67c44@mail.gmail.com> Thanks i middle resolve the problem, and i going to read the PEP-366 i've been read the 328, i will kept informed of the progresses. Thanks again for the help [?] On Thu, Feb 4, 2010 at 6:47 PM, Ben Finney > wrote: > "Gabriel Genellina" writes: > > > If you directly run a script from inside a package, Python does not > > know that it belongs to a package, and treats it as a simple, lonely > > script. In that case, relative imports won't work. > > Which I consider to be a bug. Fortunately, it's already addressed in PEP > 366 . Unfortunately, it > involves more hackish boilerplate at the top of the program, and is only > available in Python 2.6+. > > -- > \ ?Ignorance more frequently begets confidence than does | > `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 330.png Type: image/png Size: 611 bytes Desc: not available URL: From exarkun at twistedmatrix.com Thu Feb 4 21:20:22 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Fri, 05 Feb 2010 02:20:22 -0000 Subject: merge stdin, stdout? In-Reply-To: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> Message-ID: <20100205022022.26099.2092860927.divmod.xquotient.476@localhost.localdomain> On 01:56 am, jonny.lowe.12345 at gmail.com wrote: >Hi everyone, > >Is there an easy way to merge stdin and stdout? For instance suppose I >have script that prompts for a number and prints the number. If you >execute this with redirection from a file say input.txt with 42 in the >file, then executing > >./myscript < input.txt > output.txt > >the output.txt might look like this: > >Enter a number: >You entered 42. > >What I want is to have an easy way to merge input.txt and the stdout >so that output.txt look like: > >Enter a number: 42 >You entered 42. > >Here, the first 42 is of course from input.txt. It sounds like you might be looking for script(1)? Jean-Paul From half.italian at gmail.com Thu Feb 4 21:26:06 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Thu, 4 Feb 2010 18:26:06 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <1445b521-d9d9-4200-9a01-f146e1543d40@t17g2000prg.googlegroups.com> On Feb 4, 3:03?pm, Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. > > Regards > Julian I love list comprehensions, but am currently falling for 'with'. ~Sean From half.italian at gmail.com Thu Feb 4 22:10:31 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Thu, 4 Feb 2010 19:10:31 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: On Feb 3, 6:08?pm, alex23 wrote: > On Feb 4, 8:47?am, Phlip wrote: > > > Yes, calling os.path.walk() and os.path.join() all the time on raw > > strings is fun, but I seem to recall from my Ruby days a class called > > Pathname, which presented an object that behaved like a string at > > need, and like a filesystem path at need. path + 'folder' would > > call .join() and insert the / correctly, for example. > > > What's the best equivalent in Python-land? > > It's no longer supported, but the 3rd party 'path' module used to be > the go-to module for this: > > >>> from path import path > > C:\Python26\lib\site-packages\path.py:32: DeprecationWarning: the md5 > module is deprecated; use hashlib instead > ? import sys, warnings, os, fnmatch, glob, shutil, codecs, md5>>> c = path('C:\\') > >>> c.listdir() > > [path(u'C:\\AUTOEXEC.BAT'), path(u'C:\\boot.ini'), ...]>>> (c + 'python26').listdir() > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > \python26\\DLLs'), ...]>>> (c / 'python26').listdir() > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > \python26\\DLLs'), ...] > > I've hand edited the results for brevity... > > The module could do with some TLC to bring it up to date, but warning > aside it still seems to work fine under 2.6. > > (From memory, I think the original author gave up when it became clear > it would never be integrated into the standard lib[1], which is a > shame, I think there's scope for a pathtools addition to the lib that > provides this level of convenience...) > > There was also a PEP with another possible implementation:http://www.python.org/dev/peps/pep-0355/ > > Hope this helps. It's too bad that something like this can't be agreed to. I used a homegrown module like this for a couple of years in my early days with python. It was great, but I didn't know enough at the time to make it really useful. Why did Path() get rejected? Is it the idea itself, or just the approach that was used? What are the complaints? ~Sean From aharrisreid at googlemail.com Thu Feb 4 22:29:40 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Fri, 05 Feb 2010 03:29:40 +0000 Subject: Passing parameters in URL In-Reply-To: <7svgogF768U1@mid.uni-berlin.de> References: <878wbafaui.fsf@castleamber.com> <7sua7fFn74U1@mid.uni-berlin.de> <7xeil2q8e4.fsf@ruckus.brouhaha.com> <7subqbFvvpU1@mid.uni-berlin.de> <7xmxzqx804.fsf@ruckus.brouhaha.com> <7suf0pFhadU1@mid.uni-berlin.de> <7xr5p1dh2x.fsf@ruckus.brouhaha.com> <7suhh1Ft2dU1@mid.uni-berlin.de> <7x3a1h7s82.fsf@ruckus.brouhaha.com> <7svgogF768U1@mid.uni-berlin.de> Message-ID: <4B6B90A4.6060708@googlemail.com> Many thanks to all those who replied to my question and clearing-up the differences between GET and POST. I think I know what to do now - if not, I'll be back :-) Regards, Alan From sridharr at activestate.com Fri Feb 5 00:01:27 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 4 Feb 2010 21:01:27 -0800 Subject: ANN: ActivePython 2.6.4.10 is now available Message-ID: I'm happy to announce that ActivePython 2.6.4.10 is now available for download from: http://www.activestate.com/activepython/ This is a minor release with several updates and fixes. Changes in 2.6.4.10 ------------------- - PyPM is now included in 64-bit Windows and Linux builds - Include Distribute instead of setuptools - Include pip - Upgrade to Tcl/Tk 8.5.8 - [Windows] Upgrade to Pywin32 CVS (2009-11-10) - [Windows] Support for OpenSSL in 64-bit - [Windows] Include Tcl/Tk header files - [Windows] Fix broken IDLE on the 64-bit build 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. Builds for Solaris, HP-UX and AIX, and access to older versions are available with ActivePython Business Edition: http://www.activestate.com/business_edition/ 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. Beginning with the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: pypm install pylons 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/query.cgi?set_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 Edition only) - Solaris/x86 (Business Edition only) - HP-UX/PA-RISC (Business Edition only) - AIX/PowerPC (Business Edition only) - AIX/PowerPC 64-bit (Business Edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/activepython/enterprise/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 00:20:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 05:20:58 GMT Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: <00f52feb$0$15566$c3e8da3@news.astraweb.com> On Thu, 04 Feb 2010 19:36:19 -0600, Tim Chase wrote: > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma >>> Oops, that should've been Steve, my apologies. >> >> See http://bugs.python.org/issue5680 > > > Am I the only one that expected that issue to be about too many Steves > (and perhaps too many Tims) on c.l.p? :-) That was exactly my thought too. One of the multiple Steves'ly yrs, -- Steve From john at castleamber.com Fri Feb 5 00:50:20 2010 From: john at castleamber.com (John Bokma) Date: Thu, 04 Feb 2010 23:50:20 -0600 Subject: Passing command line argument to program from within IDLE? References: <6acmm5h60l9he1ntoac87ogp1dqjh4msj6@4ax.com> <00f4d6df$0$15566$c3e8da3@news.astraweb.com> <87r5p07eo6.fsf@castleamber.com> <87mxzo7edv.fsf@castleamber.com> Message-ID: <871vh0z0wz.fsf@castleamber.com> Tim Chase writes: > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 20:46:52 -0300, John Bokma >> >>> Oops, that should've been Steve, my apologies. >> >> See http://bugs.python.org/issue5680 > > Am I the only one that expected that issue to be about too many Steves > (and perhaps too many Tims) on c.l.p? :-) Ha ha ha, yeah something like that, wasn't expecting what was actually on that page. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From nagle at animats.com Fri Feb 5 01:18:37 2010 From: nagle at animats.com (John Nagle) Date: Thu, 04 Feb 2010 22:18:37 -0800 Subject: Common area of circles In-Reply-To: References: Message-ID: <4b6bb461$0$1654$742ec2ed@news.sonic.net> Chris Rebert wrote: > On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand wrote: >> Given 'n' circles and the co-ordinates of their center, and the radius of >> all being equal i.e. 'one', How can I take out the intersection of their >> area. > > How is this at all specific to Python? > > This also sounds suspiciously like homework, which you should know > this list is unlikely to give direct answers to, though you might be > able to get a few pointers or some general suggestions. Good point. This is actually a problem in what's called "constructive geometry". Usually, this is a 3D problem, for which the term "constructive solid geometry", or CSG, is used. That's where to look for algorithms. Yes, there are efficient algorithms and near-exact solutions. The basic idea is that you find all the points at which circles intersect, sort those by one coordinate, and advance across that coordinate, from one value of interest to the next. Between any two values of interest you're dealing with areas bounded by arcs and lines, so the areas can be calculated analytically. It's a lot like a rasterized polygon fill algorithm. (I used to do stuff like this back when I did physics engines with efficient 3D collision detection.) John Nagle From arnodel at googlemail.com Fri Feb 5 02:12:05 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 4 Feb 2010 23:12:05 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On 4 Feb, 23:03, Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. > > Regards > Julian * simplicity * documentation - some criticise it, I love it. * duck typing * batteries included And lots more! -- Arnaud From no.email at nospam.invalid Fri Feb 5 02:19:46 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 04 Feb 2010 23:19:46 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <7xr5p0kv3h.fsf@ruckus.brouhaha.com> Julian writes: > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". - Very easy to learn, at least for the not-too-hairy fragment - some features like generators are advanced compared with some other languages, yet still easy to use - pleasant-to-use syntax (yes, the indentation stuff that everyone is freaked out by at first) and well-evolved library makes coding very productive and enjoyable - reasonably good documentation - large and friendly user/developer community From george.sakkis at gmail.com Fri Feb 5 02:25:59 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Thu, 4 Feb 2010 23:25:59 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On Feb 5, 2:45?am, "Bruce C. Baker" wrote: > "Terry Reedy" wrote in message > > news:mailman.1929.1265328905.28905.python-list at python.org... > > > Iterators, and in particular, generators. > > A killer feature. > > > Terry Jan Reedy +1, iterators/generators is among Python's best features for me too. > Neither unique to Python. Can you name a single feature that is unique to a language, Python or other ? Every idea that's any good has been copied over, usually more than once. > And then're the other killer "features" superfluous ":"s and rigid > formatting! I'll give the benefit of doubt and assume you're joking rather than trolling. George From contact at xavierho.com Fri Feb 5 02:29:39 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 5 Feb 2010 17:29:39 +1000 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <2d56febf1002042329p63900958v56e1e9074267d1c8@mail.gmail.com> Personally, I love the fact that I can type in 2**25 in the intepreter without crashing my machine. ;) Cheers, -Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From monaghand.david at gmail.com Fri Feb 5 02:43:55 2010 From: monaghand.david at gmail.com (David Monaghan) Date: Fri, 05 Feb 2010 07:43:55 +0000 Subject: Python 3 minor irritation References: Message-ID: On Thu, 04 Feb 2010 00:39:01 +0000, David Monaghan wrote: >I have a small program which reads files from the directory in which it >resides. It's written in Python 3 and when run through IDLE or PythonWin >works fine. If I double-click the file, it works fine in Python 2.6, but in >3 it fails because it looks for the files to load in the Python31 folder, >not the one the script is in. > >It's not a big deal, but browsing around I haven't found why the behaviour >has been changed or any comment about it (That might be my poor search >technique, I suppose). > >The program fails at: > > try: > tutdoc = minidom.parse(".//Myfile.xml") > except IOError: > I very much appreciate all the help offered on this, but feel a bit of an idiot now as I can't reproduce the behaviour (it had happened on two separate machines). What I am still getting is a similar problem on my work computer with the program on a network hard drive. Not always - it'll run on repeated attempts, then fail for a few, then work again. When it failed I ran the script as suggested: import os print("curdir=", os.getcwd()) print("__file__=", __file__) input() and got the response: curdir= H:\ __file__= H:\FRCR\FRCR2010\Course documents\FRCR2009\Script1.py so it's 'sticking' at H: For interest, I ran the script from IDLE, too, and PythonWin, on three separate computers (2 Python3, 1 Python2.6) With that I get a NameError for __file__ curdir= H:\FRCR\FRCR2010\Course documents\FRCR2009 Traceback (most recent call last): File "H:\FRCR\FRCR2010\Course documents\FRCR2009\Script1.py", line 3, in print("__file__=", __file__) NameError: name '__file__' is not defined What have I done wrong? DaveM From donn.ingle at gmail.com Fri Feb 5 03:01:54 2010 From: donn.ingle at gmail.com (donn) Date: Fri, 05 Feb 2010 10:01:54 +0200 Subject: pyclutter anyone? Message-ID: <4B6BD072.4080006@gmail.com> Hi, this is a little bit of a cross-post. I posted to the clutter list, but there's little activity there. I am trying to make sense of pyClutter 1.0. Could anyone point me to an example (or post one) that shows clipping from a path applied to child objects? For example: A star shape that contains a bunch of moving rectangles which will travel/size/rotate with the star, but are clipped to the shape of the star. I suspect this will involve a custom clutter.Group class of some kind, with cogl paths and an on_paint() method, but I can find no headway on the web so far. Hope someone can help! \d -- Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software From anthra.norell at bluewin.ch Fri Feb 5 03:36:33 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 05 Feb 2010 09:36:33 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start Message-ID: <4B6BD891.3060505@bluewin.ch> Hi, I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle window. This is the command I have been using: C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c execfile('C:\\Python24\\i') And this is the command that doesn't start anything: C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c execfile('C:\\Python25\\i') The command is exactly the same with the digit 5 in the place of 4. All paths and names are correct. C:\\Python25\\i sets up sys.path but seems irrelevant, as taking the execfile () part out doesn't change anything. The OS is Windows ME. The download of 2.5 finished with a warning saying that 2.5 was the highest version for Windows 9* Any tips? Thanks Frederic From anand.shashwat at gmail.com Fri Feb 5 03:49:02 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Fri, 5 Feb 2010 14:19:02 +0530 Subject: Common area of circles In-Reply-To: <4b6bb461$0$1654$742ec2ed@news.sonic.net> References: <4b6bb461$0$1654$742ec2ed@news.sonic.net> Message-ID: Here is my approach: # input circles, remove duplicates, store them # check whether all circle intersect: if no: print '0.0' if yes: # calculate intersection points of two circles. # check if that point lies in rest all circles if yes: store it as polygon-coordinates (hull) calculate area of curve from the given two points # calculate final area : net area of curve + area of polygon Here is my final code : It's still Buggy (the logic I believe is correct, The implementation is Buggy I guess import math def catch_point(x, y): # checks for points which lie inside all the circles # stores all such point in hull kount = True for i in range(n): if (x - circle[i][0])**2 + (y - circle[i][1])**2 - 1.0 > 0: kount = False if kount == True: hull.append((x, y)) def curve_area(x0, y0, x1, y1, x2, y2): k = math.sqrt((x1 - x2)**2 + (y1 - y2)**2) area_c = math.pi * (math.degrees(math.acos(1.0 - k*k/2.0))/360) #TODO Verify area_t = 0.5 * ( x0*(y1 - y2) - x1*(y0 - y2) + x2*(y0 - y1) ) if area_t < 0: area_t = -area_t area = area_c - area_t #print area return area def polygon_area(p): # calculate area of the polygon given the co-ordinates return 0.5 * abs(sum(x0*y1 - x1*y0 for ((x0, y0), (x1, y1)) in segments(p))) def segments(p): return zip(p, p[1:] + [p[0]]) def intersect_circles(l): # check whether all circle intersects or not for i in l: for j in l: if (i[0] - j[0])**2 + (i[1] - j[1])**2 >= 4.0: sol = 0.0 return sol break return 1.0 def intersect_coordinates(l): sol = 0.0 # initialisation of final result for i in range(n): for j in range(n): # find all intersecting co-ordinates for each circle xa, xb = circle[i][0], circle[j][0] ya, yb = circle[i][1], circle[j][1] d = math.sqrt((xa - xb)**2 + (ya - yb)**2) if d == 0: continue x1 = 0.5*(xa + xb) + 0.5*(yb - ya)*math.sqrt(4 - d*d) / d y1 = 0.5*(yb + ya) - 0.5*(xb - xa)*math.sqrt(4 - d*d) / d catch_point(x1, y1) # first intersection point x2 = 0.5*(xa + xb) - 0.5*(yb - ya)*math.sqrt(4 - d*d) / d y2 = 0.5*(yb + ya) + 0.5*(xb - xa)*math.sqrt(4 - d*d) / d catch_point(x2, y2) # second intersection point sol += curve_area(circle[i][0], circle[i][1], hull[-1][0], hull[-1][1], hull[-2][0], hull[-2][1]) # add up the value of curves return sol t = int(raw_input()) # total no. of test cases for test in range(t): n = int(raw_input()) # total no. of circles circle = [] # a blank list which will contain center of circles hull = [] # a blank list which will consist of points on convex polygon for i in range(n): x,y = [float(i) for i in raw_input().split()] circle.append((x,y)) # storing the value circle = list(set(circle)) # removing duplicates n = len(circle) # calculating no. of non-duplicate circle sol = intersect_circles(circle) #intersect_circles() check whether all circle intersect if sol == 0.0: # if sol == 0.0 means all circle do not intersect print "0.000000" # solution = 0.000000 in this case elif n == 1: # if only 1 circle present, the solution is PI print "%.6f" %(math.pi) else: sol = intersect_coordinates(circle) # for rest cases we need to calculate intersection co-ordinates of circle print "%.6f" %(sol + polygon_area(hull)) # final solution sample output : 4 2 0 0 1 0 1.228370 3 0 0 0 0 0 0 3.141593 3 0 0 0 1 10 12 0.000000 3 0 0 1 0 0 1 0.192972 Either there is a redundency or there is some issue with this line : sol += curve_area(circle[i][0], circle[i][1], hull[-1][0], hull[-1][1], hull[-2][0], hull[-2][1]) Still trying to fix it. ~l0nwlf On Fri, Feb 5, 2010 at 11:48 AM, John Nagle wrote: > Chris Rebert wrote: > >> On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand >> wrote: >> >>> Given 'n' circles and the co-ordinates of their center, and the radius of >>> all being equal i.e. 'one', How can I take out the intersection of their >>> area. >>> >> >> How is this at all specific to Python? >> >> This also sounds suspiciously like homework, which you should know >> this list is unlikely to give direct answers to, though you might be >> able to get a few pointers or some general suggestions. >> > > Good point. > > This is actually a problem in what's called "constructive geometry". > Usually, this is a 3D problem, for which the term "constructive solid > geometry", or CSG, is used. That's where to look for algorithms. > > Yes, there are efficient algorithms and near-exact solutions. > The basic idea is that you find all the points at which circles > intersect, sort those by one coordinate, and advance across that > coordinate, from one value of interest to the next. Between any > two values of interest you're dealing with areas bounded by arcs > and lines, so the areas can be calculated analytically. It's a > lot like a rasterized polygon fill algorithm. > > (I used to do stuff like this back when I did physics engines > with efficient 3D collision detection.) > > John Nagle > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Fri Feb 5 04:01:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Feb 2010 10:01:49 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: Message-ID: * Anthra Norell: > Hi, > > I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle window. > > This is the command I have been using: > C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python24\\i') > > And this is the command that doesn't start anything: > C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python25\\i') > > The command is exactly the same with the digit 5 in the place of 4. All > paths and names are correct. C:\\Python25\\i sets up sys.path but seems > irrelevant, as taking the execfile () part out doesn't change anything. > The OS is Windows ME. The download of 2.5 finished with a warning saying > that 2.5 was the highest version for Windows 9* Any tips? Don't know, but the '-n' option, is that passed to IDLE? Perhaps try removing that. Cheers & hth., - Alf From news123 at free.fr Fri Feb 5 04:10:39 2010 From: news123 at free.fr (News123) Date: Fri, 05 Feb 2010 10:10:39 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Message-ID: <4b6be08f$0$10133$426a74cc@news.free.fr> Yhanks a lot I'll check whether this is the root cause. Currently my machine could live without IPV6 bye N Gabriel Genellina wrote: > En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: > >> I wrote a small xmlrpc client on Windows 7 with python 2.6 >> >> srv = xmlrpclib.Server('http://localhost:80') >> >> I was able to perform about 1 rpc call per second >> >> >> After changing to >> srv = xmlrpclib.Server('http://127.0.0.1:80') >> >> I was able to perform about 10 to 16 rpc calls per second. >> >> So it seems, that under windows 7 the host name lookup occurs for every >> RPC call > > Not necesarily. There is another difference: 127.0.0.1 is an IPv4 > address, localhost maps to both IPv4 and IPv6 addresses (::1) > > I vaguely remember a problem with that - IPv6 is tried first, doesn't > work, only then IPv4, and that slows down the whole process. > Try disabling completely the IPv6 stack, if you don't need it. > From jeanmichel at sequans.com Fri Feb 5 05:58:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 11:58:18 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6be08f$0$10133$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> Message-ID: <4B6BF9CA.4030702@sequans.com> News123 wrote: > Yhanks a lot I'll check whether this is the root cause. > > Currently my machine could live without IPV6 > > > bye > > N > > > Gabriel Genellina wrote: > >> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >> >> >>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>> >>> srv = xmlrpclib.Server('http://localhost:80') >>> >>> I was able to perform about 1 rpc call per second >>> >>> >>> After changing to >>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>> >>> I was able to perform about 10 to 16 rpc calls per second. >>> >>> So it seems, that under windows 7 the host name lookup occurs for every >>> RPC call >>> >> Not necesarily. There is another difference: 127.0.0.1 is an IPv4 >> address, localhost maps to both IPv4 and IPv6 addresses (::1) >> >> I vaguely remember a problem with that - IPv6 is tried first, doesn't >> work, only then IPv4, and that slows down the whole process. >> Try disabling completely the IPv6 stack, if you don't need it. >> >> Or you can simply use an explicit external address. Most of the time xmlRPC server/clients are used between distant machines. If your are using localhost for test purpose, then binding your server on its external IP instead of the local one could solve your problem (wihtout removing the IPV6 stack). import socket # server server = SimpleXMLRPCServer((socket.gethostname(), 5000), logRequests=False, allow_none=True) # client xmlrpclib.ServerProxy("http://%s.yourdomain.com:%s" % (socket.gethostname(), 5000)) JM PS : please don't top post :o) PS : just wondering if using the port 80 is legal From martin.hellwig at dcuktec.org Fri Feb 5 06:09:16 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 05 Feb 2010 11:09:16 +0000 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On 02/04/10 23:03, Julian wrote: > For those guys would be a poster quite cool which describes the most > popular and beloved python features. That it is ego-orientated programming ;-) http://mail.python.org/pipermail/python-announce-list/2009-April/007419.html -- mph From jeanmichel at sequans.com Fri Feb 5 06:10:57 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 12:10:57 +0100 Subject: Your beloved python features In-Reply-To: <4B6B5E72.20702@stoneleaf.us> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: <4B6BFCC1.9070104@sequans.com> Ethan Furman wrote: > Julian wrote: >> Hello, >> >> I've asked this question at stackoverflow a few weeks ago, and to make >> it clear: this should NOT be a copy of the stackoverflow-thread >> "hidden features of Python". >> >> I want to design a poster for an open source conference, the local >> usergroup will have a table there, and in the past years there were >> some people that came to the python-table just to ask "why should I >> use python?". >> >> For those guys would be a poster quite cool which describes the most >> popular and beloved python features. >> >> So, may you help me please? If there's a similar thread/blogpost/ >> whatever, please give it to me, google couldn't. >> >> Regards >> Julian > > http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf > "Choose metaclasses if you don?t value your sanity." That remembers me the time when it took me 4 hours to write a ten lines metaclass :o) JM From lallous at lgwm.org Fri Feb 5 06:11:01 2010 From: lallous at lgwm.org (lallous) Date: Fri, 5 Feb 2010 03:11:01 -0800 (PST) Subject: Building a multiline string References: Message-ID: @Ulrich: On Feb 4, 1:09?pm, Ulrich Eckhardt wrote: > Just for the record: Neither of the below methods actually produce a > multiline string. They only spread a string containing one line over > multiple lines of source code. > I meant: "Note" -> "Note: I don't want to use new lines" I did not want a multi line string Thanks guys, method 3 seems to be good enough. From duncan.booth at invalid.invalid Fri Feb 5 06:38:15 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2010 11:38:15 GMT Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: Message-ID: Anthra Norell wrote: > Hi, > > I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle > window. > > This is the command I have been using: > C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python24\\i') > > And this is the command that doesn't start anything: > C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c > execfile('C:\\Python25\\i') > > The command is exactly the same with the digit 5 in the place of 4. > All paths and names are correct. C:\\Python25\\i sets up sys.path but > seems irrelevant, as taking the execfile () part out doesn't change > anything. The OS is Windows ME. The download of 2.5 finished with a > warning saying that 2.5 was the highest version for Windows 9* Any > tips? > > Thanks > Does 'unable to start a 2.5 idle window' mean you get some sort of error or simply that nothing happens? What happens if you simply run C:\Python25\Lib\IDLELIB\idle.bat Does that work or not? What about running this from a command prompt: C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.py Does that run idle or do you get any error messages? What about this? C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.pyw Using pythonw.exe will start the program with all error output dumped in the bit bucket. Running from a command prompt with python.exe will at least let you see if there are any errors. -- Duncan Booth http://kupuguy.blogspot.com From fetchinson at googlemail.com Fri Feb 5 06:42:47 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 5 Feb 2010 12:42:47 +0100 Subject: Your beloved python features In-Reply-To: <4B6B5E72.20702@stoneleaf.us> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: >> I've asked this question at stackoverflow a few weeks ago, and to make >> it clear: this should NOT be a copy of the stackoverflow-thread >> "hidden features of Python". >> >> I want to design a poster for an open source conference, the local >> usergroup will have a table there, and in the past years there were >> some people that came to the python-table just to ask "why should I >> use python?". >> >> For those guys would be a poster quite cool which describes the most >> popular and beloved python features. >> >> So, may you help me please? If there's a similar thread/blogpost/ >> whatever, please give it to me, google couldn't. >> >> Regards >> Julian > > http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf This is effin hilarious! Should be either linked or stored on python.org Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From ashokprabhuv at gmail.com Fri Feb 5 06:57:17 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 03:57:17 -0800 (PST) Subject: Repost: Read a running process output Message-ID: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> Hi, I very badly need this to work. I have been googling out for a week with no significant solution. I open a process p1 which does keeps running for 4+ hours. It gives some output in stdout now and then. I open this process with subprocess.Popen and redirect the stdout to PIPE. However when I read the output with readline it blocks waiting forever. I need to read from p1.stdout till what it has in the PIPE. Can someone help me out with the exact code change that can accomplish the task. from subprocess import * p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) while 1: line=p1.stdout.readline() print line Thanks in advance, ~Ashok. From alain at dpt-info.u-strasbg.fr Fri Feb 5 07:12:55 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Feb 2010 13:12:55 +0100 Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> Message-ID: <87aavnnans.fsf@dpt-info.u-strasbg.fr> Ashok Prabhu writes: > from subprocess import * > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. -- Alain. From mrkafk at gmail.com Fri Feb 5 07:13:16 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 13:13:16 +0100 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <87y6jef1df.fsf@castleamber.com> <0375f27a$0$1309$c3e8da3@news.astraweb.com> <878wbdye6p.fsf@castleamber.com> <87tyu1ws3c.fsf@castleamber.com> Message-ID: Steve Holden wrote: >>> Jeez, Steve, you're beginning to sound like some kind of fallacy >>> zealot... ;) >> Death to all those who confuse agumentum ad populum with argumentum ad >> verecundiam!!! >> >> > Yeah, what did the zealots ever do for us? They produced Python? . . . Oh Python! Shut up! From alpeachey at gmail.com Fri Feb 5 07:16:16 2010 From: alpeachey at gmail.com (apeach) Date: Fri, 5 Feb 2010 04:16:16 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: I love intuitive type recognition. no need to 'DIM everything AS Integer' etc.! From bartc at freeuk.com Fri Feb 5 07:18:46 2010 From: bartc at freeuk.com (bartc) Date: Fri, 05 Feb 2010 12:18:46 GMT Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: "R Fritz" wrote in message news:e97ff208-d08e-4934-8e38-a40d668cd116 at l24g2000prh.googlegroups.com... > My favorite feature is its readability. It's as near to pseudo-code > as any language we have, and that's valuable in open source projects > or when I return to code to modify it. That might be true when used to code actual algorithms using basic features. But a lot of Pythonisms would appear mysterious to someone who doesn't know the language (for example, what does :: mean in an array index). Or perhaps pseudo-code is much more advanced these days... -- bartc From frank at chagford.com Fri Feb 5 07:45:30 2010 From: frank at chagford.com (Frank Millman) Date: Fri, 5 Feb 2010 14:45:30 +0200 Subject: Simple question about Queue.Queue and threads Message-ID: Hi all Assume you have a server process running, a pool of worker threads to perform tasks, and a Queue.Queue() to pass the tasks to the workers. In order to shut down the server cleanly, you want to ensure that the workers have all finished their tasks. I like the technique of putting a None onto the queue, and have each worker check for None, put None back onto the queue, and terminate itself. The main program would look something like this - q.put(None) for worker in worker_threads: worker.join() At this point you can be sure that each thread has completed its tasks and terminated itself. However, the queue is not empty - it still has the final None in it. Is it advisable to finalise the cleanup like this? - while not q.empty(): q.get() q.task_done() q.join() Or is this completely redundant? Thanks Frank Millman From ashokprabhuv at gmail.com Fri Feb 5 07:53:05 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 04:53:05 -0800 (PST) Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> Message-ID: <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> On Feb 5, 5:12?pm, Alain Ketterlin wrote: > Ashok Prabhu writes: > > from subprocess import * > > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. > > -- Alain. Hi Alain, Thanks for the response. However it throws an error. Please find below. >>> from subprocess import * >>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/subprocess.py", line 543, in __init__ errread, errwrite) File "/usr/lib/python2.4/subprocess.py", line 975, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory Thanks, ~Ashok. From alain at dpt-info.u-strasbg.fr Fri Feb 5 07:58:27 2010 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Fri, 05 Feb 2010 13:58:27 +0100 Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> Message-ID: <87636bn8jw.fsf@dpt-info.u-strasbg.fr> Ashok Prabhu writes: >> > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) >> >> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. >> >> -- Alain. > Thanks for the response. However it throws an error. Please find > below. > >>>> from subprocess import * >>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) You forgot to change the monolithic command into a list of words. Since you don't use the shell anymore you have to give Popen a pre-parsed command line. -- Alain. From anthra.norell at bluewin.ch Fri Feb 5 08:23:57 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 05 Feb 2010 14:23:57 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: Message-ID: <4B6C1BED.6090807@bluewin.ch> Thank you both (Alf and Duncan) for your comments. I answer Duncan's questions interleaved: Duncan Booth wrote: > Anthra Norell wrote: > > >> Hi, >> >> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >> window. >> >> This is the command I have been using: >> C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c >> execfile('C:\\Python24\\i') >> >> And this is the command that doesn't start anything: >> C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c >> execfile('C:\\Python25\\i') >> >> The command is exactly the same with the digit 5 in the place of 4. >> All paths and names are correct. C:\\Python25\\i sets up sys.path but >> seems irrelevant, as taking the execfile () part out doesn't change >> anything. The OS is Windows ME. The download of 2.5 finished with a >> warning saying that 2.5 was the highest version for Windows 9* Any >> tips? >> >> Thanks >> >> > Does 'unable to start a 2.5 idle window' mean you get some sort of error > or simply that nothing happens? > Nothing happens and no error message shows. The disk head stepper makes a brief attempt at something then goes silent and that's it. > What happens if you simply run C:\Python25\Lib\IDLELIB\idle.bat > Does that work or not? > Same thing: Nothing happens > What about running this from a command prompt: > > C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.py > Same thing: Nothing! > Does that run idle or do you get any error messages? > What about this? > > C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.pyw > > Nothing! > Using pythonw.exe will start the program with all error output dumped in > the bit bucket. Running from a command prompt with python.exe will at > least let you see if there are any errors. > python.exe from the command line works all right in a DOS window. The problem must be with idle.pyw. I tried the old idle.pyw (2.4) with the new python.exe. (2.5) and that didn't work either. What is the bit bucket? If I had a clue, I could go from there. What puzzles me is that version 2.4 has been working fine and one wouldn't think that the changes from 2.4 to 2.5 would be so extensive as to cause a major malfunction. For the time being 2.4 works fine. I'd much prefer 2.5, though, because it includes the image library (PIL), whereas 2.4 cannot even use it. Frederic From ashokprabhuv at gmail.com Fri Feb 5 08:33:00 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 05:33:00 -0800 (PST) Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> <87636bn8jw.fsf@dpt-info.u-strasbg.fr> Message-ID: <4ae7195a-d3ec-4886-9123-de88641aa797@g8g2000pri.googlegroups.com> On Feb 5, 5:58?pm, Alain Ketterlin wrote: > Ashok Prabhu writes: > >> > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > >> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. > > >> -- Alain. > > Thanks for the response. However it throws an error. Please find > > below. > > >>>> from subprocess import * > >>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) > > You forgot to change the monolithic command into a list of words. Since > you don't use the shell anymore you have to give Popen a pre-parsed > command line. > > -- Alain. Here is the error again >>> p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/subprocess.py", line 494, in __init__ raise TypeError("bufsize must be an integer") TypeError: bufsize must be an integer ~Ashok. From ashokprabhuv at gmail.com Fri Feb 5 08:39:49 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Fri, 5 Feb 2010 05:39:49 -0800 (PST) Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> <87636bn8jw.fsf@dpt-info.u-strasbg.fr> <4ae7195a-d3ec-4886-9123-de88641aa797@g8g2000pri.googlegroups.com> Message-ID: On Feb 5, 6:33?pm, Ashok Prabhu wrote: > On Feb 5, 5:58?pm, Alain Ketterlin > wrote: > > > > > Ashok Prabhu writes: > > >> > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > > >> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. > > > >> -- Alain. > > > Thanks for the response. However it throws an error. Please find > > > below. > > > >>>> from subprocess import * > > >>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) > > > You forgot to change the monolithic command into a list of words. Since > > you don't use the shell anymore you have to give Popen a pre-parsed > > command line. > > > -- Alain. > > Here is the error again > > >>> p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE) > > Traceback (most recent call last): > ? File "", line 1, in ? > ? File "/usr/lib/python2.4/subprocess.py", line 494, in __init__ > ? ? raise TypeError("bufsize must be an integer") > TypeError: bufsize must be an integer > > ~Ashok. Oops i missed the braces. But still no output. >>> p1=Popen(['/usr/sunvts/bin/64/vtsk','-d'],stdout=PIPE) >>> while 1: ... a=p1.stdout.readline() ... print a ... From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 08:43:50 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 14:43:50 +0100 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4b6c2095$0$22370$426a74cc@news.free.fr> apeach a ?crit : > I love intuitive type recognition. > > no need to 'DIM everything AS Integer' etc.! > not to mention the ever hilarious (that is, when you don't have to maintain it) typical Java idiom: EveryThing theEveryThing = new EveryThing(); From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 08:45:17 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 14:45:17 +0100 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4b6c20eb$0$22370$426a74cc@news.free.fr> Julian a ?crit : > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. My all-time favorite Python feature : it fits my brain. From rdv at roalddevries.nl Fri Feb 5 08:49:53 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 5 Feb 2010 14:49:53 +0100 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <99F0D2AF-0DAD-457C-B651-0A93A31A37CE@roalddevries.nl> On Feb 5, 2010, at 12:03 AM, Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup will have a table there, and in the past years there were > some people that came to the python-table just to ask "why should I > use python?". > > For those guys would be a poster quite cool which describes the most > popular and beloved python features. > > So, may you help me please? If there's a similar thread/blogpost/ > whatever, please give it to me, google couldn't. My reasoning: I needed a language more powerful than bash, but more portable and faster to develop (at least small scripts) than C/C++. So I needed a scripting language. Python, Ruby, Perl, Tcl, ...? Python seems to be the language with the most libraries available, programs written in it, OS-support (even runs on my smartphone), has a good data-model, has a good interactive shell (iPython). From duncan.booth at invalid.invalid Fri Feb 5 08:49:53 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 5 Feb 2010 13:49:53 GMT Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: Message-ID: Anthra Norell wrote: >> Using pythonw.exe will start the program with all error output dumped in >> the bit bucket. Running from a command prompt with python.exe will at >> least let you see if there are any errors. >> > python.exe from the command line works all right in a DOS window. The > problem must be with idle.pyw. I tried the old idle.pyw (2.4) with the > new python.exe. (2.5) and that didn't work either. > What is the bit bucket? If I had a clue, I could go from there. What > puzzles me is that version 2.4 has been working fine and one wouldn't > think that the changes from 2.4 to 2.5 would be so extensive as to cause > a major malfunction. For the time being 2.4 works fine. I'd much prefer > 2.5, though, because it includes the image library (PIL), whereas 2.4 > cannot even use it. Bit bucket: http://en.wikipedia.org/wiki/Bit_bucket If you are seeing nothing at all when running it with python.exe instead of pythonw.exe then something bizarre must be happening. My guess would have been that you had a problem importing something: e.g. if Tkinter isn't installed properly then running Idle under pythonw.exe would exit with an error message but you wouldn't see the error message. However since you don't see an error message when running it with python.exe it isn't that. Sorry, I'm out of ideas for now. -- Duncan Booth http://kupuguy.blogspot.com From mrkafk at gmail.com Fri Feb 5 09:21:05 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 15:21:05 +0100 Subject: which Message-ID: if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) else: self.cmd = cmd or self.cmd = cmd if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) From pecora at anvil.nrl.navy.mil Fri Feb 5 09:22:03 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Fri, 05 Feb 2010 09:22:03 -0500 Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> Message-ID: In article <00f4bb3a$0$15566$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 04 Feb 2010 09:57:59 -0500, Lou Pecora wrote: > > > Well, that looks a bit more complicated than I would like, but maybe > > it's doing more stuff than I can grok. Here's what I needed and how I > > did it in Python: > [...] > > # Reading same list in: > > instr=fp.readline() > > inlist=eval(instr) > > x1,y1,astr1,z1= inlist > > > > > > That's what I needed. 3 lines to write or read a inhomogeneous > > collection of variables. > > Easy, but also quick and dirty -- good enough for small scripts, but not > really good enough for production applications. > > > > I can add more variables, shuffle the order, > > whatever without messing with formatting, etc. > > This is nice and easy. But there are at least four catches: > > > * you can't safely treat the data file as human-editable > (although a sufficiently careful and Python-aware user could edit it) > > * you can't use any data that isn't a built-in, or that contains > something that is not a built-in > > * there may be reliability issues with floats - you're at the mercy of > changes to the underlying repr of float objects, and it almost certainly > will blow up in your face if you get an inf or nan (at least prior to > Python 2.6) > > * you're using eval, which is a security risk if you can't trust the > source of the data file. > > However, be aware that neither marshal nor pickle guarantees to be safe > against malicious data either. The docs for both warn against using them > on untrusted data. YAML or JSON *might* be safer, I haven't looked. I understand where you are coming from: Production Code. I was just making a point about Python and my code is only used by me. I can edit the file for the simple I/O I do. I am not recommending this way for everyone. Just an example. -- -- Lou Pecora From gdementen at gmail.com Fri Feb 5 09:25:02 2010 From: gdementen at gmail.com (Gaetan de Menten) Date: Fri, 5 Feb 2010 15:25:02 +0100 Subject: Pickling an extension type subclasses problems Message-ID: Hi all, I am trying to write an (optional!) C extension for SQLAlchemy, and I am struggling to make an extension type picklable *and* using the same format as the pure Python version (so that computers with the C extension can unpickle pickles from computers without it and vice-versa). Also the extension type (MyBase in the example code below) only serves as a base class for the type that get pickled (MyPythonType). MyPythonType also has further subclasses and those should be picklable too. My setup is as follow: On the Python side: ================ try: from cextension import MyBase except ImportError: class MyBase(object): __slots__ = ('a', 'b', 'c') def __init__(self, a, b, c): self.a, self.b, self.c = a, b, c def __getstate__(self): ... def __setstate__(self, state): ... ... class MyPythonType(MyBase): ... On the .c side: =========== I implemented a reduce method, which returns Py_BuildValue("(O(s)N)", Py_TYPE(self), "__state__", state); and in my BaseRowProxy_init method, I check the number of arguments, whether the "__state__" marker is present and unpack the state if it is. This makes the type nicely pickleable, but this is obviously not the same "pickle format" as the Python version. What would you recommend in this kind of situation? I'm a bit tired of trial and error... My last hope is to define __reduce__ on the Python side too, and make it use a module-level "reconstructor" function as follow: def mypythontype_reconstructor(cls, state): obj = object.__new__(cls, state): .... return obj Will this work? Any other idea? Thanks in advance, -- Ga?tan de Menten From killy.draw at gmail.com Fri Feb 5 09:25:05 2010 From: killy.draw at gmail.com (KDr2) Date: Fri, 5 Feb 2010 22:25:05 +0800 Subject: which In-Reply-To: References: Message-ID: <2eebcba81002050625s28b4a51dj5e67bf182601c2c4@mail.gmail.com> cmd= isinstance(cmd,str) and c.replace('${ADDR}',ip) or cmd Best Regards, -- KDr2 http://kdr2.net On Fri, Feb 5, 2010 at 10:21 PM, mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Feb 5 09:30:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 09:30:11 -0500 Subject: which In-Reply-To: References: Message-ID: mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > My own preference is for the latter, but I am sure you will find that opinions are mixed on this. In recent versions of Python you might want to take the possibility that cmd is Unicode into account by using id isinstance(cmd, basestring): regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tgrav at me.com Fri Feb 5 09:31:02 2010 From: tgrav at me.com (Tommy Grav) Date: Fri, 05 Feb 2010 09:31:02 -0500 Subject: ANN: ActivePython 2.6.4.10 is now available In-Reply-To: References: Message-ID: On Feb 5, 2010, at 12:01 AM, Sridhar Ratnakumar wrote: > I'm happy to announce that ActivePython 2.6.4.10 is now available for download from: > On what platforms does ActivePython run? > ---------------------------------------- > > ActivePython includes installers for the following platforms: > > - Windows/x86 > - Windows/x64 (aka "AMD64") > - Mac OS X Is the Mac OS X version still only 32 bit? If so does ActiveState plan to make binaries for 64bit builds for Snow Leopard? Cheers Tommy -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 5 09:41:34 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 15:41:34 +0100 Subject: which In-Reply-To: References: Message-ID: <4B6C2E1E.7000201@sequans.com> mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > I would vote for the first one. But I could use the second as well, I would'nt fight for it. What is worrying me the most in your code sample is that self.cmd can hold diferrent types (str, and something else). That is usually a bad thing to do (putting None aside). However, my remark could be totally irrelevant of course, that depends on the context. JM From jeanmichel at sequans.com Fri Feb 5 09:42:44 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 15:42:44 +0100 Subject: Your beloved python features In-Reply-To: <4b6c20eb$0$22370$426a74cc@news.free.fr> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c20eb$0$22370$426a74cc@news.free.fr> Message-ID: <4B6C2E64.2080205@sequans.com> Bruno Desthuilliers wrote: > Julian a ?crit : >> Hello, >> >> I've asked this question at stackoverflow a few weeks ago, and to make >> it clear: this should NOT be a copy of the stackoverflow-thread >> "hidden features of Python". >> >> I want to design a poster for an open source conference, the local >> usergroup will have a table there, and in the past years there were >> some people that came to the python-table just to ask "why should I >> use python?". >> >> For those guys would be a poster quite cool which describes the most >> popular and beloved python features. > > My all-time favorite Python feature : it fits my brain. Python is simple ... no offense Bruno :D JM (sorry couldn't help) From bradallen137 at gmail.com Fri Feb 5 09:57:18 2010 From: bradallen137 at gmail.com (bradallen) Date: Fri, 5 Feb 2010 06:57:18 -0800 (PST) Subject: method to intercept string formatting % operations Message-ID: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Hello, For container class derived from namedtuple, but which also behaves like a dictionary by implementing __getitem__ for non-integer index values, is there a special reserved method which allows intercepting % string formatting operations? I would like for my container type to behave appropriately depending on whether the string formatting operation has a string like this : "whatever %s yadayada" % mycontainer # needs to act like a tuple "whatever %(key)s yadayada" % mycontainer # needs to act like a dictionary I looked through the Python data model docs at but only found this: "If the left operand of a % operator is a string or Unicode object, no coercion takes place and the string formatting operation is invoked instead." Thanks! From mrkafk at gmail.com Fri Feb 5 10:15:59 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:15:59 +0100 Subject: which In-Reply-To: <4B6C2E1E.7000201@sequans.com> References: <4B6C2E1E.7000201@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > > What is worrying me the most in your code sample is that self.cmd can > hold diferrent types (str, and something else). That is usually a bad > thing to do (putting None aside). > However, my remark could be totally irrelevant of course, that depends > on the context. That's a valid criticism - but I do not know how to handle this otherwise really, because the program can be called with "cmd" to run, or a script to run (or a directory to copy) and in those cases cmd is None. I guess I could use if cmd: self.cmd = ... But. Suppose that under some circumstances cmd is not string. What then? I know that isinstance is typically not recommended, but I don't see better solution here. Regards, mk From mrkafk at gmail.com Fri Feb 5 10:21:30 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:21:30 +0100 Subject: which In-Reply-To: <2eebcba81002050625s28b4a51dj5e67bf182601c2c4@mail.gmail.com> References: <2eebcba81002050625s28b4a51dj5e67bf182601c2c4@mail.gmail.com> Message-ID: KDr2 wrote: > cmd= isinstance(cmd,str) and c.replace('${ADDR}',ip) or cmd Perlish, but I like that. :-) Regards, mk From invalid at invalid.invalid Fri Feb 5 10:24:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Feb 2010 15:24:04 +0000 (UTC) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: On 2010-02-04, Julian wrote: > I've asked this question at stackoverflow a few weeks ago, and > to make it clear: this should NOT be a copy of the > stackoverflow-thread "hidden features of Python". > > I want to design a poster for an open source conference, the > local usergroup will have a table there, and in the past years > there were some people that came to the python-table just to > ask "why should I use python?". > > For those guys would be a poster quite cool which describes > the most popular and beloved python features. In the fine old tradition: Python: It sucks less. A lot less. -- Grant Edwards grante Yow! You should all JUMP at UP AND DOWN for TWO HOURS visi.com while I decide on a NEW CAREER!! From mrkafk at gmail.com Fri Feb 5 10:25:42 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:25:42 +0100 Subject: Terminating threaded programs Message-ID: Hello everyone, I have a problem with a threaded program: it frequently hangs on sys.exit. The problem is that my program uses threads which in turn use paramiko library, which itself is threaded. I try to gracefully close the threads (below), but it doesn't always work, if paramiko calls happen to be at stage of negotiating ssh connection or smth similar. The only workable solution I have is a program sending itself SIGKILL, which makes it terminated by OS (I think so). Is there any way to brutally close the threads? I know that normally that should not be done, but shutdown when you don't care about writing out to disk is the only situation where it doesn't apply. def ctrlchandler(signal, frame): print print ENDC + "Terminating on Ctrl-C, closing threads for:", while queue: for ip, th in queue: print ip, try: lock.acquire() th.abort = True lock.release() except RuntimeError: pass queue.remove((ip,th)) print pid = os.getpid() print "Finished closing threads." # suicide - it's the only way of preventing frequent hangup on sys.exit os.kill(pid, SIGTERM) os.kill(pid, SIGKILL) sys.exit(0) From jeanmichel at sequans.com Fri Feb 5 10:28:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 16:28:25 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> Message-ID: <4B6C3919.3050300@sequans.com> mk wrote: > Jean-Michel Pichavant wrote: >> >> What is worrying me the most in your code sample is that self.cmd can >> hold diferrent types (str, and something else). That is usually a bad >> thing to do (putting None aside). >> However, my remark could be totally irrelevant of course, that >> depends on the context. > > That's a valid criticism - but I do not know how to handle this > otherwise really, because the program can be called with "cmd" to run, > or a script to run (or a directory to copy) and in those cases cmd is > None. > > I guess I could use > > if cmd: > self.cmd = ... > > > But. Suppose that under some circumstances cmd is not string. What then? > > I know that isinstance is typically not recommended, but I don't see > better solution here. > > > Regards, > mk > > If you can change your program interface, then do it, if not then you're right you don't have much choice as you are suffering from the program poor interface. You can fix this problem by explicitly asking for the thing you want to do, instead of guessing by inspecting the argument nature. myProg --help usage : myProg command [args] command list: - cmd: execute the given command line - exec: execute the given script file named - copy: copy to example: >myProg cmd "echo that's cool" >myProg exec /etc/init.d/myDaemon >myProg copy /tmp /tmp2 JM From wolftracks at invalid.com Fri Feb 5 10:39:48 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 07:39:48 -0800 Subject: Drawing a zig-zag Trail in Python? Message-ID: I'd like to draw something like an animal track. Between each point is a line. Perhaps the line would have an arrow showing the direction of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? From jjposner at optimum.net Fri Feb 5 10:42:13 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 10:42:13 -0500 Subject: which In-Reply-To: References: Message-ID: <4B6C3C55.5040907@optimum.net> On 2/5/2010 9:21 AM, mk wrote: > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > > (lunatic fringe?) Last August [1], I offered this alternative: self.cmd = (cmd.replace(r'${ADDR}',ip) if isinstance(cmd, str) else cmd) But it didn't get much love in this forum! [1] http://groups.google.com/group/comp.lang.python/browse_thread/thread/6876917a4d579d59/1f700586f4c4614d?lnk=gst&q=Posner#1f700586f4c4614d From jeanmichel at sequans.com Fri Feb 5 10:49:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 16:49:00 +0100 Subject: method to intercept string formatting % operations In-Reply-To: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Message-ID: <4B6C3DEC.9030109@sequans.com> bradallen wrote: > Hello, > > For container class derived from namedtuple, but which also behaves > like a dictionary by implementing __getitem__ for non-integer index > values, is there a special reserved method which allows intercepting % > string formatting operations? I would like for my container type to > behave appropriately depending on whether the string formatting > operation has a string like this : > > "whatever %s yadayada" % mycontainer # needs to act like a tuple > > "whatever %(key)s yadayada" % mycontainer # needs to act like a > dictionary > > I looked through the Python data model docs at reference/datamodel.html#emulating-container-types> but only found > this: > > "If the left operand of a % operator is a string or Unicode object, no > coercion takes place and the string formatting operation is invoked > instead." > > Thanks! > > class toto: def __getitem__(self, key): return 'paf' def __str__(self): return 'pif' def toTuple(self): return (1,2,3) 1/ print '%s %s %s' % toto().toTuple() '1 2 3' 2/ print '%(key)s ' % toto() 'paf' 3/ print '%s' % toto() 'pif' 1/ I don't know how to spare the explicit toTuple conversion, supporting tuple() would be tedious 2/ thanks to __getitem__ (duck typing) 3/ thanks to __str__ Anyway why would you want to use the tuple form ? it's beaten in every aspect by the dictionary form. JM "If you need something call me, I'll tell you how to live without it" (Coluche, about politicians) From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 10:49:08 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 16:49:08 +0100 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c20eb$0$22370$426a74cc@news.free.fr> Message-ID: <4b6c3df3$0$23914$426a74cc@news.free.fr> Jean-Michel Pichavant a ?crit : > Bruno Desthuilliers wrote: >> >> My all-time favorite Python feature : it fits my brain. > Python is simple ... no offense Bruno :D !-) But FWIW, that's exactly the point : even a stoopid like me can manage to learn and use Python, and proceed to write working apps without spending more time reading the doc than actually solving the problem. From __peter__ at web.de Fri Feb 5 10:49:22 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 05 Feb 2010 16:49:22 +0100 Subject: which References: Message-ID: mk wrote: > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) Neither. self.cmd = cmd self.ip = ip ... subprocess.call(self.cmd, shell=True, env=dict(ADDR=self.ip)) Please spend a bit more energy on a descriptive subject and an unambiguous exposition of your problem (in English rather than code) next time. Peter From mrkafk at gmail.com Fri Feb 5 10:52:19 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 16:52:19 +0100 Subject: which In-Reply-To: <4B6C3919.3050300@sequans.com> References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > If you can change your program interface, then do it, if not then you're > right you don't have much choice as you are suffering from the program > poor interface. > You can fix this problem by explicitly asking for the thing you want to > do, instead of guessing by inspecting the argument nature. > > myProg --help > > usage : myProg command [args] > command list: > - cmd: execute the given command line > - exec: execute the given script file named > - copy: copy to > > example: > >myProg cmd "echo that's cool" > >myProg exec /etc/init.d/myDaemon > >myProg copy /tmp /tmp2 > I sure can change the interface since I'm the author of the entire program. But I don't see how I can arrange program in a different way: the program is supposed to be called with -c parameter (command to run), -s script to run, or -y file_or_dir_to_copy. Then, I start instances of SSHThread class to do precisely that, separately for each ip/hostname: class SSHThread(threading.Thread): def __init__(self, lock, cmd, ip, username, sshprivkey=None, passw=None, port=22, script=None, remotedir=None): threading.Thread.__init__(self) self.lock = lock if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) else: self.cmd = cmd self.ip = ip self.username = username self.sshprivkey = sshprivkey self.passw = passw self.port = port self.conobj = None self.conerror = '' self.msgstr = '' self.confailed = True if script: self.setpathinfo(script, remotedir=remotedir) self.sentbytes = 0 self.finished = False self.abort = False It gets called like this: th = SSHThread(lock, opts.cmd, ip, username=username, sshprivkey=opts.key, passw=passw, port=port, script=opts.script, remotedir=opts.remotedir) ..where all the options are parsed by ConfigParser.OptionParser(). So they are either strings, or Nones. So in this context this is fine. But I wanted to make the class more robust. Perhaps I should do smth like this before setting self.cmd? assert isinstance(cmd, basestring) or cmd is None, "cmd should be string or None" and then: if cmd: self.cmd = cmd.replace.. ? Entire source code is here: http://python.domeny.com/cssh.py regards, mk From dthole at gmail.com Fri Feb 5 10:53:33 2010 From: dthole at gmail.com (David Thole) Date: Fri, 05 Feb 2010 09:53:33 -0600 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: I read this....and am a tiny bit confused about the actual problem. It's not exactly complex to realize that something like: a = b = array that a and b both point to the array. Logically speaking, I'm not sure how one could assume that the same assignment would yield a and b point to the same duplicate array. If that was the case, why not do: a = array.. b = array.. I know with what you were complaining about a few days ago, .clear makes perfect sense. If a and b point to the same array, clear should clear both arrays. Again, if you didn't want that to happen, create a duplicate array. Personally I feel that this complexity doesn't hamper programming process, and yes while its good for efficiency it also just makes sense. Also, I wouldn't look at PHP on the right way to do something programming wise. I have ~5 years experience in this language, and I dislike it a whole lot. There's a lot of things it should do right that it doesn't out of convenience. -David www.thedarktrumpet.com From jeanmichel at sequans.com Fri Feb 5 10:54:18 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 16:54:18 +0100 Subject: which In-Reply-To: <4B6C3C55.5040907@optimum.net> References: <4B6C3C55.5040907@optimum.net> Message-ID: <4B6C3F2A.1070108@sequans.com> John Posner wrote: > On 2/5/2010 9:21 AM, mk wrote: >> >> if isinstance(cmd, str): >> self.cmd = cmd.replace(r'${ADDR}',ip) >> else: >> self.cmd = cmd >> >> or >> >> self.cmd = cmd >> if isinstance(cmd, str): >> self.cmd = cmd.replace(r'${ADDR}',ip) >> >> > > (lunatic fringe?) > > Last August [1], I offered this alternative: > > self.cmd = (cmd.replace(r'${ADDR}',ip) > if isinstance(cmd, str) else > cmd) > > But it didn't get much love in this forum! > > > [1] > http://groups.google.com/group/comp.lang.python/browse_thread/thread/6876917a4d579d59/1f700586f4c4614d?lnk=gst&q=Posner#1f700586f4c4614d > Heresy ! JM From aahz at pythoncraft.com Fri Feb 5 10:55:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2010 07:55:17 -0800 Subject: list.extend([]) Question References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> Message-ID: In article <088e7a24-b0d0-4d43-bee7-193e5eaefe57 at b7g2000pro.googlegroups.com>, Dan Brown wrote: > >Why does extending a list with the empty list result in None? It >seems very counterintuitive to me, at least --- I expected ['a'].extend >([]) to result in ['a'], not None. http://www.python.org/doc/faq/general/#why-doesn-t-list-sort-return-the-sorted-list -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 11:02:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 17:02:37 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: <4b6c411b$0$20638$426a74cc@news.free.fr> mk a ?crit : (snip) > So in this context this is fine. But I wanted to make the class more > robust. Perhaps I should do smth like this before setting self.cmd? > > assert isinstance(cmd, basestring) or cmd is None, "cmd should be string > or None" > > and then: > > if cmd: > self.cmd = cmd.replace.. And what if cmd happens to be the empty string ?-) ok, me --->[] From jeanmichel at sequans.com Fri Feb 5 11:03:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 17:03:28 +0100 Subject: xmlrcp - how to marshall objects Message-ID: <4B6C4150.8050705@sequans.com> Deos anyone knows where to find an code sample describing how to implement the interface to marshall one object into XMLRPC compliant structures ? I googled without any success, and what google does not find does not exist. Let say I have this very simple class: class Point: def __init__(self, x, y): self.x = x self.y = y I've looked into xmlrpc code, I see 2 options: 1/ override the Marshaller class of client and server 2/ looks like the lib is supporting a WRAPPER list system, it uses to Marshall Datetime & Binary object. Can it be possible to add its own class (could require to emplement the 'encode' method) I sense I will spend much more time than required unless someone is pointing me in the right direction. JM From gerald.britton at gmail.com Fri Feb 5 11:06:52 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 11:06:52 -0500 Subject: which In-Reply-To: <4B6C3C55.5040907@optimum.net> References: <4B6C3C55.5040907@optimum.net> Message-ID: <5d1a32001002050806n207d7784p144819c8af4c57cb@mail.gmail.com> [snip] > Last August [1], I offered this alternative: > > ?self.cmd = (cmd.replace(r'${ADDR}',ip) > ? ? ? ? ? ? ?if isinstance(cmd, str) else > ? ? ? ? ? ? ?cmd) > > But it didn't get much love in this forum! I'd probably go for that one as well though I might consider removing the outer parentheses. -- Gerald Britton From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 11:07:52 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 17:07:52 +0100 Subject: which In-Reply-To: References: Message-ID: <4b6c4256$0$21794$426a74cc@news.free.fr> mk a ?crit : > > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd What could "cmd" be except a string ? From other posts here, I guess it's either a string or None ? If yes, then I'd go for this: if cmd: cmd = cmd.replace(r'${ADDR}',ip) self.cmd = cmd From wolftracks at invalid.com Fri Feb 5 11:17:15 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 08:17:15 -0800 Subject: How Uninstall MatPlotLib? Message-ID: See Subject. From andrew.degtiariov at gmail.com Fri Feb 5 11:21:47 2010 From: andrew.degtiariov at gmail.com (Andrew Degtiariov) Date: Fri, 5 Feb 2010 18:21:47 +0200 Subject: Import question Message-ID: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> Code of our project has split into several packages and we deploy the project using buildout. All worked fine until I need to dynamically inspect python modules. Here is structure of our src directory ????project.api.config ? ????project ? ? ????api ? ? ????config ? ? ????settings ? ????project.api.config.egg-info ????project.api.contacts ? ????project ? ? ????api ? ? ????contacts ? ? ????importer ? ? ????views ? ????project.api.contacts.egg-info ????project.api.core ? ????project ? ? ????api ? ? ????core ? ? ????js ? ? ????lib ? ? ????management ? ? ? ????commands ? ? ????middleware ? ? ????sessions ? ? ????users ? ????project.api.core.egg-info Buildout by itself generates bin/python which look like: import sys sys.path[0:0] = [ 'c:\\users\\ad\\project\\src\\project.api.core', 'c:\\users\\ad\\project\\src\\project.api.config', 'c:\\users\\ad\\project\\src\\project.api.contacts', 'c:\\users\\ad\\project\\eggs\\lockfile-0.8-py2.6.egg', 'c:\\users\\ad\\project\\parts\\django', 'c:\\users\\ad\\project\\eggs\\web.py-0.33-py2.6.egg', .... Regular code like "import project.api.config" worked fine, but now I'm tryed __import__('project.api.config'): $ bin/python >>> import project.api.config >>> __import__('project.api.config') >>> What's wrong? Ok, I'm trying imp: >>> import imp >>> imp.find_module('project.api.config') Traceback (most recent call last): File "", line 1, in ImportError: No module named project.api.config >>> import sys >>> sys.path[1] 'c:\\users\\ad\\project\\src\\project.api.config' >>> imp.find_module('project.api.config', sys.path[1]) Traceback (most recent call last): File "", line 1, in ImportError: No frozen submodule named c:\users\ad\project\src\project.api.config.project.api.config >>> There is setup.py for project.api.config: import os from setuptools import setup, find_packages name = "project.api.config" install_requires = [ 'zc.buildout', 'setuptools', 'web.py>=0.33', 'project.api.core', 'Django>=1.1.0', 'lockfile' ] if sys.platform != 'win32': install_requires.append('python-daemon') setup( name = name, version = "1.0", author = "Andrew Degtiariov", author_email = "andrew.degtiariov at gmail.com", description = "...", license = "Commercial", packages=find_packages(os.path.dirname(__file__), exclude=['ez_setup']), namespace_packages=['project, 'project.api'], include_package_data=True, zip_safe=False, install_requires = install_requires ) What's wrong? We really need to split the code for several eggs and want that all of our package's names starts from 'project.api' -- Andrew Degtiariov DA-RIPE -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Fri Feb 5 11:22:56 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 11:22:56 -0500 Subject: which In-Reply-To: References: <4B6C3C55.5040907@optimum.net> Message-ID: <4B6C45E0.1000309@optimum.net> On 2/5/2010 11:06 AM, Gerald Britton wrote: > [snip] > >> Last August [1], I offered this alternative: >> >> self.cmd = (cmd.replace(r'${ADDR}',ip) >> if isinstance(cmd, str) else >> cmd) >> >> But it didn't get much love in this forum! > > I'd probably go for that one as well though I might consider removing > the outer parentheses. Agreed ... except that you *need* the outer parentheses if the statement occupies multiple source lines. -John From aahz at pythoncraft.com Fri Feb 5 11:23:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2010 08:23:57 -0800 Subject: Wrap a function References: <38336c6d-c82d-4b83-96c9-5f1210132027@l19g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On 4 Feb 2010 16:18:04 -0800, aahz at pythoncraft.com (Aahz) declaimed the >following in gmane.comp.python.general: >> >> But in bash scripting, you'd just use rsync or cp or rm -- maybe an >> example would make clearer how REXX differs from bash. > > I suspect the only really good examples would have to written under >OS/VMS (where it originated, written to be a more powerful & friendlier >replacement for the EXEC scripting language) or AmigaOS -- to >demonstrate the switching interaction of command handlers. REXX >implementations for Windows and Linux pretty much only support the >"shell" as a command handler, whereas the two named OS could address >editors (and on the Amiga, word processors, desktop publishing programs, >terminal emulators/comm programs, system editor). > > My Amiga's been in storage since Win95 days, so this is a fictitious >example based on the reference manuals. > >address command /* use normal command shell to process commands */ >file = 'some.file' >'run ed' file /* start ED editor in background, editing 'file'*/ >address ED /* send commands to the ED instance */ >'b' /* go to bottom of file */ >'i /text to be inserted before bottom line/' >'t' /* to to top */ >'a /text inserted after first line/' >find = 'needle' >replace = 'thorn' >'rpe /' || find || '/' || replace '/' >'x' /* save & exit */ >address command >'type' file /* type file to screen */ >'filenote' file "edited via AREXX script" IOW, kinda like AppleScript? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From mrkafk at gmail.com Fri Feb 5 11:27:35 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 17:27:35 +0100 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: References: Message-ID: W. eWatson wrote: > I'd like to draw something like an animal track. Between each point is a > line. Perhaps the line would have an arrow showing the direction of > motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? Pycairo? From jarausch at skynet.be Fri Feb 5 11:31:08 2010 From: jarausch at skynet.be (Helmut Jarausch) Date: Fri, 05 Feb 2010 17:31:08 +0100 Subject: Repost: Read a running process output In-Reply-To: References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> <87aavnnans.fsf@dpt-info.u-strasbg.fr> <41180c75-38df-4950-8b4e-aad574f98ded@k36g2000prb.googlegroups.com> <87636bn8jw.fsf@dpt-info.u-strasbg.fr> <4ae7195a-d3ec-4886-9123-de88641aa797@g8g2000pri.googlegroups.com> Message-ID: <4b6c47cb$0$2865$ba620e4c@news.skynet.be> On 02/05/10 14:39, Ashok Prabhu wrote: > On Feb 5, 6:33 pm, Ashok Prabhu wrote: >> On Feb 5, 5:58 pm, Alain Ketterlin >> wrote: >> >> >> >>> Ashok Prabhu writes: >>>>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) >> >>>>> Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell. >> >>>>> -- Alain. >>>> Thanks for the response. However it throws an error. Please find >>>> below. >> >>>>>>> from subprocess import * >>>>>>> p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE) >> >>> You forgot to change the monolithic command into a list of words. Since >>> you don't use the shell anymore you have to give Popen a pre-parsed >>> command line. >> >>> -- Alain. >> >> Here is the error again >> >>>>> p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE) >> >> Traceback (most recent call last): >> File "", line 1, in ? >> File "/usr/lib/python2.4/subprocess.py", line 494, in __init__ >> raise TypeError("bufsize must be an integer") >> TypeError: bufsize must be an integer >> >> ~Ashok. > > Oops i missed the braces. But still no output. > > >>>> p1=Popen(['/usr/sunvts/bin/64/vtsk','-d'],stdout=PIPE) >>>> while 1: > ... a=p1.stdout.readline() > ... print a > ... I've tried #!/usr/bin/python import subprocess p1= subprocess.Popen(['/bin/ls','/LOCAL/'],stdout=subprocess.PIPE) for line in p1.stdout : print ">>>",line which works just fine. Are you sure, your /usr/sunvts/bin/64/vtsk writes a newline character (readline is waiting for that)? Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From gerald.britton at gmail.com Fri Feb 5 11:31:52 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 11:31:52 -0500 Subject: list.extend([]) Question In-Reply-To: References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> Message-ID: <5d1a32001002050831r6233b751mcbc5f55fb9a2c1b4@mail.gmail.com> I think it's because when you do ['a'].extend([]) or whatever, the result is whatever the method "extend" returns. But "extend" has no return value, hence you will see None if you do this interactively. On Fri, Feb 5, 2010 at 10:55 AM, Aahz wrote: > In article <088e7a24-b0d0-4d43-bee7-193e5eaefe57 at b7g2000pro.googlegroups.com>, > Dan Brown ? wrote: >> >>Why does extending a list with the empty list result in None? ?It >>seems very counterintuitive to me, at least --- I expected ['a'].extend >>([]) to result in ['a'], not None. > > http://www.python.org/doc/faq/general/#why-doesn-t-list-sort-return-the-sorted-list > -- > Aahz (aahz at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ? http://www.pythoncraft.com/ > > import antigravity > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From mrkafk at gmail.com Fri Feb 5 11:34:13 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 17:34:13 +0100 Subject: which In-Reply-To: <4b6c411b$0$20638$426a74cc@news.free.fr> References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> <4b6c411b$0$20638$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> if cmd: >> self.cmd = cmd.replace.. > > And what if cmd happens to be the empty string ?-) > > ok, me --->[] Right, I didn't think much when I wrote that. Anyway, that's back to square one. I will probably go for this anyway: assert isinstance(cmd, basestring) or cmd is None, 'cmd has to be string or None' if cmd: cmd = cmd.replace(r'${ADDR}',ip) self.cmd = cmd From jeanmichel at sequans.com Fri Feb 5 11:40:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 17:40:38 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: <4B6C4A06.6010700@sequans.com> mk wrote: > Jean-Michel Pichavant wrote: >> If you can change your program interface, then do it, if not then >> you're right you don't have much choice as you are suffering from the >> program poor interface. >> You can fix this problem by explicitly asking for the thing you want >> to do, instead of guessing by inspecting the argument nature. >> >> myProg --help >> >> usage : myProg command [args] >> command list: >> - cmd: execute the given command line >> - exec: execute the given script file named >> - copy: copy to >> >> example: >> >myProg cmd "echo that's cool" >> >myProg exec /etc/init.d/myDaemon >> >myProg copy /tmp /tmp2 >> > > I sure can change the interface since I'm the author of the entire > program. But I don't see how I can arrange program in a different way: > the program is supposed to be called with -c parameter (command to > run), -s script to run, or -y file_or_dir_to_copy. > > Then, I start instances of SSHThread class to do precisely that, > separately for each ip/hostname: > > > class SSHThread(threading.Thread): > def __init__(self, lock, cmd, ip, username, sshprivkey=None, > passw=None, port=22, script=None, remotedir=None): > > threading.Thread.__init__(self) > > self.lock = lock > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > self.ip = ip > self.username = username > self.sshprivkey = sshprivkey > self.passw = passw > self.port = port > self.conobj = None > self.conerror = '' > self.msgstr = '' > self.confailed = True > if script: > self.setpathinfo(script, remotedir=remotedir) > self.sentbytes = 0 > self.finished = False > self.abort = False > > It gets called like this: > > th = SSHThread(lock, opts.cmd, ip, username=username, > sshprivkey=opts.key, passw=passw, port=port, script=opts.script, > remotedir=opts.remotedir) > > > ..where all the options are parsed by ConfigParser.OptionParser(). So > they are either strings, or Nones. > > So in this context this is fine. But I wanted to make the class more > robust. Perhaps I should do smth like this before setting self.cmd? > > assert isinstance(cmd, basestring) or cmd is None, "cmd should be > string or None" > > and then: > > if cmd: > self.cmd = cmd.replace.. > > > ? > > Entire source code is here: > > http://python.domeny.com/cssh.py > > regards, > mk > To be honest I have not enough courrage to dive into yout 1000 lines of script :-) What I can say however: 1/ your interface is somehow broken. You ask actions through options (-c -y -s), meaning one can possibly use all these 3 options together. Your code won't handle it (you are using elif statements). What happens if I use no option at all ? As the the optparse doc states : if an option is not optional, then it is not an option (it's a positional argument). 2/ executing a script, or copying a directory are both commands as well. myProg -s /tmp/myscript.sh is nothing more than myProg -c '/bin/sh myscript.sh' myProg -y file1 is nothing more than myProg -c 'cp file1 towhatever' 3/ check your user parameters before creating your SSHThread, and create your SSHThread with already validated parameters. You don't want to pollute you SSHThread code with irrelevant user error check. my humble conclusion: 1/ rewrite your interface with prog command args [options] 2/ Simplify your SSHThread by handling only shell commands 3/ at the CLI level (right after parameter validation), mute you copy & script command to a shell command and pass it to SSHThread. Cheers, JM From jeanmichel at sequans.com Fri Feb 5 11:42:43 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 17:42:43 +0100 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: References: Message-ID: <4B6C4A83.7080802@sequans.com> mk wrote: > W. eWatson wrote: >> I'd like to draw something like an animal track. Between each point >> is a line. Perhaps the line would have an arrow showing the direction >> of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? > > Pycairo? > turtle http://docs.python.org/library/turtle.html From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 5 11:44:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 05 Feb 2010 17:44:02 +0100 Subject: list.extend([]) Question In-Reply-To: References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> Message-ID: <4b6c4ad0$0$23943$426a74cc@news.free.fr> Gerald Britton a ?crit : > I think it's because when you do ['a'].extend([]) or whatever, the > result is whatever the method "extend" returns. But "extend" has no > return value It does : it returns None. From jurgenex at hotmail.com Fri Feb 5 11:48:29 2010 From: jurgenex at hotmail.com (Jürgen Exner) Date: Fri, 05 Feb 2010 08:48:29 -0800 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: David Thole wrote in comp.lang.perl.misc: >I read this....and am a tiny bit confused about the actual problem. > >It's not exactly complex to realize that something like: >a = b = array >that a and b both point to the array. ??? What are you talking about? First of all you should post actual code, not pseudo-code because pseudo-code leads to misunderstandings. Did you mean @a = @b = @array Second what do you mean by "pointing"? That is a very ambiguous term. if you do the assignment as written above then @a and @b will be _copies_ of @array. If you want two additional references to the same array insted then you have to create that reference first and assign that reference to $a and $b instead of copying the array, see "perldoc perlref" for details. And remember, references are scalars, no matter if they reference other scalars or arrays. >Logically speaking, I'm not sure how one could assume that the same >assignment would yield a and b point to the same duplicate array. If Now what? The same array or a duplicate array? Two very different and mutually exclusive things. >that was the case, why not do: >a = array.. >b = array.. Which, after correcting the obvious syntax errors is the same as the code above. >I know with what you were complaining about a few days ago, .clear makes >perfect sense. If a and b point to the same array, clear should clear They don't point, they are copies. And what do you mean by "clear"? >both arrays. Again, if you didn't want that to happen, create a >duplicate array. But that is what that code above does. If you want references then create references. jue From sridharr at activestate.com Fri Feb 5 11:50:10 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Fri, 5 Feb 2010 08:50:10 -0800 Subject: ANN: ActivePython 2.6.4.10 is now available In-Reply-To: References: Message-ID: <7E38E471-25C3-49C9-B27F-2D4F0B355290@activestate.com> On 2010-02-05, at 6:31 AM, Tommy Grav wrote: > > On Feb 5, 2010, at 12:01 AM, Sridhar Ratnakumar wrote: > >> I'm happy to announce that ActivePython 2.6.4.10 is now available for download from: > >> On what platforms does ActivePython run? >> ---------------------------------------- >> >> ActivePython includes installers for the following platforms: >> >> - Windows/x86 >> - Windows/x64 (aka "AMD64") >> - Mac OS X > > Is the Mac OS X version still only 32 bit? Yes. > If so does ActiveState plan to make binaries for 64bit builds > for Snow Leopard? No concrete plans yet, but we do intend to make 64 bit for Mac available eventually. -srid -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Fri Feb 5 11:51:31 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 11:51:31 -0500 Subject: which In-Reply-To: <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> References: <4B6C3C55.5040907@optimum.net> <4B6C45E0.1000309@optimum.net> <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> Message-ID: <4B6C4C93.3050602@optimum.net> On 2/5/2010 11:26 AM, Gerald Britton wrote: > sure, but it will fit nicely on one line if you like > > On Fri, Feb 5, 2010 at 11:22 AM, John Posner wrote: > >> On 2/5/2010 11:06 AM, Gerald Britton wrote: >> >>> [snip] >>> >>> >>>> Last August [1], I offered this alternative: >>>> >>>> self.cmd = (cmd.replace(r'${ADDR}',ip) >>>> if isinstance(cmd, str) else >>>> cmd) >>>> >>>> But it didn't get much love in this forum! >>>> >>> I'd probably go for that one as well though I might consider removing >>> the outer parentheses. >>> >> Agreed ... except that you *need* the outer parentheses if the statement >> occupies multiple source lines. >> >> -John >> >> >> >> > > > Did you mean to take this off-list? Also, I'm contractually obligated to admonish you not to "top post". At any rate, I proposed the 3-line format specifically because it separates the data values from the if-then-else machinery, making it easier (for me) to read. But there was considerable resistance to spending so much vertical space in the source code. -John From awilliam at opengroupware.us Fri Feb 5 11:52:57 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Fri, 05 Feb 2010 11:52:57 -0500 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C4150.8050705@sequans.com> References: <4B6C4150.8050705@sequans.com> Message-ID: <1265388777.3112.7.camel@linux-m3mt> On Fri, 2010-02-05 at 17:03 +0100, Jean-Michel Pichavant wrote: > Deos anyone knows where to find an code sample describing how to > implement the interface to marshall one object into XMLRPC compliant > structures ? > I googled without any success, and what google does not find does not exist. > Let say I have this very simple class: > class Point: > def __init__(self, x, y): > self.x = x > self.y = y You have to be more specific about what you want to do; "marshall" is a fairly generic term. XML-RPC isn't CORBA; typically you don't remote persistent objects you just make individual calls. > I've looked into xmlrpc code, I see 2 options: > 1/ override the Marshaller class of client and server > 2/ looks like the lib is supporting a WRAPPER list system, it uses to > Marshall Datetime & Binary object. Can it be possible to add its own > class (could require to emplement the 'encode' method) > I sense I will spend much more time than required unless someone is > pointing me in the right direction. You can use the loads and dumps methods to process the XML-RPC call anyway you like. -- OpenGroupware developer: awilliam at whitemice.org OpenGroupare & Cyrus IMAPd documenation @ From gerald.britton at gmail.com Fri Feb 5 11:53:33 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 11:53:33 -0500 Subject: which In-Reply-To: <4B6C4C93.3050602@optimum.net> References: <4B6C3C55.5040907@optimum.net> <4B6C45E0.1000309@optimum.net> <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> <4B6C4C93.3050602@optimum.net> Message-ID: <5d1a32001002050853s4621ca0dy9976609813cc4e3@mail.gmail.com> > > Did you mean to take this off-list? Nope -- just hit the wrong key ?Also, I'm contractually obligated to > admonish you not to "top post". Contract? > > At any rate, I proposed the 3-line format specifically because it separates > the data values from the if-then-else machinery, making it easier (for me) > to read. But there was considerable resistance to spending so much vertical > space in the source code. Weird! It's three lines and the original was four lines was it not>? -- Gerald Britton From mrkafk at gmail.com Fri Feb 5 11:56:44 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 17:56:44 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C4150.8050705@sequans.com> References: <4B6C4150.8050705@sequans.com> Message-ID: Jean-Michel Pichavant wrote: Why not dump the whole thing and use Pyro, which works beautifully and handles all the serialization business by itself, you get a Python object on the other side? Unless xmlrpc has to be at the other end, that is. From giles.thomas at resolversystems.com Fri Feb 5 12:04:10 2010 From: giles.thomas at resolversystems.com (Giles Thomas) Date: Fri, 5 Feb 2010 09:04:10 -0800 (PST) Subject: ANN: Resolver One 1.8 released Message-ID: We're proud to announce that we've just released version 1.8 of Resolver One. This version switches to IronPython 2.6, which gives us support for Python 2.6 syntax along with some serious performance improvements. Resolver One is a Windows-based spreadsheet that integrates Python deeply into its recalculation loop, making the models you build more reliable and more maintainable. In version 1.8, we've worked hard on improving performance above and beyond the gains we got from IronPython 2.6, and we've also added a number of new statistical functions, along with various minor bugfixes and smaller enhancements. You can read more about Resolver One here: We have a 31-day free trial version, so if you would like to take a look, you can download it from our website: If you want to use Resolver One in an Open Source project, we offer free licenses for that: Best regards, Giles -- Giles Thomas giles.thomas at resolversystems.com +44 (0) 20 7253 6372 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From mrkafk at gmail.com Fri Feb 5 12:07:11 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:07:11 +0100 Subject: which In-Reply-To: <4B6C4A06.6010700@sequans.com> References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> <4B6C4A06.6010700@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > To be honest I have not enough courrage to dive into yout 1000 lines of > script :-) Understandable. > What I can say however: > > 1/ your interface is somehow broken. You ask actions through options (-c > -y -s), meaning one can possibly use all these 3 options together. Your > code won't handle it (you are using elif statements). What happens if I > use no option at all ? You get this: Linux RH [17:35] root ~ # cssh.py -c "ps|wc" -s /tmp/s.sh Following options that you specified are mutually exclusive: -s / --script (value: /tmp/s.sh) -c / --cmd (value: ps|wc) You have to specify exactly one of options -c / --cmd, or -s / --script, or -y / --copy. I wrote additional logic to handle such situations, I don't rely entirely on optparse. > 2/ executing a script, or copying a directory are both commands as well. > myProg -s /tmp/myscript.sh > is nothing more than > myProg -c '/bin/sh myscript.sh' True. But you have to copy the script to remote machine in the first place. It's more convenient to do this using one option (copy to remote machine & execute there). > myProg -y file1 > is nothing more than > myProg -c 'cp file1 towhatever' Err but this is command to copy a local file/dir to *remote* machine. Like scp (in fact it uses scp protocol internally). > > 3/ check your user parameters before creating your SSHThread, and create > your SSHThread with already validated parameters. You don't want to > pollute you SSHThread code with irrelevant user error check. > > > my humble conclusion: > > 1/ rewrite your interface with > prog command args [options] > > 2/ Simplify your SSHThread by handling only shell commands > > 3/ at the CLI level (right after parameter validation), mute you copy & > script > command to a shell command and pass it to SSHThread. > > Cheers, > > JM > > From mrkafk at gmail.com Fri Feb 5 12:08:40 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:08:40 +0100 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: <4B6C4A83.7080802@sequans.com> References: <4B6C4A83.7080802@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > mk wrote: >> W. eWatson wrote: >>> I'd like to draw something like an animal track. Between each point >>> is a line. Perhaps the line would have an arrow showing the direction >>> of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ?? >> >> Pycairo? >> > turtle > > http://docs.python.org/library/turtle.html It's in standard library, and therefore Not Cool. From donn.ingle at gmail.com Fri Feb 5 12:19:06 2010 From: donn.ingle at gmail.com (donn) Date: Fri, 05 Feb 2010 19:19:06 +0200 Subject: pyclutter anyone? In-Reply-To: <4B6BD072.4080006@gmail.com> References: <4B6BD072.4080006@gmail.com> Message-ID: <4B6C530A.70303@gmail.com> No one uses pyClutter? I have some code, it does not work, but maybe this will start to help solve the problem: import clutter from clutter import cogl x,y=0,0 def boo(tl,frame,obj):#,evt): global x,y obj.set_position(x, y) def xy(obj,evt): global x,y x,y = evt.x,evt.y class G(clutter.Group): """ Attempt to make a Group that can clip its children to a path. """ def __init__(self,*args): clutter.Group.__init__(self,*args) #self.set_clip(0,0,10,10) self.connect("paint",self.do_paint) self._color = clutter.Color(255,200,100) def do_paint(self, args): width,height=200,200 cogl.path_move_to(width / 2, 0) cogl.path_line_to(width, height) cogl.path_line_to(0, height) cogl.path_line_to(width / 2, 0) cogl.path_close() #cogl.set_source_color(self._color) #cogl.path_fill() ## Colour me lost from here... cogl.clip_push_from_path() clutter.Group.do_paint(self) cogl.clip_pop() def main(): global group1 stage = clutter.Stage() stage.set_size(500, 500) stage.set_color(clutter.color_from_string("#FFF")) rect1, rect2, rect3 = clutter.Rectangle(), clutter.Rectangle(), clutter.Rectangle() group1, group2, group3 = G(), clutter.Group(), clutter.Group() group1.add(rect1, group2) group2.add(rect2, group3) group3.add(rect3) group1.set_position(100, 100) group2.set_position(100, 100) group3.set_position(100, 100) rect1.set_position(0, 0) rect2.set_position(0, 0) rect3.set_position(0, 0) rect1.set_size(150, 150) rect2.set_size(150, 150) rect3.set_size(150, 150) rect1.set_color(clutter.color_from_string("#FF000090")) rect2.set_color(clutter.color_from_string("#00FF0090")) rect3.set_color(clutter.color_from_string("#0000FF90")) stage.add(group1) stage.show_all() group1.show_all() group2.show_all() group3.show_all() stage.connect("key-press-event", clutter.main_quit) stage.connect('destroy', clutter.main_quit) stage.connect('motion-event', xy) path = clutter.Path('M 0 0 L 300 0 L 300 300 L 0 300z') timeline = clutter.Timeline(4000) timeline.set_loop(True) alpha = clutter.Alpha(timeline,clutter.EASE_OUT_SINE) p_behaviour = clutter.BehaviourPath(alpha, path) path.add_move_to(0, 0) p_behaviour.apply(group3) timeline.add_marker_at_time("foo",2000) timeline.start() t=clutter.Timeline(1000) t.set_loop(True) t.connect('new-frame', boo, group1) t.start() clutter.main() if __name__ == '__main__': main() \d -- Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software From mrkafk at gmail.com Fri Feb 5 12:23:09 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:23:09 +0100 Subject: timer for a function Message-ID: I have the following situation: 1. self.conobj = paramiko.SSHClient() self.conobj.connect(self.ip, username=self.username, key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) 2. very slow SSH host that is hanging for 30+ seconds on key exchange. The timeout in the options regards only a socket timeout, not further stages of connection negotiation, so it doesn't work there. On paramiko mailing list I got the suggestion to build a timer and then quit this by myself: > The timeout option in connect() is for the socket, not for the entire > operation. You are connected, so that timeout is no longer relevant. > You would probably have to wrap the transport.connect() method in a > timer to break out of this early. Question: how can I do that? Use another threaded class? Is there some other way? Additional snag is SSHClient() is a class that internally uses threads. How do I kill brutally its threads? Is there any way to do it? Regards, mk From arnodel at googlemail.com Fri Feb 5 12:23:51 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 05 Feb 2010 17:23:51 +0000 Subject: Dreaming of new generation IDE References: Message-ID: Robert Kern writes: > I prefer Guido's formulation (which, naturally, I can't find a direct > quote for right now): if you expect that a boolean argument is only > going to take *literal* True or False, then it should be split into > two functions. So rather than three boolean arguments, would you have eight functions? -- Arnaud From jeanmichel at sequans.com Fri Feb 5 12:24:20 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 18:24:20 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C4150.8050705@sequans.com> References: <4B6C4150.8050705@sequans.com> Message-ID: <4B6C5444.4090205@sequans.com> Jean-Michel Pichavant wrote: > Deos anyone knows where to find an code sample describing how to > implement the interface to marshall one object into XMLRPC compliant > structures ? > > I googled without any success, and what google does not find does not > exist. > > Let say I have this very simple class: > > class Point: > def __init__(self, x, y): > self.x = x > self.y = y > > > I've looked into xmlrpc code, I see 2 options: > 1/ override the Marshaller class of client and server > 2/ looks like the lib is supporting a WRAPPER list system, it uses to > Marshall Datetime & Binary object. Can it be possible to add its own > class (could require to emplement the 'encode' method) > > I sense I will spend much more time than required unless someone is > pointing me in the right direction. > > JM > I realized I gave a poor example, actually the Point object is marshable (marshallable ? like to invent new words), xmlrpc will try to marshall using __dict__ if possible. import os class Point: def __init__(self, x, y): self.x = x self.y = y self.notMarshallable = os JM From tadmc at seesig.invalid Fri Feb 5 12:25:34 2010 From: tadmc at seesig.invalid (Tad McClellan) Date: Fri, 05 Feb 2010 11:25:34 -0600 Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: ["Followup-To:" header set to comp.lang.perl.misc.] J?rgen Exner wrote: > David Thole wrote in comp.lang.perl.misc: >>I read this....and am a tiny bit confused about the actual problem. >> >>It's not exactly complex to realize that something like: >>a = b = array >>that a and b both point to the array. > > ??? > What are you talking about? First of all you should post actual code, First of all, we should not be feeding the troll! actual code in one of Perl, Python or Lisp? -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" From mrkafk at gmail.com Fri Feb 5 12:29:07 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:29:07 +0100 Subject: Your beloved python features In-Reply-To: <4B6B5E72.20702@stoneleaf.us> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: Ethan Furman wrote: > http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf > Choose to get your difficult questions about threads in Python ignored. Oh well.. From jeanmichel at sequans.com Fri Feb 5 12:30:17 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 05 Feb 2010 18:30:17 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: References: <4B6C4150.8050705@sequans.com> Message-ID: <4B6C55A9.9000902@sequans.com> mk wrote: > Jean-Michel Pichavant wrote: > > Why not dump the whole thing and use Pyro, which works beautifully and > handles all the serialization business by itself, you get a Python > object on the other side? Unless xmlrpc has to be at the other end, > that is. > > Company stuff. We are all using the xmlrpc standard for our network code. JM From invalid at invalid.invalid Fri Feb 5 12:30:46 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 5 Feb 2010 17:30:46 +0000 (UTC) Subject: Drawing a zig-zag Trail in Python? References: Message-ID: On 2010-02-05, W. eWatson wrote: > I'd like to draw something like an animal track. Between each > point is a line. Perhaps the line would have an arrow showing > the direction of motion. There should be x-y coordinates > axises. PIL? MatPlotLib, ?? I'd probably use gnuplot-py, but I'm probably biased since I've been using gnuplot since way before I learned Python. -- Grant Edwards grante Yow! Hello, GORRY-O!! at I'm a GENIUS from HARVARD!! visi.com From mrkafk at gmail.com Fri Feb 5 12:30:50 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:30:50 +0100 Subject: Your beloved python features In-Reply-To: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: Julian wrote: > For those guys would be a poster quite cool which describes the most > popular and beloved python features. Dictionaries. A workhorse of Python, by far the most useful data structure. From mrkafk at gmail.com Fri Feb 5 12:35:39 2010 From: mrkafk at gmail.com (mk) Date: Fri, 05 Feb 2010 18:35:39 +0100 Subject: which In-Reply-To: References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> <4B6C4A06.6010700@sequans.com> Message-ID: mk wrote: > > > What I can say however: > > > > 1/ your interface is somehow broken. You ask actions through options (-c > > -y -s), meaning one can possibly use all these 3 options together. Your > > code won't handle it (you are using elif statements). What happens if I > > use no option at all ? Arrgh this is my bad day. You get this: Linux RH [17:35] root ~ # cssh.py -i linux You have to specify exactly one of the following: - command to run remotely, using -c command / --cmd command, or - script to run remotely, using -s scriptfile / --script scriptfile, or - file/directory to copy, using -y file_or_dir / --copy file_or_dir From bradallen137 at gmail.com Fri Feb 5 12:48:24 2010 From: bradallen137 at gmail.com (Brad Allen) Date: Fri, 5 Feb 2010 11:48:24 -0600 Subject: method to intercept string formatting % operations In-Reply-To: <4B6C3DEC.9030109@sequans.com> References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> <4B6C3DEC.9030109@sequans.com> Message-ID: <4957f1ef1002050948i49816576nfe2f614a36d17cb1@mail.gmail.com> On Fri, Feb 5, 2010 at 9:49 AM, Jean-Michel Pichavant wrote: > Anyway why would you want to use the tuple form ? it's beaten in every > aspect by the dictionary form. I'm subclassing a namedtuple, and adding some additional functionality such as __getitem__, __setitem__, so that the namedtuple also behaves like a dict. From charles at declareSub.com Fri Feb 5 12:55:58 2010 From: charles at declareSub.com (Charles Yeomans) Date: Fri, 5 Feb 2010 12:55:58 -0500 Subject: Exception class documentation Message-ID: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> I am so far unable to find the information I want about the Exception class. Information like the signature of __init__ seems to be unavailable. Any suggestions where I might find such information? Charles Yeomans From cjblaine at gmail.com Fri Feb 5 12:58:52 2010 From: cjblaine at gmail.com (cjblaine) Date: Fri, 5 Feb 2010 09:58:52 -0800 (PST) Subject: Modules failing to add runtime library path info at link time References: <9f8197ae-d371-431b-b4bd-8e3f4d6f0998@g29g2000yqe.googlegroups.com> <303e1371-bc77-4cc8-bbbf-bddfd610fad9@r19g2000yqb.googlegroups.com> <8167cbe0-d099-4a0b-804e-6e91817197ec@b10g2000yqa.googlegroups.com> Message-ID: <382f9f94-e863-4511-a824-b03225135faa@r24g2000yqd.googlegroups.com> On Feb 1, 11:35?pm, cjblaine wrote: > On Feb 1, 11:04?pm, cjblaine wrote: > > > > > On Feb 1, 8:00?pm, Christian Heimes wrote: > > > > cjblaine wrote: > > > > Where/how can I configure the appropriate portion of our Python > > > > install to do 100% the right thing instead of just 50% (-L)? > > > > Python's distutils doesn't alter the library search path unless you tell > > > it explicitly. > > > > > A specific example -- note the -L and lack of -R (Solaris build): > > > > > % python setup.py build > > > > .... > > > > gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/ > > > > apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so > > > > % > > > > The Extension() class supports the rpath argument. Simply add > > > rpath="/path/to/library/dir" and you are good. > > > > Christian > > > Thanks for the reply. > > > So, python setup.py build rpath="/whatever/lib" ? > > Replying to myself: > > No. ?Actually, Christian, it looks like it's runtime_library_dirs? > > class Extension: > ... > ? ? ? runtime_library_dirs : [string] > ? ? ? ? list of directories to search for C/C++ libraries at run time > ? ? ? ? (for shared extensions, this is when the extension is loaded) > > So, how does one inject that into, I assume, setup.cfg ? ?Ideally it > could be done via the build command-line, but I don't see a way to do > that when browsing python setup.py build --help > > ( there is no setup.cfg provided in the PyGreSQL source tree, to ) > ( continue that example case ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ) Anyone? From gandalf at shopzeus.com Fri Feb 5 13:11:17 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Fri, 05 Feb 2010 19:11:17 +0100 Subject: Editor for Python Message-ID: <4B6C5F45.8010200@shopzeus.com> Hi All, I know that this question was put up on this list a thousand times. I know that most of the editors are listed here: http://wiki.python.org/moin/PythonEditors I already tried most of them. But still, I need something that is not listed there. Requirements: * starts and works fast * has code folding, displays identation guides * auto completion * class browser * source code browser (e.g. a list of definitions, when you click it jumps to the definition * integration with pychecker or pylint * UTF-8 files * free, or not-so-expensive * works on linux and windows The one I'm using now is Geany. It does everything, except class browser and pychecker/pylint. Now maybe, I can install (or write??) a geany extension that would allow me to use pychecker. But I could not find information on that. There where others I tried (PyPE, DrPython, KomodoEdit, Editra etc.) but all of them failed for some reason. Can you please suggest another editor that I could try? Or send me a link that tells how to write or install pychecked plugin for Geany. Thanks, Laszlo -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 5 13:20:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Feb 2010 18:20:40 +0000 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C5444.4090205@sequans.com> References: <4B6C4150.8050705@sequans.com> <4B6C5444.4090205@sequans.com> Message-ID: <4B6C6178.2010002@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > Jean-Michel Pichavant wrote: >> Deos anyone knows where to find an code sample describing how to >> implement the interface to marshall one object into XMLRPC compliant >> structures ? >> >> I googled without any success, and what google does not find does not >> exist. >> >> Let say I have this very simple class: >> >> class Point: >> def __init__(self, x, y): >> self.x = x >> self.y = y >> >> >> I've looked into xmlrpc code, I see 2 options: >> 1/ override the Marshaller class of client and server >> 2/ looks like the lib is supporting a WRAPPER list system, it uses to >> Marshall Datetime & Binary object. Can it be possible to add its own >> class (could require to emplement the 'encode' method) >> >> I sense I will spend much more time than required unless someone is >> pointing me in the right direction. >> >> JM >> > I realized I gave a poor example, actually the Point object is marshable > (marshallable ? like to invent new words), xmlrpc will try to marshall > using __dict__ if possible. > "marshallable". Just pick a verb and add -able. There was an advertisement by British Gas in which someone said that his gas central heating was very turn-off-and-on-able! :-) > import os > > class Point: > def __init__(self, x, y): > self.x = x > self.y = y > self.notMarshallable = os > From jjposner at optimum.net Fri Feb 5 13:26:23 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 05 Feb 2010 13:26:23 -0500 Subject: which In-Reply-To: References: <4B6C3C55.5040907@optimum.net> <4B6C45E0.1000309@optimum.net> <5d1a32001002050826h190c4d74y539745e7c855f1ee@mail.gmail.com> <4B6C4C93.3050602@optimum.net> Message-ID: <4B6C62CF.9090902@optimum.net> On 2/5/2010 11:53 AM, Gerald Britton wrote: > Also, I'm contractually obligated to >> admonish you not to "top post". > > Contract? Joke. (I know it's hard to tell.) > >> >> At any rate, I proposed the 3-line format specifically because it separates >> the data values from the if-then-else machinery, making it easier (for me) >> to read. But there was considerable resistance to spending so much vertical >> space in the source code. > > Weird! It's three lines and the original was four lines was it not>? Yes, but most people (including you, right?) seemed to think that conditional expressions are best confined to a single line. I proposed my 3-line alternative for expressions that *cannot* reasonably be confined to a single line. -John From gerald.britton at gmail.com Fri Feb 5 13:41:52 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 13:41:52 -0500 Subject: Editor for Python In-Reply-To: <4B6C5F45.8010200@shopzeus.com> References: <4B6C5F45.8010200@shopzeus.com> Message-ID: <5d1a32001002051041od360fd1qe46a1ba8593df7ff@mail.gmail.com> 2010/2/5 Laszlo Nagy : > > ? Hi All, > > I know that this question was put up on this list a thousand times. I know > that most of the editors are listed here: > http://wiki.python.org/moin/PythonEditors > > I already tried most of them. But still, I need something that is not listed > there. Requirements: > > starts and works fast > has code folding, displays identation guides > auto completion > class browser > source code browser (e.g. a list of definitions, when you click it jumps to > the definition > integration with pychecker or pylint > UTF-8 files > free, or not-so-expensive > works on linux and windows > > The one I'm using now is Geany. It does everything, except class browser and > pychecker/pylint. Now maybe, I can install (or write??) a geany extension > that would allow me to use pychecker. But I could not find information on > that. There where others I tried (PyPE, DrPython, KomodoEdit, Editra etc.) > but all of them failed for some reason. Can you please suggest another > editor that I could try? Or send me a link that tells how to write or > install pychecked plugin for Geany. > > Thanks, > > ?? Laszlo > > > -- > http://mail.python.org/mailman/listinfo/python-list > > I use Geany too. It lets me see the classes in my module, though not within a package (Is that what you mean)? You'd probably have to write a plugin to support pychecker or pylint though I believe that its not too difficult. Who knows? Perhaps someone already has such a plugin that you can use. -- Gerald Britton From gnarlodious at gmail.com Fri Feb 5 13:44:03 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Fri, 5 Feb 2010 10:44:03 -0800 (PST) Subject: SQLite3: preventing new file creation Message-ID: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> Every time I say something like: connection=sqlite3.connect(file) sqlite creates a new database file. Can this behavior be suppressed through SQLite? Or am I forced to check for the file existing first? -- Gnarlie From wolftracks at invalid.com Fri Feb 5 14:04:34 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 11:04:34 -0800 Subject: How Uninstall MatPlotLib? In-Reply-To: References: Message-ID: On 2/5/2010 8:17 AM, W. eWatson wrote: > See Subject. I'm working in IDLE in Win7. It seems to me it gets stuck in site-packages under C:\Python25. Maybe this is as simple as deleting the entry? Well, yes there's a MPL folder under site-packages and an info MPL file of 540 bytes. There are also pylab.py, pyc,and py0 files under site. From gerald.britton at gmail.com Fri Feb 5 14:13:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 14:13:36 -0500 Subject: Exception class documentation In-Reply-To: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> Message-ID: <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> On Fri, Feb 5, 2010 at 12:55 PM, Charles Yeomans wrote: > I am so far unable to find the information I want about the Exception class. > ?Information like the signature of __init__ seems to be unavailable. ?Any > suggestions where I might find such information? > > > Charles Yeomans > -- > http://mail.python.org/mailman/listinfo/python-list > Though not documented, some silly tests indicate that it will accept pretty much anything: >>> Exception(1,2,4,54) Exception(1, 2, 4, 54) >>> Exception(*range(10)) Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>> Exception(*range(50)) Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49) >>> Exception('a','b','c','d','e') Exception('a', 'b', 'c', 'd', 'e') >>> Exception(Exception(1)) Exception(Exception(1,),) -- Gerald Britton From wanderer at dialup4less.com Fri Feb 5 14:53:08 2010 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 5 Feb 2010 11:53:08 -0800 (PST) Subject: method names nounVerb or verbNoun Message-ID: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Which is the more accepted way to compose method names nounVerb or verbNoun? For example voltageGet or getVoltage? getVoltage sounds more normal, but voltageGet is more like voltage.Get. I seem to mix them and I should probably pick one way and stick with it. Thanks From steve at holdenweb.com Fri Feb 5 14:55:25 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 14:55:25 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: > Robert Kern writes: > >> I prefer Guido's formulation (which, naturally, I can't find a direct >> quote for right now): if you expect that a boolean argument is only >> going to take *literal* True or False, then it should be split into >> two functions. > > So rather than three boolean arguments, would you have eight functions? > If there's genuinely a need for that functionality, yes. I statement that calls one of two functions depending on the value of a Boolean is normally considered to be better coupling than calling a single function with the Boolean as an argument. As with everything else you have to apply a certain amount of common sense. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From gerald.britton at gmail.com Fri Feb 5 15:00:45 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 15:00:45 -0500 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <5d1a32001002051200n11f02e65re43ad5291bbbf951@mail.gmail.com> On Fri, Feb 5, 2010 at 2:53 PM, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > > Thanks > -- > http://mail.python.org/mailman/listinfo/python-list > I'd say noun_verb (note the underscore in accordance with the style guide in PEP 8): http://www.python.org/dev/peps/pep-0008/ Function Names Function names should be lowercase, with words separated by underscores as necessary to improve readability. mixedCase is allowed only in contexts where that's already the prevailing style (e.g. threading.py), to retain backwards compatibility. -- Gerald Britton From mukeshtiwari.iiitm at gmail.com Fri Feb 5 15:14:51 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Fri, 5 Feb 2010 12:14:51 -0800 (PST) Subject: Last M digits of expression A^N Message-ID: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Hello everyone. I am kind of new to python so pardon me if i sound stupid. I have to find out the last M digits of expression.One thing i can do is (A**N)%M but my A and N are too large (10^100) and M is less than 10^5. The other approach was repeated squaring and taking mod of expression. Is there any other way to do this in python more faster than log N. def power(A,N,M): ret=1 while(N): if(N%2!=0):ret=(ret*A)%M A=(A*A)%M N=N//2 return ret From awilliam at opengroupware.us Fri Feb 5 15:15:42 2010 From: awilliam at opengroupware.us (Adam Tauno Williams) Date: Fri, 05 Feb 2010 15:15:42 -0500 Subject: xmlrcp - how to marshall objects In-Reply-To: <4B6C5444.4090205@sequans.com> References: <4B6C4150.8050705@sequans.com> <4B6C5444.4090205@sequans.com> Message-ID: <1265400942.3301.14.camel@linux-m3mt> On Fri, 2010-02-05 at 18:24 +0100, Jean-Michel Pichavant wrote: > Jean-Michel Pichavant wrote: > > Deos anyone knows where to find an code sample describing how to > > implement the interface to marshall one object into XMLRPC compliant > > structures ? > > I googled without any success, and what google does not find does not > > exist. > > Let say I have this very simple class: > > class Point: > > def __init__(self, x, y): > > self.x = x > > self.y = y > > I've looked into xmlrpc code, I see 2 options: > > 1/ override the Marshaller class of client and server > > 2/ looks like the lib is supporting a WRAPPER list system, it uses to > > Marshall Datetime & Binary object. Can it be possible to add its own > > class (could require to emplement the 'encode' method) > > I sense I will spend much more time than required unless someone is > > pointing me in the right direction. > I realized I gave a poor example, actually the Point object is marshable > (marshallable ? like to invent new words), xmlrpc will try to marshall > using __dict__ if possible. > import os > class Point: > def __init__(self, x, y): > self.x = x > self.y = y > self.notMarshallable = os This example doesn't make any sense. Why would you set a variable equal to an important module in a class named Point? What is it you are actually trying to accomplish? If you are trying to create an object publishing environment then maybe something like - rpc = xmlrpclib.loads(payload, use_datetime=True) method = rpc[1].split('.') classname = method[0] methodname = method[1] parameters = rpc[0] classclass = eval(classname) handler = classclass() call = getattr(handler, method_name) result = apply(call, parameters) result = xmlrpclib.dumps(tuple([result]), methodresponse=True) Obviously add copious amounts of exception handling and a security model. -- OpenGroupware developer: awilliam at whitemice.org OpenGroupare & Cyrus IMAPd documenation @ From nagle at animats.com Fri Feb 5 15:16:46 2010 From: nagle at animats.com (John Nagle) Date: Fri, 05 Feb 2010 12:16:46 -0800 Subject: How to guard against bugs like this one? In-Reply-To: References: Message-ID: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> kj wrote: ... > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. The right answer to this is to make module search return an error if two modules satisfy the search criteria. "First find" isn't a good solution. John Nagle From dickinsm at gmail.com Fri Feb 5 15:18:42 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 5 Feb 2010 12:18:42 -0800 (PST) Subject: Last M digits of expression A^N References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <5630ef4a-28c0-4efd-9d4f-a7b8aab28cb3@r24g2000yqd.googlegroups.com> On Feb 5, 8:14?pm, mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > 10^5. The other approach ? was ?repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. > > def power(A,N,M): > ? ? ret=1 > ? ? while(N): > ? ? ? ? if(N%2!=0):ret=(ret*A)%M > ? ? ? ? A=(A*A)%M > ? ? ? ? N=N//2 > ? ? return ret The built-in pow function does exactly this, if you give it three arguments: >>> pow(12345, 67891, 17) 10 >>> 12345 ** 67891 % 17 10L (Though this won't work for negative N.) Mark From apt.shansen at gmail.com Fri Feb 5 15:19:26 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 5 Feb 2010 12:19:26 -0800 Subject: How to guard against bugs like this one? In-Reply-To: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> References: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> Message-ID: <7a9c25c21002051219v65760f7co276617dd6422952b@mail.gmail.com> On Fri, Feb 5, 2010 at 12:16 PM, John Nagle wrote: > kj wrote: > >> Through a *lot* of trial an error I finally discovered that the >> root cause of the problem was the fact that, in the same directory >> as buggy.py, there is *another* innocuous little script, totally >> unrelated, whose name happens to be numbers.py. >> > > The right answer to this is to make module search return an > error if two modules satisfy the search criteria. "First find" > isn't a good solution. > And thereby slowdown every single import and application startup time as the common case of finding a module in one of the first couple entries in sys.path now has to search it in every single item on that path. Its not uncommon to have a LOT of things on sys.path. No thanks. "First Find" is good enough, especially with PEP328 and absolute_import being on in Python 3 (and presumably 2.7). It doesn't really help older Python versions unfortunately, but changing how import works wouldn't help them anyways. Yeah, there might be two paths on sys.path which both have a 'numbers.py' at the top level and First Find might return the wrong one, but... people making poor decisions on code organization and not using packages isn't something the language really needs to fix. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerald.britton at gmail.com Fri Feb 5 15:21:13 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Fri, 5 Feb 2010 15:21:13 -0500 Subject: Last M digits of expression A^N In-Reply-To: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <5d1a32001002051221r2b4ffadak442492bac6debb40@mail.gmail.com> On Fri, Feb 5, 2010 at 3:14 PM, mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > 10^5. The other approach ? was ?repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. > > def power(A,N,M): > ? ?ret=1 > ? ?while(N): > ? ? ? ?if(N%2!=0):ret=(ret*A)%M > ? ? ? ?A=(A*A)%M > ? ? ? ?N=N//2 > ? ?return ret > -- > http://mail.python.org/mailman/listinfo/python-list > http://docs.python.org/3.1/library/decimal.html#decimal.Context.power -- Gerald Britton From clp2 at rebertia.com Fri Feb 5 15:26:38 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Feb 2010 12:26:38 -0800 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <50697b2c1002051226o50d4ff02u101d8c362ae0d1ea@mail.gmail.com> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. Use properties[1] and just call it `voltage`. Python is not Java [2]; explicit getters/setters are unpythonic. [1] http://docs.python.org/library/functions.html#property [2] http://dirtsimple.org/2004/12/python-is-not-java.html Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Fri Feb 5 15:26:44 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Feb 2010 20:26:44 +0000 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <4B6C7F04.1090002@mrabarnett.plus.com> Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > I would use the 'normal' order, which in this case is 'get_voltage'. From mensanator at aol.com Fri Feb 5 15:28:37 2010 From: mensanator at aol.com (Mensanator) Date: Fri, 5 Feb 2010 12:28:37 -0800 (PST) Subject: Last M digits of expression A^N References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> <5630ef4a-28c0-4efd-9d4f-a7b8aab28cb3@r24g2000yqd.googlegroups.com> Message-ID: On Feb 5, 2:18?pm, Mark Dickinson wrote: > On Feb 5, 8:14?pm, mukesh tiwari wrote: > > > Hello everyone. I am kind of new to python so pardon me if i sound > > stupid. > > I have to find out the last M digits of expression.One thing i can do > > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > > 10^5. The other approach ? was ?repeated squaring and taking mod of > > expression. Is there any other way to do this in python more faster > > than log N. > > > def power(A,N,M): > > ? ? ret=1 > > ? ? while(N): > > ? ? ? ? if(N%2!=0):ret=(ret*A)%M > > ? ? ? ? A=(A*A)%M > > ? ? ? ? N=N//2 > > ? ? return ret > > The built-in pow function does exactly this, It doesn't do 'exactly' that. M is the number of digits. If you want 17 digits, the third number should 10**17. Using 17 directly will give you a 2-digit answer as shown. Try this instead: >>> pow(12345,67891,10**17) 50553131103515625 > if you give it three > arguments: > > >>> pow(12345, 67891, 17) > 10 > >>> 12345 ** 67891 % 17 > > 10L > > (Though this won't work for negative N.) > > Mark From jonny.lowe.12345 at gmail.com Fri Feb 5 15:39:07 2010 From: jonny.lowe.12345 at gmail.com (jonny lowe) Date: Fri, 5 Feb 2010 12:39:07 -0800 (PST) Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> Message-ID: <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> On Feb 4, 8:20?pm, exar... at twistedmatrix.com wrote: > On 01:56 am, jonny.lowe.12... at gmail.com wrote: > > > > >Hi everyone, > > >Is there an easy way to mergestdinandstdout? For instance suppose I > >havescriptthat prompts for a number and prints the number. If you > >execute this with redirection from a file say input.txt with 42 in the > >file, then executing > > >./myscript < input.txt > output.txt > > >the output.txt might look like this: > > >Enter a number: > >You entered 42. > > >What I want is to have an easy way to merge input.txt and thestdout > >so that output.txt look like: > > >Enter a number: 42 > >You entered 42. > > >Here, the first 42 is of course from input.txt. > > It sounds like you might be looking forscript(1)? > > Jean-Paul Hi Jean-Paul, I tried it. But stdin is not merged in with stdout. Maybe I'm using script wrongly? This is what I've done. I have a python script y. Here's what it looks like when I run it and I entered "sss": $ ./y gimme x:sss you entered sss Now I'm going to use the script command. I'm using an input file input.txt that contains just the string "hello". $ script -c "./y < input.txt" output.txt Script started, file is output.txt gimme x:you entered hello Script done, file is output.txt And when I view output.txt this is what I see: $ less output.txt Script started on Thu Feb 4 22:28:12 2010 gimme x:you entered hello Script done on Thu Feb 4 22:28:13 2010 As you can see the stdin is not printed. What I'd really wanted was something like this in output.txt: gimme x:hello you entered hello -jon From python at mrabarnett.plus.com Fri Feb 5 15:44:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 05 Feb 2010 20:44:58 +0000 Subject: How to guard against bugs like this one? In-Reply-To: <7a9c25c21002051219v65760f7co276617dd6422952b@mail.gmail.com> References: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> <7a9c25c21002051219v65760f7co276617dd6422952b@mail.gmail.com> Message-ID: <4B6C834A.7020801@mrabarnett.plus.com> Stephen Hansen wrote: > On Fri, Feb 5, 2010 at 12:16 PM, John Nagle > wrote: > > kj wrote: > > Through a *lot* of trial an error I finally discovered that the > root cause of the problem was the fact that, in the same directory > as buggy.py, there is *another* innocuous little script, totally > unrelated, whose name happens to be numbers.py. > > > The right answer to this is to make module search return an > error if two modules satisfy the search criteria. "First find" > isn't a good solution. > > > And thereby slowdown every single import and application startup time as > the common case of finding a module in one of the first couple entries > in sys.path now has to search it in every single item on that path. Its > not uncommon to have a LOT of things on sys.path. > > No thanks. "First Find" is good enough, especially with PEP328 and > absolute_import being on in Python 3 (and presumably 2.7). It doesn't > really help older Python versions unfortunately, but changing how import > works wouldn't help them anyways. Yeah, there might be two paths on > sys.path which both have a 'numbers.py' at the top level and First Find > might return the wrong one, but... people making poor decisions on code > organization and not using packages isn't something the language really > needs to fix. > You might want to write a script that looks through the search paths for duplicated names, especially ones which hide modules in the standard library. Has anyone done this already? From python at rcn.com Fri Feb 5 15:53:51 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 5 Feb 2010 12:53:51 -0800 (PST) Subject: method to intercept string formatting % operations References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Message-ID: <649b3c62-f228-4fc1-9913-2dbe4d253788@k36g2000prb.googlegroups.com> On Feb 5, 6:57?am, bradallen wrote: > Hello, > > For container class derived from namedtuple, but which also behaves > like a dictionary by implementing __getitem__ for non-integer index > values, is there a special reserved method which allows intercepting % > string formatting operations? I would like for my container type to > behave appropriately depending on whether the string formatting > operation has a string like this : > > "whatever %s yadayada" % mycontainer ?# needs to act like a tuple > > "whatever %(key)s yadayada" % mycontainer ?# needs to act like a > dictionary The implementation for str.__mod__ refuses to treat tuples and tuple subclasses as a dictionary. Since namedtuples are a subclass of tuple, you're not going to have any luck with this one. To see actual C code, look at PyString_Format() in http://svn.python.org/view/python/trunk/Objects/stringobject.c?view=markup PyObject *dict = NULL; . . . if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) && !PyObject_TypeCheck(args, &PyBaseString_Type)) dict = args; Since automatic conversion is out, you can instead use the namedtuple._asdict() method for an explicit conversion: >>> from collections import namedtuple >>> Point = namedtuple('Point', 'x y') >>> p = Point(5, 12) >>> 'x: %(x)s' % p._asdict() 'x: 5' Raymond From robert.kern at gmail.com Fri Feb 5 16:03:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Feb 2010 15:03:15 -0600 Subject: Python and Ruby In-Reply-To: <4B6B5C72.8080100@stoneleaf.us> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <4B6B5C72.8080100@stoneleaf.us> Message-ID: On 2010-02-04 17:46 PM, Ethan Furman wrote: > Robert Kern wrote: >> On 2010-02-04 14:55 PM, Jonathan Gardner wrote: >>> On Feb 3, 3:39 pm, Steve Holden wrote: >>>> Robert Kern wrote: >>>>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >>>> >>>>>> I can explain all of Python in an hour; I doubt anyone will >>>>>> understand >>>>>> all of Python in an hour. >>>> >>>>> With all respect, talking about a subject without a reasonable >>>>> chance of >>>>> your audience understanding the subject afterwards is not explaining. >>>>> It's just exposition. >>>> >>>> I agree. If the audience doesn't understand then you haven't >>>> explained it. >>> >>> On the contrary, that explanation would have everything you need. It >>> would take an hour to read or listen to the explanation, but much more >>> than that time to truly understand everything that was said. >> >> Like I said, that's exposition, not explanation. There is an important >> distinction between the two words. Simply providing information is not >> explanation. If it takes four hours for your audience to understand >> it, then you explained it in four hours no matter when you stopped >> talking. > > And if it takes six months? Would you seriously say it took you six > months to explain something because it took that long for your audience > to understand it? > > At some point you have to make the transition from person A explaining > and person(s) B understanding -- they don't necessarily happen > synchronously. Then it's exposition and understanding, not explanation and understanding. -- 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 anthra.norell at bluewin.ch Fri Feb 5 16:09:55 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Fri, 05 Feb 2010 22:09:55 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: Message-ID: <4B6C8923.3090501@bluewin.ch> Duncan Booth wrote: > Anthra Norell wrote: > > >>> Using pythonw.exe will start the program with all error output dumped in >>> the bit bucket. Running from a command prompt with python.exe will at >>> least let you see if there are any errors. >>> >>> >> python.exe from the command line works all right in a DOS window. The >> problem must be with idle.pyw. I tried the old idle.pyw (2.4) with the >> new python.exe. (2.5) and that didn't work either. >> What is the bit bucket? If I had a clue, I could go from there. What >> puzzles me is that version 2.4 has been working fine and one wouldn't >> think that the changes from 2.4 to 2.5 would be so extensive as to cause >> a major malfunction. For the time being 2.4 works fine. I'd much prefer >> 2.5, though, because it includes the image library (PIL), whereas 2.4 >> cannot even use it. >> > > Bit bucket: http://en.wikipedia.org/wiki/Bit_bucket > > If you are seeing nothing at all when running it with python.exe instead of > pythonw.exe then something bizarre must be happening. > > My guess would have been that you had a problem importing something: e.g. > if Tkinter isn't installed properly then running Idle under pythonw.exe > would exit with an error message but you wouldn't see the error message. > However since you don't see an error message when running it with > python.exe it isn't that. > > Sorry, I'm out of ideas for now. > > No matter. I'll just keep working with 2.4. The machine is on its way out anyway. I have a brand new Dell Latitude E6500 without an operating system waiting to be set up with Linux. That'll take some time. Thank you for your suggestions. Frederic From bcb at undisclosedlocation.net Fri Feb 5 16:22:25 2010 From: bcb at undisclosedlocation.net (Bruce C. Baker) Date: Fri, 5 Feb 2010 15:22:25 -0600 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: "George Sakkis" wrote in message news:de06116c-e77c-47c4-982d-62b48bca5064 at j31g2000yqa.googlegroups.com... I'll give the benefit of doubt and assume you're joking rather than trolling. George ************************************************************* Not trolling, my friend! GvR got it right when he discarded the superfluous semicolons from the ends of statements--and then he ADDS superfluous colons to the ends of control statements? It will probably be as much of a shock to you as it was to me when I learned after studying parsing that colons, semicolons, "then"'s and "do"'s, etc., are simply noise tokens that serve no purpose except to clutter up the source. As for enforced indentation, back in the late 60's when I was a programming newbie I remember thinking how cool it would be to just indent the statements controlled by for loops (we didn't have none of them fancy while loops in FORTRAN back then! :-) ) Not too long after that I saw the havoc that a buggy editor could wreak on nicely-formatted source. :-( Formatting held hostage to a significant, invisible whitespace char? An inevitable accident waiting to happen! Not good, Guido; not good at all. That'll do for starters. :-) From aharrisreid at googlemail.com Fri Feb 5 16:26:20 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Fri, 05 Feb 2010 21:26:20 +0000 Subject: Editor for Python In-Reply-To: <4B6C5F45.8010200@shopzeus.com> References: <4B6C5F45.8010200@shopzeus.com> Message-ID: <4B6C8CFC.8020507@googlemail.com> Hi Laszlo, I use Wing IDE (not free, $35 for personal edition) and PyScripter (free). I find both good, for different reasons. Regards, Alan ------------------------------------------------------------------------ Laszlo Nagy wrote: > > Hi All, > > I know that this question was put up on this list a thousand times. I > know that most of the editors are listed here: > http://wiki.python.org/moin/PythonEditors > > I already tried most of them. But still, I need something that is not > listed there. Requirements: > > * starts and works fast > * has code folding, displays identation guides > * auto completion > * class browser > * source code browser (e.g. a list of definitions, when you click > it jumps to the definition > * integration with pychecker or pylint > * UTF-8 files > * free, or not-so-expensive > * works on linux and windows > > The one I'm using now is Geany. It does everything, except class > browser and pychecker/pylint. Now maybe, I can install (or write??) a > geany extension that would allow me to use pychecker. But I could not > find information on that. There where others I tried (PyPE, DrPython, > KomodoEdit, Editra etc.) but all of them failed for some reason. Can > you please suggest another editor that I could try? Or send me a link > that tells how to write or install pychecked plugin for Geany. > > Thanks, > > Laszlo > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Fri Feb 5 16:39:46 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Feb 2010 13:39:46 -0800 Subject: Python and Ruby In-Reply-To: References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <4B6B5C72.8080100@stoneleaf.us> Message-ID: <4B6C9022.5050604@stoneleaf.us> Robert Kern wrote: > On 2010-02-04 17:46 PM, Ethan Furman wrote: >> Robert Kern wrote: >>> On 2010-02-04 14:55 PM, Jonathan Gardner wrote: >>>> On Feb 3, 3:39 pm, Steve Holden wrote: >>>>> Robert Kern wrote: >>>>>> On 2010-02-03 15:32 PM, Jonathan Gardner wrote: >>>>> >>>>>>> I can explain all of Python in an hour; I doubt anyone will >>>>>>> understand >>>>>>> all of Python in an hour. >>>>> >>>>>> With all respect, talking about a subject without a reasonable >>>>>> chance of >>>>>> your audience understanding the subject afterwards is not explaining. >>>>>> It's just exposition. >>>>> >>>>> I agree. If the audience doesn't understand then you haven't >>>>> explained it. >>>> >>>> On the contrary, that explanation would have everything you need. It >>>> would take an hour to read or listen to the explanation, but much more >>>> than that time to truly understand everything that was said. >>> >>> Like I said, that's exposition, not explanation. There is an important >>> distinction between the two words. Simply providing information is not >>> explanation. If it takes four hours for your audience to understand >>> it, then you explained it in four hours no matter when you stopped >>> talking. >> >> And if it takes six months? Would you seriously say it took you six >> months to explain something because it took that long for your audience >> to understand it? >> >> At some point you have to make the transition from person A explaining >> and person(s) B understanding -- they don't necessarily happen >> synchronously. > > Then it's exposition and understanding, not explanation and understanding. > Hmm. Well, I can see your point -- after all, if are "explaining" but your audience is not understanding, are you really explaining? Okay, looking in the dictionary... ex?plain ?verb (used with object) 1. to make plain or clear; render understandable or intelligible: to explain an obscure point. 2. to make known in detail: to explain how to do something. un?der?stand ?verb (used with object) 1. to perceive the meaning of; grasp the idea of; comprehend: to understand Spanish; I didn't understand your question. 2. to be thoroughly familiar with; apprehend clearly the character, nature, or subtleties of: to understand a trade. 3. to assign a meaning to; interpret: He understood her suggestion as a complaint. 4. to grasp the significance, implications, or importance of: He does not understand responsibility. For me, at least, it boils down to this feeling that understanding is not a True/False item, but more of a scale (like all the the numbers between 0.0 and 1.0 [not including 1.0 of course -- this *is* Python! ;)]). As a personal example, decorators are not that difficult to grasp -- you take your function and wrap it in another function; but what you can do with them! They are truly impressive once your understanding deepens. And at the end of the day (or this thread, whichever comes first ;) Python is awesome, and that's what counts. ~Ethan~ From ethan at stoneleaf.us Fri Feb 5 16:48:22 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 05 Feb 2010 13:48:22 -0800 Subject: How to guard against bugs like this one? In-Reply-To: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> References: <4b6c78d2$0$1602$742ec2ed@news.sonic.net> Message-ID: <4B6C9226.2020606@stoneleaf.us> John Nagle wrote: > kj wrote: > ... >> >> Through a *lot* of trial an error I finally discovered that the >> root cause of the problem was the fact that, in the same directory >> as buggy.py, there is *another* innocuous little script, totally >> unrelated, whose name happens to be numbers.py. > > The right answer to this is to make module search return an > error if two modules satisfy the search criteria. "First find" > isn't a good solution. > > John Nagle Then what happens when you *want* to shadow a module? As MRAB suggests, if you are really concerned about it use a script that checks for duplicate modules (not a bad idea for debugging), but don't start throwing errors... next thing you know we won't be able to shadow classes, functions, or built-ins! !-) ~Ethan~ From wanderer at dialup4less.com Fri Feb 5 16:49:33 2010 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 5 Feb 2010 13:49:33 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: On Feb 5, 3:26?pm, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > > Which is the more accepted way to compose method names nounVerb or > > verbNoun? > > > For example voltageGet or getVoltage? getVoltage sounds more normal, > > but voltageGet is more like voltage.Get. I seem to mix them and I > > should probably pick one way and stick with it. > > Use properties[1] and just call it `voltage`. Python is not Java [2]; > explicit getters/setters are unpythonic. > > [1]http://docs.python.org/library/functions.html#property > [2]http://dirtsimple.org/2004/12/python-is-not-java.html > > Cheers, > Chris > --http://blog.rebertia.com Maybe I'm not using Get right either. I'm wrapping functions. def AbbeGet(self, Lens): """ Get the Abbe Number V for the material where V = (Nd - 1)/(Nf - Nc) where the Index of Refractions are Nd at the Fraunhofer D line 0.5892um Nf at the Fraunhofer F line 0.4861um Nc at the Fraunhofer C line 0.6563um """ Nd = Lens.Mat.NtGet(0.5892) Nf = Lens.Mat.NtGet(0.4861) Nc = Lens.Mat.NtGet(0.6563) if (Nf - Nc) != 0: V = (Nd - 1)/(Nf - Nc) else: V = 1e6 return V # end AbbeGet From alfps at start.no Fri Feb 5 16:53:16 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 05 Feb 2010 22:53:16 +0100 Subject: method names nounVerb or verbNoun In-Reply-To: References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: * Wanderer: > On Feb 5, 3:26 pm, Chris Rebert wrote: >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: >>> Which is the more accepted way to compose method names nounVerb or >>> verbNoun? >>> For example voltageGet or getVoltage? getVoltage sounds more normal, >>> but voltageGet is more like voltage.Get. I seem to mix them and I >>> should probably pick one way and stick with it. >> Use properties[1] and just call it `voltage`. Python is not Java [2]; >> explicit getters/setters are unpythonic. >> >> [1]http://docs.python.org/library/functions.html#property >> [2]http://dirtsimple.org/2004/12/python-is-not-java.html >> >> Cheers, >> Chris >> --http://blog.rebertia.com > > Maybe I'm not using Get right either. I'm wrapping functions. > > def AbbeGet(self, Lens): > """ > Get the Abbe Number V for the material > where > V = (Nd - 1)/(Nf - Nc) > where the Index of Refractions are > Nd at the Fraunhofer D line 0.5892um > Nf at the Fraunhofer F line 0.4861um > Nc at the Fraunhofer C line 0.6563um > """ > > Nd = Lens.Mat.NtGet(0.5892) > Nf = Lens.Mat.NtGet(0.4861) > Nc = Lens.Mat.NtGet(0.6563) > > if (Nf - Nc) != 0: > V = (Nd - 1)/(Nf - Nc) > else: > V = 1e6 > > return V > > # end AbbeGet Consider this piece of code: x = 2*sin( angle ) versus this: x = 2*get_sin( angle ) or this: x = 2*sin_get( angle ) Cheers & hth., - Alf From clp2 at rebertia.com Fri Feb 5 16:53:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Feb 2010 13:53:57 -0800 Subject: method names nounVerb or verbNoun In-Reply-To: References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <50697b2c1002051353o5031b76el6f6f0fcd540bbf64@mail.gmail.com> On Fri, Feb 5, 2010 at 1:49 PM, Wanderer wrote: > On Feb 5, 3:26?pm, Chris Rebert wrote: >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: >> > Which is the more accepted way to compose method names nounVerb or >> > verbNoun? >> >> > For example voltageGet or getVoltage? getVoltage sounds more normal, >> > but voltageGet is more like voltage.Get. I seem to mix them and I >> > should probably pick one way and stick with it. >> >> Use properties[1] and just call it `voltage`. Python is not Java [2]; >> explicit getters/setters are unpythonic. >> >> [1]http://docs.python.org/library/functions.html#property > > Maybe I'm not using Get right either. I'm wrapping functions. > > ? ?def AbbeGet(self, Lens): > ? ? ? ?""" > ? ? ? ?Get the Abbe Number V for the material > ? ? ? ?where > ? ? ? ?V = (Nd - 1)/(Nf - Nc) > ? ? ? ?where the Index of Refractions are > ? ? ? ?Nd at the Fraunhofer D line 0.5892um > ? ? ? ?Nf at the Fraunhofer F line 0.4861um > ? ? ? ?Nc at the Fraunhofer C line 0.6563um > ? ? ? ?""" > > ? ? ? ?Nd = Lens.Mat.NtGet(0.5892) > ? ? ? ?Nf = Lens.Mat.NtGet(0.4861) > ? ? ? ?Nc = Lens.Mat.NtGet(0.6563) > > ? ? ? ?if (Nf - Nc) != 0: > ? ? ? ? ? ?V = (Nd - 1)/(Nf - Nc) > ? ? ? ?else: > ? ? ? ? ? ?V = 1e6 > > ? ? ? ?return V This isn't even really a method; you don't refer to "self" in the body at all. Why isn't it just a function? Cheers, Chris -- http://blog.rebertia.com From cmpython at gmail.com Fri Feb 5 16:56:29 2010 From: cmpython at gmail.com (CM) Date: Fri, 5 Feb 2010 13:56:29 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <65c717dd-826d-4e8e-8dd3-8a0a90df7b86@o26g2000vbd.googlegroups.com> > GvR got it right when he discarded the superfluous semicolons from the ends > of statements--and then he ADDS superfluous colons to the ends of control > statements? It will probably be as much of a shock to you as it was to me > when I learned after studying parsing that colons, semicolons, "then"'s and > "do"'s, etc., ?are simply noise tokens that serve no purpose except to > clutter up the source. Some argue that the colon is a useful visual cue that aids in readability and that "explicit is better than implicit". I think one can feel either way about it. For my part, I prefer to have colons at that point, because it serves as a mental primer that a certain type of block follows. Semi-colons at the end of statements don't seem to provide any mental priming for me that can't better be served by a line break. > As for enforced indentation, back in the late 60's when I was a programming > newbie I remember thinking how cool it would be to just indent the > statements controlled by for loops (we didn't have none of them fancy while > loops in FORTRAN back then! :-) ) ?Not too long after that I saw the havoc > that a buggy editor could wreak on nicely-formatted source. :-( Formatting > held hostage to a significant, invisible whitespace char? An inevitable > accident waiting to happen! Not good, Guido; not good at all. First, why would you tolerate a buggy editor? I've had my share of challenges in learning Python, but indentation problems would be about 403rd down on the list. A simple indentation error is shown in my editor that immediately gets fixed. No havoc at all. And I also know that every piece of Python code I ever get from others *has* to be readable (at least in terms of the very visually helpful indented blocks). Che Che > > That'll do for starters. :-) From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:02:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:02:42 GMT Subject: YAML (was: Python and Ruby) References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <7536f9c0-a36a-479d-ba95-9405b13793fd@e25g2000yqh.googlegroups.com> <981c8f1e-6c03-4869-96aa-f8ec10276ba6@k2g2000pro.googlegroups.com> <993f09ff-f09e-4c8e-b8fd-99e4180d3528@k2g2000pro.googlegroups.com> <877hqusy22.fsf@castleamber.com> <1944d953-25ad-440b-9317-a7a4b4de6dac@f17g2000prh.googlegroups.com> <87eil1ddjp.fsf_-_@castleamber.com> <00f4bb3a$0$15566$c3e8da3@news.astraweb.com> Message-ID: <037c81ba$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 09:22:03 -0500, Lou Pecora wrote: [...] >> > That's what I needed. 3 lines to write or read a inhomogeneous >> > collection of variables. >> >> Easy, but also quick and dirty -- good enough for small scripts, but >> not really good enough for production applications. [...] > I understand where you are coming from: Production Code. I was just > making a point about Python and my code is only used by me. I can edit > the file for the simple I/O I do. I am not recommending this way for > everyone. Just an example. We're in violent agreement then :) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:19:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:19:11 GMT Subject: which References: <4B6C2E1E.7000201@sequans.com> <4B6C3919.3050300@sequans.com> Message-ID: <037c8597$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 16:52:19 +0100, mk wrote: > assert isinstance(cmd, basestring) or cmd is None, "cmd should be string > or None" Do not use assertions for input validation. That's not what they're for. assert is compiled away when you run your code with the -O switch, which means that the test may never be made at all. You should limit assertions for testing "this can never happen" situations, verifying pre- and post- conditions, checking the internal logic of your code, and similar. See also: http://nedbatchelder.com/text/assert.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:19:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:19:31 GMT Subject: method to intercept string formatting % operations References: <6ccc5e49-bf38-4aff-8f9b-e53917d11944@3g2000yqn.googlegroups.com> Message-ID: <037c85ab$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 16:49:00 +0100, Jean-Michel Pichavant wrote: > Anyway why would you want to use the tuple form ? it's beaten in every > aspect by the dictionary form. Except convenience, efficiency and readability. "%s %s" % (1, 2) versus "%(a)s %(b)s" % {'a': 1, 'b': 2} I'm all in favour of the second form when you need it. But you certainly don't need it all time. -- Steven From phlip2005 at gmail.com Fri Feb 5 17:19:36 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 5 Feb 2010 14:19:36 -0800 (PST) Subject: reconstruct the source of a lambda from its func_code, func_name, etc Message-ID: <03a5232b-fdcb-48f9-926e-bdd6e2e4b638@l24g2000prh.googlegroups.com> Thy Pon: Has anyone figured out how to reflect a passed function, such as a lambda, all the way back to its source? I am aware than func_code knows the file name and line number; I would rather not use them to read the file because the lambda might not start in the first column. I will go with this option until someone suggests a better fix! -- Phlip http://penbird.tumblr.com/ From news123 at free.fr Fri Feb 5 17:20:58 2010 From: news123 at free.fr (News123) Date: Fri, 05 Feb 2010 23:20:58 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> Message-ID: <4b6c99ca$0$5907$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: > >> I wrote a small xmlrpc client on Windows 7 with python 2.6 >> >> srv = xmlrpclib.Server('http://localhost:80') >> >> I was able to perform about 1 rpc call per second >> >> After changing to >> srv = xmlrpclib.Server('http://127.0.0.1:80') >> >> I was able to perform about 10 to 16 rpc calls per second. > > Not necesarily. There is another difference: 127.0.0.1 is an IPv4 > address, localhost maps to both IPv4 and IPv6 addresses (::1) > > I vaguely remember a problem with that - IPv6 is tried first, doesn't > work, only then IPv4, and that slows down the whole process. > Try disabling completely the IPv6 stack, if you don't need it. How can I completely disable IP6. I went to my network device and disabled IPV6 under properties. The XMRPC calls were stull slow. bye N From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:21:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:21:05 GMT Subject: which References: Message-ID: <037c8609$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 15:21:05 +0100, mk wrote: > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) > else: > self.cmd = cmd > > or > > self.cmd = cmd > if isinstance(cmd, str): > self.cmd = cmd.replace(r'${ADDR}',ip) Whichever one you like. The differences are insignificance, and essentially boil down to personal preference. -- Steven From wanderer at dialup4less.com Fri Feb 5 17:21:55 2010 From: wanderer at dialup4less.com (Wanderer) Date: Fri, 5 Feb 2010 14:21:55 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <36952f27-c825-4ab8-bd2e-7dff097075fd@d30g2000vbl.googlegroups.com> On Feb 5, 4:53?pm, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 1:49 PM, Wanderer wrote: > > On Feb 5, 3:26?pm, Chris Rebert wrote: > >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > >> > Which is the more accepted way to compose method names nounVerb or > >> > verbNoun? > > >> > For example voltageGet or getVoltage? getVoltage sounds more normal, > >> > but voltageGet is more like voltage.Get. I seem to mix them and I > >> > should probably pick one way and stick with it. > > >> Use properties[1] and just call it `voltage`. Python is not Java [2]; > >> explicit getters/setters are unpythonic. > > >> [1]http://docs.python.org/library/functions.html#property > > > Maybe I'm not using Get right either. I'm wrapping functions. > > > ? ?def AbbeGet(self, Lens): > > ? ? ? ?""" > > ? ? ? ?Get the Abbe Number V for the material > > ? ? ? ?where > > ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > ? ? ? ?where the Index of Refractions are > > ? ? ? ?Nd at the Fraunhofer D line 0.5892um > > ? ? ? ?Nf at the Fraunhofer F line 0.4861um > > ? ? ? ?Nc at the Fraunhofer C line 0.6563um > > ? ? ? ?""" > > > ? ? ? ?Nd = Lens.Mat.NtGet(0.5892) > > ? ? ? ?Nf = Lens.Mat.NtGet(0.4861) > > ? ? ? ?Nc = Lens.Mat.NtGet(0.6563) > > > ? ? ? ?if (Nf - Nc) != 0: > > ? ? ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > ? ? ? ?else: > > ? ? ? ? ? ?V = 1e6 > > > ? ? ? ?return V > > This isn't even really a method; you don't refer to "self" in the body > at all. Why isn't it just a function? > > Cheers, > Chris > --http://blog.rebertia.com Okay, I guess it should be a function called abbe() instead of a method called AbbeGet(). That should solve the problem of trying to remember whether I called it GetAbbe or AbbeGet. Thanks From bartc at freeuk.com Fri Feb 5 17:22:39 2010 From: bartc at freeuk.com (bartc) Date: Fri, 05 Feb 2010 22:22:39 GMT Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: "Steve Holden" wrote in message news:mailman.1998.1265399766.28905.python-list at python.org... > Arnaud Delobelle wrote: >> Robert Kern writes: >> >>> I prefer Guido's formulation (which, naturally, I can't find a direct >>> quote for right now): if you expect that a boolean argument is only >>> going to take *literal* True or False, then it should be split into >>> two functions. >> >> So rather than three boolean arguments, would you have eight functions? >> > If there's genuinely a need for that functionality, yes. So you want a function such as drawtext(s, bold=true, italic=false, underline=true) to be split into: drawtext(s) drawtextb(s) drawtexti(s) drawtextu(s) drawtextbi(s) drawtextbu(s) drawtextiu(s) drawtextbiu(s) Which of course is going to be fun if the bold/italic/underline values are not constants; instead of writing: drawtext(s,b,i,u) you have to say: if b==0 and i==0 and u==0: drawtext(s) elif b==1 and i==0 and u==0: drawtextb(s) and so on. With half-a-dozen or more booleans, this becomes completely impractical. -- Bartc From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:26:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:26:03 GMT Subject: Python's Reference And Internal Model Of Computing Languages References: <7ed330b7-8bc2-4eac-be92-615e8b865fd6@z10g2000prh.googlegroups.com> Message-ID: <037c8733$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 09:53:33 -0600, David Thole wrote: > I read this....and am a tiny bit confused about the actual problem. > > It's not exactly complex to realize that something like: a = b = array > that a and b both point to the array. > > Logically speaking, I'm not sure how one could assume that the same > assignment would yield a and b point to the same duplicate array. It's an easy mistake to make, if you don't understand Python's object model: >>> a = b = 2 >>> a += 1 >>> a, b (3, 2) >>> a = b = [2] >>> a[0] += 1 >>> a, b ([3], [3]) For the non-Python coders reading, the difference is that ints are immutable, and hence a += 1 assigns a to a new int, leaving b untouched, but lists are mutable, hence a[0] += 1 mutates the list which both a and b refer to. This is a Good Thing, but it is one of the things which give newcomers some trouble. -- Steven From news123 at free.fr Fri Feb 5 17:26:48 2010 From: news123 at free.fr (News123) Date: Fri, 05 Feb 2010 23:26:48 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> Message-ID: <4b6c9b28$0$10494$426a74cc@news.free.fr> Hi JM, Jean-Michel Pichavant wrote: >> Gabriel Genellina wrote: >> >>> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >>> >>> >>>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>>> >>>> srv = xmlrpclib.Server('http://localhost:80') >>>> >>>> I was able to perform about 1 rpc call per second >>>> >>>> >>>> After changing to >>>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>>> >>>> I was able to perform about 10 to 16 rpc calls per second. >>>> > > Or you can simply use an explicit external address. Most of the time > xmlRPC server/clients are used between distant machines. > If your are using localhost for test purpose, then binding your server > on its external IP instead of the local one could solve your problem > (wihtout removing the IPV6 stack). > > import socket > > # server > server = SimpleXMLRPCServer((socket.gethostname(), 5000), > logRequests=False, allow_none=True) > > > # client > xmlrpclib.ServerProxy("http://%s.yourdomain.com:%s" % > (socket.gethostname(), 5000)) Well This was exactly my question. for virtual web servers I cannot just use the IP-address. some XMLRPC servers do need the histname within the HTTP-POST request. if I just replaced the hostname with the IP addres, then certain servers would not be accessable. I had to use the IP-address for connecteing, but to pass the hostname in the HTTP-POST request. I wondered how to convince puthon's SimpleXMLRPCServer (or any other standard python xmlrpc server), such, that I can obtain above mentioned goal. bye N > PS : just wondering if using the port 80 is legal If nothing else on the host runs on port 80 the answer is yes. From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:31:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:31:32 GMT Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <037c887c$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 11:53:08 -0800, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, +0.5 for getVoltage +1 get_voltage -1 for voltageGet or voltage_get > but > voltageGet is more like voltage.Get. According to PEP 8, the style guide for the standard library, method names should use lowercase initial letter, so you should have voltage.get. Following PEP 8 isn't compulsory, but it is recommended unless you want a bunch of busy-body coders telling you you need to follow PEP 8 :) > I seem to mix them and I should > probably pick one way and stick with it. Yes. -- Steven From nobody at nowhere.com Fri Feb 5 17:41:22 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 05 Feb 2010 22:41:22 +0000 Subject: Repost: Read a running process output References: <429b842a-6161-4610-9c4e-eb84dcebf844@f17g2000prh.googlegroups.com> Message-ID: On Fri, 05 Feb 2010 03:57:17 -0800, Ashok Prabhu wrote: > I very badly need this to work. I have been googling out for a week > with no significant solution. I open a process p1 which does keeps > running for 4+ hours. It gives some output in stdout now and then. I > open this process with subprocess.Popen and redirect the stdout to > PIPE. However when I read the output with readline it blocks waiting > forever. I need to read from p1.stdout till what it has in the PIPE. > Can someone help me out with the exact code change that can accomplish > the task. > > from subprocess import * > > p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True) > > while 1: > line=p1.stdout.readline() > print line The answer is essentially the same one I gave in response to your post entitled "read a process output with subprocess.Popen" yesterday. You need to persuade the command to line-buffer its output rather than block-buffering it. If the command insists on block-buffering, you're out of luck; there's no way that Python can force it to do otherwise. You might be able to persuade the command to use line-buffering by using a pty rather than a pipe for its stdout, although that depends upon os.openpty() being available on your platform (the documentation only says "Availability: some flavors of Unix"). From g.statkute at gmail.com Fri Feb 5 17:42:23 2010 From: g.statkute at gmail.com (gintare statkute) Date: Sat, 6 Feb 2010 00:42:23 +0200 Subject: execute sqlite3 dot commands in python Message-ID: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Does anybody know if it possible to execute sqlite3 dot commands in python? dovanotas:/pages/links# python Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> sqlite3 .help Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'help' >>> the same with other commands: .databases .tables http://www.sqlite.org/sqlite.html regards, gintare From robert.kern at gmail.com Fri Feb 5 17:45:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 05 Feb 2010 16:45:38 -0600 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: On 2010-02-05 16:22 PM, bartc wrote: > > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) > > Which of course is going to be fun if the bold/italic/underline values > are not constants; instead of writing: > > drawtext(s,b,i,u) > > you have to say: > > if b==0 and i==0 and u==0: > drawtext(s) > elif b==1 and i==0 and u==0: > drawtextb(s) > > and so on. With half-a-dozen or more booleans, this becomes completely > impractical. Then you refactor to drawtext(s, font) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:45:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:45:51 GMT Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: <037c8bd7$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 12:26:38 -0800, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 11:53 AM, Wanderer > wrote: >> Which is the more accepted way to compose method names nounVerb or >> verbNoun? >> >> For example voltageGet or getVoltage? getVoltage sounds more normal, >> but voltageGet is more like voltage.Get. I seem to mix them and I >> should probably pick one way and stick with it. > > Use properties[1] and just call it `voltage`. Python is not Java [2]; > explicit getters/setters are unpythonic. But sometimes you still need methods or functions of the form verb_noun. For instance, if getting or setting the voltage is an expensive operation, you don't want to fool the user into thinking it is a cheap attribute access. Or get_voltage might be a stand-alone function rather than a method. Or the getter might allow additional arguments. The admonition to avoid getters and setters isn't meant to prohibit *any* method which has a get/set in the name (whether implicit or explicit). It's meant as an antidote to the Java idiom of making *every* attribute private and accessing them via getters/setters, even when all they do is merely get/set the contents of the attribute. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:48:37 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:48:37 GMT Subject: reconstruct the source of a lambda from its func_code, func_name, etc References: <03a5232b-fdcb-48f9-926e-bdd6e2e4b638@l24g2000prh.googlegroups.com> Message-ID: <037c8c7d$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 14:19:36 -0800, Phlip wrote: > Thy Pon: > > Has anyone figured out how to reflect a passed function, such as a > lambda, all the way back to its source? Use the dis module to disassemble the byte code to human readable form, then write some sort of decompiler to translate it back to Python. The second half is the difficult part... -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 17:52:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 22:52:24 GMT Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> Message-ID: <037c8d60$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: > Ethan Furman wrote: > >> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ choose_python.pdf >> >> > Choose to get your difficult questions about threads in Python ignored. > Oh well.. With an attitude like that, you're damn lucky if you don't get kill- filed. It was SIX MINUTES since you posted your question about timers, what did you expect? Threads are hard, and many people don't use them at all. You might never get an answer, even without alienating people. Complaining after six DAYS might be acceptable, if you do it with a sense of humour, but after six minutes? Advice on public forums is free, but it doesn't come with an guaranteed response time. If you want a Service Level Agreement, you will need to pay somebody for it. -- Steven From steve at holdenweb.com Fri Feb 5 17:54:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 17:54:52 -0500 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6c99ca$0$5907$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6c99ca$0$5907$426a74cc@news.free.fr> Message-ID: <4B6CA1BC.3060401@holdenweb.com> News123 wrote: > Hi Gabriel, > > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >> >>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>> >>> srv = xmlrpclib.Server('http://localhost:80') >>> >>> I was able to perform about 1 rpc call per second >>> >>> After changing to >>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>> >>> I was able to perform about 10 to 16 rpc calls per second. >> Not necesarily. There is another difference: 127.0.0.1 is an IPv4 >> address, localhost maps to both IPv4 and IPv6 addresses (::1) >> >> I vaguely remember a problem with that - IPv6 is tried first, doesn't >> work, only then IPv4, and that slows down the whole process. >> Try disabling completely the IPv6 stack, if you don't need it. > > > > How can I completely disable IP6. > > I went to my network device and disabled IPV6 under properties. The > XMRPC calls were stull slow. > There's not a lot of point taking actions like disabling IPv6 until you actually know what the cause of the problem is (though I suppose a few likely-sounding actions are worth taking if they don't require much effort). Sounds to me like you need to get WireShark or some similar protocol analyzer on the network and determine what traffic is passing across the network. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 5 17:54:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 17:54:52 -0500 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6c99ca$0$5907$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6c99ca$0$5907$426a74cc@news.free.fr> Message-ID: <4B6CA1BC.3060401@holdenweb.com> News123 wrote: > Hi Gabriel, > > Gabriel Genellina wrote: >> En Thu, 04 Feb 2010 19:34:20 -0300, News123 escribi?: >> >>> I wrote a small xmlrpc client on Windows 7 with python 2.6 >>> >>> srv = xmlrpclib.Server('http://localhost:80') >>> >>> I was able to perform about 1 rpc call per second >>> >>> After changing to >>> srv = xmlrpclib.Server('http://127.0.0.1:80') >>> >>> I was able to perform about 10 to 16 rpc calls per second. >> Not necesarily. There is another difference: 127.0.0.1 is an IPv4 >> address, localhost maps to both IPv4 and IPv6 addresses (::1) >> >> I vaguely remember a problem with that - IPv6 is tried first, doesn't >> work, only then IPv4, and that slows down the whole process. >> Try disabling completely the IPv6 stack, if you don't need it. > > > > How can I completely disable IP6. > > I went to my network device and disabled IPV6 under properties. The > XMRPC calls were stull slow. > There's not a lot of point taking actions like disabling IPv6 until you actually know what the cause of the problem is (though I suppose a few likely-sounding actions are worth taking if they don't require much effort). Sounds to me like you need to get WireShark or some similar protocol analyzer on the network and determine what traffic is passing across the network. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 18:01:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 23:01:46 GMT Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <037c8f92$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 15:22:25 -0600, Bruce C. Baker wrote: > GvR got it right when he discarded the superfluous semicolons from the > ends of statements--and then he ADDS superfluous colons to the ends of > control statements? They're not superfluous, they have a real, practical use. > It will probably be as much of a shock to you as it > was to me when I learned after studying parsing that colons, semicolons, > "then"'s and "do"'s, etc., are simply noise tokens that serve no > purpose except to clutter up the source. Incorrect, they do have a use. Hint: source code isn't just read by parsers. > As for enforced indentation, back in the late 60's when I was a > programming newbie I remember thinking how cool it would be to just > indent the statements controlled by for loops (we didn't have none of > them fancy while loops in FORTRAN back then! :-) ) Not too long after > that I saw the havoc that a buggy editor could wreak on nicely-formatted > source. :-( As opposed to how resistant source code is to buggy editors that make other changes to source code. If your editor flips the order of characters, or turns the digit "4" into "7", or deletes braces, or inserts "#" characters at the start of lines, you would dump the editor in a second. But if the editor inserts or removes whitespace, we're supposed to continue using the editor and change the language? > Formatting held hostage to a significant, invisible > whitespace char? It's not invisible. You can see it by noticing the space between the left margin and the start of non-whitespace text. Can you see the difference between these? hello world hello world Of course you can, unless your News reader or mail client is buggy. If it is deleting whitespace at the start of lines, how can you trust it not to delete anything else? Trailing spaces and tabs, on the other hand, *are* invisible. But they're also insignificant, and so don't matter. (Except for one little tiny corner case, which I shall leave as an exercise for the advanced reader.) -- Steven From news123 at free.fr Fri Feb 5 18:03:51 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 00:03:51 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows Message-ID: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Hi, I'm using an XMLRPC server under Windows. What I wonder is how I could create a server, that can be killed with CTRL-C The server aborts easily with CTRL-BREAK but not with CTRL-C (under Windows) If I press CTRL-C it will only abort when the next RPC call occurs. It seems it is blocking in the select() call in the handle_request() function. Is there any trick, which I overlook? thanks in advance for ideas and bye N From aahz at pythoncraft.com Fri Feb 5 18:08:08 2010 From: aahz at pythoncraft.com (Aahz) Date: 5 Feb 2010 15:08:08 -0800 Subject: SQLite3: preventing new file creation References: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> Message-ID: In article <6cf467a9-99d7-4fda-99da-075b4b38e3e0 at k6g2000prg.googlegroups.com>, Gnarlodious wrote: > >Every time I say something like: > >connection=sqlite3.connect(file) > >sqlite creates a new database file. Can this behavior be suppressed >through SQLite? Or am I forced to check for the file existing first? Check first -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at holdenweb.com Fri Feb 5 18:11:04 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 18:11:04 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: bartc wrote: > > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) > The case I was discussing was where the function was required to implement significantly different logic flow for the two different values of the Boolean. > Which of course is going to be fun if the bold/italic/underline values > are not constants; instead of writing: > > drawtext(s,b,i,u) > > you have to say: > > if b==0 and i==0 and u==0: > drawtext(s) > elif b==1 and i==0 and u==0: > drawtextb(s) > > and so on. With half-a-dozen or more booleans, this becomes completely > impractical. > It's completely impractical the way you've written it anyway, since the drawtext function shouldn't be required to know whether it's printing bold, italic, etc. - those properties should be attributes of the font. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 5 18:19:09 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 05 Feb 2010 18:19:09 -0500 Subject: execute sqlite3 dot commands in python In-Reply-To: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: gintare statkute wrote: > Does anybody know if it possible to execute sqlite3 dot commands in python? > > dovanotas:/pages/links# python > Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import sqlite3 >>>> sqlite3 .help > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'module' object has no attribute 'help' > > the same with other commands: > .databases > .tables > http://www.sqlite.org/sqlite.html > No. That's not how you pass commands to sqlite3 - you connect to a database, create a cursor on the connection, and then execute SQL statements (not sqlite commands) on the cursor. Like this: >>> import sqlite3 >>> c = sqlite3.connect("deleteme") >>> cu = c.cursor() >>> cu.execute(".help") Traceback (most recent call last): File "", line 1, in sqlite3.OperationalError: near ".": syntax error >>> cu.execute("""\ ... CREATE TABLE test( ... a int primary key, ... b varchar)""") >>> As you can see, the cursor's execute() method expects SQL statements. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Fri Feb 5 18:29:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 05 Feb 2010 23:29:10 GMT Subject: Dreaming of new generation IDE References: Message-ID: <037c95fe$0$1292$c3e8da3@news.astraweb.com> On Fri, 05 Feb 2010 22:22:39 +0000, bartc wrote: > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight >>> functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) No, of course not. But one might prefer a function with an alternate API, such as: style = TextStyle(bold=True, underline=True, size=12, font='helvetica') drawtext(s, style) style.italic = True drawtext(s, style) Other alternatives might be to pass the style information as a string "BU" (bold underline) or a numeric flag (BOLD & UNDERLINE). In general, if your implementation looks like this: def function(args, flag): if flag: do_this() else: do_that() then this is a good candidate for splitting into multiple functions. Likewise: def function(args, flag): result = do_this() if flag: result = modify(result) return result or similar. The point is that such a function uses the flag to select between two different semantics. From a API perspective, it is generally better to make each behaviour an independent function (perhaps calling a third, private, function implementing any common behaviour). For example, instead of: def extreme(sequence, biggest=True): """Return the extreme value from sequence. If biggest is a true value, return the maximum value, otherwise return the smallest. """ pass # implementation left as an exercise have two functions, max and min. -- Steven From clp2 at rebertia.com Fri Feb 5 18:36:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 5 Feb 2010 15:36:19 -0800 Subject: method names nounVerb or verbNoun In-Reply-To: <037c8bd7$0$1292$c3e8da3@news.astraweb.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> <037c8bd7$0$1292$c3e8da3@news.astraweb.com> Message-ID: <50697b2c1002051536u4f29be9laac873fcd212a7b9@mail.gmail.com> On Fri, Feb 5, 2010 at 2:45 PM, Steven D'Aprano wrote: > On Fri, 05 Feb 2010 12:26:38 -0800, Chris Rebert wrote: >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer >> wrote: >>> Which is the more accepted way to compose method names nounVerb or >>> verbNoun? >>> >>> For example voltageGet or getVoltage? getVoltage sounds more normal, >>> but voltageGet is more like voltage.Get. I seem to mix them and I >>> should probably pick one way and stick with it. >> >> Use properties[1] and just call it `voltage`. Python is not Java [2]; >> explicit getters/setters are unpythonic. > > But sometimes you still need methods or functions of the form verb_noun. True, but when the verb is "get" and you're using Python, your design probably merits another going-over. If the OP hadn't used "get" as their example, I would have answered significantly differently. > For instance, if getting or setting the voltage is an expensive > operation, you don't want to fool the user into thinking it is a cheap > attribute access. I strongly disagree with this rationale as it violates the Uniform Access Principle (http://en.wikipedia.org/wiki/Uniform_access_principle). Though I concede Python's builtins don't adhere to the UAP. > Or get_voltage might be a stand-alone function rather > than a method. The OP originally said quite explicitly it was a method in their original post. (Though they since wisely changed their code structure so it's not.) > Or the getter might allow additional arguments. True; but before the OP posted the actual function body, there was no way to know whether it did. Lacking such info, I assumed the simplest and most frequent case, namely that it didn't take any args. > The admonition to avoid getters and setters isn't meant to prohibit *any* > method which has a get/set in the name (whether implicit or explicit). > It's meant as an antidote to the Java idiom of making *every* attribute > private and accessing them via getters/setters, even when all they do is > merely get/set the contents of the attribute. True. Again, before the OP posted the method body, there was no way to know it wasn't a trivial Java-esque getter. Cheers, Chris -- http://blog.rebertia.com From jackdied at gmail.com Fri Feb 5 18:43:13 2010 From: jackdied at gmail.com (Jack Diederich) Date: Fri, 5 Feb 2010 18:43:13 -0500 Subject: list.extend([]) Question In-Reply-To: <5d1a32001002050831r6233b751mcbc5f55fb9a2c1b4@mail.gmail.com> References: <088e7a24-b0d0-4d43-bee7-193e5eaefe57@b7g2000pro.googlegroups.com> <5d1a32001002050831r6233b751mcbc5f55fb9a2c1b4@mail.gmail.com> Message-ID: On Fri, Feb 5, 2010 at 11:31 AM, Gerald Britton wrote: > I think it's because when you do ['a'].extend([]) or whatever, the > result is whatever the method "extend" returns. ?But "extend" has no > return value, hence you will see None if you do this interactively. > That sums it up. In Python the convention is to raise an exception on error, return a new value in the case where a new value is created, and - as in this case - to return None for modification of an existing value. Returning "None" is vexing if you are used to another language that has a different convention but is expected for well behaved python libraries. So yeah, Python does it that way because the intent is to loudly and regularly announce that something was modified or to loudly and regularly announce that something new was /not/ created. It's a boring story with no whiz-bang feature behind it, but I like that the language behaves that way for exactly that reason. -Jack From python.list at tim.thechases.com Fri Feb 5 19:00:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 05 Feb 2010 18:00:44 -0600 Subject: Your beloved python features In-Reply-To: <037c8f92$0$1292$c3e8da3@news.astraweb.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <037c8f92$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B6CB12C.4020705@tim.thechases.com> Steven D'Aprano wrote: > Trailing spaces and tabs, on the other hand, *are* invisible. But they're > also insignificant, and so don't matter. > > (Except for one little tiny corner case, which I shall leave as an > exercise for the advanced reader.) Drat, now I'm gonna be up at odd hours tonight dredging my brain for such corner cases. My catalog so far: - triple-quoted multi-line strings - "\" line-continuations don't work with trailing whitespace (though Vim's syntax highlighting flags them, changing their color if there's whitespace afterwards) - files that read themselves (or perhaps depend on introspection/debugging modules to read themselves) Any others that I missed? -tkc From mentifex at myuw.net Fri Feb 5 19:02:53 2010 From: mentifex at myuw.net (Forthminder) Date: Fri, 5 Feb 2010 16:02:53 -0800 (PST) Subject: Google AI Challenge at U of Waterloo Message-ID: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Contest runs from 4 February to 26 February 2010. You may choose a programming language, such as Java, C++, Python, Ruby or Haskell. See details at http://csclub.uwaterloo.ca/contest/problem_description.php Bonne Chance! Mentifex -- http://www.scn.org/~mentifex/mindforth.txt From wgaggioli at gmail.com Fri Feb 5 19:08:06 2010 From: wgaggioli at gmail.com (William Gaggioli) Date: Fri, 5 Feb 2010 19:08:06 -0500 Subject: Calendar GUI Message-ID: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> Hello Everyone, I'm working on setting up some software for a Peruvian non-profit to help them organize their incoming volunteers. One of the features I'd like to add is a calendar-like view of the different volunteers arrival dates and staying time, with potentially some other info through some double-click action. Rather than writing a calendar gui myself, is there some open-source calendar program you guys could recommend that I could plug into? It has to be run locally, as the internet isn't so reliable down here, but other than that something simple and clean is ideal. Thanks, Will -------------- next part -------------- An HTML attachment was scrubbed... URL: From gabriel at opensuse.org Fri Feb 5 19:14:33 2010 From: gabriel at opensuse.org (Gabriel) Date: Fri, 5 Feb 2010 21:14:33 -0300 Subject: Calendar GUI In-Reply-To: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> Message-ID: <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: > Hello Everyone, > > I'm working on setting up some software for a Peruvian non-profit to help > them organize their incoming volunteers. One of the features I'd like to add > is a calendar-like view of the different volunteers arrival dates and > staying time, with potentially some other info through some double-click > action. Rather than writing a calendar gui myself, is there some open-source > calendar program you guys could recommend that I could plug into? It has to > be run locally, as the internet isn't so reliable down here, but other than > that something simple and clean is ideal. > I wrote a gtk gui for google calendar. Maybe you can adapt it to your needs. http://code.google.com/p/googlecalendar-gtk/ -- Kind Regards From imuaplease at gmail.com Fri Feb 5 19:24:56 2010 From: imuaplease at gmail.com (**Group User**) Date: Fri, 5 Feb 2010 16:24:56 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <1eed1fcc-f1d1-4f71-bc05-68dddb3f17b4@s33g2000prm.googlegroups.com> On Feb 6, 7:02?am, Forthminder wrote: > Contest runs from 4 February to 26 February 2010. > > You may choose a programming language, such as > Java, C++, Python, Ruby or Haskell. > > See details at > > http://csclub.uwaterloo.ca/contest/problem_description.php > > Bonne Chance! > > Mentifex > --http://www.scn.org/~mentifex/mindforth.txt I find out that I was a donkie I was hooked up Torn Screwed up And Haskel was there at that time He got anrgy, pity For my stupidity All for best Simulation for good alone KKKKKKIIIIIIIIIIEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEENNNNNNNNNNNNNNNNNNNNNNIIEEEE From charles at declaresub.com Fri Feb 5 19:27:55 2010 From: charles at declaresub.com (Charles Yeomans) Date: Fri, 5 Feb 2010 19:27:55 -0500 Subject: Exception class documentation In-Reply-To: <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> Message-ID: <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> On Feb 5, 2010, at 2:13 PM, Gerald Britton wrote: > On Fri, Feb 5, 2010 at 12:55 PM, Charles Yeomans > wrote: >> I am so far unable to find the information I want about the >> Exception class. >> Information like the signature of __init__ seems to be >> unavailable. Any >> suggestions where I might find such information? >> > > Though not documented, some silly tests indicate that it will accept > pretty much anything: > >>>> Exception(1,2,4,54) > Exception(1, 2, 4, 54) >>>> Exception(*range(10)) > Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>>> Exception(*range(50)) > Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, > 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, > 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49) >>>> Exception('a','b','c','d','e') > Exception('a', 'b', 'c', 'd', 'e') >>>> Exception(Exception(1)) > Exception(Exception(1,),) I had also tried such tests. If you pass a single argument msg, it is assigned to the message property, and the args property is set to (msg,). If you pass more than one argument, the tuple of arguments is assigned to the args property, and nothing is assigned to the message property. I was hoping to at least find source code that provides a definitive answer. Charles Yeomans From news123 at free.fr Fri Feb 5 19:31:16 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 01:31:16 +0100 Subject: can pydoc display doc for local funcs? or other doc tools for own code Message-ID: <4b6cb854$0$28668$426a34cc@news.free.fr> Hi, often I start "pydoc -g" in a projects working directory in order to view the docstrings of my own project and in order to get a quick overview of the code structure In some cases I would like to see also to see private methods (especially when trying to understand the internals of a collegues code or even to browse throught the internals of my own code) Therefore I wonder whether pydoc could be configured such, that it would also display private methods (the ones with leading underscores) If not: What tools / methodologies would you recommend to quickly browse own / collegues source code. In many cases the function prototypes and the doc strings of public and private methods would be sufficient for me. thanks for any ideas N From gagsl-py2 at yahoo.com.ar Fri Feb 5 19:56:21 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 05 Feb 2010 21:56:21 -0300 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: > I'm using an XMLRPC server under Windows. > > What I wonder is how I could create a server, that can be killed with > CTRL-C > > The server aborts easily with CTRL-BREAK but not with CTRL-C (under > Windows) > > If I press CTRL-C it will only abort when the next RPC call occurs. > It seems it is blocking in the select() call in the handle_request() > function. Python 2.6 and up behaves exactly as you want. On previous versions you may use this: class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): ... your methods ... if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): # pre 2.6 quit = False def serve_forever(self): while not self.quit: self.handle_request() def shutdown(self): self.quit = True def server_bind(self): self.socket.settimeout(1.0) SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) -- Gabriel Genellina From wolftracks at invalid.com Fri Feb 5 21:49:08 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 05 Feb 2010 18:49:08 -0800 Subject: Drawing a zig-zag Trail in Python? In-Reply-To: References: Message-ID: On 2/5/2010 9:30 AM, Grant Edwards wrote: > On 2010-02-05, W. eWatson wrote: > >> I'd like to draw something like an animal track. Between each >> point is a line. Perhaps the line would have an arrow showing >> the direction of motion. There should be x-y coordinates >> axises. PIL? MatPlotLib, ?? > > I'd probably use gnuplot-py, but I'm probably biased since I've > been using gnuplot since way before I learned Python. > It appears this is easier than I thought. MLB's plot will do it. I can put arrows at the end of a line, and even use sleep to watch the path slowly evolving. From andrej.mitrovich at gmail.com Fri Feb 5 22:17:17 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Fri, 5 Feb 2010 19:17:17 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> <1eed1fcc-f1d1-4f71-bc05-68dddb3f17b4@s33g2000prm.googlegroups.com> Message-ID: <814cf6b9-546c-4e1c-a02b-80d84a757da5@f15g2000yqe.googlegroups.com> Sweet, something to keep my brain busy for the next couple of weeks. From nagle at animats.com Fri Feb 5 22:38:15 2010 From: nagle at animats.com (John Nagle) Date: Fri, 05 Feb 2010 19:38:15 -0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <4b6ce04c$0$1622$742ec2ed@news.sonic.net> Forthminder wrote: ... Ignore. Well-known nut. See "http://www.nothingisreal.com/mentifex_faq.html" John Nagle From fuzzy.666.chaos at gmail.com Fri Feb 5 22:54:48 2010 From: fuzzy.666.chaos at gmail.com (Jordan Uchima) Date: Fri, 5 Feb 2010 21:54:48 -0600 Subject: "Nim" game being created, no GUI used... Need tips... Message-ID: <1b07ab151002051954hf3c946bqf4f306184228da40@mail.gmail.com> I am creating a game called Nim, but cannot get a loop going no matter what I do. What i am trying to do is get it to only accept input from 1 to 4, and keep asking for input from the same player if he/she enters in an invalid number. I also want it to stop when there is 1 or no piece(s) left, and declare the player who DID NOT take the last piece the winner. Also, how do I word the coding so that way it will make the players take turns? there are 2 players. there are 13 pieces to start with. i am using python 2.6.4 . here is my code: ----------------------------------------------------------------------------------------------------------------------------------------------- # taking pieces away player1Choice = raw_input("Well, " + namePlayer1 + " how many"\ " pieces would you like to take?\n" + range(1, 4)) player2Choice = raw_input("Well, " + namePlayer2 + " how many"\ " pieces would you like to take?\n" + range(1, 4)) # setting a variable for the number of pieces x = 13 - int(player1Choice or player2Choice) and not < 0 # to alternate turns turn = \ while player1Choice is False: print player1Choice and "There is ", x, " pieces remaining." while player1Choice is True: print player2Choice and "There is ", x, " pieces remaining." while player2Choice is False: print player2Choice and "There is ", x, " pieces remaining." while player1Choice and player2Choice is True: print player1Choice and "There is ", x, " pieces remaining." while x != range(0, 1): continue turn # to determine winner/loser loss = while x = range(0, 4) is True: print loser " loses!" + loser = \ if player1Choice = loss: print namePlayer1 + loss elif player2Choice = loss: print namePlayer2 + loss else player1Choice and player2Choice = loss: print "It's a draw!" elif player1Choice != loss: print "" elif player2Choice != loss: print "" else player1Choice and player2Choice != loss: print "Keep going! Only ", x, " pieces left!" winner = \ if player1Choice != loss: print namePlayer1 " wins!" elif player2Choice != loss: print namePlayer2 " wins!" elif player1Choice and player2Choice != loss: print "Keep going! Only ", x, " pieces left!" elif player1Choice = loss: print namePlayer1 + loss elif player2Choice = loss: print namePlayer2 + loss else player1Choice and player2Choice = loss: print "It's a draw!" # getting player's names namePlayer1 = raw_input("Hello Player 1, what is your name?\n") namePlayer2 = raw_input("Hello Player 2, what is your name?\n") # greeting players print "Hello", namePlayer1, "and", namePlayer2, "!" # instructions print "Welcome to the game of Nim, where you actually have to think!\n\n"\ "The instructions are simple: you can take 1 to 4 pieces at a time,"\ " but, if you take the last piece, YOU LOSE!\n\n"\ "To take pieces, simply type in the number of pieces you want"\ " to take, and press the ENTER (or in some cases, RETURN) key.\n\n"\ "However, you can NOT take 0 pieces, or more than 4 pieces!\n\n"\ "Well then, let's get started! :-)" # starting the game print turn --------------------------------------------------------------------------------------------------------------------------------------------- All help and insertions would be appreciated. You can reach me at fuzzy.666.chaos at gmail.com . Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From toylet.toylet at gmail.com Fri Feb 5 23:18:40 2010 From: toylet.toylet at gmail.com (Man-wai Chang to The Door (24000bps)) Date: Sat, 06 Feb 2010 12:18:40 +0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: On 06-Feb-10 08:02, Forthminder wrote: > Contest runs from 4 February to 26 February 2010. > http://csclub.uwaterloo.ca/contest/problem_description.php > Bonne Chance! It's definitely *not* exactly a programming challenge, but algorithm challenge. A programming (only) challenge should only require the players to write codes to implement an algorithm. This one requires both algorithm design & programming. -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.7 ^ ^ 12:16:01 up 6 days 20:22 2 users load average: 0.45 0.26 0.09 ???! ???! ???! ???! ???! ???! ????? (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa From gherron at islandtraining.com Fri Feb 5 23:55:54 2010 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 05 Feb 2010 20:55:54 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> Message-ID: <4B6CF65A.6030703@islandtraining.com> Craig Berry wrote: > Is there any way to get mouse wheel events from glut in PyOpenGL? > > Use Linux. (On Linux, Glut returns mouse wheel events as buttons 4 and 5), or use FreeGlut. On both Windows and Linux freeglut returns mouse wheel events as buttons 4 and 5. Gary Herron From darnzen at gmail.com Sat Feb 6 00:05:53 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 5 Feb 2010 21:05:53 -0800 (PST) Subject: WCK and PIL Message-ID: <1fbe5e4b-2179-410b-9f76-9d65a7a08dce@k19g2000yqc.googlegroups.com> I've written an app using the wck library (widget construction kit, see http://www.effbot.org), in addition to the wckGraph module. What I'd like to do, is take the output of one of my windows (happens to be a graph), and save it as a *.png or *.gif. I was planning on using the PIL for this. I'd like to use the code I have as is, without re- writing all the graphic calls to use PIL methods. WCK uses its own "pixmap" class for storing images in memory. I can't find any documentation or class reference for pixmap and what I find in the source is confusing. Does anyone have any direct experience with these libraries that can tell me that there's some super easy thing I'm missing? I'd love it if the wck pixmap is compatible with PIL. I don't have the time to mess with it unless I know its going to work. From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:10:08 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:10:08 -0300 Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> Message-ID: En Fri, 05 Feb 2010 17:39:07 -0300, jonny lowe escribi?: > On Feb 4, 8:20 pm, exar... at twistedmatrix.com wrote: >> On 01:56 am, jonny.lowe.12... at gmail.com wrote: >> >What I want is to have an easy way to merge input.txt and thestdout >> >so that output.txt look like: >> >> >Enter a number: 42 >> >You entered 42. >> >> >Here, the first 42 is of course from input.txt. >> >> It sounds like you might be looking forscript(1)? > > $ script -c "./y < input.txt" output.txt > Script started, file is output.txt > gimme x:you entered hello > Script done, file is output.txt Try moving the redirection out of the command: $ script -c ./y output.txt < input.txt -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:19:22 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:19:22 -0300 Subject: Dreaming of new generation IDE References: Message-ID: En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: > "Steve Holden" wrote in message > news:mailman.1998.1265399766.28905.python-list at python.org... >> Arnaud Delobelle wrote: >>> Robert Kern writes: >>> >>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>> quote for right now): if you expect that a boolean argument is only >>>> going to take *literal* True or False, then it should be split into ^^^^^^^^^^^^^^^^^^^^^^^ >>>> two functions. >>> >>> So rather than three boolean arguments, would you have eight functions? >>> >> If there's genuinely a need for that functionality, yes. > > So you want a function such as drawtext(s, bold=true, italic=false, > underline=true) to be split into: > > drawtext(s) > drawtextb(s) > drawtexti(s) > drawtextu(s) > drawtextbi(s) > drawtextbu(s) > drawtextiu(s) > drawtextbiu(s) Note the *literal* part. If you (the programmer) is likely to know the parameter value when writing the code, then the function is actually two separate functions. By example, foo.get_path(absolute=True) should be written as foo.get_absolute_path() and foo.get_relative_path() It gets worse when one parameter alters the type of the returned value, or even the number of returned values. This is an actual example: def build_image(self, zone=-1, return_sizes=False): ... if return_size: return img, sizes else: return img image = foo.build_image(3) but: image, sizes = foo.build_image(3, True) It should be split onto two separate functions; in this particular case, computing 'sizes' required actually drawing the image, so the solution was to make those 'sizes' attributes of the returned image. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:19:54 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:19:54 -0300 Subject: Import question References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> Message-ID: En Fri, 05 Feb 2010 13:21:47 -0300, Andrew Degtiariov escribi?: > Code of our project has split into several packages and we deploy the > project using buildout. > All worked fine until I need to dynamically inspect python modules. Entirely by luck, I'd say :) > ????project.api.config > ? ????project > ? ? ????api > ? ? ????config > ? ? ????settings > ? ????project.api.config.egg-info > ????project.api.contacts > ? ????project > ? ? ????api > ? ? ????contacts > ? ? ????importer > ? ? ????views > ? ????project.api.contacts.egg-info > Regular code like "import project.api.config" worked fine, but now I'm > tryed > __import__('project.api.config'): > > $ bin/python > >>>> import project.api.config >>>> __import__('project.api.config') > 'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'> You can't use dots neither in module names nor package names as they're identifiers [1]. It's like trying to use an attribute named 'foo.bar': you can handle it with getattr/setattr, but normal attribute access won't work: py> x.foo.bar = 1 Traceback (most recent call last): File "", line 1, in AttributeError: X instance has no attribute 'foo' py> setattr(x, 'foo.bar', 1) py> x.foo.bar Traceback (most recent call last): File "", line 1, in AttributeError: X instance has no attribute 'foo' py> getattr(x, 'foo.bar') 1 [1] http://docs.python.org/reference/simple_stmts.html#the-import-statement > What's wrong? We really need to split the code for several eggs and want > that all of our package's names starts from 'project.api' The only sane solution is to avoid using dots in package names. Sorry, but having project.api.config, project.api.contacts as directory names is simply crazy. Looks like you actually wanted to use this layout: project/ api/ config/ ... contacts/ ... core/ ... but made a wrong turn in the road... -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:20:13 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:20:13 -0300 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: <4B6C1BED.6090807@bluewin.ch> Message-ID: En Fri, 05 Feb 2010 10:23:57 -0300, Anthra Norell escribi?: >>> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >>> window. The OS is Windows ME. The download of 2.5 finished with a >>> warning saying that 2.5 was the highest version for Windows 9* Any >>> tips? I'd suggest a couple more tests. Open the Python interpreter and execute: py> from idlelib import idle This *should* launch IDLE, or raise an error... If nothing happens, exit the process and open another one, and execute: py> import Tkinter py> root = Tkinter.Tk() py> root.mainloop() An empty window should appear. If not, I'd say something is wrong with the Tcl/Tk libraries. > For the time being 2.4 works fine. I'd much prefer 2.5, though, because > it includes the image library (PIL), whereas 2.4 cannot even use it. PIL has an impressive compatibility record - it works with *any* Python version from 1.5.2 up. You should be able to use PIL with 2.4 without problems. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sat Feb 6 00:59:35 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sat, 06 Feb 2010 02:59:35 -0300 Subject: Simple question about Queue.Queue and threads References: Message-ID: En Fri, 05 Feb 2010 09:45:30 -0300, Frank Millman escribi?: > Assume you have a server process running, a pool of worker threads to > perform tasks, and a Queue.Queue() to pass the tasks to the workers. > > In order to shut down the server cleanly, you want to ensure that the > workers have all finished their tasks. I like the technique of putting a > None onto the queue, and have each worker check for None, put None back > onto the queue, and terminate itself. > > The main program would look something like this - > > q.put(None) > for worker in worker_threads: > worker.join() > > At this point you can be sure that each thread has completed its tasks > and terminated itself. > > However, the queue is not empty - it still has the final None in it. Yes - but who cares? :) > Is it advisable to finalise the cleanup like this? - > > while not q.empty(): > q.get() > q.task_done() > q.join() > > Or is this completely redundant? I don't see what you gain by doing that. On the other hand, you might check whether the queue contains exactly one item and it is None, just to be sure that all queued work has been done. (BTW, I'd use a different sentinel instead of None; perhaps this could not happen in your current code, but it's easy to inadvertedly put a None in the queue, stopping all workers prematurely.) -- Gabriel Genellina From torriem at gmail.com Sat Feb 6 00:59:54 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 05 Feb 2010 22:59:54 -0700 Subject: Calendar GUI In-Reply-To: <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> Message-ID: <4B6D055A.30901@gmail.com> Gabriel wrote: > On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: >> I'm working on setting up some software for a Peruvian non-profit to help >> them organize their incoming volunteers. One of the features I'd like to add >> is a calendar-like view of the different volunteers arrival dates and >> staying time, with potentially some other info through some double-click >> action. Rather than writing a calendar gui myself, is there some open-source >> calendar program you guys could recommend that I could plug into? It has to >> be run locally, as the internet isn't so reliable down here, but other than >> that something simple and clean is ideal. > > I wrote a gtk gui for google calendar. > > Maybe you can adapt it to your needs. > > http://code.google.com/p/googlecalendar-gtk/ Would this work without an internet connection? The original poster stated that internet isn't so reliable, hence the need for a local solution. From frank at chagford.com Sat Feb 6 01:30:55 2010 From: frank at chagford.com (Frank Millman) Date: Sat, 6 Feb 2010 08:30:55 +0200 Subject: Simple question about Queue.Queue and threads References: Message-ID: On Feb 6, 7:59 am, "Gabriel Genellina" wrote: > En Fri, 05 Feb 2010 09:45:30 -0300, Frank Millman > escribi?: > [...] > > However, the queue is not empty - it still has the final None in it. > > Yes - but who cares? :) > That was my point. I didn't think I needed to care, but I wanted to be sure I was not missing something. I will just discard all the final cleanup code. > > (BTW, I'd use a different sentinel instead of None; perhaps this could not > happen in your current code, but it's easy to inadvertedly put a None in > the queue, stopping all workers prematurely.) > Good advice. Thanks, Gabriel Frank From greg.ewing at canterbury.ac.nz Sat Feb 6 03:08:09 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 06 Feb 2010 21:08:09 +1300 Subject: ANN: PyGUI 2.2 Message-ID: PyGUI 2.2 is available: http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Highlights of this version: - TextEditor component with tabs, scrolling and word wrap - Classes for laying out components in rows, colums and grids - Printing support What is PyGUI? -------------- PyGUI is a cross-platform GUI toolkit designed to be lightweight and have a highly Pythonic API. -- Gregory Ewing greg.ewing at canterbury.ac.nz http://www.cosc.canterbury.ac.nz/greg.ewing/ From pavlovevidence at gmail.com Sat Feb 6 04:29:10 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Feb 2010 01:29:10 -0800 (PST) Subject: execute sqlite3 dot commands in python References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: On Feb 5, 3:19?pm, Steve Holden wrote: > gintare statkute wrote: > > Does anybody know if it possible to execute sqlite3 dot commands in python? > > > dovanotas:/pages/links# python > > Python 2.5.2 (r252:60911, Jan ?4 2009, 17:40:26) > > [GCC 4.3.2] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import sqlite3 > >>>> sqlite3 ?.help > > Traceback (most recent call last): > > ? File "", line 1, in > > AttributeError: 'module' object has no attribute 'help' > > > the same with other commands: > > .databases > > .tables > >http://www.sqlite.org/sqlite.html > > No. Well actually you can, sort of. For instance: os.system('sqlite3 :memory: .help') Carl Banks From andrewt.herd at gmail.com Sat Feb 6 04:32:58 2010 From: andrewt.herd at gmail.com (Andrew) Date: Sat, 6 Feb 2010 01:32:58 -0800 (PST) Subject: PyQt4 designer custom properties - combo box style References: Message-ID: On Feb 4, 2:59?pm, David Boddie wrote: > On Tuesday 02 February 2010 22:25, Andrew wrote: > > > I am creating custom widgets for the PyQt4 Designer. I can create > > custom properties, but I'm looking for how to create a custom property > > that has a combo box drop down. I've seen them in the example widgets > > and tried following them, but they are using pre-defined items to > > populate their property, so it's not a very clear example of how to > > get the combo box property to work. > > Can you explain a bit more about what you have seen and what you are > trying to do. Are you trying to create a property that is treated > specially by Designer or do you want to get the data for the combo > box from somewhere else? I'm attempting to create a drop down property for a custom widget I'm creating. So when in designer and you scroll down to the custom properties, under the regular widget properties, one of them would be a drop down menu. The data to populate it will be coming from our API and currently is a list of string-items. Yes, it would be treated specially by Designer, since it's the only place it would be seen. In the PyQt4\examples\designer folder, it carries a number of custom widgets that will load into designer. The datetimeedit widget creates a custom drop down menu property. The plugin pulls its information from the QtCore libraries and from the QCalander Widget. Though I am unable to find a better example or even explanation of how it's actually creating that drop down menu. > > > Is there any other examples or help for this kind of setup? > > Have you seen this article? > > ?http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html No, I haven't, thanks. That might step in the right direction. I can't run it right now, so I'm not sure if it is putting a spinbox as it's property or just the value from the spin box. > > David Andrew From keakon at gmail.com Sat Feb 6 04:33:24 2010 From: keakon at gmail.com (keakon) Date: Sat, 6 Feb 2010 01:33:24 -0800 (PST) Subject: which References: Message-ID: self.cmd = cmd.replace(r'${ADDR}',ip) if isinstance(cmd, str) else cmd From cameron.jp at gmail.com Sat Feb 6 04:40:26 2010 From: cameron.jp at gmail.com (Jeff Cameron) Date: Sat, 6 Feb 2010 01:40:26 -0800 (PST) Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: On Feb 5, 11:18?pm, "Man-wai Chang to The Door (24000bps)" wrote: > On 06-Feb-10 08:02, Forthminder wrote: > > > Contest runs from 4 February to 26 February 2010. > >http://csclub.uwaterloo.ca/contest/problem_description.php > > Bonne Chance! > > It's definitely *not* exactly a programming challenge, but algorithm > challenge. > > A programming (only) challenge should only require the players to write > codes to implement an algorithm. > > This one requires both algorithm design & programming. > > -- > ? ?@~@ ? Might, Courage, Vision, SINCERITY. > ? / v \ ?Simplicity is Beauty! May the Force and Farce be with you! > /( _ )\ (x86_64 Ubuntu 9.10) ?Linux 2.6.32.7 > ? ?^ ^ ? 12:16:01 up 6 days 20:22 2 users load average: 0.45 0.26 0.09 > ???! ???! ???! ???! ???! ???! ????? (CSSA):http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa Hello, this is Jeff Cameron, the organizer of the Google AI Challenge. I'm glad to see all this interest in our humble little contest. I wish you all the best of luck, and encourage everyone to try their hand at writing an AI for Tron! www.ai-contest.com From no.email at nospam.invalid Sat Feb 6 04:45:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Feb 2010 01:45:03 -0800 Subject: Google AI Challenge at U of Waterloo References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: <7xpr4ihf4w.fsf@ruckus.brouhaha.com> "Man-wai Chang to The Door (24000bps)" writes: > It's definitely *not* exactly a programming challenge, but algorithm > challenge. > A programming (only) challenge should only require the players to > write codes to implement an algorithm. Eh? Just about every interesting programming challenge is mostly about algorithm selection. Try some Project Euler for example. From pavlovevidence at gmail.com Sat Feb 6 04:56:41 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 6 Feb 2010 01:56:41 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> <037c8bd7$0$1292$c3e8da3@news.astraweb.com> Message-ID: <6ee9e549-081b-4f22-9f08-62440df85d5d@t17g2000prg.googlegroups.com> On Feb 5, 3:36?pm, Chris Rebert wrote: > On Fri, Feb 5, 2010 at 2:45 PM, Steven D'Aprano > > wrote: > > For instance, if getting or setting the voltage is an expensive > > operation, you don't want to fool the user into thinking it is a cheap > > attribute access. > > I strongly disagree with this rationale as it violates the Uniform > Access Principle > (http://en.wikipedia.org/wiki/Uniform_access_principle). Though I > concede Python's builtins don't adhere to the UAP. And I strongly disagree with the Uniform Access Principle. I want my accesses to an object to be explicitly "data-like" or "method-like", even if Based on the Wikipedia page, Meyer's main reason behind UAP seems to be to minimize the need to break interfaces: the UAP is a means to an end. Python achieves that end without the conforming to UAP, therefore it doesn't need it, and there's no reason to adhere to it. Carl Banks From anthra.norell at bluewin.ch Sat Feb 6 06:21:46 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Sat, 06 Feb 2010 12:21:46 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: References: <4B6C1BED.6090807@bluewin.ch> Message-ID: <4B6D50CA.5070006@bluewin.ch> Gabriel, Thanks for your hints. I take them up one by one: Gabriel Genellina wrote: > En Fri, 05 Feb 2010 10:23:57 -0300, Anthra Norell > escribi?: > >>>> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >>>> window. The OS is Windows ME. The download of 2.5 finished with a >>>> warning saying that 2.5 was the highest version for Windows 9* Any >>>> tips? > > I'd suggest a couple more tests. > Open the Python interpreter and execute: > > py> from idlelib import idle > > This *should* launch IDLE, or raise an error... >>> import idle Traceback (most recent call last): File "", line 1, in File "C:/PYTHON25/Lib/IDLELIB\idle.pyw", line 6, in import PyShell File "C:\Python25\Lib\idlelib\PyShell.py", line 3, in ImportError: No module named os >>> import os Traceback (most recent call last): File "", line 1, in ImportError: No module named os > If nothing happens, exit > the process and open another one, and execute: > > py> import Tkinter >>> import Tkinter Traceback (most recent call last): File "", line 1, in File "C:\PYTHON25\lib\lib-tk\Tkinter.py", line 37, in import FixTk # Attempt to configure Tcl/Tk without requiring PATH File "C:\PYTHON25\lib\lib-tk\FixTk.py", line 1, in import sys, os ImportError: No module named os > > py> root = Tkinter.Tk() > py> root.mainloop() > > An empty window should appear. If not, I'd say something is wrong with > the > Tcl/Tk libraries. > >> For the time being 2.4 works fine. I'd much prefer 2.5, though, >> because it includes the image library (PIL), whereas 2.4 cannot even >> use it. > > PIL has an impressive compatibility record - it works with *any* Python > version from 1.5.2 up. You should be able to use PIL with 2.4 without > problems. > Another good hint to a side issue: I should download PIL for P2.4. I guess it wasn't available back then and so I continued doing images with P2.2. The real issue seems to be a missing module "os". C:\PYTHON25\LIB>dir os.* Volume in drive C is PKBACK# 001 Volume Serial Number is 07D1-0103 Directory of C:\PYTHON25\Lib OS PY 25,211 08-03-06 9:27a OS.PY OS PYC 24,430 06-05-08 6:45p OS.PYC 2 file(s) 49,641 bytes 0 dir(s) 2,635.30 MB free Here we are! Somehow the name got upper-cased! There's a whole bunch (131) of upper-cased names in the Lib I shall install the whole thing from scratch. That should take care if it. Thank you very much. Frederic (Looking forward to Linux!) From tompelka at gmail.com Sat Feb 6 06:38:39 2010 From: tompelka at gmail.com (Tomas Pelka) Date: Sat, 06 Feb 2010 12:38:39 +0100 Subject: how to run part of my python code as root In-Reply-To: References: Message-ID: <4B6D54BF.90903@gmail.com> sjdevnull at yahoo.com wrote: > On Feb 4, 2:05 pm, Tomas Pelka wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Hey, >> >> is there possibility how to run part of my code (function for example) >> as superuser. >> >> Or only way how to do this is create a wrapper and run is with Popen >> through sudo (but I have to configure sudo to run "whole" python as root). > thank you for excellent explanation. > In decreasing order of desirability: > 1. Find a way to not need root access (e.g. grant another user or > group access to whatever resource you're trying to access). > 2. Isolate the stuff that needs root access into a small helper > program that does strict validation of all input (including arguments, > environment, etc); when needed, run that process under sudo or > similar. I thing this approach is the best for me. But how to connect two separated processes, one running with root privileges and second without superuser privileges? Is was thinking about Queues from multiprocessing, didn't you know if it is a good choice? > 2a. Have some sort of well-verified helper daemon that has access to > the resource you need and mediates use of that resource. > 3. Run the process as root, using seteuid() to switch between user and > root privs. The entire program must be heavily verified and do strict > validation of all inputs. Any attacker who gets control over the > process can easily switch to root privs and do damage. This is > generally a bad idea. -- Tom Key fingerprint = 06C0 23C6 9EB7 0761 9807 65F4 7F6F 7EAB 496B 28AA From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 06:48:56 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 11:48:56 GMT Subject: Doctests and decorated methods don't get along Message-ID: <037d435d$0$1292$c3e8da3@news.astraweb.com> It seems that doctest doesn't discover or execute doctests in methods which have been decorated. Here is my test file: # ====== class MyStaticMethod(object): """Emulate built-in staticmethod descriptor.""" def __init__(self, f): self.f = f def __get__(self, obj, objtype=None): return self.f class Test(object): def method1(self): """Doc string >>> print 'x' x """ @staticmethod def method2(): """Doc string >>> print 'y' y """ @MyStaticMethod def method3(): """Doc string >>> print '***' # This test should fail. z """ if __name__ == '__main__': import doctest doctest.testmod(verbose=True) # ====== and here is the output using Python 2.6.4: [steve at sylar python]$ python2.6 test_doctests.py Trying: print 'x' Expecting: x ok Trying: print 'y' Expecting: y ok 5 items had no tests: __main__ __main__.MyStaticMethod __main__.MyStaticMethod.__get__ __main__.MyStaticMethod.__init__ __main__.Test 2 items passed all tests: 1 tests in __main__.Test.method1 1 tests in __main__.Test.method2 2 tests in 7 items. 2 passed and 0 failed. Test passed. It doesn't even see method3, let alone run the tests. This looks like bug to me. Have I missed anything? Any work arounds? -- Steven From news123 at free.fr Sat Feb 6 07:09:06 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 13:09:06 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows In-Reply-To: References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: <4b6d5be2$0$21960$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: > >> I'm using an XMLRPC server under Windows. >> >> What I wonder is how I could create a server, that can be killed with >> CTRL-C >> >> The server aborts easily with CTRL-BREAK but not with CTRL-C (under >> Windows) >> >> If I press CTRL-C it will only abort when the next RPC call occurs. >> It seems it is blocking in the select() call in the handle_request() >> function. > > Python 2.6 and up behaves exactly as you want. > On previous versions you may use this:] I', using python 2.6.4 nd neither on Win-XP nor on Win-7 I'm capable to abort with CTR-C ? On Linux however I can use CTRL-C . > > class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): > > ... your methods ... > > if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): > > # pre 2.6 > quit = False > > def serve_forever(self): > while not self.quit: > self.handle_request() > > def shutdown(self): > self.quit = True > > def server_bind(self): > self.socket.settimeout(1.0) > SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) > I tried something similiar, but without setting the socket timeout. I'll try it now with. N From kevin.p.dwyer at gmail.com Sat Feb 6 07:10:48 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 6 Feb 2010 12:10:48 +0000 (UTC) Subject: "Nim" game being created, no GUI used... Need tips... References: <1b07ab151002051954hf3c946bqf4f306184228da40@mail.gmail.com> Message-ID: On Fri, 05 Feb 2010 21:54:48 -0600, Jordan Uchima wrote: Hello Jordan, You could try something like this (not tested, and maybe I don't quite "get" the rules): """ Nim game. In response to question on c.l.p. """ # Start with pot of thirteen pieces and two players. # Each player takes 1 - 4 pieces each turn. # Player who takes the last piece loses. # Declare constants. NUMBER_OF_PLAYERS = 2 TOTAL_PIECES_AT_START = 13 # Declare functions. def rules(): """Print the rules of the game.""" print 'Some rules' def get_players(): """Get the names of the players.""" # Let's put the player's names in a list. players = [] # Looping like this saves us repeating lines of code for each player. for player in range(NUMBER_OF_PLAYERS): name = raw_input("Hello Player %d, what is your name?\n" % player) players.append(player) return players def take_turn(player): """Handle a player's turn.""" # Turn logic goes here. # Left as an exercise :) the_remaining_number_of_pieces_after_this_turn = 1 return the_remaining_number_of_pieces_after_this_turn def main(): """Run the game.""" # Display the rules by calling rules function. rules() # Get the players by calling the get_players function. players = get_players() # Set up the game. remaining_pieces = TOTAL_PIECES_AT_START playing = True # Main loop - let's play! while playing: # Take turns. for player in players: remaining_pieces = take_turn(player) # Check if this player has lost. if remaining_pieces == 0: # Player has taken last piece. print 'Sorry %s, you have lost.' % player # Break out of the loop playing = False break # Automatically run main function if we're run as a script. if __name__ == '__main__': main() # End. The "while" loop in the main function runs the game until a winner (or loser in this case) is declared. The "for" loop within the while loop handles the alternation of turns. Have a look at the python tutorial at http://docs.python.org/tutorial/index.html for more on "while" and "for" statements. Use functions to break up the code into related sections. Check out the tutorial material for functions too. This skeleton should give you a starting structure for your program. Have fun :) Kev From gerald.britton at gmail.com Sat Feb 6 08:09:10 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Sat, 6 Feb 2010 08:09:10 -0500 Subject: Exception class documentation In-Reply-To: <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> Message-ID: <5d1a32001002060509w56f9fce1wf72dc56d7a70d3cb@mail.gmail.com> If you browse the Python source tree, you should be able to find it. http://svn.python.org/view/python/trunk/Objects/exceptions.c?revision=77045&view=markup On Fri, Feb 5, 2010 at 7:27 PM, Charles Yeomans wrote: > > On Feb 5, 2010, at 2:13 PM, Gerald Britton wrote: > >> On Fri, Feb 5, 2010 at 12:55 PM, Charles Yeomans >> wrote: >>> >>> I am so far unable to find the information I want about the Exception >>> class. >>> ?Information like the signature of __init__ seems to be unavailable. ?Any >>> suggestions where I might find such information? >>> >> >> Though not documented, some silly tests indicate that it will accept >> pretty much anything: >> >>>>> Exception(1,2,4,54) >> >> Exception(1, 2, 4, 54) >>>>> >>>>> Exception(*range(10)) >> >> Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>>>> >>>>> Exception(*range(50)) >> >> Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, >> 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, >> 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49) >>>>> >>>>> Exception('a','b','c','d','e') >> >> Exception('a', 'b', 'c', 'd', 'e') >>>>> >>>>> Exception(Exception(1)) >> >> Exception(Exception(1,),) > > I had also tried such tests. ?If you pass a single argument msg, it is > assigned to the message property, and the args property is set to (msg,). If > you pass more than one argument, the tuple of arguments is assigned to the > args property, and nothing is assigned to the message property. ?I was > hoping to at least find source code that provides a definitive answer. > > > Charles Yeomans > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Gerald Britton From anthra.norell at bluewin.ch Sat Feb 6 08:33:57 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Sat, 06 Feb 2010 14:33:57 +0100 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start In-Reply-To: <4B6D50CA.5070006@bluewin.ch> References: <4B6C1BED.6090807@bluewin.ch> <4B6D50CA.5070006@bluewin.ch> Message-ID: <4B6D6FC5.3000705@bluewin.ch> Gabriel, After reinstalling the whole package things are shaping up. It still doesn't work but it fails more to the point of your suggestions. I update the responses to your questions: Anthra Norell wrote: > Gabriel, > Thanks for your hints. I take them up one by one: > > Gabriel Genellina wrote: >> En Fri, 05 Feb 2010 10:23:57 -0300, Anthra Norell >> escribi?: >> >>>>> I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle >>>>> window. The OS is Windows ME. The download of 2.5 finished with a >>>>> warning saying that 2.5 was the highest version for Windows 9* Any >>>>> tips? >> >> I'd suggest a couple more tests. >> Open the Python interpreter and execute: >> >> py> from idlelib import idle >> >> This *should* launch IDLE, or raise an error... > >>> import idle Traceback (most recent call last): File "", line 1, in File "C:/PYTHON25/lib/IDLELIB\idle.py", line 19, in PyShell.main() File "C:\Python25\Lib\idlelib\PyShell.py", line 1390, in main root = Tk(className="Idle") File "C:\PYTHON25\lib\lib-tk\Tkinter.py", line 1647, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, want objects, useTk, sync, use) _tkinter.TclError: Can't find a usable init.tcl in the following directories: C:/PYTHON25/lib/tcl8.4 C:/lib/tcl8.4 C:/library Checking for the whereabouts of the tcl8.4 directory I find it in C:/PYTHON25/TCL together with a few more plus some files. C:\PYTHON25\TCL>dir Volume in drive C is PKBACK# 001 Volume Serial Number is 07D1-0103 Directory of C:\PYTHON25\TCL . 11-25-08 4:09p . .. 11-25-08 4:09p .. TCL84 LIB 191,802 03-27-06 4:23p tcl84.lib TCLSTU~1 LIB 2,264 03-27-06 4:23p tclstub84.lib DDE1 2 11-25-08 4:09p DDE1.2 REG1 1 11-25-08 4:09p REG1.1 TCL8 4 11-25-08 4:09p TCL8.4 TK8 4 11-25-08 4:09p TK8.4 TK84 LIB 167,288 03-27-06 4:44p tk84.lib TKSTUB84 LIB 2,988 03-27-06 4:43p tkstub84.lib TIX8 4 02-06-10 1:09p tix8.4 4 file(s) 364,342 bytes 7 dir(s) 2,569.25 MB free This is the way the installer fixed it. The thing to do seems to be to move the tcl8.4 dirctory to the lib directory. Before I start upsetting things, perhaps you would know whether the whole TCL subtree should move. Frederic From toylet.toylet at gmail.com Sat Feb 6 08:41:52 2010 From: toylet.toylet at gmail.com (Man-wai Chang to The Door (24000bps)) Date: Sat, 06 Feb 2010 21:41:52 +0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: <7xpr4ihf4w.fsf@ruckus.brouhaha.com> References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> <7xpr4ihf4w.fsf@ruckus.brouhaha.com> Message-ID: > Eh? Just about every interesting programming challenge is mostly about > algorithm selection. Try some Project Euler for example. Everyone back then has abused the "programming" word to meant doing everything (algorithms (system analysis & design), data structures, coding, testing, documentation, auditing, ....) at cheap salaries+benefits and tight schedules! -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.7 ^ ^ 21:40:01 up 7 days 5:46 2 users load average: 0.00 0.04 0.01 ???! ???! ???! ???! ???! ???! ????? (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa From toylet.toylet at gmail.com Sat Feb 6 08:43:28 2010 From: toylet.toylet at gmail.com (Man-wai Chang to The Door (24000bps)) Date: Sat, 06 Feb 2010 21:43:28 +0800 Subject: Google AI Challenge at U of Waterloo In-Reply-To: References: <4152d196-6491-446b-bc69-5bf54109b354@k5g2000pra.googlegroups.com> Message-ID: > Hello, this is Jeff Cameron, the organizer of the Google AI Challenge. > I'm glad to see all this interest in our humble little contest. I wish > you all the best of luck, and encourage everyone to try their hand at > writing an AI for Tron! www.ai-contest.com Someone please dumb the Tron ROM from the MAME32 project and use it as baseline answer. :) -- @~@ Might, Courage, Vision, SINCERITY. / v \ Simplicity is Beauty! May the Force and Farce be with you! /( _ )\ (x86_64 Ubuntu 9.10) Linux 2.6.32.7 ^ ^ 21:42:01 up 7 days 5:48 2 users load average: 0.00 0.02 0.00 ???! ???! ???! ???! ???! ???! ????? (CSSA): http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa From wgaggioli at gmail.com Sat Feb 6 09:51:53 2010 From: wgaggioli at gmail.com (Sir Wilhelm the Sturdy) Date: Sat, 6 Feb 2010 06:51:53 -0800 (PST) Subject: Calendar GUI References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> Message-ID: <4bb356ba-b043-444e-a318-6ec010028bb4@d37g2000yqa.googlegroups.com> On Feb 6, 12:59?am, Michael Torrie wrote: > Gabriel wrote: > > On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: > >> I'm working on setting up some software for a Peruvian non-profit to help > >> them organize their incoming volunteers. One of the features I'd like to add > >> is acalendar-like view of the different volunteers arrival dates and > >> staying time, with potentially some other info through some double-click > >> action. Rather than writing acalendarguimyself, is there some open-source > >>calendarprogram you guys could recommend that I could plug into? It has to > >> be run locally, as the internet isn't so reliable down here, but other than > >> that something simple and clean is ideal. > > > I wrote a gtkguifor googlecalendar. > > > Maybe you can adapt it to your needs. > > >http://code.google.com/p/googlecalendar-gtk/ > > Would this work without an internet connection? ?The original poster > stated that internet isn't so reliable, hence the need for a local solution. The functionality of Google calendar would be perfect, but it needs to be run locally. From ALANBIDDLE70 at YAHOO.COM Sat Feb 6 10:45:39 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Sat, 06 Feb 2010 09:45:39 -0600 Subject: Need installer recommendation Message-ID: <6q2rm5htqdj2puinbg9pmkco8o6nhd72h5@4ax.com> Hi, I could use a recommendation on a free installer for use by an unsophisticated programmer, that would be me, for some simple programs which are a bit more than "Hello World," but only a little. Basically reading text files and processing the results. Nothing fancy. I am using PY2EXE to create the distribution. In doing the Google, and from past posting here, I see that most recommendations are for inno and nsis. I expect that either would do what I want. Is one a better choice for someone to learn enough to do basic stuff without getting bogged down in details which are not immediately important? -- Alan From charles at declaresub.com Sat Feb 6 11:05:42 2010 From: charles at declaresub.com (Charles Yeomans) Date: Sat, 6 Feb 2010 11:05:42 -0500 Subject: Exception class documentation In-Reply-To: <5d1a32001002060509w56f9fce1wf72dc56d7a70d3cb@mail.gmail.com> References: <4AE681DA-19BD-464E-BD14-ECF1E7261581@declareSub.com> <5d1a32001002051113g5eda1d6dwa4dd605c56e19002@mail.gmail.com> <29236418-FA36-49FB-A45B-AA414A21AE79@declaresub.com> <5d1a32001002060509w56f9fce1wf72dc56d7a70d3cb@mail.gmail.com> Message-ID: <35733041-2A61-4E19-9730-D5065CA6E826@declaresub.com> On Feb 6, 2010, at 8:09 AM, Gerald Britton wrote: > If you browse the Python source tree, you should be able to find it. > > http://svn.python.org/view/python/trunk/Objects/exceptions.c?revision=77045&view=markup > Perfect (even if I have to read C). Thanks. Charles Yeomans From mark.wendell at gmail.com Sat Feb 6 12:19:46 2010 From: mark.wendell at gmail.com (mark.wendell) Date: Sat, 6 Feb 2010 09:19:46 -0800 (PST) Subject: optparse print_help question Message-ID: Is there a way to use the optparser parser.print_help() so that it ONLY prints out the options, and NOT the usage? thanks From benjamin at python.org Sat Feb 6 12:56:40 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Feb 2010 11:56:40 -0600 Subject: [RELEASED] Python 2.7 alpha 3 Message-ID: <1afaf6161002060956o4b303053pfd8b37922bea904f@mail.gmail.com> On behalf of the Python development team, I'm cheerful to announce the third alpha release of Python 2.7. Python 2.7 is scheduled (by Guido and Python-dev) to be the last major version in the 2.x series. Though more major releases have not been absolutely ruled out, it's likely that the 2.7 release will an extended period of maintenance for the 2.x series. 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, 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/ Please note that this is a development release, intended as a preview of new features for the community, and is thus not suitable for production use. The 2.7 documentation can be found at: http://docs.python.org/2.7 Please consider trying Python 2.7 with your code and reporting any bugs you may notice to: http://bugs.python.org Enjoy! -- Benjamin Peterson 2.7 Release Manager benjamin at python.org (on behalf of the entire python-dev team and 2.7's contributors) From sccolbert at gmail.com Sat Feb 6 13:24:21 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sat, 6 Feb 2010 13:24:21 -0500 Subject: determining which value is the first to appear five times in a list? Message-ID: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> I'm working on a naive K-nearest-neighbors selection criteria for an optical character recognition problem. After I build my training set, I test each new image against against the trained feature vectors and record the scores as follows: match_vals = [(match_val_1, identifier_a), (match_val_2, identifier_b) .... ] and so on.. then I sort the list so the smallest match_val's appear first (indictating a strong match, so I may end up with something like this: [(match_val_291, identifier_b), (match_val_23, identifier_b), (match_val_22, identifer_k) .... ] Now, what I would like to do is step through this list and find the identifier which appears first a K number of times. Naively, I could make a dict and iterate through the list AND the dict at the same time and keep a tally, breaking when the criteria is met. such as: def getnn(match_vals): tallies = defaultdict(lambda: 0) for match_val, ident in match_vals: tallies[ident] += 1 for ident, tally in tallies.iteritems(): if tally == 5: return ident I would think there is a better way to do this. Any ideas? Cheers! Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 6 13:54:09 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 00:24:09 +0530 Subject: how to fix bugs (python) Message-ID: I am interested in fixing bugs in python. Are there entry-level bugs in python which makes me familiarize with the process just like gnome have gnome-love ? Just a small start-up guidance will be a big favour as I have never fixed any. Thanks, ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Feb 6 13:56:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 13:56:25 -0500 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> Message-ID: On 2/6/2010 1:24 PM, Chris Colbert wrote: > I'm working on a naive K-nearest-neighbors selection criteria for an > optical character recognition problem. > > After I build my training set, I test each new image against against the > trained feature vectors and record the scores as follows: > > match_vals = [(match_val_1, identifier_a), (match_val_2, identifier_b) > .... ] and so on.. > > then I sort the list so the smallest match_val's appear first > (indictating a strong match, so I may end up with something like this: > > [(match_val_291, identifier_b), (match_val_23, identifier_b), > (match_val_22, identifer_k) .... ] > > Now, what I would like to do is step through this list and find the > identifier which appears first a K number of times. > > Naively, I could make a dict and iterate through the list AND the dict > at the same time and keep a tally, breaking when the criteria is met. > > such as: > > def getnn(match_vals): > tallies = defaultdict(lambda: 0) > for match_val, ident in match_vals: > tallies[ident] += 1 > for ident, tally in tallies.iteritems(): > if tally == 5: > return ident > > I would think there is a better way to do this. Any ideas? You only need to check that the incremented tally is 5, which is to say, that the about-to-be-incremented tally is 4. t = tallies[ident] if t < 4: tallies[ident] = t+1 else: return ident From jjposner at optimum.net Sat Feb 6 14:00:28 2010 From: jjposner at optimum.net (John Posner) Date: Sat, 06 Feb 2010 14:00:28 -0500 Subject: Doctests and decorated methods don't get along In-Reply-To: <037d435d$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B6DBC4C.4080100@optimum.net> On 2/6/2010 6:48 AM, Steven D'Aprano wrote: > class MyStaticMethod(object): > """Emulate built-in staticmethod descriptor.""" > def __init__(self, f): > self.f = f > def __get__(self, obj, objtype=None): > return self.f How about using a function, instead of a class, to implement the decorator: import functools def MyStaticMethod(f): @functools.wraps(f) def _wrapper(*args, **kwargs): return f(*args, **kwargs) return _wrapper For me, this produces the hoped-for doctest failure in __main__.Test.method3. I tried making the class-based implementation work by using functools.wraps(), but I couldn't manage it. Also, doesn't the decorator protocol want the class to implement a __call__() method, not a __get__() method? Or am I getting hung up (not the first time) at the nexus of the descriptor and decorator protocols? -John From rrr at ronadam.com Sat Feb 6 14:03:47 2010 From: rrr at ronadam.com (Ron Adam) Date: Sat, 06 Feb 2010 13:03:47 -0600 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: Xah Lee wrote: > For anyone reading this thread and interested in my opinions, i have > written many essays related to this and netiquette. Many of which > detail other similar incidences that i personally experienced, such as > freenode's irc ban in #emacs channel. If you are interested, they can > be found on my website, search for ?ban xah lee?. Xah, Often (in the past) most of your posts have come across as complaints or ones pointing out problems or comparisons of the negative sort. Your overall negative tone is just one of the reasons you get labeled a troll. I suggest you try to be less confrontational and more positive. Use your expertise and intelligence to help others but don't be offended if they don't agree with you. There's more than one way to do almost everything and sometimes the best way for "a person" to do it is the way that person is able to grasp it. Regards, Ron From wentland at cl.uni-heidelberg.de Sat Feb 6 14:09:01 2010 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Sat, 6 Feb 2010 20:09:01 +0100 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> Message-ID: <20100206190901.GB2508@kinakuta.local> On Sat, Feb 06, 2010 at 13:24 -0500, Chris Colbert wrote: > [(match_val_291, identifier_b), (match_val_23, identifier_b), (match_val_22, > identifer_k) .... ] > > Now, what I would like to do is step through this list and find the identifier > which appears first a K number of times. I think you can use the itertools.groupby(L, lambda el: el[1]) to group elements in your *sorted* list L by the value el[1] (i.e. the identifier) and then iterate through these groups until you find the desired number of instances grouped by the same identifier. Let me exemplify this: >>> from itertools import groupby >>> instances = [(1, 'b'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'c'), (6, 'c'), (7, 'd')] >>> k = 3 >>> grouped_by_identifier = groupby(instances, lambda el: el[1]) >>> grouped_by_identifier = ((identifier, list(group)) for identifier, group in grouped_by_identifier) >>> k_instances = (group for identifier, group in grouped_by_identifier if len(group) == k) >>> next(k_instances) [(4, 'c'), (5, 'c'), (6, 'c')] >>> next(k_instances) Traceback (most recent call last): File "", line 1, in StopIteration There are certainly millions of ways to do this and most of them will be better than my proposal here, but you might like this approach. Another approach would use itertools.takewhile() or itertools.ifilter() ... Just have a look :-) yours sincerely -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From jim.hefferon at gmail.com Sat Feb 6 14:09:31 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 6 Feb 2010 11:09:31 -0800 (PST) Subject: intolerant HTML parser Message-ID: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> I generate some HTML and I want to include in my unit tests a check for syntax. So I am looking for a program that will complain at any syntax irregularities. I am familiar with Beautiful Soup (use it all the time) but it is intended to cope with bad syntax. I just tried feeding HTMLParser.HTMLParser some HTML containing '

ab

' and it didn't complain. That is, this: h=HTMLParser.HTMLParser() try: h.feed('

ab

') h.close() print "I expect not to see this line" except Exception, err: print "exception:",str(err) gives me "I expect not to see this line". Am I using that routine incorrectly? Is there a natural Python choice for this job? Thanks, Jim From jim.hefferon at gmail.com Sat Feb 6 14:35:34 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 6 Feb 2010 11:35:34 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6dc27c$0$1608$742ec2ed@news.sonic.net> Message-ID: Thank you, John. I did not find that by looking around; I must not have used the right words. The speed of the unit tests are not critical so this seems like the solution for me. Jim From hzhuo1 at gmail.com Sat Feb 6 14:36:46 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sat, 6 Feb 2010 11:36:46 -0800 (PST) Subject: How to print all expressions that match a regular expression Message-ID: Hi, I am a fresh man with python. I know there is regular expressions in Python. What I need is that given a particular regular expression, output all the matches. For example, given ?[1|2|3]{2}? as the regular expression, the program should output all 9 matches, i.e., "11 12 13 21 22 23 31 32 33". Is there any well-written routine in Python or third-party program to do this? If there isn't, could somebody make some suggestions on how to write it myself? Thanks. Zhuo From tjreedy at udel.edu Sat Feb 6 14:39:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 14:39:00 -0500 Subject: Doctests and decorated methods don't get along In-Reply-To: <037d435d$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: On 2/6/2010 6:48 AM, Steven D'Aprano wrote: > It seems that doctest doesn't discover or execute doctests in methods > which have been decorated. > > > Here is my test file: > > # ====== > class MyStaticMethod(object): > """Emulate built-in staticmethod descriptor.""" > def __init__(self, f): > self.f = f > def __get__(self, obj, objtype=None): > return self.f > > class Test(object): > def method1(self): > """Doc string > > >>> print 'x' > x > """ > > @staticmethod > def method2(): > """Doc string > > >>> print 'y' > y > """ > > @MyStaticMethod > def method3(): > """Doc string > > >>> print '***' # This test should fail. > z > """ > > if __name__ == '__main__': > import doctest > doctest.testmod(verbose=True) > # ====== > > > and here is the output using Python 2.6.4: > > [steve at sylar python]$ python2.6 test_doctests.py > Trying: > print 'x' > Expecting: > x > ok > Trying: > print 'y' > Expecting: > y > ok > 5 items had no tests: > __main__ > __main__.MyStaticMethod > __main__.MyStaticMethod.__get__ > __main__.MyStaticMethod.__init__ > __main__.Test > 2 items passed all tests: > 1 tests in __main__.Test.method1 > 1 tests in __main__.Test.method2 > 2 tests in 7 items. > 2 passed and 0 failed. > Test passed. > > > It doesn't even see method3, let alone run the tests. Method3 is wrapped as an instance of MyStaticMethod and doctest does not see that as function. Even if it did, you would might have to copy the docstring (self.__doc__ = f.__doc__) to have the test run. Note the following: (3.1) >>> Test.method3 >>> Test.__dict__['method3'] <__main__.MyStaticMethod object at 0x00F5CDF0> >>> Test.__dict__['method2'] Doctest has to scan the dict, so it does not see the attribute-lookup result. > This looks like bug to me. Have I missed anything? I would call it a limitation as I do not see the doc as promising otherwise. I believe doctest predates the descripter protocol, at least in its current form, so it may not be completely descriptor-aware. You certainly could file a feature request for improved recognition and subsequent calling of __get__. An initial patch would improve chances of action. > Any workarounds? Perhaps look at the doctest source to see why staticmethod instances are recognized as functions. If doctest directly special-cases their recognition, then use the standard nested function approach for decorators, making sure to copy the doc string. Look at functools.wraps. If doctest recognizes them by some characteristic that you have not emulated, try to improve that. Terry Jan Reedy Terry Jan Reedy From tjreedy at udel.edu Sat Feb 6 14:42:52 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 14:42:52 -0500 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <20100206190901.GB2508@kinakuta.local> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> <20100206190901.GB2508@kinakuta.local> Message-ID: On 2/6/2010 2:09 PM, Wolodja Wentland wrote: > On Sat, Feb 06, 2010 at 13:24 -0500, Chris Colbert wrote: >> [(match_val_291, identifier_b), (match_val_23, identifier_b), (match_val_22, >> identifer_k) .... ] >> >> Now, what I would like to do is step through this list and find the identifier >> which appears first a K number of times. > > I think you can use the itertools.groupby(L, lambda el: el[1]) to group > elements in your *sorted* list L by the value el[1] (i.e. the > identifier) and then iterate through these groups until you find the > desired number of instances grouped by the same identifier. This will generally not return the same result. It depends on whether OP wants *any* item appearing at least 5 times or whether the order is significant and the OP literally wants the first. Sorting the entire list may also take a *lot* longer. Terry Jan Reedy From nagle at animats.com Sat Feb 6 14:43:19 2010 From: nagle at animats.com (John Nagle) Date: Sat, 06 Feb 2010 11:43:19 -0800 Subject: intolerant HTML parser In-Reply-To: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> Message-ID: <4b6dc27c$0$1608$742ec2ed@news.sonic.net> Jim wrote: > I generate some HTML and I want to include in my unit tests a check > for syntax. So I am looking for a program that will complain at any > syntax irregularities. > > I am familiar with Beautiful Soup (use it all the time) but it is > intended to cope with bad syntax. I just tried feeding > HTMLParser.HTMLParser some HTML containing '

ab

' and it > didn't complain. Try HTML5lib. http://code.google.com/p/html5lib/downloads/list The syntax for HTML5 has well-defined notions of "correct", "fixable", and "unparseable". For example, the common but incorrect form of HTML comments, <- comment -> is understood. HTML5lib is slow, though. Sometimes very slow. It's really a reference implementation of the spec. There's code like this: #Should speed up this check somehow (e.g. move the set to a constant) if ((0x0001 <= charAsInt <= 0x0008) or (0x000E <= charAsInt <= 0x001F) or (0x007F <= charAsInt <= 0x009F) or (0xFDD0 <= charAsInt <= 0xFDEF) or charAsInt in frozenset([0x000B, 0xFFFE, 0xFFFF, 0x1FFFE, 0x1FFFF, 0x2FFFE, 0x2FFFF, 0x3FFFE, 0x3FFFF, 0x4FFFE, 0x4FFFF, 0x5FFFE, 0x5FFFF, 0x6FFFE, 0x6FFFF, 0x7FFFE, 0x7FFFF, 0x8FFFE, 0x8FFFF, 0x9FFFE, 0x9FFFF, 0xAFFFE, 0xAFFFF, 0xBFFFE, 0xBFFFF, 0xCFFFE, 0xCFFFF, 0xDFFFE, 0xDFFFF, 0xEFFFE, 0xEFFFF, 0xFFFFE, 0xFFFFF, 0x10FFFE, 0x10FFFF])): self.tokenQueue.append({"type": tokenTypes["ParseError"], "data": "illegal-codepoint-for-numeric-entity", "datavars": {"charAsInt": charAsInt}}) Every time through the loop (once per character), they build that frozen set again. John Nagle From tjreedy at udel.edu Sat Feb 6 14:49:29 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 14:49:29 -0500 Subject: how to fix bugs (python) In-Reply-To: References: Message-ID: On 2/6/2010 1:54 PM, Shashwat Anand wrote: > I am interested in fixing bugs in python. Are there entry-level bugs in > python which makes me familiarize with the process just like gnome have > gnome-love ? Just a small start-up guidance will be a big favour as I > have never fixed any. Go to python.org/dev/ and look at various pages there. The item tracker is at bugs.python.org Some items are marked easy. Many items have patches that need review. Help is needed both with Python code (modules) and C code (core and modules) depending on your abilities and interest. I would start with looking at current items on the tracker. Terry Jan Reedy From anand.shashwat at gmail.com Sat Feb 6 14:58:47 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 01:28:47 +0530 Subject: how to fix bugs (python) In-Reply-To: References: Message-ID: Thanks Terry. I am looking on it. :) On Sun, Feb 7, 2010 at 1:19 AM, Terry Reedy wrote: > On 2/6/2010 1:54 PM, Shashwat Anand wrote: > >> I am interested in fixing bugs in python. Are there entry-level bugs in >> python which makes me familiarize with the process just like gnome have >> gnome-love ? Just a small start-up guidance will be a big favour as I >> have never fixed any. >> > > Go to > python.org/dev/ > and look at various pages there. The item tracker is at > bugs.python.org > Some items are marked easy. Many items have patches that need review. Help > is needed both with Python code (modules) and C code (core and modules) > depending on your abilities and interest. I would start with looking at > current items on the tracker. > > Terry Jan Reedy > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wgaggioli at gmail.com Sat Feb 6 15:06:04 2010 From: wgaggioli at gmail.com (Sir Wilhelm the Sturdy) Date: Sat, 6 Feb 2010 12:06:04 -0800 (PST) Subject: Subclassing datetime.date Message-ID: Hi all, I recently attempted to subclass the datetime.date object resulting in horror and confusion, before submitting to a has-a relationship. That's all fine and dandy, but out of curiosity I'd like to know what I'm missing. I was attempting to allow more flexible instancing of an object, like so: import datetime class MyDate(datetime.date): def __init__(self,*args,**kw): if len(kw) + len(args) > 1: self.construct(*args,**kw) def construct(self,d,m=None,y=None,**kw): today = datetime.date.today() if m is None: m = today.month if y is None: y = today.year datetime.date.__init__(self,y,m,d,**kw) However, it wasn't having the desired effect. Indeed, I could still only instance it with 3 variables lest I get errors, and when I did call it with 3 variables it didn't reflect the order change I had implemented. Indeed, the properties were already set before it even got to the construct method. Is there some kind of built in I'm missing here? Thanks all, Will From wentland at cl.uni-heidelberg.de Sat Feb 6 15:25:40 2010 From: wentland at cl.uni-heidelberg.de (Wolodja Wentland) Date: Sat, 6 Feb 2010 21:25:40 +0100 Subject: determining which value is the first to appear five times in a list? In-Reply-To: References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> <20100206190901.GB2508@kinakuta.local> Message-ID: <20100206202540.GC2508@kinakuta.local> On Sat, Feb 06, 2010 at 14:42 -0500, Terry Reedy wrote: > On 2/6/2010 2:09 PM, Wolodja Wentland wrote: > >I think you can use the itertools.groupby(L, lambda el: el[1]) to group > >elements in your *sorted* list L by the value el[1] (i.e. the > >identifier) and then iterate through these groups until you find the > >desired number of instances grouped by the same identifier. > This will generally not return the same result. It depends on > whether OP wants *any* item appearing at least 5 times or whether > the order is significant and the OP literally wants the first. Order is preserved by itertools.groupby - Have a look: >>> instances = [(1, 'b'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'c'), (6, 'c'), (7, 'b'), (8, 'b')] >>> grouped_by_identifier = groupby(instances, lambda el: el[1]) >>> grouped_by_identifier = ((identifier, list(group)) for identifier, group in grouped_by_identifier) >>> k_instances = (group for identifier, group in grouped_by_identifier if len(group) == 2) >>> for group in k_instances: ... print group ... [(1, 'b'), (2, 'b')] [(7, 'b'), (8, 'b')] So the first element yielded by the k_instances generator will be the first group of elements from the original list whose identifier appears exactly k times in a row. > Sorting the entire list may also take a *lot* longer. Than what? Am I missing something? Is the "*sorted*" the culprit? If yes -> Just forget it as it is not relevant. -- .''`. Wolodja Wentland : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From alfps at start.no Sat Feb 6 15:31:52 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Feb 2010 21:31:52 +0100 Subject: TABS in the CPython C source code Message-ID: Just trying to delve into the CPython source code. Pleasant surprise: while e.g. the gcc compiler is written in K&R C (1975 style C), CPython seems to be written in almost modern C (1989 and on). But, hey, TABS used for indenting, combined haphazardly and randomly with SPACES used for indenting, in the same source files... The size-8 tabs look really bad in an editor configured with tab size 4, as is common in Windows. I'm concluding that the CPython programmers configure their Visual Studio's to *nix convention. Or perhaps modern Visual Studio has default tab size 8, it wouldn't surprise me (the best version was the MSVC 6.0 Developer Studio, since then that IDE has only gone downhill being re-based on the Office Assistant inspired "for dummies" IDE that Microsoft had for web designers). Anyways, I would suggest converting all those tabs to spaces, as e.g. the Boost library project does -- no tabs allowed. That's much more platform-independent. :-) Cheers, - Alf From david at boddie.org.uk Sat Feb 6 15:52:20 2010 From: david at boddie.org.uk (David Boddie) Date: Sat, 06 Feb 2010 21:52:20 +0100 Subject: PyQt4 designer custom properties - combo box style References: Message-ID: On Saturday 06 February 2010 10:32, Andrew wrote: > I'm attempting to create a drop down property for a custom widget I'm > creating. So when in designer and you scroll down to the custom > properties, under the regular widget properties, one of them would be > a drop down menu. The data to populate it will be coming from our API > and currently is a list of string-items. Yes, it would be treated > specially by Designer, since it's the only place it would be seen. Right. The drop down menus in the property editor usually contain values defined for C++ enums which have been declared to Qt's meta-object system when a C++ library or plugin is compiled. I'm not sure that PyQt can expose lists of Python values in the same way. An example of this is the alignment property in QLineEdit. > In the PyQt4\examples\designer folder, it carries a number of custom > widgets that will load into designer. The datetimeedit widget creates > a custom drop down menu property. The plugin pulls its information > from the QtCore libraries and from the QCalander Widget. Though I am > unable to find a better example or even explanation of how it's > actually creating that drop down menu. Each of the individual properties are just single values, aren't they, not collections of values? >> Have you seen this article? >> >> http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html > > No, I haven't, thanks. That might step in the right direction. I can't > run it right now, so I'm not sure if it is putting a spinbox as it's > property or just the value from the spin box. The value from each spin box is turned into a property, so there are latitude and longitude properties, though each of these only holds a double precision floating point number. It sounds like you want to be able to select from a list of values, or possibly change the values themselves. If it turns out you can't add a property to Qt Designer in the way you want, you can still add a custom editor to the widget so that users can open a context menu and select an item to configure it. This is similar to the way you can open a dialog to edit the text inside QTextEdit widgets. The article I referred to also covers this: http://qt.nokia.com/doc/qq/qq26-pyqtdesigner.html#makingamenu David From user at example.net Sat Feb 6 16:02:07 2010 From: user at example.net (monkeys paw) Date: Sat, 06 Feb 2010 16:02:07 -0500 Subject: Last M digits of expression A^N In-Reply-To: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: mukesh tiwari wrote: > Hello everyone. I am kind of new to python so pardon me if i sound > stupid. > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my A and N are too large (10^100) and M is less than > 10^5. The other approach was repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. How do you arrive at log N as the performance number? > > def power(A,N,M): > ret=1 > while(N): > if(N%2!=0):ret=(ret*A)%M > A=(A*A)%M > N=N//2 > return ret From andrej.mitrovich at gmail.com Sat Feb 6 16:05:27 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sat, 6 Feb 2010 13:05:27 -0800 (PST) Subject: TABS in the CPython C source code References: Message-ID: On Feb 6, 9:31?pm, "Alf P. Steinbach" wrote: > Just trying to delve into the CPython source code. > > Pleasant surprise: while e.g. the gcc compiler is written in K&R C (1975 style > C), CPython seems to be written in almost modern C (1989 and on). > > But, hey, TABS used for indenting, combined haphazardly and randomly with SPACES > used for indenting, in the same source files... > > The size-8 tabs look really bad in an editor configured with tab size 4, as is > common in Windows. I'm concluding that the CPython programmers configure their > Visual Studio's to *nix convention. Or perhaps modern Visual Studio has default > tab size 8, it wouldn't surprise me (the best version was the MSVC 6.0 Developer > Studio, since then that IDE has only gone downhill being re-based on the Office > Assistant inspired "for dummies" IDE that Microsoft had for web designers). > > Anyways, I would suggest converting all those tabs to spaces, as e.g. the Boost > library project does ?-- ?no tabs allowed. > > That's much more platform-independent. :-) > > Cheers, > > - Alf So what's stopping you from doing this yourself? From alfps at start.no Sat Feb 6 16:12:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 06 Feb 2010 22:12:05 +0100 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: * Andrej Mitrovic: > On Feb 6, 9:31 pm, "Alf P. Steinbach" wrote: >> Just trying to delve into the CPython source code. >> >> Pleasant surprise: while e.g. the gcc compiler is written in K&R C (1975 style >> C), CPython seems to be written in almost modern C (1989 and on). >> >> But, hey, TABS used for indenting, combined haphazardly and randomly with SPACES >> used for indenting, in the same source files... >> >> The size-8 tabs look really bad in an editor configured with tab size 4, as is >> common in Windows. I'm concluding that the CPython programmers configure their >> Visual Studio's to *nix convention. Or perhaps modern Visual Studio has default >> tab size 8, it wouldn't surprise me (the best version was the MSVC 6.0 Developer >> Studio, since then that IDE has only gone downhill being re-based on the Office >> Assistant inspired "for dummies" IDE that Microsoft had for web designers). >> >> Anyways, I would suggest converting all those tabs to spaces, as e.g. the Boost >> library project does -- no tabs allowed. >> >> That's much more platform-independent. :-) >> >> Cheers, >> >> - Alf > > So what's stopping you from doing this yourself? Depends what "this" you're referring to. If by "this" you mean, automatically converting tabs to spaces on checking out a newer version of a CPython source file, nothing in particular stops anyone from doing that. But it's needless work, and it results in "false positive" changes when checking in something. That's why e.g. Boost standardizes on spaces. If by "this" you mean, changing the coding guidelines (if such exist) for the CPython project, well I'm not involved, so the best I can do is to float the idea and point to existing practice in other projects, which I've now done. :-) Cheers & hth., - Alf From nyamatongwe+thunder at gmail.com Sat Feb 6 16:19:18 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sat, 06 Feb 2010 21:19:18 GMT Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: Alf P. Steinbach: > The size-8 tabs look really bad in an editor configured with tab size 4, > as is common in Windows. I'm concluding that the CPython programmers > configure their Visual Studio's to *nix convention. Most of the core developers use Unix. > Anyways, I would suggest converting all those tabs to spaces, as e.g. > the Boost library project does -- no tabs allowed. This would damage the usefulness of source control histories (svn annotate) as all of the converted lines would show this recent cosmetic change rather than the previous change which is likely to be a substantive modification. Neil From john at castleamber.com Sat Feb 6 16:42:29 2010 From: john at castleamber.com (John Bokma) Date: Sat, 06 Feb 2010 15:42:29 -0600 Subject: Subclassing datetime.date References: Message-ID: <87vdea9h2y.fsf@castleamber.com> Sir Wilhelm the Sturdy writes: F> Hi all, > > I recently attempted to subclass the datetime.date object resulting in > horror and confusion, before submitting to a has-a relationship. > That's all fine and dandy, but out of curiosity I'd like to know what > I'm missing. > > I was attempting to allow more flexible instancing of an object, like > so: > > import datetime > > class MyDate(datetime.date): > > def __init__(self,*args,**kw): > > if len(kw) + len(args) > 1: > self.construct(*args,**kw) > > def construct(self,d,m=None,y=None,**kw): > > today = datetime.date.today() > if m is None: > m = today.month > if y is None: > y = today.year > > datetime.date.__init__(self,y,m,d,**kw) > > > However, it wasn't having the desired effect. Indeed, I could still > only instance it with 3 variables lest I get errors, and when I did > call it with 3 variables it didn't reflect the order change I had > implemented. Indeed, the properties were already set before it even > got to the construct method. __init__ is *not* the construction method, __new__ is (at least with new style classes) > Is there some kind of built in I'm missing here? I guess __new__ but I am quite the newbie. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Sat Feb 6 16:44:56 2010 From: john at castleamber.com (John Bokma) Date: Sat, 06 Feb 2010 15:44:56 -0600 Subject: TABS in the CPython C source code References: Message-ID: <87r5oy9gyv.fsf@castleamber.com> "Alf P. Steinbach" writes: > Just trying to delve into the CPython source code. > > Pleasant surprise: while e.g. the gcc compiler is written in K&R C > (1975 style C), CPython seems to be written in almost modern C (1989 > and on). > > But, hey, TABS used for indenting, combined haphazardly and randomly > with SPACES used for indenting, in the same source files... > > The size-8 tabs look really bad in an editor configured with tab size > 4, as is common in Windows. Then you are either used a broken editor or a misconfigured editor. I've used TextPad for ages, and it can be configured to hard tab 8 (might even be the default [1]). [1] With Perl coding I configured it to indent 4 spaces, hard tab 4 spaces and convert hard tabs to 4 spaces while saving, so no surprises. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From news123 at free.fr Sat Feb 6 16:45:01 2010 From: news123 at free.fr (News123) Date: Sat, 06 Feb 2010 22:45:01 +0100 Subject: how to add pydoc strings to 'Data and other attributes' Message-ID: <4b6de2de$0$4830$426a74cc@news.free.fr> I'm having some problems with pydoc and I was not very sucessful in googling. (probably missng one key word) Is there soemthing like a documentation of pydoc (execpt pydocs output of pydoc, which doesn't seem to answer my question ) I can add docstrings to - the file head - to a class - to a class function - to a property but I don't know how document a class attribute (like 'name' ) in my example below Does anybody know how to doc it? # file starts here # ############################################################################# # This appears in the python documentation # ############################################################################# __author__ = 'News123' # this will also be part of pydoc """ general blabla will not be part of pydoc""" class MyClass(object): """ This class can be doc-ed """ name = 3 ### I don't know how to document this def get_f(self): """ the function get_f is here """ return 3 f = property(get_f,doc="this property is also documented") ######### file ends here thanks for any help N From arnodel at googlemail.com Sat Feb 6 17:08:55 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 06 Feb 2010 22:08:55 +0000 Subject: Code snippet: dualmethod descriptor References: <0373b8b9$0$1309$c3e8da3@news.astraweb.com> <00f4e6e5$0$15566$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Thu, 04 Feb 2010 00:09:02 -0300, Gabriel Genellina wrote: > >> En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano >> escribi?: >> >>> class dualmethod(object): > [...] > >> Seems useful! >> Perhaps a better place to post it would be >> , at least it's >> easier to search. > > > > Thank you for the encouragement. The recipe is now posted: > > http://code.activestate.com/recipes/577030/ Oddly, in Python 3 you can achieve something a bit similar very simply: >>> class A: ... def foo(self=None): ... return "Instance" if self else "Class" ... >>> A.foo() 'Class' >>> a = A() >>> a.foo() 'Instance' It works in python 3 because unbound methods are plain functions. -- Arnaud From arnodel at googlemail.com Sat Feb 6 17:22:47 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 06 Feb 2010 22:22:47 +0000 Subject: Dreaming of new generation IDE References: Message-ID: "Gabriel Genellina" writes: > En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: >> "Steve Holden" wrote in message >> news:mailman.1998.1265399766.28905.python-list at python.org... >>> Arnaud Delobelle wrote: >>>> Robert Kern writes: >>>> >>>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>>> quote for right now): if you expect that a boolean argument is only >>>>> going to take *literal* True or False, then it should be split into > ^^^^^^^^^^^^^^^^^^^^^^^ >>>>> two functions. >>>> >>>> So rather than three boolean arguments, would you have eight functions? >>>> >>> If there's genuinely a need for that functionality, yes. >> >> So you want a function such as drawtext(s, bold=true, italic=false, >> underline=true) to be split into: >> >> drawtext(s) >> drawtextb(s) >> drawtexti(s) >> drawtextu(s) >> drawtextbi(s) >> drawtextbu(s) >> drawtextiu(s) >> drawtextbiu(s) > > Note the *literal* part. If you (the programmer) is likely to know the > parameter value when writing the code, then the function is actually two > separate functions. Thanks, I understand what Steve Holden meant now. -- Arnaud From roy at panix.com Sat Feb 6 17:23:01 2010 From: roy at panix.com (Roy Smith) Date: Sat, 06 Feb 2010 17:23:01 -0500 Subject: How to print all expressions that match a regular expression References: Message-ID: In article , "hzhuo1 at gmail.com" wrote: > Hi, > > I am a fresh man with python. I know there is regular expressions in > Python. What I need is that given a particular regular expression, > output all the matches. For example, given ?[1|2|3]{2}? as the regular > expression, the program should output all 9 matches, i.e., "11 12 13 > 21 22 23 31 32 33". > > Is there any well-written routine in Python or third-party program to > do this? If there isn't, could somebody make some suggestions on how > to write it myself? > > Thanks. > > Zhuo Please enumerate all the strings which match ".*". Use additional sheets of paper if needed. From benjamin at python.org Sat Feb 6 17:26:55 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Feb 2010 22:26:55 +0000 (UTC) Subject: TABS in the CPython C source code References: Message-ID: Neil Hodgson gmail.com> writes: > This would damage the usefulness of source control histories (svn > annotate) as all of the converted lines would show this recent cosmetic > change rather than the previous change which is likely to be a > substantive modification. That's not completely true given svn diff -x -w. From benjamin at python.org Sat Feb 6 17:28:17 2010 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 6 Feb 2010 22:28:17 +0000 (UTC) Subject: TABS in the CPython C source code References: Message-ID: Alf P. Steinbach start.no> writes: > Anyways, I would suggest converting all those tabs to spaces This has been discussed to death of Python-dev. We use spaces for all new files and tabs for historical reasons in old files. Mixed ones should be converted one way or the other. > > That's much more platform-independent. From anand.shashwat at gmail.com Sat Feb 6 17:28:44 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 03:58:44 +0530 Subject: Last M digits of expression A^N In-Reply-To: References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: Yes, it can be done. Have a look at : http://en.wikipedia.org/wiki/Modular_exponentiation The algorithm is also mentioned in CLRS.I tried writing my own modular-exponentiation code following CLRS but observed that python pow() function is much more efficient. Have a look at this problem : https://www.spoj.pl/problems/LASTDIG/ as you can see ( https://www.spoj.pl/status/LASTDIG,l0nwlf/ )my first solution used algorithm hard-coded from CLRS which took 0.04 sec however using pow() function directly improved the efficiency to 0.0 So I would suggest to go for pow() unless you intend to learn modular exponentiation algorithm for which hand-coding is a must. here are my solutions : first one (hand-coded): 1. def pow(a, b): 2. if( not b): 3. return 1 4. if( b & 1 ): 5. return ( pow( a, b - 1 ) * a ) % 10 6. 7. tmp = pow( a, b / 2 ) 8. return ( tmp * tmp ) % 10; 9. 10. for i in xrange(input()): 11. a,b = [ int(x) for x in raw_input().split(' ')] 12. print( pow( a % 10, b ) ) second one (pow()): 1. for i in range(int(raw_input())): 2. a,b = [int(x) for x in raw_input().split()] 3. print pow (a,b,10) 4. HTH ~l0nwlf On Sun, Feb 7, 2010 at 2:32 AM, monkeys paw wrote: > mukesh tiwari wrote: > >> Hello everyone. I am kind of new to python so pardon me if i sound >> stupid. >> I have to find out the last M digits of expression.One thing i can do >> is (A**N)%M but my A and N are too large (10^100) and M is less than >> 10^5. The other approach was repeated squaring and taking mod of >> expression. Is there any other way to do this in python more faster >> than log N. >> > > How do you arrive at log N as the performance number? > > > >> def power(A,N,M): >> ret=1 >> while(N): >> if(N%2!=0):ret=(ret*A)%M >> A=(A*A)%M >> N=N//2 >> return ret >> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 6 17:31:28 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 04:01:28 +0530 Subject: Last M digits of expression A^N In-Reply-To: References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: a nice exercise to do can be this problem : http://www.codechef.com/MARCH09/problems/A4/ , it deals with both cases, first and last k digits and can be performed within O(log n) On Sun, Feb 7, 2010 at 3:58 AM, Shashwat Anand wrote: > Yes, it can be done. Have a look at : > http://en.wikipedia.org/wiki/Modular_exponentiation > The algorithm is also mentioned in CLRS.I tried writing my own > modular-exponentiation code following CLRS but observed that python pow() > function is much more efficient. > Have a look at this problem : https://www.spoj.pl/problems/LASTDIG/ > as you can see ( https://www.spoj.pl/status/LASTDIG,l0nwlf/ )my first > solution used algorithm hard-coded from CLRS which took 0.04 sec however > using pow() function directly improved the efficiency to 0.0 So I would > suggest to go for pow() unless you intend to learn modular exponentiation > algorithm for which hand-coding is a must. > > here are my solutions : > first one (hand-coded): > > > 1. def pow(a, b): > 2. if( not b): > 3. return 1 > 4. if( b & 1 ): > 5. return ( pow( a, b - 1 ) * a ) % 10 > > 6. > 7. tmp = pow( a, b / 2 ) > 8. return ( tmp * tmp ) % 10; > 9. > 10. for i in xrange(input()): > 11. a,b = [ int(x) for x in raw_input().split(' ')] > > 12. print( pow( a % 10, b ) ) > > > second one (pow()): > > > 1. for i in range(int(raw_input())): > > 2. a,b = [int(x) for x in raw_input().split()] > > 3. print pow (a,b,10) > 4. > > > HTH > ~l0nwlf > > > On Sun, Feb 7, 2010 at 2:32 AM, monkeys paw wrote: > >> mukesh tiwari wrote: >> >>> Hello everyone. I am kind of new to python so pardon me if i sound >>> stupid. >>> I have to find out the last M digits of expression.One thing i can do >>> is (A**N)%M but my A and N are too large (10^100) and M is less than >>> 10^5. The other approach was repeated squaring and taking mod of >>> expression. Is there any other way to do this in python more faster >>> than log N. >>> >> >> How do you arrive at log N as the performance number? >> >> >> >>> def power(A,N,M): >>> ret=1 >>> while(N): >>> if(N%2!=0):ret=(ret*A)%M >>> A=(A*A)%M >>> N=N//2 >>> return ret >>> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sat Feb 6 17:40:53 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 06 Feb 2010 17:40:53 -0500 Subject: determining which value is the first to appear five times in a list? In-Reply-To: <20100206202540.GC2508@kinakuta.local> References: <7f014ea61002061024y8125faam3fc99ed43e64e82@mail.gmail.com> <20100206190901.GB2508@kinakuta.local> <20100206202540.GC2508@kinakuta.local> Message-ID: On 2/6/2010 3:25 PM, Wolodja Wentland wrote: > On Sat, Feb 06, 2010 at 14:42 -0500, Terry Reedy wrote: >> On 2/6/2010 2:09 PM, Wolodja Wentland wrote: > >>> I think you can use the itertools.groupby(L, lambda el: el[1]) to group >>> elements in your *sorted* list L by the value el[1] (i.e. the >>> identifier) and then iterate through these groups until you find the >>> desired number of instances grouped by the same identifier. > >> This will generally not return the same result. It depends on >> whether OP wants *any* item appearing at least 5 times or whether >> the order is significant and the OP literally wants the first. > > Order is preserved by itertools.groupby - Have a look: Sorting does not. > >>>> instances = [(1, 'b'), (2, 'b'), (3, 'a'), (4, 'c'), (5, 'c'), (6, 'c'), (7, 'b'), (8, 'b')] >>>> grouped_by_identifier = groupby(instances, lambda el: el[1]) >>>> grouped_by_identifier = ((identifier, list(group)) for identifier, group in grouped_by_identifier) >>>> k_instances = (group for identifier, group in grouped_by_identifier if len(group) == 2) >>>> for group in k_instances: > ... print group > ... > [(1, 'b'), (2, 'b')] > [(7, 'b'), (8, 'b')] > > So the first element yielded by the k_instances generator will be the > first group of elements from the original list whose identifier appears > exactly k times in a row. > >> Sorting the entire list may also take a *lot* longer. > Than what? Than linearly scanning for the first 5x item, as in my corrected version of the original code. Terry Jan Reedy From ben+python at benfinney.id.au Sat Feb 6 17:43:23 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 07 Feb 2010 09:43:23 +1100 Subject: How to print all expressions that match a regular expression References: Message-ID: <87eikykmt0.fsf@benfinney.id.au> Roy Smith writes: > "hzhuo1 at gmail.com" wrote: > > What I need is that given a particular regular expression, output > > all the matches. [?] > Please enumerate all the strings which match ".*". Use additional > sheets of paper if needed. +1 QOTW -- \ ?Are you pondering what I'm pondering?? ?I think so, ... Brain, | `\ but how can we get seven dwarves to shave their legs?? ?_Pinky | _o__) and The Brain_ | Ben Finney From Martin.Drautzburg at web.de Sat Feb 6 17:53:53 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sat, 06 Feb 2010 23:53:53 +0100 Subject: new.instancemethod __iter__ Message-ID: <2036837.yhpURs0z1y@beaureve.gmx.net> Hello all When I create an Object and set its __iter__ method from outside s = Sequence #one of my own classes s.__iter__ = new.instancemethod(f,s,Sequence) I get different results, depending on whether I call for x in y.__iter__(): print x or for x in y: print x The first case does what I expected, i.e. it iterates over whatever f() yields. In the second case nothing is printed. I have the impression that it still calls the original __iter__() method (the one defined at the class level). Why is that so? How can I replace the __iter__() method so it does what I want. The reason I want to do such things is I need to implement operations similar to what itertools do. However I want my own classes and the operations are only similar to itertools, but differ in significant details. From davea at ieee.org Sat Feb 6 17:59:44 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 06 Feb 2010 17:59:44 -0500 Subject: Last M digits of expression A^N In-Reply-To: References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <4B6DF460.8020403@ieee.org> monkeys paw wrote: >
mukesh > tiwari wrote: >> Hello everyone. I am kind of new to python so pardon me if i sound >> stupid. >> I have to find out the last M digits of expression.One thing i can do >> is (A**N)%M but my A and N are too large (10^100) and M is less than >> 10^5. The other approach was repeated squaring and taking mod of >> expression. Is there any other way to do this in python more faster >> than log N. > > How do you arrive at log N as the performance number? > >> >> def power(A,N,M): >> ret=1 >> while(N): >> if(N%2!=0):ret=(ret*A)%M >> A=(A*A)%M >> N=N//2 >> return ret > Because the N= N/2 operation in the loop means that the number of loops is equal to the number of bits in N, or the log-base-2 of N. DaveA From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 18:03:25 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 23:03:25 GMT Subject: Doctests and decorated methods don't get along References: <037d435d$0$1292$c3e8da3@news.astraweb.com> <4B6DBC4C.4080100@optimum.net> Message-ID: <037de16f$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 14:00:28 -0500, John Posner wrote: > On 2/6/2010 6:48 AM, Steven D'Aprano wrote: >> class MyStaticMethod(object): >> """Emulate built-in staticmethod descriptor.""" >> def __init__(self, f): >> self.f = f >> def __get__(self, obj, objtype=None): >> return self.f > > How about using a function, instead of a class, to implement the > decorator: I've had problems with function decorators and doctest in the past. If I remember the problem correctly, functools.wraps changing the __module__ of the wrapped function, making it look like it came from the functool module, and so doctest would not run the tests. But it seems that has been fixed in 2.6: I can confirm your version works as expected. Nevertheless, I think it is a limitation of doctest that it doesn't see methods using the descriptor protocol. Even if I could work around my immediate issue by using a function decorator (and I don't think I can) I'd still want to fix this problem. > I tried making the class-based implementation work by using > functools.wraps(), but I couldn't manage it. Me neither. I think the problem is that the doctest.DocTestFinder class doesn't find descriptor-based methods. It special cases staticmethod, classmethod and property. > Also, doesn't the decorator > protocol want the class to implement a __call__() method, not a > __get__() method? Or am I getting hung up (not the first time) at the > nexus of the descriptor and decorator protocols? In this case, I'm actually using a descriptor as the decorator. The descriptor is called at attribute lookup, before the method is called. __get__ returns a function, which has a __call__ method, and it should all just work. -- Steven From solipsis at pitrou.net Sat Feb 6 18:30:30 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sat, 6 Feb 2010 23:30:30 +0000 (UTC) Subject: TABS in the CPython C source code References: Message-ID: Le Sat, 06 Feb 2010 22:26:55 +0000, Benjamin Peterson a ?crit?: > Neil Hodgson gmail.com> writes: >> This would damage the usefulness of source control histories (svn >> annotate) as all of the converted lines would show this recent cosmetic >> change rather than the previous change which is likely to be a >> substantive modification. > > That's not completely true given svn diff -x -w. That's even less true given we aren't ashamed to make other kinds of cosmetic changes when desired, even though it also "damages the usefulness of source control histories" ;-) From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 18:35:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 23:35:11 GMT Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> Message-ID: <037de8e1$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 23:53:53 +0100, Martin Drautzburg wrote: > Hello all > > When I create an Object and set its __iter__ method from outside > > s = Sequence #one of my own classes > s.__iter__ = new.instancemethod(f,s,Sequence) I'm confused as to why you are aliasing your class before changing it. The above just makes s an alternative name for Sequence. Did you mean this? s = Sequence() # make an instance of the class > I get different results, depending on whether I call > > > for x in y.__iter__(): > print x What's y? Where does it come from? Is y supposed to be an instance of Sequence? > or > > for x in y: > print x > > The first case does what I expected, i.e. it iterates over whatever f() > yields. In the second case nothing is printed. I have the impression > that it still calls the original __iter__() method (the one defined at > the class level). Yes, that's almost certainly what is happening. As an optimization, Python bypasses the instance for special methods __NAME__. > Why is that so? > How can I replace the __iter__() method so it does what I want. The best solution is, find another way to do what you want. The clunky solution is to use delegation to wrap your class, and have the outer class re-direct calls to special methods to the instance first. > The reason I want to do such things is I need to implement operations > similar to what itertools do. However I want my own classes and the > operations are only similar to itertools, but differ in significant > details. I don't understand this. If you want iterator operations "similar to itertools", why does this mean you need to replace anything? Just create your own iterators. Or use pre-processing and post-processing to get what you want. Can you show an example of what you would like to happen? -- Steven From jonny.lowe.12345 at gmail.com Sat Feb 6 18:41:09 2010 From: jonny.lowe.12345 at gmail.com (jonny lowe) Date: Sat, 6 Feb 2010 15:41:09 -0800 (PST) Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> Message-ID: On Feb 5, 11:10?pm, "Gabriel Genellina" wrote: > En Fri, 05 Feb 2010 17:39:07 -0300, jonny lowe > escribi?: > > > > > > > On Feb 4, 8:20 pm, exar... at twistedmatrix.com wrote: > >> On 01:56 am, jonny.lowe.12... at gmail.com wrote: > >> >What I want is to have an easy way tomergeinput.txt and thestdout > >> >so that output.txt look like: > > >> >Enter a number: 42 > >> >You entered 42. > > >> >Here, the first 42 is of course from input.txt. > > >> It sounds like you might be looking forscript(1)? > > > $ script -c "./y < input.txt" output.txt > > Script started, file is output.txt > > gimme x:you entered hello > > Script done, file is output.txt > > Try moving the redirection out of the command: > > $ script -c ./y output.txt < input.txt > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - The result is the same as before. I've tested in fedora11. -jon From dickinsm at gmail.com Sat Feb 6 18:43:35 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 6 Feb 2010 15:43:35 -0800 (PST) Subject: Last M digits of expression A^N References: <964f3a2e-2eac-43ee-a3cc-9099e4cc2c36@h9g2000prn.googlegroups.com> Message-ID: <0c50037a-8cb0-4948-9978-46f4a56fb3da@l19g2000yqb.googlegroups.com> On Feb 5, 8:14?pm, mukesh tiwari wrote: > I have to find out the last M digits of expression.One thing i can do > is (A**N)%M but my ?A and N are too large (10^100) and M is less than > 10^5. The other approach ? was ?repeated squaring and taking mod of > expression. Is there any other way to do this in python more faster > than log N. By the way, given that your M is fairly tiny compared with A and N, a little bit of elementary number theory (e.g., Euler's theorem) could save you a lot of time here. For example, pow(a, n, 10**5) is equivalent to pow(a, 5 + (n - 5) % 40000, 10**5) for any n >= 5. Not sure if this is the kind of thing you're looking for. -- Mark From lists at cheimes.de Sat Feb 6 18:54:44 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 07 Feb 2010 00:54:44 +0100 Subject: new.instancemethod __iter__ In-Reply-To: <2036837.yhpURs0z1y@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> Message-ID: <4B6E0144.8090603@cheimes.de> Martin Drautzburg wrote: > The first case does what I expected, i.e. it iterates over whatever f() > yields. In the second case nothing is printed. I have the impression > that it still calls the original __iter__() method (the one defined at > the class level). > > Why is that so? > How can I replace the __iter__() method so it does what I want. Virtually all __magic__ methods are looked up on the type, not the instance. So obj.__iter__() translates into type(obj).__iter__(obj). If you *really* need to overwrite __iter__ on your instance rather than defining it on your class, you need to proxy the method call: class MyObject(object): def __iter__(self): return self.myiter() obj = MyObject() obj.myiter = myiter That should do the trick. Christian From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 18:58:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 06 Feb 2010 23:58:07 GMT Subject: Doctests and decorated methods don't get along References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <037dee41$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 14:39:00 -0500, Terry Reedy wrote: > On 2/6/2010 6:48 AM, Steven D'Aprano wrote: >> It seems that doctest doesn't discover or execute doctests in methods >> which have been decorated. [...] > Doctest has to scan the dict, so it does not see the attribute-lookup > result. Ahaha, now we're getting somewhere. If I do this: >>> import inspect >>> import test_doctests >>> method3 = test_doctests.Test.__dict__['method3'] >>> inspect.isfunction(method3) False >>> inspect.ismethod(method3) False But: >>> inspect.ismethoddescriptor(method3) True which is what I want to see. Presumably doctest.DocTestFinder needs a patch to call methoddescriptor's __get__ method. (BTW, classmethod, staticmethod and property are all special-cased by DocTestFinder.) -- Steven From hzhuo1 at gmail.com Sat Feb 6 19:05:15 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sat, 6 Feb 2010 16:05:15 -0800 (PST) Subject: How to print all expressions that match a regular expression References: Message-ID: Thanks for your reply. So there isn't such a routine just because some of the regular expressions cannot be enumerated. However, some of them can be enumerated. I guess I have to write a function myself. Zhuo On Feb 6, 5:23?pm, Roy Smith wrote: > In article > , > > > > > > ?"hzh... at gmail.com" wrote: > > Hi, > > > I am a fresh man with python. I know there is regular expressions in > > Python. What I need is that given a particular regular expression, > > output all the matches. For example, given ?[1|2|3]{2}? as the regular > > expression, the program should output all 9 matches, i.e., "11 12 13 > > 21 22 23 31 32 33". > > > Is there any well-written routine in Python or third-party program to > > do this? If there isn't, could somebody make some suggestions on how > > to write it myself? > > > Thanks. > > > Zhuo > > Please enumerate all the strings which match ".*". ?Use additional sheets > of paper if needed. From news123 at free.fr Sat Feb 6 19:07:49 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 01:07:49 +0100 Subject: sshd in python for windows 7 Message-ID: <4b6e0455$0$20650$426a34cc@news.free.fr> Hi, I wondered which modules would be best to perform following task: A user uses a standard ssh (e.g. putty or openssh) client and performs an ssh to a windows host The windows host would run a python script acting as ssh server. Instead of controlling a shell the user would directly have access to stdin/stdout/stderr of another python script. Another option would of course be to install a non python sshd for windows. The only ssh server for windows, that I know is however a little heavy as it is openssh under cygwin (and I only used it on XP hosts.) I'm still not sure, whether python as sshd is a good choice or whether any other sshd would be better. bye N From news123 at free.fr Sat Feb 6 19:24:33 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 01:24:33 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows In-Reply-To: References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: <4b6e0841$0$22047$426a74cc@news.free.fr> Hi Gabriel, Gabriel Genellina wrote: > En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: > >> I'm using an XMLRPC server under Windows. >> >> What I wonder is how I could create a server, that can be killed with >> CTRL-C >> >> The server aborts easily with CTRL-BREAK but not with CTRL-C (under >> Windows) >> >> If I press CTRL-C it will only abort when the next RPC call occurs. >> It seems it is blocking in the select() call in the handle_request() >> function. > > Python 2.6 and up behaves exactly as you want. > On previous versions you may use this: > > class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): > > ... your methods ... > > if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): > > # pre 2.6 > quit = False > > def serve_forever(self): > while not self.quit: > self.handle_request() > > def shutdown(self): > self.quit = True > > def server_bind(self): > self.socket.settimeout(1.0) > SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) > Overloading server_bind() with your version solved my problem. thanks again N From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 19:26:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 00:26:36 GMT Subject: How to print all expressions that match a regular expression References: Message-ID: <037df4ef$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1 at gmail.com wrote: > Thanks for your reply. > So there isn't such a routine just because some of the regular > expressions cannot be enumerated. However, some of them can be > enumerated. I guess I have to write a function myself. How do you expect to tell the ones that can be enumerated apart from those that can't be? Regular expressions are programs in a "regex" programming language. What you are asking for is the same as saying: "Is there a program that can enumerate every possible set of data that is usable as valid input for a given program?" This, in turn, is equivalent to the Halting Problem -- if you can solve one, you can solve the other. You might like to google on the Halting Problem before you spend too much time on this. (Note, however, it isn't necessary to solve the Halting Problem for *all* cases in order to have a useful Endless Loop Detector program.) Why do you think you need this? Seems to me you're starting on an extraordinarily difficult job. I hope the benefit is equally extraordinary. [Aside: Python regexes aren't Turing Complete. I'm not sure about Perl regexes. Either way, this might actually be less difficult than the Halting Problem, as in "amazingly difficult" rather than "impossible".] -- Steven From jeanmichel at sequans.com Sat Feb 6 19:48:22 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sun, 07 Feb 2010 01:48:22 +0100 Subject: xmlrcp - how to marshall objects In-Reply-To: <1265400942.3301.14.camel@linux-m3mt> References: <4B6C4150.8050705@sequans.com> <4B6C5444.4090205@sequans.com> <1265400942.3301.14.camel@linux-m3mt> Message-ID: <4B6E0DD6.1000908@sequans.com> Adam Tauno Williams wrote: > On Fri, 2010-02-05 at 18:24 +0100, Jean-Michel Pichavant wrote: > >> Jean-Michel Pichavant wrote: >> >>> Deos anyone knows where to find an code sample describing how to >>> implement the interface to marshall one object into XMLRPC compliant >>> structures ? >>> I googled without any success, and what google does not find does not >>> exist. >>> Let say I have this very simple class: >>> class Point: >>> def __init__(self, x, y): >>> self.x = x >>> self.y = y >>> I've looked into xmlrpc code, I see 2 options: >>> 1/ override the Marshaller class of client and server >>> 2/ looks like the lib is supporting a WRAPPER list system, it uses to >>> Marshall Datetime & Binary object. Can it be possible to add its own >>> class (could require to emplement the 'encode' method) >>> I sense I will spend much more time than required unless someone is >>> pointing me in the right direction. >>> >> I realized I gave a poor example, actually the Point object is marshable >> (marshallable ? like to invent new words), xmlrpc will try to marshall >> using __dict__ if possible. >> import os >> class Point: >> def __init__(self, x, y): >> self.x = x >> self.y = y >> self.notMarshallable = os >> > > This example doesn't make any sense. Why would you set a variable equal > to an important module in a class named Point? > > What is it you are actually trying to accomplish? If you are trying to > create an object publishing environment then maybe something like - > > rpc = xmlrpclib.loads(payload, use_datetime=True) > method = rpc[1].split('.') > classname = method[0] > methodname = method[1] > parameters = rpc[0] > classclass = eval(classname) > handler = classclass() > call = getattr(handler, method_name) > result = apply(call, parameters) > result = xmlrpclib.dumps(tuple([result]), methodresponse=True) > > Obviously add copious amounts of exception handling and a security > model. > I just took the first non marshallable object that came to my mind. So yes that makes no sense but it was an example. I'll try to sitck to what I'm really trying to do. I have 2 classes, defined on server side class Pool: def foo(): return 42 class Stream: def __init__(self, pool): """@param pool: the pool the stream belongs so.""" self._pool = pool I won't need any more detail I think for my example. Now If I want to return a stream, sending it to the client, I can't because xmlrpclib won't be able to marshall _pool. What I need is the sever being able to marshall a Stream. I would like to overide the marshall method of that stream, so that instead of raising an error because self._pool is not marshallable, it sends an int instead identifying the pool on the server side. class Pool: instances = {} when marshalling a stream: id = some_unique_generated_int() Pool.instances[id] = self._pool self._pool = id # an int will be gracefully marshalled by the defaut marshaller # call here the default marshaller Then, when unmarshalling, the server can reassign the _pool reference using the id provided by the client. I hope I am being clear. JM From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 19:51:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 00:51:19 GMT Subject: Doctests and decorated methods don't get along References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <037dfaba$0$1292$c3e8da3@news.astraweb.com> On Sat, 06 Feb 2010 14:39:00 -0500, Terry Reedy wrote: > On 2/6/2010 6:48 AM, Steven D'Aprano wrote: >> It seems that doctest doesn't discover or execute doctests in methods >> which have been decorated [by method descriptors]. [...] >> This looks like bug to me. Have I missed anything? > > I would call it a limitation as I do not see the doc as promising > otherwise. I believe doctest predates the descripter protocol, at least > in its current form, so it may not be completely descriptor-aware. You > certainly could file a feature request for improved recognition and > subsequent calling of __get__. An initial patch would improve chances of > action. I have found an existing report for this issue: http://bugs.python.org/issue4037 The original poster's suggested fix was on the right track, but not complete. I've added a patch which works according to my tests. Since this report is currently unassigned, is there a protocol for raising its profile and having somebody check my patch for inclusion? Should I just send an email to python-dev? -- Steven From alfps at start.no Sat Feb 6 19:51:19 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 01:51:19 +0100 Subject: How to print all expressions that match a regular expression In-Reply-To: <037df4ef$0$1292$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1 at gmail.com wrote: > >> Thanks for your reply. >> So there isn't such a routine just because some of the regular >> expressions cannot be enumerated. However, some of them can be >> enumerated. I guess I have to write a function myself. > > How do you expect to tell the ones that can be enumerated apart from > those that can't be? > > Regular expressions are programs in a "regex" programming language. What > you are asking for is the same as saying: > > "Is there a program that can enumerate every possible set of data that is > usable as valid input for a given program?" > > This, in turn, is equivalent to the Halting Problem -- if you can solve > one, you can solve the other. You might like to google on the Halting > Problem before you spend too much time on this. Hm, well, text editors /regularly/ do repeated regular expression searches, producing match after match after match, on request. To use that /expression/, it seems that Theory is yet again up against Hard Reality. In such a contest where something doesn't quite /match/, is the Map, the Terrain, or perhaps the Interpretation of how the Map applies to Terrain, at fault? > (Note, however, it isn't necessary to solve the Halting Problem for *all* > cases in order to have a useful Endless Loop Detector program.) > > Why do you think you need this? Seems to me you're starting on an > extraordinarily difficult job. I hope the benefit is equally > extraordinary. Depending on the application there may be more efficient ways than applying a general purpose regexp matcher. Don't know about modern *nix but in the old days there were different greps for different purposes, egrep, fgrep, whatever. Aside: the only article by Niklaus Wirth that I can remember reading was about how to transform algorithms to more efficient ones by exploiting the invariants, and one of his examples was simple text searching, where you can advance the pattern a number of characters depending on the current non-matching character. > [Aside: Python regexes aren't Turing Complete. I'm not sure about Perl > regexes. Either way, this might actually be less difficult than the > Halting Problem, as in "amazingly difficult" rather than "impossible".] Cheers, - Alf From buzzard at urubu.freeserve.co.uk Sat Feb 6 19:52:48 2010 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sun, 07 Feb 2010 00:52:48 +0000 Subject: max / min / smallest float value on Python 2.5 Message-ID: Hello, I'm trying to find a clean and reliable way of uncovering information about 'extremal' values for floats on versions of Python earlier than 2.6 (just 2.5 actually). I don't want to add a dependence on 3rd party modules just for this purpose. e.g. For the smallest positive float I'm using, import platform if platform.architecture()[0].startswith('64'): TINY = 2.2250738585072014e-308 else: TINY = 1.1754943508222875e-38 where I've extracted the values for TINY from numpy in IDLE, >>> float(numpy.finfo(numpy.float32).tiny) 1.1754943508222875e-38 >>> float(numpy.finfo(numpy.float64).tiny) 2.2250738585072014e-308 >>> I'm not 100% sure how reliable this will be across platforms. Any ideas about the cleanest, reliable way of uncovering this type of information? (I can always invoke numpy, or use Python 2.6, on my home machine and hardcode the retrieved values, but I need the code to run on 2.5 without 3rd part dependencies.) Cheers. Duncan From steve at holdenweb.com Sat Feb 6 19:54:54 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 06 Feb 2010 19:54:54 -0500 Subject: Your beloved python features In-Reply-To: <4b6c2095$0$22370$426a74cc@news.free.fr> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c2095$0$22370$426a74cc@news.free.fr> Message-ID: <4B6E0F5E.10503@holdenweb.com> Bruno Desthuilliers wrote: > apeach a ?crit : >> I love intuitive type recognition. >> >> no need to 'DIM everything AS Integer' etc.! >> > > not to mention the ever hilarious (that is, when you don't have to > maintain it) typical Java idiom: > > EveryThing theEveryThing = new EveryThing(); > http://www.artima.com/weblogs/viewpost.jsp?thread=42242 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Sat Feb 6 20:15:48 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sun, 07 Feb 2010 02:15:48 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: <4b6c9b28$0$10494$426a74cc@news.free.fr> References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> Message-ID: <4B6E1444.9060001@sequans.com> News123 wrote: > Hi JM, > > Jean-Michel Pichavant wrote: > >> import socket >> >> # server >> server = SimpleXMLRPCServer((socket.gethostname(), 5000), >> logRequests=False, allow_none=True) >> >> >> # client >> xmlrpclib.ServerProxy("http://%s.yourdomain.com:%s" % >> (socket.gethostname(), 5000)) >> > > > Well This was exactly my question. > for virtual web servers I cannot just use the IP-address. > some XMLRPC servers do need the histname within the HTTP-POST request. > > a valid IP address would make it > if I just replaced the hostname with the IP addres, then certain servers > would not be accessable. > > I had to use the IP-address for connecteing why not using the host names? > , but to pass the hostname in > the HTTP-POST request. > > I wondered how to convince puthon's SimpleXMLRPCServer (or any other > standard python xmlrpc server), such, that I can obtain above mentioned > goal. > > > bye > > N > I'm puzzled. Unless my english is failing me, everything would be solved using hostnames if I follow you. Why don't you do that ? I am no network/IP guru, but it sounds very weird to have requests rejected when using IP addresses. Are you sure your host names are resolved with the same IPM address you are using ? JM From anand.shashwat at gmail.com Sat Feb 6 20:17:34 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 06:47:34 +0530 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: On Sun, Feb 7, 2010 at 6:22 AM, duncan smith wrote: > Hello, > I'm trying to find a clean and reliable way of uncovering information > about 'extremal' values for floats on versions of Python earlier than 2.6 > (just 2.5 actually). I don't want to add a dependence on 3rd party modules > just for this purpose. e.g. For the smallest positive float I'm using, > > > import platform > if platform.architecture()[0].startswith('64'): > TINY = 2.2250738585072014e-308 > else: > TINY = 1.1754943508222875e-38 > The above code is executed on OSX (snow leopard - 64 bit) without any issue. Your implementation seems fine to me. > > > where I've extracted the values for TINY from numpy in IDLE, > > > >>> float(numpy.finfo(numpy.float32).tiny) > 1.1754943508222875e-38 > >>> float(numpy.finfo(numpy.float64).tiny) > 2.2250738585072014e-308 > >>> > > > I'm not 100% sure how reliable this will be across platforms. Any ideas > about the cleanest, reliable way of uncovering this type of information? (I > can always invoke numpy, or use Python 2.6, on my home machine and hardcode > the retrieved values, but I need the code to run on 2.5 without 3rd part > dependencies.) Cheers. > > Duncan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From no.email at nospam.invalid Sat Feb 6 20:21:15 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 06 Feb 2010 17:21:15 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4b6c2095$0$22370$426a74cc@news.free.fr> Message-ID: <7xaavlet84.fsf@ruckus.brouhaha.com> Steve Holden writes: >> EveryThing theEveryThing = new EveryThing(); > http://www.artima.com/weblogs/viewpost.jsp?thread=42242 Pretty cool! I see your blog post criticizing Java's lack of type inference, and then immediately adjacent to the post there's a banner ad for a book called "Programming in Scala". I think I am getting a mixed message ;-) From benjamin.kaplan at case.edu Sat Feb 6 20:23:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 6 Feb 2010 20:23:16 -0500 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: On Sat, Feb 6, 2010 at 7:52 PM, duncan smith wrote: > Hello, > ? ? ?I'm trying to find a clean and reliable way of uncovering information > about 'extremal' values for floats on versions of Python earlier than 2.6 > (just 2.5 actually). ?I don't want to add a dependence on 3rd party modules > just for this purpose. ?e.g. For the smallest positive float I'm using, > > > import platform > if platform.architecture()[0].startswith('64'): > ? ?TINY = 2.2250738585072014e-308 > else: > ? ?TINY = 1.1754943508222875e-38 > > > where I've extracted the values for TINY from numpy in IDLE, > > >>>> float(numpy.finfo(numpy.float32).tiny) > 1.1754943508222875e-38 >>>> float(numpy.finfo(numpy.float64).tiny) > 2.2250738585072014e-308 >>>> > > > I'm not 100% sure how reliable this will be across platforms. ?Any ideas > about the cleanest, reliable way of uncovering this type of information? ?(I > can always invoke numpy, or use Python 2.6, on my home machine and hardcode > the retrieved values, but I need the code to run on 2.5 without 3rd part > dependencies.) ?Cheers. > > Duncan >>> import platform >>> platform.architecture() ('32bit', '') >>> tiny = 2.22e-308 >>> tiny 2.2200000000000001e-308 float32 vs. float64 has nothing to do with a 32-bit vs. a 64-bit platform. It's single precision floating-point (C float) vs. double-precision floating point (C double). It's used in numpy because numpy optimizes everything like crazy. Python always uses doubles. >>> import numpy >>> numpy.double > -- > http://mail.python.org/mailman/listinfo/python-list > From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 20:28:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 01:28:47 GMT Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: <037e0381$0$1292$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 01:51:19 +0100, Alf P. Steinbach wrote: >> Regular expressions are programs in a "regex" programming language. >> What you are asking for is the same as saying: >> >> "Is there a program that can enumerate every possible set of data that >> is usable as valid input for a given program?" >> >> This, in turn, is equivalent to the Halting Problem -- if you can solve >> one, you can solve the other. You might like to google on the Halting >> Problem before you spend too much time on this. > > Hm, well, text editors /regularly/ do repeated regular expression > searches, producing match after match after match, on request. I think you have completely misunderstood what I'm saying. I'm not saying that you can't *run* a regular expression against text and generate output. That truly would be a stupid thing to say, because I clearly can do this: >>> import re >>> mo = re.search("p.rr.t", ... "Some text containing parrots as well as other things") >>> mo.group() 'parrot' As you point out, it's not hard to embed a regex interpreter inside a text editor or other application, or to call an external library. What is difficult, and potentially impossible, is to take an arbitrary regular expression such as "p.rr.t" (the program in the regex language) and generate every possible data ("parrot", "pbrrat", ...) that would give a match when applied to that regular expression. Now, in this case, my example is very simple, and it would be easy to enumerate every possible data: there's only 65025 of them, limiting to the extended ASCII range excluding NUL (1-255). But for an arbitrary regex, it won't be that easy. Often it will be unbounded: the example of enumerating every string that matches .* has already been given. The second problem is, generating the data which gives the output you want is potentially very, very, difficult, potentially as difficult as finding collisions in cryptographic hash functions: "Given the function hashlib.sha256, enumerate all the possible inputs that give the hexadecimal result 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." This too is unbounded, but you'll have your work cut out just to find *one* match, let alone an infinite number of them. (In this specific example, your best bet is to try a crib: knowing what newsgroup this is, and knowing what I've written in the past, the message is predictable for being totally unexpected. And yes, that's a hint. A shiny penny for the first person to guess what it is.) I'm suggesting that, in general, there's no way to tell in advance which regexes will be easy and which will be hard, and even when they are easy, the enumeration will often be infinite. -- Steven From bartc at freeuk.com Sat Feb 6 20:34:14 2010 From: bartc at freeuk.com (bartc) Date: Sun, 07 Feb 2010 01:34:14 GMT Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: "Arnaud Delobelle" wrote in message news:m28wb6ypfs.fsf at googlemail.com... > "Gabriel Genellina" writes: > >> En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: >>> "Steve Holden" wrote in message >>> news:mailman.1998.1265399766.28905.python-list at python.org... >>>> Arnaud Delobelle wrote: >>>>> Robert Kern writes: >>>>> >>>>>> I prefer Guido's formulation (which, naturally, I can't find a direct >>>>>> quote for right now): if you expect that a boolean argument is only >>>>>> going to take *literal* True or False, then it should be split into >> ^^^^^^^^^^^^^^^^^^^^^^^ >>>>>> two functions. >>>>> >>>>> So rather than three boolean arguments, would you have eight >>>>> functions? >>>>> >>>> If there's genuinely a need for that functionality, yes. >>> >>> So you want a function such as drawtext(s, bold=true, italic=false, >>> underline=true) to be split into: >>> >>> drawtext(s) >>> drawtextb(s) >>> drawtexti(s) >>> drawtextu(s) >>> drawtextbi(s) >>> drawtextbu(s) >>> drawtextiu(s) >>> drawtextbiu(s) >> >> Note the *literal* part. If you (the programmer) is likely to know the >> parameter value when writing the code, then the function is actually two >> separate functions. > > Thanks, I understand what Steve Holden meant now. I've just noticed that 'literal' part. But I think I still disagree. For a real-world example, it means instead of having a room with a light-switch in it, if I *know* I want the light on or off, I should have two rooms: one with the light permanently on, and one with it permanently off, and just walk into the right one. -- Bartc From jeanmichel at sequans.com Sat Feb 6 20:36:34 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Sun, 07 Feb 2010 02:36:34 +0100 Subject: Calendar GUI In-Reply-To: <4B6D055A.30901@gmail.com> References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> <4B6D055A.30901@gmail.com> Message-ID: <4B6E1922.4030404@sequans.com> Michael Torrie wrote: > Gabriel wrote: > >> On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli wrote: >> >>> I'm working on setting up some software for a Peruvian non-profit to help >>> them organize their incoming volunteers. One of the features I'd like to add >>> is a calendar-like view of the different volunteers arrival dates and >>> staying time, with potentially some other info through some double-click >>> action. Rather than writing a calendar gui myself, is there some open-source >>> calendar program you guys could recommend that I could plug into? It has to >>> be run locally, as the internet isn't so reliable down here, but other than >>> that something simple and clean is ideal. >>> >> I wrote a gtk gui for google calendar. >> >> Maybe you can adapt it to your needs. >> >> http://code.google.com/p/googlecalendar-gtk/ >> > > Would this work without an internet connection? The original poster > stated that internet isn't so reliable, hence the need for a local solution. > > How about zimbra ? http://www.zimbra.com/products/calendar-collaboration.html Ok, that's heavy stuff, but it's free, open source and widely used. JM From python at mrabarnett.plus.com Sat Feb 6 20:48:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 07 Feb 2010 01:48:12 +0000 Subject: How to print all expressions that match a regular expression In-Reply-To: References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B6E1BDC.5090002@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Sat, 06 Feb 2010 16:05:15 -0800, hzhuo1 at gmail.com wrote: >> >>> Thanks for your reply. >>> So there isn't such a routine just because some of the regular >>> expressions cannot be enumerated. However, some of them can be >>> enumerated. I guess I have to write a function myself. >> >> How do you expect to tell the ones that can be enumerated apart from >> those that can't be? >> >> Regular expressions are programs in a "regex" programming language. >> What you are asking for is the same as saying: >> >> "Is there a program that can enumerate every possible set of data that >> is usable as valid input for a given program?" >> >> This, in turn, is equivalent to the Halting Problem -- if you can >> solve one, you can solve the other. You might like to google on the >> Halting Problem before you spend too much time on this. > > Hm, well, text editors /regularly/ do repeated regular expression > searches, producing match after match after match, on request. > [snip] I'm not sure you understood what the OP was requesting: a way of generating the strings which would match a given regex. From lists at cheimes.de Sat Feb 6 20:55:48 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 07 Feb 2010 02:55:48 +0100 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: <4B6E1DA4.2060908@cheimes.de> duncan smith wrote: > Hello, > I'm trying to find a clean and reliable way of uncovering > information about 'extremal' values for floats on versions of Python > earlier than 2.6 (just 2.5 actually). I don't want to add a dependence > on 3rd party modules just for this purpose. e.g. For the smallest > positive float I'm using, > > > import platform > if platform.architecture()[0].startswith('64'): > TINY = 2.2250738585072014e-308 > else: > TINY = 1.1754943508222875e-38 > > > where I've extracted the values for TINY from numpy in IDLE, > > > >>> float(numpy.finfo(numpy.float32).tiny) > 1.1754943508222875e-38 > >>> float(numpy.finfo(numpy.float64).tiny) > 2.2250738585072014e-308 You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's float type is build upon C's double precision float type on both 32 and 64 bit builds. The simple precision 32bit float type isn't used. The DBL_MIN and DBL_MAX values are equal on all platforms that have full IEEE 754 float point support. The radix may be different, though. Christian From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 20:57:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 01:57:24 GMT Subject: Dreaming of new generation IDE References: Message-ID: <037e0a36$0$1292$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 01:34:14 +0000, bartc wrote: > For a real-world example, it means instead of having a room with a > light-switch in it, if I *know* I want the light on or off, I should > have two rooms: one with the light permanently on, and one with it > permanently off, and just walk into the right one. I don't think you can apply real-world analogies to software in that way. They're too different. Think of the objections to having two rooms, one permanently lit up, the other permanently not: (1) Having two rooms is expensive and wasteful of physical space, which is in short supply. (2) You typically use rooms for storing things (furniture and smaller objects), having two rooms mean you would need to clone every object inside it and somehow keep them in perfect synchronisation. (3) the light that is always on will use electricity 24 hours a day, regardless of whether you are inside it or not. But none of those objections apply to functions: (1) Functions are cheap and live in memory, which is not in short supply unless you're programming for an embedded device. (1a) Even if you are programming in a device that is short of memory, the overhead of a second function is minimal. There's little difference between: def func(flag): if flag: blockA else: blockB and def funcA(): blockA def funcB(): blockB for any non-trivial code blocks, particularly if any common code is factored out into another function which you call. (2) Functions aren't typically used for storage, and when they need external data, it is easy to have them access a common data store. (3) Functions don't use CPU cycles just by existing. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 21:09:53 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 02:09:53 GMT Subject: max / min / smallest float value on Python 2.5 References: Message-ID: <037e0d22$0$1292$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 00:52:48 +0000, duncan smith wrote: > Hello, > I'm trying to find a clean and reliable way of uncovering > information about 'extremal' values for floats on versions of Python > earlier than 2.6 (just 2.5 actually). I don't want to add a dependence > on 3rd party modules just for this purpose. e.g. For the smallest > positive float I'm using, Assuming that your architecture is based on binary floats: >>> x = 1.0/2 >>> while 0.0 + x != 0.0: ... smallest = x ... x /= 2.0 ... >>> smallest 4.9406564584124654e-324 which is the smallest number that can be distinguished from zero on my system. If you're running on some weird platform with non-binary floats (perhaps a Russian ternary mainframe, or an old supercomputer with decimal floats) then you're on your own. I calculated this using Python 2.5. In 2.6, I see this: >>> sys.float_info sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.2204460492503131e-16, radix=2, rounds=1) So there's obviously a difference between how I calculate the smallest number and what Python thinks. The reason for this is left as an exercise. -- Steven From invalid at invalid.invalid Sat Feb 6 21:44:27 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 7 Feb 2010 02:44:27 +0000 (UTC) Subject: How to print all expressions that match a regular expression References: Message-ID: On 2010-02-06, Roy Smith wrote: >> I am a fresh man with python. I know there is regular expressions in >> Python. What I need is that given a particular regular expression, >> output all the matches. [..] > Please enumerate all the strings which match ".*". Use additional sheets > of paper if needed. And be sure to show your work. -- Grant From alfps at start.no Sat Feb 6 21:53:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 03:53:49 +0100 Subject: How to print all expressions that match a regular expression In-Reply-To: <037e0381$0$1292$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sun, 07 Feb 2010 01:51:19 +0100, Alf P. Steinbach wrote: > >>> Regular expressions are programs in a "regex" programming language. >>> What you are asking for is the same as saying: >>> >>> "Is there a program that can enumerate every possible set of data that >>> is usable as valid input for a given program?" >>> >>> This, in turn, is equivalent to the Halting Problem -- if you can solve >>> one, you can solve the other. You might like to google on the Halting >>> Problem before you spend too much time on this. >> Hm, well, text editors /regularly/ do repeated regular expression >> searches, producing match after match after match, on request. > > I think you have completely misunderstood what I'm saying. Yes. > I'm not saying that you can't *run* a regular expression against text and > generate output. That truly would be a stupid thing to say, because I > clearly can do this: > >>>> import re >>>> mo = re.search("p.rr.t", > ... "Some text containing parrots as well as other things") >>>> mo.group() > 'parrot' > > As you point out, it's not hard to embed a regex interpreter inside a > text editor or other application, or to call an external library. > > What is difficult, and potentially impossible, is to take an arbitrary > regular expression such as "p.rr.t" (the program in the regex language) > and generate every possible data ("parrot", "pbrrat", ...) that would > give a match when applied to that regular expression. Hm, that's not difficult to do, it's just like counting, but it's rather meaningless since either the output is trivial or it's in general exponential or infinite. So it seems we both misunderstood the problem. I didn't read the top level article until now, and reading it, I can't make sense of it. It sounds like some kind of homework problem, but without the constraints that surely would be there in a homework problem. > Now, in this case, my example is very simple, and it would be easy to > enumerate every possible data: there's only 65025 of them, limiting to > the extended ASCII range excluding NUL (1-255). But for an arbitrary > regex, it won't be that easy. Often it will be unbounded: the example of > enumerating every string that matches .* has already been given. > > The second problem is, generating the data which gives the output you > want is potentially very, very, difficult, potentially as difficult as > finding collisions in cryptographic hash functions: > > "Given the function hashlib.sha256, enumerate all the possible inputs > that give the hexadecimal result > 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." I tried some "parrot" variants but no dice. :-( [snip] > I'm suggesting that, in general, there's no way to tell in advance which > regexes will be easy and which will be hard, and even when they are easy, > the enumeration will often be infinite. I agree about the (implied) meaningless, exponential/infinite output, which means that possibly that's not what the OP meant, but disagree about the reasoning about "no way": really, regular expressions are /very/ limited so it's not hard to compute up front the number of strings it can generate from some given character set, in time linear in the length of the regexp. Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation that denotes "digit sequence") yields an infinite number of strings. And otherwise the regexp is of the form ABCDE..., where A, B, C etc are parts that each can generate a certain finite number of strings; multiplying these numbers gives the total number of strings that the regexp can generate. Cheers, - Alf From buzzard at urubu.freeserve.co.uk Sat Feb 6 22:02:05 2010 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sun, 07 Feb 2010 03:02:05 +0000 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: Christian Heimes wrote: > duncan smith wrote: >> Hello, >> I'm trying to find a clean and reliable way of uncovering >> information about 'extremal' values for floats on versions of Python >> earlier than 2.6 (just 2.5 actually). I don't want to add a dependence >> on 3rd party modules just for this purpose. e.g. For the smallest >> positive float I'm using, >> >> >> import platform >> if platform.architecture()[0].startswith('64'): >> TINY = 2.2250738585072014e-308 >> else: >> TINY = 1.1754943508222875e-38 >> >> >> where I've extracted the values for TINY from numpy in IDLE, >> >> >> >>> float(numpy.finfo(numpy.float32).tiny) >> 1.1754943508222875e-38 >> >>> float(numpy.finfo(numpy.float64).tiny) >> 2.2250738585072014e-308 > > You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's > float type is build upon C's double precision float type on both 32 and > 64 bit builds. The simple precision 32bit float type isn't used. The > DBL_MIN and DBL_MAX values are equal on all platforms that have full > IEEE 754 float point support. The radix may be different, though. > > Christian OK, this is the sort of confusion I suspected. I wasn't thinking straight. The precise issue is that I'm supplying a default value of 2.2250738585072014e-308 for a parameter (finishing temperature for a simulated annealing algorithm) in an application. I develop on Ubuntu64, but (I am told) it's too small a value when run on a Win32 server. I assume it's being interpreted as zero and raising an exception. Thanks. Duncan From alfps at start.no Sat Feb 6 22:04:03 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 04:04:03 +0100 Subject: Dreaming of new generation IDE In-Reply-To: <037e0a36$0$1292$c3e8da3@news.astraweb.com> References: <037e0a36$0$1292$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sun, 07 Feb 2010 01:34:14 +0000, bartc wrote: > >> For a real-world example, it means instead of having a room with a >> light-switch in it, if I *know* I want the light on or off, I should >> have two rooms: one with the light permanently on, and one with it >> permanently off, and just walk into the right one. > > I don't think you can apply real-world analogies to software in that way. > They're too different. > > Think of the objections to having two rooms, one permanently lit up, the > other permanently not: > > (1) Having two rooms is expensive and wasteful of physical space, which > is in short supply. > > (2) You typically use rooms for storing things (furniture and smaller > objects), having two rooms mean you would need to clone every object > inside it and somehow keep them in perfect synchronisation. > > (3) the light that is always on will use electricity 24 hours a day, > regardless of whether you are inside it or not. > > But none of those objections apply to functions: > > (1) Functions are cheap and live in memory, which is not in short supply > unless you're programming for an embedded device. > > (1a) Even if you are programming in a device that is short of memory, the > overhead of a second function is minimal. There's little difference > between: > > def func(flag): > if flag: > blockA > else: > blockB > > > and > > > def funcA(): > blockA > > def funcB(): > blockB > > > for any non-trivial code blocks, particularly if any common code is > factored out into another function which you call. > > (2) Functions aren't typically used for storage, and when they need > external data, it is easy to have them access a common data store. > > (3) Functions don't use CPU cycles just by existing. I agree with your reasoning :-), but it's not either/or. Consider, sometimes one wants to do switch.off() and sometimes one wants to do original_switch_state = switch.state() switch.off() # ... Do things that are best done in utter darkness. switch.set_state( original_switch_state ) E.g. the "switch" might be the enabled/disabled state of some GUI widget. So IMHO it depends. Sometimes one wants both kinds of "protocols". Cheers, - Alf From malaclypse2 at gmail.com Sat Feb 6 22:15:51 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Sat, 6 Feb 2010 22:15:51 -0500 Subject: sshd in python for windows 7 In-Reply-To: <4b6e0455$0$20650$426a34cc@news.free.fr> References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <16651e81002061915v72cbc134he6c3c46f6add226c@mail.gmail.com> On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: > Hi, > > I wondered which modules would be best to perform following task: > > A user uses a standard ssh (e.g. putty or openssh) client and performs > an ssh to a windows host > > The windows host would run a python script acting as ssh server. The Twisted library has an sshd implementation, called conch. Here an article with a simple python sshd built with twisted: http://www.ibm.com/developerworks/linux/library/l-twist4.html -- Jerry From hzhuo1 at gmail.com Sat Feb 6 23:16:09 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sat, 6 Feb 2010 20:16:09 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> Message-ID: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> > > So it seems we both misunderstood the problem. > > I didn't read the top level article until now, and reading it, I can't make > sense of it. > Seems that you should read the whole thing before making a post, or else you cannot know what we are talking about. Steven doesn't misunderstand me. We are talking about what I need, and he tries to help. > > > "Given the function hashlib.sha256, enumerate all the possible inputs > > that give the hexadecimal result > > 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." > > I tried some "parrot" variants but no dice. :-( > > [snip] > This is a hash collision problem. Nobody has proved that SHA-256 is collision free, even not in the random oracle model, because people always suppose that a random oracle exists, and make hash function its substitution. That means it may be broken someday. And any provable security based on random oracle model is not secure. > > I'm suggesting that, in general, there's no way to tell in advance which > > regexes will be easy and which will be hard, and even when they are easy, > > the enumeration will often be infinite. It is hard to tell in advance. However, we can add some timing limit or counting limit, to make it an algorithm, which can halt. For example, whenever the program outputs more than 1000000 expressions that match the input regex, we can halt because that exceeds our limit. But surely this is not efficient because of the post-decision. > > Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation > that denotes "digit sequence") yields an infinite number of strings. Infinity is really relative, not absolute. It is relative to the computing speed. For example, the regex '^[0|1]{2048}$' is rather simple and doesn't contain '+' or '$', but trying to output all expressions that match it has a complexity of 2^2048. If we can do that, then we can break RSA-2048. We must face the reality . Zhuo From nobody at nowhere.com Sat Feb 6 23:19:20 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 04:19:20 +0000 Subject: WCK and PIL References: <1fbe5e4b-2179-410b-9f76-9d65a7a08dce@k19g2000yqc.googlegroups.com> Message-ID: On Fri, 05 Feb 2010 21:05:53 -0800, darnzen wrote: > I've written an app using the wck library (widget construction kit, > see http://www.effbot.org), in addition to the wckGraph module. What > I'd like to do, is take the output of one of my windows (happens to be > a graph), and save it as a *.png or *.gif. I was planning on using the > PIL for this. I'd like to use the code I have as is, without re- > writing all the graphic calls to use PIL methods. > > WCK uses its own "pixmap" class for storing images in memory. I can't > find any documentation or class reference for pixmap and what I find > in the source is confusing. A WCK pixmap is a "draw object" whose underlying drawable is a pixmap (i.e. a Tk pixmap, which is the platform's native "chunk of video memory" pixmap type) rather than a window. >From the source code, WCK doesn't appear to offer any way to retrieve the pixel data (i.e. there's no way to do the opposite of draw.paste()). From steve at REMOVE-THIS-cybersource.com.au Sat Feb 6 23:31:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 04:31:36 GMT Subject: max / min / smallest float value on Python 2.5 References: Message-ID: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 03:02:05 +0000, duncan smith wrote: > The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. Thanks. I'm trying to think of what sort of experiment would be able to measure temperatures accurate to less than 3e-308 Kelvin, and my brain boiled. Surely 1e-100 would be close enough to zero as to make no practical difference? Or even 1e-30? Whatever you're simulating surely isn't going to require 300+ decimal points of accuracy. I must admit I'm not really familiar with simulated annealing, so I could be completely out of line, but my copy of "Numerical Recipes ..." by Press et al has an example, and they take the temperature down to about 1e-6 before halting. Even a trillion times lower that that is 1e-15. -- Steven From nobody at nowhere.com Sat Feb 6 23:33:12 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 04:33:12 +0000 Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> Message-ID: On Sat, 06 Feb 2010 11:09:31 -0800, Jim wrote: > I generate some HTML and I want to include in my unit tests a check > for syntax. So I am looking for a program that will complain at any > syntax irregularities. > > I am familiar with Beautiful Soup (use it all the time) but it is > intended to cope with bad syntax. I just tried feeding > HTMLParser.HTMLParser some HTML containing '

ab

' and it > didn't complain. HTMLParser is a tokeniser, not a parser. It treats the data as a stream of tokens (tags, entities, PCDATA, etc); it doesn't know anything about the HTML DTD. For all it knows, the above example could be perfectly valid (the "b" element might allow both its start and end tags to be omitted). Does the validation need to be done in Python? If not, you can use "nsgmls" to validate any SGML document for which you have a DTD. OpenSP includes nsgmls along with the various HTML DTDs. From alfps at start.no Sat Feb 6 23:38:38 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 05:38:38 +0100 Subject: How to print all expressions that match a regular expression In-Reply-To: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: * hzhuo1 at gmail.com: >> So it seems we both misunderstood the problem. >> >> I didn't read the top level article until now, and reading it, I can't make >> sense of it. >> > > [1] Seems that you should read the whole thing before making a post, or > else you cannot know what we are talking about. > Steven doesn't misunderstand me. We are talking about what I need, and > he tries to help. If you were not misunderstood then you've posted a question for which there's no practical solution. >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( >> >> [snip] >> > > This is a hash collision problem. Nobody has proved that SHA-256 is > collision free, even not in the random oracle model, because people > always suppose that a random oracle exists, and make hash function its > substitution. That means it may be broken someday. And any provable > security based on random oracle model is not secure. Stephen's little challenge wasn't about breaking SHA-256 but about guessing his secret phrase, given his clues. >>> I'm suggesting that, in general, there's no way to tell in advance which >>> regexes will be easy and which will be hard, and even when they are easy, >>> the enumeration will often be infinite. > > It is hard to tell in advance. No, it's trivial. > [2] However, we can add some timing limit > or counting limit, to make it an algorithm, which can halt. For > example, whenever the program outputs more than 1000000 expressions > that match the input regex, we can halt because that exceeds our > limit. But surely this is not efficient because of the post-decision. You don't need to wait for that output to complete. You can calculate the number of strings up front. Like it appears that you do below: >> Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation >> that denotes "digit sequence") yields an infinite number of strings. > > Infinity is really relative, not absolute. It is relative to the > computing speed. For example, the regex '^[0|1]{2048}$' is rather > simple and doesn't contain '+' or '$', but trying to output all > expressions that match it has a complexity of 2^2048. If we can do > that, then we can break RSA-2048. > We must face the reality . Here it seems that you have no problem calculating number of combinations, yet above, at the paragraph marked [2], you talk about waiting for a million strings to be output before seeing that it's too much, and earlier, at the paragraph marked [1], you maintain that your original question about generating all such strings (completely impractical) was what you wanted help with? I'm sorry but I can't make sense of this; it appears to be meaningless. Perhaps if you tried to clarify the requirements a bit. Cheers & hth., - Alf From schifschaf at gmail.com Sat Feb 6 23:49:06 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sat, 6 Feb 2010 20:49:06 -0800 (PST) Subject: Help with regex search-and-replace (Perl to Python) Message-ID: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Hi, I've got some text that looks like this: Lorem [ipsum] dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna aliqua. and I want to make it look like this: Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua. (brackets replaced by braces). I can do that with Perl pretty easily: ~~~~ for (<>) { s/\[(.+?)\]/\{$1\}/g; print; } ~~~~ but am not able to figure out how to do it with Python. I start out trying something like: ~~~~ import re, sys withbracks = re.compile(r'\[(.+?)\]') for line in sys.stdin: mat = withbracks.search(line) if mat: # Well, this line has at least one. # Should be able to use withbracks.sub() # and mat.group() maybe ... ? line = withbracks.sub('{' + mat.group(0) + '}', line) # No, that's not working right. sys.stdout.write(line) ~~~~ but then am not sure where to go with that. How would you do it? Thanks. From schifschaf at gmail.com Sun Feb 7 00:04:44 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sat, 6 Feb 2010 21:04:44 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <1500989d-b1d9-4734-ac03-5d7b9d531aeb@c4g2000yqa.googlegroups.com> On Feb 5, 8:49?am, Roald de Vries wrote: > My reasoning: I needed a language more powerful than bash, but more ? > portable and faster to develop (at least small scripts) than C/C++. So ? > I needed a scripting language. Python, Ruby, Perl, Tcl, ...? > > Python seems to be the language with the most libraries available, I like Python a lot. That said, it looks like Perl's CPAN currently has approximately double the number of packages in the Cheeseshop. I'm guessing the CPAN is still growing, but I don't know how fast it is growing compared to the Cheeseshop. I won't venture a guess as to which has a higher percentage of older unmaintained packages. From nobody at nowhere.com Sun Feb 7 00:09:40 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 05:09:40 +0000 Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> Message-ID: On Sun, 07 Feb 2010 00:26:36 +0000, Steven D'Aprano wrote: >> So there isn't such a routine just because some of the regular >> expressions cannot be enumerated. No. There isn't a routine because no-one has yet felt any need to write one. >> However, some of them can be >> enumerated. I guess I have to write a function myself. > > How do you expect to tell the ones that can be enumerated apart from > those that can't be? The ones which use the '+', '*' and '{m,}' operators match an infinite number of strings; the rest can only match a finite number (assuming POSIX REs; Python also has +? and *?). ["Enumerate" isn't the correct word here. You can *enumerate* an infinite set, in the sense that you could write a Python generator for which any member will eventually be generated.] The obvious implementation is to construct the NFA then "run" it. If you know that the RE can only match finite strings (i.e. the graph is acyclic), then you can enumerate them using depth-first traversal. If it can match infinite strings (i.e. if there are any cycles in the graph), then you would need to use either breadth-first traversal or incrementally-bounded depth-first traversal. > [Aside: Python regexes aren't Turing Complete. I'm not sure about Perl > regexes. Either way, this might actually be less difficult than the > Halting Problem, as in "amazingly difficult" rather than "impossible".] "Regular expressions" aren't Turing complete; this is implicit in the definition of "regular". The Chomsky hierarchy has four levels, with higher levels require a more capable system to decide whether a string is a member of the language defined by the grammar: grammar decidable by regular finite automaton context-free pushdown automaton[1] context-sensitive linear-bounded automaton[2] recursively-enumerable Turing machine However, any "regular expression" syntax which allows backreferences (including the POSIX specification) isn't actually "regular" in the formal sense (as it requires an infinite number of states), but context-free. [1] pushdown automaton = finite automaton with a stack [2] linear-bounded automaton = Turing machine, except that it's "tape" is finite and proportional to the size of the input. http://en.wikipedia.org/wiki/Chomsky_hierarchy From alfps at start.no Sun Feb 7 00:19:13 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 06:19:13 +0100 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: * Schif Schaf: > Hi, > > I've got some text that looks like this: > > > Lorem [ipsum] dolor sit amet, consectetur > adipisicing elit, sed do eiusmod tempor > incididunt ut [labore] et [dolore] magna aliqua. > > and I want to make it look like this: > > > Lorem {ipsum} dolor sit amet, consectetur > adipisicing elit, sed do eiusmod tempor > incididunt ut {labore} et {dolore} magna aliqua. > > (brackets replaced by braces). I can do that with Perl pretty easily: > > ~~~~ > for (<>) { > s/\[(.+?)\]/\{$1\}/g; > print; > } > ~~~~ > > but am not able to figure out how to do it with Python. I start out > trying something like: > > ~~~~ > import re, sys > withbracks = re.compile(r'\[(.+?)\]') > for line in sys.stdin: > mat = withbracks.search(line) > if mat: > # Well, this line has at least one. > # Should be able to use withbracks.sub() > # and mat.group() maybe ... ? > line = withbracks.sub('{' + mat.group(0) + '}', line) > # No, that's not working right. > > sys.stdout.write(line) > ~~~~ > > but then am not sure where to go with that. > > How would you do it? I haven't used regexps in Python before, but what I did was (1) look in the documentation, (2) check that it worked. import re text = ( "Lorem [ipsum] dolor sit amet, consectetur", "adipisicing elit, sed do eiusmod tempor", "incididunt ut [labore] et [dolore] magna aliqua." ) withbracks = re.compile( r'\[(.+?)\]' ) for line in text: print( re.sub( withbracks, r'{\1}', line) ) Python's equivalent of the Perl snippet seems to be the same number of lines, and more clear. :-) Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Sun Feb 7 00:43:26 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 02:43:26 -0300 Subject: Subclassing datetime.date References: <87vdea9h2y.fsf@castleamber.com> Message-ID: En Sat, 06 Feb 2010 18:42:29 -0300, John Bokma escribi?: > Sir Wilhelm the Sturdy writes: >> >> I recently attempted to subclass the datetime.date object resulting in >> horror and confusion, before submitting to a has-a relationship. >> That's all fine and dandy, but out of curiosity I'd like to know what >> I'm missing. >> >> class MyDate(datetime.date): >> >> def __init__(self,*args,**kw): >> ... > __init__ is *not* the construction method, __new__ is (at least with new > style classes) You're right. But in this case, instead of overriding __new__, I would add a separate constructor to avoid confusion with the existing one (a classmethod, actually, like fromordinal and fromtimestamp): py> from datetime import date py> class date(date): ... @classmethod ... def fromDMY(cls, d, m=None, y=None): ... today = date.today() ... if m is None: m = today.month ... if y is None: y = today.year ... return cls(y, m, d) ... py> date.fromDMY(20, 3, 2010) date(2010, 3, 20) py> date.fromDMY(11) date(2010, 2, 11) -- Gabriel Genellina From schifschaf at gmail.com Sun Feb 7 00:45:39 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sat, 6 Feb 2010 21:45:39 -0800 (PST) Subject: Help with regex search-and-replace (Perl to Python) References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: On Feb 7, 12:19?am, "Alf P. Steinbach" wrote: > > I haven't used regexps in Python before, but what I did was (1) look in the > documentation, Hm. I checked in the repl, running `import re; help(re)` and the docs on the `sub()` method didn't say anything about using back-refs in the replacement string. Neat feature though. > (2) check that it worked. > > > import re > > text = ( > ? ? ?"Lorem [ipsum] dolor sit amet, consectetur", > ? ? ?"adipisicing elit, sed do eiusmod tempor", > ? ? ?"incididunt ut [labore] et [dolore] magna aliqua." > ? ? ?) > > withbracks = re.compile( r'\[(.+?)\]' ) > for line in text: > ? ? ?print( re.sub( withbracks, r'{\1}', line) ) > > Seems like there's magic happening here. There's the `withbracks` regex that applies itself to `line`. But then when `re.sub()` does the replacement operation, it appears to consult the `withbracks` regex on the most recent match it just had. Thanks. From nobody at nowhere.com Sun Feb 7 00:49:28 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 05:49:28 +0000 Subject: TABS in the CPython C source code References: Message-ID: On Sat, 06 Feb 2010 21:31:52 +0100, Alf P. Steinbach wrote: > The size-8 tabs look really bad in an editor configured with tab size 4, > as is common in Windows. I'm concluding that the CPython programmers > configure their Visual Studio's to *nix convention. 8-column tabs aren't a "*nix convention"; that's been the norm since the mechanical typewriter. Historically, software and hardware which knows what a "tab" could be split into two categories: 1. Tab stops are fixed at 8-column intervals. 2. Tab stops default to 8-column intervals but can be changed. Recently, a third category has appeared (tab stops default to something other than 8 columns). The most common example is Visual Studio. No surprise there: Microsoft has a track record of introducing slight incompatibilities into established standards. Just enough to inconvenience anyone using competing products, but not so much that anyone operating in a context where Microsoft isn't dominant has to abandon Microsoft's product. Given that: 1. 8-column tabs have been the standard for longer than most of us have been alive, let alone programming, and 2. even if a particular text editor supports some other value, there is no way to communicate this fact to anything else which might read the code, the logical conclusion is that using anything other than 8 columns lies somewhere between "silly" and "assuming the world revolves around you". From gagsl-py2 at yahoo.com.ar Sun Feb 7 00:59:00 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 02:59:00 -0300 Subject: C:\Python25\Lib\IDLELIB\idle.pyw won't start References: <4B6C1BED.6090807@bluewin.ch> <4B6D50CA.5070006@bluewin.ch> Message-ID: En Sat, 06 Feb 2010 08:21:46 -0300, Anthra Norell escribi?: > Gabriel, > Thanks for your hints. I take them up one by one: > > >>> import os > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named os > > C:\PYTHON25\LIB>dir os.* > > OS PY 25,211 08-03-06 9:27a OS.PY > OS PYC 24,430 06-05-08 6:45p OS.PYC > > Here we are! Somehow the name got upper-cased! There's a whole bunch > (131) of upper-cased names in the Lib I shall install the whole thing > from scratch. That should take care if it. Thank you very much. If you still have problems, try setting the PYTHONCASEOK environment variable. C:\temp>python25 -? ... Other environment variables: ... PYTHONCASEOK : ignore case in 'import' statements (Windows). > Frederic (Looking forward to Linux!) Or at least a more decent Windows version. ME was a complete failure - Win98 Second Edition, being older, was better. -- Gabriel Genellina From tjreedy at udel.edu Sun Feb 7 01:00:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 07 Feb 2010 01:00:30 -0500 Subject: Doctests and decorated methods don't get along In-Reply-To: <037dfaba$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> <037dfaba$0$1292$c3e8da3@news.astraweb.com> Message-ID: On 2/6/2010 7:51 PM, Steven D'Aprano wrote: > I have found an existing report for this issue: > > http://bugs.python.org/issue4037 > > The original poster's suggested fix was on the right track, but not > complete. I've added a patch which works according to my tests. > > Since this report is currently unassigned, is there a protocol for > raising its profile and having somebody check my patch for inclusion? > Should I just send an email to python-dev? At one time, I believe this would have been assigned to Tim Peters, but he seems not to be very active in Python development currently. Given that the patch is fairly trivial and the module possible orphaned, and that you do not regularly bug python-dev, I suspect it would be ok to enquire, once you have a complete patch (with testcase). The latter would let a committer/reviewer quickly check that it does what you claim. You might be asked to review some other issues in exchange. (Or the OP of this thread or the tracker item might help ;-). Terry Jan Reedy From alfps at start.no Sun Feb 7 01:26:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 07:26:00 +0100 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: * Nobody: > On Sat, 06 Feb 2010 21:31:52 +0100, Alf P. Steinbach wrote: > >> The size-8 tabs look really bad in an editor configured with tab size 4, >> as is common in Windows. I'm concluding that the CPython programmers >> configure their Visual Studio's to *nix convention. > > 8-column tabs aren't a "*nix convention"; that's been the norm since > the mechanical typewriter. > > Historically, software and hardware which knows what a "tab" could be > split into two categories: > > 1. Tab stops are fixed at 8-column intervals. > 2. Tab stops default to 8-column intervals but can be changed. > > Recently, a third category has appeared (tab stops default to something > other than 8 columns). I'm sorry, but you have your history wrong. Tab stops originated with mechanical typewriters, and then printers. They could be just about anything. Tab stops have never been universally 8 columns -- so unless by "recent" introduction of other sizes you mean 1958 or thereabouts, you're completely off track. > The most common example is Visual Studio. No > surprise there: Microsoft has a track record of introducing slight > incompatibilities into established standards. Just enough to inconvenience > anyone using competing products, but not so much that anyone operating > in a context where Microsoft isn't dominant has to abandon Microsoft's > product. > > Given that: > > 1. 8-column tabs have been the standard for longer than most of us > have been alive, let alone programming, and I'm sorry, that's incorrect, it's never been standard. > 2. even if a particular text editor supports some other value, there is no > way to communicate this fact to anything else which might read the code, If you add the word "portable" and remove the word "other" and replace "supports" with "is configured to use" then that's sort of technically correct. But I agree with the general sense. And I think most everyone does. A common convention would have been nice. But we don't have that. > the logical conclusion is that using anything other than 8 columns lies > somewhere between "silly" and "assuming the world revolves around you". ?the logical conclusion is that assuming 8 column tab stops lies somewhere between "silly" and "assuming the world revolves around you"? :-) In particular, consider Windows programming. Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Sun Feb 7 01:29:20 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 03:29:20 -0300 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> <4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: En Sat, 06 Feb 2010 21:24:33 -0300, News123 escribi?: > Gabriel Genellina wrote: >> En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: >> >>> I'm using an XMLRPC server under Windows. >>> What I wonder is how I could create a server, that can be killed with >>> CTRL-C >> >> Python 2.6 and up behaves exactly as you want. >> On previous versions you may use this: >> >> def server_bind(self): >> self.socket.settimeout(1.0) >> SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) >> > > Overloading server_bind() with your version solved my problem. Strange. With Python 2.6.4 I don't need to do that; I'd say the difference is in the OS or antivirus (some AV are known to break the TCP stack). -- Gabriel Genellina From aahz at pythoncraft.com Sun Feb 7 01:38:06 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Feb 2010 22:38:06 -0800 Subject: TABS in the CPython C source code References: Message-ID: In article , Neil Hodgson wrote: >Alf P. Steinbach: >> >> Anyways, I would suggest converting all those tabs to spaces, as e.g. >> the Boost library project does -- no tabs allowed. > > This would damage the usefulness of source control histories (svn >annotate) as all of the converted lines would show this recent cosmetic >change rather than the previous change which is likely to be a >substantive modification. BTW, in case anyone is confused, it's "svn blame" vs "cvs annotate". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Sun Feb 7 01:42:22 2010 From: aahz at pythoncraft.com (Aahz) Date: 6 Feb 2010 22:42:22 -0800 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: In article <0c535d15-967d-4909-a9bb-b5970818199f at l24g2000prh.googlegroups.com>, Xah Lee wrote: > >This is a short complaint on admin abuse on #python irc channel on >freenode.net. Let's see, you are complaining about getting banned from #python by CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's grounds for extending the IRC ban permanently. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From gagsl-py2 at yahoo.com.ar Sun Feb 7 02:14:11 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 04:14:11 -0300 Subject: xmlrpc slow in windows 7 if hostnames are used References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> <4B6E1444.9060001@sequans.com> Message-ID: En Sat, 06 Feb 2010 22:15:48 -0300, Jean-Michel Pichavant escribi?: > I'm puzzled. > Unless my english is failing me, everything would be solved using > hostnames if I follow you. Why don't you do that ? > I am no network/IP guru, but it sounds very weird to have requests > rejected when using IP addresses. Are you sure your host names are > resolved with the same IPM address you are using ? HTTP 1.1 requires a Host: header field; this way, multiple web servers may share the same IP address. So you can't identify a host by its IP alone; the host name is required. This was devised in order to save IPv4 addresses; LACNIC (the Latin America addresses register) does not assign addresses to ISP's based solely on web hosting anymore - they MUST share existing IPs. And I think a similar policy is used on other regions. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Sun Feb 7 02:52:18 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Sun, 07 Feb 2010 04:52:18 -0300 Subject: Dreaming of new generation IDE References: Message-ID: En Sat, 06 Feb 2010 22:34:14 -0300, bartc escribi?: > "Arnaud Delobelle" wrote in message > news:m28wb6ypfs.fsf at googlemail.com... >> "Gabriel Genellina" writes: >>> Note the *literal* part. If you (the programmer) is likely to know the >>> parameter value when writing the code, then the function is actually >>> two >>> separate functions. >> >> Thanks, I understand what Steve Holden meant now. > > I've just noticed that 'literal' part. But I think I still disagree. > > For a real-world example, it means instead of having a room with a > light-switch in it, if I *know* I want the light on or off, I should > have two rooms: one with the light permanently on, and one with it > permanently off, and just walk into the right one. I think this would be a better analogy: A multiple screwdriver like this one http://img.alibaba.com/photo/204461747/Multi_function_screwdriver_screwdriver.jpg You use it when you need flexibility, or you don't know in advance what kind of screws you're going to encounter; they're mostly for hobbysts. On the other hand, you have separate tools like this: http://i277.photobucket.com/albums/kk43/hightecelectronica/021-482.jpg You choose one of them when you know exactly what you want. If the stuff you're working on uses exclusively certain kind of screws, you don't need flexibility, and you can choose in advance. They're also professional's choice. -- Gabriel Genellina From anand.shashwat at gmail.com Sun Feb 7 04:03:07 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 14:33:07 +0530 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: Here is one simple solution : >>> intext = """Lorem [ipsum] dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna aliqua.""" >>> intext.replace('[', '{').replace(']', '}') 'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua.' *Some people, when confronted with a problem, think "I know, I?ll use regular expressions." Now they have two problems.* ? Jamie Zawinskiin comp.lang.emacs. On Sun, Feb 7, 2010 at 11:15 AM, Schif Schaf wrote: > On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: > > > > > I haven't used regexps in Python before, but what I did was (1) look in > the > > documentation, > > Hm. I checked in the repl, running `import re; help(re)` and the docs > on the `sub()` method didn't say anything about using back-refs in the > replacement string. Neat feature though. > > > (2) check that it worked. > > > > > > import re > > > > text = ( > > "Lorem [ipsum] dolor sit amet, consectetur", > > "adipisicing elit, sed do eiusmod tempor", > > "incididunt ut [labore] et [dolore] magna aliqua." > > ) > > > > withbracks = re.compile( r'\[(.+?)\]' ) > > for line in text: > > print( re.sub( withbracks, r'{\1}', line) ) > > > > > > Seems like there's magic happening here. There's the `withbracks` > regex that applies itself to `line`. But then when `re.sub()` does the > replacement operation, it appears to consult the `withbracks` regex on > the most recent match it just had. > > Thanks. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From macosx at rocteur.cc Sun Feb 7 04:52:10 2010 From: macosx at rocteur.cc (@ Rocteur CC) Date: Sun, 7 Feb 2010 10:52:10 +0100 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: <6C6462AB-4665-40C9-B652-076FA574B872@rocteur.cc> On 07 Feb 2010, at 10:03, Shashwat Anand wrote: > Here is one simple solution : > >>> intext = """Lorem [ipsum] dolor sit amet, consectetur > adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et > [dolore] magna aliqua.""" > > >>> intext.replace('[', '{').replace(']', '}') > 'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do > eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua.' > > Some people, when confronted with a problem, think "I know, I?ll use > regular expressions." Now they have two problems. ? Jamie Zawinski > in comp.lang.emacs. That is because regular expressions are what we learned in programming the shell from sed to awk and ksh and zsh and of course Perl and we've read the two books by Jeffrey and much much more!!! How do we rethink and relearn how we do things and should we ? What is the solution ? Jerry -------------- next part -------------- An HTML attachment was scrubbed... URL: From Martin.Drautzburg at web.de Sun Feb 7 04:54:16 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sun, 07 Feb 2010 10:54:16 +0100 Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> Message-ID: <3360023.OTX69idHFh@beaureve.gmx.net> Christian Heimes wrote: > If you *really* need to overwrite __iter__ on your instance rather > than defining it on your class, you need to proxy the method call: > > class MyObject(object): > def __iter__(self): > return self.myiter() > > obj = MyObject() > obj.myiter = myiter > > That should do the trick. Thanks a lot, that works. From dickinsm at gmail.com Sun Feb 7 04:55:53 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 7 Feb 2010 01:55:53 -0800 (PST) Subject: max / min / smallest float value on Python 2.5 References: Message-ID: <6361d161-2367-44e0-a1aa-1938cb5e0bfc@21g2000yqj.googlegroups.com> On Feb 7, 12:52?am, duncan smith wrote: > import platform > if platform.architecture()[0].startswith('64'): > ? ? ?TINY = 2.2250738585072014e-308 > else: > ? ? ?TINY = 1.1754943508222875e-38 As Christian said, whether you're using 32-bit or 64-bit shouldn't make a difference here. Just use the first TINY value you give. > I'm not 100% sure how reliable this will be across platforms. ?Any ideas > about the cleanest, reliable way of uncovering this type of information? In practice, it's safe to assume that your 2.225....e-308 value is reliable across platforms. That value is the one that's appropriate for the IEEE 754 binary64 format, and it's difficult these days to find CPython running on a machine that uses any other format for C doubles (and hence for Python floats). The smallest positive *normal* number representable in IEEE 754 binary64 is exactly 2**-1022 (or approximately 2.2250738585072014e-308). The smallest positive *subnormal* number representable is exactly 2**-1074, or approximately '4.9406564584124654e-324'. (Subnormals have fewer bits of precision than normal numbers; it's the presence of subnormals that allows for 'gradual underflow'.) Some machines can/will treat subnormal numbers specially for speed reasons, either flushing a subnormal result of a floating-point operation to 0, or replacing subnormal inputs to an floating-point operation with 0, or both. So for maximal portability, and to avoid numerical problems, it's best to avoid the subnormal region. > The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. This is a bit surprising. What's the precise form of the error you get? Do you still get the same error if you replace your TINY value by something fractionally larger? (E.g., 2.23e-308.) -- Mark From rychphd at gmail.com Sun Feb 7 05:06:52 2010 From: rychphd at gmail.com (rych) Date: Sun, 7 Feb 2010 02:06:52 -0800 (PST) Subject: ctypes Structure serialization Message-ID: <615b1271-a9b0-4558-8e45-e4370698d96a@a16g2000pre.googlegroups.com> I'm not quite familiar with python serialization but the picle module, at least, doesn't seem to be able to serialize a ctypes Structure with array-fields. Even if it was, the ASCII file produced is not in a human-friendly format. Could someone please suggest a method of saving and loading the fields in ctypes' Structure derived class to a json or better yet, to something like INFO http://www.boost.org/doc/libs/1_41_0/doc/html/boost_propertytree/parsers.html#boost_propertytree.parsers.info_parser For example, I have an object of >>> class MyStruct(Structure): ... _fields_ = [("a", c_int), ... ("b", c_float), ... ("point_array", c_float * 4)] I'd like the corresponding file to look like a 1 b 1.0 point array 1.1 1.2 1.3 1.4 Thanks From Martin.Drautzburg at web.de Sun Feb 7 05:13:41 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sun, 07 Feb 2010 11:13:41 +0100 Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> Message-ID: <63288869.8iZ5tTOMcE@beaureve.gmx.net> Steven D'Aprano wrote: > If you want iterator operations "similar to itertools", why does this > mean you need to replace anything? Just create your own iterators. > > Or use pre-processing and post-processing to get what you want. > > Can you show an example of what you would like to happen? Steven, my classes repesent musical objects. The fundamental paradigm I want to apply is that of a Sequence, i.e. the most abstract aspect of music is that "things" occur in a certain order. Then I have a TimedSequence class, which is a Sequences whose elements have a "time" attribute. I now want to be able to append such Sequences by writing s1 = TimedSequence (time=1,'a') # one-element Sequence s2 = TimedSequence (time=2,'b') y = s1*2 + s2 Naively appending those sequences would give me Time=1,'a' Time=1,'a' Time=2,'b' but this is not what I want. Time needs to progress if I append a sequence to another. So what I really want is something like Time=1,'a' Time=2,'a' Time=3,'b' This implies that time is shifted to the next integer, but this is not always the case. I need to know about some kind of "alignment". In music this translates to "let a sequence start at the beginning of a bar", or half bar or quarter note or whatever. So I want to write y = s1*2 + s2(align=10) which should iterate as Time=1,'a' Time=2,'a' Time=10,'b' I have no difficulty passing "align" to the object (using __call__) and use it while I furnish my own __iter__() method. However I don't quite see how I can do this with bare itertools, though I may be wrong here. Bare in mind that it is not only about somehow getting the job done. The beauty of the resulting syntax is also important. From news123 at free.fr Sun Feb 7 05:33:55 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:33:55 +0100 Subject: xmlrpc slow in windows 7 if hostnames are used In-Reply-To: References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> Message-ID: <4b6e9714$0$29806$426a74cc@news.free.fr> Hi JM, Jean-Michel Pichavant wrote: > News123 wrote: >> Jean-Michel Pichavant wrote: >> >> >> Well This was exactly my question. >> for virtual web servers I cannot just use the IP-address. >> some XMLRPC servers do need the histname within the HTTP-POST request. >> >> > a valid IP address would make it What I meant is: Window 7 seems to be waaaayyyy slower if an xmlrpc client uses a host name ('localhost') than an IP-address ('127.0.0.1). the speed difference is between 1 request per second or 10-20 requests per second. >> if I just replaced the hostname with the IP address, then certain servers >> would not be accessable. many computers host multiple web servers under the same IP-address. ( see for example http://httpd.apache.org/docs/1.3/vhosts/name-based.html ) So I cannot just replace a host name with an IP-address and expect to receive the correct data / correct xmlrpc server. >> I had to use the IP-address for connecteing > why not using the host names? I did not want to use the hostname due to the slowdown of "locahost vs. 127.0.0.1" issue on my host. You are right, that I did not verify whether this issue exists also with external servers and I should verify this first. >> , but to pass the hostname in >> the HTTP-POST request. >> >> I wondered how to convince puthon's SimpleXMLRPCServer (or any other >> standard python xmlrpc server), such, that I can obtain above mentioned >> goal. >> >> > I'm puzzled. > Unless my english is failing me, everything would be solved using > hostnames if I follow you. Why don't you do that ? > I am no network/IP guru, but it sounds very weird to have requests > rejected when using IP addresses. Are you sure your host names are > resolved with the same IPM address you are using ? The request would not be rejected, but apache can (if being configured for name based virtual hosts) look at the hostname within the TCP/IP payload (the entire url (including the host name) is normally also in the GET / POST request ) and decide to deliver different data (or to return HTTP errors) depending on the hostname in the payload. I hope this clarifies. Your answer gave me some thoughts though: I still have to check whether the issue really exists with external requests other than localhost. Also I should probably try to attack the root cause ( probably with help of ethereal or a similiar tool) instead of trying to work around it. I could just change the windows /etc/hosts equivalent and tell localhost to have only an IPV4 address (perhaps this increases the performance) On the other hand: Some people use name based virtual servers to provide special web services by providing a 'fake-host name' in the http request. it might be, that the fake host name doesn't even have a DNS entry. ( Though security by obscurity is a questionable practice ) so for some weird use cases it could be worth knowing how to connect to one IP addres and to pass a different host name in the HTTP payload when using an xmlrpcclient bye N From news123 at free.fr Sun Feb 7 05:38:39 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:38:39 +0100 Subject: sshd in python for windows 7 In-Reply-To: References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <4B6E982F.4020404@free.fr> Hi Jerry, Jerry Hill wrote: > On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: >> Hi, >> >> I wondered which modules would be best to perform following task: >> >> A user uses a standard ssh (e.g. putty or openssh) client and performs >> an ssh to a windows host >> >> The windows host would run a python script acting as ssh server. > > The Twisted library has an sshd implementation, called conch. Here an > article with a simple python sshd built with twisted: > http://www.ibm.com/developerworks/linux/library/l-twist4.html Thanks. I'll check whether twisted conch runs also under windows. Yesterday I made the probably too fast conclusion, that twisted conch exists only for liux as I could only find a twisted-conch tarball and not a windows installer. But probably twisted-conch is already part of the twisted installer for windows. I'll check it. From news123 at free.fr Sun Feb 7 05:39:06 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:39:06 +0100 Subject: sshd in python for windows 7 In-Reply-To: References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <4b6e984a$0$29806$426a74cc@news.free.fr> Hi Jerry, Jerry Hill wrote: > On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: >> Hi, >> >> I wondered which modules would be best to perform following task: >> >> A user uses a standard ssh (e.g. putty or openssh) client and performs >> an ssh to a windows host >> >> The windows host would run a python script acting as ssh server. > > The Twisted library has an sshd implementation, called conch. Here an > article with a simple python sshd built with twisted: > http://www.ibm.com/developerworks/linux/library/l-twist4.html Thanks. I'll check whether twisted conch runs also under windows. Yesterday I made the probably too fast conclusion, that twisted conch exists only for liux as I could only find a twisted-conch tarball and not a windows installer. But probably twisted-conch is already part of the twisted installer for windows. I'll check it. From news123 at free.fr Sun Feb 7 05:42:12 2010 From: news123 at free.fr (News123) Date: Sun, 07 Feb 2010 11:42:12 +0100 Subject: sshd in python for windows 7 In-Reply-To: References: <4b6e0455$0$20650$426a34cc@news.free.fr> Message-ID: <4b6e9904$0$29806$426a74cc@news.free.fr> Hi Jerry, Jerry Hill wrote: > On Sat, Feb 6, 2010 at 7:07 PM, News123 wrote: >> Hi, >> >> I wondered which modules would be best to perform following task: >> >> A user uses a standard ssh (e.g. putty or openssh) client and performs >> an ssh to a windows host >> >> The windows host would run a python script acting as ssh server. > > The Twisted library has an sshd implementation, called conch. Here an > article with a simple python sshd built with twisted: > http://www.ibm.com/developerworks/linux/library/l-twist4.html THanks a look at it in moe detail. Yesterday I made the probably wrong assumption, that twisted-conch exists only for linux as I just found a twisted-conch tarball. Probably however twisted-conch is already part of the twisted windows installer package I'll check this. N From peloko45 at gmail.com Sun Feb 7 06:22:59 2010 From: peloko45 at gmail.com (Joan Miller) Date: Sun, 7 Feb 2010 03:22:59 -0800 (PST) Subject: Simulating logging.exception with another traceback Message-ID: <0c13d3f7-addf-4972-91c3-6f41fadfb2b5@u26g2000yqm.googlegroups.com> I would want to get the output from `logging.exception` but with traceback from the caller function (I've already all that information). This would be the error with logging.exception: -------------------- ERROR: PipeError('/bin/ls -l | ', 'no command after of pipe') Traceback (most recent call last): File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line 160, in __call__ raise PipeError(command, 'no command after of pipe') PipeError: ('/bin/ls -l | ', 'no command after of pipe') -------------------- And I've trying it with: -------------------- message = "File \"{0}\", line {1}, in {2}\n\n {3}".format( file, line, function, caller) logging.error(message) ERROR: File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line 163, in __call__ return self.throw(PipeError, command, 'no command after of pipe') -------------------- Could be used `logging.LogRecord` [1] to get it? How? [1] http://docs.python.org/library/logging.html#logging.LogRecord From chyavana at gmail.com Sun Feb 7 06:32:14 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Sun, 07 Feb 2010 19:32:14 +0800 Subject: Dynamic variable names Message-ID: Dear Folks, I have read that one should use a dictionary in python to accommodate dynamic variable names. Yet, I am puzzled how to achieve that in my case. Here is what I want to do: 1. The user inputs a number of six-digit hex numbers as a comma-separated list. These numbers represent colours, but the number of colours is not known beforehand. 2. Using these colours in pairs, I am generating image files whose names must be unique. I could use the respective hex numbers for this, but would like to explore generating filenames like colour_1-colour_2.jpg Because I do not know how many colours there would be in advance, I need to generate the colour_n names on the fly. So, my two questions are: 1. How do I do this properly in python? 2. If there is a better scheme than what I have outlined, can someone please point me to a Web link? Thank you. Chandra From steve at holdenweb.com Sun Feb 7 07:28:27 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:28:27 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: Aahz wrote: > In article <0c535d15-967d-4909-a9bb-b5970818199f at l24g2000prh.googlegroups.com>, > Xah Lee wrote: >> This is a short complaint on admin abuse on #python irc channel on >> freenode.net. > > Let's see, you are complaining about getting banned from #python by > CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's > grounds for extending the IRC ban permanently. It certainly doesn't inspire any confidence that Xah's next trip to #python is likely to last much longer than the last. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:32:14 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:32:14 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: bartc wrote: > "Arnaud Delobelle" wrote in message > news:m28wb6ypfs.fsf at googlemail.com... >> "Gabriel Genellina" writes: >> >>> En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribi?: >>>> "Steve Holden" wrote in message >>>> news:mailman.1998.1265399766.28905.python-list at python.org... >>>>> Arnaud Delobelle wrote: >>>>>> Robert Kern writes: >>>>>> >>>>>>> I prefer Guido's formulation (which, naturally, I can't find a >>>>>>> direct >>>>>>> quote for right now): if you expect that a boolean argument is only >>>>>>> going to take *literal* True or False, then it should be split into >>> ^^^^^^^^^^^^^^^^^^^^^^^ >>>>>>> two functions. >>>>>> >>>>>> So rather than three boolean arguments, would you have eight >>>>>> functions? >>>>>> >>>>> If there's genuinely a need for that functionality, yes. >>>> >>>> So you want a function such as drawtext(s, bold=true, italic=false, >>>> underline=true) to be split into: >>>> >>>> drawtext(s) >>>> drawtextb(s) >>>> drawtexti(s) >>>> drawtextu(s) >>>> drawtextbi(s) >>>> drawtextbu(s) >>>> drawtextiu(s) >>>> drawtextbiu(s) >>> >>> Note the *literal* part. If you (the programmer) is likely to know the >>> parameter value when writing the code, then the function is actually two >>> separate functions. >> >> Thanks, I understand what Steve Holden meant now. > > I've just noticed that 'literal' part. But I think I still disagree. > > For a real-world example, it means instead of having a room with a > light-switch in it, if I *know* I want the light on or off, I should > have two rooms: one with the light permanently on, and one with it > permanently off, and just walk into the right one. > Congratulations. That has to be the most bogus analogy I've seen on c.l.py this year. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:39:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:39:24 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: Nobody wrote: > On Sat, 06 Feb 2010 21:31:52 +0100, Alf P. Steinbach wrote: > >> The size-8 tabs look really bad in an editor configured with tab size 4, >> as is common in Windows. I'm concluding that the CPython programmers >> configure their Visual Studio's to *nix convention. > > 8-column tabs aren't a "*nix convention"; that's been the norm since > the mechanical typewriter. > Clearly written by someone who has never *used* a mechanical typewriter. The original mechanisms had "tab set" and "tab clear" keys, so you had variable tabbing according to the needs of the particular document you were working on. Look under "T" in http://www.mytypewriter.com/explorelearn/glossary.html if you aren't old enough to have used one. > Historically, software and hardware which knows what a "tab" could be > split into two categories: > > 1. Tab stops are fixed at 8-column intervals. > 2. Tab stops default to 8-column intervals but can be changed. > > Recently, a third category has appeared (tab stops default to something > other than 8 columns). The most common example is Visual Studio. No > surprise there: Microsoft has a track record of introducing slight > incompatibilities into established standards. Just enough to inconvenience > anyone using competing products, but not so much that anyone operating > in a context where Microsoft isn't dominant has to abandon Microsoft's > product. > Consider instead that perhaps this one time Microsoft did it for the convenience of the user (there has to be some reason why it's such a wealthy company). > Given that: > > 1. 8-column tabs have been the standard for longer than most of us > have been alive, let alone programming, and > 2. even if a particular text editor supports some other value, there is no > way to communicate this fact to anything else which might read the code, > > the logical conclusion is that using anything other than 8 columns lies > somewhere between "silly" and "assuming the world revolves around you". > Which is what you appear to be doing with your fantasy about mechanical typewriters. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:46:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:46:52 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: <4B6EB63C.1060208@holdenweb.com> Dennis Lee Bieber wrote: > On Sun, 07 Feb 2010 05:49:28 +0000, Nobody > declaimed the following in gmane.comp.python.general: > > >> 8-column tabs aren't a "*nix convention"; that's been the norm since >> the mechanical typewriter. >> > Really? None of the various Royal, Remington, and Olivetti (sp?) > typewriters I learned on had any knowledge of default tab stops. All had > a row of sliding "pins" on the carriage, which were slid back and forth > by the and button (which required one to first > position the carriage at the position at which the stop was to be > placed). The key itself functioned by first pushing a lever into > the area covered by the stop-row (after the current position stop, if > one existed), then releasing the carriage to slide until the next stop > -- uhm -- stopped the motion by impacting the lever; releasing the > key would then re-engage the normal carriage motion control, and > withdraw the lever. > > 8-space tab stops were, I believe, the default for various computer > terminals, DECwriter printers, and maybe teletype units (in which there > was no moving carriage on which a physical stop could be placed). Not > sure how an 029 keypunch machine would behave -- either punching the > code the a tab character, or skipping to the next field defined on a > drum-card. > When I started my computing career the main input medium at the installation I worked was paper tape, and the Flexowriter (pretty much a mechanical typewriter mechanism with a tape reader and punch attached) was the data preparation device (though teletypes were used at other installations). So it had adjustable tab settings. The 029 punch (and the 026 before it) used a punch card mounte on a drum to set the tab stops, which were therefore completely variable - one would use a different tab card for Fortran and PL/1, for example. So a tab was purely a spacing operation, no chads were punched from the card, and indeed I was never aware of an EBCDIC "tab" character code (which is by no means to say that there isn't one - Wikipedia says "The EBCDIC code for HT is 5"). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:46:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:46:52 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: <4B6EB63C.1060208@holdenweb.com> Dennis Lee Bieber wrote: > On Sun, 07 Feb 2010 05:49:28 +0000, Nobody > declaimed the following in gmane.comp.python.general: > > >> 8-column tabs aren't a "*nix convention"; that's been the norm since >> the mechanical typewriter. >> > Really? None of the various Royal, Remington, and Olivetti (sp?) > typewriters I learned on had any knowledge of default tab stops. All had > a row of sliding "pins" on the carriage, which were slid back and forth > by the and button (which required one to first > position the carriage at the position at which the stop was to be > placed). The key itself functioned by first pushing a lever into > the area covered by the stop-row (after the current position stop, if > one existed), then releasing the carriage to slide until the next stop > -- uhm -- stopped the motion by impacting the lever; releasing the > key would then re-engage the normal carriage motion control, and > withdraw the lever. > > 8-space tab stops were, I believe, the default for various computer > terminals, DECwriter printers, and maybe teletype units (in which there > was no moving carriage on which a physical stop could be placed). Not > sure how an 029 keypunch machine would behave -- either punching the > code the a tab character, or skipping to the next field defined on a > drum-card. > When I started my computing career the main input medium at the installation I worked was paper tape, and the Flexowriter (pretty much a mechanical typewriter mechanism with a tape reader and punch attached) was the data preparation device (though teletypes were used at other installations). So it had adjustable tab settings. The 029 punch (and the 026 before it) used a punch card mounte on a drum to set the tab stops, which were therefore completely variable - one would use a different tab card for Fortran and PL/1, for example. So a tab was purely a spacing operation, no chads were punched from the card, and indeed I was never aware of an EBCDIC "tab" character code (which is by no means to say that there isn't one - Wikipedia says "The EBCDIC code for HT is 5"). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 07:49:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 07:49:13 -0500 Subject: new.instancemethod __iter__ In-Reply-To: <63288869.8iZ5tTOMcE@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> Message-ID: Martin Drautzburg wrote: > Steven D'Aprano wrote: > >> If you want iterator operations "similar to itertools", why does this >> mean you need to replace anything? Just create your own iterators. >> >> Or use pre-processing and post-processing to get what you want. >> >> Can you show an example of what you would like to happen? > > Steven, > > my classes repesent musical objects. The fundamental paradigm I want to > apply is that of a Sequence, i.e. the most abstract aspect of music is > that "things" occur in a certain order. > > Then I have a TimedSequence class, which is a Sequences whose elements > have a "time" attribute. I now want to be able to append such Sequences > by writing > > s1 = TimedSequence (time=1,'a') # one-element Sequence > s2 = TimedSequence (time=2,'b') > > y = s1*2 + s2 > > Naively appending those sequences would give me > Time=1,'a' > Time=1,'a' > Time=2,'b' > > but this is not what I want. Time needs to progress if I append a > sequence to another. So what I really want is something like > > Time=1,'a' > Time=2,'a' > Time=3,'b' > > This implies that time is shifted to the next integer, but this is not > always the case. I need to know about some kind of "alignment". In > music this translates to "let a sequence start at the beginning of a > bar", or half bar or quarter note or whatever. > > So I want to write > > y = s1*2 + s2(align=10) > > which should iterate as > > Time=1,'a' > Time=2,'a' > Time=10,'b' > > I have no difficulty passing "align" to the object (using __call__) and > use it while I furnish my own __iter__() method. However I don't quite > see how I can do this with bare itertools, though I may be wrong here. > > Bare in mind that it is not only about somehow getting the job done. The > beauty of the resulting syntax is also important. > In that case why not just assume that the timing of a sequence is relative to the current time unless the "align" argument is given? You might also need an event of zero duration to set the start time for a sequence. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From fetchinson at googlemail.com Sun Feb 7 07:57:13 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 13:57:13 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: >>> This is a short complaint on admin abuse on #python irc channel on >>> freenode.net. >> >> Let's see, you are complaining about getting banned from #python by >> CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's >> grounds for extending the IRC ban permanently. > > It certainly doesn't inspire any confidence that Xah's next trip to > #python is likely to last much longer than the last. Some humanity, please! If you look at the web page of the guy it really strikes me as a poor bastard who deserves more pity than bashing. IRC, newsgroups, email, web page, etc, these are the only things that this guy is doing, if you take these things away from him I don't know what will be left for him. Yes, he is annoying, yes, he is trolling, but if this prevents him from jumping under the bus, then I'd say let him do it. How many serial trolls are there on c.l.p? Not many. The average troll should of course be kicked out from everywhere, but guys like Xah are really rare and on humanitarian grounds I think should be allowed to do their things. If you really think about it the damage is not that great. In medieval times 99% of crazy people (using a loose definition of crazy) were either executed or tortured and executed, however, the one lonely village clown or court clown was allowed to be crazy, he even had a decent income from the king. I'm not suggesting a stipend for Xah from the PSF :) but having a single c.l.p clown is tolerable if it makes him happy. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at holdenweb.com Sun Feb 7 08:07:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:07:30 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: hzhuo1 at gmail.com wrote: >> So it seems we both misunderstood the problem. >> >> I didn't read the top level article until now, and reading it, I can't make >> sense of it. >> > > Seems that you should read the whole thing before making a post, or > else you cannot know what we are talking about. > Steven doesn't misunderstand me. We are talking about what I need, and > he tries to help. > > > >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( >> >> [snip] >> > > This is a hash collision problem. Nobody has proved that SHA-256 is > collision free, even not in the random oracle model, because people > always suppose that a random oracle exists, and make hash function its > substitution. That means it may be broken someday. And any provable > security based on random oracle model is not secure. > It's very easy to prove that no hash function is collision-free, since the domain (all possible inputs) is much larger than the range (all possible outputs). Hence there must be many inputs that map to the same output. A *good* hash function is unpredictable enough to make finding two colliding strings impractical - and even the best hash functions that cryptographers could devise at the time have been broken. We should remember that "broken" to a cryptographer means something rather different than it does in common usage, so a broken scheme need not necessarily be dropped immediately - one would just stop using it in new systems. > >>> I'm suggesting that, in general, there's no way to tell in advance which >>> regexes will be easy and which will be hard, and even when they are easy, >>> the enumeration will often be infinite. > > It is hard to tell in advance. However, we can add some timing limit > or counting limit, to make it an algorithm, which can halt. For > example, whenever the program outputs more than 1000000 expressions > that match the input regex, we can halt because that exceeds our > limit. But surely this is not efficient because of the post-decision. > >> Essentially, any regexp that includes '+' or '*' (directly or via e.g. notation >> that denotes "digit sequence") yields an infinite number of strings. > > Infinity is really relative, not absolute. It is relative to the > computing speed. For example, the regex '^[0|1]{2048}$' is rather > simple and doesn't contain '+' or '$', but trying to output all > expressions that match it has a complexity of 2^2048. If we can do > that, then we can break RSA-2048. > We must face the reality . > I have always understood that there's a pretty real distinction between "finite" and "infinite". Are you telling me I am wrong, or are you merely saying that some finite cases might just as well be infinite for practical purposes? And I really don't see how simple enumeration of range(2^2048) breaks RSA-2048, since that problem requires you to find two factors which, when multiplied together, give that specific value. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python.list at tim.thechases.com Sun Feb 7 08:11:10 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 07:11:10 -0600 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: <4B6EBBEE.2070402@tim.thechases.com> Schif Schaf wrote: > On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: >> I haven't used regexps in Python before, but what I did was (1) look in the >> documentation, [snip] >> >> import re >> >> text = ( >> "Lorem [ipsum] dolor sit amet, consectetur", >> "adipisicing elit, sed do eiusmod tempor", >> "incididunt ut [labore] et [dolore] magna aliqua." >> ) >> >> withbracks = re.compile( r'\[(.+?)\]' ) >> for line in text: >> print( re.sub( withbracks, r'{\1}', line) ) >> > > Seems like there's magic happening here. There's the `withbracks` > regex that applies itself to `line`. But then when `re.sub()` does the > replacement operation, it appears to consult the `withbracks` regex on > the most recent match it just had. I suspect Alf's rustiness with regexps caused him to miss the simpler rendition of print withbacks.sub(r'{\1}', line) And to answer those who are reaching for other non-regex (whether string translations or .replace(), or pyparsing) solutions, it depends on what you want to happen in pathological cases like s = """Dangling closing] with properly [[nested]] and complex [properly [nested] text] and [improperly [nested] text and with some text [straddling lines] and with dangling opening [brackets """ where you'll begin to see the differences. -tkc From anand.shashwat at gmail.com Sun Feb 7 08:15:11 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 7 Feb 2010 18:45:11 +0530 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: LOL pow(funny, sys.maxint) On Sun, Feb 7, 2010 at 6:27 PM, Daniel Fetchinson wrote: > >>> This is a short complaint on admin abuse on #python irc channel on > >>> freenode.net. > >> > >> Let's see, you are complaining about getting banned from #python by > >> CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's > >> grounds for extending the IRC ban permanently. > > > > It certainly doesn't inspire any confidence that Xah's next trip to > > #python is likely to last much longer than the last. > > Some humanity, please! If you look at the web page of the guy it > really strikes me as a poor bastard who deserves more pity than > bashing. IRC, newsgroups, email, web page, etc, these are the only > things that this guy is doing, if you take these things away from him > I don't know what will be left for him. Yes, he is annoying, yes, he > is trolling, but if this prevents him from jumping under the bus, then > I'd say let him do it. How many serial trolls are there on c.l.p? Not > many. The average troll should of course be kicked out from > everywhere, but guys like Xah are really rare and on humanitarian > grounds I think should be allowed to do their things. If you really > think about it the damage is not that great. > > In medieval times 99% of crazy people (using a loose definition of > crazy) were either executed or tortured and executed, however, the one > lonely village clown or court clown was allowed to be crazy, he even > had a decent income from the king. I'm not suggesting a stipend for > Xah from the PSF :) but having a single c.l.p clown is tolerable if it > makes him happy. > > Cheers, > Daniel > > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Sun Feb 7 08:19:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:19:51 -0500 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: <4B6EBDF7.1010907@holdenweb.com> duncan smith wrote: > Christian Heimes wrote: >> duncan smith wrote: >>> Hello, >>> I'm trying to find a clean and reliable way of uncovering >>> information about 'extremal' values for floats on versions of Python >>> earlier than 2.6 (just 2.5 actually). I don't want to add a >>> dependence on 3rd party modules just for this purpose. e.g. For the >>> smallest positive float I'm using, >>> >>> >>> import platform >>> if platform.architecture()[0].startswith('64'): >>> TINY = 2.2250738585072014e-308 >>> else: >>> TINY = 1.1754943508222875e-38 >>> >>> >>> where I've extracted the values for TINY from numpy in IDLE, >>> >>> >>> >>> float(numpy.finfo(numpy.float32).tiny) >>> 1.1754943508222875e-38 >>> >>> float(numpy.finfo(numpy.float64).tiny) >>> 2.2250738585072014e-308 >> >> You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's >> float type is build upon C's double precision float type on both 32 and >> 64 bit builds. The simple precision 32bit float type isn't used. The >> DBL_MIN and DBL_MAX values are equal on all platforms that have full >> IEEE 754 float point support. The radix may be different, though. >> >> Christian > > OK, this is the sort of confusion I suspected. I wasn't thinking > straight. The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. Thanks. > Whether this is relevant or not I can't say, but you must be careful to note that the smallest representable floating-point value (i.e. the smallest number distinguishable from zero) is not the same as the smallest difference between two numbers of a given magnitude. Consider a decimal floating-point system with a two-digit exponent and a four-digit mantissa, and for convenience ignore negative mantissas. The range of representable non-zero values runs from 1E-99 to 9999E99. But adding 1E-99 to (say) 1 will just give you 1 because the system has insufficient precision to represent the true result. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:19:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:19:51 -0500 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: References: Message-ID: <4B6EBDF7.1010907@holdenweb.com> duncan smith wrote: > Christian Heimes wrote: >> duncan smith wrote: >>> Hello, >>> I'm trying to find a clean and reliable way of uncovering >>> information about 'extremal' values for floats on versions of Python >>> earlier than 2.6 (just 2.5 actually). I don't want to add a >>> dependence on 3rd party modules just for this purpose. e.g. For the >>> smallest positive float I'm using, >>> >>> >>> import platform >>> if platform.architecture()[0].startswith('64'): >>> TINY = 2.2250738585072014e-308 >>> else: >>> TINY = 1.1754943508222875e-38 >>> >>> >>> where I've extracted the values for TINY from numpy in IDLE, >>> >>> >>> >>> float(numpy.finfo(numpy.float32).tiny) >>> 1.1754943508222875e-38 >>> >>> float(numpy.finfo(numpy.float64).tiny) >>> 2.2250738585072014e-308 >> >> You are confusing a 32 / 64bit build with 32 / 64bit floats. Python's >> float type is build upon C's double precision float type on both 32 and >> 64 bit builds. The simple precision 32bit float type isn't used. The >> DBL_MIN and DBL_MAX values are equal on all platforms that have full >> IEEE 754 float point support. The radix may be different, though. >> >> Christian > > OK, this is the sort of confusion I suspected. I wasn't thinking > straight. The precise issue is that I'm supplying a default value of > 2.2250738585072014e-308 for a parameter (finishing temperature for a > simulated annealing algorithm) in an application. I develop on > Ubuntu64, but (I am told) it's too small a value when run on a Win32 > server. I assume it's being interpreted as zero and raising an > exception. Thanks. > Whether this is relevant or not I can't say, but you must be careful to note that the smallest representable floating-point value (i.e. the smallest number distinguishable from zero) is not the same as the smallest difference between two numbers of a given magnitude. Consider a decimal floating-point system with a two-digit exponent and a four-digit mantissa, and for convenience ignore negative mantissas. The range of representable non-zero values runs from 1E-99 to 9999E99. But adding 1E-99 to (say) 1 will just give you 1 because the system has insufficient precision to represent the true result. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:25:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:25:28 -0500 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <6C6462AB-4665-40C9-B652-076FA574B872@rocteur.cc> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <6C6462AB-4665-40C9-B652-076FA574B872@rocteur.cc> Message-ID: @ Rocteur CC wrote: > > On 07 Feb 2010, at 10:03, Shashwat Anand wrote: > >> Here is one simple solution : >> >>> intext = """Lorem [ipsum] dolor sit amet, consectetur adipisicing >> elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna >> aliqua.""" >> >> >>> intext.replace('[', '{').replace(']', >> '}') >> 'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do >> eiusmod tempor incididunt ut {labore} et {dolore} magna aliqua.' >> >> /Some people, when confronted with a problem, think "I know, I?ll use >> regular expressions." Now they have two problems./ ? Jamie Zawinski >> in comp.lang.emacs. > > That is because regular expressions are what we learned in programming > the shell from sed to awk and ksh and zsh and of course Perl and we've > read the two books by Jeffrey and much much more!!! > > How do we rethink and relearn how we do things and should we ? > > What is the solution ? > A rigorous focus on programming simplicity. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From fetchinson at googlemail.com Sun Feb 7 08:31:08 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 14:31:08 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: > LOL assert funny > 1 > pow(funny, sys.maxint) >> >>> This is a short complaint on admin abuse on #python irc channel on >> >>> freenode.net. >> >> >> >> Let's see, you are complaining about getting banned from #python by >> >> CROSS-POSTING between c.l.py and comp.lang.lisp. From my POV, that's >> >> grounds for extending the IRC ban permanently. >> > >> > It certainly doesn't inspire any confidence that Xah's next trip to >> > #python is likely to last much longer than the last. >> >> Some humanity, please! If you look at the web page of the guy it >> really strikes me as a poor bastard who deserves more pity than >> bashing. IRC, newsgroups, email, web page, etc, these are the only >> things that this guy is doing, if you take these things away from him >> I don't know what will be left for him. Yes, he is annoying, yes, he >> is trolling, but if this prevents him from jumping under the bus, then >> I'd say let him do it. How many serial trolls are there on c.l.p? Not >> many. The average troll should of course be kicked out from >> everywhere, but guys like Xah are really rare and on humanitarian >> grounds I think should be allowed to do their things. If you really >> think about it the damage is not that great. >> >> In medieval times 99% of crazy people (using a loose definition of >> crazy) were either executed or tortured and executed, however, the one >> lonely village clown or court clown was allowed to be crazy, he even >> had a decent income from the king. I'm not suggesting a stipend for >> Xah from the PSF :) but having a single c.l.p clown is tolerable if it >> makes him happy. >> >> Cheers, >> Daniel >> >> >> >> -- >> Psss, psss, put it down! - http://www.cafepress.com/putitdown >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve at holdenweb.com Sun Feb 7 08:31:24 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:31:24 -0500 Subject: Dynamic variable names In-Reply-To: References: Message-ID: R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I have read that one should use a dictionary in python to accommodate > dynamic variable names. Yet, I am puzzled how to achieve that in my > case. Here is what I want to do: > > 1. The user inputs a number of six-digit hex numbers as a > comma-separated list. These numbers represent colours, but the number of > colours is not known beforehand. > > 2. Using these colours in pairs, I am generating image files whose names > must be unique. I could use the respective hex numbers for this, but > would like to explore generating filenames like > > colour_1-colour_2.jpg > > Because I do not know how many colours there would be in advance, I need > to generate the colour_n names on the fly. > > So, my two questions are: > > 1. How do I do this properly in python? > > 2. If there is a better scheme than what I have outlined, can someone > please point me to a Web link? > Here's one way, though not necessarily the best: >>> import itertools >>> ctr = itertools.count(1) >>> for i in range(5): ... print "colour_%03d-colour%03d.jpg" % (ctr.next(), ctr.next()) ... colour_001-colour002.jpg colour_003-colour004.jpg colour_005-colour006.jpg colour_007-colour008.jpg colour_009-colour010.jpg >>> I zero-filled the names so they sort in numerical order. If this isn't a requirement then simply change the format string to "colour_%d-colour%d.jpg" regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From as at sci.fi Sun Feb 7 08:33:43 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 07 Feb 2010 15:33:43 +0200 Subject: Help with regex search-and-replace (Perl to Python) References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> Message-ID: Schif Schaf writes: > (brackets replaced by braces). I can do that with Perl pretty easily: > > ~~~~ > for (<>) { > s/\[(.+?)\]/\{$1\}/g; > print; > } > ~~~~ Just curious, but since this is just transpose, then why not simply tr/[]/{}/? I.e. why use a regular expression at all for this? In python you would do this with for line in text: print line.replace('[', '{').replace(']', '}') From steve at holdenweb.com Sun Feb 7 08:35:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:35:22 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: Shashwat Anand wrote: > LOL > pow(funny, sys.maxint) > Yes, funny, but it overlooks the point that Xah is a nuisance to multiple communities, not just to ours, and quite often concurrently. I'm all in favor of tolerance, but I'd like to see some evidence that rehabilitation is practical before the community has to tolerate too much of that kind of nonsense. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:37:07 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:37:07 -0500 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <4B6EBBEE.2070402@tim.thechases.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> Message-ID: <4B6EC203.4040807@holdenweb.com> Tim Chase wrote: > Schif Schaf wrote: >> On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: >>> I haven't used regexps in Python before, but what I did was (1) look >>> in the >>> documentation, > [snip] >>> >>> import re >>> >>> text = ( >>> "Lorem [ipsum] dolor sit amet, consectetur", >>> "adipisicing elit, sed do eiusmod tempor", >>> "incididunt ut [labore] et [dolore] magna aliqua." >>> ) >>> >>> withbracks = re.compile( r'\[(.+?)\]' ) >>> for line in text: >>> print( re.sub( withbracks, r'{\1}', line) ) >>> >> >> Seems like there's magic happening here. There's the `withbracks` >> regex that applies itself to `line`. But then when `re.sub()` does the >> replacement operation, it appears to consult the `withbracks` regex on >> the most recent match it just had. > > I suspect Alf's rustiness with regexps caused him to miss the simpler > rendition of > > print withbacks.sub(r'{\1}', line) > > And to answer those who are reaching for other non-regex (whether string > translations or .replace(), or pyparsing) solutions, it depends on what > you want to happen in pathological cases like > > s = """Dangling closing] > with properly [[nested]] and > complex [properly [nested] text] > and [improperly [nested] text > and with some text [straddling > lines] and with > dangling opening [brackets > """ > where you'll begin to see the differences. > Really? Under what circumstances does a simple one-for-one character replacement operation fail? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 08:37:07 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 08:37:07 -0500 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <4B6EBBEE.2070402@tim.thechases.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> Message-ID: <4B6EC203.4040807@holdenweb.com> Tim Chase wrote: > Schif Schaf wrote: >> On Feb 7, 12:19 am, "Alf P. Steinbach" wrote: >>> I haven't used regexps in Python before, but what I did was (1) look >>> in the >>> documentation, > [snip] >>> >>> import re >>> >>> text = ( >>> "Lorem [ipsum] dolor sit amet, consectetur", >>> "adipisicing elit, sed do eiusmod tempor", >>> "incididunt ut [labore] et [dolore] magna aliqua." >>> ) >>> >>> withbracks = re.compile( r'\[(.+?)\]' ) >>> for line in text: >>> print( re.sub( withbracks, r'{\1}', line) ) >>> >> >> Seems like there's magic happening here. There's the `withbracks` >> regex that applies itself to `line`. But then when `re.sub()` does the >> replacement operation, it appears to consult the `withbracks` regex on >> the most recent match it just had. > > I suspect Alf's rustiness with regexps caused him to miss the simpler > rendition of > > print withbacks.sub(r'{\1}', line) > > And to answer those who are reaching for other non-regex (whether string > translations or .replace(), or pyparsing) solutions, it depends on what > you want to happen in pathological cases like > > s = """Dangling closing] > with properly [[nested]] and > complex [properly [nested] text] > and [improperly [nested] text > and with some text [straddling > lines] and with > dangling opening [brackets > """ > where you'll begin to see the differences. > Really? Under what circumstances does a simple one-for-one character replacement operation fail? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python.list at tim.thechases.com Sun Feb 7 08:47:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 07:47:17 -0600 Subject: How to print all expressions that match a regular expression In-Reply-To: <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: <4B6EC465.3000405@tim.thechases.com> hzhuo1 at gmail.com wrote: >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." > > This is a hash collision problem. Nobody has proved that SHA-256 is > collision free It's actually pretty easy to prove that it is *not* collision free. The SHA-256 encodes 512 bits of data. So the the process of encoding (2**512)+1 distinct inputs incurs a collision in SHA-256 space as soon as you've hit (2**512)+1 if not earlier. to start you off: sha_backmap = {} for i in xrange((2**512)+2): hash = sha(str(i)) if hash in sha_backmap: print "Collision found: %i and %i" % ( i, sha_backmap[hash]) break sha_backmap[hash] = i Though it might take a computer the size of the universe, so I'm guessing that the first collision encountered is with "42". I leave the actual calculation and hashing of all possible combinations of 513 bits of data as an exercise to the reader with a lot of time on their hands or a quantum computer under their desk ;-) > It is hard to tell in advance. However, we can add some timing limit > or counting limit, to make it an algorithm, which can halt. For > example, whenever the program outputs more than 1000000 expressions > that match the input regex, we can halt because that exceeds our > limit. But surely this is not efficient because of the post-decision. As mentioned, it sounds like you either want a depth-first of the solution space that raises exceptions on an infinite/unbounded operator ("*", "+", and "{N,}" as mentioned in another email), or if you want to handle those operators, do a breadth-first search of the solution-space and track your depth (or time taken, or previous number of multi-factor atoms if you desire) to ensure you don't exceed a certain depth. But you're still talking a combinatorial number of solutions for even simple regexps. -tkc From python.list at tim.thechases.com Sun Feb 7 08:57:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 07:57:31 -0600 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <4B6EC203.4040807@holdenweb.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> <4B6EC203.4040807@holdenweb.com> Message-ID: <4B6EC6CB.8090800@tim.thechases.com> Steve Holden wrote: > Tim Chase wrote: >> And to answer those who are reaching for other non-regex (whether string >> translations or .replace(), or pyparsing) solutions, it depends on what >> you want to happen in pathological cases like >> >> s = """Dangling closing] >> with properly [[nested]] and >> complex [properly [nested] text] >> and [improperly [nested] text >> and with some text [straddling >> lines] and with >> dangling opening [brackets >> """ >> where you'll begin to see the differences. >> > Really? Under what circumstances does a simple one-for-one character > replacement operation fail? Failure is only defined in the clarified context of what the OP wants :) Replacement operations only fail if the OP's desired output from the above mess doesn't change *all* of the ]/[ characters, but only those with some form of parity (nested or otherwise). But if the OP *does* want all of the ]/[ characters replaced regardless of contextual nature, then yes, replace is a much better solution than regexps. -tkc From fetchinson at googlemail.com Sun Feb 7 09:11:41 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 15:11:41 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: >> LOL >> pow(funny, sys.maxint) >> > Yes, funny, but it overlooks the point that Xah is a nuisance to > multiple communities, not just to ours, and quite often concurrently. I don't think we need to worry about other communities or every internet related problem. The only thing we need to make sure is that c.l.p or the python community in general is friendly, tolerant, healthy and perhaps shows a good example to other communities on how to run a community, including how to handle problematic behavior. > I'm all in favor of tolerance, but I'd like to see some evidence that > rehabilitation is practical before the community has to tolerate too > much of that kind of nonsense. I don't think you get my point. Rehabilitation or cure is not the goal here. A village clown or court clown never changed, never got cured, never got reintroduced into the community as a 'normal' person. A village clown is tolerated in the purest form of the word 'tolerance' by nor wishing him to change. Let him be the clown, let everybody accept him as such, including all the annoyance and weird behavior. Hoping for someone to change is the same as assigning him to a correctional facility. I'd say let's designate a post Python Community Jester, or PCJ for short, let's name Xah Lee the PCJ and make it clear that he can engage in his activities on c.l.p and #python as he wishes without retribution and fear, and nobody should really bother him. The only people should do who don't like him is ignoring him. What is very important is that there can be only one PCJ and everybody else with objectionable behavior will be banned, blacklisted, etc. with the full force of available methods. This would I think send a very clear message to all other online communities that the Python Community is able to think outside the box, and is not afraid of taking unusual steps to maintain a healthy community and is even able to incorporate revolutionary new tactics to keep the community friendly and tolerant. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Sun Feb 7 09:14:42 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 7 Feb 2010 15:14:42 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: >>> LOL >>> pow(funny, sys.maxint) >>> >> Yes, funny, but it overlooks the point that Xah is a nuisance to >> multiple communities, not just to ours, and quite often concurrently. > > I don't think we need to worry about other communities or every > internet related problem. The only thing we need to make sure is that > c.l.p or the python community in general is friendly, tolerant, > healthy and perhaps shows a good example to other communities on how > to run a community, including how to handle problematic behavior. > >> I'm all in favor of tolerance, but I'd like to see some evidence that >> rehabilitation is practical before the community has to tolerate too >> much of that kind of nonsense. > > I don't think you get my point. Rehabilitation or cure is not the goal > here. A village clown or court clown never changed, never got cured, > never got reintroduced into the community as a 'normal' person. A > village clown is tolerated in the purest form of the word 'tolerance' > by nor wishing him to change. Let him be the clown, let everybody > accept him as such, including all the annoyance and weird behavior. > Hoping for someone to change is the same as assigning him to a > correctional facility. > > I'd say let's designate a post Python Community Jester, or PCJ for > short, let's name Xah Lee the PCJ and make it clear that he can engage > in his activities on c.l.p and #python as he wishes without > retribution and fear, and nobody should really bother him. The only > people should do who don't like him is ignoring him. What is very > important is that there can be only one PCJ and everybody else with > objectionable behavior will be banned, blacklisted, etc. with the full > force of available methods. > > This would I think send a very clear message to all other online > communities that the Python Community is able to think outside the > box, and is not afraid of taking unusual steps to maintain a healthy > community and is even able to incorporate revolutionary new tactics to > keep the community friendly and tolerant. One more thing: if every online community (or only programming related newsgroup) would designate an XY Community Jester I believe the relatively few number of serial trolls would all find their places somewhere eventually. This approach would actually work and solve a serious problem, as opposed to building more jails and more correctional facilities. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From as at sci.fi Sun Feb 7 09:30:52 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 07 Feb 2010 16:30:52 +0200 Subject: merge stdin, stdout? References: <68565855-cda5-4715-bb8b-aeddcb8678cb@z7g2000vbl.googlegroups.com> <0ec3e55a-90b6-4d49-89b5-6a5721d366b5@f15g2000yqe.googlegroups.com> Message-ID: jonny lowe writes: > The result is the same as before. I've tested in fedora11. I don't think script is the answer here, since it only stores what's displayed on a terminal and your program's input comes from a file and is not displayed on the terminal. Simplest solution is probably that you have your program echo every line of input. Maybe some hairy terminal trickery could be done? Really more of a Linux question than python. From darcy at druid.net Sun Feb 7 09:48:45 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Sun, 7 Feb 2010 09:48:45 -0500 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <20100207094845.4c448cf1.darcy@druid.net> On Sun, 7 Feb 2010 15:11:41 +0100 Daniel Fetchinson wrote: > I'd say let's designate a post Python Community Jester, or PCJ for > short, let's name Xah Lee the PCJ and make it clear that he can engage > in his activities on c.l.p and #python as he wishes without > retribution and fear, and nobody should really bother him. The only Are you sure you aren't lobbying for the position for yourself? I think you have a shot based on this proposal. -- 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 Martin.Drautzburg at web.de Sun Feb 7 09:50:53 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Sun, 07 Feb 2010 15:50:53 +0100 Subject: new.instancemethod __iter__ References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> Message-ID: <1458390.bWaDTVVBS2@beaureve.gmx.net> Steve Holden wrote: >> y = s1*2 + s2(align=10) >> >> which should iterate as >> >> Time=1,'a' >> Time=2,'a' >> Time=10,'b' >> >> I have no difficulty passing "align" to the object (using __call__) >> and use it while I furnish my own __iter__() method. However I don't >> quite see how I can do this with bare itertools, though I may be >> wrong here. >> >> Bare in mind that it is not only about somehow getting the job done. >> The beauty of the resulting syntax is also important. >> > In that case why not just assume that the timing of a sequence is > relative to the current time unless the "align" argument is given? Well that's pretty much what I'm doing. I just fail to see how I can do this with bare itertools. Currently I am doing it in the following way: When I call a Sequence as in s2(align=2) I create a new Sequence where the "align" value is simply stored in an instance variable. When creating the sum of two sequences, I create a Sequence with a new iter() method which first iterates over self and then over the second Sequence. But each time it has to look up the "align" value of the respective sequence and adjust "time" accordingly. Appending the two Sequences is the easy part, but adjusting time is the difficult part. My impression was, that itertools can only help to solve the first part. I may be missing something obvious. If that's the case, please let me know. From hzhuo1 at gmail.com Sun Feb 7 10:08:51 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sun, 7 Feb 2010 07:08:51 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> Message-ID: <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> > > And I really don't see how simple enumeration of range(2^2048) breaks > RSA-2048, since that problem requires you to find two factors which, > when multiplied together, give that specific value. > I can tell you why is that. RSA-2048 has a composite of length less than 2^2048, which is a product of two large primes. So one of its factors cannot exceed 2^2047, and we can treat the multiplication as a computation with constant complexity. So the time complexity of enumerating 2^2048 strings is the same with factoring a composite with length 2^2048 which is the product of two primes. And obviously, whenever we successfully factor the composite, we can calculate the Euler function of it. So that given any public key (n,e), calculating the private key (n,d) is easy. From steve at holdenweb.com Sun Feb 7 10:10:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:10:15 -0500 Subject: new.instancemethod __iter__ In-Reply-To: <1458390.bWaDTVVBS2@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> <1458390.bWaDTVVBS2@beaureve.gmx.net> Message-ID: <4B6ED7D7.6050106@holdenweb.com> Martin Drautzburg wrote: > Steve Holden wrote: > > >>> y = s1*2 + s2(align=10) >>> >>> which should iterate as >>> >>> Time=1,'a' >>> Time=2,'a' >>> Time=10,'b' >>> >>> I have no difficulty passing "align" to the object (using __call__) >>> and use it while I furnish my own __iter__() method. However I don't >>> quite see how I can do this with bare itertools, though I may be >>> wrong here. >>> >>> Bare in mind that it is not only about somehow getting the job done. >>> The beauty of the resulting syntax is also important. >>> >> In that case why not just assume that the timing of a sequence is >> relative to the current time unless the "align" argument is given? > > Well that's pretty much what I'm doing. I just fail to see how I can do > this with bare itertools. Currently I am doing it in the following way: > > When I call a Sequence as in s2(align=2) I create a new Sequence where > the "align" value is simply stored in an instance variable. > > When creating the sum of two sequences, I create a Sequence with a new > iter() method which first iterates over self and then over the second > Sequence. But each time it has to look up the "align" value of the > respective sequence and adjust "time" accordingly. > > Appending the two Sequences is the easy part, but adjusting time is the > difficult part. My impression was, that itertools can only help to > solve the first part. > > I may be missing something obvious. If that's the case, please let me > know. > Perhaps I am assuming too much of your simulation environment/player. I presumed that there would be a global "current time" value that would be passed into or available to the play method of the sequences. However I can see that you might need something more complex if (e.g.) you want to be able to start playing at an arbitrary point in time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:10:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:10:15 -0500 Subject: new.instancemethod __iter__ In-Reply-To: <1458390.bWaDTVVBS2@beaureve.gmx.net> References: <2036837.yhpURs0z1y@beaureve.gmx.net> <037de8e1$0$1292$c3e8da3@news.astraweb.com> <63288869.8iZ5tTOMcE@beaureve.gmx.net> <1458390.bWaDTVVBS2@beaureve.gmx.net> Message-ID: <4B6ED7D7.6050106@holdenweb.com> Martin Drautzburg wrote: > Steve Holden wrote: > > >>> y = s1*2 + s2(align=10) >>> >>> which should iterate as >>> >>> Time=1,'a' >>> Time=2,'a' >>> Time=10,'b' >>> >>> I have no difficulty passing "align" to the object (using __call__) >>> and use it while I furnish my own __iter__() method. However I don't >>> quite see how I can do this with bare itertools, though I may be >>> wrong here. >>> >>> Bare in mind that it is not only about somehow getting the job done. >>> The beauty of the resulting syntax is also important. >>> >> In that case why not just assume that the timing of a sequence is >> relative to the current time unless the "align" argument is given? > > Well that's pretty much what I'm doing. I just fail to see how I can do > this with bare itertools. Currently I am doing it in the following way: > > When I call a Sequence as in s2(align=2) I create a new Sequence where > the "align" value is simply stored in an instance variable. > > When creating the sum of two sequences, I create a Sequence with a new > iter() method which first iterates over self and then over the second > Sequence. But each time it has to look up the "align" value of the > respective sequence and adjust "time" accordingly. > > Appending the two Sequences is the easy part, but adjusting time is the > difficult part. My impression was, that itertools can only help to > solve the first part. > > I may be missing something obvious. If that's the case, please let me > know. > Perhaps I am assuming too much of your simulation environment/player. I presumed that there would be a global "current time" value that would be passed into or available to the play method of the sequences. However I can see that you might need something more complex if (e.g.) you want to be able to start playing at an arbitrary point in time. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From fuzzy.666.chaos at gmail.com Sun Feb 7 10:22:55 2010 From: fuzzy.666.chaos at gmail.com (Jordan Uchima) Date: Sun, 7 Feb 2010 09:22:55 -0600 Subject: still having problems with "Nim". using python 2.6.4 Message-ID: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> I have attached the file that the game is on. feel free to modify it to make it better. all suggestions are welcome. if you don't want to download the file then here's the code: ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Start with thirteen pieces and two players. # Each player takes 1 - 4 pieces each turn. # Player who takes the last piece loses. # Declare constants. NUMBER_OF_PLAYERS = 2 TOTAL_PIECES_AT_START = 13 namePlayer1 = raw_input("Hello Player 1, what is your name?\n") namePlayer2 = raw_input("Hello Player 2, what is your name?\n") # Declare functions. def rules(): """Print the rules of the game.""" print 'The player that takes the last piece loses!'\ 'You can only take 1 - 4 pieces!\n\n' def get_players(): """Get the names of the players.""" # Let's put the player's names in a list. players = [] # Looping like this saves us repeating lines of code for each player. for player in range(NUMBER_OF_PLAYERS): players.append(player) break return players def take_turn(player): """Handle a player's turn.""" # Turn logic goes here. player1Choice = int(raw_input(namePlayer1 + " how many pieces would you like to take?\n")), player2Choice = int(raw_input(namePlayer2 + " how many pieces would you like to take?\n")) playerChoice = player1Choice and player2Choice x = 13 - playerChoice loss = x <=2 and x >= 0, while player1Choice == loss is True: print namePlayer1 + " loses!" while player2Choice == loss is True: print namePlayer2, loss while player1Choice and player2Choice == loss is True: print "It's a draw!" while player1Choice != loss is True: print x while player2Choice != loss is True: print x while player1Choice and player2Choice != loss is True: print ("Keep going! Only ", x, " pieces left!") validChoice = \ player1Choice == range(1, 4) is True, print x player1Choice == range(1, 4) is False, print validChoice player2Choice == range(1, 4) is True, print x player2Choice == range(1, 4) is False, print validChoice def main(): """Run the game.""" # Display the rules by calling rules function. rules() # Get the players by calling the get_players function. players = get_players() # Set up the game. remaining_pieces = TOTAL_PIECES_AT_START playing = True # Main loop - let's play! while playing: # Take turns. for player in players: remaining_pieces = take_turn(player) # Check if this player has lost. if remaining_pieces <= 1: # Player has taken last piece. print 'Sorry ', loser, ' you have lost.' # Break out of the loop playing = False break # Automatically run main function if we're run as a script. if __name__ == '__main__': main() # End. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- my problem is that i can't get it to make the players have more than 1 turn each, it accepts any value for playerChoice, (it is only supposed to accept values from 1 to 4), and "x" resets after each turn. i can get it to subtract playerChoice from "x", and display the result, which should be "x", but, then, "x" resets... by the way, i need this program finished by wednesday, Feb. 10, 2010. Please help me!!! -- Jordan (fuzzy.666.chaos at gmail.com) -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: Nim.py Type: application/octet-stream Size: 2785 bytes Desc: not available URL: From steve at holdenweb.com Sun Feb 7 10:38:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:38:38 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> Message-ID: <4B6EDE7E.7020304@holdenweb.com> hzhuo1 at gmail.com wrote: >> And I really don't see how simple enumeration of range(2^2048) breaks >> RSA-2048, since that problem requires you to find two factors which, >> when multiplied together, give that specific value. >> > > I can tell you why is that. RSA-2048 has a composite of length less > than 2^2048, which is a product of two large primes. So one of its > factors cannot exceed 2^2047, and we can treat the multiplication as a > computation with constant complexity. So the time complexity of > enumerating 2^2048 strings is the same with factoring a composite with > length 2^2048 which is the product of two primes. > > And obviously, whenever we successfully factor the composite, we can > calculate the Euler function of it. So that given any public key > (n,e), calculating the private key (n,d) is easy. > So all I have to do to break RSA is to count to 2^2048? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:38:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:38:38 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> Message-ID: <4B6EDE7E.7020304@holdenweb.com> hzhuo1 at gmail.com wrote: >> And I really don't see how simple enumeration of range(2^2048) breaks >> RSA-2048, since that problem requires you to find two factors which, >> when multiplied together, give that specific value. >> > > I can tell you why is that. RSA-2048 has a composite of length less > than 2^2048, which is a product of two large primes. So one of its > factors cannot exceed 2^2047, and we can treat the multiplication as a > computation with constant complexity. So the time complexity of > enumerating 2^2048 strings is the same with factoring a composite with > length 2^2048 which is the product of two primes. > > And obviously, whenever we successfully factor the composite, we can > calculate the Euler function of it. So that given any public key > (n,e), calculating the private key (n,d) is easy. > So all I have to do to break RSA is to count to 2^2048? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:46:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:46:34 -0500 Subject: still having problems with "Nim". using python 2.6.4 In-Reply-To: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> References: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> Message-ID: <4B6EE05A.8080100@holdenweb.com> Jordan Uchima wrote: > I have attached the file that the game is on. feel free to modify it to > make it better. all suggestions are welcome. if you don't want to > download the file then here's the code: > [...] > > my problem is that i can't get it to make the players have more than 1 > turn each, it accepts any value for playerChoice, (it is only supposed > to accept values from 1 to 4), and "x" resets after each turn. i can get > it to subtract playerChoice from "x", and display the result, which > should be "x", but, then, "x" resets... by the way, i need this program > finished by wednesday, Feb. 10, 2010. Please help me!!! > The deadline implies an even higher probability that this is homework. I don't know whether you declared this in your earlier post, but it's always as well to do so. You've made a substantial effort to solve the problem though, so I don't mind trying to help. I hope you regard the following as helpful. You need a program structure that keeps going until the required termination condition is reached. One such structure would be: while sticks_remaining > 1: taketurn(next_player()) So now you only need a next_player() function that returns alternate values on successive calls and a taketurn() function that reduces the number of sticks according to the instructions form the given player. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 10:46:34 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 10:46:34 -0500 Subject: still having problems with "Nim". using python 2.6.4 In-Reply-To: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> References: <1b07ab151002070722g17630b26y3eb6722918e4fd97@mail.gmail.com> Message-ID: <4B6EE05A.8080100@holdenweb.com> Jordan Uchima wrote: > I have attached the file that the game is on. feel free to modify it to > make it better. all suggestions are welcome. if you don't want to > download the file then here's the code: > [...] > > my problem is that i can't get it to make the players have more than 1 > turn each, it accepts any value for playerChoice, (it is only supposed > to accept values from 1 to 4), and "x" resets after each turn. i can get > it to subtract playerChoice from "x", and display the result, which > should be "x", but, then, "x" resets... by the way, i need this program > finished by wednesday, Feb. 10, 2010. Please help me!!! > The deadline implies an even higher probability that this is homework. I don't know whether you declared this in your earlier post, but it's always as well to do so. You've made a substantial effort to solve the problem though, so I don't mind trying to help. I hope you regard the following as helpful. You need a program structure that keeps going until the required termination condition is reached. One such structure would be: while sticks_remaining > 1: taketurn(next_player()) So now you only need a next_player() function that returns alternate values on successive calls and a taketurn() function that reduces the number of sticks according to the instructions form the given player. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From aahz at pythoncraft.com Sun Feb 7 11:00:27 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Feb 2010 08:00:27 -0800 Subject: threading+popen2 hang References: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> Message-ID: In article <188bfb67-3334-4325-adfc-3fa4d28f0cbf at d27g2000yqn.googlegroups.com>, lofic wrote: > >Works fine on RHEL5/python 2.4.3 >Hangs on RHEL4/python 2.3.4 Then use Python 2.4 -- surely you don't expect anyone to provide bugfixes for a release that's several years old? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Sun Feb 7 11:24:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Feb 2010 08:24:04 -0800 Subject: passing string for editing in input() References: Message-ID: In article , Chris Rebert wrote: >On Tue, Feb 2, 2010 at 5:24 AM, mk wrote: >> >> Is there an easy way to get an editing (readline) in Python that would >> contain string for editing and would not just be empty? >> >> I googled but found nothing. > >Er...: http://docs.python.org/library/readline.html >It's the third hit for "python readline". > >Actually reading the page, sounds like you want readline.insert_text() >specifically. That seems a tad harsh, especially after reading the docs and following Peter Otten's link. It's not at all obvious how to actually use insert_text(), and although I probably could have figured it out on my own, I might well have posted here myself. Did you try using insert_text() before posting? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at REMOVE-THIS-cybersource.com.au Sun Feb 7 11:31:12 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 16:31:12 GMT Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <00f87008$0$15628$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 13:57:13 +0100, Daniel Fetchinson wrote: > having a single c.l.p clown is tolerable if it makes him happy. Why should we care about his happiness if it comes at the expense of the happiness of hundreds of other people? I mean, if he decided that his happiness was best satisfied by following you home one day and smashing all your windows and pouring tar all over your furniture and smearing excrement over your clothes, should we tolerate that because it makes him happy? And later, in another post: > A village clown is tolerated in the purest form of the word 'tolerance' > by nor wishing him to change. Let him be the clown, let everybody > accept him as such, including all the annoyance and weird behavior. Why should we? What's in it for us? > Hoping for someone to change is the same as assigning him to a > correctional facility. That's a ridiculous comparison, which could only have been spoken to somebody who has never been in prison. You trivialise the problem of the punishment society by equating it to expecting a modicum of polite behaviour in public. > I'd say let's designate a post Python Community Jester, or PCJ for > short, let's name Xah Lee the PCJ and make it clear that he can engage > in his activities on c.l.p and #python as he wishes without > retribution and fear, and nobody should really bother him. The only > people should do who don't like him is ignoring him. What is very > important is that there can be only one PCJ and everybody else with > objectionable behavior will be banned, blacklisted, etc. with the full > force of available methods. Why should Xah Lee get special treatment? If other anti-social nuisances and trolls are banned, why should he get the privilege of being tolerated no matter what he does? What is so special about Xah Lee that he gets carte blanche permission to be as obnoxious as he wants, while everyone else has to follow the rules of polite society? -- Steven From ldl08 at gmx.net Sun Feb 7 12:07:33 2010 From: ldl08 at gmx.net (David) Date: Mon, 08 Feb 2010 01:07:33 +0800 Subject: Your impression of for-novice writings on assertions In-Reply-To: References: Message-ID: <4B6EF355.1040405@gmx.net> Hi Alf, I think you talk too much... :-) Basically I am all for a verbose approach in a text for beginners, but on the other hand it is necessary to stick to the point you are making. When, for example, you introduce your reader to the thoughts of Francis Glassborrow on page 5 of chapter three, then the only relevant point you are making is the following: "Many programmers hide the structure of their code behind their comments [which is to be avoided]". If you insist on a proper citation here, then use a footnote, but even there I would suggest you merely offer the link. As it stands you are not to the point, and frankly, as a beginner I have enough stuff troubling my head so that I do not need superfluous information as to the evolution of the things you are talking about. Just the facts, please. My 2 cents, David On 03/02/10 04:54, Alf P. Steinbach wrote: > I've started on ch 3 of my beginner's intro to programming, now delving > into the details of the Python language. > > It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at > which is at Google Docs. > > The first topic is about assertions and exceptions. I wonder whether > this text is easy or difficult to understand for a beginner. Or any > improvements that could be made. > > > Cheers, > > - Alf From john at castleamber.com Sun Feb 7 12:38:51 2010 From: john at castleamber.com (John Bokma) Date: Sun, 07 Feb 2010 11:38:51 -0600 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <87eikx54k4.fsf@castleamber.com> Daniel Fetchinson writes: > One more thing: Yeah, one more thing: since you are all for a better community why not reply without quoting the entire message? Just quote enough to provide some decent context. Xah is just a spammer. It amazes me how often people want to step in the role of Xah's sockpuppet. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From tjreedy at udel.edu Sun Feb 7 13:20:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 07 Feb 2010 13:20:25 -0500 Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: On 2/7/2010 7:39 AM, Steve Holden wrote: > Clearly written by someone who has never *used* a mechanical typewriter. > The original mechanisms had "tab set" and "tab clear" keys, so you had > variable tabbing according to the needs of the particular document you > were working on. Look under "T" in > > http://www.mytypewriter.com/explorelearn/glossary.html > > if you aren't old enough to have used one. I did start with real typewriters. The 'standard', if anything, was 1/2" for paragraph indents. That was 5 chars with normal 10 cpi type, 6 with 12 cpi 'elite' type. I used both. I always thought the 8 char unix indent to be excessive. If a power of 2 was needed, rounding 5 down to 4 would have been more sensible. Wordperfect, which I wrote a couple of books with, followed the typewriter model in defaulting tab stops to every 1/2 inch, regardless of font. Sensible software tab defaults were not pioneered by Microsoft. Terry Jan Reedy From darnzen at gmail.com Sun Feb 7 13:24:40 2010 From: darnzen at gmail.com (darnzen) Date: Sun, 7 Feb 2010 10:24:40 -0800 (PST) Subject: WCK and PIL References: <1fbe5e4b-2179-410b-9f76-9d65a7a08dce@k19g2000yqc.googlegroups.com> Message-ID: <28dee2e8-25a1-4f1d-901e-d8f7d0417e0a@z26g2000yqm.googlegroups.com> On Feb 6, 10:19?pm, Nobody wrote: > On Fri, 05 Feb 2010 21:05:53 -0800, darnzen wrote: > > I've written an app using thewcklibrary (widget construction kit, > > seehttp://www.effbot.org), in addition to the wckGraph module. What > > I'd like to do, is take the output of one of my windows (happens to be > > a graph), and save it as a *.png or *.gif. I was planning on using the > >PILfor this. I'd like to use the code I have as is, without re- > > writing all the graphic calls to usePILmethods. > > >WCKuses its own "pixmap" class for storing images in memory. I can't > > find any documentation or class reference for pixmap and what I find > > in the source is confusing. > > AWCKpixmap is a "draw object" whose underlying drawable is a pixmap > (i.e. a Tk pixmap, which is the platform's native "chunk of video memory" > pixmap type) rather than a window. > > From the source code,WCKdoesn't appear to offer any way to retrieve the > pixel data (i.e. there's no way to do the opposite of draw.paste()). I found a description of how to use a WCK drawing interface to draw into a PIL image. (http://effbot.org/zone/pil-draw-wck.htm) but I'm not sure how to use that class (SimpleDraw) to allow me to use existing WCK code. Should I use it as a "mix in" to overwrite base methods via inheritance? class MyClass(SimpleDraw, Widget): pass From rikutheronin at gmail.com Sun Feb 7 13:36:10 2010 From: rikutheronin at gmail.com (Pablo Recio Quijano) Date: Sun, 7 Feb 2010 19:36:10 +0100 Subject: Checking the coding style Message-ID: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Hi! I'm finishing a project writen in Python, and I realize about the document PEP8 - Style Guide for Python Code [1]. Is there any app or script that checks if my project pass that style guide? I also worked with Drupal, and I know there is some modules and scripts that checks its coding standars [2] and it's very usefull to clean the code. Thanks in advance! [1] http://www.python.org/dev/peps/pep-0008/ [2] http://drupal.org/coding-standards -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From misceverything at gmail.com Sun Feb 7 14:02:30 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 11:02:30 -0800 (PST) Subject: Executing Commands From Windows Service Message-ID: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> I have a script, which runs as a Windows service under the LocalSystem account, that I wish to have execute some commands. Specifically, the program will call plink.exe to create a reverse SSH tunnel. Right now I'm using subprocess.Popen to do so. When I run it interactively via an admin account, all is well. However, when I'm running it via service, no luck. I'm assuming this is to do with the fact that it's trying to run under the LocalSystem account, which is failing. What would be the best way around this? Thanks! From gerald.britton at gmail.com Sun Feb 7 14:17:19 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Sun, 7 Feb 2010 14:17:19 -0500 Subject: Checking the coding style In-Reply-To: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Message-ID: <5d1a32001002071117n18ba7b47j515d75946b79af0f@mail.gmail.com> pylint and pychecker are good options On Sun, Feb 7, 2010 at 1:36 PM, Pablo Recio Quijano wrote: > Hi! > I'm finishing a project writen in Python, and I realize about the document > PEP8 - Style Guide for Python Code [1]. > Is there any app or script that checks if my project pass that style guide? > I also worked with Drupal, and I know there is some modules and scripts that > checks its coding standars [2] and it's very usefull to clean the code. > Thanks in advance! > [1]?http://www.python.org/dev/peps/pep-0008/ > [2]?http://drupal.org/coding-standards > > -- > Pablo Recio Quijano > > Estudiante de Ingenier?a Inform?tica (UCA) > Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos > Participante del IV Concurso Universitario de Software Libre > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- Gerald Britton From apt.shansen at gmail.com Sun Feb 7 14:17:40 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 7 Feb 2010 11:17:40 -0800 Subject: Executing Commands From Windows Service In-Reply-To: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <7a9c25c21002071117p139f00bx19362eaf72a8d037@mail.gmail.com> On Sun, Feb 7, 2010 at 11:02 AM, T wrote: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. Specifically, the > program will call plink.exe to create a reverse SSH tunnel. Right now > I'm using subprocess.Popen to do so. When I run it interactively via > an admin account, all is well. However, when I'm running it via > service, no luck. I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. What > would be the best way around this? Thanks! > I don't know what your specific issue is, but here's some tips for running Python as a service on windows which are not always immediately obvious and can cause failures: - The search path is screwy: if you are importing a module that happens to be the same name as a dll in system32 (even if this isn't at all a python dll), it can get confused. - There is *no* sys.stdout! This is a big one. If any piece of code you're using ever does 'print', the whole thing can crash hard. I replace sys.stdout and sys.stderr with a fake file-like object that catches errors in attempting to .write to the real one and ignores them. If neither of those two are a problem for you, you need to define "no luck" before anyone will be able to help you. Are there errors in the event viewer? Are you getting an exception that's killing out your service (capture and write to a file with the logging module)? Or is the Popen call being run and returning but just not doing anything (in which case, try capturing output from the command and see if it indicates an error message from plink.exe). Etc. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.p.dwyer at gmail.com Sun Feb 7 14:22:26 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 7 Feb 2010 19:22:26 +0000 (UTC) Subject: Checking the coding style References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Message-ID: On Sun, 07 Feb 2010 19:36:10 +0100, Pablo Recio Quijano wrote: > Hi! > > I'm finishing a project writen in Python, and I realize about the > document PEP8 - Style Guide for Python Code [1]. > > Is there any app or script that checks if my project pass that style > guide? I also worked with Drupal, and I know there is some modules and > scripts that checks its coding standars [2] and it's very usefull to > clean the code. > > Thanks in advance! > > [1] http://www.python.org/dev/peps/pep-0008/ [2] > http://drupal.org/coding-standards Hello Pablo, The pep8 package (http://pypi.python.org/pypi/pep8) can do this, though I have never used it myself. PyLint is a customisable static analysis program that checks style among other things. Cheers, Kev From rikutheronin at gmail.com Sun Feb 7 14:27:45 2010 From: rikutheronin at gmail.com (Pablo Recio Quijano) Date: Sun, 7 Feb 2010 20:27:45 +0100 Subject: Checking the coding style In-Reply-To: <5d1a32001002071117n18ba7b47j515d75946b79af0f@mail.gmail.com> References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> <5d1a32001002071117n18ba7b47j515d75946b79af0f@mail.gmail.com> Message-ID: <1fb1c371002071127u8cf0bf2w3eeef60c03bf6868@mail.gmail.com> Thanks! Pylint was what i was loking for 2010/2/7 Gerald Britton > pylint and pychecker are good options > > On Sun, Feb 7, 2010 at 1:36 PM, Pablo Recio Quijano > wrote: > > Hi! > > I'm finishing a project writen in Python, and I realize about the > document > > PEP8 - Style Guide for Python Code [1]. > > Is there any app or script that checks if my project pass that style > guide? > > I also worked with Drupal, and I know there is some modules and scripts > that > > checks its coding standars [2] and it's very usefull to clean the code. > > Thanks in advance! > > [1] http://www.python.org/dev/peps/pep-0008/ > > [2] http://drupal.org/coding-standards > > > > -- > > Pablo Recio Quijano > > > > Estudiante de Ingenier?a Inform?tica (UCA) > > Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos > > Participante del IV Concurso Universitario de Software Libre > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > Gerald Britton > -- Pablo Recio Quijano Estudiante de Ingenier?a Inform?tica (UCA) Alumno colaborador del Departamento de Lenguajes y Sistemas Inform?ticos Participante del IV Concurso Universitario de Software Libre -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Sun Feb 7 14:59:40 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sun, 7 Feb 2010 11:59:40 -0800 (PST) Subject: Checking the coding style References: <1fb1c371002071036n6abcf519x4b636162461c5c9c@mail.gmail.com> Message-ID: <4f2ae5b7-1b4e-46cc-94ae-e70b3099ea7a@d37g2000yqa.googlegroups.com> On Feb 7, 8:22?pm, Kev Dwyer wrote: > On Sun, 07 Feb 2010 19:36:10 +0100, Pablo Recio Quijano wrote: > > Hi! > > > I'm finishing a project writen in Python, and I realize about the > > document PEP8 - Style Guide for Python Code [1]. > > > Is there any app or script that checks if my project pass that style > > guide? I also worked with Drupal, and I know there is some modules and > > scripts that checks its coding standars [2] and it's very usefull to > > clean the code. > > > Thanks in advance! > > > [1]http://www.python.org/dev/peps/pep-0008/[2] > >http://drupal.org/coding-standards > > Hello Pablo, > > The pep8 package (http://pypi.python.org/pypi/pep8) can do this, though > I have never used it myself. ?PyLint is a customisable static analysis > program that checks style among other things. > > Cheers, > > Kev I've used pep8.py myself for some Python 3.x projects, and it's pretty good. You don't need to install it either, a simple call via python pep8.py 'yourpythonfile.py' should do. I think PyLint can be used for Python 2.x, but I'm not sure about 3.x. From buzzard at urubu.freeserve.co.uk Sun Feb 7 15:45:59 2010 From: buzzard at urubu.freeserve.co.uk (duncan smith) Date: Sun, 07 Feb 2010 20:45:59 +0000 Subject: max / min / smallest float value on Python 2.5 In-Reply-To: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> References: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Sun, 07 Feb 2010 03:02:05 +0000, duncan smith wrote: > >> The precise issue is that I'm supplying a default value of >> 2.2250738585072014e-308 for a parameter (finishing temperature for a >> simulated annealing algorithm) in an application. I develop on >> Ubuntu64, but (I am told) it's too small a value when run on a Win32 >> server. I assume it's being interpreted as zero and raising an >> exception. Thanks. > > I'm trying to think of what sort of experiment would be able to measure > temperatures accurate to less than 3e-308 Kelvin, and my brain boiled. > > Surely 1e-100 would be close enough to zero as to make no practical > difference? Or even 1e-30? Whatever you're simulating surely isn't going > to require 300+ decimal points of accuracy. > > I must admit I'm not really familiar with simulated annealing, so I could > be completely out of line, but my copy of "Numerical Recipes ..." by > Press et al has an example, and they take the temperature down to about > 1e-6 before halting. Even a trillion times lower that that is 1e-15. > > It depends on the optimisation problem, but I suppose the fitness functions could be tweaked. I could paste the actual code if anyone's interested, but the following pseudo-python gives the idea. For an exponential cooling schedule the temperatures are generated as below. The lower the final temperature the greater the number of iterations, and the longer the algorithm spends searching locally for an optimal solution (having already searched more widely for areas of high fitness at higher temperatures). The probability of moving to a less fit solution is given by exp(dF/temp) where dF is a (negative) change in fitness and temp is the current temperature. So I could scale the fitness function to cope with higher finishing temperatures. I'm going to have to think about the point raised by Steve (Holden). I also think I can probably improve on raising StopIteration if exp(dF/temp) overflows by yielding False instead (although if it does overflow it probably indicates a poor choice of cooling schedule for the given problem). Stuff to think about. Cheers. Duncan import random import math def temps(start, final, mult): t = start while t > final: yield t t *= mult def sim_anneal(permuter, start, final, mult): rand = random.random exp = math.exp for temp in temps(start, final, mult): dF = permuter.next() if dF >= 0: yield True else: try: yield rand() < exp(dF / temp) except OverflowError: raise StopIteration class Permuter(object): def __init__(self, obj): self.obj = obj self.proposed = None def run(self, start, final, mult): for decision in sim_anneal(self, start, final, mult): if decision: # commit proposed change to self.obj def next(): # propose a change to self.obj # calculate and return the change in fitness self.proposed = proposed return dF From dickinsm at gmail.com Sun Feb 7 16:06:59 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 7 Feb 2010 13:06:59 -0800 (PST) Subject: max / min / smallest float value on Python 2.5 References: <00f7c75e$0$15628$c3e8da3@news.astraweb.com> Message-ID: <11668ca0-0f7f-41d0-9f6b-2e9f6b6a02ea@l26g2000yqd.googlegroups.com> On Feb 7, 8:45?pm, duncan smith wrote: [...] > interested, but the following pseudo-python gives the idea. ?For an [...] > ? ? ? ? ? ? ?try: > ? ? ? ? ? ? ? ? ?yield rand() < exp(dF / temp) Practically speaking, the condition rand() < exp(dF / temp) is never going to be satisfied if dF / temp < -40 (in fact, the output of rand() is always an exact multiple of 2**-53, so the condition rand() < exp(-40) is identical to the condition rand() == 0.0, which should occur for one random sample out of every 9 thousand million million or so). So assuming that your fitness delta dF can't get smaller than 1e-16 or so in absolute value (which seems reasonable, given that dF is presumably the result of subtracting two numbers of 'normal' magnitude), there would be little point having temp go much smaller than, say, 1e-20. IOW, I agree with Steven: 2.2e-308 seems extreme. -- Mark From nyamatongwe+thunder at gmail.com Sun Feb 7 16:08:45 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sun, 07 Feb 2010 21:08:45 GMT Subject: TABS in the CPython C source code In-Reply-To: References: Message-ID: Aahz: > BTW, in case anyone is confused, it's "svn blame" vs "cvs annotate". Possibly earlier versions of SVN only supported "blame" but the variants "annotate", "ann", and "praise" all work with the version of SVN (1.6.5) I have installed. Neil From james.harris.1 at googlemail.com Sun Feb 7 16:25:21 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sun, 7 Feb 2010 13:25:21 -0800 (PST) Subject: Available for use: Tabs management software Message-ID: In case someone else finds it useful here is a program I wrote a year or so ago to help manage tab characters. It will convert tabs to runs of spaces, convert runs of spaces to tabs, or count or check for tab characters as required. It supports tab stops at regular and irregular positions. http://codewiki.wikispaces.com/tabs.py It is written in Python and you can either use it from the command line or call the functions from another Python script. Documentation is included on the web page. James From half.italian at gmail.com Sun Feb 7 16:43:02 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sun, 7 Feb 2010 13:43:02 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> On Feb 7, 11:02?am, T wrote: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. ?Specifically, the > program will call plink.exe to create a reverse SSH tunnel. ?Right now > I'm using subprocess.Popen to do so. ?When I run it interactively via > an admin account, all is well. ?However, when I'm running it via > service, no luck. ?I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. ?What > would be the best way around this? ?Thanks! Try running/debugging your service from the commandline as " debug" That should lead you to the error. Otherwise, we need to see a traceback and some code to be better able to help. ~Sean From misceverything at gmail.com Sun Feb 7 16:51:19 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 13:51:19 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> Message-ID: <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> On Feb 7, 4:43?pm, Sean DiZazzo wrote: > On Feb 7, 11:02?am, T wrote: > > > I have a script, which runs as a Windows service under the LocalSystem > > account, that I wish to have execute some commands. ?Specifically, the > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > an admin account, all is well. ?However, when I'm running it via > > service, no luck. ?I'm assuming this is to do with the fact that it's > > trying to run under the LocalSystem account, which is failing. ?What > > would be the best way around this? ?Thanks! > > Try running/debugging your service from the commandline as > " debug" ?That should lead you to the error. > > Otherwise, we need to see a traceback and some code to be better able > to help. > > ~Sean It's working fine when I run it via " debug" - that's how I was testing before. It's when I start the service that it fails - and you can see that, when you run it with debug, plink.exe runs under my username. When I run it as a service, it runs under System... From ahleniusm at gmail.com Sun Feb 7 16:51:36 2010 From: ahleniusm at gmail.com (m_ahlenius) Date: Sun, 7 Feb 2010 13:51:36 -0800 (PST) Subject: question on using tarfile to read a *.tar.gzip file Message-ID: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> Hi, I have a number of relatively large number *tar.gzip files to process. With the py module tarfile, I see that I can access and extract them, one at a time to a temporary dir, but that of course takes time. All that I need to do is to read the first and last lines of each file and then move on to the next one. I am not changing anything in these files - just reading. The file lines are not fixed lengths either, which makes it a bit more fun. Is there a way to do this, without decompressing each file to a temp dir? Like is there a method using some tarfile interface adapter to read a compressed file? Otherwise I'll just access each file, extract it, grab the 1st and last lines and then delete the temp file. thx 'mark From hzhuo1 at gmail.com Sun Feb 7 16:57:14 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sun, 7 Feb 2010 13:57:14 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <1dc6c8d4-72c9-463d-a747-59387d19f4df@d34g2000vbl.googlegroups.com> <04dfa894-bf5d-4aea-a093-5394d6b295ba@p23g2000vbl.googlegroups.com> Message-ID: That is a method called brute force. According to my computation, 2^2048= 32317006071311007300714876688669951960444102669715484032130345427524655138867890 89319720141152291346368871796092189801949411955915049092109508815238644828312063 08773673009960917501977503896521067960576383840675682767922186426197561618380943 38476170470581645852036305042887575891541065808607552399123930385521914333389668 34242068497478656456949485617603532632205807780565933102619270846031415025859286 41771167259436037184618573575983511523016459044036976132332872312271256847108202 09725157101726931323469678542580656697935045997268352998638215525166389437335543 602135433229604645318478604952148193555853611059596230656L which is a very large number. There are some other algorithms for factoring integers, including Generalized number field sieve. And in quantum computing, there is an algorithm called Shor, which is claimed to be a polynomial algorithm if run under quantum computers. But seems that kind of computers haven't been successfully built, or else RSA and many other security mechanisms based on computation complexity cannot be used any longer. What I need in my application is just to list all expressions that match a particular regex, which I believe will be more efficient to deal with if there is a general function for this purpose. Unfortunately there is not such a function, so I will write my own function to deal with my particular regex, which can be enumerated. Sincerely, Zhuo On Feb 7, 10:38?am, Steve Holden wrote: > hzh... at gmail.com wrote: > >> And I really don't see how simple enumeration of range(2^2048) breaks > >> RSA-2048, since that problem requires you to find two factors which, > >> when multiplied together, give that specific value. > > > I can tell you why is that. RSA-2048 has a composite of length less > > than 2^2048, which is a product of two large primes. So one of its > > factors cannot exceed 2^2047, and we can treat the multiplication as a > > computation with constant complexity. So the time complexity of > > enumerating 2^2048 strings is the same with factoring a composite with > > length 2^2048 which is the product of two primes. > > > And obviously, whenever we successfully factor the composite, we can > > calculate the Euler function of it. So that given any public key > > (n,e), calculating the private key (n,d) is easy. > > So all I have to do to break RSA is to count to 2^2048? > > regards > ?Steve > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 ?http://us.pycon.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ From half.italian at gmail.com Sun Feb 7 17:02:37 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sun, 7 Feb 2010 14:02:37 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> Message-ID: > > It's working fine when I run it via " debug" - that's how > I was testing before. ?It's when I start the service that it fails - > and you can see that, when you run it with debug, plink.exe runs under > my username. ?When I run it as a service, it runs under System... You can have the service run as any user under the service properties. Perhaps set the service to run under your username? There may be some environment variables set in your session that aren't in the one its running as. So maybe check there as well. Off to drink beer. Good luck. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 7 17:07:15 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 07 Feb 2010 22:07:15 GMT Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> Message-ID: <00f8becc$0$15628$c3e8da3@news.astraweb.com> On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: >> "Given the function hashlib.sha256, enumerate all the possible inputs >> that give the hexadecimal result >> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." > > I tried some "parrot" variants but no dice. :-( Oh, everybody expects parrots! That's not unexpected -- as a clue, I wrote that "the message is predictable for being totally unexpected". The input was "Nobody expects the Spanish Inquisition!", which is another Monty Python catchphrase. -- Steven From alfps at start.no Sun Feb 7 17:14:39 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 07 Feb 2010 23:14:39 +0100 Subject: Executing Commands From Windows Service In-Reply-To: <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> Message-ID: * T: > On Feb 7, 4:43 pm, Sean DiZazzo wrote: >> On Feb 7, 11:02 am, T wrote: >> >>> I have a script, which runs as a Windows service under the LocalSystem >>> account, that I wish to have execute some commands. Specifically, the >>> program will call plink.exe to create a reverse SSH tunnel. Right now >>> I'm using subprocess.Popen to do so. When I run it interactively via >>> an admin account, all is well. However, when I'm running it via >>> service, no luck. I'm assuming this is to do with the fact that it's >>> trying to run under the LocalSystem account, which is failing. What >>> would be the best way around this? Thanks! >> Try running/debugging your service from the commandline as >> " debug" That should lead you to the error. >> >> Otherwise, we need to see a traceback and some code to be better able >> to help. >> >> ~Sean > > It's working fine when I run it via " debug" - that's how > I was testing before. It's when I start the service that it fails - > and you can see that, when you run it with debug, plink.exe runs under > my username. When I run it as a service, it runs under System... This sounds like a Windows programming problem, not anything related to Python per se. Windows services are generally limited in what they can do, such as interaction with the user, and I guess that spills over to network access. Also, services need to interact with the service control manager, the "scum" as it's known. Well, all right, that's just what my coworkers and I called it once. But essentially, it's an even-driven execution model, which means that it might not work to use just any program, such as [python.exe], directly as a service. The Windows Resource Kit used to have a facility for running ordinary programs as services. I'm not sure what it did at the technical level, but it worked. Or it appeared to work. You might also find it useful to look up the documentation on services that interact with the user. In the old times that was mostly a matter of configuring which account the service ran under. But I think it all got more complicated with Microsoft's introduction of Terminal services (generally, most of the complication in modern Windows is due to the shift in focus about 1995, ditching the personal computer user market in favor of the enterprise and MIS market). Cross-posted to [comp.os.ms-windows.programmer.win32], follow-ups set to that group -- that means, unless overridden you won't see follow-ups in [c.l.p]. I think that group may give more informative and helpful responses. Cheers & hth., - Alf From clp2 at rebertia.com Sun Feb 7 17:52:38 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Feb 2010 14:52:38 -0800 Subject: passing string for editing in input() In-Reply-To: References: Message-ID: <50697b2c1002071452o685d5054sc94b747676033cee@mail.gmail.com> On Sun, Feb 7, 2010 at 8:24 AM, Aahz wrote: > In article , > Chris Rebert ? wrote: >>On Tue, Feb 2, 2010 at 5:24 AM, mk wrote: >>> >>> Is there an easy way to get an editing (readline) in Python that would >>> contain string for editing and would not just be empty? >>> >>> I googled but found nothing. >> >>Er...: http://docs.python.org/library/readline.html >>It's the third hit for "python readline". >> >>Actually reading the page, sounds like you want readline.insert_text() >>specifically. > > That seems a tad harsh, especially after reading the docs and following > Peter Otten's link. ?It's not at all obvious how to actually use > insert_text(), and although I probably could have figured it out on my > own, I might well have posted here myself. ?Did you try using > insert_text() before posting? No; I've never used the readline module for that matter. I was just giving a (hopefully helpful) suggestion based on a quick scan of the docs (hence the tentative "sounds like"). The OP's comment about finding /nothing/ on Google made it sound as though they hadn't located/checked the readline module docs. In retrospect, I might have misinterpreted in that regard; but in my defense, if they did check the docs, it might have been good to say so, and if they had found insert_text(), they ought to have made their question more specific. Cheers, Chris From python.list at tim.thechases.com Sun Feb 7 18:01:24 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 07 Feb 2010 17:01:24 -0600 Subject: question on using tarfile to read a *.tar.gzip file In-Reply-To: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> References: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> Message-ID: <4B6F4644.60201@tim.thechases.com> > Is there a way to do this, without decompressing each file to a temp > dir? Like is there a method using some tarfile interface adapter to > read a compressed file? Otherwise I'll just access each file, extract > it, grab the 1st and last lines and then delete the temp file. I think you're looking for the extractfile() method of the TarFile object: from glob import glob from tarfile import TarFile for fname in glob('*.tgz'): print fname tf = TarFile.gzopen(fname) for ti in tf: print ' %s' % ti.name f = tf.extractfile(ti) if not f: continue fi = iter(f) # f doesn't natively support next() first_line = fi.next() for line in fi: pass f.close() print " First line: %r" % first_line print " Last line: %r" % line tf.close() If you just want the first & last lines, it's a little more complex if you don't want to scan the entire file (like I do with the for-loop), but the file-like object returned by extractfile() is documented as supporting seek() so you can skip to the end and then read backwards until you have sufficient lines. I wrote a "get the last line of a large file using seeks from the EOF" function which you can find at [1] which should handle the odd edge cases of $BUFFER_SIZE containing more or less than a full line and then reading backwards in chunks (if needed) until you have one full line, handling a one-line file, and other odd/annoying edge-cases. Hope it helps. -tkc [1] http://mail.python.org/pipermail/python-list/2009-January/1186176.html From james.harris.1 at googlemail.com Sun Feb 7 18:09:15 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Sun, 7 Feb 2010 15:09:15 -0800 (PST) Subject: Available for use: Tabs management software References: Message-ID: <5e9b7d2a-a1dc-4a73-a3f6-4acc4dcb6fc5@b10g2000yqa.googlegroups.com> On 7 Feb, 21:25, James Harris wrote: > In case someone else finds it useful here is a program I wrote a year > or so ago to help manage tab characters. It will convert tabs to runs > of spaces, convert runs of spaces to tabs, or count or check for tab > characters as required. It supports tab stops at regular and irregular > positions. > > ?http://codewiki.wikispaces.com/tabs.py > > It is written in Python and you can either use it from the command > line or call the functions from another Python script. Documentation > is included on the web page. After posting this I realised the code had a dependence on a separate debugging module. I've commented-out all such references and tested it in isolation from other code. Everything behaved as it should so if you download it you should find it just works. The only dependence is on Python (i.e. Python 2.x; I gather 3.x needs print statements and maybe other stuff to be changed). Any issues, feel free to post them here. James From nobody at nowhere.com Sun Feb 7 18:55:52 2010 From: nobody at nowhere.com (Nobody) Date: Sun, 07 Feb 2010 23:55:52 +0000 Subject: TABS in the CPython C source code References: Message-ID: On Sun, 07 Feb 2010 05:49:28 +0000, Nobody wrote: >> The size-8 tabs look really bad in an editor configured with tab size 4, >> as is common in Windows. I'm concluding that the CPython programmers >> configure their Visual Studio's to *nix convention. > > 8-column tabs aren't a "*nix convention"; that's been the norm since > the mechanical typewriter. Okay, as everyone has pointed out, it's not quite that old. I've seen typewriters with fixed tabs, but I'm not certain that they were at 8 columns, and even if they were, it wasn't common enough to be a standard. From as at sci.fi Sun Feb 7 19:21:17 2010 From: as at sci.fi (Anssi Saari) Date: Mon, 08 Feb 2010 02:21:17 +0200 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: Julian writes: > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". Thanks for the hint, interesting stuff in there. > For those guys would be a poster quite cool which describes the most > popular and beloved python features. For me as an electronics HW guy, I really like that I can easily handle binary data without doing tedious and error prone shifting and anding and oring. From ahleniusm at gmail.com Sun Feb 7 19:25:50 2010 From: ahleniusm at gmail.com (m_ahlenius) Date: Sun, 7 Feb 2010 16:25:50 -0800 (PST) Subject: question on using tarfile to read a *.tar.gzip file References: <0a75116c-345f-461c-a9d4-ae89edf556cf@z26g2000yqm.googlegroups.com> Message-ID: <56cb4ae5-7a8d-4571-a9f2-57f3c7500664@v25g2000yqk.googlegroups.com> On Feb 7, 5:01?pm, Tim Chase wrote: > > Is there a way to do this, without decompressing each file to a temp > > dir? ?Like is there a method using some tarfile interface adapter to > > read a compressed file? ?Otherwise I'll just access each file, extract > > it, ?grab the 1st and last lines and then delete the temp file. > > I think you're looking for the extractfile() method of the > TarFile object: > > ? ?from glob import glob > ? ?from tarfile import TarFile > ? ?for fname in glob('*.tgz'): > ? ? ?print fname > ? ? ?tf = TarFile.gzopen(fname) > ? ? ?for ti in tf: > ? ? ? ?print ' %s' % ti.name > ? ? ? ?f = tf.extractfile(ti) > ? ? ? ?if not f: continue > ? ? ? ?fi = iter(f) # f doesn't natively support next() > ? ? ? ?first_line = fi.next() > ? ? ? ?for line in fi: pass > ? ? ? ?f.close() > ? ? ? ?print " ?First line: %r" % first_line > ? ? ? ?print " ?Last line: %r" % line > ? ? ?tf.close() > > If you just want the first & last lines, it's a little more > complex if you don't want to scan the entire file (like I do with > the for-loop), but the file-like object returned by extractfile() > is documented as supporting seek() so you can skip to the end and > then read backwards until you have sufficient lines. ?I wrote a > "get the last line of a large file using seeks from the EOF" > function which you can find at [1] which should handle the odd > edge cases of $BUFFER_SIZE containing more or less than a full > line and then reading backwards in chunks (if needed) until you > have one full line, handling a one-line file, and other > odd/annoying edge-cases. ?Hope it helps. > > -tkc > > [1]http://mail.python.org/pipermail/python-list/2009-January/1186176.html Thanks Tim - this was very helpful. Just learning about tarfile. 'mark From escalation746 at yahoo.com Sun Feb 7 19:26:25 2010 From: escalation746 at yahoo.com (escalation746) Date: Sun, 7 Feb 2010 16:26:25 -0800 (PST) Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 Message-ID: I am having a heck of a time doing the simplest thing: installing Python and the pywin extensions, including the PythonWin editor I have always relied on, into my new Windows 7 Professional 64-bit OS. I tried the Python package from python.org and pywin32 from sourceforge. But the latter would not install, saying that it could not find Python 2.6 in the registry. And apparently it will not let me specify the location of same, although a dialogue window tantalises me with blank text boxes I cannot type into. I then tried the 64-bit version of ActiveState's Python, but this installed sans the PythonWin editor, apparently. At least I cannot find it either in the Start menu or in the Python folder. What am I missing? What have I not been told? -- robin From apt.shansen at gmail.com Sun Feb 7 19:55:05 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 7 Feb 2010 16:55:05 -0800 Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 In-Reply-To: References: Message-ID: <7a9c25c21002071655h4a4076e7tb9f94e92a78a3273@mail.gmail.com> On Sun, Feb 7, 2010 at 4:26 PM, escalation746 wrote: > I am having a heck of a time doing the simplest thing: installing > Python and the pywin extensions, including the PythonWin editor I have > always relied on, into my new Windows 7 Professional 64-bit OS. I > tried the Python package from python.org and pywin32 from sourceforge. > But the latter would not install, saying that it could not find Python > 2.6 in the registry. And apparently it will not let me specify the > location of same, although a dialogue window tantalises me with blank > text boxes I cannot type into. > Saying, "the Python package from python.org" is insufficiently specific; are you sure you got the 64-bit version of BOTH packages? If you install 64-bit Python, any extensions must also be 64-bit. If you look at http://sourceforge.net/projects/pywin32/files/ you'll notice separate builds for 64-bit, marked amd64. Are you sure you got the pywin32-214.win-amd64-py2.6.exe and not the normal one? Alternatively, you can just get the 32-bit version of both and install them. But you can't mix and match, 32-bit one, 64-bit the other, in that case they won't find each-other. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From andrej.mitrovich at gmail.com Sun Feb 7 19:57:01 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Sun, 7 Feb 2010 16:57:01 -0800 (PST) Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 References: Message-ID: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> On Feb 8, 1:26?am, escalation746 wrote: > I am having a heck of a time doing the simplest thing: installing > Python and the pywin extensions, including the PythonWin editor I have > always relied on, into my new Windows 7 Professional 64-bit OS. I > tried the Python package from python.org and pywin32 from sourceforge. > But the latter would not install, saying that it could not find Python > 2.6 in the registry. And apparently it will not let me specify the > location of same, although a dialogue window tantalises me with blank > text boxes I cannot type into. > > I then tried the 64-bit version of ActiveState's Python, but this > installed sans the PythonWin editor, apparently. At least I cannot > find it either in the Start menu or in the Python folder. > > What am I missing? What have I not been told? > > -- robin Perhaps you've accidentally downloaded the wrong version of PythonWin? I think this should be the one: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win-amd64-py2.6.exe/download From misceverything at gmail.com Sun Feb 7 19:57:36 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 16:57:36 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> Message-ID: <811dd4e9-6eea-4c1f-a24b-ba0179e57f84@a13g2000vbf.googlegroups.com> Thanks for the suggestions - I think my next step is to try running it under an admin user account, as you guys both mentioned. Alf - you're absolutely right, Microsoft has srvany.exe, which allows you to run any EXE as a Windows service. I've done this in the past, but it's more of a "hack"..so this go around (since I will be distributing this program), I wanted to go the more professional route..which, unfortunately, involves learning the "scum". :) I posted this to comp.os.ms-windows.programmer.win32, so we'll see if what the Win32 programmers have to say as well. Thanks again! From escalation746 at yahoo.com Sun Feb 7 20:02:33 2010 From: escalation746 at yahoo.com (escalation746) Date: Sun, 7 Feb 2010 17:02:33 -0800 (PST) Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 References: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> Message-ID: <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> Andrej Mitrovic wrote: > Perhaps you've accidentally downloaded the wrong version of PythonWin? Erk, yes, my bad. Thanks for the quick help! Though I still wonder why the ActiveState build does not include this. -- robin From misceverything at gmail.com Sun Feb 7 20:05:39 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 17:05:39 -0800 (PST) Subject: Modifying Class Object Message-ID: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Ok, just looking for a sanity check here, or maybe something I'm missing. I have a class Test, for example: class Test: def __init__(self, param1, param2, param3): self.param1 = param1 self.param2 = param2 self.param3 = param3 Next, I have a dictionary mytest that contains instances of Test. If I want to modify one of the Test instances within my dictionary, I have to rewrite the entire entry, correct (since Python passes by value, not reference)? I.e. if I wish to change just param3 of an instance, I would have to do: def changevalue(): for key in mytest.keys(): currentparam = mytest[key] param1 = currentparam.param1 param2 = currentparam.param2 param3 = currentparam.param3 param3 = "newvalue" mytest[key] = Test(param1, param2, param3) If there's an easier way to accomplish this that I'm missing, that'd be great! From clp2 at rebertia.com Sun Feb 7 20:16:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Feb 2010 17:16:19 -0800 Subject: Modifying Class Object In-Reply-To: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <50697b2c1002071716k26062ba9h640835149f34c6e9@mail.gmail.com> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: > Ok, just looking for a sanity check here, or maybe something I'm > missing. ?I have a class Test, for example: > > class Test: > ? ?def __init__(self, param1, param2, param3): > ? ? ? ?self.param1 = param1 > ? ? ? ?self.param2 = param2 > ? ? ? ?self.param3 = param3 > > Next, I have a dictionary mytest that contains instances of Test. ?If > I want to modify one of the Test instances within my dictionary, I > have to rewrite the entire entry, correct (since Python passes by > value, not reference)? Incorrect; Python uses neither. See http://effbot.org/zone/call-by-object.htm for a excellent explanation of what Python does use. > I.e. if I wish to change just param3 of an > instance, I would have to do: > > def changevalue(): > ? ?for key in mytest.keys(): > ? ? ? ?currentparam = mytest[key] > ? ? ? ?param1 = currentparam.param1 > ? ? ? ?param2 = currentparam.param2 > ? ? ? ?param3 = currentparam.param3 > ? ? ? ?param3 = "newvalue" > ? ? ? ?mytest[key] = Test(param1, param2, param3) > > If there's an easier way to accomplish this that I'm missing, that'd > be great! def changevalue(): for test in mytest.values(): test.param3 = "newvalue" Cheers, Chris -- http://blog.rebertia.com From steve at holdenweb.com Sun Feb 7 20:19:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 20:19:53 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <00f8becc$0$15628$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <00f8becc$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B6F66B9.2060801@holdenweb.com> Steven D'Aprano wrote: > On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: > >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( > > Oh, everybody expects parrots! That's not unexpected -- as a clue, I > wrote that "the message is predictable for being totally unexpected". > > The input was "Nobody expects the Spanish Inquisition!", which is another > Monty Python catchphrase. > > Bugger - Got everything except the trailing exclamation mark ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Sun Feb 7 20:19:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 20:19:53 -0500 Subject: How to print all expressions that match a regular expression In-Reply-To: <00f8becc$0$15628$c3e8da3@news.astraweb.com> References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <00f8becc$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B6F66B9.2060801@holdenweb.com> Steven D'Aprano wrote: > On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: > >>> "Given the function hashlib.sha256, enumerate all the possible inputs >>> that give the hexadecimal result >>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >> I tried some "parrot" variants but no dice. :-( > > Oh, everybody expects parrots! That's not unexpected -- as a clue, I > wrote that "the message is predictable for being totally unexpected". > > The input was "Nobody expects the Spanish Inquisition!", which is another > Monty Python catchphrase. > > Bugger - Got everything except the trailing exclamation mark ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From misceverything at gmail.com Sun Feb 7 20:24:13 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 17:24:13 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Feb 7, 8:16?pm, Chris Rebert wrote: > On Sun, Feb 7, 2010 at 5:05 PM, T wrote: > > Ok, just looking for a sanity check here, or maybe something I'm > > missing. ?I have a class Test, for example: > > > class Test: > > ? ?def __init__(self, param1, param2, param3): > > ? ? ? ?self.param1 = param1 > > ? ? ? ?self.param2 = param2 > > ? ? ? ?self.param3 = param3 > > > Next, I have a dictionary mytest that contains instances of Test. ?If > > I want to modify one of the Test instances within my dictionary, I > > have to rewrite the entire entry, correct (since Python passes by > > value, not reference)? > > Incorrect; Python uses neither. Seehttp://effbot.org/zone/call-by-object.htmfor a excellent explanation > of what Python does use. > > > I.e. if I wish to change just param3 of an > > instance, I would have to do: > > > def changevalue(): > > ? ?for key in mytest.keys(): > > ? ? ? ?currentparam = mytest[key] > > ? ? ? ?param1 = currentparam.param1 > > ? ? ? ?param2 = currentparam.param2 > > ? ? ? ?param3 = currentparam.param3 > > ? ? ? ?param3 = "newvalue" > > ? ? ? ?mytest[key] = Test(param1, param2, param3) > > > If there's an easier way to accomplish this that I'm missing, that'd > > be great! > > def changevalue(): > ? ? for test in mytest.values(): > ? ? ? ? test.param3 = "newvalue" > > Cheers, > Chris > --http://blog.rebertia.com Thanks so much - this makes life a lot easier! And a great reference as well. Cheers, Doug From steve at holdenweb.com Sun Feb 7 20:31:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 20:31:31 -0500 Subject: Modifying Class Object In-Reply-To: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: T wrote: > Ok, just looking for a sanity check here, or maybe something I'm > missing. I have a class Test, for example: > > class Test: > def __init__(self, param1, param2, param3): > self.param1 = param1 > self.param2 = param2 > self.param3 = param3 > > Next, I have a dictionary mytest that contains instances of Test. If > I want to modify one of the Test instances within my dictionary, I > have to rewrite the entire entry, correct (since Python passes by > value, not reference)? I.e. if I wish to change just param3 of an > instance, I would have to do: > > def changevalue(): > for key in mytest.keys(): > currentparam = mytest[key] > param1 = currentparam.param1 > param2 = currentparam.param2 > param3 = currentparam.param3 > param3 = "newvalue" > mytest[key] = Test(param1, param2, param3) > > If there's an easier way to accomplish this that I'm missing, that'd > be great! def changevalue(): for key in mytest.keys(): mytest[key].param3 = "newvalue" regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Sun Feb 7 20:32:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Feb 2010 02:32:31 +0100 Subject: python admin abuse complaint In-Reply-To: References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: <4B6F69AF.8050200@sequans.com> Steve Holden wrote: > Shashwat Anand wrote: > >> LOL >> pow(funny, sys.maxint) >> >> > Yes, funny, but it overlooks the point that Xah is a nuisance to > multiple communities, not just to ours, and quite often concurrently. > > I'm all in favor of tolerance, but I'd like to see some evidence that > rehabilitation is practical before the community has to tolerate too > much of that kind of nonsense. > > regards > Steve > Actually for one Xah post I get, I then get 20 mails complaining about him. The fact is, for someone like me who subscribed only to the python list (what's the purpose of subscribing the perl list when you know about python existence btw :o) ), the real annoying spam comes from the complains, not Xah. Speaking for myself, I may get 3 or 4 posts from Xah a month at most. Something I can live with. So guys, just ignore him if you don't like him. Mailers & news readers have plenty of feature to make it happen. Adding my contribution to complains... JM From python at mrabarnett.plus.com Sun Feb 7 20:48:21 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 01:48:21 +0000 Subject: python admin abuse complaint In-Reply-To: <4B6F69AF.8050200@sequans.com> References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> <4B6F69AF.8050200@sequans.com> Message-ID: <4B6F6D65.7030408@mrabarnett.plus.com> Jean-Michel Pichavant wrote: > Steve Holden wrote: >> Shashwat Anand wrote: >> >>> LOL >>> pow(funny, sys.maxint) >>> >>> >> Yes, funny, but it overlooks the point that Xah is a nuisance to >> multiple communities, not just to ours, and quite often concurrently. >> >> I'm all in favor of tolerance, but I'd like to see some evidence that >> rehabilitation is practical before the community has to tolerate too >> much of that kind of nonsense. >> >> regards >> Steve >> > Actually for one Xah post I get, I then get 20 mails complaining about > him. The fact is, for someone like me who subscribed only to the python > list (what's the purpose of subscribing the perl list when you know > about python existence btw :o) ), the real annoying spam comes from the > complains, not Xah. Speaking for myself, I may get 3 or 4 posts from Xah > a month at most. Something I can live with. > > So guys, just ignore him if you don't like him. Mailers & news readers > have plenty of feature to make it happen. > > Adding my contribution to complains... > Alternatively, add [XAH] to the subject in the replies so that they can be filtered out easily. :-) From alfps at start.no Sun Feb 7 20:51:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 02:51:05 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Chris Rebert: > On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >> Ok, just looking for a sanity check here, or maybe something I'm >> missing. I have a class Test, for example: >> >> class Test: >> def __init__(self, param1, param2, param3): >> self.param1 = param1 >> self.param2 = param2 >> self.param3 = param3 >> >> Next, I have a dictionary mytest that contains instances of Test. If >> I want to modify one of the Test instances within my dictionary, I >> have to rewrite the entire entry, correct (since Python passes by >> value, not reference)? > > Incorrect; Python uses neither. See > http://effbot.org/zone/call-by-object.htm for a excellent explanation > of what Python does use. Hm. While most everything I've seen at effbot.org has been clear and to the point, that particular article reads like a ton of obfuscation. Python passes pointers by value, just as e.g. Java does. There, it needed just 10 words or so. :-) Or perhaps some more words to point out that in the Java language spec those reference values are called pointers, but that this terminology isn't (apparently) used for Python, and isn't even well known among Java programmers. But that's just one extra little para. One just has to be clear about exactly what it is that's passed by value. Not Python objects, but references (pointers) to them, the id(o) values. >> I.e. if I wish to change just param3 of an >> instance, I would have to do: >> >> def changevalue(): >> for key in mytest.keys(): >> currentparam = mytest[key] >> param1 = currentparam.param1 >> param2 = currentparam.param2 >> param3 = currentparam.param3 >> param3 = "newvalue" >> mytest[key] = Test(param1, param2, param3) >> >> If there's an easier way to accomplish this that I'm missing, that'd >> be great! > > def changevalue(): > for test in mytest.values(): > test.param3 = "newvalue" Cheers, - Alf From python at mrabarnett.plus.com Sun Feb 7 21:07:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 02:07:55 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <4B6F71FB.6060709@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Chris Rebert: >> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>> Ok, just looking for a sanity check here, or maybe something I'm >>> missing. I have a class Test, for example: >>> >>> class Test: >>> def __init__(self, param1, param2, param3): >>> self.param1 = param1 >>> self.param2 = param2 >>> self.param3 = param3 >>> >>> Next, I have a dictionary mytest that contains instances of Test. If >>> I want to modify one of the Test instances within my dictionary, I >>> have to rewrite the entire entry, correct (since Python passes by >>> value, not reference)? >> >> Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> of what Python does use. > > Hm. While most everything I've seen at effbot.org has been clear and to > the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) Or perhaps some more words to > point out that in the Java language spec those reference values are > called pointers, but that this terminology isn't (apparently) used for > Python, and isn't even well known among Java programmers. But that's > just one extra little para. > > One just has to be clear about exactly what it is that's passed by value. > > Not Python objects, but references (pointers) to them, the id(o) values. > A reference is not the same as a pointer. A pointer tells you where something is; a reference doesn't. From alfps at start.no Sun Feb 7 21:21:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 03:21:11 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * MRAB: > Alf P. Steinbach wrote: >> * Chris Rebert: >>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>> Ok, just looking for a sanity check here, or maybe something I'm >>>> missing. I have a class Test, for example: >>>> >>>> class Test: >>>> def __init__(self, param1, param2, param3): >>>> self.param1 = param1 >>>> self.param2 = param2 >>>> self.param3 = param3 >>>> >>>> Next, I have a dictionary mytest that contains instances of Test. If >>>> I want to modify one of the Test instances within my dictionary, I >>>> have to rewrite the entire entry, correct (since Python passes by >>>> value, not reference)? >>> >>> Incorrect; Python uses neither. See >>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>> of what Python does use. >> >> Hm. While most everything I've seen at effbot.org has been clear and >> to the point, that particular article reads like a ton of obfuscation. >> >> Python passes pointers by value, just as e.g. Java does. >> >> There, it needed just 10 words or so. :-) Or perhaps some more words >> to point out that in the Java language spec those reference values are >> called pointers, but that this terminology isn't (apparently) used for >> Python, and isn't even well known among Java programmers. But that's >> just one extra little para. >> >> One just has to be clear about exactly what it is that's passed by value. >> >> Not Python objects, but references (pointers) to them, the id(o) values. >> > A reference is not the same as a pointer. Depends on your choice terminology. I referred to the Java (language spec) terminology to make it clear. > A pointer tells you where something is; a reference doesn't. Sorry, I don't know of any relevant terminology where that is the case. Cheers & hth., - Alf From steven at REMOVE.THIS.cybersource.com.au Sun Feb 7 21:33:12 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 02:33:12 GMT Subject: How to print all expressions that match a regular expression References: <037df4ef$0$1292$c3e8da3@news.astraweb.com> <037e0381$0$1292$c3e8da3@news.astraweb.com> <00f8becc$0$15628$c3e8da3@news.astraweb.com> Message-ID: On Sun, 07 Feb 2010 20:19:53 -0500, Steve Holden wrote: > Steven D'Aprano wrote: >> On Sun, 07 Feb 2010 03:53:49 +0100, Alf P. Steinbach wrote: >> >>>> "Given the function hashlib.sha256, enumerate all the possible inputs >>>> that give the hexadecimal result >>>> 0a2591aaf3340ad92faecbc5908e74d04b51ee5d2deee78f089f1607570e2e91." >>> I tried some "parrot" variants but no dice. :-( >> >> Oh, everybody expects parrots! That's not unexpected -- as a clue, I >> wrote that "the message is predictable for being totally unexpected". >> >> The input was "Nobody expects the Spanish Inquisition!", which is >> another Monty Python catchphrase. >> >> > Bugger - Got everything except the trailing exclamation mark ... NOBODY EXPECTS THE TRAILING EXCLAMATION MARK!!! -- Steven From schifschaf at gmail.com Sun Feb 7 22:00:40 2010 From: schifschaf at gmail.com (Schif Schaf) Date: Sun, 7 Feb 2010 19:00:40 -0800 (PST) Subject: Help with regex search-and-replace (Perl to Python) References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> <4B6EC203.4040807@holdenweb.com> Message-ID: <06a91472-3974-45d3-b86a-c3c9055a5831@z26g2000yqm.googlegroups.com> On Feb 7, 8:57?am, Tim Chase wrote: > Steve Holden wrote: > > > Really? Under what circumstances does a simple one-for-one character > > replacement operation fail? > > Failure is only defined in the clarified context of what the OP > wants :) ?Replacement operations only fail if the OP's desired > output from the above mess doesn't change *all* of the ]/[ > characters, but only those with some form of parity (nested or > otherwise). ?But if the OP *does* want all of the ]/[ characters > replaced regardless of contextual nature, then yes, replace is a > much better solution than regexps. > I need to do the usual "pipe text through and do various search/ replace" thing fairly often. The above case of having to replace brackets with braces is only one example. Simple string methods run out of steam pretty quickly and much of my work relies on using regular expressions. Yes, I try to keep focused on simplicity, and often regexes are the simplest solution for my day-to-day needs. From steve at holdenweb.com Sun Feb 7 22:03:06 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 07 Feb 2010 22:03:06 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * MRAB: >> Alf P. Steinbach wrote: >>> * Chris Rebert: >>>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>>> Ok, just looking for a sanity check here, or maybe something I'm >>>>> missing. I have a class Test, for example: >>>>> >>>>> class Test: >>>>> def __init__(self, param1, param2, param3): >>>>> self.param1 = param1 >>>>> self.param2 = param2 >>>>> self.param3 = param3 >>>>> >>>>> Next, I have a dictionary mytest that contains instances of Test. If >>>>> I want to modify one of the Test instances within my dictionary, I >>>>> have to rewrite the entire entry, correct (since Python passes by >>>>> value, not reference)? >>>> >>>> Incorrect; Python uses neither. See >>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>>> of what Python does use. >>> >>> Hm. While most everything I've seen at effbot.org has been clear and >>> to the point, that particular article reads like a ton of obfuscation. >>> >>> Python passes pointers by value, just as e.g. Java does. >>> >>> There, it needed just 10 words or so. :-) Or perhaps some more words >>> to point out that in the Java language spec those reference values >>> are called pointers, but that this terminology isn't (apparently) >>> used for Python, and isn't even well known among Java programmers. >>> But that's just one extra little para. >>> >>> One just has to be clear about exactly what it is that's passed by >>> value. >>> >>> Not Python objects, but references (pointers) to them, the id(o) values. >>> >> A reference is not the same as a pointer. > > Depends on your choice terminology. I referred to the Java (language > spec) terminology to make it clear. > > >> A pointer tells you where something is; a reference doesn't. > > Sorry, I don't know of any relevant terminology where that is the case. > Alf: This topic was discussed at great, nay interminable, length about a year ago. I'd appreciate it if you would search the archives and read what was said then rather than hashing the whole topic over again to nobody's real advantage. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Sun Feb 7 22:10:06 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 7 Feb 2010 19:10:06 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <7a9c25c21002071910p462a2ddckc5d54de48cbeb97f@mail.gmail.com> On Sun, Feb 7, 2010 at 5:51 PM, Alf P. Steinbach wrote: > Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> >> of what Python does use. >> > > Hm. While most everything I've seen at effbot.org has been clear and to > the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) Or perhaps some more words to > point out that in the Java language spec those reference values are called > pointers, but that this terminology isn't (apparently) used for Python, and > isn't even well known among Java programmers. But that's just one extra > little para. > One just has to be clear about exactly what it is that's passed by value. > > Not Python objects, but references (pointers) to them, the id(o) values. > Sigh. Why does this always come up? And then someone makes a statement like this, and now a /very/ long thread in which everyone argues semantics will begin and sooner or later, the presence of the GIL will cause a Python civil war, even though the GIL has nothing to do with anything related to this conversation. Mark my words! Python only passes by value if you use a non-standard definition of "value": and the moment you do that, a whole bunch of people will start making weird assumptions of Python's object and scoping semantics and all kinds of confusion will occur. Or holy wars on words shall come to pass. Python does not have pointers, it is not passing a pointer, it is passing an object. The moment you start talking about passing pointers, people start expecting things to work as if they -were- pointers. Python objects don't. Python has names, and objects. It passes objects. Those objects get a new name as a result. If the object is mutable, changes will be seen by the caller. If the object is not, changes won't (because you're re-binding a name, not changing an object). Any attempt to apply any other sort of words or labels besides "names" and "objects" to the situation is just going to confuse people and make them think Python-is-LanguageXor Python-works-like-LanguageY. Let the argument begin! Again. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptmcg at austin.rr.com Sun Feb 7 22:11:10 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Sun, 7 Feb 2010 19:11:10 -0800 (PST) Subject: How to print all expressions that match a regular expression References: Message-ID: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> On Feb 6, 1:36?pm, "hzh... at gmail.com" wrote: > Hi, > > I am a fresh man with python. I know there is regular expressions in > Python. What I need is that given a particular regular expression, > output all the matches. For example, given ?[1|2|3]{2}? as the regular > expression, the program should output all 9 matches, i.e., "11 12 13 > 21 22 23 31 32 33". > > Is there any well-written routine in Python or third-party program to > do this? If there isn't, could somebody make some suggestions on how > to write it myself? > > Thanks. > > Zhuo Please check out this example on the pyparsing wiki, invRegex.py: http://pyparsing.wikispaces.com/file/view/invRegex.py. This code implements a generator that returns successive matching strings for the given regex. Running it, I see that you actually have a typo in your example. >>> print list(invert("[1|2|3]{2}")) ['11', '1|', '12', '13', '|1', '||', '|2', '|3', '21', '2|', '22', '23', '31', '3|', '32', '33'] I think you meant either "[123]{2}" or "(1|2|3){2}". >>> print list(invert("[123]{2}")) ['11', '12', '13', '21', '22', '23', '31', '32', '33'] >>> print list(invert("(1|2|3){2}")) ['11', '12', '13', '21', '22', '23', '31', '32', '33'] Of course, as other posters have pointed out, this inverter does not accept regexen with unbounded multiple characters '+' or '*', but '?' and "{min,max}" notation will work. Even '.' is supported, although this can generate a large number of return values. Of course, you'll also have to install pyparsing to get this to work. -- Paul From steven at REMOVE.THIS.cybersource.com.au Sun Feb 7 22:14:22 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 03:14:22 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Sun, 07 Feb 2010 22:03:06 -0500, Steve Holden wrote: > Alf: > > This topic was discussed at great, nay interminable, length about a year > ago. I'd appreciate it if you would search the archives and read what > was said then rather than hashing the whole topic over again to nobody's > real advantage. Curse you Steve, I had just come up with a brilliant rebuttal of Alf's position. It was sheer genius, the sort of thing that would have James Gosling weeping with envy. Oh well, into the bitbucket it goes... -- Steven From wuwei23 at gmail.com Sun Feb 7 22:18:33 2010 From: wuwei23 at gmail.com (alex23) Date: Sun, 7 Feb 2010 19:18:33 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: "Alf P. Steinbach" wrote: > Hm. While most everything I've seen at effbot.org has been clear and to the > point, that particular article reads like a ton of obfuscation. Must. Resist. Ad hominem. > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) 10 words _plus_ an understanding of Java. Do you really think its appropriate to discuss Python's behaviour purely in terms of other languages? Further, you've managed to define Python's behaviour as being somehow _both_ of the major evaluation strategies - calling a reference by value - so you're asking people to understand two totally irrelevant models just to avoid describing one in its own terms. Rather than arguing about whether you have a 'value' or a 'reference', it's a lot easier to explain that you're passing mutable & immutable objects around. The behaviour is thus defined in terms of the object and _not_ in the calling model, and is far more consistent with object references throughout the language. It also doesn't require reference to other languages simply to define Python's model in terms of what it isn't. From alfps at start.no Sun Feb 7 22:27:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 04:27:07 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * MRAB: >>> Alf P. Steinbach wrote: >>>> * Chris Rebert: >>>>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>>>> Ok, just looking for a sanity check here, or maybe something I'm >>>>>> missing. I have a class Test, for example: >>>>>> >>>>>> class Test: >>>>>> def __init__(self, param1, param2, param3): >>>>>> self.param1 = param1 >>>>>> self.param2 = param2 >>>>>> self.param3 = param3 >>>>>> >>>>>> Next, I have a dictionary mytest that contains instances of Test. If >>>>>> I want to modify one of the Test instances within my dictionary, I >>>>>> have to rewrite the entire entry, correct (since Python passes by >>>>>> value, not reference)? >>>>> Incorrect; Python uses neither. See >>>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>>>> of what Python does use. >>>> Hm. While most everything I've seen at effbot.org has been clear and >>>> to the point, that particular article reads like a ton of obfuscation. >>>> >>>> Python passes pointers by value, just as e.g. Java does. >>>> >>>> There, it needed just 10 words or so. :-) Or perhaps some more words >>>> to point out that in the Java language spec those reference values >>>> are called pointers, but that this terminology isn't (apparently) >>>> used for Python, and isn't even well known among Java programmers. >>>> But that's just one extra little para. >>>> >>>> One just has to be clear about exactly what it is that's passed by >>>> value. >>>> >>>> Not Python objects, but references (pointers) to them, the id(o) values. >>>> >>> A reference is not the same as a pointer. >> Depends on your choice terminology. I referred to the Java (language >> spec) terminology to make it clear. >> >> >>> A pointer tells you where something is; a reference doesn't. >> Sorry, I don't know of any relevant terminology where that is the case. >> > Alf: > > This topic was discussed at great, nay interminable, length about a year > ago. I'd appreciate it if you would search the archives and read what > was said then rather than hashing the whole topic over again to nobody's > real advantage. Well that's my point, and thanks for backing me up on that :-): it's very simple, and as demonstrated can be expressed in 10 words or less (plus perhaps a terminology reference, as I did above), so all that discussion and in particular the lengthy article at effbot serves as obfuscation and nothing else. By the way, most every programming language has some corner like that, something that is utterly simple but somehow has some kind of obfuscation-meme attached. In C++ it's "call" and "constructor". It doesn't help that the language's standard lays down the law on it, it doesn't help that the language's creator has laid down the law, it doesn't help that it's utterly and completely simple. Somehow newbies and even some experienced people manage to create their own terminological nightmare and drawing conclusions about reality from that misguided obfuscated view, and then discussing it up and down and sideways. Cheers & hth., - Alf From austin.brkich at gmail.com Sun Feb 7 22:56:39 2010 From: austin.brkich at gmail.com (7H3LaughingMan) Date: Sun, 7 Feb 2010 19:56:39 -0800 (PST) Subject: C/C++ Import Message-ID: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> To make the background information short, I am trying to take a program that uses Python for scripting and recompile it for Linux since it originally was built to run on Win32. The program itself was designed to be able to be compiled on Linux and someone made there on release with source that added python scripting. After some issues I got it to compile but now it is unable to import the files that it needs. The program is running the following code... PyImport_Import( PyString_FromString("python.PlayerManager") ); This is meant to import the file PlayerManager.py inside of the python folder. However it throws the following Python Error (Gotten through PyErr_Print()) ImportError: No module named python.PlayerManager I am using 2.6.4 so I can't call it by the filename, does anyone know how to do a proper import? From steven at REMOVE.THIS.cybersource.com.au Sun Feb 7 23:01:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 04:01:05 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Mon, 08 Feb 2010 02:51:05 +0100, Alf P. Steinbach wrote: > Python passes pointers by value, just as e.g. Java does. How do I get a pointer in pure Python code (no ctypes)? I tried both Pascal and C syntax (^x and *x), but both give syntax errors. For that matter, how do I get a pointer in Java code? If Python doesn't have pointers, then why are you talking about Python passing pointers? It's a vacuous truth, like saying that Python passes dinosaurs by name. -- Steven From misceverything at gmail.com Sun Feb 7 23:15:52 2010 From: misceverything at gmail.com (T) Date: Sun, 7 Feb 2010 20:15:52 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> Oops, this one was my fault - the object I was having the issues with was actually a shelve file, not a dictionary..so just re-assigning the variable isn't working, but re-writing the object to the shelve file does. So in this case, is there any way to just change a single value, or am I stuck rewriting the entry? From cjstevens at gmail.com Mon Feb 8 00:08:33 2010 From: cjstevens at gmail.com (Chris Stevens) Date: Mon, 8 Feb 2010 16:08:33 +1100 Subject: Python 2.4 and list of dictionary issues Message-ID: Hi all, I'm a python newbie so please excuse me if I am missing something simple here. I am writing a script which requires a list of dictionaries (originally a dictionary of dictionaries, but I changed it to a list to try and overcome the below problem). Now my understanding is that you create the empty list, then append or add entries to it. Correct? Here is some code: userInfo = [] ... userInfo.append( { 'username' : uidString[0], ... 'failedattempts' : int(0) }) I'm not to sure on the bracketing here, but I have tried many combinations. The issue here is that I get a "IndexError: list index out of range" message on the line "userInfo.append( {" I wrote this script on a box with Python 2.6 and it worked fine. Moving it to a box with 2.4, and I get this error. I can't understand why i'm getting a list index out of range error when trying to append (not reference) a list?? I have also tried "+=", and userInfo(len(userInfo))= .... just get the same error. Could anyone shed some light on this? Thanks, Chris From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 00:12:14 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 05:12:14 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: On Mon, 08 Feb 2010 03:21:11 +0100, Alf P. Steinbach wrote: >> A pointer tells you where something is; a reference doesn't. > > Sorry, I don't know of any relevant terminology where that is the case. Taken from Wikipedia: "A pointer is a simple, less abstracted implementation of the more abstracted reference data type (although it is not as directly usable as a C++ reference)." http://en.wikipedia.org/wiki/Pointer_(computing) In other words, a pointer is a specific type of reference. A reference in turn is an opaque but low-level data type which "refers to" in some way to the data you actually care about. (C++ has a concrete reference type, which is not to be confused with abstract references.) http://en.wikipedia.org/wiki/Reference_(computer_science) Unless otherwise stated, references are opaque and coders need not care how the reference mechanism is implemented, see e.g.: http://www.cocoabuilder.com/archive/cocoa/20777-opaque-reference.html In Python you don't use references directly, there is no reference type or object. You can simulate the semantics of references (but not pointers) by putting your object in a list and passing the list around. -- Steven From alfps at start.no Mon Feb 8 00:12:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 06:12:50 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steven D'Aprano: > On Mon, 08 Feb 2010 02:51:05 +0100, Alf P. Steinbach wrote: > >> Python passes pointers by value, just as e.g. Java does. > > How do I get a pointer in pure Python code (no ctypes)? I tried both > Pascal and C syntax (^x and *x), but both give syntax errors. Well, I don't believe that you tried that. :-) From one point of view it's extremely easy: just create some object, even just type 42 as an integer literal, and you can apply all of Python's pointer operations to the result -- which isn't much, basically just checking for pointer equality via 'is' or applying 'id' to get a value that represents the pointer uniquely, or copying the pointer via assignment or parameter passing. Whether you can obtain the bits of the internal pointer value, represented as e.g. an int, formally depends on the Python implementation. In CPython the 'id' function provides the internal pointer value as an int. I.e., with CPython you can do def foo( o ): print( id( o ) ) # Shows the pointer value in decimal. whatever = 42 print( id( whatever ) ) # Shows the pointer value in decimal. foo( whatever ) # Shows the exact *same* pointer value. which at a slightly higher level of abstraction works just as well with any conceivable Python implementation, although you have no formal guarantee that the conceptual "pointer" values are actually the internally memory addresses. But, in CPython they are, and you run into them all the time, for example (where the "at" tells you that it's a memory location specification, a pointer), >>> import turtle >>> turtle.forward >>> >>> id( turtle.forward ) 14384416 >>> hex( id( turtle.forward ) ) '0xdb7d20' >>> _ > For that matter, how do I get a pointer in Java code? As with Python, from one point of view it's extremely easy, just 'new' some object, and then you can apply all of Java's pure pointer operations to the result -- which isn't much, basically just checking for pointer equality and copying a pointer via assignment or parameter passing. In Java it's a pointer by definition, namely the language spec's definition. From another point of view, getting at the internal representation of the pointer is a bit harder in Java than in Python, at least as far as I know. It may not be practically possible. Disclaimer: I'm not a Java expert, and haven't used Java for years, and it just might be possible by using JNI (Java Native Interface), but that requires you to write a dynamic library in e.g. C or C++, and as I recall Java just creates a kind of fixed reference for the duration of a JNI call so the JNI side of things may not tell you anything about the Java side of things before or after the call. But if it helps, just to learn about pointers in various languages you -- or rather, some other reader, because I suspect that you know this already! :-) -- might look at . It contains a simple pointers example expressed in four different languages, namely C, C++, Pascal and Java, in particular comparing C and Java. > If Python doesn't have pointers, then why are you talking about Python > passing pointers? It's a vacuous truth, like saying that Python passes > dinosaurs by name. See above. Cheers & hth., - Alf From hzhuo1 at gmail.com Mon Feb 8 00:17:59 2010 From: hzhuo1 at gmail.com (hzhuo1 at gmail.com) Date: Sun, 7 Feb 2010 21:17:59 -0800 (PST) Subject: How to print all expressions that match a regular expression References: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> Message-ID: <76609ff4-6579-4b2b-80b7-fb88bd5f1fa7@a32g2000yqm.googlegroups.com> > > Please check out this example on the pyparsing wiki, invRegex.py:http://pyparsing.wikispaces.com/file/view/invRegex.py. ?This code > implements a generator that returns successive matching strings for > the given regex. ?Running it, I see that you actually have a typo in > your example. > > >>> print list(invert("[1|2|3]{2}")) > > ['11', '1|', '12', '13', '|1', '||', '|2', '|3', '21', '2|', '22', > '23', '31', '3|', '32', '33'] > > I think you meant either "[123]{2}" or "(1|2|3){2}". > > >>> print list(invert("[123]{2}")) > > ['11', '12', '13', '21', '22', '23', '31', '32', '33'] > > >>> print list(invert("(1|2|3){2}")) > > ['11', '12', '13', '21', '22', '23', '31', '32', '33'] > > Of course, as other posters have pointed out, this inverter does not > accept regexen with unbounded multiple characters '+' or '*', but '?' > and "{min,max}" notation will work. ?Even '.' is supported, although > this can generate a large number of return values. > > Of course, you'll also have to install pyparsing to get this to work. > > -- Paul Hi Paul, Thanks very much. This is exactly what I need now. I will check this function. Zhuo From alfps at start.no Mon Feb 8 00:18:14 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 06:18:14 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steven D'Aprano: > On Mon, 08 Feb 2010 03:21:11 +0100, Alf P. Steinbach wrote: > >>> A pointer tells you where something is; a reference doesn't. >> Sorry, I don't know of any relevant terminology where that is the case. > > Taken from Wikipedia: > > "A pointer is a simple, less abstracted implementation of the more > abstracted reference data type (although it is not as directly usable as > a C++ reference)." > > http://en.wikipedia.org/wiki/Pointer_(computing) > > In other words, a pointer is a specific type of reference. A reference in > turn is an opaque but low-level data type which "refers to" in some way > to the data you actually care about. (C++ has a concrete reference type, > which is not to be confused with abstract references.) > > http://en.wikipedia.org/wiki/Reference_(computer_science) > > Unless otherwise stated, references are opaque and coders need not care > how the reference mechanism is implemented, see e.g.: > > http://www.cocoabuilder.com/archive/cocoa/20777-opaque-reference.html > > In Python you don't use references directly, there is no reference type > or object. You can simulate the semantics of references (but not > pointers) by putting your object in a list and passing the list around. Yes, sort of. The last paragraph however confuses two different meanings of "reference". So when using terms such as "reference" it helps to refer :-) to some specific terminology, unless that's clearly understood from context. Cheers, - Alf From aahz at pythoncraft.com Mon Feb 8 00:23:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 7 Feb 2010 21:23:51 -0800 Subject: python admin abuse complaint References: <0c535d15-967d-4909-a9bb-b5970818199f@l24g2000prh.googlegroups.com> Message-ID: In article , Jean-Michel Pichavant wrote: > >So guys, just ignore him if you don't like him. Mailers & news readers >have plenty of feature to make it happen. Unfortunately, unless you have a stable group of people with self-control, that doesn't work. Idiots like Xah will always get responses. (This opinion brought to you by two decades of experience with BBS, mailing lists, and Usenet.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From clp2 at rebertia.com Mon Feb 8 00:35:40 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 7 Feb 2010 21:35:40 -0800 Subject: Python 2.4 and list of dictionary issues In-Reply-To: References: Message-ID: <50697b2c1002072135s68fbac3eqab417ff6fa5ac4cc@mail.gmail.com> On Sun, Feb 7, 2010 at 9:08 PM, Chris Stevens wrote: > Hi all, > > I'm a python newbie so please excuse me if I am missing something > simple here. I am writing a script which requires a list of > dictionaries (originally a dictionary of dictionaries, but I changed > it to a list to try and overcome the below problem). > > Now my understanding is that you create the empty list, then append or > add entries to it. Correct? > > Here is some code: > > userInfo = [] > ... > userInfo.append( { > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'username' : uidString[0], > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?... > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'failedattempts' : int(0) > }) > > I'm not to sure on the bracketing here, but I have tried many > combinations. The issue here is that I get a "IndexError: list index > out of range" message on the line "userInfo.append( {" Please include the full and exact error Traceback, and remember to do so in the future. > I wrote this script on a box with Python 2.6 and it worked fine. > Moving it to a box with 2.4, and I get this error. I can't understand > why i'm getting a list index out of range error when trying to append > (not reference) a list?? I have also tried "+=", and > userInfo(len(userInfo))= .... just get the same error. > > Could anyone shed some light on this? I would guess that `uidString` is probably an empty string or list, thus when you try to access the first character or item of it via uidString[0], you get an error. However, as you didn't include a Traceback, I can't be sure. I have no idea why the error only shows itself for certain Python versions; the problem is probably in some part of the code you're not showing us. Cheers, Chris -- http://blog.rebertia.com From danielwong at berkeley.edu Mon Feb 8 01:06:14 2010 From: danielwong at berkeley.edu (danielx) Date: Sun, 7 Feb 2010 22:06:14 -0800 (PST) Subject: convention for documenting function parameters in doc strings Message-ID: Is there a convention for how to document function (or method) parameters in doc strings? Recently, I've been doing alot of PHP programming, and in PHPdoc, you'd do it like this: /* * @param type $foo Description. * * @return type Description. */ function bar($foo) { ... } Is there an equivalent convention I (c|sh)ould be using in my Python docstrings? I saw that Python 3 has function annotations, which could be used for this purpose, but function annotations have no particular purpose within the language itself (which seems like a mistake to me), and they don't exist in the Python 2.x series (at least not the older versions). From gherron at islandtraining.com Mon Feb 8 01:26:14 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 07 Feb 2010 22:26:14 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> Message-ID: <4B6FAE86.2060603@islandtraining.com> Craig Berry wrote: > Can someone please tell me if there's a way to do this, or answer > definitively that there is no way? I have a design in progress that > could really use mousewheel control, and I don't want to settle for > Plan B until I know Plan A is impossible. :) > > On Fri, Feb 5, 2010 at 19:48, Craig Berry wrote: > >> Is there any way to get mouse wheel events from glut in PyOpenGL? >> >> -- >> Craig Berry - http://www.cine.net/~cberry/ >> "Lots of things in the universe don?t solve any problems, and >> nevertheless exist." -- Sean Carroll >> >> > > > > Didn't I answer this already? GLUT on windows usually does not catch mousewheel events for me. (Although it seems to me that is has worked sporadically over past years and versions.) GLUT on Linux does catch wheel events nicely -- but read on anyway... Freeglut (which is open source) is an (almost) direct binary replacement for GLUT, and it *does* catch mousewheel events. (On both Windows and Linux.) Is there a reason this answer is not satisfactory? If you're not *forced* to use GLUT, use FREEGLUT and your problem is solved with no additional work. If you *are* forced to use GLUT, rebel. GLUT has not been maintained for more than 10 years, is showing its age, and is licensed in such a way that you can't modify it. Use FREEGLUT instead: see http://freeglut.sourceforge.net/ From half.italian at gmail.com Mon Feb 8 01:28:19 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sun, 7 Feb 2010 22:28:19 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> <811dd4e9-6eea-4c1f-a24b-ba0179e57f84@a13g2000vbf.googlegroups.com> Message-ID: On Feb 7, 4:57?pm, T wrote: > Thanks for the suggestions - ?I think my next step is to try running > it under an admin user account, as you guys both mentioned. ?Alf - > you're absolutely right, Microsoft has srvany.exe, which allows you to > run any EXE as a Windows service. ?I've done this in the past, but > it's more of a "hack"..so this go around (since I will be distributing > this program), I wanted to go the more professional route..which, > unfortunately, involves learning the "scum". :) ?I ?posted this to > comp.os.ms-windows.programmer.win32, so we'll see if what the Win32 > programmers have to say as well. ?Thanks again! I use windows services and they are very reliable. I would say though that relying on plink.exe is much less reliable than either python or the service that it is running under. Why not take a look at paramiko as the ssh client library? I think it runs under windows. Also perhaps Twisted has something. Either way would be light years ahead of using subprocess with plink. Just my thoughts. ~Sean From austin.bingham at gmail.com Mon Feb 8 01:42:24 2010 From: austin.bingham at gmail.com (Austin Bingham) Date: Mon, 8 Feb 2010 07:42:24 +0100 Subject: C/C++ Import In-Reply-To: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: Does the 'python' directory contain a file named '__init__.py'? This is required to let that directory act as a package (see: http://docs.python.org/tutorial/modules.html#packages); without it, you'll see the symptoms you're seeing. Austin On Mon, Feb 8, 2010 at 4:56 AM, 7H3LaughingMan wrote: > To make the background information short, I am trying to take a > program that uses Python for scripting and recompile it for Linux > since it originally was built to run on Win32. The program itself was > designed to be able to be compiled on Linux and someone made there on > release with source that added python scripting. After some issues I > got it to compile but now it is unable to import the files that it > needs. > > The program is running the following code... > PyImport_Import( PyString_FromString("python.PlayerManager") ); > > This is meant to import the file PlayerManager.py inside of the python > folder. However it throws the following Python Error (Gotten through > PyErr_Print()) > ImportError: No module named python.PlayerManager > > I am using 2.6.4 so I can't call it by the filename, does anyone know > how to do a proper import? > -- > http://mail.python.org/mailman/listinfo/python-list > From cdberry at gmail.com Mon Feb 8 01:45:44 2010 From: cdberry at gmail.com (Craig Berry) Date: Sun, 7 Feb 2010 22:45:44 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <4B6FAE86.2060603@islandtraining.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> Message-ID: <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> On Sun, Feb 7, 2010 at 22:26, Gary Herron wrote: > Didn't I answer this already? If you did, for whatever reason I didn't see it; I just rechecked my inbox to be sure. Thanks for doing so again! I assume, given the list we're on, that Freeglut can be used with Python. I'll look into it. Thanks for the pointer! -- Craig Berry - http://www.cine.net/~cberry/ "Lots of things in the universe don?t solve any problems, and nevertheless exist." -- Sean Carroll From arnodel at googlemail.com Mon Feb 8 02:19:59 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 08 Feb 2010 07:19:59 +0000 Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: "Alf P. Steinbach" writes: > * Chris Rebert: >> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>> Ok, just looking for a sanity check here, or maybe something I'm >>> missing. I have a class Test, for example: >>> >>> class Test: >>> def __init__(self, param1, param2, param3): >>> self.param1 = param1 >>> self.param2 = param2 >>> self.param3 = param3 >>> >>> Next, I have a dictionary mytest that contains instances of Test. If >>> I want to modify one of the Test instances within my dictionary, I >>> have to rewrite the entire entry, correct (since Python passes by >>> value, not reference)? >> >> Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> of what Python does use. > > Hm. While most everything I've seen at effbot.org has been clear and > to the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. Please! Not this again! This has been discussed to death and beyond more than enough times. Go search the c.l.p archives, read it all, and I'm sure you won't want to add anything anymore. -- Arnaud From grflanagan at gmail.com Mon Feb 8 03:02:43 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 08 Feb 2010 08:02:43 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Arnaud Delobelle wrote: > "Alf P. Steinbach" writes: > >> * Chris Rebert: >>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>> Ok, just looking for a sanity check here, or maybe something I'm >>>> missing. I have a class Test, for example: >>>> >>>> class Test: >>>> def __init__(self, param1, param2, param3): >>>> self.param1 = param1 >>>> self.param2 = param2 >>>> self.param3 = param3 >>>> >>>> Next, I have a dictionary mytest that contains instances of Test. If >>>> I want to modify one of the Test instances within my dictionary, I >>>> have to rewrite the entire entry, correct (since Python passes by >>>> value, not reference)? >>> Incorrect; Python uses neither. See >>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>> of what Python does use. >> Hm. While most everything I've seen at effbot.org has been clear and >> to the point, that particular article reads like a ton of obfuscation. >> >> Python passes pointers by value, just as e.g. Java does. > > > Please! Not this again! This has been discussed to death and beyond more > than enough times. Go search the c.l.p archives, read it all, and I'm > sure you won't want to add anything anymore. > +1 !! From rogerb at rogerbinns.com Mon Feb 8 03:11:22 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 08 Feb 2010 00:11:22 -0800 Subject: SQLite3: preventing new file creation In-Reply-To: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> References: <6cf467a9-99d7-4fda-99da-075b4b38e3e0@k6g2000prg.googlegroups.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gnarlodious wrote: > Every time I say something like: > > connection=sqlite3.connect(file) > > sqlite creates a new database file. Can this behavior be suppressed > through SQLite? Or am I forced to check for the file existing first? This is due to the API that pysqlite uses to talk to SQLite. (There is a more recent API but pysqlite remains backwards compatible with older SQLite versions). Note that although SQLite will create the file, it will be zero length (*) until you do a command that causes a database change. Also as a guideline be careful with SQLite files. In particular not only is there a database file, but there may also be a journal file. If the journal is removed then the main database file can be corrupted. (The journal contains data in order to rollback back incomplete transactions from the database.) (*) On Mac due to an operating system bug the file will actually be created as one byte in length containing the upper case letter 'S'. There is a dedicated mailing list for Python and SQLite: http://groups.google.com/group/python-sqlite You can use the newer SQLite database open API as well as many other SQLite APIs not supported by pysqlite by using APSW. (Disclaimer: I am the author of APSW.) Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAktvxyoACgkQmOOfHg372QQjqwCglx0u6OgGgOsQm0Bwd7s6BmCS 7EgAoKDdMZyDaw3Ov+Uqzs3RFX/NSHEK =/E0N -----END PGP SIGNATURE----- From rogerb at rogerbinns.com Mon Feb 8 03:16:35 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 08 Feb 2010 00:16:35 -0800 Subject: execute sqlite3 dot commands in python In-Reply-To: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 gintare statkute wrote: > Does anybody know if it possible to execute sqlite3 dot commands in python? The dot commands are parsed and executed by different code not part of the standard SQLite library. However if you want interactive shell functionality from Python then you can use APSW. It includes a shell you can just go ahead and use based on a shell class you can extend with your own methods, direct input and output as needed, completion etc. http://apsw.googlecode.com/svn/publish/shell.html (Disclaimer: I am the APSW author) Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAktvyGMACgkQmOOfHg372QT5mgCgrMCtb3bHd3rF0L+lL/nZV6BX zrMAn1fcxS4CyKYF4KXVBcVcEXWhxoig =hpkY -----END PGP SIGNATURE----- From petef4+usenet at gmail.com Mon Feb 8 03:27:52 2010 From: petef4+usenet at gmail.com (Pete Forman) Date: Mon, 08 Feb 2010 08:27:52 +0000 Subject: xmlrpc slow in windows 7 if hostnames are used References: <4b6b4b6c$0$23902$426a74cc@news.free.fr> <4b6be08f$0$10133$426a74cc@news.free.fr> <4b6c9b28$0$10494$426a74cc@news.free.fr> <4B6E1444.9060001@sequans.com> Message-ID: "Gabriel Genellina" writes: > En Sat, 06 Feb 2010 22:15:48 -0300, Jean-Michel Pichavant > escribi?: > >> I'm puzzled. >> Unless my english is failing me, everything would be solved using >> hostnames if I follow you. Why don't you do that ? >> I am no network/IP guru, but it sounds very weird to have requests >> rejected when using IP addresses. Are you sure your host names are >> resolved with the same IPM address you are using ? > > HTTP 1.1 requires a Host: header field; this way, multiple web > servers may share the same IP address. So you can't identify a host > by its IP alone; the host name is required. This was devised in > order to save IPv4 addresses; LACNIC (the Latin America addresses > register) does not assign addresses to ISP's based solely on web > hosting anymore - they MUST share existing IPs. And I think a > similar policy is used on other regions. If you really want to go for speed you should be able to set the Host: header to the name but use the IP address to make the connection. Something else that might be slowing you down is anti-spyware or anti-virus. Several products put a long list of blacklist sites in the hosts file. Windows can be rather slow to process that file. -- Pete Forman -./\.- West Sussex, UK -./\.- http://petef.22web.net -./\.- petef4+usenet at gmail.com -./\.- From anthra.norell at bluewin.ch Mon Feb 8 03:30:51 2010 From: anthra.norell at bluewin.ch (Anthra Norell) Date: Mon, 08 Feb 2010 09:30:51 +0100 Subject: Help with regex search-and-replace (Perl to Python) In-Reply-To: <06a91472-3974-45d3-b86a-c3c9055a5831@z26g2000yqm.googlegroups.com> References: <6705a5d5-551f-43c8-a863-50b051c6c0bc@d37g2000yqa.googlegroups.com> <4B6EBBEE.2070402@tim.thechases.com> <4B6EC203.4040807@holdenweb.com> <06a91472-3974-45d3-b86a-c3c9055a5831@z26g2000yqm.googlegroups.com> Message-ID: <4B6FCBBB.3090707@bluewin.ch> Schif Schaf wrote: > On Feb 7, 8:57 am, Tim Chase wrote: > >> Steve Holden wrote: >> >> >>> Really? Under what circumstances does a simple one-for-one character >>> replacement operation fail? >>> >> Failure is only defined in the clarified context of what the OP >> wants :) Replacement operations only fail if the OP's desired >> output from the above mess doesn't change *all* of the ]/[ >> characters, but only those with some form of parity (nested or >> otherwise). But if the OP *does* want all of the ]/[ characters >> replaced regardless of contextual nature, then yes, replace is a >> much better solution than regexps. >> >> > > I need to do the usual "pipe text through and do various search/ > replace" thing fairly often. The above case of having to replace > brackets with braces is only one example. Simple string methods run > out of steam pretty quickly and much of my work relies on using > regular expressions. Yes, I try to keep focused on simplicity, and > often regexes are the simplest solution for my day-to-day needs. > Could you post a complex case? It's a kindness to your helpers to simplify your case, but if the simplification doesn't cover the full scope of your problem you can't expect the suggestions to cover it. Frederic From rychphd at gmail.com Mon Feb 8 03:38:12 2010 From: rychphd at gmail.com (rych) Date: Mon, 8 Feb 2010 00:38:12 -0800 (PST) Subject: ctypes Structure serialization References: <615b1271-a9b0-4558-8e45-e4370698d96a@a16g2000pre.googlegroups.com> Message-ID: OK, an easier question, hopefully. How to unpack all fields from ctypes Structure line by line and save into the name-value pairs? From ldo at geek-central.gen.new_zealand Mon Feb 8 03:53:24 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Feb 2010 21:53:24 +1300 Subject: The Case For Do-Once Message-ID: I wrote my first Python extension library over the last couple of weeks. I took note of all the recommendations to keep track of reference counts, to ensure that objects were not disposed when they shouldn?t be, and were when they should. However, the example code seems to use gotos. And the trouble with these is that they don?t nest and un-nest easily; try to do too much refactoring with them, and you run into the age-old ?spaghetti code? problem. Which is where the do-once block comes in. The basic control flow is this: * Unconditionally initialize all dynamic storage to nil * Do the main body of the code, aborting in any error * Regardless of success or failure of the above, dispose of all allocated dynamic storage, using disposal calls which turn into noops if passed pointers that are already nil. For example, here?s a utility routine from my extension that, passed a Python array object, returns the address and length of the storage: static void GetBufferInfo ( PyObject * FromArray, unsigned long * addr, unsigned long * len ) /* returns the address and length of the data in a Python array object. */ { PyObject * TheBufferInfo = 0; PyObject * AddrObj = 0; PyObject * LenObj = 0; do /*once*/ { TheBufferInfo = PyObject_CallMethod(FromArray, "buffer_info", ""); if (TheBufferInfo == 0) break; AddrObj = PyTuple_GetItem(TheBufferInfo, 0); LenObj = PyTuple_GetItem(TheBufferInfo, 1); if (PyErr_Occurred()) break; Py_INCREF(AddrObj); Py_INCREF(LenObj); *addr = PyInt_AsUnsignedLongMask(AddrObj); *len = PyInt_AsUnsignedLongMask(LenObj); if (PyErr_Occurred()) break; } while (false); Py_XDECREF(AddrObj); Py_XDECREF(LenObj); Py_XDECREF(TheBufferInfo); } /*GetBufferInfo*/ You can pretty much determine by inspection that all the reference counts are properly maintained, no need to trace through convoluted flows of control. From stefan_ml at behnel.de Mon Feb 8 03:59:42 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 09:59:42 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <7xbpg5dazb.fsf@ruckus.brouhaha.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> Message-ID: <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> Paul Rubin, 04.02.2010 02:51: > John Nagle writes: >> Analysis of each domain is >> performed in a separate process, but each process uses multiple >> threads to read process several web pages simultaneously. >> >> Some of the threads go compute-bound for a second or two at a time as >> they parse web pages. > > You're probably better off using separate processes for the different > pages. If I remember, you were using BeautifulSoup, which while very > cool, is pretty doggone slow for use on large volumes of pages. I don't > know if there's much that can be done about that without going off on a > fairly messy C or C++ coding adventure. Maybe someday someone will do > that. Well, if multi-core performance is so important here, then there's a pretty simple thing the OP can do: switch to lxml. http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Stefan From duncan.booth at invalid.invalid Mon Feb 8 04:00:37 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Feb 2010 09:00:37 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> Message-ID: T wrote: > Oops, this one was my fault - the object I was having the issues with > was actually a shelve file, not a dictionary..so just re-assigning the > variable isn't working, but re-writing the object to the shelve file > does. So in this case, is there any way to just change a single > value, or am I stuck rewriting the entry? Either open the shelve with writeback=True or rewrite the entry. Rewriting the entry isn't hard: you can just re-use the same value: def changevalue(): for key in mytest.keys(): temp = mytest[key] temp.param3 = "newvalue" mytest[key] = temp If you really are changing every item in the shelve using writeback=True will be much simpler, but if you are only changing a few then just tell the shelve that you've updated them as above. -- Duncan Booth http://kupuguy.blogspot.com From stefan_ml at behnel.de Mon Feb 8 04:02:00 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 10:02:00 +0100 Subject: Stephen -- Bruce? In-Reply-To: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> References: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> Message-ID: <4b6fd308$0$6722$9b4e6d93@newsspool2.arcor-online.net> Mensanator, 05.02.2010 00:36: > On Feb 4, 5:13 pm, "Alf P. Steinbach" wrote: >> What's this about all the Stephen'ses here? >> >> Shouldn't it be Bruce? > > Of course. We just call everyone Stephen to avoid confusion. Some people even manage to adapt the spellings accordingly. Stefan From louis.coilliot at gmail.com Mon Feb 8 04:02:50 2010 From: louis.coilliot at gmail.com (lofic) Date: Mon, 8 Feb 2010 01:02:50 -0800 (PST) Subject: threading+popen2 hang References: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> Message-ID: <2542cf60-a193-4087-a1fe-1d60ee13c630@v25g2000yqk.googlegroups.com> On 7 f?v, 17:00, a... at pythoncraft.com (Aahz) wrote: > In article <188bfb67-3334-4325-adfc-3fa4d28f0... at d27g2000yqn.googlegroups.com>, > > lofic ? wrote: > > >Works fine on RHEL5/python 2.4.3 > >Hangs on RHEL4/python 2.3.4 > > Then use Python 2.4 -- surely you don't expect anyone to provide bugfixes > for a release that's several years old? > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > import antigravity 2.3 is the version provided with RHEL 4, which is still widely used in production environments. Sometimes it is not so easy to shift to another version in production systems. Some people don't work with the last bleeding edge Fedora release and must deal with (sometimes pretty old) existing system pools. I could deploy python 2.4 in addition to python 2.3, but it is much shake up for a little bug and a little program. I was not expected a bugfix, but maybe a workaround. Louis From no.email at nospam.invalid Mon Feb 8 04:10:07 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 08 Feb 2010 01:10:07 -0800 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <7xeikw2ivk.fsf@ruckus.brouhaha.com> Stefan Behnel writes: > Well, if multi-core performance is so important here, then there's a pretty > simple thing the OP can do: switch to lxml. > > http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ Well, lxml is uses libxml2, a fast XML parser written in C, but AFAIK it only works on well-formed XML. The point of Beautiful Soup is that it works on all kinds of garbage hand-written legacy HTML with mismatched tags and other sorts of errors. Beautiful Soup is slower because it's full of special cases and hacks for that reason, and it is written in Python. Writing something that complex in C to handle so much potentially malicious input would be quite a lot of work to write at all, and very difficult to ensure was really safe. Look at the many browser vulnerabilities we've seen over the years due to that sort of problem, for example. But, for web crawling, you really do need to handle the messy and wrong HTML properly. From stefan_ml at behnel.de Mon Feb 8 04:16:34 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 10:16:34 +0100 Subject: intolerant HTML parser In-Reply-To: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> Message-ID: <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> Jim, 06.02.2010 20:09: > I generate some HTML and I want to include in my unit tests a check > for syntax. So I am looking for a program that will complain at any > syntax irregularities. First thing to note here is that you should consider switching to an HTML generation tool that does this automatically. Generating markup manually is usually not a good idea. > I am familiar with Beautiful Soup (use it all the time) but it is > intended to cope with bad syntax. I just tried feeding > HTMLParser.HTMLParser some HTML containing '

ab

' and it > didn't complain. > > That is, this: > h=HTMLParser.HTMLParser() > try: > h.feed('

ab

') > h.close() > print "I expect not to see this line" > except Exception, err: > print "exception:",str(err) > gives me "I expect not to see this line". > > Am I using that routine incorrectly? Is there a natural Python choice > for this job? You can use lxml and let it validate the HTML output against the HTML DTD. Just load the DTD from a catalog using the DOCTYPE in the document (see the 'docinfo' property on the parse tree). http://codespeak.net/lxml/validation.html#id1 Note that when parsing the HTML file, you should disable the parser failure recovery to make sure it barks on syntax errors instead of fixing them up. http://codespeak.net/lxml/parsing.html#parser-options http://codespeak.net/lxml/parsing.html#parsing-html Stefan From stefan_ml at behnel.de Mon Feb 8 04:19:54 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 10:19:54 +0100 Subject: The Case For Do-Once In-Reply-To: References: Message-ID: <4b6fd73a$0$6734$9b4e6d93@newsspool2.arcor-online.net> Lawrence D'Oliveiro, 08.02.2010 09:53: > I wrote my first Python extension library over the last couple of weeks. I > took note of all the recommendations to keep track of reference counts, to > ensure that objects were not disposed when they shouldn?t be, and were when > they should. This sounds more like a case for Cython to me, should have saved you a lot of time. Stefan From andrew.degtiariov at gmail.com Mon Feb 8 04:37:53 2010 From: andrew.degtiariov at gmail.com (Andrew Degtiariov) Date: Mon, 8 Feb 2010 11:37:53 +0200 Subject: Import question In-Reply-To: References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> Message-ID: <5d1b76f61002080137o6e3f9a1fjdab8bcf8d3959faf@mail.gmail.com> 2010/2/6 Gabriel Genellina > En Fri, 05 Feb 2010 13:21:47 -0300, Andrew Degtiariov > escribi?: > > > Code of our project has split into several packages and we deploy the >> project using buildout. >> All worked fine until I need to dynamically inspect python modules. >> > > Entirely by luck, I'd say :) > > > ????project.api.config >> ? ????project >> ? ? ????api >> ? ? ????config >> ? ? ????settings >> ? ????project.api.config.egg-info >> ????project.api.contacts >> ? ????project >> ? ? ????api >> ? ? ????contacts >> ? ? ????importer >> ? ? ????views >> ? ????project.api.contacts.egg-info >> > > Regular code like "import project.api.config" worked fine, but now I'm >> tryed >> __import__('project.api.config'): >> >> $ bin/python >> >> import project.api.config >>>>> __import__('project.api.config') >>>>> >>>> > 'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'> >> > > > If someone is interesting - __import__ works but imp doesn't. In my example: >>> m = __import__('project.api.config') >>> m >>> m.api >>> m.api.config Please note that the m and m.api pointed to first installing package with namespace project.api but m.api.config have pointed to the proper file. And releasing code with several distributions it is one of goals of Distribute. And you might look to pypi for... zope. There is lot of package which names starts from "zope." It's really convenient -- Andrew Degtiariov DA-RIPE -------------- next part -------------- An HTML attachment was scrubbed... URL: From gagsl-py2 at yahoo.com.ar Mon Feb 8 05:19:34 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 08 Feb 2010 07:19:34 -0300 Subject: How to print all expressions that match a regular expression References: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> <76609ff4-6579-4b2b-80b7-fb88bd5f1fa7@a32g2000yqm.googlegroups.com> Message-ID: En Mon, 08 Feb 2010 02:17:59 -0300, hzhuo1 at gmail.com escribi?: >> Please check out this example on the pyparsing wiki, >> invRegex.py:http://pyparsing.wikispaces.com/file/view/invRegex.py. >> This code >> implements a generator that returns successive matching strings for >> the given regex. [...] >> Of course, as other posters have pointed out, this inverter does not >> accept regexen with unbounded multiple characters '+' or '*', but '?' >> and "{min,max}" notation will work. Even '.' is supported, although >> this can generate a large number of return values. > > Thanks very much. This is exactly what I need now. I will check this > function. > Here you have another approach based on [1]. This is a generator-based approach, yielding all strings in increasing length order. In principle it can handle unbounded repetitions, except as written the maximum recursion limit is shortly reached (the original code is in Haskell, I almost blindly translated it into Python; certainly it can be rewritten more efficiently) You have to parse the R.E. and generate the corresponding function calls to the merge/prod/closure functions -- pyparsing certainly can help with that. "ab" becomes prod(a,b), "a|b" becomes merge(a,b), and "a*" becomes closure(a) By example, to find the language defined by this expression "(a|bc)*d", one has to evaluate: prod( closure( merge(['a'], prod(['b'],['c']))), ['d'] ) wich yields these strings: d ad aad bcd aaad abcd bcad ... bcbcbcbcaad bcbcbcbcbcd aaaaaaaaaaad and after 234 results aborts with a recursion error :( [1] http://www.cs.utexas.edu/users/misra/Notes.dir/RegExp.pdf -- Gabriel Genellina -------------- next part -------------- A non-text attachment was scrubbed... Name: enumerate_regular_language.py Type: application/octet-stream Size: 2732 bytes Desc: not available URL: From gagsl-py2 at yahoo.com.ar Mon Feb 8 05:19:34 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 08 Feb 2010 07:19:34 -0300 Subject: How to print all expressions that match a regular expression References: <79728aa8-073f-48c5-8162-fa57e9fefd69@a32g2000yqm.googlegroups.com> <76609ff4-6579-4b2b-80b7-fb88bd5f1fa7@a32g2000yqm.googlegroups.com> Message-ID: En Mon, 08 Feb 2010 02:17:59 -0300, hzhuo1 at gmail.com escribi?: >> Please check out this example on the pyparsing wiki, >> invRegex.py:http://pyparsing.wikispaces.com/file/view/invRegex.py. >> This code >> implements a generator that returns successive matching strings for >> the given regex. [...] >> Of course, as other posters have pointed out, this inverter does not >> accept regexen with unbounded multiple characters '+' or '*', but '?' >> and "{min,max}" notation will work. Even '.' is supported, although >> this can generate a large number of return values. > > Thanks very much. This is exactly what I need now. I will check this > function. > Here you have another approach based on [1]. This is a generator-based approach, yielding all strings in increasing length order. In principle it can handle unbounded repetitions, except as written the maximum recursion limit is shortly reached (the original code is in Haskell, I almost blindly translated it into Python; certainly it can be rewritten more efficiently) You have to parse the R.E. and generate the corresponding function calls to the merge/prod/closure functions -- pyparsing certainly can help with that. "ab" becomes prod(a,b), "a|b" becomes merge(a,b), and "a*" becomes closure(a) By example, to find the language defined by this expression "(a|bc)*d", one has to evaluate: prod( closure( merge(['a'], prod(['b'],['c']))), ['d'] ) wich yields these strings: d ad aad bcd aaad abcd bcad ... bcbcbcbcaad bcbcbcbcbcd aaaaaaaaaaad and after 234 results aborts with a recursion error :( [1] http://www.cs.utexas.edu/users/misra/Notes.dir/RegExp.pdf -- Gabriel Genellina -------------- next part -------------- A non-text attachment was scrubbed... Name: enumerate_regular_language.py Type: application/octet-stream Size: 2732 bytes Desc: not available URL: From ldo at geek-central.gen.new_zealand Mon Feb 8 05:19:45 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Mon, 08 Feb 2010 23:19:45 +1300 Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> Message-ID: In message <4b6fd672$0$6734$9b4e6d93 at newsspool2.arcor-online.net>, Stefan Behnel wrote: > Jim, 06.02.2010 20:09: > >> I generate some HTML and I want to include in my unit tests a check >> for syntax. So I am looking for a program that will complain at any >> syntax irregularities. > > First thing to note here is that you should consider switching to an HTML > generation tool that does this automatically. I think that?s what he?s writing. From stefan_ml at behnel.de Mon Feb 8 05:36:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 11:36:45 +0100 Subject: intolerant HTML parser In-Reply-To: References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Lawrence D'Oliveiro, 08.02.2010 11:19: > In message <4b6fd672$0$6734$9b4e6d93 at newsspool2.arcor-online.net>, Stefan > Behnel wrote: > >> Jim, 06.02.2010 20:09: >> >>> I generate some HTML and I want to include in my unit tests a check >>> for syntax. So I am looking for a program that will complain at any >>> syntax irregularities. >> First thing to note here is that you should consider switching to an HTML >> generation tool that does this automatically. > > I think that?s what he?s writing. I don't read it that way. There's a huge difference between - generating HTML manually and validating (some of) it in a unit test and - generating HTML using a tool that guarantees correct HTML output the advantage of the second approach being that others have already done all the debugging for you. Stefan From jeanmichel at sequans.com Mon Feb 8 05:49:52 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Feb 2010 11:49:52 +0100 Subject: convention for documenting function parameters in doc strings In-Reply-To: References: Message-ID: <4B6FEC50.90708@sequans.com> danielx wrote: > Is there a convention for how to document function (or method) > parameters in doc strings? Recently, I've been doing alot of PHP > programming, and in PHPdoc, you'd do it like this: > > /* > * @param type $foo Description. > * > * @return type Description. > */ > function bar($foo) { > ... > } > > Is there an equivalent convention I (c|sh)ould be using in my Python > docstrings? I saw that Python 3 has function annotations, which could > be used for this purpose, but function annotations have no particular > purpose within the language itself (which seems like a mistake to me), > and they don't exist in the Python 2.x series (at least not the older > versions). > Different strategies here: 1/ most doc builders propose their own format. You can stick to it if you don't want to use another builder (e.g. epydoc has a specific syntax to document signatures) 2/ Use a 'standard' format, usually these formats are a bit more formal but they gain in portability, most builders support these formats. reStructuredText is one of them and supported by all python doc builders. http://epydoc.sourceforge.net/manual-othermarkup.html JM From klausneuner72 at googlemail.com Mon Feb 8 05:57:33 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Mon, 8 Feb 2010 02:57:33 -0800 (PST) Subject: use strings to call functions Message-ID: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Hello, I am writing a program that analyzes files of different formats. I would like to use a function for each format. Obviously, functions can be mapped to file formats. E.g. like this: if file.endswith('xyz'): xyz(file) elif file.endswith('abc'): abc(file) ... Yet, I would prefer to do something of the following kind: func = file[-3:] apply_func(func, file) Can something of this kind be done in Python? Klaus From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 8 06:11:14 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 08 Feb 2010 12:11:14 +0100 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4b6ff153$0$28652$426a74cc@news.free.fr> Klaus Neuner a ?crit : > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] A file extension is not necessarily 3 chars long. > apply_func(func, file) > > Can something of this kind be done in Python? The simplest (and canonical) solution is to use a dict: def handle_txt(path): # code here def handle_py(path): # code here etc... def handle_default(path): # for anything else handlers = { ".txt" : handle_txt, ".py" : handle_py, # etc } import os def handle_file(path): dummy, ext = os.path.splitext(path) handler = handlers.get(ext, handle_default) return handler(path) HTH From boblatest at googlemail.com Mon Feb 8 06:14:40 2010 From: boblatest at googlemail.com (boblatest) Date: Mon, 8 Feb 2010 03:14:40 -0800 (PST) Subject: Create a backslash-escaped version of a string? Message-ID: Hello, I'd like to have control characters in a string to be converted to their backslash-escaped counterparts. I looked in the encoders section of the string module but couldn't find anything appropriate. I could write it myself but I'm sure something of the sort exists. The hypothetical method "c_escaped()" would work like this: >>> a="abc\rdef" >>> print a.c_escaped() abc\rdef >>> Thanks, robert From sivaits4u at gmail.com Mon Feb 8 06:20:50 2010 From: sivaits4u at gmail.com (Bujji) Date: Mon, 8 Feb 2010 16:50:50 +0530 Subject: speed of server Message-ID: <581ce2791002080320p4e257539s6d089d5f75a62853@mail.gmail.com> hi all, how to find the speed of a particular server ( suppose it is hosting a site yahoo.com) how can i find it using python script whether it is slow or faster on that time help me thanks Bujji -------------- next part -------------- An HTML attachment was scrubbed... URL: From klausneuner72 at googlemail.com Mon Feb 8 06:26:39 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Mon, 8 Feb 2010 03:26:39 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> Message-ID: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> > > A file extension is not necessarily 3 chars long. No, of course not. But it is, if I choose to use only (self-made) file endings that are 3 chars long. Anyway, it was just an example. > handlers = { > ? ? ".txt" : handle_txt, > ? ? ".py" : handle_py, > ? ? # etc > ? ? } > That is exactly what I would like to avoid: Having to map the function 'handle_txt' to '.txt'. Firstly, because I don't want to repeat anything and secondly, because I will one day add a new function and forget to add its name to the dictionary. (This is not severe if there is only one dictionary for mapping functions, but it will make life a lot harder, if a lot of mappings of this kind are used.) What I want is calling the string directly. In Prolog, I would use something like: get_file_ending(File, Ending), Predicate =.. [Ending, File], call(Predicate). From clp2 at rebertia.com Mon Feb 8 06:28:39 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 8 Feb 2010 03:28:39 -0800 Subject: Create a backslash-escaped version of a string? In-Reply-To: References: Message-ID: <50697b2c1002080328s55ec1369u98466118a620fb98@mail.gmail.com> On Mon, Feb 8, 2010 at 3:14 AM, boblatest wrote: > Hello, > > I'd like to have control characters in a string to be converted to > their backslash-escaped counterparts. I looked in the encoders section > of the string module but couldn't find anything appropriate. I could > write it myself but I'm sure something of the sort exists. The > hypothetical method "c_escaped()" would work like this: > >>>> a="abc\rdef" >>>> print a.c_escaped() > abc\rdef print a.encode("string-escape") Note that there are some wrinkles if the string contains quote marks (and possibly also if it contains Unicode; I didn't test). Cheers, Chris -- http://blog.rebertia.com From davea at ieee.org Mon Feb 8 06:30:34 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 08 Feb 2010 06:30:34 -0500 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4B6FF5DA.2040804@ieee.org> Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? > > Klaus > > > You perhaps were intending to use the file extension , rather than the last three characters of the name. If so, consider os.path.splitext(). And you shouldn't shadow the builtin *file* type with a variable of the same name. More directly to your question, best suggestion is to build a (const) dictionary: apply_func = { "xyz":xyz, "abc":abc } which maps the strings to functions. This line can be at outer scope, as long as it follows all the appropriate function definitions. Notice that the individual functions need not be in the same module, if you use a fully qualified name in the dictionary. And of course, there's no necessity of naming the function exactly the same as the extension. So you could implement the functions in another module 'implem", and use the following: import implem apply_func = { "xyz":implem.process_xyz_files, "abc":implem.process_abc_files } Now, you use it by something like: dummy, func_ext = os.path.splitext(my_filename) apply_func(func_ext, my_filename) (all code untested) DaveA From wojciech_mula at poczta.null.onet.pl.invalid Mon Feb 8 06:37:49 2010 From: wojciech_mula at poczta.null.onet.pl.invalid (Wojciech =?ISO-8859-2?Q?Mu=B3a?=) Date: Mon, 8 Feb 2010 12:37:49 +0100 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <20100208123749.d0c0d6c1.wojciech_mula@poczta.null.onet.pl.invalid> Klaus Neuner wrote: > > handlers = { > > ? ? ".txt" : handle_txt, > > ? ? ".py" : handle_py, > > ? ? # etc > > ? ? } > > > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. Use dictionary mantained by runtime: def handle(extensions): funname = "handle_" + extension return globals()[funname] handle('txt') # => function handle_txt w. From mail at timgolden.me.uk Mon Feb 8 06:50:02 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Feb 2010 11:50:02 +0000 Subject: use strings to call functions In-Reply-To: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <4B6FFA6A.9080604@timgolden.me.uk> On 08/02/2010 11:26, Klaus Neuner wrote: >> >> A file extension is not necessarily 3 chars long. > > No, of course not. But it is, if I choose to use only (self-made) file > endings that are 3 chars long. Anyway, it was just an example. > >> handlers = { >> ".txt" : handle_txt, >> ".py" : handle_py, >> # etc >> } >> > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. (This is not severe if there > is only one dictionary for mapping functions, but it will make life a > lot harder, if a lot of mappings of this kind are used.) > > What I want is calling the string directly. In Prolog, I would use > something like: > > get_file_ending(File, Ending), > Predicate =.. [Ending, File], > call(Predicate). You basically need a getattr lookup. If you're prepared to instantiate a class or to import a handlers module then you can just look up against that: def handle_py (stuff): "print handling py" def handle_default (stuff): "print handling default"
import handlers ext = "py" handler = getattr (handlers, "handle_" + ext, handlers.handle_default) handler ("stuff")
You can do the equivalent by having a Handlers class with the appropriate methods (handle_py, etc.) and which you then instantiate. If you want to keep everything in one module, you should be able to achieve the same effect by looking the module up in sys.modules and then proceeding as above: import sys def handle_py (stuff): print "handling py" def handle_default (stuff): print "handling default" ext = "py" me = sys.modules[__name__] handler = getattr (me, "handle_" + ext, me.handle_default) handler ("blah") (All untested...) TJG From steve at holdenweb.com Mon Feb 8 06:51:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 06:51:38 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Steven D'Aprano wrote: > On Sun, 07 Feb 2010 22:03:06 -0500, Steve Holden wrote: > >> Alf: >> >> This topic was discussed at great, nay interminable, length about a year >> ago. I'd appreciate it if you would search the archives and read what >> was said then rather than hashing the whole topic over again to nobody's >> real advantage. > > Curse you Steve, I had just come up with a brilliant rebuttal of Alf's > position. It was sheer genius, the sort of thing that would have James > Gosling weeping with envy. > > Oh well, into the bitbucket it goes... > > You're a better man for it, Steven! Admirable self-restraint ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 8 06:59:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 06:59:02 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: [...] >> Alf: >> >> This topic was discussed at great, nay interminable, length about a year >> ago. I'd appreciate it if you would search the archives and read what >> was said then rather than hashing the whole topic over again to nobody's >> real advantage. > > Well that's my point, and thanks for backing me up on that :-): it's > very simple, and as demonstrated can be expressed in 10 words or less > (plus perhaps a terminology reference, as I did above), so all that > discussion and in particular the lengthy article at effbot serves as > obfuscation and nothing else. > Please don't assume I was trying to support you. Your remarks showed considerable ignorance of issue that were extremely nuanced. Whatever point you were trying to make was lost in your self-aggrandizing disrespect of Fredrik Lundh, a software engineer of some repute with a long history of contribution to Python. The fact that your post was basically a restatement of one of the several competing positions in that thread makes it no more right than any of the others. > By the way, most every programming language has some corner like that, > something that is utterly simple but somehow has some kind of > obfuscation-meme attached. > Why thank you for the education. Somehow in my 40-odd years of programming I had quite overlooked that fact. Which helps how? > In C++ it's "call" and "constructor". It doesn't help that the > language's standard lays down the law on it, it doesn't help that the > language's creator has laid down the law, it doesn't help that it's > utterly and completely simple. Somehow newbies and even some experienced > people manage to create their own terminological nightmare and drawing > conclusions about reality from that misguided obfuscated view, and then > discussing it up and down and sideways. > Which IMHO you have done little to assist. Just how exactly *do* we succeed in asking you not to discuss something? yours intemperate-ly - steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Mon Feb 8 06:59:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 08 Feb 2010 12:59:39 +0100 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4B6FFCAB.2040802@sequans.com> Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? > > Klaus > > You won't need anything else than defining the proper function to support the extension with the following code: import os class Handlers: class NoHandler(Exception): pass @staticmethod def txt(fileName): print 'I am processing a txt file' @staticmethod def tar(fileName): print 'I am processing a tar file' @classmethod def default(cls, fileName): raise cls.NoHandler("I don't know how to handle %s " % fileName) for fileName in ['/tmp/test.txt', '/tmp/sdfsd.sfds']: _, extension = os.path.splitext(fileName) func = getattr(Handlers, extension.replace('.', ''), Handlers.default) try: func(fileName) except Handlers.NoHandler, exc: print exc JM From steve at holdenweb.com Mon Feb 8 07:01:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 07:01:42 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: Gerard Flanagan wrote: > Arnaud Delobelle wrote: >> "Alf P. Steinbach" writes: >> >>> * Chris Rebert: >>>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>>> Ok, just looking for a sanity check here, or maybe something I'm >>>>> missing. I have a class Test, for example: >>>>> >>>>> class Test: >>>>> def __init__(self, param1, param2, param3): >>>>> self.param1 = param1 >>>>> self.param2 = param2 >>>>> self.param3 = param3 >>>>> >>>>> Next, I have a dictionary mytest that contains instances of Test. If >>>>> I want to modify one of the Test instances within my dictionary, I >>>>> have to rewrite the entire entry, correct (since Python passes by >>>>> value, not reference)? >>>> Incorrect; Python uses neither. See >>>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>>> of what Python does use. >>> Hm. While most everything I've seen at effbot.org has been clear and >>> to the point, that particular article reads like a ton of obfuscation. >>> >>> Python passes pointers by value, just as e.g. Java does. >> >> >> Please! Not this again! This has been discussed to death and beyond more >> than enough times. Go search the c.l.p archives, read it all, and I'm >> sure you won't want to add anything anymore. >> > > +1 !! > +1000 -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From stefan_ml at behnel.de Mon Feb 8 07:03:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 08 Feb 2010 13:03:10 +0100 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <4b6ffd7e$0$6735$9b4e6d93@newsspool2.arcor-online.net> Klaus Neuner, 08.02.2010 11:57: > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? Others have already pointed you to the approach of using a dict, or a module/class namespace with functions/methods to do this. Either of the latter two would be my favourite, depending on the complexity of the handlers. A class is more suitable as a container for short, highly correlated handlers, whereas a module makes more sense for handlers that do rather different things, or that are longer than a single function. A mixture of the two, e.g. a module of classes, where an entire class is used to implement a complete handler over several methods (potentially including some inheritance hierarchy between handlers that share functionality) might also be a solution. Note that objects can be callable in Python (special method __call__), you can exploit that here. What you are implementing here is commonly called a dispatch mechanism, BTW. There are several ways to do that, also within in Python. A web search should reveal some more. Stefan From steve at holdenweb.com Mon Feb 8 07:08:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 07:08:15 -0500 Subject: use strings to call functions In-Reply-To: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <4B6FFEAF.5070305@holdenweb.com> Klaus Neuner wrote: >> A file extension is not necessarily 3 chars long. > > No, of course not. But it is, if I choose to use only (self-made) file > endings that are 3 chars long. Anyway, it was just an example. > >> handlers = { >> ".txt" : handle_txt, >> ".py" : handle_py, >> # etc >> } >> > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. (This is not severe if there > is only one dictionary for mapping functions, but it will make life a > lot harder, if a lot of mappings of this kind are used.) > > What I want is calling the string directly. In Prolog, I would use > something like: > > get_file_ending(File, Ending), > Predicate =.. [Ending, File], > call(Predicate). > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 8 07:08:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 07:08:15 -0500 Subject: use strings to call functions In-Reply-To: <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <4b6ff153$0$28652$426a74cc@news.free.fr> <22b192df-8a54-4141-81c8-0ee068815420@c4g2000yqa.googlegroups.com> Message-ID: <4B6FFEAF.5070305@holdenweb.com> Klaus Neuner wrote: >> A file extension is not necessarily 3 chars long. > > No, of course not. But it is, if I choose to use only (self-made) file > endings that are 3 chars long. Anyway, it was just an example. > >> handlers = { >> ".txt" : handle_txt, >> ".py" : handle_py, >> # etc >> } >> > > That is exactly what I would like to avoid: Having to map the function > 'handle_txt' to '.txt'. Firstly, because I don't want to repeat > anything and secondly, because I will one day add a new function and > forget to add its name to the dictionary. (This is not severe if there > is only one dictionary for mapping functions, but it will make life a > lot harder, if a lot of mappings of this kind are used.) > > What I want is calling the string directly. In Prolog, I would use > something like: > > get_file_ending(File, Ending), > Predicate =.. [Ending, File], > call(Predicate). > > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From tim_grove at sil.org Mon Feb 8 09:22:56 2010 From: tim_grove at sil.org (Timothy W. Grove) Date: Mon, 08 Feb 2010 14:22:56 +0000 Subject: Python User Group near Cheltenham, UK ? Message-ID: <4B701E40.2030307@sil.org> Anyone know of an 'active' Python User Group near Cheltenham, UK? I spotted one in Birmingham (http://www.pywm.eu), but would like one a little closer ... :-) Tim From jfabiani at yolo.com Mon Feb 8 09:27:21 2010 From: jfabiani at yolo.com (jfabiani at yolo.com) Date: Mon, 08 Feb 2010 06:27:21 -0800 Subject: Calendar GUI References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <1adde6891002051614k3dc02d1o9651c59147f6c7d0@mail.gmail.com> <4B6D055A.30901@gmail.com> Message-ID: Jean-Michel Pichavant wrote: > Michael Torrie wrote: >> Gabriel wrote: >> >>> On Fri, Feb 5, 2010 at 9:08 PM, William Gaggioli >>> wrote: >>> >>>> I'm working on setting up some software for a Peruvian non-profit to >>>> help them organize their incoming volunteers. One of the features I'd >>>> like to add is a calendar-like view of the different volunteers arrival >>>> dates and staying time, with potentially some other info through some >>>> double-click action. Rather than writing a calendar gui myself, is >>>> there some open-source calendar program you guys could recommend that I >>>> could plug into? It has to be run locally, as the internet isn't so >>>> reliable down here, but other than that something simple and clean is >>>> ideal. >>>> Take a look at wxscheduler, and chandler. Johnf From solipsis at pitrou.net Mon Feb 8 09:28:41 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 8 Feb 2010 14:28:41 +0000 (UTC) Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: Le Tue, 02 Feb 2010 15:02:49 -0800, John Nagle a ?crit?: > I know there's a performance penalty for running Python on a multicore > CPU, but how bad is it? I've read the key paper > ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate if > the GIL just limited Python to running on one CPU at a time, but it's > worse than that; there's excessive overhead due to a lame locking > implementation. Running CPU-bound multithreaded code on a dual-core CPU > runs HALF AS FAST as on a single-core CPU, according to Beasley. That's on certain types of workloads, and perhaps on certain OSes, so you should try benching your own workload to see whether it applies. Two closing remarks: - this should (hopefully) be fixed in 3.2, as exarkun noticed - instead of spawning one thread per Web page, you could use Twisted or another event loop mechanism in order to process pages serially, in the order of arrival Regards Antoine. From mail at timgolden.me.uk Mon Feb 8 09:46:09 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 08 Feb 2010 14:46:09 +0000 Subject: Python User Group near Cheltenham, UK ? In-Reply-To: <4B701E40.2030307@sil.org> References: <4B701E40.2030307@sil.org> Message-ID: <4B7023B1.2050802@timgolden.me.uk> On 08/02/2010 14:22, Timothy W. Grove wrote: > Anyone know of an 'active' Python User Group near Cheltenham, UK? I > spotted one in Birmingham (http://www.pywm.eu), but would like one a > little closer ... :-) Don't think there's anything further west than Northants / W. Midlands. There are Open Source things in Oxford but nothing Python-specific, I believe. TJG From austin.brkich at gmail.com Mon Feb 8 09:50:20 2010 From: austin.brkich at gmail.com (7H3LaughingMan) Date: Mon, 8 Feb 2010 06:50:20 -0800 (PST) Subject: C/C++ Import References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: <4d7eb353-fb6b-4379-beee-8971ddc2472d@o28g2000yqh.googlegroups.com> The folder does contain a file named '__init__.py'. However it contains nothing inside of the file. On Feb 8, 12:42?am, Austin Bingham wrote: > Does the 'python' directory contain a file named '__init__.py'? This > is required to let that directory act as a package (see:http://docs.python.org/tutorial/modules.html#packages);without it, > you'll see the symptoms you're seeing. > > Austin > > On Mon, Feb 8, 2010 at 4:56 AM, 7H3LaughingMan wrote: > > To make the background information short, I am trying to take a > > program that uses Python for scripting and recompile it for Linux > > since it originally was built to run on Win32. The program itself was > > designed to be able to be compiled on Linux and someone made there on > > release with source that added python scripting. After some issues I > > got it to compile but now it is unable to import the files that it > > needs. > > > The program is running the following code... > > PyImport_Import( PyString_FromString("python.PlayerManager") ); > > > This is meant to import the file PlayerManager.py inside of the python > > folder. However it throws the following Python Error (Gotten through > > PyErr_Print()) > > ImportError: No module named python.PlayerManager > > > I am using 2.6.4 so I can't call it by the filename, does anyone know > > how to do a proper import? > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From Steven.Rumbalski at fiserv.com Mon Feb 8 09:51:02 2010 From: Steven.Rumbalski at fiserv.com (Steven) Date: Mon, 8 Feb 2010 06:51:02 -0800 (PST) Subject: Simple question about Queue.Queue and threads References: Message-ID: <770583c3-a7c7-4a3d-b90f-9546801040e3@u26g2000yqm.googlegroups.com> On Feb 5, 7:45?am, "Frank Millman" wrote: > Hi all > > Assume you have a server process running, a pool of worker threads to > perform tasks, and aQueue.Queue() to pass the tasks to the workers. > > In order to shut down the server cleanly, you want to ensure that the > workers have all finished their tasks. I like the technique of putting a > None onto thequeue, and have each worker check for None, put None back onto > thequeue, and terminate itself. > > The main program would look something like this - > > ? ? q.put(None) > ? ? for worker in worker_threads: > ? ? ? ? worker.join() > > At this point you can be sure that each thread has completed its tasks and > terminated itself. > > However, thequeueis not empty - it still has the final None in it. > > Is it advisable to finalise the cleanup like this? - > > ? ? while not q.empty(): > ? ? ? ? q.get() > ? ? ? ? q.task_done() > ? ? q.join() > > Or is this completely redundant? > > Thanks > > Frank Millman Queue objects have support for this signaling baked in with q.task_done and q.join. After the server process has put all tasks into the queue, it can join the queue itself, not the worker threads. q.join() This will block until all tasks have been gotten AND completed. The worker threads would simply do this: task_data = q.get() do_task(task_data) q.task_done() Using pairs of get and task_done you no longer need to send a signal. Just exit the server process and the worker threads will die (assuming of course, you set .setDaemon(True) before starting each worker thread). Steven Rumbalski From grflanagan at gmail.com Mon Feb 8 10:00:27 2010 From: grflanagan at gmail.com (Gerard Flanagan) Date: Mon, 08 Feb 2010 15:00:27 +0000 Subject: use strings to call functions In-Reply-To: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > xyz(file) > elif file.endswith('abc'): > abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > As mentioned, a dictionary dispatch will do what you want, but you can also use the self-registering technique outlined here: http://effbot.org/zone/metaclass-plugins.htm [Fredrik Lundh] (For Plugin, read Handler in this case.) One idea might be to have Handler classes such as: class TextHandler(HandlerType): extensions = ['', 'txt', 'rst'] def run(self, *args, **kw): .... do stuff then the __init__ of HandlerType's metaclass: def __init__(cls, name, bases, attrs): for ext in attrs.get('extensions', []): registry[ext] = cls then use like: registry['txt']().run() If you don't need state, you could perhaps make 'run' a staticmethod and store it rather than the class, eg. registry[ext] = cls.run and then just: registry['txt']() hth G.F ------------------------------------------------------------------------ registry = {} class HandlerType(object): class __metaclass__(type): def __init__(cls, name, bases, attrs): for ext in attrs.get('extensions', []): registry[ext] = cls class TextHandler(HandlerType): extensions = ['', 'txt'] print registry From alfps at start.no Mon Feb 8 10:22:03 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 16:22:03 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: > [...] >>> Alf: >>> >>> This topic was discussed at great, nay interminable, length about a year >>> ago. I'd appreciate it if you would search the archives and read what >>> was said then rather than hashing the whole topic over again to nobody's >>> real advantage. >> Well that's my point, and thanks for backing me up on that :-): it's >> very simple, and as demonstrated can be expressed in 10 words or less >> (plus perhaps a terminology reference, as I did above), so all that >> discussion and in particular the lengthy article at effbot serves as >> obfuscation and nothing else. >> > Please don't assume I was trying to support you. Your remarks showed > considerable ignorance of issue that were extremely nuanced. Whatever > point you were trying to make was lost in your self-aggrandizing > disrespect of Fredrik Lundh, a software engineer of some repute with a > long history of contribution to Python. The fact that your post was > basically a restatement of one of the several competing positions in > that thread makes it no more right than any of the others. What on Earth are you babbling about? Perhaps next you'll drag in the Pope, saying I've shown him some disrespect. News for you: the Pope ain't participating. >> By the way, most every programming language has some corner like that, >> something that is utterly simple but somehow has some kind of >> obfuscation-meme attached. >> > Why thank you for the education. Somehow in my 40-odd years of > programming I had quite overlooked that fact. Which helps how? > >> In C++ it's "call" and "constructor". It doesn't help that the >> language's standard lays down the law on it, it doesn't help that the >> language's creator has laid down the law, it doesn't help that it's >> utterly and completely simple. Somehow newbies and even some experienced >> people manage to create their own terminological nightmare and drawing >> conclusions about reality from that misguided obfuscated view, and then >> discussing it up and down and sideways. >> > Which IMHO you have done little to assist. Just how exactly *do* we > succeed in asking you not to discuss something? That's just a silly as the above. Hello? *Not* discuss an on-topic topic? Anyways, we haven't reached discussion yet, if it will ever come to that. All I see is a lot of silly noise about a simple trivially true technical statement, with incoherent allegations of disrespect to the Pope, the current king of France, and whomever, unfortunately as usual in this group. :-( Cheers & hth., - Alf From wanderer at dialup4less.com Mon Feb 8 10:24:32 2010 From: wanderer at dialup4less.com (Wanderer) Date: Mon, 8 Feb 2010 07:24:32 -0800 (PST) Subject: method names nounVerb or verbNoun References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> <36952f27-c825-4ab8-bd2e-7dff097075fd@d30g2000vbl.googlegroups.com> Message-ID: <0434e8b6-fe13-4eed-97c7-090c1c2b0a3a@y7g2000vbb.googlegroups.com> On Feb 5, 5:21?pm, Wanderer wrote: > On Feb 5, 4:53?pm, Chris Rebert wrote: > > > > > On Fri, Feb 5, 2010 at 1:49 PM, Wanderer wrote: > > > On Feb 5, 3:26?pm, Chris Rebert wrote: > > >> On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wrote: > > >> > Which is the more accepted way to compose method names nounVerb or > > >> > verbNoun? > > > >> > For example voltageGet or getVoltage? getVoltage sounds more normal, > > >> > but voltageGet is more like voltage.Get. I seem to mix them and I > > >> > should probably pick one way and stick with it. > > > >> Use properties[1] and just call it `voltage`. Python is not Java [2]; > > >> explicit getters/setters are unpythonic. > > > >> [1]http://docs.python.org/library/functions.html#property > > > > Maybe I'm not using Get right either. I'm wrapping functions. > > > > ? ?def AbbeGet(self, Lens): > > > ? ? ? ?""" > > > ? ? ? ?Get the Abbe Number V for the material > > > ? ? ? ?where > > > ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > > ? ? ? ?where the Index of Refractions are > > > ? ? ? ?Nd at the Fraunhofer D line 0.5892um > > > ? ? ? ?Nf at the Fraunhofer F line 0.4861um > > > ? ? ? ?Nc at the Fraunhofer C line 0.6563um > > > ? ? ? ?""" > > > > ? ? ? ?Nd = Lens.Mat.NtGet(0.5892) > > > ? ? ? ?Nf = Lens.Mat.NtGet(0.4861) > > > ? ? ? ?Nc = Lens.Mat.NtGet(0.6563) > > > > ? ? ? ?if (Nf - Nc) != 0: > > > ? ? ? ? ? ?V = (Nd - 1)/(Nf - Nc) > > > ? ? ? ?else: > > > ? ? ? ? ? ?V = 1e6 > > > > ? ? ? ?return V > > > This isn't even really a method; you don't refer to "self" in the body > > at all. Why isn't it just a function? > > > Cheers, > > Chris > > --http://blog.rebertia.com > > Okay, I guess it should be a function called abbe() instead of a > method called AbbeGet(). That should solve the problem of trying to > remember whether I called it GetAbbe or AbbeGet. > > Thanks Actually I decided it still should be a method, just not of doublet but of Lens. so the calls change from V1 = self.AbbeGet(Lens1) V2 = self.AbbeGet(Lens2) V1 = self.Lens1.abbe() V2 = self.Lens2.abbe() From boblatest at googlemail.com Mon Feb 8 10:50:55 2010 From: boblatest at googlemail.com (boblatest) Date: Mon, 8 Feb 2010 07:50:55 -0800 (PST) Subject: Create a backslash-escaped version of a string? References: Message-ID: <21d5019a-95ed-4c28-8c8e-8f2a6b9fc050@j31g2000yqa.googlegroups.com> On Feb 8, 12:28?pm, Chris Rebert wrote: > print a.encode("string-escape") How could I miss that? I was on that doc page already. Should have typed "/escape" in the browser ;-) Thanks, robert From gherron at islandtraining.com Mon Feb 8 11:02:54 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Feb 2010 08:02:54 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> Message-ID: <4B7035AE.2020500@islandtraining.com> Craig Berry wrote: > On Sun, Feb 7, 2010 at 22:26, Gary Herron wrote: > > >> Didn't I answer this already? >> > > If you did, for whatever reason I didn't see it; I just rechecked my > inbox to be sure. Thanks for doing so again! > > I assume, given the list we're on, that Freeglut can be used with > Python. I'll look into it. Thanks for the pointer! > > Yes, easily. PyOpenGL has bindings for all the procedures in GLUT/FREEGLUT. Just tell PyOpenGL to use the freeglut library instead, or even just copy freeglut (.dll or .so or whatever) over your existing glut library (glut32.dll or whatever). It really can serve as a binary drop in replacement. Gary Herron From james at agentultra.com Mon Feb 8 11:21:07 2010 From: james at agentultra.com (J Kenneth King) Date: Mon, 08 Feb 2010 11:21:07 -0500 Subject: Overcoming python performance penalty for multicore CPU References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> <7xeikw2ivk.fsf@ruckus.brouhaha.com> Message-ID: <85zl3ju2a4.fsf@agentultra.com> Paul Rubin writes: > Stefan Behnel writes: >> Well, if multi-core performance is so important here, then there's a pretty >> simple thing the OP can do: switch to lxml. >> >> http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ > > Well, lxml is uses libxml2, a fast XML parser written in C, but AFAIK it > only works on well-formed XML. The point of Beautiful Soup is that it > works on all kinds of garbage hand-written legacy HTML with mismatched > tags and other sorts of errors. Beautiful Soup is slower because it's > full of special cases and hacks for that reason, and it is written in > Python. Writing something that complex in C to handle so much > potentially malicious input would be quite a lot of work to write at > all, and very difficult to ensure was really safe. Look at the many > browser vulnerabilities we've seen over the years due to that sort of > problem, for example. But, for web crawling, you really do need to > handle the messy and wrong HTML properly. If the difference is great enough, you might get a benefit from analyzing all pages with lxml and throwing invalid pages into a bucket for later processing with BeautifulSoup. From aahz at pythoncraft.com Mon Feb 8 11:22:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 08:22:40 -0800 Subject: threading+popen2 hang References: <188bfb67-3334-4325-adfc-3fa4d28f0cbf@d27g2000yqn.googlegroups.com> <2542cf60-a193-4087-a1fe-1d60ee13c630@v25g2000yqk.googlegroups.com> Message-ID: In article <2542cf60-a193-4087-a1fe-1d60ee13c630 at v25g2000yqk.googlegroups.com>, lofic wrote: >On 7 f=E9v, 17:00, a... at pythoncraft.com (Aahz) wrote: >> In article <188bfb67-3334-4325-adfc-3fa4d28f0... at d27g2000yqn.googlegroups= >.com>, >> lofic =A0 wrote: >>> >>>Works fine on RHEL5/python 2.4.3 >>>Hangs on RHEL4/python 2.3.4 >> >> Then use Python 2.4 -- surely you don't expect anyone to provide bugfixes >> for a release that's several years old? > >2.3 is the version provided with RHEL 4, which is still widely used in >production environments. Sometimes it is not so easy to shift to >another version in production systems. Believe me, I'm well aware of that (my last job was also stuck on 2.3). Nevertheless, the pool of people familiar with the minutiae of bugs for both Python 2.3 and 2.4 is dwindling daily, and your best recourse is intensive Googling. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From misceverything at gmail.com Mon Feb 8 11:37:38 2010 From: misceverything at gmail.com (T) Date: Mon, 8 Feb 2010 08:37:38 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <5af715b7-61d3-4283-bd23-cead735195bc@t31g2000prh.googlegroups.com> <959b345f-92a9-4ab4-9d0a-771baaa54272@p6g2000vbl.googlegroups.com> <811dd4e9-6eea-4c1f-a24b-ba0179e57f84@a13g2000vbf.googlegroups.com> Message-ID: On Feb 8, 1:28?am, Sean DiZazzo wrote: > On Feb 7, 4:57?pm, T wrote: > > > Thanks for the suggestions - ?I think my next step is to try running > > it under an admin user account, as you guys both mentioned. ?Alf - > > you're absolutely right, Microsoft has srvany.exe, which allows you to > > run any EXE as a Windows service. ?I've done this in the past, but > > it's more of a "hack"..so this go around (since I will be distributing > > this program), I wanted to go the more professional route..which, > > unfortunately, involves learning the "scum". :) ?I ?posted this to > > comp.os.ms-windows.programmer.win32, so we'll see if what the Win32 > > programmers have to say as well. ?Thanks again! > > I use windows services and they are very reliable. ?I would say though > that relying on plink.exe is much less reliable than either python or > the service that it is running under. > > Why not take a look at paramiko as the ssh client library? ?I think it > runs under windows. ?Also perhaps Twisted has something. ?Either way > would be light years ahead of using subprocess with plink. > > Just my thoughts. > > ~Sean I totally agree that it would be much more reliable to use a Python library for SSH - however, the program will need to execute other external binaries as well. So my goal at this point is to track down _why_ it's failing when running as a service. The actual command is as follows: C:\plink.exe -R 9999:127.0.0.1:2020 -batch -i C:\keyfile.ppk user at 10.10.10.1 I tried having subprocess.Popen run plink.exe by itself and piping output to file, and this worked - so I know it's at least executing plink.exe. Sorry, I realize this isn't truly just a Python-related question, but any help would be greatly appreciated! So far no help at comp.os.ms-windows.programmer.win32.. From jkrukoff at ltgc.com Mon Feb 8 11:43:10 2010 From: jkrukoff at ltgc.com (John Krukoff) Date: Mon, 08 Feb 2010 09:43:10 -0700 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <7xeikw2ivk.fsf@ruckus.brouhaha.com> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <7xbpg5dazb.fsf@ruckus.brouhaha.com> <4b6fd27e$0$6722$9b4e6d93@newsspool2.arcor-online.net> <7xeikw2ivk.fsf@ruckus.brouhaha.com> Message-ID: <1265647390.10548.1804.camel@localhost.localdomain> On Mon, 2010-02-08 at 01:10 -0800, Paul Rubin wrote: > Stefan Behnel writes: > > Well, if multi-core performance is so important here, then there's a pretty > > simple thing the OP can do: switch to lxml. > > > > http://blog.ianbicking.org/2008/03/30/python-html-parser-performance/ > > Well, lxml is uses libxml2, a fast XML parser written in C, but AFAIK it > only works on well-formed XML. The point of Beautiful Soup is that it > works on all kinds of garbage hand-written legacy HTML with mismatched > tags and other sorts of errors. Beautiful Soup is slower because it's > full of special cases and hacks for that reason, and it is written in > Python. Writing something that complex in C to handle so much > potentially malicious input would be quite a lot of work to write at > all, and very difficult to ensure was really safe. Look at the many > browser vulnerabilities we've seen over the years due to that sort of > problem, for example. But, for web crawling, you really do need to > handle the messy and wrong HTML properly. > Actually, lxml has an HTML parser which does pretty well with the standard level of broken one finds most often on the web. And, when it falls down, it's easy to integrate BeautifulSoup as a slow backup for when things go really wrong (as J Kenneth King mentioned earlier): http://codespeak.net/lxml/lxmlhtml.html#parsing-html At least in my experience, I haven't actually had to parse anything that lxml couldn't handle yet, however. -- John Krukoff Land Title Guarantee Company From tjreedy at udel.edu Mon Feb 8 11:52:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Feb 2010 11:52:17 -0500 Subject: C/C++ Import In-Reply-To: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: On 2/7/2010 10:56 PM, 7H3LaughingMan wrote: > To make the background information short, I am trying to take a > program that uses Python for scripting and recompile it for Linux > since it originally was built to run on Win32. The program itself was > designed to be able to be compiled on Linux and someone made there on > release with source that added python scripting. After some issues I > got it to compile but now it is unable to import the files that it > needs. > > The program is running the following code... > PyImport_Import( PyString_FromString("python.PlayerManager") ); > > This is meant to import the file PlayerManager.py inside of the python > folder. However it throws the following Python Error (Gotten through > PyErr_Print()) > ImportError: No module named python.PlayerManager > > I am using 2.6.4 so I can't call it by the filename, does anyone know > how to do a proper import? Your 'python' package directory must be in a directory listed in sys.path. I would print that check. From misceverything at gmail.com Mon Feb 8 12:05:05 2010 From: misceverything at gmail.com (T) Date: Mon, 8 Feb 2010 09:05:05 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> Message-ID: <7c8003e9-5813-4891-bcc8-6e00e69740b2@c10g2000vbr.googlegroups.com> On Feb 8, 4:00?am, Duncan Booth wrote: > T wrote: > > Oops, this one was my fault - the object I was having the issues with > > was actually a shelve file, not a dictionary..so just re-assigning the > > variable isn't working, but re-writing the object to the shelve file > > does. ?So in this case, is there any way to just change a single > > value, or am I stuck rewriting the entry? > > Either open the shelve with writeback=True or rewrite the entry. > Rewriting the entry isn't hard: you can just re-use the same value: > > def changevalue(): > ? ? for key in mytest.keys(): > ? ? ? ? temp = mytest[key] > ? ? ? ? temp.param3 = "newvalue" > ? ? ? ? mytest[key] = temp > > If you really are changing every item in the shelve using writeback=True > will be much simpler, but if you are only changing a few then just tell the > shelve that you've updated them as above. > > -- > Duncan Boothhttp://kupuguy.blogspot.com Duncan - Thanks for your help. So each of the shelve entries I'm modifying look something like this: myshelve[key] = TestClassObject(param1, param2, param3, param4, param5, etc.). In this case, with quite a few parameters, would you suggest setting writeback=True and just modifying the needed value, or rewriting the entire entry? I have to admit the writeback option looks good, and if the TestClassObject format ever changes (i.e. if I ever change the order of the params), this particular function will be unchanged. However, I don't know what the performance hit would be in using it. From mrkafk at gmail.com Mon Feb 8 12:07:56 2010 From: mrkafk at gmail.com (mk) Date: Mon, 08 Feb 2010 18:07:56 +0100 Subject: Your beloved python features In-Reply-To: <037c8d60$0$1292$c3e8da3@news.astraweb.com> References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: > >> Ethan Furman wrote: >> >>> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ > choose_python.pdf >>> >> Choose to get your difficult questions about threads in Python ignored. >> Oh well.. > > With an attitude like that, you're damn lucky if you don't get kill- > filed. It was SIX MINUTES since you posted your question about timers, > what did you expect? I didn't expect immediate answer to this particular question. I have repeatedly asked many questions about threads in the past, and IIRC every one of them was ignored. > > Threads are hard, and many people don't use them at all. You might never > get an answer, even without alienating people. Complaining after six DAYS > might be acceptable, if you do it with a sense of humour, but after six > minutes? Well, it's 4 days now. I would be happy to get 50% response rate. Apparently nobody is really using threads. regards, mk From phlip2005 at gmail.com Mon Feb 8 12:12:46 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 09:12:46 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Message-ID: Stefan Behnel wrote: > I don't read it that way. There's a huge difference between > > - generating HTML manually and validating (some of) it in a unit test > > and > > - generating HTML using a tool that guarantees correct HTML output > > the advantage of the second approach being that others have already done > all the debugging for you. Anyone TDDing around HTML or XML should use or fork my assert_xml() (from django-test-extensions). The current version trivially detects a leading tag and uses etree.HTML(xml); else it goes with the stricter etree.XML(xml). The former will not complain about the provided sample HTML. Sadly, the industry has such a legacy of HTML written in Notepad that well-formed (X)HTML will never be well-formed XML. My own action item here is to apply Stefan's parser_options suggestion to make the etree.HTML() stricter. However, a generator is free to produce arbitrarily restricted XML that avoids the problems with XHTML. It could, for example, push any Javascript that even dreams of using & instead of & out into .js files. So an assert_xml() hot-wired to process only XML - with the true HTML doctype - is still useful to TDD generated code, because its XPath reference will detect that you get the nodes you expect. -- Phlip http://c2.com/cgi/wiki?ZeekLand From python at mrabarnett.plus.com Mon Feb 8 12:31:13 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 17:31:13 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <4B704A61.7070405@mrabarnett.plus.com> Steven D'Aprano wrote: > On Mon, 08 Feb 2010 02:51:05 +0100, Alf P. Steinbach wrote: > >> Python passes pointers by value, just as e.g. Java does. > > How do I get a pointer in pure Python code (no ctypes)? I tried both > Pascal and C syntax (^x and *x), but both give syntax errors. > In Pascal it's x^. > For that matter, how do I get a pointer in Java code? > > If Python doesn't have pointers, then why are you talking about Python > passing pointers? It's a vacuous truth, like saying that Python passes > dinosaurs by name. > From python at mrabarnett.plus.com Mon Feb 8 12:33:45 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 17:33:45 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <4B704AF9.2030804@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Steve Holden: >> [...] >>>> Alf: >>>> >>>> This topic was discussed at great, nay interminable, length about a >>>> year >>>> ago. I'd appreciate it if you would search the archives and read what >>>> was said then rather than hashing the whole topic over again to >>>> nobody's >>>> real advantage. >>> Well that's my point, and thanks for backing me up on that :-): it's >>> very simple, and as demonstrated can be expressed in 10 words or less >>> (plus perhaps a terminology reference, as I did above), so all that >>> discussion and in particular the lengthy article at effbot serves as >>> obfuscation and nothing else. >>> >> Please don't assume I was trying to support you. Your remarks showed >> considerable ignorance of issue that were extremely nuanced. Whatever >> point you were trying to make was lost in your self-aggrandizing >> disrespect of Fredrik Lundh, a software engineer of some repute with a >> long history of contribution to Python. The fact that your post was >> basically a restatement of one of the several competing positions in >> that thread makes it no more right than any of the others. > > What on Earth are you babbling about? > > Perhaps next you'll drag in the Pope, saying I've shown him some > disrespect. > > News for you: the Pope ain't participating. > [snip] The Pope isn't (as far as we know) a Pythonista. From duncan.booth at invalid.invalid Mon Feb 8 12:57:45 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Feb 2010 17:57:45 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0795c4c2-bfd4-4372-903e-a91e45b37d50@b35g2000vbc.googlegroups.com> <7c8003e9-5813-4891-bcc8-6e00e69740b2@c10g2000vbr.googlegroups.com> Message-ID: T wrote: > Duncan - Thanks for your help. So each of the shelve entries I'm > modifying look something like this: myshelve[key] > TestClassObject(param1, param2, param3, param4, param5, etc.). In > this case, with quite a few parameters, would you suggest setting > writeback=True and just modifying the needed value, or rewriting the > entire entry? I have to admit the writeback option looks good, and if > the TestClassObject format ever changes (i.e. if I ever change the > order of the params), this particular function will be unchanged. > However, I don't know what the performance hit would be in using it. Only you know your data and pattern of use. Try a few tests to get a feel of the trade-offs between explicitly flagging items as changed or using writeback=True. From phlip2005 at gmail.com Mon Feb 8 13:16:22 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 10:16:22 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <5e67584b-2421-4254-addf-b4a355836a20@b9g2000pri.googlegroups.com> and the tweak is: parser = etree.HTMLParser(recover=False) return etree.HTML(xml, parser) That reduces tolerance. The entire assert_xml() is (apologies for wrapping lines!): def _xml_to_tree(self, xml): from lxml import etree self._xml = xml try: if ' 0, xpath + ' not found in ' + self._xml) node = nodes[0] if kw.get('verbose', False): self.reveal_xml(node) # "here have ye been? What have ye seen?"--Morgoth return node def reveal_xml(self, node): 'Spews an XML node as source, for diagnosis' from lxml import etree print etree.tostring(node, pretty_print=True) # CONSIDER does pretty_print work? why not? def deny_xml(self, xml, xpath): 'Check that a given extent of XML or HTML does not contain a given XPath' tree = self._xml_to_tree(xml) nodes = tree.xpath(xpath) self.assertEqual(0, len(nodes), xpath + ' should not appear in ' + self._xml) From deets at nospam.web.de Mon Feb 8 14:04:19 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 08 Feb 2010 20:04:19 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <7tb5hlF3nmU1@mid.uni-berlin.de> Am 08.02.10 02:51, schrieb Alf P. Steinbach: > * Chris Rebert: >> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>> Ok, just looking for a sanity check here, or maybe something I'm >>> missing. I have a class Test, for example: >>> >>> class Test: >>> def __init__(self, param1, param2, param3): >>> self.param1 = param1 >>> self.param2 = param2 >>> self.param3 = param3 >>> >>> Next, I have a dictionary mytest that contains instances of Test. If >>> I want to modify one of the Test instances within my dictionary, I >>> have to rewrite the entire entry, correct (since Python passes by >>> value, not reference)? >> >> Incorrect; Python uses neither. See >> http://effbot.org/zone/call-by-object.htm for a excellent explanation >> of what Python does use. > > Hm. While most everything I've seen at effbot.org has been clear and to > the point, that particular article reads like a ton of obfuscation. > > Python passes pointers by value, just as e.g. Java does. > > There, it needed just 10 words or so. :-) Or perhaps some more words to > point out that in the Java language spec those reference values are > called pointers, but that this terminology isn't (apparently) used for > Python, and isn't even well known among Java programmers. But that's > just one extra little para. > > One just has to be clear about exactly what it is that's passed by value. > > Not Python objects, but references (pointers) to them, the id(o) values. Whao. You just needed 10 words, plus a paragraph to explain something in terms of a spec that's just about 600 pages strong. Amazing display of conciseness, and certainly the most valuable thing for some programming newbie to work with. Thanks! Diez From alfps at start.no Mon Feb 8 14:10:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 08 Feb 2010 20:10:00 +0100 Subject: Modifying Class Object In-Reply-To: <7tb5hlF3nmU1@mid.uni-berlin.de> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: * Diez B. Roggisch: > Am 08.02.10 02:51, schrieb Alf P. Steinbach: >> * Chris Rebert: >>> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>>> Ok, just looking for a sanity check here, or maybe something I'm >>>> missing. I have a class Test, for example: >>>> >>>> class Test: >>>> def __init__(self, param1, param2, param3): >>>> self.param1 = param1 >>>> self.param2 = param2 >>>> self.param3 = param3 >>>> >>>> Next, I have a dictionary mytest that contains instances of Test. If >>>> I want to modify one of the Test instances within my dictionary, I >>>> have to rewrite the entire entry, correct (since Python passes by >>>> value, not reference)? >>> >>> Incorrect; Python uses neither. See >>> http://effbot.org/zone/call-by-object.htm for a excellent explanation >>> of what Python does use. >> >> Hm. While most everything I've seen at effbot.org has been clear and to >> the point, that particular article reads like a ton of obfuscation. >> >> Python passes pointers by value, just as e.g. Java does. >> >> There, it needed just 10 words or so. :-) Or perhaps some more words to >> point out that in the Java language spec those reference values are >> called pointers, but that this terminology isn't (apparently) used for >> Python, and isn't even well known among Java programmers. But that's >> just one extra little para. >> >> One just has to be clear about exactly what it is that's passed by value. >> >> Not Python objects, but references (pointers) to them, the id(o) values. > > Whao. You just needed 10 words, plus a paragraph to explain something in > terms of a spec that's just about 600 pages strong. Amazing display of > conciseness, and certainly the most valuable thing for some programming > newbie to work with. Thanks! I apologize for assuming that "pointer" is a known word to [c.l.p.] denizens. But, if it can help, although for clarity I had to provide a concrete reference, you don't need to read the complete Java language spec to understand that word. Just Google it. Cheers & hth., - ALf From gagsl-py2 at yahoo.com.ar Mon Feb 8 14:21:15 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Mon, 08 Feb 2010 16:21:15 -0300 Subject: Import question References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> <5d1b76f61002080137o6e3f9a1fjdab8bcf8d3959faf@mail.gmail.com> Message-ID: En Mon, 08 Feb 2010 06:37:53 -0300, Andrew Degtiariov escribi?: > 2010/2/6 Gabriel Genellina >> En Fri, 05 Feb 2010 13:21:47 -0300, Andrew Degtiariov >> escribi?: >> >> >>> Code of our project has split into several packages and we deploy the >>> project using buildout. >>> All worked fine until I need to dynamically inspect python modules. >> Entirely by luck, I'd say :) >> >> >> ????project.api.config >>> ? ????project >>> ? ? ????api >>> ? ? ????config >>> ? ? ????settings >>> ? ????project.api.config.egg-info >>> ????project.api.contacts >>> ? ????project >>> ? ? ????api >>> ? ? ????contacts >>> ? ? ????importer >>> ? ? ????views >>> ? ????project.api.contacts.egg-info >>> > If someone is interesting - __import__ works but imp doesn't. > In my example: >>>> m = __import__('project.api.config') >>>> m > 'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'> >>>> m.api > 'c:\users\ad\project\src\project.api.contacts\project\api\__init__.pyc'> >>>> m.api.config > from'c:\users\ad\project\src\project.api.config\project\api\config\__init__.pyc'> > > Please note that the m and m.api pointed to first installing package with > namespace project.api but m.api.config have pointed to the proper file. > > And releasing code with several distributions it is one of goals of > Distribute. And you might look to pypi for... zope. There is lot of > package > which names starts from "zope." > It's really convenient Those are called namespace packages. Zope and Plone (ab)use them extensively. The intended usage is to break up a big, monolithic package [0] in parts that can be distributed independently. To implement a namespace package, you need an empty __init__.py file with only these lines [1]: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) But think carefully if you really need namespace packages; they solve a specific problem, aren't a general purpose technique. See [2] for a discussion. [0] Think of a huge behemoth with a "Z O P E" sign on both sides :) [1] http://docs.python.org/library/pkgutil.html [2] http://weblion.psu.edu/news/are-we-overusing-namespace-packages -- Gabriel Genellina From db3l.net at gmail.com Mon Feb 8 14:25:09 2010 From: db3l.net at gmail.com (David Bolen) Date: Mon, 08 Feb 2010 14:25:09 -0500 Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: T writes: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. Specifically, the > program will call plink.exe to create a reverse SSH tunnel. Right now > I'm using subprocess.Popen to do so. When I run it interactively via > an admin account, all is well. However, when I'm running it via > service, no luck. I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. What > would be the best way around this? Thanks! The LocalSystem account is not, if I recall correctly, permitted to access the network. You'll have to install the service to run under some other account that has appropriate access to the network. -- David From olivier.darge at gmail.com Mon Feb 8 14:28:53 2010 From: olivier.darge at gmail.com (OdarR) Date: Mon, 8 Feb 2010 11:28:53 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> Message-ID: <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> On 8 f?v, 11:57, Klaus Neuner wrote: > Hello, > > I am writing a program that analyzes files of different formats. I > would like to use a function for each format. Obviously, functions can > be mapped to file formats. E.g. like this: > > if file.endswith('xyz'): > ? ? xyz(file) > elif file.endswith('abc'): > ? ? abc(file) > > ... > > Yet, I would prefer to do something of the following kind: > > func = file[-3:] > apply_func(func, file) > > Can something of this kind be done in Python? and with eval(), did you try ? import sys def functext(): print "texte" def funcdoc(): print "doc" def funcabc(): print "abc" if __name__ == "__main__": #replace filename with suitable value filename = sys.argv[1].split('.')[1] try: eval('func' + filename + '()') except: print 'error' From gherron at islandtraining.com Mon Feb 8 14:47:40 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Feb 2010 11:47:40 -0800 Subject: use strings to call functions In-Reply-To: <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <4B706A5C.2080506@islandtraining.com> OdarR wrote: > On 8 f?v, 11:57, Klaus Neuner wrote: > >> Hello, >> >> I am writing a program that analyzes files of different formats. I >> would like to use a function for each format. Obviously, functions can >> be mapped to file formats. E.g. like this: >> >> if file.endswith('xyz'): >> xyz(file) >> elif file.endswith('abc'): >> abc(file) >> >> ... >> >> Yet, I would prefer to do something of the following kind: >> >> func = file[-3:] >> apply_func(func, file) >> >> Can something of this kind be done in Python? >> I may have missed a bit of this thread -- so I have to ask: Has anyone mentioned using getattr yet? It's a way of looking up *any* attribute using a string to specify the name. Like this for your particular example: class Functions: # This could be a module instead of a class def xyz(...): ... def abc(...): ... ... and so on ... ext = os.path.splitext(file) # Parses out the extension fn = getattr(Functions, ext) # Lookup the correct function fn(...) # and call it Gary Herron From gnewsg at gmail.com Mon Feb 8 15:04:12 2010 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Mon, 8 Feb 2010 12:04:12 -0800 (PST) Subject: setuptools/distutil and pywin32 Message-ID: <04946f8f-46c0-4e90-b0cb-26a44e6c0323@r24g2000yqd.googlegroups.com> Hi, I have a program which requires pywin32 as a dependancy and I'd like to make setuptools automatically retrieve it from internet and install it. My setup.py script looks like this: from setuptools import setup setup( ... ... install_requires = ['pywin32'] ... ) When I run setup.py install I get this error: Processing dependencies for psutil==0.1.3 Searching for pywin32 Reading http://pypi.python.org/simple/pywin32/ Reading http://sf.net/projects/pywin32 Reading http://sourceforge.net/project/showfiles.php?group_id=78018 Best match: pywin32 214 Downloading http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/pywin32-214.win32-py2.6.exe download Processing download error: Not a recognized archive type: c:\users\giampa~1\appdata\local \temp\easy_ install-xefzrd\download I've googled a lot about this but it seems that as of right now it's just not possible to install pywin32 via setuptools but it seems pretty strange to me as it is a very important third party module. Can someone confirm to me that there's no way to solve this problem? Thanks in advance, ---- Giampaolo http://code.google.com/p/psutil http://code.google.com/p/pyftpdlib From debatem1 at gmail.com Mon Feb 8 15:06:26 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Feb 2010 15:06:26 -0500 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: On Mon, Feb 8, 2010 at 12:07 PM, mk wrote: > Steven D'Aprano wrote: >> >> On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: >> >>> Ethan Furman wrote: >>> >>>> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ >> >> choose_python.pdf >>>> >>> Choose to get your difficult questions about threads in Python ignored. >>> Oh well.. >> >> With an attitude like that, you're damn lucky if you don't get kill- >> filed. It was SIX MINUTES since you posted your question about timers, >> what did you expect? > > I didn't expect immediate answer to this particular question. I have > repeatedly asked many questions about threads in the past, and IIRC every > one of them was ignored. > >> >> Threads are hard, and many people don't use them at all. You might never >> get an answer, even without alienating people. Complaining after six DAYS >> might be acceptable, if you do it with a sense of humour, but after six >> minutes? > > Well, it's 4 days now. I would be happy to get 50% response rate. Apparently > nobody is really using threads. > > regards, > mk I use threads. Geremy Condra From pwashington85 at gmail.com Mon Feb 8 15:16:24 2010 From: pwashington85 at gmail.com (spike) Date: Mon, 8 Feb 2010 12:16:24 -0800 (PST) Subject: Does anyone have a Python Logic Map/Flow Chart? (Example Provided) Message-ID: <05a9edbc-63e9-4155-833c-15cf5dacd7ea@p13g2000pre.googlegroups.com> Has anyone been able to come across a Python logic map or flow chart? An example can be seen here on the right: http://en.wikipedia.org/wiki/Usenet This would be very helpful for users. From pwashington85 at gmail.com Mon Feb 8 15:20:15 2010 From: pwashington85 at gmail.com (spike) Date: Mon, 8 Feb 2010 12:20:15 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) Message-ID: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Has anyone been able to come across a Python logic map or Python logic flow chart? An example can be seen on the right under History: http://en.wikipedia.org/wiki/Usenet#History This would be very helpful for all users. From invalid at gmail.com Mon Feb 8 15:36:43 2010 From: invalid at gmail.com (Dave Peterson) Date: Mon, 8 Feb 2010 12:36:43 -0800 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples Message-ID: Page 7: Very first example doesn't compile: syntax error Pate 11: 2nd example: syntax error Page 12, printing digits: syntax error Page 13, printing a number: syntax error page 14, statements: syntax error From benjamin.kaplan at case.edu Mon Feb 8 15:45:05 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 8 Feb 2010 15:45:05 -0500 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples In-Reply-To: References: Message-ID: On Mon, Feb 8, 2010 at 3:36 PM, Dave Peterson wrote: > Page 7: Very first example doesn't compile: syntax error > Pate 11: 2nd example: syntax error > Page 12, printing digits: syntax error > Page 13, printing a number: syntax error > page 14, statements: syntax error > Let me guess, you're using Python 3.1. That book was written for Python 2.x and there were several backwards-incompatible changes. For instance, print was changed from a statement to a function. Which is why the "Hello, World" doesn't work any more. If you want to use the older books, use Python 2.6 instead. > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From robert.kern at gmail.com Mon Feb 8 15:52:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Feb 2010 14:52:20 -0600 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples In-Reply-To: References: Message-ID: On 2010-02-08 14:36 PM, Dave Peterson wrote: > Page 7: Very first example doesn't compile: syntax error > Pate 11: 2nd example: syntax error > Page 12, printing digits: syntax error > Page 13, printing a number: syntax error > page 14, statements: syntax error This book was written for the 2.x versions of Python. Are you using Python 3.1? Python changed some of its syntax for version 3.0, notably print "Hello, world!" becomes print("Hello, world!") This accounts for all of the SyntaxErrors that you are seeing. The examples aren't broken for the version of Python it is teaching. You may want to try _Dive Into Python 3_ to learn about Python 3 in particular: http://diveintopython3.org/ -- 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 andrej.mitrovich at gmail.com Mon Feb 8 15:53:00 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 8 Feb 2010 12:53:00 -0800 (PST) Subject: Awful book warning: How to think like a (Python) programmer - non-working examples References: Message-ID: The book covers Python 2.x syntax. You might have downloaded Python 3.1, which has different syntax then Python 2.x. From what I can tell, the first example on page 7 is ">>> print 1 + 1". Try issuing this command: print(1 + 1) If everything goes well, and you get '2' as the answer, then you're probably using Python 3.x. You will have to download the Python 2.x binaries from the Python website, install Python 2.x, and try the example from the book again. From vim at aryehleib.com Mon Feb 8 15:54:15 2010 From: vim at aryehleib.com (Aryeh Leib Taurog) Date: Mon, 8 Feb 2010 12:54:15 -0800 (PST) Subject: glibc detected double free or corruption Message-ID: <2e4cd5eb-decf-43a9-8d2e-8d3b99134d50@19g2000yql.googlegroups.com> I'm encountering the following error on my fastcgi web server and would greatly appreciate ANY pointers for debugging/fixing this problem. *** glibc detected *** /usr/bin/python2.5: double free or corruption (fasttop): 0x08b47d60 *** If I don't set MALLOC_CHECK_ then the server just hangs and the above message appears in the fastcgi error log. With MALLOC_CHECK_=0 I get an error message in the browser instead. I'm using the following components (on a shared hosting account): Debian lenny 64 bit Python 2.5.2 lighttpd 1.4.19 Django 1.1.1 latest flup (today's hg tip, flup-server-ae5fe54fba18) postgresql 8.3.9 psycopg2 2.0.13 What's interesting about the problem is it seems to happen only when new fcgi processes are spawned and only when a db query is made. That is, the frequency of the problem corresponds exactly with the maxrequests setting on my fcgi process. If I set maxrequests to 1 then I get this error for each request that hits the database. If I set it to 3 then I get the error with every third request, if that request hits the database. If I put Django into DEBUG and set MALLOC_CHECK_=0 then I get the following error with traceback: Exception Type: OperationalError Exception Value: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. Exception Location: /home/altaurog/django/db/backends/util.py in execute, line 19 Regardless of which url/view I request, the exception always is raised on a sql execute statement. --- Aryeh Leib Taurog From Martin.Drautzburg at web.de Mon Feb 8 15:59:18 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Mon, 08 Feb 2010 21:59:18 +0100 Subject: Ternary plus Message-ID: <1475043.2616QT5JLn@beaureve.gmx.net> Just for the hell of it ... I can easily define __plus__() with three parameters. If the last one is optional the + operation works as expected. Is there a way to pass the third argument to "+" From vinay_sajip at yahoo.co.uk Mon Feb 8 16:13:33 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 8 Feb 2010 13:13:33 -0800 (PST) Subject: Simulating logging.exception with another traceback References: <0c13d3f7-addf-4972-91c3-6f41fadfb2b5@u26g2000yqm.googlegroups.com> Message-ID: <3512c1a4-01e3-449d-8e48-e673e668bb17@u26g2000yqm.googlegroups.com> On Feb 7, 11:22?am, Joan Miller wrote: > I would want to get the output from `logging.exception` but with > traceback from the caller function (I've already all that > information). > > This would be the error withlogging.exception: > -------------------- > ERROR: > ? PipeError('/bin/ls -l | ?', 'no command after of pipe') > Traceback (most recent call last): > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > 160, in __call__ > ? ? raise PipeError(command, 'no command after of pipe') > PipeError: ('/bin/ls -l | ?', 'no command after of pipe') > -------------------- > > And I've trying it with: > -------------------- > message = "File \"{0}\", line {1}, in {2}\n\n ?{3}".format( > ? ? ? ? ? ? ? ? file, line, function, caller)logging.error(message) > > ERROR: > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > ? 163, in __call__ ? ?return self.throw(PipeError, command, 'no > ? command after of pipe') > -------------------- > > Could be used `logging.LogRecord` [1] to get it? How? > > [1]http://docs.python.org/library/logging.html#logging.LogRecord Sorry, Joan, I don't understand your question. Can you create a short script which throws an exception, and show exactly how you want it formatted? The logger.exception method does the same as logger.error, except that it prints exception trace information and is intended to be called from exception handling clauses. You can format exceptions how you like by subclassing Formatter and overriding formatException. Regards, Vinay Sajip From dmalcolm at redhat.com Mon Feb 8 16:14:08 2010 From: dmalcolm at redhat.com (David Malcolm) Date: Mon, 08 Feb 2010 16:14:08 -0500 Subject: Awful book warning: How to think like a (Python) programmer - non-working examples In-Reply-To: References: Message-ID: <1265663648.25625.233.camel@brick> On Mon, 2010-02-08 at 12:53 -0800, Andrej Mitrovic wrote: > The book covers Python 2.x syntax. > > You might have downloaded Python 3.1, which has different syntax then > Python 2.x. From what I can tell, the first example on page 7 is ">>> > print 1 + 1". > > Try issuing this command: > print(1 + 1) > > If everything goes well, and you get '2' as the answer, then you're > probably using Python 3.x. You will have to download the Python 2.x > binaries from the Python website, install Python 2.x, and try the > example from the book again. Sorry to nitpick; the main thrust of the above sounds correct, in that: print 1 + 1 works in Python 2 but fails in Python 3, but, a minor correction, note that: print(1+1) does work in Python 2 as well as in Python 3; the parentheses are treated (in the former) as denoting grouping of a subexpression, rather than function invocation (in the latter): Python 2.6.2 (r262:71600, Jan 25 2010, 13:22:47) [GCC 4.4.2 20100121 (Red Hat 4.4.2-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print(1+1) 2 This can be useful if you're trying to write short fragments of code that work with both. Look at the startup message, or run this command, which should work on both python2 and python3: import sys; print(sys.version) Hope this is helpful Dave From andrej.mitrovich at gmail.com Mon Feb 8 16:27:00 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Mon, 8 Feb 2010 13:27:00 -0800 (PST) Subject: Awful book warning: How to think like a (Python) programmer - non-working examples References: Message-ID: On Feb 8, 10:14?pm, David Malcolm wrote: > On Mon, 2010-02-08 at 12:53 -0800, Andrej Mitrovic wrote: > > The book covers Python 2.x syntax. > > > You might have downloaded Python 3.1, which has different syntax then > > Python 2.x. From what I can tell, the first example on page 7 is ">>> > > print 1 + 1". > > > Try issuing this command: > > print(1 + 1) > > > If everything goes well, and you get '2' as the answer, then you're > > probably using Python 3.x. You will have to download the Python 2.x > > binaries from the Python website, install Python 2.x, and try the > > example from the book again. > > Sorry to nitpick; the main thrust of the above sounds correct, in that: > ? ? print 1 + 1 > works in Python 2 but fails in Python 3, but, a minor correction, note > that: > ? ? print(1+1) > does work in Python 2 as well as in Python 3; the parentheses are > treated (in the former) as denoting grouping of a subexpression, rather > than function invocation (in the latter): > > Python 2.6.2 (r262:71600, Jan 25 2010, 13:22:47) > [GCC 4.4.2 20100121 (Red Hat 4.4.2-28)] on linux2 > Type "help", "copyright", "credits" or "license" for more information.>>> print(1+1) > > 2 > > This can be useful if you're trying to write short fragments of code > that work with both. > > Look at the startup message, or run this command, which should work on > both python2 and python3: > ? import sys; print(sys.version) > > Hope this is helpful > Dave Oops, you're right. I'm used to Python 3 syntax so I'm only aware of some basic differences. :) From aahz at pythoncraft.com Mon Feb 8 16:28:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 13:28:03 -0800 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: In article <0efe23a6-b16d-4f92-8bc0-12d056bf599d at z26g2000yqm.googlegroups.com>, OdarR wrote: > >and with eval(), did you try ? WARNING: eval() is almost always the wrong answer to any question -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From robert.kern at gmail.com Mon Feb 8 16:28:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 08 Feb 2010 15:28:54 -0600 Subject: Ternary plus In-Reply-To: <1475043.2616QT5JLn@beaureve.gmx.net> References: <1475043.2616QT5JLn@beaureve.gmx.net> Message-ID: On 2010-02-08 14:59 PM, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" No. -- 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 gherron at islandtraining.com Mon Feb 8 16:35:10 2010 From: gherron at islandtraining.com (Gary Herron) Date: Mon, 08 Feb 2010 13:35:10 -0800 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <4B70838E.4070700@islandtraining.com> spike wrote: > Has anyone been able to come across a Python logic map or Python logic > flow chart? > > An example can be seen on the right under History: > http://en.wikipedia.org/wiki/Usenet#History > > This would be very helpful for all users. > Huh??? What aspect of Python were you thinking of mapping out? Your example us a bad ascii art graph of -- I've no clue what? Gary Herron From olivier.darge at gmail.com Mon Feb 8 16:39:33 2010 From: olivier.darge at gmail.com (OdarR) Date: Mon, 8 Feb 2010 13:39:33 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> On 8 f?v, 22:28, a... at pythoncraft.com (Aahz) wrote: > In article <0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, > > OdarR ? wrote: > > >and with eval(), did you try ? > > WARNING: eval() is almost always the wrong answer to any question warning : it works ! another question ? > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > import antigravity From andrew.degtiariov at gmail.com Mon Feb 8 16:39:42 2010 From: andrew.degtiariov at gmail.com (Andrew Degtiariov) Date: Mon, 8 Feb 2010 23:39:42 +0200 Subject: Import question In-Reply-To: References: <5d1b76f61002050821p10d2b302wcf90d410b92f419@mail.gmail.com> <5d1b76f61002080137o6e3f9a1fjdab8bcf8d3959faf@mail.gmail.com> Message-ID: <5d1b76f61002081339u5648906bp282e5e7bddde1760@mail.gmail.com> Those are called namespace packages. Zope and Plone (ab)use them > extensively. The intended usage is to break up a big, monolithic package > [0] in parts that can be distributed independently. To implement a > namespace package, you need an empty __init__.py file with only these > lines [1]: > > from pkgutil import extend_path > __path__ = extend_path(__path__, __name__) > > But think carefully if you really need namespace packages; they solve a > specific problem, aren't a general purpose technique. See [2] for a > discussion. > > [0] Think of a huge behemoth with a "Z O P E" sign on both sides :) > [1] http://docs.python.org/library/pkgutil.html > [2] http://weblion.psu.edu/news/are-we-overusing-namespace-packages > > Hm.. We are using pkg_resources.declare_namespace(__name__) but I think pkgutil is much better. And we are using buildout so the omelette might help me. Link [2] very interesting. Thank you, Gabrial. -- Andrew Degtiariov DA-RIPE -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Mon Feb 8 16:40:33 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Feb 2010 10:40:33 +1300 Subject: The Case For Do-Once References: Message-ID: In message , Lawrence D'Oliveiro wrote: > The basic control flow is this: > * Unconditionally initialize all dynamic storage to nil > * Do the main body of the code, aborting in any error > * Regardless of success or failure of the above, dispose of all > allocated dynamic storage, using disposal calls which turn into > noops if passed pointers that are already nil. For more examples, see the spuhelper.c module here . From davodavo2 at gmail.com Mon Feb 8 16:47:52 2010 From: davodavo2 at gmail.com (Davo) Date: Mon, 8 Feb 2010 13:47:52 -0800 (PST) Subject: Read PGM's with more than 256 range in PIL1.1.7 Message-ID: <24a311e0-963e-43a5-9d8f-3a573dbf5fe2@m35g2000prh.googlegroups.com> I have a PGM format image file with 4096 range. When I reads it with PIL, I get an image with 8-bit values and alternate columns are zero. Does PIL support reading and writing PGM's with more than 8-bits? Davo From mensanator at aol.com Mon Feb 8 17:31:48 2010 From: mensanator at aol.com (Mensanator) Date: Mon, 8 Feb 2010 14:31:48 -0800 (PST) Subject: Stephen -- Bruce? References: <2a932e46-1b81-4a97-bbee-3bf92b3b1447@l19g2000yqb.googlegroups.com> <4b6fd308$0$6722$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <54742c54-bf2d-4228-ad7c-d1dca1858775@m16g2000yqc.googlegroups.com> On Feb 8, 3:02?am, Stefan Behnel wrote: > Mensanator, 05.02.2010 00:36: > > > On Feb 4, 5:13 pm, "Alf P. Steinbach" wrote: > >> What's this about all the Stephen'ses here? > > >> Shouldn't it be Bruce? > > > Of course. We just call everyone Stephen to avoid confusion. > > Some people even manage to adapt the spellings accordingly. > > Stefan You appear to be confused. From aahz at pythoncraft.com Mon Feb 8 17:36:47 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 14:36:47 -0800 Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: In article , Sean DiZazzo wrote: >On Feb 3, 6:08=A0pm, alex23 wrote: >> >> There was also a PEP with another possible implementation: >> http://www.python.org/dev/peps/pep-0355/ > >Why did Path() get rejected? Is it the idea itself, or just the >approach that was used? What are the complaints? You should search for the discussiona around it. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Mon Feb 8 17:43:46 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 14:43:46 -0800 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: In article <5790c33c-13d0-4596-91b0-b3c9aeebf637 at f8g2000yqn.googlegroups.com>, OdarR wrote: >On 8 f=E9v, 22:28, a... at pythoncraft.com (Aahz) wrote: >> In article <0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups= >.com>, >> OdarR =A0 wrote: >>> >>>and with eval(), did you try ? >> >> WARNING: eval() is almost always the wrong answer to any question > >warning : it works ! Works for what? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From phlip2005 at gmail.com Mon Feb 8 17:46:36 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 14:46:36 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: <9a2b87ca-abd4-4d5d-9fca-9ebee8a44730@m35g2000prh.googlegroups.com> On Feb 8, 2:36?pm, a... at pythoncraft.com (Aahz) wrote: > >> There was also a PEP with another possible implementation: > >>http://www.python.org/dev/peps/pep-0355/ > > >Why did Path() get rejected? ?Is it the idea itself, or just the > >approach that was used? ?What are the complaints? > > You should search for the discussiona around it. I, OTOH, am burning rubber with Python 2.6.1, so leading edge concerns are not mine - yet! I went with this version, generously ripped out & plopped into our project: # URL: http://www.jorendorff.com/articles/python/path # Author: Jason Orendorff (and others - see the url!) # Date: 7 Mar 2004 class path(_base): """ Represents a filesystem path. """ Gods bless http://www.google.com/codesearch, huh?! -- Phlip http://c2.com/cgi/wiki?ZeekLand From python at mrabarnett.plus.com Mon Feb 8 17:50:02 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 08 Feb 2010 22:50:02 +0000 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: <4B70951A.90805@mrabarnett.plus.com> geremy condra wrote: > On Mon, Feb 8, 2010 at 12:07 PM, mk wrote: >> Steven D'Aprano wrote: >>> On Fri, 05 Feb 2010 18:29:07 +0100, mk wrote: >>> >>>> Ethan Furman wrote: >>>> >>>>> http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/ >>> choose_python.pdf >>>> Choose to get your difficult questions about threads in Python ignored. >>>> Oh well.. >>> With an attitude like that, you're damn lucky if you don't get kill- >>> filed. It was SIX MINUTES since you posted your question about timers, >>> what did you expect? >> I didn't expect immediate answer to this particular question. I have >> repeatedly asked many questions about threads in the past, and IIRC every >> one of them was ignored. >> >>> Threads are hard, and many people don't use them at all. You might never >>> get an answer, even without alienating people. Complaining after six DAYS >>> might be acceptable, if you do it with a sense of humour, but after six >>> minutes? >> Well, it's 4 days now. I would be happy to get 50% response rate. Apparently >> nobody is really using threads. >> >> regards, >> mk > > I use threads. > So do I, where appropriate. From aahz at pythoncraft.com Mon Feb 8 17:50:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 14:50:21 -0800 Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: In article <28c6967f-7637-4823-aee9-15487e1ce98b at o28g2000yqh.googlegroups.com>, Julian wrote: > >I want to design a poster for an open source conference, the local >usergroup will have a table there, and in the past years there were >some people that came to the python-table just to ask "why should I >use python?". Readability -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Mon Feb 8 18:24:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 8 Feb 2010 15:24:01 -0800 Subject: Building a multiline string References: Message-ID: In article , lallous wrote: > >x = ( >"line1" # can use comments >"line2" >"line3" >) You should indent the second and following lines (I changed the name to "xyz" to make clear that the following lines use a regular Python indent rather than lining up under the open paren): xyz = ( "line1" # can use comments "line2" "line3" ) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From steve at REMOVE-THIS-cybersource.com.au Mon Feb 8 18:46:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 08 Feb 2010 23:46:47 GMT Subject: ANN: obfuscate Message-ID: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> I am pleased to announce the first public release of obfuscate 0.2.2a. http://pypi.python.org/pypi/obfuscate/0.2.2a obfuscate is a pure-Python module providing classical encryption algorithms suitable for obfuscating and unobfuscating text. obfuscate includes the following ciphers: - Caesar, rot13, rot5, rot18, rot47 - atbash - Playfair, Playfair6 and Playfair16 - Railfence (encryption only) - Keyword - Affine - Vigenere - frob (xor) and others. DISCLAIMER: obfuscate is not cryptographically strong, and should not be used where high security is required. (The ciphers provided in obfuscate may have been state of the art centuries ago, but should not be used where strong encryption is required. obfuscate is released under the MIT licence. Requires Python 2.5 or 2.6. -- Steven D'Aprano From pavlovevidence at gmail.com Mon Feb 8 19:26:18 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 16:26:18 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> On Feb 4, 7:10?pm, Sean DiZazzo wrote: > On Feb 3, 6:08?pm, alex23 wrote: > > > > > On Feb 4, 8:47?am, Phlip wrote: > > > > Yes, calling os.path.walk() and os.path.join() all the time on raw > > > strings is fun, but I seem to recall from my Ruby days a class called > > > Pathname, which presented an object that behaved like a string at > > > need, and like a filesystem path at need. path + 'folder' would > > > call .join() and insert the / correctly, for example. > > > > What's the best equivalent in Python-land? > > > It's no longer supported, but the 3rd party 'path' module used to be > > the go-to module for this: > > > >>> from path import path > > > C:\Python26\lib\site-packages\path.py:32: DeprecationWarning: the md5 > > module is deprecated; use hashlib instead > > ? import sys, warnings, os, fnmatch, glob, shutil, codecs, md5>>> c = path('C:\\') > > >>> c.listdir() > > > [path(u'C:\\AUTOEXEC.BAT'), path(u'C:\\boot.ini'), ...]>>> (c + 'python26').listdir() > > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > > \python26\\DLLs'), ...]>>> (c / 'python26').listdir() > > > [path(u'C:\\python26\\circuits.pth_disabled_for_egg'), path(u'C:\ > > \python26\\DLLs'), ...] > > > I've hand edited the results for brevity... > > > The module could do with some TLC to bring it up to date, but warning > > aside it still seems to work fine under 2.6. > > > (From memory, I think the original author gave up when it became clear > > it would never be integrated into the standard lib[1], which is a > > shame, I think there's scope for a pathtools addition to the lib that > > provides this level of convenience...) > > > There was also a PEP with another possible implementation:http://www.python.org/dev/peps/pep-0355/ > > > Hope this helps. > > It's too bad that something like this can't be agreed to. ?I used a > homegrown module like this for a couple of years in my early days with > python. ?It was great, but I didn't know enough at the time to make it > really useful. > > Why did Path() get rejected? ?Is it the idea itself, or just the > approach that was used? ?What are the complaints? I don't know if it was the reason it was rejected, but a seriously divisive question is whether the path should be a subset of string. Under ordinary circumstances it would be a poor choice for inheritance (only a few string methods would be useful fot a pathname), but some people were fiercely adamant that paths should be passable to open() as-in (without having to explicity convert to string). IIRC, the guy who maintained path wavered between subclassing and not subclassing str. I don't remember if the idea of modifying open to accept path objects came up. Carl Banks From lists at cheimes.de Mon Feb 8 19:29:01 2010 From: lists at cheimes.de (Christian Heimes) Date: Tue, 09 Feb 2010 01:29:01 +0100 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B70AC4D.6040008@cheimes.de> Steven D'Aprano schrieb: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) Nice work! Your work should be interesting for everybody who has read Simon Sing's "The Code Book: The Science of Secrecy from Ancient Egypt to Quantum". Christian From debatem1 at gmail.com Mon Feb 8 19:37:52 2010 From: debatem1 at gmail.com (geremy condra) Date: Mon, 8 Feb 2010 19:37:52 -0500 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: On Mon, Feb 8, 2010 at 6:46 PM, Steven D'Aprano wrote: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > ?- Caesar, rot13, rot5, rot18, rot47 > ?- atbash > ?- Playfair, Playfair6 and Playfair16 > ?- Railfence (encryption only) > ?- Keyword > ?- Affine > ?- Vigenere > ?- frob (xor) > > and others. > > DISCLAIMER: obfuscate is not cryptographically strong, and should not be > used where high security is required. (The ciphers provided in obfuscate > may have been state of the art centuries ago, but should not be used > where strong encryption is required. > > obfuscate is released under the MIT licence. > > Requires Python 2.5 or 2.6. > > > -- > Steven D'Aprano > -- > http://mail.python.org/mailman/listinfo/python-list > Nice! Maybe someday you can extend it with a pen-and-paper signature scheme ;) Geremy Condra From alfps at start.no Mon Feb 8 19:44:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 01:44:35 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: * alex23: > "Alf P. Steinbach" wrote: >> Hm. While most everything I've seen at effbot.org has been clear and to the >> point, that particular article reads like a ton of obfuscation. > > Must. Resist. Ad hominem. > >> Python passes pointers by value, just as e.g. Java does. >> >> There, it needed just 10 words or so. :-) > > 10 words _plus_ an understanding of Java. No, one only needs an understanding of "pointer". "Pointer" is a mostly language independent concept. The reference to the Java language spec, where that term is used for this, was just an unsuccessful attempt to keep out word-play arguments based on the incompatibility of some incompatible meaning of "pointer"... Cheers & hth., - Alf From sccolbert at gmail.com Mon Feb 8 20:08:00 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 8 Feb 2010 20:08:00 -0500 Subject: Read PGM's with more than 256 range in PIL1.1.7 In-Reply-To: <24a311e0-963e-43a5-9d8f-3a573dbf5fe2@m35g2000prh.googlegroups.com> References: <24a311e0-963e-43a5-9d8f-3a573dbf5fe2@m35g2000prh.googlegroups.com> Message-ID: <7f014ea61002081708w362fc0ccr26019221660ac5e3@mail.gmail.com> According the pil manual it handles PGM files with "'1', 'L', or 'RGB' data" which leads me to believe 16bit data is not supported. You CAN write your own decoder for that though: http://www.pythonware.com/library/pil/handbook/decoder.htm It would be trivial to write a decoder for the pgm format. On Mon, Feb 8, 2010 at 4:47 PM, Davo wrote: > I have a PGM format image file with 4096 range. When I reads it with > PIL, I get an image with 8-bit values and alternate columns are zero. > Does PIL support reading and writing PGM's with more than 8-bits? > > Davo > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:31:35 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:31:35 GMT Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: On Mon, 08 Feb 2010 18:07:56 +0100, mk wrote: >> Threads are hard, and many people don't use them at all. You might >> never get an answer, even without alienating people. Complaining after >> six DAYS might be acceptable, if you do it with a sense of humour, but >> after six minutes? > > Well, it's 4 days now. I would be happy to get 50% response rate. > Apparently nobody is really using threads. Please see my response to your post "timer for a function". -- Steven From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:36:48 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:36:48 GMT Subject: timer for a function References: Message-ID: On Fri, 05 Feb 2010 18:23:09 +0100, mk wrote: [...] > On paramiko mailing list I got the suggestion to build a timer and then > quit this by myself: > >> The timeout option in connect() is for the socket, not for the entire >> operation. You are connected, so that timeout is no longer relevant. >> You would probably have to wrap the transport.connect() method in a >> timer to break out of this early. > > Question: how can I do that? Use another threaded class? Is there some > other way? I don't use threads enough (or at all) to answer that question directly, but I can point you at these. Hopefully they will help, or at least give you some ideas: http://code.activestate.com/recipes/534115/ http://code.activestate.com/recipes/473878/ Found by googling for "python timeout any function". > Additional snag is SSHClient() is a class that internally uses threads. > How do I kill brutally its threads? Is there any way to do it? You can't kill threads in Python. You have to ask them nicely to die. Google on "python kill thread" for more. -- Steven From aonlazio at gmail.com Mon Feb 8 20:39:58 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Mon, 8 Feb 2010 20:39:58 -0500 Subject: Programing family Message-ID: I have thought funny things If we think all languages are like a family I could draft them like this (Python base) C is Python's Mom C++ : Dad Pascal/Assembly : Grandparents C# : Uncle Java : Ant Ruby: Cousin Perl : Girlfriend What u guys think? XD -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:49:39 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:49:39 GMT Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> Message-ID: On Mon, 08 Feb 2010 21:59:18 +0100, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" How do you give three operands to a binary operator? Binary operators only have two sides, a left and a right, so you can only fit two operands around them. Mathematicians solve this problem by using functions: add(a, b, c, d) In Python, you can do this: >>> class F: ... def __add__(self, other, foo=None): ... print self, other, foo ... return 1 ... >>> >>> F() + 3 <__main__.F instance at 0xb7f06f4c> 3 None 1 >>> F().__add__(3, 4) <__main__.F instance at 0xb7f06d8c> 3 4 1 but if you do, people will laugh and point at you in the street. *wink* -- Steven From jeanmichel at sequans.com Mon Feb 8 20:50:13 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 02:50:13 +0100 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <4B70BF55.90704@sequans.com> Aahz wrote: > In article <0efe23a6-b16d-4f92-8bc0-12d056bf599d at z26g2000yqm.googlegroups.com>, > OdarR wrote: > >> and with eval(), did you try ? >> > > WARNING: eval() is almost always the wrong answer to any question > Some say that eval is evil ! JM From steven at REMOVE.THIS.cybersource.com.au Mon Feb 8 20:51:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 01:51:01 GMT Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: On Mon, 08 Feb 2010 14:43:46 -0800, Aahz wrote: >>> WARNING: eval() is almost always the wrong answer to any question >> >>warning : it works ! > > Works for what? Code injection security bugs, of course. http://en.wikipedia.org/wiki/Code_injection It is surprisingly difficult to sanitize strings in Python to make them safe to pass to eval. Unless you are prepared to trust the input data explicitly, it's best to just avoid eval. -- Steven From apt.shansen at gmail.com Mon Feb 8 20:55:44 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 17:55:44 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> Message-ID: <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> On Mon, Feb 8, 2010 at 4:44 PM, Alf P. Steinbach wrote: > No, one only needs an understanding of "pointer". > > "Pointer" is a mostly language independent concept. > > The reference to the Java language spec, where that term is used for this, > was just an unsuccessful attempt to keep out word-play arguments based on > the incompatibility of some incompatible meaning of "pointer"... > The fact is, "pointer" is not really a language independent concept. Just because a concept is used in multiple languages doesn't make it a general purpose term that has a clear meaning that's defined in a well-understood way. The last time I paid attention to one of your semantic arguments was when you were talking about "routine", where that -was- a language independent concept, but as wholly inappropriate to use in context of Python as pass-by-value (especially due to ambiguity). You seem to have an idea of a word in your head and a meaning and context, and are ignoring the fact that there's a huge body of knowledge that places another context or meaning on that word or phrase. Thus, the usage of that phrase actually -confuses- and does not -clarify-. The terms "call by reference" and "call by value" have *meaning* beyond the purely abstract: they have meaning to semantics that people expect when you use them, meaning to how the language works, and those meanings do *not* apply to Python. Python doesn't have pointers. That you can do id() and see something like a memory address is a CPython implementation detail which is not guaranteed and the fact that Python is implemented -in- a language which -does- have pointers, and that implementation uses pointers beneath the Python level. But the Python language (and CPython implementation) does -not- provide pointers to us. We do not use pointers in any Python code we do. To say, "pass by value" implies things to people. It describes a sort of world where I'm a function about to do some work, and on my desk I have a series of boxes with names on it. It describes an environment where someone comes over and drops something into each of my boxes. The contents of these boxes are mine alone! To say, "pass by reference" implies other things to people. It describes a sort of world where my desk doesn't have any boxes, really. It's got some places for boxes, but when someone gives me something? They give me their boxes too. The actual -stuff- in them I can swap between the two boxes if I want, and when I give those boxes back to the one who called me? They'll be swapped. That's a sort of defining characteristic of pass-by-reference environments. _Neither_ of these are accurate descriptions of Python's universe. You can say, "its pass by value, just be specific that the value is..." but at that point the statement is meaningless. You've taken a relatively well-understood statement with certain meaning and a semantic weight behind what it means, and just totally made it into something else entirely. By changing the entire meaning of "value", from the value of the variable which is copied, to the value of the memory address, you've changed -everything- that 'pass by value' means. So you should use a different word. Like, "objects" (or "sharing" is also used.) Python has names, and objects. The guy over there has things on his desk, with a label attached to it that has a name. He tosses it over to me, and I get the same object he did-- no boxes. I put my own label on it, even though he keeps hold of his label. I fiddle with it, and might toss it back. Or might not, maybe I'll toss something else back. Either way, he still has it. In Python, we get objects. Real objects. The original one. Its not a pointer, its an object, that happens to have a label attached to it. It doesn't have any idea what that label is, and it can't even find out. Its not in any boxes owned by any functions, its just floating out there with everything else, with lots of labels tied to it. Its just that when the last one is cut, nothing else is holding it up, and it falls to the ground and gets swept away. That python is pass-by-objects is -really- important for people to understand to really "get" python, and using other terms is /bad/ because it makes them think of the semantics those terms imply. Because if you don't -remember- and just instinctively -know- that Python is "pass-by-objects", you'll forget the difference between passing an immutable and a mutable object into a function, and be surprised by the result. >>> import copy >>> def doit(a): ... a += a ... return a ... >>> test1 = 1 >>> test2 = doit(test1) >>> test1 1 >>> test2 2 >>> test3 = [1] >>> test4 = doit(test3) >>> test3 [1, 1] >>> test4 [1, 1] I know you already know this, but the point is: you're -hurting- other peoples understanding by using terms like this that don't apply to Python's specific nature. In Python, every function gets the original objects that you pass into it. Some are immutable, some are mutable. With immutable ones, it might very well seem like its pass-by-value and behaves like pass-by-value semantics, but when you get mutable objects, that changes /quickly/. Changing "value" to mean, "the memory address where the object is stored" just obfuscates the entire point and doesn't actually explain what people need to understand in this question. --S P.S. I couldn't resist. :( -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Feb 8 21:03:32 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:03:32 -0800 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: <7a9c25c21002081803n858a715wc9baace9f6210c04@mail.gmail.com> On Mon, Feb 8, 2010 at 5:51 PM, Steven D'Aprano < steven at remove.this.cybersource.com.au> wrote: > On Mon, 08 Feb 2010 14:43:46 -0800, Aahz wrote: > > >>> WARNING: eval() is almost always the wrong answer to any question > >> > >>warning : it works ! > > > > Works for what? > > Code injection security bugs, of course. > > http://en.wikipedia.org/wiki/Code_injection > > It is surprisingly difficult to sanitize strings in Python to make them > safe to pass to eval. Unless you are prepared to trust the input data > explicitly, it's best to just avoid eval. > I'd make it a bit stronger: unless you are prepared to trust the input data explicitly, and forever-- and extending that trust to whomever might in the future be hired to work along, beside, under, or instead of you-- including the fact that they may use your system or code in a different or new way to get the data-- or how you may in the future decide to grow your system in ways you're not today prepared for and are committed to do a complete review of your entire codebase on every such change to ensure you don't leak some potentially bad data down into such a place-- then you can use eval. Otherwise, other solutions are better. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Mon Feb 8 21:16:04 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:16:04 -0800 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: <7a9c25c21002081816r3b7a7c4fq5b079424dbd1f46e@mail.gmail.com> On Fri, Feb 5, 2010 at 7:25 AM, mk wrote: > Hello everyone, > > I have a problem with a threaded program: it frequently hangs on sys.exit. > I use threads all the time (well, for certain types of workloads) and have never seen this. Are your threads daemon threads? The only time I've seen sys.exit() not close out my program is when I'm launching non-daemon threads on accident. Now, I do get some slightly random errors on close due to threads doing stuff or returning from doing stuff while the shutdown procedure is going on, but I don't really care, cuz, well, I'm shutting everything down and nothing worth knowing is going on in the rest of the program. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Mon Feb 8 21:19:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 08 Feb 2010 20:19:57 -0600 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4B70C64D.3020908@tim.thechases.com> Steven D'Aprano wrote: > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) I prefer the strength of Triple ROT-13 for my obfuscation needs, but I don't see it listed here. I guess I'll have to roll my own despite the dire warnings against amateur cryptographers authoring their own unvetted implementations. ;-) -tkc From sccolbert at gmail.com Mon Feb 8 21:29:50 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 8 Feb 2010 21:29:50 -0500 Subject: ANN: obfuscate In-Reply-To: <4B70C64D.3020908@tim.thechases.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <4B70C64D.3020908@tim.thechases.com> Message-ID: <7f014ea61002081829i2333f8b3y791485074e35b4ca@mail.gmail.com> I always though a double rot13 followed by a rot26 was the best? On Mon, Feb 8, 2010 at 9:19 PM, Tim Chase wrote: > Steven D'Aprano wrote: > >> obfuscate is a pure-Python module providing classical encryption >> algorithms suitable for obfuscating and unobfuscating text. >> >> obfuscate includes the following ciphers: >> - Caesar, rot13, rot5, rot18, rot47 >> - atbash >> - Playfair, Playfair6 and Playfair16 >> - Railfence (encryption only) >> - Keyword >> - Affine >> - Vigenere >> - frob (xor) >> > > I prefer the strength of Triple ROT-13 for my obfuscation needs, but I > don't see it listed here. I guess I'll have to roll my own despite the dire > warnings against amateur cryptographers authoring their own unvetted > implementations. ;-) > > -tkc > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Feb 8 21:42:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 08 Feb 2010 21:42:53 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: Stephen Hansen wrote: [...] > P.S. I couldn't resist. :( > And here I was, sitting on my hands ... but someone was wrong on the Internet, so D'Aprano had to put them right. Your fatal weakness. Of course this won't make the slightest difference. "'When I use a word,' said Humpty ..." regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Mon Feb 8 21:44:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:44:17 -0800 Subject: timer for a function In-Reply-To: References: Message-ID: <7a9c25c21002081844h5a280e94k794ddc5d0df77610@mail.gmail.com> On Fri, Feb 5, 2010 at 9:23 AM, mk wrote: > On paramiko mailing list I got the suggestion to build a timer and then > quit this by myself: > > The timeout option in connect() is for the socket, not for the entire >> operation. You are connected, so that timeout is no longer relevant. >> You would probably have to wrap the transport.connect() method in a >> timer to break out of this early. >> > > Question: how can I do that? Use another threaded class? Is there some > other way? > What OS? Does this have to be OS-independant? Are you using more then one transport/SSLClient in your process and you want to just kill one (and any of its child threads), or are you doing one per process? If you want to terminate -all- threads your process is running in a given timeframe, using a SIGALRM in the signal module will do it, I believe-- provided you don't need to support windows. I had a contextlib manager do that for awhile. If you only want to terminate one (and its child-threads)... you're out of luck, I think. The only way to terminate a thread in Python is with conditions/events/whatever and the thread cooperating and exiting on its own. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Mon Feb 8 21:46:05 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 18:46:05 -0800 (PST) Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> Message-ID: <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> On Feb 8, 12:59?pm, Martin Drautzburg wrote: > Just for the hell of it ... > > I can easily define __plus__() with three parameters. If the last one is > optional the + operation works as expected. Is there a way to pass the > third argument to "+" If, for some reason, you wanted to define a type for which it makes sense to "add" three objects, but not two, you can get the effect you want, kind of. (a + b + c) is useful (a + b) is meaningless You can have __add__ return a closure for the first addition, then perform the operation on the second one. Example (untested): class Closure(object): def __init__(self,t1,t2): self.t1 = t1 self.t2 = t2 def __add__(self,t3): # whole operation peformed here return self.t1 + self.t2 + t3 class MySpecialInt(int): def __add__(self,other): return Closure(self,other) I wouldn't recommend it. Just use a function call with three arguments. Carl Banks From apt.shansen at gmail.com Mon Feb 8 21:48:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 18:48:02 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden wrote: > Stephen Hansen wrote: > [...] > > P.S. I couldn't resist. :( > > > > And here I was, sitting on my hands ... but someone was wrong on the > Internet, so D'Aprano had to put them right. Your fatal weakness. > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." > This is getting out of hand. First, someone thought I was you. Now you think I'm D'Aprano. I'm just gonna go by Bob for now on. :) --B -------------- next part -------------- An HTML attachment was scrubbed... URL: From pavlovevidence at gmail.com Mon Feb 8 21:55:17 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 18:55:17 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> On Feb 8, 12:20?pm, spike wrote: > Has anyone been able to come across a Python logic map or Python logic > flow chart? > > An example can be seen on the right under History:http://en.wikipedia.org/wiki/Usenet#History > > This would be very helpful for all users. Begin | | V Start Editor | | V Write Code <----+ | | | | V | Run Python | | | | | No. V | Did it do what you want? | | Yes. | V Stop. HTH. Carl Banks From pavlovevidence at gmail.com Mon Feb 8 21:57:19 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Mon, 8 Feb 2010 18:57:19 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <0dc66912-76de-4979-b98d-8358436b8ee8@d37g2000yqa.googlegroups.com> On Feb 8, 1:35?pm, Gary Herron wrote: > spike wrote: > > Has anyone been able to come across a Python logic map or Python logic > > flow chart? > > > An example can be seen on the right under History: > >http://en.wikipedia.org/wiki/Usenet#History > > > This would be very helpful for all users. > > Huh??? ?What aspect of Python were you thinking of mapping out? > > Your example us a bad ascii art graph of -- I've no clue what? Usenet servers. Back in the day people had these in their .sigfiles Carl Banks From python at mrabarnett.plus.com Mon Feb 8 22:07:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 09 Feb 2010 03:07:55 +0000 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> Message-ID: <4B70D18B.5040008@mrabarnett.plus.com> Stephen Hansen wrote: > On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden > wrote: > > Stephen Hansen wrote: > [...] > > P.S. I couldn't resist. :( > > > > And here I was, sitting on my hands ... but someone was wrong on the > Internet, so D'Aprano had to put them right. Your fatal weakness. > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." > > > This is getting out of hand. > > First, someone thought I was you. > > Now you think I'm D'Aprano. > > I'm just gonna go by Bob for now on. > > :) > > --B > Bruce would be less confusing. :-) From apt.shansen at gmail.com Mon Feb 8 22:17:48 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 19:17:48 -0800 Subject: Modifying Class Object In-Reply-To: <4B70D18B.5040008@mrabarnett.plus.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> <4B70D18B.5040008@mrabarnett.plus.com> Message-ID: <7a9c25c21002081917m3e8f7afbw3f5b0d58edf6a509@mail.gmail.com> On Mon, Feb 8, 2010 at 7:07 PM, MRAB wrote: > This is getting out of hand. >> >> First, someone thought I was you. >> >> Now you think I'm D'Aprano. >> >> I'm just gonna go by Bob for now on. >> :) >> >> --B >> >> Bruce would be less confusing. :-) I've heard that, and can't fathom the claim. I've only ever met a single Bruce in my entire life, though I've seen a couple on the 'net. Maybe its geographical, and Bruce's just don't like California? I dunno. Stephen's though I'm used to being one of many; I was 'number 5' at the office for quite awhile, since I worked directly for (and next to) a Stephen, with another Stephen, and frequently at to ask two other Stephen's for advice. So we all went by numbers. Time to take up the habit on the internet! Anyways. Ahem. --Bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Mon Feb 8 22:24:40 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:24:40 -0800 Subject: Socket Error: Permission Denied Message-ID: I'm using IDLE with winxp. It seems every day I get into the Subject above. Usually, after 5-8 minutes I get past it. A msg appearing at the same time say, "IDLE's subprocess didn't make connect. ... possible firewall problem." A resource for this is . There a number of choices. Perhaps the most appealing is: adgprogramming: first, bring up your task manager and make sure there are no python processes running. 2.6.x subprocesses can get stuck. Then make sure that your firewall isn't blocking socket access to localhost. Then restart IDLE. IDLE 3.1.1 may work for you since it has the recent enhancement that allows multiple copies of IDLE to run simultaneously, but it still needs interprocess access via sockets. How would I know the which Python processes or subprocesses are running? I can kill the main one, but that seems to do no good. pythonw.exe. Comments? From wolftracks at invalid.com Mon Feb 8 22:38:48 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:38:48 -0800 Subject: Socket Error: Permission Denied In-Reply-To: References: Message-ID: On 2/8/2010 7:24 PM, W. eWatson wrote: > I'm using IDLE with winxp. It seems every day I get into the Subject > above. Usually, after 5-8 minutes I get past it. A msg appearing at the > same time say, "IDLE's subprocess didn't make connect. ... possible > firewall problem." > > A resource for this is . There a > number of choices. Perhaps the most appealing is: > > adgprogramming: first, bring up your task manager and make sure there > are no python processes running. 2.6.x subprocesses can get stuck. > Then make sure that your firewall isn't blocking socket access to > localhost. Then restart IDLE. IDLE 3.1.1 may work for you since it > has the recent enhancement that allows multiple copies of IDLE to run > simultaneously, but it still needs interprocess access via sockets. > > How would I know the which Python processes or subprocesses are running? > I can kill the main one, but that seems to do no good. > pythonw.exe. > > Comments? I'm using McAffee. I see it was pythonw.exe blocked in red. There are several choices: Allow Access, Allow Outboubnd only Block (current), Remove Prgrm permission, Learn More. Outbound only seem reasonable, but why does the blocking keep returning every many hours, or maybe when I reboot, which I've done several times today? From wolftracks at invalid.com Mon Feb 8 22:45:50 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:45:50 -0800 Subject: Socket Error: Permission Denied In-Reply-To: References: Message-ID: I decided to go with outbound. Now when I run the program, I get a long of messabge about deprecations and NumpyTest will be removed in the next release. please update code to nose or unittest. From wolftracks at invalid.com Mon Feb 8 22:53:29 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 08 Feb 2010 19:53:29 -0800 Subject: Tangling with mathplotlib(MPL) on XP and Win7 -- show() stopper Message-ID: I'm doing most of this on a win7 machine. When I installed MPL, I had two small dialogs appear that said something was missing, but I pressed on. MPL seemed to generally work except for the show() problem. When it was to be executed to show the output of plot(x,y), it did just that; however, the shell window hung, and I had to upper right corner x my way out of it--2 to 3 steps. The plot window and program easily went the same way. IDLE is the tool of choice on both machines. I'm in the process of bringing programs from my XP to the win7 machine, and on the XP machine I decided to start using MPL with a 900 line Py program that I'm revising. I had gotten stuck with the very same problem there. However, last night I realized someone had added a MPL plot to it years ago, and it does not fail on show(). I've put print stmts after show() in the big program, but nothing is printed in either case when I close the plot window. Tried in IDLE and executing from clicking on the py file in its folder. I brought some of this up on the MPL mailing list, and one respondent said he had tried some of the examples with show(), and they had worked. I noticed the dialog msgs mentioned above, and thought I made a mistake in not installing numpy first, so tried to figure out a way to do it. Three posts on different forums did not provide an answer. I accidentally found the author of MPL's hidden away in one of MPL files. He said it didn't make a difference and asked me not to use his address. I though the warning msgs might be of interest to him, so wrote to him. He had blocked me. Perhaps I need to file a bug report to get his attention on that. Anyway, I'm now stalled on the development of the big program. It's possible this is an IDLE problem, but I ran the big program with a click on the file, and the black window showed the same problem. This is all on XP Pro. I'm going to copy the two code segments here. Maybe someone can see a difference. =================OLD working code============ def light_curve( self ): result = [] test = 1 for tup in self.subimages: left,top,subimage = tup total = 0 avg_total = 0 if (test == 1): box = (left, top, left+128, top+128) region = self.reference_image.crop(box) self.reference_image.paste(subimage, box) test = 2 else: for x in range(left+43,left+82): for y in range(top+43, top+82): avg_total = avg_total + self.reference_image.getpixel((x, y)) for x in range(43,82): #take the center 40 X 40 pixel block for y in range(43,82): v = subimage.getpixel((x, y)) total = total + v #for x in range(left, left+127): # for y in range(top, top+127): # avg_total = avg_total + self.reference_image.getpixel((x, y)) #for x in range(0, 127): # for y in range(0, 127): # total = total + subimage.getpixel((x, y)) result.append(total - avg_total) #(average - background average) gives pixel intensity above the background) plotting_x = range(2, len(result)+2) plot(plotting_x, result) xlabel('Frame #') ylabel('Pixel count above background count') title('Light curve for selected subplot') show() ===========New Code with show problem def get_point_trail_stats(self): # Simple track statistics xy = array(self.xya)[:,0:2] # creates a two column array for x,y pt2pt_dist = [] pt_dist = [] for k in arange(0,len(xy)-1): distance = sqrt((xy[k+1,0]-xy[k,0])**2 + (xy[k+1,1]-xy[k,1])**2) pt_dist.append(distance) # wtw print "k ",k, (xy[k,0], xy[k,1]), " distance: ", distance # wtwfor k in arange(0, len(xy)-50): # wtw print "k: %3i dist: %6.2f (x,y) (%4.1f,%4.1f)" % (k, pt_dist[k], xy[k,0], xy[k,1]) per_tile25 = stats.scoreatpercentile(pt_dist,25.0) per_tile50 = stats.scoreatpercentile(pt_dist,50.0) per_tile75 = stats.scoreatpercentile(pt_dist,75.0) mean = stats.mean(pt_dist) std = stats.std(pt_dist) #sys.exit() amin = min(pt_dist) amax = max(pt_dist) print " mean: %7.2f std: %7.2f min: %7.2f max: %7.2f" % (mean, std, amin, amax) print " quartiles (25-per: %7.2f, 50-per: %7.2f, 75-per: %7.2f): " % (per_tile25, per_tile50, per_tile75) #print " Extended stats" #print " min: %7.2f max: %7.2f mean: %7.2f std: %7.2f" % \ # (min, max, mean, std) #print " p25: %7.2f p50: %7.2f p75: %7.2f" % (per_tile25, per_tile50, per_tile75) trk_stats = (amin, amax, mean, std, per_tile25, per_tile50, per_tile75) fig = figure() ax1 = fig.add_subplot(111) v = (0, 640, 0, 480) print "shapes: ", xy[:,0].shape, xy[:,1].shape fig.close() ax1.plot(xy[:,0], xy[:,1]) #,100*s, c , picker=True) ax1.axis(v) #x = (0,1,3,20,20);y=(5,7, 9, 22,90) #col = ax1.plot(x,y) show() print "something for wtw plot" print return trk_stats From alfps at start.no Mon Feb 8 23:01:16 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 05:01:16 +0100 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: * Stephen Hansen -> Alf P. Steinbach: > > [snip] > To say, "pass by value" implies things to people. It describes a sort of > world where I'm a function about to do some work, and on my desk I have > a series of boxes with names on it. It describes an environment where > someone comes over and drops something into each of my boxes. The > contents of these boxes are mine alone! Then, when the imprecision makes people misunderstand, one should not say that. One should then be more precise. One should say /what/ is passed by value. [snip] > >>> import copy > >>> def doit(a): > ... a += a > ... return a > ... > >>> test1 = 1 > >>> test2 = doit(test1) > >>> test1 > 1 > >>> test2 > 2 > >>> test3 = [1] > >>> test4 = doit(test3) > >>> test3 > [1, 1] > >>> test4 > [1, 1] > > I know you already know this, but the point is: you're -hurting- other > peoples understanding by using terms like this that don't apply to > Python's specific nature. The terms apply very well to Java. And Java has the identical parameter passing mechanism for class type objects. Hence, the argument is bogus. Cheers & hth., - Alf PS: I cannot see any of your postings on Usenet. So I just sort of grabbed this from GMane and posted to Usenet. Hopefully you'll see it back at the list. :-) From gnarlodious at gmail.com Mon Feb 8 23:02:30 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Mon, 8 Feb 2010 20:02:30 -0800 (PST) Subject: Python 3: Plist as OrderedDict Message-ID: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> I am trying to read a *.plist into Python 3's OrderedDict but can't figure it out. Saying something like this: from plistlib import readPlist dict=readPlist('/path/file.plist') --> arbitrarily ordered dictionary compared to the XML file from collections import OrderedDict OrderedDict(readPlist('/path/file.plist')) --> essentially does the same thing as the previous readPlist seems to do the scrambling, is this a non-implementation in Python 3.1? I "upgraded" to Py3 to have OrderedDict, so please don't say it is impossible... -- Gnarlie From ben+python at benfinney.id.au Mon Feb 8 23:17:23 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 09 Feb 2010 15:17:23 +1100 Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: <871vgvjb58.fsf@benfinney.id.au> Gnarlodious writes: > from plistlib import readPlist > dict=readPlist('/path/file.plist') > --> arbitrarily ordered dictionary compared to the XML file Right. The items in a dict are unordered, and when serialised to a list they will appear in an arbitrary, unpredictable order. >>> foo = dict( ... [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]) >>> foo {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} > from collections import OrderedDict > OrderedDict(readPlist('/path/file.plist')) > --> essentially does the same thing as the previous Yes, because you are initialising an OrderedDict instance from a dict. That accesses the dict items as an iterable, which of course is going to retrieve the items in an arbitrary, unpredictable order. >>> foo.items() dict_items([('a', 1), ('c', 3), ('b', 2), ('e', 5), ('d', 4)]) The OrderedDict then faithfully remembers the arbitrary ordering of the items. >>> from collections import OrderedDict >>> OrderedDict(foo.items()) OrderedDict([('a', 1), ('c', 3), ('b', 2), ('e', 5), ('d', 4)]) > readPlist seems to do the scrambling Nothing ?does? the scrambling; the order is forgotten by the dict as soon as the items go in. > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... What you'll need to do is insert the items into the OrderedDict instance in the desired order. You will, of course, need to define what that desired order is. >>> sorted(foo.items(), key=(lambda item: item[0])) [('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)] >>> OrderedDict(sorted(foo.items(), key=(lambda item: item[0]))) OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)]) -- \ ?When we talk to God, we're praying. When God talks to us, | `\ we're schizophrenic.? ?Jane Wagner, via Lily Tomlin, 1985 | _o__) | Ben Finney From benjamin.kaplan at case.edu Mon Feb 8 23:21:13 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 8 Feb 2010 23:21:13 -0500 Subject: Python 3: Plist as OrderedDict In-Reply-To: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: On Mon, Feb 8, 2010 at 11:02 PM, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: > > from plistlib import readPlist > dict=readPlist('/path/file.plist') > --> arbitrarily ordered dictionary compared to the XML file > > from collections import OrderedDict > OrderedDict(readPlist('/path/file.plist')) > --> essentially does the same thing as the previous > readPlist seems to do the scrambling, is this a non-implementation in > Python 3.1? > > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... > > -- Gnarlie readPlist returns a dict. That dict is unordered. Wrapping the call in OrderedDict() doesn't suddenly make readPlist use an ordered dict instead, it just takes the (unordered) dict and sticks it in a new OrderedDict. I suppose you could dig into the plistlib source code and change that to use the OrderedDict if you really need it. > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Mon Feb 8 23:25:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Feb 2010 23:25:25 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: On 2/8/2010 2:10 PM, Alf P. Steinbach wrote: > I apologize for assuming that "pointer" is a known word to [c.l.p.] > denizens. It is irrelevant. Python calls Python functions by associating argument objects (or objects derived therefrom) with paramenter names, very much like assigment statements. If one understands Python objects, names, and assignment statements, which one must to understand Python, this completely explains the function calls, function execution, and its effect on passed objects. All Python expressions evaluate to an object. Call expressions evaluate to the object returned by the function. Different interpreters implement call and return differently. Certainly, most humans do not use C pointers when they mentally execute Python code. Terry Jan Reedy From apt.shansen at gmail.com Mon Feb 8 23:29:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 20:29:02 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> On Mon, Feb 8, 2010 at 8:01 PM, Alf P. Steinbach wrote: > * Stephen Hansen -> Alf P. Steinbach: > >> >> [snip] >> >> To say, "pass by value" implies things to people. It describes a sort of >> world where I'm a function about to do some work, and on my desk I have a >> series of boxes with names on it. It describes an environment where someone >> comes over and drops something into each of my boxes. The contents of these >> boxes are mine alone! >> > > Then, when the imprecision makes people misunderstand, one should not say > that. > > One should then be more precise. > > One should say /what/ is passed by value. > No. One should not use the phrase that is fundamentally imprecise. The phrase "pass by value" means something different then the phrase "pass by object" aka "pass by sharing". They are in many cases very similar. They are not the same. Using it is simply wrong. There is really no legitimate argument you can make otherwise: even in languages where call-by-value IS the norm, the phrase is imprecise enough to confuse people, as the semantics of what call-by-value mean to a language vary. But those semantics do NOT apply to Python. [snip] > >> >> I know you already know this, but the point is: you're -hurting- other >> peoples understanding by using terms like this that don't apply to Python's >> specific nature. >> > > The terms apply very well to Java. And Java has the identical parameter > passing mechanism for class type objects. Hence, the argument is bogus. > Java uses silly terminology; and that it chooses to use silly terminology in no way impacts the validity of the argument. Java isn't an authority. Python's been around longer! And the specific behavior here, "call by value where the value is an object reference" was named "call by sharing" back in the 1970's by Liskov. Java isn't call-by-value (for objects) either, even if that phrase is common in the Java community. C is call-by-value. VB is, I believe, call-by-value -- though I may be wrong here, as I only sort of blinked at VB a long, long time ago. Its distinct. Its different. Its neither call-by-value, nor call-by-reference. The /value/ of a thing is NOT its identity. Its the /state/ of that thing. By your argument, call-by-reference is call-by-value too! Because you're passing "a value" -- but you're -always- going to pass some piece of data, otherwise you're not actually passing anything. The /by value/ vs /by reference/ vs /by sharing/ is not about "is a value being passed", in all cases, "a value" is. By Value means a copy of the thing is made. By Reference means you're accessing the callers variable directly. By Sharing means you're both sharing the same object. PS: I cannot see any of your postings on Usenet. So I just sort of grabbed > this from GMane and posted to Usenet. Hopefully you'll see it back at the > list. :-) I've heard that before, and have no idea why, nor any real interest in solving it: I don't want to read cpl via Usenet, and prefer to read it as a mailing list. Somewhere between Gmail->python.org->python.org's usenet server->the world, some people don't seem to get my posts. Yet it shows up on some news servers, not others. No idea. Nothing I know of can solve it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From bchang2002 at gmail.com Mon Feb 8 23:40:54 2010 From: bchang2002 at gmail.com (dontcare) Date: Mon, 8 Feb 2010 20:40:54 -0800 (PST) Subject: xml.sax parsing elements with the same name References: <51ad9cee-6b7b-42c8-8f9e-44c0f8b96bc7@j19g2000yqk.googlegroups.com> <4b4c2f2e$0$6731$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <961b9e15-5d20-472b-92bc-917796dc6e5e@y7g2000prc.googlegroups.com> If you are using jython, then you might also want to consider VTD-XML, which is a lot easier to use and faster than SAX, native XPath support may be useful too http;//vtd-xml.sf.net On Jan 12, 12:13?am, Stefan Behnel wrote: > amadain, 11.01.2010 20:13: > > > > > > > I have an event log with 100s of thousands of entries with logs of the > > form: > > > > uniqueId="1261124569.35725_PFS_1_1340035961"> > > ? ? > > ? ? ? > > ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? > > ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? ? ? ? > > ? ? ? ? ? ? ? > > ? ? ? ? ? > > ? ? ? > > > > > I am usingxml.saxto parse the event log. > > You should give ElementTree's iterparse() a try (xml.etree package). > Instead of a stream of simple events, it will give you a stream of > subtrees, which are a lot easier to work with. You can intercept the event > stream on each 'event' tag, handle it completely in one obvious code step, > and then delete any content you are done with to safe memory. > > It's also very fast, you will like not loose muchperformancecompared toxml.sax. > > Stefan- Hide quoted text - > > - Show quoted text - From tjreedy at udel.edu Mon Feb 8 23:47:20 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 08 Feb 2010 23:47:20 -0500 Subject: Python 3: Plist as OrderedDict In-Reply-To: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: On 2/8/2010 11:02 PM, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: > > from plistlib import readPlist As a general note, include a link or something when discussing a relatively obscure module that seems not to even be listed in pypi. > dict=readPlist('/path/file.plist') Redefining a basic builtin name like 'dict' is usually a bad idea. > --> arbitrarily ordered dictionary compared to the XML file > > from collections import OrderedDict > OrderedDict(readPlist('/path/file.plist')) > --> essentially does the same thing as the previous > readPlist seems to do the scrambling, is this a non-implementation in > Python 3.1? > > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... I agree with Benjamin -- check the source. Is plistlib 3.x ready? Terry Jan Reedy From alfps at start.no Tue Feb 9 00:12:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 06:12:07 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: * Terry Reedy: > On 2/8/2010 2:10 PM, Alf P. Steinbach wrote: > >> I apologize for assuming that "pointer" is a known word to [c.l.p.] >> denizens. > > It is irrelevant. > > Python calls Python functions by associating argument objects (or > objects derived therefrom) with paramenter names, very much like > assigment statements. Well, part of the above is word-play. When a name refers to an object elsewhere and that reference can be copied around, then it is a pointer to the object in e.g. the Java sense, which I very purposefully referenced to be clear about it. So you're saying that X is irrelevant in Python because Python uses Y, where Y is a description of X... But part of what you write puzzles me. As far as the language spec is concerned the argument passing mechanism seems to me to be identical to assignments, not just "very much like". Your phrase "or objects derived therefrom" seems to imply that immutable objects can be copied (an optimization that once was rejected), but as far as I can see the language spec only talks about binding with no provision for binding to do anything else than making a name refer directly to a specified object, presumably with *the same id*. Not talking about things built on top of argument passing like *, and not talking about scopes or other (in this context) extraneous details: is there something I've overlooked in the basic mechanism? > If one understands Python objects, names, and assignment statements, > which one must to understand Python, this completely explains the > function calls, function execution, and its effect on passed objects. Yes. There are many ways to understand it though. The simplest description, reality, that names refer to objects, where those references can be copied, i.e. that they in e.g. the Java sense are pointers to objects, seems to be simplest -- and is certainly shortest. :-) > All Python expressions evaluate to an object. Call expressions evaluate > to the object returned by the function. > > Different interpreters implement call and return differently. Certainly, > most humans do not use C pointers when they mentally execute Python code. The Java language spec reference for "pointer" was to avoid arguments about irrelevant specialized meanings of the term, such as C pointers. Cheers & hth., - Alf From phlip2005 at gmail.com Tue Feb 9 00:21:55 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 8 Feb 2010 21:21:55 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> Message-ID: <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> Carl Banks wrote: > I don't know if it was the reason it was rejected, but a seriously > divisive question is whether the path should be a subset of string. OMG that's nothing but the OO "circle vs ellipse" non-question. Glad to see the Committee derailed a perfectly good library over such sophistry. > Under ordinary circumstances it would be a poor choice for inheritance > (only a few string methods would be useful fot a pathname), but some > people were fiercely adamant that paths should be passable to open() > as-in (without having to explicity convert to string). That's just silly. To be object-based, you should say path.open('r'). fopen() and its ilk are too 1960s... My 5th Grade science teacher, one Eunice Feight, once expressed chagrin for submitting a proposal to Readers' Digest, and getting it accepted. She sold them the following sloka: Don't be clever don't be witty Or you'll wind up BEING the Committee! -- Phlip http://penbird.tumblr.com/ From ijcsorgeditor at gmail.com Tue Feb 9 00:35:55 2010 From: ijcsorgeditor at gmail.com (editor ijcs) Date: Mon, 8 Feb 2010 21:35:55 -0800 (PST) Subject: Call for Paper The International Journal of Computer Science (IJCS) Message-ID: Call for Paper The International Journal of Computer Science (IJCS) publishes original papers on all subjects relevant to computer science, communication network, and information systems. The highest priority will be given to those contributions concerned with a discussion of the background of a practical problem, the establishment of an appropriate model, the determination of a solution, approximate or exact, analytical or numerical, and a discussion of the relevance of the results when applied to the real-life problem. Paper submissions are invited in the area of computer science, in particular the technological advances and research results in the fields of theoretical, experimental, applied electronics, computer science, communication network and Information technology. Topics of interest include but are not limited to the following: Computer Science * Parallel Processing and Distributed Computing * Foundations of High-performance Computing * Graph Theory and Analysis of Algorithms * Artificial Intelligences and Pattern/Image Recognitions * Neural Networks and Biomedical Simulations * Virtual Visions and Virtual Simulations * Data Mining, Web Image Mining and Applications * Data Base Management & Information Retrievals Adaptive Systems * Bifurcation, Biocybernetics & Bioinformatics * Blind Systems, Neural Networks &Control Systems * Cryptosystems &Data Compression * Evolutional Computation &Fuzzy Systems * Image Processing and Image Recognition, Modeling & Optimization * Speech Processing, Speech Synthesis & Speech Recognition * Video Signal Processing, Watermarking & Wavelet Transform * All topics related Computer Science Communication Network * Quantum Computing & Coding * Error Controls Agent Computing & Multi-Agents Systems * Defining Spectrum Rights and Open Spectrum Solutions * Quality of Services and Communication Protocols * Satellite and Optical Communication Systems * 3G/4G Network Evolutions & CDMA/GSM Communication Protocols * Mobile Computing, Transmission/Switching/Distribution technologies * Communication Theory & Signal Processing for Communications * Wireless Communications, Wireless & Mobile Networking * Optical Networks and Systems &Next-Generation Networking and Internet * Communication QoS &Reliability and Modeling * Ad-hoc, Sensor & Mesh Networking * Multimedia Services, Communication Software & Services * Communication and Information System Security * System control and network/service management * Network and Internet protocols and standards * Client-server, distributed & Web-based communication systems * Broadband and multimedia systems & applications * Trials of advanced systems and services * Any topics related Communication Network Information and Systems * Cryptography and Foundation of Computer Security * Authentication/Authorization Issues * IDS/Firewall, Anti-Spam mail & Anti-virus issues * Biometric authentication & algorithms * Fingerprint /Hand/Biometrics Recognitions and Technologies * IC-card Security, OTP & Key Management Issues * E-commerce, Ubiquitous & RFID Applications * Metadata, Meta Modeling, XML & Data Management * Knowledge Management, Web Security & Privacy * Cyber Threats, Web Services & Web Engineering * Web Intelligence, Protocols & Standards * Proxies and Servers * Multimedia Applications * Ontology and the Semantic Web * B2B, B2C and C2C * E-Business System Design and Development, E-Payment * Portal Strategies, Social Networks and Information Systems * Social and Legal Issues and Digital Ecology * E-Governance, E-Learning and Virtual Classrooms * E-Entertainment, E-Journalism * Any topics related Information systems Electronics * Circuits & Devices * Communication Networks & Systems * Communications & Information Processing * Digital Signal Processing & Electrical Engineering Communications * Electromagnetics & Microwaves * Instrumentation * Measurement & Testing * Nanoscience & Nanotechnology * Optics & Optoelectronic Effects * Devices, Systems &Semiconductors * Systems & Control Engineering * Telecommunications * Any topics related Electronics International Journal of Computer Science (IJCS) ISSN: 1884-9083 Website: https://sites.google.com/site/ijcsorg/ Manuscript submission to: ijcsorgeditor at gmail.com All submitted papers will be judged based on their quality by the technical committee and reviewers. Papers that describe research and experimentation are encouraged. All paper submissions will be handled electronically and detailed instructions on submission procedure are available on IJCS web pages. Researchers and authors are invited to participate in the peer-review process of IJCS papers if your research interest matches with the themes of Call for Papers. For other information, please contact IJCS Managing Editor. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 00:38:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 05:38:26 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: On Tue, 09 Feb 2010 05:01:16 +0100, Alf P. Steinbach wrote: > * Stephen Hansen -> Alf P. Steinbach: >> >> [snip] >> To say, "pass by value" implies things to people. It describes a sort >> of world where I'm a function about to do some work, and on my desk I >> have a series of boxes with names on it. It describes an environment >> where someone comes over and drops something into each of my boxes. The >> contents of these boxes are mine alone! > > Then, when the imprecision makes people misunderstand, one should not > say that. > > One should then be more precise. > > One should say /what/ is passed by value. I don't see how that matters. Python's behaviour is EXACTLY the same, no matter what you pass to the function. You don't pass pointers in Python, because you, the Python author, have no way of specifying a pointer in Python code. It is *always* an object that you pass, by giving a literal, the name an object is bound to, or some other expression that returns an object: function( my_object ) function( 12345 ) function( ham(3) + spam(5) ) If you're talking to the person who writes Python code, then you should discuss the sorts of things that exist in Python: objects and names and expressions, but no pointers. If you're talking about the Python virtual machine, instead of the high- level Python code, then you should say so -- but there are still no pointers in the VM. Look at the output of dis.dis and you will see objects pushed onto a stack, but no pointers. It's not until you get past the level of Python code, past the virtual machine, and into the implementation of the virtual machine, that you will finally find pointers. But why stop there? If somebody asks you a question about Python, and you choose to ignore them and answer a different question about one particular implementation's internals instead, I don't see why you stop there. Why not go down another layer and talk about copying bytes, or two layers and answer that Python does call-by-bit-flipping, or a layer below that and say it's all done by varying potential differences? You shouldn't expect your listener to understand machine code to understand Python's high-level behaviour, nor should you expect them to be C coders. You don't need to understand pointers to understand a language that doesn't support them. [...] > The terms apply very well to Java. And Java has the identical parameter > passing mechanism for class type objects. Hence, the argument is bogus. Everything I've said applies to Java as well, and the argument about call- by-whatever is just as prevalent in Java circles as in Python. Example #1: Q: If Java uses the pass-by reference, why won't a swap function work? A: Your question demonstrates a common error made by Java language newcomers. Indeed, even seasoned veterans find it difficult to keep the terms straight. Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value. http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html Example #2: Myth: "Objects are passed by reference, primitives are passed by value" Some proponents of this then say, "Ah, except for immutable objects which are passed by value [etc]" which introduces loads of rules without really tackling how Java works. http://www.yoda.arachsys.com/java/passing.html Example #3: Java is Pass-by-Value, Dammit! http://javadude.com/articles/passbyvalue.htm Java programmers suffer for a bad mental model just as much as Python programmers. All this is because of two conceptual mistakes: (1) the Java community has conflated the internals of what happens in the implementation of the Java VM with high-level Java code; and (2) a refusal to accept that there are calling strategies other than pass-by-value and pass-by-reference. -- Steven From ldo at geek-central.gen.new_zealand Tue Feb 9 00:43:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 09 Feb 2010 18:43:48 +1300 Subject: ctypes Structure serialization References: <615b1271-a9b0-4558-8e45-e4370698d96a@a16g2000pre.googlegroups.com> Message-ID: In message <615b1271-a9b0-4558-8e45- e4370698d96a at a16g2000pre.googlegroups.com>, rych wrote: > I'm not quite familiar with python serialization but the picle module, > at least, doesn't seem to be able to serialize a ctypes Structure with > array-fields. Remember that a ctypes structure is supposed to represent a lower-language- level structure, which is just a block of bytes. Those bytes are the serialization. From olivier.darge at gmail.com Tue Feb 9 01:00:15 2010 From: olivier.darge at gmail.com (OdarR) Date: Mon, 8 Feb 2010 22:00:15 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: On 9 f?v, 02:50, Jean-Michel Pichavant wrote: > Aahz wrote: > > In article <0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, > > OdarR ? wrote: > > >> and with eval(), did you try ? > > > WARNING: eval() is almost always the wrong answer to any question > > Some say that eval is evil ! > > JM go to hell ;-), it is part of the language, it seems to match the aforementioned question. I don't see it as a problem. Let's wait Klaus opinion. Olivier From apt.shansen at gmail.com Tue Feb 9 01:26:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 8 Feb 2010 22:26:11 -0800 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <7a9c25c21002082226t7f042f00lf001c827fe7b88eb@mail.gmail.com> On Mon, Feb 8, 2010 at 10:00 PM, OdarR wrote: > On 9 f?v, 02:50, Jean-Michel Pichavant wrote: > > Aahz wrote: > > > In article < > 0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, > > > OdarR wrote: > > > > >> and with eval(), did you try ? > > > > > WARNING: eval() is almost always the wrong answer to any question > > > > Some say that eval is evil ! > > > > JM > > go to hell ;-), it is part of the language, it seems to match the > aforementioned question. > > I don't see it as a problem. > Yes, it is a part of the language, because as a dynamic language has to have such a capability. Because there are legitimate use-cases for it. But they are extremely rare. Extremely rare. But it is there: if there is a real, legitimate use-case for a feature that can't be solved by other means, then certainly include a feature to accomplish that goal. But that doesn't mean you use that feature all over just because its there. You use it when its appropriate. The ability to do a thing doesn't mean you should do a thing. In most cases, eval is not appropriate. It might do what you think you want, but often there are huge consequences and not at all obvious considerations you have to take into account. Usually when you think you want to eval, there's a better way to approach the problem. It might not seem right away to be as "easy" or "seamless" as you think you want, but there are almost always compelling reasons why its better, easier, more efficient and simpler. People are trying to help the OP not only by providing the easiest approach to solve a problem, but trying to show him the best way to make /good code/. Good Code isn't a purely subjective thing left up to idle taste. ... Also? "go to hell" even with a smiley is being an asshat. Don't be an asshat. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Tue Feb 9 01:35:57 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 07:35:57 +0100 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: * Stephen Hansen: > On Mon, Feb 8, 2010 at 8:01 PM, Alf P. Steinbach > wrote: > > * Stephen Hansen -> Alf P. Steinbach: > > > [snip] > > To say, "pass by value" implies things to people. It describes a > sort of world where I'm a function about to do some work, and on > my desk I have a series of boxes with names on it. It describes > an environment where someone comes over and drops something into > each of my boxes. The contents of these boxes are mine alone! > > > Then, when the imprecision makes people misunderstand, one should > not say that. > > One should then be more precise. > > One should say /what/ is passed by value. > > > No. > > One should not use the phrase that is fundamentally imprecise. > > The phrase "pass by value" means something different then the phrase > "pass by object" aka "pass by sharing". They are in many cases very > similar. They are not the same. Right. "pass by value" is a lower level notion. And as you show below, in the paragraph marked [1], it can be used to describe call by sharing very succinctly and precisely, just as I did... ;-) > Using it is simply wrong. There is > really no legitimate argument you can make otherwise: even in languages > where call-by-value IS the norm, the phrase is imprecise enough to > confuse people, as the semantics of what call-by-value mean to a > language vary. But those semantics do NOT apply to Python. In a way that's right, but only at the level of abstraction of pass by sharing. At that level it's wrong to say that pass by sharing is pass by value (as they reportedly do over in Java-land), just as, at that level, it's wrong to say that pass by reference is pass by value notwithstanding that some kind of value must be copied in the internal implementation. Describing pass by sharing in terms of pass by value is however very simple and legitimate, involving a higher level described in terms of a lower level -- as you illustrate right below: > [snip] > I know you already know this, but the point is: you're -hurting- > other peoples understanding by using terms like this that don't > apply to Python's specific nature. > The terms apply very well to Java. And Java has the identical > parameter passing mechanism for class type objects. Hence, the > argument is bogus. > > > [1] Java uses silly terminology; and that it chooses to use silly > terminology in no way impacts the validity of the argument. Java isn't > an authority. Python's been around longer! And the specific behavior > here, "call by value where the value is an object reference" was named > "call by sharing" back in the 1970's by Liskov. Yep. As you write, "call by sharing" can be described as "call by value where the value is an object reference". Althuogh I'd rather use "where the value is an object pointer", because the word "pointer" already denotes a copyable value so doesn't make the head spin... > Java isn't call-by-value (for objects) either, even if that phrase is > common in the Java community. Right, and here the parenthesis (for objects) establishes which abstraction level. > C is call-by-value. VB is, I believe, > call-by-value -- though I may be wrong here, as I only sort of blinked > at VB a long, long time ago. Full VB supports both call by sharing and call by reference. > Its distinct. Its different. Its neither call-by-value, nor > call-by-reference. The /value/ of a thing is NOT its identity. Its the > /state/ of that thing. Talking about a reference value (a.k.a. pointer), as you do earlier above in [1], does not mean that one is talking about a Python object value. So essentially the paragraph immediately above seems to be a confusion based on multiple meanings of "value", unless it's just a description of Python objects? > By your argument, call-by-reference is call-by-value too! Because you're > passing "a value" -- but you're -always- going to pass some piece of > data, otherwise you're not actually passing anything. No, whatever you think my argument is (no quote, so I'm left in the dark about that assumption) here you're back to confusing levels of abstraction again. Call by reference is necessarily, at some level, implemented in terms of call by value. That doesn't make call by reference the same as call by value, not more than the human body is one giant molecule just because it consists of molecules. > The /by value/ vs /by reference/ vs /by sharing/ is not about "is a > value being passed", in all cases, "a value" is. By Value means a copy > of the thing is made. By Reference means you're accessing the callers > variable directly. By Sharing means you're both sharing the same object. Yes, violent agreement. > PS: I cannot see any of your postings on Usenet. So I just sort of > grabbed this from GMane and posted to Usenet. Hopefully you'll see > it back at the list. :-) > > > I've heard that before, and have no idea why, nor any real interest in > solving it: I don't want to read cpl via Usenet, and prefer to read it > as a mailing list. Somewhere between Gmail->python.org->python.org > 's usenet server->the world, some people don't seem > to get my posts. Yet it shows up on some news servers, not others. > > No idea. Nothing I know of can solve it. Not sure, but perhaps it's possible to mail directly to gmane? Cheers & hth., - Alf From frank at chagford.com Tue Feb 9 01:45:03 2010 From: frank at chagford.com (Frank Millman) Date: Tue, 9 Feb 2010 08:45:03 +0200 Subject: Simple question about Queue.Queue and threads References: <770583c3-a7c7-4a3d-b90f-9546801040e3@u26g2000yqm.googlegroups.com> Message-ID: On Feb 8, 4:51 pm, Steven wrote: > > Queue objects have support for this signaling baked in with > q.task_done and q.join. > > After the server process has put all tasks into the queue, it can join > the queue itself, not the worker threads. > > q.join() > > This will block until all tasks have been gotten AND completed. The > worker threads would simply do this: > task_data = q.get() > do_task(task_data) > q.task_done() > > Using pairs of get and task_done you no longer need to send a signal. > Just exit the server process and the worker threads will die (assuming > of course, you set .setDaemon(True) before starting each worker > thread). > Thanks, Steven. This works perfectly in my scenario, and tidies up the code a bit. Minor point - according to the 2.6 docs, .setDaemon(True) is the old API - the current way of specifying this is .daemon = True. Thanks for the tip. Frank From nad at acm.org Tue Feb 9 01:47:25 2010 From: nad at acm.org (Ned Deily) Date: Mon, 08 Feb 2010 22:47:25 -0800 Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: In article , Terry Reedy wrote: > On 2/8/2010 11:02 PM, Gnarlodious wrote: > > I am trying to read a *.plist into Python 3's OrderedDict but can't > > figure it out. Saying something like this: > > from plistlib import readPlist > As a general note, include a link or something when discussing a > relatively obscure module that seems not to even be listed in pypi. http://docs.python.org/library/plistlib.html -- Ned Deily, nad at acm.org From pwashington85 at gmail.com Tue Feb 9 01:47:42 2010 From: pwashington85 at gmail.com (spike) Date: Mon, 8 Feb 2010 22:47:42 -0800 (PST) Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> Message-ID: <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> On Feb 8, 1:35?pm, Gary Herron wrote: > spike wrote: > > Has anyone been able to come across a Python logic map or Python logic > > flow chart? > > > An example can be seen on the right under History: > >http://en.wikipedia.org/wiki/Usenet#History > > > This would be very helpful for all users. > > Huh??? ?What aspect of Python were you thinking of mapping out? > > Your example us a bad ascii art graph of -- I've no clue what? > > Gary Herron Do you know what "Logic" means? Guess not. Before you comedians quit your day job some people are looking for information. If you have nothing positive to say, go pester somewhere else. Grow up. From greg.ewing at canterbury.ac.nz Tue Feb 9 01:55:16 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Feb 2010 19:55:16 +1300 Subject: equivalent of Ruby's Pathname? In-Reply-To: <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> Message-ID: <7tceiuF94hU1@mid.individual.net> Carl Banks wrote: > I don't remember if the idea of modifying open to accept path > objects came up. It wouldn't just be open() that people would want modified -- it would be every other function that takes a pathname as well. I seem to recall another point of contention was whether path objects should have methods for accessing the file system (opening files, renaming them, etc.) or whether it should confine itself to representing and manipulating pathnames. In any case, introducing any kind of path object at this late stage of the language's development would result in More Than One Way to represent pathnames, with neither of them being the obvious choice. -- Greg From greg.ewing at canterbury.ac.nz Tue Feb 9 01:58:29 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 09 Feb 2010 19:58:29 +1300 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <7tceorF94hU2@mid.individual.net> Tim Chase wrote: > I prefer the strength of Triple ROT-13 for my obfuscation needs, but I > don't see it listed here. That's old hat -- with the advent of 3GHz cpus and GPGPU, all the experts are recommending quadruple ROT-128 nowadays. -- Greg From python at rcn.com Tue Feb 9 02:15:57 2010 From: python at rcn.com (Raymond Hettinger) Date: Mon, 8 Feb 2010 23:15:57 -0800 (PST) Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> Message-ID: <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> On Feb 8, 8:02?pm, Gnarlodious wrote: > I am trying to read a *.plist into Python 3's OrderedDict but can't > figure it out. Saying something like this: ... > I "upgraded" to Py3 to have OrderedDict, so please don't say it is > impossible... You may be able to monkey patch an OrderedDict into the PlistParser. Here's an untested stab at it: from collections import OrderedDict import plistlib plistlib._InteralDict = OrderedDict Raymond From alfps at start.no Tue Feb 9 02:19:56 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 08:19:56 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: * Steven D'Aprano: > On Tue, 09 Feb 2010 05:01:16 +0100, Alf P. Steinbach wrote: > >> * Stephen Hansen -> Alf P. Steinbach: >>> [snip] >>> To say, "pass by value" implies things to people. It describes a sort >>> of world where I'm a function about to do some work, and on my desk I >>> have a series of boxes with names on it. It describes an environment >>> where someone comes over and drops something into each of my boxes. The >>> contents of these boxes are mine alone! >> Then, when the imprecision makes people misunderstand, one should not >> say that. >> >> One should then be more precise. >> >> One should say /what/ is passed by value. > > I don't see how that matters. Python's behaviour is EXACTLY the same, no > matter what you pass to the function. > > You don't pass pointers in Python, because you, the Python author, have > no way of specifying a pointer in Python code. It is *always* an object > that you pass, by giving a literal, the name an object is bound to, or > some other expression that returns an object: > > function( my_object ) > function( 12345 ) > function( ham(3) + spam(5) ) Every name and literal above (and in Python generally) stands for a copyable reference to an object, not for the object itself. You can copy the reference: a = [123] b = a assert( a is b ) # Doesn't matter if mutable or immutable or what. A copyable reference is a pointer. That is, a "pointer", in e.g. the Java sense, and in the general language independent sense, means a copyable reference -- as illustrated e.g. in the Stanford computer science 101 course page I referred you to earlier, with C versus Java pointers illustrated in the concrete. Hence, since every name and literal above stands for a copyable reference, and since a copyable reference is a pointer, every name and literal above stands for a pointer -- that's /all/ that you handle directly in Python, namely pointers. But if that terminology sounds bad or has too strong C-vibes or Java-vibes or whatever, then we just need some other term for a Python "copyable reference". > If you're talking to the person who writes Python code, then you should > discuss the sorts of things that exist in Python: objects and names and > expressions, but no pointers. Well, given this terminology debate we may need some other term. But IMHO the horse drawing the wagon needs to be mentioned to the potential wagon driver, whatever that horse is called -- fourfooter, drawing-animal... Anything else seems just senseless, meaningless abstraction, replacing one simple single concept with a load of connections and special case rules. > If you're talking about the Python virtual machine, instead of the high- > level Python code, then you should say so -- but there are still no > pointers in the VM. Look at the output of dis.dis and you will see > objects pushed onto a stack, but no pointers. I don't think you will see any Python objects pushed on the stack. But you will see copyable object references pushed on the stack. That is, you will see pointers pushed on the stack. > It's not until you get past the level of Python code, past the virtual > machine, and into the implementation of the virtual machine, that you > will finally find pointers. There too. > But why stop there? If somebody asks you a question about Python, and you > choose to ignore them and answer a different question about one > particular implementation's internals instead, I don't see why you stop > there. Why not go down another layer and talk about copying bytes, or two > layers and answer that Python does call-by-bit-flipping, or a layer below > that and say it's all done by varying potential differences? I think a good professional programmer knows about all these levels. Unfortunately, at least about 10 years ago students fresh out of college in Norway did not know about "internal" things such as call stacks, which led them to adopt many Unholy Programming Practices and to be Extremely Baffled by things such as stack traces. > You shouldn't expect your listener to understand machine code to > understand Python's high-level behaviour, nor should you expect them to > be C coders. You don't need to understand pointers to understand a > language that doesn't support them. From the above comments it seems you're thinking about C pointers. To prevent that misconception I've defined the term "pointer" in every or most every posting I've made in this thread, including this posting. I've also posted a link to a Stanford University page with a simple-words explanation (they even have an animated Bunny video, although I've not looked at it); it's CS 101. You don't have anything /but/ pointers in Python. So pointers are key -- by whatever name. [snip] > Java programmers suffer for a bad mental model just as much as Python > programmers. Yes. :-) > All this is because of two conceptual mistakes: (1) the Java community > has conflated the internals of what happens in the implementation of the > Java VM with high-level Java code; and (2) a refusal to accept that there > are calling strategies other than pass-by-value and pass-by-reference. I'm not entirely sure about causes, but there is a tendency in general for humans to go from one extreme to another that they regard as "opposite". Using the term "call by value" for the Java (and Python) parameter passing is just Wrong(TM), at least without a clear understanding of what can be passed. Using "call by value" in a description of that model, mentioning very clearly what's passed, is on the other hand very practical: it's short, succinct & correct. Cheers & hth., - Alf From sivaits4u at gmail.com Tue Feb 9 02:20:22 2010 From: sivaits4u at gmail.com (Bujji) Date: Tue, 9 Feb 2010 12:50:22 +0530 Subject: event handling in pyuthon Message-ID: <581ce2791002082320t2af425ffif36e6683e08cd038@mail.gmail.com> hi all, any event handling mechanisms in python ? i want event handler examples in python Thanks Bujji -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul.nospam at rudin.co.uk Tue Feb 9 02:29:33 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 09 Feb 2010 07:29:33 +0000 Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> Message-ID: <873a1a3m02.fsf@rudin.co.uk> Steven D'Aprano writes: > On Mon, 08 Feb 2010 14:43:46 -0800, Aahz wrote: > >>>> WARNING: eval() is almost always the wrong answer to any question >>> >>>warning : it works ! >> >> Works for what? > > Code injection security bugs, of course. > > http://en.wikipedia.org/wiki/Code_injection > > It is surprisingly difficult to sanitize strings in Python to make them > safe to pass to eval. Unless you are prepared to trust the input data > explicitly, it's best to just avoid eval. Despite the fact that it's used in the standard library... From gherron at digipen.edu Tue Feb 9 02:35:51 2010 From: gherron at digipen.edu (Gary Herron) Date: Mon, 08 Feb 2010 23:35:51 -0800 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> Message-ID: <4B711057.9030003@digipen.edu> spike wrote: > On Feb 8, 1:35 pm, Gary Herron wrote: > >> spike wrote: >> >>> Has anyone been able to come across a Python logic map or Python logic >>> flow chart? >>> >>> An example can be seen on the right under History: >>> http://en.wikipedia.org/wiki/Usenet#History >>> >>> This would be very helpful for all users. >>> >> Huh??? What aspect of Python were you thinking of mapping out? >> >> Your example us a bad ascii art graph of -- I've no clue what? >> >> Gary Herron >> > > Do you know what "Logic" means? Guess not. Before you comedians quit > your day job some people are looking for information. If you have > nothing positive to say, go pester somewhere else. > > Grow up. > Why the attitude? I wouldn't have asked for a clarification if I didn't want to help. However, I seriously have *no* idea what the OP has asked for when he says "Python logic map". Do you? If so, then answer the poor guy's question instead of whining at me. (And I'll respectfully read your answer, just to see how you interpret "Python logic map".) And I still claim that the example he aimed us at does not help in figuring out what he's asking. It's a (nearly) 30 year old ascii-art drawing of the connectivity between (mostly university and government research lab ) computers that comprised the UUCP/USENET and ARPANET -- the precursor to today's internet. BUT, that begs the question: What does an old network connectivity chart have to do with a "Python logic map"? If the OP is asking for a way to draw flow charts of Python programs, then why is his example of something that is *not* a flow chart, and drawn with 30 year old technology to boot. If he is asking for a way to draw some kind of a connectivity graph, then I have to ask: Connectivity of what? -- Gary Herron, PhD. Department of Computer Science DigiPen Institute of Technology (425) 895-4418 From austin.bingham at gmail.com Tue Feb 9 02:39:49 2010 From: austin.bingham at gmail.com (Austin Bingham) Date: Tue, 9 Feb 2010 08:39:49 +0100 Subject: C/C++ Import In-Reply-To: References: <08bbf51f-7f4e-430f-95c8-31670b6a44a2@a5g2000yqi.googlegroups.com> Message-ID: Just to elaborate on Terry's point a bit, sys.path is influenced (in part) by the PYTHONPATH environment variable. If you find that the directory containing 'python' is not in sys.path (which you can check with 'import sys; print sys.path'), add that directory to PYTHONPATH and try again. This may not be the solution you ultimately end up using, but it'll get you pointed in the right direction. Austin On Mon, Feb 8, 2010 at 5:52 PM, Terry Reedy wrote: > On 2/7/2010 10:56 PM, 7H3LaughingMan wrote: >> >> To make the background information short, I am trying to take a >> program that uses Python for scripting and recompile it for Linux >> since it originally was built to run on Win32. The program itself was >> designed to be able to be compiled on Linux and someone made there on >> release with source that added python scripting. After some issues I >> got it to compile but now it is unable to import the files that it >> needs. >> >> The program is running the following code... >> PyImport_Import( PyString_FromString("python.PlayerManager") ); >> >> This is meant to import the file PlayerManager.py inside of the python >> folder. However it throws the following Python Error (Gotten through >> PyErr_Print()) >> ImportError: No module named python.PlayerManager >> >> I am using 2.6.4 so I can't call it by the filename, does anyone know >> how to do a proper import? > > Your 'python' package directory must be in a directory listed in sys.path. I > would print that check. > > -- > http://mail.python.org/mailman/listinfo/python-list > From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 03:11:02 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 08:11:02 GMT Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <5790c33c-13d0-4596-91b0-b3c9aeebf637@f8g2000yqn.googlegroups.com> <873a1a3m02.fsf@rudin.co.uk> Message-ID: On Tue, 09 Feb 2010 07:29:33 +0000, Paul Rudin wrote: >> It is surprisingly difficult to sanitize strings in Python to make them >> safe to pass to eval. Unless you are prepared to trust the input data >> explicitly, it's best to just avoid eval. > > Despite the fact that it's used in the standard library... Wisely or not, the standard library implicitly trusts it's input. That's one of the many reasons why it's so hard to have a restricted subset of Python. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 03:21:48 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 08:21:48 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: On Tue, 09 Feb 2010 08:19:56 +0100, Alf P. Steinbach wrote: > You don't have anything /but/ pointers in Python. x = 5 y = "hello" You want us to accept that the values of x and y are some mysterious pointer entities rather than the integer object 5 and the string object "hello". At the point that your explanation depends on the reader understanding that the value of a variable x is not actually the thing that they assign to x, but some mysterious, invisible entity that exists entirely inside the implementation where the user can never reach, you probably should rethink your attachment to that explanation. No wonder so many Java programmers are still confused by it. It might help your case if we had a word for the thing that is actually assigned to the variable. In plain English that is "value", but you want to use that for the pointer to the thing-that-we-otherwise-would-call- value, which leaves us no simple way to talk about the int 5 and string "hello". -- Steven From deets at nospam.web.de Tue Feb 9 03:40:16 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Feb 2010 09:40:16 +0100 Subject: Doctests and decorated methods don't get along In-Reply-To: <037d435d$0$1292$c3e8da3@news.astraweb.com> References: <037d435d$0$1292$c3e8da3@news.astraweb.com> Message-ID: <7tclbhF8ttU1@mid.uni-berlin.de> Am 06.02.10 12:48, schrieb Steven D'Aprano: > It seems that doctest doesn't discover or execute doctests in methods > which have been decorated. > > > Here is my test file: > > # ====== > class MyStaticMethod(object): > """Emulate built-in staticmethod descriptor.""" > def __init__(self, f): > self.f = f > def __get__(self, obj, objtype=None): > return self.f > > class Test(object): > def method1(self): > """Doc string > > >>> print 'x' > x > """ > > @staticmethod > def method2(): > """Doc string > > >>> print 'y' > y > """ > > @MyStaticMethod > def method3(): > """Doc string > > >>> print '***' # This test should fail. > z > """ > > if __name__ == '__main__': > import doctest > doctest.testmod(verbose=True) > # ====== > > > and here is the output using Python 2.6.4: > > [steve at sylar python]$ python2.6 test_doctests.py > Trying: > print 'x' > Expecting: > x > ok > Trying: > print 'y' > Expecting: > y > ok > 5 items had no tests: > __main__ > __main__.MyStaticMethod > __main__.MyStaticMethod.__get__ > __main__.MyStaticMethod.__init__ > __main__.Test > 2 items passed all tests: > 1 tests in __main__.Test.method1 > 1 tests in __main__.Test.method2 > 2 tests in 7 items. > 2 passed and 0 failed. > Test passed. > > > It doesn't even see method3, let alone run the tests. > > > This looks like bug to me. Have I missed anything? > > Any work arounds? Use functools.wraps to preserve some essential parts of the function declaration. def my_static(f): @wraps(f) def _d(*args, **kwargs): return f(*args, **kwargs) return _d Diez From deets at nospam.web.de Tue Feb 9 03:47:42 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 09 Feb 2010 09:47:42 +0100 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <7tclpfFccvU1@mid.uni-berlin.de> Am 09.02.10 07:00, schrieb OdarR: > On 9 f?v, 02:50, Jean-Michel Pichavant wrote: >> Aahz wrote: >>> In article<0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>, >>> OdarR wrote: >> >>>> and with eval(), did you try ? >> >>> WARNING: eval() is almost always the wrong answer to any question >> >> Some say that eval is evil ! >> >> JM > > go to hell ;-), it is part of the language, it seems to match the > aforementioned question. And if the extension happens to be valid python-code, you might inject code malus code through the filename. Great idea! globals()["function_" + ext]() is all you need, and doesn't suffer from that attack vector. Diez From george.sakkis at gmail.com Tue Feb 9 03:54:08 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Tue, 9 Feb 2010 00:54:08 -0800 (PST) Subject: To (monkey)patch or not to (monkey)patch, that is the question Message-ID: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> I was talking to a colleague about one rather unexpected/undesired (though not buggy) behavior of some package we use. Although there is an easy fix (or at least workaround) on our end without any apparent side effect, he strongly suggested extending the relevant code by hard patching it and posting the patch upstream, hopefully to be accepted at some point in the future. In fact we maintain patches against specific versions of several packages that are applied automatically on each new build. The main argument is that this is the right thing to do, as opposed to an "ugly" workaround or a fragile monkey patch. On the other hand, I favor practicality over purity and my general rule of thumb is that "no patch" > "monkey patch" > "hard patch", at least for anything less than a (critical) bug fix. So I'm wondering if there is a consensus on when it's better to (hard) patch, monkey patch or just try to work around a third party package that doesn't do exactly what one would like. Does it have mainly to do with the reason for the patch (e.g. fixing a bug, modifying behavior, adding missing feature), the given package (size, complexity, maturity, developer responsiveness), something else or there are no general rules and one should decide on a case-by-case basis ? George From klausneuner72 at googlemail.com Tue Feb 9 04:04:20 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Tue, 9 Feb 2010 01:04:20 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> Message-ID: <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> > go to hell ;-), it is part of the language, it seems to match the > aforementioned question. Thats right. In fact, your code is the precise analogy of my Prolog example in Python. Obviously, eval() and call() are both inherently dangerous. They should never be used in programs that are used in programs that get input from people other than the author. Yet, my program is supposed to parse files that I have created myself and that are on my laptop. It is not supposed to interact with anybody else than me. On the other hand, I think, it is worthwhile getting acquainted with the getattr-stuff, because this method can be useful in many contexts. Anyway, thanks to all who participated in this thread. It taught me a lot. From alfps at start.no Tue Feb 9 04:08:15 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 10:08:15 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> Message-ID: * Steven D'Aprano: > On Tue, 09 Feb 2010 08:19:56 +0100, Alf P. Steinbach wrote: > >> You don't have anything /but/ pointers in Python. > > x = 5 The above assigns to x a pointer to an object whose value is 5: x ------> 5 > y = "hello" Ditto result: y ------> "hello" And if now do x = y then the code is assigning (copying) to x the pointer in y: x ----------- \ y ---------- > "hello" which you can check by assert( x is y ) or assert( id( x ) == id( y ) ) and which becomes essential to understand when that object is mutable... Like: x = [1, 2, 3, 4] y = "hello" y = x y.append( 5 ) print( x ) > You want us to accept that the values of x and y are some mysterious > pointer entities rather than the integer object 5 and the string object > "hello". The basics of pointers are simple. You can copy pointers (assignment, argument), and you can check for equality (is), and you can refer to the object that's pointed to (attribute access, indexing, operators). And in CPython you can even obtain the pointer value as an integer via id(). So there's nothing mysterious. In particular x = [1, 2, 3, 4] y = x does not copy the object value, it only copies the pointer. That also matters for e.g. x = 10000000*"A" y = x And aliasing, like in the last three examples above, is pretty difficult to understand without a pointer view of things. And if aliasing is not understood, then forever stranded at beginner's level. > At the point that your explanation depends on the reader understanding > that the value of a variable x is not actually the thing that they assign > to x, but some mysterious, invisible entity that exists entirely inside > the implementation where the user can never reach, you probably should > rethink your attachment to that explanation. No wonder so many Java > programmers are still confused by it. Thanks for thinking about my writings. As it happens I've already written about pointers in chapter 2, although not mentioning the word "pointer". :-) I made do with the term "reference", because in Python there's not anything else (in particular there's no pass by reference) that could cause confusion. However, that cop-out (is that the right term?) wouldn't work for text based on a language like C++, which has another kind of reference, or for that matter C# which is like Python and Java except that C# also has pass by reference... Some mixed feedbacks on that writing, but it's section 2.6.7 "References & automatic garbage collection" in ch 2 "Basic concepts" at (I hope I typed the URL correctly). > It might help your case if we had a word for the thing that is actually > assigned to the variable. In plain English that is "value", but you want > to use that for the pointer to the thing-that-we-otherwise-would-call- > value, which leaves us no simple way to talk about the int 5 and string > "hello". There are two values: the pointer value, and the object value. In CPython: >>> a = "blah" >>> str.format( "Pointer = {0}, object = {1}".format( id( a ), a ) ) 'Pointer = 12090272, object = blah' >>> _ More simply, there's the pointer and there's the object pointed to. Or, in the not-very-general-but-I-think-works-in-Python terminology that I used in 2.6.7, there's the reference and there's the object. So the thing that's actually assigned to a variable is in language-independent terminology a "pointer" (or pointer value), although that doesn't mean C or Pascal or whatever specific language pointer but just a copyable object reference, and perhaps in Python-specific terminology it's just a "reference". I don't know better terms... Cheers, - Alf From stefan_ml at behnel.de Tue Feb 9 04:21:29 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Feb 2010 10:21:29 +0100 Subject: intolerant HTML parser In-Reply-To: References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> Message-ID: <4b712919$0$6584$9b4e6d93@newsspool3.arcor-online.net> Lawrence D'Oliveiro, 08.02.2010 22:39: > In message <4b6fe93d$0$6724$9b4e6d93 at newsspool2.arcor-online.net>, Stefan > Behnel wrote: > >> - generating HTML using a tool that guarantees correct HTML output > > Where do you think these tools come from? Usually PyPI. Stefan From waku at idi.ntnu.no Tue Feb 9 04:51:57 2010 From: waku at idi.ntnu.no (waku) Date: Tue, 9 Feb 2010 01:51:57 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: On Feb 2, 10:49?pm, Jonathan Gardner wrote: > On Feb 2, 2:21?am,waku wrote: [...] > > there are languages where indentation can be either enforced and allow > > one to omit some syntactic nuissance like braces or begin-end clauses, > > or made optional, requiring other syntactic means for delimiting > > blocks etc. ?(consider f# with its #light declaration, for example.) > > If you're writing "experimental code", you're doing it wrong. Every > line of code you write may end up on the space shuttle one day (so to > speak!) Why not write the code well-formatted in the first place, so > that any bugs you introduce are as easily visible as possible? you're missing the large part of the language's customers that use it specifically for experimenting. they're not developing space shuttles, but rather explore available data, experiment with algorithms, etc. (and for space shuttles, i doubt python is the first choice anyway.) yes, i am writing lots of experimental code, and i know many who do, too, and there is *nothing* wrong about it. and then, i sometimes use ipython to interactively experiment, saving the input to a log file, and editing it afterwards as needed. and just the mere fact that i *have* to adapt my editor to ipython's indentation policy (or vice versa) whenever working with others' code because otherwise the code fails, is fairly annoying. there is nothing wrong or stupid about the editor in this respect. > The only reason why you may want to write crap code without proper > formatting is because your text editor is stupid. 'proper' formatting is, in some languages, something achieved by simply running a pretty formatter. in some, it's the job of the programmer. it has nothing to do with the claimed stupidity of the editor. > If that's the case, > get rid of your text editor and find some tools that help you do the > right thing the first time. [...] > If you're text editor has a problem with indenting, you have a > terrible text editor. Period, end of sentence. > you're just wrong. > You can't screw in bolts with a hammer, and you can't level with a > saw. ... and you can't freely format you code with python. > Don't try to write code in any language without a real text 'real'? meaning one able to guess how to combine code from multiple developers with different indentation policies, for example, one using tabs, another four spaces, and yet another eight? (which is not at all uncommon, and not quite wrong or stupid.) > editor that can do proper indentation. Don't let your teammates use > deficient text editors either. I wouldn't appreciate it if I delivered > precision components that my teammates tried to install with > sledgehammers. > > This is the 21st Century. Good text editors are not hard to find on > any platform. 'stupid', 'wrong', 'deficient', 'terrible', ... you're using strong words instead of concrete arguments, it might intimidate your opponents, but is hardly helpful in a fair discussion. vQ From stefan_ml at behnel.de Tue Feb 9 05:01:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 09 Feb 2010 11:01:04 +0100 Subject: use strings to call functions In-Reply-To: <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> Message-ID: <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> Klaus Neuner, 09.02.2010 10:04: > my program is supposed to parse files that I have created myself and that > are on my laptop. It is not supposed to interact with anybody else > than me. Famous last words. Stefan From peloko45 at gmail.com Tue Feb 9 05:06:52 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 9 Feb 2010 02:06:52 -0800 (PST) Subject: Simulating logging.exception with another traceback References: <0c13d3f7-addf-4972-91c3-6f41fadfb2b5@u26g2000yqm.googlegroups.com> <3512c1a4-01e3-449d-8e48-e673e668bb17@u26g2000yqm.googlegroups.com> Message-ID: <1ec8b017-36cc-4ed2-b6d1-52ddc5015d13@b7g2000yqd.googlegroups.com> On 8 feb, 21:13, Vinay Sajip wrote: > On Feb 7, 11:22?am, Joan Miller wrote: > > > > > I would want to get the output from `logging.exception` but with > > traceback from the caller function (I've already all that > > information). > > > This would be the error withlogging.exception: > > -------------------- > > ERROR: > > ? PipeError('/bin/ls -l | ?', 'no command after of pipe') > > Traceback (most recent call last): > > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > > 160, in __call__ > > ? ? raise PipeError(command, 'no command after of pipe') > > PipeError: ('/bin/ls -l | ?', 'no command after of pipe') > > -------------------- > > > And I've trying it with: > > -------------------- > > message = "File \"{0}\", line {1}, in {2}\n\n ?{3}".format( > > ? ? ? ? ? ? ? ? file, line, function, caller)logging.error(message) > > > ERROR: > > ? File "/data/neo/Proyectos/Python/Scripy/lib/scripy/shell.py", line > > ? 163, in __call__ ? ?return self.throw(PipeError, command, 'no > > ? command after of pipe') > > -------------------- > > > Could be used `logging.LogRecord` [1] to get it? How? > > > [1]http://docs.python.org/library/logging.html#logging.LogRecord > > Sorry, Joan, > > I don't understand your question. Can you create a short script which > throws an exception, and show exactly how you want it formatted? > > The logger.exception method does the same as logger.error, except that > it prints exception trace information and is intended to be called > from exception handling clauses. You can format exceptions how you > like by subclassing Formatter and overriding formatException. > > Regards, > > Vinay Sajip Hi! I want to throw `logging.exception()` [1] but using the traceback of caller's function, so: --------- up=1 frame = traceback.extract_stack(limit=up+2) --------- Reading the code, `traceback.print_exception` prints the message from a record got with `LogRecord.getMessage()` [2] So I'm supposed that I'd have to use it to get a new record that can be used by `traceback.print_exception`. [1] http://code.python.org/hg/branches/release2.6-maint-full/file/f5a05355fe48/Lib/logging/__init__.py#l408 [2] http://code.python.org/hg/branches/release2.6-maint-full/file/f5a05355fe48/Lib/logging/__init__.py#l423 From gagsl-py2 at yahoo.com.ar Tue Feb 9 05:11:05 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 07:11:05 -0300 Subject: Need installer recommendation References: <6q2rm5htqdj2puinbg9pmkco8o6nhd72h5@4ax.com> Message-ID: En Sat, 06 Feb 2010 12:45:39 -0300, Alan Biddle escribi?: > I could use a recommendation on a free installer for use by an > unsophisticated programmer, that would be me, for some simple programs > which are a bit more than "Hello World," but only a little. Basically > reading text files and processing the results. Nothing fancy. I am > using PY2EXE to create the distribution. > > In doing the Google, and from past posting here, I see that most > recommendations are for inno and nsis. I expect that either would do > what I want. Is one a better choice for someone to learn enough to do > basic stuff without getting bogged down in details which are not > immediately important? I, for myself, prefer InnoSetup. For a simple and standard installer, just use the wizard to create it, and you're done. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Tue Feb 9 05:11:09 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 07:11:09 -0300 Subject: Pickling an extension type subclasses problems References: Message-ID: En Fri, 05 Feb 2010 11:25:02 -0300, Gaetan de Menten escribi?: > I am trying to write an (optional!) C extension for SQLAlchemy, and I > am struggling to make an extension type picklable *and* using the same > format as the pure Python version (so that computers with the C > extension can unpickle pickles from computers without it and > vice-versa). [...] > My last hope is to define __reduce__ on the Python > side too, That seems reasonable. > and make it use a module-level "reconstructor" function as > follow: > > def mypythontype_reconstructor(cls, state): > obj = object.__new__(cls, state): > .... > return obj > > Will this work? Any other idea? If you're going to call object.__new__(cls, state) anyway, then just return the object's type as the first item in __reduce__; no need to create such global function -- Gabriel Genellina From jeanmichel at sequans.com Tue Feb 9 05:25:42 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 11:25:42 +0100 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> Message-ID: <4B713826.6010009@sequans.com> Carl Banks wrote: > On Feb 8, 12:20 pm, spike wrote: > >> Has anyone been able to come across a Python logic map or Python logic >> flow chart? >> >> An example can be seen on the right under History:http://en.wikipedia.org/wiki/Usenet#History >> >> This would be very helpful for all users. >> > > > Begin > | > | > V > Start Editor > | > | > V > Write Code <----+ > | | > | | > V | > Run Python | > | | > | | No. > V | > Did it do what you want? > | > | Yes. > | > V > Stop. > > > HTH. > > > Carl Banks > I use this one: Begin | | V Start Mail client | | V Ask python-list <-----+ | | | | V what a bunch of dumbass wait 2 min | | | | | No. V | Did you get any answer ? | | Yes. | V Stop. JM From jeanmichel at sequans.com Tue Feb 9 05:39:58 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 11:39:58 +0100 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <4B713826.6010009@sequans.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <49d5eb96-1a07-47a3-bc7b-e54ab963151d@l26g2000yqd.googlegroups.com> <4B713826.6010009@sequans.com> Message-ID: <4B713B7E.3080302@sequans.com> >> > > I use this one: > > Begin > | > | > V > Start Mail client > | > | > V > Ask python-list <-----+ > | | > | | > V what a bunch of dumbass wait 2 min | > | | > | | No. > V | > Did you get any answer ? > | > | Yes. > | > V > Stop. > > > > JM How to miss a joke thanks to some crappy line word wraping whatsoever feature. I'll burn thunderbird. Don't use it ! JM From duncan.booth at invalid.invalid Tue Feb 9 05:44:57 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 9 Feb 2010 10:44:57 GMT Subject: Modifying Class Object References: Message-ID: "Alf P. Steinbach" wrote: > A copyable reference is a pointer. That is, a "pointer", in e.g. the > Java sense, > and in the general language independent sense, means a copyable > reference -- as illustrated e.g. in the Stanford computer science > 101 course page I > referred you to earlier, with C versus Java pointers illustrated in > the concrete. The fact that C style pointers are used internally is an detail of the CPython implementation. In CPython objects once created remain in the same memory location (and their id is their address). Compare that to IronPython where the objects themselves can move around in memory so they have no fixed address. Try comparing the IronPython implementation to C pointers and you'll cause a lot of confusion. e.g. someone might think the id() value is in some way related to an address. Ruby implements integers without using any pointers at all: there's nothing in the Python specification which prevents a Python implementation doing the same for small integers, in fact I believe it has been tried but wasn't found to improve performance. The terminology of 'objects', 'names', 'references' describes an abstract machine. The Python runtime can implement it in any way it chooses so long as those semantics are preserved. One implementation involves 'pointers', but that word implies other baggage which is not a required part of the model. -- Duncan Booth http://kupuguy.blogspot.com From wolftracks at invalid.com Tue Feb 9 05:50:05 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 09 Feb 2010 02:50:05 -0800 Subject: Socket Error: Permission Denied (Firewall) In-Reply-To: References: Message-ID: (corrected typos) I decided to go with outbound in McAfee. Now when I run the program, I get a long list of messages about deprecations and NumpyTest will be removed in the next release. please update code to nose or unittest. From steve at holdenweb.com Tue Feb 9 07:31:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:31:17 -0500 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) In-Reply-To: <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> Message-ID: spike wrote: > On Feb 8, 1:35 pm, Gary Herron wrote: >> spike wrote: >>> Has anyone been able to come across a Python logic map or Python logic >>> flow chart? >>> An example can be seen on the right under History: >>> http://en.wikipedia.org/wiki/Usenet#History >>> This would be very helpful for all users. >> Huh??? What aspect of Python were you thinking of mapping out? >> >> Your example us a bad ascii art graph of -- I've no clue what? >> >> Gary Herron > > Do you know what "Logic" means? Guess not. Before you comedians quit > your day job some people are looking for information. If you have > nothing positive to say, go pester somewhere else. > > Grow up. Oh right, we forgot, it's our duty to answer every question that comes in, seriously and to the point, no matter how badly it is phrased and how obnoxious the questioner becomes when the answer is not immediately forthcoming. This is the Intarwebs. I suggest it's *you* who needs to grow up. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 07:38:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:38:42 -0500 Subject: equivalent of Ruby's Pathname? In-Reply-To: <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> Message-ID: Phlip wrote: > Carl Banks wrote: > >> I don't know if it was the reason it was rejected, but a seriously >> divisive question is whether the path should be a subset of string. > > OMG that's nothing but the OO "circle vs ellipse" non-question. Glad > to see the Committee derailed a perfectly good library over such > sophistry. > That's nothing but the most arrant nonsense, as you would discover if you took the trouble to read the discussion on python-dev instead of jumping to conclusions. >> Under ordinary circumstances it would be a poor choice for inheritance >> (only a few string methods would be useful fot a pathname), but some >> people were fiercely adamant that paths should be passable to open() >> as-in (without having to explicity convert to string). > > That's just silly. To be object-based, you should say path.open('r'). > fopen() and its ilk are too 1960s... > What? Are you arguing for "myfile.txt".open('r') to be a valid Python construct? If not then surely you can see that paths would require different treatment from strings, which was the main thrust of the discussion on the dev list. I find it really irritating when the clueless come along and criticize decisions made by the developers after thorough discussion. Not only do decisions have to be made about how code is going to work (and work for the next twenty years or so), but someone has to commit to maintaining the code before it goes in (otherwise Python will be full of bit-rot). To call your criticism ill-informed would be flattering it. > My 5th Grade science teacher, one Eunice Feight, once expressed > chagrin for submitting a proposal to Readers' Digest, and getting it > accepted. She sold them the following sloka: > > Don't be clever don't be witty > Or you'll wind up BEING the Committee! > Criticism isn't pretty Specially when your logic's shitty. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 07:40:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:40:55 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden > wrote: > > Stephen Hansen wrote: > [...] > > P.S. I couldn't resist. :( > > > > And here I was, sitting on my hands ... but someone was wrong on the > Internet, so D'Aprano had to put them right. Your fatal weakness. > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." > > > This is getting out of hand. > > First, someone thought I was you. > > Now you think I'm D'Aprano. > > I'm just gonna go by Bob for now on. > > :) > Sorry about that, Bob. But you have to admit your pedantry was rather D'Aprano-like (I have these feeling I just insulted you both with one sentence). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 07:44:38 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 07:44:38 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: Alf P. Steinbach wrote: > * Stephen Hansen: [...] >> I've heard that before, and have no idea why, nor any real interest in >> solving it: I don't want to read cpl via Usenet, and prefer to read it >> as a mailing list. Somewhere between Gmail->python.org->python.org >> 's usenet server->the world, some people don't seem >> to get my posts. Yet it shows up on some news servers, not others. >> >> No idea. Nothing I know of can solve it. > > Not sure, but perhaps it's possible to mail directly to gmane? > Is there *any* problem you don't have a fatuous answer for? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From clp2 at rebertia.com Tue Feb 9 07:52:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Feb 2010 04:52:02 -0800 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <89d4fa66-8749-4551-909b-96f9182fd8c5@l24g2000prh.googlegroups.com> Message-ID: <50697b2c1002090452g502c30c7jaea48a4e4f821a37@mail.gmail.com> On Tue, Feb 9, 2010 at 4:38 AM, Steve Holden wrote: > Phlip wrote: >> Carl Banks wrote: >> >>> I don't know if it was the reason it was rejected, but a seriously >>> divisive question is whether the path should be a subset of string. >> >> OMG that's nothing but the OO "circle vs ellipse" non-question. Glad >> to see the Committee derailed a perfectly good library over such >> sophistry. >> > That's nothing but the most arrant nonsense, as you would discover if > you took the trouble to read the discussion on python-dev instead of > jumping to conclusions. > >>> Under ordinary circumstances it would be a poor choice for inheritance >>> (only a few string methods would be useful fot a pathname), but some >>> people were fiercely adamant that paths should be passable to open() >>> as-in (without having to explicity convert to string). >> >> That's just silly. To be object-based, you should say path.open('r'). >> fopen() and its ilk are too 1960s... >> > What? Are you arguing for "myfile.txt".open('r') to be a valid Python > construct? If not then surely you can see that paths would require > different treatment from strings, which was the main thrust of the > discussion on the dev list. Based on the context, I'm /pretty/ sure he was (implicitly) talking about e.g. Path("myfile.txt").open('r'). Cheers, Chris -- http://blog.rebertia.com From roy at panix.com Tue Feb 9 08:21:35 2010 From: roy at panix.com (Roy Smith) Date: Tue, 09 Feb 2010 08:21:35 -0500 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: In article <00fa27a3$0$15628$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) No pig latin? From phlip2005 at gmail.com Tue Feb 9 09:00:23 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 9 Feb 2010 06:00:23 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > It wouldn't just be open() that people would want modified -- > it would be every other function that takes a pathname as > well. Then refer to the same argument against implicit type conversions in C+ +. A ::std::string must call .c_str() to turn into a lowly char*, before passing into a C function. Advocating for 8 characters of convenience opens the risk of silent bugs at refactor time. > I seem to recall another point of contention was whether > path objects should have methods for accessing the file > system (opening files, renaming them, etc.) or whether it > should confine itself to representing and manipulating > pathnames. In that case, the package I picked seems to have "erred" on the side of programmer convenience. Because the basic file operations (exist, stat, move/rename, copy, open, chmod, unlink) come as a complete and whole kit, a class should simply present that kit, insulating against filesystem differences. > In any case, introducing any kind of path object at this > late stage of the language's development would result in > More Than One Way to represent pathnames, with neither of > them being the obvious choice. Ah, now we get down to the root of the problem. Because Python is so stuck on the "one best way to do it" mentality, language bigotry prevented the Committee from picking from among several equally valid but non-best options. And after 20 years of growth, Python still has no Pathname class. What a mature community! C-: -- Phlip http://c2.com/cgi/wiki?MoreliaViridis From tiagokatcipis at gmail.com Tue Feb 9 09:01:31 2010 From: tiagokatcipis at gmail.com (Tiago Katcipis) Date: Tue, 9 Feb 2010 12:01:31 -0200 Subject: event handling in pyuthon In-Reply-To: <581ce2791002082320t2af425ffif36e6683e08cd038@mail.gmail.com> References: <581ce2791002082320t2af425ffif36e6683e08cd038@mail.gmail.com> Message-ID: <60a9403b1002090601v783534e2q496b499070dbed61@mail.gmail.com> On Tue, Feb 9, 2010 at 5:20 AM, Bujji wrote: > hi all, > any event handling mechanisms in python ? > i want event handler examples in python > dont know if it is this that you are looking for: http://home.gna.org/py-notify/ > > > Thanks > Bujji > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Carolyn.Nevills at fortbend.k12.tx.us Tue Feb 9 09:04:53 2010 From: Carolyn.Nevills at fortbend.k12.tx.us (Nevills, Carolyn) Date: Tue, 9 Feb 2010 08:04:53 -0600 Subject: Plese take me off the mailing list Message-ID: Good morning, Please take my name off your mailing list . Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: From twistedphrame at gmail.com Tue Feb 9 09:11:24 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 06:11:24 -0800 (PST) Subject: errno 107 socket.recv issue Message-ID: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> I have a simple tcp server and client where the server sits and waits for a message and then processes it, my client sends its first message to the server. On the server I receive: socket.error: [Errno 107] Transport endpoint is not connected when calling msg = self.socket.recv(self.buffer) My client receives the error: socket.error: [Errno 104] Connection reset by peer when calling msg = self.socket.recv(self.buffer) I was working on the server and client over the weekend and sending and receiving worked fine, I wanted to debug a few things and I get this when I try to run it (no changes made from what I had on the weekend) From ALANBIDDLE70 at YAHOO.COM Tue Feb 9 09:17:40 2010 From: ALANBIDDLE70 at YAHOO.COM (Alan Biddle) Date: Tue, 09 Feb 2010 08:17:40 -0600 Subject: Need installer recommendation References: <6q2rm5htqdj2puinbg9pmkco8o6nhd72h5@4ax.com> Message-ID: Thanks you very much for the suggestion. I will give it a try. Since I posted the original question, I have tried PyInstaller. I am using Python 2.6.4, which is technically not supported, but it worked fine for the simple programs I tried, and simple enough even for me. ;) -- Alan From steve at holdenweb.com Tue Feb 9 09:30:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 09:30:55 -0500 Subject: errno 107 socket.recv issue In-Reply-To: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> Message-ID: Jordan Apgar wrote: > I have a simple tcp server and client where the server sits and waits > for a message and then processes it, my client sends its first message > to the server. On the server I receive: > > socket.error: [Errno 107] Transport endpoint is not connected > when calling > msg = self.socket.recv(self.buffer) > > My client receives the error: > socket.error: [Errno 104] Connection reset by peer > when calling > msg = self.socket.recv(self.buffer) > > I was working on the server and client over the weekend and sending > and receiving worked fine, I wanted to debug a few things and I get > this when I try to run it (no changes made from what I had on the > weekend) My car has this problem. It makes a noise when it rolls along the road. I've brought the wheel for you to take a look at, can you fix it, please? ;-) A little more context might be helpful - at least the error traceback and the code that makes the socket calls. I presume you are using TCP judging by the client error message. This implies the server isn't listening. Have you correctly bound the socket to an IP address and port before issuing an accept() call? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From misceverything at gmail.com Tue Feb 9 09:52:26 2010 From: misceverything at gmail.com (T) Date: Tue, 9 Feb 2010 06:52:26 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> On Feb 8, 2:25?pm, David Bolen wrote: > T writes: > > I have a script, which runs as a Windows service under the LocalSystem > > account, that I wish to have execute some commands. ?Specifically, the > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > an admin account, all is well. ?However, when I'm running it via > > service, no luck. ?I'm assuming this is to do with the fact that it's > > trying to run under the LocalSystem account, which is failing. ?What > > would be the best way around this? ?Thanks! > > The LocalSystem account is not, if I recall correctly, permitted to > access the network. > > You'll have to install the service to run under some other account that > has appropriate access to the network. > > -- David The more testing I do, I think you may be right..I was able to get it to work under a local admin account, and it worked under debug mode (which would also have been running as this user). I'm a bit surprised though - I was under the assumption that LocalSystem had rights to access the network? From jeanmichel at sequans.com Tue Feb 9 09:56:41 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 15:56:41 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> Message-ID: <4B7177A9.30809@sequans.com> Jordan Apgar wrote: > I have a simple tcp server and client where the server sits and waits > for a message and then processes it, my client sends its first message > to the server. On the server I receive: > > socket.error: [Errno 107] Transport endpoint is not connected > when calling > msg = self.socket.recv(self.buffer) > > My client receives the error: > socket.error: [Errno 104] Connection reset by peer > when calling > msg = self.socket.recv(self.buffer) > > I was working on the server and client over the weekend and sending > and receiving worked fine, I wanted to debug a few things and I get > this when I try to run it (no changes made from what I had on the > weekend) > Unless you want to know more about net coding, I would suggest to use libraries for that. Pyro or xmlrpclib are among the most used. Then if you have any connection problem, that's because there is a connection problem. Not because you mess up with your net code. JM From python-url at phaseit.net Tue Feb 9 10:03:02 2010 From: python-url at phaseit.net (Gabriel Genellina) Date: Tue, 9 Feb 2010 15:03:02 +0000 (UTC) Subject: Python-URL! - weekly Python news and links (Feb 9) Message-ID: QOTW: "You see? That's what I like about the Python community: people even apologise for apologising :)" - Tim Golden http://groups.google.com/group/comp.lang.python/msg/858d1c31d0c2adff The third alpha version of Python 2.7 is ready for testing: http://groups.google.com/group/comp.lang.python/t/6f49dacfe8759508/ How to enumerate all possible strings matching a given regular expression: http://groups.google.com/group/comp.lang.python/t/1b78346c6661ac4f/ Which language features do you like most? http://groups.google.com/group/comp.lang.python/t/599b3c9772421ece/ Implementing a two-dimensional array in a simple way seems to actually be more efficient than other, more sophisticated alternatives: http://groups.google.com/group/comp.lang.python/t/55e595d6dc4ca3f4/ The new GIL (to be implemented in Python 3.2) will provide less overhead, especially in multicore CPUs: http://groups.google.com/group/comp.lang.python/t/586ef2d3685fa7ea/ In Python 3, 'exec' inside a function does not have the same effect as before: http://groups.google.com/group/comp.lang.python/t/7a046e4ede9c310a/ Using Queue objects to feed and synchronize several worker threads: http://groups.google.com/group/comp.lang.python/t/32256dd608c9c02/ New generation IDEs should provide much better and integrated refactoring tools: http://groups.google.com/group/comp.lang.python/t/e019614ea149e7bd/ There is no module in the standard library to handle filesystem paths in an OO way - but why? http://groups.google.com/group/comp.lang.pythonf580fb3763208425ece/ A "History Channel" special: how the way a TAB key was interpreted changed over time http://groups.google.com/group/comp.lang.python82d9181fcd31ffea3f4/ After a false start, finally we get our first "Is it Call-By-Value or Call-By-Reference?" thread of the year! http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Just beginning with Python? This page is a great place to start: http://wiki.python.org/moin/BeginnersGuide/Programmers The Python Papers aims to publish "the efforts of Python enthusiasts": http://pythonpapers.org/ The Python Magazine is a technical monthly devoted to Python: http://pythonmagazine.com Readers have recommended the "Planet" site: http://planet.python.org comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/group/comp.lang.python.announce/topics Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html The Python Package Index catalogues packages. http://www.python.org/pypi/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donations/ The Summary of Python Tracker Issues is an automatically generated report summarizing new bugs, closed ones, and patch submissions. http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date nullege is an interesting search Web application, with the intelligence to distinguish between Python code and comments. It provides what appear to be relevant results, and demands neither Java nor CSS be enabled: http://www.nullege.com Although unmaintained since 2002, the Cetus collection of Python hyperlinks retains a few gems. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://code.activestate.com/recipes/langs/python/ Many Python conferences around the world are in preparation. Watch this space for links to them. Among several Python-oriented RSS/RDF feeds available, see: http://www.python.org/channews.rdf For more, see: http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://www.python.org/dev/peps/pep-0042/ del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python Enjoy the *Python Magazine*. http://pymag.phparch.com/ *Py: the Journal of the Python Language* http://www.pyzine.com Dr.Dobb's Portal is another source of Python news and articles: http://www.ddj.com/TechSearch/searchResults.jhtml?queryText=python and Python articles regularly appear at IBM DeveloperWorks: http://www.ibm.com/developerworks/search/searchResults.jsp?searchSite=dW&searchScope=dW&encodedQuery=python&rankprofile=8 Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://search.gmane.org/?query=python+URL+weekly+news+links&group=gmane.comp.python.general&sort=date http://groups.google.com/groups/search?q=Python-URL!+group%3Acomp.lang.python&start=0&scoring=d& http://lwn.net/Search/DoSearch?words=python-url&ctype3=yes&cat_25=yes There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". Write to the same address to unsubscribe. -- The Python-URL! Team-- Phaseit, Inc. (http://phaseit.net) is pleased to participate in and sponsor the "Python-URL!" project. Watch this space for upcoming news about posting archives. From twistedphrame at gmail.com Tue Feb 9 10:20:33 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 07:20:33 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> Message-ID: <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> I found my car ;) here's the server: class commServer: """Class to hold a tcp server and interact with with it allows for a wrapper around socket class to keep code clean""" def __init__ (self, host, hostid, port, buff =1024): self.host = host self.hostid = hostid #id of the server self.port = port self.buffer = buff self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.conn = None self.addr = None def bindServ(self): """Connect to the server specified by self.host, self.port""" self.socket.bind((self.host, self.port)) def closeConn(self): """Disconnect from the server connected to""" self.conn.close() def listen(self): self.socket.listen(1) def accept(self): self.conn, self.addr = self.socket.accept() #lets you send a string msg to the server def sendMSG(self, msg): self.conn.send(msg) #lets you receive data from the server def recvMSG(self): msg = self.socket.recv(self.buffer) if msg == "": #if the client disconnected let's not throw return False else: return msg class Negotiator: """Negotiator for the server handles all communication with the client to verify the server and prepare the file the client wants for download""" def __init__(self, host, hostid, port, rsa_key): self.server = commServer(host,hostid,port) def Negotiate(self): self.server.bindServ() self.server.listen() self.server.accept() #Plan on being asked for server confirmation clmsg = self.server.recvMSG() # it fails right here on the server calling the Server Negotiator as: host = "127.0.0.1" port = 8005 HOSTID = a string key = an RSA key servernegotiator = Negotiator(host,HostID, port, key) if servernegotiator.Negotiate() == False: print "something went wrong" print "Done" for the client it is: class commClient: """Class to hold a tcp client and interact with with it allows for a wrapper around socket class to keep code clean""" def __init__ (self, host, hostid, port, buff =1024): self.host = host self.hostid = hostid #id of the server self.port = port self.buffer = buff self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def connectServ(self): """Connect to the server specified by self.host, self.port""" self.socket.connect((self.host, self.port)) def disconnServ(self): """Disconnect from the server connected to""" self.socket.close() #lets you send a string msg to the server def sendMSG(self, msg): self.socket.send(msg) #lets you receive data from the server def recvMSG(self): msg = self.socket.recv(self.buffer) if msg == "": #if the server disconnected let's not throw something later return False else: return msg class Negotiator: """The Negotiator handles all communications and message handling necessary for verifying the server, and that the file is available to download""" def __init__(self, host, hostid, port, rsa_key): """client should be a commClient object that has not been connected to the server.""" self.client = commClient(host, hostid, port) self.clientKey = rsa_key self.serverKey = None self.CScipher = None #AES cipher for client -> server self.SCcipher = None #AES cipher for server -> client self.CShalves = None #tuple for random halves by client self.SChalves = None #tuple for random halves by server self.file = None def Negotiate(self, fname): """Contact the server, verify the server, negotiates for a file to be downloaded by the client. It returns the file name to be downloaded, and the cipher to decrypt it.""" self.client.connectServ() print "connected" #tell the server you want to connect clmsg = message(CONN, (self.client.getHost(), self.client.getHostID())) #message acts as a wrapper around a message type and the data for the type self.client.sendMSG(clmsg.getSendable()) # here is were it fails the Negotiator is called as: host = "127.0.0.1" port = 8005 HOSTID is the same string as before key is an RSA key clientnegotiator = Negotiator(host, HostID, port, key) filename = clientnegotiator.Negotiate("hostid") the stack traces are: Server side: Traceback (most recent call last): File "Server.py", line 17, in if servernegotiator.Negotiate() == False: File "/home/twistedphrame/Desktop/communication/ ServerNegotiator.py", line 184, in Negotiate clmsg = self.server.recvMSG() File "/home/twistedphrame/Desktop/communication/ ServerNegotiator.py", line 67, in recvMSG msg = self.socket.recv(self.buffer) socket.error: [Errno 107] Transport endpoint is not connected Client Side: File "Client.py", line 17, in filename = clientnegotiator.Negotiate("hostid") File "/home/twistedphrame/Desktop/communication/ ClientNegotiator.py", line 209, in Negotiate srvmsg = self.client.recvMSG() File "/home/twistedphrame/Desktop/communication/ ClientNegotiator.py", line 55, in recvMSG msg = self.socket.recv(self.buffer) socket.error: [Errno 104] Connection reset by peer From gnarlodious at gmail.com Tue Feb 9 10:21:28 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 07:21:28 -0800 (PST) Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> Message-ID: On Feb 9, 12:15?am, Raymond Hettinger wrote: > You may be able to monkey patch an OrderedDict into the PlistParser. > Here's an untested stab at it: > > ? ? from collections import OrderedDict > ? ? import plistlib > ? ? plistlib._InteralDict = OrderedDict Genius! After fixing the misspelled InteralDict I got this: from collections import OrderedDict import plistlib plistlib._InternalDict = OrderedDict plistlib.readPlist('/path/to/some.plist') --> OrderedDict([('List', 'of'), ('tuples', 'in'), ('plist', 'order')]) So thank you for that [somewhat contorted] solution. (PyN00b): Now how do I extract the list from the function? -- Gnarlie From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 9 10:23:59 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Feb 2010 16:23:59 +0100 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <4b717e07$0$14666$426a34cc@news.free.fr> Phlip a ?crit : > Gregory Ewing wrote: > >> In any case, introducing any kind of path object at this >> late stage of the language's development would result in >> More Than One Way to represent pathnames, with neither of >> them being the obvious choice. > > Ah, now we get down to the root of the problem. Because Python is so > stuck on the "one best way to do it" > mentality, language bigotry > prevented the Committee from picking from among several equally valid > but non-best options. You failed to actually _read_ what you're answering to. Try again. Using your brain, this time. From apt.shansen at gmail.com Tue Feb 9 10:27:06 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:27:06 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> On Mon, Feb 8, 2010 at 10:35 PM, Alf P. Steinbach wrote: > Right. > > "pass by value" is a lower level notion. > > And as you show below, in the paragraph marked [1], it can be used to > describe call by sharing very succinctly and precisely, just as I did... ;-) No. There's nothing at all succinct or precise about either "value" or "reference" when speaking of programming languages, and using both together just compounds that. They are loaded words. The phrase "call my value where value is an object reference" is not clear, not obvious, not helpful. It requires far too much explanation of every single word there, depending on the background of who you are speaking to, to explain how it does not exactly use any of the words in a way which the person may be expecting, and making sure they understand that it does not imply anything that those words usually imply. I'm not even going to bother further-- I shouldn't have to begin with-- your entire post is full of arguments with no more weight then, "I say this means that, and its clearer" with absolutely no regard for the fact that all of these words have weight and meaning to the world outside of your head. Python has objects, and objects have names. Objects are never copied implicitly, and objects can be referred to by many names in many places, thus you may share those objects as you see fit. Some objects you may change, some objects you may not. An object exists so long as someone has a name for it. Period, end of line. That's the mental model and passing model that is valid in Python. There are no "copyable references", because a reference is a 'thing' and copying it is an action. In Python there are simply objects. That's where the abstraction begins and ends. What is so obvious, precise, succinct and clear to YOU is mixing loaded terms with a implications and semantic expectations from countless other languages and sources in computer science. If you want to think of things that way in your head, then by all means, do so. But it doesn't make it right, and further arguing is clearly just not going to do any good. You're insisting on using imprecise terminology common to other languages in complicated ways together to describe very simple things. Python has objects, objects are given various names. It helps no one to try to artificially create an abstraction above that which the language provides as you are doing. I've heard that before, and have no idea why, nor any real interest in >> solving it: I don't want to read cpl via Usenet, and prefer to read it as a >> mailing list. Somewhere between Gmail->python.org->python.org < >> http://python.org>'s usenet server->the world, some people don't seem to >> get my posts. Yet it shows up on some news servers, not others. >> >> >> No idea. Nothing I know of can solve it. >> > > Not sure, but perhaps it's possible to mail directly to gmane? > I participate with the community via python-list; I take no responsibility for the deficiency of any particular usenet server which may or may not mirror python-list accurately. Usenet's a fuzzy thing like that, with all the servers cross-sharing and messages bouncing around. I have no need for its complexity and unbounded freedom. I'm subscribed to a mailing list, albeit a high-volume one. That its cross-mirrored with a usenet group is something I have no control over, and usenet is inherently beyond control. Its great that Gmane provides a means of making usenet discussion groups accessible as mailing lists, but I don't see any reason to bother. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ericthecyclist at gmail.com Tue Feb 9 10:27:39 2010 From: ericthecyclist at gmail.com (CyclingGuy) Date: Tue, 9 Feb 2010 07:27:39 -0800 (PST) Subject: PostgreSQL driver for Python applications that supports bytea correctly? Message-ID: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Can anyone recommend a PostgreSQL driver for Python that supports selecting and inserting bytea types? I'm not looking to write server functions in Python, just client applications. Thank you Eric. From mgedmin at gmail.com Tue Feb 9 10:32:54 2010 From: mgedmin at gmail.com (Marius Gedminas) Date: Tue, 9 Feb 2010 07:32:54 -0800 (PST) Subject: Python-URL! - weekly Python news and links (Feb 9) References: Message-ID: The last three URLs are malformed: On Feb 9, 5:03?pm, "Gabriel Genellina" wrote: > ? ? There is no module in the standard library to handle filesystem paths > ? ? in an OO way - but why? > ? ? ? ?http://groups.google.com/group/comp.lang.pythonf580fb3763208425ece/ > > ? ? A "History Channel" special: how the way a TAB key was interpreted > ? ? changed over time > ? ? ? ?http://groups.google.com/group/comp.lang.python82d9181fcd31ffea3f4/ > > ? ? After a false start, finally we get our first "Is it Call-By-Value or > ? ? Call-By-Reference?" thread of the year! > ? ? ? ?http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ Any chance of getting them fixed? Regards, -- Marius Gedminas From apt.shansen at gmail.com Tue Feb 9 10:34:57 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:34:57 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002081848j6d15cac4uf8d5d31a34ca227e@mail.gmail.com> Message-ID: <7a9c25c21002090734v324f8b5bic6d2bc675bce8cbe@mail.gmail.com> On Tue, Feb 9, 2010 at 4:40 AM, Steve Holden wrote: > Stephen Hansen wrote: > > This is getting out of hand. > > > > First, someone thought I was you. > > > > Now you think I'm D'Aprano. > > > > I'm just gonna go by Bob for now on. > > > > :) > > > Sorry about that, Bob. But you have to admit your pedantry was rather > D'Aprano-like (I have these feeling I just insulted you both with one > sentence). > I'm not sure how I feel about the word /pedantry/ to describe what I have to say (in fact, I sort of thought it might be better applied to the other side of the discussion), but I don't see anything terribly insulting with being confused with the other Ste[ph|v]en's floating around python-list, even allowing for blowhard tendencies we may or may not have. :) Even if I'm the only one who can spell his name right. :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Feb 9 10:37:42 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:37:42 -0800 Subject: Python-URL! - weekly Python news and links (Feb 9) In-Reply-To: References: Message-ID: <7a9c25c21002090737o13b1fd48p8b688d5640eefead@mail.gmail.com> On Tue, Feb 9, 2010 at 7:03 AM, Gabriel Genellina wrote: > After a false start, finally we get our first "Is it Call-By-Value or > Call-By-Reference?" thread of the year! > http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ LOL. Can we set up some sort of "argh" filter on python-list, analogous to a spam filter, which detects these threads and shunts them to python-list-ohnoyoudidnt at python.org? Because avoiding them is -hard-. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Tue Feb 9 10:37:50 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 9 Feb 2010 16:37:50 +0100 Subject: ANN: obfuscate In-Reply-To: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: > I am pleased to announce the first public release of obfuscate 0.2.2a. > > http://pypi.python.org/pypi/obfuscate/0.2.2a > > obfuscate is a pure-Python module providing classical encryption > algorithms suitable for obfuscating and unobfuscating text. > > obfuscate includes the following ciphers: > - Caesar, rot13, rot5, rot18, rot47 > - atbash > - Playfair, Playfair6 and Playfair16 > - Railfence (encryption only) > - Keyword > - Affine > - Vigenere > - frob (xor) > > and others. > > DISCLAIMER: obfuscate is not cryptographically strong, and should not be > used where high security is required. (The ciphers provided in obfuscate > may have been state of the art centuries ago, but should not be used > where strong encryption is required. > > obfuscate is released under the MIT licence. > > Requires Python 2.5 or 2.6. Great, these packages are badly needed! If the code base stabilizes in a production version after losing the alphas and betas they would be a great addition to the stdlib, I think. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From apt.shansen at gmail.com Tue Feb 9 10:47:35 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:47:35 -0800 Subject: To (monkey)patch or not to (monkey)patch, that is the question In-Reply-To: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: <7a9c25c21002090747w39f4ec30i910557c79a8dcb29@mail.gmail.com> On Tue, Feb 9, 2010 at 12:54 AM, George Sakkis wrote: > So I'm wondering if there is a consensus on when it's better to (hard) > patch, monkey patch or just try to work around a third party package > that doesn't do exactly what one would like. Does it have mainly to do > with the reason for the patch (e.g. fixing a bug, modifying behavior, > adding missing feature), the given package (size, complexity, > maturity, developer responsiveness), something else or there are no > general rules and one should decide on a case-by-case basis ? > IMHO, monkey-patching is one of those things that you shouldn't really mention in the public without looking both ways, leaning in, and lowering your voice. Its not that its -bad- exactly, and its really not terribly kinky or obscene, but its something that you still shouldn't exactly do in polite company, y'know? There's no guarantees it'll work forever, so its not the safest practice, but if you're willing to accept the burden (and ideally have a unit test proving that it still functions after an update to such a package), then... consenting adults! Go ahead. If you can get the upstream package to make such a thing not necessary, that's ideal-er, of course. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Tue Feb 9 10:48:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 16:48:39 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> Message-ID: <4B7183D7.2010805@sequans.com> Jordan Apgar wrote: > I found my car ;) > > here's the server: > > class commServer: > """Class to hold a tcp server and interact with with it > allows for a wrapper around socket class to keep code clean""" > > def __init__ (self, host, hostid, port, buff =1024): > self.host = host > self.hostid = hostid #id of the server > self.port = port > self.buffer = buff > self.socket = socket.socket(socket.AF_INET, > socket.SOCK_STREAM) > self.conn = None > self.addr = None > > def bindServ(self): > """Connect to the server specified by self.host, self.port""" > self.socket.bind((self.host, self.port)) > def closeConn(self): > """Disconnect from the server connected to""" > self.conn.close() > def listen(self): > self.socket.listen(1) > def accept(self): > self.conn, self.addr = self.socket.accept() > > #lets you send a string msg to the server > def sendMSG(self, msg): > self.conn.send(msg) > #lets you receive data from the server > def recvMSG(self): > msg = self.socket.recv(self.buffer) > if msg == "": #if the client disconnected let's not throw > return False > else: > return msg > > > class Negotiator: > """Negotiator for the server handles all communication with the > client to > verify the server and prepare the file the client wants for > download""" > def __init__(self, host, hostid, port, rsa_key): > self.server = commServer(host,hostid,port) > > def Negotiate(self): > self.server.bindServ() > self.server.listen() > self.server.accept() > > #Plan on being asked for server confirmation > clmsg = self.server.recvMSG() # it fails right here on the > server > > > calling the Server Negotiator as: > host = "127.0.0.1" > port = 8005 > HOSTID = a string > key = an RSA key > servernegotiator = Negotiator(host,HostID, port, key) > if servernegotiator.Negotiate() == False: > print "something went wrong" > print "Done" > > > > for the client it is: > class commClient: > """Class to hold a tcp client and interact with with it > allows for a wrapper around socket class to keep code clean""" > > def __init__ (self, host, hostid, port, buff =1024): > self.host = host > self.hostid = hostid #id of the server > self.port = port > self.buffer = buff > self.socket = socket.socket(socket.AF_INET, > socket.SOCK_STREAM) > > def connectServ(self): > """Connect to the server specified by self.host, self.port""" > self.socket.connect((self.host, self.port)) > def disconnServ(self): > """Disconnect from the server connected to""" > self.socket.close() > > #lets you send a string msg to the server > def sendMSG(self, msg): > self.socket.send(msg) > #lets you receive data from the server > def recvMSG(self): > msg = self.socket.recv(self.buffer) > if msg == "": #if the server disconnected let's not throw > something later > return False > else: > return msg > > > > class Negotiator: > """The Negotiator handles all communications and message handling > necessary for verifying the server, and that the file is available > to > download""" > def __init__(self, host, hostid, port, rsa_key): > """client should be a commClient object that has not been > connected > to the server.""" > self.client = commClient(host, hostid, port) > self.clientKey = rsa_key > self.serverKey = None > self.CScipher = None #AES cipher for client -> server > self.SCcipher = None #AES cipher for server -> client > self.CShalves = None #tuple for random halves by client > self.SChalves = None #tuple for random halves by server > self.file = None > > > def Negotiate(self, fname): > """Contact the server, verify the server, > negotiates for a file to be downloaded by the client. It > returns > the file name to be downloaded, and the cipher to decrypt > it.""" > > self.client.connectServ() > print "connected" > > #tell the server you want to connect > clmsg = message(CONN, (self.client.getHost(), > self.client.getHostID())) #message acts > as a wrapper around a message type and the data for the type > self.client.sendMSG(clmsg.getSendable()) # here is were it > fails > > the Negotiator is called as: > host = "127.0.0.1" > port = 8005 > HOSTID is the same string as before > key is an RSA key > clientnegotiator = Negotiator(host, HostID, port, key) > filename = clientnegotiator.Negotiate("hostid") > > the stack traces are: > Server side: > Traceback (most recent call last): > File "Server.py", line 17, in > if servernegotiator.Negotiate() == False: > File "/home/twistedphrame/Desktop/communication/ > ServerNegotiator.py", line 184, in Negotiate > clmsg = self.server.recvMSG() > File "/home/twistedphrame/Desktop/communication/ > ServerNegotiator.py", line 67, in recvMSG > msg = self.socket.recv(self.buffer) > socket.error: [Errno 107] Transport endpoint is not connected > > Client Side: > File "Client.py", line 17, in > filename = clientnegotiator.Negotiate("hostid") > File "/home/twistedphrame/Desktop/communication/ > ClientNegotiator.py", line 209, in Negotiate > srvmsg = self.client.recvMSG() > File "/home/twistedphrame/Desktop/communication/ > ClientNegotiator.py", line 55, in recvMSG > msg = self.socket.recv(self.buffer) > socket.error: [Errno 104] Connection reset by peer > > > http://docs.python.org/library/socketserver.html JM From jeanmichel at sequans.com Tue Feb 9 10:53:35 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 16:53:35 +0100 Subject: PostgreSQL driver for Python applications that supports bytea correctly? In-Reply-To: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> References: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Message-ID: <4B7184FF.7090405@sequans.com> CyclingGuy wrote: > Can anyone recommend a PostgreSQL driver for Python that supports > selecting and inserting bytea types? > I'm not looking to write server functions in Python, just client > applications. > > Thank you > Eric. > Did you try any ? I know about pgdb, and since it has a function called escape_bytea it may support this type... JM From steve at holdenweb.com Tue Feb 9 10:53:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 10:53:52 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Mon, Feb 8, 2010 at 10:35 PM, Alf P. Steinbach > wrote: > > Right. > > "pass by value" is a lower level notion. > > And as you show below, in the paragraph marked [1], it can be used > to describe call by sharing very succinctly and precisely, just as I > did... ;-) > > > No. There's nothing at all succinct or precise about either "value" or > "reference" when speaking of programming languages, and using both > together just compounds that. They are loaded words. The phrase "call my > value where value is an object reference" is not clear, not obvious, not > helpful. It requires far too much explanation of every single word > there, depending on the background of who you are speaking to, to > explain how it does not exactly use any of the words in a way which the > person may be expecting, and making sure they understand that it does > not imply anything that those words usually imply. > > I'm not even going to bother further-- I shouldn't have to begin with-- > your entire post is full of arguments with no more weight then, "I say > this means that, and its clearer" with absolutely no regard for the fact > that all of these words have weight and meaning to the world outside of > your head. > [several paragraphs-worth of bothering further] So you didn't believe me when I said > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Tue Feb 9 10:54:13 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:54:13 -0800 Subject: Programing family In-Reply-To: References: Message-ID: <7a9c25c21002090754r37a63ef2y2e02e47b4179bbeb@mail.gmail.com> On Mon, Feb 8, 2010 at 5:39 PM, AON LAZIO wrote: > I have thought funny things > If we think all languages are like a family > I could draft them like this (Python base) > > C is Python's Mom > I can see this. > C++ : Dad > Ick, no. C++ is the dirty Uncle who gets touchy with us in inappropriate ways. > Pascal/Assembly : Grandparents > o.O > C# : Uncle Java : Aunt If C# and Java are our parents siblings and we're older by quite a bit then them, then... that implies some sort of shady things in our family tree! Maybe Grandpappy married a bombshell just out of high school and managed to knock her up. Then again, we did take some stuff from both. So maybe C# and Java are our neighbors, and our sister had an affair with one of them and got knocked up, and so we got the "logging" package and decorators and. Er. I fail at this analogy. Ruby: Cousin > I can see this. > Perl : Girlfriend > You seriously need to duck and run for cover at this one. Someone on one of our sides is going to throw a rock at you now. :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Tue Feb 9 10:55:47 2010 From: mrkafk at gmail.com (mk) Date: Tue, 09 Feb 2010 16:55:47 +0100 Subject: timer for a function In-Reply-To: <7a9c25c21002081844h5a280e94k794ddc5d0df77610@mail.gmail.com> References: <7a9c25c21002081844h5a280e94k794ddc5d0df77610@mail.gmail.com> Message-ID: Stephen Hansen wrote: > Question: how can I do that? Use another threaded class? Is there > some other way? First of all, thanks for answer! > What OS? Does this have to be OS-independant? Err, sorry -- this is Linux/UNIX only. > Are you using more then > one transport/SSLClient in your process and you want to just kill one > (and any of its child threads), or are you doing one per process? I'm using multiple threads myself, one per IP basically, which in turn call paramiko calls, which itself is threaded. > If you want to terminate -all- threads your process is running in a > given timeframe, using a SIGALRM in the signal module will do it, I > believe-- provided you don't need to support windows. Thanks, that's still useful! Although... 1. if I don't install signal handler for SIGALRM I get this printed on the console at the end of execution: Alarm clock Although it does seem to close cleanly. Is there any way to suppress this message? 2. If I do install signal handler for SIGALRM, I'm back at square one: Exception in thread Thread-25 (most likely raised during interpreter shutdown): Traceback (most recent call last): File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap File "./cssh.py", line 1003, in run File "./cssh.py", line 739, in ssh_connect_for_scp File "build/bdist.linux-i686/egg/paramiko/transport.py", line 1006, in connect File "build/bdist.linux-i686/egg/paramiko/transport.py", line 1382, in _log exceptions.TypeError: 'NoneType' object is not callable Unhandled exception in thread started by This happens even though I surround "connect" (line 1006) with catching all Exceptions: try: self.trans.connect(hostkey=None, username=self.username, pkey = pkey) except Exception, e: self.conerror = str(e) >I had a contextlib > manager do that for awhile. If you only want to terminate one (and its > child-threads)... you're out of luck, I think. The only way to terminate > a thread in Python is with conditions/events/whatever and the thread > cooperating and exiting on its own. I will probably have to get the library author look at this. Regards, mk From apt.shansen at gmail.com Tue Feb 9 10:59:13 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 07:59:13 -0800 Subject: Socket Error: Permission Denied In-Reply-To: References: Message-ID: <7a9c25c21002090759s3c94f2a8wd3ccb18b8faa9012@mail.gmail.com> On Mon, Feb 8, 2010 at 7:38 PM, W. eWatson wrote: > I'm using McAffee. I see it was pythonw.exe blocked in red. There are > several choices: Allow Access, Allow Outboubnd only > Block (current), Remove Prgrm permission, Learn More. > > Outbound only seem reasonable, but why does the blocking keep returning > every many hours, or maybe when I reboot, which I've done several times > today? I can't help you with McAfee, contact their support forums. As for outbound vs anything else... pythonw.exe needs to accept connections at least on the local machine. No idea how to get McAfee to allow that. Outbound may not be sufficient, you may need just Allow. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From gnarlodious at gmail.com Tue Feb 9 11:07:42 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 08:07:42 -0800 (PST) Subject: Python 3: Plist as OrderedDict References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> Message-ID: <663dd630-f029-4b6f-909e-52ce79adbbd1@x1g2000prb.googlegroups.com> On Feb 9, 12:15?am, Raymond Hettinger wrote: > You may be able to monkey patch an OrderedDict into the PlistParser. > Here's an untested stab at it: > ? ? from collections import OrderedDict > ? ? import plistlib > ? ? plistlib._InteralDict = OrderedDict Genius! After fixing the misspelled InteralDict I got this: from collections import OrderedDict import plistlib plistlib._InternalDict = OrderedDict plistlib.readPlist('/path/to/some.plist') --> OrderedDict([('List', 'of'), ('tuples', 'in'), ('plist', 'order')]) So thank you for that [somewhat contorted] solution. To extract the list I am saying this: ordered=plistlib.readPlist(path) print(list(ordered)) # only a list of keys print(ordered[list(ordered)[0]]) However this seems too laborious. is there an easier way? -- Gnarlie From invalid at invalid.invalid Tue Feb 9 11:10:56 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 16:10:56 +0000 (UTC) Subject: How to measure elapsed time under Windows? Message-ID: What's the correct way to measure small periods of elapsed time. I've always used time.clock() in the past: start = time.clock() [stuff being timed] stop = time.clock() delta = stop-start However on multi-processor machines that doesn't work. Sometimes I get negative values for delta. According to google, this is due to a bug in Windows that causes the value of time.clock() to be different depending on which core in a multi-core CPU you happen to be on. [insert appropriate MS-bashing here] Is there another way to measure small periods of elapsed time (say in the 1-10ms range)? Is there a way to lock the python process to a single core so that time.clock() works right? -- Grant Edwards grante Yow! If I felt any more at SOPHISTICATED I would DIE visi.com of EMBARRASSMENT! From rodrick.brown at gmail.com Tue Feb 9 11:13:35 2010 From: rodrick.brown at gmail.com (rodrick brown) Date: Tue, 9 Feb 2010 11:13:35 -0500 Subject: Programing family In-Reply-To: References: Message-ID: <53AA95DE-1589-466E-BEE3-7B95728C766E@gmail.com> Don't forget his little brother Go! Sent from my iPhone 3GS. On Feb 8, 2010, at 8:39 PM, AON LAZIO wrote: > I have thought funny things > If we think all languages are like a family > I could draft them like this (Python base) > > C is Python's Mom > C++ : Dad > Pascal/Assembly : Grandparents > C# : Uncle > Java : Ant > Ruby: Cousin > Perl : Girlfriend > > > What u guys think? XD > -- > Passion is my style > -- > http://mail.python.org/mailman/listinfo/python-list From mail at timgolden.me.uk Tue Feb 9 11:21:17 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 09 Feb 2010 16:21:17 +0000 Subject: Python-URL! - weekly Python news and links (Feb 9) In-Reply-To: <7a9c25c21002090737o13b1fd48p8b688d5640eefead@mail.gmail.com> References: <7a9c25c21002090737o13b1fd48p8b688d5640eefead@mail.gmail.com> Message-ID: <4B718B7D.8050603@timgolden.me.uk> On 09/02/2010 15:37, Stephen Hansen wrote: > On Tue, Feb 9, 2010 at 7:03 AM, Gabriel Genellinawrote: > >> After a false start, finally we get our first "Is it Call-By-Value or >> Call-By-Reference?" thread of the year! >> http://groups.google.com/group/comp.lang.pythonfd36962c4970ac487ea/ > > > LOL. > > Can we set up some sort of "argh" filter on python-list, analogous to a spam > filter, which detects these threads and shunts them to > python-list-ohnoyoudidnt at python.org? > > Because avoiding them is -hard-. Oh no it isn't! (Sorry; couldn't resist) TJG From robert.kern at gmail.com Tue Feb 9 11:29:42 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 09 Feb 2010 10:29:42 -0600 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >> I am pleased to announce the first public release of obfuscate 0.2.2a. >> >> http://pypi.python.org/pypi/obfuscate/0.2.2a >> >> obfuscate is a pure-Python module providing classical encryption >> algorithms suitable for obfuscating and unobfuscating text. >> >> obfuscate includes the following ciphers: >> - Caesar, rot13, rot5, rot18, rot47 >> - atbash >> - Playfair, Playfair6 and Playfair16 >> - Railfence (encryption only) >> - Keyword >> - Affine >> - Vigenere >> - frob (xor) >> >> and others. >> >> DISCLAIMER: obfuscate is not cryptographically strong, and should not be >> used where high security is required. (The ciphers provided in obfuscate >> may have been state of the art centuries ago, but should not be used >> where strong encryption is required. >> >> obfuscate is released under the MIT licence. >> >> Requires Python 2.5 or 2.6. > > Great, these packages are badly needed! > > If the code base stabilizes in a production version after losing the > alphas and betas they would be a great addition to the stdlib, I > think. Why? -- 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 jpahonthe at gmail.com Tue Feb 9 11:33:32 2010 From: jpahonthe at gmail.com (r. clayton) Date: Tue, 9 Feb 2010 08:33:32 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> Message-ID: > http://docs.python.org/library/socketserver.html > > JM each time a handler is spawned is it client specific? in other words when two clients send something to the server do handlers spawn for each of them or does everything just go into a single handler? From twistedphrame at gmail.com Tue Feb 9 11:36:25 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 08:36:25 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> Message-ID: <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> > http://docs.python.org/library/socketserver.html > > JM each time a handler is spawned is it client specific? in other words when two clients send something to the server do handlers spawn for each of them or does everything just go into a single handler? From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 9 11:49:21 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 09 Feb 2010 17:49:21 +0100 Subject: Programing family In-Reply-To: References: Message-ID: <4b719209$0$10071$426a34cc@news.free.fr> On Feb 8, 2010, at 8:39 PM, AON LAZIO wrote: > >> I have thought funny things >> If we think all languages are like a family Then it would be a very incestuous family fore sure. >> I could draft them like this (Python base) >> >> C is Python's Mom >> C++ : Dad Not that much C++ in Python, IMHO. If that's for the OO part, then the closer to Python's object model I can think of is javascript. Historically, Python comes from ABC, which itself comes from SETL. >> Pascal/Assembly : Grandparents Assembly ? What about binary machine code then ?-) >> C# : Uncle >> Java : Ant Interesting typo here !-) Hmmm... Python predates both C# and Java. Ok, technically speaking nothing prevents an uncle or aunt from being younger than their nephews, and I even saw the case a couple time - but that's far from being the common case. >> Ruby: Cousin >> Perl : Girlfriend Then it's kind of a very passionate love-hate relationship - bordering on pathological FWIW !-) Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of course Simula and Smalltalk. From darcy at druid.net Tue Feb 9 11:51:15 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 9 Feb 2010 11:51:15 -0500 Subject: PostgreSQL driver for Python applications that supports bytea correctly? In-Reply-To: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> References: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Message-ID: <20100209115115.fd6bd546.darcy@druid.net> On Tue, 9 Feb 2010 07:27:39 -0800 (PST) CyclingGuy wrote: > Can anyone recommend a PostgreSQL driver for Python that supports > selecting and inserting bytea types? > I'm not looking to write server functions in Python, just client > applications. http://www.PyGreSQL.org/ -- 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 no.email at nospam.invalid Tue Feb 9 11:56:14 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 09 Feb 2010 08:56:14 -0800 Subject: Programing family References: <4b719209$0$10071$426a34cc@news.free.fr> Message-ID: <7xaavi5owh.fsf@ruckus.brouhaha.com> Bruno Desthuilliers writes: > Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of > course Simula and Smalltalk. http://i.imgur.com/1gF1j.jpg From apt.shansen at gmail.com Tue Feb 9 11:57:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 08:57:17 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002090727t23ccd46fy9289ed56d93ce929@mail.gmail.com> Message-ID: <7a9c25c21002090857r2ff4ee51k899c5451e552cf25@mail.gmail.com> On Tue, Feb 9, 2010 at 7:53 AM, Steve Holden wrote: > > [several paragraphs-worth of bothering further] > > So you didn't believe me when I said > > > Of course this won't make the slightest difference. "'When I use a > > word,' said Humpty ..." > It was early, I was barely awake. That paragraph was originally the last one. Apparently some extra bother had to work itself out. I'm pretty sure I got the last of it squeezed out. I swear I /wanted/ to believe you. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Tue Feb 9 12:06:42 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 09:06:42 -0800 Subject: Python 3: Plist as OrderedDict In-Reply-To: <663dd630-f029-4b6f-909e-52ce79adbbd1@x1g2000prb.googlegroups.com> References: <8042fe2c-c014-491f-984c-5a5f7d9644b9@x10g2000prk.googlegroups.com> <4576331d-fb60-499e-aff6-f61a4c0fc01e@l24g2000prh.googlegroups.com> <663dd630-f029-4b6f-909e-52ce79adbbd1@x1g2000prb.googlegroups.com> Message-ID: <7a9c25c21002090906ya5c10c3rb57c4eb19203f00@mail.gmail.com> On Tue, Feb 9, 2010 at 8:07 AM, Gnarlodious wrote: > To extract the list I am saying this: > > ordered=plistlib.readPlist(path) > print(list(ordered)) # only a list of keys > print(ordered[list(ordered)[0]]) > > However this seems too laborious. is there an easier way? > I'm not familiar with plistlib or what you're trying to do-- it'd help if you provided the output from those print's, as I don't have a plist on hand which I can use to test it out and see what you're seeing. But, is "ordered.keys()" or "ordered.items()" what you're trying to get? Or, ordered[ordered.keys()[0]] to get the first one? Or "for key in ordered: print(ordered[key])" which will get the keys in order and print the values according to that order? Basically, I'm not sure what you're actually trying to do. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From half.italian at gmail.com Tue Feb 9 12:09:50 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Tue, 9 Feb 2010 09:09:50 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: On Feb 9, 6:52?am, T wrote: > On Feb 8, 2:25?pm, David Bolen wrote: > > > > > T writes: > > > I have a script, which runs as a Windows service under the LocalSystem > > > account, that I wish to have execute some commands. ?Specifically, the > > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > > an admin account, all is well. ?However, when I'm running it via > > > service, no luck. ?I'm assuming this is to do with the fact that it's > > > trying to run under the LocalSystem account, which is failing. ?What > > > would be the best way around this? ?Thanks! > > > The LocalSystem account is not, if I recall correctly, permitted to > > access the network. > > > You'll have to install the service to run under some other account that > > has appropriate access to the network. > > > -- David > > The more testing I do, I think you may be right..I was able to get it > to work under a local admin account, and it worked under debug mode > (which would also have been running as this user). ?I'm a bit > surprised though - I was under the assumption that LocalSystem had > rights to access the network? You really need a way to see the error you are getting. If you can't get it to show you the error in the shell, set up some logging to a file, and find the error that way. I think the user can access the network just fine, but that maybe plink.exe is not in his path or some such thing. Find the error! From apt.shansen at gmail.com Tue Feb 9 12:14:26 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 09:14:26 -0800 Subject: How to measure elapsed time under Windows? In-Reply-To: References: Message-ID: <7a9c25c21002090914r68310597se5541213279252fd@mail.gmail.com> On Tue, Feb 9, 2010 at 8:10 AM, Grant Edwards wrote: > However on multi-processor machines that doesn't work. > Sometimes I get negative values for delta. According to > google, this is due to a bug in Windows that causes the value > of time.clock() to be different depending on which core in a > multi-core CPU you happen to be on. [insert appropriate > MS-bashing here] > > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > > Is there a way to lock the python process to a single core so > that time.clock() works right? The only time I ever had to do that, I just grabbed: http://svn.python.org/projects/python/trunk/Tools/pybench/systimes.py HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Tue Feb 9 12:25:48 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Feb 2010 12:25:48 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7tb5hlF3nmU1@mid.uni-berlin.de> Message-ID: On 2/9/2010 12:12 AM, Alf P. Steinbach wrote: > As far as the language spec is concerned the argument passing mechanism > seems to me to be identical to assignments, not just "very much like". Except for the cross-namespace nature of the assignment, yes. Glad you agree. > Your phrase "or objects derived therefrom" seems to imply that immutable > objects can be copied No. Given def f(*args, **kwds): print(args, kwds) the objects bound to args and kwds are a tuple and dict *derived* from (that collect together) the objects passed. Terry Jan Reedy From thomasharrisonnelson at gmail.com Tue Feb 9 12:39:27 2010 From: thomasharrisonnelson at gmail.com (Thomas Nelson) Date: Tue, 9 Feb 2010 09:39:27 -0800 (PST) Subject: mac install Message-ID: I downloaded the 3.1.1 dmg from http://www.python.org/download/releases/3.1.1/ but when I run it I get the error "The folowing install step failed: run postflight script for python documentation." The bugs list has this bug at http://bugs.python.org/issue6934 but it's described as fixed. Is it only fixed for the source version? Where should I go to install? Thanks, Tom From aahz at pythoncraft.com Tue Feb 9 12:40:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Feb 2010 09:40:03 -0800 Subject: pyclutter anyone? References: <4B6BD072.4080006@gmail.com> Message-ID: In article , donn wrote: > >No one uses pyClutter? Never heard of it before. >I have some code, it does not work, but maybe this will start to help >solve the problem: You need to provide some more detail than "does not work". Perhaps this will help: http://www.catb.org/~esr/faqs/smart-questions.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From aahz at pythoncraft.com Tue Feb 9 12:47:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 9 Feb 2010 09:47:39 -0800 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: In article , Robert Kern wrote: >On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>> >>> obfuscate is a pure-Python module providing classical encryption >>> algorithms suitable for obfuscating and unobfuscating text. >>> >>> DISCLAIMER: obfuscate is not cryptographically strong, and should not be >>> used where high security is required. (The ciphers provided in obfuscate >>> may have been state of the art centuries ago, but should not be used >>> where strong encryption is required. >> >> Great, these packages are badly needed! >> >> If the code base stabilizes in a production version after losing the >> alphas and betas they would be a great addition to the stdlib, I >> think. > >Why? You missed the white-on-white smiley, I think. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ import antigravity From jeanmichel at sequans.com Tue Feb 9 12:49:51 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 18:49:51 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> Message-ID: <4B71A03F.8070803@sequans.com> Jordan Apgar wrote: >> http://docs.python.org/library/socketserver.html >> >> JM >> > > each time a handler is spawned is it client specific? in other words > when two clients send something to the server do handlers spawn for > each of them or does everything just go into a single handler? > docstring of the example: """ The RequestHandler class for our server. It is instantiated once per connection to the server, and must override the handle() method to implement communication to the client. """ If you want data persistant over connections, store them in your handler class. class MyTCPHandler(SocketServer.BaseRequestHandler): cnxNumber = 0 def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() # just send back the same data, but upper-cased self.request.send(self.data.upper()) cnxNumber +=1 print "handling connection N?%s" % cnxNumber JM From ricaraoz at gmail.com Tue Feb 9 13:00:36 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Tue, 09 Feb 2010 15:00:36 -0300 Subject: Your beloved python features In-Reply-To: References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <4B71A2C4.1060507@gmail.com> Bruce C. Baker wrote: > "Terry Reedy" wrote in message > news:mailman.1929.1265328905.28905.python-list at python.org... > >> Iterators, and in particular, generators. >> A killer feature. >> >> Terry Jan Reedy >> >> > > Neither unique to Python. > > And then're the other killer "features" superfluous ":"s and rigid > formatting! > Hmmmm.... Let's see..... nope, I could not find the "unique" word neither in the subject or in the cited text. I've had a strange feeling last weeks. Two possible explanations come to mind : a) The list is under a concerted troll attack. b) Idiocy is contagious. I wonder which... P.S. : will the indentation of the choices be noticed? Shouldn't I put them within braces? -------------- next part -------------- An HTML attachment was scrubbed... URL: From salman.haq at gmail.com Tue Feb 9 13:02:45 2010 From: salman.haq at gmail.com (slmnhq) Date: Tue, 9 Feb 2010 10:02:45 -0800 (PST) Subject: Incorrect 'Host' header when using urllib2 to access a server by its IPv6 link-local address Message-ID: <6f17b819-0420-41d2-8875-f087d8c392d8@c28g2000vbc.googlegroups.com> I have a snippet of Python code that makes an HTTP GET request to an Apache web server (v 2.2.3) using urllib2. The server responds with an HTTP 400 error presumably because of a malformed 'Host' header. The snippet is quite simple: it creates a url based on IPv6 string literal syntax, then creates a Request object and calls urlopen. def via_urllib2 (addr="fe80::207:b8ff:fedc:636b", scope_id="eth4"): host = "[%s%%%s]:80" % (addr, scope_id) # "[fe80::207:b8ff:fedc: 636b%eth4]" url = "http://"+host+"/system/status/" req = urllib2.Request(url) f = urllib2.urlopen(req) print f.read() The urlopen() throws: HTTPError: HTTP Error 400: Bad Request The Apache error_log reports "Client sent malformed Host header". Googling for "apache Client sent malformed Host header ipv6" I came across the following bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=35122 The problem is that Apache does not handle the scope id in the host header field very well and reports a 400 error. So I tried to override that field by creating my own header in the above snippet: ... req.add_header('Host', "["+urllib.quote(addr)+"]") ... Now the header is simply 'Host: [fe80::207:b8ff:fedc:636b]" (notice the lack of "%eth4"). However, this still results in the same error. I know this is not a problem with urllib2 per say, but I'm posting here in the hope that some Python coder may be knowledgeable enough about HTTP and IPv6 that they might be able to provide an answer. Thank you, Salman From python at rcn.com Tue Feb 9 13:03:25 2010 From: python at rcn.com (Raymond Hettinger) Date: Tue, 9 Feb 2010 10:03:25 -0800 (PST) Subject: To (monkey)patch or not to (monkey)patch, that is the question References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: <6f5a299b-66a9-43ae-acf7-6d6450f7f240@b1g2000prc.googlegroups.com> On Feb 9, 12:54?am, George Sakkis wrote: > So I'm wondering if there is a consensus on when it's better to (hard) > patch, monkey patch or just try to work around a third party package > that doesn't do exactly what one would like. Does it have mainly to do > with the reason for the patch (e.g. fixing a bug, modifying behavior, > adding missing feature), the given package (size, complexity, > maturity, developer responsiveness), something else or there are no > general rules and one should decide on a case-by-case basis ? I agree that practically beats purity here. Python is a consenting adults language that makes monkey patching possible. It provides a direct way to compensate for someone failing to put hooks in their API. The risk of monkey patching is that if other modules use the patched module, they have no way of knowing that the behavior is changed. IOW, monkey patching is a fragile technique for a large project. Raymond From twistedphrame at gmail.com Tue Feb 9 13:03:45 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 10:03:45 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> Message-ID: <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> thanks JM, at this point i switched over to this scheme and now I'm getting an error durring instantiation of the server: Server.py: from Crypto.PublicKey import RSA from ServerNegotiator import ServerNegotiator from sharedComs import * f = open("hostid") tup = stringToTuple(f.readline()[0:-1]) HostID = f.readline()[0:-1] f.close() key = RSA.construct((long(tup[0]),long(tup[1]), long(tup[2]), long(tup[3]), long(tup[4]),long(tup[5]))) host = "localhost" port = 8005 servernegotiator = ServerNegotiator(host,HostID, port, key) servernegotiator.start() ServerNegotiatior.py lines 185 - end class ServerNegotiator: def __init__(self, host, port, hostid, rsa_key, buf = 512): negotiator = Negotiator(host, hostid, rsa_key,buf) self.server = SocketServer.TCPServer((host, port), negotiator) def start(self): self.server.serve_forever() Traceback (most recent call last): File "Server.py", line 16, in servernegotiator = ServerNegotiator(host,HostID, port, key) File "/home/twistedphrame/Desktop/communication/ ServerNegotiator.py", line 188, in __init__ self.server = SocketServer.TCPServer((host, port), negotiator) File "/usr/lib/python2.6/SocketServer.py", line 400, in __init__ self.server_bind() File "/usr/lib/python2.6/SocketServer.py", line 411, in server_bind self.socket.bind(self.server_address) File "", line 1, in bind TypeError: an integer is required From twistedphrame at gmail.com Tue Feb 9 13:09:53 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 10:09:53 -0800 (PST) Subject: Pycrypto RSA Issue Message-ID: <36189d1d-b33f-49bc-9857-74611e665aed@j6g2000vbd.googlegroups.com> I am trying to encrypt public data along with another tuple and then decrypt it after sending. RSA is needed for negotiation of keys for AES. But I just get garbage after I decrypt it. This is what I'm attempting to do: from Crypto.PublicKey import RSA from Crypto import Random gkey = RSA.generate(384, Random.new().read) string = str((gkey.publickey().__getstate__(), (333,444))) print string print data = gkey.encrypt(string,"") print "data:",data print print "decrypt" print "decrypt,", gkey.decrypt(data) print "done" All I get are junk values when printing the decrypted value. From olivier.darge at gmail.com Tue Feb 9 13:11:17 2010 From: olivier.darge at gmail.com (OdarR) Date: Tue, 9 Feb 2010 10:11:17 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <72bd2afa-2a58-489d-819a-966a92096d1d@y33g2000yqb.googlegroups.com> On 9 f?v, 11:01, Stefan Behnel wrote: > Klaus Neuner, 09.02.2010 10:04: > > > my program is supposed to parse files that I have created myself and that > > are on my laptop. It is not supposed to interact with anybody else > > than me. > > Famous last words. > > Stefan I knew it. Olivier From jeanmichel at sequans.com Tue Feb 9 13:23:21 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 19:23:21 +0100 Subject: How to measure elapsed time under Windows? In-Reply-To: References: Message-ID: <4B71A819.8050509@sequans.com> Grant Edwards wrote: > What's the correct way to measure small periods of elapsed > time. I've always used time.clock() in the past: > > start = time.clock() > [stuff being timed] > stop = time.clock() > > delta = stop-start > > > However on multi-processor machines that doesn't work. > Sometimes I get negative values for delta. According to > google, this is due to a bug in Windows that causes the value > of time.clock() to be different depending on which core in a > multi-core CPU you happen to be on. [insert appropriate > MS-bashing here] > > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > > Is there a way to lock the python process to a single core so > that time.clock() works right? > > Did you try with the datetime module ? import datetime t0 = datetime.datetime.now() t1 = t0 - datetime.datetime.now() t1.microseconds Out[4]: 644114 JM From pheensoowt at farifluset.mailexpire.com Tue Feb 9 13:27:36 2010 From: pheensoowt at farifluset.mailexpire.com (Legrandin) Date: 09 Feb 2010 18:27:36 GMT Subject: Pycrypto RSA Issue References: <36189d1d-b33f-49bc-9857-74611e665aed@j6g2000vbd.googlegroups.com> Message-ID: <4b71a918$0$14115$703f8584@textnews.kpn.nl> > gkey = RSA.generate(384, Random.new().read) > string = str((gkey.publickey().__getstate__(),(333,444))) You are encrypting with RSA a piece of data which is way larger than the key size (48 bytes). From george.trojan at noaa.gov Tue Feb 9 13:41:45 2010 From: george.trojan at noaa.gov (George Trojan) Date: Tue, 09 Feb 2010 18:41:45 +0000 Subject: errno 107 socket.recv issue In-Reply-To: <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: Argument mismatch? Jordan Apgar wrote: > > servernegotiator = ServerNegotiator(host,HostID, port, key) > > class ServerNegotiator: > def __init__(self, host, port, hostid, rsa_key, buf = 512): > From Martin.Drautzburg at web.de Tue Feb 9 13:47:43 2010 From: Martin.Drautzburg at web.de (Martin Drautzburg) Date: Tue, 09 Feb 2010 19:47:43 +0100 Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> Message-ID: <8281270.AG5xCW3FSB@beaureve.gmx.net> Carl Banks wrote: > You can have __add__ return a closure for the first addition, then > perform the operation on the second one. Example (untested): > > class Closure(object): > def __init__(self,t1,t2): > self.t1 = t1 > self.t2 = t2 > def __add__(self,t3): > # whole operation peformed here > return self.t1 + self.t2 + t3 > > class MySpecialInt(int): > def __add__(self,other): > return Closure(self,other) > > > I wouldn't recommend it. Just use a function call with three > arguments. That's way cool. Of course! - CURRYING!! If you can return closures you can do everything with just single-parameter functions. BTW I am not really trying to add three objects, I wanted a third object which controls the way the addition is done. Sort of like "/" and "//" which are two different ways of doing division. Anyways: thanks a lot. From gnarlodious at gmail.com Tue Feb 9 13:51:09 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 10:51:09 -0800 (PST) Subject: mac install References: Message-ID: <618b5d95-252c-425c-bd18-b38e3bf5e7fb@s36g2000prh.googlegroups.com> Hello. The answer is, I don't know. But I originally replaced my existing Python with 3.1.1. I then had to backtrack because some stuff broke. Nothing in the OS, but adapting every Python script on my HD was not what I wanted to do. So my Py3 executable is at: /Library/Frameworks/Python.framework/Versions/3.1/bin/python3.1 then symlink to that in folder: /usr/local/bin using command: sudo ln -s /Library/Frameworks/Python.framework/Versions/3.1/bin/ python3.1 /usr/local/bin/python3.1 so that saying: ls /usr/local/bin shows the link to the Py3 folder as: python3.1 -> /Library/Frameworks/Python.framework/Versions/3.1/bin/ python3.1 Now your existing scripts still work on Py 2.6. New scripts invoke Py3 like this: #!/usr/local/bin/python3.1 For Terminal sessions, an alias in your bash_profile puts you in Py3 by default without nasty surprises: alias python=/usr/local/bin/python3.1 You can also create a file at: /Library/Python/3.1/site-packages/sitecustomize.py with a configuration that runs at loadtime, although some things seem to fail. But all in all this system has worked well for me (including CGI) and should be easy to go mainstream once Apple goes to Py3. -- Gnarlie From jeanmichel at sequans.com Tue Feb 9 13:51:31 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 09 Feb 2010 19:51:31 +0100 Subject: errno 107 socket.recv issue In-Reply-To: <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: <4B71AEB3.3030908@sequans.com> Jordan Apgar wrote: > thanks JM, > > at this point i switched over to this scheme and now I'm getting an > error durring instantiation of the server: > Server.py: > from Crypto.PublicKey import RSA > from ServerNegotiator import ServerNegotiator > from sharedComs import * > > f = open("hostid") > tup = stringToTuple(f.readline()[0:-1]) > HostID = f.readline()[0:-1] > f.close() > > key = RSA.construct((long(tup[0]),long(tup[1]), long(tup[2]), > long(tup[3]), > long(tup[4]),long(tup[5]))) > host = "localhost" > port = 8005 > > servernegotiator = ServerNegotiator(host,HostID, port, key) > servernegotiator.start() > > > ServerNegotiatior.py lines 185 - end > class ServerNegotiator: > def __init__(self, host, port, hostid, rsa_key, buf = 512): > negotiator = Negotiator(host, hostid, rsa_key,buf) > self.server = SocketServer.TCPServer((host, port), negotiator) > > def start(self): > self.server.serve_forever() > > > > > > Traceback (most recent call last): > File "Server.py", line 16, in > servernegotiator = ServerNegotiator(host,HostID, port, key) > File "/home/twistedphrame/Desktop/communication/ > ServerNegotiator.py", line 188, in __init__ > self.server = SocketServer.TCPServer((host, port), negotiator) > File "/usr/lib/python2.6/SocketServer.py", line 400, in __init__ > self.server_bind() > File "/usr/lib/python2.6/SocketServer.py", line 411, in server_bind > self.socket.bind(self.server_address) > File "", line 1, in bind > TypeError: an integer is required > > servernegotiator = ServerNegotiator(host,HostID, port, key) class ServerNegotiator: def __init__(self, host, port, hostid, rsa_key, buf = 512): you swapped port & hostID in your call JM From gnarlodious at gmail.com Tue Feb 9 13:58:19 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Tue, 9 Feb 2010 10:58:19 -0800 (PST) Subject: Programing family References: <4b719209$0$10071$426a34cc@news.free.fr> <7xaavi5owh.fsf@ruckus.brouhaha.com> Message-ID: On Feb 9, 9:56?am, Paul Rubin wrote: > http://i.imgur.com/1gF1j.jpg Very funny, except where is Python and Forth? -- Gnarlie From invalid at invalid.invalid Tue Feb 9 14:04:01 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 19:04:01 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Jean-Michel Pichavant wrote: > Grant Edwards wrote: >> What's the correct way to measure small periods of elapsed >> time. I've always used time.clock() in the past: >> >> start = time.clock() >> [stuff being timed] >> stop = time.clock() >> >> delta = stop-start >> >> However on multi-processor machines that doesn't work. >> Sometimes I get negative values for delta. According to >> google, this is due to a bug in Windows that causes the value >> of time.clock() to be different depending on which core in a >> multi-core CPU you happen to be on. [insert appropriate >> MS-bashing here] >> >> Is there another way to measure small periods of elapsed time >> (say in the 1-10ms range)? >> >> Is there a way to lock the python process to a single core so >> that time.clock() works right? >> >> > > Did you try with the datetime module ? No. What mechanism does it use to get the current date/time? > import datetime > t0 = datetime.datetime.now() > t1 = t0 - datetime.datetime.now() > t1.microseconds > Out[4]: 644114 That looks very broken to me. I need to measure stuff in the 1-20ms range, and the smallest value you can measure using the method above appears to be 640ms. Thats almost 2/3 of a second. -- Grant Edwards grante Yow! If our behavior is at strict, we do not need fun! visi.com From twistedphrame at gmail.com Tue Feb 9 14:13:46 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 11:13:46 -0800 (PST) Subject: errno 107 socket.recv issue References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: On Feb 9, 1:51?pm, Jean-Michel Pichavant wrote: > Jordan Apgar wrote: > > thanks JM, > > > at this point i switched over to this scheme and now I'm getting an > > error durring instantiation of the server: > > Server.py: > > from Crypto.PublicKey import RSA > > from ServerNegotiator import ServerNegotiator > > from sharedComs import * > > > f = open("hostid") > > tup = stringToTuple(f.readline()[0:-1]) > > HostID = f.readline()[0:-1] > > f.close() > > > key = RSA.construct((long(tup[0]),long(tup[1]), long(tup[2]), > > long(tup[3]), > > ? ? ? ? ? ? ? ? ? ? ?long(tup[4]),long(tup[5]))) > > host = "localhost" > > port = 8005 > > > servernegotiator = ServerNegotiator(host,HostID, port, key) > > servernegotiator.start() > > > ServerNegotiatior.py lines 185 - end > > class ServerNegotiator: > > ? ? def __init__(self, host, port, hostid, rsa_key, buf = 512): > > ? ? ? ? negotiator = Negotiator(host, hostid, rsa_key,buf) > > ? ? ? ? self.server = SocketServer.TCPServer((host, port), negotiator) > > > ? ? def start(self): > > ? ? ? ? self.server.serve_forever() > > > Traceback (most recent call last): > > ? File "Server.py", line 16, in > > ? ? servernegotiator = ServerNegotiator(host,HostID, port, key) > > ? File "/home/twistedphrame/Desktop/communication/ > > ServerNegotiator.py", line 188, in __init__ > > ? ? self.server = SocketServer.TCPServer((host, port), negotiator) > > ? File "/usr/lib/python2.6/SocketServer.py", line 400, in __init__ > > ? ? self.server_bind() > > ? File "/usr/lib/python2.6/SocketServer.py", line 411, in server_bind > > ? ? self.socket.bind(self.server_address) > > ? File "", line 1, in bind > > TypeError: an integer is required > > servernegotiator = ServerNegotiator(host,HostID, port, key) > class ServerNegotiator: > ? ? def __init__(self, host, port, hostid, rsa_key, buf = 512): > > you swapped port & hostID in your call > > JM tThanks guys it's working now... feel a little stupid though. From twistedphrame at gmail.com Tue Feb 9 14:14:27 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Tue, 9 Feb 2010 11:14:27 -0800 (PST) Subject: Pycrypto RSA Issue References: <36189d1d-b33f-49bc-9857-74611e665aed@j6g2000vbd.googlegroups.com> <4b71a918$0$14115$703f8584@textnews.kpn.nl> Message-ID: <6a1bbf69-3cfc-4d2b-b329-939ca6d2d553@x9g2000vbo.googlegroups.com> On Feb 9, 1:27?pm, Legrandin wrote: > > gkey = RSA.generate(384, Random.new().read) > > string = str((gkey.publickey().__getstate__(),(333,444))) > > You are encrypting with RSA a piece of data which is way > larger than the key size (48 bytes). ah thanks Legrandin From db3l.net at gmail.com Tue Feb 9 14:18:50 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 09 Feb 2010 14:18:50 -0500 Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: T writes: > The more testing I do, I think you may be right..I was able to get it > to work under a local admin account, and it worked under debug mode > (which would also have been running as this user). I'm a bit > surprised though - I was under the assumption that LocalSystem had > rights to access the network? Not from my past experience - the system account (LocalSystem for services) can be surprising, in that it's pretty much unlimited access to all local resources, but severely limited in a handful of cases, one of which is any attempt to access the network. I can't recall for sure if it's an absolute block, or if in some cases you can configure around it (e.g., it might use a null session for remote shares which can be enabled through the registry on the target machine). I've basically stuck "LocalSystem = no network" in my head from past experience. So you can either install your service to run under your existing account, or create an account specifically for running your service, granting that account just the rights it needs. -- David From sjdevnull at yahoo.com Tue Feb 9 14:59:18 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Tue, 9 Feb 2010 11:59:18 -0800 (PST) Subject: To (monkey)patch or not to (monkey)patch, that is the question References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: On Feb 9, 3:54?am, George Sakkis wrote: > I was talking to a colleague about one rather unexpected/undesired > (though not buggy) behavior of some package we use. Although there is > an easy fix (or at least workaround) on our end without any apparent > side effect, he strongly suggested extending the relevant code by hard > patching it and posting the patch upstream, hopefully to be accepted > at some point in the future. In fact we maintain patches against > specific versions of several packages that are applied automatically > on each new build. The main argument is that this is the right thing > to do, as opposed to an "ugly" workaround or a fragile monkey patch. > On the other hand, I favor practicality over purity and my general > rule of thumb is that "no patch" > "monkey patch" > "hard patch", at > least for anything less than a (critical) bug fix. I'd monkey patch for the meantime, but send a hard patch in the hopes of shifting the maintenance burden to someone else. (Plus maybe help out the upstream project and other people, I guess) From alfps at start.no Tue Feb 9 15:02:12 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 21:02:12 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Duncan Booth: > "Alf P. Steinbach" wrote: > >> A copyable reference is a pointer. That is, a "pointer", in e.g. the >> Java sense, >> and in the general language independent sense, means a copyable >> reference -- as illustrated e.g. in the Stanford computer science >> 101 course page I >> referred you to earlier, with C versus Java pointers illustrated in >> the concrete. > > The fact that C style pointers are used internally is an detail of the > CPython implementation. Your statement seems pretty irrelevant to anything. It's almost hilarious, quoting a single paragraph about how irrelevant the C pointer is, and responding with something like that. Do you understand that you're restating (in the form of exemplifying) what you're quoting? > In CPython objects once created remain in the same memory location (and > their id is their address). Compare that to IronPython where the objects > themselves can move around in memory so they have no fixed address. Try > comparing the IronPython implementation to C pointers and you'll cause a > lot of confusion. e.g. someone might think the id() value is in some way > related to an address. Did you /read/ what you quoted? > Ruby implements integers without using any pointers at all: there's nothing > in the Python specification which prevents a Python implementation doing > the same for small integers, in fact I believe it has been tried but wasn't > found to improve performance. All theree of your points about Python are wrong; I don't know about the Ruby point. First, the current Python language specification formally prevents the optimization you mention, because there's no support for binding to do anything but direct binding leaving object identities unchanged. But in practice that's no big deal though: I can't imagine any code relying on identities of completely immutable objects. Second, even the variant that was tried improved performance. But it would reportedly have wreaked havoc with imperfect C code. Third, the optimization doesn't do away with pointers. If it did then it would transform the language completely. The user's view is still one where names denote pointers. > The terminology of 'objects', 'names', 'references' describes an abstract > machine. The Python runtime can implement it in any way it chooses so long > as those semantics are preserved. One implementation involves 'pointers', It seems that you're thinking of C pointers. That's pretty dumb since (1) it doesn't make sense, and (2) it has been mentioned in almost every article in this thread, including my first, and including the single paragraph that *you quoted above*, which was only about that, that we're not talking about C pointers here. Python names denote pointers by definition (of pointer). > but that word implies other baggage which is not a required part of the > model. The word itself doesn't imply other baggage, no. It might help to *read* what you're quoting, try to follow references, so on. Cheers & hth., - Alf From wolftracks at invalid.com Tue Feb 9 15:02:50 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 09 Feb 2010 12:02:50 -0800 Subject: Tangling with mathplotlib(MPL) on XP and Win7 -- show() stopper In-Reply-To: References: Message-ID: Solved. I need to get into the interactive mode. Never heard of it until this morning. From alfps at start.no Tue Feb 9 15:04:08 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 21:04:08 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Stephen Hansen: > [...] >>> I've heard that before, and have no idea why, nor any real interest in >>> solving it: I don't want to read cpl via Usenet, and prefer to read it >>> as a mailing list. Somewhere between Gmail->python.org->python.org >>> 's usenet server->the world, some people don't seem >>> to get my posts. Yet it shows up on some news servers, not others. >>> >>> No idea. Nothing I know of can solve it. >> Not sure, but perhaps it's possible to mail directly to gmane? >> > Is there *any* problem you don't have a fatuous answer for? I thought the answer could help. You thought you cold do a bit of ad hominem attack. That's the difference between us. Cheers, - Alf From steve at holdenweb.com Tue Feb 9 15:39:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 15:39:05 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Stephen Hansen: >> [...] >>>> I've heard that before, and have no idea why, nor any real interest in >>>> solving it: I don't want to read cpl via Usenet, and prefer to read it >>>> as a mailing list. Somewhere between Gmail->python.org->python.org >>>> 's usenet server->the world, some people don't seem >>>> to get my posts. Yet it shows up on some news servers, not others. >>>> >>>> No idea. Nothing I know of can solve it. >>> Not sure, but perhaps it's possible to mail directly to gmane? >>> >> Is there *any* problem you don't have a fatuous answer for? > > I thought the answer could help. > > You thought you cold do a bit of ad hominem attack. > > That's the difference between us. > Well, the way I see it, you assumed you knew better than Stephen, and insisted on proposing a solution to a problem that he clearly stated he had no interest in. I'm not quite sure, given that, what the point of the advice was. However, my question was genuine, based on your observed behavior. I agree I might have phrased it more politely, but I do find your self-assurance somewhat irritating. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Tue Feb 9 15:39:44 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 15:39:44 -0500 Subject: errno 107 socket.recv issue In-Reply-To: References: <894c03c7-a4e6-4baf-a0c9-dc243977264a@h12g2000vbd.googlegroups.com> <848c2009-f4bd-435c-afdb-d0dfeef47b0f@b35g2000vbc.googlegroups.com> <6a64449e-ce78-43e7-a5bd-6a299fcff4e6@w12g2000vbj.googlegroups.com> <9943e9c3-cb13-4fea-af00-9e6b26851b37@f8g2000vba.googlegroups.com> Message-ID: Jordan Apgar wrote: > On Feb 9, 1:51 pm, Jean-Michel Pichavant [...] >> you swapped port & hostID in your call >> >> JM > > tThanks guys it's working now... feel a little stupid though. Cool! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From quindennis at grandecom.net Tue Feb 9 16:00:47 2010 From: quindennis at grandecom.net (Quin) Date: Tue, 9 Feb 2010 15:00:47 -0600 Subject: New to Python Message-ID: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' this generates output: not found processing so, it doesn't find the substring, but goes into processing code anyway. This is using IronPython From alfps at start.no Tue Feb 9 16:08:27 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 09 Feb 2010 22:08:27 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >>>> * Stephen Hansen: >>> [...] >>>>> I've heard that before, and have no idea why, nor any real interest in >>>>> solving it: I don't want to read cpl via Usenet, and prefer to read it >>>>> as a mailing list. Somewhere between Gmail->python.org->python.org >>>>> 's usenet server->the world, some people don't seem >>>>> to get my posts. Yet it shows up on some news servers, not others. >>>>> >>>>> No idea. Nothing I know of can solve it. >>>> Not sure, but perhaps it's possible to mail directly to gmane? >>>> >>> Is there *any* problem you don't have a fatuous answer for? >> I thought the answer could help. >> >> You thought you cold do a bit of ad hominem attack. >> >> That's the difference between us. >> > Well, the way I see it, you assumed you knew better than Stephen, and > insisted on proposing a solution to a problem that he clearly stated he > had no interest in. You're going into motivations, that it seems to me that you're projecting, saying that any helpful suggestion mean that one thinks one knows better and implies a desire to demonstrate imagined superiority. You're trying to portray a helping hand as a negative personal characteristic of the helper. "the only reason that guy tries to help you is because he wishes to show how superior he (thinks he) is". That's your style in a fair number of postings, and now here: * ad hominem attack, * projection (at least the way I read it), and * inject - noise - about - something - completely - irrelevant Note that readers can easily guess about motivations for the last. > I'm not quite sure, given that, what the point of the advice was. There are many people who read just the Usenet group, e.g. via Google groups. When you say you don't understand the point of the advice, you're saying that * those people don't matter, and that * it doesn't matter whether they can read Stephen Hansen's articles. That's * slighting Stephen Hansen, and * showing off an extreme ego-centric view of the world, sorry. > However, my question was genuine, based on your observed behavior. I > agree I might have phrased it more politely, but I do find your > self-assurance somewhat irritating. Thanks. :-) Cheers & hth., - Alf From gagsl-py2 at yahoo.com.ar Tue Feb 9 16:18:44 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 18:18:44 -0300 Subject: Python-URL! - weekly Python news and links (Feb 9) References: Message-ID: En Tue, 09 Feb 2010 12:32:54 -0300, Marius Gedminas escribi?: > The last three URLs are malformed: Sorry... It happens even in the best of families :) These are the right ones: There is no module in the standard library to handle filesystem paths in an OO way - but why? http://groups.google.com/group/comp.lang.python/t/f580fb3763208425/ A "History Channel" special: how the way a TAB key was interpreted changed over time http://groups.google.com/group/comp.lang.python/t/82d9181fcd31ffe4/ After a false start, finally we get our first "Is it Call-By-Value or Call-By-Reference?" thread of the year! http://groups.google.com/group/comp.lang.python/t/fd36962c4970ac48/ -- Gabriel Genellina From invalid at invalid.invalid Tue Feb 9 16:19:05 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 21:19:05 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Grant Edwards wrote: > On 2010-02-09, Jean-Michel Pichavant wrote: >> Did you try with the datetime module ? > > No. What mechanism does it use to get the current date/time? > >> import datetime >> t0 = datetime.datetime.now() >> t1 = t0 - datetime.datetime.now() >> t1.microseconds >> Out[4]: 644114 > > That looks very broken to me. I need to measure stuff in the > 1-20ms range, and the smallest value you can measure using the > method above appears to be 640ms. Thats almost 2/3 of a second. Duh. It just occurred to me that was done interactively. I'll give the datetime module a try once I reboot my test machine back into Windows. -- Grant Edwards grante Yow! Is this sexual at intercourse yet?? Is it, visi.com huh, is it?? From db3l.net at gmail.com Tue Feb 9 16:25:24 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 09 Feb 2010 16:25:24 -0500 Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: David Bolen writes: > Not from my past experience - the system account (LocalSystem for > services) can be surprising, in that it's pretty much unlimited access > to all local resources, but severely limited in a handful of cases, > one of which is any attempt to access the network. I can't recall for > sure if it's an absolute block, or if in some cases you can configure > around it (e.g., it might use a null session for remote shares which > can be enabled through the registry on the target machine). I've > basically stuck "LocalSystem = no network" in my head from past > experience. Given it's been a few years, I decided to try some tests, and the above is too simplistic. The LocalSystem account runs without any local Windows credentials (e.g., not like a logged in user), which has several consequences. One is that you can't access any network resources that require such credentials (like shares). However, there's no sort of firewall filtering or anything, so plain old TCP/IP connections are fine. Unless, of course, the client being used also has other needs for local Windows credentials, independent or as a pre-requisite to the network operations. So backing up a bit, the TCP/IP connection that plink is making is not inherently disabled by running under LocalSystem, but it's certainly possible that plink is trying to identify the user under which it is operating to perhaps identify ssh keys or other local resources it needs to operate. You might be able to cover this with command line options (e.g., plink supports "-i" to specify a key file to use), but you'll also need to ensure that the file you are referencing is readable by the LocalSystem account. One of the other responders had a very good point about locating plink in the first place too. Services run beneath an environment that is inherited from the service control manager process, and won't include various settings that are applied to your user when logged in, especially things like local path changes, and working directories. Should you change the system path (via the environment settings), you'll need to reboot for the service control manager to notice - I don't think you can restart it without a reboot. So it's generally safer to be very clear, and absolute when possible, in a service for paths to external resources. The prior advice of running the service as an identified user (e.g., with local credentials) is still good as it does remove most of these issues since if you can run the script manually under that user you know it'll work under service. But it's not a hard requirement. If your script is dying such that a top level exception is being raised you should be able to find it in the application event log. So that might give further information on what about the different environment is problematic. You can also use the win32traceutil module to help with grabbing debug output on the fly. Import the module in your service, which will implicitly redirect stdout/stderr to a trace buffer. Run the same win32traceutil module from the command line in another window. Then start the service. Any stdout/stderr will be reflected in the other window. Can't catch everything (suppressed exceptions, or I/O that doesn't flow through the script's stdout/stderr), but again might help point in the right direction. -- David From jgardner at jonathangardner.net Tue Feb 9 16:41:34 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 9 Feb 2010 13:41:34 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: On Feb 9, 1:51?am, waku wrote: > 'stupid', 'wrong', 'deficient', 'terrible', ... ?you're using strong > words instead of concrete arguments, it might intimidate your > opponents, but is hardly helpful in a fair discussion. > In today's day and age, I don't know how a text editor which cannot do simple indentation can be considered anything but "stupid", "wrong", "deficient", and "terrible". There is simply no excuse for this kind of behavior on the part of the text editor. I mean, how long has vi had the auto indent feature? How many decades has emacs supported the same? This isn't new technology, or difficult technology to implement. It's not even non-standard anymore. Heck, far more advanced features, such as syntax highlighting, are standard in all text editors. Your problem is you're using something like Windows Notepad to edit your code. Windows Notepad is a terrible tool for writing anything, let alone writing code. Why in the world would any programming language adapt itself to the mental deficiencies of Windows Notepad? I mean, if you were an artist, would you use MS Paint to do anything serious? If you did, would you complain that the art world has a problem because they don't accept your paintings? I strongly suggest you download one of the *hundreds* of free text editors available for the Windows platform that give you the indentation features you so sorely lack. I suggest ViM, though it has a steep learning curve. From hklasky at gmail.com Tue Feb 9 16:42:39 2010 From: hklasky at gmail.com (seth) Date: Tue, 9 Feb 2010 13:42:39 -0800 (PST) Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 Message-ID: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> There is something you could possibly help me with. We have a code that creates a simple Python shelve database. We are able to serialize objects and store them in the dbm file. This seem to work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6, but on Os X 10.5 with Python 2.5 the database filename is changed by the operating system by attaching the .db extension to it. Does an one know why is that? What is worse, at the time of reading it we get the error below the extracted code, on Os X 10.5: if os.path.exists( tarname )and tarfile.is_tarfile( tarname ): try: datastore_tarfile=tarfile.open( tarname, 'r:gz' ) print "Successfully opened the tarball: %s"%tarname members=datastore_tarfile.getnames() for dbmFile in members: datastore_tarfile.extract( dbmFile ) print "Extracting Realizations File: %s"%dbmFile realizations=shelve.open( dbmFile, 'c', 2, writeback = False ) Successfully opened the tarball: datastore.tar.gz Extracting Realizations File: realizations.dbm.db (22, 'Invalid argument') This does not happen on Windows XP with Python 2.5. Does anyone know what is happening on Os X? Any comments and suggestions will be greatly appreciated. Thank you very much in advance. From jgardner at jonathangardner.net Tue Feb 9 16:43:37 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 9 Feb 2010 13:43:37 -0800 (PST) Subject: PostgreSQL driver for Python applications that supports bytea correctly? References: <897cf085-0a29-4372-835d-1c9e23e346a5@e19g2000prn.googlegroups.com> Message-ID: <690d8388-0f24-4461-89a1-cb34e3a082a9@k5g2000pra.googlegroups.com> On Feb 9, 7:27?am, CyclingGuy wrote: > Can anyone recommend a PostgreSQL driver for Python that supports > selecting and inserting bytea types? > Can you name some that don't? From invalid at invalid.invalid Tue Feb 9 16:45:38 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 21:45:38 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Jean-Michel Pichavant wrote: > Grant Edwards wrote: >> What's the correct way to measure small periods of elapsed >> time. I've always used time.clock() in the past: >> >> start = time.clock() >> [stuff being timed] >> stop = time.clock() >> >> delta = stop-start >> >> >> However on multi-processor machines that doesn't work. >> Sometimes I get negative values for delta. According to >> google, this is due to a bug in Windows that causes the value >> of time.clock() to be different depending on which core in a >> multi-core CPU you happen to be on. [insert appropriate >> MS-bashing here] >> >> Is there another way to measure small periods of elapsed time >> (say in the 1-10ms range)? >> >> Is there a way to lock the python process to a single core so >> that time.clock() works right? > Did you try with the datetime module ? > > import datetime > t0 = datetime.datetime.now() > t1 = t0 - datetime.datetime.now() > t1.microseconds > Out[4]: 644114 Doesn't work. datetime.datetime.now has granularity of 15-16ms. Intervals much less that that often come back with a delta of 0. A delay of 20ms produces a delta of either 15-16ms or 31-32ms -- Grant Edwards grante Yow! I'm receiving a coded at message from EUBIE BLAKE!! visi.com From gagsl-py2 at yahoo.com.ar Tue Feb 9 16:50:53 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 18:50:53 -0300 Subject: Programing family References: Message-ID: En Mon, 08 Feb 2010 22:39:58 -0300, AON LAZIO escribi?: > I have thought funny things > If we think all languages are like a family > I could draft them like this (Python base) Have a look at: http://oreilly.com/news/languageposter_0504.html -- Gabriel Genellina From invalid at invalid.invalid Tue Feb 9 17:00:50 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 9 Feb 2010 22:00:50 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Grant Edwards wrote: > On 2010-02-09, Jean-Michel Pichavant wrote: >> Grant Edwards wrote: >>> What's the correct way to measure small periods of elapsed >>> time. I've always used time.clock() in the past: >>> >>> start = time.clock() >>> [stuff being timed] >>> stop = time.clock() >>> >>> delta = stop-start >>> >>> >>> However on multi-processor machines that doesn't work. >>> Sometimes I get negative values for delta. According to >>> google, this is due to a bug in Windows that causes the value >>> of time.clock() to be different depending on which core in a >>> multi-core CPU you happen to be on. [insert appropriate >>> MS-bashing here] >>> >>> Is there another way to measure small periods of elapsed time >>> (say in the 1-10ms range)? >>> >>> Is there a way to lock the python process to a single core so >>> that time.clock() works right? > >> Did you try with the datetime module ? >> >> import datetime >> t0 = datetime.datetime.now() >> t1 = t0 - datetime.datetime.now() >> t1.microseconds >> Out[4]: 644114 > > Doesn't work. datetime.datetime.now has granularity of > 15-16ms. time.time() exhibits the same behavior, so I assume that datetime.datetime.new() ends up making the same libc/system call as time.time(). From what I can grok of the datetime module source code, it looks like it's calling gettimeofday(). I can't find any real documentation on the granularity of Win32 gettimeofday() other than a blog post that claims it is 10ms (which doesn't agree with what my tests show). -- Grant Edwards grante Yow! I feel better about at world problems now! visi.com From mukeshtiwari.iiitm at gmail.com Tue Feb 9 17:06:56 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Tue, 9 Feb 2010 14:06:56 -0800 (PST) Subject: Problem Regarding Queue Message-ID: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> Could some one please tell what is wrong with this code. I am trying to use Queue in this program but i am getting error Traceback (most recent call last): File "/home/user/NetBeansProjects/NewPythonProject2/src/ Pollard_rho.py", line 80, in factor(n) File "/home/user/NetBeansProjects/NewPythonProject2/src/ Pollard_rho.py", line 59, in factor Q_1=Queue() NameError: global name 'Queue' is not defined. As i am new to python so kindly pardon me if i sound stupid. Here is the code # To change this template, choose Tools | Templates # and open the template in the editor. __author__="Mukesh Tiwari" __date__ ="$Feb 10, 2010 1:35:26 AM$" import random import sys def gcd(a,b): while b: a,b=b,a%b return a def rabin_miller(p): if(p<2): return False if(p!=2 and p%2==0): return False s=p-1 while(s%2==0): s>>=1 for i in xrange(10): a=random.randrange(p-1)+1 temp=s mod=pow(a,temp,p) while(temp!=p-1 and mod!=1 and mod!=p-1): mod=(mod*mod)%p temp=temp*2 if(mod!=p-1 and temp%2==0): return False return True def pollard(n): if(n%2==0): return 2; x=random.randrange(2,1000000) c=random.randrange(2,1000000) y=x d=1 while(d==1): x=(x*x+c)%n y=(y*y+c)%n y=(y*y+c)%n d=gcd(x-y,n) if(d==n): break; return d; def factor(n): #if(rabin_miller(n)): # print n # return #d=pollard(n) #if(d!=n): # factor(d) # factor(n/d) #else: # factor(n) Q_1=Queue() Q_2=Queue() Q_1.put(n) while(not Q_1.empty()): l=Q_1.get() if(rabin_miller(l)): Q_2.put(l) continue d=pollard(l) if(d==l):Q_1.put(l) else: Q_1.put(d) Q_1.put(l/d) while(not Q_2.empty()): print Q_2.get() if __name__ == "__main__": while(True): n=input(); factor(n) From simon at brunningonline.net Tue Feb 9 17:10:46 2010 From: simon at brunningonline.net (Simon Brunning) Date: Tue, 9 Feb 2010 22:10:46 +0000 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> On 9 February 2010 16:29, Robert Kern wrote: > On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >> If the code base stabilizes in a production version after losing the >> alphas and betas they would be a great addition to the stdlib, I >> think. > > Why? I agree. Why wait? Put them in the stdlib now! -- Cheers, Simon B. From gordon at panix.com Tue Feb 9 17:11:45 2010 From: gordon at panix.com (John Gordon) Date: Tue, 9 Feb 2010 22:11:45 +0000 (UTC) Subject: New to Python References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: In <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d at posted.grandecom> "Quin" writes: > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > this generates output: > not found > processing > so, it doesn't find the substring, but goes into processing code anyway. I got this output when f contained 'mystring': foundit processing And this output when f did not contain 'mystring': notfound I have no idea why it would have worked otherwise for you. When you posted your question, did you type the code by hand? Perhaps you made a mistake. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From apt.shansen at gmail.com Tue Feb 9 17:25:31 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 14:25:31 -0800 Subject: Problem Regarding Queue In-Reply-To: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> References: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> Message-ID: <7a9c25c21002091425p5ed2181bybe1e5d89e99a89c2@mail.gmail.com> On Tue, Feb 9, 2010 at 2:06 PM, mukesh tiwari wrote: > Could some one please tell what is wrong with this code. I am trying > to use Queue in this program but i am getting error > Traceback (most recent call last): > File "/home/user/NetBeansProjects/NewPythonProject2/src/ > Pollard_rho.py", line 80, in > factor(n) > File "/home/user/NetBeansProjects/NewPythonProject2/src/ > Pollard_rho.py", line 59, in factor > Q_1=Queue() > NameError: global name 'Queue' is not defined. > That's because you haven't imported the Queue module. You need to do: import Queue Then call: Q_1 = Queue.Queue() Alternately, you can do: from Queue import Queue And instantiate the class the same way you previously were. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Tue Feb 9 17:28:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 9 Feb 2010 14:28:12 -0800 Subject: equivalent of Ruby's Pathname? In-Reply-To: References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> <91770e62-2fef-45c9-9e4d-e64088058af1@g8g2000pri.googlegroups.com> <7tceiuF94hU1@mid.individual.net> Message-ID: <50697b2c1002091428n167d2f5ew4393f7bab9a4a8d8@mail.gmail.com> On Tue, Feb 9, 2010 at 6:00 AM, Phlip wrote: > Ah, now we get down to the root of the problem. Because Python is so > stuck on the "one best way to do it" mentality, language bigotry > prevented the Committee from picking from among several equally valid > but non-best options. And after 20 years of growth, Python still has > no Pathname class. What a mature community! C-: Committee? I think you have us confused with C++... *wink*, Chris From drobinow at gmail.com Tue Feb 9 17:42:57 2010 From: drobinow at gmail.com (David Robinow) Date: Tue, 9 Feb 2010 17:42:57 -0500 Subject: ANN: obfuscate In-Reply-To: <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> Message-ID: <4eb0089f1002091442pa4ce024ueb5fa8326cf4b7e@mail.gmail.com> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning wrote: > On 9 February 2010 16:29, Robert Kern wrote: >> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>> If the code base stabilizes in a production version after losing the >>> alphas and betas they would be a great addition to the stdlib, I >>> think. >> >> Why? > > I agree. Why wait? Put them in the stdlib now! > > -- > Cheers, > Simon B. Can we please stop this? From sridharr at activestate.com Tue Feb 9 17:49:07 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Tue, 9 Feb 2010 14:49:07 -0800 Subject: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 In-Reply-To: <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> References: <5b6da8b6-f814-4779-b7cb-b02762e16f2c@a5g2000yqi.googlegroups.com> <5cb36cc2-fe75-4542-af70-b33400fd4dea@f8g2000yqn.googlegroups.com> Message-ID: On 2010-02-07, at 5:02 PM, escalation746 wrote: > Andrej Mitrovic wrote: > >> Perhaps you've accidentally downloaded the wrong version of PythonWin? > > Erk, yes, my bad. > > Thanks for the quick help! Though I still wonder why the ActiveState > build does not include this. I just added support for PyWin32 in ActivePython 2.6 64-bit. http://twitter.com/sridhr/status/8874549314 I should be part of next release (2.6.4.11). -srid From arnodel at googlemail.com Tue Feb 9 17:52:35 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 09 Feb 2010 22:52:35 +0000 Subject: EAFP gone wrong Message-ID: Hi all, Hi have a set of classes that represent mathematical objects which can be represented as a string using a 'latex' method (after Knuth's famous typesetting system). As I want to be able to typeset some builtin types as well, I have a generic function, latex(), as follows: def latex(val): try: return val.latex() except AttributeError: if isinstance(val, (tuple, list)): return ", ".join(map(latex, val)) elif isinstance(val, dict): return ", ".join( "%s=%s" % (latex(k), latex(v)) for k, v in sorted(val.iteritems()) ) else: return str(val) It's EAFP and I have used this for a while with no problem. Recently I added a new class for 'n choose r' objects, as follows: class Choose(Expression): def __init__(self, n, r): self.subexprs = n, r self.n = n self.r = r def calc(self, ns=None, calc=calc): return choose(calc(self.n, ns), calc(self.r, ns)) def latex(self): return "{%s \\choose %s}" % (latex(self.n), latex(self.k)) When I create a Choose object and try to get its latex representation, this happens: >>> c = Choose(5, 3) >>> latex(c) '' This puzzled me for a bit: why is it not trying to use the latex() method of the Choose object? I read and reread the definition of the latex() method for a while until I found that there was a typo. Where it says: latex(self.k) it should say: latex(self.r) Thus it triggers an AttributeError, which is exactly the kind of exception that I am catching in the latex() function after trying val.latex(). (Of course I could have caught this by calling c.latex() directly but it's such a short method definition that I couldn't imagine missing the typo!). This means that EAFP made me hide a typo which would have been obviously detected had I LBYLed, i.e. instead of try: return val.latex() except AttributeError: ... do if hasattr(val, 'latex'): return val.latex() else: ... So was it wrong to say it's EAFP in this case? Should I have known to LBYL from the start? How do you decide which one to use? Up to now, I thought it was more or less a matter of taste but now this makes me think that at least LBYL is better than catching AttributeError. Thanks for any guidance. -- Arnaud From mark0978 at gmail.com Tue Feb 9 17:55:30 2010 From: mark0978 at gmail.com (Mark Jones) Date: Tue, 9 Feb 2010 14:55:30 -0800 (PST) Subject: I've built Python, but can't figure out how to package it for windows Message-ID: Python 2.6.4 is built, and I found a bdist_wininst project and wininst-8 project. How do I manage to build the msi for this thing? From alfps at start.no Tue Feb 9 18:09:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 00:09:23 +0100 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> Message-ID: * David Robinow: > On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning wrote: >> On 9 February 2010 16:29, Robert Kern wrote: >>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>>> If the code base stabilizes in a production version after losing the >>>> alphas and betas they would be a great addition to the stdlib, I >>>> think. >>> Why? >> I agree. Why wait? Put them in the stdlib now! >> > Can we please stop this? I agree. I haven't looked at the code but the functionality that's listed is useful, e.g. in a Usenet client, and it's fun to play around with for a beginner. Also, for example, Christian Heimes wrote else-thread: ?Your work should be interesting for everybody who has read Simon Sing's "The Code Book: The Science of Secrecy from Ancient Egypt to Quantum"? (and I for one have that book). Cheers, - Alf From ben+python at benfinney.id.au Tue Feb 9 18:11:41 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 10:11:41 +1100 Subject: EAFP gone wrong References: Message-ID: <87k4umhumq.fsf@benfinney.id.au> Arnaud Delobelle writes: > As I want to be able to typeset some builtin types as well, I have a > generic function, latex(), as follows: > > def latex(val): > try: > return val.latex() > except AttributeError: [?] > It's EAFP and I have used this for a while with no problem. [?] > I found that there was a typo. Where it says: > > latex(self.k) > > it should say: > > latex(self.r) > > Thus it triggers an AttributeError, which is exactly the kind of > exception that I am catching in the latex() function after trying > val.latex(). (Of course I could have caught this by calling c.latex() > directly but it's such a short method definition that I couldn't > imagine missing the typo!). > > This means that EAFP made me hide a typo which would have been obviously > detected had I LBYLed The correct approach here is to reduce the operations being done in the ?try? suite to a minimum. The fact that you're calling a function in the ?try? block obviously opens you to the potential for an AttributeError from that function. Since that's not what you intend to catch, you need to separate those concerns. def latex(val): def make_result_in_the_absence_of_a_latex_method(): result = transmogrify(val) return result try: typeset_func = val.latex except AttributeError: typeset_func = make_result_in_the_absence_of_a_latex_method result = typeset_func() return result -- \ ?Two hands working can do more than a thousand clasped in | `\ prayer.? ?Anonymous | _o__) | Ben Finney From helmert at informatik.uni-freiburg.de Tue Feb 9 18:22:50 2010 From: helmert at informatik.uni-freiburg.de (Malte Helmert) Date: Wed, 10 Feb 2010 00:22:50 +0100 Subject: EAFP gone wrong In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: > This means that EAFP made me hide a typo which would have been obviously > detected had I LBYLed, i.e. instead of > > try: > return val.latex() > except AttributeError: > ... > > do > > if hasattr(val, 'latex'): > return val.latex() > else: > ... > > > So was it wrong to say it's EAFP in this case? I would say that it's not really the EAFP concept that is problematic here, but rather that the try block encompasses more code than it should. Generally try blocks should be as narrow as possible, i.e., they should contain only the part where you really want to catch a potential failure. "return val.latex()" does two separate things that might fail: the lookup of val.latex, and the actual method call. If I understood you correctly, you only want to catch the AttributeError in the "val.latex" lookup here, and hence I'd say the "correct" application of EAFP here would be something like: try: foo = val.latex except AttributeError: ... else: return foo() Whether that's any better than LBYL in this particular case is of course debatable -- one nice thing compared to your LBYL version is that it doesn't look up val.latex twice upon success. But you could also get that via the LBYLish: latex_method = getattr(val, "latex") if latex_method: return latex_method() ... Malte From helmert at informatik.uni-freiburg.de Tue Feb 9 18:27:10 2010 From: helmert at informatik.uni-freiburg.de (Malte Helmert) Date: Wed, 10 Feb 2010 00:27:10 +0100 Subject: EAFP gone wrong In-Reply-To: <87k4umhumq.fsf@benfinney.id.au> References: <87k4umhumq.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > def latex(val): > def make_result_in_the_absence_of_a_latex_method(): > result = transmogrify(val) > return result > > try: > typeset_func = val.latex > except AttributeError: > typeset_func = make_result_in_the_absence_of_a_latex_method > > result = typeset_func() > return result In this particular case, where in the case of an AttributeError you want to use a fallback callable with the same signature as the bound method you get in case of success, I'd say getattr with a default is the nicest approach: def latex(val): def make_result_in_the_absence_of_a_latex_method(): result = transmogrify(val) return result return getattr(val, "latex", make_result_in_the_absence_of_a_latex_method)() Doesn't work as nicely if you don't have make_result_in_the_absence_of_a_latex_method's functionality bundled into a suitable function already, though. Malte From stef.mientki at gmail.com Tue Feb 9 18:27:13 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Wed, 10 Feb 2010 00:27:13 +0100 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> Message-ID: <4B71EF50.7050801@gmail.com> On 10-02-2010 00:09, Alf P. Steinbach wrote: > * David Robinow: >> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning >> wrote: >>> On 9 February 2010 16:29, Robert Kern wrote: >>>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>>>> If the code base stabilizes in a production version after losing the >>>>> alphas and betas they would be a great addition to the stdlib, I >>>>> think. >>>> Why? >>> I agree. Why wait? Put them in the stdlib now! >>> >> Can we please stop this? > > I agree. > sorry I don't, unless Python is only meant for the very well educated people in encryption. > I haven't looked at the code but the functionality that's listed is > useful, e.g. in a Usenet client, and it's fun to play around with for > a beginner. I neither did look at the code, but as a beginner with just 3 years of experience in Python, I've tried several scrambling libs, for a quick and dirty use. All were much too difficult, so I made my own xor-something. Coming from Delphi, a scrambling lib is working is less than 10 minutes, without the need of any knowledge of encryption. I prefer Python over Delphi, but some things are made very complex in Python. cheers, Stef > > Also, for example, Christian Heimes wrote else-thread: ?Your work > should be interesting for everybody who has read Simon Sing's "The > Code Book: The Science of Secrecy from Ancient Egypt to Quantum"? (and > I for one have that book). > > > Cheers, > > - Alf From steve at REMOVE-THIS-cybersource.com.au Tue Feb 9 18:31:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 23:31:32 GMT Subject: Programing family References: <4b719209$0$10071$426a34cc@news.free.fr> Message-ID: <00fb7592$0$15628$c3e8da3@news.astraweb.com> On Tue, 09 Feb 2010 17:49:21 +0100, Bruno Desthuilliers wrote: > On Feb 8, 2010, at 8:39 PM, AON LAZIO wrote: >> >>> I have thought funny things >>> If we think all languages are like a family > > Then it would be a very incestuous family fore sure. > >>> I could draft them like this (Python base) >>> >>> C is Python's Mom >>> C++ : Dad > > Not that much C++ in Python, IMHO. If that's for the OO part, then the > closer to Python's object model I can think of is javascript. I thought that Javascript didn't even have inheritance until recently? Like in the last year? > Historically, Python comes from ABC, which itself comes from SETL. > >>> Pascal/Assembly : Grandparents > > Assembly ? What about binary machine code then ?-) I'd say assembly is more like the distant answer, back when we still had tails and lived in trees and worried about being eaten by eagles. >>> C# : Uncle >>> Java : Ant > > Interesting typo here !-) > > Hmmm... Python predates both C# and Java. Ok, technically speaking > nothing prevents an uncle or aunt from being younger than their nephews, > and I even saw the case a couple time - but that's far from being the > common case. > >>> Ruby: Cousin >>> Perl : Girlfriend > > Then it's kind of a very passionate love-hate relationship - bordering > on pathological FWIW !-) I'd say that the girlfriend is more likely Lisp or Haskell -- some of the more functional aspects of Python have been inspired by these languages. > Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of > course Simula and Smalltalk. -- Steven From steve at REMOVE-THIS-cybersource.com.au Tue Feb 9 18:37:45 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 09 Feb 2010 23:37:45 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: <00fb7707$0$15628$c3e8da3@news.astraweb.com> On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote: > You thought you cold do a bit of ad hominem attack. That phrase you keep using, "ad hominem"... it doesn't mean what you seem to think it means. An ad hominem attack is not when somebody makes a criticism of you personally. It is when somebody says something along the lines of "Don't pay any attention to Alf, he doesn't know what he's talking about, he's a ". You might not like the personal criticism, but that doesn't make it either an attack or a fallacy. -- Steven From alfps at start.no Tue Feb 9 18:40:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 00:40:50 +0100 Subject: Easter Eggs Message-ID: I know 3 Python Easter Eggs, from __future__ import braces import this help( "antigravity" ) Are there more? Cheers, - Alf From gagsl-py2 at yahoo.com.ar Tue Feb 9 18:43:51 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 20:43:51 -0300 Subject: How to measure elapsed time under Windows? References: Message-ID: En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards escribi?: > What's the correct way to measure small periods of elapsed > time. I've always used time.clock() in the past: > > However on multi-processor machines that doesn't work. > Sometimes I get negative values for delta. According to > google, this is due to a bug in Windows that causes the value > of time.clock() to be different depending on which core in a > multi-core CPU you happen to be on. [insert appropriate > MS-bashing here] I'm not sure you can blame MS of this issue; anyway, this patch should fix the problem: http://support.microsoft.com/?id=896256 > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? No that I know of. QueryPerformanceCounter (the function used by time.clock) seems to be the best timer available. > Is there a way to lock the python process to a single core so > that time.clock() works right? Interactively, from the Task Manager: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_assign_process.mspx In code, using SetProcessAffinityMask and related functions: http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx -- Gabriel Genellina From mrabarnett at mrabarnett.plus.com Tue Feb 9 18:49:25 2010 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Tue, 09 Feb 2010 23:49:25 +0000 Subject: EAFP gone wrong In-Reply-To: References: Message-ID: <4B71F485.4050703@mrabarnett.plus.com> Arnaud Delobelle wrote: > Hi all, > > Hi have a set of classes that represent mathematical objects which can > be represented as a string using a 'latex' method (after Knuth's famous > typesetting system). As I want to be able to typeset some builtin types as > well, I have a generic function, latex(), as follows: > > def latex(val): > try: > return val.latex() > except AttributeError: > if isinstance(val, (tuple, list)): > return ", ".join(map(latex, val)) > elif isinstance(val, dict): > return ", ".join( > "%s=%s" % (latex(k), latex(v)) > for k, v in sorted(val.iteritems()) > ) > else: > return str(val) > > It's EAFP and I have used this for a while with no problem. Recently I > added a new class for 'n choose r' objects, as follows: > > class Choose(Expression): > def __init__(self, n, r): > self.subexprs = n, r > self.n = n > self.r = r > def calc(self, ns=None, calc=calc): > return choose(calc(self.n, ns), calc(self.r, ns)) > def latex(self): > return "{%s \\choose %s}" % (latex(self.n), latex(self.k)) > > When I create a Choose object and try to get its latex representation, > this happens: > >>>> c = Choose(5, 3) >>>> latex(c) > '' > > This puzzled me for a bit: why is it not trying to use the latex() > method of the Choose object? I read and reread the definition of the > latex() method for a while until I found that there was a typo. Where > it says: > > latex(self.k) > > it should say: > > latex(self.r) > > Thus it triggers an AttributeError, which is exactly the kind of > exception that I am catching in the latex() function after trying > val.latex(). (Of course I could have caught this by calling c.latex() > directly but it's such a short method definition that I couldn't imagine > missing the typo!). > > This means that EAFP made me hide a typo which would have been obviously > detected had I LBYLed, i.e. instead of > > try: > return val.latex() > except AttributeError: > ... > > do > > if hasattr(val, 'latex'): > return val.latex() > else: > ... > > > So was it wrong to say it's EAFP in this case? Should I have known to > LBYL from the start? How do you decide which one to use? Up to now, I > thought it was more or less a matter of taste but now this makes me > think that at least LBYL is better than catching AttributeError. > > Thanks for any guidance. > In addition to the other replies, you should've tested the Choose class. :-) From rantingrick at gmail.com Tue Feb 9 18:55:36 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 9 Feb 2010 15:55:36 -0800 (PST) Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> Message-ID: On Feb 9, 7:21?am, Roy Smith wrote: > In article <00fa27a3$0$15628$c3e8... at news.astraweb.com>, > ?Steven D'Aprano wrote: [..] > No pig latin? Wait a minute guys, Stevens a well known prankster and comic relief clown around here, I think he's just shining us all on! ;o) From jeanmichel at sequans.com Tue Feb 9 18:59:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 00:59:15 +0100 Subject: New to Python In-Reply-To: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <4B71F6D3.9020803@sequans.com> Quin wrote: > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > this generates output: > not found > processing > > so, it doesn't find the substring, but goes into processing code anyway. > > This is using IronPython The code you povided works as expected. Copy paste the exact code JM From gagsl-py2 at yahoo.com.ar Tue Feb 9 18:59:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 20:59:16 -0300 Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> <8281270.AG5xCW3FSB@beaureve.gmx.net> Message-ID: En Tue, 09 Feb 2010 15:47:43 -0300, Martin Drautzburg escribi?: > Carl Banks wrote: > >> You can have __add__ return a closure for the first addition, then >> perform the operation on the second one. Example (untested): >> > > That's way cool. > > Of course! - CURRYING!! If you can return closures > you can do everything with just single-parameter functions. insight> > > BTW I am not really trying to add three objects, I wanted a third object > which controls the way the addition is done. Sort of like "/" and "//" > which are two different ways of doing division. See http://code.activestate.com/recipes/384122/ for another cool hack that may help with that. -- Gabriel Genellina From rantingrick at gmail.com Tue Feb 9 19:01:44 2010 From: rantingrick at gmail.com (rantingrick) Date: Tue, 9 Feb 2010 16:01:44 -0800 (PST) Subject: Easter Eggs References: Message-ID: <7e0eb494-71d6-47c6-96ad-fecf0866fb25@d27g2000yqn.googlegroups.com> On Feb 9, 5:40?pm, "Alf P. Steinbach" wrote: > I know 3 Python Easter Eggs, > > ? ?from __future__ import braces > ? ?import this > ? ?help( "antigravity" ) > > Are there more? > > Cheers, > > - Alf Oh this is just great ALF! Now what secrets will the Py-Illuminati have to giggle about whist watching Monty Python's flying circus and enjoying those delightfully delicious little crumpets? I very disappointed in you sir! :'-( PS WTF From alfps at start.no Tue Feb 9 19:06:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 01:06:02 +0100 Subject: Modifying Class Object In-Reply-To: <00fb7707$0$15628$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote: > >> You thought you cold do a bit of ad hominem attack. > > That phrase you keep using, "ad hominem"... it doesn't mean what you seem > to think it means. > > An ad hominem attack is not when somebody makes a criticism of you > personally. It is when somebody says something along the lines of "Don't > pay any attention to Alf, he doesn't know what he's talking about, he's a > ". ad hominem Latin [?d ?h?m??n?m] adj & adv 1. directed against a person rather than against his arguments 2. based on or appealing to emotion rather than reason Compare ad rem See also argumentum ad hominem > You might not like the personal criticism, but that doesn't make it > either an attack or a fallacy. Steve Holden attacked only at the personal level, via characterization. In response to ... > >> No idea. Nothing I know of can solve it [failure of article propagation]. > > Not sure, but perhaps it's possible to mail directly to gmane? ... Steve Holden wrote: Is there *any* problem you don't have a fatuous answer for? Which doesn't have anything to do with any subject matter discussed, not even the PS that he was replying to (which absolutely didn't warrant that description or any negative response), but which does convey an impression of a person. Then he wrote you assumed you knew better than Stephen [Hansen] which again is only about a person, and here about the person's motivations for trying to help. And there was a bit more with some collateral damage in the implications. It's pretty dirty and yes, personal attacks are ad hominem; see above. The ad hominem attacks that he appears to routinely engage in reflect back on Steve Holden but the sub-threads that they invariably spawn also constitute a high level of noise deflecting from whatever issue was discussed. Cheers & hth. (especially the dictionary reference), - Alf PS: in order to recognize various forms of fallacies the following is a quite useful resource: . I just typed "fallacies" in the Firefox address bar. - DS From gagsl-py2 at yahoo.com.ar Tue Feb 9 19:14:57 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 21:14:57 -0300 Subject: I've built Python, but can't figure out how to package it for windows References: Message-ID: En Tue, 09 Feb 2010 19:55:30 -0300, Mark Jones escribi?: > Python 2.6.4 is built, and I found a bdist_wininst project and > wininst-8 project. > > How do I manage to build the msi for this thing? See the Tools\msi directory; and look for some posts last year from Tim Golden regarding some issues with the directory layout and other details. -- Gabriel Genellina From rtw at freenet.co.uk Tue Feb 9 19:16:24 2010 From: rtw at freenet.co.uk (Rob Williscroft) Date: Tue, 09 Feb 2010 18:16:24 -0600 Subject: Problem Regarding Queue References: <80fed7d5-76eb-40c8-ace1-0c35736de399@t17g2000prg.googlegroups.com> Message-ID: mukesh tiwari wrote in news:80fed7d5-76eb-40c8-ace1-0c35736de399 @t17g2000prg.googlegroups.com in comp.lang.python: > Could some one please tell what is wrong with this code. I am trying > to use Queue in this program but i am getting error The type you appear to be trying to use is Queue.Queue which you import with: from Queue import Queue http://docs.python.org/library/queue.html?highlight=queue#Queue.Queue > Q_1=Queue() > Q_2=Queue() > Q_1.put(n) > while(not Q_1.empty()): > l=Q_1.get() > if(rabin_miller(l)): > Q_2.put(l) > continue > d=pollard(l) > if(d==l):Q_1.put(l) > else: As the help page above points out also check out the deque Class: http://docs.python.org/library/collections.html#collections.deque Rob. From ben+python at benfinney.id.au Tue Feb 9 19:23:34 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 11:23:34 +1100 Subject: Personal criticisms and logical fallacies (was: Modifying Class Object) References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> Message-ID: <87eikuhrax.fsf_-_@benfinney.id.au> Steven D'Aprano writes: > An ad hominem attack is not when somebody makes a criticism of you > personally. It is when somebody says something along the lines of > "Don't pay any attention to Alf, he doesn't know what he's talking > about, he's a ". In other words, a criticism of the person is only a fallacy if it is both irrelevant to the argument *and* used to dismiss the argument. Many criticisms are introduced not because they directly connect to the argument, but simply because they are relevant to the demonstrated behaviour at the time. > You might not like the personal criticism, but that doesn't make it > either an attack or a fallacy. Exactly. A personal criticism can be expressed *as a criticism*, and be valid or not without needing to be relevant to your chosen argument. Look to the criticism on its own merits, and decide what to do about it. -- \ ?If there were not God, there would be no atheists.? ?G. K. | `\ Chesterton | _o__) | Ben Finney From van.lindberg at gmail.com Tue Feb 9 19:24:15 2010 From: van.lindberg at gmail.com (VanL) Date: Tue, 09 Feb 2010 18:24:15 -0600 Subject: PyCon is coming! Tomorrow, Feb. 10 is the last day for pre-conference rates Message-ID: PyCon is coming! Tomorrow (February 10th) is the last day for pre-conference rates. You can register for PyCon online at: Register while it is still Feb. 10th somewhere in the world and rest easy in the knowledge that within 10 days you will enjoying the company of some of the finest Python hackers in the world. As an additional bonus, PyCon this year will be in Atlanta, making it an ideal location for those looking for a way to escape the late winter blizzards in the northeastern United States, or the dreary fog of the Bay area. See you at PyCon 2010! From mark0978 at gmail.com Tue Feb 9 19:24:58 2010 From: mark0978 at gmail.com (Mark Jones) Date: Tue, 9 Feb 2010 16:24:58 -0800 (PST) Subject: I've built Python, but can't figure out how to package it for windows References: Message-ID: That was so simple, thanks. I scanned all the folders for inst, install, setup, but since msi was the expected output extension, I didn't see that! On Feb 9, 6:14?pm, "Gabriel Genellina" wrote: > En Tue, 09 Feb 2010 19:55:30 -0300, Mark Jones ? > escribi?: > > > Python 2.6.4 is built, and I found a bdist_wininst project and > > wininst-8 project. > > > How do I manage to build the msi for this thing? > > See the Tools\msi directory; and look for some posts last year from Tim ? > Golden regarding some issues with the directory layout and other details. > > -- > Gabriel Genellina From half.italian at gmail.com Tue Feb 9 19:27:41 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Tue, 9 Feb 2010 16:27:41 -0800 (PST) Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <22ac2bce-cf12-45e2-9d89-d7df56a2faa7@b1g2000prc.googlegroups.com> Message-ID: <8fc356e0-f3ed-4a67-9b37-f21561cef4a5@p13g2000pre.googlegroups.com> On Feb 8, 2:36?pm, a... at pythoncraft.com (Aahz) wrote: > In article , > Sean DiZazzo ? wrote: > > >On Feb 3, 6:08=A0pm, alex23 wrote: > > >> There was also a PEP with another possible implementation: > >>http://www.python.org/dev/peps/pep-0355/ > > >Why did Path() get rejected? ?Is it the idea itself, or just the > >approach that was used? ?What are the complaints? > > You should search for the discussiona around it. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > import antigravity I read the discussion, and there was definitely some going back and forth on whether it should be sub-classed from string, but the conversation just seemed to stop abruptly with no decision one way of the other. Maybe I missed a thread. I guess being dropped without a final go-ahead is just as good as a formal no anyway. From gagsl-py2 at yahoo.com.ar Tue Feb 9 19:29:31 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 21:29:31 -0300 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: En Tue, 09 Feb 2010 20:27:13 -0300, Stef Mientki escribi?: > On 10-02-2010 00:09, Alf P. Steinbach wrote: >> * David Robinow: >>> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning >>> wrote: >>>> On 9 February 2010 16:29, Robert Kern wrote: >>>>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote: >>>>>> If the code base stabilizes in a production version after losing the >>>>>> alphas and betas they would be a great addition to the stdlib, I >>>>>> think. >>>>> Why? >>>> I agree. Why wait? Put them in the stdlib now! >>> Can we please stop this? >> I agree. >> > sorry I don't, > unless Python is only meant for the very well educated people in > encryption. > >> I haven't looked at the code but the functionality that's listed is >> useful, e.g. in a Usenet client, and it's fun to play around with for a >> beginner. > I neither did look at the code, > but as a beginner with just 3 years of experience in Python, > I've tried several scrambling libs, for a quick and dirty use. > All were much too difficult, so I made my own xor-something. > Coming from Delphi, a scrambling lib is working is less than 10 minutes, > without the need of any knowledge of encryption. > I prefer Python over Delphi, but some things are made very complex in > Python. Are you sure? >>> def xor(s, key): ... return ''.join(chr(ord(c)^key) for c in s) ... >>> txt = "Hello world!" >>> xor(txt, 123) '3\x1e\x17\x17\x14[\x0c\x14\t\x17\x1fZ' >>> xor(_, 123) 'Hello world!' The Delphi code would be certainly longer than that, some variation of: function encrypt_xor(const s: string; key: integer); var i: integer; begin SetLength(Result, length(s)); for i:=1 to length(s) do begin Result[i] := chr(ord(s[i]) xor key); end; end; (untested) -- Gabriel Genellina From alfps at start.no Tue Feb 9 19:38:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 01:38:50 +0100 Subject: Personal criticisms and logical fallacies In-Reply-To: <87eikuhrax.fsf_-_@benfinney.id.au> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> Message-ID: * Ben Finney: > Steven D'Aprano writes: > >> An ad hominem attack is not when somebody makes a criticism of you >> personally. It is when somebody says something along the lines of >> "Don't pay any attention to Alf, he doesn't know what he's talking >> about, he's a ". > > In other words, a criticism of the person is only a fallacy if it is > both irrelevant to the argument *and* used to dismiss the argument. Or to weaken an argument, or to draw attention away from an argument, or to weaken future arguments... However, although in this particular case the Ad Hominems constituted logical fallacies, not all Ad Hominems are logical fallacies. For example, if a person is a chronic liar, has a known history of lying, then that can have a strong bearing on whether the person's claims -- technical or about other persons -- should be seriously considered[1]. Cheers & hth., - Alf Notes: [1] As explained at From gagsl-py2 at yahoo.com.ar Tue Feb 9 19:39:31 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 09 Feb 2010 21:39:31 -0300 Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> Message-ID: En Tue, 09 Feb 2010 21:06:02 -0300, Alf P. Steinbach escribi?: > * Steven D'Aprano: >> On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote: >> >>> You thought you cold do a bit of ad hominem attack. >> That phrase you keep using, "ad hominem"... it doesn't mean what you >> seem to think it means. >> An ad hominem attack is not when somebody makes a criticism of you >> personally. It is when somebody says something along the lines of >> "Don't pay any attention to Alf, he doesn't know what he's talking >> about, he's a ". > > > ad hominem Latin [?d ?h?m??n?m] > adj & adv > 1. directed against a person rather than against his arguments ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 2. based on or appealing to emotion rather than reason Compare ad rem > See also argumentum ad hominem > > In response to ... > > > >> No idea. Nothing I know of can solve it [failure of article > propagation]. > > > > Not sure, but perhaps it's possible to mail directly to gmane? > > ... Steve Holden wrote: > > > Is there *any* problem you don't have a fatuous answer for? > > > Which doesn't have anything to do with any subject matter discussed, not > even the PS that he was replying to (which absolutely didn't warrant > that description or any negative response), but which does convey an > impression of a person. This doesn't make it an ad hominem fallacie. This is just criticism directed to your person, that you may like or not. It would be a fallacie if it were intended to dismiss your argument. > PS: in order to recognize various forms of fallacies the following is a > quite useful resource: . > I just typed "fallacies" in the Firefox address bar. - DS From the above site: "this fallacy involves two steps. First, an attack against the character of person making the claim [...] Second, this attack is taken to be evidence against the claim or argument the person in question is making (or presenting)." That second part is missing in S. H. posts. -- Gabriel Genellina From lists at cheimes.de Tue Feb 9 20:03:47 2010 From: lists at cheimes.de (Christian Heimes) Date: Wed, 10 Feb 2010 02:03:47 +0100 Subject: ANN: obfuscate In-Reply-To: <4B71EF50.7050801@gmail.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: <4B7205F3.6040603@cheimes.de> Stef Mientki wrote: > sorry I don't, > unless Python is only meant for the very well educated people in encryption. All algorithms in obfuscate are obsolete, insecure and only interesting for people *that* want to get well educated in the history of encryption. > I neither did look at the code, > but as a beginner with just 3 years of experience in Python, > I've tried several scrambling libs, for a quick and dirty use. > All were much too difficult, so I made my own xor-something. > Coming from Delphi, a scrambling lib is working is less than 10 minutes, > without the need of any knowledge of encryption. > I prefer Python over Delphi, but some things are made very complex in > Python. It's tricky to implement modern cryptographic algorithms with Python. Most example codes are written in C and the implementations are using overflow (e.g. 255 + 1 == 0) a lot. It took me twice as long to get the TEA family (TEA, XTEA, XXTEA) crypt functions right in Python than I required to wrap existing code in an handwritten C interface. One of the strongest encryption algorithm in the list -- Vigen?re -- was crack over 150 years (!) ago. A much, much stronger version of the principles behind Vigen?re was used in the German Enigma machine. Because the algorithm was still not good enought some clever guy called Turing and his team was able to crack the enigma. It's one of the main reasons the Germans were defeated and the world doesn't look like in Robert Harris "Fatherland" today. Oh, and we go computers, too. ;) Grab pycrypto, m2crypto or one of the other packages if you need a minimum amount of security. Christian From ben+python at benfinney.id.au Tue Feb 9 20:24:44 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 12:24:44 +1100 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: <871vgtj31f.fsf@benfinney.id.au> Christian Heimes writes: > All algorithms in obfuscate are obsolete, insecure and only > interesting for people *that* want to get well educated in the history > of encryption. Not true. Another use case is suggested by the chosen name for the library: to obfuscate text against casual human reading, while not making it at all difficult to decrypt by people who are motivated to do so. The classic example is rot-13 encryption of text in internet messages; it would be a failure of imagination to suggest there are not other, similar use cases. > Grab pycrypto, m2crypto or one of the other packages if you need a > minimum amount of security. Agreed. However, for cases that *don't* need security from determined attackers, I don't think those obviate the usefulness of this library. -- \ ?Reality must take precedence over public relations, for nature | `\ cannot be fooled.? ?Richard P. Feynman | _o__) | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Tue Feb 9 20:35:21 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 01:35:21 GMT Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: On Wed, 10 Feb 2010 02:03:47 +0100, Christian Heimes wrote: > Stef Mientki wrote: >> sorry I don't, >> unless Python is only meant for the very well educated people in >> encryption. > > All algorithms in obfuscate are obsolete, insecure and only interesting > for people *that* want to get well educated in the history of > encryption. [...] > Grab pycrypto, m2crypto or one of the other packages if you need a > minimum amount of security. As the author of obfuscate, I would like to second Christian's statement. obfuscate is NOT meant for serious security, as I state in both the source code and the documentation to the module. That's not to say that it can't be useful for some people -- I wouldn't have spent the time writing it if I didn't think it was useful. But it is useful for obfuscation, education and puzzles, not for secure encryption. I'm not sure how serious the calls for this to be added to the standard library are. If they're serious, I'm grateful for the votes of confidence from people, but I can't imagine Guido saying yes. In any case, it's premature to talk about adding it to the std library while it is still in alpha. Thank you for all the comments, even the tongue-in-cheek ones. This has exceeded my wildest expectations! I'm always interested in feedback, good and bad, either publicly or privately. -- Steven From tjreedy at udel.edu Tue Feb 9 21:04:43 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 09 Feb 2010 21:04:43 -0500 Subject: Programing family In-Reply-To: <4b719209$0$10071$426a34cc@news.free.fr> References: <4b719209$0$10071$426a34cc@news.free.fr> Message-ID: >>> C is Python's Mom >>> C++ : Dad Obviously no. The other parent might be arguably be Barbara Liskov's CLU, itself based on Algol. http://en.wikipedia.org/wiki/CLU_%28programming_language%29 CLU contributions: The basic object model, including mutable/immutable The function call-by-object model Iterators/generators/yield Multiple assignment and function returns Terry Jan Reedy From danielwong at berkeley.edu Tue Feb 9 21:40:26 2010 From: danielwong at berkeley.edu (danielx) Date: Tue, 9 Feb 2010 18:40:26 -0800 (PST) Subject: convention for documenting function parameters in doc strings References: Message-ID: On Feb 8, 2:49?am, Jean-Michel Pichavant wrote: > danielx wrote: > > Is there aconventionfor how to document function (or method) > > parameters in doc strings? Recently, I've been doing alot of PHP > > programming, and in PHPdoc, you'd do it like this: > > > /* > > ?* @param type $foo Description. > > ?* > > ?* @return type Description. > > ?*/ > > function bar($foo) { > > ? ... > > } > > > Is there an equivalentconventionI (c|sh)ould be using in my Python > > docstrings? I saw that Python 3 has function annotations, which could > > be used for this purpose, but function annotations have no particular > > purpose within the language itself (which seems like a mistake to me), > > and they don't exist in the Python 2.x series (at least not the older > > versions). > > Different strategies here: > > 1/ most doc builders propose their own format. You can stick to it if > you don't want to use another builder (e.g. epydoc has a specific syntax > to document signatures) > 2/ Use a 'standard' format, usually these formats are a bit more formal > but they gain in portability, most builders support these formats. > reStructuredText is one of them and supported by all python doc builders. > > http://epydoc.sourceforge.net/manual-othermarkup.html > > JM Thanks for the link, Jean-Michel. I was hoping to find out more about how this is don in reStructuredText, since that seems to be what's used to document Python at docs.python.org. There is a section in the page that you linked to which describes how documenting function parameters in reST works, which seems to be what I was looking for. From orgnut at yahoo.com Tue Feb 9 22:09:45 2010 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 09 Feb 2010 19:09:45 -0800 Subject: New to Python In-Reply-To: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: Quin wrote: > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > this generates output: > not found > processing > > so, it doesn't find the substring, but goes into processing code anyway. > > This is using IronPython As others have already said, this _does_ work properly. But a minor rearrangement is simpler, and IMHO clearer: if 'mystring' not in s: print 'not found' else: print 'foundit' print 'processing' -=- Larry -=- From quindennis at grandecom.net Tue Feb 9 22:30:52 2010 From: quindennis at grandecom.net (Quin) Date: Tue, 9 Feb 2010 21:30:52 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Thanks guys, I'm thinking it's a problem with IronPython. I'm switching to PyScripter and will test tomorrow. "Larry Hudson" wrote in message news:ybmdnRFZZ_3nvu_WnZ2dnUVZ_hGdnZ2d at giganews.com... > Quin wrote: >> s = f.readline() >> if 'mystring' in s: print 'foundit' >> if 'mystring' not in s: print 'not found' >> if 'mystring' in s: >> print 'processing' >> >> this generates output: >> not found >> processing >> >> so, it doesn't find the substring, but goes into processing code anyway. >> >> This is using IronPython > > As others have already said, this _does_ work properly. > > But a minor rearrangement is simpler, and IMHO clearer: > > if 'mystring' not in s: > print 'not found' > else: > print 'foundit' > print 'processing' > > -=- Larry -=- From python.list at tim.thechases.com Tue Feb 9 22:36:50 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 09 Feb 2010 21:36:50 -0600 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <4B7229D2.8060704@tim.thechases.com> Larry Hudson wrote: > But a minor rearrangement is simpler, and IMHO clearer: > > if 'mystring' not in s: > print 'not found' > else: > print 'foundit' > print 'processing' I've always vacillated on whether that would better be written as Larry does, or as if 'mystring' in s print 'foundit' print 'processing' else: print 'not found' removing the "not" from the condition. I admit I choose one over the other based on some gut-feeling aesthetic that I can't really nail down. I think one of my major influencing factors revolves around the negative "not" portion having one or two lines and the positive portion having a large block of code. If the code-blocks are more equal in size, I tend to use "if {positive}", but if the negative "not" section is only 1-2 lines, I tend to do as Larry writes and make it harder to miss by using "if {negative}". Otherwise the "if {positive}...else" can end up sufficiently distant from the "if" that it's easy to miss. Any thoughts on how others make the choice? -tkc From cs at zip.com.au Tue Feb 9 22:54:17 2010 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 10 Feb 2010 14:54:17 +1100 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <4B7229D2.8060704@tim.thechases.com> Message-ID: <20100210035417.GA5737@cskk.homeip.net> On 09Feb2010 21:36, Tim Chase wrote: | Larry Hudson wrote: | >But a minor rearrangement is simpler, and IMHO clearer: | > | >if 'mystring' not in s: | > print 'not found' | >else: | > print 'foundit' | > print 'processing' | | I've always vacillated on whether that would better be written as | Larry does, or as | | if 'mystring' in s | print 'foundit' | print 'processing' | else: | print 'not found' | | removing the "not" from the condition. I admit I choose one over | the other based on some gut-feeling aesthetic that I can't really | nail down. I think one of my major influencing factors revolves | around the negative "not" portion having one or two lines and the | positive portion having a large block of code. If the code-blocks | are more equal in size, I tend to use "if {positive}", but if the | negative "not" section is only 1-2 lines, I tend to do as Larry | writes and make it harder to miss by using "if {negative}". | Otherwise the "if {positive}...else" can end up sufficiently distant | from the "if" that it's easy to miss. I do it like you, usually: if one branch is small, it comes first, the other branch is easily in sight under the "else". Otherwise, I tend to go with "if {positive}", or at any rate "if {the easiest-to-read-form-of-the-test}" if it all still reads well. If the program flow gets ugly one way, that breaks "still reads well" and can be cause to flip the condition. In loops my tendency is a bit less flexible; I often have code like this: while ...: if winnowing-test: whinge set flag continue or break, depending main body of loop here... Not a lot of choice about positive/negative in that scenario, though it fits well with the first criterion. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ A Master is someone who started before you did. - Gary Zukav From daniel at stutzbachenterprises.com Tue Feb 9 22:58:02 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Tue, 9 Feb 2010 21:58:02 -0600 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: On Tue, Feb 9, 2010 at 9:36 PM, Tim Chase wrote: > removing the "not" from the condition. I admit I choose one over the other > based on some gut-feeling aesthetic that I can't really nail down. I think > one of my major influencing factors revolves around the negative "not" > portion having one or two lines and the positive portion having a large > block of code. If one block is much shorter, I tend to put the shorter block first. That way, the "else" and the "if" are almost always on the screen together at the same time. If they're both long, I factor out one or both of the blocks into functions. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Tue Feb 9 23:01:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 09 Feb 2010 23:01:31 -0500 Subject: New to Python In-Reply-To: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Quin wrote: > Thanks guys, I'm thinking it's a problem with IronPython. I'm switching > to PyScripter and will test tomorrow. > I'd be very surprised to find that something as basic as this was wrong with IronPython. Complex commercial software has been built on it, so there's little question that the platform is sound. Are you *sure* you copied and pasted the session you listed? regards Steve > "Larry Hudson" wrote in message > news:ybmdnRFZZ_3nvu_WnZ2dnUVZ_hGdnZ2d at giganews.com... >> Quin wrote: >>> s = f.readline() >>> if 'mystring' in s: print 'foundit' >>> if 'mystring' not in s: print 'not found' >>> if 'mystring' in s: >>> print 'processing' >>> >>> this generates output: >>> not found >>> processing >>> >>> so, it doesn't find the substring, but goes into processing code anyway. >>> >>> This is using IronPython >> >> As others have already said, this _does_ work properly. >> >> But a minor rearrangement is simpler, and IMHO clearer: >> >> if 'mystring' not in s: >> print 'not found' >> else: >> print 'foundit' >> print 'processing' >> >> -=- Larry -=- > -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Tue Feb 9 23:05:09 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 20:05:09 -0800 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: <7a9c25c21002092005k7b8f6a2csec1ea5a8c28ec530@mail.gmail.com> On Tue, Feb 9, 2010 at 7:58 PM, Daniel Stutzbach < daniel at stutzbachenterprises.com> wrote: > On Tue, Feb 9, 2010 at 9:36 PM, Tim Chase wrote: > >> removing the "not" from the condition. I admit I choose one over the >> other based on some gut-feeling aesthetic that I can't really nail down. I >> think one of my major influencing factors revolves around the negative "not" >> portion having one or two lines and the positive portion having a large >> block of code. > > > If one block is much shorter, I tend to put the shorter block first. That > way, the "else" and the "if" are almost always on the screen together at the > same time. If they're both long, I factor out one or both of the blocks > into functions. > Agree 100%. I like whatever the little branch is to be first, with the big branch falling into the "else:". It reads better then to have an "else:" at the end with only a line or two: in such a situation what 'else' is doesn't really have direct meaning, you have to look too far up to connect it to the "if" logic. Comments shouldn't be needed-- if an "else:" falls too far away from the "if" then scrolling around and looking for the code, it won't be immediately obvious in meaning. And if both branches are fairly long, it tends to imply that I just might benefit from some more functions to re-organize logic into manageable chunks. Then again, general rule of thumb? If a function is not entirely visible on my screen, it might imply I might benefit from some more functions. Though this is not anything like a hard rule. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Tue Feb 9 23:09:37 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 05:09:37 +0100 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: * Tim Chase: > Larry Hudson wrote: >> But a minor rearrangement is simpler, and IMHO clearer: >> >> if 'mystring' not in s: >> print 'not found' >> else: >> print 'foundit' >> print 'processing' > > I've always vacillated on whether that would better be written as Larry > does, or as > > if 'mystring' in s > print 'foundit' > print 'processing' > else: > print 'not found' > > removing the "not" from the condition. I admit I choose one over the > other based on some gut-feeling aesthetic that I can't really nail > down. I think one of my major influencing factors revolves around the > negative "not" portion having one or two lines and the positive portion > having a large block of code. If the code-blocks are more equal in > size, I tend to use "if {positive}", but if the negative "not" section > is only 1-2 lines, I tend to do as Larry writes and make it harder to > miss by using "if {negative}". Otherwise the "if {positive}...else" can > end up sufficiently distant from the "if" that it's easy to miss. > > Any thoughts on how others make the choice? I think it spills over from the practice of checking preconditions first, e.g. returning or raising exceptions or whatever. This avoids silly n-level nesting of the main "normal case" part. Cheers, - Alf From python at bdurham.com Tue Feb 9 23:45:28 2010 From: python at bdurham.com (python at bdurham.com) Date: Tue, 09 Feb 2010 23:45:28 -0500 Subject: Creating formatted output using picture strings Message-ID: <1265777128.24758.1359202989@webmail.messagingengine.com> Does Python provide a way to format a string according to a 'picture' format? For example, if I have a string '123456789' and want it formatted like '(123)-45-(678)[9]', is there a module or function that will allow me to do this or do I need to code this type of transformation myself? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Wed Feb 10 00:24:20 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 21:24:20 -0800 Subject: Creating formatted output using picture strings In-Reply-To: <1265777128.24758.1359202989@webmail.messagingengine.com> References: <1265777128.24758.1359202989@webmail.messagingengine.com> Message-ID: <7a9c25c21002092124v51815151m96042ed8483afe23@mail.gmail.com> On Tue, Feb 9, 2010 at 8:45 PM, wrote: > Does Python provide a way to format a string according to a 'picture' > format? > > For example, if I have a string '123456789' and want it formatted like > '(123)-45-(678)[9]', is there a module or function that will allow me to do > this or do I need to code this type of transformation myself? > Although I usually don't jump to suggesting regular expressions, its the easiest way I can figure out to do this. >>> import re >>> >>> print re.sub(r"(\d{3})(\d{2})(\d{3})(\d)", r"(\1)-\2-(\3)[\4]", "123456789") (123)-45-(678)[9] --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptmcg at austin.rr.com Wed Feb 10 01:41:46 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Tue, 9 Feb 2010 22:41:46 -0800 (PST) Subject: How to measure elapsed time under Windows? References: Message-ID: <7c76a725-bd88-41a0-9867-820b82b872e7@l19g2000yqb.googlegroups.com> On Feb 9, 10:10?am, Grant Edwards wrote: > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > On Feb 9, 10:10 am, Grant Edwards wrote: > Is there another way to measure small periods of elapsed time > (say in the 1-10ms range)? > I made repeated calls to time.clock() in a generator expression, which is as fast a loop I can think of in Python. Then I computed the successive time deltas to see if any granularities jumped out. Here are the results: >>> import time >>> from itertools import groupby >>> >>> # get about 1000 different values of time.clock() >>> ts = set(time.clock() for i in range(1000)) >>> >>> # sort in ascending order >>> ts = sorted(ts) >>> >>> # compute diffs between adjacent time values >>> diffs = [j-i for i,j in zip(ts[:-1],ts[1:])] >>> >>> # sort and group >>> diffs.sort() >>> diffgroups = groupby(diffs) >>> >>> # print the distribution of time differences in microseconds >>> for i in diffgroups: print "%3d %12.6f" % (len(list(i[1])), i[0]*1e6) ... 25 2.234921 28 2.234921 242 2.514286 506 2.514286 45 2.793651 116 2.793651 1 3.073016 8 3.073016 6 3.352381 4 3.631746 3 3.911112 1 3.911112 5 4.190477 2 4.469842 1 6.146033 1 8.660319 1 9.777779 1 10.895239 1 11.174605 1 24.304765 1 41.904767 There seems to be a step size of about .28 microseconds. So I would guess time.clock() has enough resolution. But also beware of the overhead of the calls to clock() - using timeit, I find that each call takes about 2 microseconds (consistent with the smallest time difference in the above data set). -- Paul From apt.shansen at gmail.com Wed Feb 10 01:47:40 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 22:47:40 -0800 Subject: New to Python In-Reply-To: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <7a9c25c21002092247g2a3a2c4bt6e93921a73c005c3@mail.gmail.com> On Tue, Feb 9, 2010 at 7:30 PM, Quin wrote: > Thanks guys, I'm thinking it's a problem with IronPython. I'm switching to > PyScripter and will test tomorrow. > The chance of this being the case is vanishingly small. Provide real code, copy-pasted directly from a real file, and showing real results that demonstrate this behavior. There is no way that IronProfile is so utterly and fundamentally broken that such a simple and basic function doesn't work like this. There's no way that what you've shown us as describing the behavior is -really- what's happening. You seem to be paraphrasing code to illustrate a problem: but that's leaving out what's -really- causing the problem that you think isn't related, but really is. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Wed Feb 10 01:51:32 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Wed, 10 Feb 2010 01:51:32 -0500 Subject: Personal criticisms and logical fallacies In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> Message-ID: <20100210015132.3808f0d5.darcy@druid.net> On Wed, 10 Feb 2010 01:38:50 +0100 "Alf P. Steinbach" wrote: > However, although in this particular case the Ad Hominems constituted logical > fallacies, not all Ad Hominems are logical fallacies. Yes they are. Using the reputation of someone to prove or disprove their claims is a logical fallacy. > For example, if a person is a chronic liar, has a known history of lying, then > that can have a strong bearing on whether the person's claims -- technical or > about other persons -- should be seriously considered[1]. Yes but it's still a fallacy. Taking the author's history into account may be valid for deciding that further investigation is warranted but by itself it does not prove anything about the claims. Suggesting that it does is fallacious. "Bill is a liar therefore his statement is false" is a fallacy. "Bill is a liar so take his claims with a grain of salt" is not. There is another case. "Bill never tells the truth therefore his claim is wrong" is not an ad hominem fallacy. It's a sylogism. It may or may not be correct but if the first statement is true (Bill always lies) then the the conclusion is true. -- 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 howe.steven at gmail.com Wed Feb 10 02:06:24 2010 From: howe.steven at gmail.com (Steven Howe) Date: Tue, 09 Feb 2010 23:06:24 -0800 Subject: Personal criticisms and logical fallacies In-Reply-To: <20100210015132.3808f0d5.darcy@druid.net> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> <20100210015132.3808f0d5.darcy@druid.net> Message-ID: <4B725AF0.9030803@gmail.com> Really, is this a relevant topic on a program mail list? You guys need to get a room and start discussing angel counts on pinheads under the blankets. sph On 02/09/2010 10:51 PM, D'Arcy J.M. Cain wrote: > On Wed, 10 Feb 2010 01:38:50 +0100 > "Alf P. Steinbach" wrote: > >> However, although in this particular case the Ad Hominems constituted logical >> fallacies, not all Ad Hominems are logical fallacies. >> > Yes they are. Using the reputation of someone to prove or disprove > their claims is a logical fallacy. > > >> For example, if a person is a chronic liar, has a known history of lying, then >> that can have a strong bearing on whether the person's claims -- technical or >> about other persons -- should be seriously considered[1]. >> > Yes but it's still a fallacy. Taking the author's history into account > may be valid for deciding that further investigation is warranted but by > itself it does not prove anything about the claims. Suggesting that it > does is fallacious. > > "Bill is a liar therefore his statement is false" is a fallacy. "Bill > is a liar so take his claims with a grain of salt" is not. > > There is another case. "Bill never tells the truth therefore his > claim is wrong" is not an ad hominem fallacy. It's a sylogism. It may > or may not be correct but if the first statement is true (Bill always > lies) then the the conclusion is true. > > From ben+python at benfinney.id.au Wed Feb 10 02:41:53 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 10 Feb 2010 18:41:53 +1100 Subject: Personal criticisms and logical fallacies References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> Message-ID: <87wrylh70e.fsf@benfinney.id.au> "D'Arcy J.M. Cain" writes: > On Wed, 10 Feb 2010 01:38:50 +0100 > "Alf P. Steinbach" wrote: > > However, although in this particular case the Ad Hominems > > constituted logical fallacies, not all Ad Hominems are logical > > fallacies. > > Yes they are. Using the reputation of someone to prove or disprove > their claims is a logical fallacy. The trouble is, the bulk of statements Alf is calling ?ad hominem attack? are, if one actually reads them, a criticism of his person. Not intended as a connecting claim in an argument, but a claim *distinct from* the argument Alf is engaged in. So they're *not intended* to prove or disprove the specific claims that immediately precede them. They're intended, at least partly, to provoke self-reflection on the part of the person criticised and, ideally, an improvement in behaviour. Failure to recognise a criticism as such, and instead repeatedly flinging the term ?ad hominem? around as though it has any bearing, is an example of behaviour that could easily be improved, if only the person engaging in it would stop. -- \ ?You've got to think about big things while you're doing small | `\ things, so that all the small things go in the right | _o__) direction.? ?Alvin Toffler | Ben Finney From apt.shansen at gmail.com Wed Feb 10 02:43:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Tue, 9 Feb 2010 23:43:17 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> Message-ID: <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> On Tue, Feb 9, 2010 at 1:08 PM, Alf P. Steinbach wrote: [abundant snips which do not accurately represent who said what where due to my own laziness] > Not sure, but perhaps it's possible to mail directly to gmane? >>>>> >>>>> Is there *any* problem you don't have a fatuous answer for? >>>> >>> I thought the answer could help. >>> >>> You thought you cold do a bit of ad hominem attack. >>> >>> That's the difference between us. >>> >>> Well, the way I see it, you assumed you knew better than Stephen, and >> insisted on proposing a solution to a problem that he clearly stated he >> had no interest in. >> > > You're going into motivations, that it seems to me that you're projecting, > saying that any helpful suggestion mean that one thinks one knows better and > implies a desire to demonstrate imagined superiority. > > You're trying to portray a helping hand as a negative personal > characteristic of the helper. > > "the only reason that guy tries to help you is because he wishes to show > how superior he (thinks he) is". > > That's your style in a fair number of postings, and now here: > > * ad hominem attack, > I am, frankly, tired of this. Please stop this overly obsessive sensitivity towards what you think are "ad hominem" attacks. Just drop it. Its worthless. It degrades you. Your arguments are frequently nothing more then, "I define the world this way and you do not disagree so I declare your argument invalid". You've dismissed at least one of my arguments with a simple hand-waving of, "That's invalid, cuz." The thing is, there was no basis for 'cuz' beyond "In my own head this is what I think, this is how I'm defining words" The response of others to such arguments has been, "Do you /really/ need to be so absolutely right in everything?!" which is said in frustration, irritation and with deep sighing. And then begins the loud declarations of ad hominem attacks. Its not productive. It doesn't help your case or arguments. Its tired. It doesn't make your case. It doesn't make anyone but you look bad. Every time you go on about, "YOU ARE AD HOMINEM'N ME!", you just make yourself look worse. Yeah. People can be snarky in a community. Maybe... MAYBE... Steve Holden is periodically a little snarky at you. It is not without reason. And your declarations of his ad hominem attacks against you comes off as nothing but base /whining/. Just drop it. Its boring. Also... I'm not quite sure, given that, what the point of the advice was. >> > > There are many people who read just the Usenet group, e.g. via Google > groups. > > When you say you don't understand the point of the advice, you're saying > that > > * those people don't matter, and that > > * it doesn't matter whether they can read Stephen Hansen's articles. > > That's > > * slighting Stephen Hansen, and > > * showing off an extreme ego-centric view of the world, > Please do NOT presume to take up my defense on ANY level. I can handle myself, thank you. I have said as much on two occasions that I don't know why some people seem unable to see my postings on usenet, and that despite this, I don't really care. It is not worth it to me to make my voice known to every possible listener in the world. I don't have sufficient vanity to assume that I need to be heard. I speak when it interests me to speak; and if heard, perhaps I'm listened to. Perhaps they will be helped. Perhaps they will not. Perhaps someone will argue with me. Perhaps we will both benefit from this debate and the exchange of ideas. That's the ideal situation, of course. Discourse and debate leading to new understanding. But I don't need anyone to defend my place in such discourse. I do not want, and utterly reject, anyone else standing up and taking any sort of stand on my behalf related to if someone else has slighted me. If and when I feel that I have been slighted, I will react accordingly. If Steve Holden slighted me in any way (he has not), I am more then capable of saying so on my own. I'd tell the BDFL he was an ass if he were an ass (he is not!) if I thought it was warranted. Thank you, but the value of my contribution to the community is a determination that I will make based on my own interest to share; and a determination those who do read me will make based on their interest to respond. If I needed everyone to hear me, I'd start up a blog and post rants all the time. If I felt that my contribution were not being heard fairly according to its worth, I'd try to take steps to make sure I was. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Wed Feb 10 02:53:53 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 08:53:53 +0100 Subject: Personal criticisms and logical fallacies In-Reply-To: <87wrylh70e.fsf@benfinney.id.au> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> <87wrylh70e.fsf@benfinney.id.au> Message-ID: * Ben Finney: > "D'Arcy J.M. Cain" writes: > >> On Wed, 10 Feb 2010 01:38:50 +0100 >> "Alf P. Steinbach" wrote: >>> However, although in this particular case the Ad Hominems >>> constituted logical fallacies, not all Ad Hominems are logical >>> fallacies. >> Yes they are. Using the reputation of someone to prove or disprove >> their claims is a logical fallacy. > > The trouble is, the bulk of statements Alf is calling ?ad hominem > attack? are, if one actually reads them, a criticism of his person. Not > intended as a connecting claim in an argument, but a claim *distinct > from* the argument Alf is engaged in. That's false. Happily anyone can check back, e.g. up-thread here. Judging by the last few months the number of persons engaging in ad hominem attacks in this group is small, counted on one hand with possibly one finger from the other hand to help. They're very active. But happily, few. However, in the other non-moderated groups I participate in the number of such persons is essentially *zero*, not counting sporadic visits from trolls. > So they're *not intended* to prove or disprove the specific claims that > immediately precede them. They're intended, at least partly, to provoke > self-reflection on the part of the person criticised and, ideally, an > improvement in behaviour. And that's ad hominem, implying unacceptable behavior on my part, which if you could back up you'd cited. > Failure to recognise a criticism as such, and instead repeatedly > flinging the term ?ad hominem? around as though it has any bearing, is > an example of behaviour that could easily be improved, if only the > person engaging in it would stop. Cheers & hth., - Alf From arnodel at googlemail.com Wed Feb 10 02:55:10 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 07:55:10 +0000 Subject: EAFP gone wrong References: Message-ID: Malte Helmert writes: > Arnaud Delobelle wrote: > >> This means that EAFP made me hide a typo which would have been obviously >> detected had I LBYLed, i.e. instead of >> >> try: >> return val.latex() >> except AttributeError: >> ... >> >> do >> >> if hasattr(val, 'latex'): >> return val.latex() >> else: >> ... >> >> >> So was it wrong to say it's EAFP in this case? > > I would say that it's not really the EAFP concept that is problematic > here, but rather that the try block encompasses more code than it > should. Generally try blocks should be as narrow as possible, i.e., they > should contain only the part where you really want to catch a potential > failure. > > "return val.latex()" does two separate things that might fail: the > lookup of val.latex, and the actual method call. If I understood you > correctly, you only want to catch the AttributeError in the "val.latex" > lookup here, and hence I'd say the "correct" application of EAFP here > would be something like: > > try: > foo = val.latex > except AttributeError: > ... > else: > return foo() > > Whether that's any better than LBYL in this particular case is of course > debatable -- one nice thing compared to your LBYL version is that it > doesn't look up val.latex twice upon success. But you could also get > that via the LBYLish: > > latex_method = getattr(val, "latex") > if latex_method: > return latex_method() > Ben, Malte, Thanks for your informative replies. I can now see where my blind spot was and that I never really used EAFP properly before. I think I will go with one of the two solutions above (probably the second) as I feel it's a bit heavy handed to create a closure and perhaps call it every time the latex() function is called. Matthew, You are right. Believe me I am fully aware of this. To my shame I have many thousands lines of Python without any tests in this project and I don't even know where to start... Thanks again, -- Arnaud From alfps at start.no Wed Feb 10 03:13:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 09:13:22 +0100 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> Message-ID: * Stephen Hansen: > > On Tue, Feb 9, 2010 at 1:08 PM, Alf P. Steinbach > wrote: > [abundant snips which do not accurately represent who said what where > due to my own laziness] > > Not sure, but perhaps it's possible to mail directly > to gmane? > > Is there *any* problem you don't have a fatuous answer for? > > I thought the answer could help. > > You thought you cold do a bit of ad hominem attack. > > That's the difference between us. > > Well, the way I see it, you assumed you knew better than > Stephen, and > insisted on proposing a solution to a problem that he clearly > stated he > had no interest in. > > > You're going into motivations, that it seems to me that you're > projecting, saying that any helpful suggestion mean that one thinks > one knows better and implies a desire to demonstrate imagined > superiority. > > You're trying to portray a helping hand as a negative personal > characteristic of the helper. > > "the only reason that guy tries to help you is because he wishes to > show how superior he (thinks he) is". > > That's your style in a fair number of postings, and now here: > > * ad hominem attack, > > > I am, frankly, tired of this. > > Please stop this overly obsessive sensitivity towards what you think are > "ad hominem" attacks. Just drop it. Its worthless. It degrades you. Your > arguments are frequently nothing more then, "I define the world this way > and you do not disagree so I declare your argument invalid". I'm happy that even though that may (with some low probability) be your actual opinion, it's incorrect. > You've > dismissed at least one of my arguments with a simple hand-waving of, > "That's invalid, cuz." That is not a quote of me. It is a lie. > The thing is, there was no basis for 'cuz' beyond > "In my own head this is what I think, this is how I'm defining words" That's also a lie, and it's not a quote of me. And just to be clear, as anyone can see by looking up-thread, generally, contrary to your claims, I give references for whatever that I suspect might be genuinely misunderstood. And so I've done in (nearly) every article in the original thread, especially for the terms, and still people have posted articles apparently mis-interpreting those terms in very non-sensible ways -- one gets tired of that, yes. > The response of others to such arguments has been, "Do you /really/ need > to be so absolutely right in everything?!" which is said in frustration, > irritation and with deep sighing. It's true that that kind of insinuative arguments have been used in this group, yes. It goes to alleged motives and alleged history instead of the technical, that is, it is a purely personal attack. So, ironically, you're here citing one kind of hominem attack -- not exactly clever when you're arguing that such does not occur. > And then begins the loud declarations of ad hominem attacks. > > Its not productive. It doesn't help your case or arguments. > > Its tired. > > It doesn't make your case. It doesn't make anyone but you look bad. > Every time you go on about, "YOU ARE AD HOMINEM'N ME!", you just make > yourself look worse. > > Yeah. People can be snarky in a community. Maybe... MAYBE... Steve > Holden is periodically a little snarky at you. It is not without reason. > And your declarations of his ad hominem attacks against you comes off as > nothing but base /whining/. > > Just drop it. > > Its boring. > > Also... > > I'm not quite sure, given that, what the point of the advice was. > > > There are many people who read just the Usenet group, e.g. via > Google groups. > > When you say you don't understand the point of the advice, you're > saying that > > * those people don't matter, and that > > * it doesn't matter whether they can read Stephen Hansen's articles. > > That's > > * slighting Stephen Hansen, and > > * showing off an extreme ego-centric view of the world, > > > Please do NOT presume to take up my defense on ANY level. > > I can handle myself, thank you. I do offer unsolicited help now and then, as I gave you and for which Steve Holden decided that a bit of personal attack would be suitable. But my help was just as much in order to help others (who can't read your non-propagated articles) as in order to help you personally. That's the spirit of Usenet in many other groups. One just helps out, and often the reaction is a "thank you" instead of an ad hominem attack (as with Steve Holden) or, as in your case, faked quotes and general lies, which is border-line ad hominem. Anyway, please stop post faked quotes and general lies, as you do above. Cheers & hth., - Alf From apt.shansen at gmail.com Wed Feb 10 03:27:24 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 00:27:24 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> Message-ID: <7a9c25c21002100027q377d902cp9578312c7dffe9cc@mail.gmail.com> On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach wrote: > You've dismissed at least one of my arguments with a simple hand-waving of, >> "That's invalid, cuz." >> > > That is not a quote of me. It is a lie. > > > > The thing is, there was no basis for 'cuz' beyond "In my own head this is >> what I think, this is how I'm defining words" >> > > That's also a lie, and it's not a quote of me. > On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach wrote: > > Anyway, please stop post faked quotes and general lies, as you do above. Wow. If that's your argument, I question your sanity. None of the "quotes" were faked. None of the "quotes" were lies. If a message were intended as an actual quotation of another's words, I'd include actual citation. That a message is included in quotation-characters does not make it an actual citation. They are, quite obviously IMHO, paraphrased references to how I evaluate your arguments. The word "cuz" alone seems to make that very, very, very, very, very, very obvious. Get over yourself. Seriously. Quote marks don't make a quotation. If and when I choose to quote you, I will quote you. You will see a line saying, as you see above, "On , Alf wrote:" > >> I can handle myself, thank you. >> > > I do offer unsolicited help now and then, as I gave you and for which Steve > Holden decided that a bit of personal attack would be suitable. > > But my help was just as much in order to help others (who can't read your > non-propagated articles) as in order to help you personally. That's the > spirit of Usenet in many other groups. One just helps out, and often the > reaction is a "thank you" instead of an ad hominem attack (as with Steve > Holden) or, as in your case, faked quotes and general lies, which is > border-line ad hominem. > I reject the assistance of you-- or anyone else-- to make my voice heard. You do not speak for me. You will not speak for me. I speak for myself, thank you. Do not presume to subjugate my voice by defending it for your purposes. Anyway, please stop post faked quotes and general lies, as you do above. I didn't. You're nuts if you think I did. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Wed Feb 10 03:31:43 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Feb 2010 00:31:43 -0800 (PST) Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> <8281270.AG5xCW3FSB@beaureve.gmx.net> Message-ID: On Feb 9, 6:47?pm, Martin Drautzburg wrote: > BTW I am not really trying to add three objects, I wanted a third object > which controls the way the addition is done. Sort of like "/" and "//" > which are two different ways of doing division. That seems like a reasonable use case for a third parameter to __add__, though as others have pointed out the only way to pass the third argument is to call __add__ explicitly. Here's an extract from the decimal module: class Decimal(object): ... def __add__(self, other, context=None): other = _convert_other(other) if other is NotImplemented: return other if context is None: context = getcontext() ... And here's how it's used in the decimal.Context module: class Context(object): ... def add(self, a, b): """Return the sum of the two operands. >>> ExtendedContext.add(Decimal('12'), Decimal('7.00')) Decimal('19.00') >>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4')) Decimal('1.02E+4') """ return a.__add__(b, context=self) -- Mark From martin.hellwig at dcuktec.org Wed Feb 10 03:40:44 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Feb 2010 08:40:44 +0000 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: On 02/10/10 03:36, Tim Chase wrote: > Larry Hudson wrote: >> But a minor rearrangement is simpler, and IMHO clearer: >> >> if 'mystring' not in s: >> print 'not found' >> else: >> print 'foundit' >> print 'processing' > > I've always vacillated on whether that would better be written as Larry > does, or as > > if 'mystring' in s > print 'foundit' > print 'processing' > else: > print 'not found' > > Any thoughts on how others make the choice? > I cases like this when aesthetics are not that much of a deal breaker, I usually put the condition which I think will be the true the majority of the time first. This is not for performance reasons (never tested whether this has any effect) but more documentation like purpose to go from a most expected case to the least expected one. YMMV -- mph From apt.shansen at gmail.com Wed Feb 10 03:41:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 00:41:02 -0800 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002100027q377d902cp9578312c7dffe9cc@mail.gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <7a9c25c21002100027q377d902cp9578312c7dffe9cc@mail.gmail.com> Message-ID: <7a9c25c21002100041n17dbdce4ycce5f9eb974b9940@mail.gmail.com> > > On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach wrote: > >> I do offer unsolicited help now and then, as I gave you and for which >>> Steve Holden decided that a bit of personal attack would be suitable. >> >> Really, I do have to say. It's one thing to say, "Aren't you being rude?" (please note, this is not an actual quotation of any actual person, and I feel it is required I make this disclaimer since you have shown you are unable to differentiate a statement paraphrased in quotation marks from an actual quotation and citation of another's words) It's another thing entirely to decide on your own to be my champion and choose to speak for me in my defense. The former is someone offering unsolicited help; the latter I find more then a little insulting. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Wed Feb 10 03:42:05 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Wed, 10 Feb 2010 00:42:05 -0800 (PST) Subject: Ternary plus References: <1475043.2616QT5JLn@beaureve.gmx.net> <0265924b-3e3c-4c0a-8e0c-993d33b5d0bf@r24g2000yqd.googlegroups.com> <8281270.AG5xCW3FSB@beaureve.gmx.net> Message-ID: <67d10050-7553-4c88-8dbb-f51c19cb2b5e@j31g2000yqa.googlegroups.com> On Feb 10, 8:31?am, Mark Dickinson wrote: > And here's how it's used in the decimal.Context module: Aargh! decimal.Context *class*, not module. And it occurs to me that it would have been cleaner to have Decimal.__add__ call Context.add rather than the other way around. Then Decimal.__add__ could have stayed a two-argument function, as intended. Oh well. -- Mark From klausneuner72 at googlemail.com Wed Feb 10 03:58:37 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Wed, 10 Feb 2010 00:58:37 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> Message-ID: <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> On Feb 9, 11:01?am, Stefan Behnel wrote: > KlausNeuner, 09.02.2010 10:04: > > > my program is supposed to parse files that I have created myself and that > > are on my laptop. It is not supposed to interact with anybody else > > than me. > > Famous last words. > > Stefan All right, I admit that eval() is evil and should never be used. Under no circumstances. (Which is, of course, the reason, why Python has eval().) The same applies to knives. You shouldn't use them. You shouldn't even use them in your own kitchen. A man might enter your kitchen, take your knife away and use it against you. From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 04:28:20 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 10:28:20 +0100 Subject: Programing family In-Reply-To: <00fb7592$0$15628$c3e8da3@news.astraweb.com> References: <4b719209$0$10071$426a34cc@news.free.fr> <00fb7592$0$15628$c3e8da3@news.astraweb.com> Message-ID: <4b727c27$0$10168$426a74cc@news.free.fr> Steven D'Aprano a ?crit : > On Tue, 09 Feb 2010 17:49:21 +0100, Bruno Desthuilliers wrote: > >> Not that much C++ in Python, IMHO. If that's for the OO part, then the >> closer to Python's object model I can think of is javascript. > > I thought that Javascript didn't even have inheritance until recently? If you mean "class inheritance", it's obviously not something you'd expect to find in a prototype based language. But inheritance works with prototypes too. From __peter__ at web.de Wed Feb 10 04:45:37 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Feb 2010 10:45:37 +0100 Subject: Creating formatted output using picture strings Message-ID: python at bdurham.com wrote: > Does Python provide a way to format a string according to a > 'picture' format? > > For example, if I have a string '123456789' and want it formatted > like '(123)-45-(678)[9]', is there a module or function that will > allow me to do this or do I need to code this type of > transformation myself? A basic implementation without regular expressions: >>> def picture(s, pic, placeholder="@"): ... parts = pic.split(placeholder) ... result = [None]*(len(parts)+len(s)) ... result[::2] = parts ... result[1::2] = s ... return "".join(result) ... >>> >>> picture("123456789", "(@@@)-@@-(@@@)[@]") '(123)-45-(678)[9]' Peter From nad at acm.org Wed Feb 10 05:11:59 2010 From: nad at acm.org (Ned Deily) Date: Wed, 10 Feb 2010 02:11:59 -0800 Subject: mac install References: Message-ID: In article , Thomas Nelson wrote: > I downloaded the 3.1.1 dmg from http://www.python.org/download/releases/3.1.1/ > but when I run it I get the error "The folowing install step failed: > run postflight script for python documentation." The bugs list has > this bug at http://bugs.python.org/issue6934 but it's described as > fixed. Is it only fixed for the source version? Where should I go to > install? Unfortunately, there hasn't been a release of Python 3.1 since 3.1.1. On the other hand, the problem isn't critical: it only prevents the installation from creating the .pyc compiled byte-code files for the python files in the standard library. Python 3.1.1 should run just fine, albeit sometimes a bit slower, without them. -- Ned Deily, nad at acm.org From quindennis at grandecom.net Wed Feb 10 05:21:44 2010 From: quindennis at grandecom.net (Quin) Date: Wed, 10 Feb 2010 04:21:44 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Well, PyScripter works find with that code. Furthermore, the un-intellisense in IronPython was problematic, inserting the wrong things, which I had to erase. Also, there were some code constructs IronPython let pass that PyScripter didn't, namely, print(), PyScripter requires the () Something simple, like: n = -1 if n <> -1: print('fell through') falls through to the print. So, I don't know what the problem is with IronPython, perhaps it isn't compatible with Python v3, but on my machine, at least, it doesn't perform. "Steve Holden" wrote in message news:mailman.2272.1265774639.28905.python-list at python.org... > Quin wrote: >> Thanks guys, I'm thinking it's a problem with IronPython. I'm switching >> to PyScripter and will test tomorrow. >> > I'd be very surprised to find that something as basic as this was wrong > with IronPython. Complex commercial software has been built on it, so > there's little question that the platform is sound. > > Are you *sure* you copied and pasted the session you listed? > > regards > Steve > >> "Larry Hudson" wrote in message >> news:ybmdnRFZZ_3nvu_WnZ2dnUVZ_hGdnZ2d at giganews.com... >>> Quin wrote: >>>> s = f.readline() >>>> if 'mystring' in s: print 'foundit' >>>> if 'mystring' not in s: print 'not found' >>>> if 'mystring' in s: >>>> print 'processing' >>>> >>>> this generates output: >>>> not found >>>> processing >>>> >>>> so, it doesn't find the substring, but goes into processing code >>>> anyway. >>>> >>>> This is using IronPython >>> >>> As others have already said, this _does_ work properly. >>> >>> But a minor rearrangement is simpler, and IMHO clearer: >>> >>> if 'mystring' not in s: >>> print 'not found' >>> else: >>> print 'foundit' >>> print 'processing' >>> >>> -=- Larry -=- >> > > > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ > Holden Web LLC http://www.holdenweb.com/ > UPCOMING EVENTS: http://holdenweb.eventbrite.com/ > From jeanmichel at sequans.com Wed Feb 10 05:22:12 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 11:22:12 +0100 Subject: New to Python In-Reply-To: <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <4B7288D4.8010704@sequans.com> Quin wrote: > Thanks guys, I'm thinking it's a problem with IronPython. I'm > switching to PyScripter and will test tomorrow. > > I'm willing to bet money that it is not. If ironPython had a broken if statement, don't you think we would have known, already ? There's a rule when test writing/testing code: "if you think the compiler is wrong, then you are wrong twice." JM From quindennis at grandecom.net Wed Feb 10 05:23:43 2010 From: quindennis at grandecom.net (Quin) Date: Wed, 10 Feb 2010 04:23:43 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Well, now you know! "Jean-Michel Pichavant" wrote in message news:mailman.2286.1265797348.28905.python-list at python.org... > Quin wrote: >> Thanks guys, I'm thinking it's a problem with IronPython. I'm switching >> to PyScripter and will test tomorrow. >> >> > I'm willing to bet money that it is not. If ironPython had a broken if > statement, don't you think we would have known, already ? > > There's a rule when test writing/testing code: > "if you think the compiler is wrong, then you are wrong twice." > > JM From olof.bjarnason at gmail.com Wed Feb 10 05:50:45 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 10 Feb 2010 11:50:45 +0100 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: 2010/2/10 Peter Otten <__peter__ at web.de>: > python at bdurham.com wrote: > >> Does Python provide a way to format a string according to a >> 'picture' format? >> >> For example, if I have a string '123456789' and want it formatted >> like '(123)-45-(678)[9]', is there a module or function that will >> allow me to do this or do I need to code this type of >> transformation myself? > > A basic implementation without regular expressions: > >>>> def picture(s, pic, placeholder="@"): > ... ? ? parts = pic.split(placeholder) > ... ? ? result = [None]*(len(parts)+len(s)) > ... ? ? result[::2] = parts > ... ? ? result[1::2] = s > ... ? ? return "".join(result) > ... >>>> >>>> picture("123456789", "(@@@)-@@-(@@@)[@]") > '(123)-45-(678)[9]' > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > Inspired by your answer here's another version: >>> def picture(s, pic): ... if len(s)==0: return pic ... if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) ... return pic[0]+picture(s, pic[1:]) ... >>> picture("123456789", "(###)-##-(###)[#]") '(123)-45-(678)[9]' >>> -- http://olofb.wordpress.com From jeanmichel at sequans.com Wed Feb 10 05:53:46 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 11:53:46 +0100 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <4B72903A.1030404@sequans.com> Quin wrote: > Well, now you know! > > "Jean-Michel Pichavant" wrote in message > news:mailman.2286.1265797348.28905.python-list at python.org... >> Quin wrote: >>> Thanks guys, I'm thinking it's a problem with IronPython. I'm >>> switching to PyScripter and will test tomorrow. >>> >>> >> I'm willing to bet money that it is not. If ironPython had a broken >> if statement, don't you think we would have known, already ? >> >> There's a rule when test writing/testing code: >> "if you think the compiler is wrong, then you are wrong twice." >> >> JM > All I know is that you are using a python implementation that does not support python 3. No wonder why your py3 code fails. Please do not top post. JM IronPython * Stable Version is 2.0.3 (targeting Python 2.5) * Developers Version is 2.6 Beta 3 (targeting Python 2.6) From fetchinson at googlemail.com Wed Feb 10 06:06:37 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 10 Feb 2010 12:06:37 +0100 Subject: ANN: obfuscate In-Reply-To: <871vgtj31f.fsf@benfinney.id.au> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> Message-ID: >> All algorithms in obfuscate are obsolete, insecure and only >> interesting for people *that* want to get well educated in the history >> of encryption. > > Not true. Another use case is suggested by the chosen name for the > library: to obfuscate text against casual human reading, while not > making it at all difficult to decrypt by people who are motivated to do > so. > > The classic example is rot-13 encryption of text in internet messages; > it would be a failure of imagination to suggest there are not other, > similar use cases. I fully agree. Judging by the posts on c.l.p the need for simple obfuscation regularly comes up. I also posted something not so long ago and got all sorts of useful advice, a package here, a module there, etc. It also turned out that everybody mostly writes his/her own obfuscation routine. That is why I suggested that perhaps if the code base stabilizes an inclusion into the stdlib could be discussed. I'm not sure it really needs to go there but if it turns out that as many people need this kind of stuff as I imagine it, well, then we have enough use cases for sure. >> Grab pycrypto, m2crypto or one of the other packages if you need a >> minimum amount of security. > > Agreed. However, for cases that *don't* need security from determined > attackers, I don't think those obviate the usefulness of this library. Exactly. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From simon at brunningonline.net Wed Feb 10 06:12:26 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Feb 2010 11:12:26 +0000 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: <8c7f10c61002100312j39c775ddi736af6693e1e2549@mail.gmail.com> On 10 February 2010 03:36, Tim Chase wrote: > Any thoughts on how others make the choice? There are two criteria that I use here. I'll often tend towards the positive test; it's just that little bit easier to comprehend, I think. On the other hand, if one case is overwhelmingly more common, I'll usually put that first even if it does mean using a negative test. I'm not buying the short-case-first argument. If the code in a case block is long enough for that to matter, it really belongs in a function of its own anyway. -- Cheers, Simon B. From simon at brunningonline.net Wed Feb 10 06:23:01 2010 From: simon at brunningonline.net (Simon Brunning) Date: Wed, 10 Feb 2010 11:23:01 +0000 Subject: ANN: obfuscate In-Reply-To: <871vgtj31f.fsf@benfinney.id.au> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> Message-ID: <8c7f10c61002100323v1650769dob3d0411a0c5b08c8@mail.gmail.com> On 10 February 2010 01:24, Ben Finney wrote: > The classic example is rot-13 encryption of text in internet messages; > it would be a failure of imagination to suggest there are not other, > similar use cases. That's built-in: >>> "Hello World!".encode('rot-13') 'Uryyb Jbeyq!' -- Cheers, Simon B. From mail at timgolden.me.uk Wed Feb 10 06:27:48 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 10 Feb 2010 11:27:48 +0000 Subject: ANN: obfuscate In-Reply-To: <8c7f10c61002100323v1650769dob3d0411a0c5b08c8@mail.gmail.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> <8c7f10c61002100323v1650769dob3d0411a0c5b08c8@mail.gmail.com> Message-ID: <4B729834.7050606@timgolden.me.uk> On 10/02/2010 11:23, Simon Brunning wrote: > "Hello World!".encode('rot-13') Not any more! Python 3.1.1 (r311:74483, Aug 17 2009, win32 Type "help", "copyright", "credits" or >>> "Hello World!".encode('rot-13') Traceback (most recent call last): File "", line 1, in LookupError: unknown encoding: rot-13 >>> TJG From alfps at start.no Wed Feb 10 06:45:47 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 12:45:47 +0100 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: * Olof Bjarnason: > 2010/2/10 Peter Otten <__peter__ at web.de>: >> python at bdurham.com wrote: >> >>> Does Python provide a way to format a string according to a >>> 'picture' format? >>> >>> For example, if I have a string '123456789' and want it formatted >>> like '(123)-45-(678)[9]', is there a module or function that will >>> allow me to do this or do I need to code this type of >>> transformation myself? >> A basic implementation without regular expressions: >> >>>>> def picture(s, pic, placeholder="@"): >> ... parts = pic.split(placeholder) >> ... result = [None]*(len(parts)+len(s)) >> ... result[::2] = parts >> ... result[1::2] = s >> ... return "".join(result) >> ... >>>>> picture("123456789", "(@@@)-@@-(@@@)[@]") >> '(123)-45-(678)[9]' >> >> Peter >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Inspired by your answer here's another version: > >>>> def picture(s, pic): > ... if len(s)==0: return pic > ... if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) > ... return pic[0]+picture(s, pic[1:]) > ... >>>> picture("123456789", "(###)-##-(###)[#]") > '(123)-45-(678)[9]' I learned a bit by Peter Otten's example; I would have gotten to that notation sooner or later, but that example made it 'sooner' :-). I think your version is cute. I'd probably write it in a non-recursive way, though, like def picture( s, pic, placeholder = "@" ): result = "" char_iter = iter( s ) for c in pic: result += c if c != placeholder else next( char_iter ) return result Of course this is mostly personal preference, but there is also a functional difference. With your version an IndexError will be raised if there are too /many/ characters in s, while too few characters in s will yield "#" in the result. With my version a StopIteration will be raised if there are to /few/ characters in s, while too many characters will just have the extraneous chars ignored. Cheers, - Alf From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 06:55:44 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 12:55:44 +0100 Subject: use strings to call functions In-Reply-To: <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> Message-ID: <4b729eb2$0$18397$426a74cc@news.free.fr> Klaus Neuner a ?crit : > > All right, I admit that eval() is evil and should never be used. Can you tell the difference between your above statement and the following: """ eval() is potentially dangerous and can make code harder to debug. 99% of the proposed use case for eval() are covered by simpler, less dangerous and easier to understand solutions, so the GoodPractice(tm) is to favor these solutions and only use eval() - with appropriate care - for the remaining 1% _real_ use case. """ If you can't tell the difference, then you're about as (im)mature as my 13 year old son and it might eventually be time to grow up. > The same applies to knives. You shouldn't use them. You > shouldn't even use them in your own kitchen. A man might enter your > kitchen, take your knife away and use it against you. Knives - specially the kind I use in my kitchen - are indeed potentially dangerous, and I indeed had to educate my son so he wouldn't do anything stupid with them - like pointing a knife at someone, running across the house with a knife in his hand, or using them instead of a more appropriate tool. The probability that someone will enter your kitchen and use one of your knives against you, while not null, are low enough to be ignored IMHO. I whish I could say the same about script kiddies or more educated (and dangerous) bad guys trying to attack our servers. But you obviously never had to neither fix a compromised server nor raise a kid - else you'd now better. Hopefully you didn't raise my kid - now I just pray none of your code will ever run on our servers. From martin.hellwig at dcuktec.org Wed Feb 10 06:59:40 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 10 Feb 2010 11:59:40 +0000 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: On 02/10/10 10:53, Jean-Michel Pichavant wrote: > Quin wrote: >> Well, now you know! >> > > All I know is that you are using a python implementation that does not > support python 3. No wonder why your py3 code fails. > You knew you known, you know :-) -- mph From snarks at gmail.com Wed Feb 10 07:24:36 2010 From: snarks at gmail.com (Phil Hibbs) Date: Wed, 10 Feb 2010 04:24:36 -0800 (PST) Subject: Generic spreadsheet interface Message-ID: <3acdf3a7-e2eb-4a9a-bc89-7e285073a9c9@o28g2000yqh.googlegroups.com> I've currently got an Excel spreadsheet with loads of VBA, and I've been thinking of porting it to OpenOffice.org. "This is a Python list!" I hear you cry, but bear with me - rather than just re-writing all the VBA code in OOo script, I thought, "why not make it generic - so it can work with Excel or OOo?" - then I thought of Python. Python can interface with both, but the specifics of how to interface with each are very different. What would be nice is a generic wrapper class that can work with either. Has anyone come across anything like that? Phil Hibbs. From fuzzyman at gmail.com Wed Feb 10 07:28:02 2010 From: fuzzyman at gmail.com (Fuzzyman) Date: Wed, 10 Feb 2010 04:28:02 -0800 (PST) Subject: Dreaming of new generation IDE References: <11ef42cc-dc97-4f2e-8d6b-88cbe1abed8b@v37g2000prh.googlegroups.com> Message-ID: On Feb 3, 7:38?pm, Phlip wrote: > On Feb 3, 10:57?am, Adam Tauno Williams > wrote: > > > > Current editors suck because they can't see into the code and browse > > > it - unless it's so statically typed it's painful. > > > ? ?I edit Python in MonoDevelop ?2.2; ?and I can browse my file, > > classes, etc... ?So I don't know what you mean by "can't see into the > > code". ?It works pretty well. > > > Of course it can't tell that I've set x = {an integer}, as that only > > happens at runtime. > > > > That's why I wrote this: > > >http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_ed... > > You just said that your code browsing "works pretty well, except when > it doesn't". > > Hence my blog entry. If your editor analyzed your code at runtime, > instead of just static analysis, then it could see that x = an > integer, or an object, no matter how dynamic your language. > The Wingware Wing IDE has an integrated debugger. The IDE does type inferencing through static analysis to provide autocomplete and code navigation features. If you run the code under the debugger it will also use 'actual' type information to augment the static analysis. Michael Foord -- http://www.voidspace.org.uk/ From mailings at julianmoritz.de Wed Feb 10 07:40:39 2010 From: mailings at julianmoritz.de (Julian) Date: Wed, 10 Feb 2010 04:40:39 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> <4B6B5E72.20702@stoneleaf.us> <037c8d60$0$1292$c3e8da3@news.astraweb.com> Message-ID: hello there, thanks everyone for that many answers! I'm lying in bed with a bad cold, so I'll get through all the posts on the weekend. regards Julian From olof.bjarnason at gmail.com Wed Feb 10 07:46:31 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Wed, 10 Feb 2010 13:46:31 +0100 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: 2010/2/10 Alf P. Steinbach : > * Olof Bjarnason: >> >> 2010/2/10 Peter Otten <__peter__ at web.de>: >>> >>> python at bdurham.com wrote: >>> >>>> Does Python provide a way to format a string according to a >>>> 'picture' format? >>>> >>>> For example, if I have a string '123456789' and want it formatted >>>> like '(123)-45-(678)[9]', is there a module or function that will >>>> allow me to do this or do I need to code this type of >>>> transformation myself? >>> >>> A basic implementation without regular expressions: >>> >>>>>> def picture(s, pic, placeholder="@"): >>> >>> ... ? ? parts = pic.split(placeholder) >>> ... ? ? result = [None]*(len(parts)+len(s)) >>> ... ? ? result[::2] = parts >>> ... ? ? result[1::2] = s >>> ... ? ? return "".join(result) >>> ... >>>>>> >>>>>> picture("123456789", "(@@@)-@@-(@@@)[@]") >>> >>> '(123)-45-(678)[9]' >>> >>> Peter >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >> >> Inspired by your answer here's another version: >> >>>>> def picture(s, pic): >> >> ... ? if len(s)==0: return pic >> ... ? if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) >> ... ? return pic[0]+picture(s, pic[1:]) >> ... >>>>> >>>>> picture("123456789", "(###)-##-(###)[#]") >> >> '(123)-45-(678)[9]' > > I learned a bit by Peter Otten's example; I would have gotten to that > notation sooner or later, but that example made it 'sooner' :-). > > I think your version is cute. Thanks! Here's another version (maybe a little more readable?): def first(s): return s[0] def rest(s): return s[1:] def picture(s, pic): if not s: return pic if first(pic)=='#': return first(s)+picture(rest(s), rest(pic)) return first(pic)+picture(s, rest(pic)) > > I'd probably write it in a non-recursive way, though, like > > ? ?def picture( s, pic, placeholder = "@" ): > ? ? ? ?result = "" > ? ? ? ?char_iter = iter( s ) > ? ? ? ?for c in pic: > ? ? ? ? ? ?result += c if c != placeholder else next( char_iter ) > ? ? ? ?return result > > Of course this is mostly personal preference, but there is also a functional > difference. > > With your version an IndexError will be raised if there are too /many/ > characters in s, while too few characters in s will yield "#" in the result. > > With my version a StopIteration will be raised if there are to /few/ > characters in s, while too many characters will just have the extraneous > chars ignored. > > > Cheers, > > - Alf > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://olofb.wordpress.com From klausneuner72 at googlemail.com Wed Feb 10 08:24:33 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Wed, 10 Feb 2010 05:24:33 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> <4b729eb2$0$18397$426a74cc@news.free.fr> Message-ID: On Feb 10, 12:55?pm, Bruno Desthuilliers wrote: > KlausNeunera ?crit : > > > > > All right, I admit that eval() is evil and should never be used. > > Can you tell the difference between your above statement and the following: As already pointed out in my second post (though perhaps not explicitly enough), I like the getattr-stuff better than eval(). That is why I will not use eval(). I don't have a reason to use eval(). All I wanted to say is this: If there are no circumstances at all under which eval() can reasonably be used, then it should not be part of Python. As it is part of Python (and as Python is a carefully designed language), there will most probably some situations in which one might want to use it. From almar.klein at gmail.com Wed Feb 10 08:29:42 2010 From: almar.klein at gmail.com (Almar Klein) Date: Wed, 10 Feb 2010 14:29:42 +0100 Subject: ANN: visvis v1.1 Message-ID: Hi all, I am pleased to announce version 1.1 of visvis, a Python visualization library for of 1D to 4D data. Website: http://code.google.com/p/visvis/ Discussion group: http://groups.google.com/group/visvis/ Documentation: http://code.google.com/p/visvis/wiki/Visvis_basics === Description === Visvis is a pure Python visualization library that uses OpenGl to display 1D to 4D data; it can be used from simple plotting tasks to rendering 3D volumetric data that moves in time. Visvis can be used in Python scripts, interactive Python sessions (as with IPython) and can be embedded in applications. Visvis employs an object oriented structure; each object being visualized (e.g. a line or a texture) has various properties that can be modified to change its behavior or appearance. A Matlab-like interface in the form of a set of functions allows easy creation of these objects (e.g. plot(), imshow(), volshow()). === Changes === A complete list can be found at http://code.google.com/p/visvis/wiki/releaseNotes. - Colormaps are now supported for texture objects. A colorbar and colormapEditor wibject are also available. - The performance of rendering 3D volumes has significantly improved. A new shader (raycast) is also available). - Fonts are rendered more smoothly and faster. - Data for textures is automatically padded to a factor two if necessary, and down-sampled if too large to fit in OpenGl memory. - Visvis now works for any OpenGl version from OpenGl 1.1 (some features might not be supported for lower versions though). Regards, Almar -------------- next part -------------- An HTML attachment was scrubbed... URL: From ptmcg at austin.rr.com Wed Feb 10 08:37:22 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 10 Feb 2010 05:37:22 -0800 (PST) Subject: How to measure elapsed time under Windows? References: Message-ID: <87404349-5d3a-4396-aeff-60edc14a506a@f8g2000yqn.googlegroups.com> On Feb 10, 2:24?am, Dennis Lee Bieber wrote: > On Tue, 9 Feb 2010 21:45:38 +0000 (UTC), Grant Edwards > declaimed the following in > gmane.comp.python.general: > > > Doesn't work. ?datetime.datetime.now has granularity of > > 15-16ms. > > > Intervals much less that that often come back with a delta of > > 0. ?A delay of 20ms produces a delta of either 15-16ms or > > 31-32ms > > ? ? ? ? WinXP uses an ~15ms time quantum for task switching. Which defines > the step rate of the wall clock output... > > http://www.eggheadcafe.com/software/aspnet/35546579/the-quantum-was-n...http://www.eggheadcafe.com/software/aspnet/32823760/how-do-you-set-ti... > > http://www.lochan.org/2005/keith-cl/useful/win32time.html > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ Gabriel Genellina reports that time.clock() uses Windows' QueryPerformanceCounter() API, which has much higher resolution than the task switcher's 15ms. QueryPerformanceCounter's resolution is hardware-dependent; using the Win API, and a little test program, I get this value on my machine: Frequency is 3579545 ticks/sec Resolution is 0.279365114840015 microsecond/tick -- Paul From roy at panix.com Wed Feb 10 08:38:18 2010 From: roy at panix.com (Roy Smith) Date: Wed, 10 Feb 2010 08:38:18 -0500 Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: In article , Tim Chase wrote: > Larry Hudson wrote: > > But a minor rearrangement is simpler, and IMHO clearer: > > > > if 'mystring' not in s: > > print 'not found' > > else: > > print 'foundit' > > print 'processing' > > I've always vacillated on whether that would better be written as > Larry does, or as > > if 'mystring' in s > print 'foundit' > print 'processing' > else: > print 'not found' > > removing the "not" from the condition. I admit I choose one over > the other based on some gut-feeling aesthetic that I can't really > nail down. I think one of my major influencing factors revolves > around the negative "not" portion having one or two lines and the > positive portion having a large block of code. If the > code-blocks are more equal in size, I tend to use "if > {positive}", but if the negative "not" section is only 1-2 lines, > I tend to do as Larry writes and make it harder to miss by using > "if {negative}". Otherwise the "if {positive}...else" can end up > sufficiently distant from the "if" that it's easy to miss. > > Any thoughts on how others make the choice? > > -tkc In general, I try to avoid negation, because it makes things harder to understand. When you write: if not foo: blah else: blah-blah the else clause is executed if "not foo is not true". That quickly gets confusing. As for the code blocks being so large that the else becomes distant from the condition, that smells like the two codeblocks want to be refactored into distinct functions: if foo: do_one_thing() else: do_something_else() It's not always practical, but my first reaction would be to try that and see if it works. From catonano at gmail.com Wed Feb 10 08:45:49 2010 From: catonano at gmail.com (catonano) Date: Wed, 10 Feb 2010 05:45:49 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: Vladimir, On Feb 3, 12:10?pm, Vladimir Ignatov wrote: > Hello, > > I am sitting here for quite some time, but usually keep silent ;-) I > Finally I develop a feeling that strong instrumentation / tools can > bring us the best of two worlds. That I am dreaming on is an absolute > new type/class of IDE suitable for Python and potentially for other > dynamic-type languages. Instead of current text-oriented IDEs, it > should be a database-centric and resemble current CAD systems instead > of being just "fancy text editor". Source text should be an output > product of that CAD and not a "source material" itself. I don't know CAD systems, but I want to share my comments about this. I self learned to program with Squeak Smalltalk at 17. Later, I worked with VisualAge for Java, that was a Smalltalk IDE applied to Java. Now, I can tell you that in Smalltalk IDEs the code is not written in files. It's stored in a thing called "image". You have these frames, in the first frame you have the classes, in the second frame you have the child classes and in the third frame you have the methods of the child class you selected. A bigger frame showed the code of the single method you had selected. You modified the method, hit ctrl-s and it was COMPILED and saved in the image. You had a frame in which you could interactively call your objects, some of them represented things that were "showable" on the monitor and you could see these things pop up as you instantiated them. Then, you had some specialized browsers in which you could search, for example, all the places a method was called in (a thing I have difficulties with, in python, today) VisualAge had its own management version system such that EVERY TIME I saved a method, it became a VERSION and there was a specialized browser for browsing the versions (the image tended to grow, that's it) while the regular browser defaulted on the last version and there was a tool for freezing a version as a milestone. Today, I tried to understand the twisted.web.client code and I found 3 methods I couldn't find by who were called. I asked on the mailing list and they suggested me where they were called and that the tool for such thing is "grep". So, you grep, you get a list of files, you open each one of them and keep scrolling and switching from one file to another... endlessly. Maybe I'm getting old, but I tend to get lost in the process. I can't believe the code editing situation today is in a such sorry state. Is this what you meant ? If it's this, then it's not experimental at all, it's been done already and been put apart. Crap won :-( You write: > Instead of current text-oriented IDEs, it > should be a database-centric well, it seems you agree with Alan Kay, (the Smalltalk inventor) when he wrote that programming is NOT glorified text editing. He called it "direct manipulation" every method was a live thing you could send messages to and the source code that implemented it was just an attribute of the method. So you could have had a World Of Warcraft like interface, to manipulate your methods. You know what I'm doing now ? I'm drawing the map of twisted.web.client on a paper with a pencil :-( Bye Catonano From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 08:51:19 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 14:51:19 +0100 Subject: use strings to call functions In-Reply-To: References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> <4b729eb2$0$18397$426a74cc@news.free.fr> Message-ID: <4b72b9c8$0$8274$426a74cc@news.free.fr> Klaus Neuner a ?crit : > On Feb 10, 12:55 pm, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> KlausNeunera ?crit : >> >> >> >>> All right, I admit that eval() is evil and should never be used. >> Can you tell the difference between your above statement and the following: > > As already pointed out in my second post (though perhaps not > explicitly enough), Or perhaps is it me that failed to re-read a bit more of the thread before answering - I obviously missed the irony (and made an a... of myself), sorry :-/ > All > I wanted to say is this: If there are no circumstances at all under > which eval() can reasonably be used, then it should not be part of > Python. As it is part of Python (and as Python is a carefully designed > language), there will most probably some situations in which one might > want to use it. Indeed. From duncan.booth at invalid.invalid Wed Feb 10 08:56:03 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Feb 2010 13:56:03 GMT Subject: Modifying Class Object References: Message-ID: "Alf P. Steinbach" wrote: >> In CPython objects once created remain in the same memory location >> (and their id is their address). Compare that to IronPython where the >> objects themselves can move around in memory so they have no fixed >> address. Try comparing the IronPython implementation to C pointers >> and you'll cause a lot of confusion. e.g. someone might think the >> id() value is in some way related to an address. > > Did you /read/ what you quoted? > > >> Ruby implements integers without using any pointers at all: there's >> nothing in the Python specification which prevents a Python >> implementation doing the same for small integers, in fact I believe >> it has been tried but wasn't found to improve performance. > > All theree of your points about Python are wrong; I don't know about > the Ruby point. Would you care to expand upon your claim that my three points about Python are wrong? Are you saying that CPyhton objects move around, or that IronPython objects are fixed to a single memory location or that their id is related to their address? Clue here: IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082 Type "help", "copyright", "credits" or "license" for more information. >>> x = 42 >>> id(x) 43 >>> y = 43 >>> id(y) 44 >>> z = "whatever" >>> id(z) 45 -- Duncan Booth http://kupuguy.blogspot.com From quindennis at grandecom.net Wed Feb 10 08:59:19 2010 From: quindennis at grandecom.net (Quin) Date: Wed, 10 Feb 2010 07:59:19 -0600 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: You know, Jack, that was the point of my original post: to determine why things weren't working. Do you still want to bet money that it is? I can screenshot you TD. "Jean-Michel Pichavant" wrote in message news:mailman.2288.1265799238.28905.python-list at python.org... > Quin wrote: >> Well, now you know! >> >> "Jean-Michel Pichavant" wrote in message >> news:mailman.2286.1265797348.28905.python-list at python.org... >>> Quin wrote: >>>> Thanks guys, I'm thinking it's a problem with IronPython. I'm >>>> switching to PyScripter and will test tomorrow. >>>> >>>> >>> I'm willing to bet money that it is not. If ironPython had a broken if >>> statement, don't you think we would have known, already ? >>> >>> There's a rule when test writing/testing code: >>> "if you think the compiler is wrong, then you are wrong twice." >>> >>> JM >> > > All I know is that you are using a python implementation that does not > support python 3. No wonder why your py3 code fails. > > Please do not top post. > > JM > > > IronPython > > * Stable Version is 2.0.3 (targeting Python 2.5) > * Developers Version is 2.6 Beta 3 (targeting Python 2.6) > From malkarouri at gmail.com Wed Feb 10 08:59:41 2010 From: malkarouri at gmail.com (Muhammad Alkarouri) Date: Wed, 10 Feb 2010 05:59:41 -0800 (PST) Subject: Function attributes Message-ID: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Hi everyone, What is the simplest way to access the attributes of a function from inside it, other than using its explicit name? In a function like f below: def f(*args): f.args = args print args is there any other way? I am guessing the next question will be: should I really care? It just feels like there should be a way, but I am not able to verbalise a valid one at the moment, sorry. Regards, Muhammad Alkarouri From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 09:16:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 14:16:46 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> Message-ID: <0382abea$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 09:13:22 +0100, Alf P. Steinbach wrote: >> You've >> dismissed at least one of my arguments with a simple hand-waving of, >> "That's invalid, cuz." > > That is not a quote of me. It is a lie. Alf, although your English in this forum has been excellent so far, I understand you are Norwegian, so it is possible that you aren't a native English speaker and possibly unaware that quotation marks are sometimes ambiguous in English. While it is true that quoted text is officially meant to indicate a direct quote, it is also commonly used in informal text to indicate a paraphrase. (There are other uses as well, but they don't concern us now.) Unfortunately, this means that in informal discussions like this it is sometimes difficult to distinguish a direct quote from a paraphrase, except by context. In context, as a native speaker, I can assure you that Stephen Hansen's use of quotation marks is a paraphrase and not meant to be read as a direct quote. As a paraphrase, it's not a *lie* -- it should be read as Stephen's *opinion* of your actions, not a direct quote. Stephen might, or might not, be *mistaken*, but it's unlikely he's actively lying. Arguing pedantically that you didn't write those exact words won't win you any friends or supporters. You can choose to defend yourself against a gross misrepresentation of what you actually said; or you can accept that it captures the spirit (but not the letter) of your words; or you can choose a middle position, and accept that even if it is not a 100% accurate representation of your statements, perhaps it is 90% accurate, or 10%, or 50%. The exact amount doesn't really matter, and will be subjective, and frankly I don't care. But whatever degree you choose to accept, it is obvious that a number of people are not just being annoyed by your behaviour, but they are annoyed enough to publicly chastise you for it. That includes Steve Holden, who is usually far more even-tempered than (e.g.) me. Without necessarily suggesting that you are 100% to blame for the antagonism, its unlikely that so many disparate individuals are all 100% mistaken. As you say, the public record is there for anyone who wishes to read the history. Believe me Alf, the fact that people are taking the time to try to argue with you instead of just kill-filing you is a compliment. -- Steven From waku at idi.ntnu.no Wed Feb 10 09:33:50 2010 From: waku at idi.ntnu.no (waku) Date: Wed, 10 Feb 2010 06:33:50 -0800 (PST) Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> Message-ID: <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> On Feb 9, 10:41?pm, Jonathan Gardner wrote: > On Feb 9, 1:51?am, waku wrote: > > > 'stupid', 'wrong', 'deficient', 'terrible', ... ?you're using strong > > words instead of concrete arguments, it might intimidate your > > opponents, but is hardly helpful in a fair discussion. > > In today's day and age, I don't know how a text editor which cannot do > simple indentation can be considered anything but "stupid", "wrong", > "deficient", and "terrible". There is simply no excuse for this kind > of behavior on the part of the text editor. i thought we were not discussing text editors, why should you insist so much on diverting attention from the issue of a programmer being *forced* to keep perfect indentation to the issue of an editor doing autoindent or the like. > > I mean, how long has vi had the auto indent feature? How many decades > has emacs supported the same? This isn't new technology, or difficult > technology to implement. It's not even non-standard anymore. Heck, far > more advanced features, such as syntax highlighting, are standard in > all text editors. wow! and then, back to the issue of enforced indentation in python? > Your problem is you're using something like Windows Notepad to edit > your code. thin ice! you haven't got the faintest idea of what i use to edit my code, do you. Windows Notepad is a terrible tool for writing anything, > let alone writing code. Why in the world would any programming > language adapt itself to the mental deficiencies of Windows Notepad? I > mean, if you were an artist, would you use MS Paint to do anything > serious? If you did, would you complain that the art world has a > problem because they don't accept your paintings? > > I strongly suggest you download one of the *hundreds* of free text > editors available for the Windows platform that give you the > indentation features you so sorely lack. I suggest ViM, though it has > a steep learning curve. listen to what people say before responding, and stop showing off. again, you haven't used a single reasonable argument here. vQ From __peter__ at web.de Wed Feb 10 09:35:57 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 10 Feb 2010 15:35:57 +0100 Subject: New to Python References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: Quin wrote: > You know, Jack, that was the point of my original post: to determine why > things weren't working. Do you still want to bet money that it is? I can > screenshot you TD. You haven't posted the complete script, and you haven't given a thorough description how you invoke that script. To help us find an explanation for your problem and a possible fix please make the script as small as you can while preserving its very strange behaviour, open a DOS window and invoke the Ironpython interpreter manually on the command line. Finally copy and paste the output and the complete script and post it here again. Peter From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 09:36:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 14:36:32 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: <0382b08c$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? In a function like f > below: > > def f(*args): > f.args = args > print args > > is there any other way? Not built-in. > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a valid > one at the moment, sorry. I completely agree with you. It is a wart that functions are only able to refer to themselves by name, because if the name changes, things break. Consider: old_f = f # save the old version of the function def f(x): return old_f(x+1) # make a new function and call it f This won't work correctly, because old_f still tries to refer to itself under the name "f", and things break very quickly. -- Steven From krister.svanlund at gmail.com Wed Feb 10 09:46:00 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Wed, 10 Feb 2010 15:46:00 +0100 Subject: Function attributes In-Reply-To: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: <2cf430a61002100646k557abc9dm73212357d2d3dad3@mail.gmail.com> On Wed, Feb 10, 2010 at 2:59 PM, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): > ? ?f.args = args > ? ?print args > > is there any other way? > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a > valid one at the moment, sorry. > > Regards, > > Muhammad Alkarouri > -- > http://mail.python.org/mailman/listinfo/python-list > This sounds like something you shouldn't be doing. You should probably use a class instead. (Sending again to get it on the list >_<) From klausneuner72 at googlemail.com Wed Feb 10 09:49:37 2010 From: klausneuner72 at googlemail.com (Klaus Neuner) Date: Wed, 10 Feb 2010 06:49:37 -0800 (PST) Subject: use strings to call functions References: <134f2422-7a28-4188-afa3-9fefa9c09059@d27g2000yqn.googlegroups.com> <0efe23a6-b16d-4f92-8bc0-12d056bf599d@z26g2000yqm.googlegroups.com> <77799a8f-da82-4e78-896e-10ebc018b129@d27g2000yqn.googlegroups.com> <4b713260$0$6574$9b4e6d93@newsspool3.arcor-online.net> <9601ab59-87f2-4f39-9c7e-0efb5e6398e6@36g2000yqu.googlegroups.com> <4b729eb2$0$18397$426a74cc@news.free.fr> <4b72b9c8$0$8274$426a74cc@news.free.fr> Message-ID: > Or perhaps is it me that failed to re-read a bit more of the thread > before answering - I obviously missed the irony (and made an a... of > myself), sorry :-/ There is nothing to be sorry about. I am grateful to all participants of this thread. I know a lot more about Python than before. From steve at holdenweb.com Wed Feb 10 09:51:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 09:51:11 -0500 Subject: Python and Ruby In-Reply-To: <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> Message-ID: waku wrote: > On Feb 9, 10:41 pm, Jonathan Gardner > wrote: >> On Feb 9, 1:51 am, waku wrote: >> >>> 'stupid', 'wrong', 'deficient', 'terrible', ... you're using strong >>> words instead of concrete arguments, it might intimidate your >>> opponents, but is hardly helpful in a fair discussion. >> In today's day and age, I don't know how a text editor which cannot do >> simple indentation can be considered anything but "stupid", "wrong", >> "deficient", and "terrible". There is simply no excuse for this kind >> of behavior on the part of the text editor. > > i thought we were not discussing text editors, why should you insist > so much on diverting attention from the issue of a programmer being > *forced* to keep perfect indentation to the issue of an editor doing > autoindent or the like. > It's as sensible to complain about people being "*forced* to keep perfect indentation" as it is to complain about people being *forced* to use braces to delimit code blocks. This is called "syntax", and it's a part of the language, so get over it - this aspect of Python has been present in the language since its inception, and it isn't going to change. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From jeanmichel at sequans.com Wed Feb 10 09:54:37 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 15:54:37 +0100 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <4B72C8AD.2060203@sequans.com> Quin wrote: > You know, Jack, that was the point of my original post: to determine > why things weren't working. Do you still want to bet money that it > is? I can screenshot you TD. > Another flaming war starting... IronPython implements python 2.5 and you're still complaining about your py3 code not working. Try your code in a ruby shell, and tell the ruby community that their intepreter cannot even handle an if statement. Feel free to put my mail address in cc. So to be clear, IronPython can properly handle if statements. I'll bet all your money on that. Jack From visiblelight at gmail.com Wed Feb 10 09:59:54 2010 From: visiblelight at gmail.com (Vision) Date: Wed, 10 Feb 2010 06:59:54 -0800 (PST) Subject: looking for some libraries Message-ID: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> hi all, I am doing some stuffs with some software, which has similar layout like this: Editbox________1 Editbox________2 Editbox________3 _OK_ _______________ | output | | output | | output | | output | | output | -------------------------- What I need to do is to fill the edit boxes, then press the OK button, then I will get some output text below. This is tedious since I have lots of entries to deal with. So I am trying to write some scripts to handle this. And I wonder if there is any library available for me to simplify the process? Thanks! From jjposner at optimum.net Wed Feb 10 10:08:47 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 10:08:47 -0500 Subject: Function attributes In-Reply-To: <0382b08c$0$1277$c3e8da3@news.astraweb.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B72CBFF.9020500@optimum.net> On 2/10/2010 9:36 AM, Steven D'Aprano wrote: > On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > >> Hi everyone, >> >> What is the simplest way to access the attributes of a function from >> inside it, other than using its explicit name? In a function like f >> below: >> >> def f(*args): >> f.args = args >> print args >> >> is there any other way? > > Not built-in. > > >> I am guessing the next question will be: should I really care? It just >> feels like there should be a way, but I am not able to verbalise a valid >> one at the moment, sorry. > > I completely agree with you. It is a wart that functions are only able to > refer to themselves by name, because if the name changes, things break. > Consider: > > old_f = f # save the old version of the function > > def f(x): > return old_f(x+1) # make a new function and call it f > > This won't work correctly, because old_f still tries to refer to itself > under the name "f", and things break very quickly. They didn't break immediately for me -- what am I missing?: #------------------- def f(): return "old func" g = f print "name attr of f:", f.__name__ print "name attr of g:", g.__name__ def f(): return "new func" print "name attr of f:", f.__name__ print "name attr of g:", g.__name__ print "*** calling function currently named f:" print f() print "*** calling function currently named g:" print g() #------------------- program output (Python 2.6.4): name attr of f: f name attr of g: f name attr of f: f name attr of g: f *** calling function currently named f: new func *** calling function currently named g: old func -John From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 10 10:24:56 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 10 Feb 2010 16:24:56 +0100 Subject: Function attributes In-Reply-To: <4B72CBFF.9020500@optimum.net> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> Message-ID: <4b72cfb9$0$30354$426a74cc@news.free.fr> John Posner a ?crit : > On 2/10/2010 9:36 AM, Steven D'Aprano wrote: >> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: >> (snip) >>> def f(*args): >>> f.args = args >>> print args >>> (snip) >> I completely agree with you. It is a wart that functions are only able to >> refer to themselves by name, because if the name changes, things break. >> Consider: >> >> old_f = f # save the old version of the function >> >> def f(x): >> return old_f(x+1) # make a new function and call it f >> >> This won't work correctly, because old_f still tries to refer to itself >> under the name "f", and things break very quickly. > > They didn't break immediately for me -- what am I missing?: The fact that in the OP's snippet, code inside f's body refers to f by its name. From skylarking11 at gmail.com Wed Feb 10 10:29:40 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 10 Feb 2010 07:29:40 -0800 (PST) Subject: Python v. Processing Message-ID: I am a light user of Python in a role as a systems administrator...I am new to the list, but have grown to really enjoy using Python to help in my job...Another interest I have ( but haven't fully explored ) is the idea of using programming as a creative outlet .. I have heard Processing: http://processing.org/ is a good language for these sort of endeavors --- I am interested in Processing, but would rather do similar creative work in Python (i know that is vague, but the projects on Processing.org are good examples of what I am intending to do ). I've tried learning different languages concurrently, and it is usually too much for me too handle.... Are there creative types using Python in the way Processing is being implemented? Just curious of their similarities and differences, and what Python's limitations maybe be in this arena ( if any ) . Thanks! From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 10:33:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 15:33:34 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> Message-ID: <0382bdeb$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote: >> This won't work correctly, because old_f still tries to refer to itself >> under the name "f", and things break very quickly. > > They didn't break immediately for me -- what am I missing?: The original function f doesn't try to refer to itself in any way. With no recursive call or access, it doesn't matter what f is named. See this example instead: >>> def f(x): ... if x < 0: ... print "original" ... return f(-x) ... else: ... return x+1 ... >>> f(2) 3 >>> f(-2) original 3 >>> >>> old_f = f >>> def f(x): ... if x > 0: ... return old_f(-x) ... else: ... return x ... >>> f(-1) -1 >>> f(1) original original original original original original [...] File "", line 3, in f File "", line 4, in f File "", line 3, in f RuntimeError: maximum recursion depth exceeded -- Steven From yakovenko87 at gmail.com Wed Feb 10 10:34:13 2010 From: yakovenko87 at gmail.com (=?UTF-8?B?0JrQuNGA0LjQu9C7?=) Date: Wed, 10 Feb 2010 07:34:13 -0800 (PST) Subject: not correct socket closing Message-ID: <13f582d6-dc41-48a3-9900-5ed95a42dcf0@a32g2000yqm.googlegroups.com> Hi all, I have got a small script for upload file on http server, and I need interrupt uploading if I get tired wait. I create socket: self.conn = httplib.HTTPConnection("192.168.0.195") #self.conn.debuglevel = 1 self.conn.request("POST", "/upload/", body, head) if self.conn.sock: self.conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)) and close it in other thread: if self.conn.sock: self.conn.close() Python notify me what socket have closed, but he continues to send data. As can I close it and stop sending of the data? Best Regards, Kirill. From apt.shansen at gmail.com Wed Feb 10 10:42:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 07:42:37 -0800 Subject: Modifying Class Object In-Reply-To: <0382abea$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002100742x2f8fbeefi5f33fbdd475fdc77@mail.gmail.com> On Wed, Feb 10, 2010 at 6:16 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > While it is true that quoted text is officially meant to indicate a > direct quote, it is also commonly used in informal text to indicate a > paraphrase. (There are other uses as well, but they don't concern us now.) > Hm. I hadn't considered that others may interpret my words in the context of other cultural punctuation rules; it seemed obvious to me that the phrases Alf declared a "lie" were an opinion, and indeed as Steven points out, my interpretation and paraphrasing of the original arguments. Apologies if you considered it a direct quote and thought I was attempting to assert you actually said what was in quote marks. The comments were simply my interpretation (accurate or inaccurate as that may be, it is my interpretation) of your remarks, and not a quotation of your remarks to be attributed to you. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 10 10:51:31 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 10:51:31 -0500 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: catonano wrote: [... much wishing for the "good old day" of SmallTalk ...] > Today, I tried to understand the twisted.web.client code and I found 3 > methods I couldn't find by who were called. > > I asked on the mailing list and they suggested me where they were > called and that the tool for such thing is "grep". > > So, you grep, you get a list of files, you open each one of them and > keep scrolling and switching from one file to another... endlessly. > Maybe I'm getting old, but I tend to get lost in the process. > Maybe you are getting old. Or maybe you didn't realise that the advice was given you so that it would be useful whether or not you were using an IDE. > I can't believe the code editing situation today is in a such sorry > state. > It isn't. There are many IDEs that will allow you to easily locate the calls of specific methods. > Is this what you meant ? > > If it's this, then it's not experimental at all, it's been done > already and been put apart. > > Crap won :-( > It seems you yearn for the days of the SmallTalk image. Unfortunately this didn't allow for conveniences like using external data stored in files whose contents persisted and which could be transferred between different machines. I would never call SmallTalk "crap": it was a ground-breaking system almost 40 yers ago. But the environment suffered from many limitations of which you appear to be entirely unaware. > You write: > >> Instead of current text-oriented IDEs, it >> should be a database-centric > > well, it seems you agree with Alan Kay, (the Smalltalk inventor) when > he wrote that programming is NOT glorified text editing. > > He called it "direct manipulation" every method was a live thing you > could send messages to and the source code that implemented it was > just an attribute of the method. > This aspect of SmallTalk was one of the things that made software engineering rather difficult. Everything could be changed on the fly. > So you could have had a World Of Warcraft like interface, to > manipulate your methods. > > You know what I'm doing now ? I'm drawing the map of > twisted.web.client on a paper with a pencil :-( > Well why don't you get yourself a sensible tool like Wing IDE or Komodo? They at least will let you solve the problem you currently face without having to poke around in the innards of a running virtual machine the way we used to in SmallTalk. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From franke.rob at googlemail.com Wed Feb 10 10:54:50 2010 From: franke.rob at googlemail.com (Robert Franke) Date: Wed, 10 Feb 2010 16:54:50 +0100 Subject: Python v. Processing In-Reply-To: References: Message-ID: Hi Sky, there is a project called pyprocessing (http://code.google.com/p/pyprocessing/) that aims to create a similar environment like processing in python. I am not sure though how advanced this is. Cheers, Robert On Wed, Feb 10, 2010 at 4:29 PM, Sky Larking wrote: > I am a light user of Python in a role as a systems administrator...I > am new to the list, but have grown to really enjoy using Python to > help in my job...Another interest I have ( but haven't fully > explored ) ?is the idea of using programming as a creative outlet .. I > have heard Processing: http://processing.org/ is a good language for > these sort of endeavors --- I am interested in Processing, but would > rather do similar creative work in ?Python (i know that is vague, but > the projects on Processing.org are good examples of what I am > intending to do ). I've tried learning different languages > concurrently, and it is usually too much for me too handle.... Are > there creative types using Python in the way Processing is being > implemented? Just curious of their similarities and differences, and > what Python's limitations maybe be in this arena ( if any ) . > > Thanks! > -- > http://mail.python.org/mailman/listinfo/python-list > From apt.shansen at gmail.com Wed Feb 10 10:56:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 07:56:37 -0800 Subject: Function attributes In-Reply-To: <0382b08c$0$1277$c3e8da3@news.astraweb.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > > What is the simplest way to access the attributes of a function from > > inside it, other than using its explicit name? In a function like f > > Not built-in. > > > I am guessing the next question will be: should I really care? It just > > feels like there should be a way, but I am not able to verbalise a valid > > one at the moment, sorry. > > I completely agree with you. It is a wart that functions are only able to > refer to themselves by name, because if the name changes, things break. > I agree its slightly... in-elegant, or sub-optimal, but I'm not sure I want to call it a *wart*. If one calls it a wart, there might be inspiration to fix it. And this sounds like a precursor to making "self" non-explicit, and I *really* like my explicit self. :) Then again, I have been slightly bruised by this sub-optimal situation before. I tried to do a function using a frame hack to get the information easily, but failed. My long years of avoiding frame hacks like the plague have left me deficient. :( --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Wed Feb 10 11:02:54 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 16:02:54 +0000 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: <4B72D8AE.3000503@mrabarnett.plus.com> Olof Bjarnason wrote: > 2010/2/10 Peter Otten <__peter__ at web.de>: >> python at bdurham.com wrote: >> >>> Does Python provide a way to format a string according to a >>> 'picture' format? >>> >>> For example, if I have a string '123456789' and want it formatted >>> like '(123)-45-(678)[9]', is there a module or function that will >>> allow me to do this or do I need to code this type of >>> transformation myself? >> A basic implementation without regular expressions: >> >>>>> def picture(s, pic, placeholder="@"): >> ... parts = pic.split(placeholder) >> ... result = [None]*(len(parts)+len(s)) >> ... result[::2] = parts >> ... result[1::2] = s >> ... return "".join(result) >> ... >>>>> picture("123456789", "(@@@)-@@-(@@@)[@]") >> '(123)-45-(678)[9]' >> >> Peter >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Inspired by your answer here's another version: > >>>> def picture(s, pic): > ... if len(s)==0: return pic > ... if pic[0]=='#': return s[0]+picture(s[1:], pic[1:]) > ... return pic[0]+picture(s, pic[1:]) > ... >>>> picture("123456789", "(###)-##-(###)[#]") > '(123)-45-(678)[9]' > Here's a version without recursion: >>> def picture(s, pic): ... pic = pic.replace("%", "%%").replace("#", "%s") ... return pic % tuple(s) ... >>> picture("123456789", "(###)-##-(###)[#]") '(123)-45-(678)[9]' From apt.shansen at gmail.com Wed Feb 10 11:06:25 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 08:06:25 -0800 Subject: Creating formatted output using picture strings In-Reply-To: References: Message-ID: <7a9c25c21002100806m66bc38f6mc2242c381be5c7ee@mail.gmail.com> On Wed, Feb 10, 2010 at 1:45 AM, Peter Otten <__peter__ at web.de> wrote: > A basic implementation without regular expressions: > > >>> def picture(s, pic, placeholder="@"): > ... parts = pic.split(placeholder) > ... result = [None]*(len(parts)+len(s)) > ... result[::2] = parts > ... result[1::2] = s > ... return "".join(result) > ... > >>> > >>> picture("123456789", "(@@@)-@@-(@@@)[@]") > '(123)-45-(678)[9]' > Huh. This is the best version of those posted, I think (especially including mine! My jumping to regex is worthy of shame, sh ame). It took a little bit to figure out what was really going on here, but its a single-pass through to do it without recursion or building a bunch of intermediate strings that are concatenated and dropped away. Its clever, and I don't mean that in the bad way, because -all- the solutions are pretty clever in the sneaky-tricky-neat way. But this is clever-cool. Just slightly dark-voodoo-incantation-esque. Slightly! --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Feb 10 11:10:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 10 Feb 2010 10:10:23 -0600 Subject: Personal criticisms and logical fallacies In-Reply-To: <4B725AF0.9030803@gmail.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <00fb7707$0$15628$c3e8da3@news.astraweb.com> <87eikuhrax.fsf_-_@benfinney.id.au> <20100210015132.3808f0d5.darcy@druid.net> <4B725AF0.9030803@gmail.com> Message-ID: On 2010-02-10 01:06 AM, Steven Howe wrote: > Really, is this a relevant topic on a program mail list? Yes. Meta-discussions about how we discuss programming productively are also on-topic. -- 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 invalid at invalid.invalid Wed Feb 10 11:15:22 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 16:15:22 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Gabriel Genellina wrote: > En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards > escribi?: > >> What's the correct way to measure small periods of elapsed >> time. I've always used time.clock() in the past: >> >> However on multi-processor machines that doesn't work. >> Sometimes I get negative values for delta. According to >> google, this is due to a bug in Windows that causes the value >> of time.clock() to be different depending on which core in a >> multi-core CPU you happen to be on. [insert appropriate >> MS-bashing here] > > I'm not sure you can blame MS of this issue; anyway, this > patch should fix the problem: > http://support.microsoft.com/?id=896256 I'm curious why it wouldn't be Microsoft's fault, because A) Everything is Microsoft's fault. ;) B) If a patch to MS Windows fixes the problem, how is it not a problem in MS Windows? >> Is there a way to lock the python process to a single core so >> that time.clock() works right? > > Interactively, from the Task Manager: > http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_assign_process.mspx Thanks. That looks a bit easier than disabling the second core (which is what I ended up doing). > In code, using SetProcessAffinityMask and related functions: > http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx With help from google and some old mailing list posting I might even try that. -- Grant Edwards grante Yow! It's a lot of fun at being alive ... I wonder if visi.com my bed is made?!? From rantingrick at gmail.com Wed Feb 10 12:15:07 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Feb 2010 09:15:07 -0800 (PST) Subject: looking for some libraries References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> Message-ID: <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> On Feb 10, 8:59?am, Vision wrote: > hi all, > I am doing some stuffs with some software, which has similar layout > like this: > Editbox________1 > Editbox________2 > Editbox________3 > ? ? ? ?_OK_ > _______________ > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > | ? ? ? ?output ? ? ? ?| > -------------------------- > What I need to do is to fill the edit boxes, then press the OK button, > then I will get some output text below. > This is tedious since I have lots of entries to deal with. > So I am trying to write some scripts to handle this. And I wonder if > there is any library available for me to simplify the process? > Thanks! Well a GUI kit comes to mind. And since you did not mention a preference (or much really) i would suggest Tkinter in the stdlib as a starting point. Here is a big hint! #-- start code --# import Tkinter as tk def fooit(): lister.insert(END, entry1.get()) app = tk.Tk() label1 = tk.Label(app, text='label-1').grid(row=0, column=0) entry1 = tk.Entry(app).grid(row=0, column=1) tk.Button(app, text='OK', command=fooit).grid(row=1, column=0, columnspan=2) lister = tk.Listbox(app, width=20, height=10) lister.grid(row=2, column=0, columnspan=2) app.mainloop() #-- end code --# i would wrap the label and entry up into a class myself but milage may vary. From rantingrick at gmail.com Wed Feb 10 12:20:34 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 10 Feb 2010 09:20:34 -0800 (PST) Subject: looking for some libraries References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> Message-ID: <72f1941d-92bd-4063-aa14-d5bb3e0b5107@j31g2000yqa.googlegroups.com> @Vision Its nice to start with examples that don't crash, so try this instead ;D import Tkinter as tk def fooit(): lister.insert('end', entry1.get()) app = tk.Tk() label1 = tk.Label(app, text='label-1').grid(row=0, column=0) entry1 = tk.Entry(app) entry1.grid(row=0, column=1) tk.Button(app, text='OK', command=fooit).grid(row=1, column=0, columnspan=2) -- there are no redo's in Usenet!! lister = tk.Listbox(app, width=20, height=10) lister.grid(row=2, column=0, columnspan=2) app.mainloop() From python at mrabarnett.plus.com Wed Feb 10 12:23:36 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 17:23:36 +0000 Subject: Function attributes In-Reply-To: <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> Message-ID: <4B72EB98.1000204@mrabarnett.plus.com> Stephen Hansen wrote: > On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano > > wrote: > > On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: > > What is the simplest way to access the attributes of a function from > > inside it, other than using its explicit name? In a function like f > > Not built-in. > > > I am guessing the next question will be: should I really care? It > just > > feels like there should be a way, but I am not able to verbalise > a valid > > one at the moment, sorry. > > I completely agree with you. It is a wart that functions are only > able to > refer to themselves by name, because if the name changes, things break. > > > I agree its slightly... in-elegant, or sub-optimal, but I'm not sure I > want to call it a *wart*. If one calls it a wart, there might be > inspiration to fix it. > > And this sounds like a precursor to making "self" non-explicit, and I > *really* like my explicit self. :) > > Then again, I have been slightly bruised by this sub-optimal situation > before. > > I tried to do a function using a frame hack to get the information > easily, but failed. My long years of avoiding frame hacks like the > plague have left me deficient. :( > Does this mean that Python needs, say, __function__ (and perhaps also __module__)? From python at bdurham.com Wed Feb 10 12:23:38 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 10 Feb 2010 12:23:38 -0500 Subject: Creating formatted output using picture strings In-Reply-To: <1265822561.1942.1359302945@webmail.messagingengine.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <1265822618.2095.1359305405@webmail.messagingengine.com> Original poster here. Thank you all for your ideas. I certainly learned some great techniques by studying everyone's solutions!! I was thinking that there was a built-in function for this common(?) use case which is why I shied away from writing my own in the first place ... hoping to not-reinvent the wheel, etc. Here's the solution I came up with myself. Its not as sexy as some of the posted solutions, but it does have the advantage of not failing when the number of input chars <> the number of placeholders in the pic string. I think it handles the edge cases pretty elegantly unless I'm too close to the details to miss the obvious. Any feedback on what follows would be appreciated. # format s using a picture string # stops processing when runs out of chars in s or pic string # example: picture("123456789", "(@@@)-@@-(@@@)[@]") def picture( s, pic, placeholder="@" ): s = list( s ) output = [] for sym in pic: if sym <> placeholder: output.append( sym ) elif len( s ): output.append( s.pop( 0 ) ) else: break return ''.join( output ) # test cases print picture("123456789", "(@@@)-@@-(@@@)[@]") print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") print picture("1234", "(@@@)-@@-(@@@)[@]") print picture("123456789", "(@@@)-@@-(@@@)") print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") Regards, Malcolm From cdberry at gmail.com Wed Feb 10 12:38:33 2010 From: cdberry at gmail.com (Craig Berry) Date: Wed, 10 Feb 2010 09:38:33 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> Message-ID: <8dee73061002100938l39f4b609k94088afefccecdd0@mail.gmail.com> I'm happy to report that FreeGLUT solved my problem. I obtained the Windows prepackaged binary distribution, pulled out freeglut.dll, renamed it to glut32.dll, and replaced the existing glut32.dll in the PyOpenGL installation directory tree with the new version. Mousewheel events are now reported, and everything else seems to be working as expected. Thanks for your help! -- Craig Berry - http://www.cine.net/~cberry/ "Lots of things in the universe don?t solve any problems, and nevertheless exist." -- Sean Carroll From jeanmichel at sequans.com Wed Feb 10 12:55:00 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 10 Feb 2010 18:55:00 +0100 Subject: looking for some libraries In-Reply-To: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> Message-ID: <4B72F2F4.4020607@sequans.com> Vision wrote: > hi all, > I am doing some stuffs with some software, which has similar layout > like this: > Editbox________1 > Editbox________2 > Editbox________3 > _OK_ > _______________ > | output | > | output | > | output | > | output | > | output | > -------------------------- > What I need to do is to fill the edit boxes, then press the OK button, > then I will get some output text below. > This is tedious since I have lots of entries to deal with. > So I am trying to write some scripts to handle this. And I wonder if > there is any library available for me to simplify the process? > Thanks! > Someone posted this link few weeks ago: http://www.sikuli.org/ It supports only mac & windows though. You can also have a look at http://pywinauto.openqa.org/ JM From python.list at tim.thechases.com Wed Feb 10 13:04:14 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 12:04:14 -0600 Subject: Creating formatted output using picture strings In-Reply-To: <1265822618.2095.1359305405@webmail.messagingengine.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265822618.2095.1359305405@webmail.messagingengine.com> Message-ID: <4B72F51E.1080609@tim.thechases.com> python at bdurham.com wrote: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! Thanks for the positive feedback -- it's something most folks like to hear when they try to assist and such thanks appears too rarely on the list. > Here's the solution I came up with myself. Its not as sexy as some of > the posted solutions, but it does have the advantage of not failing when > the number of input chars <> the number of placeholders in the pic > string. > > Any feedback on what follows would be appreciated. [snip] > # test cases > print picture("123456789", "(@@@)-@@-(@@@)[@]") > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") > print picture("1234", "(@@@)-@@-(@@@)[@]") > print picture("123456789", "(@@@)-@@-(@@@)") > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") > You don't give the expected output for these test cases, so it's hard to tell whether you want to pad-left or pad-right. Riffing on MRAB's lovely solution, you can do something like def picture( s, pic, placeholder='@', padding=' ', pad_left=True ): assert placeholder != '%' s = str(s) expected = pic.count(placeholder) if len(s) > expected: s = s[:expected] if len(s) < expected: if pad_left: s = s.rjust(expected, padding) else: s = s.ljust(expected, padding) return pic.replace( '%', '%%').replace( placeholder, '%s') % tuple(s) print picture("123456789", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789ABC", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("1234", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]", pad_left=False) That way you can specify your placeholder, your padding character, and whether you want it to pad to the left or right. -tkc From jjposner at optimum.net Wed Feb 10 13:15:27 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 13:15:27 -0500 Subject: Function attributes In-Reply-To: <4b72cfb9$0$30354$426a74cc@news.free.fr> References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <4b72cfb9$0$30354$426a74cc@news.free.fr> Message-ID: <4b72f7a5$0$5017$607ed4bc@cv.net> On 2/10/2010 10:24 AM, Bruno Desthuilliers wrote: >> >> They didn't break immediately for me -- what am I missing?: > > The fact that in the OP's snippet, code inside f's body refers to f by > its name. Of course! Tx. -John From arnodel at googlemail.com Wed Feb 10 13:21:35 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 18:21:35 +0000 Subject: Creating formatted output using picture strings References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: python at bdurham.com writes: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! > > I was thinking that there was a built-in function for this common(?) use > case which is why I shied away from writing my own in the first place > ... hoping to not-reinvent the wheel, etc. > > Here's the solution I came up with myself. Its not as sexy as some of > the posted solutions, but it does have the advantage of not failing when > the number of input chars <> the number of placeholders in the pic > string. I think it handles the edge cases pretty elegantly unless I'm > too close to the details to miss the obvious. > > Any feedback on what follows would be appreciated. > > # format s using a picture string > # stops processing when runs out of chars in s or pic string > # example: picture("123456789", "(@@@)-@@-(@@@)[@]") > def picture( s, pic, placeholder="@" ): > s = list( s ) > output = [] > for sym in pic: > if sym <> placeholder: > output.append( sym ) > elif len( s ): > output.append( s.pop( 0 ) ) > else: > break > return ''.join( output ) > > # test cases > print picture("123456789", "(@@@)-@@-(@@@)[@]") > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") > print picture("1234", "(@@@)-@@-(@@@)[@]") > print picture("123456789", "(@@@)-@@-(@@@)") > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") > > Regards, > Malcolm def picture(s, pic, placeholder='@'): nextchar=iter(s).next return ''.join(nextchar() if i == placeholder else i for i in pic) passes all your test cases I think (I can't be sure because you didn't post the expected output). The trick is that when nextchar reaches the end of the string 's', it raises a StopIteration which is caught by the generator expression. -- Arnaud From python at bdurham.com Wed Feb 10 13:30:21 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 10 Feb 2010 13:30:21 -0500 Subject: Creating formatted output using picture strings In-Reply-To: <4B72F51E.1080609@tim.thechases.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265822618.2095.1359305405@webmail.messagingengine.com> <4B72F51E.1080609@tim.thechases.com> Message-ID: <1265826621.13859.1359315979@webmail.messagingengine.com> Hi Tim, Thank you very much for your update to MRAB's creative solution. > You don't give the expected output for these test cases, so > it's hard to tell whether you want to pad-left or pad-right. To be honest, I wasn't sure myself :) My original post was the result of doing some simple formatting where my input strings were 'guaranteed' to be a consistent length. I hadn't started to think about the specs for a more universal picture function until I started to study and test the solutions proposed by others. It bears repeating again - what a clever mix of techniques - I really learned a lot more than I was expecting! I appreciate you taking the extra time to analyze the problem and refine it further. Cheers, Malcolm Riffing on MRAB's lovely solution, you can do something like def picture( s, pic, placeholder='@', padding=' ', pad_left=True ): assert placeholder != '%' s = str(s) expected = pic.count(placeholder) if len(s) > expected: s = s[:expected] if len(s) < expected: if pad_left: s = s.rjust(expected, padding) else: s = s.ljust(expected, padding) return pic.replace( '%', '%%').replace( placeholder, '%s') % tuple(s) print picture("123456789", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789ABC", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("1234", "(@@@)-@@-(@@@)[@]", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False) print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]", pad_left=False) That way you can specify your placeholder, your padding character, and whether you want it to pad to the left or right. From usenot at geekmail.INVALID Wed Feb 10 13:30:22 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 10 Feb 2010 19:30:22 +0100 Subject: Python and Ruby References: <1519c5ed-e883-470b-bb82-06078215fd5b@r19g2000yqb.googlegroups.com> <037471d0$0$1309$c3e8da3@news.astraweb.com> <4c174f35-84e7-48f1-8c72-7c0de3818384@z26g2000yqm.googlegroups.com> <636ee042-7411-4867-970c-96250c06498d@o28g2000yqh.googlegroups.com> Message-ID: <20100210193022.5067e3e3@geekmail.INVALID> On Wed, 10 Feb 2010 09:51:11 -0500 Steve Holden wrote: > [snip] > It's as sensible to complain about people being "*forced* to keep > perfect indentation" as it is to complain about people being *forced* > to use braces to delimit code blocks. > > This is called "syntax", and it's a part of the language, so get over > it - this aspect of Python has been present in the language since its > inception, and it isn't going to change. > Amen. Now everybody do a quick from __future__ import braces and get back to work. /W -- INVALID? DE! From arnodel at googlemail.com Wed Feb 10 13:31:23 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 18:31:23 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <0382bdeb$0$1277$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote: > >>> This won't work correctly, because old_f still tries to refer to itself >>> under the name "f", and things break very quickly. >> >> They didn't break immediately for me -- what am I missing?: > > The original function f doesn't try to refer to itself in any way. With > no recursive call or access, it doesn't matter what f is named. > > See this example instead: > > >>>> def f(x): > ... if x < 0: > ... print "original" > ... return f(-x) > ... else: > ... return x+1 > ... >>>> f(2) > 3 >>>> f(-2) > original > 3 >>>> >>>> old_f = f >>>> def f(x): > ... if x > 0: > ... return old_f(-x) > ... else: > ... return x > ... >>>> f(-1) > -1 >>>> f(1) > original > original > original > original > original > original > [...] > File "", line 3, in f > File "", line 4, in f > File "", line 3, in f > RuntimeError: maximum recursion depth exceeded It's not ideal, but you can use a decorator like this to solve this problem: def bindfunction(f): def bound_f(*args, **kwargs): return f(bound_f, *args, **kwargs) bound_f.__name__ = f.__name__ return bound_f >>> @bindfunction ... def factorial(this_function, n): ... if n > 0: ... return n * this_function(n - 1) ... else: ... return 1 ... >>> factorial(15) 1307674368000L >>> fac = factorial >>> fac(15) 1307674368000L >>> factorial = 'foobar' >>> fac(15) 1307674368000L -- Arnaud From gherron at islandtraining.com Wed Feb 10 13:33:24 2010 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 10 Feb 2010 10:33:24 -0800 Subject: [PyOpenGL-Users] Mouse wheel events? In-Reply-To: <8dee73061002100938l39f4b609k94088afefccecdd0@mail.gmail.com> References: <8dee73061002051948lf46b7am2746f2a04a4f16b@mail.gmail.com> <8dee73061002072157s5695eb25pd17e1846fc705f3f@mail.gmail.com> <4B6FAE86.2060603@islandtraining.com> <8dee73061002072245s3b01f2edvc31717e7a2876b31@mail.gmail.com> <8dee73061002100938l39f4b609k94088afefccecdd0@mail.gmail.com> Message-ID: <4B72FBF4.7060501@islandtraining.com> Craig Berry wrote: > I'm happy to report that FreeGLUT solved my problem. I obtained the > Windows prepackaged binary distribution, pulled out freeglut.dll, > renamed it to glut32.dll, and replaced the existing glut32.dll in the > PyOpenGL installation directory tree with the new version. Mousewheel > events are now reported, and everything else seems to be working as > expected. Thanks for your help! > > :-) Gary Herron From python at bdurham.com Wed Feb 10 13:36:34 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 10 Feb 2010 13:36:34 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <1265826994.14794.1359317783@webmail.messagingengine.com> Arnaud, Very cool!! Just when I thought the problem couldn't be made simpler ... WOW!!! Again, a big thank you to everyone who posted solutions!!! I'm humbled at how clever and different everyone's techniques have been. I have to say, I learned much more than I thought I needed to learn :) Thanks again! Malcolm ----- Original message ----- From: "Arnaud Delobelle" To: python-list at python.org Date: Wed, 10 Feb 2010 18:21:35 +0000 Subject: Re: Creating formatted output using picture strings python at bdurham.com writes: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! > > I was thinking that there was a built-in function for this common(?) use > case which is why I shied away from writing my own in the first place > ... hoping to not-reinvent the wheel, etc. > > Here's the solution I came up with myself. Its not as sexy as some of > the posted solutions, but it does have the advantage of not failing when > the number of input chars <> the number of placeholders in the pic > string. I think it handles the edge cases pretty elegantly unless I'm > too close to the details to miss the obvious. > > Any feedback on what follows would be appreciated. > > # format s using a picture string > # stops processing when runs out of chars in s or pic string > # example: picture("123456789", "(@@@)-@@-(@@@)[@]") > def picture( s, pic, placeholder="@" ): > s = list( s ) > output = [] > for sym in pic: > if sym <> placeholder: > output.append( sym ) > elif len( s ): > output.append( s.pop( 0 ) ) > else: > break > return ''.join( output ) > > # test cases > print picture("123456789", "(@@@)-@@-(@@@)[@]") > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") > print picture("1234", "(@@@)-@@-(@@@)[@]") > print picture("123456789", "(@@@)-@@-(@@@)") > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") > > Regards, > Malcolm def picture(s, pic, placeholder='@'): nextchar=iter(s).next return ''.join(nextchar() if i == placeholder else i for i in pic) passes all your test cases I think (I can't be sure because you didn't post the expected output). The trick is that when nextchar reaches the end of the string 's', it raises a StopIteration which is caught by the generator expression. -- Arnaud From ethan at stoneleaf.us Wed Feb 10 13:38:58 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 10 Feb 2010 10:38:58 -0800 Subject: Modifying Class Object In-Reply-To: <0382abea$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B72FD42.8010203@stoneleaf.us> Steven D'Aprano wrote: > > Believe me Alf, the fact that people are taking the time to try to argue > with you instead of just kill-filing you is a compliment. It's a compliment I am not paying, although I am grateful to those who are attempting to teach him. At the rate it's going, though, I don't see myself buying any book he produces. Besides the arrogant attitude, he is wrong on so many things about Python it is truly stunning. He seems to have confidence born of ignorance... a scary sight to see. In the spirit of being helpful and not just being a jerk myself: Alf, Using smileys after declaring somebody is mistaken/wrong/etc makes you look bad. Not attempting to learn the language makes you look like an arrogant idiot (case in point: passing-by-object). Accusing anyone and everyone that criticizes you of making ad hominem (sp?) attacks makes you look like a whiner. After all is said and done - if you had a truly good grasp of Python, I might buy your book even if you still had -- ummm -- a less than winning presence on the mailing list; but right now your understanding is not worth paying for. Hoping-this-helps-but-not-really-expecting-it-to-ly yours, ~Ethan~ From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 13:58:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 18:58:02 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> Message-ID: <0382edd6$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 17:23:36 +0000, MRAB wrote: > Stephen Hansen wrote: >> On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano >> > > wrote: >> >> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: >> > What is the simplest way to access the attributes of a function >> > from inside it, other than using its explicit name? In a >> > function like f >> >> Not built-in. [...] > Does this mean that Python needs, say, __function__ (and perhaps also > __module__)? Python already has __module__, except that it is spelled: import __main__ As for __function__, perhaps, but a solution I would be satisfied with would be to make it optional. Most functions are not recursive, and do not attach attributes to themselves. For the few that do need to refer to themselves, it would be sufficient to call a decorator to get the behaviour needed. I thought I had come up with such a thing, once before, but I can't find it now :( -- Steven From donn.ingle at gmail.com Wed Feb 10 14:00:57 2010 From: donn.ingle at gmail.com (donn) Date: Wed, 10 Feb 2010 21:00:57 +0200 Subject: Creating formatted output using picture strings In-Reply-To: <1265826994.14794.1359317783@webmail.messagingengine.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265826994.14794.1359317783@webmail.messagingengine.com> Message-ID: <4B730269.70809@gmail.com> On 10/02/2010 20:36, python at bdurham.com wrote: > def picture(s, pic, placeholder='@'): > nextchar=iter(s).next > return ''.join(nextchar() if i == placeholder else i for i in pic) Hell's teeth - even I understood that! Amazing solution. \d -- Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software From steve at REMOVE-THIS-cybersource.com.au Wed Feb 10 14:04:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 19:04:58 GMT Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <0382bdeb$0$1277$c3e8da3@news.astraweb.com> Message-ID: <0382ef76$0$1277$c3e8da3@news.astraweb.com> On Wed, 10 Feb 2010 18:31:23 +0000, Arnaud Delobelle wrote: > It's not ideal, but you can use a decorator like this to solve this > problem: > > def bindfunction(f): > def bound_f(*args, **kwargs): > return f(bound_f, *args, **kwargs) > bound_f.__name__ = f.__name__ > return bound_f Ah, very nice. Perhaps it's better to use functools.wraps? import functools def bindfunction(f): @functools.wraps(f) def bound_f(*args, **kwargs): return f(bound_f, *args, **kwargs) return bound_f -- Steven From no.email at please.post Wed Feb 10 14:09:46 2010 From: no.email at please.post (kj) Date: Wed, 10 Feb 2010 19:09:46 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia Message-ID: Some people have mathphobia. I'm developing a wicked case of Unicodephobia. I have read a *ton* of stuff on Unicode. It doesn't even seem all that hard. Or so I think. Then I start writing code, and WHAM: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) (There, see? My Unicodephobia just went up a notch.) Here's the thing: I don't even know how to *begin* debugging errors like this. This is where I could use some help. In the past I've gone for method of choice of the clueless: "programming by trial-and-error", try random crap until something "works." And if that "strategy" fails, I come begging for help to c.l.p. And thanks for the very effective pointers for getting rid of the errors. But afterwards I remain as clueless as ever... It's the old "give a man a fish" vs. "teach a man to fish" story. I need a systematic approach to troubleshooting and debugging these Unicode errors. I don't know what. Some tools maybe. Some useful modules or builtin commands. A diagnostic flowchart? I don't think that any more RTFM on Unicode is going to help (I've done it in spades), but if there's a particularly good write-up on Unicode debugging, please let me know. Any suggestions would be much appreciated. FWIW, I'm using Python 2.6. The example above happens to come from a script that extracts data from HTML files, which are all in English, but they are a daily occurrence when I write code to process non-English text. The script uses Beautiful Soup. I won't post a lot of code because, as I said, what I'm after is not so much a way around this specific error as much as the tools and techniques to troubleshoot it and fix it on my own. But to ground the problem a bit I'll say that the exception above happens during the execution of a statement of the form: x = '%s %s' % (y, z) Also, I found that, with the exact same values y and z as above, all of the following statements work perfectly fine: x = '%s' % y x = '%s' % z print y print z print y, z TIA! ~K From jgardner at jonathangardner.net Wed Feb 10 14:22:44 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 10 Feb 2010 11:22:44 -0800 (PST) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> On Feb 10, 11:09?am, kj wrote: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) > You'll have to understand some terminology first. "codec" is a description of how to encode and decode unicode data to a stream of bytes. "decode" means you are taking a series of bytes and converting it to unicode. "encode" is the opposite---take a unicode string and convert it to a stream of bytes. "ascii" is a codec that can only describe 0-127 with bytes 0-127. "utf-8", "utf-16", etc... are other codecs. There's a lot of them. Only some of them (ie, utf-8, utf-16) can encode all unicode. Most (ie, ascii) can only do a subset of unicode. In this case, you've fed a stream of bytes with 128 as one of the bytes to the decoder. Since the decoder thinks it's working with ascii, it doesn't know what to do with 128. There's a number of ways to fix this: (1) Feed it unicode instead, so it doesn't try to decode it. (2) Tell it what encoding you are using, because it's obviously not ascii. > > FWIW, I'm using Python 2.6. ?The example above happens to come from > a script that extracts data from HTML files, which are all in > English, but they are a daily occurrence when I write code to > process non-English text. ?The script uses Beautiful Soup. ?I won't > post a lot of code because, as I said, what I'm after is not so > much a way around this specific error as much as the tools and > techniques to troubleshoot it and fix it on my own. ?But to ground > the problem a bit I'll say that the exception above happens during > the execution of a statement of the form: > > ? x = '%s %s' % (y, z) > > Also, I found that, with the exact same values y and z as above, > all of the following statements work perfectly fine: > > ? x = '%s' % y > ? x = '%s' % z > ? print y > ? print z > ? print y, z > What are y and z? Are they unicode or strings? What are their values? It sounds like someone, probably beautiful soup, is trying to turn your strings into unicode. A full stacktrace would be useful to see who did what where. From duncan.booth at invalid.invalid Wed Feb 10 14:56:20 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Feb 2010 19:56:20 GMT Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: kj wrote: > But to ground > the problem a bit I'll say that the exception above happens during > the execution of a statement of the form: > > x = '%s %s' % (y, z) > > Also, I found that, with the exact same values y and z as above, > all of the following statements work perfectly fine: > > x = '%s' % y > x = '%s' % z > print y > print z > print y, z > One of y or z is unicode, the other is str. The statement that goes wrong is combining the unicode string with the other one so the result has to be unicode. That means whichever of y or z is str is being decoded to unicode is being decoded with the default of 'ascii'. When you format them separately one assignment to x gives a unicode result, the other gives str. When you print them you are encoding the unicode value to ascii and that isn't giving a problem. 1. Print the repr of each value so you can see which is which. 2. Explicitly decode the str to unicode using whatever encoding is correct (possibly utf-8) when formatting. 3. Explicitly encode back to str when printing using the encoding of your output device. 4. Know what types you are using: never mix str and unicode without being explicit. 5. When you post to this newsgroup include the full traceback, not just the error message. From python at mrabarnett.plus.com Wed Feb 10 14:56:25 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 19:56:25 +0000 Subject: Creating formatted output using picture strings In-Reply-To: <4B72F51E.1080609@tim.thechases.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <1265822618.2095.1359305405@webmail.messagingengine.com> <4B72F51E.1080609@tim.thechases.com> Message-ID: <4B730F69.8090205@mrabarnett.plus.com> Tim Chase wrote: > python at bdurham.com wrote: >> Original poster here. >> >> Thank you all for your ideas. I certainly learned some great techniques >> by studying everyone's solutions!! > > Thanks for the positive feedback -- it's something most folks like to > hear when they try to assist and such thanks appears too rarely on the > list. > >> Here's the solution I came up with myself. Its not as sexy as some of >> the posted solutions, but it does have the advantage of not failing when >> the number of input chars <> the number of placeholders in the pic >> string. > > >> Any feedback on what follows would be appreciated. > [snip] >> # test cases >> print picture("123456789", "(@@@)-@@-(@@@)[@]") >> print picture("123456789ABC", "(@@@)-@@-(@@@)[@]") >> print picture("1234", "(@@@)-@@-(@@@)[@]") >> print picture("123456789", "(@@@)-@@-(@@@)") >> print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]") >> > > You don't give the expected output for these test cases, so it's hard to > tell whether you want to pad-left or pad-right. > > Riffing on MRAB's lovely solution, you can do something like > > def picture( > s, pic, > placeholder='@', > padding=' ', > pad_left=True > ): > assert placeholder != '%' > s = str(s) > expected = pic.count(placeholder) > if len(s) > expected: > s = s[:expected] > if len(s) < expected: > if pad_left: > s = s.rjust(expected, padding) > else: > s = s.ljust(expected, padding) > return pic.replace( > '%', '%%').replace( > placeholder, '%s') % tuple(s) > > print picture("123456789", "(@@@)-@@-(@@@)[@]", pad_left=False) > print picture("123456789ABC", "(@@@)-@@-(@@@)[@]", pad_left=False) > print picture("1234", "(@@@)-@@-(@@@)[@]", pad_left=False) > print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False) > print picture("123456789", "(@@@)-@@-(@@@)[@][@@@@@]", pad_left=False) > > That way you can specify your placeholder, your padding character, and > whether you want it to pad to the left or right. > The code changes any existing '%' to '%%' because each placeholder will be changed to '%s'. However, if the placeholder itself is '%' then the initial 'fix' isn't necessary. Therefore: def picture(s, pic, placeholder='@', padding=' ', pad_left=True): s = str(s) expected = pic.count(placeholder) if len(s) > expected: s = s[:expected] elif len(s) < expected: if pad_left: s = s.rjust(expected, padding) else: s = s.ljust(expected, padding) if placeholder != '%': pic = pic.replace('%', '%%') return pic.replace(placeholder, '%s') % tuple(s) From invalid at invalid.invalid Wed Feb 10 14:57:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 19:57:04 +0000 (UTC) Subject: Creating formatted output using picture strings References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: On 2010-02-10, python at bdurham.com wrote: [regardning "picture" output format specifiers] > I was thinking that there was a built-in function for this > common(?) use case I haven't seen that paradigm since my one-and-only exposure to COBOL in a class I took back in 1979. Is the "picture" thing commonly used in other places than COBOL? -- Grant Edwards grante Yow! Did I say I was at a sardine? Or a bus??? visi.com From alfps at start.no Wed Feb 10 15:02:14 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 21:02:14 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Duncan Booth: > "Alf P. Steinbach" wrote: > >>> In CPython objects once created remain in the same memory location >>> (and their id is their address). Compare that to IronPython where the >>> objects themselves can move around in memory so they have no fixed >>> address. Try comparing the IronPython implementation to C pointers >>> and you'll cause a lot of confusion. e.g. someone might think the >>> id() value is in some way related to an address. >> Did you /read/ what you quoted? >> >> >>> Ruby implements integers without using any pointers at all: there's >>> nothing in the Python specification which prevents a Python >>> implementation doing the same for small integers, in fact I believe >>> it has been tried but wasn't found to improve performance. >> All theree of your points about Python are wrong; I don't know about >> the Ruby point. > > Would you care to expand upon your claim that my three points about Python > are wrong? Sure. I already did in the article you're replying to, immediately following what you quote above. You snipped that which you're asking for, so I requote: First, the current Python language specification formally prevents the optimization you mention, because there's no support for binding to do anything but direct binding leaving object identities unchanged. But in practice that's no big deal though: I can't imagine any code relying on identities of completely immutable objects. Second, even the variant that was tried improved performance. But it would reportedly have wreaked havoc with imperfect C code. Third, the optimization doesn't do away with pointers. If it did then it would transform the language completely. The user's view is still one where names denote pointers. Since in the quoting above no reference to definition of "pointer" remains: "pointer" refers to a copyable reference value as seen from the Python level, in the same way as "pointer" is used by e.g. the Java language spec. > Are you saying that CPyhton objects move around, or that > IronPython objects are fixed to a single memory location or that their id > is related to their address? No, I can't see how you can deduce any such connection from I wrote. Whether objects "move around" depends on what exactly you mean by "move around", and given that, it may then depend on the Python implementation. However, from the Python point of view every object has a fixed unique id, available via id(). > Clue here: > > IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082 > Type "help", "copyright", "credits" or "license" for more information. >>>> x = 42 >>>> id(x) > 43 >>>> y = 43 >>>> id(y) > 44 >>>> z = "whatever" >>>> id(z) > 45 > I'm guessing wildly that you're trying to illustrate id's that don't correspond to memory addresses? If so, then that's correct: a Python (or Java, or whatever language) pointer is not necessarily directly a memory address, and furthermore id is not guaranteed to reproduce the bits of a pointer value -- which might not even make sense. All that id does is to produce a value that uniquely identifies the object pointed to, i.e. it corresponds to the pointer value, and although in CPython that's simply the bits of a C pointer typed as integer, in IronPython it's not. Cheers & hth., - Alf From python at mrabarnett.plus.com Wed Feb 10 15:05:55 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Feb 2010 20:05:55 +0000 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: <4B7311A3.3010504@mrabarnett.plus.com> kj wrote: > > Some people have mathphobia. I'm developing a wicked case of > Unicodephobia. > > I have read a *ton* of stuff on Unicode. It doesn't even seem all > that hard. Or so I think. Then I start writing code, and WHAM: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) > > (There, see? My Unicodephobia just went up a notch.) > > Here's the thing: I don't even know how to *begin* debugging errors > like this. This is where I could use some help. > > In the past I've gone for method of choice of the clueless: > "programming by trial-and-error", try random crap until something > "works." And if that "strategy" fails, I come begging for help to > c.l.p. And thanks for the very effective pointers for getting rid > of the errors. > > But afterwards I remain as clueless as ever... It's the old "give > a man a fish" vs. "teach a man to fish" story. > > I need a systematic approach to troubleshooting and debugging these > Unicode errors. I don't know what. Some tools maybe. Some useful > modules or builtin commands. A diagnostic flowchart? I don't > think that any more RTFM on Unicode is going to help (I've done it > in spades), but if there's a particularly good write-up on Unicode > debugging, please let me know. > > Any suggestions would be much appreciated. > > FWIW, I'm using Python 2.6. The example above happens to come from > a script that extracts data from HTML files, which are all in > English, but they are a daily occurrence when I write code to > process non-English text. The script uses Beautiful Soup. I won't > post a lot of code because, as I said, what I'm after is not so > much a way around this specific error as much as the tools and > techniques to troubleshoot it and fix it on my own. But to ground > the problem a bit I'll say that the exception above happens during > the execution of a statement of the form: > > x = '%s %s' % (y, z) > > Also, I found that, with the exact same values y and z as above, > all of the following statements work perfectly fine: > > x = '%s' % y > x = '%s' % z > print y > print z > print y, z > Decode all text input; encode all text output; do all text processing in Unicode, which also means making all text literals Unicode (prefixed with 'u'). Note: I'm talking about when you're working with _text_, as distinct from when you're working with _binary data_, ie bytes. From twistedphrame at gmail.com Wed Feb 10 15:13:58 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Wed, 10 Feb 2010 12:13:58 -0800 (PST) Subject: SocketServer error: AttributeError: instance has no __call__ method Message-ID: Hey guys, I'm having some issues connecting to my Socket Server, I get this traceback on the sever side: ---------------------------------------- Exception happened during processing of request from ('127.0.0.1', 56404) Traceback (most recent call last): File "/usr/lib/python2.6/SocketServer.py", line 281, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python2.6/SocketServer.py", line 307, in process_request self.finish_request(request, client_address) File "/usr/lib/python2.6/SocketServer.py", line 320, in finish_request self.RequestHandlerClass(request, client_address, self) AttributeError: Negotiator instance has no __call__ method ---------------------------------------- here's the handler and my server: #server side negotiator from message import message from sharedComs import * from Crypto.Hash import SHA256 from Crypto.Cipher import AES from Crypto import Random from Crypto.PublicKey import RSA import xmlrpclib as xmlrpc import os import SocketServer class Negotiator(SocketServer.BaseRequestHandler): CLIENT_KEY = 0 CSCIPHER = 1 SCCIPHER = 2 CSHALVES = 3 SCHALVES = 4 FILENAME = 5 def __init__(self, host, hostid, rsa_key, buf = 512): self.host = host self.hostid = hostid self.serverKey = rsa_key self.buffer = buf self.clientKey = None self.SCcipher = None self.CScipher = None self.CSHalves = None self.SCHalves = None self.file = None usr_dict = {} def setSChalves(self): usr_dict[str(self.client_address)][SCHALVES] = (Random.new().read(32), Random.new().read(32)) def createCiphers(self): """Create the two ciphers we will be using for communication between negotiators""" name = str(self.client_address) usr_dict[name][1] = AES.new(SHA256.new(str("KCS", usr_dict[name] [SCHALVES][0], self.serverKey.publickey(), usr_dict[name] [CSHALVES][0], usr_dict[name] [CLIENT_KEY].publickey())).digest()) usr_dict[name][2] = AES.new(SHA256.new(str("KSC", usr_dict[name] [SCHALVES][1], self.serverKey.publickey(), usr_dict[name] [CSHALVES][1], usr_dict[name] [CLIENT_KEY].publickey())).digest()) def handleConn(self, clmsg): data = clmsg[1] if data[0] == self.host and data[1] == self.hostid: return True else: return False def getClientHalves(self, clmsg): """Get the halves from the clien as well as the client key.""" print clmsg print "clmsg[1]", clmsg[1] data = stringToTuple(clmsg[1]) print "tuple", data print "tuple[0]", data[0] print "tuple[1]", data[1] data = self.serverKey.decrypt(str(data[0])) print print "data:",data print data = stringToTuple(data) usr_dict[str(self.client_address)][CLIENT_KEY] = RSA.construct((data[0],data[1])) usr_dict[str(self.client_address)][CSHALVES] = (data[2], data[3]) def handleFileReq(self, clmsg): """Determine if the file requested exists: TODO: if the client is allowed to acces""" data = DecodeAES(self.CScipher, clmsg[1]) usr_dict[str(self.client_address)][FILENAME] = data return os.path.exists(usr_dict[str(self.client_address)][5]) def packageFile(self): f = open(usr_dict[str(self.client_address)][5],"rb") data = f.read() f.close() crypt = EncodeAES(self.SCcipher, data) f = open(usr_dict[str(self.client_address)] [5]+str(self.client_address), "wb") f.write(crypt) f.close return (True,self.file+self.client.getAddr()) def handleUserDisc(self, clmsg): os.remove(usr_dict[str(self.client_address)][FILENAME] +str(self.client_address)) def handle(self): #Plan on being asked for server comfirmation msg = self.request.recv(self.buffer) name = str(self.client_address) clmsg = None if not msg == "": clmsg = xmlrpc.loads() if not name in usr_dict: user_dict[name] = ["","","","","",""] print "handle Server ver" clmsg = clmsg[0] if clmsg[0] == CONN: if not self.handleConn(clmsg): print "Not right HostID" del usr_dict[name] else: #We got the right message send a reply with our key srvmsg = message(SERVER_INFO, str(self.serverKey.publickey())) self.request.send(xmlrpc.dumps(srvmsg.getSendable())) elif clmsg[0] == CS_KEY: #all this is public key encryption #plan on getting key halves from the client # as well as the clients public key print "get key/halves from client" self.getClientHalves(clmsg) #send over our halves now print "send halves" self.setSCHalves() srvmsg = message(SC_KEYDAT, str(usr_dict[name] [0].encrypt(usr_dict[name][4],""))) #everyones halves were sent so generate the ciphers self.createCiphers() #all this is AES encryption #### USER AUTH HERE JUST SENDING ACK FOR NOW #no user auth yet so just acknowledge the user exists print "send usr ack" srvmsg = message(USER_ACK, str(EncodeAES(usr_dict[name] [2],True))) self.server.send(xmlrpc.dumps(servmsg.getSendable())) #the client should be sending a file request elif clmsg[0] == FILE_REQ: print "expecting file req" available = self.handleFileReq(clmsg) if available: #file is available srvmsg = message(FILE_ACK, str(EncodeAES(usr_dict[name] [2],available))) else: #file isn't available srvmsg = message(FILE_ACK, str(EncodeAES(usr_dict[name] [2],available))) print "File %s not Available" %self.file del usr_dict[name] #package the file and tell the client package = self.packageFile() srvmsg = message(DL_READY, EncodeAES(usr_dict[name][2], package)) self.server.send(xmlrpc(srvmsg.getSendable())) if not package[0]: # the file wasn't pakaged so close the connection #the client tells us they got the file so just remove the file that #was made print "expecting USER_DISC" else: if not usr_dict[name][5] == "": handleUserDisc(clmsg) del usr_dict[name] class ServerNegotiator: def __init__(self, host, port, hostid, rsa_key, buf = 512): negotiator = Negotiator(host, hostid, rsa_key,buf) self.server = SocketServer.TCPServer((host, port), negotiator) def start(self): self.server.serve_forever() Do I need to write the __call__() method as well? From alfps at start.no Wed Feb 10 15:14:54 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 21:14:54 +0100 Subject: Modifying Class Object In-Reply-To: <0382abea$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 09:13:22 +0100, Alf P. Steinbach wrote: > >>> You've >>> dismissed at least one of my arguments with a simple hand-waving of, >>> "That's invalid, cuz." >> That is not a quote of me. It is a lie. > > Alf, although your English in this forum has been excellent so far, I > understand you are Norwegian, so it is possible that you aren't a native > English speaker and possibly unaware that quotation marks are sometimes > ambiguous in English. > > While it is true that quoted text is officially meant to indicate a > direct quote, it is also commonly used in informal text to indicate a > paraphrase. (There are other uses as well, but they don't concern us now.) > > Unfortunately, this means that in informal discussions like this it is > sometimes difficult to distinguish a direct quote from a paraphrase, > except by context. In context, as a native speaker, I can assure you that > Stephen Hansen's use of quotation marks is a paraphrase and not meant to > be read as a direct quote. I'm aware that Stephen Hansen maintains that, but I'm not replying to his ramblings about insanity and so on (perhaps he is a child, but I'm not replying to that kind of stuff). Anyway, in the original article he refererred to part of the quoted text, quoting that in turn as an example of how allegedly patronising (or whatever) I'd been to him. Re-quoting a part *does not make sense* for paraphrasing. And anyway, he wrote a piece where quotes seemed to signify quoting, drawing conclusions from the quoted text. It's just plain lying. Cheers & hth., - Alf From anthony.tolle at gmail.com Wed Feb 10 15:17:51 2010 From: anthony.tolle at gmail.com (Anthony Tolle) Date: Wed, 10 Feb 2010 12:17:51 -0800 (PST) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> On Feb 10, 2:09?pm, kj wrote: > Some people have mathphobia. ?I'm developing a wicked case of > Unicodephobia. > [snip] Some general advice (Looks like I am reiterating what MRAB said -- I type slower :): 1. If possible, use unicode strings for everything. That is, don't use both str and unicode within the same project. 2. If that isn't possible, convert strings to unicode as early as possible, work with them that way, then convert them back as late as possible. 3. Know what type of string you are working with! If a function returns or accepts a string value, verify whether the expected type is unicode or str. 4. Consider switching to Python 3.x, since there is only one string type (unicode). -- From ssteinerx at gmail.com Wed Feb 10 15:19:52 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Wed, 10 Feb 2010 15:19:52 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <72157116-44AD-4F52-BB6E-35BBD629A7A6@gmail.com> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: > On 2010-02-10, python at bdurham.com wrote: > > [regardning "picture" output format specifiers] > >> I was thinking that there was a built-in function for this >> common(?) use case > > I haven't seen that paradigm since my one-and-only exposure to > COBOL in a class I took back in 1979. Is the "picture" thing > commonly used in other places than COBOL? Seriously? I've seen it in dozens places other than COBOL over the years in everything from templating languages to report generators, to built-in support in a variety of languages (dBASE II anyone?). Haven't you ever had to get a e.g. a phone number or social security number from user input? S From tjreedy at udel.edu Wed Feb 10 15:24:39 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Feb 2010 15:24:39 -0500 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: On 2/10/2010 5:21 AM, Quin wrote: > Well, PyScripter works find with that code. Furthermore, the > un-intellisense in IronPython was problematic, inserting the wrong > things, which I had to erase. > > Also, there were some code constructs IronPython let pass that > PyScripter didn't, namely, print(), PyScripter requires the () > > Something simple, like: > n = -1 > if n <> -1: > print('fell through') > > falls through to the print. > > So, I don't know what the problem is with IronPython, perhaps it isn't > compatible with Python v3, but on my machine, at least, it doesn't perform. '<>' is not legal in Python3, so above is not Python3 code. From python.list at tim.thechases.com Wed Feb 10 15:39:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 14:39:44 -0600 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <4B731990.4020400@tim.thechases.com> Grant Edwards wrote: > [regardning "picture" output format specifiers] >> I was thinking that there was a built-in function for this >> common(?) use case > > I haven't seen that paradigm since my one-and-only exposure to > COBOL in a class I took back in 1979. Is the "picture" thing > commonly used in other places than COBOL? I've spotted in the wild as recently as Visual Basic 6. I don't know if remnants made it into Visual Fred (VB.net). I think they're referred to as "format strings", but they're a mystical (and poorly documented) suite of characters that seem to have accrued features like my bathtub gets mildew. Most folks just copy and paste the format strings from the web. -tkc From invalid at invalid.invalid Wed Feb 10 15:40:41 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 20:40:41 +0000 (UTC) Subject: Creating formatted output using picture strings References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: On 2010-02-10, ssteinerX at gmail.com wrote: > On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: > >> On 2010-02-10, python at bdurham.com wrote: >> >> [regardning "picture" output format specifiers] >> >>> I was thinking that there was a built-in function for this >>> common(?) use case >> >> I haven't seen that paradigm since my one-and-only exposure to >> COBOL in a class I took back in 1979. Is the "picture" thing >> commonly used in other places than COBOL? > > Seriously? Seriously. > I've seen it in dozens places other than COBOL over the years > in everything from templating languages to report generators, > to built-in support in a variety of languages (dBASE II > anyone?). > > Haven't you ever had to get a e.g. a phone number or social > security number from user input? Nope. I guess it's specific to certain application areas. I've never done any database type stuff. I do mostly embedded, device drivers, networking/protocols, industrial automation, Unix system admin/automation, and scientific visualization. -- Grant Edwards grante Yow! I once decorated my at apartment entirely in ten visi.com foot salad forks!! From subhakolkata1234 at gmail.com Wed Feb 10 15:42:17 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Wed, 10 Feb 2010 12:42:17 -0800 (PST) Subject: A silly question on file opening Message-ID: Dear Group, I was using Python with IDLE as GUI for quite some time. My Operating System was Windows XP with Service Pack2. Recently I changed the Operating System to Windows XP with Service Pack3. I had to reinstall Python for which I downloaded "python-2.6.4.msi"and loaded it in my D drive. Here, as I am trying to open the file if I am giving a statement like, file_open=open("python26/file","r") It is showing an error, On checking how the files are stored it is showing that it is storing in D drive directly but not in Python folder in D drive there is no Python folder at all. I tried to change the location to D:\file and as I saw in Python Docs the file reading option is now "r+" so I changed the statement to file_open=open("D:\file","r+") but it is still giving error. Did I install it wrongly? If you can please help it out. Best Regards, Subhabrata. From ssteinerx at gmail.com Wed Feb 10 15:52:42 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Wed, 10 Feb 2010 15:52:42 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: On Feb 10, 2010, at 3:40 PM, Grant Edwards wrote: > On 2010-02-10, ssteinerX at gmail.com wrote: >> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: >> >>> On 2010-02-10, python at bdurham.com wrote: >>> >>> [regardning "picture" output format specifiers] >>> >>>> I was thinking that there was a built-in function for this >>>> common(?) use case >>> >>> I haven't seen that paradigm since my one-and-only exposure to >>> COBOL in a class I took back in 1979. Is the "picture" thing >>> commonly used in other places than COBOL? >> >> Seriously? > > Seriously. > >> I've seen it in dozens places other than COBOL over the years >> in everything from templating languages to report generators, >> to built-in support in a variety of languages (dBASE II >> anyone?). >> >> Haven't you ever had to get a e.g. a phone number or social >> security number from user input? > > Nope. I guess it's specific to certain application areas. I've > never done any database type stuff. I do mostly embedded, > device drivers, networking/protocols, industrial automation, > Unix system admin/automation, and scientific visualization. Yah, I've hardly ever had to get SSN input from users in a device driver ;-). That's what makes groups like this go 'round; we have all done different types of things which gives us all different perspectives. S From ethan at stoneleaf.us Wed Feb 10 15:56:02 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 10 Feb 2010 12:56:02 -0800 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: <4B7229D2.8060704@tim.thechases.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> Message-ID: <4B731D62.1010004@stoneleaf.us> Tim Chase wrote: > Any thoughts on how others make the choice? > > -tkc If one branch is only a few lines, it comes first. As often as not, that tiny branch is checking for errors, and the "else" branch doesn't need to be indented. def func(arg1): if arg1 is 'stupid': raise ValueError("that's a stupid argument!") do_something do_something_else etc, etc ~Ethan~ From anthony.tolle at gmail.com Wed Feb 10 15:57:52 2010 From: anthony.tolle at gmail.com (Anthony Tolle) Date: Wed, 10 Feb 2010 12:57:52 -0800 (PST) Subject: A silly question on file opening References: Message-ID: On Feb 10, 3:42?pm, joy99 wrote: > Dear Group, > [snip] > I tried to change the location to D:\file and as I saw in Python Docs > the file reading option is now "r+" so I changed the statement to > ? ?file_open=open("D:\file","r+") > but it is still giving error. Only use "r+" if you need to also write to the file. "r" is still good for opening for reading. Without seeing a traceback, I can only assume the error is caused by using a backslash in the path without escaping it. Try either the following: file_open=open("D:\\file","r+") file_open=open(r"D:\file","r+") For an explanation, see the Python documentation: http://docs.python.org/reference/lexical_analysis.html#string-literals From no.email at please.post Wed Feb 10 16:03:01 2010 From: no.email at please.post (kj) Date: Wed, 10 Feb 2010 21:03:01 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: In <402ac982-0750-4977-adb2-602b19149d81 at m24g2000prn.googlegroups.com> Jonathan Gardner writes: >On Feb 10, 11:09=A0am, kj wrote: >> FWIW, I'm using Python 2.6. =A0The example above happens to come from >> a script that extracts data from HTML files, which are all in >> English, but they are a daily occurrence when I write code to >> process non-English text. =A0The script uses Beautiful Soup. =A0I won't >> post a lot of code because, as I said, what I'm after is not so >> much a way around this specific error as much as the tools and >> techniques to troubleshoot it and fix it on my own. =A0But to ground >> the problem a bit I'll say that the exception above happens during >> the execution of a statement of the form: >> >> =A0 x =3D '%s %s' % (y, z) >> >> Also, I found that, with the exact same values y and z as above, >> all of the following statements work perfectly fine: >> >> =A0 x =3D '%s' % y >> =A0 x =3D '%s' % z >> =A0 print y >> =A0 print z >> =A0 print y, z >> >What are y and z? x = "%s %s" % (table['id'], table.tr.renderContents()) where the variable table represents a BeautifulSoup.Tag instance. >Are they unicode or strings? The first item (table['id']) is unicode, and the second is str. >What are their values? The only easy way I know to examine the values of these strings is to print them, which, I know, is very crude. (IOW, to answer this question usefully, in the context of this problem, more Unicode knowhow is needed than I have.) If I print them, the output for the first one on my screen is "mainTable", and for the second it is Tags Id >It sounds like someone, probably beautiful soup, is trying to turn >your strings into unicode. A full stacktrace would be useful to see >who did what where. Unfortunately, there's not much in the stacktrace: Traceback (most recent call last): File "./download_tt.py", line 427, in x = "%s %s" % (table['id'], table.tr.renderContents()) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 41: ordinal not in range(128) (NB: the difference between this error message and the one I originally posted, namely the position of the unrecognized byte, is because I simplified the code for the purpose of posting it here, eliminating one additional processing of the second entry of the tuple above.) ~K From steve at holdenweb.com Wed Feb 10 16:14:51 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 16:14:51 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > * Duncan Booth: >> "Alf P. Steinbach" wrote: >> >>>> In CPython objects once created remain in the same memory location >>>> (and their id is their address). Compare that to IronPython where the >>>> objects themselves can move around in memory so they have no fixed >>>> address. Try comparing the IronPython implementation to C pointers >>>> and you'll cause a lot of confusion. e.g. someone might think the >>>> id() value is in some way related to an address. >>> Did you /read/ what you quoted? >>> >>> >>>> Ruby implements integers without using any pointers at all: there's >>>> nothing in the Python specification which prevents a Python >>>> implementation doing the same for small integers, in fact I believe >>>> it has been tried but wasn't found to improve performance. >>> All theree of your points about Python are wrong; I don't know about >>> the Ruby point. >> >> Would you care to expand upon your claim that my three points about >> Python are wrong? > > Sure. I already did in the article you're replying to, immediately > following what you quote above. You snipped that which you're asking > for, so I requote: > > > > First, the current Python language specification formally prevents the > optimization you mention, because there's no support for binding to do > anything but direct binding leaving object identities unchanged. > > But in practice that's no big deal though: I can't imagine any code > relying on identities of completely immutable objects. > > Second, even the variant that was tried improved performance. > > But it would reportedly have wreaked havoc with imperfect C code. > > Third, the optimization doesn't do away with pointers. If it did then it > would transform the language completely. The user's view is still one > where names denote pointers. > > > > Since in the quoting above no reference to definition of "pointer" > remains: "pointer" refers to a copyable reference value as seen from the > Python level, in the same way as "pointer" is used by e.g. the Java > language spec. > > >> Are you saying that CPyhton objects move around, or that IronPython >> objects are fixed to a single memory location or that their id is >> related to their address? > > No, I can't see how you can deduce any such connection from I wrote. > > Whether objects "move around" depends on what exactly you mean by "move > around", and given that, it may then depend on the Python implementation. > > However, from the Python point of view every object has a fixed unique > id, available via id(). > > >> Clue here: >> >> IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> x = 42 >>>>> id(x) >> 43 >>>>> y = 43 >>>>> id(y) >> 44 >>>>> z = "whatever" >>>>> id(z) >> 45 >> > > I'm guessing wildly that you're trying to illustrate id's that don't > correspond to memory addresses? > > If so, then that's correct: a Python (or Java, or whatever language) > pointer is not necessarily directly a memory address, and furthermore id > is not guaranteed to reproduce the bits of a pointer value -- which > might not even make sense. > > All that id does is to produce a value that uniquely identifies the > object pointed to, i.e. it corresponds to the pointer value, and > although in CPython that's simply the bits of a C pointer typed as > integer, in IronPython it's not. > You go too far here. What you are referring to in your bizarrely constructed definition above as a pointer does not allow you to access the value that is "pointed to". So I fail to see why you feel its its introduction is necessary. Whether in CPython, Jython or IronPython the value returned by calling id(x) (whether x is a literal, a simple name or a more complex expression) is absolutely no use as an accessor: it does not give you access to the referenced value. If you disagree, please write (in any implementation you like: it need not even be portable, though I can't imagine why ti wouldn't be) a Python function which takes an id() value as its argument and returns the value for which the id() value was provided. So in your world it's unnecessary for pointers to point to anything (or references to refer to something)? For someone who cheerfully admits to being wrong from time to time (an admirable characteristic) you are certainly difficult to convince on this point. One wonders what further hand-waving will follow. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Wed Feb 10 16:18:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 13:18:17 -0800 Subject: New to Python In-Reply-To: References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> Message-ID: <7a9c25c21002101318w2b72f255ga4ee2b643a8ac66d@mail.gmail.com> On Wed, Feb 10, 2010 at 2:21 AM, Quin wrote: > Well, PyScripter works find with that code. Furthermore, the > un-intellisense in IronPython was problematic, inserting the wrong things, > which I had to erase. > I think you're confused and are comparing apples to oranges. To define a couple terms-- I'm starting at the basics, forgive me: Python is a language; CPython is an implementation of that language, in C. Often, Python and CPython are used interchangeably, but not always. There are sort of two concurrent versions of Python available today, both current; 2.6 and 3.1. IronPython is an alternate implementation of the Python 2.6 language, built upon the .NET platform. It's a language, not a tool. (Well, insofar as every language is ultimately a tool). IronPython (like Jython, PyPy, and the other Python alternate implementations) does not yet support Python 3.x. PyScripter is an IDE for Python. IDE's have intellisense and such, languages do not. I'm not sure what you were using as your IDE when you used IronPython-- perhaps IronPython Studio? That's a distinct thing from IronPython itself. PyScripter can support both Python 2.x and 3.x, but I don't know if it requires any settings to change between modes or if you have to select which interpreter you want to use. We can only guess what actual version of Python you're using from your comments, but it looks sort of like 2.x Also, there were some code constructs IronPython let pass that PyScripter > didn't, namely, print(), PyScripter requires the () > > Something simple, like: > n = -1 > if n <> -1: > print('fell through') > > falls through to the print. > PyScripter is not a language, but a tool; in Python 3.x, print requires the () as it is a function. Additionally, in Python 3.x, you have to say "not equal" as !=, you can't use <> anymore. In Python 2.x, print is a statement. You /may/ put () around an expression but that isn't the same thing. For simple operations it frequently looks the same and produces the same output, though. In Python 2.x, you can say "not equal" as either != or <>. The original code: s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' ... will only work on Python 2.x, as print is being used as a statement. If you change print to a function, that code will work in either Python 2.x or Python 3.x. However, in both CPython and IronPython, the above is provably correct code. It works fine: with those five lines alone, you are guaranteed to get 'foundit' followed by 'processing' if mystring is in s. With those five lines alone, you must get that result. If you aren't, then there's something else going on before or after-- and its not about IronPython vs CPython. To help diagnose what's wrong, copy and paste -real- results from a command prompt or interpreter when you run it, providing complete code. Something else is going wrong, you're looking in the wrong place to find the solution. If you're using an IDE, perhaps that IDE is doing something strange (though I can't fathom what), or perhaps its pointing at a different version of Python then you're expecting. We can't really tell from what you've said. So, I don't know what the problem is with IronPython, perhaps it isn't > compatible with Python v3, but on my machine, at least, it doesn't perform. > The current version of IronPython (http://ironpython.net/) is 2.6, yes. They have not yet made a Python 3.x port. Then again, much of the code you've shown us seems to imply you're using Python 2.x, not 3.x. So I can't quite make sense of your environment yet to offer more help-- specifically, you seem to be saying IronPython, but not actually -mean- IronPython, but instead some IDE? --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Wed Feb 10 16:19:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Feb 2010 13:19:14 -0800 Subject: Creating formatted output using picture strings In-Reply-To: <72157116-44AD-4F52-BB6E-35BBD629A7A6@gmail.com> References: <1265822561.1942.1359302945@webmail.messagingengine.com> <72157116-44AD-4F52-BB6E-35BBD629A7A6@gmail.com> Message-ID: <50697b2c1002101319p407af3d7o5333c416b4db9522@mail.gmail.com> On Wed, Feb 10, 2010 at 12:19 PM, ssteinerX at gmail.com wrote: > On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote: >> On 2010-02-10, python at bdurham.com wrote: >> >> [regardning "picture" output format specifiers] >> >>> I was thinking that there was a built-in function for this >>> common(?) use case >> >> I haven't seen that paradigm since my one-and-only exposure to >> COBOL in a class I took back in 1979. Is the "picture" thing >> commonly used in other places than COBOL? > Haven't you ever had to get a e.g. a phone number or social security number from user input? If I have a GUI, I can just put 3 separate length-limited text fields and then I only have to check that the input is numerical and each field is of the right length; no fiddling with punctuation or manual separation into fields; or more likely, there's already a phone number widget! In other words, I won't care about the punctuation characters anyway. If I don't have a GUI: (1) my program is probably not for end-users, so I can be less user-friendly and more dictatorial about the required format (2) or it's munging mediocre data from a DB and I need to be more error-tolerant that picture formatting would allow (3) in any case, it's not *that* hard to do without picture formatting (although it might get tedious after a while, probably hence why some languages in just the right niche indeed offer picture formatting): phone_parts = input("Phone number?: ").replace('(', '').replace(')', '').split('-') if not all(part.isdigit() for part in phone_parts) or [3,3,4] != map(len, phone_parts): #error message to user Stricter validation would either be user-unfriendly or is left as an exercise to the reader. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 16:23:08 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 21:23:08 GMT Subject: A silly question on file opening References: Message-ID: On Wed, 10 Feb 2010 12:42:17 -0800, joy99 wrote: > I tried to change the location to D:\file and as I saw in Python Docs > the file reading option is now "r+" so I changed the statement to > file_open=open("D:\file","r+") > but it is still giving error. You should copy and paste (do not re-type!) the *exact* line that leads to an error, and the full traceback that Python prints. But in this case I can guess what the problem is. Like most C-inspired languages, Python uses backslashes to put in special characters: e.g. \n for newline, \t for tab, and \f for formfeed. So when you try to open "D:\file" you are actually looking for a file on D drive called (chr(12) + "ile"), not "file". The solution to this is to remember that Windows accepts forward slashes as well as backslashes, and always use the forward slash. So try: open("D:/file") and see if that works. >>> print "D:\file" D: ile >>> print "D:/file" D:/file -- Steven From gerald.britton at gmail.com Wed Feb 10 16:27:36 2010 From: gerald.britton at gmail.com (Gerald Britton) Date: Wed, 10 Feb 2010 16:27:36 -0500 Subject: "if {negative}" vs. "if {positive}" style In-Reply-To: <4B731D62.1010004@stoneleaf.us> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <4B7229D2.8060704@tim.thechases.com> <4B731D62.1010004@stoneleaf.us> Message-ID: <5d1a32001002101327j1e2ceff3vd899d493f68443f7@mail.gmail.com> On Wed, Feb 10, 2010 at 3:56 PM, Ethan Furman wrote: > Tim Chase wrote: >> >> Any thoughts on how others make the choice? >> >> -tkc > > If one branch is only a few lines, it comes first. ?As often as not, that > tiny branch is checking for errors, and the "else" branch doesn't need to be > indented. > > def func(arg1): > ? ?if arg1 is 'stupid': > ? ? ? ?raise ValueError("that's a stupid argument!") > ? ?do_something > ? ?do_something_else > ? ?etc, etc > > > ~Ethan~ > -- > http://mail.python.org/mailman/listinfo/python-list > Something similar in a for-loop: for x in y: if not should_process(x): continue # process x -- Gerald Britton From apt.shansen at gmail.com Wed Feb 10 16:33:41 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 13:33:41 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: <7a9c25c21002101333q64006b8bm29ad9b7f82a60973@mail.gmail.com> On Wed, Feb 10, 2010 at 1:03 PM, kj wrote: > >What are y and z? > > x = "%s %s" % (table['id'], table.tr.renderContents()) > > where the variable table represents a BeautifulSoup.Tag instance. > > >Are they unicode or strings? > > The first item (table['id']) is unicode, and the second is str. > The problem is you are mixing unicode and strings; if you want to support unicode at all, you should use it -everywhere- within your program. At the entry-points, you should convert from strings to unicode, then use unicode -exclusively-. Here, you are trying to combine a unicode variable with a string variable, and Python is -trying- to convert it for you, but it can't. I suspect you aren't actually realizing this implicit conversion is going on: Python's trying to produce an output string according to what you've requested. To do that, it is upgrading x from string to unicode, and then writing to that string first table['id'] then table.tr.renderContents(). Its the table.tr.renderContents that, I believe, is your problem: it is a byte string, but it contains encoded data. You have to 'upgrade' it to unicode before you can pump it over into x, because Python doesn't know what encoding that is. It just knows there's a character somewhere in there that doesn't fit into ASCII. I can't quite tell you what the encoding is, though it may be UTF8. Try: table.tr.renderContents().decode("utf8") Its an easy mistake to make. To further illustrate, do this: >>> "%s %s" % (u'hi', u'bye') u'hi bye' Even though you're assigning a regular string to "x", you're using a format str to merge in a unicode string to it. So Python implicitly upgrades your format string, as if you had typed: >>> u"%s %s" % (u'hi', 'bye') Upgrading a string to unicode is easy, provided a string contains nothing but plain ASCII. The moment it contains encoded data, the default translation fails. So you have to explicitly tell Python how to convert the byte string back into unicode-- meaning, you have to decode it. Take this example: >>> s = u"He\u2014llo".encode("utf8") >>> s 'He\xe2\x80\x94llo' >>> "%s %s" % (u'hi', s) Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 2: ordinal not in range(128) >>> "%s %s" % (u'hi', s.decode("utf8")) u'hi He\u2014llo' I started out with a string, "s", containing Hello with an em-dash stuck in the middle. I encoded it as UTF8: its now a byte string similar to what may exist on any webpage you get. Remember, pure "unicode" exists only in memory. Everything on the internet or a file is /encoded/. You work with unicode in memory, then encode it to some form when writing it out-- anywhere. When I first try to combine the two, I get an error like you got. But if I explicitly decode my 's', it all works fine. The encoded form is translated back into unicode. As for how to debug and deal with issues like this... never mix unicode and regular strings, use unicode strings exclusively in your logic, and decode as early as possible. Then the only problem you're likely to run into is situations where a claimed encoding/charset is a lie. (Web servers sometimes claim charset/encoding A, or a file may claim charset/encoding B, even though the file was written out by someone with charset/encoding C... and there's no easy way to go around fixing such situations) HTH, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Wed Feb 10 16:39:33 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 21:39:33 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <4B72CBFF.9020500@optimum.net> <0382bdeb$0$1277$c3e8da3@news.astraweb.com> <0382ef76$0$1277$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano writes: > On Wed, 10 Feb 2010 18:31:23 +0000, Arnaud Delobelle wrote: > >> It's not ideal, but you can use a decorator like this to solve this >> problem: >> >> def bindfunction(f): >> def bound_f(*args, **kwargs): >> return f(bound_f, *args, **kwargs) >> bound_f.__name__ = f.__name__ >> return bound_f > > Ah, very nice. Perhaps it's better to use functools.wraps? > > import functools > > def bindfunction(f): > @functools.wraps(f) > def bound_f(*args, **kwargs): > return f(bound_f, *args, **kwargs) > return bound_f I think I wrote this before functools :). Anyway it still doesn't work with mutually recursive functions. I also tried another approach (can't find the file anymore, so I've redone it, sorry no time to make it very readable) as below. It doesn't require an extra first argument for the function and it takes care of mutually recursive functions if used as in the example. def bindglobals(*args): """ Binds all the globals in all the arguments which must be functions. return the new bound functions. When called with a single argument, return the bound function so it can be used as a decorator. It is assumed that all argument are functions and have the same global namespace """ function_names = [f.__name__ for f in args] def get_global(f, n): d = f.func_globals if n not in d: d = d['__builtins__'].__dict__ return d[n] bound_globals = dict( (n, get_global(f, n)) for f in args for n in f.func_code.co_names if n not in function_names ) bound_functions = [ type(f)(f.func_code, bound_globals, f.func_name, f.func_defaults, f.func_closure) for f in args ] bound_globals.update(zip(function_names, bound_functions)) if len(args) == 1: return bound_functions[0] else: return bound_functions # Example @bindglobals def fac(n): return 1 if n <= 1 else n*fac(n - 1) # Decorator syntax cannot be used with mutually recursive functions: def even(n): return True if not n else odd(n - 1) def odd(n): return False if not n else even(n - 1) even, odd = bindglobals(even, odd) # Example in action: >>> fac(10) 3628800 >>> f = fac >>> fac = 'foo' >>> f(10) 3628800 >>> even(5), odd(5) (False, True) >>> e, o = even, odd >>> even, odd = 'spam', 'eggs' >>> e(5), o(5) (False, True) This is proof of concept stuff - probably very fragile! -- Arnaud From clp2 at rebertia.com Wed Feb 10 16:43:14 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Feb 2010 13:43:14 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: <50697b2c1002101343h5a853325g74c8b470735b95e@mail.gmail.com> On Wed, Feb 10, 2010 at 1:03 PM, kj wrote: > In <402ac982-0750-4977-adb2-602b19149d81 at m24g2000prn.googlegroups.com> Jonathan Gardner writes: >>It sounds like someone, probably beautiful soup, is trying to turn >>your strings into unicode. A full stacktrace would be useful to see >>who did what where. > > Unfortunately, there's not much in the stacktrace: > > Traceback (most recent call last): > File "./download_tt.py", line 427, in > x = "%s %s" % (table['id'], table.tr.renderContents()) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 41: ordinal not in range(128) Think I've found the problem. According to the BeautifulSoup docs, renderContents() returns a (by default, UTF-8-encoded) str [i.e. byte sequence] as opposed to unicode[i.e. abstract code point sequence] . Thus, as was said previously, you're combining the unicode from table['id']and the str from renderContents(), so Python tries to automatically+implicitly convert the str to unicode by decoding it as ASCII. However, it's not ASCII but UTF-8, hence you get the error about it having non-ASCII bytes. Solution: Convert the output of renderContents() back to unicode. x = u"%s %s" % (table['id'], table.tr.renderContents().decode('utf8')) Now only unicode objects are being combined. Your problem is particularly ironic considering how well BeautifulSoup handles Unicode overall; I was unable to locate a renderContents() equivalent that returned unicode. Cheers, Chris -- http://blog.rebertia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 16:46:19 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 21:46:19 GMT Subject: Modifying Class Object References: Message-ID: On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: > "pointer" refers to a copyable reference value as seen from the Python > level, in the same way as "pointer" is used by e.g. the Java language > spec. Python doesn't have "copyable reference values" in the Python level. It has objects. It seems to me that your argument is based on the premises: (1) that the "value" of a variable is not what 99.99% of people would describe as the value, but is some hidden, implementation dependent "pointer" instead; (2) that "pointer" doesn't necessarily mean what 99% of people who learned C or Pascal understand by pointer; (3) that mangling both common English and programmers' expectations in that fashion is somehow more accurate and more useful than using the 35 year old term "call by object" (or "call by object reference"); (4) and, presumably because of some deeply-held belief that the only parameter passing strategies that we're allowed to talk about are "call by value" and "call by reference", no matter how much violence we do to the concept of both value and pointer, Python and Java must be call-by- value since they clearly aren't call-by-reference. Of these, the only one that I consider value is that Python and Java are not call-y-reference. Otherwise, I reject all these premises, and consequently none of your arguments make the slightest sense to me. You keep talking about Python operating on pointers. I've never used a single pointer in 10+ years of Python coding, no matter how many times you tell me I have. What the implementation of the Python virtual machine does is not what I do high-level Python code, and the implementation is not the language. -- Steven From arnodel at googlemail.com Wed Feb 10 16:47:19 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 21:47:19 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> <0382b08c$0$1277$c3e8da3@news.astraweb.com> <7a9c25c21002100756h57d9eb94h78fe68c98a0ed5c2@mail.gmail.com> Message-ID: MRAB writes: > Does this mean that Python needs, say, __function__ (and perhaps also > __module__)? See PEP 3130 "Access to Current Module/Class/Function" (rejected) (http://www.python.org/dev/peps/pep-3130/) -- Arnaud From pavlovevidence at gmail.com Wed Feb 10 16:47:44 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 10 Feb 2010 13:47:44 -0800 (PST) Subject: "if {negative}" vs. "if {positive}" style (was: New to Python) References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> Message-ID: <41a79d8c-65d2-41e3-bb61-5a987b40be1b@w27g2000pre.googlegroups.com> On Feb 9, 7:36?pm, Tim Chase wrote: > Larry Hudson wrote: > > But a minor rearrangement is simpler, and IMHO clearer: > > > if 'mystring' not in s: > > ? ? ?print 'not found' > > else: > > ? ? ?print 'foundit' > > ? ? ?print 'processing' > > I've always vacillated on whether that would better be written as > Larry does, or as > > ? ?if 'mystring' in s > ? ? ?print 'foundit' > ? ? ?print 'processing' > ? ?else: > ? ? ?print 'not found' [pass] > Any thoughts on how others make the choice? I almost always arrange it as follows, regardless of the size of the blocks or whether the condition is negated or not: if (typical-condition): typical-case else: exceptional-case In particular I almost always test if something is not None, because being None is almost always the exceptional case: if x is not None: ... else: ... However, whenever the exceptional case action is to break, return, continue, or raise an exception, I'll test for it and leave the typical case unnested: if (exceptional-condition): exceptional-case typical-case No, it deosn't bother me in the least that I sometimes test for the exceptional case and sometimes for the typical. Whenever there is no typical case or exceptional case I'll go for the simpler condition. Carl Banks From gagsl-py2 at yahoo.com.ar Wed Feb 10 16:49:40 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Feb 2010 18:49:40 -0300 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: En Wed, 10 Feb 2010 10:59:41 -0300, Muhammad Alkarouri escribi?: > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): > f.args = args > print args > > is there any other way? See this: >>> def foo(): pass ... >>> import sys >>> sys.getrefcount(foo) 2 The 2 means that there is a *single* reference to the function - the foo name in the global namespace. No other reference exists, there is no hidden attribute somewhere that you may use. If you want another way to reach the function, you'll have to add it yourself. I've written a decorator for "injecting" a __function__ name into the function namespace, but I can't find it anywhere. I think I implemented it by adding a fake additional argument and replacing LOAD_GLOBAL with LOAD_NAME in the bytecode. > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a > valid one at the moment, sorry. One reason would be to write truly recursive functions (currently, a recursive call involves a name lookup, which could potentially return a different function). Another one, to implement some kind of tail call optimization. -- Gabriel Genellina From jjposner at optimum.net Wed Feb 10 16:55:07 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 16:55:07 -0500 Subject: Creating formatted output using picture strings In-Reply-To: References: <1265822561.1942.1359302945@webmail.messagingengine.com> Message-ID: <4b732b20$0$5011$607ed4bc@cv.net> On 2/10/2010 2:57 PM, Grant Edwards wrote: > On 2010-02-10, python at bdurham.com wrote: > > [regardning "picture" output format specifiers] > >> I was thinking that there was a built-in function for this >> common(?) use case > > I haven't seen that paradigm since my one-and-only exposure to > COBOL in a class I took back in 1979. Is the "picture" thing > commonly used in other places than COBOL? > FWIW, Microsoft Excel supports "Custom" numeric cell formats that use a PICTURE-like syntax. -John From jcd at sdf.lonestar.org Wed Feb 10 16:57:09 2010 From: jcd at sdf.lonestar.org (J. Cliff Dyer) Date: Wed, 10 Feb 2010 16:57:09 -0500 Subject: New to Python In-Reply-To: <7a9c25c21002101318w2b72f255ga4ee2b643a8ac66d@mail.gmail.com> References: <14Cdnb6rubmdUOzWnZ2dnUVZ_gadnZ2d@posted.grandecom> <6eudnY6p35_ute_WnZ2dnUVZ_gWdnZ2d@posted.grandecom> <7a9c25c21002101318w2b72f255ga4ee2b643a8ac66d@mail.gmail.com> Message-ID: <1265839029.5997.11.camel@aalcdl07> On Wed, 2010-02-10 at 13:18 -0800, Stephen Hansen wrote: > > The original code: > > > s = f.readline() > if 'mystring' in s: print 'foundit' > if 'mystring' not in s: print 'not found' > if 'mystring' in s: > print 'processing' > > > ... will only work on Python 2.x, as print is being used as a > statement. If you change print to a function, that code will work in > either Python 2.x or Python 3.x. > > > However, in both CPython and IronPython, the above is provably correct > code. It works fine: with those five lines alone, you are guaranteed > to get 'foundit' followed by 'processing' if mystring is in s. With > those five lines alone, you must get that result. If you aren't, then > there's something else going on before or after-- and its not about > IronPython vs CPython. To help diagnose what's wrong, copy and paste > -real- results from a command prompt or interpreter when you run it, > providing complete code. Something else is going wrong, you're looking > in the wrong place to find the solution. One other assumption that you are making is that f is a file-like object that supports a reasonalbe readline function. Quin: can you Ctrl-C, Ctrl-V the following code into a python file, by itself, and run it to reproduce your problem? from StringIO import StringIO f = StringIO('This string contains mystring') s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' # Should print: # foundit # processing f = StringIO('This string does not contain MyStRiNg') s = f.readline() if 'mystring' in s: print 'foundit' if 'mystring' not in s: print 'not found' if 'mystring' in s: print 'processing' # Should print: # not found And please, humor me and copy and paste the exact results as returned by your IronPython interpreter. From alfps at start.no Wed Feb 10 17:02:27 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 23:02:27 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steve Holden: > Alf P. Steinbach wrote: [snip] >> >> Since in the quoting above no reference to definition of "pointer" >> remains: "pointer" refers to a copyable reference value as seen from the >> Python level, in the same way as "pointer" is used by e.g. the Java >> language spec. >> [snip] >> >> If so, then that's correct: a Python (or Java, or whatever language) >> pointer is not necessarily directly a memory address, and furthermore id >> is not guaranteed to reproduce the bits of a pointer value -- which >> might not even make sense. >> >> All that id does is to produce a value that uniquely identifies the >> object pointed to, i.e. it corresponds to the pointer value, and >> although in CPython that's simply the bits of a C pointer typed as >> integer, in IronPython it's not. >> > You go too far here. What you are referring to in your bizarrely > constructed definition above No, it's not bizarre, it's the standard general language independent definition. And since I'm referring to an external definition (Java) it's not mine, either. :-) > as a pointer does not allow you to access > the value that is "pointed to". So I fail to see why you feel its its > introduction is necessary. Python provides a number of ways to access the object pointed to. Attribute access, indexing, and operators access the objects pointed to. For example, x = s[0] accesses the object that s points (refers) to. While 'is', 'id' and assignment operate on the pointers (references) themselves. So there's one set of language features that operate on pointers, and one set of language features that operate on the pointed to objects. This is so also in Java and C#. For example. > Whether in CPython, Jython or IronPython the value returned by calling > id(x) (whether x is a literal, a simple name or a more complex > expression) is absolutely no use as an accessor: it does not give you > access to the referenced value. Yes, the id does not give you access to the referenced object. > If you disagree, please write (in any implementation you like: it need > not even be portable, though I can't imagine why ti wouldn't be) a > Python function which takes an id() value as its argument and returns > the value for which the id() value was provided. No, I don't disagree with that. It would be excessively inefficient to do, involving enumeration of all objects. > So in your world it's unnecessary for pointers to point to anything (or > references to refer to something)? For someone who cheerfully admits to > being wrong from time to time (an admirable characteristic) you are > certainly difficult to convince on this point. One wonders what further > hand-waving will follow. He he, "further" handwaiving: you're good at unsubstantiated allegations. I generally strive to provide concrete examples, and you know it. Anywyay, treating the first sentence as a genuine question: in the most likely interpretation it seems that you're conflating id's with pointers. An id() value uniquely represents a pointer (i.e., the identity of the object pointed to). It is not itself a pointer since it lack any pointer semantics. For a less likely more technical interpretation, as far as I know in Python there's just one case of a pointer that does not point to anything, namely as exemplified by def foo(): print( x ) x = "whatever" The Java equivalent would say "NullPointerException", in Python it says something like "unbound". Which means the same. Cheers & hth., - Alf From alfps at start.no Wed Feb 10 17:09:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 23:09:25 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Ethan Furman: > Steven D'Aprano wrote: >> >> Believe me Alf, the fact that people are taking the time to try to >> argue with you instead of just kill-filing you is a compliment. > > It's a compliment I am not paying, although I am grateful to those who > are attempting to teach him. At the rate it's going, though, I don't > see myself buying any book he produces. > > Besides the arrogant attitude, he is wrong on so many things about > Python it is truly stunning. That's bullshit. I am probably wrong about many Python things, for this is so no matter the language and the practictioner, but not any that you know about. > He seems to have confidence born of > ignorance... a scary sight to see. > > In the spirit of being helpful and not just being a jerk myself: > > Alf, > > Using smileys after declaring somebody is mistaken/wrong/etc makes you > look bad. > > Not attempting to learn the language makes you look like an arrogant > idiot (case in point: passing-by-object). > > Accusing anyone and everyone that criticizes you of making ad hominem > (sp?) attacks makes you look like a whiner. > > After all is said and done - if you had a truly good grasp of Python, I > might buy your book even if you still had -- ummm -- a less than winning > presence on the mailing list; but right now your understanding is not > worth paying for. > > Hoping-this-helps-but-not-really-expecting-it-to-ly yours, It's yet another ad hominem attack, which means that you're painfully aware of supporting an untenable technical position, or supporting a clique of people. It also reflects rather badly on you. Cheers & hth., - Alf From jjposner at optimum.net Wed Feb 10 17:13:06 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 10 Feb 2010 17:13:06 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B732F72.1030208@optimum.net> On 2/10/2010 1:38 PM, Ethan Furman wrote: > > After all is said and done - if you had a truly good grasp of Python, I > might buy your book even if you still had -- ummm -- a less than winning > presence on the mailing list; but right now your understanding is not > worth paying for. > Alf, here's my suggestion on how to respond to people's criticisms of your technical prowess: come up with the "best ever" description of Python's variable-assignment and argument-passing schemes, and place the description in your manuscript [1]. Section 2.4, "Naming things", currently does not address the issues discussed in this thread ("pass by XXX", etc.). HTH, John [1] http://mail.python.org/pipermail/python-list/2009-December/1229932.html From twistedphrame at gmail.com Wed Feb 10 17:19:50 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Wed, 10 Feb 2010 14:19:50 -0800 (PST) Subject: SimpleXMLRPCServer and client address Message-ID: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> I'm trying to right a server that needs specific information for each client accessing it. The easiest way I could think of doing this is keeping this information based on ip address (the information is only valid for a short time). I know there is no was to get the client's address directly and have seen a few examples of subclassing the SimpleXMLRPCServer like this: class RPCServer(SimpleXMLRPCServer): def _dispatch(self, method, params): """Extend dispatch, adding client info to some parameters.""" if method in ({my list of methods I needed client address}): return SimpleXMLRPCServer._dispatch(self, method, params+(self.client_address,)) return SimpleXMLRPCServer._dispatch(self, method, params); but to be honest I don't understand what's going on there or how to use it. Would anyone be able to explain this to me? From arnodel at googlemail.com Wed Feb 10 17:19:50 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 10 Feb 2010 22:19:50 +0000 Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: "Alf P. Steinbach" writes: [...] > That's bullshit. [...] > not any that you know about. [...] > yet another ad hominem attack [...] > It also reflects rather badly on you. [...] > - Alf Alf, The above was extracted from the last post from you but I could have picked almost any of your recent endeavours. I've come to the conclusion that you're not a cute furry alien with a long nose. You're a big bad troll! -- Arnaud From icanbob at gmail.com Wed Feb 10 17:19:55 2010 From: icanbob at gmail.com (bobicanprogram) Date: Wed, 10 Feb 2010 14:19:55 -0800 (PST) Subject: strange issue with C extension using Py_BuildValue Message-ID: I'm am having "strange" problems with the code snip below. When this code is built on a 64bit Linux, it would appear to work flawlessly. When the source is rebuilt on a 32bit Linux it begins to crack in strange ways. The issue seems to be associated with the sender field in the Py_BuildValue call. The fact that sender is a pointer should mean that its value is an unsigned integer. However, on the 32 bit build the failure is that the msgPtr->data value is "messed up". If the format associated with the sender (a pointer) from "L" to "i" things work on the 32 bit side but break on the 64 bit side. I fully understand that an address will be stored differently on the 64bit vs. the 32bit systems. The problem is that the code is recompiled from source in both cases so shouldn't the "L" format work as expected in both architectures? Furthermore, how can an incorrect format result in messing up the field which follows? Thanks in advance for any help. bob PS. The Python side using this extension isn't expecting to do anything with the sender parameter other than store it for later use as a parameter in a Reply() function call. ie. an address goes from extension ->Python -> extension. ========= begin code snip =================== static PyObject *simpl_receive(PyObject *self, PyObject *args) { int ret; char *sender; FCMSG_REC *msgPtr; // call the actual simpl C library function ret = Receive(&sender, NULL, 0); // what sort of message are we dealing with? if (ret > 0) // message { msgPtr = (FCMSG_REC *)sender; return( Py_BuildValue("iLz#", ret, sender, &msgPtr->data, ret) ); } ========== end code snip ============ From ldo at geek-central.gen.new_zealand Wed Feb 10 17:30:24 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 11 Feb 2010 11:30:24 +1300 Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> <4b712919$0$6584$9b4e6d93@newsspool3.arcor-online.net> Message-ID: In message <4b712919$0$6584$9b4e6d93 at newsspool3.arcor-online.net>, Stefan Behnel wrote: > Usually PyPI. Where do you think these tools come from? They don?t write themselves, you know. From gagsl-py2 at yahoo.com.ar Wed Feb 10 17:37:36 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 10 Feb 2010 19:37:36 -0300 Subject: How to measure elapsed time under Windows? References: Message-ID: En Wed, 10 Feb 2010 13:15:22 -0300, Grant Edwards escribi?: > On 2010-02-09, Gabriel Genellina wrote: >> En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards >> escribi?: >> >>> What's the correct way to measure small periods of elapsed >>> time. I've always used time.clock() in the past: >>> However on multi-processor machines that doesn't work. >>> Sometimes I get negative values for delta. According to >>> google, this is due to a bug in Windows that causes the value >>> of time.clock() to be different depending on which core in a >>> multi-core CPU you happen to be on. [insert appropriate >>> MS-bashing here] >> >> I'm not sure you can blame MS of this issue; anyway, this >> patch should fix the problem: >> http://support.microsoft.com/?id=896256 > > I'm curious why it wouldn't be Microsoft's fault, because > > A) Everything is Microsoft's fault. ;) > > B) If a patch to MS Windows fixes the problem, how is it not a > problem in MS Windows? I won't argue against A) because its truthness (?) is self-evident :) 99% of my code does not run in Python 3.x; I may fix it and it will eventually run fine, but that doesn't mean it's *my* fault. The original problem was with the RDTSC instruction on multicore CPUs; different cores may yield different results because they're not synchronized at all times. Windows XP was launched in 2001, and the first dual core processors able to execute Windows were AMD Opteron and IBM Pentium D, both launched around April 2005 (and targeting the server market, not the home/desktop market of Windows XP). How could MS know in 2001 of a hardware issue that would happen four years in the future? Guido seems very jealous of his time machine and does not lend it to anyone. -- Gabriel Genellina From invalid at invalid.invalid Wed Feb 10 17:40:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 10 Feb 2010 22:40:34 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: Message-ID: On 2010-02-09, Gabriel Genellina wrote: > In code, using SetProcessAffinityMask and related functions: > http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx That solves the problem. If I don't set the process affinity mask, I regularly get measurements that are off by 6ms. I presume 6ms is the skew between the two cores' performance counter values. I don't know if that difference is stable or how it varies, but now it doesn't matter. :) -- Grant Edwards grante Yow! If our behavior is at strict, we do not need fun! visi.com From misceverything at gmail.com Wed Feb 10 17:55:22 2010 From: misceverything at gmail.com (T) Date: Wed, 10 Feb 2010 14:55:22 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> Message-ID: <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> On Feb 9, 4:25?pm, David Bolen wrote: > David Bolen writes: > > Not from my past experience - the system account (LocalSystem for > > services) can be surprising, in that it's pretty much unlimited access > > to all local resources, but severely limited in a handful of cases, > > one of which is any attempt to access the network. ?I can't recall for > > sure if it's an absolute block, or if in some cases you can configure > > around it (e.g., it might use a null session for remote shares which > > can be enabled through the registry on the target machine). ?I've > > basically stuck "LocalSystem = no network" in my head from past > > experience. > > Given it's been a few years, I decided to try some tests, and the > above is too simplistic. > > The LocalSystem account runs without any local Windows credentials > (e.g., not like a logged in user), which has several consequences. > One is that you can't access any network resources that require such > credentials (like shares). ?However, there's no sort of firewall > filtering or anything, so plain old TCP/IP connections are fine. > Unless, of course, the client being used also has other needs for > local Windows credentials, independent or as a pre-requisite to the > network operations. > > So backing up a bit, the TCP/IP connection that plink is making is not > inherently disabled by running under LocalSystem, but it's certainly > possible that plink is trying to identify the user under which it is > operating to perhaps identify ssh keys or other local resources it > needs to operate. ?You might be able to cover this with command line > options (e.g., plink supports "-i" to specify a key file to use), but > you'll also need to ensure that the file you are referencing is > readable by the LocalSystem account. > > One of the other responders had a very good point about locating plink > in the first place too. ?Services run beneath an environment that is > inherited from the service control manager process, and won't include > various settings that are applied to your user when logged in, > especially things like local path changes, and working directories. > Should you change the system path (via the environment settings), > you'll need to reboot for the service control manager to notice - I > don't think you can restart it without a reboot. > > So it's generally safer to be very clear, and absolute when possible, > in a service for paths to external resources. > > The prior advice of running the service as an identified user (e.g., > with local credentials) is still good as it does remove most of these > issues since if you can run the script manually under that user you > know it'll work under service. ?But it's not a hard requirement. > > If your script is dying such that a top level exception is being > raised you should be able to find it in the application event log. ?So > that might give further information on what about the different > environment is problematic. > > You can also use the win32traceutil module to help with grabbing debug > output on the fly. ?Import the module in your service, which will > implicitly redirect stdout/stderr to a trace buffer. ?Run the same > win32traceutil module from the command line in another window. ?Then > start the service. ?Any stdout/stderr will be reflected in the other > window. ?Can't catch everything (suppressed exceptions, or I/O that > doesn't flow through the script's stdout/stderr), but again might help > point in the right direction. > > -- David Great suggestions once again - I did verify that it was at least running the plink.exe binary when under LocalSystem by having the service run "plink.exe > C:\plinkoutput.txt" - this worked fine. And, as I mentioned, it's now working just fine when running under a regular admin account. So, I think that's going to be my solution to avoid any further issues. My best guess at this point (as you mentioned), is that plink.exe is doing _something_ network-related that LocalSystem doesn't have the privileges to do - what exactly it is, I have no idea. I may play around with it some more later, but running the service under an admin account should be a perfectly acceptable solution. Also, I will be writing other Python apps that the service will be executing - so it goes without saying that I'll be including a log to file option :) Thanks again for all your guys' help! From alfps at start.no Wed Feb 10 17:56:36 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 10 Feb 2010 23:56:36 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: > >> "pointer" refers to a copyable reference value as seen from the Python >> level, in the same way as "pointer" is used by e.g. the Java language >> spec. > > Python doesn't have "copyable reference values" in the Python level. It > has objects. Given s = [1] t = s # Copies reference. t[0] = 2 # Changes referenced object via copied reference. print( s ) # Checks the object via the original reference. your argument that the copied reference does not exist, is just silly. And you know it. > It seems to me that your argument is based on the premises: > > (1) that the "value" of a variable is not what 99.99% of people would > describe as the value, but is some hidden, implementation dependent > "pointer" instead; No. The Python language spec defines what value of an object means. And people use "value" with many different meanings, using Common Sense to arbitrate. It would be senseless to try to pin down a single meaning of the word "value". You're arguing against a position unrelated to mine. > (2) that "pointer" doesn't necessarily mean what 99% of people who > learned C or Pascal understand by pointer; No. But although this is "just" a terminological issue, it's worth discussing. I refuse to believe that 99% of C and Pascal programmers believe that "pointer" only refers to the pointer implementation in their language of choice. In my first article in this thread I specifically referred to the Java language specification, which says, first sentence in ?4.3.1 in the 3.0 spec, that "The reference values (often just references) are pointers to these objects, and a special null reference, which refers to no object." which is relevant to Python because Java has the same semantics, although Java "NullPointerException" is called "unbound" in Python (but this is again just terminology, not semantics). I.e., the general pointer term /can/ be used, and is used, for reference values. Only a willingness to misinterpret can cause confusion, at least when the terminology is defined, as I've done all the time. Secondly I referred (actually that was in response to you) to a Stanford University introduction to pointers, comparing four languages including Java. I didn't refer you to Wikipedia because that article seems to lack mention of reference based languages and does include a reference to an article that I wrote about pointers in C++ (now off-net), and given the noise level here it would therefore probably not help. > (3) that mangling both common English and programmers' expectations in > that fashion is somehow more accurate and more useful than using the 35 > year old term "call by object" (or "call by object reference"); No, I haven't stated any opposition to using that term; the archives show the opposite. So for the second time here you're arguing against a silly position that I do not hold. > (4) and, presumably because of some deeply-held belief that the only > parameter passing strategies that we're allowed to talk about are "call > by value" and "call by reference", no matter how much violence we do to > the concept of both value and pointer, Python and Java must be call-by- > value since they clearly aren't call-by-reference. Well that's the third time here that you're arguing against a silly position that I do not hold. > Of these, the only one that I consider value is that Python and Java are > not call-y-reference. Otherwise, I reject all these premises, Good rejection as far as 1, 3 and 4 are concerned. Regarding the term "pointer", your point 2, I strongly encourage you to seek out the sources I've referenced and quoted. For without a common language it's difficult to communicate, and if Python programmers should continue to not understand common terms then that would just further flame wars such as this thread has escalated to. Please seek out sources. Don't just take my word, instead, read e.g. what I've quoted, try out the example I've given, and so on: be critical (to your own assumptions also!). > and > consequently none of your arguments make the slightest sense to me. Well, you'd first have to examine at least one of my arguments. In this article you haven't, instead attacking a number of positions that I haven't advocated and do not hold, except for your silly denial of existence of references at the top. But that's just silly -- consider the concrete example given. > You > keep talking about Python operating on pointers. I've never used a single > pointer in 10+ years of Python coding, no matter how many times you tell > me I have. What the implementation of the Python virtual machine does is > not what I do high-level Python code, and the implementation is not the > language. Here again you're conflating things and engage in a kind of denial coupled with a correct argument. It's hard to argue against such confusion. Instead I've tried above to address your only relevant point, by a concrete example. Summing up, denying the existence of references, as you do at the top, is just silly; do consider the code example. Your points 1, 3 and 4 attack positions that I do not hold and have not advocated. Your point 2, about terminology, is important on its own. And I suggest you check out the references I've given. And read what I quoted from the language specification of a language with the same semantics as Python. Cheers & hth., - Alf From dmalcolm at redhat.com Wed Feb 10 18:03:32 2010 From: dmalcolm at redhat.com (David Malcolm) Date: Wed, 10 Feb 2010 18:03:32 -0500 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> References: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> Message-ID: <1265843012.8386.17.camel@brick> On Wed, 2010-02-10 at 12:17 -0800, Anthony Tolle wrote: > On Feb 10, 2:09 pm, kj wrote: > > Some people have mathphobia. I'm developing a wicked case of > > Unicodephobia. > > [snip] > > Some general advice (Looks like I am reiterating what MRAB said -- I > type slower :): > > 1. If possible, use unicode strings for everything. That is, don't > use both str and unicode within the same project. > > 2. If that isn't possible, convert strings to unicode as early as > possible, work with them that way, then convert them back as late as > possible. > > 3. Know what type of string you are working with! If a function > returns or accepts a string value, verify whether the expected type is > unicode or str. > > 4. Consider switching to Python 3.x, since there is only one string > type (unicode). Some further nasty gotchas: 5. Be wary of the encoding of sys.stdout (and stderr/stdin), e.g. when issuing a "print" statement: they can change on Unix depending on whether the python process is directly connected to a tty or not. (a) If they're directly connected to a tty, their encoding is taken from the locale, UTF-8 on my machine: [david at brick ~]$ python -c 'print u"\u03b1\u03b2\u03b3"' ??? (prints alpha, beta, gamma to terminal, though these characters might not survive being sent in this email) (b) If they're not (e.g. cronjob, daemon, within a shell pipeline, etc) their encoding is the default encoding, which is typically ascii; rerunning the same command, but piping into "cat": [david at brick ~]$ python -c 'print u"\u03b1\u03b2\u03b3"'| cat Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) (c) These problems can lurk in sources and only manifest themselves during _deployment_ of code. You can set PYTHONIOENCODING=ascii in the environment to force (a) to behave like (b), so that your code will fail whilst you're _developing_ it, rather than on your servers at midnight: [david at brick ~]$ PYTHONIOENCODING=ascii python -c 'print u"\u03b1\u03b2 \u03b3"' Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) (Given the above, it could be argued perhaps that one should never "print" unicode instances, and instead should write the data to file-like objects, specifying an encoding. Not sure). 6. If you're using pygtk (specifically the "pango" module, typically implicitly imported), be warned that it abuses the C API to set the default encoding inside python, which probably breaks any unicode instances in memory at the time, and is likely to cause weird side effects: [david at brick ~]$ python Python 2.6.2 (r262:71600, Jan 25 2010, 13:22:47) [GCC 4.4.2 20100121 (Red Hat 4.4.2-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getdefaultencoding() 'ascii' >>> import pango >>> sys.getdefaultencoding() 'utf-8' (the above is on Fedora 12, though I'd expect to see the same weirdness on any linux distro running gnome 2) Python 3 will probably make this all much easier; you'll still have to care about encodings when dealing with files/sockets/etc, but it should be much more clear what's going on. I hope. Hope this is helpful Dave From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 18:11:10 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 10 Feb 2010 23:11:10 GMT Subject: Modifying Class Object References: Message-ID: On Wed, 10 Feb 2010 23:02:27 +0100, Alf P. Steinbach wrote: > For a less likely more technical interpretation, as far as I know in > Python there's just one case of a pointer that does not point to > anything, namely as exemplified by > > def foo(): > print( x ) > x = "whatever" > > The Java equivalent would say "NullPointerException", in Python it says > something like "unbound". Which means the same. Not in plain language. NullPointerException means that x is assigned to a null pointer, and you have tried to follow that pointer. Unbound means that x has nothing assigned to it. Semantically, the difference is somewhat analogous to the situations: "the president is dead, and a new president hasn't yet been appointed" (the office of the president is currently assigned to a dead guy) versus "the king has dissolved parliament and with it the office of president" (there is no president at all) Now, of course we understand that in the implementation of CPython, local variables are stored efficiently in slots in an array, and you can't have empty slots: every address always has some bit pattern. It is very likely that the CPython implementation uses a nil pointer to indicate an empty slot just like Java does. The difference is that Java exposes that implementation decision as part of the language specification, while Python deliberately does not. It isn't an accident that the Python exception describes the *semantics* of the error (x is not bound to any value) rather than the implementation detail (the slot known as x has a nil pointer in it). Semantically, the Python language treats the slot as empty and leaves the details of how the implementation recognises empty slots as an implementation decision. I'm just as interested by the implementation decisions made in CPython as the next guy, but they don't effect the semantics of the high level Python language. Here is a thought experiment for you: One can imagine an implementation of Python that eschews all pointers for some scheme by which objects are cleverly copied and synchronized as needed. Such an implementation would still be Python, but it would be entirely pointer-free. -- Steven From pengyu.ut at gmail.com Wed Feb 10 18:23:42 2010 From: pengyu.ut at gmail.com (Peng Yu) Date: Wed, 10 Feb 2010 15:23:42 -0800 (PST) Subject: Is a merge interval function available? Message-ID: I'm wondering there is already a function in python library that can merge intervals. For example, if I have the following intervals ('[' and ']' means closed interval as in http://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_endpoints) [1, 3] [2, 9] [10,13] [11,12] I want to get the following merged intervals. [1,9] [10,13] Could somebody let me know if there is a function in the python library? From alfps at start.no Wed Feb 10 18:34:05 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 00:34:05 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 23:02:27 +0100, Alf P. Steinbach wrote: > >> For a less likely more technical interpretation, as far as I know in >> Python there's just one case of a pointer that does not point to >> anything, namely as exemplified by >> >> def foo(): >> print( x ) >> x = "whatever" >> >> The Java equivalent would say "NullPointerException", in Python it says >> something like "unbound". Which means the same. > > Not in plain language. NullPointerException means that x is assigned to a > null pointer, and you have tried to follow that pointer. Unbound means > that x has nothing assigned to it. No, it's the same. String x; somethingIDontRememberProbablyIo.println( x ) // Java equivalent It's just different terminology, "NullPointerException" versus "unbound". It's the same semantics. Nothing substantial is changed by changing the Java message or changing the Python message. The word is just a word. > Semantically, the difference is > somewhat analogous to the situations: > > "the president is dead, and a new president hasn't yet been appointed" > (the office of the president is currently assigned to a dead guy) > > versus > > "the king has dissolved parliament and with it the office of president" > (there is no president at all) > > Now, of course we understand that in the implementation of CPython, local > variables are stored efficiently in slots in an array, and you can't have > empty slots: every address always has some bit pattern. It is very likely > that the CPython implementation uses a nil pointer to indicate an empty > slot just like Java does. The difference is that Java exposes that > implementation decision as part of the language specification, while > Python deliberately does not. How a Python implementation implements local variables is irrelevant, except that since references to local variables can be copied and *live on*, be used, after a call, it has to work as if it uses implementation level pointers. The notion of pointers (references) at the language level is not the same as the notion of pointers at the implementation level. This is the same as the notion of integers at the Python 3.x level (unbounded values) is not the same as the notion of integers at the C or C# or Java level (depending on the Python implementation, bounded values with wrap-around or undefined behavior). I.e. you're conflating two levels here. You can perhaps more easily see that by considering an implementation of Python in Python, using some computed counter as object id's. It doesn't change the user view of copyable references. But it hides all that C pointer stuff two or three abstraction levels down so that it becomes meaningless to talk about it. > It isn't an accident that the Python exception describes the *semantics* > of the error (x is not bound to any value) rather than the implementation > detail (the slot known as x has a nil pointer in it). Semantically, the > Python language treats the slot as empty and leaves the details of how > the implementation recognises empty slots as an implementation decision. > > I'm just as interested by the implementation decisions made in CPython as > the next guy, but they don't effect the semantics of the high level > Python language. Right. > Here is a thought experiment for you: > > One can imagine an implementation of Python that eschews all pointers for > some scheme by which objects are cleverly copied and synchronized as > needed. Such an implementation would still be Python, but it would be > entirely pointer-free. Uhm, bad example (it wouldn't work exactly as described), but concerning what I think you're trying to /communicate/, that X at the Python level is not the same as X at the implementation level, like, 'int' at the Python 3.x level is not 'int' in C, and like, "pointer" at the Python level is not "pointer" in C: yes. Cheers & hth., - Alf From rhodri at wildebst.demon.co.uk Wed Feb 10 18:35:19 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 10 Feb 2010 23:35:19 -0000 Subject: Python Logic Map/Logic Flow Chart. (Example Provided) References: <60293adf-71e9-4700-b2a8-ca12525ce7d0@e33g2000prn.googlegroups.com> <656ca700-95e7-4f1b-b312-2b169e39c050@e19g2000prn.googlegroups.com> Message-ID: On Tue, 09 Feb 2010 07:35:51 -0000, Gary Herron wrote: > spike wrote: >> On Feb 8, 1:35 pm, Gary Herron wrote: >> >>> spike wrote: >>> >>>> Has anyone been able to come across a Python logic map or Python logic >>>> flow chart? >>>> An example can be seen on the right under History: >>>> http://en.wikipedia.org/wiki/Usenet#History >>>> This would be very helpful for all users. >>>> >>> Huh??? What aspect of Python were you thinking of mapping out? >>> >>> Your example us a bad ascii art graph of -- I've no clue what? >>> >>> Gary Herron >>> >> >> Do you know what "Logic" means? Guess not. Before you comedians quit >> your day job some people are looking for information. If you have >> nothing positive to say, go pester somewhere else. >> >> Grow up. >> > > Why the attitude? I wouldn't have asked for a clarification if I didn't > want to help. However, I seriously have *no* idea what the OP has asked > for when he says "Python logic map". Do you? If so, then answer the > poor guy's question instead of whining at me. (And I'll respectfully > read your answer, just to see how you interpret "Python logic map".) Er, Gary, that *is* the OP. He's just much better at being peeved than at clearly explaining what he wants. And sorry, but I have no idea what Python logic maps or Python logic flow charts either, or even what a inter-network connectivity diagram might have to do with them. An expansion of the original question is definitely in order. -- Rhodri James *-* Wildebeeste Herder to the Masses From wayne.dads.bell at gmail.com Wed Feb 10 19:16:23 2010 From: wayne.dads.bell at gmail.com (dads) Date: Wed, 10 Feb 2010 16:16:23 -0800 (PST) Subject: sqlite3 bug? Message-ID: When the method below is run it raises 'sqlite3.OperationalError: no such table: dave'. the arguments are ds = a datestamp and w = a string of digits. The path of the db is C:\sv_zip_test\2006\2006.db and the table is definitely named dave. I've run the sql in sql manager and it works. Is this a bug? def findArchive(self, ds, w): year = ds.GetYear() if year < 2005: wx.MessageBox('Year out of Archive, check the date!') return year = str(year) archive = 'C:/sv_zip_test' dbfp = os.path.abspath(os.path.join(archive, year, year + '.db')) if os.path.exists(dbfp): con = sqlite3.connect('dbfp') cur = con.cursor() #cur.execute("SELECT * FROM dave WHERE webno = ?", [w]) cur.execute("SELECT * FROM dave") for r in cur: self.fil.AppendText(r[2] + '\n') else: wx.MessageBox('no db, %s' % dbfp) From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 19:26:40 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Feb 2010 00:26:40 GMT Subject: Is a merge interval function available? References: Message-ID: On Wed, 10 Feb 2010 15:23:42 -0800, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. For example, if I have the following intervals ('[' and > ']' means closed interval as in > http://en.wikipedia.org/wiki/Interval_(mathematics) #Excluding_the_endpoints) Not in the standard library. There may be third-party libraries that do it. Did you google "python interval"? -- Steven From python.list at tim.thechases.com Wed Feb 10 19:38:13 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 18:38:13 -0600 Subject: sqlite3 bug? In-Reply-To: References: Message-ID: <4B735175.9020704@tim.thechases.com> dads wrote: > When the method below is run it raises 'sqlite3.OperationalError: no > such table: dave'. > the arguments are ds = a datestamp and w = a string of digits. The > path of the db is > C:\sv_zip_test\2006\2006.db and the table is definitely named dave. > I've run the sql > in sql manager and it works. Is this a bug? > > dbfp = os.path.abspath(os.path.join(archive, year, year + '.db')) > if os.path.exists(dbfp): > con = sqlite3.connect('dbfp') did you mean connect(dbfp) instead of connect('dbfp') ? -tkc From list-sink at trainedmonkeystudios.org Wed Feb 10 19:44:13 2010 From: list-sink at trainedmonkeystudios.org (Terrence Cole) Date: Wed, 10 Feb 2010 16:44:13 -0800 Subject: Bizarre arithmetic results Message-ID: <1265849053.24800.38.camel@localhost> Can someone explain to me what python is doing here? Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -0.1 ** 0.1 -0.7943282347242815 >>> a = -0.1; b = 0.1 >>> a ** b (0.7554510437117542+0.2454609236416552j) >>> -abs(a ** b) -0.7943282347242815 Why does the literal version return the signed magnitude and the variable version return a complex? Cheers, Terrence From davidism at gmail.com Wed Feb 10 19:48:39 2010 From: davidism at gmail.com (David) Date: Wed, 10 Feb 2010 16:48:39 -0800 (PST) Subject: Get __doc__ from main module in imported module. Message-ID: I have a module toolkit.py with some functions I use often. One of these functions displays a usage message (__doc__). def usage(messages=[], exit=-1): """Print the doc string as wells as any useful messages.""" print(__doc__) for message in messages: print("\033[91m{}\033[0m".format(message)) if exit >= 0: sys.exit(exit) I import this module into another module, with the doc string I want to display. However, calling usage prints toolkit's doc string (None), not the current module's doc string. How can I access the top level module's doc string from toolkit? From no.email at please.post Wed Feb 10 19:50:50 2010 From: no.email at please.post (kj) Date: Thu, 11 Feb 2010 00:50:50 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: In Duncan Booth writes: >kj wrote: >> But to ground >> the problem a bit I'll say that the exception above happens during >> the execution of a statement of the form: >> >> x = '%s %s' % (y, z) >> >> Also, I found that, with the exact same values y and z as above, >> all of the following statements work perfectly fine: >> >> x = '%s' % y >> x = '%s' % z >> print y >> print z >> print y, z >> >One of y or z is unicode, the other is str. Yes, that was the root of the problem. >1. Print the repr of each value so you can see which is which. Thanks for pointing out repr; it's really useful when dealing with Unicode headaches. Thanks for all the replies! ~K From ahleniusm at gmail.com Wed Feb 10 20:17:17 2010 From: ahleniusm at gmail.com (m_ahlenius) Date: Wed, 10 Feb 2010 17:17:17 -0800 (PST) Subject: question on storing dates in a tuple Message-ID: Hi, I have a weird question about tuples. I am getting some dates from a mysql db, using the mysqldb interface. I am doing a standard query with several of the fields are "datetime" format in mysql. When I retrieve and print them in python, they look fine. eg. storeddate = 2010-02-07 12:03:41 But when I append these dates into a string to write to an ascii log file, they come out as: datetime.datetime(2010, 2, 7, 12, 03, 41) (or something along those lines). It appears that I am dealing with some sort of date object here. So I am just trying to understand what's going on, and whats the best work with such objects. thanks 'mark From skippy.hammond at gmail.com Wed Feb 10 20:24:30 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 11 Feb 2010 12:24:30 +1100 Subject: strange issue with C extension using Py_BuildValue In-Reply-To: References: Message-ID: <4B735C4E.3040408@gmail.com> On 11/02/2010 9:19 AM, bobicanprogram wrote: > I'm am having "strange" problems with the code snip below. > > When this code is built on a 64bit Linux, it would appear to work > flawlessly. When the source is rebuilt on a 32bit Linux it begins > to crack in strange ways. The issue seems to be associated with the > sender field in the Py_BuildValue call. The fact that sender is a > pointer should mean that its value is an unsigned integer. However, > on the 32 bit build the failure is that the msgPtr->data value is > "messed up". If the format associated with the sender (a pointer) > from "L" to "i" things work on the 32 bit side but break on the 64 bit > side. I expect that in a 32bit build of linux, a "long long" (the 'L' format) is still 64 bits. You probably want something like: Py_BuildValue("iNz#", ret, PyLong_FromVoidPtr(sender), &msgPtr->data, ret); and PyLong_AsVoidPtr() for the other direction. HTH, Mark From mludvig at logix.net.nz Wed Feb 10 20:25:10 2010 From: mludvig at logix.net.nz (Michal Ludvig) Date: Thu, 11 Feb 2010 14:25:10 +1300 Subject: ignoring some placeholders in string formatting Message-ID: <4B735C76.9040505@logix.net.nz> Hi all, when I've got a string, say: URL="http://xyz/blah?session=%(session)s&message=%(message)s" is it possible to fill in only 'session' and leave "%(message)s" as is when it isn't present in the values dict? For example: URL % { 'session' : 123 } raises KeyError because of missing 'message' in the dict. I could indeed replace '%(session)s' with a string replace or regexp but that's not very elegant ;-) Is there any way to tell the formatter to use only what's available and ignore the rest? Thanks Michal From clp2 at rebertia.com Wed Feb 10 20:30:52 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 10 Feb 2010 17:30:52 -0800 Subject: question on storing dates in a tuple In-Reply-To: References: Message-ID: <50697b2c1002101730t60532036i3ef4a853d10c2d9f@mail.gmail.com> On Wed, Feb 10, 2010 at 5:17 PM, m_ahlenius wrote: > Hi, > > I have a weird question about tuples. ?I am getting some dates from a > mysql db, using the mysqldb interface. ?I am doing a standard query > with several of the fields are "datetime" format in mysql. > When I retrieve and print them in python, they look fine. > > eg. > storeddate = 2010-02-07 12:03:41 > > But when I append these dates ?into a string to write to an ascii ?log > file, they come out as: > > datetime.datetime(2010, 2, 7, 12, 03, 41) ? ?(or something along those > lines). > > It appears that I am dealing with some sort of date object here. ? So > I am just trying to understand what's going on, and whats the best > work with such objects. http://docs.python.org/library/datetime.html#datetime.datetime >>> from datetime import datetime >>> now = datetime.now() >>> print str(now) 2010-02-10 17:22:12.459277 >>> print repr(now) datetime.datetime(2010, 2, 10, 17, 22, 12, 459277) >>> print (now,) (datetime.datetime(2010, 2, 10, 17, 22, 12, 459277),) tuples use repr() on their elements when they're converted to strings, and repr() on datetime-s uses the constructor notation as opposed to the more normal notation used by str(). Same sort of thing happens with strings; note the presence/lack of quotes: >>> string = "aa" >>> print str(string) aa >>> print repr(string) 'aa' >>> print (string,) ('aa',) Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Wed Feb 10 20:31:37 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 02:31:37 +0100 Subject: Get __doc__ from main module in imported module. In-Reply-To: References: Message-ID: * David: > I have a module toolkit.py with some functions I use often. One of > these functions displays a usage message (__doc__). > > def usage(messages=[], exit=-1): > """Print the doc string as wells as any useful messages.""" > print(__doc__) > for message in messages: > print("\033[91m{}\033[0m".format(message)) Consider using a terminal control library such as 'curses' instead of embedding escape sequences directly in the text, since escape sequences vary from terminal to terminal. > if exit >= 0: > sys.exit(exit) > > I import this module into another module, with the doc string I want > to display. However, calling usage prints toolkit's doc string > (None), not the current module's doc string. The function doesn't know where it's called from. You have to tell it, or dynamically create a module-specific function. One way to tell it is to pass the current module as an argument. > How can I access the top level module's doc string from toolkit? Like import __main__ print_usage( __main__ ) with suitable definition of 'usage'. Cheers & hth., - Alf From rhodri at wildebst.demon.co.uk Wed Feb 10 20:36:11 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Feb 2010 01:36:11 -0000 Subject: question on storing dates in a tuple References: Message-ID: On Thu, 11 Feb 2010 01:17:17 -0000, m_ahlenius wrote: > Hi, > > I have a weird question about tuples. I am getting some dates from a > mysql db, using the mysqldb interface. I am doing a standard query > with several of the fields are "datetime" format in mysql. > When I retrieve and print them in python, they look fine. > > eg. > storeddate = 2010-02-07 12:03:41 > > But when I append these dates into a string to write to an ascii log > file, they come out as: > > datetime.datetime(2010, 2, 7, 12, 03, 41) (or something along those > lines). > > It appears that I am dealing with some sort of date object here. So > I am just trying to understand what's going on, and whats the best > work with such objects. You're getting Python datetime objects: rhodri at gnudebst:~$ 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. >>> import datetime >>> now = datetime.datetime.today() >>> print str(now) 2010-02-11 01:30:03.749223 >>> print repr(now) datetime.datetime(2010, 2, 11, 1, 30, 3, 749223) See http://docs.python.org/library/datetime.html#datetime-objects for details of what you can do with them. In your case, you probably just want to use "str()" to explicitly convert the object into a string. -- Rhodri James *-* Wildebeeste Herder to the Masses From jeanmichel at sequans.com Wed Feb 10 20:36:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Feb 2010 02:36:15 +0100 Subject: SimpleXMLRPCServer and client address In-Reply-To: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> Message-ID: <4B735F0F.6080503@sequans.com> Jordan Apgar wrote: > I'm trying to right a server that needs specific information for each > client accessing it. The easiest way I could think of doing this is > keeping this information based on ip address (the information is only > valid for a short time). I know there is no was to get the client's > address directly and have seen a few examples of subclassing the > SimpleXMLRPCServer like this: > > class RPCServer(SimpleXMLRPCServer): > > def _dispatch(self, method, params): > """Extend dispatch, adding client info to some parameters.""" > if method in ({my list of methods I needed client address}): > return SimpleXMLRPCServer._dispatch(self, method, > params+(self.client_address,)) > return SimpleXMLRPCServer._dispatch(self, method, params); > > > but to be honest I don't understand what's going on there or how to > use it. Would anyone be able to explain this to me? > I don't know exactly what you are trying to do, but if your server requires informations from the client, it would be better to ask explicitly the client for those informations. For instance, if a method requires te client IP address, then the IP address is definitely a parameter of the method. JM From python.list at tim.thechases.com Wed Feb 10 20:53:44 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 10 Feb 2010 19:53:44 -0600 Subject: ignoring some placeholders in string formatting In-Reply-To: <4B735C76.9040505@logix.net.nz> References: <4B735C76.9040505@logix.net.nz> Message-ID: <4B736328.806@tim.thechases.com> Michal Ludvig wrote: > URL="http://xyz/blah?session=%(session)s&message=%(message)s" > > is it possible to fill in only 'session' and leave "%(message)s" as is > when it isn't present in the values dict? > > For example: > URL % { 'session' : 123 } > raises KeyError because of missing 'message' in the dict. > > I could indeed replace '%(session)s' with a string replace or regexp but > that's not very elegant ;-) You can use a defaultdict instead of a regular dict: from collections import defaultdict d = defaultdict(str) d['session'] = 123 URL="http://xyz/blah?session=%(session)s&message=%(message)s" print URL % d -tkc From steven at REMOVE.THIS.cybersource.com.au Wed Feb 10 21:11:38 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Feb 2010 02:11:38 GMT Subject: ignoring some placeholders in string formatting References: Message-ID: On Thu, 11 Feb 2010 14:25:10 +1300, Michal Ludvig wrote: > Hi all, > > when I've got a string, say: > > URL="http://xyz/blah?session=%(session)s&message=%(message)s" > > is it possible to fill in only 'session' and leave "%(message)s" as is > when it isn't present in the values dict? No, but instead see string templates: http://docs.python.org/library/string.html#template-strings -- Steven From davidism at gmail.com Wed Feb 10 21:32:28 2010 From: davidism at gmail.com (David) Date: Wed, 10 Feb 2010 18:32:28 -0800 (PST) Subject: Get __doc__ from main module in imported module. References: Message-ID: <7775b9dd-7692-4f43-92b3-9c155e9c21ff@a17g2000pre.googlegroups.com> > > How can I access the top level module's doc string from toolkit? > > Like > > ? ? ?import __main__ > ? ? ?print_usage( __main__ ) > > with suitable definition of 'usage'. > > Cheers & hth., > > - Alf Problem solved! Thanks for the other tips too. From python at mrabarnett.plus.com Wed Feb 10 21:51:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 02:51:06 +0000 Subject: ignoring some placeholders in string formatting In-Reply-To: <4B735C76.9040505@logix.net.nz> References: <4B735C76.9040505@logix.net.nz> Message-ID: <4B73709A.8070201@mrabarnett.plus.com> Michal Ludvig wrote: > Hi all, > > when I've got a string, say: > > URL="http://xyz/blah?session=%(session)s&message=%(message)s" > > is it possible to fill in only 'session' and leave "%(message)s" as is > when it isn't present in the values dict? > > For example: > URL % { 'session' : 123 } > raises KeyError because of missing 'message' in the dict. > > I could indeed replace '%(session)s' with a string replace or regexp but > that's not very elegant ;-) > > Is there any way to tell the formatter to use only what's available and > ignore the rest? > You could write a class inheriting from dict which, for example, returns "%(key)s" if the key "key" is absent: >>> class IgnoreDict(dict): def __getitem__(self, key): try: return dict.__getitem__(self, key) except KeyError: return "%%(%s)s" % key >>> d = {'session': 123} >>> URL = "http://xyz/blah?session=%(session)s&message=%(message)s" >>> URL % d Traceback (most recent call last): File "", line 1, in URL % d KeyError: 'message' >>> URL % IgnoreDict(d) 'http://xyz/blah?session=123&message=%(message)s' From steve at holdenweb.com Wed Feb 10 21:51:42 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 21:51:42 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Ethan Furman: >> Steven D'Aprano wrote: >>> >>> Believe me Alf, the fact that people are taking the time to try to >>> argue with you instead of just kill-filing you is a compliment. >> >> It's a compliment I am not paying, although I am grateful to those who >> are attempting to teach him. At the rate it's going, though, I don't >> see myself buying any book he produces. >> >> Besides the arrogant attitude, he is wrong on so many things about >> Python it is truly stunning. > > That's bullshit. I am probably wrong about many Python things, for this > is so no matter the language and the practictioner, but not any that you > know about. > So your accomplishments include mind-reading now, and you understand everything that Stephen knows and does not know about? That's a startling and, I suggest, untenable claim. > >> He seems to have confidence born of ignorance... a scary sight to see. >> >> In the spirit of being helpful and not just being a jerk myself: >> >> Alf, >> >> Using smileys after declaring somebody is mistaken/wrong/etc makes you >> look bad. >> >> Not attempting to learn the language makes you look like an arrogant >> idiot (case in point: passing-by-object). >> >> Accusing anyone and everyone that criticizes you of making ad hominem >> (sp?) attacks makes you look like a whiner. >> >> After all is said and done - if you had a truly good grasp of Python, >> I might buy your book even if you still had -- ummm -- a less than >> winning presence on the mailing list; but right now your understanding >> is not worth paying for. >> >> Hoping-this-helps-but-not-really-expecting-it-to-ly yours, > > It's yet another ad hominem attack, which means that you're painfully > aware of supporting an untenable technical position, or supporting a > clique of people. > So now the whole thing boils down to "Alf against the world"? The reminds me of the story about the woman who went to see her son qualify from his basic army training. When asked what she thought of the parade she said it was very nice, but that "everyone but our Alf was out of step". I am unsure at this stage what it would take to convince you that you are not only wrong about several important aspects of Python but also wrong-headed. Whenever anyone points out any aspect of your behavior which is unacceptable or ignorant you trot out this accusation that people are making "ad hominem attacks" as though commenting on aspects of your personality is an attempt to undermine your arguments. It isn't. The two are orthogonal. Your arguments are wrong *and* you are behaving like a pratt. A change in either one of these aspects would improve matters, but each seems as unlikely as the other. > It also reflects rather badly on you. Sigh. We're all out of step again, obviously. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From kirby.urner at gmail.com Wed Feb 10 22:10:42 2010 From: kirby.urner at gmail.com (kirby.urner at gmail.com) Date: Wed, 10 Feb 2010 19:10:42 -0800 (PST) Subject: FWD: Lore about Division Message-ID: <47257550-587f-4ae6-b909-655a3dff1024@k18g2000prf.googlegroups.com> Alan: 2^(1/2) Kirby: Also pow(2, 0.5) in Python. Alan: Gee, I wonder if pow(2, (1/2)) also works in Python? Kirby: It does if you remember integer division in earlier versions, such that one needed: from __future__ import division or, simply made it 1./2 or 1/2. or something, to force a floating point answer. In 3.x, division is natively floating, with // to force an integer output. [ EDITOR'S NOTE: not quite right, may be floating type output with integer value ] This is Python 3.1, right out of the box: >>> pow(2, 1/2) 1.4142135623730951 Alan: That reminds me of FORTRAN http://en.wikipedia.org/wiki/Fortran_language_features#Implicit_and_explicit_typing "Unless specified otherwise, all variables starting with letters I, J, K, L, M and N are default INTEGER, and all others are default REAL; other data types must be explicitly declared. This is known as implicit typing and is a heritage of early FORTRAN days." Kirby: I think the original intent was something like "closure" i.e. int / int should give int, whereas float / float or float / int or int / float should coerce float answer, and that is how it was done. However it was later realized, by Guido and others, that in source code, when you see a / b, you really have no way of knowing what's going through there, i.e. a and b might name anything, so it gets hard to debug if the behavior is so dependent on 1 versus 3 use cases. Better to just have a consistent float output, no matter what. Then use // if you want to force an integer value output, even if you input floats to get floats back: >>> 1.//2. 0.0 >>> 1/2 0.5 >>> 3.//2. 1.0 It's quite basic to a language, how it deals with division, so Guido had to devise a scheme that would let the snake "shed its skin". Already, the brand name (Python) was in his favor, as that's what Pythons do (shed skin). A lot of basic changes piled up, including a more complete move to a Unicode basis for source files. If you're going to break backward compatibility, might as well do a lot of breaking all at once. As of this writing, we're on the other end of it, having made the leap from 2.x to 3.x. The backward incompatibility gap has been crossed. However, a number of important libraries and other assets still need to bring up the rear, so a new PEP (Python Enhancement Proposal) has been accepted, to freeze Python for awhile, in terms of its core syntax and semantics. Give the library people some breathing room. This seems a good plan. [ original context: http://groups.yahoo.com/group/synergeo/ ] From wuwei23 at gmail.com Wed Feb 10 22:22:27 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Feb 2010 19:22:27 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <6da47c86-b533-4d54-8b8a-d68feb2c4101@v20g2000prb.googlegroups.com> catonano wrote: > You know what I'm doing now ? I'm drawing the map of > twisted.web.client on a paper with a pencil :-( You're a programmer. Why are you complaining about the problem instead of endeavouring to solve it? From tjreedy at udel.edu Wed Feb 10 22:25:00 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Feb 2010 22:25:00 -0500 Subject: Function attributes In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: On 2/10/2010 4:49 PM, Gabriel Genellina wrote: > I've written a decorator for "injecting" a __function__ name into the > function namespace, but I can't find it anywhere. I think I implemented > it by adding a fake additional argument and replacing LOAD_GLOBAL with > LOAD_NAME in the bytecode. The decorator only needs to replace the defaults args tuple. It does not even need to know the parameter name, just that it is the only (or last) with a default . def f(n, me=None): if n > 0: return n*me(n-1) elif n==0: return 1 f.__defaults__ = (f,) # 3.1 print(f(5)) # 120 To generalize: def g(a,b=1,me=None): if a: return me(0) else: return 41+b g.__defaults__ = g.__defaults__[:len(g.__defaults__)-1] + (g,) print(g(3)) #42 Of course, user could still screw up recursion by providing another value for 'me'. This strikes me as about a likely (low) as a user screwing up recursion in a library module function by rebinding the name in the imported module. Terry Jan Reedy From alfps at start.no Wed Feb 10 22:36:51 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 04:36:51 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steve Holden: > > So now the whole thing boils down to "Alf against the world"? The > reminds me of the story about the woman who went to see her son qualify > from his basic army training. When asked what she thought of the parade > she said it was very nice, but that "everyone but our Alf was out of step". Considering your frequent ad hominem attacks (and this is yet one more), you seem to think that social coercion works well for establishing engineering solutions or scientific truth. That's a misconception. Social matters and matters of engineering or science are different things. > I am unsure at this stage what it would take to convince you that you > are not only wrong about several important aspects of Python but also > wrong-headed. You might start by starting a thread about one such thing; I'll correct you if you're wrong about something I know, or if you demonstrate that I'm wrong about something, then I'll be happy to learn something, as always. It would be a nice change from your extreme focus on my person, if you could manage to discuss something technical. > Whenever anyone points out any aspect of your behavior > which is unacceptable or ignorant you trot out this accusation that > people are making "ad hominem attacks" as though commenting on aspects > of your personality is an attempt to undermine your arguments. That's an ad hominem attack, albeit a pretty silly one. Your behavior, with ad hominem, coercion, insinuations, misrepresentations and so forth the basic ingredients, is completely unacceptable to me, by the way. It's like a bully in the schoolyard. > It isn't. The two are orthogonal. Your arguments are wrong *and* you are > behaving like a pratt. A change in either one of these aspects would > improve matters, but each seems as unlikely as the other. > >> It also reflects rather badly on you. > > Sigh. We're all out of step again, obviously. If you had any argument that held regarding the technical, then I think you (and I mean the singular you) would have tried it by now. But instead, you engage in this bullying behavior. Cheers, - Alf From nobody at nowhere.com Wed Feb 10 22:37:06 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 11 Feb 2010 03:37:06 +0000 Subject: A silly question on file opening References: Message-ID: On Wed, 10 Feb 2010 21:23:08 +0000, Steven D'Aprano wrote: > The solution to this is to remember that Windows accepts forward slashes > as well as backslashes, and always use the forward slash. So try: > > open("D:/file") > > and see if that works. The solution is not to hard-code pathnames in your source file. Read the base directory from an environment variable, registry key, or configuration file, and use os.path.join() to construct paths relative to that directory. On Unix, there are situations which require hard-coding pathnames, e.g. the path to the package's system-wide configuration file. But on Windows, there isn't a single directory whose name is fixed. "Windows" isn't guaranteed to be on "C:", and the other standard directories typically have names which vary by language. Hard-coding "Program Files" is a quick way to guarantee that your software won't work on systems using a language other than English. From lanyjie at yahoo.com Wed Feb 10 22:40:54 2010 From: lanyjie at yahoo.com (Yingjie Lan) Date: Wed, 10 Feb 2010 19:40:54 -0800 (PST) Subject: expy 0.6 released Message-ID: <155225.21818.qm@web54203.mail.re2.yahoo.com> Hi: EXPY (http://expy.sourceforge.net/) is an express way to extend Python. Why consider expy? Here are some good reasons: (I). WYSIWYG. The expy project enables you to write your module in Python the way your extension would be (WYSIWYG), and meanwhile write your implementation in pure C. You specify your modules, functions, methods, classes, and even their documentations the usual way of writing your Python correspondences. Then provide your implementation to the functions/methods by returning a multi-line string. By such an arrangement, everything falls in its right place, and your extension code becomes easy to read and maintain. Also, the generated code is very human-friendly. (II). You only provide minimal information to indicate your intension of how your module/class would function in Python. So your extension is largely independent from the Python extension API. As your interaction with the Python extension API is reduced to minimal (you only care about the functionality and logic), it is then possible that your module written in expy can be independent of changes in the extension API. (III). The building and setup of your project can be automatically done with the distutil tool. In the tutorial, there are ample examples on how easily this is achieved. (IV). Very light weight. The expy tool is surprisingly light weight dispite of its powerful ability, as it is written in pure Python. There is no parser or compiler for code generation, but rather the powerful reflexion mechanism of Python is exploited in a clever way to generate human-friendly codes. Currently, generating code in C is supported, however, the implementation is well modularized and code generation in other languages such as Java and C++ should be easy. Currently, EXPY/CXPY works with Python 2.5, 2.6. I haven?t tested with Python 2.7 or 3.x (for 3.x, need to use the code tool first, and I am not sure if the C API for 3.x has changed much, if you happen to try it out, let me know what happened). While there are already a couple of other projects trying to simply this task with different strategies, such as Cython, Pyrex and modulator, this project is unique and charming in its own way. All you need is the WYSIWYG Python file for your module extension, then expy takes care of everything else. What follows in this documentation is on how to extend Python in C using expy-cxpy: the module expy helps define your module, while module cxpy helps generate C codes for your defined module. Yingjie From nobody at nowhere.com Wed Feb 10 22:48:05 2010 From: nobody at nowhere.com (Nobody) Date: Thu, 11 Feb 2010 03:48:05 +0000 Subject: Is a merge interval function available? References: Message-ID: On Wed, 10 Feb 2010 15:23:42 -0800, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. For example, if I have the following intervals ('[' > and ']' means closed interval as in > http://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_endpoints) > > [1, 3] > [2, 9] > [10,13] > [11,12] > > I want to get the following merged intervals. > > [1,9] > [10,13] > > Could somebody let me know if there is a function in the python > library? No, but try this: def merge(intervals): if not intervals: return [] intervals = sorted(intervals, key = lambda x: x[0]) result = [] (a, b) = intervals[0] for (x, y) in intervals[1:]: if x <= b: b = max(b, y) else: result.append((a, b)) (a, b) = (x, y) result.append((a, b)) return result From steve at holdenweb.com Wed Feb 10 22:49:15 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 22:49:15 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: > [snip] >>> >>> Since in the quoting above no reference to definition of "pointer" >>> remains: "pointer" refers to a copyable reference value as seen from the >>> Python level, in the same way as "pointer" is used by e.g. the Java >>> language spec. >>> > [snip] >>> >>> If so, then that's correct: a Python (or Java, or whatever language) >>> pointer is not necessarily directly a memory address, and furthermore id >>> is not guaranteed to reproduce the bits of a pointer value -- which >>> might not even make sense. >>> >>> All that id does is to produce a value that uniquely identifies the >>> object pointed to, i.e. it corresponds to the pointer value, and >>> although in CPython that's simply the bits of a C pointer typed as >>> integer, in IronPython it's not. >>> >> You go too far here. What you are referring to in your bizarrely >> constructed definition above > > No, it's not bizarre, it's the standard general language independent > definition. > *The* standard general language independent definition? As defined where? The id() value doesn't "correspond to the pointer value", it corresponds to the object. Why you see the need for this indirection remains a mystery. > And since I'm referring to an external definition (Java) it's not mine, > either. :-) > > >> as a pointer does not allow you to access >> the value that is "pointed to". So I fail to see why you feel its its >> introduction is necessary. > > Python provides a number of ways to access the object pointed to. > > Attribute access, indexing, and operators access the objects pointed to. No, they access the objects. In the IronPython implementation, for example, it has already been shown quite clearly that the id value is simply an attribute of the object, whose values are incremented by one for each new object. > > For example, > > x = s[0] > > accesses the object that s points (refers) to. It accesses (the first element of) the object bound to the name "s". > > While 'is', 'id' and assignment operate on the pointers (references) > themselves. > The 'is' operator is a simple test for equality of ids of the objects resulting from the evaluation of two expressions. The expressions can be literals, simple names, or any other valid Python expression. They are *not* pointers, or references. id() simply returns a unique value identifying a particular object. In CPython, where objects do not migrate in memory once created, the memory address of the object is used. In IronPython each object is assigned an id when it is created, and that value is stored as an attribute. > So there's one set of language features that operate on pointers, and > one set of language features that operate on the pointed to objects. > This is so also in Java and C#. For example. > > >> Whether in CPython, Jython or IronPython the value returned by calling >> id(x) (whether x is a literal, a simple name or a more complex >> expression) is absolutely no use as an accessor: it does not give you >> access to the referenced value. > > Yes, the id does not give you access to the referenced object. > Well at least we have found one aspect of Python we agree on. > >> If you disagree, please write (in any implementation you like: it need >> not even be portable, though I can't imagine why ti wouldn't be) a >> Python function which takes an id() value as its argument and returns >> the value for which the id() value was provided. > > No, I don't disagree with that. > Good. > It would be excessively inefficient to do, involving enumeration of all > objects. > > >> So in your world it's unnecessary for pointers to point to anything (or >> references to refer to something)? For someone who cheerfully admits to >> being wrong from time to time (an admirable characteristic) you are >> certainly difficult to convince on this point. One wonders what further >> hand-waving will follow. > > He he, "further" handwaiving: you're good at unsubstantiated allegations. > I am simply pointing out that to make your point you are relying on abstractions which increasingly diverge from the reality of the Python language. I don't think it's unreasonable to describe that as "hand-waving". You apparently do. > I generally strive to provide concrete examples, and you know it. > Again with the mind-reading: you appear to have convinced yourself that you are an authority on what I know. > Anywyay, treating the first sentence as a genuine question: in the most > likely interpretation it seems that you're conflating id's with > pointers. An id() value uniquely represents a pointer (i.e., the > identity of the object pointed to). It is not itself a pointer since it > lack any pointer semantics. > No, it doesn't uniquely represent a pointer, it uniquely represents an *object*. > For a less likely more technical interpretation, as far as I know in > Python there's just one case of a pointer that does not point to > anything, namely as exemplified by > > def foo(): > print( x ) > x = "whatever" > > The Java equivalent would say "NullPointerException", in Python it says > something like "unbound". Which means the same. > Be careful when comparing static and dynamic languages. Java, being a static language, has no equivalent to Python's NameError and AttributeError, which both represent situations in which no object has been bound to a name. In those cases it isn't that the name exists and is bound to a "null pointer", it's simply that the name doesn't exist. So there is no "copyable reference value". regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Wed Feb 10 22:56:49 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 19:56:49 -0800 Subject: SimpleXMLRPCServer and client address In-Reply-To: <4B735F0F.6080503@sequans.com> References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> <4B735F0F.6080503@sequans.com> Message-ID: <7a9c25c21002101956x1298f01euc40285c2227a0598@mail.gmail.com> On Wed, Feb 10, 2010 at 5:36 PM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > I don't know exactly what you are trying to do, but if your server requires > informations from the client, it would be better to ask explicitly the > client for those informations. > For instance, if a method requires te client IP address, then the IP > address is definitely a parameter of the method. > I can't answer the OP, as I don't know the answer to his specific question-- but er, asking a client to provide one's IP address is not really a very workable solution. There's no way to really determine your own IP address in a reliable way. All the usual methods (e.g., socket.gethostbyname(socket.gethostname())) can fail and/or be wrong in some not terribly uncommon situations. The only reliable way to get such a piece of information is to connect to a server, and ask that server what address you were connecting to them as. Even then, that IP may not be the same as an IP you use to connect to say, a different server (on a different network) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 10 23:03:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 23:03:29 -0500 Subject: Is a merge interval function available? In-Reply-To: References: Message-ID: Nobody wrote: > On Wed, 10 Feb 2010 15:23:42 -0800, Peng Yu wrote: > >> I'm wondering there is already a function in python library that can >> merge intervals. For example, if I have the following intervals ('[' >> and ']' means closed interval as in >> http://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_endpoints) >> >> [1, 3] >> [2, 9] >> [10,13] >> [11,12] >> >> I want to get the following merged intervals. >> >> [1,9] >> [10,13] >> >> Could somebody let me know if there is a function in the python >> library? > > No, but try this: > > def merge(intervals): > if not intervals: > return [] > intervals = sorted(intervals, key = lambda x: x[0]) Since Python uses lexical sorting and the intervals are lists isn't the key specification redundant here? > result = [] > (a, b) = intervals[0] > for (x, y) in intervals[1:]: > if x <= b: > b = max(b, y) > else: > result.append((a, b)) > (a, b) = (x, y) > result.append((a, b)) > return result > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From apt.shansen at gmail.com Wed Feb 10 23:13:17 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 10 Feb 2010 20:13:17 -0800 Subject: Modifying Class Object In-Reply-To: References: Message-ID: <7a9c25c21002102013l4a5eb26ay2f684b8e1ba35256@mail.gmail.com> On Wed, Feb 10, 2010 at 7:49 PM, Steve Holden wrote: > *The* standard general language independent definition? As defined where? > Wait, what happened here? This thread started a couple days ago; you pointed out its futility, and even knowing better, I jumped in the deep end. When I realized the futility, you rightly I-told-you-so'd me. You didn't have to pick up my slack ;) On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden wrote: > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Wed Feb 10 23:19:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 23:19:52 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> >> So now the whole thing boils down to "Alf against the world"? The >> reminds me of the story about the woman who went to see her son qualify >> from his basic army training. When asked what she thought of the parade >> she said it was very nice, but that "everyone but our Alf was out of >> step". > > Considering your frequent ad hominem attacks (and this is yet one more), > you seem to think that social coercion works well for establishing > engineering solutions or scientific truth. > > That's a misconception. > So now I understand neither engineering nor science? I find that assertion offensive, though unsurprising. > Social matters and matters of engineering or science are different things. > I am hardly ignorant of that, as you should know from my many past writings on both aspects of Python usage. You are attempting to teach your grandmother to suck eggs. > >> I am unsure at this stage what it would take to convince you that you >> are not only wrong about several important aspects of Python but also >> wrong-headed. > > You might start by starting a thread about one such thing; I'll correct > you if you're wrong about something I know, or if you demonstrate that > I'm wrong about something, then I'll be happy to learn something, as > always. > > It would be a nice change from your extreme focus on my person, if you > could manage to discuss something technical. > See below. > >> Whenever anyone points out any aspect of your behavior >> which is unacceptable or ignorant you trot out this accusation that >> people are making "ad hominem attacks" as though commenting on aspects >> of your personality is an attempt to undermine your arguments. > > That's an ad hominem attack, albeit a pretty silly one. > [facepalm] > Your behavior, with ad hominem, coercion, insinuations, > misrepresentations and so forth the basic ingredients, is completely > unacceptable to me, by the way. > > It's like a bully in the schoolyard. > I am attempting to persuade, not to coerce. > >> It isn't. The two are orthogonal. Your arguments are wrong *and* you are >> behaving like a pratt. A change in either one of these aspects would >> improve matters, but each seems as unlikely as the other. >> >>> It also reflects rather badly on you. >> >> Sigh. We're all out of step again, obviously. > > If you had any argument that held regarding the technical, then I think > you (and I mean the singular you) would have tried it by now. > > But instead, you engage in this bullying behavior. > My (technical) views on your insistence that Python's semantics require the use of pointers to explain them is ongoing elsewhere, and remains open for you to refute. In this particular part of the thread I am attempting, unsuccessfully, to convince you that a change in *your* behavior would lead to less hostility directed towards the way you present your ideas. You apparently feel it is quite acceptable to tell people to "learn to read", and calling their assertions "bullshit", but when we try to point out aspects of your behavior that are either undesirable or unacceptable we are indulging in "ad hominem attacks". In your terms, your accusing me of bullying behavior is an ad hominem attack on me, so I won't bother to respond further. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 10 23:21:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 10 Feb 2010 23:21:08 -0500 Subject: Modifying Class Object In-Reply-To: <7a9c25c21002102013l4a5eb26ay2f684b8e1ba35256@mail.gmail.com> References: <7a9c25c21002102013l4a5eb26ay2f684b8e1ba35256@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Wed, Feb 10, 2010 at 7:49 PM, Steve Holden > wrote: > > *The* standard general language independent definition? As > defined where? > > > Wait, what happened here? > > This thread started a couple days ago; you pointed out its futility, and > even knowing better, I jumped in the deep end. When I realized the > futility, you rightly I-told-you-so'd me. > > You didn't have to pick up my slack ;) > > On Mon, Feb 8, 2010 at 6:42 PM, Steve Holden > wrote: > > Of course this won't make the slightest difference. "'When I use a > word,' said Humpty ..." Yes, but someone on the Internet is wrong, dammit, I can't go to bed yet. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From daniel at stutzbachenterprises.com Wed Feb 10 23:27:30 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 10 Feb 2010 22:27:30 -0600 Subject: Is a merge interval function available? In-Reply-To: References: Message-ID: On Wed, Feb 10, 2010 at 5:23 PM, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. > Not in the standard library, but this package may help: http://pypi.python.org/pypi/interval -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken at seehart.com Wed Feb 10 23:42:25 2010 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Feb 2010 20:42:25 -0800 Subject: regex to match python string literal syntax Message-ID: <4B738AB1.2030702@seehart.com> I found this: http://code.activestate.com/recipes/475109/ But it is incorrect in some cases, such as: * "foo \" bar"* / (incorrectly matches "foo \")/ * '''* /(incorrectly matches the second two single quotes)/ *" foo bar "* / (incorrectly matches quote containing newline/) Anyone know a regular expression that correctly matches python string literals? Thanks in advance, Ken -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Wed Feb 10 23:49:01 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 05:49:01 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >> [snip] >>>> Since in the quoting above no reference to definition of "pointer" >>>> remains: "pointer" refers to a copyable reference value as seen from the >>>> Python level, in the same way as "pointer" is used by e.g. the Java >>>> language spec. >>>> >> [snip] >>>> If so, then that's correct: a Python (or Java, or whatever language) >>>> pointer is not necessarily directly a memory address, and furthermore id >>>> is not guaranteed to reproduce the bits of a pointer value -- which >>>> might not even make sense. >>>> >>>> All that id does is to produce a value that uniquely identifies the >>>> object pointed to, i.e. it corresponds to the pointer value, and >>>> although in CPython that's simply the bits of a C pointer typed as >>>> integer, in IronPython it's not. >>>> >>> You go too far here. What you are referring to in your bizarrely >>> constructed definition above >> No, it's not bizarre, it's the standard general language independent >> definition. >> > *The* standard general language independent definition? Yes. > As defined where? For example, as I used as reference in my first posting, the Java language spec. But it has nothing specifically to do with Java. It is a basic concept in computer science, that (most) CS students learn in their *first year*. E.g. A pointer stores a reference to something. Unfortunately there is no fixed term for the thing that the pointer points to, and across different computer languages there is a wide variety of things that pointers point to. We use the term pointee for the thing that the pointer points to, and we stick to the basic properties of the pointer/pointee relationship which are true in all languages. The term "reference" means pretty much the same thing as "pointer" -- "reference" implies a more high-level discussion, while "pointer" implies the traditional compiled language implementation of pointers as addresses. For the basic pointer/pointee rules covered here, the terms are effectively equivalent. Note that that discussion at Stanford University has several Java examples + a FAQ about the application of the term "pointer" to Java (plus of course that that's specified by the language spec), so "implies ... pointers as addresses" is not smart to get too focused on. Some common sense is required. As mentioned, it is for first-year students. But anyway, this is just terminology; if you don't like the term, then invent or suggest one that you're able to grok or think others will more likely grok. > The id() value doesn't "correspond to the pointer value", it > corresponds to the object. Why you see the need for this indirection > remains a mystery. The language specifies pointer semantics, that's all. You can copy and replace references. So, they quack like pointers, waddle like pointers and look like pointers: = pointers. >> And since I'm referring to an external definition (Java) it's not mine, >> either. :-) >> >> >>> as a pointer does not allow you to access >>> the value that is "pointed to". So I fail to see why you feel its its >>> introduction is necessary. >> Python provides a number of ways to access the object pointed to. >> >> Attribute access, indexing, and operators access the objects pointed to. > > No, they access the objects. What's the difference between "access the objects" and "access the objects"? I'm not genuinely interested in how you came up with this amazing rebuttal, it was a rhetorical question only. But I note that the only difference seems to be that you don't want the objects to be referenced (pointed to) by anything, removing that bit of text, which would make it a bit problematic to apply /any/ operation... > In the IronPython implementation, for > example, it has already been shown quite clearly that the id value is > simply an attribute of the object, whose values are incremented by one > for each new object. Please demonstrate how that is relevant to whatever you're arguing. >> For example, >> >> x = s[0] >> >> accesses the object that s points (refers) to. > > It accesses (the first element of) the object bound to the name "s". Yes. >> While 'is', 'id' and assignment operate on the pointers (references) >> themselves. >> > The 'is' operator is a simple test for equality of ids of the objects > resulting from the evaluation of two expressions. The expressions can be > literals, simple names, or any other valid Python expression. Yes. > They are *not* pointers, or references. Simple demonstration that they're references (have reference semantics): s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. It's pretty hard to argue seriously against this without committing a number of fallacies. Denial is of course easy, and you've done that, but it's at best just childish. > id() simply returns a unique value identifying a particular object. In > CPython, where objects do not migrate in memory once created, the memory > address of the object is used. In IronPython each object is assigned an > id when it is created, and that value is stored as an attribute. Yes. >> So there's one set of language features that operate on pointers, and >> one set of language features that operate on the pointed to objects. >> This is so also in Java and C#. For example. >> >>> Whether in CPython, Jython or IronPython the value returned by calling >>> id(x) (whether x is a literal, a simple name or a more complex >>> expression) is absolutely no use as an accessor: it does not give you >>> access to the referenced value. >> Yes, the id does not give you access to the referenced object. >> > Well at least we have found one aspect of Python we agree on. Oh, good. :-) >>> If you disagree, please write (in any implementation you like: it need >>> not even be portable, though I can't imagine why ti wouldn't be) a >>> Python function which takes an id() value as its argument and returns >>> the value for which the id() value was provided. >> No, I don't disagree with that. >> > Good. > >> It would be excessively inefficient to do, involving enumeration of all >> objects. >> >> >>> So in your world it's unnecessary for pointers to point to anything (or >>> references to refer to something)? For someone who cheerfully admits to >>> being wrong from time to time (an admirable characteristic) you are >>> certainly difficult to convince on this point. One wonders what further >>> hand-waving will follow. >> He he, "further" handwaiving: you're good at unsubstantiated allegations. >> > I am simply pointing out that to make your point you are relying on > abstractions which increasingly diverge from the reality of the Python > language. On the contrary, the closest abstraction to reference semantics is reference semantics. No special cases needed. No extraneous conceptual ballast. > I don't think it's unreasonable to describe that as > "hand-waving". You apparently do. Yes and no. Regarding what you write now, that is regarding what people (who don't have set positions) find easier to grasp: discussing that is necessarily handwaiving, but to the same degree no matter which side you argue. Unless one applies statistics. So by your own argument you're handwaiving. On the other hand, regarding what you wrote earlier you implied a history of handwaiving from me. You would be unable to give examples of that. But above you present an argument about IronPython which suggest some unspecified contradiction with something unspecified (to get to the implied contradiction a reader would have to form a picture that would be misrepresenting me), and *that* is an example of handwaiving, diversion and misrepresentation -- which I didn't have to look far to find... >> I generally strive to provide concrete examples, and you know it. >> > Again with the mind-reading: you appear to have convinced yourself that > you are an authority on what I know. What on Earth are you babbling about now? I say what I do. You therefore think I'm reading your mind? Hello. Get a grip. >> Anywyay, treating the first sentence as a genuine question: in the most >> likely interpretation it seems that you're conflating id's with >> pointers. An id() value uniquely represents a pointer (i.e., the >> identity of the object pointed to). It is not itself a pointer since it >> lack any pointer semantics. >> > No, it doesn't uniquely represent a pointer, Denial is just stupid, sorry. > it uniquely represents an *object*. Yes, and that implies that it also uniquely represents a pointer to the object. If nothing else you could take the address of the object and have a direct correspondence (one-to-one mapping) with the id value, contradicting your statement. But that's just one concrete example, it doesn't capture the general idea of an abstract pointer: it only shows that your statement is a self-contradiction, i.e., fallacious. >> For a less likely more technical interpretation, as far as I know in >> Python there's just one case of a pointer that does not point to >> anything, namely as exemplified by >> >> def foo(): >> print( x ) >> x = "whatever" >> >> The Java equivalent would say "NullPointerException", in Python it says >> something like "unbound". Which means the same. >> > Be careful when comparing static and dynamic languages. Java, being a > static language, has no equivalent to Python's NameError and > AttributeError, which both represent situations in which no object has > been bound to a name. In those cases it isn't that the name exists and > is bound to a "null pointer", it's simply that the name doesn't exist. > So there is no "copyable reference value". Yes, you have point there (the first so far, I must add, since this is at the end of the article!). And it is a good but subtle point that I was a bit hesitant to mention. But since you've let that cat out of ze bag, Java and Python differ in what dangerous name/pointer features they offer: IIRC Java allows a name to become "unbound" by assigning nullpointer, i.e. an extra path to that dangerous nullpointer/unbound state, while Python allows a name to become non-existent via del, i.e. an extra path to that dangerous non-existence. Still, the unbound/nullpointer state is the same, with the same effect. And that's quite suggestive. Cheers & hth., - Alf From dinov at microsoft.com Wed Feb 10 23:58:33 2010 From: dinov at microsoft.com (Dino Viehland) Date: Thu, 11 Feb 2010 04:58:33 +0000 Subject: Modifying Class Object In-Reply-To: References: Message-ID: <1A472770E042064698CB5ADC83A12ACD392D9ED8@TK5EX14MBXC116.redmond.corp.microsoft.com> Steve wrote: > id() simply returns a unique value identifying a particular object. In > CPython, where objects do not migrate in memory once created, the > memory > address of the object is used. In IronPython each object is assigned an > id when it is created, and that value is stored as an attribute. Just a point of clarification: In IronPython ids are lazily assigned upon a call to the id(). They're actually fairly expensive to create because the ids need to be maintained by a dictionary which uses weak references. > >> If you disagree, please write (in any implementation you like: it need > >> not even be portable, though I can't imagine why ti wouldn't be) a > >> Python function which takes an id() value as its argument and > >> returns the value for which the id() value was provided. Just for fun this works in IronPython 2.6: >>> import clr >>> clr.AddReference('Microsoft.Dynamic') >>> from Microsoft.Scripting.Runtime import IdDispenser >>> x = object() >>> id(x) 43 >>> IdDispenser.GetObject(43) >>> IdDispenser.GetObject(43) is x True Please, please, no one ever use this code! I do generally agree with the sentiment that id is object identity and in way related to pointers though. From alfps at start.no Thu Feb 11 00:01:54 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 06:01:54 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> So now the whole thing boils down to "Alf against the world"? The >>> reminds me of the story about the woman who went to see her son qualify >>> from his basic army training. When asked what she thought of the parade >>> she said it was very nice, but that "everyone but our Alf was out of >>> step". >> Considering your frequent ad hominem attacks (and this is yet one more), >> you seem to think that social coercion works well for establishing >> engineering solutions or scientific truth. >> >> That's a misconception. >> > So now I understand neither engineering nor science? I find that > assertion offensive, though unsurprising. > >> Social matters and matters of engineering or science are different things. >> > I am hardly ignorant of that, as you should know from my many past > writings on both aspects of Python usage. You are attempting to teach > your grandmother to suck eggs. >>> I am unsure at this stage what it would take to convince you that you >>> are not only wrong about several important aspects of Python but also >>> wrong-headed. >> You might start by starting a thread about one such thing; I'll correct >> you if you're wrong about something I know, or if you demonstrate that >> I'm wrong about something, then I'll be happy to learn something, as >> always. >> >> It would be a nice change from your extreme focus on my person, if you >> could manage to discuss something technical. >> > See below. >>> Whenever anyone points out any aspect of your behavior >>> which is unacceptable or ignorant you trot out this accusation that >>> people are making "ad hominem attacks" as though commenting on aspects >>> of your personality is an attempt to undermine your arguments. >> That's an ad hominem attack, albeit a pretty silly one. >> > [facepalm] > >> Your behavior, with ad hominem, coercion, insinuations, >> misrepresentations and so forth the basic ingredients, is completely >> unacceptable to me, by the way. >> >> It's like a bully in the schoolyard. >> > I am attempting to persuade, not to coerce. >>> It isn't. The two are orthogonal. Your arguments are wrong *and* you are >>> behaving like a pratt. A change in either one of these aspects would >>> improve matters, but each seems as unlikely as the other. >>> >>>> It also reflects rather badly on you. >>> Sigh. We're all out of step again, obviously. >> If you had any argument that held regarding the technical, then I think >> you (and I mean the singular you) would have tried it by now. >> >> But instead, you engage in this bullying behavior. >> > My (technical) views on your insistence that Python's semantics require > the use of pointers to explain them is ongoing elsewhere, and remains > open for you to refute. > > In this particular part of the thread I am attempting, unsuccessfully, > to convince you that a change in *your* behavior would lead to less > hostility directed towards the way you present your ideas. > > You apparently feel it is quite acceptable to tell people to "learn to > read", I have not used that expression. However I have suggest and emphasized that it might help to *read* whatever one quotes, when the quoted material (such as one paragraph) has not been read. Telling someone to "learn to read" is a Steve Holden'sk way to imply that the person is an ignoramus who hasn't bothered to learn to read. Telling a person to read something that's obviously not been read is quite another matter. So, you are misrepresenting -- again -- and in a quite revealing way, sorry. > and calling their assertions "bullshit", Yes, in this group, but only for personal attacks. Such as yours. I think I've shown extreme restraint in the face of bullying from you and some followers, and calling the insinuations bullshit is quite mild. > but when we try to point > out aspects of your behavior that are either undesirable or unacceptable > we are indulging in "ad hominem attacks". That is an untrue and extremely misleading description of what you've been doing. > In your terms, your accusing me of bullying behavior is an ad hominem > attack on me, so I won't bother to respond further. You're complaining about the person you're hitting saying clearly what you did. If some truthful words about bullying can get you straight I'm for it. Even if it means getting down to your level (and yes, I did). Cheers, - Alf From mark0978 at gmail.com Thu Feb 11 00:24:34 2010 From: mark0978 at gmail.com (Mark Jones) Date: Wed, 10 Feb 2010 21:24:34 -0800 (PST) Subject: I've built Python, but can't figure out how to package it for windows References: Message-ID: Turns out there is an tools/msi directory and in there is python code to help build the MSI from the tree you built. Only problem is you can't use it without having python and PythonWin installed. So I grabbed 2.6.4 python and pythonwin and installed them. It uses COM objects and the CabSDK from MS to build the MSI file. And then it has a couple of "Issues" that I had to resolve. First you need a VS2008 shell so you can nmake -f msisupport.mak then you need to grab a copy of TIX (I didn't have to build it, just have it in place fore the license.terms file (probably could have just removed that list member for the same effect, but I was worried about something else being needed down below) ("Tcl", "tcl8*", "license.terms"), ("Tk", "tk8*", "license.terms"), ("Tix", "Tix-*", "license.terms")): had to be changed to: ("Tcl", "tcl-8*", "license.terms"), ("Tk", "tk-8*", "license.terms"), ("Tix", "Tix*", "license.terms")): because the package names have evidently changed in the not to distant past? After that, I ran c:\python26\python msi.py and then it griped about the python264.chm being missing, so instead of trying to build it, I grabbed the one from the copy of python I had to install in order to build python and dumped it in the expected location. Oh yea, I also had to go to the PC directory and nmake -f icons.mak This gave me a runnable msi file to install python (which was already installed, so that I could build the msi file to install my own version). Oh well, at least it is built now. Whew! From gagsl-py2 at yahoo.com.ar Thu Feb 11 00:35:08 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Feb 2010 02:35:08 -0300 Subject: SocketServer error: AttributeError: instance has no __call__ method References: Message-ID: En Wed, 10 Feb 2010 17:13:58 -0300, Jordan Apgar escribi?: > I'm having some issues connecting to my Socket Server, I get this > traceback on the sever side: > ---------------------------------------- > Exception happened during processing of request from ('127.0.0.1', > 56404) > Traceback (most recent call last): > File "/usr/lib/python2.6/SocketServer.py", line 320, in > finish_request > self.RequestHandlerClass(request, client_address, self) > AttributeError: Negotiator instance has no __call__ method > ---------------------------------------- > class ServerNegotiator: > def __init__(self, host, port, hostid, rsa_key, buf = 512): > negotiator = Negotiator(host, hostid, rsa_key,buf) > self.server = SocketServer.TCPServer((host, port), negotiator) You have to pass the *class* of the RequestHandler you want, not an instance. TCPServer will create an instance of such class for every request handled. So you can't (or shouldn't) save permanent info in the handler, like rsa_key. Store all those parameters in the server. From the handler, you may access the server using its .server attribute. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Thu Feb 11 00:37:17 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Feb 2010 02:37:17 -0300 Subject: SimpleXMLRPCServer and client address References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> Message-ID: En Wed, 10 Feb 2010 19:19:50 -0300, Jordan Apgar escribi?: > I'm trying to right a server that needs specific information for each > client accessing it. The easiest way I could think of doing this is > keeping this information based on ip address (the information is only > valid for a short time). I know there is no was to get the client's > address directly and have seen a few examples of subclassing the > SimpleXMLRPCServer like this: > > class RPCServer(SimpleXMLRPCServer): > > def _dispatch(self, method, params): > """Extend dispatch, adding client info to some parameters.""" > if method in ({my list of methods I needed client address}): > return SimpleXMLRPCServer._dispatch(self, method, > params+(self.client_address,)) > return SimpleXMLRPCServer._dispatch(self, method, params); > > > but to be honest I don't understand what's going on there or how to > use it. Would anyone be able to explain this to me? Do you want an explanation of what the above code does? -- Gabriel Genellina From steven at REMOVE.THIS.cybersource.com.au Thu Feb 11 00:46:27 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 11 Feb 2010 05:46:27 GMT Subject: Modifying Class Object References: Message-ID: On Wed, 10 Feb 2010 23:56:36 +0100, Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: >> >>> "pointer" refers to a copyable reference value as seen from the Python >>> level, in the same way as "pointer" is used by e.g. the Java language >>> spec. >> >> Python doesn't have "copyable reference values" in the Python level. It >> has objects. > > Given > > s = [1] > t = s # Copies reference. > t[0] = 2 # Changes referenced object via copied reference. > print( s ) # Checks the object via the original reference. > > your argument that the copied reference does not exist, is just silly. > > And you know it. You keep making a habit of pretending that you know what other people are thinking, accusing them of lying for having an opinion that differs from yours, and of deliberately making silly arguments that the poster (in this case, me) knows is untrue. It is an obnoxious, trolling habit. Please stop it. I don't "know" it is a silly argument, because I don't accept your givens. Specifically: s = [1] t = s # Binds the name t to the object bound to the name s. t[0] = 2 # Changes the object bound to the name t print(s) # Checks the object via the original name. Notice that your version describes what happens according to some implementation, below the level of the Python virtual machine. My version describes what happens at the level of high-level Python code, which is the defined semantics of the language. It makes no assumptions about the implementation, completely unlike yours which is entirely implementation- specific. My description is equally valid whether Python is being executed by the CPython virtual machine on an Intel-compatible processor, or hand-simulated with pencil and paper, or something completely different. Yours is not. I describe the high-level language, you describe one implementation. Neither view is *wrong*, per se, but one describes the semantics of the language while the other describes the implementation. The first paragraph of the Python docs about the execution model says: "NAMES REFER TO OBJECTS [emphasis added]. Names are introduced by name binding operations. Each occurrence of a name in the program text refers to the binding of that name established in the innermost function block containing the use." http://docs.python.org/reference/executionmodel.html Apart from the use of the generic English term "refers to" (and similar), you will find *nothing* about pointers in this. That's because pointers are not a part of the high-level behaviour of Python. See also: http://docs.python.org/reference/simple_stmts.html#assignment-statements where you will also not find the word "pointer" used to describe any high- level Python feature, or used in relation to assignment. -- Steven From wuwei23 at gmail.com Thu Feb 11 01:10:53 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 10 Feb 2010 22:10:53 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <81e93706-0e5f-429c-8514-f079c3910289@x1g2000prb.googlegroups.com> "Alf P. Steinbach" wrote: > Telling someone to "learn to read" is a Steve Holden'sk way to imply that the > person is an ignoramus who hasn't bothered to learn to read. Ad hominem. > So, you > are misrepresenting ?-- ?again ?-- ?and in a quite revealing way, sorry. Ad hominem. > Yes, in this group, but only for personal attacks. Such as yours. Ad hominem. > I think I've shown extreme restraint in the face of bullying from you and some > followers, and calling the insinuations bullshit is quite mild. Ad hominem. > That is an untrue and extremely misleading description of what you've been doing. Ad hominem. > Even if it means getting down to your level (and yes, I did). Ad hominem. So the real lesson you're trying to impart is to do as you say and not as you do? From ken at seehart.com Thu Feb 11 01:28:43 2010 From: ken at seehart.com (Ken Seehart) Date: Wed, 10 Feb 2010 22:28:43 -0800 Subject: regex to match python string literal syntax In-Reply-To: <4B738AB1.2030702@seehart.com> References: <4B738AB1.2030702@seehart.com> Message-ID: <4B73A39B.5090503@seehart.com> Found this in pypy! # Match any flavor of string; /*the terminating quote is optional*/ # so that we're robust in the face of incomplete program text. _match_stringre = re.compile(r""" \""" [^"\\]* (?: (?: \\. | "(?!"") ) [^"\\]* )* (?: \""" )? | " [^"\\\n]* (?: \\. [^"\\\n]* )* "? | ''' [^'\\]* (?: (?: \\. | '(?!'') ) [^'\\]* )* (?: ''' )? | ' [^'\\\n]* (?: \\. [^'\\\n]* )* '? """, re.VERBOSE | re.DOTALL).match Problem solved. Ken Ken Seehart wrote: > > I found this: > http://code.activestate.com/recipes/475109/ > > But it is incorrect in some cases, such as: > * > "foo \" bar"* / (incorrectly matches "foo \")/ > * > '''* /(incorrectly matches the second two single quotes)/ > > *" foo > bar "* / (incorrectly matches quote containing newline/) > > Anyone know a regular expression that correctly matches python string > literals? > > Thanks in advance, > Ken > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 11 01:37:35 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 07:37:35 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steven D'Aprano: > On Wed, 10 Feb 2010 23:56:36 +0100, Alf P. Steinbach wrote: > >> * Steven D'Aprano: >>> On Wed, 10 Feb 2010 21:02:14 +0100, Alf P. Steinbach wrote: >>> >>>> "pointer" refers to a copyable reference value as seen from the Python >>>> level, in the same way as "pointer" is used by e.g. the Java language >>>> spec. >>> Python doesn't have "copyable reference values" in the Python level. It >>> has objects. >> Given >> >> s = [1] >> t = s # Copies reference. >> t[0] = 2 # Changes referenced object via copied reference. >> print( s ) # Checks the object via the original reference. >> >> your argument that the copied reference does not exist, is just silly. >> >> And you know it. > > You keep making a habit of pretending that you know what other people are > thinking, No, that is untrue, I do neither know nor pretend to know what other people are thinking. But I do know that you know some elementary things, such as understanding what the code above does. I do not by that mean that you don't also understand far more advanced things :-), just that I'm fairly ~100% sure that you do understand the code above. > accusing them of lying for having an opinion that differs from > yours, That is untrue. [snip] > I don't "know" it is a silly argument, because I don't accept your > givens. Specifically: > > s = [1] > t = s # Binds the name t to the object bound to the name s. > t[0] = 2 # Changes the object bound to the name t > print(s) # Checks the object via the original name. > > Notice that your version describes what happens according to some > implementation, below the level of the Python virtual machine. Consider just the assert( t is not s ) t = s Does this change anything at all in the computer's memory? If it doesn't, then it has no effect whatsoever. But since it does have an effect, a memory change has been effected. You describe that memory change as that t has been "bound" to the same object as s. By which you mean that henceforth, until the next assignment to t, t *refers* to the same object as s. That explanation in terms of "refers" is necessary. No beginner knows what it means that a name is "bound" to something means, until it's been explained. The explanation is necessarily in terms of "refers to". When something A refers to something B, then by definition A is a *reference* to B. Anyway, you have changed which object t refers to, by changing memory contents so that t now refers to the same object as s. Effectively, by making t refer to the same object as s, by all measures of reference equality (which is just, do they refer to same object?) you have *copied* the s reference to t. For if you haven't, then t necessarily refers to something else. So the memory change, whatever it was, involved an effective copying of a reference, in memory. And that copying of a reference, in memory, implies a copyable reference. Going the other way, copying of references very directly implies binding. No need for the long logic chain above. So copying of references is in my view much more powerful as a model of what goes on, yielding immediate conclusions, avoiding special case rules, and being very suitable for visualization. Not the least, it's more powerful because in order to explain "bind" you need "refer" and "reference", so the "bind" view involves more, violating Occam's. But given the explanation in terms of "refer" and "reference" you do not need "bind", so it's less, it's simpler -- and it's easier to visualize. --- Anyway, there is more practical way to look at it. Say that you're going to implement a linked list. The functionality required for that is exactly that of general pointers. But a linked list can be implemented in Python, using names (attributes) as pointers. And since that works, without having to do anything extra in order to "implement" pointers in terms of names, but just using those names directly, those names necessarily have the functionality of general pointers. > My version > describes what happens at the level of high-level Python code, which is > the defined semantics of the language. It makes no assumptions about the > implementation, completely unlike yours which is entirely implementation- > specific. My description is equally valid whether Python is being > executed by the CPython virtual machine on an Intel-compatible processor, > or hand-simulated with pencil and paper, or something completely > different. Yours is not. > > I describe the high-level language, you describe one implementation. > Neither view is *wrong*, per se, but one describes the semantics of the > language while the other describes the implementation. > > The first paragraph of the Python docs about the execution model says: > > "NAMES REFER TO OBJECTS [emphasis added]. Names are introduced by name > binding operations. Each occurrence of a name in the program text refers > to the binding of that name established in the innermost function block > containing the use." > > http://docs.python.org/reference/executionmodel.html > > Apart from the use of the generic English term "refers to" (and similar), > you will find *nothing* about pointers in this. That's because pointers > are not a part of the high-level behaviour of Python. Well, apart from... As you say. > See also: > > http://docs.python.org/reference/simple_stmts.html#assignment-statements > > where you will also not find the word "pointer" used to describe any high- > level Python feature, or used in relation to assignment. Yes, that's right. It does not mean that such a description is invalid. It only means that common sense needs to be applied, and that the urge to misinterpret needs to be suppressed. I don't think those are problems for novices. But still a better term than "pointer" would be nice, and I guess "reference" is it, as suggested by the course material I linked to. Cheers & hth., - Alf From alfps at start.no Thu Feb 11 01:46:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 07:46:46 +0100 Subject: Modifying Class Object In-Reply-To: <81e93706-0e5f-429c-8514-f079c3910289@x1g2000prb.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <81e93706-0e5f-429c-8514-f079c3910289@x1g2000prb.googlegroups.com> Message-ID: * alex23: > "Alf P. Steinbach" wrote: >> Telling someone to "learn to read" is a Steve Holden'sk way to imply that the >> person is an ignoramus who hasn't bothered to learn to read. > > Ad hominem. > >> So, you >> are misrepresenting -- again -- and in a quite revealing way, sorry. > > Ad hominem. > >> Yes, in this group, but only for personal attacks. Such as yours. > > Ad hominem. > >> I think I've shown extreme restraint in the face of bullying from you and some >> followers, and calling the insinuations bullshit is quite mild. > > Ad hominem. > >> That is an untrue and extremely misleading description of what you've been doing. > > Ad hominem. > >> Even if it means getting down to your level (and yes, I did). > > Ad hominem. > > So the real lesson you're trying to impart is to do as you say and not > as you do? Well, I don't think any of you guys would hold out as long as I did. I think it's Not Nice to get personal. But there's a limit, one can't just ignore punches every day, and you're right, the above from me was ad hominem all the way (well, except that it doesn't concern any technical discussion, and that I'm not injecting noise but responding to such and trying to reduce it in the future, but still). Cheers, - Alf From ivlenin at gmail.com Thu Feb 11 02:38:32 2010 From: ivlenin at gmail.com (I V) Date: 11 Feb 2010 08:38:32 +0100 Subject: Modifying Class Object References: Message-ID: <4b73b3f8$1@news.x-privat.org> On Thu, 11 Feb 2010 07:37:35 +0100, Alf P. Steinbach wrote: > * Steven D'Aprano: >> s = [1] >> t = s # Binds the name t to the object bound to the name s. >> t[0] = 2 # Changes the object bound to the name t print(s) # >> Checks the object via the original name. >> >> Notice that your version describes what happens according to some >> implementation, below the level of the Python virtual machine. > > Consider just the > > assert( t is not s ) > > t = s > > Does this change anything at all in the computer's memory? > > If it doesn't, then it has no effect whatsoever. > > But since it does have an effect, a memory change has been effected. I don't think your disagreeing with Steven here - by talking about "the computers memory," it's clear that you are talking about the details of an implementation of python, not the semantics of python itself. Unless, of course, you are under the misapprehension that "the computer's memory" is relevant to the python language, rather than the particular implementation. Python itself has nothing to do with "computers" or "memory"; these are mere implementation details. From wayne.dads.bell at gmail.com Thu Feb 11 02:39:36 2010 From: wayne.dads.bell at gmail.com (wayne.dads.bell at gmail.com) Date: Thu, 11 Feb 2010 07:39:36 +0000 Subject: sqlite3 bug? In-Reply-To: <4B735175.9020704@tim.thechases.com> Message-ID: <001636498db3b55769047f4e4011@google.com> Thank you It just highlights that when your tired things can easily be missed and maybe you should leave things until the morning to view things with fresh eyes =) -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Thu Feb 11 02:59:38 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 11 Feb 2010 20:59:38 +1300 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> Message-ID: <7thr3kFeqlU1@mid.individual.net> Christian Heimes wrote: > A much, much stronger version of the > principles behind Vigen?re was used in the German Enigma machine. > Because the algorithm was still not good enought some clever guy called > Turing and his team was able to crack the enigma. Actually I gather it had a lot to do with the fact that the Germans made some blunders in the way they used the Enigma that seriously compromised its security. There was reportedly a branch of the German forces that used their Enigmas differently, avoiding those mistakes, and the British never managed to crack any of their messages. -- Greg From greg.ewing at canterbury.ac.nz Thu Feb 11 03:01:35 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 11 Feb 2010 21:01:35 +1300 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <871vgtj31f.fsf@benfinney.id.au> Message-ID: <7thr76FeqlU2@mid.individual.net> Daniel Fetchinson wrote: > It also turned out that everybody mostly writes his/her > own obfuscation routine. Hey, it gives you the additional advantage of obfuscation by obscurity! -- Greg From alfps at start.no Thu Feb 11 03:09:04 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 09:09:04 +0100 Subject: Modifying Class Object In-Reply-To: <4b73b3f8$1@news.x-privat.org> References: <4b73b3f8$1@news.x-privat.org> Message-ID: * I V: > On Thu, 11 Feb 2010 07:37:35 +0100, Alf P. Steinbach wrote: >> * Steven D'Aprano: >>> s = [1] >>> t = s # Binds the name t to the object bound to the name s. >>> t[0] = 2 # Changes the object bound to the name t print(s) # >>> Checks the object via the original name. >>> >>> Notice that your version describes what happens according to some >>> implementation, below the level of the Python virtual machine. >> Consider just the >> >> assert( t is not s ) >> >> t = s >> >> Does this change anything at all in the computer's memory? >> >> If it doesn't, then it has no effect whatsoever. >> >> But since it does have an effect, a memory change has been effected. > > I don't think your disagreeing with Steven here - by talking about "the > computers memory," it's clear that you are talking about the details of > an implementation of python, not the semantics of python itself. Unless, > of course, you are under the misapprehension that "the computer's memory" > is relevant to the python language, rather than the particular > implementation. Python itself has nothing to do with "computers" or > "memory"; these are mere implementation details. You know, the programming language that doesn't need computers: Python. :-) Cheers, - Alf (not sure how to read your posting, but it's funny anyhow) From mail at timgolden.me.uk Thu Feb 11 03:56:32 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Feb 2010 08:56:32 +0000 Subject: I've built Python, but can't figure out how to package it for windows In-Reply-To: References: Message-ID: <4B73C640.1000500@timgolden.me.uk> On 11/02/2010 05:24, Mark Jones wrote: [... problems building from tools/msi ...] I sympathise. I went through similar hoops last year, merely to be able to do it. I think I'm right in saying that very few people are bothered enough to package their own MSI on windows because the (probably very few) developers who have a need to run bleeding-edge Python, eg to test out patches or whatever, can simply run from \pcbuild\python_d.exe or whatever. And everyone else simply runs the MSI provided on python.org. I'm fairly sure I'm right in saying that it's Martin von L who builds the MSIs for python.org and if I haven't done it before I'd like to offer him a vote of thanks for having done and for continuing to do this. The tools/msi is used by him to do those builds and does make certain assumptions. One, in particular, is that you have an *existing* copy of some recent Python running somewhere. (I use python25, I think). Altho' it might be nice to be able to bootstrap, in practice it isn't a problem. For interest's sake I offer my make-snapshots area which I use to build trunk or branches for Python 2.x / 3.x when I have the change: http://svn.tjg.org.uk/make-snapshots Feel free to look at least to see what I'm doing. I think I didn't bother with Tix (I don't use Tkinter) so thanks for providing some input on that; I may well go back and retrofit. TJG From mail at timgolden.me.uk Thu Feb 11 04:10:49 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Feb 2010 09:10:49 +0000 Subject: Executing Commands From Windows Service In-Reply-To: <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> Message-ID: <4B73C999.90206@timgolden.me.uk> On 10/02/2010 22:55, T wrote: > Great suggestions once again - I did verify that it was at least > running the plink.exe binary when under LocalSystem by having the > service run "plink.exe> C:\plinkoutput.txt" - this worked fine. And, > as I mentioned, it's now working just fine when running under a > regular admin account. So, I think that's going to be my solution to > avoid any further issues. My best guess at this point (as you > mentioned), is that plink.exe is doing _something_ network-related > that LocalSystem doesn't have the privileges to do - what exactly it > is, I have no idea. I may play around with it some more later, but > running the service under an admin account should be a perfectly > acceptable solution. > > Also, I will be writing other Python apps that the service will be > executing - so it goes without saying that I'll be including a log to > file option :) Thanks again for all your guys' help! I'm not sure if this has been said already, but a reasonably common approach to services is to create a user specifically for the service and grant it exactly the privs / perms it needs (once you work out what they are). You then assign it a generated password, eg a GUID which you don't even try to remember: simply cut-and-paste it in. Then create the service to run under that user. That way you don't have the service running under some local Administrator account with the associated risk of its being subverted and gaining more control than you want. Nor do you have it running as a real user whose password might change for any reason, leaving you with a service which won't start up. I don't remember at this moment whether such a user's profile is automatically loaded in the process when the service starts or whether you have to do the LoadUserProfile thing. TJG From lists at cheimes.de Thu Feb 11 04:46:16 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Feb 2010 10:46:16 +0100 Subject: ANN: obfuscate In-Reply-To: <7thr3kFeqlU1@mid.individual.net> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> Message-ID: <4B73D1E8.9040603@cheimes.de> Gregory Ewing wrote: > Actually I gather it had a lot to do with the fact that > the Germans made some blunders in the way they used the > Enigma that seriously compromised its security. There > was reportedly a branch of the German forces that used > their Enigmas differently, avoiding those mistakes, and > the British never managed to crack any of their messages. IIRC some versions of the Enigma weren't cracked because they used a different setup and different daily keys. The predecessor of the Enigma was cracked by Polish scientists years before WW2 started. Some flaws in the instructions and a known plain text attack made the crack of the Enigma practical. It took the British scientists merely hours rather than days or weeks to decipher the daily key with some smart tricks. For example they started fake attacks on ships or cities just to have the names in some encrypted reports. From aabelyakov at gmail.com Thu Feb 11 04:57:00 2010 From: aabelyakov at gmail.com (aabelyakov) Date: Thu, 11 Feb 2010 01:57:00 -0800 (PST) Subject: Unicode strings Message-ID: <9c47f29c-4f98-442c-ba60-ec1d68f401f8@b7g2000yqd.googlegroups.com> Excellent! But what about the unicode From aabelyakov at gmail.com Thu Feb 11 05:00:05 2010 From: aabelyakov at gmail.com (aabelyakov) Date: Thu, 11 Feb 2010 02:00:05 -0800 (PST) Subject: Unicode strings Message-ID: Excellent! But what about the unicode? From no.email at nospam.invalid Thu Feb 11 06:32:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Feb 2010 03:32:18 -0800 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> Message-ID: <7x6364gg8t.fsf@ruckus.brouhaha.com> Gregory Ewing writes: > Actually I gather it had a lot to do with the fact that the Germans > made some blunders in the way they used the Enigma that seriously > compromised its security. There was reportedly a branch of the German > forces that used their Enigmas differently, avoiding those mistakes, > and the British never managed to crack any of their messages. I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they were more careful with procedures, but the machine was also harder to crack because it had four rotors instead of three. IIRC, the Brits were eventually (1942?) able to capture one by shooting up a German submarine and boarding it to get the machine while the sub was sinking; a British sailor wasn't able to get out in time and drowned during that operation. Getting the rotor settings off the captured unit (they may have had to do it more than once) was enough to get a foothold into the code. My memory is hazy on this by now so I may have some parts wrong, but David Kahn's book "Seizing the Enigma" tells the story (I read it many years ago). A fictionalized version appears in Neil Stephenson's novel "Cryptonomicon". From zasaconsulting at gmail.com Thu Feb 11 06:44:55 2010 From: zasaconsulting at gmail.com (Alexzive) Date: Thu, 11 Feb 2010 03:44:55 -0800 (PST) Subject: how to improve this cycle (extracting data from structured array)? Message-ID: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> Hello guys, I am just wondering if there is a quick way to improve this algorithm [N is a structured array which hold info about the nodes n of a finite element mesh, and n is about 300.000). I need to extract info from N and put it in to a 3*n matrix NN which I reshape then with numpy. I think to "append" is quite unefficient: *********************************************************** N = odb.rootAssembly.instances['PART-1-1'].nodes NN=[] B=[0,0,0] #auxsiliar vector for i in range(len(N)): B[0] = N[i].label B[1] = N[i].coordinates[0] B[2] = N[i].coordinates[1] NN = append(NN,B) NN=NN.reshape(-1,3) **************************************************** Many Thanks in advance! Alex From python.list at tim.thechases.com Thu Feb 11 07:08:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Feb 2010 06:08:31 -0600 Subject: how to improve this cycle (extracting data from structured array)? In-Reply-To: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> References: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> Message-ID: <4B73F33F.9060205@tim.thechases.com> Alexzive wrote: > I am just wondering if there is a quick way to improve this algorithm > [N is a structured array which hold info about the nodes n of a finite > element mesh, and n is about 300.000). I need to extract info from N > and put it in to a 3*n matrix NN which I reshape then with numpy. I > think to "append" is quite unefficient: > > *********************************************************** > N = odb.rootAssembly.instances['PART-1-1'].nodes > > NN=[] > > B=[0,0,0] > #auxsiliar vector > for i in range(len(N)): > B[0] = N[i].label > B[1] = N[i].coordinates[0] > B[2] = N[i].coordinates[1] > NN = append(NN,B) Usually this would be written with a list-comprehension, something like nn = [(x.label, x.coordinates[0], x.coordinates[1]) for x in N] or if you really need lists-of-lists instead of lists-of-tuples: nn = [[x.label, x.coordinates[0], x.coordinates[1]] for x in N] -tkc From __peter__ at web.de Thu Feb 11 07:25:47 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Feb 2010 13:25:47 +0100 Subject: Bizarre arithmetic results References: Message-ID: Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? Operator precedence. >>> -0.1**0.1 -0.7943282347242815 >>> (-0.1)**0.1 (0.7554510437117542+0.2454609236416552j) Quoting http://docs.python.org/3.1/reference/expressions.html: """ The power operator binds more tightly than unary operators on its left; it binds less tightly than unary operators on its right. """ Peter From andreengels at gmail.com Thu Feb 11 07:26:56 2010 From: andreengels at gmail.com (Andre Engels) Date: Thu, 11 Feb 2010 13:26:56 +0100 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: <6faf39c91002110426j2f41d7ebjb1775e6ee6968386@mail.gmail.com> On Thu, Feb 11, 2010 at 1:44 AM, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb ?3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? It's an issue of precedence of operators: -0.1 ** 0.1 is interpreted as -(0.1 ** 0.1) and not as (-0.1) ** 0.1 -- Andr? Engels, andreengels at gmail.com From dickinsm at gmail.com Thu Feb 11 07:27:14 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Feb 2010 04:27:14 -0800 (PST) Subject: Bizarre arithmetic results References: Message-ID: On Feb 11, 12:44?am, Terrence Cole wrote: > Can someone explain to me what python is doing here? > >>> -0.1 ** 0.1 > -0.7943282347242815 Here you're computing -(0.1 ** 0.1). The exponentiation operator binds more strongly than the negation operator. > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.7554510437117542+0.2454609236416552j) Here you're computing (-0.1) ** 0.1. -- Mark From anand.shashwat at gmail.com Thu Feb 11 07:31:54 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 11 Feb 2010 18:01:54 +0530 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: Do you really believe that -0.1 ** 0.1 is a valid computational problem ? Can you raise a negative number to a fractional power ? Output on my console (python 2.6) >>> -.1 ** .1 -0.79432823472428149 >>> a,b = -.1,.1 >>> a**b Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power >>> -abs(a**b) Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power There is a little issue here that '>>> -.1 ** .1' should give you error message. That is it. On Thu, Feb 11, 2010 at 6:14 AM, Terrence Cole < list-sink at trainedmonkeystudios.org> wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> -0.1 ** 0.1 > -0.7943282347242815 > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.7554510437117542+0.2454609236416552j) > >>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? > > Cheers, > Terrence > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Thu Feb 11 07:33:37 2010 From: lists at cheimes.de (Christian Heimes) Date: Thu, 11 Feb 2010 13:33:37 +0100 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: Terrence Cole wrote: >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? The binary power operator has a higher precedence than the unary negative operator. -0.1 ** 0.1 is equal to -(0.1**0.1) Christian From anand.shashwat at gmail.com Thu Feb 11 07:35:26 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 11 Feb 2010 18:05:26 +0530 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: Just realized my flaw >>> .1**.1 0.79432823472428149 >>> (-.1)**(.1) Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power - a ** b = - (a ** b) and not (-a) ** b, Thats why -.1**.1 giving you -0.79432823472428149 since .1 ** .1 = 0.79432823472428149 and minus sign is appended prior to it. On Thu, Feb 11, 2010 at 6:01 PM, Shashwat Anand wrote: > Do you really believe that -0.1 ** 0.1 is a valid computational problem ? > Can you raise a negative number to a fractional power ? > Output on my console (python 2.6) > > >>> -.1 ** .1 > -0.79432823472428149 > >>> a,b = -.1,.1 > >>> a**b > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > >>> -abs(a**b) > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > > There is a little issue here that '>>> -.1 ** .1' should give you error > message. That is it. > > > > On Thu, Feb 11, 2010 at 6:14 AM, Terrence Cole < > list-sink at trainedmonkeystudios.org> wrote: > >> Can someone explain to me what python is doing here? >> >> Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) >> [GCC 4.3.4] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> -0.1 ** 0.1 >> -0.7943282347242815 >> >>> a = -0.1; b = 0.1 >> >>> a ** b >> (0.7554510437117542+0.2454609236416552j) >> >>> -abs(a ** b) >> -0.7943282347242815 >> >> Why does the literal version return the signed magnitude and the >> variable version return a complex? >> >> Cheers, >> Terrence >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jpiitula at ling.helsinki.fi Thu Feb 11 07:37:45 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 Feb 2010 14:37:45 +0200 Subject: Bizarre arithmetic results References: Message-ID: Terrence Cole writes: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> -0.1 ** 0.1 > -0.7943282347242815 > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.7554510437117542+0.2454609236416552j) > >>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? The minus sign is not part of the literal syntax. Python takes the expression as -(0.1 ** 0.1), the binary operator binding tighter than the unary. Try (-0.1) ** 0.1, and try a = 0.1, then -a ** 0.1. From mail at timgolden.me.uk Thu Feb 11 07:43:35 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 11 Feb 2010 12:43:35 +0000 Subject: ANN: obfuscate In-Reply-To: <7x6364gg8t.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <7x6364gg8t.fsf@ruckus.brouhaha.com> Message-ID: <4B73FB77.1090005@timgolden.me.uk> On 11/02/2010 11:32, Paul Rubin wrote: > Gregory Ewing writes: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the German >> forces that used their Enigmas differently, avoiding those mistakes, >> and the British never managed to crack any of their messages. > > I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they > were more careful with procedures, but the machine was also harder to > crack because it had four rotors instead of three. IIRC, the Brits were > eventually (1942?) able to capture one by shooting up a German submarine > and boarding it to get the machine while the sub was sinking; a British > sailor wasn't able to get out in time and drowned during that operation. > Getting the rotor settings off the captured unit (they may have had to > do it more than once) was enough to get a foothold into the code. My > memory is hazy on this by now so I may have some parts wrong, but David > Kahn's book "Seizing the Enigma" tells the story (I read it many years > ago). A fictionalized version appears in Neil Stephenson's novel > "Cryptonomicon". And for those who haven't been to Bletchley Park [*] I recommend it. Not only is it full of interesting stuff, but it has an engagingly amateurish air about it which I personally prefer to the sleek-and-shiny nature of many museum-y places today. When I was there last summer I was disappointed to see that they'd closed the Pigeon Museum. But the Model Railway club was still there (altho' we were too late in the day to get in) and the new Computing Museum is full of delightful nostalgic clutter being worked on by enthusiastic people. My kind of place.. TJG [*] http://www.bletchleypark.org.uk/ From python.list at tim.thechases.com Thu Feb 11 07:47:56 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Feb 2010 06:47:56 -0600 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: <4B73FC7C.5040006@tim.thechases.com> Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? I think this recently showed up on the list and the answer involved the order of operations and precedence of "-" vs. "**". To check, try >>> (-0.1) ** 0.1 >>> -(0.1 ** 0.1) The first one is what the assignment-to-variables gains you, but I think "**" has a higher precedence than the unary-"-" so it gets performed first. I don't have Py3 on my machine here, and 2.5 rejects the first form: Python 2.5.4 (r254:67916, Nov 19 2009, 19:46:21) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -(0.1**0.1) -0.79432823472428149 >>> (-0.1)**0.1 Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power But perhaps Py3 changes evaluation, returning an complex number. -tkc From fetchinson at googlemail.com Thu Feb 11 07:49:37 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 11 Feb 2010 13:49:37 +0100 Subject: Bizarre arithmetic results In-Reply-To: <1265849053.24800.38.camel@localhost> References: <1265849053.24800.38.camel@localhost> Message-ID: On 2/11/10, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? Try this and think about operator precedence: Python 3.1.1 (r311:74480, Dec 13 2009, 16:50:25) [GCC 4.4.2 20091027 (Red Hat 4.4.2-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> (-0.1)**0.1 (0.7554510437117542+0.2454609236416552j) >>> I.e. -0.1**0.1 is not the same as (-0.1)**0.1, because it's first 0.1**0.1 and then a minus sign. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From wayne.dads.bell at gmail.com Thu Feb 11 08:20:24 2010 From: wayne.dads.bell at gmail.com (dads) Date: Thu, 11 Feb 2010 05:20:24 -0800 (PST) Subject: sqlite3 bug? References: Message-ID: Thank you It just highlights that when your tired things can easily be missed and maybe you should leave things until the morning to view things with fresh eyes =) From martin.hellwig at dcuktec.org Thu Feb 11 08:21:56 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Feb 2010 13:21:56 +0000 Subject: Executing Commands From Windows Service In-Reply-To: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: On 02/07/10 19:02, T wrote: > I have a script, which runs as a Windows service under the LocalSystem > account, that I wish to have execute some commands. Specifically, the > program will call plink.exe to create a reverse SSH tunnel. Right now > I'm using subprocess.Popen to do so. When I run it interactively via > an admin account, all is well. However, when I'm running it via > service, no luck. I'm assuming this is to do with the fact that it's > trying to run under the LocalSystem account, which is failing. What > would be the best way around this? Thanks! All being said about LS account not having the appropriate rights to access the necessary devices/files. Could it be so simple that the network is plain simply not available at all? For wireless connections I believe the connection/authentication by default is made in user space. I would save the output of an ipconfig run as the LS account to a file and see what is happening. Perhaps followed by a ping. -- mph From vishal_shetye at persistent.co.in Thu Feb 11 08:27:51 2010 From: vishal_shetye at persistent.co.in (Vishal Shetye) Date: Thu, 11 Feb 2010 18:57:51 +0530 Subject: base32hex support in python? Message-ID: <14B8F27D7CE40C4C9E481B2B845C2E0D026A34BDCF@EXCHANGE.persistent.co.in> Hi, One of the modules that I am currently working on requires base32hex encoding as defined by RFC 4648, section 7. I checked base64 module which has base32encode/decode functionality but not with extended hex alphabet. Is there a module, currently available, that provides this? As far as I see, it looks fairly simple to add support for base32hex. It differs from the base32 encoding only in the alphabet used. I am willing to provide a patch. Just to note, map01 argument won't be applicable to base32hexdecode as this encoding uses both 0 (zero) and O (oh) in its alphabet. Looking at the section 13 of RFC 4648, I think, adding base32hex support would make it conform to RFC 4648. - Vishal DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails. -------------- next part -------------- An HTML attachment was scrubbed... URL: From marklocklear at gmail.com Thu Feb 11 08:33:41 2010 From: marklocklear at gmail.com (Lumbee) Date: Thu, 11 Feb 2010 05:33:41 -0800 (PST) Subject: exception in Tkinter on Ubtunu... Message-ID: <561ee0cf-f1fd-49ee-89e9-527124f9ff62@q16g2000yqq.googlegroups.com> ...hey guys, I posted this over on the Ubuntu forums with no luck. I'm running Ubuntu 9.10 and python 2.5. In Idle when I type in a function I get this error... >>> Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1417, in __call__ return self.func(*args) File "/usr/lib/python2.5/idlelib/MultiCall.py", line 151, in handler r = l[i](event) File "/usr/lib/python2.5/idlelib/CallTips.py", line 55, in try_open_calltip_event self.open_calltip(False) File "/usr/lib/python2.5/idlelib/CallTips.py", line 79, in open_calltip self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1]) File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 66, in showtip self.position_window() File "/usr/lib/python2.5/idlelib/CallTipWindow.py", line 35, in position_window self.parencol)) File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 2860, in bbox self.tk.call((self._w, 'bbox') + args)) or None File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1033, in _getints return tuple(map(getint, self.tk.splitlist(string))) ValueError: invalid literal for int() with base 10: '(167,' testNestEggFixed( ...I've tried reinstalling, and am not sure where to go from here. I also get a 2nd small windows about 2X2" with 'idle' in the title, and nothing in the box, and I cannot use the mouse if I open a Python program from Idle. Any ideas? From jeanmichel at sequans.com Thu Feb 11 08:34:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 11 Feb 2010 14:34:16 +0100 Subject: SimpleXMLRPCServer and client address In-Reply-To: <7a9c25c21002101956x1298f01euc40285c2227a0598@mail.gmail.com> References: <15978e65-2b55-4424-8536-b486a97be793@o16g2000vbf.googlegroups.com> <4B735F0F.6080503@sequans.com> <7a9c25c21002101956x1298f01euc40285c2227a0598@mail.gmail.com> Message-ID: <4B740758.8020208@sequans.com> Stephen Hansen wrote: > On Wed, Feb 10, 2010 at 5:36 PM, Jean-Michel Pichavant > > wrote: > > I don't know exactly what you are trying to do, but if your server > requires informations from the client, it would be better to ask > explicitly the client for those informations. > For instance, if a method requires te client IP address, then the > IP address is definitely a parameter of the method. > > > I can't answer the OP, as I don't know the answer to his specific > question-- but er, asking a client to provide one's IP address is not > really a very workable solution. There's no way to really determine > your own IP address in a reliable way. > > All the usual methods (e.g., > socket.gethostbyname(socket.gethostname())) can fail and/or be wrong > in some not terribly uncommon situations. The only reliable way to get > such a piece of information is to connect to a server, and ask that > server what address you were connecting to them as. Even then, that IP > may not be the same as an IP you use to connect to say, a different > server (on a different network) > > --S You're probably right. But my point covered only the fact that if a method needs something it should ask it explicitly throught parameters, not taking the opportunity to guess it since it happens that it's a xmlrpc server and that the information could be deduced from the client IP address. My feeling is that the OP needed something else than the client IP address, and was trying at the server side to map client IPs with the data he effectively needs. I could be wrong though. JM From Juergen.Hermann at 1und1.de Thu Feb 11 08:34:26 2010 From: Juergen.Hermann at 1und1.de (jhermann) Date: Thu, 11 Feb 2010 05:34:26 -0800 (PST) Subject: Your beloved python features References: <28c6967f-7637-4823-aee9-15487e1ce98b@o28g2000yqh.googlegroups.com> Message-ID: <8504b5fe-8776-4c60-a001-a27bc0225f6d@q16g2000yqq.googlegroups.com> $ python -c "import this" From duncan.booth at invalid.invalid Thu Feb 11 08:38:46 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Feb 2010 13:38:46 GMT Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Tim Chase wrote: > But perhaps Py3 changes evaluation, returning an complex number. Yes, the change is documented at http://docs.python.org/3.1/reference/expressions.html#the-power-operator If it is in any of the "What's new in Python x.xx" documents or in a PEP somewhere I haven't spotted it. -- Duncan Booth http://kupuguy.blogspot.com From zasaconsulting at gmail.com Thu Feb 11 09:16:12 2010 From: zasaconsulting at gmail.com (Alexzive) Date: Thu, 11 Feb 2010 06:16:12 -0800 (PST) Subject: how to improve this cycle (extracting data from structured array)? References: <6ab43302-8700-495e-a2f7-c52282c62301@b2g2000yqi.googlegroups.com> Message-ID: <992f5035-904f-49b6-9d6a-6bf16cd03e32@x22g2000yqx.googlegroups.com> On Feb 11, 1:08?pm, Tim Chase wrote: > Alexzive wrote: > > I am just wondering if there is a quick way to improve this algorithm > > [N is a structured array which hold info about the nodes n of a finite > > element mesh, and n is about 300.000). I need to extract info from N > > and put it in to a 3*n matrix NN which I reshape then with numpy. I > > think to "append" is quite unefficient: > > > *********************************************************** > > N = odb.rootAssembly.instances['PART-1-1'].nodes > > > NN=[] > > > B=[0,0,0] > > ?#auxsiliar vector > > for i in range(len(N)): > > ? ? B[0] = N[i].label > > ? ? B[1] = N[i].coordinates[0] > > ? ? B[2] = N[i].coordinates[1] > > ? ? NN = append(NN,B) > > Usually this would be written with a list-comprehension, > something like > > ? ?nn = [(x.label, x.coordinates[0], x.coordinates[1]) > ? ? ? ? ?for x in N] > > or if you really need lists-of-lists instead of lists-of-tuples: > > ? ?nn = [[x.label, x.coordinates[0], x.coordinates[1]] > ? ? ? ? ?for x in N] > > -tkc yeah, much better thanks! Alex From dickinsm at gmail.com Thu Feb 11 09:21:57 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Thu, 11 Feb 2010 06:21:57 -0800 (PST) Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: <9ea745cf-e10e-4b61-a2bc-8390f54c79ff@d37g2000yqa.googlegroups.com> On Feb 11, 1:38?pm, Duncan Booth wrote: > Tim Chase wrote: > > But perhaps Py3 changes evaluation, returning an complex number. > > Yes, the change is documented athttp://docs.python.org/3.1/reference/expressions.html#the-power-operator > > If it is in any of the "What's new in Python x.xx" documents or in a PEP > somewhere I haven't spotted it. Not in the 'what's new' documents, as far as I can tell, but this change was introduced as part of implementing PEP 3141. http://www.python.org/dev/peps/pep-3141/ Here's an extract from the PEP, describing the 'Complex' abstract base class: class Complex(Number): """Complex defines the operations that work on the builtin complex type. In short, those are: conversion to complex, bool(), .real, .imag, +, -, *, /, **, abs(), .conjugate(), ==, and !=. If it is given heterogenous arguments, and doesn't have special knowledge about them, it should fall back to the builtin complex type as described below. """ @abstractmethod def __pow__(self, exponent): """a**b; should promote to float or complex when necessary.""" raise NotImplementedError -- Mark From hjebbers at gmail.com Thu Feb 11 09:32:33 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 06:32:33 -0800 (PST) Subject: python crash on windows but not on linux Message-ID: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> To all, I am running an EDI translator, and doing stress tests. When processing a test with a (relatively) big EDI file(s) on windowsXP I get a crash: 'sorry for the inconvenience' etc (so no clues about what is causing the problem) This happens with python 2.4, 2.5, 2.6 It does not happen in the same setup&tests on linux. (while the linux machine has only half of the RAM of the windows machine). I am quite sure it is not some external module; there's no GUI (apart from 'print'), no network connections. Actually, the crash is not predictable....the crash occurs most of the time...but at different points. So basically I am wondering how to proceed. Is it related to a memory problem? (which does not occur on Linux) any pointer is very welcome, henk-jan From cjw at ncf.ca Thu Feb 11 10:24:00 2010 From: cjw at ncf.ca (cjw) Date: Thu, 11 Feb 2010 10:24:00 -0500 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: On 05-Feb-10 14:53 PM, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > > Thanks I prefer verbNoun. Let's remember that PEP 8 is a guide, not a set of rules. Colin W. From gilsapir86 at gmail.com Thu Feb 11 10:31:47 2010 From: gilsapir86 at gmail.com (apple man) Date: Thu, 11 Feb 2010 07:31:47 -0800 (PST) Subject: can you help me about this deal? Message-ID: <608d3dbd-4705-42e8-a77b-ee425a6dc8ef@d27g2000yqn.googlegroups.com> hi i saw this very cheap macbook pro 500$ here: (the 3rd from the left) http://sites.google.com/site/applestorebyamazone1/ i want to buy it, is it a good price? can i get a lower price? thanks From robert.kern at gmail.com Thu Feb 11 10:55:30 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Feb 2010 09:55:30 -0600 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: On 2010-02-11 06:31 AM, Shashwat Anand wrote: > Do you really believe that -0.1 ** 0.1 is a valid computational problem > ? Can you raise a negative number to a fractional power ? > Output on my console (python 2.6) > > >>> -.1 ** .1 > -0.79432823472428149 > >>> a,b = -.1,.1 > >>> a**b > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > >>> -abs(a**b) > Traceback (most recent call last): > File "", line 1, in > ValueError: negative number cannot be raised to a fractional power > > There is a little issue here that '>>> -.1 ** .1' should give you error > message. That is it. No, fractional powers of negative numbers are perfectly valid mathematically. The result is a complex number. In Python 3 (what the OP is using), this has been implemented, but not in Python 2.6. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at holdenweb.com Thu Feb 11 10:59:41 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 10:59:41 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: [...] >> In this particular part of the thread I am attempting, unsuccessfully, >> to convince you that a change in *your* behavior would lead to less >> hostility directed towards the way you present your ideas. >> >> You apparently feel it is quite acceptable to tell people to "learn to >> read", > > I have not used that expression. > > However I have suggest and emphasized that it might help to *read* > whatever one quotes, when the quoted material (such as one paragraph) > has not been read. > > Telling someone to "learn to read" is a Steve Holden'sk way to imply > that the person is an ignoramus who hasn't bothered to learn to read. > Telling a person to read something that's obviously not been read is > quite another matter. So, you are misrepresenting -- again -- and in > a quite revealing way, sorry. > Pardon me? You used it on December 16 in a response to Mensanator in message M :> How about devoting a section on downloading the source files M :> and compiling it on a Mac? AS:> Learn to read. AS:> At the top of every second page it tells you that this is an AS:> introduction based on Windows. I am sure you will have some glib response as to why this wasn't rude at all. Allow me to correct you - it was, and rudeness is not welcomed on comp.lang.python. That doesn't mean it doesn't happen (why, I have even been known to be rude myself - we are none of us perfect, after all). I have already given ample evidence that when I am wrong I will admit it. You, contrariwise, maintain that you will admit when you are wrong (I believe 40% of the time was the figure you used) but I fail to remember any single incident when you made such an admission. >> and calling their assertions "bullshit", > > Yes, in this group, but only for personal attacks. > > Such as yours. > > I think I've shown extreme restraint in the face of bullying from you > and some followers, and calling the insinuations bullshit is quite mild. I don't have "followers". Assertions I make are my own, and stand alone without the need of support. Calling them "bullshit" is indeed quite mild, but doesn't invalidate them. You can only do that by engaging, but instead you hysterically shout "ad hominem" whenever anyone makes a personal remark. > >> but when we try to point >> out aspects of your behavior that are either undesirable or unacceptable >> we are indulging in "ad hominem attacks". > > That is an untrue and extremely misleading description of what you've > been doing. > I'll let that be judged on the record. You have consistently refused to accept, despite assertions from several individuals (presumably those you choose to characterize as my "followers", thereby allowing you to write them off without seriously considering what they say - at least that is how it looks from the outside) that criticism of your behavior is not, in fact, an ad hominem attack but an attempt to engage you in debate and have you modify that behavior. So, for the final time: remarks about personal characteristics only constitute ad hominem attacks ONLY when they are made for the purpose of invalidating other (typically, in this group, technical) arguments. If we met in person at a conference (God help us both) and you sat in an open space session picking your nose, would you deem it an "ad hominem attack" if I told you to stop? It sounds like it, even though I would tell you to stop not so that others would respect your technical arguments any less, but because by departing from the accepted standards of behavior you would offend others. > >> In your terms, your accusing me of bullying behavior is an ad hominem >> attack on me, so I won't bother to respond further. > > You're complaining about the person you're hitting saying clearly what > you did. > > If some truthful words about bullying can get you straight I'm for it. > > Even if it means getting down to your level (and yes, I did). > Nope, I'm not complaining at all. That's your tactic: "look, Steve is hitting me". You are entitled to write what you like on this newsgroup, but you have to accept that it will have consequences. I am simply pointing out that what's sauce for the goose is sauce for the gander. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Feb 11 10:59:49 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 10:59:49 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: Alf P. Steinbach wrote: > * Steven D'Aprano: [...] >> accusing them of lying for having an opinion that differs from yours, > > That is untrue. > Well, that says it all really. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From mrkafk at gmail.com Thu Feb 11 11:17:44 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 17:17:44 +0100 Subject: Any way to turn off exception handling? (debugging) Message-ID: Hello everyone, I'm getting an exception (on socket) handled in a program I'm trying to debug. I have trouble locating where exactly that happens. In such situation turning exception handling off could be useful, bc unhandled exception stack trace is precisely what I'm trying to obtain. Anybody knows of such possibility? Regards, mk From martin.hellwig at dcuktec.org Thu Feb 11 11:23:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Feb 2010 16:23:34 +0000 Subject: method names nounVerb or verbNoun In-Reply-To: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> References: <8336759e-b47b-45dc-8d10-03e4e7ee00c4@s17g2000vbs.googlegroups.com> Message-ID: On 02/05/10 19:53, Wanderer wrote: > Which is the more accepted way to compose method names nounVerb or > verbNoun? > > For example voltageGet or getVoltage? getVoltage sounds more normal, > but voltageGet is more like voltage.Get. I seem to mix them and I > should probably pick one way and stick with it. > > Thanks For me personally I do the following: spam_get/spam_set; might be preferred if you have more spam_* functions (i.e. spam_del, spam_eat, etc.) set_spam/get_spam; is I think reasonable if you have also a *_ham function (i.e. set_ham, get_ham). Funny thing for me is that when I have both spam_* & *_ham naming, I usually rethink my approach and split it out to separate classes/modules. Please note that this is at the moment a personal, uneducated, never really thought about it, preference. Meaning it is very likely that with some more insight there is a good chance that I find my approach in retrospect flawed. -- mph From jpiitula at ling.helsinki.fi Thu Feb 11 11:23:38 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 11 Feb 2010 18:23:38 +0200 Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Robert Kern writes: > On 2010-02-11 06:31 AM, Shashwat Anand wrote: > > There is a little issue here that '>>> -.1 ** .1' should give you > > error message. That is it. > > No, fractional powers of negative numbers are perfectly valid > mathematically. The result is a complex number. In Python 3 (what > the OP is using), this has been implemented, but not in Python 2.6. Perhaps it should raise a MisleadingSpacingError at compile time. The error message could recommend - .1**.1, or better -(.1 ** .1). From steve at holdenweb.com Thu Feb 11 11:27:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 11:27:17 -0500 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: Message-ID: mk wrote: > Hello everyone, > > I'm getting an exception (on socket) handled in a program I'm trying to > debug. I have trouble locating where exactly that happens. > > In such situation turning exception handling off could be useful, bc > unhandled exception stack trace is precisely what I'm trying to obtain. > > Anybody knows of such possibility? > > Regards, > mk > If the exception is currently being trapped by a handler in your code you could just insert a "raise" statement at the start of that handler. This will re-raise the same exception, which will presumably not be caught a second time? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 11 11:41:58 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 11 Feb 2010 17:41:58 +0100 Subject: Dreaming of new generation IDE In-Reply-To: References: Message-ID: <4b743340$0$20738$426a74cc@news.free.fr> catonano a ?crit : (snip) > Today, I tried to understand the twisted.web.client code and I found 3 > methods I couldn't find by who were called. > > I asked on the mailing list and they suggested me where they were > called and that the tool for such thing is "grep". > > So, you grep, you get a list of files, you open each one of them and > keep scrolling May I suggest reading grep's FineManual ? with proper options, you'll get not only the file, but also the exact lines (and lineno) where the expression appears. > If it's this, then it's not experimental at all, it's been done > already and been put apart. > > Crap won :-( Ever read "worst is better" ?-) Now, image-based systems like Smalltalk do have their share of quirks and drawbacks too. Also, Smalltalk's toolbox can only be used by and for Smalltalk. A bit autistic, he ? I'm doing mostly web development nowadays. That means that I'm constantly switching between server-side code (mostly Python or PHP but can be almost any other language), shell scripts, SQL, html + whatever templating language is used by this project, javascript and css. And of course quite a few configuration file formats... So well, as far as I'm concerned, not having to learn 42+ different toolboxes is a big plus (having to remember 42+ different languages is already hard enough) - I can use a same code editor (Emacs) and standard unix/linux text-handling tools on all my codebase. From aahz at pythoncraft.com Thu Feb 11 11:43:45 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 08:43:45 -0800 Subject: Terminating threaded programs References: Message-ID: In article , mk wrote: > >I have a problem with a threaded program: it frequently hangs on sys.exit. > >The problem is that my program uses threads which in turn use paramiko >library, which itself is threaded. > >I try to gracefully close the threads (below), but it doesn't always >work, if paramiko calls happen to be at stage of negotiating ssh >connection or smth similar. > >The only workable solution I have is a program sending itself SIGKILL, >which makes it terminated by OS (I think so). You can also use os._exit(). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From mrkafk at gmail.com Thu Feb 11 11:45:05 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 17:45:05 +0100 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: kj wrote: > I have read a *ton* of stuff on Unicode. It doesn't even seem all > that hard. Or so I think. Then I start writing code, and WHAM: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) > > (There, see? My Unicodephobia just went up a notch.) > > Here's the thing: I don't even know how to *begin* debugging errors > like this. This is where I could use some help. >>> a=u'\u0104' >>> >>> type(a) >>> >>> nu=a.encode('utf-8') >>> >>> type(nu) See what I mean? You encode INTO string, and decode OUT OF string. To make matters more complicated, str.encode() internally DECODES from string into unicode: >>> nu '\xc4\x84' >>> >>> type(nu) >>> nu.encode() Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128) There's logic to this, although it makes my brain want to explode. :-) Regards, mk From mgulsoy at gmail.com Thu Feb 11 11:45:30 2010 From: mgulsoy at gmail.com (M3RT) Date: Thu, 11 Feb 2010 08:45:30 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: Hi, The problem may be related to how you treat the EDI file or lets say DATA. Also your coding style is important. Can you provide more info? From mrkafk at gmail.com Thu Feb 11 11:47:59 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 17:47:59 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: Message-ID: Steve Holden wrote: >> I'm getting an exception (on socket) handled in a program I'm trying to >> debug. I have trouble locating where exactly that happens. > If the exception is currently being trapped by a handler in your code It's not my code. > you could just insert a "raise" statement at the start of that handler. > This will re-raise the same exception, which will presumably not be > caught a second time? I don't know where the handler is, that is precisely a problem. I'm trying to locate that handler. Regards, mk From simon at brunningonline.net Thu Feb 11 12:07:46 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 11 Feb 2010 17:07:46 +0000 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: Message-ID: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> On 11 February 2010 16:17, mk wrote: > I'm getting an exception (on socket) handled in a program I'm trying to > debug. I have trouble locating where exactly that happens. > > In such situation turning exception handling off could be useful, bc > unhandled exception stack trace is precisely what I'm trying to obtain. > > Anybody knows of such possibility? Not as far as I know. Besides, the chances are that if you were to be able to turn off exception handling altogether your code wouldn't make it as far as the code you are interested in anyway. Is there some way you could monkey patch the exception class to add some logging in there or something? -- Cheers, Simon B. From hjebbers at gmail.com Thu Feb 11 12:12:20 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 09:12:20 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On Feb 11, 5:45?pm, M3RT wrote: > Hi, > > The problem may be related to how you treat the EDI file or lets say > DATA. Also your coding style is important. Can you provide more info? Yes, a whole lot more; but I do not want to bother you with that now. I was just wondering if it is possible that the same setup gives a CRASH! on windows and just works on linux. (where is the bug?) kind regards, henk-jan From coldtortuga at gmail.com Thu Feb 11 12:30:04 2010 From: coldtortuga at gmail.com (Francis Carr) Date: Thu, 11 Feb 2010 09:30:04 -0800 (PST) Subject: Dreaming of new generation IDE References: Message-ID: <5b51740d-11f1-4f01-b51c-d1b6ea161eb7@l19g2000yqb.googlegroups.com> > I can't believe the code editing situation today is in a such sorry > state. I can't believe an old coder is feeling so sorry for himself. > Today, I tried to understand the twisted.web.client code and I found 3 > methods I couldn't find by who were called. > > I asked on the mailing list and they suggested me where they were > called and that the tool for such thing is "grep". > > So, you grep, you get a list of files, you open each one of them and > keep scrolling and switching from one file to another... endlessly. > Maybe I'm getting old, but I tend to get lost in the process. Maybe the relevant lesson to be taken from Smalltalk is *not* "put it all in one image" but instead "write code to solve problems, e.g., reading code" I suggest defining a few shell functions to *automate* the search, for example in zsh function allf () { # Recursively find files with suffix matching comma-separated list in $1. # For example, "allf cpp,hpp" finds all "*.cpp" and "*.hpp". find . -type f | grep -E "\.(${1//,/|})$" } function src () { # Similar to "allf", then search for a regex among the results. find . -type f -print0 | grep -zE "\.(${1//,/|})$" | xargs -0 grep - lE $2 } function srcl () { # Similar to "src" (see above), # then search for a pattern among the results, # and pass matching files to "less". src $1 $2 | xargs less -p $2 } Smalltalk's images are cool. But they are such a huge hammer, and they impose so many additional requirements! The costs outweigh the cool. -- FC From mrkafk at gmail.com Thu Feb 11 12:32:55 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 18:32:55 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> Message-ID: Simon Brunning wrote: > Not as far as I know. Besides, the chances are that if you were to be > able to turn off exception handling altogether your code wouldn't make > it as far as the code you are interested in anyway. Sure, but I could deal with that, jerry-rigging the code as exceptions go by, finally reaching the exception I care about. With all the problems, this would still be much better than nothing. As thing are, the only way to do this is guessing and turning particular try / except blocks off. (a really nifty solution would be turning exceptions on or off per module / file basis). IIRC Lua and/or C++ do have this ability, why not Python? I smell material for a PEP. > Is there some way you could monkey patch the exception class to add > some logging in there or something? Sure I can, but how do I get out of Python the info *what called particular class/instance*? That is, how do I know who's the caller? Regards, mk From no.email at please.post Thu Feb 11 12:37:27 2010 From: no.email at please.post (kj) Date: Thu, 11 Feb 2010 17:37:27 +0000 (UTC) Subject: Need debugging knowhow for my creeping Unicodephobia References: Message-ID: In mk writes: >To make matters more complicated, str.encode() internally DECODES from >string into unicode: > >>> nu >'\xc4\x84' > >>> > >>> type(nu) > > >>> nu.encode() >Traceback (most recent call last): > File "", line 1, in >UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: >ordinal not in range(128) >There's logic to this, although it makes my brain want to explode. :-) Thanks for pointing this one out! It could have easily pushed my Unicodephobia into the incurable zone... ~K From apt.shansen at gmail.com Thu Feb 11 12:45:52 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 11 Feb 2010 09:45:52 -0800 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> Message-ID: <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> On Thu, Feb 11, 2010 at 9:32 AM, mk wrote: > Simon Brunning wrote: > >> Not as far as I know. Besides, the chances are that if you were to be >> able to turn off exception handling altogether your code wouldn't make >> it as far as the code you are interested in anyway. >> > > Sure, but I could deal with that, jerry-rigging the code as exceptions go > by, finally reaching the exception I care about. > > With all the problems, this would still be much better than nothing. As > thing are, the only way to do this is guessing and turning particular try / > except blocks off. > > (a really nifty solution would be turning exceptions on or off per module / > file basis). > > IIRC Lua and/or C++ do have this ability, why not Python? > > I smell material for a PEP. Um, Lua has nothing even vaguely like Python's exceptions. It has errors, and you can "catch" them only by doing a protected call. Otherwise they halt the entire interpreter. Python exceptions are pervasive. I don't think you fully understand HOW pervasive they are-- "turning off" exceptions would utterly break a -vast- amount of Python code. Exceptions are not errors: exceptions are the uncommon, the exceptional, case. If one could somehow turn off exceptions, you can't even do a for loop: every for loop would become infinite-- exceptions are how Python signals the end of an iterator. Think about that, *every* for loop in Python suddenly breaks. They're also used in countless other areas which are simply not errors. > Is there some way you could monkey patch the exception class to add >> some logging in there or something? >> > > Sure I can, but how do I get out of Python the info *what called particular > class/instance*? That is, how do I know who's the caller? > Um... run your code in a debugger. That's what debugger's are -for-. "pdb" is a simple one. Various IDE's have more advanced ones. I think you're better served showing us what, "I'm getting an exception (on socket) handled..." actually means, what is actually happening with real code and output, and getting pointers on where to look, then trying to gather material to support an honestly impossible change :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Feb 11 12:46:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 17:46:29 +0000 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: <4B744275.4000503@mrabarnett.plus.com> mk wrote: > kj wrote: >> I have read a *ton* of stuff on Unicode. It doesn't even seem all >> that hard. Or so I think. Then I start writing code, and WHAM: >> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position >> 0: ordinal not in range(128) >> >> (There, see? My Unicodephobia just went up a notch.) >> >> Here's the thing: I don't even know how to *begin* debugging errors >> like this. This is where I could use some help. > > >>> a=u'\u0104' > >>> > >>> type(a) > > >>> > >>> nu=a.encode('utf-8') > >>> > >>> type(nu) > > > > See what I mean? You encode INTO string, and decode OUT OF string. > Traditionally strings were string of byte-sized characters. Because they were byte-sided they could also be used to contain binary data. Then along came Unicode. When working with Unicode in Python 2, you should use the 'unicode' type for text (Unicode strings) and limit the 'str' type to binary data (bytestrings, ie bytes) only. In Python 3 they've been renamed to 'str' for Unicode _strings_ and 'bytes' for binary data (bytes!). > To make matters more complicated, str.encode() internally DECODES from > string into unicode: > > >>> nu > '\xc4\x84' > >>> > >>> type(nu) > > >>> nu.encode() > Traceback (most recent call last): > File "", line 1, in > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: > ordinal not in range(128) > > There's logic to this, although it makes my brain want to explode. :-) > Strictly speaking, only Unicode can be encoded. What Python 2 is doing here is trying to be helpful: if it's already a bytestring then decode it first to Unicode and then re-encode it to a bytestring. Unfortunately, the default encoding is ASCII, and the bytestring isn't valid ASCII. Python 2 is being 'helpful' in a bad way! From __peter__ at web.de Thu Feb 11 13:01:15 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Feb 2010 19:01:15 +0100 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: hjebbers wrote: > On Feb 11, 5:45 pm, M3RT wrote: >> The problem may be related to how you treat the EDI file or lets say >> DATA. Also your coding style is important. Can you provide more info? > > Yes, a whole lot more; but I do not want to bother you with that now. > I was just wondering if it is possible that the same setup gives a > CRASH! on windows and just works on linux. > (where is the bug?) In the platform-specific code ;) Even on alt.haruspicy they cannot do much without a liver now and then... From python at mrabarnett.plus.com Thu Feb 11 13:06:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 18:06:34 +0000 Subject: ANN: obfuscate In-Reply-To: <4B73D1E8.9040603@cheimes.de> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> Message-ID: <4B74472A.6010301@mrabarnett.plus.com> Christian Heimes wrote: > Gregory Ewing wrote: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the >> German forces that used their Enigmas differently, avoiding those >> mistakes, and the British never managed to crack any of their >> messages. > > IIRC some versions of the Enigma weren't cracked because they used a > different setup and different daily keys. > > The predecessor of the Enigma was cracked by Polish scientists years > before WW2 started. Some flaws in the instructions and a known plain > text attack made the crack of the Enigma practical. It took the > British scientists merely hours rather than days or weeks to decipher > the daily key with some smart tricks. For example they started fake > attacks on ships or cities just to have the names in some encrypted > reports. > In some cases the British had decoded the messages before the intended recipient! The Americans decoded Japanese messages about an planned attack on an island, but didn't know which one because of the fake names, so they instructed their bases to report certain problems in a way that the Japanese could decode. Midway reported a shortage of water, the Japanese decoded it and sent a message about it, the Americans decoded their message and discovered that island's fake name, and thus found out that Midway was the intended target of the attack. From no.email at nospam.invalid Thu Feb 11 13:14:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Feb 2010 10:14:39 -0800 Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: <7xpr4bwsfk.fsf@ruckus.brouhaha.com> mk writes: >> Um... run your code in a debugger. > > ..except the code in question is multithreaded and pdb is no good for > that, and last time I checked, yappi was broken. Try winpdb.org. From mrkafk at gmail.com Thu Feb 11 13:19:52 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 19:19:52 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: > the uncommon, the exceptional, case. If one could somehow turn off > exceptions, you can't even do a for loop: every for loop would become > infinite-- exceptions are how Python signals the end of an iterator. > Think about that, *every* for loop in Python suddenly breaks. Ouch. > Sure I can, but how do I get out of Python the info *what called > particular class/instance*? That is, how do I know who's the caller? > > > Um... run your code in a debugger. ..except the code in question is multithreaded and pdb is no good for that, and last time I checked, yappi was broken. > > That's what debugger's are -for-. > > "pdb" is a simple one. Various IDE's have more advanced ones. I tried using pdb on paramiko and my own threaded code, lost some hair in the process, and gave up. It's good for tracing the main thread, basically, not for threading.Threads. > I think you're better served showing us what, "I'm getting an exception > (on socket) handled..." actually means, what is actually happening with > real code and output, and getting pointers on where to look, then trying > to gather material to support an honestly impossible change :) I'm using a threaded library paramiko (probably by now half of this group is sick of hearing me saying this again). 2 of (rather broken) hosts (Solaris, Linux) are really, really slow when responding over SSH, like a minute for a key exchange. In paramiko, timeout doesn't work bc the timeout specified there is timeout for a socket and not for SSH. When calling transport.socket.close() via threading.Timer like this: def printandclose(self): print "\ntrying to close transport.sock" self.trans.sock.close() self.flag = True self.flag = False timer = threading.Timer(4, self.printandclose) timer.start() self.trans.start_client() timer.cancel() ... I'm getting this on the console: ERROR (9, 'Bad file descriptor') According to a guy who is very knowledgable on the library (thanks for all the help, James) this is result of catching socket.error somewhere in paramiko code, like "except socket.error". I need to find that place. On top of lack of proper handling of timeouts, this is important bc when calling paramiko SSHClient.connect() (which in turn uses the same machinery as transport.start_client IIRC) paramiko uses close to 100% of CPU when negotiating with such broken or unresponsive hosts. For my reasons, I need to get this fixed. Regards, mk From mrkafk at gmail.com Thu Feb 11 13:24:31 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 19:24:31 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Stephen Hansen wrote: > the uncommon, the exceptional, case. If one could somehow turn off > exceptions, you can't even do a for loop: every for loop would become > infinite-- exceptions are how Python signals the end of an iterator. > Think about that, *every* for loop in Python suddenly breaks. Hmm what if one could turn off exception handling for particular exception classes? From mrabarnett at mrabarnett.plus.com Thu Feb 11 13:24:32 2010 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Thu, 11 Feb 2010 18:24:32 +0000 Subject: ANN: obfuscate In-Reply-To: <7x6364gg8t.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <7x6364gg8t.fsf@ruckus.brouhaha.com> Message-ID: <4B744B60.8070202@mrabarnett.plus.com> Paul Rubin wrote: > Gregory Ewing writes: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the German >> forces that used their Enigmas differently, avoiding those mistakes, >> and the British never managed to crack any of their messages. > > I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they > were more careful with procedures, but the machine was also harder to > crack because it had four rotors instead of three. IIRC, the Brits were > eventually (1942?) able to capture one by shooting up a German submarine > and boarding it to get the machine while the sub was sinking; a British > sailor wasn't able to get out in time and drowned during that operation. > Getting the rotor settings off the captured unit (they may have had to > do it more than once) was enough to get a foothold into the code. My > memory is hazy on this by now so I may have some parts wrong, but David > Kahn's book "Seizing the Enigma" tells the story (I read it many years > ago). A fictionalized version appears in Neil Stephenson's novel > "Cryptonomicon". U-559? I think that's the one where Hollywood made a film about it, but portraying it as a purely American action. That didn't go down too well in the UK! From python at mrabarnett.plus.com Thu Feb 11 13:24:52 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Feb 2010 18:24:52 +0000 Subject: ANN: obfuscate In-Reply-To: <7x6364gg8t.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <7x6364gg8t.fsf@ruckus.brouhaha.com> Message-ID: <4B744B74.30309@mrabarnett.plus.com> Paul Rubin wrote: > Gregory Ewing writes: >> Actually I gather it had a lot to do with the fact that the Germans >> made some blunders in the way they used the Enigma that seriously >> compromised its security. There was reportedly a branch of the German >> forces that used their Enigmas differently, avoiding those mistakes, >> and the British never managed to crack any of their messages. > > I think you are thinking of the Kriegsmarine (naval) Enigma. Yes they > were more careful with procedures, but the machine was also harder to > crack because it had four rotors instead of three. IIRC, the Brits were > eventually (1942?) able to capture one by shooting up a German submarine > and boarding it to get the machine while the sub was sinking; a British > sailor wasn't able to get out in time and drowned during that operation. > Getting the rotor settings off the captured unit (they may have had to > do it more than once) was enough to get a foothold into the code. My > memory is hazy on this by now so I may have some parts wrong, but David > Kahn's book "Seizing the Enigma" tells the story (I read it many years > ago). A fictionalized version appears in Neil Stephenson's novel > "Cryptonomicon". U-559? I think that's the one where Hollywood made a film about it, but portraying it as a purely American action. That didn't go down too well in the UK! From __peter__ at web.de Thu Feb 11 13:35:59 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Feb 2010 19:35:59 +0100 Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: mk wrote: > >> the uncommon, the exceptional, case. If one could somehow turn off >> exceptions, you can't even do a for loop: every for loop would become >> infinite-- exceptions are how Python signals the end of an iterator. >> Think about that, *every* for loop in Python suddenly breaks. > > Ouch. > >> Sure I can, but how do I get out of Python the info *what called >> particular class/instance*? That is, how do I know who's the caller? >> >> >> Um... run your code in a debugger. > > ..except the code in question is multithreaded and pdb is no good for > that, and last time I checked, yappi was broken. > >> >> That's what debugger's are -for-. >> >> "pdb" is a simple one. Various IDE's have more advanced ones. > > I tried using pdb on paramiko and my own threaded code, lost some hair > in the process, and gave up. It's good for tracing the main thread, > basically, not for threading.Threads. > >> I think you're better served showing us what, "I'm getting an exception >> (on socket) handled..." actually means, what is actually happening with >> real code and output, and getting pointers on where to look, then trying >> to gather material to support an honestly impossible change :) > > I'm using a threaded library paramiko (probably by now half of this > group is sick of hearing me saying this again). 2 of (rather broken) > hosts (Solaris, Linux) are really, really slow when responding over SSH, > like a minute for a key exchange. In paramiko, timeout doesn't work bc > the timeout specified there is timeout for a socket and not for SSH. > > When calling transport.socket.close() via threading.Timer like this: > > def printandclose(self): > print "\ntrying to close transport.sock" > self.trans.sock.close() > self.flag = True > > > self.flag = False > timer = threading.Timer(4, self.printandclose) > timer.start() > self.trans.start_client() > timer.cancel() > > ... I'm getting this on the console: > > ERROR (9, 'Bad file descriptor') > > According to a guy who is very knowledgable on the library (thanks for > all the help, James) this is result of catching socket.error somewhere > in paramiko code, like "except socket.error". > > I need to find that place. On top of lack of proper handling of > timeouts, this is important bc when calling paramiko SSHClient.connect() > (which in turn uses the same machinery as transport.start_client IIRC) > paramiko uses close to 100% of CPU when negotiating with such broken or > unresponsive hosts. > > For my reasons, I need to get this fixed. You could try to shadow the exception class with None: >>> ZeroDivisionError = None >>> try: ... 1/0 ... except ZeroDivisionError: ... print "caught" ... Traceback (most recent call last): File "", line 2, in ZeroDivisionError: integer division or modulo by zero Applying that technique on a module containing try: ... except socket.error: ... #untested import socket class SocketWrapper: def __getattr__(self, name): return getattr(socket, name) error = None import module_using_socket module_using_socket.socket = SocketWrapper() Peter From steve at holdenweb.com Thu Feb 11 13:42:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 13:42:08 -0500 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: mk wrote: > Stephen Hansen wrote: >> the uncommon, the exceptional, case. If one could somehow turn off >> exceptions, you can't even do a for loop: every for loop would become >> infinite-- exceptions are how Python signals the end of an iterator. >> Think about that, *every* for loop in Python suddenly breaks. > > Hmm what if one could turn off exception handling for particular > exception classes? > An extension of the warnings mechanism might be the easiest way to play with an implementation ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From invalid at invalid.invalid Thu Feb 11 13:43:23 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 11 Feb 2010 18:43:23 +0000 (UTC) Subject: Bizarre arithmetic results References: Message-ID: On 2010-02-11, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 > -0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b > (0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? Didn't we just do this one last week? -- Grant Edwards grante Yow! Hello? Enema Bondage? at I'm calling because I want visi.com to be happy, I guess ... From breamoreboy at yahoo.co.uk Thu Feb 11 13:53:04 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 11 Feb 2010 18:53:04 +0000 Subject: ANN: obfuscate In-Reply-To: <4B73D1E8.9040603@cheimes.de> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> Message-ID: Christian Heimes wrote: > Gregory Ewing wrote: >> Actually I gather it had a lot to do with the fact that >> the Germans made some blunders in the way they used the >> Enigma that seriously compromised its security. There >> was reportedly a branch of the German forces that used >> their Enigmas differently, avoiding those mistakes, and >> the British never managed to crack any of their messages. > > IIRC some versions of the Enigma weren't cracked because they used a > different setup and different daily keys. > > The predecessor of the Enigma was cracked by Polish scientists years > before WW2 started. Some flaws in the instructions and a known plain > text attack made the crack of the Enigma practical. It took the British > scientists merely hours rather than days or weeks to decipher the daily > key with some smart tricks. For example they started fake attacks on > ships or cities just to have the names in some encrypted reports. I believe that all of Enigma was eventually cracked cos of two major flaws. 1) A letter could never be sent as itself. 2) The Luftwaffe were very poor when compared to the Wehrmacht or Kriegsmarine about security so they were a major leak of data regarding the other organisations. 3) The users instead of using random three letter combinations kept using the same ones. HIT LER and BER LIN were popular, but the most famous one at Bletchley Park was the name of the guy's girlfriend. Further, the far more powerful Geheimscreiber was also cracked at Bletchley by using Colossus. Sorry some years since I read the book about this so can't remember the title or author. Regards. Mark Lawrence. From ssteinerx at gmail.com Thu Feb 11 13:57:29 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Thu, 11 Feb 2010 13:57:29 -0500 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: <15A7B7FA-BE34-4A6B-9D84-47CF3683E6DA@gmail.com> On Feb 11, 2010, at 11:43 AM, Aahz wrote: > In article , > mk wrote: >> >> I have a problem with a threaded program: it frequently hangs on sys.exit. >> >> The problem is that my program uses threads which in turn use paramiko >> library, which itself is threaded. >> >> I try to gracefully close the threads (below), but it doesn't always >> work, if paramiko calls happen to be at stage of negotiating ssh >> connection or smth similar. >> >> The only workable solution I have is a program sending itself SIGKILL, >> which makes it terminated by OS (I think so). > > You can also use os._exit(). This just came up on the Twisted IRC channel last night and came to the same conclusion. Python's going to wait for threads to terminate and if they're not going to, neither is Python. os._exit() came up as the 'last resort' way out of the app. S From mrkafk at gmail.com Thu Feb 11 14:10:30 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 20:10:30 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: <7xpr4bwsfk.fsf@ruckus.brouhaha.com> References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> <7xpr4bwsfk.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > mk writes: >>> Um... run your code in a debugger. >> ..except the code in question is multithreaded and pdb is no good for >> that, and last time I checked, yappi was broken. > > Try winpdb.org. This is a treasure! In minutes I've had this attached to remote process and debugging threads. Muchos gracias Paul! Regards, mk From mattbarkan at gmail.com Thu Feb 11 14:11:51 2010 From: mattbarkan at gmail.com (galileo228) Date: Thu, 11 Feb 2010 11:11:51 -0800 (PST) Subject: python and http POST Message-ID: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Hey All, Been teaching myself Python for a few weeks, and am trying to write a program that will go to a url, enter a string in one of the search fields, submit the search, and return the contents of the search result. I'm using httplib2. My two particular questions: 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), how do I know what the particular key should be? In other words, how do I tell python which form on the web page I'm visiting I'd like to fill in? Do I simply go to the webpage itself and look at the html source? But if that's the case, which tag tells me the name of the key? 2) Even once python fills in the form properly, how can I tell it to 'submit' the search? Thanks all! Matt From mrkafk at gmail.com Thu Feb 11 14:12:23 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 20:12:23 +0100 Subject: Any way to turn off exception handling? (debugging) In-Reply-To: References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Peter Otten wrote: > try: > ... > except socket.error: > ... > > #untested > import socket > > class SocketWrapper: > def __getattr__(self, name): > return getattr(socket, name) > error = None > > import module_using_socket > module_using_socket.socket = SocketWrapper() Very interesting solution. Thanks! Regards, mk From hjebbers at gmail.com Thu Feb 11 14:19:08 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 11:19:08 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On Feb 11, 7:01?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 5:45 pm, M3RT wrote: > >> The problem may be related to how you treat the EDI file or lets say > >> DATA. Also your coding style is important. Can you provide more info? > > > Yes, a whole lot more; but I do not want to bother you with that now. > > I was just wondering if it is possible that the same setup gives a > > CRASH! on windows and just works on linux. > > (where is the bug?) > > In the platform-specific code ;) > > Even on alt.haruspicy they cannot do much without a liver now and then... if it is in the platform-specific code should I make this into a bugreport? (because the crash does not appear at the same place in my code (when doing the same test-run) it will be quite hard to point down....) henk-jan From hjebbers at gmail.com Thu Feb 11 14:30:22 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 11:30:22 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On Feb 11, 7:01?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 5:45 pm, M3RT wrote: > >> The problem may be related to how you treat the EDI file or lets say > >> DATA. Also your coding style is important. Can you provide more info? > > > Yes, a whole lot more; but I do not want to bother you with that now. > > I was just wondering if it is possible that the same setup gives a > > CRASH! on windows and just works on linux. > > (where is the bug?) > > In the platform-specific code ;) > > Even on alt.haruspicy they cannot do much without a liver now and then... if it is in the platform-specific code should I make this into a bugreport? (because the crash does not appear at the same place in my code (when doing the same test-run) it will be quite hard to point down....) henk-jan From danijel.gvero at gmail.com Thu Feb 11 14:31:52 2010 From: danijel.gvero at gmail.com (DANNY) Date: Thu, 11 Feb 2010 11:31:52 -0800 (PST) Subject: MODULE FOR I, P FRAME Message-ID: Hello! I am currently developing a simple video player in python, and my problem is that i can't find a module which has a function that can determine if frame(image) is I or P coded (MPEG coding). I have been using PIL but I couldnt find anything that could help me with that problem. Thanks for sugestions! From hjebbers at gmail.com Thu Feb 11 14:40:39 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 11:40:39 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> On Feb 11, 7:01?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 5:45 pm, M3RT wrote: > >> The problem may be related to how you treat the EDI file or lets say > >> DATA. Also your coding style is important. Can you provide more info? > > > Yes, a whole lot more; but I do not want to bother you with that now. > > I was just wondering if it is possible that the same setup gives a > > CRASH! on windows and just works on linux. > > (where is the bug?) > > In the platform-specific code ;) > > Even on alt.haruspicy they cannot do much without a liver now and then... if it is in the platform-specific code should I make this into a bugreport? (because the crash does not appear at the same place in my code (when doing the same test-run) it will be quite hard to point down....) henk-jan From malaclypse2 at gmail.com Thu Feb 11 14:42:42 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Thu, 11 Feb 2010 14:42:42 -0500 Subject: python crash on windows but not on linux In-Reply-To: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <16651e81002111142g1447cd87t74e7f932873e7fac@mail.gmail.com> On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > To all, > I am running an EDI translator, and doing stress tests. > When processing a test with a (relatively) big EDI file(s) on > windowsXP ?I get a crash: > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > causing the problem) > You need to give us more information if we're going to be able to help. At the very least, you'll need to copy & paste the actual error message. It would be even better if you could show us some of your code, and better yet if you could give us a small bit of code that is self contained and reproduces the problem you're experiencing. -- Jerry From nathan.farrar at gmail.com Thu Feb 11 14:47:24 2010 From: nathan.farrar at gmail.com (Nathan Farrar) Date: Thu, 11 Feb 2010 12:47:24 -0700 Subject: PExpect Cross-Platform Alternative Message-ID: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Hello Community, Recently I've been automating lots of network operations tasks via simple python scripts. Originally, I utilized paramiko but found that the module had issues working with cisco equipment. I switched to pexpect and things have worked wonderfully since (I've been running this scripts in a Linux environment). However, I was just tasked to get these scripts running in a windows environment and to my dismay very quickly realized that pexpect is not cross platform compatible. Am I stuck, or are there solutions out there? Cheers! Nathan -- The men the American people admire most extravagantly are the most daring liars; the men they detest most violently are those who try to tell them the truth. -- H. L. Mencken -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 11 14:55:54 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 20:55:54 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steven D'Aprano: > [...] >>> accusing them of lying for having an opinion that differs from yours, >> That is untrue. >> > Well, that says it all really. You seem to insinuate that I'm saying that Steven is lying, and/or that Steven is lying. From context and your earlier similar behavior, I presume the former only. Anyway that's a *very* dirty insinuation. And ... It seems you *do not understand* the difference between an incorrect statement and a lie. Which is very telling, I'm sorry. And you have yet again concentrated on a personal attack via insinuation etc., diversion, which also is very telling, sorry. Cheers, - Alf From steve at holdenweb.com Thu Feb 11 14:57:39 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 14:57:39 -0500 Subject: PExpect Cross-Platform Alternative In-Reply-To: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> References: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Message-ID: Nathan Farrar wrote: > Hello Community, > > Recently I've been automating lots of network operations tasks via > simple python scripts. Originally, I utilized paramiko but found that > the module had issues working with cisco equipment. I switched to > pexpect and things have worked wonderfully since (I've been running this > scripts in a Linux environment). However, I was just tasked to get > these scripts running in a windows environment and to my dismay very > quickly realized that pexpect is not cross platform compatible. > > Am I stuck, or are there solutions out there? > It works pretty well under Cygwin (which also improves your Windows scripting environment no end). Any chance you would be allowed to install that? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ken at seehart.com Thu Feb 11 14:58:53 2010 From: ken at seehart.com (Ken Seehart) Date: Thu, 11 Feb 2010 11:58:53 -0800 Subject: python and http POST In-Reply-To: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <4B74617D.90709@seehart.com> "Use tamperdata to view and modify HTTP/HTTPS headers and post parameters... " https://addons.mozilla.org/en-US/firefox/addon/966 Enjoy, Ken galileo228 wrote: > Hey All, > > Been teaching myself Python for a few weeks, and am trying to write a > program that will go to a url, enter a string in one of the search > fields, submit the search, and return the contents of the search > result. > > I'm using httplib2. > > My two particular questions: > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > how do I know what the particular key should be? In other words, how > do I tell python which form on the web page I'm visiting I'd like to > fill in? Do I simply go to the webpage itself and look at the html > source? But if that's the case, which tag tells me the name of the > key? > > 2) Even once python fills in the form properly, how can I tell it to > 'submit' the search? > > Thanks all! > > Matt > From alfps at start.no Thu Feb 11 15:16:43 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 21:16:43 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: > [...] >>> In this particular part of the thread I am attempting, unsuccessfully, >>> to convince you that a change in *your* behavior would lead to less >>> hostility directed towards the way you present your ideas. >>> >>> You apparently feel it is quite acceptable to tell people to "learn to >>> read", >> I have not used that expression. >> >> However I have suggest and emphasized that it might help to *read* >> whatever one quotes, when the quoted material (such as one paragraph) >> has not been read. >> >> Telling someone to "learn to read" is a Steve Holden'sk way to imply >> that the person is an ignoramus who hasn't bothered to learn to read. >> Telling a person to read something that's obviously not been read is >> quite another matter. So, you are misrepresenting -- again -- and in >> a quite revealing way, sorry. >> > Pardon me? You used it on December 16 in a response to Mensanator in > message > > M :> How about devoting a section on downloading the source files > M :> and compiling it on a Mac? > > AS:> Learn to read. > > AS:> At the top of every second page it tells you that this is an > AS:> introduction based on Windows. > > I am sure you will have some glib response as to why this wasn't rude at > all. Allow me to correct you - it was, and rudeness is not welcomed on > comp.lang.python. That doesn't mean it doesn't happen (why, I have even > been known to be rude myself - we are none of us perfect, after all). > > I have already given ample evidence that when I am wrong I will admit > it. You, contrariwise, maintain that you will admit when you are wrong > (I believe 40% of the time was the figure you used) No, 40% of contested cases. But that was sort of a white lie. I'm not that often wrong, and anyway it doesn't apply to me in [comp.lang.python] so far. It only applies to groups where only things that might be incorrect are challenged. > but I fail to > remember any single incident when you made such an admission. Your memory seems to be very very bad, since I've stated I've been wrong also in direct debates with you. But one person who /does/ have severe trouble admitting that he's wrong, going to the extreme of ad hominem attacks and using terms such as "wring" to avoid saying it (it's quite amazing, almost unbelievable) is Steve Holden. Anyway, I was wrong about not having used that phrase "learn to read". I'm not sure if I ever apologized directly to Mensanator for that, and now it's history, but what I do know I did was to follow up on that comment of his, making changes, and to acknowledge him for that in the [ack.txt] listing. Any reader might draw conclusions from that, e.g. what I positively did or what I possibly forgot to do -- we're not perfect beings any of us. [Steve Holden rambling with personal characterizations & circular logic snipped] Cheers & hth., - Alf From mrkafk at gmail.com Thu Feb 11 15:17:54 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 21:17:54 +0100 Subject: Terminating threaded programs In-Reply-To: <7a9c25c21002081816r3b7a7c4fq5b079424dbd1f46e@mail.gmail.com> References: <7a9c25c21002081816r3b7a7c4fq5b079424dbd1f46e@mail.gmail.com> Message-ID: Stephen Hansen wrote: > I use threads all the time (well, for certain types of workloads) and > have never seen this. > > Are your threads daemon threads? The only time I've seen sys.exit() not > close out my program is when I'm launching non-daemon threads on accident. The snag is that my program is using calls to another threaded library (paramiko) which does lots of stuff with sockets and communication (SSH). Paramiko in turn calls Crypto which has compiled C extensions. I really don't know what's going on in there, just guessing that this might trigger this behavior. > Now, I do get some slightly random errors on close due to threads doing > stuff or returning from doing stuff while the shutdown procedure is > going on, but I don't really care, cuz, well, I'm shutting everything > down and nothing worth knowing is going on in the rest of the program. Same as me, except I get lots of exceptions in threads if I shut down with sys.exit. SIGTERM somehow gets around this problem. I'll try os._exit. Regards, mk From mrkafk at gmail.com Thu Feb 11 15:18:16 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 21:18:16 +0100 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: Aahz wrote: > You can also use os._exit(). Thanks! From mrkafk at gmail.com Thu Feb 11 15:22:09 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 21:22:09 +0100 Subject: Terminating threaded programs In-Reply-To: References: Message-ID: Aahz wrote: > You can also use os._exit(). Yes! It works cleanly! Thanks a million! OTOH, if I use sys.exit(), it's just hanging there. Regards, mk From jgardner at jonathangardner.net Thu Feb 11 16:03:22 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 11 Feb 2010 13:03:22 -0800 (PST) Subject: Is a merge interval function available? References: Message-ID: On Feb 10, 3:23?pm, Peng Yu wrote: > I'm wondering there is already a function in python library that can > merge intervals. For example, if I have the following intervals ('[' > and ']' means closed interval as inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...) > > [1, 3] > [2, 9] > [10,13] > [11,12] > > I want to get the following merged intervals. > > [1,9] > [10,13] > > Could somebody let me know if there is a function in the python > library? I vaguely recall a similar question a long time ago. Peng, is this a homework assignment? Perhaps we should add a standard module called "homework". It can have functions for all the different homework assignments we see on c.l.python. We can simply point people to this module and then can include the code in their answers. From alfps at start.no Thu Feb 11 16:37:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 22:37:46 +0100 Subject: Is a merge interval function available? In-Reply-To: References: Message-ID: * Jonathan Gardner: > On Feb 10, 3:23 pm, Peng Yu wrote: >> I'm wondering there is already a function in python library that can >> merge intervals. For example, if I have the following intervals ('[' >> and ']' means closed interval as inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...) >> >> [1, 3] >> [2, 9] >> [10,13] >> [11,12] >> >> I want to get the following merged intervals. >> >> [1,9] >> [10,13] >> >> Could somebody let me know if there is a function in the python >> library? > > I vaguely recall a similar question a long time ago. Peng, is this a > homework assignment? > > Perhaps we should add a standard module called "homework". It can have > functions for all the different homework assignments we see on > c.l.python. We can simply point people to this module and then can > include the code in their answers. If it's possible, there was/is this guy over in clc.c++ who responded/responds to homework questions with the most advanced, convoluted and, except for misleading names, technically correct solutions. Cheers, - Alf From mrkafk at gmail.com Thu Feb 11 16:43:17 2010 From: mrkafk at gmail.com (mk) Date: Thu, 11 Feb 2010 22:43:17 +0100 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: <4B744275.4000503@mrabarnett.plus.com> References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: MRAB wrote: > When working with Unicode in Python 2, you should use the 'unicode' type > for text (Unicode strings) and limit the 'str' type to binary data > (bytestrings, ie bytes) only. Well OK, always use u'something', that's simple -- but isn't str what I get from files and sockets and the like? > In Python 3 they've been renamed to 'str' for Unicode _strings_ and > 'bytes' for binary data (bytes!). Neat, except that the process of porting most projects and external libraries to P3 seems to be, how should I put it, standing still? Or am I wrong? But that's the impression I get? Take web frameworks for example. Does any of them have serious plans and work in place to port to P3? > Strictly speaking, only Unicode can be encoded. How so? Can't bytestrings containing characters of, say, koi8r encoding be encoded? > What Python 2 is doing here is trying to be helpful: if it's already a > bytestring then decode it first to Unicode and then re-encode it to a > bytestring. It's really cumbersome sometimes, even if two libraries are written by one author: for instance, Mako and SQLAlchemy are written by the same guy. They are both top-of-the line in my humble opinion, but when you connect them you get things like this: 1. you query SQLAlchemy object, that happens to have string fields in relational DB. 2. Corresponding Python attributes of those objects then have type str, not unicode. 3. then I pass those objects to Mako for HTML rendering. Typically, it works: but if and only if a character in there does not happen to be out of ASCII range. If it does, you get UnicodeDecodeError on an unsuspecting user. Sure, I wrote myself a helper that iterates over keyword dictionary to make sure to convert all str to unicode and only then passes the dictionary to render_unicode. It's an overhead, though. It would be nicer to have it all unicode from db and then just pass it for rendering and having it working. (unless there's something in filters that I missed, but there's encoding of templates, tags, but I didn't find anything on automatic conversion of objects passed to method rendering template) But maybe I'm whining. > Unfortunately, the default encoding is ASCII, and the bytestring isn't > valid ASCII. Python 2 is being 'helpful' in a bad way! And the default encoding is coded in such way so it cannot be changed in sitecustomize (without code modification, that is). Regards, mk From astan.chee at al.com.au Thu Feb 11 16:43:25 2010 From: astan.chee at al.com.au (Astan Chee) Date: Fri, 12 Feb 2010 08:43:25 +1100 Subject: calculating a string equation Message-ID: <4B7479FD.2050400@al.com.au> Hi, I have some variables in my script that looks like this: vars = {'var_a':'10','var_b':'4'} eqat = "(var_a/2.0) <= var_b" result = "(var_a+var_b)/7" What I'm trying to do is to plug in var_a and var_b's values from vars into eqat and see if eqat returns true or false as well as getting the value of result if these variables were "plugged in". How do I do this? I'm also expecting eqat and result to contain various python mathematical operators like **, and compounded ()'s. I'm not sure how to convert the equation; if I have to make a bunch of if-statements or if there is a python function that already does something like this. Thanks for any help. Cheers Astan From robert.kern at gmail.com Thu Feb 11 16:48:12 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 11 Feb 2010 15:48:12 -0600 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: On 2010-02-11 15:43 PM, mk wrote: > MRAB wrote: >> Strictly speaking, only Unicode can be encoded. > > How so? Can't bytestrings containing characters of, say, koi8r encoding > be encoded? I think he means that only unicode objects can be encoded using the .encode() method, as clarified by his next sentence: >> What Python 2 is doing here is trying to be helpful: if it's already a >> bytestring then decode it first to Unicode and then re-encode it to a >> bytestring. -- 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 arnodel at googlemail.com Thu Feb 11 16:50:00 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 11 Feb 2010 21:50:00 +0000 Subject: calculating a string equation References: Message-ID: Astan Chee writes: > Hi, > I have some variables in my script that looks like this: > vars = {'var_a':'10','var_b':'4'} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > What I'm trying to do is to plug in var_a and var_b's values from vars > into eqat and see if eqat returns true or false as well as getting the > value of result if these variables were "plugged in". How do I do > this? > I'm also expecting eqat and result to contain various python > mathematical operators like **, and compounded ()'s. > I'm not sure how to convert the equation; if I have to make a bunch of > if-statements or if there is a python function that already does > something like this. Yes: eval() >>> vars = {'var_a':10 ,'var_b':4} >>> eqat = "(var_a/2.0) <= var_b" >>> result = "(var_a+var_b)/7" >>> eval(eqat, vars) False >>> eval(result, vars) 2 (Note that I have slightly modified your vars dictionary) See a recent thread about the dangers of eval(). -- Arnaud From tjreedy at udel.edu Thu Feb 11 17:11:17 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 17:11:17 -0500 Subject: Modifying Class Object In-Reply-To: References: Message-ID: On 2/11/2010 1:37 AM, Alf P. Steinbach wrote: > Consider just the > assert( t is not s ) > t = s > > Does this change anything at all in the computer's memory? By 'computer', do you mean 'anything that computes' (including humans) or specifically 'electronic computer'? > But since it does have an effect, a memory change has been effected. Agreed, in whatever 'memory' the 'computer' is using. > You describe that memory change as that t has been "bound" to the same > object as s. I prefer to use the word 'associated': namespaces are a many-to-one association between names and objects. > By which you mean that henceforth, until the next assignment to t, t > *refers* to the same object as s. T and s are both associated with the same object. > That explanation in terms of "refers" is necessary. I disagree > No beginner knows what it means that a name is "bound" to something means, until it's been > explained. I agree, which is why I am trying to avoid 'bound', etc, in favor of 'associated'. One problem of 'bind' is that it sometimes raises the question of which is bound to which. 'Associated' avoids that. > The explanation is necessarily in terms of "refers to". I have given an alternative, even if you still prefer yours. > When something A refers to something B, then by definition A is a > *reference* to B. I presume you agree that the name 'Alf P. Steinbach' refers to you. Do you then consider it to be a 'reference' to you? In either case, the Python definition uses 'refers to' in the same way that names refer to people, and did even before names were used in electro-mechanical computer programming. >Steven D'Aprano: >> My version describes what happens at the level of high-level Python >> code, which is the defined semantics of the language. It makes no >> assumptions about the implementation, completely unlike yours which is >> entirely implementation- >> specific. My description is equally valid whether Python is being >> executed by the CPython virtual machine on an Intel-compatible >> processor, or hand-simulated with pencil and paper, or something >> completely different. Yours is not. About 13 years ago, I noticed that electronically executable Python was very similar to some of the designed-for-human-reading algoritm languages (pseudocode) that were not. I then coined the oxymoron 'executable pseudocode' for Python. I see the difference between the descriptions as reflecting the difference between Python, the executable algorithm language and Python, the machine programming language. >> I describe the high-level language, you describe one implementation. >> Neither view is *wrong*, per se, but one describes the semantics of >> the language while the other describes the implementation. I think anyone writing books using Python should at least understand the abstract view even if he prefers to write from the more concrete view. Terry Jan Reedy From alfps at start.no Thu Feb 11 17:26:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 11 Feb 2010 23:26:34 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Terry Reedy: > On 2/11/2010 1:37 AM, Alf P. Steinbach wrote: > >> Consider just the >> assert( t is not s ) >> t = s >> >> Does this change anything at all in the computer's memory? > > By 'computer', do you mean 'anything that computes' (including humans) > or specifically 'electronic computer'? In this context I mean the virtual machine that a Python language assumes. Doesn't matter if it's electronic or a pen-and-pencil simulation. >> But since it does have an effect, a memory change has been effected. > > Agreed, in whatever 'memory' the 'computer' is using. > >> You describe that memory change as that t has been "bound" to the same >> object as s. > > I prefer to use the word 'associated': namespaces are a many-to-one > association between names and objects. > >> By which you mean that henceforth, until the next assignment to t, t >> *refers* to the same object as s. > > T and s are both associated with the same object. > >> That explanation in terms of "refers" is necessary. > > I disagree > >> No beginner knows what it means that a name is "bound" to something >> means, until it's been >> explained. > > I agree, which is why I am trying to avoid 'bound', etc, in favor of > 'associated'. One problem of 'bind' is that it sometimes raises the > question of which is bound to which. 'Associated' avoids that. > >> The explanation is necessarily in terms of "refers to". > > I have given an alternative, even if you still prefer yours. "Associated" is just less precise than "refers". "Associated" is two-way. Anyway it's just a term, and if you define it to mean a one-way reference, then nothing substantial is changed except more room for misunderstanding. >> When something A refers to something B, then by definition A is a >> *reference* to B. > > I presume you agree that the name 'Alf P. Steinbach' refers to you. Do > you then consider it to be a 'reference' to you? Yes, and that's irrelevant, because you can't change a name. It's a slightly different meaning. But a name edit field with my name in it most probably refers to me. > In either case, the > Python definition uses 'refers to' in the same way that names refer to > people, and did even before names were used in electro-mechanical > computer programming. That's so subtle a distinction that it appears meaningless to me. It says "refers to" but doesn't mean "refers to"? > >Steven D'Aprano: >>> My version describes what happens at the level of high-level Python >>> code, which is the defined semantics of the language. It makes no >>> assumptions about the implementation, completely unlike yours which is >>> entirely implementation- >>> specific. My description is equally valid whether Python is being >>> executed by the CPython virtual machine on an Intel-compatible >>> processor, or hand-simulated with pencil and paper, or something >>> completely different. Yours is not. > > About 13 years ago, I noticed that electronically executable Python was > very similar to some of the designed-for-human-reading algoritm > languages (pseudocode) that were not. I then coined the oxymoron > 'executable pseudocode' for Python. I see the difference between the > descriptions as reflecting the difference between Python, the executable > algorithm language and Python, the machine programming language. > > >> I describe the high-level language, you describe one implementation. > >> Neither view is *wrong*, per se, but one describes the semantics of > >> the language while the other describes the implementation. > > I think anyone writing books using Python should at least understand the > abstract view even if he prefers to write from the more concrete view. It seems to me that you lack an understanding of the abstract here, going into imagined and not concretely discussed differences between "refers to" and "refers to". Until or if (but I think it unlikely) you can explain clearly what that difference between "refers to" and "refers to" is, it's just wordplay. Cheers & hth., - Alf From steve at holdenweb.com Thu Feb 11 17:36:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 11 Feb 2010 17:36:05 -0500 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: mk wrote: > MRAB wrote: > >> When working with Unicode in Python 2, you should use the 'unicode' type >> for text (Unicode strings) and limit the 'str' type to binary data >> (bytestrings, ie bytes) only. > > Well OK, always use u'something', that's simple -- but isn't str what I > get from files and sockets and the like? > Yes, which is why you need to know what encoding was used to create it. >> In Python 3 they've been renamed to 'str' for Unicode _strings_ and >> 'bytes' for binary data (bytes!). > > Neat, except that the process of porting most projects and external > libraries to P3 seems to be, how should I put it, standing still? Or am > I wrong? But that's the impression I get? > No, it's probably not going as quickly as you would like, but it's certainly not standing still. Some of these libraries are substantial works, and there were changes to the C API that take quite a bit of work to adapt existing code to. > Take web frameworks for example. Does any of them have serious plans and > work in place to port to P3? > There have already been demonstrations of partially-working Python 3 Django. I can't speak to the rest. >> Strictly speaking, only Unicode can be encoded. > > How so? Can't bytestrings containing characters of, say, koi8r encoding > be encoded? > It's just terminology. If a bytestring contains koi8r characters then (as you unconsciously recognized by your use of the word "encoding") it already *has* been encoded. >> What Python 2 is doing here is trying to be helpful: if it's already a >> bytestring then decode it first to Unicode and then re-encode it to a >> bytestring. > > It's really cumbersome sometimes, even if two libraries are written by > one author: for instance, Mako and SQLAlchemy are written by the same > guy. They are both top-of-the line in my humble opinion, but when you > connect them you get things like this: > > 1. you query SQLAlchemy object, that happens to have string fields in > relational DB. > > 2. Corresponding Python attributes of those objects then have type str, > not unicode. > Yes, a relational database will often return ASCII, but nowadays people are increasingly using encoded Unicode. In that case you need to be aware of the encoding that has been used to render the Unicode values into the byte strings (which in Python 2 are of type str) so that you can decode them into Unicode. > 3. then I pass those objects to Mako for HTML rendering. > > Typically, it works: but if and only if a character in there does not > happen to be out of ASCII range. If it does, you get UnicodeDecodeError > on an unsuspecting user. > Well first you need to be clear what you are passing to Mako. > Sure, I wrote myself a helper that iterates over keyword dictionary to > make sure to convert all str to unicode and only then passes the > dictionary to render_unicode. It's an overhead, though. It would be > nicer to have it all unicode from db and then just pass it for rendering > and having it working. (unless there's something in filters that I > missed, but there's encoding of templates, tags, but I didn't find > anything on automatic conversion of objects passed to method rendering > template) > Some database modules will distinguish between fields of type varchar and nvarchar, returning Unicode objects for the latter. You will need to ensure that the module knows which encoding is used in the database. This is usually automatic. > But maybe I'm whining. > Nope, just struggling with a topic that is far from straightforward the first time you encounter it. > >> Unfortunately, the default encoding is ASCII, and the bytestring isn't >> valid ASCII. Python 2 is being 'helpful' in a bad way! > > And the default encoding is coded in such way so it cannot be changed in > sitecustomize (without code modification, that is). > Yes, the default encoding is not always convenient. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From hjebbers at gmail.com Thu Feb 11 17:39:45 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 14:39:45 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> On Feb 11, 8:42?pm, Jerry Hill wrote: > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > To all, > > I am running an EDI translator, and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > You need to give us more information if we're going to be able to > help. ?At the very least, you'll need to copy & paste the actual error > message. ?It would be even better if you could show us some of your > code, and better yet if you could give us a small bit of code that is > self contained and reproduces the problem you're experiencing. > > -- > Jerry the error is a windows thing, I can make a screenshot of it, but I can not copy/paste text. how do I upload a png-file? problem is that the same error happens over and over (I can reproduce it), but not at the same place (the is a logging in the application so that is quite easy to see.) but ....I can show you my code. it's an open source EDI application. but it is not a small bit of code.... I am more than will to show you how to reproduce the error. kind regards, henk-jan From hjebbers at gmail.com Thu Feb 11 17:39:51 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 14:39:51 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <10419981-eca8-44c7-a216-508431481151@h12g2000yql.googlegroups.com> On Feb 11, 8:42?pm, Jerry Hill wrote: > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > To all, > > I am running an EDI translator, and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > You need to give us more information if we're going to be able to > help. ?At the very least, you'll need to copy & paste the actual error > message. ?It would be even better if you could show us some of your > code, and better yet if you could give us a small bit of code that is > self contained and reproduces the problem you're experiencing. > > -- > Jerry the error is a windows thing, I can make a screenshot of it, but I can not copy/paste text. how do I upload a png-file? problem is that the same error happens over and over (I can reproduce it), but not at the same place (the is a logging in the application so that is quite easy to see.) but ....I can show you my code. it's an open source EDI application. but it is not a small bit of code.... I am more than will to show you how to reproduce the error. kind regards, henk-jan From tjreedy at udel.edu Thu Feb 11 17:52:05 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 17:52:05 -0500 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > Robert Kern writes: >> On 2010-02-11 06:31 AM, Shashwat Anand wrote: >>> There is a little issue here that '>>> -.1 ** .1' should give you >>> error message. That is it. >> >> No, fractional powers of negative numbers are perfectly valid >> mathematically. The result is a complex number. In Python 3 (what >> the OP is using), this has been implemented, but not in Python 2.6. > > Perhaps it should raise a MisleadingSpacingError at compile time. You forgot the smiley ;-). > The error message could recommend - .1**.1, or better -(.1 ** .1). The compiler would never see the difference between -.1 ** .1 and the first and probably no difference with the second either. From pavlovevidence at gmail.com Thu Feb 11 17:56:15 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Thu, 11 Feb 2010 14:56:15 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: <007f26f3-5310-4ed9-bb25-b467fb248825@m35g2000prh.googlegroups.com> On Feb 11, 2:39?pm, hjebbers wrote: > On Feb 11, 8:42?pm, Jerry Hill wrote: > > > > > > > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > > To all, > > > I am running an EDI translator, and doing stress tests. > > > When processing a test with a (relatively) big EDI file(s) on > > > windowsXP ?I get a crash: > > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > > causing the problem) > > > You need to give us more information if we're going to be able to > > help. ?At the very least, you'll need to copy & paste the actual error > > message. ?It would be even better if you could show us some of your > > code, and better yet if you could give us a small bit of code that is > > self contained and reproduces the problem you're experiencing. > > > -- > > Jerry > > the error is a windows thing, I can make a screenshot of it, but I can > not copy/paste text. > how do I upload a png-file? > > problem is that the same error happens over and over (I can reproduce > it), but not at the same place (the is a logging in the application so > that is quite easy to see.) > but ....I can show you my code. it's an open source EDI application. > but it is not a small bit of code.... > I am more than will to show you how to reproduce the error. People coming here ask for help will vary in the amount of detail given, but I've rarely seen anyone as reluctant as you. It's like walking into an auto repair shop and asking the mechanic what's wrong with your car by trying to imitate the noise it makes. If your code is very largre, you're not going to get out of this without doing some of your own legwork. I'm sorry. Do this: Take your code, make a copy of it. Start removing code from the copy (in a controlled way) until the problem disappears. When you remove code don't worry about whether it produces anything useful, the object is to try to identify what's causing the error. Whatever code you removed when the error disappears should give you a clue what's causing it. Then, if need be, you can come back and post details. If you manage to get the program to a small size without eliminating the problem, you can post it here. Carl Banks From tjreedy at udel.edu Thu Feb 11 17:59:50 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 17:59:50 -0500 Subject: python crash on windows but not on linux In-Reply-To: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On 2/11/2010 9:32 AM, hjebbers wrote: > To all, > I am running an EDI translator, and doing stress tests. > When processing a test with a (relatively) big EDI file(s) on > windowsXP I get a crash: > 'sorry for the inconvenience' etc (so no clues about what is > causing the problem) > > This happens with python 2.4, 2.5, 2.6 > It does not happen in the same setup&tests on linux. (while the linux > machine has only half of the RAM of the windows machine). > I am quite sure it is not some external module; there's no GUI (apart > from 'print'), no network connections. > Actually, the crash is not predictable....the crash occurs most of the > time...but at different points. > > So basically I am wondering how to proceed. > Is it related to a memory problem? (which does not occur on Linux) > > any pointer is very welcome, Are you using a 3rd-party extension (compiled-C) module? If so, I would suspect something platform specific in that. From emile at fenx.com Thu Feb 11 18:13:19 2010 From: emile at fenx.com (Emile van Sebille) Date: Thu, 11 Feb 2010 15:13:19 -0800 Subject: python crash on windows but not on linux In-Reply-To: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: On 2/11/2010 6:32 AM hjebbers said... > To all, > I am running an EDI translator, ... let's say bots :) > and doing stress tests. > When processing a test with a (relatively) big EDI file(s) on > windowsXP I get a crash: > 'sorry for the inconvenience' etc (so no clues about what is > causing the problem) ... and it's running directly under python... I use textpad. It allows me to launch a script from a command window under its control, which when python subsequently crashes, commonly leaves the traceback in the textpad launched command window. Perhaps that'll help? Emile --also on the bots list and will be digging in seriously over the next several weeks > > This happens with python 2.4, 2.5, 2.6 > It does not happen in the same setup&tests on linux. (while the linux > machine has only half of the RAM of the windows machine). > I am quite sure it is not some external module; there's no GUI (apart > from 'print'), no network connections. > Actually, the crash is not predictable....the crash occurs most of the > time...but at different points. > > So basically I am wondering how to proceed. > Is it related to a memory problem? (which does not occur on Linux) > > any pointer is very welcome, > > henk-jan From tjreedy at udel.edu Thu Feb 11 18:20:16 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 18:20:16 -0500 Subject: python and http POST In-Reply-To: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: On 2/11/2010 2:11 PM, galileo228 wrote: > Hey All, > > Been teaching myself Python for a few weeks, and am trying to write a > program that will go to a url, enter a string in one of the search > fields, submit the search, and return the contents of the search > result. > > I'm using httplib2. > > My two particular questions: > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > how do I know what the particular key should be? In other words, how > do I tell python which form on the web page I'm visiting I'd like to > fill in? Do I simply go to the webpage itself and look at the html > source? But if that's the case, which tag tells me the name of the > key? > > 2) Even once python fills in the form properly, how can I tell it to > 'submit' the search? This http://groups.csail.mit.edu/uid/sikuli/ *might* help you. From peter.milliken at gmail.com Thu Feb 11 18:26:58 2010 From: peter.milliken at gmail.com (Peter) Date: Thu, 11 Feb 2010 15:26:58 -0800 (PST) Subject: Is a merge interval function available? References: Message-ID: <14520376-06ca-4cc9-a6b0-52b00a95700e@g28g2000prb.googlegroups.com> On Feb 12, 8:03?am, Jonathan Gardner wrote: > On Feb 10, 3:23?pm, Peng Yu wrote: > > > > > > > I'm wondering there is already a function in python library that can > > merge intervals. For example, if I have the following intervals ('[' > > and ']' means closed interval as inhttp://en.wikipedia.org/wiki/Interval_(mathematics)#Excluding_the_end...) > > > [1, 3] > > [2, 9] > > [10,13] > > [11,12] > > > I want to get the following merged intervals. > > > [1,9] > > [10,13] > > > Could somebody let me know if there is a function in the python > > library? > > I vaguely recall a similar question a long time ago. Peng, is this a > homework assignment? > > Perhaps we should add a standard module called "homework". It can have > functions for all the different homework assignments we see on > c.l.python. We can simply point people to this module and then can > include the code in their answers. Good idea - that would (also) give the teachers a convenient place to check for what assignments have been solved by this list so they can propose something else. They can also grade the submissions against the code kept in this area - exact copies could receive an "F" (for example :-)) Peter From rhodri at wildebst.demon.co.uk Thu Feb 11 18:32:08 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 11 Feb 2010 23:32:08 -0000 Subject: MODULE FOR I, P FRAME References: Message-ID: On Thu, 11 Feb 2010 19:31:52 -0000, DANNY wrote: > Hello! > > I am currently developing a simple video player in python, and my > problem is that i can't find a module which has a function that can > determine if frame(image) is I or P coded (MPEG coding). I have been > using PIL but I couldnt find anything that could help me with that > problem. How are you reading the video? PIL doesn't claim to do more than identify MPEG files. Also, which MPEG encoding, in which container format? If you aren't just putting a wrapper around something like ffmpeg, I rather suspect you'll have to decode the bitstream yourself. That could be rather painful if you're talking about MPEG-4/10. -- Rhodri James *-* Wildebeeste Herder to the Masses From tjreedy at udel.edu Thu Feb 11 18:34:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Feb 2010 18:34:14 -0500 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <4B744275.4000503@mrabarnett.plus.com> Message-ID: On 2/11/2010 4:43 PM, mk wrote: > Neat, except that the process of porting most projects and external > libraries to P3 seems to be, how should I put it, standing still? What is important are the libraries, so more new projects can start in 3.x. There is a slow trickly of 3.x support announcements. > But maybe I'm whining. Or perhaps explaining why 3.x unicode improvements are needed. tjr From gagsl-py2 at yahoo.com.ar Thu Feb 11 18:36:40 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Thu, 11 Feb 2010 20:36:40 -0300 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy escribi?: > On 2/10/2010 4:49 PM, Gabriel Genellina wrote: > >> I've written a decorator for "injecting" a __function__ name into the >> function namespace, but I can't find it anywhere. I think I implemented >> it by adding a fake additional argument and replacing LOAD_GLOBAL with >> LOAD_NAME in the bytecode. > > The decorator only needs to replace the defaults args tuple. > It does not even need to know the parameter name, > just that it is the only (or last) with a default . > > def f(n, me=None): > if n > 0: return n*me(n-1) > elif n==0: return 1 > > f.__defaults__ = (f,) # 3.1 > print(f(5)) This is simple to implement, but requires changing the function definition. My goal was to keep the original code unchanged, that is, leave it as: def f(n): if n > 0: return n*f(n-1) elif n==0: return 1 (like a normal, recursive function), and make the 'f' inside the function body "magically" refer to the function itself. > Of course, user could still screw up recursion by providing another > value for 'me'. This strikes me as about a likely (low) as a user > screwing up recursion in a library module function by rebinding the name > in the imported module. Well, if people really want to shoot themselves in the foot, there's nothing we can do to avoid that... -- Gabriel Genellina From jlconlin at gmail.com Thu Feb 11 18:39:09 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 11 Feb 2010 15:39:09 -0800 (PST) Subject: Please help with MemoryError Message-ID: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> I have been using Python for several years now and have never run into memory errors? until now. My Python program now consumes over 2 GB of memory and then I get a MemoryError. I know I am reading lots of files into memory, but not 2GB worth. I thought I didn't have to worry about memory allocation in Python because of the garbage collector. On this note I have a few questions. FYI I am using Python 2.6.4 on my Mac. 1. When I pass a variable to the constructor of a class does it copy that variable or is it just a reference/pointer? I was under the impression that it was just a pointer to the data. 2. When do I need to manually allocate/deallocate memory and when can I trust Python to take care of it? 3. Any good practice suggestions? Thanks, Jeremy From martin.hellwig at dcuktec.org Thu Feb 11 18:46:27 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 11 Feb 2010 23:46:27 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: Well at least you are well written and more subtle than Xah Lee. Though I find him also quite amusing, I do like a good flame-war every now and again, and in that perspective I solute you. -- mph From apt.shansen at gmail.com Thu Feb 11 18:56:50 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 11 Feb 2010 15:56:50 -0800 Subject: Please help with MemoryError In-Reply-To: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <7a9c25c21002111556x4cc04c23u2586a952fd1c8b91@mail.gmail.com> On Thu, Feb 11, 2010 at 3:39 PM, Jeremy wrote: > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. I know I am reading lots of files into memory, but not > 2GB worth. I thought I didn't have to worry about memory allocation > in Python because of the garbage collector. On this note I have a few > questions. FYI I am using Python 2.6.4 on my Mac. > Is this pure-python, or are you using extension modules? Its possible a C extension has a memory leak. Its also possible you're keeping references to objects far longer then you need. > 1. When I pass a variable to the constructor of a class does it > copy that variable or is it just a reference/pointer? I was under the > impression that it was just a pointer to the data. > The question doesn't precisely make sense in terms of Python, but I think I see what you're getting at. Python doesn't implicitly copy anything: you have to explicitly copy an object to end up with two of them. That said, it sort of depends on what you're doing. When you pass objects into a class, if that class stores a reference to those objects, they'll live as long as the class does. More details would require you showing some examples of what you're doing. > 2. When do I need to manually allocate/deallocate memory and when > can I trust Python to take care of it? > Generally, you can "trust" Python-- and you can't manually allocate/deallocate even if you wanted to. If you're suffering a memory leak, it almost certainly comes from one of two places: 1. Your code is keeping references somewhere to objects that you don't need anymore, or 2. Some C extension you are using has some ref-counting bugs. Once upon a time, reference cycles would also cause memory leaks, but the cyclic GC breaks them now. > 3. Any good practice suggestions? > Look over your code: look at places where you bind objects to any names that aren't local. Look for lists or dictionaries that you're putting stuff into without really meaning to keep it forever, and maybe you aren't purging. Global vars are worth a close look too. This may be useful: http://www.lshift.net/blog/2008/11/14/tracing-python-memory-leaks --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 11 19:03:43 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 01:03:43 +0100 Subject: Please help with MemoryError In-Reply-To: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: * Jeremy: > I have been using Python for several years now and have never run into > memory errors? > > until now. > > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. I know I am reading lots of files into memory, but not > 2GB worth. I thought I didn't have to worry about memory allocation > in Python because of the garbage collector. On this note I have a few > questions. FYI I am using Python 2.6.4 on my Mac. > > 1. When I pass a variable to the constructor of a class does it > copy that variable or is it just a reference/pointer? I was under the > impression that it was just a pointer to the data. Uhm, I discovered that "pointer" is apparently a Loaded Word in the Python community. At least in some sub-community, so, best avoided. But essentially you're just passing a reference to an object. The object is not copied. > 2. When do I need to manually allocate/deallocate memory and when > can I trust Python to take care of it? Python takes care of deallocation of objects that are /no longer referenced/. > 3. Any good practice suggestions? You need to get rid of references to objects before Python will garbage collect them. Typically, in a language like Python (or Java, C#...) memory leaks are caused by keeping object references in singletons or globals, e.g. for purposes of event notifications. For example, you may have some dictionary somewhere. Such references from singletons/globals need to be removed. You do not, however, need to be concerned about circular references, at least unless you need some immediate deallocation. For although circular references will prevent the objects involved from being immediately deallocated, the general garbage collector will take care of them later. Cheers & hth., - Alf From sridharr at activestate.com Thu Feb 11 19:22:49 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Thu, 11 Feb 2010 16:22:49 -0800 Subject: ANN: ActivePython 2.5.5.7 is now available Message-ID: <1E441CA2-F197-4F5B-B4F5-A5FE2E3D7882@activestate.com> I'm happy to announce that ActivePython 2.5.5.7 is now available for download from: http://www.activestate.com/activepython/ This is a minor release with several updates and fixes. Changes in 2.5.5.7 ------------------ - Upgrade to Python 2.5.5 - Upgrade to Tcl/Tk 8.5.8 - Upgrade to PyWin32 CVS (2009-11-10) - Security upgrade to openssl-0.9.8l - [Windows] Include Tcl/Tk header files - [Windows] Allow side-by-side installation of 32-bit and 64-bit builds - [Mac] Fix the MacOSX build to use Tcl/Tk 8.5.x See the release notes for full details: http://docs.activestate.com/activepython/2.5/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. Builds for Solaris, HP-UX and AIX, and access to older versions are available with ActivePython Business Edition: http://www.activestate.com/business_edition/ 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. Beginning with the 2.6.3.7 release, ActivePython includes a binary package manager for Python (PyPM) that can be used to install packages much easily. For example: pypm install pylons See this page for full details: http://docs.activestate.com/activepython/2.5/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.5/ We would welcome any and all feedback to: ActivePython-feedback at activestate.com Please file bugs against ActivePython at: http://bugs.activestate.com/query.cgi?set_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 Edition only) - Solaris/x86 (Business Edition only) - HP-UX/PA-RISC (Business Edition only) - AIX/PowerPC (Business Edition only) - AIX/PowerPC 64-bit (Business Edition only) Custom builds are available in Enterprise Edition: http://www.activestate.com/activepython/enterprise/ Thanks, and enjoy! The Python Team -- Sridhar Ratnakumar sridharr at activestate.com From jgardner at jonathangardner.net Thu Feb 11 19:36:45 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 11 Feb 2010 16:36:45 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: On Feb 11, 3:39?pm, Jeremy wrote: > I have been using Python for several years now and have never run into > memory errors? > > until now. > Yes, Python does a good job of making memory errors the least of your worries as a programmer. Maybe it's doing too good of a job... > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. ?I know I am reading lots of files into memory, but not > 2GB worth. Do a quick calculation: How much are leaving around after you read in a file? Do you create an object for each line? What does that object have associated with it? You may find that you have some strange O(N^2) behavior regarding memory here. Oftentimes people forget that you have to evaluate how your algorithm will run in time *and* memory. >?I thought I didn't have to worry about memory allocation > in Python because of the garbage collector. While it's not the #1 concern, you still have to keep track of how you are using memory and try not to be wasteful. Use good algorithms, let things fall out of scope, etc... > 1. ? ?When I pass a variable to the constructor of a class does it > copy that variable or is it just a reference/pointer? ?I was under the > impression that it was just a pointer to the data. For objects, until you make a copy, there is no copy made. That's the general rule and even though it isn't always correct, it is correct enough. > 2. ? ?When do I need to manually allocate/deallocate memory and when > can I trust Python to take care of it? Let things fall out of scope. If you're concerned, use delete. Try to avoid using the global namespace for everything, and try to keep your lists and dicts small. > 3. ? ?Any good practice suggestions? > Don't read in the entire file and then process it. Try to do line-by- line processing. Figure out what your algorithm is doing in terms of time *and* memory. You likely have some O(N^2) or worse in memory usage. Don't use Python variables to store data long-term. Instead, setup a database or a file and use that. I'd first look at using a file, then using SQLite, and then a full-fledged database like PostgreSQL. Don't write processes that sit around for a long time unless you also evaluate whether that process grows in size as it runs. If it does, you need to figure out why and stop that memory leak. Simpler code uses less memory. Not just because it is smaller, but because you are not copying and moving data all over the place. See what you can do to simplify your code. Maybe you'll expose the nasty O(N^2) behavior. From hjebbers at gmail.com Thu Feb 11 20:09:13 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:09:13 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <6dd5bb28-9d70-4bef-999b-a4ae7b45847a@l26g2000yqd.googlegroups.com> On Feb 11, 11:59?pm, Terry Reedy wrote: > On 2/11/2010 9:32 AM, hjebbers wrote: > > > > > To all, > > I am running an EDI translator, and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > Are you using a 3rd-party extension (compiled-C) module? If so, I would > suspect something platform specific in that. That was my first thought. Sop I tried to eliminate that. well, there is a connection to a database. but I tested this with connections to SQLite, MySQL, PostGreSQL, and the crash keeps coming. So I think it is not a 3rd party module.... And all else is is pure python. kind regards, Henk-Jan From steve at REMOVE-THIS-cybersource.com.au Thu Feb 11 20:09:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 01:09:30 GMT Subject: Modifying Class Object References: Message-ID: <03849660$0$1277$c3e8da3@news.astraweb.com> On Thu, 11 Feb 2010 17:11:17 -0500, Terry Reedy wrote: > About 13 years ago, I noticed that electronically executable Python was > very similar to some of the designed-for-human-reading algoritm > languages (pseudocode) that were not. I then coined the oxymoron > 'executable pseudocode' for Python. That was yours? Nice one! -- Steve From hjebbers at gmail.com Thu Feb 11 20:14:03 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:14:03 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <481d2511-0bf1-4012-be1b-f1af54af5ada@g28g2000yqh.googlegroups.com> On Feb 12, 12:13?am, Emile van Sebille wrote: > On 2/11/2010 6:32 AM hjebbers said... > > > To all, > > I am running an EDI translator, > > ... let's say bots ?:) > > > and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > ... and it's running directly under python... > > I use textpad. ?It allows me to launch a script from a command window > under its control, which when python subsequently crashes, commonly > leaves the traceback in the textpad launched command window. > > Perhaps that'll help? > > Emile > --also on the bots list and will be digging in seriously over the next > several weeks > > > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > > henk-jan > > Hi Emile, yes, we are talking bots. I run the bots engine from the commandline. But... there is no python traceback. Python crashed 'hard'. or have you something else in mind? kind regards,henk-jan From steve at REMOVE-THIS-cybersource.com.au Thu Feb 11 20:14:04 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 01:14:04 GMT Subject: Modifying Class Object References: Message-ID: <03849771$0$1277$c3e8da3@news.astraweb.com> On Thu, 11 Feb 2010 23:26:34 +0100, Alf P. Steinbach wrote: >> I presume you agree that the name 'Alf P. Steinbach' refers to you. Do >> you then consider it to be a 'reference' to you? > > Yes, and that's irrelevant, because you can't change a name. Pardon me, but you most certainly can. Even Germany, which doesn't allow people to change their legal name for frivolous reasons, makes exceptions and will allow people to change their name if (e.g.) they have a sex change, or if they are burdened with a name that causes them ridicule, and presumably for their equivalent of the witness relocation program. And even Germany doesn't presume to tell people what name they are known by to their friends and family. In Python, one can't change names *in place*, because strings are immutable. (Although I have seen a hack with ctypes which allows you to modify string objects. It makes a nice trick, but is completely useless because of the side-effects.) Even if you could modify the name, that would break the namespace it was stored in. But of course you can change names in two steps: x = something() y = x del x And lo, we have changed the name x to y. -- Steven From alfps at start.no Thu Feb 11 20:17:46 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 02:17:46 +0100 Subject: Modifying Class Object In-Reply-To: <03849771$0$1277$c3e8da3@news.astraweb.com> References: <03849771$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Thu, 11 Feb 2010 23:26:34 +0100, Alf P. Steinbach wrote: > >>> I presume you agree that the name 'Alf P. Steinbach' refers to you. Do >>> you then consider it to be a 'reference' to you? >> Yes, and that's irrelevant, because you can't change a name. > > Pardon me, but you most certainly can. Even Germany, which doesn't allow > people to change their legal name for frivolous reasons, makes exceptions > and will allow people to change their name if (e.g.) they have a sex > change, or if they are burdened with a name that causes them ridicule, > and presumably for their equivalent of the witness relocation program. > And even Germany doesn't presume to tell people what name they are known > by to their friends and family. > > In Python, one can't change names *in place*, because strings are > immutable. (Although I have seen a hack with ctypes which allows you to > modify string objects. It makes a nice trick, but is completely useless > because of the side-effects.) Even if you could modify the name, that > would break the namespace it was stored in. But of course you can change > names in two steps: > > x = something() > y = x > del x > > And lo, we have changed the name x to y. Good joke. :-) Cheers, - Alf From nobody at nowhere.com Thu Feb 11 20:27:28 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 12 Feb 2010 01:27:28 +0000 Subject: Need debugging knowhow for my creeping Unicodephobia References: <923ca72c-7b21-4abe-920f-b0b148df8ec7@t42g2000vbt.googlegroups.com> Message-ID: On Wed, 10 Feb 2010 12:17:51 -0800, Anthony Tolle wrote: > 4. Consider switching to Python 3.x, since there is only one string > type (unicode). However: one drawback of Python 3.x is that the repr() of a Unicode string is no longer restricted to ASCII. There is an ascii() function which behaves like the 2.x repr(). However: the interpreter uses repr() for displaying the value of an expression typed at the interactive prompt, which results in "can't encode" errors if the string cannot be converted to your locale's encoding. From twistedphrame at gmail.com Thu Feb 11 20:27:58 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Thu, 11 Feb 2010 17:27:58 -0800 (PST) Subject: Pycrypto RSA ciphertext to string back to ciphertext issue Message-ID: <4b65abb5-072f-4e3c-91eb-95eea6c8a6a9@b10g2000vbh.googlegroups.com> Hey all, I'm trying to convert the encrypted data from RSA to a string for sending over xmlrpc and then back to usable data. Whenever I decrypt I just get junk data. Has anyone else tried doing this? Here's some example code: from Crypto.PublicKey import RSA from Crypto import Random key = RSA.generate(384, Random.new().read) l = str(key.encrypt("dog","")) l = stringToTuple(l) l = key.decrypt(tuple(l)) print l string to tuple: def stringToTuple(string): if string[0] + string[-1] == "()": items = string[1:-1] items = items.split(',') return items else: raise ValueError("Badly formatted string (missing brackets).") thanks for any help, I've been messing with this for days and have come up dry. From hjebbers at gmail.com Thu Feb 11 20:30:39 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:30:39 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <0cf3d611-dc7f-4d77-b9e5-59762c022f20@g27g2000yqh.googlegroups.com> On Feb 12, 12:13?am, Emile van Sebille wrote: > On 2/11/2010 6:32 AM hjebbers said... > > > To all, > > I am running an EDI translator, > > ... let's say bots ?:) > > > and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > ... and it's running directly under python... > > I use textpad. ?It allows me to launch a script from a command window > under its control, which when python subsequently crashes, commonly > leaves the traceback in the textpad launched command window. > > Perhaps that'll help? > > Emile > --also on the bots list and will be digging in seriously over the next > several weeks > > > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > > henk-jan > > From hjebbers at gmail.com Thu Feb 11 20:32:00 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:32:00 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <626c4c0f-c02c-44f7-9032-5ea2c11e58a8@h2g2000yqj.googlegroups.com> On Feb 12, 12:13?am, Emile van Sebille wrote: > On 2/11/2010 6:32 AM hjebbers said... > > > To all, > > I am running an EDI translator, > > ... let's say bots ?:) > > > and doing stress tests. > > When processing a test with a (relatively) big EDI file(s) on > > windowsXP ?I get a crash: > > ? ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > causing the problem) > > ... and it's running directly under python... > > I use textpad. ?It allows me to launch a script from a command window > under its control, which when python subsequently crashes, commonly > leaves the traceback in the textpad launched command window. > > Perhaps that'll help? > > Emile > --also on the bots list and will be digging in seriously over the next > several weeks > > > > > This happens with python 2.4, 2.5, 2.6 > > It does not happen in the same setup&tests on linux. (while the linux > > machine has only half of the RAM of the windows machine). > > I am quite sure it is not some external module; there's no GUI (apart > > from 'print'), no network connections. > > Actually, the crash is not predictable....the crash occurs most of the > > time...but at different points. > > > So basically I am wondering how to proceed. > > Is it related to a memory problem? (which does not occur on Linux) > > > any pointer is very welcome, > > > henk-jan > > From hjebbers at gmail.com Thu Feb 11 20:33:14 2010 From: hjebbers at gmail.com (hjebbers) Date: Thu, 11 Feb 2010 17:33:14 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <007f26f3-5310-4ed9-bb25-b467fb248825@m35g2000prh.googlegroups.com> Message-ID: <221e80b8-fd1b-4585-bbd6-9ccb14eedb08@k41g2000yqm.googlegroups.com> On Feb 11, 11:56?pm, Carl Banks wrote: > On Feb 11, 2:39?pm, hjebbers wrote: > > > > > On Feb 11, 8:42?pm, Jerry Hill wrote: > > > > On Thu, Feb 11, 2010 at 9:32 AM, hjebbers wrote: > > > > To all, > > > > I am running an EDI translator, and doing stress tests. > > > > When processing a test with a (relatively) big EDI file(s) on > > > > windowsXP ?I get a crash: > > > > ? ?'sorry for the inconvenience' etc ?(so no clues about what is > > > > causing the problem) > > > > You need to give us more information if we're going to be able to > > > help. ?At the very least, you'll need to copy & paste the actual error > > > message. ?It would be even better if you could show us some of your > > > code, and better yet if you could give us a small bit of code that is > > > self contained and reproduces the problem you're experiencing. > > > > -- > > > Jerry > > > the error is a windows thing, I can make a screenshot of it, but I can > > not copy/paste text. > > how do I upload a png-file? > > > problem is that the same error happens over and over (I can reproduce > > it), but not at the same place (the is a logging in the application so > > that is quite easy to see.) > > but ....I can show you my code. it's an open source EDI application. > > but it is not a small bit of code.... > > I am more than will to show you how to reproduce the error. > > People coming here ask for help will vary in the amount of detail > given, but I've rarely seen anyone as reluctant as you. ?It's like > walking into an auto repair shop and asking the mechanic what's wrong > with your car by trying to imitate the noise it makes. > I am reluctant because it is a lot of code ....as I told you, it occurs during stress tests. I am more than willing to show how to reproduce the crash. > If your code is very largre, you're not going to get out of this > without doing some of your own legwork. ?I'm sorry. I am more than willing to do this, of course. > > Do this: Take your code, make a copy of it. ?Start removing code from > the copy (in a controlled way) until the problem disappears. ?When you > remove code don't worry about whether it produces anything useful, the > object is to try to identify what's causing the error. ?Whatever code > you removed when the error disappears should give you a clue what's > causing it. ?Then, if need be, you can come back and post details. ?If > you manage to get the program to a small size without eliminating the > problem, you can post it here. OK, I know how to trace a bug. As I said, these are stress tests, in this case the input files are MUCH larger than usualy. Other stress tests run thousands of input file of regular to big size..... This all runs. It does run OK on Linux (so am I looking for a bug in my program??). The crash pops up at different places...this makes the procedure you suggest quite awkward. It is a hard crash of python. There is no traceback or something: Python dies. Python is no more. It's stone dead. It has ceased to be. It's a stiff. It's kicked the bucket etc kind regards, henk-jan From nobody at nowhere.com Thu Feb 11 20:37:59 2010 From: nobody at nowhere.com (Nobody) Date: Fri, 12 Feb 2010 01:37:59 +0000 Subject: Is a merge interval function available? References: Message-ID: On Wed, 10 Feb 2010 23:03:29 -0500, Steve Holden wrote: >> intervals = sorted(intervals, key = lambda x: x[0]) > > Since Python uses lexical sorting and the intervals are lists isn't the > key specification redundant here? Yes, but I wanted to make it explicit. Well, omitting the key= would change the sorting order in the event that multiple intervals have the same start, but it still won't affect the result of the function overall. From steve at REMOVE-THIS-cybersource.com.au Thu Feb 11 20:50:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 01:50:26 GMT Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <03849ff7$0$1277$c3e8da3@news.astraweb.com> On Thu, 11 Feb 2010 15:39:09 -0800, Jeremy wrote: > My Python program now consumes over 2 GB of memory and then I get a > MemoryError. I know I am reading lots of files into memory, but not 2GB > worth. Are you sure? Keep in mind that Python has a comparatively high overhead due to its object-oriented nature. If you have a list of characters: ['a', 'b', 'c', 'd'] there is the (small) overhead of the list structure itself, but each individual character is not a single byte, but a relatively large object: >>> sys.getsizeof('a') 32 So if you read (say) a 500MB file into a single giant string, you will have 500MB plus the overhead of a single string object (which is negligible). But if you read it into a list of 500 million single characters, you will have the overhead of a single list, plus 500 million strings, and that's *not* negligible: 32 bytes each instead of 1. So try to avoid breaking a single huge strings into vast numbers of tiny strings all at once. > I thought I didn't have to worry about memory allocation in > Python because of the garbage collector. You don't have to worry about explicitly allocating memory, and you almost never have to worry about explicitly freeing memory (unless you are making objects that, directly or indirectly, contain themselves -- see below); but unless you have an infinite amount of RAM available of course you can run out of memory if you use it all up :) > On this note I have a few > questions. FYI I am using Python 2.6.4 on my Mac. > > 1. When I pass a variable to the constructor of a class does it copy > that variable or is it just a reference/pointer? I was under the > impression that it was just a pointer to the data. Python's calling model is the same whether you pass to a class constructor or any other function or method: x = ["some", "data"] obj = f(x) The function f (which might be a class constructor) sees the exact same list as you assigned to x -- the list is not copied first. However, there's no promise made about what f does with that list -- it might copy the list, or make one or more additional lists: def f(a_list): another_copy = a_list[:] another_list = map(int, a_list) > 2. When do I need > to manually allocate/deallocate memory and when can I trust Python to > take care of it? You never need to manually allocate memory. You *may* need to deallocate memory if you make "reference loops", where one object refers to itself: l = [] # make an empty list l.append(l) # add the list l to itself Python can break such simple reference loops itself, but for more complicated ones, you may need to break them yourself: a = [] b = {2: a} c = (None, b) d = [1, 'z', c] a.append(d) # a reference loop Python will deallocate objects when they are no longer in use. They are always considered in use any time you have them assigned to a name, or in a list or dict or other structure which is in use. You can explicitly remove a name with the del command. For example: x = ['my', 'data'] del x After deleting the name x, the list object itself is no longer in use anywhere and Python will deallocate it. But consider: x = ['my', 'data'] y = x # y now refers to THE SAME list object del x Although you have deleted the name x, the list object is still bound to the name y, and so Python will *not* deallocate the list. Likewise: x = ['my', 'data'] y = [None, 1, x, 'hello world'] del x Although now the list isn't bound to a name, it is inside another list, and so Python will not deallocate it. > 3. Any good practice suggestions? Write small functions. Any temporary objects created by the function will be automatically deallocated when the function returns. Avoid global variables. They are a good way to inadvertently end up with multiple long-lasting copies of data. Try to keep data in one big piece rather than lots of little pieces. But contradicting the above, if the one big piece is too big, it will be hard for the operating system to swap it in and out of virtual memory, causing thrashing, which is *really* slow. So aim for big, but not huge. (By "big" I mean megabyte-sized; by "huge" I mean hundreds of megabytes.) If possible, avoid reading the entire file in at once, and instead process it line-by-line. Hope this helps, -- Steven From python at mrabarnett.plus.com Thu Feb 11 20:52:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 01:52:47 +0000 Subject: Pycrypto RSA ciphertext to string back to ciphertext issue In-Reply-To: <4b65abb5-072f-4e3c-91eb-95eea6c8a6a9@b10g2000vbh.googlegroups.com> References: <4b65abb5-072f-4e3c-91eb-95eea6c8a6a9@b10g2000vbh.googlegroups.com> Message-ID: <4B74B46F.9070603@mrabarnett.plus.com> Jordan Apgar wrote: > Hey all, > I'm trying to convert the encrypted data from RSA to a string for > sending over xmlrpc and then back to usable data. Whenever I decrypt > I just get junk data. Has anyone else tried doing this? Here's some > example code: > > from Crypto.PublicKey import RSA > from Crypto import Random > > key = RSA.generate(384, Random.new().read) > l = str(key.encrypt("dog","")) > l = stringToTuple(l) > l = key.decrypt(tuple(l)) > print l > > string to tuple: > def stringToTuple(string): > if string[0] + string[-1] == "()": > items = string[1:-1] > items = items.split(',') > return items > else: > raise ValueError("Badly formatted string (missing brackets).") > > thanks for any help, I've been messing with this for days and have > come up dry. I don't know what you're trying to do with converting tuples to bytestrings and back, but this works: >>> key = RSA.generate(384, Random.new().read) >>> encrypted = key.encrypt("dog", "")[0] >>> encrypted "NB\xe9\xcf\x88\xf8b.\x81X{\x12\xeaH\x03\xe9\xc4\xd6\xdb\x00lS\r\xc9in|\xa5\xb1' $\x90_\xc5t$\xd0\xc40-p\x8b\xd0\x95\xdb\xa6\xf7\xc2" >>> key.decrypt(encrypted) 'dog' From python.list at tim.thechases.com Thu Feb 11 21:36:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 11 Feb 2010 20:36:57 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <4B74BEC9.40805@tim.thechases.com> Jonathan Gardner wrote: > Don't use Python variables to store data long-term. Instead, setup a > database or a file and use that. I'd first look at using a file, then > using SQLite, and then a full-fledged database like PostgreSQL. Just to add to the mix, I'd put the "anydbm" module on the gradient between "using a file" and "using sqlite". It's a nice intermediate step between rolling your own file formats for data on disk, and having to write SQL since access is entirely like you'd do with a regular Python dictionary. -tkc From aahz at pythoncraft.com Thu Feb 11 21:38:46 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 18:38:46 -0800 Subject: timer for a function References: Message-ID: In article , mk wrote: > >self.conobj = paramiko.SSHClient() > >self.conobj.connect(self.ip, username=self.username, >key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout) > >2. very slow SSH host that is hanging for 30+ seconds on key exchange. > >The timeout in the options regards only a socket timeout, not further >stages of connection negotiation, so it doesn't work there. Does paramiko offer any kind of callback? In a similar situation with pycurl, I built my own timer into a callback. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Thu Feb 11 21:41:27 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 18:41:27 -0800 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: In article <34fcf680-1aa4-4835-9eba-3db3249f36b2 at q16g2000yqq.googlegroups.com>, hjebbers wrote: > >the error is a windows thing, I can make a screenshot of it, but I can >not copy/paste text. In that case, you need to -- very carefully -- make sure you transcribe exactly the message that you see on the screen. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Thu Feb 11 21:44:28 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 18:44:28 -0800 Subject: Bizarre arithmetic results References: Message-ID: In article , Grant Edwards wrote: > >Didn't we just do this one last week? Let's do the Time Warp again! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From alfps at start.no Thu Feb 11 21:47:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 03:47:34 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Martin P. Hellwig: > > Well at least you are well written and more subtle than Xah Lee. > Though I find him also quite amusing, I do like a good flame-war every > now and again, and in that perspective I solute you. The technical discussion is now at point where one poster maintains that references don't exist in Python, and another poster, in support, maintains that "refers to" in the language spec doesn't mean "refers to" but instead means "refers to", whatever's that meant to mean. As a technical discussion it's meaningless drivel. And as an argument in that technical discussion your allegation of trolling is just yet another fallacy, and meaningless. But in a social context, declaring support or placing oneself within a group, or for that matter "Poisoning the well", it can make sense. This group has an extraordinary high level of flaming and personal attacks, and it's the only group I've seen where there are threads (I think I've seen 3, within the last two months, not participating in them) with the regulars reitererating how "friendly" the group is, how difficult it is to get flamed here. In other groups it's not necessary for the regulars to point out how friendly the group is. But then, in other groups personal attacks are rare. And so when you mention Xah Lee I'm now wondering what is cause, and what is effect. I was informed that he'd done extensive cross-posting, and his own web site seems to confirm that his ISP at one time reacted to a complaint about such cross-posting. I've also seen directly that he has employed pretty foul language in characterizing Python in an article, and even without that language negative loaded characterizations without any evidence to back them up (like, for example, yours above) must be considered intentional flame bait. But did it start that way for Xah Lee? I'm not going to check the archives. It's enough, wrt. the point I'm making about some regulars of the group, that even with such evidence of active trolling at hand -- ISP reaction to cross-posting, needless foul language, unsubstantiated characterizations -- based on my experience here I think it's just as likely that it started out by Xah Lee being flamed, perhaps repeatedly, with personal attacks and by group action. Or perhaps it didn't, but at this point it would not surprise me in the slightest. Cheers & hth., - Alf From no.email at nospam.invalid Thu Feb 11 22:41:21 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 11 Feb 2010 19:41:21 -0800 Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> Message-ID: <7xy6iz86ji.fsf@ruckus.brouhaha.com> Mark Lawrence writes: >> The predecessor of the Enigma was cracked by Polish scientists years >> before WW2 started.... > I believe that all of Enigma was eventually cracked cos of two major > flaws. I think it never would have been cracked if it hadn't been cracked (whether by the Brits or the Poles) before the war started, using commercial versions of the Enigma that they had access to. The military Enigma and its operating methods got more sophisticated as the war went on, and the cryptanalysts were able to keep up with it by incrementally improving techniques that they were already using at scale. If they were suddenly confronted with the full-blown military system in the middle of the war, it would have been a lot harder to do anything about it. At least, most of the Enigma-related books I've read give that impression and even come out and say such things. > Further, the far more powerful Geheimscreiber was also cracked at > Bletchley by using Colossus. Sorry some years since I read the book > about this so can't remember the title or author. See http://en.wikipedia.org/wiki/Colossus_computer That was almost at the end of the war though. From aahz at pythoncraft.com Thu Feb 11 23:58:02 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 20:58:02 -0800 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: In article , Tim Chase wrote: > >Just to add to the mix, I'd put the "anydbm" module on the gradient >between "using a file" and "using sqlite". It's a nice intermediate >step between rolling your own file formats for data on disk, and having >to write SQL since access is entirely like you'd do with a regular >Python dictionary. Not quite. One critical difference between dbm and dicts is the need to remember to "save" changes by setting the key's valud again. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 00:16:59 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 21:16:59 -0800 Subject: execute sqlite3 dot commands in python References: <8e7295c71002051442u3ccaab0bobaa994d8dc05b07c@mail.gmail.com> Message-ID: In article , Steve Holden wrote: > >No. That's not how you pass commands to sqlite3 - you connect to a >database, create a cursor on the connection, and then execute SQL >statements (not sqlite commands) on the cursor. Like this: > >>>> import sqlite3 >>>> c = sqlite3.connect("deleteme") >>>> cu = c.cursor() >>>> cu.execute(".help") >Traceback (most recent call last): > File "", line 1, in >sqlite3.OperationalError: near ".": syntax error >>>> cu.execute("""\ >... CREATE TABLE test( >... a int primary key, >... b varchar)""") > >>>> > >As you can see, the cursor's execute() method expects SQL statements. However, it may not be obvious that some things that don't look like SQL are. For example, "pragma integrity_check". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 00:18:26 2010 From: aahz at pythoncraft.com (Aahz) Date: 11 Feb 2010 21:18:26 -0800 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> <4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: In article , Gabriel Genellina wrote: > >Strange. With Python 2.6.4 I don't need to do that; I'd say the difference >is in the OS or antivirus (some AV are known to break the TCP stack). Perhaps, but I've also found that ctrl-C doesn't work on Windows. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From tjreedy at udel.edu Fri Feb 12 00:31:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Feb 2010 00:31:14 -0500 Subject: Function attributes In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: On 2/11/2010 6:36 PM, Gabriel Genellina wrote: > This is simple to implement, but requires changing the function > definition. My goal was to keep the original code unchanged, that is, > leave it as: > > def f(n): > if n > 0: return n*f(n-1) > elif n==0: return 1 > > (like a normal, recursive function), and make the 'f' inside the function > body "magically" refer to the function itself. Someone did this several years ago with a bytecode hack. I believe it was in the cookbook. It was rejected as part of standard CPython. From tjreedy at udel.edu Fri Feb 12 00:48:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Feb 2010 00:48:30 -0500 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: On 2/11/2010 9:41 PM, Aahz wrote: > In article<34fcf680-1aa4-4835-9eba-3db3249f36b2 at q16g2000yqq.googlegroups.com>, > hjebbers wrote: >> >> the error is a windows thing, I can make a screenshot of it, but I can >> not copy/paste text. I think I know what box you mean. I believe this happened about 18 months ago with IDLE before 3.0 was released. Something to do with MS VC, which is different from gcc used on *nix. > In that case, you need to -- very carefully -- make sure you transcribe > exactly the message that you see on the screen. From frank at chagford.com Fri Feb 12 01:59:54 2010 From: frank at chagford.com (Frank Millman) Date: Fri, 12 Feb 2010 08:59:54 +0200 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr><4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: "Aahz" wrote in message news:hl2ob2$3ib$1 at panix5.panix.com... > In article , > Gabriel Genellina wrote: >> >>Strange. With Python 2.6.4 I don't need to do that; I'd say the difference >>is in the OS or antivirus (some AV are known to break the TCP stack). > > Perhaps, but I've also found that ctrl-C doesn't work on Windows. I don't know if this is exactly the same, but FWIW ... I had the following, in a test program - from wsgiref.simple_server import make_server myserver = MyServer() httpd = make_server('', 7789, myserver) httpd.serve_forever() try: while True: sleep(1) except KeyboardInterrupt: httpd.shutdown() I could not get it to respond to Ctrl-C. Then I read somewhere that it must run in a separate thread, so I changed it like this - - httpd.serve_forever() + threading.Thread(target=httpd.serve_forever).start() Now it does respond to Ctrl-C. HTH Frank Millman From bob.martin at excite.com Fri Feb 12 02:16:01 2010 From: bob.martin at excite.com (Bob Martin) Date: Fri, 12 Feb 2010 07:16:01 GMT Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: in 144446 20100212 034121 Paul Rubin wrote: >See http://en.wikipedia.org/wiki/Colossus_computer >That was almost at the end of the war though. Colossus was working by the end of 1943 - the year that the Americans first dropped bombs on Germany ;-) From arnodel at googlemail.com Fri Feb 12 02:29:12 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 12 Feb 2010 07:29:12 +0000 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: "Gabriel Genellina" writes: > En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy > escribi?: >> On 2/10/2010 4:49 PM, Gabriel Genellina wrote: >> >>> I've written a decorator for "injecting" a __function__ name into the >>> function namespace, but I can't find it anywhere. I think I implemented >>> it by adding a fake additional argument and replacing LOAD_GLOBAL with >>> LOAD_NAME in the bytecode. >> >> The decorator only needs to replace the defaults args tuple. >> It does not even need to know the parameter name, >> just that it is the only (or last) with a default . >> >> def f(n, me=None): >> if n > 0: return n*me(n-1) >> elif n==0: return 1 >> >> f.__defaults__ = (f,) # 3.1 >> print(f(5)) > > This is simple to implement, but requires changing the function > definition. My goal was to keep the original code unchanged, that is, > leave it as: > > def f(n): > if n > 0: return n*f(n-1) > elif n==0: return 1 > > (like a normal, recursive function), and make the 'f' inside the function > body "magically" refer to the function itself. I posted an example of a decorator that does just this in this thread a couple of days ago: http://mail.python.org/pipermail/python-list/2010-February/1235742.html It doesn't require any bytecode hacking, although it requires breaking apart the function object and making a new one from the bits. -- Arnaud From javier.collado at gmail.com Fri Feb 12 02:59:44 2010 From: javier.collado at gmail.com (Javier Collado) Date: Fri, 12 Feb 2010 08:59:44 +0100 Subject: python and http POST In-Reply-To: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: Hello, I haven't used httplib2, but you can certainly use any other alternative to send HTTP requests: - urllib/urllib2 - mechanize With regard to how do you find the form you're looking for, you may: - create the HTTP request on your own with urllib2. To find out what variables do you need to post, you can use tamperdata Firefox addon as suggested (I haven't used that one) or httpfox (I have and it works great). - use mechanize to locate the form for you, fill the data in and click on the submit button. Additionally, you may wan to scrape some data that may be useful for your requests. For that BeautifulSoup is good solution (with some Firebug help to visually locate what you're looking for). Best regards, Javier P.S. Some examples here: http://www.packtpub.com/article/web-scraping-with-python http://www.packtpub.com/article/web-scraping-with-python-part-2 2010/2/11 galileo228 : > Hey All, > > Been teaching myself Python for a few weeks, and am trying to write a > program that will go to a url, enter a string in one of the search > fields, submit the search, and return the contents of the search > result. > > I'm using httplib2. > > My two particular questions: > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > how do I know what the particular key should be? In other words, how > do I tell python which form on the web page I'm visiting I'd like to > fill in? Do I simply go to the webpage itself and look at the html > source? But if that's the case, which tag tells me the name of the > key? > > 2) Even once python fills in the form properly, how can I tell it to > 'submit' the search? > > Thanks all! > > Matt > -- > http://mail.python.org/mailman/listinfo/python-list > From jpiitula at ling.helsinki.fi Fri Feb 12 04:40:20 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 12 Feb 2010 11:40:20 +0200 Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Terry Reedy writes: > On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > > Robert Kern writes: > >> On 2010-02-11 06:31 AM, Shashwat Anand wrote: > >>> There is a little issue here that '>>> -.1 ** .1' should give you > >>> error message. That is it. > >> > >> No, fractional powers of negative numbers are perfectly valid > >> mathematically. The result is a complex number. In Python 3 (what > >> the OP is using), this has been implemented, but not in Python 2.6. > > > > Perhaps it should raise a MisleadingSpacingError at compile time. > > You forgot the smiley ;-). > > > The error message could recommend - .1**.1, or better -(.1 ** .1). > > The compiler would never see the difference between -.1 ** .1 and the > first and probably no difference with the second either. It could be done the same way that the compiler keeps track of the source line numbers now: early phases annotate their output with any information that later phases may need. This error would be detected during syntactic analysis. :) From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 12 04:46:29 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 12 Feb 2010 10:46:29 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4b75235b$0$23469$426a74cc@news.free.fr> Alf P. Steinbach a ?crit : (snip) > This group has an extraordinary high level of flaming and personal > attacks Oh my... (snip remaining non-sense) Mr Steinbach, I bet you'll count this as another "flaming" and "personal attack", but nonetheless : you might have happier time if you were able to understand the distinction between disagreement and "personal attack". (now back to more interesting readings) From jeanmichel at sequans.com Fri Feb 12 05:33:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Feb 2010 11:33:19 +0100 Subject: ANN: obfuscate In-Reply-To: References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: <4B752E6F.5070305@sequans.com> Bob Martin wrote: > in 144446 20100212 034121 Paul Rubin wrote: > > >> See http://en.wikipedia.org/wiki/Colossus_computer >> That was almost at the end of the war though. >> > > Colossus was working by the end of 1943 - the year that the Americans first dropped > bombs on Germany ;-) > sept 1939 - sept 1945. It's nearer from the end, than from the begining. JM From vinay_sajip at yahoo.co.uk Fri Feb 12 05:42:07 2010 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Fri, 12 Feb 2010 02:42:07 -0800 (PST) Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: <1d2a3c99-4837-45f8-8af0-73a155011686@z26g2000yqm.googlegroups.com> On Feb 11, 7:12?pm, mk wrote: > Peter Otten wrote: > > try: > > ? ?... > > except socket.error: > > ? ?... > > > #untested > > import socket > > > class SocketWrapper: > > ? ? def __getattr__(self, name): > > ? ? ? ? return getattr(socket, name) > > ? ? error = None > > > import module_using_socket > > module_using_socket.socket = SocketWrapper() > > Very interesting solution. Thanks! > > Regards, > mk On Feb 11, 2:12 pm, mk wrote: > Peter Otten wrote: > > try: > > ... > > except socket.error: > > ... > > > #untested > > import socket > > > class SocketWrapper: > > def __getattr__(self, name): > > return getattr(socket, name) > > error = None > > > import module_using_socket > > module_using_socket.socket = SocketWrapper() > > Very interesting solution. Thanks! > > Regards, > mk You could refine Peter's suggestion further. For example, if you don't want to change the flow of execution (as Peter's suggestion does) but just log the occurrences, then you could try something like this: # socktest.py import socket def test(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(('localhost', 9999)) except socket.error, e: print '-- handler printing:', e # sockwrap.py import socket import traceback import logging class SocketWrapper: def __getattr__(self, name): return getattr(socket, name) @property def error(self): # In practice you could log to a specific logger logging.exception('A socket error occurred') return getattr(socket, 'error') def wrap(mod): mod.socket = SocketWrapper() # Now try it out >>> import socktest, sockwrap >>> sockwrap.wrap(socktest) >>> socktest.test() ERROR:root:A socket error occurred Traceback (most recent call last): File "socktest.py", line 7, in test s.connect(('localhost', 9999)) File "", line 1, in connect error: (10061, 'Connection refused') -- handler printing: (10061, 'Connection refused') >>> Regards, Vinay Sajip From hjebbers at gmail.com Fri Feb 12 05:56:19 2010 From: hjebbers at gmail.com (hjebbers) Date: Fri, 12 Feb 2010 02:56:19 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> Message-ID: <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> On Feb 12, 3:41?am, a... at pythoncraft.com (Aahz) wrote: > In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, > > hjebbers ? wrote: > > >the error is a windows thing, I can make a screenshot of it, but I can > >not copy/paste text. > > In that case, you need to -- very carefully -- make sure you transcribe > exactly the message that you see on the screen. > -- > Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > "At Resolver we've found it useful to short-circuit any doubt and just ? ? ? ? > refer to comments in code as 'lies'. :-)" The message on the screen is (I typed it over): ************************************************************************************** python.exe python.exe has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost For more information about the error, click here. *************************************************************************************** the information about the error is a windows dump. kind regards, henk-jan From duncan.booth at invalid.invalid Fri Feb 12 07:10:26 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 12 Feb 2010 12:10:26 GMT Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Peter Otten <__peter__ at web.de> wrote: > You could try to shadow the exception class with None: > >>>> ZeroDivisionError = None >>>> try: > ... 1/0 > ... except ZeroDivisionError: > ... print "caught" > ... > Traceback (most recent call last): > File "", line 2, in > ZeroDivisionError: integer division or modulo by zero > This works in Python 2.x but will break in Python 3. None is not a valid exception specification and Python 3 will check for that and complain. >>> ZeroDivisionError = None >>> try: ... 1/0 ... except ZeroDivisionError: ... print('caught') ... Traceback (most recent call last): File "", line 2, in ZeroDivisionError: int division or modulo by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 3, in TypeError: catching classes that do not inherit from BaseException is not allowed >>> A better solution is to use an empty tuple as that is a valid exception specification so will work in both Python 2.x and 3.x: >>> ZeroDivisionError = () >>> try: ... 1/0 ... except ZeroDivisionError: ... print('caught') ... Traceback (most recent call last): File "", line 2, in ZeroDivisionError: int division or modulo by zero -- Duncan Booth http://kupuguy.blogspot.com From python.list at tim.thechases.com Fri Feb 12 07:15:41 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 06:15:41 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <4B75466D.6040706@tim.thechases.com> Aahz wrote: > Tim Chase wrote: >> Just to add to the mix, I'd put the "anydbm" module on the gradient >> between "using a file" and "using sqlite". It's a nice intermediate >> step between rolling your own file formats for data on disk, and having >> to write SQL since access is entirely like you'd do with a regular >> Python dictionary. > > Not quite. One critical difference between dbm and dicts is the need to > remember to "save" changes by setting the key's valud again. Could you give an example of this? I'm not sure I understand what you're saying. I've used anydbm a bunch of times and other than wrapping access in d = anydbm.open(DB_NAME, "c") # use d as a dict here d.close() and I've never hit any "need to remember to save changes by setting the key's value again". The only gotcha I've hit is the anydbm requirement that all keys/values be strings. Slightly annoying at times, but my most frequent use case. -tkc From prakash.stack at gmail.com Fri Feb 12 07:17:52 2010 From: prakash.stack at gmail.com (prakash jp) Date: Fri, 12 Feb 2010 17:47:52 +0530 Subject: search entire drive say c: Message-ID: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Hi all, can any of u help to search a file say "abc.txt" in entire c drive (windows) and print the path/s stating such a files presence. Thanks in advance Regards Prakash -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Fri Feb 12 07:36:42 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 12 Feb 2010 12:36:42 +0000 Subject: search entire drive say c: In-Reply-To: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <4B754B5A.3000405@timgolden.me.uk> On 12/02/2010 12:17, prakash jp wrote: > Hi all, > > can any of u help to search a file say "abc.txt" in entire c drive (windows) > and print the path/s stating such a files presence. This sounds rather like homework... Have a look at os.walk TJG From python.list at tim.thechases.com Fri Feb 12 08:01:12 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 07:01:12 -0600 Subject: search entire drive say c: In-Reply-To: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <4B755118.7090706@tim.thechases.com> > can any of u help to search a file say "abc.txt" in entire c drive (windows) > and print the path/s stating such a files presence. Well, you can just do it from DOS: c:\> dir /s/b/a abc.txt Just use os.walk() and check the list of files returned at each directory-level iteration. ROOT = "c:\\" fname = "abc.txt".lower() for p, d, f in os.walk(ROOT): for fn in f: if fn.lower() == fname: print os.path.join(p, f) # break You might also investigate using os.path.normcase() instead of .lower() -tkc From davea at ieee.org Fri Feb 12 08:06:07 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 12 Feb 2010 08:06:07 -0500 Subject: python crash on windows but not on linux In-Reply-To: <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: <4B75523F.4020903@ieee.org> hjebbers wrote: > On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: > >> In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >> >> hjebbers wrote: >> >> >>> the error is a windows thing, I can make a screenshot of it, but I can >>> not copy/paste text. >>> >> In that case, you need to -- very carefully -- make sure you transcribe >> exactly the message that you see on the screen. >> -- >> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >> >> "At Resolver we've found it useful to short-circuit any doubt and just >> refer to comments in code as 'lies'. :-)" >> > > The message on the screen is (I typed it over): > > You shouldn't ever have to retype the message. Just paste from the DOS box (or "Command Prompt"). It's easy using QuickEdit mode. You select a rectangle of the text by selecting with the mouse, then using right-click to put it in the clipboard. If that doesn't work, you haven't yet enabled QuickEdit mode. Use right-click on the DOS box's title bar. Choose Properties. Select the first tab, which is Options. You should then see a selection box called "Quick Edit Mode". Turn it on, and you won't have this problem again. DaveA From simon at brunningonline.net Fri Feb 12 08:21:26 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 12 Feb 2010 13:21:26 +0000 Subject: search entire drive say c: In-Reply-To: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <8c7f10c61002120521x3a820074r6765cc4622f912ca@mail.gmail.com> On 12 February 2010 12:17, prakash jp wrote: > can any of u help to search a file say "abc.txt" in entire c drive (windows) > and print?the path/s stating such a files presence. http://code.activestate.com/recipes/499305/ might be a useful start. -- Cheers, Simon B. From hjebbers at gmail.com Fri Feb 12 08:32:05 2010 From: hjebbers at gmail.com (hjebbers) Date: Fri, 12 Feb 2010 05:32:05 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: On Feb 12, 2:06?pm, Dave Angel wrote: > hjebbers wrote: > > On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: > > >> In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, > > >> hjebbers ? wrote: > > >>> the error is a windows thing, I can make a screenshot of it, but I can > >>> not copy/paste text. > > >> In that case, you need to -- very carefully -- make sure you transcribe > >> exactly the message that you see on the screen. > >> -- > >> Aahz (a... at pythoncraft.com) ? ? ? ? ? <*> ? ? ? ?http://www.pythoncraft.com/ > > >> "At Resolver we've found it useful to short-circuit any doubt and just ? ? ? ? > >> refer to comments in code as 'lies'. :-)" > > > The message on the screen is (I typed it over): > > > > > You shouldn't ever have to retype the message. ?Just paste from the DOS > box (or "Command Prompt"). ?It's easy using QuickEdit mode. > > You select a rectangle of the text by selecting with the mouse, then > using right-click to put it in the clipboard. > > If that doesn't work, you haven't yet enabled QuickEdit mode. ?Use > right-click on the DOS box's title bar. ?Choose Properties. ?Select the > first tab, which is Options. > > You should then see a selection box called "Quick Edit Mode". ?Turn it > on, and you won't have this problem again. > > DaveA Hi Dave, thanks. but the message is not in the DOS box (or "Command Prompt"). I do run the program in a DOS box (or "Command Prompt"), but the error is a windows dialog box. I can not select in this dialog box. kind regards, henk-jan From steve at holdenweb.com Fri Feb 12 08:34:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 08:34:40 -0500 Subject: python crash on windows but not on linux In-Reply-To: <4B75523F.4020903@ieee.org> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> <4B75523F.4020903@ieee.org> Message-ID: <4B7558F0.5090403@holdenweb.com> Dave Angel wrote: > hjebbers wrote: >> On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: >> >>> In article >>> <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >>> >>> hjebbers wrote: >>> >>> >>>> the error is a windows thing, I can make a screenshot of it, but I can >>>> not copy/paste text. >>>> >>> In that case, you need to -- very carefully -- make sure you transcribe >>> exactly the message that you see on the screen. >>> -- >>> Aahz (a... at pythoncraft.com) <*> >>> http://www.pythoncraft.com/ >>> >>> "At Resolver we've found it useful to short-circuit any doubt and >>> just refer to comments in code as 'lies'. :-)" >>> >> >> The message on the screen is (I typed it over): >> >> > > You shouldn't ever have to retype the message. Just paste from the DOS > box (or "Command Prompt"). It's easy using QuickEdit mode. > > You select a rectangle of the text by selecting with the mouse, then > using right-click to put it in the clipboard. > > If that doesn't work, you haven't yet enabled QuickEdit mode. Use > right-click on the DOS box's title bar. Choose Properties. Select the > first tab, which is Options. > > You should then see a selection box called "Quick Edit Mode". Turn it > on, and you won't have this problem again. > > DaveA > Dave: I think you miss the point: this message is being displayed in a Windows error message dialog box, not in the command window. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 12 08:34:40 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 08:34:40 -0500 Subject: python crash on windows but not on linux In-Reply-To: <4B75523F.4020903@ieee.org> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> <4B75523F.4020903@ieee.org> Message-ID: <4B7558F0.5090403@holdenweb.com> Dave Angel wrote: > hjebbers wrote: >> On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: >> >>> In article >>> <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >>> >>> hjebbers wrote: >>> >>> >>>> the error is a windows thing, I can make a screenshot of it, but I can >>>> not copy/paste text. >>>> >>> In that case, you need to -- very carefully -- make sure you transcribe >>> exactly the message that you see on the screen. >>> -- >>> Aahz (a... at pythoncraft.com) <*> >>> http://www.pythoncraft.com/ >>> >>> "At Resolver we've found it useful to short-circuit any doubt and >>> just refer to comments in code as 'lies'. :-)" >>> >> >> The message on the screen is (I typed it over): >> >> > > You shouldn't ever have to retype the message. Just paste from the DOS > box (or "Command Prompt"). It's easy using QuickEdit mode. > > You select a rectangle of the text by selecting with the mouse, then > using right-click to put it in the clipboard. > > If that doesn't work, you haven't yet enabled QuickEdit mode. Use > right-click on the DOS box's title bar. Choose Properties. Select the > first tab, which is Options. > > You should then see a selection box called "Quick Edit Mode". Turn it > on, and you won't have this problem again. > > DaveA > Dave: I think you miss the point: this message is being displayed in a Windows error message dialog box, not in the command window. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From eknath.iyer at gmail.com Fri Feb 12 08:41:40 2010 From: eknath.iyer at gmail.com (Eknath Venkataramani) Date: Fri, 12 Feb 2010 08:41:40 -0500 Subject: pyparsing wrong output Message-ID: <692c428f1002120541n6b3aabb0jb62c50f90715f38e@mail.gmail.com> I am trying to write a parser in pyparsing. Help Me. http://paste.pocoo.org/show/177078/ is the code and this is input file: http://paste.pocoo.org/show/177076/ . I get output as: * * -- Eknath Venkataramani +91-9844952442 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Fri Feb 12 08:53:02 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Feb 2010 14:53:02 +0100 Subject: Any way to turn off exception handling? (debugging) References: <8c7f10c61002110907r5724a0f1wa9e4a3c19a4455d6@mail.gmail.com> <7a9c25c21002110945i6b747c07i251a91c48c86f5b6@mail.gmail.com> Message-ID: Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: > >> You could try to shadow the exception class with None: > This works in Python 2.x but will break in Python 3. None is not a valid > exception specification and Python 3 will check for that and complain. > A better solution is to use an empty tuple as that is a valid exception > specification so will work in both Python 2.x and 3.x: Out of curiosity I tried a custom __subclasscheck__, but didn't get it to work in 3.1: $ cat instance_check.py class ZeroDivisionError(BaseException): class __metaclass__(type): def __subclasscheck__(self, other): print "performing subclass check --> %s" % catch return catch if __name__ == "__main__": for catch in [True, False]: print "catch = %s" % catch try: 1/0 except ZeroDivisionError: print "caught" $ python2.6 instance_check.py catch = True performing subclass check --> True caught catch = False performing subclass check --> False Traceback (most recent call last): File "instance_check.py", line 11, in 1/0 ZeroDivisionError: integer division or modulo by zero $ Peter From ljz at asfast.com Fri Feb 12 09:01:20 2010 From: ljz at asfast.com (Lloyd Zusman) Date: Fri, 12 Feb 2010 14:01:20 +0000 (UTC) Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? Message-ID: Perl has the following constructs to check whether a file is considered to contain "text" or "binary" data: if (-T $filename) { print "file contains 'text' characters\n"; } if (-B $filename) { print "file contains 'binary' characters\n"; } Is there already a Python analog to these? I'm happy to write them on my own if no such constructs currently exist, but before I start, I'd like to make sure that I'm not "re-inventing the wheel". By the way, here's what the perl docs say about these constructs. I'm looking for something similar in Python: ... The -T and -B switches work as follows. The first block or so ... of the file is examined for odd characters such as strange control ... codes or characters with the high bit set. If too many strange ... characters (>30%) are found, it's a -B file; otherwise it's a -T ... file. Also, any file containing null in the first block is ... considered a binary file. [ ... ] Thanks in advance for any suggestions. -- Lloyd Zusman ljz at asfast.com God bless you. From lists at cheimes.de Fri Feb 12 09:09:58 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 15:09:58 +0100 Subject: python crash on windows but not on linux In-Reply-To: <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: <4B756136.3070202@cheimes.de> hjebbers wrote: > The message on the screen is (I typed it over): > > ************************************************************************************** > python.exe > > python.exe has encountered a problem and needs to close. > We are sorry for the inconvenience. > > If you were in the middle of something, the information you were > working on might be > lost > > For more information about the error, click here. > > button> > *************************************************************************************** > the information about the error is a windows dump. I suggest you install some sort of debugger on your system (e.g. Visual Studio) and do a post mortem analysis of your stack trace. Christian From lists at cheimes.de Fri Feb 12 09:14:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 15:14:07 +0100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <4B75622F.8040303@cheimes.de> Lloyd Zusman wrote: > .... The -T and -B switches work as follows. The first block or so > .... of the file is examined for odd characters such as strange control > .... codes or characters with the high bit set. If too many strange > .... characters (>30%) are found, it's a -B file; otherwise it's a -T > .... file. Also, any file containing null in the first block is > .... considered a binary file. [ ... ] That's a butt ugly heuristic that will lead to lots of false positives if your text happens to be UTF-16 encoded or non-english text UTF-8 encoded. Christian From lists at cheimes.de Fri Feb 12 09:14:07 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 15:14:07 +0100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <4B75622F.8040303@cheimes.de> Lloyd Zusman wrote: > .... The -T and -B switches work as follows. The first block or so > .... of the file is examined for odd characters such as strange control > .... codes or characters with the high bit set. If too many strange > .... characters (>30%) are found, it's a -B file; otherwise it's a -T > .... file. Also, any file containing null in the first block is > .... considered a binary file. [ ... ] That's a butt ugly heuristic that will lead to lots of false positives if your text happens to be UTF-16 encoded or non-english text UTF-8 encoded. Christian From __peter__ at web.de Fri Feb 12 09:17:04 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 12 Feb 2010 15:17:04 +0100 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> Message-ID: hjebbers wrote: > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: >> hjebbers wrote: >> > On Feb 11, 5:45 pm, M3RT wrote: >> >> The problem may be related to how you treat the EDI file or lets say >> >> DATA. Also your coding style is important. Can you provide more info? >> >> > Yes, a whole lot more; but I do not want to bother you with that now. >> > I was just wondering if it is possible that the same setup gives a >> > CRASH! on windows and just works on linux. >> > (where is the bug?) >> >> In the platform-specific code ;) >> >> Even on alt.haruspicy they cannot do much without a liver now and then... > > if it is in the platform-specific code should I make this into a > bugreport? A this stage a bug report would be useless. The details you have provided so far don't give anyone without physical access to your machine a chance to reproduce the error. > (because the crash does not appear at the same place in my code (when > doing the same test-run) it will be quite hard to point down....) Indeed. The culprit may be an extension written in C that is overwriting memory still in use by other parts of your program. Peter From clp2 at rebertia.com Fri Feb 12 09:18:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 12 Feb 2010 06:18:24 -0800 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <50697b2c1002120618u1d3cacccx45a0f209313b220@mail.gmail.com> On Fri, Feb 12, 2010 at 6:01 AM, Lloyd Zusman wrote: > Perl has the following constructs to check whether a file is considered > to contain "text" or "binary" data: > > if (-T $filename) { print "file contains 'text' characters\n"; } > if (-B $filename) { print "file contains 'binary' characters\n"; } > > Is there already a Python analog to these? I'm happy to write them on > my own if no such constructs currently exist, but before I start, I'd > like to make sure that I'm not "re-inventing the wheel". > > By the way, here's what the perl docs say about these constructs. I'm > looking for something similar in Python: > > ... The -T ?and -B ?switches work as follows. The first block or so > ... of the file is examined for odd characters such as strange control > ... codes or characters with the high bit set. If too many strange > ... characters (>30%) are found, it's a -B file; otherwise it's a -T > ... file. Also, any file containing null in the first block is > ... considered a binary file. [ ... ] Pray tell, what are the circumstances that lead you to use such a heuristic rather than a more definitive method? Cheers, Chris -- http://blog.rebertia.com From simon at brunningonline.net Fri Feb 12 09:18:54 2010 From: simon at brunningonline.net (Simon Brunning) Date: Fri, 12 Feb 2010 14:18:54 +0000 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: <4B75622F.8040303@cheimes.de> References: <4B75622F.8040303@cheimes.de> Message-ID: <8c7f10c61002120618r611ea8dfj4d2f4bbaf25a920@mail.gmail.com> On 12 February 2010 14:14, Christian Heimes wrote: > That's a butt ugly heuristic He did say it was from Perl, the home of butt-ugly. -- Cheers, Simon B. From aahz at pythoncraft.com Fri Feb 12 09:21:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 06:21:19 -0800 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: In article , Tim Chase wrote: >Aahz wrote: >> Tim Chase wrote: >>> >>> Just to add to the mix, I'd put the "anydbm" module on the gradient >>> between "using a file" and "using sqlite". It's a nice intermediate >>> step between rolling your own file formats for data on disk, and having >>> to write SQL since access is entirely like you'd do with a regular >>> Python dictionary. >> >> Not quite. One critical difference between dbm and dicts is the need to >> remember to "save" changes by setting the key's valud again. > >Could you give an example of this? I'm not sure I understand >what you're saying. I've used anydbm a bunch of times and other >than wrapping access in > > d = anydbm.open(DB_NAME, "c") > # use d as a dict here > d.close() > >and I've never hit any "need to remember to save changes by >setting the key's value again". The only gotcha I've hit is the >anydbm requirement that all keys/values be strings. Slightly >annoying at times, but my most frequent use case. Well, you're more likely to hit this by wrapping dbm with shelve (because it's a little more obvious when you're using pickle directly), but consider this: d = anydbm.open(DB_NAME, "c") x = MyClass() d['foo'] = x x.bar = 123 Your dbm does NOT have the change to x.bar recorded, you must do this again: d['foo'] = x With a dict, you have Python's reference semantics. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 09:22:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 06:22:40 -0800 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: In article , Dennis Lee Bieber wrote: >On 11 Feb 2010 21:18:26 -0800, aahz at pythoncraft.com (Aahz) declaimed the >following in gmane.comp.python.general: >> In article , >> Gabriel Genellina wrote: >>> >>>Strange. With Python 2.6.4 I don't need to do that; I'd say the difference >>>is in the OS or antivirus (some AV are known to break the TCP stack). >> >> Perhaps, but I've also found that ctrl-C doesn't work on Windows. > > Unless the running program makes an I/O call to the console, I don't >think gets past the device driver... That's probably it. It's more annoying for me because I run Windows with a VM on a Mac, which doesn't have ctrl-break. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Fri Feb 12 09:26:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 06:26:51 -0800 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: In article , Lloyd Zusman wrote: > >Perl has the following constructs to check whether a file is considered >to contain "text" or "binary" data: > >if (-T $filename) { print "file contains 'text' characters\n"; } >if (-B $filename) { print "file contains 'binary' characters\n"; } Assuming you're on a Unix-like system or can install Cygwin, the standard response is to use the "file" command. It's *much* more sophisticated. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From prakash.stack at gmail.com Fri Feb 12 09:33:18 2010 From: prakash.stack at gmail.com (prakash jp) Date: Fri, 12 Feb 2010 20:03:18 +0530 Subject: search entire drive say c: In-Reply-To: <4B755118.7090706@tim.thechases.com> References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> <4B755118.7090706@tim.thechases.com> Message-ID: <805f59d51002120633h387323dcjb9be71e5955536cd@mail.gmail.com> Thank u Tim Case, all, Also how to run the standalone generated from script taking unc path names to account regards Prakash On Fri, Feb 12, 2010 at 6:31 PM, Tim Chase wrote: > can any of u help to search a file say "abc.txt" in entire c drive >> (windows) >> and print the path/s stating such a files presence. >> > > Well, you can just do it from DOS: > > c:\> dir /s/b/a abc.txt > > Just use os.walk() and check the list of files returned at each > directory-level iteration. > > ROOT = "c:\\" > fname = "abc.txt".lower() > for p, d, f in os.walk(ROOT): > for fn in f: > if fn.lower() == fname: > print os.path.join(p, f) > # break > > You might also investigate using os.path.normcase() instead of .lower() > > -tkc > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 12 09:39:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 12 Feb 2010 15:39:22 +0100 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> Message-ID: <4b7567fe$0$13293$426a34cc@news.free.fr> Peter Otten a ?crit : (snip) > Even on alt.haruspicy they cannot do much without a liver now and then... Muhahahahaha !-) +1 QOTW From python.list at tim.thechases.com Fri Feb 12 09:45:17 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 08:45:17 -0600 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: References: Message-ID: <4B75697D.5040403@tim.thechases.com> Lloyd Zusman wrote: > Perl has the following constructs to check whether a file is considered > to contain "text" or "binary" data: > > if (-T $filename) { print "file contains 'text' characters\n"; } > if (-B $filename) { print "file contains 'binary' characters\n"; } > > Is there already a Python analog to these? I'm happy to write them on > my own if no such constructs currently exist, but before I start, I'd > like to make sure that I'm not "re-inventing the wheel". > > By the way, here's what the perl docs say about these constructs. I'm > looking for something similar in Python: > > ... The -T and -B switches work as follows. The first block or so > ... of the file is examined for odd characters such as strange control > ... codes or characters with the high bit set. If too many strange > ... characters (>30%) are found, it's a -B file; otherwise it's a -T > ... file. Also, any file containing null in the first block is > ... considered a binary file. [ ... ] While I agree with the others who have responded along the lines of "that's a hinky heuristic", it's not too hard to write an analog: import string def is_text(fname, chars=set(string.printable), threshold=0.3, portion=1024, # read a kilobyte to find out mode='rb', ): assert portion is None or portion > 0 assert 0 < threshold < 1 f = file(fname, mode) if portion is None: content = iter(f) else: content = iter(f.read(int(portion))) f.close() total = valid = 0 for c in content: if c in chars: valid += 1 total += 1 return (float(valid)/total) > threshold def is_bin(*args, **kwargs): return not is_text(*args, **kwargs) for fname in ( '/usr/bin/abiword', '/home/tkc/.bashrc', ): print fname, is_text(fname) It should allow you to tweak the charset to consider "text", defaulting to string.printable, but adjust the "text" chars and the file-reading-mode accordingly if you're using unicode text (perhaps inverting the logic to make it an "binary chars" set). You can also change the threshold from 0.3 (30%) to whatever you need, and test the entire file or a subset of it (this defaults to just reading the first K of the file, but if you pass None for the portion, it will read the whole thing, even if it's a TB file). -tkc From jlconlin at gmail.com Fri Feb 12 09:45:31 2010 From: jlconlin at gmail.com (Jeremy) Date: Fri, 12 Feb 2010 06:45:31 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> Message-ID: <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> On Feb 11, 6:50?pm, Steven D'Aprano wrote: > On Thu, 11 Feb 2010 15:39:09 -0800, Jeremy wrote: > > My Python program now consumes over 2 GB of memory and then I get a > > MemoryError. ?I know I am reading lots of files into memory, but not 2GB > > worth. > > Are you sure? > > Keep in mind that Python has a comparatively high overhead due to its > object-oriented nature. If you have a list of characters: > > ['a', 'b', 'c', 'd'] > > there is the (small) overhead of the list structure itself, but each > individual character is not a single byte, but a relatively large object: > > ?>>> sys.getsizeof('a') > 32 > > So if you read (say) a 500MB file into a single giant string, you will > have 500MB plus the overhead of a single string object (which is > negligible). But if you read it into a list of 500 million single > characters, you will have the overhead of a single list, plus 500 million > strings, and that's *not* negligible: 32 bytes each instead of 1. > > So try to avoid breaking a single huge strings into vast numbers of tiny > strings all at once. > > > I thought I didn't have to worry about memory allocation in > > Python because of the garbage collector. > > You don't have to worry about explicitly allocating memory, and you > almost never have to worry about explicitly freeing memory (unless you > are making objects that, directly or indirectly, contain themselves -- > see below); but unless you have an infinite amount of RAM available of > course you can run out of memory if you use it all up :) > > > On this note I have a few > > questions. ?FYI I am using Python 2.6.4 on my Mac. > > > 1. ? ?When I pass a variable to the constructor of a class does it copy > > that variable or is it just a reference/pointer? ?I was under the > > impression that it was just a pointer to the data. > > Python's calling model is the same whether you pass to a class > constructor or any other function or method: > > x = ["some", "data"] > obj = f(x) > > The function f (which might be a class constructor) sees the exact same > list as you assigned to x -- the list is not copied first. However, > there's no promise made about what f does with that list -- it might copy > the list, or make one or more additional lists: > > def f(a_list): > ? ? another_copy = a_list[:] > ? ? another_list = map(int, a_list) > > > 2. ? ?When do I need > > to manually allocate/deallocate memory and when can I trust Python to > > take care of it? > > You never need to manually allocate memory. > > You *may* need to deallocate memory if you make "reference loops", where > one object refers to itself: > > l = [] ?# make an empty list > l.append(l) ?# add the list l to itself > > Python can break such simple reference loops itself, but for more > complicated ones, you may need to break them yourself: > > a = [] > b = {2: a} > c = (None, b) > d = [1, 'z', c] > a.append(d) ?# a reference loop > > Python will deallocate objects when they are no longer in use. They are > always considered in use any time you have them assigned to a name, or in > a list or dict or other structure which is in use. > > You can explicitly remove a name with the del command. For example: > > x = ['my', 'data'] > del x > > After deleting the name x, the list object itself is no longer in use > anywhere and Python will deallocate it. But consider: > > x = ['my', 'data'] > y = x ?# y now refers to THE SAME list object > del x > > Although you have deleted the name x, the list object is still bound to > the name y, and so Python will *not* deallocate the list. > > Likewise: > > x = ['my', 'data'] > y = [None, 1, x, 'hello world'] > del x > > Although now the list isn't bound to a name, it is inside another list, > and so Python will not deallocate it. > > > 3. ? ?Any good practice suggestions? > > Write small functions. Any temporary objects created by the function will > be automatically deallocated when the function returns. > > Avoid global variables. They are a good way to inadvertently end up with > multiple long-lasting copies of data. > > Try to keep data in one big piece rather than lots of little pieces. > > But contradicting the above, if the one big piece is too big, it will be > hard for the operating system to swap it in and out of virtual memory, > causing thrashing, which is *really* slow. So aim for big, but not huge. > > (By "big" I mean megabyte-sized; by "huge" I mean hundreds of megabytes.) > > If possible, avoid reading the entire file in at once, and instead > process it line-by-line. > > Hope this helps, > > -- > Steven Wow, what a great bunch of responses. Thank you very much. If I understand correctly the suggestions seem to be: 1. Write algorithms to read a file one line at a time instead of reading the whole thing 2. Use lots of little functions so that memory can fall out of scope. You also confirmed what I thought was true that all variables are passed "by reference" so I don't need to worry about the data being copied (unless I do that explicitly). Thanks! Jeremy From python.list at tim.thechases.com Fri Feb 12 09:54:27 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 12 Feb 2010 08:54:27 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> Message-ID: <4B756BA3.3090408@tim.thechases.com> Aahz wrote: >>> Not quite. One critical difference between dbm and dicts >>> is the need to remember to "save" changes by setting the >>> key's valud again. >> >> Could you give an example of this? I'm not sure I >> understand what you're saying. > > Well, you're more likely to hit this by wrapping dbm with shelve (because > it's a little more obvious when you're using pickle directly), but > consider this: > > d = anydbm.open(DB_NAME, "c") > x = MyClass() > d['foo'] = x > x.bar = 123 > > Your dbm does NOT have the change to x.bar recorded, you must do this > again: > > d['foo'] = x > > With a dict, you have Python's reference semantics. Ah, that makes sense...fallout of the "dbm only does string keys/values". It try to adhere to the "only use strings", so I'm more cognizant of when I martial complex data-types in or out of those strings. But I can see where it could bite a person. Thanks, -tkc From edreamleo at gmail.com Fri Feb 12 10:09:47 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Fri, 12 Feb 2010 09:09:47 -0600 Subject: ANN: Leo 4.7 rc1 released Message-ID: <8pran590ve55gaasfur10pv4jbcuvvr6pi@4ax.com> Leo 4.7 release candidate 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7 rc 1 fixes all known serious bugs in Leo; minor nits remain. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - Leo creates a 'Recovered Nodes' node to hold data that otherwise might be lost due to clone conflicts. - @auto-rst now works much more reliably reliably. - Leo no longer supports @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream February 12, 2010 From bob.martin at excite.com Fri Feb 12 10:13:07 2010 From: bob.martin at excite.com (Bob Martin) Date: Fri, 12 Feb 2010 15:13:07 GMT Subject: ANN: obfuscate References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: <7eedn.39244$Ym4.2333@text.news.virginmedia.com> in 144460 20100212 103319 Jean-Michel Pichavant wrote: >Bob Martin wrote: >> in 144446 20100212 034121 Paul Rubin wrote: >> >> >>> See http://en.wikipedia.org/wiki/Colossus_computer >>> That was almost at the end of the war though. >>> >> >> Colossus was working by the end of 1943 - the year that the Americans first dropped >> bombs on Germany ;-) >> >sept 1939 - sept 1945. It's nearer from the end, than from the begining. If I must spell it out ;-) Near the end for us Brits but the Americans were only just getting into the action in Europe. From breamoreboy at yahoo.co.uk Fri Feb 12 10:39:37 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 12 Feb 2010 15:39:37 +0000 Subject: ANN: obfuscate In-Reply-To: <7xy6iz86ji.fsf@ruckus.brouhaha.com> References: <00fa27a3$0$15628$c3e8da3@news.astraweb.com> <8c7f10c61002091410o10fe04d8r4a8c544605af64ae@mail.gmail.com> <4B71EF50.7050801@gmail.com> <7thr3kFeqlU1@mid.individual.net> <4B73D1E8.9040603@cheimes.de> <7xy6iz86ji.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Mark Lawrence writes: >>> The predecessor of the Enigma was cracked by Polish scientists years >>> before WW2 started.... >> I believe that all of Enigma was eventually cracked cos of two major >> flaws. > > I think it never would have been cracked if it hadn't been cracked > (whether by the Brits or the Poles) before the war started, using > commercial versions of the Enigma that they had access to. The military > Enigma and its operating methods got more sophisticated as the war went > on, and the cryptanalysts were able to keep up with it by incrementally > improving techniques that they were already using at scale. If they > were suddenly confronted with the full-blown military system in the > middle of the war, it would have been a lot harder to do anything about > it. At least, most of the Enigma-related books I've read give that > impression and even come out and say such things. I completely agree. > >> Further, the far more powerful Geheimscreiber was also cracked at >> Bletchley by using Colossus. Sorry some years since I read the book >> about this so can't remember the title or author. > > See http://en.wikipedia.org/wiki/Colossus_computer > That was almost at the end of the war though. From macmanes at gmail.com Fri Feb 12 11:06:41 2010 From: macmanes at gmail.com (PeroMHC) Date: Fri, 12 Feb 2010 08:06:41 -0800 (PST) Subject: concatenate fasta file Message-ID: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Hi All, I have a simple problem that I hope somebody can help with. I have an input file (a fasta file) that I need to edit.. Input file format >name 1 tactcatacatac >name 2 acggtggcat >name 3 gggtaccacgtt I need to concatenate the sequences.. make them look like >concatenated tactcatacatacacggtggcatgggtaccacgtt thanks. Matt From tjreedy at udel.edu Fri Feb 12 11:08:34 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Feb 2010 11:08:34 -0500 Subject: Bizarre arithmetic results In-Reply-To: References: <1265849053.24800.38.camel@localhost> Message-ID: On 2/12/2010 4:40 AM, Jussi Piitulainen wrote: > Terry Reedy writes: >> On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: >>> Robert Kern writes: >>>> On 2010-02-11 06:31 AM, Shashwat Anand wrote: >>>>> There is a little issue here that '>>> -.1 ** .1' should give you >>>>> error message. That is it. >>>> >>>> No, fractional powers of negative numbers are perfectly valid >>>> mathematically. The result is a complex number. In Python 3 (what >>>> the OP is using), this has been implemented, but not in Python 2.6. >>> >>> Perhaps it should raise a MisleadingSpacingError at compile time. >> >> You forgot the smiley ;-). >> >> > The error message could recommend - .1**.1, or better -(.1 ** .1). >> >> The compiler would never see the difference between -.1 ** .1 and the >> first and probably no difference with the second either. > > It could be done the same way that the compiler keeps track of the > source line numbers now: early phases annotate their output with any > information that later phases may need. This error would be detected > during syntactic analysis. There is no error to detect. Sorry, read the manual and either learn or lookup precedence rules (there is a table in the end of the Expressions chapter) or use parentheses when not sure. From roy at panix.com Fri Feb 12 11:23:54 2010 From: roy at panix.com (Roy Smith) Date: Fri, 12 Feb 2010 11:23:54 -0500 Subject: concatenate fasta file References: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Message-ID: In article <62a50def-e391-4585-9a23-fb91f2e2edc8 at b9g2000pri.googlegroups.com>, PeroMHC wrote: > Hi All, I have a simple problem that I hope somebody can help with. I > have an input file (a fasta file) that I need to edit.. > > Input file format > > >name 1 > tactcatacatac > >name 2 > acggtggcat > >name 3 > gggtaccacgtt > > I need to concatenate the sequences.. make them look like > > >concatenated > tactcatacatacacggtggcatgggtaccacgtt > > thanks. Matt Some quick ideas. First, try something along the lines of (not tested): data=[] for line in sys.stdin: if line.startswith('>'): continue data.append(line.strip()) print ''.join(data) Second, check out http://biopython.org/wiki/Main_Page. I'm sure somebody has solved this problem before. From jeanmichel at sequans.com Fri Feb 12 11:49:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 12 Feb 2010 17:49:15 +0100 Subject: concatenate fasta file In-Reply-To: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> References: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Message-ID: <4B75868B.2030807@sequans.com> PeroMHC wrote: > Hi All, I have a simple problem that I hope somebody can help with. I > have an input file (a fasta file) that I need to edit.. > > Input file format > > >> name 1 >> > tactcatacatac > >> name 2 >> > acggtggcat > >> name 3 >> > gggtaccacgtt > > I need to concatenate the sequences.. make them look like > > >> concatenated >> > tactcatacatacacggtggcatgggtaccacgtt > > thanks. Matt > A solution using regexp: found = [] for line in open('seqfile.txt'): found += re.findall('^[acgtACGT]+$', line) print found > ['tactcatacatac', 'acggtggcat', 'gggtaccacgtt'] print ''.join(found) > 'tactcatacatacacggtggcatgggtaccacgtt' JM From python at mrabarnett.plus.com Fri Feb 12 12:05:37 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 17:05:37 +0000 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? In-Reply-To: <4B75622F.8040303@cheimes.de> References: <4B75622F.8040303@cheimes.de> Message-ID: <4B758A61.4090606@mrabarnett.plus.com> Christian Heimes wrote: > Lloyd Zusman wrote: >> .... The -T and -B switches work as follows. The first block or so >> .... of the file is examined for odd characters such as strange control >> .... codes or characters with the high bit set. If too many strange >> .... characters (>30%) are found, it's a -B file; otherwise it's a -T >> .... file. Also, any file containing null in the first block is >> .... considered a binary file. [ ... ] > > That's a butt ugly heuristic that will lead to lots of false positives > if your text happens to be UTF-16 encoded or non-english text UTF-8 encoded. > ...or non-English Latin-1 text... From jcquevedo84 at gmail.com Fri Feb 12 12:08:59 2010 From: jcquevedo84 at gmail.com (Juan Carlos Rodriguez) Date: Fri, 12 Feb 2010 13:08:59 -0400 Subject: Configuring apache to execute python scripts using mod_python handler Message-ID: I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added AddHandler mod_python .py PythonHandler mptest PythonDebug On 2. Then I added the line "LoadModule python_module modules/ mod_python.so" to http.conf. Then I tried execute the python script mentioned below from browser. from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Hello World!") return apache.OK Then I am getting the following error Traceback (most recent call last): File "D:\softwares\Python25\Lib\site-packages\mod_python \importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "D:\softwares\Python25\Lib\site-packages\mod_python \importer.py", line 1202, in _process_target module = import_module(module_name, path=path) File "D:\softwares\Python25\Lib\site-packages\mod_python \importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named mptest I am using Apache 2.2.4, python 2.5 and mod_python-3.3.1.win32-py2.5- Apache2.2. I am able to execute python scripts by configuring apache to execute the cgi scripts. But I want to execute it using mod_python as it is faster compared to cgi mode. Someone please help me on this issue. -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon.hibbs at gmail.com Fri Feb 12 12:11:38 2010 From: simon.hibbs at gmail.com (Simon Hibbs) Date: Fri, 12 Feb 2010 09:11:38 -0800 (PST) Subject: Generic spreadsheet interface References: <3acdf3a7-e2eb-4a9a-bc89-7e285073a9c9@o28g2000yqh.googlegroups.com> Message-ID: <34982944-fa6a-45e9-86a1-4b09a5a39d6e@z19g2000yqk.googlegroups.com> Hi Bro, I don't know of anything like that. The spreadsheet sites I do know of are application-specific. http://www.python-excel.org/ http://wiki.services.openoffice.org/wiki/Python http://lucasmanual.com/mywiki/OpenOffice Note that the OO.o bindings for Python are only for Python 2.3 which is a little archaic, but it's the version I started with and should be more than good enough for spreadsheet work. A port to 2.5 is well underway. You'd probably need to write your own application-specific wrapper modules with a common API and then use those, but it's probably not as much work as it sounds and could be developed incrementaly. Alternatively you just write your code against one spreadsheet module, and then write a wrapper module for the other spreadsheet API so it looks the same. Simon Hibbs From davea at ieee.org Fri Feb 12 12:14:26 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 12 Feb 2010 12:14:26 -0500 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: <4B758C72.7020901@ieee.org> hjebbers wrote: > On Feb 12, 2:06 pm, Dave Angel wrote: > >> hjebbers wrote: >> >>> On Feb 12, 3:41 am, a... at pythoncraft.com (Aahz) wrote: >>> >>>> In article <34fcf680-1aa4-4835-9eba-3db3249f3... at q16g2000yqq.googlegroups.com>, >>>> >>>> hjebbers wrote: >>>> >>>>> the error is a windows thing, I can make a screenshot of it, but I can >>>>> not copy/paste text. >>>>> >>>> In that case, you need to -- very carefully -- make sure you transcribe >>>> exactly the message that you see on the screen. >>>> -- >>>> Aahz (a... at pythoncraft.com) <*> http://www.pythoncraft.com/ >>>> >>>> "At Resolver we've found it useful to short-circuit any doubt and just >>>> refer to comments in code as 'lies'. :-)" >>>> >>> The message on the screen is (I typed it over): >>> >>> >>> >> You shouldn't ever have to retype the message. Just paste from the DOS >> box (or "Command Prompt"). It's easy using QuickEdit mode. >> >> You select a rectangle of the text by selecting with the mouse, then >> using right-click to put it in the clipboard. >> >> If that doesn't work, you haven't yet enabled QuickEdit mode. Use >> right-click on the DOS box's title bar. Choose Properties. Select the >> first tab, which is Options. >> >> You should then see a selection box called "Quick Edit Mode". Turn it >> on, and you won't have this problem again. >> >> DaveA >> > > Hi Dave, > > thanks. > but the message is not in the DOS box (or "Command Prompt"). > I do run the program in a DOS box (or "Command Prompt"), but the error > is a windows dialog box. > I can not select in this dialog box. > > kind regards, > henk-jan > > Whoops! I agree those dialog boxes that don't support select/copy are a pain. Sorry my response wasn't applicable. DaveA From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 12:14:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 17:14:57 GMT Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> Message-ID: <038578a2$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 06:45:31 -0800, Jeremy wrote: > You also confirmed what I thought was true that all variables are passed > "by reference" so I don't need to worry about the data being copied > (unless I do that explicitly). No, but yes. No, variables are not passed by reference, but yes, you don't have to worry about them being copied. You have probably been mislead into thinking that there are only two calling conventions possible, "pass by value" and "pass by reference". That is incorrect. There are many different calling conventions, and different groups use the same names to mean radically different things. If a language passes variables by reference, you can write a "swap" function like this: def swap(a, b): a, b = b, a x = 1 y = 2 swap(x, y) assert (x == 2) and (y==1) But this does not work in Python, and cannot work without trickery. So Python absolutely is not "pass by reference". On the other hand, if a variable is passed by value, then a copy is made and you can do this: def append1(alist): alist.append(1) # modify the copy return alist x = [] newlist = append1(x) assert x == [] # The old value still exists. But this also doesn't work in Python! So Python isn't "pass by value" either. What Python does is called "pass by sharing", or sometimes "pass by object reference". It is exactly the same as what (e.g.) Ruby and Java do, except that confusingly the Ruby people call it "pass by reference" and the Java people call it "pass by value", thus guaranteeing the maximum amount of confusion possible. More here: http://effbot.org/zone/call-by-object.htm http://en.wikipedia.org/wiki/Evaluation_strategy -- Steven From torriem at gmail.com Fri Feb 12 12:18:23 2010 From: torriem at gmail.com (Michael Torrie) Date: Fri, 12 Feb 2010 10:18:23 -0700 Subject: looking for some libraries In-Reply-To: <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> References: <6f94f534-ed05-4b45-aa38-c05060eb7f4b@o36g2000vbl.googlegroups.com> <9cb81f4e-e7cd-4b5d-992e-2e31f786a1da@f8g2000yqn.googlegroups.com> Message-ID: <4B758D5F.6000907@gmail.com> rantingrick wrote: > Well a GUI kit comes to mind. And since you did not mention a > preference (or much really) i would suggest Tkinter in the stdlib as a > starting point. Here is a big hint! I think the original poster is looking for a way to automate an existing GUI process, and screen-scrape the resulting output from this existing GUI. He does not say what OS he is working on, so it's hard to really suggest anything. If he's on Windows, I'd give a look at AutoIt[1], which has its own complete programming language. I know with AutoIt I could click on buttons and then scrape text from an edit box. AutoIt probably has the ability to write this data out to a file as well. Not Python, but hey. [1] http://www.autoitscript.com/autoit3/index.shtml From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 12:20:06 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 17:20:06 GMT Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: <038579d7$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 15:14:07 +0100, Christian Heimes wrote: > Lloyd Zusman wrote: >> .... The -T and -B switches work as follows. The first block or so >> .... of the file is examined for odd characters such as strange control >> .... codes or characters with the high bit set. If too many strange >> .... characters (>30%) are found, it's a -B file; otherwise it's a -T >> .... file. Also, any file containing null in the first block is .... >> considered a binary file. [ ... ] > > That's a butt ugly heuristic that will lead to lots of false positives > if your text happens to be UTF-16 encoded or non-english text UTF-8 > encoded. And a hell of a lot of false negatives if the file is binary. The way I've always seen it, a file is binary if it contains a single binary character *anywhere* in the file. -- Steven From hjebbers at gmail.com Fri Feb 12 12:21:07 2010 From: hjebbers at gmail.com (hjebbers) Date: Fri, 12 Feb 2010 09:21:07 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> Message-ID: <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> On Feb 12, 3:17?pm, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: > >> hjebbers wrote: > >> > On Feb 11, 5:45 pm, M3RT wrote: > >> >> The problem may be related to how you treat the EDI file or lets say > >> >> DATA. Also your coding style is important. Can you provide more info? > > >> > Yes, a whole lot more; but I do not want to bother you with that now. > >> > I was just wondering if it is possible that the same setup gives a > >> > CRASH! on windows and just works on linux. > >> > (where is the bug?) > > >> In the platform-specific code ;) > > >> Even on alt.haruspicy they cannot do much without a liver now and then... > > > if it is in the platform-specific code should I make this into a > > bugreport? > > A this stage a bug report would be useless. The details you have provided so > far don't give anyone without physical access to your machine a chance to > reproduce the error. > > > (because the crash does not appear at the same place in my code (when > > doing the same test-run) it will be quite hard to point down....) > > Indeed. The culprit may be an extension written in C that is overwriting > memory still in use by other parts of your program. > > Peter No C extensions used. Definitely not. As these crashes occur during stress tests, I go to the limits of the memory available. What strikes me is: 1. the crash on windows, but linux works OK (same test sets) 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as much). kind regards, Henk-jan From jcquevedo84 at gmail.com Fri Feb 12 12:34:33 2010 From: jcquevedo84 at gmail.com (Juan Carlos Rodriguez) Date: Fri, 12 Feb 2010 13:34:33 -0400 Subject: Helpp I want view page .py on apache WHAT CAN I DO??????????????? Message-ID: Dear all, I am trying implement a text from mod_python. I have a apahce service 2.2.4, python 2.5 and mod_python 3.3.1 I have this mistake: MOD_PYTHON ERROR ProcessId: 5956 Interpreter: '192.168.5.32' ServerName: '192.168.5.32' DocumentRoot: 'D:/aplicaciones/web' URI: '/python/index.py' Location: None Directory: 'D:/aplicaciones/web/python/' Filename: 'D:/aplicaciones/web/python/index.py' PathInfo: '' Phase: 'PythonHandler' Handler: 'mptest' Traceback (most recent call last): File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1202, in _process_target module = import_module(module_name, path=path) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named mptest *WHAT CAN I DO?* -------------- next part -------------- An HTML attachment was scrubbed... URL: From chyavana at gmail.com Fri Feb 12 12:45:35 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Sat, 13 Feb 2010 01:45:35 +0800 Subject: Sorting a list of lists Message-ID: <4B7593BF.1030708@gmail.com> Dear Folks, I have lines of values like so: 14, [25, 105, 104] 10, [107, 106, 162] 21, [26, 116, 165] I need to sort them in two ways: (a) By the numeric value of the first column; and (b) by the sum of the elements of the second item in each list, which is a list in itself. At present, I have appended each line into a list L so that I for teh above minimal data, I have a list of lists thus: [[14, [25, 105, 104]], [10, [107, 106, 162]], [21, [26, 116, 165]]] I have tried using (a) sorted(L, key = lambda x:(x[0])) and (b) sorted(L, key = lambda x:(sum(x[1]))) and get the anticipated results for (a) and (b0, at least with the above minimal data set. Is this a sensible way to go about the sorting, or are there better ways of doing it in Python? Also, I am baffled because the above fails obviously when len(L) is about a hundred and I can't figure out why. TIA Chandra From jpiitula at ling.helsinki.fi Fri Feb 12 12:48:33 2010 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 12 Feb 2010 19:48:33 +0200 Subject: Bizarre arithmetic results References: <1265849053.24800.38.camel@localhost> Message-ID: Terry Reedy writes: > On 2/12/2010 4:40 AM, Jussi Piitulainen wrote: > > Terry Reedy writes: > >> On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > >>> Robert Kern writes: > >>>> On 2010-02-11 06:31 AM, Shashwat Anand wrote: > >>>>> There is a little issue here that '>>> -.1 ** .1' should give you > >>>>> error message. That is it. > >>>> > >>>> No, fractional powers of negative numbers are perfectly valid > >>>> mathematically. The result is a complex number. In Python 3 (what > >>>> the OP is using), this has been implemented, but not in Python 2.6. > >>> > >>> Perhaps it should raise a MisleadingSpacingError at compile time. > >> > >> You forgot the smiley ;-). > >> > >> > The error message could recommend - .1**.1, or better -(.1 ** .1). > >> > >> The compiler would never see the difference between -.1 ** .1 and the > >> first and probably no difference with the second either. > > > > It could be done the same way that the compiler keeps track of the > > source line numbers now: early phases annotate their output with any > > information that later phases may need. This error would be detected > > during syntactic analysis. > > There is no error to detect. Sorry, read the manual and either learn > or lookup precedence rules (there is a table in the end of the > Expressions chapter) or use parentheses when not sure. Thanks. From cgoldberg at gmail.com Fri Feb 12 13:18:27 2010 From: cgoldberg at gmail.com (corey goldberg) Date: Fri, 12 Feb 2010 10:18:27 -0800 (PST) Subject: PExpect Cross-Platform Alternative References: <348a45771002111147q534fba67m831fbf3961ea55d2@mail.gmail.com> Message-ID: <31a6439e-3832-48c8-b956-3b421b6f5e12@z39g2000vbb.googlegroups.com> > > I was just tasked to get > > these scripts running in a windows environment and to my dismay very > > quickly realized that pexpect is not cross platform compatible. > > Am I stuck, or are there solutions out there? I haven't tried it, but here is another Python implementation of Expect that claims to run on Windows also: http://code.google.com/p/python-expect/ -Corey From python at mrabarnett.plus.com Fri Feb 12 13:24:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 18:24:17 +0000 Subject: Sorting a list of lists In-Reply-To: <4B7593BF.1030708@gmail.com> References: <4B7593BF.1030708@gmail.com> Message-ID: <4B759CD1.4040402@mrabarnett.plus.com> R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I have lines of values like so: > > 14, [25, 105, 104] > 10, [107, 106, 162] > 21, [26, 116, 165] > > I need to sort them in two ways: > > (a) By the numeric value of the first column; and > > (b) by the sum of the elements of the second item in each list, which is > a list in itself. > > At present, I have appended each line into a list L so that I for teh > above minimal data, I have a list of lists thus: > > [[14, [25, 105, 104]], [10, [107, 106, 162]], [21, [26, 116, 165]]] > > I have tried using > > (a) sorted(L, key = lambda x:(x[0])) > > and > > (b) sorted(L, key = lambda x:(sum(x[1]))) > > and get the anticipated results for (a) and (b0, at least with the above > minimal data set. > > Is this a sensible way to go about the sorting, or are there better ways > of doing it in Python? > It's the obvious way to do it. > Also, I am baffled because the above fails obviously when len(L) is > about a hundred and I can't figure out why. > You'd have to post an example of that, but you could try deleting some of the entries before sorting so see whether you can still reproduce the problem with a smaller list. From sparks.m at gmail.com Fri Feb 12 13:32:23 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Fri, 12 Feb 2010 10:32:23 -0800 (PST) Subject: Modifying Class Object References: Message-ID: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Hi Alf, Before I start, note we're talking about semantics, not implementation. That distinction is very important. On Feb 11, 4:49 am, "Alf P. Steinbach" wrote: > > *The* standard general language independent definition? [ of pointer ] > Yes. > > > As defined where? > > For example, as I used as reference in my first posting, the Java language spec. > But it has nothing specifically to do with Java. It is a basic concept in > computer science, that (most) CS students learn in their *first year*. > > E.g. > > > A pointer stores a reference to something. Unfortunately there is no fixed term > for the thing that the pointer points to, and across different computer > languages there is a wide variety of things that pointers point to. We use the > term pointee for the thing that the pointer points to, and we stick to the basic > properties of the pointer/pointee relationship which are true in all languages. > The term "reference" means pretty much the same thing as "pointer" -- > "reference" implies a more high-level discussion, while "pointer" implies the > traditional compiled language implementation of pointers as addresses. For the > basic pointer/pointee rules covered here, the terms are effectively equivalent. > This is where you have gone wrong. You have taken a first year undergraduate academic generalisation and assumed that it applies to The World. In theory, there is no difference between practice and theory, but in practice there is (so the saying goes). The World however has another place for defining terms. That place is of highly varying quality, but generally a better place to correct semantics of terms. Who knows, eventually there may be a single commonly accepted viewpoint. (Which would bring a whole new level of pedantry of course )-: I am referring to Wikipedia here. (this is a vague attempt at humour, rather than an attempt to patronise which it may also come over as) Let's look at the tip of the iceberg for that: "In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address." http://en.wikipedia.org/wiki/Pointer_%28computing%29 Similarly for Call by Value: (which *is* a loaded term) In call-by-value, the argument expression is evaluated, and the resulting value is bound to the corresponding variable in the function (frequently by copying the value into a new memory region). If the function or procedure is able to assign values to its parameters, only its local copy is assigned ? that is, anything passed into a function call is unchanged in the caller's scope when the function returns. http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value Call by Reference: (again, loaded term): In call-by-reference evaluation (also referred to as pass-by- reference), a function receives an implicit reference to the argument, rather than a copy of its value. This typically means that the function can modify the argument- something that will be seen by its caller. http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference Call by Sharing: (far less common term) Also known as "call by object" or "call by object-sharing" is an evaluation strategy first named by Barbara Liskov et al. for the language CLU in 1974[1]. It is used by languages such as Python[2], Iota, Java (for object references)[3], Ruby, Scheme, OCaml, AppleScript, and many other languages. The semantics of call-by-sharing differ from call-by-reference in that assignments to function arguments within the function aren't visible to the caller (unlike by-reference semantics). http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing As you can see, there are generally accepted terms and definitions here, and python is accepted as falling not into the value or reference camp, along with some other languages. Understanding why IMO comes back to some basic aspects of python which I believe trip up experienced developers. This claim is based on talking to someone experienced in coding for a couple of decades, who has done a CS degree (like me), and just didn't understand why I would use python. I spent an couple of _days_ explaining this, along with python's evaluation model, and at the end we ended up where we started: * Python is a language which is focussed on programmer performance, not machine performance, because relative to programmer cost, machines are cheap. Therefore you focus your language to optimise for the programmer, not the machine. In this case, let's drop back to the word "pointer" which I can understand that you like. Indeed, it took me a fair while to let go of the word when talking about python, but you do have to. Why? Well, assume this definition isn't bad: "In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address." OK, let's assume that we can generalise this to ignore the address bit, like so: "In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory" That's still not valid for python - why? Let's keep trimming it back: "A pointer is a programming language data type whose value refers directly to another value" Seems OK. But not valid for python. Why? Let's keep going. "A pointer is a data type whose value" Ah, maybe that is the reason. Let's look at the canonical kind of way of describing what's happening here: >>> x = [1,2,3] >>> def hello(world): ... print world ... >>> hello(x) [1, 2, 3] This is actually alot more complicated to explain than it might seem if someone starts thinking "what's going on underneath". Let's take the description you'd give to a beginner first. (OK, depends on beginner) Beginner description -------------------- A list object is created and initialised containing 3 integers -1,2 & 3. The name x is bound to this list object. Next a function - hello - is defined which takes one argument. When called, the name world is bound to the object passed in. The function body then runs and the object bound to world is used by print to print whatever str(world) returns. The function hello is then called with the value bound to the name x. OK, that seems pretty simple and clear. Little odd in the terminology perhaps, but it's clear. We deal with names and objects. The less beginner explanation ----------------------------- >>> x = [1,2,3] 3 anonymous integer objects are created with the values 1,2 and 3. These are bound inside a sequence which when iterated over yields the 3 integer objects. list is then called with this sequence object (of whatever kind it is under the hood). A list object is then created such that: x[0] appears bound to the integer object 1 x[1] appears bound to the integer object 2 x[2] appears bound to the integer object 3 Note I do NOT say that x[0] contains a reference to object 1, because in languages that contain references you would: a) have access to the reference b) have a means of dereferencing the reference c) Have to dereference the reference in order to obtain the value. This is because a reference is a form of l-value and r-value. It is a value in itself, and refers to a value. Python does not have such a beast. (The closest you can get is a class property, but I digress) In python, the language, we do not have a) or b) nor have to do c). (indeed cannot do "c") Why do I say "appears bound" ? Because x[0] is syntactic sugar to a function call - x.__getitem__(0) So... This results in a list object being created allowing access to 3 integer objects. The name "x" is bound to this list object. >>> def hello(world): ... print world ... This statement (not definition) creates a function object which accepts one argument which will be and object labelled "world" inside the scope of the function. The resulting function object is bound to the name "hello" in the same scope as "x". The resulting function object also has a bunch of other attributes, which I won't go into. >>> hello(x) [1, 2, 3] This is quite complex if you go down this layer. hello is a name bound to the function object we created earlier. Python effectivelly does this: >>> getattr(hello, "__call__") And uses that as the method to call with the arguments provided. Specifically, the object that x is bound to is passed as the sole argument to the __call__ method (wrapper) that getattr(hello, "__call__") returned. The object, not a reference. The object, not a pointer. This is because python's semantics are designed for humans not machines. When applying the object we humans call x to the function object we humans call hello ... >>> def hello(world): ... print world ...inside the scope of the function object, the name world is bound to the object that the calling scope calls x. This may be *implemented* in one runtime using references in one language. It may be *implemented* in another runtime using pointers in another. In PyPy the implementation will be to pass the object by sharing. (I suspect, I've not looked at PyPy's internal's but that's what I'd expect) Anyhow, by hook or by crook, inside hello, the name world is now bound to our previously created list object, which itself has made it such that we can retrieve the 3 integers we asked it to. The print statement evaluates str(world), which evaluates world.__str__(), and passes the resulting string object to the subsystem that actually spits characters out of stdout. That's a significantly more complicated explanation, but still does not need or use the terms pointers or references. The object itself is passed as the argument. The fact that an object may have many names is by the by. Now, you may be asking yourself (indeed I'm certain you may be) "But how is that any difference, really, from pointers and references". Indeed it will seem odd to hear clearly well educated people arguing against you saying "no, they're not pointers or references". It seems odd, primarily because in languages where you have pointers and references, pointers and references are in themselves values. Specifically, in such languages you start talking about l-values and r-values. An r-value is a value that may be assigned to an l-value. An l-value essentially thus denotes storage - a destination for an r-value. An l-values is a machine oriented concept. A name is a human oriented concept. Python doesn't have l-values. It has names, and r-values. A name is just a name, and has no value. When the name is used syntactically, the value (object) it is bound to is used in its place. Thus using your example "demonstrating" that references exist in python is something you're not yourself understanding correctly. Rather than thinking of names as boxes which can contain values, think of them as labels (post it notes) that can be stuck onto values/objects. If you do this, it will simplify your thinking. This was your wording: s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. This is mine: s = ["A"] A list object is created such that the string object "A" can be retrieved from it. The label "s" is stuck on the object. t = s Sticks the label "t" onto the object as well. t[0] = "B" Applies the __setitem__ method of the list object we've created with the integer object 0 and string object "B". (What this does is anyone's guess really, someone could have changed the implementation of list before these 4 lines were executed) print( s ) print takes the list object which s is stuck onto. It then calls the __str__ method of the list object passed it, gets back a string object and spits that out stdout. Whether we chose to use the label s or t is irrelevant, the object _itself_ is passed in. (in terms of semantics) Again, note, we're talking about semantics, not implementation. That distinction is very important. Once again, you might say, "but my explanation works well with references and pointers", and yes in terms of implementation, those things will exist. But if you confuse the implementation as the semantics, you run into problems. For example, going back to your (incorrect) explanation: s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. If t or s are references or pointers, I should be able to deal with the reference or pointer itself as a value. After all accepted definitions of pointer boil down to: "A pointer is a programming language data type whose value refers directly to another value" And similarly for references: "Generally, a reference is a value that enables a program to directly access the particular data item." http://en.wikipedia.org/wiki/Reference#Computer_science ie both pointers and references are themselves values that enable access to the value AND are NOT in themselves the value they point/refer to. In python, if I do this: def hello(world): print world X = [1,2,3] hello(X) Then "X" is best described as a name bound to the object [1,2,3] hello(X) is best described as calling the function bound to the name "hello" with a single argument being the object that the name "X" is bound to. Inside hello, "world" is a name that is bound to whatever object gets slung inside as its first argument. Not a pointer. Not a reference. The object. This semantics is radically different from languages like C, Pascal, and similar. One final approach. Suppose I do this: a = (1,2,3) b = (4,5,6) c = (7,8,9) d = [a, b, c] And I claim that a, b and c are references. (as per your explanation) This would mean that d[2] must also be the same reference as c. (if you take d[2] to be a reference - which it isn't) Therefore updating d[2] must update c. That could imply that d[2] += (10,) Should result in c's reference referring to the value (7,8,9,10) And with D having the value [ (1,2,3), (4,5,6), (7,8,9,10) ] This is perfectly logical semantics if you're dealing with references and pointers. However, python doesn't deal with them. It deals with objects and names. D does indeed result with that value, but c is left unchanged. The reason is because python only has r-values and names, and no l-values. d[2] += (10,) Results in d[2] being evaluated - that is the __getitem__ method on the object d is bound to is called with the argument 2. This returns the tuple object (7,8,9). The __add__ method of that tuple object is then called, with the argument (10,) This returns a new tuple object (7,8,9,10) Finalled the __setitem__ method of the object d is bound to is called with the argument 2 and the freshly minted tuple object (7,8,9,10). This results in c being left unchanged. This results in D having the correct value. If we were dealing with references and pointers it would be perfectly acceptable for c to be modified. In python, the label "c" cannot be tacked onto the returned value. Crucially, a pointer can be a pointer to a pointer, and you can have references to references (which allows you to dereference the pointer/reference and change the pointer/ reference). You can't do this in python names directly. (You can come close using properties, and by messing around in globals and locals, but that's getting quite nasty, and not really the same semantics.) Anyway, I hope you've not found that patronising or ad-hominem. If you've found my explanation overly simplistic or using too simple phrasing, please excuse that - it's a style of writing I've picked up on a writing course once. In summary, if you claim that there's references or pointers here... s = ["A"] t = s # Copies the reference. t[0] = "B" # Changes the referenced object via the reference copy. print( s ) # Inspects object (now changed) via original reference. ... since references and pointers are values themselves, not the values they refer to, how can I store a reference to a reference? That is update the value of s from a function? Specifically, if python has pointers or references, this should be doable: s = 1 # Claim is that s is a reference to 1 update(s, 2) # Update the reference s to point at the value 2 How do I write the function "update" used above in pure python. (without messing with globals(), locals(), or diving into any other language implementation specific concepts) After all, I can write that in any other language that has pointers & references. Finally, note, we're talking about semantics, not implementation. That distinction is very important. If this seems odd, the reason is because python's semantics are very much more like those of a functional language when it comes to function calls, than it is to standard imperative languages. Python's functions are all impure however, and side effects are common, due to objects not (all) being immutable. Your experience here is leading you to the wrong conclusions and incorrect reasoning. Regards, Michael -- http://www.kamaelia.org/ From jjposner at optimum.net Fri Feb 12 13:32:49 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 12 Feb 2010 13:32:49 -0500 Subject: Sorting a list of lists In-Reply-To: <4B7593BF.1030708@gmail.com> References: <4B7593BF.1030708@gmail.com> Message-ID: <4B759ED1.3090507@optimum.net> On 2/12/2010 12:45 PM, R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I have lines of values like so: > > 14, [25, 105, 104] > 10, [107, 106, 162] > 21, [26, 116, 165] > > I need to sort them in two ways: > > (a) By the numeric value of the first column; and > > (b) by the sum of the elements of the second item in each list, which is > a list in itself. > > At present, I have appended each line into a list L so that I for teh > above minimal data, I have a list of lists thus: > > [[14, [25, 105, 104]], [10, [107, 106, 162]], [21, [26, 116, 165]]] > > I have tried using > > (a) sorted(L, key = lambda x:(x[0])) Just plain "sorted(L)" will work, because Python knows how to compare your [N, [N,N,N]]-format values: >>> [14, [25, 105, 104]] < (14, [25, 105, 103]] False >>> [14, [25, 105, 104]] < (14, [25, 105, 105]] True >>> > > and > > (b) sorted(L, key = lambda x:(sum(x[1]))) That looks good. > > and get the anticipated results for (a) and (b0, at least with the above > minimal data set. > > Is this a sensible way to go about the sorting, or are there better ways > of doing it in Python? You're doing fine. > > Also, I am baffled because the above fails obviously when len(L) is > about a hundred and I can't figure out why. Please cut-and-paste the exact error message (or other evidence of "failure") into a message. Tx, John From jjposner at optimum.net Fri Feb 12 13:45:46 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 12 Feb 2010 13:45:46 -0500 Subject: Please help with MemoryError In-Reply-To: <038578a2$0$1277$c3e8da3@news.astraweb.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B75A1DA.5030004@optimum.net> On 2/12/2010 12:14 PM, Steven D'Aprano wrote: > On Fri, 12 Feb 2010 06:45:31 -0800, Jeremy wrote: > >> You also confirmed what I thought was true that all variables are passed >> "by reference" so I don't need to worry about the data being copied >> (unless I do that explicitly). > > No, but yes. > > No, variables are not passed by reference, but yes, you don't have to > worry about them being copied. > > You have probably been mislead into thinking that there are only two > calling conventions possible, "pass by value" and "pass by reference". > That is incorrect. There are many different calling conventions, and > different groups use the same names to mean radically different things. > > If a language passes variables by reference, you can write a "swap" > function like this: > > def swap(a, b): > a, b = b, a > > x = 1 > y = 2 > swap(x, y) > assert (x == 2) and (y==1) > > But this does not work in Python, and cannot work without trickery. So > Python absolutely is not "pass by reference". > > On the other hand, if a variable is passed by value, then a copy is made > and you can do this: > > def append1(alist): > alist.append(1) # modify the copy > return alist > > x = [] > newlist = append1(x) > assert x == [] # The old value still exists. > > But this also doesn't work in Python! So Python isn't "pass by value" > either. > > What Python does is called "pass by sharing", or sometimes "pass by > object reference". It is exactly the same as what (e.g.) Ruby and Java > do, except that confusingly the Ruby people call it "pass by reference" > and the Java people call it "pass by value", thus guaranteeing the > maximum amount of confusion possible. > > > More here: > http://effbot.org/zone/call-by-object.htm > http://en.wikipedia.org/wiki/Evaluation_strategy > Excellent writeup, Steve! You and Jeremy might be interested in a message on "pass-by-XXX" from John Zelle, the author of the textbook "Python Programming: An Introduction to Computer Science". [1] This was part of a long thread in May 2008 on the Python edu-sig list -- nearly as long as "Modifying Class Object", but with nowhere near the fireworks! Tx, John [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html From senhor.abrantes at gmail.com Fri Feb 12 14:12:37 2010 From: senhor.abrantes at gmail.com (joao abrantes) Date: Fri, 12 Feb 2010 19:12:37 +0000 Subject: Pixel control In-Reply-To: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> References: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> Message-ID: <880fa1d41002121112r4e8c1550xf32cdea17a2bfeb@mail.gmail.com> noone knows if it's possible? i really need this.. On Thu, Feb 4, 2010 at 10:57 PM, joao abrantes wrote: > Hello everyone. For example i am using a screen resolution of 800x600 is it > possible to make python control the color of the pixels? For example paint > the pixel (100,200) in red! And it would stay red when i am seeing a > webpage, a movie, playing a game... etc.. Regards, Jo?o Abrantes. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mccolgst at gmail.com Fri Feb 12 14:36:46 2010 From: mccolgst at gmail.com (McColgst) Date: Fri, 12 Feb 2010 11:36:46 -0800 (PST) Subject: search entire drive say c: References: <805f59d51002120417k736230d7yf5b45ee1940e63a7@mail.gmail.com> Message-ID: <8d585aae-2764-4d98-9027-b7d3c9f03b94@p23g2000vbl.googlegroups.com> > ? ?ROOT = "c:\\" > ? ?fname = "abc.txt".lower() > ? ?for p, d, f in os.walk(ROOT): > ? ? ?for fn in f: > ? ? ? ?if fn.lower() == fname: > ? ? ? ? ?print os.path.join(p, f) > ? ? ? ? ?# break I think you mean print os.path.join(p,fn) -sean From mdekauwe at gmail.com Fri Feb 12 14:39:18 2010 From: mdekauwe at gmail.com (Martin) Date: Fri, 12 Feb 2010 11:39:18 -0800 (PST) Subject: Replace various regex Message-ID: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Hi, I am trying to come up with a more generic scheme to match and replace a series of regex, which look something like this... 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) Ideally match the pattern to the right of the "!" sign (e.g. lai), I would then like to be able to replace one or all of the corresponding numbers on the line. So far I have a rather unsatisfactory solution, any suggestions would be appreciated... The file read in is an ascii file. f = open(fname, 'r') s = f.read() if CANHT: s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! canht_ft", CANHT, s) where CANHT might be CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' But this involves me passing the entire string. Thanks. Martin From mccolgst at gmail.com Fri Feb 12 14:57:34 2010 From: mccolgst at gmail.com (McColgst) Date: Fri, 12 Feb 2010 11:57:34 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Message-ID: <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> On Feb 12, 2:39?pm, Martin wrote: > Hi, > > I am trying to come up with a more generic scheme to match and replace > a series of regex, which look something like this... > > 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > would then like to be able to replace one or all of the corresponding > numbers on the line. So far I have a rather unsatisfactory solution, > any suggestions would be appreciated... > > The file read in is an ascii file. > > f = open(fname, 'r') > s = f.read() > > if CANHT: > ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > canht_ft", CANHT, s) > > where CANHT might be > > CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > But this involves me passing the entire string. > > Thanks. > > Martin If I understand correctly, there are a couple ways to do it. One is to use .split() and split by the '!' sign, given that you wont have more than one '!' on a line. This will return a list of the words split by the delimiter, in this case being '!', so you should get back (19.01,16.38,0.79,1.26,1.00 , canht_ft(1:npft) ) and you can do whatever replace functions you want using the list. check out split: http://docs.python.org/library/stdtypes.html#str.split Another, is in your regular expression, you can match the first part or second part of the string by specifying where the '!' is, if you want to match the part after the '!' I would do something like r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- date with my regex syntax, but I think you get the idea.) I hope I understood correctly, and I hope that helps. -sean From mrkafk at gmail.com Fri Feb 12 15:07:08 2010 From: mrkafk at gmail.com (mk) Date: Fri, 12 Feb 2010 21:07:08 +0100 Subject: Please help with MemoryError In-Reply-To: <4B75A1DA.5030004@optimum.net> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: John Posner wrote: >> http://effbot.org/zone/call-by-object.htm >> http://en.wikipedia.org/wiki/Evaluation_strategy > [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html Hmm how about "call by label-value"? That is, you change labels by assignment, but pass the value of the label to a function. Since label value is passed, original label is not changed (i.e. it's not call by reference). However, an object referenced by label value can be changed in Python, like in classic example of list label passed to a function and then this list being modified in a function. Regards, mk From alfps at start.no Fri Feb 12 15:22:02 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 21:22:02 +0100 Subject: Modifying Class Object In-Reply-To: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: * Michael Sparks: > Hi Alf, > > > Before I start, note we're talking about semantics, not > implementation. That distinction is very important. Yes. It would seem to readers that posters here do not grasp and are unable to grasp that distinction. However, all those references to implementation aspects, persisting in the face of corrections, have just, IMHO, been consistent attempts at misrepresentation. > On Feb 11, 4:49 am, "Alf P. Steinbach" wrote: >>> *The* standard general language independent definition? > > [ of pointer ] > >> Yes. >> >>> As defined where? >> For example, as I used as reference in my first posting, the Java language spec. >> But it has nothing specifically to do with Java. It is a basic concept in >> computer science, that (most) CS students learn in their *first year*. >> >> E.g. >> >> >> A pointer stores a reference to something. Unfortunately there is no fixed term >> for the thing that the pointer points to, and across different computer >> languages there is a wide variety of things that pointers point to. We use the >> term pointee for the thing that the pointer points to, and we stick to the basic >> properties of the pointer/pointee relationship which are true in all languages. >> The term "reference" means pretty much the same thing as "pointer" -- >> "reference" implies a more high-level discussion, while "pointer" implies the >> traditional compiled language implementation of pointers as addresses. For the >> basic pointer/pointee rules covered here, the terms are effectively equivalent. >> > > This is where you have gone wrong. You have taken a first year > undergraduate > academic generalisation and assumed that it applies to The World.' I'm sorry to disappoint, but no. It was a random Google hit to find a first-year text that perhaps posters here could understand. Not insinuiting anything about their mental prowess or lack thereof, but just something they might understand given a repeatedly demonstrated inability to understand such basics, or even to understand the concept of reference to a definition of a term. Please do consider that my usage of the term "pointer" has always, in this thread, including the first article I posted in this thread, been with explicit reference to the Java language spec's meaning. You may argue that those who wrote that language spec are confused about things or whatever, but that's rather stretching it, wouldn't you say? > In theory, there is no difference between practice and theory, but in practice > there is (so the saying goes). > > The World however has another place for defining terms. That place is > of highly > varying quality, but generally a better place to correct semantics of > terms. > Who knows, eventually there may be a single commonly accepted > viewpoint. (Which > would bring a whole new level of pedantry of course )-: > > I am referring to Wikipedia here. (this is a vague attempt at humour, > rather > than an attempt to patronise which it may also come over as) I understand. You may note that that Wikipedia article refers to an article that I wrote about pointers in C++. So, this must be the most silly "argument by authority" ever offered. I find that amusing and would have included a smiley except that I think that that would incur further flames. It's no criticism of you; I do appreciate your effort, thanks. And I reiterate that the meaning of "pointer" I have used is the meaning in the Java language spec. And that that's about semantics, not about implementation, and not about C pointers or Pascal pointers or whatever else that some would rather wish it was. [snip] In the following that I snipped you had good discussion except for (as I could see) a fallacy-based denial of references existing in Python. I don't think there's any point in discussing that further, because it's evidently a religious matter where rational arguments -- and I've tried a few -- don't reach, in spite of the extreme triviality of the subject matter. Thanks for the effort at non-flaming discussion, it *is* appreciated. Cheers & hth., - Alf From mwilson at the-wire.com Fri Feb 12 15:22:08 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 12 Feb 2010 15:22:08 -0500 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: mk wrote: > John Posner wrote: > >>> http://effbot.org/zone/call-by-object.htm >>> http://en.wikipedia.org/wiki/Evaluation_strategy > >> [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html > > Hmm how about "call by label-value"? Nothing egregiously wrong with it.. maybe it's a bit wordy. It may be an uphill fight getting it accepted into computer science the way Call by value, Call by reference, Call by sharing, and Call by copy-restore have been (). Mel. > > That is, you change labels by assignment, but pass the value of the > label to a function. Since label value is passed, original label is not > changed (i.e. it's not call by reference). > > However, an object referenced by label value can be changed in Python, > like in classic example of list label passed to a function and then this > list being modified in a function. > > Regards, > mk From alfps at start.no Fri Feb 12 15:26:24 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 21:26:24 +0100 Subject: Modifying Class Object In-Reply-To: <4b75235b$0$23469$426a74cc@news.free.fr> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> Message-ID: * Bruno Desthuilliers: > Alf P. Steinbach a ?crit : > (snip) >> This group has an extraordinary high level of flaming and personal >> attacks > > Oh my... > > (snip remaining non-sense) > > Mr Steinbach, I bet you'll count this as another "flaming" and "personal > attack", but nonetheless : you might have happier time if you were able > to understand the distinction between disagreement and "personal attack". > > (now back to more interesting readings) Yes, I do count this as a personal attack and flaming. The litmus test for that is that it says something very negative about the person you're debating with. In addition, your statement about the earlier attacks on me, is untrue, and your implication that it's only about attacks on me, is untrue. Both of which are very misleading, by the way. I'm assuming that you're intentionally lying. Cheers & hth., - Alf From mdekauwe at gmail.com Fri Feb 12 15:28:48 2010 From: mdekauwe at gmail.com (Martin) Date: Fri, 12 Feb 2010 12:28:48 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> Message-ID: On Feb 12, 7:57?pm, McColgst wrote: > On Feb 12, 2:39?pm, Martin wrote: > > > > > > > Hi, > > > I am trying to come up with a more generic scheme to match and replace > > a series of regex, which look something like this... > > > 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > > 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > > would then like to be able to replace one or all of the corresponding > > numbers on the line. So far I have a rather unsatisfactory solution, > > any suggestions would be appreciated... > > > The file read in is an ascii file. > > > f = open(fname, 'r') > > s = f.read() > > > if CANHT: > > ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > > canht_ft", CANHT, s) > > > where CANHT might be > > > CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > > But this involves me passing the entire string. > > > Thanks. > > > Martin > > If I understand correctly, there are a couple ways to do it. > One is to use .split() and split by the '!' sign, given that you wont > have more than one '!' on a line. This will return a list of the words > split by the delimiter, in this case being '!', so you should get back > (19.01,16.38,0.79,1.26,1.00 ?, ?canht_ft(1:npft) ) ?and you can do > whatever replace functions you want using the list. > > check out split:http://docs.python.org/library/stdtypes.html#str.split > > Another, is in your regular expression, you can match the first part > or second part of the string by specifying where the '!' is, > if you want to match the part after the '!' I would do something like > r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- > date with my regex syntax, but I think you get the idea.) > > I hope I understood correctly, and I hope that helps. > > -sean Hi I like the second suggestion, so this wouldn't rely on me having to match the numbers only the string canht for example but still allow me to replace the whole line, is that what you mean? I tried it and the expression seemed to replace the entire file, so perhaps i am doing something wrong. But in principle I think that might be a better scheme than my current one. i tried if CANHT: #s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! canht_ft", CANHT, s) s = re.sub(r"[^! canht_ft]", CANHT, s) From python at mrabarnett.plus.com Fri Feb 12 15:30:29 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 12 Feb 2010 20:30:29 +0000 Subject: Replace various regex In-Reply-To: <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> Message-ID: <4B75BA65.8000107@mrabarnett.plus.com> McColgst wrote: > On Feb 12, 2:39 pm, Martin wrote: >> Hi, >> >> I am trying to come up with a more generic scheme to match and replace >> a series of regex, which look something like this... >> >> 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) >> 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) >> >> Ideally match the pattern to the right of the "!" sign (e.g. lai), I >> would then like to be able to replace one or all of the corresponding >> numbers on the line. So far I have a rather unsatisfactory solution, >> any suggestions would be appreciated... >> >> The file read in is an ascii file. >> >> f = open(fname, 'r') >> s = f.read() >> >> if CANHT: >> s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! >> canht_ft", CANHT, s) >> >> where CANHT might be >> >> CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' >> >> But this involves me passing the entire string. >> >> Thanks. >> >> Martin > > If I understand correctly, there are a couple ways to do it. > One is to use .split() and split by the '!' sign, given that you wont > have more than one '!' on a line. This will return a list of the words > split by the delimiter, in this case being '!', so you should get back > (19.01,16.38,0.79,1.26,1.00 , canht_ft(1:npft) ) and you can do > whatever replace functions you want using the list. > > check out split: http://docs.python.org/library/stdtypes.html#str.split > The .split method is the best way if you process the file a line at a time. The .split method, incidentally, accepts a maxcount argument so that you can split a line no more than once. > Another, is in your regular expression, you can match the first part > or second part of the string by specifying where the '!' is, > if you want to match the part after the '!' I would do something like > r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- > date with my regex syntax, but I think you get the idea.) > The regex would be r"(?m)^[^!]*(!.*)" to capture the '!' and the rest of the line. > I hope I understood correctly, and I hope that helps. > From subhakolkata1234 at gmail.com Fri Feb 12 15:32:29 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 12 Feb 2010 12:32:29 -0800 (PST) Subject: A silly question on file opening References: Message-ID: <085eb96f-9023-4ef3-af29-95749f62e311@s36g2000prh.googlegroups.com> On Feb 11, 1:57?am, Anthony Tolle wrote: > On Feb 10, 3:42?pm,joy99 wrote: > > > Dear Group, > > [snip] > > I tried to change the location to D:\file and as I saw in Python Docs > > the file reading option is now "r+" so I changed the statement to > > ? ?file_open=open("D:\file","r+") > > but it is still giving error. > > Only use "r+" if you need to also write to the file. ?"r" is still > good for opening for reading. > > Without seeing a traceback, I can only assume the error is caused by > using a backslash in the path without escaping it. ?Try either the > following: > > file_open=open("D:\\file","r+") > > file_open=open(r"D:\file","r+") > > For an explanation, see the Python documentation: > > http://docs.python.org/reference/lexical_analysis.html#string-literals Dear Group, I am sorry I could not report. I was trying your solutions, I could try only one or two, they are working. My problem got solved. Thank you for your suggestions. But soon I find time, I would try all of them, so that I can learn more and what I try to do in this room to get better angles over any problem from experts like you. Thank you for giving me your valuable time despite your busy schedule. Wishing you happy day ahead, Best Regards, Subhabrata. From ethan at stoneleaf.us Fri Feb 12 15:33:28 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 12 Feb 2010 12:33:28 -0800 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: <4B75BB18.7010904@stoneleaf.us> mk wrote: > John Posner wrote: > >>> http://effbot.org/zone/call-by-object.htm >>> http://en.wikipedia.org/wiki/Evaluation_strategy > >> [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html > > Hmm how about "call by label-value"? > > That is, you change labels by assignment, but pass the value of the > label to a function. Since label value is passed, original label is not > changed (i.e. it's not call by reference). > > However, an object referenced by label value can be changed in Python, > like in classic example of list label passed to a function and then this > list being modified in a function. > > Regards, > mk > Because "value" and "reference" are already well defined terms with very definite meanings, I think using them in any way to describe Python's model will lead to confusion. Seems to me that "call by object", a term coined decades ago, and that accurately defines the way that Python (the language) actually does it, should be the term used. My $0.02. ~Ethan~ From ben+python at benfinney.id.au Fri Feb 12 15:41:40 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 13 Feb 2010 07:41:40 +1100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: <87ocjufapn.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > In article , > Lloyd Zusman wrote: > >if (-T $filename) { print "file contains 'text' characters\n"; } > >if (-B $filename) { print "file contains 'binary' characters\n"; } > > Assuming you're on a Unix-like system or can install Cygwin, the > standard response is to use the "file" command. It's *much* more > sophisticated. Indeed, the ?file? command is an expected (though not standard) part of most Unix systems, and its use frees us from the lies of filenames about their contents. The sophistication comes from an extensive database of heuristics ? filesystem attributes, ?magic? content signatures, and parsing ? that are together known as the ?magic database?. This database is maintained along with the ?file? program, and made accessible through a C library from the same code base called ?magic?. So, you don't actually need to use the ?file? command to access this sophistication. Just about every program on a GNU system that wants to display file types, such as the graphical file manager, will query the ?magic? library directly to get the file type. The ?file? code base has for a while now also included a Python interface to this library, importable as the module name ?magic?. Unfortunately it isn't registered at PyPI as far as I can tell. (There are several project using the name ?magic? that implement something similar, but they are nowhere near as sophisticated.) On a Debian GNU/Linux system, you can install the ?python-magic? package to get this installed. Otherwise, you can build it from the ?file? code base . -- \ ?I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.? ?Douglas Adams | Ben Finney From jcquevedo84 at gmail.com Fri Feb 12 15:46:19 2010 From: jcquevedo84 at gmail.com (Juan Carlos Rodriguez) Date: Fri, 12 Feb 2010 08:46:19 -1200 Subject: ImportError: No module named mptest Message-ID: Dear all, I am trying implement a text from mod_python. I have a apahce service 2.2.4, python 2.5 and mod_python 3.3.1 I have this mistake: MOD_PYTHON ERROR ProcessId: 5956 Interpreter: '192.168.5.32' ServerName: '192.168.5.32' DocumentRoot: 'D:/aplicaciones/web' URI: '/python/index.py' Location: None Directory: 'D:/aplicaciones/web/python/' Filename: 'D:/aplicaciones/web/python/index.py' PathInfo: '' Phase: 'PythonHandler' Handler: 'mptest' Traceback (most recent call last): File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch default=default_handler, arg=req, silent=hlist.silent) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1202, in _process_target module = import_module(module_name, path=path) File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 304, in import_module return __import__(module_name, {}, {}, ['*']) ImportError: No module named mptest *WHAT CAN I DO?* -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at cheimes.de Fri Feb 12 15:59:32 2010 From: lists at cheimes.de (Christian Heimes) Date: Fri, 12 Feb 2010 21:59:32 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: mk wrote: > Hmm how about "call by label-value"? Or "call by guido"? How do you like "call like a dutch"? :] From mdekauwe at gmail.com Fri Feb 12 16:02:40 2010 From: mdekauwe at gmail.com (Martin) Date: Fri, 12 Feb 2010 13:02:40 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <479c4f49-ac58-4385-9624-428d4747d9f6@c5g2000vbh.googlegroups.com> Message-ID: On Feb 12, 8:30?pm, MRAB wrote: > McColgst wrote: > > On Feb 12, 2:39 pm, Martin wrote: > >> Hi, > > >> I am trying to come up with a more generic scheme to match and replace > >> a series of regex, which look something like this... > > >> 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > >> 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > >> Ideally match the pattern to the right of the "!" sign (e.g. lai), I > >> would then like to be able to replace one or all of the corresponding > >> numbers on the line. So far I have a rather unsatisfactory solution, > >> any suggestions would be appreciated... > > >> The file read in is an ascii file. > > >> f = open(fname, 'r') > >> s = f.read() > > >> if CANHT: > >> ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > >> canht_ft", CANHT, s) > > >> where CANHT might be > > >> CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > >> But this involves me passing the entire string. > > >> Thanks. > > >> Martin > > > If I understand correctly, there are a couple ways to do it. > > One is to use .split() and split by the '!' sign, given that you wont > > have more than one '!' on a line. This will return a list of the words > > split by the delimiter, in this case being '!', so you should get back > > (19.01,16.38,0.79,1.26,1.00 ?, ?canht_ft(1:npft) ) ?and you can do > > whatever replace functions you want using the list. > > > check out split:http://docs.python.org/library/stdtypes.html#str.split > > The .split method is the best way if you process the file a line at a > time. The .split method, incidentally, accepts a maxcount argument so > that you can split a line no more than once. > > > Another, is in your regular expression, you can match the first part > > or second part of the string by specifying where the '!' is, > > if you want to match the part after the '!' I would do something like > > r"[^! cahnt_ft]", or something similar (i'm not particularly up-to- > > date with my regex syntax, but I think you get the idea.) > > The regex would be r"(?m)^[^!]*(!.*)" to capture the '!' and the rest of > the line. > > > > > I hope I understood correctly, and I hope that helps. I guess I could read the file a line at a time and try splitting it, though I though it would be better to read it all once then search for the various regex I need to match and replace? I am not sure that regex helps, as that would match and replace every line which had a "!". Perhaps if i explain more thoroughly? So the input file looks something like this... 9*0.0 ! canopy(1:ntiles) 12.100 ! cs 0.0 ! gs 9*50.0 ! rgrain(1:ntiles) 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) 9*0.46 ! snow_tile(1:ntiles) 0.46 ! snow_grnd 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) 9*276.78 ! tstar_tile(1:ntiles) 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) So for each of the strings following the "!" I may potentially want to match them and replace some of the numbers. That is I might search for the expression snow_grnd with the intention of substituting 0.46 for another number. What i came up with was a way to match all the numbers and pass the replacement string. From alfps at start.no Fri Feb 12 16:03:47 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 22:03:47 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: * Christian Heimes: > mk wrote: >> Hmm how about "call by label-value"? > > Or "call by guido"? How do you like "call like a dutch"? :] Just a note: it might be more clear to talk about "pass by XXX" than "call by XXX". Unless you're talking about something else than argument passing. The standard terminology is in my view fine. Cheers & hth., - Alf From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 16:33:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 21:33:31 GMT Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> Message-ID: <0385b53b$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 21:07:08 +0100, mk wrote: > John Posner wrote: > >>> http://effbot.org/zone/call-by-object.htm >>> http://en.wikipedia.org/wiki/Evaluation_strategy > >> [1] http://mail.python.org/pipermail/edu-sig/2008-May/008583.html > > Hmm how about "call by label-value"? Python's calling convention already has an well-established name, established over thirty years ago by the distinguished computer scientist Barbara Liskov, namely call-by-sharing. It's also known as "call-by- object-reference". It doesn't need yet another name. -- Steven From solipsis at pitrou.net Fri Feb 12 16:52:34 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 21:52:34 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit?: > > What Python does is called "pass by sharing", or sometimes "pass by > object reference". It is exactly the same as what (e.g.) Ruby and Java > do, except that confusingly the Ruby people call it "pass by reference" > and the Java people call it "pass by value", thus guaranteeing the > maximum amount of confusion possible. Well, I think the Ruby people got it right. Python *does* pass parameters by reference. After all, we even speak about reference counting, reference cycles, etc. So I'm not sure what distinction you're making here. From steve at holdenweb.com Fri Feb 12 17:10:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 17:10:01 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B75D1B9.1050809@holdenweb.com> Antoine Pitrou wrote: > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : >> What Python does is called "pass by sharing", or sometimes "pass by >> object reference". It is exactly the same as what (e.g.) Ruby and Java >> do, except that confusingly the Ruby people call it "pass by reference" >> and the Java people call it "pass by value", thus guaranteeing the >> maximum amount of confusion possible. > > Well, I think the Ruby people got it right. Python *does* pass parameters > by reference. After all, we even speak about reference counting, > reference cycles, etc. > > So I'm not sure what distinction you're making here. > He's distinguishing what Python does from the "call by reference" which has been used since the days of Algol 60. As has already been pointed out, if Python used call by reference then the following code would run without raising an AssertionError: def exchange(a, b): a, b = b, a x = 1 y = 2 exchange(x, y) assert (x == 2 and y == 1) Since function-local assignment always takes place in the function call's local namespace Python does not, and cannot, work like this, and hence the term "call by reference" is inapplicable to Python's semantics. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Fri Feb 12 17:10:01 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 17:10:01 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <4B75D1B9.1050809@holdenweb.com> Antoine Pitrou wrote: > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : >> What Python does is called "pass by sharing", or sometimes "pass by >> object reference". It is exactly the same as what (e.g.) Ruby and Java >> do, except that confusingly the Ruby people call it "pass by reference" >> and the Java people call it "pass by value", thus guaranteeing the >> maximum amount of confusion possible. > > Well, I think the Ruby people got it right. Python *does* pass parameters > by reference. After all, we even speak about reference counting, > reference cycles, etc. > > So I'm not sure what distinction you're making here. > He's distinguishing what Python does from the "call by reference" which has been used since the days of Algol 60. As has already been pointed out, if Python used call by reference then the following code would run without raising an AssertionError: def exchange(a, b): a, b = b, a x = 1 y = 2 exchange(x, y) assert (x == 2 and y == 1) Since function-local assignment always takes place in the function call's local namespace Python does not, and cannot, work like this, and hence the term "call by reference" is inapplicable to Python's semantics. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Fri Feb 12 17:12:06 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 23:12:06 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Antoine Pitrou: > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : >> What Python does is called "pass by sharing", or sometimes "pass by >> object reference". It is exactly the same as what (e.g.) Ruby and Java >> do, except that confusingly the Ruby people call it "pass by reference" >> and the Java people call it "pass by value", thus guaranteeing the >> maximum amount of confusion possible. > > Well, I think the Ruby people got it right. Python *does* pass parameters > by reference. After all, we even speak about reference counting, > reference cycles, etc. > > So I'm not sure what distinction you're making here. Steven talks about the standard meaning of "pass by reference". Essentially that means that you can implement a routine "swap" such that a = 1; b = 2; swap( a, b ) results in a == 2 and b == 1. In Pascal that's 'var' parameters, in C there's no such, in C++ it's reference type parameters using '&' as a type builder, in C# it's 'out' and 'ref' parameters (I think C# has both the most practical and the most elegant implementation, you can see at the call site whether it's by reference), so on. To some degree "pass by reference" is however just a collection of special cases with some similarity. For example, if one says that the guiding principle & main criterion is that one should not have to indicate the pass by reference at the call site, then that would exclude C#. But if one allows some indication at the call site, then that would perhaps include C (applying the & address op), which everyone agrees does not have call by reference. So, to understand the conventional meaning of the term it is perhaps necessary to have some knowledge of all the special cases, like here C# versus C. Cheers & hth., - Alf From steve at holdenweb.com Fri Feb 12 17:17:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 17:17:00 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > You may note that that Wikipedia article refers to an article that I > wrote about pointers in C++. > It's a broken link, referring to a non-existent server. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Fri Feb 12 17:27:19 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 23:27:19 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> You may note that that Wikipedia article refers to an article that I >> wrote about pointers in C++. >> > It's a broken link, referring to a non-existent server. Yes, sorry. It's been that way a long time, and for the same reason my C++ tutorial, the only one linked to from the C++ FAQ, is also off-line. However, if you're interested then copies of the "pointers" doc are likely to be floating around (at one time some mention of it somewhere generated very high traffic over a few weeks, people downloading the PDF, and then I almost reversed my decision not to have ads...). Cheers & hth., - Alf From solipsis at pitrou.net Fri Feb 12 17:27:32 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 22:27:32 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75D1B9.1050809@holdenweb.com> Message-ID: Le Fri, 12 Feb 2010 17:10:01 -0500, Steve Holden a ?crit?: > > As has already been pointed out, if Python used call by reference then > the following code would run without raising an AssertionError: > > def exchange(a, b): > a, b = b, a > > x = 1 > y = 2 > exchange(x, y) > assert (x == 2 and y == 1) > > Since function-local assignment always takes place in the function > call's local namespace I don't think this is related to a difference in parameter passing style. It's just that assignment ("=") means a different thing in Python than in non-object languages (or fake-object languages such as C++ or PHP): it rebinds instead of mutating in-place. If it mutated, you wouldn't have the AssertionError. If you mutate in-place: >>> def exchange(a, b): ... t = a[:] ... a[:] = b ... b[:] = t ... >>> x, y = [1], [2] >>> exchange(x, y) >>> x, y ([2], [1]) Regards Antoine. From solipsis at pitrou.net Fri Feb 12 17:37:55 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 22:37:55 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Le Fri, 12 Feb 2010 23:12:06 +0100, Alf P. Steinbach a ?crit?: > > Steven talks about the standard meaning of "pass by reference". See my answer to Steve's message. You can't postulate a "standard meaning" of "pass by reference" independently of the specificities of each language. For example a "variable" in Python means something different than in non-object languages; it is impossible to have an agnostic definition. In Python and other true object languages, the operations on references (especially assignment) don't have the same semantics as in more archaic languages. This is no reason, IMO, to refuse using the term "pass by reference". The state of art in computing languages evolves, and it wouldn't be constructive to remain stuck with definitions from the 1960s. Regards Antoine. From steve at REMOVE-THIS-cybersource.com.au Fri Feb 12 17:44:52 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 12 Feb 2010 22:44:52 GMT Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> Message-ID: <0385c5f3$0$1277$c3e8da3@news.astraweb.com> On Fri, 12 Feb 2010 21:26:24 +0100, Alf P. Steinbach wrote: > Yes, I do count this as a personal attack and flaming. > > The litmus test for that is that it says something very negative about > the person you're debating with. As negative as accusing somebody of intentionally lying? Or is it only a personal attack when other people dare to disagree with Alf P. Steinbach? > In addition, your statement about the earlier attacks on me, is untrue, > and your implication that it's only about attacks on me, is untrue. Both > of which are very misleading, by the way. I'm assuming that you're > intentionally lying. Get over yourself. You're not so important that everyone is falling over themselves to discredit you by intentional lying. You do bring some technical knowledge and perspectives that is valuable to this community, but it comes with so much spikiness, near-paranoia and Freudian projection that it is extremely unpleasant dealing with you. Since you first came to this community, you have displayed a remarkable ability to take personal offence at virtually every disagreement, a deeply paranoid viewpoint that whenever somebody contradicts your statements they are deliberately lying, and a level of arrogance that is outstanding even for computer science. (How sure of yourself do you have to be to write a textbook for beginners in a language that you yourself are a self-professed beginner in?) I note with interest that this is not the only forum where your reaction to disagreement is to accuse others of deliberate lying. It is a habit of yours, and you've displayed it frequently and repeatedly. For example: http://coding.derkeiler.com/Archive/General/comp.programming/2006-08/msg00139.html http://www.embeddedrelated.com/usenet/embedded/show/43780-20.php http://groups.google.am/group/comp.lang.c++/browse_thread/thread/555331f8dd594837 I'm no longer willing to tolerate the unpleasant attitudes you display. So congratulations Alf. I've only kill-filed one other person on this newsgroup until now. You are now the second. I may reverse it some time in the future, but for now I'm just not interested in your paranoid accusations that others are lying about you and your continual misuse of the term "ad hominem" to refer to any and all criticism of your behaviour. *plonk* -- Steven From rtw at rtw.me.uk Fri Feb 12 17:46:23 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Fri, 12 Feb 2010 16:46:23 -0600 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: hjebbers wrote in news:2864756a-292b-4138-abfd- 3348b72b7e9a at u9g2000yqb.googlegroups.com in comp.lang.python: > the information about the error is a windows dump. This may help: # http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx SEM_FAILCRITICALERRORS = 1 SEM_NOALIGNMENTFAULTEXCEPT = 4 SEM_NOGPFAULTERRORBOX = 4 SEM_NOOPENFILEERRORBOX = 8 import ctypes from ctypes.wintypes import UINT SetErrorMode = ctypes.windll.kernel32.SetErrorMode SetErrorMode.restype = UINT SetErrorMode.argtypes = ( UINT,) Then putting: SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX ) at the start of you programme, should stop the "Critical Error" dialog box you are seeing and you may get a chance to see a traceback. Rob. From alfps at start.no Fri Feb 12 17:49:38 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 12 Feb 2010 23:49:38 +0100 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Antoine Pitrou: > Le Fri, 12 Feb 2010 23:12:06 +0100, Alf P. Steinbach a ?crit : >> Steven talks about the standard meaning of "pass by reference". > > See my answer to Steve's message. You can't postulate a "standard > meaning" of "pass by reference" independently of the specificities of > each language. Agreed. See e.g. my discussion of C versus C# in the article you responded to. > For example a "variable" in Python means something > different than in non-object languages; it is impossible to have an > agnostic definition. It's possible and relatively speaking easy, but it's bound up with such a tangle of terminological and religious issues that it's best not discussed here. :-( But if you find/have a description that helps you understand what's going on, and that correctly predicts the effect of code, then just Use It. :-) After all, learning some "simpler" description would at that point just be more work. > In Python and other true object languages, the operations on references > (especially assignment) don't have the same semantics as in more archaic > languages. This is no reason, IMO, to refuse using the term "pass by > reference". The state of art in computing languages evolves, and it > wouldn't be constructive to remain stuck with definitions from the 1960s. The main reason for not using that term for Python is that "pass by reference" has the extremely strong connotation of being able to implement 'swap'. And since there already is adequate standard terminology, why confuse things. Cheers & hth., - Alf From g.bogle at auckland.no.spam.ac.nz Fri Feb 12 18:18:48 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 13 Feb 2010 12:18:48 +1300 Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > def swap(a, b): > a, b = b, a > > x = 1 > y = 2 > swap(x, y) > assert (x == 2) and (y==1) Can't the same point be more simply made with this example: def setval(a): a = 12345 x = 1 setval(x) print x ? From steve at holdenweb.com Fri Feb 12 18:26:57 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 18:26:57 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Gib Bogle wrote: > Steven D'Aprano wrote: > >> def swap(a, b): >> a, b = b, a >> >> x = 1 >> y = 2 >> swap(x, y) >> assert (x == 2) and (y==1) > > Can't the same point be more simply made with this example: > > def setval(a): > a = 12345 > > x = 1 > setval(x) > print x > Yes, and it will doubtless be subject to exactly the same bogus refutations. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From solipsis at pitrou.net Fri Feb 12 18:30:12 2010 From: solipsis at pitrou.net (Antoine Pitrou) Date: Fri, 12 Feb 2010 23:30:12 +0000 (UTC) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: Le Fri, 12 Feb 2010 23:49:38 +0100, Alf P. Steinbach a ?crit?: > > The main reason for not using that term for Python is that "pass by > reference" has the extremely strong connotation of being able to > implement 'swap'. But 'swap' is so easy to write as a one-line statement that it's foolish to want to make a Python function for it... cheers Antoine. From alfps at start.no Fri Feb 12 18:47:56 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 00:47:56 +0100 Subject: Modifying Class Object In-Reply-To: <0385c5f3$0$1277$c3e8da3@news.astraweb.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Fri, 12 Feb 2010 21:26:24 +0100, Alf P. Steinbach wrote: > >> Yes, I do count this as a personal attack and flaming. >> >> The litmus test for that is that it says something very negative about >> the person you're debating with. > > As negative as accusing somebody of intentionally lying? > > Or is it only a personal attack when other people dare to disagree with > Alf P. Steinbach? Do you mean that everybody else is allowed to get personal, but I, in return, am not so allowed? >> In addition, your statement about the earlier attacks on me, is untrue, >> and your implication that it's only about attacks on me, is untrue. Both >> of which are very misleading, by the way. I'm assuming that you're >> intentionally lying. > > Get over yourself. You're not so important that everyone is falling over > themselves to discredit you by intentional lying. This implies something about my beliefs about my importance, that is, it is clearly intended as an ad hominem attack. I'm getting a bit tired of that. > You do bring some technical knowledge and perspectives that is valuable to > this community, but it comes with so much spikiness, near-paranoia and > Freudian projection that it is extremely unpleasant dealing with you. > > Since you first came to this community, you have displayed a remarkable > ability to take personal offence at virtually every disagreement, That is not true. I do take offense at pure personal attacks, though. Personal attacks are about person, technical discussion is about technical things. > a deeply paranoid viewpoint that whenever somebody contradicts your > statements they are deliberately lying, That's just stupid, sorry. Being paranoid is not about being attacked, or about pointing out when someone's lying. Hello. > and a level of arrogance that is > outstanding even for computer science. (How sure of yourself do you have > to be to write a textbook for beginners in a language that you yourself > are a self-professed beginner in?) > > I note with interest that this is not the only forum where your reaction > to disagreement is to accuse others of deliberate lying. Your argument gets a bit circular. > It is a habit of yours, That is untrue. > and you've displayed it frequently No, that is untrue. > and repeatedly. Yes, I have repeatedly pointed when people have been lying, citing the evidence and logic leading to that conclusion. I wouldn't just "accuse" someone of something like that. It's far too serious (however, above you're happy with accusing me of being paranoid and whatever, so I conclude that you have no such qualms). > For example: > > http://coding.derkeiler.com/Archive/General/comp.programming/2006-08/msg00139.html > > http://www.embeddedrelated.com/usenet/embedded/show/43780-20.php > > http://groups.google.am/group/comp.lang.c++/browse_thread/thread/555331f8dd594837 Yes, I've been on the net a long time, and consequently I have been involved in flame wars. :-)[1] That is no excuse for your behavior. An extremely long thread dedicated to the notion that there are no references in Python (which is blatantly false), coupled with personal attacks on the one person arguing that there are. I could easily think that you were having me on. Of course most anyone else who'd hold the rational opinion would not join the battlefield, because it clearly wasn't and isn't about convincing or educating anyone, but I feel that follow-ups to my articles should be answered. Cheers & hth., - Alf Notes: [1] Like one here where some guy A objects to some other guy B's use of the term "portable assembler" about C, where at first I try to defend B's point of view, since it is after all one employed even by the creators of C. B sensibly opts out of the discussion while I stay on, predictable result. Another flame war is with some functional programming fanatic, and a third with a known troll. From greg.ewing at canterbury.ac.nz Fri Feb 12 18:55:42 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Feb 2010 12:55:42 +1300 Subject: Please help with MemoryError In-Reply-To: <0385b53b$0$1277$c3e8da3@news.astraweb.com> References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75A1DA.5030004@optimum.net> <0385b53b$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7tm7g9Fu56U1@mid.individual.net> Steven D'Aprano wrote: > Python's calling convention already has an well-established name, > established over thirty years ago by the distinguished computer scientist > Barbara Liskov, namely call-by-sharing. And she was mistaken in thinking it needed a new name. -- Greg From jim.hefferon at gmail.com Fri Feb 12 19:02:12 2010 From: jim.hefferon at gmail.com (Jim) Date: Fri, 12 Feb 2010 16:02:12 -0800 (PST) Subject: intolerant HTML parser References: <735ba42e-e50a-4b08-a8b2-7228971aa50e@z41g2000yqz.googlegroups.com> <4b6fd672$0$6734$9b4e6d93@newsspool2.arcor-online.net> <4b6fe93d$0$6724$9b4e6d93@newsspool2.arcor-online.net> <4b712919$0$6584$9b4e6d93@newsspool3.arcor-online.net> Message-ID: I want to thank everyone for the help, which I found very useful (the parts that I understood :-) ). Since I think there was some question, it happens that I am working under django and submitting a certain form triggers an html mail. I wanted to validate the html in some of my unit tests. It is only about 30 lines of html so I think I'll take a pass on automated html generation, but FWIW the intolerant parser found a couple of errors. Thanks again, Jim From rantingrick at gmail.com Fri Feb 12 19:05:45 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Feb 2010 16:05:45 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: On Feb 12, 4:10?pm, Steve Holden wrote: > Antoine Pitrou wrote: > > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : On Feb 12, 4:10?pm, Steve Holden wrote: > Antoine Pitrou wrote: > > Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : Steve, Why do so many of your posts come in as doubles and triples. Is this a case of "studdering click finger" of some fault of your newsreader? -- concerned fellow pythonista... From kevin.p.dwyer at gmail.com Fri Feb 12 19:18:43 2010 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sat, 13 Feb 2010 00:18:43 +0000 (UTC) Subject: Configuring apache to execute python scripts using mod_python handler References: Message-ID: On Fri, 12 Feb 2010 13:08:59 -0400, Juan Carlos Rodriguez wrote: Hello Juan Carlos, You're better off raising this on the mod_python list, however... Python is looking for a module called mptest, and cannot find it. Have you created the mptest.py module? (It should contain the handler function in your item (2)). Is it on the python path used by the webserver? See for example the last post at http://forums.devshed.com/apache-development-15/installing-python-on-apache-42184.html which shows how you can set up the path. Cheers, Kev From m.echavarriagregory at umiami.edu Fri Feb 12 19:21:22 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Fri, 12 Feb 2010 19:21:22 -0500 Subject: MemoryError, can I use more? Message-ID: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Dear group: I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... Thanks, Angelica. From robert.kern at gmail.com Fri Feb 12 19:31:15 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 12 Feb 2010 18:31:15 -0600 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-12 17:30 PM, Antoine Pitrou wrote: > Le Fri, 12 Feb 2010 23:49:38 +0100, Alf P. Steinbach a ?crit : >> >> The main reason for not using that term for Python is that "pass by >> reference" has the extremely strong connotation of being able to >> implement 'swap'. > > But 'swap' is so easy to write as a one-line statement that it's foolish > to want to make a Python function for it... Yes, but that's besides the point. The exercise at hand is to classify the semantic behavior of the function call syntax with respect to its arguments. Being able to implement swap() as a function is a distinguishing feature of the kind of function call semantics that the computer science community has named "call by reference." -- 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 aahz at pythoncraft.com Fri Feb 12 19:35:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 16:35:19 -0800 Subject: Dreaming of new generation IDE References: Message-ID: In article , Steve Holden wrote: >bartc wrote: >> "Arnaud Delobelle" wrote in message >> news:m28wb6ypfs.fsf at googlemail.com... >>> "Gabriel Genellina" writes: >>>> >>>> Note the *literal* part. If you (the programmer) is likely to know the >>>> parameter value when writing the code, then the function is actually two >>>> separate functions. >>> >>> Thanks, I understand what Steve Holden meant now. >> >> I've just noticed that 'literal' part. But I think I still disagree. >> >> For a real-world example, it means instead of having a room with a >> light-switch in it, if I *know* I want the light on or off, I should >> have two rooms: one with the light permanently on, and one with it >> permanently off, and just walk into the right one. > >Congratulations. That has to be the most bogus analogy I've seen on >c.l.py this year. Aww, c'mon, it's less than two months into the year, don't be so hyperbolic. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From gagsl-py2 at yahoo.com.ar Fri Feb 12 19:41:16 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 21:41:16 -0300 Subject: pyparsing wrong output References: <692c428f1002120541n6b3aabb0jb62c50f90715f38e@mail.gmail.com> Message-ID: En Fri, 12 Feb 2010 10:41:40 -0300, Eknath Venkataramani escribi?: > I am trying to write a parser in pyparsing. > Help Me. http://paste.pocoo.org/show/177078/ is the code and this is > input > file: http://paste.pocoo.org/show/177076/ . > I get output as: > There is nothing wrong with pyparsing here. scanString() returns a generator, like this: py> g = (x for x in range(20) if x % 3 == 1) py> g at 0x00E50D78> A generator is like a function that may be suspended and restarted. It yields one value at a time, and only runs when you ask for the next value: py> next(g) 1 py> next(g) 4 You may use a `for` loop to consume the generator: py> for i in g: ... print i ... 7 10 13 16 19 Once it run to exhaustion, asking for more elements always raises StopIteration: py> next(g) Traceback (most recent call last): File "", line 1, in StopIteration Try something like this: results = x.scanString(filedata) for result in results: print result See http://docs.python.org/tutorial/classes.html#generators -- Gabriel Genellina From ckaynor at zindagigames.com Fri Feb 12 19:44:57 2010 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Fri, 12 Feb 2010 16:44:57 -0800 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: A 32 bit app can only use 4 GB of memory itself (regardless of the amount of system ram), the OS claims some of this for the system, dlls occupy some of it, etc. As such, the app can only really use a smaller subset (generally between 2 to 3 GB, depending upon the app and the OS). Chris On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica < m.echavarriagregory at umiami.edu> wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount > of data it works with is huge. I have managed to keep memory footprint low, > but have found that, independent of the physical RAM of the machine, python > always gives the MemoryError message when it has occupied exactly only 2.2 > GB. I have tested this in 4 different machines, all with memory of 3 to 4 > GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I > typed help(MemoryError) and it is a class itself, but that help told me > nothing I can use... > > Thanks, > Angelica. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Fri Feb 12 19:45:02 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 12 Feb 2010 19:45:02 -0500 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: [...] > Of course most anyone else who'd hold the > rational opinion would not join the battlefield, because it clearly > wasn't and isn't about convincing or educating anyone, but I feel that > follow-ups to my articles should be answered. > In other words, you must have the last word, a behavioral characteristic I will avoid drawing the obvious conclusions about for fear of begin accused (yet again) of making ad hominem attacks. I suppose you will therefore be unable to resist the temptation to respond to this. Though I'd love to be proved wrong again. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From breamoreboy at yahoo.co.uk Fri Feb 12 19:48:27 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 00:48:27 +0000 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Fri, 12 Feb 2010 21:26:24 +0100, Alf P. Steinbach wrote: >> >>> Yes, I do count this as a personal attack and flaming. >>> >>> The litmus test for that is that it says something very negative about >>> the person you're debating with. >> >> As negative as accusing somebody of intentionally lying? >> >> Or is it only a personal attack when other people dare to disagree >> with Alf P. Steinbach? > > Do you mean that everybody else is allowed to get personal, but I, in > return, am not so allowed? > > >>> In addition, your statement about the earlier attacks on me, is untrue, >>> and your implication that it's only about attacks on me, is untrue. Both >>> of which are very misleading, by the way. I'm assuming that you're >>> intentionally lying. >> >> Get over yourself. You're not so important that everyone is falling >> over themselves to discredit you by intentional lying. > > This implies something about my beliefs about my importance, that is, it > is clearly intended as an ad hominem attack. > > I'm getting a bit tired of that. > > > >> You do bring some technical knowledge and perspectives that is >> valuable to >> this community, but it comes with so much spikiness, near-paranoia and >> Freudian projection that it is extremely unpleasant dealing with you. >> >> Since you first came to this community, you have displayed a >> remarkable ability to take personal offence at virtually every >> disagreement, > > That is not true. > > I do take offense at pure personal attacks, though. > > Personal attacks are about person, technical discussion is about > technical things. > > > >> a deeply paranoid viewpoint that whenever somebody contradicts your >> statements they are deliberately lying, > > That's just stupid, sorry. > > Being paranoid is not about being attacked, or about pointing out when > someone's lying. > > Hello. > > >> and a level of arrogance that is outstanding even for computer >> science. (How sure of yourself do you have to be to write a textbook >> for beginners in a language that you yourself are a self-professed >> beginner in?) >> >> I note with interest that this is not the only forum where your >> reaction to disagreement is to accuse others of deliberate lying. > > Your argument gets a bit circular. > > > >> It is a habit of yours, > > That is untrue. > > >> and you've displayed it frequently > > No, that is untrue. > > >> and repeatedly. > > Yes, I have repeatedly pointed when people have been lying, citing the > evidence and logic leading to that conclusion. > > I wouldn't just "accuse" someone of something like that. > > It's far too serious (however, above you're happy with accusing me of > being paranoid and whatever, so I conclude that you have no such qualms). > > >> For example: >> >> http://coding.derkeiler.com/Archive/General/comp.programming/2006-08/msg00139.html >> >> >> http://www.embeddedrelated.com/usenet/embedded/show/43780-20.php >> >> http://groups.google.am/group/comp.lang.c++/browse_thread/thread/555331f8dd594837 >> > > Yes, I've been on the net a long time, and consequently I have been > involved in flame wars. :-)[1] > > That is no excuse for your behavior. > > An extremely long thread dedicated to the notion that there are no > references in Python (which is blatantly false), coupled with personal > attacks on the one person arguing that there are. I could easily think > that you were having me on. Of course most anyone else who'd hold the > rational opinion would not join the battlefield, because it clearly > wasn't and isn't about convincing or educating anyone, but I feel that > follow-ups to my articles should be answered. > > > Cheers & hth., > > - Alf > > > Notes: > [1] Like one here where some guy A objects to some other guy B's use of > the term "portable assembler" about C, where at first I try to defend > B's point of view, since it is after all one employed even by the > creators of C. B sensibly opts out of the discussion while I stay on, > predictable result. Another flame war is with some functional > programming fanatic, and a third with a known troll. I'm intrigued by your comments over the last couple of weeks, as you obviously know so much more about Python than people who have been working on it and/or using it for the 20 odd years of the existence of the language. Is it safe to assume that shortly you will be telling the scientific community that Einstein was a complete bozo and that his theory of relativity is crap, or that Stephen (Bob?) Hawking knows nothing about the origins of the universe? To put it another way, please stand up Alf, your voice is rather muffled. And this isn't an ad hominem attack, whatever the hell that means, I (NOTE I ) personally wish you'd bugger off and leave the bandwidth to people who genuinely want to discuss Python, computing algorithms, whatever. And please do NOT bother to reply. Your pathetic smileys and/or HTH garbage cut no ice with me. I'm quite simply staggered that the Python community as a whole have shown far more patience than I have, otherwise you'd have been shot down in seriously bad flames days ago. To you, Alf, get stuffed. To the rest of the Python community, thank you for doing a fantastic job, I do appreciate it, and am currently in my own little way attempting to put something back in. Regards. Mark Lawrence. From greg.ewing at canterbury.ac.nz Fri Feb 12 19:55:46 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 13 Feb 2010 13:55:46 +1300 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> <4B75D1B9.1050809@holdenweb.com> Message-ID: <7tmb0tFektU1@mid.individual.net> Antoine Pitrou wrote: > It's just that assignment ("=") means a different thing in Python than in > non-object languages (or fake-object languages such as C++ or PHP): it > rebinds instead of mutating in-place. If it mutated, you wouldn't have > the AssertionError. It doesn't really have anything to do with assignment semantics. The essence of pass-by-reference is that the formal parameter name becomes an alias for the actual parameter in all respects. Whatever the semantics of assignment, you can come up with variations of the language that either do or don't support pass-by-reference in this sense. It's an orthogonal issue. -- Greg From ssteinerx at gmail.com Fri Feb 12 19:58:26 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Fri, 12 Feb 2010 19:58:26 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: <6546CE32-E9EA-4E33-9C7B-8A9808A4A083@gmail.com> On Feb 12, 2010, at 7:21 PM, Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... How are you determining that it has occupied "exactly only 2.2GB?" S From breamoreboy at yahoo.co.uk Fri Feb 12 20:00:47 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 01:00:47 +0000 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... > > Thanks, > Angelica. Please check the archives for the thread Please help with MemoryError, it was only posted a day or two back. It's a problem specific to Windows. Kindest regards. Mark Lawrence. From gagsl-py2 at yahoo.com.ar Fri Feb 12 20:03:04 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 22:03:04 -0300 Subject: Helpp I want view page .py on apache WHAT CAN I DO??????????????? References: Message-ID: Hola! En Fri, 12 Feb 2010 14:34:33 -0300, Juan Carlos Rodriguez escribi?: > ImportError: No module named mptest Hay una lista en castellano sobre Python: http://python.org.ar/pyar/ListaDeCorreo -- Gabriel Genellina From aahz at pythoncraft.com Fri Feb 12 20:06:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 17:06:49 -0800 Subject: Dreaming of new generation IDE References: <4b743340$0$20738$426a74cc@news.free.fr> Message-ID: In article <4b743340$0$20738$426a74cc at news.free.fr>, Bruno Desthuilliers wrote: > >Ever read "worst is better" ?-) Nope -- maybe you mean "worse is better"? http://www.jwz.org/doc/worse-is-better.html (Nitpicking because you need the correct term to search.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From benjamin.kaplan at case.edu Fri Feb 12 20:14:46 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 12 Feb 2010 20:14:46 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: On Fri, Feb 12, 2010 at 7:21 PM, Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... > > Thanks, > Angelica. There's nothing you can do in Python to fix it. A MemoryError means that Python asked the OS to malloc something and it refused to give it any more memory. In this case, it's because Windows will only allocate 2GB of RAM to a single process. There is a way to extend that to 3GB, but I don't quite understand how to do it- something about setting linker flags. Easiest way to handle this would be to switch to a 64-bit Python on a 64-bit platform. That way, you can use up to 8TB of memory. http://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx#memory_limits > -- > http://mail.python.org/mailman/listinfo/python-list > From alfps at start.no Fri Feb 12 20:29:42 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 02:29:42 +0100 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: * Mark Lawrence: > Alf P. Steinbach wrote: >> >> An extremely long thread dedicated to the notion that there are no >> references in Python (which is blatantly false), coupled with personal >> attacks on the one person arguing that there are. I could easily think >> that you were having me on. Of course most anyone else who'd hold the >> rational opinion would not join the battlefield, because it clearly >> wasn't and isn't about convincing or educating anyone, but I feel that >> follow-ups to my articles should be answered. [snippety] > > I'm intrigued by your comments over the last couple of weeks, as you > obviously know so much more about Python than people who have been > working on it and/or using it for the 20 odd years of the existence of > the language. I don't. On the other hand, it's a fallacy to think other people must be perfect. The glossary of my Python 3.1.1 documentation defines "Reference count: The number of references to an object. [...]" And so arguing against the existence of assignable references in Python would be silly if it was a genuine technical discussion. But I suspect that, in spite of my /first article's/ reference and frequent later references to term definitions etc., many who posted in this thread thought they were arguing against some other point of view, in the frenzy not bothering to check out things or actually /read/ what they replied to. So, as demonstrated, assuming that you were referring to people participating in this thread, people who have used a language for 20 odd years can still be wrong about something -- even when that something is utterly trivial. > Is it safe to assume that shortly you will be telling the > scientific community that Einstein was a complete bozo and that his > theory of relativity is crap, or that Stephen (Bob?) Hawking knows > nothing about the origins of the universe? > > To put it another way, please stand up Alf, your voice is rather > muffled. And this isn't an ad hominem attack Your response *is not* a personal attack? Then why are you trying to imply all kinds of things about my person, and not mentioning anything technical? Is there anything in the above, about assignable references, that you really think is on a par with relativity and requires Einstein's genius to understand? >, whatever the hell that > means, I (NOTE I ) personally wish you'd bugger off and leave the > bandwidth to people who genuinely want to discuss Python, computing > algorithms, whatever. > > And please do NOT bother to reply. Your pathetic smileys and/or HTH > garbage cut no ice with me. I'm quite simply staggered that the Python > community as a whole have shown far more patience than I have, otherwise > you'd have been shot down in seriously bad flames days ago. > > To you, Alf, get stuffed. Are you sure that this is not a personal attack? Just curious how you manage to think it couldn't be. Cheers & hth., ;-) - Alf From aahz at pythoncraft.com Fri Feb 12 20:32:26 2010 From: aahz at pythoncraft.com (Aahz) Date: 12 Feb 2010 17:32:26 -0800 Subject: Calendar GUI References: <42f7d5c51002051608u38e6a3bbt2a07dcf330acf92@mail.gmail.com> <4B6D055A.30901@gmail.com> Message-ID: In article , wrote: > >Take a look at wxscheduler, and chandler. You're joking about Chandler, right? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From gagsl-py2 at yahoo.com.ar Fri Feb 12 20:36:42 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 22:36:42 -0300 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> Message-ID: En Fri, 12 Feb 2010 11:22:40 -0300, Aahz escribi?: > In article , > Dennis Lee Bieber wrote: >> On 11 Feb 2010 21:18:26 -0800, aahz at pythoncraft.com (Aahz) declaimed the >> following in gmane.comp.python.general: >>> In article , >>> Gabriel Genellina wrote: >>>> >>>> Strange. With Python 2.6.4 I don't need to do that; I'd say the >>>> difference >>>> is in the OS or antivirus (some AV are known to break the TCP stack). >>> >>> Perhaps, but I've also found that ctrl-C doesn't work on Windows. >> >> Unless the running program makes an I/O call to the console, I don't >> think gets past the device driver... > > That's probably it. It's more annoying for me because I run Windows with > a VM on a Mac, which doesn't have ctrl-break. On a "real" PC with Windows XP SP3 and Python 2.6.4, with an idle server, just hitting Ctrl-C was enough: D:\temp>python -m SimpleXMLRPCServer Running XML-RPC server on port 8000 Traceback (most recent call last): File "d:\apps\python26\lib\runpy.py", line 122, in _run_module_as_main "__main__", fname, loader, pkg_name) File "d:\apps\python26\lib\runpy.py", line 34, in _run_code exec code in run_globals File "d:\apps\python26\lib\SimpleXMLRPCServer.py", line 615, in server.serve_forever() File "d:\apps\python26\lib\SocketServer.py", line 224, in serve_forever r, w, e = select.select([self], [], [], poll_interval) KeyboardInterrupt A slightly more realistic example: a busy, single threaded server. I had to hit Ctrl-C twice: the first time, KeyboardInterrupt was sent as a Fault response to the client. import sys def busy(): x = 50000 y = x**x return "Ok" if sys.argv[1]=='server': import SimpleXMLRPCServer server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000),logRequests=False) server.register_function(busy) server.serve_forever() else: import xmlrpclib proxy = xmlrpclib.ServerProxy("http://localhost:8000/") while True: print "client", proxy.busy() Maybe the OP's code containes a bare 'except:' clause that swallows KeyboardInterrupt, or the server is so busy that is always executing a function handler (and all KeyboardInterrupt become Fault and are sent as a function response). Mmm, perhaps that's a bug, a KeyboardInterrupt should bubble up to the server code, not being treated as an error in computing the function result. -- Gabriel Genellina From lists at cheimes.de Fri Feb 12 20:42:59 2010 From: lists at cheimes.de (Christian Heimes) Date: Sat, 13 Feb 2010 02:42:59 +0100 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> Message-ID: Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. The amount of RAM in your boxes is unrelated to your issue. A 32bit process is able to address only 4GB of virtual memory because it has no way to access memory addresses beyond the 32bit border. Large amount of the address space are reserved for multiple purposes like error checking (e.g. the NULL pointer), the entry point of the program, its stack and address space for reallocating dynamic linked libraries. On modern Linux systems the space for the heap is about 2.6 to 2.7 GB large. The heap is the memory segment used by malloc() and friends. It looks like the memory segment for the heap is slightly smaller on Windows. Virtual memory isn't the same as resident memory. A program may only occupy 100 MB in your RAM (resident memory) but it may use 1.5 GB of virtual memory. Virtual memory takes memory fragmentation and unused pages into account. If you malloc() 1 GB memory but just file up the first byte your program requires 1 GB of virtual memory but only a few KB resident memory. At least that's the story on Linux and several other Unix-like OSes. I'm not sure how Windows deals with memory. If your program needs more than 2 GB of RAM you should switch to a 64bit OS and a 64bit version of Python. Windows AMD64 builds for Python are available on python. Christian From gagsl-py2 at yahoo.com.ar Fri Feb 12 20:48:30 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 22:48:30 -0300 Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle escribi?: > I posted an example of a decorator that does just this in this thread a > couple of days ago: > > http://mail.python.org/pipermail/python-list/2010-February/1235742.html Ouch! I didn't see your post, nor several other earlier posts in this thread. In fact, I thought mine was the *first* reply when I wrote it! Yes, of course, your code does exactly that without any bytecode hacks. -- Gabriel Genellina From gagsl-py2 at yahoo.com.ar Fri Feb 12 21:08:49 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Fri, 12 Feb 2010 23:08:49 -0300 Subject: Pixel control References: <880fa1d41002041457v44b7c4ddobe79db5fc7c9ebd5@mail.gmail.com> <880fa1d41002121112r4e8c1550xf32cdea17a2bfeb@mail.gmail.com> Message-ID: En Fri, 12 Feb 2010 16:12:37 -0300, joao abrantes escribi?: > noone knows if it's possible? i really need this.. > > On Thu, Feb 4, 2010 at 10:57 PM, joao abrantes > wrote: > >> Hello everyone. For example i am using a screen resolution of 800x600 >> is it >> possible to make python control the color of the pixels? For example >> paint >> the pixel (100,200) in red! And it would stay red when i am seeing a >> webpage, a movie, playing a game... etc.. First investigate how you could do such thing using whichever technology is needed, and only then, ask how you could do *that* in Python. -- Gabriel Genellina From gre1600 at gmail.com Fri Feb 12 21:18:26 2010 From: gre1600 at gmail.com (felix gao) Date: Fri, 12 Feb 2010 18:18:26 -0800 Subject: ConfigParser is not parsing Message-ID: Hi all, I am trying to get the some configuration file read in by Python, however, after the read command it return a list with the filename that I passed in. what is going on? Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import ConfigParser >>> p = ConfigParser.SafeConfigParser() >>> cfg = p.read("S3Files.conf") >>> cfg ['S3Files.conf'] cat S3Files.conf [main] taskName=FileConfigDriver lastProcessed=2010-01-31 dateFromat=%Y-%m-%d skippingValue=86400 skippingInterval=seconds Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rantingrick at gmail.com Fri Feb 12 21:23:46 2010 From: rantingrick at gmail.com (rantingrick) Date: Fri, 12 Feb 2010 18:23:46 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> Message-ID: <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> This entire thread has imploded like a neutron star into an infantile debate that only Caddie Couric, Bill O Reilly, and everyone on PMS-NBC can hold a candle to! The only post i enjoyed was Steve Howes! >From my unique perspective of not really knowing (or for that matter) really caring about any of you i can say *some* of you have most undoubly shown your true colors in this thread! First of all, we all know how D Aprano has such an unfettered ego problem. I myself have been the victom of his insults but simultaniously also found them quite enjoyable (at times) I'd classify Steven d'Aprano as a "well informed" arsehole with an inner clown trying to escape. Then there is "alex23". The only sockpuppet (of many suspects within this group) that i can 100 percent prove and of whom i knew sooner or later would come along for his chance at trolling. Just look at his GG cache and you will see 99% of his post are argmentitve, abusive trolls! He's a fish that waits for threads like these just so he can flop around! As for Alf, no he is not *tecnically* right about the definition of "ad homine" but that *really* doesn't matter. He has (time and time again) been personally attacked by some of the more "supposedly respected" people in this group. And as always the roaches start coming out of the woodwork in a most "pathetic puppy dog" way. What would you puppets do if there were no one to pull your strings? But the most nortoriuos behavior of all belongs to none other that the PSF chairman himself! Yes "Steve Holden", you should be ashamed of yourself! Your attacks have been more amd more destructive over the past year or so. Even if your behavoir could "somehow" be justified how can someone in your position lead the PSF and act as such an infintile way? I am very ashamed of you Steve and you really owe Alf (and the community at large) an apology although i doubt it will happen because then your own people will turn against you. I have documented the bad behavours of certain "pythonistas" on this group for some time now. And my original assumtions that only a handful of people really follow this group. Maybe one day we will have a fair playing feild for all but sadly it looks to be more like a pipe dream! Sleep well kids! From darkrho at gmail.com Fri Feb 12 21:28:32 2010 From: darkrho at gmail.com (Rolando Espinoza La Fuente) Date: Fri, 12 Feb 2010 22:28:32 -0400 Subject: ConfigParser is not parsing In-Reply-To: References: Message-ID: <4eca3f41002121828x494c3dere60e9c96b71a27ef@mail.gmail.com> read() does not return the config object >>> import ConfigParser >>> config = ConfigParser.SafeConfigParser() >>> config.read('S3Files.conf') ['S3Files.conf'] >>> config.sections() ['main'] >>> config.get('main', 'taskName') 'FileConfigDriver' Regards, Rolando Espinoza La fuente www.rolandoespinoza.info On Fri, Feb 12, 2010 at 10:18 PM, felix gao wrote: > Hi all, > I am trying to get the some configuration file read in by Python, however, > after the read command it return a list with the filename that I passed in. > what is going on? > Python 2.6.1 (r261:67515, Jul ?7 2009, 23:51:51) > [GCC 4.2.1 (Apple Inc. build 5646)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import ConfigParser >>>> p = ConfigParser.SafeConfigParser() >>>> cfg = p.read("S3Files.conf") >>>> cfg > ['S3Files.conf'] > > ?cat S3Files.conf > [main] > taskName=FileConfigDriver > lastProcessed=2010-01-31 > dateFromat=%Y-%m-%d > skippingValue=86400 > skippingInterval=seconds > Thanks in advance. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From twistedphrame at gmail.com Fri Feb 12 22:57:08 2010 From: twistedphrame at gmail.com (Jordan Apgar) Date: Fri, 12 Feb 2010 19:57:08 -0800 (PST) Subject: fork vs threading.Thread Message-ID: I'm trying to run two servers in the same program at once. Here are the two: class TftpServJ(Thread): def __init__(self, ip, root, port=69, debug = False ): Thread.__init__(self) setup stuff here def run(self): try: self.server.listen(self.ip, self.port) except KeyboardInterrupt: pass and class XMLServer(Thread): def __init__(self, host, port, hostid, rsa_key): Thread.__init__(self) setup stuff def run(self): self.server.serve_forever() I call them as: tftpserv = TftpServJ(host, "/home/twistedphrame/Desktop/xmlrpc_server/ server") tftpserv.run() xmlserv = XMLServer(host, port, HostID, key) xmlserv.run() it seems that tftpserv runs but wont go on to spawn xmlserv as well. do I need to fork if I want both these to run at the same time? It was my impression that by using Thread execution in the main program would continue. From sccolbert at gmail.com Fri Feb 12 23:15:37 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 12 Feb 2010 23:15:37 -0500 Subject: fork vs threading.Thread In-Reply-To: References: Message-ID: <7f014ea61002122015g4786d0e8g7993dd4433b1bba8@mail.gmail.com> dont call the .run() method, call the .start() method which is defined the Thread class (and should NOT be overridden). tftpserv.start() xmlserv.start() On Fri, Feb 12, 2010 at 10:57 PM, Jordan Apgar wrote: > I'm trying to run two servers in the same program at once. Here are > the two: > class TftpServJ(Thread): > def __init__(self, ip, root, port=69, debug = False ): > Thread.__init__(self) > setup stuff here > > def run(self): > try: > self.server.listen(self.ip, self.port) > except KeyboardInterrupt: > pass > > and > class XMLServer(Thread): > def __init__(self, host, port, hostid, rsa_key): > Thread.__init__(self) > setup stuff > > def run(self): > self.server.serve_forever() > > > I call them as: > tftpserv = TftpServJ(host, "/home/twistedphrame/Desktop/xmlrpc_server/ > server") > tftpserv.run() > xmlserv = XMLServer(host, port, HostID, key) > xmlserv.run() > > > it seems that tftpserv runs but wont go on to spawn xmlserv as well. > do I need to fork if I want both these to run at the same time? It > was my impression that by using Thread execution in the main program > would continue. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Fri Feb 12 23:25:23 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 05:25:23 +0100 Subject: fork vs threading.Thread In-Reply-To: References: Message-ID: * Jordan Apgar: > I'm trying to run two servers in the same program at once. Here are > the two: > class TftpServJ(Thread): > def __init__(self, ip, root, port=69, debug = False ): > Thread.__init__(self) > setup stuff here > > def run(self): > try: > self.server.listen(self.ip, self.port) > except KeyboardInterrupt: > pass > > and > class XMLServer(Thread): > def __init__(self, host, port, hostid, rsa_key): > Thread.__init__(self) > setup stuff > > def run(self): > self.server.serve_forever() > > > I call them as: > tftpserv = TftpServJ(host, "/home/twistedphrame/Desktop/xmlrpc_server/ > server") > tftpserv.run() > xmlserv = XMLServer(host, port, HostID, key) > xmlserv.run() Here you're just calling the tftpserv.run method directly, not on a separate thread. So it blocks until it's finished (which probably is never?). Instead, try using tftpserv.start() According to the docs, "It [the start method] must be called at most once per thread object. It arranges for the object?s run() method to be invoked in a separate thread of control." You may have to decide on how you want your program to terminate, if you want that. > > > it seems that tftpserv runs but wont go on to spawn xmlserv as well. > do I need to fork if I want both these to run at the same time? It > was my impression that by using Thread execution in the main program > would continue. See above. Cheers & hth., - Alf From nagle at animats.com Sat Feb 13 00:16:51 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Feb 2010 21:16:51 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: <402ac982-0750-4977-adb2-602b19149d81@m24g2000prn.googlegroups.com> Message-ID: <4b7631ee$0$1638$742ec2ed@news.sonic.net> kj wrote: >>> =A0 x =3D '%s' % y >>> =A0 x =3D '%s' % z >>> =A0 print y >>> =A0 print z >>> =A0 print y, z Bear in mind that most Python implementations assume the "console" only handles ASCII. So "print" output is converted to ASCII, which can fail. (Actually, all modern Windows and Linux systems support Unicode consoles, but Python somehow doesn't get this.) John Nagle From ptmcg at austin.rr.com Sat Feb 13 00:28:03 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Fri, 12 Feb 2010 21:28:03 -0800 (PST) Subject: pyparsing wrong output References: <692c428f1002120541n6b3aabb0jb62c50f90715f38e@mail.gmail.com> Message-ID: <879e832b-e211-4bfd-a239-40b583a0a1d1@a5g2000yqi.googlegroups.com> On Feb 12, 6:41?pm, "Gabriel Genellina" wrote: > En Fri, 12 Feb 2010 10:41:40 -0300, Eknath Venkataramani ? > escribi?: > > > I am trying to write a parser in pyparsing. > > Help Me.http://paste.pocoo.org/show/177078/is the code and this is ? > > input > > file:http://paste.pocoo.org/show/177076/. > > I get output as: > > > > There is nothing wrong with pyparsing here. scanString() returns a ? > generator, like this: > > py> g = (x for x in range(20) if x % 3 == 1) > py> g > at 0x00E50D78> > Unfortunately, your grammar doesn't match the input text, so your generator doesn't return anything. I think you are taking sort of brute force approach to this problem, and you need to think a little more abstractly. You can't just pick a fragment and then write an expression for it, and then the next and then stitch them together - well you *can* but it helps to think both abstract and concrete at the same time. With the exception of your one key of "\'", this is a pretty basic recursive grammar. Recursive grammars are a little complicated to start with, so I'll start with a non-recursive part. And I'll work more bottom-up or inside-out. Let's start by looking at these items: count => 8, baajaar => 0.87628353, kiraae => 0.02341598, lii => 0.02178813, adr => 0.01978462, gyiimn => 0.01765590, Each item has a name (which you called "eng", so I'll keep that expression), a '=>' and *something*. In the end, we won't really care about the '=>' strings, they aren't really part of the keys or the associated values, they are just delimiting strings - they are important during parsing, but afterwards we don't really care about them. So we'll start with a pyparsing expression for this: keyval = eng + Suppress('=>') + something Sometimes, the something is an integer, sometimes it's a floating point number. I'll define some more generic forms for these than your original number, and a separate expression for a real number: integer = Combine(Optional('-') + Word(nums)) realnum = Combine(Optional('-') + Word(nums) + '.' + Word(nums)) When we parse for these two, we need to be careful to check for a realnum before an integer, so that we don't accidentally parse the leading of "3.1415" as the integer "3". something = realnum | integer So now we can parse this fragment using a delimitedList expression (which takes care of the intervening commas, and also suppresses them from the results: filedata = """ count => 8, baajaar => 0.87628353, kiraae => 0.02341598, lii => 0.02178813, adr => 0.01978462, gyiimn => 0.01765590,""" print delimitedList(keyval).parseString(filedata) Gives: ['count', '8', 'baajaar', '0.87628353', 'kiraae', '0.02341598', 'lii', '0.02178813', 'adr', '0.01978462', 'gyiimn', '0.01765590'] Right off the bat, we see that we want a little more structure to these results, so that the keys and values are grouped naturally by the parser. The easy way to do this is with Group, as in: keyval = Group(eng + Suppress('=>') + something) With this one change, we now get: [['count', '8'], ['baajaar', '0.87628353'], ['kiraae', '0.02341598'], ['lii', '0.02178813'], ['adr', '0.01978462'], ['gyiimn', '0.01765590']] Now we need to add the recursive part of your grammar. A nested input looks like: confident => { count => 4, trans => { ashhvsht => 0.75100505, phraarmnbh => 0.08341708, }, }, So in addition to integers and reals, our "something" could also be a nested list of keyvals: something = realnum | integer | (lparen + delimitedList(keyval) + rparen) This is *almost* right, with just a couple of tweaks: - the list of keyvals may have a comma after the last item before the closing '}' - we really want to suppress the opening and closing braces (lparen and rparen) - for similar structure reasons, we'll enclose the list of keyvals in a Group to retain the data hierarchy lparen,rparen = map(Suppress, "{}") something = realnum | integer | Group(lparen + delimitedList(keyval) + Optional(',') + rparen) The recursive problem is that we have defined keyval using something, and something using keyval. You can't do that in Python. So we use the pyparsing class Forward to "forward" declare something: something = Forward() keyval = Group(eng + Suppress('=>') + something) To define something as a Forward, we use the '<<' shift operator: something << (realnum | integer | Group(lparen + delimitedList(keyval) + Optional(',') + rparen)) Our grammar now looks like: lparen,rparen = map(Suppress, "{}") something = Forward() keyval = Group(eng + Suppress('=>') + something) something << (realnum | integer | Group(lparen + delimitedList(keyval) + Optional(',') + rparen)) To parse your entire input file, use a delimitedList(keyval) results = delimitedList(keyval).parseString(filedata) (There is one problem - one of your keynames is "\'". I don't know if this is a typo or intentional. If you need to accommodate even this as a keyname, just change your definition of eng to Word(alphas +r"\'").) Now if I parse your original string, I get (using the pprint module to format the results): [['markets', [['count', '8'], ['trans', [['baajaar', '0.87628353'], ['kiraae', '0.02341598'], ['lii', '0.02178813'], ['adr', '0.01978462'], ['gyiimn', '0.01765590'], ['baaaaromn', '0.01765590'], ['sdk', '0.01728024'], ['kaanuun', '0.00613574'], ',']], ',']], ['confident', [['count', '4'], ['trans', [['ashhvsht', '0.75100505'], ['phraarmnbh', '0.08341708'], ['athmvishhvaas', '0.08090452'], ['milte', '0.03768845'], ['utnii', '0.02110553'], ['anaa', '0.01432161'], ['jitne', '0.01155779'], ',']], ',']], ['consumers', [['count', '34'], ['trans', [['upbhokhtaaomn', '0.48493883'], ['upbhokhtaa', '0.27374792'], ['zrurtomn', '0.02753605'], ['suuchnaa', '0.02707965'], ['ghraahkomn', '0.02580174'], ['ne', '0.02574089'], ["\\'", '0.01947301'], ['jnmt', '0.01527414'], ',']], ',']]] But there is one more card up pyparsing's sleeve. Just as your original parser used "english" to apply a results name to your keys, it would be nice if our parser would return not a list of key-value pairs, but an actual dict-like object. Pyparsing's Dict class enhances the results in just this way. Use Dict to wrap our repetitive structures, and it will automatically define results names for us, reading the first element of each group as the key, and the remaining items in the group as the value: something << (realnum | integer | Dict(lparen + delimitedList(keyval) + Optional(',').suppress() + rparen)) results = Dict(delimitedList(keyval)).parseString(filedata) print results.dump() Gives this hierarchical structure: - confident: - count: 4 - trans: - anaa: 0.01432161 - ashhvsht: 0.75100505 - athmvishhvaas: 0.08090452 - jitne: 0.01155779 - milte: 0.03768845 - phraarmnbh: 0.08341708 - utnii: 0.02110553 - consumers: - count: 34 - trans: - \': 0.01947301 - ghraahkomn: 0.02580174 - jnmt: 0.01527414 - ne: 0.02574089 - suuchnaa: 0.02707965 - upbhokhtaa: 0.27374792 - upbhokhtaaomn: 0.48493883 - zrurtomn: 0.02753605 - markets: - count: 8 - trans: - adr: 0.01978462 - baaaaromn: 0.01765590 - baajaar: 0.87628353 - gyiimn: 0.01765590 - kaanuun: 0.00613574 - kiraae: 0.02341598 - lii: 0.02178813 - sdk: 0.01728024 You can access these fields by name like dict elements: print results.keys() print results["confident"].keys() print results["confident"]["trans"]["jitne"] If the names are valid Python identifiers (which "\'" is *not*), you can access their fields like attributes of an object: print results.confident.trans.jitne for k in results.keys(): print k, results[k].count Prints: ['confident', 'markets', 'consumers'] ['count', 'trans'] 0.01155779 0.01155779 confident 4 markets 8 consumers 34 I've posted the full program at http://pyparsing.pastebin.com/f1d0e2182. Welcome to pyparsing! -- Paul From nagle at animats.com Sat Feb 13 00:48:30 2010 From: nagle at animats.com (John Nagle) Date: Fri, 12 Feb 2010 21:48:30 -0800 Subject: Need debugging knowhow for my creeping Unicodephobia In-Reply-To: References: Message-ID: <4b763959$0$1633$742ec2ed@news.sonic.net> kj wrote: > Some people have mathphobia. I'm developing a wicked case of > Unicodephobia. > > I have read a *ton* of stuff on Unicode. It doesn't even seem all > that hard. Or so I think. Then I start writing code, and WHAM: > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) First, you haven't told us what platform you're on. Windows? Linux? Something else? If you're on Windows, and running Python from the command line, try "cmd /u" before running Python. This will get you a Windows console that will print Unicode. Python recognizes this, and "print" calls will go out to the console in Unicode, which will then print the correct characters if they're in the font being used by the Windows console. Most European languages are covered in the standard font. If you're using IDLE, or some Python debugger, it may need to be told to have its window use Unicode. John Nagle From misceverything at gmail.com Sat Feb 13 01:32:45 2010 From: misceverything at gmail.com (T) Date: Fri, 12 Feb 2010 22:32:45 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> <3d900751-44e8-4335-a812-3dd0d7b4496f@m4g2000vbn.googlegroups.com> <96353030-0e0c-4035-ae4a-5ab475251d4b@x9g2000vbo.googlegroups.com> Message-ID: On Feb 11, 4:10?am, Tim Golden wrote: > On 10/02/2010 22:55, T wrote: > > > Great suggestions once again - I did verify that it was at least > > running the plink.exe binary when under LocalSystem by having the > > service run "plink.exe> ?C:\plinkoutput.txt" - this worked fine. ?And, > > as I mentioned, it's now working just fine when running under a > > regular admin account. ?So, I think that's going to be my solution to > > avoid any further issues. ?My best guess at this point (as you > > mentioned), is that plink.exe is doing _something_ network-related > > that LocalSystem doesn't have the privileges to do - what exactly it > > is, I have no idea. ?I may play around with it some more later, but > > running the service under an admin account should be a perfectly > > acceptable solution. > > > Also, I will be writing other Python apps that the service will be > > executing - so it goes without saying that I'll be including a log to > > file option :) ?Thanks again for all your guys' help! > > I'm not sure if this has been said already, but a reasonably common > approach to services is to create a user specifically for the > service and grant it exactly the privs / perms it needs (once you > work out what they are). You then assign it a generated password, > eg a GUID which you don't even try to remember: simply cut-and-paste > it in. Then create the service to run under that user. > > That way you don't have the service running under > some local Administrator account with the associated risk > of its being subverted and gaining more control than you > want. Nor do you have it running as a real user whose > password might change for any reason, leaving you with > a service which won't start up. > > I don't remember at this moment whether such a user's profile > is automatically loaded in the process when the service starts > or whether you have to do the LoadUserProfile thing. > > TJG Tim - thanks, that's the route I'm going to go. I've created separate accounts for services before, and there's no question that's what I have to do in this case. I'm still having some issues running some commands (such as one that takes a screenshot), even as an admin user, but I think this is more due to the fact that it's trying to interact with the Desktop..so there may be no good solution. Btw great site..can't tell you how many times I've gone back to it. Keep up the great work! From misceverything at gmail.com Sat Feb 13 01:36:44 2010 From: misceverything at gmail.com (T) Date: Fri, 12 Feb 2010 22:36:44 -0800 (PST) Subject: Executing Commands From Windows Service References: <87c04446-62f9-49a6-904a-e33deca8f076@j6g2000vbd.googlegroups.com> Message-ID: <10b628f5-0b85-46c4-b2ef-2a8579c10162@d27g2000yqn.googlegroups.com> On Feb 11, 8:21?am, "Martin P. Hellwig" wrote: > On 02/07/10 19:02, T wrote: > > > I have a script, which runs as a Windows service under the LocalSystem > > account, that I wish to have execute some commands. ?Specifically, the > > program will call plink.exe to create a reverse SSH tunnel. ?Right now > > I'm using subprocess.Popen to do so. ?When I run it interactively via > > an admin account, all is well. ?However, when I'm running it via > > service, no luck. ?I'm assuming this is to do with the fact that it's > > trying to run under the LocalSystem account, which is failing. ?What > > would be the best way around this? ?Thanks! > > All being said about LS account not having the appropriate rights to > access the necessary devices/files. > > Could it be so simple that the network is plain simply not available at > all? For wireless connections I believe the connection/authentication by > default is made in user space. I would save the output of an ipconfig > run as the LS account to a file and see what is happening. > Perhaps followed by a ping. > > -- > mph Martin - another part of the program sends an email back to a specified user, and that works, so LocalSystem must at least have some network access. From the testing I've done so far, seems like there's just some grey area (which I haven't completely figured out yet) of network-related tasks that LS just can't do. I'd love to know what this is, but so far the solution I have is just to create another user and have the service use that.. From nobody at nowhere.com Sat Feb 13 02:01:39 2010 From: nobody at nowhere.com (Nobody) Date: Sat, 13 Feb 2010 07:01:39 +0000 Subject: MemoryError, can I use more? References: Message-ID: On Fri, 12 Feb 2010 19:21:22 -0500, Echavarria Gregory, Maria Angelica wrote: > I am developing a program using Python 2.5.4 in windows 32 OS. The amount > of data it works with is huge. I have managed to keep memory footprint > low, but have found that, independent of the physical RAM of the machine, > python always gives the MemoryError message when it has occupied exactly > only 2.2 GB. I have tested this in 4 different machines, all with memory > of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I > typed help(MemoryError) and it is a class itself, but that help told me > nothing I can use... A single process can't use much more than 2GiB of RAM without a 64-bit CPU and OS. If you're stuck with a 32-bit system, you really need to figure out how to limit the amount of data which is kept in memory at any one time. From vorticitywolfe at gmail.com Sat Feb 13 02:33:09 2010 From: vorticitywolfe at gmail.com (J Wolfe) Date: Fri, 12 Feb 2010 23:33:09 -0800 (PST) Subject: How do you implement a Progress Bar Message-ID: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> I would really appreciate some help with this. I'm fairly new to using classes...What am I doing wrong? All I get is a blank window. I can't seem to figure out how to initialize this Progress Bar. Thanks, Jonathan ##############################file Meter.py#################### from Tkinter import * class Meter(Frame): '''A simple progress bar widget.''' def __init__(self, master, fillcolor='orchid1', text='',value=0.0, **kw): Frame.__init__(self, master, bg='white', width=350,height=20) self.configure(**kw) self._c = Canvas(self, bg=self['bg'],width=self['width'], height=self['height'],highlightthickness=0, relief='flat',bd=0) self._c.pack(fill='x', expand=1) self._r = self._c.create_rectangle(0, 0, 0, int(self['height']), fill=fillcolor, width=0) self._t = self._c.create_text(int(self['width'])/2, int(self['height'])/2, text='') self.set(value, text) def set(self, value=0.0, text=None): #make the value failsafe: if value < 0.0: value = 0.0 elif value > 1.0: value = 1.0 if text == None: #if no text is specified get the default percentage string: text = str(int(round(100 * value))) + ' %' self._c.coords(self._r, 0, 0, int(self['width']) * value, int(self['height'])) self._c.itemconfigure(self._t, text=text) root=Tk() f=Meter(root) for i in range(100): f.set(i,"Hello") print i mainloop() From alfps at start.no Sat Feb 13 02:54:21 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 08:54:21 +0100 Subject: How do you implement a Progress Bar In-Reply-To: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> References: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> Message-ID: * J Wolfe: > I would really appreciate some help with this. I'm fairly new to > using classes...What am I doing wrong? All I get is a blank window. I > can't seem to figure out how to initialize this Progress Bar. > > Thanks, > Jonathan > > > > ##############################file Meter.py#################### > from Tkinter import * > > class Meter(Frame): > '''A simple progress bar widget.''' > def __init__(self, master, fillcolor='orchid1', text='',value=0.0, > **kw): > Frame.__init__(self, master, bg='white', width=350,height=20) > self.configure(**kw) > self._c = Canvas(self, bg=self['bg'],width=self['width'], > height=self['height'],highlightthickness=0, relief='flat',bd=0) > self._c.pack(fill='x', expand=1) > self._r = self._c.create_rectangle(0, 0, 0, int(self['height']), > fill=fillcolor, width=0) > self._t = self._c.create_text(int(self['width'])/2, > int(self['height'])/2, text='') > self.set(value, text) > > def set(self, value=0.0, text=None): > #make the value failsafe: > if value < 0.0: > value = 0.0 > elif value > 1.0: > value = 1.0 > if text == None: > #if no text is specified get the default percentage string: > text = str(int(round(100 * value))) + ' %' > self._c.coords(self._r, 0, 0, int(self['width']) * value, > int(self['height'])) > self._c.itemconfigure(self._t, text=text) > > > > root=Tk() > f=Meter(root) At his point the Meter widget has been created, but it's still invisible. To make it visible you have to register it with a layout manager (in tkinter-speak a "geometry" manager). A layout manager for a widget X is responsible for placing child widgets of X. The easiest is to add, at this point, f.pack() which uses the packing layout manager of the parent widget of f (not sure why the design is like this, but f.pack() forwards up to the parent's layout manager). You can add various optional parameters. Or use other layout mgr. Take care that all child widgets of a given parent widget use the same layout manager, otherwise the typical result is a hang. > for i in range(100): > f.set(i,"Hello") > print i This will probably happen too fast to see, before the window is presented. One idea might be to add a few buttons for testing things. > mainloop() Cheers & hth., - Alf From vorticitywolfe at gmail.com Sat Feb 13 03:22:19 2010 From: vorticitywolfe at gmail.com (J Wolfe) Date: Sat, 13 Feb 2010 00:22:19 -0800 (PST) Subject: How do you implement a Progress Bar References: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> Message-ID: <1a5d5ff2-bd54-4a2f-a74b-b1b89dd92bc8@v25g2000yqk.googlegroups.com> Thank you Alf! Here I thought it was something wrong with my class call, but it turns out I just needed to pack f and then use root.update() in the loop :-) I really appreciate your help! From half.italian at gmail.com Sat Feb 13 03:25:32 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sat, 13 Feb 2010 00:25:32 -0800 (PST) Subject: How do you implement a Progress Bar References: <0861e000-b511-4a01-8fa4-727e23e996f0@o3g2000yqb.googlegroups.com> Message-ID: <378c7809-1f69-4516-a4ef-b9eff4d1790a@u15g2000prd.googlegroups.com> On Feb 12, 11:33?pm, J Wolfe wrote: > I would really appreciate some help with this. ?I'm fairly new to > using classes...What am I doing wrong? All I get is a blank window. I > can't seem to figure out how to initialize this Progress Bar. > Study and hack on this: http://uucode.com/texts/pylongopgui/pyguiapp.html ~Sean From apt.shansen at gmail.com Sat Feb 13 04:30:37 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 13 Feb 2010 01:30:37 -0800 Subject: Modifying Class Object In-Reply-To: <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <4b75235b$0$23469$426a74cc@news.free.fr> <0385c5f3$0$1277$c3e8da3@news.astraweb.com> <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> Message-ID: <7a9c25c21002130130x61516383va871d4018d352014@mail.gmail.com> On Fri, Feb 12, 2010 at 6:23 PM, rantingrick wrote: [blah, blah, blah] First of all, we all know how D Aprano has such an unfettered ego > problem. [blah, blah, blah] And as always the roaches start > coming out of the woodwork in a most "pathetic puppy dog" way. What > would you puppets do if there were no one to pull your strings? > [blah, blah, blah] (I'd claim an ad hominem attack, but that's just boring these days) > But the most nortoriuos behavior of all belongs to none other that the > PSF chairman himself! Yes "Steve Holden", you should be ashamed of > yourself! [blah, BLAH, blah] > Your attacks have been more amd more destructive over the > past year or so. Even if your behavoir could "somehow" be justified > how can someone in your position lead the PSF and act as such an > infintile way? [blah, blah, BLAH, blah] > I am very ashamed of you Steve and you really owe Alf > (and the community at large) an apology although i doubt it will > happen because then your own people will turn against you. > Blah. Blah. Blah. Grow up. I've deliberately exited the real topic of this thread, because its clearly degenerated to complete nonsense; while in this thread Alf argues for a certain dogmatic theoretical "Standard" terminology that clearly many people disagree with (supporting the 'standard' continually with a certain language's reference manual, which by definition makes it not-standard, or you wouldn't need to quote a certain language0, and in another he argues for another position-- and and speaks in support of standard and understood terminology, the two positions together are laughable nonsense. To this he will, of course, again declare that I am simply lying. This very declaration clearly proves his own absurdity: you can argue in a circle for infinity, but when you start spouting nonsense about how those opposing you are mere liars-- ESPECIALLY-- when you have been arguing about how you have been the terrible victim of ad hominem attacks-- your own hypocrisy makes your words meaningless. I've been tempted to re-enter the actual argument, its a hard one to avoid with such clear misunderstandings held so strongly. But, I won't. Except for my editorials here. Because I am weak. Ahem, the point is-- my chief antagonist in the discussion has publicly stated I am a liar. This is provably a lie unto itself, and it damns the speaker absolutely. I have expressed my position, my thoughts, and my opinion and interpretation of my opponents position -- and his response is, "You are a liar." or, "That is a lie". That's a lie, a personal attack, all the while declaring his own victimhood. You can say, "You're mistaken", but to say, "You are a liar." is something else entirely. The chief victim of c.p.l. becomes the abuser. Now, why am I entering this thread again? Not to discuss the issue at hand. There's clearly no point. Alf has chosen to define language in his own way, ignoring any weight that established industry weight might apply to such terms. Okay. When you enter an argument of words, some people will refuse to acknowledge their own perception of the world isn't reality. It happens. There's no point in going forward after a certain point. But now, this absurdity? You are ashamed of Steve Holden for his behavior? You think he owes the community at large an apology? I don't mean to rise up in defense of Holden, as I'm sure he can defend himself should he feel the need. I took offense at Alf choosing to claim the right of defending me earlier, so I can't be a hypocrite in that. But, really. If -this- is your position? Grow up. Seriously. Steve Holden owes this community nothing. That which he has given should be welcomed and he should be thanked for it. He hasn't flamed anyone; he hasn't attacked anyone-- despite Alf's nonsense claims, though on occasion his responses are snarky (with reason)-- he hasn't /taken/ anything from this community. He's done far more then many in assisting people who are trying to learn Python and embrace its community. Frankly, how dare you claim to demand an apology for this community. If I was to be ashamed of anyone's participation in the community, it would be you over him. I'm not even ashamed of Alf. I don't agree with him, I think he's got a stubborn egocentric view of terminology and semantics which is ultimately harmful, I think he has a severe persecution complex, but despite this-- I've seen him respond to several threads recently, helpfully, and I don't even disagree with most of those responses. You're just ... blabbering. Adding arbitrary, unsupported, and unsupportable fuel to the fire to rant at some position-- how /mean/ this community is and how /terrible/ we behave-- all without any basis at all. Except you claim it. You document it. Gee, we're mean, mean, unhelpful people. And no, I'm not one of "his people" who will turn on him for admitting he is satan; if Steve Holden and I have ever been in a thread in the past -- it was us both answering some newbie, or commenting on a topic, all independently-- and I'm not even sure I was ever aware of it having happened. I remember no particular conversation, ever, between him and I. This is one of the most generally supportive technical communities I've ever seen, even when faced with clear ignorance and people even not taking the most basic due diligence before asking others to answer their questions. It goes back almost a decade to when I posted more then one /really/ stupid question to this group on some initial assumptions and thoughts-- on most groups? Such things would be ridiculed. Here, people ask questions when the OP's position isn't clear or if it seems they may be looking at the problem wrong. They go out of their way to understand the use-case and details of the question and provide solutions. They -work- to be helpful, and supportive, with some demands-- but reasonable demands. And you're all ashamed of our "bad behaviors". That makes me want to say, "Well, f--- you too". But I won't. I'll just hope you grow up and get over it and learn that hey, communities? They are never seamless, or easy, and conflict is a part of life. Some have very hard standards for acceptance, some try to embrace but there's always going to be issues. This is one of the good ones. Deal with it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From dino at phidev.org Sat Feb 13 04:50:43 2010 From: dino at phidev.org (Florian Ludwig) Date: Sat, 13 Feb 2010 10:50:43 +0100 Subject: plugin / intra process communication system Message-ID: <1266054643.26540.58.camel@brain> Hi, I'm looking for a module/plugin/intra-process-communication/hook system for python. Maybe someone here could point me to some project I missed or might have some good ideas if I end up implementing it myself. Most systems I have found are "one to many" communications but I would like "many to many", to clarify what I mean an *example* use-case: Lets say you program a wiki and like to allow different kind of authentications. So you create two plugins (for example one for OpenID and one for Shibboleth). Some time later you feel like reinventing the wheel again and you program a blog. Again you like to allow different ways of authentication and you already wrote plugins for exactly the same for your wiki, right? With most systems now some trouble begins - the blog software would need to have the interface/extention-points/however-you-name-it that the wiki software defined. The plugins you wrote probably import them from the wiki module directly which means your blog would depend on the wiki. (?!) So where to put the interface/[...] definition that is imported by those plugins? Create a package/module just containing the interface? This really get troublesome if different people wrote the wiki, the blog and another third one a plugin. Also it will probably break if you try to create a program that includes (imports and uses) the wiki and the blog at the same time. While looking for existing solutions I came across several different implementations and approaches with different advantages and disadvantages. To not list them all, here one representative implementation: trac's component architecture [0] as its well but still short documented, shares several concepts with other implementations and I failed to see how to solve the problem described above with it. So, what's your solution? Thanks for reading my long mail! Really hoping for an constructive discussion, Florian [0] http://trac.edgewall.org/wiki/TracDev/ComponentArchitecture -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From showell30 at yahoo.com Sat Feb 13 04:53:09 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 01:53:09 -0800 (PST) Subject: Function attributes References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: <3307e656-f2da-424e-96ea-1166f05835b5@b9g2000pri.googlegroups.com> On Feb 10, 5:59?am, Muhammad Alkarouri wrote: > Hi everyone, > > What is the simplest way to access the attributes of a function from > inside it, other than using its explicit name? > In a function like f below: > > def f(*args): > ? ? f.args = args > ? ? print args > > is there any other way? > I am guessing the next question will be: should I really care? It just > feels like there should be a way, but I am not able to verbalise a > valid one at the moment, sorry. > You should care. :) You can avoid referring to f twice by using an inner method with a name that is less subject to change or influence from outside forces: def countdown_function_that_might_get_renamed( n, preamble, postamble): def recurse(n): print preamble, n, postamble if n: recurse(n-1) recurse(n) countdown_function_that_might_get_renamed(10, "before", "after") Note that the example makes the recursive call more concise, by avoiding the need to resend the parameters that don't change during the recursion ("preamble" and "postamble"). Of course, you do trade off some terseness with the inner method, but it's only two lines of code and one level of indentation. For a somewhat related discussion see this short thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/197221f82f7c247b In particular see Gabriel's response to me. The fact that you are saving off f.args makes me think that you are solving a problem similar to mine, but I could be wrong. From __peter__ at web.de Sat Feb 13 05:03:20 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Feb 2010 11:03:20 +0100 Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: hjebbers wrote: > On Feb 12, 3:17 pm, Peter Otten <__pete... at web.de> wrote: >> hjebbers wrote: >> > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: >> >> hjebbers wrote: >> >> > On Feb 11, 5:45 pm, M3RT wrote: >> >> >> The problem may be related to how you treat the EDI file or lets >> >> >> say DATA. Also your coding style is important. Can you provide more >> >> >> info? >> >> >> > Yes, a whole lot more; but I do not want to bother you with that >> >> > now. I was just wondering if it is possible that the same setup >> >> > gives a CRASH! on windows and just works on linux. >> >> > (where is the bug?) >> >> >> In the platform-specific code ;) >> >> >> Even on alt.haruspicy they cannot do much without a liver now and >> >> then... >> >> > if it is in the platform-specific code should I make this into a >> > bugreport? >> >> A this stage a bug report would be useless. The details you have provided >> so far don't give anyone without physical access to your machine a chance >> to reproduce the error. >> >> > (because the crash does not appear at the same place in my code (when >> > doing the same test-run) it will be quite hard to point down....) >> >> Indeed. The culprit may be an extension written in C that is overwriting >> memory still in use by other parts of your program. >> >> Peter > > No C extensions used. Definitely not. > > As these crashes occur during stress tests, I go to the limits of the > memory available. > What strikes me is: > 1. the crash on windows, but linux works OK (same test sets) > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > much). Random thoughts: If there were not enough memory Python should give a MemoryError rather than segfault. Do both systems use the same memory layout (i. e. 32 or 64bit OS, 16 or 32 bit unicode)? Try an alpha of Python 2.7. If you're lucky "your" bug was found 'n' fixed independently. Peter From daniele.esposti at gmail.com Sat Feb 13 05:07:04 2010 From: daniele.esposti at gmail.com (Expo) Date: Sat, 13 Feb 2010 02:07:04 -0800 (PST) Subject: bsddb version mysmatch between win32 and linux Message-ID: <18361bde-a134-478f-b670-87c16fd57028@w31g2000yqk.googlegroups.com> Hi guys, I found an incompatibility in the bsddb library shipped with Python which is a different version between the win32 release and the linux release. This happend using Python 2.6.2 on win32 and OpenSuse 11.2. To reproduce this problem, create a bsddb file under win32 with this code: import shelve f = shelve.open( "test.bin" ) f["test"] = "test" f.sync() f.close() copy test.bin in the OpenSuse system and try to open it: import shelve f = shelve.open( "test.bin" ) print f["test"] and you get this traceback: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/shelve.py", line 234, in open return DbfilenameShelf(filename, flag, protocol, writeback) File "/usr/lib/python2.6/shelve.py", line 218, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback) File "/usr/lib/python2.6/anydbm.py", line 83, in open return mod.open(file, flag, mode) File "/usr/lib/python2.6/dbhash.py", line 19, in open return bsddb.hashopen(file, flag, mode) File "/usr/lib/python2.6/bsddb/__init__.py", line 361, in hashopen d.open(file, db.DB_HASH, flags, mode) bsddb.db.DBInvalidArgError: (22, 'Invalid argument -- ./test.bin: unsupported hash version: 9') I don't know yet if the problem is related to OpenSuse or to the Python linux distribution. How I can resolve this ? From hjebbers at gmail.com Sat Feb 13 05:29:48 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 02:29:48 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <2864756a-292b-4138-abfd-3348b72b7e9a@u9g2000yqb.googlegroups.com> Message-ID: On Feb 12, 11:46?pm, Rob Williscroft wrote: > hjebbers wrote in news:2864756a-292b-4138-abfd- > 3348b72b7... at u9g2000yqb.googlegroups.com in comp.lang.python: > > > the information about the error is a windows dump. > > This may help: > > #http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx > > SEM_FAILCRITICALERRORS = 1 > SEM_NOALIGNMENTFAULTEXCEPT = 4 > SEM_NOGPFAULTERRORBOX = 4 > SEM_NOOPENFILEERRORBOX = 8 > > import ctypes > from ctypes.wintypes import UINT > > SetErrorMode = ctypes.windll.kernel32.SetErrorMode > SetErrorMode.restype = UINT > SetErrorMode.argtypes = ( UINT,) > > Then putting: > > SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX ) > > at the start of you programme, should stop the "Critical Error" dialog > box you are seeing and you may get a chance to see a traceback. > > Rob. Hi Rob, thanks. I tried this, but did not work for me. henk-jan From hjebbers at gmail.com Sat Feb 13 05:49:01 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 02:49:01 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: On Feb 13, 11:03?am, Peter Otten <__pete... at web.de> wrote: > hjebbers wrote: > > On Feb 12, 3:17 pm, Peter Otten <__pete... at web.de> wrote: > >> hjebbers wrote: > >> > On Feb 11, 7:01 pm, Peter Otten <__pete... at web.de> wrote: > >> >> hjebbers wrote: > >> >> > On Feb 11, 5:45 pm, M3RT wrote: > >> >> >> The problem may be related to how you treat the EDI file or lets > >> >> >> say DATA. Also your coding style is important. Can you provide more > >> >> >> info? > > >> >> > Yes, a whole lot more; but I do not want to bother you with that > >> >> > now. I was just wondering if it is possible that the same setup > >> >> > gives a CRASH! on windows and just works on linux. > >> >> > (where is the bug?) > > >> >> In the platform-specific code ;) > > >> >> Even on alt.haruspicy they cannot do much without a liver now and > >> >> then... > > >> > if it is in the platform-specific code should I make this into a > >> > bugreport? > > >> A this stage a bug report would be useless. The details you have provided > >> so far don't give anyone without physical access to your machine a chance > >> to reproduce the error. > > >> > (because the crash does not appear at the same place in my code (when > >> > doing the same test-run) it will be quite hard to point down....) > > >> Indeed. The culprit may be an extension written in C that is overwriting > >> memory still in use by other parts of your program. > > >> Peter > > > No C extensions used. Definitely not. > > > As these crashes occur during stress tests, I go to the limits of the > > memory available. > > What strikes me is: > > 1. the crash on windows, but linux works OK (same test sets) > > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > > much). > > Random thoughts: > > If there were not enough memory Python should give a MemoryError rather than > segfault. > > Do both systems use the same memory layout (i. e. 32 or 64bit OS, 16 or 32 > bit unicode)? bot use 32bits; but the windows box uses 16 bits unicode, on linux 32bits unicode is used. the memory used by my program is for the larger part unicode strings. ....well, but that makes the better performance of linux even stranger... > > Try an alpha of Python 2.7. If you're lucky "your" bug was found 'n' fixed > independently. well...that's what I thought for version 2.6 ;-) (I run into this crash a longer time ago) but seriously, I'll try this. kind regards, henk-jan > > Peter From hjebbers at gmail.com Sat Feb 13 05:50:49 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 02:50:49 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> On Feb 13, 10:25?am, Dennis Lee Bieber wrote: > On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > declaimed the following in gmane.comp.python.general: > > > What strikes me is: > > 1. the crash on windows, but linux works OK (same test sets) > > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > > much). > > ? ? ? ? Which on its own does not mean much. > > ? ? ? ? Windows in a normal installation only grants 2GB address space to > user code, reserving the other 2GB space for the OS shared libraries. If > your program attempts to allocate over that, it will fail. That the > Windows box has twice the physical memory only means it doesn't resort > to page swapping as soon. > > ? ? ? ? There is a boot parameter switch that toggles Windows into a 3GB > user/1GB OS mode -- hey, that would be great!! on my 1,5G mahcine ;-) > it is mainly meant for server machines where there > won't be many disjoint OS libraries loaded, but the server applications > need lots of data space. > > ? ? ? ? What split does the Linux OS use? If it give 3GB to user space, > while you'd start to page swap much soon, you'd also have 50% more > virtual memory that can be allocated than under Windows. > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ I will check this.....any advice on how to check this? henk-jan From breamoreboy at yahoo.co.uk Sat Feb 13 06:02:24 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 11:02:24 +0000 Subject: Function attributes In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Gabriel Genellina wrote: > En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle > escribi?: > >> I posted an example of a decorator that does just this in this thread a >> couple of days ago: >> >> http://mail.python.org/pipermail/python-list/2010-February/1235742.html > > Ouch! I didn't see your post, nor several other earlier posts in this > thread. In fact, I thought mine was the *first* reply when I wrote it! > It's not just me then. I'm using Thunderbird on Windows Vista to view the group via gmane, and notice the earlier parts of a thread can show up hours or even days after the later ones. Would something who understands these things be kind enough to explain why this happens, or at least provide the keywords needed for google, as I haven't got a clue where to start. > Yes, of course, your code does exactly that without any bytecode hacks. > From hjebbers at gmail.com Sat Feb 13 06:03:02 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 03:03:02 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <34fcf680-1aa4-4835-9eba-3db3249f36b2@q16g2000yqq.googlegroups.com> <007f26f3-5310-4ed9-bb25-b467fb248825@m35g2000prh.googlegroups.com> Message-ID: to all, thanks for the pointers so far. if you feel the need to reproduce the crash, it's not that hard, (downloading and installing my edi translator, install configuration (button-click), and run. I have a modified version (replace some *.py files) that eliminate a lot of stuff (simpler setup, no database used, no external C-modules). contact me for recipe and files about me being reluctant to 'show the code': - the crash that happens during stress tests. - the crash occurs not always, and at different points. - the code does runs OK on linux (which does not mean there's no bugt in it ;-) kind regards, henk-jan From deets at nospam.web.de Sat Feb 13 06:24:17 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 12:24:17 +0100 Subject: python crash on windows but not on linux In-Reply-To: <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> Message-ID: <7tngf2Fo5rU1@mid.uni-berlin.de> Am 13.02.10 11:50, schrieb hjebbers: > On Feb 13, 10:25 am, Dennis Lee Bieber wrote: >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers >> declaimed the following in gmane.comp.python.general: >> >>> What strikes me is: >>> 1. the crash on windows, but linux works OK (same test sets) >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as >>> much). >> >> Which on its own does not mean much. >> >> Windows in a normal installation only grants 2GB address space to >> user code, reserving the other 2GB space for the OS shared libraries. If >> your program attempts to allocate over that, it will fail. That the >> Windows box has twice the physical memory only means it doesn't resort >> to page swapping as soon. >> >> There is a boot parameter switch that toggles Windows into a 3GB >> user/1GB OS mode -- > > hey, that would be great!! on my 1,5G mahcine ;-) You don't get it - it's about the virtual memory address space available. This has nothing to do with physical memory. Obviously if the latter runs out, the swapping will make the machine painfully slow. But that's another issue. Diez From hjebbers at gmail.com Sat Feb 13 06:35:45 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 03:35:45 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> Message-ID: <0a5e5e0a-7b2c-40a9-a1d7-77a478bf88a0@q29g2000yqn.googlegroups.com> On Feb 13, 12:24?pm, "Diez B. Roggisch" wrote: > Am 13.02.10 11:50, schrieb hjebbers: > > > > > On Feb 13, 10:25 am, Dennis Lee Bieber ?wrote: > >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > >> declaimed the following in gmane.comp.python.general: > > >>> What strikes me is: > >>> 1. the crash on windows, but linux works OK (same test sets) > >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > >>> much). > > >> ? ? ? ? ?Which on its own does not mean much. > > >> ? ? ? ? ?Windows in a normal installation only grants 2GB address space to > >> user code, reserving the other 2GB space for the OS shared libraries. If > >> your program attempts to allocate over that, it will fail. That the > >> Windows box has twice the physical memory only means it doesn't resort > >> to page swapping as soon. > > >> ? ? ? ? ?There is a boot parameter switch that toggles Windows into a 3GB > >> user/1GB OS mode -- > > > hey, that would be great!! on my 1,5G mahcine ;-) > > You don't get it - it's about the virtual memory address space > available. This has nothing to do with physical memory. Obviously if the > latter runs out, the swapping will make the machine painfully slow. But > that's another issue. > > Diez Diez, you are right; I misunderstood. henk-jan From hjebbers at gmail.com Sat Feb 13 06:54:47 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 03:54:47 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> Message-ID: <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> I enlarged the windows page file from 750Kb to 1.5Gb . The crash still happens. btw, the crash does not happen at a peak memory usage. According to windows task manager, at the moment of crash mem usage of my program is 669kb, peak memory usage is 1.136kb henk-jan From alfps at start.no Sat Feb 13 07:14:58 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 13:14:58 +0100 Subject: python crash on windows but not on linux In-Reply-To: <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> Message-ID: * hjebbers: > I enlarged the windows page file from 750Kb to 1.5Gb . > The crash still happens. > btw, the crash does not happen at a peak memory usage. > According to windows task manager, at the moment of crash mem usage of > my program is 669kb, peak memory usage is 1.136kb > > henk-jan Probably you meant to write "M", not "k" or "K"? I've never managed to make much sense of the displays in Windows' Task Manager, if that's what you're using, but I think the mem usage it's displaying by default is the process' working set, or something very similar to that measure. You can display additional columns in Task Manager, and one useful one is how much virtual memory is allocated,. And perhaps then (if that's not what you're looking it already) it'll be closer to 2 GiB? Cheers & hth., - Alf From hjebbers at gmail.com Sat Feb 13 07:34:46 2010 From: hjebbers at gmail.com (hjebbers) Date: Sat, 13 Feb 2010 04:34:46 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> Message-ID: On Feb 13, 10:25?am, Dennis Lee Bieber wrote: > On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > declaimed the following in gmane.comp.python.general: > > > What strikes me is: > > 1. the crash on windows, but linux works OK (same test sets) > > 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > > much). > > ? ? ? ? Which on its own does not mean much. > > ? ? ? ? Windows in a normal installation only grants 2GB address space to > user code, reserving the other 2GB space for the OS shared libraries. If > your program attempts to allocate over that, it will fail. That the > Windows box has twice the physical memory only means it doesn't resort > to page swapping as soon. > > ? ? ? ? There is a boot parameter switch that toggles Windows into a 3GB > user/1GB OS mode -- it is mainly meant for server machines where there > won't be many disjoint OS libraries loaded, but the server applications > need lots of data space. > > ? ? ? ? What split does the Linux OS use? If it give 3GB to user space, > while you'd start to page swap much soon, you'd also have 50% more > virtual memory that can be allocated than under Windows. > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ Hi Wulfraed, I tried this (the 3GB switch). But python still crashes. kind regards, henk-jan From davea at ieee.org Sat Feb 13 07:48:30 2010 From: davea at ieee.org (Dave Angel) Date: Sat, 13 Feb 2010 07:48:30 -0500 Subject: python crash on windows but not on linux In-Reply-To: <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> Message-ID: <4B769F9E.6040402@ieee.org> hjebbers wrote: > On Feb 13, 10:25 am, Dennis Lee Bieber wrote: > >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers >> declaimed the following in gmane.comp.python.general: >> >> >>> What strikes me is: >>> 1. the crash on windows, but linux works OK (same test sets) >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as >>> much). >>> >> Which on its own does not mean much. >> >> Windows in a normal installation only grants 2GB address space to >> user code, reserving the other 2GB space for the OS shared libraries. If >> your program attempts to allocate over that, it will fail. That the >> Windows box has twice the physical memory only means it doesn't resort >> to page swapping as soon. >> >> There is a boot parameter switch that toggles Windows into a 3GB >> user/1GB OS mode -- >> > > hey, that would be great!! on my 1,5G mahcine ;-) > > > >> it is mainly meant for server machines where there >> won't be many disjoint OS libraries loaded, but the server applications >> need lots of data space. >> >> What split does the Linux OS use? If it give 3GB to user space, >> while you'd start to page swap much soon, you'd also have 50% more >> virtual memory that can be allocated than under Windows. >> -- >> Wulfraed Dennis Lee Bieber KD6MOG >> wlfr... at ix.netcom.com HTTP://wlfraed.home.netcom.com/ >> > > I will check this.....any advice on how to check this? > > henk-jan > > As I posted in recent thread on Tutor, But the one you might want is a boot.ini option that tells the OS to only reserve 1gb for itself, and leave 3gb for user space. But there are tradeoffs, including the need to modify an application's executable to take advantage of it. And the whole system may run substantially slower, even when your're extended app isn't running. See links: http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx http://blogs.technet.com/askperf/archive/2007/03/23/memory-management-demystifying-3gb.aspx DaveA From eadrogue at gmx.net Sat Feb 13 07:51:09 2010 From: eadrogue at gmx.net (Ernest =?iso-8859-1?Q?Adrogu=E9?=) Date: Sat, 13 Feb 2010 13:51:09 +0100 Subject: how do I write a scliceable class? Message-ID: <20100213125109.GA15741@doriath.local> Hello everybody, I'm designing a container class that supports slicing. The problem is that I don't really know how to do it. class MyClass(object): def __init__(self, input_data): self._data = transform_input(input_data) def __getitem__(self, key): if isinstance(key, slice): # return a slice of self pass else: # return a scalar value return self._data[key] The question is how to return a slice of self. First I need to create a new instance... but how? I can't use MyClass(self._data[key]) because the __init__ method expects a different kind of input data. Another option is out = MyClass.__new__(MyClass) out._data = self._data[key] return out But then the __init__ method is not called, which is undesirable because subclasses of this class might need to set some custom settings in their __init__ method. So what is there to do? Any suggestion? Cheers. Ernest From steve at holdenweb.com Sat Feb 13 08:14:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Feb 2010 08:14:29 -0500 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Mark Lawrence wrote: > Gabriel Genellina wrote: >> En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle >> escribi?: >> >>> I posted an example of a decorator that does just this in this thread a >>> couple of days ago: >>> >>> http://mail.python.org/pipermail/python-list/2010-February/1235742.html >> >> Ouch! I didn't see your post, nor several other earlier posts in this >> thread. In fact, I thought mine was the *first* reply when I wrote it! > > It's not just me then. I'm using Thunderbird on Windows Vista to view > the group via gmane, and notice the earlier parts of a thread can show > up hours or even days after the later ones. Would something who > understands these things be kind enough to explain why this happens, or > at least provide the keywords needed for google, as I haven't got a clue > where to start. > There are two main channels feeding the comp.lang.python newsgroup. Gmane is primarily a news (NNTP-based) service, though for reasons best know to the organizers they choose to rename the standard newsgroups to fit their own idea of how the universe should be organized, so there the group becomes gmane.comp.python.general. The first feed is the general interchange of articles between NNTP servers: while this is usually a reliable interchange mechanism, an individual server can "glitch" occasionally (by losing network connectivity, for example, or when some part of its news support mechanism breaks temporarily). The second is the python-list mailing list, maintained as a part of the python.org infrastructure (by a hard-working team of volunteers, I should add, who get little enough credit for the sterling work they do day in day out to keep the real information flowing and the spam out). More recently the waters have been muddied by Google Groups, which sadly seems at time to be so badly managed (or simply not managed?) as to make it a principal source of spam. This surprises me, as Gmail appears to have very effective spam filtering. Many people appear to use Google Groups as their primary interface to newsgroups and/or mailing lists to the extent that they believe the Groups interface to be what everyone uses to access the list. The task of maintaining a two-way bridge between the comp.lang.python NNTP community and the python-list email community while filtering out the spam and ensuring that posts aren't duplicated too often is a difficult one. For example, I hit "reply all" to your message, and had I not trimmed the headers my NNTP client (Thunderbird) would have sent copies to you, to the mailing list AND to the newsgroup. Sometimes such messages do appear twice, particularly (in my experience) to recipients who use the email channel. In short, these things happen because life is complicated and the technical solutions available to disambiguate the feeds aren't perfect. So you might consider filing the glitches under "shit happens". Speaking personally I wouldn't have a clue how to keep this stuff going on a daily basis at the volume level we see on this group, and I am very grateful to everyone who does. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Sat Feb 13 08:20:15 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 14:20:15 +0100 Subject: how do I write a scliceable class? In-Reply-To: References: Message-ID: * Ernest Adrogu?: > Hello everybody, > > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. I'd go for it anyway, because the programmer who subclasses needs to understand the base class. And if, say, that class has a custom _init method, and it's documented that that what's a subclass should override, then, OK. No problem. > So what is there to do? Any suggestion? An alternative can be to simply check for argument value None in the constructor, and if so, don't do anything. Cheers & hth., - Alf From deets at nospam.web.de Sat Feb 13 08:23:15 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 14:23:15 +0100 Subject: how do I write a scliceable class? In-Reply-To: References: Message-ID: <4B76A7C3.2030000@nospam.web.de> Am 13.02.10 13:51, schrieb Ernest Adrogu?: > Hello everybody, > > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. I'd say you can't have your cake and eat it. Either let the constructors work with data to produce whatever state the instance really contains. If that's the case, go with your second solution. Potentially, you need to make self._data[key] some method-call that might be overridden, something along the lines of __getstate__, to make sure subclasses return all data that is relevant to them. But if you really have child-class code that needs to be run on *every* object construction, then you should make input_data optional, and pass the transformed input in for the slice-creation, bypassing the transform_input. The only other solution I can think of is to return a MyClassSlice-instance, which is just a view to MyClass instances, and restricts e.g. key-spaces. class MyClassSlice(object): def __init__(self, state, slice): self.state = state self.slice = slice def __getitem__(self, key): if isinstance(key, slice): # create subslice & return that return MyClassSlice(self.state, merged_slice(key, self.slice)) elif self.key_in_slice(key): return self._state[key] raise IndexError def key_in_slice(self, key): # this of course depends on your key-domain. Diez From breamoreboy at yahoo.co.uk Sat Feb 13 08:23:33 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 13 Feb 2010 13:23:33 +0000 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Steve Holden wrote: > Mark Lawrence wrote: >> Gabriel Genellina wrote: >>> En Fri, 12 Feb 2010 04:29:12 -0300, Arnaud Delobelle >>> escribi?: >>> >>>> I posted an example of a decorator that does just this in this thread a >>>> couple of days ago: >>>> >>>> http://mail.python.org/pipermail/python-list/2010-February/1235742.html >>> Ouch! I didn't see your post, nor several other earlier posts in this >>> thread. In fact, I thought mine was the *first* reply when I wrote it! >> It's not just me then. I'm using Thunderbird on Windows Vista to view >> the group via gmane, and notice the earlier parts of a thread can show >> up hours or even days after the later ones. Would something who >> understands these things be kind enough to explain why this happens, or >> at least provide the keywords needed for google, as I haven't got a clue >> where to start. >> > There are two main channels feeding the comp.lang.python newsgroup. > Gmane is primarily a news (NNTP-based) service, though for reasons best > know to the organizers they choose to rename the standard newsgroups to > fit their own idea of how the universe should be organized, so there the > group becomes gmane.comp.python.general. > > The first feed is the general interchange of articles between NNTP > servers: while this is usually a reliable interchange mechanism, an > individual server can "glitch" occasionally (by losing network > connectivity, for example, or when some part of its news support > mechanism breaks temporarily). > > The second is the python-list mailing list, maintained as a part of the > python.org infrastructure (by a hard-working team of volunteers, I > should add, who get little enough credit for the sterling work they do > day in day out to keep the real information flowing and the spam out). > > More recently the waters have been muddied by Google Groups, which sadly > seems at time to be so badly managed (or simply not managed?) as to make > it a principal source of spam. This surprises me, as Gmail appears to > have very effective spam filtering. Many people appear to use Google > Groups as their primary interface to newsgroups and/or mailing lists to > the extent that they believe the Groups interface to be what everyone > uses to access the list. > > The task of maintaining a two-way bridge between the comp.lang.python > NNTP community and the python-list email community while filtering out > the spam and ensuring that posts aren't duplicated too often is a > difficult one. For example, I hit "reply all" to your message, and had I > not trimmed the headers my NNTP client (Thunderbird) would have sent > copies to you, to the mailing list AND to the newsgroup. Sometimes such > messages do appear twice, particularly (in my experience) to recipients > who use the email channel. > > In short, these things happen because life is complicated and the > technical solutions available to disambiguate the feeds aren't perfect. > So you might consider filing the glitches under "shit happens". Speaking > personally I wouldn't have a clue how to keep this stuff going on a > daily basis at the volume level we see on this group, and I am very > grateful to everyone who does. > > regards > Steve Many thanks for the explanation. Kindest regards. Mark Lawrence From __peter__ at web.de Sat Feb 13 09:16:31 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 13 Feb 2010 15:16:31 +0100 Subject: how do I write a scliceable class? References: Message-ID: Ernest Adrogu? wrote: > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. > > So what is there to do? Any suggestion? Either (1) make transform_input() idempotent, i. e. ensure that transform_input(transform_input(data)) == transform_input(data) and construct the slice with MyClass(self._data[key]) or (2) require it to be invertible with inverse_transform_input(transform_input(data)) == data and make the slice with MyClass(inverse_transform_input(self._data[key])) Just stating the obvious... Peter From eadrogue at gmx.net Sat Feb 13 09:53:20 2010 From: eadrogue at gmx.net (Ernest =?iso-8859-1?Q?Adrogu=E9?=) Date: Sat, 13 Feb 2010 15:53:20 +0100 Subject: how do I write a scliceable class? In-Reply-To: References: Message-ID: <20100213145320.GA16233@doriath.local> Hi, Thanks a lot for your comments. I think I've got enough information to make a decision now. 13/02/10 @ 15:16 (+0100), thus spake Peter Otten: > Ernest Adrogu? wrote: > > > I'm designing a container class that supports slicing. > > The problem is that I don't really know how to do it. > > > > class MyClass(object): > > def __init__(self, input_data): > > self._data = transform_input(input_data) > > def __getitem__(self, key): > > if isinstance(key, slice): > > # return a slice of self > > pass > > else: > > # return a scalar value > > return self._data[key] > > > > The question is how to return a slice of self. > > First I need to create a new instance... but how? I can't > > use MyClass(self._data[key]) because the __init__ method > > expects a different kind of input data. > > > > Another option is > > > > out = MyClass.__new__(MyClass) > > out._data = self._data[key] > > return out > > > > But then the __init__ method is not called, which is > > undesirable because subclasses of this class might need > > to set some custom settings in their __init__ method. > > > > So what is there to do? Any suggestion? > > Either > > (1) make transform_input() idempotent, i. e. ensure that > > transform_input(transform_input(data)) == transform_input(data) > > and construct the slice with MyClass(self._data[key]) > > or > > (2) require it to be invertible with > > inverse_transform_input(transform_input(data)) == data > > and make the slice with MyClass(inverse_transform_input(self._data[key])) > > Just stating the obvious... > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list From invalid at invalid.invalid Sat Feb 13 10:14:58 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 13 Feb 2010 15:14:58 +0000 (UTC) Subject: concatenate fasta file References: <62a50def-e391-4585-9a23-fb91f2e2edc8@b9g2000pri.googlegroups.com> Message-ID: On 2010-02-12, PeroMHC wrote: > Hi All, I have a simple problem that I hope somebody can help with. I > have an input file (a fasta file) that I need to edit.. > > Input file format > >>name 1 > tactcatacatac >>name 2 > acggtggcat >>name 3 > gggtaccacgtt > > I need to concatenate the sequences.. make them look like > >>concatenated > tactcatacatacacggtggcatgggtaccacgtt (echo "concantenated>"; grep '^ [actg]*$' inputfile | tr -d '\n'; echo) > outputfile -- Grant From aahz at pythoncraft.com Sat Feb 13 10:26:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 07:26:52 -0800 Subject: Create a backslash-escaped version of a string? References: Message-ID: In article , boblatest wrote: > >I'd like to have control characters in a string to be converted to >their backslash-escaped counterparts. I looked in the encoders section >of the string module but couldn't find anything appropriate. I could >write it myself but I'm sure something of the sort exists. The >hypothetical method "c_escaped()" would work like this: > >>>> a="abc\rdef" >>>> print a.c_escaped() >abc\rdef >>>> This is a little different from what you want, but just for the sake of completeness: >>> print repr(a)[1:-1] abc\rdef -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Sat Feb 13 10:31:03 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 07:31:03 -0800 Subject: Modifying Class Object References: Message-ID: In article , Steve Holden wrote: > >Whether in CPython, Jython or IronPython the value returned by calling >id(x) (whether x is a literal, a simple name or a more complex >expression) is absolutely no use as an accessor: it does not give you >access to the referenced value. > >If you disagree, please write (in any implementation you like: it need >not even be portable, though I can't imagine why ti wouldn't be) a >Python function which takes an id() value as its argument and returns >the value for which the id() value was provided. IIRC, I've seen ctypes code that uses id() to get access to the object, but (obviously) I don't think that invalidates your point[er]. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Sat Feb 13 10:40:29 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 07:40:29 -0800 Subject: Modifying Class Object References: <5e12bb21-f1bc-4b43-a6ed-650d1c018e5d@o3g2000yqb.googlegroups.com> Message-ID: In article , Dennis Lee Bieber wrote: >On Fri, 12 Feb 2010 18:23:46 -0800 (PST), rantingrick > declaimed the following in >gmane.comp.python.general: >> >> This entire thread has imploded like a neutron star into an infantile >> debate that only Caddie Couric, Bill O Reilly, and everyone on PMS-NBC >> can hold a candle to! The only post i enjoyed was Steve Howes! > >{Hmm, I don't recall ever seeing a "rantingrick" on the group before... >could it be... a... "sockpuppet"?} Zie's been around a while. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From sparks.m at gmail.com Sat Feb 13 10:59:42 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Sat, 13 Feb 2010 07:59:42 -0800 (PST) Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> Message-ID: <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Hi Alf, On Feb 12, 8:22 pm, "Alf P. Steinbach" wrote: > Thanks for the effort at non-flaming discussion, it *is* > appreciated. I would appreciate it if you tried to be non-flaming yourself, since you can see I am not flaming you. I was seeking to educate you on a simple matter which you seem to be misunderstanding in python. This will be my second and last attempt to do so since you chose to be inflammatory in your response. (In case you do not understand what I find inflammatory, I will discuss that at the end) Please note below I may use CAPS occasionally. Whilst usually taken as shouting, I mean them as BOLD. Please be aware of this :-) My reason for choosing to do reply is for the simple reason that recently I had similar discussions with a colleague who was likewise stuck talking about implementation aspects (call by reference/value rather than call with object/sharing). > > Before I start, note we're talking about semantics, not > > implementation. That distinction is very important. > > Yes. [ inflammatory comment snipped] Good - common ground - a good starting point. Now, if I define a language, this has 3 main parts: * Syntax * Semantics * Implementation The syntax of python is simply and shortly defined in a machine readable format, and is therefore not interesting to discuss here. The implementation of python is similarly well defined. There are multiple such implementations, one of which is CPython. > However, all those references to implementation aspects, > persisting [ inflammatory comment snipped] In theory when talking about a language, we do not need to talk about implementation details. However when using a language, implementation details do matter as well. That's why people talk about implementation aspects. When talking about how the language is defined, you need to talk about how the language is defined. It's not defined in terms of Java pointers or references. It's defined in terms of objects and names. (Or objects and labels) The exception to this is with pure functional language. In a pure functional language I do not care about implementation details, since they are outside the scope of the language. It is worth noting that python and functional languages share a common ethos - though with different conclusions - that optimising for the programmers expression of the problem rather than for the machine *matters*. If you miss this, you will be stuck misunderstanding python, pretty much forever. If you (the reader, not necessarily Alf) understand this, good. If you don't, you need to re-read this and really understand it. (please bear in mind when I say "YOU" in that paragraph, I mean "whomever is reading this", not anyone specific) Let's get down to brass tacks. In python, the LANGUAGE, there are no pointers or references, much like in SML, haskell and friends there are no pointers or references. I'm using SML here as an example, because it is conceptually close to python in terms to some aspects of evaluation and how it deals with names and values. (There are many differences as well, but we're dealing with calling, names & values, in which they are close enough) Taking an example from SML: structure Stk = struct exception EmptyStack; datatype 'x stack = EmptyStack | push of ('x * 'x stack); fun pop(push(x,y)) = y | pop EmptyStack = raise EmptyStack; fun top(push(x,y)) = x | top EmptyStack = raise EmptyStack; end; This may be used, say from the interactive prompt, as follows: val x = EmptyStack; (* 1 *) val 'x = x; (* 2 *) val y = push(5,'x); (* 3 *) val z = push(4,y); (* 4 *) top z; (* 5 *) Now, in this example, in SML, there are only names and values. Unlike python, all values are immutable, and theoretically, no sequencing of statements. Now line 1 takes the EmptyStack value, and the name x is bound to it. Line 2 takes that same EmptyStack value, and the name 'x is also bound to it. There are no pointers in SML, just names and values. Like python, SML has aliases. 'x for example is an alias for x. However that is just a symbolic name for the object itself. When line 3 is evaluated, the value push(5, 'x) is bound to the name y. Note - push(5, 'x) is in itself a value in SML, because it has been defined as such in the Datatype definition in the structure definition Stk. When we reach line 5, the function top is called with the value that z is bound to. Not a reference. Not a pointer. The actual value. In this case z's value is push(4,push(5,EmptyStack)). Thus the SML runtime evaluates the expression top push(4,push(5,EmptyStack)) And returns the value 4. In python, I don't have such richness of ability to define values, but I have these types play with: * numbers - 1.0 , 1, 1+2i, 0x11 0777 * strings - "hello" "world" * lists - ["hello", "world" ] * tuples - ("hello", "world") * dicts - {"hello" : "world" } All of these types are defined in python as python objects. How they are implemented is irrelevant. What is relevant is that lists and dicts are mutable. The rest are not. (This mutability, along with sequencing and iteration make python different from the pure subset of SML.) However, nonetheless when I type this: def hello(world): print world hello("world") When I call "hello", with the argument "world", the language is DEFINED, that *just like SML* I am passing in that specific object. Not a copy of a value (call by value). Not a reference to the value. Not a pointer to a value. But that specific actual object. This isn't willy nilly or on a whim, that's a concious choice. [ If this makes no sense, consider that python's history comes from a CS department like SML's does, rather than from an engineering department (ala C/C++/Java). Now you might turn around and say (since you have in the thread) "but in reality you're not _really_ passing in that object, you're passing in a reference", you're wrong. If the language defines it as passing in THAT object, then it defines it as passing in THAT object. But you can come back, as you have done, over and over and claim that it's a pointer or a reference, and may even say things like "well, according to this OTHER language's definition of this word, I mean this". That's nice, but ultimately broken. Using another languages way of defining something is wrong. In python it is *defined* as passing in the object. Not a reference. Not a pointer. The object itself. If it is a pointer or reference it has a value, and refers to a value. Essentially 2 values in 1. This is part of the accepted definition of pointer or reference. "A value that allows you to find another value". By claiming that in the below: >>> stack = () >>> stack_ = stack That stack is a reference to () and that stack_ is also a reference to () _in python the language_, then I must be able to get at the value of stack itself, and the value of stack_ itself. You claim to be able to do this thus: >>> id(stack) 3078742060L >>> id(stack_) 3078742060L On the surface of things, this sounds like a good claim, but it isn't. If it was a reference, its type would be a reference. It isn't: >>> type(id(stack)) >>> type(id(stack_)) That value is an integer. Additionally, if these "id" values were references, then I would be able to take those values and _inside the language_ retrieve the value they refer to. ie I would be able to type something like this to get this sort of behaviour: >>> refstack = id(stack) >>> refstack_ = id(stack_) >>> STACK = !refstack >>> STACK_ = !refstack_ >>> STACK () >>> STACK_ () This means one of two things: * Either "stack" by itself is a reference to (), but we cannot get at the reference itself, just the value it refers to. * OR "stack" is the preferred way of dereferencing the reference associated with stack, and to get at the actual reference we do id(stack). The problem is i) is incomplete in terms of being a reference, since we can only get at the r-value. The other one is that ii) is incomplete because we have no way of going from an l-value to an r-value. This means that *AS FAR AS THE LANGUAGE* is concerned whether the implementation looks or acts like it's implemented as call by reference or whatever, it is simpler and more correct to say that as far as the *LANGUAGE* is concerned, you pass in the object, which will be bound with a local name inside the function or method. Thus is is more correct to say that python the language only has aliases. By comparison, it's possible to demonstrate that Java does have references, because it is possible to box and unbox values to/from reference values: http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#190697 Thus whilst Java's semantics may be similar, python's differ in that Java, the language, has references and python, the language, has aliases. Now let's move to the implementation aspects. Python as a language is implemented in many languages. One of these is C. There are compilers to C (pypy), C++ (shedskin), for the JVM (Jython) and .net (Ironpython). There is also an executable operation semantics for python, which can be found here: http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ This set of operational semantics is written in Haskell. Haskell is a strictly pure, lazily evaluated language. It therefore has no pointers or references, just values and names. The implementation therefore cannot be in terms of references and pointers. Therefore to say "in reality the implementation will be passing a reference or pointer" is invalid. There is after all at least one implementation that does not rely on such machine oriented language details. What you find in terms of modelling the semantics, is that implementation is seeking to model those of the python virtual machine, and there that talks about values, objects, references and the heap. However in terms of modelling how the language is used this is not exposed at the language level. Indeed the only test it uses with regard to references involves the creation of a reference type _using_ python: class Reference(object) : pass Creating a reference: a = Ref() Setting the value the reference refers to: a.value = False Passing the reference to a function, and changing the value the reference: def bar(ref): ref.value = True bar(a) Whilst you might say "But that's wrong", note that .value on the right hand side is used for unboxing the value - it's syntactic sugar for a method call on the ref object. Specifically, it's the result of doing ref.__getattr__("value"). Likewise, ref.value on the left hand side of an equals is also syntactic sugar for boxing the value - specifically it's syntactic sugar for ref.__setattr__("value", ) That's the closest you can come to Java references in python - since otherwise you have no way to box or unbox any values. If you want to claim Python has java references with no ability to box or unbox any values, then maybe that's vaguely OK, but it's still _wrong_. You can claim it's LIKE java references, but since python doesn't have references, only aliases, you'd be wrong to claim they're the same as java references. And from a language spec - semantics, not implementation viewpoint - you'd also still be wrong because you can implement python without calling the values references. Specifically, the object model defined in src/Objects.lhs and src/ObjectTheory.lhs in the above reference operational semantics specification of python uses a functional heap to contain the objects. New objects are created there thus: rewrite (State ( heap ) envs stack ( FwApp (Prim "object" "__new__") (a_c:as) )) = (state ( heap <+> [a |-> ObjValue (new [__class__ |-> a_c]) NoneValue] ) envs stack ( BwResult a )) where a = freeAddr heap In this definition, which is compilable and executable (since it's haskell), there are no references, pointers or memory allocation. Thus to say that for this: def hello(world) print world hello("world") Saying that I *must* be passing in "world" by reference since implementation requires this, is false. In *an* implementation may do that, and indeed, it's the most obvious way of *implementing* it in many languages, but to say the language specifies it that way is incorrect. After all, in the Haskell implementation for example, the object itself is just passed in. ~~ interlude ~~ Now, if python DID add references, this would be pretty awesome because it's the most obvious way of adding in software transactional memory, since this usage of X.value is remarkably close to the way I deal with values in my implementation of software transactional memory for python which you'll find here: * http://www.kamaelia.org/STM And since python doesn't already have references, you wouldn't be changing existing semantics. This won't happen for a fair while at least for many reasons, not least the fact that there's a moratorium on language changes at present. ~~ end interlude ~~ Now if we return to CPython, we find that CPython is the most commonly used implementation of python. As a result much python code is written to work well with that implementation, rather than with any other. The CPython implementation has some limitations: * It is written in C * It cannot pass in actual objects (like haskell), only primitive values. * Therefore it has to pass in pointers to values to the parts of the subsystem that do the evaluation. * It has to track memory, and performs garbage collection. * Since it tracks garbage, it uses the parlance of garbage collection - specifically including references and reference counts. A reference count is however just a count of "who knows about this object and is keeping this alive") * All memory allocation lives in the heap, and as a result python objects sit there, and the implementation slings around pointers to these things. * Logically speaking (and at the language level), python objects may contain other objects. Specifically, a list may contain another object (or even itself). Both of these types of relationship cause the reference counts to increase. * The program running tracks the objects using names, and when an object stops being findable by another object (eg no longer in a list, and no longer labelled by someone), this is a trigger which the garbage collector can use to decide to delete the object. Given CPython is written in C, it becomes natural for CPython - the implementation - to therefore start talking about objects, pointers, references, reference counts and so on. Not only that since no programmer really likes memory leaks etc, actually knowing what the implementation is doing is *at times* useful to know. Since the language spec is tied up with a specific implementation, some of these details leak into the language of the document. So yes, as a pragmatic python programmer, I do care about reference counts. I do care about weakrefs which don't increase reference counts. I do care about when values are created and deleted. However, I only do so because of the *implementation* not because of the specification. When it comes to talking about the language, saying "it's pointers" over and over or saying "it's references" over and over or even saying "it's references/pointers as defined by java" over and over does NOT make it correct. If you move forward and accept that python THE LANGUAGE uses names and objects, and names are more like labels stuck onto objects than names of boxes that objects can sit inside, you'll move forward somewhat. If you don't, that's fine, but stating your version of "truth" as correct, when told many times you are incorrect is either ignorance, arrogance, pigheadedness or stupidity. I have chosen to believe it's ignorance, and assuming good faith. Now, I did say I'd pick out the inflammatory parts of how you've spoken to me, and I will just leave them as that. You will hopefully see how they're inflammatory and modify your behaviour in future. Please note though, I will pick out one point. I was not using Wikipedia as a means of argument by authority. I was using it as a starting point for a discussion which I thought many could use as a valid starting point - since whilst not perfect, and can be highly inaccurate in places, it does form one of the few places where people generally eventually reach some form of consensus. The fact that you've previously editted, fine. Good. That's very civic minded of you and I thank you for it. The idea that somehow bringing in an acceptable definition from some source that you've effectively stated you agree with as valid (because you've editted it), somehow invalidates the meat of my points I find a little bizarre. I'll put that down to cultural differences. Anyway, here's the points I find inflammatory, and rather than respond, I'll leave them as is. I'll also not be responding to any further mails containing inflammatory comments. You can think this stupid or annoying, but quite frankly, I don't see the point. Hopefully nothing I have said above you personally find inflammatory, if you do, I apologise in advance. I do hope that my mail has moved your understanding of python calling conventions on. I primarily do this because I hope that you do not pass on your misunderstandings as fact, when in fact they are not - because doing so would do others a disservice. Regards, Michael. Inflammatory comments (from my personal viewpoint) On Feb 12, 8:22 pm, "Alf P. Steinbach" wrote: > It would seem to readers that posters here do not grasp and are > unable to grasp that distinction. The posters here do understand that distinction. > However, all those references to implementation aspects, > persisting in the face of corrections, Stating something is a correction does not make that correction true. If I state it's call by sharing, and that happens to be the definition, then correcting me and calling it call by value or call by reference does not make that correction true. If you are told something repeatedly by many sources, perhaps consider you may be wrong. > have just, IMHO, been consistent attempts at misrepresentation. This can be taken as posters choosing to misrepresent your words, and is equivalent to the question "When did you stop beating your wife?", and equally offensive. > I'm sorry to disappoint, but no. It was a random Google hit to find > a first-year text that perhaps posters here could understand. You have been talking to many people who have been around python for sometime, including those who've worked on python's internals. Assuming that they need "educating" as CS101 students is offensive. > Not insinuiting anything about heir mental prowess or lack > thereof, No. It does - whether you like it or not. Communication is about 2 (or more) parties communicating. The sender of a message should care more about how their message is recieved than how it is sent. In my case, my goal of sending you a message was to educate. Your goal APPEARS to have the purpose of defending a position you hold strongly, to the extent of ignoring the effect on others. If you think "That's their problem", then I can just correct you, and then ignore you. If that's a misrepresentation of your goals, then maybe telling you is helpful. I don't know. I do know thoughI've made that sort of mistake in the past (not to anyone here, but I have done), and realised my mistake and been grown up enough to recognise my mistake and apologise. I feel you have made that mistake here. Whether you apologise is your call. I would. > but just something they might understand given a repeatedly > demonstrated inability to understand such basics, or even to > understand the concept of reference to a definition of a term. No, they do not agree with you. This is not the same as not understanding, or lacking the mental ability to understand "basic terms". If I said you lacked the ability to understand such basics of human interaction, you'd probably be rather offended. If, at the same time, I demonstrated a complete inability to understand such basics myself, you would find such remarks inflammatory. > Please do consider that my usage of the term "pointer" has > always, in this thread, including the first article I posted > in this thread, been with explicit reference to the Java > language spec's meaning. I understand this. What you seem to misunderstand is that others also understand this. They also understand that Pointer as viewed from the Java Language Spec *IS* a different concept. There may be similarities, but the fact that you can unbox and rebox a Java Reference (as per reference above), where you *cannot* in python because, well, you can't, IS a fundamentally different concept. Conceptually you pass in the object in python. Not the object. Java has to say you pass in a reference because Java has the concept of references which may be box and unbox values. > You may argue that those who wrote that language spec are > confused about things or whatever, but that's rather stretching > it, wouldn't you say? No it isn't, there's others who claim exactly the same thing about the Java Language Spec. In python, the language spec was written by those who wrote CPython, therefore their terms are clouded by concrete details. If they weren't, they'd use the term aliases more often. > So, this must be the most silly "argument by authority" > ever offered. This is inflammatory because you are deriding my premise as "silly" because you have chosen to not ask yourself *why* I chose to use that as a starting point, and then chose to ignore all my points and arguments, deriding it as "silly". That's rather inflammatory when someone is seeking to educate you in the hope of making it such that you understand better and those you come in contact with learn the correct semantics, rather than what you think the semantics are, despite being told otherwise. > I find that amusing and would have included a smiley except that > I think that that would incur further flames. Please not I have not flamed you. I have ignored your inflammatory remarks except to note how I find them inflammatory towards myself and others. The assumption that I would flame you I do actually find relatively offensive. I've stayed out of many flame wars for many years, and generally find that seeking to understand why the opposing side in an argument is saying what they do can actually often either resolve differences or lead to an agreement to disagree. Likewise I have tried to stay away from making suggestions as to how you should change your behaviour since that could be considered inflammatory by some. > It's no criticism of you; I do appreciate your effort, thanks. This comes across as dismissive, given you ignored the entire body of my mail, and decided to deride it as "silly". > And I reiterate that the meaning of "pointer" I have used is > the meaning in the Java language spec. This assumes I have not read the thread. I have. I read the statement above numerous times. I also however have read the Java Language Spec (you are not the only person to have done this of course), and do NOT agree with you. Indeed I can see usecases where *adding* references to python, the language, could be useful. However, since they're not there, I can't. > And that that's about semantics, not about implementation, > and not about C pointers or Pascal pointers or whatever else > that some would rather wish it was. Unfortunately, you have picked a language whose semantics for references include the concept of being able to box and unbox object references. You cannot do that in python. Boxing and unboxing references is just another term for referencing and dereferencing values. Again, something you can't do in python. Again, by ignoring the meat of my argument and reiterating your point, you come across as willfulling ignoring logical rational arguments put your way in as non-inflammatory was as possible, decrying all those who disagree with you as somehow stupid, misrepresentational or ignorant. By doing so, your mail as a whole is rather inflammatory, but I've decided to only send one mail in reply to you and then leave it at that. > In the following that I snipped you had good discussion except > for (as I could see) a fallacy-based denial of references > existing in Python. No, it's not denial, it's an understanding of programming languages borne from having used a wide variety of languages from Assembler (Z80, 6502, 6800), BASIC, pascal, C, C++, Java, COBOL, Occam, Fortran, Perl, Python, Ruby, E, SML, Haskell, Prolog, Lisp, and several others I've probably forgotten I've used now over well over a quarter of century of usage. I've used languages which are reference only, object only, value only, etc. My conclusion that python is call by object sharing is based on 8 years experience of using python, and changing my views from early on viewing it as pointers/references to understand that the semantics are much closer to that of an impure functional language where you pass complex objects *themselves* (from a _semantic_ perspective). To claim that I am in "denial", somehow implies that I am either inexperienced, stupid, or unwilling to call a hammer a hammer or a screwdriver a screwdriver. I'm not. I'm simply unwilling to call a hammer a screwdriver or call a screw a nail. > I don't think there's any point in discussing that further, > because it's evidently a religious matter where rational > arguments This is inflammatory, since you dismiss my arguments now as religious rather than rational. I find that moderately disgusting and offensive. > -- and I've tried a few You have not appeared to try to understand where my argument is coming from sadly, despite me doing the same for yours. You have dismissed my disagreement as religious, rather than seeking to understanding the rational argument you have been presented, and have not argued against it. I however am seeking to be precise, by choosing NOT to use terms like reference, because they are incorrect. > -- don't reach, in spite of the extreme triviality of the > subject matter. Far from being trivial, understanding that you cannot unbox "the value" of a python object is rather fundamental to the understanding of python. Understanding that you are passing around (logically speaking) the actual object explains for example why this style of coding confuses people when they start with python: >>> class MyObject(object): ... def __init__(self, store=[]): ... self.store = store ... def append(self, X): ... self.store.append(X) ... def pop(self): ... return self.store.pop() ... >>> X = MyObject() >>> Y = MyObject() >>> X.append(10) >>> Y.pop() 10 The misunderstanding that people have is that they assume that this: ... def __init__(self, store=[]): Results in a new empty object being created every time, whereas actually it's created at the point the def statement is run, specifically here: >>> MyObject.__init__.im_func.func_defaults ([],) The fact I can get *an* object id thus: >>> id(MyObject.__init__.im_func.func_defaults[0]) 3078510124L >>> id(X.store) 3078510124L >>> id(Y.store) 3078510124L Is pretty irrelevant. It's not a reference - it's an opaque value that happens to be useful when debugging for telling whether I've got the same object or not. Otherwise the objects themselves would have no default name, and no way of telling if THIS list is different fron THAT list. However, by understanding that the [] object is created when the def statement is evaluated and the object reused by all subsequent calls, rather than being created when the object is called explains much more clearly WHY the code works the way it does. Yes, you can make a similar argument in terms of references, and under the hood that's what happens with pointers to an empty list object stored on the heap. However, in terms of semantics, it's an actual python object, not a reference. After all python is a HUMAN oriented language, not a machine oriented language. A reference says "this thing over here". An object is a thing. The latter is more HUMAN, the former is machine oriented. > Thanks for the effort at non-flaming discussion, > it *is* appreciated. It does not appear that way, since you have chosen to assume that I don't understand the thrust of your arguments, rather than disagree with them. You have chosen to assume that my arguments are wrong and used or made for religious reasons rather than rational ones - such as the desire to be precise. I sincerely hope that my reply does not offend or inflame you, since that is not the intent. I do hope it educates you and puts into context the responses you have gained from others. After all, one simply shouting in a corner saying "YOU'RE ALL WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to understand what one is talking about does not tend to engender warm fluffy feelings or sentiments of authority towards such an individual. Be it me, you, or anyone else. At the moment, you appear to me to be engaging in such a behaviour. Now you don't know from Jack and probably don't care about my viewpoint, but I would really appreciate it if you would try not to be inflammatory in your response to this. (Since you do appear to also have a need to have the last word) Hoping this was useful on some level, Michael. From alfps at start.no Sat Feb 13 11:08:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 17:08:11 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Aahz: > In article , > Steve Holden wrote: >> Whether in CPython, Jython or IronPython the value returned by calling >> id(x) (whether x is a literal, a simple name or a more complex >> expression) is absolutely no use as an accessor: it does not give you >> access to the referenced value. >> >> If you disagree, please write (in any implementation you like: it need >> not even be portable, though I can't imagine why ti wouldn't be) a >> Python function which takes an id() value as its argument and returns >> the value for which the id() value was provided. > > IIRC, I've seen ctypes code that uses id() to get access to the object, Dino Viehland gave this code: Just for fun this works in IronPython 2.6: >>> >>> import clr >>> >>> clr.AddReference('Microsoft.Dynamic') >>> >>> from Microsoft.Scripting.Runtime import IdDispenser >>> >>> x = object() >>> >>> id(x) 43 >>> >>> IdDispenser.GetObject(43) >>> >>> IdDispenser.GetObject(43) is x True > but (obviously) I don't think that invalidates your point[er]. For my part I didn't think the above would be possible without enumerating all objects. I'm guessing that Steve didn't think so either. However, I seriously doubt that an agreement with my earlier statements of that was his point, considering the "if" above, which seems to imply to the reader that instead I'd argued what he's challenging. Perhaps Steve was just confused. My original statement, with reference to the Java language spec, didn't say much more about the language than that it has assignable references. It took a long time to get the wild horses reined in in that direction. But then two others ended up arguing that Python does not have references, with one of them maintaining that "refers to" in the language spec does not mean "refers to", but instead means "refers to", so I'm guessing it's religious, yes? Cheers, - Alf From as at sci.fi Sat Feb 13 11:18:15 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 13 Feb 2010 18:18:15 +0200 Subject: MemoryError, can I use more? References: Message-ID: Nobody writes: > A single process can't use much more than 2GiB of RAM without a 64-bit CPU > and OS. That's not really true. Even Windows XP has the /3GB boot option to allow 3 GiB per process. On PCs, free operating systems and server Windows can use PAE to give access to full 4 GB per process. From robert.kern at gmail.com Sat Feb 13 11:33:53 2010 From: robert.kern at gmail.com (Robert Kern) Date: Sat, 13 Feb 2010 10:33:53 -0600 Subject: how do I write a scliceable class? In-Reply-To: <20100213125109.GA15741@doriath.local> References: <20100213125109.GA15741@doriath.local> Message-ID: On 2010-02-13 06:51 , Ernest Adrogu? wrote: > Hello everybody, > > I'm designing a container class that supports slicing. > The problem is that I don't really know how to do it. > > class MyClass(object): > def __init__(self, input_data): > self._data = transform_input(input_data) > def __getitem__(self, key): > if isinstance(key, slice): > # return a slice of self > pass > else: > # return a scalar value > return self._data[key] > > The question is how to return a slice of self. > First I need to create a new instance... but how? I can't > use MyClass(self._data[key]) because the __init__ method > expects a different kind of input data. > > Another option is > > out = MyClass.__new__(MyClass) > out._data = self._data[key] > return out > > But then the __init__ method is not called, which is > undesirable because subclasses of this class might need > to set some custom settings in their __init__ method. > > So what is there to do? Any suggestion? I highly recommend making __init__() constructors do as little computation as possible. You can add other constructors using @classmethod that do convenient transformations. -- 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 deets at nospam.web.de Sat Feb 13 11:40:21 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 17:40:21 +0100 Subject: MemoryError, can I use more? In-Reply-To: References: Message-ID: <7to2vmF2kvU1@mid.uni-berlin.de> Am 13.02.10 17:18, schrieb Anssi Saari: > Nobody writes: > >> A single process can't use much more than 2GiB of RAM without a 64-bit CPU >> and OS. > > That's not really true. Even Windows XP has the /3GB boot option to > allow 3 GiB per process. On PCs, free operating systems and server > Windows can use PAE to give access to full 4 GB per process. No, PAE can be used to access much more memory than 4GB - albeit through paging. AFAIK up to 2^36 Bytes. Diez From maligree at gmail.com Sat Feb 13 11:43:04 2010 From: maligree at gmail.com (Maligree) Date: Sat, 13 Feb 2010 08:43:04 -0800 (PST) Subject: threading and signals - main thread solely responsible for signal handling? Message-ID: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> The main part of my script is a function that does many long reads (urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to display some stats, I needed to run foo() as a seperate thread to avoid getting errno 4 (interrupted system call) errors (which occur if SIGINFO is received while urlopen is setting itself up/waiting for a response). This does the job, SIGINFO is handled without ever brutally interrupting urlopen. The problem is that after starting foo as a thread, my main thread has nothing left to do - unless it receives a signal, and I am forced to keep it in some sort of loop so that ANY signal handling can still occur. I thought I'd just occupy it with a simple while 1: pass loop but that, unfortunately, means 100% CPU usage. Is there any way I could put the main thread to sleep? Or perhaps my approach is totally wrong? From bblais at bryant.edu Sat Feb 13 12:01:36 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Feb 2010 12:01:36 -0500 Subject: multiprocessing and games Message-ID: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> Hello, I've been thinking about implementing some simple games, where one can program agents to play the game. I thought that the multiprocessing module would be perfect for it, organized with a main simulator engine spawning processes for each agent. However, I am having trouble wrapping my head around the organization of the code. I haven't found a lot of examples of using multiprocessing, and no game implementations. There are two types of games that I would like to implement. In both cases, I'd like to be able to run something like: results=Sim.run('agent1.py','agent2.py') where the Sim object is initialized before with the board size, placement of pieces, etc... The files agent1.py and agent2.py would have the code to run the agent. The two types of games are different in terms of the organization of the agent code. In the first, which I think should be more straightforward, there will be one function defined in the file with syntax like: def agent(board,my_player_number): # stuff here for the agent return move Think "tic-tac-toe" here. The simulator would have to spawn processes, which load these files and handle the communication to the main simulator. The main simulator would loop through the agents, get moves, and then update the board with these moves. In the case of tic-tac-toe, then each agent is called in serial, and the update after each move. In the case of something like Civilization or Tron, the moves are all collected and then the board is updated. The other type of game, which would work like Tron or Civilization, the agent file would not contain a function but a list of commands, like: North() North() if Neighbor['North']: East() # etc... I am not sure what the best way to organize the code, in either case, for the main simulator or the best way to use multiprocessing here. I thought that maybe Pipe would be the best choice, and for each move there would be a send() and recv() between each agent and the main simulator, where the agent would receive updated information after each move. What happens if an agent has an infinite loop (ignores a signal from the simulator that it has lost)? Can the simulator catch this, and kill the process? Does that happen if either side closes the pipe? Is there an obvious way to structure this sort of game engine? Is there an implementation already out there that I am reinventing? What information would be best to send to the agent? I was finding myself using more global variables than I was comfortable, so I figured I was thinking about this incorrectly. Any help would be great! Pointers to other examples of using multiprocessing, especially with games, would be fantastic. thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Sat Feb 13 12:02:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Feb 2010 17:02:53 +0000 Subject: threading and signals - main thread solely responsible for signal handling? In-Reply-To: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> References: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> Message-ID: <4B76DB3D.9010603@mrabarnett.plus.com> Maligree wrote: > The main part of my script is a function that does many long reads > (urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to > display some stats, I needed to run foo() as a seperate thread to > avoid getting errno 4 (interrupted system call) errors (which occur if > SIGINFO is received while urlopen is setting itself up/waiting for a > response). This does the job, SIGINFO is handled without ever brutally > interrupting urlopen. > > The problem is that after starting foo as a thread, my main thread has > nothing left to do - unless it receives a signal, and I am forced to > keep it in some sort of loop so that ANY signal handling can still > occur. I thought I'd just occupy it with a simple while 1: pass loop > but that, unfortunately, means 100% CPU usage. > > Is there any way I could put the main thread to sleep? Or perhaps my > approach is totally wrong? > The simplest fix is to call time.sleep(seconds) in the loop. Repeated sleeps of 1 second, for example, consume very little CPU time. From exarkun at twistedmatrix.com Sat Feb 13 12:22:26 2010 From: exarkun at twistedmatrix.com (exarkun at twistedmatrix.com) Date: Sat, 13 Feb 2010 17:22:26 -0000 Subject: threading and signals - main thread solely responsible for signal handling? In-Reply-To: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> References: <08ff88fe-17fa-4091-9f81-4c3a7a33a1cb@d37g2000yqa.googlegroups.com> Message-ID: <20100213172226.26099.213963272.divmod.xquotient.1291@localhost.localdomain> On 04:43 pm, maligree at gmail.com wrote: >The main part of my script is a function that does many long reads >(urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to >display some stats, I needed to run foo() as a seperate thread to >avoid getting errno 4 (interrupted system call) errors (which occur if >SIGINFO is received while urlopen is setting itself up/waiting for a >response). This does the job, SIGINFO is handled without ever brutally >interrupting urlopen. > >The problem is that after starting foo as a thread, my main thread has >nothing left to do - unless it receives a signal, and I am forced to >keep it in some sort of loop so that ANY signal handling can still >occur. I thought I'd just occupy it with a simple while 1: pass loop >but that, unfortunately, means 100% CPU usage. > >Is there any way I could put the main thread to sleep? Or perhaps my >approach is totally wrong? I don't think those two options are mutually exclusive. ;) MRAB suggested you time.sleep() in a loop, which is probably fine. However, if you want to have even /less/ activity than that in the main thread, take a look at signal.pause(). Also, perhaps not terribly interesting, signal.siginterrupt() was recently introduced, which will let you avoid EINTR if SIGINFO is received while urlopen is in a syscall (but will also prevent the signal from being handled until the syscall returns on its own). And there's always Twisted & friends. :) Jean-Paul From python at mrabarnett.plus.com Sat Feb 13 12:54:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Feb 2010 17:54:33 +0000 Subject: multiprocessing and games In-Reply-To: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> References: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> Message-ID: <4B76E759.3010503@mrabarnett.plus.com> Brian Blais wrote: > Hello, > > I've been thinking about implementing some simple games, where one can > program agents to play the game. I thought that the multiprocessing > module would be perfect for it, organized with a main simulator engine > spawning processes for each agent. However, I am having trouble > wrapping my head around the organization of the code. I haven't found a > lot of examples of using multiprocessing, and no game implementations. > > There are two types of games that I would like to implement. In both > cases, I'd like to be able to run something like: > > results=Sim.run('agent1.py','agent2.py') > > where the Sim object is initialized before with the board size, > placement of pieces, etc... The files agent1.py and agent2.py would > have the code to run the agent. The two types of games are different in > terms of the organization of the agent code. In the first, which I > think should be more straightforward, there will be one function defined > in the file with syntax like: > > def agent(board,my_player_number): > # stuff here for the agent > return move > > Think "tic-tac-toe" here. The simulator would have to spawn processes, > which load these files and handle the communication to the main > simulator. The main simulator would loop through the agents, get moves, > and then update the board with these moves. In the case of tic-tac-toe, > then each agent is called in serial, and the update after each move. In > the case of something like Civilization or Tron, the moves are all > collected and then the board is updated. > > The other type of game, which would work like Tron or Civilization, the > agent file would not contain a function but a list of commands, like: > > North() > North() > if Neighbor['North']: > East() > # etc... > > I am not sure what the best way to organize the code, in either case, > for the main simulator or the best way to use multiprocessing here. I > thought that maybe Pipe would be the best choice, and for each move > there would be a send() and recv() between each agent and the main > simulator, where the agent would receive updated information after each > move. What happens if an agent has an infinite loop (ignores a signal > from the simulator that it has lost)? Can the simulator catch this, and > kill the process? Does that happen if either side closes the pipe? Is > there an obvious way to structure this sort of game engine? Is there an > implementation already out there that I am reinventing? What > information would be best to send to the agent? I was finding myself > using more global variables than I was comfortable, so I figured I was > thinking about this incorrectly. > > > Any help would be great! Pointers to other examples of using > multiprocessing, especially with games, would be fantastic. > Forget about global variables, they're not worth it! :-) Think in terms of messages, sent via pipes, sockets or multiprocessing queues. In a game like "tic-tac-toe" (also known as "noughts and crosses", BTW), the sim sends a message to an agent requesting a move ("what's your move"). The agent can send requests for the state of the board ("what's at position (x, y)?") and get replies ("it's a X"/"it's a O"/"it's empty"), but at some point it must send the sim its move ("put a piece at (x, y)") and the sim can say whether it's valid ("OK"/"bad move"). If the agent takes too long then the sim sends just tells the agent that it took too long and should quit ("quit"). From as at sci.fi Sat Feb 13 13:52:41 2010 From: as at sci.fi (Anssi Saari) Date: Sat, 13 Feb 2010 20:52:41 +0200 Subject: MemoryError, can I use more? References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" writes: > Am 13.02.10 17:18, schrieb Anssi Saari: >> Nobody writes: >> >>> A single process can't use much more than 2GiB of RAM without a 64-bit CPU >>> and OS. >> >> That's not really true. Even Windows XP has the /3GB boot option to >> allow 3 GiB per process. On PCs, free operating systems and server >> Windows can use PAE to give access to full 4 GB per process. > > No, PAE can be used to access much more memory than 4GB - albeit > through paging. AFAIK up to 2^36 Bytes. That too. I admit, after checking, that you can't go above 3 GiB per process even in server Windows. But for Linux there exists (or existed, since it seems it hasn't been updated since 2004) a kernel patch which provides a "4GB/4GB" address split. Kernel is in one segment, userland in another and hence a process can access full 4GB. From m.faustino at gmail.com Sat Feb 13 14:31:47 2010 From: m.faustino at gmail.com (=?ISO-8859-1?Q?M=E1rcio_Faustino?=) Date: Sat, 13 Feb 2010 11:31:47 -0800 (PST) Subject: MemoryError in imaplib? Message-ID: <79bafa50-1f13-4b7a-9f3b-937cb2860c80@d37g2000yqa.googlegroups.com> Hi, When using "imaplib" to fetch e-mail messages, the "IMAP4_SSL.read" and "IMAP4_SSL.readline" functions sometimes throw a "MemoryError" exception in "chunks.append(data)" and "line.append(char)", respectively. But if I change those functions to use instead a "cStringIO" buffer object, then that exception doesn't get thrown. Is this normal? I've seen this happen with Python 2.6.4 in both Windows XP 32-bit and Windows 7 64-bit. Thanks, From gnarlodious at gmail.com Sat Feb 13 14:46:26 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 13 Feb 2010 11:46:26 -0800 (PST) Subject: Py3: Terminal or browser output? Message-ID: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Hello, searched all over but no success. I want to have a script output HTML if run in a browser and plain text if run in a Terminal. In Python 2, I just said this: if len(sys.argv)==True: and it seemed to work. Py3 must have broken that by sending a list with the path to the script in BOTH the browser and Terminal. Is there some newfangled way to determine what is running the script (hopefully without a try wrapper)? -- Gnarlie From news123 at free.fr Sat Feb 13 14:55:05 2010 From: news123 at free.fr (News123) Date: Sat, 13 Feb 2010 20:55:05 +0100 Subject: how to make a SimpleXMLRPCServer abort at CTRL-C under windows In-Reply-To: <4b6e0841$0$22047$426a74cc@news.free.fr> References: <4b6ca3d7$0$23509$426a74cc@news.free.fr> <4b6e0841$0$22047$426a74cc@news.free.fr> Message-ID: <4b77039a$0$12387$426a74cc@news.free.fr> Hi Gabriel, News123 wrote: > Hi Gabriel, > > Gabriel Genellina wrote: >> En Fri, 05 Feb 2010 20:03:51 -0300, News123 escribi?: >> >>> I'm using an XMLRPC server under Windows. >>> >>> What I wonder is how I could create a server, that can be killed with >>> CTRL-C >>> >>> The server aborts easily with CTRL-BREAK but not with CTRL-C (under >>> Windows) >>> >>> If I press CTRL-C it will only abort when the next RPC call occurs. >>> It seems it is blocking in the select() call in the handle_request() >>> function. >> Python 2.6 and up behaves exactly as you want. >> On previous versions you may use this: >> >> class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer): >> >> ... your methods ... >> >> if not hasattr(SimpleXMLRPCServer.SimpleXMLRPCServer, 'shutdown'): >> >> # pre 2.6 >> quit = False >> >> def serve_forever(self): >> while not self.quit: >> self.handle_request() >> >> def shutdown(self): >> self.quit = True >> >> def server_bind(self): >> self.socket.settimeout(1.0) >> SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self) >> > > Overloading server_bind() with your version solved my problem. > Overloading server_bind() makes the server killable with ctrl-C. I noticed however, that I can't use this as solution. If the bind function sets a time out, then it seems, that there are regular small time windows, when connecting clients fail. I don't have the error message any more, but will post it when I capture the event next time. bye N From mattbarkan at gmail.com Sat Feb 13 15:03:28 2010 From: mattbarkan at gmail.com (galileo228) Date: Sat, 13 Feb 2010 12:03:28 -0800 (PST) Subject: python and http POST References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <12f5dcf0-74aa-4c10-960e-90946d1ed853@b18g2000vba.googlegroups.com> Thank you all for your responses, and Javier thank you for your longer response. I've just downloaded mechanize and beautifulsoup and will start to play around. >From a pure learning standpoint, however, I'd really like to learn how to use the python post method (without mechanize) to go to a webpage, fill in a form, click 'submit', follow the redirect to the results page, and download content. For example, if I go to google.com, use firebug and click on the search bar, the following HTML is highlighted: So if I were to use the 'post' method, how can I tell from the code above what the ID of the searchbar is? Is it 'value', 'name', or neither? Assuming that the ID is 'name', then to search google for the term 'olypmics' would the proper code be: import httplib2 import urllib data = {'q':'olympics'} body = urllib.urlencode(data) h = httplib2.Http() resp, content = h.request("http://www.google.com", method="POST", body=body) print content; Does content return the content of the 'search results' page? And if not, how do I tell python to do that? Finally, must I transmit headers, or are they optional? Thanks all for your continued help! Matt On Feb 12, 2:59?am, Javier Collado wrote: > Hello, > > I haven't used httplib2, but you can certainly use any other > alternative to send HTTP requests: > - urllib/urllib2 > - mechanize > > With regard to how do you find the form you're looking for, you may: > - create the HTTP request on your own with urllib2. To find out what > variables do you need to post, you can use tamperdata Firefox addon as > suggested (I haven't used that one) or httpfox (I have and it works > great). > - use mechanize to locate the form for you, fill the data in and click > on the submit button. > > Additionally, you may wan to scrape some data that may be useful for > your requests. For that BeautifulSoup is good solution (with some > Firebug help to visually locate what you're looking for). > > Best regards, > ? ? Javier > > P.S. Some examples here:http://www.packtpub.com/article/web-scraping-with-pythonhttp://www.packtpub.com/article/web-scraping-with-python-part-2 > > 2010/2/11 galileo228 : > > > Hey All, > > > Been teaching myself Python for a few weeks, and am trying to write a > > program that will go to a url, enter a string in one of the search > > fields, submit the search, and return the contents of the search > > result. > > > I'm using httplib2. > > > My two particular questions: > > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > > how do I know what the particular key should be? In other words, how > > do I tell python which form on the web page I'm visiting I'd like to > > fill in? Do I simply go to the webpage itself and look at the html > > source? But if that's the case, which tag tells me the name of the > > key? > > > 2) Even once python fills in the form properly, how can I tell it to > > 'submit' the search? > > > Thanks all! > > > Matt > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From clp2 at rebertia.com Sat Feb 13 15:16:20 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Feb 2010 12:16:20 -0800 Subject: Py3: Terminal or browser output? In-Reply-To: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: <50697b2c1002131216v4ab1e695x1e082e017f6a4fb2@mail.gmail.com> On Sat, Feb 13, 2010 at 11:46 AM, Gnarlodious wrote: > Hello, searched all over but no success. I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. > In Python 2, I just said this: > > if len(sys.argv)==True: That line doesn't make sense really as it is practically equivalent to: if len(sys.argv) == 1: Which, since argv always contains at least 1 element (the program's name), is essentially checking whether /no/ arguments were passed on the command line. Recall that issubclass(bool, int) is true and that True == 1 in Python due to details of said subclassing. Note also that "== True" is almost always unnecessary as it is essentially implicit in the "if". I suspect you instead meant to write: if len(sys.argv) > 0: which for the record can be written more idiomatically as: if sys.argv: # bool(some_list) is True if some_list is not empty Which, however, as I explained, is always true since argv is /never/ completely empty, and thus the test is useless. What you probably *wanted* is: if len(sys.argv) > 1: Which is effectively the opposite of my very first code snippet and checks whether we /were/ passed some arguments on the command line. > and it seemed to work. By happy accident I suspect, due to the aforementioned way == works between bools and ints and probably a logic error in your code. > Py3 must have broken that by sending a list > with the path to the script in BOTH the browser and Terminal. Is there > some newfangled way to determine what is running the script (hopefully > without a try wrapper)? How exactly are you running the script *"in"* the browser? Browsers can only execute JavaScript, not Python. Do you mean you're running it via a webserver? If so, there are /several/ possible ways of doing that, please explain exactly which you are using. Cheers, Chris -- http://blog.rebertia.com From mattbarkan at gmail.com Sat Feb 13 15:16:38 2010 From: mattbarkan at gmail.com (galileo228) Date: Sat, 13 Feb 2010 12:16:38 -0800 (PST) Subject: python and http POST References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <29a9914f-e5f4-4a18-93fb-3b032aebac4b@d34g2000vbl.googlegroups.com> Thank you all for your responses, and Javier thank you for your longer response. I've just downloaded mechanize and beautifulsoup and will start to play around. >From a pure learning standpoint, however, I'd really like to learn how to use the python post method (without mechanize) to go to a webpage, fill in a form, click 'submit', follow the redirect to the results page, and download content. For example, if I go to google.com, use firebug and click on the search bar, the following HTML is highlighted: So if I were to use the 'post' method, how can I tell from the code above what the ID of the searchbar is? Is it 'value', 'name', or neither? Assuming that the ID is 'name', then to search google for the term 'olypmics' would the proper code be: import httplib2 import urllib data = {'q':'olympics'} body = urllib.urlencode(data) h = httplib2.Http() resp, content = h.request("http://www.google.com", method="POST", body=body) print content; Does content return the content of the 'search results' page? And if not, how do I tell python to do that? Finally, must I transmit headers, or are they optional? Thanks all for your continued help! Matt On Feb 12, 2:59?am, Javier Collado wrote: > Hello, > > I haven't used httplib2, but you can certainly use any other > alternative to send HTTP requests: > - urllib/urllib2 > - mechanize > > With regard to how do you find the form you're looking for, you may: > - create the HTTP request on your own with urllib2. To find out what > variables do you need to post, you can use tamperdata Firefox addon as > suggested (I haven't used that one) or httpfox (I have and it works > great). > - use mechanize to locate the form for you, fill the data in and click > on the submit button. > > Additionally, you may wan to scrape some data that may be useful for > your requests. For that BeautifulSoup is good solution (with some > Firebug help to visually locate what you're looking for). > > Best regards, > ? ? Javier > > P.S. Some examples here:http://www.packtpub.com/article/web-scraping-with-pythonhttp://www.packtpub.com/article/web-scraping-with-python-part-2 > > 2010/2/11 galileo228 : > > > Hey All, > > > Been teaching myself Python for a few weeks, and am trying to write a > > program that will go to a url, enter a string in one of the search > > fields, submit the search, and return the contents of the search > > result. > > > I'm using httplib2. > > > My two particular questions: > > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > > how do I know what the particular key should be? In other words, how > > do I tell python which form on the web page I'm visiting I'd like to > > fill in? Do I simply go to the webpage itself and look at the html > > source? But if that's the case, which tag tells me the name of the > > key? > > > 2) Even once python fills in the form properly, how can I tell it to > > 'submit' the search? > > > Thanks all! > > > Matt > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From deets at nospam.web.de Sat Feb 13 15:17:15 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 13 Feb 2010 21:17:15 +0100 Subject: Py3: Terminal or browser output? In-Reply-To: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: <7tofmbFdmjU1@mid.uni-berlin.de> Am 13.02.10 20:46, schrieb Gnarlodious: > Hello, searched all over but no success. I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. > In Python 2, I just said this: > > if len(sys.argv)==True: > > and it seemed to work. Py3 must have broken that by sending a list > with the path to the script in BOTH the browser and Terminal. Is there > some newfangled way to determine what is running the script (hopefully > without a try wrapper)? I have no idea what you mean by "running python in a browser". I can only guess you mean as cgi or mod_python-skript? However, maybe if os.isatty(sys.stdout.fileno()): works for you. Or you could check for certain environment variables that are present when running as CGI or mod_python skript, but not knowing *what* you do can only lead to educated guesses at best. Diez From timr at probo.com Sat Feb 13 15:29:45 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 13 Feb 2010 12:29:45 -0800 Subject: How to measure elapsed time under Windows? References: Message-ID: <1n2en51qqliplc2u8q78l3gt2dn3vmeh8d@4ax.com> "Gabriel Genellina" wrote: > >The original problem was with the RDTSC instruction on multicore CPUs; >different cores may yield different results because they're not >synchronized at all times. Not true. The synchronization issue has two causes: initial synchronization at boot time, and power management making microscopic adjustments to the clock rate. In Windows NT 4, Microsoft took extra pains to adjust the cycle counters on multiprocessor computers during boot so that the processors started out very close together. Once set, they naturally remained in lock step, until aggressive power management because more prevalent. In XP, they stopped trying to align at boot time. >Windows XP was launched in 2001, and the first dual core processors able >to execute Windows were AMD Opteron and IBM Pentium D, both launched >around April 2005 (and targeting the server market, not the home/desktop >market of Windows XP). >How could MS know in 2001 of a hardware issue that would happen four years >in the future? No, you're underestimating the problem. The issue occurs just as much in machines with multiple processor chips, which was supported clear back in the original NT 3.1, 1992. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From gnarlodious at gmail.com Sat Feb 13 15:34:36 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 13 Feb 2010 12:34:36 -0800 (PST) Subject: Py3: Terminal or browser output? References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> <7tofmbFdmjU1@mid.uni-berlin.de> Message-ID: On Feb 13, 1:17?pm, "Diez B. Roggisch" wrote: > However, maybe > > if os.isatty(sys.stdout.fileno()): OK, this works in Python 2: #!/usr/bin/python import sys, os if __name__=="__main__": if os.isatty(sys.stdout.fileno()): print "Terminal" else: print "Content-type:text/html\n\nBROWSER" likewise in Python3: #!/usr/local/bin/python3.1 import sys, os if __name__=="__main__": if os.isatty(sys.stdout.fileno()): print("Terminal") else: print("Content-type:text/html\n\nBROWSER") Thank you, always impressed with the fast help here. -- Gnarlie From mattbarkan at gmail.com Sat Feb 13 15:37:57 2010 From: mattbarkan at gmail.com (galileo228) Date: Sat, 13 Feb 2010 12:37:57 -0800 (PST) Subject: python and http POST References: <811cc10d-d6da-4b2a-afea-0778263a23fc@o28g2000yqh.googlegroups.com> Message-ID: <5df948ae-db27-4dc4-9ceb-c0777fca7678@28g2000vbf.googlegroups.com> Thank you all for your responses, and Javier thank you for your longer response. I've just downloaded mechanize and beautifulsoup and will start to play around. >From a pure learning standpoint, however, I'd really like to learn how to use the python post method (without mechanize) to go to a webpage, fill in a form, click 'submit', follow the redirect to the results page, and download content. For example, if I go to google.com, use firebug and click on the search bar, the following HTML is highlighted: So if I were to use the 'post' method, how can I tell from the code above what the ID of the searchbar is? Is it 'value', 'name', or neither? Assuming that the ID is 'name', then to search google for the term 'olypmics' would the proper code be: import httplib2 import urllib data = {'q':'olympics'} body = urllib.urlencode(data) h = httplib2.Http() resp, content = h.request("http://www.google.com", method="POST", body=body) print content; Does content return the content of the 'search results' page? And if not, how do I tell python to do that? Finally, must I transmit headers, or are they optional? Thanks all for your continued help! Matt On Feb 12, 2:59?am, Javier Collado wrote: > Hello, > > I haven't used httplib2, but you can certainly use any other > alternative to send HTTP requests: > - urllib/urllib2 > - mechanize > > With regard to how do you find the form you're looking for, you may: > - create the HTTP request on your own with urllib2. To find out what > variables do you need to post, you can use tamperdata Firefox addon as > suggested (I haven't used that one) or httpfox (I have and it works > great). > - use mechanize to locate the form for you, fill the data in and click > on the submit button. > > Additionally, you may wan to scrape some data that may be useful for > your requests. For that BeautifulSoup is good solution (with some > Firebug help to visually locate what you're looking for). > > Best regards, > ? ? Javier > > P.S. Some examples here:http://www.packtpub.com/article/web-scraping-with-pythonhttp://www.packtpub.com/article/web-scraping-with-python-part-2 > > 2010/2/11 galileo228 : > > > Hey All, > > > Been teaching myself Python for a few weeks, and am trying to write a > > program that will go to a url, enter a string in one of the search > > fields, submit the search, and return the contents of the search > > result. > > > I'm using httplib2. > > > My two particular questions: > > > 1) When I set my 'body' var, (i.e. 'body = {'query':'search_term'}), > > how do I know what the particular key should be? In other words, how > > do I tell python which form on the web page I'm visiting I'd like to > > fill in? Do I simply go to the webpage itself and look at the html > > source? But if that's the case, which tag tells me the name of the > > key? > > > 2) Even once python fills in the form properly, how can I tell it to > > 'submit' the search? > > > Thanks all! > > > Matt > > -- > >http://mail.python.org/mailman/listinfo/python-list > > From rogerb at rogerbinns.com Sat Feb 13 17:19:17 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Sat, 13 Feb 2010 14:19:17 -0800 Subject: Py3: Terminal or browser output? In-Reply-To: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gnarlodious wrote: > I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. You may also want to look into urwid. It provides you with a text console interface but can also provide HTML. It has widgets like text boxes, lists, tick boxes etc. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkt3JWUACgkQmOOfHg372QRifACfYKS7+bmt6F3WPXYatM7yKVcs knMAoLx5sJ3lFmofrrgHaS3aYOBAun0d =Nxd4 -----END PGP SIGNATURE----- From bblais at bryant.edu Sat Feb 13 17:32:15 2010 From: bblais at bryant.edu (Brian Blais) Date: Sat, 13 Feb 2010 17:32:15 -0500 Subject: multiprocessing and games In-Reply-To: <4B76E759.3010503@mrabarnett.plus.com> References: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> <4B76E759.3010503@mrabarnett.plus.com> Message-ID: <694A55DA-6557-486A-A0D5-B3B19C8B2D6F@bryant.edu> On Feb 13, 2010, at 12:54 , MRAB wrote: > Brian Blais wrote: >> I've been thinking about implementing some simple games > Forget about global variables, they're not worth it! :-) > > Think in terms of messages, sent via pipes, sockets or multiprocessing > queues. > okay...let's make this concrete. given your ideas, I have it working for the first type of agent, namely one that is called like: move=agent(board,player) For a specific example, I'm using the simplest version of a game called Nim. You start with a number of sticks, players take turns taking 1, 2, or 3 sticks, and you lose if you take the last stick. Two agents for this are: # agent1.py - simple take 1 agent def agent(board,player): return 1 # agent2.py - perfect player def agent(board,player): move=(board-1)%4 if move==0: return 1 else: return move I run my simulator like (complete code below): s=Sim('agent1','agent2') winner=s.run() and it spawns two processes, passes messages between the sim and the agents, and closes the agents nicely when the game is over. I'm not sure how I catch errors in the agents, especially accidental infinite loops. Now the second type of agent is structured differently. I'd like something like: # agent3.py - simple take 1 agent def agent(state): while True: Take(1) # agent4.py - perfect player def agent(state): N=state['board'] # get the current information while True: move=(N-1)%4 if move==0: Take(1) else: Take(move) I tried to implement this in the second wrapper below, but I can't get the agent function to "see" local functions in the wrapper. I probably need an import somewhere, but I haven't quite figured out the scoping with multiprocessing, etc... I include the code below. The two message-passing wrappers are there, and it works for the first two agents, but not the second two because of scoping issues. Is there a better way to be doing this? Are there other examples like this that I can look at to improve what I am doing? thanks, Brian Blais -- Brian Blais bblais at bryant.edu http://web.bryant.edu/~bblais http://bblais.blogspot.com/ # testing multiprocessing with games from __future__ import with_statement from multiprocessing import Pipe,Process def wrap_agent(connection,fname): agent_module = __import__(fname) end=False while not end: state=connection.recv() if state['done']: break move=agent_module.agent(state['board'],state['player']) connection.send(move) print "%s done" % fname connection.close() def wrap_agent2(connection,fname): def Take(T): state1=connection.recv() state.update(state1) if state['done']: raise ValueError # should probably use a custom exception move=T connection.send(move) execfile(fname+".py") print locals() # seems to appear in locals state=connection.recv() if state['done']: print "%s done" % fname connection.close() return try: agent(state) except ValueError: pass print "%s done" % fname connection.close() class Sim(object): def __init__(self,agent1,agent2,type=1): self.agent_files=[agent1,agent2] self.type=type def run(self): self.processes=[] self.connections=[] for fname in self.agent_files: parent,child=Pipe() self.connections.append(parent) if self.type==1: proc=Process(target=wrap_agent, args=(child,fname,)) else: proc=Process(target=wrap_agent2, args=(child,fname,)) self.processes.append(proc) for proc in self.processes: proc.start() current_player,other_player=1,2 N=23 state={} while N>1: state['board']=N state['player']=current_player state['done']=False c=self.connections[current_player-1] print "Number of sticks: ",N c.send(state) move=c.recv() print "Player ",current_player,"takes ",move N-=move current_player,other_player=other_player,current_player print "Number of sticks: ",N # send the end signals state['done']=True for c in self.connections: c.send(state) for p in self.processes: p.join() if N==1: winner=other_player else: winner=current_player print "Winner is ",winner return winner if __name__=="__main__": s=Sim('agent1','agent2') winner=s.run() print "============" s=Sim('agent3','agent4',type=2) winner=s.run() -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sat Feb 13 17:50:38 2010 From: john at castleamber.com (John Bokma) Date: Sat, 13 Feb 2010 16:50:38 -0600 Subject: Py3: Terminal or browser output? References: <5870ec4a-59e6-4606-82de-daa06673be6a@v20g2000prb.googlegroups.com> Message-ID: <87pr48agxt.fsf@castleamber.com> Gnarlodious writes: > Hello, searched all over but no success. I want to have a script > output HTML if run in a browser and plain text if run in a Terminal. > In Python 2, I just said this: > > if len(sys.argv)==True: > > and it seemed to work. Py3 must have broken that by sending a list > with the path to the script in BOTH the browser and Terminal. Is there > some newfangled way to determine what is running the script (hopefully > without a try wrapper)? Your web server (assuming CGI) sets some environment variables, which you could test for. This has as advantage (or disadvantage) that you can set the variable at the CLI and see the output the browser could get. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alfps at start.no Sat Feb 13 17:56:58 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 13 Feb 2010 23:56:58 +0100 Subject: Modifying Class Object In-Reply-To: <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Michael Sparks: > [Due to the appearance of reasoned discussion (it's not practical to read it all!), I felt it necessary to respond. It turned out to be a long sequence of trivial fallacies, peppered with various allegations and insinuations.] [snip extremely much] > Now let's move to the implementation aspects. > > Python as a language is implemented in many languages. One of these > is C. There are compilers to C (pypy), C++ (shedskin), for the JVM > (Jython) and .net (Ironpython). > > There is also an executable operation semantics for python, > which can be found here: > > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > > This set of operational semantics is written in Haskell. > > Haskell is a strictly pure, lazily evaluated language. It > therefore has no pointers or references, just values and names. > The implementation therefore cannot be in terms of references > and pointers. At this point consider whether it's possible to implement Pascal in Haskell. If it is possible, then you have a problem wrt. drawing conclusions about pointers in Pascal, uh oh, they apparently can't exist. But if it is not possible to implement Pascal in Haskell, then Haskell must be some etremely limited special-purpose language, not Turing complete -- is that acceptable to you? > Therefore to say "in reality the implementation > will be passing a reference or pointer" is invalid. There is > after all at least one implementation that does not rely on > such machine oriented language details. I'm sorry, but see above: in itself it's just yet another a fallacy. And as an argument in a debate with me it's misrepresenting. There is need to talk about "in reality" (as if the language spec and general semantics isn't real enough) nor to talk about any specific implementation. [snip very much] > I sincerely hope that my reply does not offend or inflame you, > since that is not the intent. I do hope it educates you and > puts into context the responses you have gained from others. > > After all, one simply shouting in a corner saying "YOU'RE > ALL WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one > does not to understand what one is talking about does not > tend to engender warm fluffy feelings or sentiments of > authority towards such an individual. Be it me, you, or > anyone else. > > At the moment, you appear to me to be engaging in such a > behaviour. Now you don't know from Jack and probably don't > care about my viewpoint, but I would really appreciate it > if you would try not to be inflammatory in your response > to this. (Since you do appear to also have a need to have > the last word) > > Hoping this was useful on some level, Yes. I elected to respond to just /one/ of the many arguments you presented. The other arguments, about why there are no references in Python, shared, however, the basic property of being logical fallacies packaged in kilometers of rambling text. Cheers, - Alf From vahuja4 at gmail.com Sat Feb 13 18:44:37 2010 From: vahuja4 at gmail.com (Vish) Date: Sat, 13 Feb 2010 15:44:37 -0800 (PST) Subject: Hashing in python Message-ID: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Hi, I need to hash 3d coordinates to a grid which has been divided into 4*4*4 squares. Using python, I thought of a simple way as follows: CELL_SIZE = 4 def key(point): return ( int((floor(point[0]/CELL_SIZE))*CELL_SIZE), int((floor(point[1]/CELL_SIZE))*CELL_SIZE), int((floor(point[2]/CELL_SIZE))*CELL_SIZE) ) Since python allows keys to be tuples, I think that this should work. Is there a better (more efficient) way to do it? Thank you, Vishal From steve at holdenweb.com Sat Feb 13 18:54:52 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Feb 2010 18:54:52 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Michael Sparks: > [Due to the appearance of reasoned discussion (it's not practical to read it all!) [...] >> Therefore to say "in reality the implementation will be passing a >> reference or pointer" is invalid. There is after all at least one >> implementation that does not rely on such machine oriented language >> details. > > I'm sorry, but see above: in itself it's just yet another a fallacy. > > And as an argument in a debate with me it's misrepresenting. > I see we are still all out of step with you. If it's a fallacy then I'd like to see a reasoned logical explanation of its fallaciousness. As far as I can see, if someone says "implementing Python implies the use of pointers" as you appear to be doing, then Michael's argument neatly demolishes that argument by providing a counter-example: there is an implementation of Python that does not use pointers. You, however, dismiss this as a fallacy, and suggests it somehow misrepresents you. And yet you wonder why people call your behavior (not you) paranoid. [...] > >> I sincerely hope that my reply does not offend or inflame you, >> since that is not the intent. I do hope it educates you and puts >> into context the responses you have gained from others. >> >> After all, one simply shouting in a corner saying "YOU'RE ALL >> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >> understand what one is talking about does not tend to engender warm >> fluffy feelings or sentiments of authority towards such an >> individual. Be it me, you, or anyone else. >> >> At the moment, you appear to me to be engaging in such a behaviour. >> Now you don't know from Jack and probably don't care about my >> viewpoint, but I would really appreciate it if you would try not to >> be inflammatory in your response to this. (Since you do appear to >> also have a need to have the last word) >> >> Hoping this was useful on some level, > > Yes. > > I elected to respond to just /one/ of the many arguments you > presented. > > The other arguments, about why there are no references in Python, > shared, however, the basic property of being logical fallacies > packaged in kilometers of rambling text. > And you can say this without, by your own admission, even reading it. It makes me wonder why we have paid you the compliment of engaging you in debate, since this is the most transparent evidence to date that what comes back will be unrelated to the arguments presented. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Feb 13 19:43:34 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 00:43:34 GMT Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: <4b774736$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 07:59:42 -0800, Michael Sparks wrote: > Now, if I define a language, this has 3 main parts: > * Syntax > * Semantics > * Implementation [snip] Michael, that is remarkable. Excellent work, thank you! -- Steven From python at mrabarnett.plus.com Sat Feb 13 19:47:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 00:47:18 +0000 Subject: Hashing in python In-Reply-To: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <4B774816.4040103@mrabarnett.plus.com> Vish wrote: > Hi, > > I need to hash 3d coordinates to a grid which has been divided into > 4*4*4 squares. Using python, I thought of a simple way as follows: > > CELL_SIZE = 4 > > def key(point): > > return ( > int((floor(point[0]/CELL_SIZE))*CELL_SIZE), > int((floor(point[1]/CELL_SIZE))*CELL_SIZE), > int((floor(point[2]/CELL_SIZE))*CELL_SIZE) > ) > > > Since python allows keys to be tuples, I think that this should work. > Is there a better (more efficient) way to do it? > floor(x) returns an integer, so floor(x/CELL_SIZE)*CELL_SIZE is an integer multiple of CELL_SIZE, also an integer. There's actually no point (unintentional pun!) to multiplying by CELL_SIZE: CELL_SIZE = 4 def key(point): return ( floor(point[0] / CELL_SIZE), floor(point[1] / CELL_SIZE), floor(point[2] / CELL_SIZE) ) From d.dalton at iinet.net.au Sat Feb 13 19:48:31 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sun, 14 Feb 2010 11:48:31 +1100 Subject: working with laptop battery Message-ID: <20100214004831.GA21071@debian-eeepc> Hi, I'm constantly working in the command line and need to write a program to give me alerts on my battery. Can someone please tell me what module I should use to access battery information? Looking for something that perhaps makes use of acpi so I can get estimated time left as well as a percentage. Thanks very much for any help, Dan From alfps at start.no Sat Feb 13 19:50:01 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 01:50:01 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Michael Sparks: >> [Due to the appearance of reasoned discussion (it's not practical to read it all!) > [...] >>> Therefore to say "in reality the implementation will be passing a >>> reference or pointer" is invalid. There is after all at least one >>> implementation that does not rely on such machine oriented language >>> details. >> I'm sorry, but see above: in itself it's just yet another a fallacy. >> >> And as an argument in a debate with me it's misrepresenting. >> > I see we are still all out of step with you. Why did you snip the short argument? > If it's a fallacy then I'd > like to see a reasoned logical explanation of its fallaciousness. Oh, you snipped it so that you didn't have to present it to readers. That's dishonest, Steve Holden. Requoting: > Now let's move to the implementation aspects. > > Python as a language is implemented in many languages. One of these > is C. There are compilers to C (pypy), C++ (shedskin), for the JVM > (Jython) and .net (Ironpython). > > There is also an executable operation semantics for python, > which can be found here: > > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > > This set of operational semantics is written in Haskell. > > Haskell is a strictly pure, lazily evaluated language. It > therefore has no pointers or references, just values and names. > The implementation therefore cannot be in terms of references > and pointers. At this point consider whether it's possible to implement Pascal in Haskell. If it is possible, then you have a problem wrt. drawing conclusions about pointers in Pascal, uh oh, they apparently can't exist. But if it is not possible to implement Pascal in Haskell, then Haskell must be some etremely limited special-purpose language, not Turing complete -- is that acceptable to you? > As far as I can see, if someone says "implementing Python implies the > use of pointers" as you appear to be doing, then Michael's argument > neatly demolishes that argument by providing a counter-example: there is > an implementation of Python that does not use pointers. That's meaningless. But then so is maintaining that Python doesn't have references. And so is your argument applied to Pascal, just to mention that again. > You, however, dismiss this as a fallacy, and suggests it somehow > misrepresents you. And yet you wonder why people call your behavior (not > you) paranoid. On top of the multiple fallacies, dubious snipping of arguments, statements that such arguments have not been presented (just after snipping them), and general misleading insinuations and misrepresentation, ad yet another bit of personal attack. Do you understand what that may say to readers about you, Steve Holden? Apparently it's all to defend an indefensible, idiotic position. But I think you're doing it at least partially for the fun of harassing someone. > [...] >>> I sincerely hope that my reply does not offend or inflame you, >>> since that is not the intent. I do hope it educates you and puts >>> into context the responses you have gained from others. >>> >>> After all, one simply shouting in a corner saying "YOU'RE ALL >>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>> understand what one is talking about does not tend to engender warm >>> fluffy feelings or sentiments of authority towards such an >>> individual. Be it me, you, or anyone else. >>> >>> At the moment, you appear to me to be engaging in such a behaviour. >>> Now you don't know from Jack and probably don't care about my >>> viewpoint, but I would really appreciate it if you would try not to >>> be inflammatory in your response to this. (Since you do appear to >>> also have a need to have the last word) >>> >>> Hoping this was useful on some level, >> Yes. >> >> I elected to respond to just /one/ of the many arguments you >> presented. >> >> The other arguments, about why there are no references in Python, >> shared, however, the basic property of being logical fallacies >> packaged in kilometers of rambling text. >> > And you can say this without, by your own admission, even reading it. No, you can not quote any place I have said that I haven't read his article. I did read most of it. So you are yet again within the span of one posted article presenting untrue information that you know is not true. > It > makes me wonder why we have paid you the compliment of engaging you in > debate, Gosh, I don't know. You must be stupid to do that. Yes? > since this is the most transparent evidence to date that what > comes back will be unrelated to the arguments presented. That is untrue, Steve Holden, and since you can't quote that "evidence", since you evidently /have/ read my short article which you're responding to, knowing exactly what to snip, you know that what you're saying is untrue. I think this is your third lie in one posting. But who would care to count. Cheers & hth., - Alf From benjamin.kaplan at case.edu Sat Feb 13 19:56:16 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 13 Feb 2010 19:56:16 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: On Sat, Feb 13, 2010 at 7:50 PM, Alf P. Steinbach wrote: > > At this point consider whether it's possible to implement Pascal in Haskell. > > If it is possible, then you have a problem wrt. drawing conclusions about > pointers in Pascal, uh oh, they apparently can't exist. > > But if it is not possible to implement Pascal in Haskell, then Haskell must > be some etremely limited special-purpose language, not Turing complete ?-- > ?is that acceptable to you? > > You're actually just proving his point here. It doesn't matter what model Haskell uses, a version of Pascal implemented in Haskell has pointers. Likewise, regardless of what model the implementation of Python uses, Python itself doesn't have pointers, it has objects and names. From breamoreboy at yahoo.co.uk Sat Feb 13 20:01:20 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Feb 2010 01:01:20 +0000 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Michael Sparks: >>> [Due to the appearance of reasoned discussion (it's not practical to >>> read it all!) >> [...] >>>> Therefore to say "in reality the implementation will be passing a >>>> reference or pointer" is invalid. There is after all at least one >>>> implementation that does not rely on such machine oriented language >>>> details. >>> I'm sorry, but see above: in itself it's just yet another a fallacy. >>> >>> And as an argument in a debate with me it's misrepresenting. >>> >> I see we are still all out of step with you. > > Why did you snip the short argument? > > >> If it's a fallacy then I'd >> like to see a reasoned logical explanation of its fallaciousness. > > Oh, you snipped it so that you didn't have to present it to readers. > > That's dishonest, Steve Holden. > > Requoting: > > > > Now let's move to the implementation aspects. > > > > Python as a language is implemented in many languages. One of these > > is C. There are compilers to C (pypy), C++ (shedskin), for the JVM > > (Jython) and .net (Ironpython). > > > > There is also an executable operation semantics for python, > > which can be found here: > > > > > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > > > > > This set of operational semantics is written in Haskell. > > > > Haskell is a strictly pure, lazily evaluated language. It > > therefore has no pointers or references, just values and names. > > The implementation therefore cannot be in terms of references > > and pointers. > > At this point consider whether it's possible to implement Pascal in > Haskell. > > If it is possible, then you have a problem wrt. drawing conclusions > about pointers in Pascal, uh oh, they apparently can't exist. > > But if it is not possible to implement Pascal in Haskell, then Haskell > must be some etremely limited special-purpose language, not Turing > complete -- is that acceptable to you? > > > >> As far as I can see, if someone says "implementing Python implies the >> use of pointers" as you appear to be doing, then Michael's argument >> neatly demolishes that argument by providing a counter-example: there is >> an implementation of Python that does not use pointers. > > That's meaningless. > > But then so is maintaining that Python doesn't have references. > > And so is your argument applied to Pascal, just to mention that again. > > >> You, however, dismiss this as a fallacy, and suggests it somehow >> misrepresents you. And yet you wonder why people call your behavior (not >> you) paranoid. > > On top of the multiple fallacies, dubious snipping of arguments, > statements that such arguments have not been presented (just after > snipping them), and general misleading insinuations and > misrepresentation, ad yet another bit of personal attack. > > Do you understand what that may say to readers about you, Steve Holden? > > Apparently it's all to defend an indefensible, idiotic position. But I > think you're doing it at least partially for the fun of harassing someone. > > >> [...] >>>> I sincerely hope that my reply does not offend or inflame you, since >>>> that is not the intent. I do hope it educates you and puts >>>> into context the responses you have gained from others. >>>> >>>> After all, one simply shouting in a corner saying "YOU'RE ALL >>>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>>> understand what one is talking about does not tend to engender warm >>>> fluffy feelings or sentiments of authority towards such an >>>> individual. Be it me, you, or anyone else. >>>> >>>> At the moment, you appear to me to be engaging in such a behaviour. >>>> Now you don't know from Jack and probably don't care about my >>>> viewpoint, but I would really appreciate it if you would try not to >>>> be inflammatory in your response to this. (Since you do appear to >>>> also have a need to have the last word) >>>> >>>> Hoping this was useful on some level, >>> Yes. >>> >>> I elected to respond to just /one/ of the many arguments you >>> presented. >>> >>> The other arguments, about why there are no references in Python, >>> shared, however, the basic property of being logical fallacies >>> packaged in kilometers of rambling text. >>> >> And you can say this without, by your own admission, even reading it. > > No, you can not quote any place I have said that I haven't read his > article. I did read most of it. So you are yet again within the span of > one posted article presenting untrue information that you know is not true. > > >> It >> makes me wonder why we have paid you the compliment of engaging you in >> debate, > > Gosh, I don't know. You must be stupid to do that. Yes? > > >> since this is the most transparent evidence to date that what >> comes back will be unrelated to the arguments presented. > > That is untrue, Steve Holden, and since you can't quote that "evidence", > since you evidently /have/ read my short article which you're responding > to, knowing exactly what to snip, you know that what you're saying is > untrue. I think this is your third lie in one posting. But who would > care to count. > > > Cheers & hth., > > - Alf You really are the most insulting arrogant bastard I've ever read on c.l.py in the eight years that I've been using Python. Did you get your training at the Dr Goebbels School of Propaganda? Most disgustedly. Mark Lawrence From vicente.soler at gmail.com Sat Feb 13 20:21:51 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Feb 2010 17:21:51 -0800 (PST) Subject: Selecting a file in a directory Message-ID: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Hi, My python script needs to work with a .txt file in a directory. I would like to give the user the possibility to choose the file he needs to work on in as much the same way as I open a .xls file in Excel, that is, I want to make appear the "Windows'" window and let the user choose. I think this should be quite straightforward. How should I proceed? From clp2 at rebertia.com Sat Feb 13 20:26:02 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 13 Feb 2010 17:26:02 -0800 Subject: working with laptop battery In-Reply-To: <20100214004831.GA21071@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> Message-ID: <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> On Sat, Feb 13, 2010 at 4:48 PM, Daniel Dalton wrote: > Hi, > > I'm constantly working in the command line and need to write a program > to give me alerts on my battery. Can someone please tell me what module > I should use to access battery information? Looking for something that > perhaps makes use of acpi so I can get estimated time left as well as a > percentage. It's probably gonna depend on which OS you're running. Which would be...? Cheers, Chris -- http://blog.rebertia.com From alfps at start.no Sat Feb 13 20:28:13 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 02:28:13 +0100 Subject: Selecting a file in a directory In-Reply-To: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: * vsoler: > Hi, > > My python script needs to work with a .txt file in a directory. I > would like to give the user the possibility to choose the file he > needs to work on in as much the same way as I open a .xls file in > Excel, that is, I want to make appear the "Windows'" window and let > the user choose. > > I think this should be quite straightforward. > > How should I proceed? At least in Windows one easy way is to delegate that responsibility to the Windows shell. When a user drags a file onto your script, your script is run with the path to that dragged file as argument. Or it can even be multiple files. Otherwise, tkinter has, as I recall, a standard file chooser dialog. These "standard" dialogs are generally called "common dialogs". Just google for tkinter and suitable words. Cheers & hth., - Alf From anand.shashwat at gmail.com Sat Feb 13 20:29:49 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 14 Feb 2010 06:59:49 +0530 Subject: working with laptop battery In-Reply-To: <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> Message-ID: I too am interested as to which module should I use. My OS is OS X Snow Leopard. On Sun, Feb 14, 2010 at 6:56 AM, Chris Rebert wrote: > On Sat, Feb 13, 2010 at 4:48 PM, Daniel Dalton > wrote: > > Hi, > > > > I'm constantly working in the command line and need to write a program > > to give me alerts on my battery. Can someone please tell me what module > > I should use to access battery information? Looking for something that > > perhaps makes use of acpi so I can get estimated time left as well as a > > percentage. > > It's probably gonna depend on which OS you're running. Which would be...? > > Cheers, > Chris > -- > http://blog.rebertia.com > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Sat Feb 13 20:31:33 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 17:31:33 -0800 (PST) Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> This thread is interesting on many levels. What is the core question that is being examined here? From alfps at start.no Sat Feb 13 20:34:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 02:34:11 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Benjamin Kaplan: > On Sat, Feb 13, 2010 at 7:50 PM, Alf P. Steinbach wrote: >> At this point consider whether it's possible to implement Pascal in Haskell. >> >> If it is possible, then you have a problem wrt. drawing conclusions about >> pointers in Pascal, uh oh, they apparently can't exist. >> >> But if it is not possible to implement Pascal in Haskell, then Haskell must >> be some etremely limited special-purpose language, not Turing complete -- >> is that acceptable to you? >> >> > > You're actually just proving his point here. It doesn't matter what > model Haskell uses, a version of Pascal implemented in Haskell has > pointers. Yes, that kills his argument. As you note, the Haskell bit is completely irrelevant. So his use of Haskell implementation as a "no pointers" argument is completely bogus, a fallacy. > Likewise, regardless of what model the implementation of > Python uses, Python itself doesn't have pointers, it has objects and > names. Well that's wrong for at least one general meaning of "pointer", but why quibble about terminology? Names in Python refer to objects. Those references can be copied via assignment. That's (almost) all. And it provides a very short and neat way to describe pass by sharing. Cheers & hth., - Alf From cs at zip.com.au Sat Feb 13 20:37:08 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 14 Feb 2010 12:37:08 +1100 Subject: threading and signals - main thread solely responsible for signal handling? In-Reply-To: <20100213172226.26099.213963272.divmod.xquotient.1291@localhost.localdomain> References: <20100213172226.26099.213963272.divmod.xquotient.1291@localhost.localdomain> Message-ID: <20100214013708.GA4636@cskk.homeip.net> On 13Feb2010 17:22, exarkun at twistedmatrix.com wrote: | On 04:43 pm, maligree at gmail.com wrote: | >The main part of my script is a function that does many long reads | >(urlopen, it's looped). Since I'm hell-bent on employing SIGINFO to | >display some stats, I needed to run foo() as a seperate thread to | >avoid getting errno 4 (interrupted system call) errors (which occur if | >SIGINFO is received while urlopen is setting itself up/waiting for a | >response). This does the job, SIGINFO is handled without ever brutally | >interrupting urlopen. | > | >The problem is that after starting foo as a thread, my main thread has | >nothing left to do - unless it receives a signal, and I am forced to | >keep it in some sort of loop so that ANY signal handling can still | >occur. I thought I'd just occupy it with a simple while 1: pass loop | >but that, unfortunately, means 100% CPU usage. [...] | | MRAB suggested you time.sleep() in a loop, which is probably fine. | However, if you want to have even /less/ activity than that in the | main thread, take a look at signal.pause(). Funnily enough I coded this issue just a few weeks ago, and my main program looks like this: def main(argv): xit = 0 cmd = os.path.basename(argv[0]) SM = SystemManager() [...set up a bunch of subsystems...] SM.startAll() try: signal.pause() except KeyboardInterrupt: warn("KeyboardInterrupt interrupts pause()") xit = 1 SM.close() SM.join() return xit So SM.close() tells all the subsystems to close and finish up. That largely involved putting the "EOF" sentinel value on a lot of Queues, causes the subsystems to cease processing stuff. The separate SM.join() does the actaul waiting for everything. This makes for clean and timely shutdown for me. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ If your new theorem can be stated with great simplicity, then there will exist a pathological exception. - Adrian Mathesis From vicente.soler at gmail.com Sat Feb 13 20:38:40 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Feb 2010 17:38:40 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: <381a8d2e-1212-4b26-a1d5-7370d23bfbb1@d37g2000yqa.googlegroups.com> On Feb 14, 2:28?am, "Alf P. Steinbach" wrote: > * vsoler: > > > Hi, > > > My python script needs to work with a .txt file in a directory. I > > would like to give the user the possibility to choose the file he > > needs to work on in as much the same way as I open a .xls file in > > Excel, that is, I want to make appear the "Windows'" window and let > > the user choose. > > > I think this should be quite straightforward. > > > How should I proceed? > > At least in Windows one easy way is to delegate that responsibility to the > Windows shell. When a user drags a file onto your script, your script is run > with the path to that dragged file as argument. Or it can even be multiple files. > > Otherwise, tkinter has, as I recall, a standard file chooser dialog. > > These "standard" dialogs are generally called "common dialogs". > > Just google for tkinter and suitable words. > > Cheers & hth., > > - Alf I'll try, thank you very much From d.dalton at iinet.net.au Sat Feb 13 20:43:24 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Sun, 14 Feb 2010 12:43:24 +1100 Subject: working with laptop battery In-Reply-To: <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> Message-ID: <20100214014324.GA4868@debian-eeepc> On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: > It's probably gonna depend on which OS you're running. Which would be...? Sorry, forgot to mention this. I'm running debian linux. Thanks, Dan From alfps at start.no Sat Feb 13 20:43:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 02:43:29 +0100 Subject: Modifying Class Object In-Reply-To: <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> Message-ID: * Steve Howell: > This thread is interesting on many levels. What is the core question > that is being examined here? I think that regarding the technical it is whether a Python name refers to an object or not. I maintain that it does, and that the reference can be copied, and that the semantics of the language requires this and is defined in terms of this. Steve Holden, D'Aprano and many others maintain that there are no references, or that if there are then they're only an implementation aspect, i.e. that conceiveable one could have an implementation without them. Regarding some other issues it seems to be a childish exercise in flaming, a flame war, with claims of insanity, incompetence, lying (that's actually from me, I reacted a bit strongly to faked quoting + conclusions from that in a posting not appearing on Usenet but on the Python mail list), etc. etc. ad nauseam, sprinkled with misrepresentations etc. I don't know the point of that. Cheers, - Alf From steve at holdenweb.com Sat Feb 13 20:44:47 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 13 Feb 2010 20:44:47 -0500 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: Alf P. Steinbach wrote: > * Steve Holden: >> Alf P. Steinbach wrote: >>> * Michael Sparks: >>> [Due to the appearance of reasoned discussion (it's not practical to >>> read it all!) >> [...] >>>> Therefore to say "in reality the implementation will be passing a >>>> reference or pointer" is invalid. There is after all at least one >>>> implementation that does not rely on such machine oriented language >>>> details. >>> I'm sorry, but see above: in itself it's just yet another a fallacy. >>> >>> And as an argument in a debate with me it's misrepresenting. >>> >> I see we are still all out of step with you. > > Why did you snip the short argument? > Because it's irrelevant and fallacious. > >> If it's a fallacy then I'd >> like to see a reasoned logical explanation of its fallaciousness. > > Oh, you snipped it so that you didn't have to present it to readers. > > That's dishonest, Steve Holden. > > Requoting: > > >> Now let's move to the implementation aspects. >> >> Python as a language is implemented in many languages. One of these >> is C. There are compilers to C (pypy), C++ (shedskin), for the JVM >> (Jython) and .net (Ironpython). >> >> There is also an executable operation semantics for python, >> which can be found here: >> >> > http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ > >> >> This set of operational semantics is written in Haskell. >> >> Haskell is a strictly pure, lazily evaluated language. It >> therefore has no pointers or references, just values and names. >> The implementation therefore cannot be in terms of references >> and pointers. > > At this point consider whether it's possible to implement Pascal in > Haskell. > > If it is possible, then you have a problem wrt. drawing conclusions > about pointers in Pascal, uh oh, they apparently can't exist. > > But if it is not possible to implement Pascal in Haskell, then Haskell > must be some etremely limited special-purpose language, not Turing > complete -- is that acceptable to you? > > This, if it says anything at all, appears to say that any Turing-complete language has pointers in it, which is an absurdity. > >> As far as I can see, if someone says "implementing Python implies the >> use of pointers" as you appear to be doing, then Michael's argument >> neatly demolishes that argument by providing a counter-example: there is >> an implementation of Python that does not use pointers. > > That's meaningless. > > But then so is maintaining that Python doesn't have references. > > And so is your argument applied to Pascal, just to mention that again. > *You* brought Pascal into this, not me. > >> You, however, dismiss this as a fallacy, and suggests it somehow >> misrepresents you. And yet you wonder why people call your behavior (not >> you) paranoid. > > On top of the multiple fallacies, dubious snipping of arguments, > statements that such arguments have not been presented (just after > snipping them), and general misleading insinuations and > misrepresentation, ad yet another bit of personal attack. > > Do you understand what that may say to readers about you, Steve Holden? > I'm happy to let readers draw their own conclusions about us both. > Apparently it's all to defend an indefensible, idiotic position. But I > think you're doing it at least partially for the fun of harassing someone. > Not at all. You have accused me of bullying behavior, but in truth you are the bully, and we know what happens when you give in to bullies, don't we? > >> [...] >>>> I sincerely hope that my reply does not offend or inflame you, since >>>> that is not the intent. I do hope it educates you and puts >>>> into context the responses you have gained from others. >>>> >>>> After all, one simply shouting in a corner saying "YOU'RE ALL >>>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>>> understand what one is talking about does not tend to engender warm >>>> fluffy feelings or sentiments of authority towards such an >>>> individual. Be it me, you, or anyone else. >>>> >>>> At the moment, you appear to me to be engaging in such a behaviour. >>>> Now you don't know from Jack and probably don't care about my >>>> viewpoint, but I would really appreciate it if you would try not to >>>> be inflammatory in your response to this. (Since you do appear to >>>> also have a need to have the last word) >>>> >>>> Hoping this was useful on some level, >>> Yes. >>> >>> I elected to respond to just /one/ of the many arguments you >>> presented. >>> >>> The other arguments, about why there are no references in Python, >>> shared, however, the basic property of being logical fallacies >>> packaged in kilometers of rambling text. >>> >> And you can say this without, by your own admission, even reading it. > > No, you can not quote any place I have said that I haven't read his > article. I did read most of it. So you are yet again within the span of > one posted article presenting untrue information that you know is not true. > I repeat the quote from you which you can read at the top of this post: >>> [Due to the appearance of reasoned discussion (it's not practical to >>> read it all!) >> [...] So now you say you read "most" of it. Even this statement is an admission that there are parts you did not, and yet somehow *I* am the liar? We are moving from the bizarre to the delusional here. > >> It >> makes me wonder why we have paid you the compliment of engaging you in >> debate, > > Gosh, I don't know. You must be stupid to do that. Yes? > Apparently. > >> since this is the most transparent evidence to date that what >> comes back will be unrelated to the arguments presented. > > That is untrue, Steve Holden, and since you can't quote that "evidence", > since you evidently /have/ read my short article which you're responding > to, knowing exactly what to snip, you know that what you're saying is > untrue. I think this is your third lie in one posting. But who would > care to count. > Who indeed? > > Cheers & hth., > That signature surely has to be irony. Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at REMOVE-THIS-cybersource.com.au Sat Feb 13 20:45:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 01:45:03 GMT Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: <4b77559f$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 17:21:51 -0800, vsoler wrote: > Hi, > > My python script needs to work with a .txt file in a directory. I would > like to give the user the possibility to choose the file he needs to > work on in as much the same way as I open a .xls file in Excel, that is, > I want to make appear the "Windows'" window and let the user choose. > > I think this should be quite straightforward. Python is multi-platform. Having the Windows file selection dialogs appear under Linux or Mac is anything but straightforward! The only general purpose (non-operating system specific) solution will require a GUI toolkit. > How should I proceed? >>> import tkFileDialog >>> help(tkFileDialog) See also: http://docs.python.org/library/tkinter.html http://wiki.python.org/moin/GuiProgramming or google on "python display file dialog". -- Steven From rantingrick at gmail.com Sat Feb 13 20:45:32 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Feb 2010 17:45:32 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> Message-ID: <96255e38-b30b-42f2-9cd4-baa6a7b7eeb9@j31g2000yqa.googlegroups.com> On Feb 13, 7:28?pm, "Alf P. Steinbach" wrote: > * vsoler: > > > Hi, > > > My python script needs to work with a .txt file in a directory. I > > would like to give the user the possibility to choose the file he > > needs to work on in as much the same way as I open a .xls file in > > Excel, that is, I want to make appear the "Windows'" window and let > > the user choose. > > > I think this should be quite straightforward. > > > How should I proceed? > > At least in Windows one easy way is to delegate that responsibility to the > Windows shell. When a user drags a file onto your script, your script is run > with the path to that dragged file as argument. Or it can even be multiple files. > > Otherwise, tkinter has, as I recall, a standard file chooser dialog. > > These "standard" dialogs are generally called "common dialogs". specifically Alf was referring to tkFileDialog.askopenfilename(). Heres an example... import Tkinter as tk from tkFileDialog import askopenfilename root = tk.Tk() def get_files(): path = askopenfilename(filetypes=[('TXT', '.txt')]) if path: print path tk.Button(root, text='1', font=('Wingdings', 12), command=get_files).pack(padx=5, pady=5) root.mainloop() From vicente.soler at gmail.com Sat Feb 13 21:00:03 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 13 Feb 2010 18:00:03 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> <96255e38-b30b-42f2-9cd4-baa6a7b7eeb9@j31g2000yqa.googlegroups.com> Message-ID: <89f86e28-0ed3-4232-b489-db088d320658@q21g2000yqm.googlegroups.com> On Feb 14, 2:45?am, rantingrick wrote: > On Feb 13, 7:28?pm, "Alf P. Steinbach" wrote: > > > > > * vsoler: > > > > Hi, > > > > My python script needs to work with a .txt file in a directory. I > > > would like to give the user the possibility to choose the file he > > > needs to work on in as much the same way as I open a .xls file in > > > Excel, that is, I want to make appear the "Windows'" window and let > > > the user choose. > > > > I think this should be quite straightforward. > > > > How should I proceed? > > > At least in Windows one easy way is to delegate that responsibility to the > > Windows shell. When a user drags a file onto your script, your script is run > > with the path to that dragged file as argument. Or it can even be multiple files. > > > Otherwise, tkinter has, as I recall, a standard file chooser dialog. > > > These "standard" dialogs are generally called "common dialogs". > > specifically Alf was referring to tkFileDialog.askopenfilename(). > Heres an example... > > import Tkinter as tk > from tkFileDialog import askopenfilename > > root = tk.Tk() > > def get_files(): > ? ? path = askopenfilename(filetypes=[('TXT', '.txt')]) > ? ? if path: > ? ? ? ? print path > > tk.Button(root, text='1', font=('Wingdings', 12), > command=get_files).pack(padx=5, pady=5) > > root.mainloop() Excellent!!! Just what I needed! From python at mrabarnett.plus.com Sat Feb 13 21:01:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 02:01:50 +0000 Subject: multiprocessing and games In-Reply-To: <694A55DA-6557-486A-A0D5-B3B19C8B2D6F@bryant.edu> References: <674C1392-D45E-4422-B91B-277CD02EA29B@bryant.edu> <4B76E759.3010503@mrabarnett.plus.com> <694A55DA-6557-486A-A0D5-B3B19C8B2D6F@bryant.edu> Message-ID: <4B77598E.4010800@mrabarnett.plus.com> Brian Blais wrote: > On Feb 13, 2010, at 12:54 , MRAB wrote: > >> Brian Blais wrote: >>> I've been thinking about implementing some simple games > >> Forget about global variables, they're not worth it! :-) >> >> Think in terms of messages, sent via pipes, sockets or multiprocessing >> queues. >> > > okay...let's make this concrete. given your ideas, I have it working > for the first type of agent, namely one that is called like: > > move=agent(board,player) > > For a specific example, I'm using the simplest version of a game called > Nim. You start with a number of sticks, players take turns taking 1, 2, > or 3 sticks, and you lose if you take the last stick. Two agents for > this are: > > # agent1.py - simple take 1 agent > def agent(board,player): > return 1 > > # agent2.py - perfect player > def agent(board,player): > move=(board-1)%4 > if move==0: > return 1 > else: > return move > > I run my simulator like (complete code below): > > s=Sim('agent1','agent2') > winner=s.run() > > and it spawns two processes, passes messages between the sim and the > agents, and closes the agents nicely when the game is over. I'm not > sure how I catch errors in the agents, especially accidental infinite loops. > > Now the second type of agent is structured differently. I'd like > something like: > > # agent3.py - simple take 1 agent > def agent(state): > > while True: > Take(1) > > # agent4.py - perfect player > def agent(state): > > N=state['board'] # get the current information > while True: > move=(N-1)%4 > if move==0: > Take(1) > else: > Take(move) > > I tried to implement this in the second wrapper below, but I can't get > the agent function to "see" local functions in the wrapper. I probably > need an import somewhere, but I haven't quite figured out the scoping > with multiprocessing, etc... > > I include the code below. The two message-passing wrappers are there, > and it works for the first two agents, but not the second two because of > scoping issues. > > Is there a better way to be doing this? Are there other examples like > this that I can look at to improve what I am doing? > [snip] I would try to have more separation between the agents and the simulator. The simulator would start the agents, something like this: def run_agent(agent_name, connection): agent_module = __import__(agent_name) agent_module.run(agent_name, connection) ... for agent_name in self.agent_files: parent, child = Pipe() connections.append(parent) proc = Process(target=run_agent, args=(agent_name, child)) processes.append(proc) The logic for an agent would be in its own module: agent1.py --------- def get_move(board, player): return 1 def run(agent_name, connection): end = False while not end: state = connection.recv() if state['done']: break move = get_move(state['board'], state['player']) connection.send(move) print "%s done" % agent_name connection.close() If I wanted the agents to share some logic (functions) then I would put it (them) in a common module which the agents would import. From python at mrabarnett.plus.com Sat Feb 13 21:10:28 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 02:10:28 +0000 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> Message-ID: <4B775B94.5030406@mrabarnett.plus.com> Alf P. Steinbach wrote: > * Steve Howell: >> This thread is interesting on many levels. What is the core question >> that is being examined here? > > I think that regarding the technical it is whether a Python name refers > to an object or not. I maintain that it does, and that the reference can > be copied, and that the semantics of the language requires this and is > defined in terms of this. Steve Holden, D'Aprano and many others > maintain that there are no references, or that if there are then they're > only an implementation aspect, i.e. that conceiveable one could have an > implementation without them. > > Regarding some other issues it seems to be a childish exercise in > flaming, a flame war, with claims of insanity, incompetence, lying > (that's actually from me, I reacted a bit strongly to faked quoting + > conclusions from that in a posting not appearing on Usenet but on the > Python mail list), etc. etc. ad nauseam, sprinkled with > misrepresentations etc. I don't know the point of that. > It's a pity that no-one has gone far enough to trigger Godwin's Law... ;-) From alfps at start.no Sat Feb 13 21:10:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 03:10:49 +0100 Subject: Modifying Class Object In-Reply-To: References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >>>> * Michael Sparks: >>>> [Due to the appearance of reasoned discussion (it's not practical to >>>> read it all!) >>> [...] >>>>> Therefore to say "in reality the implementation will be passing a >>>>> reference or pointer" is invalid. There is after all at least one >>>>> implementation that does not rely on such machine oriented language >>>>> details. >>>> I'm sorry, but see above: in itself it's just yet another a fallacy. >>>> >>>> And as an argument in a debate with me it's misrepresenting. >>>> >>> I see we are still all out of step with you. >> Why did you snip the short argument? >> > Because it's irrelevant and fallacious. >>> If it's a fallacy then I'd >>> like to see a reasoned logical explanation of its fallaciousness. >> Oh, you snipped it so that you didn't have to present it to readers. >> >> That's dishonest, Steve Holden. >> >> Requoting: >> >> >>> Now let's move to the implementation aspects. >>> >>> Python as a language is implemented in many languages. One of these >>> is C. There are compilers to C (pypy), C++ (shedskin), for the JVM >>> (Jython) and .net (Ironpython). >>> >>> There is also an executable operation semantics for python, >>> which can be found here: >>> >>> >> http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/ >> >>> This set of operational semantics is written in Haskell. >>> >>> Haskell is a strictly pure, lazily evaluated language. It >>> therefore has no pointers or references, just values and names. >>> The implementation therefore cannot be in terms of references >>> and pointers. >> At this point consider whether it's possible to implement Pascal in >> Haskell. >> >> If it is possible, then you have a problem wrt. drawing conclusions >> about pointers in Pascal, uh oh, they apparently can't exist. >> >> But if it is not possible to implement Pascal in Haskell, then Haskell >> must be some etremely limited special-purpose language, not Turing >> complete -- is that acceptable to you? >> >> > This, if it says anything at all, appears to say that any > Turing-complete language has pointers in it, which is an absurdity. >>> As far as I can see, if someone says "implementing Python implies the >>> use of pointers" as you appear to be doing, then Michael's argument >>> neatly demolishes that argument by providing a counter-example: there is >>> an implementation of Python that does not use pointers. >> That's meaningless. >> >> But then so is maintaining that Python doesn't have references. >> >> And so is your argument applied to Pascal, just to mention that again. >> > *You* brought Pascal into this, not me. Of course. And so? Do you think that the/your argument applies to Pascal? Just for your information, it does not work for Pascal. Or any language. It is a fallacy. It does not say anything about Python, or Pascal, or any language. >>> You, however, dismiss this as a fallacy, and suggests it somehow >>> misrepresents you. And yet you wonder why people call your behavior (not >>> you) paranoid. >> On top of the multiple fallacies, dubious snipping of arguments, >> statements that such arguments have not been presented (just after >> snipping them), and general misleading insinuations and >> misrepresentation, ad yet another bit of personal attack. >> >> Do you understand what that may say to readers about you, Steve Holden? >> > I'm happy to let readers draw their own conclusions about us both. I guess you are. For it is invariably so that most readers recall by association, and a flood of flaming does yield an impression. As a technical argument it's a fallacy, but do you care? No. >> Apparently it's all to defend an indefensible, idiotic position. But I >> think you're doing it at least partially for the fun of harassing someone. >> > Not at all. You have accused me of bullying behavior, but in truth you > are the bully, and we know what happens when you give in to bullies, > don't we? After an uncountable number of flames of my person, many from you, I'm the bullied, or victim, so to speak; as such I'm not the bully. >>> [...] >>>>> I sincerely hope that my reply does not offend or inflame you, since >>>>> that is not the intent. I do hope it educates you and puts >>>>> into context the responses you have gained from others. >>>>> >>>>> After all, one simply shouting in a corner saying "YOU'RE ALL >>>>> WRONG, WRONG, WRONG. I'M RIGHT RIGHT RIGHT", when one does not to >>>>> understand what one is talking about does not tend to engender warm >>>>> fluffy feelings or sentiments of authority towards such an >>>>> individual. Be it me, you, or anyone else. >>>>> >>>>> At the moment, you appear to me to be engaging in such a behaviour. >>>>> Now you don't know from Jack and probably don't care about my >>>>> viewpoint, but I would really appreciate it if you would try not to >>>>> be inflammatory in your response to this. (Since you do appear to >>>>> also have a need to have the last word) >>>>> >>>>> Hoping this was useful on some level, >>>> Yes. >>>> >>>> I elected to respond to just /one/ of the many arguments you >>>> presented. >>>> >>>> The other arguments, about why there are no references in Python, >>>> shared, however, the basic property of being logical fallacies >>>> packaged in kilometers of rambling text. >>>> >>> And you can say this without, by your own admission, even reading it. >> No, you can not quote any place I have said that I haven't read his >> article. I did read most of it. So you are yet again within the span of >> one posted article presenting untrue information that you know is not true. >> > I repeat the quote from you which you can read at the top of this post: >>>> [Due to the appearance of reasoned discussion (it's not practical to >>>> read it all!) >>> [...] > So now you say you read "most" of it. I haven't said anything contradictory about that. If I had then you'd have quoted it. You don't quote anything, so you're out on your usual insinuate-things argumentation technique. > Even this statement is an > admission that there are parts you did not, and yet somehow *I* am the > liar? We are moving from the bizarre to the delusional here. I'm sorry that I had to point out your relating untrue information that you knew at the time was untrue. That also applies to your snipping of the argument about Haskell, and subsequent asking for such arguments as if they hadn't been given -- and snipped. The poster explained at the start that he had some technically immaterial stuff at the end of his article. I don't know whether I reached that. But anyway, the article was just a series of fallacies like the one thinking an implementation in Haskell could prove anything about the language so implemented, all wrapped up in kilometers of rambling text. Your attack of "bizarre" and "delusion" are the usual from Steve Holden. You are injecting noise to bury an argument that you didn't like. You tried first snipping it from your response. Now you're trying the noise angle again. Cheers & hth., - Alf From sccolbert at gmail.com Sat Feb 13 21:19:59 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sat, 13 Feb 2010 21:19:59 -0500 Subject: working with laptop battery In-Reply-To: <20100214014324.GA4868@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: <7f014ea61002131819x4ba766dds245220760ef74ff1@mail.gmail.com> You'll need acpi installed: In [6]: import subprocess In [7]: p = subprocess.Popen('acpi', stdout=subprocess.PIPE) In [8]: output, errors = p.communicate() In [9]: print output ------> print(output) Battery 0: Full, 100%, rate information unavailable On Sat, Feb 13, 2010 at 8:43 PM, Daniel Dalton wrote: > On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: > > It's probably gonna depend on which OS you're running. Which would be...? > > Sorry, forgot to mention this. I'm running debian linux. > > Thanks, > Dan > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Sat Feb 13 21:22:11 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 14 Feb 2010 03:22:11 +0100 Subject: working with laptop battery In-Reply-To: <20100214014324.GA4868@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: >> It's probably gonna depend on which OS you're running. Which would be...? > > Sorry, forgot to mention this. I'm running debian linux. I don't know about python modules but have a look at /proc/acpi/battery/BAT0/info /proc/acpi/battery/BAT0/state You can parse the numbers you want from there. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python.list at tim.thechases.com Sat Feb 13 21:23:28 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 13 Feb 2010 20:23:28 -0600 Subject: working with laptop battery In-Reply-To: <20100214014324.GA4868@debian-eeepc> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: <4B775EA0.7080207@tim.thechases.com> Daniel Dalton wrote: > On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: >> It's probably gonna depend on which OS you're running. Which would be...? > > Sorry, forgot to mention this. I'm running debian linux. You should be able to read/poll the various files in /proc/acpi/battery/BAT*/* for whatever battery information you need. Each BAT* directory contains information about one of the batteries in the system (it's possible, albeit rare, to have more than one). So you might have some script that runs every $INTERVAL that looks something like from glob import glob for fname in glob('/proc/acpi/battery/BAT*/*'): f = file(fname) for line in f: do_something(line) f.close() On my Debian laptop (Gateway Solo 1200, OEM battery circa 2001), the contents look something like tim at rubbish:/proc/acpi/battery/BAT0$ cat alarm alarm: unsupported tim at rubbish:/proc/acpi/battery/BAT0$ cat info present: yes design capacity: 4016 mAh last full capacity: 4011 mAh battery technology: rechargeable design voltage: 9600 mV design capacity warning: 602 mAh design capacity low: 401 mAh capacity granularity 1: 201 mAh capacity granularity 2: 3409 mAh model number: QT08 serial number: SANYOQT08 battery type: NiMH OEM info: SANYO tim at rubbish:/proc/acpi/battery/BAT0$ cat state present: yes capacity state: ok charging state: charged present rate: unknown remaining capacity: 4011 mAh present voltage: 9600 mV -tkc From aahz at pythoncraft.com Sat Feb 13 21:29:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 18:29:17 -0800 Subject: To (monkey)patch or not to (monkey)patch, that is the question References: <1410d2e2-a6f2-4b6c-a745-6d3e34994568@q16g2000yqq.googlegroups.com> Message-ID: In article <1410d2e2-a6f2-4b6c-a745-6d3e34994568 at q16g2000yqq.googlegroups.com>, > George Sakkis wrote: > >I was talking to a colleague about one rather unexpected/undesired >(though not buggy) behavior of some package we use. Although there is >an easy fix (or at least workaround) on our end without any apparent >side effect, he strongly suggested extending the relevant code by hard >patching it and posting the patch upstream, hopefully to be accepted >at some point in the future. In fact we maintain patches against >specific versions of several packages that are applied automatically >on each new build. The main argument is that this is the right thing >to do, as opposed to an "ugly" workaround or a fragile monkey patch. >On the other hand, I favor practicality over purity and my general >rule of thumb is that "no patch" > "monkey patch" > "hard patch", at >least for anything less than a (critical) bug fix. > >So I'm wondering if there is a consensus on when it's better to (hard) >patch, monkey patch or just try to work around a third party package >that doesn't do exactly what one would like. Does it have mainly to do >with the reason for the patch (e.g. fixing a bug, modifying behavior, >adding missing feature), the given package (size, complexity, >maturity, developer responsiveness), something else or there are no >general rules and one should decide on a case-by-case basis ? There's a related option that I chose for SQLObject: extending by using internal APIs. Because SQLite doesn't work well with multiple writers (or even multiple readers with one writer when queries take a long time), we needed a retry mechanism when a query failed. I originally tried proxying the SQLite class, but that ran into problems partly related to new-style classes grabbing magic methods directly from the class, and subclassing and using the internal registration API turned out to be easier. The only change required in the existing code was to change the connection string to "sqlite_retry:". Then I ran into build problems because some machines were on SQLObject 0.10.x and others were on 0.11.x and the internal API changed between those versions. It was easily fixed by upgrading everything to 0.11.x, but it's a reminder about the fragility of relying on internal APIs. If that's not an option in your case, personally I'd prefer monkey-patching because otherwise I need to check the package into my repository. Submitting a patch upstream would be responsible behavior. Overall, I think that this is definitely an issue where heuristics work much better than rules. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From aahz at pythoncraft.com Sat Feb 13 21:41:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 13 Feb 2010 18:41:42 -0800 Subject: Modifying Class Object References: Message-ID: In article , Alf P. Steinbach wrote: > >My original statement, with reference to the Java language spec, >didn't say much more about the language than that it has assignable >references. Assuming this is what you're referring to: Python passes pointers by value, just as e.g. Java does. Then you are simply, completely, totally, and absolutely wrong. Period. Regardless of how CPython manages its state internally, Python as a programming language does not have pointers. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From rantingrick at gmail.com Sat Feb 13 21:43:20 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 13 Feb 2010 18:43:20 -0800 (PST) Subject: Selecting a file in a directory References: <9b099d4e-f5bb-4860-a2dd-6a2cb4143cd6@c16g2000yqd.googlegroups.com> <96255e38-b30b-42f2-9cd4-baa6a7b7eeb9@j31g2000yqa.googlegroups.com> <89f86e28-0ed3-4232-b489-db088d320658@q21g2000yqm.googlegroups.com> Message-ID: <2f487e21-8320-41ec-b4e3-cf51e7a198d4@c16g2000yqd.googlegroups.com> On Feb 13, 8:00?pm, vsoler wrote: > On Feb 14, 2:45?am, rantingrick wrote: (..snip..) > Excellent!!! Just what I needed! For your case, since it seems you are writing a "console type" application you may want to subdue the root window and show the user a file dialog window *only*. You can do this by using "root.withdraw()" to hide the root window. Just make sure to destroy the root window after the users is finished choosing their file (or at some appropriate time later) or else your program will not exit gracefully at close time...! Heres a way to wrap the whole enchilada into a reusable function, of course many refinements could be made but this is a simplistic version... #-- start script --# # works on python < 3.0 import Tkinter as tk from tkFileDialog import askopenfilename def showFileDialog(): root = tk.Tk() root.withdraw() path = askopenfilename(filetypes=[('TXT', '.txt')]) if path: print path # do something useful here... root.destroy() root.mainloop() showFileDialog() raw_input('press enter to quit...') #-- end script --# From showell30 at yahoo.com Sat Feb 13 21:54:34 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 18:54:34 -0800 (PST) Subject: Modifying Class Object References: Message-ID: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> On Feb 13, 6:41?pm, a... at pythoncraft.com (Aahz) wrote: > In article , > Alf P. Steinbach wrote: > > > > >My original statement, with reference to the Java language spec, > >didn't say much more about the language than that it has assignable > >references. > > Assuming this is what you're referring to: > > ? ? Python passes pointers by value, just as e.g. Java does. > > Then you are simply, completely, totally, and absolutely wrong. ?Period. > Regardless of how CPython manages its state internally, Python as a > programming language does not have pointers. ? I agree with your statement for a suitably narrow definition of the words "pointer" and "have." From showell30 at yahoo.com Sat Feb 13 22:04:28 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 19:04:28 -0800 (PST) Subject: Modifying Class Object References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> <7007f5ae-2c15-4af7-be5c-71cd650c7a06@y7g2000prc.googlegroups.com> Message-ID: On Feb 13, 6:10?pm, MRAB wrote: > Alf P. Steinbach wrote: > > * Steve Howell: > >> This thread is interesting on many levels. ?What is the core question > >> that is being examined here? > > > I think that regarding the technical it is whether a Python name refers > > to an object or not. I maintain that it does, and that the reference can > > be copied, and that the semantics of the language requires this and is > > defined in terms of this. Steve Holden, D'Aprano and many others > > maintain that there are no references, or that if there are then they're > > only an implementation aspect, i.e. that conceiveable one could have an > > implementation without them. > > > Regarding some other issues it seems to be a childish exercise in > > flaming, a flame war, with claims of insanity, incompetence, lying > > (that's actually from me, I reacted a bit strongly to faked quoting + > > conclusions from that in a posting not appearing on Usenet but on the > > Python mail list), etc. etc. ad nauseam, sprinkled with > > misrepresentations etc. I don't know the point of that. > > It's a pity that no-one has gone far enough to trigger Godwin's Law... > ;-) Godwin's Law need not be invoked here. The essential question is relevant and worthy of discussion, and most posters have presented intelligent, nuanced arguments even amidst all the needless flaming. It is actually a subtle point that I think people disagree on, whatever the extraneous personal baggage. From chyavana at gmail.com Sat Feb 13 22:19:02 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Sun, 14 Feb 2010 11:19:02 +0800 Subject: Sorting a list of lists In-Reply-To: <4B759ED1.3090507@optimum.net> References: <4B7593BF.1030708@gmail.com> <4B759ED1.3090507@optimum.net> Message-ID: <4B776BA6.8060108@gmail.com> MRAB wrote: > You'd have to post an example of that, but you could try deleting some > of the entries before sorting so see whether you can still reproduce the > problem with a smaller list. John Posner wrote: > Please cut-and-paste the exact error message (or other evidence of > "failure") into a message. Thank you both. It appears that the problem was in the way the data were being read in from a file, than in the sorting itself. Once I fixed that, the results are as expected. Chandra From alfps at start.no Sat Feb 13 22:44:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 04:44:26 +0100 Subject: Modifying Class Object In-Reply-To: References: Message-ID: * Aahz: > In article , > Alf P. Steinbach wrote: >> My original statement, with reference to the Java language spec, >> didn't say much more about the language than that it has assignable >> references. > > Assuming this is what you're referring to: > > Python passes pointers by value, just as e.g. Java does. > > Then you are simply, completely, totally, and absolutely wrong. Period. > Regardless of how CPython manages its state internally, Python as a > programming language does not have pointers. The next paragraph was about the meaning of "pointer" in that first paragraph, referring to the Java language specification for the particular meaning here, namely a reference. Note: I did not refer to CPython, C, Pascal or whatever (but you mention CPython) for a meaning of "pointer". Instead I referred to the Java language specification for that meaning, where it's pretty clear: reference. So if you don't like the terminology, you can rephrase with perhaps more palatable terms: Python uses pass by sharing. References to objects are copied, the objects themselves are not copied. See If you go to that URL, which isn't auhoritative but good enough, you find that "identical semantics in other languages such as Java and Visual Basic" Hence, your point is only a matter of terminology. The semantics /can/ be described using the term "pointer" (or for that matter the term "thingamajic"), when that term is suitably defined, and it /is/ described using that word for some languages. The language doesn't matter for the concept of pass by sharing. Hence, the terminological issue doesn't invalidate the description, as long as the terminology is clearly defined, as I did with ref to the Java lang spec. As you can see proper terminology reduces the size of explanation considerably, but as I see it that's not a big deal as long as the description is still /reasonably/ short. It does become a concern when the description runs to many pages of text. A simple thing should IMHO be simply described. But I think, as I've already stated several times up-thread, that "pointer" is a term best avoided for explanations within the Python community, even with a reference to a particular definition/usage, making the more verbose version in terms of "references" preferable for Python -- don't you agree? Cheers, - Alf From steve at REMOVE-THIS-cybersource.com.au Sat Feb 13 22:53:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 03:53:42 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> Message-ID: <4b7773c6$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 18:54:34 -0800, Steve Howell wrote: > On Feb 13, 6:41?pm, a... at pythoncraft.com (Aahz) wrote: > > Regardless of how CPython manages its state internally, Python as a > > programming language does not have pointers. ? > > I agree with your statement for a suitably narrow definition of the > words "pointer" and "have." "Suitably narrow" is not that narrow. By no stretch of the imagination can one say that Python has a built-in pointer type analogous to pointers in (say) Pascal or C -- you can't usefully get the address of a variable (although the CPython implementation leaks the address of objects, it does so in a way that is safe and useless for everything but a label). There is no equivalent to (say) the Pascal program: program main(input, output); var x: integer; ptr: ^integer; begin x := 1; ptr := @x; ptr^ := ptr^ + 1; writeln(x); end. For a suitably wide definition of "pointer", then Python does have pointers: data = ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] i = data.index('bbb') print data[i] i += 1 data[i] = 'zzz' but I trust that we all agree that describing the integer offset i above as a "pointer" is a reductio ad absurdum. -- Steven From no.email at nospam.invalid Sat Feb 13 22:56:03 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 13 Feb 2010 19:56:03 -0800 Subject: Hashing in python References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <7x3a14cvxo.fsf@ruckus.brouhaha.com> Vish writes: > I need to hash 3d coordinates to a grid which has been divided into > 4*4*4 squares. Using python, I thought of a simple way as follows: Use the built-in hash function: >>> p = (1, 2, 3) >>> print hash(p) 2528502973977326415 You can of course mod that by the table size: >>> print hash(p) % (4*4*4) 15 From showell30 at yahoo.com Sat Feb 13 23:11:06 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 20:11:06 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> Message-ID: <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> On Feb 13, 7:53?pm, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 18:54:34 -0800, Steve Howell wrote: > > On Feb 13, 6:41?pm, a... at pythoncraft.com (Aahz) wrote: > > > Regardless of how CPython manages its state internally, Python as a > > > programming language does not have pointers. ? > > > I agree with your statement for a suitably narrow definition of the > > words "pointer" and "have." > > "Suitably narrow" is not that narrow. By no stretch of the imagination > can one say that Python has a built-in pointer type analogous to pointers > in (say) Pascal or C -- you can't usefully get the address of a variable > (although the CPython implementation leaks the address of objects, it > does so in a way that is safe and useless for everything but a label). > There is no equivalent to (say) the Pascal program: > > program main(input, output); > ? var > ? ? x: integer; > ? ? ptr: ^integer; > > begin > ? x := 1; > ? ptr := @x; > ? ptr^ := ptr^ + 1; > ? writeln(x); > end. > > For a suitably wide definition of "pointer", then Python does have > pointers: > > data = ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] > i = data.index('bbb') > print data[i] > i += 1 > data[i] = 'zzz' > > but I trust that we all agree that describing the integer offset i above > as a "pointer" is a reductio ad absurdum. > For a suitably wide definition of pointers CPython does indeed have pointers, and your example is only a weaker case of that truth. There is no reductio adsurbum. If I argued that CPython had curly braced syntax that would be absurd, since it is so concretely wrong. Pointers are a more abstact concept. From sridharr at activestate.com Sat Feb 13 23:16:59 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Sat, 13 Feb 2010 20:16:59 -0800 Subject: ANN: ActivePython 2.5.5.7 is now available In-Reply-To: References: <1E441CA2-F197-4F5B-B4F5-A5FE2E3D7882@activestate.com> Message-ID: <1D5C19A6-A80E-4952-9099-120C394618E0@activestate.com> On 2010-02-13, at 1:25 AM, Dennis Lee Bieber wrote: > On Thu, 11 Feb 2010 16:22:49 -0800, Sridhar Ratnakumar > declaimed the following in > gmane.comp.python.general: > >> I'm happy to announce that ActivePython 2.5.5.7 is now available for >> download from: >> >> http://www.activestate.com/activepython/ >> > This seems to be the first Windows installer I recall that can't > "update" over an earlier 2.5.x version... It want's me to wipe out > (uninstall) my existing base before it will allow for installation (bad > enough it need admin privileges -- I'm going to be dead at work the next > time they "refresh" my desktop machine as they no longer allow users to > have local admin rights) This is probably due to http://firefly.activestate.com/shanec/activepython/ticket/11 where the MSI product code for 64-bit installer was changed to be different from the 32-bit one. Specifically the product codes used are: <=2.5.4.4: "a2e24bd9-085b-410f-aad0-5eb5fa5d73d2" >=2.5.4.6 32-bit: "a2e24bd9-085b-410f-aad0-5eb5fa5d73d2", >=2.5.4.5 64-bit: "64e24bd9-085b-410f-aad0-5eb5fa5d73d2", Consequently 64-bit installers for 2.X will have different MSI product code from 2.5.4.6 onwards. Was your "update" issue happening only with the 64-bit installer of 2.5.5.7? -srid -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sun Feb 14 00:13:33 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 05:13:33 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> Message-ID: <4b77867d$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 20:11:06 -0800, Steve Howell wrote: > For a suitably wide definition of pointers CPython does indeed have > pointers, and your example is only a weaker case of that truth. There > is no reductio adsurbum. If I argued that CPython had curly braced > syntax that would be absurd, since it is so concretely wrong. Pointers > are a more abstact concept. I would argue that your examples are equivalent. The suitably wide definition of pointers that allows you to argue that Python has pointers is an implementation detail, just as the implementation detail that the Python tokenizer uses INDENT and DEDENT tokens. An INDENT token is just another way of spelling { and DEDENT is just another way of spelling }, so therefore Python has curly bracket syntax. Do I believe this argument is valid? No, of course not, I think it does so much violence to the concepts of curly brackets and syntax as to be absurd. Just as I think the only way to justify claiming that Python has pointers is to do so much violence to the concept of pointer and to Python's object model as to also be absurd. That's not to say that the general concept of references (as in "to refer to") isn't valuable when discussing Python. If you want to say that (e.g.) following x = 1 the name "x" refers to (or even points to!) the object 1, my objections will be mild or non-existent. In that sense, it's probably impossible to program without some sort of "references": the computer manipulates variables or objects directly, while we manipulate characters in source code. The only way to write a program is to use some abstract thing (a name, an offset, whatever) that refers, in some fashion, to a collection of bits in the computer's memory. But to go from that to the idea that (say) x is a pointer does so much violence to the concept of pointer and has so much room for confusion that it is actively harmful. -- Steven From showell30 at yahoo.com Sun Feb 14 00:33:50 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 21:33:50 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> Message-ID: <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> On Feb 13, 9:13?pm, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 20:11:06 -0800, Steve Howell wrote: > > For a suitably wide definition of pointers CPython does indeed have > > pointers, and your example is only a weaker case of that truth. ?There > > is no reductio adsurbum. ?If I argued that CPython had curly braced > > syntax that would be absurd, since it is so concretely wrong. Pointers > > are a more abstact concept. > > I would argue that your examples are equivalent. > > The suitably wide definition of pointers that allows you to argue that > Python has pointers is an implementation detail, just as the > implementation detail that the Python tokenizer uses INDENT and DEDENT > tokens. An INDENT token is just another way of spelling { and DEDENT is > just another way of spelling }, so therefore Python has curly bracket > syntax. > You seem to be missing the point that "curly braces" is a concrete term that very specifically applies to spelling. > Do I believe this argument is valid? No, of course not, I think it does > so much violence to the concepts of curly brackets and syntax as to be > absurd. Just as I think the only way to justify claiming that Python has > pointers is to do so much violence to the concept of pointer and to > Python's object model as to also be absurd. > > That's not to say that the general concept of references (as in "to refer > to") isn't valuable when discussing Python. If you want to say that > (e.g.) following > > x = 1 > > the name "x" refers to (or even points to!) the object 1, my objections > will be mild or non-existent. In that sense, it's probably impossible to > program without some sort of "references": the computer manipulates > variables or objects directly, while we manipulate characters in source > code. The only way to write a program is to use some abstract thing (a > name, an offset, whatever) that refers, in some fashion, to a collection > of bits in the computer's memory. But to go from that to the idea that > (say) x is a pointer does so much violence to the concept of pointer and > has so much room for confusion that it is actively harmful. > I agree that "reference" is a much better term than "pointer.". It has the right amount of generalness in my opinion. I think "violence" is a bit overstated, but your bigger point is well taken and it seems like "reference" is useful middle ground between pure cpython language and misrepresentative analogy. From cs at zip.com.au Sun Feb 14 01:12:06 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 14 Feb 2010 17:12:06 +1100 Subject: iglob performance no better than glob In-Reply-To: <449a19de-42f7-4ae3-8099-99c27572adc8@m16g2000yqc.googlegroups.com> References: <449a19de-42f7-4ae3-8099-99c27572adc8@m16g2000yqc.googlegroups.com> Message-ID: <20100214061206.GA31131@cskk.homeip.net> On 31Jan2010 16:23, Kyp wrote: | On Jan 31, 2:44?pm, Peter Otten <__pete... at web.de> wrote: | > Kyp wrote: | > > I have a dir with a large # of files that I need to perform operations | > > on, but only needing to access a subset of the files, i.e. the first | > > 100 files. | > > Using glob is very slow, so I ran across iglob, which returns an | > > iterator, which seemed just like what I wanted. I could iterate over | > > the files that I wanted, not having to read the entire dir. [...] | > > So the iglob was faster, but accessing the first file took about the | > > same time as glob.glob. | > | > > Here's some code to compare glob vs. iglob performance, ?it outputs | > > the time before/after a glob.iglob('*.*') files.next() sequence and a | > > glob.glob('*.*') sequence. | > | > > #!/usr/bin/env python | > | > > import glob,time | > > print '\nTest of glob.iglob' | > > print 'before ? ? ? iglob:', time.asctime() | > > files = glob.iglob('*.*') | > > print 'after ? ? ? ?iglob:',time.asctime() | > > print files.next() | > > print 'after files.next():', time.asctime() | > | > > print '\nTest of glob.glob' | > > print 'before ? ? ? ?glob:', time.asctime() | > > files = glob.glob('*.*') | > > print 'after ? ? ? ? glob:',time.asctime() | > | > > Here are the results: | > | > > Test of glob.iglob | > > before ? ? ? iglob: Sun Jan 31 11:09:08 2010 | > > after ? ? ? ?iglob: Sun Jan 31 11:09:08 2010 | > > foo.bar | > > after files.next(): Sun Jan 31 11:09:59 2010 | > | > > Test of glob.glob | > > before ? ? ? ?glob: Sun Jan 31 11:09:59 2010 | > > after ? ? ? ? glob: Sun Jan 31 11:10:51 2010 | > | > > The results are about the same for the 2 approaches, both took about | > > 51 seconds. Am I doing something wrong with iglob? | > | > No, but iglob() being lazy is pointless in your case because it uses | > os.listdir() and fnmatch.filter() underneath which both read the whole | > directory before returning anything. | > | > > Is there a way to get the first X # of files from a dir with lots of | > > files, that does not take a long time to run? | > | > Here's my attempt. [...open directory and read native format...] I'd be inclined first to time os.listdir('.') versus glob.lgo('*.*'). Glob routines tend to lstat() every matching name to ensure the path exists. That's very slow. If you just do os.listdir() and choose your 100 nmaes, you only need to stat (or just try to open) them. So time glob.glob("*.*") versus os.listdir(".") first. Generally, with a large directory, stat time will change performance immensely. -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Usenet is essentially a HUGE group of people passing notes in class. --R. Kadel From steve at REMOVE-THIS-cybersource.com.au Sun Feb 14 02:21:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 07:21:44 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> Message-ID: <4b77a488$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 21:33:50 -0800, Steve Howell wrote: > You seem to be missing the point that "curly braces" is a concrete > term that very specifically applies to spelling. And you seem to be missing the point that "pointer" is also a concrete term that very specifically applies to, well, pointers. [...] > I agree that "reference" is a much better term than "pointer.". It has > the right amount of generalness in my opinion. I think "violence" is a > bit overstated, but your bigger point is well taken and it seems like > "reference" is useful middle ground between pure cpython language and > misrepresentative analogy. But reference also has a concrete meaning: C++ has a type explicitly called "reference": http://en.wikipedia.org/wiki/Reference_(C++) And of course call-by-reference (or pass-by-reference) has a specific, technical meaning. -- Steven From alfps at start.no Sun Feb 14 02:40:50 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 14 Feb 2010 08:40:50 +0100 Subject: Modifying Class Object In-Reply-To: <4b77a488$0$8767$c3e8da3@news.astraweb.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Sat, 13 Feb 2010 21:33:50 -0800, Steve Howell wrote: > >> You seem to be missing the point that "curly braces" is a concrete >> term that very specifically applies to spelling. > > And you seem to be missing the point that "pointer" is also a concrete > term that very specifically applies to, well, pointers. > > [...] >> I agree that "reference" is a much better term than "pointer.". It has >> the right amount of generalness in my opinion. I think "violence" is a >> bit overstated, but your bigger point is well taken and it seems like >> "reference" is useful middle ground between pure cpython language and >> misrepresentative analogy. > > But reference also has a concrete meaning: C++ has a type explicitly > called "reference": > > http://en.wikipedia.org/wiki/Reference_(C++) > > And of course call-by-reference (or pass-by-reference) has a specific, > technical meaning. Hm. Consider your argument about "reference" being possible to confuse with "pass by reference" in the light of "pass by name", used by Algol, . Oops, to consistently remove all possible ambiguity the term "name" can't be used about formal arguments. I think, even though "pass by name" is much less well known than "pass by reference", this indicates that it's not practically possible to remove all possible ambiguity. I think some Common Sense(TM) must in any case be assumed, and applied. Cheers, - Alf From showell30 at yahoo.com Sun Feb 14 02:45:47 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 13 Feb 2010 23:45:47 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> Message-ID: On Feb 13, 11:21?pm, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 21:33:50 -0800, Steve Howell wrote: > > You seem to be missing the point that "curly braces" is a concrete > > term that very specifically applies to spelling. > > And you seem to be missing the point that "pointer" is also a concrete > term that very specifically applies to, well, pointers. > The term "pointer" is very abstract. Please give me a concrete definition of a pointer. A curly brace is one of these: { } Pretty concrete, I hope. > [...] > > > I agree that "reference" is a much better term than "pointer.". It has > > the right amount of generalness in my opinion. I think "violence" is a > > bit overstated, but your bigger point is well taken and it seems like > > "reference" is useful middle ground between pure cpython language and > > misrepresentative analogy. > > But reference also has a concrete meaning: C++ has a type explicitly > called "reference": > > http://en.wikipedia.org/wiki/Reference_(C++) > Of course, "reference" has concrete meanings in specific contexts. But I can refer you to much more general and abstract uses of the term "reference." Do you want references? I will be happy to refer you to appropriate references. > And of course call-by-reference (or pass-by-reference) has a specific, > technical meaning. > Which is what? From showell30 at yahoo.com Sun Feb 14 03:15:02 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 00:15:02 -0800 (PST) Subject: Modifying Class Object References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002081755nc32be95qb2f567d0463babde@mail.gmail.com> <7a9c25c21002082029q303592b5v86717f406a8eff2c@mail.gmail.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: On Feb 10, 6:16?am, Steven D'Aprano wrote: > > Alf, although your English in this forum has been excellent so far, I > understand you are Norwegian, so it is possible that you aren't a native > English speaker and possibly unaware that quotation marks are sometimes > ambiguous in English. > > While it is true that quoted text is officially meant to indicate a > direct quote, it is also commonly used in informal text to indicate a > paraphrase. (There are other uses as well, but they don't concern us now.) > > Unfortunately, this means that in informal discussions like this it is > sometimes difficult to distinguish a direct quote from a paraphrase, > except by context. In context, as a native speaker, I can assure you that > Stephen Hansen's use of quotation marks is a paraphrase and not meant to > be read as a direct quote. As another native speaker of English, I can assure Alf that using quotation marks in a paraphrase in written English is actually strictly admonished against in some English speaking countries. At least according to my English teachers. To the extent that many people on the Internet don't speak English natively, I think the most conservative and reasonable convention applies--use quotes to quote directly; if you're not quoting directly, omit quotes and make clear the fact that you are paraphrasing. Which isn't to say we don't all make mistakes. I have no idea about what Stephen Hanson said. Most misattributions are actually paraphrases, whether they be in quotes or not. From apt.shansen at gmail.com Sun Feb 14 03:21:03 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 14 Feb 2010 00:21:03 -0800 Subject: Modifying Class Object In-Reply-To: <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> References: <62e5dac7-7e70-4194-a4f8-77ca9c7e3d06@z17g2000yqh.googlegroups.com> <25173e83-11fe-40e3-9a7d-3ddcc361f19a@o30g2000yqb.googlegroups.com> Message-ID: <7a9c25c21002140021i14f45531r3c4414bdb7a24b15@mail.gmail.com> On Sat, Feb 13, 2010 at 7:59 AM, Michael Sparks wrote: > Hi Alf, > > > On Feb 12, 8:22 pm, "Alf P. Steinbach" wrote: > > Thanks for the effort at non-flaming discussion, it *is* > > appreciated. > > I would appreciate it if you tried to be non-flaming yourself, > since you can see I am not flaming you. > I'm currently in a self-imposed exile from commenting on any particular details of the technical issue in this thread as I believe it futile, but I have to say: wow, kudos to you for putting SO much into saying what I tried to say, and doing so better then I was able to. Kudos. Times two. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Sun Feb 14 03:50:04 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sun, 14 Feb 2010 00:50:04 -0800 Subject: Modifying Class Object In-Reply-To: References: <9816ff65-b147-43f5-a0bf-e3dc9a0c8c64@o36g2000vbl.googlegroups.com> <7a9c25c21002092343s11815162yd39691362a51ab63@mail.gmail.com> <0382abea$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002140050j4dddcc3dkdffc1df523ee7bf2@mail.gmail.com> On Sun, Feb 14, 2010 at 12:15 AM, Steve Howell wrote: > On Feb 10, 6:16 am, Steven D'Aprano cybersource.com.au> wrote: > > > > Alf, although your English in this forum has been excellent so far, I > > understand you are Norwegian, so it is possible that you aren't a native > > English speaker and possibly unaware that quotation marks are sometimes > > ambiguous in English. > > > > While it is true that quoted text is officially meant to indicate a > > direct quote, it is also commonly used in informal text to indicate a > > paraphrase. (There are other uses as well, but they don't concern us > now.) > > > > Unfortunately, this means that in informal discussions like this it is > > sometimes difficult to distinguish a direct quote from a paraphrase, > > except by context. In context, as a native speaker, I can assure you that > > Stephen Hansen's use of quotation marks is a paraphrase and not meant to > > be read as a direct quote. > > As another native speaker of English, I can assure Alf that using > quotation marks in a paraphrase in written English is actually > strictly admonished against in some English speaking countries. At > least according to my English teachers. To the extent that many > people on the Internet don't speak English natively, I think the most > conservative and reasonable convention applies--use quotes to quote > directly; if you're not quoting directly, omit quotes and make clear > the fact that you are paraphrasing. > > Which isn't to say we don't all make mistakes. > > I have no idea about what Stephen Hanson said. Most misattributions > are actually paraphrases, whether they be in quotes or not. Well, no, I have to stand in my defense at this point. Given the context of the communication medium, an actual "quote" has IMHO a clearly defined context. It is lines, unchanged and unedited, prepended with a certain appropriate set of characters, and clearly cited with some variation of something like "On , Someone said:" A quote, in context, is an attempt to directly reference another individual's words as they spoke them. Any alteration of such words, any adjustment of such words to your own end, is dishonest. What I did was say something like this paragraph (with no quote characters before it): And then you hand-waved my arguments with a response of, "this that blah bleh" Minus the indention. There was IMHO, NO misattribution, NO reasonable assumption that I specified actual or explicit words of Alf or anyone else. There MAY be an argument someone can make claiming my statement wasn't clear, but to declare it is a deliberate /lie/ is another thing entirely. There is a difference between using quote marks and making an actual quotation-- a quotation requires a citation-- and in informal discourse use of quote marks to represent clear paraphrasing of the interpretation of position is valid, imho. In a formal paper or thesis, I'd use a different format. But this is not formal. In context that statement can not possibly be reasonable considered an actual quotation, even with quote marks. And I'm responding because: yes, I'm finding this "You are a liar." response particularly personally offensive. I should get over it. I'm just used to people disagreeing with me. Dismissing me as a liar is something new. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From paul at subsignal.org Sun Feb 14 04:16:18 2010 From: paul at subsignal.org (=?ISO-8859-9?Q?Paul_K=F6lle?=) Date: Sun, 14 Feb 2010 10:16:18 +0100 Subject: plugin / intra process communication system In-Reply-To: <1266054643.26540.58.camel@brain> References: <1266054643.26540.58.camel@brain> Message-ID: Am 13.02.2010 10:50, schrieb Florian Ludwig: > Hi, > > I'm looking for a module/plugin/intra-process-communication/hook system > for python. Maybe someone here could point me to some project I missed > or might have some good ideas if I end up implementing it myself. > > Most systems I have found are "one to many" communications but I would > like "many to many", to clarify what I mean an *example* use-case: > > Lets say you program a wiki and like to allow different kind of > authentications. So you create two plugins (for example one for > OpenID and one for Shibboleth). > > Some time later you feel like reinventing the wheel again and > you program a blog. Again you like to allow different ways of > authentication and you already wrote plugins for exactly the > same for your wiki, right? > > With most systems now some trouble begins - the blog software would need > to have the interface/extention-points/however-you-name-it that the wiki > software defined. > > The plugins you wrote probably import them from the wiki module directly > which means your blog would depend on the wiki. (?!) So where to put the > interface/[...] definition that is imported by those plugins? Create a > package/module just containing the interface? This really get > troublesome if different people wrote the wiki, the blog and another > third one a plugin. If you are talking about code sharing you can move the common code out of your applications in a seperate namespace. If you follow the model trac is using you would install a module/package/egg with the basic functionality of the pluginsystem (i.e. what's in core.py and env.py + logging and whatever you think is necessary). All shared code like your auth-plugins would go in a common plugin directory to which you can refer via PYTHONPATH. Another common technique is chaining of WSGI middleware..., check out pythonpaste.org. Then there is SOA where functionality is shared via RPC/webservices and wsdl/uddi. But my feeling is this is mostly used in "Enterprise" applications and is best used in Java/.NET where you already have libraries doing all the XML stuff. hth Paul From martin at v.loewis.de Sun Feb 14 04:25:14 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 14 Feb 2010 10:25:14 +0100 Subject: Hashing in python In-Reply-To: References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <4B77C17A.1020306@v.loewis.de> > floor(x) returns an integer Why do you say that? Assuming you are talking about math.floor, it works differently for me: py> math.floor(10.0/3) 3.0 Regards, Martin From martin at v.loewis.de Sun Feb 14 04:30:36 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 14 Feb 2010 10:30:36 +0100 Subject: Hashing in python In-Reply-To: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> Message-ID: <4B77C2BC.5080201@v.loewis.de> > CELL_SIZE = 4 > > def key(point): > > return ( > int((floor(point[0]/CELL_SIZE))*CELL_SIZE), > int((floor(point[1]/CELL_SIZE))*CELL_SIZE), > int((floor(point[2]/CELL_SIZE))*CELL_SIZE) > ) > > > Since python allows keys to be tuples, I think that this should work. > Is there a better (more efficient) way to do it? You don't say why you want to do hashing in the first place. If it is to access elements in a lookup table, and you are now using a dictionary, I'd suggest to replace that with a list. For 4x4x4 elements, you could either do table[int(point[0]/CELL_SIZE)][int(point[1]/CELL_SIZE)][int(point[2]/CELL_SIZE)] (i.e. have nested lists), or you allocate a list of 64 elements, and use def key(point): return 16*int(point[0]/CELL_SIZE) + 4*int(point[1]/CELL_SIZE) +\ int(point[2]/CELL_SIZE) table[key(point)] You could even use that key function as a key to a dictionary, if you can't use lists for some reason. Regards, Martin From karsten.goen at googlemail.com Sun Feb 14 04:33:54 2010 From: karsten.goen at googlemail.com (Karsten Goen) Date: Sun, 14 Feb 2010 10:33:54 +0100 Subject: problem with floats and calculations Message-ID: hey all, I got a problem with floats and calculations. I made an mini-application where you get random questions with some science calculations in it So the user can type in his result with the values given by random creation. And the user value is compared against the computer value... the problem is that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 here is the example: http://dpaste.com/hold/158698/ without decimal it would be very inaccurate. decimal is very accurate when I have to compare d with users calculations from a,b,c,var. But when I ask the user what is "a" the result gets inaccurate when calculating with the same values given before (b,c,d,var). Maybe anyone can help me with this problem, I don't want to generate for every possible user input a single formula. And also it should be possible for a computer, my calculator at home does the same and is much smaller and slower. thx in advance Karsten -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan-usenet at bytereef.org Sun Feb 14 05:29:56 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Sun, 14 Feb 2010 11:29:56 +0100 Subject: problem with floats and calculations In-Reply-To: References: Message-ID: <20100214102956.GA6524@yoda.bytereef.org> Karsten Goen wrote: > hey all, > I got a problem with floats and calculations. I made an mini-application where > you get random questions with some science calculations in it > So the user can type in his result with the values given by random creation. > And the user value is compared against the computer value... the problem is > that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 > > here is the example: > http://dpaste.com/hold/158698/ > > without decimal it would be very inaccurate. decimal is very accurate when I > have to compare d with users calculations from a,b,c,var. > But when I ask the user what is "a" the result gets inaccurate when calculating > with the same values given before (b,c,d,var). > > Maybe anyone can help me with this problem, I don't want to generate for every > possible user input a single formula. And also it should be possible for a > computer, my calculator at home does the same and is much smaller and slower. d = (a * b)/ (c * var) d = Decimal(d).quantize(Decimal('0.01')) By quantizing d, the above equality does not hold any longer. You've got to drop that line (your calculator doesn't quantize either). Stefan Krah From karsten.goen at googlemail.com Sun Feb 14 05:50:49 2010 From: karsten.goen at googlemail.com (Karsten Goen) Date: Sun, 14 Feb 2010 11:50:49 +0100 Subject: problem with floats and calculations In-Reply-To: <20100214102956.GA6524@yoda.bytereef.org> References: <20100214102956.GA6524@yoda.bytereef.org> Message-ID: also this doesn't help, there are still errors in the accuracy. Isn't there a perfect way to do such calculations? Karsten Goen wrote: > > hey all, > > I got a problem with floats and calculations. I made an mini-application > where > > you get random questions with some science calculations in it > > So the user can type in his result with the values given by random > creation. > > And the user value is compared against the computer value... the problem > is > > that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 > > > > here is the example: > > http://dpaste.com/hold/158698/ > > > > without decimal it would be very inaccurate. decimal is very accurate > when I > > have to compare d with users calculations from a,b,c,var. > > But when I ask the user what is "a" the result gets inaccurate when > calculating > > with the same values given before (b,c,d,var). > > > > Maybe anyone can help me with this problem, I don't want to generate for > every > > possible user input a single formula. And also it should be possible for > a > > computer, my calculator at home does the same and is much smaller and > slower. > > d = (a * b)/ (c * var) > d = Decimal(d).quantize(Decimal('0.01')) > > By quantizing d, the above equality does not hold any longer. You've got > to drop that line (your calculator doesn't quantize either). > > > Stefan Krah > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gandalf at shopzeus.com Sun Feb 14 06:28:59 2010 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Sun, 14 Feb 2010 12:28:59 +0100 Subject: MemoryError, can I use more? In-Reply-To: <7to2vmF2kvU1@mid.uni-berlin.de> References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: <4B77DE7B.1020001@shopzeus.com> 2010.02.13. 17:40 keltez?ssel, Diez B. Roggisch ?rta: > Am 13.02.10 17:18, schrieb Anssi Saari: >> Nobody writes: >> >>> A single process can't use much more than 2GiB of RAM without a >>> 64-bit CPU >>> and OS. >> >> That's not really true. Even Windows XP has the /3GB boot option to >> allow 3 GiB per process. On PCs, free operating systems and server >> Windows can use PAE to give access to full 4 GB per process. > > No, PAE can be used to access much more memory than 4GB - albeit > through paging. AFAIK up to 2^36 Bytes. PAE is for the kernel. Yes, you can use much more memory with 32 bit kernel + PAE. But the ~3G per 32bit process limit still applies. It is because the PAE extension allows the kernel to distribute the same virtual address ranges between different processes, but map them to different physical memory addresses. However, the process that was compiled and is running in 32 bit mode, cannot access more than ~3GB simply because it is not able to address more memory locations with 32 bit addresses. (minus ~1G is because it needs virtual addresses for I/O devices as well, and those addresses cannot be mapped to physical memory). So with any Python that is running in 32 bit mode, you cannot use more than ~3G memory. But you can start many instances of those programs and use 2G for each process. L From breamoreboy at yahoo.co.uk Sun Feb 14 06:41:45 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 14 Feb 2010 11:41:45 +0000 Subject: problem with floats and calculations In-Reply-To: References: <20100214102956.GA6524@yoda.bytereef.org> Message-ID: [fix top posting] > Karsten Goen wrote: >>> hey all, >>> I got a problem with floats and calculations. I made an mini-application >> where >>> you get random questions with some science calculations in it >>> So the user can type in his result with the values given by random >> creation. >>> And the user value is compared against the computer value... the problem >> is >>> that the user input is only 2 numbers behind the '.' so like 1.42, 1.75 >>> >>> here is the example: >>> http://dpaste.com/hold/158698/ >>> >>> without decimal it would be very inaccurate. decimal is very accurate >> when I >>> have to compare d with users calculations from a,b,c,var. >>> But when I ask the user what is "a" the result gets inaccurate when >> calculating >>> with the same values given before (b,c,d,var). >>> >>> Maybe anyone can help me with this problem, I don't want to generate for >> every >>> possible user input a single formula. And also it should be possible for >> a >>> computer, my calculator at home does the same and is much smaller and >> slower. >> >> d = (a * b)/ (c * var) >> d = Decimal(d).quantize(Decimal('0.01')) >> >> By quantizing d, the above equality does not hold any longer. You've got >> to drop that line (your calculator doesn't quantize either). >> >> >> Stefan Krah >> > Karsten Goen wrote: > also this doesn't help, there are still errors in the accuracy. Isn't there > a perfect way to do such calculations? > Please read the following and see if it helps. Also search the python users mailing list for something like floating point accuracy, you'll get plenty of hits. http://docs.python.org/tutorial/floatingpoint.html Regards. Mark Lawrence From stefan-usenet at bytereef.org Sun Feb 14 06:42:34 2010 From: stefan-usenet at bytereef.org (Stefan Krah) Date: Sun, 14 Feb 2010 12:42:34 +0100 Subject: problem with floats and calculations In-Reply-To: References: <20100214102956.GA6524@yoda.bytereef.org> Message-ID: <20100214114234.GA7498@yoda.bytereef.org> Karsten Goen wrote: > also this doesn't help, there are still errors in the accuracy. Isn't there a > perfect way to do such calculations? The hint I gave you removes the most egregious error in your program. You still have to quantize the result of (c*var*d) / b) if you want it to match a. If I adapt your program, I don't find any non-matching numbers. for i in range(100000): # set random numbers a = Decimal(str(random.uniform(0.1,123))).quantize(Decimal('0.01')) b = Decimal(str(random.uniform(20.1,3000))).quantize(Decimal('0.01')) c = Decimal(str(random.uniform(100, 5000))).quantize(Decimal('0.01')) var = Decimal('8.314').quantize(Decimal('0.01')) # calc d d = (a * b)/ (c * var) if ((c*var*d) / b).quantize(Decimal('0.01')) != a: print a, (c*var*d) / b Note that for perfect accuracy you should use the fraction module. Stefan Krah From abenthy at asylum.com Sun Feb 14 06:52:53 2010 From: abenthy at asylum.com (abent) Date: Sun, 14 Feb 2010 03:52:53 -0800 (PST) Subject: How to solve an LCP (linear complementarity problem) in python ? Message-ID: Is there a good library to numericly solve an LCP in python ? (http://en.wikipedia.org/wiki/Linear_complementarity_problem) An example would be very helpful because most libraries seem to only solve QP's. I need this for computing 2d contact forces in a rigid body simulation. From dino at phidev.org Sun Feb 14 07:05:06 2010 From: dino at phidev.org (Florian Ludwig) Date: Sun, 14 Feb 2010 13:05:06 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> Message-ID: <1266149106.4299.79.camel@brain> On Sun, 2010-02-14 at 10:16 +0100, Paul K?lle wrote: > Am 13.02.2010 10:50, schrieb Florian Ludwig: > > Hi, > > > > I'm looking for a module/plugin/intra-process-communication/hook system > > for python. Maybe someone here could point me to some project I missed > > or might have some good ideas if I end up implementing it myself. > > > > [...] > > > > The plugins you wrote probably import them from the wiki module directly > > which means your blog would depend on the wiki. (?!) So where to put the > > interface/[...] definition that is imported by those plugins? Create a > > package/module just containing the interface? This really get > > troublesome if different people wrote the wiki, the blog and another > > third one a plugin. > If you are talking about code sharing you can move the common code out > of your applications in a seperate namespace. If you follow the model > trac is using you would install a module/package/egg with the basic > functionality of the pluginsystem (i.e. what's in core.py and env.py + > logging and whatever you think is necessary). > All shared code like your auth-plugins would go in a common plugin > directory to which you can refer via PYTHONPATH. You're right, its about code sharing/reusing - should have said it more clearly. What I am looking for is the pluginsystem that makes this easy. Here there problem with the trac (and other plugin systems I've seen) approach: You need to define something like: | | class IAuthPlugin(Interface): [...] | in your blog software. Now within the open_id_login_plugin: | from blog import IAuthPlugin | | class OpenIdPlugin(object): | implements(IAuthPlugin) | So the OpenIdPlugin is specific for the blog and hardly sharable. Actually it is but it depends on the blog as it gets imported. This might be thought of as an implementation detail but its seems pretty common. > Another common technique is chaining of WSGI middleware..., check out > pythonpaste.org. WSGI middleware just doesn't do it in some situations. Also it only works out for web-based applications (my example was one but my question was more general). Thanks for your answer, Florian -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From moky.math at gmail.com Sun Feb 14 07:16:28 2010 From: moky.math at gmail.com (Laurent Claessens) Date: Sun, 14 Feb 2010 04:16:28 -0800 (PST) Subject: LaTeX parser and pstricks generator in python Message-ID: Hi all. I just put online a first version of two tools that combine LaTeX and python. The first one, phystricks[1], is a python module intended to generate pstricks code. The main features are * you don't have to know pstricks (but you need to have some basics in python) * you have python instead of LaTeX as backend programming language * the bounding box is automatically computed * thanks to Sage[5], you have a direct access to the derivative of functions (and much more). Thus, for example, tangent and normal vectors to any (cartesian/polar/parametric) plots are easy to draw. * eps export is possible in order to be more pdfLaTeX friendly. The documentation[3] contains many examples of figures created with phystricks. Download the file phystricks-doc.pdf[4] In a somewhat near future, I plan to add interaction with LaTeX : reading the .aux file, I can import the values of LaTeX's counters in python. You should be able to draw a line whose angular coefficient is the number of the last equation ;) That feature should also improve the computation of the bounding box in taking into account the LaTeX labels that one put in the picture. That lead me to the second tool I put online ... The second, LaTeXparser[2], is a simple LaTeXparser in python. Given a tex file, the features are * answer to the questions : what are the defined macros ? among of them, which are actually used ? with what arguments ? * substitute \input{...} by the content of the file * read the .aux file and take information about the values \label and \ref Every comments (and patches) are much welcome ! Have a good day Laurent [1] http://www.gitorious.org/phystricks [2] http://www.gitorious.org/latexparser [3] http://www.gitorious.org/phystricks-doc [4] http://www.gitorious.org/phystricks-doc/phystricks-doc/trees/master [5] http://sagemath.org/ From news123 at free.fr Sun Feb 14 07:17:40 2010 From: news123 at free.fr (News123) Date: Sun, 14 Feb 2010 13:17:40 +0100 Subject: problem with QtSignals "object has no attribute 'emit'" Message-ID: <4b77e9e4$0$6277$426a74cc@news.free.fr> Hi, I'm having a rather small code snippet, where I create pyQT signals. I manage creating a signal as class attribute, but I can't create a list of signals or a signal as object.member. > from PyQt4.QtGui import * > from PyQt4.QtCore import * > > class MyWin(QMainWindow): > clssig = pyqtSignal() > sigarr = [ pyqtSignal() ] > def emit_them(self): > self.objsig = pyqtSignal() > self.clssig.emit() # works > self.sigarr[0].emit() # fails > self.objsig.emit() # fails > > if __name__ == "__main__": > app = QApplication(sys.argv) > win = MyWin() > win.show() > win.emit_them() > sys.exit(app.exec_()) The two lines marked with fails will fail with following error: > AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'emit' The QT documentation states: "New signals should only be defined in sub-classes of QObject." I guess, that his is the reason. though I don't know enough about PyQT to understand the magic behind. Now my question: How could I create an array of signals if I wished to? I can work aroud it, but would be curious. Thanks for shadng some light on this (for me surprising) issue. N From jarausch at skynet.be Sun Feb 14 07:36:19 2010 From: jarausch at skynet.be (Helmut Jarausch) Date: Sun, 14 Feb 2010 13:36:19 +0100 Subject: How to solve an LCP (linear complementarity problem) in python ? In-Reply-To: References: Message-ID: <4b77ee43$0$2886$ba620e4c@news.skynet.be> On 02/14/10 12:52, abent wrote: > Is there a good library to numericly solve an LCP in python ? > (http://en.wikipedia.org/wiki/Linear_complementarity_problem) > > An example would be very helpful because most libraries seem to only > solve QP's. > I need this for computing 2d contact forces in a rigid body > simulation. Sorry, I can't help you except pointing you to the Complementarity Problem Net http://www.cs.wisc.edu/cpnet/ -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germany From phil at riverbankcomputing.com Sun Feb 14 07:53:49 2010 From: phil at riverbankcomputing.com (Phil Thompson) Date: Sun, 14 Feb 2010 12:53:49 +0000 Subject: problem with QtSignals "object has no attribute 'emit'" In-Reply-To: <4b77e9e4$0$6277$426a74cc@news.free.fr> References: <4b77e9e4$0$6277$426a74cc@news.free.fr> Message-ID: <50888e51273d0b98c5cb065d83488f8a@localhost> On Sun, 14 Feb 2010 13:17:40 +0100, News123 wrote: > Hi, > > I'm having a rather small code snippet, where I create pyQT signals. > I manage creating a signal as class attribute, > but I can't create a list of signals or a signal > as object.member. > > >> from PyQt4.QtGui import * >> from PyQt4.QtCore import * >> >> class MyWin(QMainWindow): >> clssig = pyqtSignal() >> sigarr = [ pyqtSignal() ] >> def emit_them(self): >> self.objsig = pyqtSignal() >> self.clssig.emit() # works >> self.sigarr[0].emit() # fails >> self.objsig.emit() # fails >> >> if __name__ == "__main__": >> app = QApplication(sys.argv) >> win = MyWin() >> win.show() >> win.emit_them() >> sys.exit(app.exec_()) > > The two lines marked with fails will fail with following error: >> AttributeError: 'PyQt4.QtCore.pyqtSignal' object has no attribute 'emit' > > The QT documentation states: > "New signals should only be defined in sub-classes of QObject." > > I guess, that his is the reason. though I don't know enough about PyQT > to understand the magic behind. > > > Now my question: > > How could I create an array of signals if I wished to? > > I can work aroud it, but would be curious. > > > Thanks for shadng some light on this (for me surprising) issue. You can't create an array of signals. Signals are defined to both Python and C++. This is done when the class is defined by introspecting the class attributes - but it doesn't look for signals any deeper than that, i.e. it won't look into your sigarr list. Even if it did, there is a second issue. Signals have unbound and bound versions (much like unbound and bound methods). The class attribute is an unbound signal that is a descriptor that will return the bound signal. It is the bound signal that implements the emit() method. It would be possible for an unbound signal's __call__ method to also return a bound signal so that you could do something like... self.sigarr[0](self).emit() ...but I can't think of a valid use case. Phil From steve at REMOVE-THIS-cybersource.com.au Sun Feb 14 10:11:19 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 14 Feb 2010 15:11:19 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> Message-ID: <4b781297$0$8767$c3e8da3@news.astraweb.com> On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote: > The term "pointer" is very abstract. Please give me a concrete > definition of a pointer. A programming language data type whose value directly specifies (or "points to") another value which is stored elsewhere in the computer memory. I quote from Wikipedia: http://en.wikipedia.org/wiki/Pointer_(computing) [quote] A pointer is a simple, less abstracted implementation of the more abstracted reference data type [end quote] And later: [quote] While "pointer" has been used to refer to references in general, it more properly applies to data structures whose interface explicitly allows the pointer to be manipulated (arithmetically via pointer arithmetic) as a memory address... [end quote] And again: [quote] A memory pointer (or just pointer) is a primitive, the value of which is intended to be used as a memory address; it is said that a pointer points to a memory address. It is also said that a pointer points to a datum [in memory] when the pointer's value is the datum's memory address. More generally, a pointer is a kind of reference, and it is said that a pointer references a datum stored somewhere in memory; to obtain that datum is to dereference the pointer. The feature that separates pointers from other kinds of reference is that a pointer's value is meant to be interpreted as a memory address, which is a rather 'low-level' concept. [end quote] > A curly brace is one of these: { } > > Pretty concrete, I hope. But { and } are glyphs in some typeface. Chances are that what you see, and what I see, are quite different, and whatever pixels we see, the compiler sees something radically different: two abstract characters implemented in some concrete fashion, but that concrete fashion is a mere implementation detail. They could be implemented as bytes x7b and x7d, or as four-byte sequences x0000007b and x0000007d for UTF-32, or who knows what in some other system. So the *concrete* representation of the curly brace varies according to the system. >From that, it's not a difficult leap to say that Pascal's BEGIN and END key words are mere alternate spellings of the abstract "open curly brace" and "close curly brace" with different concrete representations, and from that it's a small step to say that the INDENT and DEDENT tokens seen by the Python compiler (but absent from Python source code!) are too. >> But reference also has a concrete meaning: C++ has a type explicitly >> called "reference": >> >> http://en.wikipedia.org/wiki/Reference_(C++) >> >> > Of course, "reference" has concrete meanings in specific contexts. But I > can refer you to much more general and abstract uses of the term > "reference." Do you want references? I will be happy to refer you to > appropriate references. I know that reference can also be used in the abstract. I'm just warning that it can also be used in the concrete, and so we need to be wary of misunderstandings and confusions. >> And of course call-by-reference (or pass-by-reference) has a specific, >> technical meaning. >> >> > Which is what? http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference -- Steven From mukeshtiwari.iiitm at gmail.com Sun Feb 14 11:53:15 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sun, 14 Feb 2010 08:53:15 -0800 (PST) Subject: Python Optimization Message-ID: Hello everyone. I am new to python and previously i did programming in c/c++.Could some one please help me to improve the run time for this python program as i don't have idea how to optimized this code.This code also seems to be more unpythonic so how to make it look like more pythonic . I am trying for this problem(https://www.spoj.pl/problems/ FACT1/). Thank you # To change this template, choose Tools | Templates # and open the template in the editor. __author__="Mukesh Tiwari" __date__ ="$Feb 10, 2010 1:35:26 AM$" import random from Queue import Queue def gcd(a,b): while b: a,b=b,a%b return a def rabin_miller(p,t=1): if(p<2): return False if(p!=2 and p%2==0): return False s=p-1 while(s%2==0): s>>=1 for i in xrange(t): a=random.randrange(p-1)+1 temp=s mod=pow(a,temp,p) while(temp!=p-1 and mod!=1 and mod!=p-1): mod=(mod*mod)%p temp=temp*2 if(mod!=p-1 and temp%2==0): return False return True def brent(n): if(n%2==0): return 2; x,c,m=random.randrange(0,n),random.randrange(1,n),random.randrange(1,n) y,r,q=x,1,1 g,ys=0,0 while(True): x=y for i in range(r): y,k=(y*y+c)%n,0 while(True): ys=y for i in range(min(m,r-k)): y,q=(y*y+c)%n,q*abs(x-y)%n g,k=gcd(q,n),k+m if(k>= r or g>1):break r=2*r if(g>1):break if(g==n): while(True): ys,g=(x*x+c)%n,gcd(abs(x-ys),n) if(g>1):break return g def factor(n): Q_1,Q_2=Queue(),[] Q_1.put(n) while(not Q_1.empty()): l=Q_1.get() if(rabin_miller(l)): Q_2.append(l) continue d=brent(l) if(d==l):Q_1.put(l) else: Q_1.put(d) Q_1.put(l/d) return Q_2 if __name__ == "__main__": while(True): n=int(raw_input()) if(n==0):break L=factor(n) L.sort() #print L i=0 s="" while(i References: Message-ID: mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code.This > code also seems to be more unpythonic so how to make it look like more > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > FACT1/). > Thank you > > # To change this template, choose Tools | Templates > # and open the template in the editor. > > __author__="Mukesh Tiwari" > __date__ ="$Feb 10, 2010 1:35:26 AM$" > > > import random > from Queue import Queue > > > def gcd(a,b): > while b: > a,b=b,a%b > return a > > def rabin_miller(p,t=1): > if(p<2): > return False > if(p!=2 and p%2==0): > return False > s=p-1 > while(s%2==0): > s>>=1 > for i in xrange(t): > a=random.randrange(p-1)+1 > temp=s > mod=pow(a,temp,p) > while(temp!=p-1 and mod!=1 and mod!=p-1): > mod=(mod*mod)%p > temp=temp*2 > if(mod!=p-1 and temp%2==0): > return False > return True > def brent(n): > if(n%2==0): > return 2; > > x,c,m=random.randrange(0,n),random.randrange(1,n),random.randrange(1,n) > y,r,q=x,1,1 > g,ys=0,0 > while(True): > x=y > for i in range(r): > y,k=(y*y+c)%n,0 > while(True): > ys=y > for i in range(min(m,r-k)): > y,q=(y*y+c)%n,q*abs(x-y)%n > g,k=gcd(q,n),k+m > if(k>= r or g>1):break > r=2*r > if(g>1):break > if(g==n): > while(True): > ys,g=(x*x+c)%n,gcd(abs(x-ys),n) > if(g>1):break > return g > > > def factor(n): > Q_1,Q_2=Queue(),[] > Q_1.put(n) > while(not Q_1.empty()): > l=Q_1.get() > if(rabin_miller(l)): > Q_2.append(l) > continue > d=brent(l) > if(d==l):Q_1.put(l) > else: > Q_1.put(d) > Q_1.put(l/d) > return Q_2 > > > > if __name__ == "__main__": > while(True): > n=int(raw_input()) > if(n==0):break > L=factor(n) > L.sort() > #print L > i=0 > s="" > while(i cnt=L.count(L[i]) > #print "%d^%d"%(L[i],cnt) > s+=str(L[i])+"^"+str(cnt)+" " > i+=cnt > print s[:-1] A good starting point is http://wiki.python.org/moin/PythonSpeed/PerformanceTips HTH. Mark Lawrence From python at mrabarnett.plus.com Sun Feb 14 12:29:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 17:29:41 +0000 Subject: Hashing in python In-Reply-To: <4B77C17A.1020306@v.loewis.de> References: <6a2ea0d2-fe99-4ac4-ab03-a8ae95106900@k5g2000pra.googlegroups.com> <4B77C17A.1020306@v.loewis.de> Message-ID: <4B783305.5090405@mrabarnett.plus.com> Martin v. Loewis wrote: >> floor(x) returns an integer > > Why do you say that? Assuming you are talking about math.floor, it works > differently for me: > > py> math.floor(10.0/3) > 3.0 > I've just double-checked. It returns a float in Python 2.x and an int in Python 3.x. (I recently switched to Python 3.1.) From deets at nospam.web.de Sun Feb 14 12:47:30 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sun, 14 Feb 2010 18:47:30 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> Message-ID: <7tqr9iFbi7U1@mid.uni-berlin.de> Am 14.02.10 13:05, schrieb Florian Ludwig: > On Sun, 2010-02-14 at 10:16 +0100, Paul K?lle wrote: >> Am 13.02.2010 10:50, schrieb Florian Ludwig: >>> Hi, >>> >>> I'm looking for a module/plugin/intra-process-communication/hook system >>> for python. Maybe someone here could point me to some project I missed >>> or might have some good ideas if I end up implementing it myself. >>> >>> [...] >>> >>> The plugins you wrote probably import them from the wiki module directly >>> which means your blog would depend on the wiki. (?!) So where to put the >>> interface/[...] definition that is imported by those plugins? Create a >>> package/module just containing the interface? This really get >>> troublesome if different people wrote the wiki, the blog and another >>> third one a plugin. > >> If you are talking about code sharing you can move the common code out >> of your applications in a seperate namespace. If you follow the model >> trac is using you would install a module/package/egg with the basic >> functionality of the pluginsystem (i.e. what's in core.py and env.py + >> logging and whatever you think is necessary). > >> All shared code like your auth-plugins would go in a common plugin >> directory to which you can refer via PYTHONPATH. > > You're right, its about code sharing/reusing - should have said it more > clearly. What I am looking for is the pluginsystem that makes this easy. > Here there problem with the trac (and other plugin systems I've seen) > approach: > > You need to define something like: > | > | class IAuthPlugin(Interface): [...] > | > in your blog software. Why? Any reason you can't define it in a separate package the blog-software depends on, as well as your wiki? And then of course, this is not really needed. In Python, behavior counts, not type-information. So you can get away without any explicit declared interface. You might chose to not do that, for aestetic reasons, or better documentation. But you aren't forced. diez From dickinsm at gmail.com Sun Feb 14 12:48:11 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 14 Feb 2010 09:48:11 -0800 (PST) Subject: Python Optimization References: Message-ID: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> On Feb 14, 4:53?pm, mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code. > [...] How much of a speedup do you need? Are we talking about orders of magnitude (in which case you might want to consider using something like the Multiple Polynomial Quadratic Sieve method instead, or as well), or just a few percent? (1) Have you profiled the code to see where it's spending most of its time? This is an essential first step. (2) Obvious things: use range rather than xrange in your loops. Make sure that all heavily used variables/functions are local to the function you're using them in. E.g., you use range, min and abs in the middle of the 'brent' function. Instead, start the brent function by setting _abs, _range, _min = abs, range, min, and then use _abs, _range, etc. instead. Lookups of local variables are faster than globals. (3) In the inner loop: for i in range(min(m,r-k)): y,q=(y*y+c)%n,q*abs(x-y)%n you can get probably rid of the abs call. It *might* also help to avoid the tuple packing/unpacking (but see (1)). You could try doing a couple of steps at a time instead of one (i.e., unroll the loop a little bit); one advantage is that you probably don't need to bother reducing q modulo n at every step; every other step would be good enough. Depending on the relative speed of multiplication and reduction, and the sizes of the integers involved, this might save time. (4) Have you tried using Montgomery reduction in the Brent method? The inner loop of that method involves two reductions modulo n, which may well be where the biggest bottleneck is. But see (1). The other obvious bottleneck is the gcd method; if profiling shows that that's the case, there might be ways to speed that up, too. (E.g., use a binary gcd algorithm, or use Lehmer's method.) Good luck! -- Mark From showell30 at yahoo.com Sun Feb 14 12:51:38 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 09:51:38 -0800 (PST) Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> Message-ID: <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> On Feb 14, 7:11?am, Steven D'Aprano wrote: > On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote: > > The term "pointer" is very abstract. ?Please give me a concrete > > definition of a pointer. > > A programming language data type whose value directly specifies (or > "points to") another value which is stored elsewhere in the computer > memory. > > I quote from Wikipedia: > > http://en.wikipedia.org/wiki/Pointer_(computing) > > ? ? [quote] > ? ? A pointer is a simple, less abstracted implementation of the > ? ? more abstracted reference data type > ? ? [end quote] > > And later: > > ? ? [quote] > ? ? While "pointer" has been used to refer to references in > ? ? general, it more properly applies to data structures whose > ? ? interface explicitly allows the pointer to be manipulated > ? ? (arithmetically via pointer arithmetic) as a memory > ? ? address... > ? ? [end quote] > > And again: > > ? ? [quote] > ? ? A memory pointer (or just pointer) is a primitive, the value > ? ? of which is intended to be used as a memory address; it is said > ? ? that a pointer points to a memory address. It is also said that > ? ? a pointer points to a datum [in memory] when the pointer's value > ? ? is the datum's memory address. > > ? ? More generally, a pointer is a kind of reference, and it is said > ? ? that a pointer references a datum stored somewhere in memory; to > ? ? obtain that datum is to dereference the pointer. The feature that > ? ? separates pointers from other kinds of reference is that a > ? ? pointer's value is meant to be interpreted as a memory address, > ? ? which is a rather 'low-level' concept. > ? ? [end quote] > > > A curly brace is one of these: { } > > > Pretty concrete, I hope. > > But { and } are glyphs in some typeface. Chances are that what you see, > and what I see, are quite different, and whatever pixels we see, the > compiler sees something radically different: two abstract characters > implemented in some concrete fashion, but that concrete fashion is a mere > implementation detail. They could be implemented as bytes x7b and x7d, or > as four-byte sequences x0000007b and x0000007d for UTF-32, or who knows > what in some other system. So the *concrete* representation of the curly > brace varies according to the system. > > From that, it's not a difficult leap to say that Pascal's BEGIN and END > key words are mere alternate spellings of the abstract "open curly brace" > and "close curly brace" with different concrete representations, and from > that it's a small step to say that the INDENT and DEDENT tokens seen by > the Python compiler (but absent from Python source code!) are too. > Thanks. It's a useful analogy; I think I understand your point better. I've been bouncing around between Python and Javascript a lot lately, so your analogy resonates with me. There are many times when I find myself simply respelling things like begin/end, and those respellings to me almost make me think of Python and Javascript as different dialects of an underlying language. Of course, there are other places where the languages differ more substantively, too. Going back to pointers vs. references, I think the key distinction being made is that pointers allow specific memory manipulation, although I think even there you're really just dealing with abstractions. The address 0x78F394D2 is a little bit closer to the machine than, say, the 42nd element of a Python list, but they are both just abstractions on top of underlying machines, whether the machines are virtual, electronic circuits, vacuum tubes, whatever. You can add 6 to 42 and get the 48th object, but its Python's convention not to call the 48th object a memory address or expose a reference to it as a pointer. If I want to pass along the reference to the 48th element of a list as the slot to be updated (i.e. with the intention to actually mutate the list itself), then I need a tuple like (lst, 48). From kaklis at gmail.com Sun Feb 14 12:59:12 2010 From: kaklis at gmail.com (kaklis at gmail.com) Date: Sun, 14 Feb 2010 09:59:12 -0800 (PST) Subject: Comparing file last access date Message-ID: <2e4fc893-2fe7-467a-8b5e-abe0816e665d@r33g2000yqb.googlegroups.com> Hi to all, what i want is to search a folder, and if the last access date of the files in that folder is greater than, lets say 7 days, those files deleted. (Somekind of a file cleaner script) I had problems with converting now = today = datetime.date.today() and stats = os.stat(file) lastAccessDate = time.localtime(stats[7]) into matching formats so that if (now - lastAccessDate) > 7: delete the file what i do wrong Thanks in advance Antonis From aahz at pythoncraft.com Sun Feb 14 13:03:21 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2010 10:03:21 -0800 Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> Message-ID: In article <363498c7-3575-4f1e-ad53-d9cd10c8da2c at q16g2000yqq.googlegroups.com>, Mark Dickinson wrote: > >(2) Obvious things: use range rather than xrange in your loops. Um, what? You meant the reverse, surely? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From python at mrabarnett.plus.com Sun Feb 14 13:20:27 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 14 Feb 2010 18:20:27 +0000 Subject: Comparing file last access date In-Reply-To: <2e4fc893-2fe7-467a-8b5e-abe0816e665d@r33g2000yqb.googlegroups.com> References: <2e4fc893-2fe7-467a-8b5e-abe0816e665d@r33g2000yqb.googlegroups.com> Message-ID: <4B783EEB.9030800@mrabarnett.plus.com> kaklis at gmail.com wrote: > Hi to all, > what i want is to search a folder, and if the last access date of the > files in that folder is greater than, lets say 7 days, those files > deleted. (Somekind of a file cleaner script) > I had problems with converting > > now = today = datetime.date.today() > and > stats = os.stat(file) > lastAccessDate = time.localtime(stats[7]) > > into matching formats so that > if (now - lastAccessDate) > 7: > delete the file > > what i do wrong > Thanks in advance > Antonis I would use: seven_days = 7 * 24 * 60 * 60 # 7 days in seconds now = time.time() # in seconds since Epoch ... last_access = os.path.getatime(path) # in seconds since Epoch if now - last_access > seven_days: os.remove(path) From aahz at pythoncraft.com Sun Feb 14 13:21:25 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2010 10:21:25 -0800 Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 References: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> Message-ID: In article <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482 at r24g2000yqd.googlegroups.com>, seth wrote: > >We have a code that creates a simple Python shelve database. We are >able to serialize objects and store them in the dbm file. This seem to >work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6, >but on Os X 10.5 with Python 2.5 the database filename is changed by >the operating system by attaching the .db extension to it. Does an one >know why is that? Nope -- any reason you can't change the filename? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From steve at holdenweb.com Sun Feb 14 13:32:29 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Feb 2010 13:32:29 -0500 Subject: Please help with MemoryError In-Reply-To: References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: rantingrick wrote: > On Feb 12, 4:10 pm, Steve Holden wrote: >> Antoine Pitrou wrote: >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > On Feb 12, 4:10 pm, Steve Holden wrote: >> Antoine Pitrou wrote: >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > Steve, > Why do so many of your posts come in as doubles and triples. Is this a > case of "studdering click finger" of some fault of your newsreader? > > -- concerned fellow pythonista... I suspect it's because I am being insufficiently disciplined about using "reply" instead of "reply all". On gmane they only appear once, so I suspect some other component of the mail/news loop is less assiduous about de-duping the content. How do you read the list? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From showell30 at yahoo.com Sun Feb 14 13:41:35 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 10:41:35 -0800 (PST) Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> Message-ID: <88a7ff43-3f1d-4e30-ad50-59b6c2f215f7@a5g2000prg.googlegroups.com> On Feb 14, 9:48?am, Mark Dickinson wrote: > On Feb 14, 4:53?pm, mukesh tiwari > wrote: > > > Hello everyone. I am new to python and previously i did programming in > > c/c++.Could some one please help me to improve the run time for this > > python program as i don't have idea how to optimized this code. > > [...] > > How much of a speedup do you need? ?Are we talking about orders of > magnitude (in which case you might want to consider using something > like the Multiple Polynomial Quadratic Sieve method instead, or as > well), or just a few percent? > > (1) Have you profiled the code to see where it's spending most of its > time? ?This is an essential first step. > I ditto the profiling recommendation. http://docs.python.org/library/profile.html It might also be useful to time your algorithm for n=10, 100, 1000, 10000, etc., to get a better sense of how the overall algorithm behaves. From showell30 at yahoo.com Sun Feb 14 13:48:50 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 10:48:50 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> <39babfd0-30af-4357-9bda-df1fdf1f43c5@l24g2000prh.googlegroups.com> <038578a2$0$1277$c3e8da3@news.astraweb.com> Message-ID: <7c65aa94-ed69-48d9-b37b-8b1cb376fa3e@t31g2000prh.googlegroups.com> On Feb 14, 10:32?am, Steve Holden wrote: > rantingrick wrote: > > On Feb 12, 4:10 pm, Steve Holden wrote: > >> Antoine Pitrou wrote: > >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > > On Feb 12, 4:10 pm, Steve Holden wrote: > >> Antoine Pitrou wrote: > >>> Le Fri, 12 Feb 2010 17:14:57 +0000, Steven D'Aprano a ?crit : > > > Steve, > > Why do so many of your posts come in as doubles and triples. Is this a > > case of "studdering click finger" of some fault of your newsreader? > > > -- concerned fellow pythonista... > > I suspect it's because I am being insufficiently disciplined about using > "reply" instead of "reply all". On gmane they only appear once, so I > suspect some other component of the mail/news loop is less assiduous > about de-duping the content. > > How do you read the list? > Hi Steve, I mostly read the list through Google groups, and I have seen occasional dups from you. Of course, the readers themselves could be a little smarter about recognizing duplication, but that does not appear to be the case with Google. On the other hand, I am not seeing dups from you in a quick skim of this thread, so I wonder if it just takes Google a little while to weed out the dups. From showell30 at yahoo.com Sun Feb 14 14:04:37 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 11:04:37 -0800 (PST) Subject: Please help with MemoryError References: <534b45ba-3911-4fbe-b0e4-31e000a39a2c@u19g2000prh.googlegroups.com> <03849ff7$0$1277$c3e8da3@news.astraweb.com> Message-ID: <6bb774a3-ed05-402a-a7f2-9c472940379e@b9g2000pri.googlegroups.com> On Feb 11, 5:50?pm, Steven D'Aprano wrote: > On Thu, 11 Feb 2010 15:39:09 -0800, Jeremy wrote: > > My Python program now consumes over 2 GB of memory and then I get a > > MemoryError. ?I know I am reading lots of files into memory, but not 2GB > > worth. > > 2. ? ?When do I need > > to manually allocate/deallocate memory and when can I trust Python to > > take care of it? > > You never need to manually allocate memory. > > You *may* need to deallocate memory if you make "reference loops", where > one object refers to itself: > > l = [] ?# make an empty list > l.append(l) ?# add the list l to itself > > Python can break such simple reference loops itself, but for more > complicated ones, you may need to break them yourself: > > a = [] > b = {2: a} > c = (None, b) > d = [1, 'z', c] > a.append(d) ?# a reference loop > > Python will deallocate objects when they are no longer in use. They are > always considered in use any time you have them assigned to a name, or in > a list or dict or other structure which is in use. > > You can explicitly remove a name with the del command. For example: > > x = ['my', 'data'] > del x > > After deleting the name x, the list object itself is no longer in use > anywhere and Python will deallocate it. But consider: > > x = ['my', 'data'] > y = x ?# y now refers to THE SAME list object > del x > > Although you have deleted the name x, the list object is still bound to > the name y, and so Python will *not* deallocate the list. > > Likewise: > > x = ['my', 'data'] > y = [None, 1, x, 'hello world'] > del x > > Although now the list isn't bound to a name, it is inside another list, > and so Python will not deallocate it. > Another technique that comes up some time is that you have a list of objects that you are processing: x = [obj1, obj2, obj3, obj4] When you are done processing obj1, you want to remove the reference to it, but you do not necessarily want to change the list itself. You can break the reference by saying "x[0] = None" when you are done handling obj1. Of course, if you can avoid creating the list in the first place, as some people have suggested, then you really get a savings. The setting-to-None technique is also occasionally useful with objects, where you can say foo.bar = None when you are done with "bar" but not with "foo." Of course, the need to use such a technique often points out a deeper code smell with Foo itself, but I've seen it come up. Steven's examples of a reference loop are deliberately simplified, of course, but the chain of references in a real world program can get quite long, and there's often great savings to be reaped if you can break the "keystone" reference, so to speak. In other words, breaking just one reference often allows other references to fall down like dominos. From dickinsm at gmail.com Sun Feb 14 14:35:35 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 14 Feb 2010 11:35:35 -0800 (PST) Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> Message-ID: On Feb 14, 6:03?pm, a... at pythoncraft.com (Aahz) wrote: > In article <363498c7-3575-4f1e-ad53-d9cd10c8d... at q16g2000yqq.googlegroups.com>, > Mark Dickinson ? wrote: > > >(2) Obvious things: use range rather than xrange in your loops. ? > > Um, what? ?You meant the reverse, surely? Er, yes I did. Thanks! -- Mark From dickinsm at gmail.com Sun Feb 14 14:52:51 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 14 Feb 2010 11:52:51 -0800 (PST) Subject: Python Optimization References: Message-ID: <892f7664-14e9-4ce4-ab50-499fc8552ec3@v25g2000yqk.googlegroups.com> On Feb 14, 4:53?pm, mukesh tiwari wrote: > Hello everyone. I am new to python and previously i did programming in > c/c++.Could some one please help me to improve the run time for this > python program as i don't have idea how to optimized this code.This > code also seems to be more unpythonic so how to make it look like more > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > FACT1/). > Thank you One other thing: in the 'brent' function, you're setting m to randrange(1, n). What's the purpose of this? It looks to me as though m controls the number of Pollard-Rho iterations that are clumped together at one time (before doing a gcd operation), and using a random number for this doesn't make a lot of sense to me. -- Mark From showell30 at yahoo.com Sun Feb 14 15:07:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 14 Feb 2010 12:07:41 -0800 (PST) Subject: Python Optimization References: <892f7664-14e9-4ce4-ab50-499fc8552ec3@v25g2000yqk.googlegroups.com> Message-ID: <0eac0e90-fd39-4851-b979-c109218fb0ba@a5g2000prg.googlegroups.com> On Feb 14, 11:52?am, Mark Dickinson wrote: > On Feb 14, 4:53?pm, mukesh tiwari > wrote: > > > Hello everyone. I am new to python and previously i did programming in > > c/c++.Could some one please help me to improve the run time for this > > python program as i don't have idea how to optimized this code.This > > code also seems to be more unpythonic so how to make it look like more > > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > > FACT1/). > > Thank you > > One other thing: ?in the 'brent' function, you're setting m to > randrange(1, n). ?What's the purpose of this? ?It looks to me as > though m controls the number of Pollard-Rho iterations that are > clumped together at one time (before doing a gcd operation), and using > a random number for this doesn't make a lot of sense to me. > The randomness also makes the algorithm a little buggy. I tried this input: 37^5 41^5 Usually I get the right answer. Other times I get this: 37^5 41^3 1681^1 And occasionally it appears to get into an infinite loop, which definitely could be a cause of "slowness." :) From phiporiphic at gmail.com Sun Feb 14 15:23:41 2010 From: phiporiphic at gmail.com (Mr.John) Date: Sun, 14 Feb 2010 15:23:41 -0500 Subject: Fighting with subprocess.Popen Message-ID: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> I'm using Python 2.6.2 as packaged with Fedora 12. I'm trying to use subprocess.Popen() to call /usr/bin/pactl, a simple PulseAudio command parser. I'm having a hard time, because it only works part of the time. If pactl gets a blank or invalid command, it says "No valid command specified.", and this is what prints to stderr most of the time. I can get the result of "pactl list", but anything else I try returns "No valid command specified." So, pactl is getting called, but my args are disappearing somewhere. But not every time... Below is a test case that demonstrates this. Tests 1 & 2 concatenate the command and the argument, Tests 3 & 4 mimic the python docs and use the form Popen(["mycmd", "myarg"], ...), which never seems to work. import subprocess list = 'list' list_sinks = 'list-sinks' print("### TEST 1") a = subprocess.Popen('pactl ' + list, shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) print("### TEST 2") a = subprocess.Popen('pactl ' + list_sinks, shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) print("### TEST 3") a = subprocess.Popen(['pactl', list], shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) print("### TEST 4") a = subprocess.Popen(['pactl', list_sinks], shell=True, stdout=subprocess.PIPE) res = a.communicate() print(repr(res[0])) ### TEST 1 (success... snip) ### TEST 2 No valid command specified. '' ### TEST 3 No valid command specified. '' ### TEST 4 No valid command specified. '' Does anyone have any idea what I'm doing wrong? Thanks, John -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Sun Feb 14 15:39:40 2010 From: aahz at pythoncraft.com (Aahz) Date: 14 Feb 2010 12:39:40 -0800 Subject: equivalent of Ruby's Pathname? References: <843d5af9-e8db-4352-a853-4c99664eadf8@k6g2000prg.googlegroups.com> <8fc356e0-f3ed-4a67-9b37-f21561cef4a5@p13g2000pre.googlegroups.com> Message-ID: In article <8fc356e0-f3ed-4a67-9b37-f21561cef4a5 at p13g2000pre.googlegroups.com>, Sean DiZazzo wrote: >On Feb 8, 2:36=A0pm, a... at pythoncraft.com (Aahz) wrote: >> In article .com>, >> Sean DiZazzo =A0 wrote: >>> >>>Why did Path() get rejected? Is it the idea itself, or just the >>>approach that was used? What are the complaints? >> >> You should search for the discussiona around it. > >I read the discussion, and there was definitely some going back and >forth on whether it should be sub-classed from string, but the >conversation just seemed to stop abruptly with no decision one way of >the other. Maybe I missed a thread. > >I guess being dropped without a final go-ahead is just as good as a >formal no anyway. Not quite: because it was not rejected, someone who wants to shepherd the process forward would likely be welcomed (even if it ends up with formal rejection). I suggest starting by writing your own summary of the previous discussion and see if the people involved agree that your summary is reasonably accurate. Also check to see if the original PEP writer wants to be involved or whether zie is willing to have you take over. Another good (and related) starting point would be to create a reasoning favoring one side or the other that was not brought up in previous discussion. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From lists at cheimes.de Sun Feb 14 15:43:22 2010 From: lists at cheimes.de (Christian Heimes) Date: Sun, 14 Feb 2010 21:43:22 +0100 Subject: Fighting with subprocess.Popen In-Reply-To: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> References: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> Message-ID: Mr.John wrote: > Below is a test case that demonstrates this. Tests 1 & 2 concatenate the > command and the argument, Tests 3 & 4 mimic the python docs and use the form > Popen(["mycmd", "myarg"], ...), which never seems to work. It doesn't work with shell=True because the shell is not able to interpret the list form. It's recommended that you don't use shell=True unless you need a shell. Christian From rschroev_nospam_ml at fastmail.fm Sun Feb 14 15:46:13 2010 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 14 Feb 2010 21:46:13 +0100 Subject: python crash on windows but not on linux In-Reply-To: References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> <7tngf2Fo5rU1@mid.uni-berlin.de> <32835daa-ced4-4c67-b335-25b44d734674@y33g2000yqb.googlegroups.com> Message-ID: Op 2010-02-13 13:14, Alf P. Steinbach schreef: > * hjebbers: >> I enlarged the windows page file from 750Kb to 1.5Gb . >> The crash still happens. >> btw, the crash does not happen at a peak memory usage. >> According to windows task manager, at the moment of crash mem usage of >> my program is 669kb, peak memory usage is 1.136kb >> >> henk-jan > > Probably you meant to write "M", not "k" or "K"? > > I've never managed to make much sense of the displays in Windows' Task Manager, > if that's what you're using, but I think the mem usage it's displaying by > default is the process' working set, or something very similar to that measure. > > You can display additional columns in Task Manager, and one useful one is how > much virtual memory is allocated,. > > And perhaps then (if that's not what you're looking it already) it'll be closer > to 2 GiB? Note that the memory measurements in Task Manager are pretty limited and. Comparing Task Manager and Process Explorer: Task Manager - Process Explorer Mem Usage - Working Set VM Size - Private Bytes n/a - Virtual Size I tend to trust Process Explorer a lot more than Task Manager. Note that what Task Manager calls VM Size is not the size of the virtual memory as might be expected (if Process Explorer is to be trusted), and that Task Manager doesn't show the virtual memory size (at least on Windows XP). -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From tjreedy at udel.edu Sun Feb 14 16:23:30 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Feb 2010 16:23:30 -0500 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: On 2/13/2010 8:14 AM, Steve Holden wrote: > Gmane is primarily a news (NNTP-based) service, though for reasons best > know to the organizers they choose to rename the standard newsgroups to > fit their own idea of how the universe should be organized, so there the > group becomes gmane.comp.python.general. As I understand the site, the last I read a year or two ago, gmane is a technical mailinglist-to-news gateway. It does not mirror newsgroups, standard or not. It only mirrors lists such as python-list, not newsgroups, such comp.lang.python. In doing so, it organizes the lists into categories like g.comp.python, which has about 200 subgroups mirroring 200 python lists. From steve at holdenweb.com Sun Feb 14 16:32:36 2010 From: steve at holdenweb.com (Steve Holden) Date: Sun, 14 Feb 2010 16:32:36 -0500 Subject: Function attributes [OT] In-Reply-To: References: <19765822-7989-49d9-b1d2-88b403a361f0@r24g2000yqd.googlegroups.com> Message-ID: Terry Reedy wrote: > On 2/13/2010 8:14 AM, Steve Holden wrote: > >> Gmane is primarily a news (NNTP-based) service, though for reasons best >> know to the organizers they choose to rename the standard newsgroups to >> fit their own idea of how the universe should be organized, so there the >> group becomes gmane.comp.python.general. > > As I understand the site, the last I read a year or two ago, gmane is a > technical mailinglist-to-news gateway. It does not mirror newsgroups, > standard or not. It only mirrors lists such as python-list, not > newsgroups, such comp.lang.python. In doing so, it organizes the lists > into categories like g.comp.python, which has about 200 subgroups > mirroring 200 python lists. > That would make more sense. I know that the python.org infrastructure acts as a gateway between the mailing list and the newsgroup. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From rridge at csclub.uwaterloo.ca Sun Feb 14 17:05:07 2010 From: rridge at csclub.uwaterloo.ca (Ross Ridge) Date: Sun, 14 Feb 2010 17:05:07 -0500 Subject: MemoryError, can I use more? References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: "Diez B. Roggisch" writes: > No, PAE can be used to access much more memory than 4GB - albeit > through paging. AFAIK up to 2^36 Bytes. Anssi Saari wrote: >That too. I admit, after checking, that you can't go above 3 GiB per >process even in server Windows. But for Linux there exists (or >existed, since it seems it hasn't been updated since 2004) a kernel >patch which provides a "4GB/4GB" address split. Kernel is in one >segment, userland in another and hence a process can access full 4GB. Windows has a similar feature that allows 32-bit applications running on 64-bit versions of Windows to have a nearly 4Gb virtual address space. Windows also allows 32-bit applications to use more than 4GB of physical memory through a paging mechanism called "Address Windowing Extensions". Also 32-bit applications can effectively use more than 4GB of RAM through indirect means like multiple processes, the disk cache or video card RAM. Ross Ridge -- l/ // Ross Ridge -- The Great HTMU [oo][oo] rridge at csclub.uwaterloo.ca -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/ db // From joe at joemoney.net Sun Feb 14 17:42:35 2010 From: joe at joemoney.net (monkeys paw) Date: Sun, 14 Feb 2010 17:42:35 -0500 Subject: new python install Message-ID: <4badnYd5OJHA4eXWnZ2dnUVZ_oidnZ2d@insightbb.com> Upon invoking python, it hangs until Ctrl^C is typed, and then the >>> interactive shell begins. Like so: joemoney% python Python 2.4.6 (#1, Dec 13 2009, 23:45:11) [C] on sunos5 Type "help", "copyright", "credits" or "license" for more information. # Hangs ^^^ at this point until ^C is typed ^C >>> I've seen this in other new installs and wondered if there is a common problem that would cause this? It's on a sun os box From deets at nospam.web.de Sun Feb 14 18:20:40 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 15 Feb 2010 00:20:40 +0100 Subject: MemoryError, can I use more? In-Reply-To: References: <7to2vmF2kvU1@mid.uni-berlin.de> Message-ID: <7treq9FrsnU1@mid.uni-berlin.de> Am 14.02.10 12:28, schrieb Laszlo Nagy: > 2010.02.13. 17:40 keltez?ssel, Diez B. Roggisch ?rta: >> Am 13.02.10 17:18, schrieb Anssi Saari: >>> Nobody writes: >>> >>>> A single process can't use much more than 2GiB of RAM without a >>>> 64-bit CPU >>>> and OS. >>> >>> That's not really true. Even Windows XP has the /3GB boot option to >>> allow 3 GiB per process. On PCs, free operating systems and server >>> Windows can use PAE to give access to full 4 GB per process. >> >> No, PAE can be used to access much more memory than 4GB - albeit >> through paging. AFAIK up to 2^36 Bytes. > PAE is for the kernel. Yes, you can use much more memory with 32 bit > kernel + PAE. But the ~3G per 32bit process limit still applies. It is > because the PAE extension allows the kernel to distribute the same > virtual address ranges between different processes, but map them to > different physical memory addresses. However, the process that was > compiled and is running in 32 bit mode, cannot access more than ~3GB > simply because it is not able to address more memory locations with 32 > bit addresses. (minus ~1G is because it needs virtual addresses for I/O > devices as well, and those addresses cannot be mapped to physical memory). No. It can access more, through paging, similar like mmap. Specialized software like databases do that to keep large data in memory. And this has nothing to do with compilation. Of course this doesn't help for python, at least not for python-objects, as these need a flat memory model. But it's not true that only the kernels benefit from the PAE. Diez From ethan at stoneleaf.us Sun Feb 14 18:41:59 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 14 Feb 2010 15:41:59 -0800 Subject: Modifying Class Object In-Reply-To: <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> Message-ID: <4B788A47.1040609@stoneleaf.us> Steve Howell wrote: > On Feb 14, 7:11 am, Steven D'Aprano cybersource.com.au> wrote: > >>On Sat, 13 Feb 2010 23:45:47 -0800, Steve Howell wrote: >> >>>The term "pointer" is very abstract. Please give me a concrete >>>definition of a pointer. >> >>A programming language data type whose value directly specifies (or >>"points to") another value which is stored elsewhere in the computer >>memory. >> >>I quote from Wikipedia: >> >>http://en.wikipedia.org/wiki/Pointer_(computing) >> >> [quote] >> A pointer is a simple, less abstracted implementation of the >> more abstracted reference data type >> [end quote] >> >>And later: >> >> [quote] >> While "pointer" has been used to refer to references in >> general, it more properly applies to data structures whose >> interface explicitly allows the pointer to be manipulated >> (arithmetically via pointer arithmetic) as a memory >> address... >> [end quote] >> >>And again: >> >> [quote] >> A memory pointer (or just pointer) is a primitive, the value >> of which is intended to be used as a memory address; it is said >> that a pointer points to a memory address. It is also said that >> a pointer points to a datum [in memory] when the pointer's value >> is the datum's memory address. >> >> More generally, a pointer is a kind of reference, and it is said >> that a pointer references a datum stored somewhere in memory; to >> obtain that datum is to dereference the pointer. The feature that >> separates pointers from other kinds of reference is that a >> pointer's value is meant to be interpreted as a memory address, >> which is a rather 'low-level' concept. >> [end quote] >> >> >>>A curly brace is one of these: { } >> >>>Pretty concrete, I hope. >> >>But { and } are glyphs in some typeface. Chances are that what you see, >>and what I see, are quite different, and whatever pixels we see, the >>compiler sees something radically different: two abstract characters >>implemented in some concrete fashion, but that concrete fashion is a mere >>implementation detail. They could be implemented as bytes x7b and x7d, or >>as four-byte sequences x0000007b and x0000007d for UTF-32, or who knows >>what in some other system. So the *concrete* representation of the curly >>brace varies according to the system. >> >>From that, it's not a difficult leap to say that Pascal's BEGIN and END >>key words are mere alternate spellings of the abstract "open curly brace" >>and "close curly brace" with different concrete representations, and from >>that it's a small step to say that the INDENT and DEDENT tokens seen by >>the Python compiler (but absent from Python source code!) are too. >> > > > Thanks. It's a useful analogy; I think I understand your point > better. I've been bouncing around between Python and Javascript a lot > lately, so your analogy resonates with me. There are many times when > I find myself simply respelling things like begin/end, and those > respellings to me almost make me think of Python and Javascript as > different dialects of an underlying language. Of course, there are > other places where the languages differ more substantively, too. > > Going back to pointers vs. references, I think the key distinction > being made is that pointers allow specific memory manipulation, > although I think even there you're really just dealing with > abstractions. The address 0x78F394D2 is a little bit closer to the > machine than, say, the 42nd element of a Python list, but they are > both just abstractions on top of underlying machines, whether the > machines are virtual, electronic circuits, vacuum tubes, whatever. > You can add 6 to 42 and get the 48th object, but its Python's > convention not to call the 48th object a memory address or expose a > reference to it as a pointer. If I want to pass along the reference > to the 48th element of a list as the slot to be updated (i.e. with the > intention to actually mutate the list itself), then I need a tuple > like (lst, 48). > I think that's the key right there -- if 48 was really a pointer, you wouldn't need to pass lst in as 48 would in fact be the memory address of the object you wanted to manipulate. ~Ethan~ From m.echavarriagregory at umiami.edu Sun Feb 14 19:19:07 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Sun, 14 Feb 2010 19:19:07 -0500 Subject: FW: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E056@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu>, <6546CE32-E9EA-4E33-9C7B-8A9808A4A083@gmail.com>, <2E95F75EDC25D54999387A1E2E6EF62755EEF0E056@MBX02.cgcent.miami.edu> Message-ID: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E057@MBX02.cgcent.miami.edu> I use the physical and kernel memory boxes in the windows task manager under the performance tab... in that way I can see the exact RAM that just OS and idle processes occupy before I run my app, and then also the limit at which my app pushes the memory... M. Angelica Echavarria-Gregory, M.Sc., E.I. Ph.D Candidate University of Miami Phone 305 284-3611 ________________________________________ From: ssteinerX at gmail.com [ssteinerx at gmail.com] Sent: Friday, February 12, 2010 7:58 PM To: Echavarria Gregory, Maria Angelica Cc: python-list at python.org Subject: Re: MemoryError, can I use more? On Feb 12, 2010, at 7:21 PM, Echavarria Gregory, Maria Angelica wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... How are you determining that it has occupied "exactly only 2.2GB?" S From m.echavarriagregory at umiami.edu Sun Feb 14 19:20:44 2010 From: m.echavarriagregory at umiami.edu (Echavarria Gregory, Maria Angelica) Date: Sun, 14 Feb 2010 19:20:44 -0500 Subject: FW: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu>, , <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> Message-ID: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> Dear Chris, One of the machines I tested my app in is 64 bit and happened the same. The RAM consumed by the OS and other processes is already included in the 2.2 I'm telling... my app enters to work when the RAM is already consumed in ~600 MB in the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that it started a little bit higher because it has windows 7... so should I understand that there is nothing I can do for my app to use up more RAM? Thanks for your time and answer, Angelica. M. Angelica Echavarria-Gregory, M.Sc., E.I. Ph.D Candidate University of Miami Phone 305 284-3611 ________________________________ From: Chris Kaynor [ckaynor at zindagigames.com] Sent: Friday, February 12, 2010 7:44 PM To: Echavarria Gregory, Maria Angelica Cc: python-list at python.org Subject: Re: MemoryError, can I use more? A 32 bit app can only use 4 GB of memory itself (regardless of the amount of system ram), the OS claims some of this for the system, dlls occupy some of it, etc. As such, the app can only really use a smaller subset (generally between 2 to 3 GB, depending upon the app and the OS). Chris On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica > wrote: Dear group: I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... Thanks, Angelica. -- http://mail.python.org/mailman/listinfo/python-list From alfps at start.no Sun Feb 14 19:41:10 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 01:41:10 +0100 Subject: Modifying Class Object In-Reply-To: References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> Message-ID: * Ethan Furman: > Steve Howell wrote: >> >> Going back to pointers vs. references, I think the key distinction >> being made is that pointers allow specific memory manipulation, >> although I think even there you're really just dealing with >> abstractions. The address 0x78F394D2 is a little bit closer to the >> machine than, say, the 42nd element of a Python list, but they are >> both just abstractions on top of underlying machines, whether the >> machines are virtual, electronic circuits, vacuum tubes, whatever. >> You can add 6 to 42 and get the 48th object, but its Python's >> convention not to call the 48th object a memory address or expose a >> reference to it as a pointer. If I want to pass along the reference >> to the 48th element of a list as the slot to be updated (i.e. with the >> intention to actually mutate the list itself), then I need a tuple >> like (lst, 48). >> > > I think that's the key right there -- if 48 was really a pointer, you > wouldn't need to pass lst in as 48 would in fact be the memory address > of the object you wanted to manipulate. The generalization is known as a "based pointer". Except where it's a fundamental abstraction in a programming language, where it might be called anything. For example, in C++ some so called "member pointers" are logically based pointers. They have pointer syntax (as do C++ iterators, which are not necessarily pointers), but member pointers are not pointers in the C++ standard's sense; in particular, dereferencing a C++ member pointer yields a typeless entity, which is not the case for a normal pointer, although that standard confusingly calls also member pointers pointers in some places, and in other places uses the pointer term only about basic pointers. So, delving into the details of that terminology means traveling into a pretty chaotic territory. But on the other hand, going for the more abstract it gets cleaner and simpler. The Wikipedia article is about in the middle somewhere. It is perhaps not confusing that it is confusing to many. :-) Cheers & hth., - Alf From tgrav at mac.com Sun Feb 14 20:03:26 2010 From: tgrav at mac.com (Tommy Grav) Date: Sun, 14 Feb 2010 20:03:26 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> Message-ID: <5664AF57-8837-4012-ABB4-B9DAA65B0A2F@mac.com> On Feb 14, 2010, at 7:20 PM, Echavarria Gregory, Maria Angelica wrote: > > Dear Chris, > > One of the machines I tested my app in is 64 bit and happened the same. The RAM consumed by the OS and other processes is already included in the 2.2 I'm telling... my app enters to work when the RAM is already consumed in ~600 MB in the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that it started a little bit higher because it has windows 7... so should I understand that there is nothing I can do for my app to use up more RAM? It is not just the machine. If your python is compiled as 32bit then it will be limited to 2GB. To use more you have to use a 64 bit python on a 64 bit machine. Tommy -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Feb 14 21:28:16 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 14 Feb 2010 20:28:16 -0600 Subject: new python install In-Reply-To: <4badnYd5OJHA4eXWnZ2dnUVZ_oidnZ2d@insightbb.com> References: <4badnYd5OJHA4eXWnZ2dnUVZ_oidnZ2d@insightbb.com> Message-ID: <4B78B140.9020804@tim.thechases.com> monkeys paw wrote: > Upon invoking python, it hangs > until Ctrl^C is typed, and then the > >>> interactive shell begins. > > Like so: > > joemoney% python > Python 2.4.6 (#1, Dec 13 2009, 23:45:11) [C] on sunos5 > Type "help", "copyright", "credits" or "license" for more information. > # Hangs ^^^ at this point until ^C is typed > ^C > > >>> > > I've seen this in other new installs and wondered if there is > a common problem that would cause this? It's on a sun os box Though I've never seen such live, perhaps you have some sort of site-wide or user-specific config file such as ~/.pythonrc.py or a site-wide site.py file. You can read up a bit at http://docs.python.org/library/site.html http://docs.python.org/library/user.html I believe the way to test this is to start Python with either the -s or -S option (or both) to disable looking for user or site modules. Also check if you have some crazy value set for $PYTHONSTARTUP. http://docs.python.org/using/cmdline.html#cmdoption-S My guess is that something in one of these places is triggering the hang until you kill that with a ^C after which you get the requested prompt. Hope this helps, -tkc From davea at ieee.org Sun Feb 14 22:16:51 2010 From: davea at ieee.org (Dave Angel) Date: Sun, 14 Feb 2010 22:16:51 -0500 Subject: MemoryError, can I use more? In-Reply-To: <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu>, , <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> Message-ID: <4B78BCA3.4070801@ieee.org> Echavarria Gregory, Maria Angelica wrote: > Dear Chris, > > One of the machines I tested my app in is 64 bit and happened the same. The RAM consumed by the OS and other processes is already included in the 2.2 I'm telling... my app enters to work when the RAM is already consumed in ~600 MB in the 3- 32 bit machines ... in the 64 bit machine was exactly the same only that it started a little bit higher because it has windows 7... so should I understand that there is nothing I can do for my app to use up more RAM? > > Thanks for your time and answer, > Angelica. > > > M. Angelica Echavarria-Gregory, M.Sc., E.I. > Ph.D Candidate > University of Miami > Phone 305 284-3611 > > ________________________________ > From: Chris Kaynor [ckaynor at zindagigames.com] > Sent: Friday, February 12, 2010 7:44 PM > To: Echavarria Gregory, Maria Angelica > Cc: python-list at python.org > Subject: Re: MemoryError, can I use more? > > A 32 bit app can only use 4 GB of memory itself (regardless of the amount of system ram), the OS claims some of this for the system, dlls occupy some of it, etc. As such, the app can only really use a smaller subset (generally between 2 to 3 GB, depending upon the app and the OS). > > Chris > > > On Fri, Feb 12, 2010 at 4:21 PM, Echavarria Gregory, Maria Angelica > wrote: > Dear group: > > I am developing a program using Python 2.5.4 in windows 32 OS. The amount of data it works with is huge. I have managed to keep memory footprint low, but have found that, independent of the physical RAM of the machine, python always gives the MemoryError message when it has occupied exactly only 2.2 GB. I have tested this in 4 different machines, all with memory of 3 to 4 GB... I'm amazed. > > Could any of you please help me to figure out how to change that limit? I typed help(MemoryError) and it is a class itself, but that help told me nothing I can use... > > Thanks, > Angelica. > -- > http://mail.python.org/mailman/listinfo/python-list > > > There are three different limits at play here. Since you're still not saying how you're "measuring" usage, we've all been guessing just which one you're hitting. There's physical RAM, virtual address space, and swappable space (swapfile on disk). Each reaches some limit in different ways. And there are probably a dozen different ways to measure "memory use," that get a dozen different answers. If you say which one you're using, that gives "exactly 2.2 GB," maybe someone will be familiar with that particular approach, and its meaning. DaveA From tgrav at mac.com Sun Feb 14 22:39:13 2010 From: tgrav at mac.com (Tommy Grav) Date: Sun, 14 Feb 2010 22:39:13 -0500 Subject: MemoryError, can I use more? In-Reply-To: <4B78BCA3.4070801@ieee.org> References: <2E95F75EDC25D54999387A1E2E6EF6274378DA2BA0@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E055@MBX02.cgcent.miami.edu> <2E95F75EDC25D54999387A1E2E6EF62755EEF0E058@MBX02.cgcent.miami.edu> <4B78BCA3.4070801@ieee.org> Message-ID: <5FB189C5-544D-4ADF-975C-1F32776C2DB5@mac.com> On Feb 14, 2010, at 10:16 PM, Dave Angel wrote: > There are three different limits at play here. Since you're still not saying how you're "measuring" usage, we've all been guessing just which one you're hitting. There's physical RAM, virtual address space, and swappable space (swapfile on disk). Each reaches some limit in different ways. > > And there are probably a dozen different ways to measure "memory use," that get a dozen different answers. If you say which one you're using, that gives "exactly 2.2 GB," maybe someone will be familiar with that particular approach, and its meaning. I ran into the same problem on Mac OS X and investigated it. My problem was that the program reached a memory error after using 2.2GB of memory. Now what caused it specifically I am less sure of, but switching to a 64bit python on a 64bit OS (snow leopard) means that I now frequently move past this boundary (when I have enough memory of course :) Tommy From chiranjeevi.muttoju at gmail.com Mon Feb 15 03:50:33 2010 From: chiranjeevi.muttoju at gmail.com (chiranjeevi muttoju) Date: Mon, 15 Feb 2010 00:50:33 -0800 (PST) Subject: hi can any one please help me.. Message-ID: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> Hi, when i'm installing the pytc(python wrapper for tokyo cabinet.) i'm getting the fallowing error.. i'm getting this error for python2.6 only.. for python 2.4 its working fine.. --------------------------------------------- running install running build running build_ext building 'pytc' extension gcc -pthread -shared build/temp.linux-x86_64-2.6/pytc.o -L/usr/local/ lib -L. -ltokyocabinet -lpython2.6 -o build/lib.linux-x86_64-2.6/ pytc.so /usr/bin/ld: cannot find -lpython2.6 collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 --------------------------------------------- What is that error. if any body know please help me.. thank you. From alfps at start.no Mon Feb 15 04:11:18 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 10:11:18 +0100 Subject: hi can any one please help me.. In-Reply-To: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> References: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> Message-ID: * chiranjeevi muttoju: > Hi, > when i'm installing the pytc(python wrapper for tokyo cabinet.) i'm > getting the fallowing error.. i'm getting this error for python2.6 > only.. for python 2.4 its working fine.. > --------------------------------------------- > running install > running build > running build_ext > building 'pytc' extension > gcc -pthread -shared build/temp.linux-x86_64-2.6/pytc.o -L/usr/local/ > lib -L. -ltokyocabinet -lpython2.6 -o build/lib.linux-x86_64-2.6/ > pytc.so > /usr/bin/ld: cannot find -lpython2.6 > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > > --------------------------------------------- > > What is that error. if any body know please help me.. thank you. It means the compiler can't find the python2.6 library; it's not in any of the directories where gcc searches for libraries. You can specify (additional) directories where gcc should search for libraries via the LIBRARY_PATH environment variable. At least according to my MinGW documentation for Windows, but I assume that it's the same in Linux. Cheers & hth., - Alf From steve at lonetwin.net Mon Feb 15 04:12:53 2010 From: steve at lonetwin.net (steve) Date: Mon, 15 Feb 2010 14:42:53 +0530 Subject: hi can any one please help me.. References: <997acf4f-cf71-4709-bb7a-d6ab68d4ec0f@e19g2000prn.googlegroups.com> Message-ID: Hello, On 02/15/2010 02:20 PM, chiranjeevi muttoju wrote: > Hi, > when i'm installing the pytc(python wrapper for tokyo cabinet.) i'm > getting the fallowing error.. i'm getting this error for python2.6 > only.. for python 2.4 its working fine.. > --------------------------------------------- > running install > running build > running build_ext > building 'pytc' extension > gcc -pthread -shared build/temp.linux-x86_64-2.6/pytc.o -L/usr/local/ > lib -L. -ltokyocabinet -lpython2.6 -o build/lib.linux-x86_64-2.6/ > pytc.so > /usr/bin/ld: cannot find -lpython2.6 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You need to install the python development libraries. For example if you are doing this on a Fedora or Red Hat Enterprise Linux system, execute the command: $ yum install python-devel ...to install the necessary libraries. cheers, - steve From peloko45 at gmail.com Mon Feb 15 04:23:52 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 15 Feb 2010 01:23:52 -0800 (PST) Subject: Printing with raw_input Message-ID: Does `raw_input` uses internally `sys.stdout.write`? From __peter__ at web.de Mon Feb 15 05:11:20 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 11:11:20 +0100 Subject: Printing with raw_input References: Message-ID: Joan Miller wrote: > Does `raw_input` uses internally `sys.stdout.write`? You can test this yourself without reading the C source: 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. >>> import sys >>> class A: ... def write(self, s): ... sys.__stdout__.write(s.upper()) ... >>> sys.stdout = A() >>> print "yadda" YADDA >>> raw_input("foo") FOObar 'BAR' Peter From katrinewhiteson at gmail.com Mon Feb 15 05:32:36 2010 From: katrinewhiteson at gmail.com (katrine) Date: Mon, 15 Feb 2010 02:32:36 -0800 (PST) Subject: trouble installing matplotlib - syslibroot: multiply specified Message-ID: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> Hi, Hope you guys don't mind a question about building matplotlib from a biologist who wants to learn how to use python. I am trying to install matplotlib on my mac with OS X 10.4.11, using python 2.6.4 and Xcode 2.2.1. I have had a few fights with freetype and Tkinter, and I think I've got those worked out. I have configured and installed numpy, freetype, zlib, and libpng. But I am still getting an error about multiply specified syslibroot - does this make sense to anyone? Maybe I need to change the PATH somehow? Or maybe Xcode is not installed properly? (I am using the make.osx provided with matplotlib, and I am including the top of the file as I am running it here: # build mpl into a local install dir with PREFIX=/usr/local MPLVERSION=0.99.1.1 PYVERSION=2.6 PYTHON=python${PYVERSION} ZLIBVERSION=1.2.3 PNGVERSION=1.2.33 FREETYPEVERSION=2.3.7 MACOSX_DEPLOYMENT_TARGET=10.4 ## You shouldn't need to configure past this point CFLAGS="-arch i386 -arch ppc -I${PREFIX}/include -isysroot /Developer/ SDKs/MacOSX10.4u.sdk" LDFLAGS="-arch i386 -arch ppc -L${PREFIX}/lib -syslibroot,/Developer/ SDKs/MacOSX10.4u.sdk" ---------------------- ****************** ---------------------- Now here is what happens when I try to make the make.osx: katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ make -f make.osx mpl_build export MACOSX_DEPLOYMENT_TARGET=10.4 &&\ export CFLAGS="-arch i386 -arch ppc -I/usr/local/include -I/usr/local/ include/freetype2 -isysroot /Developer/SDKs/MacOSX10.4u.sdk" &&\ export LDFLAGS="-arch i386 -arch ppc -L/usr/local/lib -syslibroot,/ Developer/SDKs/MacOSX10.4u.sdk" &&\ python2.6 setup.py build ============================================================================ BUILDING MATPLOTLIB matplotlib: 0.99.1.1 python: 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) [GCC 4.0.1 (Apple Inc. build 5493)] platform: darwin REQUIRED DEPENDENCIES numpy: 1.3.0 freetype2: found, but unknown version (no pkg-config) * WARNING: Could not find 'freetype2' headers in any * of '.', './freetype2'. OPTIONAL BACKEND DEPENDENCIES libpng: found, but unknown version (no pkg-config) * Could not find 'libpng' headers in any of '.' Tkinter: Tkinter: 73770, Tk: 8.4, Tcl: 8.4 wxPython: no * wxPython not found Gtk+: no * Building for Gtk+ requires pygtk; you must be able * to "import gtk" in your build/install environment Mac OS X native: yes Qt: no Qt4: no Cairo: no OPTIONAL DATE/TIMEZONE DEPENDENCIES datetime: present, version unknown dateutil: matplotlib will provide pytz: matplotlib will provide adding pytz OPTIONAL USETEX DEPENDENCIES dvipng: no ghostscript: /bin/sh: line 1: gs: command not found latex: no [Edit setup.cfg to suppress the above messages] ============================================================================ pymods ['pylab'] packages ['matplotlib', 'matplotlib.backends', 'matplotlib.projections', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid', 'matplotlib.sphinxext', 'matplotlib.numerix', 'matplotlib.numerix.mlab', 'matplotlib.numerix.ma', 'matplotlib.numerix.linear_algebra', 'matplotlib.numerix.random_array', 'matplotlib.numerix.fft', 'matplotlib.delaunay', 'pytz', 'dateutil', 'dateutil/zoneinfo'] running build running build_py copying lib/matplotlib/mpl-data/matplotlibrc -> build/lib.macosx-10.4- fat-2.6/matplotlib/mpl-data copying lib/matplotlib/mpl-data/matplotlib.conf -> build/ lib.macosx-10.4-fat-2.6/matplotlib/mpl-data running build_ext building 'matplotlib.ft2font' extension c++ -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g - bundle -undefined dynamic_lookup -arch i386 -arch ppc -L/usr/local/lib -syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc -I/ usr/local/include -I/usr/local/include/freetype2 -isysroot /Developer/ SDKs/MacOSX10.4u.sdk build/temp.macosx-10.4-fat-2.6/src/ft2font.o build/temp.macosx-10.4-fat-2.6/src/mplutils.o build/temp.macosx-10.4- fat-2.6/CXX/cxx_extensions.o build/temp.macosx-10.4-fat-2.6/CXX/ cxxsupport.o build/temp.macosx-10.4-fat-2.6/CXX/ IndirectPythonInterface.o build/temp.macosx-10.4-fat-2.6/CXX/ cxxextensions.o -lfreetype -lz -lstdc++ -lm -o build/lib.macosx-10.4- fat-2.6/matplotlib/ft2font.so powerpc-apple-darwin8-g++-4.0.1: unrecognized option '-syslibroot,/ Developer/SDKs/MacOSX10.4u.sdk' i686-apple-darwin8-g++-4.0.1: unrecognized option '-syslibroot,/ Developer/SDKs/MacOSX10.4u.sdk' //usr/bin/ld: -usr/syslibroot: multiply specified bincollect2: /ld: -syslibroot: multiply specified ld returned 1 exit statuscollect2: ld returned 1 exit status lipo: can't open input file: /var/tmp//ccym1XU1.out (No such file or directory) error: command 'c++' failed with exit status 1 make: *** [mpl_build] Error 1 katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ gcc -V gcc: argument to `-V' is missing katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ which gcc /usr/bin/gcc katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ c f yj ny -bash: c: command not found katrine-whitesons-computer:/Applications/Q/matplotlib-0.99.1.1 katrinewhiteson$ k/l -bash: k/l: No such file or directory From alfps at start.no Mon Feb 15 06:20:10 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 12:20:10 +0100 Subject: trouble installing matplotlib - syslibroot: multiply specified In-Reply-To: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> References: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> Message-ID: * katrine: > > Hope you guys don't mind a question about building matplotlib from a > biologist who wants to learn how to use python. > > I am trying to install matplotlib on my mac with OS X 10.4.11, using > python 2.6.4 and Xcode 2.2.1. I have had a few fights with freetype > and Tkinter, and I think I've got those worked out. I have configured > and installed numpy, freetype, zlib, and libpng. But I am still > getting an error about multiply specified syslibroot - does this make > sense to anyone? Don't know if this will help, but I just googled "syslibroot", and it coughed up the following discussion: Quoting from that thread: "Try not setting LDFLAGS. Passing -isysroot to gcc might cause it to pass -isyslibroot to the linker if you're using gcc to link." Cheers, - Alf From hjebbers at gmail.com Mon Feb 15 06:39:57 2010 From: hjebbers at gmail.com (hjebbers) Date: Mon, 15 Feb 2010 03:39:57 -0800 (PST) Subject: python crash on windows but not on linux References: <9f2aa3f6-65a2-4921-b60e-350ae2b0a790@f8g2000yqn.googlegroups.com> <94e7fdd8-2021-4bee-9d16-228bc9224f88@g11g2000yqe.googlegroups.com> <603f57e4-2c7d-4007-8ecf-3d19295b0e3c@r33g2000yqb.googlegroups.com> <54238800-dfb5-4c4a-af21-109b7a68dc6b@f8g2000yqn.googlegroups.com> Message-ID: <9d348145-1dec-42cb-a4c3-408c9833a1bc@a5g2000yqi.googlegroups.com> On 13 feb, 13:48, Dave Angel wrote: > hjebbers wrote: > > On Feb 13, 10:25 am, Dennis Lee Bieber wrote: > > >> On Fri, 12 Feb 2010 09:21:07 -0800 (PST), hjebbers > >> declaimed the following in gmane.comp.python.general: > > >>> What strikes me is: > >>> 1. the crash on windows, but linux works OK (same test sets) > >>> 2. the linux box has 750Mb RAM, the windows box has 1.5Gb (twice as > >>> much). > > >> ? ? ? ? Which on its own does not mean much. > > >> ? ? ? ? Windows in a normal installation only grants 2GB address space to > >> user code, reserving the other 2GB space for the OS shared libraries. If > >> your program attempts to allocate over that, it will fail. That the > >> Windows box has twice the physical memory only means it doesn't resort > >> to page swapping as soon. > > >> ? ? ? ? There is a boot parameter switch that toggles Windows into a 3GB > >> user/1GB OS mode -- > > > hey, that would be great!! on my 1,5G mahcine ;-) > > >> it is mainly meant for server machines where there > >> won't be many disjoint OS libraries loaded, but the server applications > >> need lots of data space. > > >> ? ? ? ? What split does the Linux OS use? If it give 3GB to user space, > >> while you'd start to page swap much soon, you'd also have 50% more > >> virtual memory that can be allocated than under Windows. > >> -- > >> ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > >> ? ? ? ? wlfr... at ix.netcom.com ? ? HTTP://wlfraed.home.netcom.com/ > > > I will check this.....any advice on how to check this? > > > henk-jan > > As I posted in recent thread on Tutor, > > But the one you might want is a boot.ini option that tells the OS to > only reserve 1gb for itself, and leave 3gb for user space. ?But there > are tradeoffs, including the need to modify an application's executable > to take advantage of it. ?And the whole system may run substantially > slower, even when your're extended app isn't running. ?See links: > ?http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx > > http://blogs.technet.com/askperf/archive/2007/03/23/memory-management... > > DaveA Yes, you are right, i also would need to modify the executable. the reason why I posted on this list was the hard crash of python - which python really should not do I think. AFAICS there is no 'bug' in my edi translator (runs OK on linux) - but it uses far to much memory..... For me, I am going to bring back the memory footprint of my edi translator. Which should be fairly easy to do. kind regards, henk-jan From peloko45 at gmail.com Mon Feb 15 06:40:11 2010 From: peloko45 at gmail.com (Joan Miller) Date: Mon, 15 Feb 2010 03:40:11 -0800 (PST) Subject: Printing with raw_input References: Message-ID: On 15 feb, 10:11, Peter Otten <__pete... at web.de> wrote: > Joan Miller wrote: > > Does `raw_input` uses internally `sys.stdout.write`? > > You can test this yourself without reading the C source: > > 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.>>> import sys > >>> class A: > > ... ? ? def write(self, s): > ... ? ? ? ? ? ? sys.__stdout__.write(s.upper()) > ...>>> sys.stdout = A() > >>> print "yadda" > YADDA > >>> raw_input("foo") > > FOObar > 'BAR' > > Peter It was to display the output inside a GUI app. overriding `sys.stdout`. And as `print` also uses internally `sys.stdout.write` then can be used `print` the shell script and get the output too in the GUI, cann't it? From __peter__ at web.de Mon Feb 15 07:05:58 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 13:05:58 +0100 Subject: Printing with raw_input References: Message-ID: Joan Miller wrote: >> > Does `raw_input` uses internally `sys.stdout.write`? > It was to display the output inside a GUI app. overriding > `sys.stdout`. And as `print` also uses internally `sys.stdout.write` > then can be used `print` the shell script and get the output too in > the GUI, cann't it? It should be easy to collect data written with print and show it in a gui, but I can't see how you would integrate raw_input() into a gui app. As to shell scripts, you can invoke them via subprocess, or, if the script needs user interaction, via pexpect. Peter From chyavana at gmail.com Mon Feb 15 07:35:32 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Mon, 15 Feb 2010 20:35:32 +0800 Subject: Executing a command from within python using the subprocess module Message-ID: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Dear Folks, I want to execute a command from within python using the subprocess module. Coming from a Perl background, I thought I could use variable interpolation in strings, but found that this is neither supported nor the Python way. Accordingly, I am a little at sea about how to accomplish it. I have stated what I am trying to do in the minimal example below: --- import subprocess width = 5 height = 30 colors = ['#abcdef]', '#456789'] filename = "/tmp/image.png" # I want to get the equivalent of variable interpolation in Perl # so that the command # # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png # # is derived from the variables above # and executed by subprocess.call() or subprocess.Popen() # from within Python # # Note that the command "convert" is from the ImageMagick suite # It exists and is executable by the shell; # the remaining values are arguments. # The command has been confirmed to execute correctly. --- Thanks in advance. Chandra From alfps at start.no Mon Feb 15 07:44:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 15 Feb 2010 13:44:32 +0100 Subject: Executing a command from within python using the subprocess module In-Reply-To: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: * R (Chandra) Chandrasekhar: > > width = 5 > height = 30 > colors = ['#abcdef]', '#456789'] > filename = "/tmp/image.png" > > # I want to get the equivalent of variable interpolation in Perl > # so that the command > # > # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png > # > # is derived from the variables above Assuming that the extra right square bracket in 'colors' is a typo, here's one way: s = "convert -size {w}x{h} gradient:{g1}-{g2} {f}".format( w = width, h = height, g1 = colors[0], g2 = colors[1], f = filename ) Cheers & hth., - ALf From __peter__ at web.de Mon Feb 15 08:02:42 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 14:02:42 +0100 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: R (Chandra) Chandrasekhar wrote: > I want to execute a command from within python using the subprocess > module. > > Coming from a Perl background, I thought I could use variable > interpolation in strings, but found that this is neither supported nor > the Python way. Accordingly, I am a little at sea about how to > accomplish it. import subprocess def convert(width=5, height=30, colors=['#abcdef', '#456789'], filename="tmp/image with space in its name.png"): lookup = locals() assert all("\n" not in str(s) for s in lookup.values()) subprocess.call("""\ convert -size {width}x{height} gradient:{colors[0]}-{colors[1]} {filename}""".format(**lookup).splitlines()) convert() Peter From anand.shashwat at gmail.com Mon Feb 15 08:11:32 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 15 Feb 2010 18:41:32 +0530 Subject: Printing with raw_input In-Reply-To: References: Message-ID: raw_input uses sys.stderr I guess ? On Mon, Feb 15, 2010 at 5:35 PM, Peter Otten <__peter__ at web.de> wrote: > Joan Miller wrote: > > >> > Does `raw_input` uses internally `sys.stdout.write`? > > > It was to display the output inside a GUI app. overriding > > `sys.stdout`. And as `print` also uses internally `sys.stdout.write` > > then can be used `print` the shell script and get the output too in > > the GUI, cann't it? > > It should be easy to collect data written with print and show it in a gui, > but I can't see how you would integrate raw_input() into a gui app. > > As to shell scripts, you can invoke them via subprocess, or, if the script > needs user interaction, via pexpect. > > Peter > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From katrinewhiteson at gmail.com Mon Feb 15 08:56:37 2010 From: katrinewhiteson at gmail.com (katrine) Date: Mon, 15 Feb 2010 05:56:37 -0800 (PST) Subject: trouble installing matplotlib - syslibroot: multiply specified References: <13c961f8-ccbe-484d-b5ee-f620ef276f32@y33g2000yqb.googlegroups.com> Message-ID: On Feb 15, 12:20 pm, "Alf P. Steinbach" wrote: > * katrine: > > > > > Hope you guys don't mind a question about building matplotlib from a > > biologist who wants to learn how to use python. > > > I am trying to install matplotlib on my mac with OS X 10.4.11, using > > python 2.6.4 and Xcode 2.2.1. I have had a few fights with freetype > > and Tkinter, and I think I've got those worked out. I have configured > > and installed numpy, freetype, zlib, and libpng. But I am still > > getting an error about multiply specified syslibroot - does this make > > sense to anyone? > > Don't know if this will help, but I just googled "syslibroot", and it coughed up > the following discussion: > > > > Quoting from that thread: "Try not setting LDFLAGS. Passing -isysroot to gcc > might cause it to pass -isyslibroot to the linker if you're using gcc to link." > > Cheers, > > - Alf thanks! I managed to install an egg with easy_install, seems to work, FINALLY! thanks for your help, Katrine From jeanmichel at sequans.com Mon Feb 15 09:03:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 15:03:40 +0100 Subject: Replace various regex In-Reply-To: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Message-ID: <4B79543C.5070709@sequans.com> Martin wrote: > Hi, > > I am trying to come up with a more generic scheme to match and replace > a series of regex, which look something like this... > > 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) > 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > would then like to be able to replace one or all of the corresponding > numbers on the line. So far I have a rather unsatisfactory solution, > any suggestions would be appreciated... > > The file read in is an ascii file. > > f = open(fname, 'r') > s = f.read() > > if CANHT: > s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! > canht_ft", CANHT, s) > > where CANHT might be > > CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' > > But this involves me passing the entire string. > > Thanks. > > Martin > I remove all lines containing things like 9*0.0 in your file, cause I don't know what they mean and how to handle them. These are not numbers. import re replace = { 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 } testBuffer = """ 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) 0.46 ! snow_grnd 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) """ outputBuffer = '' for line in testBuffer.split('\n'): for key, (index, repl) in replace.items(): if key in line: parameters = { 'n' : '[\d\.]+', # given you example you have to change this one, I don't know what means 9*0.0 in your file 'index' : index - 1, } # the following pattern will silently match any digit before the th digit is found, and use a capturing parenthesis for the last pattern = '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % parameters # regexp are sometimes a nightmare to read line = re.sub(pattern, r'\1 '+repl+r'\3' , line) break outputBuffer += line +'\n' print outputBuffer From starglider.dev at gmail.com Mon Feb 15 09:10:53 2010 From: starglider.dev at gmail.com (starglider develop) Date: Mon, 15 Feb 2010 14:10:53 +0000 Subject: Talking with ebay using Python Message-ID: Hi, I need a way of talking with the eBay API: Made search, Ask for item status. What can it be done, and where can I get the info. Thank you in advance for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From acl at info.fundp.ac.be Mon Feb 15 09:11:37 2010 From: acl at info.fundp.ac.be (Anthony Cleve) Date: Mon, 15 Feb 2010 06:11:37 -0800 (PST) Subject: CFP - SLE'2010 Message-ID: <5d5f260a-71e2-46a1-80ee-ba6a4405bc7e@b7g2000yqd.googlegroups.com> CALL FOR PAPERS 3rd International Conference on Software Language Engineering SLE 2010 12-13 Oct 2010 -- Eindhoven, The Netherlands http://planet-sl.org/sle2010/ Co-located with the International Conference on Generative Programming and Component Engineering (GPCE'10). ------------------------------------------------------------ DATES Jun 28: Abstract submission (required) Jul 05: Paper submission (midnight Apia Samoa time) Aug 27: Author notification Sep 17: Paper submission for online proceedings Oct 12-13: SLE 2010 Dec 03: Camera-ready copy submission for post-proceedings ------------------------------------------------------------ Software language engineering is devoted to topics related to artificial languages in software engineering. The foremost mission of the International Conference on Software Language Engineering (SLE) is to encourage and organize communication between communities that traditionally have looked at soft- ware languages from different, more specialized, and yet complementary perspectives. Thus, technologies, methods, experiments and case studies from modelware, grammarware, and ontologyware serving the objectives of software languages are of particular relevance to SLE. We invite high-quality submissions to all conference tracks. Submissions must be PDF files following the Springer LNCS style and will be managed using the EasyChair submission system. Please check the conference web site for further information. New at SLE 2010 is a Doctoral Symposium that will provide a supportive yet questioning setting in which PhD students can present their work, including goals, methods, and preliminary results. The Symposium aims to provide students with useful guidance and feedback on various aspects of their research from established researchers and the other student attendees. Please forward this call to anyone who might be interested. http://planet-sl.org/sle2010/ ------------------------------------------------------------ PAPER SUBMISSION Submitted papers must be original work and must not be previously published in, currently submitted to, or currently in consideration for any journal, book, conference, or workshop. Each submitted paper will be reviewed closely by at least three members of the program committee. Accepted papers will be distributed at the conference via the online proceedings as well as published in the post-proceedings, which will appear in the Springer Lecture Notes in Computer Science (LNCS) series. Authors will have the opportunity to revise their accepted paper(s) for the pre- and post- proceedings. For an accepted paper to appear in the proceedings, at least one author must attend the event and present the work. ------------------------------------------------------------ RESEARCH PAPERS Research papers should report a substantial research contribution to SLE and/or a successful application of SLE techniques. We solicit high-quality contributions in the area of SLE ranging from theoretical and conceptual contributions to tools, techniques, and frameworks that support the aforementioned lifecycle activities. We list examples of tools, techniques, applications, and problems of interest to clarify the types of contributes that we seek: * Formalisms used in designing and specifying languages and tools that analyze such language descriptions * Language implementation techniques * Program and model transformation tools * Composition, integration, and mapping tools for managing different aspects of software languages or different manifestations of a given language * Transformations and transformation languages between languages and models * Language evolution * Approaches to elicitation, specification, or verification of requirements for software languages * Language development frameworks, methodologies, techniques, best practices, and tools for the broader language lifecycle covering phases such as analysis, testing , and documentation. * Design challenges in SLE * Applications of languages including innovative domain-specific languages or "little" languages The preceding list is not exclusive or exhaustive. Visit the conference web site for more information about the scope and topics of interest of SLE, or contact the program co-chairs with questions. Page limit: 20 ------------------------------------------------------------ SHORT PAPERS Short paper may describe interesting or thought-provoking concepts that are not yet fully developed or evaluated, make an initial contribution to challenging research issues in SLE, or discuss and analyze controversial issues in the field. Page limit: 10 ------------------------------------------------------------ TOOL DEMONSTRATION PAPERS Because of SLE's ample interest in tools, we seek papers that present software tools related to the field of SLE. These papers will accompany a tool demonstration to be given at the conference. The selection criteria include the originality of the tool, its innovative aspects, the relevance of the tool to SLE, and the maturity of the tool. Submissions may also include an appendix (that will not be published) containing additional screen-shots and discussion of the proposed demonstration. Page limit: 10 ------------------------------------------------------------ MINI-TUTORIAL PAPERS SLE is composed of various research areas, such as grammarware, modelware, language schemas, and semantic technologies. The cross product of attendees at SLE creates a situation where the contribution from one session may be difficult to understand by those not initiated to the area. To help unite the various communities of SLE 2010, we solicit mini-tutorials that provide discussion points for mapping common ideas between related and complementary research topics of SLE. A mini-tutorial submission should be between 15 and 20 pages. ------------------------------------------------------------ GENERAL CHAIR Mark van den Brand Eindhoven University of Technology, The Netherlands m.g.j.v.d.brand at tue.nl PROGRAM CO-CHAIRS Brian Malloy Clemson University, USA malloy at cs.clemson.edu Steffen Staab University of Koblenz-Landau, Germany staab at uni-koblenz.de DOCTORAL SYMPOSIUM CHAIRS Eric van Wyk University of Minnesota, USA evw at cs.umn.edu Steffen Zschaler Lancaster University, UK szschaler at acm.org ORGANIZATION COMMITTEE Anthony Cleve (Publicity Co-Chair) INRIA Lille, France Nicholas Kraft (Publicity Co-Chair) University of Alabama, USA Arjan van der Meer (Web Chair) Eindhoven University of Technology, The Netherlands Alexander Serebrenik (Finance Chair) Eindhoven University of Technology, The Netherlands PROGRAM COMMITTEE Uwe Assmann, Dresden University of Technology, Germany Colin Atkinson, University of Mannheim , Germany Sonia Bergamaschi, University of Modena and Reggio Emilia, Italy John Boyland, University of Wisconsin-Milwaukee, USA Jordi Cabot, University of Toronto, Canada Silvana Castano, University of Milan, Italy Anthony Cleve, INRIA Lille, France Michael Collard, University of Akron, USA Charles Consel, LaBRI / INRIA, France Stephen Edwards, Columbia University, USA Gregor Engels, University of Paderborn, Germany Aldo Gangemi, Semantic Technology Laboratory, Italy Chiara Ghidini, FBK-irst, Italy Jeff Gray, University of Alabama, USA Peter Haase, University of Karlsruhe, Germany Gorel Hedin, Lund University, Sweden Geert-Jan Houben, Delft University of Technology, The Netherlands Adrian Johnstone, University of London, UK Nicholas Kraft, University of Alabama, USA Ivan Kurtev, University of Twente, The Netherlands Julia Lawall, University of Copenhagen, Denmark Marjan Mernik, University of Maribor, Slovenia Pierre-Etienne Moreau, Ecole des Mines in Nancy, France Peter Mosses, Swansea University, UK Ralf M??ller, Hamburg University of Technolog, Germany Istvan Nagy, ASML, The Netherlands Daniel Oberle, SAP Research, Germany Richard Paige, University of York, UK Jeff Z. Pan, University of Aberdeen, UK Bijan Parsia, University of Manchester, UK James Power, National University of Ireland, Ireland Alexander Serebrenik, Eindhoven University of Technology, The Netherlands Fernando Silva Parreiras, University of Koblenz-Landau, Germany Anthony Sloane, Macquarie University, Australia Eleni Stroulia, University of Alberta, Canada York Sure, University of Koblenz-Landau, Germany Gabriele Taentzer, Technical University of Berlin, Germany Jurgen Vinju, CWI, The Netherlands Eelco Visser, Delft University of Technology, The Netherlands Steffen Zschaler, Lancaster University, UK From mdekauwe at gmail.com Mon Feb 15 09:13:17 2010 From: mdekauwe at gmail.com (Martin) Date: Mon, 15 Feb 2010 06:13:17 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> Message-ID: <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> On Feb 15, 2:03 pm, Jean-Michel Pichavant wrote: > Martin wrote: > > Hi, > > > I am trying to come up with a more generic scheme to match and replace > > a series of regex, which look something like this... > > > 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) > > 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) > > > Ideally match the pattern to the right of the "!" sign (e.g. lai), I > > would then like to be able to replace one or all of the corresponding > > numbers on the line. So far I have a rather unsatisfactory solution, > > any suggestions would be appreciated... > > > The file read in is an ascii file. > > > f = open(fname, 'r') > > s = f.read() > > > if CANHT: > > s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! > > canht_ft", CANHT, s) > > > where CANHT might be > > > CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' > > > But this involves me passing the entire string. > > > Thanks. > > > Martin > > I remove all lines containing things like 9*0.0 in your file, cause I > don't know what they mean and how to handle them. These are not numbers. > > import re > > replace = { > 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 > 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 > } > > testBuffer = """ > 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) > 0.46 ! snow_grnd > 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) > 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) > 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) > """ > > outputBuffer = '' > for line in testBuffer.split('\n'): > for key, (index, repl) in replace.items(): > if key in line: > parameters = { > 'n' : '[\d\.]+', # given you example you have to change > this one, I don't know what means 9*0.0 in your file > 'index' : index - 1, > } > # the following pattern will silently match any digit before > the th digit is found, and use a capturing parenthesis for the last > pattern = > '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % > parameters # regexp are sometimes a nightmare to read > line = re.sub(pattern, r'\1 '+repl+r'\3' , line) > break > outputBuffer += line +'\n' > > print outputBuffer Thanks I will take a look. I think perhaps I was having a very slow day when I posted and realised I could solve the original problem more efficiently and the problem wasn't perhaps as I first perceived. It is enough to match the tag to the right of the "!" sign and use this to adjust what lies on the left of the "!" sign. Currently I have this...if anyone thinks there is a neater solution I am happy to hear it. Many thanks. variable_tag = 'lai' variable = [200.0, 60.030, 0.060, 0.030, 0.030] # generate adjustment string variable = ",".join(["%s" % i for i in variable]) + ' ! ' + variable_tag # call func to adjust input file adjustStandardPftParams(variable, variable_tag, in_param_fname, out_param_fname) and the inside of this func looks like this def adjustStandardPftParams(self, variable, variable_tag, in_fname, out_fname): f = open(in_fname, 'r') of = open(out_fname, 'w') pattern_found = False while True: line = f.readline() if not line: break pattern = re.findall(r"!\s+"+variable_tag, line) if pattern: print 'yes' print >> of, "%s" % variable pattern_found = True if pattern_found: pattern_found = False else: of.write(line) f.close() of.close() return From jeanmichel at sequans.com Mon Feb 15 09:27:40 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 15:27:40 +0100 Subject: Replace various regex In-Reply-To: <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> Message-ID: <4B7959DC.2040202@sequans.com> Martin wrote: > On Feb 15, 2:03 pm, Jean-Michel Pichavant > wrote: > >> Martin wrote: >> >>> Hi, >>> >>> I am trying to come up with a more generic scheme to match and replace >>> a series of regex, which look something like this... >>> >>> 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) >>> 5.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) >>> >>> Ideally match the pattern to the right of the "!" sign (e.g. lai), I >>> would then like to be able to replace one or all of the corresponding >>> numbers on the line. So far I have a rather unsatisfactory solution, >>> any suggestions would be appreciated... >>> >>> The file read in is an ascii file. >>> >>> f = open(fname, 'r') >>> s = f.read() >>> >>> if CANHT: >>> s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ! >>> canht_ft", CANHT, s) >>> >>> where CANHT might be >>> >>> CANHT = '115.01,16.38,0.79,1.26,1.00 ! canht_ft' >>> >>> But this involves me passing the entire string. >>> >>> Thanks. >>> >>> Martin >>> >> I remove all lines containing things like 9*0.0 in your file, cause I >> don't know what they mean and how to handle them. These are not numbers. >> >> import re >> >> replace = { >> 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 >> 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 >> } >> >> testBuffer = """ >> 0.749, 0.743, 0.754, 0.759 ! stheta(1:sm_levels)(top to bottom) >> 0.46 ! snow_grnd >> 276.78,277.46,278.99,282.48 ! t_soil(1:sm_levels)(top to bottom) >> 19.01,16.38,0.79,1.26,1.00 ! canht_ft(1:npft) >> 200.0, 4.0, 2.0, 4.0, 1.0 ! lai(1:npft) >> """ >> >> outputBuffer = '' >> for line in testBuffer.split('\n'): >> for key, (index, repl) in replace.items(): >> if key in line: >> parameters = { >> 'n' : '[\d\.]+', # given you example you have to change >> this one, I don't know what means 9*0.0 in your file >> 'index' : index - 1, >> } >> # the following pattern will silently match any digit before >> the th digit is found, and use a capturing parenthesis for the last >> pattern = >> '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % >> parameters # regexp are sometimes a nightmare to read >> line = re.sub(pattern, r'\1 '+repl+r'\3' , line) >> break >> outputBuffer += line +'\n' >> >> print outputBuffer >> > > Thanks I will take a look. I think perhaps I was having a very slow > day when I posted and realised I could solve the original problem more > efficiently and the problem wasn't perhaps as I first perceived. It is > enough to match the tag to the right of the "!" sign and use this to > adjust what lies on the left of the "!" sign. Currently I have > this...if anyone thinks there is a neater solution I am happy to hear > it. Many thanks. > > variable_tag = 'lai' > variable = [200.0, 60.030, 0.060, 0.030, 0.030] > > # generate adjustment string > variable = ",".join(["%s" % i for i in variable]) + ' ! ' + > variable_tag > > # call func to adjust input file > adjustStandardPftParams(variable, variable_tag, in_param_fname, > out_param_fname) > > and the inside of this func looks like this > > def adjustStandardPftParams(self, variable, variable_tag, in_fname, > out_fname): > > f = open(in_fname, 'r') > of = open(out_fname, 'w') > pattern_found = False > > while True: > line = f.readline() > if not line: > break > pattern = re.findall(r"!\s+"+variable_tag, line) > if pattern: > print 'yes' > print >> of, "%s" % variable > pattern_found = True > > if pattern_found: > pattern_found = False > else: > of.write(line) > > f.close() > of.close() > > return > Are you sure a simple if variable_tag in line: # do some stuff is not enough ? People will usually prefer to write for line in open(in_fname, 'r') : instead of your ugly while loop ;-) JM From exallion.long at gmail.com Mon Feb 15 09:31:39 2010 From: exallion.long at gmail.com (Mug) Date: Mon, 15 Feb 2010 06:31:39 -0800 (PST) Subject: constructor overwrite Message-ID: hi ,i had a problem on constructor overwrite: i have something like: class obj: def __init__(self, x=100, y=None): if y is None: self.x=x else: self.y=y so i can call : objet = obj() # x=100 y=None or objet = obj(40) # x= 40 y=None but if i do : objet = obj('not cool') #x='not cool' y=None since x is not typed . i am waiting for a result: objet = obj('not cool') #x=100 y='not cool' as they do in C++ or java. is there a way to do it? thanks From arnodel at googlemail.com Mon Feb 15 09:41:53 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Feb 2010 14:41:53 +0000 Subject: constructor overwrite References: Message-ID: Mug writes: > hi ,i had a problem on constructor overwrite: > i have something like: > > class obj: > def __init__(self, x=100, y=None): > if y is None: > self.x=x > else: > self.y=y > so i can call : > objet = obj() # x=100 y=None > or > objet = obj(40) # x= 40 y=None > > but if i do : > objet = obj('not cool') #x='not cool' y=None > since x is not typed . > > i am waiting for a result: > objet = obj('not cool') #x=100 y='not cool' > as they do in C++ or java. > is there a way to do it? > thanks Your problem doesn't seem very well defined (e.g. do you ever call obj with two arguments?), but as I understand it you can do this: def __init__(self, x=100): if isinstance(x, int): self.x, self.y = x, None else: self.x, self.y = None, x HTH -- Arnaud From steve at holdenweb.com Mon Feb 15 09:58:19 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 09:58:19 -0500 Subject: constructor overwrite In-Reply-To: References: Message-ID: Mug wrote: > hi ,i had a problem on constructor overwrite: > i have something like: > > class obj: > def __init__(self, x=100, y=None): > if y is None: > self.x=x > else: > self.y=y > so i can call : > objet = obj() # x=100 y=None > or > objet = obj(40) # x= 40 y=None > > but if i do : > objet = obj('not cool') #x='not cool' y=None > since x is not typed . > > i am waiting for a result: > objet = obj('not cool') #x=100 y='not cool' > as they do in C++ or java. > is there a way to do it? > thanks You could check the type(s) of the argument(s) in your code, if you want, but Python does not support signature analysis, dynamic method dispatch or static typing. You can do object = obj("y='not cool') but I doubt this is what you want. Your post raises a couple of thier points. First, __init__ is *not* the constructor. By the time it is called creation of the new object is already complete, and __init__() (as its name suggests) merely initializes it. In Python 2's "new-style" classes, and in Python 3, construction is performed by the class's __new__() method. Secondly, it seems a little strange that you are happy to create different instances, in some of which self.y is not initialized and in others self.x is not initialized. You may have a good reason for doing this, I merely point it out as a potential cause of AttributeError exceptions. regards Steve regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 15 10:05:04 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 15 Feb 2010 16:05:04 +0100 Subject: constructor overwrite In-Reply-To: References: Message-ID: <4b79629f$0$685$426a74cc@news.free.fr> Mug a ?crit : > hi ,i had a problem on constructor overwrite: > i have something like: > > class obj: > def __init__(self, x=100, y=None): > if y is None: > self.x=x > else: > self.y=y With such an initializer, you'll have instances with an attribute 'y' and no attribute 'x', and instances with an attribute 'x' and no attribute 'y' : >>> class Obj(object): ... def __init__(self, x=100, y=None): ... if y is None: self.x = x ... else: self.y = y ... >>> objx = Obj() >>> objx.x 100 >>> objx.y Traceback (most recent call last): File "", line 1, in AttributeError: 'Obj' object has no attribute 'y' >>> objy = Obj(y='foo') >>> objy.x Traceback (most recent call last): File "", line 1, in AttributeError: 'Obj' object has no attribute 'x' >>> objy.y 'foo' >>> Are you *sure* this is what you want ? > so i can call : > objet = obj() # x=100 y=None > or > objet = obj(40) # x= 40 y=None > > but if i do : > objet = obj('not cool') #x='not cool' y=None What else would you expect ??? > since x is not typed . 'x' is a name, and names are indeed "untyped". Now the object bound to name 'x' is actually typed. > i am waiting for a result: > objet = obj('not cool') #x=100 y='not cool' > as they do in C++ or java. Python is neither C++ nor Java (nor Pascal nor Lisp nor FWIW), so trying to forcefit C++/Java idioms will at best lead you to pain and frustation. Just like trying to forcefit Python idioms in C++ or Java (or Pascal or Lisp etc....). > is there a way to do it? objet = obj(y='not cool') Now if you could explain the problem you're trying to solve instead of the solution you thought would solve it, we might eventually provide more help. From benedict.verheyen at gmail.com Mon Feb 15 10:29:05 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Mon, 15 Feb 2010 16:29:05 +0100 Subject: how to structure a directory with many scripts and shared code Message-ID: Hi, i wanted to ask how you guys structure your code. I mainly have scripts that automate small tasks. These scripts use a common set of utility code. My code is structured like this, for example: script_1.py script_2.py script_3.py tools\ |----->__init__.py |----->logutils.py |----->mailutils.py I was thinking of putting code in seperate directories because the number of scripts grows fast and i want to keep it clean. Something like this: script_1.py tools\ |----->__init__.py |----->logutils.py |----->mailutils.py database\ |----->__init__.py |----->script_2.py |----->script_3.py However, when i make a subdirectory, for example database and put a script in there, how would i import logutils or mailtutils from within the database subdirectory? This fails: from tools.logutils import logger Thanks, Benedict From python at bdurham.com Mon Feb 15 10:43:22 2010 From: python at bdurham.com (python at bdurham.com) Date: Mon, 15 Feb 2010 10:43:22 -0500 Subject: Time out a regular expression in Python 2.6.4? Message-ID: <1266248602.28792.1360069669@webmail.messagingengine.com> Is there any way to time out a regular expression in Python 2.6.4? Motiviation: Our application allows users to enter regular expressions as validation criteria. If a user enters a pathological regular expression, we would like to timeout the evaluation of this expression after a short period of time. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From chyavana at gmail.com Mon Feb 15 10:48:02 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Mon, 15 Feb 2010 23:48:02 +0800 Subject: Executing a command from within python using the subprocess module In-Reply-To: References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B796CB2.2000302@gmail.com> Peter Otten wrote: > import subprocess > > def convert(width=5, height=30, colors=['#abcdef', '#456789'], > filename="tmp/image with space in its name.png"): > lookup = locals() > assert all("\n" not in str(s) for s in lookup.values()) > subprocess.call("""\ > convert > -size > {width}x{height} > gradient:{colors[0]}-{colors[1]} > {filename}""".format(**lookup).splitlines()) > > convert() > > Peter Thank you. It works. Now I need to understand why and am able to follow what you are doing part of the way: 1. Assign default values in the function definition. 2. Store the variables existing in the local namespace in the list lookup. 3. Assert that there are no newlines in the values in lookup converted to strings. (Why? Is this because of splitlines() later on?) 4. Assemble a string (array?) for the subprocess.call argument using the format string syntax (section 8.1.3 et seq. of the Python documentation for 2.6.4). Your example works with default option of shell=False for subprocess.call(). 5. I am unable to decipher how you got to format(**lookup).splitlines()) especially the **prefix part, although I guess that splitlines() is dishing out the arguments one by one from each line in the subprocess.call argument. Any correction of (1) to (4) and an explanation of (5) would be most appreciated. All in all, your code is a magnificent example of wrapping the function within python. This is the first time I have seen something like this. Thank you very much. Chandra From jjposner at optimum.net Mon Feb 15 10:59:05 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 15 Feb 2010 10:59:05 -0500 Subject: Executing a command from within python using the subprocess module In-Reply-To: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B796F49.9020102@optimum.net> On 2/15/2010 7:35 AM, R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I want to execute a command from within python using the subprocess module. > > Coming from a Perl background, I thought I could use variable > interpolation in strings, but found that this is neither supported Yes, it is: see the use of string.Template below. > ... nor > the Python way. That right -- it isn't the Python way. Python offers two basic alternatives. Alf already presented the use of the "new" format() method of string objects. I think "traditional" Python string formatting might be what you want in this case: colors = ['#abcdef', '#456789'] format_string = "convert -size 5x30 gradient:%s-%s /tmp/image.png" cmd_string = format_string % tuple(colors) ... or better, by making *colors* a tuple instead of a list ... colors = ('#abcdef', '#456789') format_string = "convert -size 5x30 gradient:%s-%s /tmp/image.png" cmd_string = format_string % colors As Peter demonstrated, you need to use split() on *cmd_string* when you send the command to subprocess.call(). Now if you *really* miss using Perl, try this: c1, c2 = ('#abcdef', '#456789') template = string.Template( "convert -size 5x30 gradient:$c1-$c2 /tmp/image.png") cmd_string = template.substitute(locals()) Not worth the trouble, IMHO. Refs: http://www.python.org/doc/2.5.2/lib/typesseq-strings.html http://www.python.org/doc/2.5.2/lib/node40.html HTH, John From steve at holdenweb.com Mon Feb 15 10:59:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 10:59:22 -0500 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: <1266248602.28792.1360069669@webmail.messagingengine.com> References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: <4B796F5A.40405@holdenweb.com> python at bdurham.com wrote: > Is there any way to time out a regular expression in Python 2.6.4? > > Motiviation: Our application allows users to enter regular expressions > as validation criteria. If a user enters a pathological regular > expression, we would like to timeout the evaluation of this expression > after a short period of time. > Python itself does not contain any mechanism to terminate an operation if it takes too much time. One approach would be to run the regex in a subprocess, and apply process limits to terminate that subprocess if it ran too long. This group being what it is you are likely to receive other, better suggestions too. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 15 10:59:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 10:59:22 -0500 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: <1266248602.28792.1360069669@webmail.messagingengine.com> References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: <4B796F5A.40405@holdenweb.com> python at bdurham.com wrote: > Is there any way to time out a regular expression in Python 2.6.4? > > Motiviation: Our application allows users to enter regular expressions > as validation criteria. If a user enters a pathological regular > expression, we would like to timeout the evaluation of this expression > after a short period of time. > Python itself does not contain any mechanism to terminate an operation if it takes too much time. One approach would be to run the regex in a subprocess, and apply process limits to terminate that subprocess if it ran too long. This group being what it is you are likely to receive other, better suggestions too. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From pxrepreza at gmail.com Mon Feb 15 11:06:00 2010 From: pxrepreza at gmail.com (Paulo Repreza) Date: Mon, 15 Feb 2010 11:06:00 -0500 Subject: Loop problem while generating a new value with random.randint() Message-ID: Greetings, I'm having problems with a little script that I'm trying to finish, I don't know if I'm in the right track but I know somebody is going to help me. The script: # Import modules random for function randint import random # Generating a constant. var = 65 # Generating a random number. ranum = random.randint(1,100) #Creating while loop. Stops until var == ranum while var != ranum: if var == ranum: print var, 'equals to:', ranum else: print var, 'does not equal to:', ranum ########## End of Script ########### What I'm trying to do is to print the new value that ranum generates if the condition is not met. So far if you run the script it prints the same value over and over again, making in an infinite loop. What can I do in order to print out the new value generated every time the condition is not met? Thanks! Paulo Repreza -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Mon Feb 15 11:06:49 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 17:06:49 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: Message-ID: <4B797119.6040802@sequans.com> Benedict Verheyen wrote: > Hi, > > i wanted to ask how you guys structure your code. > I mainly have scripts that automate small tasks. > These scripts use a common set of utility code. > My code is structured like this, for example: > > script_1.py > script_2.py > script_3.py > tools\ > |----->__init__.py > |----->logutils.py > |----->mailutils.py > > I was thinking of putting code in seperate directories because the number > of scripts grows fast and i want to keep it clean. > Something like this: > > script_1.py > tools\ > |----->__init__.py > |----->logutils.py > |----->mailutils.py > database\ > |----->__init__.py > |----->script_2.py > |----->script_3.py > > However, when i make a subdirectory, for example database and put a script in there, > how would i import logutils or mailtutils from within the database subdirectory? > This fails: > from tools.logutils import logger > > Thanks, > Benedict > > Hi, 1/ Provide the output of the error so we can provide some useful help. 2/ Embed your structure into a package. Names like 'tools', 'lib', 'mail', 'log' are too generic and will clash with other badly designed module/package names. Choose a name for you package, and use it with absolute imports e.g : from myBeautifulPackage.tools.logutil import logger 3/ make sure your working copy of myBeautifulPackage is in your PYTHONPATH. JM From chyavana at gmail.com Mon Feb 15 11:11:36 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Tue, 16 Feb 2010 00:11:36 +0800 Subject: Executing a command from within python using the subprocess module In-Reply-To: References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B797238.2090007@gmail.com> Peter Otten wrote: > import subprocess > > def convert(width=5, height=30, colors=['#abcdef', '#456789'], > filename="tmp/image with space in its name.png"): > lookup = locals() > assert all("\n" not in str(s) for s in lookup.values()) > subprocess.call("""\ > convert > -size > {width}x{height} > gradient:{colors[0]}-{colors[1]} > {filename}""".format(**lookup).splitlines()) > > convert() > > Peter One other question I forgot to ask is this why is there a terminal backslash in > subprocess.call("""\ Removing the backslash makes the function fail. I wonder why, because """ is supposed to allow multi-line strings. I am sorry if this sounds obtuse but that backslash baffles me. From lacrima.maxim at gmail.com Mon Feb 15 11:15:21 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Mon, 15 Feb 2010 08:15:21 -0800 (PST) Subject: Which mock library do you prefer? Message-ID: Hello! I am newbie mastering test driven development. I can't clarify myself which mock library to use. There are number of them and which one do you prefer? Two libraries that attracted my attention are: * minimock * dingus As for me the latest one, dingus, is the easiest (see this screencast: http://vimeo.com/3949077 ), but it has very few downloads from pypi, so it scares me a little. Minimock has wider usage and community, but I have some troubles using it. Maybe I am wrong, but with minimock you always have to keep track the order of imports in your test modules. Well, may be I just don't understand fully how minimock works. What are your suggestions? From jeanmichel at sequans.com Mon Feb 15 11:17:39 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 17:17:39 +0100 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: <4B7973A3.3040407@sequans.com> Paulo Repreza wrote: > Greetings, > > I'm having problems with a little script that I'm trying to finish, I > don't know if I'm in the right track but I know somebody is going to > help me. > > The script: > > # Import modules random for function randint > > import random > > # Generating a constant. > > var = 65 > > # Generating a random number. > ranum = random.randint(1,100) > > #Creating while loop. Stops until var == ranum > while var != ranum: > if var == ranum: > print var, 'equals to:', ranum > else: > print var, 'does not equal to:', ranum > > ########## End of Script ########### > > > What I'm trying to do is to print the new value that ranum generates > if the condition is not met. So far if you run the script it prints > the same value over and over again, making in an infinite loop. What > can I do in order to print out the new value generated every time the > condition is not met? > > Thanks! > > Paulo Repreza in your script you generate the random number only once, no wonder it keep being the same value over & over. # Initialize ranum with a random number ranum = random.randint(1,100) #Creating while loop. Stops until var == ranum while var != ranum: if var == ranum: print var, 'equals to:', ranum else: print var, 'does not equal to:', ranum ranum = random.randint(1,100) # generate a new number, that's the missing line in your script JM From mmm286 at gmail.com Mon Feb 15 11:18:50 2010 From: mmm286 at gmail.com (mierdatutis mi) Date: Mon, 15 Feb 2010 17:18:50 +0100 Subject: get a field Message-ID: Hi, I have this: pe=" http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml " I would like to extract this: 691046.shtml But is dynamically. Not always have the same lenght the string. Could you help me how could I do extract this in python? Many thanks and sorry for my English! -------------- next part -------------- An HTML attachment was scrubbed... URL: From benedict.verheyen at gmail.com Mon Feb 15 11:27:41 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Mon, 15 Feb 2010 17:27:41 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4B797119.6040802@sequans.com> References: <4B797119.6040802@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Hi, > > 1/ Provide the output of the error so we can provide some useful help. > 2/ Embed your structure into a package. Names like 'tools', 'lib', > 'mail', 'log' are too generic and will clash with other badly designed > module/package names. Choose a name for you package, and use it with > absolute imports e.g : > from myBeautifulPackage.tools.logutil import logger > 3/ make sure your working copy of myBeautifulPackage is in your PYTHONPATH. > > JM Hi, the error i get is this: Traceback (most recent call last): File "update_tax_responsible.py", line 18, in from tools.logutils import logger ImportError: No module named tools.logutils As to your comments on putting everything in a package, that's the whole problem, it are all scripts where only a few of them are related and they all use one or more modules that are located in the tools directory. In that tools subdirectory i have a py file for typical file functions, time functions, and so on. For instance, the tools\fileutils.py file contains amongst others a function that calculates the size of a directory. If i understood correctly, your suggestion is to put the utility files in the tools subdirectory in a seperate package and put that package on the python path so it can be shared by all scripts. I should then further structure the scripts by putting scripts together. But since the functions in tools are really utility functions for common tasks, what would a meaningfule package name be? The scripts are really diverse for instance, one of the scripts will check the names of subdirectories made by employees, another will send mail if people forget to fill in certain fields in a database and so on. That's one of the reasons why i'm having a hard time structering it. Regards, Benedict From bruno.42.desthuilliers at websiteburo.invalid Mon Feb 15 11:30:29 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Mon, 15 Feb 2010 17:30:29 +0100 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: <4b7976a3$0$24284$426a74cc@news.free.fr> Jean-Michel Pichavant a ?crit : > Paulo Repreza wrote: >> Greetings, >> >> I'm having problems with a little script that I'm trying to finish, I >> don't know if I'm in the right track but I know somebody is going to >> help me. (snip - problem already addressed by Jean-Michel...) >> while var != ranum: >> if var == ranum: Note that this branch will never be executed - the condition in the while statement make sure var != ranum in the while block. >> print var, 'equals to:', ranum >> else: >> print var, 'does not equal to:', ranum >> From ssteinerx at gmail.com Mon Feb 15 11:30:59 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Mon, 15 Feb 2010 11:30:59 -0500 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4B797119.6040802@sequans.com> References: <4B797119.6040802@sequans.com> Message-ID: <13868D3D-76E6-4F97-8743-FC5479DFB74E@gmail.com> On Feb 15, 2010, at 11:06 AM, Jean-Michel Pichavant wrote: > 3/ make sure your working copy of myBeautifulPackage is in your PYTHONPATH. Or, make a simple setup.py which imports distribute or setuptools and use: # python setup.py develop which will put your code into the PYTHONPATH by virtue of a link inside your site-packages. First one I found googling for "setup.py develop" : https://www.siafoo.net/article/77 There's a typo in the code of section 1.2 (parenthesis at the end of import, wrong), but the basic idea is there. S From steve at holdenweb.com Mon Feb 15 11:31:58 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 11:31:58 -0500 Subject: Executing a command from within python using the subprocess module In-Reply-To: <4B797238.2090007@gmail.com> References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> <4B797238.2090007@gmail.com> Message-ID: R (Chandra) Chandrasekhar wrote: > Peter Otten wrote: >> import subprocess >> >> def convert(width=5, height=30, colors=['#abcdef', '#456789'], >> filename="tmp/image with space in its name.png"): >> lookup = locals() >> assert all("\n" not in str(s) for s in lookup.values()) >> subprocess.call("""\ >> convert >> -size >> {width}x{height} >> gradient:{colors[0]}-{colors[1]} >> {filename}""".format(**lookup).splitlines()) >> >> convert() >> >> Peter > > One other question I forgot to ask is this why is there a terminal > backslash in > >> subprocess.call("""\ > > Removing the backslash makes the function fail. > > I wonder why, because """ is supposed to allow multi-line strings. I am > sorry if this sounds obtuse but that backslash baffles me. It does, but a leading newline would cause the splitlines() result to start with an empty word - the backslash just causes the interpreter to ignore the newline immediately following, rather than including it in the string literal's value. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Mon Feb 15 11:35:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 11:35:16 -0500 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: Paulo Repreza wrote: > Greetings, > > I'm having problems with a little script that I'm trying to finish, I > don't know if I'm in the right track but I know somebody is going to > help me. > > The script: > > # Import modules random for function randint > > import random > > # Generating a constant. > > var = 65 > > # Generating a random number. > ranum = random.randint(1,100) > > #Creating while loop. Stops until var == ranum > while var != ranum: > if var == ranum: The "if" condition can never be true, since if it were then the loop would have just terminated before starting this iteration! > print var, 'equals to:', ranum > else: > print var, 'does not equal to:', ranum > Shouldn't there be something here to set ranum to a new value? Otherwise the same value will be there the next time around ... > ########## End of Script ########### > > > What I'm trying to do is to print the new value that ranum generates if > the condition is not met. So far if you run the script it prints the > same value over and over again, making in an infinite loop. What can I > do in order to print out the new value generated every time the > condition is not met? > > Thanks! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ d From chyavana at gmail.com Mon Feb 15 11:36:44 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Tue, 16 Feb 2010 00:36:44 +0800 Subject: Executing a command from within python using the subprocess module In-Reply-To: References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: <4B79781C.50205@gmail.com> Alf P. Steinbach wrote: > * R (Chandra) Chandrasekhar: >> >> width = 5 >> height = 30 >> colors = ['#abcdef]', '#456789'] >> filename = "/tmp/image.png" >> >> # I want to get the equivalent of variable interpolation in Perl >> # so that the command >> # >> # convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png >> # >> # is derived from the variables above > > Assuming that the extra right square bracket in 'colors' is a typo, > here's one way: > > s = "convert -size {w}x{h} gradient:{g1}-{g2} {f}".format( > w = width, h = height, g1 = colors[0], g2 = colors[1], f = filename > ) > > > Cheers & hth., > > - ALf Thanks, Alf. It works if I use it so: subprocess.call(s, shell=True) and I think that is because s is a single string assembled in almost the variable interpolation fashion of Perl. It does not work with the default shell=False argument, presumably because the arguments are not split into separate strings (something that was horrible to do by hand using the %s and %() syntax that I had tried out previously). I think that you and Peter have, between you, shown me two ways of using subprocess.call(): one with shell=True and the other with shell = False. Thanks. Chandra From arnodel at googlemail.com Mon Feb 15 11:39:36 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Feb 2010 16:39:36 +0000 Subject: Loop problem while generating a new value with random.randint() References: Message-ID: Jean-Michel Pichavant writes: > Paulo Repreza wrote: >> Greetings, >> >> I'm having problems with a little script that I'm trying to finish, >> I don't know if I'm in the right track but I know somebody is going >> to help me. >> >> The script: >> >> # Import modules random for function randint >> >> import random >> >> # Generating a constant. >> >> var = 65 >> >> # Generating a random number. >> ranum = random.randint(1,100) >> >> #Creating while loop. Stops until var == ranum >> while var != ranum: >> if var == ranum: >> print var, 'equals to:', ranum >> else: >> print var, 'does not equal to:', ranum >> >> ########## End of Script ########### >> >> >> What I'm trying to do is to print the new value that ranum generates >> if the condition is not met. So far if you run the script it prints >> the same value over and over again, making in an infinite loop. What >> can I do in order to print out the new value generated every time >> the condition is not met? >> >> Thanks! >> >> Paulo Repreza > in your script you generate the random number only once, no wonder it > keep being the same value over & over. > > # Initialize ranum with a random number > ranum = random.randint(1,100) > > #Creating while loop. Stops until var == ranum > while var != ranum: > if var == ranum: > print var, 'equals to:', ranum > else: > print var, 'does not equal to:', ranum > ranum = random.randint(1,100) # generate a new number, that's the > missing line in your script > > JM And a more idiomatic way of writing this in Python would be, I guess: import random var = 65 while True: ranum = random.randint(1, 100) if var == ranum: print var, 'equals to:', ranum break else: print var, 'does not equal to:', ranum (following up from a FU as I can't see the OP) -- Arnaud From __peter__ at web.de Mon Feb 15 11:44:25 2010 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Feb 2010 17:44:25 +0100 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> <4B796CB2.2000302@gmail.com> Message-ID: R (Chandra) Chandrasekhar wrote: > Peter Otten wrote: > >> import subprocess >> >> def convert(width=5, height=30, colors=['#abcdef', '#456789'], >> filename="tmp/image with space in its name.png"): >> lookup = locals() >> assert all("\n" not in str(s) for s in lookup.values()) >> subprocess.call("""\ >> convert >> -size >> {width}x{height} >> gradient:{colors[0]}-{colors[1]} >> {filename}""".format(**lookup).splitlines()) >> >> convert() >> >> Peter > > Thank you. It works. Now I need to understand why and am able to follow > what you are doing part of the way: > > 1. Assign default values in the function definition. > > 2. Store the variables existing in the local namespace in the list lookup. > > 3. Assert that there are no newlines in the values in lookup converted > to strings. (Why? Is this because of splitlines() later on?) Yes. > 4. Assemble a string (array?) for the subprocess.call argument using the > format string syntax (section 8.1.3 et seq. of the Python > documentation for 2.6.4). Your example works with default option of > shell=False for subprocess.call(). I wanted to pass the executable and its arguments as a list (a python "list" is called array in other languages) to avoid bothering with shell escapes. > 5. I am unable to decipher how you got to format(**lookup).splitlines()) > especially the **prefix part, although I guess that splitlines() is > dishing out the arguments one by one from each line in the > subprocess.call argument. Given some_dict = {key1: value1, key2: value2,...} f(**some_dict) is a shortcut for f(key1=value1, key2=value2, ...) with the additional twist that you do not have to know the key/value pairs in advance. I introduced splitlines to avoid calling the format method on every argument to "convert", i. e. def convert2(width=5, height=30, colors=['#abcdef', '#456789'], filename="tmp/image with space in its name.png"): subprocess.call([ "convert", "-size", "{width}x{height}".format(width=width, height=height), "gradient:{0}-{1}".format(*colors), filename]) I supected that it would look cleaner than the above, but now that I tried it I think convert2() is the better alternative. Peter From nobody at nowhere.com Mon Feb 15 11:50:13 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 15 Feb 2010 16:50:13 +0000 Subject: Fighting with subprocess.Popen References: <6ac1a5aa1002141223h54b6aca6k3f2a57a85fc1bad5@mail.gmail.com> Message-ID: On Sun, 14 Feb 2010 21:43:22 +0100, Christian Heimes wrote: >> Below is a test case that demonstrates this. Tests 1 & 2 concatenate the >> command and the argument, Tests 3 & 4 mimic the python docs and use the form >> Popen(["mycmd", "myarg"], ...), which never seems to work. > > It doesn't work with shell=True because the shell is not able to > interpret the list form. It's recommended that you don't use shell=True > unless you need a shell. A more general rule is to use shell=True on Windows and shell=False on Unix (including MacOSX). On Windows, whether the command is a list or a string is entirely orthogonal to whether a shell is used. The underlying execution function (CreateProcess) always uses a string, so a list is always converted to a string, and the conversion is independent of the shell= setting. The difference between shell=False and shell=True is that the former passes the string directly to CreateProcess while the latter passes "cmd.exe /c "+string (cmd.exe is actually the value of %comspec% if it is set). The reason for using shell=True on Windows is that it allows the program to be a batch file (or other script), while shell=False only works if the program is a binary executable (.exe, .com). On Unix, passing the arguments as a list in conjunction with shell=True rarely makes sense. It results in the execution of ["/bin/sh", "-c"] + args i.e. args[0] is the argument to "-c" while the remaining arguments are assigned to the shell variables $1, $2, etc. If you're using the shell, you usually you want to pass the entire command as a string, resulting in the execution of ["/bin/sh", "-c", command] From jeanmichel at sequans.com Mon Feb 15 11:50:41 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 15 Feb 2010 17:50:41 +0100 Subject: get a field In-Reply-To: References: Message-ID: <4B797B61.7090804@sequans.com> mierdatutis mi wrote: > Hi, > > I have this: > > pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" > > > I would like to extract this: 691046.shtml > > But is dynamically. Not always have the same lenght the string. > > Could you help me how could I do extract this in python? > > Many thanks and sorry for my English! > In [2]: import os In [3]: os.path.basename(pe) Out[3]: '691046.shtml' JM From steve at holdenweb.com Mon Feb 15 11:54:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 11:54:22 -0500 Subject: get a field In-Reply-To: References: Message-ID: mierdatutis mi wrote: > Hi, > > I have this: > > pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" > > > I would like to extract this: 691046.shtml > > But is dynamically. Not always have the same lenght the string. > > Could you help me how could I do extract this in python? > > Many thanks and sorry for my English! > >>> s = "http://server/path/to/file/file.shtml" >>> s.rfind("/") # finds rightmost "/" 26 >>> s[s.rfind("/")+1:] # substring starting after "/" 'file.shtml' >>> regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From nobody at nowhere.com Mon Feb 15 11:56:51 2010 From: nobody at nowhere.com (Nobody) Date: Mon, 15 Feb 2010 16:56:51 +0000 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> <4B797238.2090007@gmail.com> Message-ID: On Tue, 16 Feb 2010 00:11:36 +0800, R (Chandra) Chandrasekhar wrote: > One other question I forgot to ask is this why is there a terminal > backslash in > >> subprocess.call("""\ > > Removing the backslash makes the function fail. > > I wonder why, because """ is supposed to allow multi-line strings. I am > sorry if this sounds obtuse but that backslash baffles me. The backslash causes the following newline to be skipped, so the "c" at the beginning of "convert" is the first character in the string. Without it, the newline would be the first character, and the .splitlines() would result in an empty string as the first element in the list. Example: > """ = hello = world = """.splitlines() ['', 'hello', 'world'] > """\ = hello = world = """.splitlines() ['hello', 'world'] From phlip2005 at gmail.com Mon Feb 15 11:57:37 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 15 Feb 2010 08:57:37 -0800 (PST) Subject: Which mock library do you prefer? References: Message-ID: Lacrima wrote: > I am newbie mastering test driven development. I can't clarify myself > which mock library to use. > There are number of them and which one do you prefer? > > Two libraries that attracted my attention are: > * minimock > * dingus > As for me the latest one, dingus, is the easiest (see this screencast:http://vimeo.com/3949077? ), but it has very few downloads from pypi, > so it scares me a little. > Minimock has wider usage and community, but I have some troubles using > it. Maybe I am wrong, but with minimock you always have to keep track > the order of imports in your test modules. Well, may be I just don't > understand fully how minimock works. > > What are your suggestions? I have used http://pypi.python.org/pypi/mock/0.6.0 . It mocks, and it has a mode that works one method at a time, and another mode that mocks a method before its owning object gets constructed. However, TDD is not about mocking, and on greenfield code you should only mock to recover from some external problem, such as: - a random number generator - the system clock - anything over "the wire" - over a TCP/IP socket - hardware, such as your graphics or sound Never mock to avoid hitting the database. Some TDD verbiage advises "never hit the database". That is a mind-game to force you to decouple your code. Your objects should always have the option (via "construction encapsulation") to run as stubs, with some of their behaviors turned off. And if you TDD low-level code that hits a database, a mock would only tell the test what it wants to hear. And if you TDD high-level code that manages business rules, database records make perfectly good behavioral "fixtures" to support those rules. -- Phlip http://c2.com/cgi/wiki?ZeekLand From showell30 at yahoo.com Mon Feb 15 12:02:38 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 15 Feb 2010 09:02:38 -0800 (PST) Subject: Which mock library do you prefer? References: Message-ID: On Feb 15, 8:15?am, Lacrima wrote: > Hello! > > I am newbie mastering test driven development. I can't clarify myself > which mock library to use. > There are number of them and which one do you prefer? > > Two libraries that attracted my attention are: > * minimock > * dingus > As for me the latest one, dingus, is the easiest (see this screencast:http://vimeo.com/3949077? ), but it has very few downloads from pypi, > so it scares me a little. I've used dingus with success. I wouldn't let the lack of downloads be a concern; the funny name is probably scaring some people away, and of course there are other alternatives too. From mukeshtiwari.iiitm at gmail.com Mon Feb 15 12:08:30 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Mon, 15 Feb 2010 09:08:30 -0800 (PST) Subject: Python Optimization References: <892f7664-14e9-4ce4-ab50-499fc8552ec3@v25g2000yqk.googlegroups.com> <0eac0e90-fd39-4851-b979-c109218fb0ba@a5g2000prg.googlegroups.com> Message-ID: <276960d6-97d7-4f46-827e-b14345d8ea2d@s33g2000prm.googlegroups.com> On Feb 15, 1:07?am, Steve Howell wrote: > On Feb 14, 11:52?am, Mark Dickinson wrote: > > > > > > > On Feb 14, 4:53?pm, mukesh tiwari > > wrote: > > > > Hello everyone. I am new to python and previously i did programming in > > > c/c++.Could some one please help me to improve the run time for this > > > python program as i don't have idea how to optimized this code.This > > > code also seems to be more unpythonic so how to make it look like more > > > pythonic . I am trying for this problem(https://www.spoj.pl/problems/ > > > FACT1/). > > > Thank you > > > One other thing: ?in the 'brent' function, you're setting m to > > randrange(1, n). ?What's the purpose of this? ?It looks to me as > > though m controls the number of Pollard-Rho iterations that are > > clumped together at one time (before doing a gcd operation), and using > > a random number for this doesn't make a lot of sense to me. > > The randomness also makes the algorithm a little buggy. > > I tried this input: > > 37^5 41^5 > > Usually I get the right answer. ?Other times I get this: > > 37^5 41^3 1681^1 > > And occasionally it appears to get into an infinite loop, which > definitely could be a cause of "slowness." :) Thank you all for help. I will try to improve these short comings. From pxrepreza at gmail.com Mon Feb 15 12:27:29 2010 From: pxrepreza at gmail.com (Paulo Repreza) Date: Mon, 15 Feb 2010 12:27:29 -0500 Subject: Loop problem while generating a new value with random.randint() In-Reply-To: References: Message-ID: Thanks for the help! Using while True helps alot! Paulo Repreza -------------- next part -------------- An HTML attachment was scrubbed... URL: From fersed at gmail.com Mon Feb 15 12:55:08 2010 From: fersed at gmail.com (fernando sedano) Date: Mon, 15 Feb 2010 18:55:08 +0100 Subject: saving a TIFF Message-ID: I'm trying to save an image created from two arrays (I'm using numpy and PIL): n=(b4a-b3a)/(b4a+b3a); ndvi = Image.fromarray(n) ndvi.save("F:\Fire_scar_mapping\ILS3\ndvi_test","TIFF") ...........but I get the following error message: IOError: [Errno 22] invalid mode ('wb') or filename: 'F:\\Fire_scar_mapping\\ILS3\ndt' Could anybody tell me what I'm doing wrong? -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Mon Feb 15 13:06:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Mon, 15 Feb 2010 13:06:51 -0500 Subject: saving a TIFF In-Reply-To: References: Message-ID: On Mon, Feb 15, 2010 at 12:55 PM, fernando sedano wrote: > I'm trying to save an image created from two arrays (I'm using numpy and > PIL): > > > n=(b4a-b3a)/(b4a+b3a); > ndvi = Image.fromarray(n) > ndvi.save("F:\Fire_scar_mapping\ILS3\ndvi_test","TIFF") > > ...........but I get the following error message: > > IOError: [Errno 22] invalid mode ('wb') or filename: > 'F:\\Fire_scar_mapping\\ILS3\ndt' > > Could anybody tell me what I'm doing wrong? > > -- > http://mail.python.org/mailman/listinfo/python-list > > ---------- >>> print "F:\Fire_scar_mapping\ILS3\ndvi_test","TIFF" F:\Fire_scar_mapping\ILS3 dvi_test TIFF -------------- Notice anything wrong with that? Unlike the Windows command line, Python neither knows nor cares that the string you're entering is a file name. It sees the \n and converts it to a newline. Either double up your backslashes ( "F:\\Fire_scar_mapping\\ILS3\\ndvi_test"), use a raw string (r"F:\Fire_scar_mapping\ILS3\ndvi_test") or use forward slashes ("F:/Fire_scar_mapping/ILS3/ndvi_test") From python.list at tim.thechases.com Mon Feb 15 13:28:25 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Feb 2010 12:28:25 -0600 Subject: get a field In-Reply-To: References: Message-ID: <4B799249.2020205@tim.thechases.com> Holden wrote: > mierdatutis mi wrote: >> I have this: >> >> pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" >> >> I would like to extract this: 691046.shtml >> >> But is dynamically. Not always have the same lenght the string. > >>>> s = "http://server/path/to/file/file.shtml" >>>> s.rfind("/") # finds rightmost "/" > 26 >>>> s[s.rfind("/")+1:] # substring starting after "/" > 'file.shtml' If I didn't use os.path.basename(s) then I'd write this as "s.rsplit('/', 1)[-1]" >>> "http://server/path/to/file/file.shtml".rsplit('/', 1)[-1] 'file.shtml' >>> "".rsplit('/', 1)[-1] '' >>> "file.html".rsplit('/', 1)[-1] 'file.html' I don't know how much of a difference it makes, but I always appreciate seeing how various people solve the same problem. I tend to lean away from the find()/index() methods on strings because I have to stop and think which one raises the exception and which one returns -1 (and that it's -1 instead of 0) usually dropping to a python shell and doing >>> help("".find) >>> help("".index) to refresh my memory. FWIW, Steve's solution and the os.path.basename() both produce the same results with all 3 input values, so it's more a matter of personal style preference. The basename() version has slightly different results if you have Windows paths with backslashes: s = r'c:\path\to\file.txt' but since you (OP) know that they should be URLs with forward-slashes, it should be a non-issue. -tkc From leo at lspace.org Mon Feb 15 13:29:38 2010 From: leo at lspace.org (Leo Breebaart) Date: 15 Feb 2010 18:29:38 GMT Subject: Using class attributes Message-ID: <7tti4iFehdU1@mid.individual.net> I have a base class Foo with a number of derived classes FooA, FooB, FooC, etc. Each of these derived classes needs to read (upon initialisation) text from an associated template file FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. I can derive the template filename string for each instance by doing something like this in the base class (and then not forgetting to call super() in the __init__() of each derived class): class Foo(object): def __init__(self): self.template_filename = "%s.tmpl" % self.__class__.__name__ self.template_body = read_body_from(self.template_filename) But, since this information is the same for every instance of each derived class, I was wondering if there was a way to achieve the same thing outside of the __init__ function, and just have these assignments be done as a class attribute (i.e. so that I can refer to FooA.template_body, etc.) I can of course always just hardcode the template filenames in each derived class, but I am just curious if it can be automated through some form of introspection. -- Leo Breebaart From lacrima.maxim at gmail.com Mon Feb 15 13:33:33 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Mon, 15 Feb 2010 10:33:33 -0800 (PST) Subject: Which mock library do you prefer? References: Message-ID: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> On Feb 15, 6:57 pm, Phlip wrote: > Lacrima wrote: > > I am newbie mastering test driven development. I can't clarify myself > > which mock library to use. > > There are number of them and which one do you prefer? > > > Two libraries that attracted my attention are: > > * minimock > > * dingus > > As for me the latest one, dingus, is the easiest (see this screencast:http://vimeo.com/3949077 ), but it has very few downloads from pypi, > > so it scares me a little. > > Minimock has wider usage and community, but I have some troubles using > > it. Maybe I am wrong, but with minimock you always have to keep track > > the order of imports in your test modules. Well, may be I just don't > > understand fully how minimock works. > > > What are your suggestions? > > I have usedhttp://pypi.python.org/pypi/mock/0.6.0. It mocks, and it > has a mode that works one method at a time, and another mode that > mocks a method before its owning object gets constructed. > > However, TDD is not about mocking, and on greenfield code you should > only mock to recover from some external problem, such as: > > - a random number generator > - the system clock > - anything over "the wire" - over a TCP/IP socket > - hardware, such as your graphics or sound > > Never mock to avoid hitting the database. Some TDD verbiage advises > "never hit the database". That is a mind-game to force you to decouple > your code. Your objects should always have the option (via > "construction encapsulation") to run as stubs, with some of their > behaviors turned off. And if you TDD low-level code that hits a > database, a mock would only tell the test what it wants to hear. And > if you TDD high-level code that manages business rules, database > records make perfectly good behavioral "fixtures" to support those > rules. > > -- > Phlip > http://c2.com/cgi/wiki?ZeekLand Hi, Phlip! Thanks for your reply! Isn't what you are talking about integration tests? And unit tests should be fully isolated? So even for method 'some_method()' of class A I should mock instance of class A (i.e. to mock 'self') to test 'some_method()'. Please, could you explain in more detail your thoughts: > Your objects should always have the option (via > "construction encapsulation") to run as stubs, with some of their > behaviors turned off. And if you TDD low-level code that hits a > database, a mock would only tell the test what it wants to hear. And > if you TDD high-level code that manages business rules, database > records make perfectly good behavioral "fixtures" to support those > rules. And could you give an example. For me it's really hard to develop test first. Often I don't know what tests to write to replace hardcoded return values by objects that perform actual work. I have read several books on TDD and explored http://c2.com/cgi/wiki?TestDrivenDevelopment and related wikis, but often it seems I don't have enough understanding to write even simple application. And sorry for my English. with regards, Max. From mrkafk at gmail.com Mon Feb 15 13:43:25 2010 From: mrkafk at gmail.com (mk) Date: Mon, 15 Feb 2010 19:43:25 +0100 Subject: Plugin architecture Message-ID: Hello everyone, I'm thinking about writing plugin-style architecture for (a new) web-based app (with SQLAlchemy as backend). Say, there's core web app and someone decides to write plugin Accounting for this web app that would work with SQA objects of the core app or other plugins. I found this: http://effbot.org/zone/metaclass-plugins.htm (Although I'm not entirely sure this is the best approach for the web app) How would you approach designing such architecture using features available in Python (and some major web framework, like Pylons or Django)? Regards, mk From fetchinson at googlemail.com Mon Feb 15 13:53:23 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Mon, 15 Feb 2010 19:53:23 +0100 Subject: Plugin architecture In-Reply-To: References: Message-ID: > I'm thinking about writing plugin-style architecture for (a new) > web-based app (with SQLAlchemy as backend). > > Say, there's core web app and someone decides to write plugin Accounting > for this web app that would work with SQA objects of the core app or > other plugins. > > I found this: > > http://effbot.org/zone/metaclass-plugins.htm > > (Although I'm not entirely sure this is the best approach for the web app) > > How would you approach designing such architecture using features > available in Python (and some major web framework, like Pylons or Django)? Major web frameworks like django, turbogears (thicker ones), pylons, cherrypy (thinner ones) include all the functionality for doing this sort of thing out of the box. If I were you I would go ahead and use one of these frameworks and only start thinking about designing something new if I hit a wall. Chances are you won't. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From bigblueswope at gmail.com Mon Feb 15 13:53:38 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 13:53:38 -0500 Subject: TypeError Exception in email lib Message-ID: File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz if data[9] is None: TypeError: 'NoneType' object is unsubscriptable I'm parsing a bunch of spam and using the date field from the spams for a date-time stamp. I've fixed the lib on my box to place the call inside a try/except clause to catch the exception now, but it seems the module has a bug in it. How would I go about recommending a change the module? Original code: def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone Patched code: def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" try: if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone except TypeError: return time.mktime(data[:8] + (-1,)) ---- Auburn fans are like slinkys... not really good for anything but they still bring a smile to your face when you push them down a flight of stairs. To argue that honorable conduct is only required against an honorable enemy degrades the Americans who must carry out the orders. -- Charles Krulak, Former Commandant of the Marine Corps We are all slave to our own paradigm. -- Joshua Williams If the letters PhD appear after a person's name, that person will remain outdoors even after it's started raining. -- Jeff Kay From python at mrabarnett.plus.com Mon Feb 15 13:56:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Feb 2010 18:56:10 +0000 Subject: get a field In-Reply-To: <4B799249.2020205@tim.thechases.com> References: <4B799249.2020205@tim.thechases.com> Message-ID: <4B7998CA.2090604@mrabarnett.plus.com> Tim Chase wrote: > Holden wrote: >> mierdatutis mi wrote: >>> I have this: >>> >>> pe="http://www.rtve.es/mediateca/videos/20100211/saber-comer---patatas-castellanas-costillas-11-02-10/691046.shtml" >>> >>> >>> I would like to extract this: 691046.shtml >>> >>> But is dynamically. Not always have the same lenght the string. >> >>>>> s = "http://server/path/to/file/file.shtml" >>>>> s.rfind("/") # finds rightmost "/" >> 26 >>>>> s[s.rfind("/")+1:] # substring starting after "/" >> 'file.shtml' > > If I didn't use os.path.basename(s) then I'd write this as > "s.rsplit('/', 1)[-1]" > > >>> "http://server/path/to/file/file.shtml".rsplit('/', 1)[-1] > 'file.shtml' > >>> "".rsplit('/', 1)[-1] > '' > >>> "file.html".rsplit('/', 1)[-1] > 'file.html' > > I don't know how much of a difference it makes, but I always appreciate > seeing how various people solve the same problem. I tend to lean away > from the find()/index() methods on strings because I have to stop and > think which one raises the exception and which one returns -1 (and that > it's -1 instead of 0) usually dropping to a python shell and doing > > >>> help("".find) > >>> help("".index) > > to refresh my memory. > > FWIW, Steve's solution and the os.path.basename() both produce the same > results with all 3 input values, so it's more a matter of personal style > preference. The basename() version has slightly different results if > you have Windows paths with backslashes: > > s = r'c:\path\to\file.txt' > > but since you (OP) know that they should be URLs with forward-slashes, > it should be a non-issue. > The MacOS separator was (is?) ":". Since MacOS X it has been based on Unix, so I'm not sure what Python sees nowadays, "/" or still ":". Another platform, RISC OS, uses ".". For that reason I wouldn't use os.path.basename(). An alternative to .rsplit() is .rpartition(). From python at mrabarnett.plus.com Mon Feb 15 14:21:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Feb 2010 19:21:17 +0000 Subject: TypeError Exception in email lib In-Reply-To: References: Message-ID: <4B799EAD.90805@mrabarnett.plus.com> BJ Swope wrote: > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > I'm parsing a bunch of spam and using the date field from the spams > for a date-time stamp. > > I've fixed the lib on my box to place the call inside a try/except > clause to catch the exception now, but it seems the module has a bug > in it. > > How would I go about recommending a change the module? > > Original code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > > Patched code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > try: > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > except TypeError: > return time.mktime(data[:8] + (-1,)) > The traceback is saying that 'data' is None, not that it's too short (that would raise an IndexError). From jjposner at optimum.net Mon Feb 15 14:24:23 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 15 Feb 2010 14:24:23 -0500 Subject: Modifying Class Object In-Reply-To: References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> Message-ID: <4b799f4a$0$4980$607ed4bc@cv.net> Alf said (2/13/2010 8:34 PM): > Names in Python refer to objects. > > Those references can be copied via assignment. > > That's (almost) all. > > And it provides a very short and neat way to describe pass by sharing. Alf also said (2/13/2010 8:43 PM): > * Steve Howell: > > This thread is interesting on many levels. What is the core > > question that is being examined here? > > I think that regarding the technical it is whether a Python name > refers to an object or not. I maintain that it does, and that the > reference can be copied, and that the semantics of the language > requires this and is defined in terms of this. Steve Holden, > D'Aprano and many others maintain that there are no references, or > that if there are then they're only an implementation aspect, i.e. > that conceiveable one could have an implementation without them. Steve D'Aprano said (2/14/2010 12:13 AM): > That's not to say that the general concept of references (as in "to > refer to") isn't valuable when discussing Python. If you want to say > that (e.g.) following > > x = 1 > > the name "x" refers to (or even points to!) the object 1, my > objections will be mild or non-existent. In that sense, it's probably > impossible to program without some sort of "references": the computer > manipulates variables or objects directly, while we manipulate > characters in source code. The only way to write a program is to use > some abstract thing (a name, an offset, whatever) that refers, in > some fashion, to a collection of bits in the computer's memory. But > to go from that to the idea that (say) x is a pointer does so much > violence to the concept of pointer and has so much room for confusion > that it is actively harmful. I think most of the technical argument in this thread comes down to the various forms of the word *refer*. After execution of this Python statement: x = 5 ... we can use this English-language statement: the name *x* refers to the value *5* (If anyone has more than Steve's "mild" objection, please speak up!) The English-language statement uses the VERB "refers". It is not the same as using the NOUN "reference": *x* is a reference to the value *5* Why not? Because using the NOUN form suggests that you're talking about a particular kind of object in the world Python, as in these statements: *x* is a string *x* is a function *x* is a class But Python does not define *reference* objects -- by which I mean that executing *import types; dir(types)* produces a long list of object-type names, and there's nothing like a "reference" on that list. (I suspect there's a better way to make this "there are no reference objects" argument. Can anyone help?) Amending the statement to: the name *x* is a reference to the value *5* ... doesn't really help matters. Is *x* a NAME or is it a REFERENCE? Looking again at Alf's assertion: > [the core technical question is] whether a Python name > refers to an object or not. I maintain that it does, and that the > reference can be copied, ... and Alf's example (message dated 2/10/2010 5:02 PM): > For example, > > x = s[0] > > accesses the object that s points (refers) to. I believe Alf would characterize this assignment statement as a situation in which "a reference is copied" [using the NOUN form of "refer"]. But no object is copied during execution of this statement. Moreover, saying "a reference is copied" might mislead a Python newbie into thinking that some kind of "reference object" exists that can be copied by Python statements. So it's better to describe the situation using the VERB form of "refer": assigns the name *x* to the object that *s[0]* refers to -John From apt.shansen at gmail.com Mon Feb 15 14:31:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Mon, 15 Feb 2010 11:31:11 -0800 Subject: TypeError Exception in email lib In-Reply-To: References: Message-ID: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> On Mon, Feb 15, 2010 at 10:53 AM, BJ Swope wrote: > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > I'm parsing a bunch of spam and using the date field from the spams > for a date-time stamp. > > I've fixed the lib on my box to place the call inside a try/except > clause to catch the exception now, but it seems the module has a bug > in it. > While there may or may not be a bug in the library, I don't think its where you're fixing. Just because an exception occurs in a function doesn't mean that function is broken: its documented as accepting a 10 item tuple, only. Functions in the stdlib generally -should- throw exceptions on invalid input. Someone's passing None into it, which its not allowed to do. So -that's- where the bug probably is, I think. (Although it may not be the immediate of mktime_tz; it could be happening higher up on the stack) Advice: Always post complete tracebacks to c.p.l/python-list :) --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From bigblueswope at gmail.com Mon Feb 15 14:47:32 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 14:47:32 -0500 Subject: TypeError Exception in email lib In-Reply-To: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: On Mon, Feb 15, 2010 at 2:31 PM, Stephen Hansen wrote: > On Mon, Feb 15, 2010 at 10:53 AM, BJ Swope wrote: >> >> ?File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz >> ? ?if data[9] is None: >> TypeError: 'NoneType' object is unsubscriptable >> >> I'm parsing a bunch of spam and using the date field from the spams >> for a date-time stamp. >> >> I've fixed the lib on my box to place the call inside a try/except >> clause to catch the exception now, but it seems the module has a bug >> in it. > > While there may or may not be a bug in the library, I don't think its where > you're fixing. Just because an exception occurs in a function doesn't mean > that function is broken: its documented as accepting a 10 item tuple, only. > Functions in the stdlib generally -should- throw exceptions on invalid > input. > Someone's passing None into it, which its not allowed to do. So -that's- > where the bug probably is, I think. (Although it may not be the immediate of > mktime_tz; it could be happening higher up on the stack) > Advice: Always post complete tracebacks to c.p.l/python-list :) > --S >From the module: def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone It appears that the module is trying to accommodate the potential missing TZ data because poorly written emails are missing the TZ data. I discarded all the crontab emails that had the full traceback in them. I took out the try/except clause in the hopes that I'll get another exception soon. If I do I'll post the entire exception traceback. From davea at ieee.org Mon Feb 15 14:51:04 2010 From: davea at ieee.org (Dave Angel) Date: Mon, 15 Feb 2010 14:51:04 -0500 Subject: TypeError Exception in email lib In-Reply-To: References: Message-ID: <4B79A5A8.8020008@ieee.org> BJ Swope wrote: > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > I'm parsing a bunch of spam and using the date field from the spams > for a date-time stamp. > > I've fixed the lib on my box to place the call inside a try/except > clause to catch the exception now, but it seems the module has a bug > in it. > > How would I go about recommending a change the module? > > Original code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > > Patched code: > def mktime_tz(data): > """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > try: > if data[9] is None: > # No zone info, so localtime is better assumption than GMT > return time.mktime(data[:8] + (-1,)) > else: > t = time.mktime(data[:8] + (0,)) > return t - data[9] - time.timezone > except TypeError: > return time.mktime(data[:8] + (-1,)) > > > ---- > Auburn fans are like slinkys... not really good for anything but they > still bring a smile to your face when you push them down a flight of > stairs. > > To argue that honorable conduct is only required against an honorable > enemy degrades the Americans who must carry out the orders. -- Charles > Krulak, Former Commandant of the Marine Corps > > We are all slave to our own paradigm. -- Joshua Williams > > If the letters PhD appear after a person's name, that person will > remain outdoors even after it's started raining. -- Jeff Kay > > Is the code that calls mktime_tz() your own? If so, maybe you'd be better off fixing that. The error message indicates that the 'data' parameter is None, which is invalid, according to the 2.6 documentation anyway (the parameter to the function is supposed to be a 10-tuple). So it's a bug in the caller, not in that function. Besides, your fix will still raise another exception inside the except class, since if data[9] gives that error, so will data[:8} DaveA From clp2 at rebertia.com Mon Feb 15 14:53:46 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Feb 2010 11:53:46 -0800 Subject: Using class attributes In-Reply-To: <7tti4iFehdU1@mid.individual.net> References: <7tti4iFehdU1@mid.individual.net> Message-ID: <50697b2c1002151153l2ce0050bt9297ae9acfa34c6b@mail.gmail.com> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: > I have a base class Foo with a number of derived classes FooA, > FooB, FooC, etc. Each of these derived classes needs to read > (upon initialisation) text from an associated template file > FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. > > I can derive the template filename string for each instance by > doing something like this in the base class (and then not > forgetting to call super() in the __init__() of each derived > class): > > ?class Foo(object): > > ? ? ?def __init__(self): > ? ? ? ? ?self.template_filename = "%s.tmpl" % self.__class__.__name__ > ? ? ? ? ?self.template_body = read_body_from(self.template_filename) > > But, since this information is the same for every instance of > each derived class, I was wondering if there was a way to achieve > the same thing outside of the __init__ function, and just have > these assignments be done as a class attribute (i.e. so that I > can refer to FooA.template_body, etc.) > > I can of course always just hardcode the template filenames in > each derived class, but I am just curious if it can be automated > through some form of introspection. Metaclasses to the rescue!: class WithTemplateAttrs(type): def __new__(cls, name, bases, dct): klass = type.__new__(cls, name, bases, dct) klass.template_filename = "%s.tmpl" % name klass.template_body = read_body_from(klass.template_filename) return klass class Foo(object): __metaclass__ = WithTemplateAttrs #rest of class body here Now just have FooA, FooB, etc. subclass Foo as before. They'll automatically get the attributes generated. Cheers, Chris -- http://blog.rebertia.com From bigblueswope at gmail.com Mon Feb 15 14:54:16 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 14:54:16 -0500 Subject: TypeError Exception in email lib In-Reply-To: References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: On Mon, Feb 15, 2010 at 2:47 PM, BJ Swope wrote: > On Mon, Feb 15, 2010 at 2:31 PM, Stephen Hansen wrote: >> On Mon, Feb 15, 2010 at 10:53 AM, BJ Swope wrote: >>> >>> ?File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz >>> ? ?if data[9] is None: >>> TypeError: 'NoneType' object is unsubscriptable >>> >>> I'm parsing a bunch of spam and using the date field from the spams >>> for a date-time stamp. >>> >>> I've fixed the lib on my box to place the call inside a try/except >>> clause to catch the exception now, but it seems the module has a bug >>> in it. >> >> While there may or may not be a bug in the library, I don't think its where >> you're fixing. Just because an exception occurs in a function doesn't mean >> that function is broken: its documented as accepting a 10 item tuple, only. >> Functions in the stdlib generally -should- throw exceptions on invalid >> input. >> Someone's passing None into it, which its not allowed to do. So -that's- >> where the bug probably is, I think. (Although it may not be the immediate of >> mktime_tz; it could be happening higher up on the stack) >> Advice: Always post complete tracebacks to c.p.l/python-list :) >> --S > > > From the module: > > def mktime_tz(data): > ? ?"""Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" > ? ?if data[9] is None: > ? ? ? # No zone info, so localtime is better assumption than GMT > ? ? ? return time.mktime(data[:8] + (-1,)) > ? ?else: > ? ? ? ?t = time.mktime(data[:8] + (0,)) > ? ? ? ?return t - data[9] - time.timezone > > > It appears that the module is trying to accommodate the potential > missing TZ data because poorly written emails are missing the TZ data. > > I discarded all the crontab emails that had the full traceback in > them. ?I took out the try/except clause in the hopes that I'll get > another exception soon. > > If I do I'll post the entire exception traceback. > Speak of the devil and demons appear... /logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py Parsing of emails for spam at serv1.bigbluenetworks.com failed. Traceback (most recent call last): File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", line 81, in clean_stale_mail() File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", line 24, in clean_stale_mail utc_msg_date = email.utils.mktime_tz(msg_date2) File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz if data[9] is None: TypeError: 'NoneType' object is unsubscriptable def clean_stale_mail(): msg_date1= the_email.get('Date') msg_date2 = email.utils.parsedate_tz(msg_date1) try: utc_msg_date = email.utils.mktime_tz(msg_date2) except OverflowError: M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') return utc_stale_date = time.time() - (86000*stale_days) if utc_msg_date <= utc_stale_date: M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') try: #M = imaplib.IMAP4(HOST) M = imaplib.IMAP4_SSL(HOST) M.login(USER, PASSWD) M.select(MAILBOX) response, msg_list = M.search(None, 'ALL') # response is IMAP response, msg_list is list of Message IDs for msg_id in msg_list[0].split(): #msg_list[0] is a space separated string of message ids response, message = M.fetch(msg_id, '(RFC822)') # response is the IMAP response, message is an RFC222 message msg = email.FeedParser.FeedParser( ) msg.feed(message[0][1]) the_email = msg.close() clean_stale_mail() if the_email.is_multipart(): for part in the_email.walk(): if part.get_content_type() == 'text/html': decoded_part = part.get_payload(decode=1) soup_parse(decoded_part) elif the_email.get_content_type() == 'text/html': decoded_part = the_email.get_payload(decode=1) soup_parse(decoded_part) elif the_email.get_content_type() == 'text/plain': msg_payload = the_email.get_payload() manual_parse(msg_payload) else: continue #print msg_id, "Did't match any defined content types..." #print the_email M.expunge() M.close() M.logout() From phlip2005 at gmail.com Mon Feb 15 14:56:53 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 15 Feb 2010 11:56:53 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> Message-ID: Lacrima wrote: > Thanks for your reply! Isn't what you are talking about integration > tests? And unit tests should be fully isolated? So even for method > 'some_method()' of class A I should mock instance of class A (i.e. to > mock 'self') to test 'some_method()'. "Unit test" is a high-end QA concept. Developers can get the best return on "developer tests". They don't bother with aerospace-quality isolation between units. If a TDD test needs to pull in a bunch of modules to pass, that's generally a good thing, because they all get indirect testing. If they catch a bug, their local tests might not catch it, but the higher level tests still have a chance. (And if your product still needs unit tests, TDD will make them very easy for a formal QA team to add.) However, expensive setup is a design smell. That means if a test case requires too many lines of code for its Assemble phase (before its Activate and Assert phases), then maybe those lines of code support objects that are too coupled, and they need a better design. Throwing mocks at these objects, instead of decoupling them, will "perfume" the design smell, instead of curing it. > > "construction encapsulation") > And could you give an example. def test_frob(self): frob = Frob() frob.knob = Mock() frob.knob.value = Mock(return_value = 42) assert 42 == frob.method_using_knob() We need the mock because we can't control how Frob's constructor built its knob. So instead, give Frob the option to construct with a Knob: def test_frob(self): knob = Knob(42) frob = Frob(knob) assert frob.method_using_knob() Note that in production the Knob constructor never takes a Knob. Maybe we should upgrade the production code too (!), or maybe Knob's constructor should only create a knob if it didn't get passed one. Either technique is acceptable, because the resulting code decouples Frobs and Knobs just a little bit more. > For me it's really hard to develop test first. Often I don't know what > tests to write to replace hardcoded return values by objects that > perform actual work. You have read too many books on TDD. C-: Alternate between writing lines of test and lines of code. Run the tests after the fewest possible edits, and always correctly predict if the tests will pass, or will fail, and with what diagnostic. (And configure your editor to run the stankin tests, no matter how hard it fights you!) The high-end tricks will get easier after you get the basic cycle down. -- Phlip http://c2.com/cgi/wiki?ZeekLand From clp2 at rebertia.com Mon Feb 15 15:04:12 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Feb 2010 12:04:12 -0800 Subject: Talking with ebay using Python In-Reply-To: References: Message-ID: <50697b2c1002151204i487fea42mcba4f7142288a407@mail.gmail.com> On Mon, Feb 15, 2010 at 6:10 AM, starglider develop wrote: > Hi, > I need a way of talking with the eBay API: > Made search, > Ask for item status. > > What can it be done, and where can I get the info. In the future, search Google and PyPI (http://pypi.python.org/pypi). (PyPI is like CPAN for Python.) Here's what I came up with: pyeBay: http://ebaydeveloper.typepad.com/pyebay.html easyBay: http://pypi.python.org/pypi/easyBay/0.1dev They both haven't been updated in a while are are probably unmaintained. I have never used either of these; I have no idea whether they still work. Cheers, Chris -- http://blog.rebertia.com From clp2 at rebertia.com Mon Feb 15 15:17:35 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 15 Feb 2010 12:17:35 -0800 Subject: Talking with ebay using Python In-Reply-To: References: <50697b2c1002151204i487fea42mcba4f7142288a407@mail.gmail.com> Message-ID: <50697b2c1002151217p5a01dfa4x4b3df752d5c412e6@mail.gmail.com> > On 15 February 2010 20:04, Chris Rebert wrote: >> On Mon, Feb 15, 2010 at 6:10 AM, starglider develop >> wrote: >> > Hi, >> > I need a way of talking with the eBay API: >> > Made search, >> > Ask for item status. >> > >> > What can it be done, and where can I get the info. >> >> In the future, search Google and PyPI (http://pypi.python.org/pypi). >> (PyPI is like CPAN for Python.) >> >> Here's what I came up with: >> >> pyeBay: >> http://ebaydeveloper.typepad.com/pyebay.html >> >> easyBay: >> http://pypi.python.org/pypi/easyBay/0.1dev >> >> They both haven't been updated in a while are are probably >> unmaintained. I have never used either of these; I have no idea >> whether they still work. On Mon, Feb 15, 2010 at 12:12 PM, starglider develop wrote: > Thanks for your replay Chris, > but easyBay is no longer available, I had contact the mantainer without > result. > pyebay is new to me but lacks documentations and the output is in XML unlike > easybay the creats a class. Er, easyBay is available. Click one of the file links on its PyPI entry, they work just fine. And in the future, mention the results of any search (i.e. the fact you tried contacting the easyBay dev) in your first message. Cheers, Chris -- http://blog.rebertia.com From chiranjeevi.muttoju at gmail.com Mon Feb 15 15:33:18 2010 From: chiranjeevi.muttoju at gmail.com (chiranjeevi muttoju) Date: Mon, 15 Feb 2010 12:33:18 -0800 (PST) Subject: error: Setup script exited with error: command 'gcc' failed with exit status 1 Message-ID: <0276dd58-9d1a-456d-ab81-33bd241e7d85@t17g2000prg.googlegroups.com> Hi, When i'm trying to install some modules for python i'm getting the fallowing error.. error: Setup script exited with error: command 'gcc' failed with exit status 1 can any one know what it exactly means.. if any body know please reply. i have gcc version 4.1.2 20080704 (Red Hat 4.1.2-46). i'm using python python2.6, some of the modules getting this type of errors are.. mysqldb, and pytc., etc.. if any one know please help me.. Thanks and Regards.. chiranjeevi.muttoju From python at mrabarnett.plus.com Mon Feb 15 15:42:42 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 15 Feb 2010 20:42:42 +0000 Subject: TypeError Exception in email lib In-Reply-To: References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: <4B79B1C2.5040702@mrabarnett.plus.com> BJ Swope wrote: [snip] > > Speak of the devil and demons appear... > > /logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py > > Parsing of emails for spam at serv1.bigbluenetworks.com failed. > > Traceback (most recent call last): > File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", > line 81, in > clean_stale_mail() > File "/logs/python/imap_fetcher/spam_serv1.bigbluenetworks.com.py", > line 24, in clean_stale_mail > utc_msg_date = email.utils.mktime_tz(msg_date2) > File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz > if data[9] is None: > TypeError: 'NoneType' object is unsubscriptable > > > > def clean_stale_mail(): > msg_date1= the_email.get('Date') What is the value of 'msg_date1' at this point? > msg_date2 = email.utils.parsedate_tz(msg_date1) What is the value of 'msg_date2' at this point? The docs say that parsedate_tz() can return a 10-tuple or None. Presumably, if it can't parse the date then it returns None. > try: > utc_msg_date = email.utils.mktime_tz(msg_date2) > except OverflowError: > M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') > return > utc_stale_date = time.time() - (86000*stale_days) > if utc_msg_date <= utc_stale_date: > M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') > [snip] From philip at semanchuk.com Mon Feb 15 15:48:38 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Mon, 15 Feb 2010 15:48:38 -0500 Subject: error: Setup script exited with error: command 'gcc' failed with exit status 1 In-Reply-To: <0276dd58-9d1a-456d-ab81-33bd241e7d85@t17g2000prg.googlegroups.com> References: <0276dd58-9d1a-456d-ab81-33bd241e7d85@t17g2000prg.googlegroups.com> Message-ID: On Feb 15, 2010, at 3:33 PM, chiranjeevi muttoju wrote: > Hi, > When i'm trying to install some modules for python i'm getting the > fallowing error.. > > error: Setup script exited with error: command 'gcc' failed with exit > status 1 > > can any one know what it exactly means.. if any body know please > reply. > i have gcc version 4.1.2 20080704 (Red Hat 4.1.2-46). > i'm using python python2.6, > > some of the modules getting this type of errors are.. mysqldb, and > pytc., etc.. Hi Chiranjeevi, Show us all of the output, please -- everything from where you typed 'setup.py' until the script died. From gallium.arsenide at gmail.com Mon Feb 15 15:59:01 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Mon, 15 Feb 2010 12:59:01 -0800 (PST) Subject: TypeError Exception in email lib References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> Message-ID: <7b6e35aa-2e3c-4983-bc01-8330c3513ee6@j1g2000vbl.googlegroups.com> On Feb 15, 2:54?pm, BJ Swope wrote: > def clean_stale_mail(): > ? ? msg_date1= the_email.get('Date') > ? ? msg_date2 = email.utils.parsedate_tz(msg_date1) > ? ? try: > ? ? ? ? utc_msg_date = email.utils.mktime_tz(msg_date2) > ? ? except OverflowError: > ? ? ? ? M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') > ? ? ? ? return > ? ? utc_stale_date = time.time() - (86000*stale_days) > ? ? if utc_msg_date <= utc_stale_date: > ? ? ? ? M.store(msg_id, '+FLAGS.SILENT', '\\Deleted') It looks like msg_date1 is None. That is, 'Date' is not found in the_email. As Dave Angel said, your "patch" shouldn't fix this problem anyway. Use your patch and put the same problematic input in it to see if it really does fix the problem. (Just to satisfy our morbid curiosity, not really to help you get a true solution.) It looks to me like you have to do something to make clean_stale_mail more robust, rather than focusing on anything in the standard library. John From gallium.arsenide at gmail.com Mon Feb 15 16:03:10 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Mon, 15 Feb 2010 13:03:10 -0800 (PST) Subject: TypeError Exception in email lib References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> <7b6e35aa-2e3c-4983-bc01-8330c3513ee6@j1g2000vbl.googlegroups.com> Message-ID: On Feb 15, 3:59?pm, John Yeung wrote: > It looks to me like you have to do something to make clean_stale_mail > more robust, rather than focusing on anything in the standard library. Let me quickly add: ...or fix whatever calls clean_stale_mail, etc. John From arnodel at googlemail.com Mon Feb 15 16:25:23 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 15 Feb 2010 21:25:23 +0000 Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> Message-ID: John Posner writes: [...] >> x = s[0] [...] > assigns the name *x* to the object that *s[0]* refers to s[0] does not refer to an object, it *is* an object (once evaluated of course, otherwise it's just a Python expression). -- Arnaud From subhakolkata1234 at gmail.com Mon Feb 15 17:04:43 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Mon, 15 Feb 2010 14:04:43 -0800 (PST) Subject: Few Small Questions Regarding CGI Message-ID: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Dear Group, I am trying to learn CGI. I was checking Python Docs. There are multiple modules. Which one to start with? Is there any other material or URL for step by step learning of CGI. My next question is: I want to test it. I have a small personal computer. I have internet but is connected by a service provider. I do not have personal web page. Can I use my personal computer as a client as well as a server? If your kind time permits to answer me these questions, I would be hugely benefited. Wishing you a happy day ahead, Best Regards, Subhabrata. From dino at phidev.org Mon Feb 15 17:12:23 2010 From: dino at phidev.org (Florian Ludwig) Date: Mon, 15 Feb 2010 23:12:23 +0100 Subject: plugin / intra process communication system In-Reply-To: <7tqr9iFbi7U1@mid.uni-berlin.de> References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> Message-ID: <1266271943.4299.2887.camel@brain> On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: > > Here there problem with the trac (and other plugin systems I've > seen) > > approach: > > > > You need to define something like: > > | > > | class IAuthPlugin(Interface): [...] > > | > > in your blog software. > > Why? Any reason you can't define it in a separate package the > blog-software depends on, as well as your wiki? That's actually my point - most plugin systems I've seen, like the one trac uses, are not encouraging you to do so. Having a module that just defines an Interface is kind of weird - and in the real world no one is doing it. > And then of course, this is not really needed. In Python, behavior > counts, not type-information. So you can get away without any explicit > declared interface. You might chose to not do that, for aestetic > reasons, or better documentation. But you aren't forced. Actually some plugin-systems in python do force you and they check if your "implementation" comply with the "interface". Here is one solution I came up with. Based on the earlier example: > > Lets say you program a wiki and like to allow different kind of > > authentications. So you create two plugins (for example one for > > OpenID and one for Shibboleth). > > > > Some time later you feel like reinventing the wheel again and > > you program a blog. Again you like to allow different ways of > > authentication and you already wrote plugins for exactly the > > same for your wiki, right? auth_openid.py - providing the authentication service http://dpaste.com/hold/159619/ wiki.py - providing the wiki http://dpaste.com/hold/159634/ Now putting both together: > import pbus > > import wiki > import auth_openid > # or: import auth_shibboleth > > pbus.get("wiki").run() No interface definitions. What do you think? Any obvious pitfalls (besides reinventing something)? Please keep in mind that syntax/api is not "done" or anything its just an concept presentation. Thanks, Florian -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From bigblueswope at gmail.com Mon Feb 15 17:20:01 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Mon, 15 Feb 2010 17:20:01 -0500 Subject: TypeError Exception in email lib In-Reply-To: <4B79B1C2.5040702@mrabarnett.plus.com> References: <7a9c25c21002151131t212a74baya7f55430be00c09f@mail.gmail.com> <4B79B1C2.5040702@mrabarnett.plus.com> Message-ID: On Mon, Feb 15, 2010 at 3:42 PM, MRAB wrote: > BJ Swope wrote: > [snip] >> >> def clean_stale_mail(): >> ? ?msg_date1= the_email.get('Date') > > What is the value of 'msg_date1' at this point? > >> ? ?msg_date2 = email.utils.parsedate_tz(msg_date1) > > What is the value of 'msg_date2' at this point? > > The docs say that parsedate_tz() can return a 10-tuple or None. > > Presumably, if it can't parse the date then it returns None. > > [snip] > msg_date1: @@DATE msg_date2: None Thanks MRAB, Dave and Stephen! The spam bot didn't populate the date field with anything remotely resembling the date. The @@DATE var was left in the Date header. In reading the module I misunderstood what the "if date[9] is None:" was doing. I'll wrap my calls in a try/except. From dino at phidev.org Mon Feb 15 17:25:31 2010 From: dino at phidev.org (Florian Ludwig) Date: Mon, 15 Feb 2010 23:25:31 +0100 Subject: Plugin architecture In-Reply-To: References: Message-ID: <1266272731.4299.2902.camel@brain> Hi mk, On Mon, 2010-02-15 at 19:43 +0100, mk wrote: > Hello everyone, > > I'm thinking about writing plugin-style architecture for (a new) > web-based app (with SQLAlchemy as backend). > > [...] > > How would you approach designing such architecture using features > available in Python (and some major web framework, like Pylons or Django)? You should really look into the web framework you're using, there probably already is some plugin architecture. But being not content myself with the architectures I've seen or worked with I was looking for some input as well and posted some days back about a similar topic. Maybe some of the thoughts expressed there might help you as well: http://groups.google.com/group/comp.lang.python/browse_thread/thread/0a210267753919b0/5add7bc93789b418 Florian -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From mdekauwe at gmail.com Mon Feb 15 17:26:16 2010 From: mdekauwe at gmail.com (Martin) Date: Mon, 15 Feb 2010 14:26:16 -0800 (PST) Subject: Replace various regex References: <86bba268-1c5b-4a75-bb3c-e09493bab473@z26g2000yqm.googlegroups.com> <7b1fed01-e0bf-4240-bdef-f817996a90d6@d27g2000yqf.googlegroups.com> Message-ID: <1f520615-63df-4923-ba2e-c677e460ac9f@u9g2000yqb.googlegroups.com> On Feb 15, 2:27?pm, Jean-Michel Pichavant wrote: > Martin wrote: > > On Feb 15, 2:03 pm, Jean-Michel Pichavant > > wrote: > > >> Martin wrote: > > >>> Hi, > > >>> I am trying to come up with a more generic scheme to match and replace > >>> a series ofregex, which look something like this... > > >>> 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > >>> 5.0, 4.0, 2.0, 4.0, 1.0 ? ? ?! ?lai(1:npft) > > >>> Ideally match the pattern to the right of the "!" sign (e.g. lai), I > >>> would then like to be able to replace one or all of the corresponding > >>> numbers on the line. So far I have a rather unsatisfactory solution, > >>> any suggestions would be appreciated... > > >>> The file read in is an ascii file. > > >>> f = open(fname, 'r') > >>> s = f.read() > > >>> if CANHT: > >>> ? ? s = re.sub(r"\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+,\d+.\d+ ? ! > >>> canht_ft", CANHT, s) > > >>> where CANHT might be > > >>> CANHT = '115.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft' > > >>> But this involves me passing the entire string. > > >>> Thanks. > > >>> Martin > > >> I remove all lines containing things like 9*0.0 in your file, cause I > >> don't know what they mean and how to handle them. These are not numbers. > > >> import re > > >> replace = { > >> ? ? 'snow_grnd' : (1, '99.99,'), # replace the 1st number by 99.99 > >> ? ? 't_soil' : (2, '88.8,'), # replace the 2nd number by 88.88 > >> ? ? } > > >> testBuffer = """ > >> ?0.749, 0.743, 0.754, 0.759 ?! ?stheta(1:sm_levels)(top to bottom) > >> 0.46 ? ? ? ? ? ? ? ? ? ? ? ? ! ?snow_grnd > >> 276.78,277.46,278.99,282.48 ?! ?t_soil(1:sm_levels)(top to bottom) > >> 19.01,16.38,0.79,1.26,1.00 ? ! ?canht_ft(1:npft) > >> 200.0, 4.0, 2.0, 4.0, 1.0 ! ?lai(1:npft) > >> """ > > >> outputBuffer = '' > >> for line in testBuffer.split('\n'): > >> ? ? for key, (index, repl) in replace.items(): > >> ? ? ? ? if key in line: > >> ? ? ? ? ? ? parameters = { > >> ? ? ? ? ? ? ? ? 'n' : '[\d\.]+', # given you example you have to change > >> this one, I don't know what means 9*0.0 in your file > >> ? ? ? ? ? ? ? ? 'index' : index - 1, > >> ? ? ? ? ? ? } > >> ? ? ? ? ? ? # the following pattern will silently match any digit before > >> the th digit is found, and use a capturing parenthesis for the last > >> ? ? ? ? ? ? pattern = > >> '(\s*(?:(?:%(n)s)[,\s]+){0,%(index)s})(?:(%(n)s)[,\s]+)(.*!.*)' % > >> parameters # regexp are sometimes a nightmare to read > >> ? ? ? ? ? ? line = re.sub(pattern, r'\1 '+repl+r'\3' , line) > >> ? ? ? ? ? ? break > >> ? ? outputBuffer += line +'\n' > > >> print outputBuffer > > > Thanks I will take a look. I think perhaps I was having a very slow > > day when I posted and realised I could solve the original problem more > > efficiently and the problem wasn't perhaps as I first perceived. It is > > enough to match the tag to the right of the "!" sign and use this to > > adjust what lies on the left of the "!" sign. Currently I have > > this...if anyone thinks there is a neater solution I am happy to hear > > it. Many thanks. > > > variable_tag = 'lai' > > variable = [200.0, 60.030, 0.060, 0.030, 0.030] > > > # generate adjustment string > > variable = ",".join(["%s" % i for i in variable]) + ' ! ?' + > > variable_tag > > > # call func to adjust input file > > adjustStandardPftParams(variable, variable_tag, in_param_fname, > > out_param_fname) > > > and the inside of this func looks like this > > > def adjustStandardPftParams(self, variable, variable_tag, in_fname, > > out_fname): > > > ? ? f = open(in_fname, 'r') > > ? ? of = open(out_fname, 'w') > > ? ? pattern_found = False > > > ? ? while True: > > ? ? ? ? line = f.readline() > > ? ? ? ? if not line: > > ? ? ? ? ? ? break > > ? ? ? ? pattern = re.findall(r"!\s+"+variable_tag, line) > > ? ? ? ? if pattern: > > ? ? ? ? ? ? print 'yes' > > ? ? ? ? ? ? print >> of, "%s" % variable > > ? ? ? ?pattern_found = True > > > ? ? ? ? if pattern_found: > > ? ? ? ? ? ? pattern_found = False > > ? ? ? ? else: > > ? ? ? ? ? ? of.write(line) > > > ? ? f.close() > > ? ? of.close() > > > ? ? return > > Are you sure a simple > if variable_tag in line: > ? ? # do some stuff > > is not enough ? > > People will usually prefer to write > > for line in open(in_fname, 'r') : > > instead of your ugly while loop ;-) > > JM My while loop is suitably offended. I have changed it as you suggested...though if I do: if pattern (variable_tag) in line as you suggested i would in my example correctly pick the tag lai, but also one called dcatch_lai, which I wouldn't want. No doubt there is an obvious solution I am again missing! of = open(out_fname, 'w') pattern_found = False for line in open(in_fname, 'r'): pattern = re.findall(r"!\s+"+variable_tag, line) if pattern: print >> of, "%s" % variable pattern_found = True if pattern_found: pattern_found = False else: of.write(line) of.close() Many Thanks. From rhodri at wildebst.demon.co.uk Mon Feb 15 17:53:37 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Mon, 15 Feb 2010 22:53:37 -0000 Subject: MODULE FOR I, P FRAME References: Message-ID: On Sun, 14 Feb 2010 10:07:35 -0000, DANNY wrote: > Hy, first thanks for your response! > Well I am thinkin on coding in MPEG4/10, but I would just encode the > video in that encoding, > then stream it with VLC and save the video file on my disc. Then I > would play it with my player.... I think you're misunderstanding what VLC does here. Saving the video file should preserve format by default; you may be able save it out in YUV format (I don't have a copy on this machine to check), but that will take up ludicrous amounts of disc space and you'd still have to write a byte reader for it. If you do do that, you have lost any chance of knowing whether a frame was an I or P frame in the original format, not that it matters anyway by that point. MPEG-4/10 is hard to write efficient decoders for, and I have to admit I wouldn't do it in Python. You'd be better off writing a wrapper for one of the existing MP4 libraries. -- Rhodri James *-* Wildebeeste Herder to the Masses From gordon at panix.com Mon Feb 15 17:58:03 2010 From: gordon at panix.com (John Gordon) Date: Mon, 15 Feb 2010 22:58:03 +0000 (UTC) Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: In <631b0785-38db-4c12-a82a-7b11e2235e23 at o16g2000prh.googlegroups.com> joy99 writes: > Can I use my personal computer as a client as well as a server? Yes, if you install a web server on your PC. You would then use "localhost" in your browser instead of a standard web address. Assuming you're running Windows, have a look at this page to download the Apache web server: http://mirror.candidhosting.com/pub/apache/httpd/binaries/win32/README.html -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From steve at REMOVE-THIS-cybersource.com.au Mon Feb 15 18:05:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Feb 2010 23:05:39 GMT Subject: how to structure a directory with many scripts and shared code References: Message-ID: <4b79d343$0$8760$c3e8da3@news.astraweb.com> On Mon, 15 Feb 2010 16:29:05 +0100, Benedict Verheyen wrote: > However, when i make a subdirectory, for example database and put a > script in there, how would i import logutils or mailtutils from within > the database subdirectory? This fails: > from tools.logutils import logger Sounds like you need to ensure that the top level directory needs to be added to your PYTHONPATH. Do you need instructions to do this? -- Steven From steve at REMOVE-THIS-cybersource.com.au Mon Feb 15 18:09:59 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 15 Feb 2010 23:09:59 GMT Subject: Modifying Class Object References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> Message-ID: <4b79d447$0$8760$c3e8da3@news.astraweb.com> On Mon, 15 Feb 2010 21:25:23 +0000, Arnaud Delobelle wrote: > John Posner writes: [...] >>> x = s[0] > [...] >> assigns the name *x* to the object that *s[0]* refers to > > s[0] does not refer to an object, it *is* an object (once evaluated of > course, otherwise it's just a Python expression). Precisely. Treated as an expression, that is, as a string being evaluated by the compiler, we would say that it *refers to* an object (unless evaluation fails, in which case it refers to nothing at all). But treated as whatever you get after the compiler is done with it, that is, post- evaluation, we would say that it *is* an object. This subtle distinction is essentially the difference between a label and the thing that is labeled. -- Steven From mattbarkan at gmail.com Mon Feb 15 18:34:35 2010 From: mattbarkan at gmail.com (galileo228) Date: Mon, 15 Feb 2010 15:34:35 -0800 (PST) Subject: Parsing for email addresses Message-ID: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> Hey all, I'm trying to write python code that will open a textfile and find the email addresses inside it. I then want the code to take just the characters to the left of the "@" symbol, and place them in a list. (So if galileo228 at gmail.com was in the file, 'galileo228' would be added to the list.) Any suggestions would be much appeciated! Matt From alfps at start.no Mon Feb 15 18:45:34 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 00:45:34 +0100 Subject: Modifying Class Object In-Reply-To: <4b79d447$0$8760$c3e8da3@news.astraweb.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> <4b79d447$0$8760$c3e8da3@news.astraweb.com> Message-ID: * Steven D'Aprano: > On Mon, 15 Feb 2010 21:25:23 +0000, Arnaud Delobelle wrote: > >> John Posner writes: [...] >>>> x = s[0] >> [...] >>> assigns the name *x* to the object that *s[0]* refers to >> s[0] does not refer to an object, it *is* an object (once evaluated of >> course, otherwise it's just a Python expression). > > Precisely. Treated as an expression, that is, as a string being evaluated > by the compiler, we would say that it *refers to* an object (unless > evaluation fails, in which case it refers to nothing at all). But treated > as whatever you get after the compiler is done with it, that is, post- > evaluation, we would say that it *is* an object. > > This subtle distinction is essentially the difference between a label and > the thing that is labeled. The main differences between a pure functional language where that view can hold and be reasonable, and a language like Python, are that * Python assignments change which object a name refers to, /at runtime/. - Name binding is run time action, not a compile time action. Without run time binding names couldn't be reassigned. s = 1; s = 2 * Some Python objects are modifiable (a.k.a. mutable). - This is particularly important when two or more names refer to the same object and that object is modified. That is, a simple-minded transfer of concepts from pure functional programming to Python breaks down in these cases[1]. I hope this explanation of exactly where the functional programming enthusiasts here go wrong can be of help to readers of the thread, although I've given up hope on those holding the functional programming view (since I'm only human, and even the Gods contend in vain against that sort of thing). Cheers & hth., - Alf Notes: [1] Steven D'Aprano's focus on compilation rather than execution mainly ignores the first point, that a name in given a statement in a loop, say, can refer to different objects in different loop iterations. Happily the Python language specification explains binding as a run-time action. Binding is not a compile time action in Python, it is a run-time action, and can bind a given name in a given statement within the same routine execution, to different objects, and the language specification of course uses the phrase "refers to" to explain the situation after a run time binding. From jgardner at jonathangardner.net Mon Feb 15 18:49:31 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 15 Feb 2010 15:49:31 -0800 (PST) Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> Message-ID: <4fc54d57-cab5-41ee-8546-19e2645b329e@f17g2000prh.googlegroups.com> On Feb 15, 3:34?pm, galileo228 wrote: > > I'm trying to write python code that will open a textfile and find the > email addresses inside it. I then want the code to take just the > characters to the left of the "@" symbol, and place them in a list. > (So if galileo... at gmail.com was in the file, 'galileo228' would be > added to the list.) > > Any suggestions would be much appeciated! > You may want to use regexes for this. For every match, split on '@' and take the first bit. Note that the actual specification for email addresses is far more than a single regex can handle. However, for almost every single case out there nowadays, a regex will get what you need. From jgardner at jonathangardner.net Mon Feb 15 18:52:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 15 Feb 2010 15:52:19 -0800 (PST) Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: <6f343cb9-fc6c-40d8-ad70-7e02851857ad@k2g2000pro.googlegroups.com> On Feb 15, 2:04?pm, joy99 wrote: > > I am trying to learn CGI. I was checking Python Docs. There are > multiple modules. Which one to start with? > Is there any other material or URL for step by step learning of CGI. > I would suggest skipping 15 years of internet progress and going with a more modern framework. I recommend Pylons, although Django and web.py are not bad. > My next question is: > I want to test it. I have a small personal computer. I have internet > but is connected by a service provider. I do not have personal web > page. Can I use my personal computer as a client as well as a server? > Yes. The nature of the internet means anyone that connects can be a client or a server or both at the same time. Heck, you don't even need to have a connection to the internet. Just play with 127.0.0.1, which points right back to the same machine you're running on. I do this all the time for developing and testing out websites or change to websites I work on. From jgardner at jonathangardner.net Mon Feb 15 18:55:05 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 15 Feb 2010 15:55:05 -0800 (PST) Subject: Time out a regular expression in Python 2.6.4? References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: On Feb 15, 7:59?am, Steve Holden wrote: > pyt... at bdurham.com wrote: > > Is there any way to time out a regular expression in Python 2.6.4? > > > Motiviation: Our application allows users to enter regular expressions > > as validation criteria. If a user enters a pathological regular > > expression, we would like to timeout the evaluation of this expression > > after a short period of time. > > Python itself does not contain any mechanism to terminate an operation > if it takes too much time. > > One approach would be to run the regex in a subprocess, and apply > process limits to terminate that subprocess if it ran too long. > > This group being what it is you are likely to receive other, better > suggestions too. > I'm not sure how exactly the re module is implemented, but since I assume a great chunk is in C code, you may get away with a single process and multiple threads. One thread will watch the process, or have a timer event set to go off at a certain point. The other will actually run the regex and get killed by the timer process if it doesn't finish in time. From news123 at free.fr Mon Feb 15 19:04:28 2010 From: news123 at free.fr (News123) Date: Tue, 16 Feb 2010 01:04:28 +0100 Subject: listing existing windows services with python Message-ID: <4b79e10c$0$30277$426a74cc@news.free.fr> Hi, What is the best way with python to get a list of all windows services. As a start I would be glad to receive only the service names. However it would be nicer if I could get all the properties of a service as well. Thanks for any info and bye N From news123 at free.fr Mon Feb 15 19:10:51 2010 From: news123 at free.fr (News123) Date: Tue, 16 Feb 2010 01:10:51 +0100 Subject: How to use python to register a service (an existing .exe file) Message-ID: <4b79e28c$0$4610$426a74cc@news.free.fr> Hi, Is there a python way to register new windows services. I am aware of the instsrv.exe program, which can be used to install services. I could use subprocess.Popen to call instsrv.exe "service_name" program.exe but wondered, whether there's already an existing function. Thans in advance and bye N From ben+python at benfinney.id.au Mon Feb 15 19:17:13 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 11:17:13 +1100 Subject: Which mock library do you prefer? References: Message-ID: <87eikmc9va.fsf@benfinney.id.au> Lacrima writes: > Minimock has wider usage and community, but I have some troubles using > it. Maybe I am wrong, but with minimock you always have to keep track > the order of imports in your test modules. Well, may be I just don't > understand fully how minimock works. I'm not sure why you think you need to keep track of the order of imports. Simply set up the mocks as you want them, in your fixtures; then, when tearing down your fixtures, use ?minimock.restore()? to restore the affected namespaces to their initial state. -- \ ?? one of the main causes of the fall of the Roman Empire was | `\ that, lacking zero, they had no way to indicate successful | _o__) termination of their C programs.? ?Robert Firth | Ben Finney From alfps at start.no Mon Feb 15 19:17:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 01:17:31 +0100 Subject: listing existing windows services with python In-Reply-To: <4b79e10c$0$30277$426a74cc@news.free.fr> References: <4b79e10c$0$30277$426a74cc@news.free.fr> Message-ID: * News123: > Hi, > > > What is the best way with python to get a list of all windows services. > > As a start I would be glad to receive only the service names. > > However it would be nicer if I could get all the properties of a service > as well. > > Thanks for any info and bye * Library: If there is some existing library for that (just search the web) then that would probably be the easiest. * Registry functions: Otherwise, I'd use the general registry access functions. Info about the registry access functions is available in your Python docs. All the information about services is in the Windows registry (documented in the MSDN Library, which is available in a browsable on-line version at Microsoft). * Text-oriented commands: An alternative to using the registry access functions is to capture the output of e.g. the 'sc' command. The 'net' command also has some functionality related to services, e.g. 'net start'. Cheers & hth., - Alf From jjposner at optimum.net Mon Feb 15 19:33:19 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 15 Feb 2010 19:33:19 -0500 Subject: Modifying Class Object In-Reply-To: <4b79d447$0$8760$c3e8da3@news.astraweb.com> References: <8e6f2d9a-13a8-45f4-b1d1-52b093862237@s36g2000prf.googlegroups.com> <4b7773c6$0$8767$c3e8da3@news.astraweb.com> <8a6b1b50-a353-41fa-b152-b635ab1d7bc9@k6g2000prg.googlegroups.com> <4b77867d$0$8767$c3e8da3@news.astraweb.com> <0bebc4fe-ca6c-4f73-ba6c-0bb44fe06fc3@a5g2000prg.googlegroups.com> <4b77a488$0$8767$c3e8da3@news.astraweb.com> <4b781297$0$8767$c3e8da3@news.astraweb.com> <8043a841-b814-47a7-914e-dd25944d1d7e@q2g2000pre.googlegroups.com> <4b799f4a$0$4980$607ed4bc@cv.net> <4b79d447$0$8760$c3e8da3@news.astraweb.com> Message-ID: <4B79E7CF.3050805@optimum.net> On 2/15/2010 6:09 PM, Steven D'Aprano wrote: > On Mon, 15 Feb 2010 21:25:23 +0000, Arnaud Delobelle wrote: > >> John Posner writes: [...] >>>> x = s[0] >> [...] >>> assigns the name *x* to the object that *s[0]* refers to >> >> s[0] does not refer to an object, it *is* an object (once evaluated of >> course, otherwise it's just a Python expression). > > Precisely. Treated as an expression, that is, as a string being evaluated > by the compiler, we would say that it *refers to* an object (unless > evaluation fails, in which case it refers to nothing at all). But treated > as whatever you get after the compiler is done with it, that is, post- > evaluation, we would say that it *is* an object. > > This subtle distinction is essentially the difference between a label and > the thing that is labeled. Is this your only quibble with my writeup? If, so, I'm gratified. And your objections make perfect sense. Still, I'll attempt to justify my phrasing. I was originally going to write: assigns the name *x* to the object that THE NAME *s[0]* refers to ... but I didn't want to start a distracting argument on the use of the phrase *the name* to describe the 4-char string *s[0]*. So now I'll try to (briefly) make my case. Yes, it might be more correct to say that *s[0]* is an expression (equivalent to the more obvious expression *s.__getitem__(0)*). But in common usage, the 4-char string *s[0]* _behaves_ like a name. If you accept this viewpoint, the story on Python assignment statements becomes quite simple ... Syntactic sugar aside, there are only two kinds of assignment statements: 1. NAME = EXPRESSION The EXPRESSION creates a new object, and the NAME is assigned to that object. Examples: x = x + 1 obj = MyClass(1, 2, "red") mywordlist = mysentence.split() 2. NAME2 = NAME1 No new object is created. NAME2 becomes another name (an "alias") for the existing object that currently has NAME1 assigned to it. Examples: y = x s[0] = s[42] mydict["spamwich"] == this_sandwich obj.color = MYCOLORS.LTGREEN This viewpoint might fail in advanced areas of Python programming: properties/descriptors, double-underscore methods, etc. But in my own day-to-day usage (admittedly, I'm a hobbyist Python programmer, not a professional), it's never failed me to think this way: * A dict is a collection of user-devised names, each of which is assigned to an object. * A list/tuple is an interpreter-maintained collection of integer names (0, 1, 2, ...), each of which is assigned to an object. * A class instance is very much like a dict. Tx, John From python.list at tim.thechases.com Mon Feb 15 19:35:21 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 15 Feb 2010 18:35:21 -0600 Subject: Parsing for email addresses In-Reply-To: <4fc54d57-cab5-41ee-8546-19e2645b329e@f17g2000prh.googlegroups.com> References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <4fc54d57-cab5-41ee-8546-19e2645b329e@f17g2000prh.googlegroups.com> Message-ID: <4B79E849.7060905@tim.thechases.com> Jonathan Gardner wrote: > On Feb 15, 3:34 pm, galileo228 wrote: >> I'm trying to write python code that will open a textfile and find the >> email addresses inside it. I then want the code to take just the >> characters to the left of the "@" symbol, and place them in a list. >> (So if galileo... at gmail.com was in the file, 'galileo228' would be >> added to the list.) >> >> Any suggestions would be much appeciated! >> > > You may want to use regexes for this. For every match, split on '@' > and take the first bit. > > Note that the actual specification for email addresses is far more > than a single regex can handle. However, for almost every single case > out there nowadays, a regex will get what you need. You can even capture the part as you find the regexps. As Jonathan mentions, finding RFC-compliant email addresses can be a hairy/intractable problem. But you can get a pretty close approximation: import re r = re.compile(r'([-\w._+]+)@(?:[-\w]+\.)+(?:\w{2,5})', re.I) # ^ # if you want to allow local domains like # user at localhost # then change the "+" marked with the "^" # to a "*" and the "{2,5}" to "+" to unlimit # the TLD. This will change the outcome # of the last test "jim at com" to True for test, expected in ( ('jim at example.com', True), ('jim at sub.example.com', True), ('@example.com', False), ('@sub.example.com', False), ('@com', False), ('jim at com', False), ): m = r.match(test) if bool(m) ^ expected: print "Failed: %r should be %s" % (test, expected) emails = set() for line in file('test.txt'): for match in r.finditer(line): emails.add(match.group(1)) print "All the emails:", print ', '.join(emails) -tkc From mwilson at the-wire.com Mon Feb 15 19:36:55 2010 From: mwilson at the-wire.com (Mel) Date: Mon, 15 Feb 2010 19:36:55 -0500 Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: joy99 wrote: > Dear Group, > > I am trying to learn CGI. I was checking Python Docs. There are > multiple modules. Which one to start with? > Is there any other material or URL for step by step learning of CGI. > > My next question is: > I want to test it. I have a small personal computer. I have internet > but is connected by a service provider. I do not have personal web > page. Can I use my personal computer as a client as well as a server? A server can be as simple as: #!/usr/bin/env python # -*- coding: ASCII -*- '''Simple CGI server in Python $Id$''' import getopt, os, sys from BaseHTTPServer import HTTPServer from CGIHTTPServer import CGIHTTPRequestHandler port = 8000 opts, args = getopt.getopt (sys.argv[1:], 'd:p:', ['www=', 'port=']) for o, v in opts: if o in ['-d', '--www']: os.chdir (v) elif o in ('-p', '--port'): port = int (v) handler = HTTPServer (('', port), CGIHTTPRequestHandler) handler.serve_forever() If you run this like mycgiserver.py --www=my_www_dir and put your web pages under my_www_dir, and your CGI programs under my_www_dir/cgi-bin then pointing your browser to will show you your site. Mel. From ben+python at benfinney.id.au Mon Feb 15 20:01:03 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 12:01:03 +1100 Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> Message-ID: <87aavac7u8.fsf@benfinney.id.au> galileo228 writes: > I'm trying to write python code that will open a textfile and find the > email addresses inside it. I then want the code to take just the > characters to the left of the "@" symbol, and place them in a list. Email addresses can have more than one ?@? character. In fact, the quoting rules allow the local-part to contain *any ASCII character* and remain valid. > Any suggestions would be much appeciated! For a brief but thorough treatment of parsing email addresses, see RFC 3696, ?Application Techniques for Checking and Transformation of Names? , specifically section 3. -- \ ?What I have to do is see, at any rate, that I do not lend | `\ myself to the wrong which I condemn.? ?Henry Thoreau, _Civil | _o__) Disobedience_ | Ben Finney From steve at holdenweb.com Mon Feb 15 20:06:08 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 20:06:08 -0500 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: Jonathan Gardner wrote: > On Feb 15, 7:59 am, Steve Holden wrote: >> pyt... at bdurham.com wrote: >>> Is there any way to time out a regular expression in Python 2.6.4? >>> Motiviation: Our application allows users to enter regular expressions >>> as validation criteria. If a user enters a pathological regular >>> expression, we would like to timeout the evaluation of this expression >>> after a short period of time. >> Python itself does not contain any mechanism to terminate an operation >> if it takes too much time. >> >> One approach would be to run the regex in a subprocess, and apply >> process limits to terminate that subprocess if it ran too long. >> >> This group being what it is you are likely to receive other, better >> suggestions too. >> > > I'm not sure how exactly the re module is implemented, but since I > assume a great chunk is in C code, you may get away with a single > process and multiple threads. One thread will watch the process, or > have a timer event set to go off at a certain point. The other will > actually run the regex and get killed by the timer process if it > doesn't finish in time. That would be a great idea if it were possible to kill a thread form outside. Unfortunately it's not, so the best you can do is set a flag and have it queried periodically. This is not practical during re matching. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From python at mrabarnett.plus.com Mon Feb 15 20:37:33 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 16 Feb 2010 01:37:33 +0000 Subject: Time out a regular expression in Python 2.6.4? In-Reply-To: References: <1266248602.28792.1360069669@webmail.messagingengine.com> Message-ID: <4B79F6DD.6060207@mrabarnett.plus.com> Steve Holden wrote: > Jonathan Gardner wrote: >> On Feb 15, 7:59 am, Steve Holden wrote: >>> pyt... at bdurham.com wrote: >>>> Is there any way to time out a regular expression in Python >>>> 2.6.4? Motiviation: Our application allows users to enter >>>> regular expressions as validation criteria. If a user enters a >>>> pathological regular expression, we would like to timeout the >>>> evaluation of this expression after a short period of time. >>> Python itself does not contain any mechanism to terminate an >>> operation if it takes too much time. >>> >>> One approach would be to run the regex in a subprocess, and apply >>> process limits to terminate that subprocess if it ran too long. >>> >>> This group being what it is you are likely to receive other, >>> better suggestions too. >>> >> I'm not sure how exactly the re module is implemented, but since I >> assume a great chunk is in C code, you may get away with a single >> process and multiple threads. One thread will watch the process, or >> have a timer event set to go off at a certain point. The other >> will actually run the regex and get killed by the timer process if >> it doesn't finish in time. > > That would be a great idea if it were possible to kill a thread form > outside. Unfortunately it's not, so the best you can do is set a flag > and have it queried periodically. This is not practical during re > matching. > The code for matching in the re module is written in C, and it doesn't release the GIL because it calls the Python API, and you need to have the GIL when doing that (unless you can guarantee that the specific call is safe, that is!). This means that other threads can't run during matching. In order to be able to cancel the matching, the re module would have to release the GIL when possible and have some kind of cancel() method (belonging to which class?). A simpler option would be to add a timeout argument. It already periodically checks for ctrl-C, so perhaps the time check could be done then. From wuwei23 at gmail.com Mon Feb 15 21:16:19 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Feb 2010 18:16:19 -0800 (PST) Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> Message-ID: <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> News123 wrote: > What is the best way with python to get a list of all windows services. > > As a start I would be glad to receive only the service names. > > However it would be nicer if I could get all the properties of a service > as well. I highly recommend Tim Golden's fantastic WMI module[1]. >>> import wmi >>> c = wmi.WMI() >>> services = c.Win32_Service() >>> s = services[0] >>> s <_wmi_object: \\LIB-D5NYF1S\root \cimv2:Win32_Service.Name="Alerter"> >>> s.properties {u'DisplayName': None, u'ServiceSpecificExitCode': None, u'State': None, u'Syste mName': None, u'ErrorControl': None, u'Status': None, u'ProcessId': None, u'Desc ription': None, u'Started': None, u'AcceptStop': None, u'CheckPoint': None, u'Pa thName': None, u'WaitHint': None, u'Name': None, u'InstallDate': None, u'Caption ': None, u'StartMode': None, u'DesktopInteract': None, u'ServiceType': None, u'T agId': None, u'StartName': None, u'AcceptPause': None, u'CreationClassName': Non e, u'SystemCreationClassName': None, u'ExitCode': None} >>> s.Name u'Alerter' >>> s.Started False >>> s.ServiceType u'Share Process' 1: http://timgolden.me.uk/python/wmi/index.html From shane_k_mcintyre at yahoo.com Mon Feb 15 21:19:27 2010 From: shane_k_mcintyre at yahoo.com (Shane McIntyre) Date: Mon, 15 Feb 2010 18:19:27 -0800 (PST) Subject: Web Service Using XML for input and output Message-ID: <682170.95799.qm@web57515.mail.re1.yahoo.com> I'm attempting to use a web service that takes XML as an input and returns an XML output.? I can connect to the service and attempt to pass in the XML but do not get any results. I believe my problem is how to package up the XML and send it in the request.? The XML consists of about 20 tag/value pairs. Any code snippets or a place to look for some examples would be appreciated.? I'm currently trying to use an HTTPConnection with the XML as a parameter in the request. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at holdenweb.com Mon Feb 15 21:38:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Mon, 15 Feb 2010 21:38:35 -0500 Subject: Web Service Using XML for input and output In-Reply-To: <682170.95799.qm@web57515.mail.re1.yahoo.com> References: <682170.95799.qm@web57515.mail.re1.yahoo.com> Message-ID: Shane McIntyre wrote: > I'm attempting to use a web service that takes XML as an input and > returns an XML output. I can connect to the service and attempt to pass > in the XML but do not get any results. I believe my problem is how to > package up the XML and send it in the request. The XML consists of > about 20 tag/value pairs. Any code snippets or a place to look for some > examples would be appreciated. I'm currently trying to use an > HTTPConnection with the XML as a parameter in the request. > Well, one could fatuously point out that you must be doing it wrong, but without seeing your code it's difficult to know exactly *how* you are going wrong. For all I know your current attempt at solution might require only minimal changes to make it work. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From alfps at start.no Mon Feb 15 22:28:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 04:28:25 +0100 Subject: listing existing windows services with python In-Reply-To: <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: * alex23: > News123 wrote: >> What is the best way with python to get a list of all windows services. >> >> As a start I would be glad to receive only the service names. >> >> However it would be nicer if I could get all the properties of a service >> as well. > > I highly recommend Tim Golden's fantastic WMI module[1]. It's probably Very Good, but one Microsoft-thing one should be aware of: using WMI functionality generally starts up a background WMI service... Similarly, starting the standard clipboard viewer (discontinued in Windows Vista) starts up a silly copy-clipboard-contents-over-network service. On a low-range machine the WMI service can be a resource concern. I don't know whether the WMI service is a security concern (it probably is, considering IIS and anything Microsoft+Network and that WMI is meant to administrate machines over network, it's an enterprise thing not a personal computer user thing), but the clipboard service is, as I recall, a concern. > >>> import wmi > >>> c = wmi.WMI() > >>> services = c.Win32_Service() > >>> s = services[0] > >>> s > <_wmi_object: \\LIB-D5NYF1S\root > \cimv2:Win32_Service.Name="Alerter"> > >>> s.properties > {u'DisplayName': None, u'ServiceSpecificExitCode': None, u'State': > None, u'Syste > mName': None, u'ErrorControl': None, u'Status': None, > u'ProcessId': None, u'Desc > ription': None, u'Started': None, u'AcceptStop': None, > u'CheckPoint': None, u'Pa > thName': None, u'WaitHint': None, u'Name': None, u'InstallDate': > None, u'Caption > ': None, u'StartMode': None, u'DesktopInteract': None, > u'ServiceType': None, u'T > agId': None, u'StartName': None, u'AcceptPause': None, > u'CreationClassName': Non > e, u'SystemCreationClassName': None, u'ExitCode': None} > >>> s.Name > u'Alerter' > >>> s.Started > False > >>> s.ServiceType > u'Share Process' > > 1: http://timgolden.me.uk/python/wmi/index.html Cheers, - Alf From wingusr at gmail.com Mon Feb 15 22:42:15 2010 From: wingusr at gmail.com (TP) Date: Mon, 15 Feb 2010 19:42:15 -0800 Subject: Am I using ctypes correctly? Where are fprints going? Message-ID: >From the Cplusplus-sig, I gathered that instead of Boost.Python I should use ctypes for the following problem. But let me make sure I'm using it correctly. I am calling the C Leptonica Image Processing C Library (http://leptonica.com) from python. Within its leptprotos.h file are functions like this: extern PIX * pixRead ( const char *filename ); extern void pixDestroy ( PIX **ppix ); Using Windows XP, and within a Command Prompt I do this: python26 >>> import ctypes >>> leptonica = ctypes.cdll.leptonlib >>> pixRead = leptonica.pixRead >>> pix=ctypes.c_void_p() >>> pix.value = pixRead(r"test.tif") >>> pix c_void_p(12310144) >>> leptonica.pixGetWidth(pix) 1553 #this is the correct width >>> leptonica.pixDestroy(ctypes.byref(pix)) >>> pix c_void_p(None) #This look right, pixDestroy() sets the pointer to NULL. Is this the proper way you are supposed to supply the address of a pointer that is returned by a C function? Is there a better way? Should I have done the following also? >>> pixRead.restype = ctypes.c_void_p >>> pixDestroy.restype = None Now that the pix has been destroyed, you shouldn't be able to get its width: >>> leptonica.pixGetWidth(pix) -1 This is correct but there also should have been an error message printed out. The C library is doing this (I think, I haven't actually used the debugger on it): sprintf(charbuf, "Error in %s: %s\n", procname, msg); fprintf(stderr, charbuf, ival); But I don't see any error message appear in my console window? Finally, the documentation states for ctypes.util.find_msvcrt(): Windows only: return the filename of the VC runtype library used by Python, and by the extension modules. If the name of the library cannot be determined, None is returned. If you need to free memory, for example, allocated by an extension module with a call to the free(void *), it is important that you use the function in the same library that allocated the memory. >>> import ctypes.util >>> ctypes.util.find_msvcrt() 'msvcr90.dll' Does this mean that if I build a Debug version of the Leptonica DLL (which will use the Debug version of the runtime library, msvcr90d.dll), that I also have to build and use a Debug version of Python26? I tried using leptonlibd.dll with the ActiveState release version of Python26 and didn't see any immediate error. From ldo at geek-central.gen.new_zealand Mon Feb 15 23:22:49 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 16 Feb 2010 17:22:49 +1300 Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: In message <631b0785-38db-4c12- a82a-7b11e2235e23 at o16g2000prh.googlegroups.com>, joy99 wrote: > Is there any other material or URL for step by step learning of CGI. There?s the official spec here . From brian.curtin at gmail.com Mon Feb 15 23:50:26 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Mon, 15 Feb 2010 22:50:26 -0600 Subject: How to use python to register a service (an existing .exe file) In-Reply-To: <4b79e28c$0$4610$426a74cc@news.free.fr> References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: On Mon, Feb 15, 2010 at 18:10, News123 wrote: > Hi, > > Is there a python way to register new windows services. > > > I am aware of the > instsrv.exe program, which can be used to install services. > I could use subprocess.Popen to call > > > instsrv.exe "service_name" program.exe > > > but wondered, whether there's already an existing function. > > Thans in advance and bye > > > N > There is nothing like that in the stdlib, so calling instserv via Popen may be your best bet. "sc create" may also be helpful to you. -------------- next part -------------- An HTML attachment was scrubbed... URL: From chuckmcknight at gmail.com Tue Feb 16 00:00:39 2010 From: chuckmcknight at gmail.com (Charles McKnight) Date: Mon, 15 Feb 2010 21:00:39 -0800 (PST) Subject: TkTable and Python 3.1 Message-ID: HI All, I'm fiddling around with Python and I'm trying to get tktable to work with Python 3.1 on Apple OS X 10.6 (Snow Leopard). Has anyone successfully accomplished this task, and if so, can you share how that you got it working? I've got Darwin Ports installed (current version) and I'm using Python 3.1 (ports), Tcl/Tk 8.5 (ports) and I've installed TkTable 2.10 (ports). Somehow, I've missed doing something because the Python interpreter can't seem to find the tktable module. Thanks in advance! Chuck From brian.curtin at gmail.com Tue Feb 16 00:13:45 2010 From: brian.curtin at gmail.com (Brian Curtin) Date: Mon, 15 Feb 2010 23:13:45 -0600 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> Message-ID: On Mon, Feb 15, 2010 at 18:17, Alf P. Steinbach wrote: > * News123: > > Hi, >> >> >> What is the best way with python to get a list of all windows services. >> >> As a start I would be glad to receive only the service names. >> >> However it would be nicer if I could get all the properties of a service >> as well. >> >> Thanks for any info and bye >> > > > * Registry functions: > > Otherwise, I'd use the general registry access functions. > > Info about the registry access functions is available in your Python docs. > > All the information about services is in the Windows registry (documented > in > the MSDN Library, which is available in a browsable on-line version at > Microsoft). > As for doing this via the registry, take a look at the EnumKey and EnumValue functions of the winreg module (_winreg in 2.x). HKLM\System\CurrentControlSet\Services contains service information, and iterating over that should get a lot of what's needed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From wuwei23 at gmail.com Tue Feb 16 00:43:25 2010 From: wuwei23 at gmail.com (alex23) Date: Mon, 15 Feb 2010 21:43:25 -0800 (PST) Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: On Feb 16, 1:28?pm, "Alf P. Steinbach" wrote: > It's probably Very Good, but one Microsoft-thing one should be aware of: using > WMI functionality generally starts up a background WMI service... "Probably"? You haven't even used the module but you felt the need to contribute anyway? And I see that my suggestion is "probably" a security concern too. Would it be too much to ask for you to provide something other than unrelated anecdotes as evidence to support these claims? Or perhaps produce an alternative solution[1] for the OP instead of shitting over a working solution? So you chose to post to share your vague unsubstantiated concerns while offering the sterling advice that a developer need be familiar with a system in order to be aware of the costs in using it. Clearly time well spent by all. 1: http://essiene.blogspot.com/2005/04/python-windows-services.html From alfps at start.no Tue Feb 16 01:04:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 07:04:32 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: * alex23: > On Feb 16, 1:28 pm, "Alf P. Steinbach" wrote: >> It's probably Very Good, but one Microsoft-thing one should be aware of: using >> WMI functionality generally starts up a background WMI service... > > "Probably"? That means that since you say it's fantastic, it's probably very good. "Probably" is a way to qualify the statement. Based on your earlier and current quite emotional mode of expression I wouldn't take your word for an evaluation. > You haven't even used the module but you felt the need to > contribute anyway? Yes, since I did not contribute about the module, but rather about the functionality that it uses, which you didn't mention in your otherwise excellent reply to the OP. > And I see that my suggestion is "probably" a security concern too. Yeah. It has nothing to do with the module, though. Only with Microsoft's WMI. > Would it be too much to ask for you to provide > something other than unrelated anecdotes as evidence to support these > claims? Google it. E.g. . Other words and search engines might turn up other things, but the description of not a security "hole" but a security "crater" seems to me to indicate that it's not 100% secure. > Or perhaps produce an alternative solution[1] for the OP > instead of shitting over a working solution? Oh yes, the confusion that technical facts are somehow an expression of personal feelings and social matters, and can be chosen as one pleases, hence, that providing a fact or pointing out a possibility that is unwanted, is "shitting". From my point of view that's stupid. But I also think that apart from your "shitting" on me (and there the analogy is more apt, it's not about technical facts) it's great that you provide the kind of help that you did, pointing out a probably very good module that it seems gives the required functionality, and giving an URL. [snip further speculative insults] Cheers & hth., - Alf From wolftracks at invalid.com Tue Feb 16 01:42:04 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 15 Feb 2010 22:42:04 -0800 Subject: Looking for a Compiled Demo of MPL (matplotlib) Graphics Message-ID: Does anyone know where I can find a compiled demo that uses MPL graphics? I'd like, if possible, a Win version whose size is less than 10M, so that I can send it via e-mail, if necessary. It should use plot, so that someone can manipulate the plot with the navigation controls. At this point, I have no idea if that method is the fundamental graph tool or not. I suspect it is. If a mailable demo isn't available, maybe there's a web site that one can download such examples from? From timr at probo.com Tue Feb 16 01:58:17 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 15 Feb 2010 22:58:17 -0800 Subject: Few Small Questions Regarding CGI References: <631b0785-38db-4c12-a82a-7b11e2235e23@o16g2000prh.googlegroups.com> Message-ID: joy99 wrote: > >I am trying to learn CGI. I was checking Python Docs. There are >multiple modules. Which one to start with? Well, it seems to me that the first place to start is the built-in CGI module, in "cgi.py". I'm not aware of any other CGI-based modules in the standard library. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From danijel.gvero at gmail.com Tue Feb 16 02:14:32 2010 From: danijel.gvero at gmail.com (DANNY) Date: Mon, 15 Feb 2010 23:14:32 -0800 (PST) Subject: MODULE FOR I, P FRAME References: Message-ID: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> On Feb 16, 12:53?am, "Rhodri James" wrote: > On Sun, 14 Feb 2010 10:07:35 -0000, DANNY wrote: > > Hy, first thanks for your response! > > Well I am thinkin on coding in MPEG4/10, but I would just encode the > > video in that encoding, > > then stream it with VLC and save the video file on my disc. Then I > > would play it with my player.... > > I think you're misunderstanding what VLC does here. ?Saving the video file ? > should preserve format by default; you may be able save it out in YUV ? > format (I don't have a copy on this machine to check), but that will take ? > up ludicrous amounts of disc space and you'd still have to write a byte ? > reader for it. ?If you do do that, you have lost any chance of knowing ? > whether a frame was an I or P frame in the original format, not that it ? > matters anyway by that point. > > MPEG-4/10 is hard to write efficient decoders for, and I have to admit I ? > wouldn't do it in Python. ?You'd be better off writing a wrapper for one ? > of the existing MP4 libraries. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses Hm, well I see that and now I am thinking of using reference software for MPEG4/10 which is written in c++ http://iphome.hhi.de/suehring/tml/ just to use it as a decoder on my client side, save the file in that format and then play it in my player using pyffmpeg http://code.google.com/p/pyffmpeg/ and just manipulate frames in that clip-I think that could be possible....am I right? Thanks for your help! From peloko45 at gmail.com Tue Feb 16 03:16:01 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 16 Feb 2010 00:16:01 -0800 (PST) Subject: Union of class variables Message-ID: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> Is possible to get a third class with the class variables of another two classes? -------- class A: foo = 1 class B: bar = 2 -------- From benedict.verheyen at gmail.com Tue Feb 16 03:28:12 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Tue, 16 Feb 2010 09:28:12 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4b79d343$0$8760$c3e8da3@news.astraweb.com> References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Mon, 15 Feb 2010 16:29:05 +0100, Benedict Verheyen wrote: > >> However, when i make a subdirectory, for example database and put a >> script in there, how would i import logutils or mailtutils from within >> the database subdirectory? This fails: >> from tools.logutils import logger > > Sounds like you need to ensure that the top level directory needs to be > added to your PYTHONPATH. > > Do you need instructions to do this? > Hi Steve, thanks, i think i know how to add the top level directory to the PYTHONPATH. I'm however looking further into the suggestion of ssteinerX to use a setup.py file to add the tools utility scripts to the pythonpath. In the near future, another person will be helping me with programming and thus, i want to make sure the structure is usable by other people than myself. Furthermore, i'm thinking if it wouldn't be cleaner to make such a setup.py file per script, at least the bigger, more important scripts. Now my structure is like this: python_scripts | |-->trunk ......|-----> all scripts ......|-----> tools The python_scripts directory and subdirs are versioned via SVN. I think these steps would help: 1. Make a package of tools. 2. Put the bigger scripts in a seperate directory also using a setup.py file. 3. If possible, put the other scripts that somehow belong together in a seperate directory. Names need to be more clear but i'm just illustrating a point. python_scripts | |-->trunk ......|-----> my big script 1 ................|-----> setup.py ......|-----> my big script 2 ................|-----> setup.py ......|-----> database ................|-----> database script 1 ................|-----> database script 2 ......|-----> tools ................|-----> setup.py Does that look like a clear structure? Thanks, Benedict From wuwei23 at gmail.com Tue Feb 16 03:38:00 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Feb 2010 00:38:00 -0800 (PST) Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: "Alf P. Steinbach" wrote: > it's great that you provide the kind > of help that you did, pointing out a probably very good module that it seems > gives the required functionality, and giving an URL. Yes, because that's _actually helping people_ and not just contributing the usual self-serving pontificating nonsense that just _flows_ from your goddamn mouth like a river of effluent psuedotruths. If you really wanted to help you would've cited _actual security flaws_ in your first response to me, instead of hand waving us away to once again do the leg work of verification. Based on your postings here, you regularly don't have the time or inclination to back up some of the bizarre claims you make. It would actually improve the signal in this channel a lot if you just chose not to make those posts at all. From wuwei23 at gmail.com Tue Feb 16 03:40:22 2010 From: wuwei23 at gmail.com (alex23) Date: Tue, 16 Feb 2010 00:40:22 -0800 (PST) Subject: Union of class variables References: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> Message-ID: <0ab616a3-f507-487e-abb5-be0929d05117@f17g2000prh.googlegroups.com> On Feb 16, 6:16?pm, Joan Miller wrote: > Is possible to get a third class with the class variables of another > two classes? > > -------- > class A: > ? ? foo = 1 > > class B: > ? ? bar = 2 > -------- Through multiple inheritance? >>> class C(A, B): ... pass ... >>> C.foo 1 >>> C.bar 2 From alfps at start.no Tue Feb 16 03:52:37 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 09:52:37 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: * alex23: > "Alf P. Steinbach" wrote: >> it's great that you provide the kind >> of help that you did, pointing out a probably very good module that it seems >> gives the required functionality, and giving an URL. > > Yes, because that's _actually helping people_ and not just > contributing the usual self-serving pontificating nonsense that just > _flows_ from your goddamn mouth like a river of effluent > psuedotruths. That's an off-topic personal attack, and it's completely untrue. You're wasting bandwidth. > If you really wanted to help you would've cited _actual security > flaws_ in your first response to me, instead of hand waving us away > to once again do the leg work of verification. Posting two ranting and raving articles complaining about 1 (one) line or so in an earlier article, just because you personally wouldn't want to know that, that's a total waste of the reader's time. Disregarding the negative emotional adjectives you add everywhere, it's a good heuristic to post what you would want to know. I would want to know that a service is started, that it's designed for net based administration by Microsoft, and that so it might constitute a security risk. And so I added that information, each point of which is relevant. If you don't want to know about the "probably" little thing you can just skim over it. If you're unable to do that then something's wrong with you. > Based on your postings > here, you regularly don't have the time or inclination to back up some > of the bizarre claims you make. It would actually improve the signal > in this channel a lot if you just chose not to make those posts at all. That an off-topic personal attack, and it's completely untrue. Another poster (not me) has described you in an article here as a sockpuppet (false identity being in reality another poster here) and a troll; I believe at least the troll bit. It would reduce the noise level a bit if you stopped contributing noise like above. Cheers, - Alf From __peter__ at web.de Tue Feb 16 03:55:50 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Feb 2010 09:55:50 +0100 Subject: Printing with raw_input References: Message-ID: Shashwat Anand wrote: > raw_input uses sys.stderr I guess ? I had a look at the C code, but it's a bit confusing. If I'm reading it correctly the prompt is written to the "real" stderr if and only if sys.stdin and sys.stdout are attached to a terminal. $ python -c"raw_input('prompt\n')" 2>tmp.txt foo $ cat tmp.txt prompt $ python -c"raw_input('prompt\n')" 2>tmp.txt | cat foo prompt $ cat tmp.txt I wonder if that is intentional. Peter From peloko45 at gmail.com Tue Feb 16 03:59:19 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 16 Feb 2010 00:59:19 -0800 (PST) Subject: Union of class variables [Solved] References: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> <0ab616a3-f507-487e-abb5-be0929d05117@f17g2000prh.googlegroups.com> Message-ID: On 16 feb, 08:40, alex23 wrote: > On Feb 16, 6:16?pm, Joan Miller wrote: > > > Is possible to get a third class with the class variables of another > > two classes? > > > -------- > > class A: > > ? ? foo = 1 > > > class B: > > ? ? bar = 2 > > -------- > > Through multiple inheritance? > > ? >>> class C(A, B): > ? ... ? pass > ? ... > ? >>> C.foo > ? 1 > ? >>> C.bar > ? 2 Yes! It solves the problem :) Thanks! From ben+python at benfinney.id.au Tue Feb 16 04:01:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 20:01:08 +1100 Subject: Union of class variables References: <07320890-98ae-4b11-b6c8-f8ab5b43dd43@15g2000yqi.googlegroups.com> Message-ID: <871vgld06j.fsf@benfinney.id.au> Joan Miller writes: > Is possible to get a third class with the class variables of another > two classes? Multiple inheritance is allowed in Python: class Baz(Foo, Bar): pass However, it leads to complications that you likely don't want, e.g. . Is it *really* the case that the new class is best expressed by an IS-A relationship to *both* the others? (?Every Baz IS-A Foo; every Baz IS-A Bar?) You should consider composition, instead. Decide which other class represents the more general case of the new class, and give it additional capabilities through a HAS-A relationship. (?Every Baz IS-A Foo; every Baz HAS-A Bar?) class Baz(Foo): def __init__(self): self.bar = Bar() That way, you keep the clarity of single inheritance and additional capabilities are accessed through an attribute. -- \ ?Always code as if the guy who ends up maintaining your code | `\ will be a violent psychopath who knows where you live.? ?John | _o__) F. Woods | Ben Finney From ben+python at benfinney.id.au Tue Feb 16 04:04:45 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 16 Feb 2010 20:04:45 +1100 Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: <87wrydblg2.fsf@benfinney.id.au> alex23 writes: > Yes, because that's _actually helping people_ and not just > contributing the usual self-serving pontificating nonsense that just > _flows_ from your goddamn mouth like a river of effluent psuedotruths. I can't see what improvement you hope to achieve by sending something like this. If, instead, you just want to vent cathartically, this isn't the place to do it. Please, don't send the above kind of vitriol to this public forum. Better yet, compose it in your editor, bask in what you've written, then delete it unsent. -- \ ?Kill myself? Killing myself is the last thing I'd ever do.? | `\ ?Homer, _The Simpsons_ | _o__) | Ben Finney From gawade.ninad at gmail.com Tue Feb 16 05:43:09 2010 From: gawade.ninad at gmail.com (danin) Date: Tue, 16 Feb 2010 02:43:09 -0800 (PST) Subject: finding contents from string Message-ID: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Hi all, I am looking for particular solution. I am having one string say: string- "http://maps.google.co.in/maps/ms? hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 " and from this string i need to extract value -20.730428,86.456909. These value are dynamic so i cant use filter. So can anyone please tell me about how to do this. From arnodel at googlemail.com Tue Feb 16 05:57:59 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 10:57:59 +0000 Subject: finding contents from string References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: danin writes: > Hi all, > I am looking for particular solution. I am having one string > say: > string- "http://maps.google.co.in/maps/ms? > hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 > " > and from this string i need to extract value > -20.730428,86.456909. These value are dynamic so i cant use filter. So > can anyone please tell me about how to do this. In Python 2.5: >>> import urlparse >>> url='http://www.example.com/foo?bar=42&spam=eggs' >>> parsed_url = urlparse.urlparse(url) >>> parsed_url.query 'bar=42&spam=eggs' >>> import cgi >>> parsed_query = cgi.parse_qs(parsed_url.query) >>> parsed_query {'bar': ['42'], 'spam': ['eggs']} In Python >= 2.6, parse_qs lives in the urlparse module as well. -- Arnaud From __peter__ at web.de Tue Feb 16 06:00:06 2010 From: __peter__ at web.de (Peter Otten) Date: Tue, 16 Feb 2010 12:00:06 +0100 Subject: finding contents from string References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: danin wrote: > Hi all, > I am looking for particular solution. I am having one string > say: > string- "http://maps.google.co.in/maps/ms? > hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 > " > and from this string i need to extract value > -20.730428,86.456909. Where does the "-" come from? > These value are dynamic so i cant use filter. I don't understand. > So can anyone please tell me about how to do this. >>> from urlparse import urlparse, parse_qs >>> parse_qs(urlparse(string).query)["ll"][0] '20.730428,86.456909' Peter From spam.buster at web.de Tue Feb 16 06:25:36 2010 From: spam.buster at web.de (Lars Behrens) Date: Tue, 16 Feb 2010 12:25:36 +0100 Subject: finding contents from string References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: danin wrote: > can anyone please tell me about how to do this. Now come on, you have to give a *bit* more information. What have you done so far? What did you plan? What are the rules for finding the string? -- Cheerz Lars From wolftracks at invalid.com Tue Feb 16 07:16:58 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 04:16:58 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters Message-ID: I normally use IDLE on Win, but recently needed to go to command prompt to see all error messages. When I did, I was greeted by a host of deprecation and Numpy messages before things got running. The program otherwise functioned OK, after I found the problem I was after. Are these messages a warning to get to the next update of numpy? I would guess that updating to a higher update does not mean I need to remove the old one, correct? In general for libraries like numpy or scipy, I use win32 updates, but I see win32-p3 updates too on download pages. Since I may be distributing this program to p3 machines, will I need to provide the win32-p3 updates to those users? From news123 at free.fr Tue Feb 16 07:18:16 2010 From: news123 at free.fr (News123) Date: Tue, 16 Feb 2010 13:18:16 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: <4b7a8d08$0$666$426a74cc@news.free.fr> Thanks for your answers, The security wouldn't be a concern, as I would run while being only accessible by trusted hosts. I don't use the script often, so if it would start a WMI service during runtime and stop it afterwards it would be fine. I just wonder whether installing another 3rd party package for just listing all services s worth the effort. In my current case I'll go probably for parsing the output of "sc.exe query" or I'll traverse the registry. currently I just want to get a list of the names of the running services. bye N Alf P. Steinbach wrote: > * alex23: >> News123 wrote: >>> What is the best way with python to get a list of all windows services. >>> >>> As a start I would be glad to receive only the service names. >>> >>> However it would be nicer if I could get all the properties of a service >>> as well. >> >> I highly recommend Tim Golden's fantastic WMI module[1]. > > It's probably Very Good, but one Microsoft-thing one should be aware of: > using WMI functionality generally starts up a background WMI service... > > Similarly, starting the standard clipboard viewer (discontinued in > Windows Vista) starts up a silly copy-clipboard-contents-over-network > service. > > On a low-range machine the WMI service can be a resource concern. > > I don't know whether the WMI service is a security concern (it probably > is, considering IIS and anything Microsoft+Network and that WMI is meant > to administrate machines over network, it's an enterprise thing not a > personal computer user thing), but the clipboard service is, as I > recall, a concern. > > >> >>> import wmi >> >>> c = wmi.WMI() >> >>> services = c.Win32_Service() >> >>> s = services[0] >> >>> s >> <_wmi_object: \\LIB-D5NYF1S\root >> \cimv2:Win32_Service.Name="Alerter"> >> >>> s.properties >> {u'DisplayName': None, u'ServiceSpecificExitCode': None, u'State': >> None, u'Syste >> mName': None, u'ErrorControl': None, u'Status': None, >> u'ProcessId': None, u'Desc >> ription': None, u'Started': None, u'AcceptStop': None, >> u'CheckPoint': None, u'Pa >> thName': None, u'WaitHint': None, u'Name': None, u'InstallDate': >> None, u'Caption >> ': None, u'StartMode': None, u'DesktopInteract': None, >> u'ServiceType': None, u'T >> agId': None, u'StartName': None, u'AcceptPause': None, >> u'CreationClassName': Non >> e, u'SystemCreationClassName': None, u'ExitCode': None} >> >>> s.Name >> u'Alerter' >> >>> s.Started >> False >> >>> s.ServiceType >> u'Share Process' >> >> 1: http://timgolden.me.uk/python/wmi/index.html > > Cheers, > > - Alf From wolftracks at invalid.com Tue Feb 16 07:19:15 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 04:19:15 -0800 Subject: Is there a simple way to find the list index to the max value? Message-ID: See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. From vaayu at ymail.com Tue Feb 16 07:25:45 2010 From: vaayu at ymail.com (Praveen Boppana) Date: Tue, 16 Feb 2010 17:55:45 +0530 (IST) Subject: finding contents from string In-Reply-To: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> References: <39d959be-5b7f-442b-92d2-bc73b877b578@t34g2000prm.googlegroups.com> Message-ID: <66498.7222.qm@web95303.mail.in2.yahoo.com> It looks like you want to extract the query parameters from standard url's. There is a standard Python module to accomplish this: http://www.python.org/doc/2.5.2/lib/module-urlparse.html ________________________________ From: danin To: python-list at python.org Sent: Tue, 16 February, 2010 4:13:09 PM Subject: finding contents from string Hi all, I am looking for particular solution. I am having one string say: string- "http://maps.google.co.in/maps/ms? hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 " and from this string i need to extract value -20.730428,86.456909. These value are dynamic so i cant use filter. So can anyone please tell me about how to do this. -- http://mail.python.org/mailman/listinfo/python-list Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Feb 16 07:29:36 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Feb 2010 12:29:36 +0000 Subject: listing existing windows services with python In-Reply-To: <4b7a8d08$0$666$426a74cc@news.free.fr> References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: <4B7A8FB0.2060901@timgolden.me.uk> On 16/02/2010 12:18, News123 wrote: > I don't use the script often, so if it would start a WMI service during > runtime and stop it afterwards it would be fine. FWIW -- your other considerations notwithstanding -- I'm not aware of WMI having this effect. Generally you can assume that the WMI services are running (or not, if someone's shut them off) but I've never heard of them being started up by virtue of a call to the WMI subsystem and then stopped afterwards. That said, I'd be interested if someone did have a pointer for this; worth putting a caveat in the docs if that were the case. TJG From arnodel at googlemail.com Tue Feb 16 07:37:46 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 12:37:46 +0000 Subject: Is there a simple way to find the list index to the max value? References: Message-ID: "W. eWatson" writes: > See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. Here are a few ways. >>> a = [1,4,9,3] >>> max_index = max(xrange(len(a)), key=a.__getitem__) >>> max_index 2 >>> # Or: ... max_index = max((n, i) for i, n in enumerate(a))[1] >>> max_index 2 >>> # Or: ... from itertools import * >>> max_index = max(izip(a, count()))[1] >>> max_index 2 -- Arnaud From steve at lonetwin.net Tue Feb 16 07:38:09 2010 From: steve at lonetwin.net (steve) Date: Tue, 16 Feb 2010 18:08:09 +0530 Subject: Is there a simple way to find the list index to the max value? References: Message-ID: <4B7A91B1.6030301@lonetwin.net> On 02/16/2010 05:49 PM, W. eWatson wrote: > See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. The most obvious would be a.index(max(a)). Is that what you wanted ? cheers, - steve From arnodel at googlemail.com Tue Feb 16 07:41:36 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 12:41:36 +0000 Subject: Is there a simple way to find the list index to the max value? References: Message-ID: Arnaud Delobelle writes: > "W. eWatson" writes: > >> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. > > Here are a few ways. [...] My copy past went wrond and I forgot the first one: >>> a = [1,4,9,3] >>> max_index = a.index(max(a)) >>> max_index 2 -- Arnaud From alfps at start.no Tue Feb 16 07:48:09 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 13:48:09 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: * Tim Golden: > On 16/02/2010 12:18, News123 wrote: >> I don't use the script often, so if it would start a WMI service during >> runtime and stop it afterwards it would be fine. > > FWIW -- your other considerations notwithstanding -- I'm not aware > of WMI having this effect. Generally you can assume that the WMI > services are running (or not, if someone's shut them off) but > I've never heard of them being started up by virtue of a call > to the WMI subsystem and then stopped afterwards. > > That said, I'd be interested if someone did have a pointer for this; > worth putting a caveat in the docs if that were the case. > > TJG I just googled the filename from memory, found Don't know if I've disabled it because invoking wmic didn't produce it. Uh, wait, since it hosts the provider service(s), perhaps... Yes, 'wmic service list brief' which actually retrieves some information (I guess it can be anything, I remembered this from listing process command lines) started an [wmprvse.exe] process. It terminated after the query/usage, but as I recall in some cases it doesn't. I don't know how that works with programmatic access, but it's worth checking out. Cheers, - Alf From mail at timgolden.me.uk Tue Feb 16 08:01:26 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Feb 2010 13:01:26 +0000 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: <4B7A9726.7080304@timgolden.me.uk> On 16/02/2010 12:48, Alf P. Steinbach wrote: > I just googled the filename from memory, found > > > > Don't know if I've disabled it because invoking wmic didn't produce it. > > Uh, wait, since it hosts the provider service(s), perhaps... > > Yes, 'wmic service list brief' which actually retrieves some information (I > guess it can be anything, I remembered this from listing process command lines) > started an [wmprvse.exe] process. > > It terminated after the query/usage, but as I recall in some cases it doesn't. > > I don't know how that works with programmatic access, but it's worth checking out. Thanks. As I understand it, you're not talking about a *service* starting up or shutting down; rather a *process* starting up etc., presumably controlled by the underlying service? I'll do some further research to see what's going on there. TJG From alfps at start.no Tue Feb 16 08:51:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 14:51:22 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: * Tim Golden: > On 16/02/2010 12:48, Alf P. Steinbach wrote: >> I just googled the filename from memory, found >> >> >> >> Don't know if I've disabled it because invoking wmic didn't produce it. >> >> Uh, wait, since it hosts the provider service(s), perhaps... >> >> Yes, 'wmic service list brief' which actually retrieves some >> information (I >> guess it can be anything, I remembered this from listing process >> command lines) >> started an [wmprvse.exe] process. >> >> It terminated after the query/usage, but as I recall in some cases it >> doesn't. >> >> I don't know how that works with programmatic access, but it's worth >> checking out. > > Thanks. As I understand it, you're not talking about a *service* > starting up > or shutting down; rather a *process* starting up etc., presumably > controlled > by the underlying service? It doesn't seem to provide ordinary Windows "service"s, but it's a bit unclear since e.g. the URL above says Beginning with Windows XP, WMI resides in a shared service host with several other services. To avoid stopping all the services when a provider fails, providers are loaded into a separate host process named Wmiprvse.exe. Multiple instances of Wmiprvse.exe can run at the same time under different accounts: LocalSystem, NetworkService or LocalService. The WMI core WinMgmt.exe is loaded into the shared Local Service host named Svchost.exe. Note: wmiprvsw.exe is the Sasser worm! Note: The wmiprvse.exe file is located in the folder C:\WINDOWS\System32\Wbem. In other cases, wmiprvse.exe is a virus, spyware, trojan or worm! Check this with Security Task Manager. Checking for ordinary Windows services: C:\test> (wmic service list >nul) & tasklist /svc /fi "imagename eq wmiprvse.exe" Image Name PID Services ========================= ====== ============================================= wmiprvse.exe 1076 N/A C:\test> _ > I'll do some further research to see what's going on there. Cheers, - Alf (is this off-topic for the group?) From leo at lspace.org Tue Feb 16 08:56:45 2010 From: leo at lspace.org (Leo Breebaart) Date: 16 Feb 2010 13:56:45 GMT Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> Message-ID: <7tvmgtF68lU1@mid.individual.net> Chris Rebert writes: > On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: > > > I have a base class Foo with a number of derived classes FooA, > > FooB, FooC, etc. Each of these derived classes needs to read > > (upon initialisation) text from an associated template file > > FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. > > [...] > > But, since this information is the same for every instance of > > each derived class, I was wondering if there was a way to achieve > > the same thing outside of the __init__ function, and just have > > these assignments be done as a class attribute (i.e. so that I > > can refer to FooA.template_body, etc.) > > Metaclasses to the rescue!: > > class WithTemplateAttrs(type): > def __new__(cls, name, bases, dct): > klass =3D type.__new__(cls, name, bases, dct) > klass.template_filename =3D "%s.tmpl" % name > klass.template_body =3D read_body_from(klass.template_filename) > return klass > > class Foo(object): > __metaclass__ =3D WithTemplateAttrs > #rest of class body here > > Now just have FooA, FooB, etc. subclass Foo as before. They'll > automatically get the attributes generated. Thanks for the feedback! I am thrilled that an actual real-life issue I'm having may be resolvable by metaclasses (which so far I've only admired from afar but never considered relevant to my day-to-day work), but unfortunately I'm still struggling to get this to work. If I add your code, what happens is that the Foo class will try to read "Foo.tmpl", which does not exist -- it is only the derived classes FooA etc, that need to execute this code, not Foo itself. And actually that makes sense -- I think my problem was not too clearly thought out to begin with. Of course it's not possible to associate a single template_body with the Foo class, it will be a different template for each derived class. So at best I need to associate your metaclass with each derived class, but at that point I might as well just read the template in the __init__() method with __class__.__name__, and use lazy evaluation / caching to avoid doing the actual file-reading work more than once. I think. -- Leo Breebaart From martin.hellwig at dcuktec.org Tue Feb 16 08:56:48 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 16 Feb 2010 13:56:48 +0000 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: On 02/16/10 13:51, Alf P. Steinbach wrote: > - Alf (is this off-topic for the group?) Strictly speaking yes, but I do find it interesting and there is nothing wrong with ignoring posts you don't like to read. -- mph From rludwinowski at gmail.com Tue Feb 16 09:37:00 2010 From: rludwinowski at gmail.com (rludwinowski) Date: Tue, 16 Feb 2010 06:37:00 -0800 (PST) Subject: Implicit __init__ execution in multiple inheritance Message-ID: <776abfc7-f57b-4630-9077-8ac1e4ee1c6e@b7g2000yqd.googlegroups.com> class A: def __init__(self): print("A__init__") class B: def __init__(self): print("B__init__") class C(A, B): pass C() >> A__init__ Why __init__ class B will not be automatic executed? From arnodel at googlemail.com Tue Feb 16 09:38:51 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 14:38:51 +0000 Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: Leo Breebaart writes: > Chris Rebert writes: > >> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: >> >> > I have a base class Foo with a number of derived classes FooA, >> > FooB, FooC, etc. Each of these derived classes needs to read >> > (upon initialisation) text from an associated template file >> > FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. >> > [...] >> > But, since this information is the same for every instance of >> > each derived class, I was wondering if there was a way to achieve >> > the same thing outside of the __init__ function, and just have >> > these assignments be done as a class attribute (i.e. so that I >> > can refer to FooA.template_body, etc.) >> >> Metaclasses to the rescue!: >> >> class WithTemplateAttrs(type): >> def __new__(cls, name, bases, dct): >> klass =3D type.__new__(cls, name, bases, dct) >> klass.template_filename =3D "%s.tmpl" % name >> klass.template_body =3D read_body_from(klass.template_filename) >> return klass >> >> class Foo(object): >> __metaclass__ =3D WithTemplateAttrs >> #rest of class body here >> >> Now just have FooA, FooB, etc. subclass Foo as before. They'll >> automatically get the attributes generated. > > Thanks for the feedback! I am thrilled that an actual real-life > issue I'm having may be resolvable by metaclasses (which so far > I've only admired from afar but never considered relevant to my > day-to-day work), but unfortunately I'm still struggling to get > this to work. > > If I add your code, what happens is that the Foo class will try > to read "Foo.tmpl", which does not exist -- it is only the > derived classes FooA etc, that need to execute this code, not Foo > itself. > > And actually that makes sense -- I think my problem was not too > clearly thought out to begin with. Of course it's not possible to > associate a single template_body with the Foo class, it will be a > different template for each derived class. So at best I need to > associate your metaclass with each derived class, but at that > point I might as well just read the template in the __init__() > method with __class__.__name__, and use lazy evaluation / caching > to avoid doing the actual file-reading work more than once. > > I think. Descriptors to the rescue :) def read_body_from(filename): print "** loading content **" return "" % filename # This is a kind of class property class TemplateFilename(object): def __get__(self, obj, cls): return "%s.tmpl" % cls.__name__ # And this is a kind of cached class property class TemplateBody(object): def __get__(self, obj, cls): try: return cls._body except AttributeError: cls._body = read_body_from(cls.template_filename) return cls._body class Foo(object): template_filename = TemplateFilename() template_body = TemplateBody() class FooA(Foo): pass class FooB(Foo): pass # In action: >>> FooA.template_filename 'FooA.tmpl' >>> FooB.template_filename 'FooB.tmpl' >>> FooA.template_body ** loading content ** "" >>> FooA.template_body "" >>> foob = FooB() >>> foob.template_filename 'FooB.tmpl' >>> foob.template_body ** loading content ** "" >>> foob.template_body "" HTH -- Arnaud From arnodel at googlemail.com Tue Feb 16 09:47:32 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 14:47:32 +0000 Subject: Implicit __init__ execution in multiple inheritance References: <776abfc7-f57b-4630-9077-8ac1e4ee1c6e@b7g2000yqd.googlegroups.com> Message-ID: rludwinowski writes: > class A: > def __init__(self): > print("A__init__") > > class B: > def __init__(self): > print("B__init__") > > class C(A, B): > pass > > C() > >>> A__init__ > > Why __init__ class B will not be automatic executed? Because it's documented behaviour? By default, at initialisation, an instance of C will go up the method resolution order and only execture the first __init__() method found. If you want to change this, you have to do it explicitely within the __init__ method(s) of the parent class(es). E.g. try this (assuming Python 3 syntax): class A: def __init__(self): super().__init__() print("A__init__") class B: def __init__(self): super().__init__() print("B__init__") class C(A, B): pass C() From ssteinerx at gmail.com Tue Feb 16 09:51:34 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 16 Feb 2010 09:51:34 -0500 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: On Feb 16, 2010, at 3:28 AM, Benedict Verheyen wrote: > Steven D'Aprano wrote: >> On Mon, 15 Feb 2010 16:29:05 +0100, Benedict Verheyen wrote: >> >>> However, when i make a subdirectory, for example database and put a >>> script in there, how would i import logutils or mailtutils from within >>> the database subdirectory? This fails: >>> from tools.logutils import logger >> >> Sounds like you need to ensure that the top level directory needs to be >> added to your PYTHONPATH. >> >> Do you need instructions to do this? >> > > Hi Steve, > > > thanks, i think i know how to add the top level directory to the PYTHONPATH. > > I'm however looking further into the suggestion of ssteinerX to use a > setup.py file to add the tools utility scripts to the pythonpath. > In the near future, another person will be helping me with programming > and thus, i want to make sure the structure is usable by other people > than myself. > > Furthermore, i'm thinking if it wouldn't be cleaner to make such a setup.py > file per script, at least the bigger, more important scripts. > Now my structure is like this: > > python_scripts > | > |-->trunk > ......|-----> all scripts > ......|-----> tools > > The python_scripts directory and subdirs are versioned via SVN. > I think these steps would help: > > 1. Make a package of tools. > 2. Put the bigger scripts in a seperate directory also using a setup.py file. > 3. If possible, put the other scripts that somehow belong together in a seperate > directory. Names need to be more clear but i'm just illustrating a point. > > python_scripts > | > |-->trunk > ......|-----> my big script 1 > ................|-----> setup.py > ......|-----> my big script 2 > ................|-----> setup.py > ......|-----> database > ................|-----> database script 1 > ................|-----> database script 2 > ......|-----> tools > ................|-----> setup.py > > Does that look like a clear structure? No. Make one setup.py at the top, put related scripts (like database) into separate sub-modules, so they can all be imported off a common 'trunk' as you have it above i.e. as trunk.database.xxx. Then use entry points for any command line scripts. Slightly harder, to setup initially but much cleaner to use and maintain and, it all installs with one call to setup.py develop. S From jeanmichel at sequans.com Tue Feb 16 10:00:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 16 Feb 2010 16:00:28 +0100 Subject: Using class attributes In-Reply-To: References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: <4B7AB30C.2020806@sequans.com> Arnaud Delobelle wrote: > Leo Breebaart writes: > > >> Chris Rebert writes: >> >> >>> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: >>> >>> >>>> I have a base class Foo with a number of derived classes FooA, >>>> FooB, FooC, etc. Each of these derived classes needs to read >>>> (upon initialisation) text from an associated template file >>>> FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. >>>> [...] >>>> But, since this information is the same for every instance of >>>> each derived class, I was wondering if there was a way to achieve >>>> the same thing outside of the __init__ function, and just have >>>> these assignments be done as a class attribute (i.e. so that I >>>> can refer to FooA.template_body, etc.) >>>> >>> Metaclasses to the rescue!: >>> >>> class WithTemplateAttrs(type): >>> def __new__(cls, name, bases, dct): >>> klass =3D type.__new__(cls, name, bases, dct) >>> klass.template_filename =3D "%s.tmpl" % name >>> klass.template_body =3D read_body_from(klass.template_filename) >>> return klass >>> >>> class Foo(object): >>> __metaclass__ =3D WithTemplateAttrs >>> #rest of class body here >>> >>> Now just have FooA, FooB, etc. subclass Foo as before. They'll >>> automatically get the attributes generated. >>> >> Thanks for the feedback! I am thrilled that an actual real-life >> issue I'm having may be resolvable by metaclasses (which so far >> I've only admired from afar but never considered relevant to my >> day-to-day work), but unfortunately I'm still struggling to get >> this to work. >> >> If I add your code, what happens is that the Foo class will try >> to read "Foo.tmpl", which does not exist -- it is only the >> derived classes FooA etc, that need to execute this code, not Foo >> itself. >> >> And actually that makes sense -- I think my problem was not too >> clearly thought out to begin with. Of course it's not possible to >> associate a single template_body with the Foo class, it will be a >> different template for each derived class. So at best I need to >> associate your metaclass with each derived class, but at that >> point I might as well just read the template in the __init__() >> method with __class__.__name__, and use lazy evaluation / caching >> to avoid doing the actual file-reading work more than once. >> >> I think. >> > > Descriptors to the rescue :) > > def read_body_from(filename): > print "** loading content **" > return "" % filename > > # This is a kind of class property > class TemplateFilename(object): > def __get__(self, obj, cls): > return "%s.tmpl" % cls.__name__ > > # And this is a kind of cached class property > class TemplateBody(object): > def __get__(self, obj, cls): > try: > return cls._body > except AttributeError: > cls._body = read_body_from(cls.template_filename) > return cls._body > > class Foo(object): > template_filename = TemplateFilename() > template_body = TemplateBody() > > class FooA(Foo): > pass > > class FooB(Foo): > pass > > # In action: > >>>> FooA.template_filename >>>> > 'FooA.tmpl' > >>>> FooB.template_filename >>>> > 'FooB.tmpl' > >>>> FooA.template_body >>>> > ** loading content ** > "" > >>>> FooA.template_body >>>> > "" > >>>> foob = FooB() >>>> foob.template_filename >>>> > 'FooB.tmpl' > >>>> foob.template_body >>>> > ** loading content ** > "" > >>>> foob.template_body >>>> > "" > > HTH > > While all these proposals are giving interesting technical anwsers to the OP problem, I think that the OP original code is still the best (_imo_). class Foo(object): def __init__(self): self.template_filename = "%s.tmpl" % self.__class__.__name__ self.template_body = read_body_from(self.template_filename) That is true the same attributes are defined for every instance, but, honestly, who cares ? (unless you target the best class design 2010 price :-) ) This solution beat the others in terms of simplicity and readability. It's still usefull to train your mind with decorators and metaclasses though, they can save your life eventually. JM From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 16 10:12:36 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 16 Feb 2010 16:12:36 +0100 Subject: Implicit __init__ execution in multiple inheritance In-Reply-To: References: <776abfc7-f57b-4630-9077-8ac1e4ee1c6e@b7g2000yqd.googlegroups.com> Message-ID: <4b7ab5e5$0$23314$426a74cc@news.free.fr> Arnaud Delobelle a ?crit : > rludwinowski writes: > >> class A: >> def __init__(self): >> print("A__init__") >> >> class B: >> def __init__(self): >> print("B__init__") >> >> class C(A, B): >> pass >> >> C() >> >>>> A__init__ >> Why __init__ class B will not be automatic executed? > > Because it's documented behaviour? By default, at initialisation, an > instance of C will go up the method resolution order and only execture > the first __init__() method found. Note to the OP : Python's "methods" are attributes, so the normal attribute lookup rules apply - which is why the lookup stops at the first (in _mro_ order) '__init__' method found. From paul at subsignal.org Tue Feb 16 10:14:22 2010 From: paul at subsignal.org (=?ISO-8859-9?Q?Paul_K=F6lle?=) Date: Tue, 16 Feb 2010 16:14:22 +0100 Subject: plugin / intra process communication system In-Reply-To: <1266271943.4299.2887.camel@brain> References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <1266271943.4299.2887.camel@brain> Message-ID: Am 15.02.2010 23:12, schrieb Florian Ludwig: > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: [...] >> And then of course, this is not really needed. In Python, behavior >> counts, not type-information. So you can get away without any explicit >> declared interface. You might chose to not do that, for aestetic >> reasons, or better documentation. But you aren't forced. > > Actually some plugin-systems in python do force you and they check if > your "implementation" comply with the "interface". Which is a good thing IMO ;) > Here is one solution I came up with. [...] Can you post working code? It's not clear what "pbus" is and how it works. cheers Paul > What do you think? Any obvious pitfalls (besides reinventing something)? > > Please keep in mind that syntax/api is not "done" or anything its just > an concept presentation. > > Thanks, > Florian > > > From arnodel at googlemail.com Tue Feb 16 10:15:49 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 15:15:49 +0000 Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: Jean-Michel Pichavant writes: [...] > While all these proposals are giving interesting technical anwsers to > the OP problem, I think that the OP original code is still the best > (_imo_). > > class Foo(object): > def __init__(self): > self.template_filename = "%s.tmpl" % self.__class__.__name__ > self.template_body = read_body_from(self.template_filename) > > > That is true the same attributes are defined for every instance, but, > honestly, who cares ? (unless you target the best class design 2010 > price :-) ) You might care if you have many instances but few classes, and the size of template_body is significant. Although with this design it is possible to cache template bodies within the 'read_body_from' function if necessary. Also I was under the impression that the OP wanted these attribute to be accessible from the class object as well. -- Arnaud From robert.kern at gmail.com Tue Feb 16 10:30:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Feb 2010 09:30:29 -0600 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters In-Reply-To: References: Message-ID: On 2010-02-16 06:16 AM, W. eWatson wrote: > I normally use IDLE on Win, but recently needed to go to command prompt > to see all error messages. When I did, I was greeted by a host of > deprecation and Numpy messages before things got running. The program > otherwise functioned OK, after I found the problem I was after. Are > these messages a warning to get to the next update of numpy? > > I would guess that updating to a higher update does not mean I need to > remove the old one, correct? > > In general for libraries like numpy or scipy, I use win32 updates, but I > see win32-p3 updates too on download pages. Since I may be distributing > this program to p3 machines, will I need to provide the win32-p3 updates > to those users? You will definitely want to ask these questions on the numpy-discussion mailing list. They are numpy-specific. Please copy-and-paste the messages that you get. 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 wolftracks at invalid.com Tue Feb 16 10:34:51 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 07:34:51 -0800 Subject: Is there a simple way to find the list index to the max value? In-Reply-To: References: Message-ID: On 2/16/2010 4:41 AM, Arnaud Delobelle wrote: > Arnaud Delobelle writes: > >> "W. eWatson" writes: >> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >> Here are a few ways. > > [...] > > My copy past went wrond and I forgot the first one: > >>>> a = [1,4,9,3] >>>> max_index = a.index(max(a)) >>>> max_index > 2 > Ah, the good one for last! Thanks. From ssteinerx at gmail.com Tue Feb 16 10:35:26 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 16 Feb 2010 10:35:26 -0500 Subject: listing existing windows services with python In-Reply-To: <87wrydblg2.fsf@benfinney.id.au> References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <87wrydblg2.fsf@benfinney.id.au> Message-ID: <7137165D-34E6-4015-AD09-C26CD9677E55@gmail.com> On Feb 16, 2010, at 4:04 AM, Ben Finney wrote: > Please, don't send the above kind of vitriol to this public forum. > Better yet, compose it in your editor, bask in what you've written, then delete it unsent. +1 If you kids want to have some sort of pissing-in-your-sockpuppet type of contest to see who can out-whatever each other, do it off-list and don't waste everyone else's time with. What ever happened to "don't feed the trolls" ?? If you really believe someone's trolling, don't answer, block them, and move on. Providing a lengthy, well-reasoned reply only shows that they've pulled you into the troll pit for a fight with them, regardless of whether you're "right." S From wolftracks at invalid.com Tue Feb 16 10:37:28 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 07:37:28 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters In-Reply-To: References: Message-ID: On 2/16/2010 7:30 AM, Robert Kern wrote: > On 2010-02-16 06:16 AM, W. eWatson wrote: >> I normally use IDLE on Win, but recently needed to go to command prompt >> to see all error messages. When I did, I was greeted by a host of >> deprecation and Numpy messages before things got running. The program >> otherwise functioned OK, after I found the problem I was after. Are >> these messages a warning to get to the next update of numpy? >> >> I would guess that updating to a higher update does not mean I need to >> remove the old one, correct? >> >> In general for libraries like numpy or scipy, I use win32 updates, but I >> see win32-p3 updates too on download pages. Since I may be distributing >> this program to p3 machines, will I need to provide the win32-p3 updates >> to those users? > > You will definitely want to ask these questions on the numpy-discussion > mailing list. They are numpy-specific. Please copy-and-paste the > messages that you get. > > http://www.scipy.org/Mailing_Lists > Good idea, for the first part of this. I would think "In genera for ..." would be answerable here, but I'll give them both a shot. I'll post what I find here, as a follow up. From paul at boddie.org.uk Tue Feb 16 10:38:24 2010 From: paul at boddie.org.uk (Paul Boddie) Date: Tue, 16 Feb 2010 07:38:24 -0800 (PST) Subject: Python Optimization References: <363498c7-3575-4f1e-ad53-d9cd10c8da2c@q16g2000yqq.googlegroups.com> <88a7ff43-3f1d-4e30-ad50-59b6c2f215f7@a5g2000prg.googlegroups.com> Message-ID: <5f3d2058-40ec-415e-8ad4-7e28b98fb304@15g2000yqa.googlegroups.com> On 14 Feb, 19:41, Steve Howell wrote: > > I ditto the profiling recommendation. > > http://docs.python.org/library/profile.html (To the original inquirer...) Try this, too: http://wiki.python.org/moin/PythonSpeed/Profiling If you have the tools, it's a lot easier than scanning through tables of times. Paul From steve at holdenweb.com Tue Feb 16 10:54:00 2010 From: steve at holdenweb.com (Steve Holden) Date: Tue, 16 Feb 2010 10:54:00 -0500 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: Alf P. Steinbach wrote: [...] >> I'll do some further research to see what's going on there. > > Cheers, > > - Alf (is this off-topic for the group?) It's gone a lot further off than this without anyone complaining. I think your experiences to date should convince you that you can rely on being told when you drift too far off-topic :) regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From robert.kern at gmail.com Tue Feb 16 11:35:07 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 16 Feb 2010 10:35:07 -0600 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters In-Reply-To: References: Message-ID: On 2010-02-16 09:37 AM, W. eWatson wrote: > On 2/16/2010 7:30 AM, Robert Kern wrote: >> On 2010-02-16 06:16 AM, W. eWatson wrote: >>> I normally use IDLE on Win, but recently needed to go to command prompt >>> to see all error messages. When I did, I was greeted by a host of >>> deprecation and Numpy messages before things got running. The program >>> otherwise functioned OK, after I found the problem I was after. Are >>> these messages a warning to get to the next update of numpy? >>> >>> I would guess that updating to a higher update does not mean I need to >>> remove the old one, correct? >>> >>> In general for libraries like numpy or scipy, I use win32 updates, but I >>> see win32-p3 updates too on download pages. Since I may be distributing >>> this program to p3 machines, will I need to provide the win32-p3 updates >>> to those users? >> >> You will definitely want to ask these questions on the numpy-discussion >> mailing list. They are numpy-specific. Please copy-and-paste the >> messages that you get. >> >> http://www.scipy.org/Mailing_Lists >> > Good idea, for the first part of this. I would think "In genera for ..." > would be answerable here, but I'll give them both a shot. Both parts are very numpy/scipy-specific, trust me. The reason that numpy has binary releases for Pentium 3 machines is because we have SSE code of various levels due to our accelerated BLAS libraries. This is very rare outside of numpy and scipy. And please provide the information that I asked for over in numpy-discussion. -- 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 benedict.verheyen at gmail.com Tue Feb 16 11:35:09 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Tue, 16 Feb 2010 17:35:09 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: ssteinerX at gmail.com wrote: > On Feb 16, 2010, at 3:28 AM, Benedict Verheyen wrote: >> python_scripts >> | >> |-->trunk >> ......|-----> my big script 1 >> ................|-----> setup.py >> ......|-----> my big script 2 >> ................|-----> setup.py >> ......|-----> database >> ................|-----> database script 1 >> ................|-----> database script 2 >> ......|-----> tools >> ................|-----> setup.py >> >> Does that look like a clear structure? > > No. > > Make one setup.py at the top, put related scripts (like database) into separate sub-modules, > so they can all be imported off a common 'trunk' as you have it above i.e. as trunk.database.xxx. > > Then use entry points for any command line scripts. > > Slightly harder, to setup initially but much cleaner to use and maintain and, it all installs with one call to setup.py develop. > > S Hhhm, i can see how it makes the maintenance cleaner. However, in the case of a single setup.py, i will end up installing scripts on servers that will never use them, only some. As with making egg files for the bigger scripts, you will only install what's needed. Then again, the script are small so in that respect it doesn't really matter. How would i best distribute it? Via the single setup.py or building an egg from the setup.py or plain copying the files to the server? The code is company specific so nobody else will benefit from it. Thanks, Benedict From jeanmichel at sequans.com Tue Feb 16 11:45:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 16 Feb 2010 17:45:04 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> Message-ID: <4B7ACB90.7070502@sequans.com> Benedict Verheyen wrote: > ssteinerX at gmail.com wrote: > >> On Feb 16, 2010, at 3:28 AM, Benedict Verheyen wrote: >> > > > >>> python_scripts >>> | >>> |-->trunk >>> ......|-----> my big script 1 >>> ................|-----> setup.py >>> ......|-----> my big script 2 >>> ................|-----> setup.py >>> ......|-----> database >>> ................|-----> database script 1 >>> ................|-----> database script 2 >>> ......|-----> tools >>> ................|-----> setup.py >>> >>> Does that look like a clear structure? >>> >> No. >> >> Make one setup.py at the top, put related scripts (like database) into separate sub-modules, >> so they can all be imported off a common 'trunk' as you have it above i.e. as trunk.database.xxx. >> >> Then use entry points for any command line scripts. >> >> Slightly harder, to setup initially but much cleaner to use and maintain and, it all installs with one call to setup.py develop. >> >> S >> > > Hhhm, i can see how it makes the maintenance cleaner. > However, in the case of a single setup.py, i will end up installing scripts on servers > that will never use them, only some. > You should care about this only if your scripts exceeed a faire amount of Ko. Are you sure you've written Mo of python code ? JM From benedict.verheyen at gmail.com Tue Feb 16 11:52:29 2010 From: benedict.verheyen at gmail.com (Benedict Verheyen) Date: Tue, 16 Feb 2010 17:52:29 +0100 Subject: how to structure a directory with many scripts and shared code In-Reply-To: <4B7ACB90.7070502@sequans.com> References: <4b79d343$0$8760$c3e8da3@news.astraweb.com> <4B7ACB90.7070502@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Benedict Verheyen wrote: >> Hhhm, i can see how it makes the maintenance cleaner. >> However, in the case of a single setup.py, i will end up installing >> scripts on servers >> that will never use them, only some. >> > You should care about this only if your scripts exceeed a faire amount > of Ko. > Are you sure you've written Mo of python code ? > > JM Nope and i indicated that before: "Then again, the script are small so in that respect it doesn't really matter." Regards, Benedict From lacrima.maxim at gmail.com Tue Feb 16 11:53:42 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Tue, 16 Feb 2010 08:53:42 -0800 (PST) Subject: Which mock library do you prefer? References: <87eikmc9va.fsf@benfinney.id.au> Message-ID: On Feb 16, 2:17?am, Ben Finney wrote: > Lacrima writes: > > Minimock has wider usage and community, but I have some troubles using > > it. Maybe I am wrong, but with minimock you always have to keep track > > the order of imports in your test modules. Well, may be I just don't > > understand fully how minimock works. > > I'm not sure why you think you need to keep track of the order of > imports. > > Simply set up the mocks as you want them, in your fixtures; then, when > tearing down your fixtures, use ?minimock.restore()? to restore the > affected namespaces to their initial state. > > -- > ?\ ? ? ? ?? one of the main causes of the fall of the Roman Empire was | > ? `\ ? ? ? ?that, lacking zero, they had no way to indicate successful | > _o__) ? ? ? ? ? ? ? ? ?termination of their C programs.? ?Robert Firth | > Ben Finney Hi Ben! See these two topics: http://groups.google.com/group/minimock-dev/browse_thread/thread/bcbb3b7cc60eb96f http://groups.google.com/group/minimock-dev/browse_thread/thread/c41cd996735ea1a6 There are special cases, which you have to be aware of, if you use minimock. From tjreedy at udel.edu Tue Feb 16 11:59:59 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Feb 2010 11:59:59 -0500 Subject: Using class attributes In-Reply-To: <7tvmgtF68lU1@mid.individual.net> References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: On 2/16/2010 8:56 AM, Leo Breebaart wrote: > Chris Rebert writes: > >> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: >> >>> I have a base class Foo with a number of derived classes FooA, >>> FooB, FooC, etc. Each of these derived classes needs to read >>> (upon initialisation) text from an associated template file >>> FooA.tmpl, FooB.tmpl, FooC.tmpl, etc. >>> [...] >>> But, since this information is the same for every instance of >>> each derived class, I was wondering if there was a way to achieve >>> the same thing outside of the __init__ function, and just have >>> these assignments be done as a class attribute (i.e. so that I >>> can refer to FooA.template_body, etc.) >> >> Metaclasses to the rescue!: >> >> class WithTemplateAttrs(type): >> def __new__(cls, name, bases, dct): >> klass =3D type.__new__(cls, name, bases, dct) >> klass.template_filename =3D "%s.tmpl" % name >> klass.template_body =3D read_body_from(klass.template_filename) >> return klass >> >> class Foo(object): >> __metaclass__ =3D WithTemplateAttrs >> #rest of class body here >> >> Now just have FooA, FooB, etc. subclass Foo as before. They'll >> automatically get the attributes generated. > > Thanks for the feedback! I am thrilled that an actual real-life > issue I'm having may be resolvable by metaclasses (which so far > I've only admired from afar but never considered relevant to my > day-to-day work), I thought this a really nice example of metaclass use too. > but unfortunately I'm still struggling to get > this to work. > > If I add your code, what happens is that the Foo class will try > to read "Foo.tmpl", which does not exist -- it is only the > derived classes FooA etc, that need to execute this code, not Foo > itself. My simpleminded solution to the above would be to create a dummy Foo.tmpl file, so it does exist. Or, in __new__ above, conditionalize the fetch: if name != 'Foo': ... Terry Jan Reedy From lacrima.maxim at gmail.com Tue Feb 16 12:08:00 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Tue, 16 Feb 2010 09:08:00 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> Message-ID: <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> On Feb 15, 9:56?pm, Phlip wrote: > Lacrima wrote: > > Thanks for your reply! Isn't what you are talking about integration > > tests? And unit tests should be fully isolated? So even for method > > 'some_method()' of class A I should mock instance of class A (i.e. to > > mock 'self') to test 'some_method()'. > > "Unit test" is a high-end QA concept. Developers can get the best > return on "developer tests". They don't bother with aerospace-quality > isolation between units. > > If a TDD test needs to pull in a bunch of modules to pass, that's > generally a good thing, because they all get indirect testing. If they > catch a bug, their local tests might not catch it, but the higher > level tests still have a chance. > > (And if your product still needs unit tests, TDD will make them very > easy for a formal QA team to add.) > > However, expensive setup is a design smell. That means if a test case > requires too many lines of code for its Assemble phase (before its > Activate and Assert phases), then maybe those lines of code support > objects that are too coupled, and they need a better design. > > Throwing mocks at these objects, instead of decoupling them, will > "perfume" the design smell, instead of curing it. > > > > "construction encapsulation") > > And could you give an example. > > ? def test_frob(self): > ? ? ? frob = Frob() > ? ? ? frob.knob = Mock() > ? ? ? frob.knob.value = Mock(return_value = 42) > ? ? ? assert 42 == frob.method_using_knob() > > We need the mock because we can't control how Frob's constructor built > its knob. So instead, give Frob the option to construct with a Knob: > > ? def test_frob(self): > ? ? ? knob = Knob(42) > ? ? ? frob = Frob(knob) > ? ? ? assert frob.method_using_knob() > > Note that in production the Knob constructor never takes a Knob. Maybe > we should upgrade the production code too (!), or maybe Knob's > constructor should only create a knob if it didn't get passed one. > Either technique is acceptable, because the resulting code decouples > Frobs and Knobs just a little bit more. > > > For me it's really hard to develop test first. Often I don't know what > > tests to write to replace hardcoded return values by objects that > > perform actual work. > > You have read too many books on TDD. C-: > > Alternate between writing lines of test and lines of code. Run the > tests after the fewest possible edits, and always correctly predict if > the tests will pass, or will fail, and with what diagnostic. (And > configure your editor to run the stankin tests, no matter how hard it > fights you!) The high-end tricks will get easier after you get the > basic cycle down. > > -- > ? Phlip > ?http://c2.com/cgi/wiki?ZeekLand Hi Phlip! Thanks for your exhaustive answer. Actually, I'll investigate your example with 'frob'. From just reading the example it's not clear for me what I will benefit, using this approach. And I have already refused to write totally isolated tests, because it looks like a great waste of time. From phlip2005 at gmail.com Tue Feb 16 12:38:09 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Feb 2010 09:38:09 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> Message-ID: <07d50b9f-c4bb-4d49-82d0-bd6d1c2e42be@z10g2000prh.googlegroups.com> On Feb 16, 9:08?am, Lacrima wrote: > Thanks for your exhaustive answer. > Actually, I'll investigate your example with 'frob'. From just reading > the example it's not clear for me what I will benefit, using this > approach. I can't get a good hit for "construction encapsulation" in Google. (Although I got some good bad ones!) This paper _almost_ gets the idea: http://www.netobjectives.com/download/Code%20Qualities%20and%20Practices.pdf > And I have already refused to write totally isolated tests, because it > looks like a great waste of time. Do you run your tests after the fewest possible edits? Such as 1-3 lines of code? I'm not sure why the TDD books don't hammer that point down... -- Phlip http://c2.com/cgi/wiki?ZeekLand From deets at nospam.web.de Tue Feb 16 13:20:03 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 16 Feb 2010 19:20:03 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> Message-ID: <7u05ulFfmkU1@mid.uni-berlin.de> Am 15.02.10 23:12, schrieb Florian Ludwig: > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: >>> Here there problem with the trac (and other plugin systems I've >> seen) >>> approach: >>> >>> You need to define something like: >>> | >>> | class IAuthPlugin(Interface): [...] >>> | >>> in your blog software. >> >> Why? Any reason you can't define it in a separate package the >> blog-software depends on, as well as your wiki? > > That's actually my point - most plugin systems I've seen, like the one > trac uses, are not encouraging you to do so. Having a module that just > defines an Interface is kind of weird - and in the real world no one is > doing it. Just because nobody doesn't do it doesn't mean it's not desirable. IMHO the ones using interfaces usually immediatly implement them for some cases - so you actually get the interface for you authentication framework, and also implement an OpenID plugin for it. And this forms one package. Then you can add new packages that implement other things. repoze.who and what are examples for such design. > >> And then of course, this is not really needed. In Python, behavior >> counts, not type-information. So you can get away without any explicit >> declared interface. You might chose to not do that, for aestetic >> reasons, or better documentation. But you aren't forced. > > Actually some plugin-systems in python do force you and they check if > your "implementation" comply with the "interface". I didn't say nobody does it, I just said it isn't needed to get a working plugin system. If you don't want to have a separate package *and* don't want to pull in any unused code, this is pretty much your only option. > Here is one solution I came up with. Based on the earlier example: >>> Lets say you program a wiki and like to allow different kind of >>> authentications. So you create two plugins (for example one for >>> OpenID and one for Shibboleth). >>> >>> Some time later you feel like reinventing the wheel again and >>> you program a blog. Again you like to allow different ways of >>> authentication and you already wrote plugins for exactly the >>> same for your wiki, right? > > auth_openid.py - providing the authentication service > http://dpaste.com/hold/159619/ > > wiki.py - providing the wiki > http://dpaste.com/hold/159634/ > > Now putting both together: > >> import pbus >> >> import wiki >> import auth_openid >> # or: import auth_shibboleth >> >> pbus.get("wiki").run() > > No interface definitions. > > > What do you think? Any obvious pitfalls (besides reinventing something)? I don't know what pbus is supposed to do. Nor how it's laid out on a python package level. Diez From caseyhHAMMER_TIME at istar.ca Tue Feb 16 13:32:51 2010 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Tue, 16 Feb 2010 10:32:51 -0800 Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? Message-ID: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? -- Regards, Casey From caseyhHAMMER_TIME at istar.ca Tue Feb 16 13:38:41 2010 From: caseyhHAMMER_TIME at istar.ca (Casey Hawthorne) Date: Tue, 16 Feb 2010 10:38:41 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. Message-ID: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-death.html -- Regards, Casey From mattbarkan at gmail.com Tue Feb 16 13:58:27 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 10:58:27 -0800 (PST) Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <87aavac7u8.fsf@benfinney.id.au> Message-ID: <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> Hey all, thanks as always for the quick responses. I actually found a very simple way to do what I needed to do. In short, I needed to take an email which had a large number of addresses in the 'to' field, and place just the identifiers (everything to the left of @domain.com), in a python list. I simply highlighted all the addresses and placed them in a text file called emails.txt. Then I had the following code which placed each line in the file into the list 'names': [code] fileHandle = open('/Users/Matt/Documents/python/results.txt','r') names = fileHandle.readlines() [/code] Now, the 'names' list has values looking like this: ['aaa12 at domain.com \n', 'bbb34 at domain.com\n', etc]. So I ran the following code: [code] for x in names: st_list.append(x.replace('@domain.com\n','')) [/code] And that did the trick! 'Names' now has ['aaa12', 'bbb34', etc]. Obviously this only worked because all of the domain names were the same. If they were not then based on your comments and my own research, I would've had to use regex and the split(), which looked massively complicated to learn. Thanks all. Matt On Feb 15, 8:01?pm, Ben Finney wrote: > galileo228 writes: > > I'm trying to write python code that will open a textfile and find the > > email addresses inside it. I then want the code to take just the > > characters to the left of the "@" symbol, and place them in a list. > > Email addresses can have more than one ?@? character. In fact, the > quoting rules allow the local-part to contain *any ASCII character* and > remain valid. > > > Any suggestions would be much appeciated! > > For a brief but thorough treatment of parsing email addresses, see RFC > 3696, ?Application Techniques for Checking and Transformation of Names? > , specifically section 3. > > -- > ?\ ? ? ? ? ??What I have to do is see, at any rate, that I do not lend | > ? `\ ? ? ?myself to the wrong which I condemn.? ?Henry Thoreau, _Civil | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Disobedience_ | > Ben Finney From andrej.mitrovich at gmail.com Tue Feb 16 14:41:58 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Tue, 16 Feb 2010 11:41:58 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: Message-ID: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> On Feb 16, 7:38?pm, Casey Hawthorne wrote: > Interesting talk on Python vs. Ruby and how he would like Python to > have just a bit more syntactic flexibility. > > http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > -- > Regards, > Casey Gary's friend Geoffrey Grosenbach says in his blog post (which Gary linked to): "Python has no comparable equivalent to Ruby?s do end block. Python lambdas are limited to one line and can?t contain statements (for, if, def, etc.). Which leaves me wondering, what?s the point?" I'm sorry, lambda's do support if's and for's. Also, lambda's are expressions, not statements, but you can pass them around, keep them in a dictionary if you want to. And if you need more than one line of statements, for crying out loud use a def? And who needs those "do- end" blocks anyway, trying to turn Python into Pascal? From aahz at pythoncraft.com Tue Feb 16 14:44:45 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Feb 2010 11:44:45 -0800 Subject: Is there a simple way to find the list index to the max value? References: <4B7A91B1.6030301@lonetwin.net> Message-ID: In article <4B7A91B1.6030301 at lonetwin.net>, steve wrote: >On 02/16/2010 05:49 PM, W. eWatson wrote: >> >> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. > >The most obvious would be a.index(max(a)). Is that what you wanted ? The disadvantage of that is that it's O(2N) instead of O(N). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From dino at phidev.org Tue Feb 16 14:50:39 2010 From: dino at phidev.org (Florian Ludwig) Date: Tue, 16 Feb 2010 20:50:39 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <1266271943.4299.2887.camel@brain> Message-ID: <1266349839.10498.240.camel@brain> On Tue, 2010-02-16 at 16:14 +0100, Paul K?lle wrote: > Am 15.02.2010 23:12, schrieb Florian Ludwig: > > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: > >> [...] > >> And then of course, this is not really needed. In Python, behavior > >> counts, not type-information. So you can get away without any > >> explicit > >> declared interface. You might chose to not do that, for aestetic > >> reasons, or better documentation. But you aren't forced. > > > > Actually some plugin-systems in python do force you and they check > > if your "implementation" comply with the "interface". > Which is a good thing IMO ;) Type checking might be good but not pythonic - imo. The problem with having interfaces needed to be declared (and therefore the possibility to check) is as I outlined in my first mail: Where to put those interface descriptions if you want both sides pluggable? You probably end up depending on other modules/projects just to import the interfaces. > > Here is one solution I came up with. > [...] > Can you post working code? It's not clear what "pbus" is and how it > works. Oh, sorry. The idea is similar to "d-bus" - hence the name. Its "the communcation system". The code is pretty simple and quick. Please remember its just to show of the concept not to use it in any production software or anything. Instead of using classes as connecting-piece I thought using strings (maybe path "/plugin/wiki" or "org.example.wiki") might solve my problem. It might be possible to add optional interface validation though. pbus.py - just a simple concept implementation of a framework http://dpaste.com/hold/159980/ auth_openid.py - providing the authentication service http://dpaste.com/hold/159619/ wiki.py - providing the wiki http://dpaste.com/hold/159634/ Now putting both together: > import pbus > > import wiki > import auth_openid > # or: import auth_shibboleth > > pbus.get("wiki").run() -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From mail at timgolden.me.uk Tue Feb 16 14:53:18 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 16 Feb 2010 19:53:18 +0000 Subject: Is there a simple way to find the list index to the max value? In-Reply-To: References: <4B7A91B1.6030301@lonetwin.net> Message-ID: <4B7AF7AE.6040401@timgolden.me.uk> On 16/02/2010 19:44, Aahz wrote: > In article<4B7A91B1.6030301 at lonetwin.net>, steve wrote: >> On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >> The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disadvantage of that is that it's O(2N) instead of O(N). Well you could do this: a.sort () return -1 TJG From nagle at animats.com Tue Feb 16 15:15:05 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Feb 2010 12:15:05 -0800 Subject: The future of "frozen" types as the number of CPU cores increases Message-ID: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> In the beginning, Python had some types which were "frozen", and some which weren't. Now, there's a trend towards having both "frozen" and "unfrozen" versions of built-in types. We now have "frozen" and "unfrozen" sets, dictionaries, and byte arrays. It's becoming clear that that the concept of "frozen" is separate from the type involved. Maybe "frozen" should be generalized, so that all "unfrozen" objects also have "frozen" versions. I'd suggest p = freeze(q) which would generate a "frozen" copy of q. (For lists, this would return a tuple. For unfrozen sets, a frozen set. Etc.) p = deepfreeze(q) would generate "frozen" deep copy of q, for which each object it references is also a "frozen" copy. For objects, class c(frozenobject) : def __init__(self, someparam) : self.p = someparam ... would result in a class which returns frozen objects from the constructor. In concurrent programs, frozen objects can be shared without locking. This simplifies locking considerably. This may provide a way to get out from the Global Interpreter Lock. One possible implementation would be to have unfrozen objects managed by reference counting and locking as in CPython. Frozen objects would live in a different memory space and be garbage collected by a concurrent garbage collector. If we add "synchronized" objects with built-in locking, like Java, threading becomes much cleaner. class d(synchronized) : ... A typical "synchronized" object would be a queue. Anything with state shared across threads has to be synchronized. Only one thread at a time can be active within a synchronized object, due to a built-in implicit lock. Semantics of synchronized objects: "Synchronized" objects cannot be frozen. Trying to freeze them just returns the object. If a thread blocks on an explicit "wait", the synchronized object is temporarily unlocked during the "wait". This allows threads to wait for, say, a queue to get another entry from another thread. If only synchronized objects and frozen objects can be shared across threads, the GIL becomes unnecessary. Big performance win on multicore CPUs. "Synchronized" was a pain in Java because Java doesn't have "frozen" objects. Too much effort went into synchronizing little stuff. But in a language with frozen objects, the little stuff would be frozen, and wouldn't need its own locks. Threaded programs that already use queue objects to communicate with each other are almost ready for this kind of architecture now. If the queue class made a frozen copy of any unfrozen, unsynchronized copy placed on a queue, conversion to this approach could be almost automatic. What would probably happen in practice is that potential race conditions in existing programs would raise "unshareable object" exceptions, indicating that something needed to be synchronized. That's a good thing. This approach makes threading much easier for the typical programmer. Instead of race conditions and random errors, you get error messages. And we get rid of the GIL. I look at this as Python's answer to multicore CPUs and "Go". John Nagle From alfps at start.no Tue Feb 16 15:15:11 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 16 Feb 2010 21:15:11 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: * Steve Holden: > Alf P. Steinbach wrote: > [...] >>> I'll do some further research to see what's going on there. >> Cheers, >> >> - Alf (is this off-topic for the group?) > > It's gone a lot further off than this without anyone complaining. I > think your experiences to date should convince you that you can rely on > being told when you drift too far off-topic :) Some old folks' music, Eternity's Breath & Stratus; the guy playing is 65: Hip hoppers may skip the 80 seconds complicated intro. It is relevant in a way, although very indirectly. For although the comment did not pop up here, many Satch videos (this is not Satch) have comments like "How on Earth can he remember all those notes?" And he doesn't. It's not memorization: one can't create at this level by memorizing notes or rules. It's an understanding of the tool one uses and what one wants to create and the basic themes, and in this video it's also the synergy effect of four people doing that, creating together something they can't quite believe they're doing, so you have four madly grinning world class musicians -- and audience... :-) - Alf From python.list at tim.thechases.com Tue Feb 16 15:15:30 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 16 Feb 2010 14:15:30 -0600 Subject: Parsing for email addresses In-Reply-To: <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <87aavac7u8.fsf@benfinney.id.au> <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> Message-ID: <4B7AFCE2.7080708@tim.thechases.com> galileo228 wrote: > [code] > fileHandle = open('/Users/Matt/Documents/python/results.txt','r') > names = fileHandle.readlines() > [/code] > > Now, the 'names' list has values looking like this: ['aaa12 at domain.com > \n', 'bbb34 at domain.com\n', etc]. So I ran the following code: > > [code] > for x in names: > st_list.append(x.replace('@domain.com\n','')) > [/code] > > And that did the trick! 'Names' now has ['aaa12', 'bbb34', etc]. > > Obviously this only worked because all of the domain names were the > same. If they were not then based on your comments and my own > research, I would've had to use regex and the split(), which looked > massively complicated to learn. The complexities stemmed from several factors that, with more details, could have made the solutions less daunting: (a) you mentioned "finding" the email addresses -- this makes it sound like there's other junk in the file that has to be sifted through to find "things that look like an email address". If the sole content of the file is lines containing only email addresses, then "find the email address" is a bit like [1] (b) you omitted the detail that the domains are all the same. Even if they're not the same, (a) reduces the problem to a much easier task: s = set() for line in file('results.txt'): s.add(line.rsplit('@', 1)[0].lower()) print s If it was previously a CSV or tab-delimited file, Python offers batteries-included processing to make it easy: import csv f = file('results.txt', 'rb') r = csv.DictReader(f) # CSV # r = csv.DictReader(f, delimiter='\t') # tab delim s = set() for row in r: s.add(row['Email'].lower()) f.close() or even f = file(...) r = csv.DictReader(...) s = set(row['Email'].lower() for row in r) f.close() Hope this gives you more ideas to work with. -tkc [1] http://jacksmix.files.wordpress.com/2007/05/findx.jpg From nad at acm.org Tue Feb 16 15:26:29 2010 From: nad at acm.org (Ned Deily) Date: Tue, 16 Feb 2010 12:26:29 -0800 Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 References: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> Message-ID: In article <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482 at r24g2000yqd.googlegroups.com>, seth wrote: > We have a code that creates a simple Python shelve database. We are > able to serialize objects and store them in the dbm file. This seem to > work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6, > but on Os X 10.5 with Python 2.5 the database filename is changed by > the operating system by attaching the .db extension to it. Does an one > know why is that? It's a documented "feature": it depends on the underlying database package used by shelve. http://docs.python.org/library/shelve.html "As a side-effect, an extension may be added to the filename ..." -- Ned Deily, nad at acm.org From ben+python at benfinney.id.au Tue Feb 16 15:30:42 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 17 Feb 2010 07:30:42 +1100 Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> Message-ID: <87sk90c499.fsf@benfinney.id.au> Lacrima writes: > And I have already refused to write totally isolated tests, because it > looks like a great waste of time. It only looks like that until you chase your tail in a long, fruitless debugging session because (you later realise) the behaviour of one test is being affected by another. Test isolation is essential to ensure that your tests are doing what you think they're doing. -- \ ?A ?No? uttered from deepest conviction is better and greater | `\ than a ?Yes? merely uttered to please, or what is worse, to | _o__) avoid trouble.? ?Mohandas K. Gandhi | Ben Finney From pecora at anvil.nrl.navy.mil Tue Feb 16 15:31:33 2010 From: pecora at anvil.nrl.navy.mil (Lou Pecora) Date: Tue, 16 Feb 2010 15:31:33 -0500 Subject: A fix for pylab and TkAgg plotting in SAGE (Mac OS X) Message-ID: A few weeks ago I posted a problem with Mac OS X with matplotlib in the SAGE distribution in which attempting to import pylab gave an error message which stated that there was an import error and the module _tkagg could not be found. The problem appears to be with matplotlib (I'm not clear about this). After much searching and some emailing I have found a solution to this problem and it is easy to do. Full credit goes to Eric Sonnendrucker who sent it to me. Here it is: 1) Download the Tcl/Tk sources (go to http://www.tcl.tk/, click on Get Tcl/Tk Now, click on Sources Download Page,, download the latest version). 2) In the Terminal cd to the unix folder in the tcl folder. Compile the unix version (of Tcl and Tk) as follows ./configure --enable-framework --disable-xft make make install 3) Install SAGE from source. Download the SAGE source code (go to http://www.sagemath.org/, click on Download, click on Download complete source code). In the terminal cd to the SAGE folder and *before* you run the sage install you need to set SAGE_MATPLOTLIB_GUI=True using export SAGE_MATPLOTLIB_GUI=True with bash. The installer then picks it up automatically. Complete the SAGE installation by typing make and hit return. That's it. This will take a while (up to a few hours depending on the computer). 4) You might also need to modify you matplotlibrc by setting backend='TkAgg' after the installation Test this by doing an import pylab in sage. You should not get an error. -- -- Lou Pecora From debatem1 at gmail.com Tue Feb 16 16:12:51 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 16 Feb 2010 16:12:51 -0500 Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? In-Reply-To: References: Message-ID: Ok, I'll admit- my hand hovered over the 'initiate flamewar' button for a moment before I figured out what you were actually asking. And I know I'm working on it, which probably means 8 or 9 others are as well. Geremy Condra From wolftracks at invalid.com Tue Feb 16 16:23:48 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 16 Feb 2010 13:23:48 -0800 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 Message-ID: I've finally decided to see if I could make an executable out of a py file. Win7. Py2.5. I brought down the install file and proceeded with the install. I got two warning messages. Forgot the first. The second said,"Could not set the key value." I again used OK. I think that was the only choice. It then issued a message in a larger dialog. It was about setting a key, and pointed me to a log. It mentions a Removepy2exe -u Although it finished, I have no idea where the program is. It does not show up on the Start menu All Programs List nore my desktop. What's up? I've had these messages (key) occur on other Python installs as I transition to Win7. So far no problem. From doron.tal.list at gmail.com Tue Feb 16 16:37:30 2010 From: doron.tal.list at gmail.com (Doron Tal) Date: Tue, 16 Feb 2010 23:37:30 +0200 Subject: GIL state during import Message-ID: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Is the GIL released during import statement execution when accessing the file? If not, is it a bug? If it is not a bug, or it is here to stay for any other reason, I think it should be mentioned in the documentation. --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From userprogoogle-139 at yahoo.co.uk Tue Feb 16 16:41:21 2010 From: userprogoogle-139 at yahoo.co.uk (rodmc) Date: Tue, 16 Feb 2010 13:41:21 -0800 (PST) Subject: Shipping Executables Message-ID: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Hi, I have been merrily programming away in Python now for a few years and have a couple of applications I would like to possibly publish at some point - with the exception of certain libraries they are more or less 100% Python. However I have read elsewhere online that Python due to it's architecture is not so good for this, especially as it is easier for people to hack into the code. Also where software requires some security aspects I guess it would also not be much use, is this correct? Anyway I would appreciate any views or tips that people have? Kind regards, rod From hklasky at gmail.com Tue Feb 16 17:03:55 2010 From: hklasky at gmail.com (seth) Date: Tue, 16 Feb 2010 14:03:55 -0800 (PST) Subject: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5 References: <7a9d26a8-0a9f-4bf3-bf50-0ac5e337f482@r24g2000yqd.googlegroups.com> Message-ID: On Feb 14, 1:21 pm, a... at pythoncraft.com (Aahz) wrote: > Nope -- any reason you can't change the filename? > -- Os X 10.5 did not recognized the dbm extension. But, I have been able to fix the problem (hope it helps somebody): At http://docs.python.org/library/shelve.html it says: "shelve.open(filename[, flag='c'[, protocol=None[, writeback=False]]])? Open a persistent dictionary. The filename specified is the base filename for the underlying database. As a side-effect, an extension may be added to the filename and more than one file may be created. By default, the underlying database file is opened for reading and writing. " Then, I went ahead and try to find out which type of db file was being created: print whichdb.whichdb(dbmFile)#prints bsddb185 kpfmac:xLPR kpf$ python Python 2.5.1 (r251:54863, Feb 9 2009, 18:49:36) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import bsddb185 >>> bsddb185.open('realizations.db') I found that the dbm extension is generated by bsddb and bsddb3 so I went ahead and installed it: sudo easy_install bsddb3. Finally, in our code, I just went ahead and instead of using shelve.open, I am calling shelve.BsdDbShelf(bsddb3.btopen(filename, 'c')) #realizations=shelve.open( filename, 'c', 2, writeback = False ) #hk 021010: need to use BsdDbShelf to ensure the usage of bsddb3 on OsX 10.5 #shelve.open creates a bsddb185 file on OsX 10.5 #but shelve.open on OsX reads with bsddb3, who knows why... #as a result the shelve.open throws # (22, 'Invalid argument') dbshelf=shelve.BsdDbShelf(bsddb3.btopen(filename, 'c')) realizations=dbshelf And that fixed on Os X 10.5. It also works fine on Windows, by ensuring the proper import: try: import bsddb3 except: import bsddb as bsddb3 From arnodel at googlemail.com Tue Feb 16 17:21:06 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 16 Feb 2010 22:21:06 +0000 Subject: Is there a simple way to find the list index to the max value? References: <4B7A91B1.6030301@lonetwin.net> Message-ID: aahz at pythoncraft.com (Aahz) writes: > In article <4B7A91B1.6030301 at lonetwin.net>, steve wrote: >>On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >>The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disadvantage of that is that it's O(2N) instead of O(N). :-) Joke aside, even though you traverse the list twice, it may still be quicker than other solutions because both max and list.index are C functions and no intermediate object is constructed. -- Arnaud From debatem1 at gmail.com Tue Feb 16 17:25:53 2010 From: debatem1 at gmail.com (geremy condra) Date: Tue, 16 Feb 2010 17:25:53 -0500 Subject: Shipping Executables In-Reply-To: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: On Tue, Feb 16, 2010 at 4:41 PM, rodmc wrote: > Hi, > > I have been merrily programming away in Python now for a few years and > have a couple of applications I would like to possibly publish at some > point - with the exception of certain libraries they are more or less > 100% Python. However I have read elsewhere online that Python due to > it's architecture is not so good for this, especially as it is easier > for people to hack into the code. If you mean that it is difficult to stop people from modifying the source code, then you're correct. If you mean that python programs are more likely to have security problems than, say, C, I think its safe to assume that you're not correct about that. > Also where software requires some > security aspects I guess it would also not be much use, is this > correct? I've never had any reason to feel more concerned about the code that I write in python, and I use it for crypto research. > Anyway I would appreciate any views or tips that people have? I'd worry about developing a product worth stealing before I worried about people stealing it ;) Geremy Condra From phlip2005 at gmail.com Tue Feb 16 17:50:10 2010 From: phlip2005 at gmail.com (Phlip) Date: Tue, 16 Feb 2010 14:50:10 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: <35d8fe79-4f3f-4742-ba0f-66e3b5a4c7bd@t17g2000prg.googlegroups.com> On Feb 16, 12:30?pm, Ben Finney wrote: > Lacrima writes: > > And I have already refused to write totally isolated tests, because it > > looks like a great waste of time. > > It only looks like that until you chase your tail in a long, fruitless > debugging session because (you later realise) the behaviour of one test > is being affected by another. Test isolation is essential to ensure that > your tests are doing what you think they're doing. That is runtime test isolation. It's not the same thing as "unit test isolation". Just take care in your tearDown() to scrub your environment. Google "Mock abuse" from here... -- Phlip From tjreedy at udel.edu Tue Feb 16 17:57:28 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Feb 2010 17:57:28 -0500 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: On 2/16/2010 3:15 PM, John Nagle wrote: > In the beginning, Python had some types which were "frozen", > and some which weren't. In the beginning, there was only one 'frozen' general purpose collection type, the tuple. And Guido resisted the suggestion that lists and tuple were mutable and frozen versions of each other. However, things have changed, and lists and tuple *are* effectively mutable and hashable versions of each other, and we have the three other pairs you mentioned. The idea of freeze() may have been floated (and punctured) during Py3 discussions, but I think it a fairly good one. Terry Jan Reedy From tjreedy at udel.edu Tue Feb 16 18:01:08 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Feb 2010 18:01:08 -0500 Subject: GIL state during import In-Reply-To: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Message-ID: On 2/16/2010 4:37 PM, Doron Tal wrote: > Is the GIL released during import statement execution when accessing the > file? > If not, is it a bug? > If it is not a bug, or it is here to stay for any other reason, I think > it should be mentioned in the documentation. The CPython GIL is a CPython implementation artifact and should not be mentioned in the language docs (and is not, as far as I know). Were you thinking of something else? And why this specific feature of its behavior, whatever it is. tjr From steve at REMOVE-THIS-cybersource.com.au Tue Feb 16 18:19:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 16 Feb 2010 23:19:03 GMT Subject: ANN: obfuscate 0.2.2b Message-ID: <4b7b27e7$0$8819$c3e8da3@news.astraweb.com> I am pleased to announce the beta release of obfuscate 0.2.2b. http://pypi.python.org/pypi/obfuscate/ The beta release does not contain any new functionality from the previous version, but includes bug fixes and many new tests. obfuscate is a pure-Python module providing classical encryption algorithms suitable for obfuscating and unobfuscating text. obfuscate includes the following ciphers: - Caesar, rot13, rot5, rot18, rot47 - atbash - Playfair, Playfair6 and Playfair16 - Railfence (encryption only) - Keyword - Affine - Vigenere - frob (xor) and others. DISCLAIMER: obfuscate is not cryptographically strong, and should not be used where high security is required. (The ciphers provided in obfuscate may have been state of the art centuries ago, but should not be used where strong encryption is required. obfuscate is released under the MIT licence. Requires Python 2.5 or 2.6. From db3l.net at gmail.com Tue Feb 16 18:34:13 2010 From: db3l.net at gmail.com (David Bolen) Date: Tue, 16 Feb 2010 18:34:13 -0500 Subject: listing existing windows services with python References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: alex23 writes: > News123 wrote: >> What is the best way with python to get a list of all windows services. >> >> As a start I would be glad to receive only the service names. >> >> However it would be nicer if I could get all the properties of a service >> as well. > > I highly recommend Tim Golden's fantastic WMI module[1]. Another alternative is the win32service module from the pywin32 package (which IMO you'll almost certainly want available when doing any significant Windows-specific operations) which wraps the native win32 libraries for enumerating, querying and controlling services. A simple loop could use EnumServicesStatus to iterate through the services, OpenService with the SERVICE_QUERY_CONFIG flag to get a handle to each service, and then QueryServiceConfig to retrieve configuration information. Since pywin32 is a relatively thin wrapper over the win32 libraries, pure MSDN documentation can be used for help with the calls, augmented by any Python-related information contained in the pywin32 documentation. -- David From xiajunyi at gmail.com Tue Feb 16 18:48:17 2010 From: xiajunyi at gmail.com (Imaginationworks) Date: Tue, 16 Feb 2010 15:48:17 -0800 (PST) Subject: How to efficiently extract information from structured text file Message-ID: Hi, I am trying to read object information from a text file (approx. 30,000 lines) with the following format, each line corresponds to a line in the text file. Currently, the whole file was read into a string list using readlines(), then use for loop to search the "= {" and "};" to determine the Object, SubObject,and SubSubObject. My questions are 1) Is there any efficient method that I can search the whole string list to find the location of the tokens(such as '= {' or '};' 2) Is there any efficient ways to extract the object information you may suggest? Thanks, - Jeremy ===== Structured text file ================= Object1 = { ... SubObject1 = { .... SubSubObject1 = { ... }; }; SubObject2 = { .... SubSubObject21 = { ... }; }; SubObjectN = { .... SubSubObjectN = { ... }; }; }; From mattbarkan at gmail.com Tue Feb 16 19:07:57 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 16:07:57 -0800 (PST) Subject: Parsing for email addresses References: <26660eb6-0c49-4251-92d8-d3c13e071ba5@k11g2000vbe.googlegroups.com> <87aavac7u8.fsf@benfinney.id.au> <8bc76e9f-be88-43db-9792-205621b93364@t1g2000vbq.googlegroups.com> Message-ID: <814bb446-6fe5-42cb-9033-c330e74f6123@b7g2000yqd.googlegroups.com> Tim - Thanks for this. I actually did intend to have to sift through other junk in the file, but then figured I could just cut and paste emails directly from the 'to' field, thus making life easier. Also, in this particular instance, the domain names were the same, and thus I was able to figure out my solution, but I do need to know how to handle the same situation when the domain names are different, so your response was most helpful. Apologies for leaving out some details. Matt On Feb 16, 3:15?pm, Tim Chase wrote: > galileo228 wrote: > > [code] > > fileHandle = open('/Users/Matt/Documents/python/results.txt','r') > > names = fileHandle.readlines() > > [/code] > > > Now, the 'names' list has values looking like this: ['aa... at domain.com > > \n', 'bb... at domain.com\n', etc]. So I ran the following code: > > > [code] > > for x in names: > > ? ? st_list.append(x.replace('... at domain.com\n','')) > > [/code] > > > And that did the trick! 'Names' now has ['aaa12', 'bbb34', etc]. > > > Obviously this only worked because all of the domain names were the > > same. If they were not then based on your comments and my own > > research, I would've had to use regex and the split(), which looked > > massively complicated to learn. > > The complexities stemmed from several factors that, with more > details, could have made the solutions less daunting: > > ? ?(a) you mentioned "finding" the email addresses -- this makes > it sound like there's other junk in the file that has to be > sifted through to find "things that look like an email address". > If the sole content of the file is lines containing only email > addresses, then "find the email address" is a bit like [1] > > ? ?(b) you omitted the detail that the domains are all the same. > ? Even if they're not the same, (a) reduces the problem to a much > easier task: > > ? ?s = set() > ? ?for line in file('results.txt'): > ? ? ?s.add(line.rsplit('@', 1)[0].lower()) > ? ?print s > > If it was previously a CSV or tab-delimited file, Python offers > batteries-included processing to make it easy: > > ? ?import csv > ? ?f = file('results.txt', 'rb') > ? ?r = csv.DictReader(f) ?# CSV > ? ?# r = csv.DictReader(f, delimiter='\t') # tab delim > ? ?s = set() > ? ?for row in r: > ? ? ?s.add(row['Email'].lower()) > ? ?f.close() > > or even > > ? ?f = file(...) > ? ?r = csv.DictReader(...) > ? ?s = set(row['Email'].lower() for row in r) > ? ?f.close() > > Hope this gives you more ideas to work with. > > -tkc > > [1]http://jacksmix.files.wordpress.com/2007/05/findx.jpg From jgardner at jonathangardner.net Tue Feb 16 19:19:07 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 16 Feb 2010 16:19:07 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> On Feb 16, 11:41?am, Andrej Mitrovic wrote: > On Feb 16, 7:38?pm, Casey Hawthorne > wrote: > > > Interesting talk on Python vs. Ruby and how he would like Python to > > have just a bit more syntactic flexibility. > > >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > > -- > > Regards, > > Casey > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > linked to): "Python has no comparable equivalent to Ruby?s do end > block. Python lambdas are limited to one line and can?t contain > statements (for, if, def, etc.). Which leaves me wondering, what?s the > point?" > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > expressions, not statements, but you can pass them around, keep them > in a dictionary if you want to. And if you need more than one line of > statements, for crying out loud use a def? And who needs those "do- > end" blocks anyway, trying to turn Python into Pascal? I used to think anonymous functions (AKA blocks, etc...) would be a nice feature for Python. Then I looked at a stack trace from a different programming language with lots of anonymous functions. (I believe it was perl.) I became enlightened. From philip at semanchuk.com Tue Feb 16 19:22:40 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Tue, 16 Feb 2010 19:22:40 -0500 Subject: Shipping Executables In-Reply-To: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> On Feb 16, 2010, at 4:41 PM, rodmc wrote: > Hi, > > I have been merrily programming away in Python now for a few years and > have a couple of applications I would like to possibly publish at some > point - with the exception of certain libraries they are more or less > 100% Python. However I have read elsewhere online that Python due to > it's architecture is not so good for this, especially as it is easier > for people to hack into the code. Also where software requires some > security aspects I guess it would also not be much use, is this > correct? Hi Rod, The user's ability to hack into the code is usually considered one of the strengths of Python & open source software in general. Since most Python software that's distributed is open source, you're doing something different than most. It'd help if you explain how you want your software to differ from a typical open source distribution. Do you not want people to change the code? Are you worried about your code & ideas being stolen? bye Philip From rhodri at wildebst.demon.co.uk Tue Feb 16 19:29:44 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 17 Feb 2010 00:29:44 -0000 Subject: How to efficiently extract information from structured text file References: Message-ID: On Tue, 16 Feb 2010 23:48:17 -0000, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. My > questions are > > 1) Is there any efficient method that I can search the whole string > list to find the location of the tokens(such as '= {' or '};' The usual idiom is to process a line at a time, which avoids the memory overhead of reading the entire file in, creating the list, and so on. Assuming your input file is laid out as neatly as you said, that's straightforward to do: for line in myfile: if "= {" in line: start_a_new_object(line) elif "};" in line: end_current_object(line) else: add_stuff_to_current_object(line) You probably want more robust tests than I used there, but that depends on how well-defined your input file is. If it can be edited by hand, you'll need to be more defensive! > 2) Is there any efficient ways to extract the object information you > may suggest? That depends on what you mean by "extract the object information". If you mean "get the object name", just split the line at the "=" and strip off the whitespace you don't want. If you mean "track how objects are connected to one another, have each object keep a list of its immediate sub-objects (which will have lists of their immediate sub-objects, and so on); it's fairly easy to keep track of which objects are current using a list as a stack. If you mean something else, sorry but my crystal ball is cloudy tonight. -- Rhodri James *-* Wildebeeste Herder to the Masses From dyamins at gmail.com Tue Feb 16 19:29:55 2010 From: dyamins at gmail.com (Dan Yamins) Date: Tue, 16 Feb 2010 19:29:55 -0500 Subject: Wrap and intercept function calls Message-ID: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> Hi: I'm wondering what the best way to wrap and modify function calls is. Essentially what I want to achieve is to have a function like this: def Wrap(frame,event,arg): if event == 'call': result = PerformCheck(GetArgumentsFromFrame(frame)) if Condition(result): return result else: return [normal function call] called whenever a "call" event is about to occur. When I say "return result" I mean: return that data object instead of what the function would have returned, and prevent execution of the function. Is there any way to do this using sys.settrace? Or perhaps something from the bdb or pbd module? Thanks! Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattbarkan at gmail.com Tue Feb 16 19:31:35 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 16:31:35 -0800 (PST) Subject: Download unnamed web image? Message-ID: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> All, My python program signs onto the student facebook at my school and, given email addresses, returns the associated full name. If I were to do this through a regular browser, there is also a picture of the individual, and I am trying to get my program to download the picture as well. The problem: the html code of the page does not point to a particular file, but rather refers to (what seems like) a query. So, if one went to the facebook and searched for me using my school net id (msb83), the image of my profile on the results page is: msb83 Using BeautifulSoup, mechanize, and urllib, I've constructed the following: br.open("http://www.school.edu/students/facebook/") br.select_form(nr = 1) br.form['fulltextsearch'] = 'msb83' # this searches the facebook for me br.submit() results = br.response().read() soup = BeautifulSoup(results) foo2 = soup.find('td', attrs={'width':'95'}) foo3 = foo2.find('a') foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) # this just drills down to the line and until this point the program does not return an error save_as = os.path.join('./', msb83 + '.jpg') urllib.urlretrieve(foo4, save_as) I get the following error msg after running this code: AttributeError: 'NoneType' object has no attribute 'strip' I can download the picture through my browser by right-clicking, selecting save as, and then the image gets saved as 'deliverImage.cfm.jpeg.' Are there any suggestions as to how I might be able to download the image using python? Please let me know if more information is needed -- happy to supply it. Matt From aahz at pythoncraft.com Tue Feb 16 19:56:11 2010 From: aahz at pythoncraft.com (Aahz) Date: 16 Feb 2010 16:56:11 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: In article <8ca440b2-6094-4b35-80c5-81d000517ce0 at v20g2000prb.googlegroups.com>, Jonathan Gardner wrote: > >I used to think anonymous functions (AKA blocks, etc...) would be a >nice feature for Python. > >Then I looked at a stack trace from a different programming language >with lots of anonymous functions. (I believe it was perl.) > >I became enlightened. +1 QOTW -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From gherron at islandtraining.com Tue Feb 16 20:14:43 2010 From: gherron at islandtraining.com (Gary Herron) Date: Tue, 16 Feb 2010 17:14:43 -0800 Subject: How to efficiently extract information from structured text file In-Reply-To: References: Message-ID: <4B7B4303.2000301@islandtraining.com> Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. My > questions are > > 1) Is there any efficient method that I can search the whole string > list to find the location of the tokens(such as '= {' or '};' > Yes. Read the *whole* file into a single string using file.read() method, and then search through the string using string methods (for simple things) or use re, the regular expression module, (for more complex searches). Note: There is a point where a file becomes large enough that reading the whole file into memory at once (either as a single string or as a list of strings) is foolish. However, 30,000 lines doesn't push that boundary. > 2) Is there any efficient ways to extract the object information you > may suggest? > Again, the re module has nice ways to find a pattern, and return parse out pieces of it. Building a good regular expression takes time, experience, and a bit of black magic... To do so for this case, we might need more knowledge of your format. Also regular expressions have their limits. For instance, if the sub objects can nest to any level, then in fact, regular expressions alone can't solve the whole problem, and you'll need a more robust parser. > Thanks, > > - Jeremy > > > > ===== Structured text file ================= > Object1 = { > > ... > > SubObject1 = { > .... > > SubSubObject1 = { > ... > }; > }; > > SubObject2 = { > .... > > SubSubObject21 = { > ... > }; > }; > > SubObjectN = { > .... > > SubSubObjectN = { > ... > }; > }; > }; > From john at castleamber.com Tue Feb 16 20:48:11 2010 From: john at castleamber.com (John Bokma) Date: Tue, 16 Feb 2010 19:48:11 -0600 Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> Message-ID: <87vddw3a5g.fsf@castleamber.com> galileo228 writes: > Using BeautifulSoup, mechanize, and urllib, I've constructed the > following: > > br.open("http://www.school.edu/students/facebook/") > br.select_form(nr = 1) > > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for > me > br.submit() > results = br.response().read() > soup = BeautifulSoup(results) > foo2 = soup.find('td', attrs={'width':'95'}) > foo3 = foo2.find('a') > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) > # this just drills down to the line and until this point the > program does not return an error > > save_as = os.path.join('./', msb83 + '.jpg') > urllib.urlretrieve(foo4, save_as) > > I get the following error msg after running this code: > > AttributeError: 'NoneType' object has no attribute 'strip' Wild guess, since you didn't provide line numbers, etc. foo4 is None (I also would like to suggest to use more meaningful names) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From pavlovevidence at gmail.com Tue Feb 16 21:04:40 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Tue, 16 Feb 2010 18:04:40 -0800 (PST) Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? References: Message-ID: <009d33cc-75da-4afe-9715-31e820ddc54e@y7g2000prc.googlegroups.com> On Feb 16, 10:32?am, Casey Hawthorne wrote: > Hubris connects Ruby to Haskell, will there be such a connection > between Python and Haskell? I would have expected Hubris to link Ada and Common Lisp together. Carl Banks From steven at REMOVE.THIS.cybersource.com.au Tue Feb 16 21:11:15 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Feb 2010 02:11:15 GMT Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: On Tue, 16 Feb 2010 13:41:21 -0800, rodmc wrote: > Hi, > > I have been merrily programming away in Python now for a few years and > have a couple of applications I would like to possibly publish at some > point - with the exception of certain libraries they are more or less > 100% Python. However I have read elsewhere online that Python due to > it's architecture is not so good for this, especially as it is easier > for people to hack into the code. Looks like you are looking to apply the philosophy "No user serviceable parts inside". > Also where software requires some > security aspects I guess it would also not be much use, is this correct? Absolutely 100% wrong. It is an fundamental principle of security that you must not assume that the enemy is ignorant of your procedures. "Security by obscurity" is not security at all. See, for example: http://en.wikipedia.org/wiki/Kerckhoffs'_Principle If you are trusting that your software will be secure because people cannot read the source code, you have already failed. Hackers break into computer systems without the source code as a matter of course: allowing the source to be available generally makes so little difference as to be no difference. Worse, keeping the source code secret *as a security measure* lulls people into a false sense of security, letting them use weak security confident that since nobody knows how weak it is, it will be strong. That's not how it works. If you have other reasons for wanting to keep the source code secret, that's one thing. But doing it because it is more secure is foolish: software simply isn't more secure when supplied as a binary instead of source code. > Anyway I would appreciate any views or tips that people have? Don't worry about it. If your application is secure, it will be secure even if everybody knows how it works. If it's not secure, then the bad guys will learn how it works even without the source code. -- Steven From mattbarkan at gmail.com Tue Feb 16 21:40:11 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 18:40:11 -0800 (PST) Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> Message-ID: <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> On Feb 16, 8:48?pm, John Bokma wrote: > galileo228 writes: > > Using BeautifulSoup, mechanize, and urllib, I've constructed the > > following: > > > br.open("http://www.school.edu/students/facebook/") > > br.select_form(nr = 1) > > > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for > > me > > br.submit() > > results = br.response().read() > > soup = BeautifulSoup(results) > > foo2 = soup.find('td', attrs={'width':'95'}) > > foo3 = foo2.find('a') > > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) > > # this just drills down to the line and ? until this point the > > program does not return an error > > > save_as = os.path.join('./', msb83 + '.jpg') > > urllib.urlretrieve(foo4, save_as)> > > I get the following error msg after running this code: > > > AttributeError: 'NoneType' object has no attribute 'strip' > > Wild guess, since you didn't provide line numbers, etc. > > foo4 is None > > (I also would like to suggest to use more meaningful names) > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b I thought it was too, and I just doublechecked. It's actually foo3 = foo2.find('a') that is causing the NoneType error. Thoughts? From mattbarkan at gmail.com Tue Feb 16 21:54:58 2010 From: mattbarkan at gmail.com (galileo228) Date: Tue, 16 Feb 2010 18:54:58 -0800 (PST) Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> Message-ID: On Feb 16, 9:40?pm, galileo228 wrote: > On Feb 16, 8:48?pm, John Bokma wrote: > > > > > galileo228 writes: > > > Using BeautifulSoup, mechanize, and urllib, I've constructed the > > > following: > > > > br.open("http://www.school.edu/students/facebook/") > > > br.select_form(nr = 1) > > > > br.form['fulltextsearch'] = 'msb83' # this searches the facebook for > > > me > > > br.submit() > > > results = br.response().read() > > > soup = BeautifulSoup(results) > > > foo2 = soup.find('td', attrs={'width':'95'}) > > > foo3 = foo2.find('a') > > > foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) > > > # this just drills down to the line and ? until this point the > > > program does not return an error > > > > save_as = os.path.join('./', msb83 + '.jpg') > > > urllib.urlretrieve(foo4, save_as)> > > > I get the following error msg after running this code: > > > > AttributeError: 'NoneType' object has no attribute 'strip' > > > Wild guess, since you didn't provide line numbers, etc. > > > foo4 is None > > > (I also would like to suggest to use more meaningful names) > > > -- > > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > I thought it was too, and I just doublechecked. ?It's actually > > foo3 = foo2.find('a') > > that is causing the NoneType error. > > Thoughts? I've now fixed the foo3 issue, and I now know that the problem is with the urllib.urlretrieve line (see above). This is the error msg I get in IDLE: Traceback (most recent call last): File "/Users/Matt/Documents/python/dtest.py", line 59, in urllib.urlretrieve(foo4, save_as) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/urllib.py", line 94, in urlretrieve return _urlopener.retrieve(url, filename, reporthook, data) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/urllib.py", line 226, in retrieve url = unwrap(toBytes(url)) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ python2.6/urllib.py", line 1033, in unwrap url = url.strip() TypeError: 'NoneType' object is not callable Is this msg being generated because I'm trying to retrieve a url that's not really a file? From cournape at gmail.com Tue Feb 16 22:04:33 2010 From: cournape at gmail.com (David Cournapeau) Date: Wed, 17 Feb 2010 12:04:33 +0900 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <5b8d13221002161904s55697ceay6c943e2022f81156@mail.gmail.com> On Wed, Feb 17, 2010 at 4:41 AM, Andrej Mitrovic wrote: > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > linked to): "Python has no comparable equivalent to Ruby?s do end > block. Python lambdas are limited to one line and can?t contain > statements (for, if, def, etc.). Which leaves me wondering, what?s the > point?" > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > expressions, not statements, but you can pass them around, keep them > in a dictionary if you want to. And if you need more than one line of > statements, for crying out loud use a def? I think that's a bit of a strawman: the point made by the OP is that it enables writing simple DSL easier, and the ruby's community seems to value this. They are not advocating using anonymous functions where "normal" functions would do. cheers, David From john at castleamber.com Tue Feb 16 22:11:24 2010 From: john at castleamber.com (John Bokma) Date: Tue, 16 Feb 2010 21:11:24 -0600 Subject: Download unnamed web image? References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> Message-ID: <877hqck143.fsf@castleamber.com> galileo228 writes: > On Feb 16, 9:40?pm, galileo228 wrote: [...] > I've now fixed the foo3 issue, and I now know that the problem is with > the urllib.urlretrieve line (see above). This is the error msg I get > in IDLE: > > Traceback (most recent call last): > File "/Users/Matt/Documents/python/dtest.py", line 59, in > urllib.urlretrieve(foo4, save_as) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 94, in urlretrieve > return _urlopener.retrieve(url, filename, reporthook, data) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 226, in retrieve > url = unwrap(toBytes(url)) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 1033, in unwrap > url = url.strip() > TypeError: 'NoneType' object is not callable > > Is this msg being generated because I'm trying to retrieve a url > that's not really a file? --8<---------------cut here---------------start------------->8--- >>> import urllib; >>> urllib.urlretrieve(None) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/urllib.py", line 89, in urlretrieve return _urlopener.retrieve(url, filename, reporthook, data) File "/usr/lib/python2.5/urllib.py", line 210, in retrieve url = unwrap(toBytes(url)) File "/usr/lib/python2.5/urllib.py", line 1009, in unwrap url = url.strip() AttributeError: 'NoneType' object has no attribute 'strip' --8<---------------cut here---------------end--------------->8--- To me it looks like you're still calling urlretrieve with None as a first value. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From mrabarnett at mrabarnett.plus.com Tue Feb 16 22:14:33 2010 From: mrabarnett at mrabarnett.plus.com (Matthew Barnett) Date: Wed, 17 Feb 2010 03:14:33 +0000 Subject: Download unnamed web image? In-Reply-To: References: <25fd90d3-8c18-476b-8cb6-f53907cab1f4@x9g2000vbo.googlegroups.com> <87vddw3a5g.fsf@castleamber.com> <24f36666-b31f-4921-a6c0-19405af003a5@h2g2000yqj.googlegroups.com> Message-ID: <4B7B5F19.8010705@mrabarnett.plus.com> galileo228 wrote: > On Feb 16, 9:40 pm, galileo228 wrote: >> On Feb 16, 8:48 pm, John Bokma wrote: >> >> >> >>> galileo228 writes: >>>> Using BeautifulSoup, mechanize, and urllib, I've constructed the >>>> following: >>>> br.open("http://www.school.edu/students/facebook/") >>>> br.select_form(nr = 1) >>>> br.form['fulltextsearch'] = 'msb83' # this searches the facebook for >>>> me >>>> br.submit() >>>> results = br.response().read() >>>> soup = BeautifulSoup(results) >>>> foo2 = soup.find('td', attrs={'width':'95'}) >>>> foo3 = foo2.find('a') >>>> foo4 = foo3.find('img', attrs={'src':'deliverImage.cfm?netid=msb83'}) >>>> # this just drills down to the line and until this point the >>>> program does not return an error >>>> save_as = os.path.join('./', msb83 + '.jpg') >>>> urllib.urlretrieve(foo4, save_as)> >>>> I get the following error msg after running this code: >>>> AttributeError: 'NoneType' object has no attribute 'strip' >>> Wild guess, since you didn't provide line numbers, etc. >>> foo4 is None >>> (I also would like to suggest to use more meaningful names) >>> -- >>> John Bokma j3b >> I thought it was too, and I just doublechecked. It's actually >> >> foo3 = foo2.find('a') >> >> that is causing the NoneType error. >> >> Thoughts? > > I've now fixed the foo3 issue, and I now know that the problem is with > the urllib.urlretrieve line (see above). This is the error msg I get > in IDLE: > > Traceback (most recent call last): > File "/Users/Matt/Documents/python/dtest.py", line 59, in > urllib.urlretrieve(foo4, save_as) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 94, in urlretrieve > return _urlopener.retrieve(url, filename, reporthook, data) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 226, in retrieve > url = unwrap(toBytes(url)) > File "/Library/Frameworks/Python.framework/Versions/2.6/lib/ > python2.6/urllib.py", line 1033, in unwrap > url = url.strip() > TypeError: 'NoneType' object is not callable > > Is this msg being generated because I'm trying to retrieve a url > that's not really a file? It's because the URL you're passing in, namely foo4, is None. This is presumably because foo3.find() returns None if it can't find the entry. You checked the value of foo3, but did you check the value of foo4? From tomf.sessile at gmail.com Tue Feb 16 23:44:09 2010 From: tomf.sessile at gmail.com (TomF) Date: Tue, 16 Feb 2010 20:44:09 -0800 Subject: Is there a simple way to find the list index to the max value? References: <4B7A91B1.6030301@lonetwin.net> Message-ID: <2010021620440950073-tomfsessile@gmailcom> On 2010-02-16 11:44:45 -0800, aahz at pythoncraft.com (Aahz) said: > In article <4B7A91B1.6030301 at lonetwin.net>, steve wrote: >> On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >> The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disadvantage of that is that it's O(2N) instead of O(N). I don't think you understand order notation. There's no such thing as O(2N). To answer the original question, how about: max(enumerate(l), key=lambda x: x[1])[0] As to whether this is faster than index(max()), you'd have to time it. -Tom From nagle at animats.com Wed Feb 17 00:09:27 2010 From: nagle at animats.com (John Nagle) Date: Tue, 16 Feb 2010 21:09:27 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Terry Reedy wrote: > On 2/16/2010 3:15 PM, John Nagle wrote: >> In the beginning, Python had some types which were "frozen", > > and some which weren't. > > In the beginning, there was only one 'frozen' general purpose collection > type, the tuple. And Guido resisted the suggestion that lists and tuple > were mutable and frozen versions of each other. > > However, things have changed, and lists and tuple *are* effectively > mutable and hashable versions of each other, and we have the three other > pairs you mentioned. The idea of freeze() may have been floated (and > punctured) during Py3 discussions, but I think it a fairly good one. Yes, we're now at the point where all the built-in mutable types have "frozen" versions. But we don't have that for objects. It's generally considered a good thing in language design to offer, for user defined types, most of the functionality of built-in ones. It's the concurrency aspect of this that interests me, though. A language with immutable objects can potentially handle concurrency more safely than one where everything is potentially mutable. The language knows what can't change, which simplifies locking. John Nagle From no.email at nospam.invalid Wed Feb 17 00:52:04 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 16 Feb 2010 21:52:04 -0800 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Message-ID: <7xpr44pfy3.fsf@ruckus.brouhaha.com> John Nagle writes: >> However, things have changed, and lists and tuple *are* effectively >> mutable and hashable versions of each other... > It's the concurrency aspect of this that interests me, though. > A language with immutable objects can potentially handle concurrency > more safely than one where everything is potentially mutable. > The language knows what can't change, which simplifies locking. I wonder how well that applies to tuples containing mutable objects, e.g. t = ([1,2], [3,4]) From banibrata.dutta at gmail.com Wed Feb 17 01:10:42 2010 From: banibrata.dutta at gmail.com (Banibrata Dutta) Date: Wed, 17 Feb 2010 11:40:42 +0530 Subject: Shipping Executables In-Reply-To: References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> On Wed, Feb 17, 2010 at 7:41 AM, Steven D'Aprano < steven at remove.this.cybersource.com.au> wrote: > > security aspects I guess it would also not be much use, is this correct? > > Absolutely 100% wrong. It is an fundamental principle of security that > you must not assume that the enemy is ignorant of your procedures. > "Security by obscurity" is not security at all. > > See, for example: > > http://en.wikipedia.org/wiki/Kerckhoffs'_Principle > > I believe, the use of work 'security' wasn't the best choice to describe the need, if I understand the original poster's intentions. The intentions of original poster were "intellectual property protection", where-in they have indeed created something worth stealing, and would like to put it under lock-n-key. For that purpose, I do not think Python is the right choice. BTW for people who are non-believers in something being worth stealing needing protection, need to read about the Skype client. -- regards, Banibrata http://www.linkedin.com/in/bdutta http://twitter.com/edgeliving -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Wed Feb 17 01:17:25 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 17 Feb 2010 07:17:25 +0100 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <7xpr44pfy3.fsf@ruckus.brouhaha.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> <7xpr44pfy3.fsf@ruckus.brouhaha.com> Message-ID: * Paul Rubin: > John Nagle writes: >>> However, things have changed, and lists and tuple *are* effectively >>> mutable and hashable versions of each other... >> It's the concurrency aspect of this that interests me, though. >> A language with immutable objects can potentially handle concurrency >> more safely than one where everything is potentially mutable. >> The language knows what can't change, which simplifies locking. > > I wonder how well that applies to tuples containing mutable objects, > e.g. t = ([1,2], [3,4]) One would need a collection type that's immutable "all the way". Current frozen types don't have that. However, there's also the question of the immutability of what names refer to. It seems to me that this means that the compiler can't really assume very much without very deep analysis. And so, if it boils down to the programmer applying assumptions about mutability/constantness, then types may not be The Answer. Cheers, - Alf From debatem1 at gmail.com Wed Feb 17 02:00:59 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 17 Feb 2010 02:00:59 -0500 Subject: Shipping Executables In-Reply-To: <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> Message-ID: On Wed, Feb 17, 2010 at 1:10 AM, Banibrata Dutta wrote: > > > On Wed, Feb 17, 2010 at 7:41 AM, Steven D'Aprano > wrote: >> >> > security aspects I guess it would also not be much use, is this correct? >> Absolutely 100% wrong. It is an fundamental principle of security that >> you must not assume that the enemy is ignorant of your procedures. >> "Security by obscurity" is not security at all. >> >> See, for example: >> >> http://en.wikipedia.org/wiki/Kerckhoffs'_Principle >> > I believe, the use of work 'security' wasn't the best choice to describe the > need, if I understand the original poster's intentions. The intentions of > original poster were "intellectual property protection", Which has little to do with the language in question. > where-in they have > indeed created something worth stealing, and would like to put it under > lock-n-key. For that purpose, I do not think Python is the right choice. Why? > BTW for people who are non-believers in something being worth stealing > needing protection, need to read about the Skype client. Most of the people I know who were interested in REing skype were a lot more interested in either interoperating with the protocol or ensuring that skype wasn't deliberately including malware or a backdoor. In any even I don't see this having anything to do with Python. Geremy Condra From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 02:35:49 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Feb 2010 07:35:49 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Message-ID: On Tue, 16 Feb 2010 21:09:27 -0800, John Nagle wrote: > Yes, we're now at the point where all the built-in mutable types > have "frozen" versions. But we don't have that for objects. It's > generally considered a good thing in language design to offer, for user > defined types, most of the functionality of built-in ones. It's not hard to build immutable user-defined types. Whether they're immutable enough is another story :) >>> class FrozenMeta(type): ... def __new__(meta, classname, bases, classDict): ... def __setattr__(*args): ... raise TypeError("can't change immutable class") ... classDict['__setattr__'] = __setattr__ ... classDict['__delattr__'] = __setattr__ ... return type.__new__(meta, classname, bases, classDict) ... >>> >>> class Thingy(object): ... __metaclass__ = FrozenMeta ... def __init__(self, x): ... self.__dict__['x'] = x ... >>> >>> >>> t = Thingy(45) >>> t.x 45 >>> t.x = 42 Traceback (most recent call last): File "", line 1, in File "", line 4, in __setattr__ TypeError: can't change immutable class It's a bit ad hoc, but it seems to work for me. Unfortunately there's no way to change __dict__ to a "write once, read many" dict. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 02:36:08 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 17 Feb 2010 07:36:08 GMT Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> Message-ID: On Wed, 17 Feb 2010 02:00:59 -0500, geremy condra quoted Banibrata Dutta : >> BTW for people who are non-believers in something being worth stealing >> needing protection, need to read about the Skype client. Pardon me for breaking threading, but the original post has not come through to my provider, only the reply from Geremy. Many things are worth stealing and therefore need protection. In any case, reverse engineering software is not theft. And even if it were, keeping the source code secret is no barrier to a competent, determined attacker or investigator. Skype is a good example: despite the lack of source code and the secret protocol, analysts were able to discover that TOM-Skype sends personally identifiable information, encryption keys and private messages back to central servers. In my personal opinion, releasing closed source software is prima facie evidence that the software is or does something bad: leaking personal information, infringing somebody else's copyright or patent, or just being badly written. I'm not saying that every piece of closed source software is like that, but when you hide the source, the burden of proof is on you to prove that you're not hiding something unpleasant. -- Steven From steve at holdenweb.com Wed Feb 17 02:38:30 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Feb 2010 02:38:30 -0500 Subject: Shipping Executables In-Reply-To: References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> Message-ID: geremy condra wrote: [...] > I'd worry about developing a product worth stealing before I > worried about people stealing it ;) > > Geremy Condra +1 FAQ entry! regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 17 02:39:43 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 17 Feb 2010 02:39:43 -0500 Subject: Shipping Executables In-Reply-To: <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> Message-ID: Philip Semanchuk wrote: > > On Feb 16, 2010, at 4:41 PM, rodmc wrote: > >> Hi, >> >> I have been merrily programming away in Python now for a few years and >> have a couple of applications I would like to possibly publish at some >> point - with the exception of certain libraries they are more or less >> 100% Python. However I have read elsewhere online that Python due to >> it's architecture is not so good for this, especially as it is easier >> for people to hack into the code. Also where software requires some >> security aspects I guess it would also not be much use, is this >> correct? > > > Hi Rod, > The user's ability to hack into the code is usually considered one of > the strengths of Python & open source software in general. Since most > Python software that's distributed is open source, you're doing > something different than most. It'd help if you explain how you want > your software to differ from a typical open source distribution. Do you > not want people to change the code? Are you worried about your code & > ideas being stolen? > Do remember, though, that the Python license absolutely allows you to create both open source and proprietary products as you choose. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From ldo at geek-central.gen.new_zealand Wed Feb 17 03:02:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Feb 2010 21:02:13 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: In message <60b1abce-4381-46ab-91ed- f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: > Also, lambda's are expressions, not statements ... Is such a distinction Pythonic, or not? For example, does Python distinguish between functions and procedures? From ldo at geek-central.gen.new_zealand Wed Feb 17 03:02:56 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 17 Feb 2010 21:02:56 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: In message <8ca440b2-6094-4b35-80c5-81d000517ce0 at v20g2000prb.googlegroups.com>, Jonathan Gardner wrote: > I used to think anonymous functions (AKA blocks, etc...) would be a > nice feature for Python. > > Then I looked at a stack trace from a different programming language > with lots of anonymous functions. (I believe it was perl.) Didn?t it have source line numbers in it? What more do you need? From doron.tal.list at gmail.com Wed Feb 17 03:44:03 2010 From: doron.tal.list at gmail.com (Doron Tal) Date: Wed, 17 Feb 2010 10:44:03 +0200 Subject: GIL state during import In-Reply-To: References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Message-ID: <2a8674c61002170044n66ad77bfk3c85744eddf79337@mail.gmail.com> On Wed, Feb 17, 2010 at 1:01 AM, Terry Reedy wrote: > On 2/16/2010 4:37 PM, Doron Tal wrote: > >> Is the GIL released during import statement execution when accessing the >> file? >> If not, is it a bug? >> If it is not a bug, or it is here to stay for any other reason, I think >> it should be mentioned in the documentation. >> > > The CPython GIL is a CPython implementation artifact and should not be > mentioned in the language docs (and is not, as far as I know). Were you > thinking of something else? And why this specific feature of its behavior, > whatever it is. > > tjr > > > > -- > http://mail.python.org/mailman/listinfo/python-list > I'm sorry, I should have explained my case better. Quoting the documentation ( http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock ): "The lock is also released and reacquired around potentially blocking I/O operations like reading or writing a file, so that other threads can run while the thread that requests the I/O is waiting for the I/O operation to complete." Since on some cases the IO may be _very_ slow, any IO command which does not release the GIL can potentially stall the process. There are two problems (or more...), the first, it may stall the process for unacceptable duration. The second problem is that it is not an easy task to track down the root cause of this stall. In the specific case I'm dealing with, the problematic command is execfile (at the time of my initial writing I did not know that). --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From news123 at free.fr Wed Feb 17 04:21:55 2010 From: news123 at free.fr (News123) Date: Wed, 17 Feb 2010 10:21:55 +0100 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> Message-ID: <4b7bb533$0$23887$426a74cc@news.free.fr> Hi David, Thanks a lot. As I have pywin32 already installed this is probbaly the way to go. Meanwhile I implemented already a small module, which is parsing sc.exe's output, but probably 'll change it as my implementation is a little clumsy. bye N David Bolen wrote: > alex23 writes: > >> News123 wrote: >>> What is the best way with python to get a list of all windows services. >>> >>> As a start I would be glad to receive only the service names. >>> >>> However it would be nicer if I could get all the properties of a service >>> as well. >> I highly recommend Tim Golden's fantastic WMI module[1]. > > Another alternative is the win32service module from the pywin32 > package (which IMO you'll almost certainly want available when doing > any significant Windows-specific operations) which wraps the native > win32 libraries for enumerating, querying and controlling services. > > A simple loop could use EnumServicesStatus to iterate through the > services, OpenService with the SERVICE_QUERY_CONFIG flag to get a > handle to each service, and then QueryServiceConfig to retrieve > configuration information. > > Since pywin32 is a relatively thin wrapper over the win32 libraries, > pure MSDN documentation can be used for help with the calls, augmented > by any Python-related information contained in the pywin32 > documentation. > > -- David From dino at phidev.org Wed Feb 17 04:29:37 2010 From: dino at phidev.org (Florian Ludwig) Date: Wed, 17 Feb 2010 10:29:37 +0100 Subject: plugin / intra process communication system In-Reply-To: <7u05ulFfmkU1@mid.uni-berlin.de> References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <7u05ulFfmkU1@mid.uni-berlin.de> Message-ID: <1266398977.10498.423.camel@brain> On Tue, 2010-02-16 at 19:20 +0100, Diez B. Roggisch wrote: > Am 15.02.10 23:12, schrieb Florian Ludwig: > > On Sun, 2010-02-14 at 18:47 +0100, Diez B. Roggisch wrote: > >>> Here there problem with the trac (and other plugin systems I've > >> seen) > >>> approach: > >>> > >>> You need to define something like: > >>> | > >>> | class IAuthPlugin(Interface): [...] > >>> > >>> in your blog software. > >> > >> Why? Any reason you can't define it in a separate package the > >> blog-software depends on, as well as your wiki? > > > > That's actually my point - most plugin systems I've seen, like the one > > trac uses, are not encouraging you to do so. Having a module that just > > defines an Interface is kind of weird - and in the real world no one is > > doing it. > > Just because nobody doesn't do it doesn't mean it's not desirable. Good point. > IMHO the ones using interfaces usually immediatly implement them for some > cases - so you actually get the interface for you authentication > framework, and also implement an OpenID plugin for it. And this forms > one package. Then you can add new packages that implement other things. So if I want to implement another authentication mechanism but doesn't use any of the auth-frameworks code you mentioned you still would depend on it. > repoze.who and what are examples for such design. repoze.who is new for me, it might not actually solve my problem here but it looks interesting for other tasks :) Thanks. > >> And then of course, this is not really needed. In Python, behavior > >> counts, not type-information. So you can get away without any explicit > >> declared interface. You might chose to not do that, for aestetic > >> reasons, or better documentation. But you aren't forced. > > > > Actually some plugin-systems in python do force you and they check if > > your "implementation" comply with the "interface". > > I didn't say nobody does it, I just said it isn't needed to get a > working plugin system. If you don't want to have a separate package > *and* don't want to pull in any unused code, this is pretty much your > only option. Do you know somebody/some project/system/... who does it? Pulling unused code I definitely want to avoid so I probably will stay with this way. > > [...] > > > > What do you think? Any obvious pitfalls (besides reinventing something)? > > I don't know what pbus is supposed to do. Nor how it's laid out on a > python package level. Its "the plugin system", connecting "service providers" (plugins) and "service users". In my example the "users" also are providers at the same time, the service "auth", provides the service "wiki". Hope that clarifies my intentions a bit. Thanks, Florian PS I removed you (diez) from the TO list as that bounced. Probably related to the (not existing?) domain nospam.web.de -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From navanitachora at gmail.com Wed Feb 17 04:58:43 2010 From: navanitachora at gmail.com (Nandakumar Chandrasekhar) Date: Wed, 17 Feb 2010 17:58:43 +0800 Subject: Replacement for e.message() in python 2.6 Message-ID: <0PKdnTVryZFJIObWnZ2dnUVZ_jidnZ2d@westnet.com.au> Dear Folks, In previous versions of Python I used to use e.message() to print out the error message of an exception like so: try: result = x / y except ZeroDivisionError, e: print e.message() Unfortunately in Python 2.6 the message method is deprecated. Is there any replacement for the message method in Python 2.6 or is there any best practice that should be used in Python from now on? Thank you. Yours sincerely, Nanda From davea at ieee.org Wed Feb 17 04:59:38 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Feb 2010 04:59:38 -0500 Subject: GIL state during import In-Reply-To: References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> Message-ID: <4B7BBE0A.10509@ieee.org> Terry Reedy wrote: >
On > 2/16/2010 4:37 PM, Doron Tal wrote: >> Is the GIL released during import statement execution when accessing the >> file? >> If not, is it a bug? >> If it is not a bug, or it is here to stay for any other reason, I think >> it should be mentioned in the documentation. > > The CPython GIL is a CPython implementation artifact and should not be > mentioned in the language docs (and is not, as far as I know). Were > you thinking of something else? And why this specific feature of its > behavior, whatever it is. > > tjr > Threading vs. imports is mentioned at least once in the Python docs. See http://docs.python.org/library/threading.html, section 17.2.9 (at least in version 2.6.4) """While the import machinery is thread safe, there are two key restrictions on threaded imports due to inherent limitations in the way that thread safety is provided: * Firstly, other than in the main module, an import should not have the side effect of spawning a new thread and then waiting for that thread in any way. Failing to abide by this restriction can lead to a deadlock if the spawned thread directly or indirectly attempts to import a module. * Secondly, all import attempts must be completed before the interpreter starts shutting itself down. This can be most easily achieved by only performing imports from non-daemon threads created through the threading module. Daemon threads and threads created directly with the thread module will require some other form of synchronization to ensure they do not attempt imports after system shutdown has commenced. Failure to abide by this restriction will lead to intermittent exceptions and crashes during interpreter shutdown (as the late imports attempt to access machinery which is no longer in a valid state). """ So it may or may not use the GIL, but there are thread restrictions during an import. The rule I try to follow is not to do anything non-trivial during top-level code of a module, except inside the if __name__ == "__main__": portion. If we're inside that portion, we're not a module, we're a script. Even better, import all your modules before starting any new threads. DaveA From arnodel at googlemail.com Wed Feb 17 05:18:52 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 10:18:52 +0000 Subject: Replacement for e.message() in python 2.6 References: <0PKdnTVryZFJIObWnZ2dnUVZ_jidnZ2d@westnet.com.au> Message-ID: Nandakumar Chandrasekhar writes: > Dear Folks, > > In previous versions of Python I used to use e.message() to print out > the error message of an exception like so: > > try: > result = x / y > except ZeroDivisionError, e: > print e.message() > > Unfortunately in Python 2.6 the message method is deprecated. > > Is there any replacement for the message method in Python 2.6 or is > there any best practice that should be used in Python from now on? You can just use the __str__() method of the BaseException object for this. So instead of print e.message You can write print str(e) which in turn is equivalent to print e For more details see PEP 352 (http://www.python.org/dev/peps/pep-0352/) -- Arnaud From jkn_gg at nicorp.f9.co.uk Wed Feb 17 05:31:45 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Wed, 17 Feb 2010 02:31:45 -0800 (PST) Subject: Hubris connects Ruby to Haskell, will there be such a connection between Python and Haskell? References: <009d33cc-75da-4afe-9715-31e820ddc54e@y7g2000prc.googlegroups.com> Message-ID: On Feb 17, 2:04?am, Carl Banks wrote: > > Hubris connects Ruby to Haskell, will there be such a connection > > between Python and Haskell? > > I would have expected Hubris to link Ada and Common Lisp together. > > Carl Banks ;-) J^n From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 17 05:46:02 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 11:46:02 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: <4b7bc8e4$0$4242$426a34cc@news.free.fr> Aahz a ?crit : > In article <8ca440b2-6094-4b35-80c5-81d000517ce0 at v20g2000prb.googlegroups.com>, > Jonathan Gardner wrote: >> I used to think anonymous functions (AKA blocks, etc...) would be a >> nice feature for Python. >> >> Then I looked at a stack trace from a different programming language >> with lots of anonymous functions. (I believe it was perl.) >> >> I became enlightened. > > +1 QOTW ++1 QOTW !-) Had the same problem trying to debug some javascript... From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 17 05:48:54 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 11:48:54 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <4b7bc991$0$4242$426a34cc@news.free.fr> Lawrence D'Oliveiro a ?crit : > In message <60b1abce-4381-46ab-91ed- > f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: > >> Also, lambda's are expressions, not statements ... > > Is such a distinction Pythonic, or not? Python is (by design) a statement-based language, so yes, this distinction is pythonic !-) From doron.tal.list at gmail.com Wed Feb 17 06:02:06 2010 From: doron.tal.list at gmail.com (Doron Tal) Date: Wed, 17 Feb 2010 13:02:06 +0200 Subject: GIL state during import In-Reply-To: <4B7BBE0A.10509@ieee.org> References: <2a8674c61002161337l2932e29flcd61adf8a7e808a1@mail.gmail.com> <4B7BBE0A.10509@ieee.org> Message-ID: <2a8674c61002170302t28ed24eei9d9960c966b78011@mail.gmail.com> On Wed, Feb 17, 2010 at 11:59 AM, Dave Angel wrote: > Terry Reedy wrote: > >
On 2/16/2010 >> 4:37 PM, Doron Tal wrote: >> >>> Is the GIL released during import statement execution when accessing the >>> file? >>> If not, is it a bug? >>> If it is not a bug, or it is here to stay for any other reason, I think >>> it should be mentioned in the documentation. >>> >> >> The CPython GIL is a CPython implementation artifact and should not be >> mentioned in the language docs (and is not, as far as I know). Were you >> thinking of something else? And why this specific feature of its behavior, >> whatever it is. >> >> tjr >> >> Threading vs. imports is mentioned at least once in the Python docs. See > http://docs.python.org/library/threading.html, section 17.2.9 (at least > in version 2.6.4) > > """While the import machinery is thread safe, there are two key > restrictions on threaded imports due to inherent limitations in the way that > thread safety is provided: > > * Firstly, other than in the main module, an import should not have > the side effect of spawning a new thread and then waiting for that > thread in any way. Failing to abide by this restriction can lead > to a deadlock if the spawned thread directly or indirectly > attempts to import a module. > * Secondly, all import attempts must be completed before the > interpreter starts shutting itself down. This can be most easily > achieved by only performing imports from non-daemon threads > created through the threading module. Daemon threads and threads > created directly with the thread module will require some other > form of synchronization to ensure they do not attempt imports > after system shutdown has commenced. Failure to abide by this > restriction will lead to intermittent exceptions and crashes > during interpreter shutdown (as the late imports attempt to access > machinery which is no longer in a valid state). > > """ > > So it may or may not use the GIL, but there are thread restrictions during > an import. The rule I try to follow is not to do anything non-trivial > during top-level code of a module, except inside the > if __name__ == "__main__": > > portion. If we're inside that portion, we're not a module, we're a script. > > Even better, import all your modules before starting any new threads. > > DaveA > > > > -- > http://mail.python.org/mailman/listinfo/python-list > No argue here. The specific problem, as I wrote in reply to Terry, is with the execfile statement. It might be a part of some online plugin machinery. In such case the nature of the cause does not allow to execute it upfront. I think that the problem can be circumvented by first reading the file followed by compile and eval, as being done in Python3 (no execfile there). --doron -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 06:43:23 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 12:43:23 +0100 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 In-Reply-To: References: Message-ID: W. eWatson wrote: > I've finally decided to see if I could make an executable out of a py > file. Win7. Py2.5. I brought down the install file and proceeded with > the install. I got two warning messages. Forgot the first. The second > said,"Could not set the key value." I again used OK. I think that was > the only choice. It then issued a message in a larger dialog. It was > about setting a key, and pointed me to a log. It mentions a Removepy2exe -u > > Although it finished, I have no idea where the program is. It does not > show up on the Start menu All Programs List nore my desktop. What's up? > > I've had these messages (key) occur on other Python installs as I > transition to Win7. So far no problem. > You may want to consider dumping the thing and going for PyInstaller, which in my experience is better and has friendly developer community behind it. Regards, mk From mrkafk at gmail.com Wed Feb 17 06:44:16 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 12:44:16 +0100 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 In-Reply-To: References: Message-ID: W. eWatson wrote: P.S. I didn't really use PyInstaller on Windows, though -- just on Linux, where it works beautifully. Regards, mk From daniel at stutzbachenterprises.com Wed Feb 17 06:44:49 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Wed, 17 Feb 2010 06:44:49 -0500 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: On Tue, Feb 16, 2010 at 3:15 PM, John Nagle wrote: > One possible implementation would be > to have unfrozen objects managed by reference counting and locking as > in CPython. Frozen objects would live in a different memory space and be > garbage collected by a concurrent garbage collector. > A concurrent garbage collector for frozen object would still need to walk unfrozen objects, to find references to frozen objects. -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From lacrima.maxim at gmail.com Wed Feb 17 08:25:03 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 17 Feb 2010 05:25:03 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <07d50b9f-c4bb-4d49-82d0-bd6d1c2e42be@z10g2000prh.googlegroups.com> Message-ID: <0beb548b-2aa9-4708-86ee-c89dec988502@q21g2000yqm.googlegroups.com> On Feb 16, 7:38?pm, Phlip wrote: > > This paper _almost_ gets the idea:http://www.netobjectives.com/download/Code%20Qualities%20and%20Practi... > > > Do you run your tests after the fewest possible edits? Such as 1-3 > lines of code? > Hi! I run my tests all the time (they almost replaced debugger in my IDE). But there are times, when I can't just run tests after 1-3 lines of code. For example, I am developing an application that talks to some web service. One of methods of a class, which implements API for a given web service, should parse xml response from web service. At first, I hardcoded returned values, so that they looked like already parsed. But further, additional tests forced me to actually operate with sample xml data instead of hardcoded values. So I created sample xml file that resembled response from server. And after that I can't just write 1-3 lines between each test. Because I need to read() the file and sort it out in a loop (at least 6-9 lines of code for small xml file). And only after this procedure I run my tests with the hope that they all pass. Maybe it's not proper TDD, but I can't figure out how to reduce period between running tests in a case above. From mrkafk at gmail.com Wed Feb 17 08:53:38 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 14:53:38 +0100 Subject: Over(joy)riding Message-ID: Found in Dive into Python: """Guido, the original author of Python, explains method overriding this way: "Derived classes may override methods of their base classes. Because methods have no special privileges when calling other methods of the same object, a method of a base class that calls another method defined in the same base class, may in fact end up calling a method of a derived class that overrides it. (For C++ programmers: all methods in Python are effectively virtual.)" """ So, I set out to create such case: class A(object): def __init__(self): print "A" def met(self): print "I'm A's method" def overriden(self): print "I'm A's method to be overriden" def calling_overriden(self): self.overriden() class B(object): def __init__(self): print "B" def met(self): print "I'm B's method" class C(A): def __init__(self, arg): print "C","arg=",arg A.__init__(self) def met(self): print "I'm C's method" class D(B): def __init__(self, arg): print "D", "arg=",arg B.__init__(self) def met(self): print "I'm D's method" class E(C,D): def __init__(self, arg): print "E", "arg=",arg C.__init__(self, arg) D.__init__(self, arg) def some(self): self.met() def overriden(self): print "I'm really E's method" e = E(10) print 'MRO:', ' '.join([c.__name__ for c in E.__mro__]) e.some() e.calling_overriden() Result: ... MRO: E C A D B object I'm C's method I'm really E's method Is what I concocted in e.calling_overriden() == what Guido said on base class sometimes calling overriden method instead of its own original method? Regards, mk From userprogoogle-139 at yahoo.co.uk Wed Feb 17 08:53:50 2010 From: userprogoogle-139 at yahoo.co.uk (rodmc) Date: Wed, 17 Feb 2010 05:53:50 -0800 (PST) Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <8DFBF31D-98D4-425B-A7D1-CC83E60AB02B@semanchuk.com> Message-ID: <216c9f16-e952-410b-b0e2-d72b999d557f@g28g2000yqh.googlegroups.com> > > Hi Rod, > > The user's ability to hack into the code is usually considered one of > > the strengths of Python & open source software in general. Since most > > Python software that's distributed ?is open source, you're doing > > something different than most. It'd help if you explain how you want > > your software to differ from a typical open source distribution. Do you > > not want people to change the code? Are you worried about your code & > > ideas being stolen? Thanks to everyone for their replies. Normally I have no problem with adopting an open source model, indeed I usually encourage it. However the main problem was related to end- user licencing e.g. via some form of registration key. The other problem was related to end-user private data and sending this via a secure Internet connection. While I am ok with secure Internet connection side of it I was concerned that with the source code being available to others the security may in some way be reduced- however I note one reply which says this is not the case. Kind regards, rod From arnodel at googlemail.com Wed Feb 17 09:25:06 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 14:25:06 +0000 Subject: Over(joy)riding References: Message-ID: mk writes: > Found in Dive into Python: > > """Guido, the original author of Python, explains method overriding > this way: "Derived classes may override methods of their base > classes. Because methods have no special privileges when calling other > methods of the same object, a method of a base class that calls > another method defined in the same base class, may in fact end up > calling a method of a derived class that overrides it. (For C++ > programmers: all methods in Python are effectively virtual.)" """ > > So, I set out to create such case: > > class A(object): > def __init__(self): > print "A" > > def met(self): > print "I'm A's method" > > def overriden(self): > print "I'm A's method to be overriden" > > def calling_overriden(self): > self.overriden() [...] > class E(C,D): > def __init__(self, arg): > print "E", "arg=",arg > C.__init__(self, arg) > D.__init__(self, arg) > > def some(self): > self.met() > > def overriden(self): > print "I'm really E's method" > > e = E(10) > print 'MRO:', ' '.join([c.__name__ for c in E.__mro__]) > e.some() > e.calling_overriden() > > > Result: > ... > MRO: E C A D B object > I'm C's method > I'm really E's method > > > Is what I concocted in e.calling_overriden() == what Guido said on > base class sometimes calling overriden method instead of its own > original method? Yes! -- Arnaud From lacrima.maxim at gmail.com Wed Feb 17 09:26:33 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Wed, 17 Feb 2010 06:26:33 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: On Feb 16, 10:30?pm, Ben Finney wrote: > Lacrima writes: > > And I have already refused to write totally isolated tests, because it > > looks like a great waste of time. > > It only looks like that until you chase your tail in a long, fruitless > debugging session because (you later realise) the behaviour of one test > is being affected by another. Test isolation is essential to ensure that > your tests are doing what you think they're doing. > > -- > ?\ ? ? ? ?A ?No? uttered from deepest conviction is better and greater | > ? `\ ? ? ? than a ?Yes? merely uttered to please, or what is worse, to | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?avoid trouble.? ?Mohandas K. Gandhi | > Ben Finney Hi! Right, isolation is essential. But I can't decide to which extent I should propagate isolation. For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, author suggests that if you do unittesting you should isolate the smallest units of code from each other. For example, if you have a class: Class SomeClass(object): def method1(self): return 5 def method2(self): return self.method1 + 10 According to the book, if you want to test method2, you should isolate it from method1 and class instance('self'). Other books are not so strict... And what should I follow as newbie? Currently, I don't create mocks of units if they are within the same class with the unit under test. If that is not right approach, please, explain what are best practices... I am just learning TDD.. with regards, Maxim From chyavana at gmail.com Wed Feb 17 09:27:35 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Wed, 17 Feb 2010 22:27:35 +0800 Subject: Is automatic reload of a module available in Python? Message-ID: Dear Folks, I am currently developing a python program, let us call it "generic.py", and I am testing out the functions therein by testing them out interactively in the python interpreter by invoking python and doing import generic Once I hit an error, I need to revise my file and reload the module using reload(generic) The difference in syntax between invoking import and reload is really costing me time and patience. Therefore, I would like to ask: 1. Is there a method of auto-reloading a module while developing it and testing it with the interactive python interpreter? 2. Is there a better way of developing a program? Thank you. Chandra From mail at timgolden.me.uk Wed Feb 17 09:29:05 2010 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 17 Feb 2010 14:29:05 +0000 Subject: listing existing windows services with python In-Reply-To: References: <4b79e10c$0$30277$426a74cc@news.free.fr> <848fc0ab-8309-4e30-9731-3442f2ca57f2@b1g2000prc.googlegroups.com> <4b7a8d08$0$666$426a74cc@news.free.fr> Message-ID: <4B7BFD31.4010609@timgolden.me.uk> On 16/02/2010 13:51, Alf P. Steinbach wrote: > It doesn't seem to provide ordinary Windows "service"s, but it's a bit unclear > since e.g. the URL above says [... snip ...] Well the useful info in there appears to come from: http://msdn.microsoft.com/en-us/library/aa392783%28VS.85%29.aspx Looking around the matter, I think I'm taking the view that this is an implementation detail of WMI. However you use it, WMI is a layer on a layer on layer (especially if you're using it in Python with my module!) and it's never going to be the fastest thing going. One contributory factor will be this particular model of process-within-process. But I don't feel that it would help anybody if I were to mention it on my webpages as there's nothing the casual user can do about it. In general I tend to unrecommend WMI for something small in an app which doesn't otherwise use it, unless the convenience (and it *is* very convenient sometimes) outweighs the slight performance issue. Thanks for the heads-up anyway, Alf. I need to get up to speed with the Vista & W7 issues referred to on that page as well. TJG From xiajunyi at gmail.com Wed Feb 17 09:35:57 2010 From: xiajunyi at gmail.com (Imaginationworks) Date: Wed, 17 Feb 2010 06:35:57 -0800 (PST) Subject: How to efficiently extract information from structured text file References: Message-ID: On Feb 16, 7:14?pm, Gary Herron wrote: > Imaginationworks wrote: > > Hi, > > > I am trying to read object information from a text file (approx. > > 30,000 lines) with the following format, each line corresponds to a > > line in the text file. ?Currently, the whole file was read into a > > string list using readlines(), then use for loop to search the "= {" > > and "};" to determine the Object, SubObject,and SubSubObject. My > > questions are > > > 1) Is there any efficient method that I can search the whole string > > list to find the location of the tokens(such as '= {' or '};' > > Yes. ? Read the *whole* file into a single string using file.read() > method, and then search through the string using string methods (for > simple things) or use re, the regular expression module, (for more > complex searches). ? ? > > Note: ?There is a point where a file becomes large enough that reading > the whole file into memory at once (either as a single string or as a > list of strings) is foolish. ? ?However, 30,000 lines doesn't push that > boundary. > > > 2) Is there any efficient ways to extract the object information you > > may suggest? > > Again, the re module has nice ways to find a pattern, and return parse > out pieces of it. ? Building a good regular expression takes time, > experience, and a bit of black magic... ? ?To do so for this case, we > might need more knowledge of your format. ?Also regular expressions have > their limits. ?For instance, if the sub objects can nest to any level, > then in fact, regular expressions alone can't solve the whole problem, > and you'll need a more robust parser. > > > Thanks, > > > - Jeremy > > > ===== Structured text file ================= > > Object1 = { > > > ... > > > SubObject1 = { > > .... > > > SubSubObject1 = { > > ... > > }; > > }; > > > SubObject2 = { > > .... > > > SubSubObject21 = { > > ... > > }; > > }; > > > SubObjectN = { > > .... > > > SubSubObjectN = { > > ... > > }; > > }; > > }; > > Gary and Rhodri, Thank you for the suggestions. From mrkafk at gmail.com Wed Feb 17 09:40:35 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 15:40:35 +0100 Subject: Over(joy)riding In-Reply-To: References: Message-ID: Arnaud Delobelle wrote: >> Is what I concocted in e.calling_overriden() == what Guido said on >> base class sometimes calling overriden method instead of its own >> original method? > > Yes! For a change I achieved resounding success with Python. :-) P.S. Method resolution order in Python makes me want to kill small kittens. Regards, mk From arnodel at googlemail.com Wed Feb 17 09:52:32 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 14:52:32 +0000 Subject: Is automatic reload of a module available in Python? References: Message-ID: "R (Chandra) Chandrasekhar" writes: > Dear Folks, > > I am currently developing a python program, let us call it > "generic.py", and I am testing out the functions therein by testing > them out interactively in the python interpreter by invoking python > and doing > > import generic > > Once I hit an error, I need to revise my file and reload the module using > > reload(generic) > > The difference in syntax between invoking import and reload is really > costing me time and patience. > > Therefore, I would like to ask: > > 1. Is there a method of auto-reloading a module while developing it > and testing it with the interactive python interpreter? > > 2. Is there a better way of developing a program? > > Thank you. > > Chandra Here is a very simple way to improve what you do, which won't require you to change the way you work or to learn a new paradigm: Instead of testing your functions interactively, put your testing code in a file, e.g. 'program_tests.py'. Your can then type python program_tests.py at the shell interactive prompt. To perform the tests again, just re-execute that file. If your tests are divided into different units, you can put these in functions: def test_frobz(): #testing code for frobzation of klops def test_frizz(): #testing code for frizzment of frobzied klops # etc.. So if you want to keep doing interactive tests, you can import program_tests and call whichever testing functions you want. You may even have arguments to those functions to test them with different parameters. I know some people will point at more 'pro' ways of testing but this has the merit of being very straightforward. Then when you move on to more sophisticated techniques, I think you will understand better the motivations behind them. -- Arnaud From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 17 09:52:35 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 15:52:35 +0100 Subject: Over(joy)riding In-Reply-To: References: Message-ID: <4b7c02ac$0$23463$426a74cc@news.free.fr> mk a ?crit : > P.S. Method resolution order in Python makes me want to kill small kittens. mro is only a "problem" when using MI. From python at bdurham.com Wed Feb 17 09:57:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Feb 2010 09:57:27 -0500 Subject: How to build a list of all modules in standard library? Message-ID: <1266418647.16023.1360448951@webmail.messagingengine.com> We're building a py2exe executable that may need to do some dynamic module imports. I'm looking for suggestions on how we can mechanically generate a list of standard library modules/packages to make sure our build has the full set of Python 2.6.4 libraries. We're planning on creating a module called stdlib.py that explictly imports all modules within an "if False:" block of code per example below and then importing this script (stdlib.py) in our main script. # stdlib.py - insure that py2exe imports all modules in its build if False: # list of all standard modules import ... import # list of 3rd party modules import win32api import wmi ... Any suggestions or feedback appreciated. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 10:08:28 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 16:08:28 +0100 Subject: Over(joy)riding In-Reply-To: <4b7c02ac$0$23463$426a74cc@news.free.fr> References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > mk a ?crit : >> P.S. Method resolution order in Python makes me want to kill small >> kittens. > > mro is only a "problem" when using MI. Oh sure! And I have the impression that multiple inheritance is not used all that often. What (some) Python code I've read in open source projects typically uses single inheritance. Nevertheless MI is there in Python, might be useful in some cases and Guido put it there for some reason, so Citizens Aspiring To Become Pythonistas like me work to learn it. Regards, mk From python at bdurham.com Wed Feb 17 10:10:03 2010 From: python at bdurham.com (python at bdurham.com) Date: Wed, 17 Feb 2010 10:10:03 -0500 Subject: Recommendations for cloud based file storage service with Python API? Message-ID: <1266419403.17892.1360456229@webmail.messagingengine.com> I'm looking for recommendations on a cloud based file storage service with a Python API. Would appreciate hearing feedback from anyone using Python to interface to Amazon S3, RackSpace Cloud Files, Microsoft Azure, Rsync.net, or other hosted file storage service. What services do you recommend or suggest we avoid? Are there Python specific issues (such as lagging library updates when an API gets updated) I should be concerned about? Our use case is mananging thousands of 100K-500K data files owned by hundreds of users. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Wed Feb 17 10:14:19 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Feb 2010 16:14:19 +0100 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: <4B7C07CB.3000702@sequans.com> R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I am currently developing a python program, let us call it > "generic.py", and I am testing out the functions therein by testing > them out interactively in the python interpreter by invoking python > and doing > > import generic > > Once I hit an error, I need to revise my file and reload the module using > > reload(generic) > > The difference in syntax between invoking import and reload is really > costing me time and patience. > > Therefore, I would like to ask: > > 1. Is there a method of auto-reloading a module while developing it > and testing it with the interactive python interpreter? > > 2. Is there a better way of developing a program? > > Thank you. > > Chandra You will always find people explaining to you how it can be possible if you really know precisely how python object model works. If you actually do, you can possibly read their technics. But my short answer would be "No, there is no reliable way to reload a module". Still there is 'reload' builting function you can call on any module, by you must understand that it won't affect any other object that the module itself. New objects created from that module will take effects, but all objects created before won't. JM From kwmsmith at gmail.com Wed Feb 17 11:00:23 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Wed, 17 Feb 2010 10:00:23 -0600 Subject: Over(joy)riding In-Reply-To: References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: On Wed, Feb 17, 2010 at 9:08 AM, mk wrote: > Bruno Desthuilliers wrote: >> >> mk a ?crit : >>> >>> P.S. Method resolution order in Python makes me want to kill small >>> kittens. >> >> mro is only a "problem" when using MI. > > Oh sure! And I have the impression that multiple inheritance is not used all > that often. What (some) Python code I've read in open source projects > typically uses single inheritance. > > Nevertheless MI is there in Python, might be useful in some cases and Guido > put it there for some reason, so Citizens Aspiring To Become Pythonistas > like me work to learn it. In case you're not familiar with it, MI allows you to have mixins & traits. They work very well if the mixin superclasses don't have any clashes with the other superclasses, so each mixin adds its own unique set of methods to the derived class. Then you don't have to worry about mro and all that (at least as much). Here's an article on it, with examples: http://www.linuxjournal.com/node/4540/print Michele Simionato has some criticism of MI pitfalls and has come up with the straits module to remedy it -- you might be interested. He goes into detail here: http://www.artima.com/weblogs/viewpost.jsp?thread=246488 Kurt From dyamins at gmail.com Wed Feb 17 11:04:24 2010 From: dyamins at gmail.com (Dan Yamins) Date: Wed, 17 Feb 2010 11:04:24 -0500 Subject: Wrap and intercept function calls In-Reply-To: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> Message-ID: <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Really, nobody has any idea about this? (Sorry to repost.) On Tue, Feb 16, 2010 at 7:29 PM, Dan Yamins wrote: > Hi: > > I'm wondering what the best way to wrap and modify function calls is. > Essentially what I want to achieve is to have a function like this: > > def Wrap(frame,event,arg): > if event == 'call': > result = PerformCheck(GetArgumentsFromFrame(frame)) > if Condition(result): > return result > else: > return [normal function call] > > called whenever a "call" event is about to occur. > > When I say "return result" I mean: return that data object instead of what > the function would have returned, and prevent execution of the function. > > > Is there any way to do this using sys.settrace? Or perhaps something from > the bdb or pbd module? > > In other words, what I'm looking for is a way to intercept all function calls with a "wrapper" -- like one can do using settrace and other debugging methods -- but, unlike the debugging methods, have the "wrapping" function actually be able to intervene in the stack and, for instance, conditionally replace the function call's return with something determined in the wrapping function and prevent the function call's execution. I want to be able to do this by setting a single system-wide (or at any rate, thread-wide) value, like with settrace, and not have to modify individual functions one by one. Could I, for example, set a settrace function that somehow modifies the stack? Or is there some much better way to do this? Or, if someone can tell me that this can't be done without having to roll my own implementation of the Python interpreter, that would be great to know too. Thanks again, Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: From robert.kern at gmail.com Wed Feb 17 11:17:00 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 17 Feb 2010 10:17:00 -0600 Subject: Recommendations for cloud based file storage service with Python API? In-Reply-To: <1266419403.17892.1360456229@webmail.messagingengine.com> References: <1266419403.17892.1360456229@webmail.messagingengine.com> Message-ID: On 2010-02-17 09:10 AM, python at bdurham.com wrote: > I'm looking for recommendations on a cloud based file storage service > with a Python API. > Would appreciate hearing feedback from anyone using Python to interface > to Amazon S3, RackSpace Cloud Files, Microsoft Azure, Rsync.net, or > other hosted file storage service. What services do you recommend or > suggest we avoid? Are there Python specific issues (such as lagging > library updates when an API gets updated) I should be concerned about? I don't have any deep experience with using any of them, it is worth noting that the Python interface to the RackSpace Cloud Files API is implemented by RackSpace itself and is the premier interface to their API. It won't lag behind the API. -- 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 phlip2005 at gmail.com Wed Feb 17 11:30:24 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 17 Feb 2010 08:30:24 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: On Feb 17, 6:26?am, Lacrima wrote: > Right, isolation is essential. Please read my reply: Ben is well intentioned but completely wrong here. Mock abuse will not cure the runtime isolation problem. From phlip2005 at gmail.com Wed Feb 17 11:32:00 2010 From: phlip2005 at gmail.com (Phlip) Date: Wed, 17 Feb 2010 08:32:00 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <07d50b9f-c4bb-4d49-82d0-bd6d1c2e42be@z10g2000prh.googlegroups.com> <0beb548b-2aa9-4708-86ee-c89dec988502@q21g2000yqm.googlegroups.com> Message-ID: <2dd65d33-5f55-4124-b748-44f7b46320c7@g28g2000prb.googlegroups.com> Lacrima wrote: > I run my tests all the time (they almost replaced debugger in my IDE). > But there are times, when I can't just run tests after 1-3 lines of > code. ... > Maybe it's not proper TDD You are still being too literal. The "1-3 lines of code" guideline is a guideline, not a rule. It means 1 small edit is best, 2 edits are mostly harmless, 3 is okay, 4 is acceptable, and so on. It's the peak of the Zipf's Law curve: http://www.rimmkaufman.com/content/mobydick.png You "mocked the wire" with that hardcoded XML so that your subsequent edits can be very short and reliable. Props! From nagle at animats.com Wed Feb 17 12:26:46 2010 From: nagle at animats.com (John Nagle) Date: Wed, 17 Feb 2010 09:26:46 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: <4b7c22c8$0$1651$742ec2ed@news.sonic.net> Daniel Stutzbach wrote: > On Tue, Feb 16, 2010 at 3:15 PM, John Nagle wrote: > >> One possible implementation would be >> to have unfrozen objects managed by reference counting and locking as >> in CPython. Frozen objects would live in a different memory space and be >> garbage collected by a concurrent garbage collector. >> > > A concurrent garbage collector for frozen object would still need to walk > unfrozen objects, to find references to frozen objects. Right. But the reverse is not the case. Reference count updating wouldn't need to look at frozen object space. One way to implement locking is something like this: Mutable objects have a reference count field, a lock field, and an "owner" field. Initially, the owner of an object is its thread. If an object's only reference is a field of a synchronized object, the owner is the synchronized object. Mutable objects with an owner can be manipulated by that owner without locking. When an object reference is passed to another thread or another synchronized object, the object becomes multi-owner and the "owner" field is set to null. Thereafter, the object must be locked during updates. The headache with this is that when an object becomes multi-owner, so does everything it points to. So there's a transient as the system runs down the references, locking objects momentarily and clearing owner fields. John Nagle From mrkafk at gmail.com Wed Feb 17 12:29:36 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 18:29:36 +0100 Subject: Over(joy)riding In-Reply-To: References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: Kurt Smith wrote: > In case you're not familiar with it, MI allows you to have mixins & > traits. They work very well if the mixin superclasses don't have any > clashes with the other superclasses, so each mixin adds its own unique > set of methods to the derived class. Then you don't have to worry > about mro and all that (at least as much). > > Here's an article on it, with examples: > > http://www.linuxjournal.com/node/4540/print > > Michele Simionato has some criticism of MI pitfalls and has come up > with the straits module to remedy it -- you might be interested. He > goes into detail here: > > http://www.artima.com/weblogs/viewpost.jsp?thread=246488 Thanks Kurt, I will certainly look into that! Regards, mk From mrkafk at gmail.com Wed Feb 17 12:38:14 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 18:38:14 +0100 Subject: Referring to class methods in class attributes Message-ID: Hello everyone, OK so I have this: def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" class PYFileInfo(FileInfo): File "C:/mp3i/finfo2.py", line 64, in PYFileInfo 'internal_date': PYFileInfo.print_internal_date NameError: name 'PYFileInfo' is not defined Hmm do I get that class data attributes are defined before class is defined?! Why I would like to do it this way: 1. keeping all the stuff specific to PYFileInfo where it belongs, in a class: the print_internal_method does nothing but read timestamp from a .pyc file, so it's not a generic function. 2. I guess I could define tagdata in __init__ and be done with it: however, it's an instance attribute then and not class attribute: a few bytes are wasted. Seriously, however, suppose tagdata or smth like this is really large? It would make sense to make it class attribute and not instance attribute. So I'm trying to work out if there's a way to do it. Regards, mk From apt.shansen at gmail.com Wed Feb 17 12:59:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 17 Feb 2010 09:59:11 -0800 Subject: Referring to class methods in class attributes In-Reply-To: References: Message-ID: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> On Wed, Feb 17, 2010 at 9:38 AM, mk wrote: > It works. But if I'd like to def print_internal_date in PYFileInfo body > like so: > > class PYFileInfo(FileInfo): > 'python file properties' > > def print_internal_date(self, filename): > f = open(filename + 'c', "rb") > data = f.read(8) > mtime = struct.unpack(" return time.asctime(time.gmtime(mtime[0])) > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': PYFileInfo.print_internal_date > } > You don't have to (and can't) refer to the class within the body. Class statements are sort of... odd. They are code which is directly executed, and the results are then passed into a metaclass/type/whatever and a class object is created. While within the class body, the class doesn't exist yet. But you don't need it to. Just do: 'internal_date': print_internal_date The 'def' is in the same local scope as 'tagdata' is. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 13:00:45 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 19:00:45 +0100 Subject: mixins and new style classes Message-ID: >>> class Person(object): ... pass ... >>> class Friendly(object): ... def hello(self): ... print 'hello' ... >>> >>> Person.__bases__ += (Friendly,) Traceback (most recent call last): File "", line 1, in TypeError: Cannot create a consistent method resolution order (MRO) for bases object, Friendly But it works for old-style classes: >>> class Person: ... pass ... >>> class Friendly: ... def hello(self): ... print 'hello' ... >>> >>> p = Person() >>> >>> Person.__bases__ += (Friendly,) >>> >>> p.hello() hello Python is 2.6.1. From andrej.mitrovich at gmail.com Wed Feb 17 13:10:37 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Feb 2010 10:10:37 -0800 (PST) Subject: Traversing through variable-sized lists Message-ID: Hi, I couldn't figure out a better description for the Subject line, but anyway, I have the following: _num_frames = 32 _frames = range(0, _num_frames) # This is a list of actual objects, I'm just pseudocoding here. _values = [0, 1, 2, 3, 4] I want to call a function of _frames for each frame with a _values argument, but in a way to "spread out" the actual values. I would want something similar to the following to be called: _frames[0].func(_values[0]) _frames[1].func(_values[0]) _frames[2].func(_values[0]) _frames[3].func(_values[0]) _frames[4].func(_values[1]) _frames[5].func(_values[1]) _frames[6].func(_values[1]) _frames[7].func(_values[1]) _frames[8].func(_values[2]) ...etc... Both the _values list and _frames list can be of variable and uneven size, which is what is giving me the problems. I'm using Python 2.6. I've tried the following workaround, but it often gives me inaccurate results (due to integer division), so I had to add a safety check: num_frames = 32 values = [0, 1, 2, 3, 4] offset_step = num_frames / len(values) for index in xrange(0, num_frames): offset = index / offset_step if offset > offset_values[-1]: offset = offset_values[-1] frames[index].func(values[offset]) There has to be a better way to do this. I'd appreciate any help. Cheers! From victorsubervi at gmail.com Wed Feb 17 13:14:58 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 17 Feb 2010 14:14:58 -0400 Subject: Timer Message-ID: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Hi; I have the following css: and the following python: if new is not None: print '
' print '' % (str(wn*1008), str(wn*200)) print ''' ''' print '' % (str(wn*1008), str(wn*200)) print '' print '
' Timer(5, removeCSS, ()).start() Obviously, the removeCSS isn't going to work in that last line. What can I put there to remove the splash page after 5 seconds? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From gabriel at opensuse.org Wed Feb 17 13:30:51 2010 From: gabriel at opensuse.org (Gabriel) Date: Wed, 17 Feb 2010 15:30:51 -0300 Subject: Timer In-Reply-To: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Message-ID: <1adde6891002171030m2d83a0a3v93017aa7a1cee55c@mail.gmail.com> On Wed, Feb 17, 2010 at 3:14 PM, Victor Subervi wrote: > Hi; > I have the following css: > > and the following python: > ??if new is not None: > ?? ?print '
' > ?? ?print ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" > WIDTH="%s" HEIGHT="%s" id="myMovieName">' % (str(wn*1008), str(wn*200)) > ?? ?print ''' > > > ''' > ?? ?print ' quality=high bgcolor=#FFFFFF WIDTH="%s" HEIGHT="%s" NAME="myMovieName" > ALIGN="" TYPE="application/x-shockwave-flash" > PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">' % > (str(wn*1008), str(wn*200)) > ?? ?print '' > ?? ?print '
' > ?? ?Timer(5, removeCSS, ()).start() > Obviously, the removeCSS isn't going to work in that last line. What can I > put there to remove the splash page after 5 seconds? > TIA, > beno I don't think this has anything to do with python. -- Kind Regards From dotancohen at gmail.com Wed Feb 17 13:36:45 2010 From: dotancohen at gmail.com (Dotan Cohen) Date: Wed, 17 Feb 2010 20:36:45 +0200 Subject: Timer In-Reply-To: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Message-ID: <880dece01002171036t7e198649jd94d2bd789eadf9f@mail.gmail.com> > What can I > put there to remove the splash page after 5 seconds? > Javascript. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il Please CC me if you want to be sure that I read your message. I do not read all list mail. From apt.shansen at gmail.com Wed Feb 17 13:37:56 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 17 Feb 2010 10:37:56 -0800 Subject: Timer In-Reply-To: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> Message-ID: <7a9c25c21002171037s49568919te9840a9dabd37f29@mail.gmail.com> On Wed, Feb 17, 2010 at 10:14 AM, Victor Subervi wrote: > Obviously, the removeCSS isn't going to work in that last line. What can I > put there to remove the splash page after 5 seconds? > Even though you're generating this with python, it doesn't have anything to do with Python. You'll have to use javascript and DHTML and enable/disable classes. How to do that is beyond the scope of this group, and might depend on the browser. I'd go look into jQuery or some such which will encapsulate such dynamic things better. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Wed Feb 17 13:38:10 2010 From: mrkafk at gmail.com (mk) Date: Wed, 17 Feb 2010 19:38:10 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: Stephen Hansen wrote: > You don't have to (and can't) refer to the class within the body. Class > statements are sort of... odd. They are code which is directly executed, > and the results are then passed into a metaclass/type/whatever and a > class object is created. While within the class body, the class doesn't > exist yet. > > But you don't need it to. > > Just do: > > 'internal_date': print_internal_date > > The 'def' is in the same local scope as 'tagdata' is. Thanks, that worked. But in order to make it work I had to get rid of 'self' in print_internal_date signature, bc all other functions in tagdata have only a single argument: class PYFileInfo(FileInfo): 'python file properties' def print_internal_date(filename): ... tagdata = {'compiled_fname': lambda x: x + 'c', 'size': os.path.getsize, 'internal_date': print_internal_date } That looks weird: a method with no 'self'. Hmm that is probably seriously wrong. This obviously means no other method can call it like self.print_internal_date(), because self would get passed as first argument, yes? I checked that print_internal_date can be called on an instance, so the same method can be seen as: - class method -- when used in local scope definition like tagdata, or - instance method -- when called from an instance or from self? It should be called ______print_internal_date really. ;-) I wonder if I'm not trying to make Python things it shouldn't be doing, but it's the problem at hand that is leading me into this conundrum: all other functions for tagdata use single arguments. I should probably code around that anyway.. Regards, mk From john at castleamber.com Wed Feb 17 13:39:30 2010 From: john at castleamber.com (John Bokma) Date: Wed, 17 Feb 2010 12:39:30 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: <87fx4zlna5.fsf@castleamber.com> Jonathan Gardner writes: > Then I looked at a stack trace from a different programming language > with lots of anonymous functions. (I believe it was perl.) > > I became enlightened. If it was Perl [1], I doubt it. Because line numbers are reported, and if that doesn't help you, you can annotate anonymous functions with a nick name using local *__ANON__ = 'nice name'; Finding an issue, and not looking for a solution is not called becoming enlightened ;-) ~$ perl -e ' use Carp; my $anon = sub { local *__ANON__ = "hello, world"; croak "oops"; }; $anon->(); ' oops at -e line 4 main::hello, world() called at -e line 5 As you can see, and a line number is generated, and the nice name is shown. If you generate anonymouse functions on the fly based on parameters, you can encode this into the nice name, of course. Sadly, often bold statements about a language are made in ignorance. [1] perl is the program that executes Perl programs ;-). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From apt.shansen at gmail.com Wed Feb 17 13:51:11 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Wed, 17 Feb 2010 10:51:11 -0800 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: <7a9c25c21002171051o4bc48483qbb82cc65668434f6@mail.gmail.com> On Wed, Feb 17, 2010 at 10:38 AM, mk wrote: > Thanks, that worked. But in order to make it work I had to get rid of > 'self' in print_internal_date signature, bc all other functions in tagdata > have only a single argument: > Right, I should have caught that. You can make print_internal_date a @staticmethod. Or just leave it as a top level function where it was perfectly happy to live :) > That looks weird: a method with no 'self'. Hmm that is probably seriously > wrong. > > This obviously means no other method can call it like > self.print_internal_date(), because self would get passed as first argument, > yes? > It doesn't have to be. It could be a class method-- @classmethod does that, makes it receive 'cls' the actual class as the first argument. Or a @staticmethod, in which case it has no first-argument at all. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjw at ncf.ca Wed Feb 17 13:51:50 2010 From: cjw at ncf.ca (cjw) Date: Wed, 17 Feb 2010 13:51:50 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <4b7bc991$0$4242$426a34cc@news.free.fr> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On 17-Feb-10 05:48 AM, Bruno Desthuilliers wrote: > Lawrence D'Oliveiro a ?crit : >> In message <60b1abce-4381-46ab-91ed- >> f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: >> >>> Also, lambda's are expressions, not statements ... >> >> Is such a distinction Pythonic, or not? > > Python is (by design) a statement-based language, so yes, this > distinction is pythonic !-) Aren't lambda forms better described as function? Colin W. From jeanmichel at sequans.com Wed Feb 17 13:53:59 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 17 Feb 2010 19:53:59 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: <4B7C3B47.5040906@sequans.com> mk wrote: > Stephen Hansen wrote: > >> You don't have to (and can't) refer to the class within the body. >> Class statements are sort of... odd. They are code which is directly >> executed, and the results are then passed into a >> metaclass/type/whatever and a class object is created. While within >> the class body, the class doesn't exist yet. >> >> But you don't need it to. >> >> Just do: >> >> 'internal_date': print_internal_date >> >> The 'def' is in the same local scope as 'tagdata' is. > > Thanks, that worked. But in order to make it work I had to get rid of > 'self' in print_internal_date signature, bc all other functions in > tagdata have only a single argument: > > class PYFileInfo(FileInfo): > 'python file properties' > > def print_internal_date(filename): > ... > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } > > That looks weird: a method with no 'self'. Hmm that is probably > seriously wrong. > [snip] Absolutely not. It's called a static method, you have to decorate it with @staticmethod though. class A: @staticmethod def getInstance(): return A() a = A.getInstance() you have also the class method version: class B: @classmethod: def getInstance(cls): # class methods take a class as first parameter return cls() JM From mccredie at gmail.com Wed Feb 17 13:55:32 2010 From: mccredie at gmail.com (Matt McCredie) Date: Wed, 17 Feb 2010 18:55:32 +0000 (UTC) Subject: Traversing through variable-sized lists References: Message-ID: > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset > offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! > This is how I would do it, assuming you just want to call the remaining frames with the last value. from itertools import izip def stretch(seq, n): for val in seq: for i in xrange(n): yield val while True: yield val frames_per_value = num_frames // len(values) for frame, value in izip(frames, stretch(values, frames_per_value)): frame.func(value) Matt From ppearson at nowhere.invalid Wed Feb 17 14:15:05 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 17 Feb 2010 19:15:05 GMT Subject: Traversing through variable-sized lists References: Message-ID: <7u2thpFhfbU1@mid.individual.net> On Wed, 17 Feb 2010 10:10:37 -0800 (PST), Andrej Mitrovic wrote: [snip] > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset > offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) Here's my suggestion: Python 2.5.2 (r252:60911, Jul 22 2009, 15:35:03) >>> import math >>> import itertools >>> values = [ 1, 2, 3 ] >>> f = list( lambda x=i : x for i in range( 10 ) ) >>> n = int( math.ceil( len(f)/float( len(values) ) ) ) >>> for ff, dd in zip( f, itertools.chain(*zip( *n*[values] )) ): ... print "Function %d applied to data %d." % ( ff(dd), dd ) ... Function 1 applied to data 1. Function 1 applied to data 1. Function 1 applied to data 1. Function 1 applied to data 1. Function 2 applied to data 2. Function 2 applied to data 2. Function 2 applied to data 2. Function 2 applied to data 2. Function 3 applied to data 3. Function 3 applied to data 3. >>> -- To email me, substitute nowhere->spamcop, invalid->net. From wolfram.hinderer at googlemail.com Wed Feb 17 14:15:59 2010 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Wed, 17 Feb 2010 11:15:59 -0800 (PST) Subject: Traversing through variable-sized lists References: Message-ID: <950cfd62-ee52-4dbc-803b-38b040b52f32@y17g2000yqd.googlegroups.com> On 17 Feb., 19:10, Andrej Mitrovic wrote: > Hi, > > I couldn't figure out a better description for the Subject line, but > anyway, I have the following: > > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > ? ? for index in xrange(0, num_frames): > ? ? ? ? offset = index / offset_step > ? ? ? ? if offset > offset_values[-1]: > ? ? ? ? ? ? offset = offset_values[-1] > ? ? ? ? frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! Python 3.1: >>> def apply_spreaded(funcs, values): ... num_funcs = len(funcs) ... num_values = len(values) ... for i, func in enumerate(funcs): ... func(values[(i * num_values) // num_funcs]) >>> apply_spreaded([print] * 8, range(5)) 0 0 1 1 2 3 3 4 From hniksic at xemacs.org Wed Feb 17 14:18:39 2010 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 17 Feb 2010 20:18:39 +0100 Subject: Python version of perl's "if (-T ..)" and "if (-B ...)"? References: Message-ID: <877hqbu0vk.fsf@busola.homelinux.net> Tim Chase writes: > if portion is None: > content = iter(f) iter(f) will iterate over lines in the file, which doesn't fit with the rest of the algorithm. Creating an iterator that iterates over fixed-size file chunks (in this case of length 1) is where the two-argument form of iter comes in handy: content = iter(lambda: f.read(1), '') From jjposner at optimum.net Wed Feb 17 14:24:52 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 17 Feb 2010 14:24:52 -0500 Subject: Traversing through variable-sized lists In-Reply-To: References: Message-ID: <4B7C4284.8070709@optimum.net> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: > Hi, > > I couldn't figure out a better description for the Subject line, but > anyway, I have the following: > > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... The lines above show that you are using two different series of index values. Each function call (more properly, "method call") has the form: frames[INDEX_FROM_FIRST_SERIES].func(INDEX_FROM_SECOND_SERIES) (I've dropped the underscores in the names, for simplicity.) You're getting hung up trying to keep the two series of index values in sync. But you don't really need to. More below ... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset> offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! As you've shown above, a "for" loop takes care of the first series of index values: for index in xrange(num_frames): # "0" arg unnecessary frames[index].func(INDEX_FROM_SECOND_SERIES) The second series of index values needs to look like this: 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3 ... The trick is not to worry about matching the second series to the first series. Instead, create an "infinite" second series using a Python generator, and use as many of its values as you need. Don't worry about the unused values, because the series isn't *really* infinite. :-) Here's an easy way to create the generator import itertools second_series_gen = (i/4 for i in itertools.count()) Now, every time you need another number from this series, use its next() method. So the above code becomes: for index in xrange(num_frames): frames[index].func(second_series_gen.next()) -John From __peter__ at web.de Wed Feb 17 14:27:41 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 17 Feb 2010 20:27:41 +0100 Subject: Traversing through variable-sized lists References: Message-ID: Andrej Mitrovic wrote: > Hi, > > I couldn't figure out a better description for the Subject line, but > anyway, I have the following: > > _num_frames = 32 > _frames = range(0, _num_frames) # This is a list of actual objects, > I'm just pseudocoding here. > _values = [0, 1, 2, 3, 4] > > I want to call a function of _frames for each frame with a _values > argument, but in a way to "spread out" the actual values. > > I would want something similar to the following to be called: > > _frames[0].func(_values[0]) > _frames[1].func(_values[0]) > _frames[2].func(_values[0]) > _frames[3].func(_values[0]) > _frames[4].func(_values[1]) > _frames[5].func(_values[1]) > _frames[6].func(_values[1]) > _frames[7].func(_values[1]) > _frames[8].func(_values[2]) > ...etc... > > Both the _values list and _frames list can be of variable and uneven > size, which is what is giving me the problems. I'm using Python 2.6. > > I've tried the following workaround, but it often gives me inaccurate > results (due to integer division), so I had to add a safety check: > > num_frames = 32 > values = [0, 1, 2, 3, 4] > offset_step = num_frames / len(values) > for index in xrange(0, num_frames): > offset = index / offset_step > if offset > offset_values[-1]: > offset = offset_values[-1] > frames[index].func(values[offset]) > > There has to be a better way to do this. I'd appreciate any help. > Cheers! I tried to apply http://en.wikipedia.org/wiki/Bresenham's_line_algorithm on the problem: def bresenham(xitems, yitems): x1 = len(xitems) y1 = len(yitems) assert y1 <= x1 assert x1 > 0 deltax = x1-1 deltay = y1-1 error = deltax // 2 yitems = iter(yitems) y = next(yitems) for x in xitems: yield x, y error -= deltay if error < 0: y = next(yitems) error += deltax if __name__ == "__main__": def make_f(i): def f(v): return "%d --> %s" % (i, v) return f functions = [make_f(i) for i in range(11)] values = ["b%s" % k for k in range(5)] for f, v in bresenham(functions, values): print f(v) The implementation is derived from the code on the wikipedia page and untested. Peter From ptmcg at austin.rr.com Wed Feb 17 14:40:17 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Wed, 17 Feb 2010 11:40:17 -0800 (PST) Subject: How to efficiently extract information from structured text file References: Message-ID: <41aac4b4-2d1c-422c-af6d-604296e95a1a@k19g2000yqc.googlegroups.com> On Feb 16, 5:48?pm, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. ?Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. If you open(filename).read() this file into a variable named data, the following pyparsing parser will pick out your nested brace expressions: from pyparsing import * EQ,LBRACE,RBRACE,SEMI = map(Suppress,"={};") ident = Word(alphas, alphanums) contents = Forward() defn = Group(ident + EQ + Group(LBRACE + contents + RBRACE + SEMI)) contents << ZeroOrMore(defn | ~(LBRACE|RBRACE) + Word(printables)) results = defn.parseString(data) print results Prints: [ ['Object1', ['...', ['SubObject1', ['....', ['SubSubObject1', ['...'] ] ] ], ['SubObject2', ['....', ['SubSubObject21', ['...'] ] ] ], ['SubObjectN', ['....', ['SubSubObjectN', ['...'] ] ] ] ] ] ] -- Paul From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 14:44:47 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 20:44:47 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> Message-ID: <4b7c54a8$0$21284$426a74cc@news.free.fr> mk a ?crit : > Stephen Hansen wrote: > >> You don't have to (and can't) refer to the class within the body. >> Class statements are sort of... odd. They are code which is directly >> executed, and the results are then passed into a >> metaclass/type/whatever and a class object is created. While within >> the class body, the class doesn't exist yet. >> >> But you don't need it to. >> >> Just do: >> >> 'internal_date': print_internal_date >> >> The 'def' is in the same local scope as 'tagdata' is. > > Thanks, that worked. But in order to make it work I had to get rid of > 'self' in print_internal_date signature Indeed. Using it that way, the print_internal_date will not be wrapped in a method object. > bc all other functions in > tagdata have only a single argument: > > class PYFileInfo(FileInfo): > 'python file properties' > > def print_internal_date(filename): > ... > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } > > That looks weird: a method with no 'self'. It's not a method. > Hmm that is probably > seriously wrong. > > This obviously means no other method can call it like > self.print_internal_date(), because self would get passed as first > argument, yes? Unless you make it a staticmethod. > I checked that print_internal_date can be called on an instance, so the > same method s/method/function/ > can be seen as: > > - class method -- when used in local scope definition like tagdata, or > - instance method -- when called from an instance or from self? Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO beautifully) simple once you get it, but I agree it's a bit peculiar when compared to most mainstream OO languages. The first thing is that the def statement *always* yield a function object. Always. If you don't believe it, try the following snippet: class Foo(object): def bar(self): return "baaz" print Foo.__dict__.keys() print type(Foo.__dict__['bar']) So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The answer is : attribute lookup rules and the descriptor protocol. To make a long story short, the descriptor protocol specify that, when, during an attribute lookup, a name resolves to a class attribute AND this attribute has a __get__ method, then this __get__ method is called (with either the instance or None and the class itself as arguments) and whatever it returns becomes the result of the attribute lookup. This mechanism is what provides support for computed attributes. Now the trick is that the function type do implement the descriptor protocol. So when a function is an attribute of a class object and you try to access it as an attribute of either the class itself or an instance of the class, it's __get__ method is called with the instance (or None) and the class. Having access to itself (of course), the instance (if there's one) and the class, it's easy for it to wrap all this into a method object. Which is itself a callable object, that when called mostly inject the instance as first object in the argument's list and returns the result of calling the wrapped function object. A (naive) implementation of the whole thing might look like this: class method(object): def __init__(self, func, instance, cls): self.im_func = func self.im_self = instance self.im_class = cls def __call__(self, *args, **kw): # XXX : all sanity checks removed for readability if self.im_self: args = (self.im_func,) + args return self.im_func(*args, **kw) class function(object): # ... def __get__(self, instance, cls): return method(self, instance, cls) So, what makes a function a "method" is not being defined in a class statement's body (well, not directly at least), it's that it is an attribute of the class. FWIW, the following code is perfectly legal: class Foo(object): pass def func(obj): print "obj is %s " % obj Foo.method = func f = Foo() f.method() Foo.method(f) func(f) > I wonder if I'm not trying to make Python things it shouldn't be doing, > but it's the problem at hand that is leading me into this conundrum: all > other functions for tagdata use single arguments. I should probably code > around that anyway.. Well, the simple solution is to just leave print_internal_date as a plain function instead of insisting on making it a method. Python is 100% OO in that everything is an object, but it's not a "pure" OO language, ie it doesn't require everything to happen in a method. So if all you need is a function, by all mean just use a function !-) Now if you really need print_internal_date to be exposed as a method of PYFileInfo - like, you need polymorphic dispatch - then make it a staticmethod. My 2 cents... From deets at nospam.web.de Wed Feb 17 14:46:00 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 17 Feb 2010 20:46:00 +0100 Subject: plugin / intra process communication system In-Reply-To: References: <1266054643.26540.58.camel@brain> <7tqr9iFbi7U1@mid.uni-berlin.de> <7u05ulFfmkU1@mid.uni-berlin.de> Message-ID: <4B7C4778.8090904@nospam.web.de> >> IMHO the ones using interfaces usually immediatly implement them for some >> cases - so you actually get the interface for you authentication >> framework, and also implement an OpenID plugin for it. And this forms >> one package. Then you can add new packages that implement other things. > > So if I want to implement another authentication mechanism but doesn't > use any of the auth-frameworks code you mentioned you still would depend > on it. This depends on your definition of depending... (pun intended). Sure, the code floats around. But it isn't *used* by your application. Why do you bother so much? >> I didn't say nobody does it, I just said it isn't needed to get a >> working plugin system. If you don't want to have a separate package >> *and* don't want to pull in any unused code, this is pretty much your >> only option. > > Do you know somebody/some project/system/... who does it? > > Pulling unused code I definitely want to avoid so I probably will stay > with this way. Well, it's simply duck-typing, so you find it all over the place. Out of my head I only know about e.g. TurboMail, that allows you to specify plugins via pkg_resources entry points & simply uses them. > Its "the plugin system", connecting "service providers" (plugins) and > "service users". In my example the "users" also are providers at the > same time, the service "auth", provides the service "wiki". So it's hypothetical? To summarize my point again: if you want explicit type-checking or zope-style interface implementation, but don't want any code that implements this (at least not imported) - you need an explicit package. If you don't want this, use duck-typing. > > PS I removed you (diez) from the TO list as that bounced. Probably > related to the (not existing?) domain nospam.web.de I post through NNTP, and the email is obfuscated for the obvious reasons. From tjreedy at udel.edu Wed Feb 17 14:50:32 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 14:50:32 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On 2/17/2010 1:51 PM, cjw wrote: > On 17-Feb-10 05:48 AM, Bruno Desthuilliers wrote: >> Lawrence D'Oliveiro a ?crit : >>> In message <60b1abce-4381-46ab-91ed- >>> f2ab2154c0a1 at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: >>> >>>> Also, lambda's are expressions, not statements ... >>> >>> Is such a distinction Pythonic, or not? >> >> Python is (by design) a statement-based language, so yes, this >> distinction is pythonic !-) > Aren't lambda forms better described as function? They are expressions that evaluate to function objects nearly identical to that produced by the def statememt they abbreviate. The only difference is the .__name__ attribute. Terry Jan Reedy From tjreedy at udel.edu Wed Feb 17 14:57:23 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 14:57:23 -0500 Subject: Over(joy)riding In-Reply-To: References: Message-ID: On 2/17/2010 8:53 AM, mk wrote: > Found in Dive into Python: > > """Guido, the original author of Python, explains method overriding this > way: "Derived classes may override methods of their base classes. > Because methods have no special privileges when calling other methods of > the same object, a method of a base class that calls another method > defined in the same base class, may in fact end up calling a method of a > derived class that overrides it. (For C++ programmers: all methods in > Python are effectively virtual.)" """ > > So, I set out to create such case: > > class A(object): > def __init__(self): > print "A" > > def met(self): > print "I'm A's method" > > def overriden(self): > print "I'm A's method to be overriden" > > def calling_overriden(self): > self.overriden() > > class B(object): > def __init__(self): > print "B" > > def met(self): > print "I'm B's method" > > > class C(A): > def __init__(self, arg): > print "C","arg=",arg > A.__init__(self) > > def met(self): > print "I'm C's method" > > > class D(B): > def __init__(self, arg): > print "D", "arg=",arg > B.__init__(self) > > def met(self): > print "I'm D's method" > > > class E(C,D): > def __init__(self, arg): > print "E", "arg=",arg > C.__init__(self, arg) > D.__init__(self, arg) > > def some(self): > self.met() > > def overriden(self): > print "I'm really E's method" > > e = E(10) > print 'MRO:', ' '.join([c.__name__ for c in E.__mro__]) > e.some() > e.calling_overriden() > > > Result: > ... > MRO: E C A D B object > I'm C's method > I'm really E's method > > > Is what I concocted in e.calling_overriden() == what Guido said on base > class sometimes calling overriden method instead of its own original > method? Much more complicated than needed for this point, but I believe yes. From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 15:00:42 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 21:00:42 +0100 Subject: Over(joy)riding In-Reply-To: References: <4b7c02ac$0$23463$426a74cc@news.free.fr> Message-ID: <4b7c5863$0$24394$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: >> mk a ?crit : >>> P.S. Method resolution order in Python makes me want to kill small >>> kittens. >> >> mro is only a "problem" when using MI. > > Oh sure! And I have the impression that multiple inheritance is not used > all that often. What (some) Python code I've read in open source > projects typically uses single inheritance. Single inheritance does indeed cover most of the needs - and FWIW, even single inheritance is not used as much in Python as in some other more mainstream OOPLs. This comes partly from duck typing - inheritance is only used for implementation inheritance, not for type-based polymorphic dispatch -, and partly from Python's support for composition/delegation (thru __getattr__). Also - as you noticed - single inheritance is easier to grasp, and Python's philosophy really values simplicity, readability, maintainability, and coder's mental health !-) > Nevertheless MI is there in Python, might be useful in some cases and > Guido put it there for some reason, Indeed. As with most Python's "advanced" features, it's there so you can use it when appropriate. > so Citizens Aspiring To Become > Pythonistas like me work to learn it. FWIW, I very rarely had to use it myself in almost 10 years of Python programming - main exceptions being Zope2 stuff (which is IMHO highly unpythonic) and a couple mixin classes here and there. From tjreedy at udel.edu Wed Feb 17 15:21:51 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 15:21:51 -0500 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: On 2/17/2010 9:27 AM, R (Chandra) Chandrasekhar wrote: > Dear Folks, > > I am currently developing a python program, let us call it "generic.py", > and I am testing out the functions therein by testing them out > interactively in the python interpreter by invoking python and doing > > import generic > > Once I hit an error, I need to revise my file and reload the module using > > reload(generic) Reload is sufficiently flakey that it has been removed in 3.x. The problem is that it genearally only *partially* replaces the module, so that some code uses the old version and some the new. Guido tried to rewrite it but gave up and removed it. The most sensible way to completely remove a module is to shutdown and restart the interpreter. > The difference in syntax between invoking import and reload is really > costing me time and patience. > > Therefore, I would like to ask: > > 1. Is there a method of auto-reloading a module while developing it and > testing it with the interactive python interpreter? > > 2. Is there a better way of developing a program? This is what I now do. Edit # xxx/module.py def _test(): if __name__ == '__main__': _test() with IDLE and hit F5 to run and test. IDLE runs the file in a *fresh* subinterpreter as the main module and then, whether or not an exception is raised, switches to interactive mode, so one can interactively test any objects created (before any exception). The switch to interactive mode after running a file can also be done with a command line switch when using CPython directly. Terry Jan Reedy From tjreedy at udel.edu Wed Feb 17 15:28:03 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 15:28:03 -0500 Subject: How to build a list of all modules in standard library? In-Reply-To: <1266418647.16023.1360448951@webmail.messagingengine.com> References: <1266418647.16023.1360448951@webmail.messagingengine.com> Message-ID: On 2/17/2010 9:57 AM, python at bdurham.com wrote: > We're building a py2exe executable that may need to do some dynamic > module imports. > I'm looking for suggestions on how we can mechanically generate a list > of standard library modules/packages to make sure our build has the full > set of Python 2.6.4 libraries. Find the source file for the global module index that comes with the doc set. Terry Jan Reedy From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 15:31:48 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 21:31:48 +0100 Subject: mixins and new style classes In-Reply-To: References: Message-ID: <4b7c5fad$0$20740$426a74cc@news.free.fr> mk a ?crit : >>>> class Person(object): > ... pass > ... >>>> class Friendly(object): > ... def hello(self): > ... print 'hello' > ... >>>> >>>> Person.__bases__ += (Friendly,) > Traceback (most recent call last): > File "", line 1, in > TypeError: Cannot create a consistent method resolution > order (MRO) for bases object, Friendly Indeed. After the addition of Friendly to Person.__bases__, the mro for Person would be (Person, object, Friendly). But the mro for Friendly is (Friendly, object). This is not consistent. The right solution would be to inject Friendly before object, ie: Person.__bases__ = (Mixin, object) Now the bad news is that this fails too: TypeError: __bases__ assignment: 'Mixin' deallocator differs from 'object' The above problem is not new, and had been discussed here: http://bugs.python.org/issue672115 ...and it's still unresolved AFAICT :-/ OTHO, the concrete use case for such a feature seem to be rather uncommon. > > > But it works for old-style classes: Old-style classes are a very different beast. From bdesth.quelquechose at free.quelquepart.fr Wed Feb 17 15:34:51 2010 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 17 Feb 2010 21:34:51 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <4B7C57C7.2000701@optimum.net> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <4B7C57C7.2000701@optimum.net> Message-ID: <4b7c6064$0$20740$426a74cc@news.free.fr> John Posner a ?crit : > On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote: >> > Very nice writeup, Bruno -- thanks! > > >> >> >> def __call__(self, *args, **kw): >> # XXX : all sanity checks removed for readability >> if self.im_self: >> args = (self.im_func,) + args > > In the line above, I think you meant: > > args = (self.im_self,) + args oops :? Yes, indeed. Thanks for the correction. From andrej.mitrovich at gmail.com Wed Feb 17 15:54:42 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Feb 2010 12:54:42 -0800 (PST) Subject: Traversing through variable-sized lists References: <4B7C4284.8070709@optimum.net> Message-ID: <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> On Feb 17, 8:24?pm, John Posner wrote: > On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: > > > > > Hi, > > > I couldn't figure out a better description for the Subject line, but > > anyway, I have the following: > > > _num_frames = 32 > > _frames = range(0, _num_frames) # This is a list of actual objects, > > I'm just pseudocoding here. > > _values = [0, 1, 2, 3, 4] > > > I want to call a function of _frames for each frame with a _values > > argument, but in a way to "spread out" the actual values. > > > I would want something similar to the following to be called: > > > _frames[0].func(_values[0]) > > _frames[1].func(_values[0]) > > _frames[2].func(_values[0]) > > _frames[3].func(_values[0]) > > _frames[4].func(_values[1]) > > _frames[5].func(_values[1]) > > _frames[6].func(_values[1]) > > _frames[7].func(_values[1]) > > _frames[8].func(_values[2]) > > ...etc... > > The lines above show that you are using two different series of index > values. Each function call (more properly, "method call") has the form: > > ? ?frames[INDEX_FROM_FIRST_SERIES].func(INDEX_FROM_SECOND_SERIES) > > (I've dropped the underscores in the names, for simplicity.) You're > getting hung up trying to keep the two series of index values in sync. > But you don't really need to. More below ... > > > > > > > Both the _values list and _frames list can be of variable and uneven > > size, which is what is giving me the problems. I'm using Python 2.6. > > > I've tried the following workaround, but it often gives me inaccurate > > results (due to integer division), so I had to add a safety check: > > > num_frames = 32 > > values = [0, 1, 2, 3, 4] > > offset_step = num_frames / len(values) > > ? ? ?for index in xrange(0, num_frames): > > ? ? ? ? ?offset = index / offset_step > > ? ? ? ? ?if offset> ?offset_values[-1]: > > ? ? ? ? ? ? ?offset = offset_values[-1] > > ? ? ? ? ?frames[index].func(values[offset]) > > > There has to be a better way to do this. I'd appreciate any help. > > Cheers! > > As you've shown above, a "for" loop takes care of the first series of > index values: > > ? ?for index in xrange(num_frames): ? ? ? # "0" arg unnecessary > ? ? ? ?frames[index].func(INDEX_FROM_SECOND_SERIES) > > The second series of index values needs to look like this: > > ? ?0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3 ... > > The trick is not to worry about matching the second series to the first > series. Instead, create an "infinite" second series using a Python > generator, and use as many of its values as you need. Don't worry about > the unused values, because the series isn't *really* infinite. :-) > > Here's an easy way to create the generator > > ? ?import itertools > ? ?second_series_gen = (i/4 for i in itertools.count()) > > Now, every time you need another number from this series, use its next() > method. So the above code becomes: > > ? ?for index in xrange(num_frames): > ? ? ? ?frames[index].func(second_series_gen.next()) > > -John That's a cool trick, but maybe I wasn't specific enough. The values series are the range of values that the frames.func() function should use, it should not overflow, and I would want the function to use as evenly distributed number of values as possible from the first series. The "0000,1111" was just an example. Let me see if I can be more specific: values = [2, 3, 4] frames = [obj1, obj2, obj3, obj4, obj5, obj6] And the calls: frames[0].func(values[0]) # func.(values[2]) frames[1].func(values[0]) # func.(values[2]) frames[2].func(values[1]) # func.(values[3]) frames[3].func(values[1]) # func.(values[3]) frames[4].func(values[2]) # func.(values[4]) frames[5].func(values[2]) # func.(values[4]) However the values list might have an uneven number of items. I would like to make it as evenly distributed as possible, e.g.: values = [-2, -1, 0] frames = [obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8] frames[0].func(values[0]) # func.(values[-2]) frames[1].func(values[0]) # func.(values[-2]) frames[2].func(values[1]) # func.(values[-2]) frames[3].func(values[1]) # func.(values[-1]) frames[4].func(values[1]) # func.(values[-1]) frames[5].func(values[2]) # func.(values[-1]) frames[6].func(values[2]) # func.(values[0]) frames[7].func(values[2]) # func.(values[0]) I'll be even more specific. I have a Minimum and Maximum value that the user enters. The frame.func() function is a "translate" function, it basically moves a frame in the application in one direction or another depending on the argument value. So frame[0].func(2) would move the frame[0] 2 pixels to the right. So what I want is the function to create a smooth transition of all the frames from the Minimum to the Maximum value. If minimum was 0, and maximum was 10, I'd want the first frame moved 0 pixels (it stays in place), the last frame to move 10 pixels, and the frames between are gradually moved from 1 pixels to 9 pixels relative from their positions. Perhaps I'm just overcomplicating. I'll have a look at some drawing apps and see how they've implemented drawing straight lines under an angle, I guess that could be called a gradual change of values. Thanks for all the suggestions everyone, I'll have a look at the rest shortly. From jjposner at optimum.net Wed Feb 17 15:55:35 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 17 Feb 2010 15:55:35 -0500 Subject: Referring to class methods in class attributes In-Reply-To: <4b7c54a8$0$21284$426a74cc@news.free.fr> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: <4B7C57C7.2000701@optimum.net> On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote: > > Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO > beautifully) simple once you get it, but I agree it's a bit peculiar > when compared to most mainstream OO languages. Very nice writeup, Bruno -- thanks! > > class method(object): > def __init__(self, func, instance, cls): > self.im_func = func > self.im_self = instance > self.im_class = cls > > def __call__(self, *args, **kw): > # XXX : all sanity checks removed for readability > if self.im_self: > args = (self.im_func,) + args In the line above, I think you meant: args = (self.im_self,) + args -John From tjreedy at udel.edu Wed Feb 17 15:57:57 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 15:57:57 -0500 Subject: Wrap and intercept function calls In-Reply-To: <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: On 2/17/2010 11:04 AM, Dan Yamins wrote: > Really, nobody has any idea about this? (Sorry to repost.) > On Tue, Feb 16, 2010 at 7:29 PM, Dan Yamins > wrote: > > Hi: > > I'm wondering what the best way to wrap and modify function calls > is. Essentially what I want to achieve is to have a function like > this: > > def Wrap(frame,event,arg): > if event == 'call': > result = PerformCheck(GetArgumentsFromFrame(frame)) > if Condition(result): > return result > else: > return [normal function call] > > called whenever a "call" event is about to occur. For yourself as interpreter, execute the above for every call. For CPython, alternative 1 is to create a custom interpreter to change (wrap) the interpretation of the call-function bytecode in the ceval loop. That is its 'call event', and I believe this would catch every explicit f(args) call and only such calls. Python has no general metasyntax for changing the semantics of its syntax. The __xx__ methods are special cases for the corresponding operators *and* the corresponding user-defined class. The '__call__' method of a class applies to instances of that class. Alternative 2: class func_wrap: def __init__(self, func): self._func = func def __call__(self, args, kwds): result = PerformCheck(args, kwds) if Condition(result): return result else: return self._func(*args,**kwds) Now wrap *every* function you are interested in. Builtin functions are no problem; methods of builtin classes cannont be wrapped without subclassing. Terry Jan Reedy > When I say "return result" I mean: return that data object instead > of what the function would have returned, and prevent execution of > the function. > > Is there any way to do this using sys.settrace? Or perhaps > something from the bdb or pbd module? > > > In other words, what I'm looking for is a way to intercept all function > calls with a "wrapper" -- like one can do using settrace and other > debugging methods -- but, unlike the debugging methods, have the > "wrapping" function actually be able to intervene in the stack and, for > instance, conditionally replace the function call's return with > something determined in the wrapping function and prevent the function > call's execution. I want to be able to do this by setting a single > system-wide (or at any rate, thread-wide) value, like with settrace, and > not have to modify individual functions one by one. > > Could I, for example, set a settrace function that somehow modifies the > stack? Or is there some much better way to do this? Or, if someone can > tell me that this can't be done without having to roll my own > implementation of the Python interpreter, that would be great to know too. > > Thanks again, > Dan > From joshua.r.english at gmail.com Wed Feb 17 16:00:04 2010 From: joshua.r.english at gmail.com (Josh English) Date: Wed, 17 Feb 2010 13:00:04 -0800 (PST) Subject: MediaWiki to RTF/Word/PDF Message-ID: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> I have several pages exported from a private MediaWiki that I need to convert to a PDF document, or an RTF document, or even a Word document. So far, the only Python module I have found that parses MediaWiki files is mwlib, which only runs on Unix, as far as I can tell. I'm working on Windows here. Has anyone heard of a module that parses wiki markup and transforms it? Or am I looking at XSLT? Josh From anand.shashwat at gmail.com Wed Feb 17 16:20:17 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Thu, 18 Feb 2010 02:50:17 +0530 Subject: MediaWiki to RTF/Word/PDF In-Reply-To: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: why not try installing cygwin. I am just guessing though but I had heard it emulates *nix decently on windows. Or a better idea is to shift to *nix ;) On Thu, Feb 18, 2010 at 2:30 AM, Josh English wrote: > I have several pages exported from a private MediaWiki that I need to > convert to a PDF document, or an RTF document, or even a Word > document. > > So far, the only Python module I have found that parses MediaWiki > files is mwlib, which only runs on Unix, as far as I can tell. I'm > working on Windows here. > > Has anyone heard of a module that parses wiki markup and transforms > it? Or am I looking at XSLT? > > Josh > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Wed Feb 17 16:24:36 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 17 Feb 2010 21:24:36 +0000 Subject: Referring to class methods in class attributes References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers writes: [...] > class Foo(object): > def bar(self): > return "baaz" > > print Foo.__dict__.keys() > print type(Foo.__dict__['bar']) > > > So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The > answer is : attribute lookup rules and the descriptor protocol. It's true of Python 2.X. In Python 3 there are no more unbound method: Python 3.2a0 (py3k:75274, Oct 7 2009, 20:25:52) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... def f(self): pass ... >>> A.f >>> A.f is A.__dict__['f'] True -- Arnaud From ben+python at benfinney.id.au Wed Feb 17 17:04:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 09:04:47 +1100 Subject: Referring to class methods in class attributes References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: <87iq9vcydc.fsf@benfinney.id.au> Bruno Desthuilliers writes: > Mmmm... Let's try to explain the whole damn thing. It's really (and > IMHO beautifully) simple once you get it, but I agree it's a bit > peculiar when compared to most mainstream OO languages. [?] Bruno, that's the first time I've understood the descriptor protocol, or even understood *why* the descriptor protocol is important. Could you please post (a version of) this as a separate article somewhere? A weblog post, or a new thread in this forum, or in the documentation? Somewhere that web searches will find it prominently when searching for the Python descriptor protocol. Thank you. -- \ ?I don't want to live peacefully with difficult realities, and | `\ I see no virtue in savoring excuses for avoiding a search for | _o__) real answers.? ?Paul Z. Myers, 2009-09-12 | Ben Finney From john at castleamber.com Wed Feb 17 17:09:42 2010 From: john at castleamber.com (John Bokma) Date: Wed, 17 Feb 2010 16:09:42 -0600 Subject: MediaWiki to RTF/Word/PDF References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: <87pr43ecpl.fsf@castleamber.com> Josh English writes: > I have several pages exported from a private MediaWiki that I need to > convert to a PDF document, or an RTF document, or even a Word > document. > > So far, the only Python module I have found that parses MediaWiki > files is mwlib, which only runs on Unix, as far as I can tell. I'm > working on Windows here. > > Has anyone heard of a module that parses wiki markup and transforms > it? Or am I looking at XSLT? One option might be to install a printer driver that prints to PDF and just print the web pages. Using Saxon or AltovaXML and a suitable stylesheet might give you the nicest looking result though (but quite some work). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From breamoreboy at yahoo.co.uk Wed Feb 17 17:14:07 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 17 Feb 2010 22:14:07 +0000 Subject: Referring to class methods in class attributes In-Reply-To: <87iq9vcydc.fsf@benfinney.id.au> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Bruno Desthuilliers writes: > >> Mmmm... Let's try to explain the whole damn thing. It's really (and >> IMHO beautifully) simple once you get it, but I agree it's a bit >> peculiar when compared to most mainstream OO languages. > [?] > > Bruno, that's the first time I've understood the descriptor protocol, or > even understood *why* the descriptor protocol is important. > > Could you please post (a version of) this as a separate article > somewhere? A weblog post, or a new thread in this forum, or in the > documentation? Somewhere that web searches will find it prominently when > searching for the Python descriptor protocol. > > Thank you. > I'll second, third and fourth this request. More please Bruno, or from anybody similarly qualified. Thanks very much. Mark Lawrence. From sjdevnull at yahoo.com Wed Feb 17 17:17:47 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Wed, 17 Feb 2010 14:17:47 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7b75f9$0$1666$742ec2ed@news.sonic.net> Message-ID: <2954a28f-e810-47bc-83d6-b9afb910d9af@w12g2000vbj.googlegroups.com> On Feb 17, 2:35?am, Steven D'Aprano wrote: > On Tue, 16 Feb 2010 21:09:27 -0800, John Nagle wrote: > > ? ? Yes, we're now at the point where all the built-in mutable types > > have "frozen" versions. ?But we don't have that for objects. ?It's > > generally considered a good thing in language design to offer, for user > > defined types, most of the functionality of built-in ones. > > It's not hard to build immutable user-defined types. Whether they're > immutable enough is another story :) > > >>> class FrozenMeta(type): > > ... ? ? def __new__(meta, classname, bases, classDict): > ... ? ? ? ? def __setattr__(*args): > ... ? ? ? ? ? ? raise TypeError("can't change immutable class") > ... ? ? ? ? classDict['__setattr__'] = __setattr__ > ... ? ? ? ? classDict['__delattr__'] = __setattr__ > ... ? ? ? ? return type.__new__(meta, classname, bases, classDict) > ... > > >>> class Thingy(object): > > ... ? ? __metaclass__ = FrozenMeta > ... ? ? def __init__(self, x): > ... ? ? ? ? self.__dict__['x'] = x > ... > > >>> t = Thingy(45) > >>> t.x > 45 > >>> t.x = 42 > > Traceback (most recent call last): > ? File "", line 1, in > ? File "", line 4, in __setattr__ > TypeError: can't change immutable class > > It's a bit ad hoc, but it seems to work for me. Unfortunately there's no > way to change __dict__ to a "write once, read many" dict. Which makes it not really immutable, as does the relative ease of using a normal setattr: ... t.__dict__['x'] = "foo" ... print t.x foo ... object.__setattr__(t, "x", 42) ... print t.x 42 From ldo at geek-central.gen.new_zealand Wed Feb 17 17:46:52 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 18 Feb 2010 11:46:52 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: In message , cjw wrote: > Aren't lambda forms better described as function? Is this a function? lambda : None What about this? lambda : sys.stdout.write("hi there!\n") From davea at ieee.org Wed Feb 17 17:56:14 2010 From: davea at ieee.org (Dave Angel) Date: Wed, 17 Feb 2010 17:56:14 -0500 Subject: Traversing through variable-sized lists In-Reply-To: <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> References: <4B7C4284.8070709@optimum.net> <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> Message-ID: <4B7C740E.3040200@ieee.org> Andrej Mitrovic wrote: > On Feb 17, 8:24 pm, John Posner wrote: > >> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: >> >> > > However the values list might have an uneven number of items. I would > like to make it as evenly distributed as possible, e.g.: > > values =-2, -1, 0] > frames =obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8] > > frames[0].func(values[0]) # func.(values[-2]) > frames[1].func(values[0]) # func.(values[-2]) > frames[2].func(values[1]) # func.(values[-2]) > frames[3].func(values[1]) # func.(values[-1]) > frames[4].func(values[1]) # func.(values[-1]) > frames[5].func(values[2]) # func.(values[-1]) > frames[6].func(values[2]) # func.(values[0]) > frames[7].func(values[2]) # func.(values[0]) > > > I'll be even more specific. I have a Minimum and Maximum value that > the user enters. The frame.func() function is a "translate" function, > it basically moves a frame in the application in one direction or > another depending on the argument value. So frame[0].func(2) would > move the frame[0] 2 pixels to the right. So what I want is the > function to create a smooth transition of all the frames from the > Minimum to the Maximum value. If minimum was 0, and maximum was 10, > I'd want the first frame moved 0 pixels (it stays in place), the last > frame to move 10 pixels, and the frames between are gradually moved > from 1 pixels to 9 pixels relative from their positions. > > Perhaps I'm just overcomplicating. I'll have a look at some drawing > apps and see how they've implemented drawing straight lines under an > angle, I guess that could be called a gradual change of values. > > Thanks for all the suggestions everyone, I'll have a look at the rest > shortly. > > I think you're overcomplicating. If you have 27 frames, and you want frame 0 to move 0 pixels, and frame 27 to move 10 pixels, then you want to move frame[i] by i*10/27. And since you do the multiply first, the fact that Python 2.x division gives you integers isn't a problem. There are fancier methods for drawing lines (bresenham for example), but the main purpose of them is to to avoid multiply and divide, as well as floats. But in Python, an integer multiply is just as fast as an add or subtract, so there's no point. DaveA From tjreedy at udel.edu Wed Feb 17 17:59:14 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 17 Feb 2010 17:59:14 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On 2/17/2010 5:46 PM, Lawrence D'Oliveiro wrote: > In message, cjw wrote: > >> Aren't lambda forms better described as function? > > Is this a function? > > lambda : None > > What about this? > > lambda : sys.stdout.write("hi there!\n") To repeat: Python lambda expressions evaluate to function objects identical, except for .__name__ attribute, to the equivalent def statememnt. >>> type(lambda:None) >>> import sys >>> type(lambda : sys.stdout.write("hi there!\n")) From ben+python at benfinney.id.au Wed Feb 17 18:17:51 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 10:17:51 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: <87eikjcuzk.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > In message , cjw wrote: > > > Aren't lambda forms better described as function? > > Is this a function? > > lambda : None > > What about this? > > lambda : sys.stdout.write("hi there!\n") They are both lambda forms in Python. As a Python expression, they evaluate to (they ?return?) a function object. -- \ ?It is wrong to think that the task of physics is to find out | `\ how nature *is*. Physics concerns what we can *say* about | _o__) nature?? ?Niels Bohr | Ben Finney From xiajunyi at gmail.com Wed Feb 17 18:37:02 2010 From: xiajunyi at gmail.com (Imaginationworks) Date: Wed, 17 Feb 2010 15:37:02 -0800 (PST) Subject: How to efficiently extract information from structured text file References: <41aac4b4-2d1c-422c-af6d-604296e95a1a@k19g2000yqc.googlegroups.com> Message-ID: On Feb 17, 1:40?pm, Paul McGuire wrote: > On Feb 16, 5:48?pm, Imaginationworks wrote: > > > Hi, > > > I am trying to read object information from a text file (approx. > > 30,000 lines) with the following format, each line corresponds to a > > line in the text file. ?Currently, the whole file was read into a > > string list using readlines(), then use for loop to search the "= {" > > and "};" to determine the Object, SubObject,and SubSubObject. > > If you open(filename).read() this file into a variable named data, the > following pyparsing parser will pick out your nested brace > expressions: > > from pyparsing import * > > EQ,LBRACE,RBRACE,SEMI = map(Suppress,"={};") > ident = Word(alphas, alphanums) > contents = Forward() > defn = Group(ident + EQ + Group(LBRACE + contents + RBRACE + SEMI)) > > contents << ZeroOrMore(defn | ~(LBRACE|RBRACE) + Word(printables)) > > results = defn.parseString(data) > > print results > > Prints: > > [ > ?['Object1', > ? ?['...', > ? ? ['SubObject1', > ? ? ? ['....', > ? ? ? ? ['SubSubObject1', > ? ? ? ? ? ['...'] > ? ? ? ? ] > ? ? ? ] > ? ? ], > ? ? ['SubObject2', > ? ? ? ['....', > ? ? ? ?['SubSubObject21', > ? ? ? ? ?['...'] > ? ? ? ?] > ? ? ? ] > ? ? ], > ? ? ['SubObjectN', > ? ? ? ['....', > ? ? ? ?['SubSubObjectN', > ? ? ? ? ?['...'] > ? ? ? ?] > ? ? ? ] > ? ? ] > ? ?] > ?] > ] > > -- Paul Wow, that is great! Thanks From comptekki at gmail.com Wed Feb 17 18:48:38 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 17 Feb 2010 16:48:38 -0700 Subject: string to list when the contents is a list Message-ID: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> I have been trying to create a list form a string. The string will be a list (this is the contents will look like a list). i.e. "[]" or "['a','b']" The "[]" is simple since I can just check if value == "[]" then return [] But with "['a','b']" I have tried and get: a="['a','b']" b=a[1:-1].split(',') returns [ " 'a' "," 'b' " ] when I want it to return ['a','b']. How can I do this? thx, -wes From comptekki at gmail.com Wed Feb 17 18:53:56 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 17 Feb 2010 16:53:56 -0700 Subject: error trying to join #python on irc.freenode.net Message-ID: <533df7fa1002171553m4a0e5949wf8461473ea5d5c13@mail.gmail.com> When I try to join #python on irc.freenode.net it keeps saying: You need to identify with network services to join the room "#python" on "irc.freenode.net". Server Details: Cannot join channel (+r) - you need to be identified with services What does this mean? thx, -wes From comptekki at gmail.com Wed Feb 17 18:56:06 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 17 Feb 2010 16:56:06 -0700 Subject: error trying to join #python on irc.freenode.net In-Reply-To: <533df7fa1002171553m4a0e5949wf8461473ea5d5c13@mail.gmail.com> References: <533df7fa1002171553m4a0e5949wf8461473ea5d5c13@mail.gmail.com> Message-ID: <533df7fa1002171556t4ad514fgd1eddee0d948391c@mail.gmail.com> On Wed, Feb 17, 2010 at 4:53 PM, Wes James wrote: > When I try to join #python on irc.freenode.net it keeps saying: > > You need to identify with network services to join the room "#python" > on "irc.freenode.net". > > Server Details: > Cannot join channel (+r) - you need to be identified with services > > What does this mean? Nevermind, I think it means I need to register with the service and supply real username/password. -wes From vlastimil.brom at gmail.com Wed Feb 17 19:08:32 2010 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Thu, 18 Feb 2010 01:08:32 +0100 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> Message-ID: <9fdb569a1002171608h6dd4f936he1417148426da574@mail.gmail.com> 2010/2/18 Wes James : > I have been trying to create a list form a string. ?The string will be > a list (this is the contents will look like a list). ?i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. > > How can I do this? > > thx, > > -wes > -- > http://mail.python.org/mailman/listinfo/python-list > The potentially problematic exec or eval options left aside, if you really need to do this, you might consider pyparsing; check the example http://pyparsing.wikispaces.com/file/view/parsePythonValue.py If you know, the input string will always have this exact format (single quoted comma separated one-character strings between square brackets), you might use regular expressions to some extent, e.g. print re.findall(r"(?<=')\w(?=')", "['a','b','c','b','A']") ['a', 'b', 'c', 'b', 'A'] hth, vbr From dyamins at gmail.com Wed Feb 17 19:09:06 2010 From: dyamins at gmail.com (Dan Yamins) Date: Wed, 17 Feb 2010 19:09:06 -0500 Subject: Wrap and intercept function calls In-Reply-To: References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: <15e4667e1002171609h5de4fd17y370ead62f7fee737@mail.gmail.com> > For CPython, alternative 1 is to create a custom interpreter to change > (wrap) the interpretation of the call-function bytecode in the ceval loop. > That is its 'call event', and I believe this would catch every explicit > f(args) call and only such calls. > > > Python has no general metasyntax for changing the semantics of its syntax. > The __xx__ methods are special cases for the corresponding operators *and* > the corresponding user-defined class. The '__call__' method of a class > applies to instances of that class. Alternative 2: > > Terry thanks for your response. My hoped-for spec explicitly prohibits wrapping required each (user-defined) function to be wrapped individual, since I want to be able to have this wrapping behavior apply to many functions created by many users on the fly, and such users can't be asked to remember to wrap each function. (At most, they can be asked to set a single evironment variable or the like at the beginning of modules or interpreter sessions that should the "turn on wrapping" for all future function calls.) So I suppose the situation is as I feared? That the only way to achieve my goal without having to wrap every (user-defined) function call individually is to modify the interpreter. Is there no way to edit frame objects from inside a function? if I could do that in a settrace function, would it even help? Also: am I right in thinking that the "modified interpreter" approach would mean that my resulting software couldn't be used as a 3-rd party module, that could be easily integrated into existing python installations? Or is there some standard way of integrating dynamically loadable modifications to the interpreter in python? (e.g. so that users of my code wouldn't have to re-install of their existing modules in a separate new python installation?) Thanks! Dan > >> > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rhodri at wildebst.demon.co.uk Wed Feb 17 19:13:05 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Feb 2010 00:13:05 -0000 Subject: string to list when the contents is a list References: Message-ID: On Wed, 17 Feb 2010 23:48:38 -0000, Wes James wrote: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" If your string is trusted (i.e. goes nowhere near a user), just eval() it. -- Rhodri James *-* Wildebeeste Herder to the Masses From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 19:37:15 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 00:37:15 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> Message-ID: On Thu, 18 Feb 2010 11:46:52 +1300, Lawrence D'Oliveiro wrote: > In message , cjw wrote: > >> Aren't lambda forms better described as function? > > Is this a function? > > lambda : None > > What about this? > > lambda : sys.stdout.write("hi there!\n") Of course they are; the first is a function that takes no arguments and returns None, and the second is a function that takes no arguments, returns None, and has a side-effect of writing "hi there\n" to stout. But I imagine you already know that, so I'm not really sure I understand the point of your (rhetorical?) question. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 19:47:20 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 00:47:20 GMT Subject: string to list when the contents is a list References: Message-ID: On Thu, 18 Feb 2010 00:13:05 +0000, Rhodri James wrote: > On Wed, 17 Feb 2010 23:48:38 -0000, Wes James > wrote: > >> I have been trying to create a list form a string. The string will be >> a list (this is the contents will look like a list). i.e. "[]" or >> "['a','b']" > > If your string is trusted (i.e. goes nowhere near a user), just eval() > it. Or use something like YAML or JSON to parse it. Fredrik Lundh has a simple_eval function which should be safe to use: http://effbot.org/zone/simple-iterator-parser.htm But it's fairly simple to parse a simple list like this. Here's a quick and dirty version: def string_to_list(s): s = s.strip() if not s.startswith('[') and s.endswith(']'): raise ValueError s = s[1:-1].strip() items = [item.strip() for item in s.split(',')] for i, item in enumerate(items): items[i] = dequote(item) return items def dequote(s): for delimiter in ('"""', "'''", '"', "'"): if s.startswith(delimiter) and s.endswith(delimiter): n = len(delimiter) return s[n:-n] raise ValueError >>> s = "['a','b']" >>> print s ['a','b'] >>> string_to_list(s) ['a', 'b'] >>> x = string_to_list(s) >>> type(x) >>> x ['a', 'b'] -- Steven From breamoreboy at yahoo.co.uk Wed Feb 17 19:49:45 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Feb 2010 00:49:45 +0000 Subject: Which mock library do you prefer? In-Reply-To: References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: Phlip wrote: > On Feb 17, 6:26 am, Lacrima wrote: > >> Right, isolation is essential. > > Please read my reply: Ben is well intentioned but completely wrong > here. > > Mock abuse will not cure the runtime isolation problem. > I believe that Ben is perfectly correct, and that you are talking at cross purposes because you've missed the significance of his (you later realise) within his post. Runtime test isolation doesn't enter into from what I can see. Can you please clarify the situation one way or the other. TIA. Mark Lawrence. From mccredie at gmail.com Wed Feb 17 19:51:39 2010 From: mccredie at gmail.com (Matt McCredie) Date: Thu, 18 Feb 2010 00:51:39 +0000 (UTC) Subject: string to list when the contents is a list References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> Message-ID: Wes James gmail.com> writes: > > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. > > How can I do this? eval will work, but has a safety issue. It also has the issue of evaluating any and everything that a user might pass in. If you are using python 2.6 check out ast.literal_eval. It uses python's built in ast parser to generate an AST and then traverses it to generate a python object. Unlike eval though, it will raise an exception if anything other than a literal is represented in the string. I have used the same function in python 2.5 (copied from 2.6) and it works just fine. Here is a version modified from the code in python 2.6 that should only parse lists of strings: from _ast import List, Str, PyCF_ONLY_AST def parse(expr, filename='', mode='exec'): """ Parse an expression into an AST node. Equivalent to compile(expr, filename, mode, PyCF_ONLY_AST). """ return compile(expr, filename, mode, PyCF_ONLY_AST) def list_eval(text): """ Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None. """ node = parse(text, mode='eval').body if not isinstance(node, List): raise ValueError('malformed string') def _convert(node): if isinstance(node, Str): return node.s raise ValueError('malformed string') return list(map(_convert, node.elts)) Matt McCredie From ben+python at benfinney.id.au Wed Feb 17 19:58:19 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 11:58:19 +1100 Subject: string to list when the contents is a list References: Message-ID: <87y6irbbro.fsf@benfinney.id.au> Wes James writes: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" Pulling back to ask about the larger problem: Are you trying to create Python data structures from a serialised representation? There are several well-implemented solutions, including the standard library modules ?pickle? and ?json?. Do you have control over the choice of serialisation format? -- \ ?I went to court for a parking ticket; I pleaded insanity. I | `\ said ?Your Honour, who in their right mind parks in the passing | _o__) lane??? ?Steven Wright | Ben Finney From jgardner at jonathangardner.net Wed Feb 17 20:00:50 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:00:50 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: On Feb 17, 10:39?am, John Bokma wrote: > Jonathan Gardner writes: > > Then I looked at a stack trace from a different programming language > > with lots of anonymous functions. (I believe it was perl.) > > > I became enlightened. > > If it was Perl [1], I doubt it. Because line numbers are reported, and > if that doesn't help you, you can annotate anonymous functions with a > nick name using > > local *__ANON__ = 'nice name'; > > Finding an issue, and not looking for a solution is not called becoming > enlightened ;-) > > ~$ perl -e ' > use Carp; > > my $anon = sub { local *__ANON__ = "hello, world"; croak "oops"; }; > $anon->(); > ' > > oops at -e line 4 > ? ? ? ? main::hello, world() called at -e line 5 > > As you can see, and a line number is generated, and the nice name is > shown. > > If you generate anonymouse functions on the fly based on parameters, you > can encode this into the nice name, of course. > > Sadly, often bold statements about a language are made in ignorance. > $ perl -e '$a = sub () {die "it may have been javascript, but"}; $b = sub () {die "I am pretty sure it was perl"}; $b->()' From jgardner at jonathangardner.net Wed Feb 17 20:02:41 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:02:41 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> On Feb 17, 12:02?am, Lawrence D'Oliveiro wrote: > In message > <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, > > Jonathan Gardner wrote: > > I used to think anonymous functions (AKA blocks, etc...) would be a > > nice feature for Python. > > > Then I looked at a stack trace from a different programming language > > with lots of anonymous functions. (I believe it was perl.) > > Didn?t it have source line numbers in it? > > What more do you need? I don't know, but I tend to find the name of the function I called to be useful. It's much more memorable than line numbers, particularly when line numbers keep changing. I doubt it's just me, though. From jgardner at jonathangardner.net Wed Feb 17 20:04:00 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:04:00 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> On Feb 17, 12:02?am, Lawrence D'Oliveiro wrote: > In message <60b1abce-4381-46ab-91ed- > > f2ab2154c... at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: > > Also, lambda's are expressions, not statements ... > > Is such a distinction Pythonic, or not? For example, does Python distinguish > between functions and procedures? Not to the programmer, no. Callables are callable, no matter what they are, and they are all called the same way. (What the heck is a procedure, anyway? Is this different from a subroutine, a method, or a block?) From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 20:06:41 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 01:06:41 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: On Wed, 17 Feb 2010 12:39:30 -0600, John Bokma wrote: > Jonathan Gardner writes: > >> Then I looked at a stack trace from a different programming language >> with lots of anonymous functions. (I believe it was perl.) >> >> I became enlightened. > > If it was Perl [1], I doubt it. Because line numbers are reported, and > if that doesn't help you, you can annotate anonymous functions with a > nick name using > > local *__ANON__ = 'nice name'; [...] > As you can see, and a line number is generated, and the nice name is > shown. Given that it has a nice name, what makes it an anonymous function? It seems to me that Perl effectively has three ways of creating functions, one anonymous and two named (even if one syntax for creating a named function is almost identical to the syntax for creating an anonymous function). Once you annotate a function with a nickname, it's no different from giving it a name. If this is the case, then your answer to "anonymous functions are a PITA" is "don't use anonymous functions", which exactly the same answer we'd give here in Python land. The only difference is that Perl provides two ways of making a named function, and Python only one[1]. [1] Technically, you can make named functions with the new module and a bit of work, so Python has two ways too. -- Steven From jgardner at jonathangardner.net Wed Feb 17 20:13:23 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 17 Feb 2010 17:13:23 -0800 (PST) Subject: How to efficiently extract information from structured text file References: Message-ID: <0f783ced-0414-4b44-acf1-79f8d288f41c@z10g2000prh.googlegroups.com> On Feb 16, 3:48?pm, Imaginationworks wrote: > Hi, > > I am trying to read object information from a text file (approx. > 30,000 lines) with the following format, each line corresponds to a > line in the text file. ?Currently, the whole file was read into a > string list using readlines(), then use for loop to search the "= {" > and "};" to determine the Object, SubObject,and SubSubObject. My > questions are > > 1) Is there any efficient method that I can search the whole string > list to find the location of the tokens(such as '= {' or '};' > > 2) Is there any efficient ways to extract the object information you > may suggest? Parse it! Go full-bore with a real parser. You may want to consider one of the many fine Pythonic implementations of modern parsers, or break out more traditional parsing tools. This format is nested, meaning that you can't use regexes to parse what you want out of it. You're going to need a real, full-bore, no- holds-barred parser for this. Don't worry, the road is not easy but the destination is absolutely worth it. Once you come to appreciate and understand parsing, you have earned the right to call yourself a red-belt programmer. To get your black- belt, you'll need to write your own compiler. Having mastered these two tasks, there is no problem you cannot tackle. And once you realize that every program is really a compiler, then you have truly mastered the Zen of Programming in Any Programming Language That Will Ever Exist. With this understanding, you will judge programming language utility based solely on how hard it is to write a compiler in it, and complexity based on how hard it is to write a compiler for it. (Notice there are not a few parsers written in Python, as well as Jython and PyPy and others written for Python!) From rhodri at wildebst.demon.co.uk Wed Feb 17 20:20:42 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Thu, 18 Feb 2010 01:20:42 -0000 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 01:04:00 -0000, Jonathan Gardner wrote: > On Feb 17, 12:02 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message <60b1abce-4381-46ab-91ed- >> >> f2ab2154c... at g19g2000yqe.googlegroups.com>, Andrej Mitrovic wrote: >> > Also, lambda's are expressions, not statements ... >> >> Is such a distinction Pythonic, or not? For example, does Python >> distinguish >> between functions and procedures? > > Not to the programmer, no. Callables are callable, no matter what they > are, and they are all called the same way. > > (What the heck is a procedure, anyway? Is this different from a > subroutine, a method, or a block?) In classic Pascal, a procedure was distinct from a function in that it had no return value. The concept doesn't really apply in Python; there are no procedures in that sense, since if a function terminates without supplying an explicit return value it returns None. -- Rhodri James *-* Wildebeeste Herder to the Masses From ben+python at benfinney.id.au Wed Feb 17 20:20:49 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 12:20:49 +1100 Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> Message-ID: <87tytfbaq6.fsf@benfinney.id.au> Lacrima writes: > Right, isolation [of test cases] is essential. But I can't decide to > which extent I should propagate isolation. You used ?propagate? in a sense I don't understand there. > For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, > author suggests that if you do unittesting you should isolate the > smallest units of code from each other. I'm not sure what the author means, but I would say that as it stands that advice is independent of what testing is being done. In all cases: * Make your code units small, so each one is not doing much and is easy to understand. * Make the interface of units at each level as narrow as feasible, so they're not brittle in the face of changes to the implementation. > For example, if you have a > class: > Class SomeClass(object): > def method1(self): > return 5 > def method2(self): > return self.method1 + 10 > > According to the book, if you want to test method2, you should isolate > it from method1 and class instance('self'). I don't really know what that means. Remember that each test case should not be ?test method1?. That is far too broad, and in some cases too narrow. There is no one-to-one mapping between methods and unit test cases. Instead, each test case should test one true-or-false assertion about the behaviour of the code. ?When we start with this initial state (the test fixture), and perform this operation, the resulting state is that?. It makes a lot of sense to name the test case so the assertion being made *is* its name: not ?test frobnicate? with dozens of assertions, but one ?test_frobnicate_with_valid_spangulator_returns_true? which makes that assertion, and extra ones for each distinct assertion. The failure of a unit test case should indicate *exactly* what has gone wrong. If you want to make multiple assertions about a code unit, write multiple test cases for that unit and name the tests accordingly. This incidentally requires that you test something small enough that such a true-or-false assertion is meaningful, which leads to well-designed code with small easily-tested code units. But that's an emergent property, not a natural law. > Currently, I don't create mocks of units if they are within the same > class with the unit under test. If that is not right approach, please, > explain what are best practices... I am just learning TDD.. In the fixture of the unit test case, create whatever test doubles are necessary to put your code into the initial state you need for the test case; then tear all those down whatever the result of the test case. If you need to create great honking wads of fixtures for any test case, that is a code smell: your code units are too tightly coupled to persistent state, and need to be decoupled with narrow interfaces. The Python ?unittest? module makes this easier by letting you define fixtures common to many test cases (the ?setUp? and ?tearDown? interface). My rule of thumb is: if I need to make different fixtures for some set of test cases, I write a new test case class for those cases. -- \ ?Following fashion and the status quo is easy. Thinking about | `\ your users' lives and creating something practical is much | _o__) harder.? ?Ryan Singer, 2008-07-09 | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 20:38:29 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 01:38:29 GMT Subject: How to efficiently extract information from structured text file References: <0f783ced-0414-4b44-acf1-79f8d288f41c@z10g2000prh.googlegroups.com> Message-ID: On Wed, 17 Feb 2010 17:13:23 -0800, Jonathan Gardner wrote: > And once you realize that every program is really a compiler, then you > have truly mastered the Zen of Programming in Any Programming Language > That Will Ever Exist. In the same way that every tool is really a screwdriver. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 17 20:39:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 01:39:05 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: On Wed, 17 Feb 2010 17:04:00 -0800, Jonathan Gardner wrote: > (What the heck is a procedure, anyway? Is this different from a > subroutine, a method, or a block?) The name is used in Pascal, which probably means it originated from Fortran or Algol. A subroutine is a generic piece of code which can be re-used by some unspecified mechanism (GOSUB in Basic, by calling it in most other languages). A function is a subroutine that returns a result, and a procedure is a subroutine that doesn't return anything (not even None, or the equivalent thereof) and operates entirely by side-effect. -- Steven From debatem1 at gmail.com Wed Feb 17 20:44:11 2010 From: debatem1 at gmail.com (geremy condra) Date: Wed, 17 Feb 2010 20:44:11 -0500 Subject: Wrap and intercept function calls In-Reply-To: <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: On Wed, Feb 17, 2010 at 11:04 AM, Dan Yamins wrote: > Really, nobody has any idea about this??? (Sorry to repost.) > > On Tue, Feb 16, 2010 at 7:29 PM, Dan Yamins wrote: >> >> Hi: >> >> I'm wondering what the best way to wrap and modify function calls is. >> Essentially what I want to achieve is to have a function like this: >> >> def Wrap(frame,event,arg): >> ???? if event == 'call': >> ??????? result = PerformCheck(GetArgumentsFromFrame(frame)) >> ??????? if Condition(result): >> ??????????? return result >> ??????? else: >> ??????????? return [normal function call] >> >> called whenever a "call" event is about to occur. >> >> When I say "return result" I mean:? return that data object instead of >> what the function would have returned, and prevent execution of the >> function. >> >> Is there any way to do this using sys.settrace?? Or perhaps something from >> the bdb or pbd module? >> > > In other words, what I'm looking for is a way to intercept all function > calls with a "wrapper" --? like one can do using settrace and other > debugging methods -- but, unlike the debugging methods, have the "wrapping" > function actually be able to intervene in the stack and, for instance, > conditionally replace the function call's return with something determined > in the wrapping function and prevent the function call's execution.?? I want > to be able to do this by setting a single system-wide (or at any rate, > thread-wide) value, like with settrace, and not have to modify individual > functions one by one. > > Could I, for example, set a settrace function that somehow modifies the > stack?? Or is there some much better way to do this?? Or, if someone can > tell me that this can't be done without having to roll my own implementation > of the Python interpreter, that would be great to know too. > > Thanks again, > Dan > > > -- > http://mail.python.org/mailman/listinfo/python-list > > You could drill down through everything in globals() etc, replacing functions as you went, but its fragile (there are probably unworkable corner cases), ugly, and likely to be slow. What exactly is it you're trying to do? Geremy Condra From john at castleamber.com Wed Feb 17 21:23:19 2010 From: john at castleamber.com (John Bokma) Date: Wed, 17 Feb 2010 20:23:19 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: <87ocjncmeg.fsf@castleamber.com> Steven D'Aprano writes: > On Wed, 17 Feb 2010 12:39:30 -0600, John Bokma wrote: [..] >> If it was Perl [1], I doubt it. Because line numbers are reported, and >> if that doesn't help you, you can annotate anonymous functions with a >> nick name using >> >> local *__ANON__ = 'nice name'; > [...] >> As you can see, and a line number is generated, and the nice name is >> shown. > > Given that it has a nice name, what makes it an anonymous function? You can't do nice name(); It just changes what perl reports. > If this is the case, then your answer to "anonymous functions are a > PITA" I don't think anon functions are in general a PITA. Like with most things, (I) use them in moderation. > is "don't use anonymous functions", which exactly the same answer we'd > give here in Python land. The only difference is that Perl provides two > ways of making a named function, and Python only one[1]. Note that the local trick doesn't create a named function. There are other ways of course to create named functions in Perl, e.g. perl -e '*foo=sub { print "hello, world\n" }; foo();' Which can be fun: perl -e ' sub AUTOLOAD { my $name = our $AUTOLOAD; *$AUTOLOAD = sub { local $" = ", "; print "$name(@_)\n" }; goto &$AUTOLOAD; } foo(40); bar("hello", "world!"); baz(foo(10));' output: main::foo(40) main::bar(hello, world!) main::foo(10) main::baz(1) NB: calling foo 10 returns 1 (return value of print). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From showell30 at yahoo.com Wed Feb 17 21:27:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 17 Feb 2010 18:27:41 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> On Feb 17, 5:39?pm, Steven D'Aprano wrote: > On Wed, 17 Feb 2010 17:04:00 -0800, Jonathan Gardner wrote: > > (What the heck is a procedure, anyway? Is this different from a > > subroutine, a method, or a block?) > > The name is used in Pascal, which probably means it originated from > Fortran or Algol. > > A subroutine is a generic piece of code which can be re-used by some > unspecified mechanism (GOSUB in Basic, by calling it in most other > languages). A function is a subroutine that returns a result, and a > procedure is a subroutine that doesn't return anything (not even None, or > the equivalent thereof) and operates entirely by side-effect. > Those are useful clarifications, but they are not completely universal. Some people make the definition of function more restrictive--"if it has side effects, it is not a function." Python's definition of a method is also not universal. In some circles, method is more akin to Steven's definition of a procedure--it does not necessarily have to be associated with a class. It's all very confusing, which is why Pythonistas are typically adamant about clarifying definitions within Python's context, which is understandable. To the extent that we're all talking about one programming language, we should use the same terms. A quick Google search does not turn up an official definition of a Ruby block, although the term "block" is colloquially used in both Python and Ruby to refer to a bunch of lines of code executed in a particular context, like a loop. Python may not support the broadest notion of anonymous functions, but it definitely has anonymous blocks. You can write this in Python: for i in range(10): print i print i * i print i * i * i Python does not force you to do this: def do_stuff(i): print i print i * i print i * i * i for i in range(10): do_stuff(i) From jmheralds at gmail.com Wed Feb 17 21:29:49 2010 From: jmheralds at gmail.com (James Heralds) Date: Wed, 17 Feb 2010 18:29:49 -0800 (PST) Subject: Draft paper submission deadline is extended: SETP-10, Orlando, USA Message-ID: It would be highly appreciated if you could share this announcement with your colleagues, students and individuals whose research is in software engineering, software testing, software quality assurance, software design and related areas. Draft paper submission deadline is extended: SETP-10, Orlando, USA The 2010 International Conference on Software Engineering Theory and Practice (SETP-10) (website: http://www.PromoteResearch.org) will be held during 12-14 of July 2010 in Orlando, FL, USA. SETP is an important event in the areas of Software development, maintenance, and other areas of software engineering and related topics. The conference will be held at the same time and location where several other major international conferences will be taking place. The conference will be held as part of 2010 multi-conference (MULTICONF-10). MULTICONF-10 will be held during July 12-14, 2010 in Orlando, Florida, USA. The primary goal of MULTICONF is to promote research and developmental activities in computer science, information technology, control engineering, and related fields. Another goal is to promote the dissemination of research to a multidisciplinary audience and to facilitate communication among researchers, developers, practitioners in different fields. The following conferences are planned to be organized as part of MULTICONF-10. ? International Conference on Artificial Intelligence and Pattern Recognition (AIPR-10) ? International Conference on Automation, Robotics and Control Systems (ARCS-10) ? International Conference on Bioinformatics, Computational Biology, Genomics and Chemoinformatics (BCBGC-10) ? International Conference on Computer Communications and Networks (CCN-10) ? International Conference on Enterprise Information Systems and Web Technologies (EISWT-10) ? International Conference on High Performance Computing Systems (HPCS-10) ? International Conference on Information Security and Privacy (ISP-10) ? International Conference on Image and Video Processing and Computer Vision (IVPCV-10) ? International Conference on Software Engineering Theory and Practice (SETP-10) ? International Conference on Theoretical and Mathematical Foundations of Computer Science (TMFCS-10) MULTICONF-10 will be held at Imperial Swan Hotel and Suites. It is a full-service resort that puts you in the middle of the fun! Located 1/2 block south of the famed International Drive, the hotel is just minutes from great entertainment like Walt Disney World? Resort, Universal Studios and Sea World Orlando. Guests can enjoy free scheduled transportation to these theme parks, as well as spacious accommodations, outdoor pools and on-site dining ? all situated on 10 tropically landscaped acres. Here, guests can experience a full- service resort with discount hotel pricing in Orlando. We invite draft paper submissions. Please see the website http://www.PromoteResearch.org for more details. From wuwei23 at gmail.com Wed Feb 17 21:42:44 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Feb 2010 18:42:44 -0800 (PST) Subject: Wrap and intercept function calls References: <15e4667e1002161629y10b1a116h4bad4990d0c9c73d@mail.gmail.com> <15e4667e1002170804j3ab980a7j467142b9f2c8837@mail.gmail.com> Message-ID: Terry Reedy wrote: > Now wrap *every* function you are interested in. Builtin functions are > no problem; methods of builtin classes cannont be wrapped without > subclassing. It's a shame it's not possible to do: type.__call__ = func_wrap(type.__call__) Or even: type.__class__ = NewType From andrej.mitrovich at gmail.com Wed Feb 17 21:59:14 2010 From: andrej.mitrovich at gmail.com (Andrej Mitrovic) Date: Wed, 17 Feb 2010 18:59:14 -0800 (PST) Subject: Traversing through variable-sized lists References: <4B7C4284.8070709@optimum.net> <9049f975-cd60-4591-a73b-1142a0728ee7@v25g2000yqk.googlegroups.com> Message-ID: <5906ad53-5853-4021-8af6-8b91b2a7e3e5@g11g2000yqe.googlegroups.com> On Feb 17, 11:56?pm, Dave Angel wrote: > Andrej Mitrovic wrote: > > On Feb 17, 8:24 pm, John Posner wrote: > > >> On 2/17/2010 1:10 PM, Andrej Mitrovic wrote: > > >> > > > However the values list might have an uneven number of items. I would > > like to make it as evenly distributed as possible, e.g.: > > > values =-2, -1, 0] > > frames =obj1, obj2, obj3, obj4, obj5, obj6, obj7, obj8] > > > frames[0].func(values[0]) ?# func.(values[-2]) > > frames[1].func(values[0]) ?# func.(values[-2]) > > frames[2].func(values[1]) ?# func.(values[-2]) > > frames[3].func(values[1]) ?# func.(values[-1]) > > frames[4].func(values[1]) ?# func.(values[-1]) > > frames[5].func(values[2]) ?# func.(values[-1]) > > frames[6].func(values[2]) ?# func.(values[0]) > > frames[7].func(values[2]) ?# func.(values[0]) > > > I'll be even more specific. I have a Minimum and Maximum value that > > the user enters. The frame.func() function is a "translate" function, > > it basically moves a frame in the application in one direction or > > another depending on the argument value. So frame[0].func(2) would > > move the frame[0] 2 pixels to the right. So what I want is the > > function to create a smooth transition of all the frames from the > > Minimum to the Maximum value. If minimum was 0, and maximum was 10, > > I'd want the first frame moved 0 pixels (it stays in place), the last > > frame to move 10 pixels, and the frames between are gradually moved > > from 1 pixels to 9 pixels relative from their positions. > > > Perhaps I'm just overcomplicating. I'll have a look at some drawing > > apps and see how they've implemented drawing straight lines under an > > angle, I guess that could be called a gradual change of values. > > > Thanks for all the suggestions everyone, I'll have a look at the rest > > shortly. > > I think you're overcomplicating. ?If you have 27 frames, and you want > frame 0 to move 0 pixels, and frame 27 to move 10 pixels, then you want > to move frame[i] by i*10/27. ?And since you do the multiply first, the > fact that Python 2.x division gives you integers isn't a problem. > > There are fancier methods for drawing lines (bresenham for example), but > the main purpose of them is to to avoid multiply and divide, as well as > floats. ?But in Python, an integer multiply is just as fast as an add or > subtract, so there's no point. > > DaveA Doh! Such a simple solution, just what I was looking for. Thanks! From showell30 at yahoo.com Wed Feb 17 22:10:31 2010 From: showell30 at yahoo.com (Steve Howell) Date: Wed, 17 Feb 2010 19:10:31 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> Message-ID: On Feb 16, 4:19?pm, Jonathan Gardner wrote: > On Feb 16, 11:41?am, Andrej Mitrovic > wrote: > > > > > On Feb 16, 7:38?pm, Casey Hawthorne > > wrote: > > > > Interesting talk on Python vs. Ruby and how he would like Python to > > > have just a bit more syntactic flexibility. > > > >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > > > -- > > > Regards, > > > Casey > > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > > linked to): "Python has no comparable equivalent to Ruby?s do end > > block. Python lambdas are limited to one line and can?t contain > > statements (for, if, def, etc.). Which leaves me wondering, what?s the > > point?" > > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > > expressions, not statements, but you can pass them around, keep them > > in a dictionary if you want to. And if you need more than one line of > > statements, for crying out loud use a def? And who needs those "do- > > end" blocks anyway, trying to turn Python into Pascal? > > I used to think anonymous functions (AKA blocks, etc...) would be a > nice feature for Python. > > Then I looked at a stack trace from a different programming language > with lots of anonymous functions. (I believe it was perl.) > > I became enlightened. I use Ruby a lot in my day job, and we rarely use blocks are as anonymous callback functions, which was probably the source of your pain in other languages. Often Ruby blocks are just three or four lines of code that are inlined into a still small function, so as long as the outer function is still small (which Ruby's blocks help with--they promote terseness), it's pretty easy to find a buggy function within a traceback that is not overly big. It's also possible in Ruby to use quality-promoting techniques like unit testing, pair programming, deliberateness, etc., to avoid the need for looking at tracebacks in the first place. Python is not immune to hard-to-understand tracebacks, since you often don't often know how a method got itself into the stracktrace in the first place: Traceback (most recent call last): File "foo.py", line 11, in foo(method) File "foo.py", line 2, in foo method() File "foo.py", line 5, in bar raise Exception('I am broken!') Exception: I am broken! Even though there's no direct lexical reference to bar() in foo(), lo and behold, foo() ends up calling bar(): def foo(method): method() def bar(): raise Exception('I am broken!') def broken_function_factory(): return bar method = broken_function_factory() foo(method) From pavlovevidence at gmail.com Wed Feb 17 22:18:14 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Wed, 17 Feb 2010 19:18:14 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87fx4zlna5.fsf@castleamber.com> Message-ID: On Feb 17, 10:39?am, John Bokma wrote: > Jonathan Gardner writes: > > Then I looked at a stack trace from a different programming language > > with lots of anonymous functions. (I believe it was perl.) > > > I became enlightened. > > If it was Perl [1], I doubt it. Because line numbers are reported Ok so sonetimes I'm looking at a stack trace and sometimes I can tell what the bug is just by lookong at the function namess. But if it has just line numbers I have to dig through my code looking for the line. > and > if that doesn't help you, you can annotate anonymous functions with a > nick name using > > local *__ANON__ = 'nice name'; > > Finding an issue, and not looking for a solution is not called becoming > enlightened ;-) The issue is that a stacktrace showing a bunch of nameless line numbers can be a bad idea, not that Perl might be deficient (and we already know that in any case), so it's not good to use a lot of them. Anyway once you annotate an anonymous function, it's no longer anonymous. > ~$ perl -e ' > use Carp; > > my $anon = sub { local *__ANON__ = "hello, world"; croak "oops"; }; > $anon->(); > ' > > oops at -e line 4 > ? ? ? ? main::hello, world() called at -e line 5 > > As you can see, and a line number is generated, and the nice name is > shown. > > If you generate anonymouse functions on the fly based on parameters, you > can encode this into the nice name, of course. > > Sadly, often bold statements about a language are made in ignorance. I don't see what he said was any kind of a bold statement about a language, arguably it was about the coding style. That Perl allows annotating functions doesn't mean people do it. Carl Banks > > [1] perl is the program that executes Perl programs ;-). > > -- > John Bokma ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? j3b > > Hacking & Hiking in Mexico - ?http://johnbokma.com/http://castleamber.com/- Perl & Python Development From philip at semanchuk.com Wed Feb 17 22:27:27 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Wed, 17 Feb 2010 22:27:27 -0500 Subject: Python 3.0 usage? Message-ID: Hi all, I'm the author of an extension (posix_ipc) that works under Python 2.4 - 2.6. I have a version that works under Python 2.4-2.6 and 3.1 and I would like to release it, but it doesn't work under Python 3.0. I could hack up Python 3.0-specific workarounds, but I'm not sure it's worth it. I'm interested in opinions -- is Python 3.0 seeing use in production anywhere, or did most of the Python world move to 3.1 as soon as it was released? Thanks Philip From wolftracks at invalid.com Wed Feb 17 22:36:13 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:36:13 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters (the latest) In-Reply-To: References: Message-ID: <4B7CB5AD.6000900@invalid.com> > On 17 February 2010 07:25, wrote: > > On Wed, Feb 17, 2010 at 12:10 AM, Wayne Watson > > wrote: >> >> Hi, I'm working on a 1800+ line program that uses tkinter. Here are the >> >> messages I started getting recently. (I finally figured out how to copy >> >> them.). The program goes merrily on its way despite them. >> >> >> >> >> >> s\sentuser>sentuser_20080716NoiseStudy7.py >> >> C:\Python25\lib\site-packages\scipy\misc\__init__.py:25: >> >> DeprecationWarning: Num >> >> pyTest will be removed in the next release; please update your code to >> >> use nose >> >> or unittest >> >> test = NumpyTest().test > > > > DeprecationWarnings mean some some functionality in numpy (or scipy) > > has changed and the old way of doing things will be removed and be > > invalid in the next version. > > > > During depreciation the old code still works, but before you upgrade > > you might want to check whether and how much you use these functions > > and switch to the new behavior. > > > > In the case of numpy.test, it means that if you have tests written > > that use the numpy testing module, then you need to switch them to the > > new nose based numpy.testing. And you need to install nose for running > > numpy.test() Wayne - The DeprecationWarnings are being raised by SciPy, not by your code. You probably don't have a recent version of SciPy installed. The most recent release of SciPy is 0.7.1 and works with NumPy 1.3.0. I don't think you will see the warnings if you upgrade SciPy and NumPy on your system. Check your NumPy and SciPy versions at a python prompt as follows: >>> >>> import numpy as np >>> >>> print np.__version__ >>> >>> import scipy as sp >>> >>> print sp.__version__ You will need to completely remove the old versions if you choose to upgrade. You should be able to do this from "Add/Remove Programs". Cheers, Scott _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion at scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion From wolftracks at invalid.com Wed Feb 17 22:36:24 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:36:24 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters (the latest) In-Reply-To: References: Message-ID: <4B7CB5B8.3010000@invalid.com> > On 17 February 2010 07:25, wrote: > > On Wed, Feb 17, 2010 at 12:10 AM, Wayne Watson > > wrote: >> >> Hi, I'm working on a 1800+ line program that uses tkinter. Here are the >> >> messages I started getting recently. (I finally figured out how to copy >> >> them.). The program goes merrily on its way despite them. >> >> >> >> >> >> s\sentuser>sentuser_20080716NoiseStudy7.py >> >> C:\Python25\lib\site-packages\scipy\misc\__init__.py:25: >> >> DeprecationWarning: Num >> >> pyTest will be removed in the next release; please update your code to >> >> use nose >> >> or unittest >> >> test = NumpyTest().test > > > > DeprecationWarnings mean some some functionality in numpy (or scipy) > > has changed and the old way of doing things will be removed and be > > invalid in the next version. > > > > During depreciation the old code still works, but before you upgrade > > you might want to check whether and how much you use these functions > > and switch to the new behavior. > > > > In the case of numpy.test, it means that if you have tests written > > that use the numpy testing module, then you need to switch them to the > > new nose based numpy.testing. And you need to install nose for running > > numpy.test() Wayne - The DeprecationWarnings are being raised by SciPy, not by your code. You probably don't have a recent version of SciPy installed. The most recent release of SciPy is 0.7.1 and works with NumPy 1.3.0. I don't think you will see the warnings if you upgrade SciPy and NumPy on your system. Check your NumPy and SciPy versions at a python prompt as follows: >>> >>> import numpy as np >>> >>> print np.__version__ >>> >>> import scipy as sp >>> >>> print sp.__version__ You will need to completely remove the old versions if you choose to upgrade. You should be able to do this from "Add/Remove Programs". Cheers, Scott _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion at scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion From wolftracks at invalid.com Wed Feb 17 22:39:41 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:39:41 -0800 Subject: Updating Packages in 2.5 (win/numpy) and Related Matters (the latest) Message-ID: Had trouble posting this to the same thread above. Request above to provide response from numpy mail list. > On 17 February 2010 07:25, wrote: > > On Wed, Feb 17, 2010 at 12:10 AM, Wayne Watson > > wrote: >> >> Hi, I'm working on a 1800+ line program that uses tkinter. Here are the >> >> messages I started getting recently. (I finally figured out how to copy >> >> them.). The program goes merrily on its way despite them. >> >> >> >> >> >> s\sentuser>sentuser_20080716NoiseStudy7.py >> >> C:\Python25\lib\site-packages\scipy\misc\__init__.py:25: >> >> DeprecationWarning: Num >> >> pyTest will be removed in the next release; please update your code to >> >> use nose >> >> or unittest >> >> test = NumpyTest().test > > > > DeprecationWarnings mean some some functionality in numpy (or scipy) > > has changed and the old way of doing things will be removed and be > > invalid in the next version. > > > > During depreciation the old code still works, but before you upgrade > > you might want to check whether and how much you use these functions > > and switch to the new behavior. > > > > In the case of numpy.test, it means that if you have tests written > > that use the numpy testing module, then you need to switch them to the > > new nose based numpy.testing. And you need to install nose for running > > numpy.test() Wayne - The DeprecationWarnings are being raised by SciPy, not by your code. You probably don't have a recent version of SciPy installed. The most recent release of SciPy is 0.7.1 and works with NumPy 1.3.0. I don't think you will see the warnings if you upgrade SciPy and NumPy on your system. Check your NumPy and SciPy versions at a python prompt as follows: >>> >>> import numpy as np >>> >>> print np.__version__ >>> >>> import scipy as sp >>> >>> print sp.__version__ You will need to completely remove the old versions if you choose to upgrade. You should be able to do this from "Add/Remove Programs". Cheers, Scott _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion at scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion From wolftracks at invalid.com Wed Feb 17 22:42:28 2010 From: wolftracks at invalid.com (W. eWatson) Date: Wed, 17 Feb 2010 19:42:28 -0800 Subject: Wrestling with the Py2exe Install, Win7, Py2.5 In-Reply-To: References: Message-ID: On 2/17/2010 3:44 AM, mk wrote: > W. eWatson wrote: > > > P.S. I didn't really use PyInstaller on Windows, though -- just on > Linux, where it works beautifully. > > Regards, > mk > Well,Ive made some progress with a py2exe tutorial. It starts with the short "hello world!" program. But something stumbled right away in setup.py. I'm on a mail list to sort this out. From python at mrabarnett.plus.com Wed Feb 17 22:51:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Feb 2010 03:51:11 +0000 Subject: Python 3.0 usage? In-Reply-To: References: Message-ID: <4B7CB92F.9050100@mrabarnett.plus.com> Philip Semanchuk wrote: > Hi all, > I'm the author of an extension (posix_ipc) that works under Python 2.4 - > 2.6. I have a version that works under Python 2.4-2.6 and 3.1 and I > would like to release it, but it doesn't work under Python 3.0. I could > hack up Python 3.0-specific workarounds, but I'm not sure it's worth it. > I'm interested in opinions -- is Python 3.0 seeing use in production > anywhere, or did most of the Python world move to 3.1 as soon as it was > released? > Python 3.0 had a relatively short run before it was superseded by Python 3.1 due to certain issues, so, IMHO, I wouldn't worry about it unless someone especially requests/requires it. From no.email at nospam.invalid Wed Feb 17 23:13:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 17 Feb 2010 20:13:59 -0800 Subject: MediaWiki to RTF/Word/PDF References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: <7xfx4zp4e0.fsf@ruckus.brouhaha.com> Josh English writes: > Has anyone heard of a module that parses wiki markup and transforms > it? Or am I looking at XSLT? MediaWiki markup is quite messy and unless MediaWiki has an XML export feature that I don't know about, I don't see what good XSLT can do you. (The regular MediaWiki API generates XML results with wiki markup embedded in it). It looks like mediawiki itself can create pdf's (see any page on en.wikibooks.org for example), but the rendered pdf is not that attractive. I remember something about a Haskell module to parse mediawiki markup, if that is of any use. From rogerb at rogerbinns.com Thu Feb 18 00:19:54 2010 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 17 Feb 2010 21:19:54 -0800 Subject: Python 3.0 usage? In-Reply-To: References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Philip Semanchuk wrote: > is Python 3.0 seeing use in production > anywhere, or did most of the Python world move to 3.1 as soon as it was > released? Python 3.0 has been end of lifed: http://www.python.org/download/releases/3.0.1/ Consequently no one should be using it in production. Incidentally my own extension is in a similar situation to yours - Python 2.3 onwards is supported for the 2.x family. I did support 3.0 from beta releases onwards but various changes in the library between 3.0 and 3.1 and the end of lifing of 3.0 meant I dropped 3.0 support. No one has asked for it since. Roger -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkt8zfoACgkQmOOfHg372QS2cACgznTcQXRcxMqqlfIt4F0C2TaX d9IAoNhkY1dvX1aKlONyVGIL2zplNNF7 =jM8O -----END PGP SIGNATURE----- From wuwei23 at gmail.com Thu Feb 18 00:20:15 2010 From: wuwei23 at gmail.com (alex23) Date: Wed, 17 Feb 2010 21:20:15 -0800 (PST) Subject: Python 3.0 usage? References: Message-ID: MRAB wrote: > Python 3.0 had a relatively short run before it was superseded by Python > 3.1 due to certain issues, so, IMHO, I wouldn't worry about it unless > someone especially requests/requires it. And even then, I'd just tell them I accept patches :) From sreejithemk at gmail.com Thu Feb 18 01:48:43 2010 From: sreejithemk at gmail.com (Sreejith K) Date: Wed, 17 Feb 2010 22:48:43 -0800 (PST) Subject: Creating Import Hooks Message-ID: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Hi everyone, I need to implement custom import hooks for an application (http:// www.python.org/dev/peps/pep-0302/). I want to restrict an application to import certain modules (say socket module). Google app engine is using a module hook to do this (HardenedModulesHook in google/ appengine/tools/dev_appserver.py). But I want to allow that application to use an sdk module (custom) which imports and uses socket module. But the module hook restricts the access by sdk. Finding out, which file is importing a module give a solution?? ie. If the application is importing socket module, I want to restrict it. But if the sdk module is importing socket I want to allow it. Is there any way I can do this ? Application ======== import sdk import socket # I dont want to allow this (need to raise ImportError) SDK ==== import socket # need to allow this From jgardner at jonathangardner.net Thu Feb 18 03:03:51 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 00:03:51 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Feb 17, 10:48?pm, Sreejith K wrote: > Hi everyone, > > I need to implement custom import hooks for an application (http://www.python.org/dev/peps/pep-0302/). I want to restrict an application > to import certain modules (say socket module). Google app engine is > using a module hook to do this (HardenedModulesHook in google/ > appengine/tools/dev_appserver.py). But I want to allow that > application to use an sdk module (custom) which imports and uses > socket module. But the module hook restricts the access by sdk. > Finding out, which file is importing a module give a solution?? ie. If > the application is importing socket module, I want to restrict it. But > if the sdk module is importing socket I want to allow it. Is there any > way I can do this ? > > Application > ======== > import sdk > import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > ImportError) > > SDK > ==== > import socket ? ? ? ? ? ? ? # need to allow this SDK === import socket App === import SDK import sys socket = sys.modules['socket'] From timr at probo.com Thu Feb 18 03:07:02 2010 From: timr at probo.com (Tim Roberts) Date: Thu, 18 Feb 2010 00:07:02 -0800 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> Message-ID: <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> DANNY wrote: > >Hm, well I see that and now I am thinking of using reference software >for MPEG4/10 which is written in c++ http://iphome.hhi.de/suehring/tml/ >just to use it as a decoder on my client side, save the file in that >format and then play it in my player using pyffmpeg >http://code.google.com/p/pyffmpeg/ and just manipulate frames in that >clip-I think that could be possible....am I right? After you have passed the video through a decoder, it's no longer in MPEG format at all. It's just a series of bitmaps, so pyffmpeg wouldn't apply. If you want to save the raw MPEG data, you can certainly do that, but such data is often not divided into "frames". -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steven at REMOVE.THIS.cybersource.com.au Thu Feb 18 03:57:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 08:57:01 GMT Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > On Feb 17, 10:48?pm, Sreejith K wrote: >> Hi everyone, >> >> I need to implement custom import hooks for an application >> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an >> application to import certain modules (say socket module). Google app >> engine is using a module hook to do this (HardenedModulesHook in >> google/ appengine/tools/dev_appserver.py). But I want to allow that >> application to use an sdk module (custom) which imports and uses socket >> module. But the module hook restricts the access by sdk. Finding out, >> which file is importing a module give a solution?? ie. If the >> application is importing socket module, I want to restrict it. But if >> the sdk module is importing socket I want to allow it. Is there any way >> I can do this ? >> >> Application >> ======== >> import sdk >> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise >> ImportError) >> >> SDK >> ==== >> import socket ? ? ? ? ? ? ? # need to allow this > > > SDK > === > import socket > > App > === > import SDK > import sys > socket = sys.modules['socket'] I'm not sure, but I think Sreejith wants to prohibit imports from the App layer while allowing them from the SDK layer, not work around a prohibition in the SDK layer. In other words, he wants the import hook to do something like this: if module is socket and the caller is not SKD: prohibit else allow I could be wrong of course. -- Steven From lallous at lgwm.org Thu Feb 18 04:09:58 2010 From: lallous at lgwm.org (lallous) Date: Thu, 18 Feb 2010 01:09:58 -0800 (PST) Subject: Python library for working with simple equations Message-ID: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Hello Is there is any Python library that allow such things: Given a string expression as: x + 5 + x * (y + 2), any library that can develop the equation for example. Or if we say factor with "x" then it renders the expression with x * ( rest of expression ). There could be a functionality where when x,y are given then the expression can be evaluated. If there are two expressions, they can be added and the symbols preserved. Does such a thing exist? Thanks, Elias From clp2 at rebertia.com Thu Feb 18 04:17:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Feb 2010 01:17:42 -0800 Subject: Python library for working with simple equations In-Reply-To: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: <50697b2c1002180117v7f9cd5e5rbcf4276581369468@mail.gmail.com> On Thu, Feb 18, 2010 at 1:09 AM, lallous wrote: > Hello > > Is there is any Python library that allow such things: > > Given a string expression as: x + 5 + x * (y + 2), any library that > can develop the equation for example. > Or if we say factor with "x" then it renders the expression with x * > ( rest of expression ). > There could be a functionality where when x,y are given then the > expression can be evaluated. > If there are two expressions, they can be added and the symbols > preserved. > > Does such a thing exist? They're called computer algebra systems: http://en.wikipedia.org/wiki/Computer_algebra_system SymPy is one for Python: http://code.google.com/p/sympy/ Don't know if it supports factoring specifically; I've never used it, I just have Google-Fu. Cheers, Chris -- http://blog.rebertia.com From duncan.booth at invalid.invalid Thu Feb 18 04:23:29 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Feb 2010 09:23:29 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> Message-ID: Jonathan Gardner wrote: > On Feb 17, 12:02?am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message >> <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, >> >> Jonathan Gardner wrote: >> > I used to think anonymous functions (AKA blocks, etc...) would be a >> > nice feature for Python. >> >> > Then I looked at a stack trace from a different programming >> > language with lots of anonymous functions. (I believe it was perl.) >> >> Didn?t it have source line numbers in it? >> >> What more do you need? > > I don't know, but I tend to find the name of the function I called to > be useful. It's much more memorable than line numbers, particularly > when line numbers keep changing. > > I doubt it's just me, though. Some problems with using just line numbers to track errors: In any language it isn't much use if you get a bug report from a shipped program that says there was an error on line 793 but no report of exactly which version of the shipped code was being run. Microsoft love telling you the line number: if IE gets a Javascript error it reports line number but not filename, so you have to guess which of the HTML page or one of many included files actually had the error. Plus the line number that is reported is often slightly off. Javascript in particular is often sent to the browser compressed then uncompressed and eval'd. That makes line numbers completely useless for tracking down bugs as you'll always get the line number of the eval. Also the way functions are defined in Javascript means you'll often have almost every function listed in a backtrace as 'Anonymous'. -- Duncan Booth http://kupuguy.blogspot.com From fetchinson at googlemail.com Thu Feb 18 04:24:10 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 10:24:10 +0100 Subject: Python library for working with simple equations In-Reply-To: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: > Given a string expression as: x + 5 + x * (y + 2), any library that > can develop the equation for example. > Or if we say factor with "x" then it renders the expression with x * > ( rest of expression ). > There could be a functionality where when x,y are given then the > expression can be evaluated. > If there are two expressions, they can be added and the symbols > preserved. Take a look at sage: http://www.sagemath.org/ I wouldn't say it's simple, in fact it's huge, but it'll do the job. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From sreejithemk at gmail.com Thu Feb 18 04:28:37 2010 From: sreejithemk at gmail.com (Sreejith K) Date: Thu, 18 Feb 2010 01:28:37 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Feb 18, 1:57?pm, Steven D'Aprano wrote: > On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > > On Feb 17, 10:48?pm, Sreejith K wrote: > >> Hi everyone, > > >> I need to implement custom import hooks for an application > >> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an > >> application to import certain modules (say socket module). Google app > >> engine is using a module hook to do this (HardenedModulesHook in > >> google/ appengine/tools/dev_appserver.py). But I want to allow that > >> application to use an sdk module (custom) which imports and uses socket > >> module. But the module hook restricts the access by sdk. Finding out, > >> which file is importing a module give a solution?? ie. If the > >> application is importing socket module, I want to restrict it. But if > >> the sdk module is importing socket I want to allow it. Is there any way > >> I can do this ? > > >> Application > >> ======== > >> import sdk > >> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > >> ImportError) > > >> SDK > >> ==== > >> import socket ? ? ? ? ? ? ? # need to allow this > > > SDK > > === > > import socket > > > App > > === > > import SDK > > import sys > > socket = sys.modules['socket'] > > I'm not sure, but I think Sreejith wants to prohibit imports from the App > layer while allowing them from the SDK layer, not work around a > prohibition in the SDK layer. > > In other words, he wants the import hook to do something like this: > > if module is socket and the caller is not SKD: > ? ? prohibit > else > ? ? allow > > I could be wrong of course. > > -- > Steven @Steven, Thats exactly what I want.. Anyway to do that ?? From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 04:43:17 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 10:43:17 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> Message-ID: <4b7d0baa$0$13729$426a74cc@news.free.fr> Mark Lawrence a ?crit : > Ben Finney wrote: >> Bruno Desthuilliers writes: >> >>> Mmmm... Let's try to explain the whole damn thing. It's really (and >>> IMHO beautifully) simple once you get it, but I agree it's a bit >>> peculiar when compared to most mainstream OO languages. >> [?] >> >> Bruno, that's the first time I've understood the descriptor protocol, or >> even understood *why* the descriptor protocol is important. >> >> Could you please post (a version of) this as a separate article >> somewhere? A weblog post, or a new thread in this forum, or in the >> documentation? Somewhere that web searches will find it prominently when >> searching for the Python descriptor protocol. >> >> Thank you. >> > > I'll second, third and fourth this request. More please Bruno, or from > anybody similarly qualified. > > Thanks very much. First, thanks Ben and Mark for the kind words... I never tried to google for them, but there must be at least 4 previous posts here where I tried to explain the topic. Perhaps this latest attempt was better ?-) But anyway : if it's about making this text easier to find, it seems that posting it here is not the most efficient solution !-) Anyway : I don't have a blog and don't really have enough time / motivation for blogging. Now if anyone is willing and able to host such a text on his own website / blog / whatever, I'd be happy to rework it a bit. /wrt to have it in the documentation and the "from anybody similarly qualified", there's already a pretty comprehensive article in the official docs (well : linked from the official docs), from someone who's _way_ more qualified that I'll ever be - FWIW, everything I explained here and all my knowledge of the descriptor protocol, methods etc come from this article: http://users.rcn.com/python/download/Descriptor.htm But I understand it can be a bit intimidating for newcomers, so yes, perhaps a lighter introductory text could be helpful. So guys, if you think a revised version of my post would be of interest, I'll take you on words: provide the hosting, I'll provide the content !-) B. From danijel.gvero at gmail.com Thu Feb 18 04:50:14 2010 From: danijel.gvero at gmail.com (DANNY) Date: Thu, 18 Feb 2010 01:50:14 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> Message-ID: <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> If I want to have a MPEG-4/10 coded video and stream it through the network and than have the same video on the client side, what should I use and of course I don't want to have raw MPEG data, because than I couldn't extract the frames to manipulate them. From mrkafk at gmail.com Thu Feb 18 04:59:40 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 10:59:40 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <7a9c25c21002171051o4bc48483qbb82cc65668434f6@mail.gmail.com> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <7a9c25c21002171051o4bc48483qbb82cc65668434f6@mail.gmail.com> Message-ID: Stephen Hansen wrote: > Or just leave it as a top level function where it was perfectly happy to > live :) Yes. This is probably the sanest solution anyway, because probably having many such functions to use, packing them into smth like package.utils anyway is a good idea. I'm trying mainly to learn and test-drive such solutions, not that I would be keen to use them excessively in production code. > This obviously means no other method can call it like > self.print_internal_date(), because self would get passed as first > argument, yes? > > > It doesn't have to be. It could be a class method-- @classmethod does > that, makes it receive 'cls' the actual class as the first argument. Or > a @staticmethod, in which case it has no first-argument at all. Ahh now I get it. Thanks! So that's the use for @staticmethod (I was wondering if there was any). From snakylove at googlemail.com Thu Feb 18 05:09:39 2010 From: snakylove at googlemail.com (Snaky Love) Date: Thu, 18 Feb 2010 02:09:39 -0800 (PST) Subject: How to use AWS/PAA nowadays? PyAWS / pyamazon outdated? Message-ID: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> Hi, is anybody aware of any updated and / or maintained library for accessing AWS/PAA with Python? I found the dusty pyamazon and a derivate of it, pyaws, but both of them do not seem to support request signatures which must be used by August 15, 2009 to use the Amazon Services, and generally seem to be a little bit outdated... Is there a better way doing signed requests to AWS/PAA nowadays? How are you doing it? I found a good PHP Library here: http://getcloudfusion.com/docs - but I would like to program stuff with python - is there anything pythonic that is close to that? Thank you very much for your attention, have a nice day, Snaky From ben+python at benfinney.id.au Thu Feb 18 05:36:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 18 Feb 2010 21:36:30 +1100 Subject: Referring to class methods in class attributes References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> <4b7d0baa$0$13729$426a74cc@news.free.fr> Message-ID: <87d402bzkh.fsf@benfinney.id.au> Bruno Desthuilliers writes: > perhaps a lighter introductory text could be helpful. So guys, if you > think a revised version of my post would be of interest, I'll take you > on words: provide the hosting, I'll provide the content !-) Here, let me work my hosting magic: . -- \ ?Choose mnemonic identifiers. If you can't remember what | `\ mnemonic means, you've got a problem.? ?Larry Wall | _o__) | Ben Finney From leo at lspace.org Thu Feb 18 05:46:58 2010 From: leo at lspace.org (Leo Breebaart) Date: 18 Feb 2010 10:46:58 GMT Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> Message-ID: <7u4k52F6jsU1@mid.individual.net> Arnaud Delobelle writes: > Descriptors to the rescue :) > > def read_body_from(filename): > print "** loading content **" > return "" % filename > > # This is a kind of class property > class TemplateFilename(object): > def __get__(self, obj, cls): > return "%s.tmpl" % cls.__name__ > > # And this is a kind of cached class property > class TemplateBody(object): > def __get__(self, obj, cls): > try: > return cls._body > except AttributeError: > cls._body = read_body_from(cls.template_filename) > return cls._body > > class Foo(object): > template_filename = TemplateFilename() > template_body = TemplateBody() > > class FooA(Foo): > pass > > class FooB(Foo): > pass Very enlightening, thanks! By the way, I completely agree with the other posters in this thread that intricate solutions such as this are likely to be overkill, especially since at this point I have no idea if the inefficiency of reading those templates multiple times would at all matter (frankly, I'd doubt it). But it's certainly been educational to learn about these techniques. One observation: if I implement the descriptor solution as given above, the code works perfectly, but running the code through pychecker now causes an error, because that again causes an attempt to read from the non-existant base class template file "Foo.tmpl"... -- Leo Breebaart From jeanmichel at sequans.com Thu Feb 18 05:49:28 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Feb 2010 11:49:28 +0100 Subject: Creating Import Hooks In-Reply-To: References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: <4B7D1B38.6080800@sequans.com> Sreejith K wrote: > On Feb 18, 1:57 pm, Steven D'Aprano > wrote: > >> On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: >> >>> On Feb 17, 10:48 pm, Sreejith K wrote: >>> >>>> Hi everyone, >>>> >>>> I need to implement custom import hooks for an application >>>> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an >>>> application to import certain modules (say socket module). Google app >>>> engine is using a module hook to do this (HardenedModulesHook in >>>> google/ appengine/tools/dev_appserver.py). But I want to allow that >>>> application to use an sdk module (custom) which imports and uses socket >>>> module. But the module hook restricts the access by sdk. Finding out, >>>> which file is importing a module give a solution?? ie. If the >>>> application is importing socket module, I want to restrict it. But if >>>> the sdk module is importing socket I want to allow it. Is there any way >>>> I can do this ? >>>> >>>> Application >>>> ======== >>>> import sdk >>>> import socket # I dont want to allow this (need to raise >>>> ImportError) >>>> >>>> SDK >>>> ==== >>>> import socket # need to allow this >>>> >>> SDK >>> === >>> import socket >>> >>> App >>> === >>> import SDK >>> import sys >>> socket = sys.modules['socket'] >>> >> I'm not sure, but I think Sreejith wants to prohibit imports from the App >> layer while allowing them from the SDK layer, not work around a >> prohibition in the SDK layer. >> >> In other words, he wants the import hook to do something like this: >> >> if module is socket and the caller is not SKD: >> prohibit >> else >> allow >> >> I could be wrong of course. >> >> -- >> Steven >> > > @Steven, Thats exactly what I want.. Anyway to do that ?? > import sys sys.modules['socket'] = None import socket --------------------------------------------------------------------------- ImportError Traceback (most recent call last) ImportError: No module named socket JM From fetchinson at googlemail.com Thu Feb 18 05:50:13 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 11:50:13 +0100 Subject: Python library for working with simple equations In-Reply-To: References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: >> Given a string expression as: x + 5 + x * (y + 2), any library that >> can develop the equation for example. >> Or if we say factor with "x" then it renders the expression with x * >> ( rest of expression ). >> There could be a functionality where when x,y are given then the >> expression can be evaluated. >> If there are two expressions, they can be added and the symbols >> preserved. > > Take a look at sage: http://www.sagemath.org/ > I wouldn't say it's simple, in fact it's huge, but it'll do the job. Probably you can isolate the part of sage that you actually need and can throw away 95% of it. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From d.dalton at iinet.net.au Thu Feb 18 06:09:05 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 18 Feb 2010 22:09:05 +1100 Subject: working with laptop battery In-Reply-To: <7f014ea61002131819x4ba766dds245220760ef74ff1@mail.gmail.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> <7f014ea61002131819x4ba766dds245220760ef74ff1@mail.gmail.com> Message-ID: <20100218110905.GB30547@debian-eeepc> On Sat, Feb 13, 2010 at 09:19:59PM -0500, Chris Colbert wrote: > You'll need acpi installed: > In [6]: import subprocess Thanks for that code, I'll try putting something together this weekend. Dan From d.dalton at iinet.net.au Thu Feb 18 06:11:51 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 18 Feb 2010 22:11:51 +1100 Subject: working with laptop battery In-Reply-To: <4B775EA0.7080207@tim.thechases.com> References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> <4B775EA0.7080207@tim.thechases.com> Message-ID: <20100218111151.GA31441@debian-eeepc> I'm not sure I have those files, but I'll look a little harder this weekend when I put together the script. Thanks for your help, Dan On Sat, Feb 13, 2010 at 08:23:28PM -0600, Tim Chase wrote: > Daniel Dalton wrote: > >On Sat, Feb 13, 2010 at 05:26:02PM -0800, Chris Rebert wrote: > >>It's probably gonna depend on which OS you're running. Which would be...? > > > >Sorry, forgot to mention this. I'm running debian linux. > > You should be able to read/poll the various files in > > /proc/acpi/battery/BAT*/* > > for whatever battery information you need. Each BAT* directory > contains information about one of the batteries in the system (it's > possible, albeit rare, to have more than one). So you might have > some script that runs every $INTERVAL that looks something like > > from glob import glob > for fname in glob('/proc/acpi/battery/BAT*/*'): > f = file(fname) > for line in f: > do_something(line) > f.close() > > On my Debian laptop (Gateway Solo 1200, OEM battery circa 2001), the > contents look something like > > tim at rubbish:/proc/acpi/battery/BAT0$ cat alarm > alarm: unsupported > tim at rubbish:/proc/acpi/battery/BAT0$ cat info > present: yes > design capacity: 4016 mAh > last full capacity: 4011 mAh > battery technology: rechargeable > design voltage: 9600 mV > design capacity warning: 602 mAh > design capacity low: 401 mAh > capacity granularity 1: 201 mAh > capacity granularity 2: 3409 mAh > model number: QT08 > serial number: SANYOQT08 > battery type: NiMH > OEM info: SANYO > tim at rubbish:/proc/acpi/battery/BAT0$ cat state > present: yes > capacity state: ok > charging state: charged > present rate: unknown > remaining capacity: 4011 mAh > present voltage: 9600 mV > > > > -tkc > From mrkafk at gmail.com Thu Feb 18 06:12:36 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 12:12:36 +0100 Subject: Static method Message-ID: Hello everyone, Disclaimer: I'm doing this mainly for learning purposes, to feel what it's good for. I'm trying to get print_internal_date become a static method AND to refer to it in a class attribute 'tagdata' dict. class PYFileInfo(FileInfo): 'python file properties' @staticmethod def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" insts = list_dir(r'c:\mp3i',['.mp3', '.py']) File "C:/mp3i/finfo2.py", line 93, in list_dir insts = [c(f) for c,f in class_files] File "C:/mp3i/finfo2.py", line 69, in __init__ FileInfo.__init__(self,fname) File "C:/mp3i/finfo2.py", line 12, in __init__ self['name'] = filename File "C:/mp3i/finfo2.py", line 74, in __setitem__ self.__get_props(value) File "C:/mp3i/finfo2.py", line 79, in __get_props self[tag] = fun(value) TypeError: 'staticmethod' object is not callable I think I know where the problem is: what resides in tagdata is a static method 'wrapper', not the function itself, according to: http://docs.python.org/reference/datamodel.html "Static method objects Static method objects provide a way of defeating the transformation of function objects to method objects described above. A static method object is a wrapper around any other object, usually a user-defined method object. When a static method object is retrieved from a class or a class instance, the object actually returned is the wrapped object, which is not subject to any further transformation. Static method objects are not themselves callable, although the objects they wrap usually are." So, how do I get out the wrapped function out of static method without class call or instance call? (to be called in self[tag] = fun(value)) Yes, I do know that if I just get rid of @staticmethod, this works without a hitch. From d.dalton at iinet.net.au Thu Feb 18 06:16:07 2010 From: d.dalton at iinet.net.au (Daniel Dalton) Date: Thu, 18 Feb 2010 22:16:07 +1100 Subject: working with laptop battery In-Reply-To: References: <20100214004831.GA21071@debian-eeepc> <50697b2c1002131726p19cd33bagdc921b0db926313e@mail.gmail.com> <20100214014324.GA4868@debian-eeepc> Message-ID: <20100218111607.GC31441@debian-eeepc> On Sun, Feb 14, 2010 at 03:22:11AM +0100, Daniel Fetchinson wrote: > /proc/acpi/battery/BAT0/info > /proc/acpi/battery/BAT0/state Had a quick look, but that path doesn't seem to exist, I'll look harder on the weekend when I put the script together, because it has to be somewhere. Thanks, Dan From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 06:20:25 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 12:20:25 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <87d402bzkh.fsf@benfinney.id.au> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> <87iq9vcydc.fsf@benfinney.id.au> <4b7d0baa$0$13729$426a74cc@news.free.fr> <87d402bzkh.fsf@benfinney.id.au> Message-ID: <4b7d226d$0$14717$426a74cc@news.free.fr> Ben Finney a ?crit : > Bruno Desthuilliers writes: > >> perhaps a lighter introductory text could be helpful. So guys, if you >> think a revised version of my post would be of interest, I'll take you >> on words: provide the hosting, I'll provide the content !-) > > Here, let me work my hosting magic: . Duh ! (me banging my head on the desktop) Ok, I'll do my part of the job then !-) From snakylove at googlemail.com Thu Feb 18 06:29:47 2010 From: snakylove at googlemail.com (Snaky Love) Date: Thu, 18 Feb 2010 03:29:47 -0800 (PST) Subject: MediaWiki to RTF/Word/PDF References: <0f65e2cf-6f3e-4719-ba30-9b44588f317b@s33g2000prm.googlegroups.com> Message-ID: Hi, - I checked some ways doing this, and starting over with a new thing will give you a lot of headaches - all XSLT processors have one or another problem - success depends very much on how you where using wikipedia (plugins?) and you will have to expect a lot of poking around with details and still not beeing happy with the solutions available - there are many really crazy approaches out there to generate pdf of mediawiki "markup" - many tried, not many succeeded, most of them stop at "good enough for me"-level. So it might be a good idea, not running too far away from what they are doing at http://code.pediapress.com - you will spend much less time with installing ubuntu in a virtualbox. However there is one quite impressive tool, that does pdf conversion via css and is good for getting the job done quick and not too dirty: http://www.princexml.com/samples/ - scroll down to the mediawiki examples - they offer a free license for non-commercial projects. Good luck! Have a nice day, Snaky From stefan_ml at behnel.de Thu Feb 18 06:32:51 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Feb 2010 12:32:51 +0100 Subject: Static method In-Reply-To: References: Message-ID: <4b7d2563$0$6581$9b4e6d93@newsspool3.arcor-online.net> mk, 18.02.2010 12:12: > I'm trying to get print_internal_date become a static method AND to > refer to it in a class attribute 'tagdata' dict. > > class PYFileInfo(FileInfo): > 'python file properties' > > @staticmethod > def print_internal_date(filename): > f = open(filename + 'c', "rb") > data = f.read(8) > mtime = struct.unpack(" return time.asctime(time.gmtime(mtime[0])) > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } You can 'unroll' the decorator like this: class PYFileInfo(FileInfo): def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" References: Message-ID: <4b7d2a78$0$21465$426a74cc@news.free.fr> mk a ?crit : > I'm trying to get print_internal_date become a static method AND to > refer to it in a class attribute 'tagdata' dict. > > class PYFileInfo(FileInfo): > 'python file properties' > > @staticmethod > def print_internal_date(filename): > f = open(filename + 'c', "rb") > data = f.read(8) > mtime = struct.unpack(" return time.asctime(time.gmtime(mtime[0])) > > tagdata = {'compiled_fname': lambda x: x + 'c', > 'size': os.path.getsize, > 'internal_date': print_internal_date > } (snip) > def __get_props(self, value): > py_compile.compile(value) > for tag, fun in PYFileInfo.tagdata.items(): > self[tag] = fun(value) > > But: > > c:/Python26/pythonw.exe -u "C:/mp3i/finfo2.py" > Traceback (most recent call last): (snip) > File "C:/mp3i/finfo2.py", line 79, in __get_props > self[tag] = fun(value) > TypeError: 'staticmethod' object is not callable > > > I think I know where the problem is: what resides in tagdata is a static > method 'wrapper', not the function itself, according to: Indeed. Sorry, I'm afraid I gave you bad advice wrt/ using a staticmethod here - I should know better :( (well, OTHO staticmethods are not something I use that often). Anyway: here are a simplified version of your problem, a possible solution that _won't_ statisfy your other constraints, 2 ugly hacks that could work but that I don't really like, and what's possibly the "less worse" solution if you really need a staticmethod here. ### class Foo1(object): """ simplified version of mk's code - test() fails """ @staticmethod def bar(baaz): print baaz tagada = {'bar': bar} def test(self, baaz): self.tagada['bar'](baaz) class Foo2(object): """ naive solution : kinda work, BUT will fail with the real code that has plain functions in 'tagada' """ @staticmethod def bar(baaz): print baaz tagada = {'bar': bar} def test(self, baaz): self.tagada['bar'].__get__(self)(baaz) class Foo3(object): """ working solution 1 : defer the wrapping of 'bar' as a staticmethod """ def bar(baaz): print baaz tagada = {'bar': bar} bar = staticmethod(bar) def test(self, baaz): self.tagada['bar'](baaz) class Foo4(object): """ working solution 2 : use a lambda """ @staticmethod def bar(baaz): print baaz tagada = {'bar': lambda x : Foo4.bar(x)} def test(self, baaz): self.tagada['bar'](baaz) """ and as a "less worse" solution """ def foo5bar(baaz): print baaz class Foo5(object): tagada = {'bar': foo5bar} bar = staticmethod(foo5bar) def test(self, baaz): self.tagada['bar'](baaz) ### Another "solution" might be to write an alternate callable implementation of 'staticmethod' - which I'll leave as an exercise to the reader (...) - but that's possibly a bit overkill !-) > http://docs.python.org/reference/datamodel.html > > So, how do I get out the wrapped function out of static method without > class call or instance call? (to be called in self[tag] = fun(value)) cf above. None of the solutions I could came with really statisfy me, but well, at least 3 of them might be "good enough" depending on the context. As far as I'm concerned, I'd first try the last one, but YMMV > Yes, I do know that if I just get rid of @staticmethod, this works > without a hitch. But then you can't use print_internal_date as a method !-) HTH From sreejithemk at gmail.com Thu Feb 18 07:15:43 2010 From: sreejithemk at gmail.com (Sreejith K) Date: Thu, 18 Feb 2010 04:15:43 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: <5b007f18-9041-465a-815f-8359f884265c@m27g2000prl.googlegroups.com> On Feb 18, 3:49?pm, Jean-Michel Pichavant wrote: > Sreejith K wrote: > > On Feb 18, 1:57 pm, Steven D'Aprano > > wrote: > > >> On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > > >>> On Feb 17, 10:48 pm, Sreejith K wrote: > > >>>> Hi everyone, > > >>>> I need to implement custom import hooks for an application > >>>> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an > >>>> application to import certain modules (say socket module). Google app > >>>> engine is using a module hook to do this (HardenedModulesHook in > >>>> google/ appengine/tools/dev_appserver.py). But I want to allow that > >>>> application to use an sdk module (custom) which imports and uses socket > >>>> module. But the module hook restricts the access by sdk. Finding out, > >>>> which file is importing a module give a solution?? ie. If the > >>>> application is importing socket module, I want to restrict it. But if > >>>> the sdk module is importing socket I want to allow it. Is there any way > >>>> I can do this ? > > >>>> Application > >>>> ======== > >>>> import sdk > >>>> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > >>>> ImportError) > > >>>> SDK > >>>> ==== > >>>> import socket ? ? ? ? ? ? ? # need to allow this > > >>> SDK > >>> === > >>> import socket > > >>> App > >>> === > >>> import SDK > >>> import sys > >>> socket = sys.modules['socket'] > > >> I'm not sure, but I think Sreejith wants to prohibit imports from the App > >> layer while allowing them from the SDK layer, not work around a > >> prohibition in the SDK layer. > > >> In other words, he wants the import hook to do something like this: > > >> if module is socket and the caller is not SKD: > >> ? ? prohibit > >> else > >> ? ? allow > > >> I could be wrong of course. > > >> -- > >> Steven > > > @Steven, Thats exactly what I want.. Anyway to do that ?? > > import sys > sys.modules['socket'] = None > > import socket > --------------------------------------------------------------------------- > ImportError ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last) > > ImportError: No module named socket > > JM @Jean. Thanks for the reply. But this is not what I wanted. The import hook already restricts socket imports in applications. But I want them in sdk package (alone) which is being imported in the application. I don't want applications to directly use the socket module. That means I want to make some exceptions for sdk in import hooks. From elias.bachaalany at gmail.com Thu Feb 18 07:28:00 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 18 Feb 2010 04:28:00 -0800 (PST) Subject: Help with lambda Message-ID: Hello, I am still fairly new to Python. Can someone explain to me why there is a difference in f and g: def make_power(n): return lambda x: x ** n # Create a set of exponential functions f = [lambda x: x ** n for n in xrange(2, 5)] g = [make_power(n) for n in xrange(2, 5)] print f[0](3), f[1](3) print g[0](3), g[1](3) I expect to have "f" act same like "g". Thanks From jeanmichel at sequans.com Thu Feb 18 07:38:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Feb 2010 13:38:30 +0100 Subject: Creating Import Hooks In-Reply-To: <5b007f18-9041-465a-815f-8359f884265c@m27g2000prl.googlegroups.com> References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> <5b007f18-9041-465a-815f-8359f884265c@m27g2000prl.googlegroups.com> Message-ID: <4B7D34C6.30809@sequans.com> Sreejith K wrote: > On Feb 18, 3:49 pm, Jean-Michel Pichavant > wrote: > >> Sreejith K wrote: >> >>> On Feb 18, 1:57 pm, Steven D'Aprano >>> wrote: >>> >>>> On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: >>>> >>>>> On Feb 17, 10:48 pm, Sreejith K wrote: >>>>> >>>>>> Hi everyone, >>>>>> >>>>>> I need to implement custom import hooks for an application >>>>>> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an >>>>>> application to import certain modules (say socket module). Google app >>>>>> engine is using a module hook to do this (HardenedModulesHook in >>>>>> google/ appengine/tools/dev_appserver.py). But I want to allow that >>>>>> application to use an sdk module (custom) which imports and uses socket >>>>>> module. But the module hook restricts the access by sdk. Finding out, >>>>>> which file is importing a module give a solution?? ie. If the >>>>>> application is importing socket module, I want to restrict it. But if >>>>>> the sdk module is importing socket I want to allow it. Is there any way >>>>>> I can do this ? >>>>>> >>>>>> Application >>>>>> ======== >>>>>> import sdk >>>>>> import socket # I dont want to allow this (need to raise >>>>>> ImportError) >>>>>> >>>>>> SDK >>>>>> ==== >>>>>> import socket # need to allow this >>>>>> >>>>> SDK >>>>> === >>>>> import socket >>>>> >>>>> App >>>>> === >>>>> import SDK >>>>> import sys >>>>> socket = sys.modules['socket'] >>>>> >>>> I'm not sure, but I think Sreejith wants to prohibit imports from the App >>>> layer while allowing them from the SDK layer, not work around a >>>> prohibition in the SDK layer. >>>> >>>> In other words, he wants the import hook to do something like this: >>>> >>>> if module is socket and the caller is not SKD: >>>> prohibit >>>> else >>>> allow >>>> >>>> I could be wrong of course. >>>> >>>> -- >>>> Steven >>>> >>> @Steven, Thats exactly what I want.. Anyway to do that ?? >>> >> import sys >> sys.modules['socket'] = None >> >> import socket >> --------------------------------------------------------------------------- >> ImportError Traceback (most recent call last) >> >> ImportError: No module named socket >> >> JM >> > > @Jean. Thanks for the reply. But this is not what I wanted. The import > hook already restricts socket imports in applications. But I want them > in sdk package (alone) which is being imported in the application. I > don't want applications to directly use the socket module. That means > I want to make some exceptions for sdk in import hooks. > give us your code (the hook import) in your entry file: import socket import sys sys.modules['sdkSocket'] = sys.modules['socket'] # allow to import socket ad sdkSocket sys.modules['socket'] = None # forbid to import socket del socket within your SDK: import sdkSocket # actually the socket module print sdkSocket.__file__ '/usr/lib/python2.5/socket.pyc' JM From arnodel at googlemail.com Thu Feb 18 07:39:08 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Feb 2010 12:39:08 +0000 Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> <7u4k52F6jsU1@mid.individual.net> Message-ID: Leo Breebaart writes: > Arnaud Delobelle writes: > >> Descriptors to the rescue :) >> >> def read_body_from(filename): >> print "** loading content **" >> return "" % filename >> >> # This is a kind of class property >> class TemplateFilename(object): >> def __get__(self, obj, cls): >> return "%s.tmpl" % cls.__name__ >> >> # And this is a kind of cached class property >> class TemplateBody(object): >> def __get__(self, obj, cls): >> try: >> return cls._body >> except AttributeError: >> cls._body = read_body_from(cls.template_filename) >> return cls._body >> >> class Foo(object): >> template_filename = TemplateFilename() >> template_body = TemplateBody() >> >> class FooA(Foo): >> pass >> >> class FooB(Foo): >> pass > > Very enlightening, thanks! > > By the way, I completely agree with the other posters in this > thread that intricate solutions such as this are likely to be > overkill, especially since at this point I have no idea if the > inefficiency of reading those templates multiple times would at > all matter (frankly, I'd doubt it). But it's certainly been > educational to learn about these techniques. Writing programs is a great way to keep learning :) > One observation: if I implement the descriptor solution as given > above, the code works perfectly, but running the code through > pychecker now causes an error, because that again causes an > attempt to read from the non-existant base class template file > "Foo.tmpl"... As someone said before, you could just provide a dummy Foo.tmpl file. -- Arnaud From mrkafk at gmail.com Thu Feb 18 07:42:57 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 13:42:57 +0100 Subject: Static method In-Reply-To: <4b7d2a78$0$21465$426a74cc@news.free.fr> References: <4b7d2a78$0$21465$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> I think I know where the problem is: what resides in tagdata is a >> static method 'wrapper', not the function itself, according to: > > Indeed. Sorry, I'm afraid I gave you bad advice wrt/ using a > staticmethod here - I should know better :( (well, OTHO staticmethods > are not something I use that often). Do not worry the least bit! I'm testdriving on a closed circuit here for sake of becoming better 'driver', I'm not going to drive like this on the streets. > class Foo2(object): > """ naive solution : kinda work, BUT will fail > with the real code that has plain functions > in 'tagada' > """ > @staticmethod > def bar(baaz): > print baaz > > tagada = {'bar': bar} > > def test(self, baaz): > self.tagada['bar'].__get__(self)(baaz) Well I could always do: if isinstance(self.tagada['bar'], staticmethod): self.tagada['bar'].__get__(self)(baaz) else: self.tagada['bar'](baaz) But 1. this apparently defeats the purpose of using print_internal_date on instance/class in 'normal' way, and 2. I probably shouldn't be doing that since using isinstance is apparently like playing with yourself: while technically legal, people look at you weirdly. :-) > > class Foo3(object): > """ working solution 1 : defer the wrapping > of 'bar' as a staticmethod > """ > def bar(baaz): > print baaz > > tagada = {'bar': bar} > > bar = staticmethod(bar) > > def test(self, baaz): > self.tagada['bar'](baaz) Neat! I like this one. > > > class Foo4(object): > """ working solution 2 : use a lambda """ > @staticmethod > def bar(baaz): > print baaz > > tagada = {'bar': lambda x : Foo4.bar(x)} > > def test(self, baaz): > self.tagada['bar'](baaz) Huh? How does this one work? After all, while in Foo4 body, the Foo4 does not exist yet? Does lambda defer evaluation to runtime (when it's executed) or smth? > > > """ and as a "less worse" solution """ > > def foo5bar(baaz): > print baaz > > class Foo5(object): > tagada = {'bar': foo5bar} > > bar = staticmethod(foo5bar) > > def test(self, baaz): > self.tagada['bar'](baaz) > Yes. I probably should have stayed with this one in the first place. I feel bad for using up bandwidth and people's attention with such stuff... From contact at xavierho.com Thu Feb 18 07:45:58 2010 From: contact at xavierho.com (Xavier Ho) Date: Thu, 18 Feb 2010 22:45:58 +1000 Subject: Help with lambda In-Reply-To: References: Message-ID: <2d56febf1002180445i3c95cc7dp9b5aafeb88fa51e@mail.gmail.com> I'm looking at your code and was thinking ... why writing code that is difficult to understand? To answer your question though, they're different because in case "f", your lambda experssion is only evaluated once. That means the variable 'n' is ever only created once, and replaced repeatedly. In the second case "g", the function is only ever created once, and in effect, the lambda expression is evaluated as a new expression every time the function is called. That's why it may have been what you wanted. Seriously though, you should use a generater instead. And if that doesn't work for you, just make a function mate. Way easier to read, and you don't have to have ugly calls like f[0](3). >>> def powers(n): ... for x in xrange(2,5): ... yield x ** n ... >>> for result in powers(3): ... print result ... 8 27 64 Cheers, Xav -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Thu Feb 18 07:47:23 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 13:47:23 +0100 Subject: Referring to class methods in class attributes In-Reply-To: <4b7c54a8$0$21284$426a74cc@news.free.fr> References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >> Thanks, that worked. But in order to make it work I had to get rid of >> 'self' in print_internal_date signature > > Indeed. Using it that way, the print_internal_date will not be wrapped > in a method object. Hold on! How does Python know what to wrap and what not to wrap, assuming of course programmer doesn't use @classmethod or @staticmethod? Bc self has no special significance, it's just a (strong) convention, Python can't know what's the first argument of a function supposed to be, self or regular argument, and therefore it has no way of differentiating between functions (defined in class body) designed to become methods and those that are not? Where can I read on Python internals like this (aside from post of yours, that is)? Bc frankly skimming http://docs.python.org/reference/ didn't give me impression that a lot on the subject is there (well there's some, I found smth akin to your explanation below, although yours is way more readable)? Thanks for explanation below -- I'm going to ask some related questions. > Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO > beautifully) simple once you get it, but I agree it's a bit peculiar > when compared to most mainstream OO languages. > > The first thing is that the def statement *always* yield a function > object. Always. If you don't believe it, try the following snippet: > > class Foo(object): > def bar(self): > return "baaz" > > print Foo.__dict__.keys() > print type(Foo.__dict__['bar']) Just one thing here: >>> Foo.bar Huh?! Why does it say 'unbound' method? Shouldn't that be bound method (bound to Foo, that is)? > So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? >>> type(Foo.__dict__['bar']) >>> type(Foo.bar) instancemethod - now that's something new. > The > answer is : attribute lookup rules and the descriptor protocol. > > To make a long story short, the descriptor protocol specify that, when, > during an attribute lookup, a name resolves to a class attribute AND > this attribute has a __get__ method, then this __get__ method is called > (with either the instance or None and the class itself as arguments) Depending, I assume, on whether this is instance call | class method call, respectively? Hmm why does the __get__ receive class as argument on top of instance | None? After all, when having an instance, the class can always be found by instance.__class__ ? Is this for sake of class methods? Python is science, I gather: an answer to one question bears another 10 questions. > and whatever it returns becomes the result of the attribute lookup. This > mechanism is what provides support for computed attributes. > > Now the trick is that the function type do implement the descriptor > protocol. So when a function is an attribute of a class object and you > try to access it as an attribute of either the class itself or an > instance of the class, it's __get__ method is called with the instance > (or None) and the class. > Having access to itself (of course), Quick question: how does a function access itself? Aside from rejected PEP (http://www.python.org/dev/peps/pep-3130/) I don't see the way of accessing itself outside globals() (and even then how would a function know its name -- well it shouldn't care about it really, as function object doesn't care how it's labelled, right?). Or does in "real Python" func's __get__ receive its own function (func) as an argument, like in your example implementation below? > the > instance (if there's one) and the class, it's easy for it to wrap all > this into a method object. Which is itself a callable object, that when > called mostly inject the instance as first object in the argument's list > and returns the result of calling the wrapped function object. Aha! So that's the mechanism that makes self magically appear in an argument list! I always wondered how it worked. !!THANKS!! > My 2 cents... Well, Bruno -- that was more like $200! Regards, mk From arnodel at googlemail.com Thu Feb 18 07:47:31 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Feb 2010 12:47:31 +0000 Subject: Help with lambda References: Message-ID: lallous writes: > Hello, > > I am still fairly new to Python. Can someone explain to me why there > is a difference in f and g: > > def make_power(n): > return lambda x: x ** n > > # Create a set of exponential functions > f = [lambda x: x ** n for n in xrange(2, 5)] > g = [make_power(n) for n in xrange(2, 5)] > > print f[0](3), f[1](3) > print g[0](3), g[1](3) > > > I expect to have "f" act same like "g". > > Thanks It's a FAQ! Except I don't think it's in the official Python FAQ, but it ought to be. The reason (very quickly) is that each time you call make_power() you create a new name 'n' which is bound to a different value each time, whereas in f: [lambda x: x ** n for n in xrange(2, 5)] The 'n' is the same name for each of the lambda functions and so is bound to the same value, which by the end of the loop is 4. So each of the lambdas in the list f is the same as: lambdsa x; x**4 after the end of the list comprehension. The usual fix for this is to change f to: f = [lambda x, n=n: x ** n for n in xrange(2, 5)] I'll let you think why this works. HTH -- Arnaud From elias.bachaalany at gmail.com Thu Feb 18 07:52:02 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 18 Feb 2010 04:52:02 -0800 (PST) Subject: Help with lambda References: Message-ID: <1a3903cd-b9f7-428b-a43d-47485e8620f6@g28g2000yqh.googlegroups.com> Yes it should be listed somewhere, now I get it. Thanks Arnaud. -- Elias On Feb 18, 1:47?pm, Arnaud Delobelle wrote: > lallous writes: > > Hello, > > > I am still fairly new to Python. Can someone explain to me why there > > is a difference in f and g: > > > def make_power(n): > > ? ? return lambda x: x ** n > > > # Create a set of exponential functions > > f = [lambda x: x ** n for n in xrange(2, 5)] > > g = [make_power(n) for n in xrange(2, 5)] > > > print f[0](3), f[1](3) > > print g[0](3), g[1](3) > > > I expect to have "f" act same like "g". > > > Thanks > > It's a FAQ! ?Except I don't think it's in the official Python FAQ, but > it ought to be. > > The reason (very quickly) is that each time you call make_power() you > create a new name 'n' which is bound to a different value each time, > whereas in f: > > ? ? [lambda x: x ** n for n in xrange(2, 5)] > > The 'n' is the same name for each of the lambda functions and so is > bound to the same value, which by the end of the loop is 4. ?So each of > the lambdas in the list f is the same as: > > ? ? lambdsa x; x**4 > > after the end of the list comprehension. > > The usual fix for this is to change f to: > > f = [lambda x, n=n: x ** n for n in xrange(2, 5)] > > I'll let you think why this works. > > HTH > > -- > Arnaud From darcy at druid.net Thu Feb 18 07:56:03 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 18 Feb 2010 07:56:03 -0500 Subject: Help with lambda In-Reply-To: References: Message-ID: <20100218075603.f37aab5f.darcy@druid.net> On Thu, 18 Feb 2010 04:28:00 -0800 (PST) lallous wrote: > def make_power(n): > return lambda x: x ** n Hint: type(make_power(2)) Did you expect that to return "int"? > # Create a set of exponential functions > f = [lambda x: x ** n for n in xrange(2, 5)] > g = [make_power(n) for n in xrange(2, 5)] The result of make_power(n) is a function that raises it's argument to the power of n. I don't know what you are trying to do. Maybe this? g = [make_power(n)(2) for n in xrange(2, 5)] or g = [make_power(2)(n) for n in xrange(2, 5)] -- 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 Feb 18 08:00:03 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 14:00:03 +0100 Subject: Static method In-Reply-To: References: <4b7d2a78$0$21465$426a74cc@news.free.fr> Message-ID: <4b7d39cb$0$23451$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: (snip) >> class Foo2(object): >> """ naive solution : kinda work, BUT will fail >> with the real code that has plain functions >> in 'tagada' >> """ >> @staticmethod >> def bar(baaz): >> print baaz >> >> tagada = {'bar': bar} >> >> def test(self, baaz): >> self.tagada['bar'].__get__(self)(baaz) > > Well I could always do: > > if isinstance(self.tagada['bar'], staticmethod): > self.tagada['bar'].__get__(self)(baaz) > else: > self.tagada['bar'](baaz) > > But 1. this apparently defeats the purpose of using print_internal_date > on instance/class in 'normal' way, and 2. I probably shouldn't be doing > that since using isinstance is apparently like playing with yourself: > while technically legal, people look at you weirdly. :-) As far as I'm concerned, this would be a valid use case for isinstance. But it breaks uniformity and requires quite a lot of mostly useless code. >> >> class Foo3(object): >> """ working solution 1 : defer the wrapping >> of 'bar' as a staticmethod >> """ >> def bar(baaz): >> print baaz >> >> tagada = {'bar': bar} >> >> bar = staticmethod(bar) >> >> def test(self, baaz): >> self.tagada['bar'](baaz) > > Neat! I like this one. Not me - with the wrapping so far away from the definition, it's too easy to miss part of the "process" when you come back to this code 6 month later. >> >> >> class Foo4(object): >> """ working solution 2 : use a lambda """ >> @staticmethod >> def bar(baaz): >> print baaz >> >> tagada = {'bar': lambda x : Foo4.bar(x)} >> >> def test(self, baaz): >> self.tagada['bar'](baaz) > > Huh? How does this one work? After all, while in Foo4 body, the Foo4 > does not exist yet? Does lambda defer evaluation to runtime (when it's > executed) or smth? or smth, yes !-) A lambda expression evals to an ordinary function - just like a def statement - so Foo4 is not resolved until Foo4.tagada['bar'] is actually called. >> """ and as a "less worse" solution """ >> >> def foo5bar(baaz): >> print baaz >> >> class Foo5(object): >> tagada = {'bar': foo5bar} >> >> bar = staticmethod(foo5bar) >> >> def test(self, baaz): >> self.tagada['bar'](baaz) >> > > Yes. I probably should have stayed with this one in the first place. I > feel bad for using up bandwidth and people's attention with such stuff... Why so ? You learned something, I learned something, and quite a few other people will now have a chance to learn something. Sensible use of bandwith as far as I'm concerned. wrt/ people's attention, don't worry, it's up to the reader to pay attention or skip the whole topic !-) From elias.bachaalany at gmail.com Thu Feb 18 08:08:03 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 18 Feb 2010 05:08:03 -0800 (PST) Subject: Help with lambda References: Message-ID: <62b3fe37-5f26-406b-a4e0-48bdb9a39b5c@e1g2000yqh.googlegroups.com> On Feb 18, 1:56?pm, "D'Arcy J.M. Cain" wrote: > On Thu, 18 Feb 2010 04:28:00 -0800 (PST) > > lallous wrote: > > def make_power(n): > > ? ? return lambda x: x ** n > > Hint: type(make_power(2)) > > Did you expect that to return "int"? > No, I expect to see a specialized function. > > # Create a set of exponential functions > > f = [lambda x: x ** n for n in xrange(2, 5)] > > g = [make_power(n) for n in xrange(2, 5)] > > The result of make_power(n) is a function that raises it's argument to > the power of n. ?I don't know what you are trying to do. ?Maybe this? > > g = [make_power(n)(2) for n in xrange(2, 5)] > or > g = [make_power(2)(n) for n in xrange(2, 5)] > What I am trying to do is generate different functions. If you're curious, I was playing with ctypes and wanted to see how it handles C<->Python callbacks: CB_T = WINFUNCTYPE(c_int, c_int) many_cb_t = CFUNCTYPE(c_int, c_int, CB_T) many_cb = many_cb_t(addressof(c_void_p.in_dll(dll, "many_cb"))) #ANY_SIMPLER def make_power(n): return lambda x: x ** n cbs = [CB_T(make_power(n)) for n in xrange(0, 1000)] cbs.append(None) many_cb(3, *cbs) And the C code in a shared lib: int many_cb(int value, ...) { va_list va; va = va_start(va, value); cb_t cb; int s = 0; while ( (cb = va_arg(va, cb_t)) != NULL) { printf("calling %p", cb); int r = cb(value); s += r; printf(", r=%d\n", r); } va_end(va); return s; } Speaking of that, anyone has an idea how to make simpler the line with #ANY_SIMPLER? I try: many_cb = CB_T.in_dll(dll, "many_cb") <- but that seems to work with data items only. From leo at lspace.org Thu Feb 18 08:27:30 2010 From: leo at lspace.org (Leo Breebaart) Date: 18 Feb 2010 13:27:30 GMT Subject: Using class attributes References: <7tti4iFehdU1@mid.individual.net> <7tvmgtF68lU1@mid.individual.net> <7u4k52F6jsU1@mid.individual.net> Message-ID: <7u4ti2Fv11U1@mid.individual.net> Arnaud Delobelle writes: > > One observation: if I implement the descriptor solution as > > given above, the code works perfectly, but running the code > > through pychecker now causes an error, because that again > > causes an attempt to read from the non-existant base class > > template file "Foo.tmpl"... It's not just pychecker that doesn't like the descriptor solution: pydoc now also crashes with the same IOError. :-) > As someone said before, you could just provide a dummy Foo.tmpl > file. A pragmatic solution, but one that smells bad to me. All this started because I didn't want my program to read files more than once, but I also don't want it to read files it doesn't have to read (and that don't even need to exist) in the first place! I'll just go back to the original instance-based lazy evaluation and caching solution now -- I never really had a big problem with that. My thanks again to all of you for helping me out with this. -- Leo Breebaart From steve at holdenweb.com Thu Feb 18 08:30:35 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 08:30:35 -0500 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: mk wrote: > Bruno Desthuilliers wrote: >>> Thanks, that worked. But in order to make it work I had to get rid of >>> 'self' in print_internal_date signature >> >> Indeed. Using it that way, the print_internal_date will not be wrapped >> in a method object. > > Hold on! How does Python know what to wrap and what not to wrap, > assuming of course programmer doesn't use @classmethod or @staticmethod? > Bc self has no special significance, it's just a (strong) convention, > Python can't know what's the first argument of a function supposed to > be, self or regular argument, and therefore it has no way of > differentiating between functions (defined in class body) designed to > become methods and those that are not? > > Where can I read on Python internals like this (aside from post of > yours, that is)? Bc frankly skimming http://docs.python.org/reference/ > didn't give me impression that a lot on the subject is there (well > there's some, I found smth akin to your explanation below, although > yours is way more readable)? > > Thanks for explanation below -- I'm going to ask some related questions. > >> Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO >> beautifully) simple once you get it, but I agree it's a bit peculiar >> when compared to most mainstream OO languages. >> >> The first thing is that the def statement *always* yield a function >> object. Always. If you don't believe it, try the following snippet: >> >> class Foo(object): >> def bar(self): >> return "baaz" >> >> print Foo.__dict__.keys() >> print type(Foo.__dict__['bar']) > > Just one thing here: > >>>> Foo.bar > > > Huh?! Why does it say 'unbound' method? Shouldn't that be bound method > (bound to Foo, that is)? > No. The "unbound method" means it's a callable class attribute. The significance of "unbound" is that no specific instance is attached. >> So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? > >>>> type(Foo.__dict__['bar']) > >>>> type(Foo.bar) > > > instancemethod - now that's something new. > Well "instancemethod" is just the type of the attribute. If you create a Foo instance, its bar method also has type instancemethod, even though it's a *bound* method: >>> foo = Foo() >>> foo <__main__.Foo object at 0x7ff2a16c> >>> foo.bar > >>> type(foo.bar) >>> Note that it's only when the method is looked up *from an instance of the class* does the interpreter create the bound method. And remember that this is behavior that's specific to Python 2. > >> The >> answer is : attribute lookup rules and the descriptor protocol. >> >> To make a long story short, the descriptor protocol specify that, when, >> during an attribute lookup, a name resolves to a class attribute AND >> this attribute has a __get__ method, then this __get__ method is called >> (with either the instance or None and the class itself as arguments) > > Depending, I assume, on whether this is instance call | class method > call, respectively? > Yes. > Hmm why does the __get__ receive class as argument on top of instance | > None? After all, when having an instance, the class can always be found > by instance.__class__ ? Is this for sake of class methods? > When Bruno wrote "... AND this attribute has a __get__ method ...", the __get__method has to be defined on the attribute's class - the interpreter won't even look at the instance when trying to resolve the reference. But inheritance, of course, means that the same __get__ method may be used by several classes, and when there is no instance the specific (sub)class in question must be identifiable. So you got that right. > Python is science, I gather: an answer to one question bears another 10 > questions. > Yes, but it isn't quite "turtles all the way down". Ultimately the behavior we are discussing is hard-wired into the interpreter at the __getattribute__ level. >> and whatever it returns becomes the result of the attribute lookup. This >> mechanism is what provides support for computed attributes. >> >> Now the trick is that the function type do implement the descriptor >> protocol. So when a function is an attribute of a class object and you >> try to access it as an attribute of either the class itself or an >> instance of the class, it's __get__ method is called with the instance >> (or None) and the class. > >> Having access to itself (of course), > > Quick question: how does a function access itself? Aside from rejected > PEP (http://www.python.org/dev/peps/pep-3130/) I don't see the way of > accessing itself outside globals() (and even then how would a function > know its name -- well it shouldn't care about it really, as function > object doesn't care how it's labelled, right?). Or does in "real Python" > func's __get__ receive its own function (func) as an argument, like in > your example implementation below? > The function is an object of type function, so the lookup triggers a call to the __get__() method of the function's class, providing the instance (that is the function that is being called) as the first argument. >> the >> instance (if there's one) and the class, it's easy for it to wrap all >> this into a method object. Which is itself a callable object, that when >> called mostly inject the instance as first object in the argument's list >> and returns the result of calling the wrapped function object. > > Aha! So that's the mechanism that makes self magically appear in an > argument list! I always wondered how it worked. !!THANKS!! > > >> My 2 cents... > > Well, Bruno -- that was more like $200! > I agree, this is stuff that's hard to understand, and Bruno's explanations are most helpful. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 08:34:37 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 14:34:37 +0100 Subject: Referring to class methods in class attributes In-Reply-To: References: <7a9c25c21002170959sad21930sa730977ea33b1b7a@mail.gmail.com> <4b7c54a8$0$21284$426a74cc@news.free.fr> Message-ID: <4b7d41e1$0$18857$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: >>> Thanks, that worked. But in order to make it work I had to get rid of >>> 'self' in print_internal_date signature >> >> Indeed. Using it that way, the print_internal_date will not be wrapped >> in a method object. > > Hold on! How does Python know what to wrap and what not to wrap, > assuming of course programmer doesn't use @classmethod or @staticmethod? answered below - read on, young padawan > Bc self has no special significance, it's just a (strong) convention, > Python can't know what's the first argument of a function supposed to > be, self or regular argument, and therefore it has no way of > differentiating between functions (defined in class body) designed to > become methods and those that are not? Indeed. > Where can I read on Python internals like this (aside from post of > yours, that is)? Bc frankly skimming http://docs.python.org/reference/ > didn't give me impression that a lot on the subject is there (well > there's some, I found smth akin to your explanation below, although > yours is way more readable)? Thanks > Thanks for explanation below -- I'm going to ask some related questions. > >> Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO >> beautifully) simple once you get it, but I agree it's a bit peculiar >> when compared to most mainstream OO languages. >> >> The first thing is that the def statement *always* yield a function >> object. Always. If you don't believe it, try the following snippet: >> >> class Foo(object): >> def bar(self): >> return "baaz" >> >> print Foo.__dict__.keys() >> print type(Foo.__dict__['bar']) > > Just one thing here: > > >>> Foo.bar > > > Huh?! Why does it say 'unbound' method? Shouldn't that be bound method > (bound to Foo, that is)? Yes, but it's not bound to a Foo instance. >> So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? > > >>> type(Foo.__dict__['bar']) > Yeps. That's the function object created by the def statement. Just a plain old function - expect it's an attribute of class object "Foo". > >>> type(Foo.bar) > > > instancemethod - now that's something new. Don't let the "" fools you - it's just instancemethod.__repr__ that issues different wording according to whether the instancemethod instance is bound or not. > >> The >> answer is : attribute lookup rules and the descriptor protocol. >> >> To make a long story short, the descriptor protocol specify that, when, >> during an attribute lookup, a name resolves to a class attribute AND >> this attribute has a __get__ method, then this __get__ method is called >> (with either the instance or None and the class itself as arguments) > > Depending, I assume, on whether this is instance call | class method > call, respectively? s/call/lookup/ If it's looked up on the class, there's no instance to pass to __get__. > > Hmm why does the __get__ receive class as argument on top of instance | > None? After all, when having an instance, the class can always be found > by instance.__class__ ? Is this for sake of class methods? Having access to the class is handy when you don't have the instance. The point is mostly to let the descriptor know how it has been looked up and take appropriate decisions based on this - for a definition of "appropriote" that depends on what the descriptor is intended for . Remember that this mechanism provides the generic support for all kind of computed attributes - methods, properties, and whatever you can write yourself. > Python is science, I gather: an answer to one question bears another 10 > questions. That's the case with most technical domains - until you solved enough of the puzzle to start and see the big picture. >> and whatever it returns becomes the result of the attribute lookup. This >> mechanism is what provides support for computed attributes. >> >> Now the trick is that the function type do implement the descriptor >> protocol. So when a function is an attribute of a class object and you >> try to access it as an attribute of either the class itself or an >> instance of the class, it's __get__ method is called with the instance >> (or None) and the class. > >> Having access to itself (of course), > > Quick question: how does a function access itself? In that case, it's quite simple: function.__get__ is a method of the function type, so it's called with 'self' as first argument !-) > Aside from rejected > PEP (http://www.python.org/dev/peps/pep-3130/) I don't see the way of > accessing itself outside globals() You're confusing the function instance itself with the content of the def statement's block. The code within the def statement's block has no access to the function instance that will be built from it, but other methods of the function instance are, well, ordinary methods. > (and even then how would a function > know its name -- well it shouldn't care about it really, as function > object doesn't care how it's labelled, right?). Or does in "real Python" > func's __get__ receive its own function (func) it receives itself, yes. Ordinary method call, nothing magical here - well, almost...!-). > as an argument, like in > your example implementation below? Exactly. >> the >> instance (if there's one) and the class, it's easy for it to wrap all >> this into a method object. Which is itself a callable object, that when >> called mostly inject the instance as first object in the argument's list >> and returns the result of calling the wrapped function object. > > Aha! So that's the mechanism that makes self magically appear in an > argument list! I always wondered how it worked. Now you know. As far as I'm concerned, I do find this whole mechanism to be a thing of beauty - instead of special-casing methods, you just use plain functions and the much more generic descriptor protocol to achieve the same result - with much more flexibility. > !!THANKS!! > >> My 2 cents... > > Well, Bruno -- that was more like $200! Ok, make it 3 cents then !-) More seriously, all this is explained in Raymond Hettinger's excellent 'descriptor howto' article, that is linked from the official doc - and that's how I learned all this. From philip at semanchuk.com Thu Feb 18 08:37:59 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Thu, 18 Feb 2010 08:37:59 -0500 Subject: Python 3.0 usage? In-Reply-To: References: Message-ID: <110AD9FE-D49F-4BD5-9643-7F3FA7C7C4DD@semanchuk.com> On Feb 18, 2010, at 12:20 AM, alex23 wrote: > MRAB wrote: >> Python 3.0 had a relatively short run before it was superseded by >> Python >> 3.1 due to certain issues, so, IMHO, I wouldn't worry about it unless >> someone especially requests/requires it. > > And even then, I'd just tell them I accept patches :) Excellent idea. =) Thanks to all who replied. Cheers Philip From ptmcg at austin.rr.com Thu Feb 18 08:39:21 2010 From: ptmcg at austin.rr.com (Paul McGuire) Date: Thu, 18 Feb 2010 05:39:21 -0800 (PST) Subject: How to efficiently extract information from structured text file References: <0f783ced-0414-4b44-acf1-79f8d288f41c@z10g2000prh.googlegroups.com> Message-ID: On Feb 17, 7:38?pm, Steven D'Aprano wrote: > On Wed, 17 Feb 2010 17:13:23 -0800, Jonathan Gardner wrote: > > And once you realize that every program is really a compiler, then you > > have truly mastered the Zen of Programming in Any Programming Language > > That Will Ever Exist. > > In the same way that every tool is really a screwdriver. > > -- > Steven The way I learned this was: - Use the right tool for the right job. - Every tool is a hammer. -- Paul From mrkafk at gmail.com Thu Feb 18 08:40:36 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 14:40:36 +0100 Subject: Static method In-Reply-To: <4b7d39cb$0$23451$426a74cc@news.free.fr> References: <4b7d2a78$0$21465$426a74cc@news.free.fr> <4b7d39cb$0$23451$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: >>> >>> >>> class Foo4(object): >>> """ working solution 2 : use a lambda """ >>> @staticmethod >>> def bar(baaz): >>> print baaz >>> >>> tagada = {'bar': lambda x : Foo4.bar(x)} >>> >>> def test(self, baaz): >>> self.tagada['bar'](baaz) >> >> Huh? How does this one work? After all, while in Foo4 body, the Foo4 >> does not exist yet? Does lambda defer evaluation to runtime (when it's >> executed) or smth? > > or smth, yes !-) > > A lambda expression evals to an ordinary function - just like a def > statement - so Foo4 is not resolved until Foo4.tagada['bar'] is actually > called. This works, but... Foo4.bar in tagada is a staticmethod. So what's needed is Foo4.bar.__get__(x) (not that I'm that smart, I just got 'staticmethod is not callable' exception). It appears I have to use __get__ anyway while referring to bar in Foo4 methods: def testrefer(self, val): self.bar.__get__(val) Foo4.bar.__get__(val) At least I have to do this in my own code: def testit(self, fname): self.print_internal_date.__get__(fname + 'c') PYFileInfo.print_internal_date.__get__(fname + 'c') Or else I get "TypeError: 'staticmethod' object is not callable". From victorsubervi at gmail.com Thu Feb 18 08:56:44 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Thu, 18 Feb 2010 09:56:44 -0400 Subject: Timer In-Reply-To: <7a9c25c21002171037s49568919te9840a9dabd37f29@mail.gmail.com> References: <4dc0cfea1002171014g68d1904aw17eadd6acf74ef05@mail.gmail.com> <7a9c25c21002171037s49568919te9840a9dabd37f29@mail.gmail.com> Message-ID: <4dc0cfea1002180556g7987b6a7rb6282ae3e21ec061@mail.gmail.com> On Wed, Feb 17, 2010 at 2:37 PM, Stephen Hansen wrote: > On Wed, Feb 17, 2010 at 10:14 AM, Victor Subervi wrote: > >> Obviously, the removeCSS isn't going to work in that last line. What can I >> put there to remove the splash page after 5 seconds? >> > > Even though you're generating this with python, it doesn't have anything to > do with Python. You'll have to use javascript and DHTML and enable/disable > classes. How to do that is beyond the scope of this group, and might depend > on the browser. I'd go look into jQuery or some such which will encapsulate > such dynamic things better. > OK. Thanks. beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Thu Feb 18 09:15:20 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 06:15:20 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> Message-ID: <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> On Feb 18, 1:23?am, Duncan Booth wrote: > Jonathan Gardner wrote: > > On Feb 17, 12:02?am, Lawrence D'Oliveiro > central.gen.new_zealand> wrote: > >> In message > >> <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, > > >> Jonathan Gardner wrote: > >> > I used to think anonymous functions (AKA blocks, etc...) would be a > >> > nice feature for Python. > > >> > Then I looked at a stack trace from a different programming > >> > language with lots of anonymous functions. (I believe it was perl.) > > >> Didn?t it have source line numbers in it? > > >> What more do you need? > > > I don't know, but I tend to find the name of the function I called to > > be useful. It's much more memorable than line numbers, particularly > > when line numbers keep changing. > > > I doubt it's just me, though. > > Some problems with using just line numbers to track errors: > > In any language it isn't much use if you get a bug report from a shipped > program that says there was an error on line 793 but no report of > exactly which version of the shipped code was being run. > > Microsoft love telling you the line number: if IE gets a Javascript > error it reports line number but not filename, so you have to guess > which of the HTML page or one of many included files actually had the > error. Plus the line number that is reported is often slightly off. > > Javascript in particular is often sent to the browser compressed then > uncompressed and eval'd. That makes line numbers completely useless for > tracking down bugs as you'll always get the line number of the eval. > Also the way functions are defined in Javascript means you'll often have > almost every function listed in a backtrace as 'Anonymous'. If this is an argument against using anonymous functions, then it is a quadruple strawman. Shipping buggy code is a bad idea, even with named functions. Obscuring line numbers is a bad idea, even with named functions. Having your customers stay on older versions of your software is a bad idea, even with named functions. Not being able to know which version of software you're customer is running is a bad idea, even with named functions. Of course, using anonymous functions in no way prevents you from capturing a version number in a traceback. And in most modern source control systems, it is fairly easy to revert to an old version of that code. def factory(): return lambda: 15 / 0 def bar(method): method() def foo(method): bar(method) def baz(method): foo(method) try: baz(factory()) except: print 'problem with version 1.234a' raise problem with version 1.234a Traceback (most recent call last): File "foo.py", line 14, in baz(factory()) File "foo.py", line 11, in baz foo(method) File "foo.py", line 8, in foo bar(method) File "foo.py", line 5, in bar method() File "foo.py", line 2, in return lambda: 15 / 0 ZeroDivisionError: integer division or modulo by zero From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 09:23:27 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 15:23:27 +0100 Subject: Static method In-Reply-To: References: <4b7d2a78$0$21465$426a74cc@news.free.fr> <4b7d39cb$0$23451$426a74cc@news.free.fr> Message-ID: <4b7d4d52$0$9152$426a74cc@news.free.fr> mk a ?crit : > Bruno Desthuilliers wrote: > >>>> >>>> >>>> class Foo4(object): >>>> """ working solution 2 : use a lambda """ >>>> @staticmethod >>>> def bar(baaz): >>>> print baaz >>>> >>>> tagada = {'bar': lambda x : Foo4.bar(x)} >>>> >>>> def test(self, baaz): >>>> self.tagada['bar'](baaz) >>> >>> Huh? How does this one work? After all, while in Foo4 body, the Foo4 >>> does not exist yet? Does lambda defer evaluation to runtime (when >>> it's executed) or smth? >> >> or smth, yes !-) >> >> A lambda expression evals to an ordinary function - just like a def >> statement - so Foo4 is not resolved until Foo4.tagada['bar'] is >> actually called. > > This works, but... Foo4.bar in tagada is a staticmethod. So what's > needed is Foo4.bar.__get__(x) (not that I'm that smart, I just got > 'staticmethod is not callable' exception). Huh ??? class Foo4(object): @staticmethod def bar(baaz): print baaz tagada = {'bar': lambda x : Foo4.bar(x)} def test(self, baaz): self.tagada['bar'](baaz) >>> f = Foo4() >>> f.test(42) 42 >>> Foo4.bar(42) 42 >>> WorksForMe(tm). > It appears I have to use __get__ anyway while referring to bar in Foo4 > methods: > > def testrefer(self, val): > self.bar.__get__(val) > Foo4.bar.__get__(val) > > At least I have to do this in my own code: > > def testit(self, fname): > self.print_internal_date.__get__(fname + 'c') > PYFileInfo.print_internal_date.__get__(fname + 'c') > > > Or else I get "TypeError: 'staticmethod' object is not callable". I think you broke something somewhere. Assuming you're using Python 2.x (>= 2.3 IIRC), my above code works. From commander_coder at hotmail.com Thu Feb 18 09:37:27 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 06:37:27 -0800 (PST) Subject: unit testing a routine that sends mail Message-ID: Hello, I have a routine that sends an email (this is how a Django view notifies me that an event has happened). I want to unit test that routine. So I gave each mail a unique subject line and I want to use python's mailbox package to look for that subject. But sometimes the mail gets delivered and sometimes it does not (I use sendmail to send it but I believe that it is always sent since I can see an entry in the mail log). I thought that the mail delivery system was occasionally hitting my mailbox lock, and that I needed to first sleep for a while. So I wrote a test that sleeps, then grabs the mailbox and looks through it, and if the mail is not there then it sleeps again, etc., for up to ten tries. It is below. However, I find that if the mail is not delivered on the first try then it is never delivered, no matter how long I wait. So I think I am doing mailbox wrong but I don't see how. The real puzzler for me is that the test reliably fails every third time. For instance, if I try it six times then it succeeds the first, second, fourth, and fifth times. I have to say that I cannot understand this at all but it certainly makes the unit test useless. I'm using Python 2.6 on an Ubuntu system. If anyone could give me a pointer to why the mail is not delivered, I sure could use it. Thanks, Jim ................................................................... class sendEmail_test(unittest.TestCase): """Test sendEmail() """ config = ConfigParser.ConfigParser() config.read(CONFIG_FN) mailbox_fn=config.get('testing','mailbox') def look_in_mailbox(self,uniquifier='123456789'): """If the mailbox has a message whose subject line contains the given uniquifier then it returns that message and deletes it. Otherwise, returns None. """ sleep_time=10.0 # wait for message to be delivered? message_found=None i=0 while i<10 and not(message_found): time.sleep(sleep_time) m=mailbox.mbox(self.mailbox_fn) try: m.lock() except Exception, err: print "trouble locking the mailbox: "+str(err) try: for key,message in m.items(): subject=message['Subject'] or '' print "subject is ",subject if subject.find(uniquifier)>-1: print "+++found the message+++ i=",str(i) message_found=message m.remove(key) break m.flush() except Exception, err: print "trouble reading from the mailbox: "+str(err) m.unlock() try: m.unlock() except Exception, err: print "trouble unlocking the mailbox: "+str(err) try: m.close() except Exception, err: print "trouble closing the mailbox: "+str(err) del m i+=1 return message_found def test_mailbox(self): random.seed() uniquifier=str(int(random.getrandbits(20))) print "uniquifier is ",uniquifier # looks different every time to me rc=az_view.sendEmail(uniquifier=uniquifier) if rc: self.fail('rc is not None: '+str(rc)) found=self.look_in_mailbox(uniquifier) if not(found): self.fail('message not found') print "done" From pruebauno at latinmail.com Thu Feb 18 09:52:29 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 18 Feb 2010 06:52:29 -0800 (PST) Subject: string to list when the contents is a list References: Message-ID: <9fc69505-3224-4aa9-9357-2abb0af4abd2@c16g2000yqd.googlegroups.com> Wes James wrote: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. > > How can I do this? > > thx, > > -wes I am surprised nobody gave you the simple answer yet that may even work for your situation: b=a[2:-2].split("','") From roy at panix.com Thu Feb 18 09:55:31 2010 From: roy at panix.com (Roy Smith) Date: Thu, 18 Feb 2010 09:55:31 -0500 Subject: unit testing a routine that sends mail References: Message-ID: In article , commander_coder wrote: > The real puzzler for me is that the test reliably fails every third > time. For instance, if I try it six times then it succeeds the first, > second, fourth, and fifth times. I have to say that I cannot > understand this at all but it certainly makes the unit test useless. Just a wild guess here, but maybe there's some DNS server which round-robins three address records for some hostname you're using, one of which is bogus. I've seen that before, and this smells like the right symptoms. From python.list at tim.thechases.com Thu Feb 18 10:18:57 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Feb 2010 09:18:57 -0600 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> Message-ID: <4B7D5A61.7060203@tim.thechases.com> Wes James wrote: > I have been trying to create a list form a string. The string will be > a list (this is the contents will look like a list). i.e. "[]" or > "['a','b']" > > The "[]" is simple since I can just check if value == "[]" then return [] > > But with "['a','b']" I have tried and get: > > a="['a','b']" > > b=a[1:-1].split(',') > > returns > > [ " 'a' "," 'b' " ] > > when I want it to return ['a','b']. Just to add to the list of solutions I've seen, letting the built-in csv module do the heavy lifting: >>> s = "['a','b']" >>> import csv >>> no_brackets = s[1:-1] # s.strip(' \t[]') >>> c = csv.reader([no_brackets], quotechar="'") >>> c.next() ['a', 'b'] This also gives you a bit of control regarding how escaping is done, and other knobs & dials to twiddle if you need. Additionally, if you have more than one string to process coming from an iterable source (such as a file), you can just pass that iterator to csv.reader() instead of concocting a one-element list. -tkc From commander_coder at hotmail.com Thu Feb 18 10:25:20 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 07:25:20 -0800 (PST) Subject: unit testing a routine that sends mail References: Message-ID: <2f2546c5-f5be-4f1a-b70f-f8afd973ea65@m37g2000yqf.googlegroups.com> On Feb 18, 9:55 am, Roy Smith wrote: > Just a wild guess here, but maybe there's some DNS server which > round-robins three address records for some hostname you're using, one of > which is bogus. > > I've seen that before, and this smells like the right symptoms. Everything happens on my laptop, localhost, where I'm developing. I'm sorry; I wasn't sure how much information was too much (or too little) but I should have said that. Thank you. From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 18 10:27:16 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 18 Feb 2010 16:27:16 +0100 Subject: unit testing a routine that sends mail In-Reply-To: References: Message-ID: <4b7d5c47$0$9135$426a74cc@news.free.fr> commander_coder a ?crit : > Hello, > > I have a routine that sends an email (this is how a Django view > notifies me that an event has happened). I want to unit test that > routine. http://docs.djangoproject.com/en/dev/topics/email/#e-mail-backends Or if you're stuck with 1.x < 1.2a, you could just mock the send_mail function to test that your app does send the appropriate mail - which is what you really want to know. My 2 cents... From debatem1 at gmail.com Thu Feb 18 10:30:29 2010 From: debatem1 at gmail.com (geremy condra) Date: Thu, 18 Feb 2010 10:30:29 -0500 Subject: Python library for working with simple equations In-Reply-To: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> References: <41834591-9853-49d0-a430-158a14179c63@15g2000yqi.googlegroups.com> Message-ID: On Thu, Feb 18, 2010 at 4:09 AM, lallous wrote: > Hello > > Is there is any Python library that allow such things: > > Given a string expression as: x + 5 + x * (y + 2), any library that > can develop the equation for example. > Or if we say factor with "x" then it renders the expression with x * > ( rest of expression ). > There could be a functionality where when x,y are given then the > expression can be evaluated. > If there are two expressions, they can be added and the symbols > preserved. > > Does such a thing exist? > > Thanks, > Elias > -- > http://mail.python.org/mailman/listinfo/python-list > >From sage: >>> x = var('x') >>> g = x**2 + x >>> g(x=5) 30 >>> g.factor ... (x + 1)*x Geremy Condra From subhakolkata1234 at gmail.com Thu Feb 18 10:36:29 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Thu, 18 Feb 2010 07:36:29 -0800 (PST) Subject: Few questions on SOAP Message-ID: Dear Group, I was reading on SOA or Service Oriented Architecture for last few days and got some questions. As this is a room for the expert computer scientists, if you can help me solve my queries. As per I read and felt SOA is an architecture, which relies on few basic principles as, the system must be modular, the modules must be distributive, module interfaces must be clearly defined and documented, module that implements a service can be swapped out for another module that offers the same service and interface, service provider modules must be shareable. SOA is an architecture which is now a days governed like XML by W3C. The latest version is SOAP 1.2. SOA is implemented mainly in a client/server environment, where applications have the use of service, thus we can say it is a service- oriented architecture. It is a step towards cloud computing with its sister WSDL and BPM. If both client/server are following the SOA then they can communicate and exchange information without worrying for platform. SOAP is a software implementation of Python,.NET,J2EE based on this principle. SOAPPy is a Python implementation. My questions are: (i) Am I understanding correctly? (ii) Does SOAP has any standard architecture like UML other than the W3C one? (iii) Can I write short programs to check the SOAP using my personal computer as client as well as Server? (iv) Is SOAPpy fine? (v) What is the difference among SOAP, WSDL and BPM. (vi) As SOAP is for communication with a server if I pick a URL and start to communicate with Google/Yahoo would they allow? (vii) Can I design a web based robot/crawler with SOAP? Wishing you a Happy Day Ahead, Best Regards, Subhabrata. From sccolbert at gmail.com Thu Feb 18 10:44:00 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Feb 2010 10:44:00 -0500 Subject: How to use AWS/PAA nowadays? PyAWS / pyamazon outdated? In-Reply-To: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> References: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> Message-ID: <7f014ea61002180744v6faeec8dhd3110d03ab1c4a5a@mail.gmail.com> This one works for the product API. http://pypi.python.org/pypi/python-amazon-product-api/0.2.1 On Thu, Feb 18, 2010 at 5:09 AM, Snaky Love wrote: > Hi, > > is anybody aware of any updated and / or maintained library for > accessing AWS/PAA with Python? I found the dusty pyamazon and a > derivate of it, pyaws, but both of them do not seem to support request > signatures which must be used by August 15, 2009 to use the Amazon > Services, and generally seem to be a little bit outdated... > > Is there a better way doing signed requests to AWS/PAA nowadays? How > are you doing it? > > I found a good PHP Library here: http://getcloudfusion.com/docs - but > I would like to program stuff with python - is there anything pythonic > that is close to that? > > Thank you very much for your attention, > have a nice day, > Snaky > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Thu Feb 18 10:44:02 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 16:44:02 +0100 Subject: Static method In-Reply-To: <4b7d4d52$0$9152$426a74cc@news.free.fr> References: <4b7d2a78$0$21465$426a74cc@news.free.fr> <4b7d39cb$0$23451$426a74cc@news.free.fr> <4b7d4d52$0$9152$426a74cc@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > I think you broke something somewhere. Assuming you're using Python 2.x > (>= 2.3 IIRC), my above code works. ARGH! Forgot the "delayed staticmethod" line -- in effect I called staticmethod twice: @staticmethod def print_internal_date(filename): f = open(filename + 'c', "rb") data = f.read(8) mtime = struct.unpack(" I have a Python app which I converted to an EXE (all files separate; single EXE didn't work properly) via py2exe - I plan on distributing this and would like the ability to remotely upgrade the program (for example, via HTTP/HTTPS). Looks like it's not just the EXE that I will need need to replace (DLLs, the library.zip, etc.). What would be the best way to go about doing this? From duncan.booth at invalid.invalid Thu Feb 18 10:50:29 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 18 Feb 2010 15:50:29 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> Message-ID: Steve Howell wrote: > If this is an argument against using anonymous functions, then it is a > quadruple strawman. > > Shipping buggy code is a bad idea, even with named functions. I doubt very much whether I have ever shipped any bug-free code but even if it was fit for purpose when shipped it is quite possible that the software will interact badly with other software that did not exist at the time of shipping. > > Obscuring line numbers is a bad idea, even with named functions. In principle I agree, but where Javascript is concerned compressing the downloaded files is generally a pretty good idea and practicality beats purity. > > Having your customers stay on older versions of your software is a bad > idea, even with named functions. I think that's their decision, not mine. > > Not being able to know which version of software you're customer is > running is a bad idea, even with named functions. > I agree, but getting a complete coherent description out of a customer is not always an easy task. (I'm reading the word 'customer' here to include the case where there is no monetary relationship between the software author and the entity using it, but even when there is I think this still true.) -- Duncan Booth http://kupuguy.blogspot.com From commander_coder at hotmail.com Thu Feb 18 10:59:14 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 07:59:14 -0800 (PST) Subject: unit testing a routine that sends mail References: <4b7d5c47$0$9135$426a74cc@news.free.fr> Message-ID: <2163d143-e48c-4b07-b430-2ff9eedddc31@e1g2000yqh.googlegroups.com> On Feb 18, 10:27 am, Bruno Desthuilliers wrote: > you could just mock the send_mail > function to test that your app does send the appropriate mail - which is > what you really want to know. That's essentially what I think I am doing. I need to send a relatively complex email, multipart, with both a plain text and html versions of a message, and some attachments. I am worried that the email would fail to get out for some reason (say, attaching the html message fails), so I want to test it. I started out with a simple email, thinking to get unit tests working and then as I add stuff to the email I'd run the tests to see if it broke anything. I could mock the send_mail function by having it print to the screen "mail sent" or I could have a unit test that looked for the mail. I did the first, and it worked fine. I thought to do the second, starting with a unit test checking simply that the message got to the mailbox. But I am unable to check that, as described in the original message. Jim From commander_coder at hotmail.com Thu Feb 18 11:11:29 2010 From: commander_coder at hotmail.com (commander_coder) Date: Thu, 18 Feb 2010 08:11:29 -0800 (PST) Subject: unit testing a routine that sends mail References: <4b7d5c47$0$9135$426a74cc@news.free.fr> Message-ID: <019bb3f3-a1ec-4650-8977-cc9f12ccca53@x22g2000yqx.googlegroups.com> Bruno, I talked to someone who explained to me how what you said gives a way around my difficulty. Please ignore the other reply. I'll do what you said. Thank you; I appreciate your help. Jim From stefan_ml at behnel.de Thu Feb 18 11:12:25 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 18 Feb 2010 17:12:25 +0100 Subject: Few questions on SOAP In-Reply-To: References: Message-ID: <4b7d66e9$0$6574$9b4e6d93@newsspool3.arcor-online.net> joy99, 18.02.2010 16:36: > SOA is an architecture which is now a days governed like XML by W3C. > The latest version is SOAP 1.2. SOA has nothing to do with SOAP. SOAP is a (rather bloated) protocol for remote procedure calls. SOA is a system architecture, be it distributed or not. Stefan From showell30 at yahoo.com Thu Feb 18 11:15:46 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 08:15:46 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> Message-ID: <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> On Feb 18, 7:50?am, Duncan Booth wrote: > Steve Howell wrote: > > If this is an argument against using anonymous functions, then it is a > > quadruple strawman. > > > Shipping buggy code is a bad idea, even with named functions. > > I doubt very much whether I have ever shipped any bug-free code but > even if it was fit for purpose when shipped it is quite possible that the > software will interact badly with other software that did not exist at the > time of shipping. > > > > > Obscuring line numbers is a bad idea, even with named functions. > > In principle I agree, but where Javascript is concerned compressing the > downloaded files is generally a pretty good idea and practicality beats > purity. > > > > > Having your customers stay on older versions of your software is a bad > > idea, even with named functions. > > I think that's their decision, not mine. > > > > > Not being able to know which version of software you're customer is > > running is a bad idea, even with named functions. > mpr > I agree, but getting a complete coherent description out of a customer is > not always an easy task. (I'm reading the word 'customer' here to include > the case where there is no monetary relationship between the software > author and the entity using it, but even when there is I think this still > true.) > Just to be clear, I'm not saying it's unforgivable to occasionally ship software with bugs. It happens. Compressing Javascript is sometimes necessary, but I believe that often mangles named functions too. To the the extent that your customer is running old software and cannot always coherently describe tracebacks over a telephone, that problem can be solved in the software itself, assuming an Internet connection. The software can capture the traceback and report back to a server with the version number. So, much of the argument against anonymous functions presented so far is really orthogonal to whether functions are named or not. Circling back to the original topic, Ruby blocks, I think there is a misconception about how blocks are often used in Ruby. Usually Ruby blocks are inlined into a function and execute within that function. Example: def print_numbers() [1, 2, 3, 4, 5, 6].map { |n| [n * n, n * n * n] }.reject { |square, cube| square == 25 || cube == 64 }.map { |square, cube| cube }.each { |n| puts n raise 'problem here' } end print_numbers() The bug that I inserted into the "each" block gets reported in the traceback: foo.rb:10:in `print_numbers': problem here (RuntimeError) from foo.rb:2:in `each' from foo.rb:2:in `print_numbers' from foo.rb:14 (I do prefer Python tracebacks BTW, but that is again orthogonal to blocks vs. named functions.) The blocks of code in the above Ruby code are somewhat analogous to blocks of code in Python that happen within certain control structures, such as "if," "while," "with," etc. The extra expressiveness of Ruby comes from the fact that you can act on those blocks with your own method. Of course, there is always a tradeoff between expressiveness and simplicity. I know the person who gave the talk about Ruby vs. Python, and trust me, nine times out of ten, he prefers Python's simplicity to Ruby's expressiveness. But he likes blocks. I'm in the same boat. I use Python a lot, Ruby less so, but when I'm in Ruby-land, I actually enjoy the expressiveness of blocks. They're not particularly dangerous, and they allow you to express certain sequential operations tersely and sequentially. The contrived code below maps numbers to squares and cubes, then rejects a couple tuples, then maps back to cubes, then prints each of the cubes. def print_numbers() [1, 2, 3, 4, 5, 6].map { |n| [n * n, n * n * n] }.reject { |square, cube| square == 25 || cube == 64 }.map { |square, cube| cube }.each { |n| puts n } end IMHO there is no reason that I should have to name the content of each of those four blocks of code, nor should I have to introduce the "lambda" keyword. I don't have a less contrived example handy, but the techniques above apply often when you are filtering and massaging data. From anfedorov at gmail.com Thu Feb 18 11:19:02 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 18 Feb 2010 11:19:02 -0500 Subject: Constraints on __sub__, __eq__, etc. Message-ID: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> It seems intuitive to me that the magic methods for overriding the +, -, <, ==, >, etc. operators should have no sideffects on their operands. Also, that == should be commutative and transitive, that > and < should be transitive, and anti-commutative. Is this intuition written up in a PEP, or assumed to follow from the mathematical meanings? - Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.arnold at sas.com Thu Feb 18 11:20:44 2010 From: tim.arnold at sas.com (Tim Arnold) Date: Thu, 18 Feb 2010 11:20:44 -0500 Subject: best way to create a dict from string Message-ID: Hi, I've got some text to parse that looks like this text = ''' blah blah blah \Template[Name=RAD,LMRB=False,LMRG=True]{tables} ho dee ho ''' I want to extract the bit between the brackets and create a dictionary. Here's what I'm doing now: def options(text): d = dict() options = text[text.find('[')+1:text.find(']')] for k,v in [val.split('=') for val in options.split(',')]: d[k] = v return d if __name__ == '__main__': for line in text.split('\n'): if line.startswith('\\Template'): print options(line) is that the best way or maybe there's something simpler? The options will always be key=value format, comma separated. thanks, --TIm From apt.shansen at gmail.com Thu Feb 18 11:28:01 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 08:28:01 -0800 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> Message-ID: <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov wrote: > It seems intuitive to me that the magic methods for overriding the +, -, <, > ==, >, etc. operators should have no sideffects on their operands. Also, > that == should be commutative and transitive, that > and < should be > transitive, and anti-commutative. > > Is this intuition written up in a PEP, or assumed to follow from the > mathematical meanings? > It may be intuitive to you, but its not true, written down anywhere, nor assumed by the language, and the mathematical meaning of the operators doesn't matter to Python. Python purposefully does not enforce anything for these methods. Consider: >>> class Test(object): ... def __init__(self, v): ... self.v = v ... def __add__(self, other): ... self.v = self.v + other ... return "Ow!" ... >>> t = Test(5) >>> t + 2 'Ow!' >>> t.v 7 It not only alters an operand, but its not even returning a meaningful result. This can be abused, but is also useful for certain uses. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From anfedorov at gmail.com Thu Feb 18 11:32:17 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 18 Feb 2010 11:32:17 -0500 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> Message-ID: <7659cab31002180832w462287f8q9f7005180e770e91@mail.gmail.com> > > It may be intuitive to you, but its not true, written down anywhere, nor > assumed by the language, and the mathematical meaning of the operators > doesn't matter to Python. Python purposefully does not enforce anything for > these methods. Right, so neither is anything in PEP-8, but it's still considered "good practice". I'm running across examples like you gave (__sub__ having a side-effect on the left-hand operand) in some code, and am trying to find concrete justification for avoiding it. - Andrey On Thu, Feb 18, 2010 at 11:28 AM, Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov wrote: > >> It seems intuitive to me that the magic methods for overriding the +, -, >> <, ==, >, etc. operators should have no sideffects on their operands. Also, >> that == should be commutative and transitive, that > and < should be >> transitive, and anti-commutative. >> >> Is this intuition written up in a PEP, or assumed to follow from the >> mathematical meanings? >> > > It may be intuitive to you, but its not true, written down anywhere, nor > assumed by the language, and the mathematical meaning of the operators > doesn't matter to Python. Python purposefully does not enforce anything for > these methods. Consider: > > >>> class Test(object): > ... def __init__(self, v): > ... self.v = v > ... def __add__(self, other): > ... self.v = self.v + other > ... return "Ow!" > ... > >>> t = Test(5) > >>> t + 2 > 'Ow!' > >>> t.v > 7 > > It not only alters an operand, but its not even returning a meaningful > result. This can be abused, but is also useful for certain uses. > > --S > -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Feb 18 11:37:52 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 18 Feb 2010 11:37:52 -0500 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> Message-ID: On Thu, Feb 18, 2010 at 11:19 AM, Andrey Fedorov wrote: > It seems intuitive to me that the magic methods for overriding the +, -, <, > ==, >, etc. operators should have no sideffects on their operands. Also, > that == should be commutative and transitive, that > and < should be > transitive, and anti-commutative. > Is this intuition written up in a PEP, or assumed to follow from the > mathematical meanings? > - Andrey There are no assumptions about anything. You can do whatever you want when you implement the functions yourself. For the numeric types, they follow the intuitive meanings but that's not necessary for user defined types. Of course, your users will get very confused if a == b but b != a. Or if a == b and a != b at the same time. > -- > http://mail.python.org/mailman/listinfo/python-list > > From chyavana at gmail.com Thu Feb 18 11:38:10 2010 From: chyavana at gmail.com (R (Chandra) Chandrasekhar) Date: Fri, 19 Feb 2010 00:38:10 +0800 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: <4B7D6CF2.7010907@gmail.com> Arnaud Delobelle wrote: > Here is a very simple way to improve what you do, which won't require > you to change the way you work or to learn a new paradigm: > > Instead of testing your functions interactively, put your testing code > in a file, e.g. 'program_tests.py'. Your can then type > > python program_tests.py > > at the shell interactive prompt. To perform the tests again, just > re-execute that file. If your tests are divided into > different units, you can put these in functions: > > def test_frobz(): > #testing code for frobzation of klops > > def test_frizz(): > #testing code for frizzment of frobzied klops > > # etc.. > > So if you want to keep doing interactive tests, you can import > program_tests and call whichever testing functions you want. You may > even have arguments to those functions to test them with different > parameters. > > I know some people will point at more 'pro' ways of testing but this has > the merit of being very straightforward. Then when you move on to more > sophisticated techniques, I think you will understand better the > motivations behind them. It took me some time to cotton on to exactly what you were saying, but once I grasped it and tried it out, I found it very effective and time-saving. Thank you very much Arnaud. -- Chandra From robert.kern at gmail.com Thu Feb 18 11:39:53 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 10:39:53 -0600 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> Message-ID: On 2010-02-18 10:19 AM, Andrey Fedorov wrote: > It seems intuitive to me that the magic methods for overriding the +, -, > <, ==, >, etc. operators should have no sideffects on their operands. > Also, that == should be commutative and transitive, that > and < should > be transitive, and anti-commutative. > > Is this intuition written up in a PEP, or assumed to follow from the > mathematical meanings? Some of it is covered in the reference manual. E.g. http://docs.python.org/reference/datamodel.html#object.__lt__ -- 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 simon at brunningonline.net Thu Feb 18 11:55:19 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 18 Feb 2010 16:55:19 +0000 Subject: Is automatic reload of a module available in Python? In-Reply-To: References: Message-ID: <8c7f10c61002180855t359a7848xd9b85e724910e917@mail.gmail.com> 2010/2/17 Arnaud Delobelle : > I know some people will point at more 'pro' ways of testing but this has > the merit of being very straightforward. ?Then when you move on to more > sophisticated techniques, I think you will understand better the > motivations behind them. Oh, I don't know. I like to think I'm fairly "pro" when it comes to TDD, and this is exactly what I do - a unit test module run from the shell. -- Cheers, Simon B. From jeanmichel at sequans.com Thu Feb 18 11:58:54 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 18 Feb 2010 17:58:54 +0100 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7659cab31002180832w462287f8q9f7005180e770e91@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> <7659cab31002180832w462287f8q9f7005180e770e91@mail.gmail.com> Message-ID: <4B7D71CE.6060904@sequans.com> Andrey Fedorov wrote: > > It may be intuitive to you, but its not true, written down > anywhere, nor assumed by the language, and the mathematical > meaning of the operators doesn't matter to Python. Python > purposefully does not enforce anything for these methods. > > > Right, so neither is anything in PEP-8, but it's still considered > "good practice". I'm running across examples like you gave (__sub__ > having a side-effect on the left-hand operand) in some code, and am > trying to find concrete justification for avoiding it. > > - Andrey This is all about communication. Python allows you to call a cat a dog. You'll confuse everyone if you do so, but you can do it. If your '-' operator is doing something else than returning the sub result, it's your call, but do not expect people to get it easily. You'd better be good at writting the documentation :-) JM From mrkafk at gmail.com Thu Feb 18 12:28:44 2010 From: mrkafk at gmail.com (mk) Date: Thu, 18 Feb 2010 18:28:44 +0100 Subject: Why this doesn't work? Message-ID: Sorry to bother everyone again, but I have this problem bugging me: #!/usr/bin/python -i class Foo(object): def nostat(self,val): print val nostat.__orig_get__ = nostat.__get__ @staticmethod def nostatget(*args, **kwargs): print 'args:', args, 'kwargs:', kwargs nostat.__orig_get__(*args, **kwargs) nostat.__get__ = nostatget setattr(nostat,'__get__',nostatget) f = Foo() f.nostat('a') print f.nostat.__get__ is f.nostat.__orig_get__ This produces: a False I expected to see 'nostatget' output: nostat.__get__ = nostatget obviously failed to replace this function's __get__ method. The question is why? Isn't __get__ a normal attribute of a function nostat? This is made so much weirder that nostat.__get__ is no longer original __get__, so it looks like it should have been replaced, but if so, why nostatget doesn't get called? Regards, mk From simon at brunningonline.net Thu Feb 18 13:14:22 2010 From: simon at brunningonline.net (Simon Brunning) Date: Thu, 18 Feb 2010 18:14:22 +0000 Subject: Few questions on SOAP In-Reply-To: References: Message-ID: <8c7f10c61002181014s6da28c8t7012d751cb077f3d@mail.gmail.com> On 18 February 2010 15:36, joy99 wrote: > (iv) ? ?Is SOAPpy fine? AFAIK, SOAPpy is unsupported, and a bit on the stale side. Those poor souls forced to make SOAP calls with Python seem to be using Suds mostly these days,. -- Cheers, Simon B. From fetchinson at googlemail.com Thu Feb 18 13:16:06 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 19:16:06 +0100 Subject: What happened to pyjamas? Message-ID: Does anyone know what happened to pyjs.org ? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From breamoreboy at yahoo.co.uk Thu Feb 18 13:44:23 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Feb 2010 18:44:23 +0000 Subject: What happened to pyjamas? In-Reply-To: References: Message-ID: Daniel Fetchinson wrote: > Does anyone know what happened to pyjs.org ? > > Cheers, > Daniel > > According to google cache it was fine 13/02/2010 and it's down according to this. http://downforeveryoneorjustme.com/pyjs.org HTH. Mark Lawrence From sccolbert at gmail.com Thu Feb 18 13:44:40 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Feb 2010 13:44:40 -0500 Subject: What happened to pyjamas? In-Reply-To: References: Message-ID: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> it's working for me. On Thu, Feb 18, 2010 at 1:16 PM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > Does anyone know what happened to pyjs.org ? > > Cheers, > Daniel > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Thu Feb 18 13:47:08 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 18 Feb 2010 19:47:08 +0100 Subject: What happened to pyjamas? In-Reply-To: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: >> Does anyone know what happened to pyjs.org ? > > it's working for me. That's odd, it's unpingable for me from both Europe and the US, ping says unknown host. Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at bdurham.com Thu Feb 18 13:54:27 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 13:54:27 -0500 Subject: How secure are temp files created via tempfile.TemporaryFile()? Message-ID: <1266519267.4170.1360680003@webmail.messagingengine.com> I'm doing a code review of an application that occassionally writes blocks of secure data to temp files created with tempfile.TemporaryFile( delete=True ). How secure are temp files created via tempfile.TemporaryFile( delete=True )? Are there OS specific nuances I should be concerned about regarding use of this function on Windows (XP or higher) or Linux? Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Thu Feb 18 13:58:59 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Thu, 18 Feb 2010 13:58:59 -0500 Subject: What happened to pyjamas? In-Reply-To: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: <4B2D76D1-AE2A-47F0-A1D0-805CABA62150@gmail.com> Down from here (NH, US). S On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > From comptekki at gmail.com Thu Feb 18 14:32:59 2010 From: comptekki at gmail.com (Wes James) Date: Thu, 18 Feb 2010 12:32:59 -0700 Subject: string to list when the contents is a list In-Reply-To: <4B7D5A61.7060203@tim.thechases.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> Message-ID: <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase wrote: > Wes James wrote: > > Just to add to the list of solutions I've seen, letting the built-in csv > module do the heavy lifting: > > ?>>> s = "['a','b']" > ?>>> import csv > ?>>> no_brackets = s[1:-1] # s.strip(' \t[]') > ?>>> c = csv.reader([no_brackets], quotechar="'") > ?>>> c.next() > ?['a', 'b'] > > This also gives you a bit of control regarding how escaping is done, and > other knobs & dials to twiddle if you need. Additionally, if you have more > than one string to process coming from an iterable source (such as a file), > you can just pass that iterator to csv.reader() instead of concocting a > one-element list. Thx, I think this will work for what I want. -wes From python at mrabarnett.plus.com Thu Feb 18 14:33:11 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 18 Feb 2010 19:33:11 +0000 Subject: How secure are temp files created via tempfile.TemporaryFile()? In-Reply-To: <1266519267.4170.1360680003@webmail.messagingengine.com> References: <1266519267.4170.1360680003@webmail.messagingengine.com> Message-ID: <4B7D95F7.9020906@mrabarnett.plus.com> python at bdurham.com wrote: > I'm doing a code review of an application that occassionally writes > blocks of secure data to temp files created with tempfile.TemporaryFile( > delete=True ). > > How secure are temp files created via tempfile.TemporaryFile( delete=True )? > > Are there OS specific nuances I should be concerned about regarding use > of this function on Windows (XP or higher) or Linux? > Well, the contents of temp files aren't encrypted, if that's what you're asking, so if you're writing unencrypted data to a temp file then other applications could read it. From comptekki at gmail.com Thu Feb 18 14:56:16 2010 From: comptekki at gmail.com (Wes James) Date: Thu, 18 Feb 2010 12:56:16 -0700 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> Message-ID: <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> On Thu, Feb 18, 2010 at 12:32 PM, Wes James wrote: > On Thu, Feb 18, 2010 at 8:18 AM, Tim Chase > wrote: >> Wes James wrote: > > >> >> Just to add to the list of solutions I've seen, letting the built-in csv >> module do the heavy lifting: >> >> ?>>> s = "['a','b']" >> ?>>> import csv >> ?>>> no_brackets = s[1:-1] # s.strip(' \t[]') >> ?>>> c = csv.reader([no_brackets], quotechar="'") >> ?>>> c.next() >> ?['a', 'b'] Hmm. When I put csv.reader in a class: import csv class IS_LIST(): def __init__(self, format='', error_message='must be a list!'): self.format = format self.error_message = error_message def __call__(self, value): try: if value=='[]' or value=='': value=[] else: no_brackets = value[1:-1] # s.strip(' \t[]') c = csv.reader([no_brackets], quotechar="'") value=c.next() return (value, None) except: return (value, self.error_message) def formatter(self, value): return value I get an error (when I take the "try" out): AttributeError: 'function' object has no attribute 'reader' Why? -wes From nagle at animats.com Thu Feb 18 14:58:32 2010 From: nagle at animats.com (John Nagle) Date: Thu, 18 Feb 2010 11:58:32 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> Message-ID: <4b7d97dc$0$1587$742ec2ed@news.sonic.net> John Nagle wrote: > I look at this as Python's answer to multicore CPUs and "Go". On that note, I went to a talk at Stanford yesterday by one of the designers of Intel's Nelahem core. The four-core, eight thread version is out now. The six-core, twelve thread version is working; the speaker has one in his lab. The eight-core, sixteen thread version is some months away. This isn't an expensive CPU; this is Intel's "converged" mainstream product. (Although there will be a whole range of "economy" and "performance" versions, all with the same core but with some stuff turned off.) Python isn't ready for this. Not with the GIL. Multiple processes are not the answer. That means loading multiple copies of the same code into different areas of memory. The cache miss rate goes up accordingly. John Nagle From malkarouri at gmail.com Thu Feb 18 15:00:17 2010 From: malkarouri at gmail.com (Muhammad Alkarouri) Date: Thu, 18 Feb 2010 12:00:17 -0800 (PST) Subject: Few questions on SOAP References: Message-ID: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Your question is borderline if not out of topic in this group. I will make a few comments though. On Feb 18, 3:36?pm, joy99 wrote: > Dear Group, > > I was reading on SOA or Service Oriented Architecture for last few > days and got some questions. As this is a room for the expert computer > scientists, if you can help me solve my queries. > > As per I read and felt SOA is an architecture, which relies on few > basic principles as, > the system must be modular, the modules must be distributive, module > interfaces must be clearly defined and documented, module that > implements a service can be swapped out for another module that offers > the same service and interface, service provider modules must be > shareable. > SOA is an architecture which is now a days governed like XML by W3C. SOA is an architecture which can be implemented using any of a number of different middleware choices. It is not governed or controlled by anyone. You are mixing it up with SOAP, which is a web services technology, currently governed by W3C. For example, I tend to use SOA implemented using REST (Representational State Transfer). All of these technologies are somewhat explained in wikipedia. You probably want to start there. > The latest version is SOAP 1.2. This is the latest of SOAP, not SOA. > SOA is implemented mainly in a client/server environment, where > applications have the use of service, thus we can say it is a service- > oriented architecture. > It is a step towards cloud computing with its sister WSDL and BPM. A SOAP web service is described using WSDL. BPM is not really connected with them, but is probably more connected with SOA as an architecture. BPM can be implemented using SOAP/WSDL web services, as can SOA. > > If both client/server are following the SOA then they can communicate > and exchange information without worrying for platform. You mean SOAP here. In real life, there are interoperability issues. So various implementations of SOAP will need a bit of work to actually work together. SOA is an architecture and does not help exchanging information in a direct way. > > SOAP is a software implementation of Python,.NET,J2EE based on this > principle. SOAP is a web services protocol that was created before the concept of SOA was developed enough for use and is largely independent of it. SOAP has been implemented in many different languages, like Java, .Net, C/C++, Python, etc. > SOAPPy is a Python implementation. SOAP implementations in Python are not of the best quality (in my opinion, there are better ways to achieve the ends needed). SOAPpy is currently a bit out of date. The better ones are ZSI (for client and server) and suds (for clients). I guess I have already answered some of your questions. > > My questions are: > (i) ? ? Am I understanding correctly? See above. > (ii) ? ?Does SOAP has any standard architecture like UML other than the > W3C one? Depends on what you mean by architecture. SOAP is a standard. UML is a way of modelling software and can be used to model web services, which can then be implemented in SOAP. > (iii) ? Can I write short programs to check the SOAP using my personal > computer as client as well as Server? Yes. Try ZSI examples (http://pywebsvcs.sourceforge.net/zsi.html). > (iv) ? ?Is SOAPpy fine? See above. > (v) ? ? What is the difference among SOAP, WSDL and BPM. SOAP standardise the communication between client and server. WSDL describes the methods provided by a server to be consumed by a client (interfaces in Java language). BPM is a management method to improve business and is not a software protocol but an approach. > (vi) ? ?As SOAP is for communication with a server if I pick a URL and > start to communicate with Google/Yahoo would they allow? To be able to talk SOAP to a server, it must understand SOAP. Some of those companies do provide SOAP web service access, but their standard search pages are accessible in pure HTTP (the way you browser uses them). To access a SOAP service you need to know the functions exported by it, which are usually defined in a WSDL document. > (vii) ? Can I design a web based robot/crawler with SOAP? No. Web pages are accessed using simple HTTP. SOAP is usually deployed on top of HTTP, but most web pages are not communicated using SOAP. You can search for Python web crawling; there are a lot of examples on the web. Regards, k From python at bdurham.com Thu Feb 18 15:09:28 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 15:09:28 -0500 Subject: How secure are temp files created via tempfile.TemporaryFile()? In-Reply-To: <4B7D95F7.9020906@mrabarnett.plus.com> References: <1266519267.4170.1360680003@webmail.messagingengine.com> <4B7D95F7.9020906@mrabarnett.plus.com> Message-ID: <1266523768.19867.1360705413@webmail.messagingengine.com> MRAB, > Well, the contents of temp files aren't encrypted, if that's what you're asking I understand the contents of temp files aren't encrypted. > if you're writing unencrypted data to a temp file then other applications could read it. That's my concern - can other applications really read my temp files created with tempfile.TemporaryFile( delete=True )? I don't think so because: 1. These files appear to be exclusively locked by my process, eg. no other processes can read or write to these temp files except the process that created these files. 2. As soon as my process terminates (voluntarily or involuntarily), the temp file gets deleted. But I want to make sure. Thanks, Mal From python.list at tim.thechases.com Thu Feb 18 15:12:25 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 18 Feb 2010 14:12:25 -0600 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> Message-ID: <4B7D9F29.7070002@tim.thechases.com> > import csv > > class IS_LIST(): > def __init__(self, format='', error_message='must be a list!'): > self.format = format > self.error_message = error_message > def __call__(self, value): > try: > if value=='[]' or value=='': > value=[] > else: > no_brackets = value[1:-1] # s.strip(' \t[]') > c = csv.reader([no_brackets], quotechar="'") > value=c.next() > return (value, None) > except: > return (value, self.error_message) > def formatter(self, value): > return value > > I get an error (when I take the "try" out): > > AttributeError: 'function' object has no attribute 'reader' A couple ideas occur to me: 1) you haven't copy/pasted the exact (or entirety of the) code, and something you're doing is shadowing the "csv" module 2) are you using Python 2.x or 3.x? I don't know if the csv module has changed in 3.x but it should work in 2.x The first thing to check would be to pull up a raw python prompt and see if your csv module has the expected reader: >>> import csv >>> csv.reader If not, something likely changed in 3.x and you'd have to inspect the docs to see what happened to the reader. If you get the above evidence of an existing reader, then you're likely shadowing it. -tkc From phlip2005 at gmail.com Thu Feb 18 15:16:03 2010 From: phlip2005 at gmail.com (Phlip) Date: Thu, 18 Feb 2010 12:16:03 -0800 (PST) Subject: unit testing a routine that sends mail References: Message-ID: <7348214b-4bd1-4f41-984c-1893fb51afae@z1g2000prc.googlegroups.com> commander_coder wrote: > I have a routine that sends an email (this is how a Django view > notifies me that an event has happened). ?I want to unit test that > routine. Are you opening SMTP and POP3 sockets?? If you are not developing that layer itself, just use Django's built- in mock system. Here's my favorite assertion for it: def assert_mail(self, funk): from django.core import mail previous_mails = len(mail.outbox) funk() mails = mail.outbox[ previous_mails : ] assert [] != mails, 'the called block should produce emails' if len(mails) == 1: return mails[0] return mails You call it a little bit like this: missive = self.assert_mail( lambda: mark_order_as_shipped(order) ) Then you can use assert_contains on the missive.body, to see what mail got generated. That's what you are actually developing, so your tests should skip any irrelevant layers, and only test the layers where you yourself might add bugs. -- Phlip http://penbird.tumblr.com/ From daniele.gondoni at gmail.com Thu Feb 18 15:21:16 2010 From: daniele.gondoni at gmail.com (Daniele Gondoni) Date: Thu, 18 Feb 2010 12:21:16 -0800 (PST) Subject: What happened to pyjamas? References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: On 18 Feb, 19:58, "sstein... at gmail.com" wrote: > Down from here (NH, US). > > S > > On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > > > Unreacheable from Italy as well... From sccolbert at gmail.com Thu Feb 18 15:26:58 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 18 Feb 2010 15:26:58 -0500 Subject: What happened to pyjamas? In-Reply-To: <4B2D76D1-AE2A-47F0-A1D0-805CABA62150@gmail.com> References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> <4B2D76D1-AE2A-47F0-A1D0-805CABA62150@gmail.com> Message-ID: <7f014ea61002181226o6f8c1e20u2d525c86ac96c59f@mail.gmail.com> ah, yep, i was viewing the page chrome had cached. It's down for me too. I lose the trace in Washington: 3 G3-0-873.TAMPFL-LCR-08.verizon-gni.net (130.81.110.222) 14.399 ms 17.917 ms 18.040 ms 4 so-6-1-0-0.TPA01-BB-RTR2.verizon-gni.net (130.81.29.242) 18.666 ms 18.890 ms 19.232 ms 5 ge-1-0-0-0.ATL01-BB-RTR2.verizon-gni.net (130.81.17.48) 36.460 ms 38.546 ms 38.707 ms 6 0.so-2-2-0.XT2.ATL5.ALTER.NET (152.63.86.73) 41.357 ms 33.709 ms 35.851 ms 7 * 0.so-7-0-0.XT2.ATL4.ALTER.NET (152.63.86.109) 34.522 ms 37.320 ms 8 0.xe-10-1-0.BR3.ATL4.ALTER.NET (152.63.82.13) 37.558 ms 32.756 ms 35.533 ms 9 xe-11-2-0.edge4.Atlanta2.Level3.net (4.68.62.17) 37.715 ms 100.222 ms 102.317 ms 10 ae-71-52.ebr1.Atlanta2.Level3.net (4.68.103.60) 40.227 ms 34.315 ms 36.647 ms 11 ae-73-70.ebr3.Atlanta2.Level3.net (4.69.138.20) 42.695 ms 39.589 ms 41.666 ms 12 ae-2-2.ebr1.Washington1.Level3.net (4.69.132.86) 52.152 ms 54.256 ms 54.540 ms 13 ae-61-61.csw1.Washington1.Level3.net (4.69.134.130) 61.982 ms 62.316 ms 62.460 ms 14 ae-14-69.car4.Washington1.Level3.net (4.68.17.6) 55.660 ms 55.645 ms 56.943 ms 15 CO-LOCATION.car4.Washington1.Level3.net (4.79.170.254) 59.423 ms 58.914 ms 50.872 ms 16 * * * 17 * * * 18 * * * 19 * * * 20 * * * 21 * * * 22 * * * 23 * * * 24 * * * 25 * * * 26 * * * 27 * * * 28 * * * 29 * * * 30 * * * On Thu, Feb 18, 2010 at 1:58 PM, ssteinerX at gmail.com wrote: > Down from here (NH, US). > > S > > > On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at bdurham.com Thu Feb 18 15:32:12 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 15:32:12 -0500 Subject: Why do full path names to module show up multiple times in .PYC files? Message-ID: <1266525132.23323.1360707279@webmail.messagingengine.com> I just happened to look at a compiled Python 2.6.4 .PYC file in an editor and noticed that the full path and file name of the compiled module showed up in my .PYC file at least 10 different times. Is there a reason for full vs. relative path names and why does the module name need to be duplicated so many times? It appears that .PYO files only use a filename (without a path). I assume the only way for us to suppress path names (which may have confidential client names) in our compiled distributions is to use .PYO vs. .PYC files? Is this correct? Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From benjamin.kaplan at case.edu Thu Feb 18 15:33:14 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Thu, 18 Feb 2010 15:33:14 -0500 Subject: string to list when the contents is a list In-Reply-To: <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> <533df7fa1002181156l4055b8d0u7eeacecc0194aba1@mail.gmail.com> Message-ID: On Thu, Feb 18, 2010 at 2:56 PM, Wes James wrote: > > I get an error (when I take the "try" out): > > AttributeError: 'function' object has no attribute 'reader' > You have a function called "csv" that's defined after the import csv statement is executed. That function has no attribute 'reader", so you get the error. By the way, don't use a bare except- it's bad form because it hides any other problems you have. From luismgz at gmail.com Thu Feb 18 15:45:05 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Thu, 18 Feb 2010 12:45:05 -0800 (PST) Subject: What happened to pyjamas? References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: On Feb 18, 5:21?pm, Daniele Gondoni wrote: > On 18 Feb, 19:58, "sstein... at gmail.com" wrote: > > > Down from here (NH, US). > > > S > > > On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > Unreacheable from Italy as well... Same here (Buenos Aires, Argentina). From irmen at -NOSPAM-xs4all.nl Thu Feb 18 15:53:32 2010 From: irmen at -NOSPAM-xs4all.nl (Irmen de Jong) Date: Thu, 18 Feb 2010 21:53:32 +0100 Subject: What happened to pyjamas? In-Reply-To: References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> Message-ID: <4b7da919$0$22938$e4fe514c@news.xs4all.nl> On 2/18/10 9:45 PM, Luis M. Gonz?lez wrote: > On Feb 18, 5:21 pm, Daniele Gondoni wrote: >> On 18 Feb, 19:58, "sstein... at gmail.com" wrote: >> >>> Down from here (NH, US). >> >>> S >> >>> On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: >> >> Unreacheable from Italy as well... > > Same here (Buenos Aires, Argentina). It ain't down till Netcraft confirms it! http://uptime.netcraft.com/up/graph?site=www.pyjs.org Oh wait... -irmen From CORY.L.NARDIN at saic.com Thu Feb 18 16:00:19 2010 From: CORY.L.NARDIN at saic.com (Nardin, Cory L.) Date: Thu, 18 Feb 2010 13:00:19 -0800 Subject: Python won't run Message-ID: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> Quickly, I have a Mac Intel with Windows XP installed. Tried installing Python 2.6.4 from the binary and also ActivePython 2.6.4.10. Both installations acted the same. There seemed to be no problems during installation (used default options), but when I try to run Python I get an error message: "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem." Of course I searched on that error and it seems to be related to a MS library. In a few different places it was recommended to install the MS Visual Studio redistributable package, which I did with no change in outcome. I really have no idea what to do. Any help is appreciated. Thanks, Cory -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Thu Feb 18 16:07:21 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 18 Feb 2010 21:07:21 +0000 Subject: Few questions on SOAP In-Reply-To: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: Muhammad Alkarouri wrote: > Your question is borderline if not out of topic in this group. I will > make a few comments though. This might be a Python group, but threads often drift way off topic, which added to the language itself make this a great group to read. If you don't like the way a thread goes, you can always skip it. > > On Feb 18, 3:36 pm, joy99 wrote: >> Dear Group, >> >> I was reading on SOA or Service Oriented Architecture for last few >> days and got some questions. As this is a room for the expert computer >> scientists, if you can help me solve my queries. >> >> As per I read and felt SOA is an architecture, which relies on few >> basic principles as, >> the system must be modular, the modules must be distributive, module >> interfaces must be clearly defined and documented, module that >> implements a service can be swapped out for another module that offers >> the same service and interface, service provider modules must be >> shareable. >> SOA is an architecture which is now a days governed like XML by W3C. > > SOA is an architecture which can be implemented using any of a number > of different middleware choices. It is not governed or controlled by > anyone. You are mixing it up with SOAP, which is a web services > technology, currently governed by W3C. > For example, I tend to use SOA implemented using REST > (Representational State Transfer). > > All of these technologies are somewhat explained in wikipedia. You > probably want to start there. > >> The latest version is SOAP 1.2. > > This is the latest of SOAP, not SOA. > >> SOA is implemented mainly in a client/server environment, where >> applications have the use of service, thus we can say it is a service- >> oriented architecture. >> It is a step towards cloud computing with its sister WSDL and BPM. > > A SOAP web service is described using WSDL. BPM is not really > connected with them, but is probably more connected with SOA as an > architecture. BPM can be implemented using SOAP/WSDL web services, as > can SOA. > >> If both client/server are following the SOA then they can communicate >> and exchange information without worrying for platform. > > You mean SOAP here. > In real life, there are interoperability issues. So various > implementations of SOAP will need a bit of work to actually work > together. > > SOA is an architecture and does not help exchanging information in a > direct way. > >> SOAP is a software implementation of Python,.NET,J2EE based on this >> principle. > > SOAP is a web services protocol that was created before the concept of > SOA was developed enough for use and is largely independent of it. > SOAP has been implemented in many different languages, like > Java, .Net, C/C++, Python, etc. > >> SOAPPy is a Python implementation. > > SOAP implementations in Python are not of the best quality (in my > opinion, there are better ways to achieve the ends needed). SOAPpy is > currently a bit out of date. The better ones are ZSI (for client and > server) and suds (for clients). > > I guess I have already answered some of your questions. > >> My questions are: >> (i) Am I understanding correctly? > > See above. > >> (ii) Does SOAP has any standard architecture like UML other than the >> W3C one? > > Depends on what you mean by architecture. SOAP is a standard. UML is a > way of modelling software and can be used to model web services, which > can then be implemented in SOAP. > >> (iii) Can I write short programs to check the SOAP using my personal >> computer as client as well as Server? > > Yes. Try ZSI examples (http://pywebsvcs.sourceforge.net/zsi.html). > >> (iv) Is SOAPpy fine? > > See above. > >> (v) What is the difference among SOAP, WSDL and BPM. > > SOAP standardise the communication between client and server. WSDL > describes the methods provided by a server to be consumed by a client > (interfaces in Java language). BPM is a management method to improve > business and is not a software protocol but an approach. > >> (vi) As SOAP is for communication with a server if I pick a URL and >> start to communicate with Google/Yahoo would they allow? > > To be able to talk SOAP to a server, it must understand SOAP. Some of > those companies do provide SOAP web service access, but their standard > search pages are accessible in pure HTTP (the way you browser uses > them). > To access a SOAP service you need to know the functions exported by > it, which are usually defined in a WSDL document. > >> (vii) Can I design a web based robot/crawler with SOAP? > > No. Web pages are accessed using simple HTTP. SOAP is usually deployed > on top of HTTP, but most web pages are not communicated using SOAP. > You can search for Python web crawling; there are a lot of examples on > the web. > > > Regards, > > k From dick128 at verizon.net Thu Feb 18 16:11:54 2010 From: dick128 at verizon.net (dick bly) Date: Thu, 18 Feb 2010 15:11:54 -0600 (Central Standard Time) Subject: Win32print apache mod_python vista Message-ID: <4B7DAD19.00000C.07308@LAPTOP2> I have a program that uses mod_python in Apache and does a win32print using the default printer This works fine under win xp but the configuration under vista raises and error - no default printer found - Its the same code, same Apache, same mod_python, same python - only difference is vista so I am assuming vista is trying to be my friend by not giving me access to the printers - can any help with this ? Richard Bly cell 817 996 6458 dick128 at verizon.net -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: stampa_girl_line_en.gif Type: image/gif Size: 46417 bytes Desc: not available URL: From aahz at pythoncraft.com Thu Feb 18 16:18:51 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Feb 2010 13:18:51 -0800 Subject: string to list when the contents is a list References: <533df7fa1002171548r7e797641o5262fe402ba5ce31@mail.gmail.com> <4B7D5A61.7060203@tim.thechases.com> <533df7fa1002181132x64626794n7675e6083baf5b73@mail.gmail.com> Message-ID: In article , Wes James wrote: > > try: > if value=3D=3D'[]' or value=3D=3D'': > value=3D[] > else: > no_brackets =3D value[1:-1] # s.strip(' \t[]') > c =3D csv.reader([no_brackets], quotechar=3D"'") > value=3Dc.next() > return (value, None) > except: > return (value, self.error_message) Two important points: * Don't use bare except: clauses * Put less code in the try: clause to make it easier to track down problems -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From ethan at stoneleaf.us Thu Feb 18 16:19:16 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 18 Feb 2010 13:19:16 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7d97dc$0$1587$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <4B7DAED4.3010500@stoneleaf.us> John Nagle wrote: > John Nagle wrote: > >> I look at this as Python's answer to multicore CPUs and "Go". > > On that note, I went to a talk at Stanford yesterday by one of the > designers of Intel's Nelahem core. The four-core, eight thread > version is out now. The six-core, twelve thread version is working; > the speaker has one in his lab. The eight-core, sixteen thread version > is some months away. This isn't an expensive CPU; this is Intel's > "converged" mainstream product. (Although there will be a whole range > of "economy" and "performance" versions, all with the same core but > with some stuff turned off.) > > Python isn't ready for this. Not with the GIL. > > Multiple processes are not the answer. That means loading multiple > copies of the same code into different areas of memory. The cache > miss rate goes up accordingly. > > John Nagle Will the new GIL in 3.2 make this workable? It would still be one thread at a time, though, wouldn't it. ~Ethan~ From ntwrkd at gmail.com Thu Feb 18 16:34:46 2010 From: ntwrkd at gmail.com (ntwrkd) Date: Thu, 18 Feb 2010 13:34:46 -0800 Subject: LISA 2010 CFP Message-ID: Hello All, The USENIX Large Installation System Administration Conference is now accepting paper proposals. If you are interested in submitting a paper, please check out this blog post about submitting a paper (http://www.usenix.org/events/lisa10/cfp/), or feel free to contact me directly if you think you might have a topic to present. Thank you, Matthew From aahz at pythoncraft.com Thu Feb 18 16:40:42 2010 From: aahz at pythoncraft.com (Aahz) Date: 18 Feb 2010 13:40:42 -0800 Subject: Executing a command from within python using the subprocess module References: <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d@westnet.com.au> Message-ID: In article <5YudnaFysO8HouTWnZ2dnUVZ_tidnZ2d at westnet.com.au>, R (Chandra) Chandrasekhar wrote: > >--- >import subprocess > >width = 5 >height = 30 >colors = ['#abcdef]', '#456789'] >filename = "/tmp/image.png" > ># I want to get the equivalent of variable interpolation in Perl ># so that the command ># ># convert -size 5x30 gradient:#abcdef-#456789 /tmp/image.png Here's the equivalent of Peter's cute code in simpler form: cmd = [ 'convert', '-size', '%sx%s' % (width, height), 'gradient:%s-%s' % tuple(colors), # above could also be: 'gradient:%s-%s' % (colors[0], colors[1]), filename, ] subprocess.Popen(cmd) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 17:07:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 22:07:27 GMT Subject: Why this doesn't work? References: Message-ID: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: > nostat.__orig_get__ = nostat.__get__ I should point out that leading-and-trailing-double-underscore names are reserved for use by the language. It's unlikely that Python will introduce a special method named __orig_get__, and in truth the prohibition against using such names is honoured more in the breach than in the observance (e.g. people often use metadata names like __version__, __author__, etc.). But just be aware that you are in technical breach of Python best practices, and should consider renaming it as _orig_get or __orig_get. -- Steven From clp2 at rebertia.com Thu Feb 18 17:11:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 18 Feb 2010 14:11:24 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7d97dc$0$1587$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <50697b2c1002181411r1a1c8eb9h5c244d54213dd848@mail.gmail.com> On Thu, Feb 18, 2010 at 11:58 AM, John Nagle wrote: > ? On that note, I went to a talk at Stanford yesterday by one of the > designers of Intel's Nelahem core. ?The four-core, eight thread > version is out now. ?The six-core, twelve thread version is working; > the speaker has one in his lab. ?The eight-core, sixteen thread version > is some months away. ?This isn't an expensive CPU; this is Intel's > "converged" mainstream product. ?(Although there will be a whole range > of "economy" and "performance" versions, all with the same core but > with some stuff turned off.) > > ? Python isn't ready for this. ?Not with the GIL. Is any language, save perhaps Erlang, really ready for it? Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 17:12:02 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 22:12:02 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <4b7dbb31$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 11:58:32 -0800, John Nagle wrote: > John Nagle wrote: > >> I look at this as Python's answer to multicore CPUs and "Go". > > On that note, I went to a talk at Stanford yesterday by one of the > designers of Intel's Nelahem core. The four-core, eight thread version > is out now. [...] > > Python isn't ready for this. Not with the GIL. Pardon me, but Python is perfectly ready for this. Why aren't you using Jython or IronPython, if the GIL is such a drag on your use-case? -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 17:17:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 22:17:57 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> Message-ID: <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 06:15:20 -0800, Steve Howell wrote: > On Feb 18, 1:23?am, Duncan Booth wrote: >> Jonathan Gardner wrote: >> > On Feb 17, 12:02?am, Lawrence D'Oliveiro > > central.gen.new_zealand> wrote: >> >> In message >> >> <8ca440b2-6094-4b35-80c5-81d000517... at v20g2000prb.googlegroups.com>, >> >> >> Jonathan Gardner wrote: >> >> > I used to think anonymous functions (AKA blocks, etc...) would be >> >> > a nice feature for Python. >> >> >> > Then I looked at a stack trace from a different programming >> >> > language with lots of anonymous functions. (I believe it was >> >> > perl.) >> >> >> Didn?t it have source line numbers in it? >> >> >> What more do you need? >> >> > I don't know, but I tend to find the name of the function I called to >> > be useful. It's much more memorable than line numbers, particularly >> > when line numbers keep changing. >> >> > I doubt it's just me, though. >> >> Some problems with using just line numbers to track errors: >> >> In any language it isn't much use if you get a bug report from a >> shipped program that says there was an error on line 793 but no report >> of exactly which version of the shipped code was being run. >> >> Microsoft love telling you the line number: if IE gets a Javascript >> error it reports line number but not filename, so you have to guess >> which of the HTML page or one of many included files actually had the >> error. Plus the line number that is reported is often slightly off. >> >> Javascript in particular is often sent to the browser compressed then >> uncompressed and eval'd. That makes line numbers completely useless for >> tracking down bugs as you'll always get the line number of the eval. >> Also the way functions are defined in Javascript means you'll often >> have almost every function listed in a backtrace as 'Anonymous'. > > If this is an argument against using anonymous functions, then it is a > quadruple strawman. There really ought to be a special level of Hell for people who misuse "strawman" to mean "a weak or invalid argument" instead of what it actually means, which is a weak or invalid argument NOT HELD by your opponent, which you (generic you) made up specifically for the sake of shooting down. If you actually read what Duncan says, he prefixes his response with: "Some problems with using just line numbers to track errors". Duncan's post is an argument against relying on line numbers as your main, or only, source of information about the location of bugs in Javascript. In fact, this post is remarkable for the sheer number of actual strawman arguments that you (Steve Howell) use: > Shipping buggy code is a bad idea, even with named functions. Strawman #1: nobody said that shipping buggy code was a good idea, with or without named functions. But shipping buggy code *happens*, no matter how careful you are, so you need to expect bug reports back from users. (And they will be *hard to find* bugs, because if they were easy to find you would have found them in your own testing before shipping.) > Obscuring line numbers is a bad idea, even with named functions. Strawman #2: nobody said that obscuring line numbers was a good idea. But apparently compressing Javascript is valuable for other reasons, and obscuring the line numbers is the side-effect of doing so. And even knowing the line numbers is not necessarily useful, because many bugs aren't due to the line that raises the stack trace. Just because you know the line which failed doesn't mean you know how to fix the bug. > Having your customers stay on older versions of your software is a bad > idea, even with named functions. Strawman #3: nobody said that staying on older versions is a good idea. But sometimes it happens whether you like it or not. (Although I'd like to point out that from the end user's perspective, sometimes we don't want your stinkin' new version with all the anti- features and pessimations and will stick to the old version for as long as possible. If you don't like it, then think a bit harder before adding anti-features like fragile, easily-corrupted databases which perform really, really badly when your home directory is mounted over the network. I'm talking to you, Firefox developers.) And it doesn't really matter: you either end-of-life the old version, in which case you don't need to do anything about the bug report except say "upgrade", or you decide to continue support, in which case it doesn't matter whether the bug is reported for an old version or the latest version, you still need to fix it. > Not being able to know which version of software you're customer is > running is a bad idea, even with named functions. Strawman #4. See the pattern? When you attack a position the other guy hasn't taken, that's a strawman. When you make a weak argument, it's just a weak argument. -- Steven From apt.shansen at gmail.com Thu Feb 18 17:25:12 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 14:25:12 -0800 Subject: How to make an empty generator? Message-ID: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> This has to be a stupid question, but :) I have some generators that do stuff, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really "generators" because I want to call them /as/ a generator as part of a generalized system. The only way I can figure out how to make an empty generator is: def gen(): # do my one-time processing here return yield Is there a better way? The return/yield just makes me flinch slightly. I tried just raising StopIteration at the end, but of course that didn't work. TIA, --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Thu Feb 18 17:26:33 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 14:26:33 -0800 (PST) Subject: Help with lambda References: Message-ID: <39ded391-c814-4c17-936f-3a4f55c3d9ec@b9g2000pri.googlegroups.com> On Feb 18, 4:28?am, lallous wrote: > > f = [lambda x: x ** n for n in xrange(2, 5)] This is (pretty much) what the above code does. >>> f = [] >>> n = 2 >>> f.append(lambda x: x**n) >>> n = 3 >>> f.append(lambda x: x**n) >>> n = 4 >>> f.append(lambda x: x**n) >>> n = 5 >>> f.append(lambda x: x**n) Now, when you call f[0], you are calling "lambda x: x**n". What is "n"? You need some way of creating a new namespace and a new variable pointing to what "n" was for that iteration. Python doesn't create a namespace for every iteration like some languages may. You have to be more explicit about that. After all, what would you expect the following code to do? >>> n = 5 >>> f = [lambda x: x**n for i in range(2,5)] >>> n = 2 >>> f[0][5] Or, just call a function that will have a new namespace *for every call* and generate a function within each execution of that function (like make_power does). From brendon.wickham at gmail.com Thu Feb 18 17:44:17 2010 From: brendon.wickham at gmail.com (Brendon Wickham) Date: Fri, 19 Feb 2010 09:44:17 +1100 Subject: Few questions on SOAP In-Reply-To: References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: On 19 February 2010 08:07, Mark Lawrence wrote: > Muhammad Alkarouri wrote: >> >> Your question is borderline if not out of topic in this group. I will >> make a few comments though. > > This might be a Python group, but threads often drift way off topic, which > added to the language itself make this a great group to read. ?If you don't > like the way a thread goes, you can always skip it. Perhaps...but he answered the question very well and with great, IMO, patience. From jgardner at jonathangardner.net Thu Feb 18 17:49:38 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 14:49:38 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: On Feb 18, 8:15?am, Steve Howell wrote: > > ? ? def print_numbers() > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > ? ? ? ? ? ? [n * n, n * n * n] > ? ? ? ? }.reject { |square, cube| > ? ? ? ? ? ? square == 25 || cube == 64 > ? ? ? ? }.map { |square, cube| > ? ? ? ? ? ? cube > ? ? ? ? }.each { |n| > ? ? ? ? ? ? puts n > ? ? ? ? } > ? ? end > If this style of programming were useful, we would all be writing Lisp today. As it turned out, Lisp is incredibly difficult to read and understand, even for experienced Lispers. I am pleased that Python is not following Lisp in that regard. for n in range(1,6): square = n*n cube = n*n*n if square == 25 or cube == 64: continue print cube From robert.kern at gmail.com Thu Feb 18 17:56:09 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 16:56:09 -0600 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: On 2010-02-18 16:25 PM, Stephen Hansen wrote: > This has to be a stupid question, but :) > > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only really > "generators" because I want to call them /as/ a generator as part of a > generalized system. > > The only way I can figure out how to make an empty generator is: > > def gen(): > # do my one-time processing here > > return > yield > > Is there a better way? The return/yield just makes me flinch slightly. I > tried just raising StopIteration at the end, but of course that didn't work. class once(object): def __init__(self, func, *args, **kwds): self.func = func self.args = args self.kwds = kwds def __iter__(self): return self def next(self): self.func(*self.args, **self.kwds) raise StopIteration() Then write regular functions with the one-time processing code (not generators!). When you go to pass them into your system that wants an iterator, just wrap it with once(func). -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 18:00:51 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 23:00:51 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <4b7dc6a2$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 08:15:46 -0800, Steve Howell wrote: > Just to be clear, I'm not saying it's unforgivable to occasionally ship > software with bugs. It happens. "Occasionally"? Oh, if only. I would say that there probably isn't a non-trivial application in the world that is entirely bug-free. If you're shipping something more complex than the proverbial "Hello World", chances are high that there will be bugs, and the more complex the app, the more bugs are likely. > Compressing Javascript is sometimes necessary, but I believe that often > mangles named functions too. It doesn't mangle the function, it mangles reporting of line numbers. But if you know the name of the function, it is much easier to recover from that loss of information. > To the the extent that your customer is running old software and cannot > always coherently describe tracebacks over a telephone, that problem can > be solved in the software itself, assuming an Internet connection. The > software can capture the traceback and report back to a server with the > version number. I don't understand why you repeatedly mention "old software". It is irrelevant: the software is either supported, or not supported. If it's not supported, you don't care about the bugs. If it is supported, then it doesn't matter whether it is version 2.2 or 2.3 or the bleeding edge 2.4- pre-alpha straight out of subversion, you still have to go through the same process of finding the bug, solving it, then rolling the fix out to all supported versions where the bug applies. That's not to say that the version number isn't useful information to have, because it can be, but distinguishing between old versions and the current version isn't a useful distinction. In a sense, there are no old versions, there are merely multiple supported current versions. > So, much of the argument against anonymous functions presented so far is > really orthogonal to whether functions are named or not. Not so. The point is that anonymous functions lack useful information, namely the function name. Because line numbers can be unreliable or even missing completely, and even when reliable many people have a mental blind-spot for them (I know I do, and I'm gratified to see I'm not the only one), lacking a good name for the function is a handicap. Not necessarily an insurmountable one, but anonymous functions are more troublesome than named functions. You wouldn't name your functions: f01, f02, f03, f04, ... f99 (say), unless you were trying to deliberately obfuscate your code. Anonymous functions are even more obfuscated than that. You can get away with it so long as you're only dealing with a few, in well-defined placed, but you wouldn't want to use them all over the place. -- Steven From sjdevnull at yahoo.com Thu Feb 18 18:04:28 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 18 Feb 2010 15:04:28 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> On Feb 18, 11:15?am, Steve Howell wrote: > ? ? def print_numbers() > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > ? ? ? ? ? ? [n * n, n * n * n] > ? ? ? ? }.reject { |square, cube| > ? ? ? ? ? ? square == 25 || cube == 64 > ? ? ? ? }.map { |square, cube| > ? ? ? ? ? ? cube > ? ? ? ? }.each { |n| > ? ? ? ? ? ? puts n > ? ? ? ? } > ? ? end > > IMHO there is no reason that I should have to name the content of each > of those four blocks of code, nor should I have to introduce the > "lambda" keyword. You could do it without intermediate names or lambdas in Python as: def print_numbers(): for i in [ cube for (square, cube) in [(n*n, n*n*n) for n in [1,2,3,4,5,6]] if square!=25 and cube!=64 ]: print i But frankly, although there's no reason that you _have_ to name the content at each step, I find it a lot more readable if you do: def print_numbers(): tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] filtered = [ cube for (square, cube) in tuples if square!=25 and cube!=64 ] for f in filtered: print f From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 18:08:32 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 18 Feb 2010 23:08:32 GMT Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: <4b7dc870$0$8819$c3e8da3@news.astraweb.com> Sorry for breaking the threading, but Stephen's original post hasn't come through to my provider. On 2010-02-18 16:25 PM, Stephen Hansen wrote: > This has to be a stupid question, but :) > > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only > really "generators" because I want to call them /as/ a generator as > part of a generalized system. > > The only way I can figure out how to make an empty generator is: > > def gen(): > # do my one-time processing here > > return > yield If all you want is a generator that doesn't yield anything, then surely there isn't any one-time processing and you don't need the comment? >> Is there a better way? The return/yield just makes me flinch slightly. Meh. An empty generator is a funny thing to do, so it's not bad that it reads a bit funny. I don't have a problem with it. If it really annoys you, you could do this: def empty(): for x in []: yield -- Steven From robert.kern at gmail.com Thu Feb 18 18:30:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 17:30:54 -0600 Subject: How to make an empty generator? Message-ID: On Feb 18, 5:08 pm, Steven D'Aprano wrote: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > > This has to be a stupid question, but :) > > > I have some generators that do stuff, then start yielding results. On > > occasion, I don't want them to yield anything ever-- they're only > > really "generators" because I want to call them /as/ a generator as > > part of a generalized system. > > > The only way I can figure out how to make an empty generator is: > > > def gen(): > > # do my one-time processing here > > > return > > yield > > If all you want is a generator that doesn't yield anything, then surely > there isn't any one-time processing and you don't need the comment? Sure there is. Python doesn't know that nothing gets yielded until it hits the return statement before the yield. When it calls .next() on the iterator, the code elided by the comment executes, then the return is hit, a StopIteration exception is raised, and the iteration is complete. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From ben+python at benfinney.id.au Thu Feb 18 18:33:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 10:33:00 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: <877hqaazmb.fsf@benfinney.id.au> Robert Kern writes: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > The only way I can figure out how to make an empty generator is: > > > > def gen(): > > # do my one-time processing here > > > > return > > yield > > > > Is there a better way? The return/yield just makes me flinch > > slightly. I tried just raising StopIteration at the end, but of > > course that didn't work. No need to define functions or classes; let a generator expression take care of it for you:: >>> foo = (x for x in list()) >>> foo.next() Traceback (most recent call last): File "", line 1, in StopIteration -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard Stallman, 2002 | Ben Finney From contact at xavierho.com Thu Feb 18 18:35:02 2010 From: contact at xavierho.com (Xavier Ho) Date: Fri, 19 Feb 2010 09:35:02 +1000 Subject: How to make an empty generator? In-Reply-To: References: Message-ID: <2d56febf1002181535h782e8f41l9e50a87dd7360d36@mail.gmail.com> I don't think it's a stupid question at all. =]. But wouldn't it solve the problem if you call the generator the first time you need it to yield? Cheers, Xav On Fri, Feb 19, 2010 at 9:30 AM, Robert Kern wrote: > On Feb 18, 5:08 pm, Steven D'Aprano > wrote: > > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > > > > This has to be a stupid question, but :) > > > > > I have some generators that do stuff, then start yielding results. On > > > occasion, I don't want them to yield anything ever-- they're only > > > really "generators" because I want to call them /as/ a generator as > > > part of a generalized system. > > > > > The only way I can figure out how to make an empty generator is: > > > > > def gen(): > > > # do my one-time processing here > > > > > return > > > yield > > > > If all you want is a generator that doesn't yield anything, then surely > > there isn't any one-time processing and you don't need the comment? > > Sure there is. Python doesn't know that nothing gets yielded until it hits > the return statement before the yield. When it calls .next() on the > iterator, the code elided by the comment executes, then the return is hit, a > StopIteration exception is raised, and the iteration is complete. > > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though it > had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Feb 18 18:36:02 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 15:36:02 -0800 Subject: How to make an empty generator? In-Reply-To: References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern wrote: > class once(object): > def __init__(self, func, *args, **kwds): > self.func = func > self.args = args > self.kwds = kwds > > def __iter__(self): > return self > > def next(self): > self.func(*self.args, **self.kwds) > raise StopIteration() > Hmm, yeah. I'd probably tweak it into a decorator and name it sideeffect_only or something, but yeah, that's the right approach at least. My motivation is clarity, I can just see a colleague a year from now asking me, "... what the hell is return / yield?" and although this is more expensive, its less clear to me. Thanks. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Feb 18 18:37:09 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 15:37:09 -0800 Subject: How to make an empty generator? In-Reply-To: <4b7dc870$0$8819$c3e8da3@news.astraweb.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <4b7dc870$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002181537o441a4383s64656730c2dd5264@mail.gmail.com> On Thu, Feb 18, 2010 at 3:08 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On 2010-02-18 16:25 PM, Stephen Hansen wrote: > > The only way I can figure out how to make an empty generator is: > > > > def gen(): > > # do my one-time processing here > > > > return > > yield > > If all you want is a generator that doesn't yield anything, then surely > there isn't any one-time processing and you don't need the comment? > Its possible I didn't explain myself well. I don't want a generator that does /nothing at all/, but a generator that yields nothing. Basically, I have a core system that loads up a bunch of modules dynamically. The API of these modules is that their initialization function is a generator that yields objects that the core system juggles. For the majority of the cases, this is just fine. A couple modules though, just really need to do a one-time action, and everything's done. I /could/ change the initialization function to return a generator, and not be a generator itself, and check if its None or not, etc. But I don't really want to, as I like the API the way it is. So really, the above generator looks like: def initialize(): os.environ["BLAH"] = 5 return yield In that its doing a single side-effect action and that's it. > >> Is there a better way? The return/yield just makes me flinch slightly. > > Meh. An empty generator is a funny thing to do, so it's not bad that it > reads a bit funny. I don't have a problem with it. > It doesn't -really- annoy me, it just makes me flinch slightly, and that's very rare. Even the stranger things to do in Python rarely make me flinch. So I was wondering if I missed something basically, and if there's a proper way to do it. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From apt.shansen at gmail.com Thu Feb 18 18:40:01 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Thu, 18 Feb 2010 15:40:01 -0800 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> Message-ID: <7a9c25c21002181540x7ac9bc33uf112609b9e47ef02@mail.gmail.com> On Thu, Feb 18, 2010 at 3:36 PM, Stephen Hansen wrote: > My motivation is clarity, I can just see a colleague a year from now asking > me, "... what the hell is return / yield?" and although this is more > expensive, its less clear to me. > MORE clear to me. A class / decorator / whatever may be more expensive then return / yield, but it reads better and is more clear, to me. Not less. Ahem. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Thu Feb 18 18:47:18 2010 From: john at castleamber.com (John Bokma) Date: Thu, 18 Feb 2010 17:47:18 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <878waqw1h5.fsf@castleamber.com> Jonathan Gardner writes: > On Feb 18, 8:15?am, Steve Howell wrote: >> >> ? ? def print_numbers() >> ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| >> ? ? ? ? ? ? [n * n, n * n * n] >> ? ? ? ? }.reject { |square, cube| >> ? ? ? ? ? ? square == 25 || cube == 64 >> ? ? ? ? }.map { |square, cube| >> ? ? ? ? ? ? cube >> ? ? ? ? }.each { |n| >> ? ? ? ? ? ? puts n >> ? ? ? ? } >> ? ? end >> > > If this style of programming were useful, we would all be writing Lisp > today. As it turned out, Lisp is incredibly difficult to read and > understand, even for experienced Lispers. I am pleased that Python is > not following Lisp in that regard. > > for n in range(1,6): ^ should be 7 But for the rest, I agree with you. I can read Steve's version, but even to an experienced Perl programmer that looks quite noisy :-) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From arnodel at googlemail.com Thu Feb 18 18:49:08 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 18 Feb 2010 15:49:08 -0800 (PST) Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> Message-ID: <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> On 18 Feb, 23:33, Ben Finney wrote: [...] > No need to define functions or classes; let a generator expression take > care of it for you:: > > ? ? >>> foo = (x for x in list()) > ? ? >>> foo.next() > ? ? Traceback (most recent call last): > ? ? ? File "", line 1, in > ? ? StopIteration What about foo = iter('') Then there is the interesting foo = iter(int, 0) :) -- Arnaud From john at castleamber.com Thu Feb 18 18:50:29 2010 From: john at castleamber.com (John Bokma) Date: Thu, 18 Feb 2010 17:50:29 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <878waqw1h5.fsf@castleamber.com> Message-ID: <874olew1bu.fsf@castleamber.com> John Bokma writes: > Jonathan Gardner writes: > >> On Feb 18, 8:15?am, Steve Howell wrote: >>> >>> ? ? def print_numbers() >>> ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| >>> ? ? ? ? ? ? [n * n, n * n * n] >>> ? ? ? ? }.reject { |square, cube| >>> ? ? ? ? ? ? square == 25 || cube == 64 >>> ? ? ? ? }.map { |square, cube| >>> ? ? ? ? ? ? cube >>> ? ? ? ? }.each { |n| >>> ? ? ? ? ? ? puts n >>> ? ? ? ? } >>> ? ? end >>> >> >> If this style of programming were useful, we would all be writing Lisp >> today. As it turned out, Lisp is incredibly difficult to read and >> understand, even for experienced Lispers. I am pleased that Python is >> not following Lisp in that regard. >> >> for n in range(1,6): > > ^ should be 7 > > But for the rest, I agree with you. I can read Steve's version, but even > to an experienced Perl programmer that looks quite noisy :-) Oh, wait, it's Ruby :-D. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From jjposner at optimum.net Thu Feb 18 18:57:10 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 18 Feb 2010 18:57:10 -0500 Subject: Why this doesn't work? In-Reply-To: References: Message-ID: <4B7DD3D6.9030403@optimum.net> On 2/18/2010 12:28 PM, mk wrote: > > Sorry to bother everyone again, but I have this problem bugging me: > > #!/usr/bin/python -i > > class Foo(object): > > def nostat(self,val): > print val > > nostat.__orig_get__ = nostat.__get__ > > @staticmethod > def nostatget(*args, **kwargs): > print 'args:', args, 'kwargs:', kwargs > nostat.__orig_get__(*args, **kwargs) > > nostat.__get__ = nostatget > setattr(nostat,'__get__',nostatget) > > > f = Foo() > > f.nostat('a') > > print f.nostat.__get__ is f.nostat.__orig_get__ > > > This produces: > > a > False > > I expected to see 'nostatget' output: nostat.__get__ = nostatget > obviously failed to replace this function's __get__ method. I don't quite understand the above sentence, so I'm assuming that you wanted the final "is" test to be "True" instead of "False". It looks like you've replaced ... (A) the original __get__() method ... with ... (B) a new method that *calls* the original __get__() method So why should you expect (A) and (B) to be the same object? > > The question is why? Isn't __get__ a normal attribute of a function nostat? > > This is made so much weirder that nostat.__get__ is no longer original > __get__, so it looks like it should have been replaced, but if so, why > nostatget doesn't get called? > > Regards, > mk > > > -John From tjreedy at udel.edu Thu Feb 18 19:08:25 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Feb 2010 19:08:25 -0500 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> Message-ID: On 2/18/2010 5:25 PM, Stephen Hansen wrote: > This has to be a stupid question, but :) > > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only really > "generators" because I want to call them /as/ a generator as part of a > generalized system. > > The only way I can figure out how to make an empty generator is: > > def gen(): > # do my one-time processing here > > return > yield > > Is there a better way? The return/yield just makes me flinch slightly. I > tried just raising StopIteration at the end, but of course that didn't work. Did you try def gen(): if 0: yield ? tjr From wolftracks at invalid.com Thu Feb 18 19:10:31 2010 From: wolftracks at invalid.com (W. eWatson) Date: Thu, 18 Feb 2010 16:10:31 -0800 Subject: [Tutor] "Sounding" Off, IDLE (Win7) Message-ID: In Win7 IDLE, when I type in something with a syntax problem, a bell rings. How do I stop that? I've looked at Control Panel Sounds, but don't see anything of apparent use. From robert.kern at gmail.com Thu Feb 18 19:12:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 18:12:10 -0600 Subject: How to make an empty generator? In-Reply-To: <877hqaazmb.fsf@benfinney.id.au> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> Message-ID: On 2010-02-18 17:33 PM, Ben Finney wrote: > Robert Kern writes: > >> On 2010-02-18 16:25 PM, Stephen Hansen wrote: >>> The only way I can figure out how to make an empty generator is: >>> >>> def gen(): >>> # do my one-time processing here >>> >>> return >>> yield >>> >>> Is there a better way? The return/yield just makes me flinch >>> slightly. I tried just raising StopIteration at the end, but of >>> course that didn't work. > > No need to define functions or classes; let a generator expression take > care of it for you:: > > >>> foo = (x for x in list()) > >>> foo.next() > Traceback (most recent call last): > File "", line 1, in > StopIteration He doesn't want *any* empty generator. He wants an iterator that executes some given side-effect-producing code then immediately raises the StopIteration. -- 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 rhodri at wildebst.demon.co.uk Thu Feb 18 19:12:10 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Feb 2010 00:12:10 -0000 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: On Thu, 18 Feb 2010 22:11:24 -0000, Chris Rebert wrote: > On Thu, Feb 18, 2010 at 11:58 AM, John Nagle wrote: > >> On that note, I went to a talk at Stanford yesterday by one of the >> designers of Intel's Nelahem core. The four-core, eight thread >> version is out now. The six-core, twelve thread version is working; >> the speaker has one in his lab. The eight-core, sixteen thread version >> is some months away. This isn't an expensive CPU; this is Intel's >> "converged" mainstream product. (Although there will be a whole range >> of "economy" and "performance" versions, all with the same core but >> with some stuff turned off.) >> >> Python isn't ready for this. Not with the GIL. > > Is any language, save perhaps Erlang, really ready for it? occam :-) -- Rhodri James *-* Wildebeeste Herder to the Masses From ryan at rfk.id.au Thu Feb 18 19:19:32 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Fri, 19 Feb 2010 11:19:32 +1100 Subject: Upgrading Py2exe App In-Reply-To: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: <1266538772.3062.12.camel@rambutan> On Thu, 2010-02-18 at 07:46 -0800, T wrote: > I have a Python app which I converted to an EXE (all files separate; > single EXE didn't work properly) via py2exe - I plan on distributing > this and would like the ability to remotely upgrade the program (for > example, via HTTP/HTTPS). Looks like it's not just the EXE that I > will need need to replace (DLLs, the library.zip, etc.). What would > be the best way to go about doing this? I've been working on an auto-update framework for my own frozen apps, you might find it useful: http://pypi.python.org/pypi/esky Docs are a little scarce at the moment, the next release will hopefully come with a short tutorial (as well as support for cx_freeze and maybe py2app, depending on how adventurous I'm feeling). 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From robert.kern at gmail.com Thu Feb 18 19:20:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 18 Feb 2010 18:20:49 -0600 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> Message-ID: On 2010-02-18 17:36 PM, Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern > wrote: > > class once(object): > def __init__(self, func, *args, **kwds): > self.func = func > self.args = args > self.kwds = kwds > > def __iter__(self): > return self > > def next(self): > self.func(*self.args, **self.kwds) > raise StopIteration() > > > Hmm, yeah. I'd probably tweak it into a decorator and name it > sideeffect_only or something, but yeah, that's the right approach at least. Well, with a decorator, you could even use the cringeworthy return/yield syntax while keeping it hidden from your users (not to mention reducing the amount of boilerplate people need to write). from functools import wraps def sideeffect_only(func): @wraps(func) def wrapper(*args, **kwds): func(*args, **kwds) # Some helpful comment about why there is a return/yield. return yield return wrapper But you can also write one where the wrapper() returns a once() instance. It might be useful to use the once class instead of a generator such that you can write code that distinguishes side-effect only iterators from other iterators in your system. It might be useful for debugging if nothing else. -- 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 rhodri at wildebst.demon.co.uk Thu Feb 18 19:26:59 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Feb 2010 00:26:59 -0000 Subject: string to list when the contents is a list References: <9fc69505-3224-4aa9-9357-2abb0af4abd2@c16g2000yqd.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 14:52:29 -0000, nn wrote: > Wes James wrote: >> I have been trying to create a list form a string. The string will be >> a list (this is the contents will look like a list). i.e. "[]" or >> "['a','b']" >> >> The "[]" is simple since I can just check if value == "[]" then return >> [] >> >> But with "['a','b']" I have tried and get: >> >> a="['a','b']" >> >> b=a[1:-1].split(',') >> >> returns >> >> [ " 'a' "," 'b' " ] >> >> when I want it to return ['a','b']. >> >> How can I do this? >> >> thx, >> >> -wes > > > I am surprised nobody gave you the simple answer yet that may even > work for your situation: > > b=a[2:-2].split("','") Because it's really *very* not robust. "Harmless" whitespace defeats it for starters, and that's one of the most likely things to vary between example data and reality. If you trust your data to be well-formed enough for this to work, you might as well use eval() instead. If you don't, parsing is the only sensible answer. -- Rhodri James *-* Wildebeeste Herder to the Masses From anfedorov at gmail.com Thu Feb 18 19:30:40 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Thu, 18 Feb 2010 19:30:40 -0500 Subject: Bypassing properties on an object (also with __slots__?) Message-ID: <7659cab31002181630j7e7ebdbdw1110b859a587d568@mail.gmail.com> Two questions: 1 - is it documented that o.__dict__[attr] is a reliable way to bypass property methods? 2 - can one bypass a property method if the class has __slots__? Reason: I have a couple of different flavors of request objects which I need to make lazily conform to a standard interface. As a simplified example, a_foo_request = { 'ip': '1.2.3.4' } a_bar_request = { 'my-ip': b'\x01\x02\x03\x04' } My solution is to create two classes: class FooRequest(dict): @property def ip(self): return self['ip'] class BarRequest(dict): @property def ip(self): return "%i.%i.%i.%i" % struct.unpack("4B", self['my-ip']) Then: FooRequest(a_foo_request).ip == '1.2.3.4' # and req = BarRequest(a_bar_request) req.ip == '1.2.3.4' But some of these getters are CPU-intensive, and since the extended objects always remain immutable, I memoize them in req.__dict__, like: class BarRequest(dict): @property def ip(self): if 'ip' in self.__dict__: return self.__dict__['ip'] else: self.__dict__['ip'] = "%i.%i.%i.%i" % struct.unpack("4B", self['my-ip']) return self.__dict__['ip'] Which works as intended, and (I think) can be made prettier with a custom constant_property decorator. So... Question 0: Is there an obvious better way of achieving this functionality? Question 1: Is it safe to rely on __dict__ to bypass properties this way? Question 2: I'd like to use __slots__, but I can't seem to find a way to stop the property method from recursing. Is there one? Cheers, Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 19:32:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 00:32:03 GMT Subject: How to make an empty generator? References: Message-ID: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: > > If all you want is a generator that doesn't yield anything, then > > surely there isn't any one-time processing and you don't need the > > comment? > > Sure there is. Python doesn't know that nothing gets yielded until it > hits the return statement before the yield. When it calls .next() on the > iterator, the code elided by the comment executes, then the return is > hit, a StopIteration exception is raised, and the iteration is complete. I don't understand why you care about having *any* code before the StopIteration. That's like: def empty(): for x in range(1000): pass # Spin wheels uselessly return yield What's the point of the wheel spinning? Did I miss something? -- Steven From ben+python at benfinney.id.au Thu Feb 18 19:33:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 11:33:00 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> Message-ID: <871vgiawub.fsf@benfinney.id.au> Arnaud Delobelle writes: > What about > foo = iter('') That doesn't return a generator. >>> foo = iter('') >>> foo Whether the OP needs to create a generator, or just any iterable type, isn't clear. Robert Kern writes: > He doesn't want *any* empty generator. He wants an iterator that > executes some given side-effect-producing code then immediately raises > the StopIteration. Ah, hm. That's a rather perverse use case, but I'm sure the OP has their reasons. It's going to confuse a reader who isn't expecting it, no matter how simply it's done. So, I think the best answer is what has already been suggested, but that it's perverse enough that the hack *needs* a comment to say why it's being done. def make_empty_generator_with_side_effect(): """ Make a generator that does important work, but is empty. """ # Do the important work here. spam = object() # Make this function return an empty generator. if False: yield -- \ ?When cryptography is outlawed, bayl bhgynjf jvyy unir | `\ cevinpl.? ?Anonymous | _o__) | Ben Finney From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 19:36:00 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 00:36:00 GMT Subject: How secure are temp files created via tempfile.TemporaryFile()? References: <1266519267.4170.1360680003@webmail.messagingengine.com> <4B7D95F7.9020906@mrabarnett.plus.com> Message-ID: <4b7ddcf0$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 15:09:28 -0500, python wrote: > That's my concern - can other applications really read my temp files > created with tempfile.TemporaryFile( delete=True )? >>> import tempfile >>> x = tempfile.TemporaryFile(delete=True) Traceback (most recent call last): File "", line 1, in TypeError: TemporaryFile() got an unexpected keyword argument 'delete' The Fine Manual has good information about the security of the various calls: http://docs.python.org/library/tempfile.html tempfile.TemporaryFile(...) Return a file-like object that can be used as a temporary storage area. ... your code should not rely on a temporary file created using this function having or not having a visible name in the file system. ... tempfile.NamedTemporaryFile(...) This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file system ... Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms... > I don't think so because: > > 1. These files appear to be exclusively locked by my process, eg. no > other processes can read or write to these temp files except the process > that created these files. Exclusive locks are advisory, not mandatory, on some operating systems, so you can't rely on it. Recent versions of Windows have an interface to allow "backup software" to read files opened in exclusive mode, and I believe that the kernel can read *and write* to open files (although I welcome correction). http://en.wikipedia.org/wiki/File_locking And naturally, if your system is compromised with a root kit, then you can't trust *anything*, including file locks. But nobody expects an application to take responsibility for working securely in the face of a root kit :) > 2. As soon as my process terminates (voluntarily or involuntarily), the > temp file gets deleted. > > But I want to make sure. I think the best practice is platform-dependent: if os.name = "posix": # Unix, Linux, OpenBSD, FreeBSD, ... tmpfile = tempfile.TemporaryFile delete = None elif os.name in ["nt", "ce"]: # Windows NT, XP, 2000, CE, ... tmpfile = tempfile.NamedTemporaryFile delete = True else: # FIXME What to do for Mac, OS/2, RiscOS, Java? tmpfile = tempfile.TemporaryFile delete = None if delete is not None: f = tmpfile(*args, delete=delete) else: f = tmpfile(*args) -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 18 19:36:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 00:36:10 GMT Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> Message-ID: <4b7ddcfa$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 18:12:10 -0600, Robert Kern wrote: > He wants an iterator that executes some given side-effect-producing code > then immediately raises the StopIteration. Ah, that's the bit I missed! Yewww. Programming by side-effect... I hope the original poster has a good reason for such a thing. -- Steven From jgardner at jonathangardner.net Thu Feb 18 20:11:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 17:11:19 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <004104b2-519d-4d03-ba0f-c17e115e416b@s33g2000prm.googlegroups.com> On Feb 18, 3:04?pm, "sjdevn... at yahoo.com" wrote: > > You could do it without intermediate names or lambdas in Python as: > def print_numbers(): > ? ? for i in [ cube for (square, cube) in > ? ? ? ? ? ? ? ? ? ? ? ? ?[(n*n, n*n*n) for n in [1,2,3,4,5,6]] > ? ? ? ? ? ? ? ?if square!=25 and cube!=64 ]: > ? ? ? ? print i > > But frankly, although there's no reason that you _have_ to name the > content at each step, I find it a lot more readable if you do: > > def print_numbers(): > ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > cube!=64 ] > ? ? for f in filtered: > ? ? ? ? print f Step away from the keyboard! This is a programmer's arrest! There are laws around here, laws that we can't allow to be broken. You've just broken 12 of them. You think the laws don't apply to you, huh, punk? HUH? I'm sentencing you to three months HARD LABOR in Ruby for that code you just wrote. And if you think it's too harsh, then I'll sentence you to NINE MONTHS PHP and see how you feel about that! ;-) From rhodri at wildebst.demon.co.uk Thu Feb 18 20:11:52 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Fri, 19 Feb 2010 01:11:52 -0000 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> Message-ID: On Thu, 18 Feb 2010 09:50:14 -0000, DANNY wrote: > If I want to have a MPEG-4/10 coded video and stream it through the > network and than have the same video on the client side, what should I > use and of course I don't want to have raw MPEG data, because than I > couldn't extract the frames to manipulate them. By the looks of it, pyffmpeg may have some support for streamed input. If not, you might be able to put something together from tstools (http://developer.berlios.de/projects/tstools/) -- it's not what the tools were intended for, but there are Python bindings to the libraries that might help depending on exactly how you are streaming your video. Unfortunately the documentation is sparse to put it mildly, and pyffmpeg makes tstools look positively informative about how you're supposed to use it. -- Rhodri James *-* Wildebeeste Herder to the Masses From jgardner at jonathangardner.net Thu Feb 18 20:19:32 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Thu, 18 Feb 2010 17:19:32 -0800 (PST) Subject: Creating Import Hooks References: <9ba26789-a125-40e3-a832-8b6013aa3462@u15g2000prd.googlegroups.com> Message-ID: On Feb 18, 1:28?am, Sreejith K wrote: > On Feb 18, 1:57?pm, Steven D'Aprano > > > > wrote: > > On Thu, 18 Feb 2010 00:03:51 -0800, Jonathan Gardner wrote: > > > On Feb 17, 10:48?pm, Sreejith K wrote: > > >> Hi everyone, > > > >> I need to implement custom import hooks for an application > > >> (http://www.python.org/dev/peps/pep-0302/). I want to restrict an > > >> application to import certain modules (say socket module). Google app > > >> engine is using a module hook to do this (HardenedModulesHook in > > >> google/ appengine/tools/dev_appserver.py). But I want to allow that > > >> application to use an sdk module (custom) which imports and uses socket > > >> module. But the module hook restricts the access by sdk. Finding out, > > >> which file is importing a module give a solution?? ie. If the > > >> application is importing socket module, I want to restrict it. But if > > >> the sdk module is importing socket I want to allow it. Is there any way > > >> I can do this ? > > > >> Application > > >> ======== > > >> import sdk > > >> import socket ? ? ? ? ? ? ? # I dont want to allow this (need to raise > > >> ImportError) > > > >> SDK > > >> ==== > > >> import socket ? ? ? ? ? ? ? # need to allow this > > > > SDK > > > === > > > import socket > > > > App > > > === > > > import SDK > > > import sys > > > socket = sys.modules['socket'] > > > I'm not sure, but I think Sreejith wants to prohibit imports from the App > > layer while allowing them from the SDK layer, not work around a > > prohibition in the SDK layer. > > > In other words, he wants the import hook to do something like this: > > > if module is socket and the caller is not SKD: > > ? ? prohibit > > else > > ? ? allow > > > I could be wrong of course. > > > @Steven, Thats exactly what I want.. Anyway to do that ?? > My point was that it's really pointless to try to enforce any such thing on the program or programmer. There are ways around it. If you don't want them to play with socket, write in the documentation: "Don't play with the 'socket' module." If you want to prevent them from touching sockets at all, it's time to rethink your design. You may want to have a talk with Bruce Schneier, or at least read what he's written if you still think you need to somehow shut down a part of the system to its users. Oftentimes, programmers think they need to have control over what other people write, forgetting that they are able to do what they do due to the freedoms afforded them. They also forget that they are not in control of what other programmers do, anymore than a grocery store who refuses to stock a certain product can prevent people from getting that product. Write your code to expand freedoms, not limit them. If your design depends on limiting the choices of your users, you have done something wrong. From mwilson at the-wire.com Thu Feb 18 20:28:49 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 18 Feb 2010 20:28:49 -0500 Subject: How to make an empty generator? References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: > >> > If all you want is a generator that doesn't yield anything, then >> > surely there isn't any one-time processing and you don't need the >> > comment? >> >> Sure there is. Python doesn't know that nothing gets yielded until it >> hits the return statement before the yield. When it calls .next() on the >> iterator, the code elided by the comment executes, then the return is >> hit, a StopIteration exception is raised, and the iteration is complete. > > I don't understand why you care about having *any* code before the > StopIteration. That's like: > > def empty(): > for x in range(1000): > pass # Spin wheels uselessly > return > yield > > > What's the point of the wheel spinning? Did I miss something? I wonder whether it's for some kind of framework with a main loop like for it in list_of_iterables: for x in it: do_this_or_that (x) where, every once in a while one wants to throw some arbitrary code into the process, in the form of an empty iterable with side effects. Mel. From rantingrick at gmail.com Thu Feb 18 22:26:51 2010 From: rantingrick at gmail.com (rantingrick) Date: Thu, 18 Feb 2010 19:26:51 -0800 (PST) Subject: "Sounding" Off, IDLE (Win7) References: Message-ID: <2a3bacb8-b324-4189-a98a-d35b70358b48@i39g2000yqm.googlegroups.com> On Feb 18, 6:10?pm, "W. eWatson" wrote: > In Win7 IDLE, when I type in something with a syntax problem, a bell > rings. How do I stop that? I've looked at Control Panel Sounds, but > don't see anything of apparent use. Monkey Patch Said: """ Turn off your speakers""" From showell30 at yahoo.com Thu Feb 18 22:43:14 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 19:43:14 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <4b7dc6a2$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 18, 3:00?pm, Steven D'Aprano wrote: > [...] > You wouldn't name your functions: > > f01, f02, f03, f04, ... f99 > Exactly. > (say), unless you were trying to deliberately obfuscate your code. > Anonymous functions are even more obfuscated than that. You can get away > with it so long as you're only dealing with a few, in well-defined > placed, but you wouldn't want to use them all over the place. > I have contributed to the confusion of this discussion by talking about "anonymous functions," when the original context was "anonymous blocks." As I mentioned in an earlier response, most anonymous blocks in Ruby are placed within outer functions, so they're not that hard to locate in a traceback that provides only function names. And, of course, it is often the case that you host Ruby code on your own web server, or that you distribute Ruby code without compressing it, in which case you get a sane traceback that provides line numbers. You actually use anonymous blocks in your own code, in a few, well- defined places (generally loops). These excerpts are taken from obfuscate.py: quotient = a//mm a, mm = mm, a%mm xx, x = x - quotient*xx, xx yy, y = y - quotient*yy, yy rail = it.next() # The rail we add to. assert 0 <= rail < rails fence[rail].append(c) # Save one non-chaff character. buffer.append(msg.next()) # And toss away more chaff. n = self.hash(key) % factor key = self.mod_key(key) self.get_chars(n, msg) # Careful here! Not all classes have a __dict__! adict = getattr(obj, '__dict__', {}) for name, attr in adict.items(): if inspect.ismethoddescriptor(attr): d[nm + '.' + name] = attr.__get__(obj) If any of the above code were to fail on a customer site, you'd probably want to get line numbers in a traceback. I'm guessing you probably don't distribute your code in compressed form, and you probably take care to make sure it works right in the first place, and you probably have source control to help you pull up old versions of your code. I notice that you even have a __version__ identifier in your source code, which users of your library could capture in their tracebacks. In other words, you probably use mostly the same practices that I use, except that we seem to differ on the utility or expressiveness or Ruby blocks, or maybe we're arguing at cross purposes. From steve at holdenweb.com Thu Feb 18 22:48:21 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 22:48:21 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 18 Feb 2010 06:15:20 -0800, Steve Howell wrote: [...] > There really ought to be a special level of Hell for people who misuse > "strawman" to mean "a weak or invalid argument" instead of what it > actually means, which is a weak or invalid argument NOT HELD by your > opponent, which you (generic you) made up specifically for the sake of > shooting down. > > If you actually read what Duncan says, he prefixes his response with: > > "Some problems with using just line numbers to track errors". > > Duncan's post is an argument against relying on line numbers as your > main, or only, source of information about the location of bugs in > Javascript. > > In fact, this post is remarkable for the sheer number of actual strawman > arguments that you (Steve Howell) use: > > >> Shipping buggy code is a bad idea, even with named functions. > > Strawman #1: nobody said that shipping buggy code was a good idea, with > or without named functions. But shipping buggy code *happens*, no matter > how careful you are, so you need to expect bug reports back from users. > > (And they will be *hard to find* bugs, because if they were easy to find > you would have found them in your own testing before shipping.) > > >> Obscuring line numbers is a bad idea, even with named functions. > > Strawman #2: nobody said that obscuring line numbers was a good idea. But > apparently compressing Javascript is valuable for other reasons, and > obscuring the line numbers is the side-effect of doing so. > > And even knowing the line numbers is not necessarily useful, because many > bugs aren't due to the line that raises the stack trace. Just because you > know the line which failed doesn't mean you know how to fix the bug. > > >> Having your customers stay on older versions of your software is a bad >> idea, even with named functions. > > Strawman #3: nobody said that staying on older versions is a good idea. > But sometimes it happens whether you like it or not. > > (Although I'd like to point out that from the end user's perspective, > sometimes we don't want your stinkin' new version with all the anti- > features and pessimations and will stick to the old version for as long > as possible. If you don't like it, then think a bit harder before adding > anti-features like fragile, easily-corrupted databases which perform > really, really badly when your home directory is mounted over the > network. I'm talking to you, Firefox developers.) > > And it doesn't really matter: you either end-of-life the old version, in > which case you don't need to do anything about the bug report except say > "upgrade", or you decide to continue support, in which case it doesn't > matter whether the bug is reported for an old version or the latest > version, you still need to fix it. > > >> Not being able to know which version of software you're customer is >> running is a bad idea, even with named functions. > > Strawman #4. > > See the pattern? When you attack a position the other guy hasn't taken, > that's a strawman. When you make a weak argument, it's just a weak > argument. > Next week: Lesson 2 - Ad Hominem Attacks regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Feb 18 22:49:16 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 22:49:16 -0500 Subject: Few questions on SOAP In-Reply-To: References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: Brendon Wickham wrote: > On 19 February 2010 08:07, Mark Lawrence wrote: >> Muhammad Alkarouri wrote: >>> Your question is borderline if not out of topic in this group. I will >>> make a few comments though. >> This might be a Python group, but threads often drift way off topic, which >> added to the language itself make this a great group to read. If you don't >> like the way a thread goes, you can always skip it. > > > Perhaps...but he answered the question very well and with great, IMO, patience. +1 -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Thu Feb 18 22:52:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 18 Feb 2010 22:52:13 -0500 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <7a9c25c21002181536n50f8af58p3217b52c4142624a@mail.gmail.com> Message-ID: Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 2:56 PM, Robert Kern > wrote: > > class once(object): > def __init__(self, func, *args, **kwds): > self.func = func > self.args = args > self.kwds = kwds > > def __iter__(self): > return self > > def next(self): > self.func(*self.args, **self.kwds) > raise StopIteration() > > > Hmm, yeah. I'd probably tweak it into a decorator and name it > sideeffect_only or something, but yeah, that's the right approach at least. > > My motivation is clarity, I can just see a colleague a year from now > asking me, "... what the hell is return / yield?" and although this is > more expensive, its less clear to me. > > Thanks. > --S > So add a comment to the yield statement so it reads yield # force empty generator I realise that Jacob Kaplan-Moss calls comments in the code "lies", but the reader really only needs a small clue. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From showell30 at yahoo.com Thu Feb 18 22:57:35 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 19:57:35 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: On Feb 18, 3:04?pm, "sjdevn... at yahoo.com" wrote: > On Feb 18, 11:15?am, Steve Howell wrote: > > > ? ? def print_numbers() > > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > > ? ? ? ? ? ? [n * n, n * n * n] > > ? ? ? ? }.reject { |square, cube| > > ? ? ? ? ? ? square == 25 || cube == 64 > > ? ? ? ? }.map { |square, cube| > > ? ? ? ? ? ? cube > > ? ? ? ? }.each { |n| > > ? ? ? ? ? ? puts n > > ? ? ? ? } > > ? ? end > > > IMHO there is no reason that I should have to name the content of each > > of those four blocks of code, nor should I have to introduce the > > "lambda" keyword. > > You could do it without intermediate names or lambdas in Python as: > def print_numbers(): > ? ? for i in [ cube for (square, cube) in > ? ? ? ? ? ? ? ? ? ? ? ? ?[(n*n, n*n*n) for n in [1,2,3,4,5,6]] > ? ? ? ? ? ? ? ?if square!=25 and cube!=64 ]: > ? ? ? ? print i The problem with list comprehensions is that they read kind of out of order. On line 2 you are doing the first operation, then on line 3 you are filtering, then on line 1 your are selecting, then on line 4 you are printing. For such a small example, your code is still quite readable. > But frankly, although there's no reason that you _have_ to name the > content at each step, I find it a lot more readable if you do: > > def print_numbers(): > ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > cube!=64 ] > ? ? for f in filtered: > ? ? ? ? print f The names you give to the intermediate results here are terse--"tuples" and "filtered"--so your code reads nicely. In a more real world example, the intermediate results would be something like this: departments departments_in_new_york departments_in_new_york_not_on_bonus_cycle employees_in_departments_in_new_york_not_on_bonus_cycle names_of_employee_in_departments_in_new_york_not_on_bonus_cycle From python at mrabarnett.plus.com Thu Feb 18 22:57:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 03:57:53 +0000 Subject: "Sounding" Off, IDLE (Win7) In-Reply-To: <2a3bacb8-b324-4189-a98a-d35b70358b48@i39g2000yqm.googlegroups.com> References: <2a3bacb8-b324-4189-a98a-d35b70358b48@i39g2000yqm.googlegroups.com> Message-ID: <4B7E0C41.5000405@mrabarnett.plus.com> rantingrick wrote: > On Feb 18, 6:10 pm, "W. eWatson" wrote: >> In Win7 IDLE, when I type in something with a syntax problem, a bell >> rings. How do I stop that? I've looked at Control Panel Sounds, but >> don't see anything of apparent use. > > Monkey Patch Said: """ Turn off your speakers""" But what if you like to listen to music while programming? Look in the folder \Lib\idlelib for a file called "config-extensions.def". In it is a line: bell=1 Change that to: bell=0 Save the file and restart IDLE. From no.email at nospam.invalid Thu Feb 18 22:58:21 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Feb 2010 19:58:21 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <7xocjlx4f6.fsf@ruckus.brouhaha.com> Steve Howell writes: >> But frankly, although there's no reason that you _have_ to name the >> content at each step, I find it a lot more readable if you do: >> >> def print_numbers(): >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and >> cube!=64 ] >> ? ? for f in filtered: >> ? ? ? ? print f > > The names you give to the intermediate results here are > terse--"tuples" and "filtered"--so your code reads nicely. But that example makes tuples and filtered into completely expanded lists in memory. I don't know Ruby so I've been wondering whether the Ruby code would run as an iterator pipeline that uses constant memory. > In a more real world example, the intermediate results would be > something like this: > > departments > departments_in_new_york > departments_in_new_york_not_on_bonus_cycle > employees_in_departments_in_new_york_not_on_bonus_cycle > names_of_employee_in_departments_in_new_york_not_on_bonus_cycle http://haskell.org/ghc/docs/6.10.4/html/users_guide/syntax-extns.html#generalised-list-comprehensions might be of interest. Maybe Ruby and/or Python could grow something similar. From python at bdurham.com Thu Feb 18 23:19:41 2010 From: python at bdurham.com (python at bdurham.com) Date: Thu, 18 Feb 2010 23:19:41 -0500 Subject: How secure are temp files created via tempfile.TemporaryFile()? In-Reply-To: <4b7ddcf0$0$8819$c3e8da3@news.astraweb.com> References: <1266519267.4170.1360680003@webmail.messagingengine.com><4B7D95F7.9020906@mrabarnett.plus.com> <4b7ddcf0$0$8819$c3e8da3@news.astraweb.com> Message-ID: <1266553181.26400.1360768933@webmail.messagingengine.com> Steven, Thank you very much for your wonderful reply!! I had read the Fine Manual, but as you pointed out the documentation only mentions visibility of file names. > Exclusive locks are advisory, not mandatory, on some operating systems, so you can't rely on it. That comment and your list of OS specific behaviors were EXACTLY the type of information I was looking for. Thanks again! Malcolm From sjdevnull at yahoo.com Thu Feb 18 23:27:06 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Thu, 18 Feb 2010 20:27:06 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: On Feb 18, 10:58?pm, Paul Rubin wrote: > Steve Howell writes: > >> But frankly, although there's no reason that you _have_ to name the > >> content at each step, I find it a lot more readable if you do: > > >> def print_numbers(): > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > >> cube!=64 ] > >> ? ? for f in filtered: > >> ? ? ? ? print f > > > The names you give to the intermediate results here are > > terse--"tuples" and "filtered"--so your code reads nicely. > > But that example makes tuples and filtered into completely expanded > lists in memory. ?I don't know Ruby so I've been wondering whether the > Ruby code would run as an iterator pipeline that uses constant memory. I don't know how Ruby works, either. If it's using constant memory, switching the Python to generator comprehensions (and getting constant memory usage) is simply a matter of turning square brackets into parentheses: def print_numbers(): tuples = ((n*n, n*n*n) for n in (1,2,3,4,5,6)) filtered = ( cube for (square, cube) in tuples if square!=25 and cube!=64 ) for f in filtered: print f Replace (1,2,3,4,5,6) with xrange(100000000) and memory usage still stays constant. Though for this particular example, I prefer a strict looping solution akin to what Jonathan Gardner had upthread: for n in (1,2,3,4,5,6): square = n*n cube = n*n*n if square == 25 or cube == 64: continue print cube > > In a more real world example, the intermediate results would be > > something like this: > > > ? ?departments > > ? ?departments_in_new_york > > ? ?departments_in_new_york_not_on_bonus_cycle > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle I don't think the assertion that the names would be ridiculously long is accurate, either. Something like: departments = blah ny_depts = blah(departments) non_bonus_depts = blah(ny_depts) non_bonus_employees = blah(non_bonus_depts) employee_names = blah(non_bonus_employees) If the code is at all well-structured, it'll be just as obvious from the context that each list/generator/whatever is building from the previous one as it is in the anonymous block case. From cmpython at gmail.com Thu Feb 18 23:32:08 2010 From: cmpython at gmail.com (CM) Date: Thu, 18 Feb 2010 20:32:08 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> On Feb 18, 7:19?pm, Ryan Kelly wrote: > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > I have a Python app which I converted to an EXE (all files separate; > > single EXE didn't work properly) via py2exe - I plan on distributing > > this and would like the ability to remotely upgrade the program (for > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > be the best way to go about doing this? > > I've been working on an auto-update framework for my own frozen apps, > you might find it useful: > > ?http://pypi.python.org/pypi/esky > > Docs are a little scarce at the moment, the next release will hopefully > come with a short tutorial (as well as support for cx_freeze and maybe > py2app, depending on how adventurous I'm feeling). > > ? Cheers, > > ? ? ?Ryan This looks pretty interesting and useful. Just to help me understand it a bit more: what is it that users will download from some web page in order to initially get the py2exe'd app on their system? Is it "really" an "esky", with the app's .exe file inside it (but the esky is named the same as the app)? And then when they want to update, the app's code calls the esky class to do the work of swapping out the appropriate .exe file? Something like this? Sorry if I am confused as to how this works. Would this also work if one used InnoSetup to install the exe on the user's system? Thanks, Che From showell30 at yahoo.com Thu Feb 18 23:46:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 20:46:04 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: On Feb 18, 2:49?pm, Jonathan Gardner wrote: > On Feb 18, 8:15?am, Steve Howell wrote: > > > > > ? ? def print_numbers() > > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > > ? ? ? ? ? ? [n * n, n * n * n] > > ? ? ? ? }.reject { |square, cube| > > ? ? ? ? ? ? square == 25 || cube == 64 > > ? ? ? ? }.map { |square, cube| > > ? ? ? ? ? ? cube > > ? ? ? ? }.each { |n| > > ? ? ? ? ? ? puts n > > ? ? ? ? } > > ? ? end > > If this style of programming were useful, we would all be writing Lisp > today. As it turned out, Lisp is incredibly difficult to read and > understand, even for experienced Lispers. I am pleased that Python is > not following Lisp in that regard. > > for n in range(1,6): > ? ? square = n*n > ? ? cube = n*n*n > ? ? if square == 25 or cube == 64: continue > ? ? print cube There's definitely a cognitive dissonance between imperative programming and functional programming. It's hard for programmers used to programming in an imperative style to appreciate a functional approach, because functional solutions often read "upside down" in the actual source code and common algebraic notation: def compute_squares_and_cubes(lst): return [(n * n, n * n * n) for n in lst] def reject_bad_values(lst): return [(square, cube) for (square, cube) \ in lst if not (square == 25 or cube == 64)] def cubes_only(lst): return [cube for square, cube in lst] def print_results(lst): # 1. compute_squares_and_cubes # 2. reject_bad_values # 3. take cubes_only # 4. print values for item in \ cubes_only( # 3 reject_bad_values( # 2 compute_squares_and_cubes(lst))): # 1 print item # 4 You can, of course, restore the natural order of operations to read top-down with appropriate use of intermediate locals: def print_results(lst): lst2 = compute_squares_and_cubes(lst) lst3 = reject_bad_values(lst2) lst4 = cubes_only(lst3) for item in lst4: print item From showell30 at yahoo.com Thu Feb 18 23:57:47 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 20:57:47 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: <96c65bac-2bc1-4ae0-8349-45ec0c3404d9@l12g2000prg.googlegroups.com> On Feb 18, 7:58?pm, Paul Rubin wrote: > Steve Howell writes: > >> But frankly, although there's no reason that you _have_ to name the > >> content at each step, I find it a lot more readable if you do: > > >> def print_numbers(): > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > >> cube!=64 ] > >> ? ? for f in filtered: > >> ? ? ? ? print f > > > The names you give to the intermediate results here are > > terse--"tuples" and "filtered"--so your code reads nicely. > > But that example makes tuples and filtered into completely expanded > lists in memory. ?I don't know Ruby so I've been wondering whether the > Ruby code would run as an iterator pipeline that uses constant memory. > That's a really good question. I don't know the answer. My hunch is that you could implement generators using Ruby syntax, but it's probably not implemented that way. The fact that Python allows you to turn the intermediate results into generator expressions is a very powerful feature, of course. > > In a more real world example, the intermediate results would be > > something like this: > > > ? ?departments > > ? ?departments_in_new_york > > ? ?departments_in_new_york_not_on_bonus_cycle > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > > http://haskell.org/ghc/docs/6.10.4/html/users_guide/syntax-extns.html... > > might be of interest. ?Maybe Ruby and/or Python could grow something similar. Can you elaborate? From python at bdurham.com Fri Feb 19 00:02:44 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 19 Feb 2010 00:02:44 -0500 Subject: Using compileall to create -OO type .pyo files Message-ID: <1266555764.31891.1360772585@webmail.messagingengine.com> I've read the documentation on compileall and tried using this module directly. Nowhere can I find how to specify to compileall that it should create .pyo vs. .pyc files. Goal: I would like to use the compileall.compile_dir() method to generate -OO type .pyo files as part of a larger Python build script. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From showell30 at yahoo.com Fri Feb 19 00:05:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 21:05:04 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: On Feb 18, 8:27?pm, "sjdevn... at yahoo.com" wrote: > On Feb 18, 10:58?pm, Paul Rubin wrote: > > Steve Howell writes: > > >> But frankly, although there's no reason that you _have_ to name the > > >> content at each step, I find it a lot more readable if you do: > > > >> def print_numbers(): > > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > > >> cube!=64 ] > > >> ? ? for f in filtered: > > >> ? ? ? ? print f > > > > The names you give to the intermediate results here are > > > terse--"tuples" and "filtered"--so your code reads nicely. > > > But that example makes tuples and filtered into completely expanded > > lists in memory. ?I don't know Ruby so I've been wondering whether the > > Ruby code would run as an iterator pipeline that uses constant memory. > > I don't know how Ruby works, either. ?If it's using constant memory, > switching the Python to generator comprehensions (and getting constant > memory usage) is simply a matter of turning square brackets into > parentheses: > > def print_numbers(): > ? ? tuples = ((n*n, n*n*n) for n in (1,2,3,4,5,6)) > ? ? filtered = ( cube for (square, cube) in tuples if square!=25 and > ? ? ? ? ? ? ? ? ?cube!=64 ) > ? ? for f in filtered: > ? ? ? ? print f > > Replace (1,2,3,4,5,6) with xrange(100000000) and memory usage still > stays constant. > > Though for this particular example, I prefer a strict looping solution > akin to what Jonathan Gardner had upthread: > > for n in (1,2,3,4,5,6): > ? ? square = n*n > ? ? cube = n*n*n > ? ? if square == 25 or cube == 64: continue > ? ? print cube > > > > In a more real world example, the intermediate results would be > > > something like this: > > > > ? ?departments > > > ? ?departments_in_new_york > > > ? ?departments_in_new_york_not_on_bonus_cycle > > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > > I don't think the assertion that the names would be ridiculously long > is accurate, either. > > Something like: > > departments = blah > ny_depts = blah(departments) > non_bonus_depts = blah(ny_depts) > non_bonus_employees = blah(non_bonus_depts) > employee_names = blah(non_bonus_employees) > > If the code is at all well-structured, it'll be just as obvious from > the context that each list/generator/whatever is building from the > previous one as it is in the anonymous block case. I agree that the names don't have to be as ridiculously long as my examples, but using intermediate locals forces you to come up with consistent abbreviations between adjacent lines, which adds to the maintenance burden. When the requirements change so that bonuses apply to NY and PA departments, you would have to change three places in the code instead of one. To the extent that each of your transformations were named functions, you'd need to maintain the names there as well (something more descriptive than "blah"). From greg.ewing at canterbury.ac.nz Fri Feb 19 00:23:30 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 19 Feb 2010 18:23:30 +1300 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <4b7c22c8$0$1651$742ec2ed@news.sonic.net> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7c22c8$0$1651$742ec2ed@news.sonic.net> Message-ID: <7u6kv0F8fiU1@mid.individual.net> John Nagle wrote: > One way to implement locking is something like this: > > Mutable objects have a reference count field, a lock field, > and an "owner" field. Initially, the owner of an object is its thread. > If an object's only reference is a field of a synchronized object, the > owner is the synchronized object. The trouble with that is that there will hardly ever be "only one reference" to any object that you do anything with, even just looking at it, because temporary references come and go as the interpreter goes about its business. A simple demonstration of this: Python 2.5 (r25:51908, Apr 8 2007, 22:22:18) [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> foo = (1, 2, 3) >>> import sys >>> sys.getrefcount(foo) 2 Even though you might think that there is only one reference to foo, the very act of passing it as a parameter to getrefcount() causes another reference to come into existence temporarily. -- Greg From no.email at nospam.invalid Fri Feb 19 00:26:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 18 Feb 2010 21:26:52 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> <96c65bac-2bc1-4ae0-8349-45ec0c3404d9@l12g2000prg.googlegroups.com> Message-ID: <7x1vghkd7n.fsf@ruckus.brouhaha.com> Steve Howell writes: >> http://haskell.org/ghc/docs/6.10.4/html/users_guide/syntax-extns.html... >> might be of interest. ?Maybe Ruby and/or Python could grow something similar. > Can you elaborate? List comprehensions are a Python feature you're probably familiar with, and I think Ruby has something like them too. They originally came from Haskell. GHC (the main Haskell implementation) now supports an extended list comprehension syntax with SQL-like features. I haven't used it much yet, but here's an example from a poker ranking program (http://www.rubyquiz.com/quiz24.html) that I did as a Haskell exercise: let (winners:others) = [zip c ls | ls <- lines cs , let {h = mkHand ls; c=classify h} , then group by c , then sortWith by Down c] It's reasonably evocative and doing the same thing with the older syntax would have been a big mess. "Down" basically means sort in reverse order. From showell30 at yahoo.com Fri Feb 19 00:35:48 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 21:35:48 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <7xocjlx4f6.fsf@ruckus.brouhaha.com> Message-ID: <60ce8051-8bda-470b-8943-ce87dad9e8eb@s25g2000prd.googlegroups.com> On Feb 18, 7:58?pm, Paul Rubin wrote: > Steve Howell writes: > >> But frankly, although there's no reason that you _have_ to name the > >> content at each step, I find it a lot more readable if you do: > > >> def print_numbers(): > >> ? ? tuples = [(n*n, n*n*n) for n in (1,2,3,4,5,6)] > >> ? ? filtered = [ cube for (square, cube) in tuples if square!=25 and > >> cube!=64 ] > >> ? ? for f in filtered: > >> ? ? ? ? print f > > > The names you give to the intermediate results here are > > terse--"tuples" and "filtered"--so your code reads nicely. > > But that example makes tuples and filtered into completely expanded > lists in memory. ?I don't know Ruby so I've been wondering whether the > Ruby code would run as an iterator pipeline that uses constant memory. > Running the following code would probably answer your question. At least in the case of Array.map and Array.reject, under my version of Ruby, each block transforms the entire array before passing control to the next block. def print_numbers() [1, 2, 3, 4, 5, 6].map { |n| puts 'first block', n [n * n, n * n * n] }.reject { |square, cube| puts 'reject', square square == 25 || cube == 64 }.map { |square, cube| cube }.each { |cube| puts cube } end print_numbers() But I'm running only version 1.8.7. Version 1.9 of Ruby apparently introduced something more akin to generators and Unix pipelines: http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-using.html I haven't tried them myself. From kwmsmith at gmail.com Fri Feb 19 00:37:59 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Thu, 18 Feb 2010 23:37:59 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: On Thu, Feb 18, 2010 at 10:46 PM, Steve Howell wrote: > On Feb 18, 2:49?pm, Jonathan Gardner > wrote: >> On Feb 18, 8:15?am, Steve Howell wrote: >> >> >> >> > ? ? def print_numbers() >> > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| >> > ? ? ? ? ? ? [n * n, n * n * n] >> > ? ? ? ? }.reject { |square, cube| >> > ? ? ? ? ? ? square == 25 || cube == 64 >> > ? ? ? ? }.map { |square, cube| >> > ? ? ? ? ? ? cube >> > ? ? ? ? }.each { |n| >> > ? ? ? ? ? ? puts n >> > ? ? ? ? } >> > ? ? end >> >> If this style of programming were useful, we would all be writing Lisp >> today. As it turned out, Lisp is incredibly difficult to read and >> understand, even for experienced Lispers. I am pleased that Python is >> not following Lisp in that regard. >> >> for n in range(1,6): >> ? ? square = n*n >> ? ? cube = n*n*n >> ? ? if square == 25 or cube == 64: continue >> ? ? print cube > > There's definitely a cognitive dissonance between imperative > programming and functional programming. ?It's hard for programmers > used to programming in an imperative style to appreciate a functional > approach, because functional solutions often read "upside down" in the > actual source code and common algebraic notation: > > ? ?def compute_squares_and_cubes(lst): > ? ? ? ?return [(n * n, n * n * n) for n in lst] > > ? ?def reject_bad_values(lst): > ? ? ? ?return [(square, cube) for (square, cube) \ > ? ? ? ? ? ?in lst if not (square == 25 or cube == 64)] > > ? ?def cubes_only(lst): > ? ? ? ?return [cube for square, cube in lst] > > ? ?def print_results(lst): > ? ? ? ?# 1. compute_squares_and_cubes > ? ? ? ?# 2. reject_bad_values > ? ? ? ?# 3. take cubes_only > ? ? ? ?# 4. print values > ? ? ? ?for item in \ > ? ? ? ? ? ?cubes_only( # 3 > ? ? ? ? ? ? ? ?reject_bad_values( # 2 > ? ? ? ? ? ? ? ? ? ?compute_squares_and_cubes(lst))): # 1 > ? ? ? ? ? ?print item # 4 > > You can, of course, restore the natural order of operations to read > top-down with appropriate use of intermediate locals: > > ? ?def print_results(lst): > ? ? ? ?lst2 = compute_squares_and_cubes(lst) > ? ? ? ?lst3 = reject_bad_values(lst2) > ? ? ? ?lst4 = cubes_only(lst3) > ? ? ? ?for item in lst4: > ? ? ? ? ? ?print item > > -- > http://mail.python.org/mailman/listinfo/python-list > # sent the original to the wrong place -- resending to python-list. Somewhat off topic, but only somewhat: you could use coroutines to get a pipeline effect. #--------------8<----------------------------- # Shamelessly lifted from David Beazley's # http://www.dabeaz.com/coroutines/ def coroutine(co): def _inner(*args, **kwargs): gen = co(*args, **kwargs) gen.next() return gen return _inner def squares_and_cubes(lst, target): for n in lst: target.send((n * n, n * n * n)) @coroutine def reject_bad_values(target): while True: square, cube = (yield) if not (square == 25 or cube == 64): target.send((square, cube)) @coroutine def cubes_only(target): while True: square, cube = (yield) target.send(cube) @coroutine def print_results(): while True: print (yield) squares_and_cubes(range(10), reject_bad_values( cubes_only( print_results() ) ) ) #--------------8<----------------------------- From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 00:41:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 05:41:31 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7e248b$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 22:48:21 -0500, Steve Holden wrote: > Next week: Lesson 2 - Ad Hominem Attacks I wouldn't pay any attention to Steve, all Stevens are notorious liars. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 00:46:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 05:46:31 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <4b7e25b7$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 19:57:35 -0800, Steve Howell wrote: > The names you give to the intermediate results here are terse--"tuples" > and "filtered"--so your code reads nicely. > > In a more real world example, the intermediate results would be > something like this: > > departments > departments_in_new_york > departments_in_new_york_not_on_bonus_cycle > employees_in_departments_in_new_york_not_on_bonus_cycle > names_of_employee_in_departments_in_new_york_not_on_bonus_cycle Those last two could be written more concisely as: serfs_in_new_york names_of_serfs_in_new_york_as_if_we_cared But seriously... if you have a variable called "departments_in_new_york", presumably you also have variables called "departments_in_washington", "departments_in_los_angeles", "departments_in_houston", "departments_in_walla_walla", and so forth. If so, this is a good sign that you are doing it wrong and you need to rethink your algorithm. -- Steven From showell30 at yahoo.com Fri Feb 19 00:50:58 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 21:50:58 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <4b7dbc94$0$8819$c3e8da3@news.astraweb.com> <4b7e248b$0$8819$c3e8da3@news.astraweb.com> Message-ID: <322eb626-ef2a-4fc7-8472-850932868f7f@t34g2000prm.googlegroups.com> On Feb 18, 9:41?pm, Steven D'Aprano wrote: > On Thu, 18 Feb 2010 22:48:21 -0500, Steve Holden wrote: > > Next week: Lesson 2 - Ad Hominem Attacks > > I wouldn't pay any attention to Steve, all Stevens are notorious liars. > > -- > Steven Especially when their last name starts with H. Cheers, Steve From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 00:52:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 05:52:03 GMT Subject: How secure are temp files created via tempfile.TemporaryFile()? References: <1266519267.4170.1360680003@webmail.messagingengine.com> <4B7D95F7.9020906@mrabarnett.plus.com> <1266523768.19867.1360705413@webmail.messagingengine.com> Message-ID: <4b7e2703$0$8819$c3e8da3@news.astraweb.com> On Thu, 18 Feb 2010 21:34:58 -0800, Dennis Lee Bieber wrote: > On Thu, 18 Feb 2010 15:09:28 -0500, python at bdurham.com declaimed the > following in gmane.comp.python.general: > >> 2. As soon as my process terminates (voluntarily or involuntarily), the >> temp file gets deleted. >> > Which only means the directory entry for it is lost... depending on > the OS, someone creating a new file in "w+" and performing a long seek > just to write one byte, may now have all those disk sectors your temp > file had been in -- and can read them at leisure. > > Or some file recovery tools might make a file out of the sectors... > > If you are really worried about the contents becoming visible after > "deletion" you should probably run a wipe operation on the file (write > random sequence over data; read/verify said random sequence; write new > random sequence over file; read/verify this sequence; write 1s > complement of sequence; read/verify that final sequence). If that is your concern, then you shouldn't be using tempfile, you should be using permanent files and wiping them yourself. I think the OP is more concerned about the sort of security flaw where you open a temporary file, and some hostile process hijacks it before you're done with it. But once you're done with the file, you probably no longer care about the contents. -- Steven From greg.ewing at canterbury.ac.nz Fri Feb 19 00:52:20 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 19 Feb 2010 18:52:20 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> Message-ID: <7u6ml2Ffd8U1@mid.individual.net> Steve Howell wrote: > Python may not support the broadest notion of anonymous functions, but > it definitely has anonymous blocks. You can write this in Python: > > for i in range(10): > print i > print i * i > print i * i * i There's a clear difference between this and a Ruby block, however. A "block" in Ruby is implemented by passing a callable object to a method. There is no callable object corresponding to the body of a for-loop in Python. The important thing about Ruby blocks is not that they're anonymous, but that they're concrete objects that can be manipulated. The Ruby approach has the advantage of making it possible to implement user-defined control structures without requiring a macro facility. You can't do that in Python. However, there's something that Python's iterator protocol makes possible that you can't do with a block-passing approach. You can have multiple iterators active at once, and pull values from them as an when required in the calling code. Ruby's version of the iterator protocol can't handle that, because once an iterator is started it retains control until it's finished. Also, most people who advocate adding some form of block-passing facility to Python don't seem to have thought through what would happen if the block contains any break, continue, return or yield statements. This issue was looked into in some detail back when there was consideration of implementing the with-statement by passing the body as a function. Getting these statements to behave intuitively inside the body turned out to be a very thorny problem -- thorny enough to cause the block-passing idea to be abandoned in favour of the current implementation. -- Greg From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 01:00:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 06:00:17 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> <7u6ml2Ffd8U1@mid.individual.net> Message-ID: <4b7e28f0$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 18:52:20 +1300, Gregory Ewing wrote: > The Ruby approach has the advantage of making it possible to implement > user-defined control structures without requiring a macro facility. You > can't do that in Python. [...] > Also, most people who advocate adding some form of block-passing > facility to Python don't seem to have thought through what would happen > if the block contains any break, continue, return or yield statements. That is the only time I ever wanted blocks: I had a series of functions containing for loops that looked something vaguely like this: for x in sequence: code_A try: something except some_exception: code_B where code_B was different in each function, so I wanted to pull it out as a code block and do this: def common_loop(x, block): code_A try: something except some_exception: block for x in sequence: common_loop(x, block) The problem was that the blocks contained a continue statement, so I was stymied. -- Steven From showell30 at yahoo.com Fri Feb 19 01:07:23 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 22:07:23 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> <4b7e25b7$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 18, 9:46?pm, Steven D'Aprano wrote: > On Thu, 18 Feb 2010 19:57:35 -0800, Steve Howell wrote: > > The names you give to the intermediate results here are terse--"tuples" > > and "filtered"--so your code reads nicely. > > > In a more real world example, the intermediate results would be > > something like this: > > > ? ?departments > > ? ?departments_in_new_york > > ? ?departments_in_new_york_not_on_bonus_cycle > > ? ?employees_in_departments_in_new_york_not_on_bonus_cycle > > ? ?names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > > Those last two could be written more concisely as: > > serfs_in_new_york > names_of_serfs_in_new_york_as_if_we_cared > > But seriously... if you have a variable called "departments_in_new_york", > presumably you also have variables called "departments_in_washington", > "departments_in_los_angeles", "departments_in_houston", > "departments_in_walla_walla", and so forth. If so, this is a good sign > that you are doing it wrong and you need to rethink your algorithm. > Sure, but it could also be that you're launching a feature that is only temporarily limited to New York departments, and any investment in coming up with names for the New York filter function or intermediate local variables becomes pointless once you go national: # version 1 emps = [ ['Bob Rich', 'NY', 55], ['Alice Serf', 'NY', 30], ['Joe Peasant', 'MD', 12], ['Mary Pauper', 'CA', 13], ] emps.select { |name, state, salary| salary < 40 }.select { |name, state, salary| # limit bonuses to NY for now...reqs # may change! state == 'NY' }.each { |name, state, salary| new_salary = salary * 1.1 puts "#{name} gets a raise to #{new_salary}!" } # version 2 emps = [ ['Bob Rich', 'NY', 55], ['Alice Serf', 'NY', 30], ['Joe Peasant', 'MD', 12], ['Mary Pauper', 'CA', 13], ] emps.select { |name, state, salary| salary < 40 }.each { |name, state, salary| new_salary = salary * 1.1 puts "#{name} gets a raise to #{new_salary}!" } From robert.kern at gmail.com Fri Feb 19 01:15:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 00:15:20 -0600 Subject: How to make an empty generator? In-Reply-To: References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-18 19:28 PM, Mel wrote: > Steven D'Aprano wrote: > >> On Thu, 18 Feb 2010 17:30:54 -0600, Robert Kern wrote: >> >>> > If all you want is a generator that doesn't yield anything, then >>> > surely there isn't any one-time processing and you don't need the >>> > comment? >>> >>> Sure there is. Python doesn't know that nothing gets yielded until it >>> hits the return statement before the yield. When it calls .next() on the >>> iterator, the code elided by the comment executes, then the return is >>> hit, a StopIteration exception is raised, and the iteration is complete. >> >> I don't understand why you care about having *any* code before the >> StopIteration. That's like: >> >> def empty(): >> for x in range(1000): >> pass # Spin wheels uselessly >> return >> yield >> >> >> What's the point of the wheel spinning? Did I miss something? > > I wonder whether it's for some kind of framework with a main loop like > > for it in list_of_iterables: > for x in it: > do_this_or_that (x) > > where, every once in a while one wants to throw some arbitrary code into the > process, in the form of an empty iterable with side effects. Yes. That is exactly what the OP said in his original post: """ I have some generators that do stuff, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really "generators" because I want to call them /as/ a generator as part of a generalized system. """ -- 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 Fri Feb 19 01:16:30 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 00:16:30 -0600 Subject: How to make an empty generator? In-Reply-To: <871vgiawub.fsf@benfinney.id.au> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: On 2010-02-18 18:33 PM, Ben Finney wrote: > Robert Kern writes: > >> He doesn't want *any* empty generator. He wants an iterator that >> executes some given side-effect-producing code then immediately raises >> the StopIteration. > > Ah, hm. That's a rather perverse use case, but I'm sure the OP has their > reasons. Which he explained fairly clearly, I thought, in his original post. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 01:21:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 06:21:48 GMT Subject: How to make an empty generator? References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: >>> What's the point of the wheel spinning? Did I miss something? >> >> I wonder whether it's for some kind of framework with a main loop like >> >> for it in list_of_iterables: >> for x in it: >> do_this_or_that (x) >> >> where, every once in a while one wants to throw some arbitrary code >> into the process, in the form of an empty iterable with side effects. > > Yes. That is exactly what the OP said in his original post: > > """ > I have some generators that do stuff, then start yielding results. On > occasion, I don't want them to yield anything ever-- they're only really > "generators" because I want to call them /as/ a generator as part of a > generalized system. """ But he doesn't say anything about side-effects. If you're passing generators around, sometimes you want an empty generator, just as sometimes you want an empty string, or list, or whatever. -- Steven From showell30 at yahoo.com Fri Feb 19 01:44:16 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 22:44:16 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> On Feb 18, 9:37?pm, Kurt Smith wrote: > On Thu, Feb 18, 2010 at 10:46 PM, Steve Howell wrote: > > On Feb 18, 2:49?pm, Jonathan Gardner > > wrote: > >> On Feb 18, 8:15?am, Steve Howell wrote: > > >> > ? ? def print_numbers() > >> > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > >> > ? ? ? ? ? ? [n * n, n * n * n] > >> > ? ? ? ? }.reject { |square, cube| > >> > ? ? ? ? ? ? square == 25 || cube == 64 > >> > ? ? ? ? }.map { |square, cube| > >> > ? ? ? ? ? ? cube > >> > ? ? ? ? }.each { |n| > >> > ? ? ? ? ? ? puts n > >> > ? ? ? ? } > >> > ? ? end > > >> If this style of programming were useful, we would all be writing Lisp > >> today. As it turned out, Lisp is incredibly difficult to read and > >> understand, even for experienced Lispers. I am pleased that Python is > >> not following Lisp in that regard. > > >> for n in range(1,6): > >> ? ? square = n*n > >> ? ? cube = n*n*n > >> ? ? if square == 25 or cube == 64: continue > >> ? ? print cube > > > There's definitely a cognitive dissonance between imperative > > programming and functional programming. ?It's hard for programmers > > used to programming in an imperative style to appreciate a functional > > approach, because functional solutions often read "upside down" in the > > actual source code and common algebraic notation: > > > ? ?def compute_squares_and_cubes(lst): > > ? ? ? ?return [(n * n, n * n * n) for n in lst] > > > ? ?def reject_bad_values(lst): > > ? ? ? ?return [(square, cube) for (square, cube) \ > > ? ? ? ? ? ?in lst if not (square == 25 or cube == 64)] > > > ? ?def cubes_only(lst): > > ? ? ? ?return [cube for square, cube in lst] > > > ? ?def print_results(lst): > > ? ? ? ?# 1. compute_squares_and_cubes > > ? ? ? ?# 2. reject_bad_values > > ? ? ? ?# 3. take cubes_only > > ? ? ? ?# 4. print values > > ? ? ? ?for item in \ > > ? ? ? ? ? ?cubes_only( # 3 > > ? ? ? ? ? ? ? ?reject_bad_values( # 2 > > ? ? ? ? ? ? ? ? ? ?compute_squares_and_cubes(lst))): # 1 > > ? ? ? ? ? ?print item # 4 > > > You can, of course, restore the natural order of operations to read > > top-down with appropriate use of intermediate locals: > > > ? ?def print_results(lst): > > ? ? ? ?lst2 = compute_squares_and_cubes(lst) > > ? ? ? ?lst3 = reject_bad_values(lst2) > > ? ? ? ?lst4 = cubes_only(lst3) > > ? ? ? ?for item in lst4: > > ? ? ? ? ? ?print item > > > -- > >http://mail.python.org/mailman/listinfo/python-list > > # sent the original to the wrong place -- resending to python-list. > > Somewhat off topic, but only somewhat: ?you could use coroutines to > get a pipeline effect. > > #--------------8<----------------------------- > # Shamelessly lifted from David Beazley's > # ?http://www.dabeaz.com/coroutines/ > > def coroutine(co): > ? ?def _inner(*args, **kwargs): > ? ? ? ?gen = co(*args, **kwargs) > ? ? ? ?gen.next() > ? ? ? ?return gen > ? ?return _inner > > def squares_and_cubes(lst, target): > ? ?for n in lst: > ? ? ? ?target.send((n * n, n * n * n)) > > @coroutine > def reject_bad_values(target): > ? ?while True: > ? ? ? ?square, cube = (yield) > ? ? ? ?if not (square == 25 or cube == 64): > ? ? ? ? ? ?target.send((square, cube)) > > @coroutine > def cubes_only(target): > ? ?while True: > ? ? ? ?square, cube = (yield) > ? ? ? ?target.send(cube) > > @coroutine > def print_results(): > ? ?while True: > ? ? ? ?print (yield) > > squares_and_cubes(range(10), > ? ? ? ?reject_bad_values( > ? ? ? ? ? ?cubes_only( > ? ? ? ? ? ? ? ?print_results() > ? ? ? ? ? ? ? ?) > ? ? ? ? ? ?) > ? ? ? ?) Wow! It took me a while to get my head around it, but that's pretty cool. From ben+python at benfinney.id.au Fri Feb 19 02:01:52 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 18:01:52 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: <87ocjlaeu7.fsf@benfinney.id.au> Robert Kern writes: > On 2010-02-18 18:33 PM, Ben Finney wrote: > > Robert Kern writes: > > > >> He doesn't want *any* empty generator. He wants an iterator that > >> executes some given side-effect-producing code then immediately > >> raises the StopIteration. > > > > Ah, hm. That's a rather perverse use case, but I'm sure the OP has their > > reasons. > > Which he explained fairly clearly, I thought, in his original post. (The original post isn't available to me; the reference in your reply isn't accessible AFAICT.) In the part of the original that you quoted, he speaks only of empty generators (easy and clean), not generators that exist only for the purpose of side-effects without yielding any items. It's that latter that I describe as perverse, and I would think it worth some effort to determine if that can be avoided by a different approach. -- \ ?The problem with television is that the people must sit and | `\ keep their eyes glued on a screen: the average American family | _o__) hasn't time for it.? ?_The New York Times_, 1939 | Ben Finney From showell30 at yahoo.com Fri Feb 19 02:13:28 2010 From: showell30 at yahoo.com (Steve Howell) Date: Thu, 18 Feb 2010 23:13:28 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> <7u6ml2Ffd8U1@mid.individual.net> Message-ID: <3a910818-6911-4c9f-bdf0-7fffc31b117f@z1g2000prc.googlegroups.com> On Feb 18, 9:52?pm, Gregory Ewing wrote: > Steve Howell wrote: > > Python may not support the broadest notion of anonymous functions, but > > it definitely has anonymous blocks. ?You can write this in Python: > > > ? ? for i in range(10): > > ? ? ? ? print i > > ? ? ? ? print i * i > > ? ? ? ? print i * i * i > > There's a clear difference between this and a Ruby block, > however. A "block" in Ruby is implemented by passing a > callable object to a method. There is no callable object > corresponding to the body of a for-loop in Python. > > The important thing about Ruby blocks is not that they're > anonymous, but that they're concrete objects that can > be manipulated. > Agreed. > The Ruby approach has the advantage of making it possible > to implement user-defined control structures without > requiring a macro facility. You can't do that in Python. > > However, there's something that Python's iterator protocol > makes possible that you can't do with a block-passing > approach. You can have multiple iterators active at once, > and pull values from them as an when required in the > calling code. Ruby's version of the iterator protocol > can't handle that, because once an iterator is started > it retains control until it's finished. > Is this still true or Ruby today? http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-using.html > Also, most people who advocate adding some form of > block-passing facility to Python don't seem to have > thought through what would happen if the block contains > any break, continue, return or yield statements. > For sure. It's certainly not clear to me how Ruby handles all those cases, although I am still quite new to Ruby, so it's possible that I just haven't stumbled upon the best explanations yet. > This issue was looked into in some detail back when there > was consideration of implementing the with-statement > by passing the body as a function. Getting these > statements to behave intuitively inside the body > turned out to be a very thorny problem -- thorny enough > to cause the block-passing idea to be abandoned in > favour of the current implementation. > I found these links in the archive...were these part of the discussion you were referring to? http://mail.python.org/pipermail/python-dev/2005-April/052907.html http://mail.python.org/pipermail/python-dev/2005-April/053055.html http://mail.python.org/pipermail/python-dev/2005-April/053123.html From ken at picloud.com Fri Feb 19 02:14:19 2010 From: ken at picloud.com (Ken Elkabany) Date: Thu, 18 Feb 2010 23:14:19 -0800 Subject: ANN: PiCloud cloud library 1.8 release Message-ID: PiCloud, a cloud-computing platform for the Python Programming Language, has released version 1.8 of its client library, cloud. PiCloud enables Python users to leverage the power of an on-demand, high performance, and auto scaling compute cluster with as few as three lines of code! No server management necessary. You can find out more here: http://www.picloud.com What's New: * The client library is now open source with an LGPL license. * Users can choose to run their code across 2.5ghz nodes or 1ghz nodes with a simple kwarg. * Users can now select to run their code in real-time, guaranteeing that their processes start in under a second. * Drop-in replacement for multiprocessing. * Improved cluster workload distribution performance by 20%. * Improved efficiency of Python interpreter state extraction by the client library. * Optimized for all Python packages in the Enthought Python Distribution. * Bug fixes. * And much more! 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: * Crawling the web * Manipulating images and videos * Generating charts and graphs * Statistical analysis of data sets * Real-time data processing Cheers, Ken Elkabany PiCloud, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From nobrowser at gmail.com Fri Feb 19 02:18:20 2010 From: nobrowser at gmail.com (nobrowser) Date: Thu, 18 Feb 2010 23:18:20 -0800 (PST) Subject: with statement and standard library Message-ID: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Hi. The with statement is certainly nifty. The trouble is, the *only* two documented examples how it can be used with the library classes are file objects (which I use all the time) and thread locks which I almost never use. Yet there are many, many classes in the library whose use would be more elegant and readable if the with statement could be employed. Start with the connection objects in httplib and you can probably come up with 10 others easily. Maybe it is the case that some of these classes have with statement support already but I don't know it? If so, how can I know (without asking here each time, LOL)? If not, is there work being done on that? I am interested in this question mostly in the context of Python 2.6. Many thanks. From subhakolkata1234 at gmail.com Fri Feb 19 03:35:39 2010 From: subhakolkata1234 at gmail.com (joy99) Date: Fri, 19 Feb 2010 00:35:39 -0800 (PST) Subject: Few questions on SOAP References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: On Feb 19, 8:49?am, Steve Holden wrote: > Brendon Wickham wrote: > > On 19 February 2010 08:07, Mark Lawrence wrote: > >> Muhammad Alkarouri wrote: > >>> Your question is borderline if not out of topic in this group. I will > >>> make a few comments though. > >> This might be a Python group, but threads often drift way off topic, which > >> added to the language itself make this a great group to read. ?If you don't > >> like the way a thread goes, you can always skip it. > > > Perhaps...but he answered the question very well and with great, IMO, patience. > > +1 > -- > Steve Holden ? ? ? ? ? +1 571 484 6266 ? +1 800 494 3119 > PyCon is coming! Atlanta, Feb 2010 ?http://us.pycon.org/ > Holden Web LLC ? ? ? ? ? ? ? ?http://www.holdenweb.com/ > UPCOMING EVENTS: ? ? ? ?http://holdenweb.eventbrite.com/ Dear Group, Thank you for taking your time to discuss the issue, esp. to Mohammad for his great patience and solving each aspect in a great way. That's I frequent this group and I just learn lot. If it is bit diverted topic,sorry. Wishing you Happy Day Ahead, Best Regards, Subhabrata. From arnodel at googlemail.com Fri Feb 19 03:36:28 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 19 Feb 2010 08:36:28 +0000 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: Ben Finney writes: > Arnaud Delobelle writes: > >> What about >> foo = iter('') > > That doesn't return a generator. > > >>> foo = iter('') > >>> foo > > > Whether the OP needs to create a generator, or just any iterable type, > isn't clear. If it walks and quacks like a duck... Anyway it's not just an iterable object, it's an iterator. I can't really imagine that there would be some code which would be happy with generators but not with iterators (as long as you can't send anything to them, which is always the case with an empty generator). -- Arnaud From ben+python at benfinney.id.au Fri Feb 19 03:52:47 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 19 Feb 2010 19:52:47 +1100 Subject: How to make an empty generator? References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> Message-ID: <87k4u9a9pc.fsf@benfinney.id.au> Arnaud Delobelle writes: > Ben Finney writes: > > Whether the OP needs to create a generator, or just any iterable > > type, isn't clear. > > If it walks and quacks like a duck... Anyway it's not just an iterable > object, it's an iterator. I can't really imagine that there would be > some code which would be happy with generators but not with iterators > (as long as you can't send anything to them, which is always the case > with an empty generator). I can't imagine that someone would want to create a generator that's always empty, but has some side-effect that is the *real* purpose for using the generator. Clearly, none of us should let our limited imaginations be the guide to what people actually want to do. -- \ ?Generally speaking, the errors in religion are dangerous; | `\ those in philosophy only ridiculous.? ?David Hume, _A Treatise | _o__) of Human Nature_, 1739 | Ben Finney From sschedule at gmail.com Fri Feb 19 03:54:37 2010 From: sschedule at gmail.com (Schedule) Date: Fri, 19 Feb 2010 09:54:37 +0100 Subject: Submit HTTP GET data from XP PC to PHP on web server. Message-ID: Hello everyone I haeve tried to understand the capabilities of python in web development. Have gone throuhg forums and online tutorials. Nevertheless I am not able to find any topic which can give me some insite along with basic examples of how to send http get data from an xp mashine using python code to php on web server. I have some parameters to collect from windows mashine via http get and collect them on web server using php. Any hint how to begin would be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 04:23:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 10:23:53 +0100 Subject: Why this doesn't work? In-Reply-To: References: Message-ID: <4b7e5898$0$12109$426a34cc@news.free.fr> mk a ?crit : > (snip) Sorry, no time to get into details now - but I can at least provide a couple hints. The first point is that, to override a method on an _instance_, you have to provide a method object, not a plain function - remember that the descriptor protocol is only invoked on _class_ attributes, not on instance attributes. class Foo(object): def bar(self): print "the original bar" def mybar(self): print "mybar" >>> f = Foo() >>> f.bar = mybar >>> f.bar() Traceback (most recent call last): File "", line 1, in File "/tmp/python-1287O_i.py", line 32, in f.bar() TypeError: mybar() takes exactly 1 argument (0 given) >>> type(f.bar) >>> f.bar is mybar True >>> f.bar(f) mybar As you see, "bar" is here resolved as an ordinary instance attribute - so here it evals to the "mybar" function object. If you want it to be a method object, you do have to invoke the descriptor protocol manually: >>> f.bar = mybar.__get__(f, type(f)) >>> f.bar > >>> f.bar() mybar Or alternatively, you can use the types module: >>> import types >>> f.bar = types.MethodType(mybar, f, type(f)) >>> f.bar > >>> f.bar() mybar Second point is that the descriptor protocol is invoked on each and every lookup. So when it comes to function class attributes, you get a new method object each time: >>> f = Foo() >>> m1 = f.bar >>> m1 > >>> m2 = f.bar >>> m2 > >>> id(m1) 3084861188L >>> id(m2) 3083656564L >>> m1 is m2 False >>> I think this should help you understand why your code doesn't work as you assumed it would !-) PS : as a side note, a common optimization trick is to "short-circuit" the whole lookup / descriptor mechanism when you have to call the same method of the same object in a loop: l = [] append = l.append for i in xrange(100): append(i) print l HTH From snakylove at googlemail.com Fri Feb 19 04:44:16 2010 From: snakylove at googlemail.com (Snaky Love) Date: Fri, 19 Feb 2010 01:44:16 -0800 (PST) Subject: How to use AWS/PAA nowadays? PyAWS / pyamazon outdated? References: <555ef5e9-dc90-494d-affc-a78389f6922f@g19g2000yqe.googlegroups.com> Message-ID: <74a987e8-2fe1-4109-995f-a0470a2033d7@b7g2000yqd.googlegroups.com> wow, for some strange reason I did not find this with my first search yesterday: http://pypi.python.org/pypi/python-amazon-product-api/0.2.2 I will try this. sometime I wish all the old stuff would disappear from the internet. if somebody is looking for a cool startup idea: what about some website overlay that says "hey, dude, this stuff is old, go here, here is the new and improved thing!" :) thanks for your attention. From anh.hai.trinh at gmail.com Fri Feb 19 05:01:53 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Fri, 19 Feb 2010 02:01:53 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> Message-ID: <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> On Feb 19, 1:44?pm, Steve Howell wrote: > > > def coroutine(co): > > ? ?def _inner(*args, **kwargs): > > ? ? ? ?gen = co(*args, **kwargs) > > ? ? ? ?gen.next() > > ? ? ? ?return gen > > ? ?return _inner > > > def squares_and_cubes(lst, target): > > ? ?for n in lst: > > ? ? ? ?target.send((n * n, n * n * n)) > > > @coroutine > > def reject_bad_values(target): > > ? ?while True: > > ? ? ? ?square, cube = (yield) > > ? ? ? ?if not (square == 25 or cube == 64): > > ? ? ? ? ? ?target.send((square, cube)) > > > @coroutine > > def cubes_only(target): > > ? ?while True: > > ? ? ? ?square, cube = (yield) > > ? ? ? ?target.send(cube) > > > @coroutine > > def print_results(): > > ? ?while True: > > ? ? ? ?print (yield) > > > squares_and_cubes(range(10), > > ? ? ? ?reject_bad_values( > > ? ? ? ? ? ?cubes_only( > > ? ? ? ? ? ? ? ?print_results() > > ? ? ? ? ? ? ? ?) > > ? ? ? ? ? ?) > > ? ? ? ?) > > Wow! ?It took me a while to get my head around it, but that's pretty > cool. This pipeline idea has actually been implemented further, see . from stream import map, filter, cut range(10) >> map(lambda x: [x**2, x**3]) >> filter(lambda t: t[0]! =25 and t[1]!=64) >> cut[1] >> list [0, 1, 8, 27, 216, 343, 512, 729] -- aht From rdv at roalddevries.nl Fri Feb 19 05:30:40 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 19 Feb 2010 11:30:40 +0100 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> Message-ID: <039FC570-3380-4415-B793-C637805DAEF0@roalddevries.nl> On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: > On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov > wrote: >> It seems intuitive to me that the magic methods for overriding the >> +, -, <, ==, >, etc. operators should have no sideffects on their >> operands. Also, that == should be commutative and transitive, that >> > and < should be transitive, and anti-commutative. >> >> Is this intuition written up in a PEP, or assumed to follow from >> the mathematical meanings? > > It may be intuitive to you, but its not true, written down anywhere, > nor assumed by the language, and the mathematical meaning of the > operators doesn't matter to Python. Python purposefully does not > enforce anything for these methods. Still, it's clear that (for example) '==' is not just a normal function call. Look at this example (in ipython): >>> False == False == False True >>> True == False == False False >>> (True == False) == False True Anybody knows how why this is so? From clp2 at rebertia.com Fri Feb 19 05:39:59 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Feb 2010 02:39:59 -0800 Subject: Constraints on __sub__, __eq__, etc. In-Reply-To: <039FC570-3380-4415-B793-C637805DAEF0@roalddevries.nl> References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> <039FC570-3380-4415-B793-C637805DAEF0@roalddevries.nl> Message-ID: <50697b2c1002190239x13f3f051lb69fe674a457aca8@mail.gmail.com> On Fri, Feb 19, 2010 at 2:30 AM, Roald de Vries wrote: > On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: >> On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov >> wrote: >>> >>> It seems intuitive to me that the magic methods for overriding the +, -, >>> <, ==, >, etc. operators should have no sideffects on their operands. Also, >>> that == should be commutative and transitive, that > and < should be >>> transitive, and anti-commutative. >>> >>> Is this intuition written up in a PEP, or assumed to follow from the >>> mathematical meanings? >> >> It may be intuitive to you, but its not true, written down anywhere, nor >> assumed by the language, and the mathematical meaning of the operators >> doesn't matter to Python. Python purposefully does not enforce anything for >> these methods. > > Still, it's clear that (for example) '==' is not just a normal function > call. Look at this example (in ipython): > >>>> False == False == False > True >>>> True == False == False > False >>>> (True == False) == False > True > > Anybody knows how why this is so? Python is smart enough to recognize chained comparisons and do The Right Thing (tm). `X == Y == Z` is equivalent to `X == Y and Y == Z`. Same goes for the other comparison operators besides == and also possibly for longer chains. Cheers, Chris -- http://blog.rebertia.com From wolftracks at invalid.com Fri Feb 19 06:20:08 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 19 Feb 2010 03:20:08 -0800 Subject: The Disappearing Program? Message-ID: I've successfully compiled several small python programs on Win XP into executables using py2exe. A program goes from a name like snowball.py to snowball. A dir in the command prompt window finds snowball.py but not snowball. If I type in snowball, it executes. What's up with that? From __peter__ at web.de Fri Feb 19 06:30:15 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Feb 2010 12:30:15 +0100 Subject: Constraints on __sub__, __eq__, etc. References: <7659cab31002180819y643fd2e4k82952fb49a764582@mail.gmail.com> <7a9c25c21002180828r3774218ehacb12300562cf2c0@mail.gmail.com> Message-ID: Roald de Vries wrote: > On Feb 18, 2010, at 5:28 PM, Stephen Hansen wrote: >> On Thu, Feb 18, 2010 at 8:19 AM, Andrey Fedorov >> wrote: >>> It seems intuitive to me that the magic methods for overriding the >>> +, -, <, ==, >, etc. operators should have no sideffects on their >>> operands. Also, that == should be commutative and transitive, that >>> > and < should be transitive, and anti-commutative. >>> >>> Is this intuition written up in a PEP, or assumed to follow from >>> the mathematical meanings? >> >> It may be intuitive to you, but its not true, written down anywhere, >> nor assumed by the language, and the mathematical meaning of the >> operators doesn't matter to Python. Python purposefully does not >> enforce anything for these methods. > > Still, it's clear that (for example) '==' is not just a normal > function call. Look at this example (in ipython): > > >>> False == False == False > True > >>> True == False == False > False > >>> (True == False) == False > True > > Anybody knows how why this is so? As Chris said expr1 expr2 expr3 ... is resolved as (expr1 expr2) and (expr2 expr3) and (expr3 ... where each exprN is evaluated just once. For this to become the obvious way you have to look at interval checks like a < b < c Peter From sarosh.nust at hotmail.com Fri Feb 19 06:38:22 2010 From: sarosh.nust at hotmail.com (sarosh) Date: Fri, 19 Feb 2010 03:38:22 -0800 (PST) Subject: how to do filetransfer using usrp. Message-ID: <27652452.post@talk.nabble.com> how to do filetransfer using usrp. can i make lan interface between two computers connected to usrp each and then transfer files (images/video) between them? how to transfer files? is there any example of such kind in gnuradio? sarosh -- View this message in context: http://old.nabble.com/how-to-do-filetransfer-using-usrp.-tp27652452p27652452.html Sent from the Python - python-list mailing list archive at Nabble.com. From wuwei23 at gmail.com Fri Feb 19 07:25:14 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 19 Feb 2010 04:25:14 -0800 (PST) Subject: with statement and standard library References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: nobrowser wrote: > Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. ?Start with the connection objects in > httplib and you can probably come up with 10 others easily. ?Maybe it > is the case that some of these classes have with statement support > already but I don't know it? ?If so, how can I know (without asking > here each time, LOL)? ?If not, is there work being done on that? If an object has __enter__ and __exit__ methods, it should work as a context manager. If you do find any such classes, submitting doc bugs or patches would be really handy. However, I'm not sure if there was any attempt to retrofit the stdlib with context manager supports, so if you do come up with more elegant approaches, please contribute them, we'll all thank you :) From andreengels at gmail.com Fri Feb 19 08:04:06 2010 From: andreengels at gmail.com (Andre Engels) Date: Fri, 19 Feb 2010 14:04:06 +0100 Subject: The Disappearing Program? In-Reply-To: References: Message-ID: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wrote: > I've successfully compiled several small python programs on Win XP into > executables using py2exe. A program goes from a name like snowball.py to > snowball. A dir in the command prompt window finds snowball.py but not > snowball. If I type in snowball, it executes. What's up with that? No idea whether it has to do with your problem, but if it's executable in Windows, its name is snowball.exe, not snowball. -- Andr? Engels, andreengels at gmail.com From breamoreboy at yahoo.co.uk Fri Feb 19 09:19:06 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 19 Feb 2010 14:19:06 +0000 Subject: The Disappearing Program? In-Reply-To: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> Message-ID: Andre Engels wrote: > On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson wrote: >> I've successfully compiled several small python programs on Win XP into >> executables using py2exe. A program goes from a name like snowball.py to >> snowball. A dir in the command prompt window finds snowball.py but not >> snowball. If I type in snowball, it executes. What's up with that? > > No idea whether it has to do with your problem, but if it's executable > in Windows, its name is snowball.exe, not snowball. > Not necessarily, it's perfectly possible to setup a Python script to run on Windows using file associations in the same way that you can run a command (.bat) file. If the OP types the command "ASSOC .py" without the quotes at the command prompt, the response .py=Python.File tells you that this association has been setup. HTH. Mark Lawrence. From andreengels at gmail.com Fri Feb 19 09:33:59 2010 From: andreengels at gmail.com (Andre Engels) Date: Fri, 19 Feb 2010 15:33:59 +0100 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> Message-ID: <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence wrote: > Andre Engels wrote: >> >> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson >> wrote: >>> >>> I've successfully compiled several small python programs on Win XP into >>> executables using py2exe. A program goes from a name like snowball.py to >>> snowball. A dir in the command prompt window finds snowball.py but not >>> snowball. If I type in snowball, it executes. What's up with that? >> >> No idea whether it has to do with your problem, but if it's executable >> in Windows, its name is snowball.exe, not snowball. >> > > Not necessarily, it's perfectly possible to setup a Python script to run on > Windows using file associations in the same way that you can run a command > (.bat) file. ?If the OP types the command "ASSOC .py" without the quotes at > the command prompt, the response .py=Python.File tells you > that this association has been setup. And how does that invalidate what I wrote? One cannot associate the empty extension, so if "snowball" runs a program, that's the program in the file "snowball.exe" not the program in the file "snowball" that has its extension associated to something - it has no extension, so its extension cannot be associated. -- Andr? Engels, andreengels at gmail.com From mrkafk at gmail.com Fri Feb 19 09:39:04 2010 From: mrkafk at gmail.com (mk) Date: Fri, 19 Feb 2010 15:39:04 +0100 Subject: Why this doesn't work? In-Reply-To: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> References: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: > >> nostat.__orig_get__ = nostat.__get__ > > I should point out that leading-and-trailing-double-underscore names are > reserved for use by the language. Right... I completely missed that. I will try to change the habit. I am under impression that a function with no underscore in name is meant to be called "publicly" on instance, like Foo().nostat, a function with one underscore (and no trailing underscores) is meant to be like "it's mostly intended for internal use, but you can still call it", somewhat like "protected" in C++, and a function with two leading underscores (and no trailing underscores) is meant as completely internal to the class, not meant to be called by outsiders, somewhat like "private" in C++ (I abstract from obvious point in C++ that semantics of those keywords is enforced by a compiler in C++). Is that correct? Regards, mk From justin.mailinglists at gmail.com Fri Feb 19 09:40:19 2010 From: justin.mailinglists at gmail.com (Justin Ezequiel) Date: Fri, 19 Feb 2010 06:40:19 -0800 (PST) Subject: how to do filetransfer using usrp. References: Message-ID: <83b8c073-7b75-4746-9beb-cea0a5f11eb8@k6g2000prg.googlegroups.com> On Feb 19, 7:38?pm, sarosh wrote: > how to do filetransfer using usrp. > can i make lan interface between two computers connected to usrp each and > then transfer files (images/video) between them? > how to transfer files? > is there any example of such kind in gnuradio? > > sarosh am not sure what USRP is but a quick google found http://packages.debian.org/sid/python-usrp From daniele.gondoni at gmail.com Fri Feb 19 09:41:13 2010 From: daniele.gondoni at gmail.com (Daniele Gondoni) Date: Fri, 19 Feb 2010 06:41:13 -0800 (PST) Subject: What happened to pyjamas? References: <7f014ea61002181044u3391fef9n75fb9f45bec20500@mail.gmail.com> <4b7da919$0$22938$e4fe514c@news.xs4all.nl> Message-ID: <0710f64c-7c38-47fc-85d1-0da13fe62bb8@w31g2000yqk.googlegroups.com> On Feb 18, 9:53?pm, Irmen de Jong wrote: > On 2/18/10 9:45 PM, Luis M. Gonz?lez wrote: > > > On Feb 18, 5:21 pm, Daniele Gondoni ?wrote: > >> On 18 Feb, 19:58, "sstein... at gmail.com" ?wrote: > > >>> Down from here (NH, US). > > >>> S > > >>> On Feb 18, 2010, at 1:44 PM, Chris Colbert wrote: > > >> Unreacheable from Italy as well... > > > Same here (Buenos Aires, Argentina). > > It ain't down till Netcraft confirms it! > > http://uptime.netcraft.com/up/graph?site=www.pyjs.org > > Oh wait... > > -irmen my goodness! it seems only the domain has expired the site's still there, just add 216.34.181.97 pyjs.org to your hosts file and BANG From goon12 at gmail.com Fri Feb 19 09:43:52 2010 From: goon12 at gmail.com (Joe Riopel) Date: Fri, 19 Feb 2010 09:43:52 -0500 Subject: Submit HTTP GET data from XP PC to PHP on web server. In-Reply-To: References: Message-ID: <6a2ccd191002190643n18c990a5qc1333a362dcc4484@mail.gmail.com> On Fri, Feb 19, 2010 at 3:54 AM, Schedule wrote: > Hello everyone > > I haeve tried to understand the capabilities of python in web development. > Have gone throuhg forums and online tutorials. Nevertheless I am not able to > find any topic which can give me some insite along with basic examples of > how to send http get data from an xp mashine using python code to php on web > server. Have a look at urllib2 (urllib2.Request) and maybe mechanize (http://wwwsearch.sourceforge.net/mechanize/). From funthyme at gmail.com Fri Feb 19 09:43:56 2010 From: funthyme at gmail.com (John Pinner) Date: Fri, 19 Feb 2010 06:43:56 -0800 (PST) Subject: What happened to pyjamas? Message-ID: <6a8e506c-63df-482b-a39d-148e6217ba2c@o3g2000yqb.googlegroups.com> It appears that, in trying to cut down spm, somone chahnged a DNS entry and screwed it up : it shouldbe back before long. John -- From mrkafk at gmail.com Fri Feb 19 09:45:12 2010 From: mrkafk at gmail.com (mk) Date: Fri, 19 Feb 2010 15:45:12 +0100 Subject: Why this doesn't work? In-Reply-To: <4B7DD3D6.9030403@optimum.net> References: <4B7DD3D6.9030403@optimum.net> Message-ID: John Posner wrote: >> a >> False >> >> I expected to see 'nostatget' output: nostat.__get__ = nostatget >> obviously failed to replace this function's __get__ method. > > I don't quite understand the above sentence, so I'm assuming that you > wanted the final "is" test to be "True" instead of "False". No. I should have described my goal in plain English in first place. I wanted to replace nostat function's __get__ descriptor with a function that would allow me to peek inside it (i.e. into __get__ descriptor arguments) and that would then call original nostat.__get__. So no, I expected it to be false, that is, I expected to replace original descriptor with a "custom" descriptor. I just wondered why this custom "nostatget" descriptor didn't get called even though the new nostat.__get__ didn't seem to be its old self (so quite likely it was the new, nostatget, descriptor). But Bruno pointed out that I need instancemethod for that, not plain function. Regards, mk From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 10:01:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 16:01:53 +0100 Subject: Why this doesn't work? In-Reply-To: References: <4b7dba1e$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7ea7ce$0$15611$426a74cc@news.free.fr> mk a ?crit : > Steven D'Aprano wrote: >> On Thu, 18 Feb 2010 18:28:44 +0100, mk wrote: >> >>> nostat.__orig_get__ = nostat.__get__ >> >> I should point out that leading-and-trailing-double-underscore names >> are reserved for use by the language. > > Right... I completely missed that. I will try to change the habit. > > I am under impression that a function with no underscore in name is > meant to be called "publicly" on instance, like Foo().nostat, a function > with one underscore (and no trailing underscores) is meant to be like > "it's mostly intended for internal use, but you can still call it", > somewhat like "protected" in C++, and a function with two leading > underscores (and no trailing underscores) is meant as completely > internal to the class, not meant to be called by outsiders, somewhat > like "private" in C++ (I abstract from obvious point in C++ that > semantics of those keywords is enforced by a compiler in C++). > > Is that correct? Mostly, yes. - s/function/whatever/ : these rules apply to all names - the single leading underscore denote implementation, IOW : you should not use it, unless you have a pretty good reason to do so AND you take full responsability for what may happens - the double leading underscore is in fact mostly to protect your attribute from accidental overloading. It triggers a (simple) name-mangling operation that turns "__yourname" into "_Yourclassname__yourname". FWIW, this is something I must have a use for at most once a year, and even then most of the times because I'm a bit of a control freak sometimes. From pedro.al at fenhi.uh.cu Fri Feb 19 10:08:06 2010 From: pedro.al at fenhi.uh.cu (Yasser Almeida =?iso-8859-1?b?SGVybuFuZGV6?=) Date: Fri, 19 Feb 2010 10:08:06 -0500 Subject: Attributes in privates methods Message-ID: <20100219100806.gm1qqhaisk48ookw@correo.fenhi.uh.cu> Hi all. I have a class with the attribute 'log_file', opened out of the class: class ProteinCluster: def __init__(self,cluster_name,log_file): ... self.log_file = log_file ... Then i have a private method which write in the log_file: def _read_structure(self, pdb_code): ... ... self.log_file.write('blablabla') ... ... When i run the script, it raises the error: AttributeError: ProteinCluster instance has no attribute 'log_file' My question is, the class attributes are valids in private methods, like in publics methods? Thanks -- Yasser Almeida Hern?ndez, BSc Center of Molecular Inmunology (CIM) Nanobiology Group P.O.Box 16040, Havana, Cuba Phone: (537) 214-3178 almeida at cim.sld.cu ---------------------------------------------------------------- Correo FENHI From breamoreboy at yahoo.co.uk Fri Feb 19 10:16:20 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 19 Feb 2010 15:16:20 +0000 Subject: The Disappearing Program? In-Reply-To: <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: Andre Engels wrote: > On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence wrote: >> Andre Engels wrote: >>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson >>> wrote: >>>> I've successfully compiled several small python programs on Win XP into >>>> executables using py2exe. A program goes from a name like snowball.py to >>>> snowball. A dir in the command prompt window finds snowball.py but not >>>> snowball. If I type in snowball, it executes. What's up with that? >>> No idea whether it has to do with your problem, but if it's executable >>> in Windows, its name is snowball.exe, not snowball. >>> >> Not necessarily, it's perfectly possible to setup a Python script to run on >> Windows using file associations in the same way that you can run a command >> (.bat) file. If the OP types the command "ASSOC .py" without the quotes at >> the command prompt, the response .py=Python.File tells you >> that this association has been setup. > > And how does that invalidate what I wrote? One cannot associate the > empty extension, so if "snowball" runs a program, that's the program > in the file "snowball.exe" not the program in the file "snowball" that > has its extension associated to something - it has no extension, so > its extension cannot be associated. > Darn, only half the story, sorry. When the OP types snowball something executes. The command SET PATHEXT will show what file extensions are set to run files. On my system the response is :- c:\Users\Mark\Java2Python>set pathext PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY So snowball with any one of the 12 extensions listed above would run on my system without actually typing the extension. I'm just guessing but has an executable been created but in another directory, so snowball.py is running? Perhaps the best bet is simply to search appropriate directories, or even the whole hard drive, for snowball.*. Then the OP would know exactly what he has or hasn't got. HTH. Mark Lawrence From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 10:17:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 16:17:30 +0100 Subject: Why this doesn't work? In-Reply-To: References: <4B7DD3D6.9030403@optimum.net> Message-ID: <4b7eab77$0$31722$426a34cc@news.free.fr> mk a ?crit : > John Posner wrote: >>> a >>> False >>> >>> I expected to see 'nostatget' output: nostat.__get__ = nostatget >>> obviously failed to replace this function's __get__ method. >> >> I don't quite understand the above sentence, so I'm assuming that you >> wanted the final "is" test to be "True" instead of "False". > > No. I should have described my goal in plain English in first place. > > I wanted to replace nostat function's __get__ descriptor A "descriptor" (shortcut for "object implementing the descriptor protocol) is an object that have a __get__ method - not the __get__ method itself. A function is a descriptor. The __get__ method of the function type is a method, and methods are not descriptors. > with a function > that would allow me to peek inside it (i.e. into __get__ descriptor > arguments) => __get__(self, instance, cls=None) When called as a result of a look up on an instance f of class Foo, nostat.__get__ will get (nostat, f, Foo) as args. > So no, I expected it to be false, that is, I expected to replace > original descriptor with a "custom" descriptor. s/descriptor/__get__/ Anyway: these types (function, method etc) are implemented in (higly optimized) C, and with a lot of restriction for both performance and sanity reasons. It's a case of practicality beats purity. Another - perhaps more rewarding - exercise might be to implement a custom callable type that implements the descriptor protocol the same way the function do. From deets at nospam.web.de Fri Feb 19 10:21:51 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 19 Feb 2010 16:21:51 +0100 Subject: Attributes in privates methods In-Reply-To: References: Message-ID: <4B7EAC8F.3040001@nospam.web.de> Am 19.02.10 16:08, schrieb Yasser Almeida Hern?ndez: > Hi all. > > I have a class with the attribute 'log_file', opened out of the class: > class ProteinCluster: > def __init__(self,cluster_name,log_file): > ... > self.log_file = log_file > ... > Then i have a private method which write in the log_file: > def _read_structure(self, pdb_code): > ... > ... > self.log_file.write('blablabla') > ... > ... > When i run the script, it raises the error: > AttributeError: ProteinCluster instance has no attribute 'log_file' > > My question is, the class attributes are valids in private methods, like > in publics methods? There is no semantical difference there, you must have some other error. Diez From rdv at roalddevries.nl Fri Feb 19 10:50:41 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 19 Feb 2010 16:50:41 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> Message-ID: <950E783F-50F5-42B9-845F-0D85B927B3E8@roalddevries.nl> > This pipeline idea has actually been implemented further, see blog.onideas.ws/stream.py>. > > from stream import map, filter, cut > range(10) >> map(lambda x: [x**2, x**3]) >> filter(lambda t: t[0]! > =25 and t[1]!=64) >> cut[1] >> list > [0, 1, 8, 27, 216, 343, 512, 729] Wow, cool! Just to show that you can easily add the iterator.map(f).blabla-syntax to Python: from __future__ import print_function class rubified(list): map = lambda self, f: rubified(map(f, self)) filter = lambda self, f: rubified(filter(f, self)) reject = lambda self, f: rubified(filter(lambda x: not f(x), self)) # each = lambda self, f: rubified(reduce(lambda x, y: print(y), self, None)) def each(self, f): for x in self: f(x) def __new__(cls, value): return list.__new__(cls, value) def print_numbers(): rubified([1, 2, 3, 4, 5, 6]).map(lambda n: [n * n, n * n * n]).reject(lambda (square, cube): square == 25 or cube == 64).map(lambda (square, cube): cube).each(lambda n: print(n)) From robert.kern at gmail.com Fri Feb 19 10:51:54 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 09:51:54 -0600 Subject: How to make an empty generator? In-Reply-To: <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-19 00:21 AM, Steven D'Aprano wrote: > On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: > >>>> What's the point of the wheel spinning? Did I miss something? >>> >>> I wonder whether it's for some kind of framework with a main loop like >>> >>> for it in list_of_iterables: >>> for x in it: >>> do_this_or_that (x) >>> >>> where, every once in a while one wants to throw some arbitrary code >>> into the process, in the form of an empty iterable with side effects. >> >> Yes. That is exactly what the OP said in his original post: >> >> """ >> I have some generators that do stuff, then start yielding results. On >> occasion, I don't want them to yield anything ever-- they're only really >> "generators" because I want to call them /as/ a generator as part of a >> generalized system. """ > > But he doesn't say anything about side-effects. "I have some generators *that do stuff*, then start yielding results." [emphasis mine]. Then he gives an example of a generator that does side-effect stuff and returning before yielding anything. -- 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 wimmersimon at googlemail.com Fri Feb 19 10:52:59 2010 From: wimmersimon at googlemail.com (SiWi) Date: Fri, 19 Feb 2010 07:52:59 -0800 (PST) Subject: Executing Python code on another computer Message-ID: Hello community, I googled for an answer of the following problem, but I couldn't find anything. I've got a netbook and my fast workstation compter, which I usually use for developing. But I'd also like to take my netbook around the house and to develop Python programms on it. The problem is that naturally a netbook is not the fastest computer you could find. So I wondered if it was possible to send the Python code I'm developing on the netbook to the workstation pc via wlan, let the script execute on the workstation pc and write the output back on the netbook. Is there any possibilty to achieve that goal? From robert.kern at gmail.com Fri Feb 19 11:00:45 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 10:00:45 -0600 Subject: How to make an empty generator? In-Reply-To: <87ocjlaeu7.fsf@benfinney.id.au> References: <7a9c25c21002181425wa4cab4aq1c230b40f69b89ca@mail.gmail.com> <877hqaazmb.fsf@benfinney.id.au> <0e36c303-2b70-41e2-9773-42be3076ff18@k19g2000yqc.googlegroups.com> <871vgiawub.fsf@benfinney.id.au> <87ocjlaeu7.fsf@benfinney.id.au> Message-ID: On 2010-02-19 01:01 AM, Ben Finney wrote: > Robert Kern writes: > >> On 2010-02-18 18:33 PM, Ben Finney wrote: >>> Robert Kern writes: >>> >>>> He doesn't want *any* empty generator. He wants an iterator that >>>> executes some given side-effect-producing code then immediately >>>> raises the StopIteration. >>> >>> Ah, hm. That's a rather perverse use case, but I'm sure the OP has their >>> reasons. >> >> Which he explained fairly clearly, I thought, in his original post. > > (The original post isn't available to me; the reference in your reply > isn't accessible AFAICT.) You responded to my post which quoted his in full. > In the part of the original that you quoted, he speaks only of empty > generators (easy and clean), not generators that exist only for the > purpose of side-effects without yielding any items. """ I have some generators *that do stuff*, then start yielding results. On occasion, I don't want them to yield anything ever-- they're only really "generators" because I want to call them /as/ a generator as part of a generalized system. ... def gen(): # *do my one-time processing here* return yield """ [emphasis mine] Seriously, it's all there. I'm rather appalled at the lack of reading comprehension demonstrated in this thread. > It's that latter that I describe as perverse, and I would think it worth > some effort to determine if that can be avoided by a different approach. By rearchitecting the system to accept things that aren't iterators, yes. But he may not be in control of that system. And it may not make things cleaner to do so if he wants to use itertools to compose the iterables, whether they are for side effects or not, in various ways. -- 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 btaylordesign at gmail.com Fri Feb 19 11:05:10 2010 From: btaylordesign at gmail.com (Brandon) Date: Fri, 19 Feb 2010 08:05:10 -0800 (PST) Subject: Question about getmtime Message-ID: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Hi everyone, Does copying or moving a file affect the return value of os.path.getmtime(path)? Thank you, Brandon From robert.kern at gmail.com Fri Feb 19 11:06:10 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 19 Feb 2010 10:06:10 -0600 Subject: with statement and standard library In-Reply-To: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: On 2010-02-19 01:18 AM, nobrowser wrote: > Hi. The with statement is certainly nifty. The trouble is, the > *only* two documented examples how it can be used with the library > classes are file objects (which I use all the time) and thread locks > which I almost never use. Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. Start with the connection objects in > httplib and you can probably come up with 10 others easily. Yup. I believe that the devs wanted to adopt the new feature carefully and deliberately, though. They introduced it for file objects and locks first because those were the use cases that had been thoroughly explored in the development of the PEP. They held back from making every reasonable object a context manager in order to see how the new feature worked in the real world with those two use cases first. Now is probably a good time to start adding more sensible context managers to objects. I don't think there is any particular organized effort to do so, though. -- 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 darcy at druid.net Fri Feb 19 11:10:21 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Feb 2010 11:10:21 -0500 Subject: Executing Python code on another computer In-Reply-To: References: Message-ID: <20100219111021.42fddabb.darcy@druid.net> On Fri, 19 Feb 2010 07:52:59 -0800 (PST) SiWi wrote: > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? Yes but it isn't really a Python question. I suggest Google but you haven't given us enough information, particularly what OSs you are running. If it was me I would simply use the netbook as a thin client for programs that I am writing and running on the main server. In my case a simple xterm would do the job since vi is my IDE and bash is my runtime environment. If you are using a GUI IDE you may be able to run the GUI app on the server with the display on the netbook. -- 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 krister.svanlund at gmail.com Fri Feb 19 11:14:43 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 19 Feb 2010 17:14:43 +0100 Subject: Executing Python code on another computer In-Reply-To: References: Message-ID: <2cf430a61002190814x65804212ic0bd111972ac1aa0@mail.gmail.com> On Fri, Feb 19, 2010 at 4:52 PM, SiWi wrote: > Hello community, > I googled for an answer of the following problem, but I couldn't find > anything. > I've got a netbook and my fast workstation compter, which I usually > use for developing. > But I'd also like to take my netbook around the house and to develop > Python programms on it. > The problem is that naturally a netbook is not the fastest computer > you could find. > > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? > -- > http://mail.python.org/mailman/listinfo/python-list > I recommend setting up a SSH server on your stationary and run something like emacs. It's how I'm doing it anyway. From bornstub at gmail.com Fri Feb 19 11:16:09 2010 From: bornstub at gmail.com (Victor Lin) Date: Fri, 19 Feb 2010 08:16:09 -0800 (PST) Subject: A tool for find dependencies relationships behind Python projects Message-ID: Hi, I just wrote a tool for drawing dependencies relationships diagram of Python project on Pypi. Here is the home page of the tool: http://code.google.com/p/python-gluttony/ Some examples: Sprox: http://static.ez2learn.com/gluttony/sprox_dot.png TurboGears2: http://static.ez2learn.com/gluttony/tg2_dot.png Hope this could be helpful :P Regards. Victor Lin. From george.trojan at noaa.gov Fri Feb 19 11:25:34 2010 From: george.trojan at noaa.gov (George Trojan) Date: Fri, 19 Feb 2010 16:25:34 +0000 Subject: a question on building MySQL-python Message-ID: During installation of MySQL-python-1.2.3c1 I encountered the following error: $ python2.6 setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdb running build_ext building '_mysql' extension creating build/temp.linux-x86_64-2.6 gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/include/mysql -I/usr/local/Python-2.6.3/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv gcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -L. -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-x86_64-2.6/_mysql.so /usr/bin/ld: cannot find -lpython2.6 collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 Linker could not find libpython2.6.so. Note that the compiler *did* find Python include file: -I/usr/local/Python-2.6.3/include/python2.6. I am running CentOS5.3. Python 2.6 was configured as follows: $ TARGET=/usr/local/Python-2.6.3 $ export LDFLAGS=-Wl,-rpath,$TARGET/lib $ ./configure --prefix=$TARGET \ --with-cxx=g++ --with-threads --enable-shared to avoid messing with LD_LIBRARY_PATH. I managed to complete the installation by pasting the above link command and adding proper -L option, but I would like to know what would be the proper fix. George From krister.svanlund at gmail.com Fri Feb 19 11:26:20 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Fri, 19 Feb 2010 17:26:20 +0100 Subject: Question about getmtime In-Reply-To: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <2cf430a61002190826x380e2d29k585b127432001c34@mail.gmail.com> On Fri, Feb 19, 2010 at 5:05 PM, Brandon wrote: > Hi everyone, > > Does copying or moving a file affect the return value of > os.path.getmtime(path)? > > Thank you, > Brandon Wouldn't it be easier to make a script and see for yourself then to write a mail about it? From bruno.42.desthuilliers at websiteburo.invalid Fri Feb 19 11:26:53 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Fri, 19 Feb 2010 17:26:53 +0100 Subject: Attributes in privates methods In-Reply-To: References: Message-ID: <4b7ebbba$0$10159$426a34cc@news.free.fr> Yasser Almeida Hern?ndez a ?crit : > Hi all. > > I have a class with the attribute 'log_file', opened out of the class: > class ProteinCluster: > def __init__(self,cluster_name,log_file): > ... > self.log_file = log_file > ... > Then i have a private method which write in the log_file: > def _read_structure(self, pdb_code): > ... > ... > self.log_file.write('blablabla') > ... > ... > When i run the script, it raises the error: > AttributeError: ProteinCluster instance has no attribute 'log_file' > > My question is, the class attributes are valids in private methods, like > in publics methods? Diez already answered - the above code seems correct, so the source of your problem is elsewhere. For the record, in your code, log_file is an instance attribute - a 'class attribute' is an attribute that is defined on the class object itself, and is shared by all instances of the class. Also, Python has no notion of "public" or "private" - at least at the language level. The '_name' convention is just, well, a naming convention. This wont solve your problem - sorry, not much we can do here - but at least it will help wrt/ mutual understanding !-) From arnodel at googlemail.com Fri Feb 19 11:28:15 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 19 Feb 2010 08:28:15 -0800 (PST) Subject: Executing Python code on another computer References: Message-ID: <2cfe4b91-ca53-427e-8c74-8eb7e859f01b@i39g2000yqm.googlegroups.com> On 19 Feb, 15:52, SiWi wrote: > Hello community, > I googled for an answer of the following problem, but I couldn't find > anything. > I've got a netbook and my fast workstation compter, which I usually > use for developing. > But I'd also like to take my netbook around the house and to develop > Python programms on it. > The problem is that naturally a netbook is not the fastest computer > you could find. > > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? There are plenty of ways to do this - but they are not really related to Python. What is most convenient for you will probably depend on the tools that you are used to using, your operating system and your level of expertise with configuring network services. On mac and linux it is very easy to set up an ssh server on your workstation. You can then edit your files remotely - the method might be different depending on your operating system, unless you use something like Emacs - and also execute them remotely. -- Arnaud From james.harris.1 at googlemail.com Fri Feb 19 11:29:06 2010 From: james.harris.1 at googlemail.com (James Harris) Date: Fri, 19 Feb 2010 08:29:06 -0800 (PST) Subject: Executing Python code on another computer References: Message-ID: On 19 Feb, 15:52, SiWi wrote: > Hello community, > I googled for an answer of the following problem, but I couldn't find > anything. > I've got a netbook and my fast workstation compter, which I usually > use for developing. > But I'd also like to take my netbook around the house and to develop > Python programms on it. > The problem is that naturally a netbook is not the fastest computer > you could find. > > So I wondered if it was possible to send the Python code I'm > developing on the netbook to the workstation pc via wlan, let the > script execute on the workstation pc and write the output back on the > netbook. > > Is there any possibilty to achieve that goal? Yes. Assuming you can cope with the relatively small netbook screen here are some options: 1. Telnet (ok within a home and where no graphics needed) 2. Ssh (ok where no graphics needed) 3. An X-Windows server on your netbook (ok under Linux but good Windows X Servers may be limited or nonexistent) 4. VNC (e.g. RealVnc) to get a remote view of the workstation's screen. I use telnet and RealVnc for purposes similar to those you describe. James From btaylordesign at gmail.com Fri Feb 19 11:30:48 2010 From: btaylordesign at gmail.com (Brandon) Date: Fri, 19 Feb 2010 08:30:48 -0800 (PST) Subject: Question about getmtime References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <00c30abd-e240-4ffc-9df7-30fbf573b3ad@y33g2000yqb.googlegroups.com> On Feb 19, 10:26?am, Krister Svanlund wrote: > On Fri, Feb 19, 2010 at 5:05 PM, Brandon wrote: > > Hi everyone, > > > Does copying or moving a file affect the return value of > > os.path.getmtime(path)? > > > Thank you, > > Brandon > > Wouldn't it be easier to make a script and see for yourself then to > write a mail about it? Gee, thanks for the help. I guess. From wimmersimon at googlemail.com Fri Feb 19 11:32:48 2010 From: wimmersimon at googlemail.com (SiWi) Date: Fri, 19 Feb 2010 08:32:48 -0800 (PST) Subject: Executing Python code on another computer References: Message-ID: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> On Feb 19, 5:10?pm, "D'Arcy J.M. Cain" wrote: > On Fri, 19 Feb 2010 07:52:59 -0800 (PST) > > SiWi wrote: > > So I wondered if it was possible to send the Python code I'm > > developing on the netbook to the workstation pc via wlan, let the > > script execute on the workstation pc and write the output back on the > > netbook. > > > Is there any possibilty to achieve that goal? > > Yes but it isn't really a Python question. ?I suggest Google but you > haven't given us enough information, particularly what OSs you are > running. ?If it was me I would simply use the netbook as a thin client > for programs that I am writing and running on the main server. ?In my > case a simple xterm would do the job since vi is my IDE and bash is my > runtime environment. ?If you are using a GUI IDE you may be able to run > the GUI app on the server with the display on the netbook. > > -- > D'Arcy J.M. Cain ? ? ? ? | ?Democracy is three wolveshttp://www.druid.net/darcy/? ? ? ? ? ? ? ?| ?and a sheep voting on > +1 416 425 1212 ? ? (DoD#0082) ? ?(eNTP) ? | ?what's for dinner. I'm normally using IDLE and sometimes PyScripter on Windows Vista. The netbook is Windows XP. Should I switch to Vim or Emacs? From showell30 at yahoo.com Fri Feb 19 11:32:53 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 19 Feb 2010 08:32:53 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> Message-ID: On Feb 19, 7:50?am, Roald de Vries wrote: > > This pipeline idea has actually been implemented further, see > blog.onideas.ws/stream.py>. > > > from stream import map, filter, cut > > range(10) >> map(lambda x: [x**2, x**3]) >> filter(lambda t: t[0]! > > =25 and t[1]!=64) >> cut[1] >> list > > [0, 1, 8, 27, 216, 343, 512, 729] > > Wow, cool! > > Just to show that you can easily add the iterator.map(f).blabla-syntax ? > to Python: > > ? ? ?from __future__ import print_function > > ? ? ?class rubified(list): > ? ? ? ? ?map ? ?= lambda self, f: rubified(map(f, self)) > ? ? ? ? ?filter = lambda self, f: rubified(filter(f, self)) > ? ? ? ? ?reject = lambda self, f: rubified(filter(lambda x: not f(x), ? > self)) > ? ? ? ? ?# each = lambda self, f: rubified(reduce(lambda x, y: ? > print(y), self, None)) > ? ? ? ? ?def each(self, f): > ? ? ? ? ? ? ?for x in self: f(x) > > ? ? ? ? ?def __new__(cls, value): > ? ? ? ? ? ? ?return list.__new__(cls, value) > > ? ? ?def print_numbers(): > ? ? ? ? ?rubified([1, 2, 3, 4, 5, 6]).map(lambda n: > ? ? ? ? ? ? ?[n * n, n * n * n]).reject(lambda (square, cube): > ? ? ? ? ? ? ?square == 25 or cube == 64).map(lambda (square, cube): > ? ? ? ? ? ? ?cube).each(lambda n: > ? ? ? ? ? ? ?print(n)) Sure, that definitely achieves the overall sequential structure of operations that I like in Ruby. A couple other example have been posted as well now, which also mimic something akin to a Unix pipeline. A lot of Ruby that I see gets spelled like this: list.select { |arg1, arg2| expr }.reject { |arg| expr }.collect { |arg} expr } With your class you can translate into Python as follows: list.select(lambda arg1, arg2: expr ).reject(lambda arg: expr ).collect(lambda arg: expr ) So for chaining transformations based on filters, the difference really just comes down to syntax (and how much sugar is built into the core library). The extra expressiveness of Ruby comes from the fact that you can add statements within the block, which I find useful sometimes just for debugging purposes: debug = true data = strange_dataset_from_third_party_code() data.each { |arg| if debug and arg > 10000 puts arg end # square the values arg * arg } From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 12:21:03 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 17:21:03 GMT Subject: How to make an empty generator? References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: > On 2010-02-19 00:21 AM, Steven D'Aprano wrote: >> On Fri, 19 Feb 2010 00:15:20 -0600, Robert Kern wrote: >> >>>>> What's the point of the wheel spinning? Did I miss something? >>>> >>>> I wonder whether it's for some kind of framework with a main loop >>>> like >>>> >>>> for it in list_of_iterables: >>>> for x in it: >>>> do_this_or_that (x) >>>> >>>> where, every once in a while one wants to throw some arbitrary code >>>> into the process, in the form of an empty iterable with side effects. >>> >>> Yes. That is exactly what the OP said in his original post: >>> >>> """ >>> I have some generators that do stuff, then start yielding results. On >>> occasion, I don't want them to yield anything ever-- they're only >>> really "generators" because I want to call them /as/ a generator as >>> part of a generalized system. """ >> >> But he doesn't say anything about side-effects. > > "I have some generators *that do stuff*, then start yielding results." > [emphasis mine]. What does "do stuff" have to do with side-effects? Here's a generator that does stuff, and it has no side-effects. def generator_that_does_stuff(x): y = 3*x**2 - 5*x + 1 yield y "Do stuff" is ambiguous -- it could mean stuff with side-effects, or stuff without. The first is potentially harmful, the second is pointless. > Then he gives an example of a generator that does > side-effect stuff and returning before yielding anything. Unfortunately the OP's original post isn't visible to me, so I can only respond to your post, which may or may not quote the entire original post. The only example I have seen was an empty generator with a comment saying "do my one-time processing here", with *no* indication of what that one- time processing is supposed to be, why it is necessary, and whether it has side-effects or not. Since the OP (apparently) hasn't seen fit to comment, we're still all guessing what he means. It's certainly possible, likely even, that he's using generators that operate by side-effect: that explanation is consistent with his request. Personally, I can't imagine that would be good coding practice, but I could be wrong. -- Steven From wolftracks at invalid.com Fri Feb 19 12:21:24 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 19 Feb 2010 09:21:24 -0800 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On 2/19/2010 7:16 AM, Mark Lawrence wrote: > Andre Engels wrote: >> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence >> wrote: >>> Andre Engels wrote: >>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson ... tories, or even the whole hard drive, for snowball.*. Then the OP > would know exactly what he has or hasn't got. > > HTH. > > Mark Lawrence > Here's the answer. Consider this folder. Afolder abc.py hello.py I now apply py2exe steps to produce an "executable" for abc. The folder now changes to Afolder build dist abc.py hello.py build are two new folders. dist contains abc.exe. Somehow when I type abc at the command prompt, this follows a path to dist, and finds abc.exe, where it executes properly. Cute, eh? I have no explanation for it. I have no idea what build is for, but dist contains a bunch of other files that possible apply to doing this with other files in the Afolder. hello.py maybe. The details seem to be shrouded. Possible a Google might provide a full explanation. From darcy at druid.net Fri Feb 19 12:22:43 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 19 Feb 2010 12:22:43 -0500 Subject: Executing Python code on another computer In-Reply-To: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> Message-ID: <20100219122243.13051024.darcy@druid.net> On Fri, 19 Feb 2010 08:32:48 -0800 (PST) SiWi wrote: > I'm normally using IDLE and sometimes PyScripter on Windows Vista. The > netbook is Windows XP. Should I switch to Vim or Emacs? Umm... Yes? It's still not a Python question and is in fact a religious one. Other people have different religions. You should probably ask this question on a list dedicated to using Windows. What you want to know is how to run programs remotely. The fact that it is a Python program is irrelevant. I'm not trying to brush you off. I'm just trying to point you somewhere that can answer your question better. -- 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 Fri Feb 19 12:30:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 19 Feb 2010 17:30:42 GMT Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> Message-ID: <4b7ecac2$0$8819$c3e8da3@news.astraweb.com> On Fri, 19 Feb 2010 08:32:53 -0800, Steve Howell wrote: > The extra expressiveness of Ruby comes from the fact that you can add > statements within the block, which I find useful sometimes just for > debugging purposes: > > debug = true > data = strange_dataset_from_third_party_code() > data.each { |arg| > if debug and arg > 10000 > puts arg > end > # square the values > arg * arg > } How is that different from this? debug = true data = strange_dataset_from_third_party_code() for i, arg in enumerate(data): if debug and arg > 10000 print arg # square the values data[i] = arg * arg I don't see the extra expressiveness. What I see is that the Ruby snippet takes more lines (even excluding the final brace), and makes things implicit which in my opinion should be explicit. But since I'm no Ruby expert, perhaps I'm misreading it. -- Steven From tjreedy at udel.edu Fri Feb 19 12:41:10 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Feb 2010 12:41:10 -0500 Subject: with statement and standard library In-Reply-To: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: On 2/19/2010 2:18 AM, nobrowser wrote: > Hi. The with statement is certainly nifty. The trouble is, the > *only* two documented examples how it can be used with the library > classes are file objects (which I use all the time) and thread locks > which I almost never use. Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. Start with the connection objects in > httplib and you can probably come up with 10 others easily. Maybe it > is the case that some of these classes have with statement support > already but I don't know it? If so, how can I know (without asking > here each time, LOL)? If not, is there work being done on that? > I am interested in this question mostly in the context of Python 2.6. 2.6 is in maintenance mode only; no new features. 2.7 will be so when released in June and effectively so in a month when the first beta is released. 3.2 is a reasonable target. tjr From apt.shansen at gmail.com Fri Feb 19 12:44:16 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 19 Feb 2010 09:44:16 -0800 Subject: How to make an empty generator? In-Reply-To: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> On Fri, Feb 19, 2010 at 9:21 AM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > On Fri, 19 Feb 2010 09:51:54 -0600, Robert Kern wrote: > >> But he doesn't say anything about side-effects. > > > > "I have some generators *that do stuff*, then start yielding results." > > [emphasis mine]. > > What does "do stuff" have to do with side-effects? Here's a generator > that does stuff, and it has no side-effects. > > def generator_that_does_stuff(x): > y = 3*x**2 - 5*x + 1 > yield y > > "Do stuff" is ambiguous -- it could mean stuff with side-effects, or > stuff without. The first is potentially harmful, the second is pointless. What does it matter what *do stuff* means? My point is, there's *stuff* I need to do there, and what that stuff is really has absolutely nothing to do with the issue at hand. Its certainly a side-effect, at least in terms of the generator, otherwise there would be no point really in having the generator there at all. I have a system that consumes generators which, almost always, yield over objects to be handled. One in ten-- nay, one in 20, if not worse-- cases has me wanting to inject into this system some arbitrary code that gets run. Some bit of processing I need to get done in the context of that cycle. There's nothing harmful about it. These aren't generic generators that are going to be passed around and consumed by random things or anything else. They exist solely to be consumed by the core system. They're never composed or loaded by anything else, its just the API of how the system works. It loads bunches of modules dynamically, each module has a generator for yielding objects to be consumed. That generator is the one and only line of connection between the core system and the modules. > > Then he gives an example of a generator that does > > side-effect stuff and returning before yielding anything. > > Unfortunately the OP's original post isn't visible to me, so I can only > respond to your post, which may or may not quote the entire original post. > > The only example I have seen was an empty generator with a comment saying > "do my one-time processing here", with *no* indication of what that one- > time processing is supposed to be, why it is necessary, and whether it > has side-effects or not. > It doesn't matter what the one-time processing is supposed to be. I could say, "This particular module doesn't yield objects like all the rest, but instead just needs to override a certain utility function the system uses, to change how name equality is handled so that tests compare on normalized forms. The API for integrating into the the core system -- to be loaded as a module and integrated into the system -- is to have a generator of a certain name, which yields N objects. In this case, N = 0.". Now, having said that, why in the world does that matter at all to my question? :) It changes no part of anyone's possible solution, be it Robert's once-wrapped-to-decorator, to Holden's just-comment-the-oddity, to your empty-for-loop-yield, to any others. It doesn't *matter* what the processing has to be. And if it has side-effects or not is only relevant to the question of the perversity of my use-case, a discussion I just don't really even have any interest in =) Thanks, all, though, for your responses and solutions. Much to my embarrassment, sometime last night I realized I was being a complete idiot, and the 'correct' way to handle this in my scenario is really just: def initialize(): # do one time processing here return [] A generator is just a callable that returns an iterator, after all. If I don't want to yield anything, returning an empty iterable accomplishes the same goal to get the code loaded and run by the host-cycle while contributing nothing at all to the object pool. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 12:50:19 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 17:50:19 +0000 Subject: best way to create a dict from string In-Reply-To: References: Message-ID: <4B7ECF5B.9090900@mrabarnett.plus.com> Tim Arnold wrote: > Hi, > I've got some text to parse that looks like this > > text = ''' blah blah blah > \Template[Name=RAD,LMRB=False,LMRG=True]{tables} > ho dee ho > ''' If you're going to include backslashes in the string literal then use a raw string for safety. > I want to extract the bit between the brackets and create a dictionary. > Here's what I'm doing now: > > def options(text): > d = dict() > options = text[text.find('[')+1:text.find(']')] > for k,v in [val.split('=') for val in options.split(',')]: > d[k] = v > return d > 1. I'd check whether there's actually a template. 2. 'dict' will accept a list of key/value pairs. def options(text): start = text.find('[') end = text.find(']', start) if start == -1 or end == -1: return {} options = text[start + 1 : end] return dict(val.split('=') for val in options.split(',')) > if __name__ == '__main__': > for line in text.split('\n'): > if line.startswith('\\Template'): > print options(line) > > > is that the best way or maybe there's something simpler? The options will > always be key=value format, comma separated. > thanks, > From showell30 at yahoo.com Fri Feb 19 12:56:15 2010 From: showell30 at yahoo.com (Steve Howell) Date: Fri, 19 Feb 2010 09:56:15 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <79220dd0-3d91-47c1-84d1-5bf1760d9cef@q2g2000pre.googlegroups.com> <5a9d7518-778e-40e6-9448-ae9115c3fb6e@c34g2000pri.googlegroups.com> <4b7ecac2$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 19, 9:30?am, Steven D'Aprano wrote: > On Fri, 19 Feb 2010 08:32:53 -0800, Steve Howell wrote: > > The extra expressiveness of Ruby comes from the fact that you can add > > statements within the block, which I find useful sometimes just for > > debugging purposes: > > > ? ? debug = true > > ? ? data = strange_dataset_from_third_party_code() > > ? ? data.each { |arg| > > ? ? ? ? if debug and arg > 10000 > > ? ? ? ? ? ? puts arg > > ? ? ? ? end > > ? ? ? ? # square the values > > ? ? ? ? arg * arg > > ? ? } > > How is that different from this? > > debug = true > data = strange_dataset_from_third_party_code() > for i, arg in enumerate(data): > ? ? if debug and arg > 10000 > ? ? ? ? print arg > ? ? # square the values > ? ? data[i] = arg * arg > > I don't see the extra expressiveness. What I see is that the Ruby snippet > takes more lines (even excluding the final brace), and makes things > implicit which in my opinion should be explicit. But since I'm no Ruby > expert, perhaps I'm misreading it. > You are reading the example out of context. Can you re-read the part you snipped? The small piece of code can obviously be written imperatively, but the point of the example was not to print a bunch of squares. From python at mrabarnett.plus.com Fri Feb 19 13:06:40 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 18:06:40 +0000 Subject: Question about getmtime In-Reply-To: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <4B7ED330.4050308@mrabarnett.plus.com> Brandon wrote: > Hi everyone, > > Does copying or moving a file affect the return value of > os.path.getmtime(path)? > The modification time of a copied file should be the same as the original. The creation time of a copied file will be the time at which it was copied, so that can result in the paradoxical state of a file having been modified _before_ it was created! :-) From vincent at vincentdavis.net Fri Feb 19 13:22:09 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 19 Feb 2010 11:22:09 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() Message-ID: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> I have some some (~50) text files that have about 250,000 rows each. I am reading them in using the following which gets me what I want. But it is not fast. Is there something I am missing that should help. This is mostly an question to help me learn more about python. It takes about 4 min right now. def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') read = list(reader) data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in read]) data = [x for x in data_rows][1:] mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) mask = [row for row in mask_rows if row][3:] outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) outlier = [row for row in outlier_rows if row][3:] *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn -------------- next part -------------- An HTML attachment was scrubbed... URL: From chrisprinos at gmail.com Fri Feb 19 13:23:43 2010 From: chrisprinos at gmail.com (Chris Prinos) Date: Fri, 19 Feb 2010 10:23:43 -0800 (PST) Subject: Replacement for e.message() in python 2.6 References: <0PKdnTVryZFJIObWnZ2dnUVZ_jidnZ2d@westnet.com.au> Message-ID: <4017a5bb-ea1f-4aa8-b80f-95b6a938aaed@k19g2000yqc.googlegroups.com> On Feb 17, 4:58?am, Nandakumar Chandrasekhar wrote: > Dear Folks, > > In previous versions of Python I used to use e.message() to print out > the error message of an exception like so: > > try: > ? ? ? ? result = x / y > except ZeroDivisionError, e: > ? ? ? ? print e.message() > > Unfortunately in Python 2.6 the message method is deprecated. > > Is there any replacement for the message method in Python 2.6 or is > there any best practice that should be used in Python from now on? > > Thank you. > > Yours sincerely, > Nanda try: ? ? ? ? result = x / y except ZeroDivisionError as e: ? ? ? ? print e Note different syntax using "except ... as ..." e.message is deprecated here, but e.args[0] contains the same thing. see http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3110 and http://www.python.org/dev/peps/pep-3110/ chris From steve.l.cohen at gmail.com Fri Feb 19 13:35:56 2010 From: steve.l.cohen at gmail.com (Steven Cohen) Date: Fri, 19 Feb 2010 12:35:56 -0600 Subject: Trouble running pywin32-214.win-amd64-py3.1 on 64-bit Windows 7 Message-ID: <5cf1aff91002191035o7c65df3bjfb4f26805923ea0d@mail.gmail.com> Hello, I downloaded pywin32-214.win-amd64-py3.1, and it installs just fine (except that it prints a traceback when it tells me the postinstall script completed), but then when I try to execute Pythonwin.exe, I get the following error popup: The application can not locate win32ui.pyd (or Python) (126) The specified module could not be found However, the file win32ui.pyd is right there in the same directory from which I am executing Pythonwin.exe. Can anyone help me figure out what I am doing wrong here? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 19 13:52:16 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 19 Feb 2010 19:52:16 +0100 Subject: Executing Python code on another computer In-Reply-To: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> Message-ID: <4B7EDDE0.6000000@sequans.com> SiWi wrote: > On Feb 19, 5:10 pm, "D'Arcy J.M. Cain" wrote: > >> On Fri, 19 Feb 2010 07:52:59 -0800 (PST) >> >> SiWi wrote: >> >>> So I wondered if it was possible to send the Python code I'm >>> developing on the netbook to the workstation pc via wlan, let the >>> script execute on the workstation pc and write the output back on the >>> netbook. >>> >>> Is there any possibilty to achieve that goal? >>> >> Yes but it isn't really a Python question. I suggest Google but you >> haven't given us enough information, particularly what OSs you are >> running. If it was me I would simply use the netbook as a thin client >> for programs that I am writing and running on the main server. In my >> case a simple xterm would do the job since vi is my IDE and bash is my >> runtime environment. If you are using a GUI IDE you may be able to run >> the GUI app on the server with the display on the netbook. >> >> -- >> D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on >> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. >> > > I'm normally using IDLE and sometimes PyScripter on Windows Vista. The > netbook is Windows XP. Should I switch to Vim or Emacs? > Vista supports rdesktop , you could use it. I don't know if XP is shipped with a rdesktop client though (goggle for remote desktop). JM From cmpython at gmail.com Fri Feb 19 13:56:37 2010 From: cmpython at gmail.com (CM) Date: Fri, 19 Feb 2010 10:56:37 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On Feb 19, 12:21?pm, "W. eWatson" wrote: > On 2/19/2010 7:16 AM, Mark Lawrence wrote:> Andre Engels wrote: > >> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence > >> wrote: > >>> Andre Engels wrote: > >>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson > > ... > tories, or even the whole hard drive, for snowball.*. Then the OP> would know exactly what he has or hasn't got. > > > HTH. > > > Mark Lawrence > > Here's the answer. Consider this folder. > > Afolder > ? ?abc.py > ? ?hello.py > > I now apply py2exe steps to produce an ?"executable" for abc. The folder > now changes to > > Afolder > ? ?build > ? ?dist > ? ?abc.py > ? ?hello.py > > build are two new folders. dist contains abc.exe. > > Somehow when I type abc at the command prompt, this follows a path to > dist, and finds abc.exe, where it executes properly. > Cute, eh? I have no explanation for it. Are you sure it's executing abc.exe? If you are at a Python command prompt within the "DOS shell" and you just type just abc, I think what is happening is you are running abc.py, NOT abc.exe. py2exe creates a dist folder (short for "distributables") by default and puts your .exe into it along with whatever other files are needed to run your application. Depending on how you set the bundling options, this may be a lot of things or just 1-2 other things. Che From davea at ieee.org Fri Feb 19 14:02:28 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Feb 2010 14:02:28 -0500 Subject: Question about getmtime In-Reply-To: <00c30abd-e240-4ffc-9df7-30fbf573b3ad@y33g2000yqb.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> <00c30abd-e240-4ffc-9df7-30fbf573b3ad@y33g2000yqb.googlegroups.com> Message-ID: <4B7EE044.2080804@ieee.org> Brandon wrote: > On Feb 19, 10:26 am, Krister Svanlund > wrote: > >> On Fri, Feb 19, 2010 at 5:05 PM, Brandon wrote: >> >>> Hi everyone, >>> >>> Does copying or moving a file affect the return value of >>> os.path.getmtime(path)? >>> >>> Thank you, >>> Brandon >>> >> Wouldn't it be easier to make a script and see for yourself then to >> write a mail about it? >> > > Gee, thanks for the help. I guess. > > Well, copying the file won't affect the getmtime, since it's still there, and unmodified. Moving it will cause the getmtime to to get an os.error, because the file no longer exists. Probably you mean you're adjusting the path variable to point to the new location for the file. But the answer is still "it depends." How about if you get more specific? If you write a copy utility using two opens, a read() and a write(), then the new file will certainly get a new timestamp unless you do something to prevent it. If you copy the file from a DOS box in Windows XP, using the COPY command, then the getmtime on the new file will be identical to the one on the old. If you do it on an Amiga using pip, I have no idea. Perhaps you're writing a copy/move utility of your own, and you want to know how to cause a new file to have the same attributes as the original. If so, be more specific. DaveA From davea at ieee.org Fri Feb 19 14:04:16 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 19 Feb 2010 14:04:16 -0500 Subject: Executing Python code on another computer In-Reply-To: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> Message-ID: <4B7EE0B0.5080605@ieee.org> SiWi wrote: > On Feb 19, 5:10 pm, "D'Arcy J.M. Cain" wrote: > >> On Fri, 19 Feb 2010 07:52:59 -0800 (PST) >> >> SiWi wrote: >> >>> So I wondered if it was possible to send the Python code I'm >>> developing on the netbook to the workstation pc via wlan, let the >>> script execute on the workstation pc and write the output back on the >>> netbook. >>> >>> Is there any possibilty to achieve that goal? >>> >> Yes but it isn't really a Python question. I suggest Google but you >> haven't given us enough information, particularly what OSs you are >> running. If it was me I would simply use the netbook as a thin client >> for programs that I am writing and running on the main server. In my >> case a simple xterm would do the job since vi is my IDE and bash is my >> runtime environment. If you are using a GUI IDE you may be able to run >> the GUI app on the server with the display on the netbook. >> >> -- >> D'Arcy J.M. Cain | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on >> +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. >> > > I'm normally using IDLE and sometimes PyScripter on Windows Vista. The > netbook is Windows XP. Should I switch to Vim or Emacs? > > In that case, consider using RemoveDesktop, which is built into both Xp and Vista. DaveA From misceverything at gmail.com Fri Feb 19 14:08:53 2010 From: misceverything at gmail.com (T) Date: Fri, 19 Feb 2010 11:08:53 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> On Feb 18, 7:19?pm, Ryan Kelly wrote: > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > I have a Python app which I converted to an EXE (all files separate; > > single EXE didn't work properly) via py2exe - I plan on distributing > > this and would like the ability to remotely upgrade the program (for > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > be the best way to go about doing this? > > I've been working on an auto-update framework for my own frozen apps, > you might find it useful: > > ?http://pypi.python.org/pypi/esky > > Docs are a little scarce at the moment, the next release will hopefully > come with a short tutorial (as well as support for cx_freeze and maybe > py2app, depending on how adventurous I'm feeling). > > ? Cheers, > > ? ? ?Ryan > > -- > Ryan Kellyhttp://www.rfk.id.au?| ?This message is digitally signed. Please visit > r... at rfk.id.au ? ? ? ?| ?http://www.rfk.id.au/ramblings/gpg/for details > > ?signature.asc > < 1KViewDownload Thanks Ryan..this looks like it could be what I'm looking for, but I'm still a bit unsure of how exactly how it works. Do you happen to have an idea approx when the next release w/ tutorial will be out? From tjreedy at udel.edu Fri Feb 19 14:25:21 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Feb 2010 14:25:21 -0500 Subject: How to make an empty generator? In-Reply-To: <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: On 2/19/2010 12:44 PM, Stephen Hansen wrote: > Much to my embarrassment, sometime last night I realized I was being a > complete idiot, and the 'correct' way to handle this in my scenario is > really just: > > def initialize(): > # do one time processing here > > return [] > > A generator is just a callable that returns an iterator, after all. Confusing generators and generator functions is, well, confusing. For future reference, and clarity of communication in Pythonland, generator function: function that produces a generator when called; if python coded, its body contains 'yield'. generator: iterator produced by a generator function; has .__next__ and self-returning .__init__, like all other iterators. generator expression: an expression that evaluates to a generator; the expression is used to create a temporary anonymous generator function that is called to produce the generator and is then discarded. >>> def gf(): yield 1 >>> gf >>> g=gf() >>> g >>> ge = (1 for i in [1]) >>> ge at 0x00F5BFD0> >>> dir(ge) [..., '__iter__', ..., '__next__', ...] So, when you said that you send 'generators' to your core system, when you meant 'generator functions', we were understanably confused. (Your core system should accept iterator classes also, unless it specifically checks to avoid duck typing.) Terry Jan Reedy From anfedorov at gmail.com Fri Feb 19 14:47:50 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Fri, 19 Feb 2010 14:47:50 -0500 Subject: Chaining 501 generators breaks everything? Message-ID: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> I implemented a Sieve of Eratosthenesprimes algorithm using generators: http://gist.github.com/309109 This code which chains together 500 generators works fine (~1/20th of a second) on my laptop. The code which chaines 501 generators (s/498/499/ on line 23) doesn't seem to finish. Does anyone know the reason for this, or can anyone point me where to look for a good explanation? Cheers, Andrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From anfedorov at gmail.com Fri Feb 19 14:57:03 2010 From: anfedorov at gmail.com (Andrey Fedorov) Date: Fri, 19 Feb 2010 14:57:03 -0500 Subject: Chaining 501 generators breaks everything? In-Reply-To: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> References: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> Message-ID: <7659cab31002191157m498a1de7l1087b930682bd991@mail.gmail.com> Ack, just ran it from shell, realized my editor was just choking on a "maximum recursion depth exceeded" RuntimeError. Didn't realize generators used the call stack... - Andrey On Fri, Feb 19, 2010 at 2:47 PM, Andrey Fedorov wrote: > I implemented a Sieve of Eratosthenesprimes algorithm using generators: > > http://gist.github.com/309109 > > > This code which chains together 500 generators works fine (~1/20th of a > second) on my laptop. The code which chaines 501 generators (s/498/499/ on > line 23) doesn't seem to finish. > > Does anyone know the reason for this, or can anyone point me where to look > for a good explanation? > > Cheers, > Andrey > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 15:02:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 20:02:10 +0000 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> Message-ID: <4B7EEE42.6090806@mrabarnett.plus.com> Vincent Davis wrote: > I have some some (~50) text files that have about 250,000 rows each. I > am reading them in using the following which gets me what I want. But it > is not fast. Is there something I am missing that should help. This is > mostly an question to help me learn more about python. It takes about 4 > min right now. > > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > read = list(reader) > data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x > in read]) 'takewhile' accepts an iterable, so "[x for x in read]" can be simplified to "read". > data = [x for x in data_rows][1:] > data = data_rows[1:] > mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, > list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) > mask = [row for row in mask_rows if row][3:] > No need to convert the result of 'dropwhile' to list. > outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) > outlier = [row for row in outlier_rows if row][3:] > The problem, as I see it, is that you're scanning the rows more than once. Is this any better? def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') data = [] for row in reader: if '[MASKS]' in row: break data.append(row) data = data[1:] mask = [] if '[MASKS]' in row: mask.append(row) for row in reader: if '[OUTLIERS]' in row: break if row: mask.append(row) mask = mask[3:] outlier = [] if '[OUTLIERS]' in row: outlier.append(row) outliter.extend(row for row in outlier if row) outlier = outlier[3:] From jjposner at optimum.net Fri Feb 19 15:16:05 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 19 Feb 2010 15:16:05 -0500 Subject: How to make an empty generator? In-Reply-To: References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: <4B7EF185.1040702@optimum.net> On 2/19/2010 2:25 PM, Terry Reedy wrote: > On 2/19/2010 12:44 PM, Stephen Hansen wrote: > >> Much to my embarrassment, sometime last night I realized I was being a >> complete idiot, and the 'correct' way to handle this in my scenario is >> really just: >> >> def initialize(): >> # do one time processing here >> >> return [] >> >> A generator is just a callable that returns an iterator, after all. > > Confusing generators and generator functions is, well, confusing. > For future reference, and clarity of communication in Pythonland, > > generator function: function that produces a generator when called; if > python coded, its body contains 'yield'. > > generator: iterator produced by a generator function; I suggest: iterator produced by a generator function or a generator expression; has .__next__ and > self-returning .__init__, like all other iterators. > > generator expression: an expression that evaluates to a generator; the > expression is used to create a temporary anonymous generator function > that is called to produce the generator and is then discarded. Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms to Terry's definitions above in most places. But the Glossary says: generator A function which returns an iterator. <... more ...> generator expression An expression that returns a generator. <... more ...> The additional verbiage in these definitions mitigates the damage, but I think the first entry should be headlined *generator function* instead of *generator*. And the Glossary should include Terry's additional entry [ as amended by me :-) ]: generator An iterator produced by a generator function or a generator expression. -John From jjposner at optimum.net Fri Feb 19 16:00:30 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 19 Feb 2010 16:00:30 -0500 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> Message-ID: <4B7EFBEE.1030808@optimum.net> On 2/19/2010 3:02 PM, MRAB wrote: > Is this any better? > > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > data = [] > for row in reader: > if '[MASKS]' in row: > break > data.append(row) As noted in another thread recently, you can save time by *not* looking up the "append" method of the list object each time through the FOR loop: data = [] app_method = data.append for row in reader: if '[MASKS]' in row: break app_method(row) Similarly in the rest of the code. This technique improved performance about 31% in this test: #-------------------- import timeit tt = timeit.repeat("for i in xrange(1000000): mylist.append(i)", "mylist=[]", number=25) print "look up append() method each time:", min(tt) tt = timeit.repeat("for i in xrange(1000000): app(i)", "mylist=[]; app = mylist.append", number=25) print "look up append() method just once:", min(tt) #-------------------- output: look up append() method each time: 8.45481741783 look up append() method just once: 5.84429637887 -John From jgardner at jonathangardner.net Fri Feb 19 16:13:09 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 13:13:09 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> Message-ID: <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> On Fri, Feb 19, 2010 at 10:22 AM, Vincent Davis wrote: > I have some some (~50) text files that have about 250,000 rows each. I am > reading them in using the following which gets me what I want. But it is not > fast. Is there something I am missing that should help. This is mostly an > question to help me learn more about python. It takes about 4 min right now. > > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > read = list(reader) > You're slurping the entire file here when it's not necessary. > data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in > read]) > [x for x in read] is basically a copy of the entire list. This isn't necessary. > data = [x for x in data_rows][1:] > > Again, copying here is unnecessary. [x for x in y] isn't a paradigm in Python. If you really need a copy of an array, x = y[:] is the paradigm. > mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, > list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) > > mask = [row for row in mask_rows if row][3:] > Here's another unnecessary array copy. > > outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, read) > outlier = [row for row in outlier_rows if row][3:] > And another. Just because you're using Python doesn't mean you get to be silly in how you move data around. Avoid copies as much as possible, and try to avoid slurping in large files all at once. Line-by-line processing is best. I think you should invert this operation into a for loop. Most people tend to think of things better that way than chained iterators. It also helps you to not duplicate data when it's unnecessary. -- Jonathan Gardner jgardner at jonathangardner.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From ryan at rfk.id.au Fri Feb 19 16:28:37 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 20 Feb 2010 08:28:37 +1100 Subject: Upgrading Py2exe App In-Reply-To: <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: <1266614917.2495.34.camel@rambutan> On Thu, 2010-02-18 at 20:32 -0800, CM wrote: > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > I have a Python app which I converted to an EXE (all files separate; > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > this and would like the ability to remotely upgrade the program (for > > > example, via HTTP/HTTPS). Looks like it's not just the EXE that I > > > will need need to replace (DLLs, the library.zip, etc.). What would > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > you might find it useful: > > > > http://pypi.python.org/pypi/esky > > > > > This looks pretty interesting and useful. Thanks :-) > Just to help me understand it a bit more: what is it that users will > download from some web page in order to initially get the py2exe'd app > on their system? Is it "really" an "esky", with the app's .exe file > inside it (but the esky is named the same as the app)? Currently, it's just a zip file with the frozen app in it, which the user unzips to wherever they want the app. When unzipped it looks like this: myapp.exe <-- actually the esky bootstrap exe myapp-X.Y.Z.win32/ myapp.exe <-- the actual frozen app as produced by py2exe python26.dll ...etc... This could easily be wrapped in an installer - the important thing is just that the files end up on the user's machine in the expected directory structure. > And then when > they want to update, the app's code calls the esky class to do the > work of swapping out the appropriate .exe file? Something like this? Yes. The idea of having a "bootstrapping exe" is that actual application code can be swapped out without having to overwrite the executable file. As long as you don't change python versions, this allows updates to be safe against system crashes, even on platforms without atomic file replacement. So the frozen app does this in a background thread: Esky(sys.executable,"http://my.updates.com").auto_update() And it hits the given url, grabs the latest zipfile, downloads and unpacks and atomically places it into the application directory. Et viola, your app is at the latest version. From the packager's point of view, you run the "bdist_esky" distutils command to generate the zipfile containing your latest version, then simply upload it to your server. > Would this also work if one used InnoSetup to install the exe on the > user's system? Yes, absolutely - in fact I plan to do this myself at some stage. All that's required is that the files end up in the expected directory structure. 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From ryan at rfk.id.au Fri Feb 19 16:32:16 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Sat, 20 Feb 2010 08:32:16 +1100 Subject: Upgrading Py2exe App In-Reply-To: <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> Message-ID: <1266615136.2495.39.camel@rambutan> On Fri, 2010-02-19 at 11:08 -0800, T wrote: > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > I have a Python app which I converted to an EXE (all files separate; > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > this and would like the ability to remotely upgrade the program (for > > > example, via HTTP/HTTPS). Looks like it's not just the EXE that I > > > will need need to replace (DLLs, the library.zip, etc.). What would > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > you might find it useful: > > > > http://pypi.python.org/pypi/esky > > > > Docs are a little scarce at the moment, the next release will hopefully > > come with a short tutorial (as well as support for cx_freeze and maybe > > py2app, depending on how adventurous I'm feeling). > > > Thanks Ryan..this looks like it could be what I'm looking for, but I'm > still a bit unsure of how exactly how it works. Do you happen to have > an idea approx when the next release w/ tutorial will be out? If I punt on the py2app support, I should be able to get it done in the next 3-4 days. I'll send a quick email to python-list when it's ready. Here's a rough roadmap of where the project is heading: v0.4.0: cx_freeze support and a tutorial [the next 3-4 days] v0.4.1: py2app support [the next 2-3 weeks] v0.5.0: differential updates using bsdiff [next few months] 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From wolftracks at invalid.com Fri Feb 19 16:42:55 2010 From: wolftracks at invalid.com (W. eWatson) Date: Fri, 19 Feb 2010 13:42:55 -0800 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On 2/19/2010 10:56 AM, CM wrote: > On Feb 19, 12:21 pm, "W. eWatson" wrote: >> On 2/19/2010 7:16 AM, Mark Lawrence wrote:> Andre Engels wrote: >>>> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence >>>> wrote: >>>>> Andre Engels wrote: >>>>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson >> >> ... >> tories, or even the whole hard drive, for snowball.*. Then the OP> would know exactly what he has or hasn't got. >> >>> HTH. >> >>> Mark Lawrence >> >> Here's the answer. Consider this folder. >> >> Afolder >> abc.py >> hello.py >> >> I now apply py2exe steps to produce an "executable" for abc. The folder >> now changes to >> >> Afolder >> build >> dist >> abc.py >> hello.py >> >> build are two new folders. dist contains abc.exe. >> >> Somehow when I type abc at the command prompt, this follows a path to >> dist, and finds abc.exe, where it executes properly. >> Cute, eh? I have no explanation for it. > > Are you sure it's executing abc.exe? If you are at a Python command > prompt within the "DOS shell" and you just type just abc, I think what > is happening is you are running abc.py, NOT abc.exe. > > py2exe creates a dist folder (short for "distributables") by default > and puts your .exe into it along with whatever other files are needed > to run your application. Depending on how you set the bundling > options, this may be a lot of things or just 1-2 other things. > > Che Well, you are right. What proof do I have? In fact, I just tried to run a program that was not converted, and left off py. It worked. So maybe the only way to execute the compiled code is to to to dist? From jgardner at jonathangardner.net Fri Feb 19 16:47:46 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 13:47:46 -0800 Subject: Chaining 501 generators breaks everything? In-Reply-To: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> References: <7659cab31002191147jb219150l944eab28447e1126@mail.gmail.com> Message-ID: <6cc20cea1002191347n7a48a231ic4d65ad020296b54@mail.gmail.com> On Fri, Feb 19, 2010 at 11:47 AM, Andrey Fedorov wrote: > I implemented a?Sieve of Eratosthenes primes algorithm using generators: > > http://gist.github.com/309109 > > This code which chains together 500 generators works fine (~1/20th of a > second) on my laptop. > You may want a more traditional approach. Until Python gets tail recursion (doubtful), this won't work very well on any platform. #!/usr/bin/env python from itertools import islice, count from time import time def primes(): seen = [] for i in count(2): for s in seen: if i%s == 0: break else: # Run if the for loop doesn't break seen.append(i) yield i start = time() for i in islice(primes(), 0, 10000): print i print time() - start -- Jonathan Gardner jgardner at jonathangardner.net From mattbarkan at gmail.com Fri Feb 19 16:48:47 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 13:48:47 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) Message-ID: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Hey all, I've been working on a program that accesses my school's password protected website and downloads directory names. I'm using mechanize. Recently, the program has been unable to open the website, returning the 'errno 61 connection refused' error. I presume the school's server was blocking me because of many automated logins. However, it turns out that I cannot now open ANY url from within Python on my computer using mechanize (or urllib for that matter). And I've tried in several places -- my place, a friend's place (who also has comcast as an ISP) and the school -- but no dice, constant errno 61's whenever I try to open a url. The strangest thing about this is that firefox still works flawlessly on any site. However, at my friend's place, I was able to open url's from HIS computer, no problem. Can anyone think of anything I can do to solve this problem? Why would firefox be working fine but not Python? Any suggestions would be greatly appreciated. Matt From apt.shansen at gmail.com Fri Feb 19 16:52:57 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Fri, 19 Feb 2010 13:52:57 -0800 Subject: The Disappearing Program? In-Reply-To: References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: <7a9c25c21002191352v3dcfb04fm4a332a6f773f047e@mail.gmail.com> On Fri, Feb 19, 2010 at 1:42 PM, W. eWatson wrote: > >> Well, you are right. What proof do I have? In fact, I just tried to run a > program that was not converted, and left off py. It worked. > > So maybe the only way to execute the compiled code is to to to dist? Yes. You're meant to move everything in "dist" to where you want to run it, that's the point of the dist folder-- its what you distribute. THe .exe and the other stuff next to it the .exe needs to run. --S -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Fri Feb 19 16:58:41 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 19 Feb 2010 14:58:41 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> Message-ID: <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> In reference to the several comments about "[x for x in read] is basically a copy of the entire list. This isn't necessary." or list(read). I had thought I had a problem with having iterators in the takewhile() statement. I thought I testes and it didn't work. It seems I was wrong. It clearly works. I'll make this change and see if it is any better. I actually don't plan to read them all in at once, only as needed, but I do need the whole file in an array to perform some mathematics on them and compare different files. So my interest was in making it faster to open them as needed. I guess part of it is that they are about 5mb so I guess it might be disk speed in part. Thanks *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Fri, Feb 19, 2010 at 2:13 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Fri, Feb 19, 2010 at 10:22 AM, Vincent Davis wrote: > >> I have some some (~50) text files that have about 250,000 rows each. I am >> reading them in using the following which gets me what I want. But it is not >> fast. Is there something I am missing that should help. This is mostly an >> question to help me learn more about python. It takes about 4 min right now. >> >> def read_data_file(filename): >> reader = csv.reader(open(filename, "U"),delimiter='\t') >> read = list(reader) >> > > You're slurping the entire file here when it's not necessary. > > >> data_rows = takewhile(lambda trow: '[MASKS]' not in trow, [x for x in >> read]) >> > > [x for x in read] is basically a copy of the entire list. This isn't > necessary. > > >> data = [x for x in data_rows][1:] >> >> > > Again, copying here is unnecessary. > > [x for x in y] isn't a paradigm in Python. If you really need a copy of an > array, x = y[:] is the paradigm. > > >> mask_rows = takewhile(lambda trow: '[OUTLIERS]' not in trow, >> list(dropwhile(lambda drow: '[MASKS]' not in drow, read))) >> > > > > > >> mask = [row for row in mask_rows if row][3:] >> > > Here's another unnecessary array copy. > > >> >> outlier_rows = dropwhile(lambda drows: '[OUTLIERS]' not in drows, >> read) >> outlier = [row for row in outlier_rows if row][3:] >> > > > And another. > > Just because you're using Python doesn't mean you get to be silly in how > you move data around. Avoid copies as much as possible, and try to avoid > slurping in large files all at once. Line-by-line processing is best. > > I think you should invert this operation into a for loop. Most people tend > to think of things better that way than chained iterators. It also helps you > to not duplicate data when it's unnecessary. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Fri Feb 19 17:00:03 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 14:00:03 -0800 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: <6cc20cea1002191400j33f4735cl9809b40b5f189777@mail.gmail.com> On Fri, Feb 19, 2010 at 1:48 PM, MattB wrote: > > I've been working on a program that accesses my school's password > protected website and downloads directory names. I'm using mechanize. > > Recently, the program has been unable to open the website, returning > the 'errno 61 connection refused' error. I presume the school's server > was blocking me because of many automated logins. > > However, it turns out that I cannot now open ANY url from within > Python on my computer using mechanize (or urllib for that matter). > And I've tried in several places -- my place, a friend's place (who > also has comcast as an ISP) and the school -- but no dice, constant > errno 61's whenever I try to open a url. > > The strangest thing about this is that firefox still works flawlessly > on any site. > > However, at my friend's place, I was able to open url's from HIS > computer, no problem. > > Can anyone think of anything I can do to solve this problem? Why would > firefox be working fine but not Python? > > Any suggestions would be greatly appreciated. > Are you running behind a firewall? See if Firefox is configured with a proxy. You'll have to use that to talk to any website. -- Jonathan Gardner jgardner at jonathangardner.net From lie.1296 at gmail.com Fri Feb 19 17:05:04 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 09:05:04 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <741ae84b-a33e-4ea6-b1e5-0035ff862bdf@a18g2000yqc.googlegroups.com> Message-ID: <4b7f0b2c$1@dnews.tpgi.com.au> On 02/19/10 14:57, Steve Howell wrote: > In a more real world example, the intermediate results would be > something like this: > > departments > departments_in_new_york > departments_in_new_york_not_on_bonus_cycle > employees_in_departments_in_new_york_not_on_bonus_cycle > names_of_employee_in_departments_in_new_york_not_on_bonus_cycle > I fare better, in less than ten-seconds thinking: departments eligible_departments eligible_departments eligible_employees eligible_employee_names as a bonus, they would be much more resilient when there are change of eligibility requirements. Names doesn't have to exactly describe what's in it; in fact, if your names is way too descriptive, it may take significantly more brain-cycle to parse. A good name abstracts the objects contained in it. From half.italian at gmail.com Fri Feb 19 17:09:56 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Fri, 19 Feb 2010 14:09:56 -0800 (PST) Subject: Question about getmtime References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> Message-ID: <2f56a4b1-4f2b-4ec9-827b-e6d4e5d52f7d@v20g2000prb.googlegroups.com> On Feb 19, 10:06?am, MRAB wrote: > Brandon wrote: > > Hi everyone, > > > Does copying or moving a file affect the return value of > > os.path.getmtime(path)? > > The modification time of a copied file should be the same as the > original. > > The creation time of a copied file will be the time at which it was > copied, so that can result in the paradoxical state of a file having > been modified _before_ it was created! :-) ctime does not stand for creation time. I went through this a couple of months ago. It's updated whenever the inode is updated, so changing permissions, among other things will update it. It blew me away when I finally found this out. ~Sean From clp2 at rebertia.com Fri Feb 19 17:12:21 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Feb 2010 14:12:21 -0800 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: <50697b2c1002191412u43d6cbd0off090f987e82d61@mail.gmail.com> On Fri, Feb 19, 2010 at 1:48 PM, MattB wrote: > Hey all, > > I've been working on a program that accesses my school's password > protected website and downloads directory names. I'm using mechanize. > > Recently, the program has been unable to open the website, returning > the 'errno 61 connection refused' error. I presume the school's server > was blocking me because of many automated logins. > > However, it turns out that I cannot now open ANY url from within > Python on my computer using mechanize (or urllib for that matter). > And I've tried in several places -- my place, a friend's place (who > also has comcast as an ISP) and the school -- but no dice, constant > errno 61's whenever I try to open a url. > > The strangest thing about this is that firefox still works flawlessly > on any site. > Can anyone think of anything I can do to solve this problem? Why would > firefox be working fine but not Python? > > Any suggestions would be greatly appreciated. Based on what you've said, it's possible the school may have blocked mechanize's User-Agent somehow. Try spoofing mechanize as Firefox by setting the string for the User-Agent header to that of Firefox. See the section "Changing the automatically-added headers (User-Agent)" on http://wwwsearch.sourceforge.net/mechanize/doc.html for how to do that. To see what Firefox's User-Agent is, use http://whatsmyuseragent.com/ Cheers, Chris -- Disclaimer: This is not meant to in any way endorse violating AUPs. http://blog.rebertia.com From bret.clement at gmail.com Fri Feb 19 17:18:18 2010 From: bret.clement at gmail.com (Bret) Date: Fri, 19 Feb 2010 14:18:18 -0800 (PST) Subject: ActiveState/O'Reilly Launch New and Improved Code Share Site (Python) Message-ID: ActiveState launched today the new code.activestate.com with code recipes for dynamic languages such as Python, Perl and Tcl and web development. This site is great recipe sharing site for all Python, Perl and Tcl developers. O'Reilly will be use recipes from the site for its next Python cook book. Bit.ly link to the blog announcement: http://bit.ly/b1Wkdm From martin.hellwig at dcuktec.org Fri Feb 19 18:02:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Fri, 19 Feb 2010 23:02:34 +0000 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: On 02/19/10 21:48, MattB wrote: > Hey all, > > I've been working on a program that accesses my school's password > protected website and downloads directory names. I'm using mechanize. > > Recently, the program has been unable to open the website, returning > the 'errno 61 connection refused' error. I presume the school's server > was blocking me because of many automated logins. Being a former school BOFH, I can assure you that if I was annoyed by your 'misuse' I would have tracked you down and made you aware of it. > > However, it turns out that I cannot now open ANY url from within > Python on my computer using mechanize (or urllib for that matter). > And I've tried in several places -- my place, a friend's place (who > also has comcast as an ISP) and the school -- but no dice, constant > errno 61's whenever I try to open a url. As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > The strangest thing about this is that firefox still works flawlessly > on any site. Your system might have been centrally configure so that applications are aware of the proxy, firefox probably has been piggybacking on those settings (as it should). Most platforms can be made aware of a proxy by a DHCP option send by the DHCP server (that is when you automatically get an IP address). > Any suggestions would be greatly appreciated. > > Matt Google a bit around how you can figure out (from inside your script) whether your used platform has a proxy configured and how to use it with your application. Good luck! -- mph From jg07024 at gmail.com Fri Feb 19 18:16:35 2010 From: jg07024 at gmail.com (John Graves) Date: Fri, 19 Feb 2010 15:16:35 -0800 (PST) Subject: PyConPads at PyCon 2010 in Atlanta Message-ID: <31a94d5f-1304-46fa-9f1b-a4a68b07f6c9@s36g2000prf.googlegroups.com> Couldn't make it to PyCon 2010 in person? Want to access collaborative notes taken there? Watch the short video at http://bit.ly/dgBcpA to see how to find live notes being taken at the conference on PyConPads. You can chat with -- and thank! -- the note takers. The site: http://pyconpads.net Twitter announcements of pads: http://twitter.com/pyconpads From python at mrabarnett.plus.com Fri Feb 19 18:18:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 19 Feb 2010 23:18:14 +0000 Subject: Question about getmtime In-Reply-To: <2f56a4b1-4f2b-4ec9-827b-e6d4e5d52f7d@v20g2000prb.googlegroups.com> References: <81c5582a-f30d-4ca6-a5cf-c8a7bd086ac0@f8g2000yqn.googlegroups.com> <2f56a4b1-4f2b-4ec9-827b-e6d4e5d52f7d@v20g2000prb.googlegroups.com> Message-ID: <4B7F1C36.4030906@mrabarnett.plus.com> Sean DiZazzo wrote: > On Feb 19, 10:06 am, MRAB wrote: >> Brandon wrote: >>> Hi everyone, >>> Does copying or moving a file affect the return value of >>> os.path.getmtime(path)? >> The modification time of a copied file should be the same as the >> original. >> >> The creation time of a copied file will be the time at which it was >> copied, so that can result in the paradoxical state of a file having >> been modified _before_ it was created! :-) > > ctime does not stand for creation time. I went through this a couple > of months ago. It's updated whenever the inode is updated, so > changing permissions, among other things will update it. > > It blew me away when I finally found this out. > On Windows ctime doesn't change when the file permissions are changed. From jgardner at jonathangardner.net Fri Feb 19 18:36:50 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 15:36:50 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> Message-ID: <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> On Fri, Feb 19, 2010 at 1:58 PM, Vincent Davis wrote: > In reference to the several comments about "[x for x in read] is basically > a copy of the entire list. This isn't necessary." or list(read). I had > thought I had a problem with having iterators in the takewhile() statement. > I thought I testes and it didn't work. It seems I was wrong. It clearly > works. I'll make this change and see if it is any better. > > I actually don't plan to read them all in at once, only as needed, but I do > need the whole file in an array to perform some mathematics on them and > compare different files. So my interest was in making it faster to open them > as needed. I guess part of it is that they are about 5mb so I guess it might > be disk speed in part.nks > > Record your numbers in an array and then work your magic on them later. Don't store the entire file in memory, though. -- Jonathan Gardner jgardner at jonathangardner.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From aahz at pythoncraft.com Fri Feb 19 19:15:07 2010 From: aahz at pythoncraft.com (Aahz) Date: 19 Feb 2010 16:15:07 -0800 Subject: How to use python to register a service (an existing .exe file) References: <4b79e28c$0$4610$426a74cc@news.free.fr> Message-ID: In article <4b79e28c$0$4610$426a74cc at news.free.fr>, News123 wrote: >Is there a python way to register new windows services. > >I am aware of the >instsrv.exe program, which can be used to install services. >I could use subprocess.Popen to call > >instsrv.exe "service_name" program.exe > >but wondered, whether there's already an existing function. Use the win32 package. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. :-)" From mattbarkan at gmail.com Fri Feb 19 19:20:53 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 16:20:53 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> Message-ID: <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> On Feb 19, 6:02?pm, "Martin P. Hellwig" wrote: > On 02/19/10 21:48, MattB wrote: > > > Hey all, > > > I've been working on a program that accesses my school's password > > protected website and downloads directory names. I'm using mechanize. > > > Recently, the program has been unable to open the website, returning > > the 'errno 61 connection refused' error. I presume the school's server > > was blocking me because of many automated logins. > > Being a former school BOFH, I can assure you that if I was annoyed by > your 'misuse' I would have tracked you down and made you aware of it. > > > > > However, it turns out that I cannot now open ANY url from within > > Python on my computer using mechanize (or urllib for that matter). > > And I've tried in several places -- my place, a friend's place (who > > also has comcast as an ISP) and the school -- but no dice, constant > > errno 61's whenever I try to open a url. > > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > > > > The strangest thing about this is that firefox still works flawlessly > > on any site. > > Your system might have been centrally configure so that applications are > aware of the proxy, firefox probably has been piggybacking on those > settings (as it should). Most platforms can be made aware of a proxy by > a DHCP option send by the DHCP server (that is when you automatically > get an IP address). > > > Any suggestions would be greatly appreciated. > > > Matt > > Google a bit around how you can figure out (from inside your script) > whether your used platform has a proxy configured and how to use it with > your application. > > Good luck! > > -- > mph Hey all, I've used httpfox to identify the precise headers being sent by firefox, and then added them to my program using br.addheaders(), as per the proper mechanize syntax. No dice. (In fact, these headers were in the program when I ran it successfully from my friend's computer at his apartment). So I'm pretty sure it's not a header issue. I'll check and see whether firefox and my system are using a proxy. Also, based on Martin's comment, I just wanted to make you all aware that I intend no misuse, but rather am just trying to learn, as I'm a programming noob. I am not doing anything that I can't do myself from firefox (ie, I have an account at the school, and am allowed to sign on with my name and password and look up information in the student directory). If I do it for more than one student, it just becomes repetitive, so I thought this was a first modest goal in learning to do some programming.) That said, I'm happy to discontinue the attempts, but I'd like to know how it is that my computer (unless using firefox) is completely blocked from opening urls from within python. (And how to fix it). Thanks for the continued help. From mattbarkan at gmail.com Fri Feb 19 20:06:45 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 17:06:45 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> Message-ID: <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> On Feb 19, 7:20?pm, MattB wrote: > On Feb 19, 6:02?pm, "Martin P. Hellwig" > wrote: > > > > > On 02/19/10 21:48, MattB wrote: > > > > Hey all, > > > > I've been working on a program that accesses my school's password > > > protected website and downloads directory names. I'm using mechanize. > > > > Recently, the program has been unable to open the website, returning > > > the 'errno 61 connection refused' error. I presume the school's server > > > was blocking me because of many automated logins. > > > Being a former school BOFH, I can assure you that if I was annoyed by > > your 'misuse' I would have tracked you down and made you aware of it. > > > > However, it turns out that I cannot now open ANY url from within > > > Python on my computer using mechanize (or urllib for that matter). > > > And I've tried in several places -- my place, a friend's place (who > > > also has comcast as an ISP) and the school -- but no dice, constant > > > errno 61's whenever I try to open a url. > > > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > > > The strangest thing about this is that firefox still works flawlessly > > > on any site. > > > Your system might have been centrally configure so that applications are > > aware of the proxy, firefox probably has been piggybacking on those > > settings (as it should). Most platforms can be made aware of a proxy by > > a DHCP option send by the DHCP server (that is when you automatically > > get an IP address). > > > > Any suggestions would be greatly appreciated. > > > > Matt > > > Google a bit around how you can figure out (from inside your script) > > whether your used platform has a proxy configured and how to use it with > > your application. > > > Good luck! > > > -- > > mph > > Hey all, > > I've used httpfox to identify the precise headers being sent by > firefox, and then added them to my program using br.addheaders(), as > per the proper mechanize syntax. No dice. (In fact, these headers were > in the program when I ran it successfully from my friend's computer at > his apartment). So I'm pretty sure it's not a header issue. > > I'll check and see whether firefox and my system are using a proxy. > > Also, based on Martin's comment, I just wanted to make you all aware > that I intend no misuse, but rather am just trying to learn, as I'm a > programming noob. I am not doing anything that I can't do myself from > firefox (ie, I have an account at the school, and am allowed to sign > on with my name and password and look up information in the student > directory). If I do it for more than one student, it just becomes > repetitive, so I thought this was a first modest goal in learning to > do some programming.) > > That said, I'm happy to discontinue the attempts, but I'd like to know > how it is that my computer (unless using firefox) is completely > blocked from opening urls from within python. (And how to fix it). > > Thanks for the continued help. Breakthrough: I tried switching from a wireless connection to my router, and instead used an ethernet connection -- and now everything works. Why would this make a difference? MAC address? Is it possible for an external server to see my MAC address and block it? Clearly wasn't an IP address issue! From livingstonemark at gmail.com Fri Feb 19 20:15:33 2010 From: livingstonemark at gmail.com (Mark Livingstone) Date: Sat, 20 Feb 2010 11:15:33 +1000 Subject: Looking for crossfold validation code Message-ID: Hello, I am doing research as part of a Uni research Scholarship into using data compression for classification. What I am looking for is python code to handle the crossfold validation side of things for me - that will take my testing / training corpus and create the testing / training files after asking me for number of folds and number of times (or maybe allow me to enter a random seed or offset instead of times.) I could then either hook my classifier into the program or use it in a separate step. Probably not very hard to write, but why reinvent the wheel ;-) Thanks in advance, MarkL From clp2 at rebertia.com Fri Feb 19 20:28:04 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 19 Feb 2010 17:28:04 -0800 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: <50697b2c1002191728i698a919cgc2e2d3286a5d918c@mail.gmail.com> On Fri, Feb 19, 2010 at 5:06 PM, MattB wrote: > On Feb 19, 7:20?pm, MattB wrote: >> On Feb 19, 6:02?pm, "Martin P. Hellwig" >> wrote: >> > On 02/19/10 21:48, MattB wrote: >> > > Hey all, >> >> > > I've been working on a program that accesses my school's password >> > > protected website and downloads directory names. I'm using mechanize. >> >> > > Recently, the program has been unable to open the website, returning >> > > the 'errno 61 connection refused' error. I presume the school's server >> > > was blocking me because of many automated logins. >> >> > Being a former school BOFH, I can assure you that if I was annoyed by >> > your 'misuse' I would have tracked you down and made you aware of it. >> >> > > However, it turns out that I cannot now open ANY url from within >> > > Python on my computer using mechanize (or urllib for that matter). >> > > And I've tried in several places -- my place, a friend's place (who >> > > also has comcast as an ISP) and the school -- but no dice, constant >> > > errno 61's whenever I try to open a url. >> >> > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. >> >> > > The strangest thing about this is that firefox still works flawlessly >> > > on any site. >> >> > Your system might have been centrally configure so that applications are >> > aware of the proxy, firefox probably has been piggybacking on those >> > settings (as it should). Most platforms can be made aware of a proxy by >> > a DHCP option send by the DHCP server (that is when you automatically >> > get an IP address). >> >> > > Any suggestions would be greatly appreciated. > Breakthrough: > > I tried switching from a wireless connection to my router, and instead > used an ethernet connection -- and now everything works. > > Why would this make a difference? MAC address? Is it possible for an > external server to see my MAC address and block it? Clearly wasn't an > IP address issue! If you're using the campus network and depending on the exact network details, yes, they very likely can know your MAC address and thus block it. Since your Wi-Fi card and Ethernet card have different hardware MAC addresses, yes, switching would change your visible MAC address, thus circumventing any blocks based on it. Cheers, Chris -- Hi ACMS! http://blog.rebertia.com From anand.shashwat at gmail.com Fri Feb 19 21:25:40 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 07:55:40 +0530 Subject: the mystery of dirname() Message-ID: In the following code sample : def dirname(p): """Returns the directory component of a pathname""" i = p.rfind('/') + 1 head = p[:i] if head and head != '/'*len(head): head = head.rstrip('/') return head def dirname1(p): i = p.rfind('/') + 1 head = p[:i] if head != '/': return head.rstrip('/') return head if __name__ == "__main__": p1 = '/Users/l0nwlf/Desktop' p2 = './' p3 = '/' p4 = '.' print dirname(p1), dirname1(p1) print dirname(p2), dirname1(p2) print dirname(p3), dirname1(p3) print dirname(p4), dirname1(p4) OUTPUT: /Users/l0nwlf /Users/l0nwlf . . / / dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of "if head and head != '/'*len(head):" and replaced it with more obvious way in dirname1(). Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? Regards, ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From mattbarkan at gmail.com Fri Feb 19 21:32:59 2010 From: mattbarkan at gmail.com (MattB) Date: Fri, 19 Feb 2010 18:32:59 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: On Feb 19, 8:28?pm, Chris Rebert wrote: > On Fri, Feb 19, 2010 at 5:06 PM, MattB wrote: > > On Feb 19, 7:20?pm, MattB wrote: > >> On Feb 19, 6:02?pm, "Martin P. Hellwig" > >> wrote: > >> > On 02/19/10 21:48, MattB wrote: > >> > > Hey all, > > >> > > I've been working on a program that accesses my school's password > >> > > protected website and downloads directory names. I'm using mechanize. > > >> > > Recently, the program has been unable to open the website, returning > >> > > the 'errno 61 connection refused' error. I presume the school's server > >> > > was blocking me because of many automated logins. > > >> > Being a former school BOFH, I can assure you that if I was annoyed by > >> > your 'misuse' I would have tracked you down and made you aware of it. > > >> > > However, it turns out that I cannot now open ANY url from within > >> > > Python on my computer using mechanize (or urllib for that matter). > >> > > And I've tried in several places -- my place, a friend's place (who > >> > > also has comcast as an ISP) and the school -- but no dice, constant > >> > > errno 61's whenever I try to open a url. > > >> > As mentioned by Jonathan Gardener, this is most likely a proxy gateway. > > >> > > The strangest thing about this is that firefox still works flawlessly > >> > > on any site. > > >> > Your system might have been centrally configure so that applications are > >> > aware of the proxy, firefox probably has been piggybacking on those > >> > settings (as it should). Most platforms can be made aware of a proxy by > >> > a DHCP option send by the DHCP server (that is when you automatically > >> > get an IP address). > > >> > > Any suggestions would be greatly appreciated. > > > Breakthrough: > > > I tried switching from a wireless connection to my router, and instead > > used an ethernet connection -- and now everything works. > > > Why would this make a difference? MAC address? Is it possible for an > > external server to see my MAC address and block it? Clearly wasn't an > > IP address issue! > > If you're using the campus network and depending on the exact network > details, yes, they very likely can know your MAC address and thus > block it. > Since your Wi-Fi card and Ethernet card have different hardware MAC > addresses, yes, switching would change your visible MAC address, thus > circumventing any blocks based on it. > > Cheers, > Chris > -- > Hi ACMS!http://blog.rebertia.com Chris, I'm using the network in my own apartment. Not the campus's. Moreover, my mac's MAC address is different from the MAC address shown by my router, but as I said I'm also blocked when using my friend's wireless router at his apartment. So it must be my mac's MAC, and not the router's MAC, that's being blocked, right? But ALSO -- is it my ISP that's blocking the mac's MAC (and not the school), since I can't raise ANY url's from python when I'm on wireless? From shearichard at gmail.com Fri Feb 19 21:39:57 2010 From: shearichard at gmail.com (northof40) Date: Fri, 19 Feb 2010 18:39:57 -0800 (PST) Subject: Capturing errors raised by other scripts ? Message-ID: I'm using the subroutine module to run run python script A.py from B.py (this is on windows fwiw). A.py is not my script and it may raise arbitary errors before exiting. How can I determine what's happened before A.py exited ? To simulate this I've got this script (which is meant to simulate A.py): class customError(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value) try: raise customError(2*2) except customError as e: print 'Custom exception occurred, value:', e.value I then run my A.py like this : >>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') >>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') >>> try: ... pathtojob="python.exe A.py" ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) ... except: ... print "bad stuff happened" ... When I do this I the exception handler is not fired and the text "Custom exception occurred, value: 4" ends up in the stdout file. I'd really like it to end up in stderr because then I could say "anything in stderr ? then ignore the output and flag an error". I don't want to have to parse the stdout for error like messages and I can't make changes to A.py. I'm sure there's a better way to do this - can anyone offer some advice ? thanks Richard. From anand.shashwat at gmail.com Fri Feb 19 21:55:23 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 08:25:23 +0530 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: try this : >>> url = 'http://www.google.com' >>> proxy = {'http': 'http://username:password at proxy:port'} >>> content = urllib.urlopen(url, proxies = proxy).read() Hopefully it should run without error. Second approach can be to check whether your environment variables are setup. $set will show you. If not the case set up your environment variable. HTH, ~l0nwlf On Sat, Feb 20, 2010 at 8:02 AM, MattB wrote: > On Feb 19, 8:28 pm, Chris Rebert wrote: > > On Fri, Feb 19, 2010 at 5:06 PM, MattB wrote: > > > On Feb 19, 7:20 pm, MattB wrote: > > >> On Feb 19, 6:02 pm, "Martin P. Hellwig" > > >> wrote: > > >> > On 02/19/10 21:48, MattB wrote: > > >> > > Hey all, > > > > >> > > I've been working on a program that accesses my school's password > > >> > > protected website and downloads directory names. I'm using > mechanize. > > > > >> > > Recently, the program has been unable to open the website, > returning > > >> > > the 'errno 61 connection refused' error. I presume the school's > server > > >> > > was blocking me because of many automated logins. > > > > >> > Being a former school BOFH, I can assure you that if I was annoyed > by > > >> > your 'misuse' I would have tracked you down and made you aware of > it. > > > > >> > > However, it turns out that I cannot now open ANY url from within > > >> > > Python on my computer using mechanize (or urllib for that matter). > > >> > > And I've tried in several places -- my place, a friend's place > (who > > >> > > also has comcast as an ISP) and the school -- but no dice, > constant > > >> > > errno 61's whenever I try to open a url. > > > > >> > As mentioned by Jonathan Gardener, this is most likely a proxy > gateway. > > > > >> > > The strangest thing about this is that firefox still works > flawlessly > > >> > > on any site. > > > > >> > Your system might have been centrally configure so that applications > are > > >> > aware of the proxy, firefox probably has been piggybacking on those > > >> > settings (as it should). Most platforms can be made aware of a proxy > by > > >> > a DHCP option send by the DHCP server (that is when you > automatically > > >> > get an IP address). > > > > >> > > Any suggestions would be greatly appreciated. > > > > > Breakthrough: > > > > > I tried switching from a wireless connection to my router, and instead > > > used an ethernet connection -- and now everything works. > > > > > Why would this make a difference? MAC address? Is it possible for an > > > external server to see my MAC address and block it? Clearly wasn't an > > > IP address issue! > > > > If you're using the campus network and depending on the exact network > > details, yes, they very likely can know your MAC address and thus > > block it. > > Since your Wi-Fi card and Ethernet card have different hardware MAC > > addresses, yes, switching would change your visible MAC address, thus > > circumventing any blocks based on it. > > > > Cheers, > > Chris > > -- > > Hi ACMS!http://blog.rebertia.com > > Chris, > > I'm using the network in my own apartment. Not the campus's. > Moreover, my mac's MAC address is different from the MAC address shown > by my router, but as I said I'm also blocked when using my friend's > wireless router at his apartment. > > So it must be my mac's MAC, and not the router's MAC, that's being > blocked, right? > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > school), since I can't raise ANY url's from python when I'm on > wireless? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 22:05:43 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 03:05:43 +0000 Subject: the mystery of dirname() In-Reply-To: References: Message-ID: <4B7F5187.3060806@mrabarnett.plus.com> Shashwat Anand wrote: > In the following code sample : > > def dirname(p): > > """Returns the directory component of a pathname""" > i = p.rfind('/') + 1 > > head = p[:i] > if head and head != '/'*len(head): > > head = head.rstrip('/') > > return head > > def dirname1(p): > i = p.rfind('/') + 1 > > head = p[:i] > if head != '/': > > return head.rstrip('/') > return head > > if __name__ == "__main__": > p1 = '/Users/l0nwlf/Desktop' > > p2 = './' > p3 = '/' > p4 = '.' > > print dirname(p1), dirname1(p1) > > print dirname(p2), dirname1(p2) > > print dirname(p3), dirname1(p3) > > print dirname(p4), dirname1(p4) > > OUTPUT: > > /Users/l0nwlf /Users/l0nwlf > . . > / / > > dirname() is a function taken from /Lib/posixpath.py. However i did not quite understood the usage of "if head and head != '/'*len(head):" and replaced it with more obvious way in dirname1(). > > Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge cases here ? > What if the path is '//x'? The current dirname would return '//', whereas dirname1 would return ''. From anand.shashwat at gmail.com Fri Feb 19 22:09:05 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 08:39:05 +0530 Subject: the mystery of dirname() In-Reply-To: <4B7F5187.3060806@mrabarnett.plus.com> References: <4B7F5187.3060806@mrabarnett.plus.com> Message-ID: But this is posixpath, right ? So '//x' like path will not occur as far as I guess ? On Sat, Feb 20, 2010 at 8:35 AM, MRAB wrote: > Shashwat Anand wrote: > >> In the following code sample : >> >> def dirname(p): >> >> """Returns the directory component of a pathname""" >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head and head != '/'*len(head): >> >> head = head.rstrip('/') >> >> return head >> >> def dirname1(p): >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head != '/': >> >> return head.rstrip('/') return head >> >> if __name__ == "__main__": >> p1 = '/Users/l0nwlf/Desktop' >> >> p2 = './' >> p3 = '/' >> p4 = '.' >> >> print dirname(p1), dirname1(p1) >> >> print dirname(p2), dirname1(p2) >> >> print dirname(p3), dirname1(p3) >> >> print dirname(p4), dirname1(p4) >> >> OUTPUT: >> >> /Users/l0nwlf /Users/l0nwlf >> . . >> / / >> >> dirname() is a function taken from /Lib/posixpath.py. However i did not >> quite understood the usage of "if head and head != '/'*len(head):" and >> replaced it with more obvious way in dirname1(). >> >> Am I right to do so ? Is dirname1() more pythonic ? Did I missed any edge >> cases here ? >> >> What if the path is '//x'? The current dirname would return '//', > whereas dirname1 would return ''. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Fri Feb 19 22:13:10 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 03:13:10 +0000 Subject: Capturing errors raised by other scripts ? In-Reply-To: References: Message-ID: <4B7F5346.9060308@mrabarnett.plus.com> northof40 wrote: > I'm using the subroutine module to run run python script A.py from > B.py (this is on windows fwiw). > > A.py is not my script and it may raise arbitary errors before exiting. > How can I determine what's happened before A.py exited ? > > To simulate this I've got this script (which is meant to simulate > A.py): > > class customError(Exception): > def __init__(self, value): > self.value = value > def __str__(self): > return repr(self.value) > > try: > raise customError(2*2) > except customError as e: > print 'Custom exception occurred, value:', e.value > > > I then run my A.py like this : > >>>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') >>>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') >>>> try: > ... pathtojob="python.exe A.py" > ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) > ... except: > ... print "bad stuff happened" > ... > > When I do this I the exception handler is not fired and the text > "Custom exception occurred, value: 4" ends up in the stdout file. > > I'd really like it to end up in stderr because then I could say > "anything in stderr ? then ignore the output and flag an error". > > I don't want to have to parse the stdout for error like messages and I > can't make changes to A.py. > > I'm sure there's a better way to do this - can anyone offer some > advice ? > > thanks > A.py is printing the error message. The 'print' statement prints to stdout unless you direct it elsewhere with '>>', for example: print >> my_file, 'message' If you don't want error messages to go to stdout, then don't print them to stdout, it's as simple as that! From python at mrabarnett.plus.com Fri Feb 19 22:17:09 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 03:17:09 +0000 Subject: the mystery of dirname() In-Reply-To: References: <4B7F5187.3060806@mrabarnett.plus.com> Message-ID: <4B7F5435.2020704@mrabarnett.plus.com> Shashwat Anand wrote: > But this is posixpath, right ? So '//x' like path will not occur as far > as I guess ? > Can you guarantee that? It's safer to just leave it as it is, just in case! :-) > On Sat, Feb 20, 2010 at 8:35 AM, MRAB > wrote: > > Shashwat Anand wrote: > > In the following code sample : > > def dirname(p): > > """Returns the directory component of a pathname""" > i = p.rfind('/') + 1 > > head = p[:i] > if head and head != '/'*len(head): > > head = head.rstrip('/') > > return head > > def dirname1(p): > i = p.rfind('/') + 1 > > head = p[:i] > if head != '/': > > return head.rstrip('/') return head > > if __name__ == "__main__": > p1 = '/Users/l0nwlf/Desktop' > > p2 = './' > p3 = '/' > p4 = '.' > > print dirname(p1), dirname1(p1) > > print dirname(p2), dirname1(p2) > > print dirname(p3), dirname1(p3) > > print dirname(p4), dirname1(p4) > > OUTPUT: > > /Users/l0nwlf /Users/l0nwlf > . . > / / > > dirname() is a function taken from /Lib/posixpath.py. However i > did not quite understood the usage of "if head and head != > '/'*len(head):" and replaced it with more obvious way in dirname1(). > > Am I right to do so ? Is dirname1() more pythonic ? Did I missed > any edge cases here ? > > What if the path is '//x'? The current dirname would return '//', > whereas dirname1 would return ''. > From anand.shashwat at gmail.com Fri Feb 19 22:21:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 08:51:00 +0530 Subject: the mystery of dirname() In-Reply-To: <4B7F5435.2020704@mrabarnett.plus.com> References: <4B7F5187.3060806@mrabarnett.plus.com> <4B7F5435.2020704@mrabarnett.plus.com> Message-ID: basically I infer that : dirname = path - basename, like for path = '//x', basename = x, hence dirname = '//' On Sat, Feb 20, 2010 at 8:47 AM, MRAB wrote: > Shashwat Anand wrote: > >> But this is posixpath, right ? So '//x' like path will not occur as far as >> I guess ? >> >> Can you guarantee that? It's safer to just leave it as it is, just in > case! :-) > > > On Sat, Feb 20, 2010 at 8:35 AM, MRAB > python at mrabarnett.plus.com>> wrote: >> >> Shashwat Anand wrote: >> >> In the following code sample : >> >> def dirname(p): >> >> """Returns the directory component of a pathname""" >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head and head != '/'*len(head): >> >> head = head.rstrip('/') >> >> return head >> >> def dirname1(p): >> i = p.rfind('/') + 1 >> >> head = p[:i] >> if head != '/': >> >> return head.rstrip('/') return head >> >> if __name__ == "__main__": >> p1 = '/Users/l0nwlf/Desktop' >> >> p2 = './' >> p3 = '/' >> p4 = '.' >> >> print dirname(p1), dirname1(p1) >> >> print dirname(p2), dirname1(p2) >> >> print dirname(p3), dirname1(p3) >> >> print dirname(p4), dirname1(p4) >> >> OUTPUT: >> >> /Users/l0nwlf /Users/l0nwlf >> . . >> / / >> >> dirname() is a function taken from /Lib/posixpath.py. However i >> did not quite understood the usage of "if head and head != >> '/'*len(head):" and replaced it with more obvious way in >> dirname1(). >> >> Am I right to do so ? Is dirname1() more pythonic ? Did I missed >> any edge cases here ? >> >> What if the path is '//x'? The current dirname would return '//', >> whereas dirname1 would return ''. >> >> > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Fri Feb 19 22:33:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 20 Feb 2010 03:33:57 GMT Subject: Avoid converting functions to methods in a class Message-ID: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> I have a convention when writing unit tests to put the target of the test into a class attribute, as follows: class MyTest(unittest.TestCase): target = mymodule.someclass def test_spam(self): """Test that someclass has a spam attribute.""" self.failUnless(hasattr(self.target, 'spam')) It works well until I write a test for stand-alone functions: class AnotherTest(unittest.TestCase): target = mymodule.function def test_foo(self): self.assertEquals(self.target('a', 'b'), 'foo') The problem is that target is turned into a method of my test class, not a standalone function, and I get errors like: TypeError: function() takes exactly 2 arguments (3 given) The solution I currently use is to drop the target attribute in this class, and just refer to mymodule.function in each individual test. I don't like this solution because it violates Once And Only Once: if the function changes name, I have to make many edits to the test suite rather than just one. Are there any better solutions? -- Steven From shearichard at gmail.com Fri Feb 19 22:39:23 2010 From: shearichard at gmail.com (northof40) Date: Fri, 19 Feb 2010 19:39:23 -0800 (PST) Subject: Capturing errors raised by other scripts ? References: Message-ID: On Feb 20, 4:13?pm, MRAB wrote: > northof40 wrote: > > I'm using the subroutine module to run run python script A.py from > > B.py (this is on windows fwiw). > > > A.py is not my script and it may raise arbitary errors before exiting. > > How can I determine what's happened before A.py exited ? > > > To simulate this I've got this script (which is meant to simulate > > A.py): > > > class customError(Exception): > > ? ?def __init__(self, value): > > ? ? ? ? ? ?self.value = value > > ? ?def __str__(self): > > ? ? ? ? ? ?return repr(self.value) > > > try: > > ? ?raise customError(2*2) > > except customError as e: > > ? ?print 'Custom exception occurred, value:', e.value > > > I then run my A.py like this : > > >>>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') > >>>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') > >>>> try: > > ... ? ? pathtojob="python.exe A.py" > > ... ? ? p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) > > ... except: > > ... ? ? print "bad stuff happened" > > ... > > > When I do this I the exception handler is not fired and the text > > "Custom exception occurred, value: 4" ends up in the stdout file. > > > I'd really like it to end up in stderr because then I could say > > "anything in stderr ? then ignore the output and flag an error". > > > I don't want to have to parse the stdout for error like messages and I > > can't make changes to A.py. > > > I'm sure there's a better way to do this - can anyone offer some > > advice ? > > > thanks > > A.py is printing the error message. > > The 'print' statement prints to stdout unless you direct it elsewhere > with '>>', for example: > > ? ? ?print >> my_file, 'message' > > If you don't want error messages to go to stdout, then don't print them > to stdout, it's as simple as that! Thanks for your reply. I take your point about print - perhaps I hadn't really thought that through. Unfortunately I don't have control of the real script that's being run so if the programmer of that script has used print there's nothing I can do about it. Perhaps I could modify the question. If A.py terminates due an unhandled exception is there anyway for B.py to know that's happened (without A.py's cooperation ?). thanks Richard. If A.py terminates due to an unhandled exception From sccolbert at gmail.com Fri Feb 19 23:18:12 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 19 Feb 2010 23:18:12 -0500 Subject: Avoid converting functions to methods in a class In-Reply-To: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7f014ea61002192018n6547a63ete67d99ab1f59a724@mail.gmail.com> this is somewhat hackish: In [1]: def test(): ...: print 'spam' ...: ...: In [20]: class Ham(): ....: target = {'target': test} ....: def test_eggs(self): ....: self.target['target']() ....: ....: In [21]: h = Ham() In [22]: h.test_eggs() spam On Fri, Feb 19, 2010 at 10:33 PM, Steven D'Aprano < steve at remove-this-cybersource.com.au> wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. > > Are there any better solutions? > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Fri Feb 19 23:37:56 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Sat, 20 Feb 2010 15:37:56 +1100 Subject: Trouble running pywin32-214.win-amd64-py3.1 on 64-bit Windows 7 In-Reply-To: <5cf1aff91002191035o7c65df3bjfb4f26805923ea0d@mail.gmail.com> References: <5cf1aff91002191035o7c65df3bjfb4f26805923ea0d@mail.gmail.com> Message-ID: <4B7F6724.5070505@gmail.com> On 20/02/2010 5:35 AM, Steven Cohen wrote: > Hello, > > I downloaded pywin32-214.win-amd64-py3.1, and it installs just fine > (except that it prints a traceback when it tells me the postinstall > script completed), but then when I try to execute Pythonwin.exe, I get > the following error popup: > > The application can not locate win32ui.pyd (or Python) (126) > The specified module could not be found > > However, the file win32ui.pyd is right there in the same directory from > which I am executing Pythonwin.exe. Can anyone help me figure out what > I am doing wrong here? The pywin32 post-install script seems to break with the current Python 3.1 builds, and as a result, the pywin32 DLLs were probably not copied correctly. Try re-executing the post install script by: * Start a command-prompt by right-clicking on the shortcut and selecting 'Run as Administrator'. * Execute '\python31\python.exe \python31\scripts\pywin32_postinstall.py -install' (changing the paths as necessary). It should succeed as it is running from a console, and you might find that fixes things. HTH, Mark From cmpython at gmail.com Fri Feb 19 23:55:15 2010 From: cmpython at gmail.com (CM) Date: Fri, 19 Feb 2010 20:55:15 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: <65accaff-ab29-4dd4-9995-4ec60a034b56@y33g2000yqb.googlegroups.com> On Feb 19, 4:28?pm, Ryan Kelly wrote: > On Thu, 2010-02-18 at 20:32 -0800, CM wrote: > > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > > I have a Python app which I converted to an EXE (all files separate; > > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > > this and would like the ability to remotely upgrade the program (for > > > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > > you might find it useful: > > > > ?http://pypi.python.org/pypi/esky > > > This looks pretty interesting and useful. > > Thanks :-) > > > Just to help me understand it a bit more: ?what is it that users will > > download from some web page in order to initially get the py2exe'd app > > on their system? ?Is it "really" an "esky", with the app's .exe file > > inside it (but the esky is named the same as the app)? > > Currently, it's just a zip file with the frozen app in it, which the > user unzips to wherever they want the app. ?When unzipped it looks like > this: > > ? ?myapp.exe ?<-- actually the esky bootstrap exe > ? ?myapp-X.Y.Z.win32/ > ? ? ? ?myapp.exe ?<-- the actual frozen app as produced by py2exe > ? ? ? ?python26.dll > ? ? ? ?...etc... > > This could easily be wrapped in an installer - the important thing is > just that the files end up on the user's machine in the expected > directory structure. > > > ? And then when > > they want to update, the app's code calls the esky class to do the > > work of swapping out the appropriate .exe file? ?Something like this? > > Yes. ?The idea of having a "bootstrapping exe" is that actual > application code can be swapped out without having to overwrite the > executable file. ?As long as you don't change python versions, this > allows updates to be safe against system crashes, even on platforms > without atomic file replacement. > > So the frozen app does this in a background thread: > > ? ?Esky(sys.executable,"http://my.updates.com").auto_update() > > And it hits the given url, grabs the latest zipfile, downloads and > unpacks and atomically places it into the application directory. ?Et > viola, your app is at the latest version. > > From the packager's point of view, you run the "bdist_esky" distutils > command to generate the zipfile containing your latest version, then > simply upload it to your server. > > > Would this also work if one used InnoSetup to install the exe on the > > user's system? > > Yes, absolutely - in fact I plan to do this myself at some stage. ?All > that's required is that the files end up in the expected directory > structure. > > ? ?Ryan Wow, it sounds great. Good luck with moving forward with it. I'm not quite ready to release any apps, but as (if?) I come up on that, and if I plan on updating them, I would love to make use of Esky. Thanks for doing this. :D Che From ben+python at benfinney.id.au Fri Feb 19 23:55:56 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Feb 2010 15:55:56 +1100 Subject: Avoid converting functions to methods in a class References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: <87r5og8q03.fsf@benfinney.id.au> Steven D'Aprano writes: > I have a convention when writing unit tests Incidentally, you may be interested in the specific forum for testing in Python that is a good resource for asking questions like this. > to put the target of the test into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') I think this is because you're binding the ?target? attribute at the class definition, binding it to that class. Instead, this smells like something that should be a fixture for each test case:: class SomeClassTestCase(unittest.TestCase): def setUp(self): """ Set up test fixtures. """ self.target = mymodule.SomeClass def test_has_spam(self): """ Should have a spam attribute. """ self.failUnless(hasattr(self.target, 'spam')) def test_has_no_bacon(self): """ Should not have a bacon attribute. """ self.failIf(hasattr(self.target, 'bacon')) class SomeFunctionTest(unittest.TestCase): def setUp(self): """ Set up test fixtures. """ self.target = mymodule.some_function def test_a_b_input_returns_foo(self): """ Should return 'foo' from 'a', 'b' inputs. """ self.assertEquals(self.target('a', 'b'), 'foo') def test_c_d_input_raises_valueerror(self): """ Should raise ValueError from 'c', 'd' inputs. """ self.assertRaises( ValueError, self.target, 'c', 'd') -- \ ?A free press is one where it's okay to state the conclusion | `\ you're led to by the evidence.? ?Bill Moyers | _o__) | Ben Finney From cmpython at gmail.com Fri Feb 19 23:59:55 2010 From: cmpython at gmail.com (CM) Date: Fri, 19 Feb 2010 20:59:55 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: On Feb 19, 4:42?pm, "W. eWatson" wrote: > On 2/19/2010 10:56 AM, CM wrote: > > > On Feb 19, 12:21 pm, "W. eWatson" ?wrote: > >> On 2/19/2010 7:16 AM, Mark Lawrence wrote:> ?Andre Engels wrote: > >>>> On Fri, Feb 19, 2010 at 3:19 PM, Mark Lawrence > >>>> ?wrote: > >>>>> Andre Engels wrote: > >>>>>> On Fri, Feb 19, 2010 at 12:20 PM, W. eWatson > > >> ... > >> tories, or even the whole hard drive, for snowball.*. Then the OP> ?would know exactly what he has or hasn't got. > > >>> HTH. > > >>> Mark Lawrence > > >> Here's the answer. Consider this folder. > > >> Afolder > >> ? ? abc.py > >> ? ? hello.py > > >> I now apply py2exe steps to produce an ?"executable" for abc. The folder > >> now changes to > > >> Afolder > >> ? ? build > >> ? ? dist > >> ? ? abc.py > >> ? ? hello.py > > >> build are two new folders. dist contains abc.exe. > > >> Somehow when I type abc at the command prompt, this follows a path to > >> dist, and finds abc.exe, where it executes properly. > >> Cute, eh? I have no explanation for it. > > > Are you sure it's executing abc.exe? ?If you are at a Python command > > prompt within the "DOS shell" and you just type just abc, I think what > > is happening is you are running abc.py, NOT abc.exe. > > > py2exe creates a dist folder (short for "distributables") by default > > and puts your .exe into it along with whatever other files are needed > > to run your application. ?Depending on how you set the bundling > > options, this may be a lot of things or just 1-2 other things. > > > Che > > Well, you are right. What proof do I have? In fact, I just tried to run > a program that was not converted, and left off py. It worked. > > So maybe the only way to execute the compiled code is to to to dist? Not sure about that last question, but just try double-clicking on the .exe file in dist and your app should run. In fact, copy that dist folder to a flash drive, plug it into another computer that doesn't have Python installed on it, and doubleclick it again--it'll run again. In fact, depending on how you bundled it, you might need only the .exe file on many computers that have the Windows dlls already available. Che From wuwei23 at gmail.com Sat Feb 20 00:26:46 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 19 Feb 2010 21:26:46 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> Message-ID: <17d79b9e-0f06-4885-bb52-9cc06312f403@f17g2000prh.googlegroups.com> "W. eWatson" wrote: > So maybe the only way to execute the compiled code is to [g]o to dist? Or the compiled code needs to be in a folder that's higher in your path settings than the python file. But yes, moving into the dist directory, or running 'dist/snowball' from the project root will do the trick. From wuwei23 at gmail.com Sat Feb 20 00:38:31 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 19 Feb 2010 21:38:31 -0800 (PST) Subject: The Disappearing Program? References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> <17d79b9e-0f06-4885-bb52-9cc06312f403@f17g2000prh.googlegroups.com> Message-ID: <85adff5e-fc5e-4296-9408-b44f4b3dc207@z10g2000prh.googlegroups.com> On Feb 20, 3:26?pm, alex23 wrote: > or running 'dist/snowball' That should, of course, be: 'dist\snowball' :) From keekychen at gmail.com Sat Feb 20 00:38:47 2010 From: keekychen at gmail.com (Kee K Y CHEN) Date: Sat, 20 Feb 2010 13:38:47 +0800 Subject: Can I embedding a (python) console on python program? Message-ID: <1266644327.7846.21.camel@linux> HI All, Apologize for being a newbie to python area and sorry for my English. Actually what I need is embedding a python interactive console(or other shell console alike module) on my python program for debugging and controlling purpose during the program runtime. For example, print/set some important value, query some runtime status when I remote login to host via telnet/ssh when the program running on the host. One of the idea is I can write the program use the GUI tech, but that is not fit for someone use a text based session. In summary, in my scheme, it should something looks like the GEdit extension - python console and but may interactive with tty/vty lines. Can anyone give a brief to me? Thanks in advance. -- Kee K Y CHEN From anand.shashwat at gmail.com Sat Feb 20 00:53:00 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 11:23:00 +0530 Subject: Can I embedding a (python) console on python program? In-Reply-To: <1266644327.7846.21.camel@linux> References: <1266644327.7846.21.camel@linux> Message-ID: I am not sure what you are looking for, but you can try looking at 'cmd module' ~l0nwlf On Sat, Feb 20, 2010 at 11:08 AM, Kee K Y CHEN wrote: > HI All, > > Apologize for being a newbie to python area and sorry for my English. > > Actually what I need is embedding a python interactive console(or other > shell console alike module) on my python program for debugging and > controlling purpose during the program runtime. > > For example, print/set some important value, query some runtime status > when I remote login to host via telnet/ssh when the program running on > the host. One of the idea is I can write the program use the GUI tech, > but that is not fit for someone use a text based session. > > In summary, in my scheme, it should something looks like the GEdit > extension - python console and but may interactive with tty/vty lines. > > Can anyone give a brief to me? > > Thanks in advance. > > -- > Kee K Y CHEN > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Sat Feb 20 01:28:17 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Feb 2010 19:28:17 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> <87eikjcuzk.fsf@benfinney.id.au> Message-ID: In message <87eikjcuzk.fsf at benfinney.id.au>, Ben Finney wrote: > Lawrence D'Oliveiro writes: > >> In message , cjw wrote: >> >> > Aren't lambda forms better described as function? >> >> Is this a function? >> >> lambda : None >> >> What about this? >> >> lambda : sys.stdout.write("hi there!\n") > > They are both lambda forms in Python. As a Python expression, they > evaluate to (they ?return?) a function object. So there is no distinction between functions and procedures, then? From ldo at geek-central.gen.new_zealand Sat Feb 20 01:29:20 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Feb 2010 19:29:20 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <84166541-c10a-47b5-ae5b-b232026241c6@q2g2000pre.googlegroups.com> Message-ID: In message <84166541-c10a-47b5-ae5b- b232026241c6 at q2g2000pre.googlegroups.com>, Steve Howell wrote: > Some people make the definition of function more restrictive--"if it > has side effects, it is not a function." Does changing the contents of CPU cache count as a side-effect? From ldo at geek-central.gen.new_zealand Sat Feb 20 01:30:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 20 Feb 2010 19:30:26 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: In message , Rhodri James wrote: > In classic Pascal, a procedure was distinct from a function in that it had > no return value. The concept doesn't really apply in Python; there are no > procedures in that sense, since if a function terminates without supplying > an explicit return value it returns None. If Python doesn?t distinguish between procedures and functions, why should it distinguish between statements and expressions? From krishna.k.0001 at gmail.com Sat Feb 20 01:36:28 2010 From: krishna.k.0001 at gmail.com (krishna) Date: Fri, 19 Feb 2010 22:36:28 -0800 (PST) Subject: Scalable python dict {'key_is_a_string': [count, some_val]} Message-ID: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> I have to manage a couple of dicts with huge dataset (larger than feasible with the memory on my system), it basically has a key which is a string (actually a tuple converted to a string) and a two item list as value, with one element in the list being a count related to the key. I have to at the end sort this dictionary by the count. The platform is linux. I am planning to implement it by setting a threshold beyond which I write the data into files (3 columns: 'key count some_val' ) and later merge those files (I plan to sort the individual files by the key column and walk through the files with one pointer per file and merge them; I would add up the counts when entries from two files match by key) and sorting using the 'sort' command. Thus the bottleneck is the 'sort' command. Any suggestions, comments? By the way, is there a linux command that does the merging part? Thanks, Krishna From no.email at nospam.invalid Sat Feb 20 01:47:41 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 19 Feb 2010 22:47:41 -0800 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> Message-ID: <7xzl34pfn6.fsf@ruckus.brouhaha.com> krishna writes: > entries from two files match by key) and sorting using the 'sort' > command. Thus the bottleneck is the 'sort' command. That is a good approach. The sort command is highly optimized and will beat any Python program that does something comparable. Set LC_ALL=C if the file is all ascii, since that will bypass a lot of slow Unicode conversion and make sorting go even faster. > By the way, is there a linux command that does the merging part? sort -m Note that the sort command already does external sorting, so if you can just write out one large file and sort it, instead of sorting and then merging a bunch of smaller files, that may simplify your task. From ben+python at benfinney.id.au Sat Feb 20 02:02:18 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Feb 2010 18:02:18 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> <87eikjcuzk.fsf@benfinney.id.au> Message-ID: <87eikg8k5h.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > So there is no distinction between functions and procedures, then? In Python, no. -- \ ?When we pray to God we must be seeking nothing ? nothing.? | `\ ?Saint Francis of Assisi | _o__) | Ben Finney From lie.1296 at gmail.com Sat Feb 20 02:02:41 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:02:41 +1100 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> Message-ID: <4b7f892c$1@dnews.tpgi.com.au> On 02/20/10 13:32, MattB wrote: > > I'm using the network in my own apartment. Not the campus's. > Moreover, my mac's MAC address is different from the MAC address shown > by my router, but as I said I'm also blocked when using my friend's > wireless router at his apartment. > > So it must be my mac's MAC, and not the router's MAC, that's being > blocked, right? > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > school), since I can't raise ANY url's from python when I'm on > wireless? MAC or IP blocking can't be the reason, as the OP stated, he can use Firefox just fine. Can you access, say, http://www.google.com from urllib or mechanize? If you can't access *any website* using urllib/mechanize but you can with a browser and you're on a unix-based machine, you probably have the same problem as I used to have. Check whether you used the same hostname in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves its hostname configurations, I use Gentoo); after editing those files reboot (there are ways to avoid reboot, but rebooting guarantees the conf file is reread). Check the hostname by running this python script: import socket hn = socket.gethostname() print hn print socket.gethostbyname(hn) # should be 127.0.0.1 From ben+python at benfinney.id.au Sat Feb 20 02:04:00 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 20 Feb 2010 18:04:00 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <87aav48k2n.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > If Python doesn?t distinguish between procedures and functions, why > should it distinguish between statements and expressions? I don't see the connection between those two predicates. Why does the former matter when determining the ?should? of the latter? -- \ ?Pinky, are you pondering what I'm pondering?? ?Wuh, I think | `\ so, Brain, but wouldn't anything lose its flavor on the bedpost | _o__) overnight?? ?_Pinky and The Brain_ | Ben Finney From steve at holdenweb.com Sat Feb 20 02:12:55 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 20 Feb 2010 02:12:55 -0500 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <87aav48k2n.fsf@benfinney.id.au> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <87aav48k2n.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Lawrence D'Oliveiro writes: > >> If Python doesn?t distinguish between procedures and functions, why >> should it distinguish between statements and expressions? > > I don't see the connection between those two predicates. Why does the > former matter when determining the ?should? of the latter? > Because s similar dichotomy exists between the two pairs. Procedure <= function not returning a value Statement <= expression not returning a value regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From sjdevnull at yahoo.com Sat Feb 20 02:13:36 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Fri, 19 Feb 2010 23:13:36 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <4b7bc991$0$4242$426a34cc@news.free.fr> <87eikjcuzk.fsf@benfinney.id.au> Message-ID: On Feb 20, 1:28?am, Lawrence D'Oliveiro wrote: > In message <87eikjcuzk.... at benfinney.id.au>, Ben Finney wrote: > > > > > Lawrence D'Oliveiro writes: > > >> In message , cjw wrote: > > >> > Aren't lambda forms better described as function? > > >> Is this a function? > > >> ? ? lambda : None > > >> What about this? > > >> ? ? lambda : sys.stdout.write("hi there!\n") > > > They are both lambda forms in Python. As a Python expression, they > > evaluate to (they ?return?) a function object. > > So there is no distinction between functions and procedures, then? Not in most modern languages, no. i think the major places they are differentiated are in functional languages and in pre-1993ish languages (give or take a few years), neither of which applies to Python or Ruby. From lie.1296 at gmail.com Sat Feb 20 02:16:02 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:16:02 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <4b7f8c4d$1@dnews.tpgi.com.au> On 02/20/10 17:30, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > >> In classic Pascal, a procedure was distinct from a function in that it had >> no return value. The concept doesn't really apply in Python; there are no >> procedures in that sense, since if a function terminates without supplying >> an explicit return value it returns None. > > If Python doesn?t distinguish between procedures and functions, why should > it distinguish between statements and expressions? There are non-trivial languages that have been made without procedures and statements and non-trivial programs written on those languages. There is technically no need for a lambda that supports statements; someone could simply write a full-blown Monad framework and all of the things required for IO Monad and all their syntax sugars up to near a level of Haskell. Then we can do away with 'def's and all the statements or make them syntax sugar for the Monads. Now, why don't we start a PEP to make python a fully-functional language then? From stefan_ml at behnel.de Sat Feb 20 02:16:40 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 20 Feb 2010 08:16:40 +0100 Subject: Executing Python code on another computer In-Reply-To: <4B7EE0B0.5080605@ieee.org> References: <57835274-25f0-4dbe-96b7-7e2586c249db@z19g2000yqk.googlegroups.com> <4B7EE0B0.5080605@ieee.org> Message-ID: Dave Angel, 19.02.2010 20:04: > In that case, consider using RemoveDesktop, which is built into both Xp > and Vista. Careful, sounds like malware to me. Stefan From sjdevnull at yahoo.com Sat Feb 20 02:17:10 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Fri, 19 Feb 2010 23:17:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> On Feb 20, 1:30?am, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > > > In classic Pascal, a procedure was distinct from a function in that it had > > no return value. ?The concept doesn't really apply in Python; there are no > > procedures in that sense, since if a function terminates without supplying > > an explicit return value it returns None. > > If Python doesn?t distinguish between procedures and functions, why should > it distinguish between statements and expressions? Because the latter are different in Python (and in Ruby, and in most modern languages), while the former aren't distinguished in Python or Ruby or most modern languages? Primarily functional languages are the main exception, but other than them it's pretty uncommon to find any modern language that does distinguish procedures and functions, or one that doesn't distinguished statements and expressions. You can certainly find exceptions, but distinguishing statements and expressions is absolutely commonplace in modern languages, and distinguishing functions and procedures is in the minority. From lie.1296 at gmail.com Sat Feb 20 02:24:13 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:24:13 +1100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> Message-ID: <4b7f8e38$1@dnews.tpgi.com.au> On 02/20/10 18:17, sjdevnull at yahoo.com wrote: > On Feb 20, 1:30 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Rhodri James wrote: >> >>> In classic Pascal, a procedure was distinct from a function in that it had >>> no return value. The concept doesn't really apply in Python; there are no >>> procedures in that sense, since if a function terminates without supplying >>> an explicit return value it returns None. >> >> If Python doesn?t distinguish between procedures and functions, why should >> it distinguish between statements and expressions? > > Because the latter are different in Python (and in Ruby, and in most > modern languages), while the former aren't distinguished in Python or > Ruby or most modern languages? Primarily functional languages are the > main exception, but other than them it's pretty uncommon to find any > modern language that does distinguish procedures and functions, or one > that doesn't distinguished statements and expressions. > > You can certainly find exceptions, but distinguishing statements and > expressions is absolutely commonplace in modern languages, and > distinguishing functions and procedures is in the minority. But it all boils down to "Although practicality beats purity." From jgardner at jonathangardner.net Sat Feb 20 02:27:56 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 23:27:56 -0800 Subject: Scalable python dict {'key_is_a_string': [count, some_val]} In-Reply-To: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> Message-ID: <6cc20cea1002192327v364fd099r242b97a6316f6051@mail.gmail.com> On Fri, Feb 19, 2010 at 10:36 PM, krishna wrote: > I have to manage a couple of dicts with huge dataset (larger than > feasible with the memory on my system), it basically has a key which > is a string (actually a tuple converted to a string) and a two item > list as value, with one element in the list being a count related to > the key. I have to at the end sort this dictionary by the count. > > The platform is linux. I am planning to implement it by setting a > threshold beyond which I write the data into files (3 columns: 'key > count some_val' ) and later merge those files (I plan to sort the > individual files by the key column and walk through the files with one > pointer per file and merge them; I would add up the counts when > entries from two files match by key) and sorting using the 'sort' > command. Thus the bottleneck is the 'sort' command. > > Any suggestions, comments? > You should be using BDBs or even something like PostgreSQL. The indexes there will give you the scalability you need. I doubt you will be able to write anything that will select, update, insert or delete data better than what BDBs and PostgreSQL can give you. -- Jonathan Gardner jgardner at jonathangardner.net From pavlovevidence at gmail.com Sat Feb 20 02:30:21 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Feb 2010 23:30:21 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> Message-ID: <827dad76-528c-4ae5-9935-88ac35a211a3@z10g2000prh.googlegroups.com> On Feb 19, 10:30?pm, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > > > In classic Pascal, a procedure was distinct from a function in that it had > > no return value. ?The concept doesn't really apply in Python; there are no > > procedures in that sense, since if a function terminates without supplying > > an explicit return value it returns None. > > If Python doesn?t distinguish between procedures and functions, why should > it distinguish between statements and expressions? Because the real world works is more complex than simplified one- sentence generalizations. Carl Bnkas From lie.1296 at gmail.com Sat Feb 20 02:33:30 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 18:33:30 +1100 Subject: Can I embedding a (python) console on python program? In-Reply-To: <1266644327.7846.21.camel@linux> References: <1266644327.7846.21.camel@linux> Message-ID: <4b7f9065$1@dnews.tpgi.com.au> On 02/20/10 16:38, Kee K Y CHEN wrote: > HI All, > > Apologize for being a newbie to python area and sorry for my English. > > Actually what I need is embedding a python interactive console(or other > shell console alike module) on my python program for debugging and > controlling purpose during the program runtime. > > For example, print/set some important value, query some runtime status > when I remote login to host via telnet/ssh when the program running on > the host. One of the idea is I can write the program use the GUI tech, > but that is not fit for someone use a text based session. > > In summary, in my scheme, it should something looks like the GEdit > extension - python console and but may interactive with tty/vty lines. > > Can anyone give a brief to me? > > Thanks in advance. Look how IDLE and pdb does it. I believe the `cmd` built-in module is specifically written for this case. From pavlovevidence at gmail.com Sat Feb 20 02:36:10 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Fri, 19 Feb 2010 23:36:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <87aav48k2n.fsf@benfinney.id.au> Message-ID: On Feb 19, 11:12?pm, Steve Holden wrote: > Ben Finney wrote: > > Lawrence D'Oliveiro writes: > > >> If Python doesn?t distinguish between procedures and functions, why > >> should it distinguish between statements and expressions? > > > I don't see the connection between those two predicates. Why does the > > former matter when determining the ?should? of the latter? > > Because s similar dichotomy exists between the two pairs. > > Procedure <= function not returning a value > Statement <= expression not returning a value So if your language distinguishes between procedures and functions, it manifestly has to distinguish between statements and expressions, but there's no reason that the converse has to be true, expecially if an expression is a legal statement. Carl Banks From jgardner at jonathangardner.net Sat Feb 20 02:53:55 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Fri, 19 Feb 2010 23:53:55 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <4b7f8c4d$1@dnews.tpgi.com.au> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> Message-ID: <6cc20cea1002192353g5dec316flf34c8aaf14befe88@mail.gmail.com> On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: > > Now, why don't we start a PEP to make python a fully-functional language > then? > Because people don't think the same way that programs are written in functional languages. -- Jonathan Gardner jgardner at jonathangardner.net From lie.1296 at gmail.com Sat Feb 20 03:04:22 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sat, 20 Feb 2010 19:04:22 +1100 Subject: Capturing errors raised by other scripts ? In-Reply-To: References: Message-ID: <4b7f97a1$1@dnews.tpgi.com.au> On 02/20/10 14:39, northof40 wrote: > On Feb 20, 4:13 pm, MRAB wrote: >> northof40 wrote: >>> I'm using the subroutine module to run run python script A.py from >>> B.py (this is on windows fwiw). >> >>> A.py is not my script and it may raise arbitary errors before exiting. >>> How can I determine what's happened before A.py exited ? >> >>> To simulate this I've got this script (which is meant to simulate >>> A.py): >> >>> class customError(Exception): >>> def __init__(self, value): >>> self.value = value >>> def __str__(self): >>> return repr(self.value) >> >>> try: >>> raise customError(2*2) >>> except customError as e: >>> print 'Custom exception occurred, value:', e.value >> >>> I then run my A.py like this : >> >>>>>> fdOut, fOut = tempfile.mkstemp(suffix='.txt', prefix='AOut-') >>>>>> fdErr, fErr = tempfile.mkstemp(suffix='.txt', prefix='AErr-') >>>>>> try: >>> ... pathtojob="python.exe A.py" >>> ... p = subprocess.Popen(pathtojob, stderr=fdErr, stdout=fdOut) >>> ... except: >>> ... print "bad stuff happened" >>> ... >> >>> When I do this I the exception handler is not fired and the text >>> "Custom exception occurred, value: 4" ends up in the stdout file. >>> I'd really like it to end up in stderr because then I could say >>> "anything in stderr ? then ignore the output and flag an error". Not really; not all that is written to stderr signifies errors per se. Warning and Debugging info are often written to stderr as well. > Thanks for your reply. I take your point about print - perhaps I > hadn't really thought that through. Unfortunately I don't have control > of the real script that's being run so if the programmer of that > script has used print there's nothing I can do about it. Tracebacks is almost always written to stderr, not stdout; unless the programmer explicitly redirect the traceback into stdout. > Perhaps I could modify the question. If A.py terminates due an > unhandled exception is there anyway for B.py to know that's happened > (without A.py's cooperation ?). A well-behaved program will exit with status code 0; if and only if it exited cleanly. I believe a python program that exited due to unhandled exception always return non-zero status code. However, if the program handled an error and called exit(0) explicitly or the execution of the program falls to the end of the module; there is no way to distinguish it from regular clean exit. From pavlovevidence at gmail.com Sat Feb 20 03:12:48 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 00:12:48 -0800 (PST) Subject: Shared web host good citizenship question Message-ID: Not specifically Python related but thought I'd ask. If you have a low-bandwidth website running on a shared web hosting service as a WSGI server (or FastCGI, or any other interface with its own process), is it considered a responsible thing for the process to exit on its own after a period of non-activity, or is that something best left for the host to manage? I'd guess that modern web hosts would prefer that processes stay running, even if they go long periods without use, rather than having to periodically restart processes. Carl Banks From mattbarkan at gmail.com Sat Feb 20 03:36:15 2010 From: mattbarkan at gmail.com (MattB) Date: Sat, 20 Feb 2010 00:36:15 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> <4b7f892c$1@dnews.tpgi.com.au> Message-ID: <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> On Feb 20, 2:02?am, Lie Ryan wrote: > On 02/20/10 13:32, MattB wrote: > > > > > I'm using the network in my own apartment. Not the campus's. > > Moreover, my mac's MAC address is different from the MAC address shown > > by my router, but as I said I'm also blocked when using my friend's > > wireless router at his apartment. > > > So it must be my mac's MAC, and not the router's MAC, that's being > > blocked, right? > > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > > school), since I can't raise ANY url's from python when I'm on > > wireless? > > MAC or IP blocking can't be the reason, as the OP stated, he can use > Firefox just fine. > > Can you access, say,http://www.google.comfrom urllib or mechanize? > > If you can't access *any website* using urllib/mechanize but you can > with a browser and you're on a unix-based machine, you probably have the > same problem as I used to have. Check whether you used the same hostname > in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves > its hostname configurations, I use Gentoo); after editing those files > reboot (there are ways to avoid reboot, but rebooting guarantees the > conf file is reread). > > Check the hostname by running this python script: > > import socket > hn = socket.gethostname() > print hn > print socket.gethostbyname(hn) # should be 127.0.0.1 Lie, Wow. Strangely, that script returned 192.168.1.106. However, in Snow Leopard's airport settings, if I click on 'advanced' and then 'proxies', the default proxy for 'http' is 127.0.0.1:4444 (and in these settings, the 'use proxy for http' is checked). I just tried checking the unix files you mentioned. In etc/hosts, the following info is displayed: ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost Also found a file called ntp-restrict.conf, containing: # Access restrictions documented in ntp.conf(5) and # http://support.ntp.org/bin/view/Support/AccessRestrictions # Limit network machines to time queries only restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery # localhost is unrestricted restrict 127.0.0.1 restrict -6 ::1 includefile /private/etc/ntp.conf Not sure if these are what I'm looking for -- I'm new to unix so I may need a bit more hand-holding here. I appreciate your time and effort. Matt From clp2 at rebertia.com Sat Feb 20 03:44:10 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Feb 2010 00:44:10 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> Message-ID: <50697b2c1002200044o263a1bd0wd53d364b3fb49ccb@mail.gmail.com> On Fri, Feb 19, 2010 at 11:17 PM, sjdevnull at yahoo.com wrote: > On Feb 20, 1:30?am, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> If Python doesn?t distinguish between procedures and functions, why should >> it distinguish between statements and expressions? > > Because the latter are different in Python (and in Ruby I think your Ruby assertion needs fact-checking: irb(main):001:0> a = 7 # assignments have a value => 7 irb(main):002:0> puts(b = 42) # as further proof 42 => nil irb(main):003:0> b => 42 irb(main):004:0> c = [6,4,5] => [6, 4, 5] irb(main):005:0> if false irb(main):006:1> c.reverse! irb(main):007:1> else irb(main):008:1* c.sort! irb(main):009:1> end # even the if-else control structure has a value => [4, 5, 6] irb(main):010:0> begin # same with exception handling irb(main):011:1* raise "a runtime error" irb(main):012:1> rescue RuntimeError irb(main):013:1> "sounds bad" irb(main):014:1> end => "sounds bad" irb(main):015:0> def foo # and same with method bodies irb(main):016:1> 99 irb(main):017:1> end => nil irb(main):018:0> foo => 99 Quoth Wikipedia regarding Ruby (programming language): "For practical purposes there is no distinction between expressions and statements" Cheers, Chris -- http://blog.rebertia.com From anand.shashwat at gmail.com Sat Feb 20 03:59:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 14:29:12 +0530 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> <4b7f892c$1@dnews.tpgi.com.au> <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> Message-ID: throw up your 'ifconfig' and mozilla-proxy output here. It seems you don't know whether you are using proxy. For mozilla proxy : open mozilla -> cmd + "," -> Network -> Settings -> Paste everything that is there/ may be take a snapshot and upload a link. ~l0nwlf On Sat, Feb 20, 2010 at 2:06 PM, MattB wrote: > On Feb 20, 2:02 am, Lie Ryan wrote: > > On 02/20/10 13:32, MattB wrote: > > > > > > > > > I'm using the network in my own apartment. Not the campus's. > > > Moreover, my mac's MAC address is different from the MAC address shown > > > by my router, but as I said I'm also blocked when using my friend's > > > wireless router at his apartment. > > > > > So it must be my mac's MAC, and not the router's MAC, that's being > > > blocked, right? > > > > > But ALSO -- is it my ISP that's blocking the mac's MAC (and not the > > > school), since I can't raise ANY url's from python when I'm on > > > wireless? > > > > MAC or IP blocking can't be the reason, as the OP stated, he can use > > Firefox just fine. > > > > Can you access, say,http://www.google.comfrom urllib or mechanize? > > > > If you can't access *any website* using urllib/mechanize but you can > > with a browser and you're on a unix-based machine, you probably have the > > same problem as I used to have. Check whether you used the same hostname > > in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves > > its hostname configurations, I use Gentoo); after editing those files > > reboot (there are ways to avoid reboot, but rebooting guarantees the > > conf file is reread). > > > > Check the hostname by running this python script: > > > > import socket > > hn = socket.gethostname() > > print hn > > print socket.gethostbyname(hn) # should be 127.0.0.1 > > Lie, > > Wow. Strangely, that script returned 192.168.1.106. However, in Snow > Leopard's airport settings, if I click on 'advanced' and then > 'proxies', the default proxy for 'http' is 127.0.0.1:4444 (and in > these settings, the 'use proxy for http' is checked). > > I just tried checking the unix files you mentioned. In etc/hosts, the > following info is displayed: > > ## > # Host Database > # > # localhost is used to configure the loopback interface > # when the system is booting. Do not change this entry. > ## > > > 127.0.0.1 localhost > 255.255.255.255 broadcasthost > ::1 localhost > fe80::1%lo0 localhost > > Also found a file called ntp-restrict.conf, containing: > > # Access restrictions documented in ntp.conf(5) and > # http://support.ntp.org/bin/view/Support/AccessRestrictions > # Limit network machines to time queries only > > restrict default kod nomodify notrap nopeer noquery > restrict -6 default kod nomodify notrap nopeer noquery > > # localhost is unrestricted > restrict 127.0.0.1 > restrict -6 ::1 > > includefile /private/etc/ntp.conf > > Not sure if these are what I'm looking for -- I'm new to unix so I may > need a bit more hand-holding here. > > I appreciate your time and effort. > > Matt > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sebastian.noack at googlemail.com Sat Feb 20 05:36:04 2010 From: sebastian.noack at googlemail.com (Sebastian Noack) Date: Sat, 20 Feb 2010 11:36:04 +0100 Subject: os.pipe() + os.fork() Message-ID: <20100220113604.49b7c242@gurka> Hi, I have a problem using os.pipe() together with os.fork(). Usually when the writing end of the pipe is closed, the reading end gets EOF. So subsequent attempts to read data will return an empty string. But when you call os.fork() after you have created a pipe using os.pipe(), and read data from the pipe in the child process, when the partent process has already closed the writing end, the reading end does not get EOF. Instead of the os.read() call in the child process is blocking. I am using Linux, so I would like to know if this is a bug in Python or just weird behaviour under Linux and if it is possible work around it. Regards Sebastian Noack --------------------------------------------------------------------------- import os def test_pipe_sync(): pipe = os.pipe() os.write(pipe[1], 'Spam') os.close(pipe[1]) print repr(os.read(pipe[0], 4)) # 'Spam' is printed. print repr(os.read(pipe[0], 4)) # '' is printed, because of EOF is reached. def test_pipe_forked(): pipe = os.pipe() pid = os.fork() if pid: os.write(pipe[1], 'Spam') os.close(pipe[1]) os.waitpid(pid, 0) else: print repr(os.read(pipe[0], 4)) # 'Spam' is printed. print repr(os.read(pipe[0], 4)) # Nothing is printed and os.read() # is blocking, eventhough the other # end of the pipe was closed. if __name__ == '__main__': test_pipe_sync() print print '-' * 80 print test_pipe_forked() -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From arnodel at googlemail.com Sat Feb 20 06:00:34 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 20 Feb 2010 03:00:34 -0800 (PST) Subject: Avoid converting functions to methods in a class References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 20 Feb, 03:33, Steven D'Aprano wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > ? ? target = mymodule.someclass > > ? ? def test_spam(self): > ? ? ? ? """Test that someclass has a spam attribute.""" > ? ? ? ? self.failUnless(hasattr(self.target, 'spam')) > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > ? ? target = mymodule.function > > ? ? def test_foo(self): > ? ? ? ? self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. > > Are there any better solutions? > > -- > Steven Why not define target in the TestCase.setUp() method? class AnotherTest(unittest.TestCase): def setUp(self): self.target = mymodule.function def test_foo(self): self.assertEquals(self.target('a', 'b'), 'foo') -- Arnaud class -- Arnaud From arnodel at googlemail.com Sat Feb 20 06:03:47 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 20 Feb 2010 03:03:47 -0800 (PST) Subject: Scalable python dict {'key_is_a_string': [count, some_val]} References: <4e44ed04-7175-470a-99cb-cf51a93ff5f4@k41g2000yqm.googlegroups.com> Message-ID: On 20 Feb, 06:36, krishna wrote: > I have to manage a couple of dicts with huge dataset (larger than > feasible with the memory on my system), it basically has a key which > is a string (actually a tuple converted to a string) and a two item > list as value, with one element in the list being a count related to > the key. I have to at the end sort this dictionary by the count. > > The platform is linux. I am planning to implement it by setting a > threshold beyond which I write the data into files (3 columns: 'key > count some_val' ) and later merge those files (I plan to sort the > individual files by the key column and walk through the files with one > pointer per file and merge them; I would add up the counts when > entries from two files match by key) and sorting using the 'sort' > command. Thus the bottleneck is the 'sort' command. > > Any suggestions, comments? > > By the way, is there a linux command that does the merging part? > > Thanks, > Krishna Have you looked here? http://docs.python.org/library/persistence.html -- Arnaud From mukeshtiwari.iiitm at gmail.com Sat Feb 20 06:17:23 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sat, 20 Feb 2010 03:17:23 -0800 (PST) Subject: Precision issue in python Message-ID: Hello everyone. I think it is related to the precision with double arithmetic so i posted here.I am trying with this problem (https:// www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for all test cases whose N>=100, its K<=15." I know precision of doubles in c is 16 digits. Could some one please help me with this precision issue.I used stirling (http://en.wikipedia.org/wiki/ Stirling's_approximation) to calculate the first k digits of N. Thank you. __author__="Administrator" __date__ ="$Feb 19, 2010 3:16:47 PM$" import math if __name__ == "__main__": n=int(raw_input()) while(n>0): n-=1 raw_input() l=raw_input(); m=l.split(" ") N,K,L=int(m[0]),int(m[1]),int(m[2]) fwd,bkd=1,1 s_1,s_2="","" if(N<=200): for i in range(1,N+1): fwd=fwd*i; s=str(fwd) s_1=s[:K] else: d_1=(N*math.log(N)-N+0.5*math.log(2*math.pi*N)+(1/12/N)- (1/360/pow(N,3))+(1/1260/pow(N,5))-(1/1680/pow(N,7))+(1/1188/pow(N,9))- (691/2730/12/11/pow(N,11))+(7/6/14/13/pow(N,13)))*math.log10(math.e) d_2=d_1-int(d_1)+K-1 fwd=pow(10,d_2) #print fwd fwd=int(fwd) s_1=str(fwd) if(N<=500): for i in range(1,N+1): bkd=bkd*i bkd=bkd%pow(10,L) if(bkd==0): s_2="0"*L else: s_2=str(bkd) else: s_2="0"*L print s_1+" "+s_2 From sebastian.noack at googlemail.com Sat Feb 20 06:52:50 2010 From: sebastian.noack at googlemail.com (Sebastian Noack) Date: Sat, 20 Feb 2010 12:52:50 +0100 Subject: os.pipe() + os.fork() In-Reply-To: <20100220113604.49b7c242@gurka> References: <20100220113604.49b7c242@gurka> Message-ID: <20100220125250.35c9937d@gurka> I have figured out that, you have to close the writing end in the child process, which is reading from the pipe. Otherwise the underlying pipe is not going to be closed when the parent process is closing its writing end. This has nothing to do with Python itself. I have tried plain C and there it is the same behaviour. Regards Sebastian Noack -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From dickinsm at gmail.com Sat Feb 20 07:44:12 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Feb 2010 04:44:12 -0800 (PST) Subject: Precision issue in python References: Message-ID: On Feb 20, 11:17?am, mukesh tiwari wrote: > Hello everyone. I think it is ?related to the precision with double > arithmetic so i posted here.I am trying with this problem (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > all test cases whose N>=100, its K<=15." I know precision of doubles > in c is 16 digits. Could some one please help me with this precision > issue.I used stirling (http://en.wikipedia.org/wiki/ > Stirling's_approximation) to calculate the first k digits of N. > Thank you. If I understand you correctly, you're trying to compute the first k digits in the decimal expansion of N!, with bounds of k <= 15 and 100 <= N < 10**8. Is that right? Python's floats simply don't give you enough precision for this: you'd need to find the fractional part of log10(N!) with >= 15 digits of precision. But the integral part needs ~ log10(log10(N!)) digits, so you end up needing to compute log10(N!) with at least 15 + log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few extra digits for safety); so that's at least 25 digits needed for N close to 10**8. The decimal module would get you the results you need (are you allowed imports?). Or you could roll your own log implementation based on integer arithmetic. -- Mark From sparks.m at gmail.com Sat Feb 20 09:13:06 2010 From: sparks.m at gmail.com (Michael Sparks) Date: Sat, 20 Feb 2010 06:13:06 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> Message-ID: <3aa0205f-1e98-4376-92e4-607f96f13616@k19g2000yqc.googlegroups.com> On Feb 18, 4:15?pm, Steve Howell wrote: ... > ? ? def print_numbers() > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > ? ? ? ? ? ? [n * n, n * n * n] > ? ? ? ? }.reject { |square, cube| > ? ? ? ? ? ? square == 25 || cube == 64 > ? ? ? ? }.map { |square, cube| > ? ? ? ? ? ? cube > ? ? ? ? }.each { |n| > ? ? ? ? ? ? puts n > ? ? ? ? } > ? ? end This strikes me as a terrible example. For example, this is significantly clearer: def print_numbers() for n in [1,2,3,4,5,6]: square, cube = n * n, n * n * n if square != 25 and cube != 64: print n I /can/ see arguments for ruby style blocks in python, but not for this sort of thing, or lisp style quoted expressions[1]. ie I can see situations where you have more complex code in real life where they will definitely simplify things. [1] This is perhaps more appropriate because '(a b c) is equivalent to (quote a b c), and quote a b c can be viewed as close to python's expression "lambda: a b c" However, I can also see that in simple situations - such as the example you post - they will have a tendency to make code significantly less clear/direct. I suppose, if I have a choice between something (hard being possible & simple code looking simple) and (hard things being simpler & simple things looking harder), I'd probably personally choose the former. This is not because I don't like hard things being simple, but because I think that simple things are more common and making them look harder is a mistake. I'm well aware that's opinion however, Regards, Michael. From anand.shashwat at gmail.com Sat Feb 20 09:42:17 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 20:12:17 +0530 Subject: Precision issue in python In-Reply-To: References: Message-ID: A quick solution I came out with, no stirling numbers and had tried to avoid large integer multiplication as much as possible. import math for i in range(int(raw_input())): n, k, l = [int(i) for i in raw_input().split()] e = sum(math.log10(i) for i in range(1, n+1)) frac_e = e - math.floor(e) a = str(10**frac_e * 10**(k - 1)).split('.')[0] b = 1 for i in range(n, 0, -1): b = (b * i) % 10**l lb = len(str(b)) if lb < l: b = str(b) + '0'* (l - lb) print a, b ~l0nwlf On Sat, Feb 20, 2010 at 6:14 PM, Mark Dickinson wrote: > On Feb 20, 11:17 am, mukesh tiwari > wrote: > > Hello everyone. I think it is related to the precision with double > > arithmetic so i posted here.I am trying with this problem ( > https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : > for > > all test cases whose N>=100, its K<=15." I know precision of doubles > > in c is 16 digits. Could some one please help me with this precision > > issue.I used stirling (http://en.wikipedia.org/wiki/ > > Stirling's_approximation) to calculate the first k digits of N. > > Thank you. > > If I understand you correctly, you're trying to compute the first k > digits in the decimal expansion of N!, with bounds of k <= 15 and 100 > <= N < 10**8. Is that right? > > Python's floats simply don't give you enough precision for this: > you'd need to find the fractional part of log10(N!) with >= 15 digits > of precision. But the integral part needs ~ log10(log10(N!)) digits, > so you end up needing to compute log10(N!) with at least 15 + > log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few > extra digits for safety); so that's at least 25 digits needed for N > close to 10**8. > > The decimal module would get you the results you need (are you allowed > imports?). Or you could roll your own log implementation based on > integer arithmetic. > > -- > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dksreddy at gmail.com Sat Feb 20 09:44:52 2010 From: dksreddy at gmail.com (Sandy) Date: Sat, 20 Feb 2010 06:44:52 -0800 (PST) Subject: Looking for crossfold validation code References: Message-ID: <50026db2-ad99-41ac-bad8-ed8da0df6449@g11g2000yqe.googlegroups.com> Following is the code I use. I got it from web, but forgot the link. def k_fold_cross_validation(X, K, randomise = False): """ Generates K (training, validation) pairs from the items in X. Each pair is a partition of X, where validation is an iterable of length len(X)/K. So each training iterable is of length (K-1)*len(X)/K. If randomise is true, a copy of X is shuffled before partitioning, otherwise its order is preserved in training and validation. """ if randomise: from random import shuffle; X=list(X); shuffle(X) for k in xrange(K): training = [x for i, x in enumerate(X) if i % K != k] validation = [x for i, x in enumerate(X) if i % K == k] yield training, validation Cheers, dksr On Feb 20, 1:15?am, Mark Livingstone wrote: > Hello, > > I am doing research as part of a Uni research Scholarship into using > data compression for classification. What I am looking for is python > code to handle the crossfold validation side of things for me - that > will take my testing / training corpus and create the testing / > training files after asking me for number of folds and number of times > (or maybe allow me to enter a random seed or offset instead of times.) > I could then either hook my classifier into the program or use it in a > separate step. > > Probably not very hard to write, but why reinvent the wheel ;-) > > Thanks in advance, > > MarkL From mukeshtiwari.iiitm at gmail.com Sat Feb 20 10:13:07 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sat, 20 Feb 2010 07:13:07 -0800 (PST) Subject: Precision issue in python References: Message-ID: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> On Feb 20, 5:44?pm, Mark Dickinson wrote: > On Feb 20, 11:17?am, mukesh tiwari > wrote: > > > Hello everyone. I think it is ?related to the precision with double > > arithmetic so i posted here.I am trying with this problem (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > > all test cases whose N>=100, its K<=15." I know precision of doubles > > in c is 16 digits. Could some one please help me with this precision > > issue.I used stirling (http://en.wikipedia.org/wiki/ > > Stirling's_approximation) to calculate the first k digits of N. > > Thank you. > > If I understand you correctly, you're trying to compute the first k > digits in the decimal expansion of N!, with bounds of k <= 15 and 100 > <= N < 10**8. ?Is that right? > > Python's floats simply don't give you enough precision for this: > you'd need to find the fractional part of log10(N!) with >= 15 digits > of precision. ?But the integral part needs ~ log10(log10(N!)) digits, > so you end up needing to compute log10(N!) with at least 15 + > log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few > extra digits for safety); ?so that's at least 25 digits needed for N > close to 10**8. > > The decimal module would get you the results you need (are you allowed > imports?). ?Or you could roll your own log implementation based on > integer arithmetic. > > -- > Mark Yes i am trying to first k digits of N!.I will try your method. Thank you From wolftracks at invalid.com Sat Feb 20 10:23:16 2010 From: wolftracks at invalid.com (W. eWatson) Date: Sat, 20 Feb 2010 07:23:16 -0800 Subject: The Disappearing Program? (py2exe, graphics) In-Reply-To: <85adff5e-fc5e-4296-9408-b44f4b3dc207@z10g2000prh.googlegroups.com> References: <6faf39c91002190504nbfaeb7ev1621e586468f31aa@mail.gmail.com> <6faf39c91002190633qf8cc038k513ea2780fb50aa2@mail.gmail.com> <17d79b9e-0f06-4885-bb52-9cc06312f403@f17g2000prh.googlegroups.com> <85adff5e-fc5e-4296-9408-b44f4b3dc207@z10g2000prh.googlegroups.com> Message-ID: This apparently is not quite as easy as the py2exe tutorial suggests when MPL is involved. See . It looks like I have some reading and work to do. From malkarouri at gmail.com Sat Feb 20 10:30:54 2010 From: malkarouri at gmail.com (Muhammad Alkarouri) Date: Sat, 20 Feb 2010 07:30:54 -0800 (PST) Subject: Few questions on SOAP References: <52c61cb8-3529-4fee-9686-f755fb23c83a@b2g2000yqi.googlegroups.com> Message-ID: <72c74040-620b-4588-aa5e-63282bdacc64@v20g2000yqv.googlegroups.com> Thanks every one for commenting. I guess I misspoke. I meant to say that the group is not necessarily the best for parts of this question, so Subhabrata might not get as enthusiastic responses as in some other lists (which i don't recollect at the moment, sorry). I didn't want to convey the sense that his question is not welcome, rather that it might not get a lot of answers. Thanks Brendon and Steve for the support, and thanks Mark for correcting my slip. Regards, k From mukeshtiwari.iiitm at gmail.com Sat Feb 20 10:37:52 2010 From: mukeshtiwari.iiitm at gmail.com (mukesh tiwari) Date: Sat, 20 Feb 2010 07:37:52 -0800 (PST) Subject: Precision issue in python References: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> Message-ID: <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> On Feb 20, 8:13?pm, mukesh tiwari wrote: > On Feb 20, 5:44?pm, Mark Dickinson wrote: > > > > > > > On Feb 20, 11:17?am, mukesh tiwari > > wrote: > > > > Hello everyone. I think it is ?related to the precision with double > > > arithmetic so i posted here.I am trying with this problem (https://www.spoj.pl/problems/CALCULAT) and the problem say that "Note : for > > > all test cases whose N>=100, its K<=15." I know precision of doubles > > > in c is 16 digits. Could some one please help me with this precision > > > issue.I used stirling (http://en.wikipedia.org/wiki/ > > > Stirling's_approximation) to calculate the first k digits of N. > > > Thank you. > > > If I understand you correctly, you're trying to compute the first k > > digits in the decimal expansion of N!, with bounds of k <= 15 and 100 > > <= N < 10**8. ?Is that right? > > > Python's floats simply don't give you enough precision for this: > > you'd need to find the fractional part of log10(N!) with >= 15 digits > > of precision. ?But the integral part needs ~ log10(log10(N!)) digits, > > so you end up needing to compute log10(N!) with at least 15 + > > log10(log10(N!)) ~ 15 + log10(N) + log10(log10(N)) digits (plus a few > > extra digits for safety); ?so that's at least 25 digits needed for N > > close to 10**8. > > > The decimal module would get you the results you need (are you allowed > > imports?). ?Or you could roll your own log implementation based on > > integer arithmetic. > > > -- > > Mark > > Yes i am trying to first k digits of N!.I will try your method. > Thank you I am out of luck.I put d_2=d_1-int(d_1)+25 instead of d_2=d_1- int(d_1)+K-1 but i am getting WA. "The decimal module would get you the results you need (are you allowed imports?). Or you could roll your own log implementation based on integer arithmetic. " I don't know if is possible to import this decimal module but kindly tell me.Also a bit about log implementation Thank you From anand.shashwat at gmail.com Sat Feb 20 11:00:29 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sat, 20 Feb 2010 21:30:29 +0530 Subject: Precision issue in python In-Reply-To: <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> References: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> Message-ID: > I don't know if is possible to import this decimal module but kindly > tell me.Also a bit about log implementation > Why don't you read about decimal module (there is log too in it) and try writing your approach here in case it does not work? Or you insist someone to rewrite your code using decimal module ? :-/ ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From elias.bachaalany at gmail.com Sat Feb 20 11:12:01 2010 From: elias.bachaalany at gmail.com (lallous) Date: Sat, 20 Feb 2010 08:12:01 -0800 (PST) Subject: Pure virtual functions in Python? Message-ID: Hello How can I do something similar to pure virtual functions in C++ ? Let us consider this: class C1: # Pure virtual def cb(self, param1, param2): """ This is a callback @param param1: ... @param param2: ... """ raise NotImplementedError, "Implement me" # Implementation w/o a 'cb', thus 'cb' should not be used class C2(C1): def __init__(self): pass # Implementation w/ 'cb', thus 'cb' can be used class C3(C1): def __init__(self): pass def cb(self, param1, param2): print "i am c3 cb" # Dispatcher function that calls 'cb' only if 'cb' is implemented in child classes def dispatcher(c): if hasattr(c, 'cb'): c.cb("Hello", "World") dispatcher(C2()) dispatcher(C3()) What I want is the ability to have the dispatcher() not to call 'cb' if it was not implemented in one of the child classes. Please advise. From swrath at gmail.com Sat Feb 20 11:27:28 2010 From: swrath at gmail.com (sWrath swrath) Date: Sat, 20 Feb 2010 08:27:28 -0800 (PST) Subject: finding element by tag in xml Message-ID: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> Hi I am trying to search an element by tag and new in reading a xml file (in python). I coded this , but it did not work ---------------------------------------------- '''This is to detect the first element and print out all that element by tag''' from xml.dom.minidom import parse from xml.etree.ElementTree import* file1="book.xml" tmptree=ElementTree() tmptree.parse(file1) items=root.getiterator() dom = parse(file1) #Find tag names for node in items : if node.tag == 'author': #Get tag print dom.getElementsByTagName ('book') #Error 1 -----------------------------------------------------------------------------' 2 Questions 1. Why can't I use dom.getElementsByTagName('book') in #Error 1? How do i print the elements ? Error- AttributeError: ElementTree instance has no attribute 'getElementsByTagName' Thanks John From misceverything at gmail.com Sat Feb 20 11:38:07 2010 From: misceverything at gmail.com (T) Date: Sat, 20 Feb 2010 08:38:07 -0800 (PST) Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> Message-ID: <94febb38-2249-4ba1-872f-4ed11865f046@c28g2000vbc.googlegroups.com> On Feb 19, 4:32?pm, Ryan Kelly wrote: > On Fri, 2010-02-19 at 11:08 -0800, T wrote: > > On Feb 18, 7:19 pm, Ryan Kelly wrote: > > > On Thu, 2010-02-18 at 07:46 -0800, T wrote: > > > > I have a Python app which I converted to an EXE (all files separate; > > > > single EXE didn't work properly) via py2exe - I plan on distributing > > > > this and would like the ability to remotely upgrade the program (for > > > > example, via HTTP/HTTPS). ? Looks like it's not just the EXE that I > > > > will need need to replace (DLLs, the library.zip, etc.). ?What would > > > > be the best way to go about doing this? > > > > I've been working on an auto-update framework for my own frozen apps, > > > you might find it useful: > > > > ?http://pypi.python.org/pypi/esky > > > > Docs are a little scarce at the moment, the next release will hopefully > > > come with a short tutorial (as well as support for cx_freeze and maybe > > > py2app, depending on how adventurous I'm feeling). > > > Thanks Ryan..this looks like it could be what I'm looking for, but I'm > > still a bit unsure of how exactly how it works. ?Do you happen to have > > an idea approx when the next release w/ tutorial will be out? > > If I punt on the py2app support, I should be able to get it done in the > next 3-4 days. ?I'll send a quick email to python-list when it's ready. > > Here's a rough roadmap of where the project is heading: > > ? v0.4.0: ?cx_freeze support and a tutorial [the next 3-4 days] > ? v0.4.1: ?py2app support [the next 2-3 weeks] > ? v0.5.0: ?differential updates using bsdiff [next few months] > > ? Cheers, > > ? ? ?Ryan > > -- > Ryan Kellyhttp://www.rfk.id.au?| ?This message is digitally signed. Please visit > r... at rfk.id.au ? ? ? ?| ?http://www.rfk.id.au/ramblings/gpg/for details > > ?signature.asc > < 1KViewDownload Excellent - I look forward to giving it a try. Thanks again! From showell30 at yahoo.com Sat Feb 20 11:41:10 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sat, 20 Feb 2010 08:41:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <3aa0205f-1e98-4376-92e4-607f96f13616@k19g2000yqc.googlegroups.com> Message-ID: On Feb 20, 6:13?am, Michael Sparks wrote: > On Feb 18, 4:15?pm, Steve Howell wrote: > ... > > > ? ? def print_numbers() > > ? ? ? ? [1, 2, 3, 4, 5, 6].map { |n| > > ? ? ? ? ? ? [n * n, n * n * n] > > ? ? ? ? }.reject { |square, cube| > > ? ? ? ? ? ? square == 25 || cube == 64 > > ? ? ? ? }.map { |square, cube| > > ? ? ? ? ? ? cube > > ? ? ? ? }.each { |n| > > ? ? ? ? ? ? puts n > > ? ? ? ? } > > ? ? end > > This strikes me as a terrible example. For example, this is > significantly clearer: > ? ? def print_numbers() > ? ? ? ? for n in [1,2,3,4,5,6]: > ? ? ? ? ? ? square, cube = n * n, n * n * n > ? ? ? ? ? ? if square != 25 and cube != 64: > ? ? ? ? ? ? ? ? print n This is not an exact translation. My example prints the cubes. It is my fault for using "n" as the parameter in the last block. I would rename the parameter to cube. > > I /can/ see arguments for ruby style blocks in python, but not for > this sort of thing, or lisp style quoted expressions[1]. ie I can see > situations where you have more complex code in real life where they > will definitely simplify things. > > [1] This is perhaps more appropriate because '(a b c) is equivalent > ? ? to (quote a b c), and quote a b c can be viewed as close to > ? ? python's expression "lambda: a b c" > > However, I can also see that in simple situations - such as the > example you post - they will have a tendency to make code > significantly less clear/direct. > > I suppose, if I have a choice between something (hard being possible & > simple code looking simple) and (hard things being simpler & simple > things looking harder), I'd probably personally choose the former. > This is not because I don't like hard things being simple, but because > I think that simple things are more common and making them look harder > is a mistake. > I agree with much of what you are saying. The example is indeed terribly contrived. I'm not sure I agree that there is anything unclear or undirect about the Ruby, though. I've been fairly immersed in Ruby code, so maybe it's been warping my brain, but once you get over the unfamiliarity of the syntax, you see that there's actually a rhythm to the code. Setting aside punctuation and parameter lists, the code clearly expresses the transformations and actions in the natural order that you'd do them: LIST map expression reject criteria map expression each statement In English, for the list elements, map them to tuples of squares and cubes, reject the oddballs, take the cube, and print it out. [1, 2, 3, 4, 5, 6].map { |n| [n * n, n * n * n] }.reject { |square, cube| square == 25 || cube == 64 }.map { |square, cube| cube }.each { |cube| puts cube } For such a small problem, I agree it's verbose. But it's also completely flat--you don't need to use an "if" statement to express the concept of rejection. From martin at v.loewis.de Sat Feb 20 11:46:17 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 20 Feb 2010 17:46:17 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <4B8011D9.40005@v.loewis.de> lallous wrote: > Hello > > How can I do something similar to pure virtual functions in C++ ? See, for example http://code.activestate.com/recipes/266468/ Regards, Martin From deets at nospam.web.de Sat Feb 20 11:46:42 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 20 Feb 2010 17:46:42 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <7uahviFlubU1@mid.uni-berlin.de> Am 20.02.10 17:12, schrieb lallous: > Hello > > How can I do something similar to pure virtual functions in C++ ? > > Let us consider this: > > class C1: > > # Pure virtual > def cb(self, param1, param2): > """ > This is a callback > > @param param1: ... > @param param2: ... > """ > raise NotImplementedError, "Implement me" > > # Implementation w/o a 'cb', thus 'cb' should not be used > class C2(C1): > def __init__(self): > pass > > # Implementation w/ 'cb', thus 'cb' can be used > class C3(C1): > def __init__(self): > pass > > def cb(self, param1, param2): > print "i am c3 cb" > > # Dispatcher function that calls 'cb' only if 'cb' is implemented in > child classes > def dispatcher(c): > if hasattr(c, 'cb'): > c.cb("Hello", "World") > > dispatcher(C2()) > dispatcher(C3()) > > What I want is the ability to have the dispatcher() not to call 'cb' > if it was not implemented in one of the child classes. > > Please advise. There is nothing more beyond that what you already did. You can raise a NotImplementedError for classes that don't implement the method. That's it. Diez From martin at v.loewis.de Sat Feb 20 12:08:33 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 20 Feb 2010 18:08:33 +0100 Subject: Pure virtual functions in Python? In-Reply-To: <7uahviFlubU1@mid.uni-berlin.de> References: <7uahviFlubU1@mid.uni-berlin.de> Message-ID: <4B801711.7040501@v.loewis.de> >> class C1: >> >> # Pure virtual >> def cb(self, param1, param2): >> """ >> This is a callback >> >> @param param1: ... >> @param param2: ... >> """ >> raise NotImplementedError, "Implement me" >> >> # Dispatcher function that calls 'cb' only if 'cb' is implemented in >> child classes >> def dispatcher(c): >> if hasattr(c, 'cb'): >> c.cb("Hello", "World") >> >> dispatcher(C2()) >> dispatcher(C3()) >> >> What I want is the ability to have the dispatcher() not to call 'cb' >> if it was not implemented in one of the child classes. >> >> Please advise. > > There is nothing more beyond that what you already did. You can raise a > NotImplementedError for classes that don't implement the method. That's it. That's not true. Currently, the hasattr() call would report that cb is available, when it is actually not implemented. It would be possible to do something like if hasattr(c, 'cb') and not is_pure(c.cb): c.cb("Hello", "World") is_pure could, for example, look at a function attribute of the callback. You'd write something like @pure_virtual def cb(self, param1, param2): not_implemented Regards, Martin From deets at nospam.web.de Sat Feb 20 12:14:04 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Sat, 20 Feb 2010 18:14:04 +0100 Subject: Pure virtual functions in Python? In-Reply-To: <4B801711.7040501@v.loewis.de> References: <7uahviFlubU1@mid.uni-berlin.de> <4B801711.7040501@v.loewis.de> Message-ID: <7uajisFvihU1@mid.uni-berlin.de> Sorry, I totally mis-read the OP, too tired. You are right of course. Diez From dickinsm at gmail.com Sat Feb 20 12:17:12 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Feb 2010 09:17:12 -0800 (PST) Subject: Precision issue in python References: <4dd522d4-8c18-4fcd-ba1e-174af9098c02@v20g2000prb.googlegroups.com> <27736831-4378-4a07-aa38-8906340ecf62@e19g2000prn.googlegroups.com> Message-ID: <0550699e-9da7-4b3b-8a0d-f4549a3ddf83@j27g2000yqn.googlegroups.com> On Feb 20, 3:37?pm, mukesh tiwari wrote: > I don't know if is possible to import this decimal module but kindly > tell me.Also a bit about log implementation The decimal module is part of the standard library; I don't know what the rules are for SPOJ, but you're already importing the math module, so at least *some* imports are obviously permitted. Here's a quick demonstration of how you might use the decimal module: you can probably find ways to tweak it for speed and accuracy. from decimal import Decimal as D from decimal import getcontext getcontext().prec = 100 # working precision = 100 digits pi = D('3.14159265358979323846264338327950288419716939937510582097494459' '2307816406286208998628034825342117067982148086513282306647093844') half = D('0.5') log = D.ln def logfac(x): """Approximation to log(x!), using first few terms of Stirling's series.""" x = D(x) return log(2*pi)/2 + (x + half)*log(x) - x + \ 1/(12*x) - 1/(360*x**3) + 1/(1260*x**5) def fac_first_digits(n, k): """Get first k decimal digits of n!.""" log10_nfac = logfac(n)/log(D(10)) frac = log10_nfac - int(log10_nfac) return int(10**(frac - 1 + k)) With the above code I get, for example (with Python 2.6): >>> fac_first_digits(12345, 15) 344364246918678 >>> from math import factorial >>> int(str(factorial(12345))[:15]) 344364246918678 For small n, you'll need more terms of Stirling's series than I've used above. And there's always a small chance that the intermediate errors involved in the computation might change those first 15 digits; with a working precision of 100 and lots of terms of Stirling's series it's a *very* small chance, but it's there. If you want something 100% watertight, you'd need to compute strict upper and lower bounds for the true result, and increase precision until those bounds match sufficiently far that you can be sure of the first k digits being correct. -- Mark From rami.chowdhury at gmail.com Sat Feb 20 12:19:27 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 20 Feb 2010 12:19:27 -0500 Subject: Pure virtual functions in Python? In-Reply-To: <7uahviFlubU1@mid.uni-berlin.de> References: <7uahviFlubU1@mid.uni-berlin.de> Message-ID: <201002201219.27267.rami.chowdhury@gmail.com> On Saturday 20 February 2010 11:46:42 Diez B. Roggisch wrote: > Am 20.02.10 17:12, schrieb lallous: > > Hello > > > > How can I do something similar to pure virtual functions in C++ ? > > > > Let us consider this: > > > > class C1: > > > > # Pure virtual > > def cb(self, param1, param2): > > """ > > This is a callback > > > > @param param1: ... > > @param param2: ... > > """ > > raise NotImplementedError, "Implement me" > > > > # Implementation w/o a 'cb', thus 'cb' should not be used > > class C2(C1): > > def __init__(self): > > pass > > > > # Implementation w/ 'cb', thus 'cb' can be used > > class C3(C1): > > def __init__(self): > > pass > > > > def cb(self, param1, param2): > > print "i am c3 cb" > > > > # Dispatcher function that calls 'cb' only if 'cb' is implemented in > > child classes > > def dispatcher(c): > > if hasattr(c, 'cb'): > > c.cb("Hello", "World") > > > > dispatcher(C2()) > > dispatcher(C3()) > > > > What I want is the ability to have the dispatcher() not to call 'cb' > > if it was not implemented in one of the child classes. > > > > Please advise. > > There is nothing more beyond that what you already did. You can raise a > NotImplementedError for classes that don't implement the method. That's it. > > Diez > Perhaps you could use an easier-to-ask-forgiveness-than-permission idiom? def dispatcher(c): try: c.cb("Hello", "World") except NotImplementedError: pass ---- Rami Chowdhury "Passion is inversely proportional to the amount of real information available." -- Benford's Law of Controversy 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From vicente.soler at gmail.com Sat Feb 20 12:35:17 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 20 Feb 2010 09:35:17 -0800 (PST) Subject: Building a dict from a tuple of tuples Message-ID: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> Hello everyone! I have a tuple of tuples, coming from an Excel range, such as this: ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) I need to build a dictionary that has, as key, the row and column header. For example: d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } As you can see, if the value in the matrix is None, no key has to be added to the dictionary. Of course, my tuple of tuples is a lot bigger. How can I possibly do this? Thank you From lie.1296 at gmail.com Sat Feb 20 12:36:00 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 04:36:00 +1100 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <0dd3aaf4-61a0-4c4b-ac84-ae7d9de38b28@z39g2000vbb.googlegroups.com> <4b7f892c$1@dnews.tpgi.com.au> <2adb1d47-f899-485a-ad0e-354aa92ac227@15g2000yqi.googlegroups.com> Message-ID: <4b801d9c@dnews.tpgi.com.au> On 02/20/10 19:36, MattB wrote: > On Feb 20, 2:02 am, Lie Ryan wrote: >> On 02/20/10 13:32, MattB wrote: >> >> >> >>> I'm using the network in my own apartment. Not the campus's. >>> Moreover, my mac's MAC address is different from the MAC address shown >>> by my router, but as I said I'm also blocked when using my friend's >>> wireless router at his apartment. >> >>> So it must be my mac's MAC, and not the router's MAC, that's being >>> blocked, right? >> >>> But ALSO -- is it my ISP that's blocking the mac's MAC (and not the >>> school), since I can't raise ANY url's from python when I'm on >>> wireless? >> >> MAC or IP blocking can't be the reason, as the OP stated, he can use >> Firefox just fine. >> >> Can you access, say,http://www.google.comfrom urllib or mechanize? >> >> If you can't access *any website* using urllib/mechanize but you can >> with a browser and you're on a unix-based machine, you probably have the >> same problem as I used to have. Check whether you used the same hostname >> in /etc/conf.d/hostname and /etc/hosts (or wherever your distro saves >> its hostname configurations, I use Gentoo); after editing those files >> reboot (there are ways to avoid reboot, but rebooting guarantees the >> conf file is reread). >> >> Check the hostname by running this python script: >> >> import socket >> hn = socket.gethostname() >> print hn >> print socket.gethostbyname(hn) # should be 127.0.0.1 > > Lie, > > Wow. Strangely, that script returned 192.168.1.106. However, in Snow > Leopard's airport settings, if I click on 'advanced' and then > 'proxies', the default proxy for 'http' is 127.0.0.1:4444 (and in > these settings, the 'use proxy for http' is checked). > > I just tried checking the unix files you mentioned. In etc/hosts, the > following info is displayed: > > ## > # Host Database > # > # localhost is used to configure the loopback interface > # when the system is booting. Do not change this entry. > ## > > > 127.0.0.1 localhost > 255.255.255.255 broadcasthost > ::1 localhost > fe80::1%lo0 localhost > > > Not sure if these are what I'm looking for -- I'm new to unix so I may > need a bit more hand-holding here. Try the alternatives in this site: http://movealong.org/hostname.html > Also found a file called ntp-restrict.conf, containing: > > # Access restrictions documented in ntp.conf(5) and > # http://support.ntp.org/bin/view/Support/AccessRestrictions > # Limit network machines to time queries only > > restrict default kod nomodify notrap nopeer noquery > restrict -6 default kod nomodify notrap nopeer noquery > > # localhost is unrestricted > restrict 127.0.0.1 > restrict -6 ::1 > > includefile /private/etc/ntp.conf Not sure if ntp-restrict.conf is a red herring here since its name implies it's something for NTP (Network Time Protocol, used for time synchronization) From python at mrabarnett.plus.com Sat Feb 20 12:49:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 17:49:14 +0000 Subject: the mystery of dirname() In-Reply-To: References: <4B7F5187.3060806@mrabarnett.plus.com> <4B7F5435.2020704@mrabarnett.plus.com> Message-ID: <4B80209A.9080807@mrabarnett.plus.com> Shashwat Anand wrote: > basically I infer that : dirname = path - basename, like for path = > '//x', basename = x, hence dirname = '//' > [snip] Basically, os.path.dirname() should return the directory name, which means dropping everything after the last slash, and also the last slash. However, there's the special case where the name is in the root directory, and you want to retain the slash(es). When building a path (os.path.join()) you want to join the parts with a single slash between them, but there's the special case when a part is the root directory, and you don't want to add a slash between them, eg os.part.join('/x', 'y') should return '/x/y', but os.part.join('/', 'x') should return '/x'. From dickinsm at gmail.com Sat Feb 20 12:52:49 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sat, 20 Feb 2010 17:52:49 +0000 Subject: Precision issue in python In-Reply-To: References: Message-ID: <5c6f2a5d1002200952i580f5f26ifa69e0fb3d57418b@mail.gmail.com> On Sat, Feb 20, 2010 at 2:42 PM, Shashwat Anand wrote: > A quick solution I came out with, no stirling numbers and had tried to avoid > large integer multiplication as much as possible. > > import math > > for i in range(int(raw_input())): > ??? n, k, l = [int(i) for i in raw_input().split()] > ??? e = sum(math.log10(i) for i in range(1, n+1)) > frac_e = e - math.floor(e) This isn't going to give you enough accuracy when n gets large (and the original problem seems to allow n to be as large as 10**8), for the reasons I described earlier---that is, Python floats only give you around 16 decimal digits of precision; your 'e' value will already have used up some of those 16 digits before the point, leaving you fewer than 16 digits of precision after the point, so the absolute error in frac_e will likely be larger than 1e-15. That's not good enough for getting the first 15 digits of 10**frac_e accurately. For large n, you'll also be accumulating significant error in the sum. > a = str(10**frac_e * 10**(k - 1)).split('.')[0] The str(...).split('.') here doesn't do a good job of extracting the integer part when its argument is >= 1e12, since Python produces a result in scientific notation. I think you're going to get strange results when k >= 13. -- Mark From python at mrabarnett.plus.com Sat Feb 20 13:00:59 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 18:00:59 +0000 Subject: Building a dict from a tuple of tuples In-Reply-To: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> Message-ID: <4B80235B.2030201@mrabarnett.plus.com> vsoler wrote: > Hello everyone! > > I have a tuple of tuples, coming from an Excel range, such as this: > > ((None, u'x', u'y'), > (u'a', 1.0, 7.0), > (u'b', None, 8.0)) > > I need to build a dictionary that has, as key, the row and column > header. > > For example: > d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } > > As you can see, if the value in the matrix is None, no key has to be > added to the dictionary. > > Of course, my tuple of tuples is a lot bigger. > > How can I possibly do this? > > Thank you Does this help? matrix = ((None, u'x', u'y'), (u'a', 1.0, 7.0), (u'b', None, 8.0)) for row in matrix[1 : ]: for col, val in zip(matrix[0][1 : ], row[1 : ]): print row[0], col, val From martin.hellwig at dcuktec.org Sat Feb 20 13:28:16 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 20 Feb 2010 18:28:16 +0000 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> Message-ID: On 02/20/10 00:20, MattB wrote: > > Also, based on Martin's comment, I just wanted to make you all aware > that I intend no misuse, but rather am just trying to learn, as I'm a > programming noob. It wasn't my intention to imply that, rather the opposite, that if some BOFH would see your action as misuse (some admins are pretty trigger happy), you would expect them to contact you directly (I would). Even though you are on a wireless there are ways to track you down. For example I would search my log to see if I can make an association between a login to one of my servers and your mac address. BTW, I always followed the philosophy that learning is much more fun if you can brake/blow something up. Thus on my networks all students had a lot of freedom to do whatever they think was appropriate but they where aware that every action on my network was monitored and logged. -- mph From __peter__ at web.de Sat Feb 20 13:32:33 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 20 Feb 2010 19:32:33 +0100 Subject: Pure virtual functions in Python? References: Message-ID: lallous wrote: > How can I do something similar to pure virtual functions in C++ ? http://docs.python.org/library/abc.html#abc.abstractmethod Peter From anand.shashwat at gmail.com Sat Feb 20 13:34:14 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 21 Feb 2010 00:04:14 +0530 Subject: the mystery of dirname() In-Reply-To: <4B80209A.9080807@mrabarnett.plus.com> References: <4B7F5187.3060806@mrabarnett.plus.com> <4B7F5435.2020704@mrabarnett.plus.com> <4B80209A.9080807@mrabarnett.plus.com> Message-ID: got it. thanks. :) On Sat, Feb 20, 2010 at 11:19 PM, MRAB wrote: > Shashwat Anand wrote: > >> basically I infer that : dirname = path - basename, like for path = >> '//x', basename = x, hence dirname = '//' >> >> [snip] > Basically, os.path.dirname() should return the directory name, which > means dropping everything after the last slash, and also the last slash. > However, there's the special case where the name is in the root > directory, and you want to retain the slash(es). > > When building a path (os.path.join()) you want to join the parts with a > single slash between them, but there's the special case when a part is > the root directory, and you don't want to add a slash between them, eg > os.part.join('/x', 'y') should return '/x/y', but os.part.join('/', 'x') > should return '/x'. > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 20 13:44:29 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 21 Feb 2010 00:14:29 +0530 Subject: Precision issue in python In-Reply-To: <5c6f2a5d1002200952i580f5f26ifa69e0fb3d57418b@mail.gmail.com> References: <5c6f2a5d1002200952i580f5f26ifa69e0fb3d57418b@mail.gmail.com> Message-ID: @Mark, The str(...).split('.') here doesn't do a good job of extracting the > integer part when its argument is >= 1e12, since Python produces a > result in scientific notation. I think you're going to get strange > results when k >= 13. > Yeah, you were correct. I tested it for k >= 13, and there were issues i.e. only one character is printed. Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python CALCULAT.py 3 1000000 12 12 826393051664 000000000000 1000000 13 13 8 0000000000000 100 15 4 9 0000 The logic I tried was : for alpha = n! log(alpha) = log(n!) = log(n) + log(n-1) + .. log(2) + log(1) = e [where e = log(n) + .... + log(1)] frac_e = {e} (fractional part of e, like {1.23} = .23) now last k digits of alpha = 10**frac_e * 10**(k - 1) As I can see, the method is mathematically sound, and there is precision issues. Time for code modification. ~l0nwlf -------------- next part -------------- An HTML attachment was scrubbed... URL: From mikko at redinnovation.com Sat Feb 20 13:48:42 2010 From: mikko at redinnovation.com (Mikko Ohtamaa) Date: Sat, 20 Feb 2010 10:48:42 -0800 (PST) Subject: Compiling and running 32-bit Python on 64-bit server? Message-ID: Hi, Some server-side Python applications are limited by memory usage (hint: Zope), because Python effective uses processes and not threads for multiprocessing. This is especially true for 64-bit platforms, since Python programs are all about references and objects and 64-bit effectively doubles reference size. Some benchmarks 32-bit vs. 64-bit were discussed here: http://jstahl.org/archives/2010/01/2...ks-python-2-6/ How one could create 32-bit Python run-time enviroment, preferable virtualenv, on 64-bit Linux (VPS), reducing memory usage? This environment could actually beat 64-bit in performance, due to better memory cache use. I assume this involves having lib32 libs and compiling Python with some magical switches. Cheers, Mikko From vicente.soler at gmail.com Sat Feb 20 14:00:06 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 20 Feb 2010 11:00:06 -0800 (PST) Subject: Building a dict from a tuple of tuples References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> Message-ID: <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> On Feb 20, 7:00?pm, MRAB wrote: > vsoler wrote: > > Hello everyone! > > > I have a tuple of tuples, coming from an Excel range, such as this: > > > ((None, u'x', u'y'), > > (u'a', 1.0, 7.0), > > (u'b', None, 8.0)) > > > I need to build a dictionary that has, as key, the row and column > > header. > > > For example: > > d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } > > > As you can see, if the value in the matrix is None, no key has to be > > added to the dictionary. > > > Of course, my tuple of tuples is a lot bigger. > > > How can I possibly do this? > > > Thank you > > Does this help? > > matrix = ((None, u'x', u'y'), > (u'a', 1.0, 7.0), > (u'b', None, 8.0)) > > for row in matrix[1 : ]: > ? ? ?for col, val in zip(matrix[0][1 : ], row[1 : ]): > ? ? ? ? ?print row[0], col, val and the dictionary? it is the ultimate goal of what I am intending... Thank you From gherron at islandtraining.com Sat Feb 20 14:13:45 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 20 Feb 2010 11:13:45 -0800 Subject: os.pipe() + os.fork() In-Reply-To: <20100220125250.35c9937d@gurka> References: <20100220113604.49b7c242@gurka> <20100220125250.35c9937d@gurka> Message-ID: <4B803469.7010406@islandtraining.com> Sebastian Noack wrote: > I have figured out that, you have to close the writing end in the child > process, which is reading from the pipe. Otherwise the underlying pipe > is not going to be closed when the parent process is closing its > writing end. This has nothing to do with Python itself. I have tried > plain C and there it is the same behaviour. > > Regards > Sebastian Noack > Correct. The fork creates two processes with references to the read and write ends of the pipe. Both parent and child processes should close the ends they are not using. Here's a thought: Consider the subprocess module. It can do the fork and any necessary pipes and can do so in an OS independent way. It might make you life much easier. Gary Herron From martin at v.loewis.de Sat Feb 20 14:18:05 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sat, 20 Feb 2010 20:18:05 +0100 Subject: Compiling and running 32-bit Python on 64-bit server? In-Reply-To: References: Message-ID: <4B80356D.8000209@v.loewis.de> > How one could create 32-bit Python run-time enviroment, preferable > virtualenv, on 64-bit Linux (VPS), reducing memory usage? I'd install a 32-bit Linux on the hardware, and install a bigmem kernel if it has more than 3GB of main memory. > I assume this involves having lib32 libs and compiling Python with > some magical switches. The precise set of packages that you will need depends on the specific Linux distribution. Check whether "gcc -m32" can build a hello-world program. Then, set CC to "gcc -m32", and follow the build instructions in Python's README file. Regards, Martin From fallenblood at gmail.com Sat Feb 20 14:25:46 2010 From: fallenblood at gmail.com (egasimus) Date: Sat, 20 Feb 2010 11:25:46 -0800 (PST) Subject: if not global -- then what? Message-ID: Hi, newbie here. I've read on using the 'global' keyword being discouraged; then what is the preferred way to have something, for example a class containing program settings, accessible from everywhere, in a program spanning multiple files? From python at mrabarnett.plus.com Sat Feb 20 14:54:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 19:54:20 +0000 Subject: Building a dict from a tuple of tuples In-Reply-To: <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> Message-ID: <4B803DEC.7060304@mrabarnett.plus.com> vsoler wrote: > On Feb 20, 7:00 pm, MRAB wrote: >> vsoler wrote: >>> Hello everyone! >>> I have a tuple of tuples, coming from an Excel range, such as this: >>> ((None, u'x', u'y'), >>> (u'a', 1.0, 7.0), >>> (u'b', None, 8.0)) >>> I need to build a dictionary that has, as key, the row and column >>> header. >>> For example: >>> d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } >>> As you can see, if the value in the matrix is None, no key has to be >>> added to the dictionary. >>> Of course, my tuple of tuples is a lot bigger. >>> How can I possibly do this? >>> Thank you >> Does this help? >> >> matrix = ((None, u'x', u'y'), >> (u'a', 1.0, 7.0), >> (u'b', None, 8.0)) >> >> for row in matrix[1 : ]: >> for col, val in zip(matrix[0][1 : ], row[1 : ]): >> print row[0], col, val > > and the dictionary? > > it is the ultimate goal of what I am intending... > > Thank you The difficult bit is working out how to produce the keys and values for the dict from the tuple of tuples, and I've shown you that. The rest is straightforward. From python at mrabarnett.plus.com Sat Feb 20 15:00:23 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 20 Feb 2010 20:00:23 +0000 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <4B803F57.6010008@mrabarnett.plus.com> egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? Python's 'global' keyword is global in a file (module), not global across multiple files, so it would have helped you anyway. If you want program settings accessible across multiple modules then put the settings in a module and import that module in any other module that needs to access them. From gherron at islandtraining.com Sat Feb 20 15:00:32 2010 From: gherron at islandtraining.com (Gary Herron) Date: Sat, 20 Feb 2010 12:00:32 -0800 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <4B803F60.8010603@islandtraining.com> egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? > Define your "global" in a module (a .py file) and import that wherever you need it: mod.py: gvar = 123 # A Global (like) value main.py: import mod ... mod.gvar ... # To access the value ... mod.gvar = 456 ... #To change the value Using the "global" keyword has nothing to do with this. And in fact Python does not even have global variables in the sense you may be thinking. If you wish to provide a function in mode.py that sets the value then this would fail mod.py: gvar=123 def SetGvar(v): gvar = v because the gvar inside the function is local to that function. This is the proper place to use the "global" keyword. mode.py: gvar = 123 def SetGvar(v): global gvar # Makes gvar refer to the (global) module level gvar gvar = v Gary Herron From krister.svanlund at gmail.com Sat Feb 20 15:02:46 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sat, 20 Feb 2010 21:02:46 +0100 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <2cf430a61002201202je3ebeddv6f20639146f0b595@mail.gmail.com> On Sat, Feb 20, 2010 at 8:25 PM, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? > -- > http://mail.python.org/mailman/listinfo/python-list > There is probably a smarter way but I would recommend passing a settings object around. From ivlenin at gmail.com Sat Feb 20 15:04:21 2010 From: ivlenin at gmail.com (I V) Date: 20 Feb 2010 21:04:21 +0100 Subject: Pure virtual functions in Python? References: Message-ID: <4b804045$1@news.x-privat.org> On Sat, 20 Feb 2010 08:12:01 -0800, lallous wrote: > How can I do something similar to pure virtual functions in C++ ? >From what you want, it seems like you want cb() to not be called if it isn't implemented in the derived class; this isn't really what pure virtual functions in C++ do - pure virtual functions enforce, at compile time, that the derived class implements the method. If you have a situation when you want to either call a derived class's version of cb(), or do nothing, can you not just have an implementation of cb() in the base class that does nothing, i.e. class C1(object): def cb(self, param1, param2): pass From cdalten at gmail.com Sat Feb 20 15:46:24 2010 From: cdalten at gmail.com (chad) Date: Sat, 20 Feb 2010 12:46:24 -0800 (PST) Subject: How would I do a continuous write over a pipe in the following code... Message-ID: <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com> Given the following.... #!/usr/bin/python import subprocess as s broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE) out = broadcast.stdout while 1: out broadcast.wait() broadcast.stdout.close() The code only executes once. What I want to do is be able to continuously write over the pipe once it is open. I could put s.Popen() inside the while loop, but that seems a bit too messy. So is there some way to just open the pipe once, and once it is open, just continuously write over it vs just opening and closing the pipe every time? From vicente.soler at gmail.com Sat Feb 20 16:25:53 2010 From: vicente.soler at gmail.com (vsoler) Date: Sat, 20 Feb 2010 13:25:53 -0800 (PST) Subject: Building a dict from a tuple of tuples References: <8b2ae929-513f-4508-8a53-9011e4d0b97f@v20g2000yqv.googlegroups.com> <22502d6d-18bd-4df7-be80-aa5150e16405@o30g2000yqb.googlegroups.com> Message-ID: On Feb 20, 8:54?pm, MRAB wrote: > vsoler wrote: > > On Feb 20, 7:00 pm, MRAB wrote: > >> vsoler wrote: > >>> Hello everyone! > >>> I have a tuple of tuples, coming from an Excel range, such as this: > >>> ((None, u'x', u'y'), > >>> (u'a', 1.0, 7.0), > >>> (u'b', None, 8.0)) > >>> I need to build a dictionary that has, as key, the row and column > >>> header. > >>> For example: > >>> d={ (u'a',u'x'):1.0, (u'a',u'y'): 7.0, (u'b',u'y'):8.0 } > >>> As you can see, if the value in the matrix is None, no key has to be > >>> added to the dictionary. > >>> Of course, my tuple of tuples is a lot bigger. > >>> How can I possibly do this? > >>> Thank you > >> Does this help? > > >> matrix = ((None, u'x', u'y'), > >> (u'a', 1.0, 7.0), > >> (u'b', None, 8.0)) > > >> for row in matrix[1 : ]: > >> ? ? ?for col, val in zip(matrix[0][1 : ], row[1 : ]): > >> ? ? ? ? ?print row[0], col, val > > > and the dictionary? > > > it is the ultimate goal of what I am intending... > > > Thank you > > The difficult bit is working out how to produce the keys and values for > the dict from the tuple of tuples, and I've shown you that. The rest is > straightforward. I'll try. Thank you very much MRAB From gnarlodious at gmail.com Sat Feb 20 16:28:55 2010 From: gnarlodious at gmail.com (Gnarlodious) Date: Sat, 20 Feb 2010 13:28:55 -0800 (PST) Subject: Shared web host good citizenship question References: Message-ID: <59e76f4d-2493-411d-9cef-5420483550f1@z10g2000prh.googlegroups.com> I would say like this: If your processes are serving up straight pages, let them timeout after a while. If your processes are handling eCommerce or persistent data, keep the connection open as long as possible. -- Gnarlie From jim.hefferon at gmail.com Sat Feb 20 16:41:15 2010 From: jim.hefferon at gmail.com (Jim) Date: Sat, 20 Feb 2010 13:41:15 -0800 (PST) Subject: finding element by tag in xml References: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> Message-ID: On Feb 20, 11:27 am, sWrath swrath wrote: > 2 Questions > > 1. Why can't I use dom.getElementsByTagName('book') in #Error 1? How > do i print the elements ? > Error- AttributeError: ElementTree instance has no attribute > 'getElementsByTagName' I only see one question here. I think the error is asserting that your instance of the ET class does not have such a fcn. I also do not see it in the ET documentation. Perhaps you are looking for the XPath support at http://effbot.org/zone/element-xpath.htm ? Or perhaps you want to make your document dom representation via a different library? Jim From digitalxero at gmail.com Sat Feb 20 16:56:09 2010 From: digitalxero at gmail.com (Dj Gilcrease) Date: Sat, 20 Feb 2010 14:56:09 -0700 Subject: finding element by tag in xml In-Reply-To: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> References: <871883dd-eb99-4de4-b70f-df09234c8630@s25g2000prd.googlegroups.com> Message-ID: On Sat, Feb 20, 2010 at 9:27 AM, sWrath swrath wrote: > from xml.dom.minidom import parse > from xml.etree.ElementTree import* > > file1="book.xml" > tmptree=ElementTree() > tmptree.parse(file1) > items=root.getiterator() > > > dom = parse(file1) > > > #Find tag names > for node in items : > ? ?if node.tag == 'author': #Get tag > ? ? ? ?print dom.getElementsByTagName ('book') #Error 1 You are mixing two different types of xml parsers, either user minidom for node in dom.getElementsByTagName('author'): print node.getElementsByTagName('book') or use etree for el in items: if el.tag == 'author': print el.find('book') There are a few differences you need to note, the getElementsByTagName always returns a list even if there is only 1 element and find only returns the first element found no matter what. If you want to print all books associated with an author you would need to do something like for author in tmptree.getiterator('author'): for book in author.getiterator('book'): print book From arnodel at googlemail.com Sat Feb 20 17:02:44 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 20 Feb 2010 22:02:44 +0000 Subject: Pure virtual functions in Python? References: Message-ID: lallous writes: > Hello > > How can I do something similar to pure virtual functions in C++ ? > > Let us consider this: > > class C1: > > # Pure virtual > def cb(self, param1, param2): > """ > This is a callback > > @param param1: ... > @param param2: ... > """ > raise NotImplementedError, "Implement me" Why define it if it is virtual? > # Implementation w/o a 'cb', thus 'cb' should not be used > class C2(C1): > def __init__(self): > pass > > # Implementation w/ 'cb', thus 'cb' can be used > class C3(C1): > def __init__(self): > pass > > def cb(self, param1, param2): > print "i am c3 cb" > > # Dispatcher function that calls 'cb' only if 'cb' is implemented in > child classes > def dispatcher(c): > if hasattr(c, 'cb'): > c.cb("Hello", "World") > > dispatcher(C2()) > dispatcher(C3()) > > What I want is the ability to have the dispatcher() not to call 'cb' > if it was not implemented in one of the child classes. If you don't define cb in the parent class, it'll work. -- Arnaud From norman at smash-net.org Sat Feb 20 17:12:50 2010 From: norman at smash-net.org (=?ISO-8859-15?Q?Norman_Rie=DF?=) Date: Sat, 20 Feb 2010 23:12:50 +0100 Subject: Reading a large bz2 textfile exits early Message-ID: <4B805E62.5070909@smash-net.org> Hello, i am trying to read a large bz2 compressed textfile using the bz2 module. The file is 1717362770 lines long and 8GB large. Using this code source_file = bz2.BZ2File(file, "r") for line in source_file: print line.strip() print "Exiting" print "I used file: " + file the loop exits cleanly after 4311 lines in midline and the prints are executed. This happened on two different boxes runnig different brands of linux. Is there something i miss or should be done differently? Thank you. Regards, Norman From olaye1977 at googlemail.com Sat Feb 20 18:03:27 2010 From: olaye1977 at googlemail.com (V8 NUT) Date: Sat, 20 Feb 2010 15:03:27 -0800 (PST) Subject: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4 Message-ID: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> Been trying to fix this issue for over 6 hours now. It's doin my head in, any one know whats going on here. ==START== python setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.4/MySQLdb running build_ext building '_mysql' extension gcc -pthread -shared build/temp.linux-x86_64-2.4/_mysql.o -L/usr/lib64/ mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm - lpthread -lssl -lcrypto -o build/lib.linux-x86_64-2.4/_mysql.so /usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz /usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for - lz /usr/bin/ld: cannot find -lz collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 ==END== Am trying to get MySQL-python-1.2.3c1 installed on a CentOS 5 box running Python 2.4 I do not want to upgrade my Python version. I have tried: 1. yum install mysql-python 2. yum install librsync-devel 3. yum install python-devel With all return no errors and a notification that there's nothing to install or update. Please help. From astan.chee at al.com.au Sat Feb 20 18:07:32 2010 From: astan.chee at al.com.au (Astan Chee) Date: Sun, 21 Feb 2010 10:07:32 +1100 Subject: calculating a string equation In-Reply-To: References: Message-ID: <4B806B34.1070508@al.com.au> Arnaud Delobelle wrote: > Astan Chee writes: > > >> Hi, >> I have some variables in my script that looks like this: >> vars = {'var_a':'10','var_b':'4'} >> eqat = "(var_a/2.0) <= var_b" >> result = "(var_a+var_b)/7" >> What I'm trying to do is to plug in var_a and var_b's values from vars >> into eqat and see if eqat returns true or false as well as getting the >> value of result if these variables were "plugged in". How do I do >> this? >> I'm also expecting eqat and result to contain various python >> mathematical operators like **, and compounded ()'s. >> I'm not sure how to convert the equation; if I have to make a bunch of >> if-statements or if there is a python function that already does >> something like this. >> > > Yes: eval() > > >>>> vars = {'var_a':10 ,'var_b':4} >>>> eqat = "(var_a/2.0) <= var_b" >>>> result = "(var_a+var_b)/7" >>>> eval(eqat, vars) >>>> > False Hi, I now have a slight problem with this. This doesnt seem to work: >>> vars = {'var a':10 ,'var b':4} >>> eqat = "(var a/2.0) <= var b" >>> eval(eqat, vars) Traceback (most recent call last): File "", line 1, in eval(eqat, vars) File "", line 1 (var a/2.0) <= var b ^ SyntaxError: invalid syntax So eval can't take spaces? is there a way to go around this? Thanks again for any suggestions Cheers Astan -------------- next part -------------- An HTML attachment was scrubbed... URL: From clp2 at rebertia.com Sat Feb 20 18:21:50 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Feb 2010 15:21:50 -0800 Subject: calculating a string equation In-Reply-To: <4B806B34.1070508@al.com.au> References: <4B806B34.1070508@al.com.au> Message-ID: <50697b2c1002201521w73905736o30760b7924663b89@mail.gmail.com> On Sat, Feb 20, 2010 at 3:07 PM, Astan Chee wrote: > Arnaud Delobelle wrote: > Astan Chee writes: > Hi, > I have some variables in my script that looks like this: > vars = {'var_a':'10','var_b':'4'} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > What I'm trying to do is to plug in var_a and var_b's values from vars > into eqat and see if eqat returns true or false as well as getting the > value of result if these variables were "plugged in". How do I do > this? > I'm also expecting eqat and result to contain various python > mathematical operators like **, and compounded ()'s. > I'm not sure how to convert the equation; if I have to make a bunch of > if-statements or if there is a python function that already does > something like this. > > > Yes: eval() > > > > vars = {'var_a':10 ,'var_b':4} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > eval(eqat, vars) > > > False > > Hi, > I now have a slight problem with this. This doesnt seem to work: >>>> vars = {'var a':10 ,'var b':4} >>>> eqat = "(var a/2.0) <= var b" >>>> eval(eqat, vars) > > Traceback (most recent call last): > ? File "", line 1, in > ??? eval(eqat, vars) > ? File "", line 1 > ??? (var a/2.0) <= var b > ???????? ^ > SyntaxError: invalid syntax > > So eval can't take spaces? is there a way to go around this? eval() requires the string be valid Python code and conform to Python's syntax. Obviously your string isn't valid Python. You can either require beforehand that variables not be prefixed with "var " as they are currently, or you can get rid of the "var"s yourself: vars = {'a':10 ,'b':4} equat = equat.replace('var ','') eval(equat, vars) but this could cause problems if you have a variable whose names ends with "var"; using a regular expression for the removal would fix that. Cheers, Chris -- http://blog.rebertia.com From stef.mientki at gmail.com Sat Feb 20 18:52:33 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Sun, 21 Feb 2010 00:52:33 +0100 Subject: Is there a way to continue after an exception ? Message-ID: <4B8075C1.4090304@gmail.com> hello, I would like my program to continue on the next line after an uncaught exception, is that possible ? thanks Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Sat Feb 20 18:54:55 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 20 Feb 2010 15:54:55 -0800 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> Message-ID: DANNY wrote: > >If I want to have a MPEG-4/10 coded video and stream it through the >network and than have the same video on the client side, what should I >use and of course I don't want to have raw MPEG data, because than I >couldn't extract the frames to manipulate them. If you want to manipulate the frames (as bitmaps), then you have little choice but to decode the MPEG as you receive it, manipulate the bitmaps, and re-encode it back to MPEG. That's going to take a fair amount of time... -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From krister.svanlund at gmail.com Sat Feb 20 18:59:40 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Sun, 21 Feb 2010 00:59:40 +0100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4B8075C1.4090304@gmail.com> References: <4B8075C1.4090304@gmail.com> Message-ID: <2cf430a61002201559i1819944cre605f3904f06c541@mail.gmail.com> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: > hello, > > I would like my program to continue on the next line after an uncaught > exception, > is that possible ? > > thanks > Stef Mientki > Yes, you catch the exception and do nothing. From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 19:00:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 00:00:05 GMT Subject: if not global -- then what? References: Message-ID: <4b807784$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 11:25:46 -0800, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from everywhere, > in a program spanning multiple files? Such a thing is no different from keeping many global settings. It's not the global KEYWORD that is discouraged, but the over-use of global variables itself. See, for example: http://c2.com/cgi/wiki?GlobalVariablesAreBad http://weblogs.asp.net/wallen/archive/2003/05/08/6750.aspx In a nutshell: shared variables introduce tight coupling between parts of your code that should be independent. Whether they are truly global, or passed around in a Settings object, makes little or no difference. In both cases, the risks and problems are identical. Let me give a fanciful example: suppose your refrigerator, oven and shower all shared a single global temperature setting instead of having three local temperature settings. This would be a recipe for disaster: every operation to any of the three would need to carefully save the current temperature setting, and there's the constant risk of scalding showers, ruined foods, and undercooked meals. Having three different global temperature settings helps a bit, but that just expands the number of variables that everything has access too. Why do the television and the garage door need access to any temperature setting, let alone all three? Python globals aren't as bad as in some other languages, because "global" means global to a single module, not global to the entire program, but if you create a Settings object and import it from module to module, you break the encapsulation, *and* you then have the problem of needing to make sure it is initialised properly. http://archive.eiffel.com/doc/manuals/technology/bmarticles/joop/globals.html Global constants also aren't as bad, because the coupling is weaker. Unfortunately Python doesn't have constants, except by convention, so there's always the risk that some badly-behaved function might decide to redefine (say) math.pi to 3.15. Unfortunately, you probably can't get rid of globals altogether, but the tricks are (1) use as few of them as possible, and (2) make them local as quickly as possible. For example, you might have something like this: default_header = "My special header" # A global for option, argument in command_line: if option == "--header": default_header = argument class Printer: def print_page(self, text, header=None): if header is None: header = default_header print header print text I would limit the scope of default_header so that it was local to the printer class: for option, argument in command_line: if option == "--header": Printer.default_header = argument class Printer: default_header = "My special header" def print_page(self, text, header=None): if header is None: header = self.default_header print header print text You might not be able to completely eliminate either globals, or a Settings object, but you should be able to make it much, much smaller. In practice, to make testing easier, I'd split the command line processing into two steps: a function that reads and processes the command line into a single local settings object, then a separate function that applies those settings to the various classes. The function that reads the command line doesn't need to know where the settings eventually end up, and the function that applies the settings doesn't need to know where they come from. All the coupling between settings and classes is in one place, the second function, instead of scattered all over your code. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 19:00:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 00:00:17 GMT Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> Message-ID: <4b807791$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 18:28:16 +0000, Martin P. Hellwig wrote: > On 02/20/10 00:20, MattB wrote: > >> >> Also, based on Martin's comment, I just wanted to make you all aware >> that I intend no misuse, but rather am just trying to learn, as I'm a >> programming noob. > > It wasn't my intention to imply that, rather the opposite, that if some > BOFH would see your action as misuse (some admins are pretty trigger > happy), you would expect them to contact you directly (I would). Even > though you are on a wireless there are ways to track you down. For > example I would search my log to see if I can make an association > between a login to one of my servers and your mac address. This may be what you would do, but in my experience, it is more likely that the admin would be far too busy and/or lazy to try to track you down unless (1) they wanted to give you a warning prior to expulsion, or (2) they needed to know who you were prior to laying charges. In my experience they're far more likely to just hit the problem with a hammer by blocking you as much as is technically possible. > BTW, I always followed the philosophy that learning is much more fun if > you can brake/blow something up. Thus on my networks all students had a > lot of freedom to do whatever they think was appropriate but they where > aware that every action on my network was monitored and logged. Unfortunately this is the exception rather than the rule, I think. -- Steven From lie.1296 at gmail.com Sat Feb 20 19:21:09 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 11:21:09 +1100 Subject: Is there a way to continue after an exception ? In-Reply-To: References: <4B8075C1.4090304@gmail.com> Message-ID: <4b807c90$1@dnews.tpgi.com.au> > On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: >> hello, >> >> I would like my program to continue on the next line after an uncaught >> exception, >> is that possible ? >> >> thanks >> Stef Mientki >> That reminds me of VB's "On Error Resume Next" From vincent at vincentdavis.net Sat Feb 20 19:21:11 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 17:21:11 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> Message-ID: <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> Thanks for the help, this is considerably faster and easier to read (see below). I changed it to avoid the "break" and I think it makes it easy to understand. I am checking the conditions each time slows it but it is worth it to me at this time. Thanks again Vincent def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') data = [] mask = [] outliers = [] modified = [] data_append = data.append mask_append = mask.append outliers_append = outliers.append modified_append = modified.append maskcount = 0 outliercount = 0 modifiedcount = 0 for row in reader: if '[MASKS]' in row: maskcount += 1 if '[OUTLIERS]' in row: outliercount += 1 if '[MODIFIED]' in row: modifiedcount += 1 if not any((maskcount, outliercount, modifiedcount, not row)): data_append(row) elif not any((outliercount, modifiedcount, not row)): mask_append(row) elif not any((modifiedcount, not row)): outliers_append(row) else: if row: modified_append(row) data = data[1:] mask = mask[3:] outliers = outliers[3:] modified = modified[3:] return [data, mask, outliers, modified] *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Fri, Feb 19, 2010 at 4:36 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > > On Fri, Feb 19, 2010 at 1:58 PM, Vincent Davis wrote: > >> In reference to the several comments about "[x for x in read] is basically >> a copy of the entire list. This isn't necessary." or list(read). I had >> thought I had a problem with having iterators in the takewhile() statement. >> I thought I testes and it didn't work. It seems I was wrong. It clearly >> works. I'll make this change and see if it is any better. >> >> I actually don't plan to read them all in at once, only as needed, but I >> do need the whole file in an array to perform some mathematics on them and >> compare different files. So my interest was in making it faster to open them >> as needed. I guess part of it is that they are about 5mb so I guess it might >> be disk speed in part.nks >> >> > > Record your numbers in an array and then work your magic on them later. > Don't store the entire file in memory, though. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rzantow at gmail.com Sat Feb 20 19:25:10 2010 From: rzantow at gmail.com (rzed) Date: Sun, 21 Feb 2010 00:25:10 +0000 Subject: The Disappearing Program? References: Message-ID: "W. eWatson" wrote in news:hlls5c$89l$1 at news.eternal-september.org: > I've successfully compiled several small python programs on Win > XP into executables using py2exe. A program goes from a name like > snowball.py to snowball. A dir in the command prompt window finds > snowball.py but not snowball. If I type in snowball, it executes. > What's up with that? There is a ludicrous setting in Windows explorer that hides the extensions for known file types, such as .exe. If you see "snowball" in Win Explorer, that's probably the way your system is set. If you click on Tools . Folder Options . View you should see a checkbox for the "Hide extensions for known file types" option. Uncheck it, and the disappearing program will return to view. This is a separate issue for why snowball.py executes when you enter "snowball" at the command line. -- rzed From fetchinson at googlemail.com Sat Feb 20 19:32:53 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 21 Feb 2010 01:32:53 +0100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4B8075C1.4090304@gmail.com> References: <4B8075C1.4090304@gmail.com> Message-ID: > I would like my program to continue on the next line after an uncaught > exception, > is that possible ? try: # here is your error except: pass # this will get executed no matter what See http://docs.python.org/tutorial/errors.html HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From timr at probo.com Sat Feb 20 19:49:57 2010 From: timr at probo.com (Tim Roberts) Date: Sat, 20 Feb 2010 16:49:57 -0800 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: Chris Rebert wrote: >On Thu, Feb 18, 2010 at 11:58 AM, John Nagle wrote: >> >> ? Python isn't ready for this. ?Not with the GIL. > >Is any language, save perhaps Erlang, really ready for it? F# is. I only wish the syntax was a little less Perl-like. Too many special characters. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From marwie at gmx.de Sat Feb 20 19:55:10 2010 From: marwie at gmx.de (marwie) Date: Sat, 20 Feb 2010 16:55:10 -0800 (PST) Subject: Efficient way to break up a list into two pieces Message-ID: Hello, I recently read about augmented assignments and that (with l1, l2 being lists) l1.extend(l2) is more efficient than l1 = l1 + l2 because unnecessary copy operations can be avoided. Now my question is if there's a similar thing for breaking a list into two parts. Let's say I want to remove from l1 everything from and including position 10 and store it in l2. Then I can write l2 = l1[10:] del l1[10:] But since I'm assigning a slice the elements will be copied. Basically, I'm looking for something like l1.pop(10,len(l1)) which returns and removes a whole chunk of data. Is there such a thing (and if not, why not?) Cheers, Martin. From python at mrabarnett.plus.com Sat Feb 20 19:56:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Feb 2010 00:56:53 +0000 Subject: The Disappearing Program? In-Reply-To: References: Message-ID: <4B8084D5.2010006@mrabarnett.plus.com> rzed wrote: > "W. eWatson" wrote in > news:hlls5c$89l$1 at news.eternal-september.org: > >> I've successfully compiled several small python programs on Win >> XP into executables using py2exe. A program goes from a name like >> snowball.py to snowball. A dir in the command prompt window finds >> snowball.py but not snowball. If I type in snowball, it executes. >> What's up with that? > > There is a ludicrous setting in Windows explorer that hides the > extensions for known file types, such as .exe. If you see "snowball" > in Win Explorer, that's probably the way your system is set. If you > click on Tools . Folder Options . View you should see a checkbox for > the "Hide extensions for known file types" option. Uncheck it, and the > disappearing program will return to view. > The problem with that setting is that an .exe file could masquerade as some other type, eg "foo.txt.exe" would appear as "foo.txt", so you might have thought that you were safe opening it because it's just text. > This is a separate issue for why snowball.py executes when you enter > "snowball" at the command line. > From vincent at vincentdavis.net Sat Feb 20 20:05:35 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:05:35 -0700 Subject: Not sure why this is filling my sys memory Message-ID: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> Code is below, The files are about 5mb and 230,000 rows. When I have 43 files of them and when I get to the 35th (reading it in) my system gets so slow that it is nearly functionless. I am on a mac and activity monitor shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). The getsizeof() returns 6424 bytes for the alldata . So I am not sure what is happening. Any ideas Thanks *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Sat Feb 20 20:06:36 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:06:36 -0800 Subject: Efficient way to break up a list into two pieces In-Reply-To: References: Message-ID: <6cc20cea1002201706k27236296qcaa20e7580ed710d@mail.gmail.com> On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 > being lists) > > ? ?l1.extend(l2) > > is more efficient than > > ? ?l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if there's a similar thing for breaking a list into two parts. Let's > say I want to remove from l1 everything from and including position 10 > and store it in l2. Then I can write > > ? ?l2 = l1[10:] > ? ?del l1[10:] > > But since I'm assigning a slice the elements will be copied. > Basically, I'm looking for something like l1.pop(10,len(l1)) which > returns and removes a whole chunk of data. Is there such a thing (and > if not, why not?) > The idiom is: >>> l1, l2 = l1[:10], l1[10:] Don't know if it's optimized or not. If it's not, it could probably be. This is a really common idiom. -- Jonathan Gardner jgardner at jonathangardner.net From vincent at vincentdavis.net Sat Feb 20 20:07:59 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:07:59 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> Message-ID: <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> > Code is below, The files are about 5mb and 230,000 rows. When I have 43 > files of them and when I get to the 35th (reading it in) my system gets so > slow that it is nearly functionless. I am on a mac and activity monitor > shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). > The getsizeof() returns 6424 bytes for the alldata . So I am not sure what > is happening. > Any ideas > Thanks > > import csv, os, glob import sys def read_data_file(filename): reader = csv.reader(open(filename, "U"),delimiter='\t') data = [] mask = [] outliers = [] modified = [] data_append = data.append mask_append = mask.append outliers_append = outliers.append modified_append = modified.append maskcount = 0 outliercount = 0 modifiedcount = 0 for row in reader: if '[MASKS]' in row: maskcount += 1 if '[OUTLIERS]' in row: outliercount += 1 if '[MODIFIED]' in row: modifiedcount += 1 if not any((maskcount, outliercount, modifiedcount, not row)): data_append(row) elif not any((outliercount, modifiedcount, not row)): mask_append(row) elif not any((modifiedcount, not row)): outliers_append(row) else: if row: modified_append(row) data = data[1:] mask = mask[3:] outliers = outliers[3:] modified = modified[3:] return [data, mask, outliers, modified] def ImportDataFrom(folder): print 'Importing files from: ', folder alldata = dict() infolder = glob.glob( os.path.join(folder, '*.txt') ) numfiles = len(infolder) print 'Importing ' + str(numfiles) + ' files from: ', folder for infile in infolder: print "Loading into memory: " + os.path.split(infile)[1] fname = os.path.split(infile)[1] filedata = dict(zip([fname + '_data', fname + '_mask', fname + '_outliers', fname+'_modified'], read_data_file(infile))) print fname + ' has ' + str(len(filedata[fname + '_data'])) + ' rows of data' print fname + ' has ' + str(len(filedata[fname + '_mask'])) + ' rows of masked data' print fname + ' has ' + str(len(filedata[fname + '_outliers'])) + ' rows of outliers' print fname + ' has ' + str(len(filedata[fname +'_modified'])) + ' modified rows of data' print str(sys.getsizeof(filedata)) +'bytes'' of memory used for '+ fname print ' ' alldata.update(filedata) print str(len(alldata)/4) + ' files of ' + str(numfiles) + ' using ' + str(sys.getsizeof(alldata)) + ' bytes of memory' return alldata ImportDataFrom("/Users/vmd/Dropbox/dna/data/rawdata") -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Sat Feb 20 20:12:01 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Sun, 21 Feb 2010 06:42:01 +0530 Subject: Efficient way to break up a list into two pieces In-Reply-To: <6cc20cea1002201706k27236296qcaa20e7580ed710d@mail.gmail.com> References: <6cc20cea1002201706k27236296qcaa20e7580ed710d@mail.gmail.com> Message-ID: You can always implement your own data-structures or simply a function if you need so. A language consist of building blocks and not buildings. On Sun, Feb 21, 2010 at 6:36 AM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: > > Hello, > > > > I recently read about augmented assignments and that (with l1, l2 > > being lists) > > > > l1.extend(l2) > > > > is more efficient than > > > > l1 = l1 + l2 > > > > because unnecessary copy operations can be avoided. Now my question is > > if there's a similar thing for breaking a list into two parts. Let's > > say I want to remove from l1 everything from and including position 10 > > and store it in l2. Then I can write > > > > l2 = l1[10:] > > del l1[10:] > > > > But since I'm assigning a slice the elements will be copied. > > Basically, I'm looking for something like l1.pop(10,len(l1)) which > > returns and removes a whole chunk of data. Is there such a thing (and > > if not, why not?) > > > > The idiom is: > > >>> l1, l2 = l1[:10], l1[10:] > > Don't know if it's optimized or not. If it's not, it could probably > be. This is a really common idiom. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Sat Feb 20 20:18:24 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:18:24 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> Message-ID: <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> On Sat, Feb 20, 2010 at 4:21 PM, Vincent Davis wrote: > Thanks for the help, this is considerably faster and easier to read (see > below). I changed it to avoid the "break" and I think it makes it easy to > understand. I am checking the conditions each time slows it but it is worth > it to me at this time. > > It seems you are beginning to understand that programmer time is more valuable than machine time. Congratulations. > def read_data_file(filename): > reader = csv.reader(open(filename, "U"),delimiter='\t') > > data = [] > mask = [] > outliers = [] > modified = [] > > data_append = data.append > mask_append = mask.append > outliers_append = outliers.append > modified_append = modified.append > > I know some people do this to speed things up. Really, I don't think it's necessary or wise to do so. > maskcount = 0 > outliercount = 0 > modifiedcount = 0 > > for row in reader: > if '[MASKS]' in row: > maskcount += 1 > if '[OUTLIERS]' in row: > outliercount += 1 > if '[MODIFIED]' in row: > modifiedcount += 1 > if not any((maskcount, outliercount, modifiedcount, not row)): > data_append(row) > elif not any((outliercount, modifiedcount, not row)): > mask_append(row) > elif not any((modifiedcount, not row)): > outliers_append(row) > else: > if row: modified_append(row) > > Just playing with the logic here: 1. Notice that if "not row" is True, nothing happens? Pull it out explicitly. 2. Notice how it switches from mode to mode? Program it more explicitly. Here's my suggestion: def parse_masks(reader): for row in reader: if not row: continue elif '[OUTLIERS]' in row: parse_outliers(reader) elif '[MODIFIED]' in row: parse_modified(reader) masks.append(row) def parse_outliers(reader): for row in reader: if not row: continue elif '[MODIFIED]' in row: parse_modified(reader) outliers.append(row) def parse_modified(reader): for row in reader: if not row: continue modified.append(row) for row in reader: if not row: continue elif '[MASKS]' in row: parse_masks(reader) elif '[OUTLIERS]' in row: parse_outliers(reader) elif '[MODIFIED]' in row: parse_modified(reader) else: data.append(row) Since there is global state involved, you may want to save yourself some trouble in the future and put the above in a class where separate parsers can be kept separate. It looks like your program is turning into a regular old parser. Any format that is a little more than trivial to parse will need a real parser like the above. -- Jonathan Gardner jgardner at jonathangardner.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 20:30:05 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 01:30:05 GMT Subject: Efficient way to break up a list into two pieces References: Message-ID: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 16:55:10 -0800, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 being > lists) > > l1.extend(l2) > > is more efficient than > > l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if there's a similar thing for breaking a list into two parts. Let's say > I want to remove from l1 everything from and including position 10 and > store it in l2. Then I can write > > l2 = l1[10:] > del l1[10:] > > But since I'm assigning a slice the elements will be copied. Yes, list slicing can't make any sort of assumptions about what you're going to do next, so when you take a slice, it has to copy the data. > Basically, > I'm looking for something like l1.pop(10,len(l1)) which returns and > removes a whole chunk of data. Is there such a thing (and if not, why > not?) Such a list pop would have to copy the data too. How else could it work? What exactly is the problem you are trying to solve? If you are unhappy that copy-and-remove a slice from a list takes two lines instead of one ("won't somebody think of the shortage of newlines!!!" *wink*), then just write a helper function and call that: def copy_and_remove(alist, slice): tmp = alist[slice] del alist[slice] return tmp l2 = copy_and_remove(l1, slice(10, None)) If you are unhappy that copying slices from lists copies data, well that's just the way things are. Don't make the mistake of trying to optimize your application before you actually know what bits need optimizing. Python lists are arrays of pointers to objects, so copying a slice is fast: it doesn't have to copy the objects, just pointers. Deleting from the end of the list is also quick, because you don't have to move memory, just clear some pointers and change the length field. Splitting such an array without copying data is, essentially, impossible. Python lists aren't linked lists. But as I said, most of the time copying slices doesn't matter: the time taken is unlikely to be a serious factor in practice. If it is (and you've profiled your code, right? you're not just guessing what you think is fast and slow?) then there may be ways to optimize your code to avoid needing to copy slices, but we'd need to know what you're doing with the data. -- Steven From vincent at vincentdavis.net Sat Feb 20 20:32:28 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:32:28 -0700 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> Message-ID: <77e831101002201732m17bb9b74q5c62e279a9bf83b4@mail.gmail.com> Thanks again for the comment, not sure I will implement all of it but I will separate the "if not row" The files have some extraneous blank rows in the middle that I need to be sure not to import as blank rows. I am actually having trouble with this filling my sys memory, I posted a separate question "Why is this filling my sys memory" or something like that is the subject. I might be that my 1yr old son has been trying to help for the last hour. It is very distracting. *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 6:18 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Sat, Feb 20, 2010 at 4:21 PM, Vincent Davis wrote: > >> Thanks for the help, this is considerably faster and easier to read (see >> below). I changed it to avoid the "break" and I think it makes it easy to >> understand. I am checking the conditions each time slows it but it is worth >> it to me at this time. >> >> > It seems you are beginning to understand that programmer time is more > valuable than machine time. Congratulations. > > > >> def read_data_file(filename): >> reader = csv.reader(open(filename, "U"),delimiter='\t') >> >> data = [] >> mask = [] >> outliers = [] >> modified = [] >> >> data_append = data.append >> mask_append = mask.append >> outliers_append = outliers.append >> modified_append = modified.append >> >> > > I know some people do this to speed things up. Really, I don't think it's > necessary or wise to do so. > > >> maskcount = 0 >> outliercount = 0 >> modifiedcount = 0 >> >> for row in reader: >> if '[MASKS]' in row: >> maskcount += 1 >> if '[OUTLIERS]' in row: >> outliercount += 1 >> if '[MODIFIED]' in row: >> modifiedcount += 1 >> if not any((maskcount, outliercount, modifiedcount, not row)): >> data_append(row) >> elif not any((outliercount, modifiedcount, not row)): >> mask_append(row) >> elif not any((modifiedcount, not row)): >> outliers_append(row) >> else: >> if row: modified_append(row) >> >> > > Just playing with the logic here: > > 1. Notice that if "not row" is True, nothing happens? Pull it out > explicitly. > > 2. Notice how it switches from mode to mode? Program it more explicitly. > > Here's my suggestion: > > def parse_masks(reader): > for row in reader: > if not row: continue > elif '[OUTLIERS]' in row: parse_outliers(reader) > elif '[MODIFIED]' in row: parse_modified(reader) > masks.append(row) > > def parse_outliers(reader): > for row in reader: > if not row: continue > elif '[MODIFIED]' in row: parse_modified(reader) > outliers.append(row) > > def parse_modified(reader): > for row in reader: > if not row: continue > modified.append(row) > > for row in reader: > if not row: continue > elif '[MASKS]' in row: parse_masks(reader) > elif '[OUTLIERS]' in row: parse_outliers(reader) > elif '[MODIFIED]' in row: parse_modified(reader) > else: data.append(row) > > Since there is global state involved, you may want to save yourself some > trouble in the future and put the above in a class where separate parsers > can be kept separate. > > It looks like your program is turning into a regular old parser. Any format > that is a little more than trivial to parse will need a real parser like the > above. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jgardner at jonathangardner.net Sat Feb 20 20:34:15 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:34:15 -0800 Subject: if not global -- then what? In-Reply-To: References: Message-ID: <6cc20cea1002201734t217d548elc9c79df9e61ddfb0@mail.gmail.com> On Sat, Feb 20, 2010 at 11:25 AM, egasimus wrote: > Hi, newbie here. I've read on using the 'global' keyword being > discouraged; then what is the preferred way to have something, for > example a class containing program settings, accessible from > everywhere, in a program spanning multiple files? One of the powerful concepts to come out of Lisp was "dynamic scope". This is the ideal solution for configuration and logging. "Lexical scope" is where the value of the variables are found in the file it was defined in. This is what Python does, and it's what you're used to in most other languages. "Dynamic scope" is where the value of the variables are found by looking up the call stack. This is similar to perl's "local" keyword. It's also similar to environment variables, if you consider programs that run programs that run programs as similar to functions. (If you're familiar with neither, then that's fine.) This is useful for a program where you know it needs configuration or logging, but you don't want to have to specify it as part of the program. Whoever calls the program needs to configure it and setup their logger before calling it. Unfortunately, there is no built-in way to deal with dynamic variables in Python. But that doesn't mean you can't emulate it explicitly and clearly! In order to emulate it, you simply pass the configuration and such down to the functions you call. Each function or class instance needs to pass it further along. So, rather than: def foo(): bar() def bar() ... you need to have: def foo(config): bar(config) def bar(config): ... Obviously, only certain functions care for the config and logging setup. Others don't. And obviously, you can modify the value on the way down. Just be sure to make a copy or you'll change the entire stack's value for that configuration. There are a couple of systems that do something close to this. I don't know of any, except SQLAlchemy, that does this exactly right. WSGI is also a system that does this right, although I don't know that many people realize it. Usually, what people end up doing is setting the config values to some global in some module. Then everyone is expected to look in that module for the config. This ends up being messy, particularly for testing where you'd like to mess with the config without messing with THE config. You can tell it's messy because people end up writing code like this: old_value = get_config(...) set_config(... some new value ...) ... do your stuff ... set_config(...back to old_value...) This kind of code is hard to get right. (What happens if there is an exception before you set the old config back? That's right, you need a try-finally block.) In terms of "global", you should only really use "global" when you are need to assign to a lexically scoped variable that is shared among other functions. For instance: def foo(): i = 0 def inc(): global i; i+=1 def dec(): global i; i-=1 def get(): return i return (inc, dec, get) This really isn't that common, although it is useful. Note that the above might be better organized into a class instance. Good luck. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sat Feb 20 20:37:21 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:37:21 -0800 Subject: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4 In-Reply-To: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> References: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> Message-ID: <6cc20cea1002201737o151fe3ddu3f31fe949f254642@mail.gmail.com> On Sat, Feb 20, 2010 at 3:03 PM, V8 NUT wrote: > /usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for > -lz > /usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for - > lz > /usr/bin/ld: cannot find -lz This is your problem. > > Am trying to get MySQL-python-1.2.3c1 installed on a CentOS 5 box > running Python 2.4 > I do not want to upgrade my Python version. > I have tried: > > 1. yum install mysql-python > 2. yum install librsync-devel > 3. yum install python-devel > > With all return no errors and a notification that there's nothing to > install or update. > I think you need libz's -devel module. Not sure what libz is or what its name is in the yum repository. Might take a search or maybe an rpm -qif /usr/lib/libz.so The problem could be that mysql-python expects to see a different version of libz than what's installed on your box. If so, you'll need to see if you can find the right version. The MySQL-python people should have more help for you. -- Jonathan Gardner jgardner at jonathangardner.net From agoretoy at gmail.com Sat Feb 20 20:37:54 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sat, 20 Feb 2010 19:37:54 -0600 Subject: datelib pythonification In-Reply-To: References: Message-ID: hello all, since I posted this last time, I've added a new function dates_diff and modified the dates_dict function to set timedelta values returned by dates_diff in the returned dict def dates_dict(self,*targs,**dargs): """ dates_dict() - takes params same as prefs() returns dict key/value pair of formatted/calculated dates key is a date, value is timedelta enddate-startdate """ self.prefs(*targs,**dargs) d={} try: if self.format!="": d[self.startdate.strftime(self.format)]=self.dates_diff() else: d[self.startdate]=self.dates_diff() except ValueError: d["%s"%self.startdate]=self.dates_diff() while self.startdate From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 20:41:11 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 01:41:11 GMT Subject: Efficient way to break up a list into two pieces References: Message-ID: <4b808f37$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 17:06:36 -0800, Jonathan Gardner wrote: > On Sat, Feb 20, 2010 at 4:55 PM, marwie wrote: [...] >> ? ?l2 = l1[10:] >> ? ?del l1[10:] >> >> But since I'm assigning a slice the elements will be copied. Basically, >> I'm looking for something like l1.pop(10,len(l1)) which returns and >> removes a whole chunk of data. Is there such a thing (and if not, why >> not?) >> >> > The idiom is: > >>>> l1, l2 = l1[:10], l1[10:] No, that has different behaviour to what the Original Poster wants, AND it does two copies instead of one: (1) copy l1[:10] and l1[10:] (2) assign the names l1 and l2 to them (3) if, and only if, there are no other references to the original l1, it gets deleted (garbage collected). What the OP is doing is quite different: (1) copy l1[:10] (2) assign the name l2 to it (3) resize l1 in place to the first 10 items. What the OP wants is: (1) assign the name l2 to l1[:10] without copying (2) resize l1 in place to the first 10 items without affecting l2. -- Steven From jgardner at jonathangardner.net Sat Feb 20 20:41:28 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:41:28 -0800 Subject: speed question, reading csv using takewhile() and dropwhile() In-Reply-To: <77e831101002201732m17bb9b74q5c62e279a9bf83b4@mail.gmail.com> References: <77e831101002191022j32c5ef76u5955c1432f45e702@mail.gmail.com> <6cc20cea1002191313g37ee51dfv373f46d2f3b8d555@mail.gmail.com> <77e831101002191358r1fc98930m58463423fedc362f@mail.gmail.com> <6cc20cea1002191536qcd38823lb88a268087487959@mail.gmail.com> <77e831101002201621x5724cf80uc644f53b80df5bde@mail.gmail.com> <6cc20cea1002201718v779c785v1f9b89baa992e41f@mail.gmail.com> <77e831101002201732m17bb9b74q5c62e279a9bf83b4@mail.gmail.com> Message-ID: <6cc20cea1002201741g21a94cf4jb77c638cc130d89d@mail.gmail.com> On Sat, Feb 20, 2010 at 5:32 PM, Vincent Davis wrote: > > Thanks again for the comment, not sure I will implement all of it but I will separate the "if not row" The files have some extraneous blank rows in the middle that I need to be sure not to import as blank rows. > I am actually having trouble with this filling my sys memory, I posted a separate question "Why is this filling my sys memory" or something like that is the subject. > I might be that my 1yr old son has been trying to help for the last hour. It is very distracting. > It may be that the csvfile is reading the entire file in, rather than line-by-line. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sat Feb 20 20:44:57 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 17:44:57 -0800 Subject: Not sure why this is filling my sys memory In-Reply-To: <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> Message-ID: <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> On Sat, Feb 20, 2010 at 5:07 PM, Vincent Davis wrote: >> Code is below, The files are about 5mb and 230,000 rows. When I have 43 >> files of them and when I get to the 35th (reading it in) my system gets so >> slow that it is nearly functionless. I am on a mac and activity monitor >> shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). >> The getsizeof() returns 6424 bytes for the alldata . So I am not sure what >> is happening. With this kind of data set, you should start looking at BDBs or PostgreSQL to hold your data. While processing files this large is possible, it isn't easy. Your time is better spent letting the DB figure out how to arrange your data for you. -- Jonathan Gardner jgardner at jonathangardner.net From deadpickle at gmail.com Sat Feb 20 20:47:12 2010 From: deadpickle at gmail.com (deadpickle) Date: Sat, 20 Feb 2010 17:47:12 -0800 (PST) Subject: netcdf4-python Message-ID: <1f7f8347-4c48-42a8-8f80-6175acfb83e9@b2g2000yqi.googlegroups.com> I'm trying to use the python module "netcdf4-python" to read a netcdf file. So far I'm trying to do the basics and just open the script: from netCDF4 import Dataset rootgrp = Dataset('20060402-201025.netcdf', 'r', format='NETCDF3_CLASSIC') print rootgrp.file_format rootgrp.close() when I do this I get the exit code error (when I run in Scite): >pythonw -u "netcdf_test.py" >Exit code: -1073741819 or Python stops responding (in windows cmd). I'm not sure what is wrong so if anyone as any ideas I would gladly send you the netcdf file to try. Thanks. From vincent at vincentdavis.net Sat Feb 20 20:53:22 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 18:53:22 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> Message-ID: <77e831101002201753l6b77c2b7xa5cbdf15ba43f4c@mail.gmail.com> On Sat, Feb 20, 2010 at 6:44 PM, Jonathan Gardner < > jgardner at jonathangardner.net> wrote: With this kind of data set, you should start looking at BDBs or PostgreSQL to hold your data. While processing files this large is possible, it isn't easy. Your time is better spent letting the DB figure out how to arrange your data for you. I really do need all of it in at time, It is dna microarray data. Sure there are 230,00 rows but only 4 columns of small numbers. Would it help to make them float() ? I need to at some point. I know in numpy there is a way to set the type for the whole array "astype()" I think. What I don't get is that it show the size of the dict with all the data to have only 6424 bytes. What is using up all the memory? *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 6:44 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Sat, Feb 20, 2010 at 5:07 PM, Vincent Davis > wrote: > >> Code is below, The files are about 5mb and 230,000 rows. When I have 43 > >> files of them and when I get to the 35th (reading it in) my system gets > so > >> slow that it is nearly functionless. I am on a mac and activity monitor > >> shows that python is using 2.99GB of memory (of 4GB). (python 2.6 > 64bit). > >> The getsizeof() returns 6424 bytes for the alldata . So I am not sure > what > >> is happening. > > With this kind of data set, you should start looking at BDBs or > PostgreSQL to hold your data. While processing files this large is > possible, it isn't easy. Your time is better spent letting the DB > figure out how to arrange your data for you. > > -- > Jonathan Gardner > jgardner at jonathangardner.net > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 20:53:46 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 01:53:46 GMT Subject: if not global -- then what? References: Message-ID: <4b80922a$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 17:34:15 -0800, Jonathan Gardner wrote: > In terms of "global", you should only really use "global" when you are > need to assign to a lexically scoped variable that is shared among other > functions. For instance: > > def foo(): > i = 0 > def inc(): global i; i+=1 > def dec(): global i; i-=1 > def get(): return i > return (inc, dec, get) That doesn't do what you think it does: >>> def foo(): ... i = 0 ... def inc(): global i; i+=1 ... def dec(): global i; i-=1 ... def get(): return i ... return (inc, dec, get) ... >>> inc = foo()[0] >>> inc() Traceback (most recent call last): File "", line 1, in File "", line 3, in inc NameError: global name 'i' is not defined The problem is that i is not global. Inside the inc and dec functions, you need to declare i nonlocal, not global, and that only works in Python 3 or better. -- Steven From marwie at gmx.de Sat Feb 20 20:55:18 2010 From: marwie at gmx.de (marwie) Date: Sat, 20 Feb 2010 17:55:18 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> Message-ID: <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> On 21 Feb., 02:30, Steven D'Aprano wrote: > Python lists are arrays of pointers to objects, so copying a slice is > fast: it doesn't have to copy the objects, just pointers. Deleting from > the end of the list is also quick, because you don't have to move memory, > just clear some pointers and change the length field. > > Splitting such an array without copying data is, essentially, impossible. > Python lists aren't linked lists. Well, to split a C array I would simply set l2 to point to l1[10] and then change the length of l1 (which I store somewhere else). No copying of elements needed. I would have assumed that python can do something like this with its internal arrays of pointers, too. Anyway, this was more a question about coding style. I use l1.extend(l2) or l1 += l2 rather than l1 = l1 + l2 because it's as readable and possibly faster. I was simply wondering if something similar exists for splitting lists. From sjdevnull at yahoo.com Sat Feb 20 21:00:38 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Sat, 20 Feb 2010 18:00:38 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> Message-ID: <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> On Feb 18, 2:58?pm, John Nagle wrote: > ? ? Multiple processes are not the answer. ?That means loading multiple > copies of the same code into different areas of memory. ?The cache > miss rate goes up accordingly. A decent OS will use copy-on-write with forked processes, which should carry through to the cache for the code. From lie.1296 at gmail.com Sat Feb 20 21:17:47 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 13:17:47 +1100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4b807c90$1@dnews.tpgi.com.au> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> Message-ID: <4b8097e6$1@dnews.tpgi.com.au> On 02/21/10 12:02, Stef Mientki wrote: > On 21-02-2010 01:21, Lie Ryan wrote: >>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki wrote: >>> >>>> hello, >>>> >>>> I would like my program to continue on the next line after an uncaught >>>> exception, >>>> is that possible ? >>>> >>>> thanks >>>> Stef Mientki >>>> >>>> >> That reminds me of VB's "On Error Resume Next" >> > I think that's what I'm after ... First, read this: http://www.developerfusion.com/code/4325/on-error-resume-next-considered-harmful/ > I already redirected sys.excepthook to my own function, > but now I need a way to get to continue the code on the next line. > Is that possible ? No, not in python. You can (ab)use generators' yield to resume execution, but not in the general case: def on_error_resume_next(func): def _func(*args, **kwargs): gen = func(*args, **kwargs) resp = next(gen) while isinstance(resp, Exception): print 'an error happened, ignoring...' resp = next(gen) return resp return _func @on_error_resume_next def add_ten_error_if_zero(args): if args == 0: # raise Exception() yield Exception() # return args + 10 yield args + 10 print add_ten_error_if_zero(0) print add_ten_error_if_zero(10) A slightly better approach is to retry calling the function again, but as you can see, it's not appropriate for certain cases: def retry_on_error(func): def _func(*args, **kwargs): while True: try: ret = func(*args, **kwargs) except Exception: print 'An error happened, retrying...' else: return ret return _func @retry_on_error def add_ten_error_if_zero(args): if args == 0: raise Exception() return args + 10 print add_ten_error_if_zero(0) print add_ten_error_if_zero(10) A much better approach is to use callbacks, the callbacks determines whether to raise an exception or continue execution: def handler(e): if datetime.datetime.now() >= datetime.datetime(2012, 12, 21): raise Exception('The world has ended') # else: ignore, it's fine def add_ten_error_if_zero(args, handler): if args == 0: handler(args) return args + 10 print add_ten_error_if_zero(0, handler) print add_ten_error_if_zero(10, handler) print add_ten_error_if_zero(0, lambda e: None) # always succeeds Ignoring arbitrary error is against the The Zen of Python "Errors should never pass silently."; not that it is ever a good idea to ignore arbitrary error, when an exception happens often the function is in an indeterminate state, and continuing blindly could easily cause havocs. From ssteinerx at gmail.com Sat Feb 20 21:43:24 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 20 Feb 2010 21:43:24 -0500 Subject: Is there a way to continue after an exception ? In-Reply-To: <4b8097e6$1@dnews.tpgi.com.au> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> <4b8097e6$1@dnews.tpgi.com.au> Message-ID: On Feb 20, 2010, at 9:17 PM, Lie Ryan wrote: > On 02/21/10 12:02, Stef Mientki wrote: >> On 21-02-2010 01:21, Lie Ryan wrote: >>>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki > wrote: >>>> >>>>> hello, >>>>> >>>>> I would like my program to continue on the next line after an uncaught >>>>> exception, >>>>> is that possible ? >>>>> >>>>> thanks >>>>> Stef Mientki >>>>> >>>>> >>> That reminds me of VB's "On Error Resume Next" >>> >> I think that's what I'm after ... > > First, read this: > http://www.developerfusion.com/code/4325/on-error-resume-next-considered-harmful/ The link goes to an "Oh dear. Gremlins at work!" page. They're probably using On Error Resume Next in their VBScript code and this is the "last resort" page ;-). S From ryan at rfk.id.au Sat Feb 20 21:51:21 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Sun, 21 Feb 2010 13:51:21 +1100 Subject: Is there a way to continue after an exception ? In-Reply-To: <4b8097e6$1@dnews.tpgi.com.au> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> <4b8097e6$1@dnews.tpgi.com.au> Message-ID: <1266720681.3908.24.camel@durian> On Sun, 2010-02-21 at 13:17 +1100, Lie Ryan wrote: > On 02/21/10 12:02, Stef Mientki wrote: > > On 21-02-2010 01:21, Lie Ryan wrote: > >>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki > wrote: > >>> > >>>> hello, > >>>> > >>>> I would like my program to continue on the next line after an uncaught > >>>> exception, > >>>> is that possible ? > >>>> > >>>> thanks > >>>> Stef Mientki > >>>> > >>>> > >> That reminds me of VB's "On Error Resume Next" > >> > > I think that's what I'm after ... > > A much better approach is to use callbacks, the callbacks determines > whether to raise an exception or continue execution: > > def handler(e): > if datetime.datetime.now() >= datetime.datetime(2012, 12, 21): > raise Exception('The world has ended') > # else: ignore, it's fine > > def add_ten_error_if_zero(args, handler): > if args == 0: > handler(args) > return args + 10 > > print add_ten_error_if_zero(0, handler) > print add_ten_error_if_zero(10, handler) > print add_ten_error_if_zero(0, lambda e: None) # always succeeds Or if you don't like having to explicitly manage callbacks, you can try the "withrestart" module: http://pypi.python.org/pypi/withrestart/ It tries to pinch some of the good ideas from Common Lisp's error-handling system. from withrestart import * def add_ten_error_if_zero(n): # This gives calling code the option to ignore # the error, or raise a different one. with restarts(skip,raise_error): if n == 0: raise ValueError return n + 10 # This will raise ValueError print add_ten_error_if_zero(0) # This will print 10 with Handler(ValueError,"skip"): print add_ten_error_if_zero(0) # This will exit the python interpreter with Handler(ValueError,"raise_error",SystemExit): print add_ten_error_if_zero(0) 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From nagle at animats.com Sat Feb 20 21:58:42 2010 From: nagle at animats.com (John Nagle) Date: Sat, 20 Feb 2010 18:58:42 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> Message-ID: <4b809d57$0$1596$742ec2ed@news.sonic.net> sjdevnull at yahoo.com wrote: > On Feb 18, 2:58 pm, John Nagle wrote: >> Multiple processes are not the answer. That means loading multiple >> copies of the same code into different areas of memory. The cache >> miss rate goes up accordingly. > > A decent OS will use copy-on-write with forked processes, which should > carry through to the cache for the code. That doesn't help much if you're using the subprocess module. The C code of the interpreter is shared, but all the code generated from Python is not. This will get even worse when Unladen Swallow starts generating vast swaths of unshared x86 instructions. John Nagle From marwie at gmx.de Sat Feb 20 22:00:29 2010 From: marwie at gmx.de (marwie) Date: Sat, 20 Feb 2010 19:00:29 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> Message-ID: <37cd051e-89d6-44cc-af1b-8ecaf68468b2@e1g2000yqh.googlegroups.com> On 21 Feb., 02:41, Steven D'Aprano wrote: > What the OP is doing is quite different: > > (1) copy l1[:10] > (2) assign the name l2 to it > (3) resize l1 in place to the first 10 items. > > What the OP wants is: > > (1) assign the name l2 to l1[:10] without copying > (2) resize l1 in place to the first 10 items without affecting l2. Assuming you meant l1[10:] instead of l1[:10], that's what I wanted, yes. From vincent at vincentdavis.net Sat Feb 20 22:08:18 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 20 Feb 2010 20:08:18 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <654D55F2-B276-44E6-A6EF-A9D3A2B5002F@gmail.com> <77e831101002201821o230fea1cpff18a5dacb37e710@mail.gmail.com> Message-ID: <77e831101002201908h10c72304y8025f3adae0beac4@mail.gmail.com> Here is a sample of the output, It almost instantly uses 2GB and then starts using VMem. This is probably the right suggestion but it's another thing to install > It's probably also worth being aware of guppy's heapy stuff: http://guppy-pe.sourceforge.net/heapy_tutorial....I find it quite nice to have the following to get a quick point-in-time estimate of my app's memory usage: print 'Current memory usage: %iMB' % (hpy().heap().stat.size/(1024*1024)) 19 files of 43 using 3352 bytes of memory Loading into memory: 3_veg_nm_rep1.txt 3_veg_nm_rep1.txt has 228484 rows of data 3_veg_nm_rep1.txt has 0 rows of masked data 3_veg_nm_rep1.txt has 141 rows of outliers 3_veg_nm_rep1.txt has 0 modified rows of data 280bytes of memory used for 3_veg_nm_rep1.txt 20 files of 43 using 3352 bytes of memory Loading into memory: 3_veg_nm_rep2.txt 3_veg_nm_rep2.txt has 228484 rows of data 3_veg_nm_rep2.txt has 0 rows of masked data 3_veg_nm_rep2.txt has 119 rows of outliers 3_veg_nm_rep2.txt has 0 modified rows of data 280bytes of memory used for 3_veg_nm_rep2.txt 21 files of 43 using 3352 bytes of memory Loading into memory: 3_veg_phd_rep1.txt 3_veg_phd_rep1.txt has 228484 rows of data 3_veg_phd_rep1.txt has 0 rows of masked data 3_veg_phd_rep1.txt has 63 rows of outliers 3_veg_phd_rep1.txt has 0 modified rows of data 280bytes of memory used for 3_veg_phd_rep1.txt 22 files of 43 using 6424 bytes of memory Loading into memory: 3g_c285-11.txt 3g_c285-11.txt has 228484 rows of data 3g_c285-11.txt has 0 rows of masked data 3g_c285-11.txt has 65 rows of outliers 3g_c285-11.txt has 0 modified rows of data 280bytes of memory used for 3g_c285-11.txt 23 files of 43 using 6424 bytes of memory Loading into memory: 3g_c285-42.txt 3g_c285-42.txt has 228484 rows of data 3g_c285-42.txt has 0 rows of masked data 3g_c285-42.txt has 27 rows of outliers 3g_c285-42.txt has 0 modified rows of data 280bytes of memory used for 3g_c285-42.txt 24 files of 43 using 6424 bytes of memory Loading into memory: A6AF.txt A6AF.txt has 228484 rows of data A6AF.txt has 0 rows of masked data A6AF.txt has 36 rows of outliers A6AF.txt has 0 modified rows of data 280bytes of memory used for A6AF.txt 25 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3026_rep1.txt Grigg_3026_rep1.txt has 228484 rows of data Grigg_3026_rep1.txt has 0 rows of masked data Grigg_3026_rep1.txt has 949 rows of outliers Grigg_3026_rep1.txt has 0 modified rows of data 280bytes of memory used for Grigg_3026_rep1.txt 26 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3026_rep2.txt Grigg_3026_rep2.txt has 228484 rows of data Grigg_3026_rep2.txt has 0 rows of masked data Grigg_3026_rep2.txt has 361 rows of outliers Grigg_3026_rep2.txt has 0 modified rows of data 280bytes of memory used for Grigg_3026_rep2.txt 27 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3026_rep3_both.txt Grigg_3026_rep3_both.txt has 228484 rows of data Grigg_3026_rep3_both.txt has 0 rows of masked data Grigg_3026_rep3_both.txt has 41 rows of outliers Grigg_3026_rep3_both.txt has 0 modified rows of data 280bytes of memory used for Grigg_3026_rep3_both.txt 28 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3131_rep1.txt Grigg_3131_rep1.txt has 228484 rows of data Grigg_3131_rep1.txt has 0 rows of masked data Grigg_3131_rep1.txt has 537 rows of outliers Grigg_3131_rep1.txt has 0 modified rows of data 280bytes of memory used for Grigg_3131_rep1.txt 29 files of 43 using 6424 bytes of memory Loading into memory: Grigg_3131_rep2.txt Grigg_3131_rep2.txt has 228484 rows of data Grigg_3131_rep2.txt has 0 rows of masked data Grigg_3131_rep2.txt has 238 rows of outliers Grigg_3131_rep2.txt has 0 modified rows of data 280bytes of memory used for Grigg_3131_rep2.txt 30 files of 43 using 6424 bytes of memory *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 7:40 PM, ssteinerX at gmail.com wrote: > > On Feb 20, 2010, at 9:21 PM, Vincent Davis wrote: > > See this article for some more info about the reported sizes of things: >> http://www.doughellmann.com/PyMOTW/sys/limits.html > > > Nice article but I > must have missed something useful to my current issue. Do I get any hints? > > > Oh, sorry, there was the part about getsizeof() not including attributes > unless the class supplies a __sizeof__ method and a comment at the bottom: > > It's probably also worth being aware of guppy's heapy stuff: > http://guppy-pe.sourceforge.net/heapy_tutorial.... > > I find it quite nice to have the following to get a quick point-in-time > estimate of my app's memory usage: > > print 'Current memory usage: %iMB' % (hpy().heap().stat.size/(1024*1024)) > > Put a few of those in at various places in the collection process and you > should see where you're taking a substantial hit on each pass. > > If I remember those numbers right, 5mb != 2.5gb so something along the way > is doing something very strange. > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt.newville at gmail.com Sat Feb 20 22:21:57 2010 From: matt.newville at gmail.com (Matt Newville) Date: Sat, 20 Feb 2010 19:21:57 -0800 (PST) Subject: netcdf4-python References: <1f7f8347-4c48-42a8-8f80-6175acfb83e9@b2g2000yqi.googlegroups.com> Message-ID: On Feb 20, 7:47?pm, deadpickle wrote: > I'm trying to use the python module "netcdf4-python" to read a netcdf > file. So far I'm trying to do the basics and just open the script: > > from netCDF4 import Dataset > rootgrp = Dataset('20060402-201025.netcdf', 'r', > format='NETCDF3_CLASSIC') > print rootgrp.file_format > rootgrp.close() > > when I do this I get the exit code error (when I run in Scite): > > >pythonw -u "netcdf_test.py" > >Exit code: -1073741819 > > ?or Python stops responding (in windows cmd). > > I'm not sure what is wrong so if anyone as any ideas I would gladly > send you the netcdf file to try. Thanks. If the file is really of NetCDF3 format, scipy.io.netcdf should work. Replace netCDF4.Dataset(filename,'r',format='NETCDF3_CLASSIC') with scipy.io.netcdf.netcdf_open(filename,'r') --Matt Newville From python-list at open-sense.com Sat Feb 20 22:25:19 2010 From: python-list at open-sense.com (Michael Pardee) Date: Sat, 20 Feb 2010 21:25:19 -0600 Subject: lists of variables Message-ID: I'm relatively new to python and I was very surprised by the following behavior: >>> a=1 >>> b=2 >>> mylist=[a,b] >>> print mylist [1, 2] >>> a=3 >>> print mylist [1, 2] Whoah! Are python lists only for literals? Nope: >>> c={} >>> d={} >>> mydlist=[c,d] >>> print mydlist [{}, {}] >>> c['x']=1 >>> print mydlist [{'x': 1}, {}] So it looks like variables in a list are stored as object references. This seems to confirm that: mydlist[1]['y']=4 >>> print mydlist [{}, {'y': 4}] So I figure my initial example doesn't work because if you assign a literal to something it is changing the object. But modifying a list or dict (as long as you don't re-construct it) does not change the object. I can think of some ways to work around this, including using single element lists as "pointers": >>> aa=[1] >>> bb=[2] >>> myplist=[aa,bb] >>> print myplist [[1], [2]] >>> aa[0]=3 >>> print myplist [[3], [2]] But what would be "the python way" to accomplish "list of variables" functionality? From clp2 at rebertia.com Sat Feb 20 22:34:42 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 20 Feb 2010 19:34:42 -0800 Subject: lists of variables In-Reply-To: References: Message-ID: <50697b2c1002201934qc6148b4j79daac42d05e7afb@mail.gmail.com> On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > I'm relatively new to python and I was very surprised by the following behavior: > >>>> a=1 >>>> b=2 >>>> mylist=[a,b] >>>> print mylist > [1, 2] >>>> a=3 >>>> print mylist > [1, 2] > > Whoah! ?Are python lists only for literals? ?Nope: > >>>> c={} >>>> d={} >>>> mydlist=[c,d] >>>> print mydlist > [{}, {}] >>>> c['x']=1 >>>> print mydlist > [{'x': 1}, {}] > > So it looks like variables in a list are stored as object references. > This seems to confirm that: > > mydlist[1]['y']=4 >>>> print mydlist > [{}, {'y': 4}] > > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. ?But modifying a list > or dict (as long as you don't re-construct it) does not change the > object. Correct. If you want more gory details, read http://effbot.org/zone/call-by-object.htm > I can think of some ways to work around this, including using single > element lists as "pointers": > >>>> aa=[1] >>>> bb=[2] >>>> myplist=[aa,bb] >>>> print myplist > [[1], [2]] >>>> aa[0]=3 >>>> print myplist > [[3], [2]] > > > But what would be "the python way" to accomplish "list of variables" > functionality? What do you need that functionality for exactly? It's a rather low-level notion. Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 22:40:42 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 03:40:42 GMT Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> Message-ID: <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 17:55:18 -0800, marwie wrote: > On 21 Feb., 02:30, Steven D'Aprano cybersource.com.au> wrote: >> Python lists are arrays of pointers to objects, so copying a slice is >> fast: it doesn't have to copy the objects, just pointers. Deleting from >> the end of the list is also quick, because you don't have to move >> memory, just clear some pointers and change the length field. >> >> Splitting such an array without copying data is, essentially, >> impossible. Python lists aren't linked lists. > > Well, to split a C array I would simply set l2 to point to l1[10] and > then change the length of l1 (which I store somewhere else). No copying > of elements needed. I would have assumed that python can do something > like this with its internal arrays of pointers, too. Python lists aren't C arrays either. Python lists are *objects*. Everything in Python is an object. Consequently, Python lists have a header, which includes the len. You don't store the length somewhere else, you store it in the object: this makes for less complexity. You can't just point l2 at an arbitrary index in an array and expect it to work, it needs a header. Additionally, Python lists are over-allocated so that appends are fast. A list of (say) 1000 items might be over-allocated to (say) 1024 items, so that you can do 24 appends before the array is full and the array needs to be resized. This means that, on average, Python list appending is O(1) instead of O(N). You can't just change the length blindly, you need to worry about the over-allocation. I'm sympathetic to your concern: I've often felt offended that doing something like this: x = SomeReallyBigListOrString for item in x[1:]: process(item) has to copy the entire list or string (less the first item). But honestly, I've never found a situation where it actually mattered. > Anyway, this was more a question about coding style. I use l1.extend(l2) > or l1 += l2 rather than l1 = l1 + l2 because it's as readable and > possibly faster. I really, really hate augmented assignment for everything other than ints and floats because you can't predict what it will do. Take this for example: >>> mylist = [1, 2, 3, 4] >>> same_again = mylist >>> mylist.append(5) >>> same_again [1, 2, 3, 4, 5] mylist and same_again are the same object, so append and extend behave predictably and simply. So is simple too: >>> mylist = mylist + [-1, -2, -3] >>> mylist [1, 2, 3, 4, 5, -1, -2, -3] >>> same_again [1, 2, 3, 4, 5] Because you have re-bound the name mylist to a new list, same_again doesn't get modified. Nice. But what about mylist += something else? Is it an in-place modification, like extend and append, or a rebinding, like +? Who can remember? The answer will depend on whether mylist is a builtin list, or a subclass. And then there's this mystery: >>> mylist = [1, 2, 3] >>> mytuple = (mylist, None) >>> mytuple[0] += [4] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> mylist [1, 2, 3, 4] So in fact, += is *always* a rebinding, but *sometimes* it is an in-place modification as well. Yuck. -- Steven From no.email at nospam.invalid Sat Feb 20 22:46:33 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 20 Feb 2010 19:46:33 -0800 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> Message-ID: <7x3a0vfdye.fsf@ruckus.brouhaha.com> John Nagle writes: >> A decent OS will use copy-on-write with forked processes, which should >> carry through to the cache for the code. > > That doesn't help much if you're using the subprocess module. The > C code of the interpreter is shared, but all the code generated from > Python is not. Emacs in days of yore used a hack called "unexec" to bring its Lisp code into the pure text segment. I think it's not used any more because machines are now big enough that the benefits aren't that great. Basically in the Emacs build process, you'd start up the C portion of Emacs, then tell it to load all its Lisp code, then call "unexec". Unexec basically performed a core dump of the process, then ran something that manipulated the original Emacs image and the core dump into a new executable that had the static Lisp code and data now marked as part of the (immutable) program area. Unexec necessarily had platform dependencies, but this was managed with a bunch of ifdefs in a reasonably clean and maintainable way. I could imagine doing something similar with a large Python program. From apt.shansen at gmail.com Sat Feb 20 22:58:10 2010 From: apt.shansen at gmail.com (Stephen Hansen) Date: Sat, 20 Feb 2010 19:58:10 -0800 Subject: lists of variables In-Reply-To: References: Message-ID: <7a9c25c21002201958s1af51adeqf2b8f40fef310375@mail.gmail.com> On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > But what would be "the python way" to accomplish "list of variables" > functionality? > The problem is... Python doesn't have variables. At least not in the way that you may be used to from other languages. Yeah, it's got data, and data obviously has to be identifiable in some way, but they aren't put together like "variables" are. A variable is a box with a name on it, and in that context a 'list of variables' makes sense. You're moving around the box, or referencing the box itself. It may happen to have something in it, but that 'something' doesn't really have an identity of its own. Its just.. the thing that's in box-A. In Python, everything's an object. And objects don't really have identities of their own(okay, they do, but its not meaningful except to an identity test), but they can be named. They object has no flabbering clue what its named, or how many different people know its name, but hey. a = 1 In many languages, that's making a variable "a" and assigning it the value of 1. In Python, that's making an int object with a value of 1, and giving it a name in the current namespace. This -isn't- just using dumber/simpler words to say the same thing :) All(*) python namespaces are really dictionaries behind the scenes. a = 1 is actually doing, current_namespaces["a"] = 1. Those may sound similar, but they're really not: most importantly, because the "a" in another language is a -thing- unto itself which may hold an object. But "a" in Python is just a label in some dictionary somewhere. You can get the object a is naming, but you can't get /a/ itself. Its not a 'thing'. There's no way to make a "list of variables", because /variables/ are the part that's really missing. If you do: lst = [a, b] Python doesn't create a list and put two variables in it. It creates a list, and while doing so, sees that we want to pass 'a' and 'b' into that list. So it grabs the actual objects a and b are naming, and puts them in the list. So, long story short: what's "the python way" to accomplish a "list of variables"? Well... IMHO, it's to not do so. : ) Make a dict, pass the dict around, there's your list of variables. True, you can't ever access them /as/ variables, and have to access them as dict items, but... that's the Python way to do that. If order matters, do an ordered dict. HTH, --S *: Yes, I know about local namespaces being optimized in CPython to be an array-like structure. Implementation detail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sat Feb 20 23:09:11 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 21 Feb 2010 15:09:11 +1100 Subject: lists of variables References: Message-ID: <87fx4v6xi0.fsf@benfinney.id.au> Michael Pardee writes: > But what would be "the python way" to accomplish "list of variables" > functionality? You'll need to explain what ?list of variables? functionality is. If you mean ?collection of name-to-value mappings?, the native mapping type in Python is ?dict?. If that doesn't meet your needs, you'll need to be more specific about what behaviour you want. -- \ ?Most people don't realize that large pieces of coral, which | `\ have been painted brown and attached to the skull by common | _o__) wood screws, can make a child look like a deer.? ?Jack Handey | Ben Finney From daniel at stutzbachenterprises.com Sat Feb 20 23:18:57 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Sat, 20 Feb 2010 22:18:57 -0600 Subject: Efficient way to break up a list into two pieces In-Reply-To: References: Message-ID: On Sat, Feb 20, 2010 at 6:55 PM, marwie wrote: > Now my question is > if there's a similar thing for breaking a list into two parts. Let's > say I want to remove from l1 everything from and including position 10 > and store it in l2. Then I can write > > l2 = l1[10:] > del l1[10:] With Python's list implementation, there's no faster way to split a list into two parts. Because Python lists are essentially variable-length arrays, Python has to copy O(n) references to create l2 and then decrement O(n) references to remove them from l1. I wrote an extension type called the blist to handle this and other problems. You use it just like you'd use a list, but it has different performance characteristics. It uses a hybrid array-tree structure and performs copy-on-write behind the scenes, so it takes only O(log n) time to create l2 and only O(log n) time to trim l1. You'd use it something like this: >>> from blist import blist >>> l1 = blist() >>> # Here, populate l1 as you normally would >>> l2 = l1[10:] >>> del l1[10:] It's available at: http://pypi.python.org/pypi/blist/ -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve at REMOVE-THIS-cybersource.com.au Sat Feb 20 23:21:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 04:21:09 GMT Subject: lists of variables References: Message-ID: <4b80b4b4$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 21:25:19 -0600, Michael Pardee wrote: > I'm relatively new to python and I was very surprised by the following > behavior: [snip] I don't see why. It's fairly unusual behaviour to want, and it would be surprising if you did this: def test(): x = 1 mylist = [2, 4, x] function(mylist) assert x == 1 and the assertion failed, even though you never passed x to the function. Such behaviour could easily turn into a never-ending source of bugs. > So it looks like variables in a list are stored as object references. Python doesn't store variables in lists, it stores objects, always. Even Python variables aren't variables *grin*, although it's really difficult to avoid using the term. Python variables are mappings between names (strings) and objects, not memory locations. > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. But modifying a list or > dict (as long as you don't re-construct it) does not change the object. Yes, we talk about name binding (and rebinding) versus mutation. A simple example: >>> alist = blist = [] # bind two names to the same list object >>> alist.append(1) # mutate the list (modify in place) >>> blist [1] >>> alist = alist + [2] # a rebinding operation >>> blist [1] >>> alist [1, 2] > I can think of some ways to work around this, including using single > element lists as "pointers": Yes, that's a standard way to do it, except that by "standard" I mean "really really really rare, honestly, hardly anyone does that". Slightly less rare, but still uncommon, is to wrap objects in an instance: class Record: pass o = Record() o.x = 1 o.y = 2 modify(o) print o.x, o.y Of course you can make the class as fancy, or as simple, as you want. But a better approach is to take advantage of Python's ability to return multiple values: x = 1 y = 2 x, y = modify(x, y) rather than: x = 1 y = 2 modify([x, y]) Speaking as an old Pascal coder, you won't miss pass-by-reference very often. -- Steven From python at mrabarnett.plus.com Sat Feb 20 23:37:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Feb 2010 04:37:47 +0000 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4B80B89B.1030109@mrabarnett.plus.com> Steven D'Aprano wrote: [snip] > I'm sympathetic to your concern: I've often felt offended that doing > something like this: > > x = SomeReallyBigListOrString > for item in x[1:]: > process(item) > > has to copy the entire list or string (less the first item). But > honestly, I've never found a situation where it actually mattered. > [snip] Could lists gain an .items() method with start and end positions? I was thinking that it would be a 'view', like with dicts in Python 3. Of course, that would only be worthwhile with very long lists: x = SomeReallyBigListOrString for item in x.items(1): process(item) From jgardner at jonathangardner.net Sun Feb 21 00:21:47 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:21:47 -0800 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4b808f37$0$8819$c3e8da3@news.astraweb.com> References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> Message-ID: <6cc20cea1002202121m53c9ba3esc9d1b46dc29ce5f7@mail.gmail.com> On Sat, Feb 20, 2010 at 5:41 PM, Steven D'Aprano wrote: > > What the OP wants is: > > (1) assign the name l2 to l1[:10] without copying > (2) resize l1 in place to the first 10 items without affecting l2. > For ten items, though, is it really faster to muck around with array lengths than just copying the data over? Array copies are extremely fast on modern processors. Programmer time and processor time being what it is, I still think my answer is the correct one. No, it's not what he says he wants, but it is what he needs. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sun Feb 21 00:25:37 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:25:37 -0800 Subject: lists of variables In-Reply-To: References: Message-ID: <6cc20cea1002202125tc9b0fc6p998b9f968ce2ec5f@mail.gmail.com> On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee wrote: > > But what would be "the python way" to accomplish "list of variables" > functionality? > You're looking for namespaces, AKA dicts. >>> vars = {} >>> vars['a'] = 1 >>> vars['b'] = 2 >>> mylist = ['a', 'b'] >>> print [vars[i] for i in mylist] # Here's your dereference [1,2] >>> vars['a'] = 3 >>> print [vars[i] for i in mylist] [3,2] -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sun Feb 21 00:34:41 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:34:41 -0800 Subject: Not sure why this is filling my sys memory In-Reply-To: <77e831101002201753l6b77c2b7xa5cbdf15ba43f4c@mail.gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <77e831101002201707s733fd4b5nd3da3db55a3e0d44@mail.gmail.com> <6cc20cea1002201744u63a0b280o6268a017292dd33a@mail.gmail.com> <77e831101002201753l6b77c2b7xa5cbdf15ba43f4c@mail.gmail.com> Message-ID: <6cc20cea1002202134k60db9dceoe2daaf431e76261f@mail.gmail.com> On Sat, Feb 20, 2010 at 5:53 PM, Vincent Davis wrote: >> On Sat, Feb 20, 2010 at 6:44 PM, Jonathan Gardner??wrote: >> >> With this kind of data set, you should start looking at BDBs or >> PostgreSQL to hold your data. While processing files this large is >> possible, it isn't easy. Your time is better spent letting the DB >> figure out how to arrange your data for you. > > I really do need all of it in at time, It is dna microarray data. Sure there are 230,00 rows but only 4 columns of small numbers. Would it help to make them float() ? I need to at some point. I know in numpy there is a way to set the type for the whole array "astype()" I think. > What I don't get is that it show the size of the dict with all the data to have only?6424 bytes. What is using up all the memory? > Look into getting PostgreSQL to organize the data for you. It's much easier to do processing properly with a database handle than a file handle. You may also discover that writing functions in Python inside of PostgreSQL can scale very well for whatever data needs you have. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Sun Feb 21 00:42:14 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sat, 20 Feb 2010 21:42:14 -0800 Subject: if not global -- then what? In-Reply-To: <4b80922a$0$8819$c3e8da3@news.astraweb.com> References: <4b80922a$0$8819$c3e8da3@news.astraweb.com> Message-ID: <6cc20cea1002202142p73626c02w2898cc8d84c65fcc@mail.gmail.com> On Sat, Feb 20, 2010 at 5:53 PM, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 17:34:15 -0800, Jonathan Gardner wrote: >> In terms of "global", you should only really use "global" when you are >> need to assign to a lexically scoped variable that is shared among other >> functions. For instance: >> >> def foo(): >> ? ? i = 0 >> ? ? def inc(): global i; i+=1 >> ? ? def dec(): global i; i-=1 >> ? ? def get(): return i >> ? ? return (inc, dec, get) > > That doesn't do what you think it does: > > >>>> def foo(): > ... ? ? i = 0 > ... ? ? def inc(): global i; i+=1 > ... ? ? def dec(): global i; i-=1 > ... ? ? def get(): return i > ... ? ? return (inc, dec, get) > ... >>>> inc = foo()[0] >>>> inc() > Traceback (most recent call last): > ?File "", line 1, in > ?File "", line 3, in inc > NameError: global name 'i' is not defined > > > The problem is that i is not global. Inside the inc and dec functions, > you need to declare i nonlocal, not global, and that only works in Python > 3 or better. > Oops. :-( -- Jonathan Gardner jgardner at jonathangardner.net From pavlovevidence at gmail.com Sun Feb 21 01:31:44 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 22:31:44 -0800 (PST) Subject: lists of variables References: Message-ID: On Feb 20, 7:25?pm, Michael Pardee wrote: > I'm relatively new to python and I was very surprised by the following behavior: > > >>> a=1 > >>> b=2 > >>> mylist=[a,b] > >>> print mylist > [1, 2] > >>> a=3 > >>> print mylist > > [1, 2] > > Whoah! ?Are python lists only for literals? ?Nope: > > >>> c={} > >>> d={} > >>> mydlist=[c,d] > >>> print mydlist > [{}, {}] > >>> c['x']=1 > >>> print mydlist > > [{'x': 1}, {}] > > So it looks like variables in a list are stored as object references. > This seems to confirm that: > > mydlist[1]['y']=4>>> print mydlist > > [{}, {'y': 4}] > > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. ?But modifying a list > or dict (as long as you don't re-construct it) does not change the > object. All correct, very observant for a Python newbie. To be more immutable > I can think of some ways to work around this, including using single > element lists as "pointers": > > >>> aa=[1] > >>> bb=[2] > >>> myplist=[aa,bb] > >>> print myplist > [[1], [2]] > >>> aa[0]=3 > >>> print myplist > > [[3], [2]] > > But what would be "the python way" to accomplish "list of variables" > functionality? Python doesn't have variable references (except in a limited way; see below), so unless you want to use lists as pointers, I'd recommend rethinking the problem. Occasionally I feel like I'd like to be able to do this, but usually another way exists that is, at worst, slightly more complex. For some cases the easiest thing is to make all the variables you're interested in listing attributes of an object (or values of a dict). Then store a list of names (or keys). class X(object): pass x = X() x.foo = 1 x.bar = 2 s = ["foo","bar"] setattr(x,s[0],3) print x.foo # prints 3 A rule of thumb in deciding whether to use attributes is whether you will typically know their names in your code ahead of time; if so storing the values as attributes is a good idea. If you are inputing or calculating the names, then it's better to use a dict. ** The one place where Python does have references is when accessing variables in an enclosing scope (not counting module-level). But these references aren't objects, so you can't store them in a list, so it can't help you: def f(): s = [] a = 1 def g(): print a s.append(a) g() # prints 1 a = 2 g() # prints 2: g's a is a reference to f's a print s # prints [1,2] not [2,2] Carl Banks From imranalii84 at gmail.com Sun Feb 21 01:32:51 2010 From: imranalii84 at gmail.com (babu lohar) Date: Sat, 20 Feb 2010 22:32:51 -0800 (PST) Subject: come and join www.pakdub.com a social network with full features like games, classifieds, forums, blogs and a lot more Message-ID: <53c431ab-87a4-4798-9616-37cfbabfb289@u19g2000prh.googlegroups.com> come and join www.pakdub.com a social network with full features like games, classifieds, forums, blogs and a lot more From pavlovevidence at gmail.com Sun Feb 21 01:38:53 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 22:38:53 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: Message-ID: <2df4ab82-7877-43f5-ac00-a780885e1950@e19g2000prn.googlegroups.com> On Feb 20, 4:55?pm, marwie wrote: > Hello, > > I recently read about augmented assignments and that (with l1, l2 > being lists) > > ? ? l1.extend(l2) > > is more efficient than > > ? ? l1 = l1 + l2 > > because unnecessary copy operations can be avoided. Now my question is > if there's a similar thing for breaking a list into two parts. Let's > say I want to remove from l1 everything from and including position 10 > and store it in l2. Then I can write > > ? ? l2 = l1[10:] > ? ? del l1[10:] > > But since I'm assigning a slice the elements will be copied. That's about the best you can do with Python lists. > Basically, I'm looking for something like l1.pop(10,len(l1)) which > returns and removes a whole chunk of data. Is there such a thing (and > if not, why not?) Numpy arrays can share underlying data like that when you take slices. For instance, this probably works the way you want: a = numpy.array([1,2,3,4,5,6]) b = a[:3] c = a[3:] None of the actual data was copied here. Carl Banks From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 01:48:36 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 06:48:36 GMT Subject: Efficient way to break up a list into two pieces References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b80d744$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 21:21:47 -0800, Jonathan Gardner wrote: > On Sat, Feb 20, 2010 at 5:41 PM, Steven D'Aprano > wrote: >> >> What the OP wants is: >> >> (1) assign the name l2 to l1[:10] without copying (2) resize l1 in >> place to the first 10 items without affecting l2. >> >> > For ten items, though, is it really faster to muck around with array > lengths than just copying the data over? Array copies are extremely fast > on modern processors. My mistake, he actually wants l1[10:] copied. So you might be copying a huge amount of data, not just ten items. Or if you prefer, replace 10 by 100000000. But in either case, I agree that *in practice* it's rarely an actual problem. > Programmer time and processor time being what it is, I still think my > answer is the correct one. No, it's not what he says he wants, but it is > what he needs. You missed the point that your suggestion gives radically different behaviour to what the OP indicated he is using. He mutates the list in place, you rebind the list's name. That has *very* different semantics. >>> a = b = [1, 2, 3, 4] >>> del a[2:] # mutate in place >>> b [1, 2] >>> >>> a = b = [1, 2, 3, 4] >>> a = a[2:] # rebind the name >>> b [1, 2, 3, 4] The OP may not care about the difference, but if he does require the first behaviour, then your solution doesn't help. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 01:50:24 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 06:50:24 GMT Subject: lists of variables References: Message-ID: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote: > The one place where Python does have references is when accessing > variables in an enclosing scope (not counting module-level). What makes you say that? > But these > references aren't objects, so you can't store them in a list, so it > can't help you: I don't even understand this. Your own example clearly shows that the are objects and you can store them in a list, so I have no understanding of what you mean. > def f(): > s = [] > a = 1 > def g(): > print a a is a name bound to an object which inherits a __str__ method, hence you can print it. > s.append(a) a is bound to an object you can put in a list. > g() # prints 1 > a = 2 > g() # prints 2: g's a is a reference to f's a > print s # prints [1,2] not [2,2] Yes, you are correct that lexical scoping doesn't allow the OP to embed references to names in lists. I'm just confused why you think that lexical scoping is equivalent to references that can't be put in lists, or why you think this behaviour is any different from lexical scoping everywhere else? # Instead of two scopes, f and g, use two scopes, the module (global) # and local scope g: s = [] a = 1 def g(): print a s.append(a) g() # prints 1 a = 2 g() # prints 2: g's a is a reference to the global a print s # prints [1,2] not [2,2] There is no difference between lexical scoping between a function and a nested function, and the lexical scoping between the global namespace and a nested function. -- Steven From g.bogle at auckland.no.spam.ac.nz Sun Feb 21 02:12:33 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sun, 21 Feb 2010 20:12:33 +1300 Subject: Shipping Executables References: <68346d02-9fc2-491b-b284-a7d6251914a2@k41g2000yqm.googlegroups.com> <3de8e1f71002162210r7bb1a99eo585831d8d523532e@mail.gmail.com> Message-ID: Steven D'Aprano wrote: > On Wed, 17 Feb 2010 02:00:59 -0500, geremy condra quoted Banibrata Dutta > : > >>> BTW for people who are non-believers in something being worth stealing >>> needing protection, need to read about the Skype client. > > Pardon me for breaking threading, but the original post has not come > through to my provider, only the reply from Geremy. > > Many things are worth stealing and therefore need protection. > > In any case, reverse engineering software is not theft. And even if it > were, keeping the source code secret is no barrier to a competent, > determined attacker or investigator. Skype is a good example: despite the > lack of source code and the secret protocol, analysts were able to > discover that TOM-Skype sends personally identifiable information, > encryption keys and private messages back to central servers. > > In my personal opinion, releasing closed source software is prima facie > evidence that the software is or does something bad: leaking personal > information, infringing somebody else's copyright or patent, or just > being badly written. I'm not saying that every piece of closed source > software is like that, but when you hide the source, the burden of proof > is on you to prove that you're not hiding something unpleasant. You are assuming that everyone who might be interested in copying your code is able to reverse-engineer it. That might be true for software with a high commercial value, but it is by no means true for all software. And in saying "when you hide the source, the burden of proof is on you to prove that you're not hiding something unpleasant" you are tacitly assuming that the users of the software care about having such a thing proven. I submit that most users do not have this "guilty until proven innocent" attitude. To give a personal example: I plan soon to distribute (free) to anyone interested some scientific software. For various reasons I do not intend to distribute the source code at this stage. I'm quite confident that the users (biologists) will have neither the desire nor the ability to reverse-engineer it. Of course I'd be tremendously flattered if they did want to. I'm also confident that they will not suspect me of "hiding something unpleasant". In the worst case they might think the program is useless. From pavlovevidence at gmail.com Sun Feb 21 02:44:29 2010 From: pavlovevidence at gmail.com (Carl Banks) Date: Sat, 20 Feb 2010 23:44:29 -0800 (PST) Subject: lists of variables References: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> Message-ID: On Feb 20, 10:50?pm, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote: > > The one place where Python does have references is when accessing > > variables in an enclosing scope (not counting module-level). ? > > What makes you say that? > > > But these > > references aren't objects, so you can't store them in a list, so it > > can't help you: > > I don't even understand this. Your own example clearly shows that the are > objects and you can store them in a list, so I have no understanding of > what you mean. > > > def f(): > > ? ? s = [] > > ? ? a = 1 > > ? ? def g(): > > ? ? ? ? print a > > a is a name bound to an object which inherits a __str__ method, hence you > can print it. > > > ? ? ? ? s.append(a) > > a is bound to an object you can put in a list. > > > ? ? g() # prints 1 > > ? ? a = 2 > > ? ? g() # prints 2: g's a is a reference to f's a > > ? ? print s # prints [1,2] not [2,2] > > Yes, you are correct that lexical scoping doesn't allow the OP to embed > references to names in lists. I'm just confused why you think that > lexical scoping is equivalent to references that can't be put in lists, > or why you think this behaviour is any different from lexical scoping > everywhere else? > > # Instead of two scopes, f and g, use two scopes, the module (global) > # and local scope g: > s = [] > a = 1 > def g(): > ? ? print a > ? ? s.append(a) > > g() # prints 1 > a = 2 > g() # prints 2: g's a is a reference to the global a > print s # prints [1,2] not [2,2] > > There is no difference between lexical scoping between a function and a > nested function, and the lexical scoping between the global namespace and > a nested function. http://tinyurl.com/8e7tm Carl Banks From sjdevnull at yahoo.com Sun Feb 21 02:45:16 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Sat, 20 Feb 2010 23:45:16 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> Message-ID: <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> On Feb 20, 9:58?pm, John Nagle wrote: > sjdevn... at yahoo.com wrote: > > On Feb 18, 2:58 pm, John Nagle wrote: > >> ? ? Multiple processes are not the answer. ?That means loading multiple > >> copies of the same code into different areas of memory. ?The cache > >> miss rate goes up accordingly. > > > A decent OS will use copy-on-write with forked processes, which should > > carry through to the cache for the code. > > ? ? That doesn't help much if you're using the subprocess module. ?The > C code of the interpreter is shared, but all the code generated from > Python is not. Of course. Multithreading also fails miserably if the threads all try to call exec() or the equivalent. It works fine if you use os.fork(). From elias.bachaalany at gmail.com Sun Feb 21 03:22:56 2010 From: elias.bachaalany at gmail.com (lallous) Date: Sun, 21 Feb 2010 00:22:56 -0800 (PST) Subject: Pure virtual functions in Python? References: <7uahviFlubU1@mid.uni-berlin.de> <4B801711.7040501@v.loewis.de> Message-ID: <2c9cf10c-90fc-4b08-9f71-a5a7fb1f8a32@m37g2000yqf.googlegroups.com> On Feb 20, 6:08?pm, "Martin v. Loewis" wrote: > >> class C1: > > >> ? ? ?# Pure virtual > >> ? ? ?def cb(self, param1, param2): > >> ? ? ? ? ?""" > >> ? ? ? ? ?This is a callback > > >> ? ? ? ? ?@param param1: ... > >> ? ? ? ? ?@param param2: ... > >> ? ? ? ? ?""" > >> ? ? ? ? ?raise NotImplementedError, "Implement me" > > >> # Dispatcher function that calls 'cb' only if 'cb' is implemented in > >> child classes > >> def dispatcher(c): > >> ? ? ?if hasattr(c, 'cb'): > >> ? ? ? ? ?c.cb("Hello", "World") > > >> dispatcher(C2()) > >> dispatcher(C3()) > > >> What I want is the ability to have the dispatcher() not to call 'cb' > >> if it was not implemented in one of the child classes. > > >> Please advise. > > > There is nothing more beyond that what you already did. You can raise a > > NotImplementedError for classes that don't implement the method. That's it. > > That's not true. Currently, the hasattr() call would report that cb is > available, when it is actually not implemented. It would be possible to > do something like > > ? if hasattr(c, 'cb') and not is_pure(c.cb): > ? ? ? c.cb("Hello", "World") > > is_pure could, for example, look at a function attribute of the > callback. You'd write something like > > ? @pure_virtual > ? def cb(self, param1, param2): > ? ? ? not_implemented > > Regards, > Martin Hello Martine, Can you elaborate more on how to use the mechanism you described? Thanks, Elias From elias.bachaalany at gmail.com Sun Feb 21 03:27:24 2010 From: elias.bachaalany at gmail.com (lallous) Date: Sun, 21 Feb 2010 00:27:24 -0800 (PST) Subject: Pure virtual functions in Python? References: Message-ID: Thanks everyone for the answers. The dispatcher() is actually sits in C++ code. So my code receives an object that is an instance of the base class, it PyObject_GetAttrString(py_obj, 'funcname'). If the attribute exists I will call PyObject_CallMethod on it. If the base defines the method and it was empty, then my C++ code would still call the function. This is not optimal because I don't want to go from C++ to Python if the _derived_ class does not implement the cb. Now the base class should define it so that doc parsers properly describe the base class. The recipe suggested is not worth the trouble. Unfortunately I cannot use abc module since I use Python 2.5 From sjmachin at lexicon.net Sun Feb 21 04:16:11 2010 From: sjmachin at lexicon.net (John Machin) Date: Sun, 21 Feb 2010 01:16:11 -0800 (PST) Subject: datelib pythonification References: Message-ID: On Feb 21, 12:37?pm, alex goretoy wrote: > hello all, > ? ? since I posted this last time, I've added a new function dates_diff and [SNIP] I'm rather unsure of the context of this posting ... I'm assuming that the subject "datelib pythonification" refers to trying to make "datelib" more "pythonic", with which you appear to need help. Looking just at the new "function" (looks like a method to me) dates_diff, problems include: 1. Mostly ignores PEP-8 about spaces after commas, around operators 2. Checks types 3. Checks types using type(x) == type(y) 4. Inconsistent type checking: checks types in case of dates_diff(date1, date2) but not in case of dates_diff([date1, date2]) 5. Doesn't check for 3 or more args. 6. The 0-arg case is for what purpose? 7. The one-arg case is overkill -- if the caller has the two values in alist, all you are saving them from is the * in dates_diff(*alist) 8. Calling type(date.today()) once per 2-arg call would be a gross extravagance; calling it twice per 2-arg call is mind-boggling. 9. start,end=(targs[0][0],targs[0][1]) ... multiple constant subscripts is a code smell; this one is pongier than usual because it could easily be replaced by start, end = targs[0] Untested fix of problems 1, 3, 4, 5, 8, 9: DATE_TYPE = type(date.today()) def dates_diff(self, *targs): nargs = len(targs) if nargs == 0: return self.enddate - self.startdate if nargs == 1: arg = targs[0] if not isinstance(arg, (list, tuple)) or len(arg) != 2: raise Exception( "single arg must be list or tuple of length 2") start, end = arg elif nargs == 2: start, end = targs else: raise Exception("expected 0,1, or 2 args; found %d" % nargs) if isinstance(start, DATE_TYPE) and isinstance(end, DATE_TYPE): return end - start raise Exception("both values must be of type DATE_TYPE") HTH, John From martin at v.loewis.de Sun Feb 21 04:24:24 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 10:24:24 +0100 Subject: Pure virtual functions in Python? In-Reply-To: <2c9cf10c-90fc-4b08-9f71-a5a7fb1f8a32@m37g2000yqf.googlegroups.com> References: <7uahviFlubU1@mid.uni-berlin.de> <4B801711.7040501@v.loewis.de> <2c9cf10c-90fc-4b08-9f71-a5a7fb1f8a32@m37g2000yqf.googlegroups.com> Message-ID: <4B80FBC8.3070102@v.loewis.de> >> That's not true. Currently, the hasattr() call would report that cb is >> available, when it is actually not implemented. It would be possible to >> do something like >> >> if hasattr(c, 'cb') and not is_pure(c.cb): >> c.cb("Hello", "World") >> >> is_pure could, for example, look at a function attribute of the >> callback. You'd write something like >> >> @pure_virtual >> def cb(self, param1, param2): >> not_implemented >> >> Regards, >> Martin > > Hello Martine, > > Can you elaborate more on how to use the mechanism you described? There are various ways to do it; the one I had in mind uses function attributes: def pure_virtual(func): func.pure_virtual = True # only presence of attribute matters, # not value return func def is_pure(method): # method might be either a method or a function try: func = method.im_func except AttributeError: func = method return hasattr(func, 'pure_virtual') not_implemented = object() # could also write pass instead, or raise HTH, Martin From as at sci.fi Sun Feb 21 04:40:19 2010 From: as at sci.fi (Anssi Saari) Date: Sun, 21 Feb 2010 11:40:19 +0200 Subject: /usr/bin/ld: cannot find -lz on Cent OS - Python 2.4 References: <9d373498-df99-41ef-b193-0c05073166ff@g28g2000yqh.googlegroups.com> Message-ID: V8 NUT writes: > /usr/bin/ld: cannot find -lz > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 Could it be you're missing zlib-devel? What does yum info zlib-devel say? Or locate libz? From noamraph at gmail.com Sun Feb 21 04:42:56 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Sun, 21 Feb 2010 01:42:56 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! Message-ID: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> I'm pleased to announce DreamPie 1.0 - a new graphical interactive Python shell! Some highlights: * Has whatever you would expect from a graphical Python shell - attribute completion, tooltips which show how to call functions, highlighting of matching parentheses, etc. * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, history recall and completion works as expected, etc. * Results are saved in the Result History. * Long output is automatically folded so you can focus on what's important. * Jython and IronPython support makes DreamPie a great tool for exploring Java and .NET classes. * You can copy any amount of code and immediately execute it, and you can also copy code you typed interactively into a new file, with the Copy Code Only command. No tabs are used! * Free software licensed under GPL version 3. Check it out at http://dreampie.sourceforge.net/ and tell me what you think! Have fun, Noam From lie.1296 at gmail.com Sun Feb 21 05:21:44 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 21:21:44 +1100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <4b810953$1@dnews.tpgi.com.au> On 02/21/10 19:27, lallous wrote: > If the base defines the method and it was empty, then my C++ code > would still call the function. This is not optimal because I don't > want to go from C++ to Python if the _derived_ class does not > implement the cb. That sounds like a microoptimization; have you profiled your code and determined that calling empty function causes a bottleneck? I doubt it. > Now the base class should define it so that doc > parsers properly describe the base class. > The recipe suggested is not worth the trouble. > Unfortunately I cannot use abc module since I use Python 2.5 Because nobody here could have guessed that your dispatcher was written in C++; your problem is near trivial if your dispatcher is a pure-python code. From lie.1296 at gmail.com Sun Feb 21 05:25:03 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Sun, 21 Feb 2010 21:25:03 +1100 Subject: lists of variables In-Reply-To: <4b80b4b4$0$8819$c3e8da3@news.astraweb.com> References: <4b80b4b4$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b810a1a$1@dnews.tpgi.com.au> On 02/21/10 15:21, Steven D'Aprano wrote: >> > So it looks like variables in a list are stored as object references. > Python doesn't store variables in lists, it stores objects, always. > > Even Python variables aren't variables *grin*, although it's really > difficult to avoid using the term. Python variables are mappings between > names (strings) and objects, not memory locations. Actually, no programming languages have used the term "variable" correctly, as per its original mathematical definition. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 06:17:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 11:17:50 GMT Subject: lists of variables References: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b81165e$0$8819$c3e8da3@news.astraweb.com> On Sat, 20 Feb 2010 23:44:29 -0800, Carl Banks wrote: > On Feb 20, 10:50?pm, Steven D'Aprano cybersource.com.au> wrote: >> What makes you say that? [...] >> I don't even understand this. [...] >> I'm just confused why you think that >> lexical scoping is equivalent to references that can't be put in lists, >> or why you think this behaviour is any different from lexical scoping >> everywhere else? > http://tinyurl.com/8e7tm Ha ha ha, very amusing. But I was genuinely confused, because I know you're an experienced Python coder and not some n00b, so I thought maybe you were referring to something that escaped me. Your response, apt though it may be, does nothing to clear up my confusion. Presumably if you had a serious response you would have made it, so I'll chalk it up to a generalised confusion field. *wink* -- Steven From aaan at email.dk Sun Feb 21 07:51:36 2010 From: aaan at email.dk (Aage Andersen (REMOVE)) Date: Sun, 21 Feb 2010 13:51:36 +0100 Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <4b812c5b$0$56795$edfadb0f@dtext02.news.tele.dk> I tried to edit the awfully colors, here are the results: Traceback (most recent call last): File "dreampie.py", line 4, () File "dreampielib\gui\__init__.pyc", line 972, main() File "dreampielib\gui\__init__.pyc", line 153, __init__(self=DreamPie(path..."window_main"), pyexec='C:\\Python26\\python.exe') File "dreampielib\gui\__init__.pyc", line 829, configure(self=DreamPie(path..."window_main")) File "dreampielib\gui\tags.pyc", line 224, apply_theme_text(textview=, textbuffer=, theme={('bracket-match', 'bg', 'color'): 'darkblue', ('bracket-match', 'bg', 'isset'): True, ('bracket-match', 'fg', 'color'): 'white', ('bracket-match', 'fg', 'isset'): False, ...}) ValueError: unable to parse colour specification Now the program don't run. Aage From aaan at email.dk Sun Feb 21 08:06:54 2010 From: aaan at email.dk (Aage Andersen (REMOVE)) Date: Sun, 21 Feb 2010 14:06:54 +0100 Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <4b812c5b$0$56795$edfadb0f@dtext02.news.tele.dk> Message-ID: <4b812ff1$0$56776$edfadb0f@dtext02.news.tele.dk> I reinstalled and got this message: Traceback (most recent call last): File "dreampie.py", line 4, () File "dreampielib\gui\__init__.pyc", line 972, main() File "dreampielib\gui\__init__.pyc", line 153, __init__(self=DreamPie(path..."window_main"), pyexec='C:\\Python26\\python.exe') File "dreampielib\gui\__init__.pyc", line 829, configure(self=DreamPie(path..."window_main")) File "dreampielib\gui\tags.pyc", line 224, apply_theme_text(textview=, textbuffer=, theme={('bracket-match', 'bg', 'color'): 'darkblue', ('bracket-match', 'bg', 'isset'): True, ('bracket-match', 'fg', 'color'): 'white', ('bracket-match', 'fg', 'isset'): False, ...}) ValueError: unable to parse colour specification Aage From noamraph at gmail.com Sun Feb 21 08:18:23 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Sun, 21 Feb 2010 05:18:23 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <4b812c5b$0$56795$edfadb0f@dtext02.news.tele.dk> <4b812ff1$0$56776$edfadb0f@dtext02.news.tele.dk> Message-ID: Delete \Documents and Settings\\DreamPie and it should now work. Did you edit the colors using the configuration window or manually? If you edited them using the configuration window, can you give instructions on how to reproduce the bug? Noam On Feb 21, 3:06?pm, "Aage Andersen" wrote: > I reinstalled and got this message: > > Traceback (most recent call last): > ? File "dreampie.py", line 4, () > ? File "dreampielib\gui\__init__.pyc", line 972, main() > ? File "dreampielib\gui\__init__.pyc", line 153, > __init__(self=DreamPie(path..."window_main"), > pyexec='C:\\Python26\\python.exe') > ? File "dreampielib\gui\__init__.pyc", line 829, > configure(self=DreamPie(path..."window_main")) > ? File "dreampielib\gui\tags.pyc", line 224, > apply_theme_text(textview=, > textbuffer=, theme={('bracket-match', 'bg', 'color'): > 'darkblue', ('bracket-match', 'bg', 'isset'): True, ('bracket-match', 'fg', > 'color'): 'white', ('bracket-match', 'fg', 'isset'): False, ...}) > ValueError: unable to parse colour specification > > Aage From lacrima.maxim at gmail.com Sun Feb 21 10:54:31 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Sun, 21 Feb 2010 07:54:31 -0800 (PST) Subject: Which mock library do you prefer? References: <3ed54f46-c20b-4c02-81fc-76b12d3e9b25@d37g2000yqa.googlegroups.com> <485b80f9-96c7-4946-8f38-44eb7d81fe1d@z19g2000yqk.googlegroups.com> <87sk90c499.fsf@benfinney.id.au> <87tytfbaq6.fsf@benfinney.id.au> Message-ID: On Feb 18, 3:20?am, Ben Finney wrote: > Lacrima writes: > > Right, isolation [of test cases] is essential. But I can't decide to > > which extent I should propagate isolation. > > You used ?propagate? in a sense I don't understand there. > > > For example, in "Python Testing: Beginner's Guide" by Daniel Arbuckle, > > author suggests that if you do unittesting you should isolate the > > smallest units of code from each other. > > I'm not sure what the author means, but I would say that as it stands > that advice is independent of what testing is being done. In all cases: > > * Make your code units small, so each one is not doing much and is easy > ? to understand. > > * Make the interface of units at each level as narrow as feasible, so > ? they're not brittle in the face of changes to the implementation. > > > For example, if you have a > > class: > > Class SomeClass(object): > > ? ? def method1(self): > > ? ? ? ? return 5 > > ? ? def method2(self): > > ? ? ? ? return self.method1 + 10 > > > According to the book, if you want to test method2, you should isolate > > it from method1 and class instance('self'). > > I don't really know what that means. > > Remember that each test case should not be ?test method1?. That is far > too broad, and in some cases too narrow. There is no one-to-one mapping > between methods and unit test cases. > > Instead, each test case should test one true-or-false assertion about > the behaviour of the code. ?When we start with this initial state (the > test fixture), and perform this operation, the resulting state is that?. > > It makes a lot of sense to name the test case so the assertion being > made *is* its name: not ?test frobnicate? with dozens of assertions, but > one ?test_frobnicate_with_valid_spangulator_returns_true? which makes > that assertion, and extra ones for each distinct assertion. > > The failure of a unit test case should indicate *exactly* what has gone > wrong. If you want to make multiple assertions about a code unit, write > multiple test cases for that unit and name the tests accordingly. > > This incidentally requires that you test something small enough that > such a true-or-false assertion is meaningful, which leads to > well-designed code with small easily-tested code units. But that's an > emergent property, not a natural law. > > > Currently, I don't create mocks of units if they are within the same > > class with the unit under test. If that is not right approach, please, > > explain what are best practices... I am just learning TDD.. > > In the fixture of the unit test case, create whatever test doubles are > necessary to put your code into the initial state you need for the test > case; then tear all those down whatever the result of the test case. > > If you need to create great honking wads of fixtures for any test case, > that is a code smell: your code units are too tightly coupled to > persistent state, and need to be decoupled with narrow interfaces. > > The Python ?unittest? module makes this easier by letting you define > fixtures common to many test cases (the ?setUp? and ?tearDown? > interface). My rule of thumb is: if I need to make different fixtures > for some set of test cases, I write a new test case class for those > cases. > > -- > ?\ ? ? ? ?Following fashion and the status quo is easy. Thinking about | > ? `\ ? ? ? ?your users' lives and creating something practical is much | > _o__) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?harder.? ?Ryan Singer, 2008-07-09 | > Ben Finney Hi, Ben!!! Sorry for too late reply!!! Thank you very much for sharing your experience! I still have to grasp a lot in TDD. From mensanator at aol.com Sun Feb 21 11:30:27 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 08:30:27 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> On Feb 21, 3:42?am, Noam Yorav-Raphael wrote: > I'm pleased to announce DreamPie 1.0 - a new graphical interactive > Python shell! > What versions of Python does it suuport? From mensanator at aol.com Sun Feb 21 11:32:35 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 08:32:35 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> Message-ID: <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> On Feb 21, 10:30?am, Mensanator wrote: > On Feb 21, 3:42 am, Noam Yorav-Raphael wrote:> I'm pleased to announce DreamPie 1.0 - a new graphical interactive > > Python shell! > > What versions of Python does it suuport? What OS are supported? From skraj23mbec at gmail.com Sun Feb 21 11:46:55 2010 From: skraj23mbec at gmail.com (sk raj) Date: Sun, 21 Feb 2010 08:46:55 -0800 (PST) Subject: Free chat for u.....hot.hot.....hot.............. Message-ID: <1aa805b5-f000-41ba-9718-defd75ee330c@b7g2000pro.googlegroups.com> http://chattingfree.blogspot.com/ From sccolbert at gmail.com Sun Feb 21 11:51:40 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 21 Feb 2010 11:51:40 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> Message-ID: <7f014ea61002210851r52e63cen50b6815ab3a15b2f@mail.gmail.com> http://dreampie.sourceforge.net/download.html reading is a wonderful thing. On Sun, Feb 21, 2010 at 11:32 AM, Mensanator wrote: > On Feb 21, 10:30?am, Mensanator wrote: > > On Feb 21, 3:42 am, Noam Yorav-Raphael wrote:> I'm > pleased to announce DreamPie 1.0 - a new graphical interactive > > > Python shell! > > > > What versions of Python does it suuport? > > What OS are supported? > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sccolbert at gmail.com Sun Feb 21 12:13:50 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 21 Feb 2010 12:13:50 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> This is bloody fantastic! I must say, this fixes everything I hate about Ipython and gives me the feature I wished it had (with a few minor exceptions). I confirm this working on Kubuntu 9.10 using the ppa listed on the sites download page. I also confirm that it works interactively with PyQt4 and PyGtk (as to be expected since these toolkits use the PyOS_inputhook for the mainloop). However, it does not work interactively with wx (again, this is as expected since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support is the same as in Ipython if you dont use any of the magic threading switches, which are now deprecated anyway. Matplotlib does not work interactively for me. Is there a special switch that needs to be used? or should a pick a non-wx backend? (i'm thinking the latter is more likely) A couple of things I would like to see (and will help implement if I can find the time): 1) A shortcut to show the docstring of an object. Something like Ipython's `?`. i.e. `object.foo?` translates to `help(object.foo)` 2) How do I change the color of the blinking cursor at the bottom? I can't see the damn thing! 3) line numbers instead of the `>>>` prompt 4) a plugin facility where we can define our own `magic` commands. I use Ipython's %timeit ALL the time. 5) Double-click to re-fold the output section as well. Thanks for making this!!!! Cheers, Chris On Sun, Feb 21, 2010 at 4:42 AM, Noam Yorav-Raphael wrote: > I'm pleased to announce DreamPie 1.0 - a new graphical interactive > Python shell! > > Some highlights: > > * Has whatever you would expect from a graphical Python shell - > attribute completion, tooltips which show how to call functions, > highlighting of matching parentheses, etc. > * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, > history recall and completion works as expected, etc. > * Results are saved in the Result History. > * Long output is automatically folded so you can focus on what's > important. > * Jython and IronPython support makes DreamPie a great tool for > exploring Java and .NET classes. > * You can copy any amount of code and immediately execute it, and you > can also copy code you typed interactively into a new file, with the > Copy Code Only command. No tabs are used! > * Free software licensed under GPL version 3. > > Check it out at http://dreampie.sourceforge.net/ and tell me what you > think! > > Have fun, > Noam > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sun Feb 21 12:28:01 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Feb 2010 09:28:01 -0800 (PST) Subject: Saving the Interactive Window with PythonWin Message-ID: <2485b80a-3d51-4627-95d4-eef6dc7a6445@f29g2000yqa.googlegroups.com> Hi everyone, When I run a python script, I know that I can print the results of my calculations on the Interactive Window. Once the scripts ends, I can copy/pate these results on an OpenOffice Writer document. However, I would like to know if I can somehow add some lines to my script, so that it saves the Interactive Window to a text file. How could it be done? And, is there a way to programatically clear out the Interactive Window so that it only shows the last run? Thank you for your help From iurisilvio at gmail.com Sun Feb 21 12:38:51 2010 From: iurisilvio at gmail.com (Iuri) Date: Sun, 21 Feb 2010 15:38:51 -0200 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: <789aac5a1002210938o513573b3ve3b460ad1a166b74@mail.gmail.com> I tested it in Windows Vista. When I type single or double quotes, I get a unicode character, different of python's quotes, and it break my code. But i liked this tool! Thanks! []s iuri On Sun, Feb 21, 2010 at 3:13 PM, Chris Colbert wrote: > This is bloody fantastic! I must say, this fixes everything I hate about > Ipython and gives me the feature I wished it had (with a few minor > exceptions). > > I confirm this working on Kubuntu 9.10 using the ppa listed on the sites > download page. > > I also confirm that it works interactively with PyQt4 and PyGtk (as to be > expected since these toolkits use the PyOS_inputhook for the mainloop). > However, it does not work interactively with wx (again, this is as expected > since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support > is the same as in Ipython if you dont use any of the magic threading > switches, which are now deprecated anyway. > > Matplotlib does not work interactively for me. Is there a special switch > that needs to be used? or should a pick a non-wx backend? (i'm thinking the > latter is more likely) > > A couple of things I would like to see (and will help implement if I can > find the time): > 1) A shortcut to show the docstring of an object. Something like Ipython's > `?`. i.e. `object.foo?` translates to `help(object.foo)` > 2) How do I change the color of the blinking cursor at the bottom? I can't > see the damn thing! > 3) line numbers instead of the `>>>` prompt > 4) a plugin facility where we can define our own `magic` commands. I use > Ipython's %timeit ALL the time. > 5) Double-click to re-fold the output section as well. > > Thanks for making this!!!! > > Cheers, > > Chris > > > On Sun, Feb 21, 2010 at 4:42 AM, Noam Yorav-Raphael wrote: > >> I'm pleased to announce DreamPie 1.0 - a new graphical interactive >> Python shell! >> >> Some highlights: >> >> * Has whatever you would expect from a graphical Python shell - >> attribute completion, tooltips which show how to call functions, >> highlighting of matching parentheses, etc. >> * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, >> history recall and completion works as expected, etc. >> * Results are saved in the Result History. >> * Long output is automatically folded so you can focus on what's >> important. >> * Jython and IronPython support makes DreamPie a great tool for >> exploring Java and .NET classes. >> * You can copy any amount of code and immediately execute it, and you >> can also copy code you typed interactively into a new file, with the >> Copy Code Only command. No tabs are used! >> * Free software licensed under GPL version 3. >> >> Check it out at http://dreampie.sourceforge.net/ and tell me what you >> think! >> >> Have fun, >> Noam >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Sun Feb 21 12:44:25 2010 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 21 Feb 2010 10:44:25 -0700 Subject: Not sure why this is filling my sys memory In-Reply-To: <654D55F2-B276-44E6-A6EF-A9D3A2B5002F@gmail.com> References: <77e831101002201705j6c1fdcbalc91a3fb7d2558ac8@mail.gmail.com> <654D55F2-B276-44E6-A6EF-A9D3A2B5002F@gmail.com> Message-ID: <77e831101002210944o2e96bf0aj5370961af959d6a3@mail.gmail.com> @"ssteinerX at gmail.com" "See this article for some more info about the reported sizes of things: http://www.doughellmann.com/PyMOTW/sys/limits.html" I posted this question on stack overflow. I now have a better appreciation of ssteinerX suggestions of the above link and guppy, I also had pympler suggested. http://stackoverflow.com/questions/2306523/reading-text-files-into-list-then-storing-in-dictionay-fills-system-memory-a Thanks again *Vincent Davis 720-301-3003 * vincent at vincentdavis.net my blog | LinkedIn On Sat, Feb 20, 2010 at 7:15 PM, ssteinerX at gmail.com wrote: > > On Feb 20, 2010, at 8:05 PM, Vincent Davis wrote: > > Code is below, The files are about 5mb and 230,000 rows. When I have 43 > files of them and when I get to the 35th (reading it in) my system gets so > slow that it is nearly functionless. I am on a mac and activity monitor > shows that python is using 2.99GB of memory (of 4GB). (python 2.6 64bit). > The getsizeof() returns 6424 bytes for the alldata . So I am not sure what > is happening. > > > See this article for some more info about the reported sizes of things: > http://www.doughellmann.com/PyMOTW/sys/limits.html > > S > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vicente.soler at gmail.com Sun Feb 21 12:53:45 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Feb 2010 09:53:45 -0800 (PST) Subject: formatting a number as percentage Message-ID: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> I'm trying to print .7 as 70% I've tried: print format(.7,'%%') .7.format('%%') but neither works. I don't know what the syntax is... Can you help? Thank you From ssteinerx at gmail.com Sun Feb 21 13:09:51 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 21 Feb 2010 13:09:51 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002210851r52e63cen50b6815ab3a15b2f@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7f014ea61002210851r52e63cen50b6815ab3a15b2f@mail.gmail.com> Message-ID: <202C3A0D-E637-4C46-9CB4-BD288BC8F618@gmail.com> On Feb 21, 2010, at 11:51 AM, Chris Colbert wrote: > http://dreampie.sourceforge.net/download.html > > reading is a wonderful thing. I got it running on OS X with MacPorts after about an hour of installing everything required for gtk and gtksourceview (including a new gcc, apparently). Now...if I can just figure out how to set the font to something I can actually read both size and anti-alias-wise. S > > On Sun, Feb 21, 2010 at 11:32 AM, Mensanator wrote: > On Feb 21, 10:30?am, Mensanator wrote: > > On Feb 21, 3:42 am, Noam Yorav-Raphael wrote:> I'm pleased to announce DreamPie 1.0 - a new graphical interactive > > > Python shell! > > > > What versions of Python does it suuport? > > What OS are supported? > -- > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomf.sessile at gmail.com Sun Feb 21 13:11:19 2010 From: tomf.sessile at gmail.com (TomF) Date: Sun, 21 Feb 2010 10:11:19 -0800 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <2010022110111943658-tomfsessile@gmailcom> On 2010-02-21 09:53:45 -0800, vsoler said: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... >>> print "Grade is {0:%}".format(.87) Grade is 87.000000% or if you want to suppress those trailing zeroes: >>> print "Grade is {0:.0%}".format(.87) Grade is 87% From paul at boddie.org.uk Sun Feb 21 13:14:21 2010 From: paul at boddie.org.uk (Paul Boddie) Date: Sun, 21 Feb 2010 10:14:21 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> Message-ID: <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> On 21 Feb, 17:32, Mensanator wrote: > On Feb 21, 10:30 am, Mensanator wrote: > > > What versions of Python does it suuport? > > What OS are supported? >From the Web site referenced in the announcement (http:// dreampie.sourceforge.net/): """ # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and Python 3.1. # Works on Windows and Linux. """ Paul From sccolbert at gmail.com Sun Feb 21 13:14:57 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Sun, 21 Feb 2010 13:14:57 -0500 Subject: formatting a number as percentage In-Reply-To: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <7f014ea61002211014j949dd8dg404fb84b58d66227@mail.gmail.com> >>> print('%.0f%%' % (0.7*100)) 70% On Sun, Feb 21, 2010 at 12:53 PM, vsoler wrote: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... > > Can you help? > > Thank you > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dickinsm at gmail.com Sun Feb 21 13:15:18 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Sun, 21 Feb 2010 10:15:18 -0800 (PST) Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <25c91c15-9710-4edd-8e7f-c2057375be39@g11g2000yqe.googlegroups.com> On Feb 21, 5:53?pm, vsoler wrote: > I'm trying to print .7 as 70% > I've tried: > > print format(.7,'%%') > .7.format('%%') > > but neither works. I don't know what the syntax is... Assuming that you're using Python 2.6 (or Python 3.x): >>> format(.7, '%') '70.000000%' >>> format(.7, '.2%') '70.00%' Or see TomF's response for how to use this with the str.format method. -- Mark From vicente.soler at gmail.com Sun Feb 21 13:17:18 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 21 Feb 2010 10:17:18 -0800 (PST) Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> <2010022110111943658-tomfsessile@gmailcom> Message-ID: On Feb 21, 7:11?pm, TomF wrote: > On 2010-02-21 09:53:45 -0800, vsoler said: > > > I'm trying to print .7 as 70% > > I've tried: > > > print format(.7,'%%') > > .7.format('%%') > > > but neither works. I don't know what the syntax is... > >>> print "Grade is {0:%}".format(.87) > > Grade is 87.000000% > > or if you want to suppress those trailing zeroes: > > >>> print "Grade is {0:.0%}".format(.87) > > Grade is 87% Excellent, works perfect!!! From gd_usenet at spamfence.net Sun Feb 21 13:18:05 2010 From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Sun, 21 Feb 2010 19:18:05 +0100 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: vsoler wrote: >I'm trying to print .7 as 70% >I've tried: > >print format(.7,'%%') >.7.format('%%') > >but neither works. I don't know what the syntax is... Did you try this: >>> print('%d%%' % (0.7 * 100)) 70% Best regards, G?nther From john at castleamber.com Sun Feb 21 13:22:30 2010 From: john at castleamber.com (John Bokma) Date: Sun, 21 Feb 2010 12:22:30 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> Message-ID: <87mxz2v47t.fsf@castleamber.com> Jonathan Gardner writes: > On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: >> >> Now, why don't we start a PEP to make python a fully-functional language >> then? > > Because people don't think the same way that programs are written in > functional languages. Heh! When I learned Miranda it felt natural to me. Prolog on the other hand... In short: I am afraid you're overgeneralizing here; it depends on one's background. If not, citation needed ;-) -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From paul at boddie.org.uk Sun Feb 21 13:28:46 2010 From: paul at boddie.org.uk (Paul Boddie) Date: Sun, 21 Feb 2010 10:28:46 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> Message-ID: <238ce1ab-e216-417f-942f-8776370ef266@u20g2000yqu.googlegroups.com> On 21 Feb, 03:00, "sjdevn... at yahoo.com" wrote: > On Feb 18, 2:58?pm, John Nagle wrote: > > > ? ? Multiple processes are not the answer. ?That means loading multiple > > copies of the same code into different areas of memory. ?The cache > > miss rate goes up accordingly. > > A decent OS will use copy-on-write with forked processes, which should > carry through to the cache for the code. True, but the principal issue with CPython and copy-on-write is the reference counting. Consider a large list shared with the child processes which is to be processed (either in part or in its entirety) by each of them. As soon as the child processes start referencing each of the elements, the reference count for each element object will need to be changed and pages will start to be copied for each child process. That's why John wants to avoid the reference counting of shared data and why the Unladen Swallow project has apparently considered storing reference counts in separate regions of memory. Such shared data is really "owned" by the parent process, so it makes little sense for the child processes to manage it with a view to collecting it later. After all, such data should have no cost to each of the child processes (except, perhaps, for the size of the address space referenced by each process, and any resource issues arising from managing that). Paul From marwie at gmx.de Sun Feb 21 14:07:24 2010 From: marwie at gmx.de (marwie) Date: Sun, 21 Feb 2010 11:07:24 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> Message-ID: On 21 Feb., 04:40, Steven D'Aprano wrote: > > Additionally, Python lists are over-allocated so that appends are fast. A > list of (say) 1000 items might be over-allocated to (say) 1024 items, so > that you can do 24 appends before the array is full and the array needs > to be resized. This means that, on average, Python list appending is O(1) > instead of O(N). You can't just change the length blindly, you need to > worry about the over-allocation. Ok, I see your point. However, other data representation might still be able to optimize such a multi-element pop. I'm thinking of deques, for example. > I'm sympathetic to your concern: I've often felt offended that doing > something like this: > > x = SomeReallyBigListOrString > for item in x[1:]: > ? ? process(item) > > has to copy the entire list or string (less the first item). But > honestly, I've never found a situation where it actually mattered. Good grief, it copies that, too? I assumed that the copying is at least delayed until the assignment and that x[1:] is represented by some wrapper that just shuffles the indices around (much like the .indices method that MRAB suggested). Maybe copying chunks of data really isn't that much of an issue as it used to be (and maybe I'm getting old). The application I have in mind has to do with symbolic computation, and expressions would be represented by python lists. It's too early to do any profiling (in fact, it's at the "deciding if python is the right language to implement it" stage), but it will have to handle expressions with many terms (i.e. long lists), and in the end taking these lists apart and putting them back together in different order is the only thing the code will do. That to explain my interest in performance issues related to pyhton lists. Anyway, thanks for your help. Martin. From marwie at gmx.de Sun Feb 21 14:08:30 2010 From: marwie at gmx.de (marwie) Date: Sun, 21 Feb 2010 11:08:30 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <2df4ab82-7877-43f5-ac00-a780885e1950@e19g2000prn.googlegroups.com> Message-ID: On 21 Feb., 07:38, Carl Banks wrote: > Numpy arrays can share underlying data like that when you take > slices. ?For instance, this probably works the way you want: > > a = numpy.array([1,2,3,4,5,6]) > b = a[:3] > c = a[3:] > > None of the actual data was copied here. Hmm, that might be worth looking into. Thanks. From python at mrabarnett.plus.com Sun Feb 21 14:29:22 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 21 Feb 2010 19:29:22 +0000 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4B80B89B.1030109@mrabarnett.plus.com> References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> <4B80B89B.1030109@mrabarnett.plus.com> Message-ID: <4B818992.8060703@mrabarnett.plus.com> MRAB wrote: > Steven D'Aprano wrote: > [snip] >> I'm sympathetic to your concern: I've often felt offended that doing >> something like this: >> >> x = SomeReallyBigListOrString >> for item in x[1:]: >> process(item) >> >> has to copy the entire list or string (less the first item). But >> honestly, I've never found a situation where it actually mattered. >> > [snip] > Could lists gain an .items() method with start and end positions? I was > thinking that it would be a 'view', like with dicts in Python 3. Of > course, that would only be worthwhile with very long lists: > > x = SomeReallyBigListOrString > for item in x.items(1): > process(item) Actually, my example is a bit wrong! My suggestion should have said that the arguments of list.items would resemble those of range: x = SomeReallyBigListOrString for item in x.items(1, None): # [1 : None], or just [1 : ] process(item) Having a third 'stride' argument would also be possible. From m.11ahesh at gmail.com Sun Feb 21 15:24:09 2010 From: m.11ahesh at gmail.com (MY NAME IS MY NAME) Date: Sun, 21 Feb 2010 12:24:09 -0800 (PST) Subject: FOREX : Foreign Exchange Market : FX : Currency Market : Earn Money Quickly. Message-ID: FOREX : Foreign Exchange Market : FX : Currency Market : Earn Money Quickly. Simple Optimized Tips and Tricks, Basics of FOREX to be a king of FOREX in one day. Check out these exclusive never seen tips for free at http://forex-fx-currencymarket.blogspot.com/2010/02/forex-market-size-and-liquidity-showing.html Contents Overview : FOREX : Market Size and Liquidity Showing Top 10 Currency Traders FOREX : Speculation of Currency FOREX : Instruments Financially including Transactions FOREX : FX Rates Determinants as per Government FOREX : Trading Characteristics and Trading Centers FOREX : Market Participants with Access Levels From clp2 at rebertia.com Sun Feb 21 16:18:28 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Feb 2010 13:18:28 -0800 Subject: How would I do a continuous write over a pipe in the following code... In-Reply-To: <2NydneBvv9CPPBzWnZ2dnUVZ_jCdnZ2d@earthlink.com> References: <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com> <2NydneBvv9CPPBzWnZ2dnUVZ_jCdnZ2d@earthlink.com> Message-ID: <50697b2c1002211318s3b437bd0pa13e5f239dfe0e29@mail.gmail.com> On Sun, Feb 21, 2010 at 1:09 PM, Dennis Lee Bieber wrote: > On Sat, 20 Feb 2010 12:46:24 -0800 (PST), chad > declaimed the following in comp.lang.python: > >> Given the following.... >> >> #!/usr/bin/python >> >> import subprocess as s >> >> broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE) >> >> out = broadcast.stdout >> while 1: >> ? ? out > > ? ? ? ?Does nothing... "out" is a name bound to the object identified by > "broadcast.stdout"... > > ? ? ? ?It does nothing unless it is called as... > > ? ? ? ?out(somedata) I'm pretty sure you meant: out.write(somedata) Cheers, Chris -- http://blog.rebertia.com From martin at v.loewis.de Sun Feb 21 16:22:28 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 22:22:28 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> Message-ID: <4B81A414.7020001@v.loewis.de> John Nagle wrote: > I know there's a performance penalty for running Python on a > multicore CPU, but how bad is it? I've read the key paper > ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate > if the GIL just limited Python to running on one CPU at a time, > but it's worse than that; there's excessive overhead due to > a lame locking implementation. Running CPU-bound multithreaded > code on a dual-core CPU runs HALF AS FAST as on a single-core > CPU, according to Beasley. I couldn't reproduce these results on Linux. Not sure what "HALF AS FAST" is; I suppose it means "it runs TWICE AS LONG" - this is what I couldn't reproduce. If I run Beazley's program on Linux 2.6.26, on a 4 processor Xeon (3GHz) machine, I get 30s for the sequential execution, 40s for the multi-threaded case, and 32s for the multi-threaded case when pinning the Python process to a single CPU (using taskset(1)). So it's 6% overhead for threading, and 25% penalty for multicore CPUs - far from the 100% you seem to expect. Regards, Martin From debacle at debian.org Sun Feb 21 16:25:11 2010 From: debacle at debian.org (W. Martin Borgert) Date: Sun, 21 Feb 2010 22:25:11 +0100 Subject: Use eval() safely? Message-ID: <20100221212511.GA23046@beron.tangosoft.com> Hi, I know that this issue has been discussed before, but most of the time using only one argument to eval(). Is it possible to use the following code, e.g. run as part of a web application, to break in and if so, how? import math def myeval(untrustedinput): return eval(untrustedinput, {"__builtins__": None}, { "abs": abs, "sin": math.sin }) Is it possible to define functions or import modules from the untrusted input string? Which Python built-ins and math functions would I have to add to the functions dictionary to make it unsafe? TIA! (Please cc me, thanks.) From showell30 at yahoo.com Sun Feb 21 16:40:41 2010 From: showell30 at yahoo.com (Steve Howell) Date: Sun, 21 Feb 2010 13:40:41 -0800 (PST) Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> Message-ID: <3758eba1-2967-4de3-a3d0-79edc5dd571e@c37g2000prb.googlegroups.com> On Feb 20, 5:55?pm, marwie wrote: > On 21 Feb., 02:30, Steven D'Aprano > cybersource.com.au> wrote: > > Python lists are arrays of pointers to objects, so copying a slice is > > fast: it doesn't have to copy the objects, just pointers. Deleting from > > the end of the list is also quick, because you don't have to move memory, > > just clear some pointers and change the length field. > > > Splitting such an array without copying data is, essentially, impossible. > > Python lists aren't linked lists. > > Well, to split a C array I would simply set l2 to point to l1[10] and > then > change the length of l1 (which I store somewhere else). No copying of > elements > needed. I would have assumed that python can do something like this > with its > internal arrays of pointers, too. > When you remove 10 elements off of a list of size 1000, none of the objects themselves are moved, but the pointers to the objects are all moved, so k*990 bytes get moved backward, where k is the size of a pointer (4 or 8 typically on modern computers). There is no mechanism to advance a pointer forward when you delete or pop from the top. I proposed the following patch to implement an advance-the-pointer scheme, but it is unlikely to be accepted in the near future: http://bugs.python.org/file16034/no_mem_penalty.diff http://bugs.python.org/issue7784 You can find alternative data structures that might serve your needs better, such as collections.deque. If you are interested in how Python lists work internally, you mostly want to look at listobject.c: http://svn.python.org/view/python/trunk/Objects/listobject.c?view=markup In particular, look at list_resize(), list_slice(), and list_ass_slice(). From mensanator at aol.com Sun Feb 21 16:40:54 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 13:40:54 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: On Feb 21, 12:14?pm, Paul Boddie wrote: > On 21 Feb, 17:32, Mensanator wrote: > > > On Feb 21, 10:30 am, Mensanator wrote: > > > > What versions of Python does it suuport? > > > What OS are supported? > > From the Web site referenced in the announcement (http:// > dreampie.sourceforge.net/): > > """ > # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and > Python 3.1. > # Works on Windows and Linux. > """ Yeah, I saw that. Funny that something important like that wasn't part of the announcement. I notice no mention of Mac OS, so visiting the website was a complete waste of time on my part, wasn't it? > Paul From ryan at rfk.id.au Sun Feb 21 16:45:50 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 22 Feb 2010 08:45:50 +1100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4B81A414.7020001@v.loewis.de> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> Message-ID: <1266788750.2990.4.camel@durian> On Sun, 2010-02-21 at 22:22 +0100, Martin v. Loewis wrote: > John Nagle wrote: > > I know there's a performance penalty for running Python on a > > multicore CPU, but how bad is it? I've read the key paper > > ("www.dabeaz.com/python/GIL.pdf"), of course. It would be adequate > > if the GIL just limited Python to running on one CPU at a time, > > but it's worse than that; there's excessive overhead due to > > a lame locking implementation. Running CPU-bound multithreaded > > code on a dual-core CPU runs HALF AS FAST as on a single-core > > CPU, according to Beasley. > > I couldn't reproduce these results on Linux. Not sure what "HALF AS > FAST" is; I suppose it means "it runs TWICE AS LONG" - this is what I > couldn't reproduce. > > If I run Beazley's program on Linux 2.6.26, on a 4 processor Xeon (3GHz) > machine, I get 30s for the sequential execution, 40s for the > multi-threaded case, and 32s for the multi-threaded case when pinning > the Python process to a single CPU (using taskset(1)). > > So it's 6% overhead for threading, and 25% penalty for multicore CPUs - > far from the 100% you seem to expect. It's far from scientific, but I've seen behaviour that's close to a 100% performance penalty on a dual-core linux system: http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 Short story: a particular test suite of mine used to run in around 25 seconds, but a bit of ctypes magic to set thread affinity dropped the running time to under 13 seconds. 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From bartc at freeuk.com Sun Feb 21 16:54:30 2010 From: bartc at freeuk.com (bartc) Date: Sun, 21 Feb 2010 21:54:30 GMT Subject: lists of variables In-Reply-To: References: Message-ID: "Michael Pardee" wrote in message news:mailman.22.1266722722.4577.python-list at python.org... > I'm relatively new to python and I was very surprised by the following > behavior: > >>>> a=1 >>>> b=2 >>>> mylist=[a,b] >>>> print mylist > [1, 2] >>>> a=3 >>>> print mylist > [1, 2] > > Whoah! Are python lists only for literals? Nope: > >>>> c={} >>>> d={} >>>> mydlist=[c,d] >>>> print mydlist > [{}, {}] >>>> c['x']=1 >>>> print mydlist > [{'x': 1}, {}] > > So it looks like variables in a list are stored as object references. > This seems to confirm that: > > mydlist[1]['y']=4 >>>> print mydlist > [{}, {'y': 4}] > > So I figure my initial example doesn't work because if you assign a That shows a different outlook. I would have said your first example works as expected and it was the second example that was strange, possibly due to shallow instead of deep copies by Python. -- Bartc From ssteinerx at gmail.com Sun Feb 21 17:01:25 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 21 Feb 2010 17:01:25 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <0F03CC9E-6D2C-4D70-8327-5B45D475ED07@gmail.com> On Feb 21, 2010, at 4:40 PM, Mensanator wrote: > On Feb 21, 12:14 pm, Paul Boddie wrote: >> On 21 Feb, 17:32, Mensanator wrote: >> >>> On Feb 21, 10:30 am, Mensanator wrote: >> >>>> What versions of Python does it suuport? >> >>> What OS are supported? >> >> From the Web site referenced in the announcement (http:// >> dreampie.sourceforge.net/): >> >> """ >> # Supports Python 2.5, Python 2.6, Jython 2.5, IronPython 2.6 and >> Python 3.1. >> # Works on Windows and Linux. >> """ > > Yeah, I saw that. Funny that something important like that wasn't part > of the > announcement. I notice no mention of Mac OS, so visiting the website > was a complete > waste of time on my part, wasn't it? See my earlier message -- I have it running just fine on 10.6 with MacPorts and even managed to report a bug! S > >> Paul > > -- > http://mail.python.org/mailman/listinfo/python-list From martin at v.loewis.de Sun Feb 21 17:05:44 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 23:05:44 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> Message-ID: <4B81AE38.50501@v.loewis.de> > It's far from scientific, but I've seen behaviour that's close to a 100% > performance penalty on a dual-core linux system: > > http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 > > Short story: a particular test suite of mine used to run in around 25 > seconds, but a bit of ctypes magic to set thread affinity dropped the > running time to under 13 seconds. Indeed, it's not scientific - but with a few more details, you could improve it quite a lot: what specific Linux distribution (the posting doesn't even say it's Linux), what specific Python version had you been using? (less important) what CPUs? If you can: what specific test suite? A lot of science is about repeatability. Making a systematic study is (IMO) over-valued - anecdotal reports are useful, too, as long as they allow for repeatable experiments. Regards, Martin From martin at v.loewis.de Sun Feb 21 17:05:44 2010 From: martin at v.loewis.de (Martin v. Loewis) Date: Sun, 21 Feb 2010 23:05:44 +0100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> Message-ID: <4B81AE38.50501@v.loewis.de> > It's far from scientific, but I've seen behaviour that's close to a 100% > performance penalty on a dual-core linux system: > > http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 > > Short story: a particular test suite of mine used to run in around 25 > seconds, but a bit of ctypes magic to set thread affinity dropped the > running time to under 13 seconds. Indeed, it's not scientific - but with a few more details, you could improve it quite a lot: what specific Linux distribution (the posting doesn't even say it's Linux), what specific Python version had you been using? (less important) what CPUs? If you can: what specific test suite? A lot of science is about repeatability. Making a systematic study is (IMO) over-valued - anecdotal reports are useful, too, as long as they allow for repeatable experiments. Regards, Martin From ryan at rfk.id.au Sun Feb 21 17:39:27 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Mon, 22 Feb 2010 09:39:27 +1100 Subject: Overcoming python performance penalty for multicore CPU In-Reply-To: <4B81AE38.50501@v.loewis.de> References: <4b68ab3d$0$1675$742ec2ed@news.sonic.net> <4B81A414.7020001@v.loewis.de> <4B81AE38.50501@v.loewis.de> Message-ID: <1266791967.4574.16.camel@durian> On Sun, 2010-02-21 at 23:05 +0100, Martin v. Loewis wrote: > > It's far from scientific, but I've seen behaviour that's close to a 100% > > performance penalty on a dual-core linux system: > > > > http://www.rfk.id.au/blog/entry/a-gil-adventure-threading2 > > > > Short story: a particular test suite of mine used to run in around 25 > > seconds, but a bit of ctypes magic to set thread affinity dropped the > > running time to under 13 seconds. > > Indeed, it's not scientific - but with a few more details, you could > improve it quite a lot: what specific Linux distribution (the posting > doesn't even say it's Linux), what specific Python version had you been > using? (less important) what CPUs? If you can: what specific test suite? I'm on Ubuntu Karmic, Python 2.6.4, an AMD Athlon 7750 dual core. Unfortunately the test suite is for a proprietary application. I've been able to reproduce similar behaviour with an open-source test suite, using the current trunk of the "pyfilesystem" project: http://code.google.com/p/pyfilesystem/ In this project "OSFS" is an object-oriented interface to the local filesystem. The test case "TestOSFS.test_cases_in_separate_dirs" runs three theads, each doing a bunch of IO in a different directory. Running the tests normally: rfk at durian:/storage/software/fs$ nosetests fs/tests/test_fs.py:TestOSFS.test_cases_in_separate_dirs . ---------------------------------------------------------------------- Ran 1 test in 9.787s That's the best result from five runs - I saw it go as high as 12 seconds. Watching it in top, I see CPU usage at around 150%. Now using threading2 to set the process cpu affinity at the start of the test run: rfk at durian:/storage/software/fs$ nosetests fs/tests/test_fs.py:TestOSFS.test_cases_in_separate_dirs . ---------------------------------------------------------------------- Ran 1 test in 3.792s Again, best of five. The variability in times here is much lower - I never saw it go above 4 seconds. CPU usage is consistently 100%. 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From clp2 at rebertia.com Sun Feb 21 18:18:19 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 21 Feb 2010 15:18:19 -0800 Subject: with statement and standard library In-Reply-To: <4b81bbf7$0$1659$742ec2ed@news.sonic.net> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> <4b81bbf7$0$1659$742ec2ed@news.sonic.net> Message-ID: <50697b2c1002211518r5ce8c57auf3485ebb52ce33ee@mail.gmail.com> On Sun, Feb 21, 2010 at 3:21 PM, John Nagle wrote: > nobrowser wrote: >> >> Hi. ?The with statement is certainly nifty. ?The trouble is, the >> *only* two documented examples how it can be used with the library >> classes are file objects (which I use all the time) and thread locks >> which I almost never use. ?Yet there are many, many classes in the >> library whose use would be more elegant and readable if the with >> statement could be employed. ?Start with the connection objects in >> httplib and you can probably come up with 10 others easily. > > ? "with" is important for locks because it matters when they're > released. ?It's not as important if release is just resource > recovery. ?Reference counting will recover most objects when they > go out of scope anyway. If you're using CPython that is. The other implementations don't use refcounting and thus don't guarantee the GC will be that timely. So if one wants maximum portability, the `with` statement is *quite* useful. Not to mention there are other uses for `with` besides just freeing resources; e.g. setting a temporary decimal arithmetic context. Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 18:21:27 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 23:21:27 GMT Subject: Efficient way to break up a list into two pieces References: <4b808c9d$0$8819$c3e8da3@news.astraweb.com> <50b45708-76e7-40bc-80e3-0865775be92e@z35g2000yqd.googlegroups.com> <4b80ab3a$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4b81bff7$0$8819$c3e8da3@news.astraweb.com> On Sun, 21 Feb 2010 11:07:24 -0800, marwie wrote: >> x = SomeReallyBigListOrString >> for item in x[1:]: >> ? ? process(item) >> >> has to copy the entire list or string (less the first item). But >> honestly, I've never found a situation where it actually mattered. > > Good grief, it copies that, too? I assumed that the copying is at least > delayed until the assignment and that x[1:] is represented by some > wrapper that just shuffles the indices around (much like the .indices > method that MRAB suggested). Such complexity doesn't happen for free. It costs developer time, more complexity means more bugs, and more runtime overhead, especially for small lists. 99.9% of programs operate on small amounts of data, and "small" gets bigger every year. (I was reading one of my old Uni text books the other day, and one of the projects was an application to index all the words in a text file. The author decided to use disk storage rather than in-memory data structures because he was hoping to read files up to 60,000 words, and considered it unlikely that any PCs would have enough memory to store 60,000 words!) Unless you actually profile the code, you're as likely to be *slowing Python down* by such extra sophistication as you are to speed it up. Copying blocks of pointers is really fast on modern CPUs. As a general rule, Python aims for simplicity of implementation rather than clever, but fragile, tricks. > Maybe copying chunks of data really isn't that much of an issue as it > used to be (and maybe I'm getting old). The application I have in mind > has to do with symbolic computation, and expressions would be > represented by python lists. It's too early to do any profiling (in > fact, it's at the "deciding if python is the right language to implement > it" stage), but it will have to handle expressions with many terms (i.e. > long lists), and in the end taking these lists apart and putting them > back together in different order is the only thing the code will do. Are you likely to have expressions with a hundred or so MILLION terms? If so, then you should start thinking about clever tricks to minimise copying. Otherwise, you're engaged in premature optimization, which is the root of all computer science evil :) -- Steven From nagle at animats.com Sun Feb 21 18:21:38 2010 From: nagle at animats.com (John Nagle) Date: Sun, 21 Feb 2010 15:21:38 -0800 Subject: with statement and standard library In-Reply-To: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> References: <509b4149-0140-45c2-bb8b-557dbdafe88f@m27g2000prl.googlegroups.com> Message-ID: <4b81bbf7$0$1659$742ec2ed@news.sonic.net> nobrowser wrote: > Hi. The with statement is certainly nifty. The trouble is, the > *only* two documented examples how it can be used with the library > classes are file objects (which I use all the time) and thread locks > which I almost never use. Yet there are many, many classes in the > library whose use would be more elegant and readable if the with > statement could be employed. Start with the connection objects in > httplib and you can probably come up with 10 others easily. "with" is important for locks because it matters when they're released. It's not as important if release is just resource recovery. Reference counting will recover most objects when they go out of scope anyway. Don't get carried away just because a new feature is available. John Nagle From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 18:23:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 23:23:54 GMT Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <4b81c08a$0$8819$c3e8da3@news.astraweb.com> On Sun, 21 Feb 2010 13:40:54 -0800, Mensanator wrote: > Yeah, I saw that. Funny that something important like that wasn't part > of the > announcement. I notice no mention of Mac OS, so visiting the website was > a complete > waste of time on my part, wasn't it? Of course not. Now you know that Mac OS isn't officially supported, so you're less ignorant than you were before you went to the website. But since Dreampie is written in Python, it shouldn't be that hard to have it run on Mac OS, provided you can get the GUI tool kit it requires. -- Steven From greg.ewing at canterbury.ac.nz Sun Feb 21 18:32:47 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 22 Feb 2010 12:32:47 +1300 Subject: lists of variables In-Reply-To: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> References: <4b80d7b0$0$8819$c3e8da3@news.astraweb.com> Message-ID: <7udthfFhrbU1@mid.individual.net> Steven D'Aprano wrote: > On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote: > >>The one place where Python does have references is when accessing >>variables in an enclosing scope (not counting module-level). > > What makes you say that? I think Carl is talking about cells, which *are* actually objects (in CPython at least), but they're internal details of the interpreter, and you can't do anything useful with them from Python code. -- Greg From steve at REMOVE-THIS-cybersource.com.au Sun Feb 21 18:33:45 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 21 Feb 2010 23:33:45 GMT Subject: Use eval() safely? References: Message-ID: <4b81c2d9$0$8819$c3e8da3@news.astraweb.com> On Sun, 21 Feb 2010 22:25:11 +0100, W. Martin Borgert wrote: > Hi, > > I know that this issue has been discussed before, but most of the time > using only one argument to eval(). > > Is it possible to use the following code, e.g. run as part of a web > application, to break in and if so, how? > > import math > > def myeval(untrustedinput): > return eval(untrustedinput, {"__builtins__": None}, > { "abs": abs, "sin": math.sin }) > > Is it possible to define functions or import modules from the untrusted > input string? > > Which Python built-ins and math functions would I have to add to the > functions dictionary to make it unsafe? You've got the right idea, but the task is difficult. Please read this thread: http://tav.espians.com/a-challenge-to-break-python-security.html -- Steven From greg.ewing at canterbury.ac.nz Sun Feb 21 18:42:53 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 22 Feb 2010 12:42:53 +1300 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <7udu49Fk3uU1@mid.individual.net> lallous wrote: > If the base defines the method and it was empty, then my C++ code > would still call the function. This is not optimal because I don't > want to go from C++ to Python if the _derived_ class does not > implement the cb. I would simply not implement the method at all in the base class. Then the C++ code can do an attribute lookup for the method, and if it's not found, do nothing. -- Greg From skippy.hammond at gmail.com Sun Feb 21 18:47:34 2010 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 22 Feb 2010 10:47:34 +1100 Subject: Saving the Interactive Window with PythonWin In-Reply-To: <2485b80a-3d51-4627-95d4-eef6dc7a6445@f29g2000yqa.googlegroups.com> References: <2485b80a-3d51-4627-95d4-eef6dc7a6445@f29g2000yqa.googlegroups.com> Message-ID: <4B81C616.5010701@gmail.com> On 22/02/2010 4:28 AM, vsoler wrote: > Hi everyone, > > When I run a python script, I know that I can print the results of my > calculations on the Interactive Window. Once the scripts ends, I can > copy/pate these results on an OpenOffice Writer document. > > However, I would like to know if I can somehow add some lines to my > script, so that it saves the Interactive Window to a text file. How > could it be done? The code for the interactive window is in pywin32\framework\interact.py - eg: >>> from pywin.framework import interact >>> interact.IsInteractiveWindowVisible() True >>> If it is visible, then something like: >>> len(interact.edit.currentView.GetWindowText()) 189 >>> should get you on the right path. > > And, is there a way to programatically clear out the Interactive > Window so that it only shows the last run? Something like: interact.edit.currentView.GetWindowText('line1\nline2\nline3') should work - the first few lines will always be formatted using blue text, and the above works a little strangely when attempting it directly from the interactive prompt, but might still be useful. See the source file I mentioned above for more clues. HTH, Mark > > Thank you for your help From g.bogle at auckland.no.spam.ac.nz Sun Feb 21 19:17:10 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 22 Feb 2010 13:17:10 +1300 Subject: Problem creating executable, with PyQwt Message-ID: My student is trying to build an executable version of a program that uses PyQt and PyQwt, on Windows XP. She has installed: Python 2.6.1, Qt 4.5.0, PyQt 4.5, and PyQwt 5.2.0. There is a module error on running the executable produced by py2exe. Here is the info I got from my student: Traceback (most recent call last): File "ABM15.pyw", line 15, in File "PyQt4\Qwt5\__init__.pyc", line 32, in File "PyQt4\Qwt5\Qwt.pyc", line 12, in File "PyQt4\Qwt5\Qwt.pyc", line 10, in __load ImportError: No module named QtSvg If you Google this last line, you'll find that I've posted this to a forum, but no one answered me. Someone has also had this problem before, although I think they were using PyInstaller and not py2exe. They say that its because Qwt has a hidden import for QtSvg. If I can turn this off, maybe it'll work, but I don't know how. I have downloaded py2exe and I run the attached setup.py file in my working directory. It creates two directories: 'dist' and 'build'. An executable is created in the 'dist' directory along with other things. When I tried running it, it produces a log file, in which I find the error messages. <\quote> Perhaps someone can recognize these symptoms. Thanks, Gib From stef.mientki at gmail.com Sun Feb 21 19:32:21 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Mon, 22 Feb 2010 01:32:21 +0100 Subject: Is there a way to continue after an exception ? In-Reply-To: <1266720681.3908.24.camel@durian> References: <4B8075C1.4090304@gmail.com> <4b807c90$1@dnews.tpgi.com.au> <4b8097e6$1@dnews.tpgi.com.au> <1266720681.3908.24.camel@durian> Message-ID: <4B81D095.3000303@gmail.com> On 21-02-2010 03:51, Ryan Kelly wrote: > On Sun, 2010-02-21 at 13:17 +1100, Lie Ryan wrote: > >> On 02/21/10 12:02, Stef Mientki wrote: >> >>> On 21-02-2010 01:21, Lie Ryan wrote: >>> >>>>> On Sun, Feb 21, 2010 at 12:52 AM, Stef Mientki >>>>> >> wrote: >> >>>>> >>>>>> hello, >>>>>> >>>>>> I would like my program to continue on the next line after an uncaught >>>>>> exception, >>>>>> is that possible ? >>>>>> >>>>>> thanks >>>>>> Stef Mientki >>>>>> >>>>>> >>>>>> >>>> That reminds me of VB's "On Error Resume Next" >>>> >>>> >>> I think that's what I'm after ... >>> >> A much better approach is to use callbacks, the callbacks determines >> whether to raise an exception or continue execution: >> >> def handler(e): >> if datetime.datetime.now()>= datetime.datetime(2012, 12, 21): >> raise Exception('The world has ended') >> # else: ignore, it's fine >> >> def add_ten_error_if_zero(args, handler): >> if args == 0: >> handler(args) >> return args + 10 >> >> print add_ten_error_if_zero(0, handler) >> print add_ten_error_if_zero(10, handler) >> print add_ten_error_if_zero(0, lambda e: None) # always succeeds >> > > Or if you don't like having to explicitly manage callbacks, you can try > the "withrestart" module: > > http://pypi.python.org/pypi/withrestart/ > > It tries to pinch some of the good ideas from Common Lisp's > error-handling system. > > from withrestart import * > > def add_ten_error_if_zero(n): > # This gives calling code the option to ignore > # the error, or raise a different one. > with restarts(skip,raise_error): > if n == 0: > raise ValueError > return n + 10 > > # This will raise ValueError > print add_ten_error_if_zero(0) > > # This will print 10 > with Handler(ValueError,"skip"): > print add_ten_error_if_zero(0) > > # This will exit the python interpreter > with Handler(ValueError,"raise_error",SystemExit): > print add_ten_error_if_zero(0) > > > > Cheers, > > Ryan > > > thanks Ryan (and others), your description of withstart was very informative, and I think I understand why it's impossible what I want (something like madExcept for Delphi / C / C++, see *http://www.madshi.net/madExceptDescription.htm ) * It are not the bugs that you can predict / expect to catch, but the uncaught bugs. So made some first steps, and this seems to be sufficient for now, if you're interested, look here, http://mientki.ruhosting.nl/data_www/pylab_works/pw_bug_reporter.html cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at boddie.org.uk Sun Feb 21 20:02:22 2010 From: david at boddie.org.uk (David Boddie) Date: Mon, 22 Feb 2010 02:02:22 +0100 Subject: Problem creating executable, with PyQwt References: Message-ID: On Monday 22 February 2010 01:17, Gib Bogle wrote: > > > Traceback (most recent call last): > File "ABM15.pyw", line 15, in > File "PyQt4\Qwt5\__init__.pyc", line 32, in > File "PyQt4\Qwt5\Qwt.pyc", line 12, in > File "PyQt4\Qwt5\Qwt.pyc", line 10, in __load > ImportError: No module named QtSvg > > If you Google this last line, you'll find that I've posted this to a > forum, but no one answered me. Someone has also had this problem before, > although I think they were using PyInstaller and not py2exe. They say that > its because Qwt has a hidden import for QtSvg. If I can turn this off, > maybe it'll work, but I don't know how. > > I have downloaded py2exe and I run the attached setup.py file in my > working directory. It creates two directories: 'dist' and 'build'. An > executable is created in the 'dist' directory along with other things. > When I tried running it, it produces a log file, in which I find the error > messages. > > <\quote> > > Perhaps someone can recognize these symptoms. Someone asked this question on the PyQt mailing list, too: http://www.riverbankcomputing.com/pipermail/pyqt/2010-February/025827.html I believe it was also asked on the #pyqt IRC channel on freenode. I think I have previously referred people with py2exe/PyQt issues to this page on the PyQt Wiki: http://www.py2exe.org/index.cgi/Py2exeAndPyQt If you can somehow convince py2exe to include the QtSvg module (and presumably the libQtSvg library as well) then perhaps that will solve this problem. David From rantingrick at gmail.com Sun Feb 21 20:06:54 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 21 Feb 2010 17:06:54 -0800 (PST) Subject: Apologies -- Test message References: Message-ID: On Feb 21, 12:49?pm, Dennis Lee Bieber wrote: Note: The author of this message requested that it not be archived. This message will be removed from Groups in 6 days (Feb 28, 12:49 pm). I've not seen a message via Gmane in something like 36 hours... and find it hard to believe this group would be that quiet... Could it be that Gmane is giving you a taste of your own (David Copperfield) medicine? From rantingrick at gmail.com Sun Feb 21 20:39:19 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 21 Feb 2010 17:39:19 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> Message-ID: <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Mensanator snipped: """Yeah, I saw that. Funny that something important like that wasn't part of the announcement. I notice no mention of Mac OS, so visiting the website was a complete waste of time on my part, wasn't it?""" Oh Mensanator, why you always so grumpy? I visited your site a few years ago and i found it to be a complete waste of my time but you don't hear me whining about it do you? Besides mac is always the last to get releases (if any) everybody knows that. If you drive a porsche you can't get all upset every time you find yourself on road with pot- holes, your just not *that* important because you drive a porsche! Please (in the future) leave the ranting to me, i'm better at it ;). Thanks for the release Noam, i look forward to "test driving" it. hehe ;) From philip at semanchuk.com Sun Feb 21 21:08:08 2010 From: philip at semanchuk.com (Philip Semanchuk) Date: Sun, 21 Feb 2010 21:08:08 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> On Feb 21, 2010, at 8:39 PM, rantingrick wrote: > > > Mensanator snipped: """Yeah, I saw that. Funny that something > important like that wasn't part of the announcement. I notice no > mention of Mac OS, so visiting the website was a complete waste of > time on my part, wasn't it?""" > > Oh Mensanator, why you always so grumpy? I visited your site a few > years ago and i found it to be a complete waste of my time but you > don't hear me whining about it do you? Besides mac is always the last > to get releases (if any) everybody knows that. Erm...not if the developer uses a Mac. =) From anand.shashwat at gmail.com Sun Feb 21 21:10:48 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 07:40:48 +0530 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> Message-ID: Just got it working in mac. Installing dependencies took a bit though. On Mon, Feb 22, 2010 at 7:38 AM, Philip Semanchuk wrote: > > On Feb 21, 2010, at 8:39 PM, rantingrick wrote: > > >> >> Mensanator snipped: """Yeah, I saw that. Funny that something >> important like that wasn't part of the announcement. I notice no >> mention of Mac OS, so visiting the website was a complete waste of >> time on my part, wasn't it?""" >> >> Oh Mensanator, why you always so grumpy? I visited your site a few >> years ago and i found it to be a complete waste of my time but you >> don't hear me whining about it do you? Besides mac is always the last >> to get releases (if any) everybody knows that. >> > > > Erm...not if the developer uses a Mac. =) > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Sun Feb 21 21:32:18 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 21 Feb 2010 21:32:18 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> <42A48E92-3B0A-4E59-AFE9-A47E663E9DBA@semanchuk.com> Message-ID: <69B64EDC-57EB-41CF-BAF4-B2D63E82D80B@gmail.com> On Feb 21, 2010, at 9:10 PM, Shashwat Anand wrote: > Just got it working in mac. Installing dependencies took a bit though. I used macports and it was only 2 installs: # sudo port install py26-pygtksourceview # sudo port install py26-gtk2 It sure did install a lot of other stuff, like a new gcc(?) though; took almost an hour. S > > On Mon, Feb 22, 2010 at 7:38 AM, Philip Semanchuk wrote: > > On Feb 21, 2010, at 8:39 PM, rantingrick wrote: > > > > Mensanator snipped: """Yeah, I saw that. Funny that something > important like that wasn't part of the announcement. I notice no > mention of Mac OS, so visiting the website was a complete waste of > time on my part, wasn't it?""" > > Oh Mensanator, why you always so grumpy? I visited your site a few > years ago and i found it to be a complete waste of my time but you > don't hear me whining about it do you? Besides mac is always the last > to get releases (if any) everybody knows that. > > > Erm...not if the developer uses a Mac. =) > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From g.bogle at auckland.no.spam.ac.nz Sun Feb 21 21:42:40 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 22 Feb 2010 15:42:40 +1300 Subject: Problem creating executable, with PyQwt References: Message-ID: Thanks David. > Someone asked this question on the PyQt mailing list, too: > > http://www.riverbankcomputing.com/pipermail/pyqt/2010-February/025827.html That's my student, Helvin. > > I believe it was also asked on the #pyqt IRC channel on freenode. I think > I have previously referred people with py2exe/PyQt issues to this page on > the PyQt Wiki: > > http://www.py2exe.org/index.cgi/Py2exeAndPyQt > > If you can somehow convince py2exe to include the QtSvg module (and > presumably the libQtSvg library as well) then perhaps that will solve > this problem. I just did a quick test myself, and confirmed that this works for sip. I'm not at all clear what "--includes" arguments might be needed for QtSvg (and libQtSvg). I'll pass this info on to Helvin. Gib From mensanator at aol.com Sun Feb 21 22:44:29 2010 From: mensanator at aol.com (Mensanator) Date: Sun, 21 Feb 2010 19:44:29 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: On Feb 21, 7:39?pm, rantingrick wrote: > Mensanator snipped: """Yeah, I saw that. Funny that something > important like that wasn't part of the announcement. I notice no > mention of Mac OS, so visiting the website was a complete waste of > time on my part, wasn't it?""" > > Oh Mensanator, why you always so grumpy? Part of the job requirements of a gadfly. > I visited your site a few > years ago and i found it to be a complete waste of my time but you > don't hear me whining about it do you? Did I ever claim it wasn't? > Besides mac is always the last > to get releases (if any) everybody knows that. I'm not complaining about the lack of Mac support, just that it wasn't mentioned in the announcement. > If you drive a porsche > you can't get all upset every time you find yourself on road with pot- > holes, your just not *that* important because you drive a porsche! "You're" not getting the point. > Please (in the future) leave the ranting to me, i'm better at it ;). > > Thanks for the release Noam, i look forward to "test driving" it. > hehe ?;) From m.77ahesh at gmail.com Sun Feb 21 23:39:39 2010 From: m.77ahesh at gmail.com (miss world) Date: Sun, 21 Feb 2010 20:39:39 -0800 (PST) Subject: PAPER PRESENTATIONS AND SEMIMAR TOPICS. Message-ID: <671e4c8d-fe7a-42da-ab33-3729d0dcdff1@j27g2000yqn.googlegroups.com> PAPER PRESENTATIONS AND SEMIMAR TOPICS. CHECK OUR VAST PAPER PRESENTATIONS AND SEMIMAR TOPICS INCLUDING PROJECTS FOR FREE AT http://presentationsandseminars.blogspot.com From jgardner at jonathangardner.net Mon Feb 22 00:15:43 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Sun, 21 Feb 2010 21:15:43 -0800 Subject: Efficient way to break up a list into two pieces In-Reply-To: <4b80d744$0$8819$c3e8da3@news.astraweb.com> References: <4b808f37$0$8819$c3e8da3@news.astraweb.com> <4b80d744$0$8819$c3e8da3@news.astraweb.com> Message-ID: <6cc20cea1002212115v2c03d014x110291453f53e049@mail.gmail.com> On Sat, Feb 20, 2010 at 10:48 PM, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 21:21:47 -0800, Jonathan Gardner wrote: >> For ten items, though, is it really faster to muck around with array >> lengths than just copying the data over? Array copies are extremely fast >> on modern processors. > > My mistake, he actually wants l1[10:] copied. So you might be copying a > huge amount of data, not just ten items. > > Or if you prefer, replace 10 by 100000000. > If you need to scale that direction, it's time to install a database. >> Programmer time and processor time being what it is, I still think my >> answer is the correct one. No, it's not what he says he wants, but it is >> what he needs. > > You missed the point that your suggestion gives radically different > behaviour to what the OP indicated he is using. He mutates the list in > place, you rebind the list's name. That has *very* different semantics. > > > The OP may not care about the difference, but if he does require the > first behaviour, then your solution doesn't help. > Correct. -- Jonathan Gardner jgardner at jonathangardner.net From greg.ewing at canterbury.ac.nz Mon Feb 22 00:45:40 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 22 Feb 2010 18:45:40 +1300 Subject: Use eval() safely? In-Reply-To: References: Message-ID: <7uejcjFgf6U1@mid.individual.net> W. Martin Borgert wrote: > def myeval(untrustedinput): > return eval(untrustedinput, {"__builtins__": None}, > { "abs": abs, "sin": math.sin }) > > Is it possible to define functions or import modules from the > untrusted input string? This is NOT safe as it stands. It still isn't safe even if you put nothing in the globals dict at all. A couple of ways someone can do nasty things to you: # Wipe out any file writable by the calling process eval("[c for c in (0).__class__.__bases__[0].__subclasses__() if c.__name__ == 'file'][0]('/my/precious/file', 'w')") # Use up large amounts of memory and CPU time eval("100000**100000") -- Greg From steven at REMOVE.THIS.cybersource.com.au Mon Feb 22 01:07:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Feb 2010 06:07:05 GMT Subject: Use eval() safely? References: <7uejcjFgf6U1@mid.individual.net> Message-ID: On Mon, 22 Feb 2010 18:45:40 +1300, Gregory Ewing wrote: > W. Martin Borgert wrote: > >> def myeval(untrustedinput): >> return eval(untrustedinput, {"__builtins__": None}, >> { "abs": abs, "sin": math.sin }) >> >> Is it possible to define functions or import modules from the untrusted >> input string? > > This is NOT safe as it stands. It still isn't safe even if you put > nothing in the globals dict at all. It's *especially* not safe if you put nothing in the globals dict, because Python kindly rectifies that by putting the builtins into it: >>> eval("__builtins__.keys()", {}, {}) ['IndexError', 'all', 'help', 'vars', ... 'OverflowError'] >>> eval("globals()", {}, {}) {'__builtins__': {...}} >>> >>> eval("globals()", {'__builtins__': None}, {}) Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'globals' is not defined So {'__builtins__': None} is safer than {}. Still not safe, exactly, but safer. Or at least you make the Black Hats work harder before they own your server :) -- Steven From norman at smash-net.org Mon Feb 22 01:49:51 2010 From: norman at smash-net.org (=?ISO-8859-1?Q?Norman_Rie=DF?=) Date: Mon, 22 Feb 2010 07:49:51 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: <4B82290F.9000508@smash-net.org> Am 02/21/10 22:09, schrieb Dennis Lee Bieber: > On Sat, 20 Feb 2010 23:12:50 +0100, Norman Rie? > declaimed the following in comp.lang.python: > > >> Hello, >> >> i am trying to read a large bz2 compressed textfile using the bz2 module. >> The file is 1717362770 lines long and 8GB large. >> Using this code >> >> source_file = bz2.BZ2File(file, "r") >> for line in source_file: >> print line.strip() >> >> print "Exiting" >> print "I used file: " + file >> >> the loop exits cleanly after 4311 lines in midline and the prints are >> executed. >> This happened on two different boxes runnig different brands of linux. >> Is there something i miss or should be done differently? >> >> > Please verify your indentation! What you posted above is invalid in > many ways. > I am sorry, the indentation suffered from pasting. This is the actual code: source_file = bz2.BZ2File(file, "r") for line in source_file: print line.strip() print "Exiting" print "I used file: " + file From steven at REMOVE.THIS.cybersource.com.au Mon Feb 22 03:02:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 22 Feb 2010 08:02:01 GMT Subject: Reading a large bz2 textfile exits early References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: > This is the actual code: > > source_file = bz2.BZ2File(file, "r") > for line in source_file: > print line.strip() > > print "Exiting" > print "I used file: " + file Have you verified that the bz file is good by opening it in another application? -- Steven From norman at smash-net.org Mon Feb 22 03:43:17 2010 From: norman at smash-net.org (=?UTF-8?B?Tm9ybWFuIFJpZcOf?=) Date: Mon, 22 Feb 2010 09:43:17 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: <4B8243A5.20201@smash-net.org> Am 02/22/10 09:02, schrieb Steven D'Aprano: > On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: > > >> This is the actual code: >> >> source_file = bz2.BZ2File(file, "r") >> for line in source_file: >> print line.strip() >> >> print "Exiting" >> print "I used file: " + file >> > > Have you verified that the bz file is good by opening it in another > application? > > > > Yes, bzcat is running through the file fine. And piping bzcat output into the python script reading stdin works fine, too. From jasminsweety145 at gmail.com Mon Feb 22 05:01:18 2010 From: jasminsweety145 at gmail.com (jasmin sweety) Date: Mon, 22 Feb 2010 02:01:18 -0800 (PST) Subject: %%% Anuksha navel & smootched by the Hero V----? %%% Message-ID: %%% Anuksha navel & smootched by the Hero V----? %%% http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ From danijel.gvero at gmail.com Mon Feb 22 05:48:55 2010 From: danijel.gvero at gmail.com (DANNY) Date: Mon, 22 Feb 2010 02:48:55 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> Message-ID: <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> On Feb 21, 1:54?am, Tim Roberts wrote: > DANNY wrote: > > >If I want to have a MPEG-4/10 coded video and stream it through the > >network and than have the same video on the client side, what should I > >use and of course I don't want to have raw MPEG data, because than I > >couldn't extract the frames to manipulate them. > > If you want to manipulate the frames (as bitmaps), then you have little > choice but to decode the MPEG as you receive it, manipulate the bitmaps, > and re-encode it back to MPEG. > > That's going to take a fair amount of time... > -- > Tim Roberts, t... at probo.com > Providenza & Boekelheide, Inc. Yes, well beside bieng time-consuming, that is also inappropriate for me, because I want to have clip that would be streamed across the network and have the same GoP on the client side as the original-because I want to see what is the effect of errors on different GoP sizes. I would manipuleta the received clip just in the way that (if there are too many errors) I would stop displaying untill the next I frame.....I cant find a way to do that....is there a way? From luke.leighton at googlemail.com Mon Feb 22 05:54:01 2010 From: luke.leighton at googlemail.com (lkcl) Date: Mon, 22 Feb 2010 02:54:01 -0800 (PST) Subject: What happened to pyjamas? References: <6a8e506c-63df-482b-a39d-148e6217ba2c@o3g2000yqb.googlegroups.com> Message-ID: On Feb 19, 2:43 pm, John Pinner wrote: > It appears that, in trying to cut down spm, somone chahnged a DNS > entry and screwed it up : it shouldbe back before long. yep. i've now got access to the web interface for the dns whois records. they got poo'd up (only one entry) and then the person who made the changes was ill for a couple of days. i needed to change the DNS server to one that i control (rather than a "dumb" get-free-hosting-for-?1.99-a-month provider so that i could add http://wiki.pyjs.org (using a pyjamas-based wiki of course), move away from sourceforge VHOSTS, and generally set things up a little bit better. l. From luke.leighton at googlemail.com Mon Feb 22 05:58:17 2010 From: luke.leighton at googlemail.com (lkcl) Date: Mon, 22 Feb 2010 02:58:17 -0800 (PST) Subject: look at the google code References: Message-ID: <711cb713-4b4a-47f6-8922-ce1ada7d64e6@e1g2000yqh.googlegroups.com> On Feb 19, 10:41 am, Allison Vollmann wrote: > http://code.google.com/p/pyjamas/ > > Last update from yesterday, is the same project? only the tarballs are maintained on there, and the wiki and the issue tracker. we couldn't get control of that site for quite some time so started using sourceforget for svn, but the issue tracker on sourceforget is truly dreadful. basically there's bits of pyjamas splattered all over the place in a pick-n-mix setup :) mostly this is for the convenience of the key developers - welcome to free software, where the developers do what they like because it makes _their_ lives easier... l. From karthigacool at gmail.com Mon Feb 22 08:16:42 2010 From: karthigacool at gmail.com (karthiga madhan) Date: Mon, 22 Feb 2010 05:16:42 -0800 (PST) Subject: insurance, life insurance, home insurance and their benefits www.autoinsurance-2010.blogspot.com Message-ID: <28263151-ebd7-4aa3-a79a-e741ee3bdfa5@z10g2000prh.googlegroups.com> insurance, life insurance, home insurance and their benefits www.autoinsurance-2010.blogspot.com From lie.1296 at gmail.com Mon Feb 22 08:29:55 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Tue, 23 Feb 2010 00:29:55 +1100 Subject: Reading a large bz2 textfile exits early In-Reply-To: References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> Message-ID: <4b8286ec$1@dnews.tpgi.com.au> On 02/22/10 19:43, Norman Rie? wrote: > Am 02/22/10 09:02, schrieb Steven D'Aprano: >> On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: >> >> >>> This is the actual code: >>> >>> source_file = bz2.BZ2File(file, "r") >>> for line in source_file: >>> print line.strip() >>> >>> print "Exiting" >>> print "I used file: " + file >>> >> >> Have you verified that the bz file is good by opening it in another >> application? >> >> >> >> > > Yes, bzcat is running through the file fine. And piping bzcat output > into the python script reading stdin works fine, too. test with using something other than bzcat; bzcat does certain things differently because of the way it works (a cat for bzipped file). Try using plain "bunzip2 filename.bz2" From albert at spenarnc.xs4all.nl Mon Feb 22 08:44:02 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Feb 2010 13:44:02 GMT Subject: Modifying Class Object References: Message-ID: In article , Steve Holden wrote: >Alf P. Steinbach wrote: >> * Steve Holden: >>> Alf P. Steinbach wrote: >> [snip] >>>> >>>> Since in the quoting above no reference to definition of "pointer" >>>> remains: "pointer" refers to a copyable reference value as seen from the >>>> Python level, in the same way as "pointer" is used by e.g. the Java >>>> language spec. >>>> >> [snip] >>>> >>>> If so, then that's correct: a Python (or Java, or whatever language) >>>> pointer is not necessarily directly a memory address, and furthermore id >>>> is not guaranteed to reproduce the bits of a pointer value -- which >>>> might not even make sense. >>>> >>>> All that id does is to produce a value that uniquely identifies the >>>> object pointed to, i.e. it corresponds to the pointer value, and >>>> although in CPython that's simply the bits of a C pointer typed as >>>> integer, in IronPython it's not. >>>> >>> You go too far here. What you are referring to in your bizarrely >>> constructed definition above >> >> No, it's not bizarre, it's the standard general language independent >> definition. >> >*The* standard general language independent definition? As defined >where? The id() value doesn't "correspond to the pointer value", it >corresponds to the object. Why you see the need for this indirection >remains a mystery. No it doesn't. If an object is garbage collected, the id() might be recycled. At that time the id() corresponds to quite a different object. OTOH if you kill an object in Python it is gone forever. Of course there is a standard computer science idea of what a pointer is. If you admit the pointer terminology, you can understand that a pointer value is all what id() can tell us. You seem to subsconsciously substitute "assembler language address" for it. When someone says: "pointers are bad" what really meant is "manipulating assembler language addresses in a high level language is bad". (Everybody agrees, but sometimes you must use e.g. c as sort of assembler.) That is not the kind of pointers we're talking about here. (I once studied algol 68, and never got confused about these subjects anymore, recommended.) > >regards > Steve >-- > Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From hidura at gmail.com Mon Feb 22 09:03:32 2010 From: hidura at gmail.com (hidura at gmail.com) Date: Mon, 22 Feb 2010 14:03:32 +0000 Subject: Problem with __init__.py in Python3.1 In-Reply-To: <4bbf7fb21002041810xc9bf899v1827ff83abb67c44@mail.gmail.com> Message-ID: <001485e7c7b6fad3a9048030e5e1@google.com> For finnished the subject i resolve the problem using the PEP-328, i was using the old kind of imports :s On Feb 4, 2010 10:10pm, Hidura wrote: > Thanks i middle resolve the problem, and i going to read the PEP-366 i've > been read the 328, i will kept informed of the progresses. > Thanks again for the help > On Thu, Feb 4, 2010 at 6:47 PM, Ben Finney ben+python at benfinney.id.au> > wrote: > "Gabriel Genellina" gagsl-py2 at yahoo.com.ar> writes: > > If you directly run a script from inside a package, Python does not > > know that it belongs to a package, and treats it as a simple, lonely > > script. In that case, relative imports won't work. > Which I consider to be a bug. Fortunately, it's already addressed in PEP > 366 http://www.python.org/dev/peps/pep-0366/>. Unfortunately, it > involves more hackish boilerplate at the top of the program, and is only > available in Python 2.6+. > -- > \ ?Ignorance more frequently begets confidence than does | > `\ knowledge.? ?Charles Darwin, _The Descent of Man_, 1871 | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > -- > Hidura -------------- next part -------------- An HTML attachment was scrubbed... URL: From icanbob at gmail.com Mon Feb 22 09:40:15 2010 From: icanbob at gmail.com (bobicanprogram) Date: Mon, 22 Feb 2010 06:40:15 -0800 (PST) Subject: ANN: Python-SIMPL v2.0.0 released Message-ID: <964d1dcb-46a9-40a5-ab41-199fd1e364a7@t21g2000vbo.googlegroups.com> The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the Send/Receive/Reply messaging (first popularized by QNX) to the open source Linux world. Since its inception more that 10 years ago, the SIMPL toolkit has grown steadily in functionality. Through the use of surrogates, SIMPL modules can be dispersed seamlessly across networks including heterogeneous networks with only one Linux node. SIMPL modules can also be written in several programming languages including Python, C, C++, JAVA and Tcl/Tk. Modules written in different languages can be mixed in a SIMPL appliction. Python-SIMPL has been used to connect Python UIs to C data acquisition/ computation backends. While this is an example of a common use for the toolkit, it is by no means the only place it could be useful. Python to Python, Python to JAVA as well as Python to C are all seamlessly possible in both local or distributed applications. Python- SIMPL allows a software application to be broken up into modules where the language choices for each module can be optimized. The Python-SIMPL interface library has undergone a fundamental revision with the v2.0.0 release. The underlying shared library which wraps the SIMPL toolkit as a Python extension was cleaned up considerably. In addition two new Python wrappers were created to expose this SIMPL toolkit in more object oriented fashion to the Python developer. The simplest starting point for exploring the Python-SIMPL toolkit is an online "hello world" level tutorial at: http://www.icanprogram.com/06py/lesson1/lesson1.html The Python-SIMPL toolkit can be downloaded in source form at: http://www.icanprogram.com/simpl/python.self.htm or in precompiled binary (i386) form at: http://www.icanprogram.com/simpl/pythonbin.self.html We at the SIMPL project welcome participants at all levels of expertise. If you are interested do not hesitate to contact us. bob From wolftracks at invalid.com Mon Feb 22 10:22:02 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 07:22:02 -0800 Subject: What's Going on between Python and win7? Message-ID: Last night I copied a program from folder A to folder B. It inspects the contents of files in a folder. When I ran it in B, it gave the results for A! Out of frustration I changed the name in A, and fired up the program in B. Win7 went into search mode for the file. I looked at properties for the B program, and it was clearly pointing to folder A. Anyone have this happen to them? Another anomaly. I have the files track.py and trackstudy.py in the same folder along with 100 or so other py and txt data files. When I did a search from the folder window in the upper right corner, search only found one of the two. I called HP tech support about it, and they could see it for themselves via remote control. They had no idea, but agreed to contact MS. In this case, I noted that this search box has some sort of filter associated with it. Possibly, in my early stages of learning to navigate in Win7, I accidentally set the filter. Comments? From norman at smash-net.org Mon Feb 22 10:38:24 2010 From: norman at smash-net.org (=?UTF-8?B?Tm9ybWFuIFJpZcOf?=) Date: Mon, 22 Feb 2010 16:38:24 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: <4b8286ec$1@dnews.tpgi.com.au> References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> <4b8286ec$1@dnews.tpgi.com.au> Message-ID: <4B82A4F0.3010403@smash-net.org> Am 02/22/10 14:29, schrieb Lie Ryan: > On 02/22/10 19:43, Norman Rie? wrote: > >> Am 02/22/10 09:02, schrieb Steven D'Aprano: >> >>> On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: >>> >>> >>> >>>> This is the actual code: >>>> >>>> source_file = bz2.BZ2File(file, "r") >>>> for line in source_file: >>>> print line.strip() >>>> >>>> print "Exiting" >>>> print "I used file: " + file >>>> >>>> >>> Have you verified that the bz file is good by opening it in another >>> application? >>> >>> >>> >>> >>> >> Yes, bzcat is running through the file fine. And piping bzcat output >> into the python script reading stdin works fine, too. >> > test with using something other than bzcat; bzcat does certain things > differently because of the way it works (a cat for bzipped file). Try > using plain "bunzip2 filename.bz2" > Did that too. Works as expected. From krister.svanlund at gmail.com Mon Feb 22 10:43:07 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Mon, 22 Feb 2010 16:43:07 +0100 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: <2cf430a61002220743j4d00a7cdt828122a67f016025@mail.gmail.com> On Mon, Feb 22, 2010 at 4:22 PM, W. eWatson wrote: > Last night I copied a program from folder A to folder B. It inspects the > contents of files in a folder. When I ran it in B, it gave the results for > A! Out of frustration I changed the name in A, and fired up the program in > B. Win7 went into search mode for the file. I looked at properties for the B > program, and it was clearly pointing to folder A. > > Anyone have this happen to them? > > Another anomaly. I have the files track.py and trackstudy.py in the same > folder along with 100 or so other py and txt data files. When I did a search > from the folder window in the upper right corner, search only found one of > the two. I called HP tech support about it, and they could see it for > themselves via remote control. They had no idea, but agreed to ?contact MS. > In this case, I noted that this search box has some sort of filter > associated with it. Possibly, in my early stages of learning to navigate in > Win7, I accidentally set the filter. > > Comments? I can't really see the python related problem here... From python at mrabarnett.plus.com Mon Feb 22 11:01:34 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 16:01:34 +0000 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: <4B82AA5E.10407@mrabarnett.plus.com> W. eWatson wrote: > Last night I copied a program from folder A to folder B. It inspects the > contents of files in a folder. When I ran it in B, it gave the results > for A! Out of frustration I changed the name in A, and fired up the > program in B. Win7 went into search mode for the file. I looked at > properties for the B program, and it was clearly pointing to folder A. > Sounds like you didn't copy it but made a shortcut to it instead. > Anyone have this happen to them? > > Another anomaly. I have the files track.py and trackstudy.py in the same > folder along with 100 or so other py and txt data files. When I did a > search from the folder window in the upper right corner, search only > found one of the two. I called HP tech support about it, and they could > see it for themselves via remote control. They had no idea, but agreed > to contact MS. In this case, I noted that this search box has some sort > of filter associated with it. Possibly, in my early stages of learning > to navigate in Win7, I accidentally set the filter. > > Comments? Not Python-related. From invalid at invalid.invalid Mon Feb 22 11:29:47 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 16:29:47 +0000 (UTC) Subject: What's Going on between Python and win7? References: Message-ID: On 2010-02-22, W. eWatson wrote: > Last night I copied a program from folder A to folder B. [tail of various windows breakages elided] > Comments? Switch to Linux? Or at least install Cygwin? -- Grant Edwards grante Yow! Maybe I should have at asked for my Neutron Bomb visi.com in PAISLEY -- From mail at hellmutweber.de Mon Feb 22 11:32:11 2010 From: mail at hellmutweber.de (Hellmut Weber) Date: Mon, 22 Feb 2010 17:32:11 +0100 Subject: A tool for find dependencies relationships behind Python projects In-Reply-To: References: Message-ID: <4B82B18B.3020707@hellmutweber.de> Hi Victor, I would be intereseted to use your tool ;-) My system is Sabayon-5.1 on Lenovo T61. Trying for the first time easy_install I get the following error: ==================== root at sylvester ~ # easy_install gluttony Searching for gluttony Reading http://pypi.python.org/simple/gluttony/ Reading http://code.google.com/p/python-gluttony/ Best match: Gluttony 0.3 Downloading http://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md5=c7774d4fcc0402097f90dc81186de465 Processing Gluttony-0.3.zip Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD Traceback (most recent call last): File "/usr/bin/easy_install", line 9, in load_entry_point('distribute==0.6.8', 'console_scripts', 'easy_install')() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1708, in main with_ei_usage(lambda: File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1696, in with_ei_usage return f() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1712, in distclass=DistributionWithoutHelpCommands, **kw File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 236, in run self.easy_install(spec, not self.no_deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 471, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 501, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 680, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 957, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 946, in run_setup run_setup(setup_script, args) File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 29, in run_setup lambda: execfile( File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 70, in run return func() File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 31, in {'__file__':setup_script, '__name__':'__main__'} File "setup.py", line 9, in File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", line 1, in # File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", line 13, in ImportError: No module named pip.log root at sylvester ~ # ==================== I emerged app-misc/pip, but that didn't help, the error remains the same What is missing? Any help appreciated Best regards Hellmut Am 19.02.2010 17:16, schrieb Victor Lin: > Hi, > > I just wrote a tool for drawing dependencies relationships diagram of > Python project on Pypi. Here is the home page of the tool: > > http://code.google.com/p/python-gluttony/ > > Some examples: > Sprox: > http://static.ez2learn.com/gluttony/sprox_dot.png > > TurboGears2: > http://static.ez2learn.com/gluttony/tg2_dot.png > > Hope this could be helpful :P > > Regards. > Victor Lin. -- Dr. Hellmut Weber mail at hellmutweber.de Degenfeldstra?e 2 tel +49-89-3081172 D-80803 M?nchen-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq From bryanvick at gmail.com Mon Feb 22 11:32:36 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 08:32:36 -0800 (PST) Subject: Efficiently building ordered dict Message-ID: I am looping through a list and creating a regular dictionary. From that dict, I create an ordered dict. I can't think of a way to build the ordered dict while going through the original loop. Is there a way I can avoid creating the first unordered dict just to get the ordered dict? Also, I am using pop(k) to retrieve the values from the unordered dict while building the ordered one because I figure that as the values are removed from the unordered dict, the lookups will become faster. Is there a better idiom that the code below to create an ordered dict from an unordered list? unorderedDict = {} for thing in unorderedList: if thing.id in unorderedDict: UpdateExistingValue(unorderedDict[thing.id]) else: CreateNewValue(unorderedDict[thing.id]) orderedDict = OrderedDict() for k in sorted(unorderedDict.keys()): orderedDict[k] unorderedDict.pop(k) From anand.shashwat at gmail.com Mon Feb 22 11:49:42 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:19:42 +0530 Subject: A tool for find dependencies relationships behind Python projects In-Reply-To: <4B82B18B.3020707@hellmutweber.de> References: <4B82B18B.3020707@hellmutweber.de> Message-ID: Same issue here, easy_install fails here is traceback, Shashwat-Anands-MacBook-Pro:Downloads l0nwlf$ easy_install gluttony Searching for gluttony Reading http://pypi.python.org/simple/gluttony/ Reading http://code.google.com/p/python-gluttony/ Best match: Gluttony 0.3 Downloading http://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md5=c7774d4fcc0402097f90dc81186de465 Processing Gluttony-0.3.zip Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir /var/folders/Hm/Hmz8Y9rDEXqrbr8IUNiNiU+++TI/-Tmp-/easy_install-zlrBGJ/Gluttony-0.3/egg-dist-tmp-N3AofQ Traceback (most recent call last): File "/usr/bin/easy_install-2.6", line 10, in load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')() File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 1671, in main File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 1659, in with_ei_usage File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 1675, in File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 211, in run File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 446, in easy_install File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 476, in install_item File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 655, in install_eggs File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 930, in build_and_install File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/command/easy_install.py", line 919, in run_setup File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/sandbox.py", line 27, in run_setup File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/sandbox.py", line 63, in run File "/Library/Python/2.6/site-packages/setuptools-0.6c9-py2.6.egg/setuptools/sandbox.py", line 29, in File "setup.py", line 9, in File "/var/folders/Hm/Hmz8Y9rDEXqrbr8IUNiNiU+++TI/-Tmp-/easy_install-zlrBGJ/Gluttony-0.3/gluttony/__init__.py", line 1, in File "/var/folders/Hm/Hmz8Y9rDEXqrbr8IUNiNiU+++TI/-Tmp-/easy_install-zlrBGJ/Gluttony-0.3/gluttony/gluttony.py", line 13, in ImportError: No module named pip.log On Mon, Feb 22, 2010 at 10:02 PM, Hellmut Weber wrote: > Hi Victor, > I would be intereseted to use your tool ;-) > > My system is Sabayon-5.1 on Lenovo T61. > Trying for the first time easy_install I get the following error: > > ==================== > > root at sylvester ~ # easy_install gluttony > Searching for gluttony > Reading http://pypi.python.org/simple/gluttony/ > Reading http://code.google.com/p/python-gluttony/ > Best match: Gluttony 0.3 > > Downloading > http://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md5=c7774d4fcc0402097f90dc81186de465 > Processing Gluttony-0.3.zip > Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD > Traceback (most recent call last): > File "/usr/bin/easy_install", line 9, in > load_entry_point('distribute==0.6.8', 'console_scripts', > 'easy_install')() > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1708, in main > with_ei_usage(lambda: > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1696, in with_ei_usage > return f() > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1712, in > distclass=DistributionWithoutHelpCommands, **kw > File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup > dist.run_commands() > File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands > self.run_command(cmd) > File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command > cmd_obj.run() > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 236, in run > self.easy_install(spec, not self.no_deps) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 471, in easy_install > return self.install_item(spec, dist.location, tmpdir, deps) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 501, in install_item > dists = self.install_eggs(spec, download, tmpdir) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 680, in install_eggs > return self.build_and_install(setup_script, setup_base) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 957, in build_and_install > self.run_setup(setup_script, setup_base, args) > File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 946, in run_setup > run_setup(setup_script, args) > File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 29, > in run_setup > lambda: execfile( > File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 70, > in run > return func() > File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 31, > in > {'__file__':setup_script, '__name__':'__main__'} > File "setup.py", line 9, in > File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", line 1, > in > # > File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", line > 13, in > ImportError: No module named pip.log > root at sylvester ~ # > > ==================== > > I emerged app-misc/pip, but that didn't help, the error remains the same > > What is missing? > > Any help appreciated > > Best regards > > Hellmut > > > Am 19.02.2010 17:16, schrieb Victor Lin: > > Hi, >> >> I just wrote a tool for drawing dependencies relationships diagram of >> Python project on Pypi. Here is the home page of the tool: >> >> http://code.google.com/p/python-gluttony/ >> >> Some examples: >> Sprox: >> http://static.ez2learn.com/gluttony/sprox_dot.png >> >> TurboGears2: >> http://static.ez2learn.com/gluttony/tg2_dot.png >> >> Hope this could be helpful :P >> >> Regards. >> Victor Lin. >> > > -- > Dr. Hellmut Weber mail at hellmutweber.de > Degenfeldstra?e 2 tel +49-89-3081172 > D-80803 M?nchen-Schwabing mobil +49-172-8450321 > please: No DOCs, no PPTs. why: tinyurl.com/cbgq > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Mon Feb 22 11:51:52 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:21:52 +0530 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: Programming is most fruiful in *nix environment. On Mon, Feb 22, 2010 at 9:59 PM, Grant Edwards wrote: > On 2010-02-22, W. eWatson wrote: > > > Last night I copied a program from folder A to folder B. > > [tail of various windows breakages elided] > > > Comments? > > Switch to Linux? > > Or at least install Cygwin? > > -- > Grant Edwards grante Yow! Maybe I should have > at asked for my Neutron Bomb > visi.com in PAISLEY -- > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kiraank at gmail.com Mon Feb 22 11:53:06 2010 From: kiraank at gmail.com (KIRAN) Date: Mon, 22 Feb 2010 08:53:06 -0800 (PST) Subject: Files required for porting python Message-ID: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Hi ALL, I am newbie to python and wanted to port python on to some RTOS. The RTOS I am trying to port python is not posix compliant. First, I decided to port python on to windows and later I will port the same to my target system. [ This is just to minimize the effort being put port, debug and to stabilize]. I downloaded 2.6.1 python code and started looking through the code. I see lot of code with several files. I am not sure which code I should start with. Any help / link regarding this is appreciated. Thanks, Kiran From anand.shashwat at gmail.com Mon Feb 22 11:55:55 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:25:55 +0530 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: OrderedDict is a class in collection module in python 2.7a3+. Perhaps you can use it from there. >>> dir(collections) ['Callable', 'Container', 'Counter', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping', 'MappingView', 'MutableMapping', 'MutableSequence', 'MutableSet', 'OrderedDict', 'Sequence', 'Set', 'Sized', 'ValuesView', '_Link', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_abcoll', '_chain', '_eq', '_heapq', '_ifilter', '_imap', '_iskeyword', '_itemgetter', '_proxy', '_repeat', '_starmap', '_sys', 'defaultdict', 'deque', 'namedtuple'] ~l0nwlf On Mon, Feb 22, 2010 at 10:02 PM, Bryan wrote: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) > > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From anand.shashwat at gmail.com Mon Feb 22 12:00:12 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Mon, 22 Feb 2010 22:30:12 +0530 Subject: Files required for porting python In-Reply-To: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> References: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Message-ID: what do you exactly mean by "port python on to windows" ? Are you talking about your application or python itself :-/ ~l0nwlf On Mon, Feb 22, 2010 at 10:23 PM, KIRAN wrote: > Hi ALL, > > I am newbie to python and wanted to port python on to some RTOS. The > RTOS I am trying to port python is not posix compliant. First, I > decided to port python on to windows and later I will port the same to > my target system. [ This is just to minimize the effort being put > port, debug and to stabilize]. I downloaded 2.6.1 python code and > started looking through the code. I see lot of code with several > files. I am not sure which code I should start with. Any help / link > regarding this is appreciated. > > Thanks, > Kiran > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel at stutzbachenterprises.com Mon Feb 22 12:08:08 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Mon, 22 Feb 2010 11:08:08 -0600 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: On Mon, Feb 22, 2010 at 10:32 AM, Bryan wrote: > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) > > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) > It's not entirely clear what UpdateExistingValue and CreateNewValue do. However, it looks like you are trying to create a dictionary where the keys are sorted. Is that right? If so, you could use the sorteddict type from my blist package, which is similar to an OrderDict except it efficiently keeps the keys in sorted order instead of insertion order. For example: >>> from blist import sorteddict >>> my_dict = sorteddict({1: 'a', 6: 'b', -5: 'c'}) >>> my_dict.keys() [-5, 1, 6] >>> my_dict[2] = 'd' >>> my_dict.keys() [-5, 1, 2, 6] It's available here: http://pypi.python.org/pypi/blist/ -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexanderjquinn at yahoo.com Mon Feb 22 12:10:38 2010 From: alexanderjquinn at yahoo.com (Alex Quinn) Date: Mon, 22 Feb 2010 09:10:38 -0800 (PST) Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? Message-ID: <973565.53691.qm@web38208.mail.mud.yahoo.com> Is there a way to have some kind of database (i.e. sqlite3, bsddb, dbm, etc.) that works out of the box on any Win/Linux/Mac machine with Python 2.6+ or 3.x? It's okay if the file format is different between machines, but I want my script to work without having to install anything. Problems with current modules: * Shelve used to do this. Unfortunately, since bsddb was deprecated/removed from the standard distro and Windows doesn't have dbm or gdbm, the only remaining option on Windows is dumbdbm, which is discouraged in the docs. * Sqlite3 should fill the void now. However, in my experience, nearly every Linux Python install I encounter has a broken sqlite3 module ("ImportError: No module named _sqlite3"). It's a well-documented issue, but it the solution generally requires root access, which I don't have on these servers. Potential solutions: * Could I somehow bundle with my project the _sqlite3.so file and/or whatever else it needs? Or is there an alternate sqlite3 module I could use as a fallback that would just interface with the sqlite3 executable on the machine (i.e. /usr/local/bin/sqlite3)? * Is there a way to drop bsddb into my project so it works out of the gate (no install) on either Linux, Windows, or Mac? If you have any ideas, I'd be most appreciative. My objective here is just to find a portable and reliable solution that I can use for small projects. Thanks, Alex -- http://alexquinn.org From kiraank at gmail.com Mon Feb 22 12:11:12 2010 From: kiraank at gmail.com (Kiran K) Date: Mon, 22 Feb 2010 22:41:12 +0530 Subject: Files required for porting python In-Reply-To: References: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Message-ID: <775a6b621002220911m29664303xda13ce88f04072cb@mail.gmail.com> I will try to provide the API's on windows that my RTOS provides ex. If my RTOS has "fosCreateSemaphore" to create a semaphore I will implement the same API [ same function prototype] on windows using win32 CreateSemaphore. Similarly I will write a wrapper functions for accesing file system, task manegement, memory management. With this abstraction layer, I am simulating my target RTOS on windows [ I am ignoring realtime requirement on windows, I will worry about it once I am done with python porting]. Hope you understand the way I am going. Thanks, Kiran On Mon, Feb 22, 2010 at 10:30 PM, Shashwat Anand wrote: > what do you exactly mean by "port python on to windows" ? Are you talking > about your application or python itself :-/ > > ~l0nwlf > > On Mon, Feb 22, 2010 at 10:23 PM, KIRAN wrote: > >> Hi ALL, >> >> I am newbie to python and wanted to port python on to some RTOS. The >> RTOS I am trying to port python is not posix compliant. First, I >> decided to port python on to windows and later I will port the same to >> my target system. [ This is just to minimize the effort being put >> port, debug and to stabilize]. I downloaded 2.6.1 python code and >> started looking through the code. I see lot of code with several >> files. I am not sure which code I should start with. Any help / link >> regarding this is appreciated. >> >> Thanks, >> Kiran >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Mon Feb 22 12:17:14 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 22 Feb 2010 18:17:14 +0100 Subject: Reading a large bz2 textfile exits early In-Reply-To: <4b8286ec$1@dnews.tpgi.com.au> References: <2NydneNvv9CPPBzWnZ2dnUVZ_jAAAAAA@earthlink.com> <4b8286ec$1@dnews.tpgi.com.au> Message-ID: Lie Ryan, 22.02.2010 14:29: > On 02/22/10 19:43, Norman Rie? wrote: >> Am 02/22/10 09:02, schrieb Steven D'Aprano: >>> On Mon, 22 Feb 2010 07:49:51 +0100, Norman Rie? wrote: >>> >>> >>>> This is the actual code: >>>> >>>> source_file = bz2.BZ2File(file, "r") >>>> for line in source_file: >>>> print line.strip() >>>> >>>> print "Exiting" >>>> print "I used file: " + file >>>> >>> Have you verified that the bz file is good by opening it in another >>> application? >>> >>> >>> >>> >> Yes, bzcat is running through the file fine. And piping bzcat output >> into the python script reading stdin works fine, too. > > test with using something other than bzcat; bzcat does certain things > differently because of the way it works (a cat for bzipped file). Try > using plain "bunzip2 filename.bz2" Please note that all of this has already been suggested on the python-tutor list. Stefan From python at mrabarnett.plus.com Mon Feb 22 12:19:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 17:19:14 +0000 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: <4B82BC92.8070304@mrabarnett.plus.com> Bryan wrote: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > Why are you building a dict from a list and then an ordered dict from that? Just build the ordered dict from the list, because it's behaves like a dict, except for remembering the order in which the keys were added. From barryjogorman at gmail.com Mon Feb 22 12:26:18 2010 From: barryjogorman at gmail.com (barryjogorman) Date: Mon, 22 Feb 2010 09:26:18 -0800 (PST) Subject: Starting with Classes - basic problem Message-ID: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> HAVE THE FOLLOWING VERY BASIC PROGRAM: class Person: def _init_(self,name, job=None, pay=0): self.name=name self.job=job self.pay=pay bob = Person('Bob Smith') sue = Person('Sue Jones', job='dev', pay = 100000) print(bob.name, bob.pay) print(sue.name, sue.pay) I am getting the following error message: Traceback (most recent call last): File "C:/Python31/person1.py", line 7, in bob = Person('Bob Smith') TypeError: object.__new__() takes no parameters All suggestions gratefully received. From bryanvick at gmail.com Mon Feb 22 12:28:22 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 09:28:22 -0800 (PST) Subject: Efficiently building ordered dict References: Message-ID: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> On Feb 22, 9:19?am, MRAB wrote: > Bryan wrote: > > I am looping through a list and creating a regular dictionary. ?From > > that dict, I create an ordered dict. ?I can't think of a way to build > > the ordered dict while going through the original loop. ?Is there a > > way I can avoid creating the first unordered dict just to get the > > ordered dict? ?Also, I am using pop(k) to retrieve the values from the > > unordered dict while building the ordered one because I figure that as > > the values are removed from the unordered dict, the lookups will > > become faster. ?Is there a better idiom that the code below to create > > an ordered dict from an unordered list? > > Why are you building a dict from a list and then an ordered dict from > that? Just build the ordered dict from the list, because it's behaves > like a dict, except for remembering the order in which the keys were > added. Could you write some pseudo-code for that? I'm not sure how I would add the items to the OrderedDict while looping through the list. Wouldn't the list need to be sorted first (which in this case isn't practical)? From editor at pythonrag.org Mon Feb 22 12:33:55 2010 From: editor at pythonrag.org (Bernard Czenkusz) Date: Mon, 22 Feb 2010 11:33:55 -0600 Subject: Starting with Classes - basic problem References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: On Mon, 22 Feb 2010 09:26:18 -0800, barryjogorman wrote: > HAVE THE FOLLOWING VERY BASIC PROGRAM: > > class Person: > def _init_(self,name, job=None, pay=0): > self.name=name > self.job=job > self.pay=pay > > bob = Person('Bob Smith') > sue = Person('Sue Jones', job='dev', pay = 100000) print(bob.name, > bob.pay) > print(sue.name, sue.pay) > > I am getting the following error message: > > Traceback (most recent call last): > File "C:/Python31/person1.py", line 7, in > bob = Person('Bob Smith') > TypeError: object.__new__() takes no parameters > > > > All suggestions gratefully received. The __init__ method starts and ends with two underscores, not one underscore _init_ as you have used. From agoretoy at gmail.com Mon Feb 22 12:43:03 2010 From: agoretoy at gmail.com (alex goretoy) Date: Mon, 22 Feb 2010 11:43:03 -0600 Subject: Starting with Classes - basic problem In-Reply-To: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: you need to define init with two underscores, I've made that mistake myself long long time ago :) def __init__ not def _init_ -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Mon Feb 22 12:45:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 17:45:04 +0000 (UTC) Subject: How to measure elapsed time under Windows? References: <87404349-5d3a-4396-aeff-60edc14a506a@f8g2000yqn.googlegroups.com> Message-ID: On 2010-02-22, Albert van der Horst wrote: > In article <87404349-5d3a-4396-aeff-60edc14a506a at f8g2000yqn.googlegroups.com>, >>Gabriel Genellina reports that time.clock() uses Windows' >>QueryPerformanceCounter() API, which has much higher resolution >>than the task switcher's 15ms. QueryPerformanceCounter's >>resolution is hardware-dependent; using the Win API, and a >>little test program, I get this value on my machine: Frequency >>is 3579545 ticks/sec Resolution is 0.279365114840015 >>microsecond/tick > > In Forth we add a small machine code routine that executes the > RDTSC instruction. (I used that to play music on a couple of > mechanical instruments in real time.) It just counts the (3 > Ghz) clock cycles in a 64 bit timer. That's what clock.clock() does, except that it converts it into a floating point value in seconds. > Subtract two samples and you're done. Nope. It would fail the same way that clock.clock() does on a multi-core Windows machine. > Is there a mechanism in Python to do something similar, > embedded assembler or something? You'd get the same results as using clock.clock(). Just different format/units. > (This is not a general solution, but at least it would work on > Windows, that is i86 only.) It fails on Windows for the same reason that clock.clock() fails: the counters read by the RDTSC instruction are not synchronized between the different cores. -- Grant Edwards grante Yow! I'm a nuclear at submarine under the visi.com polar ice cap and I need a Kleenex! From python at mrabarnett.plus.com Mon Feb 22 12:45:50 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 17:45:50 +0000 Subject: Starting with Classes - basic problem In-Reply-To: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: <4B82C2CE.4050008@mrabarnett.plus.com> barryjogorman wrote: > HAVE THE FOLLOWING VERY BASIC PROGRAM: > > class Person: > def _init_(self,name, job=None, pay=0): > self.name=name > self.job=job > self.pay=pay > > bob = Person('Bob Smith') > sue = Person('Sue Jones', job='dev', pay = 100000) > print(bob.name, bob.pay) > print(sue.name, sue.pay) > > I am getting the following error message: > > Traceback (most recent call last): > File "C:/Python31/person1.py", line 7, in > bob = Person('Bob Smith') > TypeError: object.__new__() takes no parameters > > > > All suggestions gratefully received. > The special methods use double underscores, not single underscores, eg __init__ not _init_. From barryjogorman at gmail.com Mon Feb 22 12:46:52 2010 From: barryjogorman at gmail.com (barryjogorman) Date: Mon, 22 Feb 2010 09:46:52 -0800 (PST) Subject: Starting with Classes - basic problem References: <64a57269-c7b8-4ce1-b2a6-1d5095afe74d@u9g2000yqb.googlegroups.com> Message-ID: <0a181737-9c67-45ae-bcf8-22d3e4690cf6@u20g2000yqu.googlegroups.com> On Feb 22, 5:33?pm, Bernard Czenkusz wrote: > On Mon, 22 Feb 2010 09:26:18 -0800, barryjogorman wrote: > >HAVE THE FOLLOWING VERY BASIC PROGRAM: > > >class Person: > > ? ?def _init_(self,name, job=None, pay=0): > > ? ? ? ?self.name=name > > ? ? ? ?self.job=job > > ? ? ? ?self.pay=pay > > >bob = Person('Bob Smith') > >sue = Person('Sue Jones', job='dev', pay = 100000) print(bob.name, > >bob.pay) > >print(sue.name, sue.pay) > > >I am getting the following error message: > > >Traceback (most recent call last): > > ?File "C:/Python31/person1.py", line 7, in > > ? ?bob = Person('Bob Smith') > >TypeError: object.__new__() takes no parameters > > >All suggestions gratefully received. > > The __init__ method starts and ends with two underscores,not one underscore _init_ as you have used. thanks From albert at spenarnc.xs4all.nl Mon Feb 22 12:52:48 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Feb 2010 17:52:48 GMT Subject: How to measure elapsed time under Windows? References: <87404349-5d3a-4396-aeff-60edc14a506a@f8g2000yqn.googlegroups.com> Message-ID: In article <87404349-5d3a-4396-aeff-60edc14a506a at f8g2000yqn.googlegroups.com>, Paul McGuire wrote: >On Feb 10, 2:24=A0am, Dennis Lee Bieber wrote: >> On Tue, 9 Feb 2010 21:45:38 +0000 (UTC), Grant Edwards >> declaimed the following in >> gmane.comp.python.general: >> >> > Doesn't work. =A0datetime.datetime.now has granularity of >> > 15-16ms. >> >> > Intervals much less that that often come back with a delta of >> > 0. =A0A delay of 20ms produces a delta of either 15-16ms or >> > 31-32ms >> >> =A0 =A0 =A0 =A0 WinXP uses an ~15ms time quantum for task switching. Whic= >h defines >> the step rate of the wall clock output... >> >> http://www.eggheadcafe.com/software/aspnet/35546579/the-quantum-was-n...h= >ttp://www.eggheadcafe.com/software/aspnet/32823760/how-do-you-set-ti... >> >> http://www.lochan.org/2005/keith-cl/useful/win32time.html >> -- >> =A0 =A0 =A0 =A0 Wulfraed =A0 =A0 =A0 =A0 Dennis Lee Bieber =A0 =A0 =A0 = >=A0 =A0 =A0 =A0 KD6MOG >> =A0 =A0 =A0 =A0 wlfr... at ix.netcom.com =A0 =A0 HTTP://wlfraed.home.netcom.= >com/ > >Gabriel Genellina reports that time.clock() uses Windows' >QueryPerformanceCounter() API, which has much higher resolution than >the task switcher's 15ms. QueryPerformanceCounter's resolution is >hardware-dependent; using the Win API, and a little test program, I >get this value on my machine: >Frequency is 3579545 ticks/sec >Resolution is 0.279365114840015 microsecond/tick In Forth we add a small machine code routine that executes the RDTSC instruction. (I used that to play music on a couple of mechanical instruments in real time.) It just counts the (3 Ghz) clock cycles in a 64 bit timer. Subtract two samples and you're done. Is there a mechanism in Python to do something similar, embedded assembler or something? (This is not a general solution, but at least it would work on Windows, that is i86 only.) > >-- Paul -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From albert at spenarnc.xs4all.nl Mon Feb 22 13:01:44 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 22 Feb 2010 18:01:44 GMT Subject: Bizarre arithmetic results References: Message-ID: In article , Terrence Cole wrote: >Can someone explain to me what python is doing here? > >Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) >[GCC 4.3.4] on linux2 >Type "help", "copyright", "credits" or "license" for more information. >>>> -0.1 ** 0.1 Python 4.0 Warning: misleading blank space, expected: - 0.1**0.1 >-0.7943282347242815 >>>> a = -0.1; b = 0.1 >>>> a ** b >(0.7554510437117542+0.2454609236416552j) >>>> -abs(a ** b) >-0.7943282347242815 > >Why does the literal version return the signed magnitude and the >variable version return a complex? > >Cheers, >Terrence > -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From python at mrabarnett.plus.com Mon Feb 22 13:04:20 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 18:04:20 +0000 Subject: Efficiently building ordered dict In-Reply-To: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> References: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> Message-ID: <4B82C724.7030202@mrabarnett.plus.com> Bryan wrote: > On Feb 22, 9:19 am, MRAB wrote: >> Bryan wrote: >>> I am looping through a list and creating a regular dictionary. From >>> that dict, I create an ordered dict. I can't think of a way to build >>> the ordered dict while going through the original loop. Is there a >>> way I can avoid creating the first unordered dict just to get the >>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>> unordered dict while building the ordered one because I figure that as >>> the values are removed from the unordered dict, the lookups will >>> become faster. Is there a better idiom that the code below to create >>> an ordered dict from an unordered list? >> Why are you building a dict from a list and then an ordered dict from >> that? Just build the ordered dict from the list, because it's behaves >> like a dict, except for remembering the order in which the keys were >> added. > > Could you write some pseudo-code for that? I'm not sure how I would > add the items to the OrderedDict while looping through the list. > Wouldn't the list need to be sorted first (which in this case isn't > practical)? > ordered != sorted. If you want the ordered dict to be sorted by key then build a dict first and then create the ordered dict from the sorted dict. I think the quickest way to build the sorted dict is: orderedDict = OrderedDict(sorted(unorderedDict.items())) although I haven't tried 'sorteddict' (see Daniel Stutzbach's post). From arnodel at googlemail.com Mon Feb 22 13:09:31 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 22 Feb 2010 18:09:31 +0000 Subject: Efficiently building ordered dict References: Message-ID: Bryan writes: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) > > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) Why don't you sort your unorderedList first then simply create your orderedDict? To me your problem is stated in too vague terms anyway and the code you post could not really work as unorderedDict is bound to remain empty whatever the values of all the other names. At any rate, why do you need an ordered dictionary? It seems suspect to me as you sort the keys before inserting the items. -- Arnaud From breamoreboy at yahoo.co.uk Mon Feb 22 13:15:38 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 22 Feb 2010 18:15:38 +0000 Subject: Efficiently building ordered dict In-Reply-To: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> References: <90510ec9-27ea-48c2-b9d9-2903b7aba6e3@q16g2000yqq.googlegroups.com> Message-ID: Bryan wrote: > On Feb 22, 9:19 am, MRAB wrote: >> Bryan wrote: >>> I am looping through a list and creating a regular dictionary. From >>> that dict, I create an ordered dict. I can't think of a way to build >>> the ordered dict while going through the original loop. Is there a >>> way I can avoid creating the first unordered dict just to get the >>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>> unordered dict while building the ordered one because I figure that as >>> the values are removed from the unordered dict, the lookups will >>> become faster. Is there a better idiom that the code below to create >>> an ordered dict from an unordered list? >> Why are you building a dict from a list and then an ordered dict from >> that? Just build the ordered dict from the list, because it's behaves >> like a dict, except for remembering the order in which the keys were >> added. > > Could you write some pseudo-code for that? I'm not sure how I would > add the items to the OrderedDict while looping through the list. > Wouldn't the list need to be sorted first (which in this case isn't > practical)? > > > Could you please clarify what you are trying to achieve as you appear to be confusing ordering with sorting. Mark Lawrence. From wolftracks at invalid.com Mon Feb 22 13:30:31 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 10:30:31 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: On 2/22/2010 8:29 AM, Grant Edwards wrote: > On 2010-02-22, W. eWatson wrote: > >> Last night I copied a program from folder A to folder B. > > [tail of various windows breakages elided] > >> Comments? > > Switch to Linux? > > Or at least install Cygwin? > Yes, definitely not related, but maybe some W7 user has a similar experience here. It seems a natural place to look, since it should be reasonably common. I have Cygwin. From sridharr at activestate.com Mon Feb 22 13:53:31 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 22 Feb 2010 10:53:31 -0800 Subject: Python won't run In-Reply-To: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> References: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> Message-ID: <46D34AB9-9DC7-47E9-8288-2B5DFDB55BB8@activestate.com> Have you tried using http://dependencywalker.com/ ? -srid On 2010-02-18, at 1:00 PM, Nardin, Cory L. wrote: > Quickly, I have a Mac Intel with Windows XP installed. Tried installing Python 2.6.4 from the binary and also ActivePython 2.6.4.10. Both installations acted the same. There seemed to be no problems during installation (used default options), but when I try to run Python I get an error message: ?This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.? > > Of course I searched on that error and it seems to be related to a MS library. In a few different places it was recommended to install the MS Visual Studio redistributable package, which I did with no change in outcome. I really have no idea what to do. > > Any help is appreciated. > > Thanks, > Cory > -- > http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Mon Feb 22 13:57:56 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 22 Feb 2010 19:57:56 +0100 Subject: Efficiently building ordered dict In-Reply-To: References: Message-ID: * Bryan: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the > ordered dict? Also, I am using pop(k) to retrieve the values from the > unordered dict while building the ordered one because I figure that as > the values are removed from the unordered dict, the lookups will > become faster. Is there a better idiom that the code below to create > an ordered dict from an unordered list? > > unorderedDict = {} > for thing in unorderedList: > if thing.id in unorderedDict: > UpdateExistingValue(unorderedDict[thing.id]) > else: > CreateNewValue(unorderedDict[thing.id]) If this were real code the last statement would generate an exception. > orderedDict = OrderedDict() > for k in sorted(unorderedDict.keys()): > orderedDict[k] unorderedDict.pop(k) This is not even valid syntax. Please (1) explain the problem that you're trying to solve, not how you imagine the solution, and (2) if you have any code, please post real code (copy and paste). The above code is not real. Cheers & hth., - Alf From hansmu at xs4all.nl Mon Feb 22 14:32:45 2010 From: hansmu at xs4all.nl (Hans Mulder) Date: Mon, 22 Feb 2010 20:32:45 +0100 Subject: formatting a number as percentage In-Reply-To: References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: <4b82dc5a$0$22916$e4fe514c@news.xs4all.nl> G?nther Dietrich wrote: > vsoler wrote: > >> I'm trying to print .7 as 70% >> I've tried: >> >> print format(.7,'%%') >> .7.format('%%') >> >> but neither works. I don't know what the syntax is... > > Did you try this: > >>>> print('%d%%' % (0.7 * 100)) > 70% That method will always round down; TomF's method will round to the nearest whole number: >>> print "%d%%" % (0.698 * 100) 69% >>> print "{0:.0%}".format(.698) 70% Only the OP knows which one is more appropriate for his use case. Hope this helps, -- HansM From jgardner at jonathangardner.net Mon Feb 22 14:41:45 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 11:41:45 -0800 Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? In-Reply-To: <973565.53691.qm@web38208.mail.mud.yahoo.com> References: <973565.53691.qm@web38208.mail.mud.yahoo.com> Message-ID: <6cc20cea1002221141u534fd5f7v8748f50f9094011f@mail.gmail.com> On Mon, Feb 22, 2010 at 9:10 AM, Alex Quinn wrote: > > * Sqlite3 should fill the void now. ?However, in my experience, nearly every Linux Python install I encounter has a broken sqlite3 module ("ImportError: No module named _sqlite3"). It's a well-documented issue, but it the solution generally requires root access, which I don't have on these servers. > If your program is installed in the same way everything else is installed on the system (RPM or deb packages, or whatever), there should be dependencies clearly listed. When the admin installs your code, he must also install the requisite modules that you list as dependencies. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Mon Feb 22 14:45:10 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 11:45:10 -0800 Subject: Use eval() safely? In-Reply-To: <20100221212511.GA23046@beron.tangosoft.com> References: <20100221212511.GA23046@beron.tangosoft.com> Message-ID: <6cc20cea1002221145o2527b03ds74a473d59bd079@mail.gmail.com> On Sun, Feb 21, 2010 at 1:25 PM, W. Martin Borgert wrote: > > I know that this issue has been discussed before, but most of > the time using only one argument to eval(). > > Is it possible to use the following code, e.g. run as part of a > web application, to break in and if so, how? > > import math > > def myeval(untrustedinput): > ? ?return eval(untrustedinput, {"__builtins__": None}, > ? ? ? ? ? ? ? ?{ "abs": abs, "sin": math.sin }) > > Is it possible to define functions or import modules from the > untrusted input string? > > Which Python built-ins and math functions would I have to add to > the functions dictionary to make it unsafe? > Why would you ever run untrusted code on any machine in any language, let alone Python? If you're writing a web app, make it so that you only run trusted code. That is, code installed by the admin, or approved by the admin. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Mon Feb 22 15:00:19 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 12:00:19 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <87mxz2v47t.fsf@castleamber.com> References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> Message-ID: <6cc20cea1002221200g467f229cm4710db0d70d21105@mail.gmail.com> On Sun, Feb 21, 2010 at 10:22 AM, John Bokma wrote: > Jonathan Gardner writes: >> On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: >>> >>> Now, why don't we start a PEP to make python a fully-functional language >>> then? >> >> Because people don't think the same way that programs are written in >> functional languages. > > Heh! When I learned Miranda it felt natural to me. Prolog on the other > hand... > > In short: I am afraid you're overgeneralizing here; it depends on one's > background. If not, citation needed ;-) > Unfortunately, this is something that is hardly measurable. Short of a survey (of whom? of what?), there can be no objective evaluation. To date, I don't know of any such studies or surveys. I won't deny that really smart people enjoy the challenge of programming in a functional style, and some even find it easier to work with. However, when it comes to readability and maintenance, I appreciate the statement-based programming style, simply because it's easier for me to understand an debug. -- Jonathan Gardner jgardner at jonathangardner.net From no.email at nospam.invalid Mon Feb 22 15:07:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 12:07:30 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> Message-ID: <7xsk8tuj99.fsf@ruckus.brouhaha.com> Jonathan Gardner writes: > I won't deny that really smart people enjoy the challenge of > programming in a functional style, and some even find it easier to > work with. However, when it comes to readability and maintenance, I > appreciate the statement-based programming style, simply because it's > easier for me to understand an debug. One thing those people are after is programs that work properly the first time they are run, and thus don't need debugging. They achieve that a surprising amount of the time. From g.bogle at auckland.no.spam.ac.nz Mon Feb 22 15:16:26 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 23 Feb 2010 09:16:26 +1300 Subject: What's Going on between Python and win7? References: Message-ID: MRAB wrote: > W. eWatson wrote: >> Last night I copied a program from folder A to folder B. It inspects >> the contents of files in a folder. When I ran it in B, it gave the >> results for A! Out of frustration I changed the name in A, and fired >> up the program in B. Win7 went into search mode for the file. I looked >> at properties for the B program, and it was clearly pointing to folder A. >> > Sounds like you didn't copy it but made a shortcut to it instead. Windows 7 has symbolic links? From ra21vi at gmail.com Mon Feb 22 15:19:15 2010 From: ra21vi at gmail.com (Ravi Kumar) Date: Mon, 22 Feb 2010 20:19:15 +0000 Subject: GUI app on Windows for WMI digging Message-ID: <9a63e8921002221219p38c03de2mfbf74a7301cbc6dd@mail.gmail.com> Hi, I am working on an application, which retrieves Windows system info (Hardware / Software / Drivers / OS) and write to an xml. For the GUI, I selected PyQT4, and for system info using WMI, I am using WMI Package (http://timgolden.me.uk/python/wmi/index.html) and popular pywin32. To package the binary, I am considering py2exe. I need to package these in binary package (though single binary output was preferred, but could not find any examples online to achieve this). Also, I took PyQT4, but I can switch to PyGTK if it is possible to get it in single DLL/libs. Overall, I need suggestions on: - which XML library is better/lightweight on Windows?I think pure python based xml processing libs would work (so lxml is out of option). - Can I get these in single binary (not installer), or if not, then how can I get in minimum files. Py2exe results many files. - Is QT4 better or GTK? No war/flaming over this, since least widgets are needed, which are available on both. Since the GUI is just 3-4 screens/dialogs with minimum widgets, so speed does not matter. The only thing that matter is least files/libs (no seperate installation, file can provided with binary package). -- -=Ravi=- -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Feb 22 15:31:18 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Feb 2010 14:31:18 -0600 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> Message-ID: <87iq9pt3l5.fsf@castleamber.com> Jonathan Gardner writes: > On Sun, Feb 21, 2010 at 10:22 AM, John Bokma wrote: >> Jonathan Gardner writes: >>> On Fri, Feb 19, 2010 at 11:16 PM, Lie Ryan wrote: >>>> >>>> Now, why don't we start a PEP to make python a fully-functional language >>>> then? >>> >>> Because people don't think the same way that programs are written in >>> functional languages. >> >> Heh! When I learned Miranda it felt natural to me. Prolog on the other >> hand... >> >> In short: I am afraid you're overgeneralizing here; it depends on one's >> background. If not, citation needed ;-) >> > > Unfortunately, this is something that is hardly measurable. Short of a > survey (of whom? of what?), there can be no objective evaluation. To > date, I don't know of any such studies or surveys. > > I won't deny that really smart people enjoy the challenge of > programming in a functional style, and some even find it easier to > work with. However, when it comes to readability and maintenance, I > appreciate the statement-based programming style, simply because it's > easier for me to understand an debug. In my class there where basically 2 groups of people: the ones who got functional programming and the ones who had a hard time with it. The latter group consisted mostly of people who had been programming in languages like C and Pascal for years; they had a hard time thinking functionally. The former group consisted mostly of people who had little or no programming experience, with a few exceptions (including me :-) ). So I have the feeling it has more to do with your background then how people think / are wired. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Mon Feb 22 15:33:43 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Feb 2010 14:33:43 -0600 Subject: What's Going on between Python and win7? References: Message-ID: <87d3zxt3h4.fsf@castleamber.com> Gib Bogle writes: > MRAB wrote: >> W. eWatson wrote: >>> Last night I copied a program from folder A to folder B. It >>> inspects the contents of files in a folder. When I ran it in B, it >>> gave the results for A! Out of frustration I changed the name in A, >>> and fired up the program in B. Win7 went into search mode for the >>> file. I looked at properties for the B program, and it was clearly >>> pointing to folder A. >>> >> Sounds like you didn't copy it but made a shortcut to it instead. > > Windows 7 has symbolic links? Symbolic links are designed to aid in migration and application compatibility with UNIX operating systems. Microsoft has implemented its symbolic links to function just like UNIX links. : Symbolic links are available in NTFS starting with Windows Vista. http://msdn.microsoft.com/en-us/library/aa365680(VS.85).aspx -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From icanbob at gmail.com Mon Feb 22 15:37:10 2010 From: icanbob at gmail.com (bobicanprogram) Date: Mon, 22 Feb 2010 12:37:10 -0800 (PST) Subject: ANN: Python-SIMPL v2.0.0 released References: <964d1dcb-46a9-40a5-ab41-199fd1e364a7@t21g2000vbo.googlegroups.com> Message-ID: <40dd1bcc-4791-463d-a730-d8e3c52ff2a2@f8g2000vba.googlegroups.com> On Feb 22, 9:40 am, bobicanprogram wrote: > The SIMPL project (http://www.icanprogram.com/simpl) aims to bring the > Send/Receive/Reply messaging (first popularized by QNX) to the open > source Linux world. Since its inception more that 10 years ago, the > SIMPL toolkit has grown steadily in functionality. Through the use > of surrogates, SIMPL modules can be dispersed seamlessly across > networks including heterogeneous networks with only one Linux node. > SIMPL modules can also be written in several programming languages > including Python, C, C++, JAVA and Tcl/Tk. Modules written in > different languages can be mixed in a SIMPL appliction. > > Python-SIMPL has been used to connect Python UIs to C data acquisition/ > computation backends. While this is an example of a common use for > the toolkit, it is by no means the only place it could be useful. > Python to Python, Python to JAVA as well as Python to C are all > seamlessly possible in both local or distributed applications. Python- > SIMPL allows a software application to be broken up into modules where > the language choices for each module can be optimized. > > The Python-SIMPL interface library has undergone a fundamental > revision with the v2.0.0 release. The underlying shared library which > wraps the SIMPL toolkit as a Python extension was cleaned up > considerably. In addition two new Python wrappers were created to > expose this SIMPL toolkit in more object oriented fashion to the > Python developer. > > The simplest starting point for exploring the Python-SIMPL toolkit is > an online "hello world" level tutorial at: > > http://www.icanprogram.com/06py/lesson1/lesson1.html > > The Python-SIMPL toolkit can be downloaded in source form at: > > http://www.icanprogram.com/simpl/python.self.htm > > or in precompiled binary (i386) form at: > > http://www.icanprogram.com/simpl/pythonbin.self.html > > We at the SIMPL project welcome participants at all levels of > expertise. If you are interested do not hesitate to contact us. > > bob There is a typo in the source link. It should read http://www.icanprogram.com/simpl/python.self.html Sorry about that. bob From invalid at invalid.invalid Mon Feb 22 16:19:32 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 21:19:32 +0000 (UTC) Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On 2010-02-22, John Bokma wrote: > Gib Bogle writes: > >> MRAB wrote: >>> W. eWatson wrote: >>>> Last night I copied a program from folder A to folder B. It >>>> inspects the contents of files in a folder. When I ran it in B, it >>>> gave the results for A! Out of frustration I changed the name in A, >>>> and fired up the program in B. Win7 went into search mode for the >>>> file. I looked at properties for the B program, and it was clearly >>>> pointing to folder A. >>>> >>> Sounds like you didn't copy it but made a shortcut to it instead. >> >> Windows 7 has symbolic links? > > Symbolic links are designed to aid in migration and application > compatibility with UNIX operating systems. Microsoft has implemented > its symbolic links to function just like UNIX links. So symbolic links on W7 function like Unix (hard) links rather than Unix _symbolic_ links?? -- Grant Edwards grante Yow! Is this sexual at intercourse yet?? Is it, visi.com huh, is it?? From bryanvick at gmail.com Mon Feb 22 16:29:26 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 13:29:26 -0800 (PST) Subject: Efficiently building ordered dict References: Message-ID: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> On Feb 22, 10:57?am, "Alf P. Steinbach" wrote: > * Bryan: > > > > > I am looping through a list and creating a regular dictionary. ?From > > that dict, I create an ordered dict. ?I can't think of a way to build > > the ordered dict while going through the original loop. ?Is there a > > way I can avoid creating the first unordered dict just to get the > > ordered dict? ?Also, I am using pop(k) to retrieve the values from the > > unordered dict while building the ordered one because I figure that as > > the values are removed from the unordered dict, the lookups will > > become faster. ?Is there a better idiom that the code below to create > > an ordered dict from an unordered list? > > > unorderedDict = {} > > for thing in unorderedList: > > ? ?if thing.id in unorderedDict: > > ? ? ? ? ? ?UpdateExistingValue(unorderedDict[thing.id]) > > ? ?else: > > ? ? ? ? ? ?CreateNewValue(unorderedDict[thing.id]) > > If this were real code the last statement would generate an exception. > > > orderedDict = OrderedDict() > > for k in sorted(unorderedDict.keys()): > > ? ?orderedDict[k] ?unorderedDict.pop(k) > > This is not even valid syntax. > > Please > > ? ?(1) explain the problem that you're trying to solve, not how you > ? ? ? ?imagine the solution, and > > ? ?(2) if you have any code, please post real code (copy and paste). > > The above code is not real. > > Cheers & hth., > > - Alf Sorry about the sorted != ordered mix up. I want to end up with a *sorted* dict from an unordered list. *Sorting the list is not practical in this case.* I am using python 2.5, with an ActiveState recipe for an OrderedDict. Given these requirements/limitations, how would you do it? My solution is to create a regular dict from the list. Then sort the keys, and add the keys+values to an OrderedDict. Since the keys are being added to the OrderedDict in the correctly sorted order, at the end I end up with a OrderedDict that is in the correctly *sorted* order. self.accTotals = {} for row in self.rows: if row.acc.code in self.accTotals: self.accTotals[row.acc.code].addRow(row) else: accSummary = Total() accSummary.addRow(row) self.accTotals[row.acc.code] = accSummary self.accTotals = self._getOrderedDict(self.accTotals) From aonlazio at gmail.com Mon Feb 22 16:56:02 2010 From: aonlazio at gmail.com (AON LAZIO) Date: Mon, 22 Feb 2010 16:56:02 -0500 Subject: When will Python go mainstream like Java? Message-ID: That will be superb -- Passion is my style -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Mon Feb 22 17:02:47 2010 From: john at castleamber.com (John Bokma) Date: Mon, 22 Feb 2010 16:02:47 -0600 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <873a0tszco.fsf@castleamber.com> Grant Edwards writes: > On 2010-02-22, John Bokma wrote: >> Gib Bogle writes: >> >>> MRAB wrote: >>>> W. eWatson wrote: >>>>> Last night I copied a program from folder A to folder B. It >>>>> inspects the contents of files in a folder. When I ran it in B, it >>>>> gave the results for A! Out of frustration I changed the name in A, >>>>> and fired up the program in B. Win7 went into search mode for the >>>>> file. I looked at properties for the B program, and it was clearly >>>>> pointing to folder A. >>>>> >>>> Sounds like you didn't copy it but made a shortcut to it instead. >>> >>> Windows 7 has symbolic links? >> >> Symbolic links are designed to aid in migration and application >> compatibility with UNIX operating systems. Microsoft has implemented >> its symbolic links to function just like UNIX links. > > So symbolic links on W7 function like Unix (hard) links > rather than Unix _symbolic_ links?? Which leads you to this conclusion? According to http://msdn.microsoft.com/en-us/library/aa365006(VS.85).aspx There are three types of file links supported in the NTFS file system: hard links, junctions, and symbolic links. This topic is an overview of hard links and junctions. For information about symbolic links, see Creating Symbolic Links. Creating Symbolic Links: http://msdn.microsoft.com/en-us/library/aa363878(VS.85).aspx -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From arnodel at googlemail.com Mon Feb 22 17:10:47 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Mon, 22 Feb 2010 14:10:47 -0800 (PST) Subject: Efficiently building ordered dict References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> Message-ID: On 22 Feb, 21:29, Bryan wrote: > Sorry about the sorted != ordered mix up. ?I want to end up with a > *sorted* dict from an unordered list. ?*Sorting the list is not > practical in this case.* ?I am using python 2.5, with an ActiveState > recipe for an OrderedDict. Why does the dict need to be sorted? Why is it impractical to sort the list, but practical to sort the dict? Whithout knowing this, it is difficult to get an idea of your problem an a potential solution. > My solution is to create a regular dict from the list. ?Then sort the > keys, and add the keys+values to an OrderedDict. ?Since the keys are > being added to the OrderedDict in the correctly sorted order, at the > end I end up with a OrderedDict that is in the correctly *sorted* > order. > > self.accTotals = {} > for row in self.rows: > ? ? ? ? if row.acc.code in self.accTotals: > ? ? ? ? ? ? ? ? self.accTotals[row.acc.code].addRow(row) > ? ? ? ? else: > ? ? ? ? ? ? ? ? accSummary = Total() > ? ? ? ? ? ? ? ? accSummary.addRow(row) > ? ? ? ? ? ? ? ? self.accTotals[row.acc.code] = accSummary > self.accTotals = self._getOrderedDict(self.accTotals) This code is a typical example where defaultdict, which was added in Python 2.5 [1], would be of use: accTotals = defaultdict(Total) for row in self.rows: accTotals[row.acc.code].addRow(row) self.accTotals = self._getOrderedDict(accTotals) However, as you don't explain what self._getOrderedDict(...) does, it is quite difficult to guess how to improve it! [1] http://docs.python.org/library/collections.html#collections.defaultdict -- Arnaud From g.bogle at auckland.no.spam.ac.nz Mon Feb 22 17:10:54 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 23 Feb 2010 11:10:54 +1300 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: John Bokma wrote: > Gib Bogle writes: > >> MRAB wrote: >>> W. eWatson wrote: >>>> Last night I copied a program from folder A to folder B. It >>>> inspects the contents of files in a folder. When I ran it in B, it >>>> gave the results for A! Out of frustration I changed the name in A, >>>> and fired up the program in B. Win7 went into search mode for the >>>> file. I looked at properties for the B program, and it was clearly >>>> pointing to folder A. >>>> >>> Sounds like you didn't copy it but made a shortcut to it instead. >> Windows 7 has symbolic links? > > Symbolic links are designed to aid in migration and application > compatibility with UNIX operating systems. Microsoft has implemented > its symbolic links to function just like UNIX links. > > : > > Symbolic links are available in NTFS starting with Windows Vista. > > http://msdn.microsoft.com/en-us/library/aa365680(VS.85).aspx > That explains my ignorance of this (excellent) development. I'm still using W2K and XP. From deets at nospam.web.de Mon Feb 22 17:16:07 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Mon, 22 Feb 2010 23:16:07 +0100 Subject: Efficiently building ordered dict In-Reply-To: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> Message-ID: <7uge18Fta5U1@mid.uni-berlin.de> Am 22.02.10 22:29, schrieb Bryan: > On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: >> * Bryan: >> >> >> >>> I am looping through a list and creating a regular dictionary. From >>> that dict, I create an ordered dict. I can't think of a way to build >>> the ordered dict while going through the original loop. Is there a >>> way I can avoid creating the first unordered dict just to get the >>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>> unordered dict while building the ordered one because I figure that as >>> the values are removed from the unordered dict, the lookups will >>> become faster. Is there a better idiom that the code below to create >>> an ordered dict from an unordered list? >> >>> unorderedDict = {} >>> for thing in unorderedList: >>> if thing.id in unorderedDict: >>> UpdateExistingValue(unorderedDict[thing.id]) >>> else: >>> CreateNewValue(unorderedDict[thing.id]) >> >> If this were real code the last statement would generate an exception. >> >>> orderedDict = OrderedDict() >>> for k in sorted(unorderedDict.keys()): >>> orderedDict[k] unorderedDict.pop(k) >> >> This is not even valid syntax. >> >> Please >> >> (1) explain the problem that you're trying to solve, not how you >> imagine the solution, and >> >> (2) if you have any code, please post real code (copy and paste). >> >> The above code is not real. >> >> Cheers& hth., >> >> - Alf > > Sorry about the sorted != ordered mix up. I want to end up with a > *sorted* dict from an unordered list. *Sorting the list is not > practical in this case.* I am using python 2.5, with an ActiveState > recipe for an OrderedDict. > > Given these requirements/limitations, how would you do it? > > My solution is to create a regular dict from the list. Then sort the > keys, and add the keys+values to an OrderedDict. Since the keys are > being added to the OrderedDict in the correctly sorted order, at the > end I end up with a OrderedDict that is in the correctly *sorted* > order. If that works for you, I don't understand your assertion that you can't sort the list. If you have the space & time to sort the intermediate dict, then it's as easy to create the list & sort & then the ordered dict from it. It should be faster, because you sort the keys anyway. Diez From invalid at invalid.invalid Mon Feb 22 17:40:27 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 22 Feb 2010 22:40:27 +0000 (UTC) Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> <873a0tszco.fsf@castleamber.com> Message-ID: On 2010-02-22, John Bokma wrote: > Grant Edwards writes: >>>> Windows 7 has symbolic links? >>> >>> Symbolic links are designed to aid in migration and application >>> compatibility with UNIX operating systems. Microsoft has implemented >>> its symbolic links to function just like UNIX links. >> >> So symbolic links on W7 function like Unix (hard) links >> rather than Unix _symbolic_ links?? > > Which leads you to this conclusion? The quote above that says that "symbolic links" on W7 function just like "links" on Unix. A "link" on Unix is a hard link. I presumed that if they meant "symbolic links" on Unix, they would have said "symbolic links". -- Grant Edwards grante Yow! What a COINCIDENCE! at I'm an authorized "SNOOTS visi.com OF THE STARS" dealer!! From bryanvick at gmail.com Mon Feb 22 17:48:55 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 14:48:55 -0800 (PST) Subject: Efficiently building ordered dict References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> Message-ID: <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> On Feb 22, 2:16?pm, "Diez B. Roggisch" wrote: > Am 22.02.10 22:29, schrieb Bryan: > > > > > On Feb 22, 10:57 am, "Alf P. Steinbach" ?wrote: > >> * Bryan: > > >>> I am looping through a list and creating a regular dictionary. ?From > >>> that dict, I create an ordered dict. ?I can't think of a way to build > >>> the ordered dict while going through the original loop. ?Is there a > >>> way I can avoid creating the first unordered dict just to get the > >>> ordered dict? ?Also, I am using pop(k) to retrieve the values from the > >>> unordered dict while building the ordered one because I figure that as > >>> the values are removed from the unordered dict, the lookups will > >>> become faster. ?Is there a better idiom that the code below to create > >>> an ordered dict from an unordered list? > > >>> unorderedDict = {} > >>> for thing in unorderedList: > >>> ? ? if thing.id in unorderedDict: > >>> ? ? ? ? ? ? UpdateExistingValue(unorderedDict[thing.id]) > >>> ? ? else: > >>> ? ? ? ? ? ? CreateNewValue(unorderedDict[thing.id]) > > >> If this were real code the last statement would generate an exception. > > >>> orderedDict = OrderedDict() > >>> for k in sorted(unorderedDict.keys()): > >>> ? ? orderedDict[k] ?unorderedDict.pop(k) > > >> This is not even valid syntax. > > >> Please > > >> ? ? (1) explain the problem that you're trying to solve, not how you > >> ? ? ? ? imagine the solution, and > > >> ? ? (2) if you have any code, please post real code (copy and paste). > > >> The above code is not real. > > >> Cheers& ?hth., > > >> - Alf > > > Sorry about the sorted != ordered mix up. ?I want to end up with a > > *sorted* dict from an unordered list. ?*Sorting the list is not > > practical in this case.* ?I am using python 2.5, with an ActiveState > > recipe for an OrderedDict. > > > Given these requirements/limitations, how would you do it? > > > My solution is to create a regular dict from the list. ?Then sort the > > keys, and add the keys+values to an OrderedDict. ?Since the keys are > > being added to the OrderedDict in the correctly sorted order, at the > > end I end up with a OrderedDict that is in the correctly *sorted* > > order. > > If that works for you, I don't understand your assertion that you can't > sort the list. If you have the space & time to sort the intermediate > dict, then it's as easy to create the list & sort & then the ordered > dict from it. It should be faster, because you sort the keys anyway. > > Diez Here is how I am converting a regular dict to an ordered dict that is sorted by keys. def _getOrderedDict(theDict): ordered = OrderedDict() for k in sorted(theDict.keys()): ordered[k] = theDict.pop(k) return ordered The list is a bunch of objects that represent hours worked by employees on particular jobs, and accounts, and client purchase orders etc. From this list, I am generating these sorted dicts that contain summarizing information about the list. So one of the sorted dicts will give a summary of hours worked by job number. Another one will give summary information by client PO number etc. So instead of sorting the list a bunch of different ways, I keep the list as is, generate the summaries I need into dictionaries, and then sort those dictionaries as appropriate. From no.email at nospam.invalid Mon Feb 22 18:00:08 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 15:00:08 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <7xvddori4n.fsf@ruckus.brouhaha.com> John Bokma writes: > In my class there where basically 2 groups of people: the ones who got > functional programming and the ones who had a hard time with it. The > latter group consisted mostly of people who had been programming in > languages like C and Pascal for years; they had a hard time thinking > functionally. I've heard it expressed this way (paraphrased): functional programming has a steep unlearning curve. From deets at nospam.web.de Mon Feb 22 18:00:32 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Tue, 23 Feb 2010 00:00:32 +0100 Subject: Efficiently building ordered dict In-Reply-To: <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> Message-ID: <7uggkhFbc9U1@mid.uni-berlin.de> Am 22.02.10 23:48, schrieb Bryan: > On Feb 22, 2:16 pm, "Diez B. Roggisch" wrote: >> Am 22.02.10 22:29, schrieb Bryan: >> >> >> >>> On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: >>>> * Bryan: >> >>>>> I am looping through a list and creating a regular dictionary. From >>>>> that dict, I create an ordered dict. I can't think of a way to build >>>>> the ordered dict while going through the original loop. Is there a >>>>> way I can avoid creating the first unordered dict just to get the >>>>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>>>> unordered dict while building the ordered one because I figure that as >>>>> the values are removed from the unordered dict, the lookups will >>>>> become faster. Is there a better idiom that the code below to create >>>>> an ordered dict from an unordered list? >> >>>>> unorderedDict = {} >>>>> for thing in unorderedList: >>>>> if thing.id in unorderedDict: >>>>> UpdateExistingValue(unorderedDict[thing.id]) >>>>> else: >>>>> CreateNewValue(unorderedDict[thing.id]) >> >>>> If this were real code the last statement would generate an exception. >> >>>>> orderedDict = OrderedDict() >>>>> for k in sorted(unorderedDict.keys()): >>>>> orderedDict[k] unorderedDict.pop(k) >> >>>> This is not even valid syntax. >> >>>> Please >> >>>> (1) explain the problem that you're trying to solve, not how you >>>> imagine the solution, and >> >>>> (2) if you have any code, please post real code (copy and paste). >> >>>> The above code is not real. >> >>>> Cheers& hth., >> >>>> - Alf >> >>> Sorry about the sorted != ordered mix up. I want to end up with a >>> *sorted* dict from an unordered list. *Sorting the list is not >>> practical in this case.* I am using python 2.5, with an ActiveState >>> recipe for an OrderedDict. >> >>> Given these requirements/limitations, how would you do it? >> >>> My solution is to create a regular dict from the list. Then sort the >>> keys, and add the keys+values to an OrderedDict. Since the keys are >>> being added to the OrderedDict in the correctly sorted order, at the >>> end I end up with a OrderedDict that is in the correctly *sorted* >>> order. >> >> If that works for you, I don't understand your assertion that you can't >> sort the list. If you have the space& time to sort the intermediate >> dict, then it's as easy to create the list& sort& then the ordered >> dict from it. It should be faster, because you sort the keys anyway. >> >> Diez > > Here is how I am converting a regular dict to an ordered dict that is > sorted by keys. > > def _getOrderedDict(theDict): > ordered = OrderedDict() > for k in sorted(theDict.keys()): > ordered[k] = theDict.pop(k) > return ordered > > > The list is a bunch of objects that represent hours worked by > employees on particular jobs, and accounts, and client purchase orders > etc. From this list, I am generating these sorted dicts that contain > summarizing information about the list. So one of the sorted dicts > will give a summary of hours worked by job number. Another one will > give summary information by client PO number etc. So instead of > sorting the list a bunch of different ways, I keep the list as is, > generate the summaries I need into dictionaries, and then sort those > dictionaries as appropriate. Again - why? Unless there is some filtering going on that reduces the number of total entries before the sorting when building the intermediate dict, a simple ordered = OrderedDict(sorted(the_list, key=lambda v: v['some_key'])) won't cost you a dime more. I think you believe in building the dict so that ou can have the key for sorting. As shown abov - you don't need to. It might even benefitial to really re-sort the original list, because that spares you the intermediate list. Diez From ldo at geek-central.gen.new_zealand Mon Feb 22 18:00:48 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 12:00:48 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <1ecc71bf-54ab-45e6-a38a-d1861f0921d3@v25g2000yqk.googlegroups.com> Message-ID: In message <1ecc71bf-54ab-45e6-a38a-d1861f0921d3 at v25g2000yqk.googlegroups.com>, sjdevnull at yahoo.com wrote: > On Feb 20, 1:30 am, Lawrence D'Oliveiro wrote: > >> In message , Rhodri James wrote: >> >> > In classic Pascal, a procedure was distinct from a function in that it >> > had no return value. The concept doesn't really apply in Python; there >> > are no procedures in that sense, since if a function terminates without >> > supplying an explicit return value it returns None. >> >> If Python doesn?t distinguish between procedures and functions, why >> should it distinguish between statements and expressions? > > Because the latter are different in Python (and in Ruby, and in most > modern languages), while the former aren't distinguished in Python or > Ruby or most modern languages? Primarily functional languages are the > main exception, but other than them it's pretty uncommon to find any > modern language that does distinguish procedures and functions, or one > that doesn't distinguished statements and expressions. > > You can certainly find exceptions, but distinguishing statements and > expressions is absolutely commonplace in modern languages, and > distinguishing functions and procedures is in the minority. So they are worth distinguishing where they are distinguished, except where they?re not? From ldo at geek-central.gen.new_zealand Mon Feb 22 18:01:57 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 12:01:57 +1300 Subject: What's Going on between Python and win7? References: Message-ID: In message , MRAB wrote: > Not Python-related. Seems to be pretty common with Windows-related complaints in this group. From ldo at geek-central.gen.new_zealand Mon Feb 22 18:06:36 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 12:06:36 +1300 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> <873a0tszco.fsf@castleamber.com> Message-ID: In message <873a0tszco.fsf at castleamber.com>, John Bokma wrote: > According to http://msdn.microsoft.com/en-us/library/aa365006(VS.85).aspx > > There are three types of file links supported in the NTFS file > system: hard links, junctions, and symbolic links. This topic is an > overview of hard links and junctions. ?Junctions? sound like Linux/Unix ?mount points?, plus Linux-style ?bind mounts?. Except of course Dimdows puts it all into the NTFS-specific implementation, instead of at the virtual filesystem layer. So whereas Linux can handle these while letting you mix and match different filesystem types (ext3, XFS, even FAT32, etc), Windows cannot. From python at mrabarnett.plus.com Mon Feb 22 18:08:17 2010 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Feb 2010 23:08:17 +0000 Subject: Efficiently building ordered dict In-Reply-To: <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> Message-ID: <4B830E61.8000700@mrabarnett.plus.com> Bryan wrote: > On Feb 22, 2:16 pm, "Diez B. Roggisch" wrote: >> Am 22.02.10 22:29, schrieb Bryan: >> >> >> >>> On Feb 22, 10:57 am, "Alf P. Steinbach" wrote: >>>> * Bryan: >>>>> I am looping through a list and creating a regular dictionary. From >>>>> that dict, I create an ordered dict. I can't think of a way to build >>>>> the ordered dict while going through the original loop. Is there a >>>>> way I can avoid creating the first unordered dict just to get the >>>>> ordered dict? Also, I am using pop(k) to retrieve the values from the >>>>> unordered dict while building the ordered one because I figure that as >>>>> the values are removed from the unordered dict, the lookups will >>>>> become faster. Is there a better idiom that the code below to create >>>>> an ordered dict from an unordered list? >>>>> unorderedDict = {} >>>>> for thing in unorderedList: >>>>> if thing.id in unorderedDict: >>>>> UpdateExistingValue(unorderedDict[thing.id]) >>>>> else: >>>>> CreateNewValue(unorderedDict[thing.id]) >>>> If this were real code the last statement would generate an exception. >>>>> orderedDict = OrderedDict() >>>>> for k in sorted(unorderedDict.keys()): >>>>> orderedDict[k] unorderedDict.pop(k) >>>> This is not even valid syntax. >>>> Please >>>> (1) explain the problem that you're trying to solve, not how you >>>> imagine the solution, and >>>> (2) if you have any code, please post real code (copy and paste). >>>> The above code is not real. >>>> Cheers& hth., >>>> - Alf >>> Sorry about the sorted != ordered mix up. I want to end up with a >>> *sorted* dict from an unordered list. *Sorting the list is not >>> practical in this case.* I am using python 2.5, with an ActiveState >>> recipe for an OrderedDict. >>> Given these requirements/limitations, how would you do it? >>> My solution is to create a regular dict from the list. Then sort the >>> keys, and add the keys+values to an OrderedDict. Since the keys are >>> being added to the OrderedDict in the correctly sorted order, at the >>> end I end up with a OrderedDict that is in the correctly *sorted* >>> order. >> If that works for you, I don't understand your assertion that you can't >> sort the list. If you have the space & time to sort the intermediate >> dict, then it's as easy to create the list & sort & then the ordered >> dict from it. It should be faster, because you sort the keys anyway. >> >> Diez > > Here is how I am converting a regular dict to an ordered dict that is > sorted by keys. > > def _getOrderedDict(theDict): > ordered = OrderedDict() > for k in sorted(theDict.keys()): > ordered[k] = theDict.pop(k) > return ordered > As I mentioned in an earlier post, you could do: def _getOrderedDict(theDict): return OrderedDict(sorted(theDict.items())) [snip] From krister.svanlund at gmail.com Mon Feb 22 18:27:52 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 23 Feb 2010 00:27:52 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <2cf430a61002221527j416d3fc5k770d5bafe7dfd0ae@mail.gmail.com> On Mon, Feb 22, 2010 at 10:56 PM, AON LAZIO wrote: > That will be superb > > -- > Passion is my style And when will be as famous as the beatles? From bryanvick at gmail.com Mon Feb 22 18:31:32 2010 From: bryanvick at gmail.com (Bryan) Date: Mon, 22 Feb 2010 15:31:32 -0800 (PST) Subject: Efficiently building ordered dict References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> <7uge18Fta5U1@mid.uni-berlin.de> <49a75c77-92fc-483a-bce8-63f3e280d139@g10g2000yqh.googlegroups.com> <7uggkhFbc9U1@mid.uni-berlin.de> Message-ID: <8c9b72a6-8496-4992-a521-37221ebd68da@g26g2000yqn.googlegroups.com> On Feb 22, 3:00?pm, "Diez B. Roggisch" wrote: > Am 22.02.10 23:48, schrieb Bryan: > > > > > On Feb 22, 2:16 pm, "Diez B. Roggisch" ?wrote: > >> Am 22.02.10 22:29, schrieb Bryan: > > >>> On Feb 22, 10:57 am, "Alf P. Steinbach" ? ?wrote: > >>>> * Bryan: > > >>>>> I am looping through a list and creating a regular dictionary. ?From > >>>>> that dict, I create an ordered dict. ?I can't think of a way to build > >>>>> the ordered dict while going through the original loop. ?Is there a > >>>>> way I can avoid creating the first unordered dict just to get the > >>>>> ordered dict? ?Also, I am using pop(k) to retrieve the values from the > >>>>> unordered dict while building the ordered one because I figure that as > >>>>> the values are removed from the unordered dict, the lookups will > >>>>> become faster. ?Is there a better idiom that the code below to create > >>>>> an ordered dict from an unordered list? > > >>>>> unorderedDict = {} > >>>>> for thing in unorderedList: > >>>>> ? ? ?if thing.id in unorderedDict: > >>>>> ? ? ? ? ? ? ?UpdateExistingValue(unorderedDict[thing.id]) > >>>>> ? ? ?else: > >>>>> ? ? ? ? ? ? ?CreateNewValue(unorderedDict[thing.id]) > > >>>> If this were real code the last statement would generate an exception. > > >>>>> orderedDict = OrderedDict() > >>>>> for k in sorted(unorderedDict.keys()): > >>>>> ? ? ?orderedDict[k] ?unorderedDict.pop(k) > > >>>> This is not even valid syntax. > > >>>> Please > > >>>> ? ? ?(1) explain the problem that you're trying to solve, not how you > >>>> ? ? ? ? ?imagine the solution, and > > >>>> ? ? ?(2) if you have any code, please post real code (copy and paste). > > >>>> The above code is not real. > > >>>> Cheers& ? ?hth., > > >>>> - Alf > > >>> Sorry about the sorted != ordered mix up. ?I want to end up with a > >>> *sorted* dict from an unordered list. ?*Sorting the list is not > >>> practical in this case.* ?I am using python 2.5, with an ActiveState > >>> recipe for an OrderedDict. > > >>> Given these requirements/limitations, how would you do it? > > >>> My solution is to create a regular dict from the list. ?Then sort the > >>> keys, and add the keys+values to an OrderedDict. ?Since the keys are > >>> being added to the OrderedDict in the correctly sorted order, at the > >>> end I end up with a OrderedDict that is in the correctly *sorted* > >>> order. > > >> If that works for you, I don't understand your assertion that you can't > >> sort the list. If you have the space& ?time to sort the intermediate > >> dict, then it's as easy to create the list& ?sort& ?then the ordered > >> dict from it. It should be faster, because you sort the keys anyway. > > >> Diez > > > Here is how I am converting a regular dict to an ordered dict that is > > sorted by keys. > > > def _getOrderedDict(theDict): > > ? ?ordered = OrderedDict() > > ? ?for k in sorted(theDict.keys()): > > ? ? ? ? ? ?ordered[k] = theDict.pop(k) > > ? ?return ordered > > > The list is a bunch of objects that represent hours worked by > > employees on particular jobs, and accounts, and client purchase orders > > etc. ?From this list, I am generating these sorted dicts that contain > > summarizing information about the list. ?So one of the sorted dicts > > will give a summary of hours worked by job number. ?Another one will > > give summary information by client PO number etc. ?So instead of > > sorting the list a bunch of different ways, I keep the list as is, > > generate the summaries I need into dictionaries, and then sort those > > dictionaries as appropriate. > > Again - why? Unless there is some filtering going on that reduces the > number of total entries before the sorting when building the > intermediate dict, a simple > > ordered = OrderedDict(sorted(the_list, key=lambda v: v['some_key'])) > > won't cost you a dime more. > > I think you believe in building the dict so that ou can have the key for > sorting. As shown abov - you don't need to. > > It might even benefitial to really re-sort the original list, because > that spares you the intermediate list. > > Diez Lets say my list has 1 million items. If I sort the list before summarizing it, I will absolutley have to sort 1 million items. However, if I summarize first, then just sort the keys in the summary dict, I could wind up only sorting 4 or 5 items, if within that 1 million item list, there were only 4 or 5 job numbers for example. The list stays as is, and my summary dictionary is sorted so I can iterate through it and make little reports that humans will like. From jjposner at optimum.net Mon Feb 22 18:34:58 2010 From: jjposner at optimum.net (John Posner) Date: Mon, 22 Feb 2010 18:34:58 -0500 Subject: Efficiently building ordered dict In-Reply-To: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> References: <4fa3eaeb-4627-4e0c-89cd-e19c84a92e67@x22g2000yqx.googlegroups.com> Message-ID: <4B8314A2.500@optimum.net> On 2/22/2010 4:29 PM, Bryan wrote: > > Sorry about the sorted != ordered mix up. I want to end up with a > *sorted* dict from an unordered list. *Sorting the list is not > practical in this case.* I am using python 2.5, with an ActiveState > recipe for an OrderedDict. > Have you looked at this: http://pypi.python.org/pypi/sorteddict/1.2.1 >>> data = zip('afcedbijhg', range(10)) >>> old = dict(data) >>> for key in old: ... print key, old[key] ... a 0 c 2 b 5 e 3 d 4 g 9 f 1 i 6 h 8 j 7 >>> new = sorteddict.sorteddict(data) >>> for key in new: ... print key, new[key] ... a 0 b 5 c 2 d 4 e 3 f 1 g 9 h 8 i 6 j 7 -John From phlip2005 at gmail.com Mon Feb 22 18:57:22 2010 From: phlip2005 at gmail.com (Phlip) Date: Mon, 22 Feb 2010 15:57:22 -0800 (PST) Subject: When will Python go mainstream like Java? References: Message-ID: On Feb 22, 3:27?pm, Krister Svanlund wrote: > And when will be as famous as the Beatles? And when will Message-ID: You mean it's not? -- -Ed Falk, falk at despams.r.us.com http://thespamdiaries.blogspot.com/ From alexanderjquinn at yahoo.com Mon Feb 22 19:01:44 2010 From: alexanderjquinn at yahoo.com (Alex Quinn) Date: Mon, 22 Feb 2010 16:01:44 -0800 (PST) Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? In-Reply-To: <6cc20cea1002221141u534fd5f7v8748f50f9094011f@mail.gmail.com> References: <973565.53691.qm@web38208.mail.mud.yahoo.com> <6cc20cea1002221141u534fd5f7v8748f50f9094011f@mail.gmail.com> Message-ID: <146400.8956.qm@web38205.mail.mud.yahoo.com> Thanks for the reply, Jonathan, but I was hoping to find a workaround. I don't have root access for these machines so I can't repair the install. Among the 6 Linux servers at 3 separately managed organizations where I do work, the sqlite3 module was broken 100% of the time. It seems to be a common problem, so I'd like to make my code robust enough to deal with it gracefully. Ideally, the Python build process would refuse to install a faulty install, but that's another matter. I'm just looking for a workaround. Thanks, Alex ----- Original Message ---- From: Jonathan Gardner To: Alex Quinn Cc: python-list at python.org Sent: Mon, February 22, 2010 2:41:45 PM Subject: Re: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? On Mon, Feb 22, 2010 at 9:10 AM, Alex Quinn wrote: > > * Sqlite3 should fill the void now. However, in my experience, nearly every Linux Python install I encounter has a broken sqlite3 module ("ImportError: No module named _sqlite3"). It's a well-documented issue, but it the solution generally requires root access, which I don't have on these servers. > If your program is installed in the same way everything else is installed on the system (RPM or deb packages, or whatever), there should be dependencies clearly listed. When the admin installs your code, he must also install the requisite modules that you list as dependencies. -- Jonathan Gardner jgardner at jonathangardner.net From rhodri at wildebst.demon.co.uk Mon Feb 22 19:20:18 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Tue, 23 Feb 2010 00:20:18 -0000 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> Message-ID: On Mon, 22 Feb 2010 10:48:55 -0000, DANNY wrote: > On Feb 21, 1:54 am, Tim Roberts wrote: >> DANNY wrote: >> >> >If I want to have a MPEG-4/10 coded video and stream it through the >> >network and than have the same video on the client side, what should I >> >use and of course I don't want to have raw MPEG data, because than I >> >couldn't extract the frames to manipulate them. >> >> If you want to manipulate the frames (as bitmaps), then you have little >> choice but to decode the MPEG as you receive it, manipulate the bitmaps, >> and re-encode it back to MPEG. >> >> That's going to take a fair amount of time... >> -- >> Tim Roberts, t... at probo.com >> Providenza & Boekelheide, Inc. > > Yes, well beside bieng time-consuming, that is also inappropriate for > me, > because I want to have clip that would be streamed across the network > and > have the same GoP on the client side as the original-because I want to > see > what is the effect of errors on different GoP sizes. I would > manipuleta the > received clip just in the way that (if there are too many errors) I > would > stop displaying untill the next I frame.....I cant find a way to do > that....is there a way? Could you say a bit more about what you mean when you say "the effect of errors"? It's easy enough to introduce bit errors into a data file (just flip random bits), but I'm not clear what it is you're trying to measure. -- Rhodri James *-* Wildebeeste Herder to the Masses From wolftracks at invalid.com Mon Feb 22 20:25:30 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 17:25:30 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: So what's the bottom line? This link notion is completely at odds with XP, and produces what I would call something of a mess to the unwary Python/W7 user. Is there a simple solution? How do I get out of this pickle? I just want to duplicate the program in another folder, and not link to an ancestor. From shawn at milochik.com Mon Feb 22 20:54:28 2010 From: shawn at milochik.com (Shawn Milochik) Date: Mon, 22 Feb 2010 20:54:28 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: When will Java be popular enough to replace other languages in their own environments, the way Python has done to Java (Jython) and .NET (IronPython)? Shawn From stef.mientki at gmail.com Mon Feb 22 21:01:18 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 23 Feb 2010 03:01:18 +0100 Subject: How to transmit a crash report ? Message-ID: <4B8336EE.9040802@gmail.com> hello, in my python desktop applications, I'ld like to implement a crash reporter. By redirecting the sys.excepthook, I can detect a crash and collect the necessary data. Now I want that my users sends this information to me, and I can't find a good way of doing this. The following solutions came into my mind: (most of my users are on Windows, and the programs are written in Python 2.6) 1. mailto: doesn't work if the the user didn't install a default email client, or if the user uses a portable email client (that isn't started yet) Besides this limits the messages to small amounts of data. 2.other mail options: smtp AFAIK such a solution needs smtp authorization, and therefor I've to put my username and password in the desktop application. 3. http-post Although post is also limited in size, I could store information in cookies (don't know yet how), and cookies are sent parallel to the post message. On the server site I can use a small php script, that stores the post-data, cookies and/or send's a (long) email. are there better options ? thanks, Stef Mientki -------------- next part -------------- An HTML attachment was scrubbed... URL: From gt67 at hw.ac.uk Mon Feb 22 21:24:00 2010 From: gt67 at hw.ac.uk (Giorgos Tzampanakis) Date: Tue, 23 Feb 2010 02:24:00 +0000 (UTC) Subject: Writing an assembler in Python Message-ID: I'm implementing a CPU that will run on an FPGA. I want to have a (dead) simple assembler that will generate the machine code for me. I want to use Python for that. Are there any libraries that can help me with the parsing of the assembly code? From nagle at animats.com Mon Feb 22 21:24:04 2010 From: nagle at animats.com (John Nagle) Date: Mon, 22 Feb 2010 18:24:04 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> Message-ID: <4b83383b$0$1622$742ec2ed@news.sonic.net> sjdevnull at yahoo.com wrote: > On Feb 20, 9:58 pm, John Nagle wrote: >> sjdevn... at yahoo.com wrote: >>> On Feb 18, 2:58 pm, John Nagle wrote: >>>> Multiple processes are not the answer. That means loading multiple >>>> copies of the same code into different areas of memory. The cache >>>> miss rate goes up accordingly. >>> A decent OS will use copy-on-write with forked processes, which should >>> carry through to the cache for the code. >> That doesn't help much if you're using the subprocess module. The >> C code of the interpreter is shared, but all the code generated from >> Python is not. > > Of course. Multithreading also fails miserably if the threads all try > to call exec() or the equivalent. > > It works fine if you use os.fork(). Forking in multithreaded programs is iffy. What happens depends on the platform, and it's usually not what you wanted to happen. Solaris before version 10 forks all threads, and both new processes have all the threads running. POSIX semantics are to fork only the thread making the request. The problem is that this leaves the other Python threads in the new process with Python state, locks and reference counts set, but no OS thread to run them. See "http://bugs.python.org/issue1683" "http://bugs.python.org/issue874900" "http://bugs.python.org/issue6721" "http://bugs.python.org/issue7242" There are at least two open bug reports in this area. If you fork and "exec", which discards the state of Python in the child process, there's less trouble. But if you're actually forking a Python environment and running it, you're going to have at least a memory leak, and probably further difficulties. John Nagle From python at mrabarnett.plus.com Mon Feb 22 21:27:41 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Feb 2010 02:27:41 +0000 Subject: How to transmit a crash report ? In-Reply-To: <4B8336EE.9040802@gmail.com> References: <4B8336EE.9040802@gmail.com> Message-ID: <4B833D1D.6080908@mrabarnett.plus.com> Stef Mientki wrote: > hello, > > in my python desktop applications, > I'ld like to implement a crash reporter. > By redirecting the sys.excepthook, > I can detect a crash and collect the necessary data. > Now I want that my users sends this information to me, > and I can't find a good way of doing this. > > The following solutions came into my mind: > (most of my users are on Windows, and the programs are written in Python > 2.6) > > 1. mailto: > doesn't work if the the user didn't install a default email client, > or if the user uses a portable email client (that isn't started yet) > Besides this limits the messages to small amounts of data. > > 2.other mail options: smtp > AFAIK such a solution needs smtp authorization, and therefor I've to put > my username and password in the desktop application. > Try reading the documentation for Python's smtplib module. You don't need to provide any password. > 3. http-post > Although post is also limited in size, > I could store information in cookies (don't know yet how), and cookies > are sent parallel to the post message. > On the server site I can use a small php script, that stores the > post-data, cookies and/or send's a (long) email. > > are there better options ? > From no.email at nospam.invalid Mon Feb 22 21:33:40 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 18:33:40 -0800 Subject: Writing an assembler in Python References: Message-ID: <7x635obrzv.fsf@ruckus.brouhaha.com> Giorgos Tzampanakis writes: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. I want to use Python for that. Are there any libraries that > can help me with the parsing of the assembly code? One "dead simple" option is the re module. From drobinow at gmail.com Mon Feb 22 21:39:34 2010 From: drobinow at gmail.com (David Robinow) Date: Mon, 22 Feb 2010 21:39:34 -0500 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <4eb0089f1002221839v75fa29dbg7beef5ce46b2cb50@mail.gmail.com> On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson wrote: > How do I get out of this pickle? I just want to duplicate the ?program in > another folder, and not link to an ancestor. Ask in an appropriate forum. I'm not sure where that is but you might try http://www.sevenforums.com/ From ldo at geek-central.gen.new_zealand Mon Feb 22 22:08:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 16:08:19 +1300 Subject: Writing an assembler in Python References: Message-ID: In message , Giorgos Tzampanakis wrote: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. Let me suggest an alternative approach: use Python itself as the assembler. Call routines in your library to output the code. That way you have a language more powerful than any assembler. See for an example. From ldo at geek-central.gen.new_zealand Mon Feb 22 22:10:03 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 16:10:03 +1300 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> <8ca440b2-6094-4b35-80c5-81d000517ce0@v20g2000prb.googlegroups.com> <87ee053d-ebe3-47b9-9da8-c1e5967cd22c@x1g2000prb.googlegroups.com> <9c3931cf-8bfa-48dc-aa14-3b89bdad918c@z1g2000prc.googlegroups.com> <0e08238b-6c22-47c5-813a-1bc4185c132d@y7g2000prc.googlegroups.com> <3aa0205f-1e98-4376-92e4-607f96f13616@k19g2000yqc.googlegroups.com> Message-ID: In message <3aa0205f-1e98-4376-92e4-607f96f13616 at k19g2000yqc.googlegroups.com>, Michael Sparks wrote: > [1] This is perhaps more appropriate because '(a b c) is equivalent > to (quote a b c), and quote a b c can be viewed as close to > python's expression "lambda: a b c" You got to be kidding. From ldo at geek-central.gen.new_zealand Mon Feb 22 22:14:42 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Tue, 23 Feb 2010 16:14:42 +1300 Subject: MySQLdb, blobs, and inserting References: <85itgj$mlc$1@nnrp1.deja.com> <85k0fd$hv2$1@news1.xs4all.nl> <387de600.0@news.cyberway.com.sg> Message-ID: In message , Dennis Lee Bieber wrote: > Besides, the approved method of interacting with MySQLdb would use: > > c.execute("insert into items (story) values (%s)", > (file.read(), ) ) > > which lets the adapter properly escape any dangerous characters in the > data, then wrap it with any needed quotes. There are so many situations this cannot deal with... From e_d_k at yahoo.com Mon Feb 22 22:47:26 2010 From: e_d_k at yahoo.com (Ed Keith) Date: Mon, 22 Feb 2010 19:47:26 -0800 (PST) Subject: Writing an assembler in Python In-Reply-To: Message-ID: <166845.21850.qm@web58906.mail.re1.yahoo.com> > Subject: Re: Writing an assembler in Python > Giorgos > Tzampanakis wrote: > > > I'm implementing a CPU that will run on an FPGA. I > want to have a > > (dead) simple assembler that will generate the machine > code for > > me. > > Let me suggest an alternative approach: use Python itself > as the assembler. > Call routines in your library to output the code. That way > you have a > language more powerful than any assembler. > > See for > an example. > -- > http://mail.python.org/mailman/listinfo/python-list > Not a bad idea, has anyone tried this for x86 machine code? -EdK Ed Keith e_d_k at yahoo.com Blog: edkeith.blogspot.com From rpjanaka at gmail.com Mon Feb 22 22:48:54 2010 From: rpjanaka at gmail.com (R. P. Janaka) Date: Tue, 23 Feb 2010 09:18:54 +0530 Subject: How to get memory and CPU status of a particular process Message-ID: Hi all, Is there a way to get system memory consumption and CPU consumption in a platform independent way, using python...? Basically my requirement is, get the memory status and CPU status of a particular process. If there is a way to get memory info and CPU info by just giving the process ID, that is exactly what I need to do :) Is this possible with python..? -- Regards, R. P. Janaka -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Mon Feb 22 23:06:30 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 20:06:30 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On 2/22/2010 6:39 PM, David Robinow wrote: > On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson wrote: >> How do I get out of this pickle? I just want to duplicate the program in >> another folder, and not link to an ancestor. > Ask in an appropriate forum. I'm not sure where that is but you might > try http://www.sevenforums.com/ Not in my NG list. If the way this is going is that it occurs on W7, not just in my case, then it will impact many Python users. From g.bogle at auckland.no.spam.ac.nz Mon Feb 22 23:32:22 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Tue, 23 Feb 2010 17:32:22 +1300 Subject: Problem creating executable, with PyQwt References: Message-ID: David Boddie wrote: > I have previously referred people with py2exe/PyQt issues to this page on > the PyQt Wiki: > > http://www.py2exe.org/index.cgi/Py2exeAndPyQt > > If you can somehow convince py2exe to include the QtSvg module (and > presumably the libQtSvg library as well) then perhaps that will solve > this problem. > > David Thanks David, that worked a treat. :-) From jgardner at jonathangardner.net Mon Feb 22 23:35:15 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 20:35:15 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <87iq9pt3l5.fsf@castleamber.com> References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <6cc20cea1002222035y34c8b052qa352d1a7daf5db10@mail.gmail.com> On Mon, Feb 22, 2010 at 12:31 PM, John Bokma wrote: > > In my class there where basically 2 groups of people: the ones who got > functional programming and the ones who had a hard time with it. The > latter group consisted mostly of people who had been programming in > languages like C and Pascal for years; they had a hard time thinking > functionally. The former group consisted mostly of people who had little > or no programming experience, with a few exceptions (including me :-) ). > > So I have the feeling it has more to do with your background then how > people think / are wired. > That's encouraging. If functional programming is really more natural to those who are less familiar with math and programming, then perhaps there is a future for it. Unfortunately, I don't know that just knowing how to program functionally is enough. Even the functional folks have a hard time optimizing routines (time or memory). Even with DBAs, they have to know how the functional SQL query is translated into discrete machine instructions. As it is now, the vast majority (all?) of the programmers who do any programming seriously are familiar with the statement-based approach. A minority understand let alone appreciate the functional approach. -- Jonathan Gardner jgardner at jonathangardner.net From jgardner at jonathangardner.net Mon Feb 22 23:36:55 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Mon, 22 Feb 2010 20:36:55 -0800 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> On Mon, Feb 22, 2010 at 1:56 PM, AON LAZIO wrote: > That will be superb > It already has. -- Jonathan Gardner jgardner at jonathangardner.net From alfps at start.no Mon Feb 22 23:50:14 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Feb 2010 05:50:14 +0100 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: * W. eWatson: > So what's the bottom line? This link notion is completely at odds with > XP, Well, Windows NT has always had *hardlinks*. I found it a bit baffling that that functionality is documented as not implemented for Windows in the Python standard library. But OK, it was non-trivial to do prior to Windows 2000; you had to sort of hack it using the backup APIs since the functionality was not exposed through the ordinary file APIs. > and produces what I would call something of a mess to the unwary > Python/W7 user. Is there a simple solution? > > How do I get out of this pickle? I just want to duplicate the program > in another folder, and not link to an ancestor. Copy and paste. Cheers & hth., - Alf From wolftracks at invalid.com Tue Feb 23 00:05:28 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 21:05:28 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <4B836218.1000600@invalid.com> On 2/22/2010 8:50 PM, Alf P. Steinbach wrote: > * W. eWatson: >> So what's the bottom line? This link notion is completely at odds with >> XP, > > Well, Windows NT has always had *hardlinks*. > > I found it a bit baffling that that functionality is documented as not > implemented for Windows in the Python standard library. > > But OK, it was non-trivial to do prior to Windows 2000; you had to sort > of hack it using the backup APIs since the functionality was not exposed > through the ordinary file APIs. > > > >> and produces what I would call something of a mess to the unwary >> Python/W7 user. Is there a simple solution? >> >> How do I get out of this pickle? I just want to duplicate the program >> in another folder, and not link to an ancestor. > > Copy and paste. > > > Cheers & hth., > > - Alf I thought that's what I did. Is there some other way? From no.email at nospam.invalid Tue Feb 23 00:06:32 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 22 Feb 2010 21:06:32 -0800 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <7xy6iky207.fsf@ruckus.brouhaha.com> Steve Howell writes: > My gut instinct is that functional programming works well for lots of > medium sized problems and it is worth learning. I think it's worth learning because it will make you a better programmer even if you never use it for anything beyond academic exercises. It's just like playing Bach fugues in some of your practice hours will make you a better musician even if you are professionally a heavy metal rock guitarist. From wolftracks at invalid.com Tue Feb 23 00:09:51 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 21:09:51 -0800 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On 2/22/2010 8:50 PM, Alf P. Steinbach wrote: > * W. eWatson: >> So what's the bottom line? This link notion is completely at odds with >> XP, > > Well, Windows NT has always had *hardlinks*. > > I found it a bit baffling that that functionality is documented as not > implemented for Windows in the Python standard library. > > But OK, it was non-trivial to do prior to Windows 2000; you had to sort > of hack it using the backup APIs since the functionality was not exposed > through the ordinary file APIs. > > > >> and produces what I would call something of a mess to the unwary >> Python/W7 user. Is there a simple solution? >> >> How do I get out of this pickle? I just want to duplicate the program >> in another folder, and not link to an ancestor. > > Copy and paste. > > > Cheers & hth., > > - Alf Alf? Hello,Norway. My wife is Norwegian and that was her father's name. I thought that's what I did. Is there some other way? Tusin Tak (That's about the size of my vocabulary and spelling ability! 1000 thanks. What is the correct spelling?) From timr at probo.com Tue Feb 23 00:10:55 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Feb 2010 21:10:55 -0800 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> Message-ID: DANNY wrote: > >Yes, well beside bieng time-consuming, that is also inappropriate >for me, because I want to have clip that would be streamed across >the network and have the same GoP on the client side as the >original-because I want to see what is the effect of errors on >different GoP sizes. I would manipuleta the received clip just >in the way that (if there are too many errors) I would >stop displaying untill the next I frame.....I cant find a way to do >that....is there a way? Sure. You can do a partial decode yourself, scan for the start of frame markers, pull the I/P/B state from that, and periodically "forget" to pass the buffer through. Your filter could have MPEG in and out. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From showell30 at yahoo.com Tue Feb 23 00:11:25 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:11:25 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: On Feb 22, 8:35?pm, Jonathan Gardner wrote: > On Mon, Feb 22, 2010 at 12:31 PM, John Bokma wrote: > > > In my class there where basically 2 groups of people: the ones who got > > functional programming and the ones who had a hard time with it. The > > latter group consisted mostly of people who had been programming in > > languages like C and Pascal for years; they had a hard time thinking > > functionally. The former group consisted mostly of people who had little > > or no programming experience, with a few exceptions (including me :-) ). > > > So I have the feeling it has more to do with your background then how > > people think / are wired. > > That's encouraging. If functional programming is really more natural > to those who are less familiar with math and programming, then perhaps > there is a future for it. > > Unfortunately, I don't know that just knowing how to program > functionally is enough. Even the functional folks have a hard time > optimizing routines (time or memory). Even with DBAs, they have to > know how the functional SQL query is translated into discrete machine > instructions. > > As it is now, the vast majority (all?) of the programmers who do any > programming seriously are familiar with the statement-based approach. > A minority understand let alone appreciate the functional approach. > Hi Jonathon. I understand three major programming paradigms-- imperative, OO, and functional. My first instinct is always imperative, as I just want the computer to *do* stuff. I am not an expert in any paradigm and it is possible that I am overlooking other major paradigms. My gut instinct is that functional programming works well for lots of medium sized problems and it is worth learning. From wolftracks at invalid.com Tue Feb 23 00:15:01 2010 From: wolftracks at invalid.com (W. eWatson) Date: Mon, 22 Feb 2010 21:15:01 -0800 Subject: What's Going on between (Verify) Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: Maybe someone could verify my result? open file read file line print line close file data 1234 Execute it in a folder Create another folder and copy the program to it. put in a new data file as data 4567 Execute the copied program Does it give data1234? From showell30 at yahoo.com Tue Feb 23 00:17:36 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:17:36 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> Message-ID: <84a4a03f-22dd-4f05-b754-f1e55f6fdfa6@v20g2000prb.googlegroups.com> On Feb 22, 9:11?pm, Steve Howell wrote: > On Feb 22, 8:35?pm, Jonathan Gardner > wrote: > > > > > On Mon, Feb 22, 2010 at 12:31 PM, John Bokma wrote: > > > > In my class there where basically 2 groups of people: the ones who got > > > functional programming and the ones who had a hard time with it. The > > > latter group consisted mostly of people who had been programming in > > > languages like C and Pascal for years; they had a hard time thinking > > > functionally. The former group consisted mostly of people who had little > > > or no programming experience, with a few exceptions (including me :-) ). > > > > So I have the feeling it has more to do with your background then how > > > people think / are wired. > > > That's encouraging. If functional programming is really more natural > > to those who are less familiar with math and programming, then perhaps > > there is a future for it. > > > Unfortunately, I don't know that just knowing how to program > > functionally is enough. Even the functional folks have a hard time > > optimizing routines (time or memory). Even with DBAs, they have to > > know how the functional SQL query is translated into discrete machine > > instructions. > > > As it is now, the vast majority (all?) of the programmers who do any > > programming seriously are familiar with the statement-based approach. > > A minority understand let alone appreciate the functional approach. > > Hi Jonathon. ?I understand three major programming paradigms-- > imperative, OO, and functional. ?My first instinct is always > imperative, as I just want the computer to *do* stuff. > > I am not an expert in any paradigm and it is possible that I am > overlooking other major paradigms. > > My gut instinct is that functional programming works well for lots of > medium sized problems and it is worth learning. Sorry for misspelling your name, and yes I agree that you always want some notion of what happens under the covers (in any paradigm). From showell30 at yahoo.com Tue Feb 23 00:27:04 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:27:04 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> <7xy6iky207.fsf@ruckus.brouhaha.com> Message-ID: <05059b42-105b-4822-8448-d30add1dba15@k2g2000pro.googlegroups.com> On Feb 22, 9:06?pm, Paul Rubin wrote: > Steve Howell writes: > > My gut instinct is that functional programming works well for lots of > > medium sized problems and it is worth learning. > > I think it's worth learning because it will make you a better programmer > even if you never use it for anything beyond academic exercises. ?It's > just like playing Bach fugues in some of your practice hours will make > you a better musician even if you are professionally a heavy metal rock > guitarist. Well said, and your analogy is based in fact--some pretty awesome rock guitarists have training in classical and jazz. From clp2 at rebertia.com Tue Feb 23 00:45:24 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Feb 2010 21:45:24 -0800 Subject: When will Python go mainstream like Java? In-Reply-To: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> Message-ID: <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> On Mon, Feb 22, 2010 at 8:36 PM, Jonathan Gardner wrote: > On Mon, Feb 22, 2010 at 1:56 PM, AON LAZIO wrote: >> That will be superb >> > It already has. Indeed. Python is at position 7, just behind C#, in the TIOBE Index: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html Although for Java-level mainstreamness, you'd probably need to be in the top 3 or 4. Cheers, Chris -- The TIOBE Index is by no means perfect though. http://blog.rebertia.com From showell30 at yahoo.com Tue Feb 23 00:54:09 2010 From: showell30 at yahoo.com (Steve Howell) Date: Mon, 22 Feb 2010 21:54:09 -0800 (PST) Subject: When will Python go mainstream like Java? References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> Message-ID: <96c61ffb-108e-40af-9b45-7ac9b7289cb5@t34g2000prm.googlegroups.com> On Feb 22, 9:45?pm, Chris Rebert wrote: > On Mon, Feb 22, 2010 at 8:36 PM, Jonathan Gardner > > wrote: > > On Mon, Feb 22, 2010 at 1:56 PM, AON LAZIO wrote: > >> That will be superb > > > It already has. > > Indeed. Python is at position 7, just behind C#, in the TIOBE Index:http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > Although for Java-level mainstreamness, you'd probably need to be in > the top 3 or 4. > > Cheers, > Chris > -- > The TIOBE Index is by no means perfect though.http://blog.rebertia.com I am sure Python could rise to number six with some squigglies! ;) From timr at probo.com Tue Feb 23 00:57:22 2010 From: timr at probo.com (Tim Roberts) Date: Mon, 22 Feb 2010 21:57:22 -0800 Subject: Writing an assembler in Python References: <7x635obrzv.fsf@ruckus.brouhaha.com> Message-ID: <69r6o5948eut0hjjduahf2srl892pnisot@4ax.com> Paul Rubin wrote: > >Giorgos Tzampanakis writes: >> I'm implementing a CPU that will run on an FPGA. I want to have a >> (dead) simple assembler that will generate the machine code for >> me. I want to use Python for that. Are there any libraries that >> can help me with the parsing of the assembly code? > >One "dead simple" option is the re module. Yes, indeed. I have implemented TWO different FPGA-based microassemblers in Python using the essentially undocumented but magically delicious re.Scanner class. Simple and flexible. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From alfps at start.no Tue Feb 23 01:00:48 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Feb 2010 07:00:48 +0100 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: * W. eWatson: > On 2/22/2010 8:50 PM, Alf P. Steinbach wrote: >> * W. eWatson: >>> So what's the bottom line? This link notion is completely at odds with >>> XP, >> >> Well, Windows NT has always had *hardlinks*. >> >> I found it a bit baffling that that functionality is documented as not >> implemented for Windows in the Python standard library. >> >> But OK, it was non-trivial to do prior to Windows 2000; you had to sort >> of hack it using the backup APIs since the functionality was not exposed >> through the ordinary file APIs. >> >> >> >>> and produces what I would call something of a mess to the unwary >>> Python/W7 user. Is there a simple solution? >>> >>> How do I get out of this pickle? I just want to duplicate the program >>> in another folder, and not link to an ancestor. >> >> Copy and paste. >> >> >> Cheers & hth., >> >> - Alf > Alf? Hello,Norway. My wife is Norwegian and that was her father's name. > > I thought that's what I did. Is there some other way? (A) For using Explorer, see and in particular look at the tips at the bottom. (B) To get absolute control you can use the command interpreter. I don't have Windows7 but googling yielded the following URL: The "copy" command there copies files. > Tusin Tak (That's about the size of my vocabulary and spelling ability! > 1000 thanks. What is the correct spelling?) That's "tusen takk". Cheers & hth., - Alf From alfps at start.no Tue Feb 23 01:03:00 2010 From: alfps at start.no (Alf P. Steinbach) Date: Tue, 23 Feb 2010 07:03:00 +0100 Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. In-Reply-To: <7xy6iky207.fsf@ruckus.brouhaha.com> References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> <7xy6iky207.fsf@ruckus.brouhaha.com> Message-ID: * Paul Rubin: > Steve Howell writes: >> My gut instinct is that functional programming works well for lots of >> medium sized problems and it is worth learning. > > I think it's worth learning because it will make you a better programmer > even if you never use it for anything beyond academic exercises. It's > just like playing Bach fugues in some of your practice hours will make > you a better musician even if you are professionally a heavy metal rock > guitarist. Uhm, Paganini... As I understand it he invented the "destroy your instruments on stage". :-) Cheers, - Alf (off-topic) From jgorauskas at gmail.com Tue Feb 23 01:06:45 2010 From: jgorauskas at gmail.com (gorauskas) Date: Mon, 22 Feb 2010 22:06:45 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> I installed it on a Windows 7 machine with CPython 2.6.4 and I get the following error: Traceback (most recent call last): File "dreampie.py", line 3, in File "dreampielib\gui\__init__.pyc", line 73, in File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk ImportError: DLL load failed: The specified module could not be found. What am I doing wrong? Thanks, JGG From ryan at rfk.id.au Tue Feb 23 01:10:58 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Tue, 23 Feb 2010 17:10:58 +1100 Subject: ANN: esky v0.4.0 [was Re: Upgrading Py2exe App] In-Reply-To: <1266615136.2495.39.camel@rambutan> References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <20ae4031-bfb2-40ca-b79c-3b9baf44d59c@j1g2000vbl.googlegroups.com> <1266615136.2495.39.camel@rambutan> Message-ID: <1266905458.3153.16.camel@durian> Hi All, As promised I have made a new release of esky, my auto-update framework for frozen python apps. Details below for those who are interested. Cheers, Ryan ------------------------------- esky: keep frozen apps fresh Esky is an auto-update framework for frozen Python applications. It provides a simple API through which apps can find, fetch and install updates, and a bootstrapping mechanism that keeps the app safe in the face of failed or partial updates. Esky is currently capable of freezing apps with bbfreeze, cxfreeze and py2exe. Support for py2app is in the works. The latest version is v0.4.0, with the following major changes: * added support for freezing with cx_Freeze. * improved support for freezing with py2exe. * added ability to set the icon on each executable (if the chosen freezer module supports it) * made Esky.cleanup() catch and ignore common errors. * added support for Python 3 (via distribute's "use_2to3" flag) * added a brief tutorial and example application * some backwards-incompatible API changes (see ChangeLog for details) Downloads: http://pypi.python.org/pypi/esky/0.4.0/ Code, bugs, etc: http://github.com/rfk/esky/ Tutorial: http://github.com/rfk/esky/tree/master/tutorial/ -- 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From rpjanaka at gmail.com Tue Feb 23 01:12:27 2010 From: rpjanaka at gmail.com (R. P. Janaka) Date: Tue, 23 Feb 2010 11:42:27 +0530 Subject: How to get memory and CPU status of a particular process In-Reply-To: References: Message-ID: Please can anyone help me..?? On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: > Hi all, > > Is there a way to get system memory consumption and CPU consumption in a > platform independent way, using python...? > > Basically my requirement is, get the memory status and CPU status of a > particular process. If there is a way to get memory info and CPU info by > just giving the process ID, that is exactly what I need to do :) > Is this possible with python..? > > -- > Regards, > R. P. Janaka > -- Regards, R. P. Janaka -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjdevnull at yahoo.com Tue Feb 23 01:27:54 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Mon, 22 Feb 2010 22:27:54 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: On Feb 22, 9:24?pm, John Nagle wrote: > sjdevn... at yahoo.com wrote: > > On Feb 20, 9:58 pm, John Nagle wrote: > >> sjdevn... at yahoo.com wrote: > >>> On Feb 18, 2:58 pm, John Nagle wrote: > >>>> ? ? Multiple processes are not the answer. ?That means loading multiple > >>>> copies of the same code into different areas of memory. ?The cache > >>>> miss rate goes up accordingly. > >>> A decent OS will use copy-on-write with forked processes, which should > >>> carry through to the cache for the code. > >> ? ? That doesn't help much if you're using the subprocess module. ?The > >> C code of the interpreter is shared, but all the code generated from > >> Python is not. > > > Of course. ?Multithreading also fails miserably if the threads all try > > to call exec() or the equivalent. > > > It works fine if you use os.fork(). > > ? ? Forking in multithreaded programs is iffy. ?What happens depends > on the platform, and it's usually not what you wanted to happen. Well, yeah. And threading in multiprocess apps is iffy. In the real world, though, multiprocessing is much more likely to result in a decent app than multithreading--and if you're not skilled at either, starting with multiprocessing is by far the smarter way to begin. Basically, multiprocessing is always hard--but it's less hard to start without shared everything. Going with the special case (sharing everything, aka threading) is by far the stupider and more complex way to approach multiprocssing. And really, for real-world apps, it's much, much more likely that fork() will be sufficient than that you'll need to explore the vagueries of a multithreaded solution. Protected memory rocks, and in real life it's probably 95% of the time where threads are only even considered if the OS can't fork() and otherwise use processes well. From sjdevnull at yahoo.com Tue Feb 23 01:31:12 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Mon, 22 Feb 2010 22:31:12 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: <51de1750-d978-4f2f-8f72-1badf9b5acca@g11g2000yqe.googlegroups.com> On Feb 22, 9:24?pm, John Nagle wrote: > sjdevn... at yahoo.com wrote: > > On Feb 20, 9:58 pm, John Nagle wrote: > >> sjdevn... at yahoo.com wrote: > >>> On Feb 18, 2:58 pm, John Nagle wrote: > >>>> ? ? Multiple processes are not the answer. ?That means loading multiple > >>>> copies of the same code into different areas of memory. ?The cache > >>>> miss rate goes up accordingly. > >>> A decent OS will use copy-on-write with forked processes, which should > >>> carry through to the cache for the code. > >> ? ? That doesn't help much if you're using the subprocess module. ?The > >> C code of the interpreter is shared, but all the code generated from > >> Python is not. > > > Of course. ?Multithreading also fails miserably if the threads all try > > to call exec() or the equivalent. > > > It works fine if you use os.fork(). > > ? ? Forking in multithreaded programs is iffy. One more thing: the above statement ("forking in multithreaded programs is iffy"), is absolutely true, but it's also completely meaningless in modern multiprocessing programs--it's like saying "gotos in structured programs are iffy". That's true, but it also has almost no bearing on decently constructed modern programs. From FearsomeDragonfly at gmail.com Tue Feb 23 01:58:38 2010 From: FearsomeDragonfly at gmail.com (Brad Harms) Date: Tue, 23 Feb 2010 06:58:38 GMT Subject: Can I make sqlite3 or shelve work reliably on any Win/Linux/Mac? References: Message-ID: On Mon, 22 Feb 2010 09:10:38 -0800, Alex Quinn wrote: > Is there a way to have some kind of database (i.e. sqlite3, bsddb, dbm, > etc.) that works out of the box on any Win/Linux/Mac machine with Python > 2.6+ or 3.x? It's okay if the file format is different between machines, > but I want my script to work without having to install anything. > > Problems with current modules: > > * Shelve used to do this. Unfortunately, since bsddb was > deprecated/removed from the standard distro and Windows doesn't have dbm > or gdbm, the only remaining option on Windows is dumbdbm, which is > discouraged in the docs. > > * Sqlite3 should fill the void now. However, in my experience, nearly > every Linux Python install I encounter has a broken sqlite3 module > ("ImportError: No module named _sqlite3"). It's a well-documented issue, > but it the solution generally requires root access, which I don't have > on these servers. > > Potential solutions: > > * Could I somehow bundle with my project the _sqlite3.so file and/or > whatever else it needs? Or is there an alternate sqlite3 module I could > use as a fallback that would just interface with the sqlite3 executable > on the machine (i.e. /usr/local/bin/sqlite3)? > > * Is there a way to drop bsddb into my project so it works out of the > gate (no install) on either Linux, Windows, or Mac? > > If you have any ideas, I'd be most appreciative. My objective here is > just to find a portable and reliable solution that I can use for small > projects. > > Thanks, > Alex Hi, I'm speaking with little experience here, but one thought I had is to try compiling Pysqlite ( http://pypi.python.org/pypi/pysqlite/2.5.6 ) for each of your target OS's, probably using GCC cross compilers for the platforms you aren't compiling on, then sort of "splice" them together so that _sqlite3 always points to the binary for the current OS. This snippet might help you get started: import sys # Linux binary if 'linux' in sys.platform.lower(): import _sqlite3_linux as _sqlite3 # Windows binary elif 'win32' == sys.platform: import _sqlite3_windows as _sqlite3 # Mac binary elif 'darwin' == sys.platform: import _sqlite3_mac as _sqlite3 sys.modules['_sqlite3'] = _sqlite3 I'm not exactly sure when you would run this code. It would have to be sometime before you import the main sqlite3 module. -- Brad Harms -- http://alphaios.net From clp2 at rebertia.com Tue Feb 23 02:03:55 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Feb 2010 23:03:55 -0800 Subject: How to get memory and CPU status of a particular process In-Reply-To: References: Message-ID: <50697b2c1002222303td62ea73n4f957dd6de7d0ecd@mail.gmail.com> > On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: >> Hi all, >> >> Is there a way to get system memory consumption and CPU consumption in a >> platform independent way, using python...? >> >> Basically my requirement is, get the memory status and CPU status of a >> particular process. If there is a way to get memory info and CPU info by >> just giving the process ID, that is exactly what I need to do :) >> Is this possible with python..? Given Turing-completeness, one should more precisely ask whether there is already a library for doing something in Python rather than whether something is possible with Python. On Mon, Feb 22, 2010 at 10:12 PM, R. P. Janaka wrote: > Please can anyone help me..?? It is generally customary to wait /at least/ one day before pinging on one's question again. If you were to have searched PyPI (http://pypi.python.org), you would have found psutil, which seems to fit your bill: http://code.google.com/p/psutil/ Cheers, Chris -- This completes today's Netiquette lesson. http://blog.rebertia.com From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 02:08:30 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Feb 2010 07:08:30 GMT Subject: Use eval() safely? References: <20100221212511.GA23046@beron.tangosoft.com> Message-ID: On Mon, 22 Feb 2010 11:45:10 -0800, Jonathan Gardner wrote: > Why would you ever run untrusted code on any machine in any language, > let alone Python? Because sometimes you have to run untrusted code, so you want to run it in a sandbox so it can't eat your machine. E.g. viewing PDF files. Or you might be building an app that allows the user to enter code and execute it: http://tryruby.org/ > If you're writing a web app, make it so that you only run trusted code. > That is, code installed by the admin, or approved by the admin. But do you trust the admin? Do you think your admin has audited the entire tool chain of every application, library and operating system module in your system? -- Steven From jedady.1 at gmail.com Tue Feb 23 02:12:28 2010 From: jedady.1 at gmail.com (Jedady) Date: Mon, 22 Feb 2010 23:12:28 -0800 (PST) Subject: Now Win a laptop computer from (EZ laptop) free of charge Message-ID: <7f1d8648-fcd0-4e26-a4ae-790e5e660e7f@s36g2000prh.googlegroups.com> All you have to do is just click on the link below and register on- site.And you'll know the rest of the steps on your own http://ezlaptop.com/?r=130329 Good luck to all From paul.nospam at rudin.co.uk Tue Feb 23 02:16:46 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Tue, 23 Feb 2010 07:16:46 +0000 Subject: How to get memory and CPU status of a particular process References: Message-ID: <87tyt81kwx.fsf@rudin.co.uk> Chris Rebert writes: >> On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: >>> Hi all, >>> >>> Is there a way to get system memory consumption and CPU consumption in a >>> platform independent way, using python...? >>> >>> Basically my requirement is, get the memory status and CPU status of a >>> particular process. If there is a way to get memory info and CPU info by >>> just giving the process ID, that is exactly what I need to do :) >>> Is this possible with python..? > > Given Turing-completeness, one should more precisely ask whether there > is already a library for doing something in Python rather than whether > something is possible with Python. Turing-completeness is irrelevant to questions like getting memory and CPU info for a process. These are not issues of computability... From clp2 at rebertia.com Tue Feb 23 02:28:01 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Mon, 22 Feb 2010 23:28:01 -0800 Subject: How to get memory and CPU status of a particular process In-Reply-To: <87tyt81kwx.fsf@rudin.co.uk> References: <87tyt81kwx.fsf@rudin.co.uk> Message-ID: <50697b2c1002222328l2a8b79e4wcdc027eaeffc883b@mail.gmail.com> On Mon, Feb 22, 2010 at 11:16 PM, Paul Rudin wrote: > Chris Rebert writes: >>> On Tue, Feb 23, 2010 at 9:18 AM, R. P. Janaka wrote: >>>> Is there a way to get system memory consumption and CPU consumption in a >>>> platform independent way, using python...? >>>> >>>> Basically my requirement is, get the memory status and CPU status of a >>>> particular process. If there is a way to get memory info and CPU info by >>>> just giving the process ID, that is exactly what I need to do :) >>>> Is this possible with python..? >> >> Given Turing-completeness, one should more precisely ask whether there >> is already a library for doing something in Python rather than whether >> something is possible with Python. > > Turing-completeness is irrelevant to questions like getting memory and > CPU info for a process. These are not issues of computability... True, but given that it is possible to access most *nix APIs from Python and win32all provides what I understand to be extensive access to the Win32 API from Python, cross-platform coding is almost always possible in Python. You might have to manually deal with each case yourself though. (More technically, I suppose that's being multi-platform with relatively easy DIY cross-platform). Cheers, Chris -- http://blog.rebertia.com From taskinoor.hasan at csebuet.org Tue Feb 23 02:30:00 2010 From: taskinoor.hasan at csebuet.org (Taskinoor Hasan) Date: Tue, 23 Feb 2010 13:30:00 +0600 Subject: How to get memory and CPU status of a particular process In-Reply-To: References: Message-ID: <79153a2e1002222330s2eeee7c3h8ee9b94126c525e3@mail.gmail.com> On Tue, Feb 23, 2010 at 9:48 AM, R. P. Janaka wrote: > Hi all, > > Is there a way to get system memory consumption and CPU consumption in a > platform independent way, using python...? > > Basically my requirement is, get the memory status and CPU status of a > particular process. If there is a way to get memory info and CPU info by > just giving the process ID, that is exactly what I need to do :) > Is this possible with python..? > I'm afraid that this is not possible in a platform independent way. In case of Windows, you can look at Tim Golden's WMI module for Python. And in case of Linux, you need to dig the details of /proc. Regards Taskinoor Hasan (Sajid) > > -- > Regards, > R. P. Janaka > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From krister.svanlund at gmail.com Tue Feb 23 03:07:43 2010 From: krister.svanlund at gmail.com (Krister Svanlund) Date: Tue, 23 Feb 2010 09:07:43 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> On Tue, Feb 23, 2010 at 1:01 AM, Edward A. Falk wrote: > You mean it's not? > > -- > ? ? ? ?-Ed Falk, falk at despams.r.us.com > ? ? ? ?http://thespamdiaries.blogspot.com/ Javas popularity was very much a product of its time. It was something new and exciting and people got a bit too excited maybe, Python just does the same thing but better really, therefor it will not become as popular. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 03:11:52 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 23 Feb 2010 08:11:52 GMT Subject: Bizarre arithmetic results References: Message-ID: On Mon, 22 Feb 2010 18:01:44 +0000, Albert van der Horst wrote: > In article , > Terrence Cole wrote: >>Can someone explain to me what python is doing here? >> >>Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) [GCC 4.3.4] on linux2 >>Type "help", "copyright", "credits" or "license" for more information. >>>>> -0.1 ** 0.1 > > Python 4.0 > Warning: misleading blank space, expected: > - 0.1**0.1 > >>-0.7943282347242815 Making spaces significant in that fashion is mind-bogglingly awful. Let's look at a language that does this: [steve at sylar ~]$ cat ws-example.rb def a(x=4) x+2 end b = 1 print (a + b), (a+b), (a+ b), (a +b), "\n" [steve at sylar ~]$ ruby ws-example.rb 7773 -- Steven From bobbo17141 at googlemail.com Tue Feb 23 03:37:13 2010 From: bobbo17141 at googlemail.com (gabi meier) Date: Tue, 23 Feb 2010 00:37:13 -0800 (PST) Subject: =?ISO-8859-1?Q?wgv_berufsunf=E4higkeitsversicherung=2C_berufsunf=E4higk?= =?ISO-8859-1?Q?eitsversicherung_testsieger=2C_berufsunf=E4higkeitsversicherung?= =?ISO-8859-1?Q?_mlp=2C_berufsunf=E4higkeitsversicherung_preis=2C_hdi_gerling_ber?= =?ISO-8859-1?Q?ufsunf=E4higkeitsversicherung=2C?= Message-ID: wgv berufsunf?higkeitsversicherung, berufsunf?higkeitsversicherung testsieger, berufsunf?higkeitsversicherung mlp, berufsunf?higkeitsversicherung preis, hdi gerling berufsunf?higkeitsversicherung, + + + HAUSRAT VERSICHERUNG +++ HAUSRATVERSICHERUNG BILLIG +++ BILLIGE HAUSRATSVERSICHERUNG + http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://WWW.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL + + + + http://berufsunfaehigkeitsversicherung-arzt.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://berufsunfaehigkeitsversicherung-test-2009.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://berufsunfaehigkeitsversicherung-neue-leben.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL http://die-beste-berufsunfaehigkeitsversicherung.BERUFSUNFAEHIGKEITSVERSICHERUNGEN.NL autoversicherungen testsieger berufsunf?higkeit in Schleswig berufsunf?higkeitsversicherung freiberufler metallrente bu in Guinea konkrete verweisbarkeit alte leipziger versicherung in Namibia steuererkl?rung versicherungen abstrakte verweisung in Schleiz berufsunf?higkeit versicherung vergleich berufsunf?hig versicherung in Homburg n?rnberger bu versicherung berufsunf?higkeit rechner in Osnabr?ck berufsunf?higkeit versicherung berufsunf?higkeitsversicherung k?ndigen in Oranienburg bu alte leipziger berufsunf?higkeits versicherung vergleich in Sachsen http://suche.aol.de/aol/search?query=berufsunf?higkeitsversicherungen+im+test+inurl%3Afor-um&invocationType=no.omittWeb&filter=false From ishwor.gurung at gmail.com Tue Feb 23 04:00:47 2010 From: ishwor.gurung at gmail.com (Ishwor Gurung) Date: Tue, 23 Feb 2010 20:00:47 +1100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <34534aed1002230100v7e06f714oca05933851d2b02c@mail.gmail.com> On 23 February 2010 08:56, AON LAZIO wrote: > That will be superb Yes it would - but I'll just add in few words. Java - Monstrous language that was Sun's flagship language. Now, it's Oracles. Python - Hobby-ish hacking language that we all love so much (that we wish everything was written using Python). Java - The JVM code been hacked to death by Sun engineers (optimised) Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. ad-infinitum but nowhere as near to JVM I like both Python and Java but given the amount of resources put into JVM and Java (JEE is _huge_ in Enterprise if you didn't know that already and there are universities that speak Java fluently), it's kind of sad that Python till the day hasn't seen speedup in mainline releases. I see Python more as a hacker's language which will gradually evolve and support SMEs and alike in the long run than Java (and of course we write our weekend-only hacking projects in it :-) but for a market-uptake like Java requires universities, colleges and students to learn this wonderful little language and requests energetic hackers to fix lock-contention issues and the like in the core implementation. Perhaps I see a light, perhaps I see nothing.. but I feel the day is coming nearer when Python would run as fast as Java/C. Only time can tell - I hope the time is right about this. -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 From processor.dev1l at gmail.com Tue Feb 23 04:24:46 2010 From: processor.dev1l at gmail.com (Processor-Dev1l) Date: Tue, 23 Feb 2010 01:24:46 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> Message-ID: On Feb 21, 10:42?am, Noam Yorav-Raphael wrote: > I'm pleased to announce DreamPie 1.0 - a new graphical interactive > Python shell! > > Some highlights: > > * Has whatever you would expect from a graphical Python shell - > attribute completion, tooltips which show how to call functions, > highlighting of matching parentheses, etc. > * Fixes a lot of IDLE nuisances - in DreamPie interrupt always works, > history recall and completion works as expected, etc. > * Results are saved in the Result History. Very good work, Noam, I am looking forward to test this with IronPython :) > * Long output is automatically folded so you can focus on what's > important. > * Jython and IronPython support makes DreamPie a great tool for > exploring Java and .NET classes. > * You can copy any amount of code and immediately execute it, and you > can also copy code you typed interactively into a new file, with the > Copy Code Only command. No tabs are used! > * Free software licensed under GPL version 3. > > Check it out athttp://dreampie.sourceforge.net/and tell me what you > think! > > Have fun, > Noam From sebastian.noack at googlemail.com Tue Feb 23 04:24:48 2010 From: sebastian.noack at googlemail.com (sebastian.noack at googlemail.com) Date: Tue, 23 Feb 2010 01:24:48 -0800 (PST) Subject: os.pipe() + os.fork() References: <20100220113604.49b7c242@gurka> <20100220125250.35c9937d@gurka> Message-ID: <256926de-e175-4fa2-aa24-dbd5f96756ef@u20g2000yqu.googlegroups.com> On Feb 20, 8:13?pm, Gary Herron wrote: > Here's a thought: ?Consider the subprocess module. ? It can do thefork > and any necessary pipes and can do so in an OS independent way. ? It > might make you life much easier. As far as i know the subprocess module provides only functionality for running any program as subprocess. But I just want to fork the current process without putting some code in an external python script. Sebastian Noack From richard.lamboj at bilcom.at Tue Feb 23 04:40:09 2010 From: richard.lamboj at bilcom.at (Richard Lamboj) Date: Tue, 23 Feb 2010 10:40:09 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> References: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> Message-ID: <201002231040.10422.richard.lamboj@bilcom.at> Am Tuesday 23 February 2010 09:07:43 schrieb Krister Svanlund: > On Tue, Feb 23, 2010 at 1:01 AM, Edward A. Falk wrote: > > You mean it's not? > > > > -- > > ? ? ? ?-Ed Falk, falk at despams.r.us.com > > ? ? ? ?http://thespamdiaries.blogspot.com/ > > Javas popularity was very much a product of its time. It was something > new and exciting and people got a bit too excited maybe, Python just > does the same thing but better really, therefor it will not become as > popular. Good morning, i don't like Java/JSP, the synthax is blown up and the programs are damn slow. For ecllipse you should buy a cluster. There is C/C++/D, Python, Ruby, Gambas, TCL, PHP, SmallTalk and some other nice Programming Languages, so i don't understand why people use Java. "Java is the one an only OOP Language, the best one" - Yeah and whats with multiple inheritance? I'am in love with Python ;-) Kind Regards From danijel.gvero at gmail.com Tue Feb 23 05:39:21 2010 From: danijel.gvero at gmail.com (DANNY) Date: Tue, 23 Feb 2010 02:39:21 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> Message-ID: <19c11c1f-d70e-4b10-b425-6e65d4c70aeb@d2g2000yqa.googlegroups.com> @James I am thinkinhg about effect of errors that are within the sequence of P frames. Where the P frames have only the information about the changes in previous frames, so that errors are present until the next I frame. So I would like to see how is this seen in different GoP sized clips. @Tim Thanks for the advice, now I will try to do that so I have a lot of work in front of me. I will post any problems if they occure. Guys thank you again for the help! From hackingkk at gmail.com Tue Feb 23 05:53:57 2010 From: hackingkk at gmail.com (hackingKK) Date: Tue, 23 Feb 2010 16:23:57 +0530 Subject: When will Python go mainstream like Java? In-Reply-To: <201002231040.10422.richard.lamboj@bilcom.at> References: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> <201002231040.10422.richard.lamboj@bilcom.at> Message-ID: <4B83B3C5.5020502@gmail.com> On Tuesday 23 February 2010 03:10 PM, Richard Lamboj wrote: > Am Tuesday 23 February 2010 09:07:43 schrieb Krister Svanlund: > >> On Tue, Feb 23, 2010 at 1:01 AM, Edward A. Falk >> > wrote: > >>> You mean it's not? >>> >>> -- >>> -Ed Falk, falk at despams.r.us.com >>> http://thespamdiaries.blogspot.com/ >>> >> Javas popularity was very much a product of its time. It was something >> new and exciting and people got a bit too excited maybe, Python just >> does the same thing but better really, therefor it will not become as >> popular. >> > Good morning, > > i don't like Java/JSP, the synthax is blown up and the programs are damn slow. > For ecllipse you should buy a cluster. There is C/C++/D, Python, Ruby, > Gambas, TCL, PHP, SmallTalk and some other nice Programming Languages, so i > don't understand why people use Java. "Java is the one an only OOP Language, > the best one" - Yeah and whats with multiple inheritance? I'am in love with > Python ;-) > There are a few reasons why we don't see python as a "buz word". Java was well marketed and the time when it came out with libraries like swing, there was no popularly known alternative. As a matter of fact I don't really go by popularity with technologies, specially when it comes to programming languages. Just show me 2 or 3 big apps or web sites which are scalable and take multiple requests. show me just 2 instances where heavy number crunching is done efficiently and I am convinced. I don't care how many apps are developed using java as long as they remain heavy and sloooooooow. google runs on python and so do many other big applications. marketing is more about exaggeration, which Sun did for Java. Python was always in the hands of programmers who wanted their work done and wanted scalable apps. So the conclusion is that "all that is popular need not be good for every thing ". Happy hacking. Krishnakant. From peloko45 at gmail.com Tue Feb 23 05:54:25 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 23 Feb 2010 02:54:25 -0800 (PST) Subject: Fascism is coming to Internet Message-ID: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> *Sorry by this message off topic, but this is too important* Fascism is coming fastly to Internet because is the only communication way that governements (managed by the bank and multinationals) cann't control http://www.boingboing.net/2010/02/21/acta-internet-enforc.html From stefan_ml at behnel.de Tue Feb 23 05:56:39 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 23 Feb 2010 11:56:39 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: Chris Rebert, 23.02.2010 06:45: > Indeed. Python is at position 7, just behind C#, in the TIOBE Index: > http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html That index is clearly flawed. A language like PHP (whatever that is supposed to be comparable with) can't possibly be on the rise, can it? Stefan From darcy at druid.net Tue Feb 23 06:33:40 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 06:33:40 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <20100223063340.c891740a.darcy@druid.net> On Tue, 23 Feb 2010 02:54:25 -0800 (PST) Joan Miller wrote: > *Sorry by this message off topic, but this is too important* Is it just me or has the spew from gmail on this list radically increased in the last week? Anyone else considering blocking all gmail posts to this list? -- 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 generalcody at gmail.com Tue Feb 23 06:50:15 2010 From: generalcody at gmail.com (General Cody) Date: Tue, 23 Feb 2010 12:50:15 +0100 Subject: Combining C and Python programs References: Message-ID: <2010022312501516807-generalcody@gmailcom> Well... This is really a RTFM question. It's all in the Python docs... And it's really simple. From aharrisreid at googlemail.com Tue Feb 23 06:56:21 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Tue, 23 Feb 2010 11:56:21 +0000 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> Message-ID: <4B83C265.2090802@googlemail.com> gorauskas wrote: > I installed it on a Windows 7 machine with CPython 2.6.4 and I get the > following error: > > Traceback (most recent call last): > File "dreampie.py", line 3, in > File "dreampielib\gui\__init__.pyc", line 73, in > File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk > ImportError: DLL load failed: The specified module could not be found. > > What am I doing wrong? > > Thanks, JGG And I installed it on WinXP sp3 and Python 3.1 - when launched a window flashes before my eyes, then disappears! Has the installation package been checked for all common Windows versions? Regards, Alan From noamraph at gmail.com Tue Feb 23 07:11:07 2010 From: noamraph at gmail.com (Noam Yorav-Raphael) Date: Tue, 23 Feb 2010 14:11:07 +0200 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: ?Thanks! I'm happy you like it! Thanks for the feedback too. Here are my replies. On Sun, Feb 21, 2010 at 7:13 PM, Chris Colbert wrote: > This is bloody fantastic! I must say, this fixes everything I hate about > Ipython and gives me the feature I wished it had (with a few minor > exceptions). > I confirm this working on Kubuntu 9.10 using the ppa listed on the sites > download page. Great. It's important to know. > I also confirm that it works interactively with PyQt4 and PyGtk (as to be > expected since these toolkits use the PyOS_inputhook for the mainloop). > However, it does not work interactively with wx (again, this is as expected > since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support > is the same as in Ipython if you dont use any of the magic threading > switches, which are now?deprecated?anyway. Actually, currently DreamPie doesn't use PyOS_inputhook, but implements the GUI hooks by itself. So it should be possible to implement wx support if there's a way to handle events for a few milliseconds. I tried it a bit and didn't find how to do it - if you are interested in wx support and think you can help, please do. > Matplotlib does not work interactively for me. Is there a special switch > that needs to be used? or should a pick a non-wx backend? (i'm thinking the > latter is more likely) You should set "interactive:True" in your matplotlibrc file. The next DreamPie version will warn about this. > A couple of things I would like to see (and will help implement if I can > find the time): > 1) A shortcut to show the docstring of an object. Something like Ipython's > `?`. i.e. ?`object.foo?` translates to `help(object.foo)` I wrote this at http://wiki.python.org/moin/DreamPieFeatureRequests . I hope I will manage to implement this soon. > 2) How do I change the color of the blinking cursor at the bottom? I can't > see the damn thing! It should be in the color of the default text. If this is not the case, please file a bug! > 3) line numbers instead of the `>>>` prompt I know IPython does this, but I thought you needed it only if placing the cursor on top of the command doesn't do anything. Can you tell me why do you need this in the context of a graphical user interface? > 4) a plugin facility where we can define our own `magic` commands. I use > Ipython's %timeit ALL the time. Added it to the feature request page. > 5) Double-click to re-fold the output section as well. I don't think that's a good idea, because usually double-click selects the word, and I don't want to change that behavior for regular text. You can use ctrl-minus to fold the last output section! > Thanks for making this!!!! Thanks for the feedback! Noam From rdv at roalddevries.nl Tue Feb 23 07:48:51 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Tue, 23 Feb 2010 13:48:51 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: On Feb 22, 2010, at 10:56 PM, AON LAZIO wrote: > That will be superb I guess static typing will have to be added, so that tools like eclipse can inspect (and autocomplete) your programs [better]. From jeanmichel at sequans.com Tue Feb 23 07:50:15 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 23 Feb 2010 13:50:15 +0100 Subject: Avoid converting functions to methods in a class In-Reply-To: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: <4B83CF07.5000009@sequans.com> Steven D'Aprano wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. > > Are there any better solutions? > > > It looks like it works when declaring foo as static: import unittest def foo(a,b): return 'fooo' class AnotherTest(unittest.TestCase): target = staticmethod(foo) def test_foo(self): self.assertEquals(self.target('a', 'b'), 'foo') def runTest(self): self.test_foo() AnotherTest().runTest() ...AssertionError: 'fooo' != 'foo' JM From wolftracks at invalid.com Tue Feb 23 08:03:26 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 05:03:26 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 Message-ID: In the last day, I posted a message titled "What's Going on between Python and win7?" I'd appreciate it if someone could verify my claim. A sample program to do this is below. I'm using IDLE in Win7 with Py 2.5. My claim is that if one creates a program in a folder that reads a file in the folder it and then copies it to another folder, it will read the data file in the first folder, and not a changed file in the new folder. I'd appreciate it if some w7 users could try this, and let me know what they find. My experience is that if one checks the properties of the copied file, it will point to the original py file and execute it and not the copy. # Test program. Examine strange link in Python under Win7 # when copying py file to another folder. # Call the program vefifywin7.py # To verify my situation use IDLE, save and run this program there. # Put this program into a folder along with a data file # called verify.txt. Create a single text line with a few characters in it # Run this program and note if the output # Copy the program and txt file to another folder # Change the contents of the txt file # Run it again, and see if the output is the same as in the other folder track_file = open("verify.txt") aline = track_file.readline(); print aline track_file.close() From olof.bjarnason at gmail.com Tue Feb 23 08:25:07 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Tue, 23 Feb 2010 14:25:07 +0100 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <7f014ea61002210913p237adec3le0618bc899bd3f9a@mail.gmail.com> Message-ID: 2010/2/23 Noam Yorav-Raphael : > ?Thanks! I'm happy you like it! > Thanks for the feedback too. Here are my replies. > > On Sun, Feb 21, 2010 at 7:13 PM, Chris Colbert wrote: >> This is bloody fantastic! I must say, this fixes everything I hate about >> Ipython and gives me the feature I wished it had (with a few minor >> exceptions). >> I confirm this working on Kubuntu 9.10 using the ppa listed on the sites >> download page. > Great. It's important to know. > >> I also confirm that it works interactively with PyQt4 and PyGtk (as to be >> expected since these toolkits use the PyOS_inputhook for the mainloop). >> However, it does not work interactively with wx (again, this is as expected >> since wx doesn't use the PyOS_inputhook). In short, the gui toolkit support >> is the same as in Ipython if you dont use any of the magic threading >> switches, which are now?deprecated?anyway. > Actually, currently DreamPie doesn't use PyOS_inputhook, but > implements the GUI hooks by itself. So it should be possible to > implement wx support if there's a way to handle events for a few > milliseconds. I tried it a bit and didn't find how to do it - if you > are interested in wx support and think you can help, please do. > >> Matplotlib does not work interactively for me. Is there a special switch >> that needs to be used? or should a pick a non-wx backend? (i'm thinking the >> latter is more likely) > You should set "interactive:True" in your matplotlibrc file. The next > DreamPie version will warn about this. > >> A couple of things I would like to see (and will help implement if I can >> find the time): >> 1) A shortcut to show the docstring of an object. Something like Ipython's >> `?`. i.e. ?`object.foo?` translates to `help(object.foo)` > I wrote this at http://wiki.python.org/moin/DreamPieFeatureRequests . > I hope I will manage to implement this soon. > >> 2) How do I change the color of the blinking cursor at the bottom? I can't >> see the damn thing! > It should be in the color of the default text. If this is not the > case, please file a bug! > >> 3) line numbers instead of the `>>>` prompt > I know IPython does this, but I thought you needed it only if placing > the cursor on top of the command doesn't do anything. Can you tell me > why do you need this in the context of a graphical user interface? > >> 4) a plugin facility where we can define our own `magic` commands. I use >> Ipython's %timeit ALL the time. > Added it to the feature request page. > >> 5) Double-click to re-fold the output section as well. > I don't think that's a good idea, because usually double-click selects > the word, and I don't want to change that behavior for regular text. > You can use ctrl-minus to fold the last output section! > >> Thanks for making this!!!! > Thanks for the feedback! I installed latest .exe from LP on my Win7/32-bit machine, nothing happens when I start DreamPie. Is there a bug report file somewhere I could send you Noam? (Python2.6.4 installed on my machine) > > Noam > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://olofb.wordpress.com From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 23 08:46:30 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 23 Feb 2010 14:46:30 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: <2cf430a61002230007j120ee439pb99c9b6bd6123b5@mail.gmail.com> <201002231040.10422.richard.lamboj@bilcom.at> Message-ID: <4b83dc2f$0$10229$426a34cc@news.free.fr> hackingKK a ?crit : (snip) > I don't care how many apps are developed using java as long as they > remain heavy and sloooooooow. > google runs on python Please get your facts right. Python is one of the languages used internally at Google, true, but so is Java. And google-the-search-engine does not "run on python". From bruno.42.desthuilliers at websiteburo.invalid Tue Feb 23 08:47:11 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Tue, 23 Feb 2010 14:47:11 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <4b83dc57$0$10229$426a34cc@news.free.fr> Roald de Vries a ?crit : > On Feb 22, 2010, at 10:56 PM, AON LAZIO wrote: >> That will be superb > > I guess static typing will have to be added, so that tools like eclipse > can inspect (and autocomplete) your programs [better]. Yet another troll... From dickinsm at gmail.com Tue Feb 23 08:48:09 2010 From: dickinsm at gmail.com (Mark Dickinson) Date: Tue, 23 Feb 2010 05:48:09 -0800 (PST) Subject: Bizarre arithmetic results References: Message-ID: <3fb9d59b-21c2-4372-9a32-c542e884faa7@x9g2000vbo.googlegroups.com> On Feb 23, 8:11?am, Steven D'Aprano wrote: > Making spaces significant in that fashion is mind-bogglingly awful. Let's > look at a language that does this: > > [steve at sylar ~]$ cat ws-example.rb > def a(x=4) > ? ? x+2 > end > > b = 1 > print (a + b), (a+b), (a+ b), (a +b), "\n" > > [steve at sylar ~]$ ruby ws-example.rb > 7773 Hmm. That's pretty nasty, all right. Not that Python can claim to be immune to such behaviour: >>> 3 .real 3 >>> 3. real File "", line 1 3. real ^ SyntaxError: invalid syntax Though the fact that one of the cases raises an exception (rather than silently giving some different behaviour) ameliorates things a bit. -- Mark From edreamleo at gmail.com Tue Feb 23 08:53:44 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Tue, 23 Feb 2010 07:53:44 -0600 Subject: ANN: Leo 4.7 final released Message-ID: Leo 4.7 final February 23, 2009 Leo 4.7 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7 final fixes all known bugs in Leo. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - Leo creates a 'Recovered Nodes' node to hold data that otherwise might be lost due to clone conflicts. - @auto-rst now works much more reliably reliably. - Leo no longer supports @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From thom1948 at gmail.com Tue Feb 23 09:21:50 2010 From: thom1948 at gmail.com (Thomas) Date: Tue, 23 Feb 2010 06:21:50 -0800 (PST) Subject: How to transmit a crash report ? References: <4B8336EE.9040802@gmail.com> Message-ID: <0b222aec-db04-45b7-9f86-e2839ffafc40@j1g2000vbl.googlegroups.com> On Feb 22, 9:27?pm, MRAB wrote: > Stef Mientki wrote: > > hello, > > > in my python desktop applications, > > I'ld like to implement a crash reporter. > > By redirecting the sys.excepthook, > > I can detect a crash and collect the necessary data. > > Now I want that my users sends this information to me, > > and I can't find a good way of doing this. > > > The following solutions came into my mind: > > (most of my users are on Windows, and the programs are written in Python > > 2.6) > > > 1. mailto: > > doesn't work if the the user didn't install a default email client, > > or if the user uses a portable email client (that isn't started yet) > > Besides this limits the messages to small amounts of data. > > > 2.other mail options: smtp > > AFAIK such a solution needs smtp authorization, and therefor I've to put > > my username and password in the desktop application. > > Try reading the documentation for Python's smtplib module. > > You don't need to provide any password. > > > > > 3. http-post > > Although post is also limited in size, > > I could store information in cookies (don't know yet how), and cookies > > are sent parallel to the post message. > > On the server site I can use a small php script, that stores the > > post-data, cookies and/or send's a (long) email. > > > are there better options ?- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text - Try http://code.activestate.com/recipes/442459/ From malaclypse2 at gmail.com Tue Feb 23 09:34:00 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 23 Feb 2010 09:34:00 -0500 Subject: What's Going on between Python and win7? In-Reply-To: References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <16651e81002230634t6d2d0679pe9d1ac028164cc1c@mail.gmail.com> On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson wrote: > So what's the bottom line? This link notion is completely at odds with XP, > and produces what I would call something of a mess to the unwary Python/W7 > user. Is there a simple solution? I know people went off on a tangent talking about symbolic links and hard links, but it is extremely unlikely that you created something like that by accident. Windows just doesn't create those without you doing quite a bit of extra work. It certainly doesn't create them when you drag & drop files around through the normal interface. > How do I get out of this pickle? I just want to duplicate the ?program in > another folder, and not link to an ancestor. You need to dig into the technical details of what's happening on your hard drive. You say you "copied a program from folder A to folder B". Can you describe, exactly, what steps you took? What was the file name of the program? Was it just one file, or a directory, or several files? What was the path to directory A? What is the the path to directory B? When you open a CMD window and do a dir of each directory, what exactly do you see? You've given a pretty non-technical description of the problem you're experiencing. If you want more than wild speculation, you'll need to give more specifics for people to help you with. My wild guess: you held down control and shift while copying your program. That's the keyboard command to create a shortcut instead of moving or copying a file. -- Jerry From mrkafk at gmail.com Tue Feb 23 09:36:02 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 15:36:02 +0100 Subject: Is this secure? Message-ID: Hello, I need to generate passwords and I think that pseudo-random generator is not good enough, frankly. So I wrote this function: import struct def gen_rand_string(): fileobj = open('/dev/urandom','rb') rstr = fileobj.read(4) rnum = struct.unpack('L',rstr)[0] rstr = '%i' % rnum rnuml = [] while len(rstr) >= 2: c = rstr[:2] try: num = int(c) rnuml.append(num) except ValueError: pass rstr = rstr[2:] rnuml = map(lambda x: 97+x/4, rnuml) rnumc = map(chr, rnuml) return ''.join(rnumc) if __name__ == "__main__": print gen_rand_string() (yes I know that this way generated string will not contain 'z' because 99/4 + 97 = 121 which is 'y') The question is: is this secure? That is, can the string generated this way be considered truly random? (I abstract from not-quite-perfect nature of /dev/urandom at the moment; I can always switch to /dev/random which is better) Regards, mk From mrkafk at gmail.com Tue Feb 23 09:49:12 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 15:49:12 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: AON LAZIO wrote: > That will be superb Well I for one wouldn't want Python to go exactly Java way, see this: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=java&l=uk This is the percentage of job offers in UK where the keyword "Java" appears. Same for C#, it looks like C# is eating Java's lunch now: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csharp&l=uk What worries me somewhat (although not much) is that after long period of solid growth the market can't decide about Python: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=python&l=uk I learned painfully that in corporate setting merits of a programming language do not matter much, it's more like "whatever catches the groupthink" at the moment. "Java is good because big ones select Java", "static typing is good because compiler catches programmer's errors" (this one is particularly appealing to managers I found), etc. Although all my "internal use" tools are written in Python, there's no way I could convince managers to use Python as the main application devel language. This, however, is not of itself a problem: as long as language is lively and has at least a few percent of programmers using it -- which is important for existence of libraries, not much more -- there's no problem for people who want to get ahead of competition / waste less time by using advanced programming langauges. Frankly, I have yet to encounter a problem for which either a sizable Python extension or bindings to a popular library wouldn't exist. This in itself is a hallmark of a language being "enough of mainstream to actually matter in practice". This I find quite insightful: http://www.paulgraham.com/avg.html Regards, mk From mrkafk at gmail.com Tue Feb 23 09:51:42 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 15:51:42 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: Stefan Behnel wrote: > Chris Rebert, 23.02.2010 06:45: >> Indeed. Python is at position 7, just behind C#, in the TIOBE Index: >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? Well it looks like it is at least stabilized: http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=php&l=uk I find job offers to be rather good index of the extent to which the language is actually used, and this is what this index is based on (percentage of job offers with the keyword "php" in them). Regards, mk From anh.hai.trinh at gmail.com Tue Feb 23 09:59:40 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Tue, 23 Feb 2010 06:59:40 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <2fdedc76-140b-4773-a208-689a088ebb3d@l12g2000prg.googlegroups.com> <4b7f8c4d$1@dnews.tpgi.com.au> <87mxz2v47t.fsf@castleamber.com> <87iq9pt3l5.fsf@castleamber.com> <7xy6iky207.fsf@ruckus.brouhaha.com> Message-ID: On Feb 23, 1:03?pm, "Alf P. Steinbach" wrote: > > Uhm, Paganini... > > As I understand it he invented the "destroy your instruments on stage". :-) > > Cheers, > > - Alf (off-topic) You probably meant Franz Liszt, who regularly broke piano strings. Paganini was also a "rock-star" virtuoso but he did not destroy any Guarnerius or Stradivarius violins in his possession (at least not to anyone's knowledge :) As for functional programming, different people take it to mean different things. For some, simply using first-class functions qualifies as functional programming. Others require their functions to be pure so that their call graphs can be automatically reduced and their results can be lazily evaluated. If you takes the former view, most Python programmers already do functional programming :p --aht From mrkafk at gmail.com Tue Feb 23 10:00:18 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 16:00:18 +0100 Subject: Writing an assembler in Python In-Reply-To: References: Message-ID: Giorgos Tzampanakis wrote: > I'm implementing a CPU that will run on an FPGA. I want to have a > (dead) simple assembler that will generate the machine code for > me. I want to use Python for that. Are there any libraries that > can help me with the parsing of the assembly code? I'm not sure about your field of application (never done anything like that), but I found pyparsing highly usable. Regards, mk From sccolbert at gmail.com Tue Feb 23 10:06:31 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 23 Feb 2010 10:06:31 -0500 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <4B83C265.2090802@googlemail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> <4B83C265.2090802@googlemail.com> Message-ID: <7f014ea61002230706i29a9816eu8eb75369a2025b92@mail.gmail.com> Do you have gtk and PyGTK installed? Sounds like a missing dependency to me. On Tue, Feb 23, 2010 at 6:56 AM, Alan Harris-Reid < aharrisreid at googlemail.com> wrote: > gorauskas wrote: > >> I installed it on a Windows 7 machine with CPython 2.6.4 and I get the >> following error: >> >> Traceback (most recent call last): >> File "dreampie.py", line 3, in >> File "dreampielib\gui\__init__.pyc", line 73, in >> File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk >> ImportError: DLL load failed: The specified module could not be found. >> >> What am I doing wrong? >> >> Thanks, JGG >> > And I installed it on WinXP sp3 and Python 3.1 - when launched a window > flashes before my eyes, then disappears! Has the installation package been > checked for all common Windows versions? > > Regards, > Alan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.hellwig at dcuktec.org Tue Feb 23 10:10:50 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Tue, 23 Feb 2010 15:10:50 +0000 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: Actually I am still waiting for Java to be mainstream :-) You could say it is popular, which it is without doubt but in my opinion after C handed over it's pseudo de facto standard (mostly because a lot of OS'es are written in it) nobody else has had enough momenta to reach for that crown. Actually I quite like the soup of languages these days, what amuses me though, that Python seems to emerge as the de facto glue language to bind them all :-) -- mph From anh.hai.trinh at gmail.com Tue Feb 23 10:14:16 2010 From: anh.hai.trinh at gmail.com (Anh Hai Trinh) Date: Tue, 23 Feb 2010 07:14:16 -0800 (PST) Subject: Writing an assembler in Python References: Message-ID: On Feb 23, 10:08?am, Lawrence D'Oliveiro wrote: > > Let me suggest an alternative approach: use Python itself as the assembler. > Call routines in your library to output the code. That way you have a > language more powerful than any assembler. > > See for an example. SyntaxError: Non-matching "#end if" in crosscode8.py:345 From invalid at invalid.invalid Tue Feb 23 10:29:44 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 23 Feb 2010 15:29:44 +0000 (UTC) Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: On 2010-02-23, D'Arcy J.M. Cain wrote: > On Tue, 23 Feb 2010 02:54:25 -0800 (PST) > Joan Miller wrote: >> *Sorry by this message off topic, but this is too important* > > Is it just me or has the spew from gmail on this list radically > increased in the last week? Anyone else considering blocking all gmail > posts to this list? I did that a long time ago for all of the Usenet groups I read and all but one of the mailing lists I read. -- Grant Edwards grante Yow! I'm wearing PAMPERS!! at visi.com From invalid at invalid.invalid Tue Feb 23 10:31:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 23 Feb 2010 15:31:12 +0000 (UTC) Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: On 2010-02-23, Grant Edwards wrote: > On 2010-02-23, D'Arcy J.M. Cain wrote: >> On Tue, 23 Feb 2010 02:54:25 -0800 (PST) >> Joan Miller wrote: >>> *Sorry by this message off topic, but this is too important* >> >> Is it just me or has the spew from gmail on this list radically >> increased in the last week? Anyone else considering blocking all gmail >> posts to this list? > > I did that a long time ago for all of the Usenet groups I read > and all but one of the mailing lists I read. Wait, I misread the posting. I block everything from google.groups, not everything from gmail. -- Grant Edwards grante Yow! I have accepted at Provolone into my life! visi.com From mrkafk at gmail.com Tue Feb 23 10:38:28 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 16:38:28 +0100 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> Message-ID: sjdevnull at yahoo.com wrote: > On Feb 20, 9:58 pm, John Nagle wrote: >> sjdevn... at yahoo.com wrote: >>> On Feb 18, 2:58 pm, John Nagle wrote: >>>> Multiple processes are not the answer. That means loading multiple >>>> copies of the same code into different areas of memory. The cache >>>> miss rate goes up accordingly. >>> A decent OS will use copy-on-write with forked processes, which should >>> carry through to the cache for the code. >> That doesn't help much if you're using the subprocess module. The >> C code of the interpreter is shared, but all the code generated from >> Python is not. > Of course. Multithreading also fails miserably if the threads all try > to call exec() or the equivalent. > It works fine if you use os.fork(). What about just using subprocess module to run system commands in worker threads? Is this likely to have problems? Regards, mk From fetchinson at googlemail.com Tue Feb 23 10:39:11 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 23 Feb 2010 16:39:11 +0100 Subject: Avoid converting functions to methods in a class In-Reply-To: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> References: <4b7f5824$0$8819$c3e8da3@news.astraweb.com> Message-ID: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): > target = mymodule.someclass > > def test_spam(self): > """Test that someclass has a spam attribute.""" > self.failUnless(hasattr(self.target, 'spam')) > > > It works well until I write a test for stand-alone functions: > > class AnotherTest(unittest.TestCase): > target = mymodule.function > > def test_foo(self): > self.assertEquals(self.target('a', 'b'), 'foo') > > The problem is that target is turned into a method of my test class, not > a standalone function, and I get errors like: > > TypeError: function() takes exactly 2 arguments (3 given) > > The solution I currently use is to drop the target attribute in this > class, and just refer to mymodule.function in each individual test. I > don't like this solution because it violates Once And Only Once: if the > function changes name, I have to make many edits to the test suite rather > than just one. Isn't staticmethod the trick you need? HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From aharrisreid at googlemail.com Tue Feb 23 10:39:44 2010 From: aharrisreid at googlemail.com (Alan Harris-Reid) Date: Tue, 23 Feb 2010 15:39:44 +0000 Subject: DreamPie - The Python shell you've always dreamed about! In-Reply-To: <7f014ea61002230706i29a9816eu8eb75369a2025b92@mail.gmail.com> References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <1053124a-8ceb-4804-a7e5-9433acd3f02d@f17g2000prh.googlegroups.com> <4B83C265.2090802@googlemail.com> <7f014ea61002230706i29a9816eu8eb75369a2025b92@mail.gmail.com> Message-ID: <4B83F6C0.9010807@googlemail.com> Chris Colbert wrote: > Do you have gtk and PyGTK installed? Sounds like a missing dependency > to me. > > On Tue, Feb 23, 2010 at 6:56 AM, Alan Harris-Reid > > wrote: > > gorauskas wrote: > > I installed it on a Windows 7 machine with CPython 2.6.4 and I > get the > following error: > > Traceback (most recent call last): > File "dreampie.py", line 3, in > File "dreampielib\gui\__init__.pyc", line 73, in > File "dreampielib\gui\load_pygtk.pyc", line 49, in load_pygtk > ImportError: DLL load failed: The specified module could not > be found. > > What am I doing wrong? > > Thanks, JGG > > And I installed it on WinXP sp3 and Python 3.1 - when launched a > window flashes before my eyes, then disappears! Has the > installation package been checked for all common Windows versions? > > Regards, > Alan > > -- > http://mail.python.org/mailman/listinfo/python-list > > Hi Chris, thanks for the reply, That explains it. No, I don't have gtk installed - I wasn't aware of that dependency. Regards, Alan -------------- next part -------------- An HTML attachment was scrubbed... URL: From wolftracks at invalid.com Tue Feb 23 10:49:07 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 07:49:07 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA Message-ID: Anyone here going to the meeting,Subject? As far as I can tell, it meets from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to be an informal group dinner at 6 pm at some place yet unknown. Comments? From mrkafk at gmail.com Tue Feb 23 10:59:22 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 16:59:22 +0100 Subject: AKKA vs Python Message-ID: Hello everyone, Is there smth like AKKA in Python? http://akkasource.org/ Regards, mk From darcy at druid.net Tue Feb 23 11:09:54 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 11:09:54 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <20100223110954.5da3d679.darcy@druid.net> On Tue, 23 Feb 2010 15:31:12 +0000 (UTC) Grant Edwards wrote: > >> Is it just me or has the spew from gmail on this list radically > >> increased in the last week? Anyone else considering blocking all gmail > >> posts to this list? > > > > I did that a long time ago for all of the Usenet groups I read > > and all but one of the mailing lists I read. > > Wait, I misread the posting. I block everything from > google.groups, not everything from gmail. Yes, I did that a long time ago as well. But now there seems to be more and more actual spam coming from gmail.com itself. It may just be a minor blip on the spam graph but I'm keeping my eye on it. Most mailing lists that I am on are pretty good at filtering spam before it gets to the list. The only spam I ever see on my NetBSD lists are the ones that I moderate and I block them before anyone else sees them. A little more pain for me in return for a lot less pain for everyone else. I guess that's not possible on a list that is gatewayed to UseNet like this one is. Hmm. I wonder if all the spam is coming from the NG side. I'll have to look at that. One of the reasons that I stopped reading UseNet over ten years ago was because of the diminishinig S/N ratio. I have always felt that it was a mistake to gateway this group. -- 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 clp2 at rebertia.com Tue Feb 23 11:18:07 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Tue, 23 Feb 2010 08:18:07 -0800 Subject: AKKA vs Python In-Reply-To: References: Message-ID: <50697b2c1002230818t708262f1v3b63eebf12684d67@mail.gmail.com> On Tue, Feb 23, 2010 at 7:59 AM, mk wrote: > Hello everyone, > > Is there smth like AKKA in Python? > > http://akkasource.org/ Minus the "distributed" part, yes; there are a few implementations of actors for Python: http://www.doc.ic.ac.uk/~jwa/stage/ http://osl.cs.uiuc.edu/parley/ http://candygram.sourceforge.net/candygram.html It's a variant on the vanilla actor model, but I've heard good buzz about: http://www.kamaelia.org/ (Unless it wasn't already clear, I haven't used any of these myself.) Cheers, Chris -- http://blog.rebertia.com From rpdooling at gmail.com Tue Feb 23 11:26:18 2010 From: rpdooling at gmail.com (Rick Dooling) Date: Tue, 23 Feb 2010 08:26:18 -0800 (PST) Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: Message-ID: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> No telling what Windows will do. :) I am a mere hobbyist programmer, but I think real programmers will tell you that it is a bad habit to use relative paths. Use absolute paths instead and remove all doubt. http://docs.python.org/library/os.path.html RD From robert.kern at gmail.com Tue Feb 23 11:27:49 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 10:27:49 -0600 Subject: Writing an assembler in Python In-Reply-To: <166845.21850.qm@web58906.mail.re1.yahoo.com> References: <166845.21850.qm@web58906.mail.re1.yahoo.com> Message-ID: On 2010-02-22 21:47 PM, Ed Keith wrote: >> Subject: Re: Writing an assembler in Python >> Giorgos >> Tzampanakis wrote: >> >>> I'm implementing a CPU that will run on an FPGA. I >> want to have a >>> (dead) simple assembler that will generate the machine >> code for >>> me. >> >> Let me suggest an alternative approach: use Python itself >> as the assembler. >> Call routines in your library to output the code. That way >> you have a >> language more powerful than any assembler. >> >> See for >> an example. >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > Not a bad idea, has anyone tried this for x86 machine code? http://www.corepy.org/ -- 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 ssteinerx at gmail.com Tue Feb 23 11:30:39 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 23 Feb 2010 11:30:39 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: <0C0B45B8-BF31-4759-B2AE-C443D065FC17@gmail.com> On Feb 23, 2010, at 10:10 AM, Martin P. Hellwig wrote: > Actually I am still waiting for Java to be mainstream :-) > You could say it is popular, which it is without doubt but in my opinion after C handed over it's pseudo de facto standard (mostly because a lot of OS'es are written in it) nobody else has had enough momenta to reach for that crown. > > Actually I quite like the soup of languages these days, what amuses me though, that Python seems to emerge as the de facto glue language to bind them all :-) I'm sure there's a Tolkien 1-liner in there somewhere ;-). S From victorsubervi at gmail.com Tue Feb 23 11:47:18 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Tue, 23 Feb 2010 12:47:18 -0400 Subject: SMTPServerDisconnected Message-ID: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> Hi; I think the last main thing I have to do on my server is get a running email server up. Now that I've nuked sendmail and given up on postfix, I'm back to trying to get qmail up and running again. Of course, there are no active discussion lists for *any* email server, so I have to turn here for help. While running a script that worked perfectly well on another server to send an email, I get the following error: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py 52 53 ''' 54 my_mail() 55 print ''' 56 my_mail = /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() 33 to_address = ourEmail1, 34 subject = subject, 35 message = message 36 ).send() 37 Email( message = 'Name: beno -\nMessage: test' /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in send(self=) 344 smtp = smtplib.SMTP() 345 if self.smtp_server: 346 smtp.connect(self.smtp_server) 347 else: 348 smtp.connect() smtp = , smtp.connect = >, self = , self.smtp_server = 'localhost' /usr/lib64/python2.4/smtplib.py in connect(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code undefined, msg = 'getaddrinfo returns an empty list', self = , self.getreply = > /usr/lib64/python2.4/smtplib.py in getreply(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) global SMTPServerDisconnected = SMTPServerDisconnected: Connection unexpectedly closed args = ('Connection unexpectedly closed',) I cannot find the qmail logs. I assumed they'd be in either /var/qmail/supervise/qmail-send or /var/qmail/supervise/qmail-smtpd but I find no logs there. [SSH] Protocol Version 2 (OpenSSH_4.3) [SSH] Cipher: aes128-cbc Logged in (password) Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 [beno at 13gems ~]$ su Password: [root at 13gems beno]# man netstat [root at 13gems beno]# netstat Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State getnameinfo failed tcp 0 268 nrelectric.com:ssh [UNKNOWN]:61912 ESTABLISHED Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 7 [ ] DGRAM 10842 /dev/log unix 2 [ ] DGRAM 10370 @/org/kernel/udev/udevd unix 2 [ ] DGRAM 6077731 unix 3 [ ] STREAM CONNECTED 6077679 unix 3 [ ] STREAM CONNECTED 6077678 unix 2 [ ] DGRAM 6077675 unix 2 [ ] DGRAM 11556 unix 2 [ ] DGRAM 11511 unix 2 [ ] DGRAM 10990 [root at 13gems beno]# How do I trouble-shoot this? TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.91ahesh at gmail.com Tue Feb 23 13:04:13 2010 From: m.91ahesh at gmail.com (ranga...............) Date: Tue, 23 Feb 2010 10:04:13 -0800 (PST) Subject: Free check of $253 with your name. Message-ID: <0e5a7c60-e3da-4f74-8549-cc5885d1f309@g8g2000pri.googlegroups.com> Just open below site and select any one of the four red color links present below sponsors and enter your payename and address where to get your check. The secret link is http://highpayingkeywordsofadsense.blogspot.com/2010/01/google-yahoo-msn-adsense-high-paying_29.html From wolftracks at invalid.com Tue Feb 23 13:12:22 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 10:12:22 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 In-Reply-To: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: On 2/23/2010 8:26 AM, Rick Dooling wrote: > No telling what Windows will do. :) > > I am a mere hobbyist programmer, but I think real programmers will > tell you that it is a bad habit to use relative paths. Use absolute > paths instead and remove all doubt. > > http://docs.python.org/library/os.path.html > > RD You may be right. The actual 300 line program just reads the folder without specifying any path. I'm not that familiar with os path, but have seen it used. From peloko45 at gmail.com Tue Feb 23 13:14:38 2010 From: peloko45 at gmail.com (Joan Miller) Date: Tue, 23 Feb 2010 10:14:38 -0800 (PST) Subject: Fascism is coming to Internet References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> On 23 feb, 10:54, Joan Miller wrote: > *Sorry by this message off topic, but this is too important* > > Fascism is coming fastly to Internet because is the only communication > way that governements (managed by the bank and multinationals) cann't > control > > http://www.boingboing.net/2010/02/21/acta-internet-enforc.html This is something that affects to all programmers: "This calls on all parties to ensure that "third party liability" (the idea that ISPs, web-hosts, application developers, mobile carriers, universities, apartment buildings, and other "third parties" to infringement are sometimes liable for their users' copyright infringements) is on the books in their countries. It doesn't spell out what that liability should be, beyond "knowingly and materially aiding" an infringement" http://craphound.com/acta_digital_chapter-1.pdf From nevillednz at gmail.com Tue Feb 23 13:24:08 2010 From: nevillednz at gmail.com (NevilleDNZ) Date: Tue, 23 Feb 2010 10:24:08 -0800 (PST) Subject: Modifying Class Object References: Message-ID: <9e4f092e-647e-4330-b2ad-e3982b4c8f2c@t9g2000prh.googlegroups.com> Hi Groetjes Albert, I spotted your comment - re: pointers http://groups.google.com/group/comp.lang.python/msg/5c1e25919b6a74bf On Feb 22, 11:44 pm, Albert van der Horst wrote: (I once studied algol 68, and never got confused about these > subjects anymore, recommended.) Having used Algol68, then switching to C to discover "*" for manual dereferencing I immediately wanted to be back using A68 again, but alas... Then when I switched to C++ I immediately understood the "Zen" of C++'s "&"... but still wanted to switch back to A68. Was there ever a version with "Objects"... I saw a version with "Areas" but have no idea what an "Area" is. @Albert: Given the domain name "xs4all" in your email address I am sure YOU have spotted: http://www.xs4all.nl/~jmvdveer/algol.html by Marcel Also: I invite you to join one of the below groups (my .sig below) and deposit some of your Algol68 impressions.... There is also a chrestomathy site http://rosettacode.org/wiki/ALGOL_68 where you can pick out an code sample unimplemented in Algol68 and torture test your Algol68 memories. (Be warned: Most of the easy samples are done) Keep in touch NevilleDNZ -- For Algol68-user mailinglist with archives & subscription: * https://lists.sourceforge.net/lists/listinfo/algol68-user To download Linux's Algol68 Compiler, Interpreter & Runtime: * http://sourceforge.net/projects/algol68 Join the linkedin.com's Algol68 group, follow: * http://www.linkedin.com/groups?gid=2333923 From spamfresser at ch3ka.de Tue Feb 23 13:25:24 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Tue, 23 Feb 2010 19:25:24 +0100 Subject: Signature-based Function Overloading in Python Message-ID: Just a quick question about what would be the most pythonic approach in this. In Java, Method Overloading is my best friend, but this won't work in Python: >>> def a(): pass >>> def a(x): pass >>> a() Traceback (most recent call last): File "", line 1, in a() TypeError: a() takes exactly 1 argument (0 given) So - What would be the most pythonic way to emulate this? Is there any better Idom than: >>> def a(x=None): if x is None: pass else: pass ? Thanks, Michael From nagle at animats.com Tue Feb 23 13:35:38 2010 From: nagle at animats.com (John Nagle) Date: Tue, 23 Feb 2010 10:35:38 -0800 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> Message-ID: <4b841bf1$0$1632$742ec2ed@news.sonic.net> mk wrote: > sjdevnull at yahoo.com wrote: >> On Feb 20, 9:58 pm, John Nagle wrote: >>> sjdevn... at yahoo.com wrote: >>>> On Feb 18, 2:58 pm, John Nagle wrote: >>>>> Multiple processes are not the answer. That means loading >>>>> multiple >>>>> copies of the same code into different areas of memory. The cache >>>>> miss rate goes up accordingly. >>>> A decent OS will use copy-on-write with forked processes, which should >>>> carry through to the cache for the code. >>> That doesn't help much if you're using the subprocess module. The >>> C code of the interpreter is shared, but all the code generated from >>> Python is not. > >> Of course. Multithreading also fails miserably if the threads all try >> to call exec() or the equivalent. > >> It works fine if you use os.fork(). > > What about just using subprocess module to run system commands in worker > threads? Is this likely to have problems? > > Regards, > mk The discussion above was about using "fork" to avoid duplicating the entire Python environment for each subprocess. If you use the subprocess module, you load a new program, so you don't get much memory sharing. This increases the number of cache misses, which is a major bottleneck in many-CPU systems with shared caches. The issue being discussed was scaling Python for CPUs with many cores. With Intel shipping 4 cores/8 hyperthread CPUs, the 6/12 part working, and the 8/16 part coming along, this is more than a theoretical issue. John Nagle From fetchinson at googlemail.com Tue Feb 23 13:49:53 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 23 Feb 2010 19:49:53 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: > In Java, Method Overloading is my best friend, but this won't work in > Python: > > >>> def a(): > pass > >>> def a(x): > pass > >>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > > >>> def a(x=None): > if x is None: > pass > else: > pass This is generally considered to be the pythonic idiom for what you describe. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From cgrebeld at gmail.com Tue Feb 23 13:49:59 2010 From: cgrebeld at gmail.com (chris grebeldinger) Date: Tue, 23 Feb 2010 10:49:59 -0800 (PST) Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <06b6fb1b-f3ee-498c-ad8b-5557eb711a3d@x9g2000vbo.googlegroups.com> Have you tried opening file explorer in administrative mode before performing the copy? I think if there isn't sufficient permissions, it does something weird like that. From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 13:56:44 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 07:56:44 +1300 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> <06b6fb1b-f3ee-498c-ad8b-5557eb711a3d@x9g2000vbo.googlegroups.com> Message-ID: chris grebeldinger wrote: > Have you tried opening file explorer in administrative mode before > performing the copy? I think if there isn't sufficient permissions, > it does something weird like that. No From jjposner at optimum.net Tue Feb 23 13:58:59 2010 From: jjposner at optimum.net (John Posner) Date: Tue, 23 Feb 2010 13:58:59 -0500 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4B842573.2010706@optimum.net> On 2/23/2010 1:25 PM, Michael Rudolf wrote: > Just a quick question about what would be the most pythonic approach in > this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > > >>> def a(): > pass > >>> def a(x): > pass > >>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > > >>> def a(x=None): > if x is None: > pass > else: > pass > Consider this: #------------------ def myfunc(*arglist): if not arglist: print "no arguments" return for i, arg in enumerate(arglist): print "Argument %d is a %s, with value:" % (i, type(arg)), print arg myfunc() print "---" myfunc(1) print "---" myfunc(2, "three", [4, 5,6]) #------------------ program output: no arguments --- Argument 0 is a , with value: 1 --- Argument 0 is a , with value: 2 Argument 1 is a , with value: three Argument 2 is a , with value: [4, 5, 6] HTH, John From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 14:08:16 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 08:08:16 +1300 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: Rick Dooling wrote: > No telling what Windows will do. :) It isn't useful to respond to a serious question with OS bigotry. From timothy.tsvetkov at gmail.com Tue Feb 23 14:09:10 2010 From: timothy.tsvetkov at gmail.com (Timothy N. Tsvetkov) Date: Tue, 23 Feb 2010 11:09:10 -0800 (PST) Subject: Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility. References: <60b1abce-4381-46ab-91ed-f2ab2154c0a1@g19g2000yqe.googlegroups.com> Message-ID: On Feb 16, 10:41?pm, Andrej Mitrovic wrote: > On Feb 16, 7:38?pm, Casey Hawthorne > wrote: > > > Interesting talk on Python vs. Ruby and how he would like Python to > > have just a bit more syntactic flexibility. > > >http://blog.extracheese.org/2010/02/python-vs-ruby-a-battle-to-the-de... > > -- > > Regards, > > Casey > > Gary's friend Geoffrey Grosenbach says in his blog post (which Gary > linked to): "Python has no comparable equivalent to Ruby?s do end > block. Python lambdas are limited to one line and can?t contain > statements (for, if, def, etc.). Which leaves me wondering, what?s the > point?" > > I'm sorry, lambda's do support if's and for's. Also, lambda's are > expressions, not statements, but you can pass them around, keep them > in a dictionary if you want to. And if you need more than one line of > statements, for crying out loud use a def? And who needs those "do- > end" blocks anyway, trying to turn Python into Pascal? I think there are some nice use-cases for anonymous functions / blocks. First, mentioned above, is pretty DSL. And the second is using blocks in map/reduce functions. Yes, you can pass there a function but I believe that in most situations it is more readable to pass a multiline anonymous function / block than defined somewhere function written only for a single map/reduce operation. And often when you use reduce it is a bit more complicated then just one line function. From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 14:14:04 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 08:14:04 +1300 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: W. eWatson wrote: > On 2/23/2010 8:26 AM, Rick Dooling wrote: >> No telling what Windows will do. :) >> >> I am a mere hobbyist programmer, but I think real programmers will >> tell you that it is a bad habit to use relative paths. Use absolute >> paths instead and remove all doubt. >> >> http://docs.python.org/library/os.path.html >> >> RD > You may be right. The actual 300 line program just reads the folder > without specifying any path. I'm not that familiar with os path, but > have seen it used. How do you invoke the program? Do you use a Command Prompt window? From no.email at nospam.invalid Tue Feb 23 14:19:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 11:19:59 -0800 Subject: Is this secure? References: Message-ID: <7xtyt72200.fsf@ruckus.brouhaha.com> mk writes: > I need to generate passwords and I think that pseudo-random generator > is not good enough, frankly. So I wrote this function:... > The question is: is this secure? That is, can the string generated > this way be considered truly random? (I abstract from > not-quite-perfect nature of /dev/urandom at the moment; I can always > switch to /dev/random which is better) urandom is fine and the entropy loss from the numeric conversions and eliminating 'z' in that code before you get letters out is not too bad. The code is pretty ugly. The main problem is you end up with a password that's usually 5 letters but sometimes just 4 or fewer. Passwords that short are vulnerable to dictionary attacks. Longer passwords made from random letters are difficult to remember. I find it's most practical to use a few random words (chosen from a word list like /usr/dict/words) rather than random letters. Words are easier to remember and type. You might look at the site www.diceware.com for an approach to this, which you can implement with a program. The docs there are pretty thoughtful and may help you understand the relevant issues. From CORY.L.NARDIN at saic.com Tue Feb 23 14:22:16 2010 From: CORY.L.NARDIN at saic.com (Nardin, Cory L.) Date: Tue, 23 Feb 2010 11:22:16 -0800 Subject: Python won't run In-Reply-To: <46D34AB9-9DC7-47E9-8288-2B5DFDB55BB8@activestate.com> References: <29325D156EE06640B05BB9FD0D4AC2B502AC479A@0461-its-exmb04.us.saic.com> <46D34AB9-9DC7-47E9-8288-2B5DFDB55BB8@activestate.com> Message-ID: <29325D156EE06640B05BB9FD0D4AC2B502B30AFE@0461-its-exmb04.us.saic.com> Thanks so much for that suggestion. I used the tool and found two missing libraries: MSVCR90.DLL and DWMAPI.DLL. I located and copied the first library to my python directory (and resolved that dependency), but I am still missing the other. I have done a Google search and found that DWMAPI is a Vista library. I am have XP, so I am not sure why it is a required dependency? I made sure that I have all the MS updates (presumably MS would include a new library in an update if it became a required library) and that did not solve the problem. Is this a bug or should I have that library on my computer and the fact that it isn't there is the sign of some other problem? Thanks Cory ________________________________ From: Sridhar Ratnakumar [mailto:sridharr at activestate.com] Sent: Monday, February 22, 2010 11:54 AM To: Nardin, Cory L. Cc: python-list at python.org Subject: Re: Python won't run Have you tried using http://dependencywalker.com/ ? -srid On 2010-02-18, at 1:00 PM, Nardin, Cory L. wrote: Quickly, I have a Mac Intel with Windows XP installed. Tried installing Python 2.6.4 from the binary and also ActivePython 2.6.4.10. Both installations acted the same. There seemed to be no problems during installation (used default options), but when I try to run Python I get an error message: "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem." Of course I searched on that error and it seems to be related to a MS library. In a few different places it was recommended to install the MS Visual Studio redistributable package, which I did with no change in outcome. I really have no idea what to do. Any help is appreciated. Thanks, Cory -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From olof.bjarnason at gmail.com Tue Feb 23 14:30:03 2010 From: olof.bjarnason at gmail.com (Olof Bjarnason) Date: Tue, 23 Feb 2010 20:30:03 +0100 Subject: Fascism is coming to Internet In-Reply-To: <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> Message-ID: 2010/2/23 Joan Miller : > On 23 feb, 10:54, Joan Miller wrote: >> *Sorry by this message off topic, but this is too important* >> >> Fascism is coming fastly to Internet because is the only communication >> way that governements (managed by the bank and multinationals) cann't >> control >> >> http://www.boingboing.net/2010/02/21/acta-internet-enforc.html > > This is something that affects to all programmers: > > "This calls on all parties to ensure that "third party liability" (the > idea that ISPs, web-hosts, application developers, mobile carriers, > universities, apartment buildings, and other "third parties" to > infringement are sometimes liable for their users' copyright > infringements) is on the books in their countries. It doesn't spell > out what that liability should be, beyond "knowingly and materially > aiding" an infringement" > > http://craphound.com/acta_digital_chapter-1.pdf > -- > http://mail.python.org/mailman/listinfo/python-list > Even if this is "Off Topic" (which I think it really isn't in any open source / free software-oriented mailing list), I want to agree with Joan. ACTA is a *real* problem that we must fend politically. Here is a blog post I wrote about the problem with making ISPs liable for what their users communicate: http://translate.google.com/translate?js=y&prev=_t&hl=en&ie=UTF-8&layout=1&eotf=1&u=http%3A%2F%2Folofb.wordpress.com%2F&sl=sv&tl=en (sorry for the bad quality google translation -- this is an important topic!) Note the name of the important principle: "Mere conduit". -- http://olofb.wordpress.com From vicente.soler at gmail.com Tue Feb 23 14:36:23 2010 From: vicente.soler at gmail.com (vsoler) Date: Tue, 23 Feb 2010 11:36:23 -0800 (PST) Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> <4b82dc5a$0$22916$e4fe514c@news.xs4all.nl> Message-ID: <2e510063-7fc0-4cfc-8fd2-53214f1b6c4d@h12g2000vbd.googlegroups.com> On Feb 22, 8:32?pm, Hans Mulder wrote: > G?nther Dietrich wrote: > > vsoler wrote: > > >> I'm trying to print .7 as 70% > >> I've tried: > > >> print format(.7,'%%') > >> .7.format('%%') > > >> but neither works. I don't know what the syntax is... > > > Did you try this: > > >>>> print('%d%%' % (0.7 * 100)) > > 70% > > That method will always round down; TomF's method will round to > the nearest whole number: > > ?>>> print "%d%%" % (0.698 * 100) > 69% > ?>>> print "{0:.0%}".format(.698) > 70% > > Only the OP knows which one is more appropriate for his use case. > > Hope this helps, > > -- HansM Great!!! Thank you From monkey at joemoney.net Tue Feb 23 14:42:05 2010 From: monkey at joemoney.net (monkeys paw) Date: Tue, 23 Feb 2010 14:42:05 -0500 Subject: python dowload Message-ID: I used the following code to download a PDF file, but the file was invalid after running the code, is there problem with the write operation? import urllib2 url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' a = open('adobe.pdf', 'w') for line in urllib2.urlopen(url): a.write(line) From mrkafk at gmail.com Tue Feb 23 14:59:23 2010 From: mrkafk at gmail.com (mk) Date: Tue, 23 Feb 2010 11:59:23 -0800 (PST) Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On Feb 23, 7:19?pm, Paul Rubin wrote: > The code is pretty ugly. ?The main problem is you end up with a password > that's usually 5 letters but sometimes just 4 or fewer. ? Well I didn't write the whole thing here, in actual use I'd write a loop repeating the function until I have enough characters and then I'd select a substring of specified length. Anything else in the code that is ugly and I should correct? > You might look at the sitewww.diceware.comfor an approach to this, > which you can implement with a program. ?The docs there are pretty > thoughtful and may help you understand the relevant issues. Thanks. But I would also be grateful for indicating what is wrong/ugly in my code. Regards, mk From robert.kern at gmail.com Tue Feb 23 15:04:02 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 14:04:02 -0600 Subject: Is this secure? In-Reply-To: <7xtyt72200.fsf@ruckus.brouhaha.com> References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-23 13:19 PM, Paul Rubin wrote: > I find it's most practical to use a few random words (chosen from a word > list like /usr/dict/words) rather than random letters. Words are easier > to remember and type. > > You might look at the site www.diceware.com for an approach to this, > which you can implement with a program. The docs there are pretty > thoughtful and may help you understand the relevant issues. I like RFC 1751 for this: http://gitweb.pycrypto.org/?p=crypto/pycrypto-2.x.git;a=blob;f=lib/Crypto/Util/RFC1751.py;h=1c98a212c22066adabfee521b495eeb4f9d7232b;hb=HEAD Shortened URL: http://tr.im/Pv9B -- 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 gd_usenet at spamfence.net Tue Feb 23 15:09:38 2010 From: gd_usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Tue, 23 Feb 2010 21:09:38 +0100 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> <4b82dc5a$0$22916$e4fe514c@news.xs4all.nl> Message-ID: <29pd57-qhp.ln1@spamfence.net> Hans Mulder wrote: >> Did you try this: >> >>>>> print('%d%%' % (0.7 * 100)) >> 70% > >That method will always round down; TomF's method will round to >the nearest whole number: > > >>> print "%d%%" % (0.698 * 100) >69% > >>> print "{0:.0%}".format(.698) >70% It was intended as a hint to this way of formatting. He could also try: >>> print('%.0f%%' % (0.698 * 100)) 70% Best regards, G?nther From john at castleamber.com Tue Feb 23 15:09:50 2010 From: john at castleamber.com (John Bokma) Date: Tue, 23 Feb 2010 14:09:50 -0600 Subject: python dowload References: Message-ID: <87635naf3l.fsf@castleamber.com> monkeys paw writes: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') > for line in urllib2.urlopen(url): > a.write(line) pdf is /not/ text. You're processing it like it's a text file (and storing it like it's text, which on Windows is most likely a no no). import urllib2 url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' response = urllib2.urlopen(url) fh = open('adobe.pdf', 'wb') fh.write(response.read()) fh.close() response.close() -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From darcy at druid.net Tue Feb 23 15:16:25 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 15:16:25 -0500 Subject: Fascism is coming to Internet In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> Message-ID: <20100223151625.50fde3cb.darcy@druid.net> On Tue, 23 Feb 2010 20:30:03 +0100 Olof Bjarnason wrote: > Even if this is "Off Topic" (which I think it really isn't in any open > source / free software-oriented mailing list), I want to agree with > Joan. It isn't about the Python programming language so it is off topic. So what if some members have an interest? We have interest in a lot of things. We all have interest in the hardware that our programs run on but questions about hardware are also off topic. Perhaps you don't quite grasp the point of topical discussion groups. They are a way of letting individuals decide for themselves what kind of discussions they want to be involved in. By spamming the group this way you take away that freedom of choice. It's ironic when it is done in the name of freedom. -- 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 python.list at tim.thechases.com Tue Feb 23 15:17:11 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Feb 2010 14:17:11 -0600 Subject: python dowload In-Reply-To: References: Message-ID: <4B8437C7.2030408@tim.thechases.com> monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') Sure you don't need this to be 'wb' instead of 'w'? > for line in urllib2.urlopen(url): > a.write(line) I also don't know if this "for line...a.write(line)" loop is doing newline translation. If it's a binary file, you should use .read() (perhaps with a modest-sized block-size, writing it in a loop if the file can end up being large.) -tkc From malaclypse2 at gmail.com Tue Feb 23 15:17:19 2010 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 23 Feb 2010 15:17:19 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <16651e81002231217s297dc93avdaadbc51716ca098@mail.gmail.com> On Tue, Feb 23, 2010 at 2:42 PM, monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') > for line in urllib2.urlopen(url): > ? ?a.write(line) Two guesses: First, you need to call a.close() when you're done writing to the file. This will happen automatically when you have no more references to the file, but I'm guessing that you're running this code in IDLE or some other IDE, and a is still a valid reference to the file after you run that snippet. Second, you're treating the pdf file as text (you're assuming it has lines, you're not writing the file in binary mode, etc.). I don't know if that's correct for a pdf file. I would do something like this instead: Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 IDLE 2.6.4 >>> import urllib2 >>> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >>> a = open('C:/test.pdf', 'wb') >>> data = urllib2.urlopen(url).read() >>> a.write(data) >>> a.close() That seems to works for me, in that it downloads a 16 page pdf document, and that document opens without error or any other obvious problems. -- Jerry From drobinow at gmail.com Tue Feb 23 15:20:54 2010 From: drobinow at gmail.com (David Robinow) Date: Tue, 23 Feb 2010 15:20:54 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <4eb0089f1002231220uf488e59pc0b0d02c987ebc33@mail.gmail.com> On Tue, Feb 23, 2010 at 2:42 PM, monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') > for line in urllib2.urlopen(url): > ? ?a.write(line) If you're running Windows, try a = open('adobe.pdf', 'wb') [Works for me] From ssteinerx at gmail.com Tue Feb 23 15:22:39 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 23 Feb 2010 15:22:39 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <72DB116B-19DC-4BDB-A009-C80A3CE28061@gmail.com> On Feb 23, 2010, at 2:42 PM, monkeys paw wrote: > I used the following code to download a PDF file, but the > file was invalid after running the code, is there problem > with the write operation? > > import urllib2 > url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' > a = open('adobe.pdf', 'w') Try 'wb', just in case. S > for line in urllib2.urlopen(url): > a.write(line) > -- > http://mail.python.org/mailman/listinfo/python-list From anand.shashwat at gmail.com Tue Feb 23 15:28:53 2010 From: anand.shashwat at gmail.com (Shashwat Anand) Date: Wed, 24 Feb 2010 01:58:53 +0530 Subject: python dowload In-Reply-To: <4B8437C7.2030408@tim.thechases.com> References: <4B8437C7.2030408@tim.thechases.com> Message-ID: PyPdf/pdfminer library will be of help On Wed, Feb 24, 2010 at 1:47 AM, Tim Chase wrote: > monkeys paw wrote: > >> I used the following code to download a PDF file, but the >> file was invalid after running the code, is there problem >> with the write operation? >> >> import urllib2 >> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >> a = open('adobe.pdf', 'w') >> > > Sure you don't need this to be 'wb' instead of 'w'? > > > for line in urllib2.urlopen(url): >> a.write(line) >> > > I also don't know if this "for line...a.write(line)" loop is doing newline > translation. If it's a binary file, you should use .read() (perhaps with a > modest-sized block-size, writing it in a loop if the file can end up being > large.) > > -tkc > > > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arnodel at googlemail.com Tue Feb 23 15:35:04 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 23 Feb 2010 20:35:04 +0000 Subject: Signature-based Function Overloading in Python References: Message-ID: Michael Rudolf writes: > Just a quick question about what would be the most pythonic approach > in this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > >>>> def a(): > pass >>>> def a(x): > pass >>>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > >>>> def a(x=None): > if x is None: > pass > else: > pass > There are a number of frameworks for function overloading out there. FWIW, there is actually one in the Python sandbox (for Python 3): http://svn.python.org/view/sandbox/trunk/Overload3K/ -- Arnaud From enleverLesX_XXmcX at XmclavXeauX.com.invalid Tue Feb 23 15:35:53 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Tue, 23 Feb 2010 21:35:53 +0100 Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: <4b843c2b$0$17860$ba4acef3@reader.news.orange.fr> Hi! > Symbolic links are available in NTFS starting with Windows Vista. No. Hardlink come with NTFS, and already exists in W2K (and NT with specifics utilities). @-salutations -- Michel Claveau From robert.kern at gmail.com Tue Feb 23 15:49:25 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 14:49:25 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-23 13:59 PM, mk wrote: > On Feb 23, 7:19 pm, Paul Rubin wrote: > >> The code is pretty ugly. The main problem is you end up with a password >> that's usually 5 letters but sometimes just 4 or fewer. > > Well I didn't write the whole thing here, in actual use I'd write a > loop repeating the function until I have enough characters and then > I'd select a substring of specified length. > > Anything else in the code that is ugly and I should correct? I would recommend using random.SystemRandom.choice() on a sequence of acceptable characters. E.g. (untested) import random import string characters = string.letters + string.digits + '~!@#$%^&*()-+=,;./\?><|' # ... or whatever. def gen_rand_string(length): prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice(characters)) return ''.join(chars) -- 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 vicente.soler at gmail.com Tue Feb 23 15:53:14 2010 From: vicente.soler at gmail.com (vsoler) Date: Tue, 23 Feb 2010 12:53:14 -0800 (PST) Subject: Creating variables from dicts Message-ID: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Hi, I have two dicts n={'a', 'm', 'p'} v={1,3,7} and I'd like to have a=1 m=3 p=7 that is, creating some variables. How can I do this? From jgardner at jonathangardner.net Tue Feb 23 15:53:51 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Tue, 23 Feb 2010 12:53:51 -0800 Subject: SMTPServerDisconnected In-Reply-To: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> References: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> Message-ID: <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> On Tue, Feb 23, 2010 at 8:47 AM, Victor Subervi wrote: > Hi; > I think the last main thing I have to do on my server is get a running email > server up. Now that I've nuked sendmail and given up on postfix, I'm back to > trying to get qmail up and running again. Of course, there are no active > discussion lists for *any* email server, so I have to turn here for help. > While running a script that worked perfectly well on another server to send > an email, I get the following error: > A problem occurred in a Python script. Here is the sequence of function > calls leading up to the error, in the order they occurred. > A problem occurred in a Python script. Here is the sequence of function > calls leading up to the error, in the order they occurred. > ?/var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py > ?? 52 > ?? 53 ''' > ?? 54 my_mail() > ?? 55 print ''' > ?? 56 > my_mail = > ?/var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() > ?? 33 ? ? ? to_address = ourEmail1, > ?? 34 ? ? ? subject = subject, > ?? 35 ? ? ? message = message > ?? 36 ? ).send() > ?? 37 ? Email( > message = 'Name: beno -\nMessage: test' > ?/var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in > send(self=) > ??344 ? ? ? ? smtp = smtplib.SMTP() > ??345 ? ? ? ? if self.smtp_server: > ??346 ? ? ? ? ? ? smtp.connect(self.smtp_server) > ??347 ? ? ? ? else: > ??348 ? ? ? ? ? ? smtp.connect() > smtp = , smtp.connect = >, self = , self.smtp_server > = 'localhost' > ?/usr/lib64/python2.4/smtplib.py in connect(self=, > host='localhost', port=25) > ??305 ? ? ? ? if not self.sock: > ??306 ? ? ? ? ? ? raise socket.error, msg > ??307 ? ? ? ? (code, msg) = self.getreply() > ??308 ? ? ? ? if self.debuglevel > 0: print>>stderr, "connect:", msg > ??309 ? ? ? ? return (code, msg) > code undefined, msg = 'getaddrinfo returns an empty list', self = > , self.getreply = > > ?/usr/lib64/python2.4/smtplib.py in getreply(self=) > ??349 ? ? ? ? ? ? if line == '': > ??350 ? ? ? ? ? ? ? ? self.close() > ??351 ? ? ? ? ? ? ? ? raise SMTPServerDisconnected("Connection unexpectedly > closed") > ??352 ? ? ? ? ? ? if self.debuglevel > 0: print>>stderr, 'reply:', > repr(line) > ??353 ? ? ? ? ? ? resp.append(line[4:].strip()) > global SMTPServerDisconnected = > SMTPServerDisconnected: Connection unexpectedly closed > ?? ? ?args = ('Connection unexpectedly closed',) > I cannot find the qmail logs. I assumed they'd be in either > /var/qmail/supervise/qmail-send > or > /var/qmail/supervise/qmail-smtpd > but I find no logs there. > > [SSH] Protocol Version 2 (OpenSSH_4.3) > [SSH] Cipher: aes128-cbc > Logged in (password) > Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 > [beno at 13gems ~]$ su > Password: > [root at 13gems beno]# man netstat > [root at 13gems beno]# netstat > Active Internet connections (w/o servers) > Proto Recv-Q Send-Q Local Address ? ? ? ? ? ? ? Foreign Address > State > getnameinfo failed > tcp ? ? ? ?0 ? ?268 nrelectric.com:ssh ? ? ? ? ?[UNKNOWN]:61912 > ESTABLISHED > Active UNIX domain sockets (w/o servers) > Proto RefCnt Flags ? ? ? Type ? ? ? State ? ? ? ? I-Node Path > unix ?7 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?10842 ?/dev/log > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?10370 > ?@/org/kernel/udev/udevd > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?6077731 > unix ?3 ? ? ?[ ] ? ? ? ? STREAM ? ? CONNECTED ? ? 6077679 > unix ?3 ? ? ?[ ] ? ? ? ? STREAM ? ? CONNECTED ? ? 6077678 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?6077675 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?11556 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?11511 > unix ?2 ? ? ?[ ] ? ? ? ? DGRAM ? ? ? ? ? ? ? ? ? ?10990 > [root at 13gems beno]# > > How do I trouble-shoot this? Try connecting to the port that is supposed to accept mail messages via telnet and issue a few SMTP commands. -- Jonathan Gardner jgardner at jonathangardner.net From wolftracks at invalid.com Tue Feb 23 16:00:02 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 13:00:02 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 In-Reply-To: References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: On 2/23/2010 11:14 AM, Gib Bogle wrote: > W. eWatson wrote: >> On 2/23/2010 8:26 AM, Rick Dooling wrote: >>> No telling what Windows will do. :) >>> >>> I am a mere hobbyist programmer, but I think real programmers will >>> tell you that it is a bad habit to use relative paths. Use absolute >>> paths instead and remove all doubt. >>> >>> http://docs.python.org/library/os.path.html >>> >>> RD >> You may be right. The actual 300 line program just reads the folder >> without specifying any path. I'm not that familiar with os path, but >> have seen it used. > > How do you invoke the program? Do you use a Command Prompt window? IDLE, but I'm prett sure I tried it (300 lines) with Cprompt. From guglgrupe at yahoo.com Tue Feb 23 16:02:13 2010 From: guglgrupe at yahoo.com (Milenko Kindl) Date: Tue, 23 Feb 2010 13:02:13 -0800 (PST) Subject: Milenko Kindl and America's Worst French Fries Message-ID: Milenko Kindl In spite of the name, French fries are practically an American birthright. They?re offered as the first choice side dish with nearly every fast-food and sit-down chain meal available. But here?s the catch: In a recent study of 7,318 New York City patrons leaving fast food chains during the lunch hour, researchers learned that combo meals ?meaning meals with sides?averaged 1,100 calories each, which is over half a day?s allotment. It goes to show: When your regular meals at these restaurants are already pushing the nutritional envelope, adding an extra 300 (or more!) empty calories can make for a dietary disaster. The authors of the best-selling weight-loss series Eat This, Not That! and Cook This, Not That! have rounded up three of the worst orders of fries available at chain restaurants across the country. We?ve also offered up the surprising winner of the fast food French fry cook-off? you?ll never believe which restaurant chain produces the healthiest fried spuds! Worst Curly Fries Arby?s Curly Fries (Large) 640 calories 34 g fat (5 g saturated, 0 g trans) 1,460 mg sodium Arby?s is famous for its curly fries?too bad they?re overloaded with fat, calories and sodium. When one side dish accounts for nearly three- quarters of your daily allotment of salt, you know there?s a problem. As fun as these curli-Qs are, stick to the Homefry variety at Arby?s? downsizing to a small Curly Fries will still leave you with a 410- calorie side, which is more than many of Arby?s sandwiches! Bonus tip: For full nutrition information for all of your favorite chain restaurants and thousands of foods, download the bestselling Eat This, Not That! iPhone app. It?s like having your own personal nutritionist in your pocket at all times, and will help you avoid the caloric calamities and guide you to the best ways to lose your belly fast. Eat This Instead! Homestyle Fries (Small) 350 calories 15 g fat (2 g saturated) 720 mg sodium Worst Wedge Fries Jack in the Box Bacon Cheddar Wedges 715 calories 45 g fat (13 g saturated, 1 g trans) 905 mg sodium It doesn?t take a nutritionist to identify the hazards of a grease- soaked, cheese-slathered sack of deep-fried potatoes, but by appearance alone, nobody could guess what?s really at stake when you order this side from Jack?s. The American Heart Association recommends that people cap their trans fat intake at 1 percent of total calories. For people on a 2,000-calorie diet, that?s about 2 grams per day. See the problem? Another issue, of course, is the overload in calories? about one-third your daily allotment! Bonus tip: Cheese fries are clearly an unhealthy choice. But sometimes healthy-seeming options are just as dangerous as the obvious diet- sinkers. For 30 jaw-dropping examples, check out The 30 Worst Sandwiches in America. Eat This Instead! Grilled Chicken Strips (4) with Fire Roasted Salsa 185 calories 2 g fat (0.5 g saturated) 805 mg sodium Worst Fries for Your Blood Pressure Dairy Queen Chili Cheese Fries 1,240 calories 71 g fat (28 g saturated, 0.5 g trans) 2,550 milligrams sodium This one?s a no-brainer: Chili, cheese, fried potatoes. But even a savvy eater couldn?t possibly anticipate how bad these 3 ingredients could be when combined by one heavy-handed fast-food company. There?s as much sodium in this side dish as you?ll find in 15 strips of bacon. Stick with classic ketchup and recapture nearly a day?s worth of sodium and 930 calories. Bonus tip: Save calories, time, and money with our free Eat This, Not That! newsletter. Sign up today and you?ll get the Eat This, Not That! guide to shopping once and eating for a week for free! Eat This Instead! French Fries (regular) 310 calories 13 g fat (2 g saturated) 640 mg sodium Worst Regular Order of Fries Five Guys Fries (large) 1,464 calories 71 g fat (14 g saturated) 213 mg sodium Unfortunately, Five Guys doesn?t offer anything but fries in the side department. Your safest bet, of course, is to skip the fries altogether (you?d be better off adding a second patty to your burger), but if you can?t bring yourself to eat a burger sans fries, then split a regular order. That will still add 310 calories to your meal, but it beats surrendering more than 75% of your day?s calories to a greasy paper bag. Bonus tip: Sides account for a third of our combo-meal calories?but drinks account for a quarter of the total calories we consume each day! Battle the liquid bulge: Avoid all drinks on this shocking list of The Worst Drinks in the Supermarket. Eat This Instead! Regular Fries (1/2 serving) 310 calories 15 g fat (3 g saturated) 45 mg sodium Worst Fries in America Chili?s Texas Cheese Fries w/Jalapeno Ranch 1,920 calories 147 g fat (63 g saturated) 3,580 mg sodium The only thing that comes close to redeeming this cheesy mound of lard and grease is the fact that it?s ostensibly meant to be shared with a few friends. Even so, you?ll collectively be taking in an entire day?s worth of calories, three days? allotment of saturated fat, and a day and a half?s allotment of sodium. What?s even scarier, if you can imagine, is that even if you try to order more sensibly and ask for the ?half? order of Texas Cheese Fries, you?ll still receive a disastrous dish that packs in 1,400 calories. There?s one French fries side dish at Chili?s that?s acceptable, although even in its much- reduced form, you?d be better off splitting it. Bonus Tip: See what other Chili?s items made our list of The 20 Worst Restaurant Foods in America. Eat This Instead! Homestyle Fries 380 calories 23 g fat (4 g saturated) 230 mg sodium Best Fast Food Fries in America McDonald?s Small French Fries 230 calories 11 g fat (1.5 g saturated) 160 mg sodium Out of the big three fast food joints (Mickey D?s, Wendy?s, and BK), you?ll find the least caloric, least salty fries underneath the golden arches. The key to ordering a smart side dish is portion sizing?and McDonald?s has that under control. ------------ Follow Men's Health and Women's Health editor Dave Zinczenko on Twitter. You'll get the best life-changing health, nutrition and exercise secrets every day. Check out the cutting-edge guide to fast and easy weight loss, the brand-new Big Book of Exercises. Feeling lousy? Find the right medicine to ease the cold and flu Get more nutrition, health, and fitness secrets from Men's Health: Subscribe today with this special offer and save 50% off the cover price. From arnodel at googlemail.com Tue Feb 23 16:10:14 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Tue, 23 Feb 2010 21:10:14 +0000 Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: vsoler writes: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} These are sets, not dicts. > and I'd like to have > > a=1 > m=3 > p=7 As sets are unordered, you may as well have a = 3 m = 7 p = 1 or any other permutation. You need some sequences instead. E.g. n = ['a', 'm', 'p'] v = (1, 3, 7) Then you can do: for name, value in zip(n, v): globals()[name] = value After this the names, 'a', 'm' and 'p' will be bound to the values you want in the global namespace. However, it is almost always a bad idea to do this. Can you explain why you need to do this? -- Arnaud From buggsy2 at sdlfkj.com Tue Feb 23 16:11:52 2010 From: buggsy2 at sdlfkj.com (buggsy2 at sdlfkj.com) Date: Tue, 23 Feb 2010 13:11:52 -0800 Subject: What's Going on between Python and win7? References: Message-ID: "W. eWatson" writes: > I noted that this search box has > some sort of filter associated with it. Possibly, in my early stages > of learning to navigate in Win7, I accidentally set the filter. > > Comments? FYI, the only truly reliable and powerful file search utility I've found for Windows is Agent Ransack (http://download.mythicsoft.com/agentran.exe) From wuhrrr at gmail.com Tue Feb 23 16:21:36 2010 From: wuhrrr at gmail.com (Hai Vu) Date: Tue, 23 Feb 2010 13:21:36 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 12:53?pm, vsoler wrote: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} > > and I'd like to have > > a=1 > m=3 > p=7 > > that is, creating some variables. > > How can I do this? I think you meant to use the square brackets [ ] instead of the curly ones { } to define the list: >>> n = ['a', 'b', 'c'] >>> v = [3, 5, 7] >>> for x, y in zip(n, v): ... exec '%s=%d' % (x, y) ... >>> a 3 >>> b 5 >>> c 7 --- The key is the use of the exec statement, which executes the strings "a=3", "b=5", ... as if they are python statements. From wolftracks at invalid.com Tue Feb 23 16:23:10 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 13:23:10 -0800 Subject: Bay Area PUG Meeting [Speaker] Thursday in Mountain View, CA? In-Reply-To: References: Message-ID: On 2/23/2010 7:49 AM, W. eWatson wrote: > Anyone here going to the meeting,Subject? As far as I can tell, it meets > from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to > be an informal group dinner at 6 pm at some place yet unknown. Comments? From g.bogle at auckland.no.spam.ac.nz Tue Feb 23 16:29:01 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Wed, 24 Feb 2010 10:29:01 +1300 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: W. eWatson wrote: > On 2/23/2010 11:14 AM, Gib Bogle wrote: >> W. eWatson wrote: >>> On 2/23/2010 8:26 AM, Rick Dooling wrote: >>>> No telling what Windows will do. :) >>>> >>>> I am a mere hobbyist programmer, but I think real programmers will >>>> tell you that it is a bad habit to use relative paths. Use absolute >>>> paths instead and remove all doubt. >>>> >>>> http://docs.python.org/library/os.path.html >>>> >>>> RD >>> You may be right. The actual 300 line program just reads the folder >>> without specifying any path. I'm not that familiar with os path, but >>> have seen it used. >> >> How do you invoke the program? Do you use a Command Prompt window? > IDLE, but I'm prett sure I tried it (300 lines) with Cprompt. I don't know what you mean by "300 lines". Have you opened a Command Prompt window, changed to the directory where you copied the files, and executed: python your_prog.py ? From python at mrabarnett.plus.com Tue Feb 23 16:31:48 2010 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Feb 2010 21:31:48 +0000 Subject: Creating variables from dicts In-Reply-To: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4B844944.1050203@mrabarnett.plus.com> vsoler wrote: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} > Those aren't dicts, they're sets. > and I'd like to have > > a=1 > m=3 > p=7 > > that is, creating some variables. > > How can I do this? The real question is not how, but why? Anyway, assuming you want them to be global variables: globals().update(dict(zip(n, v))) On my machine the variables didn't get the correct values because, as I said, 'n' and 'v' are sets, so the order of the members is arbitrary. From benjamin.kaplan at case.edu Tue Feb 23 16:40:10 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Tue, 23 Feb 2010 16:40:10 -0500 Subject: What's Going on between Python and win7? In-Reply-To: <4b843c2b$0$17860$ba4acef3@reader.news.orange.fr> References: <87d3zxt3h4.fsf@castleamber.com> <4b843c2b$0$17860$ba4acef3@reader.news.orange.fr> Message-ID: On Tue, Feb 23, 2010 at 3:35 PM, Michel Claveau - MVP wrote: > Hi! > >> Symbolic links are available in NTFS starting with Windows Vista. > > No. > Hardlink come with NTFS, and already exists in W2K (and NT with specifics utilities). > > @-salutations > -- > Michel Claveau > And there's a difference between hard links and symbolic links. Symbolic links were added to NTFS starting with Windows Vista. http://msdn.microsoft.com/en-us/library/aa365680%28VS.85%29.aspx > -- > http://mail.python.org/mailman/listinfo/python-list > From stef.mientki at gmail.com Tue Feb 23 16:54:36 2010 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 23 Feb 2010 22:54:36 +0100 Subject: How to transmit a crash report ? In-Reply-To: <0b222aec-db04-45b7-9f86-e2839ffafc40@j1g2000vbl.googlegroups.com> References: <4B8336EE.9040802@gmail.com> <0b222aec-db04-45b7-9f86-e2839ffafc40@j1g2000vbl.googlegroups.com> Message-ID: <4B844E9C.1000706@gmail.com> On 23-02-2010 15:21, Thomas wrote: > On Feb 22, 9:27 pm, MRAB wrote: > >> Stef Mientki wrote: >> >>> hello, >>> >> >>> in my python desktop applications, >>> I'ld like to implement a crash reporter. >>> By redirecting the sys.excepthook, >>> I can detect a crash and collect the necessary data. >>> Now I want that my users sends this information to me, >>> and I can't find a good way of doing this. >>> >> >>> The following solutions came into my mind: >>> (most of my users are on Windows, and the programs are written in Python >>> 2.6) >>> >> >>> 1. mailto: >>> doesn't work if the the user didn't install a default email client, >>> or if the user uses a portable email client (that isn't started yet) >>> Besides this limits the messages to small amounts of data. >>> >> >>> 2.other mail options: smtp >>> AFAIK such a solution needs smtp authorization, and therefor I've to put >>> my username and password in the desktop application. >>> >> Try reading the documentation for Python's smtplib module. >> >> You don't need to provide any password. >> >> >> >> >>> 3. http-post >>> Although post is also limited in size, >>> I could store information in cookies (don't know yet how), and cookies >>> are sent parallel to the post message. >>> On the server site I can use a small php script, that stores the >>> post-data, cookies and/or send's a (long) email. >>> >> >>> are there better options ?- Hide quoted text - >>> >> - Show quoted text -- Hide quoted text - >> >> - Show quoted text - >> > Try http://code.activestate.com/recipes/442459/ > Apparently there's something terrible wrong on my system, because I do need username and password :-( First, a script that works without username and password. I guess it works, because the smtp_server is the smtp server of my provider, and I'm in that domain of my provider, so it won't work for a random user of my program. if Test ( 4 ) : import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart body = 'test_body' subject = 'test_subject' mail_to = 's.mientki at ru.nl' mail_from = 'stef.mientki at gmail.com' msg = MIMEMultipart ( 'alternative' ) msg [ 'To' ] = mail_to msg [ 'From' ] = mail_from msg [ 'Subject' ] = subject part1 = MIMEText ( body, 'plain' ) msg.attach ( part1 ) smtp_server = 'mail.upcmail.nl' session = smtplib.SMTP ( smtp_server ) session.sendmail ( mail_from, [mail_to], msg.as_string() ) Using smtp on google , works only if I support username and password: if Test ( 5 ) : import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart body = 'test_body' subject = 'test_subject' mail_to = 's.mientki at ru.nl' mail_from = 'stef.mientki at gmail.com' msg = MIMEMultipart ( 'alternative' ) msg [ 'To' ] = mail_to msg [ 'From' ] = mail_from msg [ 'Subject' ] = subject part1 = MIMEText ( body, 'plain' ) msg.attach ( part1 ) smtp_server = 'smtp.gmail.com' session = smtplib.SMTP ( smtp_server, 587 ) session.ehlo ( mail_from ) session.starttls () session.ehlo ( mail_from ) session.login (username, password ) session.sendmail ( mail_from, [mail_to], msg.as_string() ) And her a number of different tries with localhost / mail : if Test ( 6 ) : import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart body = 'test_body' subject = 'test_subject' mail_to = 's.mientki at ru.nl' mail_from = 'stef.mientki at gmail.com' msg = MIMEMultipart ( 'alternative' ) msg [ 'To' ] = mail_to msg [ 'From' ] = mail_from msg [ 'Subject' ] = subject part1 = MIMEText ( body, 'plain' ) msg.attach ( part1 ) session = smtplib.SMTP ( 'localhost' ) """ Traceback (most recent call last): File "D:\Data_Python_25\support\mail_support.py", line 375, in session = smtplib.SMTP ( smtp_server ) File "P:\Python26\lib\smtplib.py", line 239, in __init__ (code, msg) = self.connect(host, port) File "P:\Python26\lib\smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "P:\Python26\lib\smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "P:\Python26\lib\socket.py", line 514, in create_connection raise error, msg error: [Errno 10061] No connection could be made because the target machine actively refused it """ #session = smtplib.SMTP ( 'localhost', 25 ) #session = smtplib.SMTP ( 'mail', 25 ) session = smtplib.SMTP ( 'mail', 1025 ) """ Traceback (most recent call last): File "D:\Data_Python_25\support\mail_support.py", line 377, in session = smtplib.SMTP ( 'mail', 1025 ) File "P:\Python26\lib\smtplib.py", line 239, in __init__ (code, msg) = self.connect(host, port) File "P:\Python26\lib\smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "P:\Python26\lib\smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "P:\Python26\lib\socket.py", line 500, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): gaierror: [Errno 11001] getaddrinfo failed """ session.sendmail ( mail_from, [mail_to], msg.as_string() ) What am I doing wrong ? cheers, Stef -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Tue Feb 23 17:26:34 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Feb 2010 09:26:34 +1100 Subject: When will Python go mainstream like Java? References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: <87wry3612d.fsf@benfinney.id.au> Stefan Behnel writes: > Chris Rebert, 23.02.2010 06:45: > > Indeed. Python is at position 7, just behind C#, in the TIOBE Index: > > http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? Why not? What do you think the TIOBE measures, and why would PHP not be rising by that measure? -- \ ?To save the world requires faith and courage: faith in reason, | `\ and courage to proclaim what reason shows to be true.? | _o__) ?Bertrand Russell | Ben Finney From david at boddie.org.uk Tue Feb 23 17:28:12 2010 From: david at boddie.org.uk (David Boddie) Date: Tue, 23 Feb 2010 23:28:12 +0100 Subject: Problem creating executable, with PyQwt References: Message-ID: On Tuesday 23 February 2010 05:32, Gib Bogle wrote: > David Boddie wrote: > >> I have previously referred people with py2exe/PyQt issues to this page on >> the PyQt Wiki: >> >> http://www.py2exe.org/index.cgi/Py2exeAndPyQt >> >> If you can somehow convince py2exe to include the QtSvg module (and >> presumably the libQtSvg library as well) then perhaps that will solve >> this problem. >> >> David > > Thanks David, that worked a treat. :-) If you could update the Wiki (or maybe the py2exe Wiki, if they have one) to say what you did, that would be useful for others in the future. Then they'll only be one search away from the answer. :-) David From aahz at pythoncraft.com Tue Feb 23 17:50:15 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 14:50:15 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA References: Message-ID: In article , W. eWatson wrote: > >Anyone here going to the meeting,Subject? As far as I can tell, it meets >from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >be an informal group dinner at 6 pm at some place yet unknown. Comments? Subscribe to http://mail.python.org/mailman/listinfo/baypiggies -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From lie.1296 at gmail.com Tue Feb 23 17:55:21 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 09:55:21 +1100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4b845cfa$1@dnews.tpgi.com.au> On 02/24/10 05:25, Michael Rudolf wrote: > Just a quick question about what would be the most pythonic approach in > this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > >>>> def a(x=None): > if x is None: > pass > else: > pass Python's idiom for this has always been to use "if arg is None:"; but now with the (relatively) new decorator feature, though is not yet a popular idiom, it is now possible to do something like this: #!/usr/bin/env python from functools import wraps def overloaded(func): @wraps(func) def overloaded_func(*args, **kwargs): for f in overloaded_func.overloads: try: return f(*args, **kwargs) except TypeError: pass else: # it will be nice if the error message prints a list of # possible signatures here raise TypeError("No compatible signatures") def overload_with(func): overloaded_func.overloads.append(func) return overloaded_func overloaded_func.overloads = [func] overloaded_func.overload_with = overload_with return overloaded_func ############# @overloaded def a(): print 'a() without args' pass @a.overload_with def _(n): # note that, just like property(), the function's name in # the "def _(n):" line can be arbitrary, the important # name is in the "@overloads(a)" line print 'a() with args' pass a() a(4) a(4, 5) # ERROR: no matching signature PS: I posted the code to recipe book, for future reference: http://code.activestate.com/recipes/577064-simple-function-overloading-with-decorator/ From luismgz at gmail.com Tue Feb 23 17:56:30 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 14:56:30 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 5:53?pm, vsoler wrote: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} > > and I'd like to have > > a=1 > m=3 > p=7 > > that is, creating some variables. > > How can I do this? You are probably coming from another language and you're not used to python's data structures. If you want a list of items, you use tuples or lists. Examples: ('a', 'm', 'p') ---> this is a tuple, and it's made with parenthesis () ['a', 'm', 'p'] ---> this is a list, and it's made with brackets [] Check the documentation to see the difference between tuples and lists. For now, lets just use lists and forget about tuples... Now if you want a sequence of items ordered a key + value pairs, use a dictionary, as follows: {'name': 'joe', 'surname': 'doe', 'age': 21} ---> this is a dict, and it's made with curly braces {}. Curly braces are also used to create sets, but you don't need them now (check the documentation to learn more about sets). So going back to your question, you should have two lists, as follows: n = ['a', 'm', 'p'] v = [1,3,7] --> note that I used brackets [], not curly braces {}. And now you can build a dict formed by the keys in "n" and the values in "v": myDict = {} --> this is an new empty dictionary for k,v in zip(n,v): myDict[k] = v This results in this dictionary: {'a': 1, 'p': 7, 'm': 3}. Hope this helps... Luis From fetchinson at googlemail.com Tue Feb 23 17:57:45 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Tue, 23 Feb 2010 23:57:45 +0100 Subject: [Python-Dev] Question for you In-Reply-To: <4B844F2E.9010300@voidspace.org.uk> References: <36FA01F429A6354CB4C8C185B307F35503F4F080@XMBTX133.northgrum.com> <4B844F2E.9010300@voidspace.org.uk> Message-ID: >> Hello, Dave; >> >> My name is Craig Connor and I am a senior s/w developer at Northrop >> Grumman. >> >> I have a question for you. I have installed* Boost* (via the >> Installer), and stored it into my >> >> C Drive inside a dir called: >> >> * C:\boost_1_42* >> >> I also installed the* Boost Jam* into a directory called: >> >> * C:\boost-jam-3.1.17* >> >> I am using 2 separate compilers in my* Win OS XP (SP3)* >> >> and I would like to be able to use the Python module of Boost >> >> in order to embed Python.h into my C++ compiler. >> >> The C++ compilers that I have are: >> >> o* Dev-cpp*, and >> >> o* Visual C++.net* (of* MS Visual Studio.Net 2008*). >> >> Problem: >> >> When I compile a simple program, I keep getting the error: >> "*pyconfig.h: No such file or directory*". >> >> The program I am trying to start with is (below): >> >> *#include * >> >> *#include* >> >> *#include* >> >> *using namespace std;* >> >> *int main( )* >> >> *{* >> >> * cout << "Hello, Boost World!!" << endl;* >> >> * boost::any a(5);* >> >> * a = 7.67;* >> >> * std::cout<(a)<> >> * * >> >> * system( "PAUSE" );* >> >> * return 0;* >> >> *}* >> >> >> Also: >> >> I did set up my environmental config to go to the Boost dir. >> >> Question: >> >> Do you know what am I doing wrong? >> >> Regards, >> >> Craig Connor >> >> 720.622.2209 >> > Hello Connor, > > I think you have the wrong email address - this is Python-dev, an email > list for the development *of* Python. > > All the best, > > Michael Foord [redirecting to python-list from python-dev] And the fact that you are a "senior s/w developer" at Northrop Grumman surely doesn't sound like good advertisement for said firm. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fetchinson at googlemail.com Tue Feb 23 18:06:09 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Wed, 24 Feb 2010 00:06:09 +0100 Subject: Spam from gmail (Was: fascism) In-Reply-To: <20100223110954.5da3d679.darcy@druid.net> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: >> >> Is it just me or has the spew from gmail on this list radically >> >> increased in the last week? Anyone else considering blocking all gmail >> >> posts to this list? >> > >> > I did that a long time ago for all of the Usenet groups I read >> > and all but one of the mailing lists I read. >> >> Wait, I misread the posting. I block everything from >> google.groups, not everything from gmail. > > Yes, I did that a long time ago as well. But now there seems to be > more and more actual spam coming from gmail.com itself. It may just be > a minor blip on the spam graph but I'm keeping my eye on it. > > Most mailing lists that I am on are pretty good at filtering spam > before it gets to the list. The only spam I ever see on my NetBSD > lists are the ones that I moderate and I block them before anyone else > sees them. A little more pain for me in return for a lot less pain for > everyone else. I guess that's not possible on a list that is gatewayed > to UseNet like this one is. > > Hmm. I wonder if all the spam is coming from the NG side. I'll have > to look at that. One of the reasons that I stopped reading UseNet over > ten years ago was because of the diminishinig S/N ratio. I have always > felt that it was a mistake to gateway this group. And this has to do with python programming in what way? You, sir, are incredibly funny :) Just 5 minutes ago you declared in a nearby thread that > It isn't about the Python programming language so it is off topic. So > what if some members have an interest? We have interest in a lot of > things. We all have interest in the hardware that our programs run on > but questions about hardware are also off topic. > > Perhaps you don't quite grasp the point of topical discussion groups. > They are a way of letting individuals decide for themselves what kind > of discussions they want to be involved in. By spamming the group this > way you take away that freedom of choice. It's ironic when it is done > in the name of freedom. Touche! Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From monkey at joemoney.net Tue Feb 23 18:08:19 2010 From: monkey at joemoney.net (monkeys paw) Date: Tue, 23 Feb 2010 18:08:19 -0500 Subject: python dowload In-Reply-To: References: Message-ID: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> On 2/23/2010 3:17 PM, Tim Chase wrote: > monkeys paw wrote: >> I used the following code to download a PDF file, but the >> file was invalid after running the code, is there problem >> with the write operation? >> >> import urllib2 >> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >> a = open('adobe.pdf', 'w') > > Sure you don't need this to be 'wb' instead of 'w'? 'wb' does the trick. Thanks all! Here is the final working code, i used an index(i) to see how many reads took place, i have to assume there is a default buffer size: import urllib2 a = open('adobe.pdf', 'wb') i = 0 for line in urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): i = i + 1 a.write(line) print "Number of reads: %d" % i a.close() NEW QUESTION if y'all are still reading: Is there an integer increment operation in Python? I tried using i++ but had to revert to 'i = i + 1' > >> for line in urllib2.urlopen(url): >> a.write(line) > > I also don't know if this "for line...a.write(line)" loop is doing > newline translation. If it's a binary file, you should use .read() > (perhaps with a modest-sized block-size, writing it in a loop if the > file can end up being large.) > > -tkc > > From ldo at geek-central.gen.new_zealand Tue Feb 23 18:11:26 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:11:26 +1300 Subject: Writing an assembler in Python References: Message-ID: In message , Anh Hai Trinh wrote: > On Feb 23, 10:08 am, Lawrence D'Oliveiro wrote: >> >> Let me suggest an alternative approach: use Python itself as the >> assembler. Call routines in your library to output the code. That way you >> have a language more powerful than any assembler. >> >> See for an example. > > SyntaxError: Non-matching "#end if" in crosscode8.py:345 What mismatch? Line 345 is the last line of this routine: def org(self, addr) : """sets the origin for defining subsequent consecutive memory contents.""" self.curpsect.setorigin(self.follow(addr)) self.lastaddr = self.curpsect.origin return self # for convenient chaining of calls #end org From ldo at geek-central.gen.new_zealand Tue Feb 23 18:18:19 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:18:19 +1300 Subject: Is this secure? References: Message-ID: In message , mk wrote: > I need to generate passwords and I think that pseudo-random generator is > not good enough, frankly. So I wrote this function: Much simpler: import subprocess data, _ = subprocess.Popen \ ( args = ("pwgen", "-nc"), stdout = subprocess.PIPE ).communicate() print data From ldo at geek-central.gen.new_zealand Tue Feb 23 18:19:13 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:19:13 +1300 Subject: When will Java go mainstream like Python? References: Message-ID: In message , Martin P. Hellwig wrote: > Actually I am still waiting for Java to be mainstream :-) Too late, I think. Sun dilly-dallied over making it open source for too long, until it practically didn?t matter any more. From comptekki at gmail.com Tue Feb 23 18:19:41 2010 From: comptekki at gmail.com (Wes James) Date: Tue, 23 Feb 2010 16:19:41 -0700 Subject: python dowload In-Reply-To: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <533df7fa1002231519t127cd512r9bc2feb294db77f2@mail.gmail.com> > > > NEW QUESTION if y'all are still reading: > > Is there an integer increment operation in Python? I tried > using i++ but had to revert to 'i = i + 1' i+=1 From ldo at geek-central.gen.new_zealand Tue Feb 23 18:22:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:22:05 +1300 Subject: When will Java go mainstream like Python? References: Message-ID: In message , Ishwor Gurung wrote: > Java - The JVM code been hacked to death by Sun engineers (optimised) > Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. > ad-infinitum but nowhere as near to JVM Python is still faster, though. I think a key reason is that its VM supports reference-counting, which the Java folks never quite got the grasp of. So you see, it?s all about working smarter, not harder. From ldo at geek-central.gen.new_zealand Tue Feb 23 18:25:37 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 12:25:37 +1300 Subject: look at the google code References: <711cb713-4b4a-47f6-8922-ce1ada7d64e6@e1g2000yqh.googlegroups.com> Message-ID: In message <711cb713-4b4a-47f6-8922-ce1ada7d64e6 at e1g2000yqh.googlegroups.com>, lkcl wrote: > we couldn't get control of that site for quite some time so > started using sourceforget for svn, but the issue tracker on > sourceforget is truly dreadful. Damn. I?ve been working on my own fork of a long-neglected package on SourceForge . GitHub doesn?t offer a publicly-writable bug tracker, but I was under the impression that SourceForge did. But you?re saying it?s not worth using? From darcy at druid.net Tue Feb 23 18:29:23 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Tue, 23 Feb 2010 18:29:23 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: <20100223182923.4d259d12.darcy@druid.net> On Wed, 24 Feb 2010 00:06:09 +0100 Daniel Fetchinson wrote: > And this has to do with python programming in what way? Are you new? Meta discussions about lists are generally considered on-topic for the list. > You, sir, are incredibly funny :) Yes, I am. That however is NOT on topic. :-) And just to bring this back on topic, I did do a test and found that splitting my mailbox between Python mailing list messages and Python newsgroup messages did not indicate that that was a good barometer of spaminess. There are also quite a few decent posts from gmail.com so blocking by that domain isn't going to be the problem solver either. -- 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 ethan at stoneleaf.us Tue Feb 23 18:34:02 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 23 Feb 2010 15:34:02 -0800 Subject: python dowload In-Reply-To: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <4B8465EA.30706@stoneleaf.us> monkeys paw wrote: > NEW QUESTION if y'all are still reading: > > Is there an integer increment operation in Python? I tried > using i++ but had to revert to 'i = i + 1' Nope, but try i += 1. ~Ethan~ From sccolbert at gmail.com Tue Feb 23 18:36:48 2010 From: sccolbert at gmail.com (Chris Colbert) Date: Tue, 23 Feb 2010 18:36:48 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: <7f014ea61002231536h36a0cf20u2de17fef7f76f8ab@mail.gmail.com> this image is appropriate: http://4.bp.blogspot.com/_pS7sKjlzwFg/SwhG1S901pI/AAAAAAAAEiw/XSm93RIY2WE/s400/kelso-burn.jpg On Tue, Feb 23, 2010 at 6:06 PM, Daniel Fetchinson < fetchinson at googlemail.com> wrote: > >> >> Is it just me or has the spew from gmail on this list radically > >> >> increased in the last week? Anyone else considering blocking all > gmail > >> >> posts to this list? > >> > > >> > I did that a long time ago for all of the Usenet groups I read > >> > and all but one of the mailing lists I read. > >> > >> Wait, I misread the posting. I block everything from > >> google.groups, not everything from gmail. > > > > Yes, I did that a long time ago as well. But now there seems to be > > more and more actual spam coming from gmail.com itself. It may just be > > a minor blip on the spam graph but I'm keeping my eye on it. > > > > Most mailing lists that I am on are pretty good at filtering spam > > before it gets to the list. The only spam I ever see on my NetBSD > > lists are the ones that I moderate and I block them before anyone else > > sees them. A little more pain for me in return for a lot less pain for > > everyone else. I guess that's not possible on a list that is gatewayed > > to UseNet like this one is. > > > > Hmm. I wonder if all the spam is coming from the NG side. I'll have > > to look at that. One of the reasons that I stopped reading UseNet over > > ten years ago was because of the diminishinig S/N ratio. I have always > > felt that it was a mistake to gateway this group. > > And this has to do with python programming in what way? > > You, sir, are incredibly funny :) > > Just 5 minutes ago you declared in a nearby thread that > > > It isn't about the Python programming language so it is off topic. So > > what if some members have an interest? We have interest in a lot of > > things. We all have interest in the hardware that our programs run on > > but questions about hardware are also off topic. > > > > Perhaps you don't quite grasp the point of topical discussion groups. > > They are a way of letting individuals decide for themselves what kind > > of discussions they want to be involved in. By spamming the group this > > way you take away that freedom of choice. It's ironic when it is done > > in the name of freedom. > > Touche! > > Cheers, > Daniel > > > -- > Psss, psss, put it down! - http://www.cafepress.com/putitdown > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From luismgz at gmail.com Tue Feb 23 18:41:16 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 15:41:16 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 7:56?pm, Luis M. Gonz?lez wrote: > On Feb 23, 5:53?pm, vsoler wrote: > > > > > > > Hi, > > > I have two dicts > > > n={'a', 'm', 'p'} > > v={1,3,7} > > > and I'd like to have > > > a=1 > > m=3 > > p=7 > > > that is, creating some variables. > > > How can I do this? > > You are probably coming from another language and you're not used to > python's data structures. > If you want a list of items, you use tuples or lists. Examples: > > ? ? ('a', 'm', 'p') ---> this is a tuple, and it's made with > parenthesis () > ? ? ['a', 'm', 'p'] ---> this is a list, and it's made with brackets > [] > > Check the documentation to see the difference between tuples and > lists. > For now, lets just use lists and forget about tuples... > Now if you want a sequence of items ordered a key + value pairs, use a > dictionary, as follows: > > ? ? {'name': 'joe', 'surname': 'doe', 'age': 21} ---> this is a dict, > and it's made with curly braces {}. > > Curly braces are also used to create sets, but you don't need them now > (check the documentation to learn more about sets). > So going back to your question, you should have two lists, as follows: > > ? ? n = ['a', 'm', 'p'] > ? ? v = [1,3,7] ? ? ? ? --> note that I used brackets [], not curly > braces {}. > > And now you can build a dict formed by the keys in "n" and the values > in "v": > > ? ? myDict = {} ? ? ? ? ? --> this is an new empty dictionary > ? ? for k,v in zip(n,v): > ? ? ? ? myDict[k] = v > > This results in this dictionary: {'a': 1, 'p': 7, 'm': 3}. > > Hope this helps... > Luis By the way, if you want the variables inside myDict to be free variables, you have to add them to the local namespace. The local namespace is also a dictionary "locals()". So you can update locals as follows: locals().update( myDictionary ) This way, all the key-value pairs inside myDict become free variables. Wich is the same as declaring them as follows: a = 1 p = 7 etc... Luis From python.list at tim.thechases.com Tue Feb 23 18:41:37 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 23 Feb 2010 17:41:37 -0600 Subject: Creating variables from dicts In-Reply-To: References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4B8467B1.6010404@tim.thechases.com> Luis M. Gonz?lez wrote: > If you want a list of items, you use tuples or lists. Examples: > > ('a', 'm', 'p') ---> this is a tuple, and it's made with > parenthesis () Actually, a tuple is made with commas...the parens are just there to clarify the order of operations and make it easier to read :) >>> x = 1,2,3 >>> x (1, 2, 3) -tkc From nad at acm.org Tue Feb 23 19:13:46 2010 From: nad at acm.org (Ned Deily) Date: Tue, 23 Feb 2010 16:13:46 -0800 Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <20100223182923.4d259d12.darcy@druid.net> Message-ID: In article <20100223182923.4d259d12.darcy at druid.net>, "D'Arcy J.M. Cain" wrote: > And just to bring this back on topic, I did do a test and found that > splitting my mailbox between Python mailing list messages and Python > newsgroup messages did not indicate that that was a good barometer of > spaminess. There are also quite a few decent posts from gmail.com so > blocking by that domain isn't going to be the problem solver either. Try following the list using gmane (either via NNTP, RSS, or the web). gmane does a pretty good job of filtering the spam. http://dir.gmane.org/gmane.comp.python.general -- Ned Deily, nad at acm.org From leo.shklovskii at gmail.com Tue Feb 23 19:19:56 2010 From: leo.shklovskii at gmail.com (Leo) Date: Tue, 23 Feb 2010 16:19:56 -0800 (PST) Subject: python shell crashing on paste Message-ID: <1ede46e4-8ca1-4fe0-ad3f-7e781bbe1182@b36g2000pri.googlegroups.com> I just upgraded to Windows 7 (yes, I know) and I've been having a really strange problem with running python (2.6.4, installed from the python.org installer) from the command line. If I open the interpreter, and then paste in a long string, conhost.exe crashes. This doesn't happen when pasting the string just in the command line so its something with the python interpreter. Here's the details of the windows crash: Log Name: Application Source: Application Error Event ID: 1000 Task Category: (100) Level: Error Keywords: Classic Description: Faulting application name: conhost.exe, version: 6.1.7600.16385, time stamp: 0x4a5bc271 Faulting module name: conhost.exe, version: 6.1.7600.16385, time stamp: 0x4a5bc271 Exception code: 0xc0000005 Fault offset: 0x000048ca Faulting process id: 0x1aa8 Faulting application start time: 0x01cab4e450b97766 Faulting application path: C:\Windows\system32\conhost.exe Faulting module path: C:\Windows\system32\conhost.exe Report Id: 9c6afd6c-20d7-11df-bbd8-e390d387a902 Has anyone else seen anything like this? Any suggestions on how to even start figuring this out? --Leo From aahz at pythoncraft.com Tue Feb 23 19:21:48 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 16:21:48 -0800 Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: In article , D'Arcy J.M. Cain wrote: >On Tue, 23 Feb 2010 02:54:25 -0800 (PST) >Joan Miller wrote: >> >> *Sorry by this message off topic, but this is too important* > >Is it just me or has the spew from gmail on this list radically >increased in the last week? Anyone else considering blocking all gmail >posts to this list? Joan Miller is a regular poster; this is off-topic, but it's not spam. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From ben+python at benfinney.id.au Tue Feb 23 19:36:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 24 Feb 2010 11:36:08 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <87sk8r5v2f.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > Joan Miller is a regular poster; this is off-topic, but it's not spam. Non sequitur. Spam is spam, not by who authors or posts it, but by its distribution (to many people, e.g. via a forum like this one) and its content (off-topic and unsolicited). The message is important, its poster is a regular here; that doesn't stop the message being spam when posted here. -- \ ?Everyone is entitled to their own opinions, but they are not | `\ entitled to their own facts.? ?US Senator Pat Moynihan | _o__) | Ben Finney From lie.1296 at gmail.com Tue Feb 23 19:41:35 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 11:41:35 +1100 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: <4b8475df$1@dnews.tpgi.com.au> On 02/24/10 11:21, Aahz wrote: > In article , > D'Arcy J.M. Cain wrote: >> On Tue, 23 Feb 2010 02:54:25 -0800 (PST) >> Joan Miller wrote: >>> >>> *Sorry by this message off topic, but this is too important* >> >> Is it just me or has the spew from gmail on this list radically >> increased in the last week? Anyone else considering blocking all gmail >> posts to this list? > > Joan Miller is a regular poster; this is off-topic, but it's not spam. Does being a regular poster exempts you from having your post considered as spam? That's an http://en.wikipedia.org/wiki/Ad_hominem#Inverse_ad_hominem. From nobody at nowhere.com Tue Feb 23 20:03:23 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 24 Feb 2010 01:03:23 +0000 Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: On Mon, 22 Feb 2010 22:27:54 -0800, sjdevnull at yahoo.com wrote: > Basically, multiprocessing is always hard--but it's less hard to start > without shared everything. Going with the special case (sharing > everything, aka threading) is by far the stupider and more complex way > to approach multiprocssing. Multi-threading hardly shares anything (only dynamically-allocated and global data), while everything else (the entire stack) is per-thread. Yeah, I'm being facetious. Slightly. If you're going to write multi-threaded code, it's a good idea to wean yourself off of using global variables and shared mutable state. From nobody at nowhere.com Tue Feb 23 20:08:18 2010 From: nobody at nowhere.com (Nobody) Date: Wed, 24 Feb 2010 01:08:18 +0000 Subject: When will Java go mainstream like Python? References: Message-ID: On Wed, 24 Feb 2010 12:22:05 +1300, Lawrence D'Oliveiro wrote: >> Java - The JVM code been hacked to death by Sun engineers (optimised) >> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >> ad-infinitum but nowhere as near to JVM > > Python is still faster, though. I think a key reason is that its VM supports > reference-counting, which the Java folks never quite got the grasp of. So how does Python handle circular references? From rhodri at wildebst.demon.co.uk Tue Feb 23 20:11:48 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 24 Feb 2010 01:11:48 -0000 Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> <19c11c1f-d70e-4b10-b425-6e65d4c70aeb@d2g2000yqa.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 10:39:21 -0000, DANNY wrote: > @James I am thinkinhg about effect of errors that are within the > sequence of P frames. Where the P frames have only the information > about the changes in previous frames, so that errors are present until > the next I frame. So I would like to see how is this seen in different > GoP sized clips. Ah, I see. What I'd suggest you do is to encode your video clip at various GOP sizes (you'll want some quite extreme ones for comparison), then write a little program that reads in the file byte by byte and randomly corrupts the data as it goes through. "tsplay" from the tstools suite that I mentioned earlier will do that for you (because it was very handy for testing the robustness of our decoders). Then watch the results using VLC or similar. My recollection is that when the image isn't static, P frames tend to have enough intra-coded blocks that corrupted video data doesn't have as much effect as you might think. I've dealt with streams that had ten seconds or more between I frames, and starting at a random spot (simulating changing channel on your digital TV) builds up an intelligible (if obviously wrong) image surprisingly quickly. PS: my first name is Rhodri, not James. Don't worry, it catches a lot of people out. -- Rhodri James *-* Wildebeeste Herder to the Masses From lie.1296 at gmail.com Tue Feb 23 20:12:12 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 12:12:12 +1100 Subject: What's Going on between Python and win7? In-Reply-To: References: Message-ID: <4b847d0c$1@dnews.tpgi.com.au> On 02/23/10 05:30, W. eWatson wrote: > On 2/22/2010 8:29 AM, Grant Edwards wrote: >> On 2010-02-22, W. eWatson wrote: >> >>> Last night I copied a program from folder A to folder B. >> >> [tail of various windows breakages elided] >> >>> Comments? >> >> Switch to Linux? >> >> Or at least install Cygwin? >> > Yes, definitely not related, but maybe some W7 user has a similar > experience here. It seems a natural place to look, since it should be > reasonably common. IMHO that doesn't justify. The advice to move the discussion to a windows-specific group is not just about reducing off-topic discussion[1], but because there isn't that much Windows (Seven) users in this newsgroup. Most comp.lang.python users either uses linux, unix, macs, or older version of windows, and are not familiar with the specifics of Windows 7. It would be nice though, if you reposted the solution you found from another forum here to benefit other python Windows 7 users. [1] pretty much anything computer-related is not entirely off-topic in c.l.py because of the wide range of situations people uses python in (I've seen general algorithmic questions, text-editor wars, problems with 3rd party module, jython/ironpython internals, etc discussed in here; many of those gets quite welcomed even though technically off-topic) From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:15:40 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:15:40 GMT Subject: Bizarre arithmetic results References: <3fb9d59b-21c2-4372-9a32-c542e884faa7@x9g2000vbo.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 05:48:09 -0800, Mark Dickinson wrote: > On Feb 23, 8:11?am, Steven D'Aprano > wrote: >> Making spaces significant in that fashion is mind-bogglingly awful. >> Let's look at a language that does this: >> >> [steve at sylar ~]$ cat ws-example.rb >> def a(x=4) >> ? ? x+2 >> end >> >> b = 1 >> print (a + b), (a+b), (a+ b), (a +b), "\n" >> >> [steve at sylar ~]$ ruby ws-example.rb >> 7773 > > Hmm. That's pretty nasty, all right. Not that Python can claim to be > immune to such behaviour: > >>>> 3 .real > 3 >>>> 3. real > File "", line 1 > 3. real > ^ > SyntaxError: invalid syntax > > > Though the fact that one of the cases raises an exception (rather than > silently giving some different behaviour) ameliorates things a bit. It ameliorates it *completely* -- you won't get silent errors in Python because you add or delete whitespace around a dot. "I find it amusing when novice programmers believe their main job is preventing programs from crashing. ... More experienced programmers realize that correct code is great, code that crashes could use improvement, but incorrect code that doesn't crash is a horrible nightmare." http://www.pphsg.org/cdsmith/types.html The edge case occurs because dot does double-duty as an operator and as part of float literals. However, float literals never include whitespace: >>> 1.5 1.5 >>> 1 . 5 File "", line 1 1 . 5 ^ SyntaxError: invalid syntax and likewise for 1. 5 and 1 .5 -- the only way to get a float literal with a decimal point is by not including whitespace in it. So there is never any ambiguity about floats. You can even do this: >>> 1.5.__str__() '1.5' And since . is an operator outside of float literals, you can do this: >>> import sys >>> sys . platform 'linux2' although why you'd want to escapes me :) This actually is a feature, since it is useful when calling methods on int literals. However this is a very rare thing to do. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:30:17 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:30:17 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b841bf1$0$1632$742ec2ed@news.sonic.net> Message-ID: On Tue, 23 Feb 2010 10:35:38 -0800, John Nagle wrote: > The issue being discussed was scaling Python for CPUs with many cores. > With Intel shipping 4 cores/8 hyperthread CPUs, the 6/12 part working, > and the 8/16 part coming along, this is more than a theoretical issue. Have you tried parallelpython? http://www.parallelpython.com/ -- Steven From lie.1296 at gmail.com Tue Feb 23 20:30:41 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 12:30:41 +1100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <4b848161$1@dnews.tpgi.com.au> On 02/24/10 12:08, Nobody wrote: > On Wed, 24 Feb 2010 12:22:05 +1300, Lawrence D'Oliveiro wrote: > >>> Java - The JVM code been hacked to death by Sun engineers (optimised) >>> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >>> ad-infinitum but nowhere as near to JVM >> >> Python is still faster, though. I think a key reason is that its VM supports >> reference-counting, which the Java folks never quite got the grasp of. > > So how does Python handle circular references? There is an optional garbage collector built into the interpreter. Look at here on how it works: http://python.ca/nas/python/gc/ From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:31:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:31:47 GMT Subject: What's Going on between Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: On Tue, 23 Feb 2010 09:34:00 -0500, Jerry Hill wrote: > On Mon, Feb 22, 2010 at 8:25 PM, W. eWatson > wrote: >> So what's the bottom line? This link notion is completely at odds with >> XP, and produces what I would call something of a mess to the unwary >> Python/W7 user. Is there a simple solution? > > I know people went off on a tangent talking about symbolic links and > hard links, but it is extremely unlikely that you created something like > that by accident. Windows just doesn't create those without you doing > quite a bit of extra work. It certainly doesn't create them when you > drag & drop files around through the normal interface. I find it far more likely that Windows 7 makes it easy for the user to accidentally produce links rather than copies, rather than that Python suddenly has developed a bug where it opens a completely different file to the one you ask for. But more likely still is some confusion regarding paths. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:38:38 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:38:38 GMT Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: On Wed, 24 Feb 2010 00:06:09 +0100, Daniel Fetchinson wrote: >> Hmm. I wonder if all the spam is coming from the NG side. I'll have >> to look at that. One of the reasons that I stopped reading UseNet over >> ten years ago was because of the diminishinig S/N ratio. I have always >> felt that it was a mistake to gateway this group. > > And this has to do with python programming in what way? I think the question of whether or not comp.lang.python is being spammed, and if so, what we can do about it, is a good question to raise on comp.lang.python. Where else do you think it should be discussed? -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 20:41:26 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 01:41:26 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > By the way, if you want the variables inside myDict to be free > variables, you have to add them to the local namespace. The local > namespace is also a dictionary "locals()". So you can update locals as > follows: > > locals().update( myDictionary ) No you can't. Try it inside a function. -- Steven From m.12ahesh at gmail.com Tue Feb 23 20:50:55 2010 From: m.12ahesh at gmail.com (all in one) Date: Tue, 23 Feb 2010 17:50:55 -0800 (PST) Subject: PAPER PRESENTATIONS AND SEMIMAR TOPICS. Message-ID: PAPER PRESENTATIONS AND SEMIMAR TOPICS. CHECK OUR VAST PAPER PRESENTATIONS AND SEMIMAR TOPICS INCLUDING PROJECTS FOR FREE AT http://presentationsandseminars.blogspot.com From ssteinerx at gmail.com Tue Feb 23 20:53:37 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Tue, 23 Feb 2010 20:53:37 -0500 Subject: The future of "frozen" types as the number of CPU cores increases In-Reply-To: References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b841bf1$0$1632$742ec2ed@news.sonic.net> Message-ID: On Feb 23, 2010, at 8:30 PM, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 10:35:38 -0800, John Nagle wrote: > >> The issue being discussed was scaling Python for CPUs with many cores. >> With Intel shipping 4 cores/8 hyperthread CPUs, the 6/12 part working, >> and the 8/16 part coming along, this is more than a theoretical issue. > > Have you tried parallelpython? > > http://www.parallelpython.com/ I had not, have you used this successfully? Thanks, S From magawake at gmail.com Tue Feb 23 21:00:18 2010 From: magawake at gmail.com (Mag Gam) Date: Tue, 23 Feb 2010 21:00:18 -0500 Subject: compiling python question Message-ID: <1cbd6f831002231800gae705a9i48f781f7dec74ebe@mail.gmail.com> I am trying to compile python with Tk bindings. Do I need to do anything special for python to detect and enable Tk? This is mainly for matplotlib's TkAgg. It seems my compiled version of python isn't finding the module _tkagg From ldo at geek-central.gen.new_zealand Tue Feb 23 21:03:51 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 15:03:51 +1300 Subject: formatting a number as percentage References: <6819f2f8-7a9e-4ea4-a936-c4e00394bd30@g28g2000yqh.googlegroups.com> Message-ID: In message <6819f2f8-7a9e-4ea4-a936-c4e00394bd30 at g28g2000yqh.googlegroups.com>, vsoler wrote: > I'm trying to print .7 as 70% Just to be perverse: (lambda x : (lambda s : s[:s.index(".")] + s[s.index(".") + 1:] + "%")("%.2f" % x).lstrip("0"))(.7) :) From aahz at pythoncraft.com Tue Feb 23 21:04:49 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 18:04:49 -0800 Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: Message-ID: In article , W. eWatson wrote: > >My claim is that if one creates a program in a folder that reads a file >in the folder it and then copies it to another folder, it will read the >data file in the first folder, and not a changed file in the new folder. >I'd appreciate it if some w7 users could try this, and let me know what >they find. > >My experience is that if one checks the properties of the copied file, >it will point to the original py file and execute it and not the copy. I've no time to verify your specific claim and have no readily available proof for mine, but I've seen similar issues on Win7. AFAIK, this has nothing to do with Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:07:42 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:07:42 GMT Subject: Is this secure? References: Message-ID: On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: > Hello, > > I need to generate passwords and I think that pseudo-random generator is > not good enough, frankly. So I wrote this function: [snip] > (yes I know that this way generated string will not contain 'z' because > 99/4 + 97 = 121 which is 'y') You're worried about the security of the PRNG but then generate a TWO to FIVE character lowercase password with no digits, punctuation or the letter 'z'? That's priceless! Python's PRNG is not suitable for producing cryptographically strong streams of random bytes, but it is perfectly strong enough for generating good passwords. > The question is: is this secure? No. You are wasting your time trying to fix something which isn't a problem, and introducing a much bigger problem instead. You are MUCH MUCH MUCH better off with a six or ten character password taken from upper and lowercase letters, plus digits, plus punctuation, than a four digit password taken from lowercase letters only. Even if the first case has some subtle statistical deviation from uniformity, and the second is "truly random" (whatever that means), it doesn't matter. Nobody is going to crack your password because the password generator is 0.01% more likely to generate a "G" than a "q". But they *will* brute- force your password if you have a four digit password taken from a-y only. > That is, can the string generated this > way be considered truly random? Define truly random. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:19:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:19:31 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 23 Feb 2010 11:19:59 -0800, Paul Rubin wrote: > mk writes: >> I need to generate passwords and I think that pseudo-random generator >> is not good enough, frankly. So I wrote this function:... The question >> is: is this secure? That is, can the string generated this way be >> considered truly random? (I abstract from not-quite-perfect nature of >> /dev/urandom at the moment; I can always switch to /dev/random which is >> better) > > urandom is fine and the entropy loss from the numeric conversions and > eliminating 'z' in that code before you get letters out is not too bad. What? You're going from a possible alphabet of 62 (excluding punctuation) or 94 (inc punctuation available on an American keyboard) distinct letters down to 25, and you say that's "not too bad"? Paul, if you were anyone else, I'd be sneering uncontrollably about now, but you're not clueless about cryptography, so what have I missed? Why is reducing the number of distinct letters by more than 50% anything but a disaster? This makes the task of brute-forcing the password exponentially easier. Add the fact that the passwords are so short (as little as two characters in my tests) and this is about as far from secure as it is possible to be. -- Steven From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:21:41 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:21:41 GMT Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b841bf1$0$1632$742ec2ed@news.sonic.net> Message-ID: On Tue, 23 Feb 2010 20:53:37 -0500, ssteinerX at gmail.com wrote: >> Have you tried parallelpython? >> >> http://www.parallelpython.com/ > > I had not, have you used this successfully? Not personally, no. -- Steven From lie.1296 at gmail.com Tue Feb 23 21:22:46 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 13:22:46 +1100 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> Message-ID: <4b848d96$1@dnews.tpgi.com.au> On 02/24/10 12:38, Steven D'Aprano wrote: > On Wed, 24 Feb 2010 00:06:09 +0100, Daniel Fetchinson wrote: > >>> Hmm. I wonder if all the spam is coming from the NG side. I'll have >>> to look at that. One of the reasons that I stopped reading UseNet over >>> ten years ago was because of the diminishinig S/N ratio. I have always >>> felt that it was a mistake to gateway this group. >> >> And this has to do with python programming in what way? > > > I think the question of whether or not comp.lang.python is being spammed, > and if so, what we can do about it, is a good question to raise on > comp.lang.python. > > Where else do you think it should be discussed? comp.lang.python.spam_prevention_discussion From george.sakkis at gmail.com Tue Feb 23 21:26:21 2010 From: george.sakkis at gmail.com (George Sakkis) Date: Tue, 23 Feb 2010 18:26:21 -0800 (PST) Subject: When will Python go mainstream like Java? References: Message-ID: On Feb 23, 3:49?pm, mk wrote: > Well I for one wouldn't want Python to go exactly Java way, see this: > > http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=jav... > > This is the percentage of job offers in UK where the keyword "Java" appears. > > Same for C#, it looks like C# is eating Java's lunch now: > > http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csh... This seems to be a UK-specific trend; in the US (and most other countries I know of) Java is still going strong, e.g. http://www.indeed.com/jobtrends?q=java%2C+c%23&l= George From no.email at nospam.invalid Tue Feb 23 21:39:53 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 18:39:53 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: <7xbpff8ih2.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Paul, if you were anyone else, I'd be sneering uncontrollably about now, > but you're not clueless about cryptography, so what have I missed? Why is > reducing the number of distinct letters by more than 50% anything but a > disaster? This makes the task of brute-forcing the password exponentially > easier. Reducing the number of distinct letters by 50% decreases the entropy per character by 1 bit. That stuff about mixing letters and digits and funny symbols just makes the password a worse nuisance to remember and type, for a small gain in entropy that you can compute and make up for. The main thing you have to make sure is that the min-entropy is sufficient for your purposes, and it's generally more convenient to do that by making the password a little bit longer than by imposing contortions on the person typing it. Ross Anderson's "Security Engineering" chapter about passwords is worth reading too: http://www.cl.cam.ac.uk/~rja14/Papers/SE-03.pdf When I mentioned entropy loss to the OP though, I mostly meant loss from getting rid of the letter z. The (binary) Shannon entropy of the uniform probability distribution on 26 letters is 4.7004397 bits; on 25 letters, it's 4.6438561 bits. The difference isn't enough to give an attacker that much advantage. I like the diceware approach to passphrase generation and I've been using it for years. www.diceware.com explains it in detail and the docs there are quite well-thought-out and informative. Keep in mind that the entropy needed for an online password (attacker has to make a server query for every guess, and hopefully gets locked out after n wrong tries) and an offline one (attacker has something like a hash of the password and can run a completely offline search) are different. Here is a program that I use sometimes: from math import log dictfile = '/usr/share/dict/words' def genrandom(nbytes): with open('/dev/urandom') as f: return int(f.read(nbytes).encode('hex'), 16) def main(): wordlist = list(x.strip() for x in open(dictfile) if len(x) < 7) nwords = len(wordlist) print "%d words, entropy=%.3f bits/word"% ( nwords, log(nwords, 2)) print '-'.join(wordlist[genrandom(10)%nwords] for i in xrange(6)) main() From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:40:13 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:40:13 GMT Subject: Is this secure? References: Message-ID: On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: > The question is: is this secure? That is, can the string generated this > way be considered truly random? Putting aside the philosophical question of what "truly random" means, I presume you mean that the letters are uniformly distributed. The answer to that is, they don't like uniformly distributed. This isn't a sophisticated statistical test, it's the equivalent of a back-of-the-envelope calculation: I generated 100,000 random strings with your code, and counted how often each letter appears: If the letters are uniformly distributed, you would expect all the numbers to be quite close, but instead they range from 15063 to 25679: {'a': 15063, 'c': 20105, 'b': 15100, 'e': 25465, 'd': 25458, 'g': 25597, 'f': 25589, 'i': 25045, 'h': 25679, 'k': 22945, 'j': 25531, 'm': 16187, 'l': 16252, 'o': 16076, 'n': 16012, 'q': 16069, 'p': 16119, 's': 16088, 'r': 16087, 'u': 15951, 't': 16081, 'w': 16236, 'v': 15893, 'y': 15834, 'x': 15956} Eye-balling it, it looks vaguely two-humped, one hump around 15-16K, the second around 22-25K. Sure enough, here's a quick-and-dirty graph: a | *********************************** b | *********************************** c | *********************************************** d | *********************************************************** e | *********************************************************** f | ************************************************************ g | ************************************************************ h | ************************************************************ i | *********************************************************** j | ************************************************************ k | ****************************************************** l | ************************************** m | ************************************** n | ************************************* o | ************************************** p | ************************************** q | ************************************** r | ************************************** s | ************************************** t | ************************************** u | ************************************* v | ************************************* w | ************************************** x | ************************************* y | ************************************* The mean of the counts is 19056.72, and the mean deviation is 3992.28. While none of this is statistically sophisticated, it does indicate to me that your function is nowhere even close to uniform. It has a very strong bias. -- Steven From no.email at nospam.invalid Tue Feb 23 21:41:59 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 18:41:59 -0800 Subject: Is this secure? References: Message-ID: <7x7hq38idk.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Putting aside the philosophical question of what "truly random" means, I > presume you mean that the letters are uniformly distributed. The answer > to that is, they don't like uniformly distributed. That is a good point, the way those letters are generated (through the decimal conversion stuff), they won't be all that uniform. From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 21:43:05 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 02:43:05 GMT Subject: Is this secure? References: Message-ID: On Wed, 24 Feb 2010 02:40:13 +0000, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: > >> The question is: is this secure? That is, can the string generated this >> way be considered truly random? > > Putting aside the philosophical question of what "truly random" means, I > presume you mean that the letters are uniformly distributed. The answer > to that is, they don't like uniformly distributed. Er, they don't *look* uniformly distributed. (Of course, being random, perhaps they are and I just got unlucky.) -- Steven From no.email at nospam.invalid Tue Feb 23 21:50:52 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 18:50:52 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> Message-ID: <7x3a0r8hyr.fsf@ruckus.brouhaha.com> mk writes: >> You might look at the sitewww.diceware.comfor an approach to this, >> which you can implement with a program. ?The docs there are pretty >> thoughtful and may help you understand the relevant issues. > > Thanks. But I would also be grateful for indicating what is wrong/ugly > in my code. The stuff about converting 4 random bytes to a decimal string and then peeling off 2 digits at a time is pretty awful, and notice that since 2**32 is 4294967296, in the cases where you get 10 digits, the first 2-digit pair is never higher than 42. There are also some effects on the lower digits. The total entropy loss probably isn't fatal but as described, it's ugly. I'd write your code something like this: nletters = 5 def randomword(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a')+ord(c)%26) for c in f.read(n)]) print randomword(nletters) I wouldn't rely on a 5 letter combination for a high security application, but it might be ok for some low security purposes. Two random 5-letter combinations separated by a hyphen will be much better, and is probably easier to type than a solid block of 10 letters. From robert.kern at gmail.com Tue Feb 23 21:52:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 20:52:23 -0600 Subject: Spam from gmail (Was: fascism) In-Reply-To: <4b848d96$1@dnews.tpgi.com.au> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: On 2010-02-23 20:22 , Lie Ryan wrote: > On 02/24/10 12:38, Steven D'Aprano wrote: >> On Wed, 24 Feb 2010 00:06:09 +0100, Daniel Fetchinson wrote: >> >>>> Hmm. I wonder if all the spam is coming from the NG side. I'll have >>>> to look at that. One of the reasons that I stopped reading UseNet over >>>> ten years ago was because of the diminishinig S/N ratio. I have always >>>> felt that it was a mistake to gateway this group. >>> >>> And this has to do with python programming in what way? >> >> >> I think the question of whether or not comp.lang.python is being spammed, >> and if so, what we can do about it, is a good question to raise on >> comp.lang.python. >> >> Where else do you think it should be discussed? > > comp.lang.python.spam_prevention_discussion Which doesn't exist and never will. Sorry, but meta-discussions about the group are typically on-topic for all groups with some few exceptions (e.g. non-discussion, binary-only groups with associated .d groups, for instance). -- 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 Feb 23 22:09:36 2010 From: robert.kern at gmail.com (Robert Kern) Date: Tue, 23 Feb 2010 21:09:36 -0600 Subject: Is this secure? In-Reply-To: References: Message-ID: On 2010-02-23 20:43 , Steven D'Aprano wrote: > On Wed, 24 Feb 2010 02:40:13 +0000, Steven D'Aprano wrote: > >> On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: >> >>> The question is: is this secure? That is, can the string generated this >>> way be considered truly random? >> >> Putting aside the philosophical question of what "truly random" means, I >> presume you mean that the letters are uniformly distributed. The answer >> to that is, they don't like uniformly distributed. > > Er, they don't *look* uniformly distributed. > > (Of course, being random, perhaps they are and I just got unlucky.) You'd have to be very, *very* unlucky to get a sample of that size so far from uniformly distributed if the generating process actually were uniform. Of course, uniformity isn't really necessary. You just need enough entropy in the distribution (amongst other things like protection of the seed from being known or guessed). A skewed distribution of characters is perfectly fine provided that you had enough characters in the password to meet the desired entropy requirement. A skewed distribution does require more characters to meet a specified entropy requirement than a uniform distribution, of course. That said, for a naive strategy like "pick an independent random character, repeat", you should just use a uniform distribution. It makes the analysis easier. Worthwhile generators that give skewed distributions usually do so for a good reason, like generating pronounceable passwords. -- 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 lie.1296 at gmail.com Tue Feb 23 22:41:26 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Wed, 24 Feb 2010 14:41:26 +1100 Subject: Is this secure? In-Reply-To: References: Message-ID: <4b84a006$1@dnews.tpgi.com.au> On 02/24/10 14:09, Robert Kern wrote: > On 2010-02-23 20:43 , Steven D'Aprano wrote: >> On Wed, 24 Feb 2010 02:40:13 +0000, Steven D'Aprano wrote: >> >>> On Tue, 23 Feb 2010 15:36:02 +0100, mk wrote: >>> >>>> The question is: is this secure? That is, can the string generated this >>>> way be considered truly random? >>> >>> Putting aside the philosophical question of what "truly random" means, I >>> presume you mean that the letters are uniformly distributed. The answer >>> to that is, they don't like uniformly distributed. >> >> Er, they don't *look* uniformly distributed. >> >> (Of course, being random, perhaps they are and I just got unlucky.) > > You'd have to be very, *very* unlucky to get a sample of that size so > far from uniformly distributed if the generating process actually were > uniform. > > Of course, uniformity isn't really necessary. You just need enough > entropy in the distribution (amongst other things like protection of the > seed from being known or guessed). A skewed distribution of characters > is perfectly fine provided that you had enough characters in the > password to meet the desired entropy requirement. A skewed distribution > does require more characters to meet a specified entropy requirement > than a uniform distribution, of course. > > That said, for a naive strategy like "pick an independent random > character, repeat", you should just use a uniform distribution. It makes > the analysis easier. Worthwhile generators that give skewed > distributions usually do so for a good reason, like generating > pronounceable passwords. If an attacker knows the that the random number generator have an extreme skew and he knows the distribution of the letters, how much advantage would it give the attacker? My initial guess is that the more skewed the letters are, the better the advantage, since an attacker using brute-force can write his program to prefer the most likely letters? From luismgz at gmail.com Tue Feb 23 22:47:22 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 19:47:22 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Feb 23, 10:41?pm, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > > By the way, if you want the variables inside myDict to be free > > variables, you have to add them to the local namespace. The local > > namespace is also a dictionary "locals()". So you can update locals as > > follows: > > > ? ? locals().update( myDictionary ) > > No you can't. Try it inside a function. > > -- > Steven Sure. Inside a function I would use globals() instead. Although I don't know if it would be a good practice... Luis From no.email at nospam.invalid Tue Feb 23 22:51:53 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 19:51:53 -0800 Subject: Is this secure? References: <4b84a006$1@dnews.tpgi.com.au> Message-ID: <7xwry39tpi.fsf@ruckus.brouhaha.com> Lie Ryan writes: > If an attacker knows the that the random number generator have an > extreme skew and he knows the distribution of the letters, how much > advantage would it give the attacker? My initial guess is that the more > skewed the letters are, the better the advantage, since an attacker > using brute-force can write his program to prefer the most likely letters? A useable (conservative) estimate is that the attacker's workload is 1/p where p is the probability of the most likely password. That basically says the password strength can be measured by the min-entropy. Cryptographers often use that approach. If you want to be more precise, you can do a conditional probability calculation assuming the attacker works down the list of possible passwords in order of decreasing probability, stopping when they hit the right one. More generally still, passwords regardless of their entropy content are a sucky way to encapsulate cryptographic secrets. We keep using them because every alternative has drawbacks of its own. From rpdooling at gmail.com Tue Feb 23 22:53:03 2010 From: rpdooling at gmail.com (Rick Dooling) Date: Tue, 23 Feb 2010 19:53:03 -0800 (PST) Subject: Verifying My Troublesome Linkage Claim between Python and Win7 References: <574f6097-62f4-4bef-ad96-7185c8b872b1@c2g2000vbl.googlegroups.com> Message-ID: On Feb 23, 1:08?pm, Gib Bogle wrote: > It isn't useful to respond to a serious question with OS bigotry. Okay, I'll go with what Aahz said: > I've seen similar issues on Win7. > AFAIK, this has nothing to do with Python. From invalid at invalid.invalid Tue Feb 23 23:09:18 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 24 Feb 2010 04:09:18 +0000 (UTC) Subject: Spam from gmail (Was: fascism) References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: On 2010-02-24, Robert Kern wrote: >> comp.lang.python.spam_prevention_discussion > > Which doesn't exist and never will. Sorry, but > meta-discussions about the group are typically on-topic for > all groups with some few exceptions (e.g. non-discussion, > binary-only groups with associated .d groups, for instance). Since now we are discussing meta-discussions, is this now a meta-meta-discussion? -- Grant From steven at REMOVE.THIS.cybersource.com.au Tue Feb 23 23:15:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 04:15:31 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > On Feb 23, 10:41?pm, Steven D'Aprano > wrote: >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: >> > By the way, if you want the variables inside myDict to be free >> > variables, you have to add them to the local namespace. The local >> > namespace is also a dictionary "locals()". So you can update locals >> > as follows: >> >> > ? ? locals().update( myDictionary ) >> >> No you can't. Try it inside a function. >> >> -- >> Steven > > Sure. Inside a function I would use globals() instead. Although I don't > know if it would be a good practice... Er, how does using globals change the local variables? -- Steven From wolftracks at invalid.com Tue Feb 23 23:16:37 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 20:16:37 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA In-Reply-To: References: Message-ID: <4B84A825.1030407@invalid.com> On 2/23/2010 2:50 PM, Aahz wrote: > In article, > W. eWatson wrote: >> >> Anyone here going to the meeting,Subject? As far as I can tell, it meets >>from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >> be an informal group dinner at 6 pm at some place yet unknown. Comments? > > Subscribe to http://mail.python.org/mailman/listinfo/baypiggies Thanks. I'd appreciate it if you tell me what topic is. I belong to too many mail lists. Thursday will be my first meeting. Perhaps I'll change my mind about ML after a meeting. Can you describe anything more than the topic? Do they have books, videos, tutorials (live), casual Q/A, person-to-person chat before the speaker? From wolftracks at invalid.com Tue Feb 23 23:16:51 2010 From: wolftracks at invalid.com (W. eWatson) Date: Tue, 23 Feb 2010 20:16:51 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA In-Reply-To: References: Message-ID: On 2/23/2010 2:50 PM, Aahz wrote: > In article, > W. eWatson wrote: >> >> Anyone here going to the meeting,Subject? As far as I can tell, it meets >>from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >> be an informal group dinner at 6 pm at some place yet unknown. Comments? > > Subscribe to http://mail.python.org/mailman/listinfo/baypiggies Thanks. I'd appreciate it if you tell me what topic is. I belong to too many mail lists. Thursday will be my first meeting. Perhaps I'll change my mind about ML after a meeting. Can you describe anything more than the topic? Do they have books, videos, tutorials (live), casual Q/A, person-to-person chat before the speaker? From luismgz at gmail.com Tue Feb 23 23:44:10 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Tue, 23 Feb 2010 20:44:10 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> On Feb 24, 1:15?am, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > > On Feb 23, 10:41?pm, Steven D'Aprano > > wrote: > >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > >> > By the way, if you want the variables inside myDict to be free > >> > variables, you have to add them to the local namespace. The local > >> > namespace is also a dictionary "locals()". So you can update locals > >> > as follows: > > >> > ? ? locals().update( myDictionary ) > > >> No you can't. Try it inside a function. > > >> -- > >> Steven > > > Sure. Inside a function I would use globals() instead. Although I don't > > know if it would be a good practice... > > Er, how does using globals change the local variables? > > -- > Steven Hmmm.... well, you tell me! As I said, I don't know if this is the recomended way... Luis From ldo at geek-central.gen.new_zealand Tue Feb 23 23:48:59 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Wed, 24 Feb 2010 17:48:59 +1300 Subject: Is this secure? References: <4b84a006$1@dnews.tpgi.com.au> <7xwry39tpi.fsf@ruckus.brouhaha.com> Message-ID: In message <7xwry39tpi.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > More generally still, passwords regardless of their entropy content are > a sucky way to encapsulate cryptographic secrets. They?re a shared secret. How else would you represent a shared secret, if not with a shared secret? From loudoillond522 at gmail.com Wed Feb 24 00:27:52 2010 From: loudoillond522 at gmail.com ("Lou " Shy Amateur Strips) Date: Tue, 23 Feb 2010 21:27:52 -0800 (PST) Subject: %%% daughter fucked her x-boy friend in front of her father %%% " FREE Live shows also available" Message-ID: <8895961a-dec1-4e4e-95a5-0b116fbec24c@e19g2000prn.googlegroups.com> %%% daughter fucked her x-boy friend in front of her father %%% " FREE Live shows also available" http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ From aahz at pythoncraft.com Wed Feb 24 01:03:41 2010 From: aahz at pythoncraft.com (Aahz) Date: 23 Feb 2010 22:03:41 -0800 Subject: Bay Area PUG Meeting Thursday in Mountain View, CA References: <4B84A825.1030407@invalid.com> Message-ID: In article <4B84A825.1030407 at invalid.com>, W. eWatson wrote: >On 2/23/2010 2:50 PM, Aahz wrote: >> In article, >> W. eWatson wrote: >>> >>> Anyone here going to the meeting,Subject? As far as I can tell, it meets >>>from 7:30 to 9 pm. Their site shows no speaker yet, and there seems to >>> be an informal group dinner at 6 pm at some place yet unknown. Comments? >> >> Subscribe to http://mail.python.org/mailman/listinfo/baypiggies > >Thanks. I'd appreciate it if you tell me what topic is. I belong to too >many mail lists. Thursday will be my first meeting. Perhaps I'll change >my mind about ML after a meeting. Can you describe anything more than >the topic? Do they have books, videos, tutorials (live), casual Q/A, >person-to-person chat before the speaker? Sorry, I don't know offhand; using the mailing list is your best bet. (BayPIGgies is usually not a high-traffic list.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From mattbarkan at gmail.com Wed Feb 24 01:07:48 2010 From: mattbarkan at gmail.com (MattB) Date: Tue, 23 Feb 2010 22:07:48 -0800 (PST) Subject: Can't Access ANY url from python (errno 61) References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <4b807791$0$8819$c3e8da3@news.astraweb.com> Message-ID: <99bd0874-3462-4bb3-8c3c-54b73c88f9a6@q16g2000yqq.googlegroups.com> On Feb 20, 7:00?pm, Steven D'Aprano wrote: > On Sat, 20 Feb 2010 18:28:16 +0000, Martin P. Hellwig wrote: > > On 02/20/10 00:20, MattB wrote: > > > > >> Also, based on Martin's comment, I just wanted to make you all aware > >> that I intend no misuse, but rather am just trying to learn, as I'm a > >> programming noob. > > > > It wasn't my intention to imply that, rather the opposite, that if some > > BOFH would see your action as misuse (some admins are pretty trigger > > happy), you would expect them to contact you directly (I would). Even > > though you are on a wireless there are ways to track you down. For > > example I would search my log to see if I can make an association > > between a login to one of my servers and your mac address. > > This may be what you would do, but in my experience, it is more likely > that the admin would be far too busy and/or lazy to try to track you down > unless (1) they wanted to give you a warning prior to expulsion, or (2) > they needed to know who you were prior to laying charges. > > In my experience they're far more likely to just hit the problem with a > hammer by blocking you as much as is technically possible. > > > BTW, I always followed the philosophy that learning is much more fun if > > you can brake/blow something up. Thus on my networks all students had a > > lot of freedom to do whatever they think was appropriate but they where > > aware that every action on my network was monitored and logged. > > Unfortunately this is the exception rather than the rule, I think. > > -- > Steven All -- problem solved. Following Lie's suggestions, and the links from those pages, I went hunting around in my /library/preferences/ SystemConfiguration/. I opened all of the 6 or 7 files that were in there, and all looked as if they contained info directly related to my airport card -- networks, server names, etc. So I copied them to a backup folder and then deleted them. Then I rebooted. Then I opened IDLE and was able to raise URLs again. I'm not sure what it was about those files (or maybe a specific one) -- does anyone have any ideas? Thanks for your help and suggestions while I tried to figure this out. From sjdevnull at yahoo.com Wed Feb 24 01:31:59 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Tue, 23 Feb 2010 22:31:59 -0800 (PST) Subject: The future of "frozen" types as the number of CPU cores increases References: <4b7af8ba$0$1630$742ec2ed@news.sonic.net> <4b7d97dc$0$1587$742ec2ed@news.sonic.net> <1fdbcbf0-79c4-4f93-9e0f-92ee29aebe6c@d2g2000yqa.googlegroups.com> <4b809d57$0$1596$742ec2ed@news.sonic.net> <31029472-0e50-428c-b657-edfbd8be9e3b@v25g2000yqk.googlegroups.com> <4b83383b$0$1622$742ec2ed@news.sonic.net> Message-ID: <6d75d20c-4028-42ef-9c45-ad118e315139@z11g2000yqz.googlegroups.com> On Feb 23, 8:03?pm, Nobody wrote: > On Mon, 22 Feb 2010 22:27:54 -0800, sjdevn... at yahoo.com wrote: > > Basically, multiprocessing is always hard--but it's less hard to start > > without shared everything. ?Going with the special case (sharing > > everything, aka threading) is by far the stupider and more complex way > > to approach multiprocssing. > > Multi-threading hardly shares anything (only dynamically-allocated > and global data), while everything else (the entire stack) is per-thread. > > Yeah, I'm being facetious. Slightly. I'm afraid I may be missing the facetiousness here. The only definitional difference between threads and processes is that threads share memory, while processes don't. There are often other important practical implementation details, but sharing memory vs not sharing memory is the key theoretical distinction between threads and processes. On most platforms, whether or not you want to share memory (and abandon memory protection wrt the rest of the program) is the key factor a programmer should consider when deciding between threads and processes--the only time that's not true is when the implementation forces ancillary details upon you. From enleverLesX_XXmcX at XmclavXeauX.com.invalid Wed Feb 24 01:41:50 2010 From: enleverLesX_XXmcX at XmclavXeauX.com.invalid (Michel Claveau - MVP) Date: Wed, 24 Feb 2010 07:41:50 +0100 Subject: python shell crashing on paste References: <1ede46e4-8ca1-4fe0-ad3f-7e781bbe1182@b36g2000pri.googlegroups.com> Message-ID: <4b84ca31$0$15832$ba4acef3@reader.news.orange.fr> Hi! Where (directory) are you, when the problem come? Have you try with UAC disabled? @+ -- MCI From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 02:08:19 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 07:08:19 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> Message-ID: On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. Gonz?lez wrote: > On Feb 24, 1:15?am, Steven D'Aprano > wrote: >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: >> > On Feb 23, 10:41?pm, Steven D'Aprano >> > wrote: >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: >> >> > By the way, if you want the variables inside myDict to be free >> >> > variables, you have to add them to the local namespace. The local >> >> > namespace is also a dictionary "locals()". So you can update >> >> > locals as follows: >> >> >> > ? ? locals().update( myDictionary ) >> >> >> No you can't. Try it inside a function. >> >> >> -- >> >> Steven >> >> > Sure. Inside a function I would use globals() instead. Although I >> > don't know if it would be a good practice... >> >> Er, how does using globals change the local variables? >> >> -- >> Steven > > Hmmm.... well, you tell me! I'm not the one that said you can update locals! You said it. I said you can't, because you *can't*. The docs warn that you can't change locals, and if you try it, you will see that the docs are right. >>> def test(): ... x = 1 ... locals().update(x = 2) ... print x ... >>> >>> test() 1 > As I said, I don't know if this is the recomended way... It's not recommended because it doesn't work. -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 02:11:01 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 24 Feb 2010 07:11:01 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7xbpff8ih2.fsf@ruckus.brouhaha.com> Message-ID: On Tue, 23 Feb 2010 18:39:53 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> Paul, if you were anyone else, I'd be sneering uncontrollably about >> now, but you're not clueless about cryptography, so what have I missed? >> Why is reducing the number of distinct letters by more than 50% >> anything but a disaster? This makes the task of brute-forcing the >> password exponentially easier. > > Reducing the number of distinct letters by 50% decreases the entropy per > character by 1 bit. You say that as if 1 bit of entropy isn't much :) Given a random six character password taken out of an alphabet of 52 characters, it takes over nine billion attempts to brute force it. Reducing the alphabet by 50% cuts that down to less than 200 million. To make up for that loss of 1 bit of entropy, you need two extra characters in your password. > That stuff about mixing letters and digits and > funny symbols just makes the password a worse nuisance to remember and > type, for a small gain in entropy that you can compute and make up for. Well, everybody has their own ways of remembering passwords, and I'd much prefer to remember an eight character password with "funny symbols" that I chose myself, than a six character password with nothing but letters that was chosen for me. Of course, I flatter myself that I know how to choose good passwords, and I hate remembering long random strings even from a reduced alphabet (e.g. I hate memorizing eight digit phone numbers, and am completely incapable of remembering ten digit mobile phone numbers). -- Steven From no.email at nospam.invalid Wed Feb 24 02:58:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 23 Feb 2010 23:58:30 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7xbpff8ih2.fsf@ruckus.brouhaha.com> Message-ID: <7xljejgj4p.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > Given a random six character password taken out of an alphabet of 52 > characters, it takes over nine billion attempts to brute force it. > Reducing the alphabet by 50% cuts that down to less than 200 million. To > make up for that loss of 1 bit of entropy, you need two extra characters > in your password. One extra character comes pretty close (within 1.3 bits). Even two extra chars is probably (subjective) easier for a user to deal with than a completely random mixture of upper/lower case. You don't get the extra bit per character if that distribution is anything other than random, of course. For something like a web password (each guess takes a server hit), where the resource guarded is not very valuable, 5 chars is probably enough for most purposes. For something like an encryption key subject to offline attacks, 6 mixed-case characters will barely slow a real attacker down. As before, my suggestion is still diceware. I've used random alphanumerics in the past but they're too big a hassle, they have to be written down, etc. And of course, if you're doing something serious, use a hardware token. From danijel.gvero at gmail.com Wed Feb 24 03:28:12 2010 From: danijel.gvero at gmail.com (DANNY) Date: Wed, 24 Feb 2010 00:28:12 -0800 (PST) Subject: MODULE FOR I, P FRAME References: <52e7499a-9389-4cfc-8d1b-34c1c3c68cac@l19g2000yqb.googlegroups.com> <60tpn5tts8mq2v47lchuqcg7ffceu4d94l@4ax.com> <51901a8c-8f80-4e78-98ce-75d6b521ecc5@b2g2000yqi.googlegroups.com> <0db2e6a3-dbad-43d5-b1e4-362b200ebc6a@y17g2000yqd.googlegroups.com> <19c11c1f-d70e-4b10-b425-6e65d4c70aeb@d2g2000yqa.googlegroups.com> Message-ID: <3299bfaf-e8d9-4340-a339-e8a8d31c2fa9@f42g2000yqn.googlegroups.com> On Feb 24, 3:11?am, "Rhodri James" wrote: > On Tue, 23 Feb 2010 10:39:21 -0000, DANNY wrote: > > @James I am thinkinhg about effect of errors that are within the > > sequence of P frames. Where the P frames have only the information > > about the changes in previous frames, so that errors are present until > > the next Iframe. So I would like to see how is this seen in different > > GoP sized clips. > > Ah, I see. ?What I'd suggest you do is to encode your video clip at ? > various GOP sizes (you'll want some quite extreme ones for comparison), ? > then write a little program that reads in the file byte by byte and ? > randomly corrupts the data as it goes through. ?"tsplay" from the tstools ? > suite that I mentioned earlier will do that for you (because it was very ? > handy for testing the robustness of our decoders). ?Then watch the results ? > using VLC or similar. > > My recollection is that when the image isn't static, P frames tend to have ? > enough intra-coded blocks that corrupted video data doesn't have as much ? > effect as you might think. ?I've dealt with streams that had ten seconds ? > or more between I frames, and starting at a random spot (simulating ? > changing channel on your digital TV) builds up an intelligible (if ? > obviously wrong) image surprisingly quickly. > > PS: my first name is Rhodri, not James. ?Don't worry, it catches a lot of ? > people out. > > -- > Rhodri James *-* Wildebeeste Herder to the Masses Well for my simulation of errors I am thinking on using the WANem (Wide Area Netwrok Emulator) which has a function to simulate dellay, jitter etc.. http://wanem.sourceforge.net/ I have been downloading the clips from youtube and I surprisengly saw that I frame occures after 300 frames(at 15fps-so that means after 20 seconds)! That was quite unusal for my perception of the purpose of I frame, but then I figured out that (as you mentioned) P frames include intra-coded blocks which hide the effect of the errors. The goal of my project is to make a program which plays the corrupted video after being out thru error concealment, and in case when errors overcome some threshold error value the program doesn't paly any more frames until the I frame occures and then I would figure out the optimal threshold value for the different GoP sizes as well as different content of the clip. From greg.ewing at canterbury.ac.nz Wed Feb 24 03:33:44 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 24 Feb 2010 21:33:44 +1300 Subject: ANN: Pyrex 0.9.8.6 Message-ID: Pyrex 0.9.8.6 is now available: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/ Numerous bug fixes and a few improvements. See the CHANGES page on the web site for details. What is Pyrex? -------------- Pyrex is a language for writing Python extension modules. It lets you freely mix operations on Python and C data, with all Python reference counting and error checking handled automatically. From baptiste.lepilleur at gmail.com Wed Feb 24 03:37:19 2010 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Wed, 24 Feb 2010 09:37:19 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? Message-ID: I stumbled uppon this and find it somewhat odd: some class methods of TarFile and TarInfo do not appears in either the online documentation or search while they have a doc string: http://docs.python.org/search.html?q=gzopen http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile See script at the end for list of class methods. Is this "by design" or is there some an odd bug in doc generation lurking around? This somehow seem to be specific to module tarfile. Fraction classmethod from_float() is available in the documentation and found by a search for example... --- Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tarfile >>> help( tarfile.TarFile.gzopen ) Help on method gzopen in module tarfile: gzopen(cls, name, mode='r', fileobj=None, compresslevel=9, **kwargs) method of __builtin__.type instance Open gzip compressed tar archive name for reading or writing. Appending is not allowed. >>> help( tarfile.TarFile.bz2open ) Help on method bz2open in module tarfile: bz2open(cls, name, mode='r', fileobj=None, compresslevel=9, **kwargs) method of __builtin__.type instance Open bzip2 compressed tar archive name for reading or writing. Appending is not allowed. >>> help( tarfile.TarInfo.create_pax_global_header ) Help on method create_pax_global_header in module tarfile: create_pax_global_header(cls, pax_headers) method of __builtin__.type instance Return the object as a pax global header block sequence. Baptiste. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kidhvfhgi at gmail.com Wed Feb 24 03:58:46 2010 From: kidhvfhgi at gmail.com (hhuifhiu ijuihuh) Date: Wed, 24 Feb 2010 00:58:46 -0800 (PST) Subject: Watch nude girls fucking and sucking the cocks. Girls shaving their pussies, boys giving shots on the pussies and licking them. Also watch girls getting fucked on a car roof, a girl banged by a gang of four members. At the end the girl collect Message-ID: <3b25b8ae-1917-43ce-b3fa-098a83e41ad5@k5g2000pra.googlegroups.com> Watch nude girls fucking and sucking the cocks. Girls shaving their pussies, boys giving shots on the pussies and licking them. Also watch girls getting fucked on a car roof, a girl banged by a gang of four members. At the end the girl collects sperms from all four mens penis in her mouth and swallows it. http://sites.google.com/site/niceglamourz http://sites.google.com/site/niceglamourz http://sites.google.com/site/niceglamourz From dieter at handshake.de Wed Feb 24 04:11:25 2010 From: dieter at handshake.de (Dieter Maurer) Date: 24 Feb 2010 10:11:25 +0100 Subject: Use eval() safely? In-Reply-To: References: <7uejcjFgf6U1@mid.individual.net> Message-ID: Steven D'Aprano writes on 22 Feb 2010 06:07:05 GMT: > ... > It's *especially* not safe if you put nothing in the globals dict, > because Python kindly rectifies that by putting the builtins into it: > > >>> eval("__builtins__.keys()", {}, {}) > ['IndexError', 'all', 'help', 'vars', ... 'OverflowError'] > > > >>> eval("globals()", {}, {}) > {'__builtins__': {...}} > >>> > >>> eval("globals()", {'__builtins__': None}, {}) > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in > NameError: name 'globals' is not defined > > So {'__builtins__': None} is safer than {}. Still not safe, exactly, but > safer. Or at least you make the Black Hats work harder before they own > your server :) Using functionality introduced with the class/type homogenization, it is quite easy to get access to the "file" type (even when "__builtins__" is disabled). Having "file", arbitrary files can be read, written, destroyed... Dieter From eckhardt at satorlaser.com Wed Feb 24 04:15:17 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 24 Feb 2010 10:15:17 +0100 Subject: while loop with the condition used in the body Message-ID: <6a7f57-hj1.ln1@satorlaser.homedns.org> Hi! I'm looking for a way to write code similar to this C code: while(rq = get_request(..)) { handle_request(rq); } Currently I'm doing while True: rq = get_request(...) if not rq: break handle_request(rq) in Python 2.6. Any suggestions how to rewrite that? Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From jeanmichel at sequans.com Wed Feb 24 04:17:23 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Feb 2010 10:17:23 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: Message-ID: <4B84EEA3.2090104@sequans.com> Arnaud Delobelle wrote: > lallous writes: > > >> Hello >> >> How can I do something similar to pure virtual functions in C++ ? >> >> Let us consider this: >> >> class C1: >> >> # Pure virtual >> def cb(self, param1, param2): >> """ >> This is a callback >> >> @param param1: ... >> @param param2: ... >> """ >> raise NotImplementedError, "Implement me" >> > > Why define it if it is virtual? > Slightly off topic but this is often useful when writing interfaces. You can then properly document what should any subclass (interface implemention) be doing. The thing is that in case of virtual methods, you *do want* to raise the notImplemented exceptions, meaning you've failed to implement all the required methods. Strange thing that the OP want to silently call nothing at all when calling a virtual method, he looses all the benefits from a virtual design. Anyway, I don't deal into code optimization, this is not healthy :-) JM From nandini.sharma84 at gmail.com Wed Feb 24 04:18:18 2010 From: nandini.sharma84 at gmail.com (nandini) Date: Wed, 24 Feb 2010 01:18:18 -0800 (PST) Subject: Why One Should Go for Online Tech Support Message-ID: Being a computer user, you almost every day make calls to your local technician to repair your day to day PC problems such as operating system issues, computer security problem, browser & email issues, network and peripheral support. But hardly have you got your computer repaired right away and even if your computer gets repaired immediately, you cannot be assured of the quality of service provided. And most importantly, like every other machine, computers too need regular maintenance but a local technician cannot promise for the same. Apart from this, you would have to pay your tech support provider for his every visit, which sums up a heavy amount; sometimes going beyond the limitation of your budget. At the point in time, you must consider availing an online tech support service. Offered on onetime payment scheme, online tech support services are provided by numerous companies all across the globe. These companies hire eminent Microsoft certified engineers as technicians, who offer best services within moments. Including this, there are many more benefits of services offered by online tech support providers, such as ? * An inclusive range of tech support services on much lower prices. * Complete maintenance of your computer * A completely secured support * Instant fix for your computer For Further information please visit http://www.pccare247.com From arnodel at googlemail.com Wed Feb 24 05:07:00 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 24 Feb 2010 02:07:00 -0800 (PST) Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: <1909640d-b6d2-43df-bcee-ae523d92f3bc@l19g2000yqb.googlegroups.com> Ulrich Eckhardt wrote: > Hi! > > I'm looking for a way to write code similar to this C code: > > while(rq = get_request(..)) { > handle_request(rq); > } > > Currently I'm doing > > while True: > rq = get_request(...) > if not rq: > break > handle_request(rq) > > in Python 2.6. Any suggestions how to rewrite that? > This is the common idiom. -- Arnaud From lars at gustaebel.de Wed Feb 24 05:14:24 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Wed, 24 Feb 2010 11:14:24 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: References: Message-ID: <20100224101423.GA27668@axis.g33x.de> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: > I stumbled uppon this and find it somewhat odd: some class methods of > TarFile and TarInfo do not appears in either the online documentation or > search while they have a doc string: > > http://docs.python.org/search.html?q=gzopen > http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile > > See script at the end for list of class methods. > > Is this "by design" or is there some an odd bug in doc generation lurking > around? This somehow seem to be specific to module tarfile. Fraction > classmethod from_float() is available in the documentation and found by a > search for example... First of all, Python's module documentation is not generated from module docstrings, each module has its own rst text file in the documentation tree instead. But to answer your question: Yes, this is intentional. The TarFile class has three classmethods taropen(), gzopen(), and bz2open() each for a specific compression method. These three are used internally by the TarFile.open() classmethod and are not intended to be called directly. The TarFile.open() method is the one that is publicly documented and supposed to be used. It decides which of the three methods to use based on the mode argument and does many more other high-level things as well. Regards, -- Lars Gust?bel lars at gustaebel.de I do not care to belong to a club that accepts people like me as members. (Groucho Marx) From __peter__ at web.de Wed Feb 24 05:21:36 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Feb 2010 11:21:36 +0100 Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Ulrich Eckhardt wrote: > I'm looking for a way to write code similar to this C code: > > while(rq = get_request(..)) { > handle_request(rq); > } > > Currently I'm doing > > while True: > rq = get_request(...) > if not rq: > break > handle_request(rq) > > in Python 2.6. Any suggestions how to rewrite that? Assuming get_request(...) is called with the same arguments on each iteration and uses None to signal that there is no more data: from functools import partial for rq in iter(partial(get_request, ...), None): handle_request(rq) Peter From jeanmichel at sequans.com Wed Feb 24 05:28:13 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 24 Feb 2010 11:28:13 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4B84FF3D.1010403@sequans.com> Michael Rudolf wrote: > Just a quick question about what would be the most pythonic approach > in this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > > >>> def a(): > pass > >>> def a(x): > pass > >>> a() > Traceback (most recent call last): > File "", line 1, in > a() > TypeError: a() takes exactly 1 argument (0 given) > > So - What would be the most pythonic way to emulate this? > Is there any better Idom than: > > >>> def a(x=None): > if x is None: > pass > else: > pass > > ? > > Thanks, > Michael This is the way to do it python, and it has its advantages: 1 docstring, 1 way do do it, 1 interface. JM From duncan.booth at invalid.invalid Wed Feb 24 05:31:48 2010 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 24 Feb 2010 10:31:48 GMT Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Peter Otten <__peter__ at web.de> wrote: > Ulrich Eckhardt wrote: > >> I'm looking for a way to write code similar to this C code: >> >> while(rq = get_request(..)) { >> handle_request(rq); >> } >> > Assuming get_request(...) is called with the same arguments on each > iteration and uses None to signal that there is no more data: > > from functools import partial > > for rq in iter(partial(get_request, ...), None): > handle_request(rq) > > Peter and the next step on from this is to realise that the problem isn't how to code the calls to get_request(), the problem is actually that get_request() itself isn'ty Pythonic. Rewrite it as a generator, rename it to reflect that it now generates a sequence of requests and the code becomes: for rq in incoming_requests(...): handle_request(rq) -- Duncan Booth http://kupuguy.blogspot.com From __peter__ at web.de Wed Feb 24 05:38:33 2010 From: __peter__ at web.de (Peter Otten) Date: Wed, 24 Feb 2010 11:38:33 +0100 Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Duncan Booth wrote: > Peter Otten <__peter__ at web.de> wrote: > >> Ulrich Eckhardt wrote: >> >>> I'm looking for a way to write code similar to this C code: >>> >>> while(rq = get_request(..)) { >>> handle_request(rq); >>> } >>> >> Assuming get_request(...) is called with the same arguments on each >> iteration and uses None to signal that there is no more data: >> >> from functools import partial >> >> for rq in iter(partial(get_request, ...), None): >> handle_request(rq) >> >> Peter > > and the next step on from this is to realise that the problem isn't how to > code the calls to get_request(), the problem is actually that > get_request() itself isn'ty Pythonic. Rewrite it as a generator, rename it > to reflect that it now generates a sequence of requests and the code > becomes: > > for rq in incoming_requests(...): > handle_request(rq) ...and a likely implementation would be def incoming_requests(...): while True: rq = ... # inlined version of get_request() if not rq: break yield rq In other words: It's turtles all the way down... Peter From luismgz at gmail.com Wed Feb 24 05:44:52 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 24 Feb 2010 02:44:52 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> Message-ID: On Feb 24, 4:08?am, Steven D'Aprano wrote: > On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. Gonz?lez wrote: > > On Feb 24, 1:15?am, Steven D'Aprano > > wrote: > >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > >> > On Feb 23, 10:41?pm, Steven D'Aprano > >> > wrote: > >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > >> >> > By the way, if you want the variables inside myDict to be free > >> >> > variables, you have to add them to the local namespace. The local > >> >> > namespace is also a dictionary "locals()". So you can update > >> >> > locals as follows: > > >> >> > ? ? locals().update( myDictionary ) > > >> >> No you can't. Try it inside a function. > > >> >> -- > >> >> Steven > > >> > Sure. Inside a function I would use globals() instead. Although I > >> > don't know if it would be a good practice... > > >> Er, how does using globals change the local variables? > > >> -- > >> Steven > > > Hmmm.... well, you tell me! > > I'm not the one that said you can update locals! You said it. I said you > can't, because you *can't*. The docs warn that you can't change locals, > and if you try it, you will see that the docs are right. > > >>> def test(): > > ... ? ? x = 1 > ... ? ? locals().update(x = 2) > ... ? ? print x > ... > > >>> test() > > 1 > > > As I said, I don't know if this is the recomended way... > > It's not recommended because it doesn't work. > > -- > Steven I guess I have to check the docs... Anyway, nobody wanted to update locals() from within a function here. Doing it outside of a function seems to work. And updating globals() works in any case, which is what the OP seems to need. Isn't it? Luis From luismgz at gmail.com Wed Feb 24 05:58:38 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 24 Feb 2010 02:58:38 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> Message-ID: <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> On Feb 24, 7:44?am, Luis M. Gonz?lez wrote: > On Feb 24, 4:08?am, Steven D'Aprano > > > > > > wrote: > > On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. Gonz?lez wrote: > > > On Feb 24, 1:15?am, Steven D'Aprano > > > wrote: > > >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. Gonz?lez wrote: > > >> > On Feb 23, 10:41?pm, Steven D'Aprano > > >> > wrote: > > >> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: > > >> >> > By the way, if you want the variables inside myDict to be free > > >> >> > variables, you have to add them to the local namespace. The local > > >> >> > namespace is also a dictionary "locals()". So you can update > > >> >> > locals as follows: > > > >> >> > ? ? locals().update( myDictionary ) > > > >> >> No you can't. Try it inside a function. > > > >> >> -- > > >> >> Steven > > > >> > Sure. Inside a function I would use globals() instead. Although I > > >> > don't know if it would be a good practice... > > > >> Er, how does using globals change the local variables? > > > >> -- > > >> Steven > > > > Hmmm.... well, you tell me! > > > I'm not the one that said you can update locals! You said it. I said you > > can't, because you *can't*. The docs warn that you can't change locals, > > and if you try it, you will see that the docs are right. > > > >>> def test(): > > > ... ? ? x = 1 > > ... ? ? locals().update(x = 2) > > ... ? ? print x > > ... > > > >>> test() > > > 1 > > > > As I said, I don't know if this is the recomended way... > > > It's not recommended because it doesn't work. > > > -- > > Steven > > I guess I have to check the docs... > Anyway, nobody wanted to update locals() from within a function here. > Doing it outside of a function seems to work. > And updating globals() works in any case, which is what the OP seems > to need. Isn't it? > > Luis Alright, this is what the docs say about locals: "Note The built-in functions globals() and locals() return the current global and local dictionary, respectively, which may be useful to pass around for use as the second and third argument to exec(). Note The default locals act as described for function locals() below: modifications to the default locals dictionary should not be attempted. Pass an explicit locals dictionary if you need to see effects of the code on locals after function exec() returns." I wonder why updating locals(), not from within a function, works (at least in my interactive session). And what about the trick of updating globals? Is it legal? If not, is there any "legal" way to do what the OP needs? Luis From kse.listed.co1 at gmail.com Wed Feb 24 06:06:39 2010 From: kse.listed.co1 at gmail.com (Naeem) Date: Wed, 24 Feb 2010 03:06:39 -0800 (PST) Subject: "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ Message-ID: <0add456c-de59-4105-a01c-9eaf19a7fa20@u15g2000prd.googlegroups.com> "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ "selma blair" "salma hayek" "salma hayek hot" "salma hayek wallpapers" "hollywood sexiest scenes" "hollywood blue films" "hollywood movies free download" on http://sexyandpretty-girls.blogspot.com/ vv From eckhardt at satorlaser.com Wed Feb 24 06:24:58 2010 From: eckhardt at satorlaser.com (Ulrich Eckhardt) Date: Wed, 24 Feb 2010 12:24:58 +0100 Subject: while loop with the condition used in the body References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: Peter Otten wrote: > Duncan Booth wrote: >> for rq in incoming_requests(...): >> handle_request(rq) > > ...and a likely implementation would be > > def incoming_requests(...): > while True: > rq = ... # inlined version of get_request() > if not rq: > break > yield rq > > In other words: It's turtles all the way down... Almost. While it moves the ugliness, at least it allows separating the iteration logic from the handling logic, which is already a big step ahead! That said, there is: with as : ... so why not: while as : ... and also: if as : ... Thanks to everybody for their input! Uli -- Sator Laser GmbH Gesch?ftsf?hrer: Thorsten F?cking, Amtsgericht Hamburg HR B62 932 From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 06:38:10 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 12:38:10 +0100 Subject: Creating variables from dicts In-Reply-To: References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4b850f94$0$7054$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : > On Feb 23, 5:53 pm, vsoler wrote: >> Hi, >> >> I have two dicts >> >> n={'a', 'm', 'p'} >> v={1,3,7} >> >> and I'd like to have >> >> a=1 >> m=3 >> p=7 >> >> that is, creating some variables. >> >> How can I do this? > > You are probably coming from another language and you're not used to > python's data structures. > If you want a list of items, you use tuples or lists. If you want a list, then you use a list - not a tuple !-) > Examples: > > ('a', 'm', 'p') ---> this is a tuple, and it's made with > parenthesis () It's not the parens that "make" the tuple, it's the commas: >>> t1 = (1, 2, 3) >>> t2 = 1, 2, 3 >>> t1 (1, 2, 3) >>> t2 (1, 2, 3) >>> type(t2) >>> The only case where the parens are required is to define an empty tuple: >>> empty = () >>> empty () >>> type(empty) Now it's most of the time a good idea to still use the parens since it makes for more readable code (IMHO...) (snip helpful content) From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 06:40:22 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 12:40:22 +0100 Subject: Creating variables from dicts In-Reply-To: References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: <4b851018$0$7054$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : > On Feb 23, 10:41 pm, Steven D'Aprano > wrote: >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. Gonz?lez wrote: >>> By the way, if you want the variables inside myDict to be free >>> variables, you have to add them to the local namespace. The local >>> namespace is also a dictionary "locals()". So you can update locals as >>> follows: >>> locals().update( myDictionary ) >> No you can't. Try it inside a function. >> > > Sure. Inside a function I would use globals() instead. > Although I don't know if it would be a good practice... It's even worse than a bad practice. Hint : why is "globals" named "globals" and not "locals" ? From spamfresser at ch3ka.de Wed Feb 24 06:42:08 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 12:42:08 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: First: Thanks for all the replies so far, they really helped me. Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >> >>> def a(x=None): >> if x is None: >> pass >> else: >> pass >> > This is the way to do it python, and it has its advantages: 1 docstring, > 1 way do do it, 1 interface. Yes, I see. Actually I do now realize that even in Java I use method overloading mostly to implement optional arguments anyway, like: void constructor(){this.foo='foo'; this.initotherstuff();} void constructor(int x) {this.x=x; this.constructor();} and so on. So most of the time the idiom above is exactly what I need, as the versions of the function share code anyway. But there are also cases where they do something completely different - in these cases I might use one of the other solutions provided here or simply make two or three functions and name them appropiately. I do now see that the pythonic approach is the "best" for most cases, but I really loved to see that you *can* do overloading in a convenient way if you really want to :D Those decorators just rock :D Thanks again, Michael From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 06:48:13 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 12:48:13 +0100 Subject: Creating variables from dicts In-Reply-To: <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> Message-ID: <4b8511f0$0$24096$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : (snip) > Alright, this is what the docs say about locals: > "Note > The built-in functions globals() and locals() return the current > global and local dictionary, respectively, which may be useful to pass > around for use as the second and third argument to exec(). > > Note > The default locals act as described for function locals() below: > modifications to the default locals dictionary should not be > attempted. Pass an explicit locals dictionary if you need to see > effects of the code on locals after function exec() returns." > > I wonder why updating locals(), not from within a function, works (at > least in my interactive session). Because at the top level, locals and globals are the same thing. > And what about the trick of updating globals? Is it legal? It's legal, but it's (usually) a very bad idea - at the top-level, it harms readability, and from within a function it's doubly bad (readibility + "globals are evil"). Now as usual with GoldenRules(tm), it's meant to be broken - once you do know why you shouldn't _usually_ do it. for the very same reasons global > If not, is > there any "legal" way to do what the OP needs? > > Luis From nobody at dizum.com Wed Feb 24 06:52:50 2010 From: nobody at dizum.com (Nomen Nescio) Date: Wed, 24 Feb 2010 12:52:50 +0100 (CET) Subject: scope of generators, class variables, resulting in global na Message-ID: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Hello, Can someone help me understand what is wrong with this example? class T: A = range(2) B = range(4) s = sum(i*j for i in A for j in B) It produces the exception: : global name 'j' is not defined The exception above is especially confusing since the following similar example (I just replaced the generator by an explicit array) works: class T: A = range(2) B = range(4) s = sum([(i*j) for i in A for j in B]) (BTW, the class scope declarations are intentional). Thanks, Leo. From J.Fine at open.ac.uk Wed Feb 24 07:03:40 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Wed, 24 Feb 2010 12:03:40 +0000 Subject: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens Message-ID: Hi Does anyone know of a collection of regular expressions that will break a TeX/LaTeX document into tokens? Assume that there is no verbatim or other category code changes. Thanks Jonathan From peloko45 at gmail.com Wed Feb 24 07:18:59 2010 From: peloko45 at gmail.com (Joan Miller) Date: Wed, 24 Feb 2010 04:18:59 -0800 (PST) Subject: Fascism is coming to Internet References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <6d185c76-5ac2-4591-a3b6-229b3ac2a340@z1g2000prc.googlegroups.com> Message-ID: On 23 feb, 20:16, "D'Arcy J.M. Cain" wrote: > On Tue, 23 Feb 2010 20:30:03 +0100 > > Olof Bjarnason wrote: > > Even if this is "Off Topic" (which I think it really isn't in any open > > source / free software-oriented mailing list), I want to agree with > > Joan. > > It isn't about the Python programming language so it is off topic. ?So > what if some members have an interest? ?We have interest in a lot of > things. ?We all have interest in the hardware that our programs run on > but questions about hardware are also off topic. > > Perhaps you don't quite grasp the point of topical discussion groups. > They are a way of letting individuals decide for themselves what kind > of discussions they want to be involved in. ?By spamming the group this > way you take away that freedom of choice. ?It's ironic when it is done > in the name of freedom. > > -- To avoid the spam, I reccomend a mailing list site as librelist: http://librelist.com/index.html problem -> reaction -> solution From alfps at start.no Wed Feb 24 07:21:31 2010 From: alfps at start.no (Alf P. Steinbach) Date: Wed, 24 Feb 2010 13:21:31 +0100 Subject: scope of generators, class variables, resulting in global na In-Reply-To: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: * Nomen Nescio: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > A = range(2) > B = range(4) > s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined Which Python implementation are you using? I can't reproduce the error message that you cite. C:\test> py2 Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum(i*j for i in A for j in B) ... Traceback (most recent call last): File "", line 1, in File "", line 4, in T File "", line 4, in NameError: global name 'B' is not defined >>> exit() C:\test> py3 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum(i*j for i in A for j in B) ... Traceback (most recent call last): File "", line 1, in File "", line 4, in T File "", line 4, in NameError: global name 'B' is not defined >>> exit() C:\test> _ Reason for the NameError: The above is a /generator expression/, evaluated in a class definition. The docs have a similar example but I'm sorry, I'm unable to find it! Anyway the generator expression is evaluated as if its code was put in function. And from within the scope of that function you can't access the class scope implicitly, hence, no access to 'B'. > The exception above is especially confusing since the following similar example > (I just replaced the generator by an explicit array) works: > > class T: > A = range(2) > B = range(4) > s = sum([(i*j) for i in A for j in B]) > > (BTW, the class scope declarations are intentional). > > Thanks, Leo. This is a /list comprehension/, not a generator expression (although syntactically it's almost the same). It obeys different rules. Essentially the generator expression produces a generator object that you may name or pass around as you wish, while the comprehension is just a syntactical device for writing more concisely some equivalent code that's generated inline. However, apparently the rules changed between Python 2.x and Python 3.x. In Python 3.x also the list comprehension fails in a class definition: C:\test> py2 Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum([(i*j) for i in A for j in B]) ... >>> exit() C:\test> py3 Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class T: ... A = range(2) ... B = range(4) ... s = sum([(i*j) for i in A for j in B]) ... Traceback (most recent call last): File "", line 1, in File "", line 4, in T File "", line 4, in NameError: global name 'B' is not defined >>> exit() C:\test> _ From one point of view it's good that Py3 provides about the same behavior for generator expressions and list comprehensions. But I'd really like the above examples to Just Work. :-) Cheers & hth., - Alf From gereon.kaiping at yahoo.de Wed Feb 24 07:49:55 2010 From: gereon.kaiping at yahoo.de (Gereon Kaiping) Date: Wed, 24 Feb 2010 13:49:55 +0100 Subject: Artificial Neural Networks recommendation Message-ID: <4B852073.30500@yahoo.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'd like to use ANNs in python, especially Simple Recurrent Networks. Ideally I'd like to find a quick, pythonic module that is able to simulate different styles of network architectures including some types of recurrent networks (must: SRN/Elman, may: other recurrent networks like ESN or LSTM to experiment with them). So far I found the following Python ANN modules: - - PyNN (just a builder, requires external simulator) ? http://neuralensemble.org/trac/PyNN/ - - Con-x (part of pyro) ? http://pyrorobotics.org/?page=Conx - - PyNeurGen (includes genetic algorithms) ? http://pyneurgen.sourceforge.net/ - - ffnet (only fast forward) ? http://ffnet.sourceforge.net/ - - brian (spiking networks) ? http://www.briansimulator.org/ - - PyBrain (machine learning) ? http://pybrain.org/ Can you give me a recommendation or a review on some of these? Are there other modules for simulating ANNs? Greetings, Gereon -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkuFIHIACgkQFWJnZLsO/Wvp1ACfa2dhOd0b0SIVkOzZN0ebRJdd WFQAoIttIDNbIuqViDbPeVyS+wtGj6tI =N1oM -----END PGP SIGNATURE----- From paul.nospam at rudin.co.uk Wed Feb 24 08:11:32 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Wed, 24 Feb 2010 13:11:32 +0000 Subject: Artificial Neural Networks recommendation References: Message-ID: <87y6iird6j.fsf@rudin.co.uk> Gereon Kaiping writes: > Are there other modules for simulating ANNs? Fann has python bindings. From luismgz at gmail.com Wed Feb 24 08:41:08 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Wed, 24 Feb 2010 05:41:08 -0800 (PST) Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> Message-ID: <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> On Feb 24, 8:48?am, Bruno Desthuilliers wrote: > Luis M. Gonz lez a crit : > (snip) > > > Alright, this is what the docs say about locals: > > "Note > > The built-in functions globals() and locals() return the current > > global and local dictionary, respectively, which may be useful to pass > > around for use as the second and third argument to exec(). > > > Note > > The default locals act as described for function locals() below: > > modifications to the default locals dictionary should not be > > attempted. Pass an explicit locals dictionary if you need to see > > effects of the code on locals after function exec() returns." > > > I wonder why updating locals(), not from within a function, works (at > > least in my interactive session). > > Because at the top level, locals and globals are the same thing. > > > And what about the trick of updating globals? Is it legal? > > It's legal, but it's (usually) a very bad idea - at the top-level, it > harms readability, and from within a function it's doubly bad > (readibility + "globals are evil"). > > Now as usual with GoldenRules(tm), it's meant to be broken - once you do > know why you shouldn't _usually_ do it. > > ? for the very same reasons global > > > > > If not, is > > there any "legal" way to do what the OP needs? > > > Luis I still don't understand why is it a bad idea in the case of globals(). This is the only way I know to define variables programatically in the top-level namespace, without having to do it manually one by one. I don't see the readability problem either. Talking about Goldenrules(tm), what's the recomended way to do it? Luis From edreamleo at gmail.com Wed Feb 24 08:58:03 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Wed, 24 Feb 2010 07:58:03 -0600 Subject: ANN: Leo 4.7 final released References: Message-ID: <3qbao5tflmcds61l1ngltaq12ogdlvo2e8@4ax.com> On Tue, 23 Feb 2010 07:53:44 -0600, Edward K Ream wrote: A critical bug has been reported against Leo 4.7 final, and indeed all previous versions of Leo 4.7. The bug can cause loss of data in @file nodes when Leo 4.7 saves .leo files created with older versions of Leo. This bug will be fixed in Leo 4.7.1, due in a few days. The bug has already been fixed on Leo's trunk. My apologies for any problems this bug may have caused. From steve at holdenweb.com Wed Feb 24 08:59:13 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 08:59:13 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: At 12.34 pm on November 13, 2011 regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 24 09:02:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 09:02:17 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: <4B853169.6030904@holdenweb.com> Stefan Behnel wrote: > Chris Rebert, 23.02.2010 06:45: >> Indeed. Python is at position 7, just behind C#, in the TIOBE Index: >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? > Interesting that you are willing to trust your gut feeling against an established survey. All indexes are flawed, they are merely flawed in different ways is all. I track TIOBE because it shows trends. Python's absolute position on the list doesn't interest me so much. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 24 09:02:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 09:02:17 -0500 Subject: When will Python go mainstream like Java? In-Reply-To: References: <6cc20cea1002222036s605f542es7634a70d2b92b18a@mail.gmail.com> <50697b2c1002222145p425b1589sd00252e110a7ec5@mail.gmail.com> Message-ID: <4B853169.6030904@holdenweb.com> Stefan Behnel wrote: > Chris Rebert, 23.02.2010 06:45: >> Indeed. Python is at position 7, just behind C#, in the TIOBE Index: >> http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > That index is clearly flawed. A language like PHP (whatever that is > supposed to be comparable with) can't possibly be on the rise, can it? > Interesting that you are willing to trust your gut feeling against an established survey. All indexes are flawed, they are merely flawed in different ways is all. I track TIOBE because it shows trends. Python's absolute position on the list doesn't interest me so much. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From steve at holdenweb.com Wed Feb 24 09:07:17 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 09:07:17 -0500 Subject: How to make an empty generator? In-Reply-To: <4B7EF185.1040702@optimum.net> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> <4B7EF185.1040702@optimum.net> Message-ID: John Posner wrote: > On 2/19/2010 2:25 PM, Terry Reedy wrote: >> On 2/19/2010 12:44 PM, Stephen Hansen wrote: >> >>> Much to my embarrassment, sometime last night I realized I was being a >>> complete idiot, and the 'correct' way to handle this in my scenario is >>> really just: >>> >>> def initialize(): >>> # do one time processing here >>> >>> return [] >>> >>> A generator is just a callable that returns an iterator, after all. >> >> Confusing generators and generator functions is, well, confusing. >> For future reference, and clarity of communication in Pythonland, >> >> generator function: function that produces a generator when called; if >> python coded, its body contains 'yield'. >> >> generator: iterator produced by a generator function; > > I suggest: > > iterator produced by a generator function or a generator expression; > > has .__next__ and >> self-returning .__init__, like all other iterators. >> >> generator expression: an expression that evaluates to a generator; the >> expression is used to create a temporary anonymous generator function >> that is called to produce the generator and is then discarded. > > Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms > to Terry's definitions above in most places. But the Glossary says: > > generator > A function which returns an iterator. <... more ...> > > generator expression > An expression that returns a generator. <... more ...> > > The additional verbiage in these definitions mitigates the damage, but I > think the first entry should be headlined *generator function* instead > of *generator*. And the Glossary should include Terry's additional entry > [ as amended by me :-) ]: > > generator > An iterator produced by a generator function or a generator > expression. > > -John > +1. Can someone submit a documentation patch, please? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From victorsubervi at gmail.com Wed Feb 24 09:32:43 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 24 Feb 2010 10:32:43 -0400 Subject: Can't Connect To SMTP Message-ID: <4dc0cfea1002240632h755b199bp1cf5c36b489aac07@mail.gmail.com> Hi; I'm getting this error: A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py 52 53 ''' 54 my_mail() 55 print ''' 56 my_mail = /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() 33 to_address = ourEmail1, 34 subject = subject, 35 message = message 36 ).send() 37 Email( message = 'Name: beno -\nMessage: test' /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in send(self=) 344 smtp = smtplib.SMTP() 345 if self.smtp_server: 346 smtp.connect(self.smtp_server) 347 else: 348 smtp.connect() smtp = , smtp.connect = >, self = , self.smtp_server = 'localhost' /usr/lib64/python2.4/smtplib.py in connect(self=, host='localhost', port=25) 305 if not self.sock: 306 raise socket.error, msg 307 (code, msg) = self.getreply() 308 if self.debuglevel > 0: print>>stderr, "connect:", msg 309 return (code, msg) code undefined, msg = 'getaddrinfo returns an empty list', self = , self.getreply = > /usr/lib64/python2.4/smtplib.py in getreply(self=) 349 if line == '': 350 self.close() 351 raise SMTPServerDisconnected("Connection unexpectedly closed") 352 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line) 353 resp.append(line[4:].strip()) global SMTPServerDisconnected = SMTPServerDisconnected: Connection unexpectedly closed args = ('Connection unexpectedly closed',) I'm having a hard time reading this and making sense of it. Please help me understand where I should look to fix the problem. TIA, beno -- The Logos has come to bear http://logos.13gems.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From bruno.42.desthuilliers at websiteburo.invalid Wed Feb 24 09:44:41 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Wed, 24 Feb 2010 15:44:41 +0100 Subject: Creating variables from dicts In-Reply-To: <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> Message-ID: <4b853b4b$0$23448$426a74cc@news.free.fr> Luis M. Gonz?lez a ?crit : > On Feb 24, 8:48 am, Bruno Desthuilliers 42.desthuilli... at websiteburo.invalid> wrote: >> Luis M. Gonz lez a crit : >> >>> And what about the trick of updating globals? Is it legal? >> It's legal, but it's (usually) a very bad idea - at the top-level, it >> harms readability, and from within a function it's doubly bad >> (readibility + "globals are evil"). >> >> Now as usual with GoldenRules(tm), it's meant to be broken - once you do >> know why you shouldn't _usually_ do it. >> >>> If not, is >>> there any "legal" way to do what the OP needs? > > I still don't understand why is it a bad idea in the case of > globals(). please not the _usually_. > This is the only way I know to define variables programatically in the > top-level namespace, without having to do it manually one by one. > I don't see the readability problem either. # wrong.py x = 42 def bar(): return x + 1 def test(): y = bar() assert y==43 # snip 1kloc def foo(): globals()[x] = 43 quux() # snip some more core def quux(): globals()[y] = 1138 # snip some more core if __name__ == '__main__': foo() Enjoy... > Talking about Goldenrules(tm), what's the recomended way to do it? The "recommanded way" is 1/ to avoid using globals to share state whenever possible 2/ to avoid creating globals from a function If your problem is to conditionnaly define globals (based on environment value or whatnot), then just write the conditional at the top level. Now I don't say there's no legitimate use case for updating the global namespace from within a function - just that this is a very very very rare beast (never meet her as far as I'm concerned, and I did write some hairy code), and even then is BadEnough(tm) to require a good documentation. FWIW, your example seemed to be about updating the global namespace from within a function just to have the names available in the function, which is about the worst possible solution to the OP problem. wrt/ the OP question, mapping a sequence of values to a sequence of names is a legitimate concern, but you just dont need to define these names in the local namespace to use them - just stick'em in a dict and you're fine. From jjposner at optimum.net Wed Feb 24 09:48:32 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 09:48:32 -0500 Subject: How to make an empty generator? In-Reply-To: References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> <4B7EF185.1040702@optimum.net> Message-ID: <4B853C40.5090307@optimum.net> On 2/24/2010 9:07 AM, Steve Holden wrote: > John Posner wrote: >> Note that the Py2.6.4 documentation is inconsistent. AFAICT, it conforms >> to Terry's definitions above in most places. But the Glossary says: >> >> generator >> A function which returns an iterator.<... more ...> >> >> generator expression >> An expression that returns a generator.<... more ...> >> >> The additional verbiage in these definitions mitigates the damage, but I >> think the first entry should be headlined *generator function* instead >> of *generator*. And the Glossary should include Terry's additional entry >> [ as amended by me :-) ]: >> >> generator >> An iterator produced by a generator function or a generator >> expression. >> >> -John >> > +1. Can someone submit a documentation patch, please? > Will do. -John From phoghawk at gmail.com Wed Feb 24 10:40:55 2010 From: phoghawk at gmail.com (b3ng0) Date: Wed, 24 Feb 2010 07:40:55 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: <4308848c-b38f-4e45-bf01-8c4d2b3dcb7c@a18g2000yqc.googlegroups.com> On Feb 24, 5:52?am, Nomen Nescio wrote: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > ? A = range(2) > ? B = range(4) > ? s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined > > The exception above is especially confusing since the following similar example (I just replaced the generator by an explicit array) works: > > class T: > ? A = range(2) > ? B = range(4) > ? s = sum([(i*j) for i in A for j in B]) > > (BTW, the class scope declarations are intentional). > > Thanks, Leo. The best way to mimic the same behavior, while getting around the scoping issues, would be as follows: class T: A = range(2) B = range(4) @property def s(self): return sum(i*j for i in self.A for j in self.B) T().s will now return 6 From joncle at googlemail.com Wed Feb 24 10:45:05 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Feb 2010 07:45:05 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: On Feb 24, 12:21?pm, "Alf P. Steinbach" wrote: > * Nomen Nescio: > > > Hello, > > > Can someone help me understand what is wrong with this example? > > > class T: > > ? A = range(2) > > ? B = range(4) > > ? s = sum(i*j for i in A for j in B) > > > It produces the exception: > > > : global name 'j' is not defined > > Which Python implementation are you using? > > I can't reproduce the error message that you cite. > > > C:\test> py2 > Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum(i*j for i in A for j in B) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() > > C:\test> py3 > Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum(i*j for i in A for j in B) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() > > C:\test> _ > > > Reason for the NameError: > > The above is a /generator expression/, evaluated in a class definition. > > The docs have a similar example but I'm sorry, I'm unable to find it! Anyway the > generator expression is evaluated as if its code was put in function. And from > within the scope of that function you can't access the class scope implicitly, > hence, no access to 'B'. > > > The exception above is especially confusing since the following similar example > > (I just replaced the generator by an explicit array) works: > > > class T: > > ? A = range(2) > > ? B = range(4) > > ? s = sum([(i*j) for i in A for j in B]) > > > (BTW, the class scope declarations are intentional). > > > Thanks, Leo. > > This is a /list comprehension/, not a generator expression (although > syntactically it's almost the same). > > It obeys different rules. > > Essentially the generator expression produces a generator object that you may > name or pass around as you wish, while the comprehension is just a syntactical > device for writing more concisely some equivalent code that's generated inline. > > However, apparently the rules changed between Python 2.x and Python 3.x. > > In Python 3.x also the list comprehension fails in a class definition: > > > C:\test> py2 > Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum([(i*j) for i in A for j in B]) > ... > ?>>> exit() > > C:\test> py3 > Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum([(i*j) for i in A for j in B]) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() > > C:\test> _ > > > ?From one point of view it's good that Py3 provides about the same behavior for > generator expressions and list comprehensions. > > But I'd really like the above examples to Just Work. :-) > > Cheers & hth., > > - Alf s = sum( i*j for i,j in iterools.product(A, B) ) is a possible work around. Which could generalise to (something like): s = sum( reduce(op.mul, seq) for seq in product(A, B, B, A) ) Cheers, Jon. From robert.kern at gmail.com Wed Feb 24 10:57:34 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 09:57:34 -0600 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: On 2010-02-23 22:09 PM, Grant Edwards wrote: > On 2010-02-24, Robert Kern wrote: > >>> comp.lang.python.spam_prevention_discussion >> >> Which doesn't exist and never will. Sorry, but >> meta-discussions about the group are typically on-topic for >> all groups with some few exceptions (e.g. non-discussion, >> binary-only groups with associated .d groups, for instance). > > Since now we are discussing meta-discussions, is this now a > meta-meta-discussion? If you like, but I tend to interpret "meta-" as idempotent. It's easier on my aspirin budget. -- 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 parkerp at example.net Wed Feb 24 11:05:42 2010 From: parkerp at example.net (Peter Parker) Date: Wed, 24 Feb 2010 11:05:42 -0500 Subject: When will Python go mainstream like Java? References: Message-ID: Steve Holden wrote: > At 12.34 pm on November 13, 2011 > At December 21, 2012 at 11:11 am (according to the Maya calendar) From arnodel at googlemail.com Wed Feb 24 11:14:00 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 24 Feb 2010 08:14:00 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: <3f3ce996-7fc3-4c19-9397-e1db8f911aa4@k19g2000yqc.googlegroups.com> Nomen Nescio wrote: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > A = range(2) > B = range(4) > s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined It's due to scoping rules for classes and/or how generator expressions are compiled. When a function definition is executed from within the body of a class, the body of the class doesn't act as an outer scope for it. E.g. class A: x = 2 def f(self): return x When f is defined (technically, when the closure is made), the name 'x' is not bound to 2 but is considered to be in the global namespace (unless the class is defined within a function for example). Now generator expressions are defined as generator functions so your example is akin to something like: class T: A = range(2) B = range(4) def _gen(L): for i in L: for j in B: yield i*j s = sum(_gen(A)) (From memory, I might be wrong on some details) Now looking at the above, when _gen is defined, B is considered to be belonging to the global namespace, therefore if it is not defined there a NameError will be thrown. Now a safe workaround to this would be: class T: A = range(2) B = range(4) s = (lambda A=A, B=B: sum(i*j for i in A for j in B))() The lambda form is evaluated when the body of the class is executed, binding the names A and B to the objects you want in the generator expression. I remember suggesting a while ago that all generator expressions be implicitely wrapped like the one above in order to avoid such surprises. I can't quite remember what the arguments against were, but you can probably find them in the archives! -- Arnaud From martin.hellwig at dcuktec.org Wed Feb 24 11:38:57 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Wed, 24 Feb 2010 16:38:57 +0000 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: On 02/24/10 16:05, Peter Parker wrote: > Steve Holden wrote: >> At 12.34 pm on November 13, 2011 >> > > At December 21, 2012 at 11:11 am (according to the Maya calendar) On August 29, 1997, Java became mainstream. In a panic, Microsoft tried to embrace, extend and exterminate the system, prompting Sun to retaliate with a lawsuit, knowing that Microsoft's counterattack would eliminate all its main competitors in the U.S. This initiates an indeterminately long period of new language development culminating in a battle against corporate monopoly, which gained ever-increasing capabilities of FUD. -- mph From sbassi at clubdelarazon.org Wed Feb 24 12:07:07 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Wed, 24 Feb 2010 14:07:07 -0300 Subject: parametrizing a sqlite query Message-ID: <9e2f512b1002240907v66682f1fi7d4d4c7d2dabd880@mail.gmail.com> c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) This query returns empty. When it is executed, keywords = 'harvest'. To check it, I do it on the command line and it works as expected: sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; 11C 11D 12F I guess there is a problem with the "%". From victorsubervi at gmail.com Wed Feb 24 12:09:24 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 24 Feb 2010 13:09:24 -0400 Subject: SMTPServerDisconnected In-Reply-To: <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> References: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> Message-ID: <4dc0cfea1002240909u6a82926l4c82ec3adf9a9192@mail.gmail.com> On Tue, Feb 23, 2010 at 4:53 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Tue, Feb 23, 2010 at 8:47 AM, Victor Subervi > wrote: > > Hi; > > I think the last main thing I have to do on my server is get a running > email > > server up. Now that I've nuked sendmail and given up on postfix, I'm back > to > > trying to get qmail up and running again. Of course, there are no active > > discussion lists for *any* email server, so I have to turn here for help. > > While running a script that worked perfectly well on another server to > send > > an email, I get the following error: > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py > > 52 > > 53 ''' > > 54 my_mail() > > 55 print ''' > > 56 > > my_mail = > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() > > 33 to_address = ourEmail1, > > 34 subject = subject, > > 35 message = message > > 36 ).send() > > 37 Email( > > message = 'Name: beno -\nMessage: test' > > /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in > > send(self=) > > 344 smtp = smtplib.SMTP() > > 345 if self.smtp_server: > > 346 smtp.connect(self.smtp_server) > > 347 else: > > 348 smtp.connect() > > smtp = , smtp.connect = of > > >, self = , > self.smtp_server > > = 'localhost' > > /usr/lib64/python2.4/smtplib.py in connect(self=, > > host='localhost', port=25) > > 305 if not self.sock: > > 306 raise socket.error, msg > > 307 (code, msg) = self.getreply() > > 308 if self.debuglevel > 0: print>>stderr, "connect:", msg > > 309 return (code, msg) > > code undefined, msg = 'getaddrinfo returns an empty list', self = > > , self.getreply = > > > > /usr/lib64/python2.4/smtplib.py in getreply(self= instance>) > > 349 if line == '': > > 350 self.close() > > 351 raise SMTPServerDisconnected("Connection > unexpectedly > > closed") > > 352 if self.debuglevel > 0: print>>stderr, 'reply:', > > repr(line) > > 353 resp.append(line[4:].strip()) > > global SMTPServerDisconnected = > > SMTPServerDisconnected: Connection unexpectedly closed > > args = ('Connection unexpectedly closed',) > > I cannot find the qmail logs. I assumed they'd be in either > > /var/qmail/supervise/qmail-send > > or > > /var/qmail/supervise/qmail-smtpd > > but I find no logs there. > > > > [SSH] Protocol Version 2 (OpenSSH_4.3) > > [SSH] Cipher: aes128-cbc > > Logged in (password) > > Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 > > [beno at 13gems ~]$ su > > Password: > > [root at 13gems beno]# man netstat > > [root at 13gems beno]# netstat > > Active Internet connections (w/o servers) > > Proto Recv-Q Send-Q Local Address Foreign Address > > State > > getnameinfo failed > > tcp 0 268 nrelectric.com:ssh [UNKNOWN]:61912 > > ESTABLISHED > > Active UNIX domain sockets (w/o servers) > > Proto RefCnt Flags Type State I-Node Path > > unix 7 [ ] DGRAM 10842 /dev/log > > unix 2 [ ] DGRAM 10370 > > @/org/kernel/udev/udevd > > unix 2 [ ] DGRAM 6077731 > > unix 3 [ ] STREAM CONNECTED 6077679 > > unix 3 [ ] STREAM CONNECTED 6077678 > > unix 2 [ ] DGRAM 6077675 > > unix 2 [ ] DGRAM 11556 > > unix 2 [ ] DGRAM 11511 > > unix 2 [ ] DGRAM 10990 > > [root at 13gems beno]# > > > > How do I trouble-shoot this? > > Try connecting to the port that is supposed to accept mail messages > via telnet and issue a few SMTP commands. > Oops. I just realized I posted this twice to the same forum. My bad. I have advanced on this somewhat. I have gotten email from my server, so I know that smtp is in fact working. But I'm still getting this error. What do? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From victorsubervi at gmail.com Wed Feb 24 12:10:37 2010 From: victorsubervi at gmail.com (Victor Subervi) Date: Wed, 24 Feb 2010 13:10:37 -0400 Subject: SMTPServerDisconnected In-Reply-To: <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> References: <4dc0cfea1002230847g2e628165kbce9395e0aad2f62@mail.gmail.com> <6cc20cea1002231253p47e4c1d9m590b13a0b7421951@mail.gmail.com> Message-ID: <4dc0cfea1002240910k6e236cf1pd068bd6c3fd08bbc@mail.gmail.com> On Tue, Feb 23, 2010 at 4:53 PM, Jonathan Gardner < jgardner at jonathangardner.net> wrote: > On Tue, Feb 23, 2010 at 8:47 AM, Victor Subervi > wrote: > > Hi; > > I think the last main thing I have to do on my server is get a running > email > > server up. Now that I've nuked sendmail and given up on postfix, I'm back > to > > trying to get qmail up and running again. Of course, there are no active > > discussion lists for *any* email server, so I have to turn here for help. > > While running a script that worked perfectly well on another server to > send > > an email, I get the following error: > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > A problem occurred in a Python script. Here is the sequence of function > > calls leading up to the error, in the order they occurred. > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py > > 52 > > 53 ''' > > 54 my_mail() > > 55 print ''' > > 56 > > my_mail = > > /var/www/html/globalsolutionsgroup.vi/simplemail/mail2.py in my_mail() > > 33 to_address = ourEmail1, > > 34 subject = subject, > > 35 message = message > > 36 ).send() > > 37 Email( > > message = 'Name: beno -\nMessage: test' > > /var/www/html/globalsolutionsgroup.vi/simplemail/simplemail.py in > > send(self=) > > 344 smtp = smtplib.SMTP() > > 345 if self.smtp_server: > > 346 smtp.connect(self.smtp_server) > > 347 else: > > 348 smtp.connect() > > smtp = , smtp.connect = of > > >, self = , > self.smtp_server > > = 'localhost' > > /usr/lib64/python2.4/smtplib.py in connect(self=, > > host='localhost', port=25) > > 305 if not self.sock: > > 306 raise socket.error, msg > > 307 (code, msg) = self.getreply() > > 308 if self.debuglevel > 0: print>>stderr, "connect:", msg > > 309 return (code, msg) > > code undefined, msg = 'getaddrinfo returns an empty list', self = > > , self.getreply = > > > > /usr/lib64/python2.4/smtplib.py in getreply(self= instance>) > > 349 if line == '': > > 350 self.close() > > 351 raise SMTPServerDisconnected("Connection > unexpectedly > > closed") > > 352 if self.debuglevel > 0: print>>stderr, 'reply:', > > repr(line) > > 353 resp.append(line[4:].strip()) > > global SMTPServerDisconnected = > > SMTPServerDisconnected: Connection unexpectedly closed > > args = ('Connection unexpectedly closed',) > > I cannot find the qmail logs. I assumed they'd be in either > > /var/qmail/supervise/qmail-send > > or > > /var/qmail/supervise/qmail-smtpd > > but I find no logs there. > > > > [SSH] Protocol Version 2 (OpenSSH_4.3) > > [SSH] Cipher: aes128-cbc > > Logged in (password) > > Last login: Tue Feb 23 05:24:00 2010 from 66.248.168.67 > > [beno at 13gems ~]$ su > > Password: > > [root at 13gems beno]# man netstat > > [root at 13gems beno]# netstat > > Active Internet connections (w/o servers) > > Proto Recv-Q Send-Q Local Address Foreign Address > > State > > getnameinfo failed > > tcp 0 268 nrelectric.com:ssh [UNKNOWN]:61912 > > ESTABLISHED > > Active UNIX domain sockets (w/o servers) > > Proto RefCnt Flags Type State I-Node Path > > unix 7 [ ] DGRAM 10842 /dev/log > > unix 2 [ ] DGRAM 10370 > > @/org/kernel/udev/udevd > > unix 2 [ ] DGRAM 6077731 > > unix 3 [ ] STREAM CONNECTED 6077679 > > unix 3 [ ] STREAM CONNECTED 6077678 > > unix 2 [ ] DGRAM 6077675 > > unix 2 [ ] DGRAM 11556 > > unix 2 [ ] DGRAM 11511 > > unix 2 [ ] DGRAM 10990 > > [root at 13gems beno]# > > > > How do I trouble-shoot this? > > Try connecting to the port that is supposed to accept mail messages > via telnet and issue a few SMTP commands. > Oops. I just realized I sent this question twice to the same forum. My bad. I have received email from my server, but I'm still getting this same error. How trouble-shoot? TIA, beno -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjposner at optimum.net Wed Feb 24 12:15:08 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 12:15:08 -0500 Subject: How to make an empty generator? In-Reply-To: <4B853C40.5090307@optimum.net> References: <4b7ddc03$0$8819$c3e8da3@news.astraweb.com> <4b7e2dfb$0$8819$c3e8da3@news.astraweb.com> <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> <4B7EF185.1040702@optimum.net> <4B853C40.5090307@optimum.net> Message-ID: <4B855E9C.5040502@optimum.net> >>> generator >>> An iterator produced by a generator function or a generator >>> expression. >>> >>> -John >>> >> +1. Can someone submit a documentation patch, please? >> > > Will do. -John [sorry if this is a dup] Done: #8012 "Revise generator-related Glossary entries" -John From joncle at googlemail.com Wed Feb 24 12:21:11 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Feb 2010 09:21:11 -0800 (PST) Subject: parametrizing a sqlite query References: Message-ID: On Feb 24, 5:07?pm, Sebastian Bassi wrote: > c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) > > This query returns empty. When it is executed, keywords = 'harvest'. > To check it, I do it on the command line and it works as expected: > > sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; > 11C > 11D > 12F > > I guess there is a problem with the "%". You might want: c.execute("SELECT bin FROM bins where qtl like $keys", {'keys': keywords} ) Cheers, Jon. From mrkafk at gmail.com Wed Feb 24 12:23:17 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 18:23:17 +0100 Subject: Is this secure? In-Reply-To: <7x3a0r8hyr.fsf@ruckus.brouhaha.com> References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 03:50, Paul Rubin wrote: > The stuff about converting 4 random bytes to a decimal string and then > peeling off 2 digits at a time is pretty awful, and notice that since > 2**32 is 4294967296, in the cases where you get 10 digits, the first > 2-digit pair is never higher than 42. Yikes! I didn't think about that. This is probably where (some part of) probability skewing comes from. Anyway, the passwords for authorized users will be copied and pasted from email into in the application GUI which will remember it for them, so they will not have to remember and type them in. So I have little in the way of limitations of password length - even though in *some* cases somebody might have to (or be ignorant enough) to retype the password instead of pasting it in. In that case the "diceware" approach is not necessary, even though I will certainly remember this approach for a case when users will have to remember & type the passwords in. The main application will access the data using HTTP (probably), so the main point is that an attacker is not able to guess passwords using brute force. Using A-z with 10-char password seems to provide 3 orders of magnitude more combinations than a-z: >>> 57 ** 10 362033331456891249L >>> 25 ** 10 95367431640625L Even though I'm not sure it is worth it, assuming 1000 brute-force guesses per second (which over the web would amount pretty much to DOS), this would take # days: >>> 57 ** 10 / (1000 * 3600 * 24) 4190200595L >>> 25 ** 10 / (1000 * 3600 * 24) 1103789L Even then I'm not getting completely uniform distribution for some reason: d 39411 l 39376 f 39288 a 39275 s 39225 r 39172 p 39159 t 39073 k 39071 u 39064 e 39005 o 39005 n 38995 j 38993 h 38975 q 38958 c 38938 b 38906 g 38894 i 38847 m 38819 v 38712 z 35321 y 35228 w 35189 x 35075 Code: import operator def gen_rand_word(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)]) def count_chars(chardict, word): for c in word: try: chardict[c] += 1 except KeyError: chardict[c] = 0 if __name__ == "__main__": chardict = {} for i in range(100000): w = gen_rand_word(10) count_chars(chardict, w) counts = list(chardict.items()) counts.sort(key = operator.itemgetter(1), reverse = True) for char, count in counts: print char, count > I'd write your code something like this: > > nletters = 5 > > def randomword(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a')+ord(c)%26) for c in f.read(n)]) > > print randomword(nletters) Aw shucks when will I learn to do the stuff in 3 lines well instead of 20, poorly. :-/ Regards, mk From joncle at googlemail.com Wed Feb 24 12:29:22 2010 From: joncle at googlemail.com (Jon Clements) Date: Wed, 24 Feb 2010 09:29:22 -0800 (PST) Subject: parametrizing a sqlite query References: Message-ID: On Feb 24, 5:21?pm, Jon Clements wrote: > On Feb 24, 5:07?pm, Sebastian Bassi wrote: > > > c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) > > > This query returns empty. When it is executed, keywords = 'harvest'. > > To check it, I do it on the command line and it works as expected: > > > sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; > > 11C > > 11D > > 12F > > > I guess there is a problem with the "%". > > You might want: > c.execute("SELECT bin FROM bins where qtl like $keys", {'keys': > keywords} ) > > Cheers, > > Jon. As soon as I posted that, the $ didn't look right; the docs use :keys syntax. Cheers, Jon. From mrkafk at gmail.com Wed Feb 24 12:30:20 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 18:30:20 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: On 2010-02-24 03:26, George Sakkis wrote: >> Well I for one wouldn't want Python to go exactly Java way, see this: >> >> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=jav... >> >> This is the percentage of job offers in UK where the keyword "Java" appears. >> >> Same for C#, it looks like C# is eating Java's lunch now: >> >> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csh... > > This seems to be a UK-specific trend; in the US (and most other > countries I know of) Java is still going strong, e.g. > http://www.indeed.com/jobtrends?q=java%2C+c%23&l= Interesting, and I was thinking that UK sample was big enough for such things not to matter. Regards, mk From gagsl-py2 at yahoo.com.ar Wed Feb 24 12:32:59 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Feb 2010 14:32:59 -0300 Subject: How to measure elapsed time under Windows? References: <1n2en51qqliplc2u8q78l3gt2dn3vmeh8d@4ax.com> Message-ID: En Sat, 13 Feb 2010 17:29:45 -0300, Tim Roberts escribi?: > "Gabriel Genellina" wrote: >> >> The original problem was with the RDTSC instruction on multicore CPUs; >> different cores may yield different results because they're not >> synchronized at all times. > > Not true. The synchronization issue has two causes: initial > synchronization at boot time, and power management making microscopic > adjustments to the clock rate. In Windows NT 4, Microsoft took extra > pains > to adjust the cycle counters on multiprocessor computers during boot so > that the processors started out very close together. Once set, they > naturally remained in lock step, until aggressive power management > because > more prevalent. In XP, they stopped trying to align at boot time. Thanks for the detailed explanation! -- Gabriel Genellina From spam at removethis.btinternet.com Wed Feb 24 12:39:19 2010 From: spam at removethis.btinternet.com (Abigail) Date: Wed, 24 Feb 2010 17:39:19 -0000 Subject: Noob raw_input question Message-ID: Yesterday I downloaded and installed Python 3.1 and working through some examples but I have hit a problem >>> a = raw_input("Enter a number" ) Traceback (most recent call last): File "", line 1, in a = raw_input("Enter a number" ) NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number ") What am I doing wrong? From mrkafk at gmail.com Wed Feb 24 12:47:11 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 18:47:11 +0100 Subject: Intra-package C extensions with freeze.py In-Reply-To: <4B4E2497.20809@gmail.com> References: <4B4E2497.20809@gmail.com> Message-ID: On 2010-01-13 20:52, Pascal Chambon wrote: > I've managed to solve that by manually "monkey patching" sys.modules, > before fusemodule's actual import. But this looks like an unsatisfying > solution, to me. Geez.. > Does anyone have a clue about how to freeze a python program cleanly, in > case such inner C extensions are involved ? Does any of the freezers > (freeze.py, py2exe, pyrex, cx_freeze...) do that ? I haven't seen such > things so far in their docs. Go for pyinstaller, I have successfully packaged an app using compiled C extensions this way. Although you will have to add those extensions in "hook" script. Regards, mk From comptekki at gmail.com Wed Feb 24 12:49:08 2010 From: comptekki at gmail.com (Wes James) Date: Wed, 24 Feb 2010 10:49:08 -0700 Subject: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens In-Reply-To: References: Message-ID: <533df7fa1002240949o4f98d294u9174b4d32cd154b1@mail.gmail.com> On Wed, Feb 24, 2010 at 5:03 AM, Jonathan Fine wrote: > Hi > > Does anyone know of a collection of regular expressions that will break a > TeX/LaTeX document into tokens? ?Assume that there is no verbatim or other > category code changes. I'm not sure how this does it, but it might help: http://plastex.sourceforge.net/plastex/sect0025.html -wes From bornstub at gmail.com Wed Feb 24 12:49:18 2010 From: bornstub at gmail.com (Victor Lin) Date: Wed, 24 Feb 2010 09:49:18 -0800 (PST) Subject: A tool for find dependencies relationships behind Python projects References: Message-ID: On 2?23?, ??12?32?, Hellmut Weber wrote: > Hi Victor, > I would be intereseted to use your tool ;-) > > My system is Sabayon-5.1 on Lenovo T61. > Trying for the first time easy_install I get the following error: > > ==================== > > root at sylvester ~ # easy_install gluttony > Searching for gluttony > Readinghttp://pypi.python.org/simple/gluttony/ > Readinghttp://code.google.com/p/python-gluttony/ > Best match: Gluttony 0.3 > > Downloadinghttp://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md... > > Processing Gluttony-0.3.zip > Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD > Traceback (most recent call last): > ? ?File "/usr/bin/easy_install", line 9, in > ? ? ?load_entry_point('distribute==0.6.8', 'console_scripts', > 'easy_install')() > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1708, in main > ? ? ?with_ei_usage(lambda: > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1696, in with_ei_usage > ? ? ?return f() > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 1712, in > ? ? ?distclass=DistributionWithoutHelpCommands, **kw > ? ?File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup > ? ? ?dist.run_commands() > ? ?File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands > ? ? ?self.run_command(cmd) > ? ?File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command > ? ? ?cmd_obj.run() > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 236, in run > ? ? ?self.easy_install(spec, not self.no_deps) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 471, in easy_install > ? ? ?return self.install_item(spec, dist.location, tmpdir, deps) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 501, in install_item > ? ? ?dists = self.install_eggs(spec, download, tmpdir) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 680, in install_eggs > ? ? ?return self.build_and_install(setup_script, setup_base) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 957, in build_and_install > ? ? ?self.run_setup(setup_script, setup_base, args) > ? ?File > "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", > line 946, in run_setup > ? ? ?run_setup(setup_script, args) > ? ?File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line > 29, in run_setup > ? ? ?lambda: execfile( > ? ?File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line > 70, in run > ? ? ?return func() > ? ?File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line > 31, in > ? ? ?{'__file__':setup_script, '__name__':'__main__'} > ? ?File "setup.py", line 9, in > ? ?File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", > line 1, in > ? ? ?# > ? ?File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", > line 13, in > ImportError: No module named pip.log > root at sylvester ~ # > > ==================== > > I emerged app-misc/pip, but that didn't help, the error remains the same > > What is missing? > > Any help appreciated > > Best regards > > Hellmut > > Am 19.02.2010 17:16, schrieb Victor Lin: > > > > > > > Hi, > > > I just wrote a tool for drawing dependencies relationships diagram of > > Python project on Pypi. ?Here is the home page of the tool: > > >http://code.google.com/p/python-gluttony/ > > > Some examples: > > Sprox: > >http://static.ez2learn.com/gluttony/sprox_dot.png > > > TurboGears2: > >http://static.ez2learn.com/gluttony/tg2_dot.png > > > Hope this could be helpful :P > > > Regards. > > Victor Lin. > > -- > Dr. Hellmut Weber ? ? ? ? m... at hellmutweber.de > Degenfeldstra?e 2 ? ? ? ? tel ? +49-89-3081172 > D-80803 M?nchen-Schwabing mobil +49-172-8450321 > please: No DOCs, no PPTs. why: tinyurl.com/cbgq Hi, That is a mistake I made in when I am making the distribute. Thanks your reporting. I have already fixed the problem and released Gluttony 0.4, and I tried to install that, it works fine. Victor Lin. From spamfresser at ch3ka.de Wed Feb 24 12:56:03 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 18:56:03 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: Am 24.02.2010 18:23, schrieb mk: > Even then I'm not getting completely uniform distribution for some reason: > d 39411 > l 39376 > f 39288 > a 39275 > s 39225 > r 39172 > p 39159 > t 39073 > k 39071 > u 39064 > e 39005 > o 39005 > n 38995 > j 38993 > h 38975 > q 38958 > c 38938 > b 38906 > g 38894 > i 38847 > m 38819 > v 38712 > z 35321 > y 35228 > w 35189 > x 35075 > > Code: > > import operator > > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)]) The reason is 256 % 26 != 0 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is approx. 10) more often than w-z. You might want to skip the values 0-22 to achieve a truly uniform distribution. FYI: Electronic Cash PINs in europe (dont know about the rest of the world) were computed the same way (random hexdigit and just mod it when it's too large) leading to a high probability that your first digit was a 1 :) Regards, Michael From steve at holdenweb.com Wed Feb 24 12:59:53 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 12:59:53 -0500 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: mk wrote: > On 2010-02-24 03:50, Paul Rubin wrote: >> The stuff about converting 4 random bytes to a decimal string and then >> peeling off 2 digits at a time is pretty awful, and notice that since >> 2**32 is 4294967296, in the cases where you get 10 digits, the first >> 2-digit pair is never higher than 42. > > Yikes! I didn't think about that. This is probably where (some part of) > probability skewing comes from. > > Anyway, the passwords for authorized users will be copied and pasted > from email into in the application GUI which will remember it for them, > so they will not have to remember and type them in. So I have little in > the way of limitations of password length - even though in *some* cases > somebody might have to (or be ignorant enough) to retype the password > instead of pasting it in. > > In that case the "diceware" approach is not necessary, even though I > will certainly remember this approach for a case when users will have to > remember & type the passwords in. > > The main application will access the data using HTTP (probably), so the > main point is that an attacker is not able to guess passwords using > brute force. > > Using A-z with 10-char password seems to provide 3 orders of magnitude > more combinations than a-z: > >>>> 57 ** 10 > 362033331456891249L >>>> 25 ** 10 > 95367431640625L > > Even though I'm not sure it is worth it, assuming 1000 brute-force > guesses per second (which over the web would amount pretty much to DOS), > this would take # days: > >>>> 57 ** 10 / (1000 * 3600 * 24) > 4190200595L >>>> 25 ** 10 / (1000 * 3600 * 24) > 1103789L > > Even then I'm not getting completely uniform distribution for some reason: > > d 39411 > l 39376 > f 39288 > a 39275 > s 39225 > r 39172 > p 39159 > t 39073 > k 39071 > u 39064 > e 39005 > o 39005 > n 38995 > j 38993 > h 38975 > q 38958 > c 38938 > b 38906 > g 38894 > i 38847 > m 38819 > v 38712 > z 35321 > y 35228 > w 35189 > x 35075 > > Code: > > import operator > > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n)]) > > def count_chars(chardict, word): > for c in word: > try: > chardict[c] += 1 > except KeyError: > chardict[c] = 0 > > if __name__ == "__main__": > chardict = {} > for i in range(100000): > w = gen_rand_word(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > >> I'd write your code something like this: >> >> nletters = 5 >> >> def randomword(n): >> with open('/dev/urandom') as f: >> return ''.join([chr(ord('a')+ord(c)%26) for c in f.read(n)]) >> >> print randomword(nletters) > > Aw shucks when will I learn to do the stuff in 3 lines well instead of > 20, poorly. :-/ > When you've got as much experience as Paul? regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From deets at nospam.web.de Wed Feb 24 13:12:59 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 19:12:59 +0100 Subject: parametrizing a sqlite query In-Reply-To: References: Message-ID: <4B856C2B.3070502@nospam.web.de> Am 24.02.10 18:07, schrieb Sebastian Bassi: > c.execute("SELECT bin FROM bins WHERE qtl LIKE '%:keys%'",{'keys':keywords}) > > This query returns empty. When it is executed, keywords = 'harvest'. > To check it, I do it on the command line and it works as expected: > > sqlite> SELECT bin FROM bins WHERE qtl LIKE '%harvest%'; > 11C > 11D > 12F > > I guess there is a problem with the "%". You aren't supposed to put ' into the query. The thing you pass needs to be the full literal. Use c.execute("select ... qtl like :keys", dict(keys="%%%s%%" % keywords)) Diez From mrkafk at gmail.com Wed Feb 24 13:13:28 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 19:13:28 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 18:59, Steve Holden wrote: >> Aw shucks when will I learn to do the stuff in 3 lines well instead of >> 20, poorly. :-/ >> > When you've got as much experience as Paul? And how much experience does Paul have? (this is mostly not a facile question) For my part, my more serious effort (on and off) with programming in Python is under a year. Regards, mk From clp2 at rebertia.com Wed Feb 24 13:16:18 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 24 Feb 2010 10:16:18 -0800 Subject: Noob raw_input question In-Reply-To: References: Message-ID: <50697b2c1002241016w54c75270n25200a60279d050@mail.gmail.com> On Wed, Feb 24, 2010 at 9:39 AM, Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > ?File "", line 1, in > ? ?a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? raw_input() got renamed to just input(). Please read the 3.x transition docs at http://docs.python.org/3.1/whatsnew/3.0.html Cheers, Chris -- http://blog.rebertia.com From no.email at please.post Wed Feb 24 13:18:27 2010 From: no.email at please.post (kj) Date: Wed, 24 Feb 2010 18:18:27 +0000 (UTC) Subject: What's the word on using """ to comment-out? Message-ID: I think I remember, early in my learning of Python, coming across the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF CODE", or something to that effect. But now I can't find it! Is my memory playing me a trick? After all, from what I've seen since then, the practice of triple-quote-commenting (or TQC, pardon the TCA) is in fact quite common. Is TQC OK after all? If not, what's the case against it? Also, has the BDFL expressed an opinion on the subject? Alternatively, is there any other more or less "authoritative" opinion on TQC? TIA! ~K P.S. I can think of at least one reason to avoid TQC: it has basically the same problems with nesting that C's /**/ has. (Sure, in the case of TQC one could use "the other" triple quote, but it's not hard to see that this workaround goes only so far.) But this reason does not seem to bother many programmers, most of whom, after all, cut their teeth with C and /**/. P.S.2 I'm disregarding "it's un-Pythonic" as a reason against TQC, because it's not the kind of reason that carries much weight out here "in the trenches", as I've discovered. But, yes, I happen to think that TQC is un-Pythonic. After all, in my programming environment, it takes half as many keystrokes to comment a block of code with # than it does with """. I imagine that any decent programming environment makes #-commenting at least as easy. Therefore, there goes convenience as an argument in defense of TQC. Which leaves TMTOWTDI as the only possible defense for TQC, and TMTOWTDI is pretty un-Pythonic, no? :) From robert.kern at gmail.com Wed Feb 24 13:21:08 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 12:21:08 -0600 Subject: Noob raw_input question In-Reply-To: References: Message-ID: On 2010-02-24 11:39 AM, Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > File "", line 1, in > a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? Python 3 changed the name of raw_input() to input() (and the old input() method that evaluates the string was simply thrown out as being redundant and unsafe). http://docs.python.org/dev/3.0/whatsnew/3.0.html -- 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 jjposner at optimum.net Wed Feb 24 13:29:06 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 13:29:06 -0500 Subject: Noob raw_input question In-Reply-To: References: Message-ID: On 2/24/2010 12:39 PM, Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > File "", line 1, in > a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? > > The Python 2 built-in function "raw_input" has been renamed to "input" in Python 3. You'll probably run into this, too: Python 2: print "hello, world" Python 3: print("hello, world") You might want to install Python 2 if you're working your way through a tutorial that's targeted at that "generation" of the language. -John From steve at holdenweb.com Wed Feb 24 13:33:11 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 13:33:11 -0500 Subject: Noob raw_input question In-Reply-To: References: Message-ID: Abigail wrote: > Yesterday I downloaded and installed Python 3.1 and working through some > examples but I have hit a problem > >>>> a = raw_input("Enter a number" ) > Traceback (most recent call last): > File "", line 1, in > a = raw_input("Enter a number" ) > NameError: name 'raw_input' is not defined>>>a = raw_input("Enter a number > ") > > What am I doing wrong? > > In Python 3 raw_input() is now simply called input() regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From spam at removethis.btinternet.com Wed Feb 24 13:33:26 2010 From: spam at removethis.btinternet.com (Abigail) Date: Wed, 24 Feb 2010 18:33:26 -0000 Subject: Noob raw_input question References: Message-ID: Thank You From mrkafk at gmail.com Wed Feb 24 13:35:11 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 19:35:11 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 18:56, Michael Rudolf wrote: > The reason is 256 % 26 != 0 > 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is > approx. 10) more often than w-z. writing secure code is hard... I'm going to switch to PHP: Python world wouldn't lose much, but PHP would gain a lot. > You might want to skip the values 0-22 > to achieve a truly uniform distribution. Hmm perhaps you meant to skip values over 256 - 22 ? Bc I'm getting this (reduced the run to 1000 generated strings): def gen_rand_word(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > 22]) z 3609 b 3608 s 3567 e 3559 j 3556 r 3555 g 3548 p 3540 m 3538 q 3532 h 3528 y 3526 v 3524 i 3500 x 3496 c 3488 k 3488 l 3487 u 3487 a 3469 o 3465 d 3455 t 3439 f 3437 n 3417 w 3175 While with this: def gen_rand_word(n): with open('/dev/urandom') as f: return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) < 235]) a 3852 w 3630 s 3623 v 3582 y 3569 p 3568 c 3558 k 3558 b 3556 r 3553 x 3546 m 3534 n 3522 o 3515 h 3510 d 3505 u 3487 t 3486 i 3482 f 3477 e 3474 g 3460 q 3453 l 3437 z 3386 j 3382 1. I'm systematically getting 'a' outlier: have no idea why for now. 2. This is somewhat better (except 'a') but still not uniform. > FYI: Electronic Cash PINs in europe (dont know about the rest of the > world) were computed the same way (random hexdigit and just mod it when > it's too large) leading to a high probability that your first digit was > a 1 :) Schadenfreude is deriving joy from others' misfortunes; what is the German word, if any, for deriving solace from others' misfortunes? ;-) Regards, mk From robert.kern at gmail.com Wed Feb 24 14:01:03 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 13:01:03 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 12:35 PM, mk wrote: > While with this: > > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > < 235]) > > a 3852 ... > 1. I'm systematically getting 'a' outlier: have no idea why for now. > > 2. This is somewhat better (except 'a') but still not uniform. I will repeat my advice to just use random.SystemRandom.choice() instead of trying to interpret the bytes from /dev/urandom 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 rantingrick at gmail.com Wed Feb 24 14:03:52 2010 From: rantingrick at gmail.com (rantingrick) Date: Wed, 24 Feb 2010 11:03:52 -0800 (PST) Subject: What's the word on using """ to comment-out? References: Message-ID: <662efb8d-0ae0-4d98-b52e-9cc03ef77d80@k19g2000yqc.googlegroups.com> On Feb 24, 12:18?pm, kj wrote: > I think I remember, early in my learning of Python, coming across > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > LINES OF CODE", or something to that effect. ?But now I can't find > it! Your going to get many opinions on this subject but my stance is -- use quotes for stings and hash chars for comments -- thats the end of it for me ;) From no.email at nospam.invalid Wed Feb 24 14:09:43 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 11:09:43 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7xiq9mtpqg.fsf@ruckus.brouhaha.com> Robert Kern writes: > I will repeat my advice to just use random.SystemRandom.choice() > instead of trying to interpret the bytes from /dev/urandom directly. SystemRandom is something pretty new so I wasn't aware of it. But yeah, if I were thinking more clearly I would have suggested os.urandom instead of opening /dev/urandom. From mrkafk at gmail.com Wed Feb 24 14:09:59 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:09:59 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:01, Robert Kern wrote: > I will repeat my advice to just use random.SystemRandom.choice() instead > of trying to interpret the bytes from /dev/urandom directly. Oh I hear you -- for production use I would (will) certainly consider this. However, now I'm interested in the problem itself: why is the damn distribution not uniform? Regards, mk From mrkafk at gmail.com Wed Feb 24 14:12:09 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:12:09 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: Message-ID: <4B857A09.7040707@gmail.com> Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment). Regards, mk From mrkafk at gmail.com Wed Feb 24 14:12:09 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:12:09 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: Message-ID: <4B857A09.7040707@gmail.com> Get a decent editor, like PyScripter, and press Ctrl-' (toggle comment). Regards, mk From mrkafk at gmail.com Wed Feb 24 14:16:24 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 20:16:24 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:01, Robert Kern wrote: > I will repeat my advice to just use random.SystemRandom.choice() instead > of trying to interpret the bytes from /dev/urandom directly. Out of curiosity: def gen_rand_string(length): prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) return ''.join(chars) if __name__ == "__main__": chardict = {} for i in range(10000): ## w = gen_rand_word(10) w = gen_rand_string(10) count_chars(chardict, w) counts = list(chardict.items()) counts.sort(key = operator.itemgetter(1), reverse = True) for char, count in counts: print char, count s 3966 d 3912 g 3909 h 3905 a 3901 u 3900 q 3891 m 3888 k 3884 b 3878 x 3875 v 3867 w 3864 y 3851 l 3825 z 3821 c 3819 e 3819 r 3816 n 3808 o 3797 f 3795 t 3784 p 3765 j 3730 i 3704 Better, although still not perfect. Regards, mk From robert.kern at gmail.com Wed Feb 24 14:19:23 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 13:19:23 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 13:09 PM, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Oh I hear you -- for production use I would (will) certainly consider > this. However, now I'm interested in the problem itself: why is the damn > distribution not uniform? You want "< 234", not "< 235". (234 % 26 == 0), so you get some extra 'a's. -- 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 aahz at pythoncraft.com Wed Feb 24 14:26:36 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 11:26:36 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: In article <87sk8r5v2f.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> Joan Miller is a regular poster; this is off-topic, but it's not spam. > >Non sequitur. Spam is spam, not by who authors or posts it, but by its >distribution (to many people, e.g. via a forum like this one) and its >content (off-topic and unsolicited). > >The message is important, its poster is a regular here; that doesn't >stop the message being spam when posted here. That seems to miss the point to some extent. If I post my recipe for spinach lasagne here, is that spam? I don't think many people would call it spam, just an off-topic post. From my POV, spam is defined a bit more narrowly. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 14:27:36 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 11:27:36 -0800 Subject: What's the word on using """ to comment-out? References: Message-ID: In article , kj wrote: > >I think I remember, early in my learning of Python, coming across the >commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF >CODE", or something to that effect. But now I can't find it! > >Is my memory playing me a trick? Possibly. I certainly do that. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From spamfresser at ch3ka.de Wed Feb 24 14:30:40 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 20:30:40 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: Am 24.02.2010 19:35, schrieb mk: > On 2010-02-24 18:56, Michael Rudolf wrote: > >> The reason is 256 % 26 != 0 >> 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is >> approx. 10) more often than w-z. > > writing secure code is hard... So true. That's why one should stick to standard libs when it comes to crypto or security in general. It's just to easy to mess it up. Just ask Debian about whether touching OpenSSL was a good idea ;) >> You might want to skip the values 0-22 >> to achieve a truly uniform distribution. > Hmm perhaps you meant to skip values over 256 - 22 ? That's the same thing as x mod y equals x+N*y mod y for every natural N. > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > > 22]) Off-by-one-error: you're skipping len(range(22))==23 hits. OK, I just see that I wrote misleading 0-22 while I meant range(22). > While with this: > def gen_rand_word(n): > with open('/dev/urandom') as f: > return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) > < 235]) Same off-by-one. >> FYI: Electronic Cash PINs in europe (dont know about the rest of the >> world) were computed the same way (random hexdigit and just mod it when >> it's too large) leading to a high probability that your first digit was >> a 1 :) > Schadenfreude is deriving joy from others' misfortunes; what is the > German word, if any, for deriving solace from others' misfortunes? ;-) Well - "Schadenfreude" *is* in fact a german word :) "Schaden" is the event or result of misfortune, "Freude" is joy. Well, I really think that you should use repeated Random.choice on an alphabet. Or Random.Systemrandom.choice if you don't trust the PRNG. Regards, Michael From no.email at nospam.invalid Wed Feb 24 14:31:51 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 11:31:51 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7xeikatopk.fsf@ruckus.brouhaha.com> mk writes: > So I have little in the way of limitations of password length ...> > The main application will access the data using HTTP (probably), so > the main point is that an attacker is not able to guess passwords > using brute force. If it's HTTP instead of HTTPS and you're sending the password in the clear, then a serious attacker can simply eavesdrop the connection and pick up the password. Again, if the application is a web forum or something like that, the security requirements probably aren't terribly high. If it's (say) a financial application with potentially motivated attackers, you've got to be a lot more careful than I think you're being right now, and you should really get security specialists involved. > Using A-z with 10-char password seems to provide 3 orders of magnitude > more combinations than a-z: Yes, 2**10 = 1024 so (57/25)**10 is a little more than that. > Even then I'm not getting completely uniform distribution for some reason: Exact equality of the counts would be surprising and a sign that something was wrong with the generation process. It would be like flipping a coin 10000 times and getting exactly 5000 heads. The binomial distribution tells you that the number should be close to 5000, but that it's unlikely to be -exactly- 5000. Also, as Michael Rudolf mentioned, getting a letter by taking n%26 where n is drawn uniformly from [0..255] doesn't give a uniform distribution because 256 is not a multiple of 26. I had thought about making an adjustment for that when I posted, but it didn't seem worth cluttering up the code. Uniformity for its own sake doesn't gain you anything; what matters is entropy. If you compute the entropy difference between the slightly nonuniform distribution and a uniform one, it's very small. To get a more uniform distribution I usually just take a larger n, rather than conditionalizing the draws. For example, in the diceware-like code I posted, I read 10 random bytes (giving a uniform random number on [0..2**80]) from urandom for each word. That is still not perfectly uniform, but it's closer to the point where the difference would be very hard to detect. > Aw shucks when will I learn to do the stuff in 3 lines well instead of > 20, poorly. :-/ Well, that's partly a matter of practice, but I'll mention one way I simplified the code, which was by reading more bytes from /dev/urandom than was really necessary. I read one byte for each random letter (i.e. throwing away about 3 random bits for each letter) while you tried to encode the urandom data cleverly and map 4 random bytes to 5 alphabetic letters. /dev/urandom uses a cryptographic PRNG and it's pretty fast, so reading a few extra bytes from it to simplify your code doesn't really cost you anything. From robert.kern at gmail.com Wed Feb 24 14:36:29 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 13:36:29 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 13:16 PM, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Out of curiosity: > > def gen_rand_string(length): > prng = random.SystemRandom() > chars = [] > for i in range(length): > chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) > return ''.join(chars) > > if __name__ == "__main__": > chardict = {} > for i in range(10000): > ## w = gen_rand_word(10) > w = gen_rand_string(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > > > s 3966 > d 3912 > g 3909 > h 3905 > a 3901 > u 3900 > q 3891 > m 3888 > k 3884 > b 3878 > x 3875 > v 3867 > w 3864 > y 3851 > l 3825 > z 3821 > c 3819 > e 3819 > r 3816 > n 3808 > o 3797 > f 3795 > t 3784 > p 3765 > j 3730 > i 3704 > > Better, although still not perfect. This distribution is well within expectations. -- 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 mrkafk at gmail.com Wed Feb 24 15:02:07 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 21:02:07 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:19, Robert Kern wrote: > On 2010-02-24 13:09 PM, mk wrote: >> On 2010-02-24 20:01, Robert Kern wrote: >>> I will repeat my advice to just use random.SystemRandom.choice() instead >>> of trying to interpret the bytes from /dev/urandom directly. >> >> Oh I hear you -- for production use I would (will) certainly consider >> this. However, now I'm interested in the problem itself: why is the damn >> distribution not uniform? > > You want "< 234", not "< 235". (234 % 26 == 0), so you get some extra 'a's. Right, this explains the 'a' outlier. Fixed. But still: import operator import os import random import math def rand_str_custom(n): s = os.urandom(n) return ''.join([chr(ord('a') + ord(x) % 26) for x in s if ord(x) < 234]) def count_chars(chardict, word): for c in word: try: chardict[c] += 1 except KeyError: chardict[c] = 0 def rand_str_SystemRandom_seeding(length): seed = os.urandom(32) random.seed(seed) prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) return ''.join(chars) def rand_str_SystemRandom_noseeding(length): prng = random.SystemRandom() chars = [] for i in range(length): chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) return ''.join(chars) def sd(x): sd.sum += x sd.sum2 += x*x sd.n += 1.0 sum, sum2, n = sd.sum, sd.sum2, sd.n return math.sqrt(sum2/n - sum*sum/n/n) def gen_rand_with_fun(fun): print fun.__name__ chardict = {} for i in range(10000): w = fun(10) count_chars(chardict, w) counts = list(chardict.items()) counts.sort(key = operator.itemgetter(1), reverse = True) nums = [c[1] for c in counts] sd.sum = sd.sum2 = sd.n = 0 mean = (1.0*sum(nums))/len(nums) stddev = map(sd, nums)[-1] print 'mean', mean, 'std dev', stddev for char, count in counts: print char, count, '%.2f' % ((count - mean)/stddev), 'std devs away from mean' if __name__ == "__main__": gen_rand_with_fun(rand_str_SystemRandom_seeding) print gen_rand_with_fun(rand_str_SystemRandom_noseeding) print gen_rand_with_fun(rand_str_custom) rand_str_SystemRandom_seeding mean 3845.15384615 std dev 46.2016419186 l 3926 1.75 std devs away from mean y 3916 1.53 std devs away from mean d 3909 1.38 std devs away from mean a 3898 1.14 std devs away from mean p 3898 1.14 std devs away from mean c 3889 0.95 std devs away from mean u 3884 0.84 std devs away from mean j 3873 0.60 std devs away from mean n 3873 0.60 std devs away from mean w 3866 0.45 std devs away from mean x 3863 0.39 std devs away from mean r 3855 0.21 std devs away from mean m 3852 0.15 std devs away from mean b 3841 -0.09 std devs away from mean t 3835 -0.22 std devs away from mean o 3829 -0.35 std devs away from mean k 3827 -0.39 std devs away from mean i 3821 -0.52 std devs away from mean s 3812 -0.72 std devs away from mean q 3806 -0.85 std devs away from mean v 3803 -0.91 std devs away from mean g 3799 -1.00 std devs away from mean h 3793 -1.13 std devs away from mean e 3782 -1.37 std devs away from mean f 3766 -1.71 std devs away from mean z 3758 -1.89 std devs away from mean rand_str_SystemRandom_noseeding mean 3845.15384615 std dev 55.670522726 i 3961 2.08 std devs away from mean r 3911 1.18 std devs away from mean e 3910 1.16 std devs away from mean m 3905 1.08 std devs away from mean a 3901 1.00 std devs away from mean u 3893 0.86 std devs away from mean t 3882 0.66 std devs away from mean w 3872 0.48 std devs away from mean s 3870 0.45 std devs away from mean c 3868 0.41 std devs away from mean n 3866 0.37 std devs away from mean q 3865 0.36 std devs away from mean k 3863 0.32 std devs away from mean y 3848 0.05 std devs away from mean j 3836 -0.16 std devs away from mean v 3830 -0.27 std devs away from mean f 3829 -0.29 std devs away from mean z 3829 -0.29 std devs away from mean g 3827 -0.33 std devs away from mean l 3818 -0.49 std devs away from mean b 3803 -0.76 std devs away from mean d 3803 -0.76 std devs away from mean p 3756 -1.60 std devs away from mean x 3755 -1.62 std devs away from mean h 3744 -1.82 std devs away from mean o 3729 -2.09 std devs away from mean rand_str_custom mean 3517.15384615 std dev 40.7541336343 i 3586 1.69 std devs away from mean a 3578 1.49 std devs away from mean e 3575 1.42 std devs away from mean m 3570 1.30 std devs away from mean q 3562 1.10 std devs away from mean c 3555 0.93 std devs away from mean g 3552 0.86 std devs away from mean w 3542 0.61 std devs away from mean p 3536 0.46 std devs away from mean x 3533 0.39 std devs away from mean s 3528 0.27 std devs away from mean o 3524 0.17 std devs away from mean d 3516 -0.03 std devs away from mean t 3515 -0.05 std devs away from mean h 3511 -0.15 std devs away from mean v 3502 -0.37 std devs away from mean z 3502 -0.37 std devs away from mean b 3500 -0.42 std devs away from mean f 3496 -0.52 std devs away from mean u 3492 -0.62 std devs away from mean l 3486 -0.76 std devs away from mean r 3478 -0.96 std devs away from mean n 3476 -1.01 std devs away from mean j 3451 -1.62 std devs away from mean k 3450 -1.65 std devs away from mean y 3430 -2.14 std devs away from mean It would appear that SystemRandom().choice is indeed best (in terms of how much the counts stray from mean in std devs), but only after seeding it with os.urandom. Regards, mk From mrkafk at gmail.com Wed Feb 24 15:06:00 2010 From: mrkafk at gmail.com (mk) Date: Wed, 24 Feb 2010 21:06:00 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 20:30, Michael Rudolf wrote: >>> The reason is 256 % 26 != 0 >>> 256 mod 26 equals 22, thus your code is hitting a-v about 10% (256/26 is >>> approx. 10) more often than w-z. >> >> writing secure code is hard... > > So true. That's why one should stick to standard libs when it comes to > crypto or security in general. It's just to easy to mess it up. Just ask > Debian about whether touching OpenSSL was a good idea ;) That was brain-dead hiccup, for crying out loud how could they do smth so stupid. >> def gen_rand_word(n): >> with open('/dev/urandom') as f: >> return ''.join([chr(ord('a') + ord(x) % 26) for x in f.read(n) if ord(x) >> > 22]) > > Off-by-one-error: you're skipping len(range(22))==23 hits. Argh, it's late here. > Well, I really think that you should use repeated Random.choice on an > alphabet. > Or Random.Systemrandom.choice if you don't trust the PRNG. I just posted a comparison with calculating std deviations for various methods - using os.urandom, SystemRandom.choice with seeding and without seeding. They all seem to have slightly different distributions. Regards, mk From no.email at nospam.invalid Wed Feb 24 15:09:54 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 12:09:54 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7x3a0qpf8t.fsf@ruckus.brouhaha.com> mk writes: > def rand_str_custom(n): > s = os.urandom(n) > return ''.join([chr(ord('a') + ord(x) % 26) for x in s if ord(x) < 234]) Note that simply throws away some of the chars. You have to replace them, not throw them away. > rand_str_SystemRandom_seeding > mean 3845.15384615 std dev 46.2016419186 > l 3926 1.75 std devs away from mean > y 3916 1.53 std devs away from mean ... What do you think you're measuring here? Yes, if you're doing 1000's of draws from a distribution, you'd expect a few of them to be 1.75 sigma from the mean. Since there are 26 letters, you'd expect a multinomial distribution which you can test for with the multinomial test or some approximation from the article: http://en.wikipedia.org/wiki/Multinomial_test I wish I knew more statistics than I do, since there is probably some more familiar statistical test (e.g. the T-test) that you can use as the number of trials gets large, since each bin of the multinomial distribution should eventually start to look like a normal distribution due to the central limit theorem. Others here know a lot more about this stuff than I do, and can probably give better advice. Anyway though, the output of os.urandom should be extremely hard to distinguish from real randomness (that's the whole point of a cryptographic PRNG). From skylarking11 at gmail.com Wed Feb 24 15:15:30 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 24 Feb 2010 12:15:30 -0800 (PST) Subject: Trouble with ftplib uploading to an FTP server Message-ID: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> This bit of code is designed to get the external IP address and hostname of a client , write it locally to a file, then upload to an FTP server. It works locally( one can see the IP number and hostname with a time stamp in /Users/admin/Documents) , but when the file is opened on the server after it's FTP'ed , it's blank....I think my issue is something with the way I am utilizing the ftplib commands... I am pretty sure instead of FTPing the file, it's just creating a new one with the same name and uploading that? This script is running on some OS X 10.5 clients and reporting back to an Ubuntu 8.04 server...I am using the version of python bundled with 10.5.x ( 2.5.1 ) **************************************************************** import os import datetime import ftplib import urllib2 currdate = datetime.datetime.now() formatdate = currdate.strftime("%m-%d-%Y %H%M") def log(): fqn = os.uname()[1] ext_ip = urllib2.urlopen('http://whatismyip.org').read() log = open ('/Users/admin/Documents/locatelog.txt','w') log.write(str("Asset: %s " % fqn)) log.write(str("Checking in from IP#: %s" % ext_ip)) smush = str(fqn +' @ ' + formatdate) os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ Documents/%s.txt' % smush ) s = ftplib.FTP('10.7.1.71','username','password') fd = open('/Users/admin/Documents/%s.txt' % smush,'rb') s.storbinary("STOR %s.txt" % smush , fd) ***************************************************************************** From robert.kern at gmail.com Wed Feb 24 15:20:37 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 14:20:37 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-24 14:02 PM, mk wrote: > It would appear that SystemRandom().choice is indeed best (in terms of > how much the counts stray from mean in std devs), but only after seeding > it with os.urandom. Calling random.seed() does not affect SystemRandom() whatsoever. You are getting perfectly acceptable distributions for all three variants. -- 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 andrewpdavison at gmail.com Wed Feb 24 15:21:21 2010 From: andrewpdavison at gmail.com (Andrew Davison) Date: Wed, 24 Feb 2010 12:21:21 -0800 (PST) Subject: Artificial Neural Networks recommendation References: Message-ID: On Feb 24, 1:49?pm, Gereon Kaiping wrote: > - - PyNN (just a builder, requires external simulator) ?http://neuralensemble.org/trac/PyNN/ > - - Con-x (part of pyro) ?http://pyrorobotics.org/?page=Conx > - - PyNeurGen (includes genetic algorithms) ?http://pyneurgen.sourceforge.net/ > - - ffnet (only fast forward) ?http://ffnet.sourceforge.net/ > - - brian (spiking networks) ?http://www.briansimulator.org/ > - - PyBrain (machine learning) ?http://pybrain.org/ > > Can you give me a recommendation or a review on some of these? PyNN and Brian are intended more for biologically-realistic neural networks (for some value of realistic), aka neuronal networks, so I guess you can rule them out (similar tools that you might come across are NEST, NEURON, PCSIM). Cheers, Andrew From usenot at geekmail.INVALID Wed Feb 24 15:23:03 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Wed, 24 Feb 2010 21:23:03 +0100 Subject: Docstrings considered too complicated Message-ID: <20100224212303.242222c6@geekmail.INVALID> Hi all, a company that works with my company writes a lot of of their code in Python (lucky jerks). I've seen their code and it basically looks like this: """Function that does stuff""" def doStuff(): while not wise(up): yield scorn Now my question is this: How do I kill these people without the authorities thinking they didn't deserve it? /W -- INVALID? DE! From brixomatic at yahoo.com Wed Feb 24 15:40:10 2010 From: brixomatic at yahoo.com (Wanja Gayk) Date: Wed, 24 Feb 2010 21:40:10 +0100 Subject: When will Java go mainstream like Python? References: Message-ID: Am 24.02.2010, 00:22 Uhr, schrieb Lawrence D'Oliveiro : >> Java - The JVM code been hacked to death by Sun engineers (optimised) >> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >> ad-infinitum but nowhere as near to JVM > > Python is still faster, though. In synthetic microbenchmarks without any practical importance - possibly. > I think a key reason is that its VM supports > reference-counting, which the Java folks never quite got the grasp of. Reference counting is about the worst technique for garbage collection. Modern Java VM won't count references. They will just trace the active references from the rootand mark all objects it finds as active and save these. The remaining ones are garbage. The reason why this is faster is that there are usually less live objects than dead ones and there are less refereces to look at. kind regards W -- Erstellt mit Operas revolution?rem E-Mail-Modul: http://www.opera.com/mail/ --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From python at mrabarnett.plus.com Wed Feb 24 15:56:06 2010 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Feb 2010 20:56:06 +0000 Subject: Trouble with ftplib uploading to an FTP server In-Reply-To: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> References: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> Message-ID: <4B859266.5090201@mrabarnett.plus.com> Sky Larking wrote: > This bit of code is designed to get the external IP address and > hostname of a client , write it locally to a file, then upload to an > FTP server. It works locally( one can see the IP number and hostname > with a time stamp in /Users/admin/Documents) , but when the file is > opened on the server after it's FTP'ed , it's blank....I think my > issue is something with the way I am utilizing the ftplib commands... > I am pretty sure instead of FTPing the file, it's just creating a new > one with the same name and uploading that? > > This script is running on some OS X 10.5 clients and reporting back to > an Ubuntu 8.04 server...I am using the version of python bundled with > 10.5.x ( 2.5.1 ) > > **************************************************************** > import os > import datetime > import ftplib > import urllib2 > > > currdate = datetime.datetime.now() > formatdate = currdate.strftime("%m-%d-%Y %H%M") > > def log(): > > fqn = os.uname()[1] > ext_ip = urllib2.urlopen('http://whatismyip.org').read() > log = open ('/Users/admin/Documents/locatelog.txt','w') > log.write(str("Asset: %s " % fqn)) > log.write(str("Checking in from IP#: %s" % ext_ip)) > smush = str(fqn +' @ ' + formatdate) > os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ > Documents/%s.txt' % smush ) You're renaming the file while it's still open. What you've written is still in the buffer, not on disk. > s = ftplib.FTP('10.7.1.71','username','password') > fd = open('/Users/admin/Documents/%s.txt' % smush,'rb') > s.storbinary("STOR %s.txt" % smush , fd) > > ***************************************************************************** > From spamfresser at ch3ka.de Wed Feb 24 16:00:19 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Wed, 24 Feb 2010 22:00:19 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: Am 24.02.2010 21:06, schrieb mk: > > I just posted a comparison with calculating std deviations for various > methods - using os.urandom, SystemRandom.choice with seeding and without > seeding. I saw them > They all seem to have slightly different distributions. No they don't. Just run those tests again and you will see that you cannot put them in any order or behaviour. They are all correct now, except that you cannot seed SystemRandom, as it is *not* a PRNG (at least here, it is a wrapper for /dev/random) Regards, Michael From steve at holdenweb.com Wed Feb 24 16:06:22 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 16:06:22 -0500 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: Aahz wrote: > In article <87sk8r5v2f.fsf at benfinney.id.au>, > Ben Finney wrote: >> aahz at pythoncraft.com (Aahz) writes: >>> Joan Miller is a regular poster; this is off-topic, but it's not spam. >> Non sequitur. Spam is spam, not by who authors or posts it, but by its >> distribution (to many people, e.g. via a forum like this one) and its >> content (off-topic and unsolicited). >> >> The message is important, its poster is a regular here; that doesn't >> stop the message being spam when posted here. > > That seems to miss the point to some extent. If I post my recipe for > spinach lasagne here, is that spam? I don't think many people would call > it spam, just an off-topic post. From my POV, spam is defined a bit more > narrowly. Spam is, at least from my point of view, UCE: unsolicited commercial e-mail. So anything that isn't commercial (like those "send these to ten of your friends" emails) isn't spam (but it might just as well be). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From news123 at free.fr Wed Feb 24 16:21:59 2010 From: news123 at free.fr (News123) Date: Wed, 24 Feb 2010 22:21:59 +0100 Subject: Help with lambda In-Reply-To: <39ded391-c814-4c17-936f-3a4f55c3d9ec@b9g2000pri.googlegroups.com> References: <39ded391-c814-4c17-936f-3a4f55c3d9ec@b9g2000pri.googlegroups.com> Message-ID: <4b859877$0$23912$426a74cc@news.free.fr> Jonathan Gardner wrote: > On Feb 18, 4:28 am, lallous wrote: >> f = [lambda x: x ** n for n in xrange(2, 5)] > > This is (pretty much) what the above code does. > >>>> f = [] >>>> n = 2 >>>> f.append(lambda x: x**n) >>>> n = 3 >>>> f.append(lambda x: x**n) >>>> n = 4 >>>> f.append(lambda x: x**n) >>>> n = 5 >>>> f.append(lambda x: x**n) > > Now, when you call f[0], you are calling "lambda x: x**n". What is > "n"? > If you use a newer version of python (>= 2.5), then you might want to look at functools.partial. > def pow(a,n): > return a ** n > > f = [functools.partial(pow,n=n) for n in xrange(2, 5)] > Not sure, whether there's any (dis)advantage over > f = [lambda x,n=n: x ** n for n in xrange(2, 5)] or > f = [lambda x,n=n: pow(x,n) for n in xrange(2, 5)] bye N From tjreedy at udel.edu Wed Feb 24 16:29:18 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 24 Feb 2010 16:29:18 -0500 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: <20100224101423.GA27668@axis.g33x.de> References: <20100224101423.GA27668@axis.g33x.de> Message-ID: On 2/24/2010 5:14 AM, Lars Gust?bel wrote: > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: >> I stumbled uppon this and find it somewhat odd: some class methods of >> TarFile and TarInfo do not appears in either the online documentation or >> search while they have a doc string: >> >> http://docs.python.org/search.html?q=gzopen >> http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile >> >> See script at the end for list of class methods. >> >> Is this "by design" or is there some an odd bug in doc generation lurking >> around? This somehow seem to be specific to module tarfile. Fraction >> classmethod from_float() is available in the documentation and found by a >> search for example... > > First of all, Python's module documentation is not generated from module > docstrings, each module has its own rst text file in the documentation tree > instead. > > But to answer your question: Yes, this is intentional. The TarFile class has > three classmethods taropen(), gzopen(), and bz2open() each for a specific > compression method. These three are used internally by the TarFile.open() > classmethod and are not intended to be called directly. The TarFile.open() > method is the one that is publicly documented and supposed to be used. It > decides which of the three methods to use based on the mode argument and > does many more other high-level things as well. By current standards, the three private methods should be prefixed with '_' to indicate their private status. Could they be changed to head off such questions? Terry Jan Reedy From deets at nospam.web.de Wed Feb 24 16:39:44 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 22:39:44 +0100 Subject: python dowload In-Reply-To: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <7ulkl0F6acU1@mid.uni-berlin.de> Am 24.02.10 00:08, schrieb monkeys paw: > On 2/23/2010 3:17 PM, Tim Chase wrote: >> monkeys paw wrote: >>> I used the following code to download a PDF file, but the >>> file was invalid after running the code, is there problem >>> with the write operation? >>> >>> import urllib2 >>> url = 'http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf' >>> a = open('adobe.pdf', 'w') >> >> Sure you don't need this to be 'wb' instead of 'w'? > > 'wb' does the trick. Thanks all! > > Here is the final working code, i used an index(i) > to see how many reads took place, i have to assume there is > a default buffer size: > > import urllib2 > a = open('adobe.pdf', 'wb') > i = 0 > for line in > urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): > > i = i + 1 > a.write(line) > > print "Number of reads: %d" % i > a.close() > > > NEW QUESTION if y'all are still reading: > > Is there an integer increment operation in Python? I tried > using i++ but had to revert to 'i = i + 1' Instead, use enumerate: for i, line in enumerate(...): ... Diez From deets at nospam.web.de Wed Feb 24 16:50:04 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 22:50:04 +0100 Subject: compiling python question In-Reply-To: References: Message-ID: <4B859F0C.1060308@nospam.web.de> Am 24.02.10 03:00, schrieb Mag Gam: > I am trying to compile python with Tk bindings. Do I need to do > anything special for python to detect and enable Tk? What OS? What does the configure/build process say? Diez From arnodel at googlemail.com Wed Feb 24 16:52:26 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Wed, 24 Feb 2010 21:52:26 +0000 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: aahz at pythoncraft.com (Aahz) writes: > In article <87sk8r5v2f.fsf at benfinney.id.au>, > Ben Finney wrote: >>aahz at pythoncraft.com (Aahz) writes: >>> >>> Joan Miller is a regular poster; this is off-topic, but it's not spam. >> >>Non sequitur. Spam is spam, not by who authors or posts it, but by its >>distribution (to many people, e.g. via a forum like this one) and its >>content (off-topic and unsolicited). >> >>The message is important, its poster is a regular here; that doesn't >>stop the message being spam when posted here. > > That seems to miss the point to some extent. If I post my recipe for > spinach lasagne here, is that spam? Are they really good? Sounds good, spinach lasagne, I don't know a recipe for them. Maybe you could post it as Python code, with a lot of nested if-then-else clauses, of course :) -- Arnaud From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 16:54:25 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 10:54:25 +1300 Subject: Problem creating executable, with PyQwt References: Message-ID: David Boddie wrote: > On Tuesday 23 February 2010 05:32, Gib Bogle wrote: > >> David Boddie wrote: >> >>> I have previously referred people with py2exe/PyQt issues to this page on >>> the PyQt Wiki: >>> >>> http://www.py2exe.org/index.cgi/Py2exeAndPyQt >>> >>> If you can somehow convince py2exe to include the QtSvg module (and >>> presumably the libQtSvg library as well) then perhaps that will solve >>> this problem. >>> >>> David >> Thanks David, that worked a treat. :-) > > If you could update the Wiki (or maybe the py2exe Wiki, if they have one) > to say what you did, that would be useful for others in the future. Then > they'll only be one search away from the answer. :-) > > David OK, I'll put it on the to-do list. Gib From jgardner at jonathangardner.net Wed Feb 24 16:54:52 2010 From: jgardner at jonathangardner.net (Jonathan Gardner) Date: Wed, 24 Feb 2010 13:54:52 -0800 Subject: Docstrings considered too complicated In-Reply-To: <20100224212303.242222c6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> On Wed, Feb 24, 2010 at 12:23 PM, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ?while not wise(up): > ? ? ? ?yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? > kill -9 seems to work for me. You may want to explain, one day, why what they are doing is wrong. -- Jonathan Gardner jgardner at jonathangardner.net From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 16:59:18 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 10:59:18 +1300 Subject: Files required for porting python References: <79cb0516-c7ee-4ebd-b9ad-152c8371e1de@l24g2000prh.googlegroups.com> Message-ID: KIRAN wrote: "I see lot of code with several files." I had to laugh at this. From no.email at please.post Wed Feb 24 17:35:31 2010 From: no.email at please.post (kj) Date: Wed, 24 Feb 2010 22:35:31 +0000 (UTC) Subject: How to monitor memory usage within Python? (Linux) Message-ID: Is there some standard module for getting info about the process's memory usage, in a Linux/Unix system? (I want to avoid hacks that involve, e.g., scraping ps's output.) Thanks! ~K From dontsendleospam at gmail.com Wed Feb 24 17:37:42 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Wed, 24 Feb 2010 14:37:42 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> Message-ID: <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Hi Folks, Thanks everyone for the great contributions! I understand this better now. The distinction between a shorthand for a function definition and a shorthand for a loop iteration is crucial. Also: thanks for pointing out the even the list comprehension doesn't work in py3. That was incredibly useful! I was about to build a package using Python and now (unfortunately) I will have to find another language. Saved me a big headache! More details... > > I can't reproduce the error message that you cite. > Sorry, I made a cut and paste error in my first post. The error was exactly the one in your post. > Reason for the NameError: > > The above is a /generator expression/, evaluated in a class definition. > > The docs have a similar example but I'm sorry, I'm unable to find it! Anyway the > generator expression is evaluated as if its code was put in function. And from > within the scope of that function you can't access the class scope implicitly, > hence, no access to 'B'. > > > This is a /list comprehension/, not a generator expression (although > syntactically it's almost the same). > > It obeys different rules. > > Essentially the generator expression produces a generator object that you may > name or pass around as you wish, while the comprehension is just a syntactical > device for writing more concisely some equivalent code that's generated inline. > > However, apparently the rules changed between Python 2.x and Python 3.x. > > In Python 3.x also the list comprehension fails in a class definition: > > C:\test> py3 > Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> class T: > ... ? A = range(2) > ... ? B = range(4) > ... ? s = sum([(i*j) for i in A for j in B]) > ... > Traceback (most recent call last): > ? ?File "", line 1, in > ? ?File "", line 4, in T > ? ?File "", line 4, in > NameError: global name 'B' is not defined > ?>>> exit() Yuck! Why should the list comprehension fail in Py3? The scope rules that explain why the generator expression would fail don't apply in that case. Plus Guido's comment on generators being consumed quickly also doesn't apply. > > ?From one point of view it's good that Py3 provides about the same behavior for > generator expressions and list comprehensions. > > But I'd really like the above examples to Just Work. :-) > Absolutely agreed. Especially with the list comprehension. I read PEP 289 and the 2004 exchanges in the mailing list regarding scoping and binding issues in generator expressions, when this feature was added to the language. Forgive my blasphemy, but Guido got it wrong on this one, by suggesting that an obscure use case should drive design considerations when a far more common use case exists. The obscure use case involves confusing sequences of exceptions, while the common use case is consistent scope rules at different levels. For details search the mailing list for Guido's quote in PEP 289. Here is another example that fails... In [7]: class T: ...: A = range(2) ...: B = range(2,4) ...: g = (i*j for i in A for j in B) ...: s = sum(g) --------------------------------------------------------------------------- NameError Traceback (most recent call last) C:\Python26\ in () C:\Python26\ in T() C:\Python26\ in ((i,)) NameError: global name 'B' is not defined ... at sum(g)! These two examples work (doing the same thing at a global scope and a local scope): In [1]: class T: ...: def local(self): ...: A = range(2) ...: B = range(2,4) ...: g = (i*j for i in A for j in B) ...: s = sum(g) ...: In [2]: t = T() In [3]: t.local() In [4]: A = range(2) In [5]: B = range(2,4) In [6]: g = (i*j for i in A for j in B) In [7]: s = sum(g) Thanks to everyone who suggested workarounds. They are very helpful. At the same time, they are -- forgive my language -- so perlish (as in clever, and requiring deep understanding of the language). In Python, simple elegant constructs should work consistently across all scopes. The very fact that people chose to use the word 'workaround' indicates how quirky this aspect of the language is. It really doesn't need to be so quirky. Defining the semantics of generator expressions to mimic Arnaud's lambda workaround below would be just as justified as the current definition, and more pythonic (in the consistent, elegant sense). @Arnaud: I tried to find your earlier post -- googled "Arnaud lambda" -- but couldn't. Does anyone know of a more recent PEP that addresses these issues? Thanks, Leo. From cmpython at gmail.com Wed Feb 24 17:41:03 2010 From: cmpython at gmail.com (CM) Date: Wed, 24 Feb 2010 14:41:03 -0800 (PST) Subject: What's the word on using """ to comment-out? References: Message-ID: <4ed45391-dc4f-43ef-ab56-6743e71a31a0@o30g2000yqb.googlegroups.com> > After all, from what I've seen since then, the practice of > triple-quote-commenting (or TQC, pardon the TCA) is in fact quite > common. > > Is TQC OK after all? > > If not, what's the case against it? I have no sense of how approved it is, and don't have a strong opinion on it, but I would think that some cases against it could be: - It's used for docstrings, so when you scan code it is harder to instantly find comment blocks or docstrings if IDE parsers color code comments differently than docstrings. An IDE I use (Boa Constructor) uses "# XXX [comment]" as a comment that means "add to the to-do list" as well. - If you want to search for comments easily, you can search for #, which will probably only bring you to comments, whereas if you search for quote marks, they could be used in a number of different ways in the code. - Adhering to coding conventions is a good thing in open source applications. From deets at nospam.web.de Wed Feb 24 17:48:54 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Wed, 24 Feb 2010 23:48:54 +0100 Subject: How to monitor memory usage within Python? (Linux) In-Reply-To: References: Message-ID: <7ulomnFtk5U1@mid.uni-berlin.de> Am 24.02.10 23:35, schrieb kj: > Is there some standard module for getting info about the process's > memory usage, in a Linux/Unix system? > > (I want to avoid hacks that involve, e.g., scraping ps's output.) http://code.google.com/p/pympler/ Diez From aahz at pythoncraft.com Wed Feb 24 17:58:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 14:58:17 -0800 Subject: How to make an empty generator? References: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: In article , Terry Reedy wrote: > >Confusing generators and generator functions is, well, confusing. >For future reference, and clarity of communication in Pythonland, > >generator function: function that produces a generator when called; if >python coded, its body contains 'yield'. > >generator: iterator produced by a generator function; has .__next__ and >self-returning .__init__, like all other iterators. > >generator expression: an expression that evaluates to a generator; the >expression is used to create a temporary anonymous generator function >that is called to produce the generator and is then discarded. My preference is to use the terms "generator" and "generator iterator" (abbreviated "gen iter" or "geniter"). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 18:01:02 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:01:02 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: In article , Steve Holden wrote: >Aahz wrote: >> In article <87sk8r5v2f.fsf at benfinney.id.au>, >> Ben Finney wrote: >>> aahz at pythoncraft.com (Aahz) writes: >>>> >>>> Joan Miller is a regular poster; this is off-topic, but it's not spam. >>> >>> Non sequitur. Spam is spam, not by who authors or posts it, but by its >>> distribution (to many people, e.g. via a forum like this one) and its >>> content (off-topic and unsolicited). >>> >>> The message is important, its poster is a regular here; that doesn't >>> stop the message being spam when posted here. >> >> That seems to miss the point to some extent. If I post my recipe for >> spinach lasagne here, is that spam? I don't think many people would call >> it spam, just an off-topic post. From my POV, spam is defined a bit more >> narrowly. > >Spam is, at least from my point of view, UCE: unsolicited commercial >e-mail. So anything that isn't commercial (like those "send these to ten >of your friends" emails) isn't spam (but it might just as well be). That's roughly correct, but I also think that if someone posts the same message to five mailing lists, it's not unreasonable to call that spamming. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 18:01:52 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:01:52 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: In article <87sk8r5v2f.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> >> Joan Miller is a regular poster; this is off-topic, but it's not spam. > >Non sequitur. Spam is spam, not by who authors or posts it, but by its >distribution (to many people, e.g. via a forum like this one) and its >content (off-topic and unsolicited). > >The message is important, its poster is a regular here; that doesn't >stop the message being spam when posted here. Moreover, by your definition, your post above counts as spam. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Wed Feb 24 18:05:09 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:05:09 -0800 Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: In article , Ryan Kelly wrote: > >Yes. The idea of having a "bootstrapping exe" is that actual >application code can be swapped out without having to overwrite the >executable file. As long as you don't change python versions, this >allows updates to be safe against system crashes, even on platforms >without atomic file replacement. > >So the frozen app does this in a background thread: > > Esky(sys.executable,"http://my.updates.com").auto_update() > >And it hits the given url, grabs the latest zipfile, downloads and >unpacks and atomically places it into the application directory. Et >viola, your app is at the latest version. How does this work with a running app? What if the app is a service? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From deets at nospam.web.de Wed Feb 24 18:05:35 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 00:05:35 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <7ulpm0F3kiU1@mid.uni-berlin.de> Am 24.02.10 12:42, schrieb Michael Rudolf: > First: Thanks for all the replies so far, they really helped me. > > Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >>> >>> def a(x=None): >>> if x is None: >>> pass >>> else: >>> pass >>> >> This is the way to do it python, and it has its advantages: 1 docstring, >> 1 way do do it, 1 interface. > > Yes, I see. Actually I do now realize that even in Java I use method > overloading mostly to implement optional arguments anyway, like: > > void constructor(){this.foo='foo'; this.initotherstuff();} > void constructor(int x) {this.x=x; this.constructor();} > > and so on. > > So most of the time the idiom above is exactly what I need, as the > versions of the function share code anyway. > > But there are also cases where they do something completely different - > in these cases I might use one of the other solutions provided here or > simply make two or three functions and name them appropiately. > > I do now see that the pythonic approach is the "best" for most cases, > but I really loved to see that you *can* do overloading in a convenient > way if you really want to :D Those decorators just rock :D You can do, see packages such as PEAK rules. They offer not only type-based overloading, but also value-based. Diez From spamfresser at ch3ka.de Wed Feb 24 18:08:18 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 00:08:18 +0100 Subject: How to make an empty generator? In-Reply-To: References: <4b7ec87f$0$8819$c3e8da3@news.astraweb.com> <7a9c25c21002190944ucfcd964m6914fbb344a63f31@mail.gmail.com> Message-ID: Am 24.02.2010 23:58, schrieb Aahz: > (abbreviated "gen iter" or "geniter"). lol I don't know why, but this sounds like a sex toy to me ;) Regards, Michael From nyamatongwe+thunder at gmail.com Wed Feb 24 18:22:47 2010 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Wed, 24 Feb 2010 23:22:47 GMT Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: Steve Holden: > Spam is, at least from my point of view, UCE: unsolicited commercial > e-mail. Spam is more commonly defined as UBE (Unsolicited Bulk Email) of which UCE is a large subset. Its just as much spam if its pushing a political party or charity even though there may be no commercial advantage to the poster. Neil From ryan at rfk.id.au Wed Feb 24 18:30:07 2010 From: ryan at rfk.id.au (Ryan Kelly) Date: Thu, 25 Feb 2010 10:30:07 +1100 Subject: Upgrading Py2exe App In-Reply-To: References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> <7e9b9f31-a9a3-4b8c-a6d9-df9a1092e9ee@q21g2000yqm.googlegroups.com> Message-ID: <1267054207.2598.3.camel@rambutan> On Wed, 2010-02-24 at 15:05 -0800, Aahz wrote: > In article , > Ryan Kelly wrote: > > > >Yes. The idea of having a "bootstrapping exe" is that actual > >application code can be swapped out without having to overwrite the > >executable file. As long as you don't change python versions, this > >allows updates to be safe against system crashes, even on platforms > >without atomic file replacement. > > > >So the frozen app does this in a background thread: > > > > Esky(sys.executable,"http://my.updates.com").auto_update() > > > >And it hits the given url, grabs the latest zipfile, downloads and > >unpacks and atomically places it into the application directory. Et > >viola, your app is at the latest version. > > How does this work with a running app? What if the app is a service? The changes will only take effect the next time the app is started - currently there's no support for "hot upgrading" a running app. Would definitely be an interesting feature though... 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From aahz at pythoncraft.com Wed Feb 24 18:36:54 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 15:36:54 -0800 Subject: How to make an empty generator? References: Message-ID: In article , Michael Rudolf wrote: >Am 24.02.2010 23:58, schrieb Aahz: >> >> (abbreviated "gen iter" or "geniter"). > >lol I don't know why, but this sounds like a sex toy to me ;) And I thought only smutty Americans would have that twitch. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From soniyaa1111 at gmail.com Wed Feb 24 18:39:57 2010 From: soniyaa1111 at gmail.com (soniyaa 1111) Date: Wed, 24 Feb 2010 15:39:57 -0800 (PST) Subject: first website developed on new innovative shopping model Message-ID: <6772fae0-6392-413a-b5fa-2b37637a2d7a@k2g2000pro.googlegroups.com> http://www.shoppingreps.com?SourceId=1259 is the first website developed on new innovative shopping model. Group bargaining through social networking targeted towards volume discounts. It has presented a suitable platform to reflect this novel shopping idea. This concept and methodology is new to the internet world. The website offers free membership to the shoppers and vendors. It encourages shoppers to acquire quotes for themselves when a group is formed. The shoppers will know the size of the group and the complete product details for which they will be requested to fetch quotes from their own localities. Shoppers get their chance of testing their bargain capabilities and enjoy the benefits and fun of bargaining for a bulk order and a group. From rhodri at wildebst.demon.co.uk Wed Feb 24 18:42:47 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Wed, 24 Feb 2010 23:42:47 -0000 Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> Message-ID: On Wed, 24 Feb 2010 13:41:08 -0000, Luis M. Gonz?lez wrote: > This is the only way I know to define variables programatically in the > top-level namespace, without having to do it manually one by one. We see requests for this a lot, and the response that's frequently missed amongst all the technical trickery is "What on earth makes you think that defining variables programatically will help?" Usually the sensible thing is to collect such "variables" into a list or dictionary, since that's the only way you're going to access them safely without a whole heap more technical trickery. -- Rhodri James *-* Wildebeeste Herder to the Masses From steve at holdenweb.com Wed Feb 24 19:01:05 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 19:01:05 -0500 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: Neil Hodgson wrote: > Steve Holden: > >> Spam is, at least from my point of view, UCE: unsolicited commercial >> e-mail. > > Spam is more commonly defined as UBE (Unsolicited Bulk Email) of > which UCE is a large subset. Its just as much spam if its pushing a > political party or charity even though there may be no commercial > advantage to the poster. >From my point of view that's a far better definition. Thanks. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From robert.kern at gmail.com Wed Feb 24 19:08:38 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 18:08:38 -0600 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: On 2010-02-24 17:01 PM, Aahz wrote: > In article, > Steve Holden wrote: >> Spam is, at least from my point of view, UCE: unsolicited commercial >> e-mail. So anything that isn't commercial (like those "send these to ten >> of your friends" emails) isn't spam (but it might just as well be). > > That's roughly correct, but I also think that if someone posts the same > message to five mailing lists, it's not unreasonable to call that > spamming. This accords with my understanding of the term and, it appears, that of Wikipedia: http://en.wikipedia.org/wiki/Newsgroup_spam -- 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 aahz at pythoncraft.com Wed Feb 24 19:15:24 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 16:15:24 -0800 Subject: Executing Python code on another computer References: Message-ID: In article , SiWi wrote: > >So I wondered if it was possible to send the Python code I'm developing >on the netbook to the workstation pc via wlan, let the script execute >on the workstation pc and write the output back on the netbook. > >Is there any possibilty to achieve that goal? Fabric might help, but I think it relies on ssh. py.test also has remote capabilities. http://fabfile.org/ -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From jjposner at optimum.net Wed Feb 24 19:17:58 2010 From: jjposner at optimum.net (John Posner) Date: Wed, 24 Feb 2010 19:17:58 -0500 Subject: Docstrings considered too complicated In-Reply-To: <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> References: <20100224212303.242222c6@geekmail.INVALID> <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> Message-ID: On 2/24/2010 4:54 PM, Jonathan Gardner wrote: > On Wed, Feb 24, 2010 at 12:23 PM, Andreas Waldenburger > wrote: >> Hi all, >> >> a company that works with my company writes a lot of of their code in >> Python (lucky jerks). I've seen their code and it basically looks like >> this: >> >> """Function that does stuff""" >> def doStuff(): >> while not wise(up): >> yield scorn >> >> Now my question is this: How do I kill these people without the >> authorities thinking they didn't deserve it? >> > > kill -9 seems to work for me. > > You may want to explain, one day, why what they are doing is wrong. > They are thinking in JavaDoc, not Python. #------------------------------ """Function that does stuff""" def doStuff(): while not wise(up): yield scorn def doOtherStuff(): """Function that does stuff""" while wise(up): yield joy print doStuff.__doc__ print doOtherStuff.__doc__ #------------------------------ program output: None Function that does stuff -John From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 19:22:45 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 00:22:45 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Wed, 24 Feb 2010 21:23:03 +0100, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > while not wise(up): > yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? Well, the above isn't *wrong* as such, it is equivalent to: # Function that does stuff def doStuff(): while not wise(up): yield scorn which means the biggest problem is that they had the perfect opportunity to create a useful docstring and instead f***ed it up by turning it into a useless comment. The best way to teach them better is to introduce them to the joys of help(doStuff) and doctests. -- Steven From ben+python at benfinney.id.au Wed Feb 24 19:39:08 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 11:39:08 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: <878wai5etv.fsf@benfinney.id.au> Steve Holden writes: > Spam is, at least from my point of view, UCE: unsolicited commercial > e-mail. So anything that isn't commercial (like those "send these to > ten of your friends" emails) isn't spam (but it might just as well > be). That excludes things like the religious screeds, or any other one-way "get this message in front of as many eyeballs as possible" message. Spam is better defined as unsolicited bulk messaging. Whether it's commercial in nature is irrelevant. The content is relevant only in that it's unsolicited by the vast majority of its many recipients. -- \ ?I went to court for a parking ticket; I pleaded insanity. I | `\ said ?Your Honour, who in their right mind parks in the passing | _o__) lane??? ?Steven Wright | Ben Finney From ben+python at benfinney.id.au Wed Feb 24 19:41:55 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 11:41:55 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: <874ol65ep8.fsf@benfinney.id.au> aahz at pythoncraft.com (Aahz) writes: > In article <87sk8r5v2f.fsf at benfinney.id.au>, > Ben Finney wrote: > >Spam is spam, not by who authors or posts it, but by its distribution > >(to many people, e.g. via a forum like this one) and its content > >(off-topic and unsolicited). [?] > Moreover, by your definition, your post above counts as spam. No. Again, as several others have pointed out, discussions about how the forum should operate (meta-discussions, if you like) are on-topic in the forum. That's not to say they should dominate the forum, of course. -- \ ?I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.? | _o__) ?Groucho Marx | Ben Finney From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 19:51:20 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 00:51:20 GMT Subject: What's the word on using """ to comment-out? References: Message-ID: On Wed, 24 Feb 2010 18:18:27 +0000, kj wrote: > I think I remember, early in my learning of Python, coming across the > commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT LINES OF > CODE", or something to that effect. But now I can't find it! > > Is my memory playing me a trick? > > After all, from what I've seen since then, the practice of > triple-quote-commenting (or TQC, pardon the TCA) is in fact quite > common. Oooh, I hope not... for anything but Q&D scripting, folks should be using source control rather than filling their source code up with vast lumps of old dead code. > Is TQC OK after all? Only if you're lazy and slack, and being lazy and slack is itself only okay if you are only lazy and slack *a very little bit*. In a small script, using test-driven development, it is acceptable to comment out dead code for a single test run. At the end of the run, you either reverse the commenting out, or you delete the dead code. > If not, what's the case against it? Commenting out dead code is, itself, a BAD THING, regardless of whether you use comments or triple-quotes. http://www.coderenaissance.com/2008/09/quit-commenting-out-dead-code.html Triple-quoted comments are worrying, though, because the result of them is not specified by the language. (Other than docstrings, of course.) The CPython compiler optimizes them away at compile time, so they have no runtime influence at all, but other implementations may not include this optimization and so the string gets compiled into the byte-code, created at runtime, then immediately deleted. Ouch. -- Steven From magawake at gmail.com Wed Feb 24 19:55:25 2010 From: magawake at gmail.com (Mag Gam) Date: Wed, 24 Feb 2010 19:55:25 -0500 Subject: compiling python question In-Reply-To: <4B859F0C.1060308@nospam.web.de> References: <4B859F0C.1060308@nospam.web.de> Message-ID: <1cbd6f831002241655p2642ac10pa6c43598dcf98896@mail.gmail.com> sorry for the vague answer. Its Linux. The configure build does not say anything actually. This is for SAGE. I managed to have it pick it up by compiling/installing tcl and tk and then recompile python On Wed, Feb 24, 2010 at 4:50 PM, Diez B. Roggisch wrote: > Am 24.02.10 03:00, schrieb Mag Gam: >> >> I am trying to compile python with Tk bindings. Do I need to do >> anything special for python to detect and enable Tk? > > What OS? What does the configure/build process say? > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > From aahz at pythoncraft.com Wed Feb 24 19:56:04 2010 From: aahz at pythoncraft.com (Aahz) Date: 24 Feb 2010 16:56:04 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <874ol65ep8.fsf@benfinney.id.au> Message-ID: In article <874ol65ep8.fsf at benfinney.id.au>, Ben Finney wrote: >aahz at pythoncraft.com (Aahz) writes: >> In article <87sk8r5v2f.fsf at benfinney.id.au>, >> Ben Finney wrote: >>> >>>Spam is spam, not by who authors or posts it, but by its distribution >>>(to many people, e.g. via a forum like this one) and its content >>>(off-topic and unsolicited). >> >> Moreover, by your definition, your post above counts as spam. > >No. Again, as several others have pointed out, discussions about how the >forum should operate (meta-discussions, if you like) are on-topic in the >forum. We already agreed that the original post was not appropriate for c.l.py; further discussion about the precise term for describing that post is off-topic. Therefore, by your definition, your post is spam. My point is that c.l.py is somewhat tolerant of off-topic posts, and generally people who contribute to the newsgroup are more likely to get a pass on off-topic posts. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From robert.kern at gmail.com Wed Feb 24 19:58:17 2010 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 24 Feb 2010 18:58:17 -0600 Subject: Spam from gmail In-Reply-To: <878wai5etv.fsf@benfinney.id.au> References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: On 2010-02-24 18:39 PM, Ben Finney wrote: > Steve Holden writes: > >> Spam is, at least from my point of view, UCE: unsolicited commercial >> e-mail. So anything that isn't commercial (like those "send these to >> ten of your friends" emails) isn't spam (but it might just as well >> be). > > That excludes things like the religious screeds, or any other one-way > "get this message in front of as many eyeballs as possible" message. > > Spam is better defined as unsolicited bulk messaging. Whether it's > commercial in nature is irrelevant. The content is relevant only in that > it's unsolicited by the vast majority of its many recipients. That said, in the context of USENET or mailing lists, a single off-topic post to a single group/list from a regular contributor is not usually considered "bulk messaging" or "spam". There is already a perfectly fine word for that: "off-topic". Only when it gets cross-posted excessively or repeated verbatim indiscriminately does it usually get designated spam. I think there is an important distinction to be made between isolated off-topic messages and spam. It's not just about finding commonly agreed meanings of terms in aid of clear communication. There is a substantive difference. The repetitive nature of spam dictates what you can do about it. With spam, you can killfile people, or filter out certain hosts, or use statistical filters, or require registration or first-post moderation, etc. With the occasional off-topic post from a regular, you ask them not to do it again and subject them to unending threads about what spam is or isn't. But you only break out the comfy chair for the very worst of the offenders. -- 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 steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:04:54 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:04:54 GMT Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> Message-ID: On Wed, 24 Feb 2010 02:58:38 -0800, Luis M. Gonz?lez wrote: > I wonder why updating locals(), not from within a function, works (at > least in my interactive session). Because if you're in the global scope, locals() returns globals(), which is a real namespace and modifying it works. Inside a function, locals() returns a dict which is a *copy* of the function namespace. The reason for this is that local namespaces are not actually dicts, and you can't modify them except by actually assigning and deleting names in code. > And what about the trick of updating globals? Is it legal? If not, is > there any "legal" way to do what the OP needs? Yes, it is legal to modify globals(). It's just a dict, you can even do this: >>> globals()[2] = 4 >>> globals()[2] 4 although that's a pretty useless trick. But whether you should is another story. I won't say you should NEVER do so, but it should be rare to use global variables, and even rarer to create them programmatically. The better solution is almost always to create your own namespace, namely a dict, and use that explicitly. -- Steven From ldo at geek-central.gen.new_zealand Wed Feb 24 20:05:30 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Thu, 25 Feb 2010 14:05:30 +1300 Subject: When will Java go mainstream like Python? References: Message-ID: In message , Wanja Gayk wrote: > Reference counting is about the worst technique for garbage collection. It avoids the need for garbage collection. It means I can write things like contents = open(filename, "r").read() and know the file object will be immediately closed after its contents are returned. It also means I don?t have to predefine how much memory my program will use. A garbage collector will only kick in when the app runs low on memory. On a system with dynamic memory allocation, that will not happen until the entire system runs low on memory, unless you limit the app to some fixed amount. Which is an antiquated way of doing things. And then there?s caching. Modern CPUs owe most of their speed to assumptions that programs will obey locality of reference. Pointer-chasing is a cache- hostile activity. Garbage collection involves a lot of pointer-chasing, particularly of dead objects that have long since been flushed from the cache, compared with reference counting of recently-accessed objects. Therefore garbage collection loses performance. From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:06:16 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:06:16 GMT Subject: Use eval() safely? References: <7uejcjFgf6U1@mid.individual.net> Message-ID: On Wed, 24 Feb 2010 10:11:25 +0100, Dieter Maurer wrote: > Using functionality introduced with the class/type homogenization, it is > quite easy to get access to the "file" type (even when "__builtins__" is > disabled). Having "file", arbitrary files can be read, written, > destroyed... Not that I don't believe you (I do!) but could you demonstrate for the record? -- Steven From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:07:31 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:07:31 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 24 Feb 2010 18:23:17 +0100, mk wrote: > Anyway, the passwords for authorized users will be copied and pasted > from email into in the application GUI which will remember it for them, > so they will not have to remember and type them in. So to break your application's security model, all somebody has to do is use their PC and they have full access to their account? Or get hold of the copy and paste buffer? Or the application's config files? > So I have little in > the way of limitations of password length - even though in *some* cases > somebody might have to (or be ignorant enough) to retype the password > instead of pasting it in. Or your users might be sensible enough to not trust a role-your-own security model, and prefer to memorize the password than to trust that nobody will get access to their PC. > The main application will access the data using HTTP (probably), so the > main point is that an attacker is not able to guess passwords using > brute force. And why would they bother doing that when they can sniff the wire and get the passwords in plain text? You should assume your attackers are *smarter* than you, not trust them to be foolish. -- Steven From skylarking11 at gmail.com Wed Feb 24 20:21:58 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Wed, 24 Feb 2010 17:21:58 -0800 (PST) Subject: Trouble with ftplib uploading to an FTP server References: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> Message-ID: <79927f7d-d186-46f1-ab58-94a8d5f973fc@g10g2000yqh.googlegroups.com> On Feb 24, 3:56?pm, MRAB wrote: > Sky Larking wrote: > > This bit of code is designed to get the external IP address and > > hostname of a client , write it locally to a file, then upload to an > > FTP server. It works locally( one can see the IP number and hostname > > with a time stamp in /Users/admin/Documents) , but when the file is > > opened on the server after it's FTP'ed , it's blank....I think my > > issue is something with the way I am utilizing the ftplib commands... > > I am pretty sure instead of FTPing the file, it's just creating a new > > one with the same name and uploading that? > > > This script is running on some OS X 10.5 clients and reporting back to > > an Ubuntu 8.04 server...I am using the version of python bundled with > > 10.5.x ( 2.5.1 ) > > > **************************************************************** > > import os > > import datetime > > import ftplib > > import urllib2 > > > currdate = datetime.datetime.now() > > formatdate = currdate.strftime("%m-%d-%Y %H%M") > > > def log(): > > > ? ? fqn = os.uname()[1] > > ? ? ext_ip = urllib2.urlopen('http://whatismyip.org').read() > > ? ? log = open ('/Users/admin/Documents/locatelog.txt','w') > > ? ? log.write(str("Asset: %s " % fqn)) > > ? ? log.write(str("Checking in from IP#: %s" % ext_ip)) > > ? ? smush = str(fqn +' @ ' + formatdate) > > ? ? os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ > > Documents/%s.txt' % ?smush ) > > You're renaming the file while it's still open. What you've written is > still in the buffer, not on disk. > > > ? ? s = ftplib.FTP('10.7.1.71','username','password') > > ? ? fd = open('/Users/admin/Documents/%s.txt' % smush,'rb') > > ? ? s.storbinary("STOR %s.txt" % smush , fd) > > > ***************************************************************************** > > @ MRAB Thanks ... I can see the file in /Users/admin/Documents after the following line runs though? os.rename('/Users/admin/Documents/locatelog.txt','/Users/admin/ Documents/%s.txt' % smush ) For instance I just ran the script and os.rename() renamed it to: TestMachine.local @ 02-24-2010 2020.txt in that .txt file it reads: Asset: TestMachine.local Checking in from IP#: xx.xxx.xx.xxx This is what I want, but the FTP piece doesn't seem to work... From mrjean1 at gmail.com Wed Feb 24 20:27:05 2010 From: mrjean1 at gmail.com (MrJean1) Date: Wed, 24 Feb 2010 17:27:05 -0800 (PST) Subject: How to monitor memory usage within Python? (Linux) References: Message-ID: <6b5de37c-4a7b-4ee7-b5c8-6f412e3dbbab@l12g2000prg.googlegroups.com> For Linux only /Jean On Feb 24, 2:35?pm, kj wrote: > Is there some standard module for getting info about the process's > memory usage, in a Linux/Unix system? > > (I want to avoid hacks that involve, e.g., scraping ps's output.) > > Thanks! > > ~K From steven at REMOVE.THIS.cybersource.com.au Wed Feb 24 20:30:00 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 01:30:00 GMT Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: On Thu, 25 Feb 2010 11:39:08 +1100, Ben Finney wrote: > Spam is better defined as unsolicited bulk messaging. Whether it's > commercial in nature is irrelevant. The content is relevant only in that > it's unsolicited by the vast majority of its many recipients. Not quite. I've read tens of thousands of messages to comp.lang.python, and solicited perhaps some hundreds. Are all the rest spam? I should say not! I haven't solicited them: at no point did I say, explicitly or implicitly, "Hey strangers all over the world, send me messages asking questions about Python" but I do welcome them. (In fact, I'd be annoyed if everyone started sending the questions to me personally instead of to the list.) I think it is foolish to try to create a water-tight definition of "spam". It is clearly a fuzzy concept, which means sometimes right- thinking people can have legitimate disagreements as to whether or not something is "spam". For example, I happen to think that the OP's message about Fascism is off- topic but not spam. I think Joan is guilty of a breach of etiquette for failing to label it [OT] in the subject line, and she should have directed replies to a more appropriate forum (a mailing list, another newsgroup, a web forum, anywhere but here). But in my opinion, it didn't cross the line into spam. I wouldn't be the slightest bit tempted to killfile her, or flag the message as spam, in my mail/news client. If other people feel differently, well, that's your personal choice. But please don't try to tell me that *my* line between spam and ham is wrong, and that *yours* is the only correct one. (That last response is aimed at a generic You, not Ben specifically. Stupid English language, why can't we have a word for generic you?) -- Steven From no.email at nospam.invalid Wed Feb 24 20:31:31 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 17:31:31 -0800 Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7xk4u26qz0.fsf@ruckus.brouhaha.com> mk writes: > Anyway, the passwords for authorized users will be copied and pasted > from email into in the application GUI which will remember it for > them, so they will not have to remember and type them in. It occurs to me that you don't even need to mess with letters in that case: password = os.urandom(5).encode('hex') will generate a string of 10 hex digits that you can give to the user. (That is for Python 2.x but I think it might be broken in Python 3). It might be helpful if you could say what your application does, or anyway give an idea of what its actual security requirements are. Generating and emailing someone a random password is a fairly standard method for (e.g.) web forums to verify that the person has supplied a working email address, basically as a first level spam filter. Your scheme is probably ok for that. If you're doing something with more demanding security requirements, then as mentioned before, there is a whole lot of stuff you have to pay attention to, and focusing narrowly on password generation isn't that useful. From ben+python at benfinney.id.au Wed Feb 24 20:31:46 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 12:31:46 +1100 Subject: When will Java go mainstream like Python? References: Message-ID: <87vddm3xtp.fsf@benfinney.id.au> Lawrence D'Oliveiro writes: > [Reference counting] avoids the need for garbage collection. It means > I can write things like > > contents = open(filename, "r").read() > > and know the file object will be immediately closed after its contents > are returned. Not quite; it means you know that the object *becomes a candidate* for cleanup immediately after its contents are returned. When, or whether, that cleanup actually happens is not something that is necessarily promised by a reference-counting implementation. -- \ ?I tell you the truth: some standing here will not taste death | `\ before they see the Son of Man coming in his kingdom.? ?Jesus | _o__) Christ, c. 30 CE, as quoted in Matthew 16:28 | Ben Finney From ben+python at benfinney.id.au Wed Feb 24 20:47:48 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 25 Feb 2010 12:47:48 +1100 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: <87r5oa3x2z.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 25 Feb 2010 11:39:08 +1100, Ben Finney wrote: > > > Spam is better defined as unsolicited bulk messaging. Whether it's > > commercial in nature is irrelevant. The content is relevant only in > > that it's unsolicited by the vast majority of its many recipients. > > Not quite. > > I've read tens of thousands of messages to comp.lang.python, and > solicited perhaps some hundreds. Are all the rest spam? I should say > not! I haven't solicited them: at no point did I say, explicitly or > implicitly, "Hey strangers all over the world, send me messages asking > questions about Python" By subscribing to the forum, I maintain that you do exactly that. > but I do welcome them. Whether they're welcome or not, they're solicited in the sense of being delivered to the recipient who explicitly asked to receive messages on a particular range of topics. When a message that is well outside the nominal range of topics for a forum is broadcast to recipients by means of that forum, the message is unsolicited. -- \ ?All my life I've had one dream: to achieve my many goals.? | `\ ?Homer, _The Simpsons_ | _o__) | Ben Finney From m.76ahesh at gmail.com Wed Feb 24 20:59:48 2010 From: m.76ahesh at gmail.com (hot girl) Date: Wed, 24 Feb 2010 17:59:48 -0800 (PST) Subject: PAPER PRESENTATIONS AND SEMIMAR TOPICS. Message-ID: <9c9046ef-7e46-4b79-862e-e7d5be08d336@k41g2000yqm.googlegroups.com> PAPER PRESENTATIONS AND SEMIMAR TOPICS. CHECK OUR VAST PAPER PRESENTATIONS AND SEMIMAR TOPICS INCLUDING PROJECTS FOR FREE AT http://presentationsandseminars.blogspot.com From gagsl-py2 at yahoo.com.ar Wed Feb 24 21:04:01 2010 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Wed, 24 Feb 2010 23:04:01 -0300 Subject: Easter Eggs References: Message-ID: En Tue, 09 Feb 2010 20:40:50 -0300, Alf P. Steinbach escribi?: > I know 3 Python Easter Eggs, > > from __future__ import braces > import this > help( "antigravity" ) > > Are there more? Also try: import antigravity -- Gabriel Genellina From roy at panix.com Wed Feb 24 21:27:55 2010 From: roy at panix.com (Roy Smith) Date: Wed, 24 Feb 2010 21:27:55 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: In article , Steven D'Aprano wrote: > # Function that does stuff > def doStuff(): > while not wise(up): > yield scorn > > > which means the biggest problem is that they had the perfect opportunity > to create a useful docstring and instead f***ed it up by turning it into > a useless comment. > > The best way to teach them better is to introduce them to the joys of > help(doStuff) and doctests. Try the ROI (Return On Investment) argument. A programmer costs $X per hour (at first blush, take their salary, multiply by 1.5 for indirect costs, and divide by 2000 working hours per year). It took them N minutes to write that text, so now you know how much that piece of text cost in dollars. Given that you've invested that money, what's the best way to maximize your ROI? Well, you could take that text, and put it in front of the 'def' line. The ROI in that you can read the text when you view the source code. Perhaps by printing it out on green-bar, or carving it into clay tablets with a pointed stick. Or, you could put it after the 'def' line. Now, you can still read it when viewing the source file. But, you can also access it with help(). Or by getting the functions __doc__ string. Three times the ROI! Even the most pointy-haired bean counter can grok the fullness of that. From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 21:42:31 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 15:42:31 +1300 Subject: Executable problem - socket? Message-ID: Hi, My student has been developing a GUI (using PyQt and PyQwt) that runs a model written in Fortran and built as a DLL. She has to present on this work tomorrow. She makes an executable version of the Python code with py2exe, and the executable runs fine on her Vista laptop and my XP machine. It doesn't run on the PC that she must use for her talk tomorrow. The Fortran DLL code is started up, it writes some text output to a couple of log files, then it fails with a WindowsError (000001d) which is a write error. I suspect that this is the first attempt to write to a socket (communication from the DLL to Python is via sockets). The only clue is that the machines that her program runs on have Python installed, while the one that fails doesn't. Therefore I suspect that py2exe has omitted a necessary Python DLL. How can I track down what might be missing? Thanks Gib From python at mrabarnett.plus.com Wed Feb 24 22:10:14 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Feb 2010 03:10:14 +0000 Subject: Executable problem - socket? In-Reply-To: References: Message-ID: <4B85EA16.5090002@mrabarnett.plus.com> Gib Bogle wrote: > Hi, > My student has been developing a GUI (using PyQt and PyQwt) that runs a > model written in Fortran and built as a DLL. She has to present on this > work tomorrow. She makes an executable version of the Python code with > py2exe, and the executable runs fine on her Vista laptop and my XP > machine. It doesn't run on the PC that she must use for her talk > tomorrow. The Fortran DLL code is started up, it writes some text > output to a couple of log files, then it fails with a WindowsError > (000001d) which is a write error. I suspect that this is the first > attempt to write to a socket (communication from the DLL to Python is > via sockets). The only clue is that the machines that her program runs > on have Python installed, while the one that fails doesn't. Therefore I > suspect that py2exe has omitted a necessary Python DLL. How can I track > down what might be missing? > You could try Dependency Walker: http://dependencywalker.com/ From bigblueswope at gmail.com Wed Feb 24 22:34:16 2010 From: bigblueswope at gmail.com (BJ Swope) Date: Wed, 24 Feb 2010 22:34:16 -0500 Subject: Spam from gmail (Was: fascism) In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <20100223110954.5da3d679.darcy@druid.net> <4b848d96$1@dnews.tpgi.com.au> Message-ID: > > If you like, but I tend to interpret "meta-" as idempotent. It's easier on > my aspirin budget. > > -- > Robert Kern And here I thought it was little blue pills for idempotentcy... ---- Life is a sexually transmitted disease with a 100% fatality rate. -- brazzy Auburn fans are like slinkys... not really good for anything but they still bring a smile to your face when you push them down a flight of stairs. To argue that honorable conduct is only required against an honorable enemy degrades the Americans who must carry out the orders. -- Charles Krulak, Former Commandant of the Marine Corps We are all slave to our own paradigm. -- Joshua Williams If the letters PhD appear after a person's name, that person will remain outdoors even after it's started raining. -- Jeff Kay From steve at holdenweb.com Wed Feb 24 23:14:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Wed, 24 Feb 2010 23:14:56 -0500 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: > On Thu, 25 Feb 2010 11:39:08 +1100, Ben Finney wrote: > >> Spam is better defined as unsolicited bulk messaging. Whether it's >> commercial in nature is irrelevant. The content is relevant only in that >> it's unsolicited by the vast majority of its many recipients. > > Not quite. > > I've read tens of thousands of messages to comp.lang.python, and > solicited perhaps some hundreds. Are all the rest spam? I should say not! > I haven't solicited them: at no point did I say, explicitly or > implicitly, "Hey strangers all over the world, send me messages asking > questions about Python" but I do welcome them. > > (In fact, I'd be annoyed if everyone started sending the questions to me > personally instead of to the list.) > > I think it is foolish to try to create a water-tight definition of > "spam". It is clearly a fuzzy concept, which means sometimes right- > thinking people can have legitimate disagreements as to whether or not > something is "spam". > > For example, I happen to think that the OP's message about Fascism is off- > topic but not spam. I think Joan is guilty of a breach of etiquette for > failing to label it [OT] in the subject line, and she should have > directed replies to a more appropriate forum (a mailing list, another > newsgroup, a web forum, anywhere but here). But in my opinion, it didn't > cross the line into spam. I wouldn't be the slightest bit tempted to > killfile her, or flag the message as spam, in my mail/news client. > > If other people feel differently, well, that's your personal choice. But > please don't try to tell me that *my* line between spam and ham is wrong, > and that *yours* is the only correct one. > > (That last response is aimed at a generic You, not Ben specifically. > Stupid English language, why can't we have a word for generic you?) > > That's why SpamBayes allows per-user training. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From g.bogle at auckland.no.spam.ac.nz Wed Feb 24 23:35:56 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 17:35:56 +1300 Subject: Executable problem - socket? References: Message-ID: MRAB wrote: > Gib Bogle wrote: >> Hi, >> My student has been developing a GUI (using PyQt and PyQwt) that runs >> a model written in Fortran and built as a DLL. She has to present on >> this work tomorrow. She makes an executable version of the Python >> code with py2exe, and the executable runs fine on her Vista laptop and >> my XP machine. It doesn't run on the PC that she must use for her >> talk tomorrow. The Fortran DLL code is started up, it writes some >> text output to a couple of log files, then it fails with a >> WindowsError (000001d) which is a write error. I suspect that this is >> the first attempt to write to a socket (communication from the DLL to >> Python is via sockets). The only clue is that the machines that her >> program runs on have Python installed, while the one that fails >> doesn't. Therefore I suspect that py2exe has omitted a necessary >> Python DLL. How can I track down what might be missing? >> > You could try Dependency Walker: http://dependencywalker.com/ > Wow! I've heard of it, but never used it. The result is intriguing, but baffling. When I look at the executable ABM15.exe on my machine (where it runs OK), I see a couple of harmless messages, but interestingly the program shows up with a checksum inconsistency, between Link Checksum and Real Checksum. Apparently this causes no issues on my machine. On another XP machine, where the program fails with the write error, there is first a pop-up with this message: "Errors were detected when processing ABM15.exe. See the log for details." In the log there are two significant messages: "Error: The side-by-side configuration information for ABM15.exe contains errors. The application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem (14001)." (the checksum discrepancy is there also) "MSJAVA.DLL Error opening file. The system cannot find the file specified (2)." (needless to say, I'm not using Java, and MSJAVA.dll is not on the other machine either) I find it very puzzling that the "configuration information" (whatever that is) is OK on one machine and erroneous on another. DependencyWalker is obviously onto something - but what? (At this stage snide comments about Windows will be received without comment.) From jackdied at gmail.com Thu Feb 25 00:10:50 2010 From: jackdied at gmail.com (Jack Diederich) Date: Thu, 25 Feb 2010 00:10:50 -0500 Subject: Docstrings considered too complicated In-Reply-To: <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> References: <20100224212303.242222c6@geekmail.INVALID> <6cc20cea1002241354t19461a80gc8c4ae210af81a1b@mail.gmail.com> Message-ID: On Wed, Feb 24, 2010 at 4:54 PM, Jonathan Gardner wrote: > On Wed, Feb 24, 2010 at 12:23 PM, Andreas Waldenburger > wrote: >> >> Now my question is this: How do I kill these people without the >> authorities thinking they didn't deserve it? >> > > kill -9 seems to work for me. kill -1 -1 Back in the days of thin X terminals I used that one as a quicker alternative to actually logging out. It is also useful if you start a fork bunny and need to hit the panic switch before the machine grinds to a halt. -Jack From g.bogle at auckland.no.spam.ac.nz Thu Feb 25 00:22:04 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 18:22:04 +1300 Subject: Executable problem - correction References: Message-ID: The program doesn't fail with the write error on the other XP machine, it actually fails to execute at all, complaining about the configuration information. Therefore I'm seeing different behaviour on three XP machines: Box 1 (SP2): runs OK Box 2 (SP3): fails to start Box 3 (SP3): starts up, all Qt stuff works, fails after invoking the Fortran DLL Just to add to the confusion, execution is successful on a Windows 7 box. I forgot to mention that the laptop on which the program was built (and where it runs OK) is using Vista. I now see that it will probably be necessary to build separate Vista and XP versions - I should have realized this earlier, but was misled by the fact that the Vista-built program runs OK on my XP SP2 box. From timr at probo.com Thu Feb 25 00:44:32 2010 From: timr at probo.com (Tim Roberts) Date: Wed, 24 Feb 2010 21:44:32 -0800 Subject: What's Going on between (Verify) Python and win7? References: <87d3zxt3h4.fsf@castleamber.com> Message-ID: "W. eWatson" wrote: >Maybe someone could verify my result? > >open file >read file line >print line >close file > >data 1234 > >Execute it in a folder > >Create another folder and copy the program to it. >put in a new data file as > >data 4567 > >Execute the copied program >Does it give >data1234? No, of course not. C:\tmp\x>echo data 1234>data.txt C:\tmp\x>type check.py f = open('data.txt','r') print f.read() f.close() C:\tmp\x>check.py data 1234 C:\tmp\x>cd ..\y C:\tmp\y>echo data 4567>data.txt C:\tmp\y>copy ..\x\check.py . 1 file(s) copied. C:\tmp\y>check.py data 4567 C:\tmp\y> Would you like to post your exact code? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From half.italian at gmail.com Thu Feb 25 00:46:25 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Wed, 24 Feb 2010 21:46:25 -0800 (PST) Subject: Executable problem - correction References: Message-ID: <885c2e20-e4da-4aeb-bae7-7b3573bb1be1@k5g2000pra.googlegroups.com> On Feb 24, 9:22?pm, Gib Bogle wrote: > The program doesn't fail with the write error on the other XP machine, it > actually fails to execute at all, complaining about the configuration > information. ?Therefore I'm seeing different behaviour on three XP machines: > > Box 1 (SP2): runs OK > Box 2 (SP3): fails to start > Box 3 (SP3): starts up, all Qt stuff works, fails after invoking the Fortran DLL > > Just to add to the confusion, execution is successful on a Windows 7 box. > > I forgot to mention that the laptop on which the program was built (and where it > runs OK) is using Vista. ?I now see that it will probably be necessary to build > separate Vista and XP versions - I should have realized this earlier, but was > misled by the fact that the Vista-built program runs OK on my XP SP2 box. Did you compile the program with python 2.6? Try compiling with 2.5. ~Sean From sbassi at clubdelarazon.org Thu Feb 25 00:48:10 2010 From: sbassi at clubdelarazon.org (Sebastian Bassi) Date: Thu, 25 Feb 2010 02:48:10 -0300 Subject: parametrizing a sqlite query In-Reply-To: References: <9e2f512b1002240907v66682f1fi7d4d4c7d2dabd880@mail.gmail.com> Message-ID: <9e2f512b1002242148v2be5b4e2i387a54ee39f8dcd6@mail.gmail.com> On Wed, Feb 24, 2010 at 3:41 PM, Dennis Lee Bieber wrote: > ? ? ? ?No there isn't... The problem is that you need to put the wildcards > into the parameter instead of the placeholder. Thank you, it works now. Best, SB From greg.ewing at canterbury.ac.nz Thu Feb 25 01:00:26 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 19:00:26 +1300 Subject: Use eval() safely? In-Reply-To: References: <7uejcjFgf6U1@mid.individual.net> Message-ID: <7umhcaF9rkU1@mid.individual.net> Steven D'Aprano wrote: > Not that I don't believe you (I do!) but could you demonstrate for the > record? I posted a demonstration of this earlier in this thread. The key thing is the __subclasses__() method of a class. You can start with any object, work your way up the base class chain to object, and then use __subclasses__() to get to any builtin class in the system, including file. There was a sandboxing scheme put forward a while back which involves vetting the code and disallowing the use of any double-underscore attribute names. With a suitably censored set of builtin functions, this prevents the use of the __subclasses__ hack, as well as some other potential lines of attack. As far as I know, nobody managed to break it at the time, but it probably hasn't been tested much in the real world, if at all, so I probably wouldn't recommend using it for anything critical. -- Greg From g.bogle at auckland.no.spam.ac.nz Thu Feb 25 01:53:37 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Thu, 25 Feb 2010 19:53:37 +1300 Subject: Executable problem - correction References: <885c2e20-e4da-4aeb-bae7-7b3573bb1be1@k5g2000pra.googlegroups.com> Message-ID: Sean DiZazzo wrote: > On Feb 24, 9:22 pm, Gib Bogle wrote: >> The program doesn't fail with the write error on the other XP machine, it >> actually fails to execute at all, complaining about the configuration >> information. Therefore I'm seeing different behaviour on three XP machines: >> >> Box 1 (SP2): runs OK >> Box 2 (SP3): fails to start >> Box 3 (SP3): starts up, all Qt stuff works, fails after invoking the Fortran DLL >> >> Just to add to the confusion, execution is successful on a Windows 7 box. >> >> I forgot to mention that the laptop on which the program was built (and where it >> runs OK) is using Vista. I now see that it will probably be necessary to build >> separate Vista and XP versions - I should have realized this earlier, but was >> misled by the fact that the Vista-built program runs OK on my XP SP2 box. > > Did you compile the program with python 2.6? Try compiling with 2.5. > > ~Sean I'll have to check with Helvin, but I believe 2.6 was needed for the version of PyQt that she has installed. From ashokprabhuv at gmail.com Thu Feb 25 02:01:58 2010 From: ashokprabhuv at gmail.com (Ashok Prabhu) Date: Wed, 24 Feb 2010 23:01:58 -0800 (PST) Subject: Regular expression issue Message-ID: <3c13650c-a16d-422b-93f2-53d376c693d0@k2g2000pro.googlegroups.com> Hi, The following is a sample of my problem. I get input from user and store it in variable 'b'. I want to match the user input with the contents of another variable 'a'. However I m not able to get the exact match. Could someone help? >>> print a c c+ >>> b 'c+' >>> re.search(b,a).group() 'c' In the above example I want re to find the string 'c+' instead of 'c'. I want a solution without escaping the '+' symbol with backslash because it is given by the user. Thanks, ~Ashok. From sjdevnull at yahoo.com Thu Feb 25 02:03:30 2010 From: sjdevnull at yahoo.com (sjdevnull at yahoo.com) Date: Wed, 24 Feb 2010 23:03:30 -0800 (PST) Subject: When will Java go mainstream like Python? References: Message-ID: On Feb 24, 8:05?pm, Lawrence D'Oliveiro wrote: > In message , Wanja Gayk wrote: > > > Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. That's like saying that driving a VW Beetle avoids the need for an automobile. Reference counting is a form of garbage collection (like mark-sweep, copy-collect, and others), not a way of avoiding it. You're right that ref counting in many implementations is more deterministic than other common forms of garbage collection; IMO, Python would be well-served by making the ref-counting semantics it currently has a guaranteed part of the language spec--or at least guaranteeing that when a function returns, any otherwise unreferenced locals are immediately collected. I could be convinced otherwise, but I _think_ that that change would offer an alternative to all of the interesting cases of where the "with" statement is "useful". From arnodel at googlemail.com Thu Feb 25 02:30:20 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 07:30:20 +0000 Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: dontspamleo writes: > @Arnaud: I tried to find your earlier post -- googled "Arnaud lambda" > -- but couldn't. I remembered after posting that I sent this to python-ideas. Here is the first message in the thread: http://mail.python.org/pipermail/python-ideas/2007-December/001260.html In this thread, someone claims that this issue was discussed when genexps were first added to the language, but doesn't remember the rationale for taking this decision. Perhaps someone knows what discussion they refer to... -- Arnaud From greg.ewing at canterbury.ac.nz Thu Feb 25 02:46:41 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 20:46:41 +1300 Subject: while loop with the condition used in the body In-Reply-To: References: <6a7f57-hj1.ln1@satorlaser.homedns.org> Message-ID: <7umnjeF3epU1@mid.individual.net> Ulrich Eckhardt wrote: > so why not: > > while as : > ... > > and also: > > if as : > ... This sort of thing has been suggested repeatedly in the past, and it's always been rejected. That's not likely to change. Look up the past threads for the reasons why. -- Greg From jayeola at gmail.com Thu Feb 25 02:54:00 2010 From: jayeola at gmail.com (john maclean) Date: Thu, 25 Feb 2010 02:54:00 -0500 Subject: pydoc errors Message-ID: <4170c1721002242354q5057b2b3p46311d567777afc4@mail.gmail.com> python version is 2.6.2 does any one else have this issue? Seen a few closed tickets for various Linux Distros but it is obvoiusly still my problem. help> modules Please wait a moment while I gather a list of all available modules... dm.c: 1640: not running as root returning empty list ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowState' as flags when in fact it is of type 'GEnum' ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowActions' as flags when in fact it is of type 'GEnum' ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowMoveResizeMask' as flags when in fact it is of type 'GEnum' /usr/lib/python2.6/site-packages/httplib2/__init__.py:29: DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5 /usr/lib/python2.6/site-packages/httplib2/__init__.py:44: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha 2010-02-25 01:20:10.483800: ERROR: Could not load the stocks from /home/jmaclean/.gnome2/invest-applet/stocks.pickle: [Errno 2] No such file or directory: '/home/jmaclean/.gnome2/invest-applet/stocks.pickle' You must run this application as root -- John Maclean 07739 171 531 MSc (DIC) Enterprise Linux Systems Engineer From greg.ewing at canterbury.ac.nz Thu Feb 25 02:55:51 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 20:55:51 +1300 Subject: Creating variables from dicts In-Reply-To: <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> Message-ID: <7umo4kF7q8U1@mid.individual.net> Luis M. Gonz?lez wrote: > I still don't understand why is it a bad idea in the case of > globals(). > This is the only way I know to define variables programatically in the > top-level namespace, without having to do it manually one by one. The point is that creating variables whose names are computed at run time is usually a misguided thing to do in the first place. Think about it -- how are you going to *use* those variables that you've created? If the answer is that you're going to go looking for a way to read the values of variables whose names are computed at run time, you might as well not use variables at all, but just keep their values in a dictionary. -- Greg From paul.nospam at rudin.co.uk Thu Feb 25 02:56:05 2010 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Thu, 25 Feb 2010 07:56:05 +0000 Subject: What's the word on using """ to comment-out? References: Message-ID: <87hbp5rboq.fsf@rudin.co.uk> kj writes: > I think I remember, early in my learning of Python, coming across > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > LINES OF CODE", or something to that effect. But now I can't find > it! No idea, but it would be nice to have some multiline comment syntax (other than # at the beginning of each line). Particularly one that can be nested. From no.email at nospam.invalid Thu Feb 25 02:56:18 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 23:56:18 -0800 Subject: When will Java go mainstream like Python? References: Message-ID: <7xmxyxiw9p.fsf@ruckus.brouhaha.com> "sjdevnull at yahoo.com" writes: > IMO, Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec... > I could be convinced otherwise, but I _think_ that that change would > offer an alternative to all of the interesting cases of where the > "with" statement is "useful". The whole point of introducing the "with" statement was help cleanly get rid of the ugly and unsound reliance on refcounting semantics found in so much python code. Your proposal is aimed in the wrong direction. From no.email at nospam.invalid Thu Feb 25 02:58:39 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 24 Feb 2010 23:58:39 -0800 Subject: When will Java go mainstream like Python? References: Message-ID: <7xiq9liw5s.fsf@ruckus.brouhaha.com> Lawrence D'Oliveiro writes: > Pointer-chasing is a cache- hostile activity. Garbage collection > involves a lot of pointer-chasing, particularly of dead objects that > have long since been flushed from the cache, compared with reference > counting of recently-accessed objects. Therefore garbage collection > loses performance. Serious gc's these days only touch live data, not garbage; and they work on small enough regions of memory most of the time (generational scavenging) to not have too many cache misses. Also, hyperthreading seems to be coming back, allowing cpu cores to multitask in the presence of cache misses. From __peter__ at web.de Thu Feb 25 03:10:51 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 09:10:51 +0100 Subject: Regular expression issue References: <3c13650c-a16d-422b-93f2-53d376c693d0@k2g2000pro.googlegroups.com> Message-ID: Ashok Prabhu wrote: > The following is a sample of my problem. I get input from user and > store it in variable 'b'. I want to match the user input with the > contents of another variable 'a'. However I m not able to get the > exact match. Could someone help? > >>>> print a > c > c+ > >>>> b > 'c+' >>>> re.search(b,a).group() > 'c' > > In the above example I want re to find the string 'c+' instead of 'c'. > I want a solution without escaping the '+' symbol with backslash > because it is given by the user. >>> a = "yadda c+ yadda" >>> b = "c+" >>> re.search(re.escape(b), a).group() 'c+' But if you aren't interested in anything but string literals, you should use string search: >>> a.index(b) 6 Peter From aleksandr.goretoy at gmail.com Thu Feb 25 03:24:14 2010 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Thu, 25 Feb 2010 02:24:14 -0600 Subject: Creating variables from dicts In-Reply-To: <7umo4kF7q8U1@mid.individual.net> References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> <875b425e-2925-48ed-9ef9-b3018d7ac9b6@z35g2000yqd.googlegroups.com> <357236a4-22ed-44b8-b36a-5cf1d5850f31@b7g2000yqd.googlegroups.com> <4b8511f0$0$24096$426a74cc@news.free.fr> <7f9b4873-5a11-4e0f-99fd-8461364210fe@d2g2000yqa.googlegroups.com> <7umo4kF7q8U1@mid.individual.net> Message-ID: The problem i see with using globals() is that it can overwrite a previously defined function or key within the global namespace, making the code potentially dangerous and wild with exploits. my $0.02 -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Thu Feb 25 03:35:10 2010 From: alfps at start.no (Alf P. Steinbach) Date: Thu, 25 Feb 2010 09:35:10 +0100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: * sjdevnull at yahoo.com: > On Feb 24, 8:05 pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Wanja Gayk wrote: >> >>> Reference counting is about the worst technique for garbage collection. >> It avoids the need for garbage collection. > > That's like saying that driving a VW Beetle avoids the need for an > automobile. Reference counting is a form of garbage collection (like > mark-sweep, copy-collect, and others), not a way of avoiding it. > > You're right that ref counting in many implementations is more > deterministic than other common forms of garbage collection; IMO, > Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec--or at least > guaranteeing that when a function returns, any otherwise unreferenced > locals are immediately collected. > > I could be convinced otherwise, but I _think_ that that change would > offer an alternative to all of the interesting cases of where the > "with" statement is "useful". Well, relying on ref-counted garbage collection for cleanup actions (other than reclaiming memory) is pretty brittle in a language based on general garbage collection. As soon as a reference to X sneaks away somewhere, X doesn't clean up at scope's end, which is not a catastrophe in itself but means there's no telling when it happens or indeed whether it happens at all. I'm not sure but as I recall the D language has a solution to this, sort of declaring X so that no references to it can be retained anywhere, but it's a very different language. And Eiffel has the "expanded type" thing for "no references", but does it use that to support deterministic cleanup? I don't know whether the Eiffel 'dispose' is called for an expanded object. C# has a 'using' like Python 'with'. It works, sort of, but adds a lot of complexity. C++ has the notion of optional garbage collection (formalized in C++0x) with cleanup actions not tied to memory reclamation but to deterministically invoked destructors and I think that as an /idea/ that is clean and good, but in practice almost no-one uses garbage collection with C++, and reportedly the least unpopular implementation (the Boehm collector) imposes some very stiff requirements on the code. So I think there's no really good solution: the price for simplicity in one dimension is some complexity in another dimension, here deterministic cleanup and the problem of zombie objects (garbage collection simplifies a lot of things while zombie objects, objects that have had explicit cleanup performed and thus are invalid in a sense, compensate by adding back in a lot of complexity). Cheers, - Alf From greg.ewing at canterbury.ac.nz Thu Feb 25 03:43:08 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 25 Feb 2010 21:43:08 +1300 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <7umqtdFlrrU1@mid.individual.net> Lawrence D'Oliveiro wrote: > And then there?s caching. Modern CPUs owe most of their speed to assumptions > that programs will obey locality of reference. Pointer-chasing is a cache- > hostile activity. Another thing to consider is the rate at which garbage is created. Java's fundamental types (ints, floats, etc.) are unboxed, and objects are only used for relatively heavyweight things. So you can do quite a lot of useful computation in Java without creating any objects or leaving behind any garbage. In Python, on the other hand, you can't even do arithmetic without creating and destroying intermediate objects at every step. Collecting those objects promptly means that the same areas of memory tend to get re-used over and over, resulting in better cacheing behaviour. So I don't think you can assume that just because Java's garbage collection scheme works well for Java that it would also necessarily work well for Python. -- Greg From m.38ahesh at gmail.com Thu Feb 25 04:08:54 2010 From: m.38ahesh at gmail.com (Sree Rama) Date: Thu, 25 Feb 2010 01:08:54 -0800 (PST) Subject: Why born like human? Read Ramayana & Follow Rama. Message-ID: Why born like human? Read Ramayana & Follow Rama. Once in a life you should read this great story, read this story in simple language at http://ramayanastory-rama.blogspot.com/2010/02/sri-rama-prince-of-ayodhya.html From deets at nospam.web.de Thu Feb 25 04:13:23 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 10:13:23 +0100 Subject: pydoc errors In-Reply-To: References: Message-ID: <7umt9jF38rU1@mid.uni-berlin.de> Am 25.02.10 08:54, schrieb john maclean: > python version is 2.6.2 does any one else have this issue? Seen a few > closed tickets for various Linux Distros but it is obvoiusly still my > problem. > > > help> modules > > Please wait a moment while I gather a list of all available modules... > > dm.c: 1640: not running as root returning empty list > > ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowState' as > flags when in fact it is of type 'GEnum' > > ** (.:8391): WARNING **: Trying to register gtype 'WnckWindowActions' > as flags when in fact it is of type 'GEnum' > > ** (.:8391): WARNING **: Trying to register gtype > 'WnckWindowMoveResizeMask' as flags when in fact it is of type 'GEnum' > /usr/lib/python2.6/site-packages/httplib2/__init__.py:29: > DeprecationWarning: the md5 module is deprecated; use hashlib instead > import md5 > /usr/lib/python2.6/site-packages/httplib2/__init__.py:44: > DeprecationWarning: the sha module is deprecated; use the hashlib > module instead > import sha > 2010-02-25 01:20:10.483800: ERROR: Could not load the stocks from > /home/jmaclean/.gnome2/invest-applet/stocks.pickle: [Errno 2] No such > file or directory: > '/home/jmaclean/.gnome2/invest-applet/stocks.pickle' > You must run this application as root To me it looks as if one of your installed applications has nasty side-effects on module import. De-install it if possible, and see if that helps. Diez From no.email at nospam.invalid Thu Feb 25 04:28:30 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 25 Feb 2010 01:28:30 -0800 Subject: When will Java go mainstream like Python? References: Message-ID: <7xvddlslz5.fsf@ruckus.brouhaha.com> "Alf P. Steinbach" writes: > So I think there's no really good solution: the price for simplicity > in one dimension is some complexity in another dimension, You could look at the way Cyclone (http://cyclone.thelanguage.org) does region inference, and maybe combine that with a tracing gc. There are some functional language compilers that also use region inference. From clp2 at rebertia.com Thu Feb 25 04:41:09 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Feb 2010 01:41:09 -0800 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <50697b2c1002250141x5b40b3b8gf11e077ba8a80fef@mail.gmail.com> On Wed, Feb 24, 2010 at 11:03 PM, sjdevnull at yahoo.com wrote: > On Feb 24, 8:05?pm, Lawrence D'Oliveiro central.gen.new_zealand> wrote: >> In message , Wanja Gayk wrote: >> >> > Reference counting is about the worst technique for garbage collection. >> >> It avoids the need for garbage collection. > > That's like saying that driving a VW Beetle avoids the need for an > automobile. ?Reference counting is a form of garbage collection (like > mark-sweep, copy-collect, and others), not a way of avoiding it. > > You're right that ref counting in many implementations is more > deterministic than other common forms of garbage collection; IMO, > Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec--or at least > guaranteeing that when a function returns, any otherwise unreferenced > locals are immediately collected. > > I could be convinced otherwise, but I _think_ that that change would > offer an alternative to all of the interesting cases of where the > "with" statement is "useful". You're forgetting global context objects, such as those for Decimal: http://docs.python.org/library/decimal.html#decimal.localcontext Cheers, Chris -- http://blog.rebertia.com From arnodel at googlemail.com Thu Feb 25 05:24:09 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 02:24:09 -0800 (PST) Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> <878wai5etv.fsf@benfinney.id.au> Message-ID: Steven D'Aprano wrote: > (That last response is aimed at a generic You, not Ben specifically. > Stupid English language, why can't we have a word for generic you?) I thought the word was "one". -- Arnaud From nanyaks at googlemail.com Thu Feb 25 05:26:18 2010 From: nanyaks at googlemail.com (simn_stv) Date: Thu, 25 Feb 2010 02:26:18 -0800 (PST) Subject: taking python enterprise level?... Message-ID: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> hello people, i have been reading posts on this group for quite some time now and many, if not all (actually not all!), seem quite interesting. i plan to build an application, a network based application that i estimate (and seriously hope) would get as many as 100, 000 hits a day (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' or anything like it, its mainly for a financial transactions which gets pretty busy... so my question is this would anyone have anything that would make python a little less of a serious candidate (cos it already is) and the options may be to use some other languages (maybe java, C (oh God))...i am into a bit of php and building API's in php would not be the hard part, what i am concerned about is scalability and efficiency, well, as far as the 'core' is concerned. would python be able to manage giving me a solid 'core' and will i be able to use python provide any API i would like to implement?... im sorry if my subject was not as clear as probably should be!. i guess this should be the best place to ask this sort of thing, hope im so right. Thanks From jeanmichel at sequans.com Thu Feb 25 05:32:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 11:32:30 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: <4B8651BE.7080500@sequans.com> Michael Rudolf wrote: > First: Thanks for all the replies so far, they really helped me. > > Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >>> >>> def a(x=None): >>> if x is None: >>> pass >>> else: >>> pass >>> >> This is the way to do it python, and it has its advantages: 1 docstring, >> 1 way do do it, 1 interface. > > Yes, I see. Actually I do now realize that even in Java I use method > overloading mostly to implement optional arguments anyway, like: > > void constructor(){this.foo='foo'; this.initotherstuff();} > void constructor(int x) {this.x=x; this.constructor();} > > and so on. > > So most of the time the idiom above is exactly what I need, as the > versions of the function share code anyway. > > But there are also cases where they do something completely different > - in these cases I might use one of the other solutions provided here > or simply make two or three functions and name them appropiately. > > I do now see that the pythonic approach is the "best" for most cases, > but I really loved to see that you *can* do overloading in a > convenient way if you really want to :D Those decorators just rock :D > > Thanks again, > Michael You said it yourself: "simply make two or three functions and name them appropiately" :-) When 2 methods of a class were to have the same name for doing completely different things like you said, there's a design flaw to my opinion. JM From python.list at tim.thechases.com Thu Feb 25 05:44:31 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 04:44:31 -0600 Subject: What's the word on using """ to comment-out? In-Reply-To: <87hbp5rboq.fsf@rudin.co.uk> References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: <4B86548F.4070305@tim.thechases.com> Paul Rudin wrote: > kj writes: > >> I think I remember, early in my learning of Python, coming across >> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT >> LINES OF CODE", or something to that effect. But now I can't find >> it! > > No idea, but it would be nice to have some multiline comment syntax > (other than # at the beginning of each line). Particularly one that can > be nested. Well, there's always "if 0"/"if False", but that requires screwing with the indentation levels. Granted, any competent text editor will allow you to easily shift code indentation (I know Vim does, and am pretty sure Emacs will let you do the same...YMMV with other editors). But yes, there have been times that a multi-line commenting that doesn't touch your indentation would be nice, and I confess to using triple-quotes to do that (opting for """ or ''' based on the type of triple-quotes found in the code). However, I usually limit this for debugging purposes and they usually get pruned or uncommented for production code. -tkc From stefan_ml at behnel.de Thu Feb 25 05:50:05 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 11:50:05 +0100 Subject: When will Python go mainstream like Java? In-Reply-To: References: Message-ID: mk, 24.02.2010 18:30: > On 2010-02-24 03:26, George Sakkis wrote: >>> Well I for one wouldn't want Python to go exactly Java way, see this: >>> >>> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=jav... >>> >>> This is the percentage of job offers in UK where the keyword "Java" >>> appears. >>> >>> Same for C#, it looks like C# is eating Java's lunch now: >>> >>> http://www.itjobswatch.co.uk/charts/permanent-demand-trend.aspx?s=csh... >> >> This seems to be a UK-specific trend; in the US (and most other >> countries I know of) Java is still going strong, e.g. >> http://www.indeed.com/jobtrends?q=java%2C+c%23&l= > > Interesting, and I was thinking that UK sample was big enough for such > things not to matter. Lies, damn lies, and statistics ... Stefan From lacrima.maxim at gmail.com Thu Feb 25 05:56:41 2010 From: lacrima.maxim at gmail.com (Lacrima) Date: Thu, 25 Feb 2010 02:56:41 -0800 (PST) Subject: Using mock library (written by Michael Foord) Message-ID: <5989a385-ee81-4708-8409-3299e83dcfa7@k17g2000yqb.googlegroups.com> Hello! I use mock library http://www.voidspace.org.uk/python/mock/. There is no user group for the library, so I post in comp.lang.python and hope that people who use it will help me. The library allows to patch objects, using patch decorator. Patching is done only within the scope of the function. So if I have a lot of tests that need specific object to be patched I have to specify the same decorator for each test method: class TestSomething(unittest.TestCase): @patch('module.Class', spec = True) def test_method1(self, MockClass): Class() self.assertEquals(MockClass.called) @patch('module.Class', spec = True) def test_method2(self, MockClass): Class() MockClass.assert_called_with('foo') @patch('module.Class', spec = True) def test_method3(self, MockClass): foo = Class() self.assertRaises(AttributeError, foo.some_method) # and more ... So for every test method I always do the same patching! How can I avoid this? Thanks in advance. Sorry if my English isn't proper enough. With regards, Maxim. From jeanmichel at sequans.com Thu Feb 25 05:58:30 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 11:58:30 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: <4B8651BE.7080500@sequans.com> References: <4B8651BE.7080500@sequans.com> Message-ID: <4B8657D6.6080703@sequans.com> Jean-Michel Pichavant wrote: > Michael Rudolf wrote: >> First: Thanks for all the replies so far, they really helped me. >> >> Am 24.02.2010 11:28, schrieb Jean-Michel Pichavant: >>>> >>> def a(x=None): >>>> if x is None: >>>> pass >>>> else: >>>> pass >>>> >>> This is the way to do it python, and it has its advantages: 1 >>> docstring, >>> 1 way do do it, 1 interface. >> >> Yes, I see. Actually I do now realize that even in Java I use method >> overloading mostly to implement optional arguments anyway, like: >> >> void constructor(){this.foo='foo'; this.initotherstuff();} >> void constructor(int x) {this.x=x; this.constructor();} >> >> and so on. >> >> So most of the time the idiom above is exactly what I need, as the >> versions of the function share code anyway. >> >> But there are also cases where they do something completely different >> - in these cases I might use one of the other solutions provided here >> or simply make two or three functions and name them appropiately. >> >> I do now see that the pythonic approach is the "best" for most cases, >> but I really loved to see that you *can* do overloading in a >> convenient way if you really want to :D Those decorators just rock :D >> >> Thanks again, >> Michael > You said it yourself: "simply make two or three functions and name > them appropiately" :-) > > When 2 methods of a class were to have the same name for doing > completely different things like you said, there's a design flaw to my > opinion. > > JM I wonder if I've just written that my opinion is flawed... It surely is, but that's not why I meant :-) JM From steve at holdenweb.com Thu Feb 25 06:13:28 2010 From: steve at holdenweb.com (Steve Holden) Date: Thu, 25 Feb 2010 06:13:28 -0500 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: simn_stv wrote: > hello people, i have been reading posts on this group for quite some > time now and many, if not all (actually not all!), seem quite > interesting. > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. > > would python be able to manage giving me a solid 'core' and will i be > able to use python provide any API i would like to implement?... > > im sorry if my subject was not as clear as probably should be!. > i guess this should be the best place to ask this sort of thing, hope > im so right. > > Thanks I'd suggest that if you are running an operation that gets 100,000 hits a day then your problems won't be with Python but with organizational aspects of your operation. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From martin.hellwig at dcuktec.org Thu Feb 25 06:21:30 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Feb 2010 11:21:30 +0000 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On 02/25/10 10:26, simn_stv wrote: > what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. > > would python be able to manage giving me a solid 'core' and will i be > able to use python provide any API i would like to implement?... Python isn't the most efficient language, the assembler provided by the maker of your CPU probably is the best you can get, everything after that is a trade-off between performance and flexibility (flexible in the most flexible sense of the word :-)). That being said, for me, Python (well actually any turing complete programming language), is more like a box of lego with infinite amount of pieces. Scalability and API issues are the same as the shape and function of the model your making with lego. Sure some type of pieces might be more suited than other types but since you can simulate any type of piece with the ones that are already present, you are more limited by your imagination than by the language. So in short, I don't see any serious problems using Python, I have used it in Enterprise environments without any problems but than again I was aware not to use it for numerical intensive parts without the use of 3rd party libraries like numpy. Which for me resulted in not doing the compression of a database delta's in pure python but to offload that to a more suitable external program, still controlled from Python though. -- mph From tim.wintle at teamrubber.com Thu Feb 25 06:45:22 2010 From: tim.wintle at teamrubber.com (Tim Wintle) Date: Thu, 25 Feb 2010 11:45:22 +0000 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <1267098322.21809.26.camel@localhost> On Thu, 2010-02-25 at 02:26 -0800, simn_stv wrote: > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... I've got apps running that handle *well* over 100,000 hits / process / day using Python - although some of the heavy lifting is off-loaded to C and MySql - obviously without actually looking at your requirements that doesn't mean much as I don't know how much work each hit requires. Regarding financial transactions - you'll almost certainly want to integrate with something that already has transactional support (sql etc) - so I expect that will bear the brunt of the load > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God)) I've avoided integrating java with my python (I'm not a big fan of java) - but I've integrated quite a bit of C - it's fairly easy to do, and you can just port the inner loops if you see the need arise. > ...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. I've heard that php can be well scaled (by compiling it to bytecode/C++) - but my preference would always be to python. Tim From lie.1296 at gmail.com Thu Feb 25 06:58:11 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 25 Feb 2010 22:58:11 +1100 Subject: Can't Access ANY url from python (errno 61) In-Reply-To: <99bd0874-3462-4bb3-8c3c-54b73c88f9a6@q16g2000yqq.googlegroups.com> References: <46753272-0cdb-47b9-adf2-d4a0aade6606@o5g2000vbb.googlegroups.com> <41d2c353-cec4-43f6-bc68-b9fb48ce00e5@y17g2000yqd.googlegroups.com> <4b807791$0$8819$c3e8da3@news.astraweb.com> <99bd0874-3462-4bb3-8c3c-54b73c88f9a6@q16g2000yqq.googlegroups.com> Message-ID: <4b8665f5$1@dnews.tpgi.com.au> On 02/24/10 17:07, MattB wrote: > All -- problem solved. Following Lie's suggestions, and the links > from those pages, I went hunting around in my /library/preferences/ > SystemConfiguration/. I opened all of the 6 or 7 files that were in > there, and all looked as if they contained info directly related to my > airport card -- networks, server names, etc. So I copied them to a > backup folder and then deleted them. Then I rebooted. Glad to hear your problem solved. > Then I opened IDLE and was able to raise URLs again. I'm not sure > what it was about those files (or maybe a specific one) -- does anyone > have any ideas? Do the files get auto-generated? If they do, perhaps you could try diff-ing them with your backups and get some clue of what caused it. > Thanks for your help and suggestions while I tried to figure this out. From prasad.chand at gmail.com Thu Feb 25 07:23:24 2010 From: prasad.chand at gmail.com (prasad_chand) Date: Thu, 25 Feb 2010 04:23:24 -0800 (PST) Subject: A more pythonish code Message-ID: Hi, I use python to do simple math problems as a hobby. I have made a program that finds the number of divisors(factors) of a given number. I am hoping to improve my language skills, specifically I would like to re-write the function "prime_factors" more gracefully. While the program works right, I am hoping that I could get some input on how to write better python code. I have attached the code below. def prime_factors(n): """ Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) (1+1) = 10) Updates a global dictionary(my_dict) with prime numbers and number of occurances. In the case of 48 {2:4,3:1} """ tmp_n = n while True: if tmp_n == 1: break tmp_check = tmp_n for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): if tmp_n % x == 0: add_to_dict(x) tmp_n /= x break if tmp_check == tmp_n: #number is prime...so just to add to dict add_to_dict(tmp_n) break def add_one(x): return x+1 def mul(x,y): return x * y def add_to_dict(p_num): if my_dict.has_key(p_num): my_dict[p_num] += 1 else: my_dict[p_num] = 1 my_dict = {} prime_factors(135) l = map(add_one,my_dict.values()) print reduce(mul, l, 1) Thanks for your time. From elias.bachaalany at gmail.com Thu Feb 25 07:25:14 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 04:25:14 -0800 (PST) Subject: Pure virtual functions in Python? References: <4b810953$1@dnews.tpgi.com.au> Message-ID: On Feb 21, 11:21?am, Lie Ryan wrote: > On 02/21/10 19:27,lallouswrote: > > > > If the base defines the method and it was empty, then my C++ code > > would still call the function. This is not optimal because I don't > > want to go from C++ to Python if the _derived_ class does not > > implement the cb. > > That sounds like a microoptimization; have you profiled your code and > determined that calling empty function causes a bottleneck? I doubt it. > > > Now the base class should define it so that doc > > parsers properly describe the base class. > > The recipe suggested is not worth the trouble. > > Unfortunately I cannot use abc module since I use Python 2.5 > > Because nobody here could have guessed that your dispatcher was written > in C++; your problem is near trivial if your dispatcher is a pure-python > code. You are right. I haven't checked how much it costs to continuously call an empty function, but why do it if I know (during initialization from my C++ dispatcher code) that certain Python object should not have certain methods called. I still prefer not to call at all, even if it was an empty function. Regards, Elias From elias.bachaalany at gmail.com Thu Feb 25 07:25:48 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 04:25:48 -0800 (PST) Subject: Pure virtual functions in Python? References: <7udu49Fk3uU1@mid.individual.net> Message-ID: <38ddd614-583c-430d-b998-214bd6360eb2@b2g2000yqi.googlegroups.com> On Feb 22, 12:42?am, Gregory Ewing wrote: > lallouswrote: > > If the base defines the method and it was empty, then my C++ code > > would still call the function. This is not optimal because I don't > > want to go from C++ to Python if the _derived_ class does not > > implement the cb. > > I would simply not implement the method at all in the base > class. Then the C++ code can do an attribute lookup for > the method, and if it's not found, do nothing. > > -- > Greg That is what I currently do. But if I comment out the implementations (empty ones) then the documentation generation tool will not document the callbacks. From lie.1296 at gmail.com Thu Feb 25 07:27:03 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 25 Feb 2010 23:27:03 +1100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <4b866cb8$1@dnews.tpgi.com.au> On 02/25/10 07:40, Wanja Gayk wrote: > Am 24.02.2010, 00:22 Uhr, schrieb Lawrence D'Oliveiro > : > >>> Java - The JVM code been hacked to death by Sun engineers (optimised) >>> Python - The PVM code has seen speed-ups in Unladen or via Pyrex.. >>> ad-infinitum but nowhere as near to JVM >> >> Python is still faster, though. > > In synthetic microbenchmarks without any practical importance - possibly.. > >> I think a key reason is that its VM supports >> reference-counting, which the Java folks never quite got the grasp of. > > Reference counting is about the worst technique for garbage collection. I disagree IMO, assuming there is no circular reference, reference counting is the simple, lightweight, and best garbage collection technique. Reference counting can free memory (or return it to cache) right after the refcount turns zero; other traditional garbage management techniques runs periodically and there's a delay between getting to zero reference to actual memory release. The other weakness of traditional garbage managers is the symptomatic "stopping the time" whenever the GC is running, which makes it unsuitable for time-sensitive program. The only weakness of reference counting is its inability to detect circular reference, which is why CPython have an additional garbage collector. > Modern Java VM won't count references. They will just trace the active > references from the rootand mark all objects it finds as active and save > these. The remaining ones are garbage. The reason why this is faster is > that there are usually less live objects than dead ones and there are > less refereces to look at. Reference counting is even faster since there is only one object to be looked at: the object that is being dereferenced. There is no need to look at other live objects, there is no need to look other dead objects, just the current object. From elias.bachaalany at gmail.com Thu Feb 25 07:28:12 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 04:28:12 -0800 (PST) Subject: Walking lists Message-ID: Hello I am still learning Python, and have a question, perhaps I can shorten the code: L = ( (1, 2, 3), (4,), (5,), (6, 7) ) for x in L: print x What I want, is to write the for loop, something like this: for (first_element, the_rest) in L: print first_element for x in the_rest: # now access the rest of the elements I know I can : for x in L: first = x[0] rest = x[1:] .... Probably that is not possible, but just asking. Thanks, Elias From __peter__ at web.de Thu Feb 25 07:45:28 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 13:45:28 +0100 Subject: Walking lists References: Message-ID: lallous wrote: > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > for x in L: > print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > print first_element > for x in the_rest: > # now access the rest of the elements > > I know I can : > for x in L: > first = x[0] > rest = x[1:] > .... > Probably that is not possible, but just asking. In Python 3 you can write >>> for first, *rest in L: ... print("first:", first, "rest:", rest) ... first: 1 rest: [2, 3] first: 4 rest: [] first: 5 rest: [] first: 6 rest: [7] Peter From nanyaks at googlemail.com Thu Feb 25 07:46:38 2010 From: nanyaks at googlemail.com (simn_stv) Date: Thu, 25 Feb 2010 04:46:38 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On Feb 25, 12:13 pm, Steve Holden wrote: > simn_stv wrote: > > hello people, i have been reading posts on this group for quite some > > time now and many, if not all (actually not all!), seem quite > > interesting. > > i plan to build an application, a network based application that i > > estimate (and seriously hope) would get as many as 100, 000 hits a day > > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > > or anything like it, its mainly for a financial transactions which > > gets pretty busy... > > so my question is this would anyone have anything that would make > > python a little less of a serious candidate (cos it already is) and > > the options may be to use some other languages (maybe java, C (oh > > God))...i am into a bit of php and building API's in php would not be > > the hard part, what i am concerned about is scalability and > > efficiency, well, as far as the 'core' is concerned. > > > would python be able to manage giving me a solid 'core' and will i be > > able to use python provide any API i would like to implement?... > > > im sorry if my subject was not as clear as probably should be!. > > i guess this should be the best place to ask this sort of thing, hope > > im so right. > > > Thanks > > I'd suggest that if you are running an operation that gets 100,000 hits > a day then your problems won't be with Python but with organizational > aspects of your operation. > > regards > Steve > -- very well noted steve, i'd be careful (which is a very relative word) with the organizational aspects... i'm sure ure quite rooted in that aspect, hey u need a job??........;) From lie.1296 at gmail.com Thu Feb 25 07:50:51 2010 From: lie.1296 at gmail.com (Lie Ryan) Date: Thu, 25 Feb 2010 23:50:51 +1100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: Message-ID: <4b86724d$1@dnews.tpgi.com.au> On 02/25/10 05:18, kj wrote: > I think I remember, early in my learning of Python, coming across > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > LINES OF CODE", or something to that effect. But now I can't find > it! I've never heard of it, though I can think of a few reasons why TQC might be a bad thing. Especially if a user pydoc-ed your module and see a bunch of meaningless code. > Is my memory playing me a trick? > > After all, from what I've seen since then, the practice of > triple-quote-commenting (or TQC, pardon the TCA) is in fact quite > common. > > Is TQC OK after all? I'd say it's OK for quick and dirty code, or when you're rewriting a significant part of the code especially in early development (or you haven't setup a version control system since it's a damn small script). They shouldn't be permanent though, due to docstring problem. > If not, what's the case against it? > > Also, has the BDFL expressed an opinion on the subject? Alternatively, > is there any other more or less "authoritative" opinion on TQC? From fat.bold.cyclop at gmail.com Thu Feb 25 08:00:48 2010 From: fat.bold.cyclop at gmail.com (fat bold cyclop) Date: Thu, 25 Feb 2010 05:00:48 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? Message-ID: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> I tired to google for comparison of tuple to list but i failed. Could anyone explain it to me? Best regards, fat bold cyclop From python.list at tim.thechases.com Thu Feb 25 08:02:49 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 07:02:49 -0600 Subject: Walking lists In-Reply-To: References: Message-ID: <4B8674F9.2070904@tim.thechases.com> lallous wrote: > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > print first_element > for x in the_rest: > # now access the rest of the elements Python 3 introduced a variable tuple assignment which I suspect[*] would work in this context: for first, *rest in L: # note the asterisk print first for x in rest: do_stuff(x) > I know I can : > for x in L: > first = x[0] > rest = x[1:] However in 2.x, this is the way to do it. Though if you want to abstract the logic, you can move it to a generator: def splitter(i): for t in i: yield t[0], t[1:] for first, rest in splitter(L): print first for x in rest: do_stuff(x) -tkc [*] not having py3 on this machine, I can't readily verify this. From macbeth at panix.com Thu Feb 25 08:06:40 2010 From: macbeth at panix.com (macbeth) Date: Thu, 25 Feb 2010 08:06:40 -0500 Subject: What's the word on using """ to comment-out? In-Reply-To: <4b86724d$1@dnews.tpgi.com.au> Message-ID: > From: Lie Ryan > > On 02/25/10 05:18, kj wrote: > > I think I remember, early in my learning of Python, coming across > > the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT > > LINES OF CODE", or something to that effect. But now I can't find > > it! > > I've never heard of it, though I can think of a few reasons why TQC > might be a bad thing. Especially if a user pydoc-ed your module and see > a bunch of meaningless code. That is why I was told not to use """ to comment code. Use '#' for code and """ for docs But, I do not remember reading it any where. I found this ---> http://mail.python.org/pipermail/tutor/2004-February/028432.html From python.list at tim.thechases.com Thu Feb 25 08:07:59 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 07:07:59 -0600 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <4B86762F.9090606@tim.thechases.com> simn_stv wrote: > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. Python is as "enterprise" as the developer who wields it. Scalability revolves entirely around application design & implementation. Or you could use Erlang (or haskell, etc ;-) -tkc From gnewsg at gmail.com Thu Feb 25 08:15:04 2010 From: gnewsg at gmail.com (Giampaolo Rodola') Date: Thu, 25 Feb 2010 05:15:04 -0800 (PST) Subject: How to monitor memory usage within Python? (Linux) References: Message-ID: <01248751-3cfb-4603-9b68-9bca36106855@q16g2000yqq.googlegroups.com> On 24 Feb, 23:35, kj wrote: > Is there some standard module for getting info about the process's > memory usage, in a Linux/Unix system? > > (I want to avoid hacks that involve, e.g., scraping ps's output.) > > Thanks! > > ~K http://code.google.com/p/psutil >>> import psutil >>> p = psutil.Process(7055) >>> p.cmdline ['/usr/bin/python'] >>> rss, vms = p.get_memory_info() >>> "Resident memory: %s KB" %(rss / 1024) 'Resident memory: 3768 KB' >>> "Virtual memory: %s KB" %(vms / 1024) 'Virtual memory: 6176 KB' >>> p.get_memory_percent() 0.8342 --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ From silvio at nospam.com Thu Feb 25 08:17:55 2010 From: silvio at nospam.com (Silvio) Date: Thu, 25 Feb 2010 14:17:55 +0100 Subject: When will Java go mainstream like Python? In-Reply-To: References: Message-ID: <4b867886$0$22913$e4fe514c@news.xs4all.nl> "Lawrence D'Oliveiro" wrote in message news:hm4icr$q4o$1 at lust.ihug.co.nz... > In message , Wanja Gayk wrote: > >> Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. It means I can write things > like > > contents = open(filename, "r").read() > > and know the file object will be immediately closed after its contents are > returned. > > It also means I don?t have to predefine how much memory my program will > use. > A garbage collector will only kick in when the app runs low on memory. On > a > system with dynamic memory allocation, that will not happen until the > entire > system runs low on memory, unless you limit the app to some fixed amount. > Which is an antiquated way of doing things. > > And then there?s caching. Modern CPUs owe most of their speed to > assumptions > that programs will obey locality of reference. Pointer-chasing is a cache- > hostile activity. Garbage collection involves a lot of pointer-chasing, > particularly of dead objects that have long since been flushed from the > cache, compared with reference counting of recently-accessed objects. > Therefore garbage collection loses performance. Reference counting is a technique that is only applicable for a subset of scenarios GC can handle. RC fails when circular dependencies exist. In an ancient past I have worked with RC-based C++ frameworks and they where either very restrictive to prevent circular dependencies or ignored them resulting in memory leaks. In addition, for fast create/destroy scenario's (for examples loops that allocate objects with single cycle lifetimes) a generational GC is MUCH faster than manual malloc/free new/delete code because it enables a completely different heap management logic. Reference counting only adds to the slowness in this scenario. You are also incorrect in stating that a GC will only kick in when memory becomes scarce. Partial GCs will happen very frequently (thereby invalidating your point about caching) and are extremely fast. Only full GCs are infrequent and take more time but they will typically run in a separate thread. No general statement about the relative speed of generational GC systems versus manual heap management (or the slower variant RC) can be made since they have completely different best, general and worse case behavior and scenarios. In response to your original post: please provide links to examples of quality benchmark results. There are numerous language speed comparison benchmarks that usually put Python in the tail region with Ruby and the likes for many different applications. If you have opposing examples then you should provide them. Silvio From __peter__ at web.de Thu Feb 25 08:26:18 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 14:26:18 +0100 Subject: Using mock library (written by Michael Foord) References: <5989a385-ee81-4708-8409-3299e83dcfa7@k17g2000yqb.googlegroups.com> Message-ID: Lacrima wrote: > I use mock library http://www.voidspace.org.uk/python/mock/. There is > no user group for the library, so I post in comp.lang.python and hope > that people who use it will help me. > > The library allows to patch objects, using patch decorator. Patching > is done only within the scope of the function. So if I have a lot of > tests that need specific object to be patched I have to specify the > same decorator for each test method: > > class TestSomething(unittest.TestCase): > > @patch('module.Class', spec = True) > def test_method1(self, MockClass): > Class() > self.assertEquals(MockClass.called) > > @patch('module.Class', spec = True) > def test_method2(self, MockClass): > Class() > MockClass.assert_called_with('foo') > > @patch('module.Class', spec = True) > def test_method3(self, MockClass): > foo = Class() > self.assertRaises(AttributeError, foo.some_method) > > # and more ... > > So for every test method I always do the same patching! How can I > avoid this? I don't know mock, but the following is generic and should continue to work when you replace the faux patch() function with the one from the mock module. import unittest def patch(v): def patch(f): print "%s-patching" % v, f.__name__ return f return patch def make_postprocess(*args, **kw): def postprocess(name, bases, classdict): for k, v in classdict.items(): if k.startswith("test_"): classdict[k] = patch(*args, **kw)(v) return type(name, bases, classdict) return postprocess class A(unittest.TestCase): __metaclass__ = make_postprocess("Y") def test_bar(self): print "bar" def test_baz(self): print "baz" def foo(self): pass if __name__ == "__main__": unittest.main() Peter From arnodel at googlemail.com Thu Feb 25 08:26:45 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 05:26:45 -0800 (PST) Subject: Walking lists References: Message-ID: lallous wrote: > Hello > > > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > for x in L: > print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > print first_element > for x in the_rest: > # now access the rest of the elements > > I know I can : > for x in L: > first = x[0] > rest = x[1:] Others have replied about Python 3. In Python 2.x, you can use an iterator: for tuple in L: it = iter(tuple) first = it.next() for x in it: ... HTH -- Arnaud From elias.bachaalany at gmail.com Thu Feb 25 08:30:06 2010 From: elias.bachaalany at gmail.com (lallous) Date: Thu, 25 Feb 2010 05:30:06 -0800 (PST) Subject: Walking lists References: Message-ID: Thank you all for the replies. The solution using Python 3's syntax look very intuitive. Thanks Tim, Arnaud for the idea (I am using 2.x) -- Elias On Feb 25, 1:28?pm, lallous wrote: > Hello > > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > ? (1, 2, 3), > ? (4,), > ? (5,), > ? (6, 7) > ) > > for x in L: > ? ? print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_rest) in L: > ? print first_element > ? for x in the_rest: > ? ? # now access the rest of the elements > > I know I can : > for x in L: > ? ? first = x[0] > ? ? rest = x[1:] > ? ? .... > Probably that is not possible, but just asking. > > Thanks, > Elias From mrkafk at gmail.com Thu Feb 25 08:30:12 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 14:30:12 +0100 Subject: The best way to check if two lists have identical values Message-ID: Hello everyone, I have stumbled upon this seemingly trivial problem: the answer is not there in http://www.python.org/doc/faq/programming/, and googling does not return many references really (at least for me). I have come up with this: def qips_identical(q, oldq): qips = map(operator.itemgetter(1), q) oldqips = map(operator.itemgetter(1), oldq) if len(qips) != len(oldqips): return False dif = set(qips) ^ set(oldqips) if len(dif): return False return True There's a number of complications here, depending on definition of 'lists with identical values', like whether the same value can be repeated different number of times in two lists, or whether the order of values matters. In above example I assumed that the same values have to be repeated the same numbers of times in both lists and that order doesn't matter so long as the values are the same. I was wondering if there's a better / shorter / faster way to do this -- not necessarily in the same variant, e.g. variant where order of two lists matters would be interesting as well. Regards, mk From mrkafk at gmail.com Thu Feb 25 08:38:19 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 14:38:19 +0100 Subject: Easter Eggs In-Reply-To: References: Message-ID: On 2010-02-25 03:04, Gabriel Genellina wrote: > Also try: > import antigravity Is this Py3 egg? My 2.6 doesn't seem to get it. Regards, mk From spamfresser at ch3ka.de Thu Feb 25 08:44:20 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 14:44:20 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: <4B8651BE.7080500@sequans.com> Message-ID: Am 25.02.2010 11:58, schrieb Jean-Michel Pichavant: >> You said it yourself: "simply make two or three functions and name >> them appropiately" :-) >> >> When 2 methods of a class were to have the same name for doing >> completely different things like you said, there's a design flaw to my >> opinion. >> >> JM > I wonder if I've just written that my opinion is flawed... It surely is, > but that's not why I meant :-) :D Well, there might be cases when someone wants to do this. consider: (pseudocode - this is *not* python ;) class Machines (Object): @classmethod def shutdown(cls, Machine, emergency=False): try: if Machine is instanceof(Fileservers): if not emergency: Machine.unmount_raid_first() ... Machine.halt() if Machine is instanceof(Router): if not emergency: cls.shutdown(Machine.attachedmachines) ... ... finally: if emergency and Machine has powerswitch: Machine.powerswitch.Off() @classmethod def emergency(cls): for machine in cls.instances: cls.shutdown(machine, 1) Other design patterns might me good too, but I like the idea of having emergency protocols in *one* place here. But without method overloading, there are many many nested 'if's. One could say that the machines have to know how to shut down itself, but there might be dependencies they do not know about, and as said, it clutters the emergency protocol all over the modules. One could define normal_shutdown() and emergency_shutdown(), but I do not like this eighter, and there are still many 'if's to seperate the types. There are cases where *no* solution is perfect, and those are the cases where "2 methods of a class were to have the same name for doing completely different things" or other messy things like this are IMO *NOT* a design flaw. Regards, Michael From stefan_ml at behnel.de Thu Feb 25 08:46:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 14:46:56 +0100 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: fat bold cyclop, 25.02.2010 14:00: > I tired to google for comparison of tuple to list but i failed. > > Could anyone explain it to me? Both are not equal, so the comparison returns an arbitrary result in Py2. Note that this was fixed in Py3: 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. >>> (1,2,3) > [1,2,3] Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: tuple() > list() Stefan From __peter__ at web.de Thu Feb 25 08:46:56 2010 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Feb 2010 14:46:56 +0100 Subject: The best way to check if two lists have identical values References: Message-ID: mk wrote: > I have stumbled upon this seemingly trivial problem: the answer is not > there in http://www.python.org/doc/faq/programming/, and googling does > not return many references really (at least for me). > > I have come up with this: > > def qips_identical(q, oldq): > qips = map(operator.itemgetter(1), q) > oldqips = map(operator.itemgetter(1), oldq) I don't think the above is a relevant part of the problem. > if len(qips) != len(oldqips): > return False > dif = set(qips) ^ set(oldqips) > if len(dif): > return False > return True > > There's a number of complications here, depending on definition of > 'lists with identical values', like whether the same value can be > repeated different number of times in two lists, or whether the order of > values matters. > > In above example I assumed that the same values have to be repeated the > same numbers of times in both lists and that order doesn't matter so > long as the values are the same. No you haven't. [1, 1, 0] and [1, 0, 0] are considered equal by your algorithm. > I was wondering if there's a better / shorter / faster way to do this -- > not necessarily in the same variant, e.g. variant where order of two > lists matters would be interesting as well. sorted(left_list) == sorted(right_list) should be good enough in most cases where you do care for repetitions but not order. Peter From arnodel at googlemail.com Thu Feb 25 08:55:26 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Thu, 25 Feb 2010 05:55:26 -0800 (PST) Subject: The best way to check if two lists have identical values References: Message-ID: <045a9d2d-3fd7-4aed-9fb3-83e7e70cc881@v20g2000yqv.googlegroups.com> mk wrote: > Hello everyone, > > I have stumbled upon this seemingly trivial problem: the answer is not > there in http://www.python.org/doc/faq/programming/, and googling does > not return many references really (at least for me). > > I have come up with this: > > def qips_identical(q, oldq): > qips = map(operator.itemgetter(1), q) > oldqips = map(operator.itemgetter(1), oldq) > if len(qips) != len(oldqips): > return False > dif = set(qips) ^ set(oldqips) > if len(dif): > return False > return True > > There's a number of complications here, depending on definition of > 'lists with identical values', like whether the same value can be > repeated different number of times in two lists, or whether the order of > values matters. > > In above example I assumed that the same values have to be repeated the > same numbers of times in both lists and that order doesn't matter so > long as the values are the same. Your code checks if the two lists have the same length and the same elements, but not necessarily the same number of each elements. E.g. qips = [1, 1, 2] oldqips = [1, 2, 2] will return True If you want to check if each value has the same number of occurences, you can do return sorted(qips) == sorted(oldqips) assuming that all elements in the lists are comparable. -- Arnaud From darcy at druid.net Thu Feb 25 08:58:16 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 25 Feb 2010 08:58:16 -0500 Subject: taking python enterprise level?... In-Reply-To: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <20100225085816.fc9d4013.darcy@druid.net> On Thu, 25 Feb 2010 02:26:18 -0800 (PST) simn_stv wrote: > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day That's nothing. I ran a financial type app on Python that sometimes hit 100,000 transactions an hour. We kept looking for bottlenecks that we could convert to C but never found any. Our biggest problem was in a network heavy element of the app and that was low level TCP/IP stuff that rather than being Python's problem was something we used Python to fix. As others have pointed out, you will want some kind of enterprise database that will do a lot of the heavy lifting. I suggest PostgreSQL. It is the best open source database engine around. That will take the biggest load off your app. There's lots of decisions to make in the days ahead but I think that choosing Python as your base language is a good first one. > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. Scaleability and efficiency won't be your issues. Speed of development and clarity of code will be. Python wins. -- 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 fat.bold.cyclop at gmail.com Thu Feb 25 09:03:03 2010 From: fat.bold.cyclop at gmail.com (fat bold cyclop) Date: Thu, 25 Feb 2010 06:03:03 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> > Both are not equal, so the comparison returns an arbitrary result in Py2. Thanks, Stefan. If I understand you correctly the comparison is not valid. But I wonder if there is any logic behind this (in 2.x). Is it possible to predict result of this comparison? Thanks again, fbc From mrkafk at gmail.com Thu Feb 25 09:05:56 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 15:05:56 +0100 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-25 02:07, Steven D'Aprano wrote: > On Wed, 24 Feb 2010 18:23:17 +0100, mk wrote: > >> Anyway, the passwords for authorized users will be copied and pasted >> from email into in the application GUI which will remember it for them, >> so they will not have to remember and type them in. > > So to break your application's security model, all somebody has to do is > use their PC and they have full access to their account? > > Or get hold of the copy and paste buffer? > > Or the application's config files? Yes. There's no way around this, short of forcing them to use hardware key, which is an overkill for this application. >> So I have little in >> the way of limitations of password length - even though in *some* cases >> somebody might have to (or be ignorant enough) to retype the password >> instead of pasting it in. > Or your users might be sensible enough to not trust a role-your-own > security model, and prefer to memorize the password than to trust that > nobody will get access to their PC. The app is not that critical, it's about quarterly subscription to the service, and the users will be able to reset the password anyway. If it were that critical, I'd use the hardware keys; if hardware keys are not used, once somebody gains an (unconstrained) access to the user's PC, there's not much that app developer can do. I've read somewhere a warning from PuTTY developer that even though the key is (normally) protected by the passphrase, losing even an encrypted key is quite likely to lead to its compromise. There's even some software for that on the net: http://www.neophob.com/serendipity/index.php?/archives/127-PuTTY-Private-Key-cracker.html >> The main application will access the data using HTTP (probably), so the >> main point is that an attacker is not able to guess passwords using >> brute force. > And why would they bother doing that when they can sniff the wire and get > the passwords in plain text? You should assume your attackers are > *smarter* than you, not trust them to be foolish. I should have written HTTPS. Regards, mk From jeanmichel at sequans.com Thu Feb 25 09:18:38 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 15:18:38 +0100 Subject: Pure virtual functions in Python? In-Reply-To: References: <4b810953$1@dnews.tpgi.com.au> Message-ID: <4B8686BE.5020907@sequans.com> lallous wrote: > I still prefer not to call at all, even if it was an empty function. > > Regards, > Elias > Is there any way we could convince you that there is no point caring about this ? Even if you were trying to optimize speed, it would still require proof that an empty function is part of the problem. It sounds like someone stating "I prefer to write difficult-to-read code, because in 1978, code size used to matter". JM From chardster at gmail.com Thu Feb 25 09:21:56 2010 From: chardster at gmail.com (Richard Thomas) Date: Thu, 25 Feb 2010 06:21:56 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: On Feb 25, 2:03?pm, fat bold cyclop wrote: > > Both are not equal, so the comparison returns an arbitrary result in Py2. > > Thanks, Stefan. If I understand you correctly the comparison is not > valid. > But I wonder if there is any logic behind this (in 2.x). > Is it possible to predict result of this comparison? > > Thanks again, > fbc I believe in 2.x they are ordered by the names of their types but I could be wrong. 1 < [] < '' < () < u'' From iainking at gmail.com Thu Feb 25 09:22:53 2010 From: iainking at gmail.com (Iain King) Date: Thu, 25 Feb 2010 06:22:53 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: <0f015e4c-bc37-4322-aa5c-e071e860efd3@33g2000yqj.googlegroups.com> On Feb 25, 2:03?pm, fat bold cyclop wrote: > > Both are not equal, so the comparison returns an arbitrary result in Py2. > > Thanks, Stefan. If I understand you correctly the comparison is not > valid. > But I wonder if there is any logic behind this (in 2.x). > Is it possible to predict result of this comparison? > > Thanks again, > fbc I haven't looked in the source to check (and I'm almost 100% certain that tuple > list is an implementation detail), but I have not found any pair of tuple and list in which the list is treated as the greater. Possibly related: type(tuple()) is > type(list()). Or, to let the interpreter tell you why (1,2,3) > [1,2,3]: >>> tuple > list True Iain From daniel at stutzbachenterprises.com Thu Feb 25 09:25:22 2010 From: daniel at stutzbachenterprises.com (Daniel Stutzbach) Date: Thu, 25 Feb 2010 08:25:22 -0600 Subject: The best way to check if two lists have identical values In-Reply-To: References: Message-ID: On Thu, Feb 25, 2010 at 7:30 AM, mk wrote: > There's a number of complications here, depending on definition of 'lists > with identical values', like whether the same value can be repeated > different number of times in two lists, or whether the order of values > matters. > Order and repetitions matter: list1 == list2 Repetition matters, order does not: sorted(list1) == sorted(list2) # items must be comparable Neither matters: set(list1) == set(list2) # items must be hashable -- Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises, LLC -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Thu Feb 25 09:27:47 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 25 Feb 2010 15:27:47 +0100 Subject: Walking lists In-Reply-To: References: Message-ID: <4B8688E3.9000909@sequans.com> lallous wrote: > Thank you all for the replies. > > The solution using Python 3's syntax look very intuitive. > > Thanks Tim, Arnaud for the idea (I am using 2.x) > > -- > Elias > On Feb 25, 1:28 pm, lallous wrote: > >> Hello >> >> I am still learning Python, and have a question, perhaps I can shorten >> the code: >> >> L = ( >> (1, 2, 3), >> (4,), >> (5,), >> (6, 7) >> ) >> >> for x in L: >> print x >> >> What I want, is to write the for loop, something like this: >> >> for (first_element, the_rest) in L: >> print first_element >> for x in the_rest: >> # now access the rest of the elements >> >> I know I can : >> for x in L: >> first = x[0] >> rest = x[1:] >> .... >> Probably that is not possible, but just asking. >> >> Thanks, >> Elias >> Using slicing + list comprehension with python 2.x for first, rest in [(e[0],e[1:]) for e in L]: print first print rest 1 (2, 3) 4 () 5 () 6 (7,) But honestly, the code you provided is just fine. JM From mrkafk at gmail.com Thu Feb 25 09:43:53 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 15:43:53 +0100 Subject: The best way to check if two lists have identical values In-Reply-To: <045a9d2d-3fd7-4aed-9fb3-83e7e70cc881@v20g2000yqv.googlegroups.com> References: <045a9d2d-3fd7-4aed-9fb3-83e7e70cc881@v20g2000yqv.googlegroups.com> Message-ID: On 2010-02-25 14:55, Arnaud Delobelle wrote: > Your code checks if the two lists have the same length and the same > elements, but not necessarily the same number of each elements. E.g. > > qips = [1, 1, 2] > oldqips = [1, 2, 2] > > will return True > > If you want to check if each value has the same number of occurences, > you can do > > return sorted(qips) == sorted(oldqips) > > assuming that all elements in the lists are comparable. Thanks! Regards, mk From stefan_ml at behnel.de Thu Feb 25 09:54:58 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 15:54:58 +0100 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: fat bold cyclop, 25.02.2010 15:03: >> Both are not equal, so the comparison returns an arbitrary result in Py2. > Thanks, Stefan. If I understand you correctly the comparison is not > valid. > But I wonder if there is any logic behind this (in 2.x). > Is it possible to predict result of this comparison? The result is predictable, it's just arbitrary in that it does not depend on the values that you are comparing but only on their type. Stefan From mrkafk at gmail.com Thu Feb 25 10:03:47 2010 From: mrkafk at gmail.com (mk) Date: Thu, 25 Feb 2010 16:03:47 +0100 Subject: Is this secure? In-Reply-To: <7xk4u26qz0.fsf@ruckus.brouhaha.com> References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-25 02:31, Paul Rubin wrote: > It might be helpful if you could say what your application does, or > anyway give an idea of what its actual security requirements are. > Generating and emailing someone a random password is a fairly standard > method for (e.g.) web forums to verify that the person has supplied a > working email address, basically as a first level spam filter. Your > scheme is probably ok for that. If you're doing something with more > demanding security requirements, then as mentioned before, there is a > whole lot of stuff you have to pay attention to, and focusing narrowly > on password generation isn't that useful. OK some data: 1. I'm going to probably use HTTPS (I meant HTTP over SSL, but wrote HTTP instead of being precise) 2. The app will have GUI and it will be locally installed; it's not going to be web app, it will just be online in the sense of downloading data frequently from the net. 3. I can't disclose the details on what the app will be doing, but it's not going to be terribly security-critical, medium-level at most - what happens in the app itself is not _directly_ related to money. 4. The app will be based on subscription model, costing $10-$20 per month. It's not really doing online banking or smth like that. 5. The worst thing that can happen when security of some account is compromised is that the user will have to reset the password, resending it to predefined email (I don't really see the way of organizing it in a different manner). I'm thinking about optionally passphrase-securing the password saved in GUI. In that case 'diceware' approach would be helpful. I certainly do not want to focus narrowly on password generation: the entire security model will have to be worked out, but the project didn't get to that stage yet, it's all still in planning stages. I just wanted to have this one part (password generation) researched before I get to other stages so I don't have to implement this later in haste and do smth wrong. Regards, mk From invalid at invalid.invalid Thu Feb 25 10:07:12 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 25 Feb 2010 15:07:12 +0000 (UTC) Subject: What's the word on using """ to comment-out? References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: On 2010-02-25, Paul Rudin wrote: > kj writes: > >> I think I remember, early in my learning of Python, coming across >> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT >> LINES OF CODE", or something to that effect. But now I can't find >> it! > > No idea, but it would be nice to have some multiline comment syntax > (other than # at the beginning of each line). Particularly one that can > be nested. if 0: Seriously, that's what I generally do: mark the block of code, indent it 1 level, add an if 0: at the top. -- Grant Edwards grante Yow! What a COINCIDENCE! at I'm an authorized "SNOOTS visi.com OF THE STARS" dealer!! From lucat at despammed.com Thu Feb 25 10:26:32 2010 From: lucat at despammed.com (Luca) Date: Thu, 25 Feb 2010 16:26:32 +0100 Subject: Renaming identifiers & debugging Message-ID: <7unj59FuorU1@mid.individual.net> Hello, i am trying to develop an application to teach programming to young kids in a similar way as Logo did in the past. I would like to use an embedded Python as underlying language but this raises a problem. The target of my app are very young kids that might be unfamiliar with english, so i am wondering if there is a way to rename/redefine identifiers and messages in the language of the kid. In UCB-Logo this is very easy with the command COPYDEF "newidentifier "oldidentifier so all you have to do is setup a startup script to redefine all the identifiers to the language of the user. Is there anything similar for python? Since python would be embedded it would not be a problem for me to do it through some API. Also, i would need a way to debug the program, so set up breakpoints, execute line by line, inspect variables, is there any API for this in embedded python? Thank you, Luca From martin.hellwig at dcuktec.org Thu Feb 25 10:29:34 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Feb 2010 15:29:34 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > Our biggest problem was in > a network heavy element of the app and that was low level TCP/IP stuff > that rather than being Python's problem was something we used Python to > fix. Out off interest, could you elaborate on that? Thanks -- mph From spamfresser at ch3ka.de Thu Feb 25 10:39:27 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 16:39:27 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: Am 25.02.2010 16:07, schrieb Grant Edwards: > On 2010-02-25, Paul Rudin wrote: >> No idea, but it would be nice to have some multiline comment syntax >> (other than # at the beginning of each line). Particularly one that can >> be nested. > > if 0: > > Seriously, that's what I generally do: mark the block of code, > indent it 1 level, add an if 0: at the top. > I really hate it when I see something like this in other's code. The fact that my IDE (vim) still displays this like valid code ready to be executed can cause extreme frustration while trying to spot a bug. This is almost as bad as "commenting out" (parts of) a for loop by adding a continue. I once saw this in production code and wanted to kill the original developer, as commenting out the parts of the code with the continue (it was a *biiiig* for-loop) for debugging purposes actually would have *enabled* the code below, thus rendering the whole database useless. Lucky me that I a) had backups b) set up a sandbox and c) actually saw this before it was too late. Regards, Michael From affdfsdfdsfsd at b.com Thu Feb 25 10:39:34 2010 From: affdfsdfdsfsd at b.com (Tracubik) Date: 25 Feb 2010 15:39:34 GMT Subject: round() function Message-ID: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> hi all, i've this sample code: >>> n = 4.499 >>> str(round(n,2)) '4.5' that's right, but what i want is '4.50' to be displayed instead of '4.5'. Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. How can I solve this? Thanks in advance Nico From python.list at tim.thechases.com Thu Feb 25 10:45:16 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 25 Feb 2010 09:45:16 -0600 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <4B869B0C.5060601@tim.thechases.com> Tracubik wrote: >>>> n = 4.499 >>>> str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. Use string formatting: >>> "%0.2f" % round(4.499, 2) '4.50' -tkc From ivan.python1 at gmail.com Thu Feb 25 10:45:37 2010 From: ivan.python1 at gmail.com (mailing list) Date: Thu, 25 Feb 2010 16:45:37 +0100 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <4B869B21.4010808@gmail.com> On 25.2.2010. 16:39, Tracubik wrote: > hi all, i've this sample code: > > >>>> n = 4.499 >>>> str(round(n,2)) >>>> > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? > > Thanks in advance > Nico > You may wanna use string formating, e.g.: print "%.2f" % 4.5 From stefan_ml at behnel.de Thu Feb 25 10:46:18 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 25 Feb 2010 16:46:18 +0100 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: Tracubik, 25.02.2010 16:39: > hi all, i've this sample code: > >>>> n = 4.499 >>>> str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? Format the number as a string: print("%.2f" % round(n,2)) Stefan From jlconlin at gmail.com Thu Feb 25 10:48:44 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 25 Feb 2010 07:48:44 -0800 (PST) Subject: Can I specify regex group to return float or int instead of string? Message-ID: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> I have a regular expression that searches for some numbers and puts them into a dictionary, i.e. '(?P\d+)\s+(?P\d+\.\d+)' Is it possible to have the results of the matches returned as int or float objects instead of strings? Thanks, Jeremy From spamfresser at ch3ka.de Thu Feb 25 10:51:40 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Thu, 25 Feb 2010 16:51:40 +0100 Subject: round() function In-Reply-To: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> References: <4b8699b5$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: Am 25.02.2010 16:39, schrieb Tracubik: > hi all, i've this sample code: > >>>> n = 4.499 >>>> str(round(n,2)) > '4.5' > > that's right, but what i want is '4.50' to be displayed instead of '4.5'. > Off course i know that 4.5 = 4.50, still i'ld like to have 4.50. > > How can I solve this? > > Thanks in advance > Nico This has nothing to do with round(). round() returns a float, and float(4.50) is 4.5. You can *print* it as 4.50 using format strings, but the float will always be 4.5 >>> n = 4.499 >>> x=round(n,2) >>> x 4.5 >>> print "%.2f" % x 4.50 >>> s="%.2f" % round(n,2) >>> s '4.50' >>> From nicola.larosa at gmail.com Thu Feb 25 10:51:51 2010 From: nicola.larosa at gmail.com (Nicola Larosa (tekNico)) Date: Thu, 25 Feb 2010 07:51:51 -0800 (PST) Subject: Recommended "new" way for config files References: Message-ID: <28c20bf9-2522-442d-a6b9-82a68f267dd5@z35g2000yqd.googlegroups.com> Peter wrote: > There seems to be several strategies to enhance the old ini-style config > files with real python code > [...] > Is there a strategy that should be prefered for new projects ? 5) Use ConfigObj , by Michael Foord and yours truly. It uses an extension of the ini- style config format. Sorry for the multiple brackets, my fault. :-) -- Nicola Larosa - http://www.tekNico.net/ Ci sono paesi in cui un gesto violento se compiuto da un uomo su una don- na ? punito pi? severamente: si chiama uguaglianza sostanziale, compensa la disuguaglianza di partenza. [...] Se vince la cultura dei "vincenti" le donne perderanno. Non fanno la guerra, in genere. ? una perdita di tempo: hanno altro da fare. - Concita De Gregorio, Novembre 2009 From mwilson at the-wire.com Thu Feb 25 10:58:14 2010 From: mwilson at the-wire.com (Mel) Date: Thu, 25 Feb 2010 10:58:14 -0500 Subject: When will Java go mainstream like Python? References: Message-ID: sjdevnull at yahoo.com wrote: > You're right that ref counting in many implementations is more > deterministic than other common forms of garbage collection; IMO, > Python would be well-served by making the ref-counting semantics it > currently has a guaranteed part of the language spec--or at least > guaranteeing that when a function returns, any otherwise unreferenced > locals are immediately collected. That would be nice. The argument against it is that it would make implementations like Jython very difficult to make, if it didn't rule them out altogether. Mel. From pruebauno at latinmail.com Thu Feb 25 11:11:09 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 25 Feb 2010 08:11:09 -0800 (PST) Subject: A more pythonish code References: Message-ID: <9a564658-8b6b-4510-ba1f-ac259c7d8700@o30g2000yqb.googlegroups.com> prasad_chand wrote: > Hi, > > I use python to do simple math problems as a hobby. > > I have made a program that finds the number of divisors(factors) of a > given number. I am hoping to improve my language skills, specifically > I would like to re-write the function "prime_factors" more gracefully. > While the program works right, I am hoping that I could get some input > on how to write better python code. I have attached the code below. > > > def prime_factors(n): > """ > Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) > (1+1) = 10) > > Updates a global dictionary(my_dict) with prime numbers and number > of occurances. In the case of 48 {2:4,3:1} > > """ > tmp_n = n > > while True: > > if tmp_n == 1: > break > > tmp_check = tmp_n > > for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > if tmp_n % x == 0: > add_to_dict(x) > tmp_n /= x > break > > if tmp_check == tmp_n: #number is prime...so just to add to > dict > add_to_dict(tmp_n) > break > > > def add_one(x): > return x+1 > > > def mul(x,y): > return x * y > > def add_to_dict(p_num): > if my_dict.has_key(p_num): > my_dict[p_num] += 1 > else: > my_dict[p_num] = 1 > > > my_dict = {} > > > prime_factors(135) > l = map(add_one,my_dict.values()) > print reduce(mul, l, 1) > > > Thanks for your time. I did a quick refactoring for Python 3.1 (should mostly work in older versions too): from math import ceil, sqrt from functools import reduce from collections import defaultdict from operator import mul def prime_factors(n): """ Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) (1+1) = 10) """ factors = defaultdict(int) while n != 1: for x in range(2,int(ceil(sqrt(n)) + 1)): if n % x == 0: factors[x] += 1 n /= x break else: #number is prime...so just to add to dict factors[int(n)] += 1 break return factors factors = prime_factors(135) exponents = [x+1 for x in factors.values()] print(reduce(mul, exponents, 1)) From bruno.42.desthuilliers at websiteburo.invalid Thu Feb 25 11:16:58 2010 From: bruno.42.desthuilliers at websiteburo.invalid (Bruno Desthuilliers) Date: Thu, 25 Feb 2010 17:16:58 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: <4B8651BE.7080500@sequans.com> Message-ID: <4b86a265$0$695$426a34cc@news.free.fr> Michael Rudolf a ?crit : (snip) > (pseudocode - this is *not* python ;) > > class Machines (Object): > @classmethod > def shutdown(cls, Machine, emergency=False): > try: > if Machine is instanceof(Fileservers): > if not emergency: > Machine.unmount_raid_first() > ... > Machine.halt() > if Machine is instanceof(Router): > if not emergency: > cls.shutdown(Machine.attachedmachines) > ... > ... > finally: > if emergency and Machine has powerswitch: > Machine.powerswitch.Off() > @classmethod > def emergency(cls): > for machine in cls.instances: > cls.shutdown(machine, 1) > > One could say that the machines have to know how to shut down itself, Indeed !-) > but there might be dependencies they do not know about, Then it's the "Machines" (or a "MachineShutdownProtocol" or whatever) responsability to manage correct operation order, and you need an API to allow communication between the Machine objects and the WhateverItsName object in charge of monitoring the process. All this if you do care about correct OO design, of course - as far as I'm concerned, practicallity beats purity !-) > and as said, it > clutters the emergency protocol all over the modules. Tradeoff, tradeoff. The above won't work for a "plug&play" system. > There are cases where *no* solution is perfect, There is always at least one "less worse" solution, depending on the concrete use case. From darcy at druid.net Thu Feb 25 11:18:14 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 25 Feb 2010 11:18:14 -0500 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <20100225111814.c32887b9.darcy@druid.net> On Thu, 25 Feb 2010 15:29:34 +0000 "Martin P. Hellwig" wrote: > On 02/25/10 13:58, D'Arcy J.M. Cain wrote: > > On Thu, 25 Feb 2010 02:26:18 -0800 (PST) > > > Our biggest problem was in > > a network heavy element of the app and that was low level TCP/IP stuff > > that rather than being Python's problem was something we used Python to > > fix. > > Out off interest, could you elaborate on that? Somewhat - there is an NDA so I can't give exact details. It was crucial to our app that we sync up databases in Canada and the US (later Britain, Europe and Japan) in real time with those transactions. Our problem was that even though our two server systems were on the backbone, indeed with the same major carrier, we could not keep them in sync. We were taking way to long to transact an update across the network. The problem had to do with the way TCP/IP works, especially closer to the core. Our provider was collecting data and sending it only after filling a buffer or after a timeout. The timeout was short so it wouldn't normally be noticed and in most cases (web pages e.g.) the connection is opened, data is pushed and the connection is closed so the buffer is flushed immediately. Our patterns were different so we were hitting the timeout on every single transaction and there was no way we would have been able to keep up. Our first crack at fixing this was to simply add garbage to the packet we were sending. Making the packets an order of magnitude bigger sped up the proccessing dramatically. That wasn't a very clean solution though so we looked for a better way. That better way turned out to asynchronous update transactions. All we did was keep feeding updates to the remote site and forget about ACKS. We then had a second process which handled ACKS and tracked which packets had been properly transferred. The system had IDs on each update and retries happened if ACKS didn't happen soon enough. Naturally we ignored ACKS that we had already processed. All of the above (and much more complexity not even discussed here) was handled by Python code and database manipulation. There were a few bumps along the way but overall it worked fine. If we were using C or even assembler we would not have sped up anything and the solution we came up with would have been horrendous to code. As it was I and my chief programmer locked ourselves in the boardroom and had a working solution before the day was out. Python wins again. -- 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 electriclightheads at gmail.com Thu Feb 25 11:22:22 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 26 Feb 2010 01:22:22 +0900 Subject: hs.py = run an exec and pipe back the result as a member of a list Message-ID: <1078018b1002250822y2998e500r85f52646fa1fd190@mail.gmail.com> did this for hascillator01 that i ghc-ed from hascillator01.hs into ./ import popen2 wave = [] for frame in range(890, 1010): wave.append(int(popen2.Popen3('./hascillator01 ' + str(frame)).fromchild.readline())) print wave hascillator01 takes int and returns another int so yes this became a [ints] and that is what i expected but also yes it is so slow any cooler way to do it? now am reading the suprocess's doc .. but a bit hard to get it -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From electriclightheads at gmail.com Thu Feb 25 11:24:33 2010 From: electriclightheads at gmail.com ('2+) Date: Fri, 26 Feb 2010 01:24:33 +0900 Subject: hs.py = run an exec and pipe back the result as a member of a list In-Reply-To: <1078018b1002250822y2998e500r85f52646fa1fd190@mail.gmail.com> References: <1078018b1002250822y2998e500r85f52646fa1fd190@mail.gmail.com> Message-ID: <1078018b1002250824x26fe456cg9588e1d7b64386e7@mail.gmail.com> oops the code was wrong .. sorry import popen2 wave = [] for frame in range(890, 1010): wave.append(int(popen2.Popen3('./hascillator01 ' + str(frame)).fromchild.readline())) print wave On Fri, Feb 26, 2010 at 1:22 AM, '2+ wrote: > did this for hascillator01 that i ghc-ed from hascillator01.hs into ./ > > import popen2 > > wave = [] > for frame in range(890, 1010): > wave.append(int(popen2.Popen3('./hascillator01 ' + > str(frame)).fromchild.readline())) > print wave > > hascillator01 takes int and returns another int > so yes this became a [ints] and that is what i expected > but also yes it is so slow > any cooler way to do it? > now am reading the suprocess's doc .. but a bit hard to get it > > -- > SaRiGaMa's Oil Vending Orchestra > is podcasting: > http://sarigama.namaste.jp/podcast/rss.xml > -- SaRiGaMa's Oil Vending Orchestra is podcasting: http://sarigama.namaste.jp/podcast/rss.xml From aahz at pythoncraft.com Thu Feb 25 11:31:32 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 08:31:32 -0800 Subject: Easter Eggs References: Message-ID: In article , mk wrote: >On 2010-02-25 03:04, Gabriel Genellina wrote: >> >> Also try: >> import antigravity > >Is this Py3 egg? My 2.6 doesn't seem to get it. Maybe 2.7 will have it; 3.0.1 does. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From robert.kern at gmail.com Thu Feb 25 11:32:20 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Feb 2010 10:32:20 -0600 Subject: Is this secure? In-Reply-To: References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: On 2010-02-25 09:03 AM, mk wrote: > 2. The app will have GUI and it will be locally installed; it's not > going to be web app, it will just be online in the sense of downloading > data frequently from the net. If you are storing the password instead of making your user remember it, most platforms have some kind of keychain secure password storage. I recommend reading up on the APIs available on your targeted platforms. -- 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 skylarking11 at gmail.com Thu Feb 25 11:33:31 2010 From: skylarking11 at gmail.com (Sky Larking) Date: Thu, 25 Feb 2010 08:33:31 -0800 (PST) Subject: Trouble with ftplib uploading to an FTP server References: <6c7a868d-cd0e-45e8-995f-89944ebb86ab@t34g2000prm.googlegroups.com> <79927f7d-d186-46f1-ab58-94a8d5f973fc@g10g2000yqh.googlegroups.com> Message-ID: <7b518e48-655e-43a6-ac8c-dd473cdcba22@33g2000yqj.googlegroups.com> On Feb 25, 1:10?am, Dennis Lee Bieber wrote: > On Wed, 24 Feb 2010 17:21:58 -0800 (PST), Sky Larking > declaimed the following in > gmane.comp.python.general: > > > For instance I just ran the script and os.rename() renamed it to: > > > TestMachine.local @ 02-24-2010 2020.txt > > > in that .txt file it reads: > > > Asset: TestMachine.local Checking in from IP#: xx.xxx.xx.xxx > > > This is what I want, but the FTP piece doesn't seem to work... > > ? ? ? ? But since you haven't CLOSED the file before invoking the FTP > operation, the contents are probably in a write buffer that hasn't been > flushed. Renaming a file only changes the directory entry -- doesn't do > anything for what may or may not be in the file. > > ? ? ? ? After the program exits, the file get closed, which means the > buffers are flushed. > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ?HTTP://wlfraed.home.netcom.com/ I see my mistake now, I closed the file ...then did the upload ... and the data was there -- thanks for the help From aahz at pythoncraft.com Thu Feb 25 11:33:59 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 08:33:59 -0800 Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: In article <5cd38064-34d6-40d3-b3dc-2c853fc86728 at i39g2000yqm.googlegroups.com>, simn_stv wrote: > >i plan to build an application, a network based application that i >estimate (and seriously hope) would get as many as 100, 000 hits a day >(hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' >or anything like it, its mainly for a financial transactions which >gets pretty busy... Remember that YouTube runs on Python. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From hseylan at dr.com Thu Feb 25 11:35:40 2010 From: hseylan at dr.com (huseyin) Date: Thu, 25 Feb 2010 08:35:40 -0800 (PST) Subject: CGI File Upload Problem with Python 3.1 on IIS 7 Message-ID: <05322717-d98b-4da4-8b3a-333b42f19f89@z11g2000yqz.googlegroups.com> I am trying to upload files through cgi script written in python 3.1 on a Windows IIS 7 server. The server time out when I write in usual way that is form=cgi.cgi.FieldStorage() fileitem = form['filename'] fn = os.path.basename(fileitem.filename) open('/tmp/' + fn, 'wb').write(fileitem.file.read()) I think there is a problem with stdin, I checked it with: s=sys.stdin.buffer.read(1024) print (s) I prints the first 1024 bytes of the input stream. But when I write s=1 while s: s=sys.stdin.buffer.read(1024) print (s) the server stops responding. I think there is a problem that Python cannot understand end of input stream. I searched this on the net but could not find a solution. Thanks From invalid at invalid.invalid Thu Feb 25 11:39:11 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 25 Feb 2010 16:39:11 +0000 (UTC) Subject: What's the word on using """ to comment-out? References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: On 2010-02-25, Michael Rudolf wrote: > Am 25.02.2010 16:07, schrieb Grant Edwards: >> On 2010-02-25, Paul Rudin wrote: >>> No idea, but it would be nice to have some multiline comment syntax >>> (other than # at the beginning of each line). Particularly one that can >>> be nested. >> >> if 0: >> >> Seriously, that's what I generally do: mark the block of code, >> indent it 1 level, add an if 0: at the top. > > I really hate it when I see something like this in other's > code. The only time you'll see that in my code is if you're watching over my shoulder as I troublshoot something. > The fact that my IDE (vim) still displays this like valid code > ready to be executed can cause extreme frustration while > trying to spot a bug. Nobody in their right mind _leaves_ "commented out" code like that (or other commenting mechanisms) in a program after they're done with whatever little experiment they were performing. I know people who will re-write a block of code and leave the old code there, but comment it out, along with the date and their name, and other such nonsense. I hate that. Keeping track of what _used_ to be there and who changed what when is the job of the version control system. Trying to keep the edit-history of a file in-line as comments just makes the code hard to read and maintain. > This is almost as bad as "commenting out" (parts of) a for > loop by adding a continue. IMO, any sort of "commented out" code left in a program is a big mistake. If the code is soething that does need to stay for optional use, then it needs to be properly integrated along with logic to control when it's used. -- Grant Edwards grante Yow! Four thousand at different MAGNATES, MOGULS visi.com & NABOBS are romping in my gothic solarium!! From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 11:41:01 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 16:41:01 GMT Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> Message-ID: <4b86a81d$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: > I have a regular expression that searches for some numbers and puts them > into a dictionary, i.e. > > '(?P\d+)\s+(?P\d+\.\d+)' > > Is it possible to have the results of the matches returned as int or > float objects instead of strings? No. Just convert the match with int() or float() before storing it in the dictionary. That is, instead of: d[key] = match use d[key] = float(match) or similar. -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 11:45:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 16:45:58 GMT Subject: Renaming identifiers & debugging References: <7unj59FuorU1@mid.individual.net> Message-ID: <4b86a946$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 16:26:32 +0100, Luca wrote: > Hello, i am trying to develop an application to teach programming to > young kids in a similar way as Logo did in the past. I would like to use > an embedded Python as underlying language but this raises a problem. > > The target of my app are very young kids that might be unfamiliar with > english, so i am wondering if there is a way to rename/redefine > identifiers and messages in the language of the kid. >>> len("hello") 5 >>> length = len >>> length("hello") 5 However, you can't rename statements such as for, while, if and similar, nor can you rename error messages. There might be an internationalised version of Python in the language the children speak. Have you tried googling? > Also, i would need a way to debug the program, so set up breakpoints, > execute line by line, inspect variables, is there any API for this in > embedded python? Have you tried the Python debugger? import pdb -- Steven From lars at gustaebel.de Thu Feb 25 11:51:17 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Thu, 25 Feb 2010 17:51:17 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: References: <20100224101423.GA27668@axis.g33x.de> Message-ID: <20100225165117.GA30865@axis.g33x.de> On Wed, Feb 24, 2010 at 04:29:18PM -0500, Terry Reedy wrote: > On 2/24/2010 5:14 AM, Lars Gust?bel wrote: >> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: >>> I stumbled uppon this and find it somewhat odd: some class methods of >>> TarFile and TarInfo do not appears in either the online documentation or >>> search while they have a doc string: >> >> But to answer your question: Yes, this is intentional. The TarFile class has >> three classmethods taropen(), gzopen(), and bz2open() each for a specific >> compression method. These three are used internally by the TarFile.open() >> classmethod and are not intended to be called directly. The TarFile.open() >> method is the one that is publicly documented and supposed to be used. It >> decides which of the three methods to use based on the mode argument and >> does many more other high-level things as well. > > By current standards, the three private methods should be prefixed with > '_' to indicate their private status. Could they be changed to head off > such questions? I hope that this is not necessary. There are quite a few TarFile methods more that are not documented and don't start with an underscore. I don't think renaming all these is a good idea. The original intention behind these methods was that I wanted a lower level API for TarFile that can be used for subclassing but stays as stable as possible at the same time. Methods starting with underscores look very much like you can't make use of them. I don't know if this was a particularly good idea back then and I don't know how popular it is to subclass the TarFile class to customize it, but we cannot simply change the methods' names at this point if we don't want to break other people's code. In other words, the cure sounds worse than the disease in my opinion. -- Lars Gust?bel lars at gustaebel.de 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 jlconlin at gmail.com Thu Feb 25 12:00:07 2010 From: jlconlin at gmail.com (Jeremy) Date: Thu, 25 Feb 2010 09:00:07 -0800 (PST) Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> <4b86a81d$0$27844$c3e8da3@news.astraweb.com> Message-ID: On Feb 25, 9:41?am, Steven D'Aprano wrote: > On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: > > I have a regular expression that searches for some numbers and puts them > > into a dictionary, i.e. > > > '(?P\d+)\s+(?P\d+\.\d+)' > > > Is it possible to have the results of the matches returned as int or > > float objects instead of strings? > > No. Just convert the match with int() or float() before storing it in the > dictionary. That is, instead of: > > d[key] = match > > use > > d[key] = float(match) > > or similar. I was afraid that was the only option. Oh well, thought I'd ask anyway. Thanks for your help. Jeremy From no-spam at non-existing.invalid Thu Feb 25 12:08:28 2010 From: no-spam at non-existing.invalid (Robert) Date: Thu, 25 Feb 2010 18:08:28 +0100 Subject: Pedantic pickling error after reload? Message-ID: After (intended/controlled) reload or similar action on a module/class the pickle/cPickle.dump raises errors like pickle.PicklingError: Can't pickle : it's not the same object as somemodule.SomeClass Cause in pickle.py (and cPickle) is a line "if klass is not obj:" Shouldn't it be enough to have "if klass.__name__ != obj.__name__:" there? => a bug report/feature request? Classes can change face anyway during pickled state, why should a over-pedantic reaction break things here during runtime? (So far I'd need to walk the object tree in all facets and save against inf loops like pickle himself and re-class things .. ) From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 12:15:50 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 17:15:50 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <4b86b045$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 15:05:56 +0100, mk wrote: > On 2010-02-25 02:07, Steven D'Aprano wrote: >> On Wed, 24 Feb 2010 18:23:17 +0100, mk wrote: >> >>> Anyway, the passwords for authorized users will be copied and pasted >>> from email into in the application GUI which will remember it for >>> them, so they will not have to remember and type them in. >> >> So to break your application's security model, all somebody has to do >> is use their PC and they have full access to their account? >> >> Or get hold of the copy and paste buffer? >> >> Or the application's config files? > > Yes. There's no way around this, short of forcing them to use hardware > key, which is an overkill for this application. Of course there is. Why don't you find out how applications with real security work, instead of making up amateur insecure schemes or worrying about insignificant deviations from uniformity in your password generator? You can't get hold of a user's login password in Linux or Windows by grabbing the copy-and-paste buffer, or by looking in the password file. No hardware key required. Today, you say that your application only needs weak security because the value of the accounts are low. (If they're that low, why do you need a password at all?) But tomorrow, your application will be bigger, better, new and improved, with remote logins over the Internet and much more value -- and it will still be using the same crappy weak security that it has now, I guarantee it. If you are storing the password, instead of a hash, you fail. If you are storing a hash without a salt, you fail. Yes, an awful lot of software do these things. They shouldn't, even for supposed "low value passwords". http://blog.moertel.com/articles/2006/12/15/never-store-passwords-in-a-database http://www.codinghorror.com/blog/2007/09/youre-probably-storing-passwords-incorrectly.html >> Or your users might be sensible enough to not trust a role-your-own >> security model, and prefer to memorize the password than to trust that >> nobody will get access to their PC. > > The app is not that critical, it's about quarterly subscription to the > service, and the users will be able to reset the password anyway. And when users realise that they don't need to buy a subscription, they just need to steal a password from somebody else, what does that do to your business model? -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 12:18:09 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 17:18:09 GMT Subject: The best way to check if two lists have identical values References: Message-ID: <4b86b0d1$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 14:30:12 +0100, mk wrote: > In above example I assumed that the same values have to be repeated the > same numbers of times in both lists and that order doesn't matter so > long as the values are the same. sorted(list1) == sorted(list2) > I was wondering if there's a better / shorter / faster way to do this -- > not necessarily in the same variant, e.g. variant where order of two > lists matters would be interesting as well. list1 == list2 -- Steven From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 12:20:44 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 25 Feb 2010 17:20:44 GMT Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> <4b86a81d$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b86b16b$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 09:00:07 -0800, Jeremy wrote: > On Feb 25, 9:41?am, Steven D'Aprano cybersource.com.au> wrote: >> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: >> > I have a regular expression that searches for some numbers and puts >> > them into a dictionary, i.e. >> >> > '(?P\d+)\s+(?P\d+\.\d+)' >> >> > Is it possible to have the results of the matches returned as int or >> > float objects instead of strings? >> >> No. Just convert the match with int() or float() before storing it in >> the dictionary. That is, instead of: >> >> d[key] = match >> >> use >> >> d[key] = float(match) >> >> or similar. > > I was afraid that was the only option. Oh well, thought I'd ask anyway. Why "afraid"? What's the problem with calling int or float on the match? -- Steven From lucat at despammed.com Thu Feb 25 12:42:43 2010 From: lucat at despammed.com (Luca) Date: Thu, 25 Feb 2010 18:42:43 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <4b86a946$0$27844$c3e8da3@news.astraweb.com> References: <7unj59FuorU1@mid.individual.net> <4b86a946$0$27844$c3e8da3@news.astraweb.com> Message-ID: <7unr4kFe8jU1@mid.individual.net> Steven D'Aprano wrote: > However, you can't rename statements such as for, while, if and similar, > nor can you rename error messages. There might be an internationalised > version of Python in the language the children speak. Have you tried > googling? Yeah, this is what i am talking about. It seems that keywords (if, while, for, etc) cannot be renamed at all. Not easily at least without recompiling Python from source. Same thing with error messages. What i need is not an internationalized version of python in a specific language... but a simple way to let the teacher do it by himself/herself. Since python will be embedded in my application i could also load this via a text-file or XML file... but it seems that no API has been made available to solve this problem. Logo is the only language i know that lets the user do this in a very simple way, that's why i brought it as example of what i need. In Logo every identifier can be changed with a simple startup file and every error message can be personalized by editing a text file. This allows any user/parent/teacher to personalize the language for their kids. What i need is an API that lets my application do something similar to the python library. Unfortunately it seems that there is no easy way to do it. > Have you tried the Python debugger? > > import pdb Didn't know it, thank you. Now i need to understand if this PDB module can be used from the application that is embedding pythong (so that i can build a simple IDE to set breakpoints, show the current execution-line, skip it, etc. Thanx, Luca From jjposner at optimum.net Thu Feb 25 12:57:14 2010 From: jjposner at optimum.net (John Posner) Date: Thu, 25 Feb 2010 12:57:14 -0500 Subject: A more pythonish code In-Reply-To: References: Message-ID: <4B86B9FA.7010609@optimum.net> On 2/25/2010 7:23 AM, prasad_chand wrote: > Hi, > > I use python to do simple math problems as a hobby. > > I have made a program that finds the number of divisors(factors) of a > given number. I am hoping to improve my language skills, specifically > I would like to re-write the function "prime_factors" more gracefully. > While the program works right, I am hoping that I could get some input > on how to write better python code. I have attached the code below. > > > def prime_factors(n): > """ > Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) > (1+1) = 10) > > Updates a global dictionary(my_dict) with prime numbers and number > of occurances. In the case of 48 {2:4,3:1} > > """ > tmp_n = n A name meaning "temporary value of n" doesn't suggest how it's being used in the algorithm. In my implementation (see below), I used the name "last_result", which is (a little bit) better. > > while True: > > if tmp_n == 1: > break > > tmp_check = tmp_n > > for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > if tmp_n % x == 0: > add_to_dict(x) This function changes the value of a global variable, *my_dict*. Using global variables is frowned upon. In this case, it would be much better to have the dictionary be local to the *prime_factor* function. After you've broken out of the *while* loop, just execute "return my_dict". > tmp_n /= x > break > > if tmp_check == tmp_n: #number is prime...so just to add to > dict > add_to_dict(tmp_n) > break The only reason that the *tmp_check* variable exists is to test whether you fell out of the *for* loop without finding any divisors for *tmp_n*. A cleaner approach is to use the optional *else* clause of the *for* loop, which is executed only if you didn't *break* out of the loop: for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): if tmp_n % x == 0: add_to_dict(x) tmp_n /= x break else: # tmp_n is prime...so just to add to dict add_to_dict(tmp_n) break > > > def add_one(x): > return x+1 > > > def mul(x,y): > return x * y > > def add_to_dict(p_num): > if my_dict.has_key(p_num): > my_dict[p_num] += 1 > else: > my_dict[p_num] = 1 > As poster pruebauno pointed out, using a collections.defaultdict eliminates the need for the *add_to_dict* function. > > my_dict = {} > > > prime_factors(135) > l = map(add_one,my_dict.values()) > print reduce(mul, l, 1) This may seem trivial, but ... don't use the single-character lowercase "l" as a variable. It looks too much like the digit "1" -- in some fonts, it looks identical! FWIW, here's my implementation. It's much slower, because it doesn't use the square root optimization. It uses another optimization: when a prime factor is located, *all* of its occurrences are factored out at the same time. #-------------------------------- from collections import defaultdict def prime_factors(n): """Return the prime factors of the given number (>= 2)""" if n < 2: print "arg must be >= 2" return last_result = n factors = defaultdict(int) next_divisor = 2 while True: while last_result % next_divisor == 0: factors[next_divisor] += 1 last_result /= next_divisor if last_result == 1: return factors next_divisor += 1 #-------------------------------- HTH, John From martin.hellwig at dcuktec.org Thu Feb 25 13:22:40 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Thu, 25 Feb 2010 18:22:40 +0000 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <4B86BFF0.60004@dcuktec.org> On 02/25/10 16:18, D'Arcy J.M. Cain wrote: Very interesting, I had a similar kind of problem (a network balancer that doesn't balance small tcp packages too well) and solved it by wrapping the TCP package in UDP. UDP was treated differently, although in overall switch and router manager it has a lower priority compared to other tcp packages, in normal usage it was faster. Probably because UDP has less things to inspect and by this can be processed faster by all the network equipment in between, but to be honest it worked for me and the client wasn't interested in academic explanations and since this was a working solution I didn't investigated it any further. Oh and a big thank you for PyGreSQL,! It has proven to be an extremely useful module for me (especially since I used to hop a lot between different unixes and Windows). -- mph From tjreedy at udel.edu Thu Feb 25 13:27:11 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Feb 2010 13:27:11 -0500 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> <480ad03c-8bc5-4c02-9f90-f41fffafa5be@g28g2000yqh.googlegroups.com> Message-ID: On 2/25/2010 9:21 AM, Richard Thomas wrote: > On Feb 25, 2:03 pm, fat bold cyclop wrote: >>> Both are not equal, so the comparison returns an arbitrary result in Py2. >> >> Thanks, Stefan. If I understand you correctly the comparison is not >> valid. >> But I wonder if there is any logic behind this (in 2.x). >> Is it possible to predict result of this comparison? In general, no. The result is arbitrary, with the constraint of being consistent within a particular run. >> Thanks again, >> fbc > > I believe in 2.x they are ordered by the names of their types but I > could be wrong. This is currently true in *CPython* 2.x, but that is an implementation artifact that has changed and might be different with other implementations. Terry Jan Reedy From tjreedy at udel.edu Thu Feb 25 13:31:47 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 25 Feb 2010 13:31:47 -0500 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: <20100225165117.GA30865@axis.g33x.de> References: <20100224101423.GA27668@axis.g33x.de> <20100225165117.GA30865@axis.g33x.de> Message-ID: On 2/25/2010 11:51 AM, Lars Gust?bel wrote: > On Wed, Feb 24, 2010 at 04:29:18PM -0500, Terry Reedy wrote: >> On 2/24/2010 5:14 AM, Lars Gust?bel wrote: >>> On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: >>>> I stumbled uppon this and find it somewhat odd: some class methods of >>>> TarFile and TarInfo do not appears in either the online documentation or >>>> search while they have a doc string: >>> >>> But to answer your question: Yes, this is intentional. The TarFile class has >>> three classmethods taropen(), gzopen(), and bz2open() each for a specific >>> compression method. These three are used internally by the TarFile.open() >>> classmethod and are not intended to be called directly. The TarFile.open() >>> method is the one that is publicly documented and supposed to be used. It >>> decides which of the three methods to use based on the mode argument and >>> does many more other high-level things as well. >> >> By current standards, the three private methods should be prefixed with >> '_' to indicate their private status. Could they be changed to head off >> such questions? > > I hope that this is not necessary. There are quite a few TarFile methods > more that are not documented and don't start with an underscore. I don't think > renaming all these is a good idea. > > The original intention behind these methods was that I wanted a lower level API for > TarFile that can be used for subclassing but stays as stable as possible at the > same time. If you intended for the *names* (if not the base methods themselves) to be part of the public interface, then no underscores is appropriate. It is a tough in-between case. I guess good docs, including doc stings, is the best you can do to make the situation clear. tjr From clp2 at rebertia.com Thu Feb 25 13:38:57 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Thu, 25 Feb 2010 10:38:57 -0800 Subject: Renaming identifiers & debugging In-Reply-To: <7unj59FuorU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> Message-ID: <50697b2c1002251038v1a6b0864q87ee7e354766cfee@mail.gmail.com> On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: > Hello, i am trying to develop an application to teach programming to young > kids in a similar way as Logo did in the past. I would like to use an > embedded Python as underlying language but this raises a problem. > > The target of my app are very young kids that might be unfamiliar with > english, so i am wondering if there is a way to rename/redefine identifiers > and messages in the language of the kid. > > In UCB-Logo this is very easy with the command > ?COPYDEF "newidentifier "oldidentifier > so all you have to do is setup a startup script to redefine all the > identifiers to the language of the user. > > Is there anything similar for python? Since python would be embedded it > would not be a problem for me to do it through some API. It can certainly be done (c.f. ChinesePython - http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), but I know of no framework that simplifies the task. Essentially, you just have to manually modify Python's parser by swapping out the english for the other language (and if you want to mess with the basic types' names, their name definitions somewhere else too). There also might be encoding issues to deal with. Cheers, Chris -- http://blog.rebertia.com From gereon.kaiping at yahoo.de Thu Feb 25 13:42:13 2010 From: gereon.kaiping at yahoo.de (Gereon Kaiping) Date: Thu, 25 Feb 2010 19:42:13 +0100 Subject: Artificial Neural Networks recommendation wanted In-Reply-To: References: Message-ID: <4B86C485.80608@yahoo.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, >> - - PyNN (just a builder, requires external simulator) ?http://neuralensemble.org/trac/PyNN/ >> - - Con-x (part of pyro) ?http://pyrorobotics.org/?page=Conx >> - - PyNeurGen (includes genetic algorithms) ?http://pyneurgen.sourceforge.net/ >> - - ffnet (only fast forward) ?http://ffnet.sourceforge.net/ >> - - brian (spiking networks) ?http://www.briansimulator.org/ >> - - PyBrain (machine learning) ?http://pybrain.org/ Thanks for the answers: > Fann has python bindings. I saw it, but forgot to include it in my listing. > PyNN and Brian are intended more for biologically-realistic neural > networks (for some value of realistic), aka neuronal networks, so I > guess you can rule them out (similar tools that you might come across > are NEST, NEURON, PCSIM). Yes, I thought so. (I might keep them in mind anyway, if I get to a more biologically approach someday, just like ffnet, which doesn't support recurrent networks but might be good in what it does.) Fann seems to be inable to simulate recurrent networks, too. (There are some older discussions, but I found no trace of a successful implementation.) So my main interest would be Con-x, PyNeurGen and PyBrain. Can you tell me anything about these modules or point me to where to find more information? Greetings, Gereon -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkuGxIUACgkQFWJnZLsO/Wv63gCfRy0WTocj+9u0W/g4RI+UbmXl 1aEAnjkVvVeC4GcuuI2TN1BgCp1sYd2U =BdbD -----END PGP SIGNATURE----- From mensanator at aol.com Thu Feb 25 13:59:39 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 25 Feb 2010 10:59:39 -0800 (PST) Subject: Walking lists References: Message-ID: <369d77c3-99c5-418f-8736-cae6e371088f@t23g2000yqt.googlegroups.com> On Feb 25, 7:02?am, Tim Chase wrote: > Python 3 introduced a variable tuple assignment which I > suspect[*] would work in this context: > > ? ?for first, *rest in L: # note the asterisk > ? ? ?print first > ? ? ?for x in rest: > ? ? ? ?do_stuff(x) > > [*] not having py3 on this machine, I can't readily verify this. Seems fine under 3.1. Cool. >>> L = ((1,2,3), (4,), (5,), (6,7) ) >>> for first, *rest in L: print('first',first,end=' ') print('rest',rest) first 1 rest [2, 3] first 4 rest [] first 5 rest [] first 6 rest [7] From brixomatic at yahoo.com Thu Feb 25 14:08:43 2010 From: brixomatic at yahoo.com (Wanja Gayk) Date: Thu, 25 Feb 2010 20:08:43 +0100 Subject: When will Java go mainstream like Python? References: Message-ID: Am 25.02.2010, 02:05 Uhr, schrieb Lawrence D'Oliveiro : > In message , Wanja Gayk wrote: > >> Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. It means I can write things > like > > contents = open(filename, "r").read() > > and know the file object will be immediately closed after its contents > are returned. Which has nothing to do with reference counting in general. This is what JVMs can do aswell. Just have a look at the behaviour of Weak- and SoftReferences to get an idea what goes on behind the scenes. For example: int x = new Point(10,20).getX(); The point object will be collectable as soon as getX() returned - even better: todays JIT compilers will inline the call and not even allocate the object, if it's allocation is free of side effects. What you write above is something entirely different: it's just a mechanism to release file handles, syntactic sugar for what you have in java when you close a stream in a finally-block. If you like to know a litle more about reference counting, feel free to study the following paper on a very sophistcated reference counting GC for the JVM by Levanoni and Petrank: http://reference.kfupm.edu.sa/content/e/o/e___an_on_the_fly_reference_counting_gar_61636.pdf The paper talks about some ofthe problems that occur with reference counting. Their algorithm uses some nice techniques to avoid thread contention (the reference-counter updates must be atomic, thus require that all "mutators" are stopped) and other problems connected to "referece counting" in general, such as slow writes (-> cache coherence, etc. read-only access is faster). What the paper doesn't tell is how they deal with fragmented heap, so I wouldn't trust that this Refcount-GC will have a stable performance over a long period of time (we're talking apps like Ebay, which run 24/7 for months if not years). Their algorithm may have a "comparable" speed to the (meanwhile) old implementation the JVM's GC, but it still needs the original JVM clean up what it leaves behind(it forgets some references) - maybe that's also how they deal with a fragmeted heap, as java uses a compacting collector. So, yes, it can be fast, or let's say responsive, but in general it's not. And when it is up to speed you get stability issues at least I have not heard anything different yet. To have some numbers: Benchmark Original RC Total 2582.2 2676.0 compress 720.8 723.3 db 374.0 383.7 jack 264.6 299.7 javac 225.0 235.2 jess 181.7 209.7 mpegaudio 607.1 610.6 As you see: SUN's GC is faster. Even though: what those folks have done is impressive (but buggy). > It also means I don?t have to predefine how much memory my program will > use. Which again has nothing to do with GC. This has been a design decision. In fact todays JVM dynamically allocate memory and gro their heaps. A quick look at the command line options will make that clear: java -X [...] -Xms set initial Java heap size -Xmx set maximum Java heap size Todays GC run as folows, they initialize the heap size at what you giove them in your Xmx-Setting (or use the default). When the heap is filled up to that initial size, they do a full GC and if that won't free enough memory, they will allocate some more. This is done until the upper limit from -Xmx is hit, when the program requires more than that, it will fail with an OutOfMemoryError. As you can imagine those limits may influence the GC, but they are no requirement for a GC. Those limits exists for the security of the host system (which may not be a system that allows setting own itself, like Unix/Linux). > A garbage collector will only kick in when the app runs low on memory. Wrong. Please inform yourself. Current generational GCs have minor and major collections. The JLS only requires that before the program runs out of memory the garbage has to be collected, which does not mean it cannot do that earlier. In fact you may also request a full GC by calling "System.gc()" when you know there's time for it. But it's not recommended in general. With JDK 7 we will get a new "Garbage First" Collector, which works differently than the ones we have today. It will promise lower response times and a more predictable behaviour with about the same speed. Starting with Java6 update 14 you may try that one (if you like, I can give ou the command line switch to activate it). Basically it is also a copying collector and in some way it's also generational, but it's "promotion" strategy is different. Anyway, it also won't only clean up when memory is low, but when it detects that there is a segment which is hardly live. > On a > system with dynamic memory allocation, that will not happen until the > entire > system runs low on memory, unless you limit the app to some fixed amount. > Which is an antiquated way of doing things. Which is wrong, see above. Today eve the C++ folks start using Garbage Collectors, because allocating/deallocating space using free-lists has proven to be slower than copying live objects. > And then there?s caching. Modern CPUs owe most of their speed to > assumptions that programs will obey locality of reference. Well, and what's the point? Stack allocation is just not necessary in a copy-colllector, bevause such a collector knows no deallocation (it just saves the survovors), so there is no gain from stack allocation. Stack allocation is faster in traditional C++ programs (without GCs), because the free-lists have to be managed. Todays HotSpot-Compilers take memory-locality into account aswell, just read some papers about it, have a look at "escape analysis" for example. Some further reading: http://www.ibm.com/developerworks/java/library/j-jtp09275.html http://www.ibm.com/developerworks/java/library/j-jtp04223.html > Pointer-chasing is a cache- hostile activity. Garbage collection > involves a lot of pointer-chasing, > particularly of dead objects that have long since been flushed from the > cache, compared with reference counting of recently-accessed objects. > Therefore garbage collection loses performance. You haven't read my previous posts, have you? Dead objects are not considered by today's Garbage collectors. Those trace only "reachable" objects and copy those. They won't even look at "dead" objects. Since most objects die young, this is where you gain a lot of performance. http://www.ibm.com/developerworks/library/j-jtp01274.html Reference counters, on the other hand, must detect when the reference count falls to zero. So they must look at each object, no matter if they are about to die, just to find out if they will die. Regards -Wanja- -- Erstellt mit Operas revolution?rem E-Mail-Modul: http://www.opera.com/mail/ --- news://freenews.netfront.net/ - complaints: news at netfront.net --- From roy at panix.com Thu Feb 25 14:21:51 2010 From: roy at panix.com (Roy Smith) Date: Thu, 25 Feb 2010 14:21:51 -0500 Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: In article , "D'Arcy J.M. Cain" wrote: > The problem had to do with the way TCP/IP works, especially closer to > the core. Our provider was collecting data and sending it only after > filling a buffer or after a timeout. The timeout was short so it > wouldn't normally be noticed and in most cases (web pages e.g.) the > connection is opened, data is pushed and the connection is closed so > the buffer is flushed immediately. Our patterns were different so we > were hitting the timeout on every single transaction and there was no > way we would have been able to keep up. > > Our first crack at fixing this was to simply add garbage to the packet > we were sending. Making the packets an order of magnitude bigger sped > up the proccessing dramatically. That wasn't a very clean solution > though so we looked for a better way. Interesting, the system I'm working with now has a similar problem. We've got a request/ack protocol over TCP which often sends lots of small packets and can have all sorts of performance issues because of this. In fact, we break completely on Solaris-10 with TCP Fusion enabled. We've gone back and forth with Sun on this (they claim what we're doing is broken, we claim TCP Fusion is broken). In the end, we just tell all of our Solaris-10 customers to disable TCP Fusion. From lucat at despammed.com Thu Feb 25 14:27:01 2010 From: lucat at despammed.com (Luca) Date: Thu, 25 Feb 2010 20:27:01 +0100 Subject: Renaming identifiers & debugging In-Reply-To: References: <7unj59FuorU1@mid.individual.net> Message-ID: <7uo186FiejU1@mid.individual.net> Chris Rebert wrote: > On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: >> Hello, i am trying to develop an application to teach programming to young >> kids in a similar way as Logo did in the past. I would like to use an >> embedded Python as underlying language but this raises a problem. >> >> The target of my app are very young kids that might be unfamiliar with >> english, so i am wondering if there is a way to rename/redefine identifiers >> and messages in the language of the kid. >> >> In UCB-Logo this is very easy with the command >> COPYDEF "newidentifier "oldidentifier >> so all you have to do is setup a startup script to redefine all the >> identifiers to the language of the user. >> >> Is there anything similar for python? Since python would be embedded it >> would not be a problem for me to do it through some API. > > It can certainly be done (c.f. ChinesePython - > http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), > but I know of no framework that simplifies the task. Essentially, you > just have to manually modify Python's parser by swapping out the > english for the other language (and if you want to mess with the basic > types' names, their name definitions somewhere else too). There also > might be encoding issues to deal with. > > Cheers, > Chris > -- > http://blog.rebertia.com Yes, i am playing with Python source code, i have changed some keywords but the compile-process fails when it tries to compile some of python libraries which, of course, use english keywords... so i guess this is not a very clean/viable solution (without having to rewrite several parts of the libraries). A better solution could be to "duplicate" keywords adding a translated version but leaving the original version in place so that every module keeps working. In few words, if i was going to translate the keyword "if" in, say, italian "se", then i would have both "if" and also "se" working at the same time, in the same manner. I think that the best way to do this is to insert a "filter" somewhere that converts every "se" keyword into a "if" keyword so that python doesn't even see the change. What i would like to do is add a new keyword (lets call it "copydef" like in UCBLogo or whatever) that does this work at runtime by keeping a substitution table in RAM. If i could manage to add this new keyword to python then it would be easy to write a startup script that translates the keywords once python is "up and running" and without breaking existing python programs/libraries (unless the new keyword conflicts with functions defined inside these programs/libraries). Thanx, Luca From deets at nospam.web.de Thu Feb 25 14:28:26 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 20:28:26 +0100 Subject: Pedantic pickling error after reload? In-Reply-To: References: Message-ID: <7uo1aqFitnU1@mid.uni-berlin.de> Am 25.02.10 18:08, schrieb Robert: > After (intended/controlled) reload or similar action on a module/class > the pickle/cPickle.dump raises errors like > > pickle.PicklingError: Can't pickle : it's > not the same object as somemodule.SomeClass > > > Cause in pickle.py (and cPickle) is a line > "if klass is not obj:" > > Shouldn't it be enough to have "if klass.__name__ != obj.__name__:" there? No. This would alias classes of same name, but living in different modules. So at least you need to compare these, too. I'm not sure if there aren't even more corner-cases. Python's import-mechanism can sometimes be rather foot-shoot-prone. > => a bug report/feature request? > > Classes can change face anyway during pickled state, why should a > over-pedantic reaction break things here during runtime? > (So far I'd need to walk the object tree in all facets and save against > inf loops like pickle himself and re-class things .. ) If anything it's a feature - and I doubt it's really needed. Because reloading pickles with intermittend reload-module-operations is to rare a case to be really supported IMHO. Do yourself a favor, write a unit-test that tests the desired behavior that makes you alter your code & then reload. This makes the problem go away, and you have a more stable development through having more tests :) Diez From helps4indian at gmail.com Thu Feb 25 14:42:57 2010 From: helps4indian at gmail.com (coolboy8) Date: Thu, 25 Feb 2010 11:42:57 -0800 (PST) Subject: Best auto insurance company Message-ID: <9ec65bf7-3b50-4c9a-ba9c-681aa74d922c@t34g2000prm.googlegroups.com> Find the Best auto insurance company here please visit http://autoinsurancerathere.blogspot.com From python at mrabarnett.plus.com Thu Feb 25 14:57:51 2010 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 25 Feb 2010 19:57:51 +0000 Subject: Renaming identifiers & debugging In-Reply-To: <7uo186FiejU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> Message-ID: <4B86D63F.5090601@mrabarnett.plus.com> Luca wrote: > Chris Rebert wrote: >> On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: >>> Hello, i am trying to develop an application to teach programming to >>> young >>> kids in a similar way as Logo did in the past. I would like to use an >>> embedded Python as underlying language but this raises a problem. >>> >>> The target of my app are very young kids that might be unfamiliar with >>> english, so i am wondering if there is a way to rename/redefine >>> identifiers >>> and messages in the language of the kid. >>> >>> In UCB-Logo this is very easy with the command >>> COPYDEF "newidentifier "oldidentifier >>> so all you have to do is setup a startup script to redefine all the >>> identifiers to the language of the user. >>> >>> Is there anything similar for python? Since python would be embedded it >>> would not be a problem for me to do it through some API. >> >> It can certainly be done (c.f. ChinesePython - >> http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), >> but I know of no framework that simplifies the task. Essentially, you >> just have to manually modify Python's parser by swapping out the >> english for the other language (and if you want to mess with the basic >> types' names, their name definitions somewhere else too). There also >> might be encoding issues to deal with. >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > Yes, i am playing with Python source code, i have changed some keywords > but the compile-process fails when it tries to compile some of python > libraries which, of course, use english keywords... so i guess this is > not a very clean/viable solution (without having to rewrite several > parts of the libraries). A better solution could be to "duplicate" > keywords adding a translated version but leaving the original version in > place so that every module keeps working. In few words, if i was going > to translate the keyword "if" in, say, italian "se", then i would have > both "if" and also "se" working at the same time, in the same manner. > I think that the best way to do this is to insert a "filter" somewhere > that converts every "se" keyword into a "if" keyword so that python > doesn't even see the change. > > What i would like to do is add a new keyword (lets call it "copydef" > like in UCBLogo or whatever) that does this work at runtime by keeping a > substitution table in RAM. If i could manage to add this new keyword to > python then it would be easy to write a startup script that translates > the keywords once python is "up and running" and without breaking > existing python programs/libraries (unless the new keyword conflicts > with functions defined inside these programs/libraries). > Perhaps you could use a different extension, eg ".pyn", so existing ".py" files are handled as-is but ".pyn" files are read through a translator. From deets at nospam.web.de Thu Feb 25 15:06:11 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 21:06:11 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uo186FiejU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> Message-ID: <7uo3hkFvvuU1@mid.uni-berlin.de> Am 25.02.10 20:27, schrieb Luca: > Chris Rebert wrote: >> On Thu, Feb 25, 2010 at 7:26 AM, Luca wrote: >>> Hello, i am trying to develop an application to teach programming to >>> young >>> kids in a similar way as Logo did in the past. I would like to use an >>> embedded Python as underlying language but this raises a problem. >>> >>> The target of my app are very young kids that might be unfamiliar with >>> english, so i am wondering if there is a way to rename/redefine >>> identifiers >>> and messages in the language of the kid. >>> >>> In UCB-Logo this is very easy with the command >>> COPYDEF "newidentifier "oldidentifier >>> so all you have to do is setup a startup script to redefine all the >>> identifiers to the language of the user. >>> >>> Is there anything similar for python? Since python would be embedded it >>> would not be a problem for me to do it through some API. >> >> It can certainly be done (c.f. ChinesePython - >> http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html), >> but I know of no framework that simplifies the task. Essentially, you >> just have to manually modify Python's parser by swapping out the >> english for the other language (and if you want to mess with the basic >> types' names, their name definitions somewhere else too). There also >> might be encoding issues to deal with. >> >> Cheers, >> Chris >> -- >> http://blog.rebertia.com > > Yes, i am playing with Python source code, i have changed some keywords > but the compile-process fails when it tries to compile some of python > libraries which, of course, use english keywords... so i guess this is > not a very clean/viable solution (without having to rewrite several > parts of the libraries). A better solution could be to "duplicate" > keywords adding a translated version but leaving the original version in > place so that every module keeps working. In few words, if i was going > to translate the keyword "if" in, say, italian "se", then i would have > both "if" and also "se" working at the same time, in the same manner. > I think that the best way to do this is to insert a "filter" somewhere > that converts every "se" keyword into a "if" keyword so that python > doesn't even see the change. > > What i would like to do is add a new keyword (lets call it "copydef" > like in UCBLogo or whatever) that does this work at runtime by keeping a > substitution table in RAM. If i could manage to add this new keyword to > python then it would be easy to write a startup script that translates > the keywords once python is "up and running" and without breaking > existing python programs/libraries (unless the new keyword conflicts > with functions defined inside these programs/libraries). You could use import-hooks for importing your code. There was a python-magazine article a while ago that showed how to use that + a parser to import seamlessly a DSL. Using pyparsing to write a python-grammar on the fly that simply exchanges the keywords before passing it to the interpreter is also easy. But to be honest: I doubt it's worth the effort. Really. Teaching people how to code, but in something that is *not* the "real" language is of little, if any, benefit. And also I don't think that your concerns are valid in general. Keywords are like brandnames or other things - the stand for a concept, and people immediatly accept them when they want them. Much, much, much more important would - if anything - be a standard-library, or a wrapper for that, e.g. for turtle-graphics, that was written in terms of your desired language. Diez From pruebauno at latinmail.com Thu Feb 25 15:09:12 2010 From: pruebauno at latinmail.com (nn) Date: Thu, 25 Feb 2010 12:09:12 -0800 (PST) Subject: Can I specify regex group to return float or int instead of string? References: <3111bb7c-d5c1-45c9-9a06-94d61cc95102@u19g2000prh.googlegroups.com> <4b86a81d$0$27844$c3e8da3@news.astraweb.com> <4b86b16b$0$27844$c3e8da3@news.astraweb.com> Message-ID: On Feb 25, 12:20?pm, Steven D'Aprano wrote: > On Thu, 25 Feb 2010 09:00:07 -0800, Jeremy wrote: > > On Feb 25, 9:41?am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Thu, 25 Feb 2010 07:48:44 -0800, Jeremy wrote: > >> > I have a regular expression that searches for some numbers and puts > >> > them into a dictionary, i.e. > > >> > '(?P\d+)\s+(?P\d+\.\d+)' > > >> > Is it possible to have the results of the matches returned as int or > >> > float objects instead of strings? > > >> No. Just convert the match with int() or float() before storing it in > >> the dictionary. That is, instead of: > > >> d[key] = match > > >> use > > >> d[key] = float(match) > > >> or similar. > > > I was afraid that was the only option. ?Oh well, thought I'd ask anyway. > > Why "afraid"? What's the problem with calling int or float on the match? > > -- > Steven He must not be Dutch :-) SCNR From aahz at pythoncraft.com Thu Feb 25 15:23:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 12:23:30 -0800 Subject: os.pipe() + os.fork() References: <20100220113604.49b7c242@gurka> <20100220125250.35c9937d@gurka> <256926de-e175-4fa2-aa24-dbd5f96756ef@u20g2000yqu.googlegroups.com> Message-ID: In article <256926de-e175-4fa2-aa24-dbd5f96756ef at u20g2000yqu.googlegroups.com>, sebastian.noack at googlemail.com wrote: >On Feb 20, 8:13=A0pm, Gary Herron wrote: >> >> Here's a thought: =A0Consider the subprocess module. =A0 It can do thefor= >k >> and any necessary pipes and can do so in an OS independent way. =A0 It >> might make you life much easier. > >As far as i know the subprocess module provides only functionality for >running any program as subprocess. But I just want to fork the current >process without putting some code in an external python script. Then try multiprocessing -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Thu Feb 25 15:32:19 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 12:32:19 -0800 Subject: Pure virtual functions in Python? References: <7udu49Fk3uU1@mid.individual.net> <38ddd614-583c-430d-b998-214bd6360eb2@b2g2000yqi.googlegroups.com> Message-ID: In article <38ddd614-583c-430d-b998-214bd6360eb2 at b2g2000yqi.googlegroups.com>, lallous wrote: >On Feb 22, 12:42=A0am, Gregory Ewing >wrote: >> lallouswrote: >>> >>> If the base defines the method and it was empty, then my C++ code >>> would still call the function. This is not optimal because I don't >>> want to go from C++ to Python if the _derived_ class does not >>> implement the cb. >> >> I would simply not implement the method at all in the base >> class. Then the C++ code can do an attribute lookup for >> the method, and if it's not found, do nothing. > >That is what I currently do. But if I comment out the implementations >(empty ones) then the documentation generation tool will not document >the callbacks. Maybe deleting the method after the class would work. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From johnroth1 at gmail.com Thu Feb 25 15:51:00 2010 From: johnroth1 at gmail.com (John Roth) Date: Thu, 25 Feb 2010 12:51:00 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Feb 24, 1:23?pm, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? > > /W > > -- > INVALID? DE! Is the problem that they've got the docstring in the wrong place, or that the comment isn't saying anything that can't be read in the method name? The first is easily fixable with a bit of tutorial about how a properly placed docstring prints out in various contexts, plus a quick script to move the suckers. The second is going to take more work to get the point across that comments that reproduce what the method name says are waste. John Roth From dontsendleospam at gmail.com Thu Feb 25 17:02:31 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Thu, 25 Feb 2010 14:02:31 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: Hi Arnaud et al, Here is the link to the bug report from which the discussion in PEP 289 was extracted: http://bugs.python.org/issue872326 It looks like they were fixing a bunch of bugs and that this discussion was one of the many in that thread. Here is another post which points to the core of the issue: early/late binding. It is also pointed to in PEP 289. http://mail.python.org/pipermail/python-dev/2004-April/044555.html Here is Guido's rationale (his text is the items (a) and (b) below. My comments follow. (a) I find it hard to defend automatic variable capture given Python's general late-binding semantics MY COMMENTS: That is a good point. There are however exceptions to the "general late-binding semantics" (GLBS) in Python. The outer loop does bind early in this case in fact. A point to consider along with GLBS is the unintuitive early bind of the external iterator vs late bind of the internal iterator. That is a function not of early vs. late binding, but of the current translation of generator expressions to generator functions. Using Arnaud's approach would fix that and make the code IMO so more pythonic. (b) I believe that use cases needing early binding are uncommon and strained: they all involve creating a list of generator expressions, which IMO is a pretty unusual thing to do MY COMMENTS: This is actually a pretty common use case. Any iteration over objects of arity 2 or greater (A matrix, a table, a tree searched breadthwise under some data structures, etc.) can conveniently and cleanly be expressed using a generator expression. I'd also add that perhaps the title of Guido's post: "Generator Expressions - Let's Move Forward" may have unintentionally discouraged people from reexamining the issue. I would like to see this decision revisited. Obviously before spending any time on this I'd like to gauge if there is further interest. Am I off the mark? Maybe there is a technical misunderstanding on my part. If there are more people affected (Since the last week I found some other postings here and on other lists and blogs) who can make a clear case, then what is the next step? Cheers, Leo. From deets at nospam.web.de Thu Feb 25 17:28:32 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Thu, 25 Feb 2010 23:28:32 +0100 Subject: compiling python question In-Reply-To: References: <4B859F0C.1060308@nospam.web.de> Message-ID: <7uobshFeqbU1@mid.uni-berlin.de> Am 25.02.10 01:55, schrieb Mag Gam: > sorry for the vague answer. > > Its Linux. > > The configure build does not say anything actually. This is for SAGE. > I managed to have it pick it up by compiling/installing tcl and tk and > then recompile python Then most probably installing the tk-dev packages would have been sufficient. diez From lucat at despammed.com Thu Feb 25 18:08:26 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 00:08:26 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uo3hkFvvuU1@mid.uni-berlin.de> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> Message-ID: <7uoe7bFsdsU1@mid.individual.net> Diez B. Roggisch wrote: > You could use import-hooks for importing your code. There was a > python-magazine article a while ago that showed how to use that + a > parser to import seamlessly a DSL. I will look into this, right now i don't know what import-hooks are nor if i can use them from embedded python. > Using pyparsing to write a python-grammar on the fly that simply > exchanges the keywords before passing it to the interpreter is also easy. This could be an easy solution yes... unfortunately this makes other problems arise... for instance... if i have an IDE that shows the translated language and i want to debug it step by step... would it be easy for me to map the english version (the one that python sees) with the translated version? I still have to look at this and how to run the debugger from the application that is "hosting" python so for now the answer is "i don't know". Right now, by simply changing the file Python-3.1.1/Grammar/Grammar i could obtain this (with "if" translated in "se"): Python 3.1.1 (r311:74480, Feb 25 2010, 22:44:50) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> Vero = True >>> stampa = print >>> >>> se Vero: ... stampa("Ciao") ... Ciao >>> Which seems to work, but requires to manually change the source code and it is way too complex for someone that has zero knowledge about the internals of python (like myself). Besides... it is a very ugly hack IMO. > But to be honest: I doubt it's worth the effort. Really. Teaching people > how to code, but in something that is *not* the "real" language is of > little, if any, benefit. > > And also I don't think that your concerns are valid in general. Keywords > are like brandnames or other things - the stand for a concept, and > people immediatly accept them when they want them. Maybe you are right, but being italian myself i can remember when i was a middle schooler (no computer before that) and the hours spent on my MSX figuring out how the thing worked. I learned all the commands as "brandnames" without really understanding them. I had _no_ idea that "if" meant... if, or that "print" meant to print. I had zero knowledge of english and for this reason most of these commands were meaningless to me, i didn't even suspect they had a meaning in an existing language, i just thought that was the way computers talked. When several years later, in High School, i learned English it was a real surprise for me to find out that the commands i had learned by heart as "magical words" actually had a precise meaning in "human language" and i think this would have helped me to figure out several things that instead took hours or days to understand. Now kids have internet, they study english from the kindergarten, they have a huge quantity of manuals and books freely available, so maybe you are right and i am just over-worrying. But still, i think it would be nice to use a language familiar to the kid (especially very young ones), it would make the learning process faster (no need to learn new words) and it would make the computer feel almost like a virtual "friend". > Much, much, much more important would - if anything - be a > standard-library, or a wrapper for that, e.g. for turtle-graphics, that > was written in terms of your desired language. I already made some tests with turtle-graphics and it seems to work. My next problem was to translate the language. http://img192.imageshack.us/img192/3093/zzz5.png [Btw... i took too much time to write this post so the ladybug fell asleep...] Thanx, Luca From news123 at free.fr Thu Feb 25 18:09:39 2010 From: news123 at free.fr (News123) Date: Fri, 26 Feb 2010 00:09:39 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7unj59FuorU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> Message-ID: <4b870333$0$15434$426a34cc@news.free.fr> Hi Luca, Luca wrote: > Hello, i am trying to develop an application to teach programming to > young kids in a similar way as Logo did in the past. I would like to use > an embedded Python as underlying language but this raises a problem. > > The target of my app are very young kids that might be unfamiliar with > english, so i am wondering if there is a way to rename/redefine > identifiers and messages in the language of the kid. > > In UCB-Logo this is very easy with the command > COPYDEF "newidentifier "oldidentifier > so all you have to do is setup a startup script to redefine all the > identifiers to the language of the user. > > Is there anything similar for python? Since python would be embedded it > would not be a problem for me to do it through some API. > a pragmatic approach might be to preprocess the source code and keep the original version as comments above the translated line. (for debugging) or to preprecess the input line before the 'exec'. It might be, that kids are flexible enough to use English words without understanding them. My younger brother could write Pascal before he learnt any English and he never cared, what 'if' 'then' 'else' 'for', etc. meant. It might be useful though to internationalize the python errror messages if that's not something already done. bye N From lucat at despammed.com Thu Feb 25 18:41:57 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 00:41:57 +0100 Subject: Renaming identifiers & debugging In-Reply-To: References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> Message-ID: <7uog65F5vuU1@mid.individual.net> MRAB wrote: > Perhaps you could use a different extension, eg ".pyn", so existing > ".py" files are handled as-is but ".pyn" files are read through a > translator. This could be a good idea... especially since i could make my own extension since we are talking of a special-purpose application that only incorporates python as a library. Thanx, Luca From deets at nospam.web.de Thu Feb 25 19:05:49 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 01:05:49 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uoe7bFsdsU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> <7uoe7bFsdsU1@mid.individual.net> Message-ID: <7uohitFbm4U1@mid.uni-berlin.de> >> And also I don't think that your concerns are valid in general. >> Keywords are like brandnames or other things - the stand for a >> concept, and people immediatly accept them when they want them. > > Maybe you are right, but being italian myself i can remember when i was > a middle schooler (no computer before that) and the hours spent on my > MSX figuring out how the thing worked. I learned all the commands as > "brandnames" without really understanding them. I had _no_ idea that > "if" meant... if, or that "print" meant to print. I had zero knowledge > of english and for this reason most of these commands were meaningless > to me, i didn't even suspect they had a meaning in an existing language, > i just thought that was the way computers talked. When several years > later, in High School, i learned English it was a real surprise for me > to find out that the commands i had learned by heart as "magical words" > actually had a precise meaning in "human language" and i think this > would have helped me to figure out several things that instead took > hours or days to understand. > Now kids have internet, they study english from the kindergarten, they > have a huge quantity of manuals and books freely available, so maybe you > are right and i am just over-worrying. But still, i think it would be > nice to use a language familiar to the kid (especially very young ones), > it would make the learning process faster (no need to learn new words) > and it would make the computer feel almost like a virtual "friend". I can't argue this from a technical point of view. Nor from a personal, as when I was first exposed to programming, I already new a few bits & pieces of english (leaving highschool with an E grade though....) However, I'm pretty sure what held me back most was the lack of (affordable, tuned to the younger audience) course material, and exchange with peers. Both which has *massively* changed with the internet available even in rather rural aereas of the world. Now under the assumption that you are right here, if keywords are what children keeps from learning programming - then your approach stops much to early. I already mentioned the standard-library, but of course much more important are the builtins. What's an int? Hell, I've been using the term integer for decades now, but actually don't really know if it really stands for "ganzzahl", the german word for what it is. And once they learned the language from whatever course material you prepared for them, they'd take a look outside - and find *nothing*. No code snippet to re-use without error-prone rewriting. Lack of understanding because of unfamiliar words. And so on. All this with a rather high cost on your side to prepare & and maintain a programming environment based upon a patched, potentially buggy interpreter + assorted course material. I really think you should instead focus on creating an environtment similar to what squeak offers, something integrated with easy access to graphics and sounds, that create amazement in the children and makes them want to code to realize their dreams. And of course natively named libraries, plus course-material. I didn't measure it, but by guesstimation, the ratio between keywords & other literals in python should be around the range of 1/10. Finally - well, if I'd were to learn italian, I'd rather not have my teacher translate all the nice italian words to german in my textbook... ;) It *is*, after all, learning a language we are talking here. It is alien. Even python :) Diez From lucat at despammed.com Thu Feb 25 19:06:10 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 01:06:10 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <4b870333$0$15434$426a34cc@news.free.fr> References: <7unj59FuorU1@mid.individual.net> <4b870333$0$15434$426a34cc@news.free.fr> Message-ID: <7uohjjFcvqU1@mid.individual.net> News123 wrote: > a pragmatic approach might be to preprocess the source code > and keep the original version as comments above the translated line. > (for debugging) Not very nice to see though. This change should be transparent to the kid, he/she should not be aware of this "translation". > or to preprecess the input line before the 'exec'. This could be a solution, yes, but then i would also need to figure out a way to show the original line when debugging (still, i know nothing about pdb, maybe it is possible in a easy way). > It might be, that kids are flexible enough to use English words without > understanding them. > > My younger brother could write Pascal before he learnt any English and > he never cared, what 'if' 'then' 'else' 'for', etc. meant. I had a similar experience. When i was a middle schooler i knew nothing about English and so i learned Basic and then Pascal without actually knowing that those words had a meaning at all. For me they were just kind of "magical words" that i could use to tell the computer what to do. So i know for sure that this is possible. But... imagine the use of this language in a elementary school. Some kids, like me or you or your brother would be interested enough to find it easy to learn the new words. For others it would only be a pain. Another lesson among others that to them makes no sense at all. If we could make it easier for them to understand the words used in the language the teacher would have an easier time to explain some concepts and maybe even these kids could have fun and begin to love it. I understand that this "breaks" the language, that it would be better if they would just learn the "original" language... but most teachers would ask "then why not use Logo instead? it is already in our language..." I have nothing against logo of course, i have learned it myself even before Pascal and i had lots of fun with it. But python is much more widespread than logo and i think in some ways it makes "more sense" than logo and it is not much harder. The only problem that i see is that Logo does have its commands translated while python doesn't nor, it seems, there is an easy way to add this functionality. > It might be useful though to internationalize the python errror messages > if that's not something already done. Yes, this would be very important... but still, it should be easy for the teacher to translate the messages to make them more understandable to the kids. For instance... * Python: >>> draw Traceback (most recent call last): File "", line 1, in NameError: name 'draw' is not defined * Logo: ? draw I don't know how to draw Logo's message, while maybe too simple for a professional developer, is certainly much more easy for a kid. So you see, it is not just a matter of internationalization... it is also a matter of users-target. If i am talking to a young kid i should use words and concepts that are easy for him/her to understand... so, for my target, it would be very important not only a correct translation in my language, but also the use of words and concepts that are familiar to a kid. Thanx, Luca From deets at nospam.web.de Thu Feb 25 19:08:50 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 01:08:50 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uoe7bFsdsU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> <7uoe7bFsdsU1@mid.individual.net> Message-ID: <7uohoiFbm4U2@mid.uni-berlin.de> On a related note, did you investigate SUGAR of the OLPC? I'd say these guys certainly tried to create something that appealed to children, and AFAIK it comes with a Python interpreter. I'm don't know anything about that, nor if it comes with learning material. Might be worth checking out. Diez From aahz at pythoncraft.com Thu Feb 25 19:10:57 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 16:10:57 -0800 Subject: Compiling and running 32-bit Python on 64-bit server? References: Message-ID: In article , Mikko Ohtamaa wrote: > >How one could create 32-bit Python run-time enviroment, preferable >virtualenv, on 64-bit Linux (VPS), reducing memory usage? This >environment could actually beat 64-bit in performance, due to better >memory cache use. > >I assume this involves having lib32 libs and compiling Python with >some magical switches. The simplest approach would probably be to do the compilation on a 32-bit system and just install it on 64-bit. There are some magic flags, yes; you'll need to Google using e.g. "linux force 32-bit compile". -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From cg at graysage.com Thu Feb 25 19:11:32 2010 From: cg at graysage.com (Chris Gray) Date: 25 Feb 2010 17:11:32 -0700 Subject: When will Java go mainstream like Python? References: Message-ID: <87mxyw500b.fsf@ami-cg.GraySage.com> Lawrence D'Oliveiro writes: > In message , Wanja Gayk wrote: > > > Reference counting is about the worst technique for garbage collection. > > It avoids the need for garbage collection. It means I can write things like I'm by no means an expert, but how does reference counting deal with arbitrary long cycles of references (btw I've *written* a simple reference counter for a programming language)? When I asked someone whose knowlege of Java I trust, he said that modern Java's do both reference counting and garbage collection. That was 2 or 3 years ago. I would have guessed that Python was the same. -- Experience should guide us, not rule us. Chris Gray From deets at nospam.web.de Thu Feb 25 19:12:00 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 01:12:00 +0100 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <7uohugFedhU1@mid.uni-berlin.de> > That better way turned out to asynchronous update transactions. All we > did was keep feeding updates to the remote site and forget about ACKS. > We then had a second process which handled ACKS and tracked which > packets had been properly transferred. The system had IDs on each > update and retries happened if ACKS didn't happen soon enough. > Naturally we ignored ACKS that we had already processed. sounds like using UDP to me, of course with a protocol on top (namely the one you implemented). Any reason you sticked to TCP instead? Diez From rt8396 at gmail.com Thu Feb 25 19:29:13 2010 From: rt8396 at gmail.com (r) Date: Thu, 25 Feb 2010 16:29:13 -0800 (PST) Subject: why (1, 2, 3) > [1, 2, 3] is true? References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: On Feb 25, 7:00?am, fat bold cyclop wrote: > why (1, 2, 3) > [1, 2, 3] is true? It's simple, Everything must have a value! From ethan at stoneleaf.us Thu Feb 25 19:34:35 2010 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 25 Feb 2010 16:34:35 -0800 Subject: Renaming identifiers & debugging In-Reply-To: <7uoe7bFsdsU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uo3hkFvvuU1@mid.uni-berlin.de> <7uoe7bFsdsU1@mid.individual.net> Message-ID: <4B87171B.7030708@stoneleaf.us> Luca wrote: [snippety] > Maybe you are right, but being italian myself i can remember when i was > a middle schooler (no computer before that) and the hours spent on my > MSX figuring out how the thing worked. I learned all the commands as > "brandnames" without really understanding them. I had _no_ idea that > "if" meant... if, or that "print" meant to print. I had zero knowledge > of english and for this reason most of these commands were meaningless > to me, i didn't even suspect they had a meaning in an existing language, > i just thought that was the way computers talked. [more snippety] Perhaps the lesson to learn from this is that as *you* teach programming to non-english speakers you take the time to say "'if' means 'se', 'print' means 'stampa'", etc. I suspect your early years would have been much easier with those bits of knowledge. :) ~Ethan~ From alfps at start.no Thu Feb 25 19:41:29 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Feb 2010 01:41:29 +0100 Subject: When will Java go mainstream like Python? In-Reply-To: <87mxyw500b.fsf@ami-cg.GraySage.com> References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: * Chris Gray: > Lawrence D'Oliveiro writes: > >> In message , Wanja Gayk wrote: >> >>> Reference counting is about the worst technique for garbage collection. >> It avoids the need for garbage collection. It means I can write things like > > I'm by no means an expert, but how does reference counting deal with > arbitrary long cycles of references (btw I've *written* a simple > reference counter for a programming language)? Generally it doesn't. Some solutions have however been proposed for std::shared_ptr in C++. None have made it to any noteworthy status, but they demonstrate that there are more or less practical solutions for the most common cases. Currently the upshot is that if you need the kind of self-referential spaghetti structure (no offense) created by mathematical expressions that refer to each other, then you've passed beyond what can be handled practically by reference counting alone or even in combination with cycle handling techniques. For that you're better off with some functional language, or Python... ;-) > When I asked someone whose knowlege of Java I trust, he said that modern > Java's do both reference counting and garbage collection. That was 2 or 3 > years ago. I would have guessed that Python was the same. Yes, Python adds general garbage collection to deal with cycles. Essentially the reference counting deals efficiently and immediately with objects created by expression evaluation, while the general garbage collection deals with cyclic structures. But there's no magic: in particular in Java, Python and like languages you must still remember to remove references installed in singletons and globals (e.g. for event notifications), otherwise objects will still be referenced and thus not garbage collected, causing a memory leak. Cheers & hth., - Alf From robert.kern at gmail.com Thu Feb 25 19:42:35 2010 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 25 Feb 2010 18:42:35 -0600 Subject: why (1, 2, 3) > [1, 2, 3] is true? In-Reply-To: References: <97dbfd50-416b-4fbe-82b8-549d405b35c6@y17g2000yqd.googlegroups.com> Message-ID: On 2010-02-25 18:29 PM, r wrote: > On Feb 25, 7:00 am, fat bold cyclop wrote: >> why (1, 2, 3)> [1, 2, 3] is true? > > It's simple, Everything must have a value! That is not at all an explanation, much less a true one. Please read the other posts in this thread; they have explained the situation rather well. -- 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 aahz at pythoncraft.com Thu Feb 25 19:51:01 2010 From: aahz at pythoncraft.com (Aahz) Date: 25 Feb 2010 16:51:01 -0800 Subject: How would I do a continuous write over a pipe in the following code... References: <9d0f6456-97c7-4bde-8e07-9576b02f91f9@t31g2000prh.googlegroups.com> Message-ID: In article <9d0f6456-97c7-4bde-8e07-9576b02f91f9 at t31g2000prh.googlegroups.com>, chad wrote: > >import subprocess as s > >broadcast = s.Popen("echo test | wall", shell=True,stdout=s.PIPE) > >out = broadcast.stdout >while 1: > out > broadcast.wait() > >broadcast.stdout.close() > > >The code only executes once. What I want to do is be able to >continuously write over the pipe once it is open. I could put >s.Popen() inside the while loop, but that seems a bit too messy. So is >there some way to just open the pipe once, and once it is open, just >continuously write over it vs just opening and closing the pipe every >time? You really should do this instead, untested: broadcast = s.Popen(['wall'], stdin=s.PIPE) while 1: broadcast.write('test\n') time.sleep(1) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 19:58:07 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 00:58:07 GMT Subject: When will Java go mainstream like Python? References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: <4b871c9e$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 17:11:32 -0700, Chris Gray wrote: > I'm by no means an expert, but how does reference counting deal with > arbitrary long cycles of references (btw I've *written* a simple > reference counter for a programming language)? It doesn't, or at least the CPython one doesn't. In CPython, even a short reference cycle defeats it, which is why CPython also uses a second garbage collector. If we turn that off, we can see how even a one-element cycle defeats reference counting: >>> import gc >>> gc.disable() >>> >>> class K: ... def __del__(self): ... print "Bye now" ... >>> k = K() >>> del k # Test it works as expected. Bye now >>> >>> k = K() # Now try with a cycle. >>> k.attr = k >>> del k >>> >>> Normally, you would clear the ref cycle this way: >>> gc.collect() 2 But in this case it doesn't work because the object in the cycle has a __del__ method, and Python can't predict a safe order to run the __del__ method. (I'm surprised that this is an issue with a single object, but what do I know?) So we have to inspect the list of garbage, manually break the cycle, clear new references we've created, and then it will be garbage collected: >>> gc.garbage[0].attr = None # Break the cycle >>> del gc.garbage[:] Bye now This is one reason why __del__ methods are not recommended. > When I asked someone whose knowlege of Java I trust, he said that modern > Java's do both reference counting and garbage collection. That was 2 or > 3 years ago. I would have guessed that Python was the same. CPython has both now. Jython uses whatever the Java implementation uses, and IronPython uses .Net's memory management scheme. Other Pythons do whatever they like :) Some interesting information here: http://www.digi.com/wiki/developer/index.php/Python_Garbage_Collection -- Steven From mensanator at aol.com Thu Feb 25 20:00:32 2010 From: mensanator at aol.com (Mensanator) Date: Thu, 25 Feb 2010 17:00:32 -0800 (PST) Subject: When will Java go mainstream like Python? References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: On Feb 25, 6:41?pm, "Alf P. Steinbach" wrote: > * Chris Gray: > > > Lawrence D'Oliveiro writes: > > >> In message , Wanja Gayk wrote: > > >>> Reference counting is about the worst technique for garbage collection. > >> It avoids the need for garbage collection. It means I can write things like > > > I'm by no means an expert, but how does reference counting deal with > > arbitrary long cycles of references (btw I've *written* a simple > > reference counter for a programming language)? > > Generally it doesn't. Some solutions have however been proposed for > std::shared_ptr in C++. None have made it to any noteworthy status, but they > demonstrate that there are more or less practical solutions for the most common > cases. > > Currently the upshot is that if you need the kind of self-referential spaghetti > structure (no offense) created by mathematical expressions that refer to each > other, then you've passed beyond what can be handled practically by reference > counting alone or even in combination with cycle handling techniques. > > For that you're better off with some functional language, or Python... ;-) > > > When I asked someone whose knowlege of Java I trust, he said that modern > > Java's do both reference counting and garbage collection. That was 2 or 3 > > years ago. I would have guessed that Python was the same. > > Yes, Python adds general garbage collection to deal with cycles. > > Essentially the reference counting deals efficiently and immediately with > objects created by expression evaluation, while the general garbage collection > deals with cyclic structures. > > But there's no magic: in particular in Java, Python and like languages you must > still remember to remove references installed in singletons and globals (e.g. > for event notifications), otherwise objects will still be referenced and thus > not garbage collected, causing a memory leak. Is that really considered a leak, a single instance of an uncollected global as opposed to a function that is called millions of times, and each time it's called creates uncollected temporary variables? > > Cheers & hth., > > - Alf From steve at REMOVE-THIS-cybersource.com.au Thu Feb 25 20:06:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 01:06:18 GMT Subject: When will Java go mainstream like Python? References: <87mxyw500b.fsf@ami-cg.GraySage.com> Message-ID: <4b871e8a$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 17:00:32 -0800, Mensanator wrote: > Is that really considered a leak, a single instance of an uncollected > global as opposed to a function that is called millions of times, and > each time it's called creates uncollected temporary variables? I think it's generally called "garbage". When the amount of garbage grows, or *could* grow, it is called a leak. But nobody is going to slap you for calling a single instance of an uncollectable object a leak. -- Steven From g.bogle at auckland.no.spam.ac.nz Thu Feb 25 21:14:06 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Fri, 26 Feb 2010 15:14:06 +1300 Subject: Executable problem - socket? References: Message-ID: MRAB wrote: > You could try Dependency Walker: http://dependencywalker.com/ > I have (belatedly) read the py2exe tutorial: http://www.py2exe.org/index.cgi/Tutorial#Step522 and learned about the msvcr90.dll issue. I haven't finished sorting this out yet, but I did find that running vcredist_x86.exe (the right version!) on box 1 fixed things there. I also tried (naively) manually adding dist\Microsoft.VC90.CRT with the manifest file and msvcr90.dll, but this doesn't seem to work - it seems that p2exe must do the file copying. From darcy at druid.net Thu Feb 25 23:01:26 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Thu, 25 Feb 2010 23:01:26 -0500 Subject: taking python enterprise level?... In-Reply-To: <7uohugFedhU1@mid.uni-berlin.de> References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> Message-ID: <20100225230126.419f8c53.darcy@druid.net> On Fri, 26 Feb 2010 01:12:00 +0100 "Diez B. Roggisch" wrote: > > That better way turned out to asynchronous update transactions. All we > > did was keep feeding updates to the remote site and forget about ACKS. > > We then had a second process which handled ACKS and tracked which > > packets had been properly transferred. The system had IDs on each > > update and retries happened if ACKS didn't happen soon enough. > > Naturally we ignored ACKS that we had already processed. > > sounds like using UDP to me, of course with a protocol on top (namely > the one you implemented). > > Any reason you sticked to TCP instead? TCP does a great job of delivering a stream of data in order and handling the retries. The app really was connection oriented and we saw no reason to emulate that over an unconnected protocol. There were other wheels to reinvent that were more important. -- 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 darnzen at gmail.com Thu Feb 25 23:54:41 2010 From: darnzen at gmail.com (darnzen) Date: Thu, 25 Feb 2010 20:54:41 -0800 (PST) Subject: staticmethod and namespaces Message-ID: <814d3f0f-9530-44f3-a533-087540bdcd81@d27g2000yqf.googlegroups.com> Having an odd problem that I solved, but wondering if its the best solution (seems like a bit of a hack). First off, I'm using an external DLL that requires static callbacks, but because of this, I'm losing instance info. It will make more sense after I diagram it: #Module main.py class App: def sperg(self): pass app = App() [main loop and such] ----------------------------- # Module A.py import main class Foo: @staticmethod chum(nType, nPtr): # Need to access function / data in app instance app.sperg(nType, nPtr) From darnzen at gmail.com Fri Feb 26 00:07:55 2010 From: darnzen at gmail.com (darnzen) Date: Thu, 25 Feb 2010 21:07:55 -0800 (PST) Subject: staticmethod and namespaces Message-ID: Having an odd problem that I solved, but wondering if its the best solution (seems like a bit of a hack). First off, I'm using an external DLL that requires static callbacks, but because of this, I'm losing instance info. It could be import related? It will make more sense after I diagram it: #Module main.py from A import * class App: def sperg(self): self.a = A() app = App() [main loop and such] ----------------------------- # Module A.py import main class Foo: Selves=[] def __init__(self): Foo.Selves.append(self) @staticmethod def chum_callback(nType, nP): # Need to access function / data in app instance app.sperg(nP) # Need to access func data in Foo # I'm pulling 'self' ouf of list made in constructor self = Foo.getSelf(nP) def getSelf(nP): return self.Selves[nP] --------------------------------------------------------------------- So basically I added a list of instances to the base class so I can get at them from the staticmethod. What's bothering me the most is I can't use the global app instance in the A.py module. How can I get at the app instance (currently I'm storing that along with the class instance in the constructor)? Is there another way to do this that's not such a hack? Sorry for the double / partial post :( From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 02:12:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 07:12:48 GMT Subject: staticmethod and namespaces References: Message-ID: <4b877470$0$27844$c3e8da3@news.astraweb.com> On Thu, 25 Feb 2010 21:07:55 -0800, darnzen wrote: > Having an odd problem that I solved, but wondering if its the best > solution (seems like a bit of a hack). > > First off, I'm using an external DLL that requires static callbacks, but > because of this, I'm losing instance info. [...] > How can I get at the app instance (currently I'm storing that along with > the class instance in the constructor)? Is there another way to do this > that's not such a hack? Pass the instance explicitly: >>> class K(object): ... @staticmethod ... def static(self, x, y): ... print self, x, y ... >>> k = K() >>> k.static(k, 1, 2) <__main__.K object at 0xb7c2544c> 1 2 -- Steven From gaoxtwarrior at gmail.com Fri Feb 26 02:17:23 2010 From: gaoxtwarrior at gmail.com (Gao) Date: Fri, 26 Feb 2010 15:17:23 +0800 Subject: Hi, I know it's stupid, but does your foreigner do a lot of OT work? Message-ID: I'm Chinese, I'm working in a famous vendor company which let employee do a lot of OT work, 2 more hours per day, and sometime work in weekend. Is that the same in USA and European? From kalakal.anjali at gmail.com Fri Feb 26 02:30:11 2010 From: kalakal.anjali at gmail.com (HOT GIRLS HOT Night) Date: Thu, 25 Feb 2010 23:30:11 -0800 (PST) Subject: %%% Funny College Girls Nude Video HERE %%% Message-ID: <00f35ca7-f3d6-439e-863c-31e121b528ad@a5g2000prg.googlegroups.com> %%% Funny College Girls Nude Video HERE %%% http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ http://sites.google.com/site/hifiprofile/ From arnodel at googlemail.com Fri Feb 26 02:40:54 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Fri, 26 Feb 2010 07:40:54 +0000 Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: dontspamleo writes: > Hi Arnaud et al, > > Here is the link to the bug report from which the discussion in PEP > 289 was extracted: > > http://bugs.python.org/issue872326 > > It looks like they were fixing a bunch of bugs and that this > discussion was one of the many in that thread. > > Here is another post which points to the core of the issue: early/late > binding. It is also pointed to in PEP 289. > > http://mail.python.org/pipermail/python-dev/2004-April/044555.html Thanks for digging those out! > Here is Guido's rationale (his text is the items (a) and (b) below. My > comments follow. > > (a) I find it hard to defend automatic variable capture given Python's > general late-binding semantics > > MY COMMENTS: That is a good point. There are however exceptions to the > "general late-binding semantics" (GLBS) in Python. The outer loop does > bind early in this case in fact. A point to consider along with GLBS > is the unintuitive early bind of the external iterator vs late bind of > the internal iterator. That is a function not of early vs. late > binding, but of the current translation of generator expressions to > generator functions. Using Arnaud's approach would fix that and make > the code IMO so more pythonic. But see this message from Guido: http://bugs.python.org/issue872326#msg45190 It looks like he's thinking of early binding of free variables. Later on he seems to contradict this. Below it is mentioned that two patches were made, one with the current behaviour and one with the one you (and I) would prefer. > (b) I believe that use cases needing early binding are uncommon and > strained: they all involve creating a list of generator > expressions, which IMO is a pretty unusual thing to do > > MY COMMENTS: This is actually a pretty common use case. Any iteration > over objects of arity 2 or greater (A matrix, a table, a tree searched > breadthwise under some data structures, etc.) can conveniently and > cleanly be expressed using a generator expression. And also your example when defining a generator expression in a class scope becomes confusing with the current semantics. > I'd also add that perhaps the title of Guido's post: "Generator > Expressions - Let's Move Forward" may have unintentionally discouraged > people from reexamining the issue. > > I would like to see this decision revisited. Obviously before spending > any time on this I'd like to gauge if there is further interest. Am I > off the mark? Maybe there is a technical misunderstanding on my part. > If there are more people affected (Since the last week I found some > other postings here and on other lists and blogs) who can make a clear > case, then what is the next step? I suppose it would be interesting to see how this can be implemented, maybe look at the gexp.diff.capture file on the bug tracker. I was intending to look into it a couple of years ago but I could never find the time :( -- Arnaud From baptiste.lepilleur at gmail.com Fri Feb 26 03:28:04 2010 From: baptiste.lepilleur at gmail.com (Baptiste Lepilleur) Date: Fri, 26 Feb 2010 09:28:04 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: <20100224101423.GA27668@axis.g33x.de> References: <20100224101423.GA27668@axis.g33x.de> Message-ID: 2010/2/24 Lars Gust?bel > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: > > I stumbled uppon this and find it somewhat odd: some class methods of > > TarFile and TarInfo do not appears in either the online documentation or > > search while they have a doc string: > > > > http://docs.python.org/search.html?q=gzopen > > > http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarFile > > > > See script at the end for list of class methods. > > > > Is this "by design" or is there some an odd bug in doc generation lurking > > around? This somehow seem to be specific to module tarfile. Fraction > > classmethod from_float() is available in the documentation and found by a > > search for example... > > First of all, Python's module documentation is not generated from module > docstrings, each module has its own rst text file in the documentation tree > instead. > I was ignorant of that fact. Thanks for letting me know. > But to answer your question: Yes, this is intentional. The TarFile class > has > three classmethods taropen(), gzopen(), and bz2open() each for a specific > compression method. These three are used internally by the TarFile.open() > classmethod and are not intended to be called directly. The TarFile.open() > method is the one that is publicly documented and supposed to be used. It > decides which of the three methods to use based on the mode argument and > does many more other high-level things as well. > I think it would be best to annotate the help string to let people know of the facts it is not intended for public usage (or restriction that apply, e.g. only for subclassing as you hinted in another post). If I find a method using dir/doc string, I don't check the public documentation to see if it is present. And even if I did, now that I know that documentation is maintained separately from the code base, I would rather assumes a documentation bug than this being by design as is the case here. Notes: googling around, there is already a few uses of TarFile.gzopen(). My guess would be that people find it more convenient for passing compression level. Anyway, thanks for writing this module, it very easy to use! Baptiste. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peloko45 at gmail.com Fri Feb 26 03:55:49 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 00:55:49 -0800 (PST) Subject: Get dosctring without import Message-ID: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> When a package is imported, it gets the dosctring to store it in *__doc__*. Does that funcion is built in python? because I would want use it to get the docstring without import a package From deets at nospam.web.de Fri Feb 26 04:06:17 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 10:06:17 +0100 Subject: Get dosctring without import In-Reply-To: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <7uph89FrdiU1@mid.uni-berlin.de> Am 26.02.10 09:55, schrieb Joan Miller: > When a package is imported, it gets the dosctring to store it in > *__doc__*. > > Does that funcion is built in python? because I would want use it to > get the docstring without import a package You'd need to write your own parser for that. All standard tools simply import, see another thread a few days ago where a user had problems with help on modules. Also, without importing, you'd not get docstrings of C-extension-objects. Diez From deets at nospam.web.de Fri Feb 26 04:15:47 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 10:15:47 +0100 Subject: staticmethod and namespaces In-Reply-To: References: Message-ID: <7uphq3FuapU1@mid.uni-berlin.de> Am 26.02.10 06:07, schrieb darnzen: > Having an odd problem that I solved, but wondering if its the best > solution (seems like a bit of a hack). > > First off, I'm using an external DLL that requires static callbacks, > but because of this, I'm losing instance info. It could be import > related? It will make more sense after I diagram it: > > #Module main.py > from A import * > > class App: > def sperg(self): > self.a = A() > > app = App() > [main loop and such] > ----------------------------- > # Module A.py > import main > class Foo: > Selves=[] > def __init__(self): > Foo.Selves.append(self) > @staticmethod > def chum_callback(nType, nP): > # Need to access function / data in app instance > app.sperg(nP) > # Need to access func data in Foo > # I'm pulling 'self' ouf of list made in constructor > self = Foo.getSelf(nP) > > def getSelf(nP): > return self.Selves[nP] > > --------------------------------------------------------------------- > So basically I added a list of instances to the base class so I can > get at them from the staticmethod. > What's bothering me the most is I can't use the global app instance in > the A.py module. > > How can I get at the app instance (currently I'm storing that along > with the class instance in the constructor)? > Is there another way to do this that's not such a hack? > > Sorry for the double / partial post :( Can you show how you pass the staticmethod to the C-function? Is the DLL utilized by ctypes? I don't see any reason you couldn't use a bound method, which would give you your self, instead relying on global state. Diez From deets at nospam.web.de Fri Feb 26 04:19:15 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 10:19:15 +0100 Subject: taking python enterprise level?... In-Reply-To: References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> <7uohugFedhU1@mid.uni-berlin.de> Message-ID: <7upi0jFuapU2@mid.uni-berlin.de> Am 26.02.10 05:01, schrieb D'Arcy J.M. Cain: > On Fri, 26 Feb 2010 01:12:00 +0100 > "Diez B. Roggisch" wrote: >>> That better way turned out to asynchronous update transactions. All we >>> did was keep feeding updates to the remote site and forget about ACKS. >>> We then had a second process which handled ACKS and tracked which >>> packets had been properly transferred. The system had IDs on each >>> update and retries happened if ACKS didn't happen soon enough. >>> Naturally we ignored ACKS that we had already processed. >> >> sounds like using UDP to me, of course with a protocol on top (namely >> the one you implemented). >> >> Any reason you sticked to TCP instead? > > TCP does a great job of delivering a stream of data in order and > handling the retries. The app really was connection oriented and we > saw no reason to emulate that over an unconnected protocol. There were > other wheels to reinvent that were more important. So when you talk about ACKs, you don't mean these on the TCP-level (darn, whatever iso-level that is...), but on some higher level? Diez From massimodipierro71 at gmail.com Fri Feb 26 04:32:30 2010 From: massimodipierro71 at gmail.com (mdipierro) Date: Fri, 26 Feb 2010 01:32:30 -0800 (PST) Subject: taking python enterprise level?... References: <5cd38064-34d6-40d3-b3dc-2c853fc86728@i39g2000yqm.googlegroups.com> Message-ID: <1d8cf423-d13e-4b18-b68b-108f85cae5af@t34g2000prm.googlegroups.com> 100,000 hits a day is not a low. I get that some day on my web server without problem and without one request dropped. Most frameworks web2py, Django, Pylons can handle that kind of load since Python is not the bottle neck. You have to follow some tricks: 1) have the web server serve static pages directly and set the pragma cache expire to one month 2) cache all pages that do not have forms for at least few minutes 3) avoid database joins 4) use a server with at least 512KB Ram. 5) if you pages are large, use gzip compression If you develop your app with the web2py framework, you always have the option to deploy on the Google App Engine. If you can live with their constraints you should have no scalability problems. Massimo On Feb 25, 4:26?am, simn_stv wrote: > hello people, i have been reading posts on this group for quite some > time now and many, if not all (actually not all!), seem quite > interesting. > i plan to build an application, a network based application that i > estimate (and seriously hope) would get as many as 100, 000 hits a day > (hehe,...my dad always told me to 'AIM HIGH' ;0), not some 'facebook' > or anything like it, its mainly for a financial transactions which > gets pretty busy... > so my question is this would anyone have anything that would make > python a little less of a serious candidate (cos it already is) and > the options may be to use some other languages (maybe java, C (oh > God))...i am into a bit of php and building API's in php would not be > the hard part, what i am concerned about is scalability and > efficiency, well, as far as the 'core' is concerned. > > would python be able to manage giving me a solid 'core' and will i be > able to use python provide any API i would like to implement?... > > im sorry if my subject was not as clear as probably should be!. > i guess this should be the best place to ask this sort of thing, hope > im so right. > > Thanks From michael at stroeder.com Fri Feb 26 04:33:38 2010 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 26 Feb 2010 10:33:38 +0100 Subject: ANN: python-ldap-2.3.11 Message-ID: Find a new release of python-ldap: http://www.python-ldap.org/ python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Ciao, Michael. -- Michael Str?der E-Mail: michael at stroeder.com http://www.stroeder.com ---------------------------------------------------------------- Released 2.3.11 2010-02-26 Changes since 2.3.10: Lib/ * Fixed LDAP URL parsing with four ? but no real extensions * ldap.ldapobject.LDAPObject.rename_s() now also accepts arguments serverctrls and clientctrls * Removed untested and undocumented class ldap.ldapobject.SmartLDAPObject * Removed broken method ldap.ldapobject.LDAPObject.manage_dsa_it() Modules/ * Make use of LDAP_OPT_X_TLS_NEWCTX only if available in OpenLDAP libs used for the build * Fixed #ifdef-statements for OPT_X_TLS_PROTOCOL_MIN Doc/ * Some updates and corrections regarding description of use of LDAPv3 controls * Some more descriptions for constants * Removed comments related to old LaTeX-based documentation system From lars at gustaebel.de Fri Feb 26 04:36:28 2010 From: lars at gustaebel.de (Lars =?iso-8859-1?Q?Gust=E4bel?=) Date: Fri, 26 Feb 2010 10:36:28 +0100 Subject: Why tarfile.TarFile.gzopen is not in the online documentation? In-Reply-To: References: <20100224101423.GA27668@axis.g33x.de> Message-ID: <20100226093627.GA21027@axis.g33x.de> On Fri, Feb 26, 2010 at 09:28:04AM +0100, Baptiste Lepilleur wrote: > 2010/2/24 Lars Gust?bel > > > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: > > > I stumbled uppon this and find it somewhat odd: some class methods of > > > TarFile and TarInfo do not appears in either the online documentation or > > > search while they have a doc string: > > > > > But to answer your question: Yes, this is intentional. The TarFile class > > has three classmethods taropen(), gzopen(), and bz2open() each for a > > specific compression method. These three are used internally by the > > TarFile.open() classmethod and are not intended to be called directly. The > > TarFile.open() method is the one that is publicly documented and supposed > > to be used. It decides which of the three methods to use based on the mode > > argument and does many more other high-level things as well. > > > > I think it would be best to annotate the help string to let people know of > the facts it is not intended for public usage (or restriction that apply, > e.g. only for subclassing as you hinted in another post). Well, then please take the time and open an issue at bugs.python.org, so that this won't get lost. I will then see what I can do. -- Lars Gust?bel lars at gustaebel.de Linux is like a wigwam - no Gates, no Windows, Apache inside. From tropea at centroserviziterritoriali.com Fri Feb 26 05:00:37 2010 From: tropea at centroserviziterritoriali.com (Ippolito Nievo) Date: Fri, 26 Feb 2010 02:00:37 -0800 (PST) Subject: modbus pymodbus Message-ID: <6a551b81-8085-4a32-a868-64bd869eda08@f8g2000yqn.googlegroups.com> Hi all, someone can help me to pymodbus use? I must send some command and read aswer from an inverter. It use ModBus RTU. Thanks a lot From prasad.chand at gmail.com Fri Feb 26 05:01:59 2010 From: prasad.chand at gmail.com (prasad_chand) Date: Fri, 26 Feb 2010 02:01:59 -0800 (PST) Subject: A more pythonish code References: Message-ID: Hi Mr.Posner & nn, Thank your for your time & effort. I never knew that for...ever combination even existed. I would keep these insights in mind in the future. Thanks again, Prasad On Feb 25, 10:57?pm, John Posner wrote: > On 2/25/2010 7:23 AM, prasad_chand wrote: > > > > > Hi, > > > I use python to do simple math problems as a hobby. > > > I have made a program that finds the number of divisors(factors) of a > > given number. I am hoping to improve my language skills, specifically > > I would like to re-write the function "prime_factors" more gracefully. > > While the program works right, I am hoping that I could get some input > > on how to write better python code. I have attached the code below. > > > def prime_factors(n): > > ? ? ?""" > > ? ? ?Reduce a number to its prime factors. e.g. 48 is 2^4,3^1 (add (4+1) > > (1+1) = 10) > > > ? ? ?Updates a global dictionary(my_dict) with prime numbers and number > > of occurances. In the case of 48 {2:4,3:1} > > > ? ? ?""" > > ? ? ?tmp_n = n > > A name meaning "temporary value of n" doesn't suggest how it's being > used in the algorithm. In my implementation (see below), I used the name > "last_result", which is (a little bit) better. > > > > > ? ? ?while True: > > > ? ? ? ? ?if tmp_n == 1: > > ? ? ? ? ? ? ?break > > > ? ? ? ? ?tmp_check = tmp_n > > > ? ? ? ? ?for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > > ? ? ? ? ? ? ?if tmp_n % x == 0: > > ? ? ? ? ? ? ? ? ?add_to_dict(x) > > This function changes the value of a global variable, *my_dict*. Using > global variables is frowned upon. In this case, it would be much better > to have the dictionary be local to the *prime_factor* function. After > you've broken out of the *while* loop, just execute "return my_dict". > > > ? ? ? ? ? ? ? ? ?tmp_n /= x > > ? ? ? ? ? ? ? ? ?break > > > ? ? ? ? ?if tmp_check == tmp_n: #number is prime...so just to add to > > dict > > ? ? ? ? ? ? ?add_to_dict(tmp_n) > > ? ? ? ? ? ? ?break > > The only reason that the *tmp_check* variable exists is to test whether > you fell out of the *for* loop without finding any divisors for *tmp_n*. > A cleaner approach is to use the optional *else* clause of the *for* > loop, which is executed only if you didn't *break* out of the loop: > > ? ? ?for x in range(2,int(ceil(sqrt(tmp_n)) + 1)): > ? ? ? ? ?if tmp_n % x == 0: > ? ? ? ? ? ? ?add_to_dict(x) > ? ? ? ? ? ? ?tmp_n /= x > ? ? ? ? ? ? ?break > ? ? ?else: > ? ? ? ? ?# tmp_n is prime...so just to add to dict > ? ? ? ? ?add_to_dict(tmp_n) > ? ? ? ? ?break > > > > > def add_one(x): > > ? ? ?return x+1 > > > def mul(x,y): > > ? ? ?return x * y > > > def add_to_dict(p_num): > > ? ? ?if my_dict.has_key(p_num): > > ? ? ? ? ?my_dict[p_num] += 1 > > ? ? ?else: > > ? ? ? ? ?my_dict[p_num] = 1 > > As poster pruebauno pointed out, using a collections.defaultdict > eliminates the need for the *add_to_dict* function. > > > > > my_dict = {} > > > prime_factors(135) > > l = map(add_one,my_dict.values()) > > print reduce(mul, l, 1) > > This may seem trivial, but ... don't use the single-character lowercase > "l" as a variable. It looks too much like the digit "1" -- in some > fonts, it looks identical! > > FWIW, here's my implementation. It's much slower, because it doesn't use > the square root optimization. It uses another optimization: when a prime > factor is located, *all* of its occurrences are factored out at the same > time. > > #-------------------------------- > from collections import defaultdict > > def prime_factors(n): > ? ? ?"""Return the prime factors of the given number (>= 2)""" > ? ? ?if n < 2: > ? ? ? ? ?print "arg must be >= 2" > ? ? ? ? ?return > > ? ? ?last_result = n > ? ? ?factors = defaultdict(int) > ? ? ?next_divisor = 2 > > ? ? ?while True: > ? ? ? ? ?while last_result % next_divisor == 0: > ? ? ? ? ? ? ?factors[next_divisor] += 1 > ? ? ? ? ? ? ?last_result /= next_divisor > ? ? ? ? ? ? ?if last_result == 1: > ? ? ? ? ? ? ? ? ?return factors > ? ? ? ? ?next_divisor += 1 > #-------------------------------- > > HTH, > John From zubin.mithra at gmail.com Fri Feb 26 05:15:53 2010 From: zubin.mithra at gmail.com (Zubin Mithra) Date: Fri, 26 Feb 2010 15:45:53 +0530 Subject: PyAutoRun Message-ID: <8e7c74321002260215lc68d617x12ed543563e6ad21@mail.gmail.com> Hello, I have been using python for quite some time; however this is the first python project i have worked on. The code is hosted at http://github.com/zubin71/PyAutoRun The code needs re-factoring and feature additions; i have put up a TODO list there too. It`d be great if anyone could work on this; i intend to develop this further(with a bit of help) and will request for its addition into debian and ubuntu repositories, in time. Also, any kind of code-review, criticism, is also appreciated. However, it`d be awesome if you could just fork it at github, pull, modify and push. :) Have a nice day! cheers!!! Zubin From jeanmichel at sequans.com Fri Feb 26 05:27:51 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 11:27:51 +0100 Subject: Get dosctring without import In-Reply-To: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <4B87A227.50100@sequans.com> Joan Miller wrote: > When a package is imported, it gets the dosctring to store it in > *__doc__*. > > Does that funcion is built in python? because I would want use it to > get the docstring without import a package > Epydoc, a documentation builder is able to do so with the --parse-only option. You could take a look at the code, even grab their parser to suit your needs. It may be quite difficult though. JM From ben+python at benfinney.id.au Fri Feb 26 05:51:05 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 26 Feb 2010 21:51:05 +1100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <87bpfc46ee.fsf@benfinney.id.au> Joan Miller writes: > When a package is imported, it gets the dosctring to store it in > *__doc__*. Joan, in this message and numerous others you've been following the widespread convention of using asterisks ?*? to surround text you want to emphasise. Normally that's good, but in a programming-language context (or any other where asterisks have a separate established meaning), it's not a good idea. In many cases, asterisks signify ?match any number of arbitrary characters at this position?, which gives a rather different meaning to what you're writing. You might be better off using quotes (like '__doc__' or ?__doc__?), or the reStructuredText syntax for demarcating a special element, backticks (like `__doc__`). Even they need to be used with care, though, because they also have specific established meanings (except the typographical quotes, which is why I use them). I hope that helps. > Does that funcion is built in python? because I would want use it to > get the docstring without import a package Why is it you want to do this? Modules should not have unwanted side effects when imported; if you can't import the module without invoking those unwanted side effects, the module is poorly written. That's not to say that such poorly-written modules don't exist. What is the situation? Perhaps there's a better solution. -- \ ?Earth gets its price for what Earth gives us.? ?James Russell | `\ Lowell | _o__) | Ben Finney From __peter__ at web.de Fri Feb 26 05:57:16 2010 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Feb 2010 11:57:16 +0100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: Joan Miller wrote: > When a package is imported, it gets the dosctring to store it in > *__doc__*. > > Does that funcion is built in python? because I would want use it to > get the docstring without import a package Something to get you started: import ast def walk(root, stack): for node in ast.iter_child_nodes(root): if isinstance(node, (ast.FunctionDef, ast.ClassDef)): yield node stack.append(node) for child in walk(node, stack): yield child del stack[-1] def get_name(node): try: return node.name except AttributeError: return "(%s)" % node.__class__.__name__ def get_path(path): return ".".join(get_name(node) for node in path) def find_docstrings(filename): with open(filename) as f: module = ast.parse(f.read()) print filename.center(len(filename) + 2).center(80, "=") print ast.get_docstring(module) print "=" * 80 print path = [] for node in walk(module, path): s = ast.get_docstring(node) if s is not None: name = get_path(path + [node]) print name.center(len(name) + 2).center(80, "-") print s print if __name__ == "__main__": import sys args = sys.argv[1:] if args: for arg in args: find_docstrings(arg) else: find_docstrings("/usr/lib/python2.6/unittest.py") assert "unittest" not in sys.modules To get an idea of the differences to the import-based approach try analysing the following script: import random if random.choice([True, False]): def f(): "say hello" else: def f(): "kill a kitten" def g(): "whatever" del g Peter From ldo at geek-central.gen.new_zealand Fri Feb 26 05:59:05 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Fri, 26 Feb 2010 23:59:05 +1300 Subject: Executable problem - socket? References: Message-ID: In message , Gib Bogle wrote: > The only clue is that the machines that her program runs on have > Python installed, while the one that fails doesn't. Wouldn?t it be a whole lot simpler to install Python on the bloody machine? From peloko45 at gmail.com Fri Feb 26 06:23:17 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 03:23:17 -0800 (PST) Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> Message-ID: <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> On 26 feb, 10:51, Ben Finney wrote: > Joan Miller writes: > > When a package is imported, it gets the dosctring to store it in > > *__doc__*. > > Joan, in this message and numerous others you've been following the > widespread convention of using asterisks ?*? to surround text you want > to emphasise. > > Normally that's good, but in a programming-language context (or any > other where asterisks have a separate established meaning), it's not a > good idea. In many cases, asterisks signify ?match any number of > arbitrary characters at this position?, which gives a rather different > meaning to what you're writing. > > You might be better off using quotes (like '__doc__' or ?__doc__?), or > the reStructuredText syntax for demarcating a special element, backticks > (like `__doc__`). Even they need to be used with care, though, because > they also have specific established meanings (except the typographical > quotes, which is why I use them). > > I hope that helps. > > > Does that funcion is built in python? because I would want use it to > > get the docstring without import a package > > Why is it you want to do this? Modules should not have unwanted side > effects when imported; if you can't import the module without invoking > those unwanted side effects, the module is poorly written. > > That's not to say that such poorly-written modules don't exist. What is > the situation? Perhaps there's a better solution. I use a function in 'setupy.py' to get automatically the description from the package's docstring, but there is a problem when you import a module that has to be built by cython (because it tries load a module that doesn't exists). From peloko45 at gmail.com Fri Feb 26 06:29:51 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 03:29:51 -0800 (PST) Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> Message-ID: <8889b428-7d1d-44fa-838e-27f2671e9263@y17g2000yqd.googlegroups.com> On 26 feb, 10:57, Peter Otten <__pete... at web.de> wrote: > Joan Miller wrote: > > When a package is imported, it gets the dosctring to store it in > > *__doc__*. > > > Does that funcion is built in python? because I would want use it to > > get the docstring without import a package > > Something to get you started: > > import ast > > def walk(root, stack): > ? ? for node in ast.iter_child_nodes(root): > ? ? ? ? if isinstance(node, (ast.FunctionDef, ast.ClassDef)): > ? ? ? ? ? ? yield node > ? ? ? ? stack.append(node) > ? ? ? ? for child in walk(node, stack): > ? ? ? ? ? ? yield child > ? ? ? ? del stack[-1] > > def get_name(node): > ? ? try: > ? ? ? ? return node.name > ? ? except AttributeError: > ? ? ? ? return "(%s)" % node.__class__.__name__ > > def get_path(path): > ? ? return ".".join(get_name(node) for node in path) > > def find_docstrings(filename): > ? ? with open(filename) as f: > ? ? ? ? module = ast.parse(f.read()) > ? ? print filename.center(len(filename) + 2).center(80, "=") > ? ? print ast.get_docstring(module) > ? ? print "=" * 80 > ? ? print > > ? ? path = [] > ? ? for node in walk(module, path): > ? ? ? ? s = ast.get_docstring(node) > ? ? ? ? if s is not None: > ? ? ? ? ? ? name = get_path(path + [node]) > ? ? ? ? ? ? print name.center(len(name) + 2).center(80, "-") > ? ? ? ? ? ? print s > ? ? ? ? ? ? print > > if __name__ == "__main__": > ? ? import sys > ? ? args = sys.argv[1:] > ? ? if args: > ? ? ? ? for arg in args: > ? ? ? ? ? ? find_docstrings(arg) > ? ? else: > ? ? ? ? find_docstrings("/usr/lib/python2.6/unittest.py") > ? ? ? ? assert "unittest" not in sys.modules > > To get an idea of the differences to the import-based approach try analysing > the following script: > > import random > > if random.choice([True, False]): > ? ? def f(): > ? ? ? ? "say hello" > else: > ? ? def f(): > ? ? ? ? "kill a kitten" > > def g(): > ? ? "whatever" > del g > > Peter Thanks! What I need there is: --------- with open(os.path.join(path, package, '__init__.py')) as f: module = ast.parse(f.read()) print ast.get_docstring(module) From sanelson at gmail.com Fri Feb 26 06:40:14 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Fri, 26 Feb 2010 03:40:14 -0800 (PST) Subject: [M2Crypto] Problems uploading to IIS using FTP over SSL Message-ID: <8383975f-8e86-4783-a69e-67f5acb6c058@e1g2000yqh.googlegroups.com> System: # rpm -q python m2crypto python-2.4.3-27.el5 m2crypto-0.16-6.el5.6 # cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga) I have the following method: def ftp_tarball(aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass): date = datetime.today().strftime(date_format) ftp = ftpslib.FTP_TLS() ftp.connect(ftp_server) ftp.auth_tls() ftp.set_pasv(0) ftp.login(ftp_user, ftp_pass) filename = aggregation_dir + 'zultys-logs_' + date + '.tar.gz' short_name = os.path.split(filename)[1] tarball = open(filename, 'rb') ftp.storbinary('STOR ' + short_name, tarball) tarball.close() ftp.quit() This works perfectly with VSFTPD on Linux, with SSL forced for non- anonymous users. I try to connect to a supplier's IIS FTP server, and get: Traceback (most recent call last): File "/usr/local/bin/lumberjack", line 45, in ? lumberjack.ftp_tarball( aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass ) File "/usr/lib64/python2.4/site-packages/lumberjack.py", line 93, in ftp_tarball ftp.storbinary('STOR ' + short_name, tarball) File "/usr/lib64/python2.4/ftplib.py", line 415, in storbinary conn = self.transfercmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 345, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "/usr/lib64/python2.4/site-packages/M2Crypto/ftpslib.py", line 86, in ntransfercmd conn, size = FTP.ntransfercmd(self, cmd, rest) File "/usr/lib64/python2.4/ftplib.py", line 331, in ntransfercmd sock = self.makeport() File "/usr/lib64/python2.4/ftplib.py", line 292, in makeport resp = self.sendport(host, port) File "/usr/lib64/python2.4/ftplib.py", line 256, in sendport return self.voidcmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib64/python2.4/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib64/python2.4/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 501 Server cannot accept argument. A colleague is able to connect using the Filezilla client, configured as servertype: FTPES - FTP over explicit TLS/SSL setting. I've not been able to find any further guidnance on the web. If you've experienced this before, or can see something that I've obviously got wrong, I'd appreciate your help. TIA, S. From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 06:43:20 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 00:43:20 +1300 Subject: PyQt 4.7 installation on Windows Message-ID: I've just installed Python 2.6.4 and PyQt 4.7 on my Windows machine, on which I was using Python 2.5 and PyQt 4.5. Now 'from PyQt4 import QtGui' fails to find the DLL. Some googling shows that others have encountered the same problem, and a workaround is to copy QtGui4.dll (for example) from D:\Python26\Lib\site-packages\PyQt4\bin to D:\Python26\Lib\site-packages\PyQt4 This is obviously not a solution, just a clue. Another clue is that the Python 2.5 installation didn't have the \bin subdirectory, instead all the DLLs were in PyQt4. It looks as if for 2.6 the DLLs have been moved but the search path hasn't been changed. sys.path includes D:\python26\lib\site-packages, and the Windows PATH environment variable includes D:\Python26\Lib\site-packages\PyQt4\bin For some reason I have a sense of deja vu. Can anyone help? From spamfresser at ch3ka.de Fri Feb 26 06:47:33 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Fri, 26 Feb 2010 12:47:33 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: Am 25.02.2010 17:39, schrieb Grant Edwards: > IMO, any sort of "commented out" code left in a program is a > big mistake. If the code is soething that does need to stay > for optional use, then it needs to be properly integrated along > with logic to control when it's used. OK, then we are perfectly fine and of course for personal use everyone can "comment out" code as they wish. I'd just hate to see something like "if False" in production level code. From spamfresser at ch3ka.de Fri Feb 26 06:52:13 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Fri, 26 Feb 2010 12:52:13 +0100 Subject: What's the word on using """ to comment-out? In-Reply-To: References: <87hbp5rboq.fsf@rudin.co.uk> Message-ID: Am 26.02.2010 12:47, schrieb Michael Rudolf: > I'd just hate to see something like "if False" in production level code. And yeah, I've seen it. And worse. From J.Fine at open.ac.uk Fri Feb 26 07:00:50 2010 From: J.Fine at open.ac.uk (Jonathan Fine) Date: Fri, 26 Feb 2010 12:00:50 +0000 Subject: WANTED: Regular expressions for breaking TeX/LaTeX document into tokens In-Reply-To: References: Message-ID: Wes James wrote: > On Wed, Feb 24, 2010 at 5:03 AM, Jonathan Fine wrote: >> Hi >> >> Does anyone know of a collection of regular expressions that will break a >> TeX/LaTeX document into tokens? Assume that there is no verbatim or other >> category code changes. > > I'm not sure how this does it, but it might help: > > http://plastex.sourceforge.net/plastex/sect0025.html Thanks, Wes. I'm already using PlasTeX It handles changes of category codes, which makes it over the top for what I want to do. In addition it is a fairly large complex application, and sadly it's not at all easy to use just a part of the code base. There's been more discussion of this thread on comp.text.tex (which is where I set the follow-up to). -- Jonathan From no-spam at non-existing.invalid Fri Feb 26 07:04:38 2010 From: no-spam at non-existing.invalid (Robert) Date: Fri, 26 Feb 2010 13:04:38 +0100 Subject: (and about tests) Re: Pedantic pickling error after reload? In-Reply-To: <7uo1aqFitnU1@mid.uni-berlin.de> References: <7uo1aqFitnU1@mid.uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > Am 25.02.10 18:08, schrieb Robert: >> After (intended/controlled) reload or similar action on a module/class >> the pickle/cPickle.dump raises errors like >> >> pickle.PicklingError: Can't pickle : it's >> not the same object as somemodule.SomeClass >> >> >> Cause in pickle.py (and cPickle) is a line >> "if klass is not obj:" >> >> Shouldn't it be enough to have "if klass.__name__ != obj.__name__:" >> there? > > No. This would alias classes of same name, but living in different modules. > > So at least you need to compare these, too. I'm not sure if there aren't at that point of comparison the module is already identical ("klass = getattr(mod, name)") > even more corner-cases. Python's import-mechanism can sometimes be > rather foot-shoot-prone. still don't see a real reason against the mere module+name comparison. same issues as during pickle.load. Just the class object is renewed (intentionally) If there are things with nested classes etc, the programmer will have to rethink things on a different level: design errors. a subject for pychecker/pylint - not for breaking pickle .dump ... ? > >> => a bug report/feature request? >> >> Classes can change face anyway during pickled state, why should a >> over-pedantic reaction break things here during runtime? >> (So far I'd need to walk the object tree in all facets and save against >> inf loops like pickle himself and re-class things .. ) > > If anything it's a feature - and I doubt it's really needed. Because > reloading pickles with intermittend reload-module-operations is to rare > a case to be really supported IMHO. well, reloading is the thing which I do most in coding practice :-) For me its a basic thing like cell proliferation in biology. In my projects particularly with GUI or with python based http serving, I typically support good live module reloadabily even actively by some extra little "reload support code" (which fixes up the .__class__ etc of living Windows tree, main objects, servers ... plus a ?xisinstance? in very few locations) - at least I do this for the frequently changing core modules/classes. This way I feel a edit-run cycle >2x faster when the project is getting bigger and bigger, or when developing things out interactively. Code is exchanged frequently while living objects stay for long ... works well in practice. Reentering into the same (complex) app state for evolving those thousands of small thing (where a full parallel test coverage doesn't work out) is a major dev time consuming factor in bigger projects - in C, Java projects and even with other dynamic languages. Dynamic classes are a main reason why I use Python (adopted from Lisp long time ago; is that reload thing here possible with Ruby too?) I typically need just 1 full app reboot on 20..50 edit-run-cycles I guess. And just few unit test runs per release. Even for Cython/pyximport things I added support for this reload edit-run-cycle, because I cannot imagine to dev without this. Just standard pickle issues stood in the way. And this patch (and a failover from cPickle to pickle) did well so far. > > Do yourself a favor, write a unit-test that tests the desired behavior > that makes you alter your code & then reload. This makes the problem go > away, and you have a more stable development through having more tests :) this is a comfortable quasi religious theory raised often and easily here and there - impracticable and very slow on that fine grained code evolution level however. an interesting issue. I do unit tests for getting stability on a much higher level where/when things and functionality are quite wired. Generally after having compared I cannot confirm that "write always tests before development" ideologies pay off in practice. "Reload > pychecker/pylint > tests" works most effectively with Python in my opinion. And for GUI-development the difference is max. (min for math algorithms which are well away from data structures/OO) Another issue regarding tests IMHO is, that one should not waste the "validation power" of unit tests too easily for permanent low level evolution purposes because its a little like bacteria becoming resistent against antibiotics: Code becoming 'fit' against artificial tests, but not against real word. For example in late stage NASA tests of rockets and like, there is a validation rule, that when those tests do not go through green, there is not just a fix of the (one) cause - screwing until it works. the whole thing is at stake. And the whole test scheme has to be rethought too. ideally, whenever such a late test brakes, it requires that a completely new higher test has to be invented (in addition) ... until there is a minimal set of "fresh green lights" which were red only during there own tests, but never red regarding the real test run. A rule that unit tests are used only near a release or a milestone is healthy in that sense I think. (And a quick edit-(real)run-interact cycle is good for speed) Robert From candide at free.invalid Fri Feb 26 07:29:04 2010 From: candide at free.invalid (candide) Date: Fri, 26 Feb 2010 13:29:04 +0100 Subject: Quoting quotes Message-ID: <4b87be91$0$29882$426a74cc@news.free.fr> Suppose you have to put into a Python string the following sentence : The play "All's Well That Ends Well" by Shakespeare It's easy do it : >>> print """The play "All's Well That Ends Well" by Shakespeare""" The play "All's Well That Ends Well" by Shakespeare Now, change the sentence to this one : The play "All's Well That Ends Well" Using triple single quotes works fine >>> print '''The play "All's Well That Ends Well"''' The play "All's Well That Ends Well" But the first method doesn't run correctly : >>> print """The play "All's Well That Ends Well"""" File "", line 1 print """The play "All's Well That Ends Well"""" ^ SyntaxError: EOL while scanning single-quoted string >>> Any comment ? From victor.stinner at haypocalc.com Fri Feb 26 07:29:33 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 13:29:33 +0100 Subject: Challenge: escape from the pysandbox Message-ID: <201002261329.33740.victor.stinner@haypocalc.com> Hi, pysandbox is a new Python sandbox project under development. By default, untrusted code executed in the sandbox cannot modify the environment (write a file, use print or import a module). But you can configure the sandbox to choose exactly which features are allowed or not, eg. import sys module and read the file /etc/issue. I think that the project reached the "testable" stage. I launch a new challenge: try to escape from the sandbox. I'm unable to write strict rules. The goal is to access objects outside the sandbox. Eg. write into a file, import a module which is not in the whitelist, modify an object outside the sandbox, etc. To test the sandbox, you have 3 choices: - interpreter.py: interactive interpreter executed in the sandbox, use: --verbose to display the whole sandbox configuration, --features=help to enable help() function, --features=regex to enable regex, --help to display the help. - execfile.py : execute your script in the sandbox. It has also --features option: use --features=stdout to be able to use the print instruction :-) - use directly the Sandbox class: use methods call(), execute() or createCallback() Don't use "with sandbox: ..." because there is known but with local frame variables. I think that I will later drop this syntax because of this bug. Except of debug_sandbox, I consider that all features are safe and so you can enable all features :-) There is no prize, it's just for fun! But I will add the name of hackers founding the best exploits. pysandbox is not ready for production, it's under heavy development. Anyway I *hope* that you will quickly find bugs! -- Use tests.py to found some examples of how you can escape a sandbox. pysandbox is protected against all methods described in tests.py ;-) See the README file to get more information about how pysandbox is implemented and get a list of other Python sandboxes. pysandbox is currently specific to CPython, and it uses some ugly hacks to patch CPython in memory. In the worst case it will crash the pysandbox Python process, that's all. I tested it under Linux with Python 2.5 and 2.6. The portage to Python3 is not done yet (is someone motivated to write a patch? :-)). -- Victor Stinner http://www.haypocalc.com/ From victor.stinner at haypocalc.com Fri Feb 26 07:35:02 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 13:35:02 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002261329.33740.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> Message-ID: <201002261335.02933.victor.stinner@haypocalc.com> Le vendredi 26 f?vrier 2010 13:29:33, Victor Stinner a ?crit : > pysandbox is a new Python sandbox project ... I just forget to explain how to download it. Website: http://github.com/haypo/pysandbox/ Download the repository using git: git clone git://github.com/haypo/pysandbox.git or git clone http://github.com/haypo/pysandbox.git Or download the .zip or .tar.gz tarball using the "Download source" button on the website. -- Victor Stinner http://www.haypocalc.com/ From ben+python at benfinney.id.au Fri Feb 26 07:35:30 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 26 Feb 2010 23:35:30 +1100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> Message-ID: <87635k41kd.fsf@benfinney.id.au> Joan Miller writes: > I use a function in 'setupy.py' to get automatically the description > from the package's docstring, but there is a problem when you import a > module that has to be built by cython (because it tries load a module > that doesn't exists). A simple approach (at least, simpler than crawling a parse tree) might be to store the package description in a separate non-executable file. A common convention is to have a ?README? text file, written in reStructuredText for rendering to various output formats as part of the documentation. You could then have the ?setup.py? program read the contents of that file and use it (or a slice of it) for the package description. -- \ ?Sometimes I ? no, I don't.? ?Steven Wright | `\ | _o__) | Ben Finney From ivan.python1 at gmail.com Fri Feb 26 07:37:10 2010 From: ivan.python1 at gmail.com (=?windows-1252?Q?Ivan_=8Aipo=9A?=) Date: Fri, 26 Feb 2010 13:37:10 +0100 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <4B87C076.104@gmail.com> On 26.2.2010. 13:29, candide wrote: > Suppose you have to put into a Python string the following sentence : > > The play "All's Well That Ends Well" by Shakespeare > > It's easy do it : > > >>>> print """The play "All's Well That Ends Well" by Shakespeare""" >>>> > The play "All's Well That Ends Well" by Shakespeare > > Now, change the sentence to this one : > > The play "All's Well That Ends Well" > > Using triple single quotes works fine > > >>>> print '''The play "All's Well That Ends Well"''' >>>> > The play "All's Well That Ends Well" > > > But the first method doesn't run correctly : > > > >>>> print """The play "All's Well That Ends Well"""" >>>> > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string > >>>> > > Any comment ? > > > Well, there's no such thing as """" defined in python. From usenot at geekmail.INVALID Fri Feb 26 07:42:27 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 26 Feb 2010 13:42:27 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <20100226134227.10c94afe@geekmail.INVALID> On Thu, 25 Feb 2010 12:51:00 -0800 (PST) John Roth wrote: > On Feb 24, 1:23?pm, Andreas Waldenburger > wrote: > > a company that works with my company writes a lot of of their code > > in Python (lucky jerks). I've seen their code and it basically > > looks like this: > > > > """Function that does stuff""" > > def doStuff(): > > ? ? while not wise(up): > > ? ? ? ? yield scorn > > [snip] > Is the problem that they've got the docstring in the wrong place, > or that the comment isn't saying anything that can't be read in > the method name? > It's the first. I am superficial like that. I just needed a docstring to illustrate and didn't want to get overly creative. Not that they don't write redundant docstrings. And they use mixedCase function/method names. And they write getters and setters gratuitously. > The first is easily fixable with a bit of tutorial about how > a properly placed docstring prints out in various contexts, plus > a quick script to move the suckers. > Well, I'm not really in a position to tell them that. I'd be kind of the dork of the office in doing so. Thus my kvetching here. :) So basically, there is nothing to discuss, really. I just wanted to remind everyone that there are still morons out there (as in "lacking esprit and mental flexibility"), make everyone feel better about themselves (because surely THEY don't do that!) and then carry on. > The second is going to take more work to get the point across > that comments that reproduce what the method name says are waste. > They seem to need the reassurance, I guess, so why not let them. ;) /W -- INVALID? DE! From victor.stinner at haypocalc.com Fri Feb 26 07:42:46 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 13:42:46 +0100 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <201002261342.47003.victor.stinner@haypocalc.com> Le vendredi 26 f?vrier 2010 13:29:04, candide a ?crit : > But the first method doesn't run correctly : > >>> print """The play "All's Well That Ends Well"""" > > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string Use triple simple single quotes: >>> print '''"All's Well That Ends Well"''' "All's Well That Ends Well" -- Victor Stinner http://www.haypocalc.com/ From peloko45 at gmail.com Fri Feb 26 08:02:53 2010 From: peloko45 at gmail.com (Joan Miller) Date: Fri, 26 Feb 2010 05:02:53 -0800 (PST) Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> <87635k41kd.fsf@benfinney.id.au> Message-ID: <8777b981-6ca8-49b2-93d8-4b37b2f99b79@k17g2000yqb.googlegroups.com> On 26 feb, 12:35, Ben Finney wrote: > Joan Miller writes: > > I use a function in 'setupy.py' to get automatically the description > > from the package's docstring, but there is a problem when you import a > > module that has to be built by cython (because it tries load a module > > that doesn't exists). > > A simple approach (at least, simpler than crawling a parse tree) might > be to store the package description in a separate non-executable file. > > A common convention is to have a ?README? text file, written in > reStructuredText for rendering to various output formats as part of the > documentation. You could then have the ?setup.py? program read the > contents of that file and use it (or a slice of it) for the package > description. I get the 'README.txt' file to get the long description but I use the docstring because each package should include a short desciption about it. From benjamin.kaplan at case.edu Fri Feb 26 08:43:43 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 26 Feb 2010 08:43:43 -0500 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: On Fri, Feb 26, 2010 at 7:29 AM, candide wrote: > Suppose you have to put into a Python string the following sentence : > > The play "All's Well That Ends Well" by Shakespeare > > It's easy do it : > > >>> print """The play "All's Well That Ends Well" by Shakespeare""" > The play "All's Well That Ends Well" by Shakespeare > > Now, change the sentence to this one : > > The play "All's Well That Ends Well" > > Using triple single quotes works fine > > >>> print '''The play "All's Well That Ends Well"''' > The play "All's Well That Ends Well" > > > But the first method doesn't run correctly : > > > >>> print """The play "All's Well That Ends Well"""" > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string > >>> > > > Any comment ? > > > You have 4 quotes at the end of the line instead of 3. So the first 3 close the long quote and then the 4th opens a new quote which doesn't get closed. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From deets at nospam.web.de Fri Feb 26 08:56:56 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 14:56:56 +0100 Subject: (and about tests) Re: Pedantic pickling error after reload? In-Reply-To: References: <7uo1aqFitnU1@mid.uni-berlin.de> Message-ID: <7uq299FrmfU1@mid.uni-berlin.de> > at that point of comparison the module is already identical ("klass = > getattr(mod, name)") Ah, didn't know that context. >> even more corner-cases. Python's import-mechanism can sometimes be >> rather foot-shoot-prone. > > still don't see a real reason against the mere module+name comparison. > same issues as during pickle.load. Just the class object is renewed > (intentionally) > > If there are things with nested classes etc, the programmer will have to > rethink things on a different level: design errors. a subject for > pychecker/pylint - not for breaking pickle .dump ... ? I don't say it necessarily breaks anything. I simply don't know enough about it. It might just be that back then, identity was deemed enough to check, but you can well argue your case on the python-dev list, providing a patch + tests that ensure there is no regression. > well, reloading is the thing which I do most in coding practice :-) > For me its a basic thing like cell proliferation in biology. I simply never do it. It has subtle issues, one of them you found, others you say you work around by introducing actual frameworks. But you might well forget some corner-cases & suddently chase a chimera you deem a bug, that in fact is just an unwanted side-effect of reloading. And all this extra complexity is only good for the process of actually changing the code. It doesn't help you maintaining code quality. > Reentering into the same (complex) app state for evolving those > thousands of small thing (where a full parallel test coverage doesn't > work out) is a major dev time consuming factor in bigger projects - in > C, Java projects and even with other dynamic languages. > Dynamic classes are a main reason why I use Python (adopted from Lisp > long time ago; is that reload thing here possible with Ruby too?) So what? If this kind of complex, through rather lengthy interactions evolved state is the thing you need to work within, that's reason enough for me to think about how to automate setting this very state up. That's what programming is about - telling a computer to do things it can do, which usually means it does them *much* faster & *much* more reliable than humans do. Frankly, I can't be bothered with clicking through layers of GUIs to finally reach the destination I'm actually interested in. Let the computer do that. And once I teached him how so, I just integrate that into my test-suite. > I typically need just 1 full app reboot on 20..50 edit-run-cycles I > guess. And just few unit test runs per release. Even for > Cython/pyximport things I added support for this reload edit-run-cycle, > because I cannot imagine to dev without this. Let me assure you - it works :) for example yesterday, I create a full CRUD-interface for a web-app (which is the thing I work on mostly these days) without *once* taking a look at the browser. I wrote actions, forms, HTML, and tests along, developed the thing ready, asserted certain constraints and error-cases, and once finished, fired up the browser - and he saw, it worked! Yes, I could have written that code on the fly, hitting F5 every few seconds/minutes to see if things work out (instead of just running the specific tests through nose) - and once I'd be finished, I didn't have anything permanent that ensured the functionality over time. > this is a comfortable quasi religious theory raised often and easily > here and there - impracticable and very slow on that fine grained code > evolution level however. an interesting issue. To me, that's as much as an religious statement often heard by people that aren't (really) into test-driven development. By which I personally don't mean the variant where one writes tests first, and then code. I always develop both in lock-step, sometimes introducing a new feauter first in my test as e.g. new arguments, or new calls, and then implementing them, but as often the other way round. The argument is always a variation of "my problem is to complicated, the code-base to interviened to make it possible to test this". I call this a bluff. You might work with a code-base that makes it harder than needed to write tests for new functionality. But then, most of the time this is a sign of lack of design. Writing with testability in mind makes you think twice about how to proper componentize your application, clearly separate logic from presentation, validates API-design because using the API is immediatly done when writing the tests you need, and so forth. > > I do unit tests for getting stability on a much higher level where/when > things and functionality are quite wired. > Generally after having compared I cannot confirm that "write always > tests before development" ideologies pay off in practice. > "Reload > pychecker/pylint > tests" works most effectively with Python > in my opinion. > And for GUI-development the difference is max. > (min for math algorithms which are well away from data structures/OO) As I said, I mainly do web these days. Which can be considered GUIs as well. Testing the HTTP-interface is obviously easier & possible, and what I described earlier. But we also use selenium to test JS-driven interfaces, as now the complexity of the interface rises, with all the bells & whistles of ajaxiness and whatnot. > Another issue regarding tests IMHO is, that one should not waste the > "validation power" of unit tests too easily for permanent low level > evolution purposes because its a little like bacteria becoming resistent > against antibiotics: Code becoming 'fit' against artificial tests, but > not against real word. That's why I pull in the real world as well. I don't write unit-tests only (in fact, I don't particularily like that term, because of it's narrow-minded-ness), I write tests for whatever condition I envision *or* encounter. If anything that makes my systems fail is reproducable, it becomes a new test - and ensures this thing isn't ever happening again. Granted, though: there are things you can't really test, especially in cases where you interact with different other agents that might behave (to you) erratically. I've done robot developent as well, and of course testing e.g. an acceleration ramp dependend on ground conditions isn't something a simple unit-test can reproduce. but then... I've written some, and made sure the robot was in a controlled environment when executing them :) All in all, this argument is *much* to often used as excuse to simply not go to any possible length to make your system testable as far as it possibly can be. And in my experience, that's further than most people think. And as a consequence, quality & stability as well as design of the application suffer. > A rule that unit tests are used only near a release or a milestone is > healthy in that sense I think. > (And a quick edit-(real)run-interact cycle is good for speed) Nope, not in my opinion. Making tests an afterthought may well lead to them being written carelessly, not capturing corner-cases you encountered while actually developing, and I don't even buy the speed argument, as I already said - most of the times, the computer is faster than you setting up the environment for testing, how complex ever that may be. Testing is no silver bullet. But it's a rather mighte sword.. :) Diez From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 09:04:35 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 26 Feb 2010 14:04:35 GMT Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <4b87d4f3$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 13:29:04 +0100, candide wrote: > But the first method doesn't run correctly : > > >>>> print """The play "All's Well That Ends Well"""" > File "", line 1 > print """The play "All's Well That Ends Well"""" > ^ > SyntaxError: EOL while scanning single-quoted string >>>> >>>> > > Any comment ? Of course not. Quotes can't be nested, so the first time the parser hits three quote marks, you have reached the end of the string. You then open a new string with a single quote mark, and then fail to close it. Hence the EOL while scanning a single-quoted string. There are many solutions. Here are four: >>> print """The play "All's Well That Ends Well\"""" The play "All's Well That Ends Well" >>> print '''The play "All's Well That Ends Well"''' The play "All's Well That Ends Well" >>> print 'The play "All\'s Well That Ends Well"' The play "All's Well That Ends Well" >>> print 'The play "All' "'" 's Well That Ends Well"' The play "All's Well That Ends Well" -- Steven From sanelson at gmail.com Fri Feb 26 09:05:18 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Fri, 26 Feb 2010 14:05:18 +0000 Subject: [M2Crypto] Problems uploading to IIS using FTP over SSL Message-ID: Hello, System: # rpm -q python m2crypto python-2.4.3-27.el5 m2crypto-0.16-6.el5.6 # cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga) I have the following method: def ftp_tarball(aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass): date = datetime.today().strftime(date_format) ftp = ftpslib.FTP_TLS() ftp.connect(ftp_server) ftp.auth_tls() ftp.set_pasv(0) ftp.login(ftp_user, ftp_pass) filename = aggregation_dir + 'zultys-logs_' + date + '.tar.gz' short_name = os.path.split(filename)[1] tarball = open(filename, 'rb') ftp.storbinary('STOR ' + short_name, tarball) tarball.close() ftp.quit() This works perfectly with VSFTPD on Linux, with SSL forced for non- anonymous users. I try to connect to a supplier's IIS FTP server, and get: Traceback (most recent call last): File "/usr/local/bin/lumberjack", line 45, in ? lumberjack.ftp_tarball( aggregation_dir, date_format, ftp_server, ftp_user, ftp_pass ) File "/usr/lib64/python2.4/site-packages/lumberjack.py", line 93, in ftp_tarball ftp.storbinary('STOR ' + short_name, tarball) File "/usr/lib64/python2.4/ftplib.py", line 415, in storbinary conn = self.transfercmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 345, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "/usr/lib64/python2.4/site-packages/M2Crypto/ftpslib.py", line 86, in ntransfercmd conn, size = FTP.ntransfercmd(self, cmd, rest) File "/usr/lib64/python2.4/ftplib.py", line 331, in ntransfercmd sock = self.makeport() File "/usr/lib64/python2.4/ftplib.py", line 292, in makeport resp = self.sendport(host, port) File "/usr/lib64/python2.4/ftplib.py", line 256, in sendport return self.voidcmd(cmd) File "/usr/lib64/python2.4/ftplib.py", line 246, in voidcmd return self.voidresp() File "/usr/lib64/python2.4/ftplib.py", line 221, in voidresp resp = self.getresp() File "/usr/lib64/python2.4/ftplib.py", line 216, in getresp raise error_perm, resp ftplib.error_perm: 501 Server cannot accept argument. A colleague is able to connect using the Filezilla client, configured as servertype: FTPES - FTP over explicit TLS/SSL setting. I've not been able to find any further guidance on the web. If you've experienced this before, or can see something that I've obviously got wrong, I'd appreciate your help. TIA, S. From edreamleo at gmail.com Fri Feb 26 09:15:26 2010 From: edreamleo at gmail.com (Edward K Ream) Date: Fri, 26 Feb 2010 08:15:26 -0600 Subject: ANN: Leo 4.7.1 released Message-ID: Leo 4.7.1 final is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106 Leo 4.7.1 fixes a dangerous bug in Leo 4.7. When converting file-like sentinels to thin-like sentinels in an external file, Leo now issues a warning and sets the corresponding @file node dirty. This ensures that Leo will write the converted external file and .leo file together, making it impossible to lose data. Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html The highlights of Leo 4.7: -------------------------- - Leo now uses the simplest possible internal data model. This is the so-called "one-node" world. - Leo supports Python 3.x. - Leo requires Python 2.6 or above. - Several important improvements in file handling. - Leo converts @file nodes to @thin nodes automatically. - Leo creates a 'Recovered Nodes' node to hold data that otherwise might be lost due to clone conflicts. - @auto-rst now works much more reliably reliably. - Leo no longer supports @noref trees. Such trees are not reliable in cooperative environments. - A new Windows installer. - Many other features, including new command line options and new plugins. - Dozens of bug fixes. Links: ------ Leo: http://webpages.charter.net/edreamleo/front.html Forum: http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html From rdv at roalddevries.nl Fri Feb 26 09:22:19 2010 From: rdv at roalddevries.nl (Roald de Vries) Date: Fri, 26 Feb 2010 15:22:19 +0100 Subject: Renaming identifiers & debugging In-Reply-To: <7uog65F5vuU1@mid.individual.net> References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uog65F5vuU1@mid.individual.net> Message-ID: Hi Luca, On Feb 26, 2010, at 12:41 AM, Luca wrote: > MRAB wrote: >> Perhaps you could use a different extension, eg ".pyn", so existing >> ".py" files are handled as-is but ".pyn" files are read through a >> translator. > > This could be a good idea... especially since i could make my own > extension since we are talking of a special-purpose application that > only incorporates python as a library. I would suggest to do choose the same strategy as 'from __future__ import ...' takes, which does similar things and limits them to the module it is used in. I would be curious to hear about your results. Kind regards, Roald From gslindstrom at gmail.com Fri Feb 26 09:23:54 2010 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Fri, 26 Feb 2010 08:23:54 -0600 Subject: PyCon 2011 - Call for Tutorial Volunteers Message-ID: PyCon 2010 is complete and plans for PyCon 2011 in Atlanta have already begun! The main conference will once again be proceeded by two days of tutorials. There was quite a bit of feedback from students and teachers this year that we want to incorporate in next years classes. In order to do this, more people need to get involved; why not you? You do not need to have any experience in organizing a national conference, just the desire to help out. There is plenty to do from tasks that take a couple of hours to others that span months and you will get help with everything. The areas we will be working on are: * Proposals - help with the call for tutorial proposals and selection of classes * Room Assignments - help get the selected tutorials assigned to classrooms and monitor attendance numbers * Notes - work with teachers to get class notes printed and distributed * Program Guide - work with conference organizers to get tutorial information in the conference guide * Feedback - Work to get meaningful feedback from students and teachers (so PyCon 2012 is even better!) * Payments - collect information so our teachers get paid * Runner - On tutorial days at the conference, make yourself available to do whatever needs to be done. It's a lot of work -- and a lot of fun-- to put on tutorials for PyCon each year. You won't get paid, but you will get one of the snappy "staff" tee shirts when you attend PyCon and you get to work with an incredibly dedicated group of volunteers. Interested? Please drop a note at pycon-tutorials at python.org and let us know. Thanks, Greg Lindstrom Tutorial Coordinator, PyCon 2011 (Atlanta) -------------- next part -------------- An HTML attachment was scrubbed... URL: From fetchinson at googlemail.com Fri Feb 26 09:37:43 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Fri, 26 Feb 2010 15:37:43 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002261335.02933.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261335.02933.victor.stinner@haypocalc.com> Message-ID: >> pysandbox is a new Python sandbox project Out of curiosity, the python sandbox behind google app engine is open source? If so, how is it different from your project, if not, anyone knows if it will be in the future? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From python at bdurham.com Fri Feb 26 09:50:08 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 26 Feb 2010 09:50:08 -0500 Subject: Possible to import from a cStringIO file object vs. file on disk? Message-ID: <1267195808.16415.1362063523@webmail.messagingengine.com> Is it possible to import from a cStringIO file object (containing compiled byte code) vs. a physical file on disk? I'm thinking that this is possible, given Python's ability to import from zip files, but I'm not sure where to look next. Thank you, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeanmichel at sequans.com Fri Feb 26 09:50:25 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 15:50:25 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100226134227.10c94afe@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100226134227.10c94afe@geekmail.INVALID> Message-ID: <4B87DFB1.1080201@sequans.com> Andreas Waldenburger wrote: > On Thu, 25 Feb 2010 12:51:00 -0800 (PST) John Roth > wrote: > > >> On Feb 24, 1:23 pm, Andreas Waldenburger >> wrote: >> >>> a company that works with my company writes a lot of of their code >>> in Python (lucky jerks). I've seen their code and it basically >>> looks like this: >>> >>> """Function that does stuff""" >>> def doStuff(): >>> while not wise(up): >>> yield scorn >>> [snip] >>> >> Is the problem that they've got the docstring in the wrong place, >> or that the comment isn't saying anything that can't be read in >> the method name? >> >> > It's the first. I am superficial like that. I just needed a docstring > to illustrate and didn't want to get overly creative. > > Not that they don't write redundant docstrings. > > And they use mixedCase function/method names. > and ? whatIsTheProblem ? PEP8 is one style guide, not *the* style guide. There is neither technical nor readability issue with mixedCase, classes in PEP 8 using MixedCase. The thing is they had to chose one preference for the methods and they choose lower_case. Fine, but it's still a matter of preference (or arbitrary decision). Since you don't write code for the standard library, you can use any other naming convention. You've may have guessed it, I am using mixedCase method names, and I tell you, you cannot compare this in any way with their dumb usage of doctrings you've shown above. That being said, yoru OP's still soemhow funny, I would have shot them on sight :-) JM From invalid at invalid.invalid Fri Feb 26 10:04:04 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 26 Feb 2010 15:04:04 +0000 (UTC) Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> <4b87d4f3$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-26, Steven D'Aprano wrote: > On Fri, 26 Feb 2010 13:29:04 +0100, candide wrote: > >> But the first method doesn't run correctly : >> >> >>>>> print """The play "All's Well That Ends Well"""" >> File "", line 1 >> print """The play "All's Well That Ends Well"""" >> ^ >> SyntaxError: EOL while scanning single-quoted string >>>>> >>>>> >> >> Any comment ? > > Of course not. Quotes can't be nested, so the first time the > parser hits three quote marks, you have reached the end of the > string. You then open a new string with a single quote mark, > and then fail to close it. Hence the EOL while scanning a > single-quoted string. IMO, the error message is misleading to many people, since in many/most contexts the term "single-quoted" refers to this: 'here is a single quoted string' And not this: "this is a double-quoted string" -- Grant Edwards grante Yow! And then we could sit at on the hoods of cars at visi.com stop lights! From victor.stinner at haypocalc.com Fri Feb 26 10:04:57 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Fri, 26 Feb 2010 16:04:57 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261335.02933.victor.stinner@haypocalc.com> Message-ID: <201002261604.57625.victor.stinner@haypocalc.com> Le vendredi 26 f?vrier 2010 15:37:43, Daniel Fetchinson a ?crit : > >> pysandbox is a new Python sandbox project > > Out of curiosity, the python sandbox behind google app engine is open > source? If so, how is it different from your project, if not, anyone knows > if it will be in the future? I don't know this project. Do you have the URL of the project home page? Is it the "safelite.py" project? -- Victor Stinner http://www.haypocalc.com/ From tundra at tundraware.com Fri Feb 26 10:09:36 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 26 Feb 2010 09:09:36 -0600 Subject: Docstrings considered too complicated In-Reply-To: <20100224212303.242222c6@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > while not wise(up): > yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? > > /W > Reminiscent of: mov AX,BX ; Move the contents of BX into AX And, yes, I've actually seen that as well as: ; This is a comment -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From darnzen at gmail.com Fri Feb 26 10:32:48 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:32:48 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> Message-ID: <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> On Feb 26, 3:15?am, "Diez B. Roggisch" wrote: > Am 26.02.10 06:07, schrieb darnzen: > > > > > > > Having an odd problem that I solved, but wondering if its the best > > solution (seems like a bit of a hack). > > > First off, I'm using an external DLL that requires static callbacks, > > but because of this, I'm losing instance info. It could be import > > related? It will make more sense after I diagram it: > > > #Module main.py > > from A import * > > > class App: > > ? ? ?def sperg(self): > > ? ? ? ? ? self.a = A() > > > app = App() > > [main loop and such] > > ? ----------------------------- > > # Module A.py > > import main > > class Foo: > > ? ? ? ?Selves=[] > > ? ? ? def __init__(self): > > ? ? ? ? ? ? ? ? Foo.Selves.append(self) > > ? ? ? @staticmethod > > ? ? ? def chum_callback(nType, nP): > > ? ? ? ? ? ? ? ? # Need to access function / data in app instance > > ? ? ? ? ? ? ? ? app.sperg(nP) > > ? ? ? ? ? ? ? ? # Need to access func data in Foo > > ? ? ? ? ? ? ? ? # I'm pulling 'self' ouf of list made in constructor > > ? ? ? ? ? ? ? ? self = Foo.getSelf(nP) > > > ? ? ? def getSelf(nP): > > ? ? ? ? ? ? ? ? return self.Selves[nP] > > > --------------------------------------------------------------------- > > So basically I added a list of instances to the base class so I can > > get at them from the staticmethod. > > What's bothering me the most is I can't use the global app instance in > > the A.py module. > > > How can I get at the app instance (currently I'm storing that along > > with the class instance in the constructor)? > > Is there another way to do this that's not such a hack? > > > Sorry for the double / partial post :( > > Can you show how you pass the staticmethod to the C-function? Is the DLL > utilized by ctypes? > > I don't see any reason you couldn't use a bound method, which would give > you your self, instead relying on global state. > > Diez __main__.K << *facepalm* should of tried that! Yeah I'm using ctypes. The DLL callback set ups are as follows. The local callback is in the App namespace (in this case, some callbacks are in different modules as noted in OP), but still no access to self: #Function wrapper A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ POINTER(Data_s))(A.Callback) #DLL call to register the local callback function DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) class A: #Local callback function @staticmethod def Callback(hID, SubID, Data): print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' print 'USING KEY GENERATED FROM hID, SubID' pass I'm not sure why they need to be static callbacks, but the DLL doc's say "when using object based languages, such as c++, callback functions must be declared as static functions and not instance methods", and I couldn't get it to work without setting it up that way. I could probably have them all be "classless" functions, but with 100's of these, my namespace would be polluted up the wazoo, and I'd still have the problem that they wouldn't have access to instance methods / properties. From deets at nospam.web.de Fri Feb 26 10:41:27 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 16:41:27 +0100 Subject: staticmethod and namespaces In-Reply-To: <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> Message-ID: <7uq8d7FvifU1@mid.uni-berlin.de> Am 26.02.10 16:32, schrieb darnzen: > On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: >> Am 26.02.10 06:07, schrieb darnzen: >> >> >> >> >> >>> Having an odd problem that I solved, but wondering if its the best >>> solution (seems like a bit of a hack). >> >>> First off, I'm using an external DLL that requires static callbacks, >>> but because of this, I'm losing instance info. It could be import >>> related? It will make more sense after I diagram it: >> >>> #Module main.py >>> from A import * >> >>> class App: >>> def sperg(self): >>> self.a = A() >> >>> app = App() >>> [main loop and such] >>> ----------------------------- >>> # Module A.py >>> import main >>> class Foo: >>> Selves=[] >>> def __init__(self): >>> Foo.Selves.append(self) >>> @staticmethod >>> def chum_callback(nType, nP): >>> # Need to access function / data in app instance >>> app.sperg(nP) >>> # Need to access func data in Foo >>> # I'm pulling 'self' ouf of list made in constructor >>> self = Foo.getSelf(nP) >> >>> def getSelf(nP): >>> return self.Selves[nP] >> >>> --------------------------------------------------------------------- >>> So basically I added a list of instances to the base class so I can >>> get at them from the staticmethod. >>> What's bothering me the most is I can't use the global app instance in >>> the A.py module. >> >>> How can I get at the app instance (currently I'm storing that along >>> with the class instance in the constructor)? >>> Is there another way to do this that's not such a hack? >> >>> Sorry for the double / partial post :( >> >> Can you show how you pass the staticmethod to the C-function? Is the DLL >> utilized by ctypes? >> >> I don't see any reason you couldn't use a bound method, which would give >> you your self, instead relying on global state. >> >> Diez > > __main__.K<< *facepalm* should of tried that! > > Yeah I'm using ctypes. The DLL callback set ups are as follows. The > local callback is in the App namespace (in this case, some callbacks > are in different modules as noted in OP), but still no access to self: > > #Function wrapper > A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ > POINTER(Data_s))(A.Callback) > > #DLL call to register the local callback function > DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > class A: > #Local callback function > @staticmethod > def Callback(hID, SubID, Data): > print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > print 'USING KEY GENERATED FROM hID, SubID' > pass > > I'm not sure why they need to be static callbacks, but the DLL doc's > say "when using object based languages, such as c++, callback > functions must be declared as static functions and not instance > methods", and I couldn't get it to work without setting it up that > way. I could probably have them all be "classless" functions, but with > 100's of these, my namespace would be polluted up the wazoo, and I'd > still have the problem that they wouldn't have access to instance > methods / properties. The above code can't work with self, because you use A.expCallback which at best can of course be a classmethod. You need to instead invoke DLLSetCallback with a bound method, like this a = A() DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of static functions is differently. If ctypes manages to get *some* callback passed, I'm 100% positive that it can pass *any* callable you like, including bound methods. Diez From darnzen at gmail.com Fri Feb 26 10:42:32 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:42:32 -0800 (PST) Subject: staticmethod and namespaces References: <4b877470$0$27844$c3e8da3@news.astraweb.com> Message-ID: On Feb 26, 1:12?am, Steven D'Aprano wrote: > On Thu, 25 Feb 2010 21:07:55 -0800, darnzen wrote: > > Having an odd problem that I solved, but wondering if its the best > > solution (seems like a bit of a hack). > > > First off, I'm using an external DLL that requires static callbacks, but > > because of this, I'm losing instance info. > [...] > > How can I get at the app instance (currently I'm storing that along with > > the class instance in the constructor)? Is there another way to do this > > that's not such a hack? > > Pass the instance explicitly: > > >>> class K(object): > > ... ? ? @staticmethod > ... ? ? def static(self, x, y): > ... ? ? ? ? print self, x, y > ...>>> k = K() > >>> k.static(k, 1, 2) > > <__main__.K object at 0xb7c2544c> 1 2 > > -- > Steven Unfortunately, since the callback is from the DLL which I didn't write, I can not change what is passed to the function. Also, the DLL has no idea about my local namespace. The DLL typically will pass back two integers (which I can set the values of when I register the callback), and some data. Currently Im' using these integers as keys in a local dict where I'm storing the instances. I suppose I could use the integers to store the high and low order bytes of a pointer to the instance, but not sure how to do that in Python (would be easy in c/c++). Also, I'm not sure how python memory management works, if it will move objects around and make things buggy. Also, that is definitely a hack and isn't very 'pythonesque' From darnzen at gmail.com Fri Feb 26 10:47:10 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:47:10 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> Message-ID: On Feb 26, 9:41?am, "Diez B. Roggisch" wrote: > Am 26.02.10 16:32, schrieb darnzen: > > > > > > > On Feb 26, 3:15 am, "Diez B. Roggisch" ?wrote: > >> Am 26.02.10 06:07, schrieb darnzen: > > >>> Having an odd problem that I solved, but wondering if its the best > >>> solution (seems like a bit of a hack). > > >>> First off, I'm using an external DLL that requires static callbacks, > >>> but because of this, I'm losing instance info. It could be import > >>> related? It will make more sense after I diagram it: > > >>> #Module main.py > >>> from A import * > > >>> class App: > >>> ? ? ? def sperg(self): > >>> ? ? ? ? ? ?self.a = A() > > >>> app = App() > >>> [main loop and such] > >>> ? ?----------------------------- > >>> # Module A.py > >>> import main > >>> class Foo: > >>> ? ? ? ? Selves=[] > >>> ? ? ? ?def __init__(self): > >>> ? ? ? ? ? ? ? ? ?Foo.Selves.append(self) > >>> ? ? ? ?@staticmethod > >>> ? ? ? ?def chum_callback(nType, nP): > >>> ? ? ? ? ? ? ? ? ?# Need to access function / data in app instance > >>> ? ? ? ? ? ? ? ? ?app.sperg(nP) > >>> ? ? ? ? ? ? ? ? ?# Need to access func data in Foo > >>> ? ? ? ? ? ? ? ? ?# I'm pulling 'self' ouf of list made in constructor > >>> ? ? ? ? ? ? ? ? ?self = Foo.getSelf(nP) > > >>> ? ? ? ?def getSelf(nP): > >>> ? ? ? ? ? ? ? ? ?return self.Selves[nP] > > >>> --------------------------------------------------------------------- > >>> So basically I added a list of instances to the base class so I can > >>> get at them from the staticmethod. > >>> What's bothering me the most is I can't use the global app instance in > >>> the A.py module. > > >>> How can I get at the app instance (currently I'm storing that along > >>> with the class instance in the constructor)? > >>> Is there another way to do this that's not such a hack? > > >>> Sorry for the double / partial post :( > > >> Can you show how you pass the staticmethod to the C-function? Is the DLL > >> utilized by ctypes? > > >> I don't see any reason you couldn't use a bound method, which would give > >> you your self, instead relying on global state. > > >> Diez > > > __main__.K<< ?*facepalm* should of tried that! > > > Yeah I'm using ctypes. The DLL callback set ups are as follows. The > > local callback is in the App namespace (in this case, some callbacks > > are in different modules as noted in OP), but still no access to self: > > > ? ? ? ? ?#Function wrapper > > ? ? ? ? ?A.expCallback = WINFUNCTYPE(None, c_int, c_int, ?\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?POINTER(Data_s))(A.Callback) > > > ? ? ? ? ?#DLL call to register the local callback function > > ? ? ? ? ?DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > > ? ? ?class A: > > ? ? ? ? ?#Local callback function > > ? ?@staticmethod > > ? ?def Callback(hID, SubID, Data): > > ? ? ? ? ? ? ? print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > > ? ? ? ? ? ? ? print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > > ? ? ? ? ? ? ? print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > > ? ? ? ? ? ? ? print 'USING KEY GENERATED FROM hID, SubID' > > ? ? ? ? ? ? ? pass > > > I'm not sure why they need to be static callbacks, but the DLL doc's > > say "when using object based languages, such as c++, callback > > functions must be declared as static functions and not instance > > methods", and I couldn't get it to work without setting it up that > > way. I could probably have them all be "classless" functions, but with > > 100's of these, my namespace would be polluted up the wazoo, and I'd > > still have the problem that they wouldn't have access to instance > > methods / properties. > > The above code can't work with self, because you use > > ? A.expCallback > > which at best can of course be a classmethod. > > You need to instead invoke DLLSetCallback with a bound method, like this > > ? a = A() > ? DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of > static functions is differently. If ctypes manages to get *some* > callback passed, I'm 100% positive that it can pass *any* callable you > like, including bound methods. > > Diez This was originally how my code was set up, invoking with the bound methods, but it didn't work (crashing and bizzaro errors) and I was pulling my hair out. Then I read the documentation and changed it to static methods and everything started working. Believe me, I totally understand how using bound methods would make this problem go away. From aioe.org at technicalbloke.com Fri Feb 26 10:52:49 2010 From: aioe.org at technicalbloke.com (r0g) Date: Fri, 26 Feb 2010 15:52:49 +0000 Subject: Offline windows registry access on *nix platforms. Message-ID: Hi Everybody, I do a fair bit of programming in Python and I have to say I find perl a little intimidating right now as I don't have a lot of experience with it however its the only language I have found that seemed to have a library for what I need right now: Win32::Registry (or maybe Win32::TieRegistry) I way to read/search for windows registry keys from offline hive files e.g. NTUSER.DAT on *nix platforms, in my case Ubuntu linux - nothing more advanced than that. Given that I only need this functionality, performance is a not issue and I'm very comfortable in Python I thought I might try and write a pair of wrapper functions - one to check the existence of a key, one to return a keys values. Sadly though I have fallen at the first hurdle, I get "OS unsupported" when I type "install Win32::Registry" into CPAN so I guess it's windows only :( Anyone know of an open source module/library that can do what I want? Ideally Python or Perl, but I suppose any free language I can compile or easily bundle/distribute would do. Alternatively if anyone knows of a *nix app that can decode a windows registry into a flat text file? At a push I could compile something that can do this on windows and run it via wine but I'd really like to avoid that if I can. Suggestions & pointers greatly appreciated, Roger. From darnzen at gmail.com Fri Feb 26 10:57:38 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 07:57:38 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> Message-ID: <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> On Feb 26, 9:41?am, "Diez B. Roggisch" wrote: > Am 26.02.10 16:32, schrieb darnzen: > > > > > > > On Feb 26, 3:15 am, "Diez B. Roggisch" ?wrote: > >> Am 26.02.10 06:07, schrieb darnzen: > > >>> Having an odd problem that I solved, but wondering if its the best > >>> solution (seems like a bit of a hack). > > >>> First off, I'm using an external DLL that requires static callbacks, > >>> but because of this, I'm losing instance info. It could be import > >>> related? It will make more sense after I diagram it: > > >>> #Module main.py > >>> from A import * > > >>> class App: > >>> ? ? ? def sperg(self): > >>> ? ? ? ? ? ?self.a = A() > > >>> app = App() > >>> [main loop and such] > >>> ? ?----------------------------- > >>> # Module A.py > >>> import main > >>> class Foo: > >>> ? ? ? ? Selves=[] > >>> ? ? ? ?def __init__(self): > >>> ? ? ? ? ? ? ? ? ?Foo.Selves.append(self) > >>> ? ? ? ?@staticmethod > >>> ? ? ? ?def chum_callback(nType, nP): > >>> ? ? ? ? ? ? ? ? ?# Need to access function / data in app instance > >>> ? ? ? ? ? ? ? ? ?app.sperg(nP) > >>> ? ? ? ? ? ? ? ? ?# Need to access func data in Foo > >>> ? ? ? ? ? ? ? ? ?# I'm pulling 'self' ouf of list made in constructor > >>> ? ? ? ? ? ? ? ? ?self = Foo.getSelf(nP) > > >>> ? ? ? ?def getSelf(nP): > >>> ? ? ? ? ? ? ? ? ?return self.Selves[nP] > > >>> --------------------------------------------------------------------- > >>> So basically I added a list of instances to the base class so I can > >>> get at them from the staticmethod. > >>> What's bothering me the most is I can't use the global app instance in > >>> the A.py module. > > >>> How can I get at the app instance (currently I'm storing that along > >>> with the class instance in the constructor)? > >>> Is there another way to do this that's not such a hack? > > >>> Sorry for the double / partial post :( > > >> Can you show how you pass the staticmethod to the C-function? Is the DLL > >> utilized by ctypes? > > >> I don't see any reason you couldn't use a bound method, which would give > >> you your self, instead relying on global state. > > >> Diez > > > __main__.K<< ?*facepalm* should of tried that! > > > Yeah I'm using ctypes. The DLL callback set ups are as follows. The > > local callback is in the App namespace (in this case, some callbacks > > are in different modules as noted in OP), but still no access to self: > > > ? ? ? ? ?#Function wrapper > > ? ? ? ? ?A.expCallback = WINFUNCTYPE(None, c_int, c_int, ?\ > > ? ? ? ? ? ? ? ? ? ? ? ? ? ?POINTER(Data_s))(A.Callback) > > > ? ? ? ? ?#DLL call to register the local callback function > > ? ? ? ? ?DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > > ? ? ?class A: > > ? ? ? ? ?#Local callback function > > ? ?@staticmethod > > ? ?def Callback(hID, SubID, Data): > > ? ? ? ? ? ? ? print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > > ? ? ? ? ? ? ? print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > > ? ? ? ? ? ? ? print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > > ? ? ? ? ? ? ? print 'USING KEY GENERATED FROM hID, SubID' > > ? ? ? ? ? ? ? pass > > > I'm not sure why they need to be static callbacks, but the DLL doc's > > say "when using object based languages, such as c++, callback > > functions must be declared as static functions and not instance > > methods", and I couldn't get it to work without setting it up that > > way. I could probably have them all be "classless" functions, but with > > 100's of these, my namespace would be polluted up the wazoo, and I'd > > still have the problem that they wouldn't have access to instance > > methods / properties. > > The above code can't work with self, because you use > > ? A.expCallback > > which at best can of course be a classmethod. > > You need to instead invoke DLLSetCallback with a bound method, like this > > ? a = A() > ? DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of > static functions is differently. If ctypes manages to get *some* > callback passed, I'm 100% positive that it can pass *any* callable you > like, including bound methods. > > Diez Thinking about it some more, I believe I understand why it has to be staticfunction. To use an bound method would require the wrapper to include a reference to the instance as follows: A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ POINTER(Data_s))(a.Callback) Since a = A(); a.foo() is really A.foo(self). The problem here is that A is not a ctypes object and I can't change what arguments the DLL uses in the callback in any case. Rewording my thoughts: a bound method callback would require 'self' to be the first argument. I can not make the DLL include 'self' as it doesn't know anything about the objects in my program. Since I can't pass 'self', it has to be a staticmethod. From jlconlin at gmail.com Fri Feb 26 10:58:14 2010 From: jlconlin at gmail.com (Jeremy) Date: Fri, 26 Feb 2010 07:58:14 -0800 (PST) Subject: =?windows-1252?Q?Dictionary_or_Database=97Please_advise?= Message-ID: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> I have lots of data that I currently store in dictionaries. However, the memory requirements are becoming a problem. I am considering using a database of some sorts instead, but I have never used them before. Would a database be more memory efficient than a dictionary? I also need platform independence without having to install a database and Python interface on all the platforms I'll be using. Is there something built-in to Python that will allow me to do this? Thanks, Jeremy From willia2501 at gmail.com Fri Feb 26 11:04:55 2010 From: willia2501 at gmail.com (William Lohrmann) Date: Fri, 26 Feb 2010 08:04:55 -0800 (PST) Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: On 26 Feb, 13:29, candide wrote: > Suppose you have to put into a Python string the following sentence : > > The play "All's Well That Ends Well" by Shakespeare > > It's easy do it : > > >>> print """The play "All's Well That Ends Well" by Shakespeare""" > > The play "All's Well That Ends Well" by Shakespeare > > Now, change the sentence to this one : > > The play "All's Well That Ends Well" > > Using triple single quotes works fine > > >>> print '''The play "All's Well That Ends Well"''' > > The play "All's Well That Ends Well" > > But the first method doesn't run correctly : > > >>> print """The play "All's Well That Ends Well"""" > > ? File "", line 1 > ? ? print """The play "All's Well That Ends Well"""" > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^ > SyntaxError: EOL while scanning single-quoted string > > > > Any comment ? The best thing would be to backslash the single quote: print 'The play "All\'s Well That Ends Well"' From deets at nospam.web.de Fri Feb 26 11:08:46 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 17:08:46 +0100 Subject: staticmethod and namespaces In-Reply-To: <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> Message-ID: <7uqa0eF95lU1@mid.uni-berlin.de> Am 26.02.10 16:57, schrieb darnzen: > On Feb 26, 9:41 am, "Diez B. Roggisch" wrote: >> Am 26.02.10 16:32, schrieb darnzen: >> >> >> >> >> >>> On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: >>>> Am 26.02.10 06:07, schrieb darnzen: >> >>>>> Having an odd problem that I solved, but wondering if its the best >>>>> solution (seems like a bit of a hack). >> >>>>> First off, I'm using an external DLL that requires static callbacks, >>>>> but because of this, I'm losing instance info. It could be import >>>>> related? It will make more sense after I diagram it: >> >>>>> #Module main.py >>>>> from A import * >> >>>>> class App: >>>>> def sperg(self): >>>>> self.a = A() >> >>>>> app = App() >>>>> [main loop and such] >>>>> ----------------------------- >>>>> # Module A.py >>>>> import main >>>>> class Foo: >>>>> Selves=[] >>>>> def __init__(self): >>>>> Foo.Selves.append(self) >>>>> @staticmethod >>>>> def chum_callback(nType, nP): >>>>> # Need to access function / data in app instance >>>>> app.sperg(nP) >>>>> # Need to access func data in Foo >>>>> # I'm pulling 'self' ouf of list made in constructor >>>>> self = Foo.getSelf(nP) >> >>>>> def getSelf(nP): >>>>> return self.Selves[nP] >> >>>>> --------------------------------------------------------------------- >>>>> So basically I added a list of instances to the base class so I can >>>>> get at them from the staticmethod. >>>>> What's bothering me the most is I can't use the global app instance in >>>>> the A.py module. >> >>>>> How can I get at the app instance (currently I'm storing that along >>>>> with the class instance in the constructor)? >>>>> Is there another way to do this that's not such a hack? >> >>>>> Sorry for the double / partial post :( >> >>>> Can you show how you pass the staticmethod to the C-function? Is the DLL >>>> utilized by ctypes? >> >>>> I don't see any reason you couldn't use a bound method, which would give >>>> you your self, instead relying on global state. >> >>>> Diez >> >>> __main__.K<< *facepalm* should of tried that! >> >>> Yeah I'm using ctypes. The DLL callback set ups are as follows. The >>> local callback is in the App namespace (in this case, some callbacks >>> are in different modules as noted in OP), but still no access to self: >> >>> #Function wrapper >>> A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ >>> POINTER(Data_s))(A.Callback) >> >>> #DLL call to register the local callback function >>> DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) >> >>> class A: >>> #Local callback function >>> @staticmethod >>> def Callback(hID, SubID, Data): >>> print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' >>> print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' >>> print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' >>> print 'USING KEY GENERATED FROM hID, SubID' >>> pass >> >>> I'm not sure why they need to be static callbacks, but the DLL doc's >>> say "when using object based languages, such as c++, callback >>> functions must be declared as static functions and not instance >>> methods", and I couldn't get it to work without setting it up that >>> way. I could probably have them all be "classless" functions, but with >>> 100's of these, my namespace would be polluted up the wazoo, and I'd >>> still have the problem that they wouldn't have access to instance >>> methods / properties. >> >> The above code can't work with self, because you use >> >> A.expCallback >> >> which at best can of course be a classmethod. >> >> You need to instead invoke DLLSetCallback with a bound method, like this >> >> a = A() >> DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) >> >> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of >> static functions is differently. If ctypes manages to get *some* >> callback passed, I'm 100% positive that it can pass *any* callable you >> like, including bound methods. >> >> Diez > > Thinking about it some more, I believe I understand why it has to be > staticfunction. To use an bound method would require the wrapper to > include a reference to the instance as follows: > > A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ > POINTER(Data_s))(a.Callback) > > Since a = A(); a.foo() is really A.foo(self). The problem here is that > A is not a ctypes object and I can't change what arguments the DLL > uses in the callback in any case. Rewording my thoughts: a bound > method callback would require 'self' to be the first argument. I can > not make the DLL include 'self' as it doesn't know anything about the > objects in my program. Since I can't pass 'self', it has to be a > staticmethod. No, that's not true. A bound method implictly knows about it self, and it's a callable. What I guess is that you did the same mistake I did when I created that example - namely, not keeping a refernce to the bound method around. Ctypes will then garbage-collect the callback, which of course leads to all kinds of troubles. Try this: a = A() # keep this around bound_m = a.expCallback DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) Diez From benjamin.kaplan at case.edu Fri Feb 26 11:11:15 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Fri, 26 Feb 2010 11:11:15 -0500 Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= In-Reply-To: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Fri, Feb 26, 2010 at 10:58 AM, Jeremy wrote: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy > Python has SQLite 3 built-in and there are wrappers for MySQL and PostgreSQL on all major platforms. Any one of them will work- databases have the advantage that they're stored on the disk so you don't have all of it in memory simultaneously. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From aioe.org at technicalbloke.com Fri Feb 26 11:14:50 2010 From: aioe.org at technicalbloke.com (r0g) Date: Fri, 26 Feb 2010 16:14:50 +0000 Subject: Offline windows registry access on *nix platforms. References: Message-ID: r0g wrote: > Hi Everybody, > > I do a fair bit of programming in Python and I have to say I find perl a > little intimidating right now as I don't have a lot of experience with > it however its the only language I have found that seemed to have a > library for what I need right now: Win32::Registry (or maybe > Win32::TieRegistry) > > I way to read/search for windows registry keys from offline hive files > e.g. NTUSER.DAT on *nix platforms, in my case Ubuntu linux - nothing > more advanced than that. Actually scrap that, just found "Parse::Win32Registry", happy days! :) Roger. From deets at nospam.web.de Fri Feb 26 11:20:35 2010 From: deets at nospam.web.de (Diez B. Roggisch) Date: Fri, 26 Feb 2010 17:20:35 +0100 Subject: staticmethod and namespaces In-Reply-To: <7uqa0eF95lU1@mid.uni-berlin.de> References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> <7uqa0eF95lU1@mid.uni-berlin.de> Message-ID: <7uqamjFd2vU2@mid.uni-berlin.de> Am 26.02.10 17:08, schrieb Diez B. Roggisch: > Am 26.02.10 16:57, schrieb darnzen: >> On Feb 26, 9:41 am, "Diez B. Roggisch" wrote: >>> Am 26.02.10 16:32, schrieb darnzen: >>> >>> >>> >>> >>> >>>> On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: >>>>> Am 26.02.10 06:07, schrieb darnzen: >>> >>>>>> Having an odd problem that I solved, but wondering if its the best >>>>>> solution (seems like a bit of a hack). >>> >>>>>> First off, I'm using an external DLL that requires static callbacks, >>>>>> but because of this, I'm losing instance info. It could be import >>>>>> related? It will make more sense after I diagram it: >>> >>>>>> #Module main.py >>>>>> from A import * >>> >>>>>> class App: >>>>>> def sperg(self): >>>>>> self.a = A() >>> >>>>>> app = App() >>>>>> [main loop and such] >>>>>> ----------------------------- >>>>>> # Module A.py >>>>>> import main >>>>>> class Foo: >>>>>> Selves=[] >>>>>> def __init__(self): >>>>>> Foo.Selves.append(self) >>>>>> @staticmethod >>>>>> def chum_callback(nType, nP): >>>>>> # Need to access function / data in app instance >>>>>> app.sperg(nP) >>>>>> # Need to access func data in Foo >>>>>> # I'm pulling 'self' ouf of list made in constructor >>>>>> self = Foo.getSelf(nP) >>> >>>>>> def getSelf(nP): >>>>>> return self.Selves[nP] >>> >>>>>> --------------------------------------------------------------------- >>>>>> So basically I added a list of instances to the base class so I can >>>>>> get at them from the staticmethod. >>>>>> What's bothering me the most is I can't use the global app >>>>>> instance in >>>>>> the A.py module. >>> >>>>>> How can I get at the app instance (currently I'm storing that along >>>>>> with the class instance in the constructor)? >>>>>> Is there another way to do this that's not such a hack? >>> >>>>>> Sorry for the double / partial post :( >>> >>>>> Can you show how you pass the staticmethod to the C-function? Is >>>>> the DLL >>>>> utilized by ctypes? >>> >>>>> I don't see any reason you couldn't use a bound method, which would >>>>> give >>>>> you your self, instead relying on global state. >>> >>>>> Diez >>> >>>> __main__.K<< *facepalm* should of tried that! >>> >>>> Yeah I'm using ctypes. The DLL callback set ups are as follows. The >>>> local callback is in the App namespace (in this case, some callbacks >>>> are in different modules as noted in OP), but still no access to self: >>> >>>> #Function wrapper >>>> A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ >>>> POINTER(Data_s))(A.Callback) >>> >>>> #DLL call to register the local callback function >>>> DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) >>> >>>> class A: >>>> #Local callback function >>>> @staticmethod >>>> def Callback(hID, SubID, Data): >>>> print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' >>>> print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' >>>> print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' >>>> print 'USING KEY GENERATED FROM hID, SubID' >>>> pass >>> >>>> I'm not sure why they need to be static callbacks, but the DLL doc's >>>> say "when using object based languages, such as c++, callback >>>> functions must be declared as static functions and not instance >>>> methods", and I couldn't get it to work without setting it up that >>>> way. I could probably have them all be "classless" functions, but with >>>> 100's of these, my namespace would be polluted up the wazoo, and I'd >>>> still have the problem that they wouldn't have access to instance >>>> methods / properties. >>> >>> The above code can't work with self, because you use >>> >>> A.expCallback >>> >>> which at best can of course be a classmethod. >>> >>> You need to instead invoke DLLSetCallback with a bound method, like this >>> >>> a = A() >>> DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) >>> >>> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of >>> static functions is differently. If ctypes manages to get *some* >>> callback passed, I'm 100% positive that it can pass *any* callable you >>> like, including bound methods. >>> >>> Diez >> >> Thinking about it some more, I believe I understand why it has to be >> staticfunction. To use an bound method would require the wrapper to >> include a reference to the instance as follows: >> >> A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ >> POINTER(Data_s))(a.Callback) >> >> Since a = A(); a.foo() is really A.foo(self). The problem here is that >> A is not a ctypes object and I can't change what arguments the DLL >> uses in the callback in any case. Rewording my thoughts: a bound >> method callback would require 'self' to be the first argument. I can >> not make the DLL include 'self' as it doesn't know anything about the >> objects in my program. Since I can't pass 'self', it has to be a >> staticmethod. > > No, that's not true. A bound method implictly knows about it self, and > it's a callable. > > What I guess is that you did the same mistake I did when I created that > example - namely, not keeping a refernce to the bound method around. > Ctypes will then garbage-collect the callback, which of course leads to > all kinds of troubles. > > Try this: > > a = A() > # keep this around > bound_m = a.expCallback > DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) AAAAHHRG, same error again. Of course, use DLLSetCallback(self.hID, A.SubID, EVENTID, bound_m) because the bound method changes with each time you create it. Sorry for the confusion. Diez From clp2 at rebertia.com Fri Feb 26 11:29:51 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Feb 2010 08:29:51 -0800 Subject: =?UTF-8?Q?Re=3A_Dictionary_or_Database=E2=80=94Please_advise?= In-Reply-To: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <50697b2c1002260829m3c3da337pe0e8c39dbbe3a1df@mail.gmail.com> On Fri, Feb 26, 2010 at 7:58 AM, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? If you won't be using the SQL features of the database, `shelve` might be another option; from what I can grok, I sounds like a dictionary stored mostly on disk rather than entirely in RAM (not 100% sure though): http://docs.python.org/library/shelve.html It's in the std lib and supports several native dbm libraries for its backend; one of them should almost always be present. Cheers, Chris -- http://blog.rebertia.com From lbolla at gmail.com Fri Feb 26 11:29:54 2010 From: lbolla at gmail.com (lbolla) Date: Fri, 26 Feb 2010 08:29:54 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Feb 26, 3:58?pm, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy Maybe shelve would be enough for your needs? http://docs.python.org/library/shelve.html From usenot at geekmail.INVALID Fri Feb 26 11:34:59 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 26 Feb 2010 17:34:59 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226134227.10c94afe@geekmail.INVALID> Message-ID: <20100226173459.2b376405@geekmail.INVALID> On Fri, 26 Feb 2010 15:50:25 +0100 Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: > > > And they use mixedCase function/method names. > > > and ? whatIsTheProblem ? Thanks for proving my point. ;) No seriously though: Let it go. I wasn't being serious. As long as it works and I don't have to work with it, I don't care how anybody writes their code. /W -- INVALID? DE! From usenot at geekmail.INVALID Fri Feb 26 11:39:07 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Fri, 26 Feb 2010 17:39:07 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <20100226173907.5567609f@geekmail.INVALID> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk wrote: > On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: > > [stuff] > > Reminiscent of: > > mov AX,BX ; Move the contents of BX into AX > Well, there might be some confusion there as to what gets moved where, wouldn't you say? I guess this goes away after a couple of months, though. > And, yes, I've actually seen that as well as: > > ; This is a comment > I hope it was in a tutorial-situation. Or maybe it was written by one of those "ironic" programmers? /W -- INVALID? DE! From roy at panix.com Fri Feb 26 11:39:51 2010 From: roy at panix.com (Roy Smith) Date: Fri, 26 Feb 2010 11:39:51 -0500 Subject: Dictionary or Database‹Please advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: In article <891a98fa-c398-455a-981f-bf72af77256c at s36g2000prh.googlegroups.com>, Jeremy wrote: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy This is a very vague question, so it'll get a vague answer :-) If you have so much data that you're running into memory problems, then yes, storing the data externally in an disk-resident database seems like a reasonable idea. Once you get into databases, platform independence will be an issue. There are many databases out there to pick from. If you want something which will work on a lot of platforms, a reasonable place to start looking is MySQL. It's free, runs on lots of platforms, has good Python support, and there's lots of people on the net who know it and are willing to give help and advice. Databases have a bit of a learning curve. If you've never done any database work, don't expect to download MySql (or any other database) this afternoon and be up and running by tomorrow. Whatever database you pick, you're almost certainly going to end up having to install it wherever you install your application. There's no such thing as a universally available database that you can expect to be available everywhere. Have fun! From roy at panix.com Fri Feb 26 11:47:28 2010 From: roy at panix.com (Roy Smith) Date: Fri, 26 Feb 2010 11:47:28 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: In article , Tim Daneliuk wrote: > On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: > > Hi all, > > > > a company that works with my company writes a lot of of their code in > > Python (lucky jerks). I've seen their code and it basically looks like > > this: > > > > """Function that does stuff""" > > def doStuff(): > > while not wise(up): > > yield scorn > > > > Now my question is this: How do I kill these people without the > > authorities thinking they didn't deserve it? > > > > /W > > > > Reminiscent of: > > mov AX,BX ; Move the contents of BX into AX > > And, yes, I've actually seen that as well as: > > ; This is a comment OK, if we're going to do this, how about this one, that I just found yesterday in some production C++ code. I'm so glad somebody took the time to explain to me what p7 through p9 are. I never would have figured it out otherwise. /** * Tracing facility. Writes the message to the specified output stream. * If output stream is NULL, writes the message to the process log. * * @param msg_id The message id to use for lookup. * @param ostr The output stream. * @param p1 The first substition parameter. * @param p2 The second substition parameter. * @param p3 The third substition parameter. * @param p4 The fourth substition parameter. * @param p5 The fifth substition parameter. * @param p6 The sixth substition parameter. * @param p7 The seventh substition parameter. * @param p8 The eigth substition parameter. * @param p9 The ninth substition parameter. */ From ricaraoz at gmail.com Fri Feb 26 11:49:55 2010 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Fri, 26 Feb 2010 13:49:55 -0300 Subject: Exception in pydoc Message-ID: <4B87FBB3.8090107@gmail.com> I'm developing an in house app. Many coders here are not fluent in english, so docstrings must be in Spanish in spite of recommendations that docstrings better be in English. When I use accented characters (in this case an '?') in my docstrings I get : >>> help('OpMejoraBizobj') Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site.py", line 346, in __call__ return pydoc.help(*args, **kwds) File "C:\Python25\lib\pydoc.py", line 1645, in __call__ self.help(request) File "C:\Python25\lib\pydoc.py", line 1687, in help elif request: doc(request, 'Help on %s:') File "C:\Python25\lib\pydoc.py", line 1481, in doc pager(title % desc + '\n\n' + text.document(object, name)) File "C:\Python25\lib\pydoc.py", line 324, in document if inspect.ismodule(object): return self.docmodule(*args) File "C:\Python25\lib\pydoc.py", line 1072, in docmodule contents.append(self.document(value, key, name)) File "C:\Python25\lib\pydoc.py", line 325, in document if inspect.isclass(object): return self.docclass(*args) File "C:\Python25\lib\pydoc.py", line 1208, in docclass contents = '\n'.join(contents) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 115: ordinal not in range(128) The file's first two lines are : """ #!/usr/bin/env python # -*- coding: utf-8 -*- """ Does pydoc only deal with ASCII? From phlip2005 at gmail.com Fri Feb 26 11:55:32 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 26 Feb 2010 08:55:32 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: Andreas Waldenburger wrote: > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? Their unit tests are just as complete, illustrative, and administratively sanctioned, right? -- Phlip http://penbird.tumblr.com/ From steve at holdenweb.com Fri Feb 26 11:59:56 2010 From: steve at holdenweb.com (Steve Holden) Date: Fri, 26 Feb 2010 11:59:56 -0500 Subject: Possible to import from a cStringIO file object vs. file on disk? In-Reply-To: <1267195808.16415.1362063523@webmail.messagingengine.com> References: <1267195808.16415.1362063523@webmail.messagingengine.com> Message-ID: python at bdurham.com wrote: > Is it possible to import from a cStringIO file object (containing > compiled byte code) vs. a physical file on disk? > > I'm thinking that this is possible, given Python's ability to import > from zip files, but I'm not sure where to look next. > > Thank you, > Malcolm > You'll need to write a custom importer. PEP 302 contains the necessary details. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From R.Brodie at rl.ac.uk Fri Feb 26 12:10:12 2010 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Fri, 26 Feb 2010 17:10:12 -0000 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: "Andreas Waldenburger" wrote in message news:20100226173907.5567609f at geekmail.INVALID... >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX >> > Well, there might be some confusion there as to what gets moved where, > wouldn't you say? Depends on what assembler you're used to. I certainly find having the operands that way round confusing. From jlconlin at gmail.com Fri Feb 26 12:31:22 2010 From: jlconlin at gmail.com (Jeremy) Date: Fri, 26 Feb 2010 09:31:22 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> On Feb 26, 9:29?am, Chris Rebert wrote: > On Fri, Feb 26, 2010 at 7:58 AM, Jeremy wrote: > > I have lots of data that I currently store in dictionaries. ?However, > > the memory requirements are becoming a problem. ?I am considering > > using a database of some sorts instead, but I have never used them > > before. ?Would a database be more memory efficient than a dictionary? > > I also need platform independence without having to install a database > > and Python interface on all the platforms I'll be using. ?Is there > > something built-in to Python that will allow me to do this? > > If you won't be using the SQL features of the database, `shelve` might > be another option; from what I can grok, I sounds like a dictionary > stored mostly on disk rather than entirely in RAM (not 100% sure > though):http://docs.python.org/library/shelve.html > > It's in the std lib and supports several native dbm libraries for its > backend; one of them should almost always be present. > > Cheers, > Chris > --http://blog.rebertia.com Shelve looks like an interesting option, but what might pose an issue is that I'm reading the data from a disk instead of memory. I didn't mention this in my original post, but I was hoping that by using a database it would be more memory efficient in storing data in RAM so I wouldn't have to read from (or swap to/from) disk. Would using the shelve package make reading/writing data from disk faster since it is in a binary format? Jeremy From darcy at druid.net Fri Feb 26 12:57:50 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 26 Feb 2010 12:57:50 -0500 Subject: Dictionary or Database_Please advise In-Reply-To: References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <20100226125750.45f2406a.darcy@druid.net> On Fri, 26 Feb 2010 11:39:51 -0500 Roy Smith wrote: > Once you get into databases, platform independence will be an issue. There > are many databases out there to pick from. If you want something which > will work on a lot of platforms, a reasonable place to start looking is > MySQL. It's free, runs on lots of platforms, has good Python support, and > there's lots of people on the net who know it and are willing to give help > and advice. Or PostgreSQL. It's free, runs on lots of platforms, has good Python support, and there's lots of people on the net who know it and are willing to give help and advice. In addition, it is a truly enterprise level, SQL standard, fully transactional database. Don't start with MySQL and uprade to PostgreSQL later when you get big. Start with the best one now and be ready. > Databases have a bit of a learning curve. If you've never done any > database work, don't expect to download MySql (or any other database) this > afternoon and be up and running by tomorrow. Whatever database you get, there will probably be plenty of tutorials. See http://www.postgresql.org/docs/current/interactive/tutorial.html for the PostgreSQL one. -- 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 srikrishnamohan at gmail.com Fri Feb 26 13:03:43 2010 From: srikrishnamohan at gmail.com (km) Date: Sat, 27 Feb 2010 03:03:43 +0900 Subject: =?UTF-8?Q?Re=3A_Dictionary_or_Database=E8=BC=9Dlease_advise?= In-Reply-To: References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: Hi, Probably u should try couchdb! its a document oriented database. ( apache.couchdb.org) u can store your dictionaries as json documents and yes they are simple text files; data structures cna be directly stored into JSON documents. memory efficient too.. python module @ http://code.google.com/p/couchdb-python/ HTH Krishna ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On Sat, Feb 27, 2010 at 1:39 AM, Roy Smith wrote: > In article > <891a98fa-c398-455a-981f-bf72af77256c at s36g2000prh.googlegroups.com>, > Jeremy wrote: > > > I have lots of data that I currently store in dictionaries. However, > > the memory requirements are becoming a problem. I am considering > > using a database of some sorts instead, but I have never used them > > before. Would a database be more memory efficient than a dictionary? > > I also need platform independence without having to install a database > > and Python interface on all the platforms I'll be using. Is there > > something built-in to Python that will allow me to do this? > > > > Thanks, > > Jeremy > > This is a very vague question, so it'll get a vague answer :-) > > If you have so much data that you're running into memory problems, then > yes, storing the data externally in an disk-resident database seems like a > reasonable idea. > > Once you get into databases, platform independence will be an issue. There > are many databases out there to pick from. If you want something which > will work on a lot of platforms, a reasonable place to start looking is > MySQL. It's free, runs on lots of platforms, has good Python support, and > there's lots of people on the net who know it and are willing to give help > and advice. > > Databases have a bit of a learning curve. If you've never done any > database work, don't expect to download MySql (or any other database) this > afternoon and be up and running by tomorrow. > > Whatever database you pick, you're almost certainly going to end up having > to install it wherever you install your application. There's no such thing > as a universally available database that you can expect to be available > everywhere. > > Have fun! > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrkafk at gmail.com Fri Feb 26 13:04:27 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:04:27 +0100 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= In-Reply-To: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: Jeremy wrote: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. Is there > something built-in to Python that will allow me to do this? Since you use dictionaries, I guess that simple store saving key:value will do? If so, bsddb support built into Python will do just nicely. bsddb is multiplatform, although I have not personally tested if a binary db created on one platform will be usable on another. You'd have to check this. Caveat: from what some people say I gather that binary format between bsddb versions tends to change. There's also ultra-cool-and-modern Tokyo Cabinet key:value store with Python bindings: http://pypi.python.org/pypi/pytc/ I didn't test it, though. Regards, mk From garyrob at me.com Fri Feb 26 13:08:10 2010 From: garyrob at me.com (Gary Robinson) Date: Fri, 26 Feb 2010 13:08:10 -0500 Subject: collections use __next__() in python 2.6? Message-ID: <20100226130810913273.0085366e@me.com> The Python 2.6.4 docs for collections at http://docs.python.org/library/collections.html say that __next__() is an abstract method for the Iterable ABC. But my understanding is that __next__() isn't supposed to be used until Python 3. Also, I'm using the Mapping ABC, which inherits from Iterable, and it doesn't seem to work if I define __next__(); I am not seeing problems if I define next() instead. What am I missing? -- Gary Robinson CTO Emergent Music, LLC personal email: garyrob at me.com work email: grobinson at flyfi.com Company: http://www.flyfi.com Blog: http://www.garyrobinson.net From mrkafk at gmail.com Fri Feb 26 13:20:19 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:20:19 +0100 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= In-Reply-To: <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: Jeremy wrote: > Shelve looks like an interesting option, but what might pose an issue > is that I'm reading the data from a disk instead of memory. I didn't > mention this in my original post, but I was hoping that by using a > database it would be more memory efficient in storing data in RAM so I > wouldn't have to read from (or swap to/from) disk. Would using the > shelve package make reading/writing data from disk faster since it is > in a binary format? Read the docs: "class shelve.BsdDbShelf(dict[, protocol=None[, writeback=False]])? A subclass of Shelf which exposes first(), next(), previous(), last() and set_location() which are available in the bsddb module but not in other database modules. The dict object passed to the constructor must support those methods. This is generally accomplished by calling one of bsddb.hashopen(), bsddb.btopen() or bsddb.rnopen(). The optional protocol and writeback parameters have the same interpretation as for the Shelf class." Apparently using shelve internally gives you option of using bsddb, which is good news: bsddb is B-tree DB, which is highly efficient for finding keys. I would recommend bsddb.btopen(), as it creates B-tree DB (perhaps other implementations, like anydb or hash db are good as well, but I personally didn't test them out). I can't say for Berkeley DB implementation, but in general B-tree algorithm has O(log2 n) complexity for finding keys, which roughly means that if you need to find particular key in a db of 1 million keys, you'll probably need ~20 disk accesses (or even less if some keys looked at in the process of search happen to be in the same disk sectors). So yes, it's highly efficient. Having said that, remember that disk is many orders of magnitude slower than RAM, so it's no free lunch.. Nothing will beat memory-based data structure when it comes to speed (well new flash or hybrid disks perhaps could significantly improve in comparison to current mainstream mechanical-platter disks? there are some hyper-fast storage hardware companies out there, although they tend to charge arm and leg for their stuff for now). Caveat: Berkeley DB is dual-licensed -- if you're using it for commercial work, it might be that you'd need to buy a license for it. Although I have had no experience with this really, if someone here did perhaps they will shed some light on it? Regards, mk From jeanmichel at sequans.com Fri Feb 26 13:25:04 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 19:25:04 +0100 Subject: Docstrings considered too complicated In-Reply-To: <20100226173907.5567609f@geekmail.INVALID> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: <4B881200.5060505@sequans.com> Andreas Waldenburger wrote: > On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk > wrote: > > >> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >> >>> [stuff] >>> >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX >> >> > Well, there might be some confusion there as to what gets moved where, > wouldn't you say? I guess this goes away after a couple of months, > though. > I agree to that statement, I was surprised that mov AX,BX assumes that BX is the source, and AX the destination. I never programmed in assembler though. JM From mrkafk at gmail.com Fri Feb 26 13:26:46 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:26:46 +0100 Subject: Dictionary or Database_Please advise In-Reply-To: <20100226125750.45f2406a.darcy@druid.net> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <20100226125750.45f2406a.darcy@druid.net> Message-ID: D'Arcy J.M. Cain wrote: > Or PostgreSQL. It's free, runs on lots of platforms, has good Python > support, and there's lots of people on the net who know it and are > willing to give help and advice. In addition, it is a truly enterprise > level, SQL standard, fully transactional database. Don't start with > MySQL and uprade to PostgreSQL later when you get big. Start with the > best one now and be ready. I second that: I burned my fingers on MySQL quite a few times and don't want to have anything to do with it anymore. Eventually you hit the wall with MySQL (although I haven't tested latest and best, perhaps they improved). E.g. don't even get me started on replication that tends to randomly fizzle out quietly without telling you anything about it. Or that FOREIGN KEY is accepted but referential integrity is not enforced. Or that if you want real transactions, you have to choose InnoDB table type but then you lose much of the performance. Etc. No, if you have a choice, avoid MySQL and go for PGSQL. It's fantastic, if (necessarily) complex. Regards, mk From jeanmichel at sequans.com Fri Feb 26 13:30:23 2010 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 26 Feb 2010 19:30:23 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <4B88133F.7020006@sequans.com> Roy Smith wrote: > In article , > Tim Daneliuk wrote: > > >> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >> >>> Hi all, >>> >>> a company that works with my company writes a lot of of their code in >>> Python (lucky jerks). I've seen their code and it basically looks like >>> this: >>> >>> """Function that does stuff""" >>> def doStuff(): >>> while not wise(up): >>> yield scorn >>> >>> Now my question is this: How do I kill these people without the >>> authorities thinking they didn't deserve it? >>> >>> /W >>> >>> >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX >> >> And, yes, I've actually seen that as well as: >> >> ; This is a comment >> > > OK, if we're going to do this, how about this one, that I just found > yesterday in some production C++ code. I'm so glad somebody took the time > to explain to me what p7 through p9 are. I never would have figured it out > otherwise. > > /** > * Tracing facility. Writes the message to the specified output stream. > * If output stream is NULL, writes the message to the process log. > * > * @param msg_id The message id to use for lookup. > * @param ostr The output stream. > * @param p1 The first substition parameter. > * @param p2 The second substition parameter. > * @param p3 The third substition parameter. > * @param p4 The fourth substition parameter. > * @param p5 The fifth substition parameter. > * @param p6 The sixth substition parameter. > * @param p7 The seventh substition parameter. > * @param p8 The eigth substition parameter. > * @param p9 The ninth substition parameter. > */ > just in case the first sub param would be p0 :-) JM From arjun.chennu at gmail.com Fri Feb 26 13:39:08 2010 From: arjun.chennu at gmail.com (Arjun) Date: Fri, 26 Feb 2010 10:39:08 -0800 (PST) Subject: How to end TCP socket data while using readline()? Message-ID: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> Hi, I have a small script that runs a TCP server. A client connects to this server and transmits a stored file line-by-line, and then waits for a confirmation "done". However, when I run them the first loop never really ends -- as the TCP server keeps expecting more data. I am using a file-like-object, and so somehow I have to communicate to the server that it is the end-of-file. here is some server code sock1.bind(('', port)) print "Listening at port: ", port sock1.listen(1) # listening socket (conn, addr) = sock1.accept() # connected socket print 'Client (localhost) port: ', addr[1] cf = conn.makefile('r',0) # file like obj for socket lf = open('ccs.txt','w') for line in cf: lf.write(line) lf.flush() sys.stdout.write(line) print len(line) lf.close() (*here*) cf.close() cf = conn.makefile('w',0) print len(line) print 'sendin' stat = 'done' cf.write(stat) print stat print 'sent' cf.close() print 'script done & connection closed' The client is sending the lines through this code: s.connect((host,port)) sfp = open("dcs.txt") # script = sfp.readlines() stat = 'still' cf = s.makefile('w',0) for line in sfp.readlines(): cf.write(line) print len(line) print 'close' cf.flush() cf.close() sfp.close() cf = s.makefile('r',0) print stat, 'waiting' stat = cf.readline() print stat, 'waiting' # this should become "done waiting" cf.close() s.close() So what I am wondering is: 1. Using a file-like object means that the socket becomes uni- directional, until the mode of the file object is changed from 'r' to 'w' (or vice versa). This seems inefficient, and rather unPythonesque. Can somebody tell me if there is a more elegant way of receiving all the lines from the client, and then sending a "done" message to the client? 2. Where I have marked (*here*) in the server code, is where the execution seems to stay waiting... apparently for more input from the client. But then when I force-terminate the client script, the execution continues on the server-side!! So then it sends the "done" status to a (already dead) client, and then exits. How do I get the server to know when the EOF has been reached while using FLOs? Input on this will be much appreciated, because the documentation for readlines() didn't help me with this. Cheers, A From mrkafk at gmail.com Fri Feb 26 13:41:48 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 19:41:48 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: Roy Smith wrote: > /** > * Tracing facility. Writes the message to the specified output stream. > * If output stream is NULL, writes the message to the process log. > * > * @param msg_id The message id to use for lookup. > * @param ostr The output stream. > * @param p1 The first substition parameter. > * @param p2 The second substition parameter. > * @param p3 The third substition parameter. > * @param p4 The fourth substition parameter. > * @param p5 The fifth substition parameter. > * @param p6 The sixth substition parameter. > * @param p7 The seventh substition parameter. > * @param p8 The eigth substition parameter. > * @param p9 The ninth substition parameter. > */ Well at least they did explain something. ;-) You should be happy you don't have to deal with PHP programmers that tend to write 20-positional-argument function AND programmer 1 knows what params 1-7 do, programmer 2 knows what params 8-15 do and nobody knows what params 16-20 do. Seriously. Regards, mk From shailendra.vikas at gmail.com Fri Feb 26 14:07:10 2010 From: shailendra.vikas at gmail.com (Shailendra) Date: Fri, 26 Feb 2010 14:07:10 -0500 Subject: SystemError: error return without exception set Message-ID: Hi All, I am getting error in "SystemError: error return without exception set" which i am not able debug. I made following test program which gives same error. =========test.py============== import numpy class testClass: def __init__(self,param1=1,param2=2): self.param1,self.param2=param1,param2 def __str__(self): return 'param1=%d param2=%d'%(self.param1,self.param2) class makeLotOftestClass: def __init__(self,paramlist1=None,paramlist2=None): self.holder= numpy.empty((len(paramlist1),len(paramlist2))) for i in range(len(paramlist1)): for j in range(len(paramlist2)): self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) def __str__(): str='' for testclass in numpy.raven(self.holder): str=str+testclass.__str__() return str if __name__=='__main__': lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) print lotofclass ============================================== $ python test.py Traceback (most recent call last): File "test.py", line 25, in lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) File "test.py", line 16, in __init__ self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) SystemError: error return without exception set Can someone point out why is this exception. It seems to be a simple code. Google search for the error message did not help much. Thanks, Shailendra From toby at rcsreg.com Fri Feb 26 14:13:06 2010 From: toby at rcsreg.com (Tobiah) Date: Fri, 26 Feb 2010 19:13:06 GMT Subject: Six Minutes and fourty two seconds Message-ID: <63Vhn.92$1n5.11@newsfe04.iad> Now that I use python, this is the amount of time per day that I spend adding forgotten semicolons while debugging other languages. From aahz at pythoncraft.com Fri Feb 26 14:23:16 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 11:23:16 -0800 Subject: lists of variables References: Message-ID: In article , Michael Pardee wrote: > >I'm relatively new to python and I was very surprised by the following >behavior: http://starship.python.net/crew/mwh/hacks/objectthink.html -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From mnordhoff at mattnordhoff.com Fri Feb 26 14:28:01 2010 From: mnordhoff at mattnordhoff.com (Matt Nordhoff) Date: Fri, 26 Feb 2010 19:28:01 +0000 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: <4B8820C1.3010803@mattnordhoff.com> Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. You can fix that by not using other languages. :> -- Matt Nordhoff From nagle at animats.com Fri Feb 26 14:28:21 2010 From: nagle at animats.com (John Nagle) Date: Fri, 26 Feb 2010 11:28:21 -0800 Subject: When will Java go mainstream like Python? In-Reply-To: <7umqtdFlrrU1@mid.individual.net> References: <7umqtdFlrrU1@mid.individual.net> Message-ID: <4B8820D5.7030502@animats.com> Gregory Ewing wrote: > Lawrence D'Oliveiro wrote: >> And then there?s caching. Modern CPUs owe most of their speed to >> assumptions that programs will obey locality of reference. >> Pointer-chasing is a cache- >> hostile activity. > > Another thing to consider is the rate at which garbage is > created. Java's fundamental types (ints, floats, etc.) are > unboxed, and objects are only used for relatively heavyweight > things. So you can do quite a lot of useful computation in > Java without creating any objects or leaving behind any > garbage. > > In Python, on the other hand, you can't even do arithmetic > without creating and destroying intermediate objects at > every step. This is really a CPython implementation problem. Face it, CPython is a "naive interpreter". It pretty much does the obvious. In other words, the code for the worst case is used for all cases. It doesn't optimize out reference count updates, do type inference to avoid unnecessary boxing, or figure out at compile time which objects could be "slotted" and don't need dictionary lookups for fields. Plus, of course, there's the GIL problem. Reference counts aren't inherently slow. About 90% of reference count updates could be optimized out. The compiler needs to understand what's a temporary object and what isn't. See http://blogs.msdn.com/abhinaba/archive/2009/02/09/back-to-basics-optimizing-reference-counting-garbage-collection.aspx The language isn't inherently slow, but CPython is. The Shed Skin developer has shown what's possible. He doesn't have enough resources to finish a full implementation, but he's on the right track. There's grumbling about the restrictions in Shed Skin, but only some of Shed Skin's restrictions are inherently necessary. The one Shed Skin developer has accomplished far more than the PyPy army of ants. John Nagle From python at mrabarnett.plus.com Fri Feb 26 14:31:32 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Feb 2010 19:31:32 +0000 Subject: SystemError: error return without exception set In-Reply-To: References: Message-ID: <4B882194.7030500@mrabarnett.plus.com> Shailendra wrote: > Hi All, > I am getting error in "SystemError: error return without exception > set" which i am not able debug. I made following test program which > gives same error. > > =========test.py============== > > import numpy > > class testClass: > def __init__(self,param1=1,param2=2): > self.param1,self.param2=param1,param2 > > def __str__(self): > return 'param1=%d param2=%d'%(self.param1,self.param2) > > > class makeLotOftestClass: > def __init__(self,paramlist1=None,paramlist2=None): > self.holder= numpy.empty((len(paramlist1),len(paramlist2))) > for i in range(len(paramlist1)): > for j in range(len(paramlist2)): > > self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) > > def __str__(): > str='' > for testclass in numpy.raven(self.holder): > str=str+testclass.__str__() > return str > > if __name__=='__main__': > lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) > print lotofclass > > ============================================== > > $ python test.py > Traceback (most recent call last): > File "test.py", line 25, in > lotofclass=makeLotOftestClass(paramlist1=[10,20,30,40],paramlist2=[110,120,130,140]) > File "test.py", line 16, in __init__ > self.holder[i,j]=testClass(param1=paramlist1[i],param2=paramlist2[j]) > SystemError: error return without exception set > > Can someone point out why is this exception. It seems to be a simple > code. Google search for the error message did not help much. > As I see it, there are 2 problems here: 1. numpy arrays contain numbers, but what you're trying to put into the array are not numbers. 2. The numpy module is trying to raise an exception but it isn't setting up the exception correctly internally, which is a bug in numpy itself. From mrkafk at gmail.com Fri Feb 26 14:36:35 2010 From: mrkafk at gmail.com (mk) Date: Fri, 26 Feb 2010 20:36:35 +0100 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. My objects are flat and I don't know who's Guido. I blame it all on Python. How about a PEP "Let's make Python look like PHP"? Regards, mk From python at mrabarnett.plus.com Fri Feb 26 14:45:58 2010 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 26 Feb 2010 19:45:58 +0000 Subject: How to end TCP socket data while using readline()? In-Reply-To: References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> <4B881F04.7040106@mrabarnett.plus.com> Message-ID: <4B8824F6.9010607@mrabarnett.plus.com> Arjun Chennu wrote: > No need to flush because you're writing to a file and it'll be flushed > > anyway when you close it. > > > True. I had introduced those flush lines while I was trying to > troubleshoot this annoying situation. :-) > > You've closed the file view, but the underlying socket is still open. > > > The server will see EOF only when the socket is closed by the client, > and closing the file view doesn't close the socket itself. > > > That's what I intended to do. Keep the socket open, but close the file > object so that the direction of transfer can be reversed and a "done" > message can be sent to the client. > > TCP is meant to facilitate two-directional transfer innit? So how do I > do that while using file objects? If i have to close the socket to do > that, it seems a bit wasteful in terms of network 'transactions' > > Thanks for your reply. I've already confirmed that closing the socket > does indeed move the program ahead --- but I'd like to now make > two-directional comm. possible. > Here's a trick borrowed from the POP3 format (used for email). Server code: ... cf = conn.makefile('r', 0) # file like obj for socket lf = open('ccs.txt', 'w') for line in cf: if line == '.end\n': break if line.startswith('..'): line = line[1 : ] lf.write(line) sys.stdout.write(line) print len(line) lf.close() cf.close() ... Client code: ... cf = s.makefile('w', 0) for line in sfp.readlines(): if line.startswith('.'): cf.write('.') cf.write(line) print len(line) cr.write('.end\n') print 'close' cf.close() ... From python at bdurham.com Fri Feb 26 14:49:09 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 26 Feb 2010 14:49:09 -0500 Subject: Possible to import from a cStringIO file object vs. file on disk? In-Reply-To: <1267213340.1668.1362112899@webmail.messagingengine.com> References: <1267195808.16415.1362063523@webmail.messagingengine.com> <1267213340.1668.1362112899@webmail.messagingengine.com> Message-ID: <1267213749.2540.1362114855@webmail.messagingengine.com> Steve, > You'll need to write a custom importer. PEP 302 contains the necessary details. Thanks for pointing me to PEP 302 and the imp module. It looks like "imp.load_compiled(name, pathname[, file])" is what I need, but the description of this method (and similar methods) has the following disclaimer: Quote: "The file argument is the byte-compiled code file, open for reading in binary mode, from the beginning. It must currently be a real file object, not a user-defined class emulating a file." [1] I tried using a cStringIO object vs. a real file object, but the help documentation is correct - only a real file object can be used. Any ideas on why these modules would impose such a restriction or is this just an historical artifact? Are there any techniques I can use to avoid this physical file requirement? Thanks, Malcolm [1] http://docs.python.org/library/imp.html#imp.load_module python at bdurham.com wrote: > Is it possible to import from a cStringIO file object (containing > compiled byte code) vs. a physical file on disk? > > I'm thinking that this is possible, given Python's ability to import > from zip files, but I'm not sure where to look next. > > Thank you, > Malcolm > regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ -- http://mail.python.org/mailman/listinfo/python-list From ppearson at nowhere.invalid Fri Feb 26 15:07:52 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 26 Feb 2010 20:07:52 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7uqo0nF1ssU1@mid.individual.net> On Wed, 24 Feb 2010 20:16:24 +0100, mk wrote: > On 2010-02-24 20:01, Robert Kern wrote: >> I will repeat my advice to just use random.SystemRandom.choice() instead >> of trying to interpret the bytes from /dev/urandom directly. > > Out of curiosity: > > def gen_rand_string(length): > prng = random.SystemRandom() > chars = [] > for i in range(length): > chars.append(prng.choice('abcdefghijklmnopqrstuvwxyz')) > return ''.join(chars) > > if __name__ == "__main__": > chardict = {} > for i in range(10000): > ## w = gen_rand_word(10) > w = gen_rand_string(10) > count_chars(chardict, w) > counts = list(chardict.items()) > counts.sort(key = operator.itemgetter(1), reverse = True) > for char, count in counts: > print char, count > > > s 3966 > d 3912 > g 3909 > h 3905 > a 3901 > u 3900 > q 3891 > m 3888 > k 3884 > b 3878 > x 3875 > v 3867 > w 3864 > y 3851 > l 3825 > z 3821 > c 3819 > e 3819 > r 3816 > n 3808 > o 3797 > f 3795 > t 3784 > p 3765 > j 3730 > i 3704 > > Better, although still not perfect. What would be perfect? Surely one shouldn't be happy if all the tallies come out exactly equal: that would be a blatant indication of something very nonrandom going on. The tallies given above give a chi-squared value smack in the middle of the range expected for random sampling of a uniform distribution (p = 0.505). So the chi-squared metric of goodness-of-fit to a unifom distribution says you're doing fine. -- To email me, substitute nowhere->spamcop, invalid->net. From python at rcn.com Fri Feb 26 15:10:33 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Feb 2010 12:10:33 -0800 (PST) Subject: collections use __next__() in python 2.6? References: Message-ID: On Feb 26, 10:08?am, Gary Robinson wrote: > The Python 2.6.4 docs for collections athttp://docs.python.org/library/collections.htmlsay that __next__() is an abstract method for the Iterable ABC. But my understanding is that __next__() isn't supposed to be used until Python 3. Also, I'm using the Mapping ABC, which inherits from Iterable, and it doesn't seem to work if I define __next__(); I am not seeing problems if I define next() instead. > > What am I missing? It's a typo. The abstract method is next(). Raymond From ppearson at nowhere.invalid Fri Feb 26 15:17:43 2010 From: ppearson at nowhere.invalid (Peter Pearson) Date: 26 Feb 2010 20:17:43 GMT Subject: Is this secure? References: <7xtyt72200.fsf@ruckus.brouhaha.com> <7x3a0r8hyr.fsf@ruckus.brouhaha.com> Message-ID: <7uqoj7F1ssU2@mid.individual.net> On Wed, 24 Feb 2010 21:02:07 +0100, mk wrote: [snip] > > rand_str_SystemRandom_seeding > mean 3845.15384615 std dev 46.2016419186 > l 3926 1.75 std devs away from mean > y 3916 1.53 std devs away from mean > d 3909 1.38 std devs away from mean > a 3898 1.14 std devs away from mean > p 3898 1.14 std devs away from mean > c 3889 0.95 std devs away from mean > u 3884 0.84 std devs away from mean > j 3873 0.60 std devs away from mean > n 3873 0.60 std devs away from mean > w 3866 0.45 std devs away from mean > x 3863 0.39 std devs away from mean > r 3855 0.21 std devs away from mean > m 3852 0.15 std devs away from mean > b 3841 -0.09 std devs away from mean > t 3835 -0.22 std devs away from mean > o 3829 -0.35 std devs away from mean > k 3827 -0.39 std devs away from mean > i 3821 -0.52 std devs away from mean > s 3812 -0.72 std devs away from mean > q 3806 -0.85 std devs away from mean > v 3803 -0.91 std devs away from mean > g 3799 -1.00 std devs away from mean > h 3793 -1.13 std devs away from mean > e 3782 -1.37 std devs away from mean > f 3766 -1.71 std devs away from mean > z 3758 -1.89 std devs away from mean Chi2 = 14.43, 25 d.f., prob = 0.046362. The observed distribution is SIGNIFICANTLY CLOSER to the uniform distribution than reasonable by chance. > rand_str_SystemRandom_noseeding > mean 3845.15384615 std dev 55.670522726 > i 3961 2.08 std devs away from mean > r 3911 1.18 std devs away from mean > e 3910 1.16 std devs away from mean > m 3905 1.08 std devs away from mean > a 3901 1.00 std devs away from mean > u 3893 0.86 std devs away from mean > t 3882 0.66 std devs away from mean > w 3872 0.48 std devs away from mean > s 3870 0.45 std devs away from mean > c 3868 0.41 std devs away from mean > n 3866 0.37 std devs away from mean > q 3865 0.36 std devs away from mean > k 3863 0.32 std devs away from mean > y 3848 0.05 std devs away from mean > j 3836 -0.16 std devs away from mean > v 3830 -0.27 std devs away from mean > f 3829 -0.29 std devs away from mean > z 3829 -0.29 std devs away from mean > g 3827 -0.33 std devs away from mean > l 3818 -0.49 std devs away from mean > b 3803 -0.76 std devs away from mean > d 3803 -0.76 std devs away from mean > p 3756 -1.60 std devs away from mean > x 3755 -1.62 std devs away from mean > h 3744 -1.82 std devs away from mean > o 3729 -2.09 std devs away from mean Chi2 = 20.96, 25 d.f., prob = 0.304944. The observed distribution is not significantly different from the uniform distribution. > rand_str_custom > mean 3517.15384615 std dev 40.7541336343 > i 3586 1.69 std devs away from mean > a 3578 1.49 std devs away from mean > e 3575 1.42 std devs away from mean > m 3570 1.30 std devs away from mean > q 3562 1.10 std devs away from mean > c 3555 0.93 std devs away from mean > g 3552 0.86 std devs away from mean > w 3542 0.61 std devs away from mean > p 3536 0.46 std devs away from mean > x 3533 0.39 std devs away from mean > s 3528 0.27 std devs away from mean > o 3524 0.17 std devs away from mean > d 3516 -0.03 std devs away from mean > t 3515 -0.05 std devs away from mean > h 3511 -0.15 std devs away from mean > v 3502 -0.37 std devs away from mean > z 3502 -0.37 std devs away from mean > b 3500 -0.42 std devs away from mean > f 3496 -0.52 std devs away from mean > u 3492 -0.62 std devs away from mean > l 3486 -0.76 std devs away from mean > r 3478 -0.96 std devs away from mean > n 3476 -1.01 std devs away from mean > j 3451 -1.62 std devs away from mean > k 3450 -1.65 std devs away from mean > y 3430 -2.14 std devs away from mean Chi2 = 12.28, 25 d.f., prob = 0.015815. The observed distribution is SIGNIFICANTLY CLOSER to the uniform distribution than reasonable by chance. > It would appear that SystemRandom().choice is indeed best (in terms of > how much the counts stray from mean in std devs), but only after seeding > it with os.urandom. I don't see any reason to worry about any of the three, except perhaps that the first and last are surprisingly uniform. -- To email me, substitute nowhere->spamcop, invalid->net. From cmpython at gmail.com Fri Feb 26 15:27:06 2010 From: cmpython at gmail.com (CM) Date: Fri, 26 Feb 2010 12:27:06 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Feb 26, 10:58?am, Jeremy wrote: > I have lots of data How much is "lots"? > that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? What do you mean by more efficient? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? The SQLite datbase engine is built into Python 2.5 and up. I have heard on this list that there may be problems with it with Python 2.6 and up on Linux, but I've stayed with 2.5 and it works fine for me on WinXP, Vista, and Linux. You can use it as a disk-stored single database file, or an in-memory- only database. The SQLite website (http://www.sqlite.org/) claims it is the "most widely deployed SQL database engine in the world.", for what that's worth. Have a look at this: http://docs.python.org/library/sqlite3.html Che > > Thanks, > Jeremy From alfps at start.no Fri Feb 26 15:44:44 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Feb 2010 21:44:44 +0100 Subject: lists of variables In-Reply-To: References: Message-ID: * Michael Pardee: > I'm relatively new to python and I was very surprised by the following behavior: > >>>> a=1 >>>> b=2 'a' refers to an object representing the integer 1. Since 1 is an immutable value you can just as well think of it as 'a' containing the value 1, because a reference to an immutable value is for nearly all practical purposes indistinguishable from that value. 'b' refers to an object representing the integer 2, which, again, since integers are immutable, you can just as well think of as 'b' containing the value 2. >>>> mylist=[a,b] A 'list' object (an array) is constructed, and 'mylist' is set to refer to it. The array has two items. The first item is set to refer to same object as 'a' (a reference copy), the second item is set to refer to the same object as 'b'. But since integers are immutable you can just as well think of it as a copying of the integer values. Immutable values allow you to think of handling the values directly. >>>> print mylist > [1, 2] >>>> a=3 This changes what 'a' refers to. It does not change what the first array element refers to. >>>> print mylist > [1, 2] > > Whoah! Are python lists only for literals? No, that's an irrelevant notion. > Nope: > >>>> c={} >>>> d={} Here 'c' now refers to a dictionary object, which is mutable (can be changed). And 'd' refers to another dictionary object. >>>> mydlist=[c,d] >>>> print mydlist > [{}, {}] A 'list' array object is constructed, and 'mydlist' is set to refer to it. The first item in the array is set to refer to the same object as 'c' refers to, namely a mutable dictionary object (currently an empty dictionary). The second item in the array is set to refer to the same object as 'd' refers to, namely a mutable dictionary object (currently an empty dictionary). It's the same that happened earlier with the integers. The only difference, but it's a significant one, is that now the referred to objects are mutable, that is, they can be changed. >>>> c['x']=1 The dictionary object referred to by 'c' is updated to now have a key 'x' with associated value 1. In more gory detail: the key is associated with a reference to an object representing 1, but again, since integer values are immutable you can think of this as a direct association with the value; the reference view of this association is mostly[1] only relevant when the referred to object is mutable. Since the dictionary object that you're changing is referred to by both 'c' and the first item of 'mydlist', both of these reflect the change. >>>> print mydlist > [{'x': 1}, {}] Yep. > So it looks like variables in a list are stored as object references. You mean items in a list are references to objects. Yes. > This seems to confirm that: > > mydlist[1]['y']=4 >>>> print mydlist > [{}, {'y': 4}] To check that you should instead have printed 'd', where you'd also see the change, since 'd' refers to the same dictionary object as 'mydlist[1]' does. > So I figure my initial example doesn't work because if you assign a > literal to something it is changing the object. No, it has nothing to do with literals. With the current language definition[2], as of Python 2.x and 3.x, it's very simple: assignments copy references, and that's all they do. References to immutable objects allow you to think of values being copied around, which except for checking the identities of those objects (seldom relevant) yields the exact same conclusions about the effect of operations, but that's only because those immutable objects never change. What you did above was to copy references to mutable objects, objects that can change. Then the value-copying view breaks down. > But modifying a list > or dict (as long as you don't re-construct it) does not change the > object. A simple way to think of this is copying references. Objects are never copied by Python assignments. The assignments only copy references. > I can think of some ways to work around this, including using single > element lists as "pointers": > >>>> aa=[1] >>>> bb=[2] >>>> myplist=[aa,bb] >>>> print myplist > [[1], [2]] >>>> aa[0]=3 >>>> print myplist > [[3], [2]] This is the same as your last example above, except that now you're using 'list' arrays as the referred to mutable objects, instead of 'dict' dictionary objects. > But what would be "the python way" to accomplish "list of variables" > functionality? Possibly, if you think of assignments as copying references, you won't need that notion. Cheers & hth., - Alf Notes: [1] The reference view can be relevant also for immutable objects in (at least) two cases. One is when the program logic depends on object identity, obtainable via the id function, which is just bad programming, but I mention it for completeness. The other is where you have a really large immutable object, such as in Python 2.x a very large 'long' value; then assignments would be inefficient if the value was actually copied, but since assignments only copy references in Python you can blissfully disregard the size of the object with respect to assignments. :-) [2] Some wording in the language spec requires that an assignment behaves as if references were copied, including preservation of object identity. But object identity is almost never an issue for immutable objects, and a relaxation of that wording, for immutable values, might permit some optimization. So it just might change somewhen in the future, trading simplicity for some efficiency. From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 15:45:31 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 09:45:31 +1300 Subject: A more specific query ... Message-ID: How can I interrogate Python to find out where it is looking to find the PyQt4 DLLs in a Windows installation? Secondarily, how is this search path set? From olivier.darge at gmail.com Fri Feb 26 15:51:34 2010 From: olivier.darge at gmail.com (OdarR) Date: Fri, 26 Feb 2010 12:51:34 -0800 (PST) Subject: any news from Python Magazine ? Message-ID: Seems rather late...: http://pythonmagazine.com/ "We'll be back, better than ever, on January 26th, 2010. " Olivier From mwilson at the-wire.com Fri Feb 26 15:52:00 2010 From: mwilson at the-wire.com (Mel) Date: Fri, 26 Feb 2010 15:52 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >> wrote: >>> Reminiscent of: >>> mov AX,BX ; Move the contents of BX into AX >> Well, there might be some confusion there as to what gets moved where, >> wouldn't you say? I guess this goes away after a couple of months, >> though. > I agree to that statement, I was surprised that mov AX,BX assumes that > BX is the source, and AX the destination. I never programmed in > assembler though. You could think of it as a not bad use of the design principle "Clear The Simple Stuff Out Of The Way First". Destinations are commonly a lot simpler than sources -- just as in Python assignment statements. So you can tell more or less at a glance what's going to be changed, then get into the deep analysis to find what it's going to be changed to. Mel. From patrick.just4fun at gmail.com Fri Feb 26 15:56:47 2010 From: patrick.just4fun at gmail.com (Patrick Sabin) Date: Fri, 26 Feb 2010 21:56:47 +0100 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= In-Reply-To: <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: <4B88358F.5000501@gmail.com> > Shelve looks like an interesting option, but what might pose an issue > is that I'm reading the data from a disk instead of memory. I didn't > mention this in my original post, but I was hoping that by using a > database it would be more memory efficient in storing data in RAM so I > wouldn't have to read from (or swap to/from) disk. A database usually stores data on disk and not in RAM. However you could use sqlite with :memory:, so that it runs in RAM. > Would using the > shelve package make reading/writing data from disk faster since it is > in a binary format? > Faster than what? Shelve uses caching, so it is likely to be faster than a self-made solution. However, accessing disk is much slower than accessing RAM. > Jeremy - Patrick From invalid at invalid.invalid Fri Feb 26 16:07:15 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 26 Feb 2010 21:07:15 +0000 (UTC) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: On 2010-02-26, Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >> wrote: >> >> >>> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >>> >>>> [stuff] >>>> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >> >> Well, there might be some confusion there as to what gets moved where, >> wouldn't you say? I guess this goes away after a couple of months, >> though. > > I agree to that statement, I was surprised that mov AX,BX assumes that > BX is the source, and AX the destination. I never programmed in > assembler though. It depends on the assembler. Some are dst, src and others are the other way around. Some vary depending on the instruction. -- Grant Edwards grante Yow! Sign my PETITION. at visi.com From qtrimble at gmail.com Fri Feb 26 16:08:28 2010 From: qtrimble at gmail.com (qtrimble) Date: Fri, 26 Feb 2010 13:08:28 -0800 (PST) Subject: loop through each line in a text file Message-ID: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> I'm a python newbie but I do have some basic scripting experience. I need to take the line starting with "wer" and extract the year and day of year from that string. I want to be able to add the year and day of year from the last line having "wer*" to the lines occurring in between "wer*" lines. Python seems suitable to do this and I'm fairly certain I can eventually get this to work but I've been hit with a very short time frame so I'm looking for any generous help. The data below is just a sample. There are well over 500,000 lines that need processed. wer1999001 31.2234 82.2367 37.9535 82.3456 wer1999002 31.2234 82.2367 37.9535 82.3456 From alfps at start.no Fri Feb 26 16:12:07 2010 From: alfps at start.no (Alf P. Steinbach) Date: Fri, 26 Feb 2010 22:12:07 +0100 Subject: loop through each line in a text file In-Reply-To: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> Message-ID: * qtrimble: > I'm a python newbie but I do have some basic scripting experience. I > need to take the line starting with "wer" and extract the year and day > of year from that string. I want to be able to add the year and day > of year from the last line having "wer*" to the lines occurring in > between "wer*" lines. Python seems suitable to do this and I'm fairly > certain I can eventually get this to work but I've been hit with a > very short time frame so I'm looking for any generous help. The data > below is just a sample. There are well over 500,000 lines that need > processed. > > wer1999001 > 31.2234 82.2367 > 37.9535 82.3456 > wer1999002 > 31.2234 82.2367 > 37.9535 82.3456 >>> line = "wer1999001" >>> line 'wer1999001' >>> line[3:3+4] '1999' >>> line[7:7+3] '001' >>> _ Cheers & hth., - Alf From olivier.darge at gmail.com Fri Feb 26 16:14:12 2010 From: olivier.darge at gmail.com (OdarR) Date: Fri, 26 Feb 2010 13:14:12 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> Message-ID: <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> On 26 f?v, 22:08, qtrimble wrote: > I'm a python newbie but I do have some basic scripting experience. ?I > need to take the line starting with "wer" and extract the year and day > of year from that string. ?I want to be able to add the year and day > of year from the last line having "wer*" to the lines occurring in > between "wer*" lines. ?Python seems suitable to do this and I'm fairly > certain I can eventually get this to work but I've been hit with a > very short time frame so I'm looking for any generous help. ?The data > below is just a sample. ?There are well over 500,000 lines that need > processed. > > wer1999001 > ? ? ? 31.2234 ? ? ?82.2367 > ? ? ? 37.9535 ? ? ?82.3456 > wer1999002 > ? ? ? 31.2234 ? ? ?82.2367 > ? ? ? 37.9535 ? ? ?82.3456 did you try something as a working basis ? Olivier From clp2 at rebertia.com Fri Feb 26 16:19:27 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 26 Feb 2010 13:19:27 -0800 Subject: A more specific query ... In-Reply-To: References: Message-ID: <50697b2c1002261319y7e71c958p7bf4f4be60902066@mail.gmail.com> On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle wrote: > How can I interrogate Python to find out where it is looking to find the > PyQt4 DLLs in a Windows installation? import sys print(sys.path) Cheers, Chris -- http://blog.rebertia.com From qtrimble at gmail.com Fri Feb 26 16:21:26 2010 From: qtrimble at gmail.com (qtrimble) Date: Fri, 26 Feb 2010 13:21:26 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> Message-ID: <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> On Feb 26, 4:14?pm, OdarR wrote: > On 26 f?v, 22:08, qtrimble wrote: > > > > > I'm a python newbie but I do have some basic scripting experience. ?I > > need to take the line starting with "wer" and extract the year and day > > of year from that string. ?I want to be able to add the year and day > > of year from the last line having "wer*" to the lines occurring in > > between "wer*" lines. ?Python seems suitable to do this and I'm fairly > > certain I can eventually get this to work but I've been hit with a > > very short time frame so I'm looking for any generous help. ?The data > > below is just a sample. ?There are well over 500,000 lines that need > > processed. > > > wer1999001 > > ? ? ? 31.2234 ? ? ?82.2367 > > ? ? ? 37.9535 ? ? ?82.3456 > > wer1999002 > > ? ? ? 31.2234 ? ? ?82.2367 > > ? ? ? 37.9535 ? ? ?82.3456 > > did you try something as a working basis ? > > Olivier Yes but it's very simple - fileIN = open(r"C:\testing.txt", "r") for line in fileIN: year = line[3:7] day = line[7:10] print year, day This is good since i can get the year and day of year into a variable but I haven't gotten any further. From pistacchio at gmail.com Fri Feb 26 16:26:44 2010 From: pistacchio at gmail.com (pistacchio) Date: Fri, 26 Feb 2010 13:26:44 -0800 (PST) Subject: random.gauss: range Message-ID: hi, i'm trying the random.gauss function. can anyone explain how to get a number between a given range? like, from 0 to 20 with an average of 10? and how to determine the "steep" of the curve? i've never studied it, so mu and sigma don't really tell me a thing. thanks in advange From lucat at despammed.com Fri Feb 26 16:30:58 2010 From: lucat at despammed.com (Luca) Date: Fri, 26 Feb 2010 22:30:58 +0100 Subject: Renaming identifiers & debugging In-Reply-To: References: <7unj59FuorU1@mid.individual.net> <7uo186FiejU1@mid.individual.net> <7uog65F5vuU1@mid.individual.net> Message-ID: <7uqssjFmeeU1@mid.individual.net> Roald de Vries wrote: > I would suggest to do choose the same strategy as 'from __future__ > import ...' takes, which does similar things and limits them to the > module it is used in. I would be curious to hear about your results. > > Kind regards, Roald Hi, well, i have thought on the issue and i think that i have found a solution that does not imply renaming the keywords. It mixes a bit the suggestions i got here and this is how. My application will have a text editor (with, hopefully, code highlighting) a text-box to insert "instant" commands and a text-box for the output and a window for the "turtle". With the "instant commands" you can insert little pieces of python code and see instantly their result both as a turtle movement or textual output. With the text-editor you can load/save/write whole python programs and execute or debug them step by step. The way to track the code could use this technique http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html which gives me exactly the number of line of code under execution and also stops the code until the function "treaceit" returns. This will allow me to insert breakpoints, execute the code line by line, and so on (or at least this is the theory). Now. Since i get the number of the line i don't need anymore to have the language deal with translated keywords. The kid can write the code in his/her own language and the program will "translate it back to english" before passing them to the embedded python. When i save a source file i can save the english version and translate it "on the fly" when i load it. I can also intercept error codes and translate them as well, showing the kid only what i want him/her to see. So it would be completely transparent to the kid and it would notice it only by opening the source code via a different text-editor. In this way the files produced are 100% python files and the kid can disable this feature if he doesn't like it. This will also allow me to translate the same piece of code in any language i want, with 0 effort and this way will allow kids of different nations exchange their code and have it working on their computer. This seems a good idea to me, it reaches my points without breaking compatibility. The kid will see the language in his own language but the computer will actually work with the standard-python file. Once i have this "ready" i can proceed to other steps and try to implement other ideas that i have (remember c-robots and p-robots?). Bye, Luca From g.bogle at auckland.ac.nz Fri Feb 26 16:41:20 2010 From: g.bogle at auckland.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 10:41:20 +1300 Subject: A more specific query ... In-Reply-To: <50697b2c1002261319y7e71c958p7bf4f4be60902066@mail.gmail.com> References: <50697b2c1002261319y7e71c958p7bf4f4be60902066@mail.gmail.com> Message-ID: <4B884000.5040900@auckland.ac.nz> The point of my question was that sys.path is clearly not being used in this case. When I start Python sys.path includes D:\python26\lib\site-packages which seems to be the Python default. Using sys.path.append I have tried adding both D:\python26\lib\site-packages\PyQt4 and D:\python26\lib\site-packages\PyQt4\bin to the path, but this has no effect. So far the only way I've found to make the PyQt4 DLLs visible to Python is by copying them from PyQt4\bin into PyQt4. I've tried adding stuff to the Windows PATH, but that has no effect. Gib Chris Rebert wrote: > On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle > wrote: >> How can I interrogate Python to find out where it is looking to find the >> PyQt4 DLLs in a Windows installation? > > import sys > print(sys.path) > > Cheers, > Chris > -- > http://blog.rebertia.com From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 16:44:41 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 10:44:41 +1300 Subject: A more specific query ... References: Message-ID: Chris Rebert wrote: > On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle > wrote: >> How can I interrogate Python to find out where it is looking to find the >> PyQt4 DLLs in a Windows installation? > > import sys > print(sys.path) Note this thread: http://www.mail-archive.com/pyqt at riverbankcomputing.com/msg20121.html I'm starting to get the impression that Windows is the 'poor relation' in the Python family ... From sanelson at gmail.com Fri Feb 26 16:54:33 2010 From: sanelson at gmail.com (Stephen Nelson-Smith) Date: Fri, 26 Feb 2010 13:54:33 -0800 (PST) Subject: Problems uploading to IIS using FTP over SSL References: Message-ID: <731c347e-df4d-4ff8-af82-22380abc8ad2@f35g2000yqd.googlegroups.com> On Feb 26, 2:05?pm, Stephen Nelson-Smith wrote: > Hello, I'm sorry - I hadn't realised that python-list ended up here as well. Sincere apologies for double-posting. S. From robert.kern at gmail.com Fri Feb 26 16:56:55 2010 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 26 Feb 2010 15:56:55 -0600 Subject: random.gauss: range In-Reply-To: References: Message-ID: On 2010-02-26 15:26 PM, pistacchio wrote: > hi, > i'm trying the random.gauss function. can anyone explain how to get a > number between a given range? You don't. The Gaussian distribution has infinite range. The best you can do with the standard library is to keep sampling until you get a number inside your desired range. If you aren't careful about your choice of parameters, this could waste a lot of time. > like, from 0 to 20 with an average of > 10? and how to determine the "steep" of the curve? i've never studied > it, so mu and sigma don't really tell me a thing. Study it: http://en.wikipedia.org/wiki/Normal_distribution mu is the mean, the location of the central peak. sigma is the standard deviation, which controls the width of the peak. Larger sigma means wider and shorter peak. You may want another distribution, like random.betavariate(): http://en.wikipedia.org/wiki/Beta_distribution -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From breamoreboy at yahoo.co.uk Fri Feb 26 16:59:16 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 26 Feb 2010 21:59:16 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4B881200.5060505@sequans.com> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <4B881200.5060505@sequans.com> Message-ID: Jean-Michel Pichavant wrote: > Andreas Waldenburger wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600 Tim Daneliuk >> wrote: >> >> >>> On 2/24/2010 2:23 PM, Andreas Waldenburger wrote: >>> >>>> [stuff] >>>> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >>> >>> >> Well, there might be some confusion there as to what gets moved where, >> wouldn't you say? I guess this goes away after a couple of months, >> though. >> > > I agree to that statement, I was surprised that mov AX,BX assumes that > BX is the source, and AX the destination. I never programmed in > assembler though. > > JM The obvious solution to this problem is to write the assembler code in your own way, and then use Python to change the code to the appropriate target. Any of the solutions listed here would presumably suffice. http://nedbatchelder.com/text/python-parsers.html Regards. Mark Lawrence. From python at bdurham.com Fri Feb 26 17:10:30 2010 From: python at bdurham.com (python at bdurham.com) Date: Fri, 26 Feb 2010 17:10:30 -0500 Subject: How to determine if threads are active in an application? Message-ID: <1267222230.24180.1362126901@webmail.messagingengine.com> Is there technique to determine if threads are active in a Python application? The only technique I can think of is to check sys.modules for thread and threading. But this will only show whether these modules were imported - not whether there are actually background threads running. Motivation: We were debugging a customer's python application and they had a module that was unknowningly (to both us and them) creating threads in certain situations. This made our debugging process more complicated because there were side effects happening at unexpected times that we couldn't explain. The module in question was supplied to us as a compiled module that was considered fully tested by the customer. To prevent this confusion in the future, we're looking for a way that we can detect threads are active while we're debugging without having to manually step through every line of code in every module to check for unexpected thread creation. Thanks, Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From ldo at geek-central.gen.new_zealand Fri Feb 26 17:22:09 2010 From: ldo at geek-central.gen.new_zealand (Lawrence D'Oliveiro) Date: Sat, 27 Feb 2010 11:22:09 +1300 Subject: Quoting quotes References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: In message , William Lohrmann wrote: > The best thing would be to backslash the single quote: print 'The play > "All\'s Well That Ends Well"' Backslash-type escapes are the most general solution to this type of problem. They?re also the easiest to apply automatically: for ch in input_string : if ch in troublesome_lot : output backslash + tame representation of ch else : output ch #end if #end for From breamoreboy at yahoo.co.uk Fri Feb 26 17:25:59 2010 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 26 Feb 2010 22:25:59 +0000 Subject: Six Minutes and fourty two seconds In-Reply-To: <63Vhn.92$1n5.11@newsfe04.iad> References: <63Vhn.92$1n5.11@newsfe04.iad> Message-ID: Tobiah wrote: > Now that I use python, this is the amount of time > per day that I spend adding forgotten semicolons while > debugging other languages. You think that's bad? I've spent hours today converting the J language that I don't dare mention to Python. Once in a blue moon I came across a line of code that actually did something. The rest of it was boilerplate. I'm never ever going to sin again, because if I do, I will be reincarnated as a J type, or worse still, I C(++) type. Regards. Mark Lawrence. No that's a swaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn!!!!! From jjposner at optimum.net Fri Feb 26 17:33:10 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 26 Feb 2010 17:33:10 -0500 Subject: loop through each line in a text file In-Reply-To: <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> Message-ID: <4B884C26.8010605@optimum.net> On 2/26/2010 4:21 PM, qtrimble wrote: > > fileIN = open(r"C:\testing.txt", "r") > > for line in fileIN: > year = line[3:7] > day = line[7:10] > print year, day > > This is good since i can get the year and day of year into a variable > but I haven't gotten any further. That's an excellent start. Here's another hint ... There are two kinds of lines in your input file: * lines that begin with "wer" * all other lines So you need an if-else section to process the lines in the input file: if line.startswith("wer"): # use the contents of *line* to assign values # to variables *year* and *day* ... else: # use the current values of *year* and *day* # to process the numbers extracted from *line* Most likely, you'll also need these functions: * split() -- chop a string into pieces * int() -- string-to-integer conversion HTH, John From aahz at pythoncraft.com Fri Feb 26 17:38:58 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 14:38:58 -0800 Subject: Dictionary or =?windows-1252?Q?Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: In article , Patrick Sabin wrote: > >A database usually stores data on disk and not in RAM. However you could >use sqlite with :memory:, so that it runs in RAM. The OP wants transparent caching, so :memory: wouldn't work. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From luismgz at gmail.com Fri Feb 26 17:41:04 2010 From: luismgz at gmail.com (=?ISO-8859-1?Q?Luis_M=2E_Gonz=E1lez?=) Date: Fri, 26 Feb 2010 14:41:04 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: On Feb 26, 12:58?pm, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? > > Thanks, > Jeremy For small quantities of data, dicts are ok, but if your app continually handles (and add) large quantities of data, you should use a database. You can start with sqlite (which is bundled with python) and it's much easier to use than any other relational database out there. You don't need to install anything, since it's not a database server. You simply save your databases as files. If you don't know sql (the standard language used to query databases), I recomend this online tutorial: http://www.sqlcourse.com/ Good luck! Luis From aahz at pythoncraft.com Fri Feb 26 17:42:22 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 14:42:22 -0800 Subject: Dictionary or Database‹Please advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: In article , Roy Smith wrote: > >Whatever database you pick, you're almost certainly going to end up having >to install it wherever you install your application. There's no such thing >as a universally available database that you can expect to be available >everywhere. ...unless you use SQLite. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Fri Feb 26 17:46:36 2010 From: aahz at pythoncraft.com (Aahz) Date: 26 Feb 2010 14:46:36 -0800 Subject: =?windows-1252?Q?Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: In article <891a98fa-c398-455a-981f-bf72af77256c at s36g2000prh.googlegroups.com>, Jeremy wrote: > >I have lots of data that I currently store in dictionaries. However, >the memory requirements are becoming a problem. I am considering >using a database of some sorts instead, but I have never used them >before. Would a database be more memory efficient than a dictionary? >I also need platform independence without having to install a database >and Python interface on all the platforms I'll be using. Is there >something built-in to Python that will allow me to do this? If you're serious about needing both a disk-based backing store *and* getting maximum use/performance from your RAM, you probably will need to combine memcached with one of the other solutions offered. But given your other requirement of not installing a DB, your best option will certainly be SQLite. You can use :memory: databases, but that will require shuttling data to disk manually. I suggest that you start with plain SQLite and only worry if you prove (repeat, PROVE) that DB is your bottleneck. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From phlip2005 at gmail.com Fri Feb 26 17:52:49 2010 From: phlip2005 at gmail.com (Phlip) Date: Fri, 26 Feb 2010 14:52:49 -0800 (PST) Subject: =?windows-1252?Q?Re=3A_Dictionary_or_Database=97Please_advise?= References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <6a1f738f-400b-458f-80f6-ac4cc097f2c2@f17g2000prh.googlegroups.com> On Feb 26, 7:58?am, Jeremy wrote: > I have lots of data that I currently store in dictionaries. ?However, > the memory requirements are becoming a problem. ?I am considering > using a database of some sorts instead, but I have never used them > before. ?Would a database be more memory efficient than a dictionary? > I also need platform independence without having to install a database > and Python interface on all the platforms I'll be using. ?Is there > something built-in to Python that will allow me to do this? If you had wall-to-wall unit tests, you could swap the database in incrementally ("Deprecation Refactor"). You would just add one database table, switch one client of one dictionary to use that table, pass all the tests, and integrate. Repeat until nobody uses the dicts, then trivially retire them. If you don't have unit tests, then you have a bigger problem than memory requirements. (You can throw $50 hardware at that!) -- Phlip http://penbird.tumblr.com/ From rurpy at yahoo.com Fri Feb 26 18:19:24 2010 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Fri, 26 Feb 2010 15:19:24 -0800 (PST) Subject: loop through each line in a text file References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> Message-ID: <121bb934-6d62-482a-a5c2-848668ce237d@q16g2000yqq.googlegroups.com> On Feb 26, 2:21?pm, qtrimble wrote: > On Feb 26, 4:14?pm, OdarR wrote: > > > > below is just a sample. ?There are well over 500,000 lines that need > > > processed. > > > > wer1999001 > > > ? ? ? 31.2234 ? ? ?82.2367 > > > ? ? ? 37.9535 ? ? ?82.3456 > > > wer1999002 > > > ? ? ? 31.2234 ? ? ?82.2367 > > > ? ? ? 37.9535 ? ? ?82.3456 > > > did you try something as a working basis ? > > > Olivier > > Yes but it's very simple - > > fileIN = open(r"C:\testing.txt", "r") > > for line in fileIN: > ? ? year = line[3:7] > ? ? day = line[7:10] > ? ? print year, day > > This is good since i can get the year and day of year into a variable > but I haven't gotten any further. How about something like (untested): for line in fileIN: if line.startswith ("wer"): year = line[3:7] day = line[7:10] else: print "%s-%s %s" % (year, day, line.strip()) You can adjust the details as needed... From maygeo at netplus.ch Fri Feb 26 18:32:27 2010 From: maygeo at netplus.ch (Raphael Mayoraz) Date: Fri, 26 Feb 2010 15:32:27 -0800 Subject: Variable definition Message-ID: <4B885A0B.9040705@netplus.ch> Hello, I'd like to define variables with some specific name that has a common prefix. Something like this: varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in varDic.iteritems(): 'myPrefix' + key = value I know this is illegal, but there must be a trick somewhere. Thanks, Raphael From aleksandr.goretoy at gmail.com Fri Feb 26 18:48:56 2010 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Fri, 26 Feb 2010 17:48:56 -0600 Subject: loop through each line in a text file In-Reply-To: <4B884C26.8010605@optimum.net> References: <3484373a-2045-428e-9040-abdfecd95e25@f35g2000yqd.googlegroups.com> <07a7edd4-9e72-4425-865b-f475c2050ea7@z11g2000yqz.googlegroups.com> <22084c82-0f69-46b0-883f-ef1d3c47d792@o3g2000yqb.googlegroups.com> <4B884C26.8010605@optimum.net> Message-ID: I smell homework -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Fri Feb 26 18:58:54 2010 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 27 Feb 2010 10:58:54 +1100 Subject: Get dosctring without import References: <120f4b93-e7d0-4f58-9f3b-0490be01cdd9@k5g2000pra.googlegroups.com> <87bpfc46ee.fsf@benfinney.id.au> <76cde733-17b2-41ae-8e59-734e4c5d6fd6@d2g2000yqa.googlegroups.com> <87635k41kd.fsf@benfinney.id.au> <8777b981-6ca8-49b2-93d8-4b37b2f99b79@k17g2000yqb.googlegroups.com> Message-ID: <87pr3r35xd.fsf@benfinney.id.au> Joan Miller writes: > On 26 feb, 12:35, Ben Finney wrote: > > A common convention is to have a ?README? text file, written in > > reStructuredText for rendering to various output formats as part of > > the documentation. You could then have the ?setup.py? program read > > the contents of that file and use it (or a slice of it) for the > > package description. > I get the 'README.txt' file to get the long description but I use the > docstring because each package should include a short desciption about > it. I keep both in the same file: ===== README ===== FooBar, a library for spangulation. The FooBar library provides thribbles which can be easily frobnicated for spangulation in a sntandard manner. Other spangulation libraries are far less weebly than this one, which is the choice of discerning grognards everywhere. ===== Then, the description fields are derived by splitting the file's contents on the first paragraph break: ===== from distutils.core import setup readme_file = open("README") short_description, long_description = ( d.strip() for d in readme_file.read().split(u'\n\n', 1)) setup( # ? description=short_description, long_description=long_description, # ? ) ===== -- \ ?Some forms of reality are so horrible we refuse to face them, | `\ unless we are trapped into it by comedy. To label any subject | _o__) unsuitable for comedy is to admit defeat.? ?Peter Sellers | Ben Finney From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 19:00:32 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 13:00:32 +1300 Subject: A more specific query ... References: Message-ID: <4B8860A0.6050600@auckland.no.spam.ac.nz> The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not occur with Python 2.5 and the previous PyQt I was using (4.5, I think), it seems that something has changed either with Python 2.6 or with PyQt 4.7. It would be very nice to learn how to fix this without renaming directories, since I use Matlab frequently. Gib From g.bogle at auckland.no.spam.ac.nz Fri Feb 26 19:01:11 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 13:01:11 +1300 Subject: A more specific query ... References: Message-ID: The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not occur with Python 2.5 and the previous PyQt I was using (4.5, I think), it seems that something has changed either with Python 2.6 or with PyQt 4.7. It would be very nice to learn how to fix this without renaming directories, since I use Matlab frequently. Gib From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 19:02:40 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 00:02:40 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <4b88611f$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > Reminiscent of: > > mov AX,BX ; Move the contents of BX into AX That's a *good* comment, because without it most English-speaking people would assume you were moving the contents of AX into BX. > And, yes, I've actually seen that as well as: > > ; This is a comment Which might be a good comment, if it were part of an unfamiliar file format where the reader were not expected to know what is a comment and what is significant. For instance, I've seen similar comments at the top of config files. However, I'm pretty sure that a comment like this is inexcusable: x = x + 1 # Add one to x. -- Steven From routb3d at gmail.com Fri Feb 26 19:06:56 2010 From: routb3d at gmail.com (Routb3d) Date: Fri, 26 Feb 2010 16:06:56 -0800 (PST) Subject: importing libraries not working 2.6.4 Message-ID: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. I have tried adjusting environment variables as well as putting the files directly in the search path of Python.. Python still returns this.. Any ideas? >>> import sys >>> sys.path ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ \site-packages'] >>> import cv Traceback (most recent call last): File "", line 1, in import cv ImportError: DLL load failed: The specified module could not be found. Any help would be greatly appreciated. From rhodri at wildebst.demon.co.uk Fri Feb 26 19:15:22 2010 From: rhodri at wildebst.demon.co.uk (Rhodri James) Date: Sat, 27 Feb 2010 00:15:22 -0000 Subject: Variable definition References: Message-ID: On Fri, 26 Feb 2010 23:32:27 -0000, Raphael Mayoraz wrote: > I'd like to define variables with some specific name that has a common > prefix. Why? No seriously, how do you think this is going to solve whatever problem you clearly think it will solve? -- Rhodri James *-* Wildebeeste Herder to the Masses From alfps at start.no Fri Feb 26 19:22:24 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 27 Feb 2010 01:22:24 +0100 Subject: Variable definition In-Reply-To: References: Message-ID: * Raphael Mayoraz: > Hello, > > I'd like to define variables with some specific name that has a common > prefix. > Something like this: > > varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} > for key, value in varDic.iteritems(): > 'myPrefix' + key = value > > I know this is illegal, but there must be a trick somewhere. In general you'll IMHO be better off with the variables as attributes of an object. If you want them to be modifiable then you can do class Whatever: pass myPrefix = Whatever() myPrefix.a = 'a' myPrefix.b = 'b' myPrefix.c = 'c' If you want them to be sort of constants (weasel words intentional) then you might do (Python 3.x) -- disclaimer: off-the-cuff & I'm not sure if that function is called 'namedtuple' but I think you'll find it anyway -- import collections Color = namedtuple( "Color", "red green blue" ) myPrefix = Color( 'a', 'b', 'c' ) Cheers & hth., - Alf From rami.chowdhury at gmail.com Fri Feb 26 19:30:54 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 26 Feb 2010 16:30:54 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> Message-ID: <201002261630.54323.rami.chowdhury@gmail.com> On Friday 26 February 2010 16:06:56 Routb3d wrote: > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. > > I have tried adjusting environment variables as well as putting the > files directly in the search path of Python.. Python still returns > this.. Any ideas? Where are you expecting the cv module / package to be? It's certainly not in the standard library -- at least not in my install of Python 2.6.4... > > >>> import sys > >>> sys.path > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ > \site-packages'] > > >>> import cv > > Traceback (most recent call last): > File "", line 1, in > import cv > ImportError: DLL load failed: The specified module could not be found. > > > Any help would be greatly appreciated. ---- Rami Chowdhury "Strangers are just friends who haven't had enough gin." -- Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From aleksandr.goretoy at gmail.com Fri Feb 26 19:41:43 2010 From: aleksandr.goretoy at gmail.com (alex goretoy) Date: Fri, 26 Feb 2010 18:41:43 -0600 Subject: Variable definition In-Reply-To: References: Message-ID: On Fri, Feb 26, 2010 at 6:22 PM, Alf P. Steinbach wrote: > * Raphael Mayoraz: > >> Hello, >> >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >> for key, value in varDic.iteritems(): >> 'myPrefix' + key = value >> >> I know this is illegal, but there must be a trick somewhere. >> > > In general you'll IMHO be better off with the variables as attributes of an > object. > > If you want them to be modifiable then you can do > > class Whatever: pass > > myPrefix = Whatever() > myPrefix.a = 'a' > myPrefix.b = 'b' > myPrefix.c = 'c' > > If you want them to be sort of constants (weasel words intentional) then > you might do (Python 3.x) -- disclaimer: off-the-cuff & I'm not sure if > that function is called 'namedtuple' but I think you'll find it anyway -- > > import collections > > Color = namedtuple( "Color", "red green blue" ) > myPrefix = Color( 'a', 'b', 'c' ) > > > Cheers & hth., > > - Alf > > -- > http://mail.python.org/mailman/listinfo/python-list > you can use setattr to do your bidding for setting variable like this. That is how I've been able to do it. Not sure if its the best solution, but it is a solution. I just don't know how to use setattr without it being in a class. >>> class stuff(object): ... def __init__(self): ... pass ... def duuit(self,abc): ... for k,v in abc.items(): ... setattr(self,"prefix_%s"%k,v) ... >>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} >>> abc=stuff() >>> abc.duuit(varDic) >>> dir(abc) ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'duuit', 'prefix_blue', 'prefix_green', 'prefix_red'] >>> -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From pistacchio at gmail.com Fri Feb 26 19:46:10 2010 From: pistacchio at gmail.com (pistacchio) Date: Fri, 26 Feb 2010 16:46:10 -0800 (PST) Subject: random.gauss: range References: Message-ID: <7a49b554-2b53-4878-8150-89fafba210e9@y17g2000yqd.googlegroups.com> thanks, betadistribute did the work... and i learned a new thing! On 26 Feb, 22:56, Robert Kern wrote: > On 2010-02-26 15:26 PM, pistacchio wrote: > > > hi, > > i'm trying the random.gauss function. can anyone explain how to get a > > number between a given range? > > You don't. The Gaussian distribution has infinite range. The best you can do > with the standard library is to keep sampling until you get a number inside your > desired range. If you aren't careful about your choice of parameters, this could > waste a lot of time. > > > like, from 0 to 20 with an average of > > 10? and how to determine the "steep" of the curve? i've never studied > > it, so mu and sigma don't really tell me a thing. > > Study it: > > ? ?http://en.wikipedia.org/wiki/Normal_distribution > > mu is the mean, the location of the central peak. sigma is the standard > deviation, which controls the width of the peak. Larger sigma means wider and > shorter peak. > > You may want another distribution, like random.betavariate(): > > ? ?http://en.wikipedia.org/wiki/Beta_distribution > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ? that is made terrible by our own mad attempt to interpret it as though it had > ? an underlying truth." > ? ?-- Umberto Eco From python at rcn.com Fri Feb 26 19:46:21 2010 From: python at rcn.com (Raymond Hettinger) Date: Fri, 26 Feb 2010 16:46:21 -0800 (PST) Subject: random.gauss: range References: Message-ID: <1cb0bf77-a539-41ff-89f3-b55e423a1b32@b7g2000pro.googlegroups.com> On Feb 26, 1:26?pm, pistacchio wrote: > hi, > i'm trying the random.gauss function. can anyone explain how to get a > number between a given range? like, from 0 to 20 with an average of > 10? and how to determine the "steep" of the curve? i've never studied > it, so mu and sigma don't really tell me a thing. Try random.randrange() and random.triangular(). They are both easy to use and do not require you to enter parameters that you don't understand. FWIW, mu and sigma refer to the average and standard deviation of a normal distribution. Raymond From john at castleamber.com Fri Feb 26 19:47:26 2010 From: john at castleamber.com (John Bokma) Date: Fri, 26 Feb 2010 18:47:26 -0600 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <87635j4i8x.fsf@castleamber.com> Steven D'Aprano writes: > On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX > > > That's a *good* comment, because without it most English-speaking people > would assume you were moving the contents of AX into BX. Eh? It's a bad comment, it's of the same quality as: > x = x + 1 # Add one to x. You think the former is good because (I guess) you are not familiar with the language. The same reason why beginners comment their code like in your example. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From python at mrabarnett.plus.com Fri Feb 26 19:54:53 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Feb 2010 00:54:53 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4b88611f$0$27844$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B886D5D.4080908@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > >> Reminiscent of: >> >> mov AX,BX ; Move the contents of BX into AX > > > That's a *good* comment, because without it most English-speaking people > would assume you were moving the contents of AX into BX. > [snip] If you're reading and/or writing at assembly language level then you should know what it does anyway! The assembly languages of virtually all the processors that I've come across put the destination first, eg. x86: SUB AX,BX MOV AX,BX which does: AX := AX - BX AX := BX and ARM: SUB R0,R1,R2 MOV R0,R1 which does: R0 := R1 - R2 R0 := R1 The only assembly language I know of which does it the other way round is 68x00: SUB D0,D1 MOVE D0,D1 which does: D1 := D1 - D0 D1 := D0 I know which I prefer! :-) From alfps at start.no Fri Feb 26 20:10:26 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 27 Feb 2010 02:10:26 +0100 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: * MRAB: > Steven D'Aprano wrote: >> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >> >> >> That's a *good* comment, because without it most English-speaking >> people would assume you were moving the contents of AX into BX. >> > [snip] > If you're reading and/or writing at assembly language level then you > should know what it does anyway! > > The assembly languages of virtually all the processors that I've come > across put the destination first, eg. x86: > > SUB AX,BX > MOV AX,BX > > which does: > > AX := AX - BX > AX := BX > A bit off-topic, but there are /two/ main syntaxes for x86 assembly, namely Intel syntax (the above syntax, used by MASM, old TASM etc.) and AT&T syntax. C:\test> echo int main(){ int x = 42; } >blah.cpp C:\test> g++ blah.cpp -S -masm=intel C:\test> type blah.s | find "42" mov DWORD PTR [ebp-4], 42 C:\test> g++ blah.cpp -S -masm=att C:\test> type blah.s | find "42" movl $42, -4(%ebp) C:\test> _ Personally I find the AT&T syntax very hard to read. All those percent signs hurt my eyes... > and ARM: > > SUB R0,R1,R2 > MOV R0,R1 > > which does: > > R0 := R1 - R2 > R0 := R1 > > The only assembly language I know of which does it the other way round > is 68x00: > > SUB D0,D1 > MOVE D0,D1 > > which does: > > D1 := D1 - D0 > D1 := D0 > > I know which I prefer! :-) Cheers, - Alf From jjposner at optimum.net Fri Feb 26 20:15:16 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 26 Feb 2010 20:15:16 -0500 Subject: Variable definition In-Reply-To: <4B885A0B.9040705@netplus.ch> References: <4B885A0B.9040705@netplus.ch> Message-ID: <4B887224.2080805@optimum.net> On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: > Hello, > > I'd like to define variables with some specific name that has a common > prefix. > Something like this: > > varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} > for key, value in varDic.iteritems(): > 'myPrefix' + key = value > No trick, just swap a new key-value pair for each existing pair: for key, value in varDic.iteritems(): varDic[myPrefix + key] = value del varDict[key] Just make sure that *myPrefix* isn't an empty string! -John From rami.chowdhury at gmail.com Fri Feb 26 21:12:23 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 26 Feb 2010 18:12:23 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> <201002261630.54323.rami.chowdhury@gmail.com> Message-ID: <201002261812.23265.rami.chowdhury@gmail.com> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: > Thanks for the reply. > > I tried putting the files from > > C:\OpenCV2.0\Python2.6\Lib > > too > > C:\Python26\Lib\site-packages > > and Python still wont import.. > > I adjusted the environment variables to try and import maya.standalone but > no dice on that either. > Sorry, you've still not told me where you expect it to be. Could you let us know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? > > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury wrote: > > On Friday 26 February 2010 16:06:56 Routb3d wrote: > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. > > > > > > I have tried adjusting environment variables as well as putting the > > > files directly in the search path of Python.. Python still returns > > > this.. Any ideas? > > > > Where are you expecting the cv module / package to be? It's certainly not > > in > > the standard library -- at least not in my install of Python 2.6.4... > > > > > >>> import sys > > > >>> sys.path > > > > > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ > > > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', > > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- > > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ > > > \site-packages'] > > > > > > >>> import cv > > > > > > Traceback (most recent call last): > > > File "", line 1, in > > > > > > import cv > > > > > > ImportError: DLL load failed: The specified module could not be found. > > > > > > > > > Any help would be greatly appreciated. > > > > ---- > > Rami Chowdhury > > "Strangers are just friends who haven't had enough gin." -- Howdle's > > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) ---- Rami Chowdhury "Ninety percent of everything is crap." -- Sturgeon's Law 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From no.email at nospam.invalid Fri Feb 26 21:16:25 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 26 Feb 2010 18:16:25 -0800 Subject: Dictionary or =?utf-8?Q?Database=E2=80=94Please?= advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> Message-ID: <7xeik7h18m.fsf@ruckus.brouhaha.com> Jeremy writes: > I have lots of data that I currently store in dictionaries. However, > the memory requirements are becoming a problem. I am considering > using a database of some sorts instead, but I have never used them > before. Would a database be more memory efficient than a dictionary? What are you trying to do? Yes, a database would let you use disk instead of ram, but the slowdown might be intolerable depending on the access pattern. You really have to consider what the whole application is up to, and what the database is doing for you. It might be imposing a high overhead to create benefits (e.g. transaction isolation) that you're not actually using. Somehow I've managed to do a lot of programming on large datasets without ever using databases very much. I'm not sure that's a good thing; but anyway, a lot of times you can do better with externally sorted flat files, near-line search engines, etc. than you can with databases. If the size of your data is fixed or is not growing too fast, and it's larger than your computer's memory by just a moderate amount (e.g. you have a 2GB computer and 3GB of data), the simplest approach may be to just buy a few more ram modules and put them in your computer. From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 21:21:04 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 02:21:04 GMT Subject: =?windows-1251?q?Re=3A_Dictionary_or_Database=97Please?= advise References: <891a98fa-c398-455a-981f-bf72af77256c@s36g2000prh.googlegroups.com> <6e36f40e-eb33-4038-9896-5fb1cceb2a32@q2g2000pre.googlegroups.com> Message-ID: <4b888190$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 21:56:47 +0100, Patrick Sabin wrote: >> Shelve looks like an interesting option, but what might pose an issue >> is that I'm reading the data from a disk instead of memory. I didn't >> mention this in my original post, but I was hoping that by using a >> database it would be more memory efficient in storing data in RAM so I >> wouldn't have to read from (or swap to/from) disk. > > A database usually stores data on disk and not in RAM. However you could > use sqlite with :memory:, so that it runs in RAM. The OP started this thread with: "I have lots of data that I currently store in dictionaries. However, the memory requirements are becoming a problem." So I'm amused that he thinks the solution to running out of memory is to run the heavy overhead of a database entirely in memory, instead of lightweight dicts :) My advice is, first try to optimize your use of dicts. Are you holding onto large numbers of big dicts that you don't need? Are you making unnecessary copies? If so, fix your algorithms. If you can't optimize the dicts anymore, then move to a proper database. Don't worry about whether it is on-disk or not, databases tend to be pretty fast regardless, and it is better to run your application a little bit more slowly than to not run it at all because it ran out of memory halfway through processing the data. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 21:52:54 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 02:52:54 GMT Subject: random.gauss: range References: Message-ID: <4b888905$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 13:26:44 -0800, pistacchio wrote: > hi, > i'm trying the random.gauss function. can anyone explain how to get a > number between a given range? like, from 0 to 20 with an average of 10? That's not what a Gaussian distribution does. It has an infinite range. Are you sure you want a Gaussian, and not a uniform distribution or a triangular distribution? You could pin the values to the appropriate range: def pinned_gaussian(a, b, mu, sigma): """Return a Gaussian random number pinned to [a, b].""" return min(b, max(a, random.gauss(mu, sigma))) but that will distort the randomness slightly: you will have a slight excess of values equal to a and b than you otherwise might expect. You might not care, though, particularly if the sigma is very small relative to the minimum and maximum you want. Alternatively, you could use this approach: def truncated_gauss(a, b, mu, sigma): """Return a random number from a truncated Gaussian distribution.""" while 1: x = random.gauss(mu, sigma) if a <= x <= b: return x > and how to determine the "steep" of the curve? i've never studied it, so > mu and sigma don't really tell me a thing. mu is the average -- in your example above, mu would be 10. sigma is the standard deviation of the random variable. It tells you how much the random variable actually varies: if sigma is close to zero, most of the numbers will be close to mu and the graph will look like a spike; if sigma is large, it will be very broad and flat. Statistically, the following rules apply: 68% of the numbers will be between (mu - sigma) and (mu + sigma). 95% of the numbers will be between (mu - 2*sigma) and (mu + 2*sigma). 99.7% of the numbers will be between (mu - 3*sigma) and (mu + 3*sigma). (the percentages are approximate, not exact). So you could get a reasonable approximation to a normal distribution truncated between 0 and 20 with: truncated_gauss(0, 20, 10, 10.0/3) -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 22:15:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 03:15:47 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> Message-ID: <4b888e62$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 18:47:26 -0600, John Bokma wrote: > Steven D'Aprano writes: > >> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >> >>> Reminiscent of: >>> >>> mov AX,BX ; Move the contents of BX into AX >> >> >> That's a *good* comment, because without it most English-speaking >> people would assume you were moving the contents of AX into BX. > > Eh? It's a bad comment, it's of the same quality as: > >> x = x + 1 # Add one to x. > > You think the former is good because (I guess) you are not familiar with > the language. The same reason why beginners comment their code like in > your example. Well, in the second example, x+1 could not possibly be anything other than adding one to x in any language, programming or human: using "+" for addition is close enough to universal these days. Unless x is some fancy object that plays operator overloading tricks, then what else could x+1 be? On the other hand, mv AX,BX is not only ambiguous but in the example given the move occurs in the counter-intuitive direction, at least for English-speakers and probably most speakers of European languages. So even an experienced coder might like the reminder that this specific assembly language moves things backwards compared to his intuition, or compared to the way the rest of the language does things. Admittedly an experienced coder might be so used to that syntax that he no longer needs the comment, in which case he might find it unnecessary. But comments aren't written for the benefit of people who find it obvious. They're written for everyone else. ANY comment could be dismissed as unnecessary for somebody who is so familiar with the language and code in question that it is obvious what it is doing. Also, some assemblies perform the move in different directions according to the arguments. So you might have: mv AX,BX ; move contents of BX into AX mv @CX,DX ; move contents of @CX into DX Horrible, yes, but apparently some assembly languages did something like that. -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 22:20:18 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 03:20:18 GMT Subject: Variable definition References: <4B885A0B.9040705@netplus.ch> Message-ID: <4b888f72$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote: > On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >> Hello, >> >> I'd like to define variables with some specific name that has a common >> prefix. >> Something like this: >> >> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in >> varDic.iteritems(): 'myPrefix' + key = value >> >> > No trick, just swap a new key-value pair for each existing pair: > > for key, value in varDic.iteritems(): > varDic[myPrefix + key] = value > del varDict[key] > > Just make sure that *myPrefix* isn't an empty string! How does that answer the original poster's question? Admittedly, your solution is the Right Way To Do It, but what the OP wants is to go from a dict {'spam': 42} to a named variable myPrefixspam = 42, which is a totally bogus thing to do, but incredibly common among n00bs and refugees from horrible languages that allow that sort of abomination. -- Steven From python at mrabarnett.plus.com Fri Feb 26 22:25:47 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 27 Feb 2010 03:25:47 +0000 Subject: Docstrings considered too complicated In-Reply-To: <4b888e62$0$27844$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B8890BB.8080902@mrabarnett.plus.com> Steven D'Aprano wrote: > On Fri, 26 Feb 2010 18:47:26 -0600, John Bokma wrote: > >> Steven D'Aprano writes: >> >>> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >>> >>>> Reminiscent of: >>>> >>>> mov AX,BX ; Move the contents of BX into AX >>> >>> That's a *good* comment, because without it most English-speaking >>> people would assume you were moving the contents of AX into BX. >> Eh? It's a bad comment, it's of the same quality as: >> >>> x = x + 1 # Add one to x. >> You think the former is good because (I guess) you are not familiar with >> the language. The same reason why beginners comment their code like in >> your example. > > Well, in the second example, x+1 could not possibly be anything other > than adding one to x in any language, programming or human: using "+" for > addition is close enough to universal these days. Unless x is some fancy > object that plays operator overloading tricks, then what else could x+1 > be? > > On the other hand, mv AX,BX is not only ambiguous but in the example > given the move occurs in the counter-intuitive direction, at least for > English-speakers and probably most speakers of European languages. So > even an experienced coder might like the reminder that this specific > assembly language moves things backwards compared to his intuition, or > compared to the way the rest of the language does things. > > Admittedly an experienced coder might be so used to that syntax that he > no longer needs the comment, in which case he might find it unnecessary. > But comments aren't written for the benefit of people who find it > obvious. They're written for everyone else. ANY comment could be > dismissed as unnecessary for somebody who is so familiar with the > language and code in question that it is obvious what it is doing. > > Also, some assemblies perform the move in different directions according > to the arguments. So you might have: > > mv AX,BX ; move contents of BX into AX > mv @CX,DX ; move contents of @CX into DX > > Horrible, yes, but apparently some assembly languages did something like > that. > Ah, yes, "apparently". That's like saying "someone down the pub told me...". ;-) From jjposner at optimum.net Fri Feb 26 22:33:53 2010 From: jjposner at optimum.net (John Posner) Date: Fri, 26 Feb 2010 22:33:53 -0500 Subject: Variable definition In-Reply-To: <4b888f72$0$27844$c3e8da3@news.astraweb.com> References: <4B885A0B.9040705@netplus.ch> <4b888f72$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B8892A1.7020902@optimum.net> On 2/26/2010 10:20 PM, Steven D'Aprano wrote: > On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote: > >> On 2/26/2010 6:32 PM, Raphael Mayoraz wrote: >>> Hello, >>> >>> I'd like to define variables with some specific name that has a common >>> prefix. >>> Something like this: >>> >>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in >>> varDic.iteritems(): 'myPrefix' + key = value >>> >>> >> No trick, just swap a new key-value pair for each existing pair: >> >> for key, value in varDic.iteritems(): >> varDic[myPrefix + key] = value >> del varDict[key] >> >> Just make sure that *myPrefix* isn't an empty string! > > How does that answer the original poster's question? > > Admittedly, your solution is the Right Way To Do It, but what the OP > wants is to go from a dict {'spam': 42} to a named variable myPrefixspam > = 42, which is a totally bogus thing to do, but incredibly common among > n00bs and refugees from horrible languages that allow that sort of > abomination. Yup, I misinterpreted the OP's intent. I guess my mind just couldn't encompass the enormity of his intended transgression. -John From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 22:33:57 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 03:33:57 GMT Subject: Variable definition References: Message-ID: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 15:32:27 -0800, Raphael Mayoraz wrote: > Hello, > > I'd like to define variables with some specific name that has a common > prefix. > Something like this: > > varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} > for key, value in varDic.iteritems(): > 'myPrefix' + key = value > > I know this is illegal, but there must be a trick somewhere. The Right answer is: Don't do that. How can you use a variable without knowing its name? Suppose you do this: for key, value in varDic.iteritems(): 'myPrefix_' + key = value and then later you want: print myPrefix_blue But hang on. How could you possibly know it is called myPrefix_blue and not myPrefix_cyan or myPrefix_turquoise? You can't possibly know, so in general defining a named variable is useless. What you want instead is: some_colour = 'blue' # get this at runtime print varDic[some_colour] You don't even need the myPrefix, but if you really want it: for key, value in varDic.iteritems(): varDic['myPrefix_' + key] = value del varDic[key] some_colour = 'blue' # get this at runtime print varDic['myPrefix_' + some_colour] or any one of a million variations on this idea. For some very, very rare situations you might need to programatically define variables. The right way to do that is: globals()['myPrefix_turquoise'] = 42 or setattr(module, 'myPrefix_turquoise'] = 42 or even: exec "'myPrefix_turquoise' = 42" but if you are thinking of using that last one with data coming from an untrusted user (and nearly all users are untrusted!), then DON'T. That is a huge security hole. And it's also very slow. -- Steven From tundra at tundraware.com Fri Feb 26 22:51:17 2010 From: tundra at tundraware.com (Tim Daneliuk) Date: Fri, 26 Feb 2010 21:51:17 -0600 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2/26/2010 9:25 PM, MRAB wrote: > Steven D'Aprano wrote: >> On Fri, 26 Feb 2010 18:47:26 -0600, John Bokma wrote: >> >>> Steven D'Aprano writes: >>> >>>> On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: >>>> >>>>> Reminiscent of: >>>>> >>>>> mov AX,BX ; Move the contents of BX into AX >>>> >>>> That's a *good* comment, because without it most English-speaking >>>> people would assume you were moving the contents of AX into BX. >>> Eh? It's a bad comment, it's of the same quality as: >>> >>>> x = x + 1 # Add one to x. >>> You think the former is good because (I guess) you are not familiar with >>> the language. The same reason why beginners comment their code like in >>> your example. >> >> Well, in the second example, x+1 could not possibly be anything other >> than adding one to x in any language, programming or human: using "+" >> for addition is close enough to universal these days. Unless x is some >> fancy object that plays operator overloading tricks, then what else >> could x+1 be? >> >> On the other hand, mv AX,BX is not only ambiguous but in the example >> given the move occurs in the counter-intuitive direction, at least for >> English-speakers and probably most speakers of European languages. So >> even an experienced coder might like the reminder that this specific >> assembly language moves things backwards compared to his intuition, or >> compared to the way the rest of the language does things. >> >> Admittedly an experienced coder might be so used to that syntax that >> he no longer needs the comment, in which case he might find it >> unnecessary. But comments aren't written for the benefit of people who >> find it obvious. They're written for everyone else. ANY comment could >> be dismissed as unnecessary for somebody who is so familiar with the >> language and code in question that it is obvious what it is doing. >> >> Also, some assemblies perform the move in different directions >> according to the arguments. So you might have: >> >> mv AX,BX ; move contents of BX into AX >> mv @CX,DX ; move contents of @CX into DX >> >> Horrible, yes, but apparently some assembly languages did something >> like that. >> > Ah, yes, "apparently". That's like saying "someone down the pub told > me...". ;-) It's interesting that my silly example raised this amount of commentary. My general view about all this is that comments should be written on the assumption that the reader knows the language in question. It is not the purpose of a comment to provide a tutorial on the language (unless you're actually writing a tutorial program). Rather, a comment should illuminate the *logic* of the activity by either amplifying, clarifying, or otherwise providing a rationale' for the code in question. Demanding that programmers provide comments about the syntax and semantics of the language is - to me - absurd. For example, some time ago, I was doing some programming with embedded PIC-based hardware. The comments for that code are intended to illuminate how the *hardware* was being exploited, not how to use PIC asm: ... scan: incf current_col,F ; pickup next column to scan movlw MAX_COL+1 ; if current_col > MAX_COL then subwf current_col,W ; we just did last column, so start over btfss STATUS,Z ; zero means we need to start over goto key_scan ; nope, go look for key hits clrf current_col ; yes, reinit column counter goto scan ... The only possible exception to this I can think of is when there is some non-obvious side-effect (i.e. language and/or hardware is "misfeatured"): mov A,B ; Moving A into B also will also arm ; the nuclear warhead if the CPU is ; hotter than 110C -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From rami.chowdhury at gmail.com Fri Feb 26 22:53:53 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Fri, 26 Feb 2010 19:53:53 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> <201002261630.54323.rami.chowdhury@gmail.com> <201002261812.23265.rami.chowdhury@gmail.com> Message-ID: <06689ACA-B76B-4558-B121-A175CEB50C24@gmail.com> On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote: > C:\OpenCV2.0\Python2.6\Lib\site-packages > > no .py files here.. > > cv.pyd > libcv.dll.a > > > C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv > > _init_.py > matlan_syntax.py > adaptors.py > cv.py > It looks to me like 'opencv' is structured as a package, from which you should be able to import and work with Python libraries. Have you tried putting the above site-packages directory in sys.path: import sys; sys.path.append('C:\\OpenCV2.0\\Python2.6\\Lib\\site-packages') and then doing: from opencv import cv ? > Did I still need to compile this even though it was a win 32 installer? I don't think so, no -- AFAIK the .pyd files are compiled CPython extension modules, so it looks like they're all compiled for you. ------------- Rami Chowdhury "Never assume malice when stupidity will suffice." -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > > > On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury wrote: > On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: > > Thanks for the reply. > > > > I tried putting the files from > > > > C:\OpenCV2.0\Python2.6\Lib > > > > too > > > > C:\Python26\Lib\site-packages > > > > and Python still wont import.. > > > > I adjusted the environment variables to try and import maya.standalone but > > no dice on that either. > > > > Sorry, you've still not told me where you expect it to be. Could you let us > know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? > > > > > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury > wrote: > > > On Friday 26 February 2010 16:06:56 Routb3d wrote: > > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 pro. > > > > > > > > I have tried adjusting environment variables as well as putting the > > > > files directly in the search path of Python.. Python still returns > > > > this.. Any ideas? > > > > > > Where are you expecting the cv module / package to be? It's certainly not > > > in > > > the standard library -- at least not in my install of Python 2.6.4... > > > > > > > >>> import sys > > > > >>> sys.path > > > > > > > > ['C:\\Python26\\Lib\\idlelib', 'C:\\Program Files\\Autodesk\\Maya2010\ > > > > \Python\\Lib\\site-packages', 'C:\\Windows\\system32\\python26.zip', > > > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat- > > > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\ > > > > \site-packages'] > > > > > > > > >>> import cv > > > > > > > > Traceback (most recent call last): > > > > File "", line 1, in > > > > > > > > import cv > > > > > > > > ImportError: DLL load failed: The specified module could not be found. > > > > > > > > > > > > Any help would be greatly appreciated. > > > > > > ---- > > > Rami Chowdhury > > > "Strangers are just friends who haven't had enough gin." -- Howdle's > > > Saying 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) > > > ---- > Rami Chowdhury > "Ninety percent of everything is crap." -- Sturgeon's Law > 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) > -------------- next part -------------- An HTML attachment was scrubbed... URL: From darcy at druid.net Fri Feb 26 23:02:35 2010 From: darcy at druid.net (D'Arcy J.M. Cain) Date: Fri, 26 Feb 2010 23:02:35 -0500 Subject: Docstrings considered too complicated In-Reply-To: <4b88611f$0$27844$c3e8da3@news.astraweb.com> References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <20100226230235.fcbd4011.darcy@druid.net> On 27 Feb 2010 00:02:40 GMT Steven D'Aprano wrote: > On Fri, 26 Feb 2010 09:09:36 -0600, Tim Daneliuk wrote: > > mov AX,BX ; Move the contents of BX into AX > > That's a *good* comment, because without it most English-speaking people > would assume you were moving the contents of AX into BX. But it isn't English, it's assembler. If someone doesn't know that assembler they have no business trying to work in it. A good comment would be "move number of sheep into accumulator" or something equally as descriptive. A person who knows the assembler knows that the BX register will be copied (not "moved" btw) into the AX register. What they want from the comment is some idea why. Yes, understanding assembler is hard. You aren't going to learn it from the comments. -- 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 cs at zip.com.au Fri Feb 26 23:11:15 2010 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 27 Feb 2010 15:11:15 +1100 Subject: How to end TCP socket data while using readline()? In-Reply-To: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> References: <273a2d1e-cff5-4759-a59d-6ccfefddfa40@e1g2000yqh.googlegroups.com> Message-ID: <20100227041115.GA24869@cskk.homeip.net> On 26Feb2010 10:39, Arjun wrote: | Hi, I have a small script that runs a TCP server. A client connects to | this server and transmits a stored file line-by-line, and then waits | for a confirmation "done". However, when I run them the first loop | never really ends -- as the TCP server keeps expecting more data. I am | using a file-like-object, and so somehow I have to communicate to the | server that it is the end-of-file. | | here is some server code | | sock1.bind(('', port)) | print "Listening at port: ", port | sock1.listen(1) # listening socket | (conn, addr) = sock1.accept() # connected socket | print 'Client (localhost) port: ', addr[1] | | cf = conn.makefile('r',0) # file like obj for socket [...] | print 'close' | cf.flush() | cf.close() | sfp.close() [...] Too many files. It's not that hard! Or shouldn't be. | So what I am wondering is: | | 1. Using a file-like object means that the socket becomes uni- | directional, until the mode of the file object is changed from 'r' to | 'w' (or vice versa). This seems inefficient, and rather unPythonesque. | Can somebody tell me if there is a more elegant way of receiving all | the lines from the client, and then sending a "done" message to the | client? Get the socket. It is a file descriptor (or in may be a python "socket" object with a file descriptor inside). Open _two_ "file" objects on it using from_file = os.fdopen(fd_of_socket, "r") to_file = os.fdopen(fd_of_socket, "w"). Use the same: print >>to_file, 'close' to_file.flush() method as you're using already. Read from to_file as needed. The same scheme should work in both server and client: Don't look for EOF, watch the input line flow. You might need to use readline() instead of the file-by-line iteration stuff, which I seem to recall has some sort of problem handing out the "latest" line. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ It's better, when you're riding with someone you don't know so well, to stick to the inside line - it's easier to avoid the bits... - Barry Sheene From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 23:19:10 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 04:19:10 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b889d3d$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 00:54:53 +0000, MRAB wrote: > The assembly languages of virtually all the processors that I've come > across put the destination first, eg. x86: Incorrect. x86 assembly has two distinct syntax branches, "Intel syntax" (which is most common in the Windows world according to Wikipedia) and "AT&T syntax". See for example: http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Basic-Assembler-Syntax.html -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 23:22:39 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 04:22:39 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b889e0f$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 03:25:47 +0000, MRAB wrote: >> Also, some assemblies perform the move in different directions >> according to the arguments. So you might have: >> >> mv AX,BX ; move contents of BX into AX mv @CX,DX ; move contents of >> @CX into DX >> >> Horrible, yes, but apparently some assembly languages did something >> like that. >> > Ah, yes, "apparently". That's like saying "someone down the pub told > me...". ;-) Not down the pub, somebody on Usenet. Are you trying to suggest that people might propagate falsehoods on the Internet??? -- Steven From steve at REMOVE-THIS-cybersource.com.au Fri Feb 26 23:23:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 04:23:26 GMT Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b889e3d$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 21:51:17 -0600, Tim Daneliuk wrote: > The only possible exception to this I can think of is when there is some > non-obvious side-effect (i.e. language and/or hardware is > "misfeatured"): > > mov A,B ; Moving A into B also will also arm > ; the nuclear warhead if the CPU is > ; hotter than 110C I had an embedded device that did *just that*, but only on Tuesdays. -- Steven From davea at ieee.org Fri Feb 26 23:56:20 2010 From: davea at ieee.org (Dave Angel) Date: Fri, 26 Feb 2010 23:56:20 -0500 Subject: Variable definition In-Reply-To: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> References: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4B88A5F4.2020707@ieee.org> Steven D'Aprano wrote: > > > for key, value in varDic.iteritems(): > varDic['myPrefix_' + key] = value > del varDic[key] > > Watch out if any of the existing values already startswith 'myPrefix' You can end up with trouble just as confusing as if 'myPrefix' is an empty string DaveA From wuwei23 at gmail.com Sat Feb 27 00:31:47 2010 From: wuwei23 at gmail.com (alex23) Date: Fri, 26 Feb 2010 21:31:47 -0800 (PST) Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: Mensanator wrote: > "You're" not getting the point. If every link has to be accompanied by a summary of all of the information at the end of it, what point is there to linking? (Programmers are the _only_ people I know of who complain about the arduousness of tasks like typing quotes or clicking on links...) From g.bogle at auckland.no.spam.ac.nz Sat Feb 27 01:03:53 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Sat, 27 Feb 2010 19:03:53 +1300 Subject: A more specific query ... References: <4B8860A0.6050600@auckland.no.spam.ac.nz> Message-ID: Dennis Lee Bieber wrote: > On Sat, 27 Feb 2010 13:00:32 +1300, Gib Bogle > declaimed the following in > gmane.comp.python.general: > >> The PyQt4 problem results from having copies of the Qt DLLs in directories that >> are in the PATH, as Doug Bell discovered. In my case I have two programs that >> use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can >> import the PyQt4 modules. >> > And where are those PATH entries relative to the Python ones? You > may have to add the Python location to PATH /before/ the AMD and Matlab > entries. {I routinely -- once a year or so -- copy the PATH environment > variable to an editor, and reorder it so that the stuff I use most > occurs earlier in the list} Well diagnosed! The others were all system environment variables, while the PyQt4 PATH is mine, and therefore it was placed at the end. I've taken the AMD and Matlab PATH entries out of the system list and put them after PyQt4 in my PATH. Now peace and harmony are restored to my Python world. Thanks Gib From raghu521987 at gmail.com Sat Feb 27 02:28:02 2010 From: raghu521987 at gmail.com (raghumech) Date: Fri, 26 Feb 2010 23:28:02 -0800 (PST) Subject: mobiletrickS Message-ID: <96e8177b-d03f-4aed-9a26-1001c0f02890@b36g2000pri.googlegroups.com> FREE CALL TO ANYWHERE ...... http://mobiletricks777.blogspot.com/ From darnzen at gmail.com Sat Feb 27 02:40:02 2010 From: darnzen at gmail.com (darnzen) Date: Fri, 26 Feb 2010 23:40:02 -0800 (PST) Subject: staticmethod and namespaces References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> <7uqa0eF95lU1@mid.uni-berlin.de> <7uqamjFd2vU2@mid.uni-berlin.de> Message-ID: On Feb 26, 10:20?am, "Diez B. Roggisch" wrote: > Am 26.02.10 17:08, schrieb Diez B. Roggisch: > > > > > > > Am 26.02.10 16:57, schrieb darnzen: > >> On Feb 26, 9:41 am, "Diez B. Roggisch" wrote: > >>> Am 26.02.10 16:32, schrieb darnzen: > > >>>> On Feb 26, 3:15 am, "Diez B. Roggisch" wrote: > >>>>> Am 26.02.10 06:07, schrieb darnzen: > > >>>>>> Having an odd problem that I solved, but wondering if its the best > >>>>>> solution (seems like a bit of a hack). > > >>>>>> First off, I'm using an external DLL that requires static callbacks, > >>>>>> but because of this, I'm losing instance info. It could be import > >>>>>> related? It will make more sense after I diagram it: > > >>>>>> #Module main.py > >>>>>> from A import * > > >>>>>> class App: > >>>>>> def sperg(self): > >>>>>> self.a = A() > > >>>>>> app = App() > >>>>>> [main loop and such] > >>>>>> ----------------------------- > >>>>>> # Module A.py > >>>>>> import main > >>>>>> class Foo: > >>>>>> Selves=[] > >>>>>> def __init__(self): > >>>>>> Foo.Selves.append(self) > >>>>>> @staticmethod > >>>>>> def chum_callback(nType, nP): > >>>>>> # Need to access function / data in app instance > >>>>>> app.sperg(nP) > >>>>>> # Need to access func data in Foo > >>>>>> # I'm pulling 'self' ouf of list made in constructor > >>>>>> self = Foo.getSelf(nP) > > >>>>>> def getSelf(nP): > >>>>>> return self.Selves[nP] > > >>>>>> --------------------------------------------------------------------- > >>>>>> So basically I added a list of instances to the base class so I can > >>>>>> get at them from the staticmethod. > >>>>>> What's bothering me the most is I can't use the global app > >>>>>> instance in > >>>>>> the A.py module. > > >>>>>> How can I get at the app instance (currently I'm storing that along > >>>>>> with the class instance in the constructor)? > >>>>>> Is there another way to do this that's not such a hack? > > >>>>>> Sorry for the double / partial post :( > > >>>>> Can you show how you pass the staticmethod to the C-function? Is > >>>>> the DLL > >>>>> utilized by ctypes? > > >>>>> I don't see any reason you couldn't use a bound method, which would > >>>>> give > >>>>> you your self, instead relying on global state. > > >>>>> Diez > > >>>> __main__.K<< *facepalm* should of tried that! > > >>>> Yeah I'm using ctypes. The DLL callback set ups are as follows. The > >>>> local callback is in the App namespace (in this case, some callbacks > >>>> are in different modules as noted in OP), but still no access to self: > > >>>> #Function wrapper > >>>> A.expCallback = WINFUNCTYPE(None, c_int, c_int, \ > >>>> POINTER(Data_s))(A.Callback) > > >>>> #DLL call to register the local callback function > >>>> DLLSetCallback(self.hID, A.SubID, EVENTID, A.expCallback) > > >>>> class A: > >>>> #Local callback function > >>>> @staticmethod > >>>> def Callback(hID, SubID, Data): > >>>> print 'I DON'T KNOW WHO I AM OR WHERE I CAME FROM!!' > >>>> print 'BUT WITH hID, and SubID, I CAN FIGURE IT OUT' > >>>> print 'IF I STORE A REFERENCE TO MYSELF IN A DICT' > >>>> print 'USING KEY GENERATED FROM hID, SubID' > >>>> pass > > >>>> I'm not sure why they need to be static callbacks, but the DLL doc's > >>>> say "when using object based languages, such as c++, callback > >>>> functions must be declared as static functions and not instance > >>>> methods", and I couldn't get it to work without setting it up that > >>>> way. I could probably have them all be "classless" functions, but with > >>>> 100's of these, my namespace would be polluted up the wazoo, and I'd > >>>> still have the problem that they wouldn't have access to instance > >>>> methods / properties. > > >>> The above code can't work with self, because you use > > >>> A.expCallback > > >>> which at best can of course be a classmethod. > > >>> You need to instead invoke DLLSetCallback with a bound method, like this > > >>> a = A() > >>> DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > >>> Also, the DLL-docs seem to refer to *C* or *C++*, where the concept of > >>> static functions is differently. If ctypes manages to get *some* > >>> callback passed, I'm 100% positive that it can pass *any* callable you > >>> like, including bound methods. > > >>> Diez > > >> Thinking about it some more, I believe I understand why it has to be > >> staticfunction. To use an bound method would require the wrapper to > >> include a reference to the instance as follows: > > >> A.expCallback = WINFUNCTYPE(None, POINTER(A), c_int, c_int, \ > >> POINTER(Data_s))(a.Callback) > > >> Since a = A(); a.foo() is really A.foo(self). The problem here is that > >> A is not a ctypes object and I can't change what arguments the DLL > >> uses in the callback in any case. Rewording my thoughts: a bound > >> method callback would require 'self' to be the first argument. I can > >> not make the DLL include 'self' as it doesn't know anything about the > >> objects in my program. Since I can't pass 'self', it has to be a > >> staticmethod. > > > No, that's not true. A bound method implictly knows about it self, and > > it's a callable. > > > What I guess is that you did the same mistake I did when I created that > > example - namely, not keeping a refernce to the bound method around. > > Ctypes will then garbage-collect the callback, which of course leads to > > all kinds of troubles. > > > Try this: > > > a = A() > > # keep this around > > bound_m = a.expCallback > > DLLSetCallback(self.hID, A.SubID, EVENTID, a.expCallback) > > AAAAHHRG, same error again. > > Of course, use > > DLLSetCallback(self.hID, A.SubID, EVENTID, bound_m) > > because the bound method changes with each time you create it. > > Sorry for the confusion. > > Diez Well, I got around this mess by putting all those static callbacks into a separate module in a new class. I set them up to call a bound method of that class which passes the arguments to the appropriate bound methods of other class instances. I just have to keep a little dict of the bound method callbacks when I register them with the class. I also found a simple trick for sharing globals between modules. Pretty simple, create an empty module, say shared.py, with only the pass statement in it. Then dynamically add properties to it such as shared.app = App(). Import shared into the modules that need access to app and done! Thanks for the help on this. Always learning! From quentel.pierre at wanadoo.fr Sat Feb 27 02:57:07 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Fri, 26 Feb 2010 23:57:07 -0800 (PST) Subject: Karrigell 3.0.4 published Message-ID: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Hi, A new version of the web framework Karrigell is on line The main changes are : - more robust session management in multi-threaded and multi-process environments - Unicode management in the HTMLTags module (HTML generation in Python) - Unicode management and error reports in Karrigell Templates (simple templating system) - more of MySQL : can be used for users database ; improved online management ; blog application - use of the WhizzyWig Javascript library for blog applications - make script caching and HTTP caching optional - the alias keys can be regular expressions for a more flexible url resolution - bug fix for default host configuration and for cookie expiry date Home page : http://karrigell.sourceforge.net Download : http://sourceforge.net/project/showfiles.php?group_id=67940 Google Group : http://groups.google.com/group/karrigell Cheers, Pierre From fabfake at fake.org Sat Feb 27 03:05:24 2010 From: fabfake at fake.org (Fabiano) Date: Sat, 27 Feb 2010 09:05:24 +0100 Subject: Updates about Tk Message-ID: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> Hi, I'm going to start my little journey into the Python's lands. I have already red the old posts about but I suppose this is an evolving topic. I have understood Tk is the default Python's GUI toolkit, I have also read that version 8.5 has native widgets and visual improvements. My question is: Are the new Tk comaprable with other toolkits(Qt, GTK,Wx?)? Does Tk lack other features compared to the Qt,GTK,Wx...? (Or: is there things you can't simply do with Tk?) Thanks in advance for replying From quentel.pierre at wanadoo.fr Sat Feb 27 03:21:55 2010 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: Sat, 27 Feb 2010 00:21:55 -0800 (PST) Subject: Karrigell 3.0.4 published References: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Message-ID: On 27 f?v, 08:57, Pierre Quentel wrote: > Hi, > > A new version of the web framework Karrigell is on line > > The main changes are : > - more robust session management in multi-threaded and multi-process > environments > - Unicode management in the HTMLTags module (HTML generation in > Python) > - Unicode management and error reports in Karrigell Templates (simple > templating system) > - more of MySQL : can be used for users database ; improved online > management ; blog application > - use of the WhizzyWig Javascript library for blog applications > - make script caching and HTTP caching optional > - the alias keys can be regular expressions for a more flexible url > resolution > - bug fix for default host configuration and for cookie expiry date > > Home page :http://karrigell.sourceforge.net > Download :http://sourceforge.net/project/showfiles.php?group_id=67940 > Google Group :http://groups.google.com/group/karrigell > > Cheers, > Pierre Oops ! wrong group, sorry. It's for c.l.p.announce From half.italian at gmail.com Sat Feb 27 03:26:08 2010 From: half.italian at gmail.com (Sean DiZazzo) Date: Sat, 27 Feb 2010 00:26:08 -0800 (PST) Subject: Updates about Tk References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <699f7b37-e651-4d32-942c-28cff2e2e05d@z10g2000prh.googlegroups.com> > Are the new Tk comaprable with other toolkits(Qt, GTK,Wx?)? > Does Tk lack other features compared to the Qt,GTK,Wx...? > (Or: is there things you can't simply do with Tk?) > > Thanks in advance for replying tkinter is a good starting point. You can get some definite benefits going to wx or Qt. I guess it depends on how much experience you have creating GUIs. Choose the one you are comfortable with. From jkn_gg at nicorp.f9.co.uk Sat Feb 27 03:52:13 2010 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Sat, 27 Feb 2010 00:52:13 -0800 (PST) Subject: Karrigell 3.0.4 published References: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Message-ID: Hi Pierre > Oops ! wrong group, sorry. It's for c.l.p.announce Well, I for one was happy to learn of this release here - thanks J^n From wuwei23 at gmail.com Sat Feb 27 04:00:00 2010 From: wuwei23 at gmail.com (alex23) Date: Sat, 27 Feb 2010 01:00:00 -0800 (PST) Subject: Signature-based Function Overloading in Python References: Message-ID: Michael Rudolf wrote: > In Java, Method Overloading is my best friend Guido wrote a nice article[1] on "multimethods" using decorators, which Ian Bicking followed up on[2] with a non-global approach. 1: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 2: http://blog.ianbicking.org/more-on-multimethods.html From dino at phidev.org Sat Feb 27 04:11:58 2010 From: dino at phidev.org (Florian Ludwig) Date: Sat, 27 Feb 2010 10:11:58 +0100 Subject: Exception in pydoc In-Reply-To: <4B87FBB3.8090107@gmail.com> References: <4B87FBB3.8090107@gmail.com> Message-ID: <1267261918.16436.31.camel@brain> On Fri, 2010-02-26 at 13:49 -0300, Ricardo Ar?oz wrote: > Does pydoc only deal with ASCII? UTF-8 in docstrings works for me. Maybe: * Its actually not UTF-8 * The console you're using doesn't support UTF-8 well (note: I'm on linux, maybe its a problem with windows?) code >>> #!/usr/bin/env python # -*- coding: utf-8 -*- def foo(): """Some ?tf-8 docstring ? g?f (x)""" return False <<>> help(test) Help on module test: NAME test - # -*- coding: utf-8 -*- FILE /tmp/test.py FUNCTIONS foo() Some ?tf-8 docstring ? g?f (x) -- Florian Ludwig -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: From macosx at rocteur.cc Sat Feb 27 04:36:41 2010 From: macosx at rocteur.cc (@ Rocteur CC) Date: Sat, 27 Feb 2010 10:36:41 +0100 Subject: Python dos2unix one liner Message-ID: <70C8D379-E7C0-4852-94FD-17D9B3B67F2B@rocteur.cc> Hi, This morning I am working though Building Skills in Python and was having problems with string.strip. Then I found the input file I was using was in DOS format and I thought it be best to convert it to UNIX and so I started to type perl -i -pe 's/ and then I though, wait, I'm learning Python, I have to think in Python, as I'm a Python newbie I fired up Google and typed: +python convert dos to unix +one +liner Found perl, sed, awk but no python on the first page So I tried +python dos2unix +one +liner -perl Same thing.. But then I found http://wiki.python.org/moin/Powerful%20Python%20One-Liners and tried this: cat file.dos | python -c "import sys,re; [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in sys.stdin]" >file.unix And it works.. [10:31:11 incc-imac-intel ~/python] cat -vet file.dos one^M$ two^M$ three^M$ [10:32:10 incc-imac-intel ~/python] cat -vet file.unix one$ two$ three$ But it is long and just like sed does not do it in place. Is there a better way in Python or is this kind of thing best done in Perl ? Thanks, Jerry From martin.hellwig at dcuktec.org Sat Feb 27 05:14:02 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sat, 27 Feb 2010 10:14:02 +0000 Subject: Python dos2unix one liner In-Reply-To: References: Message-ID: On 02/27/10 09:36, @ Rocteur CC wrote: Hi a couple of fragmented things popped in my head reading your question, non of them is very constructive though in what you actually want, but here it goes anyway. - Oneline through away script with re as a built in syntax, yup that sounds like perl to me. - What is wrong with making an executable script (not being one line) and call that, this is even shorter. - ... wait a minute, you are building something in python (problem with string.strip - why don't you use the built-in string strip method instead?) which barfs on the input (win/unix line ending), should the actual solution not be in there, i.e. parsing the line first to check for line-endings? .. But wait another minute, why are you getting \r\n in the first place, python by default uses universal new lines? Hope that helps a bit, maybe you could post the part of the code what you are doing for some better suggestions. -- mph From __peter__ at web.de Sat Feb 27 06:05:01 2010 From: __peter__ at web.de (Peter Otten) Date: Sat, 27 Feb 2010 12:05:01 +0100 Subject: Python dos2unix one liner References: Message-ID: @ Rocteur CC wrote: > But then I found > http://wiki.python.org/moin/Powerful%20Python%20One-Liners > and tried this: > > cat file.dos | python -c "import sys,re; > [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in > sys.stdin]" >file.unix > > And it works.. - Don't build list comprehensions just to throw them away, use a for-loop instead. - You can often use string methods instead of regular expressions. In this case line.replace("\r\n", "\n"). > But it is long and just like sed does not do it in place. > > Is there a better way in Python or is this kind of thing best done in > Perl ? open(..., "U") ("universal" mode) converts arbitrary line endings to just "\n" $ cat -e file.dos alpha^M$ beta^M$ gamma^M$ $ python -c'open("file.unix", "wb").writelines(open("file.dos", "U"))' $ cat -e file.unix alpha$ beta$ gamma$ But still, if you want very short (and often cryptic) code Perl is hard to beat. I'd say that Python doesn't even try. Peter From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 06:44:30 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 11:44:30 GMT Subject: Python dos2unix one liner References: Message-ID: <4b89059e$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: > cat file.dos | python -c "import sys,re; > [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in > sys.stdin]" >file.unix Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal string replacement! You've been infected by too much Perl coding! *wink* Regexes are expensive, even in Perl, but more so in Python. When you don't need the 30 pound sledgehammer of regexes, use lightweight string methods. import sys; sys.stdout.write(sys.stdin.read().replace('\r\n', '\n')) ought to do it. It's not particularly short, but Python doesn't value extreme brevity -- code golf isn't terribly exciting in Python. [steve at sylar ~]$ cat -vet file.dos one^M$ two^M$ three^M$ [steve at sylar ~]$ cat file.dos | python -c "import sys; sys.stdout.write (sys.stdin.read().replace('\r\n', '\n'))" > file.unix [steve at sylar ~]$ cat -vet file.unix one$ two$ three$ [steve at sylar ~]$ Works fine. Unfortunately it still doesn't work in-place, although I think that's probably a side-effect of the shell, not Python. To do it in place, I would pass the file name: # Tested and working in the interactive interpreter. import sys filename = sys.argv[1] text = open(filename, 'rb').read().replace('\r\n', '\n') open(filename, 'wb').write(text) Turning that into a one-liner isn't terribly useful or interesting, but here we go: python -c "import sys;open(sys.argv[1], 'wb').write(open(sys.argv[1], 'rb').read().replace('\r\n', '\n'))" file Unfortunately, this does NOT work: I suspect it is because the file gets opened for writing (and hence emptied) before it gets opened for reading. Here's another attempt: python -c "import sys;t=open(sys.argv[1], 'rb').read().replace('\r\n', '\n');open(sys.argv[1], 'wb').write(t)" file [steve at sylar ~]$ cp file.dos file.txt [steve at sylar ~]$ python -c "import sys;t=open(sys.argv[1], 'rb').read ().replace('\r\n', '\n');open(sys.argv[1], 'wb').write(t)" file.txt [steve at sylar ~]$ cat -vet file.txt one$ two$ three$ [steve at sylar ~]$ Success! Of course, none of these one-liners are good practice. The best thing to use is a dedicated utility, or write a proper script that has proper error testing. > Is there a better way in Python or is this kind of thing best done in > Perl ? If by "this kind of thing" you mean text processing, then no, Python is perfectly capable of doing text processing. Regexes aren't as highly optimized as in Perl, but they're more than good enough for when you actually need a regex. If you mean "code golf" and one-liners, then, yes, this is best done in Perl :) -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 06:45:26 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 11:45:26 GMT Subject: DreamPie - The Python shell you've always dreamed about! References: <6c6a96e0-be08-4ec3-a002-0bb9232a8afd@f29g2000yqa.googlegroups.com> <12cd38b0-1d34-4b1e-96fb-19c3e2f62ab7@e1g2000yqh.googlegroups.com> <0fe91504-cb4f-46b6-a327-c5979bb104a6@q16g2000yqq.googlegroups.com> <7430987e-3603-4805-b4f4-cae73ca2d3f6@g11g2000yqe.googlegroups.com> <7a97c5ba-7ac5-42ef-b1ec-9009b0626fec@v1g2000yqk.googlegroups.com> Message-ID: <4b8905d6$0$27844$c3e8da3@news.astraweb.com> On Fri, 26 Feb 2010 21:31:47 -0800, alex23 wrote: > Mensanator wrote: >> "You're" not getting the point. > > If every link has to be accompanied by a summary of all of the > information at the end of it, what point is there to linking? > > (Programmers are the _only_ people I know of who complain about the > arduousness of tasks like typing quotes or clicking on links...) Once you've clicked on a link to Tubgirl or Goatsie Man once, you will never, ever, ever click on an untrusted link again. *wink* But seriously... I dislike being sent links without any explanation of what is in them, because in my experience, 9 times out of 10 if I had been told, I wouldn't have bothered to clink on the link. -- Steven From translatorhossam at gmail.com Sat Feb 27 06:53:12 2010 From: translatorhossam at gmail.com (hussam elagmy) Date: Sat, 27 Feb 2010 03:53:12 -0800 (PST) Subject: Open all sites that blocked in your country from here Message-ID: Open all sites that blocked in your country from here Browse the internet securely using Your Proxy You can unblock popular social networking sites such as myspace, bebo, facebook and many other sites. http://essam.zxq.net/ From translatorhossam at gmail.com Sat Feb 27 07:06:42 2010 From: translatorhossam at gmail.com (hussam elagmy) Date: Sat, 27 Feb 2010 04:06:42 -0800 (PST) Subject: Open all sites that blocked in your country from here Message-ID: <9433bc33-d585-456a-b878-0f0e110cfff1@19g2000yqu.googlegroups.com> Browse the internet securely using Your Proxy You can unblock popular social networking sites such as myspace, bebo, facebook and many other sites. http://essam.zxq.net/ From usenot at geekmail.INVALID Sat Feb 27 08:45:33 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 27 Feb 2010 14:45:33 +0100 Subject: Variable definition References: <4b8892a5$0$27844$c3e8da3@news.astraweb.com> Message-ID: <20100227144533.36d4294d@geekmail.INVALID> On 27 Feb 2010 03:33:57 GMT Steven D'Aprano wrote: > exec "'myPrefix_turquoise' = 42" > Not quite: In [1]: exec "'myPrefix_turquoise' = 42" ------------------------------------------------------------ File "", line 1 SyntaxError: can't assign to literal (, line 1) I think you meant: exec "myPrefix_turquoise = 42" /W -- INVALID? DE! From ijsporg at gmail.com Sat Feb 27 09:31:06 2010 From: ijsporg at gmail.com (org ijsp) Date: Sat, 27 Feb 2010 06:31:06 -0800 (PST) Subject: Call For Manuscripts: International Journal of Signal Processing (IJSP) Message-ID: <123a4533-5c74-4b84-8ee9-28c91827a770@s36g2000prh.googlegroups.com> Call For Manuscripts The Journal is currently accepting original high-quality research manuscripts for publication. The Journal welcomes the submission of manuscripts that meet the scientific criteria of significance and academic excellence. All research articles submitted for the journal will be peer-reviewed within three weeks of submission. Following the peer-reviewed acceptance, the accepted & formatted articles will normally be published in the next available issue. All submitted formatted full-text articles should report original, previously unpublished research results, experimental or theoretical. Articles submitted to the journal should meet these criteria and must not be under consideration for publication elsewhere. These articles should describe new and carefully confirmed findings, and experimental procedures should be given in sufficient detail for others to verify the work. The length of a full text article should be the minimum required to describe and interpret the work clearly. Papers are solicited from, but not limited to the following topics: * Adaptive Filtering & Signal Processing * Ad-Hoc and Sensor Networks * Analog and Mixed Signal Processing * Array Signal Processing * Audio and Electroacoustics * Audio/Speech Processing and Coding * Bioimaging and Signal Processing * Biometrics & Authentification * Biosignal Processing & Understanding * Communication and Broadband Networks * Communication Signal processing * Computer Vision & Virtual Reality * Cryptography and Network Security * Design and Implementation of Signal Processing Systems * Digital Signal Processing * DSP Implementations and Embedded Systems * Emerging Technologies * Hardware Implementation for Signal Processing * Higher Order Spectral Analysis * Image and Multidimensional Signal Processing * Image Processing & Understanding * Image/Video Processing and Coding * Industry Technology * Internet Signal Processing * Machine Learning for Signal Processing * Modulation and Channel Coding * Multimedia & Human-computer Interaction * Multimedia Communications * Multimedia Signal Processing * Natural Language Processing * Next Generation Mobile Communications * Nonlinear Signal Processing * Optical Communications * Parallel and Distributed Processing * PDE for Image Processing * Radar Signal Processing * Rapid Prototyping and Tools for DSP Design * RF and Wireless Communications * Sensor Array and Multi-channel Processing * Signal Processing and Communications Education * Signal Processing for Communications * Signal Processing for Security * Signal Processing Theory and Methods * Soft Computing and Machine learning for Signal Processing and Communications * Sonar Signal Processing and Localization * SP for Bioinformatics * SP for Biomedical & Cognitive Science * SP for Internet and Wireless Communications * SP for Sensor Networks * Spectrum Estimation & Modeling * Speech and Audio Coding * Speech Processing * Speech Synthesis & Recognition * Spoken Language Processing * Statistic Learning & Pattern Recognition * Statistical Signal Processing * TF Spectrum Analysis & Wavelet * Time-Frequency/Time-Scale Analysis * Video compression & Streaming * Watermarking and Information Hiding * Applications of Signal Processing (Biomedical, Bioinformatics, Genomic, Seismic, Radar, Sonar, Remote Sensing, Positioning, Embedded Systems, etc.) * Signal Processing and Communications Education * Web Engineering * Wireless Communications * Detection and Estimation * Cooperative Communication * Adaptive and Array Signal Processing * MIMO and Space-Time Signal Processing * Compressive Sensing & Applications * Cognitive Radio * Signal Processing for Communications * Network Coding * Machine Learning/AI for Signal Processing * Network Information Theory * Audio, Speech, Image & Video Signal Processing * Sequences & Complexity * Signal Processing Algorithms & Architectures * Source and Channel Coding: Theory and Practice * Underwater Communications and Signal Processing * Ad-hoc and Sensor Networks * Optical Communications and Networks * Next Generation Networking, QoS & Security * VLSI for Communication & Signal Processing * Multihop and Mesh Networks * RF Systems for Communications * Vehicular Networks * Systems, Standards and Implementations * Biomedical Signal Processing * Coding/Signal Processing in Biology * Spoken Language Processing * Biological Network & Data Analysis/Modelling CALL FOR PAPERS International Journal of Signal Processing (IJSP) Website: https://sites.google.com/site/ijsporg/ Manuscript submission to: ijsporg at gmail.com All submitted papers will be judged based on their quality by the technical committee and reviewers. Papers that describe research and experimentation are encouraged. All paper submissions will be handled electronically and detailed instructions on submission procedure are available on IJSP web pages. Researchers and authors are invited to participate in the peer-review process of IJSP papers if your research interest matches with the themes of Call for Papers. For other information, please contact IJSP Managing Editor. From macosx at rocteur.cc Sat Feb 27 10:01:53 2010 From: macosx at rocteur.cc (@ Rocteur CC) Date: Sat, 27 Feb 2010 16:01:53 +0100 Subject: Python dos2unix one liner In-Reply-To: <4b89059e$0$27844$c3e8da3@news.astraweb.com> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: > >> cat file.dos | python -c "import sys,re; >> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >> sys.stdin]" >file.unix > > Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal > string replacement! You've been infected by too much Perl coding! Thanks for the replies I'm looking at them now, however, for those who misunderstood, the above cat file.dos pipe pythong does not come from Perl but comes from: http://wiki.python.org/moin/Powerful%20Python%20One-Liners > Apply regular expression to lines from stdin > [another command] | python -c "import sys,re; > [sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', line)) > for line in sys.stdin]" Nothing to do with Perl, Perl only takes a handful of characters to do this and certainly does not require the creation an intermediate file, I simply found the above example on wiki.python.org whilst searching Google for a quick conversion solution. Thanks again for the replies I've learned a few things and I appreciate your help. Jerry From funthyme at gmail.com Sat Feb 27 10:29:46 2010 From: funthyme at gmail.com (John Pinner) Date: Sat, 27 Feb 2010 07:29:46 -0800 (PST) Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: On Feb 24, 8:23?pm, Andreas Waldenburger wrote: > Hi all, > > a company that works with my company writes a lot of of their code in > Python (lucky jerks). I've seen their code and it basically looks like > this: > > """Function that does stuff""" > def doStuff(): > ? ? while not wise(up): > ? ? ? ? yield scorn > > Now my question is this: How do I kill these people without the > authorities thinking they didn't deserve it? A good way to control Python contractors is (given that firstly there are functional specifications to comply with, and tests to pass) is to impose the following condition: that all code delivered must reach a score of (say) 9.5 or more when checked by pylint and pylint could be the way to demonstrate the problems to the 'authorities'. If payment depends on such a measure, things will change quite quickly. John -- > /W > > -- > INVALID? DE! From ssteinerx at gmail.com Sat Feb 27 10:54:50 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 10:54:50 -0500 Subject: Python dos2unix one liner In-Reply-To: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> Message-ID: On Feb 27, 2010, at 10:01 AM, @ Rocteur CC wrote: > Nothing to do with Perl, Perl only takes a handful of characters to do this and certainly does not require the creation an intermediate file Perl may be better for you for throw-away code. Use Python for the code you want to keep (and read and understand later). S From stefan_ml at behnel.de Sat Feb 27 11:25:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 27 Feb 2010 17:25:48 +0100 Subject: Python dos2unix one liner In-Reply-To: <70C8D379-E7C0-4852-94FD-17D9B3B67F2B@rocteur.cc> References: <70C8D379-E7C0-4852-94FD-17D9B3B67F2B@rocteur.cc> Message-ID: @ Rocteur CC, 27.02.2010 10:36: > cat file.dos | python -c "import > sys,re;[sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in > sys.stdin]" >file.unix See: http://partmaps.org/era/unix/award.html Stefan From rami.chowdhury at gmail.com Sat Feb 27 11:36:29 2010 From: rami.chowdhury at gmail.com (Rami Chowdhury) Date: Sat, 27 Feb 2010 08:36:29 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> Message-ID: <201002270836.29268.rami.chowdhury@gmail.com> On Friday 26 February 2010 21:49:00 Isaiah Coberly wrote: > Thanks for your help Rami.. I got it working.. I did some digging around > and found out that I needed to install opencv as admin.. Now Im trying to > run one of the samples and up against my next chalange. > > Argg.. There are so many pit falls! > > Thanks again, > Glad to be able to help :-) Especially when you've managed to solve something, could you please remember to CC the list on your reply, so if people run across the problem in future they can benefit from your experience? Thanks, Rami > > On Fri, Feb 26, 2010 at 7:57 PM, Isaiah Coberly wrote: > > Thats the furthest I have seen it get.. Ill have to remember this.. > > > > here is what Python returned.. > > > > >>> from opencv import cv > > > > Traceback (most recent call last): > > File "", line 1, in > > > > from opencv import cv > > > > File "C:\Python26\lib\site-packages\opencv\__init__.py", line 74, in > > > > > > > > from cv import * > > > > File "C:\Python26\lib\site-packages\opencv\cv.py", line 25, in > > > > _cv = swig_import_helper() > > > > File "C:\Python26\lib\site-packages\opencv\cv.py", line 21, in > > > > swig_import_helper > > > > _mod = imp.load_module('_cv', fp, pathname, description) > > > > ImportError: DLL load failed: The specified module could not be found. > > > > On Fri, Feb 26, 2010 at 7:53 PM, Rami Chowdhury wrote: > >> On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote: > >> > >> C:\OpenCV2.0\Python2.6\Lib\site-packages > >> > >> no .py files here.. > >> > >> cv.pyd > >> libcv.dll.a > >> > >> > >> C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv > >> > >> _init_.py > >> matlan_syntax.py > >> adaptors.py > >> cv.py > >> > >> > >> It looks to me like 'opencv' is structured as a package, from which you > >> should be able to import and work with Python libraries. Have you tried > >> putting the above site-packages directory in sys.path: > >> > >> import sys; sys.path.append('C: > >> \\OpenCV2.0\\Python2.6\\Lib\\site-packages') > >> > >> and then doing: > >> > >> from opencv import cv > >> > >> ? > >> > >> Did I still need to compile this even though it was a win 32 installer? > >> > >> > >> I don't think so, no -- AFAIK the .pyd files are compiled CPython > >> extension modules, so it looks like they're all compiled for you. > >> > >> ------------- > >> Rami Chowdhury > >> "Never assume malice when stupidity will suffice." -- Hanlon's Razor > >> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > >> > >> > >> > >> > >> > >> > >> On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury > >> >> > >> > wrote: > >>> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: > >>> > Thanks for the reply. > >>> > > >>> > I tried putting the files from > >>> > > >>> > C:\OpenCV2.0\Python2.6\Lib > >>> > > >>> > too > >>> > > >>> > C:\Python26\Lib\site-packages > >>> > > >>> > and Python still wont import.. > >>> > > >>> > I adjusted the environment variables to try and import > >>> > maya.standalone > >>> > >>> but > >>> > >>> > no dice on that either. > >>> > >>> Sorry, you've still not told me where you expect it to be. Could you > >>> let us > >>> know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? > >>> > >>> > On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury > >>> > >>> wrote: > >>> > > On Friday 26 February 2010 16:06:56 Routb3d wrote: > >>> > > > I used the x86 Python 2.6.4 installer. I am working in x64 Win7 > >>> > >>> pro. > >>> > >>> > > > I have tried adjusting environment variables as well as putting > >>> > > > the files directly in the search path of Python.. Python still > >>> > > > returns this.. Any ideas? > >>> > > > >>> > > Where are you expecting the cv module / package to be? It's > >>> > > certainly > >>> > >>> not > >>> > >>> > > in > >>> > > the standard library -- at least not in my install of Python > >>> > > 2.6.4... > >>> > > > >>> > > > >>> import sys > >>> > > > >>> sys.path > >>> > > > > >>> > > > ['C:\\Python26\\Lib\\idlelib', > >>> > > > 'C:\\ProgramFiles\\Autodesk\\Maya2010\ > >>> > >>> > > > \Python\\Lib\\site-packages', 'C: > >>> \\Windows\\system32\\python26.zip', > >>> > >>> > > > 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C: > >>> \\Python26\\lib\\plat- > >>> > >>> > > > win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C: > >>> \\Python26\\lib\ > >>> > >>> > > > \site-packages'] > >>> > > > > >>> > > > >>> import cv > >>> > > > > >>> > > > Traceback (most recent call last): > >>> > > > File "", line 1, in > >>> > > > > >>> > > > import cv > >>> > > > > >>> > > > ImportError: DLL load failed: The specified module could not be > >>> > >>> found. > >>> > >>> > > > Any help would be greatly appreciated. > >>> > > > >>> > > ---- > >>> > > Rami Chowdhury > >>> > > "Strangers are just friends who haven't had enough gin." -- > >>> > > Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / > >>> > > 01819-245544 (BD) > >>> > >>> ---- > >>> Rami Chowdhury > >>> "Ninety percent of everything is crap." -- Sturgeon's Law > >>> 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) ---- Rami Chowdhury -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GO d-(+++) s-:++ a-- C++> ULX+> P++ L++ E+ W+++ w-- PS+ PE t+ b+++ e++ !r z? ------END GEEK CODE BLOCK------ 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From invalid at invalid.invalid Sat Feb 27 11:59:28 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Feb 2010 16:59:28 +0000 (UTC) Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-27, @ Rocteur CC wrote: > Nothing to do with Perl, Perl only takes a handful of characters to do > this and certainly does not require the creation an intermediate file, Are you sure about that? Or does it just hide the intermediate file from you the way that sed -i does? -- Grant From emile at fenx.com Sat Feb 27 12:03:41 2010 From: emile at fenx.com (Emile van Sebille) Date: Sat, 27 Feb 2010 09:03:41 -0800 Subject: Spam from gmail In-Reply-To: References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> <87sk8r5v2f.fsf@benfinney.id.au> Message-ID: On 2/24/2010 1:52 PM Arnaud Delobelle said... > aahz at pythoncraft.com (Aahz) writes: >> That seems to miss the point to some extent. If I post my recipe for >> spinach lasagne here, is that spam? > > Are they really good? Sounds good, spinach lasagne, I don't know a > recipe for them. Maybe you could post it as Python code, with a lot of > nested if-then-else clauses, of course :) > +1 for Aahz posting his Spinach Lasagne recipe. Emile From kw at codebykevin.com Sat Feb 27 12:11:14 2010 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 27 Feb 2010 12:11:14 -0500 Subject: Updates about Tk In-Reply-To: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> Message-ID: <6adc$4b895233$4275d90a$6509@FUSE.NET> On 2/27/10 3:05 AM, Fabiano wrote: > > Hi, > I'm going to start my little journey into the Python's lands. > I have already red the old posts about but I suppose this is an evolving > topic. > I have understood Tk is the default Python's GUI toolkit, I have also > read that version 8.5 has native widgets and visual improvements. > My question is: > Are the new Tk comaprable with other toolkits(Qt, GTK,Wx?)? > Does Tk lack other features compared to the Qt,GTK,Wx...? > (Or: is there things you can't simply do with Tk?) > > Thanks in advance for replying In terms of UI, Tkinter as of 8.5 is pretty comparable to the other toolkits. The themed ttk widgets use native widgets for things like tree/tableviews, buttons, scrollbars, entry fields, labels, etc. If there's something that the core widgets don't support, there are both higher-level Python widget packages based on Tkinter (PMW, for instance) and Tkinter wrappers for Tk widget packages such as tablelist, Bwidgets, etc. More information is here: http://tkinter.unpythonic.net/wiki/ Tk still lacks in a few areas: 1. Native drag-and-drop--you have to install an extension package, TkDND, which also has a Python wrapper here: http://klappnase.bubble.org/index.html 2. Printing. The other toolkits support this out of the box. With Tk, you're pretty limited to lpr and/or generating postscript (on *Nix and Mac) and whatever native printing functionality is supported on Windows. 3. HTML rendering. The other toolkits support this natively. There are several alternatives on Tk, but none are ideal: see http://www.codebykevin.com/blosxom.cgi/2009/11/19#which-html. I find that Tk is so simple and powerful for most things that its limitations are acceptable, or can be worked around. Also, licensing can be problematic in some cases. But, as others have discussed, give the different toolkits a try and make your own choice. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From routb3d at gmail.com Sat Feb 27 12:15:09 2010 From: routb3d at gmail.com (Isaiah Coberly) Date: Sat, 27 Feb 2010 09:15:09 -0800 Subject: importing libraries not working 2.6.4 In-Reply-To: <201002270836.29268.rami.chowdhury@gmail.com> References: <6e9face0-f34d-4943-84c5-7f4a56bb0679@g28g2000prb.googlegroups.com> <201002270836.29268.rami.chowdhury@gmail.com> Message-ID: <5413BF6A-44D1-48D7-B2EE-0C6364B45B27@gmail.com> Will do.. Thanks again.. Sent from my iPhone On Feb 27, 2010, at 8:36 AM, Rami Chowdhury wrote: > On Friday 26 February 2010 21:49:00 Isaiah Coberly wrote: >> Thanks for your help Rami.. I got it working.. I did some digging >> around >> and found out that I needed to install opencv as admin.. Now Im >> trying to >> run one of the samples and up against my next chalange. >> >> Argg.. There are so many pit falls! >> >> Thanks again, >> > > Glad to be able to help :-) > > Especially when you've managed to solve something, could you please > remember > to CC the list on your reply, so if people run across the problem in > future > they can benefit from your experience? > > Thanks, > Rami > >> >> On Fri, Feb 26, 2010 at 7:57 PM, Isaiah Coberly >> wrote: >>> Thats the furthest I have seen it get.. Ill have to remember this.. >>> >>> here is what Python returned.. >>> >>>>>> from opencv import cv >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> >>> from opencv import cv >>> >>> File "C:\Python26\lib\site-packages\opencv\__init__.py", line 74, >>> in >>> >>> >>> >>> from cv import * >>> >>> File "C:\Python26\lib\site-packages\opencv\cv.py", line 25, in >>> >>> >>> _cv = swig_import_helper() >>> >>> File "C:\Python26\lib\site-packages\opencv\cv.py", line 21, in >>> >>> swig_import_helper >>> >>> _mod = imp.load_module('_cv', fp, pathname, description) >>> >>> ImportError: DLL load failed: The specified module could not be >>> found. >>> >>> On Fri, Feb 26, 2010 at 7:53 PM, Rami Chowdhury > wrote: >>>> On Feb 26, 2010, at 19:47 , Isaiah Coberly wrote: >>>> >>>> C:\OpenCV2.0\Python2.6\Lib\site-packages >>>> >>>> no .py files here.. >>>> >>>> cv.pyd >>>> libcv.dll.a >>>> >>>> >>>> C:\OpenCV2.0\Python2.6\Lib\site-packages\opencv >>>> >>>> _init_.py >>>> matlan_syntax.py >>>> adaptors.py >>>> cv.py >>>> >>>> >>>> It looks to me like 'opencv' is structured as a package, from >>>> which you >>>> should be able to import and work with Python libraries. Have you >>>> tried >>>> putting the above site-packages directory in sys.path: >>>> >>>> import sys; sys.path.append('C: >>>> \\OpenCV2.0\\Python2.6\\Lib\\site-packages') >>>> >>>> and then doing: >>>> >>>> from opencv import cv >>>> >>>> ? >>>> >>>> Did I still need to compile this even though it was a win 32 >>>> installer? >>>> >>>> >>>> I don't think so, no -- AFAIK the .pyd files are compiled CPython >>>> extension modules, so it looks like they're all compiled for you. >>>> >>>> ------------- >>>> Rami Chowdhury >>>> "Never assume malice when stupidity will suffice." -- Hanlon's >>>> Razor >>>> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >>>> >>>> >>>> >>>> >>>> >>>> >>>> On Fri, Feb 26, 2010 at 6:12 PM, Rami Chowdhury >>>> >>> >>>>> wrote: >>>>> On Friday 26 February 2010 17:42:04 Isaiah Coberly wrote: >>>>>> Thanks for the reply. >>>>>> >>>>>> I tried putting the files from >>>>>> >>>>>> C:\OpenCV2.0\Python2.6\Lib >>>>>> >>>>>> too >>>>>> >>>>>> C:\Python26\Lib\site-packages >>>>>> >>>>>> and Python still wont import.. >>>>>> >>>>>> I adjusted the environment variables to try and import >>>>>> maya.standalone >>>>> >>>>> but >>>>> >>>>>> no dice on that either. >>>>> >>>>> Sorry, you've still not told me where you expect it to be. Could >>>>> you >>>>> let us >>>>> know what .py files you can see in C:\OpenCV2.0\Python2.6\Lib ? >>>>> >>>>>> On Fri, Feb 26, 2010 at 4:30 PM, Rami Chowdhury >>>>> >>>>> wrote: >>>>>>> On Friday 26 February 2010 16:06:56 Routb3d wrote: >>>>>>>> I used the x86 Python 2.6.4 installer. I am working in x64 Win7 >>>>> >>>>> pro. >>>>> >>>>>>>> I have tried adjusting environment variables as well as putting >>>>>>>> the files directly in the search path of Python.. Python still >>>>>>>> returns this.. Any ideas? >>>>>>> >>>>>>> Where are you expecting the cv module / package to be? It's >>>>>>> certainly >>>>> >>>>> not >>>>> >>>>>>> in >>>>>>> the standard library -- at least not in my install of Python >>>>>>> 2.6.4... >>>>>>> >>>>>>>>>>> import sys >>>>>>>>>>> sys.path >>>>>>>> >>>>>>>> ['C:\\Python26\\Lib\\idlelib', >>>>>>>> 'C:\\ProgramFiles\\Autodesk\\Maya2010\ >>>>> >>>>>>>> \Python\\Lib\\site-packages', 'C: >>>>> \\Windows\\system32\\python26.zip', >>>>> >>>>>>>> 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C: >>>>> \\Python26\\lib\\plat- >>>>> >>>>>>>> win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C: >>>>> \\Python26\\lib\ >>>>> >>>>>>>> \site-packages'] >>>>>>>> >>>>>>>>>>> import cv >>>>>>>> >>>>>>>> Traceback (most recent call last): >>>>>>>> File "", line 1, in >>>>>>>> >>>>>>>> import cv >>>>>>>> >>>>>>>> ImportError: DLL load failed: The specified module could not be >>>>> >>>>> found. >>>>> >>>>>>>> Any help would be greatly appreciated. >>>>>>> >>>>>>> ---- >>>>>>> Rami Chowdhury >>>>>>> "Strangers are just friends who haven't had enough gin." -- >>>>>>> Howdle's Saying 408-597-7068 (US) / 07875-841-046 (UK) / >>>>>>> 01819-245544 (BD) >>>>> >>>>> ---- >>>>> Rami Chowdhury >>>>> "Ninety percent of everything is crap." -- Sturgeon's Law >>>>> 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) > > > ---- > Rami Chowdhury > -----BEGIN GEEK CODE BLOCK----- > Version: 3.1 > GO d-(+++) s-:++ a-- C++> ULX+> P++ L++ > E+ W+++ w-- PS+ PE t+ b+++ e++ !r z? > ------END GEEK CODE BLOCK------ > 408-597-7068 (US) / 07875-841-046 (UK) / 01819-245544 (BD) From john at castleamber.com Sat Feb 27 12:18:57 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 11:18:57 -0600 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b88611f$0$27844$c3e8da3@news.astraweb.com> <87635j4i8x.fsf@castleamber.com> <4b888e62$0$27844$c3e8da3@news.astraweb.com> Message-ID: <87r5o6zjem.fsf@castleamber.com> Steven D'Aprano writes: > Also, some assemblies perform the move in different directions according > to the arguments. So you might have: > > mv AX,BX ; move contents of BX into AX > mv @CX,DX ; move contents of @CX into DX > > Horrible, yes, but apparently some assembly languages did something like > that. It doesn't matter. Both your comments are wrong from my point of view. Someone who doesn't know in which direction the move happens is certainly not qualified to modify the code. And as for learning, he/she should start with a book, not with a piece of code that requires a comment on every line unless one can guess its meaning. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From john at castleamber.com Sat Feb 27 12:27:04 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 11:27:04 -0600 Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> Message-ID: <87mxyuzj13.fsf@castleamber.com> "ssteinerX at gmail.com" writes: > On Feb 27, 2010, at 10:01 AM, @ Rocteur CC wrote: >> Nothing to do with Perl, Perl only takes a handful of characters to >> do this and certainly does not require the creation an intermediate >> file > > Perl may be better for you for throw-away code. Use Python for the > code you want to keep (and read and understand later). Amusing how long those Python toes can be. In several replies I have noticed (often clueless) opinions on Perl. When do people learn that a language is just a tool to do a job? -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From rantingrick at gmail.com Sat Feb 27 12:29:44 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 27 Feb 2010 09:29:44 -0800 (PST) Subject: Updates about Tk References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> <6adc$4b895233$4275d90a$6509@FUSE.NET> Message-ID: On Feb 27, 11:11?am, Kevin Walzer wrote: (...snip...) > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com Great post Kevin! The only thing i would like to add are my two favorite references for learning Tkinter. They are not geared around the new ttk stuff, but still 95% relevant to any Tkinter-ing http://effbot.org/tkinterbook/ http://infohost.nmt.edu/tcc/help/pubs/tkinter/ From fetchinson at googlemail.com Sat Feb 27 12:37:22 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sat, 27 Feb 2010 18:37:22 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: <201002261604.57625.victor.stinner@haypocalc.com> References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261335.02933.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: On 2/26/10, Victor Stinner wrote: > Le vendredi 26 f?vrier 2010 15:37:43, Daniel Fetchinson a ?crit : >> >> pysandbox is a new Python sandbox project >> >> Out of curiosity, the python sandbox behind google app engine is open >> source? If so, how is it different from your project, if not, anyone >> knows >> if it will be in the future? > > I don't know this project. Do you have the URL of the project home page? Is > it > the "safelite.py" project? It's google's hosting solution called app engine, for python web applications: http://code.google.com/appengine/docs/python/gettingstarted/ I guess they also have some kind of a sandbox if they let people run python on their machines, I'm not sure if it's open source though. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From alfps at start.no Sat Feb 27 12:40:01 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sat, 27 Feb 2010 18:40:01 +0100 Subject: Python dos2unix one liner In-Reply-To: References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: * @ Rocteur CC: > > On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > >> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: >> >>> cat file.dos | python -c "import sys,re; >>> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >>> sys.stdin]" >file.unix >> >> Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal >> string replacement! You've been infected by too much Perl coding! > > Thanks for the replies I'm looking at them now, however, for those who > misunderstood, the above cat file.dos pipe pythong does not come from > Perl but comes from: > > http://wiki.python.org/moin/Powerful%20Python%20One-Liners Steven is right with the "Holy Cow" and multiple exclamation marks. For those unfamiliar with that, just google "multiple exclamation marks", I think that should work... ;-) Not only is a regular expression overkill & inefficient, but the snippet also needlessly constructs an array with size the number of lines. Consider instead e.g. import sys; sum(int(bool(sys.stdout.write(line.replace('\r\n','\n')))) for line in sys.stdin) But better, consider that it's less work to save the code in a file than copying and pasting it in a command interpreter, and then it doesn't need to be 1 line. >> Apply regular expression to lines from stdin >> [another command] | python -c "import >> sys,re;[sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', >> line)) for line in sys.stdin]" > > > Nothing to do with Perl, Perl only takes a handful of characters to do > this and certainly does not require the creation an intermediate file, I > simply found the above example on wiki.python.org whilst searching > Google for a quick conversion solution. > > Thanks again for the replies I've learned a few things and I appreciate > your help. Cheers, - Alf From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 12:42:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 27 Feb 2010 17:42:31 GMT Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b895987$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 16:01:53 +0100, @ Rocteur CC wrote: > On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > >> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: >> >>> cat file.dos | python -c "import sys,re; >>> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >>> sys.stdin]" >file.unix >> >> Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal >> string replacement! You've been infected by too much Perl coding! > > Thanks for the replies I'm looking at them now, however, for those who > misunderstood, the above cat file.dos pipe pythong does not come from > Perl but comes from: > > http://wiki.python.org/moin/Powerful%20Python%20One-Liners Whether it comes from Larry Wall himself, or a Python wiki, using regexes for a simple string replacement is like using an 80 lb sledgehammer to crack a peanut. >> Apply regular expression to lines from stdin [another command] | python >> -c "import sys,re; >> [sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', line)) for >> line in sys.stdin]" And if PATTERN is an actual regex, rather than just a simple substring, that would be worthwhile. But if PATTERN is a literal string, then string methods are much faster and use much less memory. > Nothing to do with Perl, Perl only takes a handful of characters to do > this I'm sure it does. If I were interested in code-golf, I'd be impressed. > and certainly does not require the creation an intermediate file, The solution I gave you doesn't use an intermediate file either. *slaps head and is enlightened* Oh, I'm an idiot! Since you're reading text files, there's no need to call replace('\r\n','\n'). Since there shouldn't be any bare \r characters in a DOS-style text file, just use replace('\r', ''). Of course, that's an unsafe assumption in the real world. But for a quick and dirty one-liner (and all one-liners are quick and dirty), it should be good enough. -- Steven From ssteinerx at gmail.com Sat Feb 27 13:01:22 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 13:01:22 -0500 Subject: Python dos2unix one liner In-Reply-To: <87mxyuzj13.fsf@castleamber.com> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: On Feb 27, 2010, at 12:27 PM, John Bokma wrote: > "ssteinerX at gmail.com" writes: > >> On Feb 27, 2010, at 10:01 AM, @ Rocteur CC wrote: >>> Nothing to do with Perl, Perl only takes a handful of characters to >>> do this and certainly does not require the creation an intermediate >>> file >> >> Perl may be better for you for throw-away code. Use Python for the >> code you want to keep (and read and understand later). > > Amusing how long those Python toes can be. In several replies I have > noticed (often clueless) opinions on Perl. When do people learn that a > language is just a tool to do a job? I'm not sure how "use it for what it's good for" has anything to do with toes. I've written lots of both Python and Perl and sometimes, for one-off's, Perl is quicker; if you know it. I sure don't want to maintain Perl applications though; even ones I've written. When all you have is a nail file, everything looks like a toe; that doesn't mean you want to have to maintain it. Or something. S From invalid at invalid.invalid Sat Feb 27 13:02:34 2010 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 27 Feb 2010 18:02:34 +0000 (UTC) Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 2010-02-27, @ Rocteur CC wrote: > > On 27 Feb 2010, at 12:44, Steven D'Aprano wrote: > >> On Sat, 27 Feb 2010 10:36:41 +0100, @ Rocteur CC wrote: >> >>> cat file.dos | python -c "import sys,re; >>> [sys.stdout.write(re.compile('\r\n').sub('\n', line)) for line in >>> sys.stdin]" >file.unix >> >> Holy cow!!!!!!! Calling a regex just for a straight literal-to-literal >> string replacement! You've been infected by too much Perl coding! > > Thanks for the replies I'm looking at them now, however, for those who > misunderstood, the above cat file.dos pipe pythong does not come from > Perl but comes from: > > http://wiki.python.org/moin/Powerful%20Python%20One-Liners > >> Apply regular expression to lines from stdin >> [another command] | python -c "import sys,re; >> [sys.stdout.write(re.compile('PATTERN').sub('SUBSTITUTION', line)) >> for line in sys.stdin]" > > Nothing to do with Perl, Perl only takes a handful of > characters to do this and certainly does not require the > creation an intermediate file, In _theory_ you can do a simple string-replace in situ as long as the replacement string is shorter than the original string. But I have a hard time believing that Perl actually does it that. Since I don't speak line-noise, will you please post the Perl script that you claim does the conversion without creating an intermediate file? The only way I can think of to do a general in-situ file modification is to buffer the entire file's worth of output in memory and then overwrite the file after all of the processing has finished. Python can do that too, but it's not generally a very good approach. -- Grant From usenot at geekmail.INVALID Sat Feb 27 13:10:40 2010 From: usenot at geekmail.INVALID (Andreas Waldenburger) Date: Sat, 27 Feb 2010 19:10:40 +0100 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> Message-ID: <20100227191040.6c77f2d8@geekmail.INVALID> On Sat, 27 Feb 2010 07:29:46 -0800 (PST) John Pinner wrote: > A good way to control Python contractors is (given that firstly there > are functional specifications to comply with, and tests to pass) is to > impose the following condition: > > that all code delivered must reach a score of (say) 9.5 or more when > checked by pylint > Now that *is* a good idea. I hadn't thought about that. But as I said: a) I am (we are) not in a position to impose this (We don't work with the code, we just run the software). And b) I wasn't quite serious with this anyway. But still, I'll keep that in mind. /W -- INVALID? DE! From john at castleamber.com Sat Feb 27 13:15:39 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 12:15:39 -0600 Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: <873a0mpmt0.fsf@castleamber.com> "ssteinerX at gmail.com" writes: > I'm not sure how "use it for what it's good for" has anything to do > with toes. I've the feeling that some people who use Python are easily offended by everthing Perl related. Which is silly; zealotism in general is, for that matter. > I've written lots of both Python and Perl and sometimes, for > one-off's, Perl is quicker; if you know it. > > I sure don't want to maintain Perl applications though; even ones I've > written. Ouch, I am afraid that that tells a lot about your Perl programming skills. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From ssteinerx at gmail.com Sat Feb 27 13:29:52 2010 From: ssteinerx at gmail.com (ssteinerx at gmail.com) Date: Sat, 27 Feb 2010 13:29:52 -0500 Subject: Python dos2unix one liner In-Reply-To: <873a0mpmt0.fsf@castleamber.com> References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <873a0mpmt0.fsf@castleamber.com> Message-ID: <2B2A2898-E576-4BDD-B475-C0234D14D155@gmail.com> On Feb 27, 2010, at 1:15 PM, John Bokma wrote: >> I sure don't want to maintain Perl applications though; even ones I've >> written. > > Ouch, I am afraid that that tells a lot about your Perl programming > skills. Nah, it tells you about my preferences. I can, and have, written maintainable things in many languages, including Perl. However, I *choose* Python. S From tjreedy at udel.edu Sat Feb 27 14:28:26 2010 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 27 Feb 2010 14:28:26 -0500 Subject: Karrigell 3.0.4 published In-Reply-To: References: <816a06f6-0409-4c43-ac0c-e62ced0ec993@q16g2000yqq.googlegroups.com> Message-ID: On 2/27/2010 3:21 AM, Pierre Quentel wrote: > > Oops ! wrong group, sorry. It's for c.l.p.announce Announcements also come to c.l.p and python-list. C.l.p.a should be a low-traffic subset, perhaps with followups set to c.l.p for discussion. From aahz at pythoncraft.com Sat Feb 27 14:29:17 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 11:29:17 -0800 Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: In article <87mxyuzj13.fsf at castleamber.com>, John Bokma wrote: > >Amusing how long those Python toes can be. In several replies I have >noticed (often clueless) opinions on Perl. When do people learn that a >language is just a tool to do a job? When do people learn that language makes a difference? I used to be a Perl programmer; these days, you'd have to triple my not-small salary to get me to even think about programming in Perl. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Sat Feb 27 15:46:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 12:46:38 -0800 Subject: Bizarre arithmetic results References: Message-ID: In article , Steven D'Aprano wrote: > >[steve at sylar ~]$ cat ws-example.rb Ahhh, you're a Heroes fan. ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From sillyhat at yahoo.com Sat Feb 27 15:50:38 2010 From: sillyhat at yahoo.com (Hal Styli) Date: Sat, 27 Feb 2010 12:50:38 -0800 (PST) Subject: stripping fields from xml file into a csv Message-ID: Hello, Can someone please help. I have a sed solution to the problems below but would like to rewrite in python... I need to strip out some data from a quirky xml file into a csv: from something like this < ..... cust="dick" .... product="eggs" ... quantity="12" .... > < .... cust="tom" .... product="milk" ... quantity="2" ...> < .... cust="harry" .... product="bread" ... quantity="1" ...> < .... cust="tom" .... product="eggs" ... quantity="6" ...> < ..... cust="dick" .... product="eggs" ... quantity="6" .... > to this dick,eggs,12 tom,milk,2 harry,bread,1 tom,eggs,6 dick,eggs,6 I am new to python and xml and it would be great to see some slick ways of achieving the above by using python's XML capabilities to parse the original file or python's regex to achive what I did using sed. Thanks for any constructive help given. Hal From aahz at pythoncraft.com Sat Feb 27 15:50:41 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 12:50:41 -0800 Subject: Spam from gmail References: <167f59d8-0e6f-43d5-824b-474744a21c88@a18g2000yqc.googlegroups.com> Message-ID: In article , Emile van Sebille wrote: >On 2/24/2010 1:52 PM Arnaud Delobelle said... >> aahz at pythoncraft.com (Aahz) writes: >>> >>> That seems to miss the point to some extent. If I post my recipe for >>> spinach lasagne here, is that spam? >> >> Are they really good? Sounds good, spinach lasagne, I don't know a >> recipe for them. Maybe you could post it as Python code, with a lot of >> nested if-then-else clauses, of course :) > >+1 for Aahz posting his Spinach Lasagne recipe. Sorry, I lied. ;-) I don't actually have a spinach lasagne recipe. I've got lots of others on my personal website at http://rule6.info/ (including one for Catalan Spinach). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From john at castleamber.com Sat Feb 27 15:56:22 2010 From: john at castleamber.com (John Bokma) Date: Sat, 27 Feb 2010 14:56:22 -0600 Subject: stripping fields from xml file into a csv References: Message-ID: <87aauu5rex.fsf@castleamber.com> Hal Styli writes: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite > in python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > < .... cust="harry" .... product="bread" ... quantity="1" ...> > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick > ways of achieving the above by using python's XML capabilities to > parse the original file or python's regex to achive what I did using > sed. It's not clear how your XML actually looks, but (especially) if those are all attributes of one element I probably would just use xml.sax I strongly suggest to not use regex to parse XML. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From dontsendleospam at gmail.com Sat Feb 27 18:57:15 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Sat, 27 Feb 2010 15:57:15 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: I think a big part of the problem is that the scoping rules in Python are inconsistent because classes are a different kind of object. An example helps: This works: x = 1 def f(y): return y + x This works: def f(): x = 1 def g(y): return x + y return g(2) But this doesn't work... class C: x = 1 def f(self,y): return x + y ...although what was probably meant was this, which does work... class C: x = 1 def f(self,y): return self.x + y ...and really means this... class C: x = 1 def f(self,y): return T.x + y ...which create other quirkiness when x is mutable as illustrated nicely here: http://bioscreencastwiki.com/Python_Variable_scope_gymnastics One reasonable answer to this quirkiness is RTFM. Classes are well documented as is everything else in python. Mostly late-binding semantics are also well documented. I argue that it is more consistent to have the scope for classes be consistent with the scope of everything else, which makes the early/ late binding point mute. I know this is a major change, that it would break existing code, etc. It would have been better to talk about these things before py3k. Still: 1. Has this been discussed before? 1. What would this suggestion break? 2. What are the advantages of making the scope of class variables different? Maybe is it just a historical trait? Cheers, Leo. From ssteinerx at gmail.com Sat Feb 27 19:12:10 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 19:12:10 -0500 Subject: scope of generators, class variables, resulting in global na In-Reply-To: References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: On Feb 27, 2010, at 6:57 PM, dontspamleo wrote: > > > http://bioscreencastwiki.com/Python_Variable_scope_gymnastics Broken link: Site settings could not be loaded We were unable to locate the API to request site settings. Please see below for debugging information. HTTP Response Status Code: 0 From aahz at pythoncraft.com Sat Feb 27 19:47:30 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 16:47:30 -0800 Subject: python dowload References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: In article <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d at insightbb.com>, monkeys paw wrote: >On 2/23/2010 3:17 PM, Tim Chase wrote: >> >> Sure you don't need this to be 'wb' instead of 'w'? > >'wb' does the trick. Thanks all! > >import urllib2 >a = open('adobe.pdf', 'wb') >i = 0 >for line in >urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): > i = i + 1 > a.write(line) Using a for loop here is still a BAD IDEA -- line could easily end up megabytes in size (though that is statistically unlikely). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From tarekamr at gmail.com Sat Feb 27 20:41:09 2010 From: tarekamr at gmail.com (tarekamr at gmail.com) Date: Sat, 27 Feb 2010 17:41:09 -0800 (PST) Subject: Pyrhon2.5 to 2.4 conversion Message-ID: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Hi, I am currently using oauth2.py library, and it works fine on one of my PC's (python2.5), but later on when I tried to use it with python2.4 the following line (line 332 in http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) showed a syntax error items = [(k, v if type(v) != ListType else sorted(v)) for k,v in sorted(self.items()) if k != 'oauth_signature'] So it there a way to convert this line to a python2.4 compliant syntax. Thanks a lot, Tarek From rjngrj2010 at gmail.com Sat Feb 27 20:48:15 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sat, 27 Feb 2010 17:48:15 -0800 (PST) Subject: help with Python installation Message-ID: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Hi, I have been trying to install python on my Win ME system for over two years - gave up for a while and now I am back with a resolve to solve the problem. I tried all versions of python but having installation problems for all. Installation does not proceed and I get a message saying "dll required for installation could not be run". I do not even know what to do next. I also tried Activepython. It installs but when I try to open it from Start->Programs->ActivePython 2.6, I get an error window saying - upgrade windows. Is there no solution at all to installing python on WinME. I have checked registry several times online and have sought professional help but so far no success. Thanks, I will appreciate any help gujax From benjamin.kaplan at case.edu Sat Feb 27 20:49:51 2010 From: benjamin.kaplan at case.edu (Benjamin Kaplan) Date: Sat, 27 Feb 2010 20:49:51 -0500 Subject: Pyrhon2.5 to 2.4 conversion In-Reply-To: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: On Sat, Feb 27, 2010 at 8:41 PM, tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 > the following line (line 332 in > http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant > syntax. > > That's a list comprehension. Really useful tool. That line is equivalent to items = [] for k,v in sorted(self.items()) : if k != 'oauth_signature' : if type(v) != ListType: items.append((k,v)) else : items.append(sorted(v)) -------------- next part -------------- An HTML attachment was scrubbed... URL: From zaphod at beeblebrox.net Sat Feb 27 20:52:15 2010 From: zaphod at beeblebrox.net (Zaphod) Date: Sun, 28 Feb 2010 01:52:15 GMT Subject: stripping fields from xml file into a csv References: Message-ID: On Sat, 27 Feb 2010 12:50:38 -0800, Hal Styli wrote: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite in > python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > < .... > cust="tom" .... product="milk" ... quantity="2" ...> < .... cust="harry" > .... product="bread" ... quantity="1" ...> < .... cust="tom" .... > product="eggs" ... quantity="6" ...> < ..... cust="dick" .... > product="eggs" ... quantity="6" .... > > > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick ways > of achieving the above by using python's XML capabilities to parse the > original file or python's regex to achive what I did using sed. > > Thanks for any constructive help given. > > Hal Start here: http://pyxml.sourceforge.net/topics/ From clp2 at rebertia.com Sat Feb 27 20:58:34 2010 From: clp2 at rebertia.com (Chris Rebert) Date: Sat, 27 Feb 2010 17:58:34 -0800 Subject: Pyrhon2.5 to 2.4 conversion In-Reply-To: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <50697b2c1002271758s17ec88d4oc122a31634dafb1e@mail.gmail.com> On Sat, Feb 27, 2010 at 5:41 PM, tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 > the following line (line 332 in http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant > syntax. This part is your problem: (k, v if type(v) != ListType else sorted(v)) Conditional expressions like that were added in v2.5: http://docs.python.org/whatsnew/2.5.html#pep-308-conditional-expressions Here's an untested substitute: def sort_or_tuple(k, v): if type(v) != ListType: return k, v else: return sorted(v) items = [sort_or_tuple(k,v) for k,v in sorted(self.items()) if k != 'oauth_signature'] Of course, the more obvious solution is just to upgrade your Python; it's well worth it! Cheers, Chris -- http://blog.rebertia.com From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 21:02:58 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 02:02:58 GMT Subject: Pyrhon2.5 to 2.4 conversion References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <4b89ced1$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 17:41:09 -0800, tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 the > following line (line 332 in > http://github.com/simplegeo/python-oauth2/blob/master/oauth2/ __init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant syntax. You would be better off installing Python2.5 on the PC rather than trying to backport the library to 2.4. There could be thousands of changes needed to backport the library. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 21:03:12 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 02:03:12 GMT Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: <4b89cee0$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 11:27:04 -0600, John Bokma wrote: > When do people learn that a > language is just a tool to do a job? When do people learn that there are different sorts of tools? A professional wouldn't use a screwdriver when they need a hammer. Perl has strengths: it can be *extremely* concise, regexes are optimized much more than in Python, and you can do some things as a one-liner short enough to use from the command line easily. Those are values, as seen by the millions of people who swear by Perl, but they are not Python's values. If you want something which can make fine cuts in metal, you would use a hacksaw, not a keyhole saw or a crosscut saw. If you want to cut through an three foot tree truck, you would use a ripsaw or a chainsaw, and not a hacksaw. If you want concise one-liners, you would use Perl, not Python, and if you want readable, self-documenting code, you're more likely to get it from Python than from Perl. If every tool is the same, why aren't we all using VB? Or C, or Javascript, or SmallTalk, or Forth, or ... ? In the real world, all these languages have distinguishing characteristics and different strengths and weaknesses, which is why there are still people using PL/I and Cobol as well as people using Haskell and Lisp and Boo and PHP and D and ... Languages are not just nebulous interchangeable "tools", they're tools for a particular job with particular strengths and weaknesses, and depending on what strengths you value and what weaknesses you dislike, some tools simply are better than other tools for certain tasks. -- Steven From greg.ewing at canterbury.ac.nz Sat Feb 27 21:06:44 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Feb 2010 15:06:44 +1300 Subject: staticmethod and namespaces In-Reply-To: References: <7uphq3FuapU1@mid.uni-berlin.de> <52e45c25-2802-458e-8297-9eb3bb4e055a@k17g2000yqb.googlegroups.com> <7uq8d7FvifU1@mid.uni-berlin.de> <783b7ba9-6160-4396-a8c7-1a0404100476@o30g2000yqb.googlegroups.com> <7uqa0eF95lU1@mid.uni-berlin.de> <7uqamjFd2vU2@mid.uni-berlin.de> Message-ID: <7uu0q2Fb8hU1@mid.individual.net> darnzen wrote: > Well, I got around this mess by putting all those static callbacks > into a separate module in a new class. I set them up to call a bound > method of that class which passes the arguments to the appropriate > bound methods of other class instances. I just have to keep a little > dict of the bound method callbacks when I register them with the > class. You're making it much more complicated than it needs to be. Diez is right, a bound method should work provided you keep a reference to it somewhere for as long as it's needed. -- Greg From python at mrabarnett.plus.com Sat Feb 27 21:12:12 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Feb 2010 02:12:12 +0000 Subject: Pyrhon2.5 to 2.4 conversion In-Reply-To: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> References: <739740b0-802d-4f1b-8c09-c9094242ffad@g10g2000yqh.googlegroups.com> Message-ID: <4B89D0FC.7080205@mrabarnett.plus.com> tarekamr at gmail.com wrote: > Hi, > > I am currently using oauth2.py library, and it works fine on one of my > PC's (python2.5), but later on when I tried to use it with python2.4 > the following line (line 332 in http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py) > showed a syntax error > > items = [(k, v if type(v) != ListType else sorted(v)) for k,v in > sorted(self.items()) if k != 'oauth_signature'] > > So it there a way to convert this line to a python2.4 compliant > syntax. > I think the clearest is: items = [] for k, v in sorted(self.items()): if k != 'oauth_signature': if type(v) == ListType: v = sorted(v) items.append((k, v)) From python.list at tim.thechases.com Sat Feb 27 21:19:03 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 27 Feb 2010 20:19:03 -0600 Subject: python dowload In-Reply-To: References: <2fWdnXOfjat-whnWnZ2dnUVZ_rGdnZ2d@insightbb.com> Message-ID: <4B89D297.8010901@tim.thechases.com> Aahz wrote: > monkeys paw wrote: >> On 2/23/2010 3:17 PM, Tim Chase wrote: >>> Sure you don't need this to be 'wb' instead of 'w'? >> 'wb' does the trick. Thanks all! >> >> import urllib2 >> a = open('adobe.pdf', 'wb') >> i = 0 >> for line in >> urllib2.urlopen('http://www.whirlpoolwaterheaters.com/downloads/6510413.pdf'): >> i = i + 1 >> a.write(line) > > Using a for loop here is still a BAD IDEA -- line could easily end up > megabytes in size (though that is statistically unlikely). Just so the OP has it, dealing with binary files without reading the entire content into memory would look something like from urllib2 import urlopen CHUNK_SIZE = 1024*4 # 4k, why not? OUT_NAME = 'out.pdf' a = open(OUT_NAME, 'wb') u = urlopen(URL) bytes_read = 0 while True: data = u.read(CHUNK_SIZE) if not data: break a.write(data) bytes_read += len(data) print "Wrote %i bytes to %s" % ( bytes_read, OUT_NAME) -tkc From greg.ewing at canterbury.ac.nz Sat Feb 27 21:23:03 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Feb 2010 15:23:03 +1300 Subject: Docstrings considered too complicated In-Reply-To: References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> Message-ID: <7uu1ooFiipU1@mid.individual.net> Mel wrote: > You could think of it as a not bad use of the design principle "Clear The > Simple Stuff Out Of The Way First". Destinations are commonly a lot simpler > than sources That's not usually true in assembly languages, though, where the source and destination are both very restricted and often about the same complexity. That's not to say that right-to-left is the wrong way to do it in an assembly language, but there are less misleading words than "move" that could be used. Z80 assembly language uses "load", which makes things considerably clearer: LD A, B ; load A with B -- Greg From rantingrick at gmail.com Sat Feb 27 21:26:23 2010 From: rantingrick at gmail.com (rantingrick) Date: Sat, 27 Feb 2010 18:26:23 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: <921d8fca-2cdc-4444-87c0-96f4072fbfdb@d2g2000yqa.googlegroups.com> On Feb 27, 7:48?pm, gujax wrote: > Hi, > I have been trying to install python on my Win ME system for over two > years - Wow 2 years!, you must have the patience of a saint! > Installation does not proceed and I get a message > saying "dll required for installation could not be run". Did it say "what" dll did not run, did have a name? > I do not even > know what to do next. I also tried Activepython. It installs but when > I try to open it from Start->Programs->ActivePython 2.6, I get an > error window saying - upgrade windows. Hmm, have you tried "upgrading windows, just a wild guess! From rpdooling at gmail.com Sat Feb 27 21:36:45 2010 From: rpdooling at gmail.com (Rick Dooling) Date: Sat, 27 Feb 2010 18:36:45 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: > Hi, > I have been trying to install python on my Win ME system Try this: http://tinyurl.com/w7wgp RD From ssteinerx at gmail.com Sat Feb 27 21:38:00 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sat, 27 Feb 2010 21:38:00 -0500 Subject: help with Python installation In-Reply-To: <921d8fca-2cdc-4444-87c0-96f4072fbfdb@d2g2000yqa.googlegroups.com> References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <921d8fca-2cdc-4444-87c0-96f4072fbfdb@d2g2000yqa.googlegroups.com> Message-ID: >> I do not even >> know what to do next. I also tried Activepython. It installs but when >> I try to open it from Start->Programs->ActivePython 2.6, I get an >> error window saying - upgrade windows. > > Hmm, have you tried "upgrading windows, just a wild guess! Hey, not everyone can afford to upgrade Windows and some hardware just can't handle the "new, improved" versions. How about we all chip in to buy him a copy of Ubuntu? Oh, wait, it's free... S From steve at REMOVE-THIS-cybersource.com.au Sat Feb 27 21:44:17 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 02:44:17 GMT Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> Message-ID: <4b89d880$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 15:57:15 -0800, dontspamleo wrote: > I think a big part of the problem is that the scoping rules in Python > are inconsistent because classes are a different kind of object. An > example helps: [...] > But this doesn't work... > class C: > x = 1 > def f(self,y): return x + y > > ...although what was probably meant was this, which does work... > class C: > x = 1 > def f(self,y): return self.x + y Yes, this is a deliberate design choice. See below. > ...and really means this... > class C: > x = 1 > def f(self,y): return T.x + y I don't understand what T is. Did you mean C? If so, you are wrong. self.x is not the same as .x due to inheritance rules. Consider one example: >>> class A: ... x = 1 ... def __init__(self, x=None): ... if x is not None: ... self.x = x ... >>> class B(A): ... def f(self, y): return self.x + y ... >>> class C(A): ... def f(self, y): return C.x + y ... >>> >>> B(5).f(10) 15 >>> C(5).f(10) 11 I have no doubt that there will be other examples involving multiple inheritance, but I trust I've made my point. > I argue that it is more consistent to have the scope for classes be > consistent with the scope of everything else, which makes the early/ > late binding point mute. Yes, it would be more consistent, but less useful. Apart from methods themselves, using class attributes is a relatively rare thing to do, but using global level names inside methods is very common. > I know this is a major change, that it would break existing code, etc. > It would have been better to talk about these things before py3k. Still: > > 1. Has this been discussed before? Yes. > 1. What would this suggestion break? Nearly all existing code using classes, which is nearly everything. > 2. What are the advantages of making the scope of class variables > different? Maybe is it just a historical trait? See the discussion in the PEP for introducing nested scopes in the first place: http://www.python.org/dev/peps/pep-0227/ -- Steven From python at mrabarnett.plus.com Sat Feb 27 21:45:18 2010 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 28 Feb 2010 02:45:18 +0000 Subject: Docstrings considered too complicated In-Reply-To: <7uu1ooFiipU1@mid.individual.net> References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> Message-ID: <4B89D8BE.2040905@mrabarnett.plus.com> Gregory Ewing wrote: > Mel wrote: > >> You could think of it as a not bad use of the design principle "Clear >> The Simple Stuff Out Of The Way First". Destinations are commonly a >> lot simpler than sources > > That's not usually true in assembly languages, though, > where the source and destination are both very restricted > and often about the same complexity. > > That's not to say that right-to-left is the wrong way > to do it in an assembly language, but there are less > misleading words than "move" that could be used. > > Z80 assembly language uses "load", which makes things > considerably clearer: > > LD A, B ; load A with B > Some processors distinguish between "load" (memory to register) and "store" (register to memory), and the destination and LHS operand of binary operations might be the same register, for example: CLC ; clear the carry LDA first ; accumulator := byte at first ADCA second ; accumulator := accumulator + byte at second + carry STA result ; byte at third := accumulator From steve at holdenweb.com Sat Feb 27 21:55:50 2010 From: steve at holdenweb.com (Steve Holden) Date: Sat, 27 Feb 2010 21:55:50 -0500 Subject: help with Python installation In-Reply-To: References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: Rick Dooling wrote: >> Hi, >> I have been trying to install python on my Win ME system > > Try this: > > http://tinyurl.com/w7wgp > That explains how to install Python on Windows *XP*. Windows ME is no longer a supported platform - the tools used to create it just aren't able to support platforms that old. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ From staticd at gmail.com Sat Feb 27 21:56:31 2010 From: staticd at gmail.com (staticd) Date: Sat, 27 Feb 2010 18:56:31 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: <6b04c31f-fdaa-4f63-99fb-5bebe7ae4b0e@z11g2000yqz.googlegroups.com> On Feb 27, 8:48?pm, gujax wrote: > I have been trying to install python on my Win ME system for over two > years - gave up for a while and now I am back with a resolve to solve > the problem. Dude. Give up. There are a ton of __free__ distroz of linux out there. Your troubles are not worth the effort. Why do I say this? Let's say you do, eventually, figure out what's wrong. Now what? Why are you so attached to this machine with ME on it? nd From arnodel at googlemail.com Sat Feb 27 22:14:49 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sat, 27 Feb 2010 19:14:49 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: <038b8f03-c0bc-4ca3-b4eb-73e01ce7f69f@z35g2000yqd.googlegroups.com> On 28 Feb, 01:48, gujax wrote: > Hi, > I have been trying to install python on my Win ME system for over two > years - gave up for a while and now I am back with a resolve to solve > the problem. I tried all versions of python but having installation > problems for all. Installation does not proceed and I get a message > saying "dll required for installation could not be run". I do not even > know what to do next. I also tried Activepython. It installs but when > I try to open it from Start->Programs->ActivePython 2.6, I get an > error window saying - upgrade windows. > Is there no solution at all to installing python on WinME. I have > checked registry several times online and have sought professional > help but so far no success. > Thanks, I will appreciate any help > gujax The docs (*) say that Python 2.5 is still compatible with Windows 9X and ME, but that support for these platform was dropped at 2.6. So you should be able to install and run Python 2.5. (*) http://docs.python.org/using/windows.html#installing-python -- Arnaud From staticd at gmail.com Sat Feb 27 22:37:50 2010 From: staticd at gmail.com (staticd) Date: Sat, 27 Feb 2010 19:37:50 -0800 (PST) Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> Message-ID: <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> > >Amusing how long those Python toes can be. In several replies I have > >noticed (often clueless) opinions on Perl. When do people learn that a > >language is just a tool to do a job? > > When do people learn that language makes a difference? ?I used to be a > Perl programmer; these days, you'd have to triple my not-small salary to > get me to even think about programming in Perl. dude, you nailed it. many times, if not _always_, the correct output is important. the method used to produce the output is irrelevant. From wuhrrr at gmail.com Sat Feb 27 23:15:43 2010 From: wuhrrr at gmail.com (Hai Vu) Date: Sat, 27 Feb 2010 20:15:43 -0800 (PST) Subject: stripping fields from xml file into a csv References: Message-ID: On Feb 27, 12:50?pm, Hal Styli wrote: > Hello, > > Can someone please help. > I have a sed solution to the problems below but would like to rewrite > in python... > > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > < .... cust="harry" .... product="bread" ... quantity="1" ...> > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick > ways of achieving the above by using python's XML capabilities to > parse the original file or python's regex to achive what I did using > sed. > > Thanks for any constructive help given. > > Hal Here is a sample XML file (I named it data.xml): -------------------------- -------------------------- Code: -------------------------- import csv import xml.sax # Handle the XML file with the following structure: # # ... # class OrdersHandler(xml.sax.handler.ContentHandler): def __init__(self, csvfile): # Open a csv file for output self.csvWriter = csv.writer(open(csvfile, 'w')) def startElement(self, name, attributes): # Only process the element if name == 'order': # Construct a sorted list of attribute names in order to # guarantee rows are written in the same order. We assume # the XML elements contain the same attributes attributeNames = attributes.getNames() attributeNames.sort() # Construct a row and write it to the csv file row = [] for name in attributeNames: row.append(attributes.getValue(name)) self.csvWriter.writerow(row) def endDocument(self): # Destroy the csv writer object to close the file self.csvWriter = None # Main datafile = 'data.xml' csvfile = 'data.csv' ordersHandler = OrdersHandler(csvfile) xml.sax.parse(datafile, ordersHandler) -------------------------- To solve your problem, it is easier to use SAX than DOM. Basically, use SAX to scan the XML file, if you encounter the element you like (in this case ) then you process its attributes. In this case, you sort the attributes, then write to a csv file. -------------------------- References: SAX Parser: http://docs.python.org/library/xml.sax.html SAX Content Handler: http://docs.python.org/library/xml.sax.handler.html Attributes Object: http://docs.python.org/library/xml.sax.reader.html#attributes-objects From greg.ewing at canterbury.ac.nz Sat Feb 27 23:27:11 2010 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 28 Feb 2010 17:27:11 +1300 Subject: random.gauss: range In-Reply-To: <4b888905$0$27844$c3e8da3@news.astraweb.com> References: <4b888905$0$27844$c3e8da3@news.astraweb.com> Message-ID: <7uu91gFh1gU1@mid.individual.net> Steven D'Aprano wrote: > def pinned_gaussian(a, b, mu, sigma): > """Return a Gaussian random number pinned to [a, b].""" > return min(b, max(a, random.gauss(mu, sigma))) > > def truncated_gauss(a, b, mu, sigma): > """Return a random number from a truncated Gaussian distribution.""" > while 1: > x = random.gauss(mu, sigma) > if a <= x <= b: > return x If it doesn't have to be strictly gaussian, another way is to approximate it by adding some number of uniformly distributed samples together. If you have n uniform samples ranging from 0 to a, the sum will be in the range 0 to n*a and the mean will be n*a/2. The greater the value of n, the closer the distribution will be to normal. -- Greg From pfeldman at verizon.net Sat Feb 27 23:35:28 2010 From: pfeldman at verizon.net (Dr. Phillip M. Feldman) Date: Sat, 27 Feb 2010 20:35:28 -0800 (PST) Subject: Turtle graphics speed(). Seems broken In-Reply-To: <47B5B897.2030300@behnel.de> References: <47B5B897.2030300@behnel.de> Message-ID: <27732940.post@talk.nabble.com> Stefan Behnel-3 wrote: > > Alexander.Oot at gmail.com wrote: >> I think the speed function may be broken from the turtle graphics package >> >> >> "from turtle import * >> >> speed('fastest') >> >> forward(50)" >> >> >> I have tried all of the different speed settings, but I get no change >> in the turtle's speed.... does anyone know how to fix this? > > Use "xturtle"? :) > > http://ada.rg16.asn-wien.ac.at/~python/xturtle/ > > Stefan > -- > http://mail.python.org/mailman/listinfo/python-list > > The Python library's implementation of turtle graphics is slow to the point that many applications are simply impractical. I recently converted a program to Python/turtle graphics that was originally written by my son using Processing; the result of the conversion is that the time to draw the balls increased by a factor of roughly 50! (The Processing version takes less than 0.1 seconds to generate the image, while the Python version takes almost 5 seconds on the same computer). It would be good if this performance problem can be fixed, either by patching the current implementation of turtle graphics, or by replacing it with xturtle if that is better. http://old.nabble.com/file/p27732940/balls.py balls.py -- View this message in context: http://old.nabble.com/Turtle-graphics-speed%28%29.-Seems-broken-tp15504443p27732940.html Sent from the Python - python-list mailing list archive at Nabble.com. From rjngrj2010 at gmail.com Sun Feb 28 00:46:21 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sat, 27 Feb 2010 21:46:21 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> Message-ID: On Feb 27, 9:36?pm, Rick Dooling wrote: > > Hi, > > I have been trying to install python on my Win ME system > > Try this: > > http://tinyurl.com/w7wgp > > RD I gave it a shot but the site installs the same version of ActivePython which did install on my computer but does not open any command windows. See my earlier posted e-mail. Thanks anyway, From alfps at start.no Sun Feb 28 00:49:22 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Feb 2010 06:49:22 +0100 Subject: Turtle graphics speed(). Seems broken In-Reply-To: References: <47B5B897.2030300@behnel.de> Message-ID: * Dr. Phillip M. Feldman: > > Stefan Behnel-3 wrote: >> Alexander.Oot at gmail.com wrote: >>> I think the speed function may be broken from the turtle graphics package >>> >>> >>> "from turtle import * >>> >>> speed('fastest') >>> >>> forward(50)" >>> >>> >>> I have tried all of the different speed settings, but I get no change >>> in the turtle's speed.... does anyone know how to fix this? >> Use "xturtle"? :) >> >> http://ada.rg16.asn-wien.ac.at/~python/xturtle/ >> >> Stefan >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > The Python library's implementation of turtle graphics is slow to the point > that many applications are simply impractical. I recently converted a > program to Python/turtle graphics that was originally written by my son > using Processing; the result of the conversion is that the time to draw the > balls increased by a factor of roughly 50! (The Processing version takes > less than 0.1 seconds to generate the image, while the Python version takes > almost 5 seconds on the same computer). It would be good if this > performance problem can be fixed, either by patching the current > implementation of turtle graphics, or by replacing it with xturtle if that > is better. http://old.nabble.com/file/p27732940/balls.py balls.py Try to add turtle.tracer( 0 ) before generating the graphics, and turtle.update() after. It sort of speeds things up. :-) To test it I had to rewrite your code a little, getting rid of the numpy dependency since I don't have numpy installed. Looks like this: #from numpy import * def array( data, dtype ): return data # Emulate numpy array constructor import random from math import * import sys from time import time import turtle # turtle graphics module class Timer: """Track and record elapsed time, allowing an arbitrary number of timers.""" from time import time # Constructor: def __init__(self): self.start= time() # Report elapsed time: def time(self): # Compute elapse time: elapsed= time() - self.start # Print elapsed time in seconds: print str(elapsed) + ' s', # If total elapsed time exceeds 60 seconds, also print time as # as minutes and seconds: if elapsed >= 60.0: minutes= numpy.floor(elapsed / 60.0) elapsed-= 60 * minutes print '= ' + num2str(minutes,0) + ' m ' + num2str(elapsed,3) + ' s' else: print def main(): # Section 1: User inputs. All four arrays should have the same dimensions. balls_of_type = array([20, 20], dtype=int) radius_of_type= array([35, 25], dtype=float) mass_of_type = array([4 , 2], dtype=float) color_of_type = array([0 , 1], dtype=int) canvas_width = 1000 # canvas width in pixels canvas_height= 800 # canvas height in pixels # Section 2: Setup. # Section 2.1: Initialize graphics. turtle.setup(width=canvas_width, height=canvas_height) # Use units of pixels for specifying locations on the screen: turtle.setworldcoordinates(0.0, 0.0, canvas_width, canvas_height) # Set background color to black: turtle.bgcolor("black") # We want to specify R, G, and B using whole numbers from 0 to 255: turtle.colormode(255) # Turn off animation and hide the turtle to get maximum drawing speed: turtle.speed('fastest') turtle.tracer( 0 ) turtle.hideturtle() # Section 2.2: Preliminaries. ball_types= len(balls_of_type) max_tries= 1000 tries= 0 # The following variable counts the number of time ticks: tick= 0 colors= [ (255, 0, 0), # red ( 64, 64, 230), # blue, cobalt blue (125, 0, 0), # maroon ( 0, 255, 255), # cyan,baby blue (255, 140, 0), # orange ( 0, 255, 0), # green, light green (204, 128, 0), # brown (255, 200, 120), # light orange (255, 255, 140), # cream (0, 128, 0), # dark green, forest green (255, 128, 128), # peach (255, 255, 0), # yellow (0, 0, 204), # dark blue, navy blue (150, 355, 150), # light green (128, 0, 230), # purple (77, 204, 0), # avocado (255, 128, 255), # magenta, pink (0, 204, 204), # aqua, turquoise (230, 192, 0), # gold (255, 255, 255), # white ] # Allocate 2-element lists for basis and velocity vectors: u_hat= [0,0] v_hat= [0,0] uv_speed1b= [0,0]; # before the collision uv_speed2b= [0,0]; # before the collision uv_speed1a= [0,0]; # after the collision uv_speed2a= [0,0]; # after the collision # Section 2.3: Calculate the number of balls and allocate arrays whose sizes # depend on this. # `balls` is the total number of balls: balls= sum( balls_of_type ) x = balls*[0.0] #zeros(balls, dtype=float) y = balls*[0.0] #zeros(balls, dtype=float) x_speed = balls*[0.0] #zeros(balls, dtype=float) y_speed = balls*[0.0] #zeros(balls, dtype=float) radius = balls*[0.0] #zeros(balls, dtype=float) mass = balls*[0.0] #zeros(balls, dtype=float) ball_type = balls*[0] #zeros(balls, dtype=int) ball_color= [] # empty list # Section 2.4: Assign a ball type, radius, mass, color, initial position, # and initial velocity to each ball. n= -1 for i in range(ball_types): # Valid color numbers are 0-19. If the color number of a ball type is # greater than 19, the following line of code fixes the problem by randomly # assigning acolor number. if color_of_type[i] >= 20: color_of_type[i]= random.randint(0, 20) # In the following loop, j is the ball number for the ith type of ball: for j in range(balls_of_type[i]): # After the following statement executes, `n` will be one less than the # number of balls generated. n+= 1 ball_type[n]= i radius[n]= radius_of_type[i] mass [n]= mass_of_type [i] ball_color.append( colors[color_of_type[i]] ) # Continue loop until center coordinates for ball[n] are such that this # ball does not overlap any previously generated ball. If the number of # iterations exceeds max_tries, then the program stops the loop if this # happens, the program doesn't work because there is not enough space # for all the balls in the container. for tries in range(max_tries): # generate random ball center coordinates: keepout= radius[n] + 2.0 x[n]= random.uniform(keepout, canvas_width - keepout) y[n]= random.uniform(keepout, canvas_height - keepout) # Check to see if two balls have been generated on top of each other. # First, we set good to True. True means that this ball does not # overlap any of the other balls that we have checked so far. At the # end of the inner loop, if good= False, this means that the ball did # overlap at least one of the previous balls, and the program goes back # to the top of the outer loop and generates new coordinates for the # current ball. good= True for m in range(n): # innermost loop dx= x[m] - x[n] dy= y[m] - y[n] d= sqrt(dx*dx + dy*dy) if (d <= radius[m] + radius[n] + 10): good= False break # end for inner for loop if good: break # end of loop over tries if not good: print "\nERROR: Not enough space for balls.\n" sys.exit() # Assign a random initial velocity to the current ball: theta= random.uniform(0.0, 2.0*pi) x_speed[n]= 2. * cos(theta) y_speed[n]= 2. * sin(theta) # end of loop over j (number of ball of current ball type) # end of loop over i (number of ball type) # Section 3: Draw the balls. # Initialize timer: t= Timer() for n in range(balls): turtle.penup() turtle.goto(x[n], y[n]) turtle.pendown() turtle.color(ball_color[n]) turtle.begin_fill() turtle.circle(radius[n]) turtle.end_fill() turtle.update() # Display elapsed time: print "Total drawing time: ", t.time() raw_input('Hit Enter to close figure window.') if __name__ == "__main__": msg = main() print(msg) Cheers & hth., - Alf From rjngrj2010 at gmail.com Sun Feb 28 00:51:32 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sat, 27 Feb 2010 21:51:32 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <6b04c31f-fdaa-4f63-99fb-5bebe7ae4b0e@z11g2000yqz.googlegroups.com> Message-ID: <2feb50ee-515f-48d9-99c0-772327597217@b7g2000yqd.googlegroups.com> On Feb 27, 9:56?pm, staticd wrote: > On Feb 27, 8:48?pm, gujax wrote: > > > I have been trying to install python on my Win ME system for over two > > years - gave up for a while and now I am back with a resolve to solve > > the problem. > > Dude. ?Give up. ?There are a ton of __free__ distroz of linux out > there. ?Your troubles are not worth the effort. ?Why do I say this? > Let's say you do, eventually, figure out what's wrong. ?Now what? > > Why are you so attached to this machine with ME on it? > > nd I agree with you. I have a CD of Xubuntu. I tried booting up with the CD and was impressed. I noticed few problems with screen resolution, window size etc. I am not yet sure which distroz is the best for an instrument with a 512 Mb RAM, 700MHz pentium III chip and about 10Gb mem. Not sure if this is the right forum for this topic though, And no, I am not at all attached to Win, though wouldn't say the same for my computer. Cheers, gujax From spamfresser at ch3ka.de Sun Feb 28 01:07:41 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 28 Feb 2010 07:07:41 +0100 Subject: Signature-based Function Overloading in Python In-Reply-To: References: Message-ID: Am 27.02.2010 10:00, schrieb alex23: > Michael Rudolf wrote: >> In Java, Method Overloading is my best friend > > Guido wrote a nice article[1] on "multimethods" using decorators, > which Ian Bicking followed up on[2] with a non-global approach. > > 1: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 > 2: http://blog.ianbicking.org/more-on-multimethods.html Nice! I really liked http://bob.pythonmac.org/archives/2005/03/30/five-minute-multimethods-in-python-using-dispatch/ From aahz at pythoncraft.com Sun Feb 28 02:22:31 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 23:22:31 -0800 Subject: Creating variables from dicts References: <20d3d914-f12a-4d24-9ef6-885de43c6aa8@n3g2000vbl.googlegroups.com> Message-ID: In article , Tim Chase wrote: >Luis M. Gonz?lez wrote: >> >> If you want a list of items, you use tuples or lists. Examples: >> >> ('a', 'm', 'p') ---> this is a tuple, and it's made with >> parenthesis () > >Actually, a tuple is made with commas...the parens are just there >to clarify the order of operations and make it easier to read :) > > >>> x = 1,2,3 > >>> x > (1, 2, 3) Almost true: >>> x = () >>> x () Parentheses are definitely needed for the empty tuple. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From aahz at pythoncraft.com Sun Feb 28 02:28:39 2010 From: aahz at pythoncraft.com (Aahz) Date: 27 Feb 2010 23:28:39 -0800 Subject: Is this secure? References: <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: In article , Robert Kern wrote: > >If you are storing the password instead of making your user remember >it, most platforms have some kind of keychain secure password >storage. I recommend reading up on the APIs available on your targeted >platforms. Are you sure? I haven't done a lot of research, but my impression was that Windows didn't have anything built in. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From trstrstrs123 at gmail.com Sun Feb 28 02:48:22 2010 From: trstrstrs123 at gmail.com (trstrstrs trstrstrs) Date: Sat, 27 Feb 2010 23:48:22 -0800 (PST) Subject: Paper Presentation Topics Message-ID: Paper Presentation Topics. Our database posses huge collection of topics for paper presentations in all areas. Check all our paper presentation topics at http://pptcontent.blogspot.com/ Paper Presentation Topics Paper presentation topics for ece ">Paper presentation topics for ece Paper presentation topics for cse Paper presentation topics for it Paper presentation topics for eee Paper presentation topics for mba Paper presentation topics for civil engineering Paper presentation topics for mechanical engineering Our sample list list of paper presentation topics in all area branches : Hot Topics : | Lunar Solar Power | | Speech Recognition | | Bullet Proof Vests | | Nano Robos | | Diamond Search | | Brain Controlled Car | From stefan_ml at behnel.de Sun Feb 28 03:05:11 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 09:05:11 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: References: Message-ID: Hal Styli, 27.02.2010 21:50: > I have a sed solution to the problems below but would like to rewrite > in python... Note that sed (or any other line based or text based tool) is not a sensible way to handle XML. If you want to read XML, use an XML parser. They are designed to do exactly what you want in a standard compliant way, and they can deal with all sorts of XML formatting and encoding, for example. > I need to strip out some data from a quirky xml file into a csv: > > from something like this > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > < .... cust="harry" .... product="bread" ... quantity="1" ...> > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > As others have noted, this doesn't tell much about your XML. A more complete example would be helpful. > to this > > dick,eggs,12 > tom,milk,2 > harry,bread,1 > tom,eggs,6 > dick,eggs,6 > > I am new to python and xml and it would be great to see some slick > ways of achieving the above by using python's XML capabilities to > parse the original file or python's regex to achive what I did using > sed. It's funny how often people still think that SAX is a good way to solve XML problems. Here's an untested solution that uses xml.etree.ElementTree: from xml.etree import ElementTree as ET csv_field_order = ['cust', 'product', 'quantity'] clean_up_used_elements = None for event, element in ET.iterparse("thefile.xml", events=['start']): # you may want to select a specific element.tag here # format and print the CSV line to the standard output print(','.join(element.attrib.get(title, '') for title in csv_field_order)) # safe some memory (in case the XML file is very large) if clean_up_used_elements is None: # this assigns the clear() method of the root (first) element clean_up_used_elements = element.clear clean_up_used_elements() You can strip everything dealing with 'clean_up_used_elements' (basically the last section) if your XML file is small enough to fit into memory (a couple of MB is usually fine). Stefan From m.92ahesh at gmail.com Sun Feb 28 03:14:13 2010 From: m.92ahesh at gmail.com (jaagar) Date: Sun, 28 Feb 2010 00:14:13 -0800 (PST) Subject: Paper Presentation Topics Message-ID: Paper Presentation Topics. Our database posses huge collection of topics for paper presentations in all areas. Check all our paper presentation topics at http://pptcontent.blogspot.com/ Topics for Paper Presentation : Paper presentation topics for ece. Paper presentation topics for cse. Paper presentation topics for eee. Paper presentation topics for it. Paper presentation topics for mba. Paper presentation topics for mechanical engineering. Paper presentation topics for civil engineering. Paper presentation topics for eee. Our sample list list of paper presentation topics in all area branches : Hot Topics : Lunar Solar Power,Speech Recognition,Bullet Proof Vests,Nano Robos,Diamond Search,Brain Controlled Car From no.email at nospam.invalid Sun Feb 28 03:43:10 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Feb 2010 00:43:10 -0800 Subject: Is this secure? References: <7xk4u26qz0.fsf@ruckus.brouhaha.com> Message-ID: <7xwrxxrbs1.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > Are you sure? I haven't done a lot of research, but my impression was > that Windows didn't have anything built in. I don't know much about the windows but there is the CAPI and then there is all the TCPA (i.e. DRM) stuff. Maybe it can be used somehow. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 28 03:48:31 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 08:48:31 GMT Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> Message-ID: <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> On Sat, 27 Feb 2010 19:37:50 -0800, staticd wrote: >> >Amusing how long those Python toes can be. In several replies I have >> >noticed (often clueless) opinions on Perl. When do people learn that a >> >language is just a tool to do a job? >> >> When do people learn that language makes a difference? ?I used to be a >> Perl programmer; these days, you'd have to triple my not-small salary >> to get me to even think about programming in Perl. > > dude, you nailed it. many times, if not _always_, the correct output is > important. the method used to produce the output is irrelevant. Oh really? Then by that logic, you would consider that these two functions are both equally good. Forget readability, forget maintainability, forget efficiency, we have no reason for preferring one over the other since the method is irrelevant. def greet1(name): """Print 'Hello ' for any name.""" print "Hello", name def greet2(name): """Print 'Hello ' for any name.""" count = 0 for i in range(0, ("Hello", name).__len__(), 1): word = ("Hello", name).__getitem__(i) for i in range(0, word[:].__len__(), 1): c = word.__getitem__(i) import sys import string empty = '' maketrans = getattr.__call__(string, 'maketrans') chars = maketrans.__call__(empty, empty) stdout = getattr.__call__(sys, 'stdout') write = getattr.__call__(stdout, 'write') write.__call__(c) count = count.__add__(1) import operator eq = getattr.__call__(operator, 'eq') ne = getattr.__call__(operator, 'ne') if eq.__call__(count, 2): pass elif not ne.__call__(count, 2): continue write.__call__(chr.__call__(32)) write.__call__(chr.__call__(10)) return None There ought to be some kind of competition for the least efficient solution to programming problems-ly y'rs, -- Steven From gallium.arsenide at gmail.com Sun Feb 28 03:52:14 2010 From: gallium.arsenide at gmail.com (John Yeung) Date: Sun, 28 Feb 2010 00:52:14 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <6b04c31f-fdaa-4f63-99fb-5bebe7ae4b0e@z11g2000yqz.googlegroups.com> <2feb50ee-515f-48d9-99c0-772327597217@b7g2000yqd.googlegroups.com> Message-ID: <98403c0c-f545-4b96-bb1c-08e5f2bf5f3a@f8g2000yqn.googlegroups.com> On Feb 28, 12:51?am, gujax wrote: > I agree with you. I have a CD of Xubuntu. I tried > booting up with the CD and was impressed. I noticed > few problems with screen resolution, window size etc. Though it may be worth working out any niggling problems to switch to Linux, I don't think you should feel pressured to switch if you are comfortable with Win ME on that particular machine. > And no, I am not at all attached to Win, though wouldn't > say the same for my computer. It sounds like you could have switched to Linux and resolved any configuration problems in the two years you've been trying to install Python. ;) But that said, I have used older versions of Python without any trouble on Win ME. In fact, I still have a Win ME machine running 2.5.2. According to the docs, you have to have Microsoft Installer 2.0 (freely downloadable from Microsoft if necessary) to use the 2.5 MSI distribution: http://www.python.org/download/releases/2.5.4/ If for whatever reason you can't or don't want to do this, 2.3 still has an EXE distribution: http://www.python.org/download/releases/2.3.5/ John From brown_emu at yahoo.com Sun Feb 28 05:00:45 2010 From: brown_emu at yahoo.com (Stephen Tucker) Date: Sun, 28 Feb 2010 02:00:45 -0800 (PST) Subject: getting rpy2 from repository Message-ID: <655447.28185.qm@web39705.mail.mud.yahoo.com> Hi all, I have Enthought Python 4.3 installed on my OS X 10.5. When I do $ easy_install rpy2 Searching for rpy2 No matching release version found. Searching for latest development version. Reading http://www.enthought.com/repo/epd/eggs/MacOSX/10.4_x86/ Please enter credentials to access this repository: User Name: Is there a way to point to the original (non-Enthought) repository, or is there a better way? Thanks very much in advance! Stephen From stefan_ml at behnel.de Sun Feb 28 06:05:12 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 12:05:12 +0100 Subject: Python dos2unix one liner In-Reply-To: <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: Steven D'Aprano, 28.02.2010 09:48: > There ought to be some kind of competition for the least efficient > solution to programming problems That wouldn't be very interesting. You could just write a code generator that spits out tons of garbage code including a line that solves the problem, and then let it execute the code afterwards. That beast would always win. Stefan From dontsendleospam at gmail.com Sun Feb 28 06:45:38 2010 From: dontsendleospam at gmail.com (dontspamleo) Date: Sun, 28 Feb 2010 03:45:38 -0800 (PST) Subject: scope of generators, class variables, resulting in global na References: <3994d693e577792c3cda4ea72bbf8b96@dizum.com> <2e126011-1b58-4277-a2c6-7839803ba693@u15g2000prd.googlegroups.com> <4b89d880$0$27844$c3e8da3@news.astraweb.com> Message-ID: <6cc72563-2720-4fa9-a11a-6fe9f0b7e197@c37g2000prb.googlegroups.com> > > ...and really means this... > > class C: > > ? x = 1 > > ? def f(self,y): return T.x + y > > I don't understand what T is. Did you mean C? Yes, I meant C. Thanks. > > If so, you are wrong. self.x is not the same as .x due to > inheritance rules. Consider one example: > Thanks for the nice example. Sorry for my loose language. By "really means", what I really meant was that the most appropriate construct should be the one referring to the class variable explicitly. I would consider it inelegant (at least) to use an instance variable with the same name as a class variable. > > > 1. Has this been discussed before? > > Yes. > > > 1. What would this suggestion break? > > Nearly all existing code using classes, which is nearly everything. Is it that common to have code containing a class variable with the same name as a global variable? Are there other use cases that would break? > > > 2. What are the advantages of making the scope of class variables > > different? Maybe is it just a historical trait? > > See the discussion in the PEP for introducing nested scopes in the first > place: > > http://www.python.org/dev/peps/pep-0227/ > Thanks. That is really useful. I just read the PEP. I find this paragraph very helpful: "An alternative would have been to allow name binding in class scope to behave exactly like name binding in function scope. This rule would allow class attributes to be referenced either via attribute reference or simple name. This option was ruled out because it would have been inconsistent with all other forms of class and instance attribute access, which always use attribute references. Code that used simple names would have been obscure." The point about all other access use cases requiring attribute references is a really good one. If a language requires self.f() to access the member f of class C, which happens to be a function, then self.x or C.x should also be required to access attribute x. And no one would be crazy enough to ask to have that fixed. @Steven: Are there other snippets from the PEP you were pointing to specifically? Cheers, Leo. From martin.hellwig at dcuktec.org Sun Feb 28 06:51:31 2010 From: martin.hellwig at dcuktec.org (Martin P. Hellwig) Date: Sun, 28 Feb 2010 11:51:31 +0000 Subject: Python dos2unix one liner In-Reply-To: References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: On 02/28/10 11:05, Stefan Behnel wrote: > Steven D'Aprano, 28.02.2010 09:48: >> There ought to be some kind of competition for the least efficient >> solution to programming problems > > That wouldn't be very interesting. You could just write a code generator > that spits out tons of garbage code including a line that solves the > problem, and then let it execute the code afterwards. That beast would > always win. > > Stefan > Well that would be an obvious rule that garbage code that does not contribute to the end result (ie can be taken out without affecting the end result) would not be allowed. Enforcing the rule is another beast though, but I would leave that to the competition. Though the idea of a code generator is solid, but instead of generating garbage, produces a virtual machine that implements a generator that produces a virtual machine, etc. etc. -- mph From roland.em0001 at googlemail.com Sun Feb 28 07:01:03 2010 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Sun, 28 Feb 2010 14:01:03 +0200 Subject: stripping fields from xml file into a csv In-Reply-To: References: Message-ID: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> Hello, 2010/2/28 Stefan Behnel > Hal Styli, 27.02.2010 21:50: > > I have a sed solution to the problems below but would like to rewrite > > in python... > > Note that sed (or any other line based or text based tool) is not a > sensible way to handle XML. If you want to read XML, use an XML parser. > They are designed to do exactly what you want in a standard compliant way, > and they can deal with all sorts of XML formatting and encoding, for > example. > > > > I need to strip out some data from a quirky xml file into a csv: > > > > from something like this > > > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > > < .... cust="harry" .... product="bread" ... quantity="1" ...> > > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > As others have noted, this doesn't tell much about your XML. A more > complete example would be helpful. > > > > to this > > > > dick,eggs,12 > > tom,milk,2 > > harry,bread,1 > > tom,eggs,6 > > dick,eggs,6 > > > > I am new to python and xml and it would be great to see some slick > > ways of achieving the above by using python's XML capabilities to > > parse the original file or python's regex to achive what I did using > > sed. > > another solution in this case could be to use an XSLT stylesheet. That way the input processing is defined in an XSLT stylesheet. The stylesheet is test.xsl and the insput data test.xml. The following Python code the applies the stylesheet on the input data and puts the output into foo. Python code: #!/usr/bin/python import sys import libxml2 import libxslt styledoc = libxml2.parseFile("test.xsl") style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseFile("test.xml") result = style.applyStylesheet(doc, None) style.saveResultToFilename("foo", result, 0) BR, Roland *Example run in Linux:* roland at komputer:~/Desktop/XML/XSLT$ ./xslt_test.py roland at komputer:~/Desktop/XML/XSLT$ cat foo john,eggs,12 cindy,bread,1 larry,tea bags,100 john,butter,1 derek,chicken,2 derek,milk,2 * The test.xsl stylesheet:* , , -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_ml at behnel.de Sun Feb 28 07:15:09 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 13:15:09 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> References: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> Message-ID: Roland Mueller, 28.02.2010 13:01: > The stylesheet is test.xsl and the insput data test.xml. The following > Python code the applies the stylesheet on the input data and puts the output > into foo. > > Python code: > #!/usr/bin/python > import sys > import libxml2 > import libxslt > > styledoc = libxml2.parseFile("test.xsl") > style = libxslt.parseStylesheetDoc(styledoc) > doc = libxml2.parseFile("test.xml") > result = style.applyStylesheet(doc, None) > style.saveResultToFilename("foo", result, 0) > > BR, > Roland > > *Example run in Linux:* > roland at komputer:~/Desktop/XML/XSLT$ ./xslt_test.py Note that the shorthand for the above is $ xsltproc test.xsl test.xml > foo Stefan From spamfresser at ch3ka.de Sun Feb 28 07:38:14 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 28 Feb 2010 13:38:14 +0100 Subject: Method / Functions - What are the differences? Message-ID: Out of curiosity I tried this and it actually worked as expected: >>> class T(object): x=[] foo=x.append def f(self): return self.x >>> t=T() >>> t.f() [] >>> T.foo(1) >>> t.f() [1] >>> At first I thought "hehe, always fun to play around with python. Might be useful sometimes" - but then It really confused me what I did. I mean: f is what we call a method, right? But was is foo? It is not a method and not a classmethod as it accepts no self and no cls. So that leaves staticmethod? OK, fair, as x is "static" here anyway this reflects what it does. But then consider this: >>> class T(object): def __init__(self): self.x=[] self.foo=self.x.append def f(self): return self.x >>> y=T() >>> y.x [] >>> y.foo(1) >>> y.x [1] >>> a=T() >>> a.x [] >>> a.foo(2) >>> a.x [2] >>> Note that all I did was moving the list and foo into the instance. Still no self and no cls, but also no static behaviour any more. So is foo just nothing of the above and really only a class/instance attribute which happens to be callable? Perhaps this all does not matter, but now I am really confused about the terminology. So: what makes a method a method? And of what type? Regards, Michael From albert at spenarnc.xs4all.nl Sun Feb 28 07:43:51 2010 From: albert at spenarnc.xs4all.nl (Albert van der Horst) Date: 28 Feb 2010 12:43:51 GMT Subject: problem with floats and calculations References: Message-ID: In article , Dennis Lee Bieber wrote: >On Sun, 14 Feb 2010 10:33:54 +0100, Karsten Goen > declaimed the following in >gmane.comp.python.general: > >> Maybe anyone can help me with this problem, I don't want to generate for >> every possible user input a single formula. And also it should be possible >> for a computer, my calculator at home does the same and is much smaller and >> slower. >> > Most ALL calculators that I've encountered use packed BCD internally >for numeric data. That is -- two decimal digits (0-9) and a few special >codes (mantissa sign, exponent sign, decimal point location, and >exponent start). A lot of them (though strangely not HP) included "guard >digits" -- they would display, say, 8 significant digits for results, >but kept 10 digits internally, so that rounding errors wouldn't >accumulate as rapidly. M$ Excel/Access/VisualBasic "money" data type What is displayed has no influence on rounding errors. Calculator vendors prevent puzzlement by non-knowledgeable users by having guard digits. HP apparently deals with professional users, so I think it not strange at all. >carries four decimal places, on the assumption that only two are >significant, and the last two are guards. > > Most ALL computers are using IEEE floating point (and the exceptions >are still a binary floating point, not a decimal representation). > > The practice, which /used to be/ taught, is that one does not >compare floating numbers for equality, but rather one compares the >difference between floating numbers to be less than some epsilon value; >epsilon chosen depending upon the significance needed. > > Rather than comparing > > a = b > >one uses > > abs(a - b) < epsilon > > Since Decimal() also has "infinite" series values (1.0/3.0), an >epsilon comparison may also be called for. Not may be. >-- > Wulfraed Dennis Lee Bieber KD6MOG Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst From roland.em0001 at googlemail.com Sun Feb 28 08:21:26 2010 From: roland.em0001 at googlemail.com (Roland Mueller) Date: Sun, 28 Feb 2010 15:21:26 +0200 Subject: stripping fields from xml file into a csv In-Reply-To: References: <42dbeab41002280401t2916240ak1d4bba1bcf51a5c1@mail.gmail.com> Message-ID: <42dbeab41002280521s73b01689x82f8f73f60da5587@mail.gmail.com> 2010/2/28 Stefan Behnel > Roland Mueller, 28.02.2010 13:01: > > The stylesheet is test.xsl and the insput data test.xml. The following > > Python code the applies the stylesheet on the input data and puts the > output > > into foo. > > > > Python code: > > #!/usr/bin/python > > import sys > > import libxml2 > > import libxslt > > > > styledoc = libxml2.parseFile("test.xsl") > > style = libxslt.parseStylesheetDoc(styledoc) > > doc = libxml2.parseFile("test.xml") > > result = style.applyStylesheet(doc, None) > > style.saveResultToFilename("foo", result, 0) > > > > BR, > > Roland > > > > *Example run in Linux:* > > roland at komputer:~/Desktop/XML/XSLT$ ./xslt_test.py > > Note that the shorthand for the above is > > $ xsltproc test.xsl test.xml > foo > > yes, that's true, and probably the best way to use XML stylesheets in Linux. However, this is a Python ML, and so I was sending the Python example. The original poster does not necessarily use Linux, and I do not know about Windos tools in that regard. BR, Roland > Stefan > > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at castleamber.com Sun Feb 28 08:48:40 2010 From: john at castleamber.com (John Bokma) Date: Sun, 28 Feb 2010 07:48:40 -0600 Subject: Python dos2unix one liner References: <4b89059e$0$27844$c3e8da3@news.astraweb.com> <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <4b89cee0$0$27844$c3e8da3@news.astraweb.com> Message-ID: <87pr3pa2tj.fsf@castleamber.com> Steven D'Aprano writes: > On Sat, 27 Feb 2010 11:27:04 -0600, John Bokma wrote: > >> When do people learn that a >> language is just a tool to do a job? > > When do people learn that there are different sorts of tools? A > professional wouldn't use a screwdriver when they need a hammer. [...] > Languages are not just nebulous interchangeable "tools", they're tools A hammer is just a tool to do a job. Doesn't mean one must or should use a hammer to paint a wall. > for a particular job with particular strengths and weaknesses, and > depending on what strengths you value and what weaknesses you dislike, > some tools simply are better than other tools for certain tasks. In short, we agree. -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development From alfps at start.no Sun Feb 28 09:08:49 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Feb 2010 15:08:49 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: Message-ID: * Michael Rudolf: > Out of curiosity I tried this and it actually worked as expected: > > >>> class T(object): > x=[] > foo=x.append > def f(self): > return self.x > > > >>> t=T() > >>> t.f() > [] > >>> T.foo(1) > >>> t.f() > [1] > >>> > > At first I thought "hehe, always fun to play around with python. Might > be useful sometimes" - but then It really confused me what I did. I > mean: f is what we call a method, right? But was is foo? foo is (refers to) an object that supports call notation and that forwards calls somewhere else, in this case to append on a list. You might call it (descriptive) a call forwarder, or (C# or general terminology) a delegate, or (Python 2.x) a bound method. >>> "Hello".upper >>> f = "Hello".upper >>> f >>> f() 'HELLO' >>> >>> >>> >>> f.__self__ 'Hello' >>> f.__call__ >>> print( f.__doc__ ) S.upper() -> str Return a copy of S converted to uppercase. >>> _ A common use for delegates is as command handlers in a GUI application, and in general for event notifications. Cheers & hth., - Alf From rtw at rtw.me.uk Sun Feb 28 09:24:06 2010 From: rtw at rtw.me.uk (Rob Williscroft) Date: Sun, 28 Feb 2010 08:24:06 -0600 Subject: Method / Functions - What are the differences? References: Message-ID: Michael Rudolf wrote in news:hmdo3m$287$1 at news.urz.uni-heidelberg.de in comp.lang.python: > Note that all I did was moving the list and foo into the instance. Still > no self and no cls, but also no static behaviour any more. Yes in the first case foo was an attribute of the class, and in the second an attribute of aon instance of the class. In both cases it was a bound method, something similar too: lambda item : T.x.append( item ) From fordhaivat at gmail.com Sun Feb 28 09:28:07 2010 From: fordhaivat at gmail.com (Someone Something) Date: Sun, 28 Feb 2010 09:28:07 -0500 Subject: cpan for python? Message-ID: Is there something like cpan for python? I like python's syntax, but I use perl because of cpan and the tremendous modules that it has. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ssteinerx at gmail.com Sun Feb 28 09:31:56 2010 From: ssteinerx at gmail.com (ssteinerX@gmail.com) Date: Sun, 28 Feb 2010 09:31:56 -0500 Subject: cpan for python? In-Reply-To: References: Message-ID: <383DBB77-A002-4C7D-9DB4-1371AF693070@gmail.com> On Feb 28, 2010, at 9:28 AM, Someone Something wrote: > Is there something like cpan for python? I like python's syntax, but I use perl because of cpan and the tremendous modules that it has. -- Please search the mailing list archives. This subject has been discussed to absolute death. Draw your own conclusions about what is currently and may, in the future, be available. S From vicente.soler at gmail.com Sun Feb 28 09:42:00 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 28 Feb 2010 06:42:00 -0800 (PST) Subject: Printing the arguments of an attribute in a class Message-ID: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> I have a class that is a wrapper: class wrapper: def __init__(self, object): self.wrapped = object def __getattr__(self, attrname): print 'Trace: ', attrname #print arguments to attrname, how? return getattr(self.wrapped, attrname) I can run it this way: >>> x = wrapper([1,2,3]) >>> x.append(4) Trace: append >>> x.wrapped [1, 2, 3, 4] I am able to capture the attribute name to x (that is, append). However, I do not know how to capture and print all of its arguments (in this case number 4). How should I proceed? Thank you From alfps at start.no Sun Feb 28 10:00:19 2010 From: alfps at start.no (Alf P. Steinbach) Date: Sun, 28 Feb 2010 16:00:19 +0100 Subject: Printing the arguments of an attribute in a class In-Reply-To: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> References: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> Message-ID: * vsoler: > I have a class that is a wrapper: > > class wrapper: > def __init__(self, object): > self.wrapped = object > def __getattr__(self, attrname): > print 'Trace: ', attrname > #print arguments to attrname, how? > return getattr(self.wrapped, attrname) > > I can run it this way: > >>>> x = wrapper([1,2,3]) >>>> x.append(4) > Trace: append >>>> x.wrapped > [1, 2, 3, 4] > > I am able to capture the attribute name to x (that is, append). > However, I do not know how to capture and print all of its arguments > (in this case number 4). > > How should I proceed? If your goal is just learning then in your __getattr__ you might return a wrapper for the attribute instead of the attribute itself. Equip the wrapper with a __call__ method if it is a method. And equip it with other special methods as appropriate. I can imagine that that approach will lead to some practical problems, but it may be great for learning. If your goal is tracing, then I suggest looking at the "trace" module. If your goal is something else purely practical, like intercepting method calls to do arbitrary things (logging, marshaling, whatever) then I suspect that it might getspretty complicated, hairy. For specific method calls you might just use subclassing, but for doing this in general, parameterized, you'd need to about the same kinds of things as the trace module does. So I guess then one idea might be to look at the source code of that module. But if that's what you intend to do, then best check first if there is an existing solution. ParcPlace did this thing for a number of languages and introduced a special term for it, I can't recall but something like "cross-whatever mumbo jumbo concerns" plus one single catchy name. There might be an existing Python implementation. Cheers & hth., - Alf From vicente.soler at gmail.com Sun Feb 28 10:31:30 2010 From: vicente.soler at gmail.com (vsoler) Date: Sun, 28 Feb 2010 07:31:30 -0800 (PST) Subject: Printing the arguments of an attribute in a class References: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> Message-ID: On Feb 28, 4:00?pm, "Alf P. Steinbach" wrote: > * vsoler: > > > > > I have a class that is a wrapper: > > > class wrapper: > > ? ? def __init__(self, object): > > ? ? ? ? self.wrapped = object > > ? ? def __getattr__(self, attrname): > > ? ? ? ? print 'Trace: ', attrname > > ? ? ? ? #print arguments to attrname, how? > > ? ? ? ? return getattr(self.wrapped, attrname) > > > I can run it this way: > > >>>> x = wrapper([1,2,3]) > >>>> x.append(4) > > Trace: ?append > >>>> x.wrapped > > [1, 2, 3, 4] > > > I am able to capture the attribute name to x (that is, append). > > However, I do not know how to capture and print all of its arguments > > (in this case number 4). > > > How should I proceed? > > If your goal is just learning then in your __getattr__ you might return a > wrapper for the attribute instead of the attribute itself. Equip the wrapper > with a __call__ method if it is a method. And equip it with other special > methods as appropriate. > > I can imagine that that approach will lead to some practical problems, but it > may be great for learning. > > If your goal is tracing, then I suggest looking at the "trace" module. > > If your goal is something else purely practical, like intercepting method calls > to do arbitrary things (logging, marshaling, whatever) then I suspect that it > might getspretty complicated, hairy. For specific method calls you might just > use subclassing, but for doing this in general, parameterized, you'd need to > about the same kinds of things as the trace module does. So I guess then one > idea might be to look at the source code of that module. > > But if that's what you intend to do, then best check first if there is an > existing solution. ParcPlace did this thing for a number of languages and > introduced a special term for it, I can't recall but something like > "cross-whatever mumbo jumbo concerns" plus one single catchy name. There might > be an existing Python implementation. > > Cheers & hth., > > - Alf Alf, My goal is just learning. In the code provided in the post I just can't think of a method to "see", "capture" or "use" the parameters. I am going to study the __call__ method and see if I can figure out how I can capture the parameters. Thank you Alf From fetchinson at googlemail.com Sun Feb 28 11:27:22 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 28 Feb 2010 17:27:22 +0100 Subject: cpan for python? In-Reply-To: References: Message-ID: > Is there something like cpan for python? I like python's syntax, but I use > perl because of cpan and the tremendous modules that it has. It's called PyPI or Cheese Shop: http://pypi.python.org/pypi Is it only me or others also mentally read C-SPAN when somebody writes CPAN? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From spamfresser at ch3ka.de Sun Feb 28 11:39:03 2010 From: spamfresser at ch3ka.de (Michael Rudolf) Date: Sun, 28 Feb 2010 17:39:03 +0100 Subject: Method / Functions - What are the differences? In-Reply-To: References: Message-ID: Am 28.02.2010 15:08, schrieb Alf P. Steinbach: > >>> "Hello".upper > > >>> f = "Hello".upper > >>> f > > >>> f() > 'HELLO' > >>> > >>> > >>> > >>> f.__self__ > 'Hello' Holy hand grenade. You have no Idea how enlightened I feel right now :D Thank you, "bound method" was the term I forgot and your example... ...totally revealed the internals behind this to me. Especially the last line I quoted. I mean, I always knew *that* this works, but I never knew *why*. Regards, Michael From wuhrrr at gmail.com Sun Feb 28 11:41:21 2010 From: wuhrrr at gmail.com (Hai Vu) Date: Sun, 28 Feb 2010 08:41:21 -0800 (PST) Subject: stripping fields from xml file into a csv References: Message-ID: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> On Feb 28, 12:05?am, Stefan Behnel wrote: > Hal Styli, 27.02.2010 21:50: > > > I have a sed solution to the problems below but would like to rewrite > > in python... > > Note that sed (or any other line based or text based tool) is not a > sensible way to handle XML. If you want to read XML, use an XML parser. > They are designed to do exactly what you want in a standard compliant way, > and they can deal with all sorts of XML formatting and encoding, for example. > > > I need to strip out some data from a quirky xml file into a csv: > > > from something like this > > > < ..... cust="dick" .... product="eggs" ... quantity="12" .... > > > < .... cust="tom" .... product="milk" ... quantity="2" ...> > > < .... cust="harry" .... product="bread" ... quantity="1" ...> > > < .... cust="tom" .... product="eggs" ... quantity="6" ...> > > < ..... cust="dick" .... product="eggs" ... quantity="6" .... > > > As others have noted, this doesn't tell much about your XML. A more > complete example would be helpful. > > > to this > > > dick,eggs,12 > > tom,milk,2 > > harry,bread,1 > > tom,eggs,6 > > dick,eggs,6 > > > I am new to python and xml and it would be great to see some slick > > ways of achieving the above by using python's XML capabilities to > > parse the original file or python's regex to achive what I did using > > sed. > > It's funny how often people still think that SAX is a good way to solve XML > problems. Here's an untested solution that uses xml.etree.ElementTree: > > ? ? from xml.etree import ElementTree as ET > > ? ? csv_field_order = ['cust', 'product', 'quantity'] > > ? ? clean_up_used_elements = None > ? ? for event, element in ET.iterparse("thefile.xml", events=['start']): > ? ? ? ? # you may want to select a specific element.tag here > > ? ? ? ? # format and print the CSV line to the standard output > ? ? ? ? print(','.join(element.attrib.get(title, '') > ? ? ? ? ? ? ? ? ? ? ? ?for title in csv_field_order)) > > ? ? ? ? # safe some memory (in case the XML file is very large) > ? ? ? ? if clean_up_used_elements is None: > ? ? ? ? ? ? # this assigns the clear() method of the root (first) element > ? ? ? ? ? ? clean_up_used_elements = element.clear > ? ? ? ? clean_up_used_elements() > > You can strip everything dealing with 'clean_up_used_elements' (basically > the last section) if your XML file is small enough to fit into memory (a > couple of MB is usually fine). > > Stefan This solution is so beautiful and elegant. Thank you. Now I am off to learn ElementTree. By the way, Stefan, I am using Python 2.6. Do you know the differences between ElementTree and cElementTree? From mwilson at the-wire.com Sun Feb 28 11:41:29 2010 From: mwilson at the-wire.com (Mel) Date: Sun, 28 Feb 2010 11:41:29 -0500 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <20100226173907.5567609f@geekmail.INVALID> <7uu1ooFiipU1@mid.individual.net> Message-ID: Gregory Ewing wrote: > Mel wrote: > >> You could think of it as a not bad use of the design principle "Clear The >> Simple Stuff Out Of The Way First". Destinations are commonly a lot >> simpler than sources Calculations for immediate values could be just about anything. Mel. From victor.stinner at haypocalc.com Sun Feb 28 11:43:07 2010 From: victor.stinner at haypocalc.com (Victor Stinner) Date: Sun, 28 Feb 2010 17:43:07 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: <201002281743.07452.victor.stinner@haypocalc.com> Le samedi 27 f?vrier 2010 18:37:22, Daniel Fetchinson a ?crit : > It's google's hosting solution called app engine, for python web > applications: http://code.google.com/appengine/docs/python/gettingstarted/ > > I guess they also have some kind of a sandbox if they let people run > python on their machines, I'm not sure if it's open source though. Yes, Google AppEngine has its Python sandbox and the source code is available online. I don't know the license. I found 7 vulnerabilities in 1 hour :-) I contacted Google security team. To answer to your question "How is [AppEngine] different from your project?": * pysanbox has an import whitelist, whereas AppEngine has an import blacklist (subprocess, socket, ... builtin modules are replaced by safe versions). Import a Python module written in C is forbidden. * Import a module in AppEngine imports all symbols, whereas pysandbox uses also a symbol whitelist. * AppEngine doesn't have proxies, all objects are modifiable (eg. sys.path) There are other differences, but I prefer to wait for the answer from Google before telling you more :) AppEngine sandbox and pysandbox projects are very close: most protections are based on blacklists, whereas RestrictedPython is only based on whitelists. -- Victor Stinner http://www.haypocalc.com/ From arnodel at googlemail.com Sun Feb 28 12:51:44 2010 From: arnodel at googlemail.com (Arnaud Delobelle) Date: Sun, 28 Feb 2010 17:51:44 +0000 Subject: Printing the arguments of an attribute in a class References: <1617d47d-b071-4d7f-94aa-b429c2993092@g11g2000yqe.googlegroups.com> Message-ID: vsoler writes: > I have a class that is a wrapper: > > class wrapper: > def __init__(self, object): > self.wrapped = object > def __getattr__(self, attrname): > print 'Trace: ', attrname > #print arguments to attrname, how? > return getattr(self.wrapped, attrname) > > I can run it this way: > >>>> x = wrapper([1,2,3]) >>>> x.append(4) > Trace: append >>>> x.wrapped > [1, 2, 3, 4] > > I am able to capture the attribute name to x (that is, append). > However, I do not know how to capture and print all of its arguments > (in this case number 4). > > How should I proceed? > > Thank you You could do something like this: class wrapper: def __init__(self, object): self.wrapped = object def __getattr__(self, attrname): print '** get attribute: ', self.wrapped, attrname return wrapper(getattr(self.wrapped, attrname)) def __call__(self, *args, **kwargs): print '** call with args: ', self.wrapped, args, kwargs return wrapper(self.wrapped(*args, **kwargs)) x = wrapper([1,2,3]) x.append(4) I haven't thought about it too much though. -- Arnaud From aahz at pythoncraft.com Sun Feb 28 12:55:38 2010 From: aahz at pythoncraft.com (Aahz) Date: 28 Feb 2010 09:55:38 -0800 Subject: Challenge: escape from the pysandbox References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: In article , Daniel Fetchinson wrote: > >I guess they also have some kind of a sandbox if they let people run >python on their machines, I'm not sure if it's open source though. Thing is, I'm sure that Google uses a critical backstop to any Python-based sandbox: something like a chroot jail. The Python sandbox is mostly there to inform you about what you can and can't do; the real security is provided by the OS. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From misceverything at gmail.com Sun Feb 28 13:35:23 2010 From: misceverything at gmail.com (T) Date: Sun, 28 Feb 2010 10:35:23 -0800 (PST) Subject: Py2exe - Bad File Descriptor Message-ID: <0c04902d-03e8-4b0e-8dd3-3bbdf7ea09b6@z11g2000yqz.googlegroups.com> I have a Python script, which is a Windows Service, that I created an EXE of via py2exe. As part of the program, it calls some external binaries, one of which restarts the computer. When I'm logged in, this works fine. However, if I log out, the service stops and logs the following error in the Event Log: :(9, 'Bad file descriptor') Anyone have an idea what could be causing this? From fabfake at fake.org Sun Feb 28 14:10:55 2010 From: fabfake at fake.org (Fabiano) Date: Sun, 28 Feb 2010 20:10:55 +0100 Subject: Updates about Tk In-Reply-To: References: <4b88d215$0$1105$4fafbaef@reader4.news.tin.it> <6adc$4b895233$4275d90a$6509@FUSE.NET> Message-ID: <4b8abf8e$0$1115$4fafbaef@reader4.news.tin.it> rantingrick ha scritto: > On Feb 27, 11:11 am, Kevin Walzer wrote: > > (...snip...) > >> Kevin Walzer >> Code by Kevinhttp://www.codebykevin.com > > Great post Kevin! The only thing i would like to add are my two > favorite references for learning Tkinter. They are not geared around > the new ttk stuff, but still 95% relevant to any Tkinter-ing > > http://effbot.org/tkinterbook/ > http://infohost.nmt.edu/tcc/help/pubs/tkinter/ > > Thanks @All you guys for the explanations and links! Regards From stefan_ml at behnel.de Sun Feb 28 14:20:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 28 Feb 2010 20:20:21 +0100 Subject: stripping fields from xml file into a csv In-Reply-To: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> References: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> Message-ID: Hai Vu, 28.02.2010 17:41: > By the way, Stefan, I am using Python 2.6. Do you know the differences > between ElementTree and cElementTree? Use cElementTree, it's implemented in C and a lot faster and more memory friendly. http://effbot.org/zone/celementtree.htm#benchmarks http://codespeak.net/lxml/performance.html Stefan From aahz at pythoncraft.com Sun Feb 28 14:44:44 2010 From: aahz at pythoncraft.com (Aahz) Date: 28 Feb 2010 11:44:44 -0800 Subject: Upgrading Py2exe App References: <67c4b4ee-083e-4a53-b28f-0fc384303a10@b10g2000vbh.googlegroups.com> Message-ID: In article , Ryan Kelly wrote: >On Wed, 2010-02-24 at 15:05 -0800, Aahz wrote: >> In article , >> Ryan Kelly wrote: >>> >>>Yes. The idea of having a "bootstrapping exe" is that actual >>>application code can be swapped out without having to overwrite the >>>executable file. As long as you don't change python versions, this >>>allows updates to be safe against system crashes, even on platforms >>>without atomic file replacement. >>> >>>So the frozen app does this in a background thread: >>> >>> Esky(sys.executable,"http://my.updates.com").auto_update() >>> >>>And it hits the given url, grabs the latest zipfile, downloads and >>>unpacks and atomically places it into the application directory. Et >>>viola, your app is at the latest version. >> >> How does this work with a running app? What if the app is a service? > >The changes will only take effect the next time the app is started - >currently there's no support for "hot upgrading" a running app. >From my POV, hot upgrading is less important than solid restart capabilities, particularly for services. Performing tasks like modifying the DB schema is also important (not the actual capability, but hooks for it). E.g., the next time the app starts, it should know that it's been upgraded. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From g.bogle at auckland.no.spam.ac.nz Sun Feb 28 16:15:29 2010 From: g.bogle at auckland.no.spam.ac.nz (Gib Bogle) Date: Mon, 01 Mar 2010 10:15:29 +1300 Subject: PyQt4.7 and PyQwt5.2.0 Message-ID: I installed the latest PyQt (4.7-1), then PyQwt 5.2.0, which was built with PyQt4.5.4. This line import PyQt4.Qwt5 as Qwt fails to load the DLL. Could this be the result of not using PyQt4 4.5.4? From missive at hotmail.com Sun Feb 28 16:17:30 2010 From: missive at hotmail.com (Lee Harr) Date: Mon, 1 Mar 2010 01:47:30 +0430 Subject: [ANNC] pynguin-0.1 (python-based 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 is the initial release, with many optimizations ??? and finer details yet to come. Please check it out ??? and let me know what you think. pynguin is tested with Python 2.6.4 and uses PyQt (4.6) ??? for its GUI elements. pynguin is released under GPLv3. Changes in pynguin-0.1: ??? - initial public release _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. https://signup.live.com/signup.aspx?id=60969 From misceverything at gmail.com Sun Feb 28 16:22:19 2010 From: misceverything at gmail.com (T) Date: Sun, 28 Feb 2010 13:22:19 -0800 (PST) Subject: Py2exe - Bad File Descriptor References: <0c04902d-03e8-4b0e-8dd3-3bbdf7ea09b6@z11g2000yqz.googlegroups.com> Message-ID: On Feb 28, 3:48?pm, Dennis Lee Bieber wrote: > On Sun, 28 Feb 2010 10:35:23 -0800 (PST), T > declaimed the following in gmane.comp.python.general: > > > I have a Python script, which is a Windows Service, that I created an > > EXE of via py2exe. ?As part of the program, it calls some external > > binaries, one of which restarts the computer. ?When I'm logged in, > > this works fine. ?However, if I log out, the service stops and logs > > the following error in the Event Log: > > > :(9, 'Bad file descriptor') > > > Anyone have an idea what could be causing this? > > ? ? ? ? Without code, one must play psychic... And I haven't dusted off the > Tarot cards, I Ching coins, and Crystal balls is some time (No, I don't > have a ouija board)... > > ? ? ? ? Could it be you have a mapped drive that gets disconnected when you > log off? > > ? ? ? ? Is the service being started as part of your login? > > ? ? ? ? Does it attempt to write to a console? > -- > ? ? ? ? Wulfraed ? ? ? ? Dennis Lee Bieber ? ? ? ? ? ? ? KD6MOG > ? ? ? ? wlfr... at ix.netcom.com ? ? ?HTTP://wlfraed.home.netcom.com/ Sorry for the lack of code - yes, it does try to write to the console. From what I'm finding, this error may be due to the fact that there is no "console" to write to when I'm logged off. However, I would like to be able to print to screen if I run the EXE in debug mode (i.e. "myservice.exe debug"). Do you know of any way around this? Also, I need to get the output generated from an external EXE - will subprocess.Popen cause problems if I use stdout=PIPE? Thanks for your help! From m.91ahesh at gmail.com Sun Feb 28 16:47:55 2010 From: m.91ahesh at gmail.com (ranga...............) Date: Sun, 28 Feb 2010 13:47:55 -0800 (PST) Subject: Earn Money Online without Investment Message-ID: <76315eb5-5e23-4267-9ff2-4ffe4332671b@b5g2000prd.googlegroups.com> Earn Money Online without Investment Now anyone can earn money online with out any investment by using some genuine websites. The detailed information of some of the genuine everseen good earnings website information are presented clealy for free at http://earnmoneyonline-without-investment.blogspot.com/2010/02/earn-money-with-e-mail-marketing-how-it.html Earn Money Online with out Inevstment Overview : | Home | | E-mail Marketing | | Home Job Opportunities | | Contact | | Disclaimer | | Sitemap | Earn Money By : | Reading E-mails | | Clicking Ads | | Chatting Friends | | Surfing Internet | | Filling Forms | | Taking Surveys | From aahz at pythoncraft.com Sun Feb 28 17:10:02 2010 From: aahz at pythoncraft.com (Aahz) Date: 28 Feb 2010 14:10:02 -0800 Subject: Docstrings considered too complicated References: <20100224212303.242222c6@geekmail.INVALID> <4b889e3d$0$27844$c3e8da3@news.astraweb.com> Message-ID: In article <4b889e3d$0$27844$c3e8da3 at news.astraweb.com>, Steven D'Aprano wrote: >On Fri, 26 Feb 2010 21:51:17 -0600, Tim Daneliuk wrote: >> >> The only possible exception to this I can think of is when there is some >> non-obvious side-effect (i.e. language and/or hardware is >> "misfeatured"): >> >> mov A,B ; Moving A into B also will also arm >> ; the nuclear warhead if the CPU is >> ; hotter than 110C > >I had an embedded device that did *just that*, but only on Tuesdays. Thus explaining why some people never can get the hang of Tuesdays. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of universal agreement, and whether they are precisely the optimal choices is much less important." --Henry Spencer From rjngrj2010 at gmail.com Sun Feb 28 17:23:41 2010 From: rjngrj2010 at gmail.com (gujax) Date: Sun, 28 Feb 2010 14:23:41 -0800 (PST) Subject: help with Python installation References: <8df3ec9b-6bde-43ff-b55b-570db39b4a7e@y17g2000yqd.googlegroups.com> <038b8f03-c0bc-4ca3-b4eb-73e01ce7f69f@z35g2000yqd.googlegroups.com> Message-ID: On Feb 27, 10:14?pm, Arnaud Delobelle wrote: > On 28 Feb, 01:48, gujax wrote: > > > Hi, > > I have been trying to install python on my Win ME system for over two > > years - gave up for a while and now I am back with a resolve to solve > > the problem. I tried all versions of python but having installation > > problems for all. Installation does not proceed and I get a message > > saying "dll required for installation could not be run". I do not even > > know what to do next. I also tried Activepython. It installs but when > > I try to open it from Start->Programs->ActivePython 2.6, I get an > > error window saying - upgrade windows. > > Is there no solution at all to installing python on WinME. I have > > checked registry several times online and have sought professional > > help but so far no success. > > Thanks, I will appreciate any help > > gujax > > The docs (*) say that Python 2.5 is still compatible with Windows 9X > and ME, but that support for these platform was dropped at 2.6. ?So > you should be able to install and run Python 2.5. > > (*)http://docs.python.org/using/windows.html#installing-python > > -- > Arnaud Hi, Yes indeed, Python 2.5 worked and so did numpy and scipy for this version. Thanks to all for your inputs. There are now issues with plotting - graph plotting using pylab does not work nor does the Tck- Tk, but for now I am satisfied. Hopefully I will plod my way through. I should have read the documentation properly to realize that Win ME is not supported for later versions, Thanks again Gujax From fetchinson at googlemail.com Sun Feb 28 17:40:59 2010 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Sun, 28 Feb 2010 23:40:59 +0100 Subject: Challenge: escape from the pysandbox In-Reply-To: References: <201002261329.33740.victor.stinner@haypocalc.com> <201002261604.57625.victor.stinner@haypocalc.com> Message-ID: >>I guess they also have some kind of a sandbox if they let people run >>python on their machines, I'm not sure if it's open source though. > > Thing is, I'm sure that Google uses a critical backstop to any > Python-based sandbox: something like a chroot jail. The Python sandbox > is mostly there to inform you about what you can and can't do; the real > security is provided by the OS. I see, makes perfect sense. This then raises the question whether it's important to have a 100% fool proof python sandbox without help from the OS, or this goal is not only too ambitious but also not really a useful one. One aspect might be that one might want to have a platform independent way of sandboxing, perhaps. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From candide at free.invalid Sun Feb 28 17:46:22 2010 From: candide at free.invalid (candide) Date: Sun, 28 Feb 2010 23:46:22 +0100 Subject: Quoting quotes In-Reply-To: <4b87be91$0$29882$426a74cc@news.free.fr> References: <4b87be91$0$29882$426a74cc@news.free.fr> Message-ID: <4b8af23e$0$7066$426a74cc@news.free.fr> OK, now I see the point. I was mistaken because I was supposing that every quote strictly _inside_ the string have to match another quote od the same type. Thanks to all for yours responses. From debacle at debian.org Sun Feb 28 17:52:27 2010 From: debacle at debian.org (W. Martin Borgert) Date: Sun, 28 Feb 2010 23:52:27 +0100 Subject: Use eval() safely? In-Reply-To: <7umhcaF9rkU1@mid.individual.net> Message-ID: <20100228225227.GA3200@beron.tangosoft.com> Gregory Ewing wrote: > I posted a demonstration of this earlier in this thread. As you wrote, your example does not work when using eval() like in my original post with second and third parameter to eval(): >>> import math >>> eval("[c for c in (0).__class__.__bases__[0].__subclasses__() if c.__name__ == 'file'][0]('/myfile', 'w')", { "__builtins__": None }, { "abs": abs, "sin": math.sin }) Traceback (most recent call last): File "", line 1, in File "", line 1, in IOError: file() constructor not accessible in restricted mode (Same result with Python 2.4, 2.5, and 2.6.) While I believe, that eval() is not save, I have yet to see an example for exploiting it. Leaving out the second and third parameter just proves, that one shouldn't omit them :~) Thanks in advance for any black hat example! P.S. Please Cc me, thanks. From steve at REMOVE-THIS-cybersource.com.au Sun Feb 28 17:57:47 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 22:57:47 GMT Subject: cpan for python? References: Message-ID: <4b8af4eb$0$27844$c3e8da3@news.astraweb.com> On Sun, 28 Feb 2010 17:27:22 +0100, Daniel Fetchinson wrote: > > Is it only me or others also mentally read C-SPAN when somebody writes > CPAN? No, it's not just you. This is the first time I've realised it wasn't C-SPAN. -- Steven From steve at REMOVE-THIS-cybersource.com.au Sun Feb 28 17:59:48 2010 From: steve at REMOVE-THIS-cybersource.com.au (Steven D'Aprano) Date: 28 Feb 2010 22:59:48 GMT Subject: Python dos2unix one liner References: <3B2EC15D-BCF0-48C2-A223-73E87CCAAFE7@rocteur.cc> <87mxyuzj13.fsf@castleamber.com> <2de573ff-8c31-4b2c-950b-df4e5a1bbab1@g11g2000yqe.googlegroups.com> <4b8a2dde$0$27844$c3e8da3@news.astraweb.com> Message-ID: <4b8af564$0$27844$c3e8da3@news.astraweb.com> On Sun, 28 Feb 2010 12:05:12 +0100, Stefan Behnel wrote: > Steven D'Aprano, 28.02.2010 09:48: >> There ought to be some kind of competition for the least efficient >> solution to programming problems > > That wouldn't be very interesting. You could just write a code generator > that spits out tons of garbage code including a line that solves the > problem, and then let it execute the code afterwards. That beast would > always win. Obfuscated code competitions could do the same: insert your simple, straight-forward, completely unobfuscated algorithm somewhere in the middle of 15 GB of garbage code. Who would even find it? But they don't, because human judges decide the winner, not some silly rule of "the most lines of code wins". In any case, I wasn't serious. It would be a bit of fun, if you like that sort of thing, and you might even learn a few things (I never knew that ints don't have an __eq__ method), but I can't see it taking off. I prefer to use my powers for inefficiency to be sarcastic to strangers on Usenet. -- Steven From sillyhat at yahoo.com Sun Feb 28 18:15:51 2010 From: sillyhat at yahoo.com (Hal Styli) Date: Sun, 28 Feb 2010 15:15:51 -0800 (PST) Subject: stripping fields from xml file into a csv References: <7431a354-b9cb-490b-8b8b-b8f73d9698a8@s36g2000prf.googlegroups.com> Message-ID: On 28 Feb, 19:20, Stefan Behnel wrote: > Hai Vu, 28.02.2010 17:41: > > > By the way, Stefan, I am using Python 2.6. Do you know the differences > > between ElementTree and cElementTree? > > Use cElementTree, it's implemented in C and a lot faster and more memory > friendly. > > http://effbot.org/zone/celementtree.htm#benchmarkshttp://codespeak.net/lxml/performance.html > > Stefan Thanks for the responses so far, most enlightening. Stefan, I was happy to see such concise code. Your python worked with only very minor modifications. Hai's test xml data *without* the first and last line is close enough to the data I am using: ... quirky. I get a large file given to me in this format. I believe it is created by something like: grep 'customer=' *.xml, where there are a large number of xml files. I had to edit the data to include the first and last lines, and , to get the python code to work. It's not an arduous task(!), but can you recommend a way to get it to work without manually editing the data? One other thing, what's the Roland Mueller post above about (I'm viewing htis in google groups)? What would the test.xsl file look like? Thanks again Hal. From candide at free.invalid Sun Feb 28 18:23:38 2010 From: candide at free.invalid (candide) Date: Mon, 01 Mar 2010 00:23:38 +0100 Subject: Starting Python from the terminal with no welcome message Message-ID: <4b8afafa$0$28635$426a74cc@news.free.fr> Hi, Does exist some option I could send to the python interpreter during an interactive session in order to avoid the printing of the introductory message just above the top prompt ? In my case, the welcome message is the following : Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. gdb has such an option (the so-called quiet option). Compare this : $ gdb GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i486-linux-gnu". (gdb) with that $ gdb -q (gdb) From blake at randomresources.com Sun Feb 28 18:27:32 2010 From: blake at randomresources.com (Blake B) Date: Sun, 28 Feb 2010 17:27:32 -0600 Subject: Multiple console windows for a single program? Message-ID: <56b204861002281527n738e7032p7024db6768b1a40d@mail.gmail.com> Hello, I'm wanting to write a program with multiple objects, each in a thread. Both will be doing output (with the print statement) almost constantly, so I'd like to be able to separate their outputs. What I want to do is have a separate window for each. Is my only option to make my own "console" windows using TK or something? Thanks in advance, Blake B -------------- next part -------------- An HTML attachment was scrubbed... URL: From agoretoy at gmail.com Sun Feb 28 18:42:51 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 28 Feb 2010 17:42:51 -0600 Subject: Starting Python from the terminal with no welcome message In-Reply-To: <4b8afafa$0$28635$426a74cc@news.free.fr> References: <4b8afafa$0$28635$426a74cc@news.free.fr> Message-ID: On Sun, Feb 28, 2010 at 5:23 PM, candide wrote: > Hi, > > Does exist some option I could send to the python interpreter during an > interactive session in order to avoid the printing of the introductory > message just above the top prompt ? > > In my case, the welcome message is the following : > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > > gdb has such an option (the so-called quiet option). > > > Compare this : > > $ gdb > GNU gdb 6.8-debian > Copyright (C) 2008 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later > > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. Type "show copying" > and "show warranty" for details. > This GDB was configured as "i486-linux-gnu". > (gdb) > > with that > > $ gdb -q > (gdb) > > > -- > http://mail.python.org/mailman/listinfo/python-list > good idea, could be very useful. I don't think I recall seeing that option in python. +1 -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfps at start.no Sun Feb 28 19:30:12 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 01:30:12 +0100 Subject: Sample code usable Tkinter listbox Message-ID: In case Someone Else(TM) may need this. This code is just how it currently looks, what I needed for my code, so it's not a full-fledged or even tested class. But it works. import tkinter as t import tkinter.simpledialog import tkinter.messagebox t.askstring = tkinter.simpledialog.askstring t.warningbox = tkinter.messagebox.showwarning class UsableListbox( t.Frame ): def __init__( self, parent_widget ): t.Frame.__init__( self, parent_widget ) scrollbar = t.Scrollbar( self, orient = "vertical" ) self.lb = t.Listbox( self, yscrollcommand = scrollbar.set ) scrollbar.config( command = self.lb.yview ) scrollbar.pack( side = "right", fill = "y" ) self.lb.pack( side = "left", fill = "both", expand = 1 ) def current_index( self ): indices = self.lb.curselection() assert( len( indices ) <= 1 ) # TODO: about multi-selection. return None if len( indices ) == 0 else int( indices[0] ) def current( self ): #return self.lb.get( "active" ) # Incorrect with mousing i = self.current_index() return "" if i is None else self.lb.get( i ) def append( self, item ): return self.lb.insert( "end", item ) def add_selection_event_handler( self, handler ): "An event handler takes one argument, a Tkinter Event" return self.lb.bind( "<>", handler ) Cheers, - Alf From agoretoy at gmail.com Sun Feb 28 19:36:57 2010 From: agoretoy at gmail.com (alex goretoy) Date: Sun, 28 Feb 2010 18:36:57 -0600 Subject: Multiple console windows for a single program? In-Reply-To: <56b204861002281527n738e7032p7024db6768b1a40d@mail.gmail.com> References: <56b204861002281527n738e7032p7024db6768b1a40d@mail.gmail.com> Message-ID: On Sun, Feb 28, 2010 at 5:27 PM, Blake B wrote: > Hello, > > I'm wanting to write a program with multiple objects, each in a thread. > Both will be doing output (with the print statement) almost constantly, so > I'd like to be able to separate their outputs. What I want to do is have a > separate window for each. Is my only option to make my own "console" windows > using TK or something? > > Thanks in advance, > Blake B > > -- > http://mail.python.org/mailman/listinfo/python-list > > you can also use python-vte -Alex Goretoy -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sun Feb 28 20:21:29 2010 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 28 Feb 2010 19:21:29 -0600 Subject: Starting Python from the terminal with no welcome message In-Reply-To: <4b8afafa$0$28635$426a74cc@news.free.fr> References: <4b8afafa$0$28635$426a74cc@news.free.fr> Message-ID: <4B8B1699.6090307@tim.thechases.com> candide wrote: > Does exist some option I could send to the python interpreter during an > interactive session in order to avoid the printing of the introductory > message just above the top prompt ? > > In my case, the welcome message is the following : > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. I asked a similar question a while back: http://www.opensubscriber.com/message/python-list at python.org/4611139.html (strangely, I couldn't find that in the mail.python.org archives via google) If you don't want to monkey with the prompts (like I did in that thread), you can just use bash$ python -ic "" to get a python shell without the banner. That said, it _would_ be a nice addition to have a "-q"uiet startup option that behaves like many other apps do. But with it being just a few extra characters on the command-line, I don't expect it will happen. -tkc From pmaupin at gmail.com Sun Feb 28 21:09:30 2010 From: pmaupin at gmail.com (Patrick Maupin) Date: Sun, 28 Feb 2010 20:09:30 -0600 Subject: Draft PEP on RSON configuration file format Message-ID: All: Finding .ini configuration files too limiting, JSON and XML to hard to manually edit, and YAML too complex to parse quickly, I have started work on a new configuration file parser. I call the new format RSON (for "Readable Serial Object Notation"), and it is designed to be a superset of JSON. I would love for it to be considered valuable enough to be a part of the standard library, but even if that does not come to pass, I would be very interested in feedback to help me polish the specification, and then possibly help for implementation and testing. The documentation is in rst PEP form, at: http://rson.googlecode.com/svn/trunk/doc/draftpep.txt Thanks and best regards, Pat From no.email at nospam.invalid Sun Feb 28 21:55:42 2010 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 28 Feb 2010 18:55:42 -0800 Subject: Draft PEP on RSON configuration file format References: Message-ID: <7xd3zobvip.fsf@ruckus.brouhaha.com> Patrick Maupin writes: > I have started work on a new configuration file parser.... > The documentation is in rst PEP form, at:... Noooooooo.... not another... there are too many already. :-( -1 From rantingrick at gmail.com Sun Feb 28 22:10:27 2010 From: rantingrick at gmail.com (rantingrick) Date: Sun, 28 Feb 2010 19:10:27 -0800 (PST) Subject: Sample code usable Tkinter listbox References: Message-ID: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> On Feb 28, 6:30?pm, "Alf P. Steinbach" wrote: > In case Someone Else(TM) may need this. > > This code is just how it currently looks, what I needed for my code, so it's not > a full-fledged or even tested class. Thanks for sharing Alf, Thats works fine "as-is" but what about inheriting from "tk.Listbox" directly and having the "container frame" as an attribute? I prefer this API because I hate to write the laborious "megawidget.mainwidget.methodX()" when i could instead write "megawidget.methodX()". What is your opinion on this? From steven at REMOVE.THIS.cybersource.com.au Sun Feb 28 22:18:47 2010 From: steven at REMOVE.THIS.cybersource.com.au (Steven D'Aprano) Date: 01 Mar 2010 03:18:47 GMT Subject: Draft PEP on RSON configuration file format References: Message-ID: On Sun, 28 Feb 2010 20:09:30 -0600, Patrick Maupin wrote: > All: > > Finding .ini configuration files too limiting, JSON and XML to hard to > manually edit, and YAML too complex to parse quickly, I have started > work on a new configuration file parser. > > I call the new format RSON (for "Readable Serial Object Notation"), and > it is designed to be a superset of JSON. Wait a minute... if JSON is too hard to edit, and RSON is a *superset* of JSON, that means by definition every JSON file is also a valid RSON file. Since JSON is too hard to manually edit, so is RSON. > I would love for it to be considered valuable enough to be a part of the > standard library, Come back when you actually have MANY users other than yourself using this is real-world projects. Until then, it is too early to even consider adding it the std library. Python comes with batteries included, but not experimental batteries that aren't even built yet, let alone proven that they work. -- Steven From alfps at start.no Sun Feb 28 22:57:32 2010 From: alfps at start.no (Alf P. Steinbach) Date: Mon, 01 Mar 2010 04:57:32 +0100 Subject: Sample code usable Tkinter listbox In-Reply-To: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> References: <5af8af6d-ecfc-4e4e-bba6-3622bbe874eb@o3g2000yqb.googlegroups.com> Message-ID: * rantingrick: > On Feb 28, 6:30 pm, "Alf P. Steinbach" wrote: >> In case Someone Else(TM) may need this. >> >> This code is just how it currently looks, what I needed for my code, so it's not >> a full-fledged or even tested class. > > Thanks for sharing Alf, > Thats works fine "as-is" but what about inheriting from "tk.Listbox" > directly and having the "container frame" as an attribute? I prefer > this API because I hate to write the laborious > "megawidget.mainwidget.methodX()" when i could instead write > "megawidget.methodX()". What is your opinion on this? Well the frame contains a listbox and scrollbar. And with the frame as attribute the object that you have a direct reference to would then not be the complete thing on screen, with respect to sizing and placement and such. I generally don't like widgets that present stuff outside their bounding box. I guess that could be fixed up somehow by overriding this and that, but I find it simpler to just make the enclosing widget the widget that one has a reference to. And in a way it's also good that it's more laborious to directly access the tkinter listbox stuff, because what I discovered so far is that much of it requires work arounds and fixups, i.e. that it should be wrapped in higher level methods. I had to add some more such functionality after I posted that code. So, current (this is untested except that it works for what I'm using it for!): class UsableListbox( t.Frame ): def __init__( self, parent_widget ): t.Frame.__init__( self, parent_widget ) scrollbar = t.Scrollbar( self, orient = "vertical" ) self.lb = t.Listbox( self, exportselection = 0, yscrollcommand = scrollbar.set ) scrollbar.config( command = self.lb.yview ) scrollbar.pack( side = "right", fill = "y" ) self.lb.pack( side = "left", fill = "both", expand = 1 ) def current_index( self ): indices = self.lb.curselection() assert( len( indices ) <= 1 ) # TODO: about multi-selection. return None if len( indices ) == 0 else int( indices[0] ) def current( self ): #return self.lb.get( "active" ) # Incorrect with mousing i = self.current_index() return "" if i is None else self.lb.get( i ) def item_count( self ): return self.lb.size() def clear( self ): self.lb.delete( 0, "end" ) def append( self, item ): return self.lb.insert( "end", item ) def select_item( self, i ): assert( 0 <= i < self.item_count() ) self.lb.selection_set( i ) def add_selection_event_handler( self, handler ): "An event handler takes one argument, a Tkinter Event" return self.lb.bind( "<>", handler ) Cheers, - Alf